]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant / Control interface (shared code for all backends) | |
207ef3fb | 3 | * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi> |
6fc6879b JM |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License version 2 as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * Alternatively, this software may be distributed under the terms of BSD | |
10 | * license. | |
11 | * | |
12 | * See README and COPYING for more details. | |
13 | */ | |
14 | ||
3a068632 | 15 | #include "utils/includes.h" |
6fc6879b | 16 | |
3a068632 JM |
17 | #include "utils/common.h" |
18 | #include "utils/eloop.h" | |
acec8d32 | 19 | #include "common/version.h" |
3a068632 JM |
20 | #include "common/ieee802_11_defs.h" |
21 | #include "common/wpa_ctrl.h" | |
22 | #include "eap_peer/eap.h" | |
23 | #include "eapol_supp/eapol_supp_sm.h" | |
3acb5005 | 24 | #include "rsn_supp/wpa.h" |
3a068632 JM |
25 | #include "rsn_supp/preauth.h" |
26 | #include "rsn_supp/pmksa_cache.h" | |
27 | #include "l2_packet/l2_packet.h" | |
28 | #include "wps/wps.h" | |
6fc6879b | 29 | #include "config.h" |
6fc6879b | 30 | #include "wpa_supplicant_i.h" |
2d5b792d | 31 | #include "driver_i.h" |
fcc60db4 | 32 | #include "wps_supplicant.h" |
11ef8d35 | 33 | #include "ibss_rsn.h" |
3ec97afe | 34 | #include "ap.h" |
b563b388 JM |
35 | #include "p2p_supplicant.h" |
36 | #include "p2p/p2p.h" | |
8bac466b | 37 | #include "notify.h" |
3a068632 | 38 | #include "bss.h" |
9ba9fa07 | 39 | #include "scan.h" |
3a068632 | 40 | #include "ctrl_iface.h" |
6fc6879b | 41 | |
c5121837 | 42 | extern struct wpa_driver_ops *wpa_drivers[]; |
2d5b792d | 43 | |
4b4a8ae5 JM |
44 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
45 | char *buf, int len); | |
6fc6879b JM |
46 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
47 | char *buf, int len); | |
48 | ||
49 | ||
50 | static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, | |
51 | char *cmd) | |
52 | { | |
53 | char *value; | |
54 | int ret = 0; | |
55 | ||
56 | value = os_strchr(cmd, ' '); | |
57 | if (value == NULL) | |
58 | return -1; | |
59 | *value++ = '\0'; | |
60 | ||
61 | wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value); | |
62 | if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) { | |
63 | eapol_sm_configure(wpa_s->eapol, | |
64 | atoi(value), -1, -1, -1); | |
65 | } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) { | |
66 | eapol_sm_configure(wpa_s->eapol, | |
67 | -1, atoi(value), -1, -1); | |
68 | } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) { | |
69 | eapol_sm_configure(wpa_s->eapol, | |
70 | -1, -1, atoi(value), -1); | |
71 | } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) { | |
72 | eapol_sm_configure(wpa_s->eapol, | |
73 | -1, -1, -1, atoi(value)); | |
74 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) { | |
75 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, | |
76 | atoi(value))) | |
77 | ret = -1; | |
78 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == | |
79 | 0) { | |
80 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, | |
81 | atoi(value))) | |
82 | ret = -1; | |
83 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) { | |
84 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value))) | |
85 | ret = -1; | |
42f50264 JM |
86 | } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) { |
87 | wpa_s->wps_fragment_size = atoi(value); | |
b4e34f2f JM |
88 | #ifdef CONFIG_WPS_TESTING |
89 | } else if (os_strcasecmp(cmd, "wps_version_number") == 0) { | |
90 | long int val; | |
91 | val = strtol(value, NULL, 0); | |
92 | if (val < 0 || val > 0xff) { | |
93 | ret = -1; | |
94 | wpa_printf(MSG_DEBUG, "WPS: Invalid " | |
95 | "wps_version_number %ld", val); | |
96 | } else { | |
97 | wps_version_number = val; | |
98 | wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS " | |
99 | "version %u.%u", | |
100 | (wps_version_number & 0xf0) >> 4, | |
101 | wps_version_number & 0x0f); | |
102 | } | |
103 | } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) { | |
104 | wps_testing_dummy_cred = atoi(value); | |
105 | wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d", | |
106 | wps_testing_dummy_cred); | |
107 | #endif /* CONFIG_WPS_TESTING */ | |
b6c79a99 JM |
108 | } else if (os_strcasecmp(cmd, "ampdu") == 0) { |
109 | if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0) | |
110 | ret = -1; | |
5b0e6ece JM |
111 | #ifdef CONFIG_TDLS_TESTING |
112 | } else if (os_strcasecmp(cmd, "tdls_testing") == 0) { | |
113 | extern unsigned int tdls_testing; | |
114 | tdls_testing = strtol(value, NULL, 0); | |
115 | wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing); | |
116 | #endif /* CONFIG_TDLS_TESTING */ | |
b8f64582 JM |
117 | #ifdef CONFIG_TDLS |
118 | } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) { | |
119 | int disabled = atoi(value); | |
120 | wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled); | |
121 | if (disabled) { | |
122 | if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0) | |
123 | ret = -1; | |
124 | } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0) | |
125 | ret = -1; | |
126 | wpa_tdls_enable(wpa_s->wpa, !disabled); | |
127 | #endif /* CONFIG_TDLS */ | |
611aea7d JM |
128 | } else { |
129 | value[-1] = '='; | |
130 | ret = wpa_config_process_global(wpa_s->conf, cmd, -1); | |
131 | if (ret == 0) | |
132 | wpa_supplicant_update_config(wpa_s); | |
133 | } | |
6fc6879b JM |
134 | |
135 | return ret; | |
136 | } | |
137 | ||
138 | ||
acec8d32 JM |
139 | static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s, |
140 | char *cmd, char *buf, size_t buflen) | |
141 | { | |
142 | int res; | |
143 | ||
144 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd); | |
145 | ||
146 | if (os_strcmp(cmd, "version") == 0) { | |
147 | res = os_snprintf(buf, buflen, "%s", VERSION_STR); | |
148 | if (res < 0 || (unsigned int) res >= buflen) | |
149 | return -1; | |
150 | return res; | |
151 | } | |
152 | ||
153 | return -1; | |
154 | } | |
155 | ||
156 | ||
ec717917 | 157 | #ifdef IEEE8021X_EAPOL |
6fc6879b JM |
158 | static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s, |
159 | char *addr) | |
160 | { | |
161 | u8 bssid[ETH_ALEN]; | |
162 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
163 | ||
164 | if (hwaddr_aton(addr, bssid)) { | |
165 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address " | |
166 | "'%s'", addr); | |
167 | return -1; | |
168 | } | |
169 | ||
170 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid)); | |
171 | rsn_preauth_deinit(wpa_s->wpa); | |
172 | if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL)) | |
173 | return -1; | |
174 | ||
175 | return 0; | |
176 | } | |
ec717917 | 177 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
178 | |
179 | ||
180 | #ifdef CONFIG_PEERKEY | |
181 | /* MLME-STKSTART.request(peer) */ | |
182 | static int wpa_supplicant_ctrl_iface_stkstart( | |
183 | struct wpa_supplicant *wpa_s, char *addr) | |
184 | { | |
185 | u8 peer[ETH_ALEN]; | |
186 | ||
187 | if (hwaddr_aton(addr, peer)) { | |
188 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid " | |
a7b6c422 | 189 | "address '%s'", addr); |
6fc6879b JM |
190 | return -1; |
191 | } | |
192 | ||
193 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR, | |
194 | MAC2STR(peer)); | |
195 | ||
196 | return wpa_sm_stkstart(wpa_s->wpa, peer); | |
197 | } | |
198 | #endif /* CONFIG_PEERKEY */ | |
199 | ||
200 | ||
281ff0aa GP |
201 | #ifdef CONFIG_TDLS |
202 | ||
203 | static int wpa_supplicant_ctrl_iface_tdls_discover( | |
204 | struct wpa_supplicant *wpa_s, char *addr) | |
205 | { | |
206 | u8 peer[ETH_ALEN]; | |
207 | ||
208 | if (hwaddr_aton(addr, peer)) { | |
209 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid " | |
210 | "address '%s'", addr); | |
211 | return -1; | |
212 | } | |
213 | ||
214 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR, | |
215 | MAC2STR(peer)); | |
216 | ||
217 | return wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); | |
218 | } | |
219 | ||
220 | ||
221 | static int wpa_supplicant_ctrl_iface_tdls_setup( | |
222 | struct wpa_supplicant *wpa_s, char *addr) | |
223 | { | |
224 | u8 peer[ETH_ALEN]; | |
94377fbc | 225 | int ret; |
281ff0aa GP |
226 | |
227 | if (hwaddr_aton(addr, peer)) { | |
228 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid " | |
229 | "address '%s'", addr); | |
230 | return -1; | |
231 | } | |
232 | ||
233 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR, | |
234 | MAC2STR(peer)); | |
235 | ||
94377fbc JM |
236 | ret = wpa_tdls_reneg(wpa_s->wpa, peer); |
237 | if (ret) | |
238 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | |
239 | return ret; | |
281ff0aa GP |
240 | } |
241 | ||
242 | ||
243 | static int wpa_supplicant_ctrl_iface_tdls_teardown( | |
244 | struct wpa_supplicant *wpa_s, char *addr) | |
245 | { | |
246 | u8 peer[ETH_ALEN]; | |
247 | ||
248 | if (hwaddr_aton(addr, peer)) { | |
249 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid " | |
250 | "address '%s'", addr); | |
251 | return -1; | |
252 | } | |
253 | ||
254 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR, | |
255 | MAC2STR(peer)); | |
256 | ||
257 | return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); | |
258 | } | |
259 | ||
260 | #endif /* CONFIG_TDLS */ | |
261 | ||
262 | ||
6fc6879b JM |
263 | #ifdef CONFIG_IEEE80211R |
264 | static int wpa_supplicant_ctrl_iface_ft_ds( | |
265 | struct wpa_supplicant *wpa_s, char *addr) | |
266 | { | |
267 | u8 target_ap[ETH_ALEN]; | |
76b7981d JM |
268 | struct wpa_bss *bss; |
269 | const u8 *mdie; | |
6fc6879b JM |
270 | |
271 | if (hwaddr_aton(addr, target_ap)) { | |
272 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid " | |
a7b6c422 | 273 | "address '%s'", addr); |
6fc6879b JM |
274 | return -1; |
275 | } | |
276 | ||
277 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap)); | |
278 | ||
76b7981d JM |
279 | bss = wpa_bss_get_bssid(wpa_s, target_ap); |
280 | if (bss) | |
281 | mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); | |
282 | else | |
283 | mdie = NULL; | |
284 | ||
285 | return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie); | |
6fc6879b JM |
286 | } |
287 | #endif /* CONFIG_IEEE80211R */ | |
288 | ||
289 | ||
fcc60db4 JM |
290 | #ifdef CONFIG_WPS |
291 | static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s, | |
292 | char *cmd) | |
293 | { | |
3ec97afe | 294 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
ceb34f25 | 295 | #ifdef CONFIG_P2P |
634ce802 | 296 | u8 p2p_dev_addr[ETH_ALEN]; |
ceb34f25 | 297 | #endif /* CONFIG_P2P */ |
634ce802 JM |
298 | #ifdef CONFIG_AP |
299 | u8 *_p2p_dev_addr = NULL; | |
300 | #endif /* CONFIG_AP */ | |
fcc60db4 | 301 | |
d601247c | 302 | if (cmd == NULL || os_strcmp(cmd, "any") == 0) { |
3ec97afe | 303 | _bssid = NULL; |
d601247c JM |
304 | #ifdef CONFIG_P2P |
305 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | |
306 | if (hwaddr_aton(cmd + 13, p2p_dev_addr)) { | |
307 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid " | |
308 | "P2P Device Address '%s'", | |
309 | cmd + 13); | |
310 | return -1; | |
311 | } | |
312 | _p2p_dev_addr = p2p_dev_addr; | |
313 | #endif /* CONFIG_P2P */ | |
314 | } else if (hwaddr_aton(cmd, bssid)) { | |
fcc60db4 JM |
315 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'", |
316 | cmd); | |
317 | return -1; | |
318 | } | |
319 | ||
3ec97afe JM |
320 | #ifdef CONFIG_AP |
321 | if (wpa_s->ap_iface) | |
d601247c | 322 | return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr); |
3ec97afe JM |
323 | #endif /* CONFIG_AP */ |
324 | ||
9fa243b2 | 325 | return wpas_wps_start_pbc(wpa_s, _bssid, 0); |
fcc60db4 JM |
326 | } |
327 | ||
328 | ||
329 | static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, | |
330 | char *cmd, char *buf, | |
331 | size_t buflen) | |
332 | { | |
333 | u8 bssid[ETH_ALEN], *_bssid = bssid; | |
334 | char *pin; | |
335 | int ret; | |
336 | ||
337 | pin = os_strchr(cmd, ' '); | |
338 | if (pin) | |
339 | *pin++ = '\0'; | |
340 | ||
341 | if (os_strcmp(cmd, "any") == 0) | |
342 | _bssid = NULL; | |
98aa7ca5 JM |
343 | else if (os_strcmp(cmd, "get") == 0) { |
344 | ret = wps_generate_pin(); | |
345 | goto done; | |
346 | } else if (hwaddr_aton(cmd, bssid)) { | |
3c1e2765 | 347 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'", |
fcc60db4 JM |
348 | cmd); |
349 | return -1; | |
350 | } | |
351 | ||
3ec97afe JM |
352 | #ifdef CONFIG_AP |
353 | if (wpa_s->ap_iface) | |
354 | return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, | |
355 | buf, buflen); | |
356 | #endif /* CONFIG_AP */ | |
357 | ||
fcc60db4 | 358 | if (pin) { |
3c5126a4 JM |
359 | ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0, |
360 | DEV_PW_DEFAULT); | |
fcc60db4 JM |
361 | if (ret < 0) |
362 | return -1; | |
363 | ret = os_snprintf(buf, buflen, "%s", pin); | |
364 | if (ret < 0 || (size_t) ret >= buflen) | |
365 | return -1; | |
366 | return ret; | |
367 | } | |
368 | ||
3c5126a4 | 369 | ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT); |
fcc60db4 JM |
370 | if (ret < 0) |
371 | return -1; | |
372 | ||
98aa7ca5 | 373 | done: |
fcc60db4 JM |
374 | /* Return the generated PIN */ |
375 | ret = os_snprintf(buf, buflen, "%08d", ret); | |
376 | if (ret < 0 || (size_t) ret >= buflen) | |
377 | return -1; | |
378 | return ret; | |
379 | } | |
380 | ||
381 | ||
3981cb3c JM |
382 | static int wpa_supplicant_ctrl_iface_wps_check_pin( |
383 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
384 | { | |
385 | char pin[9]; | |
386 | size_t len; | |
387 | char *pos; | |
388 | int ret; | |
389 | ||
390 | wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN", | |
391 | (u8 *) cmd, os_strlen(cmd)); | |
392 | for (pos = cmd, len = 0; *pos != '\0'; pos++) { | |
393 | if (*pos < '0' || *pos > '9') | |
394 | continue; | |
395 | pin[len++] = *pos; | |
396 | if (len == 9) { | |
397 | wpa_printf(MSG_DEBUG, "WPS: Too long PIN"); | |
398 | return -1; | |
399 | } | |
400 | } | |
401 | if (len != 4 && len != 8) { | |
402 | wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len); | |
403 | return -1; | |
404 | } | |
405 | pin[len] = '\0'; | |
406 | ||
407 | if (len == 8) { | |
408 | unsigned int pin_val; | |
409 | pin_val = atoi(pin); | |
410 | if (!wps_pin_valid(pin_val)) { | |
411 | wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit"); | |
412 | ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n"); | |
413 | if (ret < 0 || (size_t) ret >= buflen) | |
414 | return -1; | |
415 | return ret; | |
416 | } | |
417 | } | |
418 | ||
419 | ret = os_snprintf(buf, buflen, "%s", pin); | |
420 | if (ret < 0 || (size_t) ret >= buflen) | |
421 | return -1; | |
422 | ||
423 | return ret; | |
424 | } | |
425 | ||
426 | ||
116f7bb0 | 427 | #ifdef CONFIG_WPS_OOB |
46bdb83a MH |
428 | static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s, |
429 | char *cmd) | |
430 | { | |
e1ee6b60 | 431 | char *path, *method, *name; |
46bdb83a MH |
432 | |
433 | path = os_strchr(cmd, ' '); | |
434 | if (path == NULL) | |
435 | return -1; | |
436 | *path++ = '\0'; | |
437 | ||
438 | method = os_strchr(path, ' '); | |
439 | if (method == NULL) | |
440 | return -1; | |
441 | *method++ = '\0'; | |
442 | ||
e1ee6b60 MH |
443 | name = os_strchr(method, ' '); |
444 | if (name != NULL) | |
445 | *name++ = '\0'; | |
446 | ||
447 | return wpas_wps_start_oob(wpa_s, cmd, path, method, name); | |
46bdb83a | 448 | } |
116f7bb0 | 449 | #endif /* CONFIG_WPS_OOB */ |
46bdb83a MH |
450 | |
451 | ||
fcc60db4 JM |
452 | static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s, |
453 | char *cmd) | |
454 | { | |
129eb428 | 455 | u8 bssid[ETH_ALEN]; |
fcc60db4 | 456 | char *pin; |
52eb293d JM |
457 | char *new_ssid; |
458 | char *new_auth; | |
459 | char *new_encr; | |
460 | char *new_key; | |
461 | struct wps_new_ap_settings ap; | |
fcc60db4 JM |
462 | |
463 | pin = os_strchr(cmd, ' '); | |
464 | if (pin == NULL) | |
465 | return -1; | |
466 | *pin++ = '\0'; | |
467 | ||
129eb428 | 468 | if (hwaddr_aton(cmd, bssid)) { |
fcc60db4 JM |
469 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'", |
470 | cmd); | |
471 | return -1; | |
472 | } | |
473 | ||
52eb293d JM |
474 | new_ssid = os_strchr(pin, ' '); |
475 | if (new_ssid == NULL) | |
129eb428 | 476 | return wpas_wps_start_reg(wpa_s, bssid, pin, NULL); |
52eb293d JM |
477 | *new_ssid++ = '\0'; |
478 | ||
479 | new_auth = os_strchr(new_ssid, ' '); | |
480 | if (new_auth == NULL) | |
481 | return -1; | |
482 | *new_auth++ = '\0'; | |
483 | ||
484 | new_encr = os_strchr(new_auth, ' '); | |
485 | if (new_encr == NULL) | |
486 | return -1; | |
487 | *new_encr++ = '\0'; | |
488 | ||
489 | new_key = os_strchr(new_encr, ' '); | |
490 | if (new_key == NULL) | |
491 | return -1; | |
492 | *new_key++ = '\0'; | |
493 | ||
494 | os_memset(&ap, 0, sizeof(ap)); | |
495 | ap.ssid_hex = new_ssid; | |
496 | ap.auth = new_auth; | |
497 | ap.encr = new_encr; | |
498 | ap.key_hex = new_key; | |
129eb428 | 499 | return wpas_wps_start_reg(wpa_s, bssid, pin, &ap); |
fcc60db4 | 500 | } |
72df2f5f JM |
501 | |
502 | ||
70d84f11 JM |
503 | #ifdef CONFIG_AP |
504 | static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s, | |
505 | char *cmd, char *buf, | |
506 | size_t buflen) | |
507 | { | |
508 | int timeout = 300; | |
509 | char *pos; | |
510 | const char *pin_txt; | |
511 | ||
512 | if (!wpa_s->ap_iface) | |
513 | return -1; | |
514 | ||
515 | pos = os_strchr(cmd, ' '); | |
516 | if (pos) | |
517 | *pos++ = '\0'; | |
518 | ||
519 | if (os_strcmp(cmd, "disable") == 0) { | |
520 | wpas_wps_ap_pin_disable(wpa_s); | |
521 | return os_snprintf(buf, buflen, "OK\n"); | |
522 | } | |
523 | ||
524 | if (os_strcmp(cmd, "random") == 0) { | |
525 | if (pos) | |
526 | timeout = atoi(pos); | |
527 | pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout); | |
528 | if (pin_txt == NULL) | |
529 | return -1; | |
530 | return os_snprintf(buf, buflen, "%s", pin_txt); | |
531 | } | |
532 | ||
533 | if (os_strcmp(cmd, "get") == 0) { | |
534 | pin_txt = wpas_wps_ap_pin_get(wpa_s); | |
535 | if (pin_txt == NULL) | |
536 | return -1; | |
537 | return os_snprintf(buf, buflen, "%s", pin_txt); | |
538 | } | |
539 | ||
540 | if (os_strcmp(cmd, "set") == 0) { | |
541 | char *pin; | |
542 | if (pos == NULL) | |
543 | return -1; | |
544 | pin = pos; | |
545 | pos = os_strchr(pos, ' '); | |
546 | if (pos) { | |
547 | *pos++ = '\0'; | |
548 | timeout = atoi(pos); | |
549 | } | |
550 | if (os_strlen(pin) > buflen) | |
551 | return -1; | |
552 | if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0) | |
553 | return -1; | |
554 | return os_snprintf(buf, buflen, "%s", pin); | |
555 | } | |
556 | ||
557 | return -1; | |
558 | } | |
559 | #endif /* CONFIG_AP */ | |
560 | ||
561 | ||
72df2f5f JM |
562 | #ifdef CONFIG_WPS_ER |
563 | static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s, | |
564 | char *cmd) | |
565 | { | |
31fcea93 JM |
566 | char *uuid = cmd, *pin, *pos; |
567 | u8 addr_buf[ETH_ALEN], *addr = NULL; | |
72df2f5f JM |
568 | pin = os_strchr(uuid, ' '); |
569 | if (pin == NULL) | |
570 | return -1; | |
571 | *pin++ = '\0'; | |
31fcea93 JM |
572 | pos = os_strchr(pin, ' '); |
573 | if (pos) { | |
574 | *pos++ = '\0'; | |
575 | if (hwaddr_aton(pos, addr_buf) == 0) | |
576 | addr = addr_buf; | |
577 | } | |
578 | return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin); | |
72df2f5f | 579 | } |
e64dcfd5 JM |
580 | |
581 | ||
582 | static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s, | |
583 | char *cmd) | |
584 | { | |
585 | char *uuid = cmd, *pin; | |
586 | pin = os_strchr(uuid, ' '); | |
587 | if (pin == NULL) | |
588 | return -1; | |
589 | *pin++ = '\0'; | |
590 | return wpas_wps_er_learn(wpa_s, uuid, pin); | |
591 | } | |
7d6640a6 JM |
592 | |
593 | ||
ef10f473 JM |
594 | static int wpa_supplicant_ctrl_iface_wps_er_set_config( |
595 | struct wpa_supplicant *wpa_s, char *cmd) | |
596 | { | |
597 | char *uuid = cmd, *id; | |
598 | id = os_strchr(uuid, ' '); | |
599 | if (id == NULL) | |
600 | return -1; | |
601 | *id++ = '\0'; | |
602 | return wpas_wps_er_set_config(wpa_s, uuid, atoi(id)); | |
603 | } | |
604 | ||
605 | ||
7d6640a6 JM |
606 | static int wpa_supplicant_ctrl_iface_wps_er_config( |
607 | struct wpa_supplicant *wpa_s, char *cmd) | |
608 | { | |
609 | char *pin; | |
610 | char *new_ssid; | |
611 | char *new_auth; | |
612 | char *new_encr; | |
613 | char *new_key; | |
614 | struct wps_new_ap_settings ap; | |
615 | ||
616 | pin = os_strchr(cmd, ' '); | |
617 | if (pin == NULL) | |
618 | return -1; | |
619 | *pin++ = '\0'; | |
620 | ||
621 | new_ssid = os_strchr(pin, ' '); | |
622 | if (new_ssid == NULL) | |
623 | return -1; | |
624 | *new_ssid++ = '\0'; | |
625 | ||
626 | new_auth = os_strchr(new_ssid, ' '); | |
627 | if (new_auth == NULL) | |
628 | return -1; | |
629 | *new_auth++ = '\0'; | |
630 | ||
631 | new_encr = os_strchr(new_auth, ' '); | |
632 | if (new_encr == NULL) | |
633 | return -1; | |
634 | *new_encr++ = '\0'; | |
635 | ||
636 | new_key = os_strchr(new_encr, ' '); | |
637 | if (new_key == NULL) | |
638 | return -1; | |
639 | *new_key++ = '\0'; | |
640 | ||
641 | os_memset(&ap, 0, sizeof(ap)); | |
642 | ap.ssid_hex = new_ssid; | |
643 | ap.auth = new_auth; | |
644 | ap.encr = new_encr; | |
645 | ap.key_hex = new_key; | |
646 | return wpas_wps_er_config(wpa_s, cmd, pin, &ap); | |
647 | } | |
72df2f5f JM |
648 | #endif /* CONFIG_WPS_ER */ |
649 | ||
fcc60db4 JM |
650 | #endif /* CONFIG_WPS */ |
651 | ||
652 | ||
11ef8d35 JM |
653 | #ifdef CONFIG_IBSS_RSN |
654 | static int wpa_supplicant_ctrl_iface_ibss_rsn( | |
655 | struct wpa_supplicant *wpa_s, char *addr) | |
656 | { | |
657 | u8 peer[ETH_ALEN]; | |
658 | ||
659 | if (hwaddr_aton(addr, peer)) { | |
660 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid " | |
a7b6c422 | 661 | "address '%s'", addr); |
11ef8d35 JM |
662 | return -1; |
663 | } | |
664 | ||
665 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR, | |
666 | MAC2STR(peer)); | |
667 | ||
668 | return ibss_rsn_start(wpa_s->ibss_rsn, peer); | |
669 | } | |
670 | #endif /* CONFIG_IBSS_RSN */ | |
671 | ||
672 | ||
6fc6879b JM |
673 | static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, |
674 | char *rsp) | |
675 | { | |
676 | #ifdef IEEE8021X_EAPOL | |
677 | char *pos, *id_pos; | |
678 | int id; | |
679 | struct wpa_ssid *ssid; | |
680 | struct eap_peer_config *eap; | |
681 | ||
682 | pos = os_strchr(rsp, '-'); | |
683 | if (pos == NULL) | |
684 | return -1; | |
685 | *pos++ = '\0'; | |
686 | id_pos = pos; | |
687 | pos = os_strchr(pos, ':'); | |
688 | if (pos == NULL) | |
689 | return -1; | |
690 | *pos++ = '\0'; | |
691 | id = atoi(id_pos); | |
692 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); | |
693 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
694 | (u8 *) pos, os_strlen(pos)); | |
695 | ||
696 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
697 | if (ssid == NULL) { | |
698 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
699 | "to update", id); | |
700 | return -1; | |
701 | } | |
702 | eap = &ssid->eap; | |
703 | ||
704 | if (os_strcmp(rsp, "IDENTITY") == 0) { | |
705 | os_free(eap->identity); | |
706 | eap->identity = (u8 *) os_strdup(pos); | |
707 | eap->identity_len = os_strlen(pos); | |
708 | eap->pending_req_identity = 0; | |
709 | if (ssid == wpa_s->current_ssid) | |
710 | wpa_s->reassociate = 1; | |
711 | } else if (os_strcmp(rsp, "PASSWORD") == 0) { | |
712 | os_free(eap->password); | |
713 | eap->password = (u8 *) os_strdup(pos); | |
714 | eap->password_len = os_strlen(pos); | |
715 | eap->pending_req_password = 0; | |
716 | if (ssid == wpa_s->current_ssid) | |
717 | wpa_s->reassociate = 1; | |
718 | } else if (os_strcmp(rsp, "NEW_PASSWORD") == 0) { | |
719 | os_free(eap->new_password); | |
720 | eap->new_password = (u8 *) os_strdup(pos); | |
721 | eap->new_password_len = os_strlen(pos); | |
722 | eap->pending_req_new_password = 0; | |
723 | if (ssid == wpa_s->current_ssid) | |
724 | wpa_s->reassociate = 1; | |
725 | } else if (os_strcmp(rsp, "PIN") == 0) { | |
726 | os_free(eap->pin); | |
727 | eap->pin = os_strdup(pos); | |
728 | eap->pending_req_pin = 0; | |
729 | if (ssid == wpa_s->current_ssid) | |
730 | wpa_s->reassociate = 1; | |
731 | } else if (os_strcmp(rsp, "OTP") == 0) { | |
732 | os_free(eap->otp); | |
733 | eap->otp = (u8 *) os_strdup(pos); | |
734 | eap->otp_len = os_strlen(pos); | |
735 | os_free(eap->pending_req_otp); | |
736 | eap->pending_req_otp = NULL; | |
737 | eap->pending_req_otp_len = 0; | |
738 | } else if (os_strcmp(rsp, "PASSPHRASE") == 0) { | |
739 | os_free(eap->private_key_passwd); | |
740 | eap->private_key_passwd = (u8 *) os_strdup(pos); | |
741 | eap->pending_req_passphrase = 0; | |
742 | if (ssid == wpa_s->current_ssid) | |
743 | wpa_s->reassociate = 1; | |
744 | } else { | |
745 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", rsp); | |
746 | return -1; | |
747 | } | |
748 | ||
749 | return 0; | |
750 | #else /* IEEE8021X_EAPOL */ | |
751 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); | |
752 | return -1; | |
753 | #endif /* IEEE8021X_EAPOL */ | |
754 | } | |
755 | ||
756 | ||
757 | static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, | |
758 | const char *params, | |
759 | char *buf, size_t buflen) | |
760 | { | |
761 | char *pos, *end, tmp[30]; | |
762 | int res, verbose, ret; | |
763 | ||
764 | verbose = os_strcmp(params, "-VERBOSE") == 0; | |
765 | pos = buf; | |
766 | end = buf + buflen; | |
767 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { | |
768 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
769 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | |
770 | MAC2STR(wpa_s->bssid)); | |
771 | if (ret < 0 || ret >= end - pos) | |
772 | return pos - buf; | |
773 | pos += ret; | |
774 | if (ssid) { | |
775 | u8 *_ssid = ssid->ssid; | |
776 | size_t ssid_len = ssid->ssid_len; | |
777 | u8 ssid_buf[MAX_SSID_LEN]; | |
778 | if (ssid_len == 0) { | |
779 | int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); | |
780 | if (_res < 0) | |
781 | ssid_len = 0; | |
782 | else | |
783 | ssid_len = _res; | |
784 | _ssid = ssid_buf; | |
785 | } | |
786 | ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", | |
787 | wpa_ssid_txt(_ssid, ssid_len), | |
788 | ssid->id); | |
789 | if (ret < 0 || ret >= end - pos) | |
790 | return pos - buf; | |
791 | pos += ret; | |
792 | ||
793 | if (ssid->id_str) { | |
794 | ret = os_snprintf(pos, end - pos, | |
795 | "id_str=%s\n", | |
796 | ssid->id_str); | |
797 | if (ret < 0 || ret >= end - pos) | |
798 | return pos - buf; | |
799 | pos += ret; | |
800 | } | |
0e15e529 JM |
801 | |
802 | switch (ssid->mode) { | |
d7dcba70 | 803 | case WPAS_MODE_INFRA: |
0e15e529 JM |
804 | ret = os_snprintf(pos, end - pos, |
805 | "mode=station\n"); | |
806 | break; | |
d7dcba70 | 807 | case WPAS_MODE_IBSS: |
0e15e529 JM |
808 | ret = os_snprintf(pos, end - pos, |
809 | "mode=IBSS\n"); | |
810 | break; | |
d7dcba70 | 811 | case WPAS_MODE_AP: |
0e15e529 JM |
812 | ret = os_snprintf(pos, end - pos, |
813 | "mode=AP\n"); | |
814 | break; | |
2c5d725c JM |
815 | case WPAS_MODE_P2P_GO: |
816 | ret = os_snprintf(pos, end - pos, | |
817 | "mode=P2P GO\n"); | |
818 | break; | |
819 | case WPAS_MODE_P2P_GROUP_FORMATION: | |
820 | ret = os_snprintf(pos, end - pos, | |
821 | "mode=P2P GO - group " | |
822 | "formation\n"); | |
823 | break; | |
0e15e529 JM |
824 | default: |
825 | ret = 0; | |
826 | break; | |
827 | } | |
828 | if (ret < 0 || ret >= end - pos) | |
829 | return pos - buf; | |
830 | pos += ret; | |
6fc6879b JM |
831 | } |
832 | ||
43fb5297 JM |
833 | #ifdef CONFIG_AP |
834 | if (wpa_s->ap_iface) { | |
835 | pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos, | |
836 | end - pos, | |
837 | verbose); | |
838 | } else | |
839 | #endif /* CONFIG_AP */ | |
6fc6879b JM |
840 | pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); |
841 | } | |
842 | ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", | |
843 | wpa_supplicant_state_txt(wpa_s->wpa_state)); | |
844 | if (ret < 0 || ret >= end - pos) | |
845 | return pos - buf; | |
846 | pos += ret; | |
847 | ||
848 | if (wpa_s->l2 && | |
849 | l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { | |
850 | ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); | |
851 | if (ret < 0 || ret >= end - pos) | |
852 | return pos - buf; | |
853 | pos += ret; | |
854 | } | |
855 | ||
d23bd894 JM |
856 | #ifdef CONFIG_P2P |
857 | if (wpa_s->global->p2p) { | |
858 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR | |
859 | "\n", MAC2STR(wpa_s->global->p2p_dev_addr)); | |
860 | if (ret < 0 || ret >= end - pos) | |
861 | return pos - buf; | |
862 | pos += ret; | |
863 | } | |
b21e2c84 | 864 | #endif /* CONFIG_P2P */ |
6d4747a9 JM |
865 | |
866 | ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n", | |
867 | MAC2STR(wpa_s->own_addr)); | |
868 | if (ret < 0 || ret >= end - pos) | |
869 | return pos - buf; | |
870 | pos += ret; | |
d23bd894 | 871 | |
56586197 JM |
872 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
873 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
6fc6879b JM |
874 | res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, |
875 | verbose); | |
876 | if (res >= 0) | |
877 | pos += res; | |
878 | } | |
879 | ||
880 | res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); | |
881 | if (res >= 0) | |
882 | pos += res; | |
883 | ||
884 | return pos - buf; | |
885 | } | |
886 | ||
887 | ||
888 | static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, | |
889 | char *cmd) | |
890 | { | |
891 | char *pos; | |
892 | int id; | |
893 | struct wpa_ssid *ssid; | |
894 | u8 bssid[ETH_ALEN]; | |
895 | ||
896 | /* cmd: "<network id> <BSSID>" */ | |
897 | pos = os_strchr(cmd, ' '); | |
898 | if (pos == NULL) | |
899 | return -1; | |
900 | *pos++ = '\0'; | |
901 | id = atoi(cmd); | |
902 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); | |
903 | if (hwaddr_aton(pos, bssid)) { | |
904 | wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); | |
905 | return -1; | |
906 | } | |
907 | ||
908 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
909 | if (ssid == NULL) { | |
910 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
911 | "to update", id); | |
912 | return -1; | |
913 | } | |
914 | ||
915 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); | |
a8e16edc | 916 | ssid->bssid_set = !is_zero_ether_addr(bssid); |
6fc6879b JM |
917 | |
918 | return 0; | |
919 | } | |
920 | ||
921 | ||
922 | static int wpa_supplicant_ctrl_iface_list_networks( | |
923 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
924 | { | |
925 | char *pos, *end; | |
926 | struct wpa_ssid *ssid; | |
927 | int ret; | |
928 | ||
929 | pos = buf; | |
930 | end = buf + buflen; | |
931 | ret = os_snprintf(pos, end - pos, | |
932 | "network id / ssid / bssid / flags\n"); | |
933 | if (ret < 0 || ret >= end - pos) | |
934 | return pos - buf; | |
935 | pos += ret; | |
936 | ||
937 | ssid = wpa_s->conf->ssid; | |
938 | while (ssid) { | |
939 | ret = os_snprintf(pos, end - pos, "%d\t%s", | |
940 | ssid->id, | |
941 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | |
942 | if (ret < 0 || ret >= end - pos) | |
943 | return pos - buf; | |
944 | pos += ret; | |
945 | if (ssid->bssid_set) { | |
946 | ret = os_snprintf(pos, end - pos, "\t" MACSTR, | |
947 | MAC2STR(ssid->bssid)); | |
948 | } else { | |
949 | ret = os_snprintf(pos, end - pos, "\tany"); | |
950 | } | |
951 | if (ret < 0 || ret >= end - pos) | |
952 | return pos - buf; | |
953 | pos += ret; | |
4dac0245 | 954 | ret = os_snprintf(pos, end - pos, "\t%s%s%s", |
6fc6879b JM |
955 | ssid == wpa_s->current_ssid ? |
956 | "[CURRENT]" : "", | |
4dac0245 JM |
957 | ssid->disabled ? "[DISABLED]" : "", |
958 | ssid->disabled == 2 ? "[P2P-PERSISTENT]" : | |
959 | ""); | |
6fc6879b JM |
960 | if (ret < 0 || ret >= end - pos) |
961 | return pos - buf; | |
962 | pos += ret; | |
963 | ret = os_snprintf(pos, end - pos, "\n"); | |
964 | if (ret < 0 || ret >= end - pos) | |
965 | return pos - buf; | |
966 | pos += ret; | |
967 | ||
968 | ssid = ssid->next; | |
969 | } | |
970 | ||
971 | return pos - buf; | |
972 | } | |
973 | ||
974 | ||
975 | static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) | |
976 | { | |
977 | int first = 1, ret; | |
978 | ret = os_snprintf(pos, end - pos, "-"); | |
979 | if (ret < 0 || ret >= end - pos) | |
980 | return pos; | |
981 | pos += ret; | |
982 | if (cipher & WPA_CIPHER_NONE) { | |
983 | ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+"); | |
984 | if (ret < 0 || ret >= end - pos) | |
985 | return pos; | |
986 | pos += ret; | |
987 | first = 0; | |
988 | } | |
989 | if (cipher & WPA_CIPHER_WEP40) { | |
990 | ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+"); | |
991 | if (ret < 0 || ret >= end - pos) | |
992 | return pos; | |
993 | pos += ret; | |
994 | first = 0; | |
995 | } | |
996 | if (cipher & WPA_CIPHER_WEP104) { | |
997 | ret = os_snprintf(pos, end - pos, "%sWEP104", | |
998 | first ? "" : "+"); | |
999 | if (ret < 0 || ret >= end - pos) | |
1000 | return pos; | |
1001 | pos += ret; | |
1002 | first = 0; | |
1003 | } | |
1004 | if (cipher & WPA_CIPHER_TKIP) { | |
1005 | ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+"); | |
1006 | if (ret < 0 || ret >= end - pos) | |
1007 | return pos; | |
1008 | pos += ret; | |
1009 | first = 0; | |
1010 | } | |
1011 | if (cipher & WPA_CIPHER_CCMP) { | |
1012 | ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+"); | |
1013 | if (ret < 0 || ret >= end - pos) | |
1014 | return pos; | |
1015 | pos += ret; | |
1016 | first = 0; | |
1017 | } | |
1018 | return pos; | |
1019 | } | |
1020 | ||
1021 | ||
1022 | static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, | |
1023 | const u8 *ie, size_t ie_len) | |
1024 | { | |
1025 | struct wpa_ie_data data; | |
1026 | int first, ret; | |
1027 | ||
1028 | ret = os_snprintf(pos, end - pos, "[%s-", proto); | |
1029 | if (ret < 0 || ret >= end - pos) | |
1030 | return pos; | |
1031 | pos += ret; | |
1032 | ||
1033 | if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { | |
1034 | ret = os_snprintf(pos, end - pos, "?]"); | |
1035 | if (ret < 0 || ret >= end - pos) | |
1036 | return pos; | |
1037 | pos += ret; | |
1038 | return pos; | |
1039 | } | |
1040 | ||
1041 | first = 1; | |
1042 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { | |
1043 | ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+"); | |
1044 | if (ret < 0 || ret >= end - pos) | |
1045 | return pos; | |
1046 | pos += ret; | |
1047 | first = 0; | |
1048 | } | |
1049 | if (data.key_mgmt & WPA_KEY_MGMT_PSK) { | |
1050 | ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+"); | |
1051 | if (ret < 0 || ret >= end - pos) | |
1052 | return pos; | |
1053 | pos += ret; | |
1054 | first = 0; | |
1055 | } | |
1056 | if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { | |
1057 | ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+"); | |
1058 | if (ret < 0 || ret >= end - pos) | |
1059 | return pos; | |
1060 | pos += ret; | |
1061 | first = 0; | |
1062 | } | |
1063 | #ifdef CONFIG_IEEE80211R | |
1064 | if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { | |
1065 | ret = os_snprintf(pos, end - pos, "%sFT/EAP", | |
1066 | first ? "" : "+"); | |
1067 | if (ret < 0 || ret >= end - pos) | |
1068 | return pos; | |
1069 | pos += ret; | |
1070 | first = 0; | |
1071 | } | |
1072 | if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { | |
1073 | ret = os_snprintf(pos, end - pos, "%sFT/PSK", | |
1074 | first ? "" : "+"); | |
1075 | if (ret < 0 || ret >= end - pos) | |
1076 | return pos; | |
1077 | pos += ret; | |
1078 | first = 0; | |
1079 | } | |
1080 | #endif /* CONFIG_IEEE80211R */ | |
56586197 JM |
1081 | #ifdef CONFIG_IEEE80211W |
1082 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { | |
1083 | ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", | |
1084 | first ? "" : "+"); | |
1085 | if (ret < 0 || ret >= end - pos) | |
1086 | return pos; | |
1087 | pos += ret; | |
1088 | first = 0; | |
1089 | } | |
1090 | if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { | |
1091 | ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", | |
1092 | first ? "" : "+"); | |
1093 | if (ret < 0 || ret >= end - pos) | |
1094 | return pos; | |
1095 | pos += ret; | |
1096 | first = 0; | |
1097 | } | |
1098 | #endif /* CONFIG_IEEE80211W */ | |
6fc6879b JM |
1099 | |
1100 | pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); | |
1101 | ||
1102 | if (data.capabilities & WPA_CAPABILITY_PREAUTH) { | |
1103 | ret = os_snprintf(pos, end - pos, "-preauth"); | |
1104 | if (ret < 0 || ret >= end - pos) | |
1105 | return pos; | |
1106 | pos += ret; | |
1107 | } | |
1108 | ||
1109 | ret = os_snprintf(pos, end - pos, "]"); | |
1110 | if (ret < 0 || ret >= end - pos) | |
1111 | return pos; | |
1112 | pos += ret; | |
1113 | ||
1114 | return pos; | |
1115 | } | |
1116 | ||
3a068632 | 1117 | |
eef7d7a1 | 1118 | #ifdef CONFIG_WPS |
31fcea93 JM |
1119 | static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, |
1120 | char *pos, char *end, | |
3a068632 JM |
1121 | struct wpabuf *wps_ie) |
1122 | { | |
eef7d7a1 JM |
1123 | int ret; |
1124 | const char *txt; | |
1125 | ||
eef7d7a1 JM |
1126 | if (wps_ie == NULL) |
1127 | return pos; | |
eef7d7a1 JM |
1128 | if (wps_is_selected_pbc_registrar(wps_ie)) |
1129 | txt = "[WPS-PBC]"; | |
53587ec1 | 1130 | #ifdef CONFIG_WPS2 |
31fcea93 JM |
1131 | else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) |
1132 | txt = "[WPS-AUTH]"; | |
53587ec1 | 1133 | #endif /* CONFIG_WPS2 */ |
eef7d7a1 JM |
1134 | else if (wps_is_selected_pin_registrar(wps_ie)) |
1135 | txt = "[WPS-PIN]"; | |
1136 | else | |
1137 | txt = "[WPS]"; | |
1138 | ||
1139 | ret = os_snprintf(pos, end - pos, "%s", txt); | |
1140 | if (ret >= 0 && ret < end - pos) | |
1141 | pos += ret; | |
1142 | wpabuf_free(wps_ie); | |
3a068632 JM |
1143 | return pos; |
1144 | } | |
1145 | #endif /* CONFIG_WPS */ | |
1146 | ||
1147 | ||
31fcea93 JM |
1148 | static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, |
1149 | char *pos, char *end, | |
16b71ac2 | 1150 | const struct wpa_bss *bss) |
3a068632 JM |
1151 | { |
1152 | #ifdef CONFIG_WPS | |
1153 | struct wpabuf *wps_ie; | |
1154 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); | |
31fcea93 | 1155 | return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); |
3a068632 | 1156 | #else /* CONFIG_WPS */ |
eef7d7a1 | 1157 | return pos; |
3a068632 | 1158 | #endif /* CONFIG_WPS */ |
eef7d7a1 JM |
1159 | } |
1160 | ||
6fc6879b JM |
1161 | |
1162 | /* Format one result on one text line into a buffer. */ | |
1163 | static int wpa_supplicant_ctrl_iface_scan_result( | |
31fcea93 | 1164 | struct wpa_supplicant *wpa_s, |
16b71ac2 | 1165 | const struct wpa_bss *bss, char *buf, size_t buflen) |
6fc6879b JM |
1166 | { |
1167 | char *pos, *end; | |
1168 | int ret; | |
0c6b310e JM |
1169 | const u8 *ie, *ie2, *p2p; |
1170 | ||
1171 | p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); | |
1172 | if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && | |
1173 | os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == | |
1174 | 0) | |
1175 | return 0; /* Do not show P2P listen discovery results here */ | |
6fc6879b JM |
1176 | |
1177 | pos = buf; | |
1178 | end = buf + buflen; | |
1179 | ||
1180 | ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", | |
16b71ac2 | 1181 | MAC2STR(bss->bssid), bss->freq, bss->level); |
6fc6879b | 1182 | if (ret < 0 || ret >= end - pos) |
fb0e5bd7 | 1183 | return -1; |
6fc6879b | 1184 | pos += ret; |
16b71ac2 | 1185 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
6fc6879b JM |
1186 | if (ie) |
1187 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); | |
16b71ac2 | 1188 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
6fc6879b JM |
1189 | if (ie2) |
1190 | pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]); | |
31fcea93 | 1191 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
16b71ac2 | 1192 | if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) { |
6fc6879b JM |
1193 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
1194 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 1195 | return -1; |
6fc6879b JM |
1196 | pos += ret; |
1197 | } | |
16b71ac2 | 1198 | if (bss->caps & IEEE80211_CAP_IBSS) { |
6fc6879b JM |
1199 | ret = os_snprintf(pos, end - pos, "[IBSS]"); |
1200 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 1201 | return -1; |
6fc6879b JM |
1202 | pos += ret; |
1203 | } | |
16b71ac2 | 1204 | if (bss->caps & IEEE80211_CAP_ESS) { |
bd1af96a JM |
1205 | ret = os_snprintf(pos, end - pos, "[ESS]"); |
1206 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 1207 | return -1; |
bd1af96a JM |
1208 | pos += ret; |
1209 | } | |
0c6b310e JM |
1210 | if (p2p) { |
1211 | ret = os_snprintf(pos, end - pos, "[P2P]"); | |
1212 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 1213 | return -1; |
0c6b310e JM |
1214 | pos += ret; |
1215 | } | |
6fc6879b | 1216 | |
6fc6879b | 1217 | ret = os_snprintf(pos, end - pos, "\t%s", |
16b71ac2 | 1218 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
6fc6879b | 1219 | if (ret < 0 || ret >= end - pos) |
fb0e5bd7 | 1220 | return -1; |
6fc6879b JM |
1221 | pos += ret; |
1222 | ||
1223 | ret = os_snprintf(pos, end - pos, "\n"); | |
1224 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 1225 | return -1; |
6fc6879b JM |
1226 | pos += ret; |
1227 | ||
1228 | return pos - buf; | |
1229 | } | |
1230 | ||
1231 | ||
1232 | static int wpa_supplicant_ctrl_iface_scan_results( | |
1233 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
1234 | { | |
1235 | char *pos, *end; | |
16b71ac2 | 1236 | struct wpa_bss *bss; |
6fc6879b | 1237 | int ret; |
6fc6879b JM |
1238 | |
1239 | pos = buf; | |
1240 | end = buf + buflen; | |
1241 | ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " | |
1242 | "flags / ssid\n"); | |
1243 | if (ret < 0 || ret >= end - pos) | |
1244 | return pos - buf; | |
1245 | pos += ret; | |
1246 | ||
16b71ac2 | 1247 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
31fcea93 | 1248 | ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, |
6fc6879b JM |
1249 | end - pos); |
1250 | if (ret < 0 || ret >= end - pos) | |
1251 | return pos - buf; | |
1252 | pos += ret; | |
1253 | } | |
1254 | ||
1255 | return pos - buf; | |
1256 | } | |
1257 | ||
1258 | ||
1259 | static int wpa_supplicant_ctrl_iface_select_network( | |
1260 | struct wpa_supplicant *wpa_s, char *cmd) | |
1261 | { | |
1262 | int id; | |
1263 | struct wpa_ssid *ssid; | |
1264 | ||
1265 | /* cmd: "<network id>" or "any" */ | |
1266 | if (os_strcmp(cmd, "any") == 0) { | |
1267 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); | |
86b89452 WS |
1268 | ssid = NULL; |
1269 | } else { | |
1270 | id = atoi(cmd); | |
1271 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); | |
6fc6879b | 1272 | |
86b89452 WS |
1273 | ssid = wpa_config_get_network(wpa_s->conf, id); |
1274 | if (ssid == NULL) { | |
1275 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
1276 | "network id=%d", id); | |
1277 | return -1; | |
1278 | } | |
4dac0245 JM |
1279 | if (ssid->disabled == 2) { |
1280 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
1281 | "SELECT_NETWORK with persistent P2P group"); | |
1282 | return -1; | |
1283 | } | |
6fc6879b JM |
1284 | } |
1285 | ||
86b89452 | 1286 | wpa_supplicant_select_network(wpa_s, ssid); |
6fc6879b JM |
1287 | |
1288 | return 0; | |
1289 | } | |
1290 | ||
1291 | ||
1292 | static int wpa_supplicant_ctrl_iface_enable_network( | |
1293 | struct wpa_supplicant *wpa_s, char *cmd) | |
1294 | { | |
1295 | int id; | |
1296 | struct wpa_ssid *ssid; | |
1297 | ||
1298 | /* cmd: "<network id>" or "all" */ | |
1299 | if (os_strcmp(cmd, "all") == 0) { | |
1300 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); | |
86b89452 WS |
1301 | ssid = NULL; |
1302 | } else { | |
1303 | id = atoi(cmd); | |
1304 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); | |
6fc6879b | 1305 | |
86b89452 WS |
1306 | ssid = wpa_config_get_network(wpa_s->conf, id); |
1307 | if (ssid == NULL) { | |
1308 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
1309 | "network id=%d", id); | |
1310 | return -1; | |
1311 | } | |
4dac0245 JM |
1312 | if (ssid->disabled == 2) { |
1313 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
1314 | "ENABLE_NETWORK with persistent P2P group"); | |
1315 | return -1; | |
1316 | } | |
6fc6879b | 1317 | } |
86b89452 | 1318 | wpa_supplicant_enable_network(wpa_s, ssid); |
6fc6879b JM |
1319 | |
1320 | return 0; | |
1321 | } | |
1322 | ||
1323 | ||
1324 | static int wpa_supplicant_ctrl_iface_disable_network( | |
1325 | struct wpa_supplicant *wpa_s, char *cmd) | |
1326 | { | |
1327 | int id; | |
1328 | struct wpa_ssid *ssid; | |
1329 | ||
1330 | /* cmd: "<network id>" or "all" */ | |
1331 | if (os_strcmp(cmd, "all") == 0) { | |
1332 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); | |
86b89452 WS |
1333 | ssid = NULL; |
1334 | } else { | |
1335 | id = atoi(cmd); | |
1336 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); | |
6fc6879b | 1337 | |
86b89452 WS |
1338 | ssid = wpa_config_get_network(wpa_s->conf, id); |
1339 | if (ssid == NULL) { | |
1340 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
1341 | "network id=%d", id); | |
1342 | return -1; | |
1343 | } | |
4dac0245 JM |
1344 | if (ssid->disabled == 2) { |
1345 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
1346 | "DISABLE_NETWORK with persistent P2P " | |
1347 | "group"); | |
1348 | return -1; | |
1349 | } | |
6fc6879b | 1350 | } |
86b89452 | 1351 | wpa_supplicant_disable_network(wpa_s, ssid); |
6fc6879b JM |
1352 | |
1353 | return 0; | |
1354 | } | |
1355 | ||
1356 | ||
1357 | static int wpa_supplicant_ctrl_iface_add_network( | |
1358 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
1359 | { | |
1360 | struct wpa_ssid *ssid; | |
1361 | int ret; | |
1362 | ||
1363 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); | |
1364 | ||
1365 | ssid = wpa_config_add_network(wpa_s->conf); | |
1366 | if (ssid == NULL) | |
1367 | return -1; | |
8bac466b JM |
1368 | |
1369 | wpas_notify_network_added(wpa_s, ssid); | |
1370 | ||
6fc6879b JM |
1371 | ssid->disabled = 1; |
1372 | wpa_config_set_network_defaults(ssid); | |
1373 | ||
1374 | ret = os_snprintf(buf, buflen, "%d\n", ssid->id); | |
1375 | if (ret < 0 || (size_t) ret >= buflen) | |
1376 | return -1; | |
1377 | return ret; | |
1378 | } | |
1379 | ||
1380 | ||
1381 | static int wpa_supplicant_ctrl_iface_remove_network( | |
1382 | struct wpa_supplicant *wpa_s, char *cmd) | |
1383 | { | |
1384 | int id; | |
1385 | struct wpa_ssid *ssid; | |
1386 | ||
1387 | /* cmd: "<network id>" or "all" */ | |
1388 | if (os_strcmp(cmd, "all") == 0) { | |
1389 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); | |
1390 | ssid = wpa_s->conf->ssid; | |
1391 | while (ssid) { | |
8bac466b | 1392 | struct wpa_ssid *remove_ssid = ssid; |
6fc6879b JM |
1393 | id = ssid->id; |
1394 | ssid = ssid->next; | |
8bac466b | 1395 | wpas_notify_network_removed(wpa_s, remove_ssid); |
6fc6879b JM |
1396 | wpa_config_remove_network(wpa_s->conf, id); |
1397 | } | |
d8a790b9 | 1398 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
6fc6879b | 1399 | if (wpa_s->current_ssid) { |
20a0b03d JM |
1400 | wpa_sm_set_config(wpa_s->wpa, NULL); |
1401 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | |
6fc6879b JM |
1402 | wpa_supplicant_disassociate(wpa_s, |
1403 | WLAN_REASON_DEAUTH_LEAVING); | |
1404 | } | |
1405 | return 0; | |
1406 | } | |
1407 | ||
1408 | id = atoi(cmd); | |
1409 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); | |
1410 | ||
1411 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
f3857c2e JM |
1412 | if (ssid) |
1413 | wpas_notify_network_removed(wpa_s, ssid); | |
6fc6879b JM |
1414 | if (ssid == NULL || |
1415 | wpa_config_remove_network(wpa_s->conf, id) < 0) { | |
1416 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | |
1417 | "id=%d", id); | |
1418 | return -1; | |
1419 | } | |
1420 | ||
d8a790b9 | 1421 | if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) { |
6fc6879b | 1422 | /* |
d8a790b9 JM |
1423 | * Invalidate the EAP session cache if the current or |
1424 | * previously used network is removed. | |
6fc6879b JM |
1425 | */ |
1426 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
d8a790b9 JM |
1427 | } |
1428 | ||
1429 | if (ssid == wpa_s->current_ssid) { | |
20a0b03d JM |
1430 | wpa_sm_set_config(wpa_s->wpa, NULL); |
1431 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | |
6fc6879b JM |
1432 | |
1433 | wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1434 | } | |
1435 | ||
1436 | return 0; | |
1437 | } | |
1438 | ||
1439 | ||
1440 | static int wpa_supplicant_ctrl_iface_set_network( | |
1441 | struct wpa_supplicant *wpa_s, char *cmd) | |
1442 | { | |
1443 | int id; | |
1444 | struct wpa_ssid *ssid; | |
1445 | char *name, *value; | |
1446 | ||
1447 | /* cmd: "<network id> <variable name> <value>" */ | |
1448 | name = os_strchr(cmd, ' '); | |
1449 | if (name == NULL) | |
1450 | return -1; | |
1451 | *name++ = '\0'; | |
1452 | ||
1453 | value = os_strchr(name, ' '); | |
1454 | if (value == NULL) | |
1455 | return -1; | |
1456 | *value++ = '\0'; | |
1457 | ||
1458 | id = atoi(cmd); | |
1459 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", | |
1460 | id, name); | |
1461 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
1462 | (u8 *) value, os_strlen(value)); | |
1463 | ||
1464 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
1465 | if (ssid == NULL) { | |
1466 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | |
1467 | "id=%d", id); | |
1468 | return -1; | |
1469 | } | |
1470 | ||
1471 | if (wpa_config_set(ssid, name, value, 0) < 0) { | |
1472 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " | |
1473 | "variable '%s'", name); | |
1474 | return -1; | |
1475 | } | |
1476 | ||
d8a790b9 JM |
1477 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
1478 | ||
1479 | if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) { | |
6fc6879b JM |
1480 | /* |
1481 | * Invalidate the EAP session cache if anything in the current | |
d8a790b9 | 1482 | * or previously used configuration changes. |
6fc6879b JM |
1483 | */ |
1484 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
1485 | } | |
1486 | ||
1487 | if ((os_strcmp(name, "psk") == 0 && | |
1488 | value[0] == '"' && ssid->ssid_len) || | |
1489 | (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) | |
1490 | wpa_config_update_psk(ssid); | |
aa53509f DS |
1491 | else if (os_strcmp(name, "priority") == 0) |
1492 | wpa_config_update_prio_list(wpa_s->conf); | |
6fc6879b JM |
1493 | |
1494 | return 0; | |
1495 | } | |
1496 | ||
1497 | ||
1498 | static int wpa_supplicant_ctrl_iface_get_network( | |
1499 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
1500 | { | |
1501 | int id; | |
1502 | size_t res; | |
1503 | struct wpa_ssid *ssid; | |
1504 | char *name, *value; | |
1505 | ||
1506 | /* cmd: "<network id> <variable name>" */ | |
1507 | name = os_strchr(cmd, ' '); | |
1508 | if (name == NULL || buflen == 0) | |
1509 | return -1; | |
1510 | *name++ = '\0'; | |
1511 | ||
1512 | id = atoi(cmd); | |
1513 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'", | |
1514 | id, name); | |
1515 | ||
1516 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
1517 | if (ssid == NULL) { | |
1518 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | |
1519 | "id=%d", id); | |
1520 | return -1; | |
1521 | } | |
1522 | ||
1523 | value = wpa_config_get_no_key(ssid, name); | |
1524 | if (value == NULL) { | |
1525 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " | |
1526 | "variable '%s'", name); | |
1527 | return -1; | |
1528 | } | |
1529 | ||
1530 | res = os_strlcpy(buf, value, buflen); | |
1531 | if (res >= buflen) { | |
1532 | os_free(value); | |
1533 | return -1; | |
1534 | } | |
1535 | ||
1536 | os_free(value); | |
1537 | ||
1538 | return res; | |
1539 | } | |
1540 | ||
1541 | ||
1542 | #ifndef CONFIG_NO_CONFIG_WRITE | |
1543 | static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s) | |
1544 | { | |
1545 | int ret; | |
1546 | ||
1547 | if (!wpa_s->conf->update_config) { | |
1548 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed " | |
1549 | "to update configuration (update_config=0)"); | |
1550 | return -1; | |
1551 | } | |
1552 | ||
1553 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); | |
1554 | if (ret) { | |
1555 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to " | |
1556 | "update configuration"); | |
1557 | } else { | |
1558 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration" | |
1559 | " updated"); | |
1560 | } | |
1561 | ||
1562 | return ret; | |
1563 | } | |
1564 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
1565 | ||
1566 | ||
1567 | static int ctrl_iface_get_capability_pairwise(int res, char *strict, | |
1568 | struct wpa_driver_capa *capa, | |
1569 | char *buf, size_t buflen) | |
1570 | { | |
1571 | int ret, first = 1; | |
1572 | char *pos, *end; | |
1573 | size_t len; | |
1574 | ||
1575 | pos = buf; | |
1576 | end = pos + buflen; | |
1577 | ||
1578 | if (res < 0) { | |
1579 | if (strict) | |
1580 | return 0; | |
1581 | len = os_strlcpy(buf, "CCMP TKIP NONE", buflen); | |
1582 | if (len >= buflen) | |
1583 | return -1; | |
1584 | return len; | |
1585 | } | |
1586 | ||
1587 | if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) { | |
1588 | ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " "); | |
1589 | if (ret < 0 || ret >= end - pos) | |
1590 | return pos - buf; | |
1591 | pos += ret; | |
1592 | first = 0; | |
1593 | } | |
1594 | ||
1595 | if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) { | |
1596 | ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " "); | |
1597 | if (ret < 0 || ret >= end - pos) | |
1598 | return pos - buf; | |
1599 | pos += ret; | |
1600 | first = 0; | |
1601 | } | |
1602 | ||
1603 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { | |
1604 | ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " "); | |
1605 | if (ret < 0 || ret >= end - pos) | |
1606 | return pos - buf; | |
1607 | pos += ret; | |
1608 | first = 0; | |
1609 | } | |
1610 | ||
1611 | return pos - buf; | |
1612 | } | |
1613 | ||
1614 | ||
1615 | static int ctrl_iface_get_capability_group(int res, char *strict, | |
1616 | struct wpa_driver_capa *capa, | |
1617 | char *buf, size_t buflen) | |
1618 | { | |
1619 | int ret, first = 1; | |
1620 | char *pos, *end; | |
1621 | size_t len; | |
1622 | ||
1623 | pos = buf; | |
1624 | end = pos + buflen; | |
1625 | ||
1626 | if (res < 0) { | |
1627 | if (strict) | |
1628 | return 0; | |
1629 | len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen); | |
1630 | if (len >= buflen) | |
1631 | return -1; | |
1632 | return len; | |
1633 | } | |
1634 | ||
1635 | if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) { | |
1636 | ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " "); | |
1637 | if (ret < 0 || ret >= end - pos) | |
1638 | return pos - buf; | |
1639 | pos += ret; | |
1640 | first = 0; | |
1641 | } | |
1642 | ||
1643 | if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) { | |
1644 | ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " "); | |
1645 | if (ret < 0 || ret >= end - pos) | |
1646 | return pos - buf; | |
1647 | pos += ret; | |
1648 | first = 0; | |
1649 | } | |
1650 | ||
1651 | if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) { | |
1652 | ret = os_snprintf(pos, end - pos, "%sWEP104", | |
1653 | first ? "" : " "); | |
1654 | if (ret < 0 || ret >= end - pos) | |
1655 | return pos - buf; | |
1656 | pos += ret; | |
1657 | first = 0; | |
1658 | } | |
1659 | ||
1660 | if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) { | |
1661 | ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " "); | |
1662 | if (ret < 0 || ret >= end - pos) | |
1663 | return pos - buf; | |
1664 | pos += ret; | |
1665 | first = 0; | |
1666 | } | |
1667 | ||
1668 | return pos - buf; | |
1669 | } | |
1670 | ||
1671 | ||
1672 | static int ctrl_iface_get_capability_key_mgmt(int res, char *strict, | |
1673 | struct wpa_driver_capa *capa, | |
1674 | char *buf, size_t buflen) | |
1675 | { | |
1676 | int ret; | |
1677 | char *pos, *end; | |
1678 | size_t len; | |
1679 | ||
1680 | pos = buf; | |
1681 | end = pos + buflen; | |
1682 | ||
1683 | if (res < 0) { | |
1684 | if (strict) | |
1685 | return 0; | |
1686 | len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE " | |
1687 | "NONE", buflen); | |
1688 | if (len >= buflen) | |
1689 | return -1; | |
1690 | return len; | |
1691 | } | |
1692 | ||
1693 | ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); | |
1694 | if (ret < 0 || ret >= end - pos) | |
1695 | return pos - buf; | |
1696 | pos += ret; | |
1697 | ||
1698 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
1699 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { | |
1700 | ret = os_snprintf(pos, end - pos, " WPA-EAP"); | |
1701 | if (ret < 0 || ret >= end - pos) | |
1702 | return pos - buf; | |
1703 | pos += ret; | |
1704 | } | |
1705 | ||
1706 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | |
1707 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
1708 | ret = os_snprintf(pos, end - pos, " WPA-PSK"); | |
1709 | if (ret < 0 || ret >= end - pos) | |
1710 | return pos - buf; | |
1711 | pos += ret; | |
1712 | } | |
1713 | ||
1714 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { | |
1715 | ret = os_snprintf(pos, end - pos, " WPA-NONE"); | |
1716 | if (ret < 0 || ret >= end - pos) | |
1717 | return pos - buf; | |
1718 | pos += ret; | |
1719 | } | |
1720 | ||
1721 | return pos - buf; | |
1722 | } | |
1723 | ||
1724 | ||
1725 | static int ctrl_iface_get_capability_proto(int res, char *strict, | |
1726 | struct wpa_driver_capa *capa, | |
1727 | char *buf, size_t buflen) | |
1728 | { | |
1729 | int ret, first = 1; | |
1730 | char *pos, *end; | |
1731 | size_t len; | |
1732 | ||
1733 | pos = buf; | |
1734 | end = pos + buflen; | |
1735 | ||
1736 | if (res < 0) { | |
1737 | if (strict) | |
1738 | return 0; | |
1739 | len = os_strlcpy(buf, "RSN WPA", buflen); | |
1740 | if (len >= buflen) | |
1741 | return -1; | |
1742 | return len; | |
1743 | } | |
1744 | ||
1745 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | |
1746 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
1747 | ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " "); | |
1748 | if (ret < 0 || ret >= end - pos) | |
1749 | return pos - buf; | |
1750 | pos += ret; | |
1751 | first = 0; | |
1752 | } | |
1753 | ||
1754 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
1755 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { | |
1756 | ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " "); | |
1757 | if (ret < 0 || ret >= end - pos) | |
1758 | return pos - buf; | |
1759 | pos += ret; | |
1760 | first = 0; | |
1761 | } | |
1762 | ||
1763 | return pos - buf; | |
1764 | } | |
1765 | ||
1766 | ||
1767 | static int ctrl_iface_get_capability_auth_alg(int res, char *strict, | |
1768 | struct wpa_driver_capa *capa, | |
1769 | char *buf, size_t buflen) | |
1770 | { | |
1771 | int ret, first = 1; | |
1772 | char *pos, *end; | |
1773 | size_t len; | |
1774 | ||
1775 | pos = buf; | |
1776 | end = pos + buflen; | |
1777 | ||
1778 | if (res < 0) { | |
1779 | if (strict) | |
1780 | return 0; | |
1781 | len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen); | |
1782 | if (len >= buflen) | |
1783 | return -1; | |
1784 | return len; | |
1785 | } | |
1786 | ||
1787 | if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) { | |
1788 | ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " "); | |
1789 | if (ret < 0 || ret >= end - pos) | |
1790 | return pos - buf; | |
1791 | pos += ret; | |
1792 | first = 0; | |
1793 | } | |
1794 | ||
1795 | if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) { | |
1796 | ret = os_snprintf(pos, end - pos, "%sSHARED", | |
1797 | first ? "" : " "); | |
1798 | if (ret < 0 || ret >= end - pos) | |
1799 | return pos - buf; | |
1800 | pos += ret; | |
1801 | first = 0; | |
1802 | } | |
1803 | ||
1804 | if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) { | |
1805 | ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " "); | |
1806 | if (ret < 0 || ret >= end - pos) | |
1807 | return pos - buf; | |
1808 | pos += ret; | |
1809 | first = 0; | |
1810 | } | |
1811 | ||
1812 | return pos - buf; | |
1813 | } | |
1814 | ||
1815 | ||
1816 | static int wpa_supplicant_ctrl_iface_get_capability( | |
1817 | struct wpa_supplicant *wpa_s, const char *_field, char *buf, | |
1818 | size_t buflen) | |
1819 | { | |
1820 | struct wpa_driver_capa capa; | |
1821 | int res; | |
1822 | char *strict; | |
1823 | char field[30]; | |
1824 | size_t len; | |
1825 | ||
1826 | /* Determine whether or not strict checking was requested */ | |
1827 | len = os_strlcpy(field, _field, sizeof(field)); | |
1828 | if (len >= sizeof(field)) | |
1829 | return -1; | |
1830 | strict = os_strchr(field, ' '); | |
1831 | if (strict != NULL) { | |
1832 | *strict++ = '\0'; | |
1833 | if (os_strcmp(strict, "strict") != 0) | |
1834 | return -1; | |
1835 | } | |
1836 | ||
1837 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s", | |
1838 | field, strict ? strict : ""); | |
1839 | ||
1840 | if (os_strcmp(field, "eap") == 0) { | |
1841 | return eap_get_names(buf, buflen); | |
1842 | } | |
1843 | ||
1844 | res = wpa_drv_get_capa(wpa_s, &capa); | |
1845 | ||
1846 | if (os_strcmp(field, "pairwise") == 0) | |
1847 | return ctrl_iface_get_capability_pairwise(res, strict, &capa, | |
1848 | buf, buflen); | |
1849 | ||
1850 | if (os_strcmp(field, "group") == 0) | |
1851 | return ctrl_iface_get_capability_group(res, strict, &capa, | |
1852 | buf, buflen); | |
1853 | ||
1854 | if (os_strcmp(field, "key_mgmt") == 0) | |
1855 | return ctrl_iface_get_capability_key_mgmt(res, strict, &capa, | |
1856 | buf, buflen); | |
1857 | ||
1858 | if (os_strcmp(field, "proto") == 0) | |
1859 | return ctrl_iface_get_capability_proto(res, strict, &capa, | |
1860 | buf, buflen); | |
1861 | ||
1862 | if (os_strcmp(field, "auth_alg") == 0) | |
1863 | return ctrl_iface_get_capability_auth_alg(res, strict, &capa, | |
1864 | buf, buflen); | |
1865 | ||
1866 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", | |
1867 | field); | |
1868 | ||
1869 | return -1; | |
1870 | } | |
1871 | ||
1872 | ||
1873 | static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s, | |
1874 | const char *cmd, char *buf, | |
1875 | size_t buflen) | |
1876 | { | |
1877 | u8 bssid[ETH_ALEN]; | |
1878 | size_t i; | |
3a068632 | 1879 | struct wpa_bss *bss; |
6fc6879b JM |
1880 | int ret; |
1881 | char *pos, *end; | |
1882 | const u8 *ie, *ie2; | |
1883 | ||
3a068632 JM |
1884 | if (os_strcmp(cmd, "FIRST") == 0) |
1885 | bss = dl_list_first(&wpa_s->bss, struct wpa_bss, list); | |
1886 | else if (os_strncmp(cmd, "ID-", 3) == 0) { | |
1887 | i = atoi(cmd + 3); | |
1888 | bss = wpa_bss_get_id(wpa_s, i); | |
1889 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | |
1890 | i = atoi(cmd + 5); | |
1891 | bss = wpa_bss_get_id(wpa_s, i); | |
1892 | if (bss) { | |
1893 | struct dl_list *next = bss->list_id.next; | |
1894 | if (next == &wpa_s->bss_id) | |
1895 | bss = NULL; | |
1896 | else | |
1897 | bss = dl_list_entry(next, struct wpa_bss, | |
1898 | list_id); | |
6fc6879b | 1899 | } |
3a068632 JM |
1900 | } else if (hwaddr_aton(cmd, bssid) == 0) |
1901 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
1902 | else { | |
1903 | struct wpa_bss *tmp; | |
6fc6879b | 1904 | i = atoi(cmd); |
3a068632 JM |
1905 | bss = NULL; |
1906 | dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id) | |
1907 | { | |
1908 | if (i-- == 0) { | |
1909 | bss = tmp; | |
1910 | break; | |
1911 | } | |
1912 | } | |
1913 | } | |
6fc6879b | 1914 | |
3a068632 JM |
1915 | if (bss == NULL) |
1916 | return 0; | |
6fc6879b | 1917 | |
6fc6879b JM |
1918 | pos = buf; |
1919 | end = buf + buflen; | |
3fd0b8f1 | 1920 | ret = os_snprintf(pos, end - pos, |
3a068632 | 1921 | "id=%u\n" |
3fd0b8f1 JM |
1922 | "bssid=" MACSTR "\n" |
1923 | "freq=%d\n" | |
1924 | "beacon_int=%d\n" | |
1925 | "capabilities=0x%04x\n" | |
1926 | "qual=%d\n" | |
1927 | "noise=%d\n" | |
1928 | "level=%d\n" | |
1929 | "tsf=%016llu\n" | |
1930 | "ie=", | |
3a068632 | 1931 | bss->id, |
3fd0b8f1 JM |
1932 | MAC2STR(bss->bssid), bss->freq, bss->beacon_int, |
1933 | bss->caps, bss->qual, bss->noise, bss->level, | |
1934 | (unsigned long long) bss->tsf); | |
6fc6879b JM |
1935 | if (ret < 0 || ret >= end - pos) |
1936 | return pos - buf; | |
1937 | pos += ret; | |
1938 | ||
1939 | ie = (const u8 *) (bss + 1); | |
1940 | for (i = 0; i < bss->ie_len; i++) { | |
3fd0b8f1 | 1941 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); |
6fc6879b JM |
1942 | if (ret < 0 || ret >= end - pos) |
1943 | return pos - buf; | |
1944 | pos += ret; | |
1945 | } | |
0c6b310e JM |
1946 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) { |
1947 | ret = os_snprintf(pos, end - pos, "[P2P]"); | |
1948 | if (ret < 0 || ret >= end - pos) | |
1949 | return pos - buf; | |
1950 | pos += ret; | |
1951 | } | |
6fc6879b | 1952 | |
3fd0b8f1 | 1953 | ret = os_snprintf(pos, end - pos, "\n"); |
6fc6879b JM |
1954 | if (ret < 0 || ret >= end - pos) |
1955 | return pos - buf; | |
1956 | pos += ret; | |
1957 | ||
1958 | ret = os_snprintf(pos, end - pos, "flags="); | |
1959 | if (ret < 0 || ret >= end - pos) | |
1960 | return pos - buf; | |
1961 | pos += ret; | |
1962 | ||
3a068632 | 1963 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
6fc6879b JM |
1964 | if (ie) |
1965 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); | |
3a068632 | 1966 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
6fc6879b JM |
1967 | if (ie2) |
1968 | pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]); | |
31fcea93 | 1969 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
6fc6879b JM |
1970 | if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) { |
1971 | ret = os_snprintf(pos, end - pos, "[WEP]"); | |
1972 | if (ret < 0 || ret >= end - pos) | |
1973 | return pos - buf; | |
1974 | pos += ret; | |
1975 | } | |
1976 | if (bss->caps & IEEE80211_CAP_IBSS) { | |
1977 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | |
1978 | if (ret < 0 || ret >= end - pos) | |
1979 | return pos - buf; | |
1980 | pos += ret; | |
1981 | } | |
bd1af96a JM |
1982 | if (bss->caps & IEEE80211_CAP_ESS) { |
1983 | ret = os_snprintf(pos, end - pos, "[ESS]"); | |
1984 | if (ret < 0 || ret >= end - pos) | |
1985 | return pos - buf; | |
1986 | pos += ret; | |
1987 | } | |
6fc6879b | 1988 | |
3fd0b8f1 | 1989 | ret = os_snprintf(pos, end - pos, "\n"); |
6fc6879b JM |
1990 | if (ret < 0 || ret >= end - pos) |
1991 | return pos - buf; | |
1992 | pos += ret; | |
1993 | ||
6fc6879b | 1994 | ret = os_snprintf(pos, end - pos, "ssid=%s\n", |
3a068632 | 1995 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
6fc6879b JM |
1996 | if (ret < 0 || ret >= end - pos) |
1997 | return pos - buf; | |
1998 | pos += ret; | |
1999 | ||
611ed491 JM |
2000 | #ifdef CONFIG_WPS |
2001 | ie = (const u8 *) (bss + 1); | |
2002 | ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end); | |
2003 | if (ret < 0 || ret >= end - pos) | |
2004 | return pos - buf; | |
2005 | pos += ret; | |
2006 | #endif /* CONFIG_WPS */ | |
2007 | ||
0c6b310e JM |
2008 | #ifdef CONFIG_P2P |
2009 | ie = (const u8 *) (bss + 1); | |
2010 | ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end); | |
2011 | if (ret < 0 || ret >= end - pos) | |
2012 | return pos - buf; | |
2013 | pos += ret; | |
2014 | #endif /* CONFIG_P2P */ | |
2015 | ||
6fc6879b JM |
2016 | return pos - buf; |
2017 | } | |
2018 | ||
2019 | ||
2020 | static int wpa_supplicant_ctrl_iface_ap_scan( | |
2021 | struct wpa_supplicant *wpa_s, char *cmd) | |
2022 | { | |
2023 | int ap_scan = atoi(cmd); | |
86b89452 | 2024 | return wpa_supplicant_set_ap_scan(wpa_s, ap_scan); |
6fc6879b JM |
2025 | } |
2026 | ||
2027 | ||
67b9bd08 DS |
2028 | static int wpa_supplicant_ctrl_iface_scan_interval( |
2029 | struct wpa_supplicant *wpa_s, char *cmd) | |
2030 | { | |
2031 | int scan_int = atoi(cmd); | |
2032 | if (scan_int < 0) | |
2033 | return -1; | |
2034 | wpa_s->scan_interval = scan_int; | |
2035 | return 0; | |
2036 | } | |
2037 | ||
2038 | ||
78633c37 SL |
2039 | static int wpa_supplicant_ctrl_iface_bss_expire_age( |
2040 | struct wpa_supplicant *wpa_s, char *cmd) | |
2041 | { | |
2042 | int expire_age = atoi(cmd); | |
2043 | return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age); | |
2044 | } | |
2045 | ||
2046 | ||
2047 | static int wpa_supplicant_ctrl_iface_bss_expire_count( | |
2048 | struct wpa_supplicant *wpa_s, char *cmd) | |
2049 | { | |
2050 | int expire_count = atoi(cmd); | |
2051 | return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count); | |
2052 | } | |
2053 | ||
2054 | ||
32d5295f JM |
2055 | static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s) |
2056 | { | |
32d5295f JM |
2057 | wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication"); |
2058 | /* MLME-DELETEKEYS.request */ | |
0382097e JM |
2059 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0); |
2060 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0); | |
2061 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0); | |
2062 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0); | |
32d5295f | 2063 | #ifdef CONFIG_IEEE80211W |
0382097e JM |
2064 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0); |
2065 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0); | |
32d5295f JM |
2066 | #endif /* CONFIG_IEEE80211W */ |
2067 | ||
2068 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL, | |
2069 | 0); | |
2070 | /* MLME-SETPROTECTION.request(None) */ | |
2071 | wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid, | |
2072 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, | |
2073 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); | |
2074 | wpa_sm_drop_sa(wpa_s->wpa); | |
2075 | } | |
2076 | ||
2077 | ||
86d4f806 JM |
2078 | static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s, |
2079 | char *addr) | |
2080 | { | |
2081 | u8 bssid[ETH_ALEN]; | |
2082 | struct wpa_bss *bss; | |
2083 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
2084 | ||
2085 | if (hwaddr_aton(addr, bssid)) { | |
2086 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid " | |
2087 | "address '%s'", addr); | |
2088 | return -1; | |
2089 | } | |
2090 | ||
2091 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid)); | |
2092 | ||
2093 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
2094 | if (!bss) { | |
2095 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found " | |
2096 | "from BSS table"); | |
2097 | return -1; | |
2098 | } | |
2099 | ||
2100 | /* | |
2101 | * TODO: Find best network configuration block from configuration to | |
2102 | * allow roaming to other networks | |
2103 | */ | |
2104 | ||
2105 | if (!ssid) { | |
2106 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network " | |
2107 | "configuration known for the target AP"); | |
2108 | return -1; | |
2109 | } | |
2110 | ||
2111 | wpa_s->reassociate = 1; | |
2112 | wpa_supplicant_connect(wpa_s, bss, ssid); | |
2113 | ||
2114 | return 0; | |
2115 | } | |
2116 | ||
2117 | ||
b563b388 JM |
2118 | #ifdef CONFIG_P2P |
2119 | static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd) | |
2120 | { | |
2121 | unsigned int timeout = atoi(cmd); | |
2122 | enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL; | |
2123 | ||
2124 | if (os_strstr(cmd, "type=social")) | |
2125 | type = P2P_FIND_ONLY_SOCIAL; | |
2126 | else if (os_strstr(cmd, "type=progressive")) | |
2127 | type = P2P_FIND_PROGRESSIVE; | |
2128 | ||
046ef4aa | 2129 | return wpas_p2p_find(wpa_s, timeout, type, 0, NULL); |
b563b388 JM |
2130 | } |
2131 | ||
2132 | ||
2133 | static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd, | |
2134 | char *buf, size_t buflen) | |
2135 | { | |
2136 | u8 addr[ETH_ALEN]; | |
2137 | char *pos, *pos2; | |
2138 | char *pin = NULL; | |
2139 | enum p2p_wps_method wps_method; | |
2140 | int new_pin; | |
2141 | int ret; | |
2142 | int persistent_group; | |
2143 | int join; | |
2144 | int auth; | |
2145 | int go_intent = -1; | |
2146 | int freq = 0; | |
2147 | ||
2148 | /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad] [persistent] | |
108def93 | 2149 | * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] */ |
b563b388 JM |
2150 | |
2151 | if (hwaddr_aton(cmd, addr)) | |
2152 | return -1; | |
2153 | ||
2154 | pos = cmd + 17; | |
2155 | if (*pos != ' ') | |
2156 | return -1; | |
2157 | pos++; | |
2158 | ||
2159 | persistent_group = os_strstr(pos, " persistent") != NULL; | |
2160 | join = os_strstr(pos, " join") != NULL; | |
2161 | auth = os_strstr(pos, " auth") != NULL; | |
2162 | ||
2163 | pos2 = os_strstr(pos, " go_intent="); | |
2164 | if (pos2) { | |
2165 | pos2 += 11; | |
2166 | go_intent = atoi(pos2); | |
2167 | if (go_intent < 0 || go_intent > 15) | |
2168 | return -1; | |
2169 | } | |
2170 | ||
2171 | pos2 = os_strstr(pos, " freq="); | |
2172 | if (pos2) { | |
2173 | pos2 += 6; | |
2174 | freq = atoi(pos2); | |
2175 | if (freq <= 0) | |
2176 | return -1; | |
2177 | } | |
2178 | ||
2179 | if (os_strncmp(pos, "pin", 3) == 0) { | |
2180 | /* Request random PIN (to be displayed) and enable the PIN */ | |
2181 | wps_method = WPS_PIN_DISPLAY; | |
2182 | } else if (os_strncmp(pos, "pbc", 3) == 0) { | |
2183 | wps_method = WPS_PBC; | |
2184 | } else { | |
2185 | pin = pos; | |
2186 | pos = os_strchr(pin, ' '); | |
2187 | wps_method = WPS_PIN_KEYPAD; | |
2188 | if (pos) { | |
2189 | *pos++ = '\0'; | |
2190 | if (os_strncmp(pos, "label", 5) == 0) | |
2191 | wps_method = WPS_PIN_LABEL; | |
2192 | else if (os_strncmp(pos, "display", 7) == 0) | |
2193 | wps_method = WPS_PIN_DISPLAY; | |
2194 | } | |
2195 | } | |
2196 | ||
2197 | new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method, | |
2198 | persistent_group, join, auth, go_intent, | |
2199 | freq); | |
d054a462 JM |
2200 | if (new_pin == -2) { |
2201 | os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25); | |
2202 | return 25; | |
2203 | } | |
2204 | if (new_pin == -3) { | |
2205 | os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25); | |
2206 | return 25; | |
2207 | } | |
b563b388 JM |
2208 | if (new_pin < 0) |
2209 | return -1; | |
2210 | if (wps_method == WPS_PIN_DISPLAY && pin == NULL) { | |
2211 | ret = os_snprintf(buf, buflen, "%08d", new_pin); | |
2212 | if (ret < 0 || (size_t) ret >= buflen) | |
2213 | return -1; | |
2214 | return ret; | |
2215 | } | |
2216 | ||
2217 | os_memcpy(buf, "OK\n", 3); | |
2218 | return 3; | |
2219 | } | |
2220 | ||
2221 | ||
2222 | static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd) | |
2223 | { | |
2224 | unsigned int timeout = atoi(cmd); | |
2225 | return wpas_p2p_listen(wpa_s, timeout); | |
2226 | } | |
2227 | ||
2228 | ||
2229 | static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) | |
2230 | { | |
2231 | u8 addr[ETH_ALEN]; | |
2232 | char *pos; | |
2233 | ||
2234 | /* <addr> <config method> */ | |
2235 | ||
2236 | if (hwaddr_aton(cmd, addr)) | |
2237 | return -1; | |
2238 | ||
2239 | pos = cmd + 17; | |
2240 | if (*pos != ' ') | |
2241 | return -1; | |
2242 | pos++; | |
2243 | ||
2244 | return wpas_p2p_prov_disc(wpa_s, addr, pos); | |
2245 | } | |
2246 | ||
2247 | ||
2248 | static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf, | |
2249 | size_t buflen) | |
2250 | { | |
2251 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
2252 | ||
2253 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || | |
2254 | ssid->passphrase == NULL) | |
2255 | return -1; | |
2256 | ||
2257 | os_strlcpy(buf, ssid->passphrase, buflen); | |
2258 | return os_strlen(buf); | |
2259 | } | |
2260 | ||
2261 | ||
2262 | static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd, | |
2263 | char *buf, size_t buflen) | |
2264 | { | |
2265 | u64 ref; | |
2266 | int res; | |
2267 | u8 dst_buf[ETH_ALEN], *dst; | |
2268 | struct wpabuf *tlvs; | |
2269 | char *pos; | |
2270 | size_t len; | |
2271 | ||
2272 | if (hwaddr_aton(cmd, dst_buf)) | |
2273 | return -1; | |
2274 | dst = dst_buf; | |
2275 | if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 && | |
2276 | dst[3] == 0 && dst[4] == 0 && dst[5] == 0) | |
2277 | dst = NULL; | |
2278 | pos = cmd + 17; | |
2279 | if (*pos != ' ') | |
2280 | return -1; | |
2281 | pos++; | |
2282 | ||
2283 | if (os_strncmp(pos, "upnp ", 5) == 0) { | |
2284 | u8 version; | |
2285 | pos += 5; | |
2286 | if (hexstr2bin(pos, &version, 1) < 0) | |
2287 | return -1; | |
2288 | pos += 2; | |
2289 | if (*pos != ' ') | |
2290 | return -1; | |
2291 | pos++; | |
0423d090 JB |
2292 | ref = (unsigned long) wpas_p2p_sd_request_upnp(wpa_s, dst, |
2293 | version, pos); | |
b563b388 JM |
2294 | } else { |
2295 | len = os_strlen(pos); | |
2296 | if (len & 1) | |
2297 | return -1; | |
2298 | len /= 2; | |
2299 | tlvs = wpabuf_alloc(len); | |
2300 | if (tlvs == NULL) | |
2301 | return -1; | |
2302 | if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) { | |
2303 | wpabuf_free(tlvs); | |
2304 | return -1; | |
2305 | } | |
2306 | ||
0423d090 | 2307 | ref = (unsigned long) wpas_p2p_sd_request(wpa_s, dst, tlvs); |
b563b388 JM |
2308 | wpabuf_free(tlvs); |
2309 | } | |
2310 | res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref); | |
2311 | if (res < 0 || (unsigned) res >= buflen) | |
2312 | return -1; | |
2313 | return res; | |
2314 | } | |
2315 | ||
2316 | ||
2317 | static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s, | |
2318 | char *cmd) | |
2319 | { | |
2320 | long long unsigned val; | |
2321 | u64 req; | |
2322 | if (sscanf(cmd, "%llx", &val) != 1) | |
2323 | return -1; | |
2324 | req = val; | |
0423d090 | 2325 | return wpas_p2p_sd_cancel_request(wpa_s, (void *) (unsigned long) req); |
b563b388 JM |
2326 | } |
2327 | ||
2328 | ||
2329 | static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd) | |
2330 | { | |
2331 | int freq; | |
d25f7212 | 2332 | u8 dst[ETH_ALEN]; |
b563b388 JM |
2333 | u8 dialog_token; |
2334 | struct wpabuf *resp_tlvs; | |
2335 | char *pos, *pos2; | |
2336 | size_t len; | |
2337 | ||
2338 | pos = os_strchr(cmd, ' '); | |
2339 | if (pos == NULL) | |
2340 | return -1; | |
2341 | *pos++ = '\0'; | |
2342 | freq = atoi(cmd); | |
2343 | if (freq == 0) | |
2344 | return -1; | |
2345 | ||
d25f7212 | 2346 | if (hwaddr_aton(pos, dst)) |
b563b388 | 2347 | return -1; |
b563b388 JM |
2348 | pos += 17; |
2349 | if (*pos != ' ') | |
2350 | return -1; | |
2351 | pos++; | |
2352 | ||
2353 | pos2 = os_strchr(pos, ' '); | |
2354 | if (pos2 == NULL) | |
2355 | return -1; | |
2356 | *pos2++ = '\0'; | |
2357 | dialog_token = atoi(pos); | |
2358 | ||
2359 | len = os_strlen(pos2); | |
2360 | if (len & 1) | |
2361 | return -1; | |
2362 | len /= 2; | |
2363 | resp_tlvs = wpabuf_alloc(len); | |
2364 | if (resp_tlvs == NULL) | |
2365 | return -1; | |
2366 | if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) { | |
2367 | wpabuf_free(resp_tlvs); | |
2368 | return -1; | |
2369 | } | |
2370 | ||
2371 | wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs); | |
2372 | wpabuf_free(resp_tlvs); | |
2373 | return 0; | |
2374 | } | |
2375 | ||
2376 | ||
2377 | static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s, | |
2378 | char *cmd) | |
2379 | { | |
2380 | wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd); | |
2381 | return 0; | |
2382 | } | |
2383 | ||
2384 | ||
2385 | static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s, | |
2386 | char *cmd) | |
2387 | { | |
2388 | char *pos; | |
2389 | size_t len; | |
2390 | struct wpabuf *query, *resp; | |
2391 | ||
2392 | pos = os_strchr(cmd, ' '); | |
2393 | if (pos == NULL) | |
2394 | return -1; | |
2395 | *pos++ = '\0'; | |
2396 | ||
2397 | len = os_strlen(cmd); | |
2398 | if (len & 1) | |
2399 | return -1; | |
2400 | len /= 2; | |
2401 | query = wpabuf_alloc(len); | |
2402 | if (query == NULL) | |
2403 | return -1; | |
2404 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | |
2405 | wpabuf_free(query); | |
2406 | return -1; | |
2407 | } | |
2408 | ||
2409 | len = os_strlen(pos); | |
2410 | if (len & 1) { | |
2411 | wpabuf_free(query); | |
2412 | return -1; | |
2413 | } | |
2414 | len /= 2; | |
2415 | resp = wpabuf_alloc(len); | |
2416 | if (resp == NULL) { | |
2417 | wpabuf_free(query); | |
2418 | return -1; | |
2419 | } | |
2420 | if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) { | |
2421 | wpabuf_free(query); | |
2422 | wpabuf_free(resp); | |
2423 | return -1; | |
2424 | } | |
2425 | ||
2426 | if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) { | |
2427 | wpabuf_free(query); | |
2428 | wpabuf_free(resp); | |
2429 | return -1; | |
2430 | } | |
2431 | return 0; | |
2432 | } | |
2433 | ||
2434 | ||
2435 | static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd) | |
2436 | { | |
2437 | char *pos; | |
2438 | u8 version; | |
2439 | ||
2440 | pos = os_strchr(cmd, ' '); | |
2441 | if (pos == NULL) | |
2442 | return -1; | |
2443 | *pos++ = '\0'; | |
2444 | ||
2445 | if (hexstr2bin(cmd, &version, 1) < 0) | |
2446 | return -1; | |
2447 | ||
2448 | return wpas_p2p_service_add_upnp(wpa_s, version, pos); | |
2449 | } | |
2450 | ||
2451 | ||
2452 | static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd) | |
2453 | { | |
2454 | char *pos; | |
2455 | ||
2456 | pos = os_strchr(cmd, ' '); | |
2457 | if (pos == NULL) | |
2458 | return -1; | |
2459 | *pos++ = '\0'; | |
2460 | ||
2461 | if (os_strcmp(cmd, "bonjour") == 0) | |
2462 | return p2p_ctrl_service_add_bonjour(wpa_s, pos); | |
2463 | if (os_strcmp(cmd, "upnp") == 0) | |
2464 | return p2p_ctrl_service_add_upnp(wpa_s, pos); | |
2465 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | |
2466 | return -1; | |
2467 | } | |
2468 | ||
2469 | ||
2470 | static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s, | |
2471 | char *cmd) | |
2472 | { | |
2473 | size_t len; | |
2474 | struct wpabuf *query; | |
2475 | int ret; | |
2476 | ||
2477 | len = os_strlen(cmd); | |
2478 | if (len & 1) | |
2479 | return -1; | |
2480 | len /= 2; | |
2481 | query = wpabuf_alloc(len); | |
2482 | if (query == NULL) | |
2483 | return -1; | |
2484 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | |
2485 | wpabuf_free(query); | |
2486 | return -1; | |
2487 | } | |
2488 | ||
2489 | ret = wpas_p2p_service_del_bonjour(wpa_s, query); | |
2490 | wpabuf_free(query); | |
2491 | return ret; | |
2492 | } | |
2493 | ||
2494 | ||
2495 | static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd) | |
2496 | { | |
2497 | char *pos; | |
2498 | u8 version; | |
2499 | ||
2500 | pos = os_strchr(cmd, ' '); | |
2501 | if (pos == NULL) | |
2502 | return -1; | |
2503 | *pos++ = '\0'; | |
2504 | ||
2505 | if (hexstr2bin(cmd, &version, 1) < 0) | |
2506 | return -1; | |
2507 | ||
2508 | return wpas_p2p_service_del_upnp(wpa_s, version, pos); | |
2509 | } | |
2510 | ||
2511 | ||
2512 | static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd) | |
2513 | { | |
2514 | char *pos; | |
2515 | ||
2516 | pos = os_strchr(cmd, ' '); | |
2517 | if (pos == NULL) | |
2518 | return -1; | |
2519 | *pos++ = '\0'; | |
2520 | ||
2521 | if (os_strcmp(cmd, "bonjour") == 0) | |
2522 | return p2p_ctrl_service_del_bonjour(wpa_s, pos); | |
2523 | if (os_strcmp(cmd, "upnp") == 0) | |
2524 | return p2p_ctrl_service_del_upnp(wpa_s, pos); | |
2525 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | |
2526 | return -1; | |
2527 | } | |
2528 | ||
2529 | ||
2530 | static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd) | |
2531 | { | |
2532 | u8 addr[ETH_ALEN]; | |
2533 | ||
2534 | /* <addr> */ | |
2535 | ||
2536 | if (hwaddr_aton(cmd, addr)) | |
2537 | return -1; | |
2538 | ||
2539 | return wpas_p2p_reject(wpa_s, addr); | |
2540 | } | |
2541 | ||
2542 | ||
2543 | static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd) | |
2544 | { | |
2545 | char *pos; | |
2546 | int id; | |
2547 | struct wpa_ssid *ssid; | |
2548 | u8 peer[ETH_ALEN]; | |
2549 | ||
2550 | id = atoi(cmd); | |
2551 | pos = os_strstr(cmd, " peer="); | |
2552 | if (pos) { | |
2553 | pos += 6; | |
2554 | if (hwaddr_aton(pos, peer)) | |
2555 | return -1; | |
2556 | } | |
2557 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
2558 | if (ssid == NULL || ssid->disabled != 2) { | |
2559 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
2560 | "for persistent P2P group", | |
2561 | id); | |
2562 | return -1; | |
2563 | } | |
2564 | ||
2565 | return wpas_p2p_invite(wpa_s, pos ? peer : NULL, ssid, NULL); | |
2566 | } | |
2567 | ||
2568 | ||
2569 | static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd) | |
2570 | { | |
2571 | char *pos; | |
2572 | u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL; | |
2573 | ||
2574 | pos = os_strstr(cmd, " peer="); | |
2575 | if (!pos) | |
2576 | return -1; | |
2577 | ||
2578 | *pos = '\0'; | |
2579 | pos += 6; | |
2580 | if (hwaddr_aton(pos, peer)) { | |
2581 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos); | |
2582 | return -1; | |
2583 | } | |
2584 | ||
2585 | pos = os_strstr(pos, " go_dev_addr="); | |
2586 | if (pos) { | |
2587 | pos += 13; | |
2588 | if (hwaddr_aton(pos, go_dev_addr)) { | |
2589 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", | |
2590 | pos); | |
2591 | return -1; | |
2592 | } | |
2593 | go_dev = go_dev_addr; | |
2594 | } | |
2595 | ||
2596 | return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev); | |
2597 | } | |
2598 | ||
2599 | ||
2600 | static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd) | |
2601 | { | |
2602 | if (os_strncmp(cmd, "persistent=", 11) == 0) | |
2603 | return p2p_ctrl_invite_persistent(wpa_s, cmd + 11); | |
2604 | if (os_strncmp(cmd, "group=", 6) == 0) | |
2605 | return p2p_ctrl_invite_group(wpa_s, cmd + 6); | |
2606 | ||
2607 | return -1; | |
2608 | } | |
2609 | ||
2610 | ||
2611 | static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, | |
2612 | char *cmd, int freq) | |
2613 | { | |
2614 | int id; | |
2615 | struct wpa_ssid *ssid; | |
2616 | ||
2617 | id = atoi(cmd); | |
2618 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
2619 | if (ssid == NULL || ssid->disabled != 2) { | |
2620 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
2621 | "for persistent P2P group", | |
2622 | id); | |
2623 | return -1; | |
2624 | } | |
2625 | ||
2626 | return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq); | |
2627 | } | |
2628 | ||
2629 | ||
2630 | static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) | |
2631 | { | |
2632 | int freq = 0; | |
2633 | char *pos; | |
2634 | ||
2635 | pos = os_strstr(cmd, "freq="); | |
2636 | if (pos) | |
2637 | freq = atoi(pos + 5); | |
2638 | ||
2639 | if (os_strncmp(cmd, "persistent=", 11) == 0) | |
2640 | return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq); | |
2641 | if (os_strcmp(cmd, "persistent") == 0 || | |
2642 | os_strncmp(cmd, "persistent ", 11) == 0) | |
2643 | return wpas_p2p_group_add(wpa_s, 1, freq); | |
2644 | if (os_strncmp(cmd, "freq=", 5) == 0) | |
2645 | return wpas_p2p_group_add(wpa_s, 0, freq); | |
2646 | ||
2647 | wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'", | |
2648 | cmd); | |
2649 | return -1; | |
2650 | } | |
2651 | ||
2652 | ||
2653 | static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd, | |
2654 | char *buf, size_t buflen) | |
2655 | { | |
2656 | u8 addr[ETH_ALEN], *addr_ptr; | |
2657 | int next; | |
2658 | ||
2659 | if (!wpa_s->global->p2p) | |
2660 | return -1; | |
2661 | ||
2662 | if (os_strcmp(cmd, "FIRST") == 0) { | |
2663 | addr_ptr = NULL; | |
2664 | next = 0; | |
2665 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | |
2666 | if (hwaddr_aton(cmd + 5, addr) < 0) | |
2667 | return -1; | |
2668 | addr_ptr = addr; | |
2669 | next = 1; | |
2670 | } else { | |
2671 | if (hwaddr_aton(cmd, addr) < 0) | |
2672 | return -1; | |
2673 | addr_ptr = addr; | |
2674 | next = 0; | |
2675 | } | |
2676 | ||
2677 | return p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next, | |
2678 | buf, buflen); | |
2679 | } | |
2680 | ||
2681 | ||
2682 | static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) | |
2683 | { | |
2684 | char *param; | |
2685 | ||
2686 | if (wpa_s->global->p2p == NULL) | |
2687 | return -1; | |
2688 | ||
2689 | param = os_strchr(cmd, ' '); | |
2690 | if (param == NULL) | |
2691 | return -1; | |
2692 | *param++ = '\0'; | |
2693 | ||
2694 | if (os_strcmp(cmd, "discoverability") == 0) { | |
2695 | p2p_set_client_discoverability(wpa_s->global->p2p, | |
2696 | atoi(param)); | |
2697 | return 0; | |
2698 | } | |
2699 | ||
2700 | if (os_strcmp(cmd, "managed") == 0) { | |
2701 | p2p_set_managed_oper(wpa_s->global->p2p, atoi(param)); | |
2702 | return 0; | |
2703 | } | |
2704 | ||
2705 | if (os_strcmp(cmd, "listen_channel") == 0) { | |
2706 | return p2p_set_listen_channel(wpa_s->global->p2p, 81, | |
2707 | atoi(param)); | |
2708 | } | |
2709 | ||
2710 | if (os_strcmp(cmd, "ssid_postfix") == 0) { | |
2711 | return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param, | |
2712 | os_strlen(param)); | |
2713 | } | |
2714 | ||
2715 | if (os_strcmp(cmd, "noa") == 0) { | |
2716 | char *pos; | |
2717 | int count, start, duration; | |
2718 | /* GO NoA parameters: count,start_offset(ms),duration(ms) */ | |
2719 | count = atoi(param); | |
2720 | pos = os_strchr(param, ','); | |
2721 | if (pos == NULL) | |
2722 | return -1; | |
2723 | pos++; | |
2724 | start = atoi(pos); | |
2725 | pos = os_strchr(pos, ','); | |
2726 | if (pos == NULL) | |
2727 | return -1; | |
2728 | pos++; | |
2729 | duration = atoi(pos); | |
2730 | if (count < 0 || count > 255 || start < 0 || duration < 0) | |
2731 | return -1; | |
2732 | if (count == 0 && duration > 0) | |
2733 | return -1; | |
2734 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d " | |
2735 | "start=%d duration=%d", count, start, duration); | |
aefb53bd | 2736 | return wpas_p2p_set_noa(wpa_s, count, start, duration); |
b563b388 JM |
2737 | } |
2738 | ||
c381508d JM |
2739 | if (os_strcmp(cmd, "ps") == 0) |
2740 | return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1); | |
2741 | ||
2742 | if (os_strcmp(cmd, "oppps") == 0) | |
2743 | return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1); | |
2744 | ||
2745 | if (os_strcmp(cmd, "ctwindow") == 0) | |
2746 | return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param)); | |
2747 | ||
b563b388 JM |
2748 | if (os_strcmp(cmd, "disabled") == 0) { |
2749 | wpa_s->global->p2p_disabled = atoi(param); | |
2750 | wpa_printf(MSG_DEBUG, "P2P functionality %s", | |
2751 | wpa_s->global->p2p_disabled ? | |
2752 | "disabled" : "enabled"); | |
2753 | if (wpa_s->global->p2p_disabled) { | |
2754 | wpas_p2p_stop_find(wpa_s); | |
108def93 | 2755 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
b563b388 JM |
2756 | p2p_flush(wpa_s->global->p2p); |
2757 | } | |
2758 | return 0; | |
2759 | } | |
2760 | ||
6e6963ea JM |
2761 | if (os_strcmp(cmd, "force_long_sd") == 0) { |
2762 | wpa_s->force_long_sd = atoi(param); | |
2763 | return 0; | |
2764 | } | |
2765 | ||
80c9582a JM |
2766 | if (os_strcmp(cmd, "peer_filter") == 0) { |
2767 | u8 addr[ETH_ALEN]; | |
2768 | if (hwaddr_aton(param, addr)) | |
2769 | return -1; | |
2770 | p2p_set_peer_filter(wpa_s->global->p2p, addr); | |
2771 | return 0; | |
2772 | } | |
2773 | ||
72044390 JM |
2774 | if (os_strcmp(cmd, "cross_connect") == 0) |
2775 | return wpas_p2p_set_cross_connect(wpa_s, atoi(param)); | |
2776 | ||
eea2fd9e JM |
2777 | if (os_strcmp(cmd, "go_apsd") == 0) { |
2778 | if (os_strcmp(param, "disable") == 0) | |
2779 | wpa_s->set_ap_uapsd = 0; | |
2780 | else { | |
2781 | wpa_s->set_ap_uapsd = 1; | |
2782 | wpa_s->ap_uapsd = atoi(param); | |
2783 | } | |
2784 | return 0; | |
2785 | } | |
2786 | ||
2787 | if (os_strcmp(cmd, "client_apsd") == 0) { | |
2788 | if (os_strcmp(param, "disable") == 0) | |
2789 | wpa_s->set_sta_uapsd = 0; | |
2790 | else { | |
2791 | int be, bk, vi, vo; | |
2792 | char *pos; | |
2793 | /* format: BE,BK,VI,VO;max SP Length */ | |
2794 | be = atoi(param); | |
2795 | pos = os_strchr(param, ','); | |
2796 | if (pos == NULL) | |
2797 | return -1; | |
2798 | pos++; | |
2799 | bk = atoi(pos); | |
2800 | pos = os_strchr(pos, ','); | |
2801 | if (pos == NULL) | |
2802 | return -1; | |
2803 | pos++; | |
2804 | vi = atoi(pos); | |
2805 | pos = os_strchr(pos, ','); | |
2806 | if (pos == NULL) | |
2807 | return -1; | |
2808 | pos++; | |
2809 | vo = atoi(pos); | |
2810 | /* ignore max SP Length for now */ | |
2811 | ||
2812 | wpa_s->set_sta_uapsd = 1; | |
2813 | wpa_s->sta_uapsd = 0; | |
2814 | if (be) | |
2815 | wpa_s->sta_uapsd |= BIT(0); | |
2816 | if (bk) | |
2817 | wpa_s->sta_uapsd |= BIT(1); | |
2818 | if (vi) | |
2819 | wpa_s->sta_uapsd |= BIT(2); | |
2820 | if (vo) | |
2821 | wpa_s->sta_uapsd |= BIT(3); | |
2822 | } | |
2823 | return 0; | |
2824 | } | |
2825 | ||
b563b388 JM |
2826 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", |
2827 | cmd); | |
2828 | ||
2829 | return -1; | |
2830 | } | |
2831 | ||
2832 | ||
2833 | static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd) | |
2834 | { | |
2835 | char *pos, *pos2; | |
2836 | unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0; | |
2837 | ||
2838 | if (cmd[0]) { | |
2839 | pos = os_strchr(cmd, ' '); | |
2840 | if (pos == NULL) | |
2841 | return -1; | |
2842 | *pos++ = '\0'; | |
2843 | dur1 = atoi(cmd); | |
2844 | ||
2845 | pos2 = os_strchr(pos, ' '); | |
2846 | if (pos2) | |
2847 | *pos2++ = '\0'; | |
2848 | int1 = atoi(pos); | |
2849 | } else | |
2850 | pos2 = NULL; | |
2851 | ||
2852 | if (pos2) { | |
2853 | pos = os_strchr(pos2, ' '); | |
2854 | if (pos == NULL) | |
2855 | return -1; | |
2856 | *pos++ = '\0'; | |
2857 | dur2 = atoi(pos2); | |
2858 | int2 = atoi(pos); | |
2859 | } | |
2860 | ||
2861 | return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2); | |
2862 | } | |
2863 | ||
2864 | ||
2865 | static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) | |
2866 | { | |
2867 | char *pos; | |
2868 | unsigned int period = 0, interval = 0; | |
2869 | ||
2870 | if (cmd[0]) { | |
2871 | pos = os_strchr(cmd, ' '); | |
2872 | if (pos == NULL) | |
2873 | return -1; | |
2874 | *pos++ = '\0'; | |
2875 | period = atoi(cmd); | |
2876 | interval = atoi(pos); | |
2877 | } | |
2878 | ||
2879 | return wpas_p2p_ext_listen(wpa_s, period, interval); | |
2880 | } | |
2881 | ||
2882 | #endif /* CONFIG_P2P */ | |
2883 | ||
2884 | ||
0d0a8ca1 AC |
2885 | static int wpa_supplicant_ctrl_iface_sta_autoconnect( |
2886 | struct wpa_supplicant *wpa_s, char *cmd) | |
2887 | { | |
2888 | wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0; | |
2889 | return 0; | |
2890 | } | |
2891 | ||
2892 | ||
60b24b0d DS |
2893 | static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, |
2894 | size_t buflen) | |
2895 | { | |
2896 | struct wpa_signal_info si; | |
2897 | int ret; | |
2898 | ||
2899 | ret = wpa_drv_signal_poll(wpa_s, &si); | |
2900 | if (ret) | |
2901 | return -1; | |
2902 | ||
2903 | ret = os_snprintf(buf, buflen, "RSSI=%d\nLINKSPEED=%d\n" | |
2904 | "NOISE=%d\nFREQUENCY=%u\n", | |
2905 | si.current_signal, si.current_txrate / 1000, | |
2906 | si.current_noise, si.frequency); | |
2907 | if (ret < 0 || (unsigned int) ret > buflen) | |
2908 | return -1; | |
2909 | return ret; | |
2910 | } | |
2911 | ||
2912 | ||
6fc6879b JM |
2913 | char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, |
2914 | char *buf, size_t *resp_len) | |
2915 | { | |
2916 | char *reply; | |
b563b388 | 2917 | const int reply_size = 4096; |
6fc6879b JM |
2918 | int ctrl_rsp = 0; |
2919 | int reply_len; | |
2920 | ||
2921 | if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 || | |
2922 | os_strncmp(buf, "SET_NETWORK ", 12) == 0) { | |
2923 | wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", | |
2924 | (const u8 *) buf, os_strlen(buf)); | |
2925 | } else { | |
235f69fc JM |
2926 | int level = MSG_DEBUG; |
2927 | if (os_strcmp(buf, "PING") == 0) | |
2928 | level = MSG_EXCESSIVE; | |
2929 | wpa_hexdump_ascii(level, "RX ctrl_iface", | |
6fc6879b JM |
2930 | (const u8 *) buf, os_strlen(buf)); |
2931 | } | |
2932 | ||
2933 | reply = os_malloc(reply_size); | |
2934 | if (reply == NULL) { | |
2935 | *resp_len = 1; | |
2936 | return NULL; | |
2937 | } | |
2938 | ||
2939 | os_memcpy(reply, "OK\n", 3); | |
2940 | reply_len = 3; | |
2941 | ||
2942 | if (os_strcmp(buf, "PING") == 0) { | |
2943 | os_memcpy(reply, "PONG\n", 5); | |
2944 | reply_len = 5; | |
ac6912b5 BG |
2945 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
2946 | if (wpa_debug_reopen_file() < 0) | |
2947 | reply_len = -1; | |
77895cd9 JM |
2948 | } else if (os_strncmp(buf, "NOTE ", 5) == 0) { |
2949 | wpa_printf(MSG_INFO, "NOTE: %s", buf + 5); | |
6fc6879b JM |
2950 | } else if (os_strcmp(buf, "MIB") == 0) { |
2951 | reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); | |
2952 | if (reply_len >= 0) { | |
2953 | int res; | |
2954 | res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len, | |
2955 | reply_size - reply_len); | |
2956 | if (res < 0) | |
2957 | reply_len = -1; | |
2958 | else | |
2959 | reply_len += res; | |
2960 | } | |
2961 | } else if (os_strncmp(buf, "STATUS", 6) == 0) { | |
2962 | reply_len = wpa_supplicant_ctrl_iface_status( | |
2963 | wpa_s, buf + 6, reply, reply_size); | |
2964 | } else if (os_strcmp(buf, "PMKSA") == 0) { | |
540264a7 JM |
2965 | reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply, |
2966 | reply_size); | |
6fc6879b JM |
2967 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
2968 | if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) | |
2969 | reply_len = -1; | |
acec8d32 JM |
2970 | } else if (os_strncmp(buf, "GET ", 4) == 0) { |
2971 | reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4, | |
2972 | reply, reply_size); | |
6fc6879b JM |
2973 | } else if (os_strcmp(buf, "LOGON") == 0) { |
2974 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); | |
2975 | } else if (os_strcmp(buf, "LOGOFF") == 0) { | |
2976 | eapol_sm_notify_logoff(wpa_s->eapol, TRUE); | |
2977 | } else if (os_strcmp(buf, "REASSOCIATE") == 0) { | |
8401a6b0 JM |
2978 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
2979 | reply_len = -1; | |
2980 | else { | |
2981 | wpa_s->disconnected = 0; | |
2982 | wpa_s->reassociate = 1; | |
2983 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
2984 | } | |
6fc6879b | 2985 | } else if (os_strcmp(buf, "RECONNECT") == 0) { |
8401a6b0 JM |
2986 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
2987 | reply_len = -1; | |
2988 | else if (wpa_s->disconnected) { | |
6fc6879b JM |
2989 | wpa_s->disconnected = 0; |
2990 | wpa_s->reassociate = 1; | |
2991 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
2992 | } | |
ec717917 | 2993 | #ifdef IEEE8021X_EAPOL |
6fc6879b JM |
2994 | } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { |
2995 | if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) | |
2996 | reply_len = -1; | |
ec717917 | 2997 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
2998 | #ifdef CONFIG_PEERKEY |
2999 | } else if (os_strncmp(buf, "STKSTART ", 9) == 0) { | |
3000 | if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9)) | |
3001 | reply_len = -1; | |
3002 | #endif /* CONFIG_PEERKEY */ | |
3003 | #ifdef CONFIG_IEEE80211R | |
3004 | } else if (os_strncmp(buf, "FT_DS ", 6) == 0) { | |
3005 | if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6)) | |
3006 | reply_len = -1; | |
3007 | #endif /* CONFIG_IEEE80211R */ | |
fcc60db4 JM |
3008 | #ifdef CONFIG_WPS |
3009 | } else if (os_strcmp(buf, "WPS_PBC") == 0) { | |
3152ff42 CWY |
3010 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL); |
3011 | if (res == -2) { | |
3012 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
3013 | reply_len = 17; | |
3014 | } else if (res) | |
fcc60db4 JM |
3015 | reply_len = -1; |
3016 | } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) { | |
3152ff42 CWY |
3017 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8); |
3018 | if (res == -2) { | |
3019 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
3020 | reply_len = 17; | |
3021 | } else if (res) | |
fcc60db4 JM |
3022 | reply_len = -1; |
3023 | } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) { | |
3024 | reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8, | |
3025 | reply, | |
3026 | reply_size); | |
3981cb3c JM |
3027 | } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) { |
3028 | reply_len = wpa_supplicant_ctrl_iface_wps_check_pin( | |
3029 | wpa_s, buf + 14, reply, reply_size); | |
2f9929ff AC |
3030 | } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { |
3031 | if (wpas_wps_cancel(wpa_s)) | |
3032 | reply_len = -1; | |
116f7bb0 | 3033 | #ifdef CONFIG_WPS_OOB |
46bdb83a MH |
3034 | } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) { |
3035 | if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8)) | |
3036 | reply_len = -1; | |
116f7bb0 | 3037 | #endif /* CONFIG_WPS_OOB */ |
fcc60db4 JM |
3038 | } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) { |
3039 | if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8)) | |
3040 | reply_len = -1; | |
70d84f11 JM |
3041 | #ifdef CONFIG_AP |
3042 | } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) { | |
3043 | reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin( | |
3044 | wpa_s, buf + 11, reply, reply_size); | |
3045 | #endif /* CONFIG_AP */ | |
72df2f5f | 3046 | #ifdef CONFIG_WPS_ER |
e9bcfebf | 3047 | } else if (os_strcmp(buf, "WPS_ER_START") == 0) { |
08486685 JM |
3048 | if (wpas_wps_er_start(wpa_s, NULL)) |
3049 | reply_len = -1; | |
3050 | } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) { | |
3051 | if (wpas_wps_er_start(wpa_s, buf + 13)) | |
e9bcfebf JM |
3052 | reply_len = -1; |
3053 | } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) { | |
3054 | if (wpas_wps_er_stop(wpa_s)) | |
3055 | reply_len = -1; | |
72df2f5f JM |
3056 | } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) { |
3057 | if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11)) | |
3058 | reply_len = -1; | |
564cd7fa | 3059 | } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) { |
ed159ad4 JM |
3060 | int ret = wpas_wps_er_pbc(wpa_s, buf + 11); |
3061 | if (ret == -2) { | |
3062 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
3063 | reply_len = 17; | |
3064 | } else if (ret == -3) { | |
3065 | os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18); | |
3066 | reply_len = 18; | |
3067 | } else if (ret == -4) { | |
3068 | os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20); | |
3069 | reply_len = 20; | |
3070 | } else if (ret) | |
564cd7fa | 3071 | reply_len = -1; |
e64dcfd5 JM |
3072 | } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) { |
3073 | if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13)) | |
3074 | reply_len = -1; | |
ef10f473 JM |
3075 | } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) { |
3076 | if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s, | |
3077 | buf + 18)) | |
3078 | reply_len = -1; | |
7d6640a6 JM |
3079 | } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) { |
3080 | if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14)) | |
3081 | reply_len = -1; | |
72df2f5f | 3082 | #endif /* CONFIG_WPS_ER */ |
fcc60db4 | 3083 | #endif /* CONFIG_WPS */ |
11ef8d35 JM |
3084 | #ifdef CONFIG_IBSS_RSN |
3085 | } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) { | |
3086 | if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) | |
3087 | reply_len = -1; | |
3088 | #endif /* CONFIG_IBSS_RSN */ | |
b563b388 JM |
3089 | #ifdef CONFIG_P2P |
3090 | } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { | |
3091 | if (p2p_ctrl_find(wpa_s, buf + 9)) | |
3092 | reply_len = -1; | |
3093 | } else if (os_strcmp(buf, "P2P_FIND") == 0) { | |
3094 | if (p2p_ctrl_find(wpa_s, "")) | |
3095 | reply_len = -1; | |
3096 | } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) { | |
3097 | wpas_p2p_stop_find(wpa_s); | |
3098 | } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) { | |
3099 | reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply, | |
3100 | reply_size); | |
3101 | } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) { | |
3102 | if (p2p_ctrl_listen(wpa_s, buf + 11)) | |
3103 | reply_len = -1; | |
3104 | } else if (os_strcmp(buf, "P2P_LISTEN") == 0) { | |
3105 | if (p2p_ctrl_listen(wpa_s, "")) | |
3106 | reply_len = -1; | |
3107 | } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) { | |
3108 | if (wpas_p2p_group_remove(wpa_s, buf + 17)) | |
3109 | reply_len = -1; | |
3110 | } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) { | |
3111 | if (wpas_p2p_group_add(wpa_s, 0, 0)) | |
3112 | reply_len = -1; | |
3113 | } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) { | |
3114 | if (p2p_ctrl_group_add(wpa_s, buf + 14)) | |
3115 | reply_len = -1; | |
3116 | } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) { | |
3117 | if (p2p_ctrl_prov_disc(wpa_s, buf + 14)) | |
3118 | reply_len = -1; | |
3119 | } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) { | |
3120 | reply_len = p2p_get_passphrase(wpa_s, reply, reply_size); | |
3121 | } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) { | |
3122 | reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply, | |
3123 | reply_size); | |
3124 | } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) { | |
3125 | if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0) | |
3126 | reply_len = -1; | |
3127 | } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) { | |
3128 | if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0) | |
3129 | reply_len = -1; | |
3130 | } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) { | |
3131 | wpas_p2p_sd_service_update(wpa_s); | |
3132 | } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) { | |
3133 | if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0) | |
3134 | reply_len = -1; | |
3135 | } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) { | |
3136 | wpas_p2p_service_flush(wpa_s); | |
3137 | } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) { | |
3138 | if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0) | |
3139 | reply_len = -1; | |
3140 | } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) { | |
3141 | if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0) | |
3142 | reply_len = -1; | |
3143 | } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) { | |
3144 | if (p2p_ctrl_reject(wpa_s, buf + 11) < 0) | |
3145 | reply_len = -1; | |
3146 | } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) { | |
3147 | if (p2p_ctrl_invite(wpa_s, buf + 11) < 0) | |
3148 | reply_len = -1; | |
3149 | } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) { | |
3150 | reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply, | |
3151 | reply_size); | |
3152 | } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) { | |
3153 | if (p2p_ctrl_set(wpa_s, buf + 8) < 0) | |
3154 | reply_len = -1; | |
3155 | } else if (os_strcmp(buf, "P2P_FLUSH") == 0) { | |
108def93 | 3156 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
6e6963ea | 3157 | wpa_s->force_long_sd = 0; |
9526fd29 JM |
3158 | if (wpa_s->global->p2p) |
3159 | p2p_flush(wpa_s->global->p2p); | |
9d562b79 SS |
3160 | } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { |
3161 | if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) | |
3162 | reply_len = -1; | |
59eba7a2 JM |
3163 | } else if (os_strcmp(buf, "P2P_CANCEL") == 0) { |
3164 | if (wpas_p2p_cancel(wpa_s)) | |
3165 | reply_len = -1; | |
b563b388 JM |
3166 | } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) { |
3167 | if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0) | |
3168 | reply_len = -1; | |
3169 | } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) { | |
3170 | if (p2p_ctrl_presence_req(wpa_s, "") < 0) | |
3171 | reply_len = -1; | |
3172 | } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) { | |
3173 | if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0) | |
3174 | reply_len = -1; | |
3175 | } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) { | |
3176 | if (p2p_ctrl_ext_listen(wpa_s, "") < 0) | |
3177 | reply_len = -1; | |
3178 | #endif /* CONFIG_P2P */ | |
6fc6879b JM |
3179 | } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) |
3180 | { | |
3181 | if (wpa_supplicant_ctrl_iface_ctrl_rsp( | |
3182 | wpa_s, buf + os_strlen(WPA_CTRL_RSP))) | |
3183 | reply_len = -1; | |
3184 | else | |
3185 | ctrl_rsp = 1; | |
3186 | } else if (os_strcmp(buf, "RECONFIGURE") == 0) { | |
3187 | if (wpa_supplicant_reload_configuration(wpa_s)) | |
3188 | reply_len = -1; | |
3189 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | |
1a1bf008 | 3190 | wpa_supplicant_terminate_proc(wpa_s->global); |
6fc6879b JM |
3191 | } else if (os_strncmp(buf, "BSSID ", 6) == 0) { |
3192 | if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) | |
3193 | reply_len = -1; | |
3194 | } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { | |
3195 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | |
3196 | wpa_s, reply, reply_size); | |
3197 | } else if (os_strcmp(buf, "DISCONNECT") == 0) { | |
3198 | wpa_s->reassociate = 0; | |
3199 | wpa_s->disconnected = 1; | |
cf4783e3 JM |
3200 | wpa_supplicant_deauthenticate(wpa_s, |
3201 | WLAN_REASON_DEAUTH_LEAVING); | |
6fc6879b | 3202 | } else if (os_strcmp(buf, "SCAN") == 0) { |
8401a6b0 JM |
3203 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
3204 | reply_len = -1; | |
3205 | else { | |
746bba1a DS |
3206 | if (!wpa_s->scanning && |
3207 | ((wpa_s->wpa_state <= WPA_SCANNING) || | |
3208 | (wpa_s->wpa_state == WPA_COMPLETED))) { | |
3209 | wpa_s->scan_req = 2; | |
3210 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
3211 | } else { | |
3212 | wpa_printf(MSG_DEBUG, "Ongoing scan action - " | |
3213 | "reject new request"); | |
3214 | reply_len = os_snprintf(reply, reply_size, | |
3215 | "FAIL-BUSY\n"); | |
3216 | } | |
8401a6b0 | 3217 | } |
6fc6879b JM |
3218 | } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { |
3219 | reply_len = wpa_supplicant_ctrl_iface_scan_results( | |
3220 | wpa_s, reply, reply_size); | |
3221 | } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { | |
3222 | if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) | |
3223 | reply_len = -1; | |
3224 | } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { | |
3225 | if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) | |
3226 | reply_len = -1; | |
3227 | } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { | |
3228 | if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) | |
3229 | reply_len = -1; | |
3230 | } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { | |
3231 | reply_len = wpa_supplicant_ctrl_iface_add_network( | |
3232 | wpa_s, reply, reply_size); | |
3233 | } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { | |
3234 | if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) | |
3235 | reply_len = -1; | |
3236 | } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { | |
3237 | if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) | |
3238 | reply_len = -1; | |
3239 | } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { | |
3240 | reply_len = wpa_supplicant_ctrl_iface_get_network( | |
3241 | wpa_s, buf + 12, reply, reply_size); | |
3242 | #ifndef CONFIG_NO_CONFIG_WRITE | |
3243 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | |
3244 | if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) | |
3245 | reply_len = -1; | |
3246 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
3247 | } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { | |
3248 | reply_len = wpa_supplicant_ctrl_iface_get_capability( | |
3249 | wpa_s, buf + 15, reply, reply_size); | |
3250 | } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { | |
3251 | if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) | |
3252 | reply_len = -1; | |
67b9bd08 DS |
3253 | } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) { |
3254 | if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14)) | |
3255 | reply_len = -1; | |
4b4a8ae5 JM |
3256 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
3257 | reply_len = wpa_supplicant_global_iface_list( | |
3258 | wpa_s->global, reply, reply_size); | |
6fc6879b JM |
3259 | } else if (os_strcmp(buf, "INTERFACES") == 0) { |
3260 | reply_len = wpa_supplicant_global_iface_interfaces( | |
3261 | wpa_s->global, reply, reply_size); | |
3262 | } else if (os_strncmp(buf, "BSS ", 4) == 0) { | |
3263 | reply_len = wpa_supplicant_ctrl_iface_bss( | |
3264 | wpa_s, buf + 4, reply, reply_size); | |
e653b622 JM |
3265 | #ifdef CONFIG_AP |
3266 | } else if (os_strcmp(buf, "STA-FIRST") == 0) { | |
3267 | reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size); | |
3268 | } else if (os_strncmp(buf, "STA ", 4) == 0) { | |
3269 | reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply, | |
3270 | reply_size); | |
3271 | } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { | |
3272 | reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply, | |
3273 | reply_size); | |
3274 | #endif /* CONFIG_AP */ | |
207ef3fb JM |
3275 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
3276 | wpas_notify_suspend(wpa_s->global); | |
3277 | } else if (os_strcmp(buf, "RESUME") == 0) { | |
3278 | wpas_notify_resume(wpa_s->global); | |
32d5295f JM |
3279 | } else if (os_strcmp(buf, "DROP_SA") == 0) { |
3280 | wpa_supplicant_ctrl_iface_drop_sa(wpa_s); | |
86d4f806 JM |
3281 | } else if (os_strncmp(buf, "ROAM ", 5) == 0) { |
3282 | if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) | |
3283 | reply_len = -1; | |
0d0a8ca1 AC |
3284 | } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { |
3285 | if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16)) | |
3286 | reply_len = -1; | |
78633c37 SL |
3287 | } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) { |
3288 | if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15)) | |
3289 | reply_len = -1; | |
3290 | } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) { | |
3291 | if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s, | |
3292 | buf + 17)) | |
3293 | reply_len = -1; | |
281ff0aa GP |
3294 | #ifdef CONFIG_TDLS |
3295 | } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) { | |
3296 | if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14)) | |
3297 | reply_len = -1; | |
3298 | } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) { | |
3299 | if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11)) | |
3300 | reply_len = -1; | |
3301 | } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) { | |
3302 | if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14)) | |
3303 | reply_len = -1; | |
3304 | #endif /* CONFIG_TDLS */ | |
60b24b0d DS |
3305 | } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) { |
3306 | reply_len = wpa_supplicant_signal_poll(wpa_s, reply, | |
3307 | reply_size); | |
6fc6879b JM |
3308 | } else { |
3309 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | |
3310 | reply_len = 16; | |
3311 | } | |
3312 | ||
3313 | if (reply_len < 0) { | |
3314 | os_memcpy(reply, "FAIL\n", 5); | |
3315 | reply_len = 5; | |
3316 | } | |
3317 | ||
3318 | if (ctrl_rsp) | |
3319 | eapol_sm_notify_ctrl_response(wpa_s->eapol); | |
3320 | ||
3321 | *resp_len = reply_len; | |
3322 | return reply; | |
3323 | } | |
3324 | ||
3325 | ||
3326 | static int wpa_supplicant_global_iface_add(struct wpa_global *global, | |
3327 | char *cmd) | |
3328 | { | |
3329 | struct wpa_interface iface; | |
3330 | char *pos; | |
3331 | ||
3332 | /* | |
3333 | * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param> | |
3334 | * TAB<bridge_ifname> | |
3335 | */ | |
3336 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd); | |
3337 | ||
3338 | os_memset(&iface, 0, sizeof(iface)); | |
3339 | ||
3340 | do { | |
3341 | iface.ifname = pos = cmd; | |
3342 | pos = os_strchr(pos, '\t'); | |
3343 | if (pos) | |
3344 | *pos++ = '\0'; | |
3345 | if (iface.ifname[0] == '\0') | |
3346 | return -1; | |
3347 | if (pos == NULL) | |
3348 | break; | |
3349 | ||
3350 | iface.confname = pos; | |
3351 | pos = os_strchr(pos, '\t'); | |
3352 | if (pos) | |
3353 | *pos++ = '\0'; | |
3354 | if (iface.confname[0] == '\0') | |
3355 | iface.confname = NULL; | |
3356 | if (pos == NULL) | |
3357 | break; | |
3358 | ||
3359 | iface.driver = pos; | |
3360 | pos = os_strchr(pos, '\t'); | |
3361 | if (pos) | |
3362 | *pos++ = '\0'; | |
3363 | if (iface.driver[0] == '\0') | |
3364 | iface.driver = NULL; | |
3365 | if (pos == NULL) | |
3366 | break; | |
3367 | ||
3368 | iface.ctrl_interface = pos; | |
3369 | pos = os_strchr(pos, '\t'); | |
3370 | if (pos) | |
3371 | *pos++ = '\0'; | |
3372 | if (iface.ctrl_interface[0] == '\0') | |
3373 | iface.ctrl_interface = NULL; | |
3374 | if (pos == NULL) | |
3375 | break; | |
3376 | ||
3377 | iface.driver_param = pos; | |
3378 | pos = os_strchr(pos, '\t'); | |
3379 | if (pos) | |
3380 | *pos++ = '\0'; | |
3381 | if (iface.driver_param[0] == '\0') | |
3382 | iface.driver_param = NULL; | |
3383 | if (pos == NULL) | |
3384 | break; | |
3385 | ||
3386 | iface.bridge_ifname = pos; | |
3387 | pos = os_strchr(pos, '\t'); | |
3388 | if (pos) | |
3389 | *pos++ = '\0'; | |
3390 | if (iface.bridge_ifname[0] == '\0') | |
3391 | iface.bridge_ifname = NULL; | |
3392 | if (pos == NULL) | |
3393 | break; | |
3394 | } while (0); | |
3395 | ||
3396 | if (wpa_supplicant_get_iface(global, iface.ifname)) | |
3397 | return -1; | |
3398 | ||
3399 | return wpa_supplicant_add_iface(global, &iface) ? 0 : -1; | |
3400 | } | |
3401 | ||
3402 | ||
3403 | static int wpa_supplicant_global_iface_remove(struct wpa_global *global, | |
3404 | char *cmd) | |
3405 | { | |
3406 | struct wpa_supplicant *wpa_s; | |
3407 | ||
3408 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd); | |
3409 | ||
3410 | wpa_s = wpa_supplicant_get_iface(global, cmd); | |
3411 | if (wpa_s == NULL) | |
3412 | return -1; | |
3413 | return wpa_supplicant_remove_iface(global, wpa_s); | |
3414 | } | |
3415 | ||
3416 | ||
4b4a8ae5 JM |
3417 | static void wpa_free_iface_info(struct wpa_interface_info *iface) |
3418 | { | |
3419 | struct wpa_interface_info *prev; | |
3420 | ||
3421 | while (iface) { | |
3422 | prev = iface; | |
3423 | iface = iface->next; | |
3424 | ||
3425 | os_free(prev->ifname); | |
3426 | os_free(prev->desc); | |
3427 | os_free(prev); | |
3428 | } | |
3429 | } | |
3430 | ||
3431 | ||
3432 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, | |
3433 | char *buf, int len) | |
3434 | { | |
3435 | int i, res; | |
3436 | struct wpa_interface_info *iface = NULL, *last = NULL, *tmp; | |
3437 | char *pos, *end; | |
3438 | ||
c5121837 JM |
3439 | for (i = 0; wpa_drivers[i]; i++) { |
3440 | struct wpa_driver_ops *drv = wpa_drivers[i]; | |
4b4a8ae5 JM |
3441 | if (drv->get_interfaces == NULL) |
3442 | continue; | |
5fbc1f27 | 3443 | tmp = drv->get_interfaces(global->drv_priv[i]); |
4b4a8ae5 JM |
3444 | if (tmp == NULL) |
3445 | continue; | |
3446 | ||
3447 | if (last == NULL) | |
3448 | iface = last = tmp; | |
3449 | else | |
3450 | last->next = tmp; | |
3451 | while (last->next) | |
3452 | last = last->next; | |
3453 | } | |
3454 | ||
3455 | pos = buf; | |
3456 | end = buf + len; | |
3457 | for (tmp = iface; tmp; tmp = tmp->next) { | |
3458 | res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n", | |
3459 | tmp->drv_name, tmp->ifname, | |
3460 | tmp->desc ? tmp->desc : ""); | |
3461 | if (res < 0 || res >= end - pos) { | |
3462 | *pos = '\0'; | |
3463 | break; | |
3464 | } | |
3465 | pos += res; | |
3466 | } | |
3467 | ||
3468 | wpa_free_iface_info(iface); | |
3469 | ||
3470 | return pos - buf; | |
3471 | } | |
3472 | ||
3473 | ||
6fc6879b JM |
3474 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
3475 | char *buf, int len) | |
3476 | { | |
3477 | int res; | |
3478 | char *pos, *end; | |
3479 | struct wpa_supplicant *wpa_s; | |
3480 | ||
3481 | wpa_s = global->ifaces; | |
3482 | pos = buf; | |
3483 | end = buf + len; | |
3484 | ||
3485 | while (wpa_s) { | |
3486 | res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname); | |
3487 | if (res < 0 || res >= end - pos) { | |
3488 | *pos = '\0'; | |
3489 | break; | |
3490 | } | |
3491 | pos += res; | |
3492 | wpa_s = wpa_s->next; | |
3493 | } | |
3494 | return pos - buf; | |
3495 | } | |
3496 | ||
3497 | ||
3498 | char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, | |
3499 | char *buf, size_t *resp_len) | |
3500 | { | |
3501 | char *reply; | |
3502 | const int reply_size = 2048; | |
3503 | int reply_len; | |
f4a0a82c | 3504 | int level = MSG_DEBUG; |
6fc6879b | 3505 | |
f4a0a82c JM |
3506 | if (os_strcmp(buf, "PING") == 0) |
3507 | level = MSG_EXCESSIVE; | |
3508 | wpa_hexdump_ascii(level, "RX global ctrl_iface", | |
6fc6879b JM |
3509 | (const u8 *) buf, os_strlen(buf)); |
3510 | ||
3511 | reply = os_malloc(reply_size); | |
3512 | if (reply == NULL) { | |
3513 | *resp_len = 1; | |
3514 | return NULL; | |
3515 | } | |
3516 | ||
3517 | os_memcpy(reply, "OK\n", 3); | |
3518 | reply_len = 3; | |
3519 | ||
3520 | if (os_strcmp(buf, "PING") == 0) { | |
3521 | os_memcpy(reply, "PONG\n", 5); | |
3522 | reply_len = 5; | |
3523 | } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) { | |
3524 | if (wpa_supplicant_global_iface_add(global, buf + 14)) | |
3525 | reply_len = -1; | |
3526 | } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) { | |
3527 | if (wpa_supplicant_global_iface_remove(global, buf + 17)) | |
3528 | reply_len = -1; | |
4b4a8ae5 JM |
3529 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
3530 | reply_len = wpa_supplicant_global_iface_list( | |
3531 | global, reply, reply_size); | |
6fc6879b JM |
3532 | } else if (os_strcmp(buf, "INTERFACES") == 0) { |
3533 | reply_len = wpa_supplicant_global_iface_interfaces( | |
3534 | global, reply, reply_size); | |
3535 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | |
1a1bf008 | 3536 | wpa_supplicant_terminate_proc(global); |
207ef3fb JM |
3537 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
3538 | wpas_notify_suspend(global); | |
3539 | } else if (os_strcmp(buf, "RESUME") == 0) { | |
3540 | wpas_notify_resume(global); | |
6fc6879b JM |
3541 | } else { |
3542 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | |
3543 | reply_len = 16; | |
3544 | } | |
3545 | ||
3546 | if (reply_len < 0) { | |
3547 | os_memcpy(reply, "FAIL\n", 5); | |
3548 | reply_len = 5; | |
3549 | } | |
3550 | ||
3551 | *resp_len = reply_len; | |
3552 | return reply; | |
3553 | } |