]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant / Control interface (shared code for all backends) | |
1cea09a9 | 3 | * Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi> |
6fc6879b | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
6fc6879b JM |
7 | */ |
8 | ||
3a068632 | 9 | #include "utils/includes.h" |
6fc6879b | 10 | |
3a068632 JM |
11 | #include "utils/common.h" |
12 | #include "utils/eloop.h" | |
acec8d32 | 13 | #include "common/version.h" |
3a068632 JM |
14 | #include "common/ieee802_11_defs.h" |
15 | #include "common/wpa_ctrl.h" | |
16 | #include "eap_peer/eap.h" | |
17 | #include "eapol_supp/eapol_supp_sm.h" | |
3acb5005 | 18 | #include "rsn_supp/wpa.h" |
3a068632 JM |
19 | #include "rsn_supp/preauth.h" |
20 | #include "rsn_supp/pmksa_cache.h" | |
21 | #include "l2_packet/l2_packet.h" | |
22 | #include "wps/wps.h" | |
6fc6879b | 23 | #include "config.h" |
6fc6879b | 24 | #include "wpa_supplicant_i.h" |
2d5b792d | 25 | #include "driver_i.h" |
fcc60db4 | 26 | #include "wps_supplicant.h" |
11ef8d35 | 27 | #include "ibss_rsn.h" |
3ec97afe | 28 | #include "ap.h" |
b563b388 JM |
29 | #include "p2p_supplicant.h" |
30 | #include "p2p/p2p.h" | |
a8918e86 | 31 | #include "hs20_supplicant.h" |
8bac466b | 32 | #include "notify.h" |
3a068632 | 33 | #include "bss.h" |
9ba9fa07 | 34 | #include "scan.h" |
3a068632 | 35 | #include "ctrl_iface.h" |
afc064fe | 36 | #include "interworking.h" |
9aa10e2b | 37 | #include "blacklist.h" |
7de5688d | 38 | #include "wpas_glue.h" |
bc5d330a | 39 | #include "autoscan.h" |
6fc6879b | 40 | |
c5121837 | 41 | extern struct wpa_driver_ops *wpa_drivers[]; |
2d5b792d | 42 | |
4b4a8ae5 JM |
43 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
44 | char *buf, int len); | |
6fc6879b JM |
45 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
46 | char *buf, int len); | |
47 | ||
48 | ||
b5c68312 JM |
49 | static int pno_start(struct wpa_supplicant *wpa_s) |
50 | { | |
51 | int ret; | |
52 | size_t i, num_ssid; | |
53 | struct wpa_ssid *ssid; | |
54 | struct wpa_driver_scan_params params; | |
55 | ||
56 | if (wpa_s->pno) | |
57 | return 0; | |
58 | ||
59 | os_memset(¶ms, 0, sizeof(params)); | |
60 | ||
61 | num_ssid = 0; | |
62 | ssid = wpa_s->conf->ssid; | |
63 | while (ssid) { | |
349493bd | 64 | if (!wpas_network_disabled(wpa_s, ssid)) |
b5c68312 JM |
65 | num_ssid++; |
66 | ssid = ssid->next; | |
67 | } | |
68 | if (num_ssid > WPAS_MAX_SCAN_SSIDS) { | |
69 | wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from " | |
70 | "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid); | |
71 | num_ssid = WPAS_MAX_SCAN_SSIDS; | |
72 | } | |
73 | ||
74 | if (num_ssid == 0) { | |
75 | wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs"); | |
76 | return -1; | |
77 | } | |
78 | ||
79 | params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) * | |
80 | num_ssid); | |
81 | if (params.filter_ssids == NULL) | |
82 | return -1; | |
83 | i = 0; | |
d70b945d | 84 | ssid = wpa_s->conf->ssid; |
b5c68312 | 85 | while (ssid) { |
349493bd | 86 | if (!wpas_network_disabled(wpa_s, ssid)) { |
b5c68312 JM |
87 | params.ssids[i].ssid = ssid->ssid; |
88 | params.ssids[i].ssid_len = ssid->ssid_len; | |
89 | params.num_ssids++; | |
90 | os_memcpy(params.filter_ssids[i].ssid, ssid->ssid, | |
91 | ssid->ssid_len); | |
92 | params.filter_ssids[i].ssid_len = ssid->ssid_len; | |
93 | params.num_filter_ssids++; | |
94 | i++; | |
95 | if (i == num_ssid) | |
96 | break; | |
97 | } | |
98 | ssid = ssid->next; | |
99 | } | |
100 | ||
bf8d6d24 TP |
101 | if (wpa_s->conf->filter_rssi) |
102 | params.filter_rssi = wpa_s->conf->filter_rssi; | |
103 | ||
b5c68312 JM |
104 | ret = wpa_drv_sched_scan(wpa_s, ¶ms, 10 * 1000); |
105 | os_free(params.filter_ssids); | |
106 | if (ret == 0) | |
107 | wpa_s->pno = 1; | |
108 | return ret; | |
109 | } | |
110 | ||
111 | ||
112 | static int pno_stop(struct wpa_supplicant *wpa_s) | |
113 | { | |
114 | if (wpa_s->pno) { | |
115 | wpa_s->pno = 0; | |
116 | return wpa_drv_stop_sched_scan(wpa_s); | |
117 | } | |
118 | return 0; | |
119 | } | |
120 | ||
121 | ||
d445a5cd JM |
122 | static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val) |
123 | { | |
124 | char *pos; | |
125 | u8 addr[ETH_ALEN], *filter = NULL, *n; | |
126 | size_t count = 0; | |
127 | ||
128 | pos = val; | |
129 | while (pos) { | |
130 | if (*pos == '\0') | |
131 | break; | |
1485ec07 JM |
132 | if (hwaddr_aton(pos, addr)) { |
133 | os_free(filter); | |
d445a5cd | 134 | return -1; |
1485ec07 | 135 | } |
067ffa26 | 136 | n = os_realloc_array(filter, count + 1, ETH_ALEN); |
d445a5cd JM |
137 | if (n == NULL) { |
138 | os_free(filter); | |
139 | return -1; | |
140 | } | |
141 | filter = n; | |
142 | os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN); | |
143 | count++; | |
144 | ||
145 | pos = os_strchr(pos, ' '); | |
146 | if (pos) | |
147 | pos++; | |
148 | } | |
149 | ||
150 | wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN); | |
151 | os_free(wpa_s->bssid_filter); | |
152 | wpa_s->bssid_filter = filter; | |
153 | wpa_s->bssid_filter_count = count; | |
154 | ||
155 | return 0; | |
156 | } | |
157 | ||
158 | ||
6fc6879b JM |
159 | static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, |
160 | char *cmd) | |
161 | { | |
162 | char *value; | |
163 | int ret = 0; | |
164 | ||
165 | value = os_strchr(cmd, ' '); | |
166 | if (value == NULL) | |
167 | return -1; | |
168 | *value++ = '\0'; | |
169 | ||
170 | wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value); | |
171 | if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) { | |
172 | eapol_sm_configure(wpa_s->eapol, | |
173 | atoi(value), -1, -1, -1); | |
174 | } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) { | |
175 | eapol_sm_configure(wpa_s->eapol, | |
176 | -1, atoi(value), -1, -1); | |
177 | } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) { | |
178 | eapol_sm_configure(wpa_s->eapol, | |
179 | -1, -1, atoi(value), -1); | |
180 | } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) { | |
181 | eapol_sm_configure(wpa_s->eapol, | |
182 | -1, -1, -1, atoi(value)); | |
183 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) { | |
184 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, | |
185 | atoi(value))) | |
186 | ret = -1; | |
187 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == | |
188 | 0) { | |
189 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, | |
190 | atoi(value))) | |
191 | ret = -1; | |
192 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) { | |
193 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value))) | |
194 | ret = -1; | |
42f50264 JM |
195 | } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) { |
196 | wpa_s->wps_fragment_size = atoi(value); | |
b4e34f2f JM |
197 | #ifdef CONFIG_WPS_TESTING |
198 | } else if (os_strcasecmp(cmd, "wps_version_number") == 0) { | |
199 | long int val; | |
200 | val = strtol(value, NULL, 0); | |
201 | if (val < 0 || val > 0xff) { | |
202 | ret = -1; | |
203 | wpa_printf(MSG_DEBUG, "WPS: Invalid " | |
204 | "wps_version_number %ld", val); | |
205 | } else { | |
206 | wps_version_number = val; | |
207 | wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS " | |
208 | "version %u.%u", | |
209 | (wps_version_number & 0xf0) >> 4, | |
210 | wps_version_number & 0x0f); | |
211 | } | |
212 | } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) { | |
213 | wps_testing_dummy_cred = atoi(value); | |
214 | wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d", | |
215 | wps_testing_dummy_cred); | |
216 | #endif /* CONFIG_WPS_TESTING */ | |
b6c79a99 JM |
217 | } else if (os_strcasecmp(cmd, "ampdu") == 0) { |
218 | if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0) | |
219 | ret = -1; | |
5b0e6ece JM |
220 | #ifdef CONFIG_TDLS_TESTING |
221 | } else if (os_strcasecmp(cmd, "tdls_testing") == 0) { | |
222 | extern unsigned int tdls_testing; | |
223 | tdls_testing = strtol(value, NULL, 0); | |
224 | wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing); | |
225 | #endif /* CONFIG_TDLS_TESTING */ | |
b8f64582 JM |
226 | #ifdef CONFIG_TDLS |
227 | } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) { | |
228 | int disabled = atoi(value); | |
229 | wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled); | |
230 | if (disabled) { | |
231 | if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0) | |
232 | ret = -1; | |
233 | } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0) | |
234 | ret = -1; | |
235 | wpa_tdls_enable(wpa_s->wpa, !disabled); | |
236 | #endif /* CONFIG_TDLS */ | |
b5c68312 JM |
237 | } else if (os_strcasecmp(cmd, "pno") == 0) { |
238 | if (atoi(value)) | |
239 | ret = pno_start(wpa_s); | |
240 | else | |
241 | ret = pno_stop(wpa_s); | |
8b9d0bfa JM |
242 | } else if (os_strcasecmp(cmd, "radio_disabled") == 0) { |
243 | int disabled = atoi(value); | |
244 | if (wpa_drv_radio_disable(wpa_s, disabled) < 0) | |
245 | ret = -1; | |
246 | else if (disabled) | |
247 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | |
aa074a64 JM |
248 | } else if (os_strcasecmp(cmd, "uapsd") == 0) { |
249 | if (os_strcmp(value, "disable") == 0) | |
250 | wpa_s->set_sta_uapsd = 0; | |
251 | else { | |
252 | int be, bk, vi, vo; | |
253 | char *pos; | |
254 | /* format: BE,BK,VI,VO;max SP Length */ | |
255 | be = atoi(value); | |
256 | pos = os_strchr(value, ','); | |
257 | if (pos == NULL) | |
258 | return -1; | |
259 | pos++; | |
260 | bk = atoi(pos); | |
261 | pos = os_strchr(pos, ','); | |
262 | if (pos == NULL) | |
263 | return -1; | |
264 | pos++; | |
265 | vi = atoi(pos); | |
266 | pos = os_strchr(pos, ','); | |
267 | if (pos == NULL) | |
268 | return -1; | |
269 | pos++; | |
270 | vo = atoi(pos); | |
271 | /* ignore max SP Length for now */ | |
272 | ||
273 | wpa_s->set_sta_uapsd = 1; | |
274 | wpa_s->sta_uapsd = 0; | |
275 | if (be) | |
276 | wpa_s->sta_uapsd |= BIT(0); | |
277 | if (bk) | |
278 | wpa_s->sta_uapsd |= BIT(1); | |
279 | if (vi) | |
280 | wpa_s->sta_uapsd |= BIT(2); | |
281 | if (vo) | |
282 | wpa_s->sta_uapsd |= BIT(3); | |
283 | } | |
b2ff1681 JM |
284 | } else if (os_strcasecmp(cmd, "ps") == 0) { |
285 | ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1); | |
d445a5cd JM |
286 | } else if (os_strcasecmp(cmd, "bssid_filter") == 0) { |
287 | ret = set_bssid_filter(wpa_s, value); | |
611aea7d JM |
288 | } else { |
289 | value[-1] = '='; | |
290 | ret = wpa_config_process_global(wpa_s->conf, cmd, -1); | |
291 | if (ret == 0) | |
292 | wpa_supplicant_update_config(wpa_s); | |
293 | } | |
6fc6879b JM |
294 | |
295 | return ret; | |
296 | } | |
297 | ||
298 | ||
acec8d32 JM |
299 | static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s, |
300 | char *cmd, char *buf, size_t buflen) | |
301 | { | |
6ce937b8 | 302 | int res = -1; |
acec8d32 JM |
303 | |
304 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd); | |
305 | ||
306 | if (os_strcmp(cmd, "version") == 0) { | |
307 | res = os_snprintf(buf, buflen, "%s", VERSION_STR); | |
6ce937b8 DS |
308 | } else if (os_strcasecmp(cmd, "country") == 0) { |
309 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) | |
310 | res = os_snprintf(buf, buflen, "%c%c", | |
311 | wpa_s->conf->country[0], | |
312 | wpa_s->conf->country[1]); | |
acec8d32 JM |
313 | } |
314 | ||
6ce937b8 DS |
315 | if (res < 0 || (unsigned int) res >= buflen) |
316 | return -1; | |
317 | return res; | |
acec8d32 JM |
318 | } |
319 | ||
320 | ||
ec717917 | 321 | #ifdef IEEE8021X_EAPOL |
6fc6879b JM |
322 | static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s, |
323 | char *addr) | |
324 | { | |
325 | u8 bssid[ETH_ALEN]; | |
326 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
327 | ||
328 | if (hwaddr_aton(addr, bssid)) { | |
329 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address " | |
330 | "'%s'", addr); | |
331 | return -1; | |
332 | } | |
333 | ||
334 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid)); | |
335 | rsn_preauth_deinit(wpa_s->wpa); | |
336 | if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL)) | |
337 | return -1; | |
338 | ||
339 | return 0; | |
340 | } | |
ec717917 | 341 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
342 | |
343 | ||
344 | #ifdef CONFIG_PEERKEY | |
345 | /* MLME-STKSTART.request(peer) */ | |
346 | static int wpa_supplicant_ctrl_iface_stkstart( | |
347 | struct wpa_supplicant *wpa_s, char *addr) | |
348 | { | |
349 | u8 peer[ETH_ALEN]; | |
350 | ||
351 | if (hwaddr_aton(addr, peer)) { | |
352 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid " | |
a7b6c422 | 353 | "address '%s'", addr); |
6fc6879b JM |
354 | return -1; |
355 | } | |
356 | ||
357 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR, | |
358 | MAC2STR(peer)); | |
359 | ||
360 | return wpa_sm_stkstart(wpa_s->wpa, peer); | |
361 | } | |
362 | #endif /* CONFIG_PEERKEY */ | |
363 | ||
364 | ||
281ff0aa GP |
365 | #ifdef CONFIG_TDLS |
366 | ||
367 | static int wpa_supplicant_ctrl_iface_tdls_discover( | |
368 | struct wpa_supplicant *wpa_s, char *addr) | |
369 | { | |
370 | u8 peer[ETH_ALEN]; | |
2d565a61 | 371 | int ret; |
281ff0aa GP |
372 | |
373 | if (hwaddr_aton(addr, peer)) { | |
374 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid " | |
375 | "address '%s'", addr); | |
376 | return -1; | |
377 | } | |
378 | ||
379 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR, | |
380 | MAC2STR(peer)); | |
381 | ||
2d565a61 AN |
382 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
383 | ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer); | |
384 | else | |
385 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); | |
386 | ||
387 | return ret; | |
281ff0aa GP |
388 | } |
389 | ||
390 | ||
391 | static int wpa_supplicant_ctrl_iface_tdls_setup( | |
392 | struct wpa_supplicant *wpa_s, char *addr) | |
393 | { | |
394 | u8 peer[ETH_ALEN]; | |
94377fbc | 395 | int ret; |
281ff0aa GP |
396 | |
397 | if (hwaddr_aton(addr, peer)) { | |
398 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid " | |
399 | "address '%s'", addr); | |
400 | return -1; | |
401 | } | |
402 | ||
403 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR, | |
404 | MAC2STR(peer)); | |
405 | ||
94377fbc | 406 | ret = wpa_tdls_reneg(wpa_s->wpa, peer); |
2d565a61 AN |
407 | if (ret) { |
408 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | |
409 | ret = wpa_tdls_start(wpa_s->wpa, peer); | |
410 | else | |
411 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | |
412 | } | |
413 | ||
94377fbc | 414 | return ret; |
281ff0aa GP |
415 | } |
416 | ||
417 | ||
418 | static int wpa_supplicant_ctrl_iface_tdls_teardown( | |
419 | struct wpa_supplicant *wpa_s, char *addr) | |
420 | { | |
421 | u8 peer[ETH_ALEN]; | |
422 | ||
423 | if (hwaddr_aton(addr, peer)) { | |
424 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid " | |
425 | "address '%s'", addr); | |
426 | return -1; | |
427 | } | |
428 | ||
429 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR, | |
430 | MAC2STR(peer)); | |
431 | ||
2d565a61 AN |
432 | return wpa_tdls_teardown_link(wpa_s->wpa, peer, |
433 | WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED); | |
281ff0aa GP |
434 | } |
435 | ||
436 | #endif /* CONFIG_TDLS */ | |
437 | ||
438 | ||
6fc6879b JM |
439 | #ifdef CONFIG_IEEE80211R |
440 | static int wpa_supplicant_ctrl_iface_ft_ds( | |
441 | struct wpa_supplicant *wpa_s, char *addr) | |
442 | { | |
443 | u8 target_ap[ETH_ALEN]; | |
76b7981d JM |
444 | struct wpa_bss *bss; |
445 | const u8 *mdie; | |
6fc6879b JM |
446 | |
447 | if (hwaddr_aton(addr, target_ap)) { | |
448 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid " | |
a7b6c422 | 449 | "address '%s'", addr); |
6fc6879b JM |
450 | return -1; |
451 | } | |
452 | ||
453 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap)); | |
454 | ||
76b7981d JM |
455 | bss = wpa_bss_get_bssid(wpa_s, target_ap); |
456 | if (bss) | |
457 | mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); | |
458 | else | |
459 | mdie = NULL; | |
460 | ||
461 | return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie); | |
6fc6879b JM |
462 | } |
463 | #endif /* CONFIG_IEEE80211R */ | |
464 | ||
465 | ||
fcc60db4 JM |
466 | #ifdef CONFIG_WPS |
467 | static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s, | |
468 | char *cmd) | |
469 | { | |
3ec97afe | 470 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
ceb34f25 | 471 | #ifdef CONFIG_P2P |
634ce802 | 472 | u8 p2p_dev_addr[ETH_ALEN]; |
ceb34f25 | 473 | #endif /* CONFIG_P2P */ |
634ce802 JM |
474 | #ifdef CONFIG_AP |
475 | u8 *_p2p_dev_addr = NULL; | |
476 | #endif /* CONFIG_AP */ | |
fcc60db4 | 477 | |
d601247c | 478 | if (cmd == NULL || os_strcmp(cmd, "any") == 0) { |
3ec97afe | 479 | _bssid = NULL; |
d601247c JM |
480 | #ifdef CONFIG_P2P |
481 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | |
482 | if (hwaddr_aton(cmd + 13, p2p_dev_addr)) { | |
483 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid " | |
484 | "P2P Device Address '%s'", | |
485 | cmd + 13); | |
486 | return -1; | |
487 | } | |
488 | _p2p_dev_addr = p2p_dev_addr; | |
489 | #endif /* CONFIG_P2P */ | |
490 | } else if (hwaddr_aton(cmd, bssid)) { | |
fcc60db4 JM |
491 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'", |
492 | cmd); | |
493 | return -1; | |
494 | } | |
495 | ||
3ec97afe JM |
496 | #ifdef CONFIG_AP |
497 | if (wpa_s->ap_iface) | |
d601247c | 498 | return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr); |
3ec97afe JM |
499 | #endif /* CONFIG_AP */ |
500 | ||
9fa243b2 | 501 | return wpas_wps_start_pbc(wpa_s, _bssid, 0); |
fcc60db4 JM |
502 | } |
503 | ||
504 | ||
505 | static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, | |
506 | char *cmd, char *buf, | |
507 | size_t buflen) | |
508 | { | |
509 | u8 bssid[ETH_ALEN], *_bssid = bssid; | |
510 | char *pin; | |
511 | int ret; | |
512 | ||
513 | pin = os_strchr(cmd, ' '); | |
514 | if (pin) | |
515 | *pin++ = '\0'; | |
516 | ||
517 | if (os_strcmp(cmd, "any") == 0) | |
518 | _bssid = NULL; | |
98aa7ca5 JM |
519 | else if (os_strcmp(cmd, "get") == 0) { |
520 | ret = wps_generate_pin(); | |
521 | goto done; | |
522 | } else if (hwaddr_aton(cmd, bssid)) { | |
3c1e2765 | 523 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'", |
fcc60db4 JM |
524 | cmd); |
525 | return -1; | |
526 | } | |
527 | ||
3ec97afe JM |
528 | #ifdef CONFIG_AP |
529 | if (wpa_s->ap_iface) | |
530 | return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, | |
531 | buf, buflen); | |
532 | #endif /* CONFIG_AP */ | |
533 | ||
fcc60db4 | 534 | if (pin) { |
3c5126a4 JM |
535 | ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0, |
536 | DEV_PW_DEFAULT); | |
fcc60db4 JM |
537 | if (ret < 0) |
538 | return -1; | |
539 | ret = os_snprintf(buf, buflen, "%s", pin); | |
540 | if (ret < 0 || (size_t) ret >= buflen) | |
541 | return -1; | |
542 | return ret; | |
543 | } | |
544 | ||
3c5126a4 | 545 | ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT); |
fcc60db4 JM |
546 | if (ret < 0) |
547 | return -1; | |
548 | ||
98aa7ca5 | 549 | done: |
fcc60db4 JM |
550 | /* Return the generated PIN */ |
551 | ret = os_snprintf(buf, buflen, "%08d", ret); | |
552 | if (ret < 0 || (size_t) ret >= buflen) | |
553 | return -1; | |
554 | return ret; | |
555 | } | |
556 | ||
557 | ||
3981cb3c JM |
558 | static int wpa_supplicant_ctrl_iface_wps_check_pin( |
559 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
560 | { | |
561 | char pin[9]; | |
562 | size_t len; | |
563 | char *pos; | |
564 | int ret; | |
565 | ||
566 | wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN", | |
567 | (u8 *) cmd, os_strlen(cmd)); | |
568 | for (pos = cmd, len = 0; *pos != '\0'; pos++) { | |
569 | if (*pos < '0' || *pos > '9') | |
570 | continue; | |
571 | pin[len++] = *pos; | |
572 | if (len == 9) { | |
573 | wpa_printf(MSG_DEBUG, "WPS: Too long PIN"); | |
574 | return -1; | |
575 | } | |
576 | } | |
577 | if (len != 4 && len != 8) { | |
578 | wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len); | |
579 | return -1; | |
580 | } | |
581 | pin[len] = '\0'; | |
582 | ||
583 | if (len == 8) { | |
584 | unsigned int pin_val; | |
585 | pin_val = atoi(pin); | |
586 | if (!wps_pin_valid(pin_val)) { | |
587 | wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit"); | |
588 | ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n"); | |
589 | if (ret < 0 || (size_t) ret >= buflen) | |
590 | return -1; | |
591 | return ret; | |
592 | } | |
593 | } | |
594 | ||
595 | ret = os_snprintf(buf, buflen, "%s", pin); | |
596 | if (ret < 0 || (size_t) ret >= buflen) | |
597 | return -1; | |
598 | ||
599 | return ret; | |
600 | } | |
601 | ||
602 | ||
116f7bb0 | 603 | #ifdef CONFIG_WPS_OOB |
46bdb83a MH |
604 | static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s, |
605 | char *cmd) | |
606 | { | |
e1ee6b60 | 607 | char *path, *method, *name; |
46bdb83a MH |
608 | |
609 | path = os_strchr(cmd, ' '); | |
610 | if (path == NULL) | |
611 | return -1; | |
612 | *path++ = '\0'; | |
613 | ||
614 | method = os_strchr(path, ' '); | |
615 | if (method == NULL) | |
616 | return -1; | |
617 | *method++ = '\0'; | |
618 | ||
e1ee6b60 MH |
619 | name = os_strchr(method, ' '); |
620 | if (name != NULL) | |
621 | *name++ = '\0'; | |
622 | ||
623 | return wpas_wps_start_oob(wpa_s, cmd, path, method, name); | |
46bdb83a | 624 | } |
71892384 JM |
625 | #endif /* CONFIG_WPS_OOB */ |
626 | ||
3f2c8ba6 | 627 | |
71892384 | 628 | #ifdef CONFIG_WPS_NFC |
3f2c8ba6 JM |
629 | |
630 | static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s, | |
631 | char *cmd) | |
632 | { | |
633 | u8 bssid[ETH_ALEN], *_bssid = bssid; | |
634 | ||
635 | if (cmd == NULL || cmd[0] == '\0') | |
636 | _bssid = NULL; | |
637 | else if (hwaddr_aton(cmd, bssid)) | |
638 | return -1; | |
639 | ||
640 | return wpas_wps_start_nfc(wpa_s, _bssid); | |
641 | } | |
642 | ||
643 | ||
644 | static int wpa_supplicant_ctrl_iface_wps_nfc_token( | |
645 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
646 | { | |
647 | int ndef; | |
648 | struct wpabuf *buf; | |
649 | int res; | |
650 | ||
651 | if (os_strcmp(cmd, "WPS") == 0) | |
652 | ndef = 0; | |
653 | else if (os_strcmp(cmd, "NDEF") == 0) | |
654 | ndef = 1; | |
655 | else | |
656 | return -1; | |
657 | ||
658 | buf = wpas_wps_nfc_token(wpa_s, ndef); | |
659 | if (buf == NULL) | |
660 | return -1; | |
661 | ||
662 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
663 | wpabuf_len(buf)); | |
664 | reply[res++] = '\n'; | |
665 | reply[res] = '\0'; | |
666 | ||
667 | wpabuf_free(buf); | |
668 | ||
669 | return res; | |
670 | } | |
d7645d23 JM |
671 | |
672 | ||
673 | static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read( | |
674 | struct wpa_supplicant *wpa_s, char *pos) | |
675 | { | |
676 | size_t len; | |
677 | struct wpabuf *buf; | |
678 | int ret; | |
679 | ||
680 | len = os_strlen(pos); | |
681 | if (len & 0x01) | |
682 | return -1; | |
683 | len /= 2; | |
684 | ||
685 | buf = wpabuf_alloc(len); | |
686 | if (buf == NULL) | |
687 | return -1; | |
688 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { | |
689 | wpabuf_free(buf); | |
690 | return -1; | |
691 | } | |
692 | ||
693 | ret = wpas_wps_nfc_tag_read(wpa_s, buf); | |
694 | wpabuf_free(buf); | |
695 | ||
696 | return ret; | |
697 | } | |
71892384 JM |
698 | |
699 | #endif /* CONFIG_WPS_NFC */ | |
46bdb83a MH |
700 | |
701 | ||
fcc60db4 JM |
702 | static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s, |
703 | char *cmd) | |
704 | { | |
129eb428 | 705 | u8 bssid[ETH_ALEN]; |
fcc60db4 | 706 | char *pin; |
52eb293d JM |
707 | char *new_ssid; |
708 | char *new_auth; | |
709 | char *new_encr; | |
710 | char *new_key; | |
711 | struct wps_new_ap_settings ap; | |
fcc60db4 JM |
712 | |
713 | pin = os_strchr(cmd, ' '); | |
714 | if (pin == NULL) | |
715 | return -1; | |
716 | *pin++ = '\0'; | |
717 | ||
129eb428 | 718 | if (hwaddr_aton(cmd, bssid)) { |
fcc60db4 JM |
719 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'", |
720 | cmd); | |
721 | return -1; | |
722 | } | |
723 | ||
52eb293d JM |
724 | new_ssid = os_strchr(pin, ' '); |
725 | if (new_ssid == NULL) | |
129eb428 | 726 | return wpas_wps_start_reg(wpa_s, bssid, pin, NULL); |
52eb293d JM |
727 | *new_ssid++ = '\0'; |
728 | ||
729 | new_auth = os_strchr(new_ssid, ' '); | |
730 | if (new_auth == NULL) | |
731 | return -1; | |
732 | *new_auth++ = '\0'; | |
733 | ||
734 | new_encr = os_strchr(new_auth, ' '); | |
735 | if (new_encr == NULL) | |
736 | return -1; | |
737 | *new_encr++ = '\0'; | |
738 | ||
739 | new_key = os_strchr(new_encr, ' '); | |
740 | if (new_key == NULL) | |
741 | return -1; | |
742 | *new_key++ = '\0'; | |
743 | ||
744 | os_memset(&ap, 0, sizeof(ap)); | |
745 | ap.ssid_hex = new_ssid; | |
746 | ap.auth = new_auth; | |
747 | ap.encr = new_encr; | |
748 | ap.key_hex = new_key; | |
129eb428 | 749 | return wpas_wps_start_reg(wpa_s, bssid, pin, &ap); |
fcc60db4 | 750 | } |
72df2f5f JM |
751 | |
752 | ||
70d84f11 JM |
753 | #ifdef CONFIG_AP |
754 | static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s, | |
755 | char *cmd, char *buf, | |
756 | size_t buflen) | |
757 | { | |
758 | int timeout = 300; | |
759 | char *pos; | |
760 | const char *pin_txt; | |
761 | ||
762 | if (!wpa_s->ap_iface) | |
763 | return -1; | |
764 | ||
765 | pos = os_strchr(cmd, ' '); | |
766 | if (pos) | |
767 | *pos++ = '\0'; | |
768 | ||
769 | if (os_strcmp(cmd, "disable") == 0) { | |
770 | wpas_wps_ap_pin_disable(wpa_s); | |
771 | return os_snprintf(buf, buflen, "OK\n"); | |
772 | } | |
773 | ||
774 | if (os_strcmp(cmd, "random") == 0) { | |
775 | if (pos) | |
776 | timeout = atoi(pos); | |
777 | pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout); | |
778 | if (pin_txt == NULL) | |
779 | return -1; | |
780 | return os_snprintf(buf, buflen, "%s", pin_txt); | |
781 | } | |
782 | ||
783 | if (os_strcmp(cmd, "get") == 0) { | |
784 | pin_txt = wpas_wps_ap_pin_get(wpa_s); | |
785 | if (pin_txt == NULL) | |
786 | return -1; | |
787 | return os_snprintf(buf, buflen, "%s", pin_txt); | |
788 | } | |
789 | ||
790 | if (os_strcmp(cmd, "set") == 0) { | |
791 | char *pin; | |
792 | if (pos == NULL) | |
793 | return -1; | |
794 | pin = pos; | |
795 | pos = os_strchr(pos, ' '); | |
796 | if (pos) { | |
797 | *pos++ = '\0'; | |
798 | timeout = atoi(pos); | |
799 | } | |
800 | if (os_strlen(pin) > buflen) | |
801 | return -1; | |
802 | if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0) | |
803 | return -1; | |
804 | return os_snprintf(buf, buflen, "%s", pin); | |
805 | } | |
806 | ||
807 | return -1; | |
808 | } | |
809 | #endif /* CONFIG_AP */ | |
810 | ||
811 | ||
72df2f5f JM |
812 | #ifdef CONFIG_WPS_ER |
813 | static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s, | |
814 | char *cmd) | |
815 | { | |
31fcea93 JM |
816 | char *uuid = cmd, *pin, *pos; |
817 | u8 addr_buf[ETH_ALEN], *addr = NULL; | |
72df2f5f JM |
818 | pin = os_strchr(uuid, ' '); |
819 | if (pin == NULL) | |
820 | return -1; | |
821 | *pin++ = '\0'; | |
31fcea93 JM |
822 | pos = os_strchr(pin, ' '); |
823 | if (pos) { | |
824 | *pos++ = '\0'; | |
825 | if (hwaddr_aton(pos, addr_buf) == 0) | |
826 | addr = addr_buf; | |
827 | } | |
828 | return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin); | |
72df2f5f | 829 | } |
e64dcfd5 JM |
830 | |
831 | ||
832 | static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s, | |
833 | char *cmd) | |
834 | { | |
835 | char *uuid = cmd, *pin; | |
836 | pin = os_strchr(uuid, ' '); | |
837 | if (pin == NULL) | |
838 | return -1; | |
839 | *pin++ = '\0'; | |
840 | return wpas_wps_er_learn(wpa_s, uuid, pin); | |
841 | } | |
7d6640a6 JM |
842 | |
843 | ||
ef10f473 JM |
844 | static int wpa_supplicant_ctrl_iface_wps_er_set_config( |
845 | struct wpa_supplicant *wpa_s, char *cmd) | |
846 | { | |
847 | char *uuid = cmd, *id; | |
848 | id = os_strchr(uuid, ' '); | |
849 | if (id == NULL) | |
850 | return -1; | |
851 | *id++ = '\0'; | |
852 | return wpas_wps_er_set_config(wpa_s, uuid, atoi(id)); | |
853 | } | |
854 | ||
855 | ||
7d6640a6 JM |
856 | static int wpa_supplicant_ctrl_iface_wps_er_config( |
857 | struct wpa_supplicant *wpa_s, char *cmd) | |
858 | { | |
859 | char *pin; | |
860 | char *new_ssid; | |
861 | char *new_auth; | |
862 | char *new_encr; | |
863 | char *new_key; | |
864 | struct wps_new_ap_settings ap; | |
865 | ||
866 | pin = os_strchr(cmd, ' '); | |
867 | if (pin == NULL) | |
868 | return -1; | |
869 | *pin++ = '\0'; | |
870 | ||
871 | new_ssid = os_strchr(pin, ' '); | |
872 | if (new_ssid == NULL) | |
873 | return -1; | |
874 | *new_ssid++ = '\0'; | |
875 | ||
876 | new_auth = os_strchr(new_ssid, ' '); | |
877 | if (new_auth == NULL) | |
878 | return -1; | |
879 | *new_auth++ = '\0'; | |
880 | ||
881 | new_encr = os_strchr(new_auth, ' '); | |
882 | if (new_encr == NULL) | |
883 | return -1; | |
884 | *new_encr++ = '\0'; | |
885 | ||
886 | new_key = os_strchr(new_encr, ' '); | |
887 | if (new_key == NULL) | |
888 | return -1; | |
889 | *new_key++ = '\0'; | |
890 | ||
891 | os_memset(&ap, 0, sizeof(ap)); | |
892 | ap.ssid_hex = new_ssid; | |
893 | ap.auth = new_auth; | |
894 | ap.encr = new_encr; | |
895 | ap.key_hex = new_key; | |
896 | return wpas_wps_er_config(wpa_s, cmd, pin, &ap); | |
897 | } | |
1cea09a9 JM |
898 | |
899 | ||
900 | #ifdef CONFIG_WPS_NFC | |
901 | static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | |
902 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
903 | { | |
904 | int ndef; | |
905 | struct wpabuf *buf; | |
906 | int res; | |
907 | char *uuid; | |
908 | ||
909 | uuid = os_strchr(cmd, ' '); | |
910 | if (uuid == NULL) | |
911 | return -1; | |
912 | *uuid++ = '\0'; | |
913 | ||
914 | if (os_strcmp(cmd, "WPS") == 0) | |
915 | ndef = 0; | |
916 | else if (os_strcmp(cmd, "NDEF") == 0) | |
917 | ndef = 1; | |
918 | else | |
919 | return -1; | |
920 | ||
921 | buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid); | |
922 | if (buf == NULL) | |
923 | return -1; | |
924 | ||
925 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
926 | wpabuf_len(buf)); | |
927 | reply[res++] = '\n'; | |
928 | reply[res] = '\0'; | |
929 | ||
930 | wpabuf_free(buf); | |
931 | ||
932 | return res; | |
933 | } | |
934 | #endif /* CONFIG_WPS_NFC */ | |
72df2f5f JM |
935 | #endif /* CONFIG_WPS_ER */ |
936 | ||
fcc60db4 JM |
937 | #endif /* CONFIG_WPS */ |
938 | ||
939 | ||
11ef8d35 JM |
940 | #ifdef CONFIG_IBSS_RSN |
941 | static int wpa_supplicant_ctrl_iface_ibss_rsn( | |
942 | struct wpa_supplicant *wpa_s, char *addr) | |
943 | { | |
944 | u8 peer[ETH_ALEN]; | |
945 | ||
946 | if (hwaddr_aton(addr, peer)) { | |
947 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid " | |
a7b6c422 | 948 | "address '%s'", addr); |
11ef8d35 JM |
949 | return -1; |
950 | } | |
951 | ||
952 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR, | |
953 | MAC2STR(peer)); | |
954 | ||
955 | return ibss_rsn_start(wpa_s->ibss_rsn, peer); | |
956 | } | |
957 | #endif /* CONFIG_IBSS_RSN */ | |
958 | ||
959 | ||
7de5688d DW |
960 | static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, |
961 | char *rsp) | |
962 | { | |
963 | #ifdef IEEE8021X_EAPOL | |
964 | char *pos, *id_pos; | |
965 | int id; | |
966 | struct wpa_ssid *ssid; | |
967 | ||
968 | pos = os_strchr(rsp, '-'); | |
969 | if (pos == NULL) | |
970 | return -1; | |
971 | *pos++ = '\0'; | |
972 | id_pos = pos; | |
973 | pos = os_strchr(pos, ':'); | |
974 | if (pos == NULL) | |
975 | return -1; | |
976 | *pos++ = '\0'; | |
977 | id = atoi(id_pos); | |
978 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); | |
979 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
980 | (u8 *) pos, os_strlen(pos)); | |
981 | ||
982 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
983 | if (ssid == NULL) { | |
984 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
985 | "to update", id); | |
986 | return -1; | |
987 | } | |
988 | ||
989 | return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp, | |
990 | pos); | |
6fc6879b JM |
991 | #else /* IEEE8021X_EAPOL */ |
992 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); | |
993 | return -1; | |
994 | #endif /* IEEE8021X_EAPOL */ | |
995 | } | |
996 | ||
997 | ||
998 | static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, | |
999 | const char *params, | |
1000 | char *buf, size_t buflen) | |
1001 | { | |
1002 | char *pos, *end, tmp[30]; | |
0bc13468 | 1003 | int res, verbose, wps, ret; |
6fc6879b JM |
1004 | |
1005 | verbose = os_strcmp(params, "-VERBOSE") == 0; | |
0bc13468 | 1006 | wps = os_strcmp(params, "-WPS") == 0; |
6fc6879b JM |
1007 | pos = buf; |
1008 | end = buf + buflen; | |
1009 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { | |
1010 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
1011 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | |
1012 | MAC2STR(wpa_s->bssid)); | |
1013 | if (ret < 0 || ret >= end - pos) | |
1014 | return pos - buf; | |
1015 | pos += ret; | |
1016 | if (ssid) { | |
1017 | u8 *_ssid = ssid->ssid; | |
1018 | size_t ssid_len = ssid->ssid_len; | |
1019 | u8 ssid_buf[MAX_SSID_LEN]; | |
1020 | if (ssid_len == 0) { | |
1021 | int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); | |
1022 | if (_res < 0) | |
1023 | ssid_len = 0; | |
1024 | else | |
1025 | ssid_len = _res; | |
1026 | _ssid = ssid_buf; | |
1027 | } | |
1028 | ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", | |
1029 | wpa_ssid_txt(_ssid, ssid_len), | |
1030 | ssid->id); | |
1031 | if (ret < 0 || ret >= end - pos) | |
1032 | return pos - buf; | |
1033 | pos += ret; | |
1034 | ||
0bc13468 JM |
1035 | if (wps && ssid->passphrase && |
1036 | wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && | |
1037 | (ssid->mode == WPAS_MODE_AP || | |
1038 | ssid->mode == WPAS_MODE_P2P_GO)) { | |
1039 | ret = os_snprintf(pos, end - pos, | |
1040 | "passphrase=%s\n", | |
1041 | ssid->passphrase); | |
1042 | if (ret < 0 || ret >= end - pos) | |
1043 | return pos - buf; | |
1044 | pos += ret; | |
1045 | } | |
6fc6879b JM |
1046 | if (ssid->id_str) { |
1047 | ret = os_snprintf(pos, end - pos, | |
1048 | "id_str=%s\n", | |
1049 | ssid->id_str); | |
1050 | if (ret < 0 || ret >= end - pos) | |
1051 | return pos - buf; | |
1052 | pos += ret; | |
1053 | } | |
0e15e529 JM |
1054 | |
1055 | switch (ssid->mode) { | |
d7dcba70 | 1056 | case WPAS_MODE_INFRA: |
0e15e529 JM |
1057 | ret = os_snprintf(pos, end - pos, |
1058 | "mode=station\n"); | |
1059 | break; | |
d7dcba70 | 1060 | case WPAS_MODE_IBSS: |
0e15e529 JM |
1061 | ret = os_snprintf(pos, end - pos, |
1062 | "mode=IBSS\n"); | |
1063 | break; | |
d7dcba70 | 1064 | case WPAS_MODE_AP: |
0e15e529 JM |
1065 | ret = os_snprintf(pos, end - pos, |
1066 | "mode=AP\n"); | |
1067 | break; | |
2c5d725c JM |
1068 | case WPAS_MODE_P2P_GO: |
1069 | ret = os_snprintf(pos, end - pos, | |
1070 | "mode=P2P GO\n"); | |
1071 | break; | |
1072 | case WPAS_MODE_P2P_GROUP_FORMATION: | |
1073 | ret = os_snprintf(pos, end - pos, | |
1074 | "mode=P2P GO - group " | |
1075 | "formation\n"); | |
1076 | break; | |
0e15e529 JM |
1077 | default: |
1078 | ret = 0; | |
1079 | break; | |
1080 | } | |
1081 | if (ret < 0 || ret >= end - pos) | |
1082 | return pos - buf; | |
1083 | pos += ret; | |
6fc6879b JM |
1084 | } |
1085 | ||
43fb5297 JM |
1086 | #ifdef CONFIG_AP |
1087 | if (wpa_s->ap_iface) { | |
1088 | pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos, | |
1089 | end - pos, | |
1090 | verbose); | |
1091 | } else | |
1092 | #endif /* CONFIG_AP */ | |
6fc6879b JM |
1093 | pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); |
1094 | } | |
1095 | ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", | |
1096 | wpa_supplicant_state_txt(wpa_s->wpa_state)); | |
1097 | if (ret < 0 || ret >= end - pos) | |
1098 | return pos - buf; | |
1099 | pos += ret; | |
1100 | ||
1101 | if (wpa_s->l2 && | |
1102 | l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { | |
1103 | ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); | |
1104 | if (ret < 0 || ret >= end - pos) | |
1105 | return pos - buf; | |
1106 | pos += ret; | |
1107 | } | |
1108 | ||
d23bd894 JM |
1109 | #ifdef CONFIG_P2P |
1110 | if (wpa_s->global->p2p) { | |
1111 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR | |
1112 | "\n", MAC2STR(wpa_s->global->p2p_dev_addr)); | |
1113 | if (ret < 0 || ret >= end - pos) | |
1114 | return pos - buf; | |
1115 | pos += ret; | |
1116 | } | |
b21e2c84 | 1117 | #endif /* CONFIG_P2P */ |
6d4747a9 JM |
1118 | |
1119 | ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n", | |
1120 | MAC2STR(wpa_s->own_addr)); | |
1121 | if (ret < 0 || ret >= end - pos) | |
1122 | return pos - buf; | |
1123 | pos += ret; | |
d23bd894 | 1124 | |
64855b96 JM |
1125 | #ifdef CONFIG_HS20 |
1126 | if (wpa_s->current_bss && | |
4ed34f5a JM |
1127 | wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE) && |
1128 | wpa_s->wpa_proto == WPA_PROTO_RSN && | |
1129 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | |
64855b96 JM |
1130 | ret = os_snprintf(pos, end - pos, "hs20=1\n"); |
1131 | if (ret < 0 || ret >= end - pos) | |
1132 | return pos - buf; | |
1133 | pos += ret; | |
1134 | } | |
1135 | #endif /* CONFIG_HS20 */ | |
1136 | ||
56586197 JM |
1137 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
1138 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
6fc6879b JM |
1139 | res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, |
1140 | verbose); | |
1141 | if (res >= 0) | |
1142 | pos += res; | |
1143 | } | |
1144 | ||
1145 | res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); | |
1146 | if (res >= 0) | |
1147 | pos += res; | |
1148 | ||
1149 | return pos - buf; | |
1150 | } | |
1151 | ||
1152 | ||
1153 | static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, | |
1154 | char *cmd) | |
1155 | { | |
1156 | char *pos; | |
1157 | int id; | |
1158 | struct wpa_ssid *ssid; | |
1159 | u8 bssid[ETH_ALEN]; | |
1160 | ||
1161 | /* cmd: "<network id> <BSSID>" */ | |
1162 | pos = os_strchr(cmd, ' '); | |
1163 | if (pos == NULL) | |
1164 | return -1; | |
1165 | *pos++ = '\0'; | |
1166 | id = atoi(cmd); | |
1167 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); | |
1168 | if (hwaddr_aton(pos, bssid)) { | |
1169 | wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); | |
1170 | return -1; | |
1171 | } | |
1172 | ||
1173 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
1174 | if (ssid == NULL) { | |
1175 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
1176 | "to update", id); | |
1177 | return -1; | |
1178 | } | |
1179 | ||
1180 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); | |
a8e16edc | 1181 | ssid->bssid_set = !is_zero_ether_addr(bssid); |
6fc6879b JM |
1182 | |
1183 | return 0; | |
1184 | } | |
1185 | ||
1186 | ||
9aa10e2b DS |
1187 | static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s, |
1188 | char *cmd, char *buf, | |
1189 | size_t buflen) | |
1190 | { | |
1191 | u8 bssid[ETH_ALEN]; | |
1192 | struct wpa_blacklist *e; | |
1193 | char *pos, *end; | |
1194 | int ret; | |
1195 | ||
1196 | /* cmd: "BLACKLIST [<BSSID>]" */ | |
1197 | if (*cmd == '\0') { | |
1198 | pos = buf; | |
1199 | end = buf + buflen; | |
1200 | e = wpa_s->blacklist; | |
1201 | while (e) { | |
1202 | ret = os_snprintf(pos, end - pos, MACSTR "\n", | |
1203 | MAC2STR(e->bssid)); | |
1204 | if (ret < 0 || ret >= end - pos) | |
1205 | return pos - buf; | |
1206 | pos += ret; | |
1207 | e = e->next; | |
1208 | } | |
1209 | return pos - buf; | |
1210 | } | |
1211 | ||
1212 | cmd++; | |
1213 | if (os_strncmp(cmd, "clear", 5) == 0) { | |
1214 | wpa_blacklist_clear(wpa_s); | |
1215 | os_memcpy(buf, "OK\n", 3); | |
1216 | return 3; | |
1217 | } | |
1218 | ||
1219 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd); | |
1220 | if (hwaddr_aton(cmd, bssid)) { | |
1221 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd); | |
1222 | return -1; | |
1223 | } | |
1224 | ||
1225 | /* | |
1226 | * Add the BSSID twice, so its count will be 2, causing it to be | |
1227 | * skipped when processing scan results. | |
1228 | */ | |
1229 | ret = wpa_blacklist_add(wpa_s, bssid); | |
1230 | if (ret != 0) | |
1231 | return -1; | |
1232 | ret = wpa_blacklist_add(wpa_s, bssid); | |
1233 | if (ret != 0) | |
1234 | return -1; | |
1235 | os_memcpy(buf, "OK\n", 3); | |
1236 | return 3; | |
1237 | } | |
1238 | ||
1239 | ||
0597a5b5 DS |
1240 | extern int wpa_debug_level; |
1241 | extern int wpa_debug_timestamp; | |
1242 | ||
1243 | static const char * debug_level_str(int level) | |
1244 | { | |
1245 | switch (level) { | |
1246 | case MSG_EXCESSIVE: | |
1247 | return "EXCESSIVE"; | |
1248 | case MSG_MSGDUMP: | |
1249 | return "MSGDUMP"; | |
1250 | case MSG_DEBUG: | |
1251 | return "DEBUG"; | |
1252 | case MSG_INFO: | |
1253 | return "INFO"; | |
1254 | case MSG_WARNING: | |
1255 | return "WARNING"; | |
1256 | case MSG_ERROR: | |
1257 | return "ERROR"; | |
1258 | default: | |
1259 | return "?"; | |
1260 | } | |
1261 | } | |
1262 | ||
1263 | ||
1264 | static int str_to_debug_level(const char *s) | |
1265 | { | |
1266 | if (os_strcasecmp(s, "EXCESSIVE") == 0) | |
1267 | return MSG_EXCESSIVE; | |
1268 | if (os_strcasecmp(s, "MSGDUMP") == 0) | |
1269 | return MSG_MSGDUMP; | |
1270 | if (os_strcasecmp(s, "DEBUG") == 0) | |
1271 | return MSG_DEBUG; | |
1272 | if (os_strcasecmp(s, "INFO") == 0) | |
1273 | return MSG_INFO; | |
1274 | if (os_strcasecmp(s, "WARNING") == 0) | |
1275 | return MSG_WARNING; | |
1276 | if (os_strcasecmp(s, "ERROR") == 0) | |
1277 | return MSG_ERROR; | |
1278 | return -1; | |
1279 | } | |
1280 | ||
1281 | ||
1282 | static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s, | |
1283 | char *cmd, char *buf, | |
1284 | size_t buflen) | |
1285 | { | |
1286 | char *pos, *end, *stamp; | |
1287 | int ret; | |
1288 | ||
1289 | if (cmd == NULL) { | |
1290 | return -1; | |
1291 | } | |
1292 | ||
1293 | /* cmd: "LOG_LEVEL [<level>]" */ | |
1294 | if (*cmd == '\0') { | |
1295 | pos = buf; | |
1296 | end = buf + buflen; | |
1297 | ret = os_snprintf(pos, end - pos, "Current level: %s\n" | |
1298 | "Timestamp: %d\n", | |
1299 | debug_level_str(wpa_debug_level), | |
1300 | wpa_debug_timestamp); | |
1301 | if (ret < 0 || ret >= end - pos) | |
1302 | ret = 0; | |
1303 | ||
1304 | return ret; | |
1305 | } | |
1306 | ||
1307 | while (*cmd == ' ') | |
1308 | cmd++; | |
1309 | ||
1310 | stamp = os_strchr(cmd, ' '); | |
1311 | if (stamp) { | |
1312 | *stamp++ = '\0'; | |
1313 | while (*stamp == ' ') { | |
1314 | stamp++; | |
1315 | } | |
1316 | } | |
1317 | ||
1318 | if (cmd && os_strlen(cmd)) { | |
1319 | int level = str_to_debug_level(cmd); | |
1320 | if (level < 0) | |
1321 | return -1; | |
1322 | wpa_debug_level = level; | |
1323 | } | |
1324 | ||
1325 | if (stamp && os_strlen(stamp)) | |
1326 | wpa_debug_timestamp = atoi(stamp); | |
1327 | ||
1328 | os_memcpy(buf, "OK\n", 3); | |
1329 | return 3; | |
1330 | } | |
1331 | ||
1332 | ||
6fc6879b JM |
1333 | static int wpa_supplicant_ctrl_iface_list_networks( |
1334 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
1335 | { | |
1336 | char *pos, *end; | |
1337 | struct wpa_ssid *ssid; | |
1338 | int ret; | |
1339 | ||
1340 | pos = buf; | |
1341 | end = buf + buflen; | |
1342 | ret = os_snprintf(pos, end - pos, | |
1343 | "network id / ssid / bssid / flags\n"); | |
1344 | if (ret < 0 || ret >= end - pos) | |
1345 | return pos - buf; | |
1346 | pos += ret; | |
1347 | ||
1348 | ssid = wpa_s->conf->ssid; | |
1349 | while (ssid) { | |
1350 | ret = os_snprintf(pos, end - pos, "%d\t%s", | |
1351 | ssid->id, | |
1352 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | |
1353 | if (ret < 0 || ret >= end - pos) | |
1354 | return pos - buf; | |
1355 | pos += ret; | |
1356 | if (ssid->bssid_set) { | |
1357 | ret = os_snprintf(pos, end - pos, "\t" MACSTR, | |
1358 | MAC2STR(ssid->bssid)); | |
1359 | } else { | |
1360 | ret = os_snprintf(pos, end - pos, "\tany"); | |
1361 | } | |
1362 | if (ret < 0 || ret >= end - pos) | |
1363 | return pos - buf; | |
1364 | pos += ret; | |
4dac0245 | 1365 | ret = os_snprintf(pos, end - pos, "\t%s%s%s", |
6fc6879b JM |
1366 | ssid == wpa_s->current_ssid ? |
1367 | "[CURRENT]" : "", | |
4dac0245 JM |
1368 | ssid->disabled ? "[DISABLED]" : "", |
1369 | ssid->disabled == 2 ? "[P2P-PERSISTENT]" : | |
1370 | ""); | |
6fc6879b JM |
1371 | if (ret < 0 || ret >= end - pos) |
1372 | return pos - buf; | |
1373 | pos += ret; | |
1374 | ret = os_snprintf(pos, end - pos, "\n"); | |
1375 | if (ret < 0 || ret >= end - pos) | |
1376 | return pos - buf; | |
1377 | pos += ret; | |
1378 | ||
1379 | ssid = ssid->next; | |
1380 | } | |
1381 | ||
1382 | return pos - buf; | |
1383 | } | |
1384 | ||
1385 | ||
1386 | static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) | |
1387 | { | |
1388 | int first = 1, ret; | |
1389 | ret = os_snprintf(pos, end - pos, "-"); | |
1390 | if (ret < 0 || ret >= end - pos) | |
1391 | return pos; | |
1392 | pos += ret; | |
1393 | if (cipher & WPA_CIPHER_NONE) { | |
1394 | ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+"); | |
1395 | if (ret < 0 || ret >= end - pos) | |
1396 | return pos; | |
1397 | pos += ret; | |
1398 | first = 0; | |
1399 | } | |
1400 | if (cipher & WPA_CIPHER_WEP40) { | |
1401 | ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+"); | |
1402 | if (ret < 0 || ret >= end - pos) | |
1403 | return pos; | |
1404 | pos += ret; | |
1405 | first = 0; | |
1406 | } | |
1407 | if (cipher & WPA_CIPHER_WEP104) { | |
1408 | ret = os_snprintf(pos, end - pos, "%sWEP104", | |
1409 | first ? "" : "+"); | |
1410 | if (ret < 0 || ret >= end - pos) | |
1411 | return pos; | |
1412 | pos += ret; | |
1413 | first = 0; | |
1414 | } | |
1415 | if (cipher & WPA_CIPHER_TKIP) { | |
1416 | ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+"); | |
1417 | if (ret < 0 || ret >= end - pos) | |
1418 | return pos; | |
1419 | pos += ret; | |
1420 | first = 0; | |
1421 | } | |
1422 | if (cipher & WPA_CIPHER_CCMP) { | |
1423 | ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+"); | |
1424 | if (ret < 0 || ret >= end - pos) | |
1425 | return pos; | |
1426 | pos += ret; | |
1427 | first = 0; | |
1428 | } | |
1429 | return pos; | |
1430 | } | |
1431 | ||
1432 | ||
1433 | static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, | |
1434 | const u8 *ie, size_t ie_len) | |
1435 | { | |
1436 | struct wpa_ie_data data; | |
1437 | int first, ret; | |
1438 | ||
1439 | ret = os_snprintf(pos, end - pos, "[%s-", proto); | |
1440 | if (ret < 0 || ret >= end - pos) | |
1441 | return pos; | |
1442 | pos += ret; | |
1443 | ||
1444 | if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { | |
1445 | ret = os_snprintf(pos, end - pos, "?]"); | |
1446 | if (ret < 0 || ret >= end - pos) | |
1447 | return pos; | |
1448 | pos += ret; | |
1449 | return pos; | |
1450 | } | |
1451 | ||
1452 | first = 1; | |
1453 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { | |
1454 | ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+"); | |
1455 | if (ret < 0 || ret >= end - pos) | |
1456 | return pos; | |
1457 | pos += ret; | |
1458 | first = 0; | |
1459 | } | |
1460 | if (data.key_mgmt & WPA_KEY_MGMT_PSK) { | |
1461 | ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+"); | |
1462 | if (ret < 0 || ret >= end - pos) | |
1463 | return pos; | |
1464 | pos += ret; | |
1465 | first = 0; | |
1466 | } | |
1467 | if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { | |
1468 | ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+"); | |
1469 | if (ret < 0 || ret >= end - pos) | |
1470 | return pos; | |
1471 | pos += ret; | |
1472 | first = 0; | |
1473 | } | |
1474 | #ifdef CONFIG_IEEE80211R | |
1475 | if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { | |
1476 | ret = os_snprintf(pos, end - pos, "%sFT/EAP", | |
1477 | first ? "" : "+"); | |
1478 | if (ret < 0 || ret >= end - pos) | |
1479 | return pos; | |
1480 | pos += ret; | |
1481 | first = 0; | |
1482 | } | |
1483 | if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { | |
1484 | ret = os_snprintf(pos, end - pos, "%sFT/PSK", | |
1485 | first ? "" : "+"); | |
1486 | if (ret < 0 || ret >= end - pos) | |
1487 | return pos; | |
1488 | pos += ret; | |
1489 | first = 0; | |
1490 | } | |
1491 | #endif /* CONFIG_IEEE80211R */ | |
56586197 JM |
1492 | #ifdef CONFIG_IEEE80211W |
1493 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { | |
1494 | ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", | |
1495 | first ? "" : "+"); | |
1496 | if (ret < 0 || ret >= end - pos) | |
1497 | return pos; | |
1498 | pos += ret; | |
1499 | first = 0; | |
1500 | } | |
1501 | if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { | |
1502 | ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", | |
1503 | first ? "" : "+"); | |
1504 | if (ret < 0 || ret >= end - pos) | |
1505 | return pos; | |
1506 | pos += ret; | |
1507 | first = 0; | |
1508 | } | |
1509 | #endif /* CONFIG_IEEE80211W */ | |
6fc6879b JM |
1510 | |
1511 | pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); | |
1512 | ||
1513 | if (data.capabilities & WPA_CAPABILITY_PREAUTH) { | |
1514 | ret = os_snprintf(pos, end - pos, "-preauth"); | |
1515 | if (ret < 0 || ret >= end - pos) | |
1516 | return pos; | |
1517 | pos += ret; | |
1518 | } | |
1519 | ||
1520 | ret = os_snprintf(pos, end - pos, "]"); | |
1521 | if (ret < 0 || ret >= end - pos) | |
1522 | return pos; | |
1523 | pos += ret; | |
1524 | ||
1525 | return pos; | |
1526 | } | |
1527 | ||
3a068632 | 1528 | |
eef7d7a1 | 1529 | #ifdef CONFIG_WPS |
31fcea93 JM |
1530 | static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, |
1531 | char *pos, char *end, | |
3a068632 JM |
1532 | struct wpabuf *wps_ie) |
1533 | { | |
eef7d7a1 JM |
1534 | int ret; |
1535 | const char *txt; | |
1536 | ||
eef7d7a1 JM |
1537 | if (wps_ie == NULL) |
1538 | return pos; | |
eef7d7a1 JM |
1539 | if (wps_is_selected_pbc_registrar(wps_ie)) |
1540 | txt = "[WPS-PBC]"; | |
53587ec1 | 1541 | #ifdef CONFIG_WPS2 |
31fcea93 JM |
1542 | else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) |
1543 | txt = "[WPS-AUTH]"; | |
53587ec1 | 1544 | #endif /* CONFIG_WPS2 */ |
eef7d7a1 JM |
1545 | else if (wps_is_selected_pin_registrar(wps_ie)) |
1546 | txt = "[WPS-PIN]"; | |
1547 | else | |
1548 | txt = "[WPS]"; | |
1549 | ||
1550 | ret = os_snprintf(pos, end - pos, "%s", txt); | |
1551 | if (ret >= 0 && ret < end - pos) | |
1552 | pos += ret; | |
1553 | wpabuf_free(wps_ie); | |
3a068632 JM |
1554 | return pos; |
1555 | } | |
1556 | #endif /* CONFIG_WPS */ | |
1557 | ||
1558 | ||
31fcea93 JM |
1559 | static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, |
1560 | char *pos, char *end, | |
16b71ac2 | 1561 | const struct wpa_bss *bss) |
3a068632 JM |
1562 | { |
1563 | #ifdef CONFIG_WPS | |
1564 | struct wpabuf *wps_ie; | |
1565 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); | |
31fcea93 | 1566 | return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); |
3a068632 | 1567 | #else /* CONFIG_WPS */ |
eef7d7a1 | 1568 | return pos; |
3a068632 | 1569 | #endif /* CONFIG_WPS */ |
eef7d7a1 JM |
1570 | } |
1571 | ||
6fc6879b JM |
1572 | |
1573 | /* Format one result on one text line into a buffer. */ | |
1574 | static int wpa_supplicant_ctrl_iface_scan_result( | |
31fcea93 | 1575 | struct wpa_supplicant *wpa_s, |
16b71ac2 | 1576 | const struct wpa_bss *bss, char *buf, size_t buflen) |
6fc6879b JM |
1577 | { |
1578 | char *pos, *end; | |
1579 | int ret; | |
0c6b310e JM |
1580 | const u8 *ie, *ie2, *p2p; |
1581 | ||
1582 | p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); | |
1583 | if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && | |
1584 | os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == | |
1585 | 0) | |
1586 | return 0; /* Do not show P2P listen discovery results here */ | |
6fc6879b JM |
1587 | |
1588 | pos = buf; | |
1589 | end = buf + buflen; | |
1590 | ||
1591 | ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", | |
16b71ac2 | 1592 | MAC2STR(bss->bssid), bss->freq, bss->level); |
6fc6879b | 1593 | if (ret < 0 || ret >= end - pos) |
fb0e5bd7 | 1594 | return -1; |
6fc6879b | 1595 | pos += ret; |
16b71ac2 | 1596 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
6fc6879b JM |
1597 | if (ie) |
1598 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); | |
16b71ac2 | 1599 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
6fc6879b JM |
1600 | if (ie2) |
1601 | pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]); | |
31fcea93 | 1602 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
16b71ac2 | 1603 | if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) { |
6fc6879b JM |
1604 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
1605 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 1606 | return -1; |
6fc6879b JM |
1607 | pos += ret; |
1608 | } | |
16b71ac2 | 1609 | if (bss->caps & IEEE80211_CAP_IBSS) { |
6fc6879b JM |
1610 | ret = os_snprintf(pos, end - pos, "[IBSS]"); |
1611 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 1612 | return -1; |
6fc6879b JM |
1613 | pos += ret; |
1614 | } | |
16b71ac2 | 1615 | if (bss->caps & IEEE80211_CAP_ESS) { |
bd1af96a JM |
1616 | ret = os_snprintf(pos, end - pos, "[ESS]"); |
1617 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 1618 | return -1; |
bd1af96a JM |
1619 | pos += ret; |
1620 | } | |
0c6b310e JM |
1621 | if (p2p) { |
1622 | ret = os_snprintf(pos, end - pos, "[P2P]"); | |
1623 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 1624 | return -1; |
0c6b310e JM |
1625 | pos += ret; |
1626 | } | |
64855b96 | 1627 | #ifdef CONFIG_HS20 |
4ed34f5a | 1628 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) { |
64855b96 JM |
1629 | ret = os_snprintf(pos, end - pos, "[HS20]"); |
1630 | if (ret < 0 || ret >= end - pos) | |
1631 | return -1; | |
1632 | pos += ret; | |
1633 | } | |
1634 | #endif /* CONFIG_HS20 */ | |
6fc6879b | 1635 | |
6fc6879b | 1636 | ret = os_snprintf(pos, end - pos, "\t%s", |
16b71ac2 | 1637 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
6fc6879b | 1638 | if (ret < 0 || ret >= end - pos) |
fb0e5bd7 | 1639 | return -1; |
6fc6879b JM |
1640 | pos += ret; |
1641 | ||
1642 | ret = os_snprintf(pos, end - pos, "\n"); | |
1643 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 1644 | return -1; |
6fc6879b JM |
1645 | pos += ret; |
1646 | ||
1647 | return pos - buf; | |
1648 | } | |
1649 | ||
1650 | ||
1651 | static int wpa_supplicant_ctrl_iface_scan_results( | |
1652 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
1653 | { | |
1654 | char *pos, *end; | |
16b71ac2 | 1655 | struct wpa_bss *bss; |
6fc6879b | 1656 | int ret; |
6fc6879b JM |
1657 | |
1658 | pos = buf; | |
1659 | end = buf + buflen; | |
1660 | ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " | |
1661 | "flags / ssid\n"); | |
1662 | if (ret < 0 || ret >= end - pos) | |
1663 | return pos - buf; | |
1664 | pos += ret; | |
1665 | ||
16b71ac2 | 1666 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
31fcea93 | 1667 | ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, |
6fc6879b JM |
1668 | end - pos); |
1669 | if (ret < 0 || ret >= end - pos) | |
1670 | return pos - buf; | |
1671 | pos += ret; | |
1672 | } | |
1673 | ||
1674 | return pos - buf; | |
1675 | } | |
1676 | ||
1677 | ||
1678 | static int wpa_supplicant_ctrl_iface_select_network( | |
1679 | struct wpa_supplicant *wpa_s, char *cmd) | |
1680 | { | |
1681 | int id; | |
1682 | struct wpa_ssid *ssid; | |
1683 | ||
1684 | /* cmd: "<network id>" or "any" */ | |
1685 | if (os_strcmp(cmd, "any") == 0) { | |
1686 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); | |
86b89452 WS |
1687 | ssid = NULL; |
1688 | } else { | |
1689 | id = atoi(cmd); | |
1690 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); | |
6fc6879b | 1691 | |
86b89452 WS |
1692 | ssid = wpa_config_get_network(wpa_s->conf, id); |
1693 | if (ssid == NULL) { | |
1694 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
1695 | "network id=%d", id); | |
1696 | return -1; | |
1697 | } | |
4dac0245 JM |
1698 | if (ssid->disabled == 2) { |
1699 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
1700 | "SELECT_NETWORK with persistent P2P group"); | |
1701 | return -1; | |
1702 | } | |
6fc6879b JM |
1703 | } |
1704 | ||
86b89452 | 1705 | wpa_supplicant_select_network(wpa_s, ssid); |
6fc6879b JM |
1706 | |
1707 | return 0; | |
1708 | } | |
1709 | ||
1710 | ||
1711 | static int wpa_supplicant_ctrl_iface_enable_network( | |
1712 | struct wpa_supplicant *wpa_s, char *cmd) | |
1713 | { | |
1714 | int id; | |
1715 | struct wpa_ssid *ssid; | |
1716 | ||
1717 | /* cmd: "<network id>" or "all" */ | |
1718 | if (os_strcmp(cmd, "all") == 0) { | |
1719 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); | |
86b89452 WS |
1720 | ssid = NULL; |
1721 | } else { | |
1722 | id = atoi(cmd); | |
1723 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); | |
6fc6879b | 1724 | |
86b89452 WS |
1725 | ssid = wpa_config_get_network(wpa_s->conf, id); |
1726 | if (ssid == NULL) { | |
1727 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
1728 | "network id=%d", id); | |
1729 | return -1; | |
1730 | } | |
4dac0245 JM |
1731 | if (ssid->disabled == 2) { |
1732 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
1733 | "ENABLE_NETWORK with persistent P2P group"); | |
1734 | return -1; | |
1735 | } | |
84c78f95 JM |
1736 | |
1737 | if (os_strstr(cmd, " no-connect")) { | |
1738 | ssid->disabled = 0; | |
1739 | return 0; | |
1740 | } | |
6fc6879b | 1741 | } |
86b89452 | 1742 | wpa_supplicant_enable_network(wpa_s, ssid); |
6fc6879b JM |
1743 | |
1744 | return 0; | |
1745 | } | |
1746 | ||
1747 | ||
1748 | static int wpa_supplicant_ctrl_iface_disable_network( | |
1749 | struct wpa_supplicant *wpa_s, char *cmd) | |
1750 | { | |
1751 | int id; | |
1752 | struct wpa_ssid *ssid; | |
1753 | ||
1754 | /* cmd: "<network id>" or "all" */ | |
1755 | if (os_strcmp(cmd, "all") == 0) { | |
1756 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); | |
86b89452 WS |
1757 | ssid = NULL; |
1758 | } else { | |
1759 | id = atoi(cmd); | |
1760 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); | |
6fc6879b | 1761 | |
86b89452 WS |
1762 | ssid = wpa_config_get_network(wpa_s->conf, id); |
1763 | if (ssid == NULL) { | |
1764 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
1765 | "network id=%d", id); | |
1766 | return -1; | |
1767 | } | |
4dac0245 JM |
1768 | if (ssid->disabled == 2) { |
1769 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
1770 | "DISABLE_NETWORK with persistent P2P " | |
1771 | "group"); | |
1772 | return -1; | |
1773 | } | |
6fc6879b | 1774 | } |
86b89452 | 1775 | wpa_supplicant_disable_network(wpa_s, ssid); |
6fc6879b JM |
1776 | |
1777 | return 0; | |
1778 | } | |
1779 | ||
1780 | ||
1781 | static int wpa_supplicant_ctrl_iface_add_network( | |
1782 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
1783 | { | |
1784 | struct wpa_ssid *ssid; | |
1785 | int ret; | |
1786 | ||
1787 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); | |
1788 | ||
1789 | ssid = wpa_config_add_network(wpa_s->conf); | |
1790 | if (ssid == NULL) | |
1791 | return -1; | |
8bac466b JM |
1792 | |
1793 | wpas_notify_network_added(wpa_s, ssid); | |
1794 | ||
6fc6879b JM |
1795 | ssid->disabled = 1; |
1796 | wpa_config_set_network_defaults(ssid); | |
1797 | ||
1798 | ret = os_snprintf(buf, buflen, "%d\n", ssid->id); | |
1799 | if (ret < 0 || (size_t) ret >= buflen) | |
1800 | return -1; | |
1801 | return ret; | |
1802 | } | |
1803 | ||
1804 | ||
1805 | static int wpa_supplicant_ctrl_iface_remove_network( | |
1806 | struct wpa_supplicant *wpa_s, char *cmd) | |
1807 | { | |
1808 | int id; | |
1809 | struct wpa_ssid *ssid; | |
1810 | ||
1811 | /* cmd: "<network id>" or "all" */ | |
1812 | if (os_strcmp(cmd, "all") == 0) { | |
1813 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); | |
1814 | ssid = wpa_s->conf->ssid; | |
1815 | while (ssid) { | |
8bac466b | 1816 | struct wpa_ssid *remove_ssid = ssid; |
6fc6879b JM |
1817 | id = ssid->id; |
1818 | ssid = ssid->next; | |
8bac466b | 1819 | wpas_notify_network_removed(wpa_s, remove_ssid); |
6fc6879b JM |
1820 | wpa_config_remove_network(wpa_s->conf, id); |
1821 | } | |
d8a790b9 | 1822 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
6fc6879b | 1823 | if (wpa_s->current_ssid) { |
83df8149 JM |
1824 | #ifdef CONFIG_SME |
1825 | wpa_s->sme.prev_bssid_set = 0; | |
1826 | #endif /* CONFIG_SME */ | |
20a0b03d JM |
1827 | wpa_sm_set_config(wpa_s->wpa, NULL); |
1828 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | |
6fc6879b JM |
1829 | wpa_supplicant_disassociate(wpa_s, |
1830 | WLAN_REASON_DEAUTH_LEAVING); | |
1831 | } | |
1832 | return 0; | |
1833 | } | |
1834 | ||
1835 | id = atoi(cmd); | |
1836 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); | |
1837 | ||
1838 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
f3857c2e JM |
1839 | if (ssid) |
1840 | wpas_notify_network_removed(wpa_s, ssid); | |
6fc6879b JM |
1841 | if (ssid == NULL || |
1842 | wpa_config_remove_network(wpa_s->conf, id) < 0) { | |
1843 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | |
1844 | "id=%d", id); | |
1845 | return -1; | |
1846 | } | |
1847 | ||
d8a790b9 | 1848 | if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) { |
83df8149 JM |
1849 | #ifdef CONFIG_SME |
1850 | wpa_s->sme.prev_bssid_set = 0; | |
1851 | #endif /* CONFIG_SME */ | |
6fc6879b | 1852 | /* |
d8a790b9 JM |
1853 | * Invalidate the EAP session cache if the current or |
1854 | * previously used network is removed. | |
6fc6879b JM |
1855 | */ |
1856 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
d8a790b9 JM |
1857 | } |
1858 | ||
1859 | if (ssid == wpa_s->current_ssid) { | |
20a0b03d JM |
1860 | wpa_sm_set_config(wpa_s->wpa, NULL); |
1861 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | |
6fc6879b JM |
1862 | |
1863 | wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1864 | } | |
1865 | ||
1866 | return 0; | |
1867 | } | |
1868 | ||
1869 | ||
1870 | static int wpa_supplicant_ctrl_iface_set_network( | |
1871 | struct wpa_supplicant *wpa_s, char *cmd) | |
1872 | { | |
1873 | int id; | |
1874 | struct wpa_ssid *ssid; | |
1875 | char *name, *value; | |
1876 | ||
1877 | /* cmd: "<network id> <variable name> <value>" */ | |
1878 | name = os_strchr(cmd, ' '); | |
1879 | if (name == NULL) | |
1880 | return -1; | |
1881 | *name++ = '\0'; | |
1882 | ||
1883 | value = os_strchr(name, ' '); | |
1884 | if (value == NULL) | |
1885 | return -1; | |
1886 | *value++ = '\0'; | |
1887 | ||
1888 | id = atoi(cmd); | |
1889 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", | |
1890 | id, name); | |
1891 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
1892 | (u8 *) value, os_strlen(value)); | |
1893 | ||
1894 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
1895 | if (ssid == NULL) { | |
1896 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | |
1897 | "id=%d", id); | |
1898 | return -1; | |
1899 | } | |
1900 | ||
1901 | if (wpa_config_set(ssid, name, value, 0) < 0) { | |
1902 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " | |
1903 | "variable '%s'", name); | |
1904 | return -1; | |
1905 | } | |
1906 | ||
d8a790b9 JM |
1907 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
1908 | ||
1909 | if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) { | |
6fc6879b JM |
1910 | /* |
1911 | * Invalidate the EAP session cache if anything in the current | |
d8a790b9 | 1912 | * or previously used configuration changes. |
6fc6879b JM |
1913 | */ |
1914 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
1915 | } | |
1916 | ||
1917 | if ((os_strcmp(name, "psk") == 0 && | |
1918 | value[0] == '"' && ssid->ssid_len) || | |
1919 | (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) | |
1920 | wpa_config_update_psk(ssid); | |
aa53509f DS |
1921 | else if (os_strcmp(name, "priority") == 0) |
1922 | wpa_config_update_prio_list(wpa_s->conf); | |
6fc6879b JM |
1923 | |
1924 | return 0; | |
1925 | } | |
1926 | ||
1927 | ||
1928 | static int wpa_supplicant_ctrl_iface_get_network( | |
1929 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
1930 | { | |
1931 | int id; | |
1932 | size_t res; | |
1933 | struct wpa_ssid *ssid; | |
1934 | char *name, *value; | |
1935 | ||
1936 | /* cmd: "<network id> <variable name>" */ | |
1937 | name = os_strchr(cmd, ' '); | |
1938 | if (name == NULL || buflen == 0) | |
1939 | return -1; | |
1940 | *name++ = '\0'; | |
1941 | ||
1942 | id = atoi(cmd); | |
1943 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'", | |
1944 | id, name); | |
1945 | ||
1946 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
1947 | if (ssid == NULL) { | |
1948 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | |
1949 | "id=%d", id); | |
1950 | return -1; | |
1951 | } | |
1952 | ||
1953 | value = wpa_config_get_no_key(ssid, name); | |
1954 | if (value == NULL) { | |
1955 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " | |
1956 | "variable '%s'", name); | |
1957 | return -1; | |
1958 | } | |
1959 | ||
1960 | res = os_strlcpy(buf, value, buflen); | |
1961 | if (res >= buflen) { | |
1962 | os_free(value); | |
1963 | return -1; | |
1964 | } | |
1965 | ||
1966 | os_free(value); | |
1967 | ||
1968 | return res; | |
1969 | } | |
1970 | ||
1971 | ||
d94c9ee6 JM |
1972 | static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s, |
1973 | char *buf, size_t buflen) | |
1974 | { | |
1975 | char *pos, *end; | |
1976 | struct wpa_cred *cred; | |
1977 | int ret; | |
1978 | ||
1979 | pos = buf; | |
1980 | end = buf + buflen; | |
1981 | ret = os_snprintf(pos, end - pos, | |
1982 | "cred id / realm / username / domain / imsi\n"); | |
1983 | if (ret < 0 || ret >= end - pos) | |
1984 | return pos - buf; | |
1985 | pos += ret; | |
1986 | ||
1987 | cred = wpa_s->conf->cred; | |
1988 | while (cred) { | |
1989 | ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n", | |
1990 | cred->id, cred->realm ? cred->realm : "", | |
1991 | cred->username ? cred->username : "", | |
1992 | cred->domain ? cred->domain : "", | |
1993 | cred->imsi ? cred->imsi : ""); | |
1994 | if (ret < 0 || ret >= end - pos) | |
1995 | return pos - buf; | |
1996 | pos += ret; | |
1997 | ||
1998 | cred = cred->next; | |
1999 | } | |
2000 | ||
2001 | return pos - buf; | |
2002 | } | |
2003 | ||
2004 | ||
2005 | static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s, | |
2006 | char *buf, size_t buflen) | |
2007 | { | |
2008 | struct wpa_cred *cred; | |
2009 | int ret; | |
2010 | ||
2011 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED"); | |
2012 | ||
2013 | cred = wpa_config_add_cred(wpa_s->conf); | |
2014 | if (cred == NULL) | |
2015 | return -1; | |
2016 | ||
2017 | ret = os_snprintf(buf, buflen, "%d\n", cred->id); | |
2018 | if (ret < 0 || (size_t) ret >= buflen) | |
2019 | return -1; | |
2020 | return ret; | |
2021 | } | |
2022 | ||
2023 | ||
2024 | static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s, | |
2025 | char *cmd) | |
2026 | { | |
2027 | int id; | |
2028 | struct wpa_cred *cred; | |
2029 | ||
2030 | /* cmd: "<cred id>" or "all" */ | |
2031 | if (os_strcmp(cmd, "all") == 0) { | |
2032 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all"); | |
2033 | cred = wpa_s->conf->cred; | |
2034 | while (cred) { | |
2035 | id = cred->id; | |
2036 | cred = cred->next; | |
2037 | wpa_config_remove_cred(wpa_s->conf, id); | |
2038 | } | |
2039 | return 0; | |
2040 | } | |
2041 | ||
2042 | id = atoi(cmd); | |
2043 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id); | |
2044 | ||
2045 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
2046 | if (cred == NULL || | |
2047 | wpa_config_remove_cred(wpa_s->conf, id) < 0) { | |
2048 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | |
2049 | id); | |
2050 | return -1; | |
2051 | } | |
2052 | ||
2053 | return 0; | |
2054 | } | |
2055 | ||
2056 | ||
2057 | static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s, | |
2058 | char *cmd) | |
2059 | { | |
2060 | int id; | |
2061 | struct wpa_cred *cred; | |
2062 | char *name, *value; | |
2063 | ||
2064 | /* cmd: "<cred id> <variable name> <value>" */ | |
2065 | name = os_strchr(cmd, ' '); | |
2066 | if (name == NULL) | |
2067 | return -1; | |
2068 | *name++ = '\0'; | |
2069 | ||
2070 | value = os_strchr(name, ' '); | |
2071 | if (value == NULL) | |
2072 | return -1; | |
2073 | *value++ = '\0'; | |
2074 | ||
2075 | id = atoi(cmd); | |
2076 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'", | |
2077 | id, name); | |
2078 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
2079 | (u8 *) value, os_strlen(value)); | |
2080 | ||
2081 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
2082 | if (cred == NULL) { | |
2083 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | |
2084 | id); | |
2085 | return -1; | |
2086 | } | |
2087 | ||
2088 | if (wpa_config_set_cred(cred, name, value, 0) < 0) { | |
2089 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred " | |
2090 | "variable '%s'", name); | |
2091 | return -1; | |
2092 | } | |
2093 | ||
2094 | return 0; | |
2095 | } | |
2096 | ||
2097 | ||
6fc6879b JM |
2098 | #ifndef CONFIG_NO_CONFIG_WRITE |
2099 | static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s) | |
2100 | { | |
2101 | int ret; | |
2102 | ||
2103 | if (!wpa_s->conf->update_config) { | |
2104 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed " | |
2105 | "to update configuration (update_config=0)"); | |
2106 | return -1; | |
2107 | } | |
2108 | ||
2109 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); | |
2110 | if (ret) { | |
2111 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to " | |
2112 | "update configuration"); | |
2113 | } else { | |
2114 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration" | |
2115 | " updated"); | |
2116 | } | |
2117 | ||
2118 | return ret; | |
2119 | } | |
2120 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
2121 | ||
2122 | ||
2123 | static int ctrl_iface_get_capability_pairwise(int res, char *strict, | |
2124 | struct wpa_driver_capa *capa, | |
2125 | char *buf, size_t buflen) | |
2126 | { | |
2127 | int ret, first = 1; | |
2128 | char *pos, *end; | |
2129 | size_t len; | |
2130 | ||
2131 | pos = buf; | |
2132 | end = pos + buflen; | |
2133 | ||
2134 | if (res < 0) { | |
2135 | if (strict) | |
2136 | return 0; | |
2137 | len = os_strlcpy(buf, "CCMP TKIP NONE", buflen); | |
2138 | if (len >= buflen) | |
2139 | return -1; | |
2140 | return len; | |
2141 | } | |
2142 | ||
2143 | if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) { | |
2144 | ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " "); | |
2145 | if (ret < 0 || ret >= end - pos) | |
2146 | return pos - buf; | |
2147 | pos += ret; | |
2148 | first = 0; | |
2149 | } | |
2150 | ||
2151 | if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) { | |
2152 | ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " "); | |
2153 | if (ret < 0 || ret >= end - pos) | |
2154 | return pos - buf; | |
2155 | pos += ret; | |
2156 | first = 0; | |
2157 | } | |
2158 | ||
2159 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { | |
2160 | ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " "); | |
2161 | if (ret < 0 || ret >= end - pos) | |
2162 | return pos - buf; | |
2163 | pos += ret; | |
2164 | first = 0; | |
2165 | } | |
2166 | ||
2167 | return pos - buf; | |
2168 | } | |
2169 | ||
2170 | ||
2171 | static int ctrl_iface_get_capability_group(int res, char *strict, | |
2172 | struct wpa_driver_capa *capa, | |
2173 | char *buf, size_t buflen) | |
2174 | { | |
2175 | int ret, first = 1; | |
2176 | char *pos, *end; | |
2177 | size_t len; | |
2178 | ||
2179 | pos = buf; | |
2180 | end = pos + buflen; | |
2181 | ||
2182 | if (res < 0) { | |
2183 | if (strict) | |
2184 | return 0; | |
2185 | len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen); | |
2186 | if (len >= buflen) | |
2187 | return -1; | |
2188 | return len; | |
2189 | } | |
2190 | ||
2191 | if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) { | |
2192 | ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " "); | |
2193 | if (ret < 0 || ret >= end - pos) | |
2194 | return pos - buf; | |
2195 | pos += ret; | |
2196 | first = 0; | |
2197 | } | |
2198 | ||
2199 | if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) { | |
2200 | ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " "); | |
2201 | if (ret < 0 || ret >= end - pos) | |
2202 | return pos - buf; | |
2203 | pos += ret; | |
2204 | first = 0; | |
2205 | } | |
2206 | ||
2207 | if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) { | |
2208 | ret = os_snprintf(pos, end - pos, "%sWEP104", | |
2209 | first ? "" : " "); | |
2210 | if (ret < 0 || ret >= end - pos) | |
2211 | return pos - buf; | |
2212 | pos += ret; | |
2213 | first = 0; | |
2214 | } | |
2215 | ||
2216 | if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) { | |
2217 | ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " "); | |
2218 | if (ret < 0 || ret >= end - pos) | |
2219 | return pos - buf; | |
2220 | pos += ret; | |
2221 | first = 0; | |
2222 | } | |
2223 | ||
2224 | return pos - buf; | |
2225 | } | |
2226 | ||
2227 | ||
2228 | static int ctrl_iface_get_capability_key_mgmt(int res, char *strict, | |
2229 | struct wpa_driver_capa *capa, | |
2230 | char *buf, size_t buflen) | |
2231 | { | |
2232 | int ret; | |
2233 | char *pos, *end; | |
2234 | size_t len; | |
2235 | ||
2236 | pos = buf; | |
2237 | end = pos + buflen; | |
2238 | ||
2239 | if (res < 0) { | |
2240 | if (strict) | |
2241 | return 0; | |
2242 | len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE " | |
2243 | "NONE", buflen); | |
2244 | if (len >= buflen) | |
2245 | return -1; | |
2246 | return len; | |
2247 | } | |
2248 | ||
2249 | ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); | |
2250 | if (ret < 0 || ret >= end - pos) | |
2251 | return pos - buf; | |
2252 | pos += ret; | |
2253 | ||
2254 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
2255 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { | |
2256 | ret = os_snprintf(pos, end - pos, " WPA-EAP"); | |
2257 | if (ret < 0 || ret >= end - pos) | |
2258 | return pos - buf; | |
2259 | pos += ret; | |
2260 | } | |
2261 | ||
2262 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | |
2263 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
2264 | ret = os_snprintf(pos, end - pos, " WPA-PSK"); | |
2265 | if (ret < 0 || ret >= end - pos) | |
2266 | return pos - buf; | |
2267 | pos += ret; | |
2268 | } | |
2269 | ||
2270 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { | |
2271 | ret = os_snprintf(pos, end - pos, " WPA-NONE"); | |
2272 | if (ret < 0 || ret >= end - pos) | |
2273 | return pos - buf; | |
2274 | pos += ret; | |
2275 | } | |
2276 | ||
2277 | return pos - buf; | |
2278 | } | |
2279 | ||
2280 | ||
2281 | static int ctrl_iface_get_capability_proto(int res, char *strict, | |
2282 | struct wpa_driver_capa *capa, | |
2283 | char *buf, size_t buflen) | |
2284 | { | |
2285 | int ret, first = 1; | |
2286 | char *pos, *end; | |
2287 | size_t len; | |
2288 | ||
2289 | pos = buf; | |
2290 | end = pos + buflen; | |
2291 | ||
2292 | if (res < 0) { | |
2293 | if (strict) | |
2294 | return 0; | |
2295 | len = os_strlcpy(buf, "RSN WPA", buflen); | |
2296 | if (len >= buflen) | |
2297 | return -1; | |
2298 | return len; | |
2299 | } | |
2300 | ||
2301 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | |
2302 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
2303 | ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " "); | |
2304 | if (ret < 0 || ret >= end - pos) | |
2305 | return pos - buf; | |
2306 | pos += ret; | |
2307 | first = 0; | |
2308 | } | |
2309 | ||
2310 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
2311 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { | |
2312 | ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " "); | |
2313 | if (ret < 0 || ret >= end - pos) | |
2314 | return pos - buf; | |
2315 | pos += ret; | |
2316 | first = 0; | |
2317 | } | |
2318 | ||
2319 | return pos - buf; | |
2320 | } | |
2321 | ||
2322 | ||
2323 | static int ctrl_iface_get_capability_auth_alg(int res, char *strict, | |
2324 | struct wpa_driver_capa *capa, | |
2325 | char *buf, size_t buflen) | |
2326 | { | |
2327 | int ret, first = 1; | |
2328 | char *pos, *end; | |
2329 | size_t len; | |
2330 | ||
2331 | pos = buf; | |
2332 | end = pos + buflen; | |
2333 | ||
2334 | if (res < 0) { | |
2335 | if (strict) | |
2336 | return 0; | |
2337 | len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen); | |
2338 | if (len >= buflen) | |
2339 | return -1; | |
2340 | return len; | |
2341 | } | |
2342 | ||
2343 | if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) { | |
2344 | ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " "); | |
2345 | if (ret < 0 || ret >= end - pos) | |
2346 | return pos - buf; | |
2347 | pos += ret; | |
2348 | first = 0; | |
2349 | } | |
2350 | ||
2351 | if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) { | |
2352 | ret = os_snprintf(pos, end - pos, "%sSHARED", | |
2353 | first ? "" : " "); | |
2354 | if (ret < 0 || ret >= end - pos) | |
2355 | return pos - buf; | |
2356 | pos += ret; | |
2357 | first = 0; | |
2358 | } | |
2359 | ||
2360 | if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) { | |
2361 | ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " "); | |
2362 | if (ret < 0 || ret >= end - pos) | |
2363 | return pos - buf; | |
2364 | pos += ret; | |
2365 | first = 0; | |
2366 | } | |
2367 | ||
2368 | return pos - buf; | |
2369 | } | |
2370 | ||
2371 | ||
35aa088a DS |
2372 | static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s, |
2373 | char *buf, size_t buflen) | |
2374 | { | |
2375 | struct hostapd_channel_data *chnl; | |
2376 | int ret, i, j; | |
2377 | char *pos, *end, *hmode; | |
2378 | ||
2379 | pos = buf; | |
2380 | end = pos + buflen; | |
2381 | ||
2382 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | |
2383 | switch (wpa_s->hw.modes[j].mode) { | |
2384 | case HOSTAPD_MODE_IEEE80211B: | |
2385 | hmode = "B"; | |
2386 | break; | |
2387 | case HOSTAPD_MODE_IEEE80211G: | |
2388 | hmode = "G"; | |
2389 | break; | |
2390 | case HOSTAPD_MODE_IEEE80211A: | |
2391 | hmode = "A"; | |
2392 | break; | |
2393 | default: | |
2394 | continue; | |
2395 | } | |
2396 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode); | |
2397 | if (ret < 0 || ret >= end - pos) | |
2398 | return pos - buf; | |
2399 | pos += ret; | |
2400 | chnl = wpa_s->hw.modes[j].channels; | |
2401 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | |
2402 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | |
2403 | continue; | |
2404 | ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan); | |
2405 | if (ret < 0 || ret >= end - pos) | |
2406 | return pos - buf; | |
2407 | pos += ret; | |
2408 | } | |
2409 | ret = os_snprintf(pos, end - pos, "\n"); | |
2410 | if (ret < 0 || ret >= end - pos) | |
2411 | return pos - buf; | |
2412 | pos += ret; | |
2413 | } | |
2414 | ||
2415 | return pos - buf; | |
2416 | } | |
2417 | ||
2418 | ||
6fc6879b JM |
2419 | static int wpa_supplicant_ctrl_iface_get_capability( |
2420 | struct wpa_supplicant *wpa_s, const char *_field, char *buf, | |
2421 | size_t buflen) | |
2422 | { | |
2423 | struct wpa_driver_capa capa; | |
2424 | int res; | |
2425 | char *strict; | |
2426 | char field[30]; | |
2427 | size_t len; | |
2428 | ||
2429 | /* Determine whether or not strict checking was requested */ | |
2430 | len = os_strlcpy(field, _field, sizeof(field)); | |
2431 | if (len >= sizeof(field)) | |
2432 | return -1; | |
2433 | strict = os_strchr(field, ' '); | |
2434 | if (strict != NULL) { | |
2435 | *strict++ = '\0'; | |
2436 | if (os_strcmp(strict, "strict") != 0) | |
2437 | return -1; | |
2438 | } | |
2439 | ||
2440 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s", | |
2441 | field, strict ? strict : ""); | |
2442 | ||
2443 | if (os_strcmp(field, "eap") == 0) { | |
2444 | return eap_get_names(buf, buflen); | |
2445 | } | |
2446 | ||
2447 | res = wpa_drv_get_capa(wpa_s, &capa); | |
2448 | ||
2449 | if (os_strcmp(field, "pairwise") == 0) | |
2450 | return ctrl_iface_get_capability_pairwise(res, strict, &capa, | |
2451 | buf, buflen); | |
2452 | ||
2453 | if (os_strcmp(field, "group") == 0) | |
2454 | return ctrl_iface_get_capability_group(res, strict, &capa, | |
2455 | buf, buflen); | |
2456 | ||
2457 | if (os_strcmp(field, "key_mgmt") == 0) | |
2458 | return ctrl_iface_get_capability_key_mgmt(res, strict, &capa, | |
2459 | buf, buflen); | |
2460 | ||
2461 | if (os_strcmp(field, "proto") == 0) | |
2462 | return ctrl_iface_get_capability_proto(res, strict, &capa, | |
2463 | buf, buflen); | |
2464 | ||
2465 | if (os_strcmp(field, "auth_alg") == 0) | |
2466 | return ctrl_iface_get_capability_auth_alg(res, strict, &capa, | |
2467 | buf, buflen); | |
2468 | ||
35aa088a DS |
2469 | if (os_strcmp(field, "channels") == 0) |
2470 | return ctrl_iface_get_capability_channels(wpa_s, buf, buflen); | |
2471 | ||
6fc6879b JM |
2472 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", |
2473 | field); | |
2474 | ||
2475 | return -1; | |
2476 | } | |
2477 | ||
2478 | ||
afc064fe JM |
2479 | #ifdef CONFIG_INTERWORKING |
2480 | static char * anqp_add_hex(char *pos, char *end, const char *title, | |
2481 | struct wpabuf *data) | |
2482 | { | |
2483 | char *start = pos; | |
2484 | size_t i; | |
2485 | int ret; | |
2486 | const u8 *d; | |
2487 | ||
2488 | if (data == NULL) | |
2489 | return start; | |
2490 | ||
2491 | ret = os_snprintf(pos, end - pos, "%s=", title); | |
2492 | if (ret < 0 || ret >= end - pos) | |
2493 | return start; | |
2494 | pos += ret; | |
2495 | ||
2496 | d = wpabuf_head_u8(data); | |
2497 | for (i = 0; i < wpabuf_len(data); i++) { | |
2498 | ret = os_snprintf(pos, end - pos, "%02x", *d++); | |
2499 | if (ret < 0 || ret >= end - pos) | |
2500 | return start; | |
2501 | pos += ret; | |
2502 | } | |
2503 | ||
2504 | ret = os_snprintf(pos, end - pos, "\n"); | |
2505 | if (ret < 0 || ret >= end - pos) | |
2506 | return start; | |
2507 | pos += ret; | |
2508 | ||
2509 | return pos; | |
2510 | } | |
2511 | #endif /* CONFIG_INTERWORKING */ | |
2512 | ||
2513 | ||
61ce9085 | 2514 | static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
5f97dd1c | 2515 | unsigned long mask, char *buf, size_t buflen) |
6fc6879b | 2516 | { |
6fc6879b | 2517 | size_t i; |
6fc6879b JM |
2518 | int ret; |
2519 | char *pos, *end; | |
2520 | const u8 *ie, *ie2; | |
2521 | ||
6fc6879b JM |
2522 | pos = buf; |
2523 | end = buf + buflen; | |
6fc6879b | 2524 | |
5f97dd1c DS |
2525 | if (mask & WPA_BSS_MASK_ID) { |
2526 | ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id); | |
6fc6879b | 2527 | if (ret < 0 || ret >= end - pos) |
5f97dd1c | 2528 | return 0; |
6fc6879b JM |
2529 | pos += ret; |
2530 | } | |
2531 | ||
5f97dd1c DS |
2532 | if (mask & WPA_BSS_MASK_BSSID) { |
2533 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | |
2534 | MAC2STR(bss->bssid)); | |
2535 | if (ret < 0 || ret >= end - pos) | |
2536 | return 0; | |
2537 | pos += ret; | |
2538 | } | |
6fc6879b | 2539 | |
5f97dd1c DS |
2540 | if (mask & WPA_BSS_MASK_FREQ) { |
2541 | ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq); | |
2542 | if (ret < 0 || ret >= end - pos) | |
2543 | return 0; | |
2544 | pos += ret; | |
2545 | } | |
6fc6879b | 2546 | |
5f97dd1c DS |
2547 | if (mask & WPA_BSS_MASK_BEACON_INT) { |
2548 | ret = os_snprintf(pos, end - pos, "beacon_int=%d\n", | |
2549 | bss->beacon_int); | |
6fc6879b | 2550 | if (ret < 0 || ret >= end - pos) |
5f97dd1c | 2551 | return 0; |
6fc6879b JM |
2552 | pos += ret; |
2553 | } | |
5f97dd1c DS |
2554 | |
2555 | if (mask & WPA_BSS_MASK_CAPABILITIES) { | |
2556 | ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n", | |
2557 | bss->caps); | |
6fc6879b | 2558 | if (ret < 0 || ret >= end - pos) |
5f97dd1c | 2559 | return 0; |
6fc6879b JM |
2560 | pos += ret; |
2561 | } | |
5f97dd1c DS |
2562 | |
2563 | if (mask & WPA_BSS_MASK_QUAL) { | |
2564 | ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual); | |
bd1af96a | 2565 | if (ret < 0 || ret >= end - pos) |
5f97dd1c | 2566 | return 0; |
bd1af96a JM |
2567 | pos += ret; |
2568 | } | |
5f97dd1c DS |
2569 | |
2570 | if (mask & WPA_BSS_MASK_NOISE) { | |
2571 | ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise); | |
cc81110d | 2572 | if (ret < 0 || ret >= end - pos) |
5f97dd1c | 2573 | return 0; |
cc81110d JM |
2574 | pos += ret; |
2575 | } | |
6fc6879b | 2576 | |
5f97dd1c DS |
2577 | if (mask & WPA_BSS_MASK_LEVEL) { |
2578 | ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level); | |
2579 | if (ret < 0 || ret >= end - pos) | |
2580 | return 0; | |
2581 | pos += ret; | |
2582 | } | |
6fc6879b | 2583 | |
5f97dd1c DS |
2584 | if (mask & WPA_BSS_MASK_TSF) { |
2585 | ret = os_snprintf(pos, end - pos, "tsf=%016llu\n", | |
2586 | (unsigned long long) bss->tsf); | |
2587 | if (ret < 0 || ret >= end - pos) | |
2588 | return 0; | |
2589 | pos += ret; | |
2590 | } | |
2591 | ||
2592 | if (mask & WPA_BSS_MASK_AGE) { | |
2593 | struct os_time now; | |
2594 | ||
2595 | os_get_time(&now); | |
2596 | ret = os_snprintf(pos, end - pos, "age=%d\n", | |
2597 | (int) (now.sec - bss->last_update.sec)); | |
2598 | if (ret < 0 || ret >= end - pos) | |
2599 | return 0; | |
2600 | pos += ret; | |
2601 | } | |
2602 | ||
2603 | if (mask & WPA_BSS_MASK_IE) { | |
2604 | ret = os_snprintf(pos, end - pos, "ie="); | |
2605 | if (ret < 0 || ret >= end - pos) | |
2606 | return 0; | |
2607 | pos += ret; | |
2608 | ||
2609 | ie = (const u8 *) (bss + 1); | |
2610 | for (i = 0; i < bss->ie_len; i++) { | |
2611 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); | |
2612 | if (ret < 0 || ret >= end - pos) | |
2613 | return 0; | |
2614 | pos += ret; | |
2615 | } | |
2616 | ||
2617 | ret = os_snprintf(pos, end - pos, "\n"); | |
2618 | if (ret < 0 || ret >= end - pos) | |
2619 | return 0; | |
2620 | pos += ret; | |
2621 | } | |
2622 | ||
2623 | if (mask & WPA_BSS_MASK_FLAGS) { | |
2624 | ret = os_snprintf(pos, end - pos, "flags="); | |
2625 | if (ret < 0 || ret >= end - pos) | |
2626 | return 0; | |
2627 | pos += ret; | |
2628 | ||
2629 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | |
2630 | if (ie) | |
2631 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, | |
2632 | 2 + ie[1]); | |
2633 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); | |
2634 | if (ie2) | |
2635 | pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, | |
2636 | 2 + ie2[1]); | |
2637 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); | |
2638 | if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) { | |
2639 | ret = os_snprintf(pos, end - pos, "[WEP]"); | |
2640 | if (ret < 0 || ret >= end - pos) | |
2641 | return 0; | |
2642 | pos += ret; | |
2643 | } | |
2644 | if (bss->caps & IEEE80211_CAP_IBSS) { | |
2645 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | |
2646 | if (ret < 0 || ret >= end - pos) | |
2647 | return 0; | |
2648 | pos += ret; | |
2649 | } | |
2650 | if (bss->caps & IEEE80211_CAP_ESS) { | |
2651 | ret = os_snprintf(pos, end - pos, "[ESS]"); | |
2652 | if (ret < 0 || ret >= end - pos) | |
2653 | return 0; | |
2654 | pos += ret; | |
2655 | } | |
2656 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) { | |
2657 | ret = os_snprintf(pos, end - pos, "[P2P]"); | |
2658 | if (ret < 0 || ret >= end - pos) | |
2659 | return 0; | |
2660 | pos += ret; | |
2661 | } | |
64855b96 JM |
2662 | #ifdef CONFIG_HS20 |
2663 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) { | |
2664 | ret = os_snprintf(pos, end - pos, "[HS20]"); | |
2665 | if (ret < 0 || ret >= end - pos) | |
2666 | return -1; | |
2667 | pos += ret; | |
2668 | } | |
2669 | #endif /* CONFIG_HS20 */ | |
5f97dd1c DS |
2670 | |
2671 | ret = os_snprintf(pos, end - pos, "\n"); | |
2672 | if (ret < 0 || ret >= end - pos) | |
2673 | return 0; | |
2674 | pos += ret; | |
2675 | } | |
2676 | ||
2677 | if (mask & WPA_BSS_MASK_SSID) { | |
2678 | ret = os_snprintf(pos, end - pos, "ssid=%s\n", | |
2679 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | |
2680 | if (ret < 0 || ret >= end - pos) | |
2681 | return 0; | |
2682 | pos += ret; | |
2683 | } | |
6fc6879b | 2684 | |
611ed491 | 2685 | #ifdef CONFIG_WPS |
5f97dd1c DS |
2686 | if (mask & WPA_BSS_MASK_WPS_SCAN) { |
2687 | ie = (const u8 *) (bss + 1); | |
2688 | ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end); | |
2689 | if (ret < 0 || ret >= end - pos) | |
2690 | return 0; | |
2691 | pos += ret; | |
2692 | } | |
611ed491 JM |
2693 | #endif /* CONFIG_WPS */ |
2694 | ||
0c6b310e | 2695 | #ifdef CONFIG_P2P |
5f97dd1c DS |
2696 | if (mask & WPA_BSS_MASK_P2P_SCAN) { |
2697 | ie = (const u8 *) (bss + 1); | |
2698 | ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end); | |
2699 | if (ret < 0 || ret >= end - pos) | |
2700 | return 0; | |
2701 | pos += ret; | |
2702 | } | |
0c6b310e JM |
2703 | #endif /* CONFIG_P2P */ |
2704 | ||
afc064fe | 2705 | #ifdef CONFIG_INTERWORKING |
5f97dd1c DS |
2706 | if (mask & WPA_BSS_MASK_INTERNETW) { |
2707 | pos = anqp_add_hex(pos, end, "anqp_venue_name", | |
2708 | bss->anqp_venue_name); | |
2709 | pos = anqp_add_hex(pos, end, "anqp_network_auth_type", | |
2710 | bss->anqp_network_auth_type); | |
2711 | pos = anqp_add_hex(pos, end, "anqp_roaming_consortium", | |
2712 | bss->anqp_roaming_consortium); | |
2713 | pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability", | |
2714 | bss->anqp_ip_addr_type_availability); | |
2715 | pos = anqp_add_hex(pos, end, "anqp_nai_realm", | |
2716 | bss->anqp_nai_realm); | |
2717 | pos = anqp_add_hex(pos, end, "anqp_3gpp", bss->anqp_3gpp); | |
2718 | pos = anqp_add_hex(pos, end, "anqp_domain_name", | |
2719 | bss->anqp_domain_name); | |
25471fe3 JK |
2720 | #ifdef CONFIG_HS20 |
2721 | pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name", | |
2722 | bss->hs20_operator_friendly_name); | |
2723 | pos = anqp_add_hex(pos, end, "hs20_wan_metrics", | |
2724 | bss->hs20_wan_metrics); | |
2725 | pos = anqp_add_hex(pos, end, "hs20_connection_capability", | |
2726 | bss->hs20_connection_capability); | |
2727 | #endif /* CONFIG_HS20 */ | |
5f97dd1c | 2728 | } |
afc064fe JM |
2729 | #endif /* CONFIG_INTERWORKING */ |
2730 | ||
6fc6879b JM |
2731 | return pos - buf; |
2732 | } | |
2733 | ||
2734 | ||
61ce9085 DS |
2735 | static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s, |
2736 | const char *cmd, char *buf, | |
2737 | size_t buflen) | |
2738 | { | |
2739 | u8 bssid[ETH_ALEN]; | |
2740 | size_t i; | |
2741 | struct wpa_bss *bss; | |
eff1a95b DS |
2742 | struct wpa_bss *bsslast = NULL; |
2743 | struct dl_list *next; | |
2744 | int ret = 0; | |
2745 | int len; | |
5f97dd1c DS |
2746 | char *ctmp; |
2747 | unsigned long mask = WPA_BSS_MASK_ALL; | |
61ce9085 | 2748 | |
eff1a95b DS |
2749 | if (os_strncmp(cmd, "RANGE=", 6) == 0) { |
2750 | if (os_strncmp(cmd + 6, "ALL", 3) == 0) { | |
2751 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, | |
2752 | list_id); | |
2753 | bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss, | |
2754 | list_id); | |
2755 | } else { /* N1-N2 */ | |
2756 | unsigned int id1, id2; | |
2757 | ||
2758 | if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) { | |
2759 | wpa_printf(MSG_INFO, "Wrong BSS range " | |
2760 | "format"); | |
2761 | return 0; | |
2762 | } | |
2763 | ||
2764 | id1 = atoi(cmd + 6); | |
2765 | bss = wpa_bss_get_id(wpa_s, id1); | |
2766 | id2 = atoi(ctmp + 1); | |
2767 | if (id2 == 0) | |
2768 | bsslast = dl_list_last(&wpa_s->bss_id, | |
2769 | struct wpa_bss, | |
2770 | list_id); | |
2771 | else { | |
2772 | bsslast = wpa_bss_get_id(wpa_s, id2); | |
2773 | if (bsslast == NULL && bss && id2 > id1) { | |
2774 | struct wpa_bss *tmp = bss; | |
2775 | for (;;) { | |
2776 | next = tmp->list_id.next; | |
2777 | if (next == &wpa_s->bss_id) | |
2778 | break; | |
2779 | tmp = dl_list_entry( | |
2780 | next, struct wpa_bss, | |
2781 | list_id); | |
2782 | if (tmp->id > id2) | |
2783 | break; | |
2784 | bsslast = tmp; | |
2785 | } | |
2786 | } | |
2787 | } | |
2788 | } | |
2789 | } else if (os_strcmp(cmd, "FIRST") == 0) | |
51a0c3d4 | 2790 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id); |
61ce9085 DS |
2791 | else if (os_strncmp(cmd, "ID-", 3) == 0) { |
2792 | i = atoi(cmd + 3); | |
2793 | bss = wpa_bss_get_id(wpa_s, i); | |
2794 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | |
2795 | i = atoi(cmd + 5); | |
2796 | bss = wpa_bss_get_id(wpa_s, i); | |
2797 | if (bss) { | |
eff1a95b | 2798 | next = bss->list_id.next; |
61ce9085 DS |
2799 | if (next == &wpa_s->bss_id) |
2800 | bss = NULL; | |
2801 | else | |
2802 | bss = dl_list_entry(next, struct wpa_bss, | |
2803 | list_id); | |
2804 | } | |
2805 | #ifdef CONFIG_P2P | |
2806 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | |
2807 | if (hwaddr_aton(cmd + 13, bssid) == 0) | |
2808 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid); | |
2809 | else | |
2810 | bss = NULL; | |
2811 | #endif /* CONFIG_P2P */ | |
2812 | } else if (hwaddr_aton(cmd, bssid) == 0) | |
2813 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
2814 | else { | |
2815 | struct wpa_bss *tmp; | |
2816 | i = atoi(cmd); | |
2817 | bss = NULL; | |
2818 | dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id) | |
2819 | { | |
2820 | if (i-- == 0) { | |
2821 | bss = tmp; | |
2822 | break; | |
2823 | } | |
2824 | } | |
2825 | } | |
2826 | ||
5f97dd1c DS |
2827 | if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) { |
2828 | mask = strtoul(ctmp + 5, NULL, 0x10); | |
2829 | if (mask == 0) | |
2830 | mask = WPA_BSS_MASK_ALL; | |
2831 | } | |
2832 | ||
61ce9085 DS |
2833 | if (bss == NULL) |
2834 | return 0; | |
2835 | ||
eff1a95b DS |
2836 | if (bsslast == NULL) |
2837 | bsslast = bss; | |
2838 | do { | |
2839 | len = print_bss_info(wpa_s, bss, mask, buf, buflen); | |
2840 | ret += len; | |
2841 | buf += len; | |
2842 | buflen -= len; | |
2843 | if (bss == bsslast) | |
2844 | break; | |
2845 | next = bss->list_id.next; | |
2846 | if (next == &wpa_s->bss_id) | |
2847 | break; | |
2848 | bss = dl_list_entry(next, struct wpa_bss, list_id); | |
2849 | } while (bss && len); | |
2850 | ||
2851 | return ret; | |
61ce9085 DS |
2852 | } |
2853 | ||
2854 | ||
6fc6879b JM |
2855 | static int wpa_supplicant_ctrl_iface_ap_scan( |
2856 | struct wpa_supplicant *wpa_s, char *cmd) | |
2857 | { | |
2858 | int ap_scan = atoi(cmd); | |
86b89452 | 2859 | return wpa_supplicant_set_ap_scan(wpa_s, ap_scan); |
6fc6879b JM |
2860 | } |
2861 | ||
2862 | ||
67b9bd08 DS |
2863 | static int wpa_supplicant_ctrl_iface_scan_interval( |
2864 | struct wpa_supplicant *wpa_s, char *cmd) | |
2865 | { | |
2866 | int scan_int = atoi(cmd); | |
c6e86b63 | 2867 | return wpa_supplicant_set_scan_interval(wpa_s, scan_int); |
67b9bd08 DS |
2868 | } |
2869 | ||
2870 | ||
78633c37 SL |
2871 | static int wpa_supplicant_ctrl_iface_bss_expire_age( |
2872 | struct wpa_supplicant *wpa_s, char *cmd) | |
2873 | { | |
2874 | int expire_age = atoi(cmd); | |
2875 | return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age); | |
2876 | } | |
2877 | ||
2878 | ||
2879 | static int wpa_supplicant_ctrl_iface_bss_expire_count( | |
2880 | struct wpa_supplicant *wpa_s, char *cmd) | |
2881 | { | |
2882 | int expire_count = atoi(cmd); | |
2883 | return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count); | |
2884 | } | |
2885 | ||
2886 | ||
32d5295f JM |
2887 | static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s) |
2888 | { | |
32d5295f JM |
2889 | wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication"); |
2890 | /* MLME-DELETEKEYS.request */ | |
0382097e JM |
2891 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0); |
2892 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0); | |
2893 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0); | |
2894 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0); | |
32d5295f | 2895 | #ifdef CONFIG_IEEE80211W |
0382097e JM |
2896 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0); |
2897 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0); | |
32d5295f JM |
2898 | #endif /* CONFIG_IEEE80211W */ |
2899 | ||
2900 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL, | |
2901 | 0); | |
2902 | /* MLME-SETPROTECTION.request(None) */ | |
2903 | wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid, | |
2904 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, | |
2905 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); | |
2906 | wpa_sm_drop_sa(wpa_s->wpa); | |
2907 | } | |
2908 | ||
2909 | ||
86d4f806 JM |
2910 | static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s, |
2911 | char *addr) | |
2912 | { | |
90b8fc8f JM |
2913 | #ifdef CONFIG_NO_SCAN_PROCESSING |
2914 | return -1; | |
2915 | #else /* CONFIG_NO_SCAN_PROCESSING */ | |
86d4f806 JM |
2916 | u8 bssid[ETH_ALEN]; |
2917 | struct wpa_bss *bss; | |
2918 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
2919 | ||
2920 | if (hwaddr_aton(addr, bssid)) { | |
2921 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid " | |
2922 | "address '%s'", addr); | |
2923 | return -1; | |
2924 | } | |
2925 | ||
2926 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid)); | |
2927 | ||
2928 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
2929 | if (!bss) { | |
2930 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found " | |
2931 | "from BSS table"); | |
2932 | return -1; | |
2933 | } | |
2934 | ||
2935 | /* | |
2936 | * TODO: Find best network configuration block from configuration to | |
2937 | * allow roaming to other networks | |
2938 | */ | |
2939 | ||
2940 | if (!ssid) { | |
2941 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network " | |
2942 | "configuration known for the target AP"); | |
2943 | return -1; | |
2944 | } | |
2945 | ||
2946 | wpa_s->reassociate = 1; | |
2947 | wpa_supplicant_connect(wpa_s, bss, ssid); | |
2948 | ||
2949 | return 0; | |
90b8fc8f | 2950 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
86d4f806 JM |
2951 | } |
2952 | ||
2953 | ||
b563b388 JM |
2954 | #ifdef CONFIG_P2P |
2955 | static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd) | |
2956 | { | |
2957 | unsigned int timeout = atoi(cmd); | |
2958 | enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL; | |
6d92fa6e JM |
2959 | u8 dev_id[ETH_ALEN], *_dev_id = NULL; |
2960 | char *pos; | |
b563b388 JM |
2961 | |
2962 | if (os_strstr(cmd, "type=social")) | |
2963 | type = P2P_FIND_ONLY_SOCIAL; | |
2964 | else if (os_strstr(cmd, "type=progressive")) | |
2965 | type = P2P_FIND_PROGRESSIVE; | |
2966 | ||
6d92fa6e JM |
2967 | pos = os_strstr(cmd, "dev_id="); |
2968 | if (pos) { | |
2969 | pos += 7; | |
2970 | if (hwaddr_aton(pos, dev_id)) | |
2971 | return -1; | |
2972 | _dev_id = dev_id; | |
2973 | } | |
2974 | ||
2975 | return wpas_p2p_find(wpa_s, timeout, type, 0, NULL, _dev_id); | |
b563b388 JM |
2976 | } |
2977 | ||
2978 | ||
2979 | static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd, | |
2980 | char *buf, size_t buflen) | |
2981 | { | |
2982 | u8 addr[ETH_ALEN]; | |
2983 | char *pos, *pos2; | |
2984 | char *pin = NULL; | |
2985 | enum p2p_wps_method wps_method; | |
2986 | int new_pin; | |
2987 | int ret; | |
23c84252 | 2988 | int persistent_group, persistent_id = -1; |
b563b388 JM |
2989 | int join; |
2990 | int auth; | |
b31be3a0 | 2991 | int automatic; |
b563b388 JM |
2992 | int go_intent = -1; |
2993 | int freq = 0; | |
3bc462cb | 2994 | int pd; |
e2308e4b | 2995 | int ht40; |
b563b388 | 2996 | |
23c84252 JM |
2997 | /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad] |
2998 | * [persistent|persistent=<network id>] | |
e2308e4b RM |
2999 | * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] |
3000 | * [ht40] */ | |
b563b388 JM |
3001 | |
3002 | if (hwaddr_aton(cmd, addr)) | |
3003 | return -1; | |
3004 | ||
3005 | pos = cmd + 17; | |
3006 | if (*pos != ' ') | |
3007 | return -1; | |
3008 | pos++; | |
3009 | ||
3010 | persistent_group = os_strstr(pos, " persistent") != NULL; | |
23c84252 JM |
3011 | pos2 = os_strstr(pos, " persistent="); |
3012 | if (pos2) { | |
3013 | struct wpa_ssid *ssid; | |
3014 | persistent_id = atoi(pos2 + 12); | |
3015 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); | |
3016 | if (ssid == NULL || ssid->disabled != 2 || | |
3017 | ssid->mode != WPAS_MODE_P2P_GO) { | |
3018 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
3019 | "SSID id=%d for persistent P2P group (GO)", | |
3020 | persistent_id); | |
3021 | return -1; | |
3022 | } | |
3023 | } | |
b563b388 JM |
3024 | join = os_strstr(pos, " join") != NULL; |
3025 | auth = os_strstr(pos, " auth") != NULL; | |
b31be3a0 | 3026 | automatic = os_strstr(pos, " auto") != NULL; |
3bc462cb | 3027 | pd = os_strstr(pos, " provdisc") != NULL; |
e2308e4b | 3028 | ht40 = os_strstr(pos, " ht40") != NULL; |
b563b388 JM |
3029 | |
3030 | pos2 = os_strstr(pos, " go_intent="); | |
3031 | if (pos2) { | |
3032 | pos2 += 11; | |
3033 | go_intent = atoi(pos2); | |
3034 | if (go_intent < 0 || go_intent > 15) | |
3035 | return -1; | |
3036 | } | |
3037 | ||
3038 | pos2 = os_strstr(pos, " freq="); | |
3039 | if (pos2) { | |
3040 | pos2 += 6; | |
3041 | freq = atoi(pos2); | |
3042 | if (freq <= 0) | |
3043 | return -1; | |
3044 | } | |
3045 | ||
3046 | if (os_strncmp(pos, "pin", 3) == 0) { | |
3047 | /* Request random PIN (to be displayed) and enable the PIN */ | |
3048 | wps_method = WPS_PIN_DISPLAY; | |
3049 | } else if (os_strncmp(pos, "pbc", 3) == 0) { | |
3050 | wps_method = WPS_PBC; | |
3051 | } else { | |
3052 | pin = pos; | |
3053 | pos = os_strchr(pin, ' '); | |
3054 | wps_method = WPS_PIN_KEYPAD; | |
3055 | if (pos) { | |
3056 | *pos++ = '\0'; | |
07fecd39 | 3057 | if (os_strncmp(pos, "display", 7) == 0) |
b563b388 JM |
3058 | wps_method = WPS_PIN_DISPLAY; |
3059 | } | |
dcc33057 | 3060 | if (!wps_pin_str_valid(pin)) { |
36ebf7a1 MH |
3061 | os_memcpy(buf, "FAIL-INVALID-PIN\n", 17); |
3062 | return 17; | |
3063 | } | |
b563b388 JM |
3064 | } |
3065 | ||
3066 | new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method, | |
b31be3a0 | 3067 | persistent_group, automatic, join, |
e2308e4b RM |
3068 | auth, go_intent, freq, persistent_id, pd, |
3069 | ht40); | |
d054a462 JM |
3070 | if (new_pin == -2) { |
3071 | os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25); | |
3072 | return 25; | |
3073 | } | |
3074 | if (new_pin == -3) { | |
3075 | os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25); | |
3076 | return 25; | |
3077 | } | |
b563b388 JM |
3078 | if (new_pin < 0) |
3079 | return -1; | |
3080 | if (wps_method == WPS_PIN_DISPLAY && pin == NULL) { | |
3081 | ret = os_snprintf(buf, buflen, "%08d", new_pin); | |
3082 | if (ret < 0 || (size_t) ret >= buflen) | |
3083 | return -1; | |
3084 | return ret; | |
3085 | } | |
3086 | ||
3087 | os_memcpy(buf, "OK\n", 3); | |
3088 | return 3; | |
3089 | } | |
3090 | ||
3091 | ||
3092 | static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd) | |
3093 | { | |
3094 | unsigned int timeout = atoi(cmd); | |
3095 | return wpas_p2p_listen(wpa_s, timeout); | |
3096 | } | |
3097 | ||
3098 | ||
3099 | static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) | |
3100 | { | |
3101 | u8 addr[ETH_ALEN]; | |
3102 | char *pos; | |
0918c4bf | 3103 | enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG; |
b563b388 | 3104 | |
0918c4bf | 3105 | /* <addr> <config method> [join|auto] */ |
b563b388 JM |
3106 | |
3107 | if (hwaddr_aton(cmd, addr)) | |
3108 | return -1; | |
3109 | ||
3110 | pos = cmd + 17; | |
3111 | if (*pos != ' ') | |
3112 | return -1; | |
3113 | pos++; | |
3114 | ||
0918c4bf JM |
3115 | if (os_strstr(pos, " join") != NULL) |
3116 | use = WPAS_P2P_PD_FOR_JOIN; | |
3117 | else if (os_strstr(pos, " auto") != NULL) | |
3118 | use = WPAS_P2P_PD_AUTO; | |
3119 | ||
3120 | return wpas_p2p_prov_disc(wpa_s, addr, pos, use); | |
b563b388 JM |
3121 | } |
3122 | ||
3123 | ||
3124 | static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf, | |
3125 | size_t buflen) | |
3126 | { | |
3127 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
3128 | ||
3129 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || | |
3130 | ssid->passphrase == NULL) | |
3131 | return -1; | |
3132 | ||
3133 | os_strlcpy(buf, ssid->passphrase, buflen); | |
3134 | return os_strlen(buf); | |
3135 | } | |
3136 | ||
3137 | ||
3138 | static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd, | |
3139 | char *buf, size_t buflen) | |
3140 | { | |
3141 | u64 ref; | |
3142 | int res; | |
3143 | u8 dst_buf[ETH_ALEN], *dst; | |
3144 | struct wpabuf *tlvs; | |
3145 | char *pos; | |
3146 | size_t len; | |
3147 | ||
3148 | if (hwaddr_aton(cmd, dst_buf)) | |
3149 | return -1; | |
3150 | dst = dst_buf; | |
3151 | if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 && | |
3152 | dst[3] == 0 && dst[4] == 0 && dst[5] == 0) | |
3153 | dst = NULL; | |
3154 | pos = cmd + 17; | |
3155 | if (*pos != ' ') | |
3156 | return -1; | |
3157 | pos++; | |
3158 | ||
3159 | if (os_strncmp(pos, "upnp ", 5) == 0) { | |
3160 | u8 version; | |
3161 | pos += 5; | |
3162 | if (hexstr2bin(pos, &version, 1) < 0) | |
3163 | return -1; | |
3164 | pos += 2; | |
3165 | if (*pos != ' ') | |
3166 | return -1; | |
3167 | pos++; | |
7165c5dc | 3168 | ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos); |
b563b388 JM |
3169 | } else { |
3170 | len = os_strlen(pos); | |
3171 | if (len & 1) | |
3172 | return -1; | |
3173 | len /= 2; | |
3174 | tlvs = wpabuf_alloc(len); | |
3175 | if (tlvs == NULL) | |
3176 | return -1; | |
3177 | if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) { | |
3178 | wpabuf_free(tlvs); | |
3179 | return -1; | |
3180 | } | |
3181 | ||
7165c5dc | 3182 | ref = wpas_p2p_sd_request(wpa_s, dst, tlvs); |
b563b388 JM |
3183 | wpabuf_free(tlvs); |
3184 | } | |
7165c5dc JM |
3185 | if (ref == 0) |
3186 | return -1; | |
b563b388 JM |
3187 | res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref); |
3188 | if (res < 0 || (unsigned) res >= buflen) | |
3189 | return -1; | |
3190 | return res; | |
3191 | } | |
3192 | ||
3193 | ||
3194 | static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s, | |
3195 | char *cmd) | |
3196 | { | |
3197 | long long unsigned val; | |
3198 | u64 req; | |
3199 | if (sscanf(cmd, "%llx", &val) != 1) | |
3200 | return -1; | |
3201 | req = val; | |
7165c5dc | 3202 | return wpas_p2p_sd_cancel_request(wpa_s, req); |
b563b388 JM |
3203 | } |
3204 | ||
3205 | ||
3206 | static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd) | |
3207 | { | |
3208 | int freq; | |
d25f7212 | 3209 | u8 dst[ETH_ALEN]; |
b563b388 JM |
3210 | u8 dialog_token; |
3211 | struct wpabuf *resp_tlvs; | |
3212 | char *pos, *pos2; | |
3213 | size_t len; | |
3214 | ||
3215 | pos = os_strchr(cmd, ' '); | |
3216 | if (pos == NULL) | |
3217 | return -1; | |
3218 | *pos++ = '\0'; | |
3219 | freq = atoi(cmd); | |
3220 | if (freq == 0) | |
3221 | return -1; | |
3222 | ||
d25f7212 | 3223 | if (hwaddr_aton(pos, dst)) |
b563b388 | 3224 | return -1; |
b563b388 JM |
3225 | pos += 17; |
3226 | if (*pos != ' ') | |
3227 | return -1; | |
3228 | pos++; | |
3229 | ||
3230 | pos2 = os_strchr(pos, ' '); | |
3231 | if (pos2 == NULL) | |
3232 | return -1; | |
3233 | *pos2++ = '\0'; | |
3234 | dialog_token = atoi(pos); | |
3235 | ||
3236 | len = os_strlen(pos2); | |
3237 | if (len & 1) | |
3238 | return -1; | |
3239 | len /= 2; | |
3240 | resp_tlvs = wpabuf_alloc(len); | |
3241 | if (resp_tlvs == NULL) | |
3242 | return -1; | |
3243 | if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) { | |
3244 | wpabuf_free(resp_tlvs); | |
3245 | return -1; | |
3246 | } | |
3247 | ||
3248 | wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs); | |
3249 | wpabuf_free(resp_tlvs); | |
3250 | return 0; | |
3251 | } | |
3252 | ||
3253 | ||
3254 | static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s, | |
3255 | char *cmd) | |
3256 | { | |
28ef705d GB |
3257 | if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1")) |
3258 | return -1; | |
b563b388 JM |
3259 | wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd); |
3260 | return 0; | |
3261 | } | |
3262 | ||
3263 | ||
3264 | static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s, | |
3265 | char *cmd) | |
3266 | { | |
3267 | char *pos; | |
3268 | size_t len; | |
3269 | struct wpabuf *query, *resp; | |
3270 | ||
3271 | pos = os_strchr(cmd, ' '); | |
3272 | if (pos == NULL) | |
3273 | return -1; | |
3274 | *pos++ = '\0'; | |
3275 | ||
3276 | len = os_strlen(cmd); | |
3277 | if (len & 1) | |
3278 | return -1; | |
3279 | len /= 2; | |
3280 | query = wpabuf_alloc(len); | |
3281 | if (query == NULL) | |
3282 | return -1; | |
3283 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | |
3284 | wpabuf_free(query); | |
3285 | return -1; | |
3286 | } | |
3287 | ||
3288 | len = os_strlen(pos); | |
3289 | if (len & 1) { | |
3290 | wpabuf_free(query); | |
3291 | return -1; | |
3292 | } | |
3293 | len /= 2; | |
3294 | resp = wpabuf_alloc(len); | |
3295 | if (resp == NULL) { | |
3296 | wpabuf_free(query); | |
3297 | return -1; | |
3298 | } | |
3299 | if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) { | |
3300 | wpabuf_free(query); | |
3301 | wpabuf_free(resp); | |
3302 | return -1; | |
3303 | } | |
3304 | ||
3305 | if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) { | |
3306 | wpabuf_free(query); | |
3307 | wpabuf_free(resp); | |
3308 | return -1; | |
3309 | } | |
3310 | return 0; | |
3311 | } | |
3312 | ||
3313 | ||
3314 | static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd) | |
3315 | { | |
3316 | char *pos; | |
3317 | u8 version; | |
3318 | ||
3319 | pos = os_strchr(cmd, ' '); | |
3320 | if (pos == NULL) | |
3321 | return -1; | |
3322 | *pos++ = '\0'; | |
3323 | ||
3324 | if (hexstr2bin(cmd, &version, 1) < 0) | |
3325 | return -1; | |
3326 | ||
3327 | return wpas_p2p_service_add_upnp(wpa_s, version, pos); | |
3328 | } | |
3329 | ||
3330 | ||
3331 | static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd) | |
3332 | { | |
3333 | char *pos; | |
3334 | ||
3335 | pos = os_strchr(cmd, ' '); | |
3336 | if (pos == NULL) | |
3337 | return -1; | |
3338 | *pos++ = '\0'; | |
3339 | ||
3340 | if (os_strcmp(cmd, "bonjour") == 0) | |
3341 | return p2p_ctrl_service_add_bonjour(wpa_s, pos); | |
3342 | if (os_strcmp(cmd, "upnp") == 0) | |
3343 | return p2p_ctrl_service_add_upnp(wpa_s, pos); | |
3344 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | |
3345 | return -1; | |
3346 | } | |
3347 | ||
3348 | ||
3349 | static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s, | |
3350 | char *cmd) | |
3351 | { | |
3352 | size_t len; | |
3353 | struct wpabuf *query; | |
3354 | int ret; | |
3355 | ||
3356 | len = os_strlen(cmd); | |
3357 | if (len & 1) | |
3358 | return -1; | |
3359 | len /= 2; | |
3360 | query = wpabuf_alloc(len); | |
3361 | if (query == NULL) | |
3362 | return -1; | |
3363 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | |
3364 | wpabuf_free(query); | |
3365 | return -1; | |
3366 | } | |
3367 | ||
3368 | ret = wpas_p2p_service_del_bonjour(wpa_s, query); | |
3369 | wpabuf_free(query); | |
3370 | return ret; | |
3371 | } | |
3372 | ||
3373 | ||
3374 | static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd) | |
3375 | { | |
3376 | char *pos; | |
3377 | u8 version; | |
3378 | ||
3379 | pos = os_strchr(cmd, ' '); | |
3380 | if (pos == NULL) | |
3381 | return -1; | |
3382 | *pos++ = '\0'; | |
3383 | ||
3384 | if (hexstr2bin(cmd, &version, 1) < 0) | |
3385 | return -1; | |
3386 | ||
3387 | return wpas_p2p_service_del_upnp(wpa_s, version, pos); | |
3388 | } | |
3389 | ||
3390 | ||
3391 | static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd) | |
3392 | { | |
3393 | char *pos; | |
3394 | ||
3395 | pos = os_strchr(cmd, ' '); | |
3396 | if (pos == NULL) | |
3397 | return -1; | |
3398 | *pos++ = '\0'; | |
3399 | ||
3400 | if (os_strcmp(cmd, "bonjour") == 0) | |
3401 | return p2p_ctrl_service_del_bonjour(wpa_s, pos); | |
3402 | if (os_strcmp(cmd, "upnp") == 0) | |
3403 | return p2p_ctrl_service_del_upnp(wpa_s, pos); | |
3404 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | |
3405 | return -1; | |
3406 | } | |
3407 | ||
3408 | ||
3409 | static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd) | |
3410 | { | |
3411 | u8 addr[ETH_ALEN]; | |
3412 | ||
3413 | /* <addr> */ | |
3414 | ||
3415 | if (hwaddr_aton(cmd, addr)) | |
3416 | return -1; | |
3417 | ||
3418 | return wpas_p2p_reject(wpa_s, addr); | |
3419 | } | |
3420 | ||
3421 | ||
3422 | static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd) | |
3423 | { | |
3424 | char *pos; | |
3425 | int id; | |
3426 | struct wpa_ssid *ssid; | |
3427 | u8 peer[ETH_ALEN]; | |
3428 | ||
3429 | id = atoi(cmd); | |
3430 | pos = os_strstr(cmd, " peer="); | |
3431 | if (pos) { | |
3432 | pos += 6; | |
3433 | if (hwaddr_aton(pos, peer)) | |
3434 | return -1; | |
3435 | } | |
3436 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
3437 | if (ssid == NULL || ssid->disabled != 2) { | |
3438 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
3439 | "for persistent P2P group", | |
3440 | id); | |
3441 | return -1; | |
3442 | } | |
3443 | ||
3444 | return wpas_p2p_invite(wpa_s, pos ? peer : NULL, ssid, NULL); | |
3445 | } | |
3446 | ||
3447 | ||
3448 | static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd) | |
3449 | { | |
3450 | char *pos; | |
3451 | u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL; | |
3452 | ||
3453 | pos = os_strstr(cmd, " peer="); | |
3454 | if (!pos) | |
3455 | return -1; | |
3456 | ||
3457 | *pos = '\0'; | |
3458 | pos += 6; | |
3459 | if (hwaddr_aton(pos, peer)) { | |
3460 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos); | |
3461 | return -1; | |
3462 | } | |
3463 | ||
3464 | pos = os_strstr(pos, " go_dev_addr="); | |
3465 | if (pos) { | |
3466 | pos += 13; | |
3467 | if (hwaddr_aton(pos, go_dev_addr)) { | |
3468 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", | |
3469 | pos); | |
3470 | return -1; | |
3471 | } | |
3472 | go_dev = go_dev_addr; | |
3473 | } | |
3474 | ||
3475 | return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev); | |
3476 | } | |
3477 | ||
3478 | ||
3479 | static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd) | |
3480 | { | |
3481 | if (os_strncmp(cmd, "persistent=", 11) == 0) | |
3482 | return p2p_ctrl_invite_persistent(wpa_s, cmd + 11); | |
3483 | if (os_strncmp(cmd, "group=", 6) == 0) | |
3484 | return p2p_ctrl_invite_group(wpa_s, cmd + 6); | |
3485 | ||
3486 | return -1; | |
3487 | } | |
3488 | ||
3489 | ||
3490 | static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, | |
7aeac985 | 3491 | char *cmd, int freq, int ht40) |
b563b388 JM |
3492 | { |
3493 | int id; | |
3494 | struct wpa_ssid *ssid; | |
3495 | ||
3496 | id = atoi(cmd); | |
3497 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
3498 | if (ssid == NULL || ssid->disabled != 2) { | |
3499 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
3500 | "for persistent P2P group", | |
3501 | id); | |
3502 | return -1; | |
3503 | } | |
3504 | ||
7aeac985 | 3505 | return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, ht40); |
b563b388 JM |
3506 | } |
3507 | ||
3508 | ||
3509 | static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) | |
3510 | { | |
7aeac985 | 3511 | int freq = 0, ht40; |
b563b388 JM |
3512 | char *pos; |
3513 | ||
3514 | pos = os_strstr(cmd, "freq="); | |
3515 | if (pos) | |
3516 | freq = atoi(pos + 5); | |
3517 | ||
7aeac985 RM |
3518 | ht40 = os_strstr(cmd, "ht40") != NULL; |
3519 | ||
b563b388 | 3520 | if (os_strncmp(cmd, "persistent=", 11) == 0) |
7aeac985 RM |
3521 | return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq, |
3522 | ht40); | |
b563b388 JM |
3523 | if (os_strcmp(cmd, "persistent") == 0 || |
3524 | os_strncmp(cmd, "persistent ", 11) == 0) | |
7aeac985 | 3525 | return wpas_p2p_group_add(wpa_s, 1, freq, ht40); |
b563b388 | 3526 | if (os_strncmp(cmd, "freq=", 5) == 0) |
7aeac985 RM |
3527 | return wpas_p2p_group_add(wpa_s, 0, freq, ht40); |
3528 | if (ht40) | |
3529 | return wpas_p2p_group_add(wpa_s, 0, freq, ht40); | |
b563b388 JM |
3530 | |
3531 | wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'", | |
3532 | cmd); | |
3533 | return -1; | |
3534 | } | |
3535 | ||
3536 | ||
3537 | static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd, | |
3538 | char *buf, size_t buflen) | |
3539 | { | |
3540 | u8 addr[ETH_ALEN], *addr_ptr; | |
b3ffc80b JM |
3541 | int next, res; |
3542 | const struct p2p_peer_info *info; | |
3543 | char *pos, *end; | |
3544 | char devtype[WPS_DEV_TYPE_BUFSIZE]; | |
87f841a1 | 3545 | struct wpa_ssid *ssid; |
b563b388 JM |
3546 | |
3547 | if (!wpa_s->global->p2p) | |
3548 | return -1; | |
3549 | ||
3550 | if (os_strcmp(cmd, "FIRST") == 0) { | |
3551 | addr_ptr = NULL; | |
3552 | next = 0; | |
3553 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | |
3554 | if (hwaddr_aton(cmd + 5, addr) < 0) | |
3555 | return -1; | |
3556 | addr_ptr = addr; | |
3557 | next = 1; | |
3558 | } else { | |
3559 | if (hwaddr_aton(cmd, addr) < 0) | |
3560 | return -1; | |
3561 | addr_ptr = addr; | |
3562 | next = 0; | |
3563 | } | |
3564 | ||
b3ffc80b JM |
3565 | info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next); |
3566 | if (info == NULL) | |
3567 | return -1; | |
3568 | ||
3569 | pos = buf; | |
3570 | end = buf + buflen; | |
3571 | ||
3572 | res = os_snprintf(pos, end - pos, MACSTR "\n" | |
3573 | "pri_dev_type=%s\n" | |
3574 | "device_name=%s\n" | |
3575 | "manufacturer=%s\n" | |
3576 | "model_name=%s\n" | |
3577 | "model_number=%s\n" | |
3578 | "serial_number=%s\n" | |
3579 | "config_methods=0x%x\n" | |
3580 | "dev_capab=0x%x\n" | |
3581 | "group_capab=0x%x\n" | |
3582 | "level=%d\n", | |
3583 | MAC2STR(info->p2p_device_addr), | |
3584 | wps_dev_type_bin2str(info->pri_dev_type, | |
3585 | devtype, sizeof(devtype)), | |
3586 | info->device_name, | |
3587 | info->manufacturer, | |
3588 | info->model_name, | |
3589 | info->model_number, | |
3590 | info->serial_number, | |
3591 | info->config_methods, | |
3592 | info->dev_capab, | |
3593 | info->group_capab, | |
3594 | info->level); | |
3595 | if (res < 0 || res >= end - pos) | |
3596 | return pos - buf; | |
3597 | pos += res; | |
3598 | ||
c427ac92 | 3599 | ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0); |
87f841a1 JM |
3600 | if (ssid) { |
3601 | res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id); | |
3602 | if (res < 0 || res >= end - pos) | |
3603 | return pos - buf; | |
3604 | pos += res; | |
3605 | } | |
3606 | ||
b3ffc80b JM |
3607 | res = p2p_get_peer_info_txt(info, pos, end - pos); |
3608 | if (res < 0) | |
87f841a1 | 3609 | return pos - buf; |
b3ffc80b JM |
3610 | pos += res; |
3611 | ||
3612 | return pos - buf; | |
b563b388 JM |
3613 | } |
3614 | ||
3615 | ||
6f3bc72b JM |
3616 | static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s, |
3617 | const char *param) | |
3618 | { | |
3619 | struct wpa_freq_range *freq = NULL, *n; | |
3620 | unsigned int count = 0, i; | |
3621 | const char *pos, *pos2, *pos3; | |
3622 | ||
3623 | if (wpa_s->global->p2p == NULL) | |
3624 | return -1; | |
3625 | ||
3626 | /* | |
3627 | * param includes comma separated frequency range. | |
3628 | * For example: 2412-2432,2462,5000-6000 | |
3629 | */ | |
3630 | pos = param; | |
3631 | while (pos && pos[0]) { | |
067ffa26 JM |
3632 | n = os_realloc_array(freq, count + 1, |
3633 | sizeof(struct wpa_freq_range)); | |
6f3bc72b JM |
3634 | if (n == NULL) { |
3635 | os_free(freq); | |
3636 | return -1; | |
3637 | } | |
3638 | freq = n; | |
3639 | freq[count].min = atoi(pos); | |
3640 | pos2 = os_strchr(pos, '-'); | |
3641 | pos3 = os_strchr(pos, ','); | |
3642 | if (pos2 && (!pos3 || pos2 < pos3)) { | |
3643 | pos2++; | |
3644 | freq[count].max = atoi(pos2); | |
3645 | } else | |
3646 | freq[count].max = freq[count].min; | |
3647 | pos = pos3; | |
3648 | if (pos) | |
3649 | pos++; | |
3650 | count++; | |
3651 | } | |
3652 | ||
3653 | for (i = 0; i < count; i++) { | |
3654 | wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u", | |
3655 | freq[i].min, freq[i].max); | |
3656 | } | |
3657 | ||
3658 | os_free(wpa_s->global->p2p_disallow_freq); | |
3659 | wpa_s->global->p2p_disallow_freq = freq; | |
3660 | wpa_s->global->num_p2p_disallow_freq = count; | |
3661 | wpas_p2p_update_channel_list(wpa_s); | |
3662 | return 0; | |
3663 | } | |
3664 | ||
3665 | ||
b563b388 JM |
3666 | static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) |
3667 | { | |
3668 | char *param; | |
3669 | ||
3670 | if (wpa_s->global->p2p == NULL) | |
3671 | return -1; | |
3672 | ||
3673 | param = os_strchr(cmd, ' '); | |
3674 | if (param == NULL) | |
3675 | return -1; | |
3676 | *param++ = '\0'; | |
3677 | ||
3678 | if (os_strcmp(cmd, "discoverability") == 0) { | |
3679 | p2p_set_client_discoverability(wpa_s->global->p2p, | |
3680 | atoi(param)); | |
3681 | return 0; | |
3682 | } | |
3683 | ||
3684 | if (os_strcmp(cmd, "managed") == 0) { | |
3685 | p2p_set_managed_oper(wpa_s->global->p2p, atoi(param)); | |
3686 | return 0; | |
3687 | } | |
3688 | ||
3689 | if (os_strcmp(cmd, "listen_channel") == 0) { | |
3690 | return p2p_set_listen_channel(wpa_s->global->p2p, 81, | |
3691 | atoi(param)); | |
3692 | } | |
3693 | ||
3694 | if (os_strcmp(cmd, "ssid_postfix") == 0) { | |
3695 | return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param, | |
3696 | os_strlen(param)); | |
3697 | } | |
3698 | ||
3699 | if (os_strcmp(cmd, "noa") == 0) { | |
3700 | char *pos; | |
3701 | int count, start, duration; | |
3702 | /* GO NoA parameters: count,start_offset(ms),duration(ms) */ | |
3703 | count = atoi(param); | |
3704 | pos = os_strchr(param, ','); | |
3705 | if (pos == NULL) | |
3706 | return -1; | |
3707 | pos++; | |
3708 | start = atoi(pos); | |
3709 | pos = os_strchr(pos, ','); | |
3710 | if (pos == NULL) | |
3711 | return -1; | |
3712 | pos++; | |
3713 | duration = atoi(pos); | |
3714 | if (count < 0 || count > 255 || start < 0 || duration < 0) | |
3715 | return -1; | |
3716 | if (count == 0 && duration > 0) | |
3717 | return -1; | |
3718 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d " | |
3719 | "start=%d duration=%d", count, start, duration); | |
aefb53bd | 3720 | return wpas_p2p_set_noa(wpa_s, count, start, duration); |
b563b388 JM |
3721 | } |
3722 | ||
c381508d JM |
3723 | if (os_strcmp(cmd, "ps") == 0) |
3724 | return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1); | |
3725 | ||
3726 | if (os_strcmp(cmd, "oppps") == 0) | |
3727 | return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1); | |
3728 | ||
3729 | if (os_strcmp(cmd, "ctwindow") == 0) | |
3730 | return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param)); | |
3731 | ||
b563b388 JM |
3732 | if (os_strcmp(cmd, "disabled") == 0) { |
3733 | wpa_s->global->p2p_disabled = atoi(param); | |
3734 | wpa_printf(MSG_DEBUG, "P2P functionality %s", | |
3735 | wpa_s->global->p2p_disabled ? | |
3736 | "disabled" : "enabled"); | |
3737 | if (wpa_s->global->p2p_disabled) { | |
3738 | wpas_p2p_stop_find(wpa_s); | |
108def93 | 3739 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
b563b388 JM |
3740 | p2p_flush(wpa_s->global->p2p); |
3741 | } | |
3742 | return 0; | |
3743 | } | |
3744 | ||
b9cfc09a JJ |
3745 | if (os_strcmp(cmd, "conc_pref") == 0) { |
3746 | if (os_strcmp(param, "sta") == 0) | |
3747 | wpa_s->global->conc_pref = WPA_CONC_PREF_STA; | |
3748 | else if (os_strcmp(param, "p2p") == 0) | |
3749 | wpa_s->global->conc_pref = WPA_CONC_PREF_P2P; | |
3750 | else { | |
3751 | wpa_printf(MSG_INFO, "Invalid conc_pref value"); | |
3752 | return -1; | |
3753 | } | |
3754 | wpa_printf(MSG_DEBUG, "Single channel concurrency preference: " | |
3755 | "%s", param); | |
3756 | return 0; | |
3757 | } | |
3758 | ||
6e6963ea JM |
3759 | if (os_strcmp(cmd, "force_long_sd") == 0) { |
3760 | wpa_s->force_long_sd = atoi(param); | |
3761 | return 0; | |
3762 | } | |
3763 | ||
80c9582a JM |
3764 | if (os_strcmp(cmd, "peer_filter") == 0) { |
3765 | u8 addr[ETH_ALEN]; | |
3766 | if (hwaddr_aton(param, addr)) | |
3767 | return -1; | |
3768 | p2p_set_peer_filter(wpa_s->global->p2p, addr); | |
3769 | return 0; | |
3770 | } | |
3771 | ||
72044390 JM |
3772 | if (os_strcmp(cmd, "cross_connect") == 0) |
3773 | return wpas_p2p_set_cross_connect(wpa_s, atoi(param)); | |
3774 | ||
eea2fd9e JM |
3775 | if (os_strcmp(cmd, "go_apsd") == 0) { |
3776 | if (os_strcmp(param, "disable") == 0) | |
3777 | wpa_s->set_ap_uapsd = 0; | |
3778 | else { | |
3779 | wpa_s->set_ap_uapsd = 1; | |
3780 | wpa_s->ap_uapsd = atoi(param); | |
3781 | } | |
3782 | return 0; | |
3783 | } | |
3784 | ||
3785 | if (os_strcmp(cmd, "client_apsd") == 0) { | |
3786 | if (os_strcmp(param, "disable") == 0) | |
3787 | wpa_s->set_sta_uapsd = 0; | |
3788 | else { | |
3789 | int be, bk, vi, vo; | |
3790 | char *pos; | |
3791 | /* format: BE,BK,VI,VO;max SP Length */ | |
3792 | be = atoi(param); | |
3793 | pos = os_strchr(param, ','); | |
3794 | if (pos == NULL) | |
3795 | return -1; | |
3796 | pos++; | |
3797 | bk = atoi(pos); | |
3798 | pos = os_strchr(pos, ','); | |
3799 | if (pos == NULL) | |
3800 | return -1; | |
3801 | pos++; | |
3802 | vi = atoi(pos); | |
3803 | pos = os_strchr(pos, ','); | |
3804 | if (pos == NULL) | |
3805 | return -1; | |
3806 | pos++; | |
3807 | vo = atoi(pos); | |
3808 | /* ignore max SP Length for now */ | |
3809 | ||
3810 | wpa_s->set_sta_uapsd = 1; | |
3811 | wpa_s->sta_uapsd = 0; | |
3812 | if (be) | |
3813 | wpa_s->sta_uapsd |= BIT(0); | |
3814 | if (bk) | |
3815 | wpa_s->sta_uapsd |= BIT(1); | |
3816 | if (vi) | |
3817 | wpa_s->sta_uapsd |= BIT(2); | |
3818 | if (vo) | |
3819 | wpa_s->sta_uapsd |= BIT(3); | |
3820 | } | |
3821 | return 0; | |
3822 | } | |
3823 | ||
6f3bc72b JM |
3824 | if (os_strcmp(cmd, "disallow_freq") == 0) |
3825 | return p2p_ctrl_disallow_freq(wpa_s, param); | |
3826 | ||
b563b388 JM |
3827 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", |
3828 | cmd); | |
3829 | ||
3830 | return -1; | |
3831 | } | |
3832 | ||
3833 | ||
3834 | static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd) | |
3835 | { | |
3836 | char *pos, *pos2; | |
3837 | unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0; | |
3838 | ||
3839 | if (cmd[0]) { | |
3840 | pos = os_strchr(cmd, ' '); | |
3841 | if (pos == NULL) | |
3842 | return -1; | |
3843 | *pos++ = '\0'; | |
3844 | dur1 = atoi(cmd); | |
3845 | ||
3846 | pos2 = os_strchr(pos, ' '); | |
3847 | if (pos2) | |
3848 | *pos2++ = '\0'; | |
3849 | int1 = atoi(pos); | |
3850 | } else | |
3851 | pos2 = NULL; | |
3852 | ||
3853 | if (pos2) { | |
3854 | pos = os_strchr(pos2, ' '); | |
3855 | if (pos == NULL) | |
3856 | return -1; | |
3857 | *pos++ = '\0'; | |
3858 | dur2 = atoi(pos2); | |
3859 | int2 = atoi(pos); | |
3860 | } | |
3861 | ||
3862 | return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2); | |
3863 | } | |
3864 | ||
3865 | ||
3866 | static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) | |
3867 | { | |
3868 | char *pos; | |
3869 | unsigned int period = 0, interval = 0; | |
3870 | ||
3871 | if (cmd[0]) { | |
3872 | pos = os_strchr(cmd, ' '); | |
3873 | if (pos == NULL) | |
3874 | return -1; | |
3875 | *pos++ = '\0'; | |
3876 | period = atoi(cmd); | |
3877 | interval = atoi(pos); | |
3878 | } | |
3879 | ||
3880 | return wpas_p2p_ext_listen(wpa_s, period, interval); | |
3881 | } | |
3882 | ||
3883 | #endif /* CONFIG_P2P */ | |
3884 | ||
3885 | ||
afc064fe | 3886 | #ifdef CONFIG_INTERWORKING |
b02fe7ff JM |
3887 | static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst) |
3888 | { | |
3889 | u8 bssid[ETH_ALEN]; | |
3890 | struct wpa_bss *bss; | |
3891 | ||
3892 | if (hwaddr_aton(dst, bssid)) { | |
3893 | wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst); | |
3894 | return -1; | |
3895 | } | |
3896 | ||
3897 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
3898 | if (bss == NULL) { | |
3899 | wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR, | |
3900 | MAC2STR(bssid)); | |
3901 | return -1; | |
3902 | } | |
3903 | ||
3904 | return interworking_connect(wpa_s, bss); | |
3905 | } | |
3906 | ||
3907 | ||
afc064fe JM |
3908 | static int get_anqp(struct wpa_supplicant *wpa_s, char *dst) |
3909 | { | |
3910 | u8 dst_addr[ETH_ALEN]; | |
3911 | int used; | |
3912 | char *pos; | |
3913 | #define MAX_ANQP_INFO_ID 100 | |
3914 | u16 id[MAX_ANQP_INFO_ID]; | |
3915 | size_t num_id = 0; | |
3916 | ||
3917 | used = hwaddr_aton2(dst, dst_addr); | |
3918 | if (used < 0) | |
3919 | return -1; | |
3920 | pos = dst + used; | |
3921 | while (num_id < MAX_ANQP_INFO_ID) { | |
3922 | id[num_id] = atoi(pos); | |
3923 | if (id[num_id]) | |
3924 | num_id++; | |
3925 | pos = os_strchr(pos + 1, ','); | |
3926 | if (pos == NULL) | |
3927 | break; | |
3928 | pos++; | |
3929 | } | |
3930 | ||
3931 | if (num_id == 0) | |
3932 | return -1; | |
3933 | ||
3934 | return anqp_send_req(wpa_s, dst_addr, id, num_id); | |
3935 | } | |
3936 | #endif /* CONFIG_INTERWORKING */ | |
3937 | ||
3938 | ||
a8918e86 JK |
3939 | #ifdef CONFIG_HS20 |
3940 | ||
3941 | static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst) | |
3942 | { | |
3943 | u8 dst_addr[ETH_ALEN]; | |
3944 | int used; | |
3945 | char *pos; | |
3946 | u32 subtypes = 0; | |
3947 | ||
3948 | used = hwaddr_aton2(dst, dst_addr); | |
3949 | if (used < 0) | |
3950 | return -1; | |
3951 | pos = dst + used; | |
3952 | for (;;) { | |
3953 | int num = atoi(pos); | |
3954 | if (num <= 0 || num > 31) | |
3955 | return -1; | |
3956 | subtypes |= BIT(num); | |
3957 | pos = os_strchr(pos + 1, ','); | |
3958 | if (pos == NULL) | |
3959 | break; | |
3960 | pos++; | |
3961 | } | |
3962 | ||
3963 | if (subtypes == 0) | |
3964 | return -1; | |
3965 | ||
3966 | return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0); | |
3967 | } | |
3968 | ||
3969 | ||
3970 | static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s, | |
3971 | const u8 *addr, const char *realm) | |
3972 | { | |
3973 | u8 *buf; | |
3974 | size_t rlen, len; | |
3975 | int ret; | |
3976 | ||
3977 | rlen = os_strlen(realm); | |
3978 | len = 3 + rlen; | |
3979 | buf = os_malloc(len); | |
3980 | if (buf == NULL) | |
3981 | return -1; | |
3982 | buf[0] = 1; /* NAI Home Realm Count */ | |
3983 | buf[1] = 0; /* Formatted in accordance with RFC 4282 */ | |
3984 | buf[2] = rlen; | |
3985 | os_memcpy(buf + 3, realm, rlen); | |
3986 | ||
3987 | ret = hs20_anqp_send_req(wpa_s, addr, | |
3988 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | |
3989 | buf, len); | |
3990 | ||
3991 | os_free(buf); | |
3992 | ||
3993 | return ret; | |
3994 | } | |
3995 | ||
3996 | ||
3997 | static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s, | |
3998 | char *dst) | |
3999 | { | |
4000 | struct wpa_cred *cred = wpa_s->conf->cred; | |
4001 | u8 dst_addr[ETH_ALEN]; | |
4002 | int used; | |
4003 | u8 *buf; | |
4004 | size_t len; | |
4005 | int ret; | |
4006 | ||
4007 | used = hwaddr_aton2(dst, dst_addr); | |
4008 | if (used < 0) | |
4009 | return -1; | |
4010 | ||
4011 | while (dst[used] == ' ') | |
4012 | used++; | |
4013 | if (os_strncmp(dst + used, "realm=", 6) == 0) | |
4014 | return hs20_nai_home_realm_list(wpa_s, dst_addr, | |
4015 | dst + used + 6); | |
4016 | ||
4017 | len = os_strlen(dst + used); | |
4018 | ||
4019 | if (len == 0 && cred && cred->realm) | |
4020 | return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm); | |
4021 | ||
4022 | if (len % 1) | |
4023 | return -1; | |
4024 | len /= 2; | |
4025 | buf = os_malloc(len); | |
4026 | if (buf == NULL) | |
4027 | return -1; | |
4028 | if (hexstr2bin(dst + used, buf, len) < 0) { | |
4029 | os_free(buf); | |
4030 | return -1; | |
4031 | } | |
4032 | ||
4033 | ret = hs20_anqp_send_req(wpa_s, dst_addr, | |
4034 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | |
4035 | buf, len); | |
4036 | os_free(buf); | |
4037 | ||
4038 | return ret; | |
4039 | } | |
4040 | ||
4041 | #endif /* CONFIG_HS20 */ | |
4042 | ||
4043 | ||
0d0a8ca1 AC |
4044 | static int wpa_supplicant_ctrl_iface_sta_autoconnect( |
4045 | struct wpa_supplicant *wpa_s, char *cmd) | |
4046 | { | |
4047 | wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0; | |
4048 | return 0; | |
4049 | } | |
4050 | ||
4051 | ||
bc5d330a TB |
4052 | #ifdef CONFIG_AUTOSCAN |
4053 | ||
4054 | static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s, | |
4055 | char *cmd) | |
4056 | { | |
4057 | enum wpa_states state = wpa_s->wpa_state; | |
4058 | char *new_params = NULL; | |
4059 | ||
4060 | if (os_strlen(cmd) > 0) { | |
4061 | new_params = os_strdup(cmd); | |
4062 | if (new_params == NULL) | |
4063 | return -1; | |
4064 | } | |
4065 | ||
4066 | os_free(wpa_s->conf->autoscan); | |
4067 | wpa_s->conf->autoscan = new_params; | |
4068 | ||
4069 | if (wpa_s->conf->autoscan == NULL) | |
4070 | autoscan_deinit(wpa_s); | |
4071 | else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) | |
99218999 | 4072 | autoscan_init(wpa_s, 1); |
99f00324 JM |
4073 | else if (state == WPA_SCANNING) |
4074 | wpa_supplicant_reinit_autoscan(wpa_s); | |
bc5d330a TB |
4075 | |
4076 | return 0; | |
4077 | } | |
4078 | ||
4079 | #endif /* CONFIG_AUTOSCAN */ | |
4080 | ||
4081 | ||
60b24b0d DS |
4082 | static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, |
4083 | size_t buflen) | |
4084 | { | |
4085 | struct wpa_signal_info si; | |
4086 | int ret; | |
4087 | ||
4088 | ret = wpa_drv_signal_poll(wpa_s, &si); | |
4089 | if (ret) | |
4090 | return -1; | |
4091 | ||
4092 | ret = os_snprintf(buf, buflen, "RSSI=%d\nLINKSPEED=%d\n" | |
4093 | "NOISE=%d\nFREQUENCY=%u\n", | |
4094 | si.current_signal, si.current_txrate / 1000, | |
4095 | si.current_noise, si.frequency); | |
4096 | if (ret < 0 || (unsigned int) ret > buflen) | |
4097 | return -1; | |
4098 | return ret; | |
4099 | } | |
4100 | ||
4101 | ||
6fc6879b JM |
4102 | char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, |
4103 | char *buf, size_t *resp_len) | |
4104 | { | |
4105 | char *reply; | |
b563b388 | 4106 | const int reply_size = 4096; |
6fc6879b JM |
4107 | int ctrl_rsp = 0; |
4108 | int reply_len; | |
4109 | ||
4110 | if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 || | |
4111 | os_strncmp(buf, "SET_NETWORK ", 12) == 0) { | |
4112 | wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", | |
4113 | (const u8 *) buf, os_strlen(buf)); | |
4114 | } else { | |
235f69fc JM |
4115 | int level = MSG_DEBUG; |
4116 | if (os_strcmp(buf, "PING") == 0) | |
4117 | level = MSG_EXCESSIVE; | |
4118 | wpa_hexdump_ascii(level, "RX ctrl_iface", | |
6fc6879b JM |
4119 | (const u8 *) buf, os_strlen(buf)); |
4120 | } | |
4121 | ||
4122 | reply = os_malloc(reply_size); | |
4123 | if (reply == NULL) { | |
4124 | *resp_len = 1; | |
4125 | return NULL; | |
4126 | } | |
4127 | ||
4128 | os_memcpy(reply, "OK\n", 3); | |
4129 | reply_len = 3; | |
4130 | ||
4131 | if (os_strcmp(buf, "PING") == 0) { | |
4132 | os_memcpy(reply, "PONG\n", 5); | |
4133 | reply_len = 5; | |
0eed2a8d JD |
4134 | } else if (os_strcmp(buf, "IFNAME") == 0) { |
4135 | reply_len = os_strlen(wpa_s->ifname); | |
4136 | os_memcpy(reply, wpa_s->ifname, reply_len); | |
ac6912b5 BG |
4137 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
4138 | if (wpa_debug_reopen_file() < 0) | |
4139 | reply_len = -1; | |
77895cd9 JM |
4140 | } else if (os_strncmp(buf, "NOTE ", 5) == 0) { |
4141 | wpa_printf(MSG_INFO, "NOTE: %s", buf + 5); | |
6fc6879b JM |
4142 | } else if (os_strcmp(buf, "MIB") == 0) { |
4143 | reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); | |
4144 | if (reply_len >= 0) { | |
4145 | int res; | |
4146 | res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len, | |
4147 | reply_size - reply_len); | |
4148 | if (res < 0) | |
4149 | reply_len = -1; | |
4150 | else | |
4151 | reply_len += res; | |
4152 | } | |
4153 | } else if (os_strncmp(buf, "STATUS", 6) == 0) { | |
4154 | reply_len = wpa_supplicant_ctrl_iface_status( | |
4155 | wpa_s, buf + 6, reply, reply_size); | |
4156 | } else if (os_strcmp(buf, "PMKSA") == 0) { | |
540264a7 JM |
4157 | reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply, |
4158 | reply_size); | |
6fc6879b JM |
4159 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
4160 | if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) | |
4161 | reply_len = -1; | |
acec8d32 JM |
4162 | } else if (os_strncmp(buf, "GET ", 4) == 0) { |
4163 | reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4, | |
4164 | reply, reply_size); | |
6fc6879b JM |
4165 | } else if (os_strcmp(buf, "LOGON") == 0) { |
4166 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); | |
4167 | } else if (os_strcmp(buf, "LOGOFF") == 0) { | |
4168 | eapol_sm_notify_logoff(wpa_s->eapol, TRUE); | |
4169 | } else if (os_strcmp(buf, "REASSOCIATE") == 0) { | |
0b7a25c0 | 4170 | wpa_s->normal_scans = 0; |
c3d12238 | 4171 | wpa_supplicant_reinit_autoscan(wpa_s); |
8401a6b0 JM |
4172 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
4173 | reply_len = -1; | |
4174 | else { | |
4175 | wpa_s->disconnected = 0; | |
4176 | wpa_s->reassociate = 1; | |
4177 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
4178 | } | |
6fc6879b | 4179 | } else if (os_strcmp(buf, "RECONNECT") == 0) { |
0b7a25c0 | 4180 | wpa_s->normal_scans = 0; |
c3d12238 | 4181 | wpa_supplicant_reinit_autoscan(wpa_s); |
8401a6b0 JM |
4182 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
4183 | reply_len = -1; | |
4184 | else if (wpa_s->disconnected) { | |
6fc6879b JM |
4185 | wpa_s->disconnected = 0; |
4186 | wpa_s->reassociate = 1; | |
4187 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
4188 | } | |
ec717917 | 4189 | #ifdef IEEE8021X_EAPOL |
6fc6879b JM |
4190 | } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { |
4191 | if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) | |
4192 | reply_len = -1; | |
ec717917 | 4193 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
4194 | #ifdef CONFIG_PEERKEY |
4195 | } else if (os_strncmp(buf, "STKSTART ", 9) == 0) { | |
4196 | if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9)) | |
4197 | reply_len = -1; | |
4198 | #endif /* CONFIG_PEERKEY */ | |
4199 | #ifdef CONFIG_IEEE80211R | |
4200 | } else if (os_strncmp(buf, "FT_DS ", 6) == 0) { | |
4201 | if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6)) | |
4202 | reply_len = -1; | |
4203 | #endif /* CONFIG_IEEE80211R */ | |
fcc60db4 JM |
4204 | #ifdef CONFIG_WPS |
4205 | } else if (os_strcmp(buf, "WPS_PBC") == 0) { | |
3152ff42 CWY |
4206 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL); |
4207 | if (res == -2) { | |
4208 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
4209 | reply_len = 17; | |
4210 | } else if (res) | |
fcc60db4 JM |
4211 | reply_len = -1; |
4212 | } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) { | |
3152ff42 CWY |
4213 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8); |
4214 | if (res == -2) { | |
4215 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
4216 | reply_len = 17; | |
4217 | } else if (res) | |
fcc60db4 JM |
4218 | reply_len = -1; |
4219 | } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) { | |
4220 | reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8, | |
4221 | reply, | |
4222 | reply_size); | |
3981cb3c JM |
4223 | } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) { |
4224 | reply_len = wpa_supplicant_ctrl_iface_wps_check_pin( | |
4225 | wpa_s, buf + 14, reply, reply_size); | |
2f9929ff AC |
4226 | } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { |
4227 | if (wpas_wps_cancel(wpa_s)) | |
4228 | reply_len = -1; | |
116f7bb0 | 4229 | #ifdef CONFIG_WPS_OOB |
46bdb83a MH |
4230 | } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) { |
4231 | if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8)) | |
4232 | reply_len = -1; | |
71892384 JM |
4233 | #endif /* CONFIG_WPS_OOB */ |
4234 | #ifdef CONFIG_WPS_NFC | |
3f2c8ba6 JM |
4235 | } else if (os_strcmp(buf, "WPS_NFC") == 0) { |
4236 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL)) | |
4237 | reply_len = -1; | |
4238 | } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) { | |
4239 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8)) | |
4240 | reply_len = -1; | |
4241 | } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) { | |
4242 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token( | |
4243 | wpa_s, buf + 14, reply, reply_size); | |
d7645d23 JM |
4244 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) { |
4245 | if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s, | |
4246 | buf + 17)) | |
4247 | reply_len = -1; | |
71892384 | 4248 | #endif /* CONFIG_WPS_NFC */ |
fcc60db4 JM |
4249 | } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) { |
4250 | if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8)) | |
4251 | reply_len = -1; | |
70d84f11 JM |
4252 | #ifdef CONFIG_AP |
4253 | } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) { | |
4254 | reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin( | |
4255 | wpa_s, buf + 11, reply, reply_size); | |
4256 | #endif /* CONFIG_AP */ | |
72df2f5f | 4257 | #ifdef CONFIG_WPS_ER |
e9bcfebf | 4258 | } else if (os_strcmp(buf, "WPS_ER_START") == 0) { |
08486685 JM |
4259 | if (wpas_wps_er_start(wpa_s, NULL)) |
4260 | reply_len = -1; | |
4261 | } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) { | |
4262 | if (wpas_wps_er_start(wpa_s, buf + 13)) | |
e9bcfebf JM |
4263 | reply_len = -1; |
4264 | } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) { | |
4265 | if (wpas_wps_er_stop(wpa_s)) | |
4266 | reply_len = -1; | |
72df2f5f JM |
4267 | } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) { |
4268 | if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11)) | |
4269 | reply_len = -1; | |
564cd7fa | 4270 | } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) { |
ed159ad4 JM |
4271 | int ret = wpas_wps_er_pbc(wpa_s, buf + 11); |
4272 | if (ret == -2) { | |
4273 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
4274 | reply_len = 17; | |
4275 | } else if (ret == -3) { | |
4276 | os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18); | |
4277 | reply_len = 18; | |
4278 | } else if (ret == -4) { | |
4279 | os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20); | |
4280 | reply_len = 20; | |
4281 | } else if (ret) | |
564cd7fa | 4282 | reply_len = -1; |
e64dcfd5 JM |
4283 | } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) { |
4284 | if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13)) | |
4285 | reply_len = -1; | |
ef10f473 JM |
4286 | } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) { |
4287 | if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s, | |
4288 | buf + 18)) | |
4289 | reply_len = -1; | |
7d6640a6 JM |
4290 | } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) { |
4291 | if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14)) | |
4292 | reply_len = -1; | |
1cea09a9 JM |
4293 | #ifdef CONFIG_WPS_NFC |
4294 | } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) { | |
4295 | reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | |
4296 | wpa_s, buf + 24, reply, reply_size); | |
4297 | #endif /* CONFIG_WPS_NFC */ | |
72df2f5f | 4298 | #endif /* CONFIG_WPS_ER */ |
fcc60db4 | 4299 | #endif /* CONFIG_WPS */ |
11ef8d35 JM |
4300 | #ifdef CONFIG_IBSS_RSN |
4301 | } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) { | |
4302 | if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) | |
4303 | reply_len = -1; | |
4304 | #endif /* CONFIG_IBSS_RSN */ | |
b563b388 JM |
4305 | #ifdef CONFIG_P2P |
4306 | } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { | |
4307 | if (p2p_ctrl_find(wpa_s, buf + 9)) | |
4308 | reply_len = -1; | |
4309 | } else if (os_strcmp(buf, "P2P_FIND") == 0) { | |
4310 | if (p2p_ctrl_find(wpa_s, "")) | |
4311 | reply_len = -1; | |
4312 | } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) { | |
4313 | wpas_p2p_stop_find(wpa_s); | |
4314 | } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) { | |
4315 | reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply, | |
4316 | reply_size); | |
4317 | } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) { | |
4318 | if (p2p_ctrl_listen(wpa_s, buf + 11)) | |
4319 | reply_len = -1; | |
4320 | } else if (os_strcmp(buf, "P2P_LISTEN") == 0) { | |
4321 | if (p2p_ctrl_listen(wpa_s, "")) | |
4322 | reply_len = -1; | |
4323 | } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) { | |
4324 | if (wpas_p2p_group_remove(wpa_s, buf + 17)) | |
4325 | reply_len = -1; | |
4326 | } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) { | |
7aeac985 | 4327 | if (wpas_p2p_group_add(wpa_s, 0, 0, 0)) |
b563b388 JM |
4328 | reply_len = -1; |
4329 | } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) { | |
4330 | if (p2p_ctrl_group_add(wpa_s, buf + 14)) | |
4331 | reply_len = -1; | |
4332 | } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) { | |
4333 | if (p2p_ctrl_prov_disc(wpa_s, buf + 14)) | |
4334 | reply_len = -1; | |
4335 | } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) { | |
4336 | reply_len = p2p_get_passphrase(wpa_s, reply, reply_size); | |
4337 | } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) { | |
4338 | reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply, | |
4339 | reply_size); | |
4340 | } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) { | |
4341 | if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0) | |
4342 | reply_len = -1; | |
4343 | } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) { | |
4344 | if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0) | |
4345 | reply_len = -1; | |
4346 | } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) { | |
4347 | wpas_p2p_sd_service_update(wpa_s); | |
4348 | } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) { | |
4349 | if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0) | |
4350 | reply_len = -1; | |
4351 | } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) { | |
4352 | wpas_p2p_service_flush(wpa_s); | |
4353 | } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) { | |
4354 | if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0) | |
4355 | reply_len = -1; | |
4356 | } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) { | |
4357 | if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0) | |
4358 | reply_len = -1; | |
4359 | } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) { | |
4360 | if (p2p_ctrl_reject(wpa_s, buf + 11) < 0) | |
4361 | reply_len = -1; | |
4362 | } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) { | |
4363 | if (p2p_ctrl_invite(wpa_s, buf + 11) < 0) | |
4364 | reply_len = -1; | |
4365 | } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) { | |
4366 | reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply, | |
4367 | reply_size); | |
4368 | } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) { | |
4369 | if (p2p_ctrl_set(wpa_s, buf + 8) < 0) | |
4370 | reply_len = -1; | |
4371 | } else if (os_strcmp(buf, "P2P_FLUSH") == 0) { | |
108def93 | 4372 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
6e6963ea | 4373 | wpa_s->force_long_sd = 0; |
9526fd29 JM |
4374 | if (wpa_s->global->p2p) |
4375 | p2p_flush(wpa_s->global->p2p); | |
9d562b79 SS |
4376 | } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { |
4377 | if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) | |
4378 | reply_len = -1; | |
59eba7a2 JM |
4379 | } else if (os_strcmp(buf, "P2P_CANCEL") == 0) { |
4380 | if (wpas_p2p_cancel(wpa_s)) | |
4381 | reply_len = -1; | |
b563b388 JM |
4382 | } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) { |
4383 | if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0) | |
4384 | reply_len = -1; | |
4385 | } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) { | |
4386 | if (p2p_ctrl_presence_req(wpa_s, "") < 0) | |
4387 | reply_len = -1; | |
4388 | } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) { | |
4389 | if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0) | |
4390 | reply_len = -1; | |
4391 | } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) { | |
4392 | if (p2p_ctrl_ext_listen(wpa_s, "") < 0) | |
4393 | reply_len = -1; | |
4394 | #endif /* CONFIG_P2P */ | |
afc064fe JM |
4395 | #ifdef CONFIG_INTERWORKING |
4396 | } else if (os_strcmp(buf, "FETCH_ANQP") == 0) { | |
4397 | if (interworking_fetch_anqp(wpa_s) < 0) | |
4398 | reply_len = -1; | |
4399 | } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) { | |
4400 | interworking_stop_fetch_anqp(wpa_s); | |
b02fe7ff JM |
4401 | } else if (os_strncmp(buf, "INTERWORKING_SELECT", 19) == 0) { |
4402 | if (interworking_select(wpa_s, os_strstr(buf + 19, "auto") != | |
4403 | NULL) < 0) | |
4404 | reply_len = -1; | |
4405 | } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) { | |
4406 | if (ctrl_interworking_connect(wpa_s, buf + 21) < 0) | |
4407 | reply_len = -1; | |
afc064fe JM |
4408 | } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) { |
4409 | if (get_anqp(wpa_s, buf + 9) < 0) | |
4410 | reply_len = -1; | |
4411 | #endif /* CONFIG_INTERWORKING */ | |
a8918e86 JK |
4412 | #ifdef CONFIG_HS20 |
4413 | } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) { | |
4414 | if (get_hs20_anqp(wpa_s, buf + 14) < 0) | |
4415 | reply_len = -1; | |
4416 | } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) { | |
4417 | if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0) | |
4418 | reply_len = -1; | |
4419 | #endif /* CONFIG_HS20 */ | |
6fc6879b JM |
4420 | } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) |
4421 | { | |
4422 | if (wpa_supplicant_ctrl_iface_ctrl_rsp( | |
4423 | wpa_s, buf + os_strlen(WPA_CTRL_RSP))) | |
4424 | reply_len = -1; | |
4425 | else | |
4426 | ctrl_rsp = 1; | |
4427 | } else if (os_strcmp(buf, "RECONFIGURE") == 0) { | |
4428 | if (wpa_supplicant_reload_configuration(wpa_s)) | |
4429 | reply_len = -1; | |
4430 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | |
1a1bf008 | 4431 | wpa_supplicant_terminate_proc(wpa_s->global); |
6fc6879b JM |
4432 | } else if (os_strncmp(buf, "BSSID ", 6) == 0) { |
4433 | if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) | |
4434 | reply_len = -1; | |
9aa10e2b DS |
4435 | } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) { |
4436 | reply_len = wpa_supplicant_ctrl_iface_blacklist( | |
4437 | wpa_s, buf + 9, reply, reply_size); | |
0597a5b5 DS |
4438 | } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) { |
4439 | reply_len = wpa_supplicant_ctrl_iface_log_level( | |
4440 | wpa_s, buf + 9, reply, reply_size); | |
6fc6879b JM |
4441 | } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { |
4442 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | |
4443 | wpa_s, reply, reply_size); | |
4444 | } else if (os_strcmp(buf, "DISCONNECT") == 0) { | |
83df8149 JM |
4445 | #ifdef CONFIG_SME |
4446 | wpa_s->sme.prev_bssid_set = 0; | |
4447 | #endif /* CONFIG_SME */ | |
6fc6879b JM |
4448 | wpa_s->reassociate = 0; |
4449 | wpa_s->disconnected = 1; | |
6ad9c911 | 4450 | wpa_supplicant_cancel_sched_scan(wpa_s); |
d7ded758 | 4451 | wpa_supplicant_cancel_scan(wpa_s); |
cf4783e3 JM |
4452 | wpa_supplicant_deauthenticate(wpa_s, |
4453 | WLAN_REASON_DEAUTH_LEAVING); | |
6fc6879b | 4454 | } else if (os_strcmp(buf, "SCAN") == 0) { |
8401a6b0 JM |
4455 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
4456 | reply_len = -1; | |
4457 | else { | |
746bba1a DS |
4458 | if (!wpa_s->scanning && |
4459 | ((wpa_s->wpa_state <= WPA_SCANNING) || | |
4460 | (wpa_s->wpa_state == WPA_COMPLETED))) { | |
564865e1 JM |
4461 | wpa_s->normal_scans = 0; |
4462 | wpa_s->scan_req = 2; | |
4463 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
4464 | } else if (wpa_s->sched_scanning) { | |
4465 | wpa_printf(MSG_DEBUG, "Stop ongoing " | |
4466 | "sched_scan to allow requested " | |
4467 | "full scan to proceed"); | |
4468 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
746bba1a DS |
4469 | wpa_s->scan_req = 2; |
4470 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
4471 | } else { | |
4472 | wpa_printf(MSG_DEBUG, "Ongoing scan action - " | |
4473 | "reject new request"); | |
4474 | reply_len = os_snprintf(reply, reply_size, | |
4475 | "FAIL-BUSY\n"); | |
4476 | } | |
8401a6b0 | 4477 | } |
6fc6879b JM |
4478 | } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { |
4479 | reply_len = wpa_supplicant_ctrl_iface_scan_results( | |
4480 | wpa_s, reply, reply_size); | |
4481 | } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { | |
4482 | if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) | |
4483 | reply_len = -1; | |
4484 | } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { | |
4485 | if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) | |
4486 | reply_len = -1; | |
4487 | } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { | |
4488 | if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) | |
4489 | reply_len = -1; | |
4490 | } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { | |
4491 | reply_len = wpa_supplicant_ctrl_iface_add_network( | |
4492 | wpa_s, reply, reply_size); | |
4493 | } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { | |
4494 | if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) | |
4495 | reply_len = -1; | |
4496 | } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { | |
4497 | if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) | |
4498 | reply_len = -1; | |
4499 | } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { | |
4500 | reply_len = wpa_supplicant_ctrl_iface_get_network( | |
4501 | wpa_s, buf + 12, reply, reply_size); | |
d94c9ee6 JM |
4502 | } else if (os_strcmp(buf, "LIST_CREDS") == 0) { |
4503 | reply_len = wpa_supplicant_ctrl_iface_list_creds( | |
4504 | wpa_s, reply, reply_size); | |
4505 | } else if (os_strcmp(buf, "ADD_CRED") == 0) { | |
4506 | reply_len = wpa_supplicant_ctrl_iface_add_cred( | |
4507 | wpa_s, reply, reply_size); | |
4508 | } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) { | |
4509 | if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12)) | |
4510 | reply_len = -1; | |
4511 | } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) { | |
4512 | if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9)) | |
4513 | reply_len = -1; | |
6fc6879b JM |
4514 | #ifndef CONFIG_NO_CONFIG_WRITE |
4515 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | |
4516 | if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) | |
4517 | reply_len = -1; | |
4518 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
4519 | } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { | |
4520 | reply_len = wpa_supplicant_ctrl_iface_get_capability( | |
4521 | wpa_s, buf + 15, reply, reply_size); | |
4522 | } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { | |
4523 | if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) | |
4524 | reply_len = -1; | |
67b9bd08 DS |
4525 | } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) { |
4526 | if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14)) | |
4527 | reply_len = -1; | |
4b4a8ae5 JM |
4528 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
4529 | reply_len = wpa_supplicant_global_iface_list( | |
4530 | wpa_s->global, reply, reply_size); | |
6fc6879b JM |
4531 | } else if (os_strcmp(buf, "INTERFACES") == 0) { |
4532 | reply_len = wpa_supplicant_global_iface_interfaces( | |
4533 | wpa_s->global, reply, reply_size); | |
4534 | } else if (os_strncmp(buf, "BSS ", 4) == 0) { | |
4535 | reply_len = wpa_supplicant_ctrl_iface_bss( | |
4536 | wpa_s, buf + 4, reply, reply_size); | |
e653b622 JM |
4537 | #ifdef CONFIG_AP |
4538 | } else if (os_strcmp(buf, "STA-FIRST") == 0) { | |
4539 | reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size); | |
4540 | } else if (os_strncmp(buf, "STA ", 4) == 0) { | |
4541 | reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply, | |
4542 | reply_size); | |
4543 | } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { | |
4544 | reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply, | |
4545 | reply_size); | |
e60b2951 JJ |
4546 | } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) { |
4547 | if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15)) | |
4548 | reply_len = -1; | |
4549 | } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) { | |
4550 | if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13)) | |
4551 | reply_len = -1; | |
e653b622 | 4552 | #endif /* CONFIG_AP */ |
207ef3fb JM |
4553 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
4554 | wpas_notify_suspend(wpa_s->global); | |
4555 | } else if (os_strcmp(buf, "RESUME") == 0) { | |
4556 | wpas_notify_resume(wpa_s->global); | |
32d5295f JM |
4557 | } else if (os_strcmp(buf, "DROP_SA") == 0) { |
4558 | wpa_supplicant_ctrl_iface_drop_sa(wpa_s); | |
86d4f806 JM |
4559 | } else if (os_strncmp(buf, "ROAM ", 5) == 0) { |
4560 | if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) | |
4561 | reply_len = -1; | |
0d0a8ca1 AC |
4562 | } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { |
4563 | if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16)) | |
4564 | reply_len = -1; | |
78633c37 SL |
4565 | } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) { |
4566 | if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15)) | |
4567 | reply_len = -1; | |
4568 | } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) { | |
4569 | if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s, | |
4570 | buf + 17)) | |
4571 | reply_len = -1; | |
281ff0aa GP |
4572 | #ifdef CONFIG_TDLS |
4573 | } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) { | |
4574 | if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14)) | |
4575 | reply_len = -1; | |
4576 | } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) { | |
4577 | if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11)) | |
4578 | reply_len = -1; | |
4579 | } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) { | |
4580 | if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14)) | |
4581 | reply_len = -1; | |
4582 | #endif /* CONFIG_TDLS */ | |
60b24b0d DS |
4583 | } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) { |
4584 | reply_len = wpa_supplicant_signal_poll(wpa_s, reply, | |
4585 | reply_size); | |
bc5d330a TB |
4586 | #ifdef CONFIG_AUTOSCAN |
4587 | } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) { | |
4588 | if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9)) | |
4589 | reply_len = -1; | |
4590 | #endif /* CONFIG_AUTOSCAN */ | |
9482426e JM |
4591 | } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) { |
4592 | eapol_sm_request_reauth(wpa_s->eapol); | |
6fc6879b JM |
4593 | } else { |
4594 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | |
4595 | reply_len = 16; | |
4596 | } | |
4597 | ||
4598 | if (reply_len < 0) { | |
4599 | os_memcpy(reply, "FAIL\n", 5); | |
4600 | reply_len = 5; | |
4601 | } | |
4602 | ||
4603 | if (ctrl_rsp) | |
4604 | eapol_sm_notify_ctrl_response(wpa_s->eapol); | |
4605 | ||
4606 | *resp_len = reply_len; | |
4607 | return reply; | |
4608 | } | |
4609 | ||
4610 | ||
4611 | static int wpa_supplicant_global_iface_add(struct wpa_global *global, | |
4612 | char *cmd) | |
4613 | { | |
4614 | struct wpa_interface iface; | |
4615 | char *pos; | |
4616 | ||
4617 | /* | |
4618 | * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param> | |
4619 | * TAB<bridge_ifname> | |
4620 | */ | |
4621 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd); | |
4622 | ||
4623 | os_memset(&iface, 0, sizeof(iface)); | |
4624 | ||
4625 | do { | |
4626 | iface.ifname = pos = cmd; | |
4627 | pos = os_strchr(pos, '\t'); | |
4628 | if (pos) | |
4629 | *pos++ = '\0'; | |
4630 | if (iface.ifname[0] == '\0') | |
4631 | return -1; | |
4632 | if (pos == NULL) | |
4633 | break; | |
4634 | ||
4635 | iface.confname = pos; | |
4636 | pos = os_strchr(pos, '\t'); | |
4637 | if (pos) | |
4638 | *pos++ = '\0'; | |
4639 | if (iface.confname[0] == '\0') | |
4640 | iface.confname = NULL; | |
4641 | if (pos == NULL) | |
4642 | break; | |
4643 | ||
4644 | iface.driver = pos; | |
4645 | pos = os_strchr(pos, '\t'); | |
4646 | if (pos) | |
4647 | *pos++ = '\0'; | |
4648 | if (iface.driver[0] == '\0') | |
4649 | iface.driver = NULL; | |
4650 | if (pos == NULL) | |
4651 | break; | |
4652 | ||
4653 | iface.ctrl_interface = pos; | |
4654 | pos = os_strchr(pos, '\t'); | |
4655 | if (pos) | |
4656 | *pos++ = '\0'; | |
4657 | if (iface.ctrl_interface[0] == '\0') | |
4658 | iface.ctrl_interface = NULL; | |
4659 | if (pos == NULL) | |
4660 | break; | |
4661 | ||
4662 | iface.driver_param = pos; | |
4663 | pos = os_strchr(pos, '\t'); | |
4664 | if (pos) | |
4665 | *pos++ = '\0'; | |
4666 | if (iface.driver_param[0] == '\0') | |
4667 | iface.driver_param = NULL; | |
4668 | if (pos == NULL) | |
4669 | break; | |
4670 | ||
4671 | iface.bridge_ifname = pos; | |
4672 | pos = os_strchr(pos, '\t'); | |
4673 | if (pos) | |
4674 | *pos++ = '\0'; | |
4675 | if (iface.bridge_ifname[0] == '\0') | |
4676 | iface.bridge_ifname = NULL; | |
4677 | if (pos == NULL) | |
4678 | break; | |
4679 | } while (0); | |
4680 | ||
4681 | if (wpa_supplicant_get_iface(global, iface.ifname)) | |
4682 | return -1; | |
4683 | ||
4684 | return wpa_supplicant_add_iface(global, &iface) ? 0 : -1; | |
4685 | } | |
4686 | ||
4687 | ||
4688 | static int wpa_supplicant_global_iface_remove(struct wpa_global *global, | |
4689 | char *cmd) | |
4690 | { | |
4691 | struct wpa_supplicant *wpa_s; | |
4692 | ||
4693 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd); | |
4694 | ||
4695 | wpa_s = wpa_supplicant_get_iface(global, cmd); | |
4696 | if (wpa_s == NULL) | |
4697 | return -1; | |
df509539 | 4698 | return wpa_supplicant_remove_iface(global, wpa_s, 0); |
6fc6879b JM |
4699 | } |
4700 | ||
4701 | ||
4b4a8ae5 JM |
4702 | static void wpa_free_iface_info(struct wpa_interface_info *iface) |
4703 | { | |
4704 | struct wpa_interface_info *prev; | |
4705 | ||
4706 | while (iface) { | |
4707 | prev = iface; | |
4708 | iface = iface->next; | |
4709 | ||
4710 | os_free(prev->ifname); | |
4711 | os_free(prev->desc); | |
4712 | os_free(prev); | |
4713 | } | |
4714 | } | |
4715 | ||
4716 | ||
4717 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, | |
4718 | char *buf, int len) | |
4719 | { | |
4720 | int i, res; | |
4721 | struct wpa_interface_info *iface = NULL, *last = NULL, *tmp; | |
4722 | char *pos, *end; | |
4723 | ||
c5121837 JM |
4724 | for (i = 0; wpa_drivers[i]; i++) { |
4725 | struct wpa_driver_ops *drv = wpa_drivers[i]; | |
4b4a8ae5 JM |
4726 | if (drv->get_interfaces == NULL) |
4727 | continue; | |
5fbc1f27 | 4728 | tmp = drv->get_interfaces(global->drv_priv[i]); |
4b4a8ae5 JM |
4729 | if (tmp == NULL) |
4730 | continue; | |
4731 | ||
4732 | if (last == NULL) | |
4733 | iface = last = tmp; | |
4734 | else | |
4735 | last->next = tmp; | |
4736 | while (last->next) | |
4737 | last = last->next; | |
4738 | } | |
4739 | ||
4740 | pos = buf; | |
4741 | end = buf + len; | |
4742 | for (tmp = iface; tmp; tmp = tmp->next) { | |
4743 | res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n", | |
4744 | tmp->drv_name, tmp->ifname, | |
4745 | tmp->desc ? tmp->desc : ""); | |
4746 | if (res < 0 || res >= end - pos) { | |
4747 | *pos = '\0'; | |
4748 | break; | |
4749 | } | |
4750 | pos += res; | |
4751 | } | |
4752 | ||
4753 | wpa_free_iface_info(iface); | |
4754 | ||
4755 | return pos - buf; | |
4756 | } | |
4757 | ||
4758 | ||
6fc6879b JM |
4759 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
4760 | char *buf, int len) | |
4761 | { | |
4762 | int res; | |
4763 | char *pos, *end; | |
4764 | struct wpa_supplicant *wpa_s; | |
4765 | ||
4766 | wpa_s = global->ifaces; | |
4767 | pos = buf; | |
4768 | end = buf + len; | |
4769 | ||
4770 | while (wpa_s) { | |
4771 | res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname); | |
4772 | if (res < 0 || res >= end - pos) { | |
4773 | *pos = '\0'; | |
4774 | break; | |
4775 | } | |
4776 | pos += res; | |
4777 | wpa_s = wpa_s->next; | |
4778 | } | |
4779 | return pos - buf; | |
4780 | } | |
4781 | ||
4782 | ||
4783 | char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, | |
4784 | char *buf, size_t *resp_len) | |
4785 | { | |
4786 | char *reply; | |
4787 | const int reply_size = 2048; | |
4788 | int reply_len; | |
f4a0a82c | 4789 | int level = MSG_DEBUG; |
6fc6879b | 4790 | |
f4a0a82c JM |
4791 | if (os_strcmp(buf, "PING") == 0) |
4792 | level = MSG_EXCESSIVE; | |
4793 | wpa_hexdump_ascii(level, "RX global ctrl_iface", | |
6fc6879b JM |
4794 | (const u8 *) buf, os_strlen(buf)); |
4795 | ||
4796 | reply = os_malloc(reply_size); | |
4797 | if (reply == NULL) { | |
4798 | *resp_len = 1; | |
4799 | return NULL; | |
4800 | } | |
4801 | ||
4802 | os_memcpy(reply, "OK\n", 3); | |
4803 | reply_len = 3; | |
4804 | ||
4805 | if (os_strcmp(buf, "PING") == 0) { | |
4806 | os_memcpy(reply, "PONG\n", 5); | |
4807 | reply_len = 5; | |
4808 | } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) { | |
4809 | if (wpa_supplicant_global_iface_add(global, buf + 14)) | |
4810 | reply_len = -1; | |
4811 | } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) { | |
4812 | if (wpa_supplicant_global_iface_remove(global, buf + 17)) | |
4813 | reply_len = -1; | |
4b4a8ae5 JM |
4814 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
4815 | reply_len = wpa_supplicant_global_iface_list( | |
4816 | global, reply, reply_size); | |
6fc6879b JM |
4817 | } else if (os_strcmp(buf, "INTERFACES") == 0) { |
4818 | reply_len = wpa_supplicant_global_iface_interfaces( | |
4819 | global, reply, reply_size); | |
4820 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | |
1a1bf008 | 4821 | wpa_supplicant_terminate_proc(global); |
207ef3fb JM |
4822 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
4823 | wpas_notify_suspend(global); | |
4824 | } else if (os_strcmp(buf, "RESUME") == 0) { | |
4825 | wpas_notify_resume(global); | |
6fc6879b JM |
4826 | } else { |
4827 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | |
4828 | reply_len = 16; | |
4829 | } | |
4830 | ||
4831 | if (reply_len < 0) { | |
4832 | os_memcpy(reply, "FAIL\n", 5); | |
4833 | reply_len = 5; | |
4834 | } | |
4835 | ||
4836 | *resp_len = reply_len; | |
4837 | return reply; | |
4838 | } |