blob: fe39c25b7a9618d622f68d675ed8159f6fafbe67 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant / Control interface (shared code for all backends)
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2004-2015, 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"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070059
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070060static int wpa_supplicant_global_iface_list(struct wpa_global *global,
61 char *buf, int len);
62static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080063 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070064 char *buf, int len);
Dmitry Shmidtd11f0192014-03-24 12:09:47 -070065static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
66 char *val);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070067
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070068
Dmitry Shmidt04949592012-07-19 12:16:46 -070069static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
70{
71 char *pos;
72 u8 addr[ETH_ALEN], *filter = NULL, *n;
73 size_t count = 0;
74
75 pos = val;
76 while (pos) {
77 if (*pos == '\0')
78 break;
79 if (hwaddr_aton(pos, addr)) {
80 os_free(filter);
81 return -1;
82 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070083 n = os_realloc_array(filter, count + 1, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -070084 if (n == NULL) {
85 os_free(filter);
86 return -1;
87 }
88 filter = n;
89 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
90 count++;
91
92 pos = os_strchr(pos, ' ');
93 if (pos)
94 pos++;
95 }
96
97 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
98 os_free(wpa_s->bssid_filter);
99 wpa_s->bssid_filter = filter;
100 wpa_s->bssid_filter_count = count;
101
102 return 0;
103}
104
105
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800106static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
107{
108 char *pos;
109 u8 addr[ETH_ALEN], *bssid = NULL, *n;
110 struct wpa_ssid_value *ssid = NULL, *ns;
111 size_t count = 0, ssid_count = 0;
112 struct wpa_ssid *c;
113
114 /*
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800115 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800116 * SSID_SPEC ::= ssid <SSID_HEX>
117 * BSSID_SPEC ::= bssid <BSSID_HEX>
118 */
119
120 pos = val;
121 while (pos) {
122 if (*pos == '\0')
123 break;
124 if (os_strncmp(pos, "bssid ", 6) == 0) {
125 int res;
126 pos += 6;
127 res = hwaddr_aton2(pos, addr);
128 if (res < 0) {
129 os_free(ssid);
130 os_free(bssid);
131 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
132 "BSSID value '%s'", pos);
133 return -1;
134 }
135 pos += res;
136 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
137 if (n == NULL) {
138 os_free(ssid);
139 os_free(bssid);
140 return -1;
141 }
142 bssid = n;
143 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
144 count++;
145 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
146 char *end;
147 pos += 5;
148
149 end = pos;
150 while (*end) {
151 if (*end == '\0' || *end == ' ')
152 break;
153 end++;
154 }
155
156 ns = os_realloc_array(ssid, ssid_count + 1,
157 sizeof(struct wpa_ssid_value));
158 if (ns == NULL) {
159 os_free(ssid);
160 os_free(bssid);
161 return -1;
162 }
163 ssid = ns;
164
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700165 if ((end - pos) & 0x01 ||
166 end - pos > 2 * SSID_MAX_LEN ||
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800167 hexstr2bin(pos, ssid[ssid_count].ssid,
168 (end - pos) / 2) < 0) {
169 os_free(ssid);
170 os_free(bssid);
171 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
172 "SSID value '%s'", pos);
173 return -1;
174 }
175 ssid[ssid_count].ssid_len = (end - pos) / 2;
176 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
177 ssid[ssid_count].ssid,
178 ssid[ssid_count].ssid_len);
179 ssid_count++;
180 pos = end;
181 } else {
182 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
183 "'%s'", pos);
184 os_free(ssid);
185 os_free(bssid);
186 return -1;
187 }
188
189 pos = os_strchr(pos, ' ');
190 if (pos)
191 pos++;
192 }
193
194 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
195 os_free(wpa_s->disallow_aps_bssid);
196 wpa_s->disallow_aps_bssid = bssid;
197 wpa_s->disallow_aps_bssid_count = count;
198
199 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
200 os_free(wpa_s->disallow_aps_ssid);
201 wpa_s->disallow_aps_ssid = ssid;
202 wpa_s->disallow_aps_ssid_count = ssid_count;
203
204 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
205 return 0;
206
207 c = wpa_s->current_ssid;
208 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
209 return 0;
210
211 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
212 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
213 return 0;
214
215 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
216 "because current AP was marked disallowed");
217
218#ifdef CONFIG_SME
219 wpa_s->sme.prev_bssid_set = 0;
220#endif /* CONFIG_SME */
221 wpa_s->reassociate = 1;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800222 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800223 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
224 wpa_supplicant_req_scan(wpa_s, 0, 0);
225
226 return 0;
227}
228
229
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700230#ifndef CONFIG_NO_CONFIG_BLOBS
231static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
232{
233 char *name = pos;
234 struct wpa_config_blob *blob;
235 size_t len;
236
237 pos = os_strchr(pos, ' ');
238 if (pos == NULL)
239 return -1;
240 *pos++ = '\0';
241 len = os_strlen(pos);
242 if (len & 1)
243 return -1;
244
245 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
246 blob = os_zalloc(sizeof(*blob));
247 if (blob == NULL)
248 return -1;
249 blob->name = os_strdup(name);
250 blob->data = os_malloc(len / 2);
251 if (blob->name == NULL || blob->data == NULL) {
252 wpa_config_free_blob(blob);
253 return -1;
254 }
255
256 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
257 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
258 wpa_config_free_blob(blob);
259 return -1;
260 }
261 blob->len = len / 2;
262
263 wpa_config_set_blob(wpa_s->conf, blob);
264
265 return 0;
266}
267#endif /* CONFIG_NO_CONFIG_BLOBS */
268
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700269
270static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
271{
272 char *params;
273 char *pos;
274 int *freqs = NULL;
275 int ret;
276
277 if (atoi(cmd)) {
278 params = os_strchr(cmd, ' ');
279 os_free(wpa_s->manual_sched_scan_freqs);
280 if (params) {
281 params++;
282 pos = os_strstr(params, "freq=");
283 if (pos)
284 freqs = freq_range_to_channel_list(wpa_s,
285 pos + 5);
286 }
287 wpa_s->manual_sched_scan_freqs = freqs;
288 ret = wpas_start_pno(wpa_s);
289 } else {
290 ret = wpas_stop_pno(wpa_s);
291 }
292 return ret;
293}
294
295
Ravi Joshie6ccb162015-07-16 17:45:41 -0700296static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band)
297{
298 union wpa_event_data event;
299
300 if (os_strcmp(band, "AUTO") == 0)
301 wpa_s->setband = WPA_SETBAND_AUTO;
302 else if (os_strcmp(band, "5G") == 0)
303 wpa_s->setband = WPA_SETBAND_5G;
304 else if (os_strcmp(band, "2G") == 0)
305 wpa_s->setband = WPA_SETBAND_2G;
306 else
307 return -1;
308
309 if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) {
310 os_memset(&event, 0, sizeof(event));
311 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
312 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
313 wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
314 }
315
316 return 0;
317}
318
319
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700320static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s,
321 const char *cmd)
322{
323 struct wpabuf *lci;
324
325 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
326 wpabuf_free(wpa_s->lci);
327 wpa_s->lci = NULL;
328 return 0;
329 }
330
331 lci = wpabuf_parse_bin(cmd);
332 if (!lci)
333 return -1;
334
335 if (os_get_reltime(&wpa_s->lci_time)) {
336 wpabuf_free(lci);
337 return -1;
338 }
339
340 wpabuf_free(wpa_s->lci);
341 wpa_s->lci = lci;
342
343 return 0;
344}
345
346
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800347static int
348wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd)
349{
350 int relative_rssi;
351
352 if (os_strcmp(cmd, "disable") == 0) {
353 wpa_s->srp.relative_rssi_set = 0;
354 return 0;
355 }
356
357 relative_rssi = atoi(cmd);
358 if (relative_rssi < 0 || relative_rssi > 100)
359 return -1;
360 wpa_s->srp.relative_rssi = relative_rssi;
361 wpa_s->srp.relative_rssi_set = 1;
362 return 0;
363}
364
365
366static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s,
367 const char *cmd)
368{
369 char *pos;
370 int adjust_rssi;
371
372 /* <band>:adjust_value */
373 pos = os_strchr(cmd, ':');
374 if (!pos)
375 return -1;
376 pos++;
377 adjust_rssi = atoi(pos);
378 if (adjust_rssi < -100 || adjust_rssi > 100)
379 return -1;
380
381 if (os_strncmp(cmd, "2G", 2) == 0)
382 wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G;
383 else if (os_strncmp(cmd, "5G", 2) == 0)
384 wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G;
385 else
386 return -1;
387
388 wpa_s->srp.relative_adjust_rssi = adjust_rssi;
389
390 return 0;
391}
392
393
394static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s,
395 const char *cmd)
396{
397 struct wpabuf *ric_ies;
398
399 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
400 wpabuf_free(wpa_s->ric_ies);
401 wpa_s->ric_ies = NULL;
402 return 0;
403 }
404
405 ric_ies = wpabuf_parse_bin(cmd);
406 if (!ric_ies)
407 return -1;
408
409 wpabuf_free(wpa_s->ric_ies);
410 wpa_s->ric_ies = ric_ies;
411
412 return 0;
413}
414
415
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700416static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
417 char *cmd)
418{
419 char *value;
420 int ret = 0;
421
422 value = os_strchr(cmd, ' ');
423 if (value == NULL)
424 return -1;
425 *value++ = '\0';
426
427 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
428 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
429 eapol_sm_configure(wpa_s->eapol,
430 atoi(value), -1, -1, -1);
431 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
432 eapol_sm_configure(wpa_s->eapol,
433 -1, atoi(value), -1, -1);
434 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
435 eapol_sm_configure(wpa_s->eapol,
436 -1, -1, atoi(value), -1);
437 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
438 eapol_sm_configure(wpa_s->eapol,
439 -1, -1, -1, atoi(value));
440 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
441 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
Paul Stewart092955c2017-02-06 09:13:09 -0800442 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700443 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800444 } else {
445 value[-1] = '=';
446 wpa_config_process_global(wpa_s->conf, cmd, -1);
447 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700448 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
449 0) {
450 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
Paul Stewart092955c2017-02-06 09:13:09 -0800451 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700452 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800453 } else {
454 value[-1] = '=';
455 wpa_config_process_global(wpa_s->conf, cmd, -1);
456 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
Paul Stewart092955c2017-02-06 09:13:09 -0800458 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
459 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700460 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800461 } else {
462 value[-1] = '=';
463 wpa_config_process_global(wpa_s->conf, cmd, -1);
464 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700465 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
466 wpa_s->wps_fragment_size = atoi(value);
467#ifdef CONFIG_WPS_TESTING
468 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
469 long int val;
470 val = strtol(value, NULL, 0);
471 if (val < 0 || val > 0xff) {
472 ret = -1;
473 wpa_printf(MSG_DEBUG, "WPS: Invalid "
474 "wps_version_number %ld", val);
475 } else {
476 wps_version_number = val;
477 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
478 "version %u.%u",
479 (wps_version_number & 0xf0) >> 4,
480 wps_version_number & 0x0f);
481 }
482 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
483 wps_testing_dummy_cred = atoi(value);
484 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
485 wps_testing_dummy_cred);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800486 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
487 wps_corrupt_pkhash = atoi(value);
488 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
489 wps_corrupt_pkhash);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800490 } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
491 if (value[0] == '\0') {
492 wps_force_auth_types_in_use = 0;
493 } else {
494 wps_force_auth_types = strtol(value, NULL, 0);
495 wps_force_auth_types_in_use = 1;
496 }
497 } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
498 if (value[0] == '\0') {
499 wps_force_encr_types_in_use = 0;
500 } else {
501 wps_force_encr_types = strtol(value, NULL, 0);
502 wps_force_encr_types_in_use = 1;
503 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504#endif /* CONFIG_WPS_TESTING */
505 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
506 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
507 ret = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800508#ifdef CONFIG_TDLS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700509#ifdef CONFIG_TDLS_TESTING
510 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700511 tdls_testing = strtol(value, NULL, 0);
512 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
513#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
515 int disabled = atoi(value);
516 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
517 if (disabled) {
518 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
519 ret = -1;
520 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
521 ret = -1;
522 wpa_tdls_enable(wpa_s->wpa, !disabled);
523#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800524 } else if (os_strcasecmp(cmd, "pno") == 0) {
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700525 ret = wpas_ctrl_pno(wpa_s, value);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700526 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
527 int disabled = atoi(value);
528 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
529 ret = -1;
530 else if (disabled)
531 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
532 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
533 if (os_strcmp(value, "disable") == 0)
534 wpa_s->set_sta_uapsd = 0;
535 else {
536 int be, bk, vi, vo;
537 char *pos;
538 /* format: BE,BK,VI,VO;max SP Length */
539 be = atoi(value);
540 pos = os_strchr(value, ',');
541 if (pos == NULL)
542 return -1;
543 pos++;
544 bk = atoi(pos);
545 pos = os_strchr(pos, ',');
546 if (pos == NULL)
547 return -1;
548 pos++;
549 vi = atoi(pos);
550 pos = os_strchr(pos, ',');
551 if (pos == NULL)
552 return -1;
553 pos++;
554 vo = atoi(pos);
555 /* ignore max SP Length for now */
556
557 wpa_s->set_sta_uapsd = 1;
558 wpa_s->sta_uapsd = 0;
559 if (be)
560 wpa_s->sta_uapsd |= BIT(0);
561 if (bk)
562 wpa_s->sta_uapsd |= BIT(1);
563 if (vi)
564 wpa_s->sta_uapsd |= BIT(2);
565 if (vo)
566 wpa_s->sta_uapsd |= BIT(3);
567 }
Jouni Malinen21d6bc82012-04-10 16:17:59 -0700568 } else if (os_strcasecmp(cmd, "ps") == 0) {
569 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700570#ifdef CONFIG_WIFI_DISPLAY
571 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800572 int enabled = !!atoi(value);
573 if (enabled && !wpa_s->global->p2p)
574 ret = -1;
575 else
576 wifi_display_enable(wpa_s->global, enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700577#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700578 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
579 ret = set_bssid_filter(wpa_s, value);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800580 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
581 ret = set_disallow_aps(wpa_s, value);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800582 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
583 wpa_s->no_keep_alive = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700584#ifdef CONFIG_DPP
585 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
586 os_free(wpa_s->dpp_configurator_params);
587 wpa_s->dpp_configurator_params = os_strdup(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700588 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
589 wpa_s->dpp_init_max_tries = atoi(value);
590 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
591 wpa_s->dpp_init_retry_time = atoi(value);
592 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
593 wpa_s->dpp_resp_wait_time = atoi(value);
594 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
595 wpa_s->dpp_resp_max_tries = atoi(value);
596 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
597 wpa_s->dpp_resp_retry_time = atoi(value);
598#ifdef CONFIG_TESTING_OPTIONS
599 } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
600 if (hwaddr_aton(value, dpp_pkex_own_mac_override))
601 ret = -1;
602 } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
603 if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
604 ret = -1;
605 } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
606 size_t hex_len = os_strlen(value);
607
608 if (hex_len >
609 2 * sizeof(dpp_pkex_ephemeral_key_override))
610 ret = -1;
611 else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
612 hex_len / 2))
613 ret = -1;
614 else
615 dpp_pkex_ephemeral_key_override_len = hex_len / 2;
616 } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) {
617 size_t hex_len = os_strlen(value);
618
619 if (hex_len > 2 * sizeof(dpp_protocol_key_override))
620 ret = -1;
621 else if (hexstr2bin(value, dpp_protocol_key_override,
622 hex_len / 2))
623 ret = -1;
624 else
625 dpp_protocol_key_override_len = hex_len / 2;
626 } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) {
627 size_t hex_len = os_strlen(value);
628
629 if (hex_len > 2 * sizeof(dpp_nonce_override))
630 ret = -1;
631 else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2))
632 ret = -1;
633 else
634 dpp_nonce_override_len = hex_len / 2;
635#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700636#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700637#ifdef CONFIG_TESTING_OPTIONS
638 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
639 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800640 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
641 wpa_s->ext_eapol_frame_io = !!atoi(value);
642#ifdef CONFIG_AP
643 if (wpa_s->ap_iface) {
644 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
645 wpa_s->ext_eapol_frame_io;
646 }
647#endif /* CONFIG_AP */
648 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
649 wpa_s->extra_roc_dur = atoi(value);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800650 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
651 wpa_s->test_failure = atoi(value);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800652 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
653 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700654 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
655 wpa_s->ignore_auth_resp = !!atoi(value);
656 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
657 wpa_s->ignore_assoc_disallow = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700658 wpa_drv_ignore_assoc_disallow(wpa_s,
659 wpa_s->ignore_assoc_disallow);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700660 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
661 wpa_s->reject_btm_req_reason = atoi(value);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800662 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
663 os_free(wpa_s->get_pref_freq_list_override);
664 if (!value[0])
665 wpa_s->get_pref_freq_list_override = NULL;
666 else
667 wpa_s->get_pref_freq_list_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700668 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
669 wpabuf_free(wpa_s->sae_commit_override);
670 if (value[0] == '\0')
671 wpa_s->sae_commit_override = NULL;
672 else
673 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
674#ifdef CONFIG_DPP
675 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
676 os_free(wpa_s->dpp_config_obj_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700677 if (value[0] == '\0')
678 wpa_s->dpp_config_obj_override = NULL;
679 else
680 wpa_s->dpp_config_obj_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700681 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
682 os_free(wpa_s->dpp_discovery_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700683 if (value[0] == '\0')
684 wpa_s->dpp_discovery_override = NULL;
685 else
686 wpa_s->dpp_discovery_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700687 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
688 os_free(wpa_s->dpp_groups_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700689 if (value[0] == '\0')
690 wpa_s->dpp_groups_override = NULL;
691 else
692 wpa_s->dpp_groups_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700693 } else if (os_strcasecmp(cmd,
694 "dpp_ignore_netaccesskey_mismatch") == 0) {
695 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700696 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
697 dpp_test = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700698#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700699#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700700#ifdef CONFIG_FILS
701 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
702 wpa_s->disable_fils = !!atoi(value);
703 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
704 wpa_supplicant_set_default_scan_ies(wpa_s);
705#endif /* CONFIG_FILS */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700706#ifndef CONFIG_NO_CONFIG_BLOBS
707 } else if (os_strcmp(cmd, "blob") == 0) {
708 ret = wpas_ctrl_set_blob(wpa_s, value);
709#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800710 } else if (os_strcasecmp(cmd, "setband") == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700711 ret = wpas_ctrl_set_band(wpa_s, value);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800712#ifdef CONFIG_MBO
713 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
714 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
Paul Stewart092955c2017-02-06 09:13:09 -0800715 if (ret == 0) {
716 value[-1] = '=';
717 wpa_config_process_global(wpa_s->conf, cmd, -1);
718 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800719 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
720 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700721 } else if (os_strcasecmp(cmd, "oce") == 0) {
722 wpa_s->conf->oce = atoi(value);
723 if (wpa_s->conf->oce) {
724 if ((wpa_s->conf->oce & OCE_STA) &&
725 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
726 wpa_s->enable_oce = OCE_STA;
727
728 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
729 (wpa_s->drv_flags &
730 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
731 /* TODO: Need to add STA-CFON support */
732 wpa_printf(MSG_ERROR,
733 "OCE STA-CFON feature is not yet supported");
734 return -1;
735 }
736 } else {
737 wpa_s->enable_oce = 0;
738 }
739 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800740#endif /* CONFIG_MBO */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700741 } else if (os_strcasecmp(cmd, "lci") == 0) {
742 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800743 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
744 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800745 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
746 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
747 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
748 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
749 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
750 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700751 } else if (os_strcasecmp(cmd, "roaming") == 0) {
752 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700753 } else {
754 value[-1] = '=';
755 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
756 if (ret == 0)
757 wpa_supplicant_update_config(wpa_s);
758 }
759
760 return ret;
761}
762
763
764static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
765 char *cmd, char *buf, size_t buflen)
766{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700767 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700768
769 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
770
771 if (os_strcmp(cmd, "version") == 0) {
772 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700773 } else if (os_strcasecmp(cmd, "country") == 0) {
774 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
775 res = os_snprintf(buf, buflen, "%c%c",
776 wpa_s->conf->country[0],
777 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700778#ifdef CONFIG_WIFI_DISPLAY
779 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800780 int enabled;
781 if (wpa_s->global->p2p == NULL ||
782 wpa_s->global->p2p_disabled)
783 enabled = 0;
784 else
785 enabled = wpa_s->global->wifi_display;
786 res = os_snprintf(buf, buflen, "%d", enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700787#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700788#ifdef CONFIG_TESTING_GET_GTK
789 } else if (os_strcmp(cmd, "gtk") == 0) {
790 if (wpa_s->last_gtk_len == 0)
791 return -1;
792 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
793 wpa_s->last_gtk_len);
794 return res;
795#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800796 } else if (os_strcmp(cmd, "tls_library") == 0) {
797 res = tls_get_library_version(buf, buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700798#ifdef CONFIG_TESTING_OPTIONS
799 } else if (os_strcmp(cmd, "anonce") == 0) {
800 return wpa_snprintf_hex(buf, buflen,
801 wpa_sm_get_anonce(wpa_s->wpa),
802 WPA_NONCE_LEN);
803#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800804 } else {
805 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700806 }
807
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800808 if (os_snprintf_error(buflen, res))
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700809 return -1;
810 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700811}
812
813
814#ifdef IEEE8021X_EAPOL
815static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
816 char *addr)
817{
818 u8 bssid[ETH_ALEN];
819 struct wpa_ssid *ssid = wpa_s->current_ssid;
820
821 if (hwaddr_aton(addr, bssid)) {
822 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
823 "'%s'", addr);
824 return -1;
825 }
826
827 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
828 rsn_preauth_deinit(wpa_s->wpa);
829 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
830 return -1;
831
832 return 0;
833}
834#endif /* IEEE8021X_EAPOL */
835
836
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700837#ifdef CONFIG_TDLS
838
839static int wpa_supplicant_ctrl_iface_tdls_discover(
840 struct wpa_supplicant *wpa_s, char *addr)
841{
842 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800843 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700844
845 if (hwaddr_aton(addr, peer)) {
846 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
847 "address '%s'", addr);
848 return -1;
849 }
850
851 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
852 MAC2STR(peer));
853
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800854 if (wpa_tdls_is_external_setup(wpa_s->wpa))
855 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
856 else
857 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
858
859 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700860}
861
862
863static int wpa_supplicant_ctrl_iface_tdls_setup(
864 struct wpa_supplicant *wpa_s, char *addr)
865{
866 u8 peer[ETH_ALEN];
867 int ret;
868
869 if (hwaddr_aton(addr, peer)) {
870 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
871 "address '%s'", addr);
872 return -1;
873 }
874
875 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
876 MAC2STR(peer));
877
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800878 if ((wpa_s->conf->tdls_external_control) &&
879 wpa_tdls_is_external_setup(wpa_s->wpa))
880 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
881
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800882 wpa_tdls_remove(wpa_s->wpa, peer);
883
884 if (wpa_tdls_is_external_setup(wpa_s->wpa))
885 ret = wpa_tdls_start(wpa_s->wpa, peer);
886 else
887 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800888
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700889 return ret;
890}
891
892
893static int wpa_supplicant_ctrl_iface_tdls_teardown(
894 struct wpa_supplicant *wpa_s, char *addr)
895{
896 u8 peer[ETH_ALEN];
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700897 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700898
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700899 if (os_strcmp(addr, "*") == 0) {
900 /* remove everyone */
901 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
902 wpa_tdls_teardown_peers(wpa_s->wpa);
903 return 0;
904 }
905
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700906 if (hwaddr_aton(addr, peer)) {
907 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
908 "address '%s'", addr);
909 return -1;
910 }
911
912 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
913 MAC2STR(peer));
914
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800915 if ((wpa_s->conf->tdls_external_control) &&
916 wpa_tdls_is_external_setup(wpa_s->wpa))
917 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
918
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700919 if (wpa_tdls_is_external_setup(wpa_s->wpa))
920 ret = wpa_tdls_teardown_link(
921 wpa_s->wpa, peer,
922 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
923 else
924 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
925
926 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700927}
928
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700929
930static int ctrl_iface_get_capability_tdls(
931 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
932{
933 int ret;
934
935 ret = os_snprintf(buf, buflen, "%s\n",
936 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
937 (wpa_s->drv_flags &
938 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
939 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800940 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700941 return -1;
942 return ret;
943}
944
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800945
946static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
947 struct wpa_supplicant *wpa_s, char *cmd)
948{
949 u8 peer[ETH_ALEN];
950 struct hostapd_freq_params freq_params;
951 u8 oper_class;
952 char *pos, *end;
953
954 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
955 wpa_printf(MSG_INFO,
956 "tdls_chanswitch: Only supported with external setup");
957 return -1;
958 }
959
960 os_memset(&freq_params, 0, sizeof(freq_params));
961
962 pos = os_strchr(cmd, ' ');
963 if (pos == NULL)
964 return -1;
965 *pos++ = '\0';
966
967 oper_class = strtol(pos, &end, 10);
968 if (pos == end) {
969 wpa_printf(MSG_INFO,
970 "tdls_chanswitch: Invalid op class provided");
971 return -1;
972 }
973
974 pos = end;
975 freq_params.freq = atoi(pos);
976 if (freq_params.freq == 0) {
977 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
978 return -1;
979 }
980
981#define SET_FREQ_SETTING(str) \
982 do { \
983 const char *pos2 = os_strstr(pos, " " #str "="); \
984 if (pos2) { \
985 pos2 += sizeof(" " #str "=") - 1; \
986 freq_params.str = atoi(pos2); \
987 } \
988 } while (0)
989
990 SET_FREQ_SETTING(center_freq1);
991 SET_FREQ_SETTING(center_freq2);
992 SET_FREQ_SETTING(bandwidth);
993 SET_FREQ_SETTING(sec_channel_offset);
994#undef SET_FREQ_SETTING
995
996 freq_params.ht_enabled = !!os_strstr(pos, " ht");
997 freq_params.vht_enabled = !!os_strstr(pos, " vht");
998
999 if (hwaddr_aton(cmd, peer)) {
1000 wpa_printf(MSG_DEBUG,
1001 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1002 cmd);
1003 return -1;
1004 }
1005
1006 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1007 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1008 MAC2STR(peer), oper_class, freq_params.freq,
1009 freq_params.center_freq1, freq_params.center_freq2,
1010 freq_params.bandwidth, freq_params.sec_channel_offset,
1011 freq_params.ht_enabled ? " HT" : "",
1012 freq_params.vht_enabled ? " VHT" : "");
1013
1014 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1015 &freq_params);
1016}
1017
1018
1019static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1020 struct wpa_supplicant *wpa_s, char *cmd)
1021{
1022 u8 peer[ETH_ALEN];
1023
1024 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1025 wpa_printf(MSG_INFO,
1026 "tdls_chanswitch: Only supported with external setup");
1027 return -1;
1028 }
1029
1030 if (hwaddr_aton(cmd, peer)) {
1031 wpa_printf(MSG_DEBUG,
1032 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1033 cmd);
1034 return -1;
1035 }
1036
1037 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1038 MAC2STR(peer));
1039
1040 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1041}
1042
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07001043
1044static int wpa_supplicant_ctrl_iface_tdls_link_status(
1045 struct wpa_supplicant *wpa_s, const char *addr,
1046 char *buf, size_t buflen)
1047{
1048 u8 peer[ETH_ALEN];
1049 const char *tdls_status;
1050 int ret;
1051
1052 if (hwaddr_aton(addr, peer)) {
1053 wpa_printf(MSG_DEBUG,
1054 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1055 addr);
1056 return -1;
1057 }
1058 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1059 MAC2STR(peer));
1060
1061 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1062 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1063 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1064 if (os_snprintf_error(buflen, ret))
1065 return -1;
1066
1067 return ret;
1068}
1069
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001070#endif /* CONFIG_TDLS */
1071
1072
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001073static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1074{
1075 char *token, *context = NULL;
1076 struct wmm_ac_ts_setup_params params = {
1077 .tsid = 0xff,
1078 .direction = 0xff,
1079 };
1080
1081 while ((token = str_token(cmd, " ", &context))) {
1082 if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
1083 sscanf(token, "up=%i", &params.user_priority) == 1 ||
1084 sscanf(token, "nominal_msdu_size=%i",
1085 &params.nominal_msdu_size) == 1 ||
1086 sscanf(token, "mean_data_rate=%i",
1087 &params.mean_data_rate) == 1 ||
1088 sscanf(token, "min_phy_rate=%i",
1089 &params.minimum_phy_rate) == 1 ||
1090 sscanf(token, "sba=%i",
1091 &params.surplus_bandwidth_allowance) == 1)
1092 continue;
1093
1094 if (os_strcasecmp(token, "downlink") == 0) {
1095 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1096 } else if (os_strcasecmp(token, "uplink") == 0) {
1097 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1098 } else if (os_strcasecmp(token, "bidi") == 0) {
1099 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1100 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1101 params.fixed_nominal_msdu = 1;
1102 } else {
1103 wpa_printf(MSG_DEBUG,
1104 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1105 token);
1106 return -1;
1107 }
1108
1109 }
1110
1111 return wpas_wmm_ac_addts(wpa_s, &params);
1112}
1113
1114
1115static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1116{
1117 u8 tsid = atoi(cmd);
1118
1119 return wpas_wmm_ac_delts(wpa_s, tsid);
1120}
1121
1122
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001123#ifdef CONFIG_IEEE80211R
1124static int wpa_supplicant_ctrl_iface_ft_ds(
1125 struct wpa_supplicant *wpa_s, char *addr)
1126{
1127 u8 target_ap[ETH_ALEN];
1128 struct wpa_bss *bss;
1129 const u8 *mdie;
1130
1131 if (hwaddr_aton(addr, target_ap)) {
1132 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1133 "address '%s'", addr);
1134 return -1;
1135 }
1136
1137 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1138
1139 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1140 if (bss)
1141 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1142 else
1143 mdie = NULL;
1144
1145 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
1146}
1147#endif /* CONFIG_IEEE80211R */
1148
1149
1150#ifdef CONFIG_WPS
1151static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1152 char *cmd)
1153{
1154 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001155#ifdef CONFIG_P2P
1156 u8 p2p_dev_addr[ETH_ALEN];
1157#endif /* CONFIG_P2P */
1158#ifdef CONFIG_AP
1159 u8 *_p2p_dev_addr = NULL;
1160#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001161
Dmitry Shmidtc0a8db02013-11-08 11:18:33 -08001162 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001163 _bssid = NULL;
1164#ifdef CONFIG_P2P
1165 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1166 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1167 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1168 "P2P Device Address '%s'",
1169 cmd + 13);
1170 return -1;
1171 }
1172 _p2p_dev_addr = p2p_dev_addr;
1173#endif /* CONFIG_P2P */
1174 } else if (hwaddr_aton(cmd, bssid)) {
1175 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1176 cmd);
1177 return -1;
1178 }
1179
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001180#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001181 if (wpa_s->ap_iface)
1182 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1183#endif /* CONFIG_AP */
1184
1185 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
1186}
1187
1188
1189static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1190 char *cmd, char *buf,
1191 size_t buflen)
1192{
1193 u8 bssid[ETH_ALEN], *_bssid = bssid;
1194 char *pin;
1195 int ret;
1196
1197 pin = os_strchr(cmd, ' ');
1198 if (pin)
1199 *pin++ = '\0';
1200
1201 if (os_strcmp(cmd, "any") == 0)
1202 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001203 else if (os_strcmp(cmd, "get") == 0) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001204 if (wps_generate_pin((unsigned int *) &ret) < 0)
1205 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001206 goto done;
1207 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001208 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1209 cmd);
1210 return -1;
1211 }
1212
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001213#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001214 if (wpa_s->ap_iface) {
1215 int timeout = 0;
1216 char *pos;
1217
1218 if (pin) {
1219 pos = os_strchr(pin, ' ');
1220 if (pos) {
1221 *pos++ = '\0';
1222 timeout = atoi(pos);
1223 }
1224 }
1225
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001226 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001227 buf, buflen, timeout);
1228 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001229#endif /* CONFIG_AP */
1230
1231 if (pin) {
1232 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1233 DEV_PW_DEFAULT);
1234 if (ret < 0)
1235 return -1;
1236 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001237 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001238 return -1;
1239 return ret;
1240 }
1241
1242 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1243 if (ret < 0)
1244 return -1;
1245
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001246done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001247 /* Return the generated PIN */
1248 ret = os_snprintf(buf, buflen, "%08d", ret);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001249 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001250 return -1;
1251 return ret;
1252}
1253
1254
1255static int wpa_supplicant_ctrl_iface_wps_check_pin(
1256 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1257{
1258 char pin[9];
1259 size_t len;
1260 char *pos;
1261 int ret;
1262
1263 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1264 (u8 *) cmd, os_strlen(cmd));
1265 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1266 if (*pos < '0' || *pos > '9')
1267 continue;
1268 pin[len++] = *pos;
1269 if (len == 9) {
1270 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1271 return -1;
1272 }
1273 }
1274 if (len != 4 && len != 8) {
1275 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1276 return -1;
1277 }
1278 pin[len] = '\0';
1279
1280 if (len == 8) {
1281 unsigned int pin_val;
1282 pin_val = atoi(pin);
1283 if (!wps_pin_valid(pin_val)) {
1284 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1285 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001286 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001287 return -1;
1288 return ret;
1289 }
1290 }
1291
1292 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001293 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001294 return -1;
1295
1296 return ret;
1297}
1298
1299
Dmitry Shmidt04949592012-07-19 12:16:46 -07001300#ifdef CONFIG_WPS_NFC
1301
1302static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1303 char *cmd)
1304{
1305 u8 bssid[ETH_ALEN], *_bssid = bssid;
1306
1307 if (cmd == NULL || cmd[0] == '\0')
1308 _bssid = NULL;
1309 else if (hwaddr_aton(cmd, bssid))
1310 return -1;
1311
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001312 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1313 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001314}
1315
1316
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001317static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1318 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1319{
1320 int ndef;
1321 struct wpabuf *buf;
1322 int res;
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001323 char *pos;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001324
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001325 pos = os_strchr(cmd, ' ');
1326 if (pos)
1327 *pos++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001328 if (os_strcmp(cmd, "WPS") == 0)
1329 ndef = 0;
1330 else if (os_strcmp(cmd, "NDEF") == 0)
1331 ndef = 1;
1332 else
1333 return -1;
1334
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001335 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001336 if (buf == NULL)
1337 return -1;
1338
1339 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1340 wpabuf_len(buf));
1341 reply[res++] = '\n';
1342 reply[res] = '\0';
1343
1344 wpabuf_free(buf);
1345
1346 return res;
1347}
1348
1349
Dmitry Shmidt04949592012-07-19 12:16:46 -07001350static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1351 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1352{
1353 int ndef;
1354 struct wpabuf *buf;
1355 int res;
1356
1357 if (os_strcmp(cmd, "WPS") == 0)
1358 ndef = 0;
1359 else if (os_strcmp(cmd, "NDEF") == 0)
1360 ndef = 1;
1361 else
1362 return -1;
1363
1364 buf = wpas_wps_nfc_token(wpa_s, ndef);
1365 if (buf == NULL)
1366 return -1;
1367
1368 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1369 wpabuf_len(buf));
1370 reply[res++] = '\n';
1371 reply[res] = '\0';
1372
1373 wpabuf_free(buf);
1374
1375 return res;
1376}
1377
1378
1379static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1380 struct wpa_supplicant *wpa_s, char *pos)
1381{
1382 size_t len;
1383 struct wpabuf *buf;
1384 int ret;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001385 char *freq;
1386 int forced_freq = 0;
1387
1388 freq = strstr(pos, " freq=");
1389 if (freq) {
1390 *freq = '\0';
1391 freq += 6;
1392 forced_freq = atoi(freq);
1393 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001394
1395 len = os_strlen(pos);
1396 if (len & 0x01)
1397 return -1;
1398 len /= 2;
1399
1400 buf = wpabuf_alloc(len);
1401 if (buf == NULL)
1402 return -1;
1403 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1404 wpabuf_free(buf);
1405 return -1;
1406 }
1407
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001408 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001409 wpabuf_free(buf);
1410
1411 return ret;
1412}
1413
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001414
1415static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001416 char *reply, size_t max_len,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001417 int ndef)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001418{
1419 struct wpabuf *buf;
1420 int res;
1421
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001422 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001423 if (buf == NULL)
1424 return -1;
1425
1426 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1427 wpabuf_len(buf));
1428 reply[res++] = '\n';
1429 reply[res] = '\0';
1430
1431 wpabuf_free(buf);
1432
1433 return res;
1434}
1435
1436
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001437#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001438static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1439 char *reply, size_t max_len,
1440 int ndef)
1441{
1442 struct wpabuf *buf;
1443 int res;
1444
1445 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1446 if (buf == NULL) {
1447 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1448 return -1;
1449 }
1450
1451 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1452 wpabuf_len(buf));
1453 reply[res++] = '\n';
1454 reply[res] = '\0';
1455
1456 wpabuf_free(buf);
1457
1458 return res;
1459}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001460#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001461
1462
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001463static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1464 char *cmd, char *reply,
1465 size_t max_len)
1466{
1467 char *pos;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001468 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001469
1470 pos = os_strchr(cmd, ' ');
1471 if (pos == NULL)
1472 return -1;
1473 *pos++ = '\0';
1474
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001475 if (os_strcmp(cmd, "WPS") == 0)
1476 ndef = 0;
1477 else if (os_strcmp(cmd, "NDEF") == 0)
1478 ndef = 1;
1479 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001480 return -1;
1481
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001482 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001483 if (!ndef)
1484 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001485 return wpas_ctrl_nfc_get_handover_req_wps(
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001486 wpa_s, reply, max_len, ndef);
1487 }
1488
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001489#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001490 if (os_strcmp(pos, "P2P-CR") == 0) {
1491 return wpas_ctrl_nfc_get_handover_req_p2p(
1492 wpa_s, reply, max_len, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001493 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001494#endif /* CONFIG_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001495
1496 return -1;
1497}
1498
1499
1500static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001501 char *reply, size_t max_len,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001502 int ndef, int cr, char *uuid)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001503{
1504 struct wpabuf *buf;
1505 int res;
1506
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001507 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001508 if (buf == NULL)
1509 return -1;
1510
1511 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1512 wpabuf_len(buf));
1513 reply[res++] = '\n';
1514 reply[res] = '\0';
1515
1516 wpabuf_free(buf);
1517
1518 return res;
1519}
1520
1521
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001522#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001523static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1524 char *reply, size_t max_len,
1525 int ndef, int tag)
1526{
1527 struct wpabuf *buf;
1528 int res;
1529
1530 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1531 if (buf == NULL)
1532 return -1;
1533
1534 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1535 wpabuf_len(buf));
1536 reply[res++] = '\n';
1537 reply[res] = '\0';
1538
1539 wpabuf_free(buf);
1540
1541 return res;
1542}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001543#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001544
1545
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001546static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1547 char *cmd, char *reply,
1548 size_t max_len)
1549{
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001550 char *pos, *pos2;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001551 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001552
1553 pos = os_strchr(cmd, ' ');
1554 if (pos == NULL)
1555 return -1;
1556 *pos++ = '\0';
1557
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001558 if (os_strcmp(cmd, "WPS") == 0)
1559 ndef = 0;
1560 else if (os_strcmp(cmd, "NDEF") == 0)
1561 ndef = 1;
1562 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001563 return -1;
1564
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001565 pos2 = os_strchr(pos, ' ');
1566 if (pos2)
1567 *pos2++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001568 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001569 if (!ndef)
1570 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001571 return wpas_ctrl_nfc_get_handover_sel_wps(
1572 wpa_s, reply, max_len, ndef,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001573 os_strcmp(pos, "WPS-CR") == 0, pos2);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001574 }
1575
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001576#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001577 if (os_strcmp(pos, "P2P-CR") == 0) {
1578 return wpas_ctrl_nfc_get_handover_sel_p2p(
1579 wpa_s, reply, max_len, ndef, 0);
1580 }
1581
1582 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1583 return wpas_ctrl_nfc_get_handover_sel_p2p(
1584 wpa_s, reply, max_len, ndef, 1);
1585 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001586#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001587
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001588 return -1;
1589}
1590
1591
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001592static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1593 char *cmd)
1594{
1595 size_t len;
1596 struct wpabuf *req, *sel;
1597 int ret;
1598 char *pos, *role, *type, *pos2;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001599#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001600 char *freq;
1601 int forced_freq = 0;
1602
1603 freq = strstr(cmd, " freq=");
1604 if (freq) {
1605 *freq = '\0';
1606 freq += 6;
1607 forced_freq = atoi(freq);
1608 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001609#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001610
1611 role = cmd;
1612 pos = os_strchr(role, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001613 if (pos == NULL) {
1614 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001615 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001616 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001617 *pos++ = '\0';
1618
1619 type = pos;
1620 pos = os_strchr(type, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001621 if (pos == NULL) {
1622 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001623 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001624 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001625 *pos++ = '\0';
1626
1627 pos2 = os_strchr(pos, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001628 if (pos2 == NULL) {
1629 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001630 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001631 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001632 *pos2++ = '\0';
1633
1634 len = os_strlen(pos);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001635 if (len & 0x01) {
1636 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001637 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001638 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001639 len /= 2;
1640
1641 req = wpabuf_alloc(len);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001642 if (req == NULL) {
1643 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001644 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001645 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001646 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001647 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001648 wpabuf_free(req);
1649 return -1;
1650 }
1651
1652 len = os_strlen(pos2);
1653 if (len & 0x01) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001654 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001655 wpabuf_free(req);
1656 return -1;
1657 }
1658 len /= 2;
1659
1660 sel = wpabuf_alloc(len);
1661 if (sel == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001662 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001663 wpabuf_free(req);
1664 return -1;
1665 }
1666 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001667 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001668 wpabuf_free(req);
1669 wpabuf_free(sel);
1670 return -1;
1671 }
1672
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001673 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1674 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1675
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001676 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1677 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001678#ifdef CONFIG_AP
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001679 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1680 {
1681 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1682 if (ret < 0)
1683 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001684#endif /* CONFIG_AP */
1685#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001686 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1687 {
1688 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1689 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1690 {
1691 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1692 forced_freq);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001693#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001694 } else {
1695 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1696 "reported: role=%s type=%s", role, type);
1697 ret = -1;
1698 }
1699 wpabuf_free(req);
1700 wpabuf_free(sel);
1701
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001702 if (ret)
1703 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1704
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001705 return ret;
1706}
1707
Dmitry Shmidt04949592012-07-19 12:16:46 -07001708#endif /* CONFIG_WPS_NFC */
1709
1710
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001711static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1712 char *cmd)
1713{
1714 u8 bssid[ETH_ALEN];
1715 char *pin;
1716 char *new_ssid;
1717 char *new_auth;
1718 char *new_encr;
1719 char *new_key;
1720 struct wps_new_ap_settings ap;
1721
1722 pin = os_strchr(cmd, ' ');
1723 if (pin == NULL)
1724 return -1;
1725 *pin++ = '\0';
1726
1727 if (hwaddr_aton(cmd, bssid)) {
1728 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1729 cmd);
1730 return -1;
1731 }
1732
1733 new_ssid = os_strchr(pin, ' ');
1734 if (new_ssid == NULL)
1735 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1736 *new_ssid++ = '\0';
1737
1738 new_auth = os_strchr(new_ssid, ' ');
1739 if (new_auth == NULL)
1740 return -1;
1741 *new_auth++ = '\0';
1742
1743 new_encr = os_strchr(new_auth, ' ');
1744 if (new_encr == NULL)
1745 return -1;
1746 *new_encr++ = '\0';
1747
1748 new_key = os_strchr(new_encr, ' ');
1749 if (new_key == NULL)
1750 return -1;
1751 *new_key++ = '\0';
1752
1753 os_memset(&ap, 0, sizeof(ap));
1754 ap.ssid_hex = new_ssid;
1755 ap.auth = new_auth;
1756 ap.encr = new_encr;
1757 ap.key_hex = new_key;
1758 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1759}
1760
1761
1762#ifdef CONFIG_AP
1763static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1764 char *cmd, char *buf,
1765 size_t buflen)
1766{
1767 int timeout = 300;
1768 char *pos;
1769 const char *pin_txt;
1770
1771 if (!wpa_s->ap_iface)
1772 return -1;
1773
1774 pos = os_strchr(cmd, ' ');
1775 if (pos)
1776 *pos++ = '\0';
1777
1778 if (os_strcmp(cmd, "disable") == 0) {
1779 wpas_wps_ap_pin_disable(wpa_s);
1780 return os_snprintf(buf, buflen, "OK\n");
1781 }
1782
1783 if (os_strcmp(cmd, "random") == 0) {
1784 if (pos)
1785 timeout = atoi(pos);
1786 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1787 if (pin_txt == NULL)
1788 return -1;
1789 return os_snprintf(buf, buflen, "%s", pin_txt);
1790 }
1791
1792 if (os_strcmp(cmd, "get") == 0) {
1793 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1794 if (pin_txt == NULL)
1795 return -1;
1796 return os_snprintf(buf, buflen, "%s", pin_txt);
1797 }
1798
1799 if (os_strcmp(cmd, "set") == 0) {
1800 char *pin;
1801 if (pos == NULL)
1802 return -1;
1803 pin = pos;
1804 pos = os_strchr(pos, ' ');
1805 if (pos) {
1806 *pos++ = '\0';
1807 timeout = atoi(pos);
1808 }
1809 if (os_strlen(pin) > buflen)
1810 return -1;
1811 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1812 return -1;
1813 return os_snprintf(buf, buflen, "%s", pin);
1814 }
1815
1816 return -1;
1817}
1818#endif /* CONFIG_AP */
1819
1820
1821#ifdef CONFIG_WPS_ER
1822static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1823 char *cmd)
1824{
1825 char *uuid = cmd, *pin, *pos;
1826 u8 addr_buf[ETH_ALEN], *addr = NULL;
1827 pin = os_strchr(uuid, ' ');
1828 if (pin == NULL)
1829 return -1;
1830 *pin++ = '\0';
1831 pos = os_strchr(pin, ' ');
1832 if (pos) {
1833 *pos++ = '\0';
1834 if (hwaddr_aton(pos, addr_buf) == 0)
1835 addr = addr_buf;
1836 }
1837 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1838}
1839
1840
1841static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1842 char *cmd)
1843{
1844 char *uuid = cmd, *pin;
1845 pin = os_strchr(uuid, ' ');
1846 if (pin == NULL)
1847 return -1;
1848 *pin++ = '\0';
1849 return wpas_wps_er_learn(wpa_s, uuid, pin);
1850}
1851
1852
1853static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1854 struct wpa_supplicant *wpa_s, char *cmd)
1855{
1856 char *uuid = cmd, *id;
1857 id = os_strchr(uuid, ' ');
1858 if (id == NULL)
1859 return -1;
1860 *id++ = '\0';
1861 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1862}
1863
1864
1865static int wpa_supplicant_ctrl_iface_wps_er_config(
1866 struct wpa_supplicant *wpa_s, char *cmd)
1867{
1868 char *pin;
1869 char *new_ssid;
1870 char *new_auth;
1871 char *new_encr;
1872 char *new_key;
1873 struct wps_new_ap_settings ap;
1874
1875 pin = os_strchr(cmd, ' ');
1876 if (pin == NULL)
1877 return -1;
1878 *pin++ = '\0';
1879
1880 new_ssid = os_strchr(pin, ' ');
1881 if (new_ssid == NULL)
1882 return -1;
1883 *new_ssid++ = '\0';
1884
1885 new_auth = os_strchr(new_ssid, ' ');
1886 if (new_auth == NULL)
1887 return -1;
1888 *new_auth++ = '\0';
1889
1890 new_encr = os_strchr(new_auth, ' ');
1891 if (new_encr == NULL)
1892 return -1;
1893 *new_encr++ = '\0';
1894
1895 new_key = os_strchr(new_encr, ' ');
1896 if (new_key == NULL)
1897 return -1;
1898 *new_key++ = '\0';
1899
1900 os_memset(&ap, 0, sizeof(ap));
1901 ap.ssid_hex = new_ssid;
1902 ap.auth = new_auth;
1903 ap.encr = new_encr;
1904 ap.key_hex = new_key;
1905 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1906}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001907
1908
1909#ifdef CONFIG_WPS_NFC
1910static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1911 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1912{
1913 int ndef;
1914 struct wpabuf *buf;
1915 int res;
1916 char *uuid;
1917
1918 uuid = os_strchr(cmd, ' ');
1919 if (uuid == NULL)
1920 return -1;
1921 *uuid++ = '\0';
1922
1923 if (os_strcmp(cmd, "WPS") == 0)
1924 ndef = 0;
1925 else if (os_strcmp(cmd, "NDEF") == 0)
1926 ndef = 1;
1927 else
1928 return -1;
1929
1930 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1931 if (buf == NULL)
1932 return -1;
1933
1934 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1935 wpabuf_len(buf));
1936 reply[res++] = '\n';
1937 reply[res] = '\0';
1938
1939 wpabuf_free(buf);
1940
1941 return res;
1942}
1943#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001944#endif /* CONFIG_WPS_ER */
1945
1946#endif /* CONFIG_WPS */
1947
1948
1949#ifdef CONFIG_IBSS_RSN
1950static int wpa_supplicant_ctrl_iface_ibss_rsn(
1951 struct wpa_supplicant *wpa_s, char *addr)
1952{
1953 u8 peer[ETH_ALEN];
1954
1955 if (hwaddr_aton(addr, peer)) {
1956 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1957 "address '%s'", addr);
1958 return -1;
1959 }
1960
1961 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1962 MAC2STR(peer));
1963
1964 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1965}
1966#endif /* CONFIG_IBSS_RSN */
1967
1968
1969static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1970 char *rsp)
1971{
1972#ifdef IEEE8021X_EAPOL
1973 char *pos, *id_pos;
1974 int id;
1975 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001976
1977 pos = os_strchr(rsp, '-');
1978 if (pos == NULL)
1979 return -1;
1980 *pos++ = '\0';
1981 id_pos = pos;
1982 pos = os_strchr(pos, ':');
1983 if (pos == NULL)
1984 return -1;
1985 *pos++ = '\0';
1986 id = atoi(id_pos);
1987 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1988 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1989 (u8 *) pos, os_strlen(pos));
1990
1991 ssid = wpa_config_get_network(wpa_s->conf, id);
1992 if (ssid == NULL) {
1993 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1994 "to update", id);
1995 return -1;
1996 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001997
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001998 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1999 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002000#else /* IEEE8021X_EAPOL */
2001 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2002 return -1;
2003#endif /* IEEE8021X_EAPOL */
2004}
2005
2006
2007static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2008 const char *params,
2009 char *buf, size_t buflen)
2010{
2011 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002012 int res, verbose, wps, ret;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002013#ifdef CONFIG_HS20
2014 const u8 *hs20;
2015#endif /* CONFIG_HS20 */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002016 const u8 *sess_id;
2017 size_t sess_id_len;
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002018
Dmitry Shmidt56052862013-10-04 10:23:25 -07002019 if (os_strcmp(params, "-DRIVER") == 0)
2020 return wpa_drv_status(wpa_s, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002021 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002022 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002023 pos = buf;
2024 end = buf + buflen;
2025 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2026 struct wpa_ssid *ssid = wpa_s->current_ssid;
2027 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2028 MAC2STR(wpa_s->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002029 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002030 return pos - buf;
2031 pos += ret;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002032 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2033 wpa_s->assoc_freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002034 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002035 return pos - buf;
2036 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002037 if (ssid) {
2038 u8 *_ssid = ssid->ssid;
2039 size_t ssid_len = ssid->ssid_len;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002040 u8 ssid_buf[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002041 if (ssid_len == 0) {
2042 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2043 if (_res < 0)
2044 ssid_len = 0;
2045 else
2046 ssid_len = _res;
2047 _ssid = ssid_buf;
2048 }
2049 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2050 wpa_ssid_txt(_ssid, ssid_len),
2051 ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002052 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002053 return pos - buf;
2054 pos += ret;
2055
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002056 if (wps && ssid->passphrase &&
2057 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2058 (ssid->mode == WPAS_MODE_AP ||
2059 ssid->mode == WPAS_MODE_P2P_GO)) {
2060 ret = os_snprintf(pos, end - pos,
2061 "passphrase=%s\n",
2062 ssid->passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002063 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002064 return pos - buf;
2065 pos += ret;
2066 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002067 if (ssid->id_str) {
2068 ret = os_snprintf(pos, end - pos,
2069 "id_str=%s\n",
2070 ssid->id_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002071 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002072 return pos - buf;
2073 pos += ret;
2074 }
2075
2076 switch (ssid->mode) {
2077 case WPAS_MODE_INFRA:
2078 ret = os_snprintf(pos, end - pos,
2079 "mode=station\n");
2080 break;
2081 case WPAS_MODE_IBSS:
2082 ret = os_snprintf(pos, end - pos,
2083 "mode=IBSS\n");
2084 break;
2085 case WPAS_MODE_AP:
2086 ret = os_snprintf(pos, end - pos,
2087 "mode=AP\n");
2088 break;
2089 case WPAS_MODE_P2P_GO:
2090 ret = os_snprintf(pos, end - pos,
2091 "mode=P2P GO\n");
2092 break;
2093 case WPAS_MODE_P2P_GROUP_FORMATION:
2094 ret = os_snprintf(pos, end - pos,
2095 "mode=P2P GO - group "
2096 "formation\n");
2097 break;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002098 case WPAS_MODE_MESH:
2099 ret = os_snprintf(pos, end - pos,
2100 "mode=mesh\n");
2101 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002102 default:
2103 ret = 0;
2104 break;
2105 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002106 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002107 return pos - buf;
2108 pos += ret;
2109 }
2110
2111#ifdef CONFIG_AP
2112 if (wpa_s->ap_iface) {
2113 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2114 end - pos,
2115 verbose);
2116 } else
2117#endif /* CONFIG_AP */
2118 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2119 }
Paul Stewart092955c2017-02-06 09:13:09 -08002120#ifdef CONFIG_SME
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002121#ifdef CONFIG_SAE
2122 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002123#ifdef CONFIG_AP
2124 !wpa_s->ap_iface &&
2125#endif /* CONFIG_AP */
2126 wpa_s->sme.sae.state == SAE_ACCEPTED) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002127 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
2128 wpa_s->sme.sae.group);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002129 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002130 return pos - buf;
2131 pos += ret;
2132 }
2133#endif /* CONFIG_SAE */
Paul Stewart092955c2017-02-06 09:13:09 -08002134#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002135 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2136 wpa_supplicant_state_txt(wpa_s->wpa_state));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002137 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002138 return pos - buf;
2139 pos += ret;
2140
2141 if (wpa_s->l2 &&
2142 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2143 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002144 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002145 return pos - buf;
2146 pos += ret;
2147 }
2148
2149#ifdef CONFIG_P2P
2150 if (wpa_s->global->p2p) {
2151 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2152 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002153 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002154 return pos - buf;
2155 pos += ret;
2156 }
2157#endif /* CONFIG_P2P */
2158
2159 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2160 MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002161 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002162 return pos - buf;
2163 pos += ret;
2164
Dmitry Shmidt04949592012-07-19 12:16:46 -07002165#ifdef CONFIG_HS20
2166 if (wpa_s->current_bss &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002167 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2168 HS20_IE_VENDOR_TYPE)) &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002169 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2170 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002171 int release = 1;
2172 if (hs20[1] >= 5) {
2173 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2174 release = rel_num + 1;
2175 }
2176 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002177 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002178 return pos - buf;
2179 pos += ret;
2180 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002181
2182 if (wpa_s->current_ssid) {
2183 struct wpa_cred *cred;
2184 char *type;
2185
2186 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002187 size_t i;
2188
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002189 if (wpa_s->current_ssid->parent_cred != cred)
2190 continue;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002191
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002192 if (cred->provisioning_sp) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002193 ret = os_snprintf(pos, end - pos,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002194 "provisioning_sp=%s\n",
2195 cred->provisioning_sp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002196 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt051af732013-10-22 13:52:46 -07002197 return pos - buf;
2198 pos += ret;
2199 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002200
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002201 if (!cred->domain)
2202 goto no_domain;
2203
2204 i = 0;
2205 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2206 struct wpabuf *names =
2207 wpa_s->current_bss->anqp->domain_name;
2208 for (i = 0; names && i < cred->num_domain; i++)
2209 {
2210 if (domain_name_list_contains(
2211 names, cred->domain[i], 1))
2212 break;
2213 }
2214 if (i == cred->num_domain)
2215 i = 0; /* show first entry by default */
2216 }
2217 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2218 cred->domain[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002219 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002220 return pos - buf;
2221 pos += ret;
2222
2223 no_domain:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002224 if (wpa_s->current_bss == NULL ||
2225 wpa_s->current_bss->anqp == NULL)
2226 res = -1;
2227 else
2228 res = interworking_home_sp_cred(
2229 wpa_s, cred,
2230 wpa_s->current_bss->anqp->domain_name);
2231 if (res > 0)
2232 type = "home";
2233 else if (res == 0)
2234 type = "roaming";
2235 else
2236 type = "unknown";
2237
2238 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002239 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002240 return pos - buf;
2241 pos += ret;
2242
2243 break;
2244 }
2245 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002246#endif /* CONFIG_HS20 */
2247
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002248 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2249 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2250 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2251 verbose);
2252 if (res >= 0)
2253 pos += res;
2254 }
2255
Dmitry Shmidt29333592017-01-09 12:27:11 -08002256#ifdef CONFIG_MACSEC
2257 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2258 if (res > 0)
2259 pos += res;
2260#endif /* CONFIG_MACSEC */
2261
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002262 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2263 if (sess_id) {
2264 char *start = pos;
2265
2266 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2267 if (os_snprintf_error(end - pos, ret))
2268 return start - buf;
2269 pos += ret;
2270 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2271 if (ret <= 0)
2272 return start - buf;
2273 pos += ret;
2274 ret = os_snprintf(pos, end - pos, "\n");
2275 if (os_snprintf_error(end - pos, ret))
2276 return start - buf;
2277 pos += ret;
2278 }
2279
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002280 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2281 if (res >= 0)
2282 pos += res;
2283
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002284#ifdef CONFIG_WPS
2285 {
2286 char uuid_str[100];
2287 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2288 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002289 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002290 return pos - buf;
2291 pos += ret;
2292 }
2293#endif /* CONFIG_WPS */
2294
Roshan Pius3a1667e2018-07-03 15:17:14 -07002295 if (wpa_s->ieee80211ac) {
2296 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2297 if (os_snprintf_error(end - pos, ret))
2298 return pos - buf;
2299 pos += ret;
2300 }
2301
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002302#ifdef ANDROID
vandwalleffc70182014-09-11 11:40:14 -07002303 /*
2304 * Allow using the STATUS command with default behavior, say for debug,
2305 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2306 * events with STATUS-NO_EVENTS.
2307 */
2308 if (os_strcmp(params, "-NO_EVENTS")) {
2309 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2310 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2311 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2312 wpa_s->wpa_state,
2313 MAC2STR(wpa_s->bssid),
2314 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2315 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2316 wpa_s->current_ssid->ssid_len) : "");
2317 if (wpa_s->wpa_state == WPA_COMPLETED) {
2318 struct wpa_ssid *ssid = wpa_s->current_ssid;
2319 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2320 "- connection to " MACSTR
2321 " completed %s [id=%d id_str=%s]",
2322 MAC2STR(wpa_s->bssid), "(auth)",
2323 ssid ? ssid->id : -1,
2324 ssid && ssid->id_str ? ssid->id_str : "");
2325 }
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08002326 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002327#endif /* ANDROID */
2328
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002329 return pos - buf;
2330}
2331
2332
2333static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2334 char *cmd)
2335{
2336 char *pos;
2337 int id;
2338 struct wpa_ssid *ssid;
2339 u8 bssid[ETH_ALEN];
2340
2341 /* cmd: "<network id> <BSSID>" */
2342 pos = os_strchr(cmd, ' ');
2343 if (pos == NULL)
2344 return -1;
2345 *pos++ = '\0';
2346 id = atoi(cmd);
2347 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2348 if (hwaddr_aton(pos, bssid)) {
2349 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2350 return -1;
2351 }
2352
2353 ssid = wpa_config_get_network(wpa_s->conf, id);
2354 if (ssid == NULL) {
2355 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2356 "to update", id);
2357 return -1;
2358 }
2359
2360 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2361 ssid->bssid_set = !is_zero_ether_addr(bssid);
2362
2363 return 0;
2364}
2365
2366
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002367static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002368 char *cmd, char *buf,
2369 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002370{
2371 u8 bssid[ETH_ALEN];
2372 struct wpa_blacklist *e;
2373 char *pos, *end;
2374 int ret;
2375
2376 /* cmd: "BLACKLIST [<BSSID>]" */
2377 if (*cmd == '\0') {
2378 pos = buf;
2379 end = buf + buflen;
2380 e = wpa_s->blacklist;
2381 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002382 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2383 MAC2STR(e->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002384 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002385 return pos - buf;
2386 pos += ret;
2387 e = e->next;
2388 }
2389 return pos - buf;
2390 }
2391
2392 cmd++;
2393 if (os_strncmp(cmd, "clear", 5) == 0) {
2394 wpa_blacklist_clear(wpa_s);
2395 os_memcpy(buf, "OK\n", 3);
2396 return 3;
2397 }
2398
2399 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
2400 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002401 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002402 return -1;
2403 }
2404
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002405 /*
2406 * Add the BSSID twice, so its count will be 2, causing it to be
2407 * skipped when processing scan results.
2408 */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002409 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002410 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002411 return -1;
2412 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002413 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002414 return -1;
2415 os_memcpy(buf, "OK\n", 3);
2416 return 3;
2417}
2418
2419
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002420static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2421 char *cmd, char *buf,
2422 size_t buflen)
2423{
2424 char *pos, *end, *stamp;
2425 int ret;
2426
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002427 /* cmd: "LOG_LEVEL [<level>]" */
2428 if (*cmd == '\0') {
2429 pos = buf;
2430 end = buf + buflen;
2431 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2432 "Timestamp: %d\n",
2433 debug_level_str(wpa_debug_level),
2434 wpa_debug_timestamp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002435 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002436 ret = 0;
2437
2438 return ret;
2439 }
2440
2441 while (*cmd == ' ')
2442 cmd++;
2443
2444 stamp = os_strchr(cmd, ' ');
2445 if (stamp) {
2446 *stamp++ = '\0';
2447 while (*stamp == ' ') {
2448 stamp++;
2449 }
2450 }
2451
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002452 if (os_strlen(cmd)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002453 int level = str_to_debug_level(cmd);
2454 if (level < 0)
2455 return -1;
2456 wpa_debug_level = level;
2457 }
2458
2459 if (stamp && os_strlen(stamp))
2460 wpa_debug_timestamp = atoi(stamp);
2461
2462 os_memcpy(buf, "OK\n", 3);
2463 return 3;
2464}
2465
2466
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002467static int wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002468 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002469{
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002470 char *pos, *end, *prev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002471 struct wpa_ssid *ssid;
2472 int ret;
2473
2474 pos = buf;
2475 end = buf + buflen;
2476 ret = os_snprintf(pos, end - pos,
2477 "network id / ssid / bssid / flags\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002478 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002479 return pos - buf;
2480 pos += ret;
2481
2482 ssid = wpa_s->conf->ssid;
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002483
2484 /* skip over ssids until we find next one */
2485 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2486 int last_id = atoi(cmd + 8);
2487 if (last_id != -1) {
2488 while (ssid != NULL && ssid->id <= last_id) {
2489 ssid = ssid->next;
2490 }
2491 }
2492 }
2493
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002494 while (ssid) {
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002495 prev = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002496 ret = os_snprintf(pos, end - pos, "%d\t%s",
2497 ssid->id,
2498 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002499 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002500 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002501 pos += ret;
2502 if (ssid->bssid_set) {
2503 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2504 MAC2STR(ssid->bssid));
2505 } else {
2506 ret = os_snprintf(pos, end - pos, "\tany");
2507 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002508 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002509 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002510 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002511 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002512 ssid == wpa_s->current_ssid ?
2513 "[CURRENT]" : "",
2514 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002515 ssid->disabled_until.sec ?
2516 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002517 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2518 "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002519 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002520 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002521 pos += ret;
2522 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002523 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002524 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002525 pos += ret;
2526
2527 ssid = ssid->next;
2528 }
2529
2530 return pos - buf;
2531}
2532
2533
2534static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2535{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002536 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002537 ret = os_snprintf(pos, end - pos, "-");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002538 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002539 return pos;
2540 pos += ret;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002541 ret = wpa_write_ciphers(pos, end, cipher, "+");
2542 if (ret < 0)
2543 return pos;
2544 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002545 return pos;
2546}
2547
2548
2549static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2550 const u8 *ie, size_t ie_len)
2551{
2552 struct wpa_ie_data data;
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002553 char *start;
2554 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002555
2556 ret = os_snprintf(pos, end - pos, "[%s-", proto);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002557 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002558 return pos;
2559 pos += ret;
2560
2561 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2562 ret = os_snprintf(pos, end - pos, "?]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002563 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002564 return pos;
2565 pos += ret;
2566 return pos;
2567 }
2568
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002569 start = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002570 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002571 ret = os_snprintf(pos, end - pos, "%sEAP",
2572 pos == start ? "" : "+");
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;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002576 }
2577 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002578 ret = os_snprintf(pos, end - pos, "%sPSK",
2579 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002580 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002581 return pos;
2582 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002583 }
2584 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002585 ret = os_snprintf(pos, end - pos, "%sNone",
2586 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002587 if (os_snprintf_error(end - pos, ret))
2588 return pos;
2589 pos += ret;
2590 }
2591 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2592 ret = os_snprintf(pos, end - pos, "%sSAE",
2593 pos == start ? "" : "+");
2594 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002595 return pos;
2596 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002597 }
2598#ifdef CONFIG_IEEE80211R
2599 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2600 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002601 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002602 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002603 return pos;
2604 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002605 }
2606 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2607 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002608 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002609 if (os_snprintf_error(end - pos, ret))
2610 return pos;
2611 pos += ret;
2612 }
2613 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2614 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2615 pos == start ? "" : "+");
2616 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002617 return pos;
2618 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002619 }
2620#endif /* CONFIG_IEEE80211R */
2621#ifdef CONFIG_IEEE80211W
2622 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2623 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002624 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002625 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002626 return pos;
2627 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002628 }
2629 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2630 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002631 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002632 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002633 return pos;
2634 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002635 }
2636#endif /* CONFIG_IEEE80211W */
2637
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002638#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002639 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2640 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2641 pos == start ? "" : "+");
2642 if (os_snprintf_error(end - pos, ret))
2643 return pos;
2644 pos += ret;
2645 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002646#endif /* CONFIG_SUITEB */
2647
2648#ifdef CONFIG_SUITEB192
2649 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2650 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2651 pos == start ? "" : "+");
2652 if (os_snprintf_error(end - pos, ret))
2653 return pos;
2654 pos += ret;
2655 }
2656#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002657
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002658#ifdef CONFIG_FILS
2659 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2660 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2661 pos == start ? "" : "+");
2662 if (os_snprintf_error(end - pos, ret))
2663 return pos;
2664 pos += ret;
2665 }
2666 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2667 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2668 pos == start ? "" : "+");
2669 if (os_snprintf_error(end - pos, ret))
2670 return pos;
2671 pos += ret;
2672 }
2673#ifdef CONFIG_IEEE80211R
2674 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2675 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2676 pos == start ? "" : "+");
2677 if (os_snprintf_error(end - pos, ret))
2678 return pos;
2679 pos += ret;
2680 }
2681 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2682 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2683 pos == start ? "" : "+");
2684 if (os_snprintf_error(end - pos, ret))
2685 return pos;
2686 pos += ret;
2687 }
2688#endif /* CONFIG_IEEE80211R */
2689#endif /* CONFIG_FILS */
2690
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002691#ifdef CONFIG_OWE
2692 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2693 ret = os_snprintf(pos, end - pos, "%sOWE",
2694 pos == start ? "" : "+");
2695 if (os_snprintf_error(end - pos, ret))
2696 return pos;
2697 pos += ret;
2698 }
2699#endif /* CONFIG_OWE */
2700
2701#ifdef CONFIG_DPP
2702 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
2703 ret = os_snprintf(pos, end - pos, "%sDPP",
2704 pos == start ? "" : "+");
2705 if (os_snprintf_error(end - pos, ret))
2706 return pos;
2707 pos += ret;
2708 }
2709#endif /* CONFIG_DPP */
2710
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002711 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2712 ret = os_snprintf(pos, end - pos, "%sOSEN",
2713 pos == start ? "" : "+");
2714 if (os_snprintf_error(end - pos, ret))
2715 return pos;
2716 pos += ret;
2717 }
2718
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002719 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2720
2721 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2722 ret = os_snprintf(pos, end - pos, "-preauth");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002723 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002724 return pos;
2725 pos += ret;
2726 }
2727
2728 ret = os_snprintf(pos, end - pos, "]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002729 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002730 return pos;
2731 pos += ret;
2732
2733 return pos;
2734}
2735
2736
2737#ifdef CONFIG_WPS
2738static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2739 char *pos, char *end,
2740 struct wpabuf *wps_ie)
2741{
2742 int ret;
2743 const char *txt;
2744
2745 if (wps_ie == NULL)
2746 return pos;
2747 if (wps_is_selected_pbc_registrar(wps_ie))
2748 txt = "[WPS-PBC]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002749 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2750 txt = "[WPS-AUTH]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002751 else if (wps_is_selected_pin_registrar(wps_ie))
2752 txt = "[WPS-PIN]";
2753 else
2754 txt = "[WPS]";
2755
2756 ret = os_snprintf(pos, end - pos, "%s", txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002757 if (!os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002758 pos += ret;
2759 wpabuf_free(wps_ie);
2760 return pos;
2761}
2762#endif /* CONFIG_WPS */
2763
2764
2765static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2766 char *pos, char *end,
2767 const struct wpa_bss *bss)
2768{
2769#ifdef CONFIG_WPS
2770 struct wpabuf *wps_ie;
2771 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2772 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2773#else /* CONFIG_WPS */
2774 return pos;
2775#endif /* CONFIG_WPS */
2776}
2777
2778
2779/* Format one result on one text line into a buffer. */
2780static int wpa_supplicant_ctrl_iface_scan_result(
2781 struct wpa_supplicant *wpa_s,
2782 const struct wpa_bss *bss, char *buf, size_t buflen)
2783{
2784 char *pos, *end;
2785 int ret;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002786 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002787
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002788 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002789 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07002790 if (!p2p)
2791 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002792 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2793 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2794 0)
2795 return 0; /* Do not show P2P listen discovery results here */
2796
2797 pos = buf;
2798 end = buf + buflen;
2799
2800 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2801 MAC2STR(bss->bssid), bss->freq, bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002802 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002803 return -1;
2804 pos += ret;
2805 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2806 if (ie)
2807 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2808 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002809 if (ie2) {
2810 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2811 ie2, 2 + ie2[1]);
2812 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002813 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
2814 if (osen_ie)
2815 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
2816 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002817 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
2818 if (owe) {
2819 ret = os_snprintf(pos, end - pos,
2820 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2821 if (os_snprintf_error(end - pos, ret))
2822 return -1;
2823 pos += ret;
2824 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002825 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002826 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002827 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002828 if (os_snprintf_error(end - pos, ret))
2829 return -1;
2830 pos += ret;
2831 }
2832 if (mesh) {
2833 ret = os_snprintf(pos, end - pos, "[MESH]");
2834 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002835 return -1;
2836 pos += ret;
2837 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002838 if (bss_is_dmg(bss)) {
2839 const char *s;
2840 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002841 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002842 return -1;
2843 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002844 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2845 case IEEE80211_CAP_DMG_IBSS:
2846 s = "[IBSS]";
2847 break;
2848 case IEEE80211_CAP_DMG_AP:
2849 s = "[ESS]";
2850 break;
2851 case IEEE80211_CAP_DMG_PBSS:
2852 s = "[PBSS]";
2853 break;
2854 default:
2855 s = "";
2856 break;
2857 }
2858 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002859 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002860 return -1;
2861 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002862 } else {
2863 if (bss->caps & IEEE80211_CAP_IBSS) {
2864 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002865 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002866 return -1;
2867 pos += ret;
2868 }
2869 if (bss->caps & IEEE80211_CAP_ESS) {
2870 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002871 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002872 return -1;
2873 pos += ret;
2874 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002875 }
2876 if (p2p) {
2877 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002878 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002879 return -1;
2880 pos += ret;
2881 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002882#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002883 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002884 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002885 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002886 return -1;
2887 pos += ret;
2888 }
2889#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002890#ifdef CONFIG_FILS
2891 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
2892 ret = os_snprintf(pos, end - pos, "[FILS]");
2893 if (os_snprintf_error(end - pos, ret))
2894 return -1;
2895 pos += ret;
2896 }
2897#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002898#ifdef CONFIG_FST
2899 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
2900 ret = os_snprintf(pos, end - pos, "[FST]");
2901 if (os_snprintf_error(end - pos, ret))
2902 return -1;
2903 pos += ret;
2904 }
2905#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002906
2907 ret = os_snprintf(pos, end - pos, "\t%s",
2908 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002909 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002910 return -1;
2911 pos += ret;
2912
2913 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002914 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002915 return -1;
2916 pos += ret;
2917
2918 return pos - buf;
2919}
2920
2921
2922static int wpa_supplicant_ctrl_iface_scan_results(
2923 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2924{
2925 char *pos, *end;
2926 struct wpa_bss *bss;
2927 int ret;
2928
2929 pos = buf;
2930 end = buf + buflen;
2931 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2932 "flags / ssid\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002933 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002934 return pos - buf;
2935 pos += ret;
2936
2937 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2938 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2939 end - pos);
2940 if (ret < 0 || ret >= end - pos)
2941 return pos - buf;
2942 pos += ret;
2943 }
2944
2945 return pos - buf;
2946}
2947
2948
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002949#ifdef CONFIG_MESH
2950
2951static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2952 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2953{
2954 char *pos, ifname[IFNAMSIZ + 1];
2955
2956 ifname[0] = '\0';
2957
2958 pos = os_strstr(cmd, "ifname=");
2959 if (pos) {
2960 pos += 7;
2961 os_strlcpy(ifname, pos, sizeof(ifname));
2962 }
2963
2964 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
2965 return -1;
2966
2967 os_strlcpy(reply, ifname, max_len);
2968 return os_strlen(ifname);
2969}
2970
2971
2972static int wpa_supplicant_ctrl_iface_mesh_group_add(
2973 struct wpa_supplicant *wpa_s, char *cmd)
2974{
2975 int id;
2976 struct wpa_ssid *ssid;
2977
2978 id = atoi(cmd);
2979 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
2980
2981 ssid = wpa_config_get_network(wpa_s->conf, id);
2982 if (ssid == NULL) {
2983 wpa_printf(MSG_DEBUG,
2984 "CTRL_IFACE: Could not find network id=%d", id);
2985 return -1;
2986 }
2987 if (ssid->mode != WPAS_MODE_MESH) {
2988 wpa_printf(MSG_DEBUG,
2989 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2990 return -1;
2991 }
2992 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
2993 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
2994 wpa_printf(MSG_ERROR,
2995 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2996 return -1;
2997 }
2998
2999 /*
3000 * TODO: If necessary write our own group_add function,
3001 * for now we can reuse select_network
3002 */
3003 wpa_supplicant_select_network(wpa_s, ssid);
3004
3005 return 0;
3006}
3007
3008
3009static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3010 struct wpa_supplicant *wpa_s, char *cmd)
3011{
3012 struct wpa_supplicant *orig;
3013 struct wpa_global *global;
3014 int found = 0;
3015
3016 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3017
3018 global = wpa_s->global;
3019 orig = wpa_s;
3020
3021 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3022 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3023 found = 1;
3024 break;
3025 }
3026 }
3027 if (!found) {
3028 wpa_printf(MSG_ERROR,
3029 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3030 cmd);
3031 return -1;
3032 }
3033 if (wpa_s->mesh_if_created && wpa_s == orig) {
3034 wpa_printf(MSG_ERROR,
3035 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3036 return -1;
3037 }
3038
3039 wpa_s->reassociate = 0;
3040 wpa_s->disconnected = 1;
3041 wpa_supplicant_cancel_sched_scan(wpa_s);
3042 wpa_supplicant_cancel_scan(wpa_s);
3043
3044 /*
3045 * TODO: If necessary write our own group_remove function,
3046 * for now we can reuse deauthenticate
3047 */
3048 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3049
3050 if (wpa_s->mesh_if_created)
3051 wpa_supplicant_remove_iface(global, wpa_s, 0);
3052
3053 return 0;
3054}
3055
Dmitry Shmidte4663042016-04-04 10:07:49 -07003056
3057static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3058 struct wpa_supplicant *wpa_s, char *cmd)
3059{
3060 u8 addr[ETH_ALEN];
3061
3062 if (hwaddr_aton(cmd, addr) < 0)
3063 return -1;
3064
3065 return wpas_mesh_peer_remove(wpa_s, addr);
3066}
3067
3068
3069static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3070 struct wpa_supplicant *wpa_s, char *cmd)
3071{
3072 u8 addr[ETH_ALEN];
3073 int duration;
3074 char *pos;
3075
3076 pos = os_strstr(cmd, " duration=");
3077 if (pos) {
3078 *pos = '\0';
3079 duration = atoi(pos + 10);
3080 } else {
3081 duration = -1;
3082 }
3083
3084 if (hwaddr_aton(cmd, addr))
3085 return -1;
3086
3087 return wpas_mesh_peer_add(wpa_s, addr, duration);
3088}
3089
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003090#endif /* CONFIG_MESH */
3091
3092
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003093static int wpa_supplicant_ctrl_iface_select_network(
3094 struct wpa_supplicant *wpa_s, char *cmd)
3095{
3096 int id;
3097 struct wpa_ssid *ssid;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003098 char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003099
3100 /* cmd: "<network id>" or "any" */
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003101 if (os_strncmp(cmd, "any", 3) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003102 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3103 ssid = NULL;
3104 } else {
3105 id = atoi(cmd);
3106 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3107
3108 ssid = wpa_config_get_network(wpa_s->conf, id);
3109 if (ssid == NULL) {
3110 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3111 "network id=%d", id);
3112 return -1;
3113 }
3114 if (ssid->disabled == 2) {
3115 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3116 "SELECT_NETWORK with persistent P2P group");
3117 return -1;
3118 }
3119 }
3120
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003121 pos = os_strstr(cmd, " freq=");
3122 if (pos) {
3123 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3124 if (freqs) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003125 os_free(wpa_s->select_network_scan_freqs);
3126 wpa_s->select_network_scan_freqs = freqs;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003127 }
3128 }
3129
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003130 wpa_s->scan_min_time.sec = 0;
3131 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003132 wpa_supplicant_select_network(wpa_s, ssid);
3133
3134 return 0;
3135}
3136
3137
3138static int wpa_supplicant_ctrl_iface_enable_network(
3139 struct wpa_supplicant *wpa_s, char *cmd)
3140{
3141 int id;
3142 struct wpa_ssid *ssid;
3143
3144 /* cmd: "<network id>" or "all" */
3145 if (os_strcmp(cmd, "all") == 0) {
3146 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3147 ssid = NULL;
3148 } else {
3149 id = atoi(cmd);
3150 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3151
3152 ssid = wpa_config_get_network(wpa_s->conf, id);
3153 if (ssid == NULL) {
3154 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3155 "network id=%d", id);
3156 return -1;
3157 }
3158 if (ssid->disabled == 2) {
3159 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3160 "ENABLE_NETWORK with persistent P2P group");
3161 return -1;
3162 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003163
3164 if (os_strstr(cmd, " no-connect")) {
3165 ssid->disabled = 0;
3166 return 0;
3167 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003168 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003169 wpa_s->scan_min_time.sec = 0;
3170 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003171 wpa_supplicant_enable_network(wpa_s, ssid);
3172
3173 return 0;
3174}
3175
3176
3177static int wpa_supplicant_ctrl_iface_disable_network(
3178 struct wpa_supplicant *wpa_s, char *cmd)
3179{
3180 int id;
3181 struct wpa_ssid *ssid;
3182
3183 /* cmd: "<network id>" or "all" */
3184 if (os_strcmp(cmd, "all") == 0) {
3185 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3186 ssid = NULL;
3187 } else {
3188 id = atoi(cmd);
3189 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3190
3191 ssid = wpa_config_get_network(wpa_s->conf, id);
3192 if (ssid == NULL) {
3193 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3194 "network id=%d", id);
3195 return -1;
3196 }
3197 if (ssid->disabled == 2) {
3198 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3199 "DISABLE_NETWORK with persistent P2P "
3200 "group");
3201 return -1;
3202 }
3203 }
3204 wpa_supplicant_disable_network(wpa_s, ssid);
3205
3206 return 0;
3207}
3208
3209
3210static int wpa_supplicant_ctrl_iface_add_network(
3211 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3212{
3213 struct wpa_ssid *ssid;
3214 int ret;
3215
3216 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3217
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003218 ssid = wpa_supplicant_add_network(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003219 if (ssid == NULL)
3220 return -1;
3221
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003222 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003223 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003224 return -1;
3225 return ret;
3226}
3227
3228
3229static int wpa_supplicant_ctrl_iface_remove_network(
3230 struct wpa_supplicant *wpa_s, char *cmd)
3231{
3232 int id;
3233 struct wpa_ssid *ssid;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003234 int result;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003235
3236 /* cmd: "<network id>" or "all" */
3237 if (os_strcmp(cmd, "all") == 0) {
3238 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003239 if (wpa_s->sched_scanning)
3240 wpa_supplicant_cancel_sched_scan(wpa_s);
3241
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003242 eapol_sm_invalidate_cached_session(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003243 if (wpa_s->current_ssid) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003244#ifdef CONFIG_SME
3245 wpa_s->sme.prev_bssid_set = 0;
3246#endif /* CONFIG_SME */
Jouni Malinen75ecf522011-06-27 15:19:46 -07003247 wpa_sm_set_config(wpa_s->wpa, NULL);
3248 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07003249 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3250 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003251 wpa_supplicant_deauthenticate(
3252 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003253 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003254 ssid = wpa_s->conf->ssid;
3255 while (ssid) {
3256 struct wpa_ssid *remove_ssid = ssid;
3257 id = ssid->id;
3258 ssid = ssid->next;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003259 if (wpa_s->last_ssid == remove_ssid)
3260 wpa_s->last_ssid = NULL;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003261 wpas_notify_network_removed(wpa_s, remove_ssid);
3262 wpa_config_remove_network(wpa_s->conf, id);
3263 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003264 return 0;
3265 }
3266
3267 id = atoi(cmd);
3268 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3269
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003270 result = wpa_supplicant_remove_network(wpa_s, id);
3271 if (result == -1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003272 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3273 "id=%d", id);
3274 return -1;
3275 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003276 if (result == -2) {
Deepthi Gowria831d782012-09-03 11:55:38 +03003277 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3278 "network id=%d", id);
3279 return -1;
3280 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003281 return 0;
3282}
3283
3284
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003285static int wpa_supplicant_ctrl_iface_update_network(
3286 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3287 char *name, char *value)
3288{
Dmitry Shmidte4663042016-04-04 10:07:49 -07003289 int ret;
3290
3291 ret = wpa_config_set(ssid, name, value, 0);
3292 if (ret < 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003293 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3294 "variable '%s'", name);
3295 return -1;
3296 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07003297 if (ret == 1)
3298 return 0; /* No change to the previously configured value */
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003299
3300 if (os_strcmp(name, "bssid") != 0 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003301 os_strcmp(name, "bssid_hint") != 0 &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003302 os_strcmp(name, "priority") != 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003303 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3304
Dmitry Shmidte4663042016-04-04 10:07:49 -07003305 if (wpa_s->current_ssid == ssid ||
3306 wpa_s->current_ssid == NULL) {
3307 /*
3308 * Invalidate the EAP session cache if anything in the
3309 * current or previously used configuration changes.
3310 */
3311 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3312 }
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003313 }
3314
3315 if ((os_strcmp(name, "psk") == 0 &&
3316 value[0] == '"' && ssid->ssid_len) ||
3317 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3318 wpa_config_update_psk(ssid);
3319 else if (os_strcmp(name, "priority") == 0)
3320 wpa_config_update_prio_list(wpa_s->conf);
3321
3322 return 0;
3323}
3324
3325
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003326static int wpa_supplicant_ctrl_iface_set_network(
3327 struct wpa_supplicant *wpa_s, char *cmd)
3328{
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003329 int id, ret, prev_bssid_set, prev_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003330 struct wpa_ssid *ssid;
3331 char *name, *value;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003332 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003333
3334 /* cmd: "<network id> <variable name> <value>" */
3335 name = os_strchr(cmd, ' ');
3336 if (name == NULL)
3337 return -1;
3338 *name++ = '\0';
3339
3340 value = os_strchr(name, ' ');
3341 if (value == NULL)
3342 return -1;
3343 *value++ = '\0';
3344
3345 id = atoi(cmd);
3346 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3347 id, name);
3348 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3349 (u8 *) value, os_strlen(value));
3350
3351 ssid = wpa_config_get_network(wpa_s->conf, id);
3352 if (ssid == NULL) {
3353 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3354 "id=%d", id);
3355 return -1;
3356 }
3357
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003358 prev_bssid_set = ssid->bssid_set;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003359 prev_disabled = ssid->disabled;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003360 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3361 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3362 value);
3363 if (ret == 0 &&
3364 (ssid->bssid_set != prev_bssid_set ||
3365 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3366 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003367
3368 if (prev_disabled != ssid->disabled &&
3369 (prev_disabled == 2 || ssid->disabled == 2))
3370 wpas_notify_network_type_changed(wpa_s, ssid);
3371
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003372 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003373}
3374
3375
3376static int wpa_supplicant_ctrl_iface_get_network(
3377 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3378{
3379 int id;
3380 size_t res;
3381 struct wpa_ssid *ssid;
3382 char *name, *value;
3383
3384 /* cmd: "<network id> <variable name>" */
3385 name = os_strchr(cmd, ' ');
3386 if (name == NULL || buflen == 0)
3387 return -1;
3388 *name++ = '\0';
3389
3390 id = atoi(cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003391 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003392 id, name);
3393
3394 ssid = wpa_config_get_network(wpa_s->conf, id);
3395 if (ssid == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003396 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003397 "id=%d", id);
3398 return -1;
3399 }
3400
3401 value = wpa_config_get_no_key(ssid, name);
3402 if (value == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003403 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003404 "variable '%s'", name);
3405 return -1;
3406 }
3407
3408 res = os_strlcpy(buf, value, buflen);
3409 if (res >= buflen) {
3410 os_free(value);
3411 return -1;
3412 }
3413
3414 os_free(value);
3415
3416 return res;
3417}
3418
3419
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003420static int wpa_supplicant_ctrl_iface_dup_network(
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003421 struct wpa_supplicant *wpa_s, char *cmd,
3422 struct wpa_supplicant *dst_wpa_s)
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003423{
3424 struct wpa_ssid *ssid_s, *ssid_d;
3425 char *name, *id, *value;
3426 int id_s, id_d, ret;
3427
3428 /* cmd: "<src network id> <dst network id> <variable name>" */
3429 id = os_strchr(cmd, ' ');
3430 if (id == NULL)
3431 return -1;
3432 *id++ = '\0';
3433
3434 name = os_strchr(id, ' ');
3435 if (name == NULL)
3436 return -1;
3437 *name++ = '\0';
3438
3439 id_s = atoi(cmd);
3440 id_d = atoi(id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003441
3442 wpa_printf(MSG_DEBUG,
3443 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3444 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003445
3446 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3447 if (ssid_s == NULL) {
3448 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3449 "network id=%d", id_s);
3450 return -1;
3451 }
3452
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003453 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003454 if (ssid_d == NULL) {
3455 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003456 "network id=%d", id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003457 return -1;
3458 }
3459
3460 value = wpa_config_get(ssid_s, name);
3461 if (value == NULL) {
3462 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3463 "variable '%s'", name);
3464 return -1;
3465 }
3466
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003467 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003468 value);
3469
3470 os_free(value);
3471
3472 return ret;
3473}
3474
3475
Dmitry Shmidt04949592012-07-19 12:16:46 -07003476static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3477 char *buf, size_t buflen)
3478{
3479 char *pos, *end;
3480 struct wpa_cred *cred;
3481 int ret;
3482
3483 pos = buf;
3484 end = buf + buflen;
3485 ret = os_snprintf(pos, end - pos,
3486 "cred id / realm / username / domain / imsi\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003487 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003488 return pos - buf;
3489 pos += ret;
3490
3491 cred = wpa_s->conf->cred;
3492 while (cred) {
3493 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3494 cred->id, cred->realm ? cred->realm : "",
3495 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07003496 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003497 cred->imsi ? cred->imsi : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003498 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003499 return pos - buf;
3500 pos += ret;
3501
3502 cred = cred->next;
3503 }
3504
3505 return pos - buf;
3506}
3507
3508
3509static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3510 char *buf, size_t buflen)
3511{
3512 struct wpa_cred *cred;
3513 int ret;
3514
3515 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3516
3517 cred = wpa_config_add_cred(wpa_s->conf);
3518 if (cred == NULL)
3519 return -1;
3520
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003521 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3522
Dmitry Shmidt04949592012-07-19 12:16:46 -07003523 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003524 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003525 return -1;
3526 return ret;
3527}
3528
3529
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003530static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
3531 struct wpa_cred *cred)
3532{
3533 struct wpa_ssid *ssid;
3534 char str[20];
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003535 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003536
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003537 if (cred == NULL) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003538 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3539 return -1;
3540 }
3541
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003542 id = cred->id;
3543 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
3544 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3545 return -1;
3546 }
3547
3548 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
3549
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003550 /* Remove any network entry created based on the removed credential */
3551 ssid = wpa_s->conf->ssid;
3552 while (ssid) {
3553 if (ssid->parent_cred == cred) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003554 int res;
3555
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003556 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
3557 "used the removed credential", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003558 res = os_snprintf(str, sizeof(str), "%d", ssid->id);
3559 if (os_snprintf_error(sizeof(str), res))
3560 str[sizeof(str) - 1] = '\0';
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003561 ssid = ssid->next;
3562 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
3563 } else
3564 ssid = ssid->next;
3565 }
3566
3567 return 0;
3568}
3569
3570
Dmitry Shmidt04949592012-07-19 12:16:46 -07003571static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3572 char *cmd)
3573{
3574 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003575 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003576
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003577 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3578 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003579 if (os_strcmp(cmd, "all") == 0) {
3580 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3581 cred = wpa_s->conf->cred;
3582 while (cred) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003583 prev = cred;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003584 cred = cred->next;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003585 wpas_ctrl_remove_cred(wpa_s, prev);
3586 }
3587 return 0;
3588 }
3589
3590 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3591 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3592 cmd + 8);
3593 cred = wpa_s->conf->cred;
3594 while (cred) {
3595 prev = cred;
3596 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003597 if (prev->domain) {
3598 size_t i;
3599 for (i = 0; i < prev->num_domain; i++) {
3600 if (os_strcmp(prev->domain[i], cmd + 8)
3601 != 0)
3602 continue;
3603 wpas_ctrl_remove_cred(wpa_s, prev);
3604 break;
3605 }
3606 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003607 }
3608 return 0;
3609 }
3610
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003611 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3612 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3613 cmd + 16);
3614 cred = wpa_s->conf->cred;
3615 while (cred) {
3616 prev = cred;
3617 cred = cred->next;
3618 if (prev->provisioning_sp &&
3619 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3620 wpas_ctrl_remove_cred(wpa_s, prev);
3621 }
3622 return 0;
3623 }
3624
Dmitry Shmidt04949592012-07-19 12:16:46 -07003625 id = atoi(cmd);
3626 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3627
3628 cred = wpa_config_get_cred(wpa_s->conf, id);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003629 return wpas_ctrl_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003630}
3631
3632
3633static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3634 char *cmd)
3635{
3636 int id;
3637 struct wpa_cred *cred;
3638 char *name, *value;
3639
3640 /* cmd: "<cred id> <variable name> <value>" */
3641 name = os_strchr(cmd, ' ');
3642 if (name == NULL)
3643 return -1;
3644 *name++ = '\0';
3645
3646 value = os_strchr(name, ' ');
3647 if (value == NULL)
3648 return -1;
3649 *value++ = '\0';
3650
3651 id = atoi(cmd);
3652 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3653 id, name);
3654 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3655 (u8 *) value, os_strlen(value));
3656
3657 cred = wpa_config_get_cred(wpa_s->conf, id);
3658 if (cred == NULL) {
3659 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3660 id);
3661 return -1;
3662 }
3663
3664 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3665 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3666 "variable '%s'", name);
3667 return -1;
3668 }
3669
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003670 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3671
Dmitry Shmidt04949592012-07-19 12:16:46 -07003672 return 0;
3673}
3674
3675
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003676static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3677 char *cmd, char *buf,
3678 size_t buflen)
3679{
3680 int id;
3681 size_t res;
3682 struct wpa_cred *cred;
3683 char *name, *value;
3684
3685 /* cmd: "<cred id> <variable name>" */
3686 name = os_strchr(cmd, ' ');
3687 if (name == NULL)
3688 return -1;
3689 *name++ = '\0';
3690
3691 id = atoi(cmd);
3692 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3693 id, name);
3694
3695 cred = wpa_config_get_cred(wpa_s->conf, id);
3696 if (cred == NULL) {
3697 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3698 id);
3699 return -1;
3700 }
3701
3702 value = wpa_config_get_cred_no_key(cred, name);
3703 if (value == NULL) {
3704 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3705 name);
3706 return -1;
3707 }
3708
3709 res = os_strlcpy(buf, value, buflen);
3710 if (res >= buflen) {
3711 os_free(value);
3712 return -1;
3713 }
3714
3715 os_free(value);
3716
3717 return res;
3718}
3719
3720
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003721#ifndef CONFIG_NO_CONFIG_WRITE
3722static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3723{
3724 int ret;
3725
3726 if (!wpa_s->conf->update_config) {
3727 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3728 "to update configuration (update_config=0)");
3729 return -1;
3730 }
3731
3732 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3733 if (ret) {
3734 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3735 "update configuration");
3736 } else {
3737 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3738 " updated");
3739 }
3740
3741 return ret;
3742}
3743#endif /* CONFIG_NO_CONFIG_WRITE */
3744
3745
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003746struct cipher_info {
3747 unsigned int capa;
3748 const char *name;
3749 int group_only;
3750};
3751
3752static const struct cipher_info ciphers[] = {
3753 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3754 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3755 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3756 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3757 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3758 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3759 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3760 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3761};
3762
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003763static const struct cipher_info ciphers_group_mgmt[] = {
3764 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
3765 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
3766 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
3767 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
3768};
3769
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003770
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003771static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3772 struct wpa_driver_capa *capa,
3773 char *buf, size_t buflen)
3774{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003775 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003776 char *pos, *end;
3777 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003778 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003779
3780 pos = buf;
3781 end = pos + buflen;
3782
3783 if (res < 0) {
3784 if (strict)
3785 return 0;
3786 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3787 if (len >= buflen)
3788 return -1;
3789 return len;
3790 }
3791
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003792 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3793 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3794 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003795 pos == buf ? "" : " ",
3796 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003797 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003798 return pos - buf;
3799 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003800 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003801 }
3802
3803 return pos - buf;
3804}
3805
3806
3807static int ctrl_iface_get_capability_group(int res, char *strict,
3808 struct wpa_driver_capa *capa,
3809 char *buf, size_t buflen)
3810{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003811 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003812 char *pos, *end;
3813 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003814 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003815
3816 pos = buf;
3817 end = pos + buflen;
3818
3819 if (res < 0) {
3820 if (strict)
3821 return 0;
3822 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3823 if (len >= buflen)
3824 return -1;
3825 return len;
3826 }
3827
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003828 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3829 if (capa->enc & ciphers[i].capa) {
3830 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003831 pos == buf ? "" : " ",
3832 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003833 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003834 return pos - buf;
3835 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003836 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003837 }
3838
3839 return pos - buf;
3840}
3841
3842
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003843static int ctrl_iface_get_capability_group_mgmt(int res, char *strict,
3844 struct wpa_driver_capa *capa,
3845 char *buf, size_t buflen)
3846{
3847 int ret;
3848 char *pos, *end;
3849 unsigned int i;
3850
3851 pos = buf;
3852 end = pos + buflen;
3853
3854 if (res < 0)
3855 return 0;
3856
3857 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
3858 if (capa->enc & ciphers_group_mgmt[i].capa) {
3859 ret = os_snprintf(pos, end - pos, "%s%s",
3860 pos == buf ? "" : " ",
3861 ciphers_group_mgmt[i].name);
3862 if (os_snprintf_error(end - pos, ret))
3863 return pos - buf;
3864 pos += ret;
3865 }
3866 }
3867
3868 return pos - buf;
3869}
3870
3871
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003872static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3873 struct wpa_driver_capa *capa,
3874 char *buf, size_t buflen)
3875{
3876 int ret;
3877 char *pos, *end;
3878 size_t len;
3879
3880 pos = buf;
3881 end = pos + buflen;
3882
3883 if (res < 0) {
3884 if (strict)
3885 return 0;
3886 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3887 "NONE", buflen);
3888 if (len >= buflen)
3889 return -1;
3890 return len;
3891 }
3892
3893 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003894 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003895 return pos - buf;
3896 pos += ret;
3897
3898 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3899 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3900 ret = os_snprintf(pos, end - pos, " WPA-EAP");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003901 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003902 return pos - buf;
3903 pos += ret;
3904 }
3905
3906 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3907 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3908 ret = os_snprintf(pos, end - pos, " WPA-PSK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003909 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003910 return pos - buf;
3911 pos += ret;
3912 }
3913
3914 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3915 ret = os_snprintf(pos, end - pos, " WPA-NONE");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003916 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003917 return pos - buf;
3918 pos += ret;
3919 }
3920
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003921#ifdef CONFIG_SUITEB
3922 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
3923 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
3924 if (os_snprintf_error(end - pos, ret))
3925 return pos - buf;
3926 pos += ret;
3927 }
3928#endif /* CONFIG_SUITEB */
3929#ifdef CONFIG_SUITEB192
3930 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
3931 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
3932 if (os_snprintf_error(end - pos, ret))
3933 return pos - buf;
3934 pos += ret;
3935 }
3936#endif /* CONFIG_SUITEB192 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003937#ifdef CONFIG_OWE
3938 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
3939 ret = os_snprintf(pos, end - pos, " OWE");
3940 if (os_snprintf_error(end - pos, ret))
3941 return pos - buf;
3942 pos += ret;
3943 }
3944#endif /* CONFIG_OWE */
3945#ifdef CONFIG_DPP
3946 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
3947 ret = os_snprintf(pos, end - pos, " DPP");
3948 if (os_snprintf_error(end - pos, ret))
3949 return pos - buf;
3950 pos += ret;
3951 }
3952#endif /* CONFIG_DPP */
3953#ifdef CONFIG_FILS
3954 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
3955 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
3956 if (os_snprintf_error(end - pos, ret))
3957 return pos - buf;
3958 pos += ret;
3959 }
3960 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
3961 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
3962 if (os_snprintf_error(end - pos, ret))
3963 return pos - buf;
3964 pos += ret;
3965 }
3966#ifdef CONFIG_IEEE80211R
3967 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
3968 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
3969 if (os_snprintf_error(end - pos, ret))
3970 return pos - buf;
3971 pos += ret;
3972 }
3973 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
3974 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
3975 if (os_snprintf_error(end - pos, ret))
3976 return pos - buf;
3977 pos += ret;
3978 }
3979#endif /* CONFIG_IEEE80211R */
3980#endif /* CONFIG_FILS */
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003981
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003982 return pos - buf;
3983}
3984
3985
3986static int ctrl_iface_get_capability_proto(int res, char *strict,
3987 struct wpa_driver_capa *capa,
3988 char *buf, size_t buflen)
3989{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003990 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003991 char *pos, *end;
3992 size_t len;
3993
3994 pos = buf;
3995 end = pos + buflen;
3996
3997 if (res < 0) {
3998 if (strict)
3999 return 0;
4000 len = os_strlcpy(buf, "RSN WPA", buflen);
4001 if (len >= buflen)
4002 return -1;
4003 return len;
4004 }
4005
4006 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4007 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004008 ret = os_snprintf(pos, end - pos, "%sRSN",
4009 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004010 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004011 return pos - buf;
4012 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004013 }
4014
4015 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4016 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004017 ret = os_snprintf(pos, end - pos, "%sWPA",
4018 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004019 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004020 return pos - buf;
4021 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004022 }
4023
4024 return pos - buf;
4025}
4026
4027
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004028static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
4029 int res, char *strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004030 struct wpa_driver_capa *capa,
4031 char *buf, size_t buflen)
4032{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004033 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004034 char *pos, *end;
4035 size_t len;
4036
4037 pos = buf;
4038 end = pos + buflen;
4039
4040 if (res < 0) {
4041 if (strict)
4042 return 0;
4043 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4044 if (len >= buflen)
4045 return -1;
4046 return len;
4047 }
4048
4049 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004050 ret = os_snprintf(pos, end - pos, "%sOPEN",
4051 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004052 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004053 return pos - buf;
4054 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004055 }
4056
4057 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4058 ret = os_snprintf(pos, end - pos, "%sSHARED",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004059 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004060 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004061 return pos - buf;
4062 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004063 }
4064
4065 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004066 ret = os_snprintf(pos, end - pos, "%sLEAP",
4067 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004068 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004069 return pos - buf;
4070 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004071 }
4072
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004073#ifdef CONFIG_SAE
4074 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4075 ret = os_snprintf(pos, end - pos, "%sSAE",
4076 pos == buf ? "" : " ");
4077 if (os_snprintf_error(end - pos, ret))
4078 return pos - buf;
4079 pos += ret;
4080 }
4081#endif /* CONFIG_SAE */
4082
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004083#ifdef CONFIG_FILS
4084 if (wpa_is_fils_supported(wpa_s)) {
4085 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4086 pos == buf ? "" : " ");
4087 if (os_snprintf_error(end - pos, ret))
4088 return pos - buf;
4089 pos += ret;
4090 }
4091
4092#ifdef CONFIG_FILS_SK_PFS
4093 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4094 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4095 pos == buf ? "" : " ");
4096 if (os_snprintf_error(end - pos, ret))
4097 return pos - buf;
4098 pos += ret;
4099 }
4100#endif /* CONFIG_FILS_SK_PFS */
4101#endif /* CONFIG_FILS */
4102
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004103 return pos - buf;
4104}
4105
4106
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004107static int ctrl_iface_get_capability_modes(int res, char *strict,
4108 struct wpa_driver_capa *capa,
4109 char *buf, size_t buflen)
4110{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004111 int ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004112 char *pos, *end;
4113 size_t len;
4114
4115 pos = buf;
4116 end = pos + buflen;
4117
4118 if (res < 0) {
4119 if (strict)
4120 return 0;
4121 len = os_strlcpy(buf, "IBSS AP", buflen);
4122 if (len >= buflen)
4123 return -1;
4124 return len;
4125 }
4126
4127 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004128 ret = os_snprintf(pos, end - pos, "%sIBSS",
4129 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004130 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004131 return pos - buf;
4132 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004133 }
4134
4135 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004136 ret = os_snprintf(pos, end - pos, "%sAP",
4137 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004138 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004139 return pos - buf;
4140 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004141 }
4142
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004143#ifdef CONFIG_MESH
4144 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4145 ret = os_snprintf(pos, end - pos, "%sMESH",
4146 pos == buf ? "" : " ");
4147 if (os_snprintf_error(end - pos, ret))
4148 return pos - buf;
4149 pos += ret;
4150 }
4151#endif /* CONFIG_MESH */
4152
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004153 return pos - buf;
4154}
4155
4156
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004157static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4158 char *buf, size_t buflen)
4159{
4160 struct hostapd_channel_data *chnl;
4161 int ret, i, j;
4162 char *pos, *end, *hmode;
4163
4164 pos = buf;
4165 end = pos + buflen;
4166
4167 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4168 switch (wpa_s->hw.modes[j].mode) {
4169 case HOSTAPD_MODE_IEEE80211B:
4170 hmode = "B";
4171 break;
4172 case HOSTAPD_MODE_IEEE80211G:
4173 hmode = "G";
4174 break;
4175 case HOSTAPD_MODE_IEEE80211A:
4176 hmode = "A";
4177 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004178 case HOSTAPD_MODE_IEEE80211AD:
4179 hmode = "AD";
4180 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004181 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004182 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004183 }
4184 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004185 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004186 return pos - buf;
4187 pos += ret;
4188 chnl = wpa_s->hw.modes[j].channels;
4189 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004190 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4191 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004192 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004193 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004194 return pos - buf;
4195 pos += ret;
4196 }
4197 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004198 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004199 return pos - buf;
4200 pos += ret;
4201 }
4202
4203 return pos - buf;
4204}
4205
4206
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004207static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4208 char *buf, size_t buflen)
4209{
4210 struct hostapd_channel_data *chnl;
4211 int ret, i, j;
4212 char *pos, *end, *hmode;
4213
4214 pos = buf;
4215 end = pos + buflen;
4216
4217 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4218 switch (wpa_s->hw.modes[j].mode) {
4219 case HOSTAPD_MODE_IEEE80211B:
4220 hmode = "B";
4221 break;
4222 case HOSTAPD_MODE_IEEE80211G:
4223 hmode = "G";
4224 break;
4225 case HOSTAPD_MODE_IEEE80211A:
4226 hmode = "A";
4227 break;
4228 case HOSTAPD_MODE_IEEE80211AD:
4229 hmode = "AD";
4230 break;
4231 default:
4232 continue;
4233 }
4234 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4235 hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004236 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004237 return pos - buf;
4238 pos += ret;
4239 chnl = wpa_s->hw.modes[j].channels;
4240 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4241 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4242 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004243 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004244 chnl[i].chan, chnl[i].freq,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004245 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4246 " (NO_IR)" : "",
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004247 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4248 " (DFS)" : "");
4249
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004250 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004251 return pos - buf;
4252 pos += ret;
4253 }
4254 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004255 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004256 return pos - buf;
4257 pos += ret;
4258 }
4259
4260 return pos - buf;
4261}
4262
4263
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004264static int wpa_supplicant_ctrl_iface_get_capability(
4265 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4266 size_t buflen)
4267{
4268 struct wpa_driver_capa capa;
4269 int res;
4270 char *strict;
4271 char field[30];
4272 size_t len;
4273
4274 /* Determine whether or not strict checking was requested */
4275 len = os_strlcpy(field, _field, sizeof(field));
4276 if (len >= sizeof(field))
4277 return -1;
4278 strict = os_strchr(field, ' ');
4279 if (strict != NULL) {
4280 *strict++ = '\0';
4281 if (os_strcmp(strict, "strict") != 0)
4282 return -1;
4283 }
4284
4285 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4286 field, strict ? strict : "");
4287
4288 if (os_strcmp(field, "eap") == 0) {
4289 return eap_get_names(buf, buflen);
4290 }
4291
4292 res = wpa_drv_get_capa(wpa_s, &capa);
4293
4294 if (os_strcmp(field, "pairwise") == 0)
4295 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4296 buf, buflen);
4297
4298 if (os_strcmp(field, "group") == 0)
4299 return ctrl_iface_get_capability_group(res, strict, &capa,
4300 buf, buflen);
4301
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004302 if (os_strcmp(field, "group_mgmt") == 0)
4303 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4304 buf, buflen);
4305
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004306 if (os_strcmp(field, "key_mgmt") == 0)
4307 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
4308 buf, buflen);
4309
4310 if (os_strcmp(field, "proto") == 0)
4311 return ctrl_iface_get_capability_proto(res, strict, &capa,
4312 buf, buflen);
4313
4314 if (os_strcmp(field, "auth_alg") == 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004315 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4316 &capa, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004317
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004318 if (os_strcmp(field, "modes") == 0)
4319 return ctrl_iface_get_capability_modes(res, strict, &capa,
4320 buf, buflen);
4321
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004322 if (os_strcmp(field, "channels") == 0)
4323 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4324
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004325 if (os_strcmp(field, "freq") == 0)
4326 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4327
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004328#ifdef CONFIG_TDLS
4329 if (os_strcmp(field, "tdls") == 0)
4330 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4331#endif /* CONFIG_TDLS */
4332
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004333#ifdef CONFIG_ERP
4334 if (os_strcmp(field, "erp") == 0) {
4335 res = os_snprintf(buf, buflen, "ERP");
4336 if (os_snprintf_error(buflen, res))
4337 return -1;
4338 return res;
4339 }
4340#endif /* CONFIG_EPR */
4341
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004342#ifdef CONFIG_FIPS
4343 if (os_strcmp(field, "fips") == 0) {
4344 res = os_snprintf(buf, buflen, "FIPS");
4345 if (os_snprintf_error(buflen, res))
4346 return -1;
4347 return res;
4348 }
4349#endif /* CONFIG_FIPS */
4350
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004351#ifdef CONFIG_ACS
4352 if (os_strcmp(field, "acs") == 0) {
4353 res = os_snprintf(buf, buflen, "ACS");
4354 if (os_snprintf_error(buflen, res))
4355 return -1;
4356 return res;
4357 }
4358#endif /* CONFIG_ACS */
4359
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004360#ifdef CONFIG_FILS
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004361 if (os_strcmp(field, "fils") == 0) {
4362#ifdef CONFIG_FILS_SK_PFS
4363 if (wpa_is_fils_supported(wpa_s) &&
4364 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4365 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4366 if (os_snprintf_error(buflen, res))
4367 return -1;
4368 return res;
4369 }
4370#endif /* CONFIG_FILS_SK_PFS */
4371
4372 if (wpa_is_fils_supported(wpa_s)) {
4373 res = os_snprintf(buf, buflen, "FILS");
4374 if (os_snprintf_error(buflen, res))
4375 return -1;
4376 return res;
4377 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004378 }
4379#endif /* CONFIG_FILS */
4380
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004381 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4382 field);
4383
4384 return -1;
4385}
4386
4387
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004388#ifdef CONFIG_INTERWORKING
4389static char * anqp_add_hex(char *pos, char *end, const char *title,
4390 struct wpabuf *data)
4391{
4392 char *start = pos;
4393 size_t i;
4394 int ret;
4395 const u8 *d;
4396
4397 if (data == NULL)
4398 return start;
4399
4400 ret = os_snprintf(pos, end - pos, "%s=", title);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004401 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004402 return start;
4403 pos += ret;
4404
4405 d = wpabuf_head_u8(data);
4406 for (i = 0; i < wpabuf_len(data); i++) {
4407 ret = os_snprintf(pos, end - pos, "%02x", *d++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004408 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004409 return start;
4410 pos += ret;
4411 }
4412
4413 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004414 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004415 return start;
4416 pos += ret;
4417
4418 return pos;
4419}
4420#endif /* CONFIG_INTERWORKING */
4421
4422
Dmitry Shmidt29333592017-01-09 12:27:11 -08004423#ifdef CONFIG_FILS
4424static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4425{
4426 char *start = pos;
4427 const u8 *ie, *ie_end;
4428 u16 info, realms;
4429 int ret;
4430
4431 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4432 if (!ie)
4433 return 0;
4434 ie_end = ie + 2 + ie[1];
4435 ie += 2;
4436 if (ie_end - ie < 2)
4437 return -1;
4438
4439 info = WPA_GET_LE16(ie);
4440 ie += 2;
4441 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4442 if (os_snprintf_error(end - pos, ret))
4443 return 0;
4444 pos += ret;
4445
4446 if (info & BIT(7)) {
4447 /* Cache Identifier Included */
4448 if (ie_end - ie < 2)
4449 return -1;
4450 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4451 ie[0], ie[1]);
4452 if (os_snprintf_error(end - pos, ret))
4453 return 0;
4454 pos += ret;
4455 ie += 2;
4456 }
4457
4458 if (info & BIT(8)) {
4459 /* HESSID Included */
4460 if (ie_end - ie < ETH_ALEN)
4461 return -1;
4462 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4463 MAC2STR(ie));
4464 if (os_snprintf_error(end - pos, ret))
4465 return 0;
4466 pos += ret;
4467 ie += ETH_ALEN;
4468 }
4469
4470 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4471 if (realms) {
4472 if (ie_end - ie < realms * 2)
4473 return -1;
4474 ret = os_snprintf(pos, end - pos, "fils_realms=");
4475 if (os_snprintf_error(end - pos, ret))
4476 return 0;
4477 pos += ret;
4478
4479 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
4480 if (ret <= 0)
4481 return 0;
4482 pos += ret;
4483 ie += realms * 2;
4484 ret = os_snprintf(pos, end - pos, "\n");
4485 if (os_snprintf_error(end - pos, ret))
4486 return 0;
4487 pos += ret;
4488 }
4489
4490 return pos - start;
4491}
4492#endif /* CONFIG_FILS */
4493
4494
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004495static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
4496 unsigned long mask, char *buf, size_t buflen)
4497{
4498 size_t i;
4499 int ret;
4500 char *pos, *end;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004501 const u8 *ie, *ie2, *osen_ie, *mesh, *owe;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004502
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004503 pos = buf;
4504 end = buf + buflen;
4505
4506 if (mask & WPA_BSS_MASK_ID) {
4507 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004508 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004509 return 0;
4510 pos += ret;
4511 }
4512
4513 if (mask & WPA_BSS_MASK_BSSID) {
4514 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
4515 MAC2STR(bss->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004516 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004517 return 0;
4518 pos += ret;
4519 }
4520
4521 if (mask & WPA_BSS_MASK_FREQ) {
4522 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004523 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004524 return 0;
4525 pos += ret;
4526 }
4527
4528 if (mask & WPA_BSS_MASK_BEACON_INT) {
4529 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
4530 bss->beacon_int);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004531 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004532 return 0;
4533 pos += ret;
4534 }
4535
4536 if (mask & WPA_BSS_MASK_CAPABILITIES) {
4537 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
4538 bss->caps);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004539 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004540 return 0;
4541 pos += ret;
4542 }
4543
4544 if (mask & WPA_BSS_MASK_QUAL) {
4545 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004546 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004547 return 0;
4548 pos += ret;
4549 }
4550
4551 if (mask & WPA_BSS_MASK_NOISE) {
4552 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004553 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004554 return 0;
4555 pos += ret;
4556 }
4557
4558 if (mask & WPA_BSS_MASK_LEVEL) {
4559 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004560 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004561 return 0;
4562 pos += ret;
4563 }
4564
4565 if (mask & WPA_BSS_MASK_TSF) {
4566 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
4567 (unsigned long long) bss->tsf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004568 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004569 return 0;
4570 pos += ret;
4571 }
4572
4573 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004574 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004575
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004576 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004577 ret = os_snprintf(pos, end - pos, "age=%d\n",
4578 (int) (now.sec - bss->last_update.sec));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004579 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004580 return 0;
4581 pos += ret;
4582 }
4583
4584 if (mask & WPA_BSS_MASK_IE) {
4585 ret = os_snprintf(pos, end - pos, "ie=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004586 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004587 return 0;
4588 pos += ret;
4589
4590 ie = (const u8 *) (bss + 1);
4591 for (i = 0; i < bss->ie_len; i++) {
4592 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004593 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004594 return 0;
4595 pos += ret;
4596 }
4597
4598 ret = os_snprintf(pos, end - pos, "\n");
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_FLAGS) {
4605 ret = os_snprintf(pos, end - pos, "flags=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004606 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004607 return 0;
4608 pos += ret;
4609
Dmitry Shmidt29333592017-01-09 12:27:11 -08004610 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
4611
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004612 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
4613 if (ie)
4614 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
4615 2 + ie[1]);
4616 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4617 if (ie2)
Dmitry Shmidt29333592017-01-09 12:27:11 -08004618 pos = wpa_supplicant_ie_txt(pos, end,
4619 mesh ? "RSN" : "WPA2", ie2,
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004620 2 + ie2[1]);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07004621 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
4622 if (osen_ie)
4623 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
4624 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004625 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
4626 if (owe) {
4627 ret = os_snprintf(
4628 pos, end - pos,
4629 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4630 if (os_snprintf_error(end - pos, ret))
4631 return 0;
4632 pos += ret;
4633 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004634 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07004635 if (!ie && !ie2 && !osen_ie &&
4636 (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004637 ret = os_snprintf(pos, end - pos, "[WEP]");
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 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08004642
4643 if (mesh) {
4644 ret = os_snprintf(pos, end - pos, "[MESH]");
4645 if (os_snprintf_error(end - pos, ret))
4646 return 0;
4647 pos += ret;
4648 }
4649
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004650 if (bss_is_dmg(bss)) {
4651 const char *s;
4652 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004653 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004654 return 0;
4655 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004656 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
4657 case IEEE80211_CAP_DMG_IBSS:
4658 s = "[IBSS]";
4659 break;
4660 case IEEE80211_CAP_DMG_AP:
4661 s = "[ESS]";
4662 break;
4663 case IEEE80211_CAP_DMG_PBSS:
4664 s = "[PBSS]";
4665 break;
4666 default:
4667 s = "";
4668 break;
4669 }
4670 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004671 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004672 return 0;
4673 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004674 } else {
4675 if (bss->caps & IEEE80211_CAP_IBSS) {
4676 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004677 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004678 return 0;
4679 pos += ret;
4680 }
4681 if (bss->caps & IEEE80211_CAP_ESS) {
4682 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004683 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004684 return 0;
4685 pos += ret;
4686 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004687 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07004688 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
4689 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004690 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004691 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004692 return 0;
4693 pos += ret;
4694 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004695#ifdef CONFIG_HS20
4696 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
4697 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004698 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004699 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004700 pos += ret;
4701 }
4702#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004703#ifdef CONFIG_FILS
4704 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
4705 ret = os_snprintf(pos, end - pos, "[FILS]");
4706 if (os_snprintf_error(end - pos, ret))
4707 return 0;
4708 pos += ret;
4709 }
4710#endif /* CONFIG_FILS */
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004711
4712 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004713 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004714 return 0;
4715 pos += ret;
4716 }
4717
4718 if (mask & WPA_BSS_MASK_SSID) {
4719 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
4720 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004721 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004722 return 0;
4723 pos += ret;
4724 }
4725
4726#ifdef CONFIG_WPS
4727 if (mask & WPA_BSS_MASK_WPS_SCAN) {
4728 ie = (const u8 *) (bss + 1);
4729 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004730 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004731 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004732 if (ret > 0)
4733 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004734 }
4735#endif /* CONFIG_WPS */
4736
4737#ifdef CONFIG_P2P
4738 if (mask & WPA_BSS_MASK_P2P_SCAN) {
4739 ie = (const u8 *) (bss + 1);
4740 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004741 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004742 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004743 if (ret > 0)
4744 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004745 }
4746#endif /* CONFIG_P2P */
4747
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004748#ifdef CONFIG_WIFI_DISPLAY
4749 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
4750 struct wpabuf *wfd;
4751 ie = (const u8 *) (bss + 1);
4752 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
4753 WFD_IE_VENDOR_TYPE);
4754 if (wfd) {
4755 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004756 if (os_snprintf_error(end - pos, ret)) {
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004757 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004758 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004759 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004760 pos += ret;
4761
4762 pos += wpa_snprintf_hex(pos, end - pos,
4763 wpabuf_head(wfd),
4764 wpabuf_len(wfd));
4765 wpabuf_free(wfd);
4766
4767 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004768 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004769 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004770 pos += ret;
4771 }
4772 }
4773#endif /* CONFIG_WIFI_DISPLAY */
4774
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004775#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004776 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
4777 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004778 struct wpa_bss_anqp_elem *elem;
4779
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004780 pos = anqp_add_hex(pos, end, "anqp_capability_list",
4781 anqp->capability_list);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004782 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004783 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004784 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004785 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004786 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004787 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004788 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004789 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004790 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004791 anqp->nai_realm);
4792 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004793 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004794 anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -08004795 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
4796 anqp->fils_realm_info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004797#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004798 pos = anqp_add_hex(pos, end, "hs20_capability_list",
4799 anqp->hs20_capability_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004800 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004801 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004802 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004803 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004804 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004805 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004806 pos = anqp_add_hex(pos, end, "hs20_operating_class",
4807 anqp->hs20_operating_class);
4808 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
4809 anqp->hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004810 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
4811 anqp->hs20_operator_icon_metadata);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004812#endif /* CONFIG_HS20 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004813
4814 dl_list_for_each(elem, &anqp->anqp_elems,
4815 struct wpa_bss_anqp_elem, list) {
4816 char title[20];
4817
4818 os_snprintf(title, sizeof(title), "anqp[%u]",
4819 elem->infoid);
4820 pos = anqp_add_hex(pos, end, title, elem->payload);
4821 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004822 }
4823#endif /* CONFIG_INTERWORKING */
4824
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004825#ifdef CONFIG_MESH
4826 if (mask & WPA_BSS_MASK_MESH_SCAN) {
4827 ie = (const u8 *) (bss + 1);
4828 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004829 if (ret >= end - pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004830 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004831 if (ret > 0)
4832 pos += ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004833 }
4834#endif /* CONFIG_MESH */
4835
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004836 if (mask & WPA_BSS_MASK_SNR) {
4837 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
4838 if (os_snprintf_error(end - pos, ret))
4839 return 0;
4840 pos += ret;
4841 }
4842
4843 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
4844 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
4845 bss->est_throughput);
4846 if (os_snprintf_error(end - pos, ret))
4847 return 0;
4848 pos += ret;
4849 }
4850
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004851#ifdef CONFIG_FST
4852 if (mask & WPA_BSS_MASK_FST) {
4853 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
4854 if (ret < 0 || ret >= end - pos)
4855 return 0;
4856 pos += ret;
4857 }
4858#endif /* CONFIG_FST */
4859
Dmitry Shmidt29333592017-01-09 12:27:11 -08004860 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
4861 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
4862 bss->last_update_idx);
4863 if (os_snprintf_error(end - pos, ret))
4864 return 0;
4865 pos += ret;
4866 }
4867
4868 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
4869 ret = os_snprintf(pos, end - pos, "beacon_ie=");
4870 if (os_snprintf_error(end - pos, ret))
4871 return 0;
4872 pos += ret;
4873
4874 ie = (const u8 *) (bss + 1);
4875 ie += bss->ie_len;
4876 for (i = 0; i < bss->beacon_ie_len; i++) {
4877 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
4878 if (os_snprintf_error(end - pos, ret))
4879 return 0;
4880 pos += ret;
4881 }
4882
4883 ret = os_snprintf(pos, end - pos, "\n");
4884 if (os_snprintf_error(end - pos, ret))
4885 return 0;
4886 pos += ret;
4887 }
4888
4889#ifdef CONFIG_FILS
4890 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
4891 ret = print_fils_indication(bss, pos, end);
4892 if (ret < 0)
4893 return 0;
4894 pos += ret;
4895 }
4896#endif /* CONFIG_FILS */
4897
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004898 if (mask & WPA_BSS_MASK_DELIM) {
4899 ret = os_snprintf(pos, end - pos, "====\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004900 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004901 return 0;
4902 pos += ret;
4903 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07004904
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004905 return pos - buf;
4906}
4907
Dmitry Shmidt04949592012-07-19 12:16:46 -07004908
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004909static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
4910 const char *cmd, char *buf,
4911 size_t buflen)
4912{
4913 u8 bssid[ETH_ALEN];
4914 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004915 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004916 struct wpa_bss *bsslast = NULL;
4917 struct dl_list *next;
4918 int ret = 0;
4919 int len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004920 char *ctmp, *end = buf + buflen;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004921 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004922
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004923 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
4924 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
4925 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004926 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004927 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
4928 list_id);
4929 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004930 unsigned int id1, id2;
4931
4932 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
4933 wpa_printf(MSG_INFO, "Wrong BSS range "
4934 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004935 return 0;
4936 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004937
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004938 if (*(cmd + 6) == '-')
4939 id1 = 0;
4940 else
4941 id1 = atoi(cmd + 6);
4942 ctmp++;
4943 if (*ctmp >= '0' && *ctmp <= '9')
4944 id2 = atoi(ctmp);
4945 else
4946 id2 = (unsigned int) -1;
4947 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
4948 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004949 bsslast = dl_list_last(&wpa_s->bss_id,
4950 struct wpa_bss,
4951 list_id);
4952 else {
4953 bsslast = wpa_bss_get_id(wpa_s, id2);
4954 if (bsslast == NULL && bss && id2 > id1) {
4955 struct wpa_bss *tmp = bss;
4956 for (;;) {
4957 next = tmp->list_id.next;
4958 if (next == &wpa_s->bss_id)
4959 break;
4960 tmp = dl_list_entry(
4961 next, struct wpa_bss,
4962 list_id);
4963 if (tmp->id > id2)
4964 break;
4965 bsslast = tmp;
4966 }
4967 }
4968 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004969 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004970 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004971 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004972 else if (os_strncmp(cmd, "LAST", 4) == 0)
4973 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004974 else if (os_strncmp(cmd, "ID-", 3) == 0) {
4975 i = atoi(cmd + 3);
4976 bss = wpa_bss_get_id(wpa_s, i);
4977 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4978 i = atoi(cmd + 5);
4979 bss = wpa_bss_get_id(wpa_s, i);
4980 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004981 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004982 if (next == &wpa_s->bss_id)
4983 bss = NULL;
4984 else
4985 bss = dl_list_entry(next, struct wpa_bss,
4986 list_id);
4987 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08004988 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
4989 bss = wpa_s->current_bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004990#ifdef CONFIG_P2P
4991 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
4992 if (hwaddr_aton(cmd + 13, bssid) == 0)
4993 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
4994 else
4995 bss = NULL;
4996#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004997 } else if (hwaddr_aton(cmd, bssid) == 0)
4998 bss = wpa_bss_get_bssid(wpa_s, bssid);
4999 else {
5000 struct wpa_bss *tmp;
5001 i = atoi(cmd);
5002 bss = NULL;
5003 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5004 {
5005 if (i-- == 0) {
5006 bss = tmp;
5007 break;
5008 }
5009 }
5010 }
5011
Dmitry Shmidt04949592012-07-19 12:16:46 -07005012 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5013 mask = strtoul(ctmp + 5, NULL, 0x10);
5014 if (mask == 0)
5015 mask = WPA_BSS_MASK_ALL;
5016 }
5017
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005018 if (bss == NULL)
5019 return 0;
5020
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005021 if (bsslast == NULL)
5022 bsslast = bss;
5023 do {
5024 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5025 ret += len;
5026 buf += len;
5027 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005028 if (bss == bsslast) {
5029 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5030 (bss == dl_list_last(&wpa_s->bss_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005031 struct wpa_bss, list_id))) {
5032 int res;
5033
5034 res = os_snprintf(buf - 5, end - buf + 5,
5035 "####\n");
5036 if (os_snprintf_error(end - buf + 5, res)) {
5037 wpa_printf(MSG_DEBUG,
5038 "Could not add end delim");
5039 }
5040 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005041 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005042 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005043 next = bss->list_id.next;
5044 if (next == &wpa_s->bss_id)
5045 break;
5046 bss = dl_list_entry(next, struct wpa_bss, list_id);
5047 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005048
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005049 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005050}
5051
5052
5053static int wpa_supplicant_ctrl_iface_ap_scan(
5054 struct wpa_supplicant *wpa_s, char *cmd)
5055{
5056 int ap_scan = atoi(cmd);
5057 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5058}
5059
5060
5061static int wpa_supplicant_ctrl_iface_scan_interval(
5062 struct wpa_supplicant *wpa_s, char *cmd)
5063{
5064 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005065 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005066}
5067
5068
5069static int wpa_supplicant_ctrl_iface_bss_expire_age(
5070 struct wpa_supplicant *wpa_s, char *cmd)
5071{
5072 int expire_age = atoi(cmd);
5073 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5074}
5075
5076
5077static int wpa_supplicant_ctrl_iface_bss_expire_count(
5078 struct wpa_supplicant *wpa_s, char *cmd)
5079{
5080 int expire_count = atoi(cmd);
5081 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5082}
5083
5084
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005085static void wpa_supplicant_ctrl_iface_bss_flush(
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005086 struct wpa_supplicant *wpa_s, char *cmd)
5087{
5088 int flush_age = atoi(cmd);
5089
5090 if (flush_age == 0)
5091 wpa_bss_flush(wpa_s);
5092 else
5093 wpa_bss_flush_by_age(wpa_s, flush_age);
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005094}
5095
5096
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005097#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005098static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5099{
5100 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5101 /* MLME-DELETEKEYS.request */
5102 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
5103 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
5104 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
5105 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
5106#ifdef CONFIG_IEEE80211W
5107 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
5108 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
5109#endif /* CONFIG_IEEE80211W */
5110
5111 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
5112 0);
5113 /* MLME-SETPROTECTION.request(None) */
5114 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5115 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5116 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5117 wpa_sm_drop_sa(wpa_s->wpa);
5118}
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005119#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005120
5121
5122static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5123 char *addr)
5124{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005125#ifdef CONFIG_NO_SCAN_PROCESSING
5126 return -1;
5127#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005128 u8 bssid[ETH_ALEN];
5129 struct wpa_bss *bss;
5130 struct wpa_ssid *ssid = wpa_s->current_ssid;
5131
5132 if (hwaddr_aton(addr, bssid)) {
5133 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5134 "address '%s'", addr);
5135 return -1;
5136 }
5137
5138 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5139
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005140 if (!ssid) {
5141 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5142 "configuration known for the target AP");
5143 return -1;
5144 }
5145
5146 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005147 if (!bss) {
5148 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
5149 "from BSS table");
5150 return -1;
5151 }
5152
5153 /*
5154 * TODO: Find best network configuration block from configuration to
5155 * allow roaming to other networks
5156 */
5157
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005158 wpa_s->reassociate = 1;
5159 wpa_supplicant_connect(wpa_s, bss, ssid);
5160
5161 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005162#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005163}
5164
5165
5166#ifdef CONFIG_P2P
5167static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
5168{
5169 unsigned int timeout = atoi(cmd);
5170 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005171 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005172 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005173 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005174 unsigned int search_delay;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005175 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005176 u8 seek_count = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005177 int freq = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005178
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005179 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5180 wpa_dbg(wpa_s, MSG_INFO,
5181 "Reject P2P_FIND since interface is disabled");
5182 return -1;
5183 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005184 if (os_strstr(cmd, "type=social"))
5185 type = P2P_FIND_ONLY_SOCIAL;
5186 else if (os_strstr(cmd, "type=progressive"))
5187 type = P2P_FIND_PROGRESSIVE;
5188
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005189 pos = os_strstr(cmd, "dev_id=");
5190 if (pos) {
5191 pos += 7;
5192 if (hwaddr_aton(pos, dev_id))
5193 return -1;
5194 _dev_id = dev_id;
5195 }
5196
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005197 pos = os_strstr(cmd, "dev_type=");
5198 if (pos) {
5199 pos += 9;
5200 if (wps_dev_type_str2bin(pos, dev_type) < 0)
5201 return -1;
5202 _dev_type = dev_type;
5203 }
5204
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005205 pos = os_strstr(cmd, "delay=");
5206 if (pos) {
5207 pos += 6;
5208 search_delay = atoi(pos);
5209 } else
5210 search_delay = wpas_p2p_search_delay(wpa_s);
5211
Dmitry Shmidt41712582015-06-29 11:02:15 -07005212 pos = os_strstr(cmd, "freq=");
5213 if (pos) {
5214 pos += 5;
5215 freq = atoi(pos);
5216 if (freq <= 0)
5217 return -1;
5218 }
5219
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005220 /* Must be searched for last, because it adds nul termination */
5221 pos = os_strstr(cmd, " seek=");
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005222 if (pos)
5223 pos += 6;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005224 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
5225 char *term;
5226
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005227 _seek[seek_count++] = pos;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005228 seek = _seek;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005229 term = os_strchr(pos, ' ');
5230 if (!term)
5231 break;
5232 *term = '\0';
5233 pos = os_strstr(term + 1, "seek=");
5234 if (pos)
5235 pos += 5;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005236 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005237 if (seek_count > P2P_MAX_QUERY_HASH) {
5238 seek[0] = NULL;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005239 seek_count = 1;
5240 }
5241
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005242 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005243 _dev_id, search_delay, seek_count, seek, freq);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005244}
5245
5246
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005247static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
5248{
5249 const char *last = NULL;
5250 const char *token;
5251 long int token_len;
5252 unsigned int i;
5253
5254 /* Expected predefined CPT names delimited by ':' */
5255 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
5256 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
5257 wpa_printf(MSG_ERROR,
5258 "P2PS: CPT name list is too long, expected up to %d names",
5259 P2PS_FEATURE_CAPAB_CPT_MAX);
5260 cpt[0] = 0;
5261 return -1;
5262 }
5263
5264 token_len = last - token;
5265
5266 if (token_len == 3 &&
5267 os_memcmp(token, "UDP", token_len) == 0) {
5268 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5269 } else if (token_len == 3 &&
5270 os_memcmp(token, "MAC", token_len) == 0) {
5271 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
5272 } else {
5273 wpa_printf(MSG_ERROR,
5274 "P2PS: Unsupported CPT name '%s'", token);
5275 cpt[0] = 0;
5276 return -1;
5277 }
5278
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005279 if (isblank((unsigned char) *last)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005280 i++;
5281 break;
5282 }
5283 }
5284 cpt[i] = 0;
5285 return 0;
5286}
5287
5288
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005289static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
5290{
5291 struct p2ps_provision *p2ps_prov;
5292 char *pos;
5293 size_t info_len = 0;
5294 char *info = NULL;
5295 u8 role = P2PS_SETUP_NONE;
5296 long long unsigned val;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005297 int i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005298
5299 pos = os_strstr(cmd, "info=");
5300 if (pos) {
5301 pos += 5;
5302 info_len = os_strlen(pos);
5303
5304 if (info_len) {
5305 info = os_malloc(info_len + 1);
5306 if (info) {
5307 info_len = utf8_unescape(pos, info_len,
5308 info, info_len + 1);
5309 } else
5310 info_len = 0;
5311 }
5312 }
5313
5314 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
5315 if (p2ps_prov == NULL) {
5316 os_free(info);
5317 return NULL;
5318 }
5319
5320 if (info) {
5321 os_memcpy(p2ps_prov->info, info, info_len);
5322 p2ps_prov->info[info_len] = '\0';
5323 os_free(info);
5324 }
5325
5326 pos = os_strstr(cmd, "status=");
5327 if (pos)
5328 p2ps_prov->status = atoi(pos + 7);
5329 else
5330 p2ps_prov->status = -1;
5331
5332 pos = os_strstr(cmd, "adv_id=");
5333 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
5334 goto invalid_args;
5335 p2ps_prov->adv_id = val;
5336
5337 pos = os_strstr(cmd, "method=");
5338 if (pos)
5339 p2ps_prov->method = strtol(pos + 7, NULL, 16);
5340 else
5341 p2ps_prov->method = 0;
5342
5343 pos = os_strstr(cmd, "session=");
5344 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
5345 goto invalid_args;
5346 p2ps_prov->session_id = val;
5347
5348 pos = os_strstr(cmd, "adv_mac=");
5349 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
5350 goto invalid_args;
5351
5352 pos = os_strstr(cmd, "session_mac=");
5353 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
5354 goto invalid_args;
5355
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005356 pos = os_strstr(cmd, "cpt=");
5357 if (pos) {
5358 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
5359 p2ps_prov->cpt_priority))
5360 goto invalid_args;
5361 } else {
5362 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5363 }
5364
5365 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
5366 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
5367
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005368 /* force conncap with tstCap (no sanity checks) */
5369 pos = os_strstr(cmd, "tstCap=");
5370 if (pos) {
5371 role = strtol(pos + 7, NULL, 16);
5372 } else {
5373 pos = os_strstr(cmd, "role=");
5374 if (pos) {
5375 role = strtol(pos + 5, NULL, 16);
5376 if (role != P2PS_SETUP_CLIENT &&
5377 role != P2PS_SETUP_GROUP_OWNER)
5378 role = P2PS_SETUP_NONE;
5379 }
5380 }
5381 p2ps_prov->role = role;
5382
5383 return p2ps_prov;
5384
5385invalid_args:
5386 os_free(p2ps_prov);
5387 return NULL;
5388}
5389
5390
5391static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
5392{
5393 u8 addr[ETH_ALEN];
5394 struct p2ps_provision *p2ps_prov;
5395 char *pos;
5396
5397 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5398
5399 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5400
5401 if (hwaddr_aton(cmd, addr))
5402 return -1;
5403
5404 pos = cmd + 17;
5405 if (*pos != ' ')
5406 return -1;
5407
5408 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5409 if (!p2ps_prov)
5410 return -1;
5411
5412 if (p2ps_prov->status < 0) {
5413 os_free(p2ps_prov);
5414 return -1;
5415 }
5416
5417 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5418 p2ps_prov);
5419}
5420
5421
5422static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
5423{
5424 u8 addr[ETH_ALEN];
5425 struct p2ps_provision *p2ps_prov;
5426 char *pos;
5427
5428 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5429 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5430 */
5431
5432 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5433 if (hwaddr_aton(cmd, addr))
5434 return -1;
5435
5436 pos = cmd + 17;
5437 if (*pos != ' ')
5438 return -1;
5439
5440 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5441 if (!p2ps_prov)
5442 return -1;
5443
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005444 p2ps_prov->pd_seeker = 1;
5445
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005446 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5447 p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005448}
5449
5450
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005451static int parse_freq(int chwidth, int freq2)
5452{
5453 if (freq2 < 0)
5454 return -1;
5455 if (freq2)
5456 return VHT_CHANWIDTH_80P80MHZ;
5457
5458 switch (chwidth) {
5459 case 0:
5460 case 20:
5461 case 40:
5462 return VHT_CHANWIDTH_USE_HT;
5463 case 80:
5464 return VHT_CHANWIDTH_80MHZ;
5465 case 160:
5466 return VHT_CHANWIDTH_160MHZ;
5467 default:
5468 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
5469 chwidth);
5470 return -1;
5471 }
5472}
5473
5474
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005475static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
5476 char *buf, size_t buflen)
5477{
5478 u8 addr[ETH_ALEN];
5479 char *pos, *pos2;
5480 char *pin = NULL;
5481 enum p2p_wps_method wps_method;
5482 int new_pin;
5483 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005484 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005485 int join;
5486 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005487 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005488 int go_intent = -1;
5489 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005490 int pd;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005491 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005492 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
5493 size_t group_ssid_len = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005494
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005495 if (!wpa_s->global->p2p_init_wpa_s)
5496 return -1;
5497 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
5498 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
5499 wpa_s->global->p2p_init_wpa_s->ifname);
5500 wpa_s = wpa_s->global->p2p_init_wpa_s;
5501 }
5502
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005503 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
Dmitry Shmidt04949592012-07-19 12:16:46 -07005504 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005505 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005506 * [ht40] [vht] [auto] [ssid=<hexdump>] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005507
5508 if (hwaddr_aton(cmd, addr))
5509 return -1;
5510
5511 pos = cmd + 17;
5512 if (*pos != ' ')
5513 return -1;
5514 pos++;
5515
5516 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005517 pos2 = os_strstr(pos, " persistent=");
5518 if (pos2) {
5519 struct wpa_ssid *ssid;
5520 persistent_id = atoi(pos2 + 12);
5521 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
5522 if (ssid == NULL || ssid->disabled != 2 ||
5523 ssid->mode != WPAS_MODE_P2P_GO) {
5524 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
5525 "SSID id=%d for persistent P2P group (GO)",
5526 persistent_id);
5527 return -1;
5528 }
5529 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005530 join = os_strstr(pos, " join") != NULL;
5531 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005532 automatic = os_strstr(pos, " auto") != NULL;
5533 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005534 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
5535 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
5536 vht;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005537
5538 pos2 = os_strstr(pos, " go_intent=");
5539 if (pos2) {
5540 pos2 += 11;
5541 go_intent = atoi(pos2);
5542 if (go_intent < 0 || go_intent > 15)
5543 return -1;
5544 }
5545
5546 pos2 = os_strstr(pos, " freq=");
5547 if (pos2) {
5548 pos2 += 6;
5549 freq = atoi(pos2);
5550 if (freq <= 0)
5551 return -1;
5552 }
5553
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005554 pos2 = os_strstr(pos, " freq2=");
5555 if (pos2)
5556 freq2 = atoi(pos2 + 7);
5557
5558 pos2 = os_strstr(pos, " max_oper_chwidth=");
5559 if (pos2)
5560 chwidth = atoi(pos2 + 18);
5561
5562 max_oper_chwidth = parse_freq(chwidth, freq2);
5563 if (max_oper_chwidth < 0)
5564 return -1;
5565
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005566 pos2 = os_strstr(pos, " ssid=");
5567 if (pos2) {
5568 char *end;
5569
5570 pos2 += 6;
5571 end = os_strchr(pos2, ' ');
5572 if (!end)
5573 group_ssid_len = os_strlen(pos2) / 2;
5574 else
5575 group_ssid_len = (end - pos2) / 2;
5576 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
5577 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
5578 return -1;
5579 group_ssid = _group_ssid;
5580 }
5581
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005582 if (os_strncmp(pos, "pin", 3) == 0) {
5583 /* Request random PIN (to be displayed) and enable the PIN */
5584 wps_method = WPS_PIN_DISPLAY;
5585 } else if (os_strncmp(pos, "pbc", 3) == 0) {
5586 wps_method = WPS_PBC;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005587 } else if (os_strstr(pos, "p2ps") != NULL) {
5588 wps_method = WPS_P2PS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005589 } else {
5590 pin = pos;
5591 pos = os_strchr(pin, ' ');
5592 wps_method = WPS_PIN_KEYPAD;
5593 if (pos) {
5594 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005595 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005596 wps_method = WPS_PIN_DISPLAY;
5597 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005598 if (!wps_pin_str_valid(pin)) {
5599 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
5600 return 17;
5601 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005602 }
5603
5604 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005605 persistent_group, automatic, join,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005606 auth, go_intent, freq, freq2, persistent_id,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005607 pd, ht40, vht, max_oper_chwidth,
5608 group_ssid, group_ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005609 if (new_pin == -2) {
5610 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5611 return 25;
5612 }
5613 if (new_pin == -3) {
5614 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5615 return 25;
5616 }
5617 if (new_pin < 0)
5618 return -1;
5619 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
5620 ret = os_snprintf(buf, buflen, "%08d", new_pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005621 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005622 return -1;
5623 return ret;
5624 }
5625
5626 os_memcpy(buf, "OK\n", 3);
5627 return 3;
5628}
5629
5630
5631static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
5632{
5633 unsigned int timeout = atoi(cmd);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005634 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5635 wpa_dbg(wpa_s, MSG_INFO,
5636 "Reject P2P_LISTEN since interface is disabled");
5637 return -1;
5638 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005639 return wpas_p2p_listen(wpa_s, timeout);
5640}
5641
5642
5643static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
5644{
5645 u8 addr[ETH_ALEN];
5646 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005647 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005648
Dmitry Shmidt04949592012-07-19 12:16:46 -07005649 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005650
5651 if (hwaddr_aton(cmd, addr))
5652 return -1;
5653
5654 pos = cmd + 17;
5655 if (*pos != ' ')
5656 return -1;
5657 pos++;
5658
Dmitry Shmidt04949592012-07-19 12:16:46 -07005659 if (os_strstr(pos, " join") != NULL)
5660 use = WPAS_P2P_PD_FOR_JOIN;
5661 else if (os_strstr(pos, " auto") != NULL)
5662 use = WPAS_P2P_PD_AUTO;
5663
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005664 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005665}
5666
5667
5668static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
5669 size_t buflen)
5670{
5671 struct wpa_ssid *ssid = wpa_s->current_ssid;
5672
5673 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
5674 ssid->passphrase == NULL)
5675 return -1;
5676
5677 os_strlcpy(buf, ssid->passphrase, buflen);
5678 return os_strlen(buf);
5679}
5680
5681
5682static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
5683 char *buf, size_t buflen)
5684{
5685 u64 ref;
5686 int res;
5687 u8 dst_buf[ETH_ALEN], *dst;
5688 struct wpabuf *tlvs;
5689 char *pos;
5690 size_t len;
5691
5692 if (hwaddr_aton(cmd, dst_buf))
5693 return -1;
5694 dst = dst_buf;
5695 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
5696 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
5697 dst = NULL;
5698 pos = cmd + 17;
5699 if (*pos != ' ')
5700 return -1;
5701 pos++;
5702
5703 if (os_strncmp(pos, "upnp ", 5) == 0) {
5704 u8 version;
5705 pos += 5;
5706 if (hexstr2bin(pos, &version, 1) < 0)
5707 return -1;
5708 pos += 2;
5709 if (*pos != ' ')
5710 return -1;
5711 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005712 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005713#ifdef CONFIG_WIFI_DISPLAY
5714 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
5715 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
5716#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005717 } else if (os_strncmp(pos, "asp ", 4) == 0) {
5718 char *svc_str;
5719 char *svc_info = NULL;
5720 u32 id;
5721
5722 pos += 4;
5723 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
5724 return -1;
5725
5726 pos = os_strchr(pos, ' ');
5727 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
5728 return -1;
5729
5730 svc_str = pos + 1;
5731
5732 pos = os_strchr(svc_str, ' ');
5733
5734 if (pos)
5735 *pos++ = '\0';
5736
5737 /* All remaining data is the svc_info string */
5738 if (pos && pos[0] && pos[0] != ' ') {
5739 len = os_strlen(pos);
5740
5741 /* Unescape in place */
5742 len = utf8_unescape(pos, len, pos, len);
5743 if (len > 0xff)
5744 return -1;
5745
5746 svc_info = pos;
5747 }
5748
5749 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
5750 svc_str, svc_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005751 } else {
5752 len = os_strlen(pos);
5753 if (len & 1)
5754 return -1;
5755 len /= 2;
5756 tlvs = wpabuf_alloc(len);
5757 if (tlvs == NULL)
5758 return -1;
5759 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
5760 wpabuf_free(tlvs);
5761 return -1;
5762 }
5763
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005764 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005765 wpabuf_free(tlvs);
5766 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005767 if (ref == 0)
5768 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005769 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005770 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005771 return -1;
5772 return res;
5773}
5774
5775
5776static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
5777 char *cmd)
5778{
5779 long long unsigned val;
5780 u64 req;
5781 if (sscanf(cmd, "%llx", &val) != 1)
5782 return -1;
5783 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005784 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005785}
5786
5787
5788static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
5789{
5790 int freq;
5791 u8 dst[ETH_ALEN];
5792 u8 dialog_token;
5793 struct wpabuf *resp_tlvs;
5794 char *pos, *pos2;
5795 size_t len;
5796
5797 pos = os_strchr(cmd, ' ');
5798 if (pos == NULL)
5799 return -1;
5800 *pos++ = '\0';
5801 freq = atoi(cmd);
5802 if (freq == 0)
5803 return -1;
5804
5805 if (hwaddr_aton(pos, dst))
5806 return -1;
5807 pos += 17;
5808 if (*pos != ' ')
5809 return -1;
5810 pos++;
5811
5812 pos2 = os_strchr(pos, ' ');
5813 if (pos2 == NULL)
5814 return -1;
5815 *pos2++ = '\0';
5816 dialog_token = atoi(pos);
5817
5818 len = os_strlen(pos2);
5819 if (len & 1)
5820 return -1;
5821 len /= 2;
5822 resp_tlvs = wpabuf_alloc(len);
5823 if (resp_tlvs == NULL)
5824 return -1;
5825 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
5826 wpabuf_free(resp_tlvs);
5827 return -1;
5828 }
5829
5830 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
5831 wpabuf_free(resp_tlvs);
5832 return 0;
5833}
5834
5835
5836static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
5837 char *cmd)
5838{
Dmitry Shmidt04949592012-07-19 12:16:46 -07005839 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
5840 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005841 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
5842 return 0;
5843}
5844
5845
5846static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
5847 char *cmd)
5848{
5849 char *pos;
5850 size_t len;
5851 struct wpabuf *query, *resp;
5852
5853 pos = os_strchr(cmd, ' ');
5854 if (pos == NULL)
5855 return -1;
5856 *pos++ = '\0';
5857
5858 len = os_strlen(cmd);
5859 if (len & 1)
5860 return -1;
5861 len /= 2;
5862 query = wpabuf_alloc(len);
5863 if (query == NULL)
5864 return -1;
5865 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
5866 wpabuf_free(query);
5867 return -1;
5868 }
5869
5870 len = os_strlen(pos);
5871 if (len & 1) {
5872 wpabuf_free(query);
5873 return -1;
5874 }
5875 len /= 2;
5876 resp = wpabuf_alloc(len);
5877 if (resp == NULL) {
5878 wpabuf_free(query);
5879 return -1;
5880 }
5881 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
5882 wpabuf_free(query);
5883 wpabuf_free(resp);
5884 return -1;
5885 }
5886
5887 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
5888 wpabuf_free(query);
5889 wpabuf_free(resp);
5890 return -1;
5891 }
5892 return 0;
5893}
5894
5895
5896static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
5897{
5898 char *pos;
5899 u8 version;
5900
5901 pos = os_strchr(cmd, ' ');
5902 if (pos == NULL)
5903 return -1;
5904 *pos++ = '\0';
5905
5906 if (hexstr2bin(cmd, &version, 1) < 0)
5907 return -1;
5908
5909 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
5910}
5911
5912
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005913static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
5914 u8 replace, char *cmd)
5915{
5916 char *pos;
5917 char *adv_str;
5918 u32 auto_accept, adv_id, svc_state, config_methods;
5919 char *svc_info = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005920 char *cpt_prio_str;
5921 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005922
5923 pos = os_strchr(cmd, ' ');
5924 if (pos == NULL)
5925 return -1;
5926 *pos++ = '\0';
5927
5928 /* Auto-Accept value is mandatory, and must be one of the
5929 * single values (0, 1, 2, 4) */
5930 auto_accept = atoi(cmd);
5931 switch (auto_accept) {
5932 case P2PS_SETUP_NONE: /* No auto-accept */
5933 case P2PS_SETUP_NEW:
5934 case P2PS_SETUP_CLIENT:
5935 case P2PS_SETUP_GROUP_OWNER:
5936 break;
5937 default:
5938 return -1;
5939 }
5940
5941 /* Advertisement ID is mandatory */
5942 cmd = pos;
5943 pos = os_strchr(cmd, ' ');
5944 if (pos == NULL)
5945 return -1;
5946 *pos++ = '\0';
5947
5948 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5949 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
5950 return -1;
5951
5952 /* Only allow replacements if exist, and adds if not */
5953 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
5954 if (!replace)
5955 return -1;
5956 } else {
5957 if (replace)
5958 return -1;
5959 }
5960
5961 /* svc_state between 0 - 0xff is mandatory */
5962 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
5963 return -1;
5964
5965 pos = os_strchr(pos, ' ');
5966 if (pos == NULL)
5967 return -1;
5968
5969 /* config_methods is mandatory */
5970 pos++;
5971 if (sscanf(pos, "%x", &config_methods) != 1)
5972 return -1;
5973
5974 if (!(config_methods &
5975 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
5976 return -1;
5977
5978 pos = os_strchr(pos, ' ');
5979 if (pos == NULL)
5980 return -1;
5981
5982 pos++;
5983 adv_str = pos;
5984
5985 /* Advertisement string is mandatory */
5986 if (!pos[0] || pos[0] == ' ')
5987 return -1;
5988
5989 /* Terminate svc string */
5990 pos = os_strchr(pos, ' ');
5991 if (pos != NULL)
5992 *pos++ = '\0';
5993
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005994 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
5995 if (cpt_prio_str) {
5996 pos = os_strchr(pos, ' ');
5997 if (pos != NULL)
5998 *pos++ = '\0';
5999
6000 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6001 return -1;
6002 } else {
6003 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6004 cpt_prio[1] = 0;
6005 }
6006
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006007 /* Service and Response Information are optional */
6008 if (pos && pos[0]) {
6009 size_t len;
6010
6011 /* Note the bare ' included, which cannot exist legally
6012 * in unescaped string. */
6013 svc_info = os_strstr(pos, "svc_info='");
6014
6015 if (svc_info) {
6016 svc_info += 9;
6017 len = os_strlen(svc_info);
6018 utf8_unescape(svc_info, len, svc_info, len);
6019 }
6020 }
6021
6022 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6023 (u8) svc_state, (u16) config_methods,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006024 svc_info, cpt_prio);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006025}
6026
6027
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006028static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6029{
6030 char *pos;
6031
6032 pos = os_strchr(cmd, ' ');
6033 if (pos == NULL)
6034 return -1;
6035 *pos++ = '\0';
6036
6037 if (os_strcmp(cmd, "bonjour") == 0)
6038 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6039 if (os_strcmp(cmd, "upnp") == 0)
6040 return p2p_ctrl_service_add_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006041 if (os_strcmp(cmd, "asp") == 0)
6042 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006043 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6044 return -1;
6045}
6046
6047
6048static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6049 char *cmd)
6050{
6051 size_t len;
6052 struct wpabuf *query;
6053 int ret;
6054
6055 len = os_strlen(cmd);
6056 if (len & 1)
6057 return -1;
6058 len /= 2;
6059 query = wpabuf_alloc(len);
6060 if (query == NULL)
6061 return -1;
6062 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6063 wpabuf_free(query);
6064 return -1;
6065 }
6066
6067 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6068 wpabuf_free(query);
6069 return ret;
6070}
6071
6072
6073static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6074{
6075 char *pos;
6076 u8 version;
6077
6078 pos = os_strchr(cmd, ' ');
6079 if (pos == NULL)
6080 return -1;
6081 *pos++ = '\0';
6082
6083 if (hexstr2bin(cmd, &version, 1) < 0)
6084 return -1;
6085
6086 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6087}
6088
6089
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006090static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6091{
6092 u32 adv_id;
6093
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07006094 if (os_strcmp(cmd, "all") == 0) {
6095 wpas_p2p_service_flush_asp(wpa_s);
6096 return 0;
6097 }
6098
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006099 if (sscanf(cmd, "%x", &adv_id) != 1)
6100 return -1;
6101
6102 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6103}
6104
6105
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006106static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6107{
6108 char *pos;
6109
6110 pos = os_strchr(cmd, ' ');
6111 if (pos == NULL)
6112 return -1;
6113 *pos++ = '\0';
6114
6115 if (os_strcmp(cmd, "bonjour") == 0)
6116 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6117 if (os_strcmp(cmd, "upnp") == 0)
6118 return p2p_ctrl_service_del_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006119 if (os_strcmp(cmd, "asp") == 0)
6120 return p2p_ctrl_service_del_asp(wpa_s, pos);
6121 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6122 return -1;
6123}
6124
6125
6126static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6127{
6128 char *pos;
6129
6130 pos = os_strchr(cmd, ' ');
6131 if (pos == NULL)
6132 return -1;
6133 *pos++ = '\0';
6134
6135 if (os_strcmp(cmd, "asp") == 0)
6136 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6137
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006138 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6139 return -1;
6140}
6141
6142
6143static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
6144{
6145 u8 addr[ETH_ALEN];
6146
6147 /* <addr> */
6148
6149 if (hwaddr_aton(cmd, addr))
6150 return -1;
6151
6152 return wpas_p2p_reject(wpa_s, addr);
6153}
6154
6155
6156static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
6157{
6158 char *pos;
6159 int id;
6160 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006161 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006162 int freq = 0, pref_freq = 0;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006163 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006164
6165 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006166 pos = os_strstr(cmd, " peer=");
6167 if (pos) {
6168 pos += 6;
6169 if (hwaddr_aton(pos, peer))
6170 return -1;
6171 _peer = peer;
6172 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006173 ssid = wpa_config_get_network(wpa_s->conf, id);
6174 if (ssid == NULL || ssid->disabled != 2) {
6175 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6176 "for persistent P2P group",
6177 id);
6178 return -1;
6179 }
6180
Jouni Malinen31be0a42012-08-31 21:20:51 +03006181 pos = os_strstr(cmd, " freq=");
6182 if (pos) {
6183 pos += 6;
6184 freq = atoi(pos);
6185 if (freq <= 0)
6186 return -1;
6187 }
6188
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006189 pos = os_strstr(cmd, " pref=");
6190 if (pos) {
6191 pos += 6;
6192 pref_freq = atoi(pos);
6193 if (pref_freq <= 0)
6194 return -1;
6195 }
6196
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006197 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6198 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6199 vht;
Jouni Malinen31be0a42012-08-31 21:20:51 +03006200
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006201 pos = os_strstr(cmd, "freq2=");
6202 if (pos)
6203 freq2 = atoi(pos + 6);
6204
6205 pos = os_strstr(cmd, " max_oper_chwidth=");
6206 if (pos)
6207 chwidth = atoi(pos + 18);
6208
6209 max_oper_chwidth = parse_freq(chwidth, freq2);
6210 if (max_oper_chwidth < 0)
6211 return -1;
6212
6213 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
6214 max_oper_chwidth, pref_freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006215}
6216
6217
6218static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
6219{
6220 char *pos;
6221 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
6222
6223 pos = os_strstr(cmd, " peer=");
6224 if (!pos)
6225 return -1;
6226
6227 *pos = '\0';
6228 pos += 6;
6229 if (hwaddr_aton(pos, peer)) {
6230 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
6231 return -1;
6232 }
6233
6234 pos = os_strstr(pos, " go_dev_addr=");
6235 if (pos) {
6236 pos += 13;
6237 if (hwaddr_aton(pos, go_dev_addr)) {
6238 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
6239 pos);
6240 return -1;
6241 }
6242 go_dev = go_dev_addr;
6243 }
6244
6245 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
6246}
6247
6248
6249static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
6250{
6251 if (os_strncmp(cmd, "persistent=", 11) == 0)
6252 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
6253 if (os_strncmp(cmd, "group=", 6) == 0)
6254 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
6255
6256 return -1;
6257}
6258
6259
6260static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006261 int id, int freq, int vht_center_freq2,
6262 int ht40, int vht, int vht_chwidth)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006263{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006264 struct wpa_ssid *ssid;
6265
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006266 ssid = wpa_config_get_network(wpa_s->conf, id);
6267 if (ssid == NULL || ssid->disabled != 2) {
6268 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6269 "for persistent P2P group",
6270 id);
6271 return -1;
6272 }
6273
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006274 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
6275 vht_center_freq2, 0, ht40, vht,
6276 vht_chwidth, NULL, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006277}
6278
6279
6280static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
6281{
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006282 int freq = 0, persistent = 0, group_id = -1;
6283 int vht = wpa_s->conf->p2p_go_vht;
6284 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006285 int max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006286 char *token, *context = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006287#ifdef CONFIG_ACS
6288 int acs = 0;
6289#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006290
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006291 while ((token = str_token(cmd, " ", &context))) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07006292 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006293 sscanf(token, "persistent=%d", &group_id) == 1 ||
6294 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006295 continue;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006296#ifdef CONFIG_ACS
6297 } else if (os_strcmp(token, "freq=acs") == 0) {
6298 acs = 1;
6299#endif /* CONFIG_ACS */
6300 } else if (sscanf(token, "freq=%d", &freq) == 1) {
6301 continue;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006302 } else if (os_strcmp(token, "ht40") == 0) {
6303 ht40 = 1;
6304 } else if (os_strcmp(token, "vht") == 0) {
6305 vht = 1;
6306 ht40 = 1;
6307 } else if (os_strcmp(token, "persistent") == 0) {
6308 persistent = 1;
6309 } else {
6310 wpa_printf(MSG_DEBUG,
6311 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6312 token);
6313 return -1;
6314 }
6315 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006316
Roshan Pius3a1667e2018-07-03 15:17:14 -07006317#ifdef CONFIG_ACS
6318 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
6319 (acs || freq == 2 || freq == 5)) {
6320 if (freq == 2 && wpa_s->best_24_freq <= 0) {
6321 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
6322 wpa_s->p2p_go_do_acs = 1;
6323 freq = 0;
6324 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
6325 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
6326 wpa_s->p2p_go_do_acs = 1;
6327 freq = 0;
6328 } else {
6329 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
6330 wpa_s->p2p_go_do_acs = 1;
6331 }
6332 }
6333#endif /* CONFIG_ACS */
6334
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006335 max_oper_chwidth = parse_freq(chwidth, freq2);
6336 if (max_oper_chwidth < 0)
6337 return -1;
6338
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006339 if (group_id >= 0)
6340 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006341 freq, freq2, ht40, vht,
6342 max_oper_chwidth);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006343
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006344 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
6345 max_oper_chwidth);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006346}
6347
6348
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006349static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
6350 char *buf, size_t buflen)
6351{
6352 u8 dev_addr[ETH_ALEN];
6353 struct wpa_ssid *ssid;
6354 int res;
6355 const u8 *iaddr;
6356
6357 ssid = wpa_s->current_ssid;
6358 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
6359 hwaddr_aton(cmd, dev_addr))
6360 return -1;
6361
6362 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
6363 if (!iaddr)
6364 return -1;
6365 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
6366 if (os_snprintf_error(buflen, res))
6367 return -1;
6368 return res;
6369}
6370
6371
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006372static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
6373 const u8 *p2p_dev_addr)
6374{
6375 struct wpa_supplicant *wpa_s;
6376
6377 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6378 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
6379 return 1;
6380 }
6381
6382 return 0;
6383}
6384
6385
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006386static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
6387 char *buf, size_t buflen)
6388{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006389 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006390 int next, res;
6391 const struct p2p_peer_info *info;
6392 char *pos, *end;
6393 char devtype[WPS_DEV_TYPE_BUFSIZE];
6394 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006395 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006396
6397 if (!wpa_s->global->p2p)
6398 return -1;
6399
6400 if (os_strcmp(cmd, "FIRST") == 0) {
6401 addr_ptr = NULL;
6402 next = 0;
6403 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
6404 if (hwaddr_aton(cmd + 5, addr) < 0)
6405 return -1;
6406 addr_ptr = addr;
6407 next = 1;
6408 } else {
6409 if (hwaddr_aton(cmd, addr) < 0)
6410 return -1;
6411 addr_ptr = addr;
6412 next = 0;
6413 }
6414
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006415 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
6416 if (info == NULL)
6417 return -1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006418 group_capab = info->group_capab;
6419
6420 if (group_capab &&
6421 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
6422 wpa_printf(MSG_DEBUG,
6423 "P2P: Could not find any BSS with p2p_dev_addr "
6424 MACSTR ", hence override group_capab from 0x%x to 0",
6425 MAC2STR(info->p2p_device_addr), group_capab);
6426 group_capab = 0;
6427 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006428
6429 pos = buf;
6430 end = buf + buflen;
6431
6432 res = os_snprintf(pos, end - pos, MACSTR "\n"
6433 "pri_dev_type=%s\n"
6434 "device_name=%s\n"
6435 "manufacturer=%s\n"
6436 "model_name=%s\n"
6437 "model_number=%s\n"
6438 "serial_number=%s\n"
6439 "config_methods=0x%x\n"
6440 "dev_capab=0x%x\n"
6441 "group_capab=0x%x\n"
6442 "level=%d\n",
6443 MAC2STR(info->p2p_device_addr),
6444 wps_dev_type_bin2str(info->pri_dev_type,
6445 devtype, sizeof(devtype)),
6446 info->device_name,
6447 info->manufacturer,
6448 info->model_name,
6449 info->model_number,
6450 info->serial_number,
6451 info->config_methods,
6452 info->dev_capab,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006453 group_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006454 info->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006455 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006456 return pos - buf;
6457 pos += res;
6458
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006459 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
6460 {
6461 const u8 *t;
6462 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
6463 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
6464 wps_dev_type_bin2str(t, devtype,
6465 sizeof(devtype)));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006466 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006467 return pos - buf;
6468 pos += res;
6469 }
6470
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006471 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006472 if (ssid) {
6473 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006474 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006475 return pos - buf;
6476 pos += res;
6477 }
6478
6479 res = p2p_get_peer_info_txt(info, pos, end - pos);
6480 if (res < 0)
6481 return pos - buf;
6482 pos += res;
6483
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006484 if (info->vendor_elems) {
6485 res = os_snprintf(pos, end - pos, "vendor_elems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006486 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006487 return pos - buf;
6488 pos += res;
6489
6490 pos += wpa_snprintf_hex(pos, end - pos,
6491 wpabuf_head(info->vendor_elems),
6492 wpabuf_len(info->vendor_elems));
6493
6494 res = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006495 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006496 return pos - buf;
6497 pos += res;
6498 }
6499
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006500 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006501}
6502
6503
Dmitry Shmidt04949592012-07-19 12:16:46 -07006504static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
6505 const char *param)
6506{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006507 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006508
6509 if (wpa_s->global->p2p == NULL)
6510 return -1;
6511
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006512 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
6513 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006514
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006515 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
6516 struct wpa_freq_range *freq;
6517 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07006518 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006519 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006520 }
6521
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006522 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006523 return 0;
6524}
6525
6526
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006527static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
6528{
6529 char *param;
6530
6531 if (wpa_s->global->p2p == NULL)
6532 return -1;
6533
6534 param = os_strchr(cmd, ' ');
6535 if (param == NULL)
6536 return -1;
6537 *param++ = '\0';
6538
6539 if (os_strcmp(cmd, "discoverability") == 0) {
6540 p2p_set_client_discoverability(wpa_s->global->p2p,
6541 atoi(param));
6542 return 0;
6543 }
6544
6545 if (os_strcmp(cmd, "managed") == 0) {
6546 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
6547 return 0;
6548 }
6549
6550 if (os_strcmp(cmd, "listen_channel") == 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08006551 char *pos;
6552 u8 channel, op_class;
6553
6554 channel = atoi(param);
6555 pos = os_strchr(param, ' ');
6556 op_class = pos ? atoi(pos) : 81;
6557
6558 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
6559 channel, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006560 }
6561
6562 if (os_strcmp(cmd, "ssid_postfix") == 0) {
6563 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
6564 os_strlen(param));
6565 }
6566
6567 if (os_strcmp(cmd, "noa") == 0) {
6568 char *pos;
6569 int count, start, duration;
6570 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6571 count = atoi(param);
6572 pos = os_strchr(param, ',');
6573 if (pos == NULL)
6574 return -1;
6575 pos++;
6576 start = atoi(pos);
6577 pos = os_strchr(pos, ',');
6578 if (pos == NULL)
6579 return -1;
6580 pos++;
6581 duration = atoi(pos);
6582 if (count < 0 || count > 255 || start < 0 || duration < 0)
6583 return -1;
6584 if (count == 0 && duration > 0)
6585 return -1;
6586 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6587 "start=%d duration=%d", count, start, duration);
6588 return wpas_p2p_set_noa(wpa_s, count, start, duration);
6589 }
6590
6591 if (os_strcmp(cmd, "ps") == 0)
6592 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
6593
6594 if (os_strcmp(cmd, "oppps") == 0)
6595 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
6596
6597 if (os_strcmp(cmd, "ctwindow") == 0)
6598 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
6599
6600 if (os_strcmp(cmd, "disabled") == 0) {
6601 wpa_s->global->p2p_disabled = atoi(param);
6602 wpa_printf(MSG_DEBUG, "P2P functionality %s",
6603 wpa_s->global->p2p_disabled ?
6604 "disabled" : "enabled");
6605 if (wpa_s->global->p2p_disabled) {
6606 wpas_p2p_stop_find(wpa_s);
6607 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6608 p2p_flush(wpa_s->global->p2p);
6609 }
6610 return 0;
6611 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006612
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006613 if (os_strcmp(cmd, "conc_pref") == 0) {
6614 if (os_strcmp(param, "sta") == 0)
6615 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
6616 else if (os_strcmp(param, "p2p") == 0)
6617 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006618 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006619 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006620 return -1;
6621 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006622 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07006623 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006624 return 0;
6625 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006626
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006627 if (os_strcmp(cmd, "force_long_sd") == 0) {
6628 wpa_s->force_long_sd = atoi(param);
6629 return 0;
6630 }
6631
6632 if (os_strcmp(cmd, "peer_filter") == 0) {
6633 u8 addr[ETH_ALEN];
6634 if (hwaddr_aton(param, addr))
6635 return -1;
6636 p2p_set_peer_filter(wpa_s->global->p2p, addr);
6637 return 0;
6638 }
6639
6640 if (os_strcmp(cmd, "cross_connect") == 0)
6641 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
6642
6643 if (os_strcmp(cmd, "go_apsd") == 0) {
6644 if (os_strcmp(param, "disable") == 0)
6645 wpa_s->set_ap_uapsd = 0;
6646 else {
6647 wpa_s->set_ap_uapsd = 1;
6648 wpa_s->ap_uapsd = atoi(param);
6649 }
6650 return 0;
6651 }
6652
6653 if (os_strcmp(cmd, "client_apsd") == 0) {
6654 if (os_strcmp(param, "disable") == 0)
6655 wpa_s->set_sta_uapsd = 0;
6656 else {
6657 int be, bk, vi, vo;
6658 char *pos;
6659 /* format: BE,BK,VI,VO;max SP Length */
6660 be = atoi(param);
6661 pos = os_strchr(param, ',');
6662 if (pos == NULL)
6663 return -1;
6664 pos++;
6665 bk = atoi(pos);
6666 pos = os_strchr(pos, ',');
6667 if (pos == NULL)
6668 return -1;
6669 pos++;
6670 vi = atoi(pos);
6671 pos = os_strchr(pos, ',');
6672 if (pos == NULL)
6673 return -1;
6674 pos++;
6675 vo = atoi(pos);
6676 /* ignore max SP Length for now */
6677
6678 wpa_s->set_sta_uapsd = 1;
6679 wpa_s->sta_uapsd = 0;
6680 if (be)
6681 wpa_s->sta_uapsd |= BIT(0);
6682 if (bk)
6683 wpa_s->sta_uapsd |= BIT(1);
6684 if (vi)
6685 wpa_s->sta_uapsd |= BIT(2);
6686 if (vo)
6687 wpa_s->sta_uapsd |= BIT(3);
6688 }
6689 return 0;
6690 }
6691
Dmitry Shmidt04949592012-07-19 12:16:46 -07006692 if (os_strcmp(cmd, "disallow_freq") == 0)
6693 return p2p_ctrl_disallow_freq(wpa_s, param);
6694
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006695 if (os_strcmp(cmd, "disc_int") == 0) {
6696 int min_disc_int, max_disc_int, max_disc_tu;
6697 char *pos;
6698
6699 pos = param;
6700
6701 min_disc_int = atoi(pos);
6702 pos = os_strchr(pos, ' ');
6703 if (pos == NULL)
6704 return -1;
6705 *pos++ = '\0';
6706
6707 max_disc_int = atoi(pos);
6708 pos = os_strchr(pos, ' ');
6709 if (pos == NULL)
6710 return -1;
6711 *pos++ = '\0';
6712
6713 max_disc_tu = atoi(pos);
6714
6715 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
6716 max_disc_int, max_disc_tu);
6717 }
6718
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07006719 if (os_strcmp(cmd, "per_sta_psk") == 0) {
6720 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
6721 return 0;
6722 }
6723
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006724#ifdef CONFIG_WPS_NFC
6725 if (os_strcmp(cmd, "nfc_tag") == 0)
6726 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
6727#endif /* CONFIG_WPS_NFC */
6728
6729 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
6730 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
6731 return 0;
6732 }
6733
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006734 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
6735 int op_class, chan;
6736
6737 op_class = atoi(param);
6738 param = os_strchr(param, ':');
6739 if (!param)
6740 return -1;
6741 param++;
6742 chan = atoi(param);
6743 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
6744 chan);
6745 return 0;
6746 }
6747
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006748 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6749 cmd);
6750
6751 return -1;
6752}
6753
6754
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006755static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
6756{
6757 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6758 wpa_s->force_long_sd = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006759
6760#ifdef CONFIG_TESTING_OPTIONS
6761 os_free(wpa_s->get_pref_freq_list_override);
6762 wpa_s->get_pref_freq_list_override = NULL;
6763#endif /* CONFIG_TESTING_OPTIONS */
6764
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006765 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006766 wpa_s->parent->p2ps_method_config_any = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006767 if (wpa_s->global->p2p)
6768 p2p_flush(wpa_s->global->p2p);
6769}
6770
6771
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006772static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
6773{
6774 char *pos, *pos2;
6775 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
6776
6777 if (cmd[0]) {
6778 pos = os_strchr(cmd, ' ');
6779 if (pos == NULL)
6780 return -1;
6781 *pos++ = '\0';
6782 dur1 = atoi(cmd);
6783
6784 pos2 = os_strchr(pos, ' ');
6785 if (pos2)
6786 *pos2++ = '\0';
6787 int1 = atoi(pos);
6788 } else
6789 pos2 = NULL;
6790
6791 if (pos2) {
6792 pos = os_strchr(pos2, ' ');
6793 if (pos == NULL)
6794 return -1;
6795 *pos++ = '\0';
6796 dur2 = atoi(pos2);
6797 int2 = atoi(pos);
6798 }
6799
6800 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
6801}
6802
6803
6804static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
6805{
6806 char *pos;
6807 unsigned int period = 0, interval = 0;
6808
6809 if (cmd[0]) {
6810 pos = os_strchr(cmd, ' ');
6811 if (pos == NULL)
6812 return -1;
6813 *pos++ = '\0';
6814 period = atoi(cmd);
6815 interval = atoi(pos);
6816 }
6817
6818 return wpas_p2p_ext_listen(wpa_s, period, interval);
6819}
6820
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07006821
6822static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
6823{
6824 const char *pos;
6825 u8 peer[ETH_ALEN];
6826 int iface_addr = 0;
6827
6828 pos = cmd;
6829 if (os_strncmp(pos, "iface=", 6) == 0) {
6830 iface_addr = 1;
6831 pos += 6;
6832 }
6833 if (hwaddr_aton(pos, peer))
6834 return -1;
6835
6836 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
6837 return 0;
6838}
6839
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006840
6841static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
6842{
6843 int freq = 0, period = 0, interval = 0, count = 0;
6844
6845 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
6846 {
6847 wpa_printf(MSG_DEBUG,
6848 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
6849 return -1;
6850 }
6851
6852 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
6853}
6854
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006855#endif /* CONFIG_P2P */
6856
6857
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006858static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
6859{
6860 struct wpa_freq_range_list ranges;
6861 int *freqs = NULL;
6862 struct hostapd_hw_modes *mode;
6863 u16 i;
6864
6865 if (wpa_s->hw.modes == NULL)
6866 return NULL;
6867
6868 os_memset(&ranges, 0, sizeof(ranges));
6869 if (freq_range_list_parse(&ranges, val) < 0)
6870 return NULL;
6871
6872 for (i = 0; i < wpa_s->hw.num_modes; i++) {
6873 int j;
6874
6875 mode = &wpa_s->hw.modes[i];
6876 for (j = 0; j < mode->num_channels; j++) {
6877 unsigned int freq;
6878
6879 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
6880 continue;
6881
6882 freq = mode->channels[j].freq;
6883 if (!freq_range_list_includes(&ranges, freq))
6884 continue;
6885
6886 int_array_add_unique(&freqs, freq);
6887 }
6888 }
6889
6890 os_free(ranges.range);
6891 return freqs;
6892}
6893
6894
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006895#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006896
6897static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
6898{
6899 int auto_sel = 0;
6900 int *freqs = NULL;
6901
6902 if (param) {
6903 char *pos;
6904
6905 auto_sel = os_strstr(param, "auto") != NULL;
6906
6907 pos = os_strstr(param, "freq=");
6908 if (pos) {
6909 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
6910 if (freqs == NULL)
6911 return -1;
6912 }
6913
6914 }
6915
6916 return interworking_select(wpa_s, auto_sel, freqs);
6917}
6918
6919
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006920static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
6921 int only_add)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006922{
6923 u8 bssid[ETH_ALEN];
6924 struct wpa_bss *bss;
6925
6926 if (hwaddr_aton(dst, bssid)) {
6927 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
6928 return -1;
6929 }
6930
6931 bss = wpa_bss_get_bssid(wpa_s, bssid);
6932 if (bss == NULL) {
6933 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
6934 MAC2STR(bssid));
6935 return -1;
6936 }
6937
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08006938 if (bss->ssid_len == 0) {
6939 int found = 0;
6940
6941 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
6942 " does not have SSID information", MAC2STR(bssid));
6943
6944 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
6945 list) {
6946 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
6947 bss->ssid_len > 0) {
6948 found = 1;
6949 break;
6950 }
6951 }
6952
6953 if (!found)
6954 return -1;
6955 wpa_printf(MSG_DEBUG,
6956 "Found another matching BSS entry with SSID");
6957 }
6958
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006959 return interworking_connect(wpa_s, bss, only_add);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006960}
6961
6962
6963static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
6964{
6965 u8 dst_addr[ETH_ALEN];
6966 int used;
6967 char *pos;
6968#define MAX_ANQP_INFO_ID 100
6969 u16 id[MAX_ANQP_INFO_ID];
6970 size_t num_id = 0;
Dmitry Shmidt15907092014-03-25 10:42:57 -07006971 u32 subtypes = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006972 u32 mbo_subtypes = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006973
6974 used = hwaddr_aton2(dst, dst_addr);
6975 if (used < 0)
6976 return -1;
6977 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006978 if (*pos == ' ')
6979 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006980 while (num_id < MAX_ANQP_INFO_ID) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07006981 if (os_strncmp(pos, "hs20:", 5) == 0) {
6982#ifdef CONFIG_HS20
6983 int num = atoi(pos + 5);
6984 if (num <= 0 || num > 31)
6985 return -1;
6986 subtypes |= BIT(num);
6987#else /* CONFIG_HS20 */
6988 return -1;
6989#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006990 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
6991#ifdef CONFIG_MBO
6992 int num = atoi(pos + 4);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006993
6994 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006995 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006996 mbo_subtypes |= BIT(num);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006997#else /* CONFIG_MBO */
6998 return -1;
6999#endif /* CONFIG_MBO */
Dmitry Shmidt15907092014-03-25 10:42:57 -07007000 } else {
7001 id[num_id] = atoi(pos);
7002 if (id[num_id])
7003 num_id++;
7004 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007005 pos = os_strchr(pos + 1, ',');
7006 if (pos == NULL)
7007 break;
7008 pos++;
7009 }
7010
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007011 if (num_id == 0 && !subtypes && !mbo_subtypes)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007012 return -1;
7013
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007014 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007015 mbo_subtypes);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007016}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007017
7018
7019static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7020{
7021 u8 dst_addr[ETH_ALEN];
7022 struct wpabuf *advproto, *query = NULL;
7023 int used, ret = -1;
7024 char *pos, *end;
7025 size_t len;
7026
7027 used = hwaddr_aton2(cmd, dst_addr);
7028 if (used < 0)
7029 return -1;
7030
7031 pos = cmd + used;
7032 while (*pos == ' ')
7033 pos++;
7034
7035 /* Advertisement Protocol ID */
7036 end = os_strchr(pos, ' ');
7037 if (end)
7038 len = end - pos;
7039 else
7040 len = os_strlen(pos);
7041 if (len & 0x01)
7042 return -1;
7043 len /= 2;
7044 if (len == 0)
7045 return -1;
7046 advproto = wpabuf_alloc(len);
7047 if (advproto == NULL)
7048 return -1;
7049 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7050 goto fail;
7051
7052 if (end) {
7053 /* Optional Query Request */
7054 pos = end + 1;
7055 while (*pos == ' ')
7056 pos++;
7057
7058 len = os_strlen(pos);
7059 if (len) {
7060 if (len & 0x01)
7061 goto fail;
7062 len /= 2;
7063 if (len == 0)
7064 goto fail;
7065 query = wpabuf_alloc(len);
7066 if (query == NULL)
7067 goto fail;
7068 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7069 goto fail;
7070 }
7071 }
7072
7073 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7074
7075fail:
7076 wpabuf_free(advproto);
7077 wpabuf_free(query);
7078
7079 return ret;
7080}
7081
7082
7083static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7084 size_t buflen)
7085{
7086 u8 addr[ETH_ALEN];
7087 int dialog_token;
7088 int used;
7089 char *pos;
7090 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007091 struct wpabuf *resp;
7092 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007093
7094 used = hwaddr_aton2(cmd, addr);
7095 if (used < 0)
7096 return -1;
7097
7098 pos = cmd + used;
7099 while (*pos == ' ')
7100 pos++;
7101 dialog_token = atoi(pos);
7102
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007103 if (wpa_s->last_gas_resp &&
7104 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
7105 dialog_token == wpa_s->last_gas_dialog_token)
7106 resp = wpa_s->last_gas_resp;
7107 else if (wpa_s->prev_gas_resp &&
7108 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
7109 dialog_token == wpa_s->prev_gas_dialog_token)
7110 resp = wpa_s->prev_gas_resp;
7111 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007112 return -1;
7113
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007114 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007115 start = 0;
7116 requested_len = resp_len;
7117
7118 pos = os_strchr(pos, ' ');
7119 if (pos) {
7120 start = atoi(pos);
7121 if (start > resp_len)
7122 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7123 pos = os_strchr(pos, ',');
7124 if (pos == NULL)
7125 return -1;
7126 pos++;
7127 requested_len = atoi(pos);
7128 if (start + requested_len > resp_len)
7129 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7130 }
7131
7132 if (requested_len * 2 + 1 > buflen)
7133 return os_snprintf(buf, buflen, "FAIL-Too long response");
7134
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007135 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
7136 requested_len);
7137
7138 if (start + requested_len == resp_len) {
7139 /*
7140 * Free memory by dropping the response after it has been
7141 * fetched.
7142 */
7143 if (resp == wpa_s->prev_gas_resp) {
7144 wpabuf_free(wpa_s->prev_gas_resp);
7145 wpa_s->prev_gas_resp = NULL;
7146 } else {
7147 wpabuf_free(wpa_s->last_gas_resp);
7148 wpa_s->last_gas_resp = NULL;
7149 }
7150 }
7151
7152 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007153}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007154#endif /* CONFIG_INTERWORKING */
7155
7156
Dmitry Shmidt04949592012-07-19 12:16:46 -07007157#ifdef CONFIG_HS20
7158
7159static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
7160{
7161 u8 dst_addr[ETH_ALEN];
7162 int used;
7163 char *pos;
7164 u32 subtypes = 0;
7165
7166 used = hwaddr_aton2(dst, dst_addr);
7167 if (used < 0)
7168 return -1;
7169 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007170 if (*pos == ' ')
7171 pos++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007172 for (;;) {
7173 int num = atoi(pos);
7174 if (num <= 0 || num > 31)
7175 return -1;
7176 subtypes |= BIT(num);
7177 pos = os_strchr(pos + 1, ',');
7178 if (pos == NULL)
7179 break;
7180 pos++;
7181 }
7182
7183 if (subtypes == 0)
7184 return -1;
7185
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007186 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007187}
7188
7189
7190static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7191 const u8 *addr, const char *realm)
7192{
7193 u8 *buf;
7194 size_t rlen, len;
7195 int ret;
7196
7197 rlen = os_strlen(realm);
7198 len = 3 + rlen;
7199 buf = os_malloc(len);
7200 if (buf == NULL)
7201 return -1;
7202 buf[0] = 1; /* NAI Home Realm Count */
7203 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
7204 buf[2] = rlen;
7205 os_memcpy(buf + 3, realm, rlen);
7206
7207 ret = hs20_anqp_send_req(wpa_s, addr,
7208 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007209 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007210
7211 os_free(buf);
7212
7213 return ret;
7214}
7215
7216
7217static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7218 char *dst)
7219{
7220 struct wpa_cred *cred = wpa_s->conf->cred;
7221 u8 dst_addr[ETH_ALEN];
7222 int used;
7223 u8 *buf;
7224 size_t len;
7225 int ret;
7226
7227 used = hwaddr_aton2(dst, dst_addr);
7228 if (used < 0)
7229 return -1;
7230
7231 while (dst[used] == ' ')
7232 used++;
7233 if (os_strncmp(dst + used, "realm=", 6) == 0)
7234 return hs20_nai_home_realm_list(wpa_s, dst_addr,
7235 dst + used + 6);
7236
7237 len = os_strlen(dst + used);
7238
7239 if (len == 0 && cred && cred->realm)
7240 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
7241
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07007242 if (len & 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07007243 return -1;
7244 len /= 2;
7245 buf = os_malloc(len);
7246 if (buf == NULL)
7247 return -1;
7248 if (hexstr2bin(dst + used, buf, len) < 0) {
7249 os_free(buf);
7250 return -1;
7251 }
7252
7253 ret = hs20_anqp_send_req(wpa_s, dst_addr,
7254 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007255 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007256 os_free(buf);
7257
7258 return ret;
7259}
7260
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007261
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007262static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
7263 int buflen)
7264{
7265 u8 dst_addr[ETH_ALEN];
7266 int used;
7267 char *ctx = NULL, *icon, *poffset, *psize;
7268
7269 used = hwaddr_aton2(cmd, dst_addr);
7270 if (used < 0)
7271 return -1;
7272 cmd += used;
7273
7274 icon = str_token(cmd, " ", &ctx);
7275 poffset = str_token(cmd, " ", &ctx);
7276 psize = str_token(cmd, " ", &ctx);
7277 if (!icon || !poffset || !psize)
7278 return -1;
7279
7280 wpa_s->fetch_osu_icon_in_progress = 0;
7281 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
7282 reply, buflen);
7283}
7284
7285
7286static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
7287{
7288 u8 dst_addr[ETH_ALEN];
7289 int used;
7290 char *icon;
7291
7292 if (!cmd[0])
7293 return hs20_del_icon(wpa_s, NULL, NULL);
7294
7295 used = hwaddr_aton2(cmd, dst_addr);
7296 if (used < 0)
7297 return -1;
7298
7299 while (cmd[used] == ' ')
7300 used++;
7301 icon = cmd[used] ? &cmd[used] : NULL;
7302
7303 return hs20_del_icon(wpa_s, dst_addr, icon);
7304}
7305
7306
7307static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007308{
7309 u8 dst_addr[ETH_ALEN];
7310 int used;
7311 char *icon;
7312
7313 used = hwaddr_aton2(cmd, dst_addr);
7314 if (used < 0)
7315 return -1;
7316
7317 while (cmd[used] == ' ')
7318 used++;
7319 icon = &cmd[used];
7320
7321 wpa_s->fetch_osu_icon_in_progress = 0;
7322 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007323 (u8 *) icon, os_strlen(icon), inmem);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007324}
7325
Dmitry Shmidt04949592012-07-19 12:16:46 -07007326#endif /* CONFIG_HS20 */
7327
7328
Dmitry Shmidt04949592012-07-19 12:16:46 -07007329#ifdef CONFIG_AUTOSCAN
7330
7331static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
7332 char *cmd)
7333{
7334 enum wpa_states state = wpa_s->wpa_state;
7335 char *new_params = NULL;
7336
7337 if (os_strlen(cmd) > 0) {
7338 new_params = os_strdup(cmd);
7339 if (new_params == NULL)
7340 return -1;
7341 }
7342
7343 os_free(wpa_s->conf->autoscan);
7344 wpa_s->conf->autoscan = new_params;
7345
7346 if (wpa_s->conf->autoscan == NULL)
7347 autoscan_deinit(wpa_s);
7348 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
7349 autoscan_init(wpa_s, 1);
7350 else if (state == WPA_SCANNING)
7351 wpa_supplicant_reinit_autoscan(wpa_s);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007352 else
7353 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
7354 wpa_supplicant_state_txt(state));
Dmitry Shmidt04949592012-07-19 12:16:46 -07007355
7356 return 0;
7357}
7358
7359#endif /* CONFIG_AUTOSCAN */
7360
7361
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007362#ifdef CONFIG_WNM
7363
7364static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
7365{
7366 int enter;
7367 int intval = 0;
7368 char *pos;
7369 int ret;
7370 struct wpabuf *tfs_req = NULL;
7371
7372 if (os_strncmp(cmd, "enter", 5) == 0)
7373 enter = 1;
7374 else if (os_strncmp(cmd, "exit", 4) == 0)
7375 enter = 0;
7376 else
7377 return -1;
7378
7379 pos = os_strstr(cmd, " interval=");
7380 if (pos)
7381 intval = atoi(pos + 10);
7382
7383 pos = os_strstr(cmd, " tfs_req=");
7384 if (pos) {
7385 char *end;
7386 size_t len;
7387 pos += 9;
7388 end = os_strchr(pos, ' ');
7389 if (end)
7390 len = end - pos;
7391 else
7392 len = os_strlen(pos);
7393 if (len & 1)
7394 return -1;
7395 len /= 2;
7396 tfs_req = wpabuf_alloc(len);
7397 if (tfs_req == NULL)
7398 return -1;
7399 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
7400 wpabuf_free(tfs_req);
7401 return -1;
7402 }
7403 }
7404
7405 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
7406 WNM_SLEEP_MODE_EXIT, intval,
7407 tfs_req);
7408 wpabuf_free(tfs_req);
7409
7410 return ret;
7411}
7412
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007413
7414static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
7415{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007416 int query_reason, list = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007417 char *btm_candidates = NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007418
7419 query_reason = atoi(cmd);
7420
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007421 cmd = os_strchr(cmd, ' ');
7422 if (cmd) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007423 if (os_strncmp(cmd, " list", 5) == 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007424 list = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007425 else
7426 btm_candidates = cmd;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007427 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007428
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007429 wpa_printf(MSG_DEBUG,
7430 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7431 query_reason, list ? " candidate list" : "");
7432
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007433 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
7434 btm_candidates,
7435 list);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007436}
7437
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007438#endif /* CONFIG_WNM */
7439
7440
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007441static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
7442 size_t buflen)
7443{
7444 struct wpa_signal_info si;
7445 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007446 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007447
7448 ret = wpa_drv_signal_poll(wpa_s, &si);
7449 if (ret)
7450 return -1;
7451
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007452 pos = buf;
7453 end = buf + buflen;
7454
7455 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007456 "NOISE=%d\nFREQUENCY=%u\n",
7457 si.current_signal, si.current_txrate / 1000,
7458 si.current_noise, si.frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007459 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007460 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007461 pos += ret;
7462
7463 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
7464 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007465 channel_width_to_string(si.chanwidth));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007466 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007467 return -1;
7468 pos += ret;
7469 }
7470
Roshan Pius3a1667e2018-07-03 15:17:14 -07007471 if (si.center_frq1 > 0) {
7472 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
7473 si.center_frq1);
7474 if (os_snprintf_error(end - pos, ret))
7475 return -1;
7476 pos += ret;
7477 }
7478
7479 if (si.center_frq2 > 0) {
7480 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
7481 si.center_frq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007482 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007483 return -1;
7484 pos += ret;
7485 }
7486
7487 if (si.avg_signal) {
7488 ret = os_snprintf(pos, end - pos,
7489 "AVG_RSSI=%d\n", si.avg_signal);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007490 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007491 return -1;
7492 pos += ret;
7493 }
7494
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07007495 if (si.avg_beacon_signal) {
7496 ret = os_snprintf(pos, end - pos,
7497 "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
7498 if (os_snprintf_error(end - pos, ret))
7499 return -1;
7500 pos += ret;
7501 }
7502
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007503 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007504}
7505
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03007506
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007507static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
7508 const char *cmd)
7509{
7510 const char *pos;
7511 int threshold = 0;
7512 int hysteresis = 0;
7513
7514 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
7515 wpa_printf(MSG_DEBUG,
7516 "Reject SIGNAL_MONITOR command - bgscan is active");
7517 return -1;
7518 }
7519 pos = os_strstr(cmd, "THRESHOLD=");
7520 if (pos)
7521 threshold = atoi(pos + 10);
7522 pos = os_strstr(cmd, "HYSTERESIS=");
7523 if (pos)
7524 hysteresis = atoi(pos + 11);
7525 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
7526}
7527
7528
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007529#ifdef CONFIG_TESTING_OPTIONS
7530int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
7531 enum wpa_driver_if_type if_type,
7532 unsigned int *num,
7533 unsigned int *freq_list)
7534{
7535 char *pos = wpa_s->get_pref_freq_list_override;
7536 char *end;
7537 unsigned int count = 0;
7538
7539 /* Override string format:
7540 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7541
7542 while (pos) {
7543 if (atoi(pos) == (int) if_type)
7544 break;
7545 pos = os_strchr(pos, ' ');
7546 if (pos)
7547 pos++;
7548 }
7549 if (!pos)
7550 return -1;
7551 pos = os_strchr(pos, ':');
7552 if (!pos)
7553 return -1;
7554 pos++;
7555 end = os_strchr(pos, ' ');
7556 while (pos && (!end || pos < end) && count < *num) {
7557 freq_list[count++] = atoi(pos);
7558 pos = os_strchr(pos, ',');
7559 if (pos)
7560 pos++;
7561 }
7562
7563 *num = count;
7564 return 0;
7565}
7566#endif /* CONFIG_TESTING_OPTIONS */
7567
7568
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007569static int wpas_ctrl_iface_get_pref_freq_list(
7570 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
7571{
7572 unsigned int freq_list[100], num = 100, i;
7573 int ret;
7574 enum wpa_driver_if_type iface_type;
7575 char *pos, *end;
7576
7577 pos = buf;
7578 end = buf + buflen;
7579
7580 /* buf: "<interface_type>" */
7581 if (os_strcmp(cmd, "STATION") == 0)
7582 iface_type = WPA_IF_STATION;
7583 else if (os_strcmp(cmd, "AP") == 0)
7584 iface_type = WPA_IF_AP_BSS;
7585 else if (os_strcmp(cmd, "P2P_GO") == 0)
7586 iface_type = WPA_IF_P2P_GO;
7587 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
7588 iface_type = WPA_IF_P2P_CLIENT;
7589 else if (os_strcmp(cmd, "IBSS") == 0)
7590 iface_type = WPA_IF_IBSS;
7591 else if (os_strcmp(cmd, "TDLS") == 0)
7592 iface_type = WPA_IF_TDLS;
7593 else
7594 return -1;
7595
7596 wpa_printf(MSG_DEBUG,
7597 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7598 iface_type, buf);
7599
7600 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
7601 if (ret)
7602 return -1;
7603
7604 for (i = 0; i < num; i++) {
7605 ret = os_snprintf(pos, end - pos, "%s%u",
7606 i > 0 ? "," : "", freq_list[i]);
7607 if (os_snprintf_error(end - pos, ret))
7608 return -1;
7609 pos += ret;
7610 }
7611
7612 return pos - buf;
7613}
7614
7615
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007616static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
7617 char *buf, size_t buflen)
7618{
7619 int ret, i;
7620 char *pos, *end;
7621
7622 ret = os_snprintf(buf, buflen, "%016llX:\n",
7623 (long long unsigned) wpa_s->drv_flags);
7624 if (os_snprintf_error(buflen, ret))
7625 return -1;
7626
7627 pos = buf + ret;
7628 end = buf + buflen;
7629
7630 for (i = 0; i < 64; i++) {
7631 if (wpa_s->drv_flags & (1LLU << i)) {
7632 ret = os_snprintf(pos, end - pos, "%s\n",
7633 driver_flag_to_string(1LLU << i));
7634 if (os_snprintf_error(end - pos, ret))
7635 return -1;
7636 pos += ret;
7637 }
7638 }
7639
7640 return pos - buf;
7641}
7642
7643
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07007644static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
7645 size_t buflen)
7646{
7647 struct hostap_sta_driver_data sta;
7648 int ret;
7649
7650 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
7651 if (ret)
7652 return -1;
7653
7654 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03007655 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007656 if (os_snprintf_error(buflen, ret))
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07007657 return -1;
7658 return ret;
7659}
7660
7661
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007662#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07007663static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
7664 char *buf, size_t buflen)
7665{
7666 int ret;
7667
7668 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07007669 if (ret == 0) {
7670 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
7671 struct p2p_data *p2p = wpa_s->global->p2p;
7672 if (p2p) {
7673 char country[3];
7674 country[0] = cmd[8];
7675 country[1] = cmd[9];
7676 country[2] = 0x04;
7677 p2p_set_country(p2p, country);
7678 }
7679 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007680 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007681 if (os_snprintf_error(buflen, ret))
7682 ret = -1;
Dmitry Shmidt9432e122013-09-12 12:39:30 -07007683 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07007684 return ret;
7685}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007686#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07007687
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07007688
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007689static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
7690 char *buf, size_t buflen)
7691{
7692 int ret;
7693 char *pos;
7694 u8 *data = NULL;
7695 unsigned int vendor_id, subcmd;
7696 struct wpabuf *reply;
7697 size_t data_len = 0;
7698
7699 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7700 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007701 if (!isblank((unsigned char) *pos))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007702 return -EINVAL;
7703
7704 subcmd = strtoul(pos, &pos, 10);
7705
7706 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007707 if (!isblank((unsigned char) *pos++))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007708 return -EINVAL;
7709 data_len = os_strlen(pos);
7710 }
7711
7712 if (data_len) {
7713 data_len /= 2;
7714 data = os_malloc(data_len);
7715 if (!data)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007716 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007717
7718 if (hexstr2bin(pos, data, data_len)) {
7719 wpa_printf(MSG_DEBUG,
7720 "Vendor command: wrong parameter format");
7721 os_free(data);
7722 return -EINVAL;
7723 }
7724 }
7725
7726 reply = wpabuf_alloc((buflen - 1) / 2);
7727 if (!reply) {
7728 os_free(data);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007729 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007730 }
7731
7732 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
7733 reply);
7734
7735 if (ret == 0)
7736 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
7737 wpabuf_len(reply));
7738
7739 wpabuf_free(reply);
7740 os_free(data);
7741
7742 return ret;
7743}
7744
7745
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007746static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
7747{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007748#ifdef CONFIG_P2P
7749 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
7750 wpa_s->global->p2p_init_wpa_s : wpa_s;
7751#endif /* CONFIG_P2P */
7752
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007753 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
7754
Dmitry Shmidt29333592017-01-09 12:27:11 -08007755 if (wpas_abort_ongoing_scan(wpa_s) == 0)
7756 wpa_s->ignore_post_flush_scan_res = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007757
Dmitry Shmidtde47be72016-01-07 12:52:55 -08007758 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
7759 /*
7760 * Avoid possible auto connect re-connection on getting
7761 * disconnected due to state flush.
7762 */
7763 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
7764 }
7765
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007766#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08007767 wpas_p2p_group_remove(p2p_wpa_s, "*");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007768 wpas_p2p_cancel(p2p_wpa_s);
7769 p2p_ctrl_flush(p2p_wpa_s);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007770 wpas_p2p_service_flush(p2p_wpa_s);
7771 p2p_wpa_s->global->p2p_disabled = 0;
7772 p2p_wpa_s->global->p2p_per_sta_psk = 0;
7773 p2p_wpa_s->conf->num_sec_device_types = 0;
7774 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
7775 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
7776 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007777 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08007778 p2p_wpa_s->global->pending_p2ps_group = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007779 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007780#endif /* CONFIG_P2P */
7781
7782#ifdef CONFIG_WPS_TESTING
7783 wps_version_number = 0x20;
7784 wps_testing_dummy_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007785 wps_corrupt_pkhash = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08007786 wps_force_auth_types_in_use = 0;
7787 wps_force_encr_types_in_use = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007788#endif /* CONFIG_WPS_TESTING */
7789#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007790 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007791 wpas_wps_cancel(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007792 wps_registrar_flush(wpa_s->wps->registrar);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007793#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07007794 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007795 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007796
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007797#ifdef CONFIG_DPP
7798 wpas_dpp_deinit(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07007799 wpa_s->dpp_init_max_tries = 0;
7800 wpa_s->dpp_init_retry_time = 0;
7801 wpa_s->dpp_resp_wait_time = 0;
7802 wpa_s->dpp_resp_max_tries = 0;
7803 wpa_s->dpp_resp_retry_time = 0;
7804#ifdef CONFIG_TESTING_OPTIONS
7805 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
7806 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
7807 dpp_pkex_ephemeral_key_override_len = 0;
7808 dpp_protocol_key_override_len = 0;
7809 dpp_nonce_override_len = 0;
7810#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007811#endif /* CONFIG_DPP */
7812
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007813#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007814#ifdef CONFIG_TDLS_TESTING
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007815 tdls_testing = 0;
7816#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007817 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
7818 wpa_tdls_enable(wpa_s->wpa, 1);
7819#endif /* CONFIG_TDLS */
7820
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07007821 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
7822 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
7823
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007824 wpa_s->no_keep_alive = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08007825 wpa_s->own_disconnect_req = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007826
7827 os_free(wpa_s->disallow_aps_bssid);
7828 wpa_s->disallow_aps_bssid = NULL;
7829 wpa_s->disallow_aps_bssid_count = 0;
7830 os_free(wpa_s->disallow_aps_ssid);
7831 wpa_s->disallow_aps_ssid = NULL;
7832 wpa_s->disallow_aps_ssid_count = 0;
7833
7834 wpa_s->set_sta_uapsd = 0;
7835 wpa_s->sta_uapsd = 0;
7836
7837 wpa_drv_radio_disable(wpa_s, 0);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007838 wpa_blacklist_clear(wpa_s);
Dmitry Shmidt4b060592013-04-29 16:42:49 -07007839 wpa_s->extra_blacklist_count = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007840 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
7841 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08007842 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08007843 wpa_s->conf->auto_interworking = 0;
7844 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007845
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007846 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
7847 rsn_preauth_deinit(wpa_s->wpa);
7848
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007849 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
7850 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
7851 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
7852 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
7853
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08007854 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007855 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007856
7857 wpa_s->next_ssid = NULL;
7858
7859#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007860#ifdef CONFIG_HS20
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007861 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007862 hs20_del_icon(wpa_s, NULL, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007863#endif /* CONFIG_HS20 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007864#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt818ea482014-03-10 13:15:21 -07007865
7866 wpa_s->ext_mgmt_frame_handling = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007867 wpa_s->ext_eapol_frame_io = 0;
7868#ifdef CONFIG_TESTING_OPTIONS
7869 wpa_s->extra_roc_dur = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007870 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007871 wpa_s->p2p_go_csa_on_inv = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07007872 wpa_s->ignore_auth_resp = 0;
7873 wpa_s->ignore_assoc_disallow = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007874 wpa_s->testing_resend_assoc = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07007875 wpa_s->reject_btm_req_reason = 0;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08007876 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007877 os_free(wpa_s->get_pref_freq_list_override);
7878 wpa_s->get_pref_freq_list_override = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007879 wpabuf_free(wpa_s->sae_commit_override);
7880 wpa_s->sae_commit_override = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007881#ifdef CONFIG_DPP
7882 os_free(wpa_s->dpp_config_obj_override);
7883 wpa_s->dpp_config_obj_override = NULL;
7884 os_free(wpa_s->dpp_discovery_override);
7885 wpa_s->dpp_discovery_override = NULL;
7886 os_free(wpa_s->dpp_groups_override);
7887 wpa_s->dpp_groups_override = NULL;
7888 dpp_test = DPP_TEST_DISABLED;
7889#endif /* CONFIG_DPP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007890#endif /* CONFIG_TESTING_OPTIONS */
7891
7892 wpa_s->disconnected = 0;
7893 os_free(wpa_s->next_scan_freqs);
7894 wpa_s->next_scan_freqs = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007895 os_free(wpa_s->select_network_scan_freqs);
7896 wpa_s->select_network_scan_freqs = NULL;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007897
7898 wpa_bss_flush(wpa_s);
7899 if (!dl_list_empty(&wpa_s->bss)) {
7900 wpa_printf(MSG_DEBUG,
7901 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7902 MACSTR " pending_bssid=" MACSTR,
7903 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
7904 MAC2STR(wpa_s->bssid),
7905 MAC2STR(wpa_s->pending_bssid));
7906 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07007907
7908 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -08007909 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007910
7911#ifdef CONFIG_SME
7912 wpa_s->sme.last_unprot_disconnect.sec = 0;
7913#endif /* CONFIG_SME */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007914
7915 wpabuf_free(wpa_s->ric_ies);
7916 wpa_s->ric_ies = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007917}
7918
7919
7920static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
7921 char *buf, size_t buflen)
7922{
7923 struct wpa_radio_work *work;
7924 char *pos, *end;
7925 struct os_reltime now, diff;
7926
7927 pos = buf;
7928 end = buf + buflen;
7929
7930 os_get_reltime(&now);
7931
7932 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
7933 {
7934 int ret;
7935
7936 os_reltime_sub(&now, &work->time, &diff);
7937 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
7938 work->type, work->wpa_s->ifname, work->freq,
7939 work->started, diff.sec, diff.usec);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007940 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007941 break;
7942 pos += ret;
7943 }
7944
7945 return pos - buf;
7946}
7947
7948
7949static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
7950{
7951 struct wpa_radio_work *work = eloop_ctx;
7952 struct wpa_external_work *ework = work->ctx;
7953
7954 wpa_dbg(work->wpa_s, MSG_DEBUG,
7955 "Timing out external radio work %u (%s)",
7956 ework->id, work->type);
7957 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007958 work->wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007959 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07007960 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007961}
7962
7963
7964static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
7965{
7966 struct wpa_external_work *ework = work->ctx;
7967
7968 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08007969 if (work->started)
7970 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
7971 work, NULL);
7972
Dmitry Shmidt849734c2016-05-27 09:59:01 -07007973 /*
7974 * work->type points to a buffer in ework, so need to replace
7975 * that here with a fixed string to avoid use of freed memory
7976 * in debug prints.
7977 */
7978 work->type = "freed-ext-work";
7979 work->ctx = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007980 os_free(ework);
7981 return;
7982 }
7983
7984 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
7985 ework->id, ework->type);
7986 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007987 work->wpa_s->ext_work_in_progress = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007988 if (!ework->timeout)
7989 ework->timeout = 10;
7990 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
7991 work, NULL);
7992}
7993
7994
7995static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
7996 char *buf, size_t buflen)
7997{
7998 struct wpa_external_work *ework;
7999 char *pos, *pos2;
8000 size_t type_len;
8001 int ret;
8002 unsigned int freq = 0;
8003
8004 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8005
8006 ework = os_zalloc(sizeof(*ework));
8007 if (ework == NULL)
8008 return -1;
8009
8010 pos = os_strchr(cmd, ' ');
8011 if (pos) {
8012 type_len = pos - cmd;
8013 pos++;
8014
8015 pos2 = os_strstr(pos, "freq=");
8016 if (pos2)
8017 freq = atoi(pos2 + 5);
8018
8019 pos2 = os_strstr(pos, "timeout=");
8020 if (pos2)
8021 ework->timeout = atoi(pos2 + 8);
8022 } else {
8023 type_len = os_strlen(cmd);
8024 }
8025 if (4 + type_len >= sizeof(ework->type))
8026 type_len = sizeof(ework->type) - 4 - 1;
8027 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
8028 os_memcpy(ework->type + 4, cmd, type_len);
8029 ework->type[4 + type_len] = '\0';
8030
8031 wpa_s->ext_work_id++;
8032 if (wpa_s->ext_work_id == 0)
8033 wpa_s->ext_work_id++;
8034 ework->id = wpa_s->ext_work_id;
8035
8036 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
8037 ework) < 0) {
8038 os_free(ework);
8039 return -1;
8040 }
8041
8042 ret = os_snprintf(buf, buflen, "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008043 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008044 return -1;
8045 return ret;
8046}
8047
8048
8049static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
8050{
8051 struct wpa_radio_work *work;
8052 unsigned int id = atoi(cmd);
8053
8054 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8055 {
8056 struct wpa_external_work *ework;
8057
8058 if (os_strncmp(work->type, "ext:", 4) != 0)
8059 continue;
8060 ework = work->ctx;
8061 if (id && ework->id != id)
8062 continue;
8063 wpa_dbg(wpa_s, MSG_DEBUG,
8064 "Completed external radio work %u (%s)",
8065 ework->id, ework->type);
8066 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008067 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008068 radio_work_done(work);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07008069 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008070 return 3; /* "OK\n" */
8071 }
8072
8073 return -1;
8074}
8075
8076
8077static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
8078 char *buf, size_t buflen)
8079{
8080 if (os_strcmp(cmd, "show") == 0)
8081 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
8082 if (os_strncmp(cmd, "add ", 4) == 0)
8083 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
8084 if (os_strncmp(cmd, "done ", 5) == 0)
8085 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
8086 return -1;
8087}
8088
8089
8090void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
8091{
8092 struct wpa_radio_work *work, *tmp;
8093
Dmitry Shmidt18463232014-01-24 12:29:41 -08008094 if (!wpa_s || !wpa_s->radio)
8095 return;
8096
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008097 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
8098 struct wpa_radio_work, list) {
8099 struct wpa_external_work *ework;
8100
8101 if (os_strncmp(work->type, "ext:", 4) != 0)
8102 continue;
8103 ework = work->ctx;
8104 wpa_dbg(wpa_s, MSG_DEBUG,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07008105 "Flushing%s external radio work %u (%s)",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008106 work->started ? " started" : "", ework->id,
8107 ework->type);
8108 if (work->started)
8109 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8110 work, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008111 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008112 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008113 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008114}
8115
8116
Dmitry Shmidt051af732013-10-22 13:52:46 -07008117static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
8118{
8119 struct wpa_supplicant *wpa_s = eloop_ctx;
8120 eapol_sm_notify_ctrl_response(wpa_s->eapol);
8121}
8122
8123
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008124static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
8125 unsigned int *scan_id_count, int scan_id[])
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008126{
8127 const char *pos = value;
8128
8129 while (pos) {
8130 if (*pos == ' ' || *pos == '\0')
8131 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008132 if (*scan_id_count == MAX_SCAN_ID)
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008133 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008134 scan_id[(*scan_id_count)++] = atoi(pos);
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008135 pos = os_strchr(pos, ',');
8136 if (pos)
8137 pos++;
8138 }
8139
8140 return 0;
8141}
8142
8143
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008144static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
8145 char *reply, int reply_size, int *reply_len)
8146{
8147 char *pos;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008148 unsigned int manual_scan_passive = 0;
8149 unsigned int manual_scan_use_id = 0;
8150 unsigned int manual_scan_only_new = 0;
8151 unsigned int scan_only = 0;
8152 unsigned int scan_id_count = 0;
8153 int scan_id[MAX_SCAN_ID];
8154 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
8155 struct wpa_scan_results *scan_res);
8156 int *manual_scan_freqs = NULL;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008157 struct wpa_ssid_value *ssid = NULL, *ns;
8158 unsigned int ssid_count = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008159
8160 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
8161 *reply_len = -1;
8162 return;
8163 }
8164
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008165 if (radio_work_pending(wpa_s, "scan")) {
8166 wpa_printf(MSG_DEBUG,
8167 "Pending scan scheduled - reject new request");
8168 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8169 return;
8170 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008171
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008172#ifdef CONFIG_INTERWORKING
8173 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
8174 wpa_printf(MSG_DEBUG,
8175 "Interworking select in progress - reject new scan");
8176 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8177 return;
8178 }
8179#endif /* CONFIG_INTERWORKING */
8180
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008181 if (params) {
8182 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008183 scan_only = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008184
8185 pos = os_strstr(params, "freq=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008186 if (pos) {
8187 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
8188 pos + 5);
8189 if (manual_scan_freqs == NULL) {
8190 *reply_len = -1;
8191 goto done;
8192 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008193 }
8194
8195 pos = os_strstr(params, "passive=");
8196 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008197 manual_scan_passive = !!atoi(pos + 8);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008198
8199 pos = os_strstr(params, "use_id=");
8200 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008201 manual_scan_use_id = atoi(pos + 7);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008202
8203 pos = os_strstr(params, "only_new=1");
8204 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008205 manual_scan_only_new = 1;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008206
8207 pos = os_strstr(params, "scan_id=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008208 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
8209 scan_id) < 0) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008210 *reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008211 goto done;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008212 }
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008213
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008214 pos = os_strstr(params, "bssid=");
8215 if (pos) {
8216 u8 bssid[ETH_ALEN];
8217
8218 pos += 6;
8219 if (hwaddr_aton(pos, bssid)) {
8220 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
8221 *reply_len = -1;
8222 goto done;
8223 }
8224 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
8225 }
8226
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008227 pos = params;
8228 while (pos && *pos != '\0') {
8229 if (os_strncmp(pos, "ssid ", 5) == 0) {
8230 char *end;
8231
8232 pos += 5;
8233 end = pos;
8234 while (*end) {
8235 if (*end == '\0' || *end == ' ')
8236 break;
8237 end++;
8238 }
8239
8240 ns = os_realloc_array(
8241 ssid, ssid_count + 1,
8242 sizeof(struct wpa_ssid_value));
8243 if (ns == NULL) {
8244 *reply_len = -1;
8245 goto done;
8246 }
8247 ssid = ns;
8248
8249 if ((end - pos) & 0x01 ||
8250 end - pos > 2 * SSID_MAX_LEN ||
8251 hexstr2bin(pos, ssid[ssid_count].ssid,
8252 (end - pos) / 2) < 0) {
8253 wpa_printf(MSG_DEBUG,
8254 "Invalid SSID value '%s'",
8255 pos);
8256 *reply_len = -1;
8257 goto done;
8258 }
8259 ssid[ssid_count].ssid_len = (end - pos) / 2;
8260 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
8261 ssid[ssid_count].ssid,
8262 ssid[ssid_count].ssid_len);
8263 ssid_count++;
8264 pos = end;
8265 }
8266
8267 pos = os_strchr(pos, ' ');
8268 if (pos)
8269 pos++;
8270 }
8271 }
8272
8273 wpa_s->num_ssids_from_scan_req = ssid_count;
8274 os_free(wpa_s->ssids_from_scan_req);
8275 if (ssid_count) {
8276 wpa_s->ssids_from_scan_req = ssid;
8277 ssid = NULL;
8278 } else {
8279 wpa_s->ssids_from_scan_req = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008280 }
8281
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008282 if (scan_only)
8283 scan_res_handler = scan_only_handler;
8284 else if (wpa_s->scan_res_handler == scan_only_handler)
8285 scan_res_handler = NULL;
8286 else
8287 scan_res_handler = wpa_s->scan_res_handler;
8288
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008289 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
8290 ((wpa_s->wpa_state <= WPA_SCANNING) ||
8291 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008292 wpa_s->manual_scan_passive = manual_scan_passive;
8293 wpa_s->manual_scan_use_id = manual_scan_use_id;
8294 wpa_s->manual_scan_only_new = manual_scan_only_new;
8295 wpa_s->scan_id_count = scan_id_count;
8296 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8297 wpa_s->scan_res_handler = scan_res_handler;
8298 os_free(wpa_s->manual_scan_freqs);
8299 wpa_s->manual_scan_freqs = manual_scan_freqs;
8300 manual_scan_freqs = NULL;
8301
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008302 wpa_s->normal_scans = 0;
8303 wpa_s->scan_req = MANUAL_SCAN_REQ;
8304 wpa_s->after_wps = 0;
8305 wpa_s->known_wps_freq = 0;
8306 wpa_supplicant_req_scan(wpa_s, 0, 0);
8307 if (wpa_s->manual_scan_use_id) {
8308 wpa_s->manual_scan_id++;
8309 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8310 wpa_s->manual_scan_id);
8311 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8312 wpa_s->manual_scan_id);
8313 }
8314 } else if (wpa_s->sched_scanning) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008315 wpa_s->manual_scan_passive = manual_scan_passive;
8316 wpa_s->manual_scan_use_id = manual_scan_use_id;
8317 wpa_s->manual_scan_only_new = manual_scan_only_new;
8318 wpa_s->scan_id_count = scan_id_count;
8319 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8320 wpa_s->scan_res_handler = scan_res_handler;
8321 os_free(wpa_s->manual_scan_freqs);
8322 wpa_s->manual_scan_freqs = manual_scan_freqs;
8323 manual_scan_freqs = NULL;
8324
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008325 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
8326 wpa_supplicant_cancel_sched_scan(wpa_s);
8327 wpa_s->scan_req = MANUAL_SCAN_REQ;
8328 wpa_supplicant_req_scan(wpa_s, 0, 0);
8329 if (wpa_s->manual_scan_use_id) {
8330 wpa_s->manual_scan_id++;
8331 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8332 wpa_s->manual_scan_id);
8333 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8334 wpa_s->manual_scan_id);
8335 }
8336 } else {
8337 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
8338 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8339 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008340
8341done:
8342 os_free(manual_scan_freqs);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008343 os_free(ssid);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008344}
8345
8346
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008347#ifdef CONFIG_TESTING_OPTIONS
8348
8349static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
8350 unsigned int freq, const u8 *dst,
8351 const u8 *src, const u8 *bssid,
8352 const u8 *data, size_t data_len,
8353 enum offchannel_send_action_result
8354 result)
8355{
8356 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8357 " src=" MACSTR " bssid=" MACSTR " result=%s",
8358 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
8359 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
8360 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
8361 "NO_ACK" : "FAILED"));
8362}
8363
8364
8365static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
8366{
8367 char *pos, *param;
8368 size_t len;
8369 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
8370 int res, used;
8371 int freq = 0, no_cck = 0, wait_time = 0;
8372
8373 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8374 * <action=Action frame payload> */
8375
8376 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
8377
8378 pos = cmd;
8379 used = hwaddr_aton2(pos, da);
8380 if (used < 0)
8381 return -1;
8382 pos += used;
8383 while (*pos == ' ')
8384 pos++;
8385 used = hwaddr_aton2(pos, bssid);
8386 if (used < 0)
8387 return -1;
8388 pos += used;
8389
8390 param = os_strstr(pos, " freq=");
8391 if (param) {
8392 param += 6;
8393 freq = atoi(param);
8394 }
8395
8396 param = os_strstr(pos, " no_cck=");
8397 if (param) {
8398 param += 8;
8399 no_cck = atoi(param);
8400 }
8401
8402 param = os_strstr(pos, " wait_time=");
8403 if (param) {
8404 param += 11;
8405 wait_time = atoi(param);
8406 }
8407
8408 param = os_strstr(pos, " action=");
8409 if (param == NULL)
8410 return -1;
8411 param += 8;
8412
8413 len = os_strlen(param);
8414 if (len & 1)
8415 return -1;
8416 len /= 2;
8417
8418 buf = os_malloc(len);
8419 if (buf == NULL)
8420 return -1;
8421
8422 if (hexstr2bin(param, buf, len) < 0) {
8423 os_free(buf);
8424 return -1;
8425 }
8426
8427 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
8428 buf, len, wait_time,
8429 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
8430 os_free(buf);
8431 return res;
8432}
8433
8434
8435static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
8436{
8437 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
8438 offchannel_send_action_done(wpa_s);
8439}
8440
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07008441
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008442static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
8443 char *cmd)
8444{
8445 char *pos, *param;
8446 size_t len;
8447 u8 *buf;
8448 int freq = 0, datarate = 0, ssi_signal = 0;
8449 union wpa_event_data event;
8450
8451 if (!wpa_s->ext_mgmt_frame_handling)
8452 return -1;
8453
8454 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8455
8456 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
8457
8458 pos = cmd;
8459 param = os_strstr(pos, "freq=");
8460 if (param) {
8461 param += 5;
8462 freq = atoi(param);
8463 }
8464
8465 param = os_strstr(pos, " datarate=");
8466 if (param) {
8467 param += 10;
8468 datarate = atoi(param);
8469 }
8470
8471 param = os_strstr(pos, " ssi_signal=");
8472 if (param) {
8473 param += 12;
8474 ssi_signal = atoi(param);
8475 }
8476
8477 param = os_strstr(pos, " frame=");
8478 if (param == NULL)
8479 return -1;
8480 param += 7;
8481
8482 len = os_strlen(param);
8483 if (len & 1)
8484 return -1;
8485 len /= 2;
8486
8487 buf = os_malloc(len);
8488 if (buf == NULL)
8489 return -1;
8490
8491 if (hexstr2bin(param, buf, len) < 0) {
8492 os_free(buf);
8493 return -1;
8494 }
8495
8496 os_memset(&event, 0, sizeof(event));
8497 event.rx_mgmt.freq = freq;
8498 event.rx_mgmt.frame = buf;
8499 event.rx_mgmt.frame_len = len;
8500 event.rx_mgmt.ssi_signal = ssi_signal;
8501 event.rx_mgmt.datarate = datarate;
8502 wpa_s->ext_mgmt_frame_handling = 0;
8503 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
8504 wpa_s->ext_mgmt_frame_handling = 1;
8505
8506 os_free(buf);
8507
8508 return 0;
8509}
8510
8511
Paul Stewart092955c2017-02-06 09:13:09 -08008512static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
8513 char *param)
8514{
8515 struct wpa_scan_res *res;
8516 struct os_reltime now;
8517 char *pos, *end;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008518 int ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08008519
8520 if (!param)
8521 return -1;
8522
8523 if (os_strcmp(param, "START") == 0) {
8524 wpa_bss_update_start(wpa_s);
8525 return 0;
8526 }
8527
8528 if (os_strcmp(param, "END") == 0) {
8529 wpa_bss_update_end(wpa_s, NULL, 1);
8530 return 0;
8531 }
8532
8533 if (os_strncmp(param, "BSS ", 4) != 0)
8534 return -1;
8535 param += 3;
8536
8537 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
8538 if (!res)
8539 return -1;
8540
8541 pos = os_strstr(param, " flags=");
8542 if (pos)
8543 res->flags = strtol(pos + 7, NULL, 16);
8544
8545 pos = os_strstr(param, " bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008546 if (pos && hwaddr_aton(pos + 7, res->bssid))
8547 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008548
8549 pos = os_strstr(param, " freq=");
8550 if (pos)
8551 res->freq = atoi(pos + 6);
8552
8553 pos = os_strstr(param, " beacon_int=");
8554 if (pos)
8555 res->beacon_int = atoi(pos + 12);
8556
8557 pos = os_strstr(param, " caps=");
8558 if (pos)
8559 res->caps = strtol(pos + 6, NULL, 16);
8560
8561 pos = os_strstr(param, " qual=");
8562 if (pos)
8563 res->qual = atoi(pos + 6);
8564
8565 pos = os_strstr(param, " noise=");
8566 if (pos)
8567 res->noise = atoi(pos + 7);
8568
8569 pos = os_strstr(param, " level=");
8570 if (pos)
8571 res->level = atoi(pos + 7);
8572
8573 pos = os_strstr(param, " tsf=");
8574 if (pos)
8575 res->tsf = strtoll(pos + 5, NULL, 16);
8576
8577 pos = os_strstr(param, " age=");
8578 if (pos)
8579 res->age = atoi(pos + 5);
8580
8581 pos = os_strstr(param, " est_throughput=");
8582 if (pos)
8583 res->est_throughput = atoi(pos + 16);
8584
8585 pos = os_strstr(param, " snr=");
8586 if (pos)
8587 res->snr = atoi(pos + 5);
8588
8589 pos = os_strstr(param, " parent_tsf=");
8590 if (pos)
8591 res->parent_tsf = strtoll(pos + 7, NULL, 16);
8592
8593 pos = os_strstr(param, " tsf_bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008594 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
8595 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008596
8597 pos = os_strstr(param, " ie=");
8598 if (pos) {
8599 pos += 4;
8600 end = os_strchr(pos, ' ');
8601 if (!end)
8602 end = pos + os_strlen(pos);
8603 res->ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008604 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
8605 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008606 }
8607
8608 pos = os_strstr(param, " beacon_ie=");
8609 if (pos) {
8610 pos += 11;
8611 end = os_strchr(pos, ' ');
8612 if (!end)
8613 end = pos + os_strlen(pos);
8614 res->beacon_ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008615 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
8616 res->beacon_ie_len))
8617 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008618 }
8619
8620 os_get_reltime(&now);
8621 wpa_bss_update_scan_res(wpa_s, res, &now);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008622 ret = 0;
8623fail:
Paul Stewart092955c2017-02-06 09:13:09 -08008624 os_free(res);
8625
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008626 return ret;
Paul Stewart092955c2017-02-06 09:13:09 -08008627}
8628
8629
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07008630static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
8631{
8632 char *pos, *param;
8633 union wpa_event_data event;
8634 enum wpa_event_type ev;
8635
8636 /* <event name> [parameters..] */
8637
8638 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
8639
8640 pos = cmd;
8641 param = os_strchr(pos, ' ');
8642 if (param)
8643 *param++ = '\0';
8644
8645 os_memset(&event, 0, sizeof(event));
8646
8647 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
8648 ev = EVENT_INTERFACE_ENABLED;
8649 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
8650 ev = EVENT_INTERFACE_DISABLED;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07008651 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
8652 ev = EVENT_AVOID_FREQUENCIES;
8653 if (param == NULL)
8654 param = "";
8655 if (freq_range_list_parse(&event.freq_range, param) < 0)
8656 return -1;
8657 wpa_supplicant_event(wpa_s, ev, &event);
8658 os_free(event.freq_range.range);
8659 return 0;
Paul Stewart092955c2017-02-06 09:13:09 -08008660 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
8661 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07008662 } else {
8663 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
8664 cmd);
8665 return -1;
8666 }
8667
8668 wpa_supplicant_event(wpa_s, ev, &event);
8669
8670 return 0;
8671}
8672
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008673
8674static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
8675{
8676 char *pos;
8677 u8 src[ETH_ALEN], *buf;
8678 int used;
8679 size_t len;
8680
8681 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
8682
8683 pos = cmd;
8684 used = hwaddr_aton2(pos, src);
8685 if (used < 0)
8686 return -1;
8687 pos += used;
8688 while (*pos == ' ')
8689 pos++;
8690
8691 len = os_strlen(pos);
8692 if (len & 1)
8693 return -1;
8694 len /= 2;
8695
8696 buf = os_malloc(len);
8697 if (buf == NULL)
8698 return -1;
8699
8700 if (hexstr2bin(pos, buf, len) < 0) {
8701 os_free(buf);
8702 return -1;
8703 }
8704
8705 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
8706 os_free(buf);
8707
8708 return 0;
8709}
8710
8711
8712static u16 ipv4_hdr_checksum(const void *buf, size_t len)
8713{
8714 size_t i;
8715 u32 sum = 0;
8716 const u16 *pos = buf;
8717
8718 for (i = 0; i < len / 2; i++)
8719 sum += *pos++;
8720
8721 while (sum >> 16)
8722 sum = (sum & 0xffff) + (sum >> 16);
8723
8724 return sum ^ 0xffff;
8725}
8726
8727
8728#define HWSIM_PACKETLEN 1500
8729#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8730
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07008731static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
8732 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008733{
8734 struct wpa_supplicant *wpa_s = ctx;
8735 const struct ether_header *eth;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008736 struct iphdr ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008737 const u8 *pos;
8738 unsigned int i;
8739
8740 if (len != HWSIM_PACKETLEN)
8741 return;
8742
8743 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008744 os_memcpy(&ip, eth + 1, sizeof(ip));
8745 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008746
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008747 if (ip.ihl != 5 || ip.version != 4 ||
8748 ntohs(ip.tot_len) != HWSIM_IP_LEN)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008749 return;
8750
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008751 for (i = 0; i < HWSIM_IP_LEN - sizeof(ip); i++) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008752 if (*pos != (u8) i)
8753 return;
8754 pos++;
8755 }
8756
8757 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
8758 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
8759}
8760
8761
8762static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
8763 char *cmd)
8764{
8765 int enabled = atoi(cmd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008766 char *pos;
8767 const char *ifname;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008768
8769 if (!enabled) {
8770 if (wpa_s->l2_test) {
8771 l2_packet_deinit(wpa_s->l2_test);
8772 wpa_s->l2_test = NULL;
8773 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
8774 }
8775 return 0;
8776 }
8777
8778 if (wpa_s->l2_test)
8779 return 0;
8780
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008781 pos = os_strstr(cmd, " ifname=");
8782 if (pos)
8783 ifname = pos + 8;
8784 else
8785 ifname = wpa_s->ifname;
8786
8787 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008788 ETHERTYPE_IP, wpas_data_test_rx,
8789 wpa_s, 1);
8790 if (wpa_s->l2_test == NULL)
8791 return -1;
8792
8793 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
8794
8795 return 0;
8796}
8797
8798
8799static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
8800{
8801 u8 dst[ETH_ALEN], src[ETH_ALEN];
8802 char *pos;
8803 int used;
8804 long int val;
8805 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008806 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008807 struct ether_header *eth;
8808 struct iphdr *ip;
8809 u8 *dpos;
8810 unsigned int i;
8811
8812 if (wpa_s->l2_test == NULL)
8813 return -1;
8814
8815 /* format: <dst> <src> <tos> */
8816
8817 pos = cmd;
8818 used = hwaddr_aton2(pos, dst);
8819 if (used < 0)
8820 return -1;
8821 pos += used;
8822 while (*pos == ' ')
8823 pos++;
8824 used = hwaddr_aton2(pos, src);
8825 if (used < 0)
8826 return -1;
8827 pos += used;
8828
8829 val = strtol(pos, NULL, 0);
8830 if (val < 0 || val > 0xff)
8831 return -1;
8832 tos = val;
8833
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008834 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008835 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
8836 os_memcpy(eth->ether_shost, src, ETH_ALEN);
8837 eth->ether_type = htons(ETHERTYPE_IP);
8838 ip = (struct iphdr *) (eth + 1);
8839 os_memset(ip, 0, sizeof(*ip));
8840 ip->ihl = 5;
8841 ip->version = 4;
8842 ip->ttl = 64;
8843 ip->tos = tos;
8844 ip->tot_len = htons(HWSIM_IP_LEN);
8845 ip->protocol = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008846 ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8847 ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008848 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
8849 dpos = (u8 *) (ip + 1);
8850 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
8851 *dpos++ = i;
8852
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008853 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008854 HWSIM_PACKETLEN) < 0)
8855 return -1;
8856
8857 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
8858 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
8859
8860 return 0;
8861}
8862
8863
8864static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
8865 char *cmd)
8866{
8867 u8 *buf;
8868 struct ether_header *eth;
8869 struct l2_packet_data *l2 = NULL;
8870 size_t len;
8871 u16 ethertype;
8872 int res = -1;
8873
8874 len = os_strlen(cmd);
8875 if (len & 1 || len < ETH_HLEN * 2)
8876 return -1;
8877 len /= 2;
8878
8879 buf = os_malloc(len);
8880 if (buf == NULL)
8881 return -1;
8882
8883 if (hexstr2bin(cmd, buf, len) < 0)
8884 goto done;
8885
8886 eth = (struct ether_header *) buf;
8887 ethertype = ntohs(eth->ether_type);
8888
8889 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
8890 wpas_data_test_rx, wpa_s, 1);
8891 if (l2 == NULL)
8892 goto done;
8893
8894 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
8895 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
8896done:
8897 if (l2)
8898 l2_packet_deinit(l2);
8899 os_free(buf);
8900
8901 return res < 0 ? -1 : 0;
8902}
8903
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008904
8905static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
8906{
8907#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008908 char *pos;
8909
8910 wpa_trace_fail_after = atoi(cmd);
8911 pos = os_strchr(cmd, ':');
8912 if (pos) {
8913 pos++;
8914 os_strlcpy(wpa_trace_fail_func, pos,
8915 sizeof(wpa_trace_fail_func));
8916 } else {
8917 wpa_trace_fail_after = 0;
8918 }
8919 return 0;
8920#else /* WPA_TRACE_BFD */
8921 return -1;
8922#endif /* WPA_TRACE_BFD */
8923}
8924
8925
8926static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
8927 char *buf, size_t buflen)
8928{
8929#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008930 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
8931 wpa_trace_fail_func);
8932#else /* WPA_TRACE_BFD */
8933 return -1;
8934#endif /* WPA_TRACE_BFD */
8935}
8936
Jouni Malinenc4818362015-10-04 11:45:13 +03008937
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008938static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
8939{
8940#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008941 char *pos;
8942
8943 wpa_trace_test_fail_after = atoi(cmd);
8944 pos = os_strchr(cmd, ':');
8945 if (pos) {
8946 pos++;
8947 os_strlcpy(wpa_trace_test_fail_func, pos,
8948 sizeof(wpa_trace_test_fail_func));
8949 } else {
8950 wpa_trace_test_fail_after = 0;
8951 }
8952 return 0;
8953#else /* WPA_TRACE_BFD */
8954 return -1;
8955#endif /* WPA_TRACE_BFD */
8956}
8957
8958
8959static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
8960 char *buf, size_t buflen)
8961{
8962#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008963 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
8964 wpa_trace_test_fail_func);
8965#else /* WPA_TRACE_BFD */
8966 return -1;
8967#endif /* WPA_TRACE_BFD */
8968}
8969
8970
Jouni Malinenc4818362015-10-04 11:45:13 +03008971static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
8972{
8973 struct wpa_supplicant *wpa_s = eloop_ctx;
8974 int i, count = (intptr_t) timeout_ctx;
8975
8976 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
8977 count);
8978 for (i = 0; i < count; i++) {
8979 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
8980 i + 1, count);
8981 }
8982}
8983
8984
8985static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
8986{
8987 int count;
8988
8989 count = atoi(cmd);
8990 if (count <= 0)
8991 return -1;
8992
8993 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
8994 (void *) (intptr_t) count);
8995}
8996
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008997
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008998static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
8999 const char *cmd)
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009000{
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009001 struct wpabuf *buf;
9002 size_t len;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009003
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009004 len = os_strlen(cmd);
9005 if (len & 1)
9006 return -1;
9007 len /= 2;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009008
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009009 if (len == 0) {
9010 buf = NULL;
9011 } else {
9012 buf = wpabuf_alloc(len);
9013 if (buf == NULL)
9014 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009015
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009016 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
9017 wpabuf_free(buf);
9018 return -1;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009019 }
9020 }
9021
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009022 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
9023 return 0;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009024}
9025
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009026
9027static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
9028{
9029 u8 zero[WPA_TK_MAX_LEN];
9030
9031 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
9032 return -1;
9033
9034 wpa_printf(MSG_INFO, "TESTING: Reset PN");
9035 os_memset(zero, 0, sizeof(zero));
9036
9037 /* First, use a zero key to avoid any possible duplicate key avoidance
9038 * in the driver. */
9039 if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9040 wpa_s->last_tk_key_idx, 1, zero, 6,
9041 zero, wpa_s->last_tk_len) < 0)
9042 return -1;
9043
9044 /* Set the previously configured key to reset its TSC/RSC */
9045 return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9046 wpa_s->last_tk_key_idx, 1, zero, 6,
9047 wpa_s->last_tk, wpa_s->last_tk_len);
9048}
9049
9050
9051static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
9052{
9053 const char *pos = cmd;
9054 int error, pairwise;
9055
9056 error = atoi(pos);
9057 pos = os_strchr(pos, ' ');
9058 if (!pos)
9059 return -1;
9060 pairwise = atoi(pos);
9061 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
9062 return 0;
9063}
9064
9065
9066static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
9067{
9068#ifdef CONFIG_SME
9069 struct wpa_driver_associate_params params;
9070 int ret;
9071
9072 os_memset(&params, 0, sizeof(params));
9073 params.bssid = wpa_s->bssid;
9074 params.ssid = wpa_s->sme.ssid;
9075 params.ssid_len = wpa_s->sme.ssid_len;
9076 params.freq.freq = wpa_s->sme.freq;
9077 if (wpa_s->last_assoc_req_wpa_ie) {
9078 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
9079 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
9080 }
9081 params.pairwise_suite = wpa_s->pairwise_cipher;
9082 params.group_suite = wpa_s->group_cipher;
9083 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
9084 params.key_mgmt_suite = wpa_s->key_mgmt;
9085 params.wpa_proto = wpa_s->wpa_proto;
9086 params.mgmt_frame_protection = wpa_s->sme.mfp;
9087 params.rrm_used = wpa_s->rrm.rrm_used;
9088 if (wpa_s->sme.prev_bssid_set)
9089 params.prev_bssid = wpa_s->sme.prev_bssid;
9090 wpa_printf(MSG_INFO, "TESTING: Resend association request");
9091 ret = wpa_drv_associate(wpa_s, &params);
9092 wpa_s->testing_resend_assoc = 1;
9093 return ret;
9094#else /* CONFIG_SME */
9095 return -1;
9096#endif /* CONFIG_SME */
9097}
9098
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009099#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009100
9101
9102static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
9103{
9104 char *pos = cmd;
9105 int frame;
9106 size_t len;
9107 struct wpabuf *buf;
9108 struct ieee802_11_elems elems;
9109
9110 frame = atoi(pos);
9111 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9112 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009113 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009114
9115 pos = os_strchr(pos, ' ');
9116 if (pos == NULL)
9117 return -1;
9118 pos++;
9119
9120 len = os_strlen(pos);
9121 if (len == 0)
9122 return 0;
9123 if (len & 1)
9124 return -1;
9125 len /= 2;
9126
9127 buf = wpabuf_alloc(len);
9128 if (buf == NULL)
9129 return -1;
9130
9131 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
9132 wpabuf_free(buf);
9133 return -1;
9134 }
9135
9136 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
9137 ParseFailed) {
9138 wpabuf_free(buf);
9139 return -1;
9140 }
9141
9142 if (wpa_s->vendor_elem[frame] == NULL) {
9143 wpa_s->vendor_elem[frame] = buf;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009144 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009145 return 0;
9146 }
9147
9148 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
9149 wpabuf_free(buf);
9150 return -1;
9151 }
9152
9153 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
9154 wpabuf_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009155 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009156
9157 return 0;
9158}
9159
9160
9161static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
9162 char *buf, size_t buflen)
9163{
9164 int frame = atoi(cmd);
9165
9166 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9167 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009168 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009169
9170 if (wpa_s->vendor_elem[frame] == NULL)
9171 return 0;
9172
9173 return wpa_snprintf_hex(buf, buflen,
9174 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
9175 wpabuf_len(wpa_s->vendor_elem[frame]));
9176}
9177
9178
9179static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
9180{
9181 char *pos = cmd;
9182 int frame;
9183 size_t len;
9184 u8 *buf;
9185 struct ieee802_11_elems elems;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009186 int res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009187
9188 frame = atoi(pos);
9189 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9190 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009191 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009192
9193 pos = os_strchr(pos, ' ');
9194 if (pos == NULL)
9195 return -1;
9196 pos++;
9197
9198 if (*pos == '*') {
9199 wpabuf_free(wpa_s->vendor_elem[frame]);
9200 wpa_s->vendor_elem[frame] = NULL;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009201 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009202 return 0;
9203 }
9204
9205 if (wpa_s->vendor_elem[frame] == NULL)
9206 return -1;
9207
9208 len = os_strlen(pos);
9209 if (len == 0)
9210 return 0;
9211 if (len & 1)
9212 return -1;
9213 len /= 2;
9214
9215 buf = os_malloc(len);
9216 if (buf == NULL)
9217 return -1;
9218
9219 if (hexstr2bin(pos, buf, len) < 0) {
9220 os_free(buf);
9221 return -1;
9222 }
9223
9224 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
9225 os_free(buf);
9226 return -1;
9227 }
9228
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009229 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009230 os_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009231 return res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009232}
9233
9234
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009235static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
9236{
9237 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009238 size_t len;
9239 const u8 *data;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009240
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009241 /*
9242 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9243 * BSSID[6]
9244 * BSSID Information[4]
9245 * Operating Class[1]
9246 * Channel Number[1]
9247 * PHY Type[1]
9248 * Optional Subelements[variable]
9249 */
9250#define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9251
9252 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009253 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009254 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009255 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009256
9257 data = wpabuf_head_u8(neighbor_rep);
9258 len = wpabuf_len(neighbor_rep);
9259
9260 while (len >= 2 + NR_IE_MIN_LEN) {
9261 const u8 *nr;
9262 char lci[256 * 2 + 1];
9263 char civic[256 * 2 + 1];
9264 u8 nr_len = data[1];
9265 const u8 *pos = data, *end;
9266
9267 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
9268 nr_len < NR_IE_MIN_LEN) {
9269 wpa_printf(MSG_DEBUG,
9270 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9271 data[0], nr_len);
9272 goto out;
9273 }
9274
9275 if (2U + nr_len > len) {
9276 wpa_printf(MSG_DEBUG,
9277 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9278 data[0], len, nr_len);
9279 goto out;
9280 }
9281 pos += 2;
9282 end = pos + nr_len;
9283
9284 nr = pos;
9285 pos += NR_IE_MIN_LEN;
9286
9287 lci[0] = '\0';
9288 civic[0] = '\0';
9289 while (end - pos > 2) {
9290 u8 s_id, s_len;
9291
9292 s_id = *pos++;
9293 s_len = *pos++;
9294 if (s_len > end - pos)
9295 goto out;
9296 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
9297 /* Measurement Token[1] */
9298 /* Measurement Report Mode[1] */
9299 /* Measurement Type[1] */
9300 /* Measurement Report[variable] */
9301 switch (pos[2]) {
9302 case MEASURE_TYPE_LCI:
9303 if (lci[0])
9304 break;
9305 wpa_snprintf_hex(lci, sizeof(lci),
9306 pos, s_len);
9307 break;
9308 case MEASURE_TYPE_LOCATION_CIVIC:
9309 if (civic[0])
9310 break;
9311 wpa_snprintf_hex(civic, sizeof(civic),
9312 pos, s_len);
9313 break;
9314 }
9315 }
9316
9317 pos += s_len;
9318 }
9319
9320 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
9321 "bssid=" MACSTR
9322 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9323 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
9324 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
9325 nr[ETH_ALEN + 6],
9326 lci[0] ? " lci=" : "", lci,
9327 civic[0] ? " civic=" : "", civic);
9328
9329 data = end;
9330 len -= 2 + nr_len;
9331 }
9332
9333out:
9334 wpabuf_free(neighbor_rep);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009335}
9336
9337
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009338static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
9339 char *cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009340{
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009341 struct wpa_ssid_value ssid, *ssid_p = NULL;
9342 int ret, lci = 0, civic = 0;
9343 char *ssid_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009344
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009345 ssid_s = os_strstr(cmd, "ssid=");
9346 if (ssid_s) {
9347 if (ssid_parse(ssid_s + 5, &ssid)) {
9348 wpa_printf(MSG_ERROR,
9349 "CTRL: Send Neighbor Report: bad SSID");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009350 return -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009351 }
9352
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009353 ssid_p = &ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009354
9355 /*
9356 * Move cmd after the SSID text that may include "lci" or
9357 * "civic".
9358 */
9359 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
9360 if (cmd)
9361 cmd++;
9362
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009363 }
9364
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009365 if (cmd && os_strstr(cmd, "lci"))
9366 lci = 1;
9367
9368 if (cmd && os_strstr(cmd, "civic"))
9369 civic = 1;
9370
9371 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009372 wpas_ctrl_neighbor_rep_cb,
9373 wpa_s);
9374
9375 return ret;
9376}
9377
9378
9379static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
9380{
9381 eapol_sm_erp_flush(wpa_s->eapol);
9382 return 0;
9383}
9384
9385
9386static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
9387 char *cmd)
9388{
9389 char *token, *context = NULL;
9390 unsigned int enable = ~0, type = 0;
9391 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
9392 u8 *addr = NULL, *mask = NULL;
9393
9394 while ((token = str_token(cmd, " ", &context))) {
9395 if (os_strcasecmp(token, "scan") == 0) {
9396 type |= MAC_ADDR_RAND_SCAN;
9397 } else if (os_strcasecmp(token, "sched") == 0) {
9398 type |= MAC_ADDR_RAND_SCHED_SCAN;
9399 } else if (os_strcasecmp(token, "pno") == 0) {
9400 type |= MAC_ADDR_RAND_PNO;
9401 } else if (os_strcasecmp(token, "all") == 0) {
9402 type = wpa_s->mac_addr_rand_supported;
9403 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
9404 enable = atoi(token + 7);
9405 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
9406 addr = _addr;
9407 if (hwaddr_aton(token + 5, addr)) {
9408 wpa_printf(MSG_INFO,
9409 "CTRL: Invalid MAC address: %s",
9410 token);
9411 return -1;
9412 }
9413 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
9414 mask = _mask;
9415 if (hwaddr_aton(token + 5, mask)) {
9416 wpa_printf(MSG_INFO,
9417 "CTRL: Invalid MAC address mask: %s",
9418 token);
9419 return -1;
9420 }
9421 } else {
9422 wpa_printf(MSG_INFO,
9423 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9424 token);
9425 return -1;
9426 }
9427 }
9428
9429 if (!type) {
9430 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
9431 return -1;
9432 }
9433
9434 if ((wpa_s->mac_addr_rand_supported & type) != type) {
9435 wpa_printf(MSG_INFO,
9436 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
9437 type, wpa_s->mac_addr_rand_supported);
9438 return -1;
9439 }
9440
9441 if (enable > 1) {
9442 wpa_printf(MSG_INFO,
9443 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9444 return -1;
9445 }
9446
9447 if (!enable) {
9448 wpas_mac_addr_rand_scan_clear(wpa_s, type);
9449 if (wpa_s->pno) {
9450 if (type & MAC_ADDR_RAND_PNO) {
9451 wpas_stop_pno(wpa_s);
9452 wpas_start_pno(wpa_s);
9453 }
9454 } else if (wpa_s->sched_scanning &&
9455 (type & MAC_ADDR_RAND_SCHED_SCAN)) {
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07009456 wpas_scan_restart_sched_scan(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009457 }
9458 return 0;
9459 }
9460
9461 if ((addr && !mask) || (!addr && mask)) {
9462 wpa_printf(MSG_INFO,
9463 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
9464 return -1;
9465 }
9466
9467 if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) {
9468 wpa_printf(MSG_INFO,
9469 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
9470 return -1;
9471 }
9472
9473 if (type & MAC_ADDR_RAND_SCAN) {
9474 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
9475 addr, mask);
9476 }
9477
9478 if (type & MAC_ADDR_RAND_SCHED_SCAN) {
9479 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
9480 addr, mask);
9481
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07009482 if (wpa_s->sched_scanning && !wpa_s->pno)
9483 wpas_scan_restart_sched_scan(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009484 }
9485
9486 if (type & MAC_ADDR_RAND_PNO) {
9487 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
9488 addr, mask);
9489 if (wpa_s->pno) {
9490 wpas_stop_pno(wpa_s);
9491 wpas_start_pno(wpa_s);
9492 }
9493 }
9494
9495 return 0;
9496}
9497
9498
Dmitry Shmidte4663042016-04-04 10:07:49 -07009499static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
9500 char *buf, size_t buflen)
9501{
9502 size_t reply_len;
9503
9504 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
9505#ifdef CONFIG_AP
9506 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
9507 buflen - reply_len);
9508#endif /* CONFIG_AP */
9509 return reply_len;
9510}
9511
9512
9513static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
9514{
9515 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
9516#ifdef CONFIG_AP
9517 wpas_ap_pmksa_cache_flush(wpa_s);
9518#endif /* CONFIG_AP */
9519}
9520
9521
Dmitry Shmidt29333592017-01-09 12:27:11 -08009522#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9523
9524static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
9525 const char *cmd, char *buf, size_t buflen)
9526{
9527 struct rsn_pmksa_cache_entry *entry;
9528 struct wpa_ssid *ssid;
9529 char *pos, *pos2, *end;
9530 int ret;
9531 struct os_reltime now;
9532
9533 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
9534 if (!ssid)
9535 return -1;
9536
9537 pos = buf;
9538 end = buf + buflen;
9539
9540 os_get_reltime(&now);
9541
9542 /*
9543 * Entry format:
9544 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9545 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009546 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -08009547 */
9548
9549 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
9550 entry = entry->next) {
9551 if (entry->network_ctx != ssid)
9552 continue;
9553
9554 pos2 = pos;
9555 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
9556 MAC2STR(entry->aa));
9557 if (os_snprintf_error(end - pos2, ret))
9558 break;
9559 pos2 += ret;
9560
9561 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
9562 PMKID_LEN);
9563
9564 ret = os_snprintf(pos2, end - pos2, " ");
9565 if (os_snprintf_error(end - pos2, ret))
9566 break;
9567 pos2 += ret;
9568
9569 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
9570 entry->pmk_len);
9571
9572 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
9573 (int) (entry->reauth_time - now.sec),
9574 (int) (entry->expiration - now.sec),
9575 entry->akmp,
9576 entry->opportunistic);
9577 if (os_snprintf_error(end - pos2, ret))
9578 break;
9579 pos2 += ret;
9580
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009581 if (entry->fils_cache_id_set) {
9582 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
9583 entry->fils_cache_id[0],
9584 entry->fils_cache_id[1]);
9585 if (os_snprintf_error(end - pos2, ret))
9586 break;
9587 pos2 += ret;
9588 }
9589
Dmitry Shmidt29333592017-01-09 12:27:11 -08009590 ret = os_snprintf(pos2, end - pos2, "\n");
9591 if (os_snprintf_error(end - pos2, ret))
9592 break;
9593 pos2 += ret;
9594
9595 pos = pos2;
9596 }
9597
9598 return pos - buf;
9599}
9600
9601
9602static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
9603 char *cmd)
9604{
9605 struct rsn_pmksa_cache_entry *entry;
9606 struct wpa_ssid *ssid;
9607 char *pos, *pos2;
9608 int ret = -1;
9609 struct os_reltime now;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009610 int reauth_time = 0, expiration = 0, i;
Dmitry Shmidt29333592017-01-09 12:27:11 -08009611
9612 /*
9613 * Entry format:
9614 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9615 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009616 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -08009617 */
9618
9619 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
9620 if (!ssid)
9621 return -1;
9622
9623 pos = os_strchr(cmd, ' ');
9624 if (!pos)
9625 return -1;
9626 pos++;
9627
9628 entry = os_zalloc(sizeof(*entry));
9629 if (!entry)
9630 return -1;
9631
9632 if (hwaddr_aton(pos, entry->aa))
9633 goto fail;
9634
9635 pos = os_strchr(pos, ' ');
9636 if (!pos)
9637 goto fail;
9638 pos++;
9639
9640 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
9641 goto fail;
9642
9643 pos = os_strchr(pos, ' ');
9644 if (!pos)
9645 goto fail;
9646 pos++;
9647
9648 pos2 = os_strchr(pos, ' ');
9649 if (!pos2)
9650 goto fail;
9651 entry->pmk_len = (pos2 - pos) / 2;
9652 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
9653 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
9654 goto fail;
9655
9656 pos = os_strchr(pos, ' ');
9657 if (!pos)
9658 goto fail;
9659 pos++;
9660
9661 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
9662 &entry->akmp, &entry->opportunistic) != 4)
9663 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009664 for (i = 0; i < 4; i++) {
9665 pos = os_strchr(pos, ' ');
9666 if (!pos) {
9667 if (i < 3)
9668 goto fail;
9669 break;
9670 }
9671 pos++;
9672 }
9673 if (pos) {
9674 if (hexstr2bin(pos, entry->fils_cache_id,
9675 FILS_CACHE_ID_LEN) < 0)
9676 goto fail;
9677 entry->fils_cache_id_set = 1;
9678 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08009679 os_get_reltime(&now);
9680 entry->expiration = now.sec + expiration;
9681 entry->reauth_time = now.sec + reauth_time;
9682
9683 entry->network_ctx = ssid;
9684
9685 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
9686 entry = NULL;
9687 ret = 0;
9688fail:
9689 os_free(entry);
9690 return ret;
9691}
9692
Paul Stewart092955c2017-02-06 09:13:09 -08009693
9694#ifdef CONFIG_MESH
9695
9696static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
9697 const char *cmd, char *buf,
9698 size_t buflen)
9699{
9700 u8 spa[ETH_ALEN];
9701
9702 if (!wpa_s->ifmsh)
9703 return -1;
9704
9705 if (os_strcasecmp(cmd, "any") == 0)
9706 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
9707
9708 if (hwaddr_aton(cmd, spa))
9709 return -1;
9710
9711 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
9712}
9713
9714
9715static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
9716 char *cmd)
9717{
9718 /*
9719 * We do not check mesh interface existance because PMKSA should be
9720 * stored before wpa_s->ifmsh creation to suppress commit message
9721 * creation.
9722 */
9723 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
9724}
9725
9726#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -08009727#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9728
9729
Paul Stewart092955c2017-02-06 09:13:09 -08009730#ifdef CONFIG_FILS
9731static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
9732 const char *cmd)
9733{
9734 struct fils_hlp_req *req;
9735 const char *pos;
9736
9737 /* format: <dst> <packet starting from ethertype> */
9738
9739 req = os_zalloc(sizeof(*req));
9740 if (!req)
9741 return -1;
9742
9743 if (hwaddr_aton(cmd, req->dst))
9744 goto fail;
9745
9746 pos = os_strchr(cmd, ' ');
9747 if (!pos)
9748 goto fail;
9749 pos++;
9750 req->pkt = wpabuf_parse_bin(pos);
9751 if (!req->pkt)
9752 goto fail;
9753
9754 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
9755 return 0;
9756fail:
9757 wpabuf_free(req->pkt);
9758 os_free(req);
9759 return -1;
9760}
9761#endif /* CONFIG_FILS */
9762
9763
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009764static int wpas_ctrl_cmd_debug_level(const char *cmd)
9765{
9766 if (os_strcmp(cmd, "PING") == 0 ||
9767 os_strncmp(cmd, "BSS ", 4) == 0 ||
9768 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
9769 os_strncmp(cmd, "STATUS", 6) == 0 ||
9770 os_strncmp(cmd, "STA ", 4) == 0 ||
9771 os_strncmp(cmd, "STA-", 4) == 0)
9772 return MSG_EXCESSIVE;
9773 return MSG_DEBUG;
9774}
9775
9776
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009777char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
9778 char *buf, size_t *resp_len)
9779{
9780 char *reply;
9781 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009782 int reply_len;
9783
9784 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009785 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
9786 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
9787 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009788 if (wpa_debug_show_keys)
9789 wpa_dbg(wpa_s, MSG_DEBUG,
9790 "Control interface command '%s'", buf);
9791 else
9792 wpa_dbg(wpa_s, MSG_DEBUG,
9793 "Control interface command '%s [REMOVED]'",
9794 os_strncmp(buf, WPA_CTRL_RSP,
9795 os_strlen(WPA_CTRL_RSP)) == 0 ?
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009796 WPA_CTRL_RSP :
9797 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
9798 "SET_NETWORK" : "key-add"));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009799 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
Dmitry Shmidt21de2142014-04-08 10:50:52 -07009800 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009801 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
9802 (const u8 *) buf, os_strlen(buf));
9803 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009804 int level = wpas_ctrl_cmd_debug_level(buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07009805 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009806 }
9807
9808 reply = os_malloc(reply_size);
9809 if (reply == NULL) {
9810 *resp_len = 1;
9811 return NULL;
9812 }
9813
9814 os_memcpy(reply, "OK\n", 3);
9815 reply_len = 3;
9816
9817 if (os_strcmp(buf, "PING") == 0) {
9818 os_memcpy(reply, "PONG\n", 5);
9819 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07009820 } else if (os_strcmp(buf, "IFNAME") == 0) {
9821 reply_len = os_strlen(wpa_s->ifname);
9822 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009823 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
9824 if (wpa_debug_reopen_file() < 0)
9825 reply_len = -1;
9826 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
9827 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
9828 } else if (os_strcmp(buf, "MIB") == 0) {
9829 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
9830 if (reply_len >= 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009831 reply_len += eapol_sm_get_mib(wpa_s->eapol,
9832 reply + reply_len,
9833 reply_size - reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009834 }
9835 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
9836 reply_len = wpa_supplicant_ctrl_iface_status(
9837 wpa_s, buf + 6, reply, reply_size);
9838 } else if (os_strcmp(buf, "PMKSA") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -07009839 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009840 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -07009841 wpas_ctrl_iface_pmksa_flush(wpa_s);
Dmitry Shmidt29333592017-01-09 12:27:11 -08009842#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9843 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
9844 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
9845 reply, reply_size);
9846 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
9847 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
9848 reply_len = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08009849#ifdef CONFIG_MESH
9850 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
9851 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
9852 reply, reply_size);
9853 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
9854 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
9855 reply_len = -1;
9856#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -08009857#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009858 } else if (os_strncmp(buf, "SET ", 4) == 0) {
9859 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
9860 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08009861 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
9862 reply_len = wpa_config_dump_values(wpa_s->conf,
9863 reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009864 } else if (os_strncmp(buf, "GET ", 4) == 0) {
9865 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
9866 reply, reply_size);
9867 } else if (os_strcmp(buf, "LOGON") == 0) {
9868 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
9869 } else if (os_strcmp(buf, "LOGOFF") == 0) {
9870 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
9871 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
9872 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
9873 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08009874 else
9875 wpas_request_connection(wpa_s);
Dmitry Shmidt98660862014-03-11 17:26:21 -07009876 } else if (os_strcmp(buf, "REATTACH") == 0) {
9877 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
9878 !wpa_s->current_ssid)
9879 reply_len = -1;
9880 else {
9881 wpa_s->reattach = 1;
9882 wpas_request_connection(wpa_s);
9883 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009884 } else if (os_strcmp(buf, "RECONNECT") == 0) {
9885 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
9886 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08009887 else if (wpa_s->disconnected)
9888 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009889#ifdef IEEE8021X_EAPOL
9890 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
9891 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
9892 reply_len = -1;
9893#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009894#ifdef CONFIG_IEEE80211R
9895 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
9896 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
9897 reply_len = -1;
9898#endif /* CONFIG_IEEE80211R */
9899#ifdef CONFIG_WPS
9900 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
9901 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
9902 if (res == -2) {
9903 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
9904 reply_len = 17;
9905 } else if (res)
9906 reply_len = -1;
9907 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
9908 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
9909 if (res == -2) {
9910 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
9911 reply_len = 17;
9912 } else if (res)
9913 reply_len = -1;
9914 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
9915 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
9916 reply,
9917 reply_size);
9918 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
9919 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
9920 wpa_s, buf + 14, reply, reply_size);
9921 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
9922 if (wpas_wps_cancel(wpa_s))
9923 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07009924#ifdef CONFIG_WPS_NFC
9925 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
9926 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
9927 reply_len = -1;
9928 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
9929 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
9930 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08009931 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
9932 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
9933 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07009934 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
9935 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
9936 wpa_s, buf + 14, reply, reply_size);
9937 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
9938 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
9939 buf + 17))
9940 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08009941 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
9942 reply_len = wpas_ctrl_nfc_get_handover_req(
9943 wpa_s, buf + 21, reply, reply_size);
9944 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
9945 reply_len = wpas_ctrl_nfc_get_handover_sel(
9946 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08009947 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
9948 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
9949 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07009950#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009951 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
9952 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
9953 reply_len = -1;
9954#ifdef CONFIG_AP
9955 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
9956 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
9957 wpa_s, buf + 11, reply, reply_size);
9958#endif /* CONFIG_AP */
9959#ifdef CONFIG_WPS_ER
9960 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
9961 if (wpas_wps_er_start(wpa_s, NULL))
9962 reply_len = -1;
9963 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
9964 if (wpas_wps_er_start(wpa_s, buf + 13))
9965 reply_len = -1;
9966 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009967 wpas_wps_er_stop(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009968 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
9969 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
9970 reply_len = -1;
9971 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
9972 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
9973 if (ret == -2) {
9974 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
9975 reply_len = 17;
9976 } else if (ret == -3) {
9977 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
9978 reply_len = 18;
9979 } else if (ret == -4) {
9980 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
9981 reply_len = 20;
9982 } else if (ret)
9983 reply_len = -1;
9984 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
9985 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
9986 reply_len = -1;
9987 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
9988 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
9989 buf + 18))
9990 reply_len = -1;
9991 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
9992 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
9993 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07009994#ifdef CONFIG_WPS_NFC
9995 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
9996 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
9997 wpa_s, buf + 24, reply, reply_size);
9998#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009999#endif /* CONFIG_WPS_ER */
10000#endif /* CONFIG_WPS */
10001#ifdef CONFIG_IBSS_RSN
10002 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
10003 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
10004 reply_len = -1;
10005#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010006#ifdef CONFIG_MESH
10007 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
10008 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10009 wpa_s, buf + 19, reply, reply_size);
10010 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
10011 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10012 wpa_s, "", reply, reply_size);
10013 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
10014 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
10015 reply_len = -1;
10016 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
10017 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
10018 buf + 18))
10019 reply_len = -1;
Dmitry Shmidte4663042016-04-04 10:07:49 -070010020 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
10021 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
10022 reply_len = -1;
10023 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
10024 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
10025 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010026#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010027#ifdef CONFIG_P2P
10028 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010029 if (p2p_ctrl_find(wpa_s, buf + 8))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010030 reply_len = -1;
10031 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
10032 if (p2p_ctrl_find(wpa_s, ""))
10033 reply_len = -1;
10034 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
10035 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010036 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
10037 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
10038 reply_len = -1;
10039 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10040 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
10041 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010042 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
10043 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
10044 reply_size);
10045 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
10046 if (p2p_ctrl_listen(wpa_s, buf + 11))
10047 reply_len = -1;
10048 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
10049 if (p2p_ctrl_listen(wpa_s, ""))
10050 reply_len = -1;
10051 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
10052 if (wpas_p2p_group_remove(wpa_s, buf + 17))
10053 reply_len = -1;
10054 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070010055 if (p2p_ctrl_group_add(wpa_s, ""))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010056 reply_len = -1;
10057 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
10058 if (p2p_ctrl_group_add(wpa_s, buf + 14))
10059 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010060 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
10061 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
10062 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010063 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
10064 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
10065 reply_len = -1;
10066 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
10067 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
10068 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
10069 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
10070 reply_size);
10071 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10072 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
10073 reply_len = -1;
10074 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
10075 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
10076 reply_len = -1;
10077 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
10078 wpas_p2p_sd_service_update(wpa_s);
10079 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10080 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
10081 reply_len = -1;
10082 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
10083 wpas_p2p_service_flush(wpa_s);
10084 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
10085 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
10086 reply_len = -1;
10087 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
10088 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
10089 reply_len = -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010090 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
10091 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
10092 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010093 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
10094 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
10095 reply_len = -1;
10096 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
10097 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
10098 reply_len = -1;
10099 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
10100 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
10101 reply_size);
10102 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
10103 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
10104 reply_len = -1;
10105 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -070010106 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010107 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
10108 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
10109 reply_len = -1;
10110 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
10111 if (wpas_p2p_cancel(wpa_s))
10112 reply_len = -1;
10113 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
10114 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
10115 reply_len = -1;
10116 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
10117 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
10118 reply_len = -1;
10119 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
10120 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
10121 reply_len = -1;
10122 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
10123 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
10124 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070010125 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
10126 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
10127 reply_len = -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010128 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
10129 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
10130 reply_len = -1;
10131 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
10132 if (wpas_p2p_lo_stop(wpa_s))
10133 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010134#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010135#ifdef CONFIG_WIFI_DISPLAY
10136 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
10137 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
10138 reply_len = -1;
10139 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
10140 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
10141 reply, reply_size);
10142#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010143#ifdef CONFIG_INTERWORKING
10144 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
10145 if (interworking_fetch_anqp(wpa_s) < 0)
10146 reply_len = -1;
10147 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
10148 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010149 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
10150 if (ctrl_interworking_select(wpa_s, NULL) < 0)
10151 reply_len = -1;
10152 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
10153 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010154 reply_len = -1;
10155 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010156 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010157 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010158 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10159 int id;
10160
10161 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
10162 if (id < 0)
10163 reply_len = -1;
10164 else {
10165 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
10166 if (os_snprintf_error(reply_size, reply_len))
10167 reply_len = -1;
10168 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010169 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
10170 if (get_anqp(wpa_s, buf + 9) < 0)
10171 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010172 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
10173 if (gas_request(wpa_s, buf + 12) < 0)
10174 reply_len = -1;
10175 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
10176 reply_len = gas_response_get(wpa_s, buf + 17, reply,
10177 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010178#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -070010179#ifdef CONFIG_HS20
10180 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
10181 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
10182 reply_len = -1;
10183 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10184 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
10185 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010186 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080010187 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
10188 reply_len = -1;
10189 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
10190 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
10191 reply_len = -1;
10192 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
10193 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
10194 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
10195 if (del_hs20_icon(wpa_s, buf + 14) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010196 reply_len = -1;
10197 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010198 if (hs20_fetch_osu(wpa_s, 0) < 0)
10199 reply_len = -1;
10200 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
10201 if (hs20_fetch_osu(wpa_s, 1) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010202 reply_len = -1;
10203 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
10204 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010205#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010206 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
10207 {
10208 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10209 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
10210 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -070010211 else {
10212 /*
10213 * Notify response from timeout to allow the control
10214 * interface response to be sent first.
10215 */
10216 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
10217 wpa_s, NULL);
10218 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010219 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
10220 if (wpa_supplicant_reload_configuration(wpa_s))
10221 reply_len = -1;
10222 } else if (os_strcmp(buf, "TERMINATE") == 0) {
10223 wpa_supplicant_terminate_proc(wpa_s->global);
10224 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
10225 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
10226 reply_len = -1;
Dmitry Shmidte19501d2011-03-16 14:32:18 -070010227 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010228 reply_len = wpa_supplicant_ctrl_iface_blacklist(
10229 wpa_s, buf + 9, reply, reply_size);
10230 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
10231 reply_len = wpa_supplicant_ctrl_iface_log_level(
10232 wpa_s, buf + 9, reply, reply_size);
Vinit Deshpandeda134e92014-12-02 10:59:29 -080010233 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
10234 reply_len = wpa_supplicant_ctrl_iface_list_networks(
10235 wpa_s, buf + 14, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010236 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
10237 reply_len = wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -080010238 wpa_s, NULL, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010239 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070010240 wpas_request_disconnection(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010241 } else if (os_strcmp(buf, "SCAN") == 0) {
10242 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
10243 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
10244 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010245 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
10246 reply_len = wpa_supplicant_ctrl_iface_scan_results(
10247 wpa_s, reply, reply_size);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010248 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
10249 if (wpas_abort_ongoing_scan(wpa_s) < 0)
10250 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010251 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
10252 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
10253 reply_len = -1;
10254 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
10255 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
10256 reply_len = -1;
10257 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
10258 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
10259 reply_len = -1;
10260 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
10261 reply_len = wpa_supplicant_ctrl_iface_add_network(
10262 wpa_s, reply, reply_size);
10263 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
10264 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
10265 reply_len = -1;
10266 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
10267 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
10268 reply_len = -1;
10269 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
10270 reply_len = wpa_supplicant_ctrl_iface_get_network(
10271 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt684785c2014-05-12 13:34:29 -070010272 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010273 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
10274 wpa_s))
Dmitry Shmidt684785c2014-05-12 13:34:29 -070010275 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010276 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
10277 reply_len = wpa_supplicant_ctrl_iface_list_creds(
10278 wpa_s, reply, reply_size);
10279 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
10280 reply_len = wpa_supplicant_ctrl_iface_add_cred(
10281 wpa_s, reply, reply_size);
10282 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
10283 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
10284 reply_len = -1;
10285 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
10286 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
10287 reply_len = -1;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -070010288 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
10289 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
10290 reply,
10291 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010292#ifndef CONFIG_NO_CONFIG_WRITE
10293 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
10294 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
10295 reply_len = -1;
10296#endif /* CONFIG_NO_CONFIG_WRITE */
10297 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
10298 reply_len = wpa_supplicant_ctrl_iface_get_capability(
10299 wpa_s, buf + 15, reply, reply_size);
10300 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
10301 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
10302 reply_len = -1;
10303 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
10304 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
10305 reply_len = -1;
10306 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
10307 reply_len = wpa_supplicant_global_iface_list(
10308 wpa_s->global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010309 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010310 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010311 wpa_s->global, buf + 10, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010312 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
10313 reply_len = wpa_supplicant_ctrl_iface_bss(
10314 wpa_s, buf + 4, reply, reply_size);
10315#ifdef CONFIG_AP
10316 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
10317 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
10318 } else if (os_strncmp(buf, "STA ", 4) == 0) {
10319 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
10320 reply_size);
10321 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
10322 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
10323 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010324 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
10325 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
10326 reply_len = -1;
10327 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
10328 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
10329 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080010330 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
10331 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
10332 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010333 } else if (os_strcmp(buf, "STOP_AP") == 0) {
10334 if (wpas_ap_stop_ap(wpa_s))
10335 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010336#endif /* CONFIG_AP */
10337 } else if (os_strcmp(buf, "SUSPEND") == 0) {
10338 wpas_notify_suspend(wpa_s->global);
10339 } else if (os_strcmp(buf, "RESUME") == 0) {
10340 wpas_notify_resume(wpa_s->global);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010341#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010342 } else if (os_strcmp(buf, "DROP_SA") == 0) {
10343 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010344#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010345 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
10346 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
10347 reply_len = -1;
10348 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010349 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010350 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
10351 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
10352 reply_len = -1;
10353 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
10354 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
10355 buf + 17))
10356 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -070010357 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010358 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010359#ifdef CONFIG_TDLS
10360 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
10361 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
10362 reply_len = -1;
10363 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
10364 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
10365 reply_len = -1;
10366 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
10367 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
10368 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010369 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
10370 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
10371 buf + 17))
10372 reply_len = -1;
10373 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10374 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
10375 buf + 24))
10376 reply_len = -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -070010377 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
10378 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
10379 wpa_s, buf + 17, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010380#endif /* CONFIG_TDLS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010381 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
10382 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
10383 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
10384 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
10385 reply_len = -1;
10386 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
10387 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
10388 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010389 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
10390 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
10391 reply_size);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080010392 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
10393 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
10394 reply_len = -1;
Yuhao Zhengfcd6f212012-07-27 10:37:52 -070010395 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
10396 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
10397 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010398#ifdef CONFIG_AUTOSCAN
10399 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
10400 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
10401 reply_len = -1;
10402#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010403 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
10404 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
10405 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080010406#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -070010407 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
10408 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
10409 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080010410#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080010411 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
10412 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
10413 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010414 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010415 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010416 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080010417#ifdef CONFIG_WNM
10418 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
10419 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
10420 reply_len = -1;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080010421 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
10422 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
Dmitry Shmidt44c95782013-05-17 09:51:35 -070010423 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080010424#endif /* CONFIG_WNM */
Dmitry Shmidt444d5672013-04-01 13:08:44 -070010425 } else if (os_strcmp(buf, "FLUSH") == 0) {
10426 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010427 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
10428 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
10429 reply_size);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070010430#ifdef CONFIG_TESTING_OPTIONS
10431 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
10432 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
10433 reply_len = -1;
10434 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
10435 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010436 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
10437 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
10438 reply_len = -1;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -070010439 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
10440 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
10441 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010442 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
10443 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
10444 reply_len = -1;
10445 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
10446 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
10447 reply_len = -1;
10448 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
10449 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
10450 reply_len = -1;
10451 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
10452 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
10453 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010454 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
10455 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
10456 reply_len = -1;
10457 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
10458 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010459 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
10460 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
10461 reply_len = -1;
10462 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
10463 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
Jouni Malinenc4818362015-10-04 11:45:13 +030010464 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
10465 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
10466 reply_len = -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010467 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
10468 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
10469 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010470 } else if (os_strcmp(buf, "RESET_PN") == 0) {
10471 if (wpas_ctrl_reset_pn(wpa_s) < 0)
10472 reply_len = -1;
10473 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
10474 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
10475 reply_len = -1;
10476 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
10477 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
10478 reply_len = -1;
Dmitry Shmidt818ea482014-03-10 13:15:21 -070010479#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010480 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
10481 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
10482 reply_len = -1;
10483 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
10484 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
10485 reply_size);
10486 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10487 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
10488 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010489 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010490 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010491 reply_len = -1;
10492 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
10493 wpas_ctrl_iface_erp_flush(wpa_s);
10494 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
10495 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
10496 reply_len = -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010497 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
10498 reply_len = wpas_ctrl_iface_get_pref_freq_list(
10499 wpa_s, buf + 19, reply, reply_size);
Paul Stewart092955c2017-02-06 09:13:09 -080010500#ifdef CONFIG_FILS
10501 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
10502 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
10503 reply_len = -1;
10504 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
10505 wpas_flush_fils_hlp_req(wpa_s);
10506#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010507#ifdef CONFIG_DPP
10508 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
10509 int res;
10510
10511 res = wpas_dpp_qr_code(wpa_s, buf + 12);
10512 if (res < 0) {
10513 reply_len = -1;
10514 } else {
10515 reply_len = os_snprintf(reply, reply_size, "%d", res);
10516 if (os_snprintf_error(reply_size, reply_len))
10517 reply_len = -1;
10518 }
10519 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10520 int res;
10521
10522 res = wpas_dpp_bootstrap_gen(wpa_s, buf + 18);
10523 if (res < 0) {
10524 reply_len = -1;
10525 } else {
10526 reply_len = os_snprintf(reply, reply_size, "%d", res);
10527 if (os_snprintf_error(reply_size, reply_len))
10528 reply_len = -1;
10529 }
10530 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10531 if (wpas_dpp_bootstrap_remove(wpa_s, buf + 21) < 0)
10532 reply_len = -1;
10533 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10534 const char *uri;
10535
10536 uri = wpas_dpp_bootstrap_get_uri(wpa_s, atoi(buf + 22));
10537 if (!uri) {
10538 reply_len = -1;
10539 } else {
10540 reply_len = os_snprintf(reply, reply_size, "%s", uri);
10541 if (os_snprintf_error(reply_size, reply_len))
10542 reply_len = -1;
10543 }
10544 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10545 reply_len = wpas_dpp_bootstrap_info(wpa_s, atoi(buf + 19),
10546 reply, reply_size);
10547 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
10548 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
10549 reply_len = -1;
10550 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
10551 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
10552 reply_len = -1;
10553 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -070010554 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010555 wpas_dpp_listen_stop(wpa_s);
10556 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10557 int res;
10558
10559 res = wpas_dpp_configurator_add(wpa_s, buf + 20);
10560 if (res < 0) {
10561 reply_len = -1;
10562 } else {
10563 reply_len = os_snprintf(reply, reply_size, "%d", res);
10564 if (os_snprintf_error(reply_size, reply_len))
10565 reply_len = -1;
10566 }
10567 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10568 if (wpas_dpp_configurator_remove(wpa_s, buf + 24) < 0)
10569 reply_len = -1;
10570 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10571 if (wpas_dpp_configurator_sign(wpa_s, buf + 22) < 0)
10572 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -070010573 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
10574 reply_len = wpas_dpp_configurator_get_key(wpa_s, atoi(buf + 25),
10575 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010576 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
10577 int res;
10578
10579 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
10580 if (res < 0) {
10581 reply_len = -1;
10582 } else {
10583 reply_len = os_snprintf(reply, reply_size, "%d", res);
10584 if (os_snprintf_error(reply_size, reply_len))
10585 reply_len = -1;
10586 }
10587 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
10588 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
10589 reply_len = -1;
10590#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010591 } else {
10592 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
10593 reply_len = 16;
10594 }
10595
10596 if (reply_len < 0) {
10597 os_memcpy(reply, "FAIL\n", 5);
10598 reply_len = 5;
10599 }
10600
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010601 *resp_len = reply_len;
10602 return reply;
10603}
10604
10605
10606static int wpa_supplicant_global_iface_add(struct wpa_global *global,
10607 char *cmd)
10608{
10609 struct wpa_interface iface;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010610 char *pos, *extra;
10611 struct wpa_supplicant *wpa_s;
10612 unsigned int create_iface = 0;
10613 u8 mac_addr[ETH_ALEN];
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010614 enum wpa_driver_if_type type = WPA_IF_STATION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010615
10616 /*
10617 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010618 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010619 */
10620 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
10621
10622 os_memset(&iface, 0, sizeof(iface));
10623
10624 do {
10625 iface.ifname = pos = cmd;
10626 pos = os_strchr(pos, '\t');
10627 if (pos)
10628 *pos++ = '\0';
10629 if (iface.ifname[0] == '\0')
10630 return -1;
10631 if (pos == NULL)
10632 break;
10633
10634 iface.confname = pos;
10635 pos = os_strchr(pos, '\t');
10636 if (pos)
10637 *pos++ = '\0';
10638 if (iface.confname[0] == '\0')
10639 iface.confname = NULL;
10640 if (pos == NULL)
10641 break;
10642
10643 iface.driver = pos;
10644 pos = os_strchr(pos, '\t');
10645 if (pos)
10646 *pos++ = '\0';
10647 if (iface.driver[0] == '\0')
10648 iface.driver = NULL;
10649 if (pos == NULL)
10650 break;
10651
10652 iface.ctrl_interface = pos;
10653 pos = os_strchr(pos, '\t');
10654 if (pos)
10655 *pos++ = '\0';
10656 if (iface.ctrl_interface[0] == '\0')
10657 iface.ctrl_interface = NULL;
10658 if (pos == NULL)
10659 break;
10660
10661 iface.driver_param = pos;
10662 pos = os_strchr(pos, '\t');
10663 if (pos)
10664 *pos++ = '\0';
10665 if (iface.driver_param[0] == '\0')
10666 iface.driver_param = NULL;
10667 if (pos == NULL)
10668 break;
10669
10670 iface.bridge_ifname = pos;
10671 pos = os_strchr(pos, '\t');
10672 if (pos)
10673 *pos++ = '\0';
10674 if (iface.bridge_ifname[0] == '\0')
10675 iface.bridge_ifname = NULL;
10676 if (pos == NULL)
10677 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010678
10679 extra = pos;
10680 pos = os_strchr(pos, '\t');
10681 if (pos)
10682 *pos++ = '\0';
Dmitry Shmidt83474442015-04-15 13:47:09 -070010683 if (!extra[0])
10684 break;
10685
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010686 if (os_strcmp(extra, "create") == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010687 create_iface = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010688 if (!pos)
10689 break;
10690
10691 if (os_strcmp(pos, "sta") == 0) {
10692 type = WPA_IF_STATION;
10693 } else if (os_strcmp(pos, "ap") == 0) {
10694 type = WPA_IF_AP_BSS;
10695 } else {
10696 wpa_printf(MSG_DEBUG,
10697 "INTERFACE_ADD unsupported interface type: '%s'",
10698 pos);
10699 return -1;
10700 }
10701 } else {
Dmitry Shmidt83474442015-04-15 13:47:09 -070010702 wpa_printf(MSG_DEBUG,
10703 "INTERFACE_ADD unsupported extra parameter: '%s'",
10704 extra);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010705 return -1;
Dmitry Shmidt83474442015-04-15 13:47:09 -070010706 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010707 } while (0);
10708
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010709 if (create_iface) {
10710 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
10711 iface.ifname);
10712 if (!global->ifaces)
10713 return -1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010714 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010715 NULL, NULL, NULL, mac_addr, NULL) < 0) {
10716 wpa_printf(MSG_ERROR,
10717 "CTRL_IFACE interface creation failed");
10718 return -1;
10719 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010720
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010721 wpa_printf(MSG_DEBUG,
10722 "CTRL_IFACE interface '%s' created with MAC addr: "
10723 MACSTR, iface.ifname, MAC2STR(mac_addr));
10724 }
10725
10726 if (wpa_supplicant_get_iface(global, iface.ifname))
10727 goto fail;
10728
10729 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
10730 if (!wpa_s)
10731 goto fail;
10732 wpa_s->added_vif = create_iface;
10733 return 0;
10734
10735fail:
10736 if (create_iface)
10737 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
10738 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010739}
10740
10741
10742static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
10743 char *cmd)
10744{
10745 struct wpa_supplicant *wpa_s;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010746 int ret;
10747 unsigned int delete_iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010748
10749 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
10750
10751 wpa_s = wpa_supplicant_get_iface(global, cmd);
10752 if (wpa_s == NULL)
10753 return -1;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010754 delete_iface = wpa_s->added_vif;
10755 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
10756 if (!ret && delete_iface) {
10757 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
10758 cmd);
10759 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
10760 }
10761 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010762}
10763
10764
10765static void wpa_free_iface_info(struct wpa_interface_info *iface)
10766{
10767 struct wpa_interface_info *prev;
10768
10769 while (iface) {
10770 prev = iface;
10771 iface = iface->next;
10772
10773 os_free(prev->ifname);
10774 os_free(prev->desc);
10775 os_free(prev);
10776 }
10777}
10778
10779
10780static int wpa_supplicant_global_iface_list(struct wpa_global *global,
10781 char *buf, int len)
10782{
10783 int i, res;
10784 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
10785 char *pos, *end;
10786
10787 for (i = 0; wpa_drivers[i]; i++) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070010788 const struct wpa_driver_ops *drv = wpa_drivers[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010789 if (drv->get_interfaces == NULL)
10790 continue;
10791 tmp = drv->get_interfaces(global->drv_priv[i]);
10792 if (tmp == NULL)
10793 continue;
10794
10795 if (last == NULL)
10796 iface = last = tmp;
10797 else
10798 last->next = tmp;
10799 while (last->next)
10800 last = last->next;
10801 }
10802
10803 pos = buf;
10804 end = buf + len;
10805 for (tmp = iface; tmp; tmp = tmp->next) {
10806 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
10807 tmp->drv_name, tmp->ifname,
10808 tmp->desc ? tmp->desc : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010809 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010810 *pos = '\0';
10811 break;
10812 }
10813 pos += res;
10814 }
10815
10816 wpa_free_iface_info(iface);
10817
10818 return pos - buf;
10819}
10820
10821
10822static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010823 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010824 char *buf, int len)
10825{
10826 int res;
10827 char *pos, *end;
10828 struct wpa_supplicant *wpa_s;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010829 int show_ctrl = 0;
10830
10831 if (input)
10832 show_ctrl = !!os_strstr(input, "ctrl");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010833
10834 wpa_s = global->ifaces;
10835 pos = buf;
10836 end = buf + len;
10837
10838 while (wpa_s) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010839 if (show_ctrl)
10840 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
10841 wpa_s->ifname,
10842 wpa_s->conf->ctrl_interface ?
10843 wpa_s->conf->ctrl_interface : "N/A");
10844 else
10845 res = os_snprintf(pos, end - pos, "%s\n",
10846 wpa_s->ifname);
10847
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010848 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010849 *pos = '\0';
10850 break;
10851 }
10852 pos += res;
10853 wpa_s = wpa_s->next;
10854 }
10855 return pos - buf;
10856}
10857
10858
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010859static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
10860 const char *ifname,
10861 char *cmd, size_t *resp_len)
10862{
10863 struct wpa_supplicant *wpa_s;
10864
10865 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
10866 if (os_strcmp(ifname, wpa_s->ifname) == 0)
10867 break;
10868 }
10869
10870 if (wpa_s == NULL) {
10871 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
10872 if (resp)
10873 *resp_len = os_strlen(resp);
10874 else
10875 *resp_len = 1;
10876 return resp;
10877 }
10878
10879 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
10880}
10881
10882
10883static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
10884 char *buf, size_t *resp_len)
10885{
10886#ifdef CONFIG_P2P
10887 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070010888 "LIST_NETWORKS",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010889 "P2P_FIND",
10890 "P2P_STOP_FIND",
10891 "P2P_LISTEN",
10892 "P2P_GROUP_ADD",
10893 "P2P_GET_PASSPHRASE",
10894 "P2P_SERVICE_UPDATE",
10895 "P2P_SERVICE_FLUSH",
10896 "P2P_FLUSH",
10897 "P2P_CANCEL",
10898 "P2P_PRESENCE_REQ",
10899 "P2P_EXT_LISTEN",
Paul Stewart092955c2017-02-06 09:13:09 -080010900#ifdef CONFIG_AP
10901 "STA-FIRST",
10902#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010903 NULL
10904 };
10905 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080010906#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070010907 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080010908#endif /* ANDROID */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010909 "GET_CAPABILITY ",
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070010910 "GET_NETWORK ",
10911 "REMOVE_NETWORK ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010912 "P2P_FIND ",
10913 "P2P_CONNECT ",
10914 "P2P_LISTEN ",
10915 "P2P_GROUP_REMOVE ",
10916 "P2P_GROUP_ADD ",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010917 "P2P_GROUP_MEMBER ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010918 "P2P_PROV_DISC ",
10919 "P2P_SERV_DISC_REQ ",
10920 "P2P_SERV_DISC_CANCEL_REQ ",
10921 "P2P_SERV_DISC_RESP ",
10922 "P2P_SERV_DISC_EXTERNAL ",
10923 "P2P_SERVICE_ADD ",
10924 "P2P_SERVICE_DEL ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010925 "P2P_SERVICE_REP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010926 "P2P_REJECT ",
10927 "P2P_INVITE ",
10928 "P2P_PEER ",
10929 "P2P_SET ",
10930 "P2P_UNAUTHORIZE ",
10931 "P2P_PRESENCE_REQ ",
10932 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070010933 "P2P_REMOVE_CLIENT ",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080010934 "WPS_NFC_TOKEN ",
10935 "WPS_NFC_TAG_READ ",
Dmitry Shmidt413dde72014-04-11 10:23:22 -070010936 "NFC_GET_HANDOVER_SEL ",
10937 "NFC_GET_HANDOVER_REQ ",
10938 "NFC_REPORT_HANDOVER ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010939 "P2P_ASP_PROVISION ",
10940 "P2P_ASP_PROVISION_RESP ",
Paul Stewart092955c2017-02-06 09:13:09 -080010941#ifdef CONFIG_AP
10942 "STA ",
10943 "STA-NEXT ",
10944#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010945 NULL
10946 };
10947 int found = 0;
10948 int i;
10949
10950 if (global->p2p_init_wpa_s == NULL)
10951 return NULL;
10952
10953 for (i = 0; !found && cmd[i]; i++) {
10954 if (os_strcmp(buf, cmd[i]) == 0)
10955 found = 1;
10956 }
10957
10958 for (i = 0; !found && prefix[i]; i++) {
10959 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
10960 found = 1;
10961 }
10962
10963 if (found)
10964 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
10965 buf, resp_len);
10966#endif /* CONFIG_P2P */
10967 return NULL;
10968}
10969
10970
10971static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
10972 char *buf, size_t *resp_len)
10973{
10974#ifdef CONFIG_WIFI_DISPLAY
10975 if (global->p2p_init_wpa_s == NULL)
10976 return NULL;
10977 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
10978 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
10979 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
10980 buf, resp_len);
10981#endif /* CONFIG_WIFI_DISPLAY */
10982 return NULL;
10983}
10984
10985
10986static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
10987 char *buf, size_t *resp_len)
10988{
10989 char *ret;
10990
10991 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
10992 if (ret)
10993 return ret;
10994
10995 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
10996 if (ret)
10997 return ret;
10998
10999 return NULL;
11000}
11001
11002
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011003static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
11004{
11005 char *value;
11006
11007 value = os_strchr(cmd, ' ');
11008 if (value == NULL)
11009 return -1;
11010 *value++ = '\0';
11011
11012 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
11013
11014#ifdef CONFIG_WIFI_DISPLAY
11015 if (os_strcasecmp(cmd, "wifi_display") == 0) {
11016 wifi_display_enable(global, !!atoi(value));
11017 return 0;
11018 }
11019#endif /* CONFIG_WIFI_DISPLAY */
11020
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011021 /* Restore cmd to its original value to allow redirection */
11022 value[-1] = ' ';
11023
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011024 return -1;
11025}
11026
11027
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011028static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
11029 char *cmd)
11030{
11031 struct wpa_supplicant *wpa_s[2]; /* src, dst */
11032 char *p;
11033 unsigned int i;
11034
11035 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11036 * <variable name> */
11037
11038 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
11039 p = os_strchr(cmd, ' ');
11040 if (p == NULL)
11041 return -1;
11042 *p = '\0';
11043
11044 wpa_s[i] = global->ifaces;
11045 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
11046 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
11047 break;
11048 }
11049
11050 if (!wpa_s[i]) {
11051 wpa_printf(MSG_DEBUG,
11052 "CTRL_IFACE: Could not find iface=%s", cmd);
11053 return -1;
11054 }
11055
11056 cmd = p + 1;
11057 }
11058
11059 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
11060}
11061
11062
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011063#ifndef CONFIG_NO_CONFIG_WRITE
11064static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
11065{
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011066 int ret = 0, saved = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011067 struct wpa_supplicant *wpa_s;
11068
11069 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11070 if (!wpa_s->conf->update_config) {
11071 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11072 continue;
11073 }
11074
11075 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
11076 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11077 ret = 1;
11078 } else {
11079 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011080 saved++;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011081 }
11082 }
11083
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011084 if (!saved && !ret) {
11085 wpa_dbg(wpa_s, MSG_DEBUG,
11086 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11087 ret = 1;
11088 }
11089
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011090 return ret;
11091}
11092#endif /* CONFIG_NO_CONFIG_WRITE */
11093
11094
11095static int wpas_global_ctrl_iface_status(struct wpa_global *global,
11096 char *buf, size_t buflen)
11097{
11098 char *pos, *end;
11099 int ret;
11100 struct wpa_supplicant *wpa_s;
11101
11102 pos = buf;
11103 end = buf + buflen;
11104
11105#ifdef CONFIG_P2P
11106 if (global->p2p && !global->p2p_disabled) {
11107 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
11108 "\n"
11109 "p2p_state=%s\n",
11110 MAC2STR(global->p2p_dev_addr),
11111 p2p_get_state_txt(global->p2p));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011112 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011113 return pos - buf;
11114 pos += ret;
11115 } else if (global->p2p) {
11116 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011117 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011118 return pos - buf;
11119 pos += ret;
11120 }
11121#endif /* CONFIG_P2P */
11122
11123#ifdef CONFIG_WIFI_DISPLAY
11124 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
11125 !!global->wifi_display);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011126 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011127 return pos - buf;
11128 pos += ret;
11129#endif /* CONFIG_WIFI_DISPLAY */
11130
11131 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11132 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
11133 "address=" MACSTR "\n",
11134 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011135 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011136 return pos - buf;
11137 pos += ret;
11138 }
11139
11140 return pos - buf;
11141}
11142
11143
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011144#ifdef CONFIG_FST
11145
11146static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
11147 char *cmd, char *buf,
11148 size_t reply_size)
11149{
11150 char ifname[IFNAMSIZ + 1];
11151 struct fst_iface_cfg cfg;
11152 struct wpa_supplicant *wpa_s;
11153 struct fst_wpa_obj iface_obj;
11154
11155 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
11156 wpa_s = wpa_supplicant_get_iface(global, ifname);
11157 if (wpa_s) {
11158 if (wpa_s->fst) {
11159 wpa_printf(MSG_INFO, "FST: Already attached");
11160 return -1;
11161 }
11162 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
11163 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
11164 &iface_obj, &cfg);
11165 if (wpa_s->fst)
11166 return os_snprintf(buf, reply_size, "OK\n");
11167 }
11168 }
11169
11170 return -1;
11171}
11172
11173
11174static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
11175 char *cmd, char *buf,
11176 size_t reply_size)
11177{
11178 char ifname[IFNAMSIZ + 1];
11179 struct wpa_supplicant *wpa_s;
11180
11181 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
11182 wpa_s = wpa_supplicant_get_iface(global, ifname);
11183 if (wpa_s) {
11184 if (!fst_iface_detach(ifname)) {
11185 wpa_s->fst = NULL;
11186 return os_snprintf(buf, reply_size, "OK\n");
11187 }
11188 }
11189 }
11190
11191 return -1;
11192}
11193
11194#endif /* CONFIG_FST */
11195
11196
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011197char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
11198 char *buf, size_t *resp_len)
11199{
11200 char *reply;
11201 const int reply_size = 2048;
11202 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011203 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011204
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011205 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
11206 char *pos = os_strchr(buf + 7, ' ');
11207 if (pos) {
11208 *pos++ = '\0';
11209 return wpas_global_ctrl_iface_ifname(global,
11210 buf + 7, pos,
11211 resp_len);
11212 }
11213 }
11214
11215 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
11216 if (reply)
11217 return reply;
11218
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011219 if (os_strcmp(buf, "PING") == 0)
11220 level = MSG_EXCESSIVE;
11221 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011222 (const u8 *) buf, os_strlen(buf));
11223
11224 reply = os_malloc(reply_size);
11225 if (reply == NULL) {
11226 *resp_len = 1;
11227 return NULL;
11228 }
11229
11230 os_memcpy(reply, "OK\n", 3);
11231 reply_len = 3;
11232
11233 if (os_strcmp(buf, "PING") == 0) {
11234 os_memcpy(reply, "PONG\n", 5);
11235 reply_len = 5;
11236 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
11237 if (wpa_supplicant_global_iface_add(global, buf + 14))
11238 reply_len = -1;
11239 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
11240 if (wpa_supplicant_global_iface_remove(global, buf + 17))
11241 reply_len = -1;
11242 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
11243 reply_len = wpa_supplicant_global_iface_list(
11244 global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011245 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011246 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011247 global, buf + 10, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011248#ifdef CONFIG_FST
11249 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
11250 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
11251 reply,
11252 reply_size);
11253 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
11254 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
11255 reply,
11256 reply_size);
11257 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
11258 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
11259#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011260 } else if (os_strcmp(buf, "TERMINATE") == 0) {
11261 wpa_supplicant_terminate_proc(global);
11262 } else if (os_strcmp(buf, "SUSPEND") == 0) {
11263 wpas_notify_suspend(global);
11264 } else if (os_strcmp(buf, "RESUME") == 0) {
11265 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011266 } else if (os_strncmp(buf, "SET ", 4) == 0) {
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011267 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
11268#ifdef CONFIG_P2P
11269 if (global->p2p_init_wpa_s) {
11270 os_free(reply);
11271 /* Check if P2P redirection would work for this
11272 * command. */
11273 return wpa_supplicant_ctrl_iface_process(
11274 global->p2p_init_wpa_s,
11275 buf, resp_len);
11276 }
11277#endif /* CONFIG_P2P */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011278 reply_len = -1;
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011279 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011280 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
11281 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
11282 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011283#ifndef CONFIG_NO_CONFIG_WRITE
11284 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
11285 if (wpas_global_ctrl_iface_save_config(global))
11286 reply_len = -1;
11287#endif /* CONFIG_NO_CONFIG_WRITE */
11288 } else if (os_strcmp(buf, "STATUS") == 0) {
11289 reply_len = wpas_global_ctrl_iface_status(global, reply,
11290 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080011291#ifdef CONFIG_MODULE_TESTS
11292 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080011293 if (wpas_module_tests() < 0)
11294 reply_len = -1;
11295#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011296 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
11297 if (wpa_debug_reopen_file() < 0)
11298 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011299 } else {
11300 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
11301 reply_len = 16;
11302 }
11303
11304 if (reply_len < 0) {
11305 os_memcpy(reply, "FAIL\n", 5);
11306 reply_len = 5;
11307 }
11308
11309 *resp_len = reply_len;
11310 return reply;
11311}