blob: be178d7e48e525a0b9333aedf4b78ca0142e736c [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"
Dmitry Shmidtff787d52015-01-12 13:01:47 -080023#include "crypto/tls.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080024#include "ap/hostapd.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025#include "eap_peer/eap.h"
26#include "eapol_supp/eapol_supp_sm.h"
27#include "rsn_supp/wpa.h"
28#include "rsn_supp/preauth.h"
29#include "rsn_supp/pmksa_cache.h"
30#include "l2_packet/l2_packet.h"
31#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080032#include "fst/fst.h"
33#include "fst/fst_ctrl_iface.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034#include "config.h"
35#include "wpa_supplicant_i.h"
36#include "driver_i.h"
37#include "wps_supplicant.h"
38#include "ibss_rsn.h"
39#include "ap.h"
40#include "p2p_supplicant.h"
41#include "p2p/p2p.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070042#include "hs20_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070043#include "wifi_display.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044#include "notify.h"
45#include "bss.h"
46#include "scan.h"
47#include "ctrl_iface.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080048#include "interworking.h"
Dmitry Shmidte19501d2011-03-16 14:32:18 -070049#include "blacklist.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070050#include "autoscan.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080051#include "wnm_sta.h"
Dmitry Shmidt818ea482014-03-10 13:15:21 -070052#include "offchannel.h"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070053#include "drivers/driver.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080054#include "mesh.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070055
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070056static int wpa_supplicant_global_iface_list(struct wpa_global *global,
57 char *buf, int len);
58static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080059 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070060 char *buf, int len);
Dmitry Shmidtd11f0192014-03-24 12:09:47 -070061static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
62 char *val);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070063
Dmitry Shmidt04949592012-07-19 12:16:46 -070064static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
65{
66 char *pos;
67 u8 addr[ETH_ALEN], *filter = NULL, *n;
68 size_t count = 0;
69
70 pos = val;
71 while (pos) {
72 if (*pos == '\0')
73 break;
74 if (hwaddr_aton(pos, addr)) {
75 os_free(filter);
76 return -1;
77 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070078 n = os_realloc_array(filter, count + 1, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -070079 if (n == NULL) {
80 os_free(filter);
81 return -1;
82 }
83 filter = n;
84 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
85 count++;
86
87 pos = os_strchr(pos, ' ');
88 if (pos)
89 pos++;
90 }
91
92 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
93 os_free(wpa_s->bssid_filter);
94 wpa_s->bssid_filter = filter;
95 wpa_s->bssid_filter_count = count;
96
97 return 0;
98}
99
100
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800101static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
102{
103 char *pos;
104 u8 addr[ETH_ALEN], *bssid = NULL, *n;
105 struct wpa_ssid_value *ssid = NULL, *ns;
106 size_t count = 0, ssid_count = 0;
107 struct wpa_ssid *c;
108
109 /*
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800110 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800111 * SSID_SPEC ::= ssid <SSID_HEX>
112 * BSSID_SPEC ::= bssid <BSSID_HEX>
113 */
114
115 pos = val;
116 while (pos) {
117 if (*pos == '\0')
118 break;
119 if (os_strncmp(pos, "bssid ", 6) == 0) {
120 int res;
121 pos += 6;
122 res = hwaddr_aton2(pos, addr);
123 if (res < 0) {
124 os_free(ssid);
125 os_free(bssid);
126 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
127 "BSSID value '%s'", pos);
128 return -1;
129 }
130 pos += res;
131 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
132 if (n == NULL) {
133 os_free(ssid);
134 os_free(bssid);
135 return -1;
136 }
137 bssid = n;
138 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
139 count++;
140 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
141 char *end;
142 pos += 5;
143
144 end = pos;
145 while (*end) {
146 if (*end == '\0' || *end == ' ')
147 break;
148 end++;
149 }
150
151 ns = os_realloc_array(ssid, ssid_count + 1,
152 sizeof(struct wpa_ssid_value));
153 if (ns == NULL) {
154 os_free(ssid);
155 os_free(bssid);
156 return -1;
157 }
158 ssid = ns;
159
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700160 if ((end - pos) & 0x01 ||
161 end - pos > 2 * SSID_MAX_LEN ||
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800162 hexstr2bin(pos, ssid[ssid_count].ssid,
163 (end - pos) / 2) < 0) {
164 os_free(ssid);
165 os_free(bssid);
166 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
167 "SSID value '%s'", pos);
168 return -1;
169 }
170 ssid[ssid_count].ssid_len = (end - pos) / 2;
171 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
172 ssid[ssid_count].ssid,
173 ssid[ssid_count].ssid_len);
174 ssid_count++;
175 pos = end;
176 } else {
177 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
178 "'%s'", pos);
179 os_free(ssid);
180 os_free(bssid);
181 return -1;
182 }
183
184 pos = os_strchr(pos, ' ');
185 if (pos)
186 pos++;
187 }
188
189 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
190 os_free(wpa_s->disallow_aps_bssid);
191 wpa_s->disallow_aps_bssid = bssid;
192 wpa_s->disallow_aps_bssid_count = count;
193
194 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
195 os_free(wpa_s->disallow_aps_ssid);
196 wpa_s->disallow_aps_ssid = ssid;
197 wpa_s->disallow_aps_ssid_count = ssid_count;
198
199 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
200 return 0;
201
202 c = wpa_s->current_ssid;
203 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
204 return 0;
205
206 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
207 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
208 return 0;
209
210 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
211 "because current AP was marked disallowed");
212
213#ifdef CONFIG_SME
214 wpa_s->sme.prev_bssid_set = 0;
215#endif /* CONFIG_SME */
216 wpa_s->reassociate = 1;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800217 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800218 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
219 wpa_supplicant_req_scan(wpa_s, 0, 0);
220
221 return 0;
222}
223
224
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700225#ifndef CONFIG_NO_CONFIG_BLOBS
226static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
227{
228 char *name = pos;
229 struct wpa_config_blob *blob;
230 size_t len;
231
232 pos = os_strchr(pos, ' ');
233 if (pos == NULL)
234 return -1;
235 *pos++ = '\0';
236 len = os_strlen(pos);
237 if (len & 1)
238 return -1;
239
240 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
241 blob = os_zalloc(sizeof(*blob));
242 if (blob == NULL)
243 return -1;
244 blob->name = os_strdup(name);
245 blob->data = os_malloc(len / 2);
246 if (blob->name == NULL || blob->data == NULL) {
247 wpa_config_free_blob(blob);
248 return -1;
249 }
250
251 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
252 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
253 wpa_config_free_blob(blob);
254 return -1;
255 }
256 blob->len = len / 2;
257
258 wpa_config_set_blob(wpa_s->conf, blob);
259
260 return 0;
261}
262#endif /* CONFIG_NO_CONFIG_BLOBS */
263
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700264
265static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
266{
267 char *params;
268 char *pos;
269 int *freqs = NULL;
270 int ret;
271
272 if (atoi(cmd)) {
273 params = os_strchr(cmd, ' ');
274 os_free(wpa_s->manual_sched_scan_freqs);
275 if (params) {
276 params++;
277 pos = os_strstr(params, "freq=");
278 if (pos)
279 freqs = freq_range_to_channel_list(wpa_s,
280 pos + 5);
281 }
282 wpa_s->manual_sched_scan_freqs = freqs;
283 ret = wpas_start_pno(wpa_s);
284 } else {
285 ret = wpas_stop_pno(wpa_s);
286 }
287 return ret;
288}
289
290
Ravi Joshie6ccb162015-07-16 17:45:41 -0700291static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band)
292{
293 union wpa_event_data event;
294
295 if (os_strcmp(band, "AUTO") == 0)
296 wpa_s->setband = WPA_SETBAND_AUTO;
297 else if (os_strcmp(band, "5G") == 0)
298 wpa_s->setband = WPA_SETBAND_5G;
299 else if (os_strcmp(band, "2G") == 0)
300 wpa_s->setband = WPA_SETBAND_2G;
301 else
302 return -1;
303
304 if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) {
305 os_memset(&event, 0, sizeof(event));
306 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
307 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
308 wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
309 }
310
311 return 0;
312}
313
314
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700315static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s,
316 const char *cmd)
317{
318 struct wpabuf *lci;
319
320 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
321 wpabuf_free(wpa_s->lci);
322 wpa_s->lci = NULL;
323 return 0;
324 }
325
326 lci = wpabuf_parse_bin(cmd);
327 if (!lci)
328 return -1;
329
330 if (os_get_reltime(&wpa_s->lci_time)) {
331 wpabuf_free(lci);
332 return -1;
333 }
334
335 wpabuf_free(wpa_s->lci);
336 wpa_s->lci = lci;
337
338 return 0;
339}
340
341
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
343 char *cmd)
344{
345 char *value;
346 int ret = 0;
347
348 value = os_strchr(cmd, ' ');
349 if (value == NULL)
350 return -1;
351 *value++ = '\0';
352
353 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
354 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
355 eapol_sm_configure(wpa_s->eapol,
356 atoi(value), -1, -1, -1);
357 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
358 eapol_sm_configure(wpa_s->eapol,
359 -1, atoi(value), -1, -1);
360 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
361 eapol_sm_configure(wpa_s->eapol,
362 -1, -1, atoi(value), -1);
363 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
364 eapol_sm_configure(wpa_s->eapol,
365 -1, -1, -1, atoi(value));
366 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
367 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
368 atoi(value)))
369 ret = -1;
370 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
371 0) {
372 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
373 atoi(value)))
374 ret = -1;
375 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
376 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
377 ret = -1;
378 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
379 wpa_s->wps_fragment_size = atoi(value);
380#ifdef CONFIG_WPS_TESTING
381 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
382 long int val;
383 val = strtol(value, NULL, 0);
384 if (val < 0 || val > 0xff) {
385 ret = -1;
386 wpa_printf(MSG_DEBUG, "WPS: Invalid "
387 "wps_version_number %ld", val);
388 } else {
389 wps_version_number = val;
390 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
391 "version %u.%u",
392 (wps_version_number & 0xf0) >> 4,
393 wps_version_number & 0x0f);
394 }
395 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
396 wps_testing_dummy_cred = atoi(value);
397 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
398 wps_testing_dummy_cred);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800399 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
400 wps_corrupt_pkhash = atoi(value);
401 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
402 wps_corrupt_pkhash);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800403 } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
404 if (value[0] == '\0') {
405 wps_force_auth_types_in_use = 0;
406 } else {
407 wps_force_auth_types = strtol(value, NULL, 0);
408 wps_force_auth_types_in_use = 1;
409 }
410 } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
411 if (value[0] == '\0') {
412 wps_force_encr_types_in_use = 0;
413 } else {
414 wps_force_encr_types = strtol(value, NULL, 0);
415 wps_force_encr_types_in_use = 1;
416 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700417#endif /* CONFIG_WPS_TESTING */
418 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
419 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
420 ret = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800421#ifdef CONFIG_TDLS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422#ifdef CONFIG_TDLS_TESTING
423 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700424 tdls_testing = strtol(value, NULL, 0);
425 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
426#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700427 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
428 int disabled = atoi(value);
429 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
430 if (disabled) {
431 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
432 ret = -1;
433 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
434 ret = -1;
435 wpa_tdls_enable(wpa_s->wpa, !disabled);
436#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800437 } else if (os_strcasecmp(cmd, "pno") == 0) {
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700438 ret = wpas_ctrl_pno(wpa_s, value);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700439 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
440 int disabled = atoi(value);
441 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
442 ret = -1;
443 else if (disabled)
444 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
445 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
446 if (os_strcmp(value, "disable") == 0)
447 wpa_s->set_sta_uapsd = 0;
448 else {
449 int be, bk, vi, vo;
450 char *pos;
451 /* format: BE,BK,VI,VO;max SP Length */
452 be = atoi(value);
453 pos = os_strchr(value, ',');
454 if (pos == NULL)
455 return -1;
456 pos++;
457 bk = atoi(pos);
458 pos = os_strchr(pos, ',');
459 if (pos == NULL)
460 return -1;
461 pos++;
462 vi = atoi(pos);
463 pos = os_strchr(pos, ',');
464 if (pos == NULL)
465 return -1;
466 pos++;
467 vo = atoi(pos);
468 /* ignore max SP Length for now */
469
470 wpa_s->set_sta_uapsd = 1;
471 wpa_s->sta_uapsd = 0;
472 if (be)
473 wpa_s->sta_uapsd |= BIT(0);
474 if (bk)
475 wpa_s->sta_uapsd |= BIT(1);
476 if (vi)
477 wpa_s->sta_uapsd |= BIT(2);
478 if (vo)
479 wpa_s->sta_uapsd |= BIT(3);
480 }
Jouni Malinen21d6bc82012-04-10 16:17:59 -0700481 } else if (os_strcasecmp(cmd, "ps") == 0) {
482 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700483#ifdef CONFIG_WIFI_DISPLAY
484 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800485 int enabled = !!atoi(value);
486 if (enabled && !wpa_s->global->p2p)
487 ret = -1;
488 else
489 wifi_display_enable(wpa_s->global, enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700490#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700491 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
492 ret = set_bssid_filter(wpa_s, value);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800493 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
494 ret = set_disallow_aps(wpa_s, value);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800495 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
496 wpa_s->no_keep_alive = !!atoi(value);
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700497#ifdef CONFIG_TESTING_OPTIONS
498 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
499 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800500 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
501 wpa_s->ext_eapol_frame_io = !!atoi(value);
502#ifdef CONFIG_AP
503 if (wpa_s->ap_iface) {
504 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
505 wpa_s->ext_eapol_frame_io;
506 }
507#endif /* CONFIG_AP */
508 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
509 wpa_s->extra_roc_dur = atoi(value);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800510 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
511 wpa_s->test_failure = atoi(value);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800512 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
513 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700514 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
515 wpa_s->ignore_auth_resp = !!atoi(value);
516 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
517 wpa_s->ignore_assoc_disallow = !!atoi(value);
518 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
519 wpa_s->reject_btm_req_reason = atoi(value);
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700520#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700521#ifndef CONFIG_NO_CONFIG_BLOBS
522 } else if (os_strcmp(cmd, "blob") == 0) {
523 ret = wpas_ctrl_set_blob(wpa_s, value);
524#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800525 } else if (os_strcasecmp(cmd, "setband") == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700526 ret = wpas_ctrl_set_band(wpa_s, value);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800527#ifdef CONFIG_MBO
528 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
529 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
530 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
531 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
532#endif /* CONFIG_MBO */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700533 } else if (os_strcasecmp(cmd, "lci") == 0) {
534 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800535 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
536 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700537 } else {
538 value[-1] = '=';
539 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
540 if (ret == 0)
541 wpa_supplicant_update_config(wpa_s);
542 }
543
544 return ret;
545}
546
547
548static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
549 char *cmd, char *buf, size_t buflen)
550{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700551 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700552
553 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
554
555 if (os_strcmp(cmd, "version") == 0) {
556 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700557 } else if (os_strcasecmp(cmd, "country") == 0) {
558 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
559 res = os_snprintf(buf, buflen, "%c%c",
560 wpa_s->conf->country[0],
561 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700562#ifdef CONFIG_WIFI_DISPLAY
563 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800564 int enabled;
565 if (wpa_s->global->p2p == NULL ||
566 wpa_s->global->p2p_disabled)
567 enabled = 0;
568 else
569 enabled = wpa_s->global->wifi_display;
570 res = os_snprintf(buf, buflen, "%d", enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700571#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700572#ifdef CONFIG_TESTING_GET_GTK
573 } else if (os_strcmp(cmd, "gtk") == 0) {
574 if (wpa_s->last_gtk_len == 0)
575 return -1;
576 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
577 wpa_s->last_gtk_len);
578 return res;
579#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800580 } else if (os_strcmp(cmd, "tls_library") == 0) {
581 res = tls_get_library_version(buf, buflen);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800582 } else {
583 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584 }
585
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800586 if (os_snprintf_error(buflen, res))
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700587 return -1;
588 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589}
590
591
592#ifdef IEEE8021X_EAPOL
593static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
594 char *addr)
595{
596 u8 bssid[ETH_ALEN];
597 struct wpa_ssid *ssid = wpa_s->current_ssid;
598
599 if (hwaddr_aton(addr, bssid)) {
600 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
601 "'%s'", addr);
602 return -1;
603 }
604
605 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
606 rsn_preauth_deinit(wpa_s->wpa);
607 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
608 return -1;
609
610 return 0;
611}
612#endif /* IEEE8021X_EAPOL */
613
614
615#ifdef CONFIG_PEERKEY
616/* MLME-STKSTART.request(peer) */
617static int wpa_supplicant_ctrl_iface_stkstart(
618 struct wpa_supplicant *wpa_s, char *addr)
619{
620 u8 peer[ETH_ALEN];
621
622 if (hwaddr_aton(addr, peer)) {
623 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
624 "address '%s'", addr);
625 return -1;
626 }
627
628 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
629 MAC2STR(peer));
630
631 return wpa_sm_stkstart(wpa_s->wpa, peer);
632}
633#endif /* CONFIG_PEERKEY */
634
635
636#ifdef CONFIG_TDLS
637
638static int wpa_supplicant_ctrl_iface_tdls_discover(
639 struct wpa_supplicant *wpa_s, char *addr)
640{
641 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800642 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700643
644 if (hwaddr_aton(addr, peer)) {
645 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
646 "address '%s'", addr);
647 return -1;
648 }
649
650 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
651 MAC2STR(peer));
652
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800653 if (wpa_tdls_is_external_setup(wpa_s->wpa))
654 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
655 else
656 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
657
658 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700659}
660
661
662static int wpa_supplicant_ctrl_iface_tdls_setup(
663 struct wpa_supplicant *wpa_s, char *addr)
664{
665 u8 peer[ETH_ALEN];
666 int ret;
667
668 if (hwaddr_aton(addr, peer)) {
669 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
670 "address '%s'", addr);
671 return -1;
672 }
673
674 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
675 MAC2STR(peer));
676
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800677 if ((wpa_s->conf->tdls_external_control) &&
678 wpa_tdls_is_external_setup(wpa_s->wpa))
679 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
680
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800681 wpa_tdls_remove(wpa_s->wpa, peer);
682
683 if (wpa_tdls_is_external_setup(wpa_s->wpa))
684 ret = wpa_tdls_start(wpa_s->wpa, peer);
685 else
686 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800687
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700688 return ret;
689}
690
691
692static int wpa_supplicant_ctrl_iface_tdls_teardown(
693 struct wpa_supplicant *wpa_s, char *addr)
694{
695 u8 peer[ETH_ALEN];
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700696 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700697
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700698 if (os_strcmp(addr, "*") == 0) {
699 /* remove everyone */
700 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
701 wpa_tdls_teardown_peers(wpa_s->wpa);
702 return 0;
703 }
704
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700705 if (hwaddr_aton(addr, peer)) {
706 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
707 "address '%s'", addr);
708 return -1;
709 }
710
711 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
712 MAC2STR(peer));
713
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800714 if ((wpa_s->conf->tdls_external_control) &&
715 wpa_tdls_is_external_setup(wpa_s->wpa))
716 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
717
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700718 if (wpa_tdls_is_external_setup(wpa_s->wpa))
719 ret = wpa_tdls_teardown_link(
720 wpa_s->wpa, peer,
721 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
722 else
723 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
724
725 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700726}
727
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700728
729static int ctrl_iface_get_capability_tdls(
730 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
731{
732 int ret;
733
734 ret = os_snprintf(buf, buflen, "%s\n",
735 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
736 (wpa_s->drv_flags &
737 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
738 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800739 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700740 return -1;
741 return ret;
742}
743
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800744
745static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
746 struct wpa_supplicant *wpa_s, char *cmd)
747{
748 u8 peer[ETH_ALEN];
749 struct hostapd_freq_params freq_params;
750 u8 oper_class;
751 char *pos, *end;
752
753 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
754 wpa_printf(MSG_INFO,
755 "tdls_chanswitch: Only supported with external setup");
756 return -1;
757 }
758
759 os_memset(&freq_params, 0, sizeof(freq_params));
760
761 pos = os_strchr(cmd, ' ');
762 if (pos == NULL)
763 return -1;
764 *pos++ = '\0';
765
766 oper_class = strtol(pos, &end, 10);
767 if (pos == end) {
768 wpa_printf(MSG_INFO,
769 "tdls_chanswitch: Invalid op class provided");
770 return -1;
771 }
772
773 pos = end;
774 freq_params.freq = atoi(pos);
775 if (freq_params.freq == 0) {
776 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
777 return -1;
778 }
779
780#define SET_FREQ_SETTING(str) \
781 do { \
782 const char *pos2 = os_strstr(pos, " " #str "="); \
783 if (pos2) { \
784 pos2 += sizeof(" " #str "=") - 1; \
785 freq_params.str = atoi(pos2); \
786 } \
787 } while (0)
788
789 SET_FREQ_SETTING(center_freq1);
790 SET_FREQ_SETTING(center_freq2);
791 SET_FREQ_SETTING(bandwidth);
792 SET_FREQ_SETTING(sec_channel_offset);
793#undef SET_FREQ_SETTING
794
795 freq_params.ht_enabled = !!os_strstr(pos, " ht");
796 freq_params.vht_enabled = !!os_strstr(pos, " vht");
797
798 if (hwaddr_aton(cmd, peer)) {
799 wpa_printf(MSG_DEBUG,
800 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
801 cmd);
802 return -1;
803 }
804
805 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
806 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
807 MAC2STR(peer), oper_class, freq_params.freq,
808 freq_params.center_freq1, freq_params.center_freq2,
809 freq_params.bandwidth, freq_params.sec_channel_offset,
810 freq_params.ht_enabled ? " HT" : "",
811 freq_params.vht_enabled ? " VHT" : "");
812
813 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
814 &freq_params);
815}
816
817
818static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
819 struct wpa_supplicant *wpa_s, char *cmd)
820{
821 u8 peer[ETH_ALEN];
822
823 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
824 wpa_printf(MSG_INFO,
825 "tdls_chanswitch: Only supported with external setup");
826 return -1;
827 }
828
829 if (hwaddr_aton(cmd, peer)) {
830 wpa_printf(MSG_DEBUG,
831 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
832 cmd);
833 return -1;
834 }
835
836 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
837 MAC2STR(peer));
838
839 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
840}
841
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -0700842
843static int wpa_supplicant_ctrl_iface_tdls_link_status(
844 struct wpa_supplicant *wpa_s, const char *addr,
845 char *buf, size_t buflen)
846{
847 u8 peer[ETH_ALEN];
848 const char *tdls_status;
849 int ret;
850
851 if (hwaddr_aton(addr, peer)) {
852 wpa_printf(MSG_DEBUG,
853 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
854 addr);
855 return -1;
856 }
857 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
858 MAC2STR(peer));
859
860 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
861 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
862 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
863 if (os_snprintf_error(buflen, ret))
864 return -1;
865
866 return ret;
867}
868
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700869#endif /* CONFIG_TDLS */
870
871
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800872static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
873{
874 char *token, *context = NULL;
875 struct wmm_ac_ts_setup_params params = {
876 .tsid = 0xff,
877 .direction = 0xff,
878 };
879
880 while ((token = str_token(cmd, " ", &context))) {
881 if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
882 sscanf(token, "up=%i", &params.user_priority) == 1 ||
883 sscanf(token, "nominal_msdu_size=%i",
884 &params.nominal_msdu_size) == 1 ||
885 sscanf(token, "mean_data_rate=%i",
886 &params.mean_data_rate) == 1 ||
887 sscanf(token, "min_phy_rate=%i",
888 &params.minimum_phy_rate) == 1 ||
889 sscanf(token, "sba=%i",
890 &params.surplus_bandwidth_allowance) == 1)
891 continue;
892
893 if (os_strcasecmp(token, "downlink") == 0) {
894 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
895 } else if (os_strcasecmp(token, "uplink") == 0) {
896 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
897 } else if (os_strcasecmp(token, "bidi") == 0) {
898 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
899 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
900 params.fixed_nominal_msdu = 1;
901 } else {
902 wpa_printf(MSG_DEBUG,
903 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
904 token);
905 return -1;
906 }
907
908 }
909
910 return wpas_wmm_ac_addts(wpa_s, &params);
911}
912
913
914static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
915{
916 u8 tsid = atoi(cmd);
917
918 return wpas_wmm_ac_delts(wpa_s, tsid);
919}
920
921
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922#ifdef CONFIG_IEEE80211R
923static int wpa_supplicant_ctrl_iface_ft_ds(
924 struct wpa_supplicant *wpa_s, char *addr)
925{
926 u8 target_ap[ETH_ALEN];
927 struct wpa_bss *bss;
928 const u8 *mdie;
929
930 if (hwaddr_aton(addr, target_ap)) {
931 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
932 "address '%s'", addr);
933 return -1;
934 }
935
936 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
937
938 bss = wpa_bss_get_bssid(wpa_s, target_ap);
939 if (bss)
940 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
941 else
942 mdie = NULL;
943
944 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
945}
946#endif /* CONFIG_IEEE80211R */
947
948
949#ifdef CONFIG_WPS
950static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
951 char *cmd)
952{
953 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -0700954#ifdef CONFIG_P2P
955 u8 p2p_dev_addr[ETH_ALEN];
956#endif /* CONFIG_P2P */
957#ifdef CONFIG_AP
958 u8 *_p2p_dev_addr = NULL;
959#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800960
Dmitry Shmidtc0a8db02013-11-08 11:18:33 -0800961 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962 _bssid = NULL;
963#ifdef CONFIG_P2P
964 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
965 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
966 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
967 "P2P Device Address '%s'",
968 cmd + 13);
969 return -1;
970 }
971 _p2p_dev_addr = p2p_dev_addr;
972#endif /* CONFIG_P2P */
973 } else if (hwaddr_aton(cmd, bssid)) {
974 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
975 cmd);
976 return -1;
977 }
978
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800979#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980 if (wpa_s->ap_iface)
981 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
982#endif /* CONFIG_AP */
983
984 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
985}
986
987
988static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
989 char *cmd, char *buf,
990 size_t buflen)
991{
992 u8 bssid[ETH_ALEN], *_bssid = bssid;
993 char *pin;
994 int ret;
995
996 pin = os_strchr(cmd, ' ');
997 if (pin)
998 *pin++ = '\0';
999
1000 if (os_strcmp(cmd, "any") == 0)
1001 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001002 else if (os_strcmp(cmd, "get") == 0) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001003 if (wps_generate_pin((unsigned int *) &ret) < 0)
1004 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001005 goto done;
1006 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001007 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1008 cmd);
1009 return -1;
1010 }
1011
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001012#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001013 if (wpa_s->ap_iface) {
1014 int timeout = 0;
1015 char *pos;
1016
1017 if (pin) {
1018 pos = os_strchr(pin, ' ');
1019 if (pos) {
1020 *pos++ = '\0';
1021 timeout = atoi(pos);
1022 }
1023 }
1024
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001025 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001026 buf, buflen, timeout);
1027 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001028#endif /* CONFIG_AP */
1029
1030 if (pin) {
1031 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1032 DEV_PW_DEFAULT);
1033 if (ret < 0)
1034 return -1;
1035 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001036 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037 return -1;
1038 return ret;
1039 }
1040
1041 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1042 if (ret < 0)
1043 return -1;
1044
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001045done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046 /* Return the generated PIN */
1047 ret = os_snprintf(buf, buflen, "%08d", ret);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001048 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001049 return -1;
1050 return ret;
1051}
1052
1053
1054static int wpa_supplicant_ctrl_iface_wps_check_pin(
1055 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1056{
1057 char pin[9];
1058 size_t len;
1059 char *pos;
1060 int ret;
1061
1062 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1063 (u8 *) cmd, os_strlen(cmd));
1064 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1065 if (*pos < '0' || *pos > '9')
1066 continue;
1067 pin[len++] = *pos;
1068 if (len == 9) {
1069 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1070 return -1;
1071 }
1072 }
1073 if (len != 4 && len != 8) {
1074 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1075 return -1;
1076 }
1077 pin[len] = '\0';
1078
1079 if (len == 8) {
1080 unsigned int pin_val;
1081 pin_val = atoi(pin);
1082 if (!wps_pin_valid(pin_val)) {
1083 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1084 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001085 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001086 return -1;
1087 return ret;
1088 }
1089 }
1090
1091 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001092 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001093 return -1;
1094
1095 return ret;
1096}
1097
1098
Dmitry Shmidt04949592012-07-19 12:16:46 -07001099#ifdef CONFIG_WPS_NFC
1100
1101static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1102 char *cmd)
1103{
1104 u8 bssid[ETH_ALEN], *_bssid = bssid;
1105
1106 if (cmd == NULL || cmd[0] == '\0')
1107 _bssid = NULL;
1108 else if (hwaddr_aton(cmd, bssid))
1109 return -1;
1110
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001111 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1112 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001113}
1114
1115
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001116static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1117 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1118{
1119 int ndef;
1120 struct wpabuf *buf;
1121 int res;
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001122 char *pos;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001123
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001124 pos = os_strchr(cmd, ' ');
1125 if (pos)
1126 *pos++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001127 if (os_strcmp(cmd, "WPS") == 0)
1128 ndef = 0;
1129 else if (os_strcmp(cmd, "NDEF") == 0)
1130 ndef = 1;
1131 else
1132 return -1;
1133
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001134 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001135 if (buf == NULL)
1136 return -1;
1137
1138 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1139 wpabuf_len(buf));
1140 reply[res++] = '\n';
1141 reply[res] = '\0';
1142
1143 wpabuf_free(buf);
1144
1145 return res;
1146}
1147
1148
Dmitry Shmidt04949592012-07-19 12:16:46 -07001149static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1150 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1151{
1152 int ndef;
1153 struct wpabuf *buf;
1154 int res;
1155
1156 if (os_strcmp(cmd, "WPS") == 0)
1157 ndef = 0;
1158 else if (os_strcmp(cmd, "NDEF") == 0)
1159 ndef = 1;
1160 else
1161 return -1;
1162
1163 buf = wpas_wps_nfc_token(wpa_s, ndef);
1164 if (buf == NULL)
1165 return -1;
1166
1167 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1168 wpabuf_len(buf));
1169 reply[res++] = '\n';
1170 reply[res] = '\0';
1171
1172 wpabuf_free(buf);
1173
1174 return res;
1175}
1176
1177
1178static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1179 struct wpa_supplicant *wpa_s, char *pos)
1180{
1181 size_t len;
1182 struct wpabuf *buf;
1183 int ret;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001184 char *freq;
1185 int forced_freq = 0;
1186
1187 freq = strstr(pos, " freq=");
1188 if (freq) {
1189 *freq = '\0';
1190 freq += 6;
1191 forced_freq = atoi(freq);
1192 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001193
1194 len = os_strlen(pos);
1195 if (len & 0x01)
1196 return -1;
1197 len /= 2;
1198
1199 buf = wpabuf_alloc(len);
1200 if (buf == NULL)
1201 return -1;
1202 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1203 wpabuf_free(buf);
1204 return -1;
1205 }
1206
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001207 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001208 wpabuf_free(buf);
1209
1210 return ret;
1211}
1212
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001213
1214static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001215 char *reply, size_t max_len,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001216 int ndef)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001217{
1218 struct wpabuf *buf;
1219 int res;
1220
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001221 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001222 if (buf == NULL)
1223 return -1;
1224
1225 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1226 wpabuf_len(buf));
1227 reply[res++] = '\n';
1228 reply[res] = '\0';
1229
1230 wpabuf_free(buf);
1231
1232 return res;
1233}
1234
1235
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001236#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001237static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1238 char *reply, size_t max_len,
1239 int ndef)
1240{
1241 struct wpabuf *buf;
1242 int res;
1243
1244 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1245 if (buf == NULL) {
1246 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1247 return -1;
1248 }
1249
1250 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1251 wpabuf_len(buf));
1252 reply[res++] = '\n';
1253 reply[res] = '\0';
1254
1255 wpabuf_free(buf);
1256
1257 return res;
1258}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001259#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001260
1261
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001262static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1263 char *cmd, char *reply,
1264 size_t max_len)
1265{
1266 char *pos;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001267 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001268
1269 pos = os_strchr(cmd, ' ');
1270 if (pos == NULL)
1271 return -1;
1272 *pos++ = '\0';
1273
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001274 if (os_strcmp(cmd, "WPS") == 0)
1275 ndef = 0;
1276 else if (os_strcmp(cmd, "NDEF") == 0)
1277 ndef = 1;
1278 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001279 return -1;
1280
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001281 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001282 if (!ndef)
1283 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001284 return wpas_ctrl_nfc_get_handover_req_wps(
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001285 wpa_s, reply, max_len, ndef);
1286 }
1287
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001288#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001289 if (os_strcmp(pos, "P2P-CR") == 0) {
1290 return wpas_ctrl_nfc_get_handover_req_p2p(
1291 wpa_s, reply, max_len, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001292 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001293#endif /* CONFIG_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001294
1295 return -1;
1296}
1297
1298
1299static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001300 char *reply, size_t max_len,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001301 int ndef, int cr, char *uuid)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001302{
1303 struct wpabuf *buf;
1304 int res;
1305
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001306 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001307 if (buf == NULL)
1308 return -1;
1309
1310 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1311 wpabuf_len(buf));
1312 reply[res++] = '\n';
1313 reply[res] = '\0';
1314
1315 wpabuf_free(buf);
1316
1317 return res;
1318}
1319
1320
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001321#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001322static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1323 char *reply, size_t max_len,
1324 int ndef, int tag)
1325{
1326 struct wpabuf *buf;
1327 int res;
1328
1329 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1330 if (buf == NULL)
1331 return -1;
1332
1333 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1334 wpabuf_len(buf));
1335 reply[res++] = '\n';
1336 reply[res] = '\0';
1337
1338 wpabuf_free(buf);
1339
1340 return res;
1341}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001342#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001343
1344
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001345static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1346 char *cmd, char *reply,
1347 size_t max_len)
1348{
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001349 char *pos, *pos2;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001350 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001351
1352 pos = os_strchr(cmd, ' ');
1353 if (pos == NULL)
1354 return -1;
1355 *pos++ = '\0';
1356
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001357 if (os_strcmp(cmd, "WPS") == 0)
1358 ndef = 0;
1359 else if (os_strcmp(cmd, "NDEF") == 0)
1360 ndef = 1;
1361 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001362 return -1;
1363
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001364 pos2 = os_strchr(pos, ' ');
1365 if (pos2)
1366 *pos2++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001367 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001368 if (!ndef)
1369 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001370 return wpas_ctrl_nfc_get_handover_sel_wps(
1371 wpa_s, reply, max_len, ndef,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001372 os_strcmp(pos, "WPS-CR") == 0, pos2);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001373 }
1374
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001375#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001376 if (os_strcmp(pos, "P2P-CR") == 0) {
1377 return wpas_ctrl_nfc_get_handover_sel_p2p(
1378 wpa_s, reply, max_len, ndef, 0);
1379 }
1380
1381 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1382 return wpas_ctrl_nfc_get_handover_sel_p2p(
1383 wpa_s, reply, max_len, ndef, 1);
1384 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001385#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001386
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001387 return -1;
1388}
1389
1390
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001391static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1392 char *cmd)
1393{
1394 size_t len;
1395 struct wpabuf *req, *sel;
1396 int ret;
1397 char *pos, *role, *type, *pos2;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001398#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001399 char *freq;
1400 int forced_freq = 0;
1401
1402 freq = strstr(cmd, " freq=");
1403 if (freq) {
1404 *freq = '\0';
1405 freq += 6;
1406 forced_freq = atoi(freq);
1407 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001408#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001409
1410 role = cmd;
1411 pos = os_strchr(role, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001412 if (pos == NULL) {
1413 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001414 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001415 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001416 *pos++ = '\0';
1417
1418 type = pos;
1419 pos = os_strchr(type, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001420 if (pos == NULL) {
1421 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001422 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001423 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001424 *pos++ = '\0';
1425
1426 pos2 = os_strchr(pos, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001427 if (pos2 == NULL) {
1428 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001429 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001430 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001431 *pos2++ = '\0';
1432
1433 len = os_strlen(pos);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001434 if (len & 0x01) {
1435 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001436 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001437 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001438 len /= 2;
1439
1440 req = wpabuf_alloc(len);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001441 if (req == NULL) {
1442 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001443 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001444 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001445 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001446 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001447 wpabuf_free(req);
1448 return -1;
1449 }
1450
1451 len = os_strlen(pos2);
1452 if (len & 0x01) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001453 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001454 wpabuf_free(req);
1455 return -1;
1456 }
1457 len /= 2;
1458
1459 sel = wpabuf_alloc(len);
1460 if (sel == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001461 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001462 wpabuf_free(req);
1463 return -1;
1464 }
1465 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001466 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001467 wpabuf_free(req);
1468 wpabuf_free(sel);
1469 return -1;
1470 }
1471
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001472 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1473 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1474
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001475 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1476 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001477#ifdef CONFIG_AP
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001478 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1479 {
1480 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1481 if (ret < 0)
1482 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001483#endif /* CONFIG_AP */
1484#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001485 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1486 {
1487 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1488 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1489 {
1490 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1491 forced_freq);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001492#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001493 } else {
1494 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1495 "reported: role=%s type=%s", role, type);
1496 ret = -1;
1497 }
1498 wpabuf_free(req);
1499 wpabuf_free(sel);
1500
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001501 if (ret)
1502 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1503
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001504 return ret;
1505}
1506
Dmitry Shmidt04949592012-07-19 12:16:46 -07001507#endif /* CONFIG_WPS_NFC */
1508
1509
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001510static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1511 char *cmd)
1512{
1513 u8 bssid[ETH_ALEN];
1514 char *pin;
1515 char *new_ssid;
1516 char *new_auth;
1517 char *new_encr;
1518 char *new_key;
1519 struct wps_new_ap_settings ap;
1520
1521 pin = os_strchr(cmd, ' ');
1522 if (pin == NULL)
1523 return -1;
1524 *pin++ = '\0';
1525
1526 if (hwaddr_aton(cmd, bssid)) {
1527 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1528 cmd);
1529 return -1;
1530 }
1531
1532 new_ssid = os_strchr(pin, ' ');
1533 if (new_ssid == NULL)
1534 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1535 *new_ssid++ = '\0';
1536
1537 new_auth = os_strchr(new_ssid, ' ');
1538 if (new_auth == NULL)
1539 return -1;
1540 *new_auth++ = '\0';
1541
1542 new_encr = os_strchr(new_auth, ' ');
1543 if (new_encr == NULL)
1544 return -1;
1545 *new_encr++ = '\0';
1546
1547 new_key = os_strchr(new_encr, ' ');
1548 if (new_key == NULL)
1549 return -1;
1550 *new_key++ = '\0';
1551
1552 os_memset(&ap, 0, sizeof(ap));
1553 ap.ssid_hex = new_ssid;
1554 ap.auth = new_auth;
1555 ap.encr = new_encr;
1556 ap.key_hex = new_key;
1557 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1558}
1559
1560
1561#ifdef CONFIG_AP
1562static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1563 char *cmd, char *buf,
1564 size_t buflen)
1565{
1566 int timeout = 300;
1567 char *pos;
1568 const char *pin_txt;
1569
1570 if (!wpa_s->ap_iface)
1571 return -1;
1572
1573 pos = os_strchr(cmd, ' ');
1574 if (pos)
1575 *pos++ = '\0';
1576
1577 if (os_strcmp(cmd, "disable") == 0) {
1578 wpas_wps_ap_pin_disable(wpa_s);
1579 return os_snprintf(buf, buflen, "OK\n");
1580 }
1581
1582 if (os_strcmp(cmd, "random") == 0) {
1583 if (pos)
1584 timeout = atoi(pos);
1585 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1586 if (pin_txt == NULL)
1587 return -1;
1588 return os_snprintf(buf, buflen, "%s", pin_txt);
1589 }
1590
1591 if (os_strcmp(cmd, "get") == 0) {
1592 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1593 if (pin_txt == NULL)
1594 return -1;
1595 return os_snprintf(buf, buflen, "%s", pin_txt);
1596 }
1597
1598 if (os_strcmp(cmd, "set") == 0) {
1599 char *pin;
1600 if (pos == NULL)
1601 return -1;
1602 pin = pos;
1603 pos = os_strchr(pos, ' ');
1604 if (pos) {
1605 *pos++ = '\0';
1606 timeout = atoi(pos);
1607 }
1608 if (os_strlen(pin) > buflen)
1609 return -1;
1610 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1611 return -1;
1612 return os_snprintf(buf, buflen, "%s", pin);
1613 }
1614
1615 return -1;
1616}
1617#endif /* CONFIG_AP */
1618
1619
1620#ifdef CONFIG_WPS_ER
1621static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1622 char *cmd)
1623{
1624 char *uuid = cmd, *pin, *pos;
1625 u8 addr_buf[ETH_ALEN], *addr = NULL;
1626 pin = os_strchr(uuid, ' ');
1627 if (pin == NULL)
1628 return -1;
1629 *pin++ = '\0';
1630 pos = os_strchr(pin, ' ');
1631 if (pos) {
1632 *pos++ = '\0';
1633 if (hwaddr_aton(pos, addr_buf) == 0)
1634 addr = addr_buf;
1635 }
1636 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1637}
1638
1639
1640static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1641 char *cmd)
1642{
1643 char *uuid = cmd, *pin;
1644 pin = os_strchr(uuid, ' ');
1645 if (pin == NULL)
1646 return -1;
1647 *pin++ = '\0';
1648 return wpas_wps_er_learn(wpa_s, uuid, pin);
1649}
1650
1651
1652static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1653 struct wpa_supplicant *wpa_s, char *cmd)
1654{
1655 char *uuid = cmd, *id;
1656 id = os_strchr(uuid, ' ');
1657 if (id == NULL)
1658 return -1;
1659 *id++ = '\0';
1660 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1661}
1662
1663
1664static int wpa_supplicant_ctrl_iface_wps_er_config(
1665 struct wpa_supplicant *wpa_s, char *cmd)
1666{
1667 char *pin;
1668 char *new_ssid;
1669 char *new_auth;
1670 char *new_encr;
1671 char *new_key;
1672 struct wps_new_ap_settings ap;
1673
1674 pin = os_strchr(cmd, ' ');
1675 if (pin == NULL)
1676 return -1;
1677 *pin++ = '\0';
1678
1679 new_ssid = os_strchr(pin, ' ');
1680 if (new_ssid == NULL)
1681 return -1;
1682 *new_ssid++ = '\0';
1683
1684 new_auth = os_strchr(new_ssid, ' ');
1685 if (new_auth == NULL)
1686 return -1;
1687 *new_auth++ = '\0';
1688
1689 new_encr = os_strchr(new_auth, ' ');
1690 if (new_encr == NULL)
1691 return -1;
1692 *new_encr++ = '\0';
1693
1694 new_key = os_strchr(new_encr, ' ');
1695 if (new_key == NULL)
1696 return -1;
1697 *new_key++ = '\0';
1698
1699 os_memset(&ap, 0, sizeof(ap));
1700 ap.ssid_hex = new_ssid;
1701 ap.auth = new_auth;
1702 ap.encr = new_encr;
1703 ap.key_hex = new_key;
1704 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1705}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001706
1707
1708#ifdef CONFIG_WPS_NFC
1709static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1710 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1711{
1712 int ndef;
1713 struct wpabuf *buf;
1714 int res;
1715 char *uuid;
1716
1717 uuid = os_strchr(cmd, ' ');
1718 if (uuid == NULL)
1719 return -1;
1720 *uuid++ = '\0';
1721
1722 if (os_strcmp(cmd, "WPS") == 0)
1723 ndef = 0;
1724 else if (os_strcmp(cmd, "NDEF") == 0)
1725 ndef = 1;
1726 else
1727 return -1;
1728
1729 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1730 if (buf == NULL)
1731 return -1;
1732
1733 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1734 wpabuf_len(buf));
1735 reply[res++] = '\n';
1736 reply[res] = '\0';
1737
1738 wpabuf_free(buf);
1739
1740 return res;
1741}
1742#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001743#endif /* CONFIG_WPS_ER */
1744
1745#endif /* CONFIG_WPS */
1746
1747
1748#ifdef CONFIG_IBSS_RSN
1749static int wpa_supplicant_ctrl_iface_ibss_rsn(
1750 struct wpa_supplicant *wpa_s, char *addr)
1751{
1752 u8 peer[ETH_ALEN];
1753
1754 if (hwaddr_aton(addr, peer)) {
1755 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1756 "address '%s'", addr);
1757 return -1;
1758 }
1759
1760 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1761 MAC2STR(peer));
1762
1763 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1764}
1765#endif /* CONFIG_IBSS_RSN */
1766
1767
1768static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1769 char *rsp)
1770{
1771#ifdef IEEE8021X_EAPOL
1772 char *pos, *id_pos;
1773 int id;
1774 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001775
1776 pos = os_strchr(rsp, '-');
1777 if (pos == NULL)
1778 return -1;
1779 *pos++ = '\0';
1780 id_pos = pos;
1781 pos = os_strchr(pos, ':');
1782 if (pos == NULL)
1783 return -1;
1784 *pos++ = '\0';
1785 id = atoi(id_pos);
1786 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1787 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1788 (u8 *) pos, os_strlen(pos));
1789
1790 ssid = wpa_config_get_network(wpa_s->conf, id);
1791 if (ssid == NULL) {
1792 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1793 "to update", id);
1794 return -1;
1795 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001796
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001797 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1798 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001799#else /* IEEE8021X_EAPOL */
1800 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1801 return -1;
1802#endif /* IEEE8021X_EAPOL */
1803}
1804
1805
1806static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1807 const char *params,
1808 char *buf, size_t buflen)
1809{
1810 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001811 int res, verbose, wps, ret;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001812#ifdef CONFIG_HS20
1813 const u8 *hs20;
1814#endif /* CONFIG_HS20 */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001815 const u8 *sess_id;
1816 size_t sess_id_len;
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001817
Dmitry Shmidt56052862013-10-04 10:23:25 -07001818 if (os_strcmp(params, "-DRIVER") == 0)
1819 return wpa_drv_status(wpa_s, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001821 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001822 pos = buf;
1823 end = buf + buflen;
1824 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1825 struct wpa_ssid *ssid = wpa_s->current_ssid;
1826 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1827 MAC2STR(wpa_s->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001828 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001829 return pos - buf;
1830 pos += ret;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001831 ret = os_snprintf(pos, end - pos, "freq=%u\n",
1832 wpa_s->assoc_freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001833 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001834 return pos - buf;
1835 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001836 if (ssid) {
1837 u8 *_ssid = ssid->ssid;
1838 size_t ssid_len = ssid->ssid_len;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001839 u8 ssid_buf[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001840 if (ssid_len == 0) {
1841 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1842 if (_res < 0)
1843 ssid_len = 0;
1844 else
1845 ssid_len = _res;
1846 _ssid = ssid_buf;
1847 }
1848 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1849 wpa_ssid_txt(_ssid, ssid_len),
1850 ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001851 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001852 return pos - buf;
1853 pos += ret;
1854
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001855 if (wps && ssid->passphrase &&
1856 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1857 (ssid->mode == WPAS_MODE_AP ||
1858 ssid->mode == WPAS_MODE_P2P_GO)) {
1859 ret = os_snprintf(pos, end - pos,
1860 "passphrase=%s\n",
1861 ssid->passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001862 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001863 return pos - buf;
1864 pos += ret;
1865 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001866 if (ssid->id_str) {
1867 ret = os_snprintf(pos, end - pos,
1868 "id_str=%s\n",
1869 ssid->id_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001870 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001871 return pos - buf;
1872 pos += ret;
1873 }
1874
1875 switch (ssid->mode) {
1876 case WPAS_MODE_INFRA:
1877 ret = os_snprintf(pos, end - pos,
1878 "mode=station\n");
1879 break;
1880 case WPAS_MODE_IBSS:
1881 ret = os_snprintf(pos, end - pos,
1882 "mode=IBSS\n");
1883 break;
1884 case WPAS_MODE_AP:
1885 ret = os_snprintf(pos, end - pos,
1886 "mode=AP\n");
1887 break;
1888 case WPAS_MODE_P2P_GO:
1889 ret = os_snprintf(pos, end - pos,
1890 "mode=P2P GO\n");
1891 break;
1892 case WPAS_MODE_P2P_GROUP_FORMATION:
1893 ret = os_snprintf(pos, end - pos,
1894 "mode=P2P GO - group "
1895 "formation\n");
1896 break;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001897 case WPAS_MODE_MESH:
1898 ret = os_snprintf(pos, end - pos,
1899 "mode=mesh\n");
1900 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001901 default:
1902 ret = 0;
1903 break;
1904 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001905 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001906 return pos - buf;
1907 pos += ret;
1908 }
1909
1910#ifdef CONFIG_AP
1911 if (wpa_s->ap_iface) {
1912 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1913 end - pos,
1914 verbose);
1915 } else
1916#endif /* CONFIG_AP */
1917 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1918 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001919#ifdef CONFIG_SAE
1920 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001921#ifdef CONFIG_AP
1922 !wpa_s->ap_iface &&
1923#endif /* CONFIG_AP */
1924 wpa_s->sme.sae.state == SAE_ACCEPTED) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001925 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1926 wpa_s->sme.sae.group);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001927 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001928 return pos - buf;
1929 pos += ret;
1930 }
1931#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001932 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1933 wpa_supplicant_state_txt(wpa_s->wpa_state));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001934 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001935 return pos - buf;
1936 pos += ret;
1937
1938 if (wpa_s->l2 &&
1939 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1940 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001941 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001942 return pos - buf;
1943 pos += ret;
1944 }
1945
1946#ifdef CONFIG_P2P
1947 if (wpa_s->global->p2p) {
1948 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1949 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001950 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001951 return pos - buf;
1952 pos += ret;
1953 }
1954#endif /* CONFIG_P2P */
1955
1956 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1957 MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001958 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001959 return pos - buf;
1960 pos += ret;
1961
Dmitry Shmidt04949592012-07-19 12:16:46 -07001962#ifdef CONFIG_HS20
1963 if (wpa_s->current_bss &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001964 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1965 HS20_IE_VENDOR_TYPE)) &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001966 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1967 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001968 int release = 1;
1969 if (hs20[1] >= 5) {
1970 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1971 release = rel_num + 1;
1972 }
1973 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001974 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07001975 return pos - buf;
1976 pos += ret;
1977 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001978
1979 if (wpa_s->current_ssid) {
1980 struct wpa_cred *cred;
1981 char *type;
1982
1983 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07001984 size_t i;
1985
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001986 if (wpa_s->current_ssid->parent_cred != cred)
1987 continue;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001988
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001989 if (cred->provisioning_sp) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07001990 ret = os_snprintf(pos, end - pos,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001991 "provisioning_sp=%s\n",
1992 cred->provisioning_sp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001993 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt051af732013-10-22 13:52:46 -07001994 return pos - buf;
1995 pos += ret;
1996 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001997
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001998 if (!cred->domain)
1999 goto no_domain;
2000
2001 i = 0;
2002 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2003 struct wpabuf *names =
2004 wpa_s->current_bss->anqp->domain_name;
2005 for (i = 0; names && i < cred->num_domain; i++)
2006 {
2007 if (domain_name_list_contains(
2008 names, cred->domain[i], 1))
2009 break;
2010 }
2011 if (i == cred->num_domain)
2012 i = 0; /* show first entry by default */
2013 }
2014 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2015 cred->domain[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002016 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002017 return pos - buf;
2018 pos += ret;
2019
2020 no_domain:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002021 if (wpa_s->current_bss == NULL ||
2022 wpa_s->current_bss->anqp == NULL)
2023 res = -1;
2024 else
2025 res = interworking_home_sp_cred(
2026 wpa_s, cred,
2027 wpa_s->current_bss->anqp->domain_name);
2028 if (res > 0)
2029 type = "home";
2030 else if (res == 0)
2031 type = "roaming";
2032 else
2033 type = "unknown";
2034
2035 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002036 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002037 return pos - buf;
2038 pos += ret;
2039
2040 break;
2041 }
2042 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002043#endif /* CONFIG_HS20 */
2044
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002045 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2046 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2047 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2048 verbose);
2049 if (res >= 0)
2050 pos += res;
2051 }
2052
Dmitry Shmidt29333592017-01-09 12:27:11 -08002053#ifdef CONFIG_MACSEC
2054 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2055 if (res > 0)
2056 pos += res;
2057#endif /* CONFIG_MACSEC */
2058
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002059 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2060 if (sess_id) {
2061 char *start = pos;
2062
2063 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2064 if (os_snprintf_error(end - pos, ret))
2065 return start - buf;
2066 pos += ret;
2067 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2068 if (ret <= 0)
2069 return start - buf;
2070 pos += ret;
2071 ret = os_snprintf(pos, end - pos, "\n");
2072 if (os_snprintf_error(end - pos, ret))
2073 return start - buf;
2074 pos += ret;
2075 }
2076
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002077 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2078 if (res >= 0)
2079 pos += res;
2080
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002081#ifdef CONFIG_WPS
2082 {
2083 char uuid_str[100];
2084 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2085 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002086 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002087 return pos - buf;
2088 pos += ret;
2089 }
2090#endif /* CONFIG_WPS */
2091
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002092#ifdef ANDROID
vandwalleffc70182014-09-11 11:40:14 -07002093 /*
2094 * Allow using the STATUS command with default behavior, say for debug,
2095 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2096 * events with STATUS-NO_EVENTS.
2097 */
2098 if (os_strcmp(params, "-NO_EVENTS")) {
2099 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2100 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2101 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2102 wpa_s->wpa_state,
2103 MAC2STR(wpa_s->bssid),
2104 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2105 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2106 wpa_s->current_ssid->ssid_len) : "");
2107 if (wpa_s->wpa_state == WPA_COMPLETED) {
2108 struct wpa_ssid *ssid = wpa_s->current_ssid;
2109 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2110 "- connection to " MACSTR
2111 " completed %s [id=%d id_str=%s]",
2112 MAC2STR(wpa_s->bssid), "(auth)",
2113 ssid ? ssid->id : -1,
2114 ssid && ssid->id_str ? ssid->id_str : "");
2115 }
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08002116 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002117#endif /* ANDROID */
2118
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002119 return pos - buf;
2120}
2121
2122
2123static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2124 char *cmd)
2125{
2126 char *pos;
2127 int id;
2128 struct wpa_ssid *ssid;
2129 u8 bssid[ETH_ALEN];
2130
2131 /* cmd: "<network id> <BSSID>" */
2132 pos = os_strchr(cmd, ' ');
2133 if (pos == NULL)
2134 return -1;
2135 *pos++ = '\0';
2136 id = atoi(cmd);
2137 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2138 if (hwaddr_aton(pos, bssid)) {
2139 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2140 return -1;
2141 }
2142
2143 ssid = wpa_config_get_network(wpa_s->conf, id);
2144 if (ssid == NULL) {
2145 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2146 "to update", id);
2147 return -1;
2148 }
2149
2150 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2151 ssid->bssid_set = !is_zero_ether_addr(bssid);
2152
2153 return 0;
2154}
2155
2156
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002157static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002158 char *cmd, char *buf,
2159 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002160{
2161 u8 bssid[ETH_ALEN];
2162 struct wpa_blacklist *e;
2163 char *pos, *end;
2164 int ret;
2165
2166 /* cmd: "BLACKLIST [<BSSID>]" */
2167 if (*cmd == '\0') {
2168 pos = buf;
2169 end = buf + buflen;
2170 e = wpa_s->blacklist;
2171 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002172 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2173 MAC2STR(e->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002174 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002175 return pos - buf;
2176 pos += ret;
2177 e = e->next;
2178 }
2179 return pos - buf;
2180 }
2181
2182 cmd++;
2183 if (os_strncmp(cmd, "clear", 5) == 0) {
2184 wpa_blacklist_clear(wpa_s);
2185 os_memcpy(buf, "OK\n", 3);
2186 return 3;
2187 }
2188
2189 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
2190 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002191 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002192 return -1;
2193 }
2194
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002195 /*
2196 * Add the BSSID twice, so its count will be 2, causing it to be
2197 * skipped when processing scan results.
2198 */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002199 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002200 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002201 return -1;
2202 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002203 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002204 return -1;
2205 os_memcpy(buf, "OK\n", 3);
2206 return 3;
2207}
2208
2209
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002210static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2211 char *cmd, char *buf,
2212 size_t buflen)
2213{
2214 char *pos, *end, *stamp;
2215 int ret;
2216
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002217 /* cmd: "LOG_LEVEL [<level>]" */
2218 if (*cmd == '\0') {
2219 pos = buf;
2220 end = buf + buflen;
2221 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2222 "Timestamp: %d\n",
2223 debug_level_str(wpa_debug_level),
2224 wpa_debug_timestamp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002225 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002226 ret = 0;
2227
2228 return ret;
2229 }
2230
2231 while (*cmd == ' ')
2232 cmd++;
2233
2234 stamp = os_strchr(cmd, ' ');
2235 if (stamp) {
2236 *stamp++ = '\0';
2237 while (*stamp == ' ') {
2238 stamp++;
2239 }
2240 }
2241
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002242 if (os_strlen(cmd)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002243 int level = str_to_debug_level(cmd);
2244 if (level < 0)
2245 return -1;
2246 wpa_debug_level = level;
2247 }
2248
2249 if (stamp && os_strlen(stamp))
2250 wpa_debug_timestamp = atoi(stamp);
2251
2252 os_memcpy(buf, "OK\n", 3);
2253 return 3;
2254}
2255
2256
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002257static int wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002258 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002259{
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002260 char *pos, *end, *prev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002261 struct wpa_ssid *ssid;
2262 int ret;
2263
2264 pos = buf;
2265 end = buf + buflen;
2266 ret = os_snprintf(pos, end - pos,
2267 "network id / ssid / bssid / flags\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002268 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002269 return pos - buf;
2270 pos += ret;
2271
2272 ssid = wpa_s->conf->ssid;
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002273
2274 /* skip over ssids until we find next one */
2275 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2276 int last_id = atoi(cmd + 8);
2277 if (last_id != -1) {
2278 while (ssid != NULL && ssid->id <= last_id) {
2279 ssid = ssid->next;
2280 }
2281 }
2282 }
2283
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002284 while (ssid) {
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002285 prev = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002286 ret = os_snprintf(pos, end - pos, "%d\t%s",
2287 ssid->id,
2288 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002289 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002290 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002291 pos += ret;
2292 if (ssid->bssid_set) {
2293 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2294 MAC2STR(ssid->bssid));
2295 } else {
2296 ret = os_snprintf(pos, end - pos, "\tany");
2297 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002298 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002299 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002300 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002301 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002302 ssid == wpa_s->current_ssid ?
2303 "[CURRENT]" : "",
2304 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002305 ssid->disabled_until.sec ?
2306 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002307 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2308 "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002309 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002310 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002311 pos += ret;
2312 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002313 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002314 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002315 pos += ret;
2316
2317 ssid = ssid->next;
2318 }
2319
2320 return pos - buf;
2321}
2322
2323
2324static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2325{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002326 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002327 ret = os_snprintf(pos, end - pos, "-");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002328 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002329 return pos;
2330 pos += ret;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002331 ret = wpa_write_ciphers(pos, end, cipher, "+");
2332 if (ret < 0)
2333 return pos;
2334 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002335 return pos;
2336}
2337
2338
2339static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2340 const u8 *ie, size_t ie_len)
2341{
2342 struct wpa_ie_data data;
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002343 char *start;
2344 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002345
2346 ret = os_snprintf(pos, end - pos, "[%s-", proto);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002347 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002348 return pos;
2349 pos += ret;
2350
2351 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2352 ret = os_snprintf(pos, end - pos, "?]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002353 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002354 return pos;
2355 pos += ret;
2356 return pos;
2357 }
2358
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002359 start = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002360 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002361 ret = os_snprintf(pos, end - pos, "%sEAP",
2362 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002363 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002364 return pos;
2365 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002366 }
2367 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002368 ret = os_snprintf(pos, end - pos, "%sPSK",
2369 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002370 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002371 return pos;
2372 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002373 }
2374 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002375 ret = os_snprintf(pos, end - pos, "%sNone",
2376 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002377 if (os_snprintf_error(end - pos, ret))
2378 return pos;
2379 pos += ret;
2380 }
2381 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2382 ret = os_snprintf(pos, end - pos, "%sSAE",
2383 pos == start ? "" : "+");
2384 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002385 return pos;
2386 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002387 }
2388#ifdef CONFIG_IEEE80211R
2389 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2390 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002391 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002392 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002393 return pos;
2394 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002395 }
2396 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2397 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002398 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002399 if (os_snprintf_error(end - pos, ret))
2400 return pos;
2401 pos += ret;
2402 }
2403 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2404 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2405 pos == start ? "" : "+");
2406 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002407 return pos;
2408 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002409 }
2410#endif /* CONFIG_IEEE80211R */
2411#ifdef CONFIG_IEEE80211W
2412 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2413 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002414 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002415 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002416 return pos;
2417 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002418 }
2419 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2420 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002421 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002422 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002423 return pos;
2424 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002425 }
2426#endif /* CONFIG_IEEE80211W */
2427
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002428#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002429 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2430 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2431 pos == start ? "" : "+");
2432 if (os_snprintf_error(end - pos, ret))
2433 return pos;
2434 pos += ret;
2435 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002436#endif /* CONFIG_SUITEB */
2437
2438#ifdef CONFIG_SUITEB192
2439 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2440 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2441 pos == start ? "" : "+");
2442 if (os_snprintf_error(end - pos, ret))
2443 return pos;
2444 pos += ret;
2445 }
2446#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002447
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002448#ifdef CONFIG_FILS
2449 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2450 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2451 pos == start ? "" : "+");
2452 if (os_snprintf_error(end - pos, ret))
2453 return pos;
2454 pos += ret;
2455 }
2456 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2457 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2458 pos == start ? "" : "+");
2459 if (os_snprintf_error(end - pos, ret))
2460 return pos;
2461 pos += ret;
2462 }
2463#ifdef CONFIG_IEEE80211R
2464 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2465 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2466 pos == start ? "" : "+");
2467 if (os_snprintf_error(end - pos, ret))
2468 return pos;
2469 pos += ret;
2470 }
2471 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2472 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2473 pos == start ? "" : "+");
2474 if (os_snprintf_error(end - pos, ret))
2475 return pos;
2476 pos += ret;
2477 }
2478#endif /* CONFIG_IEEE80211R */
2479#endif /* CONFIG_FILS */
2480
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002481 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2482 ret = os_snprintf(pos, end - pos, "%sOSEN",
2483 pos == start ? "" : "+");
2484 if (os_snprintf_error(end - pos, ret))
2485 return pos;
2486 pos += ret;
2487 }
2488
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002489 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2490
2491 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2492 ret = os_snprintf(pos, end - pos, "-preauth");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002493 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002494 return pos;
2495 pos += ret;
2496 }
2497
2498 ret = os_snprintf(pos, end - pos, "]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002499 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002500 return pos;
2501 pos += ret;
2502
2503 return pos;
2504}
2505
2506
2507#ifdef CONFIG_WPS
2508static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2509 char *pos, char *end,
2510 struct wpabuf *wps_ie)
2511{
2512 int ret;
2513 const char *txt;
2514
2515 if (wps_ie == NULL)
2516 return pos;
2517 if (wps_is_selected_pbc_registrar(wps_ie))
2518 txt = "[WPS-PBC]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002519 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2520 txt = "[WPS-AUTH]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002521 else if (wps_is_selected_pin_registrar(wps_ie))
2522 txt = "[WPS-PIN]";
2523 else
2524 txt = "[WPS]";
2525
2526 ret = os_snprintf(pos, end - pos, "%s", txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002527 if (!os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002528 pos += ret;
2529 wpabuf_free(wps_ie);
2530 return pos;
2531}
2532#endif /* CONFIG_WPS */
2533
2534
2535static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2536 char *pos, char *end,
2537 const struct wpa_bss *bss)
2538{
2539#ifdef CONFIG_WPS
2540 struct wpabuf *wps_ie;
2541 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2542 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2543#else /* CONFIG_WPS */
2544 return pos;
2545#endif /* CONFIG_WPS */
2546}
2547
2548
2549/* Format one result on one text line into a buffer. */
2550static int wpa_supplicant_ctrl_iface_scan_result(
2551 struct wpa_supplicant *wpa_s,
2552 const struct wpa_bss *bss, char *buf, size_t buflen)
2553{
2554 char *pos, *end;
2555 int ret;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002556 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002557
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002558 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002559 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07002560 if (!p2p)
2561 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002562 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2563 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2564 0)
2565 return 0; /* Do not show P2P listen discovery results here */
2566
2567 pos = buf;
2568 end = buf + buflen;
2569
2570 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2571 MAC2STR(bss->bssid), bss->freq, bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002572 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002573 return -1;
2574 pos += ret;
2575 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2576 if (ie)
2577 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2578 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002579 if (ie2) {
2580 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2581 ie2, 2 + ie2[1]);
2582 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002583 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
2584 if (osen_ie)
2585 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
2586 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002587 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002588 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002589 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002590 if (os_snprintf_error(end - pos, ret))
2591 return -1;
2592 pos += ret;
2593 }
2594 if (mesh) {
2595 ret = os_snprintf(pos, end - pos, "[MESH]");
2596 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002597 return -1;
2598 pos += ret;
2599 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002600 if (bss_is_dmg(bss)) {
2601 const char *s;
2602 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002603 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002604 return -1;
2605 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002606 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2607 case IEEE80211_CAP_DMG_IBSS:
2608 s = "[IBSS]";
2609 break;
2610 case IEEE80211_CAP_DMG_AP:
2611 s = "[ESS]";
2612 break;
2613 case IEEE80211_CAP_DMG_PBSS:
2614 s = "[PBSS]";
2615 break;
2616 default:
2617 s = "";
2618 break;
2619 }
2620 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002621 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002622 return -1;
2623 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002624 } else {
2625 if (bss->caps & IEEE80211_CAP_IBSS) {
2626 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002627 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002628 return -1;
2629 pos += ret;
2630 }
2631 if (bss->caps & IEEE80211_CAP_ESS) {
2632 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002633 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002634 return -1;
2635 pos += ret;
2636 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002637 }
2638 if (p2p) {
2639 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002640 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002641 return -1;
2642 pos += ret;
2643 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002644#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002645 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002646 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002647 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002648 return -1;
2649 pos += ret;
2650 }
2651#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002652#ifdef CONFIG_FILS
2653 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
2654 ret = os_snprintf(pos, end - pos, "[FILS]");
2655 if (os_snprintf_error(end - pos, ret))
2656 return -1;
2657 pos += ret;
2658 }
2659#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002660#ifdef CONFIG_FST
2661 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
2662 ret = os_snprintf(pos, end - pos, "[FST]");
2663 if (os_snprintf_error(end - pos, ret))
2664 return -1;
2665 pos += ret;
2666 }
2667#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002668
2669 ret = os_snprintf(pos, end - pos, "\t%s",
2670 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002671 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002672 return -1;
2673 pos += ret;
2674
2675 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002676 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002677 return -1;
2678 pos += ret;
2679
2680 return pos - buf;
2681}
2682
2683
2684static int wpa_supplicant_ctrl_iface_scan_results(
2685 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2686{
2687 char *pos, *end;
2688 struct wpa_bss *bss;
2689 int ret;
2690
2691 pos = buf;
2692 end = buf + buflen;
2693 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2694 "flags / ssid\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002695 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002696 return pos - buf;
2697 pos += ret;
2698
2699 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2700 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2701 end - pos);
2702 if (ret < 0 || ret >= end - pos)
2703 return pos - buf;
2704 pos += ret;
2705 }
2706
2707 return pos - buf;
2708}
2709
2710
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002711#ifdef CONFIG_MESH
2712
2713static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2714 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2715{
2716 char *pos, ifname[IFNAMSIZ + 1];
2717
2718 ifname[0] = '\0';
2719
2720 pos = os_strstr(cmd, "ifname=");
2721 if (pos) {
2722 pos += 7;
2723 os_strlcpy(ifname, pos, sizeof(ifname));
2724 }
2725
2726 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
2727 return -1;
2728
2729 os_strlcpy(reply, ifname, max_len);
2730 return os_strlen(ifname);
2731}
2732
2733
2734static int wpa_supplicant_ctrl_iface_mesh_group_add(
2735 struct wpa_supplicant *wpa_s, char *cmd)
2736{
2737 int id;
2738 struct wpa_ssid *ssid;
2739
2740 id = atoi(cmd);
2741 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
2742
2743 ssid = wpa_config_get_network(wpa_s->conf, id);
2744 if (ssid == NULL) {
2745 wpa_printf(MSG_DEBUG,
2746 "CTRL_IFACE: Could not find network id=%d", id);
2747 return -1;
2748 }
2749 if (ssid->mode != WPAS_MODE_MESH) {
2750 wpa_printf(MSG_DEBUG,
2751 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2752 return -1;
2753 }
2754 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
2755 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
2756 wpa_printf(MSG_ERROR,
2757 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2758 return -1;
2759 }
2760
2761 /*
2762 * TODO: If necessary write our own group_add function,
2763 * for now we can reuse select_network
2764 */
2765 wpa_supplicant_select_network(wpa_s, ssid);
2766
2767 return 0;
2768}
2769
2770
2771static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2772 struct wpa_supplicant *wpa_s, char *cmd)
2773{
2774 struct wpa_supplicant *orig;
2775 struct wpa_global *global;
2776 int found = 0;
2777
2778 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
2779
2780 global = wpa_s->global;
2781 orig = wpa_s;
2782
2783 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2784 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
2785 found = 1;
2786 break;
2787 }
2788 }
2789 if (!found) {
2790 wpa_printf(MSG_ERROR,
2791 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
2792 cmd);
2793 return -1;
2794 }
2795 if (wpa_s->mesh_if_created && wpa_s == orig) {
2796 wpa_printf(MSG_ERROR,
2797 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
2798 return -1;
2799 }
2800
2801 wpa_s->reassociate = 0;
2802 wpa_s->disconnected = 1;
2803 wpa_supplicant_cancel_sched_scan(wpa_s);
2804 wpa_supplicant_cancel_scan(wpa_s);
2805
2806 /*
2807 * TODO: If necessary write our own group_remove function,
2808 * for now we can reuse deauthenticate
2809 */
2810 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2811
2812 if (wpa_s->mesh_if_created)
2813 wpa_supplicant_remove_iface(global, wpa_s, 0);
2814
2815 return 0;
2816}
2817
Dmitry Shmidte4663042016-04-04 10:07:49 -07002818
2819static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
2820 struct wpa_supplicant *wpa_s, char *cmd)
2821{
2822 u8 addr[ETH_ALEN];
2823
2824 if (hwaddr_aton(cmd, addr) < 0)
2825 return -1;
2826
2827 return wpas_mesh_peer_remove(wpa_s, addr);
2828}
2829
2830
2831static int wpa_supplicant_ctrl_iface_mesh_peer_add(
2832 struct wpa_supplicant *wpa_s, char *cmd)
2833{
2834 u8 addr[ETH_ALEN];
2835 int duration;
2836 char *pos;
2837
2838 pos = os_strstr(cmd, " duration=");
2839 if (pos) {
2840 *pos = '\0';
2841 duration = atoi(pos + 10);
2842 } else {
2843 duration = -1;
2844 }
2845
2846 if (hwaddr_aton(cmd, addr))
2847 return -1;
2848
2849 return wpas_mesh_peer_add(wpa_s, addr, duration);
2850}
2851
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002852#endif /* CONFIG_MESH */
2853
2854
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002855static int wpa_supplicant_ctrl_iface_select_network(
2856 struct wpa_supplicant *wpa_s, char *cmd)
2857{
2858 int id;
2859 struct wpa_ssid *ssid;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07002860 char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002861
2862 /* cmd: "<network id>" or "any" */
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07002863 if (os_strncmp(cmd, "any", 3) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002864 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2865 ssid = NULL;
2866 } else {
2867 id = atoi(cmd);
2868 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2869
2870 ssid = wpa_config_get_network(wpa_s->conf, id);
2871 if (ssid == NULL) {
2872 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2873 "network id=%d", id);
2874 return -1;
2875 }
2876 if (ssid->disabled == 2) {
2877 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2878 "SELECT_NETWORK with persistent P2P group");
2879 return -1;
2880 }
2881 }
2882
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07002883 pos = os_strstr(cmd, " freq=");
2884 if (pos) {
2885 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
2886 if (freqs) {
2887 wpa_s->scan_req = MANUAL_SCAN_REQ;
2888 os_free(wpa_s->manual_scan_freqs);
2889 wpa_s->manual_scan_freqs = freqs;
2890 }
2891 }
2892
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002893 wpa_s->scan_min_time.sec = 0;
2894 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002895 wpa_supplicant_select_network(wpa_s, ssid);
2896
2897 return 0;
2898}
2899
2900
2901static int wpa_supplicant_ctrl_iface_enable_network(
2902 struct wpa_supplicant *wpa_s, char *cmd)
2903{
2904 int id;
2905 struct wpa_ssid *ssid;
2906
2907 /* cmd: "<network id>" or "all" */
2908 if (os_strcmp(cmd, "all") == 0) {
2909 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2910 ssid = NULL;
2911 } else {
2912 id = atoi(cmd);
2913 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2914
2915 ssid = wpa_config_get_network(wpa_s->conf, id);
2916 if (ssid == NULL) {
2917 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2918 "network id=%d", id);
2919 return -1;
2920 }
2921 if (ssid->disabled == 2) {
2922 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2923 "ENABLE_NETWORK with persistent P2P group");
2924 return -1;
2925 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002926
2927 if (os_strstr(cmd, " no-connect")) {
2928 ssid->disabled = 0;
2929 return 0;
2930 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002931 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002932 wpa_s->scan_min_time.sec = 0;
2933 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002934 wpa_supplicant_enable_network(wpa_s, ssid);
2935
2936 return 0;
2937}
2938
2939
2940static int wpa_supplicant_ctrl_iface_disable_network(
2941 struct wpa_supplicant *wpa_s, char *cmd)
2942{
2943 int id;
2944 struct wpa_ssid *ssid;
2945
2946 /* cmd: "<network id>" or "all" */
2947 if (os_strcmp(cmd, "all") == 0) {
2948 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2949 ssid = NULL;
2950 } else {
2951 id = atoi(cmd);
2952 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2953
2954 ssid = wpa_config_get_network(wpa_s->conf, id);
2955 if (ssid == NULL) {
2956 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2957 "network id=%d", id);
2958 return -1;
2959 }
2960 if (ssid->disabled == 2) {
2961 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2962 "DISABLE_NETWORK with persistent P2P "
2963 "group");
2964 return -1;
2965 }
2966 }
2967 wpa_supplicant_disable_network(wpa_s, ssid);
2968
2969 return 0;
2970}
2971
2972
2973static int wpa_supplicant_ctrl_iface_add_network(
2974 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2975{
2976 struct wpa_ssid *ssid;
2977 int ret;
2978
2979 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2980
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07002981 ssid = wpa_supplicant_add_network(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002982 if (ssid == NULL)
2983 return -1;
2984
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002985 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002986 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002987 return -1;
2988 return ret;
2989}
2990
2991
2992static int wpa_supplicant_ctrl_iface_remove_network(
2993 struct wpa_supplicant *wpa_s, char *cmd)
2994{
2995 int id;
2996 struct wpa_ssid *ssid;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07002997 int result;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002998
2999 /* cmd: "<network id>" or "all" */
3000 if (os_strcmp(cmd, "all") == 0) {
3001 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003002 if (wpa_s->sched_scanning)
3003 wpa_supplicant_cancel_sched_scan(wpa_s);
3004
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003005 eapol_sm_invalidate_cached_session(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003006 if (wpa_s->current_ssid) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003007#ifdef CONFIG_SME
3008 wpa_s->sme.prev_bssid_set = 0;
3009#endif /* CONFIG_SME */
Jouni Malinen75ecf522011-06-27 15:19:46 -07003010 wpa_sm_set_config(wpa_s->wpa, NULL);
3011 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07003012 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3013 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003014 wpa_supplicant_deauthenticate(
3015 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003016 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003017 ssid = wpa_s->conf->ssid;
3018 while (ssid) {
3019 struct wpa_ssid *remove_ssid = ssid;
3020 id = ssid->id;
3021 ssid = ssid->next;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003022 if (wpa_s->last_ssid == remove_ssid)
3023 wpa_s->last_ssid = NULL;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003024 wpas_notify_network_removed(wpa_s, remove_ssid);
3025 wpa_config_remove_network(wpa_s->conf, id);
3026 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003027 return 0;
3028 }
3029
3030 id = atoi(cmd);
3031 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3032
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003033 result = wpa_supplicant_remove_network(wpa_s, id);
3034 if (result == -1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003035 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3036 "id=%d", id);
3037 return -1;
3038 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003039 if (result == -2) {
Deepthi Gowria831d782012-09-03 11:55:38 +03003040 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3041 "network id=%d", id);
3042 return -1;
3043 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003044 return 0;
3045}
3046
3047
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003048static int wpa_supplicant_ctrl_iface_update_network(
3049 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3050 char *name, char *value)
3051{
Dmitry Shmidte4663042016-04-04 10:07:49 -07003052 int ret;
3053
3054 ret = wpa_config_set(ssid, name, value, 0);
3055 if (ret < 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003056 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3057 "variable '%s'", name);
3058 return -1;
3059 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07003060 if (ret == 1)
3061 return 0; /* No change to the previously configured value */
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003062
3063 if (os_strcmp(name, "bssid") != 0 &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003064 os_strcmp(name, "priority") != 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003065 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3066
Dmitry Shmidte4663042016-04-04 10:07:49 -07003067 if (wpa_s->current_ssid == ssid ||
3068 wpa_s->current_ssid == NULL) {
3069 /*
3070 * Invalidate the EAP session cache if anything in the
3071 * current or previously used configuration changes.
3072 */
3073 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3074 }
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003075 }
3076
3077 if ((os_strcmp(name, "psk") == 0 &&
3078 value[0] == '"' && ssid->ssid_len) ||
3079 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3080 wpa_config_update_psk(ssid);
3081 else if (os_strcmp(name, "priority") == 0)
3082 wpa_config_update_prio_list(wpa_s->conf);
3083
3084 return 0;
3085}
3086
3087
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003088static int wpa_supplicant_ctrl_iface_set_network(
3089 struct wpa_supplicant *wpa_s, char *cmd)
3090{
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003091 int id, ret, prev_bssid_set, prev_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003092 struct wpa_ssid *ssid;
3093 char *name, *value;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003094 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003095
3096 /* cmd: "<network id> <variable name> <value>" */
3097 name = os_strchr(cmd, ' ');
3098 if (name == NULL)
3099 return -1;
3100 *name++ = '\0';
3101
3102 value = os_strchr(name, ' ');
3103 if (value == NULL)
3104 return -1;
3105 *value++ = '\0';
3106
3107 id = atoi(cmd);
3108 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3109 id, name);
3110 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3111 (u8 *) value, os_strlen(value));
3112
3113 ssid = wpa_config_get_network(wpa_s->conf, id);
3114 if (ssid == NULL) {
3115 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3116 "id=%d", id);
3117 return -1;
3118 }
3119
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003120 prev_bssid_set = ssid->bssid_set;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003121 prev_disabled = ssid->disabled;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003122 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3123 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3124 value);
3125 if (ret == 0 &&
3126 (ssid->bssid_set != prev_bssid_set ||
3127 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3128 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003129
3130 if (prev_disabled != ssid->disabled &&
3131 (prev_disabled == 2 || ssid->disabled == 2))
3132 wpas_notify_network_type_changed(wpa_s, ssid);
3133
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003134 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003135}
3136
3137
3138static int wpa_supplicant_ctrl_iface_get_network(
3139 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3140{
3141 int id;
3142 size_t res;
3143 struct wpa_ssid *ssid;
3144 char *name, *value;
3145
3146 /* cmd: "<network id> <variable name>" */
3147 name = os_strchr(cmd, ' ');
3148 if (name == NULL || buflen == 0)
3149 return -1;
3150 *name++ = '\0';
3151
3152 id = atoi(cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003153 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003154 id, name);
3155
3156 ssid = wpa_config_get_network(wpa_s->conf, id);
3157 if (ssid == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003158 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003159 "id=%d", id);
3160 return -1;
3161 }
3162
3163 value = wpa_config_get_no_key(ssid, name);
3164 if (value == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003165 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003166 "variable '%s'", name);
3167 return -1;
3168 }
3169
3170 res = os_strlcpy(buf, value, buflen);
3171 if (res >= buflen) {
3172 os_free(value);
3173 return -1;
3174 }
3175
3176 os_free(value);
3177
3178 return res;
3179}
3180
3181
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003182static int wpa_supplicant_ctrl_iface_dup_network(
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003183 struct wpa_supplicant *wpa_s, char *cmd,
3184 struct wpa_supplicant *dst_wpa_s)
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003185{
3186 struct wpa_ssid *ssid_s, *ssid_d;
3187 char *name, *id, *value;
3188 int id_s, id_d, ret;
3189
3190 /* cmd: "<src network id> <dst network id> <variable name>" */
3191 id = os_strchr(cmd, ' ');
3192 if (id == NULL)
3193 return -1;
3194 *id++ = '\0';
3195
3196 name = os_strchr(id, ' ');
3197 if (name == NULL)
3198 return -1;
3199 *name++ = '\0';
3200
3201 id_s = atoi(cmd);
3202 id_d = atoi(id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003203
3204 wpa_printf(MSG_DEBUG,
3205 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3206 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003207
3208 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3209 if (ssid_s == NULL) {
3210 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3211 "network id=%d", id_s);
3212 return -1;
3213 }
3214
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003215 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003216 if (ssid_d == NULL) {
3217 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003218 "network id=%d", id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003219 return -1;
3220 }
3221
3222 value = wpa_config_get(ssid_s, name);
3223 if (value == NULL) {
3224 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3225 "variable '%s'", name);
3226 return -1;
3227 }
3228
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003229 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003230 value);
3231
3232 os_free(value);
3233
3234 return ret;
3235}
3236
3237
Dmitry Shmidt04949592012-07-19 12:16:46 -07003238static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3239 char *buf, size_t buflen)
3240{
3241 char *pos, *end;
3242 struct wpa_cred *cred;
3243 int ret;
3244
3245 pos = buf;
3246 end = buf + buflen;
3247 ret = os_snprintf(pos, end - pos,
3248 "cred id / realm / username / domain / imsi\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003249 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003250 return pos - buf;
3251 pos += ret;
3252
3253 cred = wpa_s->conf->cred;
3254 while (cred) {
3255 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3256 cred->id, cred->realm ? cred->realm : "",
3257 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07003258 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003259 cred->imsi ? cred->imsi : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003260 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003261 return pos - buf;
3262 pos += ret;
3263
3264 cred = cred->next;
3265 }
3266
3267 return pos - buf;
3268}
3269
3270
3271static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3272 char *buf, size_t buflen)
3273{
3274 struct wpa_cred *cred;
3275 int ret;
3276
3277 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3278
3279 cred = wpa_config_add_cred(wpa_s->conf);
3280 if (cred == NULL)
3281 return -1;
3282
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003283 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3284
Dmitry Shmidt04949592012-07-19 12:16:46 -07003285 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003286 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003287 return -1;
3288 return ret;
3289}
3290
3291
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003292static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
3293 struct wpa_cred *cred)
3294{
3295 struct wpa_ssid *ssid;
3296 char str[20];
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003297 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003298
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003299 if (cred == NULL) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003300 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3301 return -1;
3302 }
3303
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003304 id = cred->id;
3305 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
3306 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3307 return -1;
3308 }
3309
3310 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
3311
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003312 /* Remove any network entry created based on the removed credential */
3313 ssid = wpa_s->conf->ssid;
3314 while (ssid) {
3315 if (ssid->parent_cred == cred) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003316 int res;
3317
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003318 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
3319 "used the removed credential", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003320 res = os_snprintf(str, sizeof(str), "%d", ssid->id);
3321 if (os_snprintf_error(sizeof(str), res))
3322 str[sizeof(str) - 1] = '\0';
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003323 ssid = ssid->next;
3324 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
3325 } else
3326 ssid = ssid->next;
3327 }
3328
3329 return 0;
3330}
3331
3332
Dmitry Shmidt04949592012-07-19 12:16:46 -07003333static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3334 char *cmd)
3335{
3336 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003337 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003338
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003339 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3340 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003341 if (os_strcmp(cmd, "all") == 0) {
3342 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3343 cred = wpa_s->conf->cred;
3344 while (cred) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003345 prev = cred;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003346 cred = cred->next;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003347 wpas_ctrl_remove_cred(wpa_s, prev);
3348 }
3349 return 0;
3350 }
3351
3352 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3353 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3354 cmd + 8);
3355 cred = wpa_s->conf->cred;
3356 while (cred) {
3357 prev = cred;
3358 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003359 if (prev->domain) {
3360 size_t i;
3361 for (i = 0; i < prev->num_domain; i++) {
3362 if (os_strcmp(prev->domain[i], cmd + 8)
3363 != 0)
3364 continue;
3365 wpas_ctrl_remove_cred(wpa_s, prev);
3366 break;
3367 }
3368 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003369 }
3370 return 0;
3371 }
3372
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003373 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3374 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3375 cmd + 16);
3376 cred = wpa_s->conf->cred;
3377 while (cred) {
3378 prev = cred;
3379 cred = cred->next;
3380 if (prev->provisioning_sp &&
3381 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3382 wpas_ctrl_remove_cred(wpa_s, prev);
3383 }
3384 return 0;
3385 }
3386
Dmitry Shmidt04949592012-07-19 12:16:46 -07003387 id = atoi(cmd);
3388 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3389
3390 cred = wpa_config_get_cred(wpa_s->conf, id);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003391 return wpas_ctrl_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003392}
3393
3394
3395static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3396 char *cmd)
3397{
3398 int id;
3399 struct wpa_cred *cred;
3400 char *name, *value;
3401
3402 /* cmd: "<cred id> <variable name> <value>" */
3403 name = os_strchr(cmd, ' ');
3404 if (name == NULL)
3405 return -1;
3406 *name++ = '\0';
3407
3408 value = os_strchr(name, ' ');
3409 if (value == NULL)
3410 return -1;
3411 *value++ = '\0';
3412
3413 id = atoi(cmd);
3414 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3415 id, name);
3416 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3417 (u8 *) value, os_strlen(value));
3418
3419 cred = wpa_config_get_cred(wpa_s->conf, id);
3420 if (cred == NULL) {
3421 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3422 id);
3423 return -1;
3424 }
3425
3426 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3427 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3428 "variable '%s'", name);
3429 return -1;
3430 }
3431
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003432 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3433
Dmitry Shmidt04949592012-07-19 12:16:46 -07003434 return 0;
3435}
3436
3437
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003438static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3439 char *cmd, char *buf,
3440 size_t buflen)
3441{
3442 int id;
3443 size_t res;
3444 struct wpa_cred *cred;
3445 char *name, *value;
3446
3447 /* cmd: "<cred id> <variable name>" */
3448 name = os_strchr(cmd, ' ');
3449 if (name == NULL)
3450 return -1;
3451 *name++ = '\0';
3452
3453 id = atoi(cmd);
3454 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3455 id, name);
3456
3457 cred = wpa_config_get_cred(wpa_s->conf, id);
3458 if (cred == NULL) {
3459 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3460 id);
3461 return -1;
3462 }
3463
3464 value = wpa_config_get_cred_no_key(cred, name);
3465 if (value == NULL) {
3466 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3467 name);
3468 return -1;
3469 }
3470
3471 res = os_strlcpy(buf, value, buflen);
3472 if (res >= buflen) {
3473 os_free(value);
3474 return -1;
3475 }
3476
3477 os_free(value);
3478
3479 return res;
3480}
3481
3482
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003483#ifndef CONFIG_NO_CONFIG_WRITE
3484static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3485{
3486 int ret;
3487
3488 if (!wpa_s->conf->update_config) {
3489 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3490 "to update configuration (update_config=0)");
3491 return -1;
3492 }
3493
3494 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3495 if (ret) {
3496 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3497 "update configuration");
3498 } else {
3499 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3500 " updated");
3501 }
3502
3503 return ret;
3504}
3505#endif /* CONFIG_NO_CONFIG_WRITE */
3506
3507
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003508struct cipher_info {
3509 unsigned int capa;
3510 const char *name;
3511 int group_only;
3512};
3513
3514static const struct cipher_info ciphers[] = {
3515 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3516 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3517 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3518 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3519 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3520 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3521 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3522 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3523};
3524
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003525static const struct cipher_info ciphers_group_mgmt[] = {
3526 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
3527 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
3528 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
3529 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
3530};
3531
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003532
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003533static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3534 struct wpa_driver_capa *capa,
3535 char *buf, size_t buflen)
3536{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003537 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003538 char *pos, *end;
3539 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003540 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003541
3542 pos = buf;
3543 end = pos + buflen;
3544
3545 if (res < 0) {
3546 if (strict)
3547 return 0;
3548 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3549 if (len >= buflen)
3550 return -1;
3551 return len;
3552 }
3553
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003554 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3555 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3556 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003557 pos == buf ? "" : " ",
3558 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003559 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003560 return pos - buf;
3561 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003562 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003563 }
3564
3565 return pos - buf;
3566}
3567
3568
3569static int ctrl_iface_get_capability_group(int res, char *strict,
3570 struct wpa_driver_capa *capa,
3571 char *buf, size_t buflen)
3572{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003573 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003574 char *pos, *end;
3575 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003576 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003577
3578 pos = buf;
3579 end = pos + buflen;
3580
3581 if (res < 0) {
3582 if (strict)
3583 return 0;
3584 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3585 if (len >= buflen)
3586 return -1;
3587 return len;
3588 }
3589
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003590 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3591 if (capa->enc & ciphers[i].capa) {
3592 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003593 pos == buf ? "" : " ",
3594 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003595 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003596 return pos - buf;
3597 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003598 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003599 }
3600
3601 return pos - buf;
3602}
3603
3604
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003605static int ctrl_iface_get_capability_group_mgmt(int res, char *strict,
3606 struct wpa_driver_capa *capa,
3607 char *buf, size_t buflen)
3608{
3609 int ret;
3610 char *pos, *end;
3611 unsigned int i;
3612
3613 pos = buf;
3614 end = pos + buflen;
3615
3616 if (res < 0)
3617 return 0;
3618
3619 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
3620 if (capa->enc & ciphers_group_mgmt[i].capa) {
3621 ret = os_snprintf(pos, end - pos, "%s%s",
3622 pos == buf ? "" : " ",
3623 ciphers_group_mgmt[i].name);
3624 if (os_snprintf_error(end - pos, ret))
3625 return pos - buf;
3626 pos += ret;
3627 }
3628 }
3629
3630 return pos - buf;
3631}
3632
3633
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003634static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3635 struct wpa_driver_capa *capa,
3636 char *buf, size_t buflen)
3637{
3638 int ret;
3639 char *pos, *end;
3640 size_t len;
3641
3642 pos = buf;
3643 end = pos + buflen;
3644
3645 if (res < 0) {
3646 if (strict)
3647 return 0;
3648 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3649 "NONE", buflen);
3650 if (len >= buflen)
3651 return -1;
3652 return len;
3653 }
3654
3655 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003656 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003657 return pos - buf;
3658 pos += ret;
3659
3660 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3661 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3662 ret = os_snprintf(pos, end - pos, " WPA-EAP");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003663 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003664 return pos - buf;
3665 pos += ret;
3666 }
3667
3668 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3669 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3670 ret = os_snprintf(pos, end - pos, " WPA-PSK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003671 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003672 return pos - buf;
3673 pos += ret;
3674 }
3675
3676 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3677 ret = os_snprintf(pos, end - pos, " WPA-NONE");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003678 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003679 return pos - buf;
3680 pos += ret;
3681 }
3682
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003683#ifdef CONFIG_SUITEB
3684 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
3685 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
3686 if (os_snprintf_error(end - pos, ret))
3687 return pos - buf;
3688 pos += ret;
3689 }
3690#endif /* CONFIG_SUITEB */
3691#ifdef CONFIG_SUITEB192
3692 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
3693 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
3694 if (os_snprintf_error(end - pos, ret))
3695 return pos - buf;
3696 pos += ret;
3697 }
3698#endif /* CONFIG_SUITEB192 */
3699
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003700 return pos - buf;
3701}
3702
3703
3704static int ctrl_iface_get_capability_proto(int res, char *strict,
3705 struct wpa_driver_capa *capa,
3706 char *buf, size_t buflen)
3707{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003708 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003709 char *pos, *end;
3710 size_t len;
3711
3712 pos = buf;
3713 end = pos + buflen;
3714
3715 if (res < 0) {
3716 if (strict)
3717 return 0;
3718 len = os_strlcpy(buf, "RSN WPA", buflen);
3719 if (len >= buflen)
3720 return -1;
3721 return len;
3722 }
3723
3724 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3725 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003726 ret = os_snprintf(pos, end - pos, "%sRSN",
3727 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003728 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003729 return pos - buf;
3730 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003731 }
3732
3733 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3734 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003735 ret = os_snprintf(pos, end - pos, "%sWPA",
3736 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003737 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003738 return pos - buf;
3739 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003740 }
3741
3742 return pos - buf;
3743}
3744
3745
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003746static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
3747 int res, char *strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003748 struct wpa_driver_capa *capa,
3749 char *buf, size_t buflen)
3750{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003751 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003752 char *pos, *end;
3753 size_t len;
3754
3755 pos = buf;
3756 end = pos + buflen;
3757
3758 if (res < 0) {
3759 if (strict)
3760 return 0;
3761 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3762 if (len >= buflen)
3763 return -1;
3764 return len;
3765 }
3766
3767 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003768 ret = os_snprintf(pos, end - pos, "%sOPEN",
3769 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003770 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003771 return pos - buf;
3772 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003773 }
3774
3775 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3776 ret = os_snprintf(pos, end - pos, "%sSHARED",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003777 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003778 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003779 return pos - buf;
3780 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003781 }
3782
3783 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003784 ret = os_snprintf(pos, end - pos, "%sLEAP",
3785 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003786 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003787 return pos - buf;
3788 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003789 }
3790
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003791#ifdef CONFIG_SAE
3792 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
3793 ret = os_snprintf(pos, end - pos, "%sSAE",
3794 pos == buf ? "" : " ");
3795 if (os_snprintf_error(end - pos, ret))
3796 return pos - buf;
3797 pos += ret;
3798 }
3799#endif /* CONFIG_SAE */
3800
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003801 return pos - buf;
3802}
3803
3804
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003805static int ctrl_iface_get_capability_modes(int res, char *strict,
3806 struct wpa_driver_capa *capa,
3807 char *buf, size_t buflen)
3808{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003809 int ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003810 char *pos, *end;
3811 size_t len;
3812
3813 pos = buf;
3814 end = pos + buflen;
3815
3816 if (res < 0) {
3817 if (strict)
3818 return 0;
3819 len = os_strlcpy(buf, "IBSS AP", buflen);
3820 if (len >= buflen)
3821 return -1;
3822 return len;
3823 }
3824
3825 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003826 ret = os_snprintf(pos, end - pos, "%sIBSS",
3827 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003828 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003829 return pos - buf;
3830 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003831 }
3832
3833 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003834 ret = os_snprintf(pos, end - pos, "%sAP",
3835 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003836 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003837 return pos - buf;
3838 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003839 }
3840
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003841#ifdef CONFIG_MESH
3842 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
3843 ret = os_snprintf(pos, end - pos, "%sMESH",
3844 pos == buf ? "" : " ");
3845 if (os_snprintf_error(end - pos, ret))
3846 return pos - buf;
3847 pos += ret;
3848 }
3849#endif /* CONFIG_MESH */
3850
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003851 return pos - buf;
3852}
3853
3854
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07003855static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3856 char *buf, size_t buflen)
3857{
3858 struct hostapd_channel_data *chnl;
3859 int ret, i, j;
3860 char *pos, *end, *hmode;
3861
3862 pos = buf;
3863 end = pos + buflen;
3864
3865 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3866 switch (wpa_s->hw.modes[j].mode) {
3867 case HOSTAPD_MODE_IEEE80211B:
3868 hmode = "B";
3869 break;
3870 case HOSTAPD_MODE_IEEE80211G:
3871 hmode = "G";
3872 break;
3873 case HOSTAPD_MODE_IEEE80211A:
3874 hmode = "A";
3875 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003876 case HOSTAPD_MODE_IEEE80211AD:
3877 hmode = "AD";
3878 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07003879 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003880 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07003881 }
3882 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003883 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07003884 return pos - buf;
3885 pos += ret;
3886 chnl = wpa_s->hw.modes[j].channels;
3887 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003888 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3889 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07003890 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003891 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07003892 return pos - buf;
3893 pos += ret;
3894 }
3895 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003896 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07003897 return pos - buf;
3898 pos += ret;
3899 }
3900
3901 return pos - buf;
3902}
3903
3904
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003905static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3906 char *buf, size_t buflen)
3907{
3908 struct hostapd_channel_data *chnl;
3909 int ret, i, j;
3910 char *pos, *end, *hmode;
3911
3912 pos = buf;
3913 end = pos + buflen;
3914
3915 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3916 switch (wpa_s->hw.modes[j].mode) {
3917 case HOSTAPD_MODE_IEEE80211B:
3918 hmode = "B";
3919 break;
3920 case HOSTAPD_MODE_IEEE80211G:
3921 hmode = "G";
3922 break;
3923 case HOSTAPD_MODE_IEEE80211A:
3924 hmode = "A";
3925 break;
3926 case HOSTAPD_MODE_IEEE80211AD:
3927 hmode = "AD";
3928 break;
3929 default:
3930 continue;
3931 }
3932 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3933 hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003934 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003935 return pos - buf;
3936 pos += ret;
3937 chnl = wpa_s->hw.modes[j].channels;
3938 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3939 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3940 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08003941 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003942 chnl[i].chan, chnl[i].freq,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003943 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
3944 " (NO_IR)" : "",
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08003945 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3946 " (DFS)" : "");
3947
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003948 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003949 return pos - buf;
3950 pos += ret;
3951 }
3952 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003953 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003954 return pos - buf;
3955 pos += ret;
3956 }
3957
3958 return pos - buf;
3959}
3960
3961
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003962static int wpa_supplicant_ctrl_iface_get_capability(
3963 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3964 size_t buflen)
3965{
3966 struct wpa_driver_capa capa;
3967 int res;
3968 char *strict;
3969 char field[30];
3970 size_t len;
3971
3972 /* Determine whether or not strict checking was requested */
3973 len = os_strlcpy(field, _field, sizeof(field));
3974 if (len >= sizeof(field))
3975 return -1;
3976 strict = os_strchr(field, ' ');
3977 if (strict != NULL) {
3978 *strict++ = '\0';
3979 if (os_strcmp(strict, "strict") != 0)
3980 return -1;
3981 }
3982
3983 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3984 field, strict ? strict : "");
3985
3986 if (os_strcmp(field, "eap") == 0) {
3987 return eap_get_names(buf, buflen);
3988 }
3989
3990 res = wpa_drv_get_capa(wpa_s, &capa);
3991
3992 if (os_strcmp(field, "pairwise") == 0)
3993 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3994 buf, buflen);
3995
3996 if (os_strcmp(field, "group") == 0)
3997 return ctrl_iface_get_capability_group(res, strict, &capa,
3998 buf, buflen);
3999
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004000 if (os_strcmp(field, "group_mgmt") == 0)
4001 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4002 buf, buflen);
4003
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004004 if (os_strcmp(field, "key_mgmt") == 0)
4005 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
4006 buf, buflen);
4007
4008 if (os_strcmp(field, "proto") == 0)
4009 return ctrl_iface_get_capability_proto(res, strict, &capa,
4010 buf, buflen);
4011
4012 if (os_strcmp(field, "auth_alg") == 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004013 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4014 &capa, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004015
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004016 if (os_strcmp(field, "modes") == 0)
4017 return ctrl_iface_get_capability_modes(res, strict, &capa,
4018 buf, buflen);
4019
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004020 if (os_strcmp(field, "channels") == 0)
4021 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4022
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004023 if (os_strcmp(field, "freq") == 0)
4024 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4025
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004026#ifdef CONFIG_TDLS
4027 if (os_strcmp(field, "tdls") == 0)
4028 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4029#endif /* CONFIG_TDLS */
4030
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004031#ifdef CONFIG_ERP
4032 if (os_strcmp(field, "erp") == 0) {
4033 res = os_snprintf(buf, buflen, "ERP");
4034 if (os_snprintf_error(buflen, res))
4035 return -1;
4036 return res;
4037 }
4038#endif /* CONFIG_EPR */
4039
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004040#ifdef CONFIG_FIPS
4041 if (os_strcmp(field, "fips") == 0) {
4042 res = os_snprintf(buf, buflen, "FIPS");
4043 if (os_snprintf_error(buflen, res))
4044 return -1;
4045 return res;
4046 }
4047#endif /* CONFIG_FIPS */
4048
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004049#ifdef CONFIG_ACS
4050 if (os_strcmp(field, "acs") == 0) {
4051 res = os_snprintf(buf, buflen, "ACS");
4052 if (os_snprintf_error(buflen, res))
4053 return -1;
4054 return res;
4055 }
4056#endif /* CONFIG_ACS */
4057
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004058#ifdef CONFIG_FILS
4059 if (os_strcmp(field, "fils") == 0 &&
4060 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_FILS)) {
4061 res = os_snprintf(buf, buflen, "FILS");
4062 if (os_snprintf_error(buflen, res))
4063 return -1;
4064 return res;
4065 }
4066#endif /* CONFIG_FILS */
4067
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004068 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4069 field);
4070
4071 return -1;
4072}
4073
4074
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004075#ifdef CONFIG_INTERWORKING
4076static char * anqp_add_hex(char *pos, char *end, const char *title,
4077 struct wpabuf *data)
4078{
4079 char *start = pos;
4080 size_t i;
4081 int ret;
4082 const u8 *d;
4083
4084 if (data == NULL)
4085 return start;
4086
4087 ret = os_snprintf(pos, end - pos, "%s=", title);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004088 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004089 return start;
4090 pos += ret;
4091
4092 d = wpabuf_head_u8(data);
4093 for (i = 0; i < wpabuf_len(data); i++) {
4094 ret = os_snprintf(pos, end - pos, "%02x", *d++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004095 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004096 return start;
4097 pos += ret;
4098 }
4099
4100 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004101 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004102 return start;
4103 pos += ret;
4104
4105 return pos;
4106}
4107#endif /* CONFIG_INTERWORKING */
4108
4109
Dmitry Shmidt29333592017-01-09 12:27:11 -08004110#ifdef CONFIG_FILS
4111static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4112{
4113 char *start = pos;
4114 const u8 *ie, *ie_end;
4115 u16 info, realms;
4116 int ret;
4117
4118 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4119 if (!ie)
4120 return 0;
4121 ie_end = ie + 2 + ie[1];
4122 ie += 2;
4123 if (ie_end - ie < 2)
4124 return -1;
4125
4126 info = WPA_GET_LE16(ie);
4127 ie += 2;
4128 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4129 if (os_snprintf_error(end - pos, ret))
4130 return 0;
4131 pos += ret;
4132
4133 if (info & BIT(7)) {
4134 /* Cache Identifier Included */
4135 if (ie_end - ie < 2)
4136 return -1;
4137 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4138 ie[0], ie[1]);
4139 if (os_snprintf_error(end - pos, ret))
4140 return 0;
4141 pos += ret;
4142 ie += 2;
4143 }
4144
4145 if (info & BIT(8)) {
4146 /* HESSID Included */
4147 if (ie_end - ie < ETH_ALEN)
4148 return -1;
4149 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4150 MAC2STR(ie));
4151 if (os_snprintf_error(end - pos, ret))
4152 return 0;
4153 pos += ret;
4154 ie += ETH_ALEN;
4155 }
4156
4157 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4158 if (realms) {
4159 if (ie_end - ie < realms * 2)
4160 return -1;
4161 ret = os_snprintf(pos, end - pos, "fils_realms=");
4162 if (os_snprintf_error(end - pos, ret))
4163 return 0;
4164 pos += ret;
4165
4166 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
4167 if (ret <= 0)
4168 return 0;
4169 pos += ret;
4170 ie += realms * 2;
4171 ret = os_snprintf(pos, end - pos, "\n");
4172 if (os_snprintf_error(end - pos, ret))
4173 return 0;
4174 pos += ret;
4175 }
4176
4177 return pos - start;
4178}
4179#endif /* CONFIG_FILS */
4180
4181
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004182static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
4183 unsigned long mask, char *buf, size_t buflen)
4184{
4185 size_t i;
4186 int ret;
4187 char *pos, *end;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004188 const u8 *ie, *ie2, *osen_ie, *mesh;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004189
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004190 pos = buf;
4191 end = buf + buflen;
4192
4193 if (mask & WPA_BSS_MASK_ID) {
4194 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004195 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004196 return 0;
4197 pos += ret;
4198 }
4199
4200 if (mask & WPA_BSS_MASK_BSSID) {
4201 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
4202 MAC2STR(bss->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004203 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004204 return 0;
4205 pos += ret;
4206 }
4207
4208 if (mask & WPA_BSS_MASK_FREQ) {
4209 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004210 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004211 return 0;
4212 pos += ret;
4213 }
4214
4215 if (mask & WPA_BSS_MASK_BEACON_INT) {
4216 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
4217 bss->beacon_int);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004218 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004219 return 0;
4220 pos += ret;
4221 }
4222
4223 if (mask & WPA_BSS_MASK_CAPABILITIES) {
4224 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
4225 bss->caps);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004226 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004227 return 0;
4228 pos += ret;
4229 }
4230
4231 if (mask & WPA_BSS_MASK_QUAL) {
4232 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004233 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004234 return 0;
4235 pos += ret;
4236 }
4237
4238 if (mask & WPA_BSS_MASK_NOISE) {
4239 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004240 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004241 return 0;
4242 pos += ret;
4243 }
4244
4245 if (mask & WPA_BSS_MASK_LEVEL) {
4246 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004247 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004248 return 0;
4249 pos += ret;
4250 }
4251
4252 if (mask & WPA_BSS_MASK_TSF) {
4253 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
4254 (unsigned long long) bss->tsf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004255 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004256 return 0;
4257 pos += ret;
4258 }
4259
4260 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004261 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004262
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004263 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004264 ret = os_snprintf(pos, end - pos, "age=%d\n",
4265 (int) (now.sec - bss->last_update.sec));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004266 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004267 return 0;
4268 pos += ret;
4269 }
4270
4271 if (mask & WPA_BSS_MASK_IE) {
4272 ret = os_snprintf(pos, end - pos, "ie=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004273 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004274 return 0;
4275 pos += ret;
4276
4277 ie = (const u8 *) (bss + 1);
4278 for (i = 0; i < bss->ie_len; i++) {
4279 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004280 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004281 return 0;
4282 pos += ret;
4283 }
4284
4285 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004286 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004287 return 0;
4288 pos += ret;
4289 }
4290
4291 if (mask & WPA_BSS_MASK_FLAGS) {
4292 ret = os_snprintf(pos, end - pos, "flags=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004293 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004294 return 0;
4295 pos += ret;
4296
Dmitry Shmidt29333592017-01-09 12:27:11 -08004297 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
4298
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004299 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
4300 if (ie)
4301 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
4302 2 + ie[1]);
4303 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4304 if (ie2)
Dmitry Shmidt29333592017-01-09 12:27:11 -08004305 pos = wpa_supplicant_ie_txt(pos, end,
4306 mesh ? "RSN" : "WPA2", ie2,
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004307 2 + ie2[1]);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07004308 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
4309 if (osen_ie)
4310 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
4311 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004312 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07004313 if (!ie && !ie2 && !osen_ie &&
4314 (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004315 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004316 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004317 return 0;
4318 pos += ret;
4319 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08004320
4321 if (mesh) {
4322 ret = os_snprintf(pos, end - pos, "[MESH]");
4323 if (os_snprintf_error(end - pos, ret))
4324 return 0;
4325 pos += ret;
4326 }
4327
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004328 if (bss_is_dmg(bss)) {
4329 const char *s;
4330 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004331 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004332 return 0;
4333 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004334 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
4335 case IEEE80211_CAP_DMG_IBSS:
4336 s = "[IBSS]";
4337 break;
4338 case IEEE80211_CAP_DMG_AP:
4339 s = "[ESS]";
4340 break;
4341 case IEEE80211_CAP_DMG_PBSS:
4342 s = "[PBSS]";
4343 break;
4344 default:
4345 s = "";
4346 break;
4347 }
4348 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004349 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004350 return 0;
4351 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004352 } else {
4353 if (bss->caps & IEEE80211_CAP_IBSS) {
4354 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004355 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004356 return 0;
4357 pos += ret;
4358 }
4359 if (bss->caps & IEEE80211_CAP_ESS) {
4360 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004361 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004362 return 0;
4363 pos += ret;
4364 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004365 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07004366 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
4367 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004368 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004369 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004370 return 0;
4371 pos += ret;
4372 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004373#ifdef CONFIG_HS20
4374 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
4375 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004376 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004377 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004378 pos += ret;
4379 }
4380#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004381#ifdef CONFIG_FILS
4382 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
4383 ret = os_snprintf(pos, end - pos, "[FILS]");
4384 if (os_snprintf_error(end - pos, ret))
4385 return 0;
4386 pos += ret;
4387 }
4388#endif /* CONFIG_FILS */
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004389
4390 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004391 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004392 return 0;
4393 pos += ret;
4394 }
4395
4396 if (mask & WPA_BSS_MASK_SSID) {
4397 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
4398 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004399 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004400 return 0;
4401 pos += ret;
4402 }
4403
4404#ifdef CONFIG_WPS
4405 if (mask & WPA_BSS_MASK_WPS_SCAN) {
4406 ie = (const u8 *) (bss + 1);
4407 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004408 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004409 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004410 if (ret > 0)
4411 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004412 }
4413#endif /* CONFIG_WPS */
4414
4415#ifdef CONFIG_P2P
4416 if (mask & WPA_BSS_MASK_P2P_SCAN) {
4417 ie = (const u8 *) (bss + 1);
4418 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004419 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004420 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004421 if (ret > 0)
4422 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004423 }
4424#endif /* CONFIG_P2P */
4425
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004426#ifdef CONFIG_WIFI_DISPLAY
4427 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
4428 struct wpabuf *wfd;
4429 ie = (const u8 *) (bss + 1);
4430 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
4431 WFD_IE_VENDOR_TYPE);
4432 if (wfd) {
4433 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004434 if (os_snprintf_error(end - pos, ret)) {
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004435 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004436 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004437 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004438 pos += ret;
4439
4440 pos += wpa_snprintf_hex(pos, end - pos,
4441 wpabuf_head(wfd),
4442 wpabuf_len(wfd));
4443 wpabuf_free(wfd);
4444
4445 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004446 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004447 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004448 pos += ret;
4449 }
4450 }
4451#endif /* CONFIG_WIFI_DISPLAY */
4452
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004453#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004454 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
4455 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004456 struct wpa_bss_anqp_elem *elem;
4457
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004458 pos = anqp_add_hex(pos, end, "anqp_capability_list",
4459 anqp->capability_list);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004460 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004461 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004462 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004463 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004464 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004465 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004466 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004467 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004468 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004469 anqp->nai_realm);
4470 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004471 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004472 anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -08004473 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
4474 anqp->fils_realm_info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004475#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004476 pos = anqp_add_hex(pos, end, "hs20_capability_list",
4477 anqp->hs20_capability_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004478 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004479 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004480 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004481 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004482 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004483 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004484 pos = anqp_add_hex(pos, end, "hs20_operating_class",
4485 anqp->hs20_operating_class);
4486 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
4487 anqp->hs20_osu_providers_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004488#endif /* CONFIG_HS20 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004489
4490 dl_list_for_each(elem, &anqp->anqp_elems,
4491 struct wpa_bss_anqp_elem, list) {
4492 char title[20];
4493
4494 os_snprintf(title, sizeof(title), "anqp[%u]",
4495 elem->infoid);
4496 pos = anqp_add_hex(pos, end, title, elem->payload);
4497 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004498 }
4499#endif /* CONFIG_INTERWORKING */
4500
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004501#ifdef CONFIG_MESH
4502 if (mask & WPA_BSS_MASK_MESH_SCAN) {
4503 ie = (const u8 *) (bss + 1);
4504 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004505 if (ret >= end - pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004506 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004507 if (ret > 0)
4508 pos += ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004509 }
4510#endif /* CONFIG_MESH */
4511
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004512 if (mask & WPA_BSS_MASK_SNR) {
4513 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
4514 if (os_snprintf_error(end - pos, ret))
4515 return 0;
4516 pos += ret;
4517 }
4518
4519 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
4520 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
4521 bss->est_throughput);
4522 if (os_snprintf_error(end - pos, ret))
4523 return 0;
4524 pos += ret;
4525 }
4526
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004527#ifdef CONFIG_FST
4528 if (mask & WPA_BSS_MASK_FST) {
4529 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
4530 if (ret < 0 || ret >= end - pos)
4531 return 0;
4532 pos += ret;
4533 }
4534#endif /* CONFIG_FST */
4535
Dmitry Shmidt29333592017-01-09 12:27:11 -08004536 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
4537 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
4538 bss->last_update_idx);
4539 if (os_snprintf_error(end - pos, ret))
4540 return 0;
4541 pos += ret;
4542 }
4543
4544 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
4545 ret = os_snprintf(pos, end - pos, "beacon_ie=");
4546 if (os_snprintf_error(end - pos, ret))
4547 return 0;
4548 pos += ret;
4549
4550 ie = (const u8 *) (bss + 1);
4551 ie += bss->ie_len;
4552 for (i = 0; i < bss->beacon_ie_len; i++) {
4553 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
4554 if (os_snprintf_error(end - pos, ret))
4555 return 0;
4556 pos += ret;
4557 }
4558
4559 ret = os_snprintf(pos, end - pos, "\n");
4560 if (os_snprintf_error(end - pos, ret))
4561 return 0;
4562 pos += ret;
4563 }
4564
4565#ifdef CONFIG_FILS
4566 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
4567 ret = print_fils_indication(bss, pos, end);
4568 if (ret < 0)
4569 return 0;
4570 pos += ret;
4571 }
4572#endif /* CONFIG_FILS */
4573
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004574 if (mask & WPA_BSS_MASK_DELIM) {
4575 ret = os_snprintf(pos, end - pos, "====\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004576 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004577 return 0;
4578 pos += ret;
4579 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07004580
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004581 return pos - buf;
4582}
4583
Dmitry Shmidt04949592012-07-19 12:16:46 -07004584
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004585static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
4586 const char *cmd, char *buf,
4587 size_t buflen)
4588{
4589 u8 bssid[ETH_ALEN];
4590 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004591 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004592 struct wpa_bss *bsslast = NULL;
4593 struct dl_list *next;
4594 int ret = 0;
4595 int len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004596 char *ctmp, *end = buf + buflen;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004597 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004598
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004599 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
4600 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
4601 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004602 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004603 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
4604 list_id);
4605 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004606 unsigned int id1, id2;
4607
4608 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
4609 wpa_printf(MSG_INFO, "Wrong BSS range "
4610 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004611 return 0;
4612 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004613
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004614 if (*(cmd + 6) == '-')
4615 id1 = 0;
4616 else
4617 id1 = atoi(cmd + 6);
4618 ctmp++;
4619 if (*ctmp >= '0' && *ctmp <= '9')
4620 id2 = atoi(ctmp);
4621 else
4622 id2 = (unsigned int) -1;
4623 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
4624 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004625 bsslast = dl_list_last(&wpa_s->bss_id,
4626 struct wpa_bss,
4627 list_id);
4628 else {
4629 bsslast = wpa_bss_get_id(wpa_s, id2);
4630 if (bsslast == NULL && bss && id2 > id1) {
4631 struct wpa_bss *tmp = bss;
4632 for (;;) {
4633 next = tmp->list_id.next;
4634 if (next == &wpa_s->bss_id)
4635 break;
4636 tmp = dl_list_entry(
4637 next, struct wpa_bss,
4638 list_id);
4639 if (tmp->id > id2)
4640 break;
4641 bsslast = tmp;
4642 }
4643 }
4644 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004645 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004646 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004647 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004648 else if (os_strncmp(cmd, "LAST", 4) == 0)
4649 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004650 else if (os_strncmp(cmd, "ID-", 3) == 0) {
4651 i = atoi(cmd + 3);
4652 bss = wpa_bss_get_id(wpa_s, i);
4653 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4654 i = atoi(cmd + 5);
4655 bss = wpa_bss_get_id(wpa_s, i);
4656 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004657 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004658 if (next == &wpa_s->bss_id)
4659 bss = NULL;
4660 else
4661 bss = dl_list_entry(next, struct wpa_bss,
4662 list_id);
4663 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08004664 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
4665 bss = wpa_s->current_bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004666#ifdef CONFIG_P2P
4667 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
4668 if (hwaddr_aton(cmd + 13, bssid) == 0)
4669 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
4670 else
4671 bss = NULL;
4672#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004673 } else if (hwaddr_aton(cmd, bssid) == 0)
4674 bss = wpa_bss_get_bssid(wpa_s, bssid);
4675 else {
4676 struct wpa_bss *tmp;
4677 i = atoi(cmd);
4678 bss = NULL;
4679 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
4680 {
4681 if (i-- == 0) {
4682 bss = tmp;
4683 break;
4684 }
4685 }
4686 }
4687
Dmitry Shmidt04949592012-07-19 12:16:46 -07004688 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
4689 mask = strtoul(ctmp + 5, NULL, 0x10);
4690 if (mask == 0)
4691 mask = WPA_BSS_MASK_ALL;
4692 }
4693
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004694 if (bss == NULL)
4695 return 0;
4696
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004697 if (bsslast == NULL)
4698 bsslast = bss;
4699 do {
4700 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
4701 ret += len;
4702 buf += len;
4703 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004704 if (bss == bsslast) {
4705 if ((mask & WPA_BSS_MASK_DELIM) && len &&
4706 (bss == dl_list_last(&wpa_s->bss_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004707 struct wpa_bss, list_id))) {
4708 int res;
4709
4710 res = os_snprintf(buf - 5, end - buf + 5,
4711 "####\n");
4712 if (os_snprintf_error(end - buf + 5, res)) {
4713 wpa_printf(MSG_DEBUG,
4714 "Could not add end delim");
4715 }
4716 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004717 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004718 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004719 next = bss->list_id.next;
4720 if (next == &wpa_s->bss_id)
4721 break;
4722 bss = dl_list_entry(next, struct wpa_bss, list_id);
4723 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004724
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004725 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004726}
4727
4728
4729static int wpa_supplicant_ctrl_iface_ap_scan(
4730 struct wpa_supplicant *wpa_s, char *cmd)
4731{
4732 int ap_scan = atoi(cmd);
4733 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
4734}
4735
4736
4737static int wpa_supplicant_ctrl_iface_scan_interval(
4738 struct wpa_supplicant *wpa_s, char *cmd)
4739{
4740 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004741 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004742}
4743
4744
4745static int wpa_supplicant_ctrl_iface_bss_expire_age(
4746 struct wpa_supplicant *wpa_s, char *cmd)
4747{
4748 int expire_age = atoi(cmd);
4749 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
4750}
4751
4752
4753static int wpa_supplicant_ctrl_iface_bss_expire_count(
4754 struct wpa_supplicant *wpa_s, char *cmd)
4755{
4756 int expire_count = atoi(cmd);
4757 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
4758}
4759
4760
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004761static void wpa_supplicant_ctrl_iface_bss_flush(
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07004762 struct wpa_supplicant *wpa_s, char *cmd)
4763{
4764 int flush_age = atoi(cmd);
4765
4766 if (flush_age == 0)
4767 wpa_bss_flush(wpa_s);
4768 else
4769 wpa_bss_flush_by_age(wpa_s, flush_age);
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07004770}
4771
4772
Dmitry Shmidt21de2142014-04-08 10:50:52 -07004773#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004774static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
4775{
4776 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
4777 /* MLME-DELETEKEYS.request */
4778 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
4779 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
4780 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
4781 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
4782#ifdef CONFIG_IEEE80211W
4783 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
4784 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
4785#endif /* CONFIG_IEEE80211W */
4786
4787 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
4788 0);
4789 /* MLME-SETPROTECTION.request(None) */
4790 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
4791 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
4792 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
4793 wpa_sm_drop_sa(wpa_s->wpa);
4794}
Dmitry Shmidt21de2142014-04-08 10:50:52 -07004795#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004796
4797
4798static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
4799 char *addr)
4800{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004801#ifdef CONFIG_NO_SCAN_PROCESSING
4802 return -1;
4803#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004804 u8 bssid[ETH_ALEN];
4805 struct wpa_bss *bss;
4806 struct wpa_ssid *ssid = wpa_s->current_ssid;
4807
4808 if (hwaddr_aton(addr, bssid)) {
4809 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
4810 "address '%s'", addr);
4811 return -1;
4812 }
4813
4814 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
4815
Dmitry Shmidt444d5672013-04-01 13:08:44 -07004816 if (!ssid) {
4817 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
4818 "configuration known for the target AP");
4819 return -1;
4820 }
4821
4822 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004823 if (!bss) {
4824 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
4825 "from BSS table");
4826 return -1;
4827 }
4828
4829 /*
4830 * TODO: Find best network configuration block from configuration to
4831 * allow roaming to other networks
4832 */
4833
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004834 wpa_s->reassociate = 1;
4835 wpa_supplicant_connect(wpa_s, bss, ssid);
4836
4837 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004838#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004839}
4840
4841
4842#ifdef CONFIG_P2P
4843static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
4844{
4845 unsigned int timeout = atoi(cmd);
4846 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004847 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004848 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004849 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004850 unsigned int search_delay;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004851 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08004852 u8 seek_count = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004853 int freq = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004854
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004855 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4856 wpa_dbg(wpa_s, MSG_INFO,
4857 "Reject P2P_FIND since interface is disabled");
4858 return -1;
4859 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004860 if (os_strstr(cmd, "type=social"))
4861 type = P2P_FIND_ONLY_SOCIAL;
4862 else if (os_strstr(cmd, "type=progressive"))
4863 type = P2P_FIND_PROGRESSIVE;
4864
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004865 pos = os_strstr(cmd, "dev_id=");
4866 if (pos) {
4867 pos += 7;
4868 if (hwaddr_aton(pos, dev_id))
4869 return -1;
4870 _dev_id = dev_id;
4871 }
4872
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004873 pos = os_strstr(cmd, "dev_type=");
4874 if (pos) {
4875 pos += 9;
4876 if (wps_dev_type_str2bin(pos, dev_type) < 0)
4877 return -1;
4878 _dev_type = dev_type;
4879 }
4880
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004881 pos = os_strstr(cmd, "delay=");
4882 if (pos) {
4883 pos += 6;
4884 search_delay = atoi(pos);
4885 } else
4886 search_delay = wpas_p2p_search_delay(wpa_s);
4887
Dmitry Shmidt41712582015-06-29 11:02:15 -07004888 pos = os_strstr(cmd, "freq=");
4889 if (pos) {
4890 pos += 5;
4891 freq = atoi(pos);
4892 if (freq <= 0)
4893 return -1;
4894 }
4895
Dmitry Shmidt216983b2015-02-06 10:50:36 -08004896 /* Must be searched for last, because it adds nul termination */
4897 pos = os_strstr(cmd, " seek=");
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004898 if (pos)
4899 pos += 6;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08004900 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
4901 char *term;
4902
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004903 _seek[seek_count++] = pos;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004904 seek = _seek;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004905 term = os_strchr(pos, ' ');
4906 if (!term)
4907 break;
4908 *term = '\0';
4909 pos = os_strstr(term + 1, "seek=");
4910 if (pos)
4911 pos += 5;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08004912 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08004913 if (seek_count > P2P_MAX_QUERY_HASH) {
4914 seek[0] = NULL;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004915 seek_count = 1;
4916 }
4917
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004918 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004919 _dev_id, search_delay, seek_count, seek, freq);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08004920}
4921
4922
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004923static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
4924{
4925 const char *last = NULL;
4926 const char *token;
4927 long int token_len;
4928 unsigned int i;
4929
4930 /* Expected predefined CPT names delimited by ':' */
4931 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
4932 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
4933 wpa_printf(MSG_ERROR,
4934 "P2PS: CPT name list is too long, expected up to %d names",
4935 P2PS_FEATURE_CAPAB_CPT_MAX);
4936 cpt[0] = 0;
4937 return -1;
4938 }
4939
4940 token_len = last - token;
4941
4942 if (token_len == 3 &&
4943 os_memcmp(token, "UDP", token_len) == 0) {
4944 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
4945 } else if (token_len == 3 &&
4946 os_memcmp(token, "MAC", token_len) == 0) {
4947 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
4948 } else {
4949 wpa_printf(MSG_ERROR,
4950 "P2PS: Unsupported CPT name '%s'", token);
4951 cpt[0] = 0;
4952 return -1;
4953 }
4954
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004955 if (isblank((unsigned char) *last)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004956 i++;
4957 break;
4958 }
4959 }
4960 cpt[i] = 0;
4961 return 0;
4962}
4963
4964
Dmitry Shmidt216983b2015-02-06 10:50:36 -08004965static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
4966{
4967 struct p2ps_provision *p2ps_prov;
4968 char *pos;
4969 size_t info_len = 0;
4970 char *info = NULL;
4971 u8 role = P2PS_SETUP_NONE;
4972 long long unsigned val;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004973 int i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08004974
4975 pos = os_strstr(cmd, "info=");
4976 if (pos) {
4977 pos += 5;
4978 info_len = os_strlen(pos);
4979
4980 if (info_len) {
4981 info = os_malloc(info_len + 1);
4982 if (info) {
4983 info_len = utf8_unescape(pos, info_len,
4984 info, info_len + 1);
4985 } else
4986 info_len = 0;
4987 }
4988 }
4989
4990 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
4991 if (p2ps_prov == NULL) {
4992 os_free(info);
4993 return NULL;
4994 }
4995
4996 if (info) {
4997 os_memcpy(p2ps_prov->info, info, info_len);
4998 p2ps_prov->info[info_len] = '\0';
4999 os_free(info);
5000 }
5001
5002 pos = os_strstr(cmd, "status=");
5003 if (pos)
5004 p2ps_prov->status = atoi(pos + 7);
5005 else
5006 p2ps_prov->status = -1;
5007
5008 pos = os_strstr(cmd, "adv_id=");
5009 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
5010 goto invalid_args;
5011 p2ps_prov->adv_id = val;
5012
5013 pos = os_strstr(cmd, "method=");
5014 if (pos)
5015 p2ps_prov->method = strtol(pos + 7, NULL, 16);
5016 else
5017 p2ps_prov->method = 0;
5018
5019 pos = os_strstr(cmd, "session=");
5020 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
5021 goto invalid_args;
5022 p2ps_prov->session_id = val;
5023
5024 pos = os_strstr(cmd, "adv_mac=");
5025 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
5026 goto invalid_args;
5027
5028 pos = os_strstr(cmd, "session_mac=");
5029 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
5030 goto invalid_args;
5031
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005032 pos = os_strstr(cmd, "cpt=");
5033 if (pos) {
5034 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
5035 p2ps_prov->cpt_priority))
5036 goto invalid_args;
5037 } else {
5038 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5039 }
5040
5041 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
5042 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
5043
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005044 /* force conncap with tstCap (no sanity checks) */
5045 pos = os_strstr(cmd, "tstCap=");
5046 if (pos) {
5047 role = strtol(pos + 7, NULL, 16);
5048 } else {
5049 pos = os_strstr(cmd, "role=");
5050 if (pos) {
5051 role = strtol(pos + 5, NULL, 16);
5052 if (role != P2PS_SETUP_CLIENT &&
5053 role != P2PS_SETUP_GROUP_OWNER)
5054 role = P2PS_SETUP_NONE;
5055 }
5056 }
5057 p2ps_prov->role = role;
5058
5059 return p2ps_prov;
5060
5061invalid_args:
5062 os_free(p2ps_prov);
5063 return NULL;
5064}
5065
5066
5067static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
5068{
5069 u8 addr[ETH_ALEN];
5070 struct p2ps_provision *p2ps_prov;
5071 char *pos;
5072
5073 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5074
5075 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5076
5077 if (hwaddr_aton(cmd, addr))
5078 return -1;
5079
5080 pos = cmd + 17;
5081 if (*pos != ' ')
5082 return -1;
5083
5084 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5085 if (!p2ps_prov)
5086 return -1;
5087
5088 if (p2ps_prov->status < 0) {
5089 os_free(p2ps_prov);
5090 return -1;
5091 }
5092
5093 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5094 p2ps_prov);
5095}
5096
5097
5098static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
5099{
5100 u8 addr[ETH_ALEN];
5101 struct p2ps_provision *p2ps_prov;
5102 char *pos;
5103
5104 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5105 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5106 */
5107
5108 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5109 if (hwaddr_aton(cmd, addr))
5110 return -1;
5111
5112 pos = cmd + 17;
5113 if (*pos != ' ')
5114 return -1;
5115
5116 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5117 if (!p2ps_prov)
5118 return -1;
5119
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005120 p2ps_prov->pd_seeker = 1;
5121
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005122 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5123 p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005124}
5125
5126
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005127static int parse_freq(int chwidth, int freq2)
5128{
5129 if (freq2 < 0)
5130 return -1;
5131 if (freq2)
5132 return VHT_CHANWIDTH_80P80MHZ;
5133
5134 switch (chwidth) {
5135 case 0:
5136 case 20:
5137 case 40:
5138 return VHT_CHANWIDTH_USE_HT;
5139 case 80:
5140 return VHT_CHANWIDTH_80MHZ;
5141 case 160:
5142 return VHT_CHANWIDTH_160MHZ;
5143 default:
5144 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
5145 chwidth);
5146 return -1;
5147 }
5148}
5149
5150
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005151static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
5152 char *buf, size_t buflen)
5153{
5154 u8 addr[ETH_ALEN];
5155 char *pos, *pos2;
5156 char *pin = NULL;
5157 enum p2p_wps_method wps_method;
5158 int new_pin;
5159 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005160 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005161 int join;
5162 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005163 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005164 int go_intent = -1;
5165 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005166 int pd;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005167 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005168 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
5169 size_t group_ssid_len = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005170
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005171 if (!wpa_s->global->p2p_init_wpa_s)
5172 return -1;
5173 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
5174 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
5175 wpa_s->global->p2p_init_wpa_s->ifname);
5176 wpa_s = wpa_s->global->p2p_init_wpa_s;
5177 }
5178
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005179 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
Dmitry Shmidt04949592012-07-19 12:16:46 -07005180 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005181 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005182 * [ht40] [vht] [auto] [ssid=<hexdump>] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005183
5184 if (hwaddr_aton(cmd, addr))
5185 return -1;
5186
5187 pos = cmd + 17;
5188 if (*pos != ' ')
5189 return -1;
5190 pos++;
5191
5192 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005193 pos2 = os_strstr(pos, " persistent=");
5194 if (pos2) {
5195 struct wpa_ssid *ssid;
5196 persistent_id = atoi(pos2 + 12);
5197 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
5198 if (ssid == NULL || ssid->disabled != 2 ||
5199 ssid->mode != WPAS_MODE_P2P_GO) {
5200 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
5201 "SSID id=%d for persistent P2P group (GO)",
5202 persistent_id);
5203 return -1;
5204 }
5205 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005206 join = os_strstr(pos, " join") != NULL;
5207 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005208 automatic = os_strstr(pos, " auto") != NULL;
5209 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005210 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
5211 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
5212 vht;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005213
5214 pos2 = os_strstr(pos, " go_intent=");
5215 if (pos2) {
5216 pos2 += 11;
5217 go_intent = atoi(pos2);
5218 if (go_intent < 0 || go_intent > 15)
5219 return -1;
5220 }
5221
5222 pos2 = os_strstr(pos, " freq=");
5223 if (pos2) {
5224 pos2 += 6;
5225 freq = atoi(pos2);
5226 if (freq <= 0)
5227 return -1;
5228 }
5229
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005230 pos2 = os_strstr(pos, " freq2=");
5231 if (pos2)
5232 freq2 = atoi(pos2 + 7);
5233
5234 pos2 = os_strstr(pos, " max_oper_chwidth=");
5235 if (pos2)
5236 chwidth = atoi(pos2 + 18);
5237
5238 max_oper_chwidth = parse_freq(chwidth, freq2);
5239 if (max_oper_chwidth < 0)
5240 return -1;
5241
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005242 pos2 = os_strstr(pos, " ssid=");
5243 if (pos2) {
5244 char *end;
5245
5246 pos2 += 6;
5247 end = os_strchr(pos2, ' ');
5248 if (!end)
5249 group_ssid_len = os_strlen(pos2) / 2;
5250 else
5251 group_ssid_len = (end - pos2) / 2;
5252 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
5253 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
5254 return -1;
5255 group_ssid = _group_ssid;
5256 }
5257
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005258 if (os_strncmp(pos, "pin", 3) == 0) {
5259 /* Request random PIN (to be displayed) and enable the PIN */
5260 wps_method = WPS_PIN_DISPLAY;
5261 } else if (os_strncmp(pos, "pbc", 3) == 0) {
5262 wps_method = WPS_PBC;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005263 } else if (os_strstr(pos, "p2ps") != NULL) {
5264 wps_method = WPS_P2PS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005265 } else {
5266 pin = pos;
5267 pos = os_strchr(pin, ' ');
5268 wps_method = WPS_PIN_KEYPAD;
5269 if (pos) {
5270 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005271 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005272 wps_method = WPS_PIN_DISPLAY;
5273 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005274 if (!wps_pin_str_valid(pin)) {
5275 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
5276 return 17;
5277 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005278 }
5279
5280 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005281 persistent_group, automatic, join,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005282 auth, go_intent, freq, freq2, persistent_id,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005283 pd, ht40, vht, max_oper_chwidth,
5284 group_ssid, group_ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005285 if (new_pin == -2) {
5286 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5287 return 25;
5288 }
5289 if (new_pin == -3) {
5290 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5291 return 25;
5292 }
5293 if (new_pin < 0)
5294 return -1;
5295 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
5296 ret = os_snprintf(buf, buflen, "%08d", new_pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005297 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005298 return -1;
5299 return ret;
5300 }
5301
5302 os_memcpy(buf, "OK\n", 3);
5303 return 3;
5304}
5305
5306
5307static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
5308{
5309 unsigned int timeout = atoi(cmd);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005310 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5311 wpa_dbg(wpa_s, MSG_INFO,
5312 "Reject P2P_LISTEN since interface is disabled");
5313 return -1;
5314 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005315 return wpas_p2p_listen(wpa_s, timeout);
5316}
5317
5318
5319static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
5320{
5321 u8 addr[ETH_ALEN];
5322 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005323 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005324
Dmitry Shmidt04949592012-07-19 12:16:46 -07005325 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005326
5327 if (hwaddr_aton(cmd, addr))
5328 return -1;
5329
5330 pos = cmd + 17;
5331 if (*pos != ' ')
5332 return -1;
5333 pos++;
5334
Dmitry Shmidt04949592012-07-19 12:16:46 -07005335 if (os_strstr(pos, " join") != NULL)
5336 use = WPAS_P2P_PD_FOR_JOIN;
5337 else if (os_strstr(pos, " auto") != NULL)
5338 use = WPAS_P2P_PD_AUTO;
5339
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005340 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005341}
5342
5343
5344static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
5345 size_t buflen)
5346{
5347 struct wpa_ssid *ssid = wpa_s->current_ssid;
5348
5349 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
5350 ssid->passphrase == NULL)
5351 return -1;
5352
5353 os_strlcpy(buf, ssid->passphrase, buflen);
5354 return os_strlen(buf);
5355}
5356
5357
5358static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
5359 char *buf, size_t buflen)
5360{
5361 u64 ref;
5362 int res;
5363 u8 dst_buf[ETH_ALEN], *dst;
5364 struct wpabuf *tlvs;
5365 char *pos;
5366 size_t len;
5367
5368 if (hwaddr_aton(cmd, dst_buf))
5369 return -1;
5370 dst = dst_buf;
5371 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
5372 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
5373 dst = NULL;
5374 pos = cmd + 17;
5375 if (*pos != ' ')
5376 return -1;
5377 pos++;
5378
5379 if (os_strncmp(pos, "upnp ", 5) == 0) {
5380 u8 version;
5381 pos += 5;
5382 if (hexstr2bin(pos, &version, 1) < 0)
5383 return -1;
5384 pos += 2;
5385 if (*pos != ' ')
5386 return -1;
5387 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005388 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005389#ifdef CONFIG_WIFI_DISPLAY
5390 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
5391 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
5392#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005393 } else if (os_strncmp(pos, "asp ", 4) == 0) {
5394 char *svc_str;
5395 char *svc_info = NULL;
5396 u32 id;
5397
5398 pos += 4;
5399 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
5400 return -1;
5401
5402 pos = os_strchr(pos, ' ');
5403 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
5404 return -1;
5405
5406 svc_str = pos + 1;
5407
5408 pos = os_strchr(svc_str, ' ');
5409
5410 if (pos)
5411 *pos++ = '\0';
5412
5413 /* All remaining data is the svc_info string */
5414 if (pos && pos[0] && pos[0] != ' ') {
5415 len = os_strlen(pos);
5416
5417 /* Unescape in place */
5418 len = utf8_unescape(pos, len, pos, len);
5419 if (len > 0xff)
5420 return -1;
5421
5422 svc_info = pos;
5423 }
5424
5425 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
5426 svc_str, svc_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005427 } else {
5428 len = os_strlen(pos);
5429 if (len & 1)
5430 return -1;
5431 len /= 2;
5432 tlvs = wpabuf_alloc(len);
5433 if (tlvs == NULL)
5434 return -1;
5435 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
5436 wpabuf_free(tlvs);
5437 return -1;
5438 }
5439
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005440 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005441 wpabuf_free(tlvs);
5442 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005443 if (ref == 0)
5444 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005445 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005446 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005447 return -1;
5448 return res;
5449}
5450
5451
5452static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
5453 char *cmd)
5454{
5455 long long unsigned val;
5456 u64 req;
5457 if (sscanf(cmd, "%llx", &val) != 1)
5458 return -1;
5459 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005460 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005461}
5462
5463
5464static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
5465{
5466 int freq;
5467 u8 dst[ETH_ALEN];
5468 u8 dialog_token;
5469 struct wpabuf *resp_tlvs;
5470 char *pos, *pos2;
5471 size_t len;
5472
5473 pos = os_strchr(cmd, ' ');
5474 if (pos == NULL)
5475 return -1;
5476 *pos++ = '\0';
5477 freq = atoi(cmd);
5478 if (freq == 0)
5479 return -1;
5480
5481 if (hwaddr_aton(pos, dst))
5482 return -1;
5483 pos += 17;
5484 if (*pos != ' ')
5485 return -1;
5486 pos++;
5487
5488 pos2 = os_strchr(pos, ' ');
5489 if (pos2 == NULL)
5490 return -1;
5491 *pos2++ = '\0';
5492 dialog_token = atoi(pos);
5493
5494 len = os_strlen(pos2);
5495 if (len & 1)
5496 return -1;
5497 len /= 2;
5498 resp_tlvs = wpabuf_alloc(len);
5499 if (resp_tlvs == NULL)
5500 return -1;
5501 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
5502 wpabuf_free(resp_tlvs);
5503 return -1;
5504 }
5505
5506 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
5507 wpabuf_free(resp_tlvs);
5508 return 0;
5509}
5510
5511
5512static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
5513 char *cmd)
5514{
Dmitry Shmidt04949592012-07-19 12:16:46 -07005515 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
5516 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005517 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
5518 return 0;
5519}
5520
5521
5522static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
5523 char *cmd)
5524{
5525 char *pos;
5526 size_t len;
5527 struct wpabuf *query, *resp;
5528
5529 pos = os_strchr(cmd, ' ');
5530 if (pos == NULL)
5531 return -1;
5532 *pos++ = '\0';
5533
5534 len = os_strlen(cmd);
5535 if (len & 1)
5536 return -1;
5537 len /= 2;
5538 query = wpabuf_alloc(len);
5539 if (query == NULL)
5540 return -1;
5541 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
5542 wpabuf_free(query);
5543 return -1;
5544 }
5545
5546 len = os_strlen(pos);
5547 if (len & 1) {
5548 wpabuf_free(query);
5549 return -1;
5550 }
5551 len /= 2;
5552 resp = wpabuf_alloc(len);
5553 if (resp == NULL) {
5554 wpabuf_free(query);
5555 return -1;
5556 }
5557 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
5558 wpabuf_free(query);
5559 wpabuf_free(resp);
5560 return -1;
5561 }
5562
5563 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
5564 wpabuf_free(query);
5565 wpabuf_free(resp);
5566 return -1;
5567 }
5568 return 0;
5569}
5570
5571
5572static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
5573{
5574 char *pos;
5575 u8 version;
5576
5577 pos = os_strchr(cmd, ' ');
5578 if (pos == NULL)
5579 return -1;
5580 *pos++ = '\0';
5581
5582 if (hexstr2bin(cmd, &version, 1) < 0)
5583 return -1;
5584
5585 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
5586}
5587
5588
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005589static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
5590 u8 replace, char *cmd)
5591{
5592 char *pos;
5593 char *adv_str;
5594 u32 auto_accept, adv_id, svc_state, config_methods;
5595 char *svc_info = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005596 char *cpt_prio_str;
5597 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005598
5599 pos = os_strchr(cmd, ' ');
5600 if (pos == NULL)
5601 return -1;
5602 *pos++ = '\0';
5603
5604 /* Auto-Accept value is mandatory, and must be one of the
5605 * single values (0, 1, 2, 4) */
5606 auto_accept = atoi(cmd);
5607 switch (auto_accept) {
5608 case P2PS_SETUP_NONE: /* No auto-accept */
5609 case P2PS_SETUP_NEW:
5610 case P2PS_SETUP_CLIENT:
5611 case P2PS_SETUP_GROUP_OWNER:
5612 break;
5613 default:
5614 return -1;
5615 }
5616
5617 /* Advertisement ID is mandatory */
5618 cmd = pos;
5619 pos = os_strchr(cmd, ' ');
5620 if (pos == NULL)
5621 return -1;
5622 *pos++ = '\0';
5623
5624 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5625 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
5626 return -1;
5627
5628 /* Only allow replacements if exist, and adds if not */
5629 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
5630 if (!replace)
5631 return -1;
5632 } else {
5633 if (replace)
5634 return -1;
5635 }
5636
5637 /* svc_state between 0 - 0xff is mandatory */
5638 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
5639 return -1;
5640
5641 pos = os_strchr(pos, ' ');
5642 if (pos == NULL)
5643 return -1;
5644
5645 /* config_methods is mandatory */
5646 pos++;
5647 if (sscanf(pos, "%x", &config_methods) != 1)
5648 return -1;
5649
5650 if (!(config_methods &
5651 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
5652 return -1;
5653
5654 pos = os_strchr(pos, ' ');
5655 if (pos == NULL)
5656 return -1;
5657
5658 pos++;
5659 adv_str = pos;
5660
5661 /* Advertisement string is mandatory */
5662 if (!pos[0] || pos[0] == ' ')
5663 return -1;
5664
5665 /* Terminate svc string */
5666 pos = os_strchr(pos, ' ');
5667 if (pos != NULL)
5668 *pos++ = '\0';
5669
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005670 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
5671 if (cpt_prio_str) {
5672 pos = os_strchr(pos, ' ');
5673 if (pos != NULL)
5674 *pos++ = '\0';
5675
5676 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
5677 return -1;
5678 } else {
5679 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5680 cpt_prio[1] = 0;
5681 }
5682
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005683 /* Service and Response Information are optional */
5684 if (pos && pos[0]) {
5685 size_t len;
5686
5687 /* Note the bare ' included, which cannot exist legally
5688 * in unescaped string. */
5689 svc_info = os_strstr(pos, "svc_info='");
5690
5691 if (svc_info) {
5692 svc_info += 9;
5693 len = os_strlen(svc_info);
5694 utf8_unescape(svc_info, len, svc_info, len);
5695 }
5696 }
5697
5698 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
5699 (u8) svc_state, (u16) config_methods,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005700 svc_info, cpt_prio);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005701}
5702
5703
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005704static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
5705{
5706 char *pos;
5707
5708 pos = os_strchr(cmd, ' ');
5709 if (pos == NULL)
5710 return -1;
5711 *pos++ = '\0';
5712
5713 if (os_strcmp(cmd, "bonjour") == 0)
5714 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
5715 if (os_strcmp(cmd, "upnp") == 0)
5716 return p2p_ctrl_service_add_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005717 if (os_strcmp(cmd, "asp") == 0)
5718 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005719 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
5720 return -1;
5721}
5722
5723
5724static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
5725 char *cmd)
5726{
5727 size_t len;
5728 struct wpabuf *query;
5729 int ret;
5730
5731 len = os_strlen(cmd);
5732 if (len & 1)
5733 return -1;
5734 len /= 2;
5735 query = wpabuf_alloc(len);
5736 if (query == NULL)
5737 return -1;
5738 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
5739 wpabuf_free(query);
5740 return -1;
5741 }
5742
5743 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
5744 wpabuf_free(query);
5745 return ret;
5746}
5747
5748
5749static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
5750{
5751 char *pos;
5752 u8 version;
5753
5754 pos = os_strchr(cmd, ' ');
5755 if (pos == NULL)
5756 return -1;
5757 *pos++ = '\0';
5758
5759 if (hexstr2bin(cmd, &version, 1) < 0)
5760 return -1;
5761
5762 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
5763}
5764
5765
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005766static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
5767{
5768 u32 adv_id;
5769
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005770 if (os_strcmp(cmd, "all") == 0) {
5771 wpas_p2p_service_flush_asp(wpa_s);
5772 return 0;
5773 }
5774
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005775 if (sscanf(cmd, "%x", &adv_id) != 1)
5776 return -1;
5777
5778 return wpas_p2p_service_del_asp(wpa_s, adv_id);
5779}
5780
5781
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005782static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
5783{
5784 char *pos;
5785
5786 pos = os_strchr(cmd, ' ');
5787 if (pos == NULL)
5788 return -1;
5789 *pos++ = '\0';
5790
5791 if (os_strcmp(cmd, "bonjour") == 0)
5792 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
5793 if (os_strcmp(cmd, "upnp") == 0)
5794 return p2p_ctrl_service_del_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005795 if (os_strcmp(cmd, "asp") == 0)
5796 return p2p_ctrl_service_del_asp(wpa_s, pos);
5797 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
5798 return -1;
5799}
5800
5801
5802static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
5803{
5804 char *pos;
5805
5806 pos = os_strchr(cmd, ' ');
5807 if (pos == NULL)
5808 return -1;
5809 *pos++ = '\0';
5810
5811 if (os_strcmp(cmd, "asp") == 0)
5812 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
5813
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005814 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
5815 return -1;
5816}
5817
5818
5819static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
5820{
5821 u8 addr[ETH_ALEN];
5822
5823 /* <addr> */
5824
5825 if (hwaddr_aton(cmd, addr))
5826 return -1;
5827
5828 return wpas_p2p_reject(wpa_s, addr);
5829}
5830
5831
5832static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
5833{
5834 char *pos;
5835 int id;
5836 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005837 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08005838 int freq = 0, pref_freq = 0;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005839 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005840
5841 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005842 pos = os_strstr(cmd, " peer=");
5843 if (pos) {
5844 pos += 6;
5845 if (hwaddr_aton(pos, peer))
5846 return -1;
5847 _peer = peer;
5848 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005849 ssid = wpa_config_get_network(wpa_s->conf, id);
5850 if (ssid == NULL || ssid->disabled != 2) {
5851 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
5852 "for persistent P2P group",
5853 id);
5854 return -1;
5855 }
5856
Jouni Malinen31be0a42012-08-31 21:20:51 +03005857 pos = os_strstr(cmd, " freq=");
5858 if (pos) {
5859 pos += 6;
5860 freq = atoi(pos);
5861 if (freq <= 0)
5862 return -1;
5863 }
5864
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08005865 pos = os_strstr(cmd, " pref=");
5866 if (pos) {
5867 pos += 6;
5868 pref_freq = atoi(pos);
5869 if (pref_freq <= 0)
5870 return -1;
5871 }
5872
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005873 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
5874 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
5875 vht;
Jouni Malinen31be0a42012-08-31 21:20:51 +03005876
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005877 pos = os_strstr(cmd, "freq2=");
5878 if (pos)
5879 freq2 = atoi(pos + 6);
5880
5881 pos = os_strstr(cmd, " max_oper_chwidth=");
5882 if (pos)
5883 chwidth = atoi(pos + 18);
5884
5885 max_oper_chwidth = parse_freq(chwidth, freq2);
5886 if (max_oper_chwidth < 0)
5887 return -1;
5888
5889 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
5890 max_oper_chwidth, pref_freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005891}
5892
5893
5894static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
5895{
5896 char *pos;
5897 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
5898
5899 pos = os_strstr(cmd, " peer=");
5900 if (!pos)
5901 return -1;
5902
5903 *pos = '\0';
5904 pos += 6;
5905 if (hwaddr_aton(pos, peer)) {
5906 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
5907 return -1;
5908 }
5909
5910 pos = os_strstr(pos, " go_dev_addr=");
5911 if (pos) {
5912 pos += 13;
5913 if (hwaddr_aton(pos, go_dev_addr)) {
5914 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
5915 pos);
5916 return -1;
5917 }
5918 go_dev = go_dev_addr;
5919 }
5920
5921 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
5922}
5923
5924
5925static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
5926{
5927 if (os_strncmp(cmd, "persistent=", 11) == 0)
5928 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
5929 if (os_strncmp(cmd, "group=", 6) == 0)
5930 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
5931
5932 return -1;
5933}
5934
5935
5936static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005937 int id, int freq, int vht_center_freq2,
5938 int ht40, int vht, int vht_chwidth)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005939{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005940 struct wpa_ssid *ssid;
5941
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005942 ssid = wpa_config_get_network(wpa_s->conf, id);
5943 if (ssid == NULL || ssid->disabled != 2) {
5944 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
5945 "for persistent P2P group",
5946 id);
5947 return -1;
5948 }
5949
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005950 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
5951 vht_center_freq2, 0, ht40, vht,
5952 vht_chwidth, NULL, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005953}
5954
5955
5956static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
5957{
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005958 int freq = 0, persistent = 0, group_id = -1;
5959 int vht = wpa_s->conf->p2p_go_vht;
5960 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005961 int max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005962 char *token, *context = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005963
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005964 while ((token = str_token(cmd, " ", &context))) {
5965 if (sscanf(token, "freq=%d", &freq) == 1 ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005966 sscanf(token, "freq2=%d", &freq2) == 1 ||
5967 sscanf(token, "persistent=%d", &group_id) == 1 ||
5968 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005969 continue;
5970 } else if (os_strcmp(token, "ht40") == 0) {
5971 ht40 = 1;
5972 } else if (os_strcmp(token, "vht") == 0) {
5973 vht = 1;
5974 ht40 = 1;
5975 } else if (os_strcmp(token, "persistent") == 0) {
5976 persistent = 1;
5977 } else {
5978 wpa_printf(MSG_DEBUG,
5979 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
5980 token);
5981 return -1;
5982 }
5983 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005984
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005985 max_oper_chwidth = parse_freq(chwidth, freq2);
5986 if (max_oper_chwidth < 0)
5987 return -1;
5988
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005989 if (group_id >= 0)
5990 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005991 freq, freq2, ht40, vht,
5992 max_oper_chwidth);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005993
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005994 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
5995 max_oper_chwidth);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005996}
5997
5998
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005999static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
6000 char *buf, size_t buflen)
6001{
6002 u8 dev_addr[ETH_ALEN];
6003 struct wpa_ssid *ssid;
6004 int res;
6005 const u8 *iaddr;
6006
6007 ssid = wpa_s->current_ssid;
6008 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
6009 hwaddr_aton(cmd, dev_addr))
6010 return -1;
6011
6012 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
6013 if (!iaddr)
6014 return -1;
6015 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
6016 if (os_snprintf_error(buflen, res))
6017 return -1;
6018 return res;
6019}
6020
6021
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006022static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
6023 char *buf, size_t buflen)
6024{
6025 u8 addr[ETH_ALEN], *addr_ptr;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006026 int next, res;
6027 const struct p2p_peer_info *info;
6028 char *pos, *end;
6029 char devtype[WPS_DEV_TYPE_BUFSIZE];
6030 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006031 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006032
6033 if (!wpa_s->global->p2p)
6034 return -1;
6035
6036 if (os_strcmp(cmd, "FIRST") == 0) {
6037 addr_ptr = NULL;
6038 next = 0;
6039 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
6040 if (hwaddr_aton(cmd + 5, addr) < 0)
6041 return -1;
6042 addr_ptr = addr;
6043 next = 1;
6044 } else {
6045 if (hwaddr_aton(cmd, addr) < 0)
6046 return -1;
6047 addr_ptr = addr;
6048 next = 0;
6049 }
6050
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006051 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
6052 if (info == NULL)
6053 return -1;
6054
6055 pos = buf;
6056 end = buf + buflen;
6057
6058 res = os_snprintf(pos, end - pos, MACSTR "\n"
6059 "pri_dev_type=%s\n"
6060 "device_name=%s\n"
6061 "manufacturer=%s\n"
6062 "model_name=%s\n"
6063 "model_number=%s\n"
6064 "serial_number=%s\n"
6065 "config_methods=0x%x\n"
6066 "dev_capab=0x%x\n"
6067 "group_capab=0x%x\n"
6068 "level=%d\n",
6069 MAC2STR(info->p2p_device_addr),
6070 wps_dev_type_bin2str(info->pri_dev_type,
6071 devtype, sizeof(devtype)),
6072 info->device_name,
6073 info->manufacturer,
6074 info->model_name,
6075 info->model_number,
6076 info->serial_number,
6077 info->config_methods,
6078 info->dev_capab,
6079 info->group_capab,
6080 info->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006081 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006082 return pos - buf;
6083 pos += res;
6084
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006085 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
6086 {
6087 const u8 *t;
6088 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
6089 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
6090 wps_dev_type_bin2str(t, devtype,
6091 sizeof(devtype)));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006092 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006093 return pos - buf;
6094 pos += res;
6095 }
6096
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006097 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006098 if (ssid) {
6099 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006100 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006101 return pos - buf;
6102 pos += res;
6103 }
6104
6105 res = p2p_get_peer_info_txt(info, pos, end - pos);
6106 if (res < 0)
6107 return pos - buf;
6108 pos += res;
6109
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006110 if (info->vendor_elems) {
6111 res = os_snprintf(pos, end - pos, "vendor_elems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006112 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006113 return pos - buf;
6114 pos += res;
6115
6116 pos += wpa_snprintf_hex(pos, end - pos,
6117 wpabuf_head(info->vendor_elems),
6118 wpabuf_len(info->vendor_elems));
6119
6120 res = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006121 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006122 return pos - buf;
6123 pos += res;
6124 }
6125
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006126 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006127}
6128
6129
Dmitry Shmidt04949592012-07-19 12:16:46 -07006130static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
6131 const char *param)
6132{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006133 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006134
6135 if (wpa_s->global->p2p == NULL)
6136 return -1;
6137
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006138 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
6139 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006140
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006141 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
6142 struct wpa_freq_range *freq;
6143 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07006144 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006145 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006146 }
6147
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006148 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006149 return 0;
6150}
6151
6152
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006153static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
6154{
6155 char *param;
6156
6157 if (wpa_s->global->p2p == NULL)
6158 return -1;
6159
6160 param = os_strchr(cmd, ' ');
6161 if (param == NULL)
6162 return -1;
6163 *param++ = '\0';
6164
6165 if (os_strcmp(cmd, "discoverability") == 0) {
6166 p2p_set_client_discoverability(wpa_s->global->p2p,
6167 atoi(param));
6168 return 0;
6169 }
6170
6171 if (os_strcmp(cmd, "managed") == 0) {
6172 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
6173 return 0;
6174 }
6175
6176 if (os_strcmp(cmd, "listen_channel") == 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08006177 char *pos;
6178 u8 channel, op_class;
6179
6180 channel = atoi(param);
6181 pos = os_strchr(param, ' ');
6182 op_class = pos ? atoi(pos) : 81;
6183
6184 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
6185 channel, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006186 }
6187
6188 if (os_strcmp(cmd, "ssid_postfix") == 0) {
6189 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
6190 os_strlen(param));
6191 }
6192
6193 if (os_strcmp(cmd, "noa") == 0) {
6194 char *pos;
6195 int count, start, duration;
6196 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6197 count = atoi(param);
6198 pos = os_strchr(param, ',');
6199 if (pos == NULL)
6200 return -1;
6201 pos++;
6202 start = atoi(pos);
6203 pos = os_strchr(pos, ',');
6204 if (pos == NULL)
6205 return -1;
6206 pos++;
6207 duration = atoi(pos);
6208 if (count < 0 || count > 255 || start < 0 || duration < 0)
6209 return -1;
6210 if (count == 0 && duration > 0)
6211 return -1;
6212 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6213 "start=%d duration=%d", count, start, duration);
6214 return wpas_p2p_set_noa(wpa_s, count, start, duration);
6215 }
6216
6217 if (os_strcmp(cmd, "ps") == 0)
6218 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
6219
6220 if (os_strcmp(cmd, "oppps") == 0)
6221 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
6222
6223 if (os_strcmp(cmd, "ctwindow") == 0)
6224 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
6225
6226 if (os_strcmp(cmd, "disabled") == 0) {
6227 wpa_s->global->p2p_disabled = atoi(param);
6228 wpa_printf(MSG_DEBUG, "P2P functionality %s",
6229 wpa_s->global->p2p_disabled ?
6230 "disabled" : "enabled");
6231 if (wpa_s->global->p2p_disabled) {
6232 wpas_p2p_stop_find(wpa_s);
6233 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6234 p2p_flush(wpa_s->global->p2p);
6235 }
6236 return 0;
6237 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006238
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006239 if (os_strcmp(cmd, "conc_pref") == 0) {
6240 if (os_strcmp(param, "sta") == 0)
6241 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
6242 else if (os_strcmp(param, "p2p") == 0)
6243 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006244 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006245 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006246 return -1;
6247 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006248 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07006249 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006250 return 0;
6251 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006252
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006253 if (os_strcmp(cmd, "force_long_sd") == 0) {
6254 wpa_s->force_long_sd = atoi(param);
6255 return 0;
6256 }
6257
6258 if (os_strcmp(cmd, "peer_filter") == 0) {
6259 u8 addr[ETH_ALEN];
6260 if (hwaddr_aton(param, addr))
6261 return -1;
6262 p2p_set_peer_filter(wpa_s->global->p2p, addr);
6263 return 0;
6264 }
6265
6266 if (os_strcmp(cmd, "cross_connect") == 0)
6267 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
6268
6269 if (os_strcmp(cmd, "go_apsd") == 0) {
6270 if (os_strcmp(param, "disable") == 0)
6271 wpa_s->set_ap_uapsd = 0;
6272 else {
6273 wpa_s->set_ap_uapsd = 1;
6274 wpa_s->ap_uapsd = atoi(param);
6275 }
6276 return 0;
6277 }
6278
6279 if (os_strcmp(cmd, "client_apsd") == 0) {
6280 if (os_strcmp(param, "disable") == 0)
6281 wpa_s->set_sta_uapsd = 0;
6282 else {
6283 int be, bk, vi, vo;
6284 char *pos;
6285 /* format: BE,BK,VI,VO;max SP Length */
6286 be = atoi(param);
6287 pos = os_strchr(param, ',');
6288 if (pos == NULL)
6289 return -1;
6290 pos++;
6291 bk = atoi(pos);
6292 pos = os_strchr(pos, ',');
6293 if (pos == NULL)
6294 return -1;
6295 pos++;
6296 vi = atoi(pos);
6297 pos = os_strchr(pos, ',');
6298 if (pos == NULL)
6299 return -1;
6300 pos++;
6301 vo = atoi(pos);
6302 /* ignore max SP Length for now */
6303
6304 wpa_s->set_sta_uapsd = 1;
6305 wpa_s->sta_uapsd = 0;
6306 if (be)
6307 wpa_s->sta_uapsd |= BIT(0);
6308 if (bk)
6309 wpa_s->sta_uapsd |= BIT(1);
6310 if (vi)
6311 wpa_s->sta_uapsd |= BIT(2);
6312 if (vo)
6313 wpa_s->sta_uapsd |= BIT(3);
6314 }
6315 return 0;
6316 }
6317
Dmitry Shmidt04949592012-07-19 12:16:46 -07006318 if (os_strcmp(cmd, "disallow_freq") == 0)
6319 return p2p_ctrl_disallow_freq(wpa_s, param);
6320
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006321 if (os_strcmp(cmd, "disc_int") == 0) {
6322 int min_disc_int, max_disc_int, max_disc_tu;
6323 char *pos;
6324
6325 pos = param;
6326
6327 min_disc_int = atoi(pos);
6328 pos = os_strchr(pos, ' ');
6329 if (pos == NULL)
6330 return -1;
6331 *pos++ = '\0';
6332
6333 max_disc_int = atoi(pos);
6334 pos = os_strchr(pos, ' ');
6335 if (pos == NULL)
6336 return -1;
6337 *pos++ = '\0';
6338
6339 max_disc_tu = atoi(pos);
6340
6341 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
6342 max_disc_int, max_disc_tu);
6343 }
6344
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07006345 if (os_strcmp(cmd, "per_sta_psk") == 0) {
6346 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
6347 return 0;
6348 }
6349
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006350#ifdef CONFIG_WPS_NFC
6351 if (os_strcmp(cmd, "nfc_tag") == 0)
6352 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
6353#endif /* CONFIG_WPS_NFC */
6354
6355 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
6356 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
6357 return 0;
6358 }
6359
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006360 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6361 cmd);
6362
6363 return -1;
6364}
6365
6366
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006367static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
6368{
6369 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6370 wpa_s->force_long_sd = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006371 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006372 wpa_s->parent->p2ps_method_config_any = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006373 if (wpa_s->global->p2p)
6374 p2p_flush(wpa_s->global->p2p);
6375}
6376
6377
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006378static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
6379{
6380 char *pos, *pos2;
6381 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
6382
6383 if (cmd[0]) {
6384 pos = os_strchr(cmd, ' ');
6385 if (pos == NULL)
6386 return -1;
6387 *pos++ = '\0';
6388 dur1 = atoi(cmd);
6389
6390 pos2 = os_strchr(pos, ' ');
6391 if (pos2)
6392 *pos2++ = '\0';
6393 int1 = atoi(pos);
6394 } else
6395 pos2 = NULL;
6396
6397 if (pos2) {
6398 pos = os_strchr(pos2, ' ');
6399 if (pos == NULL)
6400 return -1;
6401 *pos++ = '\0';
6402 dur2 = atoi(pos2);
6403 int2 = atoi(pos);
6404 }
6405
6406 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
6407}
6408
6409
6410static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
6411{
6412 char *pos;
6413 unsigned int period = 0, interval = 0;
6414
6415 if (cmd[0]) {
6416 pos = os_strchr(cmd, ' ');
6417 if (pos == NULL)
6418 return -1;
6419 *pos++ = '\0';
6420 period = atoi(cmd);
6421 interval = atoi(pos);
6422 }
6423
6424 return wpas_p2p_ext_listen(wpa_s, period, interval);
6425}
6426
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07006427
6428static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
6429{
6430 const char *pos;
6431 u8 peer[ETH_ALEN];
6432 int iface_addr = 0;
6433
6434 pos = cmd;
6435 if (os_strncmp(pos, "iface=", 6) == 0) {
6436 iface_addr = 1;
6437 pos += 6;
6438 }
6439 if (hwaddr_aton(pos, peer))
6440 return -1;
6441
6442 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
6443 return 0;
6444}
6445
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006446
6447static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
6448{
6449 int freq = 0, period = 0, interval = 0, count = 0;
6450
6451 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
6452 {
6453 wpa_printf(MSG_DEBUG,
6454 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
6455 return -1;
6456 }
6457
6458 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
6459}
6460
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006461#endif /* CONFIG_P2P */
6462
6463
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006464static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
6465{
6466 struct wpa_freq_range_list ranges;
6467 int *freqs = NULL;
6468 struct hostapd_hw_modes *mode;
6469 u16 i;
6470
6471 if (wpa_s->hw.modes == NULL)
6472 return NULL;
6473
6474 os_memset(&ranges, 0, sizeof(ranges));
6475 if (freq_range_list_parse(&ranges, val) < 0)
6476 return NULL;
6477
6478 for (i = 0; i < wpa_s->hw.num_modes; i++) {
6479 int j;
6480
6481 mode = &wpa_s->hw.modes[i];
6482 for (j = 0; j < mode->num_channels; j++) {
6483 unsigned int freq;
6484
6485 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
6486 continue;
6487
6488 freq = mode->channels[j].freq;
6489 if (!freq_range_list_includes(&ranges, freq))
6490 continue;
6491
6492 int_array_add_unique(&freqs, freq);
6493 }
6494 }
6495
6496 os_free(ranges.range);
6497 return freqs;
6498}
6499
6500
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006501#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006502
6503static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
6504{
6505 int auto_sel = 0;
6506 int *freqs = NULL;
6507
6508 if (param) {
6509 char *pos;
6510
6511 auto_sel = os_strstr(param, "auto") != NULL;
6512
6513 pos = os_strstr(param, "freq=");
6514 if (pos) {
6515 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
6516 if (freqs == NULL)
6517 return -1;
6518 }
6519
6520 }
6521
6522 return interworking_select(wpa_s, auto_sel, freqs);
6523}
6524
6525
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006526static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
6527 int only_add)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006528{
6529 u8 bssid[ETH_ALEN];
6530 struct wpa_bss *bss;
6531
6532 if (hwaddr_aton(dst, bssid)) {
6533 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
6534 return -1;
6535 }
6536
6537 bss = wpa_bss_get_bssid(wpa_s, bssid);
6538 if (bss == NULL) {
6539 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
6540 MAC2STR(bssid));
6541 return -1;
6542 }
6543
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08006544 if (bss->ssid_len == 0) {
6545 int found = 0;
6546
6547 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
6548 " does not have SSID information", MAC2STR(bssid));
6549
6550 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
6551 list) {
6552 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
6553 bss->ssid_len > 0) {
6554 found = 1;
6555 break;
6556 }
6557 }
6558
6559 if (!found)
6560 return -1;
6561 wpa_printf(MSG_DEBUG,
6562 "Found another matching BSS entry with SSID");
6563 }
6564
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006565 return interworking_connect(wpa_s, bss, only_add);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006566}
6567
6568
6569static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
6570{
6571 u8 dst_addr[ETH_ALEN];
6572 int used;
6573 char *pos;
6574#define MAX_ANQP_INFO_ID 100
6575 u16 id[MAX_ANQP_INFO_ID];
6576 size_t num_id = 0;
Dmitry Shmidt15907092014-03-25 10:42:57 -07006577 u32 subtypes = 0;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006578 int get_cell_pref = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006579
6580 used = hwaddr_aton2(dst, dst_addr);
6581 if (used < 0)
6582 return -1;
6583 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006584 if (*pos == ' ')
6585 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006586 while (num_id < MAX_ANQP_INFO_ID) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07006587 if (os_strncmp(pos, "hs20:", 5) == 0) {
6588#ifdef CONFIG_HS20
6589 int num = atoi(pos + 5);
6590 if (num <= 0 || num > 31)
6591 return -1;
6592 subtypes |= BIT(num);
6593#else /* CONFIG_HS20 */
6594 return -1;
6595#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006596 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
6597#ifdef CONFIG_MBO
6598 int num = atoi(pos + 4);
6599 if (num != MBO_ANQP_SUBTYPE_CELL_CONN_PREF)
6600 return -1;
6601 get_cell_pref = 1;
6602#else /* CONFIG_MBO */
6603 return -1;
6604#endif /* CONFIG_MBO */
Dmitry Shmidt15907092014-03-25 10:42:57 -07006605 } else {
6606 id[num_id] = atoi(pos);
6607 if (id[num_id])
6608 num_id++;
6609 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006610 pos = os_strchr(pos + 1, ',');
6611 if (pos == NULL)
6612 break;
6613 pos++;
6614 }
6615
6616 if (num_id == 0)
6617 return -1;
6618
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006619 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes,
6620 get_cell_pref);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006621}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006622
6623
6624static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
6625{
6626 u8 dst_addr[ETH_ALEN];
6627 struct wpabuf *advproto, *query = NULL;
6628 int used, ret = -1;
6629 char *pos, *end;
6630 size_t len;
6631
6632 used = hwaddr_aton2(cmd, dst_addr);
6633 if (used < 0)
6634 return -1;
6635
6636 pos = cmd + used;
6637 while (*pos == ' ')
6638 pos++;
6639
6640 /* Advertisement Protocol ID */
6641 end = os_strchr(pos, ' ');
6642 if (end)
6643 len = end - pos;
6644 else
6645 len = os_strlen(pos);
6646 if (len & 0x01)
6647 return -1;
6648 len /= 2;
6649 if (len == 0)
6650 return -1;
6651 advproto = wpabuf_alloc(len);
6652 if (advproto == NULL)
6653 return -1;
6654 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
6655 goto fail;
6656
6657 if (end) {
6658 /* Optional Query Request */
6659 pos = end + 1;
6660 while (*pos == ' ')
6661 pos++;
6662
6663 len = os_strlen(pos);
6664 if (len) {
6665 if (len & 0x01)
6666 goto fail;
6667 len /= 2;
6668 if (len == 0)
6669 goto fail;
6670 query = wpabuf_alloc(len);
6671 if (query == NULL)
6672 goto fail;
6673 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
6674 goto fail;
6675 }
6676 }
6677
6678 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
6679
6680fail:
6681 wpabuf_free(advproto);
6682 wpabuf_free(query);
6683
6684 return ret;
6685}
6686
6687
6688static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
6689 size_t buflen)
6690{
6691 u8 addr[ETH_ALEN];
6692 int dialog_token;
6693 int used;
6694 char *pos;
6695 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006696 struct wpabuf *resp;
6697 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006698
6699 used = hwaddr_aton2(cmd, addr);
6700 if (used < 0)
6701 return -1;
6702
6703 pos = cmd + used;
6704 while (*pos == ' ')
6705 pos++;
6706 dialog_token = atoi(pos);
6707
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006708 if (wpa_s->last_gas_resp &&
6709 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
6710 dialog_token == wpa_s->last_gas_dialog_token)
6711 resp = wpa_s->last_gas_resp;
6712 else if (wpa_s->prev_gas_resp &&
6713 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
6714 dialog_token == wpa_s->prev_gas_dialog_token)
6715 resp = wpa_s->prev_gas_resp;
6716 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006717 return -1;
6718
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006719 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006720 start = 0;
6721 requested_len = resp_len;
6722
6723 pos = os_strchr(pos, ' ');
6724 if (pos) {
6725 start = atoi(pos);
6726 if (start > resp_len)
6727 return os_snprintf(buf, buflen, "FAIL-Invalid range");
6728 pos = os_strchr(pos, ',');
6729 if (pos == NULL)
6730 return -1;
6731 pos++;
6732 requested_len = atoi(pos);
6733 if (start + requested_len > resp_len)
6734 return os_snprintf(buf, buflen, "FAIL-Invalid range");
6735 }
6736
6737 if (requested_len * 2 + 1 > buflen)
6738 return os_snprintf(buf, buflen, "FAIL-Too long response");
6739
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006740 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
6741 requested_len);
6742
6743 if (start + requested_len == resp_len) {
6744 /*
6745 * Free memory by dropping the response after it has been
6746 * fetched.
6747 */
6748 if (resp == wpa_s->prev_gas_resp) {
6749 wpabuf_free(wpa_s->prev_gas_resp);
6750 wpa_s->prev_gas_resp = NULL;
6751 } else {
6752 wpabuf_free(wpa_s->last_gas_resp);
6753 wpa_s->last_gas_resp = NULL;
6754 }
6755 }
6756
6757 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006758}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006759#endif /* CONFIG_INTERWORKING */
6760
6761
Dmitry Shmidt04949592012-07-19 12:16:46 -07006762#ifdef CONFIG_HS20
6763
6764static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
6765{
6766 u8 dst_addr[ETH_ALEN];
6767 int used;
6768 char *pos;
6769 u32 subtypes = 0;
6770
6771 used = hwaddr_aton2(dst, dst_addr);
6772 if (used < 0)
6773 return -1;
6774 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006775 if (*pos == ' ')
6776 pos++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006777 for (;;) {
6778 int num = atoi(pos);
6779 if (num <= 0 || num > 31)
6780 return -1;
6781 subtypes |= BIT(num);
6782 pos = os_strchr(pos + 1, ',');
6783 if (pos == NULL)
6784 break;
6785 pos++;
6786 }
6787
6788 if (subtypes == 0)
6789 return -1;
6790
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08006791 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006792}
6793
6794
6795static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
6796 const u8 *addr, const char *realm)
6797{
6798 u8 *buf;
6799 size_t rlen, len;
6800 int ret;
6801
6802 rlen = os_strlen(realm);
6803 len = 3 + rlen;
6804 buf = os_malloc(len);
6805 if (buf == NULL)
6806 return -1;
6807 buf[0] = 1; /* NAI Home Realm Count */
6808 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
6809 buf[2] = rlen;
6810 os_memcpy(buf + 3, realm, rlen);
6811
6812 ret = hs20_anqp_send_req(wpa_s, addr,
6813 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08006814 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006815
6816 os_free(buf);
6817
6818 return ret;
6819}
6820
6821
6822static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
6823 char *dst)
6824{
6825 struct wpa_cred *cred = wpa_s->conf->cred;
6826 u8 dst_addr[ETH_ALEN];
6827 int used;
6828 u8 *buf;
6829 size_t len;
6830 int ret;
6831
6832 used = hwaddr_aton2(dst, dst_addr);
6833 if (used < 0)
6834 return -1;
6835
6836 while (dst[used] == ' ')
6837 used++;
6838 if (os_strncmp(dst + used, "realm=", 6) == 0)
6839 return hs20_nai_home_realm_list(wpa_s, dst_addr,
6840 dst + used + 6);
6841
6842 len = os_strlen(dst + used);
6843
6844 if (len == 0 && cred && cred->realm)
6845 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
6846
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07006847 if (len & 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07006848 return -1;
6849 len /= 2;
6850 buf = os_malloc(len);
6851 if (buf == NULL)
6852 return -1;
6853 if (hexstr2bin(dst + used, buf, len) < 0) {
6854 os_free(buf);
6855 return -1;
6856 }
6857
6858 ret = hs20_anqp_send_req(wpa_s, dst_addr,
6859 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08006860 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006861 os_free(buf);
6862
6863 return ret;
6864}
6865
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08006866
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08006867static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
6868 int buflen)
6869{
6870 u8 dst_addr[ETH_ALEN];
6871 int used;
6872 char *ctx = NULL, *icon, *poffset, *psize;
6873
6874 used = hwaddr_aton2(cmd, dst_addr);
6875 if (used < 0)
6876 return -1;
6877 cmd += used;
6878
6879 icon = str_token(cmd, " ", &ctx);
6880 poffset = str_token(cmd, " ", &ctx);
6881 psize = str_token(cmd, " ", &ctx);
6882 if (!icon || !poffset || !psize)
6883 return -1;
6884
6885 wpa_s->fetch_osu_icon_in_progress = 0;
6886 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
6887 reply, buflen);
6888}
6889
6890
6891static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
6892{
6893 u8 dst_addr[ETH_ALEN];
6894 int used;
6895 char *icon;
6896
6897 if (!cmd[0])
6898 return hs20_del_icon(wpa_s, NULL, NULL);
6899
6900 used = hwaddr_aton2(cmd, dst_addr);
6901 if (used < 0)
6902 return -1;
6903
6904 while (cmd[used] == ' ')
6905 used++;
6906 icon = cmd[used] ? &cmd[used] : NULL;
6907
6908 return hs20_del_icon(wpa_s, dst_addr, icon);
6909}
6910
6911
6912static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08006913{
6914 u8 dst_addr[ETH_ALEN];
6915 int used;
6916 char *icon;
6917
6918 used = hwaddr_aton2(cmd, dst_addr);
6919 if (used < 0)
6920 return -1;
6921
6922 while (cmd[used] == ' ')
6923 used++;
6924 icon = &cmd[used];
6925
6926 wpa_s->fetch_osu_icon_in_progress = 0;
6927 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08006928 (u8 *) icon, os_strlen(icon), inmem);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08006929}
6930
Dmitry Shmidt04949592012-07-19 12:16:46 -07006931#endif /* CONFIG_HS20 */
6932
6933
Dmitry Shmidt04949592012-07-19 12:16:46 -07006934#ifdef CONFIG_AUTOSCAN
6935
6936static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
6937 char *cmd)
6938{
6939 enum wpa_states state = wpa_s->wpa_state;
6940 char *new_params = NULL;
6941
6942 if (os_strlen(cmd) > 0) {
6943 new_params = os_strdup(cmd);
6944 if (new_params == NULL)
6945 return -1;
6946 }
6947
6948 os_free(wpa_s->conf->autoscan);
6949 wpa_s->conf->autoscan = new_params;
6950
6951 if (wpa_s->conf->autoscan == NULL)
6952 autoscan_deinit(wpa_s);
6953 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
6954 autoscan_init(wpa_s, 1);
6955 else if (state == WPA_SCANNING)
6956 wpa_supplicant_reinit_autoscan(wpa_s);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006957 else
6958 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
6959 wpa_supplicant_state_txt(state));
Dmitry Shmidt04949592012-07-19 12:16:46 -07006960
6961 return 0;
6962}
6963
6964#endif /* CONFIG_AUTOSCAN */
6965
6966
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006967#ifdef CONFIG_WNM
6968
6969static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
6970{
6971 int enter;
6972 int intval = 0;
6973 char *pos;
6974 int ret;
6975 struct wpabuf *tfs_req = NULL;
6976
6977 if (os_strncmp(cmd, "enter", 5) == 0)
6978 enter = 1;
6979 else if (os_strncmp(cmd, "exit", 4) == 0)
6980 enter = 0;
6981 else
6982 return -1;
6983
6984 pos = os_strstr(cmd, " interval=");
6985 if (pos)
6986 intval = atoi(pos + 10);
6987
6988 pos = os_strstr(cmd, " tfs_req=");
6989 if (pos) {
6990 char *end;
6991 size_t len;
6992 pos += 9;
6993 end = os_strchr(pos, ' ');
6994 if (end)
6995 len = end - pos;
6996 else
6997 len = os_strlen(pos);
6998 if (len & 1)
6999 return -1;
7000 len /= 2;
7001 tfs_req = wpabuf_alloc(len);
7002 if (tfs_req == NULL)
7003 return -1;
7004 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
7005 wpabuf_free(tfs_req);
7006 return -1;
7007 }
7008 }
7009
7010 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
7011 WNM_SLEEP_MODE_EXIT, intval,
7012 tfs_req);
7013 wpabuf_free(tfs_req);
7014
7015 return ret;
7016}
7017
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007018
7019static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
7020{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007021 int query_reason, list = 0;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007022
7023 query_reason = atoi(cmd);
7024
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007025 cmd = os_strchr(cmd, ' ');
7026 if (cmd) {
7027 cmd++;
7028 if (os_strncmp(cmd, "list", 4) == 0) {
7029 list = 1;
7030 } else {
7031 wpa_printf(MSG_DEBUG, "WNM Query: Invalid option %s",
7032 cmd);
7033 return -1;
7034 }
7035 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007036
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007037 wpa_printf(MSG_DEBUG,
7038 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7039 query_reason, list ? " candidate list" : "");
7040
7041 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason, list);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007042}
7043
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007044#endif /* CONFIG_WNM */
7045
7046
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007047static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
7048 size_t buflen)
7049{
7050 struct wpa_signal_info si;
7051 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007052 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007053
7054 ret = wpa_drv_signal_poll(wpa_s, &si);
7055 if (ret)
7056 return -1;
7057
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007058 pos = buf;
7059 end = buf + buflen;
7060
7061 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007062 "NOISE=%d\nFREQUENCY=%u\n",
7063 si.current_signal, si.current_txrate / 1000,
7064 si.current_noise, si.frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007065 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007066 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007067 pos += ret;
7068
7069 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
7070 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007071 channel_width_to_string(si.chanwidth));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007072 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007073 return -1;
7074 pos += ret;
7075 }
7076
7077 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
7078 ret = os_snprintf(pos, end - pos,
7079 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
7080 si.center_frq1, si.center_frq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007081 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007082 return -1;
7083 pos += ret;
7084 }
7085
7086 if (si.avg_signal) {
7087 ret = os_snprintf(pos, end - pos,
7088 "AVG_RSSI=%d\n", si.avg_signal);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007089 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007090 return -1;
7091 pos += ret;
7092 }
7093
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07007094 if (si.avg_beacon_signal) {
7095 ret = os_snprintf(pos, end - pos,
7096 "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
7097 if (os_snprintf_error(end - pos, ret))
7098 return -1;
7099 pos += ret;
7100 }
7101
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007102 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007103}
7104
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03007105
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007106static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
7107 const char *cmd)
7108{
7109 const char *pos;
7110 int threshold = 0;
7111 int hysteresis = 0;
7112
7113 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
7114 wpa_printf(MSG_DEBUG,
7115 "Reject SIGNAL_MONITOR command - bgscan is active");
7116 return -1;
7117 }
7118 pos = os_strstr(cmd, "THRESHOLD=");
7119 if (pos)
7120 threshold = atoi(pos + 10);
7121 pos = os_strstr(cmd, "HYSTERESIS=");
7122 if (pos)
7123 hysteresis = atoi(pos + 11);
7124 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
7125}
7126
7127
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007128static int wpas_ctrl_iface_get_pref_freq_list(
7129 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
7130{
7131 unsigned int freq_list[100], num = 100, i;
7132 int ret;
7133 enum wpa_driver_if_type iface_type;
7134 char *pos, *end;
7135
7136 pos = buf;
7137 end = buf + buflen;
7138
7139 /* buf: "<interface_type>" */
7140 if (os_strcmp(cmd, "STATION") == 0)
7141 iface_type = WPA_IF_STATION;
7142 else if (os_strcmp(cmd, "AP") == 0)
7143 iface_type = WPA_IF_AP_BSS;
7144 else if (os_strcmp(cmd, "P2P_GO") == 0)
7145 iface_type = WPA_IF_P2P_GO;
7146 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
7147 iface_type = WPA_IF_P2P_CLIENT;
7148 else if (os_strcmp(cmd, "IBSS") == 0)
7149 iface_type = WPA_IF_IBSS;
7150 else if (os_strcmp(cmd, "TDLS") == 0)
7151 iface_type = WPA_IF_TDLS;
7152 else
7153 return -1;
7154
7155 wpa_printf(MSG_DEBUG,
7156 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7157 iface_type, buf);
7158
7159 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
7160 if (ret)
7161 return -1;
7162
7163 for (i = 0; i < num; i++) {
7164 ret = os_snprintf(pos, end - pos, "%s%u",
7165 i > 0 ? "," : "", freq_list[i]);
7166 if (os_snprintf_error(end - pos, ret))
7167 return -1;
7168 pos += ret;
7169 }
7170
7171 return pos - buf;
7172}
7173
7174
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007175static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
7176 char *buf, size_t buflen)
7177{
7178 int ret, i;
7179 char *pos, *end;
7180
7181 ret = os_snprintf(buf, buflen, "%016llX:\n",
7182 (long long unsigned) wpa_s->drv_flags);
7183 if (os_snprintf_error(buflen, ret))
7184 return -1;
7185
7186 pos = buf + ret;
7187 end = buf + buflen;
7188
7189 for (i = 0; i < 64; i++) {
7190 if (wpa_s->drv_flags & (1LLU << i)) {
7191 ret = os_snprintf(pos, end - pos, "%s\n",
7192 driver_flag_to_string(1LLU << i));
7193 if (os_snprintf_error(end - pos, ret))
7194 return -1;
7195 pos += ret;
7196 }
7197 }
7198
7199 return pos - buf;
7200}
7201
7202
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07007203static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
7204 size_t buflen)
7205{
7206 struct hostap_sta_driver_data sta;
7207 int ret;
7208
7209 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
7210 if (ret)
7211 return -1;
7212
7213 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03007214 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007215 if (os_snprintf_error(buflen, ret))
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07007216 return -1;
7217 return ret;
7218}
7219
7220
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007221#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07007222static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
7223 char *buf, size_t buflen)
7224{
7225 int ret;
7226
7227 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07007228 if (ret == 0) {
7229 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
7230 struct p2p_data *p2p = wpa_s->global->p2p;
7231 if (p2p) {
7232 char country[3];
7233 country[0] = cmd[8];
7234 country[1] = cmd[9];
7235 country[2] = 0x04;
7236 p2p_set_country(p2p, country);
7237 }
7238 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007239 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007240 if (os_snprintf_error(buflen, ret))
7241 ret = -1;
Dmitry Shmidt9432e122013-09-12 12:39:30 -07007242 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07007243 return ret;
7244}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007245#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07007246
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07007247
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007248static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
7249 char *buf, size_t buflen)
7250{
7251 int ret;
7252 char *pos;
7253 u8 *data = NULL;
7254 unsigned int vendor_id, subcmd;
7255 struct wpabuf *reply;
7256 size_t data_len = 0;
7257
7258 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7259 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007260 if (!isblank((unsigned char) *pos))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007261 return -EINVAL;
7262
7263 subcmd = strtoul(pos, &pos, 10);
7264
7265 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007266 if (!isblank((unsigned char) *pos++))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007267 return -EINVAL;
7268 data_len = os_strlen(pos);
7269 }
7270
7271 if (data_len) {
7272 data_len /= 2;
7273 data = os_malloc(data_len);
7274 if (!data)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007275 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007276
7277 if (hexstr2bin(pos, data, data_len)) {
7278 wpa_printf(MSG_DEBUG,
7279 "Vendor command: wrong parameter format");
7280 os_free(data);
7281 return -EINVAL;
7282 }
7283 }
7284
7285 reply = wpabuf_alloc((buflen - 1) / 2);
7286 if (!reply) {
7287 os_free(data);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007288 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007289 }
7290
7291 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
7292 reply);
7293
7294 if (ret == 0)
7295 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
7296 wpabuf_len(reply));
7297
7298 wpabuf_free(reply);
7299 os_free(data);
7300
7301 return ret;
7302}
7303
7304
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007305static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
7306{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007307#ifdef CONFIG_P2P
7308 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
7309 wpa_s->global->p2p_init_wpa_s : wpa_s;
7310#endif /* CONFIG_P2P */
7311
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007312 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
7313
Dmitry Shmidt29333592017-01-09 12:27:11 -08007314 if (wpas_abort_ongoing_scan(wpa_s) == 0)
7315 wpa_s->ignore_post_flush_scan_res = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007316
Dmitry Shmidtde47be72016-01-07 12:52:55 -08007317 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
7318 /*
7319 * Avoid possible auto connect re-connection on getting
7320 * disconnected due to state flush.
7321 */
7322 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
7323 }
7324
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007325#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08007326 wpas_p2p_group_remove(p2p_wpa_s, "*");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007327 wpas_p2p_cancel(p2p_wpa_s);
7328 p2p_ctrl_flush(p2p_wpa_s);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007329 wpas_p2p_service_flush(p2p_wpa_s);
7330 p2p_wpa_s->global->p2p_disabled = 0;
7331 p2p_wpa_s->global->p2p_per_sta_psk = 0;
7332 p2p_wpa_s->conf->num_sec_device_types = 0;
7333 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
7334 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
7335 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007336 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08007337 p2p_wpa_s->global->pending_p2ps_group = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007338 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007339#endif /* CONFIG_P2P */
7340
7341#ifdef CONFIG_WPS_TESTING
7342 wps_version_number = 0x20;
7343 wps_testing_dummy_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007344 wps_corrupt_pkhash = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08007345 wps_force_auth_types_in_use = 0;
7346 wps_force_encr_types_in_use = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007347#endif /* CONFIG_WPS_TESTING */
7348#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007349 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007350 wpas_wps_cancel(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007351 wps_registrar_flush(wpa_s->wps->registrar);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007352#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07007353 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007354 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007355
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007356#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007357#ifdef CONFIG_TDLS_TESTING
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007358 tdls_testing = 0;
7359#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007360 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
7361 wpa_tdls_enable(wpa_s->wpa, 1);
7362#endif /* CONFIG_TDLS */
7363
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07007364 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
7365 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
7366
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007367 wpa_s->no_keep_alive = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08007368 wpa_s->own_disconnect_req = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007369
7370 os_free(wpa_s->disallow_aps_bssid);
7371 wpa_s->disallow_aps_bssid = NULL;
7372 wpa_s->disallow_aps_bssid_count = 0;
7373 os_free(wpa_s->disallow_aps_ssid);
7374 wpa_s->disallow_aps_ssid = NULL;
7375 wpa_s->disallow_aps_ssid_count = 0;
7376
7377 wpa_s->set_sta_uapsd = 0;
7378 wpa_s->sta_uapsd = 0;
7379
7380 wpa_drv_radio_disable(wpa_s, 0);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007381 wpa_blacklist_clear(wpa_s);
Dmitry Shmidt4b060592013-04-29 16:42:49 -07007382 wpa_s->extra_blacklist_count = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007383 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
7384 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08007385 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08007386 wpa_s->conf->auto_interworking = 0;
7387 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007388
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007389 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
7390 rsn_preauth_deinit(wpa_s->wpa);
7391
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007392 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
7393 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
7394 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
7395 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
7396
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08007397 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007398 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007399
7400 wpa_s->next_ssid = NULL;
7401
7402#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007403#ifdef CONFIG_HS20
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007404 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007405 hs20_del_icon(wpa_s, NULL, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007406#endif /* CONFIG_HS20 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007407#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt818ea482014-03-10 13:15:21 -07007408
7409 wpa_s->ext_mgmt_frame_handling = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007410 wpa_s->ext_eapol_frame_io = 0;
7411#ifdef CONFIG_TESTING_OPTIONS
7412 wpa_s->extra_roc_dur = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007413 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007414 wpa_s->p2p_go_csa_on_inv = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07007415 wpa_s->ignore_auth_resp = 0;
7416 wpa_s->ignore_assoc_disallow = 0;
7417 wpa_s->reject_btm_req_reason = 0;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08007418 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007419#endif /* CONFIG_TESTING_OPTIONS */
7420
7421 wpa_s->disconnected = 0;
7422 os_free(wpa_s->next_scan_freqs);
7423 wpa_s->next_scan_freqs = NULL;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007424
7425 wpa_bss_flush(wpa_s);
7426 if (!dl_list_empty(&wpa_s->bss)) {
7427 wpa_printf(MSG_DEBUG,
7428 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7429 MACSTR " pending_bssid=" MACSTR,
7430 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
7431 MAC2STR(wpa_s->bssid),
7432 MAC2STR(wpa_s->pending_bssid));
7433 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07007434
7435 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -08007436 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007437
7438#ifdef CONFIG_SME
7439 wpa_s->sme.last_unprot_disconnect.sec = 0;
7440#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007441}
7442
7443
7444static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
7445 char *buf, size_t buflen)
7446{
7447 struct wpa_radio_work *work;
7448 char *pos, *end;
7449 struct os_reltime now, diff;
7450
7451 pos = buf;
7452 end = buf + buflen;
7453
7454 os_get_reltime(&now);
7455
7456 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
7457 {
7458 int ret;
7459
7460 os_reltime_sub(&now, &work->time, &diff);
7461 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
7462 work->type, work->wpa_s->ifname, work->freq,
7463 work->started, diff.sec, diff.usec);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007464 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007465 break;
7466 pos += ret;
7467 }
7468
7469 return pos - buf;
7470}
7471
7472
7473static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
7474{
7475 struct wpa_radio_work *work = eloop_ctx;
7476 struct wpa_external_work *ework = work->ctx;
7477
7478 wpa_dbg(work->wpa_s, MSG_DEBUG,
7479 "Timing out external radio work %u (%s)",
7480 ework->id, work->type);
7481 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007482 work->wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007483 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07007484 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007485}
7486
7487
7488static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
7489{
7490 struct wpa_external_work *ework = work->ctx;
7491
7492 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08007493 if (work->started)
7494 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
7495 work, NULL);
7496
Dmitry Shmidt849734c2016-05-27 09:59:01 -07007497 /*
7498 * work->type points to a buffer in ework, so need to replace
7499 * that here with a fixed string to avoid use of freed memory
7500 * in debug prints.
7501 */
7502 work->type = "freed-ext-work";
7503 work->ctx = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007504 os_free(ework);
7505 return;
7506 }
7507
7508 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
7509 ework->id, ework->type);
7510 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007511 work->wpa_s->ext_work_in_progress = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007512 if (!ework->timeout)
7513 ework->timeout = 10;
7514 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
7515 work, NULL);
7516}
7517
7518
7519static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
7520 char *buf, size_t buflen)
7521{
7522 struct wpa_external_work *ework;
7523 char *pos, *pos2;
7524 size_t type_len;
7525 int ret;
7526 unsigned int freq = 0;
7527
7528 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
7529
7530 ework = os_zalloc(sizeof(*ework));
7531 if (ework == NULL)
7532 return -1;
7533
7534 pos = os_strchr(cmd, ' ');
7535 if (pos) {
7536 type_len = pos - cmd;
7537 pos++;
7538
7539 pos2 = os_strstr(pos, "freq=");
7540 if (pos2)
7541 freq = atoi(pos2 + 5);
7542
7543 pos2 = os_strstr(pos, "timeout=");
7544 if (pos2)
7545 ework->timeout = atoi(pos2 + 8);
7546 } else {
7547 type_len = os_strlen(cmd);
7548 }
7549 if (4 + type_len >= sizeof(ework->type))
7550 type_len = sizeof(ework->type) - 4 - 1;
7551 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
7552 os_memcpy(ework->type + 4, cmd, type_len);
7553 ework->type[4 + type_len] = '\0';
7554
7555 wpa_s->ext_work_id++;
7556 if (wpa_s->ext_work_id == 0)
7557 wpa_s->ext_work_id++;
7558 ework->id = wpa_s->ext_work_id;
7559
7560 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
7561 ework) < 0) {
7562 os_free(ework);
7563 return -1;
7564 }
7565
7566 ret = os_snprintf(buf, buflen, "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007567 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007568 return -1;
7569 return ret;
7570}
7571
7572
7573static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
7574{
7575 struct wpa_radio_work *work;
7576 unsigned int id = atoi(cmd);
7577
7578 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
7579 {
7580 struct wpa_external_work *ework;
7581
7582 if (os_strncmp(work->type, "ext:", 4) != 0)
7583 continue;
7584 ework = work->ctx;
7585 if (id && ework->id != id)
7586 continue;
7587 wpa_dbg(wpa_s, MSG_DEBUG,
7588 "Completed external radio work %u (%s)",
7589 ework->id, ework->type);
7590 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007591 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007592 radio_work_done(work);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07007593 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007594 return 3; /* "OK\n" */
7595 }
7596
7597 return -1;
7598}
7599
7600
7601static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
7602 char *buf, size_t buflen)
7603{
7604 if (os_strcmp(cmd, "show") == 0)
7605 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
7606 if (os_strncmp(cmd, "add ", 4) == 0)
7607 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
7608 if (os_strncmp(cmd, "done ", 5) == 0)
7609 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
7610 return -1;
7611}
7612
7613
7614void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
7615{
7616 struct wpa_radio_work *work, *tmp;
7617
Dmitry Shmidt18463232014-01-24 12:29:41 -08007618 if (!wpa_s || !wpa_s->radio)
7619 return;
7620
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007621 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
7622 struct wpa_radio_work, list) {
7623 struct wpa_external_work *ework;
7624
7625 if (os_strncmp(work->type, "ext:", 4) != 0)
7626 continue;
7627 ework = work->ctx;
7628 wpa_dbg(wpa_s, MSG_DEBUG,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07007629 "Flushing%s external radio work %u (%s)",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007630 work->started ? " started" : "", ework->id,
7631 ework->type);
7632 if (work->started)
7633 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
7634 work, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007635 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07007636 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007637 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007638}
7639
7640
Dmitry Shmidt051af732013-10-22 13:52:46 -07007641static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
7642{
7643 struct wpa_supplicant *wpa_s = eloop_ctx;
7644 eapol_sm_notify_ctrl_response(wpa_s->eapol);
7645}
7646
7647
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007648static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
7649 unsigned int *scan_id_count, int scan_id[])
Dmitry Shmidtc2817022014-07-02 10:32:10 -07007650{
7651 const char *pos = value;
7652
7653 while (pos) {
7654 if (*pos == ' ' || *pos == '\0')
7655 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007656 if (*scan_id_count == MAX_SCAN_ID)
Dmitry Shmidtc2817022014-07-02 10:32:10 -07007657 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007658 scan_id[(*scan_id_count)++] = atoi(pos);
Dmitry Shmidtc2817022014-07-02 10:32:10 -07007659 pos = os_strchr(pos, ',');
7660 if (pos)
7661 pos++;
7662 }
7663
7664 return 0;
7665}
7666
7667
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007668static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
7669 char *reply, int reply_size, int *reply_len)
7670{
7671 char *pos;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007672 unsigned int manual_scan_passive = 0;
7673 unsigned int manual_scan_use_id = 0;
7674 unsigned int manual_scan_only_new = 0;
7675 unsigned int scan_only = 0;
7676 unsigned int scan_id_count = 0;
7677 int scan_id[MAX_SCAN_ID];
7678 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
7679 struct wpa_scan_results *scan_res);
7680 int *manual_scan_freqs = NULL;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07007681 struct wpa_ssid_value *ssid = NULL, *ns;
7682 unsigned int ssid_count = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007683
7684 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
7685 *reply_len = -1;
7686 return;
7687 }
7688
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007689 if (radio_work_pending(wpa_s, "scan")) {
7690 wpa_printf(MSG_DEBUG,
7691 "Pending scan scheduled - reject new request");
7692 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
7693 return;
7694 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007695
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07007696#ifdef CONFIG_INTERWORKING
7697 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
7698 wpa_printf(MSG_DEBUG,
7699 "Interworking select in progress - reject new scan");
7700 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
7701 return;
7702 }
7703#endif /* CONFIG_INTERWORKING */
7704
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007705 if (params) {
7706 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007707 scan_only = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007708
7709 pos = os_strstr(params, "freq=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007710 if (pos) {
7711 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
7712 pos + 5);
7713 if (manual_scan_freqs == NULL) {
7714 *reply_len = -1;
7715 goto done;
7716 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007717 }
7718
7719 pos = os_strstr(params, "passive=");
7720 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007721 manual_scan_passive = !!atoi(pos + 8);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007722
7723 pos = os_strstr(params, "use_id=");
7724 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007725 manual_scan_use_id = atoi(pos + 7);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007726
7727 pos = os_strstr(params, "only_new=1");
7728 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007729 manual_scan_only_new = 1;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07007730
7731 pos = os_strstr(params, "scan_id=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007732 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
7733 scan_id) < 0) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07007734 *reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007735 goto done;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07007736 }
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07007737
7738 pos = params;
7739 while (pos && *pos != '\0') {
7740 if (os_strncmp(pos, "ssid ", 5) == 0) {
7741 char *end;
7742
7743 pos += 5;
7744 end = pos;
7745 while (*end) {
7746 if (*end == '\0' || *end == ' ')
7747 break;
7748 end++;
7749 }
7750
7751 ns = os_realloc_array(
7752 ssid, ssid_count + 1,
7753 sizeof(struct wpa_ssid_value));
7754 if (ns == NULL) {
7755 *reply_len = -1;
7756 goto done;
7757 }
7758 ssid = ns;
7759
7760 if ((end - pos) & 0x01 ||
7761 end - pos > 2 * SSID_MAX_LEN ||
7762 hexstr2bin(pos, ssid[ssid_count].ssid,
7763 (end - pos) / 2) < 0) {
7764 wpa_printf(MSG_DEBUG,
7765 "Invalid SSID value '%s'",
7766 pos);
7767 *reply_len = -1;
7768 goto done;
7769 }
7770 ssid[ssid_count].ssid_len = (end - pos) / 2;
7771 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
7772 ssid[ssid_count].ssid,
7773 ssid[ssid_count].ssid_len);
7774 ssid_count++;
7775 pos = end;
7776 }
7777
7778 pos = os_strchr(pos, ' ');
7779 if (pos)
7780 pos++;
7781 }
7782 }
7783
7784 wpa_s->num_ssids_from_scan_req = ssid_count;
7785 os_free(wpa_s->ssids_from_scan_req);
7786 if (ssid_count) {
7787 wpa_s->ssids_from_scan_req = ssid;
7788 ssid = NULL;
7789 } else {
7790 wpa_s->ssids_from_scan_req = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007791 }
7792
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007793 if (scan_only)
7794 scan_res_handler = scan_only_handler;
7795 else if (wpa_s->scan_res_handler == scan_only_handler)
7796 scan_res_handler = NULL;
7797 else
7798 scan_res_handler = wpa_s->scan_res_handler;
7799
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007800 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
7801 ((wpa_s->wpa_state <= WPA_SCANNING) ||
7802 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007803 wpa_s->manual_scan_passive = manual_scan_passive;
7804 wpa_s->manual_scan_use_id = manual_scan_use_id;
7805 wpa_s->manual_scan_only_new = manual_scan_only_new;
7806 wpa_s->scan_id_count = scan_id_count;
7807 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
7808 wpa_s->scan_res_handler = scan_res_handler;
7809 os_free(wpa_s->manual_scan_freqs);
7810 wpa_s->manual_scan_freqs = manual_scan_freqs;
7811 manual_scan_freqs = NULL;
7812
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007813 wpa_s->normal_scans = 0;
7814 wpa_s->scan_req = MANUAL_SCAN_REQ;
7815 wpa_s->after_wps = 0;
7816 wpa_s->known_wps_freq = 0;
7817 wpa_supplicant_req_scan(wpa_s, 0, 0);
7818 if (wpa_s->manual_scan_use_id) {
7819 wpa_s->manual_scan_id++;
7820 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
7821 wpa_s->manual_scan_id);
7822 *reply_len = os_snprintf(reply, reply_size, "%u\n",
7823 wpa_s->manual_scan_id);
7824 }
7825 } else if (wpa_s->sched_scanning) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007826 wpa_s->manual_scan_passive = manual_scan_passive;
7827 wpa_s->manual_scan_use_id = manual_scan_use_id;
7828 wpa_s->manual_scan_only_new = manual_scan_only_new;
7829 wpa_s->scan_id_count = scan_id_count;
7830 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
7831 wpa_s->scan_res_handler = scan_res_handler;
7832 os_free(wpa_s->manual_scan_freqs);
7833 wpa_s->manual_scan_freqs = manual_scan_freqs;
7834 manual_scan_freqs = NULL;
7835
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007836 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
7837 wpa_supplicant_cancel_sched_scan(wpa_s);
7838 wpa_s->scan_req = MANUAL_SCAN_REQ;
7839 wpa_supplicant_req_scan(wpa_s, 0, 0);
7840 if (wpa_s->manual_scan_use_id) {
7841 wpa_s->manual_scan_id++;
7842 *reply_len = os_snprintf(reply, reply_size, "%u\n",
7843 wpa_s->manual_scan_id);
7844 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
7845 wpa_s->manual_scan_id);
7846 }
7847 } else {
7848 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
7849 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
7850 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007851
7852done:
7853 os_free(manual_scan_freqs);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07007854 os_free(ssid);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007855}
7856
7857
Dmitry Shmidt818ea482014-03-10 13:15:21 -07007858#ifdef CONFIG_TESTING_OPTIONS
7859
7860static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
7861 unsigned int freq, const u8 *dst,
7862 const u8 *src, const u8 *bssid,
7863 const u8 *data, size_t data_len,
7864 enum offchannel_send_action_result
7865 result)
7866{
7867 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
7868 " src=" MACSTR " bssid=" MACSTR " result=%s",
7869 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
7870 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
7871 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
7872 "NO_ACK" : "FAILED"));
7873}
7874
7875
7876static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
7877{
7878 char *pos, *param;
7879 size_t len;
7880 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
7881 int res, used;
7882 int freq = 0, no_cck = 0, wait_time = 0;
7883
7884 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
7885 * <action=Action frame payload> */
7886
7887 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
7888
7889 pos = cmd;
7890 used = hwaddr_aton2(pos, da);
7891 if (used < 0)
7892 return -1;
7893 pos += used;
7894 while (*pos == ' ')
7895 pos++;
7896 used = hwaddr_aton2(pos, bssid);
7897 if (used < 0)
7898 return -1;
7899 pos += used;
7900
7901 param = os_strstr(pos, " freq=");
7902 if (param) {
7903 param += 6;
7904 freq = atoi(param);
7905 }
7906
7907 param = os_strstr(pos, " no_cck=");
7908 if (param) {
7909 param += 8;
7910 no_cck = atoi(param);
7911 }
7912
7913 param = os_strstr(pos, " wait_time=");
7914 if (param) {
7915 param += 11;
7916 wait_time = atoi(param);
7917 }
7918
7919 param = os_strstr(pos, " action=");
7920 if (param == NULL)
7921 return -1;
7922 param += 8;
7923
7924 len = os_strlen(param);
7925 if (len & 1)
7926 return -1;
7927 len /= 2;
7928
7929 buf = os_malloc(len);
7930 if (buf == NULL)
7931 return -1;
7932
7933 if (hexstr2bin(param, buf, len) < 0) {
7934 os_free(buf);
7935 return -1;
7936 }
7937
7938 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
7939 buf, len, wait_time,
7940 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
7941 os_free(buf);
7942 return res;
7943}
7944
7945
7946static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
7947{
7948 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
7949 offchannel_send_action_done(wpa_s);
7950}
7951
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07007952
Dmitry Shmidt849734c2016-05-27 09:59:01 -07007953static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
7954 char *cmd)
7955{
7956 char *pos, *param;
7957 size_t len;
7958 u8 *buf;
7959 int freq = 0, datarate = 0, ssi_signal = 0;
7960 union wpa_event_data event;
7961
7962 if (!wpa_s->ext_mgmt_frame_handling)
7963 return -1;
7964
7965 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
7966
7967 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
7968
7969 pos = cmd;
7970 param = os_strstr(pos, "freq=");
7971 if (param) {
7972 param += 5;
7973 freq = atoi(param);
7974 }
7975
7976 param = os_strstr(pos, " datarate=");
7977 if (param) {
7978 param += 10;
7979 datarate = atoi(param);
7980 }
7981
7982 param = os_strstr(pos, " ssi_signal=");
7983 if (param) {
7984 param += 12;
7985 ssi_signal = atoi(param);
7986 }
7987
7988 param = os_strstr(pos, " frame=");
7989 if (param == NULL)
7990 return -1;
7991 param += 7;
7992
7993 len = os_strlen(param);
7994 if (len & 1)
7995 return -1;
7996 len /= 2;
7997
7998 buf = os_malloc(len);
7999 if (buf == NULL)
8000 return -1;
8001
8002 if (hexstr2bin(param, buf, len) < 0) {
8003 os_free(buf);
8004 return -1;
8005 }
8006
8007 os_memset(&event, 0, sizeof(event));
8008 event.rx_mgmt.freq = freq;
8009 event.rx_mgmt.frame = buf;
8010 event.rx_mgmt.frame_len = len;
8011 event.rx_mgmt.ssi_signal = ssi_signal;
8012 event.rx_mgmt.datarate = datarate;
8013 wpa_s->ext_mgmt_frame_handling = 0;
8014 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
8015 wpa_s->ext_mgmt_frame_handling = 1;
8016
8017 os_free(buf);
8018
8019 return 0;
8020}
8021
8022
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07008023static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
8024{
8025 char *pos, *param;
8026 union wpa_event_data event;
8027 enum wpa_event_type ev;
8028
8029 /* <event name> [parameters..] */
8030
8031 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
8032
8033 pos = cmd;
8034 param = os_strchr(pos, ' ');
8035 if (param)
8036 *param++ = '\0';
8037
8038 os_memset(&event, 0, sizeof(event));
8039
8040 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
8041 ev = EVENT_INTERFACE_ENABLED;
8042 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
8043 ev = EVENT_INTERFACE_DISABLED;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07008044 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
8045 ev = EVENT_AVOID_FREQUENCIES;
8046 if (param == NULL)
8047 param = "";
8048 if (freq_range_list_parse(&event.freq_range, param) < 0)
8049 return -1;
8050 wpa_supplicant_event(wpa_s, ev, &event);
8051 os_free(event.freq_range.range);
8052 return 0;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07008053 } else {
8054 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
8055 cmd);
8056 return -1;
8057 }
8058
8059 wpa_supplicant_event(wpa_s, ev, &event);
8060
8061 return 0;
8062}
8063
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008064
8065static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
8066{
8067 char *pos;
8068 u8 src[ETH_ALEN], *buf;
8069 int used;
8070 size_t len;
8071
8072 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
8073
8074 pos = cmd;
8075 used = hwaddr_aton2(pos, src);
8076 if (used < 0)
8077 return -1;
8078 pos += used;
8079 while (*pos == ' ')
8080 pos++;
8081
8082 len = os_strlen(pos);
8083 if (len & 1)
8084 return -1;
8085 len /= 2;
8086
8087 buf = os_malloc(len);
8088 if (buf == NULL)
8089 return -1;
8090
8091 if (hexstr2bin(pos, buf, len) < 0) {
8092 os_free(buf);
8093 return -1;
8094 }
8095
8096 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
8097 os_free(buf);
8098
8099 return 0;
8100}
8101
8102
8103static u16 ipv4_hdr_checksum(const void *buf, size_t len)
8104{
8105 size_t i;
8106 u32 sum = 0;
8107 const u16 *pos = buf;
8108
8109 for (i = 0; i < len / 2; i++)
8110 sum += *pos++;
8111
8112 while (sum >> 16)
8113 sum = (sum & 0xffff) + (sum >> 16);
8114
8115 return sum ^ 0xffff;
8116}
8117
8118
8119#define HWSIM_PACKETLEN 1500
8120#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8121
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07008122static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
8123 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008124{
8125 struct wpa_supplicant *wpa_s = ctx;
8126 const struct ether_header *eth;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008127 struct iphdr ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008128 const u8 *pos;
8129 unsigned int i;
8130
8131 if (len != HWSIM_PACKETLEN)
8132 return;
8133
8134 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008135 os_memcpy(&ip, eth + 1, sizeof(ip));
8136 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008137
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008138 if (ip.ihl != 5 || ip.version != 4 ||
8139 ntohs(ip.tot_len) != HWSIM_IP_LEN)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008140 return;
8141
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008142 for (i = 0; i < HWSIM_IP_LEN - sizeof(ip); i++) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008143 if (*pos != (u8) i)
8144 return;
8145 pos++;
8146 }
8147
8148 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
8149 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
8150}
8151
8152
8153static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
8154 char *cmd)
8155{
8156 int enabled = atoi(cmd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008157 char *pos;
8158 const char *ifname;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008159
8160 if (!enabled) {
8161 if (wpa_s->l2_test) {
8162 l2_packet_deinit(wpa_s->l2_test);
8163 wpa_s->l2_test = NULL;
8164 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
8165 }
8166 return 0;
8167 }
8168
8169 if (wpa_s->l2_test)
8170 return 0;
8171
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008172 pos = os_strstr(cmd, " ifname=");
8173 if (pos)
8174 ifname = pos + 8;
8175 else
8176 ifname = wpa_s->ifname;
8177
8178 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008179 ETHERTYPE_IP, wpas_data_test_rx,
8180 wpa_s, 1);
8181 if (wpa_s->l2_test == NULL)
8182 return -1;
8183
8184 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
8185
8186 return 0;
8187}
8188
8189
8190static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
8191{
8192 u8 dst[ETH_ALEN], src[ETH_ALEN];
8193 char *pos;
8194 int used;
8195 long int val;
8196 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008197 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008198 struct ether_header *eth;
8199 struct iphdr *ip;
8200 u8 *dpos;
8201 unsigned int i;
8202
8203 if (wpa_s->l2_test == NULL)
8204 return -1;
8205
8206 /* format: <dst> <src> <tos> */
8207
8208 pos = cmd;
8209 used = hwaddr_aton2(pos, dst);
8210 if (used < 0)
8211 return -1;
8212 pos += used;
8213 while (*pos == ' ')
8214 pos++;
8215 used = hwaddr_aton2(pos, src);
8216 if (used < 0)
8217 return -1;
8218 pos += used;
8219
8220 val = strtol(pos, NULL, 0);
8221 if (val < 0 || val > 0xff)
8222 return -1;
8223 tos = val;
8224
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008225 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008226 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
8227 os_memcpy(eth->ether_shost, src, ETH_ALEN);
8228 eth->ether_type = htons(ETHERTYPE_IP);
8229 ip = (struct iphdr *) (eth + 1);
8230 os_memset(ip, 0, sizeof(*ip));
8231 ip->ihl = 5;
8232 ip->version = 4;
8233 ip->ttl = 64;
8234 ip->tos = tos;
8235 ip->tot_len = htons(HWSIM_IP_LEN);
8236 ip->protocol = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008237 ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8238 ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008239 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
8240 dpos = (u8 *) (ip + 1);
8241 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
8242 *dpos++ = i;
8243
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008244 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008245 HWSIM_PACKETLEN) < 0)
8246 return -1;
8247
8248 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
8249 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
8250
8251 return 0;
8252}
8253
8254
8255static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
8256 char *cmd)
8257{
8258 u8 *buf;
8259 struct ether_header *eth;
8260 struct l2_packet_data *l2 = NULL;
8261 size_t len;
8262 u16 ethertype;
8263 int res = -1;
8264
8265 len = os_strlen(cmd);
8266 if (len & 1 || len < ETH_HLEN * 2)
8267 return -1;
8268 len /= 2;
8269
8270 buf = os_malloc(len);
8271 if (buf == NULL)
8272 return -1;
8273
8274 if (hexstr2bin(cmd, buf, len) < 0)
8275 goto done;
8276
8277 eth = (struct ether_header *) buf;
8278 ethertype = ntohs(eth->ether_type);
8279
8280 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
8281 wpas_data_test_rx, wpa_s, 1);
8282 if (l2 == NULL)
8283 goto done;
8284
8285 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
8286 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
8287done:
8288 if (l2)
8289 l2_packet_deinit(l2);
8290 os_free(buf);
8291
8292 return res < 0 ? -1 : 0;
8293}
8294
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008295
8296static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
8297{
8298#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008299 char *pos;
8300
8301 wpa_trace_fail_after = atoi(cmd);
8302 pos = os_strchr(cmd, ':');
8303 if (pos) {
8304 pos++;
8305 os_strlcpy(wpa_trace_fail_func, pos,
8306 sizeof(wpa_trace_fail_func));
8307 } else {
8308 wpa_trace_fail_after = 0;
8309 }
8310 return 0;
8311#else /* WPA_TRACE_BFD */
8312 return -1;
8313#endif /* WPA_TRACE_BFD */
8314}
8315
8316
8317static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
8318 char *buf, size_t buflen)
8319{
8320#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008321 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
8322 wpa_trace_fail_func);
8323#else /* WPA_TRACE_BFD */
8324 return -1;
8325#endif /* WPA_TRACE_BFD */
8326}
8327
Jouni Malinenc4818362015-10-04 11:45:13 +03008328
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008329static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
8330{
8331#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008332 char *pos;
8333
8334 wpa_trace_test_fail_after = atoi(cmd);
8335 pos = os_strchr(cmd, ':');
8336 if (pos) {
8337 pos++;
8338 os_strlcpy(wpa_trace_test_fail_func, pos,
8339 sizeof(wpa_trace_test_fail_func));
8340 } else {
8341 wpa_trace_test_fail_after = 0;
8342 }
8343 return 0;
8344#else /* WPA_TRACE_BFD */
8345 return -1;
8346#endif /* WPA_TRACE_BFD */
8347}
8348
8349
8350static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
8351 char *buf, size_t buflen)
8352{
8353#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008354 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
8355 wpa_trace_test_fail_func);
8356#else /* WPA_TRACE_BFD */
8357 return -1;
8358#endif /* WPA_TRACE_BFD */
8359}
8360
8361
Jouni Malinenc4818362015-10-04 11:45:13 +03008362static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
8363{
8364 struct wpa_supplicant *wpa_s = eloop_ctx;
8365 int i, count = (intptr_t) timeout_ctx;
8366
8367 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
8368 count);
8369 for (i = 0; i < count; i++) {
8370 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
8371 i + 1, count);
8372 }
8373}
8374
8375
8376static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
8377{
8378 int count;
8379
8380 count = atoi(cmd);
8381 if (count <= 0)
8382 return -1;
8383
8384 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
8385 (void *) (intptr_t) count);
8386}
8387
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008388
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008389static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
8390 const char *cmd)
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008391{
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008392 struct wpabuf *buf;
8393 size_t len;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008394
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008395 len = os_strlen(cmd);
8396 if (len & 1)
8397 return -1;
8398 len /= 2;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008399
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008400 if (len == 0) {
8401 buf = NULL;
8402 } else {
8403 buf = wpabuf_alloc(len);
8404 if (buf == NULL)
8405 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008406
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008407 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
8408 wpabuf_free(buf);
8409 return -1;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008410 }
8411 }
8412
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008413 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
8414 return 0;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008415}
8416
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008417#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008418
8419
8420static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
8421{
8422 char *pos = cmd;
8423 int frame;
8424 size_t len;
8425 struct wpabuf *buf;
8426 struct ieee802_11_elems elems;
8427
8428 frame = atoi(pos);
8429 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
8430 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008431 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008432
8433 pos = os_strchr(pos, ' ');
8434 if (pos == NULL)
8435 return -1;
8436 pos++;
8437
8438 len = os_strlen(pos);
8439 if (len == 0)
8440 return 0;
8441 if (len & 1)
8442 return -1;
8443 len /= 2;
8444
8445 buf = wpabuf_alloc(len);
8446 if (buf == NULL)
8447 return -1;
8448
8449 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
8450 wpabuf_free(buf);
8451 return -1;
8452 }
8453
8454 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
8455 ParseFailed) {
8456 wpabuf_free(buf);
8457 return -1;
8458 }
8459
8460 if (wpa_s->vendor_elem[frame] == NULL) {
8461 wpa_s->vendor_elem[frame] = buf;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008462 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008463 return 0;
8464 }
8465
8466 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
8467 wpabuf_free(buf);
8468 return -1;
8469 }
8470
8471 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
8472 wpabuf_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008473 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008474
8475 return 0;
8476}
8477
8478
8479static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
8480 char *buf, size_t buflen)
8481{
8482 int frame = atoi(cmd);
8483
8484 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
8485 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008486 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008487
8488 if (wpa_s->vendor_elem[frame] == NULL)
8489 return 0;
8490
8491 return wpa_snprintf_hex(buf, buflen,
8492 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
8493 wpabuf_len(wpa_s->vendor_elem[frame]));
8494}
8495
8496
8497static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
8498{
8499 char *pos = cmd;
8500 int frame;
8501 size_t len;
8502 u8 *buf;
8503 struct ieee802_11_elems elems;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008504 int res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008505
8506 frame = atoi(pos);
8507 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
8508 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008509 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008510
8511 pos = os_strchr(pos, ' ');
8512 if (pos == NULL)
8513 return -1;
8514 pos++;
8515
8516 if (*pos == '*') {
8517 wpabuf_free(wpa_s->vendor_elem[frame]);
8518 wpa_s->vendor_elem[frame] = NULL;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008519 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008520 return 0;
8521 }
8522
8523 if (wpa_s->vendor_elem[frame] == NULL)
8524 return -1;
8525
8526 len = os_strlen(pos);
8527 if (len == 0)
8528 return 0;
8529 if (len & 1)
8530 return -1;
8531 len /= 2;
8532
8533 buf = os_malloc(len);
8534 if (buf == NULL)
8535 return -1;
8536
8537 if (hexstr2bin(pos, buf, len) < 0) {
8538 os_free(buf);
8539 return -1;
8540 }
8541
8542 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
8543 os_free(buf);
8544 return -1;
8545 }
8546
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008547 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008548 os_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008549 return res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07008550}
8551
8552
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008553static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
8554{
8555 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008556 size_t len;
8557 const u8 *data;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008558
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008559 /*
8560 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
8561 * BSSID[6]
8562 * BSSID Information[4]
8563 * Operating Class[1]
8564 * Channel Number[1]
8565 * PHY Type[1]
8566 * Optional Subelements[variable]
8567 */
8568#define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
8569
8570 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008571 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008572 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008573 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008574
8575 data = wpabuf_head_u8(neighbor_rep);
8576 len = wpabuf_len(neighbor_rep);
8577
8578 while (len >= 2 + NR_IE_MIN_LEN) {
8579 const u8 *nr;
8580 char lci[256 * 2 + 1];
8581 char civic[256 * 2 + 1];
8582 u8 nr_len = data[1];
8583 const u8 *pos = data, *end;
8584
8585 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
8586 nr_len < NR_IE_MIN_LEN) {
8587 wpa_printf(MSG_DEBUG,
8588 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
8589 data[0], nr_len);
8590 goto out;
8591 }
8592
8593 if (2U + nr_len > len) {
8594 wpa_printf(MSG_DEBUG,
8595 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
8596 data[0], len, nr_len);
8597 goto out;
8598 }
8599 pos += 2;
8600 end = pos + nr_len;
8601
8602 nr = pos;
8603 pos += NR_IE_MIN_LEN;
8604
8605 lci[0] = '\0';
8606 civic[0] = '\0';
8607 while (end - pos > 2) {
8608 u8 s_id, s_len;
8609
8610 s_id = *pos++;
8611 s_len = *pos++;
8612 if (s_len > end - pos)
8613 goto out;
8614 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
8615 /* Measurement Token[1] */
8616 /* Measurement Report Mode[1] */
8617 /* Measurement Type[1] */
8618 /* Measurement Report[variable] */
8619 switch (pos[2]) {
8620 case MEASURE_TYPE_LCI:
8621 if (lci[0])
8622 break;
8623 wpa_snprintf_hex(lci, sizeof(lci),
8624 pos, s_len);
8625 break;
8626 case MEASURE_TYPE_LOCATION_CIVIC:
8627 if (civic[0])
8628 break;
8629 wpa_snprintf_hex(civic, sizeof(civic),
8630 pos, s_len);
8631 break;
8632 }
8633 }
8634
8635 pos += s_len;
8636 }
8637
8638 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
8639 "bssid=" MACSTR
8640 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
8641 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
8642 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
8643 nr[ETH_ALEN + 6],
8644 lci[0] ? " lci=" : "", lci,
8645 civic[0] ? " civic=" : "", civic);
8646
8647 data = end;
8648 len -= 2 + nr_len;
8649 }
8650
8651out:
8652 wpabuf_free(neighbor_rep);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008653}
8654
8655
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008656static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
8657 char *cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008658{
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008659 struct wpa_ssid_value ssid, *ssid_p = NULL;
8660 int ret, lci = 0, civic = 0;
8661 char *ssid_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008662
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008663 ssid_s = os_strstr(cmd, "ssid=");
8664 if (ssid_s) {
8665 if (ssid_parse(ssid_s + 5, &ssid)) {
8666 wpa_printf(MSG_ERROR,
8667 "CTRL: Send Neighbor Report: bad SSID");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008668 return -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008669 }
8670
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008671 ssid_p = &ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008672
8673 /*
8674 * Move cmd after the SSID text that may include "lci" or
8675 * "civic".
8676 */
8677 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
8678 if (cmd)
8679 cmd++;
8680
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008681 }
8682
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008683 if (cmd && os_strstr(cmd, "lci"))
8684 lci = 1;
8685
8686 if (cmd && os_strstr(cmd, "civic"))
8687 civic = 1;
8688
8689 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008690 wpas_ctrl_neighbor_rep_cb,
8691 wpa_s);
8692
8693 return ret;
8694}
8695
8696
8697static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
8698{
8699 eapol_sm_erp_flush(wpa_s->eapol);
8700 return 0;
8701}
8702
8703
8704static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
8705 char *cmd)
8706{
8707 char *token, *context = NULL;
8708 unsigned int enable = ~0, type = 0;
8709 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
8710 u8 *addr = NULL, *mask = NULL;
8711
8712 while ((token = str_token(cmd, " ", &context))) {
8713 if (os_strcasecmp(token, "scan") == 0) {
8714 type |= MAC_ADDR_RAND_SCAN;
8715 } else if (os_strcasecmp(token, "sched") == 0) {
8716 type |= MAC_ADDR_RAND_SCHED_SCAN;
8717 } else if (os_strcasecmp(token, "pno") == 0) {
8718 type |= MAC_ADDR_RAND_PNO;
8719 } else if (os_strcasecmp(token, "all") == 0) {
8720 type = wpa_s->mac_addr_rand_supported;
8721 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
8722 enable = atoi(token + 7);
8723 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
8724 addr = _addr;
8725 if (hwaddr_aton(token + 5, addr)) {
8726 wpa_printf(MSG_INFO,
8727 "CTRL: Invalid MAC address: %s",
8728 token);
8729 return -1;
8730 }
8731 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
8732 mask = _mask;
8733 if (hwaddr_aton(token + 5, mask)) {
8734 wpa_printf(MSG_INFO,
8735 "CTRL: Invalid MAC address mask: %s",
8736 token);
8737 return -1;
8738 }
8739 } else {
8740 wpa_printf(MSG_INFO,
8741 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
8742 token);
8743 return -1;
8744 }
8745 }
8746
8747 if (!type) {
8748 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
8749 return -1;
8750 }
8751
8752 if ((wpa_s->mac_addr_rand_supported & type) != type) {
8753 wpa_printf(MSG_INFO,
8754 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
8755 type, wpa_s->mac_addr_rand_supported);
8756 return -1;
8757 }
8758
8759 if (enable > 1) {
8760 wpa_printf(MSG_INFO,
8761 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
8762 return -1;
8763 }
8764
8765 if (!enable) {
8766 wpas_mac_addr_rand_scan_clear(wpa_s, type);
8767 if (wpa_s->pno) {
8768 if (type & MAC_ADDR_RAND_PNO) {
8769 wpas_stop_pno(wpa_s);
8770 wpas_start_pno(wpa_s);
8771 }
8772 } else if (wpa_s->sched_scanning &&
8773 (type & MAC_ADDR_RAND_SCHED_SCAN)) {
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008774 wpas_scan_restart_sched_scan(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008775 }
8776 return 0;
8777 }
8778
8779 if ((addr && !mask) || (!addr && mask)) {
8780 wpa_printf(MSG_INFO,
8781 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
8782 return -1;
8783 }
8784
8785 if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) {
8786 wpa_printf(MSG_INFO,
8787 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
8788 return -1;
8789 }
8790
8791 if (type & MAC_ADDR_RAND_SCAN) {
8792 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
8793 addr, mask);
8794 }
8795
8796 if (type & MAC_ADDR_RAND_SCHED_SCAN) {
8797 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
8798 addr, mask);
8799
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008800 if (wpa_s->sched_scanning && !wpa_s->pno)
8801 wpas_scan_restart_sched_scan(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008802 }
8803
8804 if (type & MAC_ADDR_RAND_PNO) {
8805 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
8806 addr, mask);
8807 if (wpa_s->pno) {
8808 wpas_stop_pno(wpa_s);
8809 wpas_start_pno(wpa_s);
8810 }
8811 }
8812
8813 return 0;
8814}
8815
8816
Dmitry Shmidte4663042016-04-04 10:07:49 -07008817static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
8818 char *buf, size_t buflen)
8819{
8820 size_t reply_len;
8821
8822 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
8823#ifdef CONFIG_AP
8824 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
8825 buflen - reply_len);
8826#endif /* CONFIG_AP */
8827 return reply_len;
8828}
8829
8830
8831static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
8832{
8833 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
8834#ifdef CONFIG_AP
8835 wpas_ap_pmksa_cache_flush(wpa_s);
8836#endif /* CONFIG_AP */
8837}
8838
8839
Dmitry Shmidt29333592017-01-09 12:27:11 -08008840#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
8841
8842static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
8843 const char *cmd, char *buf, size_t buflen)
8844{
8845 struct rsn_pmksa_cache_entry *entry;
8846 struct wpa_ssid *ssid;
8847 char *pos, *pos2, *end;
8848 int ret;
8849 struct os_reltime now;
8850
8851 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
8852 if (!ssid)
8853 return -1;
8854
8855 pos = buf;
8856 end = buf + buflen;
8857
8858 os_get_reltime(&now);
8859
8860 /*
8861 * Entry format:
8862 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
8863 * <expiration in seconds> <akmp> <opportunistic>
8864 */
8865
8866 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
8867 entry = entry->next) {
8868 if (entry->network_ctx != ssid)
8869 continue;
8870
8871 pos2 = pos;
8872 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
8873 MAC2STR(entry->aa));
8874 if (os_snprintf_error(end - pos2, ret))
8875 break;
8876 pos2 += ret;
8877
8878 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
8879 PMKID_LEN);
8880
8881 ret = os_snprintf(pos2, end - pos2, " ");
8882 if (os_snprintf_error(end - pos2, ret))
8883 break;
8884 pos2 += ret;
8885
8886 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
8887 entry->pmk_len);
8888
8889 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
8890 (int) (entry->reauth_time - now.sec),
8891 (int) (entry->expiration - now.sec),
8892 entry->akmp,
8893 entry->opportunistic);
8894 if (os_snprintf_error(end - pos2, ret))
8895 break;
8896 pos2 += ret;
8897
8898 ret = os_snprintf(pos2, end - pos2, "\n");
8899 if (os_snprintf_error(end - pos2, ret))
8900 break;
8901 pos2 += ret;
8902
8903 pos = pos2;
8904 }
8905
8906 return pos - buf;
8907}
8908
8909
8910static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
8911 char *cmd)
8912{
8913 struct rsn_pmksa_cache_entry *entry;
8914 struct wpa_ssid *ssid;
8915 char *pos, *pos2;
8916 int ret = -1;
8917 struct os_reltime now;
8918 int reauth_time = 0, expiration = 0;
8919
8920 /*
8921 * Entry format:
8922 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
8923 * <expiration in seconds> <akmp> <opportunistic>
8924 */
8925
8926 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
8927 if (!ssid)
8928 return -1;
8929
8930 pos = os_strchr(cmd, ' ');
8931 if (!pos)
8932 return -1;
8933 pos++;
8934
8935 entry = os_zalloc(sizeof(*entry));
8936 if (!entry)
8937 return -1;
8938
8939 if (hwaddr_aton(pos, entry->aa))
8940 goto fail;
8941
8942 pos = os_strchr(pos, ' ');
8943 if (!pos)
8944 goto fail;
8945 pos++;
8946
8947 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
8948 goto fail;
8949
8950 pos = os_strchr(pos, ' ');
8951 if (!pos)
8952 goto fail;
8953 pos++;
8954
8955 pos2 = os_strchr(pos, ' ');
8956 if (!pos2)
8957 goto fail;
8958 entry->pmk_len = (pos2 - pos) / 2;
8959 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
8960 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
8961 goto fail;
8962
8963 pos = os_strchr(pos, ' ');
8964 if (!pos)
8965 goto fail;
8966 pos++;
8967
8968 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
8969 &entry->akmp, &entry->opportunistic) != 4)
8970 goto fail;
8971 os_get_reltime(&now);
8972 entry->expiration = now.sec + expiration;
8973 entry->reauth_time = now.sec + reauth_time;
8974
8975 entry->network_ctx = ssid;
8976
8977 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
8978 entry = NULL;
8979 ret = 0;
8980fail:
8981 os_free(entry);
8982 return ret;
8983}
8984
8985#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
8986
8987
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008988static int wpas_ctrl_cmd_debug_level(const char *cmd)
8989{
8990 if (os_strcmp(cmd, "PING") == 0 ||
8991 os_strncmp(cmd, "BSS ", 4) == 0 ||
8992 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
8993 os_strncmp(cmd, "STATUS", 6) == 0 ||
8994 os_strncmp(cmd, "STA ", 4) == 0 ||
8995 os_strncmp(cmd, "STA-", 4) == 0)
8996 return MSG_EXCESSIVE;
8997 return MSG_DEBUG;
8998}
8999
9000
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009001char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
9002 char *buf, size_t *resp_len)
9003{
9004 char *reply;
9005 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009006 int reply_len;
9007
9008 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009009 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
9010 if (wpa_debug_show_keys)
9011 wpa_dbg(wpa_s, MSG_DEBUG,
9012 "Control interface command '%s'", buf);
9013 else
9014 wpa_dbg(wpa_s, MSG_DEBUG,
9015 "Control interface command '%s [REMOVED]'",
9016 os_strncmp(buf, WPA_CTRL_RSP,
9017 os_strlen(WPA_CTRL_RSP)) == 0 ?
9018 WPA_CTRL_RSP : "SET_NETWORK");
9019 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
Dmitry Shmidt21de2142014-04-08 10:50:52 -07009020 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009021 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
9022 (const u8 *) buf, os_strlen(buf));
9023 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009024 int level = wpas_ctrl_cmd_debug_level(buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07009025 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009026 }
9027
9028 reply = os_malloc(reply_size);
9029 if (reply == NULL) {
9030 *resp_len = 1;
9031 return NULL;
9032 }
9033
9034 os_memcpy(reply, "OK\n", 3);
9035 reply_len = 3;
9036
9037 if (os_strcmp(buf, "PING") == 0) {
9038 os_memcpy(reply, "PONG\n", 5);
9039 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07009040 } else if (os_strcmp(buf, "IFNAME") == 0) {
9041 reply_len = os_strlen(wpa_s->ifname);
9042 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009043 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
9044 if (wpa_debug_reopen_file() < 0)
9045 reply_len = -1;
9046 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
9047 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
9048 } else if (os_strcmp(buf, "MIB") == 0) {
9049 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
9050 if (reply_len >= 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009051 reply_len += eapol_sm_get_mib(wpa_s->eapol,
9052 reply + reply_len,
9053 reply_size - reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009054 }
9055 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
9056 reply_len = wpa_supplicant_ctrl_iface_status(
9057 wpa_s, buf + 6, reply, reply_size);
9058 } else if (os_strcmp(buf, "PMKSA") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -07009059 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009060 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -07009061 wpas_ctrl_iface_pmksa_flush(wpa_s);
Dmitry Shmidt29333592017-01-09 12:27:11 -08009062#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9063 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
9064 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
9065 reply, reply_size);
9066 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
9067 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
9068 reply_len = -1;
9069#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009070 } else if (os_strncmp(buf, "SET ", 4) == 0) {
9071 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
9072 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08009073 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
9074 reply_len = wpa_config_dump_values(wpa_s->conf,
9075 reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009076 } else if (os_strncmp(buf, "GET ", 4) == 0) {
9077 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
9078 reply, reply_size);
9079 } else if (os_strcmp(buf, "LOGON") == 0) {
9080 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
9081 } else if (os_strcmp(buf, "LOGOFF") == 0) {
9082 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
9083 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
9084 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
9085 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08009086 else
9087 wpas_request_connection(wpa_s);
Dmitry Shmidt98660862014-03-11 17:26:21 -07009088 } else if (os_strcmp(buf, "REATTACH") == 0) {
9089 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
9090 !wpa_s->current_ssid)
9091 reply_len = -1;
9092 else {
9093 wpa_s->reattach = 1;
9094 wpas_request_connection(wpa_s);
9095 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009096 } else if (os_strcmp(buf, "RECONNECT") == 0) {
9097 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
9098 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08009099 else if (wpa_s->disconnected)
9100 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009101#ifdef IEEE8021X_EAPOL
9102 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
9103 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
9104 reply_len = -1;
9105#endif /* IEEE8021X_EAPOL */
9106#ifdef CONFIG_PEERKEY
9107 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
9108 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
9109 reply_len = -1;
9110#endif /* CONFIG_PEERKEY */
9111#ifdef CONFIG_IEEE80211R
9112 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
9113 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
9114 reply_len = -1;
9115#endif /* CONFIG_IEEE80211R */
9116#ifdef CONFIG_WPS
9117 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
9118 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
9119 if (res == -2) {
9120 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
9121 reply_len = 17;
9122 } else if (res)
9123 reply_len = -1;
9124 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
9125 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
9126 if (res == -2) {
9127 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
9128 reply_len = 17;
9129 } else if (res)
9130 reply_len = -1;
9131 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
9132 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
9133 reply,
9134 reply_size);
9135 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
9136 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
9137 wpa_s, buf + 14, reply, reply_size);
9138 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
9139 if (wpas_wps_cancel(wpa_s))
9140 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07009141#ifdef CONFIG_WPS_NFC
9142 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
9143 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
9144 reply_len = -1;
9145 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
9146 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
9147 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08009148 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
9149 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
9150 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07009151 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
9152 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
9153 wpa_s, buf + 14, reply, reply_size);
9154 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
9155 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
9156 buf + 17))
9157 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08009158 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
9159 reply_len = wpas_ctrl_nfc_get_handover_req(
9160 wpa_s, buf + 21, reply, reply_size);
9161 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
9162 reply_len = wpas_ctrl_nfc_get_handover_sel(
9163 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08009164 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
9165 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
9166 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07009167#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009168 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
9169 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
9170 reply_len = -1;
9171#ifdef CONFIG_AP
9172 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
9173 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
9174 wpa_s, buf + 11, reply, reply_size);
9175#endif /* CONFIG_AP */
9176#ifdef CONFIG_WPS_ER
9177 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
9178 if (wpas_wps_er_start(wpa_s, NULL))
9179 reply_len = -1;
9180 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
9181 if (wpas_wps_er_start(wpa_s, buf + 13))
9182 reply_len = -1;
9183 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009184 wpas_wps_er_stop(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009185 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
9186 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
9187 reply_len = -1;
9188 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
9189 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
9190 if (ret == -2) {
9191 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
9192 reply_len = 17;
9193 } else if (ret == -3) {
9194 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
9195 reply_len = 18;
9196 } else if (ret == -4) {
9197 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
9198 reply_len = 20;
9199 } else if (ret)
9200 reply_len = -1;
9201 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
9202 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
9203 reply_len = -1;
9204 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
9205 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
9206 buf + 18))
9207 reply_len = -1;
9208 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
9209 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
9210 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07009211#ifdef CONFIG_WPS_NFC
9212 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
9213 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
9214 wpa_s, buf + 24, reply, reply_size);
9215#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009216#endif /* CONFIG_WPS_ER */
9217#endif /* CONFIG_WPS */
9218#ifdef CONFIG_IBSS_RSN
9219 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
9220 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
9221 reply_len = -1;
9222#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009223#ifdef CONFIG_MESH
9224 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
9225 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
9226 wpa_s, buf + 19, reply, reply_size);
9227 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
9228 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
9229 wpa_s, "", reply, reply_size);
9230 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
9231 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
9232 reply_len = -1;
9233 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
9234 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
9235 buf + 18))
9236 reply_len = -1;
Dmitry Shmidte4663042016-04-04 10:07:49 -07009237 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
9238 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
9239 reply_len = -1;
9240 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
9241 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
9242 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009243#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009244#ifdef CONFIG_P2P
9245 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -08009246 if (p2p_ctrl_find(wpa_s, buf + 8))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009247 reply_len = -1;
9248 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
9249 if (p2p_ctrl_find(wpa_s, ""))
9250 reply_len = -1;
9251 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
9252 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08009253 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
9254 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
9255 reply_len = -1;
9256 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
9257 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
9258 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009259 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
9260 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
9261 reply_size);
9262 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
9263 if (p2p_ctrl_listen(wpa_s, buf + 11))
9264 reply_len = -1;
9265 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
9266 if (p2p_ctrl_listen(wpa_s, ""))
9267 reply_len = -1;
9268 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
9269 if (wpas_p2p_group_remove(wpa_s, buf + 17))
9270 reply_len = -1;
9271 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07009272 if (p2p_ctrl_group_add(wpa_s, ""))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009273 reply_len = -1;
9274 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
9275 if (p2p_ctrl_group_add(wpa_s, buf + 14))
9276 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009277 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
9278 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
9279 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009280 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
9281 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
9282 reply_len = -1;
9283 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
9284 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
9285 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
9286 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
9287 reply_size);
9288 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
9289 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
9290 reply_len = -1;
9291 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
9292 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
9293 reply_len = -1;
9294 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
9295 wpas_p2p_sd_service_update(wpa_s);
9296 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
9297 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
9298 reply_len = -1;
9299 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
9300 wpas_p2p_service_flush(wpa_s);
9301 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
9302 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
9303 reply_len = -1;
9304 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
9305 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
9306 reply_len = -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08009307 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
9308 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
9309 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009310 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
9311 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
9312 reply_len = -1;
9313 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
9314 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
9315 reply_len = -1;
9316 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
9317 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
9318 reply_size);
9319 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
9320 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
9321 reply_len = -1;
9322 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -07009323 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009324 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
9325 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
9326 reply_len = -1;
9327 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
9328 if (wpas_p2p_cancel(wpa_s))
9329 reply_len = -1;
9330 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
9331 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
9332 reply_len = -1;
9333 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
9334 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
9335 reply_len = -1;
9336 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
9337 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
9338 reply_len = -1;
9339 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
9340 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
9341 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07009342 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
9343 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
9344 reply_len = -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07009345 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
9346 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
9347 reply_len = -1;
9348 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
9349 if (wpas_p2p_lo_stop(wpa_s))
9350 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009351#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07009352#ifdef CONFIG_WIFI_DISPLAY
9353 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
9354 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
9355 reply_len = -1;
9356 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
9357 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
9358 reply, reply_size);
9359#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009360#ifdef CONFIG_INTERWORKING
9361 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
9362 if (interworking_fetch_anqp(wpa_s) < 0)
9363 reply_len = -1;
9364 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
9365 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009366 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
9367 if (ctrl_interworking_select(wpa_s, NULL) < 0)
9368 reply_len = -1;
9369 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
9370 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009371 reply_len = -1;
9372 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08009373 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009374 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08009375 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
9376 int id;
9377
9378 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
9379 if (id < 0)
9380 reply_len = -1;
9381 else {
9382 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
9383 if (os_snprintf_error(reply_size, reply_len))
9384 reply_len = -1;
9385 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009386 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
9387 if (get_anqp(wpa_s, buf + 9) < 0)
9388 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07009389 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
9390 if (gas_request(wpa_s, buf + 12) < 0)
9391 reply_len = -1;
9392 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
9393 reply_len = gas_response_get(wpa_s, buf + 17, reply,
9394 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009395#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -07009396#ifdef CONFIG_HS20
9397 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
9398 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
9399 reply_len = -1;
9400 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
9401 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
9402 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08009403 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08009404 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
9405 reply_len = -1;
9406 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
9407 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
9408 reply_len = -1;
9409 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
9410 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
9411 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
9412 if (del_hs20_icon(wpa_s, buf + 14) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08009413 reply_len = -1;
9414 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07009415 if (hs20_fetch_osu(wpa_s, 0) < 0)
9416 reply_len = -1;
9417 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
9418 if (hs20_fetch_osu(wpa_s, 1) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08009419 reply_len = -1;
9420 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
9421 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07009422#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009423 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
9424 {
9425 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
9426 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
9427 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07009428 else {
9429 /*
9430 * Notify response from timeout to allow the control
9431 * interface response to be sent first.
9432 */
9433 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
9434 wpa_s, NULL);
9435 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009436 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
9437 if (wpa_supplicant_reload_configuration(wpa_s))
9438 reply_len = -1;
9439 } else if (os_strcmp(buf, "TERMINATE") == 0) {
9440 wpa_supplicant_terminate_proc(wpa_s->global);
9441 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
9442 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
9443 reply_len = -1;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07009444 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009445 reply_len = wpa_supplicant_ctrl_iface_blacklist(
9446 wpa_s, buf + 9, reply, reply_size);
9447 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
9448 reply_len = wpa_supplicant_ctrl_iface_log_level(
9449 wpa_s, buf + 9, reply, reply_size);
Vinit Deshpandeda134e92014-12-02 10:59:29 -08009450 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
9451 reply_len = wpa_supplicant_ctrl_iface_list_networks(
9452 wpa_s, buf + 14, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009453 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
9454 reply_len = wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -08009455 wpa_s, NULL, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009456 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07009457 wpas_request_disconnection(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009458 } else if (os_strcmp(buf, "SCAN") == 0) {
9459 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
9460 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
9461 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009462 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
9463 reply_len = wpa_supplicant_ctrl_iface_scan_results(
9464 wpa_s, reply, reply_size);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009465 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
9466 if (wpas_abort_ongoing_scan(wpa_s) < 0)
9467 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009468 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
9469 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
9470 reply_len = -1;
9471 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
9472 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
9473 reply_len = -1;
9474 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
9475 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
9476 reply_len = -1;
9477 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
9478 reply_len = wpa_supplicant_ctrl_iface_add_network(
9479 wpa_s, reply, reply_size);
9480 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
9481 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
9482 reply_len = -1;
9483 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
9484 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
9485 reply_len = -1;
9486 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
9487 reply_len = wpa_supplicant_ctrl_iface_get_network(
9488 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07009489 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009490 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
9491 wpa_s))
Dmitry Shmidt684785c2014-05-12 13:34:29 -07009492 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07009493 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
9494 reply_len = wpa_supplicant_ctrl_iface_list_creds(
9495 wpa_s, reply, reply_size);
9496 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
9497 reply_len = wpa_supplicant_ctrl_iface_add_cred(
9498 wpa_s, reply, reply_size);
9499 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
9500 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
9501 reply_len = -1;
9502 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
9503 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
9504 reply_len = -1;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07009505 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
9506 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
9507 reply,
9508 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009509#ifndef CONFIG_NO_CONFIG_WRITE
9510 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
9511 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
9512 reply_len = -1;
9513#endif /* CONFIG_NO_CONFIG_WRITE */
9514 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
9515 reply_len = wpa_supplicant_ctrl_iface_get_capability(
9516 wpa_s, buf + 15, reply, reply_size);
9517 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
9518 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
9519 reply_len = -1;
9520 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
9521 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
9522 reply_len = -1;
9523 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
9524 reply_len = wpa_supplicant_global_iface_list(
9525 wpa_s->global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08009526 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009527 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08009528 wpa_s->global, buf + 10, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009529 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
9530 reply_len = wpa_supplicant_ctrl_iface_bss(
9531 wpa_s, buf + 4, reply, reply_size);
9532#ifdef CONFIG_AP
9533 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
9534 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
9535 } else if (os_strncmp(buf, "STA ", 4) == 0) {
9536 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
9537 reply_size);
9538 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
9539 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
9540 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07009541 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
9542 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
9543 reply_len = -1;
9544 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
9545 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
9546 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009547 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
9548 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
9549 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08009550 } else if (os_strcmp(buf, "STOP_AP") == 0) {
9551 if (wpas_ap_stop_ap(wpa_s))
9552 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009553#endif /* CONFIG_AP */
9554 } else if (os_strcmp(buf, "SUSPEND") == 0) {
9555 wpas_notify_suspend(wpa_s->global);
9556 } else if (os_strcmp(buf, "RESUME") == 0) {
9557 wpas_notify_resume(wpa_s->global);
Dmitry Shmidt21de2142014-04-08 10:50:52 -07009558#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009559 } else if (os_strcmp(buf, "DROP_SA") == 0) {
9560 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
Dmitry Shmidt21de2142014-04-08 10:50:52 -07009561#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009562 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
9563 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
9564 reply_len = -1;
9565 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009566 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009567 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
9568 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
9569 reply_len = -1;
9570 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
9571 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
9572 buf + 17))
9573 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07009574 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009575 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009576#ifdef CONFIG_TDLS
9577 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
9578 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
9579 reply_len = -1;
9580 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
9581 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
9582 reply_len = -1;
9583 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
9584 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
9585 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009586 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
9587 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
9588 buf + 17))
9589 reply_len = -1;
9590 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
9591 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
9592 buf + 24))
9593 reply_len = -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07009594 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
9595 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
9596 wpa_s, buf + 17, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009597#endif /* CONFIG_TDLS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009598 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
9599 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
9600 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
9601 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
9602 reply_len = -1;
9603 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
9604 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
9605 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009606 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
9607 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
9608 reply_size);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08009609 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
9610 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
9611 reply_len = -1;
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07009612 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
9613 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
9614 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07009615#ifdef CONFIG_AUTOSCAN
9616 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
9617 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
9618 reply_len = -1;
9619#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07009620 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
9621 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
9622 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08009623#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07009624 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
9625 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
9626 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08009627#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009628 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
9629 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
9630 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009631 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08009632 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009633 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08009634#ifdef CONFIG_WNM
9635 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
9636 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
9637 reply_len = -1;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08009638 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
9639 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
Dmitry Shmidt44c95782013-05-17 09:51:35 -07009640 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08009641#endif /* CONFIG_WNM */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07009642 } else if (os_strcmp(buf, "FLUSH") == 0) {
9643 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009644 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
9645 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
9646 reply_size);
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009647#ifdef CONFIG_TESTING_OPTIONS
9648 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
9649 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
9650 reply_len = -1;
9651 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
9652 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009653 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
9654 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
9655 reply_len = -1;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009656 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
9657 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
9658 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009659 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
9660 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
9661 reply_len = -1;
9662 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
9663 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
9664 reply_len = -1;
9665 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
9666 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
9667 reply_len = -1;
9668 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
9669 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
9670 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009671 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
9672 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
9673 reply_len = -1;
9674 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
9675 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009676 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
9677 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
9678 reply_len = -1;
9679 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
9680 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
Jouni Malinenc4818362015-10-04 11:45:13 +03009681 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
9682 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
9683 reply_len = -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009684 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
9685 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
9686 reply_len = -1;
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009687#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009688 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
9689 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
9690 reply_len = -1;
9691 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
9692 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
9693 reply_size);
9694 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
9695 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
9696 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009697 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009698 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009699 reply_len = -1;
9700 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
9701 wpas_ctrl_iface_erp_flush(wpa_s);
9702 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
9703 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
9704 reply_len = -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009705 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
9706 reply_len = wpas_ctrl_iface_get_pref_freq_list(
9707 wpa_s, buf + 19, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009708 } else {
9709 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
9710 reply_len = 16;
9711 }
9712
9713 if (reply_len < 0) {
9714 os_memcpy(reply, "FAIL\n", 5);
9715 reply_len = 5;
9716 }
9717
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009718 *resp_len = reply_len;
9719 return reply;
9720}
9721
9722
9723static int wpa_supplicant_global_iface_add(struct wpa_global *global,
9724 char *cmd)
9725{
9726 struct wpa_interface iface;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07009727 char *pos, *extra;
9728 struct wpa_supplicant *wpa_s;
9729 unsigned int create_iface = 0;
9730 u8 mac_addr[ETH_ALEN];
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009731 enum wpa_driver_if_type type = WPA_IF_STATION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009732
9733 /*
9734 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009735 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009736 */
9737 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
9738
9739 os_memset(&iface, 0, sizeof(iface));
9740
9741 do {
9742 iface.ifname = pos = cmd;
9743 pos = os_strchr(pos, '\t');
9744 if (pos)
9745 *pos++ = '\0';
9746 if (iface.ifname[0] == '\0')
9747 return -1;
9748 if (pos == NULL)
9749 break;
9750
9751 iface.confname = pos;
9752 pos = os_strchr(pos, '\t');
9753 if (pos)
9754 *pos++ = '\0';
9755 if (iface.confname[0] == '\0')
9756 iface.confname = NULL;
9757 if (pos == NULL)
9758 break;
9759
9760 iface.driver = pos;
9761 pos = os_strchr(pos, '\t');
9762 if (pos)
9763 *pos++ = '\0';
9764 if (iface.driver[0] == '\0')
9765 iface.driver = NULL;
9766 if (pos == NULL)
9767 break;
9768
9769 iface.ctrl_interface = pos;
9770 pos = os_strchr(pos, '\t');
9771 if (pos)
9772 *pos++ = '\0';
9773 if (iface.ctrl_interface[0] == '\0')
9774 iface.ctrl_interface = NULL;
9775 if (pos == NULL)
9776 break;
9777
9778 iface.driver_param = pos;
9779 pos = os_strchr(pos, '\t');
9780 if (pos)
9781 *pos++ = '\0';
9782 if (iface.driver_param[0] == '\0')
9783 iface.driver_param = NULL;
9784 if (pos == NULL)
9785 break;
9786
9787 iface.bridge_ifname = pos;
9788 pos = os_strchr(pos, '\t');
9789 if (pos)
9790 *pos++ = '\0';
9791 if (iface.bridge_ifname[0] == '\0')
9792 iface.bridge_ifname = NULL;
9793 if (pos == NULL)
9794 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07009795
9796 extra = pos;
9797 pos = os_strchr(pos, '\t');
9798 if (pos)
9799 *pos++ = '\0';
Dmitry Shmidt83474442015-04-15 13:47:09 -07009800 if (!extra[0])
9801 break;
9802
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009803 if (os_strcmp(extra, "create") == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07009804 create_iface = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009805 if (!pos)
9806 break;
9807
9808 if (os_strcmp(pos, "sta") == 0) {
9809 type = WPA_IF_STATION;
9810 } else if (os_strcmp(pos, "ap") == 0) {
9811 type = WPA_IF_AP_BSS;
9812 } else {
9813 wpa_printf(MSG_DEBUG,
9814 "INTERFACE_ADD unsupported interface type: '%s'",
9815 pos);
9816 return -1;
9817 }
9818 } else {
Dmitry Shmidt83474442015-04-15 13:47:09 -07009819 wpa_printf(MSG_DEBUG,
9820 "INTERFACE_ADD unsupported extra parameter: '%s'",
9821 extra);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07009822 return -1;
Dmitry Shmidt83474442015-04-15 13:47:09 -07009823 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009824 } while (0);
9825
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07009826 if (create_iface) {
9827 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
9828 iface.ifname);
9829 if (!global->ifaces)
9830 return -1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009831 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07009832 NULL, NULL, NULL, mac_addr, NULL) < 0) {
9833 wpa_printf(MSG_ERROR,
9834 "CTRL_IFACE interface creation failed");
9835 return -1;
9836 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009837
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07009838 wpa_printf(MSG_DEBUG,
9839 "CTRL_IFACE interface '%s' created with MAC addr: "
9840 MACSTR, iface.ifname, MAC2STR(mac_addr));
9841 }
9842
9843 if (wpa_supplicant_get_iface(global, iface.ifname))
9844 goto fail;
9845
9846 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
9847 if (!wpa_s)
9848 goto fail;
9849 wpa_s->added_vif = create_iface;
9850 return 0;
9851
9852fail:
9853 if (create_iface)
9854 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
9855 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009856}
9857
9858
9859static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
9860 char *cmd)
9861{
9862 struct wpa_supplicant *wpa_s;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07009863 int ret;
9864 unsigned int delete_iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009865
9866 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
9867
9868 wpa_s = wpa_supplicant_get_iface(global, cmd);
9869 if (wpa_s == NULL)
9870 return -1;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07009871 delete_iface = wpa_s->added_vif;
9872 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
9873 if (!ret && delete_iface) {
9874 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
9875 cmd);
9876 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
9877 }
9878 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009879}
9880
9881
9882static void wpa_free_iface_info(struct wpa_interface_info *iface)
9883{
9884 struct wpa_interface_info *prev;
9885
9886 while (iface) {
9887 prev = iface;
9888 iface = iface->next;
9889
9890 os_free(prev->ifname);
9891 os_free(prev->desc);
9892 os_free(prev);
9893 }
9894}
9895
9896
9897static int wpa_supplicant_global_iface_list(struct wpa_global *global,
9898 char *buf, int len)
9899{
9900 int i, res;
9901 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
9902 char *pos, *end;
9903
9904 for (i = 0; wpa_drivers[i]; i++) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07009905 const struct wpa_driver_ops *drv = wpa_drivers[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009906 if (drv->get_interfaces == NULL)
9907 continue;
9908 tmp = drv->get_interfaces(global->drv_priv[i]);
9909 if (tmp == NULL)
9910 continue;
9911
9912 if (last == NULL)
9913 iface = last = tmp;
9914 else
9915 last->next = tmp;
9916 while (last->next)
9917 last = last->next;
9918 }
9919
9920 pos = buf;
9921 end = buf + len;
9922 for (tmp = iface; tmp; tmp = tmp->next) {
9923 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
9924 tmp->drv_name, tmp->ifname,
9925 tmp->desc ? tmp->desc : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009926 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009927 *pos = '\0';
9928 break;
9929 }
9930 pos += res;
9931 }
9932
9933 wpa_free_iface_info(iface);
9934
9935 return pos - buf;
9936}
9937
9938
9939static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08009940 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009941 char *buf, int len)
9942{
9943 int res;
9944 char *pos, *end;
9945 struct wpa_supplicant *wpa_s;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08009946 int show_ctrl = 0;
9947
9948 if (input)
9949 show_ctrl = !!os_strstr(input, "ctrl");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009950
9951 wpa_s = global->ifaces;
9952 pos = buf;
9953 end = buf + len;
9954
9955 while (wpa_s) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08009956 if (show_ctrl)
9957 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
9958 wpa_s->ifname,
9959 wpa_s->conf->ctrl_interface ?
9960 wpa_s->conf->ctrl_interface : "N/A");
9961 else
9962 res = os_snprintf(pos, end - pos, "%s\n",
9963 wpa_s->ifname);
9964
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009965 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009966 *pos = '\0';
9967 break;
9968 }
9969 pos += res;
9970 wpa_s = wpa_s->next;
9971 }
9972 return pos - buf;
9973}
9974
9975
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07009976static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
9977 const char *ifname,
9978 char *cmd, size_t *resp_len)
9979{
9980 struct wpa_supplicant *wpa_s;
9981
9982 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
9983 if (os_strcmp(ifname, wpa_s->ifname) == 0)
9984 break;
9985 }
9986
9987 if (wpa_s == NULL) {
9988 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
9989 if (resp)
9990 *resp_len = os_strlen(resp);
9991 else
9992 *resp_len = 1;
9993 return resp;
9994 }
9995
9996 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
9997}
9998
9999
10000static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
10001 char *buf, size_t *resp_len)
10002{
10003#ifdef CONFIG_P2P
10004 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070010005 "LIST_NETWORKS",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010006 "P2P_FIND",
10007 "P2P_STOP_FIND",
10008 "P2P_LISTEN",
10009 "P2P_GROUP_ADD",
10010 "P2P_GET_PASSPHRASE",
10011 "P2P_SERVICE_UPDATE",
10012 "P2P_SERVICE_FLUSH",
10013 "P2P_FLUSH",
10014 "P2P_CANCEL",
10015 "P2P_PRESENCE_REQ",
10016 "P2P_EXT_LISTEN",
10017 NULL
10018 };
10019 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080010020#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070010021 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080010022#endif /* ANDROID */
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070010023 "GET_NETWORK ",
10024 "REMOVE_NETWORK ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010025 "P2P_FIND ",
10026 "P2P_CONNECT ",
10027 "P2P_LISTEN ",
10028 "P2P_GROUP_REMOVE ",
10029 "P2P_GROUP_ADD ",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010030 "P2P_GROUP_MEMBER ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010031 "P2P_PROV_DISC ",
10032 "P2P_SERV_DISC_REQ ",
10033 "P2P_SERV_DISC_CANCEL_REQ ",
10034 "P2P_SERV_DISC_RESP ",
10035 "P2P_SERV_DISC_EXTERNAL ",
10036 "P2P_SERVICE_ADD ",
10037 "P2P_SERVICE_DEL ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010038 "P2P_SERVICE_REP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010039 "P2P_REJECT ",
10040 "P2P_INVITE ",
10041 "P2P_PEER ",
10042 "P2P_SET ",
10043 "P2P_UNAUTHORIZE ",
10044 "P2P_PRESENCE_REQ ",
10045 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070010046 "P2P_REMOVE_CLIENT ",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080010047 "WPS_NFC_TOKEN ",
10048 "WPS_NFC_TAG_READ ",
Dmitry Shmidt413dde72014-04-11 10:23:22 -070010049 "NFC_GET_HANDOVER_SEL ",
10050 "NFC_GET_HANDOVER_REQ ",
10051 "NFC_REPORT_HANDOVER ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010052 "P2P_ASP_PROVISION ",
10053 "P2P_ASP_PROVISION_RESP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010054 NULL
10055 };
10056 int found = 0;
10057 int i;
10058
10059 if (global->p2p_init_wpa_s == NULL)
10060 return NULL;
10061
10062 for (i = 0; !found && cmd[i]; i++) {
10063 if (os_strcmp(buf, cmd[i]) == 0)
10064 found = 1;
10065 }
10066
10067 for (i = 0; !found && prefix[i]; i++) {
10068 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
10069 found = 1;
10070 }
10071
10072 if (found)
10073 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
10074 buf, resp_len);
10075#endif /* CONFIG_P2P */
10076 return NULL;
10077}
10078
10079
10080static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
10081 char *buf, size_t *resp_len)
10082{
10083#ifdef CONFIG_WIFI_DISPLAY
10084 if (global->p2p_init_wpa_s == NULL)
10085 return NULL;
10086 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
10087 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
10088 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
10089 buf, resp_len);
10090#endif /* CONFIG_WIFI_DISPLAY */
10091 return NULL;
10092}
10093
10094
10095static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
10096 char *buf, size_t *resp_len)
10097{
10098 char *ret;
10099
10100 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
10101 if (ret)
10102 return ret;
10103
10104 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
10105 if (ret)
10106 return ret;
10107
10108 return NULL;
10109}
10110
10111
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010112static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
10113{
10114 char *value;
10115
10116 value = os_strchr(cmd, ' ');
10117 if (value == NULL)
10118 return -1;
10119 *value++ = '\0';
10120
10121 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
10122
10123#ifdef CONFIG_WIFI_DISPLAY
10124 if (os_strcasecmp(cmd, "wifi_display") == 0) {
10125 wifi_display_enable(global, !!atoi(value));
10126 return 0;
10127 }
10128#endif /* CONFIG_WIFI_DISPLAY */
10129
Dmitry Shmidt61593f02014-04-21 16:27:35 -070010130 /* Restore cmd to its original value to allow redirection */
10131 value[-1] = ' ';
10132
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010133 return -1;
10134}
10135
10136
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010137static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
10138 char *cmd)
10139{
10140 struct wpa_supplicant *wpa_s[2]; /* src, dst */
10141 char *p;
10142 unsigned int i;
10143
10144 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
10145 * <variable name> */
10146
10147 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
10148 p = os_strchr(cmd, ' ');
10149 if (p == NULL)
10150 return -1;
10151 *p = '\0';
10152
10153 wpa_s[i] = global->ifaces;
10154 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
10155 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
10156 break;
10157 }
10158
10159 if (!wpa_s[i]) {
10160 wpa_printf(MSG_DEBUG,
10161 "CTRL_IFACE: Could not find iface=%s", cmd);
10162 return -1;
10163 }
10164
10165 cmd = p + 1;
10166 }
10167
10168 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
10169}
10170
10171
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010172#ifndef CONFIG_NO_CONFIG_WRITE
10173static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
10174{
Dmitry Shmidt61593f02014-04-21 16:27:35 -070010175 int ret = 0, saved = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010176 struct wpa_supplicant *wpa_s;
10177
10178 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
10179 if (!wpa_s->conf->update_config) {
10180 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
10181 continue;
10182 }
10183
10184 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
10185 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
10186 ret = 1;
10187 } else {
10188 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
Dmitry Shmidt61593f02014-04-21 16:27:35 -070010189 saved++;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010190 }
10191 }
10192
Dmitry Shmidt61593f02014-04-21 16:27:35 -070010193 if (!saved && !ret) {
10194 wpa_dbg(wpa_s, MSG_DEBUG,
10195 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
10196 ret = 1;
10197 }
10198
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010199 return ret;
10200}
10201#endif /* CONFIG_NO_CONFIG_WRITE */
10202
10203
10204static int wpas_global_ctrl_iface_status(struct wpa_global *global,
10205 char *buf, size_t buflen)
10206{
10207 char *pos, *end;
10208 int ret;
10209 struct wpa_supplicant *wpa_s;
10210
10211 pos = buf;
10212 end = buf + buflen;
10213
10214#ifdef CONFIG_P2P
10215 if (global->p2p && !global->p2p_disabled) {
10216 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
10217 "\n"
10218 "p2p_state=%s\n",
10219 MAC2STR(global->p2p_dev_addr),
10220 p2p_get_state_txt(global->p2p));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010221 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010222 return pos - buf;
10223 pos += ret;
10224 } else if (global->p2p) {
10225 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010226 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010227 return pos - buf;
10228 pos += ret;
10229 }
10230#endif /* CONFIG_P2P */
10231
10232#ifdef CONFIG_WIFI_DISPLAY
10233 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
10234 !!global->wifi_display);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010235 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010236 return pos - buf;
10237 pos += ret;
10238#endif /* CONFIG_WIFI_DISPLAY */
10239
10240 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
10241 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
10242 "address=" MACSTR "\n",
10243 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010244 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010245 return pos - buf;
10246 pos += ret;
10247 }
10248
10249 return pos - buf;
10250}
10251
10252
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010253#ifdef CONFIG_FST
10254
10255static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
10256 char *cmd, char *buf,
10257 size_t reply_size)
10258{
10259 char ifname[IFNAMSIZ + 1];
10260 struct fst_iface_cfg cfg;
10261 struct wpa_supplicant *wpa_s;
10262 struct fst_wpa_obj iface_obj;
10263
10264 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
10265 wpa_s = wpa_supplicant_get_iface(global, ifname);
10266 if (wpa_s) {
10267 if (wpa_s->fst) {
10268 wpa_printf(MSG_INFO, "FST: Already attached");
10269 return -1;
10270 }
10271 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
10272 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
10273 &iface_obj, &cfg);
10274 if (wpa_s->fst)
10275 return os_snprintf(buf, reply_size, "OK\n");
10276 }
10277 }
10278
10279 return -1;
10280}
10281
10282
10283static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
10284 char *cmd, char *buf,
10285 size_t reply_size)
10286{
10287 char ifname[IFNAMSIZ + 1];
10288 struct wpa_supplicant *wpa_s;
10289
10290 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
10291 wpa_s = wpa_supplicant_get_iface(global, ifname);
10292 if (wpa_s) {
10293 if (!fst_iface_detach(ifname)) {
10294 wpa_s->fst = NULL;
10295 return os_snprintf(buf, reply_size, "OK\n");
10296 }
10297 }
10298 }
10299
10300 return -1;
10301}
10302
10303#endif /* CONFIG_FST */
10304
10305
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010306char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
10307 char *buf, size_t *resp_len)
10308{
10309 char *reply;
10310 const int reply_size = 2048;
10311 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010312 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010313
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010314 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
10315 char *pos = os_strchr(buf + 7, ' ');
10316 if (pos) {
10317 *pos++ = '\0';
10318 return wpas_global_ctrl_iface_ifname(global,
10319 buf + 7, pos,
10320 resp_len);
10321 }
10322 }
10323
10324 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
10325 if (reply)
10326 return reply;
10327
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010328 if (os_strcmp(buf, "PING") == 0)
10329 level = MSG_EXCESSIVE;
10330 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010331 (const u8 *) buf, os_strlen(buf));
10332
10333 reply = os_malloc(reply_size);
10334 if (reply == NULL) {
10335 *resp_len = 1;
10336 return NULL;
10337 }
10338
10339 os_memcpy(reply, "OK\n", 3);
10340 reply_len = 3;
10341
10342 if (os_strcmp(buf, "PING") == 0) {
10343 os_memcpy(reply, "PONG\n", 5);
10344 reply_len = 5;
10345 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
10346 if (wpa_supplicant_global_iface_add(global, buf + 14))
10347 reply_len = -1;
10348 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
10349 if (wpa_supplicant_global_iface_remove(global, buf + 17))
10350 reply_len = -1;
10351 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
10352 reply_len = wpa_supplicant_global_iface_list(
10353 global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010354 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010355 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010356 global, buf + 10, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010357#ifdef CONFIG_FST
10358 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
10359 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
10360 reply,
10361 reply_size);
10362 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
10363 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
10364 reply,
10365 reply_size);
10366 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
10367 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
10368#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010369 } else if (os_strcmp(buf, "TERMINATE") == 0) {
10370 wpa_supplicant_terminate_proc(global);
10371 } else if (os_strcmp(buf, "SUSPEND") == 0) {
10372 wpas_notify_suspend(global);
10373 } else if (os_strcmp(buf, "RESUME") == 0) {
10374 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010375 } else if (os_strncmp(buf, "SET ", 4) == 0) {
Dmitry Shmidt61593f02014-04-21 16:27:35 -070010376 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
10377#ifdef CONFIG_P2P
10378 if (global->p2p_init_wpa_s) {
10379 os_free(reply);
10380 /* Check if P2P redirection would work for this
10381 * command. */
10382 return wpa_supplicant_ctrl_iface_process(
10383 global->p2p_init_wpa_s,
10384 buf, resp_len);
10385 }
10386#endif /* CONFIG_P2P */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010387 reply_len = -1;
Dmitry Shmidt61593f02014-04-21 16:27:35 -070010388 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010389 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
10390 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
10391 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070010392#ifndef CONFIG_NO_CONFIG_WRITE
10393 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
10394 if (wpas_global_ctrl_iface_save_config(global))
10395 reply_len = -1;
10396#endif /* CONFIG_NO_CONFIG_WRITE */
10397 } else if (os_strcmp(buf, "STATUS") == 0) {
10398 reply_len = wpas_global_ctrl_iface_status(global, reply,
10399 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080010400#ifdef CONFIG_MODULE_TESTS
10401 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080010402 if (wpas_module_tests() < 0)
10403 reply_len = -1;
10404#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010405 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
10406 if (wpa_debug_reopen_file() < 0)
10407 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010408 } else {
10409 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
10410 reply_len = 16;
10411 }
10412
10413 if (reply_len < 0) {
10414 os_memcpy(reply, "FAIL\n", 5);
10415 reply_len = 5;
10416 }
10417
10418 *resp_len = reply_len;
10419 return reply;
10420}