blob: 9f5d4f403b83b7b7101cfd57d1330501b1030599 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant / Control interface (shared code for all backends)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003 * Copyright (c) 2004-2014, 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"
10
11#include "utils/common.h"
12#include "utils/eloop.h"
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080013#include "utils/uuid.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014#include "common/version.h"
15#include "common/ieee802_11_defs.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070016#include "common/ieee802_11_common.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070017#include "common/wpa_ctrl.h"
18#include "eap_peer/eap.h"
19#include "eapol_supp/eapol_supp_sm.h"
20#include "rsn_supp/wpa.h"
21#include "rsn_supp/preauth.h"
22#include "rsn_supp/pmksa_cache.h"
23#include "l2_packet/l2_packet.h"
24#include "wps/wps.h"
25#include "config.h"
26#include "wpa_supplicant_i.h"
27#include "driver_i.h"
28#include "wps_supplicant.h"
29#include "ibss_rsn.h"
30#include "ap.h"
31#include "p2p_supplicant.h"
32#include "p2p/p2p.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070033#include "hs20_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070034#include "wifi_display.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070035#include "notify.h"
36#include "bss.h"
37#include "scan.h"
38#include "ctrl_iface.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080039#include "interworking.h"
Dmitry Shmidte19501d2011-03-16 14:32:18 -070040#include "blacklist.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070041#include "autoscan.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080042#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044static int wpa_supplicant_global_iface_list(struct wpa_global *global,
45 char *buf, int len);
46static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
47 char *buf, int len);
48
49
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080050static int pno_start(struct wpa_supplicant *wpa_s)
51{
Dmitry Shmidt56052862013-10-04 10:23:25 -070052 int ret, interval;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080053 size_t i, num_ssid;
54 struct wpa_ssid *ssid;
55 struct wpa_driver_scan_params params;
56
Dmitry Shmidt18463232014-01-24 12:29:41 -080057 if (wpa_s->pno || wpa_s->pno_sched_pending)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080058 return 0;
59
Dmitry Shmidt4d9ecd82013-11-05 18:08:27 -080060 if ((wpa_s->wpa_state > WPA_SCANNING) &&
61 (wpa_s->wpa_state <= WPA_COMPLETED)) {
62 wpa_printf(MSG_ERROR, "PNO: In assoc process");
63 return -EAGAIN;
64 }
65
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080066 if (wpa_s->wpa_state == WPA_SCANNING) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080067 wpa_supplicant_cancel_scan(wpa_s);
Dmitry Shmidt18463232014-01-24 12:29:41 -080068 if (wpa_s->sched_scanning) {
69 wpa_printf(MSG_DEBUG, "Schedule PNO on completion of "
70 "ongoing sched scan");
71 wpa_supplicant_cancel_sched_scan(wpa_s);
72 wpa_s->pno_sched_pending = 1;
73 return 0;
74 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080075 }
76
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080077 os_memset(&params, 0, sizeof(params));
78
79 num_ssid = 0;
80 ssid = wpa_s->conf->ssid;
81 while (ssid) {
Dmitry Shmidt04949592012-07-19 12:16:46 -070082 if (!wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080083 num_ssid++;
84 ssid = ssid->next;
85 }
86 if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
87 wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
88 "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
89 num_ssid = WPAS_MAX_SCAN_SSIDS;
90 }
91
92 if (num_ssid == 0) {
93 wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
94 return -1;
95 }
96
97 params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
98 num_ssid);
99 if (params.filter_ssids == NULL)
100 return -1;
101 i = 0;
102 ssid = wpa_s->conf->ssid;
103 while (ssid) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700104 if (!wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800105 params.ssids[i].ssid = ssid->ssid;
106 params.ssids[i].ssid_len = ssid->ssid_len;
107 params.num_ssids++;
108 os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
109 ssid->ssid_len);
110 params.filter_ssids[i].ssid_len = ssid->ssid_len;
111 params.num_filter_ssids++;
112 i++;
113 if (i == num_ssid)
114 break;
115 }
116 ssid = ssid->next;
117 }
118
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700119 if (wpa_s->conf->filter_rssi)
120 params.filter_rssi = wpa_s->conf->filter_rssi;
121
Dmitry Shmidt56052862013-10-04 10:23:25 -0700122 interval = wpa_s->conf->sched_scan_interval ?
123 wpa_s->conf->sched_scan_interval : 10;
124
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800125 ret = wpa_supplicant_start_sched_scan(wpa_s, &params, interval);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800126 os_free(params.filter_ssids);
127 if (ret == 0)
128 wpa_s->pno = 1;
129 return ret;
130}
131
132
133static int pno_stop(struct wpa_supplicant *wpa_s)
134{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800135 int ret = 0;
136
Dmitry Shmidt18463232014-01-24 12:29:41 -0800137 if (wpa_s->pno || wpa_s->sched_scanning) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800138 wpa_s->pno = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800139 ret = wpa_supplicant_stop_sched_scan(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800140 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800141
Dmitry Shmidt18463232014-01-24 12:29:41 -0800142 wpa_s->pno_sched_pending = 0;
143
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800144 if (wpa_s->wpa_state == WPA_SCANNING)
145 wpa_supplicant_req_scan(wpa_s, 0, 0);
146
147 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800148}
149
150
Dmitry Shmidt04949592012-07-19 12:16:46 -0700151static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
152{
153 char *pos;
154 u8 addr[ETH_ALEN], *filter = NULL, *n;
155 size_t count = 0;
156
157 pos = val;
158 while (pos) {
159 if (*pos == '\0')
160 break;
161 if (hwaddr_aton(pos, addr)) {
162 os_free(filter);
163 return -1;
164 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700165 n = os_realloc_array(filter, count + 1, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700166 if (n == NULL) {
167 os_free(filter);
168 return -1;
169 }
170 filter = n;
171 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
172 count++;
173
174 pos = os_strchr(pos, ' ');
175 if (pos)
176 pos++;
177 }
178
179 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
180 os_free(wpa_s->bssid_filter);
181 wpa_s->bssid_filter = filter;
182 wpa_s->bssid_filter_count = count;
183
184 return 0;
185}
186
187
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800188static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
189{
190 char *pos;
191 u8 addr[ETH_ALEN], *bssid = NULL, *n;
192 struct wpa_ssid_value *ssid = NULL, *ns;
193 size_t count = 0, ssid_count = 0;
194 struct wpa_ssid *c;
195
196 /*
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800197 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800198 * SSID_SPEC ::= ssid <SSID_HEX>
199 * BSSID_SPEC ::= bssid <BSSID_HEX>
200 */
201
202 pos = val;
203 while (pos) {
204 if (*pos == '\0')
205 break;
206 if (os_strncmp(pos, "bssid ", 6) == 0) {
207 int res;
208 pos += 6;
209 res = hwaddr_aton2(pos, addr);
210 if (res < 0) {
211 os_free(ssid);
212 os_free(bssid);
213 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
214 "BSSID value '%s'", pos);
215 return -1;
216 }
217 pos += res;
218 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
219 if (n == NULL) {
220 os_free(ssid);
221 os_free(bssid);
222 return -1;
223 }
224 bssid = n;
225 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
226 count++;
227 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
228 char *end;
229 pos += 5;
230
231 end = pos;
232 while (*end) {
233 if (*end == '\0' || *end == ' ')
234 break;
235 end++;
236 }
237
238 ns = os_realloc_array(ssid, ssid_count + 1,
239 sizeof(struct wpa_ssid_value));
240 if (ns == NULL) {
241 os_free(ssid);
242 os_free(bssid);
243 return -1;
244 }
245 ssid = ns;
246
247 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
248 hexstr2bin(pos, ssid[ssid_count].ssid,
249 (end - pos) / 2) < 0) {
250 os_free(ssid);
251 os_free(bssid);
252 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
253 "SSID value '%s'", pos);
254 return -1;
255 }
256 ssid[ssid_count].ssid_len = (end - pos) / 2;
257 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
258 ssid[ssid_count].ssid,
259 ssid[ssid_count].ssid_len);
260 ssid_count++;
261 pos = end;
262 } else {
263 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
264 "'%s'", pos);
265 os_free(ssid);
266 os_free(bssid);
267 return -1;
268 }
269
270 pos = os_strchr(pos, ' ');
271 if (pos)
272 pos++;
273 }
274
275 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
276 os_free(wpa_s->disallow_aps_bssid);
277 wpa_s->disallow_aps_bssid = bssid;
278 wpa_s->disallow_aps_bssid_count = count;
279
280 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
281 os_free(wpa_s->disallow_aps_ssid);
282 wpa_s->disallow_aps_ssid = ssid;
283 wpa_s->disallow_aps_ssid_count = ssid_count;
284
285 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
286 return 0;
287
288 c = wpa_s->current_ssid;
289 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
290 return 0;
291
292 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
293 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
294 return 0;
295
296 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
297 "because current AP was marked disallowed");
298
299#ifdef CONFIG_SME
300 wpa_s->sme.prev_bssid_set = 0;
301#endif /* CONFIG_SME */
302 wpa_s->reassociate = 1;
303 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
304 wpa_supplicant_req_scan(wpa_s, 0, 0);
305
306 return 0;
307}
308
309
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
311 char *cmd)
312{
313 char *value;
314 int ret = 0;
315
316 value = os_strchr(cmd, ' ');
317 if (value == NULL)
318 return -1;
319 *value++ = '\0';
320
321 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
322 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
323 eapol_sm_configure(wpa_s->eapol,
324 atoi(value), -1, -1, -1);
325 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
326 eapol_sm_configure(wpa_s->eapol,
327 -1, atoi(value), -1, -1);
328 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
329 eapol_sm_configure(wpa_s->eapol,
330 -1, -1, atoi(value), -1);
331 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
332 eapol_sm_configure(wpa_s->eapol,
333 -1, -1, -1, atoi(value));
334 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
335 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
336 atoi(value)))
337 ret = -1;
338 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
339 0) {
340 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
341 atoi(value)))
342 ret = -1;
343 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
344 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
345 ret = -1;
346 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
347 wpa_s->wps_fragment_size = atoi(value);
348#ifdef CONFIG_WPS_TESTING
349 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
350 long int val;
351 val = strtol(value, NULL, 0);
352 if (val < 0 || val > 0xff) {
353 ret = -1;
354 wpa_printf(MSG_DEBUG, "WPS: Invalid "
355 "wps_version_number %ld", val);
356 } else {
357 wps_version_number = val;
358 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
359 "version %u.%u",
360 (wps_version_number & 0xf0) >> 4,
361 wps_version_number & 0x0f);
362 }
363 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
364 wps_testing_dummy_cred = atoi(value);
365 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
366 wps_testing_dummy_cred);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800367 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
368 wps_corrupt_pkhash = atoi(value);
369 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
370 wps_corrupt_pkhash);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700371#endif /* CONFIG_WPS_TESTING */
372 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
373 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
374 ret = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800375#ifdef CONFIG_TDLS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700376#ifdef CONFIG_TDLS_TESTING
377 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
378 extern unsigned int tdls_testing;
379 tdls_testing = strtol(value, NULL, 0);
380 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
381#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700382 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
383 int disabled = atoi(value);
384 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
385 if (disabled) {
386 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
387 ret = -1;
388 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
389 ret = -1;
390 wpa_tdls_enable(wpa_s->wpa, !disabled);
391#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800392 } else if (os_strcasecmp(cmd, "pno") == 0) {
393 if (atoi(value))
394 ret = pno_start(wpa_s);
395 else
396 ret = pno_stop(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700397 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
398 int disabled = atoi(value);
399 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
400 ret = -1;
401 else if (disabled)
402 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
403 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
404 if (os_strcmp(value, "disable") == 0)
405 wpa_s->set_sta_uapsd = 0;
406 else {
407 int be, bk, vi, vo;
408 char *pos;
409 /* format: BE,BK,VI,VO;max SP Length */
410 be = atoi(value);
411 pos = os_strchr(value, ',');
412 if (pos == NULL)
413 return -1;
414 pos++;
415 bk = atoi(pos);
416 pos = os_strchr(pos, ',');
417 if (pos == NULL)
418 return -1;
419 pos++;
420 vi = atoi(pos);
421 pos = os_strchr(pos, ',');
422 if (pos == NULL)
423 return -1;
424 pos++;
425 vo = atoi(pos);
426 /* ignore max SP Length for now */
427
428 wpa_s->set_sta_uapsd = 1;
429 wpa_s->sta_uapsd = 0;
430 if (be)
431 wpa_s->sta_uapsd |= BIT(0);
432 if (bk)
433 wpa_s->sta_uapsd |= BIT(1);
434 if (vi)
435 wpa_s->sta_uapsd |= BIT(2);
436 if (vo)
437 wpa_s->sta_uapsd |= BIT(3);
438 }
Jouni Malinen21d6bc82012-04-10 16:17:59 -0700439 } else if (os_strcasecmp(cmd, "ps") == 0) {
440 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700441#ifdef CONFIG_WIFI_DISPLAY
442 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800443 int enabled = !!atoi(value);
444 if (enabled && !wpa_s->global->p2p)
445 ret = -1;
446 else
447 wifi_display_enable(wpa_s->global, enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700448#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700449 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
450 ret = set_bssid_filter(wpa_s, value);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800451 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
452 ret = set_disallow_aps(wpa_s, value);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800453 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
454 wpa_s->no_keep_alive = !!atoi(value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700455 } else {
456 value[-1] = '=';
457 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
458 if (ret == 0)
459 wpa_supplicant_update_config(wpa_s);
460 }
461
462 return ret;
463}
464
465
466static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
467 char *cmd, char *buf, size_t buflen)
468{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700469 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700470
471 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
472
473 if (os_strcmp(cmd, "version") == 0) {
474 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700475 } else if (os_strcasecmp(cmd, "country") == 0) {
476 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
477 res = os_snprintf(buf, buflen, "%c%c",
478 wpa_s->conf->country[0],
479 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700480#ifdef CONFIG_WIFI_DISPLAY
481 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800482 int enabled;
483 if (wpa_s->global->p2p == NULL ||
484 wpa_s->global->p2p_disabled)
485 enabled = 0;
486 else
487 enabled = wpa_s->global->wifi_display;
488 res = os_snprintf(buf, buflen, "%d", enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700489 if (res < 0 || (unsigned int) res >= buflen)
490 return -1;
491 return res;
492#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700493#ifdef CONFIG_TESTING_GET_GTK
494 } else if (os_strcmp(cmd, "gtk") == 0) {
495 if (wpa_s->last_gtk_len == 0)
496 return -1;
497 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
498 wpa_s->last_gtk_len);
499 return res;
500#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501 }
502
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700503 if (res < 0 || (unsigned int) res >= buflen)
504 return -1;
505 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700506}
507
508
509#ifdef IEEE8021X_EAPOL
510static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
511 char *addr)
512{
513 u8 bssid[ETH_ALEN];
514 struct wpa_ssid *ssid = wpa_s->current_ssid;
515
516 if (hwaddr_aton(addr, bssid)) {
517 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
518 "'%s'", addr);
519 return -1;
520 }
521
522 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
523 rsn_preauth_deinit(wpa_s->wpa);
524 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
525 return -1;
526
527 return 0;
528}
529#endif /* IEEE8021X_EAPOL */
530
531
532#ifdef CONFIG_PEERKEY
533/* MLME-STKSTART.request(peer) */
534static int wpa_supplicant_ctrl_iface_stkstart(
535 struct wpa_supplicant *wpa_s, char *addr)
536{
537 u8 peer[ETH_ALEN];
538
539 if (hwaddr_aton(addr, peer)) {
540 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
541 "address '%s'", addr);
542 return -1;
543 }
544
545 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
546 MAC2STR(peer));
547
548 return wpa_sm_stkstart(wpa_s->wpa, peer);
549}
550#endif /* CONFIG_PEERKEY */
551
552
553#ifdef CONFIG_TDLS
554
555static int wpa_supplicant_ctrl_iface_tdls_discover(
556 struct wpa_supplicant *wpa_s, char *addr)
557{
558 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800559 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700560
561 if (hwaddr_aton(addr, peer)) {
562 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
563 "address '%s'", addr);
564 return -1;
565 }
566
567 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
568 MAC2STR(peer));
569
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800570 if (wpa_tdls_is_external_setup(wpa_s->wpa))
571 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
572 else
573 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
574
575 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700576}
577
578
579static int wpa_supplicant_ctrl_iface_tdls_setup(
580 struct wpa_supplicant *wpa_s, char *addr)
581{
582 u8 peer[ETH_ALEN];
583 int ret;
584
585 if (hwaddr_aton(addr, peer)) {
586 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
587 "address '%s'", addr);
588 return -1;
589 }
590
591 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
592 MAC2STR(peer));
593
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800594 if ((wpa_s->conf->tdls_external_control) &&
595 wpa_tdls_is_external_setup(wpa_s->wpa))
596 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
597
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800598 wpa_tdls_remove(wpa_s->wpa, peer);
599
600 if (wpa_tdls_is_external_setup(wpa_s->wpa))
601 ret = wpa_tdls_start(wpa_s->wpa, peer);
602 else
603 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800604
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700605 return ret;
606}
607
608
609static int wpa_supplicant_ctrl_iface_tdls_teardown(
610 struct wpa_supplicant *wpa_s, char *addr)
611{
612 u8 peer[ETH_ALEN];
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700613 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700614
615 if (hwaddr_aton(addr, peer)) {
616 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
617 "address '%s'", addr);
618 return -1;
619 }
620
621 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
622 MAC2STR(peer));
623
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800624 if ((wpa_s->conf->tdls_external_control) &&
625 wpa_tdls_is_external_setup(wpa_s->wpa))
626 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
627
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700628 if (wpa_tdls_is_external_setup(wpa_s->wpa))
629 ret = wpa_tdls_teardown_link(
630 wpa_s->wpa, peer,
631 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
632 else
633 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
634
635 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700636}
637
638#endif /* CONFIG_TDLS */
639
640
641#ifdef CONFIG_IEEE80211R
642static int wpa_supplicant_ctrl_iface_ft_ds(
643 struct wpa_supplicant *wpa_s, char *addr)
644{
645 u8 target_ap[ETH_ALEN];
646 struct wpa_bss *bss;
647 const u8 *mdie;
648
649 if (hwaddr_aton(addr, target_ap)) {
650 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
651 "address '%s'", addr);
652 return -1;
653 }
654
655 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
656
657 bss = wpa_bss_get_bssid(wpa_s, target_ap);
658 if (bss)
659 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
660 else
661 mdie = NULL;
662
663 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
664}
665#endif /* CONFIG_IEEE80211R */
666
667
668#ifdef CONFIG_WPS
669static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
670 char *cmd)
671{
672 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -0700673#ifdef CONFIG_P2P
674 u8 p2p_dev_addr[ETH_ALEN];
675#endif /* CONFIG_P2P */
676#ifdef CONFIG_AP
677 u8 *_p2p_dev_addr = NULL;
678#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800679
Dmitry Shmidtc0a8db02013-11-08 11:18:33 -0800680 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700681 _bssid = NULL;
682#ifdef CONFIG_P2P
683 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
684 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
685 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
686 "P2P Device Address '%s'",
687 cmd + 13);
688 return -1;
689 }
690 _p2p_dev_addr = p2p_dev_addr;
691#endif /* CONFIG_P2P */
692 } else if (hwaddr_aton(cmd, bssid)) {
693 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
694 cmd);
695 return -1;
696 }
697
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800698#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700699 if (wpa_s->ap_iface)
700 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
701#endif /* CONFIG_AP */
702
703 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
704}
705
706
707static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
708 char *cmd, char *buf,
709 size_t buflen)
710{
711 u8 bssid[ETH_ALEN], *_bssid = bssid;
712 char *pin;
713 int ret;
714
715 pin = os_strchr(cmd, ' ');
716 if (pin)
717 *pin++ = '\0';
718
719 if (os_strcmp(cmd, "any") == 0)
720 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800721 else if (os_strcmp(cmd, "get") == 0) {
722 ret = wps_generate_pin();
723 goto done;
724 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
726 cmd);
727 return -1;
728 }
729
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800730#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800731 if (wpa_s->ap_iface) {
732 int timeout = 0;
733 char *pos;
734
735 if (pin) {
736 pos = os_strchr(pin, ' ');
737 if (pos) {
738 *pos++ = '\0';
739 timeout = atoi(pos);
740 }
741 }
742
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700743 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800744 buf, buflen, timeout);
745 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700746#endif /* CONFIG_AP */
747
748 if (pin) {
749 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
750 DEV_PW_DEFAULT);
751 if (ret < 0)
752 return -1;
753 ret = os_snprintf(buf, buflen, "%s", pin);
754 if (ret < 0 || (size_t) ret >= buflen)
755 return -1;
756 return ret;
757 }
758
759 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
760 if (ret < 0)
761 return -1;
762
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800763done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764 /* Return the generated PIN */
765 ret = os_snprintf(buf, buflen, "%08d", ret);
766 if (ret < 0 || (size_t) ret >= buflen)
767 return -1;
768 return ret;
769}
770
771
772static int wpa_supplicant_ctrl_iface_wps_check_pin(
773 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
774{
775 char pin[9];
776 size_t len;
777 char *pos;
778 int ret;
779
780 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
781 (u8 *) cmd, os_strlen(cmd));
782 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
783 if (*pos < '0' || *pos > '9')
784 continue;
785 pin[len++] = *pos;
786 if (len == 9) {
787 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
788 return -1;
789 }
790 }
791 if (len != 4 && len != 8) {
792 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
793 return -1;
794 }
795 pin[len] = '\0';
796
797 if (len == 8) {
798 unsigned int pin_val;
799 pin_val = atoi(pin);
800 if (!wps_pin_valid(pin_val)) {
801 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
802 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
803 if (ret < 0 || (size_t) ret >= buflen)
804 return -1;
805 return ret;
806 }
807 }
808
809 ret = os_snprintf(buf, buflen, "%s", pin);
810 if (ret < 0 || (size_t) ret >= buflen)
811 return -1;
812
813 return ret;
814}
815
816
Dmitry Shmidt04949592012-07-19 12:16:46 -0700817#ifdef CONFIG_WPS_NFC
818
819static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
820 char *cmd)
821{
822 u8 bssid[ETH_ALEN], *_bssid = bssid;
823
824 if (cmd == NULL || cmd[0] == '\0')
825 _bssid = NULL;
826 else if (hwaddr_aton(cmd, bssid))
827 return -1;
828
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800829 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
830 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700831}
832
833
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800834static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
835 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
836{
837 int ndef;
838 struct wpabuf *buf;
839 int res;
Dmitry Shmidt1e78e762013-04-02 11:05:36 -0700840 char *pos;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800841
Dmitry Shmidt1e78e762013-04-02 11:05:36 -0700842 pos = os_strchr(cmd, ' ');
843 if (pos)
844 *pos++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800845 if (os_strcmp(cmd, "WPS") == 0)
846 ndef = 0;
847 else if (os_strcmp(cmd, "NDEF") == 0)
848 ndef = 1;
849 else
850 return -1;
851
Dmitry Shmidt1e78e762013-04-02 11:05:36 -0700852 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800853 if (buf == NULL)
854 return -1;
855
856 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
857 wpabuf_len(buf));
858 reply[res++] = '\n';
859 reply[res] = '\0';
860
861 wpabuf_free(buf);
862
863 return res;
864}
865
866
Dmitry Shmidt04949592012-07-19 12:16:46 -0700867static int wpa_supplicant_ctrl_iface_wps_nfc_token(
868 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
869{
870 int ndef;
871 struct wpabuf *buf;
872 int res;
873
874 if (os_strcmp(cmd, "WPS") == 0)
875 ndef = 0;
876 else if (os_strcmp(cmd, "NDEF") == 0)
877 ndef = 1;
878 else
879 return -1;
880
881 buf = wpas_wps_nfc_token(wpa_s, ndef);
882 if (buf == NULL)
883 return -1;
884
885 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
886 wpabuf_len(buf));
887 reply[res++] = '\n';
888 reply[res] = '\0';
889
890 wpabuf_free(buf);
891
892 return res;
893}
894
895
896static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
897 struct wpa_supplicant *wpa_s, char *pos)
898{
899 size_t len;
900 struct wpabuf *buf;
901 int ret;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800902 char *freq;
903 int forced_freq = 0;
904
905 freq = strstr(pos, " freq=");
906 if (freq) {
907 *freq = '\0';
908 freq += 6;
909 forced_freq = atoi(freq);
910 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700911
912 len = os_strlen(pos);
913 if (len & 0x01)
914 return -1;
915 len /= 2;
916
917 buf = wpabuf_alloc(len);
918 if (buf == NULL)
919 return -1;
920 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
921 wpabuf_free(buf);
922 return -1;
923 }
924
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800925 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700926 wpabuf_free(buf);
927
928 return ret;
929}
930
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800931
932static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800933 char *reply, size_t max_len,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800934 int ndef)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800935{
936 struct wpabuf *buf;
937 int res;
938
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800939 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800940 if (buf == NULL)
941 return -1;
942
943 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
944 wpabuf_len(buf));
945 reply[res++] = '\n';
946 reply[res] = '\0';
947
948 wpabuf_free(buf);
949
950 return res;
951}
952
953
Dmitry Shmidt96be6222014-02-13 10:16:51 -0800954#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800955static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
956 char *reply, size_t max_len,
957 int ndef)
958{
959 struct wpabuf *buf;
960 int res;
961
962 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
963 if (buf == NULL) {
964 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
965 return -1;
966 }
967
968 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
969 wpabuf_len(buf));
970 reply[res++] = '\n';
971 reply[res] = '\0';
972
973 wpabuf_free(buf);
974
975 return res;
976}
Dmitry Shmidt96be6222014-02-13 10:16:51 -0800977#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800978
979
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800980static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
981 char *cmd, char *reply,
982 size_t max_len)
983{
984 char *pos;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800985 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800986
987 pos = os_strchr(cmd, ' ');
988 if (pos == NULL)
989 return -1;
990 *pos++ = '\0';
991
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800992 if (os_strcmp(cmd, "WPS") == 0)
993 ndef = 0;
994 else if (os_strcmp(cmd, "NDEF") == 0)
995 ndef = 1;
996 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800997 return -1;
998
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800999 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001000 if (!ndef)
1001 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001002 return wpas_ctrl_nfc_get_handover_req_wps(
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001003 wpa_s, reply, max_len, ndef);
1004 }
1005
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001006#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001007 if (os_strcmp(pos, "P2P-CR") == 0) {
1008 return wpas_ctrl_nfc_get_handover_req_p2p(
1009 wpa_s, reply, max_len, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001010 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001011#endif /* CONFIG_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001012
1013 return -1;
1014}
1015
1016
1017static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001018 char *reply, size_t max_len,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001019 int ndef, int cr, char *uuid)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001020{
1021 struct wpabuf *buf;
1022 int res;
1023
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001024 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001025 if (buf == NULL)
1026 return -1;
1027
1028 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1029 wpabuf_len(buf));
1030 reply[res++] = '\n';
1031 reply[res] = '\0';
1032
1033 wpabuf_free(buf);
1034
1035 return res;
1036}
1037
1038
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001039#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001040static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1041 char *reply, size_t max_len,
1042 int ndef, int tag)
1043{
1044 struct wpabuf *buf;
1045 int res;
1046
1047 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1048 if (buf == NULL)
1049 return -1;
1050
1051 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1052 wpabuf_len(buf));
1053 reply[res++] = '\n';
1054 reply[res] = '\0';
1055
1056 wpabuf_free(buf);
1057
1058 return res;
1059}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001060#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001061
1062
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001063static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1064 char *cmd, char *reply,
1065 size_t max_len)
1066{
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001067 char *pos, *pos2;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001068 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001069
1070 pos = os_strchr(cmd, ' ');
1071 if (pos == NULL)
1072 return -1;
1073 *pos++ = '\0';
1074
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001075 if (os_strcmp(cmd, "WPS") == 0)
1076 ndef = 0;
1077 else if (os_strcmp(cmd, "NDEF") == 0)
1078 ndef = 1;
1079 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001080 return -1;
1081
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001082 pos2 = os_strchr(pos, ' ');
1083 if (pos2)
1084 *pos2++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001085 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001086 if (!ndef)
1087 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001088 return wpas_ctrl_nfc_get_handover_sel_wps(
1089 wpa_s, reply, max_len, ndef,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001090 os_strcmp(pos, "WPS-CR") == 0, pos2);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001091 }
1092
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001093#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001094 if (os_strcmp(pos, "P2P-CR") == 0) {
1095 return wpas_ctrl_nfc_get_handover_sel_p2p(
1096 wpa_s, reply, max_len, ndef, 0);
1097 }
1098
1099 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1100 return wpas_ctrl_nfc_get_handover_sel_p2p(
1101 wpa_s, reply, max_len, ndef, 1);
1102 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001103#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001104
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001105 return -1;
1106}
1107
1108
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001109static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
1110 char *cmd)
1111{
1112 size_t len;
1113 struct wpabuf *buf;
1114 int ret;
1115
1116 len = os_strlen(cmd);
1117 if (len & 0x01)
1118 return -1;
1119 len /= 2;
1120
1121 buf = wpabuf_alloc(len);
1122 if (buf == NULL)
1123 return -1;
1124 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1125 wpabuf_free(buf);
1126 return -1;
1127 }
1128
1129 ret = wpas_wps_nfc_rx_handover_sel(wpa_s, buf);
1130 wpabuf_free(buf);
1131
1132 return ret;
1133}
1134
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001135
1136static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1137 char *cmd)
1138{
1139 size_t len;
1140 struct wpabuf *req, *sel;
1141 int ret;
1142 char *pos, *role, *type, *pos2;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001143#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001144 char *freq;
1145 int forced_freq = 0;
1146
1147 freq = strstr(cmd, " freq=");
1148 if (freq) {
1149 *freq = '\0';
1150 freq += 6;
1151 forced_freq = atoi(freq);
1152 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001153#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001154
1155 role = cmd;
1156 pos = os_strchr(role, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001157 if (pos == NULL) {
1158 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001159 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001160 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001161 *pos++ = '\0';
1162
1163 type = pos;
1164 pos = os_strchr(type, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001165 if (pos == NULL) {
1166 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001167 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001168 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001169 *pos++ = '\0';
1170
1171 pos2 = os_strchr(pos, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001172 if (pos2 == NULL) {
1173 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001174 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001175 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001176 *pos2++ = '\0';
1177
1178 len = os_strlen(pos);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001179 if (len & 0x01) {
1180 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001181 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001182 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001183 len /= 2;
1184
1185 req = wpabuf_alloc(len);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001186 if (req == NULL) {
1187 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001188 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001189 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001190 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001191 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001192 wpabuf_free(req);
1193 return -1;
1194 }
1195
1196 len = os_strlen(pos2);
1197 if (len & 0x01) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001198 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001199 wpabuf_free(req);
1200 return -1;
1201 }
1202 len /= 2;
1203
1204 sel = wpabuf_alloc(len);
1205 if (sel == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001206 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001207 wpabuf_free(req);
1208 return -1;
1209 }
1210 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001211 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001212 wpabuf_free(req);
1213 wpabuf_free(sel);
1214 return -1;
1215 }
1216
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001217 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1218 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1219
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001220 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1221 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001222#ifdef CONFIG_AP
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001223 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1224 {
1225 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1226 if (ret < 0)
1227 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001228#endif /* CONFIG_AP */
1229#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001230 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1231 {
1232 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1233 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1234 {
1235 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1236 forced_freq);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001237#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001238 } else {
1239 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1240 "reported: role=%s type=%s", role, type);
1241 ret = -1;
1242 }
1243 wpabuf_free(req);
1244 wpabuf_free(sel);
1245
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001246 if (ret)
1247 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1248
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001249 return ret;
1250}
1251
Dmitry Shmidt04949592012-07-19 12:16:46 -07001252#endif /* CONFIG_WPS_NFC */
1253
1254
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001255static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1256 char *cmd)
1257{
1258 u8 bssid[ETH_ALEN];
1259 char *pin;
1260 char *new_ssid;
1261 char *new_auth;
1262 char *new_encr;
1263 char *new_key;
1264 struct wps_new_ap_settings ap;
1265
1266 pin = os_strchr(cmd, ' ');
1267 if (pin == NULL)
1268 return -1;
1269 *pin++ = '\0';
1270
1271 if (hwaddr_aton(cmd, bssid)) {
1272 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1273 cmd);
1274 return -1;
1275 }
1276
1277 new_ssid = os_strchr(pin, ' ');
1278 if (new_ssid == NULL)
1279 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1280 *new_ssid++ = '\0';
1281
1282 new_auth = os_strchr(new_ssid, ' ');
1283 if (new_auth == NULL)
1284 return -1;
1285 *new_auth++ = '\0';
1286
1287 new_encr = os_strchr(new_auth, ' ');
1288 if (new_encr == NULL)
1289 return -1;
1290 *new_encr++ = '\0';
1291
1292 new_key = os_strchr(new_encr, ' ');
1293 if (new_key == NULL)
1294 return -1;
1295 *new_key++ = '\0';
1296
1297 os_memset(&ap, 0, sizeof(ap));
1298 ap.ssid_hex = new_ssid;
1299 ap.auth = new_auth;
1300 ap.encr = new_encr;
1301 ap.key_hex = new_key;
1302 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1303}
1304
1305
1306#ifdef CONFIG_AP
1307static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1308 char *cmd, char *buf,
1309 size_t buflen)
1310{
1311 int timeout = 300;
1312 char *pos;
1313 const char *pin_txt;
1314
1315 if (!wpa_s->ap_iface)
1316 return -1;
1317
1318 pos = os_strchr(cmd, ' ');
1319 if (pos)
1320 *pos++ = '\0';
1321
1322 if (os_strcmp(cmd, "disable") == 0) {
1323 wpas_wps_ap_pin_disable(wpa_s);
1324 return os_snprintf(buf, buflen, "OK\n");
1325 }
1326
1327 if (os_strcmp(cmd, "random") == 0) {
1328 if (pos)
1329 timeout = atoi(pos);
1330 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1331 if (pin_txt == NULL)
1332 return -1;
1333 return os_snprintf(buf, buflen, "%s", pin_txt);
1334 }
1335
1336 if (os_strcmp(cmd, "get") == 0) {
1337 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1338 if (pin_txt == NULL)
1339 return -1;
1340 return os_snprintf(buf, buflen, "%s", pin_txt);
1341 }
1342
1343 if (os_strcmp(cmd, "set") == 0) {
1344 char *pin;
1345 if (pos == NULL)
1346 return -1;
1347 pin = pos;
1348 pos = os_strchr(pos, ' ');
1349 if (pos) {
1350 *pos++ = '\0';
1351 timeout = atoi(pos);
1352 }
1353 if (os_strlen(pin) > buflen)
1354 return -1;
1355 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1356 return -1;
1357 return os_snprintf(buf, buflen, "%s", pin);
1358 }
1359
1360 return -1;
1361}
1362#endif /* CONFIG_AP */
1363
1364
1365#ifdef CONFIG_WPS_ER
1366static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1367 char *cmd)
1368{
1369 char *uuid = cmd, *pin, *pos;
1370 u8 addr_buf[ETH_ALEN], *addr = NULL;
1371 pin = os_strchr(uuid, ' ');
1372 if (pin == NULL)
1373 return -1;
1374 *pin++ = '\0';
1375 pos = os_strchr(pin, ' ');
1376 if (pos) {
1377 *pos++ = '\0';
1378 if (hwaddr_aton(pos, addr_buf) == 0)
1379 addr = addr_buf;
1380 }
1381 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1382}
1383
1384
1385static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1386 char *cmd)
1387{
1388 char *uuid = cmd, *pin;
1389 pin = os_strchr(uuid, ' ');
1390 if (pin == NULL)
1391 return -1;
1392 *pin++ = '\0';
1393 return wpas_wps_er_learn(wpa_s, uuid, pin);
1394}
1395
1396
1397static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1398 struct wpa_supplicant *wpa_s, char *cmd)
1399{
1400 char *uuid = cmd, *id;
1401 id = os_strchr(uuid, ' ');
1402 if (id == NULL)
1403 return -1;
1404 *id++ = '\0';
1405 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1406}
1407
1408
1409static int wpa_supplicant_ctrl_iface_wps_er_config(
1410 struct wpa_supplicant *wpa_s, char *cmd)
1411{
1412 char *pin;
1413 char *new_ssid;
1414 char *new_auth;
1415 char *new_encr;
1416 char *new_key;
1417 struct wps_new_ap_settings ap;
1418
1419 pin = os_strchr(cmd, ' ');
1420 if (pin == NULL)
1421 return -1;
1422 *pin++ = '\0';
1423
1424 new_ssid = os_strchr(pin, ' ');
1425 if (new_ssid == NULL)
1426 return -1;
1427 *new_ssid++ = '\0';
1428
1429 new_auth = os_strchr(new_ssid, ' ');
1430 if (new_auth == NULL)
1431 return -1;
1432 *new_auth++ = '\0';
1433
1434 new_encr = os_strchr(new_auth, ' ');
1435 if (new_encr == NULL)
1436 return -1;
1437 *new_encr++ = '\0';
1438
1439 new_key = os_strchr(new_encr, ' ');
1440 if (new_key == NULL)
1441 return -1;
1442 *new_key++ = '\0';
1443
1444 os_memset(&ap, 0, sizeof(ap));
1445 ap.ssid_hex = new_ssid;
1446 ap.auth = new_auth;
1447 ap.encr = new_encr;
1448 ap.key_hex = new_key;
1449 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1450}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001451
1452
1453#ifdef CONFIG_WPS_NFC
1454static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1455 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1456{
1457 int ndef;
1458 struct wpabuf *buf;
1459 int res;
1460 char *uuid;
1461
1462 uuid = os_strchr(cmd, ' ');
1463 if (uuid == NULL)
1464 return -1;
1465 *uuid++ = '\0';
1466
1467 if (os_strcmp(cmd, "WPS") == 0)
1468 ndef = 0;
1469 else if (os_strcmp(cmd, "NDEF") == 0)
1470 ndef = 1;
1471 else
1472 return -1;
1473
1474 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1475 if (buf == NULL)
1476 return -1;
1477
1478 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1479 wpabuf_len(buf));
1480 reply[res++] = '\n';
1481 reply[res] = '\0';
1482
1483 wpabuf_free(buf);
1484
1485 return res;
1486}
1487#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001488#endif /* CONFIG_WPS_ER */
1489
1490#endif /* CONFIG_WPS */
1491
1492
1493#ifdef CONFIG_IBSS_RSN
1494static int wpa_supplicant_ctrl_iface_ibss_rsn(
1495 struct wpa_supplicant *wpa_s, char *addr)
1496{
1497 u8 peer[ETH_ALEN];
1498
1499 if (hwaddr_aton(addr, peer)) {
1500 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1501 "address '%s'", addr);
1502 return -1;
1503 }
1504
1505 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1506 MAC2STR(peer));
1507
1508 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1509}
1510#endif /* CONFIG_IBSS_RSN */
1511
1512
1513static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1514 char *rsp)
1515{
1516#ifdef IEEE8021X_EAPOL
1517 char *pos, *id_pos;
1518 int id;
1519 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001520
1521 pos = os_strchr(rsp, '-');
1522 if (pos == NULL)
1523 return -1;
1524 *pos++ = '\0';
1525 id_pos = pos;
1526 pos = os_strchr(pos, ':');
1527 if (pos == NULL)
1528 return -1;
1529 *pos++ = '\0';
1530 id = atoi(id_pos);
1531 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1532 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1533 (u8 *) pos, os_strlen(pos));
1534
1535 ssid = wpa_config_get_network(wpa_s->conf, id);
1536 if (ssid == NULL) {
1537 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1538 "to update", id);
1539 return -1;
1540 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001541
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001542 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1543 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001544#else /* IEEE8021X_EAPOL */
1545 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1546 return -1;
1547#endif /* IEEE8021X_EAPOL */
1548}
1549
1550
1551static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1552 const char *params,
1553 char *buf, size_t buflen)
1554{
1555 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001556 int res, verbose, wps, ret;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001557#ifdef CONFIG_HS20
1558 const u8 *hs20;
1559#endif /* CONFIG_HS20 */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001560
Dmitry Shmidt56052862013-10-04 10:23:25 -07001561 if (os_strcmp(params, "-DRIVER") == 0)
1562 return wpa_drv_status(wpa_s, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001563 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001564 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001565 pos = buf;
1566 end = buf + buflen;
1567 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1568 struct wpa_ssid *ssid = wpa_s->current_ssid;
1569 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1570 MAC2STR(wpa_s->bssid));
1571 if (ret < 0 || ret >= end - pos)
1572 return pos - buf;
1573 pos += ret;
1574 if (ssid) {
1575 u8 *_ssid = ssid->ssid;
1576 size_t ssid_len = ssid->ssid_len;
1577 u8 ssid_buf[MAX_SSID_LEN];
1578 if (ssid_len == 0) {
1579 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1580 if (_res < 0)
1581 ssid_len = 0;
1582 else
1583 ssid_len = _res;
1584 _ssid = ssid_buf;
1585 }
1586 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1587 wpa_ssid_txt(_ssid, ssid_len),
1588 ssid->id);
1589 if (ret < 0 || ret >= end - pos)
1590 return pos - buf;
1591 pos += ret;
1592
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001593 if (wps && ssid->passphrase &&
1594 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1595 (ssid->mode == WPAS_MODE_AP ||
1596 ssid->mode == WPAS_MODE_P2P_GO)) {
1597 ret = os_snprintf(pos, end - pos,
1598 "passphrase=%s\n",
1599 ssid->passphrase);
1600 if (ret < 0 || ret >= end - pos)
1601 return pos - buf;
1602 pos += ret;
1603 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001604 if (ssid->id_str) {
1605 ret = os_snprintf(pos, end - pos,
1606 "id_str=%s\n",
1607 ssid->id_str);
1608 if (ret < 0 || ret >= end - pos)
1609 return pos - buf;
1610 pos += ret;
1611 }
1612
1613 switch (ssid->mode) {
1614 case WPAS_MODE_INFRA:
1615 ret = os_snprintf(pos, end - pos,
1616 "mode=station\n");
1617 break;
1618 case WPAS_MODE_IBSS:
1619 ret = os_snprintf(pos, end - pos,
1620 "mode=IBSS\n");
1621 break;
1622 case WPAS_MODE_AP:
1623 ret = os_snprintf(pos, end - pos,
1624 "mode=AP\n");
1625 break;
1626 case WPAS_MODE_P2P_GO:
1627 ret = os_snprintf(pos, end - pos,
1628 "mode=P2P GO\n");
1629 break;
1630 case WPAS_MODE_P2P_GROUP_FORMATION:
1631 ret = os_snprintf(pos, end - pos,
1632 "mode=P2P GO - group "
1633 "formation\n");
1634 break;
1635 default:
1636 ret = 0;
1637 break;
1638 }
1639 if (ret < 0 || ret >= end - pos)
1640 return pos - buf;
1641 pos += ret;
1642 }
1643
1644#ifdef CONFIG_AP
1645 if (wpa_s->ap_iface) {
1646 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1647 end - pos,
1648 verbose);
1649 } else
1650#endif /* CONFIG_AP */
1651 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1652 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001653#ifdef CONFIG_SAE
1654 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001655#ifdef CONFIG_AP
1656 !wpa_s->ap_iface &&
1657#endif /* CONFIG_AP */
1658 wpa_s->sme.sae.state == SAE_ACCEPTED) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001659 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1660 wpa_s->sme.sae.group);
1661 if (ret < 0 || ret >= end - pos)
1662 return pos - buf;
1663 pos += ret;
1664 }
1665#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001666 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1667 wpa_supplicant_state_txt(wpa_s->wpa_state));
1668 if (ret < 0 || ret >= end - pos)
1669 return pos - buf;
1670 pos += ret;
1671
1672 if (wpa_s->l2 &&
1673 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1674 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1675 if (ret < 0 || ret >= end - pos)
1676 return pos - buf;
1677 pos += ret;
1678 }
1679
1680#ifdef CONFIG_P2P
1681 if (wpa_s->global->p2p) {
1682 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1683 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1684 if (ret < 0 || ret >= end - pos)
1685 return pos - buf;
1686 pos += ret;
1687 }
1688#endif /* CONFIG_P2P */
1689
1690 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1691 MAC2STR(wpa_s->own_addr));
1692 if (ret < 0 || ret >= end - pos)
1693 return pos - buf;
1694 pos += ret;
1695
Dmitry Shmidt04949592012-07-19 12:16:46 -07001696#ifdef CONFIG_HS20
1697 if (wpa_s->current_bss &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001698 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1699 HS20_IE_VENDOR_TYPE)) &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001700 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1701 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001702 int release = 1;
1703 if (hs20[1] >= 5) {
1704 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1705 release = rel_num + 1;
1706 }
1707 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001708 if (ret < 0 || ret >= end - pos)
1709 return pos - buf;
1710 pos += ret;
1711 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001712
1713 if (wpa_s->current_ssid) {
1714 struct wpa_cred *cred;
1715 char *type;
1716
1717 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07001718 size_t i;
1719
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001720 if (wpa_s->current_ssid->parent_cred != cred)
1721 continue;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001722
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001723 if (cred->provisioning_sp) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07001724 ret = os_snprintf(pos, end - pos,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001725 "provisioning_sp=%s\n",
1726 cred->provisioning_sp);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001727 if (ret < 0 || ret >= end - pos)
1728 return pos - buf;
1729 pos += ret;
1730 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001731
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001732 if (!cred->domain)
1733 goto no_domain;
1734
1735 i = 0;
1736 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1737 struct wpabuf *names =
1738 wpa_s->current_bss->anqp->domain_name;
1739 for (i = 0; names && i < cred->num_domain; i++)
1740 {
1741 if (domain_name_list_contains(
1742 names, cred->domain[i], 1))
1743 break;
1744 }
1745 if (i == cred->num_domain)
1746 i = 0; /* show first entry by default */
1747 }
1748 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1749 cred->domain[i]);
1750 if (ret < 0 || ret >= end - pos)
1751 return pos - buf;
1752 pos += ret;
1753
1754 no_domain:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001755 if (wpa_s->current_bss == NULL ||
1756 wpa_s->current_bss->anqp == NULL)
1757 res = -1;
1758 else
1759 res = interworking_home_sp_cred(
1760 wpa_s, cred,
1761 wpa_s->current_bss->anqp->domain_name);
1762 if (res > 0)
1763 type = "home";
1764 else if (res == 0)
1765 type = "roaming";
1766 else
1767 type = "unknown";
1768
1769 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1770 if (ret < 0 || ret >= end - pos)
1771 return pos - buf;
1772 pos += ret;
1773
1774 break;
1775 }
1776 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001777#endif /* CONFIG_HS20 */
1778
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001779 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1780 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1781 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1782 verbose);
1783 if (res >= 0)
1784 pos += res;
1785 }
1786
1787 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1788 if (res >= 0)
1789 pos += res;
1790
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001791#ifdef CONFIG_WPS
1792 {
1793 char uuid_str[100];
1794 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1795 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1796 if (ret < 0 || ret >= end - pos)
1797 return pos - buf;
1798 pos += ret;
1799 }
1800#endif /* CONFIG_WPS */
1801
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08001802#ifdef ANDROID
1803 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
Irfan Sherifff20a4432012-04-16 16:48:34 -07001804 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08001805 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
Irfan Sherifff20a4432012-04-16 16:48:34 -07001806 wpa_s->wpa_state,
Irfan Sheriffe78e7672012-08-01 11:10:15 -07001807 MAC2STR(wpa_s->bssid),
andy2_kuo5b5fb022012-05-22 11:53:07 -07001808 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1809 wpa_ssid_txt(wpa_s->current_ssid->ssid,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001810 wpa_s->current_ssid->ssid_len) : "");
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08001811 if (wpa_s->wpa_state == WPA_COMPLETED) {
1812 struct wpa_ssid *ssid = wpa_s->current_ssid;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001813 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1814 "- connection to " MACSTR
1815 " completed %s [id=%d id_str=%s]",
1816 MAC2STR(wpa_s->bssid), "(auth)",
1817 ssid ? ssid->id : -1,
1818 ssid && ssid->id_str ? ssid->id_str : "");
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08001819 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08001820#endif /* ANDROID */
1821
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001822 return pos - buf;
1823}
1824
1825
1826static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1827 char *cmd)
1828{
1829 char *pos;
1830 int id;
1831 struct wpa_ssid *ssid;
1832 u8 bssid[ETH_ALEN];
1833
1834 /* cmd: "<network id> <BSSID>" */
1835 pos = os_strchr(cmd, ' ');
1836 if (pos == NULL)
1837 return -1;
1838 *pos++ = '\0';
1839 id = atoi(cmd);
1840 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1841 if (hwaddr_aton(pos, bssid)) {
1842 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1843 return -1;
1844 }
1845
1846 ssid = wpa_config_get_network(wpa_s->conf, id);
1847 if (ssid == NULL) {
1848 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1849 "to update", id);
1850 return -1;
1851 }
1852
1853 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1854 ssid->bssid_set = !is_zero_ether_addr(bssid);
1855
1856 return 0;
1857}
1858
1859
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001860static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001861 char *cmd, char *buf,
1862 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001863{
1864 u8 bssid[ETH_ALEN];
1865 struct wpa_blacklist *e;
1866 char *pos, *end;
1867 int ret;
1868
1869 /* cmd: "BLACKLIST [<BSSID>]" */
1870 if (*cmd == '\0') {
1871 pos = buf;
1872 end = buf + buflen;
1873 e = wpa_s->blacklist;
1874 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001875 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1876 MAC2STR(e->bssid));
1877 if (ret < 0 || ret >= end - pos)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001878 return pos - buf;
1879 pos += ret;
1880 e = e->next;
1881 }
1882 return pos - buf;
1883 }
1884
1885 cmd++;
1886 if (os_strncmp(cmd, "clear", 5) == 0) {
1887 wpa_blacklist_clear(wpa_s);
1888 os_memcpy(buf, "OK\n", 3);
1889 return 3;
1890 }
1891
1892 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1893 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001894 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001895 return -1;
1896 }
1897
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001898 /*
1899 * Add the BSSID twice, so its count will be 2, causing it to be
1900 * skipped when processing scan results.
1901 */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001902 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001903 if (ret != 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001904 return -1;
1905 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001906 if (ret != 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001907 return -1;
1908 os_memcpy(buf, "OK\n", 3);
1909 return 3;
1910}
1911
1912
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001913static const char * debug_level_str(int level)
1914{
1915 switch (level) {
1916 case MSG_EXCESSIVE:
1917 return "EXCESSIVE";
1918 case MSG_MSGDUMP:
1919 return "MSGDUMP";
1920 case MSG_DEBUG:
1921 return "DEBUG";
1922 case MSG_INFO:
1923 return "INFO";
1924 case MSG_WARNING:
1925 return "WARNING";
1926 case MSG_ERROR:
1927 return "ERROR";
1928 default:
1929 return "?";
1930 }
1931}
1932
1933
1934static int str_to_debug_level(const char *s)
1935{
1936 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1937 return MSG_EXCESSIVE;
1938 if (os_strcasecmp(s, "MSGDUMP") == 0)
1939 return MSG_MSGDUMP;
1940 if (os_strcasecmp(s, "DEBUG") == 0)
1941 return MSG_DEBUG;
1942 if (os_strcasecmp(s, "INFO") == 0)
1943 return MSG_INFO;
1944 if (os_strcasecmp(s, "WARNING") == 0)
1945 return MSG_WARNING;
1946 if (os_strcasecmp(s, "ERROR") == 0)
1947 return MSG_ERROR;
1948 return -1;
1949}
1950
1951
1952static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1953 char *cmd, char *buf,
1954 size_t buflen)
1955{
1956 char *pos, *end, *stamp;
1957 int ret;
1958
1959 if (cmd == NULL) {
1960 return -1;
1961 }
1962
1963 /* cmd: "LOG_LEVEL [<level>]" */
1964 if (*cmd == '\0') {
1965 pos = buf;
1966 end = buf + buflen;
1967 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1968 "Timestamp: %d\n",
1969 debug_level_str(wpa_debug_level),
1970 wpa_debug_timestamp);
1971 if (ret < 0 || ret >= end - pos)
1972 ret = 0;
1973
1974 return ret;
1975 }
1976
1977 while (*cmd == ' ')
1978 cmd++;
1979
1980 stamp = os_strchr(cmd, ' ');
1981 if (stamp) {
1982 *stamp++ = '\0';
1983 while (*stamp == ' ') {
1984 stamp++;
1985 }
1986 }
1987
1988 if (cmd && os_strlen(cmd)) {
1989 int level = str_to_debug_level(cmd);
1990 if (level < 0)
1991 return -1;
1992 wpa_debug_level = level;
1993 }
1994
1995 if (stamp && os_strlen(stamp))
1996 wpa_debug_timestamp = atoi(stamp);
1997
1998 os_memcpy(buf, "OK\n", 3);
1999 return 3;
2000}
2001
2002
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002003static int wpa_supplicant_ctrl_iface_list_networks(
2004 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2005{
2006 char *pos, *end;
2007 struct wpa_ssid *ssid;
2008 int ret;
2009
2010 pos = buf;
2011 end = buf + buflen;
2012 ret = os_snprintf(pos, end - pos,
2013 "network id / ssid / bssid / flags\n");
2014 if (ret < 0 || ret >= end - pos)
2015 return pos - buf;
2016 pos += ret;
2017
2018 ssid = wpa_s->conf->ssid;
2019 while (ssid) {
2020 ret = os_snprintf(pos, end - pos, "%d\t%s",
2021 ssid->id,
2022 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2023 if (ret < 0 || ret >= end - pos)
2024 return pos - buf;
2025 pos += ret;
2026 if (ssid->bssid_set) {
2027 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2028 MAC2STR(ssid->bssid));
2029 } else {
2030 ret = os_snprintf(pos, end - pos, "\tany");
2031 }
2032 if (ret < 0 || ret >= end - pos)
2033 return pos - buf;
2034 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002035 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002036 ssid == wpa_s->current_ssid ?
2037 "[CURRENT]" : "",
2038 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002039 ssid->disabled_until.sec ?
2040 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002041 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2042 "");
2043 if (ret < 0 || ret >= end - pos)
2044 return pos - buf;
2045 pos += ret;
2046 ret = os_snprintf(pos, end - pos, "\n");
2047 if (ret < 0 || ret >= end - pos)
2048 return pos - buf;
2049 pos += ret;
2050
2051 ssid = ssid->next;
2052 }
2053
2054 return pos - buf;
2055}
2056
2057
2058static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2059{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002060 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002061 ret = os_snprintf(pos, end - pos, "-");
2062 if (ret < 0 || ret >= end - pos)
2063 return pos;
2064 pos += ret;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002065 ret = wpa_write_ciphers(pos, end, cipher, "+");
2066 if (ret < 0)
2067 return pos;
2068 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002069 return pos;
2070}
2071
2072
2073static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2074 const u8 *ie, size_t ie_len)
2075{
2076 struct wpa_ie_data data;
2077 int first, ret;
2078
2079 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2080 if (ret < 0 || ret >= end - pos)
2081 return pos;
2082 pos += ret;
2083
2084 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2085 ret = os_snprintf(pos, end - pos, "?]");
2086 if (ret < 0 || ret >= end - pos)
2087 return pos;
2088 pos += ret;
2089 return pos;
2090 }
2091
2092 first = 1;
2093 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2094 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
2095 if (ret < 0 || ret >= end - pos)
2096 return pos;
2097 pos += ret;
2098 first = 0;
2099 }
2100 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2101 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
2102 if (ret < 0 || ret >= end - pos)
2103 return pos;
2104 pos += ret;
2105 first = 0;
2106 }
2107 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2108 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
2109 if (ret < 0 || ret >= end - pos)
2110 return pos;
2111 pos += ret;
2112 first = 0;
2113 }
2114#ifdef CONFIG_IEEE80211R
2115 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2116 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2117 first ? "" : "+");
2118 if (ret < 0 || ret >= end - pos)
2119 return pos;
2120 pos += ret;
2121 first = 0;
2122 }
2123 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2124 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2125 first ? "" : "+");
2126 if (ret < 0 || ret >= end - pos)
2127 return pos;
2128 pos += ret;
2129 first = 0;
2130 }
2131#endif /* CONFIG_IEEE80211R */
2132#ifdef CONFIG_IEEE80211W
2133 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2134 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2135 first ? "" : "+");
2136 if (ret < 0 || ret >= end - pos)
2137 return pos;
2138 pos += ret;
2139 first = 0;
2140 }
2141 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2142 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2143 first ? "" : "+");
2144 if (ret < 0 || ret >= end - pos)
2145 return pos;
2146 pos += ret;
2147 first = 0;
2148 }
2149#endif /* CONFIG_IEEE80211W */
2150
2151 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2152
2153 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2154 ret = os_snprintf(pos, end - pos, "-preauth");
2155 if (ret < 0 || ret >= end - pos)
2156 return pos;
2157 pos += ret;
2158 }
2159
2160 ret = os_snprintf(pos, end - pos, "]");
2161 if (ret < 0 || ret >= end - pos)
2162 return pos;
2163 pos += ret;
2164
2165 return pos;
2166}
2167
2168
2169#ifdef CONFIG_WPS
2170static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2171 char *pos, char *end,
2172 struct wpabuf *wps_ie)
2173{
2174 int ret;
2175 const char *txt;
2176
2177 if (wps_ie == NULL)
2178 return pos;
2179 if (wps_is_selected_pbc_registrar(wps_ie))
2180 txt = "[WPS-PBC]";
2181#ifdef CONFIG_WPS2
2182 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2183 txt = "[WPS-AUTH]";
2184#endif /* CONFIG_WPS2 */
2185 else if (wps_is_selected_pin_registrar(wps_ie))
2186 txt = "[WPS-PIN]";
2187 else
2188 txt = "[WPS]";
2189
2190 ret = os_snprintf(pos, end - pos, "%s", txt);
2191 if (ret >= 0 && ret < end - pos)
2192 pos += ret;
2193 wpabuf_free(wps_ie);
2194 return pos;
2195}
2196#endif /* CONFIG_WPS */
2197
2198
2199static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2200 char *pos, char *end,
2201 const struct wpa_bss *bss)
2202{
2203#ifdef CONFIG_WPS
2204 struct wpabuf *wps_ie;
2205 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2206 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2207#else /* CONFIG_WPS */
2208 return pos;
2209#endif /* CONFIG_WPS */
2210}
2211
2212
2213/* Format one result on one text line into a buffer. */
2214static int wpa_supplicant_ctrl_iface_scan_result(
2215 struct wpa_supplicant *wpa_s,
2216 const struct wpa_bss *bss, char *buf, size_t buflen)
2217{
2218 char *pos, *end;
2219 int ret;
2220 const u8 *ie, *ie2, *p2p;
2221
2222 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07002223 if (!p2p)
2224 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002225 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2226 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2227 0)
2228 return 0; /* Do not show P2P listen discovery results here */
2229
2230 pos = buf;
2231 end = buf + buflen;
2232
2233 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2234 MAC2STR(bss->bssid), bss->freq, bss->level);
2235 if (ret < 0 || ret >= end - pos)
2236 return -1;
2237 pos += ret;
2238 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2239 if (ie)
2240 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2241 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2242 if (ie2)
2243 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2244 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2245 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2246 ret = os_snprintf(pos, end - pos, "[WEP]");
2247 if (ret < 0 || ret >= end - pos)
2248 return -1;
2249 pos += ret;
2250 }
2251 if (bss->caps & IEEE80211_CAP_IBSS) {
2252 ret = os_snprintf(pos, end - pos, "[IBSS]");
2253 if (ret < 0 || ret >= end - pos)
2254 return -1;
2255 pos += ret;
2256 }
2257 if (bss->caps & IEEE80211_CAP_ESS) {
2258 ret = os_snprintf(pos, end - pos, "[ESS]");
2259 if (ret < 0 || ret >= end - pos)
2260 return -1;
2261 pos += ret;
2262 }
2263 if (p2p) {
2264 ret = os_snprintf(pos, end - pos, "[P2P]");
2265 if (ret < 0 || ret >= end - pos)
2266 return -1;
2267 pos += ret;
2268 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002269#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002270 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002271 ret = os_snprintf(pos, end - pos, "[HS20]");
2272 if (ret < 0 || ret >= end - pos)
2273 return -1;
2274 pos += ret;
2275 }
2276#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002277
2278 ret = os_snprintf(pos, end - pos, "\t%s",
2279 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2280 if (ret < 0 || ret >= end - pos)
2281 return -1;
2282 pos += ret;
2283
2284 ret = os_snprintf(pos, end - pos, "\n");
2285 if (ret < 0 || ret >= end - pos)
2286 return -1;
2287 pos += ret;
2288
2289 return pos - buf;
2290}
2291
2292
2293static int wpa_supplicant_ctrl_iface_scan_results(
2294 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2295{
2296 char *pos, *end;
2297 struct wpa_bss *bss;
2298 int ret;
2299
2300 pos = buf;
2301 end = buf + buflen;
2302 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2303 "flags / ssid\n");
2304 if (ret < 0 || ret >= end - pos)
2305 return pos - buf;
2306 pos += ret;
2307
2308 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2309 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2310 end - pos);
2311 if (ret < 0 || ret >= end - pos)
2312 return pos - buf;
2313 pos += ret;
2314 }
2315
2316 return pos - buf;
2317}
2318
2319
2320static int wpa_supplicant_ctrl_iface_select_network(
2321 struct wpa_supplicant *wpa_s, char *cmd)
2322{
2323 int id;
2324 struct wpa_ssid *ssid;
2325
2326 /* cmd: "<network id>" or "any" */
2327 if (os_strcmp(cmd, "any") == 0) {
2328 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2329 ssid = NULL;
2330 } else {
2331 id = atoi(cmd);
2332 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2333
2334 ssid = wpa_config_get_network(wpa_s->conf, id);
2335 if (ssid == NULL) {
2336 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2337 "network id=%d", id);
2338 return -1;
2339 }
2340 if (ssid->disabled == 2) {
2341 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2342 "SELECT_NETWORK with persistent P2P group");
2343 return -1;
2344 }
2345 }
2346
2347 wpa_supplicant_select_network(wpa_s, ssid);
2348
2349 return 0;
2350}
2351
2352
2353static int wpa_supplicant_ctrl_iface_enable_network(
2354 struct wpa_supplicant *wpa_s, char *cmd)
2355{
2356 int id;
2357 struct wpa_ssid *ssid;
2358
2359 /* cmd: "<network id>" or "all" */
2360 if (os_strcmp(cmd, "all") == 0) {
2361 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2362 ssid = NULL;
2363 } else {
2364 id = atoi(cmd);
2365 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2366
2367 ssid = wpa_config_get_network(wpa_s->conf, id);
2368 if (ssid == NULL) {
2369 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2370 "network id=%d", id);
2371 return -1;
2372 }
2373 if (ssid->disabled == 2) {
2374 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2375 "ENABLE_NETWORK with persistent P2P group");
2376 return -1;
2377 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002378
2379 if (os_strstr(cmd, " no-connect")) {
2380 ssid->disabled = 0;
2381 return 0;
2382 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002383 }
2384 wpa_supplicant_enable_network(wpa_s, ssid);
2385
2386 return 0;
2387}
2388
2389
2390static int wpa_supplicant_ctrl_iface_disable_network(
2391 struct wpa_supplicant *wpa_s, char *cmd)
2392{
2393 int id;
2394 struct wpa_ssid *ssid;
2395
2396 /* cmd: "<network id>" or "all" */
2397 if (os_strcmp(cmd, "all") == 0) {
2398 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2399 ssid = NULL;
2400 } else {
2401 id = atoi(cmd);
2402 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2403
2404 ssid = wpa_config_get_network(wpa_s->conf, id);
2405 if (ssid == NULL) {
2406 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2407 "network id=%d", id);
2408 return -1;
2409 }
2410 if (ssid->disabled == 2) {
2411 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2412 "DISABLE_NETWORK with persistent P2P "
2413 "group");
2414 return -1;
2415 }
2416 }
2417 wpa_supplicant_disable_network(wpa_s, ssid);
2418
2419 return 0;
2420}
2421
2422
2423static int wpa_supplicant_ctrl_iface_add_network(
2424 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2425{
2426 struct wpa_ssid *ssid;
2427 int ret;
2428
2429 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2430
2431 ssid = wpa_config_add_network(wpa_s->conf);
2432 if (ssid == NULL)
2433 return -1;
2434
2435 wpas_notify_network_added(wpa_s, ssid);
2436
2437 ssid->disabled = 1;
2438 wpa_config_set_network_defaults(ssid);
2439
2440 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2441 if (ret < 0 || (size_t) ret >= buflen)
2442 return -1;
2443 return ret;
2444}
2445
2446
2447static int wpa_supplicant_ctrl_iface_remove_network(
2448 struct wpa_supplicant *wpa_s, char *cmd)
2449{
2450 int id;
2451 struct wpa_ssid *ssid;
Dmitry Shmidt2f023192013-03-12 12:44:17 -07002452 int was_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002453
2454 /* cmd: "<network id>" or "all" */
2455 if (os_strcmp(cmd, "all") == 0) {
2456 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Dmitry Shmidt2f023192013-03-12 12:44:17 -07002457 if (wpa_s->sched_scanning)
2458 wpa_supplicant_cancel_sched_scan(wpa_s);
2459
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002460 eapol_sm_invalidate_cached_session(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002461 if (wpa_s->current_ssid) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002462#ifdef CONFIG_SME
2463 wpa_s->sme.prev_bssid_set = 0;
2464#endif /* CONFIG_SME */
Jouni Malinen75ecf522011-06-27 15:19:46 -07002465 wpa_sm_set_config(wpa_s->wpa, NULL);
2466 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002467 wpa_supplicant_deauthenticate(
2468 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002469 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002470 ssid = wpa_s->conf->ssid;
2471 while (ssid) {
2472 struct wpa_ssid *remove_ssid = ssid;
2473 id = ssid->id;
2474 ssid = ssid->next;
2475 wpas_notify_network_removed(wpa_s, remove_ssid);
2476 wpa_config_remove_network(wpa_s->conf, id);
2477 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002478 return 0;
2479 }
2480
2481 id = atoi(cmd);
2482 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2483
2484 ssid = wpa_config_get_network(wpa_s->conf, id);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002485 if (ssid)
2486 wpas_notify_network_removed(wpa_s, ssid);
Deepthi Gowria831d782012-09-03 11:55:38 +03002487 if (ssid == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002488 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2489 "id=%d", id);
2490 return -1;
2491 }
2492
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002493 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002494#ifdef CONFIG_SME
2495 wpa_s->sme.prev_bssid_set = 0;
2496#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002497 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002498 * Invalidate the EAP session cache if the current or
2499 * previously used network is removed.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002500 */
2501 eapol_sm_invalidate_cached_session(wpa_s->eapol);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002502 }
2503
2504 if (ssid == wpa_s->current_ssid) {
Jouni Malinen75ecf522011-06-27 15:19:46 -07002505 wpa_sm_set_config(wpa_s->wpa, NULL);
2506 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002507
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002508 wpa_supplicant_deauthenticate(wpa_s,
2509 WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002510 }
2511
Dmitry Shmidt2f023192013-03-12 12:44:17 -07002512 was_disabled = ssid->disabled;
2513
Deepthi Gowria831d782012-09-03 11:55:38 +03002514 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2515 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2516 "network id=%d", id);
2517 return -1;
2518 }
2519
Dmitry Shmidt2f023192013-03-12 12:44:17 -07002520 if (!was_disabled && wpa_s->sched_scanning) {
2521 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2522 "network from filters");
2523 wpa_supplicant_cancel_sched_scan(wpa_s);
2524 wpa_supplicant_req_scan(wpa_s, 0, 0);
2525 }
2526
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002527 return 0;
2528}
2529
2530
2531static int wpa_supplicant_ctrl_iface_set_network(
2532 struct wpa_supplicant *wpa_s, char *cmd)
2533{
2534 int id;
2535 struct wpa_ssid *ssid;
2536 char *name, *value;
2537
2538 /* cmd: "<network id> <variable name> <value>" */
2539 name = os_strchr(cmd, ' ');
2540 if (name == NULL)
2541 return -1;
2542 *name++ = '\0';
2543
2544 value = os_strchr(name, ' ');
2545 if (value == NULL)
2546 return -1;
2547 *value++ = '\0';
2548
2549 id = atoi(cmd);
2550 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2551 id, name);
2552 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2553 (u8 *) value, os_strlen(value));
2554
2555 ssid = wpa_config_get_network(wpa_s->conf, id);
2556 if (ssid == NULL) {
2557 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2558 "id=%d", id);
2559 return -1;
2560 }
2561
2562 if (wpa_config_set(ssid, name, value, 0) < 0) {
2563 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2564 "variable '%s'", name);
2565 return -1;
2566 }
2567
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002568 if (os_strcmp(name, "bssid") != 0 &&
2569 os_strcmp(name, "priority") != 0)
2570 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002571
2572 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002573 /*
2574 * Invalidate the EAP session cache if anything in the current
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002575 * or previously used configuration changes.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002576 */
2577 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2578 }
2579
2580 if ((os_strcmp(name, "psk") == 0 &&
2581 value[0] == '"' && ssid->ssid_len) ||
2582 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2583 wpa_config_update_psk(ssid);
2584 else if (os_strcmp(name, "priority") == 0)
2585 wpa_config_update_prio_list(wpa_s->conf);
2586
2587 return 0;
2588}
2589
2590
2591static int wpa_supplicant_ctrl_iface_get_network(
2592 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2593{
2594 int id;
2595 size_t res;
2596 struct wpa_ssid *ssid;
2597 char *name, *value;
2598
2599 /* cmd: "<network id> <variable name>" */
2600 name = os_strchr(cmd, ' ');
2601 if (name == NULL || buflen == 0)
2602 return -1;
2603 *name++ = '\0';
2604
2605 id = atoi(cmd);
2606 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2607 id, name);
2608
2609 ssid = wpa_config_get_network(wpa_s->conf, id);
2610 if (ssid == NULL) {
2611 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2612 "id=%d", id);
2613 return -1;
2614 }
2615
2616 value = wpa_config_get_no_key(ssid, name);
2617 if (value == NULL) {
2618 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2619 "variable '%s'", name);
2620 return -1;
2621 }
2622
2623 res = os_strlcpy(buf, value, buflen);
2624 if (res >= buflen) {
2625 os_free(value);
2626 return -1;
2627 }
2628
2629 os_free(value);
2630
2631 return res;
2632}
2633
2634
Dmitry Shmidt04949592012-07-19 12:16:46 -07002635static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2636 char *buf, size_t buflen)
2637{
2638 char *pos, *end;
2639 struct wpa_cred *cred;
2640 int ret;
2641
2642 pos = buf;
2643 end = buf + buflen;
2644 ret = os_snprintf(pos, end - pos,
2645 "cred id / realm / username / domain / imsi\n");
2646 if (ret < 0 || ret >= end - pos)
2647 return pos - buf;
2648 pos += ret;
2649
2650 cred = wpa_s->conf->cred;
2651 while (cred) {
2652 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2653 cred->id, cred->realm ? cred->realm : "",
2654 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07002655 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07002656 cred->imsi ? cred->imsi : "");
2657 if (ret < 0 || ret >= end - pos)
2658 return pos - buf;
2659 pos += ret;
2660
2661 cred = cred->next;
2662 }
2663
2664 return pos - buf;
2665}
2666
2667
2668static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2669 char *buf, size_t buflen)
2670{
2671 struct wpa_cred *cred;
2672 int ret;
2673
2674 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2675
2676 cred = wpa_config_add_cred(wpa_s->conf);
2677 if (cred == NULL)
2678 return -1;
2679
2680 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2681 if (ret < 0 || (size_t) ret >= buflen)
2682 return -1;
2683 return ret;
2684}
2685
2686
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002687static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2688 struct wpa_cred *cred)
2689{
2690 struct wpa_ssid *ssid;
2691 char str[20];
2692
2693 if (cred == NULL || wpa_config_remove_cred(wpa_s->conf, cred->id) < 0) {
2694 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2695 return -1;
2696 }
2697
2698 /* Remove any network entry created based on the removed credential */
2699 ssid = wpa_s->conf->ssid;
2700 while (ssid) {
2701 if (ssid->parent_cred == cred) {
2702 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2703 "used the removed credential", ssid->id);
2704 os_snprintf(str, sizeof(str), "%d", ssid->id);
2705 ssid = ssid->next;
2706 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2707 } else
2708 ssid = ssid->next;
2709 }
2710
2711 return 0;
2712}
2713
2714
Dmitry Shmidt04949592012-07-19 12:16:46 -07002715static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2716 char *cmd)
2717{
2718 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002719 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002720
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002721 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2722 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002723 if (os_strcmp(cmd, "all") == 0) {
2724 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2725 cred = wpa_s->conf->cred;
2726 while (cred) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002727 prev = cred;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002728 cred = cred->next;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002729 wpas_ctrl_remove_cred(wpa_s, prev);
2730 }
2731 return 0;
2732 }
2733
2734 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2735 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2736 cmd + 8);
2737 cred = wpa_s->conf->cred;
2738 while (cred) {
2739 prev = cred;
2740 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002741 if (prev->domain) {
2742 size_t i;
2743 for (i = 0; i < prev->num_domain; i++) {
2744 if (os_strcmp(prev->domain[i], cmd + 8)
2745 != 0)
2746 continue;
2747 wpas_ctrl_remove_cred(wpa_s, prev);
2748 break;
2749 }
2750 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002751 }
2752 return 0;
2753 }
2754
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002755 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
2756 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2757 cmd + 16);
2758 cred = wpa_s->conf->cred;
2759 while (cred) {
2760 prev = cred;
2761 cred = cred->next;
2762 if (prev->provisioning_sp &&
2763 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
2764 wpas_ctrl_remove_cred(wpa_s, prev);
2765 }
2766 return 0;
2767 }
2768
Dmitry Shmidt04949592012-07-19 12:16:46 -07002769 id = atoi(cmd);
2770 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2771
2772 cred = wpa_config_get_cred(wpa_s->conf, id);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002773 return wpas_ctrl_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002774}
2775
2776
2777static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2778 char *cmd)
2779{
2780 int id;
2781 struct wpa_cred *cred;
2782 char *name, *value;
2783
2784 /* cmd: "<cred id> <variable name> <value>" */
2785 name = os_strchr(cmd, ' ');
2786 if (name == NULL)
2787 return -1;
2788 *name++ = '\0';
2789
2790 value = os_strchr(name, ' ');
2791 if (value == NULL)
2792 return -1;
2793 *value++ = '\0';
2794
2795 id = atoi(cmd);
2796 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2797 id, name);
2798 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2799 (u8 *) value, os_strlen(value));
2800
2801 cred = wpa_config_get_cred(wpa_s->conf, id);
2802 if (cred == NULL) {
2803 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2804 id);
2805 return -1;
2806 }
2807
2808 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2809 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2810 "variable '%s'", name);
2811 return -1;
2812 }
2813
2814 return 0;
2815}
2816
2817
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002818#ifndef CONFIG_NO_CONFIG_WRITE
2819static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2820{
2821 int ret;
2822
2823 if (!wpa_s->conf->update_config) {
2824 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2825 "to update configuration (update_config=0)");
2826 return -1;
2827 }
2828
2829 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2830 if (ret) {
2831 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2832 "update configuration");
2833 } else {
2834 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2835 " updated");
2836 }
2837
2838 return ret;
2839}
2840#endif /* CONFIG_NO_CONFIG_WRITE */
2841
2842
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002843struct cipher_info {
2844 unsigned int capa;
2845 const char *name;
2846 int group_only;
2847};
2848
2849static const struct cipher_info ciphers[] = {
2850 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2851 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2852 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2853 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
2854 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
2855 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
2856 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
2857 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
2858};
2859
2860
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002861static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2862 struct wpa_driver_capa *capa,
2863 char *buf, size_t buflen)
2864{
2865 int ret, first = 1;
2866 char *pos, *end;
2867 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002868 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002869
2870 pos = buf;
2871 end = pos + buflen;
2872
2873 if (res < 0) {
2874 if (strict)
2875 return 0;
2876 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2877 if (len >= buflen)
2878 return -1;
2879 return len;
2880 }
2881
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002882 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2883 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
2884 ret = os_snprintf(pos, end - pos, "%s%s",
2885 first ? "" : " ", ciphers[i].name);
2886 if (ret < 0 || ret >= end - pos)
2887 return pos - buf;
2888 pos += ret;
2889 first = 0;
2890 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002891 }
2892
2893 return pos - buf;
2894}
2895
2896
2897static int ctrl_iface_get_capability_group(int res, char *strict,
2898 struct wpa_driver_capa *capa,
2899 char *buf, size_t buflen)
2900{
2901 int ret, first = 1;
2902 char *pos, *end;
2903 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002904 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002905
2906 pos = buf;
2907 end = pos + buflen;
2908
2909 if (res < 0) {
2910 if (strict)
2911 return 0;
2912 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2913 if (len >= buflen)
2914 return -1;
2915 return len;
2916 }
2917
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002918 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2919 if (capa->enc & ciphers[i].capa) {
2920 ret = os_snprintf(pos, end - pos, "%s%s",
2921 first ? "" : " ", ciphers[i].name);
2922 if (ret < 0 || ret >= end - pos)
2923 return pos - buf;
2924 pos += ret;
2925 first = 0;
2926 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002927 }
2928
2929 return pos - buf;
2930}
2931
2932
2933static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2934 struct wpa_driver_capa *capa,
2935 char *buf, size_t buflen)
2936{
2937 int ret;
2938 char *pos, *end;
2939 size_t len;
2940
2941 pos = buf;
2942 end = pos + buflen;
2943
2944 if (res < 0) {
2945 if (strict)
2946 return 0;
2947 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2948 "NONE", buflen);
2949 if (len >= buflen)
2950 return -1;
2951 return len;
2952 }
2953
2954 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2955 if (ret < 0 || ret >= end - pos)
2956 return pos - buf;
2957 pos += ret;
2958
2959 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2960 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2961 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2962 if (ret < 0 || ret >= end - pos)
2963 return pos - buf;
2964 pos += ret;
2965 }
2966
2967 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2968 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2969 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2970 if (ret < 0 || ret >= end - pos)
2971 return pos - buf;
2972 pos += ret;
2973 }
2974
2975 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2976 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2977 if (ret < 0 || ret >= end - pos)
2978 return pos - buf;
2979 pos += ret;
2980 }
2981
2982 return pos - buf;
2983}
2984
2985
2986static int ctrl_iface_get_capability_proto(int res, char *strict,
2987 struct wpa_driver_capa *capa,
2988 char *buf, size_t buflen)
2989{
2990 int ret, first = 1;
2991 char *pos, *end;
2992 size_t len;
2993
2994 pos = buf;
2995 end = pos + buflen;
2996
2997 if (res < 0) {
2998 if (strict)
2999 return 0;
3000 len = os_strlcpy(buf, "RSN WPA", buflen);
3001 if (len >= buflen)
3002 return -1;
3003 return len;
3004 }
3005
3006 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3007 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3008 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
3009 if (ret < 0 || ret >= end - pos)
3010 return pos - buf;
3011 pos += ret;
3012 first = 0;
3013 }
3014
3015 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3016 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3017 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
3018 if (ret < 0 || ret >= end - pos)
3019 return pos - buf;
3020 pos += ret;
3021 first = 0;
3022 }
3023
3024 return pos - buf;
3025}
3026
3027
3028static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
3029 struct wpa_driver_capa *capa,
3030 char *buf, size_t buflen)
3031{
3032 int ret, first = 1;
3033 char *pos, *end;
3034 size_t len;
3035
3036 pos = buf;
3037 end = pos + buflen;
3038
3039 if (res < 0) {
3040 if (strict)
3041 return 0;
3042 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3043 if (len >= buflen)
3044 return -1;
3045 return len;
3046 }
3047
3048 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3049 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
3050 if (ret < 0 || ret >= end - pos)
3051 return pos - buf;
3052 pos += ret;
3053 first = 0;
3054 }
3055
3056 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3057 ret = os_snprintf(pos, end - pos, "%sSHARED",
3058 first ? "" : " ");
3059 if (ret < 0 || ret >= end - pos)
3060 return pos - buf;
3061 pos += ret;
3062 first = 0;
3063 }
3064
3065 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3066 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
3067 if (ret < 0 || ret >= end - pos)
3068 return pos - buf;
3069 pos += ret;
3070 first = 0;
3071 }
3072
3073 return pos - buf;
3074}
3075
3076
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003077static int ctrl_iface_get_capability_modes(int res, char *strict,
3078 struct wpa_driver_capa *capa,
3079 char *buf, size_t buflen)
3080{
3081 int ret, first = 1;
3082 char *pos, *end;
3083 size_t len;
3084
3085 pos = buf;
3086 end = pos + buflen;
3087
3088 if (res < 0) {
3089 if (strict)
3090 return 0;
3091 len = os_strlcpy(buf, "IBSS AP", buflen);
3092 if (len >= buflen)
3093 return -1;
3094 return len;
3095 }
3096
3097 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3098 ret = os_snprintf(pos, end - pos, "%sIBSS", first ? "" : " ");
3099 if (ret < 0 || ret >= end - pos)
3100 return pos - buf;
3101 pos += ret;
3102 first = 0;
3103 }
3104
3105 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3106 ret = os_snprintf(pos, end - pos, "%sAP", first ? "" : " ");
3107 if (ret < 0 || ret >= end - pos)
3108 return pos - buf;
3109 pos += ret;
3110 first = 0;
3111 }
3112
3113 return pos - buf;
3114}
3115
3116
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07003117static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3118 char *buf, size_t buflen)
3119{
3120 struct hostapd_channel_data *chnl;
3121 int ret, i, j;
3122 char *pos, *end, *hmode;
3123
3124 pos = buf;
3125 end = pos + buflen;
3126
3127 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3128 switch (wpa_s->hw.modes[j].mode) {
3129 case HOSTAPD_MODE_IEEE80211B:
3130 hmode = "B";
3131 break;
3132 case HOSTAPD_MODE_IEEE80211G:
3133 hmode = "G";
3134 break;
3135 case HOSTAPD_MODE_IEEE80211A:
3136 hmode = "A";
3137 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003138 case HOSTAPD_MODE_IEEE80211AD:
3139 hmode = "AD";
3140 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07003141 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003142 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07003143 }
3144 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3145 if (ret < 0 || ret >= end - pos)
3146 return pos - buf;
3147 pos += ret;
3148 chnl = wpa_s->hw.modes[j].channels;
3149 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003150 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3151 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07003152 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3153 if (ret < 0 || ret >= end - pos)
3154 return pos - buf;
3155 pos += ret;
3156 }
3157 ret = os_snprintf(pos, end - pos, "\n");
3158 if (ret < 0 || ret >= end - pos)
3159 return pos - buf;
3160 pos += ret;
3161 }
3162
3163 return pos - buf;
3164}
3165
3166
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003167static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3168 char *buf, size_t buflen)
3169{
3170 struct hostapd_channel_data *chnl;
3171 int ret, i, j;
3172 char *pos, *end, *hmode;
3173
3174 pos = buf;
3175 end = pos + buflen;
3176
3177 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3178 switch (wpa_s->hw.modes[j].mode) {
3179 case HOSTAPD_MODE_IEEE80211B:
3180 hmode = "B";
3181 break;
3182 case HOSTAPD_MODE_IEEE80211G:
3183 hmode = "G";
3184 break;
3185 case HOSTAPD_MODE_IEEE80211A:
3186 hmode = "A";
3187 break;
3188 case HOSTAPD_MODE_IEEE80211AD:
3189 hmode = "AD";
3190 break;
3191 default:
3192 continue;
3193 }
3194 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3195 hmode);
3196 if (ret < 0 || ret >= end - pos)
3197 return pos - buf;
3198 pos += ret;
3199 chnl = wpa_s->hw.modes[j].channels;
3200 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3201 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3202 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08003203 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003204 chnl[i].chan, chnl[i].freq,
3205 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08003206 " (NO_IBSS)" : "",
3207 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3208 " (DFS)" : "");
3209
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003210 if (ret < 0 || ret >= end - pos)
3211 return pos - buf;
3212 pos += ret;
3213 }
3214 ret = os_snprintf(pos, end - pos, "\n");
3215 if (ret < 0 || ret >= end - pos)
3216 return pos - buf;
3217 pos += ret;
3218 }
3219
3220 return pos - buf;
3221}
3222
3223
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003224static int wpa_supplicant_ctrl_iface_get_capability(
3225 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3226 size_t buflen)
3227{
3228 struct wpa_driver_capa capa;
3229 int res;
3230 char *strict;
3231 char field[30];
3232 size_t len;
3233
3234 /* Determine whether or not strict checking was requested */
3235 len = os_strlcpy(field, _field, sizeof(field));
3236 if (len >= sizeof(field))
3237 return -1;
3238 strict = os_strchr(field, ' ');
3239 if (strict != NULL) {
3240 *strict++ = '\0';
3241 if (os_strcmp(strict, "strict") != 0)
3242 return -1;
3243 }
3244
3245 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3246 field, strict ? strict : "");
3247
3248 if (os_strcmp(field, "eap") == 0) {
3249 return eap_get_names(buf, buflen);
3250 }
3251
3252 res = wpa_drv_get_capa(wpa_s, &capa);
3253
3254 if (os_strcmp(field, "pairwise") == 0)
3255 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3256 buf, buflen);
3257
3258 if (os_strcmp(field, "group") == 0)
3259 return ctrl_iface_get_capability_group(res, strict, &capa,
3260 buf, buflen);
3261
3262 if (os_strcmp(field, "key_mgmt") == 0)
3263 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3264 buf, buflen);
3265
3266 if (os_strcmp(field, "proto") == 0)
3267 return ctrl_iface_get_capability_proto(res, strict, &capa,
3268 buf, buflen);
3269
3270 if (os_strcmp(field, "auth_alg") == 0)
3271 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3272 buf, buflen);
3273
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003274 if (os_strcmp(field, "modes") == 0)
3275 return ctrl_iface_get_capability_modes(res, strict, &capa,
3276 buf, buflen);
3277
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07003278 if (os_strcmp(field, "channels") == 0)
3279 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3280
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003281 if (os_strcmp(field, "freq") == 0)
3282 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3283
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003284 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3285 field);
3286
3287 return -1;
3288}
3289
3290
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003291#ifdef CONFIG_INTERWORKING
3292static char * anqp_add_hex(char *pos, char *end, const char *title,
3293 struct wpabuf *data)
3294{
3295 char *start = pos;
3296 size_t i;
3297 int ret;
3298 const u8 *d;
3299
3300 if (data == NULL)
3301 return start;
3302
3303 ret = os_snprintf(pos, end - pos, "%s=", title);
3304 if (ret < 0 || ret >= end - pos)
3305 return start;
3306 pos += ret;
3307
3308 d = wpabuf_head_u8(data);
3309 for (i = 0; i < wpabuf_len(data); i++) {
3310 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3311 if (ret < 0 || ret >= end - pos)
3312 return start;
3313 pos += ret;
3314 }
3315
3316 ret = os_snprintf(pos, end - pos, "\n");
3317 if (ret < 0 || ret >= end - pos)
3318 return start;
3319 pos += ret;
3320
3321 return pos;
3322}
3323#endif /* CONFIG_INTERWORKING */
3324
3325
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003326static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3327 unsigned long mask, char *buf, size_t buflen)
3328{
3329 size_t i;
3330 int ret;
3331 char *pos, *end;
3332 const u8 *ie, *ie2;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003333
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003334 pos = buf;
3335 end = buf + buflen;
3336
3337 if (mask & WPA_BSS_MASK_ID) {
3338 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3339 if (ret < 0 || ret >= end - pos)
3340 return 0;
3341 pos += ret;
3342 }
3343
3344 if (mask & WPA_BSS_MASK_BSSID) {
3345 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3346 MAC2STR(bss->bssid));
3347 if (ret < 0 || ret >= end - pos)
3348 return 0;
3349 pos += ret;
3350 }
3351
3352 if (mask & WPA_BSS_MASK_FREQ) {
3353 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3354 if (ret < 0 || ret >= end - pos)
3355 return 0;
3356 pos += ret;
3357 }
3358
3359 if (mask & WPA_BSS_MASK_BEACON_INT) {
3360 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3361 bss->beacon_int);
3362 if (ret < 0 || ret >= end - pos)
3363 return 0;
3364 pos += ret;
3365 }
3366
3367 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3368 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3369 bss->caps);
3370 if (ret < 0 || ret >= end - pos)
3371 return 0;
3372 pos += ret;
3373 }
3374
3375 if (mask & WPA_BSS_MASK_QUAL) {
3376 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3377 if (ret < 0 || ret >= end - pos)
3378 return 0;
3379 pos += ret;
3380 }
3381
3382 if (mask & WPA_BSS_MASK_NOISE) {
3383 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3384 if (ret < 0 || ret >= end - pos)
3385 return 0;
3386 pos += ret;
3387 }
3388
3389 if (mask & WPA_BSS_MASK_LEVEL) {
3390 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3391 if (ret < 0 || ret >= end - pos)
3392 return 0;
3393 pos += ret;
3394 }
3395
3396 if (mask & WPA_BSS_MASK_TSF) {
3397 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3398 (unsigned long long) bss->tsf);
3399 if (ret < 0 || ret >= end - pos)
3400 return 0;
3401 pos += ret;
3402 }
3403
3404 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003405 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003406
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003407 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003408 ret = os_snprintf(pos, end - pos, "age=%d\n",
3409 (int) (now.sec - bss->last_update.sec));
3410 if (ret < 0 || ret >= end - pos)
3411 return 0;
3412 pos += ret;
3413 }
3414
3415 if (mask & WPA_BSS_MASK_IE) {
3416 ret = os_snprintf(pos, end - pos, "ie=");
3417 if (ret < 0 || ret >= end - pos)
3418 return 0;
3419 pos += ret;
3420
3421 ie = (const u8 *) (bss + 1);
3422 for (i = 0; i < bss->ie_len; i++) {
3423 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3424 if (ret < 0 || ret >= end - pos)
3425 return 0;
3426 pos += ret;
3427 }
3428
3429 ret = os_snprintf(pos, end - pos, "\n");
3430 if (ret < 0 || ret >= end - pos)
3431 return 0;
3432 pos += ret;
3433 }
3434
3435 if (mask & WPA_BSS_MASK_FLAGS) {
3436 ret = os_snprintf(pos, end - pos, "flags=");
3437 if (ret < 0 || ret >= end - pos)
3438 return 0;
3439 pos += ret;
3440
3441 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3442 if (ie)
3443 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3444 2 + ie[1]);
3445 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3446 if (ie2)
3447 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3448 2 + ie2[1]);
3449 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3450 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3451 ret = os_snprintf(pos, end - pos, "[WEP]");
3452 if (ret < 0 || ret >= end - pos)
3453 return 0;
3454 pos += ret;
3455 }
3456 if (bss->caps & IEEE80211_CAP_IBSS) {
3457 ret = os_snprintf(pos, end - pos, "[IBSS]");
3458 if (ret < 0 || ret >= end - pos)
3459 return 0;
3460 pos += ret;
3461 }
3462 if (bss->caps & IEEE80211_CAP_ESS) {
3463 ret = os_snprintf(pos, end - pos, "[ESS]");
3464 if (ret < 0 || ret >= end - pos)
3465 return 0;
3466 pos += ret;
3467 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07003468 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3469 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003470 ret = os_snprintf(pos, end - pos, "[P2P]");
3471 if (ret < 0 || ret >= end - pos)
3472 return 0;
3473 pos += ret;
3474 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003475#ifdef CONFIG_HS20
3476 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3477 ret = os_snprintf(pos, end - pos, "[HS20]");
3478 if (ret < 0 || ret >= end - pos)
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08003479 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003480 pos += ret;
3481 }
3482#endif /* CONFIG_HS20 */
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003483
3484 ret = os_snprintf(pos, end - pos, "\n");
3485 if (ret < 0 || ret >= end - pos)
3486 return 0;
3487 pos += ret;
3488 }
3489
3490 if (mask & WPA_BSS_MASK_SSID) {
3491 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3492 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3493 if (ret < 0 || ret >= end - pos)
3494 return 0;
3495 pos += ret;
3496 }
3497
3498#ifdef CONFIG_WPS
3499 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3500 ie = (const u8 *) (bss + 1);
3501 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3502 if (ret < 0 || ret >= end - pos)
3503 return 0;
3504 pos += ret;
3505 }
3506#endif /* CONFIG_WPS */
3507
3508#ifdef CONFIG_P2P
3509 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3510 ie = (const u8 *) (bss + 1);
3511 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3512 if (ret < 0 || ret >= end - pos)
3513 return 0;
3514 pos += ret;
3515 }
3516#endif /* CONFIG_P2P */
3517
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003518#ifdef CONFIG_WIFI_DISPLAY
3519 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3520 struct wpabuf *wfd;
3521 ie = (const u8 *) (bss + 1);
3522 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3523 WFD_IE_VENDOR_TYPE);
3524 if (wfd) {
3525 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt96be6222014-02-13 10:16:51 -08003526 if (ret < 0 || ret >= end - pos) {
3527 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08003528 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08003529 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003530 pos += ret;
3531
3532 pos += wpa_snprintf_hex(pos, end - pos,
3533 wpabuf_head(wfd),
3534 wpabuf_len(wfd));
3535 wpabuf_free(wfd);
3536
3537 ret = os_snprintf(pos, end - pos, "\n");
3538 if (ret < 0 || ret >= end - pos)
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08003539 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003540 pos += ret;
3541 }
3542 }
3543#endif /* CONFIG_WIFI_DISPLAY */
3544
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003545#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003546 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3547 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003548 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003549 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003550 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003551 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003552 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003553 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003554 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003555 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003556 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003557 anqp->nai_realm);
3558 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003559 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003560 anqp->domain_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003561#ifdef CONFIG_HS20
3562 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003563 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003564 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003565 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003566 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003567 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003568 pos = anqp_add_hex(pos, end, "hs20_operating_class",
3569 anqp->hs20_operating_class);
3570 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
3571 anqp->hs20_osu_providers_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003572#endif /* CONFIG_HS20 */
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003573 }
3574#endif /* CONFIG_INTERWORKING */
3575
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08003576 if (mask & WPA_BSS_MASK_DELIM) {
3577 ret = os_snprintf(pos, end - pos, "====\n");
3578 if (ret < 0 || ret >= end - pos)
3579 return 0;
3580 pos += ret;
3581 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07003582
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003583 return pos - buf;
3584}
3585
Dmitry Shmidt04949592012-07-19 12:16:46 -07003586
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003587static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3588 const char *cmd, char *buf,
3589 size_t buflen)
3590{
3591 u8 bssid[ETH_ALEN];
3592 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003593 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003594 struct wpa_bss *bsslast = NULL;
3595 struct dl_list *next;
3596 int ret = 0;
3597 int len;
3598 char *ctmp;
3599 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003600
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003601 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3602 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3603 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003604 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003605 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3606 list_id);
3607 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003608 unsigned int id1, id2;
3609
3610 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3611 wpa_printf(MSG_INFO, "Wrong BSS range "
3612 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003613 return 0;
3614 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003615
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003616 if (*(cmd + 6) == '-')
3617 id1 = 0;
3618 else
3619 id1 = atoi(cmd + 6);
3620 ctmp++;
3621 if (*ctmp >= '0' && *ctmp <= '9')
3622 id2 = atoi(ctmp);
3623 else
3624 id2 = (unsigned int) -1;
3625 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3626 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07003627 bsslast = dl_list_last(&wpa_s->bss_id,
3628 struct wpa_bss,
3629 list_id);
3630 else {
3631 bsslast = wpa_bss_get_id(wpa_s, id2);
3632 if (bsslast == NULL && bss && id2 > id1) {
3633 struct wpa_bss *tmp = bss;
3634 for (;;) {
3635 next = tmp->list_id.next;
3636 if (next == &wpa_s->bss_id)
3637 break;
3638 tmp = dl_list_entry(
3639 next, struct wpa_bss,
3640 list_id);
3641 if (tmp->id > id2)
3642 break;
3643 bsslast = tmp;
3644 }
3645 }
3646 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003647 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003648 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07003649 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003650 else if (os_strncmp(cmd, "LAST", 4) == 0)
3651 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003652 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3653 i = atoi(cmd + 3);
3654 bss = wpa_bss_get_id(wpa_s, i);
3655 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3656 i = atoi(cmd + 5);
3657 bss = wpa_bss_get_id(wpa_s, i);
3658 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003659 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003660 if (next == &wpa_s->bss_id)
3661 bss = NULL;
3662 else
3663 bss = dl_list_entry(next, struct wpa_bss,
3664 list_id);
3665 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003666#ifdef CONFIG_P2P
3667 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3668 if (hwaddr_aton(cmd + 13, bssid) == 0)
3669 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3670 else
3671 bss = NULL;
3672#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003673 } else if (hwaddr_aton(cmd, bssid) == 0)
3674 bss = wpa_bss_get_bssid(wpa_s, bssid);
3675 else {
3676 struct wpa_bss *tmp;
3677 i = atoi(cmd);
3678 bss = NULL;
3679 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3680 {
3681 if (i-- == 0) {
3682 bss = tmp;
3683 break;
3684 }
3685 }
3686 }
3687
Dmitry Shmidt04949592012-07-19 12:16:46 -07003688 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3689 mask = strtoul(ctmp + 5, NULL, 0x10);
3690 if (mask == 0)
3691 mask = WPA_BSS_MASK_ALL;
3692 }
3693
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003694 if (bss == NULL)
3695 return 0;
3696
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003697 if (bsslast == NULL)
3698 bsslast = bss;
3699 do {
3700 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3701 ret += len;
3702 buf += len;
3703 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08003704 if (bss == bsslast) {
3705 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3706 (bss == dl_list_last(&wpa_s->bss_id,
3707 struct wpa_bss, list_id)))
3708 os_snprintf(buf - 5, 5, "####\n");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003709 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08003710 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003711 next = bss->list_id.next;
3712 if (next == &wpa_s->bss_id)
3713 break;
3714 bss = dl_list_entry(next, struct wpa_bss, list_id);
3715 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003716
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003717 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003718}
3719
3720
3721static int wpa_supplicant_ctrl_iface_ap_scan(
3722 struct wpa_supplicant *wpa_s, char *cmd)
3723{
3724 int ap_scan = atoi(cmd);
3725 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3726}
3727
3728
3729static int wpa_supplicant_ctrl_iface_scan_interval(
3730 struct wpa_supplicant *wpa_s, char *cmd)
3731{
3732 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003733 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003734}
3735
3736
3737static int wpa_supplicant_ctrl_iface_bss_expire_age(
3738 struct wpa_supplicant *wpa_s, char *cmd)
3739{
3740 int expire_age = atoi(cmd);
3741 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3742}
3743
3744
3745static int wpa_supplicant_ctrl_iface_bss_expire_count(
3746 struct wpa_supplicant *wpa_s, char *cmd)
3747{
3748 int expire_count = atoi(cmd);
3749 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3750}
3751
3752
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07003753static int wpa_supplicant_ctrl_iface_bss_flush(
3754 struct wpa_supplicant *wpa_s, char *cmd)
3755{
3756 int flush_age = atoi(cmd);
3757
3758 if (flush_age == 0)
3759 wpa_bss_flush(wpa_s);
3760 else
3761 wpa_bss_flush_by_age(wpa_s, flush_age);
3762 return 0;
3763}
3764
3765
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003766static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3767{
3768 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3769 /* MLME-DELETEKEYS.request */
3770 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3771 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3772 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3773 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3774#ifdef CONFIG_IEEE80211W
3775 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3776 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3777#endif /* CONFIG_IEEE80211W */
3778
3779 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3780 0);
3781 /* MLME-SETPROTECTION.request(None) */
3782 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3783 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3784 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3785 wpa_sm_drop_sa(wpa_s->wpa);
3786}
3787
3788
3789static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3790 char *addr)
3791{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003792#ifdef CONFIG_NO_SCAN_PROCESSING
3793 return -1;
3794#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003795 u8 bssid[ETH_ALEN];
3796 struct wpa_bss *bss;
3797 struct wpa_ssid *ssid = wpa_s->current_ssid;
3798
3799 if (hwaddr_aton(addr, bssid)) {
3800 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3801 "address '%s'", addr);
3802 return -1;
3803 }
3804
3805 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3806
Dmitry Shmidt444d5672013-04-01 13:08:44 -07003807 if (!ssid) {
3808 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3809 "configuration known for the target AP");
3810 return -1;
3811 }
3812
3813 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003814 if (!bss) {
3815 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3816 "from BSS table");
3817 return -1;
3818 }
3819
3820 /*
3821 * TODO: Find best network configuration block from configuration to
3822 * allow roaming to other networks
3823 */
3824
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003825 wpa_s->reassociate = 1;
3826 wpa_supplicant_connect(wpa_s, bss, ssid);
3827
3828 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003829#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003830}
3831
3832
3833#ifdef CONFIG_P2P
3834static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3835{
3836 unsigned int timeout = atoi(cmd);
3837 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003838 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003839 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003840 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003841 unsigned int search_delay;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003842
3843 if (os_strstr(cmd, "type=social"))
3844 type = P2P_FIND_ONLY_SOCIAL;
3845 else if (os_strstr(cmd, "type=progressive"))
3846 type = P2P_FIND_PROGRESSIVE;
3847
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003848 pos = os_strstr(cmd, "dev_id=");
3849 if (pos) {
3850 pos += 7;
3851 if (hwaddr_aton(pos, dev_id))
3852 return -1;
3853 _dev_id = dev_id;
3854 }
3855
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003856 pos = os_strstr(cmd, "dev_type=");
3857 if (pos) {
3858 pos += 9;
3859 if (wps_dev_type_str2bin(pos, dev_type) < 0)
3860 return -1;
3861 _dev_type = dev_type;
3862 }
3863
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003864 pos = os_strstr(cmd, "delay=");
3865 if (pos) {
3866 pos += 6;
3867 search_delay = atoi(pos);
3868 } else
3869 search_delay = wpas_p2p_search_delay(wpa_s);
3870
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003871 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
3872 _dev_id, search_delay);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003873}
3874
3875
3876static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3877 char *buf, size_t buflen)
3878{
3879 u8 addr[ETH_ALEN];
3880 char *pos, *pos2;
3881 char *pin = NULL;
3882 enum p2p_wps_method wps_method;
3883 int new_pin;
3884 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003885 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003886 int join;
3887 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003888 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003889 int go_intent = -1;
3890 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003891 int pd;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07003892 int ht40, vht;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003893
Dmitry Shmidt04949592012-07-19 12:16:46 -07003894 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3895 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003896 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07003897 * [ht40] [vht] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003898
3899 if (hwaddr_aton(cmd, addr))
3900 return -1;
3901
3902 pos = cmd + 17;
3903 if (*pos != ' ')
3904 return -1;
3905 pos++;
3906
3907 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003908 pos2 = os_strstr(pos, " persistent=");
3909 if (pos2) {
3910 struct wpa_ssid *ssid;
3911 persistent_id = atoi(pos2 + 12);
3912 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3913 if (ssid == NULL || ssid->disabled != 2 ||
3914 ssid->mode != WPAS_MODE_P2P_GO) {
3915 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3916 "SSID id=%d for persistent P2P group (GO)",
3917 persistent_id);
3918 return -1;
3919 }
3920 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003921 join = os_strstr(pos, " join") != NULL;
3922 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003923 automatic = os_strstr(pos, " auto") != NULL;
3924 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07003925 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
3926 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
3927 vht;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003928
3929 pos2 = os_strstr(pos, " go_intent=");
3930 if (pos2) {
3931 pos2 += 11;
3932 go_intent = atoi(pos2);
3933 if (go_intent < 0 || go_intent > 15)
3934 return -1;
3935 }
3936
3937 pos2 = os_strstr(pos, " freq=");
3938 if (pos2) {
3939 pos2 += 6;
3940 freq = atoi(pos2);
3941 if (freq <= 0)
3942 return -1;
3943 }
3944
3945 if (os_strncmp(pos, "pin", 3) == 0) {
3946 /* Request random PIN (to be displayed) and enable the PIN */
3947 wps_method = WPS_PIN_DISPLAY;
3948 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3949 wps_method = WPS_PBC;
3950 } else {
3951 pin = pos;
3952 pos = os_strchr(pin, ' ');
3953 wps_method = WPS_PIN_KEYPAD;
3954 if (pos) {
3955 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003956 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003957 wps_method = WPS_PIN_DISPLAY;
3958 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003959 if (!wps_pin_str_valid(pin)) {
3960 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3961 return 17;
3962 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003963 }
3964
3965 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003966 persistent_group, automatic, join,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003967 auth, go_intent, freq, persistent_id, pd,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07003968 ht40, vht);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003969 if (new_pin == -2) {
3970 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3971 return 25;
3972 }
3973 if (new_pin == -3) {
3974 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3975 return 25;
3976 }
3977 if (new_pin < 0)
3978 return -1;
3979 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3980 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3981 if (ret < 0 || (size_t) ret >= buflen)
3982 return -1;
3983 return ret;
3984 }
3985
3986 os_memcpy(buf, "OK\n", 3);
3987 return 3;
3988}
3989
3990
3991static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3992{
3993 unsigned int timeout = atoi(cmd);
3994 return wpas_p2p_listen(wpa_s, timeout);
3995}
3996
3997
3998static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
3999{
4000 u8 addr[ETH_ALEN];
4001 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004002 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004003
Dmitry Shmidt04949592012-07-19 12:16:46 -07004004 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004005
4006 if (hwaddr_aton(cmd, addr))
4007 return -1;
4008
4009 pos = cmd + 17;
4010 if (*pos != ' ')
4011 return -1;
4012 pos++;
4013
Dmitry Shmidt04949592012-07-19 12:16:46 -07004014 if (os_strstr(pos, " join") != NULL)
4015 use = WPAS_P2P_PD_FOR_JOIN;
4016 else if (os_strstr(pos, " auto") != NULL)
4017 use = WPAS_P2P_PD_AUTO;
4018
4019 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004020}
4021
4022
4023static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4024 size_t buflen)
4025{
4026 struct wpa_ssid *ssid = wpa_s->current_ssid;
4027
4028 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4029 ssid->passphrase == NULL)
4030 return -1;
4031
4032 os_strlcpy(buf, ssid->passphrase, buflen);
4033 return os_strlen(buf);
4034}
4035
4036
4037static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4038 char *buf, size_t buflen)
4039{
4040 u64 ref;
4041 int res;
4042 u8 dst_buf[ETH_ALEN], *dst;
4043 struct wpabuf *tlvs;
4044 char *pos;
4045 size_t len;
4046
4047 if (hwaddr_aton(cmd, dst_buf))
4048 return -1;
4049 dst = dst_buf;
4050 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4051 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4052 dst = NULL;
4053 pos = cmd + 17;
4054 if (*pos != ' ')
4055 return -1;
4056 pos++;
4057
4058 if (os_strncmp(pos, "upnp ", 5) == 0) {
4059 u8 version;
4060 pos += 5;
4061 if (hexstr2bin(pos, &version, 1) < 0)
4062 return -1;
4063 pos += 2;
4064 if (*pos != ' ')
4065 return -1;
4066 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004067 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004068#ifdef CONFIG_WIFI_DISPLAY
4069 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4070 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4071#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004072 } else {
4073 len = os_strlen(pos);
4074 if (len & 1)
4075 return -1;
4076 len /= 2;
4077 tlvs = wpabuf_alloc(len);
4078 if (tlvs == NULL)
4079 return -1;
4080 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4081 wpabuf_free(tlvs);
4082 return -1;
4083 }
4084
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004085 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004086 wpabuf_free(tlvs);
4087 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004088 if (ref == 0)
4089 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004090 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4091 if (res < 0 || (unsigned) res >= buflen)
4092 return -1;
4093 return res;
4094}
4095
4096
4097static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4098 char *cmd)
4099{
4100 long long unsigned val;
4101 u64 req;
4102 if (sscanf(cmd, "%llx", &val) != 1)
4103 return -1;
4104 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004105 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004106}
4107
4108
4109static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4110{
4111 int freq;
4112 u8 dst[ETH_ALEN];
4113 u8 dialog_token;
4114 struct wpabuf *resp_tlvs;
4115 char *pos, *pos2;
4116 size_t len;
4117
4118 pos = os_strchr(cmd, ' ');
4119 if (pos == NULL)
4120 return -1;
4121 *pos++ = '\0';
4122 freq = atoi(cmd);
4123 if (freq == 0)
4124 return -1;
4125
4126 if (hwaddr_aton(pos, dst))
4127 return -1;
4128 pos += 17;
4129 if (*pos != ' ')
4130 return -1;
4131 pos++;
4132
4133 pos2 = os_strchr(pos, ' ');
4134 if (pos2 == NULL)
4135 return -1;
4136 *pos2++ = '\0';
4137 dialog_token = atoi(pos);
4138
4139 len = os_strlen(pos2);
4140 if (len & 1)
4141 return -1;
4142 len /= 2;
4143 resp_tlvs = wpabuf_alloc(len);
4144 if (resp_tlvs == NULL)
4145 return -1;
4146 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4147 wpabuf_free(resp_tlvs);
4148 return -1;
4149 }
4150
4151 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4152 wpabuf_free(resp_tlvs);
4153 return 0;
4154}
4155
4156
4157static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4158 char *cmd)
4159{
Dmitry Shmidt04949592012-07-19 12:16:46 -07004160 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4161 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004162 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4163 return 0;
4164}
4165
4166
4167static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4168 char *cmd)
4169{
4170 char *pos;
4171 size_t len;
4172 struct wpabuf *query, *resp;
4173
4174 pos = os_strchr(cmd, ' ');
4175 if (pos == NULL)
4176 return -1;
4177 *pos++ = '\0';
4178
4179 len = os_strlen(cmd);
4180 if (len & 1)
4181 return -1;
4182 len /= 2;
4183 query = wpabuf_alloc(len);
4184 if (query == NULL)
4185 return -1;
4186 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4187 wpabuf_free(query);
4188 return -1;
4189 }
4190
4191 len = os_strlen(pos);
4192 if (len & 1) {
4193 wpabuf_free(query);
4194 return -1;
4195 }
4196 len /= 2;
4197 resp = wpabuf_alloc(len);
4198 if (resp == NULL) {
4199 wpabuf_free(query);
4200 return -1;
4201 }
4202 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4203 wpabuf_free(query);
4204 wpabuf_free(resp);
4205 return -1;
4206 }
4207
4208 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4209 wpabuf_free(query);
4210 wpabuf_free(resp);
4211 return -1;
4212 }
4213 return 0;
4214}
4215
4216
4217static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4218{
4219 char *pos;
4220 u8 version;
4221
4222 pos = os_strchr(cmd, ' ');
4223 if (pos == NULL)
4224 return -1;
4225 *pos++ = '\0';
4226
4227 if (hexstr2bin(cmd, &version, 1) < 0)
4228 return -1;
4229
4230 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4231}
4232
4233
4234static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4235{
4236 char *pos;
4237
4238 pos = os_strchr(cmd, ' ');
4239 if (pos == NULL)
4240 return -1;
4241 *pos++ = '\0';
4242
4243 if (os_strcmp(cmd, "bonjour") == 0)
4244 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4245 if (os_strcmp(cmd, "upnp") == 0)
4246 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4247 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4248 return -1;
4249}
4250
4251
4252static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4253 char *cmd)
4254{
4255 size_t len;
4256 struct wpabuf *query;
4257 int ret;
4258
4259 len = os_strlen(cmd);
4260 if (len & 1)
4261 return -1;
4262 len /= 2;
4263 query = wpabuf_alloc(len);
4264 if (query == NULL)
4265 return -1;
4266 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4267 wpabuf_free(query);
4268 return -1;
4269 }
4270
4271 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4272 wpabuf_free(query);
4273 return ret;
4274}
4275
4276
4277static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4278{
4279 char *pos;
4280 u8 version;
4281
4282 pos = os_strchr(cmd, ' ');
4283 if (pos == NULL)
4284 return -1;
4285 *pos++ = '\0';
4286
4287 if (hexstr2bin(cmd, &version, 1) < 0)
4288 return -1;
4289
4290 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4291}
4292
4293
4294static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4295{
4296 char *pos;
4297
4298 pos = os_strchr(cmd, ' ');
4299 if (pos == NULL)
4300 return -1;
4301 *pos++ = '\0';
4302
4303 if (os_strcmp(cmd, "bonjour") == 0)
4304 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4305 if (os_strcmp(cmd, "upnp") == 0)
4306 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4307 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4308 return -1;
4309}
4310
4311
4312static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4313{
4314 u8 addr[ETH_ALEN];
4315
4316 /* <addr> */
4317
4318 if (hwaddr_aton(cmd, addr))
4319 return -1;
4320
4321 return wpas_p2p_reject(wpa_s, addr);
4322}
4323
4324
4325static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4326{
4327 char *pos;
4328 int id;
4329 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07004330 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08004331 int freq = 0, pref_freq = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004332 int ht40, vht;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004333
4334 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07004335 pos = os_strstr(cmd, " peer=");
4336 if (pos) {
4337 pos += 6;
4338 if (hwaddr_aton(pos, peer))
4339 return -1;
4340 _peer = peer;
4341 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004342 ssid = wpa_config_get_network(wpa_s->conf, id);
4343 if (ssid == NULL || ssid->disabled != 2) {
4344 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4345 "for persistent P2P group",
4346 id);
4347 return -1;
4348 }
4349
Jouni Malinen31be0a42012-08-31 21:20:51 +03004350 pos = os_strstr(cmd, " freq=");
4351 if (pos) {
4352 pos += 6;
4353 freq = atoi(pos);
4354 if (freq <= 0)
4355 return -1;
4356 }
4357
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08004358 pos = os_strstr(cmd, " pref=");
4359 if (pos) {
4360 pos += 6;
4361 pref_freq = atoi(pos);
4362 if (pref_freq <= 0)
4363 return -1;
4364 }
4365
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004366 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4367 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4368 vht;
Jouni Malinen31be0a42012-08-31 21:20:51 +03004369
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004370 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4371 pref_freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004372}
4373
4374
4375static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4376{
4377 char *pos;
4378 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4379
4380 pos = os_strstr(cmd, " peer=");
4381 if (!pos)
4382 return -1;
4383
4384 *pos = '\0';
4385 pos += 6;
4386 if (hwaddr_aton(pos, peer)) {
4387 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4388 return -1;
4389 }
4390
4391 pos = os_strstr(pos, " go_dev_addr=");
4392 if (pos) {
4393 pos += 13;
4394 if (hwaddr_aton(pos, go_dev_addr)) {
4395 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4396 pos);
4397 return -1;
4398 }
4399 go_dev = go_dev_addr;
4400 }
4401
4402 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4403}
4404
4405
4406static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4407{
4408 if (os_strncmp(cmd, "persistent=", 11) == 0)
4409 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4410 if (os_strncmp(cmd, "group=", 6) == 0)
4411 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4412
4413 return -1;
4414}
4415
4416
4417static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004418 char *cmd, int freq, int ht40,
4419 int vht)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004420{
4421 int id;
4422 struct wpa_ssid *ssid;
4423
4424 id = atoi(cmd);
4425 ssid = wpa_config_get_network(wpa_s->conf, id);
4426 if (ssid == NULL || ssid->disabled != 2) {
4427 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4428 "for persistent P2P group",
4429 id);
4430 return -1;
4431 }
4432
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004433 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004434 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004435}
4436
4437
4438static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4439{
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004440 int freq = 0, ht40, vht;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004441 char *pos;
4442
4443 pos = os_strstr(cmd, "freq=");
4444 if (pos)
4445 freq = atoi(pos + 5);
4446
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004447 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4448 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4449 vht;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004450
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004451 if (os_strncmp(cmd, "persistent=", 11) == 0)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004452 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004453 ht40, vht);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004454 if (os_strcmp(cmd, "persistent") == 0 ||
4455 os_strncmp(cmd, "persistent ", 11) == 0)
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004456 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004457 if (os_strncmp(cmd, "freq=", 5) == 0)
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004458 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004459 if (ht40)
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004460 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004461
4462 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4463 cmd);
4464 return -1;
4465}
4466
4467
4468static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4469 char *buf, size_t buflen)
4470{
4471 u8 addr[ETH_ALEN], *addr_ptr;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004472 int next, res;
4473 const struct p2p_peer_info *info;
4474 char *pos, *end;
4475 char devtype[WPS_DEV_TYPE_BUFSIZE];
4476 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004477 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004478
4479 if (!wpa_s->global->p2p)
4480 return -1;
4481
4482 if (os_strcmp(cmd, "FIRST") == 0) {
4483 addr_ptr = NULL;
4484 next = 0;
4485 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4486 if (hwaddr_aton(cmd + 5, addr) < 0)
4487 return -1;
4488 addr_ptr = addr;
4489 next = 1;
4490 } else {
4491 if (hwaddr_aton(cmd, addr) < 0)
4492 return -1;
4493 addr_ptr = addr;
4494 next = 0;
4495 }
4496
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004497 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4498 if (info == NULL)
4499 return -1;
4500
4501 pos = buf;
4502 end = buf + buflen;
4503
4504 res = os_snprintf(pos, end - pos, MACSTR "\n"
4505 "pri_dev_type=%s\n"
4506 "device_name=%s\n"
4507 "manufacturer=%s\n"
4508 "model_name=%s\n"
4509 "model_number=%s\n"
4510 "serial_number=%s\n"
4511 "config_methods=0x%x\n"
4512 "dev_capab=0x%x\n"
4513 "group_capab=0x%x\n"
4514 "level=%d\n",
4515 MAC2STR(info->p2p_device_addr),
4516 wps_dev_type_bin2str(info->pri_dev_type,
4517 devtype, sizeof(devtype)),
4518 info->device_name,
4519 info->manufacturer,
4520 info->model_name,
4521 info->model_number,
4522 info->serial_number,
4523 info->config_methods,
4524 info->dev_capab,
4525 info->group_capab,
4526 info->level);
4527 if (res < 0 || res >= end - pos)
4528 return pos - buf;
4529 pos += res;
4530
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004531 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4532 {
4533 const u8 *t;
4534 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4535 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4536 wps_dev_type_bin2str(t, devtype,
4537 sizeof(devtype)));
4538 if (res < 0 || res >= end - pos)
4539 return pos - buf;
4540 pos += res;
4541 }
4542
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004543 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004544 if (ssid) {
4545 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4546 if (res < 0 || res >= end - pos)
4547 return pos - buf;
4548 pos += res;
4549 }
4550
4551 res = p2p_get_peer_info_txt(info, pos, end - pos);
4552 if (res < 0)
4553 return pos - buf;
4554 pos += res;
4555
4556 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004557}
4558
4559
Dmitry Shmidt04949592012-07-19 12:16:46 -07004560static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4561 const char *param)
4562{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07004563 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004564
4565 if (wpa_s->global->p2p == NULL)
4566 return -1;
4567
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07004568 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4569 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004570
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07004571 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4572 struct wpa_freq_range *freq;
4573 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07004574 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07004575 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004576 }
4577
Dmitry Shmidt04949592012-07-19 12:16:46 -07004578 wpas_p2p_update_channel_list(wpa_s);
4579 return 0;
4580}
4581
4582
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004583static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4584{
4585 char *param;
4586
4587 if (wpa_s->global->p2p == NULL)
4588 return -1;
4589
4590 param = os_strchr(cmd, ' ');
4591 if (param == NULL)
4592 return -1;
4593 *param++ = '\0';
4594
4595 if (os_strcmp(cmd, "discoverability") == 0) {
4596 p2p_set_client_discoverability(wpa_s->global->p2p,
4597 atoi(param));
4598 return 0;
4599 }
4600
4601 if (os_strcmp(cmd, "managed") == 0) {
4602 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4603 return 0;
4604 }
4605
4606 if (os_strcmp(cmd, "listen_channel") == 0) {
4607 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4608 atoi(param));
4609 }
4610
4611 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4612 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4613 os_strlen(param));
4614 }
4615
4616 if (os_strcmp(cmd, "noa") == 0) {
4617 char *pos;
4618 int count, start, duration;
4619 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4620 count = atoi(param);
4621 pos = os_strchr(param, ',');
4622 if (pos == NULL)
4623 return -1;
4624 pos++;
4625 start = atoi(pos);
4626 pos = os_strchr(pos, ',');
4627 if (pos == NULL)
4628 return -1;
4629 pos++;
4630 duration = atoi(pos);
4631 if (count < 0 || count > 255 || start < 0 || duration < 0)
4632 return -1;
4633 if (count == 0 && duration > 0)
4634 return -1;
4635 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4636 "start=%d duration=%d", count, start, duration);
4637 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4638 }
4639
4640 if (os_strcmp(cmd, "ps") == 0)
4641 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4642
4643 if (os_strcmp(cmd, "oppps") == 0)
4644 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4645
4646 if (os_strcmp(cmd, "ctwindow") == 0)
4647 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4648
4649 if (os_strcmp(cmd, "disabled") == 0) {
4650 wpa_s->global->p2p_disabled = atoi(param);
4651 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4652 wpa_s->global->p2p_disabled ?
4653 "disabled" : "enabled");
4654 if (wpa_s->global->p2p_disabled) {
4655 wpas_p2p_stop_find(wpa_s);
4656 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4657 p2p_flush(wpa_s->global->p2p);
4658 }
4659 return 0;
4660 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004661
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07004662 if (os_strcmp(cmd, "conc_pref") == 0) {
4663 if (os_strcmp(param, "sta") == 0)
4664 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4665 else if (os_strcmp(param, "p2p") == 0)
4666 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07004667 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07004668 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07004669 return -1;
4670 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07004671 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07004672 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07004673 return 0;
4674 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004675
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004676 if (os_strcmp(cmd, "force_long_sd") == 0) {
4677 wpa_s->force_long_sd = atoi(param);
4678 return 0;
4679 }
4680
4681 if (os_strcmp(cmd, "peer_filter") == 0) {
4682 u8 addr[ETH_ALEN];
4683 if (hwaddr_aton(param, addr))
4684 return -1;
4685 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4686 return 0;
4687 }
4688
4689 if (os_strcmp(cmd, "cross_connect") == 0)
4690 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4691
4692 if (os_strcmp(cmd, "go_apsd") == 0) {
4693 if (os_strcmp(param, "disable") == 0)
4694 wpa_s->set_ap_uapsd = 0;
4695 else {
4696 wpa_s->set_ap_uapsd = 1;
4697 wpa_s->ap_uapsd = atoi(param);
4698 }
4699 return 0;
4700 }
4701
4702 if (os_strcmp(cmd, "client_apsd") == 0) {
4703 if (os_strcmp(param, "disable") == 0)
4704 wpa_s->set_sta_uapsd = 0;
4705 else {
4706 int be, bk, vi, vo;
4707 char *pos;
4708 /* format: BE,BK,VI,VO;max SP Length */
4709 be = atoi(param);
4710 pos = os_strchr(param, ',');
4711 if (pos == NULL)
4712 return -1;
4713 pos++;
4714 bk = atoi(pos);
4715 pos = os_strchr(pos, ',');
4716 if (pos == NULL)
4717 return -1;
4718 pos++;
4719 vi = atoi(pos);
4720 pos = os_strchr(pos, ',');
4721 if (pos == NULL)
4722 return -1;
4723 pos++;
4724 vo = atoi(pos);
4725 /* ignore max SP Length for now */
4726
4727 wpa_s->set_sta_uapsd = 1;
4728 wpa_s->sta_uapsd = 0;
4729 if (be)
4730 wpa_s->sta_uapsd |= BIT(0);
4731 if (bk)
4732 wpa_s->sta_uapsd |= BIT(1);
4733 if (vi)
4734 wpa_s->sta_uapsd |= BIT(2);
4735 if (vo)
4736 wpa_s->sta_uapsd |= BIT(3);
4737 }
4738 return 0;
4739 }
4740
Dmitry Shmidt04949592012-07-19 12:16:46 -07004741 if (os_strcmp(cmd, "disallow_freq") == 0)
4742 return p2p_ctrl_disallow_freq(wpa_s, param);
4743
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004744 if (os_strcmp(cmd, "disc_int") == 0) {
4745 int min_disc_int, max_disc_int, max_disc_tu;
4746 char *pos;
4747
4748 pos = param;
4749
4750 min_disc_int = atoi(pos);
4751 pos = os_strchr(pos, ' ');
4752 if (pos == NULL)
4753 return -1;
4754 *pos++ = '\0';
4755
4756 max_disc_int = atoi(pos);
4757 pos = os_strchr(pos, ' ');
4758 if (pos == NULL)
4759 return -1;
4760 *pos++ = '\0';
4761
4762 max_disc_tu = atoi(pos);
4763
4764 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4765 max_disc_int, max_disc_tu);
4766 }
4767
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004768 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4769 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4770 return 0;
4771 }
4772
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004773#ifdef CONFIG_WPS_NFC
4774 if (os_strcmp(cmd, "nfc_tag") == 0)
4775 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
4776#endif /* CONFIG_WPS_NFC */
4777
4778 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
4779 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
4780 return 0;
4781 }
4782
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004783 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4784 cmd);
4785
4786 return -1;
4787}
4788
4789
Dmitry Shmidt444d5672013-04-01 13:08:44 -07004790static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4791{
4792 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4793 wpa_s->force_long_sd = 0;
4794 if (wpa_s->global->p2p)
4795 p2p_flush(wpa_s->global->p2p);
4796}
4797
4798
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004799static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4800{
4801 char *pos, *pos2;
4802 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4803
4804 if (cmd[0]) {
4805 pos = os_strchr(cmd, ' ');
4806 if (pos == NULL)
4807 return -1;
4808 *pos++ = '\0';
4809 dur1 = atoi(cmd);
4810
4811 pos2 = os_strchr(pos, ' ');
4812 if (pos2)
4813 *pos2++ = '\0';
4814 int1 = atoi(pos);
4815 } else
4816 pos2 = NULL;
4817
4818 if (pos2) {
4819 pos = os_strchr(pos2, ' ');
4820 if (pos == NULL)
4821 return -1;
4822 *pos++ = '\0';
4823 dur2 = atoi(pos2);
4824 int2 = atoi(pos);
4825 }
4826
4827 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
4828}
4829
4830
4831static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
4832{
4833 char *pos;
4834 unsigned int period = 0, interval = 0;
4835
4836 if (cmd[0]) {
4837 pos = os_strchr(cmd, ' ');
4838 if (pos == NULL)
4839 return -1;
4840 *pos++ = '\0';
4841 period = atoi(cmd);
4842 interval = atoi(pos);
4843 }
4844
4845 return wpas_p2p_ext_listen(wpa_s, period, interval);
4846}
4847
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004848
4849static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
4850{
4851 const char *pos;
4852 u8 peer[ETH_ALEN];
4853 int iface_addr = 0;
4854
4855 pos = cmd;
4856 if (os_strncmp(pos, "iface=", 6) == 0) {
4857 iface_addr = 1;
4858 pos += 6;
4859 }
4860 if (hwaddr_aton(pos, peer))
4861 return -1;
4862
4863 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
4864 return 0;
4865}
4866
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004867#endif /* CONFIG_P2P */
4868
4869
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004870static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
4871{
4872 struct wpa_freq_range_list ranges;
4873 int *freqs = NULL;
4874 struct hostapd_hw_modes *mode;
4875 u16 i;
4876
4877 if (wpa_s->hw.modes == NULL)
4878 return NULL;
4879
4880 os_memset(&ranges, 0, sizeof(ranges));
4881 if (freq_range_list_parse(&ranges, val) < 0)
4882 return NULL;
4883
4884 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4885 int j;
4886
4887 mode = &wpa_s->hw.modes[i];
4888 for (j = 0; j < mode->num_channels; j++) {
4889 unsigned int freq;
4890
4891 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
4892 continue;
4893
4894 freq = mode->channels[j].freq;
4895 if (!freq_range_list_includes(&ranges, freq))
4896 continue;
4897
4898 int_array_add_unique(&freqs, freq);
4899 }
4900 }
4901
4902 os_free(ranges.range);
4903 return freqs;
4904}
4905
4906
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004907#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004908
4909static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
4910{
4911 int auto_sel = 0;
4912 int *freqs = NULL;
4913
4914 if (param) {
4915 char *pos;
4916
4917 auto_sel = os_strstr(param, "auto") != NULL;
4918
4919 pos = os_strstr(param, "freq=");
4920 if (pos) {
4921 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
4922 if (freqs == NULL)
4923 return -1;
4924 }
4925
4926 }
4927
4928 return interworking_select(wpa_s, auto_sel, freqs);
4929}
4930
4931
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004932static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
4933{
4934 u8 bssid[ETH_ALEN];
4935 struct wpa_bss *bss;
4936
4937 if (hwaddr_aton(dst, bssid)) {
4938 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
4939 return -1;
4940 }
4941
4942 bss = wpa_bss_get_bssid(wpa_s, bssid);
4943 if (bss == NULL) {
4944 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4945 MAC2STR(bssid));
4946 return -1;
4947 }
4948
4949 return interworking_connect(wpa_s, bss);
4950}
4951
4952
4953static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4954{
4955 u8 dst_addr[ETH_ALEN];
4956 int used;
4957 char *pos;
4958#define MAX_ANQP_INFO_ID 100
4959 u16 id[MAX_ANQP_INFO_ID];
4960 size_t num_id = 0;
4961
4962 used = hwaddr_aton2(dst, dst_addr);
4963 if (used < 0)
4964 return -1;
4965 pos = dst + used;
4966 while (num_id < MAX_ANQP_INFO_ID) {
4967 id[num_id] = atoi(pos);
4968 if (id[num_id])
4969 num_id++;
4970 pos = os_strchr(pos + 1, ',');
4971 if (pos == NULL)
4972 break;
4973 pos++;
4974 }
4975
4976 if (num_id == 0)
4977 return -1;
4978
4979 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4980}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004981
4982
4983static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4984{
4985 u8 dst_addr[ETH_ALEN];
4986 struct wpabuf *advproto, *query = NULL;
4987 int used, ret = -1;
4988 char *pos, *end;
4989 size_t len;
4990
4991 used = hwaddr_aton2(cmd, dst_addr);
4992 if (used < 0)
4993 return -1;
4994
4995 pos = cmd + used;
4996 while (*pos == ' ')
4997 pos++;
4998
4999 /* Advertisement Protocol ID */
5000 end = os_strchr(pos, ' ');
5001 if (end)
5002 len = end - pos;
5003 else
5004 len = os_strlen(pos);
5005 if (len & 0x01)
5006 return -1;
5007 len /= 2;
5008 if (len == 0)
5009 return -1;
5010 advproto = wpabuf_alloc(len);
5011 if (advproto == NULL)
5012 return -1;
5013 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
5014 goto fail;
5015
5016 if (end) {
5017 /* Optional Query Request */
5018 pos = end + 1;
5019 while (*pos == ' ')
5020 pos++;
5021
5022 len = os_strlen(pos);
5023 if (len) {
5024 if (len & 0x01)
5025 goto fail;
5026 len /= 2;
5027 if (len == 0)
5028 goto fail;
5029 query = wpabuf_alloc(len);
5030 if (query == NULL)
5031 goto fail;
5032 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
5033 goto fail;
5034 }
5035 }
5036
5037 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
5038
5039fail:
5040 wpabuf_free(advproto);
5041 wpabuf_free(query);
5042
5043 return ret;
5044}
5045
5046
5047static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5048 size_t buflen)
5049{
5050 u8 addr[ETH_ALEN];
5051 int dialog_token;
5052 int used;
5053 char *pos;
5054 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005055 struct wpabuf *resp;
5056 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005057
5058 used = hwaddr_aton2(cmd, addr);
5059 if (used < 0)
5060 return -1;
5061
5062 pos = cmd + used;
5063 while (*pos == ' ')
5064 pos++;
5065 dialog_token = atoi(pos);
5066
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005067 if (wpa_s->last_gas_resp &&
5068 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5069 dialog_token == wpa_s->last_gas_dialog_token)
5070 resp = wpa_s->last_gas_resp;
5071 else if (wpa_s->prev_gas_resp &&
5072 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5073 dialog_token == wpa_s->prev_gas_dialog_token)
5074 resp = wpa_s->prev_gas_resp;
5075 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005076 return -1;
5077
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005078 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005079 start = 0;
5080 requested_len = resp_len;
5081
5082 pos = os_strchr(pos, ' ');
5083 if (pos) {
5084 start = atoi(pos);
5085 if (start > resp_len)
5086 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5087 pos = os_strchr(pos, ',');
5088 if (pos == NULL)
5089 return -1;
5090 pos++;
5091 requested_len = atoi(pos);
5092 if (start + requested_len > resp_len)
5093 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5094 }
5095
5096 if (requested_len * 2 + 1 > buflen)
5097 return os_snprintf(buf, buflen, "FAIL-Too long response");
5098
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005099 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5100 requested_len);
5101
5102 if (start + requested_len == resp_len) {
5103 /*
5104 * Free memory by dropping the response after it has been
5105 * fetched.
5106 */
5107 if (resp == wpa_s->prev_gas_resp) {
5108 wpabuf_free(wpa_s->prev_gas_resp);
5109 wpa_s->prev_gas_resp = NULL;
5110 } else {
5111 wpabuf_free(wpa_s->last_gas_resp);
5112 wpa_s->last_gas_resp = NULL;
5113 }
5114 }
5115
5116 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005117}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005118#endif /* CONFIG_INTERWORKING */
5119
5120
Dmitry Shmidt04949592012-07-19 12:16:46 -07005121#ifdef CONFIG_HS20
5122
5123static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5124{
5125 u8 dst_addr[ETH_ALEN];
5126 int used;
5127 char *pos;
5128 u32 subtypes = 0;
5129
5130 used = hwaddr_aton2(dst, dst_addr);
5131 if (used < 0)
5132 return -1;
5133 pos = dst + used;
5134 for (;;) {
5135 int num = atoi(pos);
5136 if (num <= 0 || num > 31)
5137 return -1;
5138 subtypes |= BIT(num);
5139 pos = os_strchr(pos + 1, ',');
5140 if (pos == NULL)
5141 break;
5142 pos++;
5143 }
5144
5145 if (subtypes == 0)
5146 return -1;
5147
5148 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5149}
5150
5151
5152static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5153 const u8 *addr, const char *realm)
5154{
5155 u8 *buf;
5156 size_t rlen, len;
5157 int ret;
5158
5159 rlen = os_strlen(realm);
5160 len = 3 + rlen;
5161 buf = os_malloc(len);
5162 if (buf == NULL)
5163 return -1;
5164 buf[0] = 1; /* NAI Home Realm Count */
5165 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5166 buf[2] = rlen;
5167 os_memcpy(buf + 3, realm, rlen);
5168
5169 ret = hs20_anqp_send_req(wpa_s, addr,
5170 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5171 buf, len);
5172
5173 os_free(buf);
5174
5175 return ret;
5176}
5177
5178
5179static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5180 char *dst)
5181{
5182 struct wpa_cred *cred = wpa_s->conf->cred;
5183 u8 dst_addr[ETH_ALEN];
5184 int used;
5185 u8 *buf;
5186 size_t len;
5187 int ret;
5188
5189 used = hwaddr_aton2(dst, dst_addr);
5190 if (used < 0)
5191 return -1;
5192
5193 while (dst[used] == ' ')
5194 used++;
5195 if (os_strncmp(dst + used, "realm=", 6) == 0)
5196 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5197 dst + used + 6);
5198
5199 len = os_strlen(dst + used);
5200
5201 if (len == 0 && cred && cred->realm)
5202 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5203
5204 if (len % 1)
5205 return -1;
5206 len /= 2;
5207 buf = os_malloc(len);
5208 if (buf == NULL)
5209 return -1;
5210 if (hexstr2bin(dst + used, buf, len) < 0) {
5211 os_free(buf);
5212 return -1;
5213 }
5214
5215 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5216 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5217 buf, len);
5218 os_free(buf);
5219
5220 return ret;
5221}
5222
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005223
5224static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5225{
5226 u8 dst_addr[ETH_ALEN];
5227 int used;
5228 char *icon;
5229
5230 used = hwaddr_aton2(cmd, dst_addr);
5231 if (used < 0)
5232 return -1;
5233
5234 while (cmd[used] == ' ')
5235 used++;
5236 icon = &cmd[used];
5237
5238 wpa_s->fetch_osu_icon_in_progress = 0;
5239 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5240 (u8 *) icon, os_strlen(icon));
5241}
5242
Dmitry Shmidt04949592012-07-19 12:16:46 -07005243#endif /* CONFIG_HS20 */
5244
5245
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005246static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5247 struct wpa_supplicant *wpa_s, char *cmd)
5248{
5249 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5250 return 0;
5251}
5252
5253
Dmitry Shmidt04949592012-07-19 12:16:46 -07005254#ifdef CONFIG_AUTOSCAN
5255
5256static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5257 char *cmd)
5258{
5259 enum wpa_states state = wpa_s->wpa_state;
5260 char *new_params = NULL;
5261
5262 if (os_strlen(cmd) > 0) {
5263 new_params = os_strdup(cmd);
5264 if (new_params == NULL)
5265 return -1;
5266 }
5267
5268 os_free(wpa_s->conf->autoscan);
5269 wpa_s->conf->autoscan = new_params;
5270
5271 if (wpa_s->conf->autoscan == NULL)
5272 autoscan_deinit(wpa_s);
5273 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5274 autoscan_init(wpa_s, 1);
5275 else if (state == WPA_SCANNING)
5276 wpa_supplicant_reinit_autoscan(wpa_s);
5277
5278 return 0;
5279}
5280
5281#endif /* CONFIG_AUTOSCAN */
5282
5283
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005284#ifdef CONFIG_WNM
5285
5286static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5287{
5288 int enter;
5289 int intval = 0;
5290 char *pos;
5291 int ret;
5292 struct wpabuf *tfs_req = NULL;
5293
5294 if (os_strncmp(cmd, "enter", 5) == 0)
5295 enter = 1;
5296 else if (os_strncmp(cmd, "exit", 4) == 0)
5297 enter = 0;
5298 else
5299 return -1;
5300
5301 pos = os_strstr(cmd, " interval=");
5302 if (pos)
5303 intval = atoi(pos + 10);
5304
5305 pos = os_strstr(cmd, " tfs_req=");
5306 if (pos) {
5307 char *end;
5308 size_t len;
5309 pos += 9;
5310 end = os_strchr(pos, ' ');
5311 if (end)
5312 len = end - pos;
5313 else
5314 len = os_strlen(pos);
5315 if (len & 1)
5316 return -1;
5317 len /= 2;
5318 tfs_req = wpabuf_alloc(len);
5319 if (tfs_req == NULL)
5320 return -1;
5321 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5322 wpabuf_free(tfs_req);
5323 return -1;
5324 }
5325 }
5326
5327 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5328 WNM_SLEEP_MODE_EXIT, intval,
5329 tfs_req);
5330 wpabuf_free(tfs_req);
5331
5332 return ret;
5333}
5334
Dmitry Shmidt44c95782013-05-17 09:51:35 -07005335
5336static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5337{
5338 int query_reason;
5339
5340 query_reason = atoi(cmd);
5341
5342 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5343 query_reason);
5344
5345 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5346}
5347
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005348#endif /* CONFIG_WNM */
5349
5350
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005351/* Get string representation of channel width */
5352static const char * channel_width_name(enum chan_width width)
5353{
5354 switch (width) {
5355 case CHAN_WIDTH_20_NOHT:
5356 return "20 MHz (no HT)";
5357 case CHAN_WIDTH_20:
5358 return "20 MHz";
5359 case CHAN_WIDTH_40:
5360 return "40 MHz";
5361 case CHAN_WIDTH_80:
5362 return "80 MHz";
5363 case CHAN_WIDTH_80P80:
5364 return "80+80 MHz";
5365 case CHAN_WIDTH_160:
5366 return "160 MHz";
5367 default:
5368 return "unknown";
5369 }
5370}
5371
5372
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005373static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5374 size_t buflen)
5375{
5376 struct wpa_signal_info si;
5377 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005378 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005379
5380 ret = wpa_drv_signal_poll(wpa_s, &si);
5381 if (ret)
5382 return -1;
5383
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005384 pos = buf;
5385 end = buf + buflen;
5386
5387 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005388 "NOISE=%d\nFREQUENCY=%u\n",
5389 si.current_signal, si.current_txrate / 1000,
5390 si.current_noise, si.frequency);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005391 if (ret < 0 || ret > end - pos)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005392 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005393 pos += ret;
5394
5395 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5396 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5397 channel_width_name(si.chanwidth));
5398 if (ret < 0 || ret > end - pos)
5399 return -1;
5400 pos += ret;
5401 }
5402
5403 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5404 ret = os_snprintf(pos, end - pos,
5405 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5406 si.center_frq1, si.center_frq2);
5407 if (ret < 0 || ret > end - pos)
5408 return -1;
5409 pos += ret;
5410 }
5411
5412 if (si.avg_signal) {
5413 ret = os_snprintf(pos, end - pos,
5414 "AVG_RSSI=%d\n", si.avg_signal);
5415 if (ret < 0 || ret >= end - pos)
5416 return -1;
5417 pos += ret;
5418 }
5419
5420 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005421}
5422
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03005423
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07005424static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5425 size_t buflen)
5426{
5427 struct hostap_sta_driver_data sta;
5428 int ret;
5429
5430 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5431 if (ret)
5432 return -1;
5433
5434 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03005435 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5436 if (ret < 0 || (size_t) ret > buflen)
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07005437 return -1;
5438 return ret;
5439}
5440
5441
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005442#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07005443static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5444 char *buf, size_t buflen)
5445{
5446 int ret;
5447
5448 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07005449 if (ret == 0) {
5450 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5451 struct p2p_data *p2p = wpa_s->global->p2p;
5452 if (p2p) {
5453 char country[3];
5454 country[0] = cmd[8];
5455 country[1] = cmd[9];
5456 country[2] = 0x04;
5457 p2p_set_country(p2p, country);
5458 }
5459 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08005460 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt9432e122013-09-12 12:39:30 -07005461 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07005462 return ret;
5463}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08005464#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07005465
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005466
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005467static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5468{
5469 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5470
5471#ifdef CONFIG_P2P
5472 wpas_p2p_stop_find(wpa_s);
5473 p2p_ctrl_flush(wpa_s);
5474 wpas_p2p_group_remove(wpa_s, "*");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005475 wpas_p2p_service_flush(wpa_s);
5476 wpa_s->global->p2p_disabled = 0;
5477 wpa_s->global->p2p_per_sta_psk = 0;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005478 wpa_s->conf->num_sec_device_types = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005479 wpa_s->p2p_disable_ip_addr_req = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005480#endif /* CONFIG_P2P */
5481
5482#ifdef CONFIG_WPS_TESTING
5483 wps_version_number = 0x20;
5484 wps_testing_dummy_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005485 wps_corrupt_pkhash = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005486#endif /* CONFIG_WPS_TESTING */
5487#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005488 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005489 wpas_wps_cancel(wpa_s);
5490#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07005491 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005492 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005493
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005494#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005495#ifdef CONFIG_TDLS_TESTING
5496 extern unsigned int tdls_testing;
5497 tdls_testing = 0;
5498#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005499 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5500 wpa_tdls_enable(wpa_s->wpa, 1);
5501#endif /* CONFIG_TDLS */
5502
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07005503 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5504 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5505
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005506 wpa_s->no_keep_alive = 0;
5507
5508 os_free(wpa_s->disallow_aps_bssid);
5509 wpa_s->disallow_aps_bssid = NULL;
5510 wpa_s->disallow_aps_bssid_count = 0;
5511 os_free(wpa_s->disallow_aps_ssid);
5512 wpa_s->disallow_aps_ssid = NULL;
5513 wpa_s->disallow_aps_ssid_count = 0;
5514
5515 wpa_s->set_sta_uapsd = 0;
5516 wpa_s->sta_uapsd = 0;
5517
5518 wpa_drv_radio_disable(wpa_s, 0);
5519
5520 wpa_bss_flush(wpa_s);
5521 wpa_blacklist_clear(wpa_s);
Dmitry Shmidt4b060592013-04-29 16:42:49 -07005522 wpa_s->extra_blacklist_count = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005523 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5524 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005525 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08005526 wpa_s->conf->auto_interworking = 0;
5527 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005528
5529 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5530 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5531 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5532 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5533
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005534 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005535
5536 wpa_s->next_ssid = NULL;
5537
5538#ifdef CONFIG_INTERWORKING
5539 hs20_cancel_fetch_osu(wpa_s);
5540#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005541}
5542
5543
5544static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5545 char *buf, size_t buflen)
5546{
5547 struct wpa_radio_work *work;
5548 char *pos, *end;
5549 struct os_reltime now, diff;
5550
5551 pos = buf;
5552 end = buf + buflen;
5553
5554 os_get_reltime(&now);
5555
5556 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5557 {
5558 int ret;
5559
5560 os_reltime_sub(&now, &work->time, &diff);
5561 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5562 work->type, work->wpa_s->ifname, work->freq,
5563 work->started, diff.sec, diff.usec);
5564 if (ret < 0 || ret >= end - pos)
5565 break;
5566 pos += ret;
5567 }
5568
5569 return pos - buf;
5570}
5571
5572
5573static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5574{
5575 struct wpa_radio_work *work = eloop_ctx;
5576 struct wpa_external_work *ework = work->ctx;
5577
5578 wpa_dbg(work->wpa_s, MSG_DEBUG,
5579 "Timing out external radio work %u (%s)",
5580 ework->id, work->type);
5581 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5582 os_free(ework);
5583 radio_work_done(work);
5584}
5585
5586
5587static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5588{
5589 struct wpa_external_work *ework = work->ctx;
5590
5591 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005592 if (work->started)
5593 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5594 work, NULL);
5595
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005596 os_free(ework);
5597 return;
5598 }
5599
5600 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5601 ework->id, ework->type);
5602 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5603 if (!ework->timeout)
5604 ework->timeout = 10;
5605 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5606 work, NULL);
5607}
5608
5609
5610static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5611 char *buf, size_t buflen)
5612{
5613 struct wpa_external_work *ework;
5614 char *pos, *pos2;
5615 size_t type_len;
5616 int ret;
5617 unsigned int freq = 0;
5618
5619 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5620
5621 ework = os_zalloc(sizeof(*ework));
5622 if (ework == NULL)
5623 return -1;
5624
5625 pos = os_strchr(cmd, ' ');
5626 if (pos) {
5627 type_len = pos - cmd;
5628 pos++;
5629
5630 pos2 = os_strstr(pos, "freq=");
5631 if (pos2)
5632 freq = atoi(pos2 + 5);
5633
5634 pos2 = os_strstr(pos, "timeout=");
5635 if (pos2)
5636 ework->timeout = atoi(pos2 + 8);
5637 } else {
5638 type_len = os_strlen(cmd);
5639 }
5640 if (4 + type_len >= sizeof(ework->type))
5641 type_len = sizeof(ework->type) - 4 - 1;
5642 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5643 os_memcpy(ework->type + 4, cmd, type_len);
5644 ework->type[4 + type_len] = '\0';
5645
5646 wpa_s->ext_work_id++;
5647 if (wpa_s->ext_work_id == 0)
5648 wpa_s->ext_work_id++;
5649 ework->id = wpa_s->ext_work_id;
5650
5651 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5652 ework) < 0) {
5653 os_free(ework);
5654 return -1;
5655 }
5656
5657 ret = os_snprintf(buf, buflen, "%u", ework->id);
5658 if (ret < 0 || (size_t) ret >= buflen)
5659 return -1;
5660 return ret;
5661}
5662
5663
5664static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5665{
5666 struct wpa_radio_work *work;
5667 unsigned int id = atoi(cmd);
5668
5669 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5670 {
5671 struct wpa_external_work *ework;
5672
5673 if (os_strncmp(work->type, "ext:", 4) != 0)
5674 continue;
5675 ework = work->ctx;
5676 if (id && ework->id != id)
5677 continue;
5678 wpa_dbg(wpa_s, MSG_DEBUG,
5679 "Completed external radio work %u (%s)",
5680 ework->id, ework->type);
5681 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5682 os_free(ework);
5683 radio_work_done(work);
5684 return 3; /* "OK\n" */
5685 }
5686
5687 return -1;
5688}
5689
5690
5691static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5692 char *buf, size_t buflen)
5693{
5694 if (os_strcmp(cmd, "show") == 0)
5695 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5696 if (os_strncmp(cmd, "add ", 4) == 0)
5697 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5698 if (os_strncmp(cmd, "done ", 5) == 0)
5699 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5700 return -1;
5701}
5702
5703
5704void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5705{
5706 struct wpa_radio_work *work, *tmp;
5707
Dmitry Shmidt18463232014-01-24 12:29:41 -08005708 if (!wpa_s || !wpa_s->radio)
5709 return;
5710
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005711 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5712 struct wpa_radio_work, list) {
5713 struct wpa_external_work *ework;
5714
5715 if (os_strncmp(work->type, "ext:", 4) != 0)
5716 continue;
5717 ework = work->ctx;
5718 wpa_dbg(wpa_s, MSG_DEBUG,
5719 "Flushing %sexternal radio work %u (%s)",
5720 work->started ? " started" : "", ework->id,
5721 ework->type);
5722 if (work->started)
5723 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5724 work, NULL);
5725 os_free(ework);
5726 radio_work_done(work);
5727 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005728}
5729
5730
Dmitry Shmidt051af732013-10-22 13:52:46 -07005731static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
5732{
5733 struct wpa_supplicant *wpa_s = eloop_ctx;
5734 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5735}
5736
5737
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005738static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
5739{
5740 int *freqs = NULL;
5741
5742 freqs = freq_range_to_channel_list(wpa_s, val);
5743 if (freqs == NULL)
5744 return -1;
5745
5746 os_free(wpa_s->manual_scan_freqs);
5747 wpa_s->manual_scan_freqs = freqs;
5748
5749 return 0;
5750}
5751
5752
5753static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
5754 char *reply, int reply_size, int *reply_len)
5755{
5756 char *pos;
5757
5758 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5759 *reply_len = -1;
5760 return;
5761 }
5762
5763 wpa_s->manual_scan_passive = 0;
5764 wpa_s->manual_scan_use_id = 0;
5765 wpa_s->manual_scan_only_new = 0;
5766
5767 if (params) {
5768 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
5769 wpa_s->scan_res_handler = scan_only_handler;
5770
5771 pos = os_strstr(params, "freq=");
5772 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
5773 *reply_len = -1;
5774 return;
5775 }
5776
5777 pos = os_strstr(params, "passive=");
5778 if (pos)
5779 wpa_s->manual_scan_passive = !!atoi(pos + 8);
5780
5781 pos = os_strstr(params, "use_id=");
5782 if (pos)
5783 wpa_s->manual_scan_use_id = atoi(pos + 7);
5784
5785 pos = os_strstr(params, "only_new=1");
5786 if (pos)
5787 wpa_s->manual_scan_only_new = 1;
5788 } else {
5789 os_free(wpa_s->manual_scan_freqs);
5790 wpa_s->manual_scan_freqs = NULL;
5791 if (wpa_s->scan_res_handler == scan_only_handler)
5792 wpa_s->scan_res_handler = NULL;
5793 }
5794
5795 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
5796 ((wpa_s->wpa_state <= WPA_SCANNING) ||
5797 (wpa_s->wpa_state == WPA_COMPLETED))) {
5798 wpa_s->normal_scans = 0;
5799 wpa_s->scan_req = MANUAL_SCAN_REQ;
5800 wpa_s->after_wps = 0;
5801 wpa_s->known_wps_freq = 0;
5802 wpa_supplicant_req_scan(wpa_s, 0, 0);
5803 if (wpa_s->manual_scan_use_id) {
5804 wpa_s->manual_scan_id++;
5805 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5806 wpa_s->manual_scan_id);
5807 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5808 wpa_s->manual_scan_id);
5809 }
5810 } else if (wpa_s->sched_scanning) {
5811 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
5812 wpa_supplicant_cancel_sched_scan(wpa_s);
5813 wpa_s->scan_req = MANUAL_SCAN_REQ;
5814 wpa_supplicant_req_scan(wpa_s, 0, 0);
5815 if (wpa_s->manual_scan_use_id) {
5816 wpa_s->manual_scan_id++;
5817 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5818 wpa_s->manual_scan_id);
5819 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5820 wpa_s->manual_scan_id);
5821 }
5822 } else {
5823 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
5824 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
5825 }
5826}
5827
5828
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005829char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
5830 char *buf, size_t *resp_len)
5831{
5832 char *reply;
5833 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005834 int reply_len;
5835
5836 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005837 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
5838 if (wpa_debug_show_keys)
5839 wpa_dbg(wpa_s, MSG_DEBUG,
5840 "Control interface command '%s'", buf);
5841 else
5842 wpa_dbg(wpa_s, MSG_DEBUG,
5843 "Control interface command '%s [REMOVED]'",
5844 os_strncmp(buf, WPA_CTRL_RSP,
5845 os_strlen(WPA_CTRL_RSP)) == 0 ?
5846 WPA_CTRL_RSP : "SET_NETWORK");
5847 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
5848 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0 ||
5849 os_strncmp(buf, "NFC_RX_HANDOVER_SEL", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005850 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
5851 (const u8 *) buf, os_strlen(buf));
5852 } else {
5853 int level = MSG_DEBUG;
5854 if (os_strcmp(buf, "PING") == 0)
5855 level = MSG_EXCESSIVE;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005856 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005857 }
5858
5859 reply = os_malloc(reply_size);
5860 if (reply == NULL) {
5861 *resp_len = 1;
5862 return NULL;
5863 }
5864
5865 os_memcpy(reply, "OK\n", 3);
5866 reply_len = 3;
5867
5868 if (os_strcmp(buf, "PING") == 0) {
5869 os_memcpy(reply, "PONG\n", 5);
5870 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005871 } else if (os_strcmp(buf, "IFNAME") == 0) {
5872 reply_len = os_strlen(wpa_s->ifname);
5873 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005874 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
5875 if (wpa_debug_reopen_file() < 0)
5876 reply_len = -1;
5877 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
5878 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
5879 } else if (os_strcmp(buf, "MIB") == 0) {
5880 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
5881 if (reply_len >= 0) {
5882 int res;
5883 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
5884 reply_size - reply_len);
5885 if (res < 0)
5886 reply_len = -1;
5887 else
5888 reply_len += res;
5889 }
5890 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
5891 reply_len = wpa_supplicant_ctrl_iface_status(
5892 wpa_s, buf + 6, reply, reply_size);
5893 } else if (os_strcmp(buf, "PMKSA") == 0) {
5894 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
5895 reply_size);
5896 } else if (os_strncmp(buf, "SET ", 4) == 0) {
5897 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
5898 reply_len = -1;
5899 } else if (os_strncmp(buf, "GET ", 4) == 0) {
5900 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
5901 reply, reply_size);
5902 } else if (os_strcmp(buf, "LOGON") == 0) {
5903 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5904 } else if (os_strcmp(buf, "LOGOFF") == 0) {
5905 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
5906 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
5907 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5908 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005909 else
5910 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005911 } else if (os_strcmp(buf, "RECONNECT") == 0) {
5912 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5913 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005914 else if (wpa_s->disconnected)
5915 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005916#ifdef IEEE8021X_EAPOL
5917 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
5918 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
5919 reply_len = -1;
5920#endif /* IEEE8021X_EAPOL */
5921#ifdef CONFIG_PEERKEY
5922 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
5923 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
5924 reply_len = -1;
5925#endif /* CONFIG_PEERKEY */
5926#ifdef CONFIG_IEEE80211R
5927 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
5928 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
5929 reply_len = -1;
5930#endif /* CONFIG_IEEE80211R */
5931#ifdef CONFIG_WPS
5932 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
5933 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
5934 if (res == -2) {
5935 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5936 reply_len = 17;
5937 } else if (res)
5938 reply_len = -1;
5939 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
5940 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
5941 if (res == -2) {
5942 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5943 reply_len = 17;
5944 } else if (res)
5945 reply_len = -1;
5946 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
5947 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
5948 reply,
5949 reply_size);
5950 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
5951 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
5952 wpa_s, buf + 14, reply, reply_size);
5953 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
5954 if (wpas_wps_cancel(wpa_s))
5955 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005956#ifdef CONFIG_WPS_NFC
5957 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
5958 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
5959 reply_len = -1;
5960 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
5961 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
5962 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005963 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
5964 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
5965 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005966 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
5967 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
5968 wpa_s, buf + 14, reply, reply_size);
5969 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
5970 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
5971 buf + 17))
5972 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005973 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
5974 reply_len = wpas_ctrl_nfc_get_handover_req(
5975 wpa_s, buf + 21, reply, reply_size);
5976 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
5977 reply_len = wpas_ctrl_nfc_get_handover_sel(
5978 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005979 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
5980 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s, buf + 20))
5981 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005982 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
5983 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
5984 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005985#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005986 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
5987 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
5988 reply_len = -1;
5989#ifdef CONFIG_AP
5990 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
5991 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
5992 wpa_s, buf + 11, reply, reply_size);
5993#endif /* CONFIG_AP */
5994#ifdef CONFIG_WPS_ER
5995 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
5996 if (wpas_wps_er_start(wpa_s, NULL))
5997 reply_len = -1;
5998 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
5999 if (wpas_wps_er_start(wpa_s, buf + 13))
6000 reply_len = -1;
6001 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
6002 if (wpas_wps_er_stop(wpa_s))
6003 reply_len = -1;
6004 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
6005 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
6006 reply_len = -1;
6007 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
6008 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
6009 if (ret == -2) {
6010 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6011 reply_len = 17;
6012 } else if (ret == -3) {
6013 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
6014 reply_len = 18;
6015 } else if (ret == -4) {
6016 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
6017 reply_len = 20;
6018 } else if (ret)
6019 reply_len = -1;
6020 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
6021 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
6022 reply_len = -1;
6023 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
6024 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
6025 buf + 18))
6026 reply_len = -1;
6027 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
6028 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
6029 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006030#ifdef CONFIG_WPS_NFC
6031 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6032 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6033 wpa_s, buf + 24, reply, reply_size);
6034#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006035#endif /* CONFIG_WPS_ER */
6036#endif /* CONFIG_WPS */
6037#ifdef CONFIG_IBSS_RSN
6038 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
6039 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
6040 reply_len = -1;
6041#endif /* CONFIG_IBSS_RSN */
6042#ifdef CONFIG_P2P
6043 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
6044 if (p2p_ctrl_find(wpa_s, buf + 9))
6045 reply_len = -1;
6046 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
6047 if (p2p_ctrl_find(wpa_s, ""))
6048 reply_len = -1;
6049 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
6050 wpas_p2p_stop_find(wpa_s);
6051 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
6052 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
6053 reply_size);
6054 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
6055 if (p2p_ctrl_listen(wpa_s, buf + 11))
6056 reply_len = -1;
6057 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
6058 if (p2p_ctrl_listen(wpa_s, ""))
6059 reply_len = -1;
6060 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
6061 if (wpas_p2p_group_remove(wpa_s, buf + 17))
6062 reply_len = -1;
6063 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006064 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006065 reply_len = -1;
6066 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
6067 if (p2p_ctrl_group_add(wpa_s, buf + 14))
6068 reply_len = -1;
6069 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
6070 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
6071 reply_len = -1;
6072 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
6073 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
6074 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
6075 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6076 reply_size);
6077 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6078 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6079 reply_len = -1;
6080 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6081 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6082 reply_len = -1;
6083 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6084 wpas_p2p_sd_service_update(wpa_s);
6085 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6086 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6087 reply_len = -1;
6088 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6089 wpas_p2p_service_flush(wpa_s);
6090 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6091 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6092 reply_len = -1;
6093 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6094 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6095 reply_len = -1;
6096 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6097 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6098 reply_len = -1;
6099 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6100 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6101 reply_len = -1;
6102 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6103 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6104 reply_size);
6105 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6106 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6107 reply_len = -1;
6108 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006109 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006110 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6111 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6112 reply_len = -1;
6113 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6114 if (wpas_p2p_cancel(wpa_s))
6115 reply_len = -1;
6116 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6117 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6118 reply_len = -1;
6119 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6120 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6121 reply_len = -1;
6122 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6123 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6124 reply_len = -1;
6125 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6126 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6127 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07006128 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6129 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6130 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006131#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006132#ifdef CONFIG_WIFI_DISPLAY
6133 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6134 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
6135 reply_len = -1;
6136 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
6137 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
6138 reply, reply_size);
6139#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006140#ifdef CONFIG_INTERWORKING
6141 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
6142 if (interworking_fetch_anqp(wpa_s) < 0)
6143 reply_len = -1;
6144 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
6145 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006146 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
6147 if (ctrl_interworking_select(wpa_s, NULL) < 0)
6148 reply_len = -1;
6149 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
6150 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006151 reply_len = -1;
6152 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
6153 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
6154 reply_len = -1;
6155 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
6156 if (get_anqp(wpa_s, buf + 9) < 0)
6157 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006158 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
6159 if (gas_request(wpa_s, buf + 12) < 0)
6160 reply_len = -1;
6161 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
6162 reply_len = gas_response_get(wpa_s, buf + 17, reply,
6163 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006164#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -07006165#ifdef CONFIG_HS20
6166 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
6167 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
6168 reply_len = -1;
6169 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6170 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
6171 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08006172 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
6173 if (hs20_icon_request(wpa_s, buf + 18) < 0)
6174 reply_len = -1;
6175 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
6176 if (hs20_fetch_osu(wpa_s) < 0)
6177 reply_len = -1;
6178 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
6179 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006180#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006181 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
6182 {
6183 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6184 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
6185 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07006186 else {
6187 /*
6188 * Notify response from timeout to allow the control
6189 * interface response to be sent first.
6190 */
6191 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
6192 wpa_s, NULL);
6193 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006194 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
6195 if (wpa_supplicant_reload_configuration(wpa_s))
6196 reply_len = -1;
6197 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6198 wpa_supplicant_terminate_proc(wpa_s->global);
6199 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
6200 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
6201 reply_len = -1;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07006202 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006203 reply_len = wpa_supplicant_ctrl_iface_blacklist(
6204 wpa_s, buf + 9, reply, reply_size);
6205 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
6206 reply_len = wpa_supplicant_ctrl_iface_log_level(
6207 wpa_s, buf + 9, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006208 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
6209 reply_len = wpa_supplicant_ctrl_iface_list_networks(
6210 wpa_s, reply, reply_size);
6211 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07006212#ifdef CONFIG_SME
6213 wpa_s->sme.prev_bssid_set = 0;
6214#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006215 wpa_s->reassociate = 0;
6216 wpa_s->disconnected = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006217 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006218 wpa_supplicant_cancel_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006219 wpa_supplicant_deauthenticate(wpa_s,
6220 WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006221 } else if (os_strcmp(buf, "SCAN") == 0) {
6222 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
6223 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
6224 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006225 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
6226 reply_len = wpa_supplicant_ctrl_iface_scan_results(
6227 wpa_s, reply, reply_size);
6228 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
6229 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
6230 reply_len = -1;
6231 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
6232 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
6233 reply_len = -1;
6234 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
6235 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
6236 reply_len = -1;
6237 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
6238 reply_len = wpa_supplicant_ctrl_iface_add_network(
6239 wpa_s, reply, reply_size);
6240 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
6241 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
6242 reply_len = -1;
6243 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6244 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
6245 reply_len = -1;
6246 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
6247 reply_len = wpa_supplicant_ctrl_iface_get_network(
6248 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006249 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
6250 reply_len = wpa_supplicant_ctrl_iface_list_creds(
6251 wpa_s, reply, reply_size);
6252 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
6253 reply_len = wpa_supplicant_ctrl_iface_add_cred(
6254 wpa_s, reply, reply_size);
6255 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
6256 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
6257 reply_len = -1;
6258 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
6259 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
6260 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006261#ifndef CONFIG_NO_CONFIG_WRITE
6262 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6263 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
6264 reply_len = -1;
6265#endif /* CONFIG_NO_CONFIG_WRITE */
6266 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
6267 reply_len = wpa_supplicant_ctrl_iface_get_capability(
6268 wpa_s, buf + 15, reply, reply_size);
6269 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
6270 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
6271 reply_len = -1;
6272 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
6273 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
6274 reply_len = -1;
6275 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6276 reply_len = wpa_supplicant_global_iface_list(
6277 wpa_s->global, reply, reply_size);
6278 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6279 reply_len = wpa_supplicant_global_iface_interfaces(
6280 wpa_s->global, reply, reply_size);
6281 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
6282 reply_len = wpa_supplicant_ctrl_iface_bss(
6283 wpa_s, buf + 4, reply, reply_size);
6284#ifdef CONFIG_AP
6285 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
6286 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
6287 } else if (os_strncmp(buf, "STA ", 4) == 0) {
6288 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
6289 reply_size);
6290 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
6291 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
6292 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006293 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
6294 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
6295 reply_len = -1;
6296 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
6297 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
6298 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08006299 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
6300 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
6301 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006302#endif /* CONFIG_AP */
6303 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6304 wpas_notify_suspend(wpa_s->global);
6305 } else if (os_strcmp(buf, "RESUME") == 0) {
6306 wpas_notify_resume(wpa_s->global);
6307 } else if (os_strcmp(buf, "DROP_SA") == 0) {
6308 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
6309 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
6310 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
6311 reply_len = -1;
6312 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
6313 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
6314 reply_len = -1;
6315 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
6316 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
6317 reply_len = -1;
6318 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
6319 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
6320 buf + 17))
6321 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07006322 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
6323 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
6324 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006325#ifdef CONFIG_TDLS
6326 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
6327 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
6328 reply_len = -1;
6329 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
6330 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
6331 reply_len = -1;
6332 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
6333 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
6334 reply_len = -1;
6335#endif /* CONFIG_TDLS */
6336 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
6337 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
6338 reply_size);
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07006339 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
6340 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
6341 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006342#ifdef CONFIG_AUTOSCAN
6343 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
6344 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
6345 reply_len = -1;
6346#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006347#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07006348 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
6349 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
6350 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08006351#endif /* ANDROID */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006352 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006353 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006354 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006355#ifdef CONFIG_WNM
6356 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
6357 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
6358 reply_len = -1;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07006359 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
6360 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
6361 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006362#endif /* CONFIG_WNM */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006363 } else if (os_strcmp(buf, "FLUSH") == 0) {
6364 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006365 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
6366 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
6367 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006368 } else {
6369 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6370 reply_len = 16;
6371 }
6372
6373 if (reply_len < 0) {
6374 os_memcpy(reply, "FAIL\n", 5);
6375 reply_len = 5;
6376 }
6377
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006378 *resp_len = reply_len;
6379 return reply;
6380}
6381
6382
6383static int wpa_supplicant_global_iface_add(struct wpa_global *global,
6384 char *cmd)
6385{
6386 struct wpa_interface iface;
6387 char *pos;
6388
6389 /*
6390 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6391 * TAB<bridge_ifname>
6392 */
6393 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
6394
6395 os_memset(&iface, 0, sizeof(iface));
6396
6397 do {
6398 iface.ifname = pos = cmd;
6399 pos = os_strchr(pos, '\t');
6400 if (pos)
6401 *pos++ = '\0';
6402 if (iface.ifname[0] == '\0')
6403 return -1;
6404 if (pos == NULL)
6405 break;
6406
6407 iface.confname = pos;
6408 pos = os_strchr(pos, '\t');
6409 if (pos)
6410 *pos++ = '\0';
6411 if (iface.confname[0] == '\0')
6412 iface.confname = NULL;
6413 if (pos == NULL)
6414 break;
6415
6416 iface.driver = pos;
6417 pos = os_strchr(pos, '\t');
6418 if (pos)
6419 *pos++ = '\0';
6420 if (iface.driver[0] == '\0')
6421 iface.driver = NULL;
6422 if (pos == NULL)
6423 break;
6424
6425 iface.ctrl_interface = pos;
6426 pos = os_strchr(pos, '\t');
6427 if (pos)
6428 *pos++ = '\0';
6429 if (iface.ctrl_interface[0] == '\0')
6430 iface.ctrl_interface = NULL;
6431 if (pos == NULL)
6432 break;
6433
6434 iface.driver_param = pos;
6435 pos = os_strchr(pos, '\t');
6436 if (pos)
6437 *pos++ = '\0';
6438 if (iface.driver_param[0] == '\0')
6439 iface.driver_param = NULL;
6440 if (pos == NULL)
6441 break;
6442
6443 iface.bridge_ifname = pos;
6444 pos = os_strchr(pos, '\t');
6445 if (pos)
6446 *pos++ = '\0';
6447 if (iface.bridge_ifname[0] == '\0')
6448 iface.bridge_ifname = NULL;
6449 if (pos == NULL)
6450 break;
6451 } while (0);
6452
6453 if (wpa_supplicant_get_iface(global, iface.ifname))
6454 return -1;
6455
6456 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
6457}
6458
6459
6460static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
6461 char *cmd)
6462{
6463 struct wpa_supplicant *wpa_s;
6464
6465 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
6466
6467 wpa_s = wpa_supplicant_get_iface(global, cmd);
6468 if (wpa_s == NULL)
6469 return -1;
Dmitry Shmidte15c7b52011-08-03 15:04:35 -07006470 return wpa_supplicant_remove_iface(global, wpa_s, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006471}
6472
6473
6474static void wpa_free_iface_info(struct wpa_interface_info *iface)
6475{
6476 struct wpa_interface_info *prev;
6477
6478 while (iface) {
6479 prev = iface;
6480 iface = iface->next;
6481
6482 os_free(prev->ifname);
6483 os_free(prev->desc);
6484 os_free(prev);
6485 }
6486}
6487
6488
6489static int wpa_supplicant_global_iface_list(struct wpa_global *global,
6490 char *buf, int len)
6491{
6492 int i, res;
6493 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
6494 char *pos, *end;
6495
6496 for (i = 0; wpa_drivers[i]; i++) {
6497 struct wpa_driver_ops *drv = wpa_drivers[i];
6498 if (drv->get_interfaces == NULL)
6499 continue;
6500 tmp = drv->get_interfaces(global->drv_priv[i]);
6501 if (tmp == NULL)
6502 continue;
6503
6504 if (last == NULL)
6505 iface = last = tmp;
6506 else
6507 last->next = tmp;
6508 while (last->next)
6509 last = last->next;
6510 }
6511
6512 pos = buf;
6513 end = buf + len;
6514 for (tmp = iface; tmp; tmp = tmp->next) {
6515 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
6516 tmp->drv_name, tmp->ifname,
6517 tmp->desc ? tmp->desc : "");
6518 if (res < 0 || res >= end - pos) {
6519 *pos = '\0';
6520 break;
6521 }
6522 pos += res;
6523 }
6524
6525 wpa_free_iface_info(iface);
6526
6527 return pos - buf;
6528}
6529
6530
6531static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
6532 char *buf, int len)
6533{
6534 int res;
6535 char *pos, *end;
6536 struct wpa_supplicant *wpa_s;
6537
6538 wpa_s = global->ifaces;
6539 pos = buf;
6540 end = buf + len;
6541
6542 while (wpa_s) {
6543 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
6544 if (res < 0 || res >= end - pos) {
6545 *pos = '\0';
6546 break;
6547 }
6548 pos += res;
6549 wpa_s = wpa_s->next;
6550 }
6551 return pos - buf;
6552}
6553
6554
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07006555static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
6556 const char *ifname,
6557 char *cmd, size_t *resp_len)
6558{
6559 struct wpa_supplicant *wpa_s;
6560
6561 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6562 if (os_strcmp(ifname, wpa_s->ifname) == 0)
6563 break;
6564 }
6565
6566 if (wpa_s == NULL) {
6567 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
6568 if (resp)
6569 *resp_len = os_strlen(resp);
6570 else
6571 *resp_len = 1;
6572 return resp;
6573 }
6574
6575 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
6576}
6577
6578
6579static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
6580 char *buf, size_t *resp_len)
6581{
6582#ifdef CONFIG_P2P
6583 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -07006584 "LIST_NETWORKS",
6585 "SAVE_CONFIG",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07006586 "P2P_FIND",
6587 "P2P_STOP_FIND",
6588 "P2P_LISTEN",
6589 "P2P_GROUP_ADD",
6590 "P2P_GET_PASSPHRASE",
6591 "P2P_SERVICE_UPDATE",
6592 "P2P_SERVICE_FLUSH",
6593 "P2P_FLUSH",
6594 "P2P_CANCEL",
6595 "P2P_PRESENCE_REQ",
6596 "P2P_EXT_LISTEN",
6597 NULL
6598 };
6599 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -08006600#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -07006601 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -08006602#endif /* ANDROID */
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -07006603 "GET_NETWORK ",
6604 "REMOVE_NETWORK ",
6605 "SET ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07006606 "P2P_FIND ",
6607 "P2P_CONNECT ",
6608 "P2P_LISTEN ",
6609 "P2P_GROUP_REMOVE ",
6610 "P2P_GROUP_ADD ",
6611 "P2P_PROV_DISC ",
6612 "P2P_SERV_DISC_REQ ",
6613 "P2P_SERV_DISC_CANCEL_REQ ",
6614 "P2P_SERV_DISC_RESP ",
6615 "P2P_SERV_DISC_EXTERNAL ",
6616 "P2P_SERVICE_ADD ",
6617 "P2P_SERVICE_DEL ",
6618 "P2P_REJECT ",
6619 "P2P_INVITE ",
6620 "P2P_PEER ",
6621 "P2P_SET ",
6622 "P2P_UNAUTHORIZE ",
6623 "P2P_PRESENCE_REQ ",
6624 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07006625 "P2P_REMOVE_CLIENT ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07006626 NULL
6627 };
6628 int found = 0;
6629 int i;
6630
6631 if (global->p2p_init_wpa_s == NULL)
6632 return NULL;
6633
6634 for (i = 0; !found && cmd[i]; i++) {
6635 if (os_strcmp(buf, cmd[i]) == 0)
6636 found = 1;
6637 }
6638
6639 for (i = 0; !found && prefix[i]; i++) {
6640 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
6641 found = 1;
6642 }
6643
6644 if (found)
6645 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6646 buf, resp_len);
6647#endif /* CONFIG_P2P */
6648 return NULL;
6649}
6650
6651
6652static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
6653 char *buf, size_t *resp_len)
6654{
6655#ifdef CONFIG_WIFI_DISPLAY
6656 if (global->p2p_init_wpa_s == NULL)
6657 return NULL;
6658 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
6659 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
6660 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6661 buf, resp_len);
6662#endif /* CONFIG_WIFI_DISPLAY */
6663 return NULL;
6664}
6665
6666
6667static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
6668 char *buf, size_t *resp_len)
6669{
6670 char *ret;
6671
6672 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
6673 if (ret)
6674 return ret;
6675
6676 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
6677 if (ret)
6678 return ret;
6679
6680 return NULL;
6681}
6682
6683
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006684static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
6685{
6686 char *value;
6687
6688 value = os_strchr(cmd, ' ');
6689 if (value == NULL)
6690 return -1;
6691 *value++ = '\0';
6692
6693 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
6694
6695#ifdef CONFIG_WIFI_DISPLAY
6696 if (os_strcasecmp(cmd, "wifi_display") == 0) {
6697 wifi_display_enable(global, !!atoi(value));
6698 return 0;
6699 }
6700#endif /* CONFIG_WIFI_DISPLAY */
6701
6702 return -1;
6703}
6704
6705
6706#ifndef CONFIG_NO_CONFIG_WRITE
6707static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
6708{
6709 int ret = 0;
6710 struct wpa_supplicant *wpa_s;
6711
6712 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6713 if (!wpa_s->conf->update_config) {
6714 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6715 continue;
6716 }
6717
6718 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
6719 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6720 ret = 1;
6721 } else {
6722 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6723 }
6724 }
6725
6726 return ret;
6727}
6728#endif /* CONFIG_NO_CONFIG_WRITE */
6729
6730
6731static int wpas_global_ctrl_iface_status(struct wpa_global *global,
6732 char *buf, size_t buflen)
6733{
6734 char *pos, *end;
6735 int ret;
6736 struct wpa_supplicant *wpa_s;
6737
6738 pos = buf;
6739 end = buf + buflen;
6740
6741#ifdef CONFIG_P2P
6742 if (global->p2p && !global->p2p_disabled) {
6743 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
6744 "\n"
6745 "p2p_state=%s\n",
6746 MAC2STR(global->p2p_dev_addr),
6747 p2p_get_state_txt(global->p2p));
6748 if (ret < 0 || ret >= end - pos)
6749 return pos - buf;
6750 pos += ret;
6751 } else if (global->p2p) {
6752 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
6753 if (ret < 0 || ret >= end - pos)
6754 return pos - buf;
6755 pos += ret;
6756 }
6757#endif /* CONFIG_P2P */
6758
6759#ifdef CONFIG_WIFI_DISPLAY
6760 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
6761 !!global->wifi_display);
6762 if (ret < 0 || ret >= end - pos)
6763 return pos - buf;
6764 pos += ret;
6765#endif /* CONFIG_WIFI_DISPLAY */
6766
6767 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6768 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
6769 "address=" MACSTR "\n",
6770 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
6771 if (ret < 0 || ret >= end - pos)
6772 return pos - buf;
6773 pos += ret;
6774 }
6775
6776 return pos - buf;
6777}
6778
6779
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006780char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
6781 char *buf, size_t *resp_len)
6782{
6783 char *reply;
6784 const int reply_size = 2048;
6785 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006786 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006787
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07006788 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
6789 char *pos = os_strchr(buf + 7, ' ');
6790 if (pos) {
6791 *pos++ = '\0';
6792 return wpas_global_ctrl_iface_ifname(global,
6793 buf + 7, pos,
6794 resp_len);
6795 }
6796 }
6797
6798 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
6799 if (reply)
6800 return reply;
6801
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006802 if (os_strcmp(buf, "PING") == 0)
6803 level = MSG_EXCESSIVE;
6804 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006805 (const u8 *) buf, os_strlen(buf));
6806
6807 reply = os_malloc(reply_size);
6808 if (reply == NULL) {
6809 *resp_len = 1;
6810 return NULL;
6811 }
6812
6813 os_memcpy(reply, "OK\n", 3);
6814 reply_len = 3;
6815
6816 if (os_strcmp(buf, "PING") == 0) {
6817 os_memcpy(reply, "PONG\n", 5);
6818 reply_len = 5;
6819 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
6820 if (wpa_supplicant_global_iface_add(global, buf + 14))
6821 reply_len = -1;
6822 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
6823 if (wpa_supplicant_global_iface_remove(global, buf + 17))
6824 reply_len = -1;
6825 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6826 reply_len = wpa_supplicant_global_iface_list(
6827 global, reply, reply_size);
6828 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6829 reply_len = wpa_supplicant_global_iface_interfaces(
6830 global, reply, reply_size);
6831 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6832 wpa_supplicant_terminate_proc(global);
6833 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6834 wpas_notify_suspend(global);
6835 } else if (os_strcmp(buf, "RESUME") == 0) {
6836 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006837 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6838 if (wpas_global_ctrl_iface_set(global, buf + 4))
6839 reply_len = -1;
6840#ifndef CONFIG_NO_CONFIG_WRITE
6841 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6842 if (wpas_global_ctrl_iface_save_config(global))
6843 reply_len = -1;
6844#endif /* CONFIG_NO_CONFIG_WRITE */
6845 } else if (os_strcmp(buf, "STATUS") == 0) {
6846 reply_len = wpas_global_ctrl_iface_status(global, reply,
6847 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -08006848#ifdef CONFIG_MODULE_TESTS
6849 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
6850 int wpas_module_tests(void);
6851 if (wpas_module_tests() < 0)
6852 reply_len = -1;
6853#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006854 } else {
6855 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6856 reply_len = 16;
6857 }
6858
6859 if (reply_len < 0) {
6860 os_memcpy(reply, "FAIL\n", 5);
6861 reply_len = 5;
6862 }
6863
6864 *resp_len = reply_len;
6865 return reply;
6866}