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