blob: d3c87da2c2da4d301336c35ce5fc14ecea7dd020 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant / Control interface (shared code for all backends)
Dmitry Shmidt04949592012-07-19 12:16:46 -07003 * Copyright (c) 2004-2012, 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"
13#include "common/version.h"
14#include "common/ieee802_11_defs.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070015#include "common/ieee802_11_common.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070016#include "common/wpa_ctrl.h"
17#include "eap_peer/eap.h"
18#include "eapol_supp/eapol_supp_sm.h"
19#include "rsn_supp/wpa.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "l2_packet/l2_packet.h"
23#include "wps/wps.h"
24#include "config.h"
25#include "wpa_supplicant_i.h"
26#include "driver_i.h"
27#include "wps_supplicant.h"
28#include "ibss_rsn.h"
29#include "ap.h"
30#include "p2p_supplicant.h"
31#include "p2p/p2p.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070032#include "hs20_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070033#include "wifi_display.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034#include "notify.h"
35#include "bss.h"
36#include "scan.h"
37#include "ctrl_iface.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080038#include "interworking.h"
Dmitry Shmidte19501d2011-03-16 14:32:18 -070039#include "blacklist.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070040#include "autoscan.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080041#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042
43extern struct wpa_driver_ops *wpa_drivers[];
44
45static int wpa_supplicant_global_iface_list(struct wpa_global *global,
46 char *buf, int len);
47static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
48 char *buf, int len);
49
50
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080051static int pno_start(struct wpa_supplicant *wpa_s)
52{
53 int ret;
54 size_t i, num_ssid;
55 struct wpa_ssid *ssid;
56 struct wpa_driver_scan_params params;
57
58 if (wpa_s->pno)
59 return 0;
60
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080061 if (wpa_s->wpa_state == WPA_SCANNING) {
62 wpa_supplicant_cancel_sched_scan(wpa_s);
63 wpa_supplicant_cancel_scan(wpa_s);
64 }
65
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080066 os_memset(&params, 0, sizeof(params));
67
68 num_ssid = 0;
69 ssid = wpa_s->conf->ssid;
70 while (ssid) {
Dmitry Shmidt04949592012-07-19 12:16:46 -070071 if (!wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080072 num_ssid++;
73 ssid = ssid->next;
74 }
75 if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
76 wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
77 "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
78 num_ssid = WPAS_MAX_SCAN_SSIDS;
79 }
80
81 if (num_ssid == 0) {
82 wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
83 return -1;
84 }
85
86 params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
87 num_ssid);
88 if (params.filter_ssids == NULL)
89 return -1;
90 i = 0;
91 ssid = wpa_s->conf->ssid;
92 while (ssid) {
Dmitry Shmidt04949592012-07-19 12:16:46 -070093 if (!wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080094 params.ssids[i].ssid = ssid->ssid;
95 params.ssids[i].ssid_len = ssid->ssid_len;
96 params.num_ssids++;
97 os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
98 ssid->ssid_len);
99 params.filter_ssids[i].ssid_len = ssid->ssid_len;
100 params.num_filter_ssids++;
101 i++;
102 if (i == num_ssid)
103 break;
104 }
105 ssid = ssid->next;
106 }
107
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700108 if (wpa_s->conf->filter_rssi)
109 params.filter_rssi = wpa_s->conf->filter_rssi;
110
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800111 ret = wpa_drv_sched_scan(wpa_s, &params, 10 * 1000);
112 os_free(params.filter_ssids);
113 if (ret == 0)
114 wpa_s->pno = 1;
115 return ret;
116}
117
118
119static int pno_stop(struct wpa_supplicant *wpa_s)
120{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800121 int ret = 0;
122
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800123 if (wpa_s->pno) {
124 wpa_s->pno = 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800125 ret = wpa_drv_stop_sched_scan(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800126 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800127
128 if (wpa_s->wpa_state == WPA_SCANNING)
129 wpa_supplicant_req_scan(wpa_s, 0, 0);
130
131 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800132}
133
134
Dmitry Shmidt04949592012-07-19 12:16:46 -0700135static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
136{
137 char *pos;
138 u8 addr[ETH_ALEN], *filter = NULL, *n;
139 size_t count = 0;
140
141 pos = val;
142 while (pos) {
143 if (*pos == '\0')
144 break;
145 if (hwaddr_aton(pos, addr)) {
146 os_free(filter);
147 return -1;
148 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700149 n = os_realloc_array(filter, count + 1, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700150 if (n == NULL) {
151 os_free(filter);
152 return -1;
153 }
154 filter = n;
155 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
156 count++;
157
158 pos = os_strchr(pos, ' ');
159 if (pos)
160 pos++;
161 }
162
163 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
164 os_free(wpa_s->bssid_filter);
165 wpa_s->bssid_filter = filter;
166 wpa_s->bssid_filter_count = count;
167
168 return 0;
169}
170
171
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800172static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
173{
174 char *pos;
175 u8 addr[ETH_ALEN], *bssid = NULL, *n;
176 struct wpa_ssid_value *ssid = NULL, *ns;
177 size_t count = 0, ssid_count = 0;
178 struct wpa_ssid *c;
179
180 /*
181 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | “”
182 * SSID_SPEC ::= ssid <SSID_HEX>
183 * BSSID_SPEC ::= bssid <BSSID_HEX>
184 */
185
186 pos = val;
187 while (pos) {
188 if (*pos == '\0')
189 break;
190 if (os_strncmp(pos, "bssid ", 6) == 0) {
191 int res;
192 pos += 6;
193 res = hwaddr_aton2(pos, addr);
194 if (res < 0) {
195 os_free(ssid);
196 os_free(bssid);
197 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
198 "BSSID value '%s'", pos);
199 return -1;
200 }
201 pos += res;
202 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
203 if (n == NULL) {
204 os_free(ssid);
205 os_free(bssid);
206 return -1;
207 }
208 bssid = n;
209 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
210 count++;
211 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
212 char *end;
213 pos += 5;
214
215 end = pos;
216 while (*end) {
217 if (*end == '\0' || *end == ' ')
218 break;
219 end++;
220 }
221
222 ns = os_realloc_array(ssid, ssid_count + 1,
223 sizeof(struct wpa_ssid_value));
224 if (ns == NULL) {
225 os_free(ssid);
226 os_free(bssid);
227 return -1;
228 }
229 ssid = ns;
230
231 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
232 hexstr2bin(pos, ssid[ssid_count].ssid,
233 (end - pos) / 2) < 0) {
234 os_free(ssid);
235 os_free(bssid);
236 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
237 "SSID value '%s'", pos);
238 return -1;
239 }
240 ssid[ssid_count].ssid_len = (end - pos) / 2;
241 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
242 ssid[ssid_count].ssid,
243 ssid[ssid_count].ssid_len);
244 ssid_count++;
245 pos = end;
246 } else {
247 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
248 "'%s'", pos);
249 os_free(ssid);
250 os_free(bssid);
251 return -1;
252 }
253
254 pos = os_strchr(pos, ' ');
255 if (pos)
256 pos++;
257 }
258
259 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
260 os_free(wpa_s->disallow_aps_bssid);
261 wpa_s->disallow_aps_bssid = bssid;
262 wpa_s->disallow_aps_bssid_count = count;
263
264 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
265 os_free(wpa_s->disallow_aps_ssid);
266 wpa_s->disallow_aps_ssid = ssid;
267 wpa_s->disallow_aps_ssid_count = ssid_count;
268
269 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
270 return 0;
271
272 c = wpa_s->current_ssid;
273 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
274 return 0;
275
276 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
277 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
278 return 0;
279
280 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
281 "because current AP was marked disallowed");
282
283#ifdef CONFIG_SME
284 wpa_s->sme.prev_bssid_set = 0;
285#endif /* CONFIG_SME */
286 wpa_s->reassociate = 1;
287 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
288 wpa_supplicant_req_scan(wpa_s, 0, 0);
289
290 return 0;
291}
292
293
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
295 char *cmd)
296{
297 char *value;
298 int ret = 0;
299
300 value = os_strchr(cmd, ' ');
301 if (value == NULL)
302 return -1;
303 *value++ = '\0';
304
305 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
306 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
307 eapol_sm_configure(wpa_s->eapol,
308 atoi(value), -1, -1, -1);
309 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
310 eapol_sm_configure(wpa_s->eapol,
311 -1, atoi(value), -1, -1);
312 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
313 eapol_sm_configure(wpa_s->eapol,
314 -1, -1, atoi(value), -1);
315 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
316 eapol_sm_configure(wpa_s->eapol,
317 -1, -1, -1, atoi(value));
318 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
319 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
320 atoi(value)))
321 ret = -1;
322 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
323 0) {
324 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
325 atoi(value)))
326 ret = -1;
327 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
328 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
329 ret = -1;
330 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
331 wpa_s->wps_fragment_size = atoi(value);
332#ifdef CONFIG_WPS_TESTING
333 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
334 long int val;
335 val = strtol(value, NULL, 0);
336 if (val < 0 || val > 0xff) {
337 ret = -1;
338 wpa_printf(MSG_DEBUG, "WPS: Invalid "
339 "wps_version_number %ld", val);
340 } else {
341 wps_version_number = val;
342 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
343 "version %u.%u",
344 (wps_version_number & 0xf0) >> 4,
345 wps_version_number & 0x0f);
346 }
347 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
348 wps_testing_dummy_cred = atoi(value);
349 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
350 wps_testing_dummy_cred);
351#endif /* CONFIG_WPS_TESTING */
352 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
353 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
354 ret = -1;
355#ifdef CONFIG_TDLS_TESTING
356 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
357 extern unsigned int tdls_testing;
358 tdls_testing = strtol(value, NULL, 0);
359 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
360#endif /* CONFIG_TDLS_TESTING */
361#ifdef CONFIG_TDLS
362 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
363 int disabled = atoi(value);
364 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
365 if (disabled) {
366 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
367 ret = -1;
368 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
369 ret = -1;
370 wpa_tdls_enable(wpa_s->wpa, !disabled);
371#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800372 } else if (os_strcasecmp(cmd, "pno") == 0) {
373 if (atoi(value))
374 ret = pno_start(wpa_s);
375 else
376 ret = pno_stop(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700377 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
378 int disabled = atoi(value);
379 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
380 ret = -1;
381 else if (disabled)
382 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
383 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
384 if (os_strcmp(value, "disable") == 0)
385 wpa_s->set_sta_uapsd = 0;
386 else {
387 int be, bk, vi, vo;
388 char *pos;
389 /* format: BE,BK,VI,VO;max SP Length */
390 be = atoi(value);
391 pos = os_strchr(value, ',');
392 if (pos == NULL)
393 return -1;
394 pos++;
395 bk = atoi(pos);
396 pos = os_strchr(pos, ',');
397 if (pos == NULL)
398 return -1;
399 pos++;
400 vi = atoi(pos);
401 pos = os_strchr(pos, ',');
402 if (pos == NULL)
403 return -1;
404 pos++;
405 vo = atoi(pos);
406 /* ignore max SP Length for now */
407
408 wpa_s->set_sta_uapsd = 1;
409 wpa_s->sta_uapsd = 0;
410 if (be)
411 wpa_s->sta_uapsd |= BIT(0);
412 if (bk)
413 wpa_s->sta_uapsd |= BIT(1);
414 if (vi)
415 wpa_s->sta_uapsd |= BIT(2);
416 if (vo)
417 wpa_s->sta_uapsd |= BIT(3);
418 }
Jouni Malinen21d6bc82012-04-10 16:17:59 -0700419 } else if (os_strcasecmp(cmd, "ps") == 0) {
420 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700421#ifdef CONFIG_WIFI_DISPLAY
422 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
423 wifi_display_enable(wpa_s->global, !!atoi(value));
424#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700425 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
426 ret = set_bssid_filter(wpa_s, value);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800427 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
428 ret = set_disallow_aps(wpa_s, value);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800429 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
430 wpa_s->no_keep_alive = !!atoi(value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431 } else {
432 value[-1] = '=';
433 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
434 if (ret == 0)
435 wpa_supplicant_update_config(wpa_s);
436 }
437
438 return ret;
439}
440
441
442static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
443 char *cmd, char *buf, size_t buflen)
444{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700445 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446
447 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
448
449 if (os_strcmp(cmd, "version") == 0) {
450 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700451 } else if (os_strcasecmp(cmd, "country") == 0) {
452 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
453 res = os_snprintf(buf, buflen, "%c%c",
454 wpa_s->conf->country[0],
455 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700456#ifdef CONFIG_WIFI_DISPLAY
457 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
458 res = os_snprintf(buf, buflen, "%d",
459 wpa_s->global->wifi_display);
460 if (res < 0 || (unsigned int) res >= buflen)
461 return -1;
462 return res;
463#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700464 }
465
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700466 if (res < 0 || (unsigned int) res >= buflen)
467 return -1;
468 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700469}
470
471
472#ifdef IEEE8021X_EAPOL
473static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
474 char *addr)
475{
476 u8 bssid[ETH_ALEN];
477 struct wpa_ssid *ssid = wpa_s->current_ssid;
478
479 if (hwaddr_aton(addr, bssid)) {
480 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
481 "'%s'", addr);
482 return -1;
483 }
484
485 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
486 rsn_preauth_deinit(wpa_s->wpa);
487 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
488 return -1;
489
490 return 0;
491}
492#endif /* IEEE8021X_EAPOL */
493
494
495#ifdef CONFIG_PEERKEY
496/* MLME-STKSTART.request(peer) */
497static int wpa_supplicant_ctrl_iface_stkstart(
498 struct wpa_supplicant *wpa_s, char *addr)
499{
500 u8 peer[ETH_ALEN];
501
502 if (hwaddr_aton(addr, peer)) {
503 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
504 "address '%s'", addr);
505 return -1;
506 }
507
508 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
509 MAC2STR(peer));
510
511 return wpa_sm_stkstart(wpa_s->wpa, peer);
512}
513#endif /* CONFIG_PEERKEY */
514
515
516#ifdef CONFIG_TDLS
517
518static int wpa_supplicant_ctrl_iface_tdls_discover(
519 struct wpa_supplicant *wpa_s, char *addr)
520{
521 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800522 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700523
524 if (hwaddr_aton(addr, peer)) {
525 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
526 "address '%s'", addr);
527 return -1;
528 }
529
530 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
531 MAC2STR(peer));
532
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800533 if (wpa_tdls_is_external_setup(wpa_s->wpa))
534 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
535 else
536 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
537
538 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700539}
540
541
542static int wpa_supplicant_ctrl_iface_tdls_setup(
543 struct wpa_supplicant *wpa_s, char *addr)
544{
545 u8 peer[ETH_ALEN];
546 int ret;
547
548 if (hwaddr_aton(addr, peer)) {
549 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
550 "address '%s'", addr);
551 return -1;
552 }
553
554 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
555 MAC2STR(peer));
556
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800557 wpa_tdls_remove(wpa_s->wpa, peer);
558
559 if (wpa_tdls_is_external_setup(wpa_s->wpa))
560 ret = wpa_tdls_start(wpa_s->wpa, peer);
561 else
562 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800563
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564 return ret;
565}
566
567
568static int wpa_supplicant_ctrl_iface_tdls_teardown(
569 struct wpa_supplicant *wpa_s, char *addr)
570{
571 u8 peer[ETH_ALEN];
572
573 if (hwaddr_aton(addr, peer)) {
574 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
575 "address '%s'", addr);
576 return -1;
577 }
578
579 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
580 MAC2STR(peer));
581
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800582 return wpa_tdls_teardown_link(wpa_s->wpa, peer,
583 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584}
585
586#endif /* CONFIG_TDLS */
587
588
589#ifdef CONFIG_IEEE80211R
590static int wpa_supplicant_ctrl_iface_ft_ds(
591 struct wpa_supplicant *wpa_s, char *addr)
592{
593 u8 target_ap[ETH_ALEN];
594 struct wpa_bss *bss;
595 const u8 *mdie;
596
597 if (hwaddr_aton(addr, target_ap)) {
598 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
599 "address '%s'", addr);
600 return -1;
601 }
602
603 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
604
605 bss = wpa_bss_get_bssid(wpa_s, target_ap);
606 if (bss)
607 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
608 else
609 mdie = NULL;
610
611 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
612}
613#endif /* CONFIG_IEEE80211R */
614
615
616#ifdef CONFIG_WPS
617static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
618 char *cmd)
619{
620 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -0700621#ifdef CONFIG_P2P
622 u8 p2p_dev_addr[ETH_ALEN];
623#endif /* CONFIG_P2P */
624#ifdef CONFIG_AP
625 u8 *_p2p_dev_addr = NULL;
626#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800627
Irfan Sheriffa7534b92012-09-06 18:30:39 -0700628 if (cmd == NULL || os_strcmp(cmd, "any") == 0 || cmd[0] == '\0') {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700629 _bssid = NULL;
630#ifdef CONFIG_P2P
631 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
632 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
633 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
634 "P2P Device Address '%s'",
635 cmd + 13);
636 return -1;
637 }
638 _p2p_dev_addr = p2p_dev_addr;
639#endif /* CONFIG_P2P */
640 } else if (hwaddr_aton(cmd, bssid)) {
641 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
642 cmd);
643 return -1;
644 }
645
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800646#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700647 if (wpa_s->ap_iface)
648 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
649#endif /* CONFIG_AP */
650
651 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
652}
653
654
655static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
656 char *cmd, char *buf,
657 size_t buflen)
658{
659 u8 bssid[ETH_ALEN], *_bssid = bssid;
660 char *pin;
661 int ret;
662
663 pin = os_strchr(cmd, ' ');
664 if (pin)
665 *pin++ = '\0';
666
667 if (os_strcmp(cmd, "any") == 0)
668 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800669 else if (os_strcmp(cmd, "get") == 0) {
670 ret = wps_generate_pin();
671 goto done;
672 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700673 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
674 cmd);
675 return -1;
676 }
677
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800678#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800679 if (wpa_s->ap_iface) {
680 int timeout = 0;
681 char *pos;
682
683 if (pin) {
684 pos = os_strchr(pin, ' ');
685 if (pos) {
686 *pos++ = '\0';
687 timeout = atoi(pos);
688 }
689 }
690
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700691 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800692 buf, buflen, timeout);
693 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700694#endif /* CONFIG_AP */
695
696 if (pin) {
697 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
698 DEV_PW_DEFAULT);
699 if (ret < 0)
700 return -1;
701 ret = os_snprintf(buf, buflen, "%s", pin);
702 if (ret < 0 || (size_t) ret >= buflen)
703 return -1;
704 return ret;
705 }
706
707 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
708 if (ret < 0)
709 return -1;
710
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800711done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700712 /* Return the generated PIN */
713 ret = os_snprintf(buf, buflen, "%08d", ret);
714 if (ret < 0 || (size_t) ret >= buflen)
715 return -1;
716 return ret;
717}
718
719
720static int wpa_supplicant_ctrl_iface_wps_check_pin(
721 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
722{
723 char pin[9];
724 size_t len;
725 char *pos;
726 int ret;
727
728 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
729 (u8 *) cmd, os_strlen(cmd));
730 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
731 if (*pos < '0' || *pos > '9')
732 continue;
733 pin[len++] = *pos;
734 if (len == 9) {
735 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
736 return -1;
737 }
738 }
739 if (len != 4 && len != 8) {
740 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
741 return -1;
742 }
743 pin[len] = '\0';
744
745 if (len == 8) {
746 unsigned int pin_val;
747 pin_val = atoi(pin);
748 if (!wps_pin_valid(pin_val)) {
749 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
750 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
751 if (ret < 0 || (size_t) ret >= buflen)
752 return -1;
753 return ret;
754 }
755 }
756
757 ret = os_snprintf(buf, buflen, "%s", pin);
758 if (ret < 0 || (size_t) ret >= buflen)
759 return -1;
760
761 return ret;
762}
763
764
Dmitry Shmidt04949592012-07-19 12:16:46 -0700765#ifdef CONFIG_WPS_NFC
766
767static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
768 char *cmd)
769{
770 u8 bssid[ETH_ALEN], *_bssid = bssid;
771
772 if (cmd == NULL || cmd[0] == '\0')
773 _bssid = NULL;
774 else if (hwaddr_aton(cmd, bssid))
775 return -1;
776
777 return wpas_wps_start_nfc(wpa_s, _bssid);
778}
779
780
781static int wpa_supplicant_ctrl_iface_wps_nfc_token(
782 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
783{
784 int ndef;
785 struct wpabuf *buf;
786 int res;
787
788 if (os_strcmp(cmd, "WPS") == 0)
789 ndef = 0;
790 else if (os_strcmp(cmd, "NDEF") == 0)
791 ndef = 1;
792 else
793 return -1;
794
795 buf = wpas_wps_nfc_token(wpa_s, ndef);
796 if (buf == NULL)
797 return -1;
798
799 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
800 wpabuf_len(buf));
801 reply[res++] = '\n';
802 reply[res] = '\0';
803
804 wpabuf_free(buf);
805
806 return res;
807}
808
809
810static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
811 struct wpa_supplicant *wpa_s, char *pos)
812{
813 size_t len;
814 struct wpabuf *buf;
815 int ret;
816
817 len = os_strlen(pos);
818 if (len & 0x01)
819 return -1;
820 len /= 2;
821
822 buf = wpabuf_alloc(len);
823 if (buf == NULL)
824 return -1;
825 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
826 wpabuf_free(buf);
827 return -1;
828 }
829
830 ret = wpas_wps_nfc_tag_read(wpa_s, buf);
831 wpabuf_free(buf);
832
833 return ret;
834}
835
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800836
837static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
838 char *reply, size_t max_len)
839{
840 struct wpabuf *buf;
841 int res;
842
843 buf = wpas_wps_nfc_handover_req(wpa_s);
844 if (buf == NULL)
845 return -1;
846
847 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
848 wpabuf_len(buf));
849 reply[res++] = '\n';
850 reply[res] = '\0';
851
852 wpabuf_free(buf);
853
854 return res;
855}
856
857
858static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
859 char *cmd, char *reply,
860 size_t max_len)
861{
862 char *pos;
863
864 pos = os_strchr(cmd, ' ');
865 if (pos == NULL)
866 return -1;
867 *pos++ = '\0';
868
869 if (os_strcmp(cmd, "NDEF") != 0)
870 return -1;
871
872 if (os_strcmp(pos, "WPS") == 0) {
873 return wpas_ctrl_nfc_get_handover_req_wps(wpa_s, reply,
874 max_len);
875 }
876
877 return -1;
878}
879
880
881static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
882 char *reply, size_t max_len)
883{
884 struct wpabuf *buf;
885 int res;
886
887 buf = wpas_wps_nfc_handover_sel(wpa_s);
888 if (buf == NULL)
889 return -1;
890
891 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
892 wpabuf_len(buf));
893 reply[res++] = '\n';
894 reply[res] = '\0';
895
896 wpabuf_free(buf);
897
898 return res;
899}
900
901
902static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
903 char *cmd, char *reply,
904 size_t max_len)
905{
906 char *pos;
907
908 pos = os_strchr(cmd, ' ');
909 if (pos == NULL)
910 return -1;
911 *pos++ = '\0';
912
913 if (os_strcmp(cmd, "NDEF") != 0)
914 return -1;
915
916 if (os_strcmp(pos, "WPS") == 0) {
917 return wpas_ctrl_nfc_get_handover_sel_wps(wpa_s, reply,
918 max_len);
919 }
920
921 return -1;
922}
923
924
925static int wpas_ctrl_nfc_rx_handover_req(struct wpa_supplicant *wpa_s,
926 char *cmd, char *reply,
927 size_t max_len)
928{
929 size_t len;
930 struct wpabuf *buf;
931 int ret;
932
933 len = os_strlen(cmd);
934 if (len & 0x01)
935 return -1;
936 len /= 2;
937
938 buf = wpabuf_alloc(len);
939 if (buf == NULL)
940 return -1;
941 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
942 wpabuf_free(buf);
943 return -1;
944 }
945
946 ret = wpas_wps_nfc_rx_handover_req(wpa_s, buf);
947 wpabuf_free(buf);
948
949 return ret;
950}
951
952
953static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
954 char *cmd)
955{
956 size_t len;
957 struct wpabuf *buf;
958 int ret;
959
960 len = os_strlen(cmd);
961 if (len & 0x01)
962 return -1;
963 len /= 2;
964
965 buf = wpabuf_alloc(len);
966 if (buf == NULL)
967 return -1;
968 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
969 wpabuf_free(buf);
970 return -1;
971 }
972
973 ret = wpas_wps_nfc_rx_handover_sel(wpa_s, buf);
974 wpabuf_free(buf);
975
976 return ret;
977}
978
Dmitry Shmidt04949592012-07-19 12:16:46 -0700979#endif /* CONFIG_WPS_NFC */
980
981
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700982static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
983 char *cmd)
984{
985 u8 bssid[ETH_ALEN];
986 char *pin;
987 char *new_ssid;
988 char *new_auth;
989 char *new_encr;
990 char *new_key;
991 struct wps_new_ap_settings ap;
992
993 pin = os_strchr(cmd, ' ');
994 if (pin == NULL)
995 return -1;
996 *pin++ = '\0';
997
998 if (hwaddr_aton(cmd, bssid)) {
999 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1000 cmd);
1001 return -1;
1002 }
1003
1004 new_ssid = os_strchr(pin, ' ');
1005 if (new_ssid == NULL)
1006 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1007 *new_ssid++ = '\0';
1008
1009 new_auth = os_strchr(new_ssid, ' ');
1010 if (new_auth == NULL)
1011 return -1;
1012 *new_auth++ = '\0';
1013
1014 new_encr = os_strchr(new_auth, ' ');
1015 if (new_encr == NULL)
1016 return -1;
1017 *new_encr++ = '\0';
1018
1019 new_key = os_strchr(new_encr, ' ');
1020 if (new_key == NULL)
1021 return -1;
1022 *new_key++ = '\0';
1023
1024 os_memset(&ap, 0, sizeof(ap));
1025 ap.ssid_hex = new_ssid;
1026 ap.auth = new_auth;
1027 ap.encr = new_encr;
1028 ap.key_hex = new_key;
1029 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1030}
1031
1032
1033#ifdef CONFIG_AP
1034static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1035 char *cmd, char *buf,
1036 size_t buflen)
1037{
1038 int timeout = 300;
1039 char *pos;
1040 const char *pin_txt;
1041
1042 if (!wpa_s->ap_iface)
1043 return -1;
1044
1045 pos = os_strchr(cmd, ' ');
1046 if (pos)
1047 *pos++ = '\0';
1048
1049 if (os_strcmp(cmd, "disable") == 0) {
1050 wpas_wps_ap_pin_disable(wpa_s);
1051 return os_snprintf(buf, buflen, "OK\n");
1052 }
1053
1054 if (os_strcmp(cmd, "random") == 0) {
1055 if (pos)
1056 timeout = atoi(pos);
1057 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1058 if (pin_txt == NULL)
1059 return -1;
1060 return os_snprintf(buf, buflen, "%s", pin_txt);
1061 }
1062
1063 if (os_strcmp(cmd, "get") == 0) {
1064 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1065 if (pin_txt == NULL)
1066 return -1;
1067 return os_snprintf(buf, buflen, "%s", pin_txt);
1068 }
1069
1070 if (os_strcmp(cmd, "set") == 0) {
1071 char *pin;
1072 if (pos == NULL)
1073 return -1;
1074 pin = pos;
1075 pos = os_strchr(pos, ' ');
1076 if (pos) {
1077 *pos++ = '\0';
1078 timeout = atoi(pos);
1079 }
1080 if (os_strlen(pin) > buflen)
1081 return -1;
1082 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1083 return -1;
1084 return os_snprintf(buf, buflen, "%s", pin);
1085 }
1086
1087 return -1;
1088}
1089#endif /* CONFIG_AP */
1090
1091
1092#ifdef CONFIG_WPS_ER
1093static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1094 char *cmd)
1095{
1096 char *uuid = cmd, *pin, *pos;
1097 u8 addr_buf[ETH_ALEN], *addr = NULL;
1098 pin = os_strchr(uuid, ' ');
1099 if (pin == NULL)
1100 return -1;
1101 *pin++ = '\0';
1102 pos = os_strchr(pin, ' ');
1103 if (pos) {
1104 *pos++ = '\0';
1105 if (hwaddr_aton(pos, addr_buf) == 0)
1106 addr = addr_buf;
1107 }
1108 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1109}
1110
1111
1112static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1113 char *cmd)
1114{
1115 char *uuid = cmd, *pin;
1116 pin = os_strchr(uuid, ' ');
1117 if (pin == NULL)
1118 return -1;
1119 *pin++ = '\0';
1120 return wpas_wps_er_learn(wpa_s, uuid, pin);
1121}
1122
1123
1124static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1125 struct wpa_supplicant *wpa_s, char *cmd)
1126{
1127 char *uuid = cmd, *id;
1128 id = os_strchr(uuid, ' ');
1129 if (id == NULL)
1130 return -1;
1131 *id++ = '\0';
1132 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1133}
1134
1135
1136static int wpa_supplicant_ctrl_iface_wps_er_config(
1137 struct wpa_supplicant *wpa_s, char *cmd)
1138{
1139 char *pin;
1140 char *new_ssid;
1141 char *new_auth;
1142 char *new_encr;
1143 char *new_key;
1144 struct wps_new_ap_settings ap;
1145
1146 pin = os_strchr(cmd, ' ');
1147 if (pin == NULL)
1148 return -1;
1149 *pin++ = '\0';
1150
1151 new_ssid = os_strchr(pin, ' ');
1152 if (new_ssid == NULL)
1153 return -1;
1154 *new_ssid++ = '\0';
1155
1156 new_auth = os_strchr(new_ssid, ' ');
1157 if (new_auth == NULL)
1158 return -1;
1159 *new_auth++ = '\0';
1160
1161 new_encr = os_strchr(new_auth, ' ');
1162 if (new_encr == NULL)
1163 return -1;
1164 *new_encr++ = '\0';
1165
1166 new_key = os_strchr(new_encr, ' ');
1167 if (new_key == NULL)
1168 return -1;
1169 *new_key++ = '\0';
1170
1171 os_memset(&ap, 0, sizeof(ap));
1172 ap.ssid_hex = new_ssid;
1173 ap.auth = new_auth;
1174 ap.encr = new_encr;
1175 ap.key_hex = new_key;
1176 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1177}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001178
1179
1180#ifdef CONFIG_WPS_NFC
1181static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1182 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1183{
1184 int ndef;
1185 struct wpabuf *buf;
1186 int res;
1187 char *uuid;
1188
1189 uuid = os_strchr(cmd, ' ');
1190 if (uuid == NULL)
1191 return -1;
1192 *uuid++ = '\0';
1193
1194 if (os_strcmp(cmd, "WPS") == 0)
1195 ndef = 0;
1196 else if (os_strcmp(cmd, "NDEF") == 0)
1197 ndef = 1;
1198 else
1199 return -1;
1200
1201 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1202 if (buf == NULL)
1203 return -1;
1204
1205 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1206 wpabuf_len(buf));
1207 reply[res++] = '\n';
1208 reply[res] = '\0';
1209
1210 wpabuf_free(buf);
1211
1212 return res;
1213}
1214#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001215#endif /* CONFIG_WPS_ER */
1216
1217#endif /* CONFIG_WPS */
1218
1219
1220#ifdef CONFIG_IBSS_RSN
1221static int wpa_supplicant_ctrl_iface_ibss_rsn(
1222 struct wpa_supplicant *wpa_s, char *addr)
1223{
1224 u8 peer[ETH_ALEN];
1225
1226 if (hwaddr_aton(addr, peer)) {
1227 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1228 "address '%s'", addr);
1229 return -1;
1230 }
1231
1232 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1233 MAC2STR(peer));
1234
1235 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1236}
1237#endif /* CONFIG_IBSS_RSN */
1238
1239
1240static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1241 char *rsp)
1242{
1243#ifdef IEEE8021X_EAPOL
1244 char *pos, *id_pos;
1245 int id;
1246 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001247
1248 pos = os_strchr(rsp, '-');
1249 if (pos == NULL)
1250 return -1;
1251 *pos++ = '\0';
1252 id_pos = pos;
1253 pos = os_strchr(pos, ':');
1254 if (pos == NULL)
1255 return -1;
1256 *pos++ = '\0';
1257 id = atoi(id_pos);
1258 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1259 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1260 (u8 *) pos, os_strlen(pos));
1261
1262 ssid = wpa_config_get_network(wpa_s->conf, id);
1263 if (ssid == NULL) {
1264 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1265 "to update", id);
1266 return -1;
1267 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001268
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001269 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1270 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001271#else /* IEEE8021X_EAPOL */
1272 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1273 return -1;
1274#endif /* IEEE8021X_EAPOL */
1275}
1276
1277
1278static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1279 const char *params,
1280 char *buf, size_t buflen)
1281{
1282 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001283 int res, verbose, wps, ret;
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001284
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001285 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001286 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001287 pos = buf;
1288 end = buf + buflen;
1289 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1290 struct wpa_ssid *ssid = wpa_s->current_ssid;
1291 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1292 MAC2STR(wpa_s->bssid));
1293 if (ret < 0 || ret >= end - pos)
1294 return pos - buf;
1295 pos += ret;
1296 if (ssid) {
1297 u8 *_ssid = ssid->ssid;
1298 size_t ssid_len = ssid->ssid_len;
1299 u8 ssid_buf[MAX_SSID_LEN];
1300 if (ssid_len == 0) {
1301 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1302 if (_res < 0)
1303 ssid_len = 0;
1304 else
1305 ssid_len = _res;
1306 _ssid = ssid_buf;
1307 }
1308 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1309 wpa_ssid_txt(_ssid, ssid_len),
1310 ssid->id);
1311 if (ret < 0 || ret >= end - pos)
1312 return pos - buf;
1313 pos += ret;
1314
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001315 if (wps && ssid->passphrase &&
1316 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1317 (ssid->mode == WPAS_MODE_AP ||
1318 ssid->mode == WPAS_MODE_P2P_GO)) {
1319 ret = os_snprintf(pos, end - pos,
1320 "passphrase=%s\n",
1321 ssid->passphrase);
1322 if (ret < 0 || ret >= end - pos)
1323 return pos - buf;
1324 pos += ret;
1325 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001326 if (ssid->id_str) {
1327 ret = os_snprintf(pos, end - pos,
1328 "id_str=%s\n",
1329 ssid->id_str);
1330 if (ret < 0 || ret >= end - pos)
1331 return pos - buf;
1332 pos += ret;
1333 }
1334
1335 switch (ssid->mode) {
1336 case WPAS_MODE_INFRA:
1337 ret = os_snprintf(pos, end - pos,
1338 "mode=station\n");
1339 break;
1340 case WPAS_MODE_IBSS:
1341 ret = os_snprintf(pos, end - pos,
1342 "mode=IBSS\n");
1343 break;
1344 case WPAS_MODE_AP:
1345 ret = os_snprintf(pos, end - pos,
1346 "mode=AP\n");
1347 break;
1348 case WPAS_MODE_P2P_GO:
1349 ret = os_snprintf(pos, end - pos,
1350 "mode=P2P GO\n");
1351 break;
1352 case WPAS_MODE_P2P_GROUP_FORMATION:
1353 ret = os_snprintf(pos, end - pos,
1354 "mode=P2P GO - group "
1355 "formation\n");
1356 break;
1357 default:
1358 ret = 0;
1359 break;
1360 }
1361 if (ret < 0 || ret >= end - pos)
1362 return pos - buf;
1363 pos += ret;
1364 }
1365
1366#ifdef CONFIG_AP
1367 if (wpa_s->ap_iface) {
1368 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1369 end - pos,
1370 verbose);
1371 } else
1372#endif /* CONFIG_AP */
1373 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1374 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001375#ifdef CONFIG_SAE
1376 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1377 wpa_s->sme.sae.state == SAE_ACCEPTED && !wpa_s->ap_iface) {
1378 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1379 wpa_s->sme.sae.group);
1380 if (ret < 0 || ret >= end - pos)
1381 return pos - buf;
1382 pos += ret;
1383 }
1384#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001385 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1386 wpa_supplicant_state_txt(wpa_s->wpa_state));
1387 if (ret < 0 || ret >= end - pos)
1388 return pos - buf;
1389 pos += ret;
1390
1391 if (wpa_s->l2 &&
1392 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1393 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1394 if (ret < 0 || ret >= end - pos)
1395 return pos - buf;
1396 pos += ret;
1397 }
1398
1399#ifdef CONFIG_P2P
1400 if (wpa_s->global->p2p) {
1401 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1402 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1403 if (ret < 0 || ret >= end - pos)
1404 return pos - buf;
1405 pos += ret;
1406 }
1407#endif /* CONFIG_P2P */
1408
1409 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1410 MAC2STR(wpa_s->own_addr));
1411 if (ret < 0 || ret >= end - pos)
1412 return pos - buf;
1413 pos += ret;
1414
Dmitry Shmidt04949592012-07-19 12:16:46 -07001415#ifdef CONFIG_HS20
1416 if (wpa_s->current_bss &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001417 wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE) &&
1418 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1419 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001420 ret = os_snprintf(pos, end - pos, "hs20=1\n");
1421 if (ret < 0 || ret >= end - pos)
1422 return pos - buf;
1423 pos += ret;
1424 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001425
1426 if (wpa_s->current_ssid) {
1427 struct wpa_cred *cred;
1428 char *type;
1429
1430 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1431 if (wpa_s->current_ssid->parent_cred != cred)
1432 continue;
1433 if (!cred->domain)
1434 continue;
1435
1436 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1437 cred->domain);
1438 if (ret < 0 || ret >= end - pos)
1439 return pos - buf;
1440 pos += ret;
1441
1442 if (wpa_s->current_bss == NULL ||
1443 wpa_s->current_bss->anqp == NULL)
1444 res = -1;
1445 else
1446 res = interworking_home_sp_cred(
1447 wpa_s, cred,
1448 wpa_s->current_bss->anqp->domain_name);
1449 if (res > 0)
1450 type = "home";
1451 else if (res == 0)
1452 type = "roaming";
1453 else
1454 type = "unknown";
1455
1456 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1457 if (ret < 0 || ret >= end - pos)
1458 return pos - buf;
1459 pos += ret;
1460
1461 break;
1462 }
1463 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001464#endif /* CONFIG_HS20 */
1465
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001466 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1467 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1468 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1469 verbose);
1470 if (res >= 0)
1471 pos += res;
1472 }
1473
1474 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1475 if (res >= 0)
1476 pos += res;
1477
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08001478#ifdef ANDROID
1479 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
Irfan Sherifff20a4432012-04-16 16:48:34 -07001480 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08001481 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
Irfan Sherifff20a4432012-04-16 16:48:34 -07001482 wpa_s->wpa_state,
Irfan Sheriffe78e7672012-08-01 11:10:15 -07001483 MAC2STR(wpa_s->bssid),
andy2_kuo5b5fb022012-05-22 11:53:07 -07001484 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1485 wpa_ssid_txt(wpa_s->current_ssid->ssid,
Irfan Sheriff10294772012-05-11 11:23:35 -07001486 wpa_s->current_ssid->ssid_len) : "");
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08001487 if (wpa_s->wpa_state == WPA_COMPLETED) {
1488 struct wpa_ssid *ssid = wpa_s->current_ssid;
1489 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED "- connection to "
1490 MACSTR " completed %s [id=%d id_str=%s]",
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001491 MAC2STR(wpa_s->bssid), "(auth)",
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08001492 ssid ? ssid->id : -1,
1493 ssid && ssid->id_str ? ssid->id_str : "");
1494 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08001495#endif /* ANDROID */
1496
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001497 return pos - buf;
1498}
1499
1500
1501static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1502 char *cmd)
1503{
1504 char *pos;
1505 int id;
1506 struct wpa_ssid *ssid;
1507 u8 bssid[ETH_ALEN];
1508
1509 /* cmd: "<network id> <BSSID>" */
1510 pos = os_strchr(cmd, ' ');
1511 if (pos == NULL)
1512 return -1;
1513 *pos++ = '\0';
1514 id = atoi(cmd);
1515 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1516 if (hwaddr_aton(pos, bssid)) {
1517 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1518 return -1;
1519 }
1520
1521 ssid = wpa_config_get_network(wpa_s->conf, id);
1522 if (ssid == NULL) {
1523 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1524 "to update", id);
1525 return -1;
1526 }
1527
1528 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1529 ssid->bssid_set = !is_zero_ether_addr(bssid);
1530
1531 return 0;
1532}
1533
1534
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001535static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001536 char *cmd, char *buf,
1537 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001538{
1539 u8 bssid[ETH_ALEN];
1540 struct wpa_blacklist *e;
1541 char *pos, *end;
1542 int ret;
1543
1544 /* cmd: "BLACKLIST [<BSSID>]" */
1545 if (*cmd == '\0') {
1546 pos = buf;
1547 end = buf + buflen;
1548 e = wpa_s->blacklist;
1549 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001550 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1551 MAC2STR(e->bssid));
1552 if (ret < 0 || ret >= end - pos)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001553 return pos - buf;
1554 pos += ret;
1555 e = e->next;
1556 }
1557 return pos - buf;
1558 }
1559
1560 cmd++;
1561 if (os_strncmp(cmd, "clear", 5) == 0) {
1562 wpa_blacklist_clear(wpa_s);
1563 os_memcpy(buf, "OK\n", 3);
1564 return 3;
1565 }
1566
1567 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1568 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001569 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001570 return -1;
1571 }
1572
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001573 /*
1574 * Add the BSSID twice, so its count will be 2, causing it to be
1575 * skipped when processing scan results.
1576 */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001577 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001578 if (ret != 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001579 return -1;
1580 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001581 if (ret != 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07001582 return -1;
1583 os_memcpy(buf, "OK\n", 3);
1584 return 3;
1585}
1586
1587
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001588extern int wpa_debug_level;
1589extern int wpa_debug_timestamp;
1590
1591static const char * debug_level_str(int level)
1592{
1593 switch (level) {
1594 case MSG_EXCESSIVE:
1595 return "EXCESSIVE";
1596 case MSG_MSGDUMP:
1597 return "MSGDUMP";
1598 case MSG_DEBUG:
1599 return "DEBUG";
1600 case MSG_INFO:
1601 return "INFO";
1602 case MSG_WARNING:
1603 return "WARNING";
1604 case MSG_ERROR:
1605 return "ERROR";
1606 default:
1607 return "?";
1608 }
1609}
1610
1611
1612static int str_to_debug_level(const char *s)
1613{
1614 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1615 return MSG_EXCESSIVE;
1616 if (os_strcasecmp(s, "MSGDUMP") == 0)
1617 return MSG_MSGDUMP;
1618 if (os_strcasecmp(s, "DEBUG") == 0)
1619 return MSG_DEBUG;
1620 if (os_strcasecmp(s, "INFO") == 0)
1621 return MSG_INFO;
1622 if (os_strcasecmp(s, "WARNING") == 0)
1623 return MSG_WARNING;
1624 if (os_strcasecmp(s, "ERROR") == 0)
1625 return MSG_ERROR;
1626 return -1;
1627}
1628
1629
1630static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1631 char *cmd, char *buf,
1632 size_t buflen)
1633{
1634 char *pos, *end, *stamp;
1635 int ret;
1636
1637 if (cmd == NULL) {
1638 return -1;
1639 }
1640
1641 /* cmd: "LOG_LEVEL [<level>]" */
1642 if (*cmd == '\0') {
1643 pos = buf;
1644 end = buf + buflen;
1645 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1646 "Timestamp: %d\n",
1647 debug_level_str(wpa_debug_level),
1648 wpa_debug_timestamp);
1649 if (ret < 0 || ret >= end - pos)
1650 ret = 0;
1651
1652 return ret;
1653 }
1654
1655 while (*cmd == ' ')
1656 cmd++;
1657
1658 stamp = os_strchr(cmd, ' ');
1659 if (stamp) {
1660 *stamp++ = '\0';
1661 while (*stamp == ' ') {
1662 stamp++;
1663 }
1664 }
1665
1666 if (cmd && os_strlen(cmd)) {
1667 int level = str_to_debug_level(cmd);
1668 if (level < 0)
1669 return -1;
1670 wpa_debug_level = level;
1671 }
1672
1673 if (stamp && os_strlen(stamp))
1674 wpa_debug_timestamp = atoi(stamp);
1675
1676 os_memcpy(buf, "OK\n", 3);
1677 return 3;
1678}
1679
1680
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001681static int wpa_supplicant_ctrl_iface_list_networks(
1682 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1683{
1684 char *pos, *end;
1685 struct wpa_ssid *ssid;
1686 int ret;
1687
1688 pos = buf;
1689 end = buf + buflen;
1690 ret = os_snprintf(pos, end - pos,
1691 "network id / ssid / bssid / flags\n");
1692 if (ret < 0 || ret >= end - pos)
1693 return pos - buf;
1694 pos += ret;
1695
1696 ssid = wpa_s->conf->ssid;
1697 while (ssid) {
1698 ret = os_snprintf(pos, end - pos, "%d\t%s",
1699 ssid->id,
1700 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1701 if (ret < 0 || ret >= end - pos)
1702 return pos - buf;
1703 pos += ret;
1704 if (ssid->bssid_set) {
1705 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
1706 MAC2STR(ssid->bssid));
1707 } else {
1708 ret = os_snprintf(pos, end - pos, "\tany");
1709 }
1710 if (ret < 0 || ret >= end - pos)
1711 return pos - buf;
1712 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001713 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001714 ssid == wpa_s->current_ssid ?
1715 "[CURRENT]" : "",
1716 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001717 ssid->disabled_until.sec ?
1718 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001719 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
1720 "");
1721 if (ret < 0 || ret >= end - pos)
1722 return pos - buf;
1723 pos += ret;
1724 ret = os_snprintf(pos, end - pos, "\n");
1725 if (ret < 0 || ret >= end - pos)
1726 return pos - buf;
1727 pos += ret;
1728
1729 ssid = ssid->next;
1730 }
1731
1732 return pos - buf;
1733}
1734
1735
1736static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
1737{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001738 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001739 ret = os_snprintf(pos, end - pos, "-");
1740 if (ret < 0 || ret >= end - pos)
1741 return pos;
1742 pos += ret;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001743 ret = wpa_write_ciphers(pos, end, cipher, "+");
1744 if (ret < 0)
1745 return pos;
1746 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001747 return pos;
1748}
1749
1750
1751static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
1752 const u8 *ie, size_t ie_len)
1753{
1754 struct wpa_ie_data data;
1755 int first, ret;
1756
1757 ret = os_snprintf(pos, end - pos, "[%s-", proto);
1758 if (ret < 0 || ret >= end - pos)
1759 return pos;
1760 pos += ret;
1761
1762 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
1763 ret = os_snprintf(pos, end - pos, "?]");
1764 if (ret < 0 || ret >= end - pos)
1765 return pos;
1766 pos += ret;
1767 return pos;
1768 }
1769
1770 first = 1;
1771 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
1772 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
1773 if (ret < 0 || ret >= end - pos)
1774 return pos;
1775 pos += ret;
1776 first = 0;
1777 }
1778 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
1779 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
1780 if (ret < 0 || ret >= end - pos)
1781 return pos;
1782 pos += ret;
1783 first = 0;
1784 }
1785 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
1786 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
1787 if (ret < 0 || ret >= end - pos)
1788 return pos;
1789 pos += ret;
1790 first = 0;
1791 }
1792#ifdef CONFIG_IEEE80211R
1793 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
1794 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
1795 first ? "" : "+");
1796 if (ret < 0 || ret >= end - pos)
1797 return pos;
1798 pos += ret;
1799 first = 0;
1800 }
1801 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
1802 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
1803 first ? "" : "+");
1804 if (ret < 0 || ret >= end - pos)
1805 return pos;
1806 pos += ret;
1807 first = 0;
1808 }
1809#endif /* CONFIG_IEEE80211R */
1810#ifdef CONFIG_IEEE80211W
1811 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1812 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
1813 first ? "" : "+");
1814 if (ret < 0 || ret >= end - pos)
1815 return pos;
1816 pos += ret;
1817 first = 0;
1818 }
1819 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
1820 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
1821 first ? "" : "+");
1822 if (ret < 0 || ret >= end - pos)
1823 return pos;
1824 pos += ret;
1825 first = 0;
1826 }
1827#endif /* CONFIG_IEEE80211W */
1828
1829 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
1830
1831 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
1832 ret = os_snprintf(pos, end - pos, "-preauth");
1833 if (ret < 0 || ret >= end - pos)
1834 return pos;
1835 pos += ret;
1836 }
1837
1838 ret = os_snprintf(pos, end - pos, "]");
1839 if (ret < 0 || ret >= end - pos)
1840 return pos;
1841 pos += ret;
1842
1843 return pos;
1844}
1845
1846
1847#ifdef CONFIG_WPS
1848static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
1849 char *pos, char *end,
1850 struct wpabuf *wps_ie)
1851{
1852 int ret;
1853 const char *txt;
1854
1855 if (wps_ie == NULL)
1856 return pos;
1857 if (wps_is_selected_pbc_registrar(wps_ie))
1858 txt = "[WPS-PBC]";
1859#ifdef CONFIG_WPS2
1860 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
1861 txt = "[WPS-AUTH]";
1862#endif /* CONFIG_WPS2 */
1863 else if (wps_is_selected_pin_registrar(wps_ie))
1864 txt = "[WPS-PIN]";
1865 else
1866 txt = "[WPS]";
1867
1868 ret = os_snprintf(pos, end - pos, "%s", txt);
1869 if (ret >= 0 && ret < end - pos)
1870 pos += ret;
1871 wpabuf_free(wps_ie);
1872 return pos;
1873}
1874#endif /* CONFIG_WPS */
1875
1876
1877static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
1878 char *pos, char *end,
1879 const struct wpa_bss *bss)
1880{
1881#ifdef CONFIG_WPS
1882 struct wpabuf *wps_ie;
1883 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1884 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
1885#else /* CONFIG_WPS */
1886 return pos;
1887#endif /* CONFIG_WPS */
1888}
1889
1890
1891/* Format one result on one text line into a buffer. */
1892static int wpa_supplicant_ctrl_iface_scan_result(
1893 struct wpa_supplicant *wpa_s,
1894 const struct wpa_bss *bss, char *buf, size_t buflen)
1895{
1896 char *pos, *end;
1897 int ret;
1898 const u8 *ie, *ie2, *p2p;
1899
1900 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1901 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
1902 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
1903 0)
1904 return 0; /* Do not show P2P listen discovery results here */
1905
1906 pos = buf;
1907 end = buf + buflen;
1908
1909 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
1910 MAC2STR(bss->bssid), bss->freq, bss->level);
1911 if (ret < 0 || ret >= end - pos)
1912 return -1;
1913 pos += ret;
1914 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1915 if (ie)
1916 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
1917 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1918 if (ie2)
1919 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
1920 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
1921 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
1922 ret = os_snprintf(pos, end - pos, "[WEP]");
1923 if (ret < 0 || ret >= end - pos)
1924 return -1;
1925 pos += ret;
1926 }
1927 if (bss->caps & IEEE80211_CAP_IBSS) {
1928 ret = os_snprintf(pos, end - pos, "[IBSS]");
1929 if (ret < 0 || ret >= end - pos)
1930 return -1;
1931 pos += ret;
1932 }
1933 if (bss->caps & IEEE80211_CAP_ESS) {
1934 ret = os_snprintf(pos, end - pos, "[ESS]");
1935 if (ret < 0 || ret >= end - pos)
1936 return -1;
1937 pos += ret;
1938 }
1939 if (p2p) {
1940 ret = os_snprintf(pos, end - pos, "[P2P]");
1941 if (ret < 0 || ret >= end - pos)
1942 return -1;
1943 pos += ret;
1944 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001945#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001946 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001947 ret = os_snprintf(pos, end - pos, "[HS20]");
1948 if (ret < 0 || ret >= end - pos)
1949 return -1;
1950 pos += ret;
1951 }
1952#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001953
1954 ret = os_snprintf(pos, end - pos, "\t%s",
1955 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1956 if (ret < 0 || ret >= end - pos)
1957 return -1;
1958 pos += ret;
1959
1960 ret = os_snprintf(pos, end - pos, "\n");
1961 if (ret < 0 || ret >= end - pos)
1962 return -1;
1963 pos += ret;
1964
1965 return pos - buf;
1966}
1967
1968
1969static int wpa_supplicant_ctrl_iface_scan_results(
1970 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1971{
1972 char *pos, *end;
1973 struct wpa_bss *bss;
1974 int ret;
1975
1976 pos = buf;
1977 end = buf + buflen;
1978 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
1979 "flags / ssid\n");
1980 if (ret < 0 || ret >= end - pos)
1981 return pos - buf;
1982 pos += ret;
1983
1984 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
1985 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
1986 end - pos);
1987 if (ret < 0 || ret >= end - pos)
1988 return pos - buf;
1989 pos += ret;
1990 }
1991
1992 return pos - buf;
1993}
1994
1995
1996static int wpa_supplicant_ctrl_iface_select_network(
1997 struct wpa_supplicant *wpa_s, char *cmd)
1998{
1999 int id;
2000 struct wpa_ssid *ssid;
2001
2002 /* cmd: "<network id>" or "any" */
2003 if (os_strcmp(cmd, "any") == 0) {
2004 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2005 ssid = NULL;
2006 } else {
2007 id = atoi(cmd);
2008 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2009
2010 ssid = wpa_config_get_network(wpa_s->conf, id);
2011 if (ssid == NULL) {
2012 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2013 "network id=%d", id);
2014 return -1;
2015 }
2016 if (ssid->disabled == 2) {
2017 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2018 "SELECT_NETWORK with persistent P2P group");
2019 return -1;
2020 }
2021 }
2022
2023 wpa_supplicant_select_network(wpa_s, ssid);
2024
2025 return 0;
2026}
2027
2028
2029static int wpa_supplicant_ctrl_iface_enable_network(
2030 struct wpa_supplicant *wpa_s, char *cmd)
2031{
2032 int id;
2033 struct wpa_ssid *ssid;
2034
2035 /* cmd: "<network id>" or "all" */
2036 if (os_strcmp(cmd, "all") == 0) {
2037 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2038 ssid = NULL;
2039 } else {
2040 id = atoi(cmd);
2041 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2042
2043 ssid = wpa_config_get_network(wpa_s->conf, id);
2044 if (ssid == NULL) {
2045 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2046 "network id=%d", id);
2047 return -1;
2048 }
2049 if (ssid->disabled == 2) {
2050 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2051 "ENABLE_NETWORK with persistent P2P group");
2052 return -1;
2053 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002054
2055 if (os_strstr(cmd, " no-connect")) {
2056 ssid->disabled = 0;
2057 return 0;
2058 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002059 }
2060 wpa_supplicant_enable_network(wpa_s, ssid);
2061
2062 return 0;
2063}
2064
2065
2066static int wpa_supplicant_ctrl_iface_disable_network(
2067 struct wpa_supplicant *wpa_s, char *cmd)
2068{
2069 int id;
2070 struct wpa_ssid *ssid;
2071
2072 /* cmd: "<network id>" or "all" */
2073 if (os_strcmp(cmd, "all") == 0) {
2074 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2075 ssid = NULL;
2076 } else {
2077 id = atoi(cmd);
2078 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2079
2080 ssid = wpa_config_get_network(wpa_s->conf, id);
2081 if (ssid == NULL) {
2082 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2083 "network id=%d", id);
2084 return -1;
2085 }
2086 if (ssid->disabled == 2) {
2087 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2088 "DISABLE_NETWORK with persistent P2P "
2089 "group");
2090 return -1;
2091 }
2092 }
2093 wpa_supplicant_disable_network(wpa_s, ssid);
2094
2095 return 0;
2096}
2097
2098
2099static int wpa_supplicant_ctrl_iface_add_network(
2100 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2101{
2102 struct wpa_ssid *ssid;
2103 int ret;
2104
2105 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2106
2107 ssid = wpa_config_add_network(wpa_s->conf);
2108 if (ssid == NULL)
2109 return -1;
2110
2111 wpas_notify_network_added(wpa_s, ssid);
2112
2113 ssid->disabled = 1;
2114 wpa_config_set_network_defaults(ssid);
2115
2116 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2117 if (ret < 0 || (size_t) ret >= buflen)
2118 return -1;
2119 return ret;
2120}
2121
2122
2123static int wpa_supplicant_ctrl_iface_remove_network(
2124 struct wpa_supplicant *wpa_s, char *cmd)
2125{
2126 int id;
2127 struct wpa_ssid *ssid;
2128
2129 /* cmd: "<network id>" or "all" */
2130 if (os_strcmp(cmd, "all") == 0) {
2131 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002132 eapol_sm_invalidate_cached_session(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002133 if (wpa_s->current_ssid) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002134#ifdef CONFIG_SME
2135 wpa_s->sme.prev_bssid_set = 0;
2136#endif /* CONFIG_SME */
Jouni Malinen75ecf522011-06-27 15:19:46 -07002137 wpa_sm_set_config(wpa_s->wpa, NULL);
2138 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002139 wpa_supplicant_deauthenticate(
2140 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002141 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002142 ssid = wpa_s->conf->ssid;
2143 while (ssid) {
2144 struct wpa_ssid *remove_ssid = ssid;
2145 id = ssid->id;
2146 ssid = ssid->next;
2147 wpas_notify_network_removed(wpa_s, remove_ssid);
2148 wpa_config_remove_network(wpa_s->conf, id);
2149 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002150 return 0;
2151 }
2152
2153 id = atoi(cmd);
2154 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2155
2156 ssid = wpa_config_get_network(wpa_s->conf, id);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002157 if (ssid)
2158 wpas_notify_network_removed(wpa_s, ssid);
Deepthi Gowria831d782012-09-03 11:55:38 +03002159 if (ssid == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002160 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2161 "id=%d", id);
2162 return -1;
2163 }
2164
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002165 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002166#ifdef CONFIG_SME
2167 wpa_s->sme.prev_bssid_set = 0;
2168#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002169 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002170 * Invalidate the EAP session cache if the current or
2171 * previously used network is removed.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002172 */
2173 eapol_sm_invalidate_cached_session(wpa_s->eapol);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002174 }
2175
2176 if (ssid == wpa_s->current_ssid) {
Jouni Malinen75ecf522011-06-27 15:19:46 -07002177 wpa_sm_set_config(wpa_s->wpa, NULL);
2178 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002179
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002180 wpa_supplicant_deauthenticate(wpa_s,
2181 WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002182 }
2183
Deepthi Gowria831d782012-09-03 11:55:38 +03002184 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2185 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2186 "network id=%d", id);
2187 return -1;
2188 }
2189
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002190 return 0;
2191}
2192
2193
2194static int wpa_supplicant_ctrl_iface_set_network(
2195 struct wpa_supplicant *wpa_s, char *cmd)
2196{
2197 int id;
2198 struct wpa_ssid *ssid;
2199 char *name, *value;
2200
2201 /* cmd: "<network id> <variable name> <value>" */
2202 name = os_strchr(cmd, ' ');
2203 if (name == NULL)
2204 return -1;
2205 *name++ = '\0';
2206
2207 value = os_strchr(name, ' ');
2208 if (value == NULL)
2209 return -1;
2210 *value++ = '\0';
2211
2212 id = atoi(cmd);
2213 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2214 id, name);
2215 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2216 (u8 *) value, os_strlen(value));
2217
2218 ssid = wpa_config_get_network(wpa_s->conf, id);
2219 if (ssid == NULL) {
2220 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2221 "id=%d", id);
2222 return -1;
2223 }
2224
2225 if (wpa_config_set(ssid, name, value, 0) < 0) {
2226 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2227 "variable '%s'", name);
2228 return -1;
2229 }
2230
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002231 if (os_strcmp(name, "bssid") != 0 &&
2232 os_strcmp(name, "priority") != 0)
2233 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002234
2235 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002236 /*
2237 * Invalidate the EAP session cache if anything in the current
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002238 * or previously used configuration changes.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002239 */
2240 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2241 }
2242
2243 if ((os_strcmp(name, "psk") == 0 &&
2244 value[0] == '"' && ssid->ssid_len) ||
2245 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2246 wpa_config_update_psk(ssid);
2247 else if (os_strcmp(name, "priority") == 0)
2248 wpa_config_update_prio_list(wpa_s->conf);
2249
2250 return 0;
2251}
2252
2253
2254static int wpa_supplicant_ctrl_iface_get_network(
2255 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2256{
2257 int id;
2258 size_t res;
2259 struct wpa_ssid *ssid;
2260 char *name, *value;
2261
2262 /* cmd: "<network id> <variable name>" */
2263 name = os_strchr(cmd, ' ');
2264 if (name == NULL || buflen == 0)
2265 return -1;
2266 *name++ = '\0';
2267
2268 id = atoi(cmd);
2269 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2270 id, name);
2271
2272 ssid = wpa_config_get_network(wpa_s->conf, id);
2273 if (ssid == NULL) {
2274 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2275 "id=%d", id);
2276 return -1;
2277 }
2278
2279 value = wpa_config_get_no_key(ssid, name);
2280 if (value == NULL) {
2281 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2282 "variable '%s'", name);
2283 return -1;
2284 }
2285
2286 res = os_strlcpy(buf, value, buflen);
2287 if (res >= buflen) {
2288 os_free(value);
2289 return -1;
2290 }
2291
2292 os_free(value);
2293
2294 return res;
2295}
2296
2297
Dmitry Shmidt04949592012-07-19 12:16:46 -07002298static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2299 char *buf, size_t buflen)
2300{
2301 char *pos, *end;
2302 struct wpa_cred *cred;
2303 int ret;
2304
2305 pos = buf;
2306 end = buf + buflen;
2307 ret = os_snprintf(pos, end - pos,
2308 "cred id / realm / username / domain / imsi\n");
2309 if (ret < 0 || ret >= end - pos)
2310 return pos - buf;
2311 pos += ret;
2312
2313 cred = wpa_s->conf->cred;
2314 while (cred) {
2315 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2316 cred->id, cred->realm ? cred->realm : "",
2317 cred->username ? cred->username : "",
2318 cred->domain ? cred->domain : "",
2319 cred->imsi ? cred->imsi : "");
2320 if (ret < 0 || ret >= end - pos)
2321 return pos - buf;
2322 pos += ret;
2323
2324 cred = cred->next;
2325 }
2326
2327 return pos - buf;
2328}
2329
2330
2331static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2332 char *buf, size_t buflen)
2333{
2334 struct wpa_cred *cred;
2335 int ret;
2336
2337 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2338
2339 cred = wpa_config_add_cred(wpa_s->conf);
2340 if (cred == NULL)
2341 return -1;
2342
2343 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2344 if (ret < 0 || (size_t) ret >= buflen)
2345 return -1;
2346 return ret;
2347}
2348
2349
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002350static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2351 struct wpa_cred *cred)
2352{
2353 struct wpa_ssid *ssid;
2354 char str[20];
2355
2356 if (cred == NULL || wpa_config_remove_cred(wpa_s->conf, cred->id) < 0) {
2357 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2358 return -1;
2359 }
2360
2361 /* Remove any network entry created based on the removed credential */
2362 ssid = wpa_s->conf->ssid;
2363 while (ssid) {
2364 if (ssid->parent_cred == cred) {
2365 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2366 "used the removed credential", ssid->id);
2367 os_snprintf(str, sizeof(str), "%d", ssid->id);
2368 ssid = ssid->next;
2369 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2370 } else
2371 ssid = ssid->next;
2372 }
2373
2374 return 0;
2375}
2376
2377
Dmitry Shmidt04949592012-07-19 12:16:46 -07002378static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2379 char *cmd)
2380{
2381 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002382 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002383
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002384 /* cmd: "<cred id>", "all", or "sp_fqdn=<FQDN>" */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002385 if (os_strcmp(cmd, "all") == 0) {
2386 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2387 cred = wpa_s->conf->cred;
2388 while (cred) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002389 prev = cred;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002390 cred = cred->next;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002391 wpas_ctrl_remove_cred(wpa_s, prev);
2392 }
2393 return 0;
2394 }
2395
2396 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2397 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2398 cmd + 8);
2399 cred = wpa_s->conf->cred;
2400 while (cred) {
2401 prev = cred;
2402 cred = cred->next;
2403 if (prev->domain &&
2404 os_strcmp(prev->domain, cmd + 8) == 0)
2405 wpas_ctrl_remove_cred(wpa_s, prev);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002406 }
2407 return 0;
2408 }
2409
2410 id = atoi(cmd);
2411 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2412
2413 cred = wpa_config_get_cred(wpa_s->conf, id);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002414 return wpas_ctrl_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002415}
2416
2417
2418static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2419 char *cmd)
2420{
2421 int id;
2422 struct wpa_cred *cred;
2423 char *name, *value;
2424
2425 /* cmd: "<cred id> <variable name> <value>" */
2426 name = os_strchr(cmd, ' ');
2427 if (name == NULL)
2428 return -1;
2429 *name++ = '\0';
2430
2431 value = os_strchr(name, ' ');
2432 if (value == NULL)
2433 return -1;
2434 *value++ = '\0';
2435
2436 id = atoi(cmd);
2437 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2438 id, name);
2439 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2440 (u8 *) value, os_strlen(value));
2441
2442 cred = wpa_config_get_cred(wpa_s->conf, id);
2443 if (cred == NULL) {
2444 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2445 id);
2446 return -1;
2447 }
2448
2449 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2450 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2451 "variable '%s'", name);
2452 return -1;
2453 }
2454
2455 return 0;
2456}
2457
2458
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002459#ifndef CONFIG_NO_CONFIG_WRITE
2460static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2461{
2462 int ret;
2463
2464 if (!wpa_s->conf->update_config) {
2465 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2466 "to update configuration (update_config=0)");
2467 return -1;
2468 }
2469
2470 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2471 if (ret) {
2472 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2473 "update configuration");
2474 } else {
2475 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2476 " updated");
2477 }
2478
2479 return ret;
2480}
2481#endif /* CONFIG_NO_CONFIG_WRITE */
2482
2483
2484static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2485 struct wpa_driver_capa *capa,
2486 char *buf, size_t buflen)
2487{
2488 int ret, first = 1;
2489 char *pos, *end;
2490 size_t len;
2491
2492 pos = buf;
2493 end = pos + buflen;
2494
2495 if (res < 0) {
2496 if (strict)
2497 return 0;
2498 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2499 if (len >= buflen)
2500 return -1;
2501 return len;
2502 }
2503
2504 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
2505 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
2506 if (ret < 0 || ret >= end - pos)
2507 return pos - buf;
2508 pos += ret;
2509 first = 0;
2510 }
2511
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002512 if (capa->enc & WPA_DRIVER_CAPA_ENC_GCMP) {
2513 ret = os_snprintf(pos, end - pos, "%sGCMP", first ? "" : " ");
2514 if (ret < 0 || ret >= end - pos)
2515 return pos - buf;
2516 pos += ret;
2517 first = 0;
2518 }
2519
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002520 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
2521 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
2522 if (ret < 0 || ret >= end - pos)
2523 return pos - buf;
2524 pos += ret;
2525 first = 0;
2526 }
2527
2528 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2529 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " ");
2530 if (ret < 0 || ret >= end - pos)
2531 return pos - buf;
2532 pos += ret;
2533 first = 0;
2534 }
2535
2536 return pos - buf;
2537}
2538
2539
2540static int ctrl_iface_get_capability_group(int res, char *strict,
2541 struct wpa_driver_capa *capa,
2542 char *buf, size_t buflen)
2543{
2544 int ret, first = 1;
2545 char *pos, *end;
2546 size_t len;
2547
2548 pos = buf;
2549 end = pos + buflen;
2550
2551 if (res < 0) {
2552 if (strict)
2553 return 0;
2554 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2555 if (len >= buflen)
2556 return -1;
2557 return len;
2558 }
2559
2560 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
2561 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
2562 if (ret < 0 || ret >= end - pos)
2563 return pos - buf;
2564 pos += ret;
2565 first = 0;
2566 }
2567
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002568 if (capa->enc & WPA_DRIVER_CAPA_ENC_GCMP) {
2569 ret = os_snprintf(pos, end - pos, "%sGCMP", first ? "" : " ");
2570 if (ret < 0 || ret >= end - pos)
2571 return pos - buf;
2572 pos += ret;
2573 first = 0;
2574 }
2575
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002576 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
2577 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
2578 if (ret < 0 || ret >= end - pos)
2579 return pos - buf;
2580 pos += ret;
2581 first = 0;
2582 }
2583
2584 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) {
2585 ret = os_snprintf(pos, end - pos, "%sWEP104",
2586 first ? "" : " ");
2587 if (ret < 0 || ret >= end - pos)
2588 return pos - buf;
2589 pos += ret;
2590 first = 0;
2591 }
2592
2593 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) {
2594 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " ");
2595 if (ret < 0 || ret >= end - pos)
2596 return pos - buf;
2597 pos += ret;
2598 first = 0;
2599 }
2600
2601 return pos - buf;
2602}
2603
2604
2605static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2606 struct wpa_driver_capa *capa,
2607 char *buf, size_t buflen)
2608{
2609 int ret;
2610 char *pos, *end;
2611 size_t len;
2612
2613 pos = buf;
2614 end = pos + buflen;
2615
2616 if (res < 0) {
2617 if (strict)
2618 return 0;
2619 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2620 "NONE", buflen);
2621 if (len >= buflen)
2622 return -1;
2623 return len;
2624 }
2625
2626 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2627 if (ret < 0 || ret >= end - pos)
2628 return pos - buf;
2629 pos += ret;
2630
2631 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2632 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2633 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2634 if (ret < 0 || ret >= end - pos)
2635 return pos - buf;
2636 pos += ret;
2637 }
2638
2639 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2640 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2641 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2642 if (ret < 0 || ret >= end - pos)
2643 return pos - buf;
2644 pos += ret;
2645 }
2646
2647 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2648 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2649 if (ret < 0 || ret >= end - pos)
2650 return pos - buf;
2651 pos += ret;
2652 }
2653
2654 return pos - buf;
2655}
2656
2657
2658static int ctrl_iface_get_capability_proto(int res, char *strict,
2659 struct wpa_driver_capa *capa,
2660 char *buf, size_t buflen)
2661{
2662 int ret, first = 1;
2663 char *pos, *end;
2664 size_t len;
2665
2666 pos = buf;
2667 end = pos + buflen;
2668
2669 if (res < 0) {
2670 if (strict)
2671 return 0;
2672 len = os_strlcpy(buf, "RSN WPA", buflen);
2673 if (len >= buflen)
2674 return -1;
2675 return len;
2676 }
2677
2678 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2679 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2680 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
2681 if (ret < 0 || ret >= end - pos)
2682 return pos - buf;
2683 pos += ret;
2684 first = 0;
2685 }
2686
2687 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2688 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
2689 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
2690 if (ret < 0 || ret >= end - pos)
2691 return pos - buf;
2692 pos += ret;
2693 first = 0;
2694 }
2695
2696 return pos - buf;
2697}
2698
2699
2700static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
2701 struct wpa_driver_capa *capa,
2702 char *buf, size_t buflen)
2703{
2704 int ret, first = 1;
2705 char *pos, *end;
2706 size_t len;
2707
2708 pos = buf;
2709 end = pos + buflen;
2710
2711 if (res < 0) {
2712 if (strict)
2713 return 0;
2714 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
2715 if (len >= buflen)
2716 return -1;
2717 return len;
2718 }
2719
2720 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
2721 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
2722 if (ret < 0 || ret >= end - pos)
2723 return pos - buf;
2724 pos += ret;
2725 first = 0;
2726 }
2727
2728 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
2729 ret = os_snprintf(pos, end - pos, "%sSHARED",
2730 first ? "" : " ");
2731 if (ret < 0 || ret >= end - pos)
2732 return pos - buf;
2733 pos += ret;
2734 first = 0;
2735 }
2736
2737 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
2738 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
2739 if (ret < 0 || ret >= end - pos)
2740 return pos - buf;
2741 pos += ret;
2742 first = 0;
2743 }
2744
2745 return pos - buf;
2746}
2747
2748
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07002749static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
2750 char *buf, size_t buflen)
2751{
2752 struct hostapd_channel_data *chnl;
2753 int ret, i, j;
2754 char *pos, *end, *hmode;
2755
2756 pos = buf;
2757 end = pos + buflen;
2758
2759 for (j = 0; j < wpa_s->hw.num_modes; j++) {
2760 switch (wpa_s->hw.modes[j].mode) {
2761 case HOSTAPD_MODE_IEEE80211B:
2762 hmode = "B";
2763 break;
2764 case HOSTAPD_MODE_IEEE80211G:
2765 hmode = "G";
2766 break;
2767 case HOSTAPD_MODE_IEEE80211A:
2768 hmode = "A";
2769 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002770 case HOSTAPD_MODE_IEEE80211AD:
2771 hmode = "AD";
2772 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07002773 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002774 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07002775 }
2776 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
2777 if (ret < 0 || ret >= end - pos)
2778 return pos - buf;
2779 pos += ret;
2780 chnl = wpa_s->hw.modes[j].channels;
2781 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002782 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
2783 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07002784 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
2785 if (ret < 0 || ret >= end - pos)
2786 return pos - buf;
2787 pos += ret;
2788 }
2789 ret = os_snprintf(pos, end - pos, "\n");
2790 if (ret < 0 || ret >= end - pos)
2791 return pos - buf;
2792 pos += ret;
2793 }
2794
2795 return pos - buf;
2796}
2797
2798
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002799static int wpa_supplicant_ctrl_iface_get_capability(
2800 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
2801 size_t buflen)
2802{
2803 struct wpa_driver_capa capa;
2804 int res;
2805 char *strict;
2806 char field[30];
2807 size_t len;
2808
2809 /* Determine whether or not strict checking was requested */
2810 len = os_strlcpy(field, _field, sizeof(field));
2811 if (len >= sizeof(field))
2812 return -1;
2813 strict = os_strchr(field, ' ');
2814 if (strict != NULL) {
2815 *strict++ = '\0';
2816 if (os_strcmp(strict, "strict") != 0)
2817 return -1;
2818 }
2819
2820 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
2821 field, strict ? strict : "");
2822
2823 if (os_strcmp(field, "eap") == 0) {
2824 return eap_get_names(buf, buflen);
2825 }
2826
2827 res = wpa_drv_get_capa(wpa_s, &capa);
2828
2829 if (os_strcmp(field, "pairwise") == 0)
2830 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
2831 buf, buflen);
2832
2833 if (os_strcmp(field, "group") == 0)
2834 return ctrl_iface_get_capability_group(res, strict, &capa,
2835 buf, buflen);
2836
2837 if (os_strcmp(field, "key_mgmt") == 0)
2838 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
2839 buf, buflen);
2840
2841 if (os_strcmp(field, "proto") == 0)
2842 return ctrl_iface_get_capability_proto(res, strict, &capa,
2843 buf, buflen);
2844
2845 if (os_strcmp(field, "auth_alg") == 0)
2846 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
2847 buf, buflen);
2848
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07002849 if (os_strcmp(field, "channels") == 0)
2850 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
2851
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002852 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
2853 field);
2854
2855 return -1;
2856}
2857
2858
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002859#ifdef CONFIG_INTERWORKING
2860static char * anqp_add_hex(char *pos, char *end, const char *title,
2861 struct wpabuf *data)
2862{
2863 char *start = pos;
2864 size_t i;
2865 int ret;
2866 const u8 *d;
2867
2868 if (data == NULL)
2869 return start;
2870
2871 ret = os_snprintf(pos, end - pos, "%s=", title);
2872 if (ret < 0 || ret >= end - pos)
2873 return start;
2874 pos += ret;
2875
2876 d = wpabuf_head_u8(data);
2877 for (i = 0; i < wpabuf_len(data); i++) {
2878 ret = os_snprintf(pos, end - pos, "%02x", *d++);
2879 if (ret < 0 || ret >= end - pos)
2880 return start;
2881 pos += ret;
2882 }
2883
2884 ret = os_snprintf(pos, end - pos, "\n");
2885 if (ret < 0 || ret >= end - pos)
2886 return start;
2887 pos += ret;
2888
2889 return pos;
2890}
2891#endif /* CONFIG_INTERWORKING */
2892
2893
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07002894static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
2895 unsigned long mask, char *buf, size_t buflen)
2896{
2897 size_t i;
2898 int ret;
2899 char *pos, *end;
2900 const u8 *ie, *ie2;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07002901
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07002902 pos = buf;
2903 end = buf + buflen;
2904
2905 if (mask & WPA_BSS_MASK_ID) {
2906 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
2907 if (ret < 0 || ret >= end - pos)
2908 return 0;
2909 pos += ret;
2910 }
2911
2912 if (mask & WPA_BSS_MASK_BSSID) {
2913 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2914 MAC2STR(bss->bssid));
2915 if (ret < 0 || ret >= end - pos)
2916 return 0;
2917 pos += ret;
2918 }
2919
2920 if (mask & WPA_BSS_MASK_FREQ) {
2921 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
2922 if (ret < 0 || ret >= end - pos)
2923 return 0;
2924 pos += ret;
2925 }
2926
2927 if (mask & WPA_BSS_MASK_BEACON_INT) {
2928 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
2929 bss->beacon_int);
2930 if (ret < 0 || ret >= end - pos)
2931 return 0;
2932 pos += ret;
2933 }
2934
2935 if (mask & WPA_BSS_MASK_CAPABILITIES) {
2936 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
2937 bss->caps);
2938 if (ret < 0 || ret >= end - pos)
2939 return 0;
2940 pos += ret;
2941 }
2942
2943 if (mask & WPA_BSS_MASK_QUAL) {
2944 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
2945 if (ret < 0 || ret >= end - pos)
2946 return 0;
2947 pos += ret;
2948 }
2949
2950 if (mask & WPA_BSS_MASK_NOISE) {
2951 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
2952 if (ret < 0 || ret >= end - pos)
2953 return 0;
2954 pos += ret;
2955 }
2956
2957 if (mask & WPA_BSS_MASK_LEVEL) {
2958 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
2959 if (ret < 0 || ret >= end - pos)
2960 return 0;
2961 pos += ret;
2962 }
2963
2964 if (mask & WPA_BSS_MASK_TSF) {
2965 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
2966 (unsigned long long) bss->tsf);
2967 if (ret < 0 || ret >= end - pos)
2968 return 0;
2969 pos += ret;
2970 }
2971
2972 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002973 struct os_time now;
2974
2975 os_get_time(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07002976 ret = os_snprintf(pos, end - pos, "age=%d\n",
2977 (int) (now.sec - bss->last_update.sec));
2978 if (ret < 0 || ret >= end - pos)
2979 return 0;
2980 pos += ret;
2981 }
2982
2983 if (mask & WPA_BSS_MASK_IE) {
2984 ret = os_snprintf(pos, end - pos, "ie=");
2985 if (ret < 0 || ret >= end - pos)
2986 return 0;
2987 pos += ret;
2988
2989 ie = (const u8 *) (bss + 1);
2990 for (i = 0; i < bss->ie_len; i++) {
2991 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
2992 if (ret < 0 || ret >= end - pos)
2993 return 0;
2994 pos += ret;
2995 }
2996
2997 ret = os_snprintf(pos, end - pos, "\n");
2998 if (ret < 0 || ret >= end - pos)
2999 return 0;
3000 pos += ret;
3001 }
3002
3003 if (mask & WPA_BSS_MASK_FLAGS) {
3004 ret = os_snprintf(pos, end - pos, "flags=");
3005 if (ret < 0 || ret >= end - pos)
3006 return 0;
3007 pos += ret;
3008
3009 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3010 if (ie)
3011 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3012 2 + ie[1]);
3013 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3014 if (ie2)
3015 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3016 2 + ie2[1]);
3017 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3018 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3019 ret = os_snprintf(pos, end - pos, "[WEP]");
3020 if (ret < 0 || ret >= end - pos)
3021 return 0;
3022 pos += ret;
3023 }
3024 if (bss->caps & IEEE80211_CAP_IBSS) {
3025 ret = os_snprintf(pos, end - pos, "[IBSS]");
3026 if (ret < 0 || ret >= end - pos)
3027 return 0;
3028 pos += ret;
3029 }
3030 if (bss->caps & IEEE80211_CAP_ESS) {
3031 ret = os_snprintf(pos, end - pos, "[ESS]");
3032 if (ret < 0 || ret >= end - pos)
3033 return 0;
3034 pos += ret;
3035 }
3036 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) {
3037 ret = os_snprintf(pos, end - pos, "[P2P]");
3038 if (ret < 0 || ret >= end - pos)
3039 return 0;
3040 pos += ret;
3041 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003042#ifdef CONFIG_HS20
3043 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3044 ret = os_snprintf(pos, end - pos, "[HS20]");
3045 if (ret < 0 || ret >= end - pos)
3046 return -1;
3047 pos += ret;
3048 }
3049#endif /* CONFIG_HS20 */
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003050
3051 ret = os_snprintf(pos, end - pos, "\n");
3052 if (ret < 0 || ret >= end - pos)
3053 return 0;
3054 pos += ret;
3055 }
3056
3057 if (mask & WPA_BSS_MASK_SSID) {
3058 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3059 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3060 if (ret < 0 || ret >= end - pos)
3061 return 0;
3062 pos += ret;
3063 }
3064
3065#ifdef CONFIG_WPS
3066 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3067 ie = (const u8 *) (bss + 1);
3068 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3069 if (ret < 0 || ret >= end - pos)
3070 return 0;
3071 pos += ret;
3072 }
3073#endif /* CONFIG_WPS */
3074
3075#ifdef CONFIG_P2P
3076 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3077 ie = (const u8 *) (bss + 1);
3078 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3079 if (ret < 0 || ret >= end - pos)
3080 return 0;
3081 pos += ret;
3082 }
3083#endif /* CONFIG_P2P */
3084
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003085#ifdef CONFIG_WIFI_DISPLAY
3086 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3087 struct wpabuf *wfd;
3088 ie = (const u8 *) (bss + 1);
3089 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3090 WFD_IE_VENDOR_TYPE);
3091 if (wfd) {
3092 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3093 if (ret < 0 || ret >= end - pos)
3094 return pos - buf;
3095 pos += ret;
3096
3097 pos += wpa_snprintf_hex(pos, end - pos,
3098 wpabuf_head(wfd),
3099 wpabuf_len(wfd));
3100 wpabuf_free(wfd);
3101
3102 ret = os_snprintf(pos, end - pos, "\n");
3103 if (ret < 0 || ret >= end - pos)
3104 return pos - buf;
3105 pos += ret;
3106 }
3107 }
3108#endif /* CONFIG_WIFI_DISPLAY */
3109
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003110#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003111 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3112 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003113 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003114 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003115 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003116 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003117 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003118 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003119 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003120 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003121 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003122 anqp->nai_realm);
3123 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003124 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003125 anqp->domain_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003126#ifdef CONFIG_HS20
3127 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003128 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003129 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003130 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003131 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003132 anqp->hs20_connection_capability);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003133#endif /* CONFIG_HS20 */
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003134 }
3135#endif /* CONFIG_INTERWORKING */
3136
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07003137#ifdef ANDROID
3138 ret = os_snprintf(pos, end - pos, "====\n");
3139 if (ret < 0 || ret >= end - pos)
3140 return 0;
3141 pos += ret;
3142#endif
3143
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003144 return pos - buf;
3145}
3146
Dmitry Shmidt04949592012-07-19 12:16:46 -07003147
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003148static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3149 const char *cmd, char *buf,
3150 size_t buflen)
3151{
3152 u8 bssid[ETH_ALEN];
3153 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003154 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003155 struct wpa_bss *bsslast = NULL;
3156 struct dl_list *next;
3157 int ret = 0;
3158 int len;
3159 char *ctmp;
3160 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003161
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003162 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3163 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3164 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003165 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003166 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3167 list_id);
3168 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003169 unsigned int id1, id2;
3170
3171 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3172 wpa_printf(MSG_INFO, "Wrong BSS range "
3173 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003174 return 0;
3175 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003176
3177 id1 = atoi(cmd + 6);
3178 bss = wpa_bss_get_id(wpa_s, id1);
3179 id2 = atoi(ctmp + 1);
3180 if (id2 == 0)
3181 bsslast = dl_list_last(&wpa_s->bss_id,
3182 struct wpa_bss,
3183 list_id);
3184 else {
3185 bsslast = wpa_bss_get_id(wpa_s, id2);
3186 if (bsslast == NULL && bss && id2 > id1) {
3187 struct wpa_bss *tmp = bss;
3188 for (;;) {
3189 next = tmp->list_id.next;
3190 if (next == &wpa_s->bss_id)
3191 break;
3192 tmp = dl_list_entry(
3193 next, struct wpa_bss,
3194 list_id);
3195 if (tmp->id > id2)
3196 break;
3197 bsslast = tmp;
3198 }
3199 }
3200 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003201 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003202 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07003203 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003204 else if (os_strncmp(cmd, "LAST", 4) == 0)
3205 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003206 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3207 i = atoi(cmd + 3);
3208 bss = wpa_bss_get_id(wpa_s, i);
3209 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3210 i = atoi(cmd + 5);
3211 bss = wpa_bss_get_id(wpa_s, i);
3212 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003213 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003214 if (next == &wpa_s->bss_id)
3215 bss = NULL;
3216 else
3217 bss = dl_list_entry(next, struct wpa_bss,
3218 list_id);
3219 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003220#ifdef CONFIG_P2P
3221 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3222 if (hwaddr_aton(cmd + 13, bssid) == 0)
3223 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3224 else
3225 bss = NULL;
3226#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003227 } else if (hwaddr_aton(cmd, bssid) == 0)
3228 bss = wpa_bss_get_bssid(wpa_s, bssid);
3229 else {
3230 struct wpa_bss *tmp;
3231 i = atoi(cmd);
3232 bss = NULL;
3233 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3234 {
3235 if (i-- == 0) {
3236 bss = tmp;
3237 break;
3238 }
3239 }
3240 }
3241
Dmitry Shmidt04949592012-07-19 12:16:46 -07003242 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3243 mask = strtoul(ctmp + 5, NULL, 0x10);
3244 if (mask == 0)
3245 mask = WPA_BSS_MASK_ALL;
3246 }
3247
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003248 if (bss == NULL)
3249 return 0;
3250
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003251 if (bsslast == NULL)
3252 bsslast = bss;
3253 do {
3254 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3255 ret += len;
3256 buf += len;
3257 buflen -= len;
3258 if (bss == bsslast)
3259 break;
3260 next = bss->list_id.next;
3261 if (next == &wpa_s->bss_id)
3262 break;
3263 bss = dl_list_entry(next, struct wpa_bss, list_id);
3264 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003265
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07003266 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003267}
3268
3269
3270static int wpa_supplicant_ctrl_iface_ap_scan(
3271 struct wpa_supplicant *wpa_s, char *cmd)
3272{
3273 int ap_scan = atoi(cmd);
3274 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3275}
3276
3277
3278static int wpa_supplicant_ctrl_iface_scan_interval(
3279 struct wpa_supplicant *wpa_s, char *cmd)
3280{
3281 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003282 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003283}
3284
3285
3286static int wpa_supplicant_ctrl_iface_bss_expire_age(
3287 struct wpa_supplicant *wpa_s, char *cmd)
3288{
3289 int expire_age = atoi(cmd);
3290 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3291}
3292
3293
3294static int wpa_supplicant_ctrl_iface_bss_expire_count(
3295 struct wpa_supplicant *wpa_s, char *cmd)
3296{
3297 int expire_count = atoi(cmd);
3298 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3299}
3300
3301
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07003302static int wpa_supplicant_ctrl_iface_bss_flush(
3303 struct wpa_supplicant *wpa_s, char *cmd)
3304{
3305 int flush_age = atoi(cmd);
3306
3307 if (flush_age == 0)
3308 wpa_bss_flush(wpa_s);
3309 else
3310 wpa_bss_flush_by_age(wpa_s, flush_age);
3311 return 0;
3312}
3313
3314
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003315static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3316{
3317 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3318 /* MLME-DELETEKEYS.request */
3319 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3320 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3321 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3322 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3323#ifdef CONFIG_IEEE80211W
3324 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3325 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3326#endif /* CONFIG_IEEE80211W */
3327
3328 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3329 0);
3330 /* MLME-SETPROTECTION.request(None) */
3331 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3332 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3333 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3334 wpa_sm_drop_sa(wpa_s->wpa);
3335}
3336
3337
3338static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3339 char *addr)
3340{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003341#ifdef CONFIG_NO_SCAN_PROCESSING
3342 return -1;
3343#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003344 u8 bssid[ETH_ALEN];
3345 struct wpa_bss *bss;
3346 struct wpa_ssid *ssid = wpa_s->current_ssid;
3347
3348 if (hwaddr_aton(addr, bssid)) {
3349 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3350 "address '%s'", addr);
3351 return -1;
3352 }
3353
3354 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3355
3356 bss = wpa_bss_get_bssid(wpa_s, bssid);
3357 if (!bss) {
3358 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3359 "from BSS table");
3360 return -1;
3361 }
3362
3363 /*
3364 * TODO: Find best network configuration block from configuration to
3365 * allow roaming to other networks
3366 */
3367
3368 if (!ssid) {
3369 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3370 "configuration known for the target AP");
3371 return -1;
3372 }
3373
3374 wpa_s->reassociate = 1;
3375 wpa_supplicant_connect(wpa_s, bss, ssid);
3376
3377 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003378#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003379}
3380
3381
3382#ifdef CONFIG_P2P
3383static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3384{
3385 unsigned int timeout = atoi(cmd);
3386 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003387 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3388 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003389 unsigned int search_delay;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003390
3391 if (os_strstr(cmd, "type=social"))
3392 type = P2P_FIND_ONLY_SOCIAL;
3393 else if (os_strstr(cmd, "type=progressive"))
3394 type = P2P_FIND_PROGRESSIVE;
3395
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003396 pos = os_strstr(cmd, "dev_id=");
3397 if (pos) {
3398 pos += 7;
3399 if (hwaddr_aton(pos, dev_id))
3400 return -1;
3401 _dev_id = dev_id;
3402 }
3403
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003404 pos = os_strstr(cmd, "delay=");
3405 if (pos) {
3406 pos += 6;
3407 search_delay = atoi(pos);
3408 } else
3409 search_delay = wpas_p2p_search_delay(wpa_s);
3410
3411 return wpas_p2p_find(wpa_s, timeout, type, 0, NULL, _dev_id,
3412 search_delay);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003413}
3414
3415
3416static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3417 char *buf, size_t buflen)
3418{
3419 u8 addr[ETH_ALEN];
3420 char *pos, *pos2;
3421 char *pin = NULL;
3422 enum p2p_wps_method wps_method;
3423 int new_pin;
3424 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003425 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003426 int join;
3427 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003428 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003429 int go_intent = -1;
3430 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003431 int pd;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003432 int ht40;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003433
Dmitry Shmidt04949592012-07-19 12:16:46 -07003434 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3435 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003436 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3437 * [ht40] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003438
3439 if (hwaddr_aton(cmd, addr))
3440 return -1;
3441
3442 pos = cmd + 17;
3443 if (*pos != ' ')
3444 return -1;
3445 pos++;
3446
3447 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003448 pos2 = os_strstr(pos, " persistent=");
3449 if (pos2) {
3450 struct wpa_ssid *ssid;
3451 persistent_id = atoi(pos2 + 12);
3452 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3453 if (ssid == NULL || ssid->disabled != 2 ||
3454 ssid->mode != WPAS_MODE_P2P_GO) {
3455 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3456 "SSID id=%d for persistent P2P group (GO)",
3457 persistent_id);
3458 return -1;
3459 }
3460 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003461 join = os_strstr(pos, " join") != NULL;
3462 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003463 automatic = os_strstr(pos, " auto") != NULL;
3464 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003465 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003466
3467 pos2 = os_strstr(pos, " go_intent=");
3468 if (pos2) {
3469 pos2 += 11;
3470 go_intent = atoi(pos2);
3471 if (go_intent < 0 || go_intent > 15)
3472 return -1;
3473 }
3474
3475 pos2 = os_strstr(pos, " freq=");
3476 if (pos2) {
3477 pos2 += 6;
3478 freq = atoi(pos2);
3479 if (freq <= 0)
3480 return -1;
3481 }
3482
3483 if (os_strncmp(pos, "pin", 3) == 0) {
3484 /* Request random PIN (to be displayed) and enable the PIN */
3485 wps_method = WPS_PIN_DISPLAY;
3486 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3487 wps_method = WPS_PBC;
3488 } else {
3489 pin = pos;
3490 pos = os_strchr(pin, ' ');
3491 wps_method = WPS_PIN_KEYPAD;
3492 if (pos) {
3493 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003494 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003495 wps_method = WPS_PIN_DISPLAY;
3496 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003497 if (!wps_pin_str_valid(pin)) {
3498 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3499 return 17;
3500 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003501 }
3502
3503 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003504 persistent_group, automatic, join,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003505 auth, go_intent, freq, persistent_id, pd,
3506 ht40);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003507 if (new_pin == -2) {
3508 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3509 return 25;
3510 }
3511 if (new_pin == -3) {
3512 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3513 return 25;
3514 }
3515 if (new_pin < 0)
3516 return -1;
3517 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3518 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3519 if (ret < 0 || (size_t) ret >= buflen)
3520 return -1;
3521 return ret;
3522 }
3523
3524 os_memcpy(buf, "OK\n", 3);
3525 return 3;
3526}
3527
3528
3529static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3530{
3531 unsigned int timeout = atoi(cmd);
3532 return wpas_p2p_listen(wpa_s, timeout);
3533}
3534
3535
3536static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
3537{
3538 u8 addr[ETH_ALEN];
3539 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003540 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003541
Dmitry Shmidt04949592012-07-19 12:16:46 -07003542 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003543
3544 if (hwaddr_aton(cmd, addr))
3545 return -1;
3546
3547 pos = cmd + 17;
3548 if (*pos != ' ')
3549 return -1;
3550 pos++;
3551
Dmitry Shmidt04949592012-07-19 12:16:46 -07003552 if (os_strstr(pos, " join") != NULL)
3553 use = WPAS_P2P_PD_FOR_JOIN;
3554 else if (os_strstr(pos, " auto") != NULL)
3555 use = WPAS_P2P_PD_AUTO;
3556
3557 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003558}
3559
3560
3561static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
3562 size_t buflen)
3563{
3564 struct wpa_ssid *ssid = wpa_s->current_ssid;
3565
3566 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
3567 ssid->passphrase == NULL)
3568 return -1;
3569
3570 os_strlcpy(buf, ssid->passphrase, buflen);
3571 return os_strlen(buf);
3572}
3573
3574
3575static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
3576 char *buf, size_t buflen)
3577{
3578 u64 ref;
3579 int res;
3580 u8 dst_buf[ETH_ALEN], *dst;
3581 struct wpabuf *tlvs;
3582 char *pos;
3583 size_t len;
3584
3585 if (hwaddr_aton(cmd, dst_buf))
3586 return -1;
3587 dst = dst_buf;
3588 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
3589 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
3590 dst = NULL;
3591 pos = cmd + 17;
3592 if (*pos != ' ')
3593 return -1;
3594 pos++;
3595
3596 if (os_strncmp(pos, "upnp ", 5) == 0) {
3597 u8 version;
3598 pos += 5;
3599 if (hexstr2bin(pos, &version, 1) < 0)
3600 return -1;
3601 pos += 2;
3602 if (*pos != ' ')
3603 return -1;
3604 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003605 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003606#ifdef CONFIG_WIFI_DISPLAY
3607 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
3608 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
3609#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003610 } else {
3611 len = os_strlen(pos);
3612 if (len & 1)
3613 return -1;
3614 len /= 2;
3615 tlvs = wpabuf_alloc(len);
3616 if (tlvs == NULL)
3617 return -1;
3618 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
3619 wpabuf_free(tlvs);
3620 return -1;
3621 }
3622
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003623 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003624 wpabuf_free(tlvs);
3625 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003626 if (ref == 0)
3627 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003628 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
3629 if (res < 0 || (unsigned) res >= buflen)
3630 return -1;
3631 return res;
3632}
3633
3634
3635static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
3636 char *cmd)
3637{
3638 long long unsigned val;
3639 u64 req;
3640 if (sscanf(cmd, "%llx", &val) != 1)
3641 return -1;
3642 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003643 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003644}
3645
3646
3647static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
3648{
3649 int freq;
3650 u8 dst[ETH_ALEN];
3651 u8 dialog_token;
3652 struct wpabuf *resp_tlvs;
3653 char *pos, *pos2;
3654 size_t len;
3655
3656 pos = os_strchr(cmd, ' ');
3657 if (pos == NULL)
3658 return -1;
3659 *pos++ = '\0';
3660 freq = atoi(cmd);
3661 if (freq == 0)
3662 return -1;
3663
3664 if (hwaddr_aton(pos, dst))
3665 return -1;
3666 pos += 17;
3667 if (*pos != ' ')
3668 return -1;
3669 pos++;
3670
3671 pos2 = os_strchr(pos, ' ');
3672 if (pos2 == NULL)
3673 return -1;
3674 *pos2++ = '\0';
3675 dialog_token = atoi(pos);
3676
3677 len = os_strlen(pos2);
3678 if (len & 1)
3679 return -1;
3680 len /= 2;
3681 resp_tlvs = wpabuf_alloc(len);
3682 if (resp_tlvs == NULL)
3683 return -1;
3684 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
3685 wpabuf_free(resp_tlvs);
3686 return -1;
3687 }
3688
3689 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
3690 wpabuf_free(resp_tlvs);
3691 return 0;
3692}
3693
3694
3695static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
3696 char *cmd)
3697{
Dmitry Shmidt04949592012-07-19 12:16:46 -07003698 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
3699 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003700 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
3701 return 0;
3702}
3703
3704
3705static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
3706 char *cmd)
3707{
3708 char *pos;
3709 size_t len;
3710 struct wpabuf *query, *resp;
3711
3712 pos = os_strchr(cmd, ' ');
3713 if (pos == NULL)
3714 return -1;
3715 *pos++ = '\0';
3716
3717 len = os_strlen(cmd);
3718 if (len & 1)
3719 return -1;
3720 len /= 2;
3721 query = wpabuf_alloc(len);
3722 if (query == NULL)
3723 return -1;
3724 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
3725 wpabuf_free(query);
3726 return -1;
3727 }
3728
3729 len = os_strlen(pos);
3730 if (len & 1) {
3731 wpabuf_free(query);
3732 return -1;
3733 }
3734 len /= 2;
3735 resp = wpabuf_alloc(len);
3736 if (resp == NULL) {
3737 wpabuf_free(query);
3738 return -1;
3739 }
3740 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
3741 wpabuf_free(query);
3742 wpabuf_free(resp);
3743 return -1;
3744 }
3745
3746 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
3747 wpabuf_free(query);
3748 wpabuf_free(resp);
3749 return -1;
3750 }
3751 return 0;
3752}
3753
3754
3755static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
3756{
3757 char *pos;
3758 u8 version;
3759
3760 pos = os_strchr(cmd, ' ');
3761 if (pos == NULL)
3762 return -1;
3763 *pos++ = '\0';
3764
3765 if (hexstr2bin(cmd, &version, 1) < 0)
3766 return -1;
3767
3768 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
3769}
3770
3771
3772static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
3773{
3774 char *pos;
3775
3776 pos = os_strchr(cmd, ' ');
3777 if (pos == NULL)
3778 return -1;
3779 *pos++ = '\0';
3780
3781 if (os_strcmp(cmd, "bonjour") == 0)
3782 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
3783 if (os_strcmp(cmd, "upnp") == 0)
3784 return p2p_ctrl_service_add_upnp(wpa_s, pos);
3785 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
3786 return -1;
3787}
3788
3789
3790static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
3791 char *cmd)
3792{
3793 size_t len;
3794 struct wpabuf *query;
3795 int ret;
3796
3797 len = os_strlen(cmd);
3798 if (len & 1)
3799 return -1;
3800 len /= 2;
3801 query = wpabuf_alloc(len);
3802 if (query == NULL)
3803 return -1;
3804 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
3805 wpabuf_free(query);
3806 return -1;
3807 }
3808
3809 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
3810 wpabuf_free(query);
3811 return ret;
3812}
3813
3814
3815static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
3816{
3817 char *pos;
3818 u8 version;
3819
3820 pos = os_strchr(cmd, ' ');
3821 if (pos == NULL)
3822 return -1;
3823 *pos++ = '\0';
3824
3825 if (hexstr2bin(cmd, &version, 1) < 0)
3826 return -1;
3827
3828 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
3829}
3830
3831
3832static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
3833{
3834 char *pos;
3835
3836 pos = os_strchr(cmd, ' ');
3837 if (pos == NULL)
3838 return -1;
3839 *pos++ = '\0';
3840
3841 if (os_strcmp(cmd, "bonjour") == 0)
3842 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
3843 if (os_strcmp(cmd, "upnp") == 0)
3844 return p2p_ctrl_service_del_upnp(wpa_s, pos);
3845 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
3846 return -1;
3847}
3848
3849
3850static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
3851{
3852 u8 addr[ETH_ALEN];
3853
3854 /* <addr> */
3855
3856 if (hwaddr_aton(cmd, addr))
3857 return -1;
3858
3859 return wpas_p2p_reject(wpa_s, addr);
3860}
3861
3862
3863static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
3864{
3865 char *pos;
3866 int id;
3867 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07003868 u8 *_peer = NULL, peer[ETH_ALEN];
Jouni Malinen31be0a42012-08-31 21:20:51 +03003869 int freq = 0;
3870 int ht40;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003871
3872 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07003873 pos = os_strstr(cmd, " peer=");
3874 if (pos) {
3875 pos += 6;
3876 if (hwaddr_aton(pos, peer))
3877 return -1;
3878 _peer = peer;
3879 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003880 ssid = wpa_config_get_network(wpa_s->conf, id);
3881 if (ssid == NULL || ssid->disabled != 2) {
3882 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
3883 "for persistent P2P group",
3884 id);
3885 return -1;
3886 }
3887
Jouni Malinen31be0a42012-08-31 21:20:51 +03003888 pos = os_strstr(cmd, " freq=");
3889 if (pos) {
3890 pos += 6;
3891 freq = atoi(pos);
3892 if (freq <= 0)
3893 return -1;
3894 }
3895
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003896 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40;
Jouni Malinen31be0a42012-08-31 21:20:51 +03003897
Dmitry Shmidtaa532512012-09-24 10:35:31 -07003898 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003899}
3900
3901
3902static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
3903{
3904 char *pos;
3905 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
3906
3907 pos = os_strstr(cmd, " peer=");
3908 if (!pos)
3909 return -1;
3910
3911 *pos = '\0';
3912 pos += 6;
3913 if (hwaddr_aton(pos, peer)) {
3914 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
3915 return -1;
3916 }
3917
3918 pos = os_strstr(pos, " go_dev_addr=");
3919 if (pos) {
3920 pos += 13;
3921 if (hwaddr_aton(pos, go_dev_addr)) {
3922 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
3923 pos);
3924 return -1;
3925 }
3926 go_dev = go_dev_addr;
3927 }
3928
3929 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
3930}
3931
3932
3933static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
3934{
3935 if (os_strncmp(cmd, "persistent=", 11) == 0)
3936 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
3937 if (os_strncmp(cmd, "group=", 6) == 0)
3938 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
3939
3940 return -1;
3941}
3942
3943
3944static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003945 char *cmd, int freq, int ht40)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003946{
3947 int id;
3948 struct wpa_ssid *ssid;
3949
3950 id = atoi(cmd);
3951 ssid = wpa_config_get_network(wpa_s->conf, id);
3952 if (ssid == NULL || ssid->disabled != 2) {
3953 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
3954 "for persistent P2P group",
3955 id);
3956 return -1;
3957 }
3958
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003959 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, ht40);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003960}
3961
3962
3963static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
3964{
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003965 int freq = 0, ht40;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003966 char *pos;
3967
3968 pos = os_strstr(cmd, "freq=");
3969 if (pos)
3970 freq = atoi(pos + 5);
3971
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003972 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003973
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003974 if (os_strncmp(cmd, "persistent=", 11) == 0)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003975 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
3976 ht40);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003977 if (os_strcmp(cmd, "persistent") == 0 ||
3978 os_strncmp(cmd, "persistent ", 11) == 0)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003979 return wpas_p2p_group_add(wpa_s, 1, freq, ht40);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003980 if (os_strncmp(cmd, "freq=", 5) == 0)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003981 return wpas_p2p_group_add(wpa_s, 0, freq, ht40);
3982 if (ht40)
3983 return wpas_p2p_group_add(wpa_s, 0, freq, ht40);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003984
3985 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
3986 cmd);
3987 return -1;
3988}
3989
3990
3991static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
3992 char *buf, size_t buflen)
3993{
3994 u8 addr[ETH_ALEN], *addr_ptr;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003995 int next, res;
3996 const struct p2p_peer_info *info;
3997 char *pos, *end;
3998 char devtype[WPS_DEV_TYPE_BUFSIZE];
3999 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004000 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004001
4002 if (!wpa_s->global->p2p)
4003 return -1;
4004
4005 if (os_strcmp(cmd, "FIRST") == 0) {
4006 addr_ptr = NULL;
4007 next = 0;
4008 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4009 if (hwaddr_aton(cmd + 5, addr) < 0)
4010 return -1;
4011 addr_ptr = addr;
4012 next = 1;
4013 } else {
4014 if (hwaddr_aton(cmd, addr) < 0)
4015 return -1;
4016 addr_ptr = addr;
4017 next = 0;
4018 }
4019
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004020 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4021 if (info == NULL)
4022 return -1;
4023
4024 pos = buf;
4025 end = buf + buflen;
4026
4027 res = os_snprintf(pos, end - pos, MACSTR "\n"
4028 "pri_dev_type=%s\n"
4029 "device_name=%s\n"
4030 "manufacturer=%s\n"
4031 "model_name=%s\n"
4032 "model_number=%s\n"
4033 "serial_number=%s\n"
4034 "config_methods=0x%x\n"
4035 "dev_capab=0x%x\n"
4036 "group_capab=0x%x\n"
4037 "level=%d\n",
4038 MAC2STR(info->p2p_device_addr),
4039 wps_dev_type_bin2str(info->pri_dev_type,
4040 devtype, sizeof(devtype)),
4041 info->device_name,
4042 info->manufacturer,
4043 info->model_name,
4044 info->model_number,
4045 info->serial_number,
4046 info->config_methods,
4047 info->dev_capab,
4048 info->group_capab,
4049 info->level);
4050 if (res < 0 || res >= end - pos)
4051 return pos - buf;
4052 pos += res;
4053
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004054 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4055 {
4056 const u8 *t;
4057 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4058 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4059 wps_dev_type_bin2str(t, devtype,
4060 sizeof(devtype)));
4061 if (res < 0 || res >= end - pos)
4062 return pos - buf;
4063 pos += res;
4064 }
4065
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004066 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004067 if (ssid) {
4068 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4069 if (res < 0 || res >= end - pos)
4070 return pos - buf;
4071 pos += res;
4072 }
4073
4074 res = p2p_get_peer_info_txt(info, pos, end - pos);
4075 if (res < 0)
4076 return pos - buf;
4077 pos += res;
4078
4079 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004080}
4081
4082
Dmitry Shmidt04949592012-07-19 12:16:46 -07004083static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4084 const char *param)
4085{
4086 struct wpa_freq_range *freq = NULL, *n;
4087 unsigned int count = 0, i;
4088 const char *pos, *pos2, *pos3;
4089
4090 if (wpa_s->global->p2p == NULL)
4091 return -1;
4092
4093 /*
4094 * param includes comma separated frequency range.
4095 * For example: 2412-2432,2462,5000-6000
4096 */
4097 pos = param;
4098 while (pos && pos[0]) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004099 n = os_realloc_array(freq, count + 1,
4100 sizeof(struct wpa_freq_range));
Dmitry Shmidt04949592012-07-19 12:16:46 -07004101 if (n == NULL) {
4102 os_free(freq);
4103 return -1;
4104 }
4105 freq = n;
4106 freq[count].min = atoi(pos);
4107 pos2 = os_strchr(pos, '-');
4108 pos3 = os_strchr(pos, ',');
4109 if (pos2 && (!pos3 || pos2 < pos3)) {
4110 pos2++;
4111 freq[count].max = atoi(pos2);
4112 } else
4113 freq[count].max = freq[count].min;
4114 pos = pos3;
4115 if (pos)
4116 pos++;
4117 count++;
4118 }
4119
4120 for (i = 0; i < count; i++) {
4121 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4122 freq[i].min, freq[i].max);
4123 }
4124
4125 os_free(wpa_s->global->p2p_disallow_freq);
4126 wpa_s->global->p2p_disallow_freq = freq;
4127 wpa_s->global->num_p2p_disallow_freq = count;
4128 wpas_p2p_update_channel_list(wpa_s);
4129 return 0;
4130}
4131
4132
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004133static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4134{
4135 char *param;
4136
4137 if (wpa_s->global->p2p == NULL)
4138 return -1;
4139
4140 param = os_strchr(cmd, ' ');
4141 if (param == NULL)
4142 return -1;
4143 *param++ = '\0';
4144
4145 if (os_strcmp(cmd, "discoverability") == 0) {
4146 p2p_set_client_discoverability(wpa_s->global->p2p,
4147 atoi(param));
4148 return 0;
4149 }
4150
4151 if (os_strcmp(cmd, "managed") == 0) {
4152 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4153 return 0;
4154 }
4155
4156 if (os_strcmp(cmd, "listen_channel") == 0) {
4157 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4158 atoi(param));
4159 }
4160
4161 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4162 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4163 os_strlen(param));
4164 }
4165
4166 if (os_strcmp(cmd, "noa") == 0) {
4167 char *pos;
4168 int count, start, duration;
4169 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4170 count = atoi(param);
4171 pos = os_strchr(param, ',');
4172 if (pos == NULL)
4173 return -1;
4174 pos++;
4175 start = atoi(pos);
4176 pos = os_strchr(pos, ',');
4177 if (pos == NULL)
4178 return -1;
4179 pos++;
4180 duration = atoi(pos);
4181 if (count < 0 || count > 255 || start < 0 || duration < 0)
4182 return -1;
4183 if (count == 0 && duration > 0)
4184 return -1;
4185 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4186 "start=%d duration=%d", count, start, duration);
4187 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4188 }
4189
4190 if (os_strcmp(cmd, "ps") == 0)
4191 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4192
4193 if (os_strcmp(cmd, "oppps") == 0)
4194 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4195
4196 if (os_strcmp(cmd, "ctwindow") == 0)
4197 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4198
4199 if (os_strcmp(cmd, "disabled") == 0) {
4200 wpa_s->global->p2p_disabled = atoi(param);
4201 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4202 wpa_s->global->p2p_disabled ?
4203 "disabled" : "enabled");
4204 if (wpa_s->global->p2p_disabled) {
4205 wpas_p2p_stop_find(wpa_s);
4206 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4207 p2p_flush(wpa_s->global->p2p);
4208 }
4209 return 0;
4210 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004211
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07004212 if (os_strcmp(cmd, "conc_pref") == 0) {
4213 if (os_strcmp(param, "sta") == 0)
4214 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4215 else if (os_strcmp(param, "p2p") == 0)
4216 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07004217 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07004218 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07004219 return -1;
4220 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07004221 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07004222 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07004223 return 0;
4224 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004225
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004226 if (os_strcmp(cmd, "force_long_sd") == 0) {
4227 wpa_s->force_long_sd = atoi(param);
4228 return 0;
4229 }
4230
4231 if (os_strcmp(cmd, "peer_filter") == 0) {
4232 u8 addr[ETH_ALEN];
4233 if (hwaddr_aton(param, addr))
4234 return -1;
4235 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4236 return 0;
4237 }
4238
4239 if (os_strcmp(cmd, "cross_connect") == 0)
4240 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4241
4242 if (os_strcmp(cmd, "go_apsd") == 0) {
4243 if (os_strcmp(param, "disable") == 0)
4244 wpa_s->set_ap_uapsd = 0;
4245 else {
4246 wpa_s->set_ap_uapsd = 1;
4247 wpa_s->ap_uapsd = atoi(param);
4248 }
4249 return 0;
4250 }
4251
4252 if (os_strcmp(cmd, "client_apsd") == 0) {
4253 if (os_strcmp(param, "disable") == 0)
4254 wpa_s->set_sta_uapsd = 0;
4255 else {
4256 int be, bk, vi, vo;
4257 char *pos;
4258 /* format: BE,BK,VI,VO;max SP Length */
4259 be = atoi(param);
4260 pos = os_strchr(param, ',');
4261 if (pos == NULL)
4262 return -1;
4263 pos++;
4264 bk = atoi(pos);
4265 pos = os_strchr(pos, ',');
4266 if (pos == NULL)
4267 return -1;
4268 pos++;
4269 vi = atoi(pos);
4270 pos = os_strchr(pos, ',');
4271 if (pos == NULL)
4272 return -1;
4273 pos++;
4274 vo = atoi(pos);
4275 /* ignore max SP Length for now */
4276
4277 wpa_s->set_sta_uapsd = 1;
4278 wpa_s->sta_uapsd = 0;
4279 if (be)
4280 wpa_s->sta_uapsd |= BIT(0);
4281 if (bk)
4282 wpa_s->sta_uapsd |= BIT(1);
4283 if (vi)
4284 wpa_s->sta_uapsd |= BIT(2);
4285 if (vo)
4286 wpa_s->sta_uapsd |= BIT(3);
4287 }
4288 return 0;
4289 }
4290
Dmitry Shmidt04949592012-07-19 12:16:46 -07004291 if (os_strcmp(cmd, "disallow_freq") == 0)
4292 return p2p_ctrl_disallow_freq(wpa_s, param);
4293
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004294 if (os_strcmp(cmd, "disc_int") == 0) {
4295 int min_disc_int, max_disc_int, max_disc_tu;
4296 char *pos;
4297
4298 pos = param;
4299
4300 min_disc_int = atoi(pos);
4301 pos = os_strchr(pos, ' ');
4302 if (pos == NULL)
4303 return -1;
4304 *pos++ = '\0';
4305
4306 max_disc_int = atoi(pos);
4307 pos = os_strchr(pos, ' ');
4308 if (pos == NULL)
4309 return -1;
4310 *pos++ = '\0';
4311
4312 max_disc_tu = atoi(pos);
4313
4314 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4315 max_disc_int, max_disc_tu);
4316 }
4317
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004318 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4319 cmd);
4320
4321 return -1;
4322}
4323
4324
4325static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4326{
4327 char *pos, *pos2;
4328 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4329
4330 if (cmd[0]) {
4331 pos = os_strchr(cmd, ' ');
4332 if (pos == NULL)
4333 return -1;
4334 *pos++ = '\0';
4335 dur1 = atoi(cmd);
4336
4337 pos2 = os_strchr(pos, ' ');
4338 if (pos2)
4339 *pos2++ = '\0';
4340 int1 = atoi(pos);
4341 } else
4342 pos2 = NULL;
4343
4344 if (pos2) {
4345 pos = os_strchr(pos2, ' ');
4346 if (pos == NULL)
4347 return -1;
4348 *pos++ = '\0';
4349 dur2 = atoi(pos2);
4350 int2 = atoi(pos);
4351 }
4352
4353 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
4354}
4355
4356
4357static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
4358{
4359 char *pos;
4360 unsigned int period = 0, interval = 0;
4361
4362 if (cmd[0]) {
4363 pos = os_strchr(cmd, ' ');
4364 if (pos == NULL)
4365 return -1;
4366 *pos++ = '\0';
4367 period = atoi(cmd);
4368 interval = atoi(pos);
4369 }
4370
4371 return wpas_p2p_ext_listen(wpa_s, period, interval);
4372}
4373
4374#endif /* CONFIG_P2P */
4375
4376
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004377#ifdef CONFIG_INTERWORKING
4378static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
4379{
4380 u8 bssid[ETH_ALEN];
4381 struct wpa_bss *bss;
4382
4383 if (hwaddr_aton(dst, bssid)) {
4384 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
4385 return -1;
4386 }
4387
4388 bss = wpa_bss_get_bssid(wpa_s, bssid);
4389 if (bss == NULL) {
4390 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4391 MAC2STR(bssid));
4392 return -1;
4393 }
4394
4395 return interworking_connect(wpa_s, bss);
4396}
4397
4398
4399static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4400{
4401 u8 dst_addr[ETH_ALEN];
4402 int used;
4403 char *pos;
4404#define MAX_ANQP_INFO_ID 100
4405 u16 id[MAX_ANQP_INFO_ID];
4406 size_t num_id = 0;
4407
4408 used = hwaddr_aton2(dst, dst_addr);
4409 if (used < 0)
4410 return -1;
4411 pos = dst + used;
4412 while (num_id < MAX_ANQP_INFO_ID) {
4413 id[num_id] = atoi(pos);
4414 if (id[num_id])
4415 num_id++;
4416 pos = os_strchr(pos + 1, ',');
4417 if (pos == NULL)
4418 break;
4419 pos++;
4420 }
4421
4422 if (num_id == 0)
4423 return -1;
4424
4425 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4426}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004427
4428
4429static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4430{
4431 u8 dst_addr[ETH_ALEN];
4432 struct wpabuf *advproto, *query = NULL;
4433 int used, ret = -1;
4434 char *pos, *end;
4435 size_t len;
4436
4437 used = hwaddr_aton2(cmd, dst_addr);
4438 if (used < 0)
4439 return -1;
4440
4441 pos = cmd + used;
4442 while (*pos == ' ')
4443 pos++;
4444
4445 /* Advertisement Protocol ID */
4446 end = os_strchr(pos, ' ');
4447 if (end)
4448 len = end - pos;
4449 else
4450 len = os_strlen(pos);
4451 if (len & 0x01)
4452 return -1;
4453 len /= 2;
4454 if (len == 0)
4455 return -1;
4456 advproto = wpabuf_alloc(len);
4457 if (advproto == NULL)
4458 return -1;
4459 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
4460 goto fail;
4461
4462 if (end) {
4463 /* Optional Query Request */
4464 pos = end + 1;
4465 while (*pos == ' ')
4466 pos++;
4467
4468 len = os_strlen(pos);
4469 if (len) {
4470 if (len & 0x01)
4471 goto fail;
4472 len /= 2;
4473 if (len == 0)
4474 goto fail;
4475 query = wpabuf_alloc(len);
4476 if (query == NULL)
4477 goto fail;
4478 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
4479 goto fail;
4480 }
4481 }
4482
4483 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
4484
4485fail:
4486 wpabuf_free(advproto);
4487 wpabuf_free(query);
4488
4489 return ret;
4490}
4491
4492
4493static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
4494 size_t buflen)
4495{
4496 u8 addr[ETH_ALEN];
4497 int dialog_token;
4498 int used;
4499 char *pos;
4500 size_t resp_len, start, requested_len;
4501
4502 if (!wpa_s->last_gas_resp)
4503 return -1;
4504
4505 used = hwaddr_aton2(cmd, addr);
4506 if (used < 0)
4507 return -1;
4508
4509 pos = cmd + used;
4510 while (*pos == ' ')
4511 pos++;
4512 dialog_token = atoi(pos);
4513
4514 if (os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) != 0 ||
4515 dialog_token != wpa_s->last_gas_dialog_token)
4516 return -1;
4517
4518 resp_len = wpabuf_len(wpa_s->last_gas_resp);
4519 start = 0;
4520 requested_len = resp_len;
4521
4522 pos = os_strchr(pos, ' ');
4523 if (pos) {
4524 start = atoi(pos);
4525 if (start > resp_len)
4526 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4527 pos = os_strchr(pos, ',');
4528 if (pos == NULL)
4529 return -1;
4530 pos++;
4531 requested_len = atoi(pos);
4532 if (start + requested_len > resp_len)
4533 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4534 }
4535
4536 if (requested_len * 2 + 1 > buflen)
4537 return os_snprintf(buf, buflen, "FAIL-Too long response");
4538
4539 return wpa_snprintf_hex(buf, buflen,
4540 wpabuf_head_u8(wpa_s->last_gas_resp) + start,
4541 requested_len);
4542}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004543#endif /* CONFIG_INTERWORKING */
4544
4545
Dmitry Shmidt04949592012-07-19 12:16:46 -07004546#ifdef CONFIG_HS20
4547
4548static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
4549{
4550 u8 dst_addr[ETH_ALEN];
4551 int used;
4552 char *pos;
4553 u32 subtypes = 0;
4554
4555 used = hwaddr_aton2(dst, dst_addr);
4556 if (used < 0)
4557 return -1;
4558 pos = dst + used;
4559 for (;;) {
4560 int num = atoi(pos);
4561 if (num <= 0 || num > 31)
4562 return -1;
4563 subtypes |= BIT(num);
4564 pos = os_strchr(pos + 1, ',');
4565 if (pos == NULL)
4566 break;
4567 pos++;
4568 }
4569
4570 if (subtypes == 0)
4571 return -1;
4572
4573 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
4574}
4575
4576
4577static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4578 const u8 *addr, const char *realm)
4579{
4580 u8 *buf;
4581 size_t rlen, len;
4582 int ret;
4583
4584 rlen = os_strlen(realm);
4585 len = 3 + rlen;
4586 buf = os_malloc(len);
4587 if (buf == NULL)
4588 return -1;
4589 buf[0] = 1; /* NAI Home Realm Count */
4590 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
4591 buf[2] = rlen;
4592 os_memcpy(buf + 3, realm, rlen);
4593
4594 ret = hs20_anqp_send_req(wpa_s, addr,
4595 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
4596 buf, len);
4597
4598 os_free(buf);
4599
4600 return ret;
4601}
4602
4603
4604static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4605 char *dst)
4606{
4607 struct wpa_cred *cred = wpa_s->conf->cred;
4608 u8 dst_addr[ETH_ALEN];
4609 int used;
4610 u8 *buf;
4611 size_t len;
4612 int ret;
4613
4614 used = hwaddr_aton2(dst, dst_addr);
4615 if (used < 0)
4616 return -1;
4617
4618 while (dst[used] == ' ')
4619 used++;
4620 if (os_strncmp(dst + used, "realm=", 6) == 0)
4621 return hs20_nai_home_realm_list(wpa_s, dst_addr,
4622 dst + used + 6);
4623
4624 len = os_strlen(dst + used);
4625
4626 if (len == 0 && cred && cred->realm)
4627 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
4628
4629 if (len % 1)
4630 return -1;
4631 len /= 2;
4632 buf = os_malloc(len);
4633 if (buf == NULL)
4634 return -1;
4635 if (hexstr2bin(dst + used, buf, len) < 0) {
4636 os_free(buf);
4637 return -1;
4638 }
4639
4640 ret = hs20_anqp_send_req(wpa_s, dst_addr,
4641 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
4642 buf, len);
4643 os_free(buf);
4644
4645 return ret;
4646}
4647
4648#endif /* CONFIG_HS20 */
4649
4650
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004651static int wpa_supplicant_ctrl_iface_sta_autoconnect(
4652 struct wpa_supplicant *wpa_s, char *cmd)
4653{
4654 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
4655 return 0;
4656}
4657
4658
Dmitry Shmidt04949592012-07-19 12:16:46 -07004659#ifdef CONFIG_AUTOSCAN
4660
4661static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
4662 char *cmd)
4663{
4664 enum wpa_states state = wpa_s->wpa_state;
4665 char *new_params = NULL;
4666
4667 if (os_strlen(cmd) > 0) {
4668 new_params = os_strdup(cmd);
4669 if (new_params == NULL)
4670 return -1;
4671 }
4672
4673 os_free(wpa_s->conf->autoscan);
4674 wpa_s->conf->autoscan = new_params;
4675
4676 if (wpa_s->conf->autoscan == NULL)
4677 autoscan_deinit(wpa_s);
4678 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
4679 autoscan_init(wpa_s, 1);
4680 else if (state == WPA_SCANNING)
4681 wpa_supplicant_reinit_autoscan(wpa_s);
4682
4683 return 0;
4684}
4685
4686#endif /* CONFIG_AUTOSCAN */
4687
4688
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004689#ifdef CONFIG_WNM
4690
4691static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
4692{
4693 int enter;
4694 int intval = 0;
4695 char *pos;
4696 int ret;
4697 struct wpabuf *tfs_req = NULL;
4698
4699 if (os_strncmp(cmd, "enter", 5) == 0)
4700 enter = 1;
4701 else if (os_strncmp(cmd, "exit", 4) == 0)
4702 enter = 0;
4703 else
4704 return -1;
4705
4706 pos = os_strstr(cmd, " interval=");
4707 if (pos)
4708 intval = atoi(pos + 10);
4709
4710 pos = os_strstr(cmd, " tfs_req=");
4711 if (pos) {
4712 char *end;
4713 size_t len;
4714 pos += 9;
4715 end = os_strchr(pos, ' ');
4716 if (end)
4717 len = end - pos;
4718 else
4719 len = os_strlen(pos);
4720 if (len & 1)
4721 return -1;
4722 len /= 2;
4723 tfs_req = wpabuf_alloc(len);
4724 if (tfs_req == NULL)
4725 return -1;
4726 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
4727 wpabuf_free(tfs_req);
4728 return -1;
4729 }
4730 }
4731
4732 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
4733 WNM_SLEEP_MODE_EXIT, intval,
4734 tfs_req);
4735 wpabuf_free(tfs_req);
4736
4737 return ret;
4738}
4739
4740#endif /* CONFIG_WNM */
4741
4742
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004743static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
4744 size_t buflen)
4745{
4746 struct wpa_signal_info si;
4747 int ret;
4748
4749 ret = wpa_drv_signal_poll(wpa_s, &si);
4750 if (ret)
4751 return -1;
4752
4753 ret = os_snprintf(buf, buflen, "RSSI=%d\nLINKSPEED=%d\n"
4754 "NOISE=%d\nFREQUENCY=%u\n",
4755 si.current_signal, si.current_txrate / 1000,
4756 si.current_noise, si.frequency);
4757 if (ret < 0 || (unsigned int) ret > buflen)
4758 return -1;
4759 return ret;
4760}
4761
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03004762
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07004763static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
4764 size_t buflen)
4765{
4766 struct hostap_sta_driver_data sta;
4767 int ret;
4768
4769 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
4770 if (ret)
4771 return -1;
4772
4773 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03004774 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
4775 if (ret < 0 || (size_t) ret > buflen)
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07004776 return -1;
4777 return ret;
4778}
4779
4780
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004781#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07004782static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
4783 char *buf, size_t buflen)
4784{
4785 int ret;
4786
4787 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
4788 if (ret == 0)
4789 ret = sprintf(buf, "%s\n", "OK");
4790 return ret;
4791}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004792#endif
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07004793
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004794
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004795char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
4796 char *buf, size_t *resp_len)
4797{
4798 char *reply;
4799 const int reply_size = 4096;
4800 int ctrl_rsp = 0;
4801 int reply_len;
4802
4803 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004804 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
4805 os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
4806 os_strncmp(buf, "NFC_RX_HANDOVER_SEL", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004807 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
4808 (const u8 *) buf, os_strlen(buf));
4809 } else {
4810 int level = MSG_DEBUG;
4811 if (os_strcmp(buf, "PING") == 0)
4812 level = MSG_EXCESSIVE;
4813 wpa_hexdump_ascii(level, "RX ctrl_iface",
4814 (const u8 *) buf, os_strlen(buf));
Dmitry Shmidtaa532512012-09-24 10:35:31 -07004815 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004816 }
4817
4818 reply = os_malloc(reply_size);
4819 if (reply == NULL) {
4820 *resp_len = 1;
4821 return NULL;
4822 }
4823
4824 os_memcpy(reply, "OK\n", 3);
4825 reply_len = 3;
4826
4827 if (os_strcmp(buf, "PING") == 0) {
4828 os_memcpy(reply, "PONG\n", 5);
4829 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004830 } else if (os_strcmp(buf, "IFNAME") == 0) {
4831 reply_len = os_strlen(wpa_s->ifname);
4832 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004833 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
4834 if (wpa_debug_reopen_file() < 0)
4835 reply_len = -1;
4836 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
4837 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
4838 } else if (os_strcmp(buf, "MIB") == 0) {
4839 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
4840 if (reply_len >= 0) {
4841 int res;
4842 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
4843 reply_size - reply_len);
4844 if (res < 0)
4845 reply_len = -1;
4846 else
4847 reply_len += res;
4848 }
4849 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
4850 reply_len = wpa_supplicant_ctrl_iface_status(
4851 wpa_s, buf + 6, reply, reply_size);
4852 } else if (os_strcmp(buf, "PMKSA") == 0) {
4853 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
4854 reply_size);
4855 } else if (os_strncmp(buf, "SET ", 4) == 0) {
4856 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
4857 reply_len = -1;
4858 } else if (os_strncmp(buf, "GET ", 4) == 0) {
4859 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
4860 reply, reply_size);
4861 } else if (os_strcmp(buf, "LOGON") == 0) {
4862 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
4863 } else if (os_strcmp(buf, "LOGOFF") == 0) {
4864 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
4865 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
4866 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4867 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004868 else
4869 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004870 } else if (os_strcmp(buf, "RECONNECT") == 0) {
4871 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4872 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004873 else if (wpa_s->disconnected)
4874 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004875#ifdef IEEE8021X_EAPOL
4876 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
4877 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
4878 reply_len = -1;
4879#endif /* IEEE8021X_EAPOL */
4880#ifdef CONFIG_PEERKEY
4881 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
4882 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
4883 reply_len = -1;
4884#endif /* CONFIG_PEERKEY */
4885#ifdef CONFIG_IEEE80211R
4886 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
4887 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
4888 reply_len = -1;
4889#endif /* CONFIG_IEEE80211R */
4890#ifdef CONFIG_WPS
4891 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
4892 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
4893 if (res == -2) {
4894 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
4895 reply_len = 17;
4896 } else if (res)
4897 reply_len = -1;
4898 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
4899 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
4900 if (res == -2) {
4901 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
4902 reply_len = 17;
4903 } else if (res)
4904 reply_len = -1;
4905 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
4906 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
4907 reply,
4908 reply_size);
4909 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
4910 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
4911 wpa_s, buf + 14, reply, reply_size);
4912 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
4913 if (wpas_wps_cancel(wpa_s))
4914 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004915#ifdef CONFIG_WPS_NFC
4916 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
4917 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
4918 reply_len = -1;
4919 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
4920 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
4921 reply_len = -1;
4922 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
4923 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
4924 wpa_s, buf + 14, reply, reply_size);
4925 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
4926 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
4927 buf + 17))
4928 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004929 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
4930 reply_len = wpas_ctrl_nfc_get_handover_req(
4931 wpa_s, buf + 21, reply, reply_size);
4932 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
4933 reply_len = wpas_ctrl_nfc_get_handover_sel(
4934 wpa_s, buf + 21, reply, reply_size);
4935 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_REQ ", 20) == 0) {
4936 reply_len = wpas_ctrl_nfc_rx_handover_req(
4937 wpa_s, buf + 20, reply, reply_size);
4938 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
4939 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s, buf + 20))
4940 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004941#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004942 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
4943 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
4944 reply_len = -1;
4945#ifdef CONFIG_AP
4946 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
4947 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
4948 wpa_s, buf + 11, reply, reply_size);
4949#endif /* CONFIG_AP */
4950#ifdef CONFIG_WPS_ER
4951 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
4952 if (wpas_wps_er_start(wpa_s, NULL))
4953 reply_len = -1;
4954 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
4955 if (wpas_wps_er_start(wpa_s, buf + 13))
4956 reply_len = -1;
4957 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
4958 if (wpas_wps_er_stop(wpa_s))
4959 reply_len = -1;
4960 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
4961 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
4962 reply_len = -1;
4963 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
4964 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
4965 if (ret == -2) {
4966 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
4967 reply_len = 17;
4968 } else if (ret == -3) {
4969 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
4970 reply_len = 18;
4971 } else if (ret == -4) {
4972 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
4973 reply_len = 20;
4974 } else if (ret)
4975 reply_len = -1;
4976 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
4977 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
4978 reply_len = -1;
4979 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
4980 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
4981 buf + 18))
4982 reply_len = -1;
4983 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
4984 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
4985 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004986#ifdef CONFIG_WPS_NFC
4987 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
4988 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
4989 wpa_s, buf + 24, reply, reply_size);
4990#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004991#endif /* CONFIG_WPS_ER */
4992#endif /* CONFIG_WPS */
4993#ifdef CONFIG_IBSS_RSN
4994 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
4995 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
4996 reply_len = -1;
4997#endif /* CONFIG_IBSS_RSN */
4998#ifdef CONFIG_P2P
4999 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
5000 if (p2p_ctrl_find(wpa_s, buf + 9))
5001 reply_len = -1;
5002 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
5003 if (p2p_ctrl_find(wpa_s, ""))
5004 reply_len = -1;
5005 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
5006 wpas_p2p_stop_find(wpa_s);
5007 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
5008 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
5009 reply_size);
5010 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
5011 if (p2p_ctrl_listen(wpa_s, buf + 11))
5012 reply_len = -1;
5013 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
5014 if (p2p_ctrl_listen(wpa_s, ""))
5015 reply_len = -1;
5016 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
5017 if (wpas_p2p_group_remove(wpa_s, buf + 17))
5018 reply_len = -1;
5019 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005020 if (wpas_p2p_group_add(wpa_s, 0, 0, 0))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005021 reply_len = -1;
5022 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
5023 if (p2p_ctrl_group_add(wpa_s, buf + 14))
5024 reply_len = -1;
5025 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
5026 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
5027 reply_len = -1;
5028 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
5029 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
5030 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
5031 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
5032 reply_size);
5033 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
5034 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
5035 reply_len = -1;
5036 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
5037 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
5038 reply_len = -1;
5039 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
Dmitry Shmidtb5e8f062012-08-08 10:56:33 -07005040#ifdef ANDROID_P2P
5041 wpas_p2p_sd_service_update(wpa_s, SRV_UPDATE);
5042#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005043 wpas_p2p_sd_service_update(wpa_s);
Dmitry Shmidtb5e8f062012-08-08 10:56:33 -07005044#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005045 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
5046 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
5047 reply_len = -1;
5048 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
5049 wpas_p2p_service_flush(wpa_s);
5050 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
5051 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
5052 reply_len = -1;
5053 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
5054 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
5055 reply_len = -1;
5056 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
5057 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
5058 reply_len = -1;
5059 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
5060 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
5061 reply_len = -1;
5062 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
5063 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
5064 reply_size);
5065 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
5066 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
5067 reply_len = -1;
5068 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
5069 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
5070 wpa_s->force_long_sd = 0;
5071 if (wpa_s->global->p2p)
5072 p2p_flush(wpa_s->global->p2p);
5073 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
5074 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
5075 reply_len = -1;
5076 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
5077 if (wpas_p2p_cancel(wpa_s))
5078 reply_len = -1;
5079 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
5080 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
5081 reply_len = -1;
5082 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
5083 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
5084 reply_len = -1;
5085 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
5086 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
5087 reply_len = -1;
5088 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
5089 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
5090 reply_len = -1;
5091#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005092#ifdef CONFIG_WIFI_DISPLAY
5093 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
5094 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
5095 reply_len = -1;
5096 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
5097 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
5098 reply, reply_size);
5099#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005100#ifdef CONFIG_INTERWORKING
5101 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
5102 if (interworking_fetch_anqp(wpa_s) < 0)
5103 reply_len = -1;
5104 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
5105 interworking_stop_fetch_anqp(wpa_s);
5106 } else if (os_strncmp(buf, "INTERWORKING_SELECT", 19) == 0) {
5107 if (interworking_select(wpa_s, os_strstr(buf + 19, "auto") !=
5108 NULL) < 0)
5109 reply_len = -1;
5110 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
5111 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
5112 reply_len = -1;
5113 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
5114 if (get_anqp(wpa_s, buf + 9) < 0)
5115 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005116 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
5117 if (gas_request(wpa_s, buf + 12) < 0)
5118 reply_len = -1;
5119 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
5120 reply_len = gas_response_get(wpa_s, buf + 17, reply,
5121 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005122#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005123#ifdef CONFIG_HS20
5124 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
5125 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
5126 reply_len = -1;
5127 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
5128 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
5129 reply_len = -1;
5130#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005131 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
5132 {
5133 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
5134 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
5135 reply_len = -1;
5136 else
5137 ctrl_rsp = 1;
5138 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
5139 if (wpa_supplicant_reload_configuration(wpa_s))
5140 reply_len = -1;
5141 } else if (os_strcmp(buf, "TERMINATE") == 0) {
5142 wpa_supplicant_terminate_proc(wpa_s->global);
5143 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
5144 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
5145 reply_len = -1;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07005146 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005147 reply_len = wpa_supplicant_ctrl_iface_blacklist(
5148 wpa_s, buf + 9, reply, reply_size);
5149 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
5150 reply_len = wpa_supplicant_ctrl_iface_log_level(
5151 wpa_s, buf + 9, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005152 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
5153 reply_len = wpa_supplicant_ctrl_iface_list_networks(
5154 wpa_s, reply, reply_size);
5155 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07005156#ifdef CONFIG_SME
5157 wpa_s->sme.prev_bssid_set = 0;
5158#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005159 wpa_s->reassociate = 0;
5160 wpa_s->disconnected = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005161 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005162 wpa_supplicant_cancel_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005163 wpa_supplicant_deauthenticate(wpa_s,
5164 WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005165 } else if (os_strcmp(buf, "SCAN") == 0 ||
5166 os_strncmp(buf, "SCAN ", 5) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005167 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5168 reply_len = -1;
5169 else {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005170 if (os_strlen(buf) > 4 &&
5171 os_strncasecmp(buf + 5, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt3a787e62013-01-17 10:32:35 -08005172 wpa_s->scan_res_handler = scan_only_handler;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005173 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005174 ((wpa_s->wpa_state <= WPA_SCANNING) ||
5175 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07005176 wpa_s->normal_scans = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005177 wpa_s->scan_req = MANUAL_SCAN_REQ;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005178 wpa_supplicant_req_scan(wpa_s, 0, 0);
5179 } else if (wpa_s->sched_scanning) {
5180 wpa_printf(MSG_DEBUG, "Stop ongoing "
5181 "sched_scan to allow requested "
5182 "full scan to proceed");
5183 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005184 wpa_s->scan_req = MANUAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005185 wpa_supplicant_req_scan(wpa_s, 0, 0);
5186 } else {
5187 wpa_printf(MSG_DEBUG, "Ongoing scan action - "
5188 "reject new request");
5189 reply_len = os_snprintf(reply, reply_size,
5190 "FAIL-BUSY\n");
5191 }
5192 }
5193 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
5194 reply_len = wpa_supplicant_ctrl_iface_scan_results(
5195 wpa_s, reply, reply_size);
5196 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
5197 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
5198 reply_len = -1;
5199 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
5200 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
5201 reply_len = -1;
5202 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
5203 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
5204 reply_len = -1;
5205 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
5206 reply_len = wpa_supplicant_ctrl_iface_add_network(
5207 wpa_s, reply, reply_size);
5208 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
5209 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
5210 reply_len = -1;
5211 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
5212 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
5213 reply_len = -1;
5214 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
5215 reply_len = wpa_supplicant_ctrl_iface_get_network(
5216 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005217 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
5218 reply_len = wpa_supplicant_ctrl_iface_list_creds(
5219 wpa_s, reply, reply_size);
5220 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
5221 reply_len = wpa_supplicant_ctrl_iface_add_cred(
5222 wpa_s, reply, reply_size);
5223 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
5224 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
5225 reply_len = -1;
5226 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
5227 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
5228 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005229#ifndef CONFIG_NO_CONFIG_WRITE
5230 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
5231 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
5232 reply_len = -1;
5233#endif /* CONFIG_NO_CONFIG_WRITE */
5234 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
5235 reply_len = wpa_supplicant_ctrl_iface_get_capability(
5236 wpa_s, buf + 15, reply, reply_size);
5237 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
5238 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
5239 reply_len = -1;
5240 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
5241 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
5242 reply_len = -1;
5243 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
5244 reply_len = wpa_supplicant_global_iface_list(
5245 wpa_s->global, reply, reply_size);
5246 } else if (os_strcmp(buf, "INTERFACES") == 0) {
5247 reply_len = wpa_supplicant_global_iface_interfaces(
5248 wpa_s->global, reply, reply_size);
5249 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
5250 reply_len = wpa_supplicant_ctrl_iface_bss(
5251 wpa_s, buf + 4, reply, reply_size);
5252#ifdef CONFIG_AP
5253 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
5254 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
5255 } else if (os_strncmp(buf, "STA ", 4) == 0) {
5256 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
5257 reply_size);
5258 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
5259 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
5260 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005261 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
5262 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
5263 reply_len = -1;
5264 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
5265 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
5266 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005267#endif /* CONFIG_AP */
5268 } else if (os_strcmp(buf, "SUSPEND") == 0) {
5269 wpas_notify_suspend(wpa_s->global);
5270 } else if (os_strcmp(buf, "RESUME") == 0) {
5271 wpas_notify_resume(wpa_s->global);
5272 } else if (os_strcmp(buf, "DROP_SA") == 0) {
5273 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
5274 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
5275 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
5276 reply_len = -1;
5277 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
5278 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
5279 reply_len = -1;
5280 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
5281 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
5282 reply_len = -1;
5283 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
5284 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
5285 buf + 17))
5286 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005287 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
5288 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
5289 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005290#ifdef CONFIG_TDLS
5291 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
5292 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
5293 reply_len = -1;
5294 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
5295 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
5296 reply_len = -1;
5297 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
5298 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
5299 reply_len = -1;
5300#endif /* CONFIG_TDLS */
5301 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
5302 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
5303 reply_size);
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07005304 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
5305 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
5306 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005307#ifdef CONFIG_AUTOSCAN
5308 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
5309 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
5310 reply_len = -1;
5311#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005312#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07005313 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
5314 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
5315 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005316#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005317 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08005318 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005319 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005320#ifdef CONFIG_WNM
5321 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
5322 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
5323 reply_len = -1;
5324#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005325 } else {
5326 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
5327 reply_len = 16;
5328 }
5329
5330 if (reply_len < 0) {
5331 os_memcpy(reply, "FAIL\n", 5);
5332 reply_len = 5;
5333 }
5334
5335 if (ctrl_rsp)
5336 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5337
5338 *resp_len = reply_len;
5339 return reply;
5340}
5341
5342
5343static int wpa_supplicant_global_iface_add(struct wpa_global *global,
5344 char *cmd)
5345{
5346 struct wpa_interface iface;
5347 char *pos;
5348
5349 /*
5350 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
5351 * TAB<bridge_ifname>
5352 */
5353 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
5354
5355 os_memset(&iface, 0, sizeof(iface));
5356
5357 do {
5358 iface.ifname = pos = cmd;
5359 pos = os_strchr(pos, '\t');
5360 if (pos)
5361 *pos++ = '\0';
5362 if (iface.ifname[0] == '\0')
5363 return -1;
5364 if (pos == NULL)
5365 break;
5366
5367 iface.confname = pos;
5368 pos = os_strchr(pos, '\t');
5369 if (pos)
5370 *pos++ = '\0';
5371 if (iface.confname[0] == '\0')
5372 iface.confname = NULL;
5373 if (pos == NULL)
5374 break;
5375
5376 iface.driver = pos;
5377 pos = os_strchr(pos, '\t');
5378 if (pos)
5379 *pos++ = '\0';
5380 if (iface.driver[0] == '\0')
5381 iface.driver = NULL;
5382 if (pos == NULL)
5383 break;
5384
5385 iface.ctrl_interface = pos;
5386 pos = os_strchr(pos, '\t');
5387 if (pos)
5388 *pos++ = '\0';
5389 if (iface.ctrl_interface[0] == '\0')
5390 iface.ctrl_interface = NULL;
5391 if (pos == NULL)
5392 break;
5393
5394 iface.driver_param = pos;
5395 pos = os_strchr(pos, '\t');
5396 if (pos)
5397 *pos++ = '\0';
5398 if (iface.driver_param[0] == '\0')
5399 iface.driver_param = NULL;
5400 if (pos == NULL)
5401 break;
5402
5403 iface.bridge_ifname = pos;
5404 pos = os_strchr(pos, '\t');
5405 if (pos)
5406 *pos++ = '\0';
5407 if (iface.bridge_ifname[0] == '\0')
5408 iface.bridge_ifname = NULL;
5409 if (pos == NULL)
5410 break;
5411 } while (0);
5412
5413 if (wpa_supplicant_get_iface(global, iface.ifname))
5414 return -1;
5415
5416 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
5417}
5418
5419
5420static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
5421 char *cmd)
5422{
5423 struct wpa_supplicant *wpa_s;
5424
5425 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
5426
5427 wpa_s = wpa_supplicant_get_iface(global, cmd);
5428 if (wpa_s == NULL)
5429 return -1;
Dmitry Shmidte15c7b52011-08-03 15:04:35 -07005430 return wpa_supplicant_remove_iface(global, wpa_s, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005431}
5432
5433
5434static void wpa_free_iface_info(struct wpa_interface_info *iface)
5435{
5436 struct wpa_interface_info *prev;
5437
5438 while (iface) {
5439 prev = iface;
5440 iface = iface->next;
5441
5442 os_free(prev->ifname);
5443 os_free(prev->desc);
5444 os_free(prev);
5445 }
5446}
5447
5448
5449static int wpa_supplicant_global_iface_list(struct wpa_global *global,
5450 char *buf, int len)
5451{
5452 int i, res;
5453 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
5454 char *pos, *end;
5455
5456 for (i = 0; wpa_drivers[i]; i++) {
5457 struct wpa_driver_ops *drv = wpa_drivers[i];
5458 if (drv->get_interfaces == NULL)
5459 continue;
5460 tmp = drv->get_interfaces(global->drv_priv[i]);
5461 if (tmp == NULL)
5462 continue;
5463
5464 if (last == NULL)
5465 iface = last = tmp;
5466 else
5467 last->next = tmp;
5468 while (last->next)
5469 last = last->next;
5470 }
5471
5472 pos = buf;
5473 end = buf + len;
5474 for (tmp = iface; tmp; tmp = tmp->next) {
5475 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
5476 tmp->drv_name, tmp->ifname,
5477 tmp->desc ? tmp->desc : "");
5478 if (res < 0 || res >= end - pos) {
5479 *pos = '\0';
5480 break;
5481 }
5482 pos += res;
5483 }
5484
5485 wpa_free_iface_info(iface);
5486
5487 return pos - buf;
5488}
5489
5490
5491static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
5492 char *buf, int len)
5493{
5494 int res;
5495 char *pos, *end;
5496 struct wpa_supplicant *wpa_s;
5497
5498 wpa_s = global->ifaces;
5499 pos = buf;
5500 end = buf + len;
5501
5502 while (wpa_s) {
5503 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
5504 if (res < 0 || res >= end - pos) {
5505 *pos = '\0';
5506 break;
5507 }
5508 pos += res;
5509 wpa_s = wpa_s->next;
5510 }
5511 return pos - buf;
5512}
5513
5514
5515char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
5516 char *buf, size_t *resp_len)
5517{
5518 char *reply;
5519 const int reply_size = 2048;
5520 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005521 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005522
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005523 if (os_strcmp(buf, "PING") == 0)
5524 level = MSG_EXCESSIVE;
5525 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005526 (const u8 *) buf, os_strlen(buf));
5527
5528 reply = os_malloc(reply_size);
5529 if (reply == NULL) {
5530 *resp_len = 1;
5531 return NULL;
5532 }
5533
5534 os_memcpy(reply, "OK\n", 3);
5535 reply_len = 3;
5536
5537 if (os_strcmp(buf, "PING") == 0) {
5538 os_memcpy(reply, "PONG\n", 5);
5539 reply_len = 5;
5540 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
5541 if (wpa_supplicant_global_iface_add(global, buf + 14))
5542 reply_len = -1;
5543 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
5544 if (wpa_supplicant_global_iface_remove(global, buf + 17))
5545 reply_len = -1;
5546 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
5547 reply_len = wpa_supplicant_global_iface_list(
5548 global, reply, reply_size);
5549 } else if (os_strcmp(buf, "INTERFACES") == 0) {
5550 reply_len = wpa_supplicant_global_iface_interfaces(
5551 global, reply, reply_size);
5552 } else if (os_strcmp(buf, "TERMINATE") == 0) {
5553 wpa_supplicant_terminate_proc(global);
5554 } else if (os_strcmp(buf, "SUSPEND") == 0) {
5555 wpas_notify_suspend(global);
5556 } else if (os_strcmp(buf, "RESUME") == 0) {
5557 wpas_notify_resume(global);
5558 } else {
5559 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
5560 reply_len = 16;
5561 }
5562
5563 if (reply_len < 0) {
5564 os_memcpy(reply, "FAIL\n", 5);
5565 reply_len = 5;
5566 }
5567
5568 *resp_len = reply_len;
5569 return reply;
5570}