]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant / Control interface (shared code for all backends) | |
d31b5ac7 | 3 | * Copyright (c) 2004-2014, 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" |
4a6cc862 JM |
10 | #ifdef CONFIG_TESTING_OPTIONS |
11 | #include <net/ethernet.h> | |
12 | #include <netinet/ip.h> | |
13 | #endif /* CONFIG_TESTING_OPTIONS */ | |
6fc6879b | 14 | |
3a068632 JM |
15 | #include "utils/common.h" |
16 | #include "utils/eloop.h" | |
8aaafcee | 17 | #include "utils/uuid.h" |
acec8d32 | 18 | #include "common/version.h" |
3a068632 | 19 | #include "common/ieee802_11_defs.h" |
337c781f | 20 | #include "common/ieee802_11_common.h" |
3a068632 | 21 | #include "common/wpa_ctrl.h" |
9d4ff04a | 22 | #include "ap/hostapd.h" |
3a068632 JM |
23 | #include "eap_peer/eap.h" |
24 | #include "eapol_supp/eapol_supp_sm.h" | |
3acb5005 | 25 | #include "rsn_supp/wpa.h" |
3a068632 JM |
26 | #include "rsn_supp/preauth.h" |
27 | #include "rsn_supp/pmksa_cache.h" | |
28 | #include "l2_packet/l2_packet.h" | |
29 | #include "wps/wps.h" | |
6fc6879b | 30 | #include "config.h" |
6fc6879b | 31 | #include "wpa_supplicant_i.h" |
2d5b792d | 32 | #include "driver_i.h" |
fcc60db4 | 33 | #include "wps_supplicant.h" |
11ef8d35 | 34 | #include "ibss_rsn.h" |
3ec97afe | 35 | #include "ap.h" |
b563b388 JM |
36 | #include "p2p_supplicant.h" |
37 | #include "p2p/p2p.h" | |
a8918e86 | 38 | #include "hs20_supplicant.h" |
9675ce35 | 39 | #include "wifi_display.h" |
8bac466b | 40 | #include "notify.h" |
3a068632 | 41 | #include "bss.h" |
9ba9fa07 | 42 | #include "scan.h" |
3a068632 | 43 | #include "ctrl_iface.h" |
afc064fe | 44 | #include "interworking.h" |
9aa10e2b | 45 | #include "blacklist.h" |
bc5d330a | 46 | #include "autoscan.h" |
e9199e31 | 47 | #include "wnm_sta.h" |
60b893df | 48 | #include "offchannel.h" |
7a4a93b9 | 49 | #include "drivers/driver.h" |
79070906 | 50 | #include "mesh.h" |
6fc6879b | 51 | |
4b4a8ae5 JM |
52 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
53 | char *buf, int len); | |
6fc6879b JM |
54 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
55 | char *buf, int len); | |
d3c9c35f DS |
56 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, |
57 | char *val); | |
6fc6879b | 58 | |
d445a5cd JM |
59 | static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val) |
60 | { | |
61 | char *pos; | |
62 | u8 addr[ETH_ALEN], *filter = NULL, *n; | |
63 | size_t count = 0; | |
64 | ||
65 | pos = val; | |
66 | while (pos) { | |
67 | if (*pos == '\0') | |
68 | break; | |
1485ec07 JM |
69 | if (hwaddr_aton(pos, addr)) { |
70 | os_free(filter); | |
d445a5cd | 71 | return -1; |
1485ec07 | 72 | } |
067ffa26 | 73 | n = os_realloc_array(filter, count + 1, ETH_ALEN); |
d445a5cd JM |
74 | if (n == NULL) { |
75 | os_free(filter); | |
76 | return -1; | |
77 | } | |
78 | filter = n; | |
79 | os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN); | |
80 | count++; | |
81 | ||
82 | pos = os_strchr(pos, ' '); | |
83 | if (pos) | |
84 | pos++; | |
85 | } | |
86 | ||
87 | wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN); | |
88 | os_free(wpa_s->bssid_filter); | |
89 | wpa_s->bssid_filter = filter; | |
90 | wpa_s->bssid_filter_count = count; | |
91 | ||
92 | return 0; | |
93 | } | |
94 | ||
95 | ||
6407f413 JM |
96 | static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val) |
97 | { | |
98 | char *pos; | |
99 | u8 addr[ETH_ALEN], *bssid = NULL, *n; | |
100 | struct wpa_ssid_value *ssid = NULL, *ns; | |
101 | size_t count = 0, ssid_count = 0; | |
102 | struct wpa_ssid *c; | |
103 | ||
104 | /* | |
65015b2d | 105 | * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | "" |
6407f413 JM |
106 | * SSID_SPEC ::= ssid <SSID_HEX> |
107 | * BSSID_SPEC ::= bssid <BSSID_HEX> | |
108 | */ | |
109 | ||
110 | pos = val; | |
111 | while (pos) { | |
112 | if (*pos == '\0') | |
113 | break; | |
114 | if (os_strncmp(pos, "bssid ", 6) == 0) { | |
115 | int res; | |
116 | pos += 6; | |
117 | res = hwaddr_aton2(pos, addr); | |
118 | if (res < 0) { | |
119 | os_free(ssid); | |
120 | os_free(bssid); | |
121 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " | |
122 | "BSSID value '%s'", pos); | |
123 | return -1; | |
124 | } | |
125 | pos += res; | |
126 | n = os_realloc_array(bssid, count + 1, ETH_ALEN); | |
127 | if (n == NULL) { | |
128 | os_free(ssid); | |
129 | os_free(bssid); | |
130 | return -1; | |
131 | } | |
132 | bssid = n; | |
133 | os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN); | |
134 | count++; | |
135 | } else if (os_strncmp(pos, "ssid ", 5) == 0) { | |
136 | char *end; | |
137 | pos += 5; | |
138 | ||
139 | end = pos; | |
140 | while (*end) { | |
141 | if (*end == '\0' || *end == ' ') | |
142 | break; | |
143 | end++; | |
144 | } | |
145 | ||
146 | ns = os_realloc_array(ssid, ssid_count + 1, | |
147 | sizeof(struct wpa_ssid_value)); | |
148 | if (ns == NULL) { | |
149 | os_free(ssid); | |
150 | os_free(bssid); | |
151 | return -1; | |
152 | } | |
153 | ssid = ns; | |
154 | ||
155 | if ((end - pos) & 0x01 || end - pos > 2 * 32 || | |
156 | hexstr2bin(pos, ssid[ssid_count].ssid, | |
157 | (end - pos) / 2) < 0) { | |
158 | os_free(ssid); | |
159 | os_free(bssid); | |
160 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " | |
161 | "SSID value '%s'", pos); | |
162 | return -1; | |
163 | } | |
164 | ssid[ssid_count].ssid_len = (end - pos) / 2; | |
165 | wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID", | |
166 | ssid[ssid_count].ssid, | |
167 | ssid[ssid_count].ssid_len); | |
168 | ssid_count++; | |
169 | pos = end; | |
170 | } else { | |
171 | wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value " | |
172 | "'%s'", pos); | |
173 | os_free(ssid); | |
174 | os_free(bssid); | |
175 | return -1; | |
176 | } | |
177 | ||
178 | pos = os_strchr(pos, ' '); | |
179 | if (pos) | |
180 | pos++; | |
181 | } | |
182 | ||
183 | wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN); | |
184 | os_free(wpa_s->disallow_aps_bssid); | |
185 | wpa_s->disallow_aps_bssid = bssid; | |
186 | wpa_s->disallow_aps_bssid_count = count; | |
187 | ||
188 | wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count); | |
189 | os_free(wpa_s->disallow_aps_ssid); | |
190 | wpa_s->disallow_aps_ssid = ssid; | |
191 | wpa_s->disallow_aps_ssid_count = ssid_count; | |
192 | ||
193 | if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING) | |
194 | return 0; | |
195 | ||
196 | c = wpa_s->current_ssid; | |
197 | if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS) | |
198 | return 0; | |
199 | ||
200 | if (!disallowed_bssid(wpa_s, wpa_s->bssid) && | |
201 | !disallowed_ssid(wpa_s, c->ssid, c->ssid_len)) | |
202 | return 0; | |
203 | ||
204 | wpa_printf(MSG_DEBUG, "Disconnect and try to find another network " | |
205 | "because current AP was marked disallowed"); | |
206 | ||
207 | #ifdef CONFIG_SME | |
208 | wpa_s->sme.prev_bssid_set = 0; | |
209 | #endif /* CONFIG_SME */ | |
210 | wpa_s->reassociate = 1; | |
211 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
212 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
213 | ||
214 | return 0; | |
215 | } | |
216 | ||
217 | ||
1120e452 JM |
218 | #ifndef CONFIG_NO_CONFIG_BLOBS |
219 | static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos) | |
220 | { | |
221 | char *name = pos; | |
222 | struct wpa_config_blob *blob; | |
223 | size_t len; | |
224 | ||
225 | pos = os_strchr(pos, ' '); | |
226 | if (pos == NULL) | |
227 | return -1; | |
228 | *pos++ = '\0'; | |
229 | len = os_strlen(pos); | |
230 | if (len & 1) | |
231 | return -1; | |
232 | ||
233 | wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name); | |
234 | blob = os_zalloc(sizeof(*blob)); | |
235 | if (blob == NULL) | |
236 | return -1; | |
237 | blob->name = os_strdup(name); | |
238 | blob->data = os_malloc(len / 2); | |
239 | if (blob->name == NULL || blob->data == NULL) { | |
240 | wpa_config_free_blob(blob); | |
241 | return -1; | |
242 | } | |
243 | ||
244 | if (hexstr2bin(pos, blob->data, len / 2) < 0) { | |
245 | wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data"); | |
246 | wpa_config_free_blob(blob); | |
247 | return -1; | |
248 | } | |
249 | blob->len = len / 2; | |
250 | ||
251 | wpa_config_set_blob(wpa_s->conf, blob); | |
252 | ||
253 | return 0; | |
254 | } | |
255 | #endif /* CONFIG_NO_CONFIG_BLOBS */ | |
256 | ||
d3c9c35f DS |
257 | |
258 | static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd) | |
259 | { | |
260 | char *params; | |
261 | char *pos; | |
262 | int *freqs = NULL; | |
263 | int ret; | |
264 | ||
265 | if (atoi(cmd)) { | |
266 | params = os_strchr(cmd, ' '); | |
267 | os_free(wpa_s->manual_sched_scan_freqs); | |
268 | if (params) { | |
269 | params++; | |
270 | pos = os_strstr(params, "freq="); | |
271 | if (pos) | |
272 | freqs = freq_range_to_channel_list(wpa_s, | |
273 | pos + 5); | |
274 | } | |
275 | wpa_s->manual_sched_scan_freqs = freqs; | |
276 | ret = wpas_start_pno(wpa_s); | |
277 | } else { | |
278 | ret = wpas_stop_pno(wpa_s); | |
279 | } | |
280 | return ret; | |
281 | } | |
282 | ||
283 | ||
6fc6879b JM |
284 | static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, |
285 | char *cmd) | |
286 | { | |
287 | char *value; | |
288 | int ret = 0; | |
289 | ||
290 | value = os_strchr(cmd, ' '); | |
291 | if (value == NULL) | |
292 | return -1; | |
293 | *value++ = '\0'; | |
294 | ||
295 | wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value); | |
296 | if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) { | |
297 | eapol_sm_configure(wpa_s->eapol, | |
298 | atoi(value), -1, -1, -1); | |
299 | } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) { | |
300 | eapol_sm_configure(wpa_s->eapol, | |
301 | -1, atoi(value), -1, -1); | |
302 | } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) { | |
303 | eapol_sm_configure(wpa_s->eapol, | |
304 | -1, -1, atoi(value), -1); | |
305 | } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) { | |
306 | eapol_sm_configure(wpa_s->eapol, | |
307 | -1, -1, -1, atoi(value)); | |
308 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) { | |
309 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, | |
310 | atoi(value))) | |
311 | ret = -1; | |
312 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == | |
313 | 0) { | |
314 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, | |
315 | atoi(value))) | |
316 | ret = -1; | |
317 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) { | |
318 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value))) | |
319 | ret = -1; | |
42f50264 JM |
320 | } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) { |
321 | wpa_s->wps_fragment_size = atoi(value); | |
b4e34f2f JM |
322 | #ifdef CONFIG_WPS_TESTING |
323 | } else if (os_strcasecmp(cmd, "wps_version_number") == 0) { | |
324 | long int val; | |
325 | val = strtol(value, NULL, 0); | |
326 | if (val < 0 || val > 0xff) { | |
327 | ret = -1; | |
328 | wpa_printf(MSG_DEBUG, "WPS: Invalid " | |
329 | "wps_version_number %ld", val); | |
330 | } else { | |
331 | wps_version_number = val; | |
332 | wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS " | |
333 | "version %u.%u", | |
334 | (wps_version_number & 0xf0) >> 4, | |
335 | wps_version_number & 0x0f); | |
336 | } | |
337 | } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) { | |
338 | wps_testing_dummy_cred = atoi(value); | |
339 | wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d", | |
340 | wps_testing_dummy_cred); | |
91226e0d JM |
341 | } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) { |
342 | wps_corrupt_pkhash = atoi(value); | |
343 | wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d", | |
344 | wps_corrupt_pkhash); | |
b4e34f2f | 345 | #endif /* CONFIG_WPS_TESTING */ |
b6c79a99 JM |
346 | } else if (os_strcasecmp(cmd, "ampdu") == 0) { |
347 | if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0) | |
348 | ret = -1; | |
9d2cb3ec | 349 | #ifdef CONFIG_TDLS |
5b0e6ece JM |
350 | #ifdef CONFIG_TDLS_TESTING |
351 | } else if (os_strcasecmp(cmd, "tdls_testing") == 0) { | |
352 | extern unsigned int tdls_testing; | |
353 | tdls_testing = strtol(value, NULL, 0); | |
354 | wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing); | |
355 | #endif /* CONFIG_TDLS_TESTING */ | |
b8f64582 JM |
356 | } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) { |
357 | int disabled = atoi(value); | |
358 | wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled); | |
359 | if (disabled) { | |
360 | if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0) | |
361 | ret = -1; | |
362 | } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0) | |
363 | ret = -1; | |
364 | wpa_tdls_enable(wpa_s->wpa, !disabled); | |
365 | #endif /* CONFIG_TDLS */ | |
b5c68312 | 366 | } else if (os_strcasecmp(cmd, "pno") == 0) { |
d3c9c35f | 367 | ret = wpas_ctrl_pno(wpa_s, value); |
8b9d0bfa JM |
368 | } else if (os_strcasecmp(cmd, "radio_disabled") == 0) { |
369 | int disabled = atoi(value); | |
370 | if (wpa_drv_radio_disable(wpa_s, disabled) < 0) | |
371 | ret = -1; | |
372 | else if (disabled) | |
373 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | |
aa074a64 JM |
374 | } else if (os_strcasecmp(cmd, "uapsd") == 0) { |
375 | if (os_strcmp(value, "disable") == 0) | |
376 | wpa_s->set_sta_uapsd = 0; | |
377 | else { | |
378 | int be, bk, vi, vo; | |
379 | char *pos; | |
380 | /* format: BE,BK,VI,VO;max SP Length */ | |
381 | be = atoi(value); | |
382 | pos = os_strchr(value, ','); | |
383 | if (pos == NULL) | |
384 | return -1; | |
385 | pos++; | |
386 | bk = atoi(pos); | |
387 | pos = os_strchr(pos, ','); | |
388 | if (pos == NULL) | |
389 | return -1; | |
390 | pos++; | |
391 | vi = atoi(pos); | |
392 | pos = os_strchr(pos, ','); | |
393 | if (pos == NULL) | |
394 | return -1; | |
395 | pos++; | |
396 | vo = atoi(pos); | |
397 | /* ignore max SP Length for now */ | |
398 | ||
399 | wpa_s->set_sta_uapsd = 1; | |
400 | wpa_s->sta_uapsd = 0; | |
401 | if (be) | |
402 | wpa_s->sta_uapsd |= BIT(0); | |
403 | if (bk) | |
404 | wpa_s->sta_uapsd |= BIT(1); | |
405 | if (vi) | |
406 | wpa_s->sta_uapsd |= BIT(2); | |
407 | if (vo) | |
408 | wpa_s->sta_uapsd |= BIT(3); | |
409 | } | |
b2ff1681 JM |
410 | } else if (os_strcasecmp(cmd, "ps") == 0) { |
411 | ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1); | |
9675ce35 JM |
412 | #ifdef CONFIG_WIFI_DISPLAY |
413 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { | |
bab6677a JM |
414 | int enabled = !!atoi(value); |
415 | if (enabled && !wpa_s->global->p2p) | |
416 | ret = -1; | |
417 | else | |
418 | wifi_display_enable(wpa_s->global, enabled); | |
9675ce35 | 419 | #endif /* CONFIG_WIFI_DISPLAY */ |
d445a5cd JM |
420 | } else if (os_strcasecmp(cmd, "bssid_filter") == 0) { |
421 | ret = set_bssid_filter(wpa_s, value); | |
6407f413 JM |
422 | } else if (os_strcasecmp(cmd, "disallow_aps") == 0) { |
423 | ret = set_disallow_aps(wpa_s, value); | |
2ec535fd JM |
424 | } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) { |
425 | wpa_s->no_keep_alive = !!atoi(value); | |
60b893df JM |
426 | #ifdef CONFIG_TESTING_OPTIONS |
427 | } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) { | |
428 | wpa_s->ext_mgmt_frame_handling = !!atoi(value); | |
9d4ff04a JM |
429 | } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) { |
430 | wpa_s->ext_eapol_frame_io = !!atoi(value); | |
431 | #ifdef CONFIG_AP | |
432 | if (wpa_s->ap_iface) { | |
433 | wpa_s->ap_iface->bss[0]->ext_eapol_frame_io = | |
434 | wpa_s->ext_eapol_frame_io; | |
435 | } | |
436 | #endif /* CONFIG_AP */ | |
1f94e4ee JM |
437 | } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) { |
438 | wpa_s->extra_roc_dur = atoi(value); | |
60b893df | 439 | #endif /* CONFIG_TESTING_OPTIONS */ |
1120e452 JM |
440 | #ifndef CONFIG_NO_CONFIG_BLOBS |
441 | } else if (os_strcmp(cmd, "blob") == 0) { | |
442 | ret = wpas_ctrl_set_blob(wpa_s, value); | |
443 | #endif /* CONFIG_NO_CONFIG_BLOBS */ | |
611aea7d JM |
444 | } else { |
445 | value[-1] = '='; | |
446 | ret = wpa_config_process_global(wpa_s->conf, cmd, -1); | |
447 | if (ret == 0) | |
448 | wpa_supplicant_update_config(wpa_s); | |
449 | } | |
6fc6879b JM |
450 | |
451 | return ret; | |
452 | } | |
453 | ||
454 | ||
acec8d32 JM |
455 | static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s, |
456 | char *cmd, char *buf, size_t buflen) | |
457 | { | |
6ce937b8 | 458 | int res = -1; |
acec8d32 JM |
459 | |
460 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd); | |
461 | ||
462 | if (os_strcmp(cmd, "version") == 0) { | |
463 | res = os_snprintf(buf, buflen, "%s", VERSION_STR); | |
6ce937b8 DS |
464 | } else if (os_strcasecmp(cmd, "country") == 0) { |
465 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) | |
466 | res = os_snprintf(buf, buflen, "%c%c", | |
467 | wpa_s->conf->country[0], | |
468 | wpa_s->conf->country[1]); | |
9675ce35 JM |
469 | #ifdef CONFIG_WIFI_DISPLAY |
470 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { | |
bab6677a JM |
471 | int enabled; |
472 | if (wpa_s->global->p2p == NULL || | |
473 | wpa_s->global->p2p_disabled) | |
474 | enabled = 0; | |
475 | else | |
476 | enabled = wpa_s->global->wifi_display; | |
477 | res = os_snprintf(buf, buflen, "%d", enabled); | |
9675ce35 JM |
478 | if (res < 0 || (unsigned int) res >= buflen) |
479 | return -1; | |
480 | return res; | |
481 | #endif /* CONFIG_WIFI_DISPLAY */ | |
fa7ae950 JM |
482 | #ifdef CONFIG_TESTING_GET_GTK |
483 | } else if (os_strcmp(cmd, "gtk") == 0) { | |
484 | if (wpa_s->last_gtk_len == 0) | |
485 | return -1; | |
486 | res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk, | |
487 | wpa_s->last_gtk_len); | |
488 | return res; | |
489 | #endif /* CONFIG_TESTING_GET_GTK */ | |
acec8d32 JM |
490 | } |
491 | ||
6ce937b8 DS |
492 | if (res < 0 || (unsigned int) res >= buflen) |
493 | return -1; | |
494 | return res; | |
acec8d32 JM |
495 | } |
496 | ||
497 | ||
ec717917 | 498 | #ifdef IEEE8021X_EAPOL |
6fc6879b JM |
499 | static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s, |
500 | char *addr) | |
501 | { | |
502 | u8 bssid[ETH_ALEN]; | |
503 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
504 | ||
505 | if (hwaddr_aton(addr, bssid)) { | |
506 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address " | |
507 | "'%s'", addr); | |
508 | return -1; | |
509 | } | |
510 | ||
511 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid)); | |
512 | rsn_preauth_deinit(wpa_s->wpa); | |
513 | if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL)) | |
514 | return -1; | |
515 | ||
516 | return 0; | |
517 | } | |
ec717917 | 518 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
519 | |
520 | ||
521 | #ifdef CONFIG_PEERKEY | |
522 | /* MLME-STKSTART.request(peer) */ | |
523 | static int wpa_supplicant_ctrl_iface_stkstart( | |
524 | struct wpa_supplicant *wpa_s, char *addr) | |
525 | { | |
526 | u8 peer[ETH_ALEN]; | |
527 | ||
528 | if (hwaddr_aton(addr, peer)) { | |
529 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid " | |
a7b6c422 | 530 | "address '%s'", addr); |
6fc6879b JM |
531 | return -1; |
532 | } | |
533 | ||
534 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR, | |
535 | MAC2STR(peer)); | |
536 | ||
537 | return wpa_sm_stkstart(wpa_s->wpa, peer); | |
538 | } | |
539 | #endif /* CONFIG_PEERKEY */ | |
540 | ||
541 | ||
281ff0aa GP |
542 | #ifdef CONFIG_TDLS |
543 | ||
544 | static int wpa_supplicant_ctrl_iface_tdls_discover( | |
545 | struct wpa_supplicant *wpa_s, char *addr) | |
546 | { | |
547 | u8 peer[ETH_ALEN]; | |
2d565a61 | 548 | int ret; |
281ff0aa GP |
549 | |
550 | if (hwaddr_aton(addr, peer)) { | |
551 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid " | |
552 | "address '%s'", addr); | |
553 | return -1; | |
554 | } | |
555 | ||
556 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR, | |
557 | MAC2STR(peer)); | |
558 | ||
2d565a61 AN |
559 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
560 | ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer); | |
561 | else | |
562 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); | |
563 | ||
564 | return ret; | |
281ff0aa GP |
565 | } |
566 | ||
567 | ||
568 | static int wpa_supplicant_ctrl_iface_tdls_setup( | |
569 | struct wpa_supplicant *wpa_s, char *addr) | |
570 | { | |
571 | u8 peer[ETH_ALEN]; | |
94377fbc | 572 | int ret; |
281ff0aa GP |
573 | |
574 | if (hwaddr_aton(addr, peer)) { | |
575 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid " | |
576 | "address '%s'", addr); | |
577 | return -1; | |
578 | } | |
579 | ||
580 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR, | |
581 | MAC2STR(peer)); | |
582 | ||
800d5872 SD |
583 | if ((wpa_s->conf->tdls_external_control) && |
584 | wpa_tdls_is_external_setup(wpa_s->wpa)) | |
585 | return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | |
586 | ||
3887878e SD |
587 | wpa_tdls_remove(wpa_s->wpa, peer); |
588 | ||
589 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | |
590 | ret = wpa_tdls_start(wpa_s->wpa, peer); | |
591 | else | |
592 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | |
2d565a61 | 593 | |
94377fbc | 594 | return ret; |
281ff0aa GP |
595 | } |
596 | ||
597 | ||
598 | static int wpa_supplicant_ctrl_iface_tdls_teardown( | |
599 | struct wpa_supplicant *wpa_s, char *addr) | |
600 | { | |
601 | u8 peer[ETH_ALEN]; | |
4ed8d954 | 602 | int ret; |
281ff0aa | 603 | |
38ddccae AN |
604 | if (os_strcmp(addr, "*") == 0) { |
605 | /* remove everyone */ | |
606 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *"); | |
607 | wpa_tdls_teardown_peers(wpa_s->wpa); | |
608 | return 0; | |
609 | } | |
610 | ||
281ff0aa GP |
611 | if (hwaddr_aton(addr, peer)) { |
612 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid " | |
613 | "address '%s'", addr); | |
614 | return -1; | |
615 | } | |
616 | ||
617 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR, | |
618 | MAC2STR(peer)); | |
619 | ||
800d5872 SD |
620 | if ((wpa_s->conf->tdls_external_control) && |
621 | wpa_tdls_is_external_setup(wpa_s->wpa)) | |
622 | return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); | |
623 | ||
4ed8d954 AS |
624 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
625 | ret = wpa_tdls_teardown_link( | |
626 | wpa_s->wpa, peer, | |
627 | WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED); | |
628 | else | |
629 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); | |
630 | ||
631 | return ret; | |
281ff0aa GP |
632 | } |
633 | ||
6e9375e4 DS |
634 | |
635 | static int ctrl_iface_get_capability_tdls( | |
636 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
637 | { | |
638 | int ret; | |
639 | ||
640 | ret = os_snprintf(buf, buflen, "%s\n", | |
641 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ? | |
642 | (wpa_s->drv_flags & | |
643 | WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ? | |
644 | "EXTERNAL" : "INTERNAL") : "UNSUPPORTED"); | |
645 | if (ret < 0 || (size_t) ret > buflen) | |
646 | return -1; | |
647 | return ret; | |
648 | } | |
649 | ||
281ff0aa GP |
650 | #endif /* CONFIG_TDLS */ |
651 | ||
652 | ||
eb2f2088 MB |
653 | static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd) |
654 | { | |
655 | char *token, *context = NULL; | |
656 | struct wmm_ac_ts_setup_params params = { | |
657 | .tsid = 0xff, | |
658 | .direction = 0xff, | |
659 | }; | |
660 | ||
661 | while ((token = str_token(cmd, " ", &context))) { | |
662 | if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 || | |
663 | sscanf(token, "up=%i", ¶ms.user_priority) == 1 || | |
664 | sscanf(token, "nominal_msdu_size=%i", | |
665 | ¶ms.nominal_msdu_size) == 1 || | |
666 | sscanf(token, "mean_data_rate=%i", | |
667 | ¶ms.mean_data_rate) == 1 || | |
668 | sscanf(token, "min_phy_rate=%i", | |
669 | ¶ms.minimum_phy_rate) == 1 || | |
670 | sscanf(token, "sba=%i", | |
671 | ¶ms.surplus_bandwidth_allowance) == 1) | |
672 | continue; | |
673 | ||
674 | if (os_strcasecmp(token, "downlink") == 0) { | |
675 | params.direction = WMM_TSPEC_DIRECTION_DOWNLINK; | |
676 | } else if (os_strcasecmp(token, "uplink") == 0) { | |
677 | params.direction = WMM_TSPEC_DIRECTION_UPLINK; | |
678 | } else if (os_strcasecmp(token, "bidi") == 0) { | |
679 | params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL; | |
680 | } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) { | |
681 | params.fixed_nominal_msdu = 1; | |
682 | } else { | |
683 | wpa_printf(MSG_DEBUG, | |
684 | "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'", | |
685 | token); | |
686 | return -1; | |
687 | } | |
688 | ||
689 | } | |
690 | ||
691 | return wpas_wmm_ac_addts(wpa_s, ¶ms); | |
692 | } | |
693 | ||
694 | ||
695 | static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd) | |
696 | { | |
697 | u8 tsid = atoi(cmd); | |
698 | ||
699 | return wpas_wmm_ac_delts(wpa_s, tsid); | |
700 | } | |
701 | ||
702 | ||
6fc6879b JM |
703 | #ifdef CONFIG_IEEE80211R |
704 | static int wpa_supplicant_ctrl_iface_ft_ds( | |
705 | struct wpa_supplicant *wpa_s, char *addr) | |
706 | { | |
707 | u8 target_ap[ETH_ALEN]; | |
76b7981d JM |
708 | struct wpa_bss *bss; |
709 | const u8 *mdie; | |
6fc6879b JM |
710 | |
711 | if (hwaddr_aton(addr, target_ap)) { | |
712 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid " | |
a7b6c422 | 713 | "address '%s'", addr); |
6fc6879b JM |
714 | return -1; |
715 | } | |
716 | ||
717 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap)); | |
718 | ||
76b7981d JM |
719 | bss = wpa_bss_get_bssid(wpa_s, target_ap); |
720 | if (bss) | |
721 | mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); | |
722 | else | |
723 | mdie = NULL; | |
724 | ||
725 | return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie); | |
6fc6879b JM |
726 | } |
727 | #endif /* CONFIG_IEEE80211R */ | |
728 | ||
729 | ||
fcc60db4 JM |
730 | #ifdef CONFIG_WPS |
731 | static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s, | |
732 | char *cmd) | |
733 | { | |
3ec97afe | 734 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
ceb34f25 | 735 | #ifdef CONFIG_P2P |
634ce802 | 736 | u8 p2p_dev_addr[ETH_ALEN]; |
ceb34f25 | 737 | #endif /* CONFIG_P2P */ |
634ce802 JM |
738 | #ifdef CONFIG_AP |
739 | u8 *_p2p_dev_addr = NULL; | |
740 | #endif /* CONFIG_AP */ | |
fcc60db4 | 741 | |
d601247c | 742 | if (cmd == NULL || os_strcmp(cmd, "any") == 0) { |
3ec97afe | 743 | _bssid = NULL; |
d601247c JM |
744 | #ifdef CONFIG_P2P |
745 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | |
746 | if (hwaddr_aton(cmd + 13, p2p_dev_addr)) { | |
747 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid " | |
748 | "P2P Device Address '%s'", | |
749 | cmd + 13); | |
750 | return -1; | |
751 | } | |
752 | _p2p_dev_addr = p2p_dev_addr; | |
753 | #endif /* CONFIG_P2P */ | |
754 | } else if (hwaddr_aton(cmd, bssid)) { | |
fcc60db4 JM |
755 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'", |
756 | cmd); | |
757 | return -1; | |
758 | } | |
759 | ||
3ec97afe JM |
760 | #ifdef CONFIG_AP |
761 | if (wpa_s->ap_iface) | |
d601247c | 762 | return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr); |
3ec97afe JM |
763 | #endif /* CONFIG_AP */ |
764 | ||
9fa243b2 | 765 | return wpas_wps_start_pbc(wpa_s, _bssid, 0); |
fcc60db4 JM |
766 | } |
767 | ||
768 | ||
769 | static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, | |
770 | char *cmd, char *buf, | |
771 | size_t buflen) | |
772 | { | |
773 | u8 bssid[ETH_ALEN], *_bssid = bssid; | |
774 | char *pin; | |
775 | int ret; | |
776 | ||
777 | pin = os_strchr(cmd, ' '); | |
778 | if (pin) | |
779 | *pin++ = '\0'; | |
780 | ||
781 | if (os_strcmp(cmd, "any") == 0) | |
782 | _bssid = NULL; | |
98aa7ca5 JM |
783 | else if (os_strcmp(cmd, "get") == 0) { |
784 | ret = wps_generate_pin(); | |
785 | goto done; | |
786 | } else if (hwaddr_aton(cmd, bssid)) { | |
3c1e2765 | 787 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'", |
fcc60db4 JM |
788 | cmd); |
789 | return -1; | |
790 | } | |
791 | ||
3ec97afe | 792 | #ifdef CONFIG_AP |
c423708f JM |
793 | if (wpa_s->ap_iface) { |
794 | int timeout = 0; | |
795 | char *pos; | |
796 | ||
797 | if (pin) { | |
798 | pos = os_strchr(pin, ' '); | |
799 | if (pos) { | |
800 | *pos++ = '\0'; | |
801 | timeout = atoi(pos); | |
802 | } | |
803 | } | |
804 | ||
3ec97afe | 805 | return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, |
c423708f JM |
806 | buf, buflen, timeout); |
807 | } | |
3ec97afe JM |
808 | #endif /* CONFIG_AP */ |
809 | ||
fcc60db4 | 810 | if (pin) { |
3c5126a4 JM |
811 | ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0, |
812 | DEV_PW_DEFAULT); | |
fcc60db4 JM |
813 | if (ret < 0) |
814 | return -1; | |
815 | ret = os_snprintf(buf, buflen, "%s", pin); | |
816 | if (ret < 0 || (size_t) ret >= buflen) | |
817 | return -1; | |
818 | return ret; | |
819 | } | |
820 | ||
3c5126a4 | 821 | ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT); |
fcc60db4 JM |
822 | if (ret < 0) |
823 | return -1; | |
824 | ||
98aa7ca5 | 825 | done: |
fcc60db4 JM |
826 | /* Return the generated PIN */ |
827 | ret = os_snprintf(buf, buflen, "%08d", ret); | |
828 | if (ret < 0 || (size_t) ret >= buflen) | |
829 | return -1; | |
830 | return ret; | |
831 | } | |
832 | ||
833 | ||
3981cb3c JM |
834 | static int wpa_supplicant_ctrl_iface_wps_check_pin( |
835 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
836 | { | |
837 | char pin[9]; | |
838 | size_t len; | |
839 | char *pos; | |
840 | int ret; | |
841 | ||
842 | wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN", | |
843 | (u8 *) cmd, os_strlen(cmd)); | |
844 | for (pos = cmd, len = 0; *pos != '\0'; pos++) { | |
845 | if (*pos < '0' || *pos > '9') | |
846 | continue; | |
847 | pin[len++] = *pos; | |
848 | if (len == 9) { | |
849 | wpa_printf(MSG_DEBUG, "WPS: Too long PIN"); | |
850 | return -1; | |
851 | } | |
852 | } | |
853 | if (len != 4 && len != 8) { | |
854 | wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len); | |
855 | return -1; | |
856 | } | |
857 | pin[len] = '\0'; | |
858 | ||
859 | if (len == 8) { | |
860 | unsigned int pin_val; | |
861 | pin_val = atoi(pin); | |
862 | if (!wps_pin_valid(pin_val)) { | |
863 | wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit"); | |
864 | ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n"); | |
865 | if (ret < 0 || (size_t) ret >= buflen) | |
866 | return -1; | |
867 | return ret; | |
868 | } | |
869 | } | |
870 | ||
871 | ret = os_snprintf(buf, buflen, "%s", pin); | |
872 | if (ret < 0 || (size_t) ret >= buflen) | |
873 | return -1; | |
874 | ||
875 | return ret; | |
876 | } | |
877 | ||
878 | ||
71892384 | 879 | #ifdef CONFIG_WPS_NFC |
3f2c8ba6 JM |
880 | |
881 | static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s, | |
882 | char *cmd) | |
883 | { | |
884 | u8 bssid[ETH_ALEN], *_bssid = bssid; | |
885 | ||
886 | if (cmd == NULL || cmd[0] == '\0') | |
887 | _bssid = NULL; | |
888 | else if (hwaddr_aton(cmd, bssid)) | |
889 | return -1; | |
890 | ||
23318bea | 891 | return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL, |
91a65018 | 892 | 0, 0); |
3f2c8ba6 JM |
893 | } |
894 | ||
895 | ||
bbf41865 JM |
896 | static int wpa_supplicant_ctrl_iface_wps_nfc_config_token( |
897 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
898 | { | |
899 | int ndef; | |
900 | struct wpabuf *buf; | |
901 | int res; | |
88c8bf31 | 902 | char *pos; |
bbf41865 | 903 | |
88c8bf31 JM |
904 | pos = os_strchr(cmd, ' '); |
905 | if (pos) | |
906 | *pos++ = '\0'; | |
bbf41865 JM |
907 | if (os_strcmp(cmd, "WPS") == 0) |
908 | ndef = 0; | |
909 | else if (os_strcmp(cmd, "NDEF") == 0) | |
910 | ndef = 1; | |
911 | else | |
912 | return -1; | |
913 | ||
88c8bf31 | 914 | buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos); |
bbf41865 JM |
915 | if (buf == NULL) |
916 | return -1; | |
917 | ||
918 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
919 | wpabuf_len(buf)); | |
920 | reply[res++] = '\n'; | |
921 | reply[res] = '\0'; | |
922 | ||
923 | wpabuf_free(buf); | |
924 | ||
925 | return res; | |
926 | } | |
927 | ||
928 | ||
3f2c8ba6 JM |
929 | static int wpa_supplicant_ctrl_iface_wps_nfc_token( |
930 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
931 | { | |
932 | int ndef; | |
933 | struct wpabuf *buf; | |
934 | int res; | |
935 | ||
936 | if (os_strcmp(cmd, "WPS") == 0) | |
937 | ndef = 0; | |
938 | else if (os_strcmp(cmd, "NDEF") == 0) | |
939 | ndef = 1; | |
940 | else | |
941 | return -1; | |
942 | ||
943 | buf = wpas_wps_nfc_token(wpa_s, ndef); | |
944 | if (buf == NULL) | |
945 | return -1; | |
946 | ||
947 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
948 | wpabuf_len(buf)); | |
949 | reply[res++] = '\n'; | |
950 | reply[res] = '\0'; | |
951 | ||
952 | wpabuf_free(buf); | |
953 | ||
954 | return res; | |
955 | } | |
d7645d23 JM |
956 | |
957 | ||
958 | static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read( | |
959 | struct wpa_supplicant *wpa_s, char *pos) | |
960 | { | |
961 | size_t len; | |
962 | struct wpabuf *buf; | |
963 | int ret; | |
b56f6c88 JM |
964 | char *freq; |
965 | int forced_freq = 0; | |
966 | ||
967 | freq = strstr(pos, " freq="); | |
968 | if (freq) { | |
969 | *freq = '\0'; | |
970 | freq += 6; | |
971 | forced_freq = atoi(freq); | |
972 | } | |
d7645d23 JM |
973 | |
974 | len = os_strlen(pos); | |
975 | if (len & 0x01) | |
976 | return -1; | |
977 | len /= 2; | |
978 | ||
979 | buf = wpabuf_alloc(len); | |
980 | if (buf == NULL) | |
981 | return -1; | |
982 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { | |
983 | wpabuf_free(buf); | |
984 | return -1; | |
985 | } | |
986 | ||
b56f6c88 | 987 | ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq); |
d7645d23 JM |
988 | wpabuf_free(buf); |
989 | ||
990 | return ret; | |
991 | } | |
71892384 | 992 | |
e65552dd JM |
993 | |
994 | static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s, | |
bbaaaee1 | 995 | char *reply, size_t max_len, |
41f9ffb6 | 996 | int ndef) |
e65552dd JM |
997 | { |
998 | struct wpabuf *buf; | |
999 | int res; | |
1000 | ||
41f9ffb6 | 1001 | buf = wpas_wps_nfc_handover_req(wpa_s, ndef); |
e65552dd JM |
1002 | if (buf == NULL) |
1003 | return -1; | |
1004 | ||
1005 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1006 | wpabuf_len(buf)); | |
1007 | reply[res++] = '\n'; | |
1008 | reply[res] = '\0'; | |
1009 | ||
1010 | wpabuf_free(buf); | |
1011 | ||
1012 | return res; | |
1013 | } | |
1014 | ||
1015 | ||
88853aed | 1016 | #ifdef CONFIG_P2P |
93588780 JM |
1017 | static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s, |
1018 | char *reply, size_t max_len, | |
1019 | int ndef) | |
1020 | { | |
1021 | struct wpabuf *buf; | |
1022 | int res; | |
1023 | ||
1024 | buf = wpas_p2p_nfc_handover_req(wpa_s, ndef); | |
1025 | if (buf == NULL) { | |
1026 | wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request"); | |
1027 | return -1; | |
1028 | } | |
1029 | ||
1030 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1031 | wpabuf_len(buf)); | |
1032 | reply[res++] = '\n'; | |
1033 | reply[res] = '\0'; | |
1034 | ||
1035 | wpabuf_free(buf); | |
1036 | ||
1037 | return res; | |
1038 | } | |
88853aed | 1039 | #endif /* CONFIG_P2P */ |
93588780 JM |
1040 | |
1041 | ||
e65552dd JM |
1042 | static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s, |
1043 | char *cmd, char *reply, | |
1044 | size_t max_len) | |
1045 | { | |
1046 | char *pos; | |
41f9ffb6 | 1047 | int ndef; |
e65552dd JM |
1048 | |
1049 | pos = os_strchr(cmd, ' '); | |
1050 | if (pos == NULL) | |
1051 | return -1; | |
1052 | *pos++ = '\0'; | |
1053 | ||
41f9ffb6 JM |
1054 | if (os_strcmp(cmd, "WPS") == 0) |
1055 | ndef = 0; | |
1056 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1057 | ndef = 1; | |
1058 | else | |
e65552dd JM |
1059 | return -1; |
1060 | ||
bbaaaee1 | 1061 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
41f9ffb6 JM |
1062 | if (!ndef) |
1063 | return -1; | |
bbaaaee1 | 1064 | return wpas_ctrl_nfc_get_handover_req_wps( |
41f9ffb6 | 1065 | wpa_s, reply, max_len, ndef); |
e65552dd JM |
1066 | } |
1067 | ||
88853aed | 1068 | #ifdef CONFIG_P2P |
93588780 JM |
1069 | if (os_strcmp(pos, "P2P-CR") == 0) { |
1070 | return wpas_ctrl_nfc_get_handover_req_p2p( | |
1071 | wpa_s, reply, max_len, ndef); | |
1072 | } | |
88853aed | 1073 | #endif /* CONFIG_P2P */ |
93588780 | 1074 | |
e65552dd JM |
1075 | return -1; |
1076 | } | |
1077 | ||
1078 | ||
1079 | static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s, | |
5ab9a6a5 | 1080 | char *reply, size_t max_len, |
f3f2ba2e | 1081 | int ndef, int cr, char *uuid) |
e65552dd JM |
1082 | { |
1083 | struct wpabuf *buf; | |
1084 | int res; | |
1085 | ||
f3f2ba2e | 1086 | buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid); |
e65552dd JM |
1087 | if (buf == NULL) |
1088 | return -1; | |
1089 | ||
1090 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1091 | wpabuf_len(buf)); | |
1092 | reply[res++] = '\n'; | |
1093 | reply[res] = '\0'; | |
1094 | ||
1095 | wpabuf_free(buf); | |
1096 | ||
1097 | return res; | |
1098 | } | |
1099 | ||
1100 | ||
88853aed | 1101 | #ifdef CONFIG_P2P |
93588780 JM |
1102 | static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s, |
1103 | char *reply, size_t max_len, | |
1104 | int ndef, int tag) | |
1105 | { | |
1106 | struct wpabuf *buf; | |
1107 | int res; | |
1108 | ||
1109 | buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag); | |
1110 | if (buf == NULL) | |
1111 | return -1; | |
1112 | ||
1113 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1114 | wpabuf_len(buf)); | |
1115 | reply[res++] = '\n'; | |
1116 | reply[res] = '\0'; | |
1117 | ||
1118 | wpabuf_free(buf); | |
1119 | ||
1120 | return res; | |
1121 | } | |
88853aed | 1122 | #endif /* CONFIG_P2P */ |
93588780 JM |
1123 | |
1124 | ||
e65552dd JM |
1125 | static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s, |
1126 | char *cmd, char *reply, | |
1127 | size_t max_len) | |
1128 | { | |
f3f2ba2e | 1129 | char *pos, *pos2; |
5ab9a6a5 | 1130 | int ndef; |
e65552dd JM |
1131 | |
1132 | pos = os_strchr(cmd, ' '); | |
1133 | if (pos == NULL) | |
1134 | return -1; | |
1135 | *pos++ = '\0'; | |
1136 | ||
5ab9a6a5 JM |
1137 | if (os_strcmp(cmd, "WPS") == 0) |
1138 | ndef = 0; | |
1139 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1140 | ndef = 1; | |
1141 | else | |
e65552dd JM |
1142 | return -1; |
1143 | ||
f3f2ba2e JM |
1144 | pos2 = os_strchr(pos, ' '); |
1145 | if (pos2) | |
1146 | *pos2++ = '\0'; | |
5ab9a6a5 | 1147 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
93588780 JM |
1148 | if (!ndef) |
1149 | return -1; | |
5ab9a6a5 JM |
1150 | return wpas_ctrl_nfc_get_handover_sel_wps( |
1151 | wpa_s, reply, max_len, ndef, | |
f3f2ba2e | 1152 | os_strcmp(pos, "WPS-CR") == 0, pos2); |
e65552dd JM |
1153 | } |
1154 | ||
88853aed | 1155 | #ifdef CONFIG_P2P |
93588780 JM |
1156 | if (os_strcmp(pos, "P2P-CR") == 0) { |
1157 | return wpas_ctrl_nfc_get_handover_sel_p2p( | |
1158 | wpa_s, reply, max_len, ndef, 0); | |
1159 | } | |
1160 | ||
1161 | if (os_strcmp(pos, "P2P-CR-TAG") == 0) { | |
1162 | return wpas_ctrl_nfc_get_handover_sel_p2p( | |
1163 | wpa_s, reply, max_len, ndef, 1); | |
1164 | } | |
88853aed | 1165 | #endif /* CONFIG_P2P */ |
93588780 | 1166 | |
e65552dd JM |
1167 | return -1; |
1168 | } | |
1169 | ||
1170 | ||
e4758827 JM |
1171 | static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s, |
1172 | char *cmd) | |
1173 | { | |
1174 | size_t len; | |
1175 | struct wpabuf *req, *sel; | |
1176 | int ret; | |
1177 | char *pos, *role, *type, *pos2; | |
88853aed | 1178 | #ifdef CONFIG_P2P |
b56f6c88 JM |
1179 | char *freq; |
1180 | int forced_freq = 0; | |
1181 | ||
1182 | freq = strstr(cmd, " freq="); | |
1183 | if (freq) { | |
1184 | *freq = '\0'; | |
1185 | freq += 6; | |
1186 | forced_freq = atoi(freq); | |
1187 | } | |
88853aed | 1188 | #endif /* CONFIG_P2P */ |
e4758827 JM |
1189 | |
1190 | role = cmd; | |
1191 | pos = os_strchr(role, ' '); | |
73127764 JM |
1192 | if (pos == NULL) { |
1193 | wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report"); | |
e4758827 | 1194 | return -1; |
73127764 | 1195 | } |
e4758827 JM |
1196 | *pos++ = '\0'; |
1197 | ||
1198 | type = pos; | |
1199 | pos = os_strchr(type, ' '); | |
73127764 JM |
1200 | if (pos == NULL) { |
1201 | wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report"); | |
e4758827 | 1202 | return -1; |
73127764 | 1203 | } |
e4758827 JM |
1204 | *pos++ = '\0'; |
1205 | ||
1206 | pos2 = os_strchr(pos, ' '); | |
73127764 JM |
1207 | if (pos2 == NULL) { |
1208 | wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report"); | |
e4758827 | 1209 | return -1; |
73127764 | 1210 | } |
e4758827 JM |
1211 | *pos2++ = '\0'; |
1212 | ||
1213 | len = os_strlen(pos); | |
73127764 JM |
1214 | if (len & 0x01) { |
1215 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report"); | |
e4758827 | 1216 | return -1; |
73127764 | 1217 | } |
e4758827 JM |
1218 | len /= 2; |
1219 | ||
1220 | req = wpabuf_alloc(len); | |
73127764 JM |
1221 | if (req == NULL) { |
1222 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message"); | |
e4758827 | 1223 | return -1; |
73127764 | 1224 | } |
e4758827 | 1225 | if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) { |
73127764 | 1226 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report"); |
e4758827 JM |
1227 | wpabuf_free(req); |
1228 | return -1; | |
1229 | } | |
1230 | ||
1231 | len = os_strlen(pos2); | |
1232 | if (len & 0x01) { | |
73127764 | 1233 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report"); |
e4758827 JM |
1234 | wpabuf_free(req); |
1235 | return -1; | |
1236 | } | |
1237 | len /= 2; | |
1238 | ||
1239 | sel = wpabuf_alloc(len); | |
1240 | if (sel == NULL) { | |
73127764 | 1241 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message"); |
e4758827 JM |
1242 | wpabuf_free(req); |
1243 | return -1; | |
1244 | } | |
1245 | if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) { | |
73127764 | 1246 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report"); |
e4758827 JM |
1247 | wpabuf_free(req); |
1248 | wpabuf_free(sel); | |
1249 | return -1; | |
1250 | } | |
1251 | ||
73127764 JM |
1252 | wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d", |
1253 | role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel)); | |
1254 | ||
e4758827 JM |
1255 | if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) { |
1256 | ret = wpas_wps_nfc_report_handover(wpa_s, req, sel); | |
88853aed | 1257 | #ifdef CONFIG_AP |
d9507936 JM |
1258 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) |
1259 | { | |
1260 | ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel); | |
50d1f890 JM |
1261 | if (ret < 0) |
1262 | ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel); | |
88853aed JM |
1263 | #endif /* CONFIG_AP */ |
1264 | #ifdef CONFIG_P2P | |
db6ae69e JM |
1265 | } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0) |
1266 | { | |
b56f6c88 | 1267 | ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0); |
db6ae69e JM |
1268 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0) |
1269 | { | |
b56f6c88 JM |
1270 | ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel, |
1271 | forced_freq); | |
88853aed | 1272 | #endif /* CONFIG_P2P */ |
e4758827 JM |
1273 | } else { |
1274 | wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover " | |
1275 | "reported: role=%s type=%s", role, type); | |
1276 | ret = -1; | |
1277 | } | |
1278 | wpabuf_free(req); | |
1279 | wpabuf_free(sel); | |
1280 | ||
73127764 JM |
1281 | if (ret) |
1282 | wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages"); | |
1283 | ||
e4758827 JM |
1284 | return ret; |
1285 | } | |
1286 | ||
71892384 | 1287 | #endif /* CONFIG_WPS_NFC */ |
46bdb83a MH |
1288 | |
1289 | ||
fcc60db4 JM |
1290 | static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s, |
1291 | char *cmd) | |
1292 | { | |
129eb428 | 1293 | u8 bssid[ETH_ALEN]; |
fcc60db4 | 1294 | char *pin; |
52eb293d JM |
1295 | char *new_ssid; |
1296 | char *new_auth; | |
1297 | char *new_encr; | |
1298 | char *new_key; | |
1299 | struct wps_new_ap_settings ap; | |
fcc60db4 JM |
1300 | |
1301 | pin = os_strchr(cmd, ' '); | |
1302 | if (pin == NULL) | |
1303 | return -1; | |
1304 | *pin++ = '\0'; | |
1305 | ||
129eb428 | 1306 | if (hwaddr_aton(cmd, bssid)) { |
fcc60db4 JM |
1307 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'", |
1308 | cmd); | |
1309 | return -1; | |
1310 | } | |
1311 | ||
52eb293d JM |
1312 | new_ssid = os_strchr(pin, ' '); |
1313 | if (new_ssid == NULL) | |
129eb428 | 1314 | return wpas_wps_start_reg(wpa_s, bssid, pin, NULL); |
52eb293d JM |
1315 | *new_ssid++ = '\0'; |
1316 | ||
1317 | new_auth = os_strchr(new_ssid, ' '); | |
1318 | if (new_auth == NULL) | |
1319 | return -1; | |
1320 | *new_auth++ = '\0'; | |
1321 | ||
1322 | new_encr = os_strchr(new_auth, ' '); | |
1323 | if (new_encr == NULL) | |
1324 | return -1; | |
1325 | *new_encr++ = '\0'; | |
1326 | ||
1327 | new_key = os_strchr(new_encr, ' '); | |
1328 | if (new_key == NULL) | |
1329 | return -1; | |
1330 | *new_key++ = '\0'; | |
1331 | ||
1332 | os_memset(&ap, 0, sizeof(ap)); | |
1333 | ap.ssid_hex = new_ssid; | |
1334 | ap.auth = new_auth; | |
1335 | ap.encr = new_encr; | |
1336 | ap.key_hex = new_key; | |
129eb428 | 1337 | return wpas_wps_start_reg(wpa_s, bssid, pin, &ap); |
fcc60db4 | 1338 | } |
72df2f5f JM |
1339 | |
1340 | ||
70d84f11 JM |
1341 | #ifdef CONFIG_AP |
1342 | static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s, | |
1343 | char *cmd, char *buf, | |
1344 | size_t buflen) | |
1345 | { | |
1346 | int timeout = 300; | |
1347 | char *pos; | |
1348 | const char *pin_txt; | |
1349 | ||
1350 | if (!wpa_s->ap_iface) | |
1351 | return -1; | |
1352 | ||
1353 | pos = os_strchr(cmd, ' '); | |
1354 | if (pos) | |
1355 | *pos++ = '\0'; | |
1356 | ||
1357 | if (os_strcmp(cmd, "disable") == 0) { | |
1358 | wpas_wps_ap_pin_disable(wpa_s); | |
1359 | return os_snprintf(buf, buflen, "OK\n"); | |
1360 | } | |
1361 | ||
1362 | if (os_strcmp(cmd, "random") == 0) { | |
1363 | if (pos) | |
1364 | timeout = atoi(pos); | |
1365 | pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout); | |
1366 | if (pin_txt == NULL) | |
1367 | return -1; | |
1368 | return os_snprintf(buf, buflen, "%s", pin_txt); | |
1369 | } | |
1370 | ||
1371 | if (os_strcmp(cmd, "get") == 0) { | |
1372 | pin_txt = wpas_wps_ap_pin_get(wpa_s); | |
1373 | if (pin_txt == NULL) | |
1374 | return -1; | |
1375 | return os_snprintf(buf, buflen, "%s", pin_txt); | |
1376 | } | |
1377 | ||
1378 | if (os_strcmp(cmd, "set") == 0) { | |
1379 | char *pin; | |
1380 | if (pos == NULL) | |
1381 | return -1; | |
1382 | pin = pos; | |
1383 | pos = os_strchr(pos, ' '); | |
1384 | if (pos) { | |
1385 | *pos++ = '\0'; | |
1386 | timeout = atoi(pos); | |
1387 | } | |
1388 | if (os_strlen(pin) > buflen) | |
1389 | return -1; | |
1390 | if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0) | |
1391 | return -1; | |
1392 | return os_snprintf(buf, buflen, "%s", pin); | |
1393 | } | |
1394 | ||
1395 | return -1; | |
1396 | } | |
1397 | #endif /* CONFIG_AP */ | |
1398 | ||
1399 | ||
72df2f5f JM |
1400 | #ifdef CONFIG_WPS_ER |
1401 | static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s, | |
1402 | char *cmd) | |
1403 | { | |
31fcea93 JM |
1404 | char *uuid = cmd, *pin, *pos; |
1405 | u8 addr_buf[ETH_ALEN], *addr = NULL; | |
72df2f5f JM |
1406 | pin = os_strchr(uuid, ' '); |
1407 | if (pin == NULL) | |
1408 | return -1; | |
1409 | *pin++ = '\0'; | |
31fcea93 JM |
1410 | pos = os_strchr(pin, ' '); |
1411 | if (pos) { | |
1412 | *pos++ = '\0'; | |
1413 | if (hwaddr_aton(pos, addr_buf) == 0) | |
1414 | addr = addr_buf; | |
1415 | } | |
1416 | return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin); | |
72df2f5f | 1417 | } |
e64dcfd5 JM |
1418 | |
1419 | ||
1420 | static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s, | |
1421 | char *cmd) | |
1422 | { | |
1423 | char *uuid = cmd, *pin; | |
1424 | pin = os_strchr(uuid, ' '); | |
1425 | if (pin == NULL) | |
1426 | return -1; | |
1427 | *pin++ = '\0'; | |
1428 | return wpas_wps_er_learn(wpa_s, uuid, pin); | |
1429 | } | |
7d6640a6 JM |
1430 | |
1431 | ||
ef10f473 JM |
1432 | static int wpa_supplicant_ctrl_iface_wps_er_set_config( |
1433 | struct wpa_supplicant *wpa_s, char *cmd) | |
1434 | { | |
1435 | char *uuid = cmd, *id; | |
1436 | id = os_strchr(uuid, ' '); | |
1437 | if (id == NULL) | |
1438 | return -1; | |
1439 | *id++ = '\0'; | |
1440 | return wpas_wps_er_set_config(wpa_s, uuid, atoi(id)); | |
1441 | } | |
1442 | ||
1443 | ||
7d6640a6 JM |
1444 | static int wpa_supplicant_ctrl_iface_wps_er_config( |
1445 | struct wpa_supplicant *wpa_s, char *cmd) | |
1446 | { | |
1447 | char *pin; | |
1448 | char *new_ssid; | |
1449 | char *new_auth; | |
1450 | char *new_encr; | |
1451 | char *new_key; | |
1452 | struct wps_new_ap_settings ap; | |
1453 | ||
1454 | pin = os_strchr(cmd, ' '); | |
1455 | if (pin == NULL) | |
1456 | return -1; | |
1457 | *pin++ = '\0'; | |
1458 | ||
1459 | new_ssid = os_strchr(pin, ' '); | |
1460 | if (new_ssid == NULL) | |
1461 | return -1; | |
1462 | *new_ssid++ = '\0'; | |
1463 | ||
1464 | new_auth = os_strchr(new_ssid, ' '); | |
1465 | if (new_auth == NULL) | |
1466 | return -1; | |
1467 | *new_auth++ = '\0'; | |
1468 | ||
1469 | new_encr = os_strchr(new_auth, ' '); | |
1470 | if (new_encr == NULL) | |
1471 | return -1; | |
1472 | *new_encr++ = '\0'; | |
1473 | ||
1474 | new_key = os_strchr(new_encr, ' '); | |
1475 | if (new_key == NULL) | |
1476 | return -1; | |
1477 | *new_key++ = '\0'; | |
1478 | ||
1479 | os_memset(&ap, 0, sizeof(ap)); | |
1480 | ap.ssid_hex = new_ssid; | |
1481 | ap.auth = new_auth; | |
1482 | ap.encr = new_encr; | |
1483 | ap.key_hex = new_key; | |
1484 | return wpas_wps_er_config(wpa_s, cmd, pin, &ap); | |
1485 | } | |
1cea09a9 JM |
1486 | |
1487 | ||
1488 | #ifdef CONFIG_WPS_NFC | |
1489 | static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | |
1490 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
1491 | { | |
1492 | int ndef; | |
1493 | struct wpabuf *buf; | |
1494 | int res; | |
1495 | char *uuid; | |
1496 | ||
1497 | uuid = os_strchr(cmd, ' '); | |
1498 | if (uuid == NULL) | |
1499 | return -1; | |
1500 | *uuid++ = '\0'; | |
1501 | ||
1502 | if (os_strcmp(cmd, "WPS") == 0) | |
1503 | ndef = 0; | |
1504 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1505 | ndef = 1; | |
1506 | else | |
1507 | return -1; | |
1508 | ||
1509 | buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid); | |
1510 | if (buf == NULL) | |
1511 | return -1; | |
1512 | ||
1513 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1514 | wpabuf_len(buf)); | |
1515 | reply[res++] = '\n'; | |
1516 | reply[res] = '\0'; | |
1517 | ||
1518 | wpabuf_free(buf); | |
1519 | ||
1520 | return res; | |
1521 | } | |
1522 | #endif /* CONFIG_WPS_NFC */ | |
72df2f5f JM |
1523 | #endif /* CONFIG_WPS_ER */ |
1524 | ||
fcc60db4 JM |
1525 | #endif /* CONFIG_WPS */ |
1526 | ||
1527 | ||
11ef8d35 JM |
1528 | #ifdef CONFIG_IBSS_RSN |
1529 | static int wpa_supplicant_ctrl_iface_ibss_rsn( | |
1530 | struct wpa_supplicant *wpa_s, char *addr) | |
1531 | { | |
1532 | u8 peer[ETH_ALEN]; | |
1533 | ||
1534 | if (hwaddr_aton(addr, peer)) { | |
1535 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid " | |
a7b6c422 | 1536 | "address '%s'", addr); |
11ef8d35 JM |
1537 | return -1; |
1538 | } | |
1539 | ||
1540 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR, | |
1541 | MAC2STR(peer)); | |
1542 | ||
1543 | return ibss_rsn_start(wpa_s->ibss_rsn, peer); | |
1544 | } | |
1545 | #endif /* CONFIG_IBSS_RSN */ | |
1546 | ||
1547 | ||
7de5688d DW |
1548 | static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, |
1549 | char *rsp) | |
1550 | { | |
1551 | #ifdef IEEE8021X_EAPOL | |
1552 | char *pos, *id_pos; | |
1553 | int id; | |
1554 | struct wpa_ssid *ssid; | |
1555 | ||
1556 | pos = os_strchr(rsp, '-'); | |
1557 | if (pos == NULL) | |
1558 | return -1; | |
1559 | *pos++ = '\0'; | |
1560 | id_pos = pos; | |
1561 | pos = os_strchr(pos, ':'); | |
1562 | if (pos == NULL) | |
1563 | return -1; | |
1564 | *pos++ = '\0'; | |
1565 | id = atoi(id_pos); | |
1566 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); | |
1567 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
1568 | (u8 *) pos, os_strlen(pos)); | |
1569 | ||
1570 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
1571 | if (ssid == NULL) { | |
1572 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
1573 | "to update", id); | |
1574 | return -1; | |
1575 | } | |
1576 | ||
1577 | return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp, | |
1578 | pos); | |
6fc6879b JM |
1579 | #else /* IEEE8021X_EAPOL */ |
1580 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); | |
1581 | return -1; | |
1582 | #endif /* IEEE8021X_EAPOL */ | |
1583 | } | |
1584 | ||
1585 | ||
1586 | static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, | |
1587 | const char *params, | |
1588 | char *buf, size_t buflen) | |
1589 | { | |
1590 | char *pos, *end, tmp[30]; | |
0bc13468 | 1591 | int res, verbose, wps, ret; |
f9cd147d JM |
1592 | #ifdef CONFIG_HS20 |
1593 | const u8 *hs20; | |
1594 | #endif /* CONFIG_HS20 */ | |
6fc6879b | 1595 | |
a771c07d JM |
1596 | if (os_strcmp(params, "-DRIVER") == 0) |
1597 | return wpa_drv_status(wpa_s, buf, buflen); | |
6fc6879b | 1598 | verbose = os_strcmp(params, "-VERBOSE") == 0; |
0bc13468 | 1599 | wps = os_strcmp(params, "-WPS") == 0; |
6fc6879b JM |
1600 | pos = buf; |
1601 | end = buf + buflen; | |
1602 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { | |
1603 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
1604 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | |
1605 | MAC2STR(wpa_s->bssid)); | |
1606 | if (ret < 0 || ret >= end - pos) | |
1607 | return pos - buf; | |
1608 | pos += ret; | |
b6ebdfbe BP |
1609 | ret = os_snprintf(pos, end - pos, "freq=%u\n", |
1610 | wpa_s->assoc_freq); | |
1611 | if (ret < 0 || ret >= end - pos) | |
1612 | return pos - buf; | |
1613 | pos += ret; | |
6fc6879b JM |
1614 | if (ssid) { |
1615 | u8 *_ssid = ssid->ssid; | |
1616 | size_t ssid_len = ssid->ssid_len; | |
1617 | u8 ssid_buf[MAX_SSID_LEN]; | |
1618 | if (ssid_len == 0) { | |
1619 | int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); | |
1620 | if (_res < 0) | |
1621 | ssid_len = 0; | |
1622 | else | |
1623 | ssid_len = _res; | |
1624 | _ssid = ssid_buf; | |
1625 | } | |
1626 | ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", | |
1627 | wpa_ssid_txt(_ssid, ssid_len), | |
1628 | ssid->id); | |
1629 | if (ret < 0 || ret >= end - pos) | |
1630 | return pos - buf; | |
1631 | pos += ret; | |
1632 | ||
0bc13468 JM |
1633 | if (wps && ssid->passphrase && |
1634 | wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && | |
1635 | (ssid->mode == WPAS_MODE_AP || | |
1636 | ssid->mode == WPAS_MODE_P2P_GO)) { | |
1637 | ret = os_snprintf(pos, end - pos, | |
1638 | "passphrase=%s\n", | |
1639 | ssid->passphrase); | |
1640 | if (ret < 0 || ret >= end - pos) | |
1641 | return pos - buf; | |
1642 | pos += ret; | |
1643 | } | |
6fc6879b JM |
1644 | if (ssid->id_str) { |
1645 | ret = os_snprintf(pos, end - pos, | |
1646 | "id_str=%s\n", | |
1647 | ssid->id_str); | |
1648 | if (ret < 0 || ret >= end - pos) | |
1649 | return pos - buf; | |
1650 | pos += ret; | |
1651 | } | |
0e15e529 JM |
1652 | |
1653 | switch (ssid->mode) { | |
d7dcba70 | 1654 | case WPAS_MODE_INFRA: |
0e15e529 JM |
1655 | ret = os_snprintf(pos, end - pos, |
1656 | "mode=station\n"); | |
1657 | break; | |
d7dcba70 | 1658 | case WPAS_MODE_IBSS: |
0e15e529 JM |
1659 | ret = os_snprintf(pos, end - pos, |
1660 | "mode=IBSS\n"); | |
1661 | break; | |
d7dcba70 | 1662 | case WPAS_MODE_AP: |
0e15e529 JM |
1663 | ret = os_snprintf(pos, end - pos, |
1664 | "mode=AP\n"); | |
1665 | break; | |
2c5d725c JM |
1666 | case WPAS_MODE_P2P_GO: |
1667 | ret = os_snprintf(pos, end - pos, | |
1668 | "mode=P2P GO\n"); | |
1669 | break; | |
1670 | case WPAS_MODE_P2P_GROUP_FORMATION: | |
1671 | ret = os_snprintf(pos, end - pos, | |
1672 | "mode=P2P GO - group " | |
1673 | "formation\n"); | |
1674 | break; | |
0e15e529 JM |
1675 | default: |
1676 | ret = 0; | |
1677 | break; | |
1678 | } | |
1679 | if (ret < 0 || ret >= end - pos) | |
1680 | return pos - buf; | |
1681 | pos += ret; | |
6fc6879b JM |
1682 | } |
1683 | ||
43fb5297 JM |
1684 | #ifdef CONFIG_AP |
1685 | if (wpa_s->ap_iface) { | |
1686 | pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos, | |
1687 | end - pos, | |
1688 | verbose); | |
1689 | } else | |
1690 | #endif /* CONFIG_AP */ | |
6fc6879b JM |
1691 | pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); |
1692 | } | |
4954c859 JM |
1693 | #ifdef CONFIG_SAE |
1694 | if (wpa_s->wpa_state >= WPA_ASSOCIATED && | |
e1ae5d74 JM |
1695 | #ifdef CONFIG_AP |
1696 | !wpa_s->ap_iface && | |
1697 | #endif /* CONFIG_AP */ | |
1698 | wpa_s->sme.sae.state == SAE_ACCEPTED) { | |
4954c859 JM |
1699 | ret = os_snprintf(pos, end - pos, "sae_group=%d\n", |
1700 | wpa_s->sme.sae.group); | |
1701 | if (ret < 0 || ret >= end - pos) | |
1702 | return pos - buf; | |
1703 | pos += ret; | |
1704 | } | |
1705 | #endif /* CONFIG_SAE */ | |
6fc6879b JM |
1706 | ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", |
1707 | wpa_supplicant_state_txt(wpa_s->wpa_state)); | |
1708 | if (ret < 0 || ret >= end - pos) | |
1709 | return pos - buf; | |
1710 | pos += ret; | |
1711 | ||
1712 | if (wpa_s->l2 && | |
1713 | l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { | |
1714 | ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); | |
1715 | if (ret < 0 || ret >= end - pos) | |
1716 | return pos - buf; | |
1717 | pos += ret; | |
1718 | } | |
1719 | ||
d23bd894 JM |
1720 | #ifdef CONFIG_P2P |
1721 | if (wpa_s->global->p2p) { | |
1722 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR | |
1723 | "\n", MAC2STR(wpa_s->global->p2p_dev_addr)); | |
1724 | if (ret < 0 || ret >= end - pos) | |
1725 | return pos - buf; | |
1726 | pos += ret; | |
1727 | } | |
b21e2c84 | 1728 | #endif /* CONFIG_P2P */ |
6d4747a9 JM |
1729 | |
1730 | ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n", | |
1731 | MAC2STR(wpa_s->own_addr)); | |
1732 | if (ret < 0 || ret >= end - pos) | |
1733 | return pos - buf; | |
1734 | pos += ret; | |
d23bd894 | 1735 | |
64855b96 JM |
1736 | #ifdef CONFIG_HS20 |
1737 | if (wpa_s->current_bss && | |
f9cd147d JM |
1738 | (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss, |
1739 | HS20_IE_VENDOR_TYPE)) && | |
4ed34f5a JM |
1740 | wpa_s->wpa_proto == WPA_PROTO_RSN && |
1741 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | |
f9cd147d JM |
1742 | int release = 1; |
1743 | if (hs20[1] >= 5) { | |
1744 | u8 rel_num = (hs20[6] & 0xf0) >> 4; | |
1745 | release = rel_num + 1; | |
1746 | } | |
1747 | ret = os_snprintf(pos, end - pos, "hs20=%d\n", release); | |
64855b96 JM |
1748 | if (ret < 0 || ret >= end - pos) |
1749 | return pos - buf; | |
1750 | pos += ret; | |
1751 | } | |
e99b4f3a JM |
1752 | |
1753 | if (wpa_s->current_ssid) { | |
1754 | struct wpa_cred *cred; | |
1755 | char *type; | |
1756 | ||
1757 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { | |
463c8ffb JM |
1758 | size_t i; |
1759 | ||
e99b4f3a JM |
1760 | if (wpa_s->current_ssid->parent_cred != cred) |
1761 | continue; | |
e99b4f3a | 1762 | |
aa26ba68 | 1763 | if (cred->provisioning_sp) { |
463c8ffb | 1764 | ret = os_snprintf(pos, end - pos, |
aa26ba68 JM |
1765 | "provisioning_sp=%s\n", |
1766 | cred->provisioning_sp); | |
463c8ffb JM |
1767 | if (ret < 0 || ret >= end - pos) |
1768 | return pos - buf; | |
1769 | pos += ret; | |
1770 | } | |
e99b4f3a | 1771 | |
aa26ba68 JM |
1772 | if (!cred->domain) |
1773 | goto no_domain; | |
1774 | ||
1775 | i = 0; | |
1776 | if (wpa_s->current_bss && wpa_s->current_bss->anqp) { | |
1777 | struct wpabuf *names = | |
1778 | wpa_s->current_bss->anqp->domain_name; | |
1779 | for (i = 0; names && i < cred->num_domain; i++) | |
1780 | { | |
1781 | if (domain_name_list_contains( | |
1782 | names, cred->domain[i], 1)) | |
1783 | break; | |
1784 | } | |
1785 | if (i == cred->num_domain) | |
1786 | i = 0; /* show first entry by default */ | |
1787 | } | |
1788 | ret = os_snprintf(pos, end - pos, "home_sp=%s\n", | |
1789 | cred->domain[i]); | |
1790 | if (ret < 0 || ret >= end - pos) | |
1791 | return pos - buf; | |
1792 | pos += ret; | |
1793 | ||
1794 | no_domain: | |
e99b4f3a JM |
1795 | if (wpa_s->current_bss == NULL || |
1796 | wpa_s->current_bss->anqp == NULL) | |
1797 | res = -1; | |
1798 | else | |
1799 | res = interworking_home_sp_cred( | |
1800 | wpa_s, cred, | |
1801 | wpa_s->current_bss->anqp->domain_name); | |
1802 | if (res > 0) | |
1803 | type = "home"; | |
1804 | else if (res == 0) | |
1805 | type = "roaming"; | |
1806 | else | |
1807 | type = "unknown"; | |
1808 | ||
1809 | ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type); | |
1810 | if (ret < 0 || ret >= end - pos) | |
1811 | return pos - buf; | |
1812 | pos += ret; | |
1813 | ||
1814 | break; | |
1815 | } | |
1816 | } | |
64855b96 JM |
1817 | #endif /* CONFIG_HS20 */ |
1818 | ||
56586197 JM |
1819 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
1820 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
6fc6879b JM |
1821 | res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, |
1822 | verbose); | |
1823 | if (res >= 0) | |
1824 | pos += res; | |
1825 | } | |
1826 | ||
1827 | res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); | |
1828 | if (res >= 0) | |
1829 | pos += res; | |
1830 | ||
8aaafcee JM |
1831 | #ifdef CONFIG_WPS |
1832 | { | |
1833 | char uuid_str[100]; | |
1834 | uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str)); | |
1835 | ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str); | |
1836 | if (ret < 0 || ret >= end - pos) | |
1837 | return pos - buf; | |
1838 | pos += ret; | |
1839 | } | |
1840 | #endif /* CONFIG_WPS */ | |
1841 | ||
f6c2b8c3 | 1842 | #ifdef ANDROID |
a6ab82d7 | 1843 | /* |
1844 | * Allow using the STATUS command with default behavior, say for debug, | |
1845 | * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE | |
1846 | * events with STATUS-NO_EVENTS. | |
1847 | */ | |
1848 | if (os_strcmp(params, "-NO_EVENTS")) { | |
1849 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE | |
1850 | "id=%d state=%d BSSID=" MACSTR " SSID=%s", | |
1851 | wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, | |
1852 | wpa_s->wpa_state, | |
1853 | MAC2STR(wpa_s->bssid), | |
1854 | wpa_s->current_ssid && wpa_s->current_ssid->ssid ? | |
1855 | wpa_ssid_txt(wpa_s->current_ssid->ssid, | |
1856 | wpa_s->current_ssid->ssid_len) : ""); | |
1857 | if (wpa_s->wpa_state == WPA_COMPLETED) { | |
1858 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
1859 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED | |
1860 | "- connection to " MACSTR | |
1861 | " completed %s [id=%d id_str=%s]", | |
1862 | MAC2STR(wpa_s->bssid), "(auth)", | |
1863 | ssid ? ssid->id : -1, | |
1864 | ssid && ssid->id_str ? ssid->id_str : ""); | |
1865 | } | |
f6c2b8c3 DS |
1866 | } |
1867 | #endif /* ANDROID */ | |
1868 | ||
6fc6879b JM |
1869 | return pos - buf; |
1870 | } | |
1871 | ||
1872 | ||
1873 | static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, | |
1874 | char *cmd) | |
1875 | { | |
1876 | char *pos; | |
1877 | int id; | |
1878 | struct wpa_ssid *ssid; | |
1879 | u8 bssid[ETH_ALEN]; | |
1880 | ||
1881 | /* cmd: "<network id> <BSSID>" */ | |
1882 | pos = os_strchr(cmd, ' '); | |
1883 | if (pos == NULL) | |
1884 | return -1; | |
1885 | *pos++ = '\0'; | |
1886 | id = atoi(cmd); | |
1887 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); | |
1888 | if (hwaddr_aton(pos, bssid)) { | |
1889 | wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); | |
1890 | return -1; | |
1891 | } | |
1892 | ||
1893 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
1894 | if (ssid == NULL) { | |
1895 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
1896 | "to update", id); | |
1897 | return -1; | |
1898 | } | |
1899 | ||
1900 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); | |
a8e16edc | 1901 | ssid->bssid_set = !is_zero_ether_addr(bssid); |
6fc6879b JM |
1902 | |
1903 | return 0; | |
1904 | } | |
1905 | ||
1906 | ||
9aa10e2b DS |
1907 | static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s, |
1908 | char *cmd, char *buf, | |
1909 | size_t buflen) | |
1910 | { | |
1911 | u8 bssid[ETH_ALEN]; | |
1912 | struct wpa_blacklist *e; | |
1913 | char *pos, *end; | |
1914 | int ret; | |
1915 | ||
1916 | /* cmd: "BLACKLIST [<BSSID>]" */ | |
1917 | if (*cmd == '\0') { | |
1918 | pos = buf; | |
1919 | end = buf + buflen; | |
1920 | e = wpa_s->blacklist; | |
1921 | while (e) { | |
1922 | ret = os_snprintf(pos, end - pos, MACSTR "\n", | |
1923 | MAC2STR(e->bssid)); | |
1924 | if (ret < 0 || ret >= end - pos) | |
1925 | return pos - buf; | |
1926 | pos += ret; | |
1927 | e = e->next; | |
1928 | } | |
1929 | return pos - buf; | |
1930 | } | |
1931 | ||
1932 | cmd++; | |
1933 | if (os_strncmp(cmd, "clear", 5) == 0) { | |
1934 | wpa_blacklist_clear(wpa_s); | |
1935 | os_memcpy(buf, "OK\n", 3); | |
1936 | return 3; | |
1937 | } | |
1938 | ||
1939 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd); | |
1940 | if (hwaddr_aton(cmd, bssid)) { | |
1941 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd); | |
1942 | return -1; | |
1943 | } | |
1944 | ||
1945 | /* | |
1946 | * Add the BSSID twice, so its count will be 2, causing it to be | |
1947 | * skipped when processing scan results. | |
1948 | */ | |
1949 | ret = wpa_blacklist_add(wpa_s, bssid); | |
bd8838a3 | 1950 | if (ret < 0) |
9aa10e2b DS |
1951 | return -1; |
1952 | ret = wpa_blacklist_add(wpa_s, bssid); | |
bd8838a3 | 1953 | if (ret < 0) |
9aa10e2b DS |
1954 | return -1; |
1955 | os_memcpy(buf, "OK\n", 3); | |
1956 | return 3; | |
1957 | } | |
1958 | ||
1959 | ||
0597a5b5 DS |
1960 | static const char * debug_level_str(int level) |
1961 | { | |
1962 | switch (level) { | |
1963 | case MSG_EXCESSIVE: | |
1964 | return "EXCESSIVE"; | |
1965 | case MSG_MSGDUMP: | |
1966 | return "MSGDUMP"; | |
1967 | case MSG_DEBUG: | |
1968 | return "DEBUG"; | |
1969 | case MSG_INFO: | |
1970 | return "INFO"; | |
1971 | case MSG_WARNING: | |
1972 | return "WARNING"; | |
1973 | case MSG_ERROR: | |
1974 | return "ERROR"; | |
1975 | default: | |
1976 | return "?"; | |
1977 | } | |
1978 | } | |
1979 | ||
1980 | ||
1981 | static int str_to_debug_level(const char *s) | |
1982 | { | |
1983 | if (os_strcasecmp(s, "EXCESSIVE") == 0) | |
1984 | return MSG_EXCESSIVE; | |
1985 | if (os_strcasecmp(s, "MSGDUMP") == 0) | |
1986 | return MSG_MSGDUMP; | |
1987 | if (os_strcasecmp(s, "DEBUG") == 0) | |
1988 | return MSG_DEBUG; | |
1989 | if (os_strcasecmp(s, "INFO") == 0) | |
1990 | return MSG_INFO; | |
1991 | if (os_strcasecmp(s, "WARNING") == 0) | |
1992 | return MSG_WARNING; | |
1993 | if (os_strcasecmp(s, "ERROR") == 0) | |
1994 | return MSG_ERROR; | |
1995 | return -1; | |
1996 | } | |
1997 | ||
1998 | ||
1999 | static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s, | |
2000 | char *cmd, char *buf, | |
2001 | size_t buflen) | |
2002 | { | |
2003 | char *pos, *end, *stamp; | |
2004 | int ret; | |
2005 | ||
2006 | if (cmd == NULL) { | |
2007 | return -1; | |
2008 | } | |
2009 | ||
2010 | /* cmd: "LOG_LEVEL [<level>]" */ | |
2011 | if (*cmd == '\0') { | |
2012 | pos = buf; | |
2013 | end = buf + buflen; | |
2014 | ret = os_snprintf(pos, end - pos, "Current level: %s\n" | |
2015 | "Timestamp: %d\n", | |
2016 | debug_level_str(wpa_debug_level), | |
2017 | wpa_debug_timestamp); | |
2018 | if (ret < 0 || ret >= end - pos) | |
2019 | ret = 0; | |
2020 | ||
2021 | return ret; | |
2022 | } | |
2023 | ||
2024 | while (*cmd == ' ') | |
2025 | cmd++; | |
2026 | ||
2027 | stamp = os_strchr(cmd, ' '); | |
2028 | if (stamp) { | |
2029 | *stamp++ = '\0'; | |
2030 | while (*stamp == ' ') { | |
2031 | stamp++; | |
2032 | } | |
2033 | } | |
2034 | ||
2035 | if (cmd && os_strlen(cmd)) { | |
2036 | int level = str_to_debug_level(cmd); | |
2037 | if (level < 0) | |
2038 | return -1; | |
2039 | wpa_debug_level = level; | |
2040 | } | |
2041 | ||
2042 | if (stamp && os_strlen(stamp)) | |
2043 | wpa_debug_timestamp = atoi(stamp); | |
2044 | ||
2045 | os_memcpy(buf, "OK\n", 3); | |
2046 | return 3; | |
2047 | } | |
2048 | ||
2049 | ||
6fc6879b | 2050 | static int wpa_supplicant_ctrl_iface_list_networks( |
90903a77 | 2051 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
6fc6879b JM |
2052 | { |
2053 | char *pos, *end; | |
2054 | struct wpa_ssid *ssid; | |
2055 | int ret; | |
2056 | ||
2057 | pos = buf; | |
2058 | end = buf + buflen; | |
2059 | ret = os_snprintf(pos, end - pos, | |
2060 | "network id / ssid / bssid / flags\n"); | |
2061 | if (ret < 0 || ret >= end - pos) | |
2062 | return pos - buf; | |
2063 | pos += ret; | |
2064 | ||
2065 | ssid = wpa_s->conf->ssid; | |
90903a77 VD |
2066 | |
2067 | /* skip over ssids until we find next one */ | |
2068 | if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) { | |
2069 | int last_id = atoi(cmd + 8); | |
2070 | if (last_id != -1) { | |
2071 | while (ssid != NULL && ssid->id <= last_id) { | |
2072 | ssid = ssid->next; | |
2073 | } | |
2074 | } | |
2075 | } | |
2076 | ||
6fc6879b JM |
2077 | while (ssid) { |
2078 | ret = os_snprintf(pos, end - pos, "%d\t%s", | |
2079 | ssid->id, | |
2080 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | |
2081 | if (ret < 0 || ret >= end - pos) | |
2082 | return pos - buf; | |
2083 | pos += ret; | |
2084 | if (ssid->bssid_set) { | |
2085 | ret = os_snprintf(pos, end - pos, "\t" MACSTR, | |
2086 | MAC2STR(ssid->bssid)); | |
2087 | } else { | |
2088 | ret = os_snprintf(pos, end - pos, "\tany"); | |
2089 | } | |
2090 | if (ret < 0 || ret >= end - pos) | |
2091 | return pos - buf; | |
2092 | pos += ret; | |
00e5e3d5 | 2093 | ret = os_snprintf(pos, end - pos, "\t%s%s%s%s", |
6fc6879b JM |
2094 | ssid == wpa_s->current_ssid ? |
2095 | "[CURRENT]" : "", | |
4dac0245 | 2096 | ssid->disabled ? "[DISABLED]" : "", |
00e5e3d5 JM |
2097 | ssid->disabled_until.sec ? |
2098 | "[TEMP-DISABLED]" : "", | |
4dac0245 JM |
2099 | ssid->disabled == 2 ? "[P2P-PERSISTENT]" : |
2100 | ""); | |
6fc6879b JM |
2101 | if (ret < 0 || ret >= end - pos) |
2102 | return pos - buf; | |
2103 | pos += ret; | |
2104 | ret = os_snprintf(pos, end - pos, "\n"); | |
2105 | if (ret < 0 || ret >= end - pos) | |
2106 | return pos - buf; | |
2107 | pos += ret; | |
2108 | ||
2109 | ssid = ssid->next; | |
2110 | } | |
2111 | ||
2112 | return pos - buf; | |
2113 | } | |
2114 | ||
2115 | ||
2116 | static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) | |
2117 | { | |
0282a8c4 | 2118 | int ret; |
6fc6879b JM |
2119 | ret = os_snprintf(pos, end - pos, "-"); |
2120 | if (ret < 0 || ret >= end - pos) | |
2121 | return pos; | |
2122 | pos += ret; | |
0282a8c4 JM |
2123 | ret = wpa_write_ciphers(pos, end, cipher, "+"); |
2124 | if (ret < 0) | |
2125 | return pos; | |
2126 | pos += ret; | |
6fc6879b JM |
2127 | return pos; |
2128 | } | |
2129 | ||
2130 | ||
2131 | static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, | |
2132 | const u8 *ie, size_t ie_len) | |
2133 | { | |
2134 | struct wpa_ie_data data; | |
ea3b8c1d JM |
2135 | char *start; |
2136 | int ret; | |
6fc6879b JM |
2137 | |
2138 | ret = os_snprintf(pos, end - pos, "[%s-", proto); | |
2139 | if (ret < 0 || ret >= end - pos) | |
2140 | return pos; | |
2141 | pos += ret; | |
2142 | ||
2143 | if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { | |
2144 | ret = os_snprintf(pos, end - pos, "?]"); | |
2145 | if (ret < 0 || ret >= end - pos) | |
2146 | return pos; | |
2147 | pos += ret; | |
2148 | return pos; | |
2149 | } | |
2150 | ||
ea3b8c1d | 2151 | start = pos; |
6fc6879b | 2152 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { |
ea3b8c1d JM |
2153 | ret = os_snprintf(pos, end - pos, "%sEAP", |
2154 | pos == start ? "" : "+"); | |
6fc6879b JM |
2155 | if (ret < 0 || ret >= end - pos) |
2156 | return pos; | |
2157 | pos += ret; | |
6fc6879b JM |
2158 | } |
2159 | if (data.key_mgmt & WPA_KEY_MGMT_PSK) { | |
ea3b8c1d JM |
2160 | ret = os_snprintf(pos, end - pos, "%sPSK", |
2161 | pos == start ? "" : "+"); | |
6fc6879b JM |
2162 | if (ret < 0 || ret >= end - pos) |
2163 | return pos; | |
2164 | pos += ret; | |
6fc6879b JM |
2165 | } |
2166 | if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { | |
ea3b8c1d JM |
2167 | ret = os_snprintf(pos, end - pos, "%sNone", |
2168 | pos == start ? "" : "+"); | |
6fc6879b JM |
2169 | if (ret < 0 || ret >= end - pos) |
2170 | return pos; | |
2171 | pos += ret; | |
6fc6879b | 2172 | } |
be6b29f6 JA |
2173 | if (data.key_mgmt & WPA_KEY_MGMT_SAE) { |
2174 | ret = os_snprintf(pos, end - pos, "%sSAE", | |
2175 | pos == start ? "" : "+"); | |
2176 | if (ret < 0 || ret >= end - pos) | |
2177 | return pos; | |
2178 | pos += ret; | |
2179 | } | |
6fc6879b JM |
2180 | #ifdef CONFIG_IEEE80211R |
2181 | if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { | |
2182 | ret = os_snprintf(pos, end - pos, "%sFT/EAP", | |
ea3b8c1d | 2183 | pos == start ? "" : "+"); |
6fc6879b JM |
2184 | if (ret < 0 || ret >= end - pos) |
2185 | return pos; | |
2186 | pos += ret; | |
6fc6879b JM |
2187 | } |
2188 | if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { | |
2189 | ret = os_snprintf(pos, end - pos, "%sFT/PSK", | |
ea3b8c1d | 2190 | pos == start ? "" : "+"); |
6fc6879b JM |
2191 | if (ret < 0 || ret >= end - pos) |
2192 | return pos; | |
2193 | pos += ret; | |
6fc6879b | 2194 | } |
be6b29f6 JA |
2195 | if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) { |
2196 | ret = os_snprintf(pos, end - pos, "%sFT/SAE", | |
2197 | pos == start ? "" : "+"); | |
2198 | if (ret < 0 || ret >= end - pos) | |
2199 | return pos; | |
2200 | pos += ret; | |
2201 | } | |
6fc6879b | 2202 | #endif /* CONFIG_IEEE80211R */ |
56586197 JM |
2203 | #ifdef CONFIG_IEEE80211W |
2204 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { | |
2205 | ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", | |
ea3b8c1d | 2206 | pos == start ? "" : "+"); |
56586197 JM |
2207 | if (ret < 0 || ret >= end - pos) |
2208 | return pos; | |
2209 | pos += ret; | |
56586197 JM |
2210 | } |
2211 | if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { | |
2212 | ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", | |
ea3b8c1d | 2213 | pos == start ? "" : "+"); |
56586197 JM |
2214 | if (ret < 0 || ret >= end - pos) |
2215 | return pos; | |
2216 | pos += ret; | |
56586197 JM |
2217 | } |
2218 | #endif /* CONFIG_IEEE80211W */ | |
6fc6879b | 2219 | |
666497c8 JM |
2220 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
2221 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B", | |
2222 | pos == start ? "" : "+"); | |
2223 | if (ret < 0 || ret >= end - pos) | |
2224 | return pos; | |
2225 | pos += ret; | |
2226 | } | |
2227 | ||
6fc6879b JM |
2228 | pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); |
2229 | ||
2230 | if (data.capabilities & WPA_CAPABILITY_PREAUTH) { | |
2231 | ret = os_snprintf(pos, end - pos, "-preauth"); | |
2232 | if (ret < 0 || ret >= end - pos) | |
2233 | return pos; | |
2234 | pos += ret; | |
2235 | } | |
2236 | ||
2237 | ret = os_snprintf(pos, end - pos, "]"); | |
2238 | if (ret < 0 || ret >= end - pos) | |
2239 | return pos; | |
2240 | pos += ret; | |
2241 | ||
2242 | return pos; | |
2243 | } | |
2244 | ||
3a068632 | 2245 | |
eef7d7a1 | 2246 | #ifdef CONFIG_WPS |
31fcea93 JM |
2247 | static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, |
2248 | char *pos, char *end, | |
3a068632 JM |
2249 | struct wpabuf *wps_ie) |
2250 | { | |
eef7d7a1 JM |
2251 | int ret; |
2252 | const char *txt; | |
2253 | ||
eef7d7a1 JM |
2254 | if (wps_ie == NULL) |
2255 | return pos; | |
eef7d7a1 JM |
2256 | if (wps_is_selected_pbc_registrar(wps_ie)) |
2257 | txt = "[WPS-PBC]"; | |
31fcea93 JM |
2258 | else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) |
2259 | txt = "[WPS-AUTH]"; | |
eef7d7a1 JM |
2260 | else if (wps_is_selected_pin_registrar(wps_ie)) |
2261 | txt = "[WPS-PIN]"; | |
2262 | else | |
2263 | txt = "[WPS]"; | |
2264 | ||
2265 | ret = os_snprintf(pos, end - pos, "%s", txt); | |
2266 | if (ret >= 0 && ret < end - pos) | |
2267 | pos += ret; | |
2268 | wpabuf_free(wps_ie); | |
3a068632 JM |
2269 | return pos; |
2270 | } | |
2271 | #endif /* CONFIG_WPS */ | |
2272 | ||
2273 | ||
31fcea93 JM |
2274 | static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, |
2275 | char *pos, char *end, | |
16b71ac2 | 2276 | const struct wpa_bss *bss) |
3a068632 JM |
2277 | { |
2278 | #ifdef CONFIG_WPS | |
2279 | struct wpabuf *wps_ie; | |
2280 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); | |
31fcea93 | 2281 | return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); |
3a068632 | 2282 | #else /* CONFIG_WPS */ |
eef7d7a1 | 2283 | return pos; |
3a068632 | 2284 | #endif /* CONFIG_WPS */ |
eef7d7a1 JM |
2285 | } |
2286 | ||
6fc6879b JM |
2287 | |
2288 | /* Format one result on one text line into a buffer. */ | |
2289 | static int wpa_supplicant_ctrl_iface_scan_result( | |
31fcea93 | 2290 | struct wpa_supplicant *wpa_s, |
16b71ac2 | 2291 | const struct wpa_bss *bss, char *buf, size_t buflen) |
6fc6879b JM |
2292 | { |
2293 | char *pos, *end; | |
2294 | int ret; | |
638d9456 | 2295 | const u8 *ie, *ie2, *p2p, *mesh; |
0c6b310e | 2296 | |
638d9456 | 2297 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
0c6b310e | 2298 | p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); |
bb50ae43 JM |
2299 | if (!p2p) |
2300 | p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE); | |
0c6b310e JM |
2301 | if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && |
2302 | os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == | |
2303 | 0) | |
2304 | return 0; /* Do not show P2P listen discovery results here */ | |
6fc6879b JM |
2305 | |
2306 | pos = buf; | |
2307 | end = buf + buflen; | |
2308 | ||
2309 | ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", | |
16b71ac2 | 2310 | MAC2STR(bss->bssid), bss->freq, bss->level); |
6fc6879b | 2311 | if (ret < 0 || ret >= end - pos) |
fb0e5bd7 | 2312 | return -1; |
6fc6879b | 2313 | pos += ret; |
16b71ac2 | 2314 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
6fc6879b JM |
2315 | if (ie) |
2316 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); | |
16b71ac2 | 2317 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
638d9456 JA |
2318 | if (ie2) { |
2319 | pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2", | |
2320 | ie2, 2 + ie2[1]); | |
2321 | } | |
31fcea93 | 2322 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
16b71ac2 | 2323 | if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) { |
6fc6879b JM |
2324 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
2325 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 2326 | return -1; |
6fc6879b JM |
2327 | pos += ret; |
2328 | } | |
638d9456 JA |
2329 | if (mesh) { |
2330 | ret = os_snprintf(pos, end - pos, "[MESH]"); | |
2331 | if (ret < 0 || ret >= end - pos) | |
2332 | return -1; | |
2333 | pos += ret; | |
2334 | } | |
e403ba85 BS |
2335 | if (bss_is_dmg(bss)) { |
2336 | const char *s; | |
2337 | ret = os_snprintf(pos, end - pos, "[DMG]"); | |
6fc6879b | 2338 | if (ret < 0 || ret >= end - pos) |
fb0e5bd7 | 2339 | return -1; |
6fc6879b | 2340 | pos += ret; |
e403ba85 BS |
2341 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
2342 | case IEEE80211_CAP_DMG_IBSS: | |
2343 | s = "[IBSS]"; | |
2344 | break; | |
2345 | case IEEE80211_CAP_DMG_AP: | |
2346 | s = "[ESS]"; | |
2347 | break; | |
2348 | case IEEE80211_CAP_DMG_PBSS: | |
2349 | s = "[PBSS]"; | |
2350 | break; | |
2351 | default: | |
2352 | s = ""; | |
2353 | break; | |
2354 | } | |
2355 | ret = os_snprintf(pos, end - pos, "%s", s); | |
bd1af96a | 2356 | if (ret < 0 || ret >= end - pos) |
fb0e5bd7 | 2357 | return -1; |
bd1af96a | 2358 | pos += ret; |
e403ba85 BS |
2359 | } else { |
2360 | if (bss->caps & IEEE80211_CAP_IBSS) { | |
2361 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | |
2362 | if (ret < 0 || ret >= end - pos) | |
2363 | return -1; | |
2364 | pos += ret; | |
2365 | } | |
2366 | if (bss->caps & IEEE80211_CAP_ESS) { | |
2367 | ret = os_snprintf(pos, end - pos, "[ESS]"); | |
2368 | if (ret < 0 || ret >= end - pos) | |
2369 | return -1; | |
2370 | pos += ret; | |
2371 | } | |
bd1af96a | 2372 | } |
0c6b310e JM |
2373 | if (p2p) { |
2374 | ret = os_snprintf(pos, end - pos, "[P2P]"); | |
2375 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 2376 | return -1; |
0c6b310e JM |
2377 | pos += ret; |
2378 | } | |
64855b96 | 2379 | #ifdef CONFIG_HS20 |
4ed34f5a | 2380 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) { |
64855b96 JM |
2381 | ret = os_snprintf(pos, end - pos, "[HS20]"); |
2382 | if (ret < 0 || ret >= end - pos) | |
2383 | return -1; | |
2384 | pos += ret; | |
2385 | } | |
2386 | #endif /* CONFIG_HS20 */ | |
6fc6879b | 2387 | |
6fc6879b | 2388 | ret = os_snprintf(pos, end - pos, "\t%s", |
16b71ac2 | 2389 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
6fc6879b | 2390 | if (ret < 0 || ret >= end - pos) |
fb0e5bd7 | 2391 | return -1; |
6fc6879b JM |
2392 | pos += ret; |
2393 | ||
2394 | ret = os_snprintf(pos, end - pos, "\n"); | |
2395 | if (ret < 0 || ret >= end - pos) | |
fb0e5bd7 | 2396 | return -1; |
6fc6879b JM |
2397 | pos += ret; |
2398 | ||
2399 | return pos - buf; | |
2400 | } | |
2401 | ||
2402 | ||
2403 | static int wpa_supplicant_ctrl_iface_scan_results( | |
2404 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
2405 | { | |
2406 | char *pos, *end; | |
16b71ac2 | 2407 | struct wpa_bss *bss; |
6fc6879b | 2408 | int ret; |
6fc6879b JM |
2409 | |
2410 | pos = buf; | |
2411 | end = buf + buflen; | |
2412 | ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " | |
2413 | "flags / ssid\n"); | |
2414 | if (ret < 0 || ret >= end - pos) | |
2415 | return pos - buf; | |
2416 | pos += ret; | |
2417 | ||
16b71ac2 | 2418 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
31fcea93 | 2419 | ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, |
6fc6879b JM |
2420 | end - pos); |
2421 | if (ret < 0 || ret >= end - pos) | |
2422 | return pos - buf; | |
2423 | pos += ret; | |
2424 | } | |
2425 | ||
2426 | return pos - buf; | |
2427 | } | |
2428 | ||
2429 | ||
603a3f34 JL |
2430 | #ifdef CONFIG_MESH |
2431 | ||
2432 | static int wpa_supplicant_ctrl_iface_mesh_group_add( | |
2433 | struct wpa_supplicant *wpa_s, char *cmd) | |
2434 | { | |
2435 | int id; | |
2436 | struct wpa_ssid *ssid; | |
2437 | ||
2438 | id = atoi(cmd); | |
2439 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id); | |
2440 | ||
2441 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
2442 | if (ssid == NULL) { | |
2443 | wpa_printf(MSG_DEBUG, | |
2444 | "CTRL_IFACE: Could not find network id=%d", id); | |
2445 | return -1; | |
2446 | } | |
2447 | if (ssid->mode != WPAS_MODE_MESH) { | |
2448 | wpa_printf(MSG_DEBUG, | |
2449 | "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network"); | |
2450 | return -1; | |
2451 | } | |
0c6099f3 MH |
2452 | if (ssid->key_mgmt != WPA_KEY_MGMT_NONE && |
2453 | ssid->key_mgmt != WPA_KEY_MGMT_SAE) { | |
2454 | wpa_printf(MSG_ERROR, | |
2455 | "CTRL_IFACE: key_mgmt for mesh network should be open or SAE"); | |
2456 | return -1; | |
2457 | } | |
603a3f34 JL |
2458 | |
2459 | /* | |
2460 | * TODO: If necessary write our own group_add function, | |
2461 | * for now we can reuse select_network | |
2462 | */ | |
2463 | wpa_supplicant_select_network(wpa_s, ssid); | |
2464 | ||
2465 | return 0; | |
2466 | } | |
2467 | ||
2468 | ||
2469 | static int wpa_supplicant_ctrl_iface_mesh_group_remove( | |
2470 | struct wpa_supplicant *wpa_s, char *cmd) | |
2471 | { | |
2472 | if (!cmd) { | |
2473 | wpa_printf(MSG_ERROR, | |
2474 | "CTRL_IFACE: MESH_GROUP_REMOVE ifname cannot be empty"); | |
2475 | return -1; | |
2476 | } | |
2477 | ||
2478 | /* | |
2479 | * TODO: Support a multiple mesh and other iface type combinations | |
2480 | */ | |
2481 | if (os_strcmp(cmd, wpa_s->ifname) != 0) { | |
2482 | wpa_printf(MSG_DEBUG, | |
2483 | "CTRL_IFACE: MESH_GROUP_REMOVE unknown interface name: %s", | |
2484 | cmd); | |
2485 | return -1; | |
2486 | } | |
2487 | ||
2488 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd); | |
2489 | ||
2490 | wpa_s->reassociate = 0; | |
2491 | wpa_s->disconnected = 1; | |
2492 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
2493 | wpa_supplicant_cancel_scan(wpa_s); | |
2494 | ||
2495 | /* | |
2496 | * TODO: If necessary write our own group_remove function, | |
2497 | * for now we can reuse deauthenticate | |
2498 | */ | |
2499 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
2500 | ||
2501 | return 0; | |
2502 | } | |
2503 | ||
2504 | #endif /* CONFIG_MESH */ | |
2505 | ||
2506 | ||
6fc6879b JM |
2507 | static int wpa_supplicant_ctrl_iface_select_network( |
2508 | struct wpa_supplicant *wpa_s, char *cmd) | |
2509 | { | |
2510 | int id; | |
2511 | struct wpa_ssid *ssid; | |
204c9ac4 | 2512 | char *pos; |
6fc6879b JM |
2513 | |
2514 | /* cmd: "<network id>" or "any" */ | |
204c9ac4 | 2515 | if (os_strncmp(cmd, "any", 3) == 0) { |
6fc6879b | 2516 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); |
86b89452 WS |
2517 | ssid = NULL; |
2518 | } else { | |
2519 | id = atoi(cmd); | |
2520 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); | |
6fc6879b | 2521 | |
86b89452 WS |
2522 | ssid = wpa_config_get_network(wpa_s->conf, id); |
2523 | if (ssid == NULL) { | |
2524 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
2525 | "network id=%d", id); | |
2526 | return -1; | |
2527 | } | |
4dac0245 JM |
2528 | if (ssid->disabled == 2) { |
2529 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
2530 | "SELECT_NETWORK with persistent P2P group"); | |
2531 | return -1; | |
2532 | } | |
6fc6879b JM |
2533 | } |
2534 | ||
204c9ac4 DS |
2535 | pos = os_strstr(cmd, " freq="); |
2536 | if (pos) { | |
2537 | int *freqs = freq_range_to_channel_list(wpa_s, pos + 6); | |
2538 | if (freqs) { | |
2539 | wpa_s->scan_req = MANUAL_SCAN_REQ; | |
2540 | os_free(wpa_s->manual_scan_freqs); | |
2541 | wpa_s->manual_scan_freqs = freqs; | |
2542 | } | |
2543 | } | |
2544 | ||
86b89452 | 2545 | wpa_supplicant_select_network(wpa_s, ssid); |
6fc6879b JM |
2546 | |
2547 | return 0; | |
2548 | } | |
2549 | ||
2550 | ||
2551 | static int wpa_supplicant_ctrl_iface_enable_network( | |
2552 | struct wpa_supplicant *wpa_s, char *cmd) | |
2553 | { | |
2554 | int id; | |
2555 | struct wpa_ssid *ssid; | |
2556 | ||
2557 | /* cmd: "<network id>" or "all" */ | |
2558 | if (os_strcmp(cmd, "all") == 0) { | |
2559 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); | |
86b89452 WS |
2560 | ssid = NULL; |
2561 | } else { | |
2562 | id = atoi(cmd); | |
2563 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); | |
6fc6879b | 2564 | |
86b89452 WS |
2565 | ssid = wpa_config_get_network(wpa_s->conf, id); |
2566 | if (ssid == NULL) { | |
2567 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
2568 | "network id=%d", id); | |
2569 | return -1; | |
2570 | } | |
4dac0245 JM |
2571 | if (ssid->disabled == 2) { |
2572 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
2573 | "ENABLE_NETWORK with persistent P2P group"); | |
2574 | return -1; | |
2575 | } | |
84c78f95 JM |
2576 | |
2577 | if (os_strstr(cmd, " no-connect")) { | |
2578 | ssid->disabled = 0; | |
2579 | return 0; | |
2580 | } | |
6fc6879b | 2581 | } |
86b89452 | 2582 | wpa_supplicant_enable_network(wpa_s, ssid); |
6fc6879b JM |
2583 | |
2584 | return 0; | |
2585 | } | |
2586 | ||
2587 | ||
2588 | static int wpa_supplicant_ctrl_iface_disable_network( | |
2589 | struct wpa_supplicant *wpa_s, char *cmd) | |
2590 | { | |
2591 | int id; | |
2592 | struct wpa_ssid *ssid; | |
2593 | ||
2594 | /* cmd: "<network id>" or "all" */ | |
2595 | if (os_strcmp(cmd, "all") == 0) { | |
2596 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); | |
86b89452 WS |
2597 | ssid = NULL; |
2598 | } else { | |
2599 | id = atoi(cmd); | |
2600 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); | |
6fc6879b | 2601 | |
86b89452 WS |
2602 | ssid = wpa_config_get_network(wpa_s->conf, id); |
2603 | if (ssid == NULL) { | |
2604 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
2605 | "network id=%d", id); | |
2606 | return -1; | |
2607 | } | |
4dac0245 JM |
2608 | if (ssid->disabled == 2) { |
2609 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
2610 | "DISABLE_NETWORK with persistent P2P " | |
2611 | "group"); | |
2612 | return -1; | |
2613 | } | |
6fc6879b | 2614 | } |
86b89452 | 2615 | wpa_supplicant_disable_network(wpa_s, ssid); |
6fc6879b JM |
2616 | |
2617 | return 0; | |
2618 | } | |
2619 | ||
2620 | ||
2621 | static int wpa_supplicant_ctrl_iface_add_network( | |
2622 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
2623 | { | |
2624 | struct wpa_ssid *ssid; | |
2625 | int ret; | |
2626 | ||
2627 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); | |
2628 | ||
2629 | ssid = wpa_config_add_network(wpa_s->conf); | |
2630 | if (ssid == NULL) | |
2631 | return -1; | |
8bac466b JM |
2632 | |
2633 | wpas_notify_network_added(wpa_s, ssid); | |
2634 | ||
6fc6879b JM |
2635 | ssid->disabled = 1; |
2636 | wpa_config_set_network_defaults(ssid); | |
2637 | ||
2638 | ret = os_snprintf(buf, buflen, "%d\n", ssid->id); | |
2639 | if (ret < 0 || (size_t) ret >= buflen) | |
2640 | return -1; | |
2641 | return ret; | |
2642 | } | |
2643 | ||
2644 | ||
2645 | static int wpa_supplicant_ctrl_iface_remove_network( | |
2646 | struct wpa_supplicant *wpa_s, char *cmd) | |
2647 | { | |
2648 | int id; | |
2649 | struct wpa_ssid *ssid; | |
725fc39e | 2650 | int was_disabled; |
6fc6879b JM |
2651 | |
2652 | /* cmd: "<network id>" or "all" */ | |
2653 | if (os_strcmp(cmd, "all") == 0) { | |
2654 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); | |
725fc39e DS |
2655 | if (wpa_s->sched_scanning) |
2656 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
2657 | ||
d8a790b9 | 2658 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
6fc6879b | 2659 | if (wpa_s->current_ssid) { |
83df8149 JM |
2660 | #ifdef CONFIG_SME |
2661 | wpa_s->sme.prev_bssid_set = 0; | |
2662 | #endif /* CONFIG_SME */ | |
20a0b03d JM |
2663 | wpa_sm_set_config(wpa_s->wpa, NULL); |
2664 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | |
07783eaa JM |
2665 | wpa_supplicant_deauthenticate( |
2666 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
6fc6879b | 2667 | } |
391f4925 JK |
2668 | ssid = wpa_s->conf->ssid; |
2669 | while (ssid) { | |
2670 | struct wpa_ssid *remove_ssid = ssid; | |
2671 | id = ssid->id; | |
2672 | ssid = ssid->next; | |
c267753b JM |
2673 | if (wpa_s->last_ssid == remove_ssid) |
2674 | wpa_s->last_ssid = NULL; | |
391f4925 JK |
2675 | wpas_notify_network_removed(wpa_s, remove_ssid); |
2676 | wpa_config_remove_network(wpa_s->conf, id); | |
2677 | } | |
6fc6879b JM |
2678 | return 0; |
2679 | } | |
2680 | ||
2681 | id = atoi(cmd); | |
2682 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); | |
2683 | ||
2684 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
f3857c2e JM |
2685 | if (ssid) |
2686 | wpas_notify_network_removed(wpa_s, ssid); | |
59ff6653 | 2687 | if (ssid == NULL) { |
6fc6879b JM |
2688 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
2689 | "id=%d", id); | |
2690 | return -1; | |
2691 | } | |
2692 | ||
c267753b JM |
2693 | if (wpa_s->last_ssid == ssid) |
2694 | wpa_s->last_ssid = NULL; | |
2695 | ||
d8a790b9 | 2696 | if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) { |
83df8149 JM |
2697 | #ifdef CONFIG_SME |
2698 | wpa_s->sme.prev_bssid_set = 0; | |
2699 | #endif /* CONFIG_SME */ | |
6fc6879b | 2700 | /* |
d8a790b9 JM |
2701 | * Invalidate the EAP session cache if the current or |
2702 | * previously used network is removed. | |
6fc6879b JM |
2703 | */ |
2704 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
d8a790b9 JM |
2705 | } |
2706 | ||
2707 | if (ssid == wpa_s->current_ssid) { | |
20a0b03d JM |
2708 | wpa_sm_set_config(wpa_s->wpa, NULL); |
2709 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | |
6fc6879b | 2710 | |
07783eaa JM |
2711 | wpa_supplicant_deauthenticate(wpa_s, |
2712 | WLAN_REASON_DEAUTH_LEAVING); | |
6fc6879b JM |
2713 | } |
2714 | ||
725fc39e DS |
2715 | was_disabled = ssid->disabled; |
2716 | ||
59ff6653 DG |
2717 | if (wpa_config_remove_network(wpa_s->conf, id) < 0) { |
2718 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the " | |
2719 | "network id=%d", id); | |
2720 | return -1; | |
2721 | } | |
2722 | ||
725fc39e DS |
2723 | if (!was_disabled && wpa_s->sched_scanning) { |
2724 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove " | |
2725 | "network from filters"); | |
2726 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
2727 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
2728 | } | |
2729 | ||
6fc6879b JM |
2730 | return 0; |
2731 | } | |
2732 | ||
2733 | ||
1c330a2f DS |
2734 | static int wpa_supplicant_ctrl_iface_update_network( |
2735 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, | |
2736 | char *name, char *value) | |
2737 | { | |
2738 | if (wpa_config_set(ssid, name, value, 0) < 0) { | |
2739 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " | |
2740 | "variable '%s'", name); | |
2741 | return -1; | |
2742 | } | |
2743 | ||
2744 | if (os_strcmp(name, "bssid") != 0 && | |
2745 | os_strcmp(name, "priority") != 0) | |
2746 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); | |
2747 | ||
2748 | if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) { | |
2749 | /* | |
2750 | * Invalidate the EAP session cache if anything in the current | |
2751 | * or previously used configuration changes. | |
2752 | */ | |
2753 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
2754 | } | |
2755 | ||
2756 | if ((os_strcmp(name, "psk") == 0 && | |
2757 | value[0] == '"' && ssid->ssid_len) || | |
2758 | (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) | |
2759 | wpa_config_update_psk(ssid); | |
2760 | else if (os_strcmp(name, "priority") == 0) | |
2761 | wpa_config_update_prio_list(wpa_s->conf); | |
07cb45cc TP |
2762 | else if (os_strcmp(name, "no_auto_peer") == 0) |
2763 | ssid->no_auto_peer = atoi(value); | |
1c330a2f DS |
2764 | |
2765 | return 0; | |
2766 | } | |
2767 | ||
2768 | ||
6fc6879b JM |
2769 | static int wpa_supplicant_ctrl_iface_set_network( |
2770 | struct wpa_supplicant *wpa_s, char *cmd) | |
2771 | { | |
0ef023e4 | 2772 | int id, ret, prev_bssid_set; |
6fc6879b JM |
2773 | struct wpa_ssid *ssid; |
2774 | char *name, *value; | |
0ef023e4 | 2775 | u8 prev_bssid[ETH_ALEN]; |
6fc6879b JM |
2776 | |
2777 | /* cmd: "<network id> <variable name> <value>" */ | |
2778 | name = os_strchr(cmd, ' '); | |
2779 | if (name == NULL) | |
2780 | return -1; | |
2781 | *name++ = '\0'; | |
2782 | ||
2783 | value = os_strchr(name, ' '); | |
2784 | if (value == NULL) | |
2785 | return -1; | |
2786 | *value++ = '\0'; | |
2787 | ||
2788 | id = atoi(cmd); | |
2789 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", | |
2790 | id, name); | |
2791 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
2792 | (u8 *) value, os_strlen(value)); | |
2793 | ||
2794 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
2795 | if (ssid == NULL) { | |
2796 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | |
2797 | "id=%d", id); | |
2798 | return -1; | |
2799 | } | |
2800 | ||
0ef023e4 JM |
2801 | prev_bssid_set = ssid->bssid_set; |
2802 | os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN); | |
2803 | ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name, | |
2804 | value); | |
2805 | if (ret == 0 && | |
2806 | (ssid->bssid_set != prev_bssid_set || | |
2807 | os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0)) | |
2808 | wpas_notify_network_bssid_set_changed(wpa_s, ssid); | |
2809 | return ret; | |
6fc6879b JM |
2810 | } |
2811 | ||
2812 | ||
2813 | static int wpa_supplicant_ctrl_iface_get_network( | |
2814 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
2815 | { | |
2816 | int id; | |
2817 | size_t res; | |
2818 | struct wpa_ssid *ssid; | |
2819 | char *name, *value; | |
2820 | ||
2821 | /* cmd: "<network id> <variable name>" */ | |
2822 | name = os_strchr(cmd, ' '); | |
2823 | if (name == NULL || buflen == 0) | |
2824 | return -1; | |
2825 | *name++ = '\0'; | |
2826 | ||
2827 | id = atoi(cmd); | |
2828 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'", | |
2829 | id, name); | |
2830 | ||
2831 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
2832 | if (ssid == NULL) { | |
2833 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | |
2834 | "id=%d", id); | |
2835 | return -1; | |
2836 | } | |
2837 | ||
2838 | value = wpa_config_get_no_key(ssid, name); | |
2839 | if (value == NULL) { | |
2840 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " | |
2841 | "variable '%s'", name); | |
2842 | return -1; | |
2843 | } | |
2844 | ||
2845 | res = os_strlcpy(buf, value, buflen); | |
2846 | if (res >= buflen) { | |
2847 | os_free(value); | |
2848 | return -1; | |
2849 | } | |
2850 | ||
2851 | os_free(value); | |
2852 | ||
2853 | return res; | |
2854 | } | |
2855 | ||
2856 | ||
1c330a2f DS |
2857 | static int wpa_supplicant_ctrl_iface_dup_network( |
2858 | struct wpa_supplicant *wpa_s, char *cmd) | |
2859 | { | |
2860 | struct wpa_ssid *ssid_s, *ssid_d; | |
2861 | char *name, *id, *value; | |
2862 | int id_s, id_d, ret; | |
2863 | ||
2864 | /* cmd: "<src network id> <dst network id> <variable name>" */ | |
2865 | id = os_strchr(cmd, ' '); | |
2866 | if (id == NULL) | |
2867 | return -1; | |
2868 | *id++ = '\0'; | |
2869 | ||
2870 | name = os_strchr(id, ' '); | |
2871 | if (name == NULL) | |
2872 | return -1; | |
2873 | *name++ = '\0'; | |
2874 | ||
2875 | id_s = atoi(cmd); | |
2876 | id_d = atoi(id); | |
2877 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'", | |
2878 | id_s, id_d, name); | |
2879 | ||
2880 | ssid_s = wpa_config_get_network(wpa_s->conf, id_s); | |
2881 | if (ssid_s == NULL) { | |
2882 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
2883 | "network id=%d", id_s); | |
2884 | return -1; | |
2885 | } | |
2886 | ||
2887 | ssid_d = wpa_config_get_network(wpa_s->conf, id_d); | |
2888 | if (ssid_d == NULL) { | |
2889 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
2890 | "network id=%d", id_s); | |
2891 | return -1; | |
2892 | } | |
2893 | ||
2894 | value = wpa_config_get(ssid_s, name); | |
2895 | if (value == NULL) { | |
2896 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " | |
2897 | "variable '%s'", name); | |
2898 | return -1; | |
2899 | } | |
2900 | ||
2901 | ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name, | |
2902 | value); | |
2903 | ||
2904 | os_free(value); | |
2905 | ||
2906 | return ret; | |
2907 | } | |
2908 | ||
2909 | ||
d94c9ee6 JM |
2910 | static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s, |
2911 | char *buf, size_t buflen) | |
2912 | { | |
2913 | char *pos, *end; | |
2914 | struct wpa_cred *cred; | |
2915 | int ret; | |
2916 | ||
2917 | pos = buf; | |
2918 | end = buf + buflen; | |
2919 | ret = os_snprintf(pos, end - pos, | |
2920 | "cred id / realm / username / domain / imsi\n"); | |
2921 | if (ret < 0 || ret >= end - pos) | |
2922 | return pos - buf; | |
2923 | pos += ret; | |
2924 | ||
2925 | cred = wpa_s->conf->cred; | |
2926 | while (cred) { | |
2927 | ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n", | |
2928 | cred->id, cred->realm ? cred->realm : "", | |
2929 | cred->username ? cred->username : "", | |
463c8ffb | 2930 | cred->domain ? cred->domain[0] : "", |
d94c9ee6 JM |
2931 | cred->imsi ? cred->imsi : ""); |
2932 | if (ret < 0 || ret >= end - pos) | |
2933 | return pos - buf; | |
2934 | pos += ret; | |
2935 | ||
2936 | cred = cred->next; | |
2937 | } | |
2938 | ||
2939 | return pos - buf; | |
2940 | } | |
2941 | ||
2942 | ||
2943 | static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s, | |
2944 | char *buf, size_t buflen) | |
2945 | { | |
2946 | struct wpa_cred *cred; | |
2947 | int ret; | |
2948 | ||
2949 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED"); | |
2950 | ||
2951 | cred = wpa_config_add_cred(wpa_s->conf); | |
2952 | if (cred == NULL) | |
2953 | return -1; | |
2954 | ||
1619e9d5 JM |
2955 | wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id); |
2956 | ||
d94c9ee6 JM |
2957 | ret = os_snprintf(buf, buflen, "%d\n", cred->id); |
2958 | if (ret < 0 || (size_t) ret >= buflen) | |
2959 | return -1; | |
2960 | return ret; | |
2961 | } | |
2962 | ||
2963 | ||
736d4f2d JM |
2964 | static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s, |
2965 | struct wpa_cred *cred) | |
2966 | { | |
2967 | struct wpa_ssid *ssid; | |
2968 | char str[20]; | |
1619e9d5 | 2969 | int id; |
736d4f2d | 2970 | |
1619e9d5 | 2971 | if (cred == NULL) { |
736d4f2d JM |
2972 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); |
2973 | return -1; | |
2974 | } | |
2975 | ||
1619e9d5 JM |
2976 | id = cred->id; |
2977 | if (wpa_config_remove_cred(wpa_s->conf, id) < 0) { | |
2978 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); | |
2979 | return -1; | |
2980 | } | |
2981 | ||
2982 | wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id); | |
2983 | ||
736d4f2d JM |
2984 | /* Remove any network entry created based on the removed credential */ |
2985 | ssid = wpa_s->conf->ssid; | |
2986 | while (ssid) { | |
2987 | if (ssid->parent_cred == cred) { | |
2988 | wpa_printf(MSG_DEBUG, "Remove network id %d since it " | |
2989 | "used the removed credential", ssid->id); | |
2990 | os_snprintf(str, sizeof(str), "%d", ssid->id); | |
2991 | ssid = ssid->next; | |
2992 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, str); | |
2993 | } else | |
2994 | ssid = ssid->next; | |
2995 | } | |
2996 | ||
2997 | return 0; | |
2998 | } | |
2999 | ||
3000 | ||
d94c9ee6 JM |
3001 | static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s, |
3002 | char *cmd) | |
3003 | { | |
3004 | int id; | |
736d4f2d | 3005 | struct wpa_cred *cred, *prev; |
d94c9ee6 | 3006 | |
aa26ba68 JM |
3007 | /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or |
3008 | * "provisioning_sp=<FQDN> */ | |
d94c9ee6 JM |
3009 | if (os_strcmp(cmd, "all") == 0) { |
3010 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all"); | |
3011 | cred = wpa_s->conf->cred; | |
3012 | while (cred) { | |
736d4f2d | 3013 | prev = cred; |
d94c9ee6 | 3014 | cred = cred->next; |
736d4f2d | 3015 | wpas_ctrl_remove_cred(wpa_s, prev); |
d94c9ee6 JM |
3016 | } |
3017 | return 0; | |
3018 | } | |
3019 | ||
9afe52eb JM |
3020 | if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) { |
3021 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'", | |
3022 | cmd + 8); | |
3023 | cred = wpa_s->conf->cred; | |
3024 | while (cred) { | |
3025 | prev = cred; | |
3026 | cred = cred->next; | |
463c8ffb JM |
3027 | if (prev->domain) { |
3028 | size_t i; | |
3029 | for (i = 0; i < prev->num_domain; i++) { | |
3030 | if (os_strcmp(prev->domain[i], cmd + 8) | |
3031 | != 0) | |
3032 | continue; | |
3033 | wpas_ctrl_remove_cred(wpa_s, prev); | |
3034 | break; | |
3035 | } | |
3036 | } | |
9afe52eb JM |
3037 | } |
3038 | return 0; | |
3039 | } | |
3040 | ||
aa26ba68 JM |
3041 | if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) { |
3042 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'", | |
3043 | cmd + 16); | |
3044 | cred = wpa_s->conf->cred; | |
3045 | while (cred) { | |
3046 | prev = cred; | |
3047 | cred = cred->next; | |
3048 | if (prev->provisioning_sp && | |
3049 | os_strcmp(prev->provisioning_sp, cmd + 16) == 0) | |
3050 | wpas_ctrl_remove_cred(wpa_s, prev); | |
3051 | } | |
3052 | return 0; | |
3053 | } | |
3054 | ||
d94c9ee6 JM |
3055 | id = atoi(cmd); |
3056 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id); | |
3057 | ||
3058 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
736d4f2d | 3059 | return wpas_ctrl_remove_cred(wpa_s, cred); |
d94c9ee6 JM |
3060 | } |
3061 | ||
3062 | ||
3063 | static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s, | |
3064 | char *cmd) | |
3065 | { | |
3066 | int id; | |
3067 | struct wpa_cred *cred; | |
3068 | char *name, *value; | |
3069 | ||
3070 | /* cmd: "<cred id> <variable name> <value>" */ | |
3071 | name = os_strchr(cmd, ' '); | |
3072 | if (name == NULL) | |
3073 | return -1; | |
3074 | *name++ = '\0'; | |
3075 | ||
3076 | value = os_strchr(name, ' '); | |
3077 | if (value == NULL) | |
3078 | return -1; | |
3079 | *value++ = '\0'; | |
3080 | ||
3081 | id = atoi(cmd); | |
3082 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'", | |
3083 | id, name); | |
3084 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
3085 | (u8 *) value, os_strlen(value)); | |
3086 | ||
3087 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
3088 | if (cred == NULL) { | |
3089 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | |
3090 | id); | |
3091 | return -1; | |
3092 | } | |
3093 | ||
3094 | if (wpa_config_set_cred(cred, name, value, 0) < 0) { | |
3095 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred " | |
3096 | "variable '%s'", name); | |
3097 | return -1; | |
3098 | } | |
3099 | ||
1619e9d5 JM |
3100 | wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name); |
3101 | ||
d94c9ee6 JM |
3102 | return 0; |
3103 | } | |
3104 | ||
3105 | ||
c880ab87 JM |
3106 | static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s, |
3107 | char *cmd, char *buf, | |
3108 | size_t buflen) | |
3109 | { | |
3110 | int id; | |
3111 | size_t res; | |
3112 | struct wpa_cred *cred; | |
3113 | char *name, *value; | |
3114 | ||
3115 | /* cmd: "<cred id> <variable name>" */ | |
3116 | name = os_strchr(cmd, ' '); | |
3117 | if (name == NULL) | |
3118 | return -1; | |
3119 | *name++ = '\0'; | |
3120 | ||
3121 | id = atoi(cmd); | |
3122 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'", | |
3123 | id, name); | |
3124 | ||
3125 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
3126 | if (cred == NULL) { | |
3127 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | |
3128 | id); | |
3129 | return -1; | |
3130 | } | |
3131 | ||
3132 | value = wpa_config_get_cred_no_key(cred, name); | |
3133 | if (value == NULL) { | |
3134 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'", | |
3135 | name); | |
3136 | return -1; | |
3137 | } | |
3138 | ||
3139 | res = os_strlcpy(buf, value, buflen); | |
3140 | if (res >= buflen) { | |
3141 | os_free(value); | |
3142 | return -1; | |
3143 | } | |
3144 | ||
3145 | os_free(value); | |
3146 | ||
3147 | return res; | |
3148 | } | |
3149 | ||
3150 | ||
6fc6879b JM |
3151 | #ifndef CONFIG_NO_CONFIG_WRITE |
3152 | static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s) | |
3153 | { | |
3154 | int ret; | |
3155 | ||
3156 | if (!wpa_s->conf->update_config) { | |
3157 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed " | |
3158 | "to update configuration (update_config=0)"); | |
3159 | return -1; | |
3160 | } | |
3161 | ||
3162 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); | |
3163 | if (ret) { | |
3164 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to " | |
3165 | "update configuration"); | |
3166 | } else { | |
3167 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration" | |
3168 | " updated"); | |
3169 | } | |
3170 | ||
3171 | return ret; | |
3172 | } | |
3173 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
3174 | ||
3175 | ||
4daa011b JM |
3176 | struct cipher_info { |
3177 | unsigned int capa; | |
3178 | const char *name; | |
3179 | int group_only; | |
3180 | }; | |
3181 | ||
3182 | static const struct cipher_info ciphers[] = { | |
3183 | { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 }, | |
3184 | { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 }, | |
3185 | { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 }, | |
3186 | { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 }, | |
3187 | { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 }, | |
3188 | { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 }, | |
3189 | { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 }, | |
3190 | { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 } | |
3191 | }; | |
3192 | ||
3193 | ||
6fc6879b JM |
3194 | static int ctrl_iface_get_capability_pairwise(int res, char *strict, |
3195 | struct wpa_driver_capa *capa, | |
3196 | char *buf, size_t buflen) | |
3197 | { | |
ea3b8c1d | 3198 | int ret; |
6fc6879b JM |
3199 | char *pos, *end; |
3200 | size_t len; | |
4daa011b | 3201 | unsigned int i; |
6fc6879b JM |
3202 | |
3203 | pos = buf; | |
3204 | end = pos + buflen; | |
3205 | ||
3206 | if (res < 0) { | |
3207 | if (strict) | |
3208 | return 0; | |
3209 | len = os_strlcpy(buf, "CCMP TKIP NONE", buflen); | |
3210 | if (len >= buflen) | |
3211 | return -1; | |
3212 | return len; | |
3213 | } | |
3214 | ||
4daa011b JM |
3215 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
3216 | if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) { | |
3217 | ret = os_snprintf(pos, end - pos, "%s%s", | |
ea3b8c1d JM |
3218 | pos == buf ? "" : " ", |
3219 | ciphers[i].name); | |
4daa011b JM |
3220 | if (ret < 0 || ret >= end - pos) |
3221 | return pos - buf; | |
3222 | pos += ret; | |
4daa011b | 3223 | } |
6fc6879b JM |
3224 | } |
3225 | ||
3226 | return pos - buf; | |
3227 | } | |
3228 | ||
3229 | ||
3230 | static int ctrl_iface_get_capability_group(int res, char *strict, | |
3231 | struct wpa_driver_capa *capa, | |
3232 | char *buf, size_t buflen) | |
3233 | { | |
ea3b8c1d | 3234 | int ret; |
6fc6879b JM |
3235 | char *pos, *end; |
3236 | size_t len; | |
4daa011b | 3237 | unsigned int i; |
6fc6879b JM |
3238 | |
3239 | pos = buf; | |
3240 | end = pos + buflen; | |
3241 | ||
3242 | if (res < 0) { | |
3243 | if (strict) | |
3244 | return 0; | |
3245 | len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen); | |
3246 | if (len >= buflen) | |
3247 | return -1; | |
3248 | return len; | |
3249 | } | |
3250 | ||
4daa011b JM |
3251 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
3252 | if (capa->enc & ciphers[i].capa) { | |
3253 | ret = os_snprintf(pos, end - pos, "%s%s", | |
ea3b8c1d JM |
3254 | pos == buf ? "" : " ", |
3255 | ciphers[i].name); | |
4daa011b JM |
3256 | if (ret < 0 || ret >= end - pos) |
3257 | return pos - buf; | |
3258 | pos += ret; | |
4daa011b | 3259 | } |
6fc6879b JM |
3260 | } |
3261 | ||
3262 | return pos - buf; | |
3263 | } | |
3264 | ||
3265 | ||
3266 | static int ctrl_iface_get_capability_key_mgmt(int res, char *strict, | |
3267 | struct wpa_driver_capa *capa, | |
3268 | char *buf, size_t buflen) | |
3269 | { | |
3270 | int ret; | |
3271 | char *pos, *end; | |
3272 | size_t len; | |
3273 | ||
3274 | pos = buf; | |
3275 | end = pos + buflen; | |
3276 | ||
3277 | if (res < 0) { | |
3278 | if (strict) | |
3279 | return 0; | |
3280 | len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE " | |
3281 | "NONE", buflen); | |
3282 | if (len >= buflen) | |
3283 | return -1; | |
3284 | return len; | |
3285 | } | |
3286 | ||
3287 | ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); | |
3288 | if (ret < 0 || ret >= end - pos) | |
3289 | return pos - buf; | |
3290 | pos += ret; | |
3291 | ||
3292 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
3293 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { | |
3294 | ret = os_snprintf(pos, end - pos, " WPA-EAP"); | |
3295 | if (ret < 0 || ret >= end - pos) | |
3296 | return pos - buf; | |
3297 | pos += ret; | |
3298 | } | |
3299 | ||
3300 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | |
3301 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
3302 | ret = os_snprintf(pos, end - pos, " WPA-PSK"); | |
3303 | if (ret < 0 || ret >= end - pos) | |
3304 | return pos - buf; | |
3305 | pos += ret; | |
3306 | } | |
3307 | ||
3308 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { | |
3309 | ret = os_snprintf(pos, end - pos, " WPA-NONE"); | |
3310 | if (ret < 0 || ret >= end - pos) | |
3311 | return pos - buf; | |
3312 | pos += ret; | |
3313 | } | |
3314 | ||
3315 | return pos - buf; | |
3316 | } | |
3317 | ||
3318 | ||
3319 | static int ctrl_iface_get_capability_proto(int res, char *strict, | |
3320 | struct wpa_driver_capa *capa, | |
3321 | char *buf, size_t buflen) | |
3322 | { | |
ea3b8c1d | 3323 | int ret; |
6fc6879b JM |
3324 | char *pos, *end; |
3325 | size_t len; | |
3326 | ||
3327 | pos = buf; | |
3328 | end = pos + buflen; | |
3329 | ||
3330 | if (res < 0) { | |
3331 | if (strict) | |
3332 | return 0; | |
3333 | len = os_strlcpy(buf, "RSN WPA", buflen); | |
3334 | if (len >= buflen) | |
3335 | return -1; | |
3336 | return len; | |
3337 | } | |
3338 | ||
3339 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | |
3340 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
ea3b8c1d JM |
3341 | ret = os_snprintf(pos, end - pos, "%sRSN", |
3342 | pos == buf ? "" : " "); | |
6fc6879b JM |
3343 | if (ret < 0 || ret >= end - pos) |
3344 | return pos - buf; | |
3345 | pos += ret; | |
6fc6879b JM |
3346 | } |
3347 | ||
3348 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
3349 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { | |
ea3b8c1d JM |
3350 | ret = os_snprintf(pos, end - pos, "%sWPA", |
3351 | pos == buf ? "" : " "); | |
6fc6879b JM |
3352 | if (ret < 0 || ret >= end - pos) |
3353 | return pos - buf; | |
3354 | pos += ret; | |
6fc6879b JM |
3355 | } |
3356 | ||
3357 | return pos - buf; | |
3358 | } | |
3359 | ||
3360 | ||
3361 | static int ctrl_iface_get_capability_auth_alg(int res, char *strict, | |
3362 | struct wpa_driver_capa *capa, | |
3363 | char *buf, size_t buflen) | |
3364 | { | |
ea3b8c1d | 3365 | int ret; |
6fc6879b JM |
3366 | char *pos, *end; |
3367 | size_t len; | |
3368 | ||
3369 | pos = buf; | |
3370 | end = pos + buflen; | |
3371 | ||
3372 | if (res < 0) { | |
3373 | if (strict) | |
3374 | return 0; | |
3375 | len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen); | |
3376 | if (len >= buflen) | |
3377 | return -1; | |
3378 | return len; | |
3379 | } | |
3380 | ||
3381 | if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) { | |
ea3b8c1d JM |
3382 | ret = os_snprintf(pos, end - pos, "%sOPEN", |
3383 | pos == buf ? "" : " "); | |
6fc6879b JM |
3384 | if (ret < 0 || ret >= end - pos) |
3385 | return pos - buf; | |
3386 | pos += ret; | |
6fc6879b JM |
3387 | } |
3388 | ||
3389 | if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) { | |
3390 | ret = os_snprintf(pos, end - pos, "%sSHARED", | |
ea3b8c1d | 3391 | pos == buf ? "" : " "); |
6fc6879b JM |
3392 | if (ret < 0 || ret >= end - pos) |
3393 | return pos - buf; | |
3394 | pos += ret; | |
6fc6879b JM |
3395 | } |
3396 | ||
3397 | if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) { | |
ea3b8c1d JM |
3398 | ret = os_snprintf(pos, end - pos, "%sLEAP", |
3399 | pos == buf ? "" : " "); | |
6fc6879b JM |
3400 | if (ret < 0 || ret >= end - pos) |
3401 | return pos - buf; | |
3402 | pos += ret; | |
6fc6879b JM |
3403 | } |
3404 | ||
3405 | return pos - buf; | |
3406 | } | |
3407 | ||
3408 | ||
65d52fc1 BR |
3409 | static int ctrl_iface_get_capability_modes(int res, char *strict, |
3410 | struct wpa_driver_capa *capa, | |
3411 | char *buf, size_t buflen) | |
3412 | { | |
ea3b8c1d | 3413 | int ret; |
65d52fc1 BR |
3414 | char *pos, *end; |
3415 | size_t len; | |
3416 | ||
3417 | pos = buf; | |
3418 | end = pos + buflen; | |
3419 | ||
3420 | if (res < 0) { | |
3421 | if (strict) | |
3422 | return 0; | |
3423 | len = os_strlcpy(buf, "IBSS AP", buflen); | |
3424 | if (len >= buflen) | |
3425 | return -1; | |
3426 | return len; | |
3427 | } | |
3428 | ||
3429 | if (capa->flags & WPA_DRIVER_FLAGS_IBSS) { | |
ea3b8c1d JM |
3430 | ret = os_snprintf(pos, end - pos, "%sIBSS", |
3431 | pos == buf ? "" : " "); | |
65d52fc1 BR |
3432 | if (ret < 0 || ret >= end - pos) |
3433 | return pos - buf; | |
3434 | pos += ret; | |
65d52fc1 BR |
3435 | } |
3436 | ||
3437 | if (capa->flags & WPA_DRIVER_FLAGS_AP) { | |
ea3b8c1d JM |
3438 | ret = os_snprintf(pos, end - pos, "%sAP", |
3439 | pos == buf ? "" : " "); | |
65d52fc1 BR |
3440 | if (ret < 0 || ret >= end - pos) |
3441 | return pos - buf; | |
3442 | pos += ret; | |
65d52fc1 BR |
3443 | } |
3444 | ||
3445 | return pos - buf; | |
3446 | } | |
3447 | ||
3448 | ||
35aa088a DS |
3449 | static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s, |
3450 | char *buf, size_t buflen) | |
3451 | { | |
3452 | struct hostapd_channel_data *chnl; | |
3453 | int ret, i, j; | |
3454 | char *pos, *end, *hmode; | |
3455 | ||
3456 | pos = buf; | |
3457 | end = pos + buflen; | |
3458 | ||
3459 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | |
3460 | switch (wpa_s->hw.modes[j].mode) { | |
3461 | case HOSTAPD_MODE_IEEE80211B: | |
3462 | hmode = "B"; | |
3463 | break; | |
3464 | case HOSTAPD_MODE_IEEE80211G: | |
3465 | hmode = "G"; | |
3466 | break; | |
3467 | case HOSTAPD_MODE_IEEE80211A: | |
3468 | hmode = "A"; | |
3469 | break; | |
7829894c VK |
3470 | case HOSTAPD_MODE_IEEE80211AD: |
3471 | hmode = "AD"; | |
3472 | break; | |
35aa088a DS |
3473 | default: |
3474 | continue; | |
3475 | } | |
3476 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode); | |
3477 | if (ret < 0 || ret >= end - pos) | |
3478 | return pos - buf; | |
3479 | pos += ret; | |
3480 | chnl = wpa_s->hw.modes[j].channels; | |
3481 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | |
3482 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | |
3483 | continue; | |
3484 | ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan); | |
3485 | if (ret < 0 || ret >= end - pos) | |
3486 | return pos - buf; | |
3487 | pos += ret; | |
3488 | } | |
3489 | ret = os_snprintf(pos, end - pos, "\n"); | |
3490 | if (ret < 0 || ret >= end - pos) | |
3491 | return pos - buf; | |
3492 | pos += ret; | |
3493 | } | |
3494 | ||
3495 | return pos - buf; | |
3496 | } | |
3497 | ||
3498 | ||
06060522 BR |
3499 | static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s, |
3500 | char *buf, size_t buflen) | |
3501 | { | |
3502 | struct hostapd_channel_data *chnl; | |
3503 | int ret, i, j; | |
3504 | char *pos, *end, *hmode; | |
3505 | ||
3506 | pos = buf; | |
3507 | end = pos + buflen; | |
3508 | ||
3509 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | |
3510 | switch (wpa_s->hw.modes[j].mode) { | |
3511 | case HOSTAPD_MODE_IEEE80211B: | |
3512 | hmode = "B"; | |
3513 | break; | |
3514 | case HOSTAPD_MODE_IEEE80211G: | |
3515 | hmode = "G"; | |
3516 | break; | |
3517 | case HOSTAPD_MODE_IEEE80211A: | |
3518 | hmode = "A"; | |
3519 | break; | |
3520 | case HOSTAPD_MODE_IEEE80211AD: | |
3521 | hmode = "AD"; | |
3522 | break; | |
3523 | default: | |
3524 | continue; | |
3525 | } | |
3526 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n", | |
3527 | hmode); | |
3528 | if (ret < 0 || ret >= end - pos) | |
3529 | return pos - buf; | |
3530 | pos += ret; | |
3531 | chnl = wpa_s->hw.modes[j].channels; | |
3532 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | |
3533 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | |
3534 | continue; | |
0547124d | 3535 | ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n", |
06060522 | 3536 | chnl[i].chan, chnl[i].freq, |
0a443580 IP |
3537 | chnl[i].flag & HOSTAPD_CHAN_NO_IR ? |
3538 | " (NO_IR)" : "", | |
0547124d DS |
3539 | chnl[i].flag & HOSTAPD_CHAN_RADAR ? |
3540 | " (DFS)" : ""); | |
3541 | ||
06060522 BR |
3542 | if (ret < 0 || ret >= end - pos) |
3543 | return pos - buf; | |
3544 | pos += ret; | |
3545 | } | |
3546 | ret = os_snprintf(pos, end - pos, "\n"); | |
3547 | if (ret < 0 || ret >= end - pos) | |
3548 | return pos - buf; | |
3549 | pos += ret; | |
3550 | } | |
3551 | ||
3552 | return pos - buf; | |
3553 | } | |
3554 | ||
3555 | ||
6fc6879b JM |
3556 | static int wpa_supplicant_ctrl_iface_get_capability( |
3557 | struct wpa_supplicant *wpa_s, const char *_field, char *buf, | |
3558 | size_t buflen) | |
3559 | { | |
3560 | struct wpa_driver_capa capa; | |
3561 | int res; | |
3562 | char *strict; | |
3563 | char field[30]; | |
3564 | size_t len; | |
3565 | ||
3566 | /* Determine whether or not strict checking was requested */ | |
3567 | len = os_strlcpy(field, _field, sizeof(field)); | |
3568 | if (len >= sizeof(field)) | |
3569 | return -1; | |
3570 | strict = os_strchr(field, ' '); | |
3571 | if (strict != NULL) { | |
3572 | *strict++ = '\0'; | |
3573 | if (os_strcmp(strict, "strict") != 0) | |
3574 | return -1; | |
3575 | } | |
3576 | ||
3577 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s", | |
3578 | field, strict ? strict : ""); | |
3579 | ||
3580 | if (os_strcmp(field, "eap") == 0) { | |
3581 | return eap_get_names(buf, buflen); | |
3582 | } | |
3583 | ||
3584 | res = wpa_drv_get_capa(wpa_s, &capa); | |
3585 | ||
3586 | if (os_strcmp(field, "pairwise") == 0) | |
3587 | return ctrl_iface_get_capability_pairwise(res, strict, &capa, | |
3588 | buf, buflen); | |
3589 | ||
3590 | if (os_strcmp(field, "group") == 0) | |
3591 | return ctrl_iface_get_capability_group(res, strict, &capa, | |
3592 | buf, buflen); | |
3593 | ||
3594 | if (os_strcmp(field, "key_mgmt") == 0) | |
3595 | return ctrl_iface_get_capability_key_mgmt(res, strict, &capa, | |
3596 | buf, buflen); | |
3597 | ||
3598 | if (os_strcmp(field, "proto") == 0) | |
3599 | return ctrl_iface_get_capability_proto(res, strict, &capa, | |
3600 | buf, buflen); | |
3601 | ||
3602 | if (os_strcmp(field, "auth_alg") == 0) | |
3603 | return ctrl_iface_get_capability_auth_alg(res, strict, &capa, | |
3604 | buf, buflen); | |
3605 | ||
65d52fc1 BR |
3606 | if (os_strcmp(field, "modes") == 0) |
3607 | return ctrl_iface_get_capability_modes(res, strict, &capa, | |
3608 | buf, buflen); | |
3609 | ||
35aa088a DS |
3610 | if (os_strcmp(field, "channels") == 0) |
3611 | return ctrl_iface_get_capability_channels(wpa_s, buf, buflen); | |
3612 | ||
06060522 BR |
3613 | if (os_strcmp(field, "freq") == 0) |
3614 | return ctrl_iface_get_capability_freq(wpa_s, buf, buflen); | |
3615 | ||
6e9375e4 DS |
3616 | #ifdef CONFIG_TDLS |
3617 | if (os_strcmp(field, "tdls") == 0) | |
3618 | return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen); | |
3619 | #endif /* CONFIG_TDLS */ | |
3620 | ||
6fc6879b JM |
3621 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", |
3622 | field); | |
3623 | ||
3624 | return -1; | |
3625 | } | |
3626 | ||
3627 | ||
afc064fe JM |
3628 | #ifdef CONFIG_INTERWORKING |
3629 | static char * anqp_add_hex(char *pos, char *end, const char *title, | |
3630 | struct wpabuf *data) | |
3631 | { | |
3632 | char *start = pos; | |
3633 | size_t i; | |
3634 | int ret; | |
3635 | const u8 *d; | |
3636 | ||
3637 | if (data == NULL) | |
3638 | return start; | |
3639 | ||
3640 | ret = os_snprintf(pos, end - pos, "%s=", title); | |
3641 | if (ret < 0 || ret >= end - pos) | |
3642 | return start; | |
3643 | pos += ret; | |
3644 | ||
3645 | d = wpabuf_head_u8(data); | |
3646 | for (i = 0; i < wpabuf_len(data); i++) { | |
3647 | ret = os_snprintf(pos, end - pos, "%02x", *d++); | |
3648 | if (ret < 0 || ret >= end - pos) | |
3649 | return start; | |
3650 | pos += ret; | |
3651 | } | |
3652 | ||
3653 | ret = os_snprintf(pos, end - pos, "\n"); | |
3654 | if (ret < 0 || ret >= end - pos) | |
3655 | return start; | |
3656 | pos += ret; | |
3657 | ||
3658 | return pos; | |
3659 | } | |
3660 | #endif /* CONFIG_INTERWORKING */ | |
3661 | ||
3662 | ||
61ce9085 | 3663 | static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
5f97dd1c | 3664 | unsigned long mask, char *buf, size_t buflen) |
6fc6879b | 3665 | { |
6fc6879b | 3666 | size_t i; |
6fc6879b JM |
3667 | int ret; |
3668 | char *pos, *end; | |
3669 | const u8 *ie, *ie2; | |
3670 | ||
6fc6879b JM |
3671 | pos = buf; |
3672 | end = buf + buflen; | |
6fc6879b | 3673 | |
5f97dd1c DS |
3674 | if (mask & WPA_BSS_MASK_ID) { |
3675 | ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id); | |
6fc6879b | 3676 | if (ret < 0 || ret >= end - pos) |
5f97dd1c | 3677 | return 0; |
6fc6879b JM |
3678 | pos += ret; |
3679 | } | |
3680 | ||
5f97dd1c DS |
3681 | if (mask & WPA_BSS_MASK_BSSID) { |
3682 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | |
3683 | MAC2STR(bss->bssid)); | |
3684 | if (ret < 0 || ret >= end - pos) | |
3685 | return 0; | |
3686 | pos += ret; | |
3687 | } | |
6fc6879b | 3688 | |
5f97dd1c DS |
3689 | if (mask & WPA_BSS_MASK_FREQ) { |
3690 | ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq); | |
3691 | if (ret < 0 || ret >= end - pos) | |
3692 | return 0; | |
3693 | pos += ret; | |
3694 | } | |
6fc6879b | 3695 | |
5f97dd1c DS |
3696 | if (mask & WPA_BSS_MASK_BEACON_INT) { |
3697 | ret = os_snprintf(pos, end - pos, "beacon_int=%d\n", | |
3698 | bss->beacon_int); | |
6fc6879b | 3699 | if (ret < 0 || ret >= end - pos) |
5f97dd1c | 3700 | return 0; |
6fc6879b JM |
3701 | pos += ret; |
3702 | } | |
5f97dd1c DS |
3703 | |
3704 | if (mask & WPA_BSS_MASK_CAPABILITIES) { | |
3705 | ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n", | |
3706 | bss->caps); | |
6fc6879b | 3707 | if (ret < 0 || ret >= end - pos) |
5f97dd1c | 3708 | return 0; |
6fc6879b JM |
3709 | pos += ret; |
3710 | } | |
5f97dd1c DS |
3711 | |
3712 | if (mask & WPA_BSS_MASK_QUAL) { | |
3713 | ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual); | |
bd1af96a | 3714 | if (ret < 0 || ret >= end - pos) |
5f97dd1c | 3715 | return 0; |
bd1af96a JM |
3716 | pos += ret; |
3717 | } | |
5f97dd1c DS |
3718 | |
3719 | if (mask & WPA_BSS_MASK_NOISE) { | |
3720 | ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise); | |
cc81110d | 3721 | if (ret < 0 || ret >= end - pos) |
5f97dd1c | 3722 | return 0; |
cc81110d JM |
3723 | pos += ret; |
3724 | } | |
6fc6879b | 3725 | |
5f97dd1c DS |
3726 | if (mask & WPA_BSS_MASK_LEVEL) { |
3727 | ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level); | |
3728 | if (ret < 0 || ret >= end - pos) | |
3729 | return 0; | |
3730 | pos += ret; | |
3731 | } | |
6fc6879b | 3732 | |
5f97dd1c DS |
3733 | if (mask & WPA_BSS_MASK_TSF) { |
3734 | ret = os_snprintf(pos, end - pos, "tsf=%016llu\n", | |
3735 | (unsigned long long) bss->tsf); | |
3736 | if (ret < 0 || ret >= end - pos) | |
3737 | return 0; | |
3738 | pos += ret; | |
3739 | } | |
3740 | ||
3741 | if (mask & WPA_BSS_MASK_AGE) { | |
acb69cec | 3742 | struct os_reltime now; |
5f97dd1c | 3743 | |
acb69cec | 3744 | os_get_reltime(&now); |
5f97dd1c DS |
3745 | ret = os_snprintf(pos, end - pos, "age=%d\n", |
3746 | (int) (now.sec - bss->last_update.sec)); | |
3747 | if (ret < 0 || ret >= end - pos) | |
3748 | return 0; | |
3749 | pos += ret; | |
3750 | } | |
3751 | ||
3752 | if (mask & WPA_BSS_MASK_IE) { | |
3753 | ret = os_snprintf(pos, end - pos, "ie="); | |
3754 | if (ret < 0 || ret >= end - pos) | |
3755 | return 0; | |
3756 | pos += ret; | |
3757 | ||
3758 | ie = (const u8 *) (bss + 1); | |
3759 | for (i = 0; i < bss->ie_len; i++) { | |
3760 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); | |
3761 | if (ret < 0 || ret >= end - pos) | |
3762 | return 0; | |
3763 | pos += ret; | |
3764 | } | |
3765 | ||
3766 | ret = os_snprintf(pos, end - pos, "\n"); | |
3767 | if (ret < 0 || ret >= end - pos) | |
3768 | return 0; | |
3769 | pos += ret; | |
3770 | } | |
3771 | ||
3772 | if (mask & WPA_BSS_MASK_FLAGS) { | |
3773 | ret = os_snprintf(pos, end - pos, "flags="); | |
3774 | if (ret < 0 || ret >= end - pos) | |
3775 | return 0; | |
3776 | pos += ret; | |
3777 | ||
3778 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | |
3779 | if (ie) | |
3780 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, | |
3781 | 2 + ie[1]); | |
3782 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); | |
3783 | if (ie2) | |
3784 | pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, | |
3785 | 2 + ie2[1]); | |
3786 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); | |
3787 | if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) { | |
3788 | ret = os_snprintf(pos, end - pos, "[WEP]"); | |
3789 | if (ret < 0 || ret >= end - pos) | |
3790 | return 0; | |
3791 | pos += ret; | |
3792 | } | |
e403ba85 BS |
3793 | if (bss_is_dmg(bss)) { |
3794 | const char *s; | |
3795 | ret = os_snprintf(pos, end - pos, "[DMG]"); | |
5f97dd1c DS |
3796 | if (ret < 0 || ret >= end - pos) |
3797 | return 0; | |
3798 | pos += ret; | |
e403ba85 BS |
3799 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
3800 | case IEEE80211_CAP_DMG_IBSS: | |
3801 | s = "[IBSS]"; | |
3802 | break; | |
3803 | case IEEE80211_CAP_DMG_AP: | |
3804 | s = "[ESS]"; | |
3805 | break; | |
3806 | case IEEE80211_CAP_DMG_PBSS: | |
3807 | s = "[PBSS]"; | |
3808 | break; | |
3809 | default: | |
3810 | s = ""; | |
3811 | break; | |
3812 | } | |
3813 | ret = os_snprintf(pos, end - pos, "%s", s); | |
5f97dd1c DS |
3814 | if (ret < 0 || ret >= end - pos) |
3815 | return 0; | |
3816 | pos += ret; | |
e403ba85 BS |
3817 | } else { |
3818 | if (bss->caps & IEEE80211_CAP_IBSS) { | |
3819 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | |
3820 | if (ret < 0 || ret >= end - pos) | |
3821 | return 0; | |
3822 | pos += ret; | |
3823 | } | |
3824 | if (bss->caps & IEEE80211_CAP_ESS) { | |
3825 | ret = os_snprintf(pos, end - pos, "[ESS]"); | |
3826 | if (ret < 0 || ret >= end - pos) | |
3827 | return 0; | |
3828 | pos += ret; | |
3829 | } | |
5f97dd1c | 3830 | } |
bb50ae43 JM |
3831 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || |
3832 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { | |
5f97dd1c DS |
3833 | ret = os_snprintf(pos, end - pos, "[P2P]"); |
3834 | if (ret < 0 || ret >= end - pos) | |
3835 | return 0; | |
3836 | pos += ret; | |
3837 | } | |
64855b96 JM |
3838 | #ifdef CONFIG_HS20 |
3839 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) { | |
3840 | ret = os_snprintf(pos, end - pos, "[HS20]"); | |
3841 | if (ret < 0 || ret >= end - pos) | |
ff486913 | 3842 | return 0; |
64855b96 JM |
3843 | pos += ret; |
3844 | } | |
3845 | #endif /* CONFIG_HS20 */ | |
5f97dd1c DS |
3846 | |
3847 | ret = os_snprintf(pos, end - pos, "\n"); | |
3848 | if (ret < 0 || ret >= end - pos) | |
3849 | return 0; | |
3850 | pos += ret; | |
3851 | } | |
3852 | ||
3853 | if (mask & WPA_BSS_MASK_SSID) { | |
3854 | ret = os_snprintf(pos, end - pos, "ssid=%s\n", | |
3855 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | |
3856 | if (ret < 0 || ret >= end - pos) | |
3857 | return 0; | |
3858 | pos += ret; | |
3859 | } | |
6fc6879b | 3860 | |
611ed491 | 3861 | #ifdef CONFIG_WPS |
5f97dd1c DS |
3862 | if (mask & WPA_BSS_MASK_WPS_SCAN) { |
3863 | ie = (const u8 *) (bss + 1); | |
3864 | ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end); | |
3865 | if (ret < 0 || ret >= end - pos) | |
3866 | return 0; | |
3867 | pos += ret; | |
3868 | } | |
611ed491 JM |
3869 | #endif /* CONFIG_WPS */ |
3870 | ||
0c6b310e | 3871 | #ifdef CONFIG_P2P |
5f97dd1c DS |
3872 | if (mask & WPA_BSS_MASK_P2P_SCAN) { |
3873 | ie = (const u8 *) (bss + 1); | |
3874 | ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end); | |
3875 | if (ret < 0 || ret >= end - pos) | |
3876 | return 0; | |
3877 | pos += ret; | |
3878 | } | |
0c6b310e JM |
3879 | #endif /* CONFIG_P2P */ |
3880 | ||
337c781f JM |
3881 | #ifdef CONFIG_WIFI_DISPLAY |
3882 | if (mask & WPA_BSS_MASK_WIFI_DISPLAY) { | |
3883 | struct wpabuf *wfd; | |
3884 | ie = (const u8 *) (bss + 1); | |
3885 | wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len, | |
3886 | WFD_IE_VENDOR_TYPE); | |
3887 | if (wfd) { | |
3888 | ret = os_snprintf(pos, end - pos, "wfd_subelems="); | |
5e6aa04b EL |
3889 | if (ret < 0 || ret >= end - pos) { |
3890 | wpabuf_free(wfd); | |
ff486913 | 3891 | return 0; |
5e6aa04b | 3892 | } |
337c781f JM |
3893 | pos += ret; |
3894 | ||
3895 | pos += wpa_snprintf_hex(pos, end - pos, | |
3896 | wpabuf_head(wfd), | |
3897 | wpabuf_len(wfd)); | |
3898 | wpabuf_free(wfd); | |
3899 | ||
3900 | ret = os_snprintf(pos, end - pos, "\n"); | |
3901 | if (ret < 0 || ret >= end - pos) | |
ff486913 | 3902 | return 0; |
337c781f JM |
3903 | pos += ret; |
3904 | } | |
3905 | } | |
3906 | #endif /* CONFIG_WIFI_DISPLAY */ | |
3907 | ||
afc064fe | 3908 | #ifdef CONFIG_INTERWORKING |
476aed35 JM |
3909 | if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) { |
3910 | struct wpa_bss_anqp *anqp = bss->anqp; | |
5f97dd1c | 3911 | pos = anqp_add_hex(pos, end, "anqp_venue_name", |
476aed35 | 3912 | anqp->venue_name); |
5f97dd1c | 3913 | pos = anqp_add_hex(pos, end, "anqp_network_auth_type", |
476aed35 | 3914 | anqp->network_auth_type); |
5f97dd1c | 3915 | pos = anqp_add_hex(pos, end, "anqp_roaming_consortium", |
476aed35 | 3916 | anqp->roaming_consortium); |
5f97dd1c | 3917 | pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability", |
476aed35 | 3918 | anqp->ip_addr_type_availability); |
5f97dd1c | 3919 | pos = anqp_add_hex(pos, end, "anqp_nai_realm", |
476aed35 JM |
3920 | anqp->nai_realm); |
3921 | pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp); | |
5f97dd1c | 3922 | pos = anqp_add_hex(pos, end, "anqp_domain_name", |
476aed35 | 3923 | anqp->domain_name); |
25471fe3 JK |
3924 | #ifdef CONFIG_HS20 |
3925 | pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name", | |
476aed35 | 3926 | anqp->hs20_operator_friendly_name); |
25471fe3 | 3927 | pos = anqp_add_hex(pos, end, "hs20_wan_metrics", |
476aed35 | 3928 | anqp->hs20_wan_metrics); |
25471fe3 | 3929 | pos = anqp_add_hex(pos, end, "hs20_connection_capability", |
476aed35 | 3930 | anqp->hs20_connection_capability); |
1d2215fc JM |
3931 | pos = anqp_add_hex(pos, end, "hs20_operating_class", |
3932 | anqp->hs20_operating_class); | |
3933 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_list", | |
3934 | anqp->hs20_osu_providers_list); | |
25471fe3 | 3935 | #endif /* CONFIG_HS20 */ |
5f97dd1c | 3936 | } |
afc064fe JM |
3937 | #endif /* CONFIG_INTERWORKING */ |
3938 | ||
79070906 MH |
3939 | #ifdef CONFIG_MESH |
3940 | if (mask & WPA_BSS_MASK_MESH_SCAN) { | |
3941 | ie = (const u8 *) (bss + 1); | |
3942 | ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end); | |
3943 | if (ret < 0 || ret >= end - pos) | |
3944 | return 0; | |
3945 | pos += ret; | |
3946 | } | |
3947 | #endif /* CONFIG_MESH */ | |
3948 | ||
c6673429 DS |
3949 | if (mask & WPA_BSS_MASK_DELIM) { |
3950 | ret = os_snprintf(pos, end - pos, "====\n"); | |
3951 | if (ret < 0 || ret >= end - pos) | |
3952 | return 0; | |
3953 | pos += ret; | |
3954 | } | |
3955 | ||
6fc6879b JM |
3956 | return pos - buf; |
3957 | } | |
3958 | ||
3959 | ||
61ce9085 DS |
3960 | static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s, |
3961 | const char *cmd, char *buf, | |
3962 | size_t buflen) | |
3963 | { | |
3964 | u8 bssid[ETH_ALEN]; | |
3965 | size_t i; | |
3966 | struct wpa_bss *bss; | |
eff1a95b DS |
3967 | struct wpa_bss *bsslast = NULL; |
3968 | struct dl_list *next; | |
3969 | int ret = 0; | |
3970 | int len; | |
5f97dd1c DS |
3971 | char *ctmp; |
3972 | unsigned long mask = WPA_BSS_MASK_ALL; | |
61ce9085 | 3973 | |
eff1a95b DS |
3974 | if (os_strncmp(cmd, "RANGE=", 6) == 0) { |
3975 | if (os_strncmp(cmd + 6, "ALL", 3) == 0) { | |
3976 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, | |
3977 | list_id); | |
3978 | bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss, | |
3979 | list_id); | |
3980 | } else { /* N1-N2 */ | |
3981 | unsigned int id1, id2; | |
3982 | ||
3983 | if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) { | |
3984 | wpa_printf(MSG_INFO, "Wrong BSS range " | |
3985 | "format"); | |
3986 | return 0; | |
3987 | } | |
3988 | ||
9f42d49c AS |
3989 | if (*(cmd + 6) == '-') |
3990 | id1 = 0; | |
3991 | else | |
3992 | id1 = atoi(cmd + 6); | |
3993 | ctmp++; | |
3994 | if (*ctmp >= '0' && *ctmp <= '9') | |
3995 | id2 = atoi(ctmp); | |
3996 | else | |
3997 | id2 = (unsigned int) -1; | |
3998 | bss = wpa_bss_get_id_range(wpa_s, id1, id2); | |
3999 | if (id2 == (unsigned int) -1) | |
eff1a95b DS |
4000 | bsslast = dl_list_last(&wpa_s->bss_id, |
4001 | struct wpa_bss, | |
4002 | list_id); | |
4003 | else { | |
4004 | bsslast = wpa_bss_get_id(wpa_s, id2); | |
4005 | if (bsslast == NULL && bss && id2 > id1) { | |
4006 | struct wpa_bss *tmp = bss; | |
4007 | for (;;) { | |
4008 | next = tmp->list_id.next; | |
4009 | if (next == &wpa_s->bss_id) | |
4010 | break; | |
4011 | tmp = dl_list_entry( | |
4012 | next, struct wpa_bss, | |
4013 | list_id); | |
4014 | if (tmp->id > id2) | |
4015 | break; | |
4016 | bsslast = tmp; | |
4017 | } | |
4018 | } | |
4019 | } | |
4020 | } | |
f330b4b4 | 4021 | } else if (os_strncmp(cmd, "FIRST", 5) == 0) |
51a0c3d4 | 4022 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id); |
cc03d0fe AS |
4023 | else if (os_strncmp(cmd, "LAST", 4) == 0) |
4024 | bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id); | |
61ce9085 DS |
4025 | else if (os_strncmp(cmd, "ID-", 3) == 0) { |
4026 | i = atoi(cmd + 3); | |
4027 | bss = wpa_bss_get_id(wpa_s, i); | |
4028 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | |
4029 | i = atoi(cmd + 5); | |
4030 | bss = wpa_bss_get_id(wpa_s, i); | |
4031 | if (bss) { | |
eff1a95b | 4032 | next = bss->list_id.next; |
61ce9085 DS |
4033 | if (next == &wpa_s->bss_id) |
4034 | bss = NULL; | |
4035 | else | |
4036 | bss = dl_list_entry(next, struct wpa_bss, | |
4037 | list_id); | |
4038 | } | |
4039 | #ifdef CONFIG_P2P | |
4040 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | |
4041 | if (hwaddr_aton(cmd + 13, bssid) == 0) | |
4042 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid); | |
4043 | else | |
4044 | bss = NULL; | |
4045 | #endif /* CONFIG_P2P */ | |
4046 | } else if (hwaddr_aton(cmd, bssid) == 0) | |
4047 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
4048 | else { | |
4049 | struct wpa_bss *tmp; | |
4050 | i = atoi(cmd); | |
4051 | bss = NULL; | |
4052 | dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id) | |
4053 | { | |
4054 | if (i-- == 0) { | |
4055 | bss = tmp; | |
4056 | break; | |
4057 | } | |
4058 | } | |
4059 | } | |
4060 | ||
5f97dd1c DS |
4061 | if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) { |
4062 | mask = strtoul(ctmp + 5, NULL, 0x10); | |
4063 | if (mask == 0) | |
4064 | mask = WPA_BSS_MASK_ALL; | |
4065 | } | |
4066 | ||
61ce9085 DS |
4067 | if (bss == NULL) |
4068 | return 0; | |
4069 | ||
eff1a95b DS |
4070 | if (bsslast == NULL) |
4071 | bsslast = bss; | |
4072 | do { | |
4073 | len = print_bss_info(wpa_s, bss, mask, buf, buflen); | |
4074 | ret += len; | |
4075 | buf += len; | |
4076 | buflen -= len; | |
cfd42c94 DS |
4077 | if (bss == bsslast) { |
4078 | if ((mask & WPA_BSS_MASK_DELIM) && len && | |
4079 | (bss == dl_list_last(&wpa_s->bss_id, | |
4080 | struct wpa_bss, list_id))) | |
4081 | os_snprintf(buf - 5, 5, "####\n"); | |
eff1a95b | 4082 | break; |
cfd42c94 | 4083 | } |
eff1a95b DS |
4084 | next = bss->list_id.next; |
4085 | if (next == &wpa_s->bss_id) | |
4086 | break; | |
4087 | bss = dl_list_entry(next, struct wpa_bss, list_id); | |
4088 | } while (bss && len); | |
4089 | ||
4090 | return ret; | |
61ce9085 DS |
4091 | } |
4092 | ||
4093 | ||
6fc6879b JM |
4094 | static int wpa_supplicant_ctrl_iface_ap_scan( |
4095 | struct wpa_supplicant *wpa_s, char *cmd) | |
4096 | { | |
4097 | int ap_scan = atoi(cmd); | |
86b89452 | 4098 | return wpa_supplicant_set_ap_scan(wpa_s, ap_scan); |
6fc6879b JM |
4099 | } |
4100 | ||
4101 | ||
67b9bd08 DS |
4102 | static int wpa_supplicant_ctrl_iface_scan_interval( |
4103 | struct wpa_supplicant *wpa_s, char *cmd) | |
4104 | { | |
4105 | int scan_int = atoi(cmd); | |
c6e86b63 | 4106 | return wpa_supplicant_set_scan_interval(wpa_s, scan_int); |
67b9bd08 DS |
4107 | } |
4108 | ||
4109 | ||
78633c37 SL |
4110 | static int wpa_supplicant_ctrl_iface_bss_expire_age( |
4111 | struct wpa_supplicant *wpa_s, char *cmd) | |
4112 | { | |
4113 | int expire_age = atoi(cmd); | |
4114 | return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age); | |
4115 | } | |
4116 | ||
4117 | ||
4118 | static int wpa_supplicant_ctrl_iface_bss_expire_count( | |
4119 | struct wpa_supplicant *wpa_s, char *cmd) | |
4120 | { | |
4121 | int expire_count = atoi(cmd); | |
4122 | return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count); | |
4123 | } | |
4124 | ||
4125 | ||
39ee845f DS |
4126 | static int wpa_supplicant_ctrl_iface_bss_flush( |
4127 | struct wpa_supplicant *wpa_s, char *cmd) | |
4128 | { | |
4129 | int flush_age = atoi(cmd); | |
4130 | ||
4131 | if (flush_age == 0) | |
4132 | wpa_bss_flush(wpa_s); | |
4133 | else | |
4134 | wpa_bss_flush_by_age(wpa_s, flush_age); | |
4135 | return 0; | |
4136 | } | |
4137 | ||
4138 | ||
9ff4de6d | 4139 | #ifdef CONFIG_TESTING_OPTIONS |
32d5295f JM |
4140 | static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s) |
4141 | { | |
32d5295f JM |
4142 | wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication"); |
4143 | /* MLME-DELETEKEYS.request */ | |
0382097e JM |
4144 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0); |
4145 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0); | |
4146 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0); | |
4147 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0); | |
32d5295f | 4148 | #ifdef CONFIG_IEEE80211W |
0382097e JM |
4149 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0); |
4150 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0); | |
32d5295f JM |
4151 | #endif /* CONFIG_IEEE80211W */ |
4152 | ||
4153 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL, | |
4154 | 0); | |
4155 | /* MLME-SETPROTECTION.request(None) */ | |
4156 | wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid, | |
4157 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, | |
4158 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); | |
4159 | wpa_sm_drop_sa(wpa_s->wpa); | |
4160 | } | |
9ff4de6d | 4161 | #endif /* CONFIG_TESTING_OPTIONS */ |
32d5295f JM |
4162 | |
4163 | ||
86d4f806 JM |
4164 | static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s, |
4165 | char *addr) | |
4166 | { | |
90b8fc8f JM |
4167 | #ifdef CONFIG_NO_SCAN_PROCESSING |
4168 | return -1; | |
4169 | #else /* CONFIG_NO_SCAN_PROCESSING */ | |
86d4f806 JM |
4170 | u8 bssid[ETH_ALEN]; |
4171 | struct wpa_bss *bss; | |
4172 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
4173 | ||
4174 | if (hwaddr_aton(addr, bssid)) { | |
4175 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid " | |
4176 | "address '%s'", addr); | |
4177 | return -1; | |
4178 | } | |
4179 | ||
4180 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid)); | |
4181 | ||
2f9b66d3 JM |
4182 | if (!ssid) { |
4183 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network " | |
4184 | "configuration known for the target AP"); | |
4185 | return -1; | |
4186 | } | |
4187 | ||
4188 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); | |
86d4f806 JM |
4189 | if (!bss) { |
4190 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found " | |
4191 | "from BSS table"); | |
4192 | return -1; | |
4193 | } | |
4194 | ||
4195 | /* | |
4196 | * TODO: Find best network configuration block from configuration to | |
4197 | * allow roaming to other networks | |
4198 | */ | |
4199 | ||
86d4f806 JM |
4200 | wpa_s->reassociate = 1; |
4201 | wpa_supplicant_connect(wpa_s, bss, ssid); | |
4202 | ||
4203 | return 0; | |
90b8fc8f | 4204 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
86d4f806 JM |
4205 | } |
4206 | ||
4207 | ||
b563b388 JM |
4208 | #ifdef CONFIG_P2P |
4209 | static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd) | |
4210 | { | |
4211 | unsigned int timeout = atoi(cmd); | |
4212 | enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL; | |
6d92fa6e | 4213 | u8 dev_id[ETH_ALEN], *_dev_id = NULL; |
2b384109 | 4214 | u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL; |
6d92fa6e | 4215 | char *pos; |
05a77b3b | 4216 | unsigned int search_delay; |
b563b388 | 4217 | |
e9eb648e JM |
4218 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
4219 | wpa_dbg(wpa_s, MSG_INFO, | |
4220 | "Reject P2P_FIND since interface is disabled"); | |
4221 | return -1; | |
4222 | } | |
b563b388 JM |
4223 | if (os_strstr(cmd, "type=social")) |
4224 | type = P2P_FIND_ONLY_SOCIAL; | |
4225 | else if (os_strstr(cmd, "type=progressive")) | |
4226 | type = P2P_FIND_PROGRESSIVE; | |
4227 | ||
6d92fa6e JM |
4228 | pos = os_strstr(cmd, "dev_id="); |
4229 | if (pos) { | |
4230 | pos += 7; | |
4231 | if (hwaddr_aton(pos, dev_id)) | |
4232 | return -1; | |
4233 | _dev_id = dev_id; | |
4234 | } | |
4235 | ||
2b384109 JM |
4236 | pos = os_strstr(cmd, "dev_type="); |
4237 | if (pos) { | |
4238 | pos += 9; | |
4239 | if (wps_dev_type_str2bin(pos, dev_type) < 0) | |
4240 | return -1; | |
4241 | _dev_type = dev_type; | |
4242 | } | |
4243 | ||
37448ede JM |
4244 | pos = os_strstr(cmd, "delay="); |
4245 | if (pos) { | |
4246 | pos += 6; | |
4247 | search_delay = atoi(pos); | |
05a77b3b JM |
4248 | } else |
4249 | search_delay = wpas_p2p_search_delay(wpa_s); | |
37448ede | 4250 | |
2b384109 JM |
4251 | return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type, |
4252 | _dev_id, search_delay); | |
b563b388 JM |
4253 | } |
4254 | ||
4255 | ||
4256 | static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd, | |
4257 | char *buf, size_t buflen) | |
4258 | { | |
4259 | u8 addr[ETH_ALEN]; | |
4260 | char *pos, *pos2; | |
4261 | char *pin = NULL; | |
4262 | enum p2p_wps_method wps_method; | |
4263 | int new_pin; | |
4264 | int ret; | |
23c84252 | 4265 | int persistent_group, persistent_id = -1; |
b563b388 JM |
4266 | int join; |
4267 | int auth; | |
b31be3a0 | 4268 | int automatic; |
b563b388 JM |
4269 | int go_intent = -1; |
4270 | int freq = 0; | |
3bc462cb | 4271 | int pd; |
20ea1ca4 | 4272 | int ht40, vht; |
b563b388 | 4273 | |
23c84252 JM |
4274 | /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad] |
4275 | * [persistent|persistent=<network id>] | |
e2308e4b | 4276 | * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] |
20ea1ca4 | 4277 | * [ht40] [vht] */ |
b563b388 JM |
4278 | |
4279 | if (hwaddr_aton(cmd, addr)) | |
4280 | return -1; | |
4281 | ||
4282 | pos = cmd + 17; | |
4283 | if (*pos != ' ') | |
4284 | return -1; | |
4285 | pos++; | |
4286 | ||
4287 | persistent_group = os_strstr(pos, " persistent") != NULL; | |
23c84252 JM |
4288 | pos2 = os_strstr(pos, " persistent="); |
4289 | if (pos2) { | |
4290 | struct wpa_ssid *ssid; | |
4291 | persistent_id = atoi(pos2 + 12); | |
4292 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); | |
4293 | if (ssid == NULL || ssid->disabled != 2 || | |
4294 | ssid->mode != WPAS_MODE_P2P_GO) { | |
4295 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
4296 | "SSID id=%d for persistent P2P group (GO)", | |
4297 | persistent_id); | |
4298 | return -1; | |
4299 | } | |
4300 | } | |
b563b388 JM |
4301 | join = os_strstr(pos, " join") != NULL; |
4302 | auth = os_strstr(pos, " auth") != NULL; | |
b31be3a0 | 4303 | automatic = os_strstr(pos, " auto") != NULL; |
3bc462cb | 4304 | pd = os_strstr(pos, " provdisc") != NULL; |
20ea1ca4 EP |
4305 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
4306 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | |
4307 | vht; | |
b563b388 JM |
4308 | |
4309 | pos2 = os_strstr(pos, " go_intent="); | |
4310 | if (pos2) { | |
4311 | pos2 += 11; | |
4312 | go_intent = atoi(pos2); | |
4313 | if (go_intent < 0 || go_intent > 15) | |
4314 | return -1; | |
4315 | } | |
4316 | ||
4317 | pos2 = os_strstr(pos, " freq="); | |
4318 | if (pos2) { | |
4319 | pos2 += 6; | |
4320 | freq = atoi(pos2); | |
4321 | if (freq <= 0) | |
4322 | return -1; | |
4323 | } | |
4324 | ||
4325 | if (os_strncmp(pos, "pin", 3) == 0) { | |
4326 | /* Request random PIN (to be displayed) and enable the PIN */ | |
4327 | wps_method = WPS_PIN_DISPLAY; | |
4328 | } else if (os_strncmp(pos, "pbc", 3) == 0) { | |
4329 | wps_method = WPS_PBC; | |
4330 | } else { | |
4331 | pin = pos; | |
4332 | pos = os_strchr(pin, ' '); | |
4333 | wps_method = WPS_PIN_KEYPAD; | |
4334 | if (pos) { | |
4335 | *pos++ = '\0'; | |
07fecd39 | 4336 | if (os_strncmp(pos, "display", 7) == 0) |
b563b388 JM |
4337 | wps_method = WPS_PIN_DISPLAY; |
4338 | } | |
dcc33057 | 4339 | if (!wps_pin_str_valid(pin)) { |
36ebf7a1 MH |
4340 | os_memcpy(buf, "FAIL-INVALID-PIN\n", 17); |
4341 | return 17; | |
4342 | } | |
b563b388 JM |
4343 | } |
4344 | ||
4345 | new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method, | |
b31be3a0 | 4346 | persistent_group, automatic, join, |
e2308e4b | 4347 | auth, go_intent, freq, persistent_id, pd, |
20ea1ca4 | 4348 | ht40, vht); |
d054a462 JM |
4349 | if (new_pin == -2) { |
4350 | os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25); | |
4351 | return 25; | |
4352 | } | |
4353 | if (new_pin == -3) { | |
4354 | os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25); | |
4355 | return 25; | |
4356 | } | |
b563b388 JM |
4357 | if (new_pin < 0) |
4358 | return -1; | |
4359 | if (wps_method == WPS_PIN_DISPLAY && pin == NULL) { | |
4360 | ret = os_snprintf(buf, buflen, "%08d", new_pin); | |
4361 | if (ret < 0 || (size_t) ret >= buflen) | |
4362 | return -1; | |
4363 | return ret; | |
4364 | } | |
4365 | ||
4366 | os_memcpy(buf, "OK\n", 3); | |
4367 | return 3; | |
4368 | } | |
4369 | ||
4370 | ||
4371 | static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd) | |
4372 | { | |
4373 | unsigned int timeout = atoi(cmd); | |
e9eb648e JM |
4374 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
4375 | wpa_dbg(wpa_s, MSG_INFO, | |
4376 | "Reject P2P_LISTEN since interface is disabled"); | |
4377 | return -1; | |
4378 | } | |
b563b388 JM |
4379 | return wpas_p2p_listen(wpa_s, timeout); |
4380 | } | |
4381 | ||
4382 | ||
4383 | static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) | |
4384 | { | |
4385 | u8 addr[ETH_ALEN]; | |
4386 | char *pos; | |
0918c4bf | 4387 | enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG; |
b563b388 | 4388 | |
0918c4bf | 4389 | /* <addr> <config method> [join|auto] */ |
b563b388 JM |
4390 | |
4391 | if (hwaddr_aton(cmd, addr)) | |
4392 | return -1; | |
4393 | ||
4394 | pos = cmd + 17; | |
4395 | if (*pos != ' ') | |
4396 | return -1; | |
4397 | pos++; | |
4398 | ||
0918c4bf JM |
4399 | if (os_strstr(pos, " join") != NULL) |
4400 | use = WPAS_P2P_PD_FOR_JOIN; | |
4401 | else if (os_strstr(pos, " auto") != NULL) | |
4402 | use = WPAS_P2P_PD_AUTO; | |
4403 | ||
4404 | return wpas_p2p_prov_disc(wpa_s, addr, pos, use); | |
b563b388 JM |
4405 | } |
4406 | ||
4407 | ||
4408 | static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf, | |
4409 | size_t buflen) | |
4410 | { | |
4411 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
4412 | ||
4413 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || | |
4414 | ssid->passphrase == NULL) | |
4415 | return -1; | |
4416 | ||
4417 | os_strlcpy(buf, ssid->passphrase, buflen); | |
4418 | return os_strlen(buf); | |
4419 | } | |
4420 | ||
4421 | ||
4422 | static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd, | |
4423 | char *buf, size_t buflen) | |
4424 | { | |
4425 | u64 ref; | |
4426 | int res; | |
4427 | u8 dst_buf[ETH_ALEN], *dst; | |
4428 | struct wpabuf *tlvs; | |
4429 | char *pos; | |
4430 | size_t len; | |
4431 | ||
4432 | if (hwaddr_aton(cmd, dst_buf)) | |
4433 | return -1; | |
4434 | dst = dst_buf; | |
4435 | if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 && | |
4436 | dst[3] == 0 && dst[4] == 0 && dst[5] == 0) | |
4437 | dst = NULL; | |
4438 | pos = cmd + 17; | |
4439 | if (*pos != ' ') | |
4440 | return -1; | |
4441 | pos++; | |
4442 | ||
4443 | if (os_strncmp(pos, "upnp ", 5) == 0) { | |
4444 | u8 version; | |
4445 | pos += 5; | |
4446 | if (hexstr2bin(pos, &version, 1) < 0) | |
4447 | return -1; | |
4448 | pos += 2; | |
4449 | if (*pos != ' ') | |
4450 | return -1; | |
4451 | pos++; | |
7165c5dc | 4452 | ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos); |
347d6a5b JM |
4453 | #ifdef CONFIG_WIFI_DISPLAY |
4454 | } else if (os_strncmp(pos, "wifi-display ", 13) == 0) { | |
4455 | ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13); | |
4456 | #endif /* CONFIG_WIFI_DISPLAY */ | |
b563b388 JM |
4457 | } else { |
4458 | len = os_strlen(pos); | |
4459 | if (len & 1) | |
4460 | return -1; | |
4461 | len /= 2; | |
4462 | tlvs = wpabuf_alloc(len); | |
4463 | if (tlvs == NULL) | |
4464 | return -1; | |
4465 | if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) { | |
4466 | wpabuf_free(tlvs); | |
4467 | return -1; | |
4468 | } | |
4469 | ||
7165c5dc | 4470 | ref = wpas_p2p_sd_request(wpa_s, dst, tlvs); |
b563b388 JM |
4471 | wpabuf_free(tlvs); |
4472 | } | |
7165c5dc JM |
4473 | if (ref == 0) |
4474 | return -1; | |
b563b388 JM |
4475 | res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref); |
4476 | if (res < 0 || (unsigned) res >= buflen) | |
4477 | return -1; | |
4478 | return res; | |
4479 | } | |
4480 | ||
4481 | ||
4482 | static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s, | |
4483 | char *cmd) | |
4484 | { | |
4485 | long long unsigned val; | |
4486 | u64 req; | |
4487 | if (sscanf(cmd, "%llx", &val) != 1) | |
4488 | return -1; | |
4489 | req = val; | |
7165c5dc | 4490 | return wpas_p2p_sd_cancel_request(wpa_s, req); |
b563b388 JM |
4491 | } |
4492 | ||
4493 | ||
4494 | static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd) | |
4495 | { | |
4496 | int freq; | |
d25f7212 | 4497 | u8 dst[ETH_ALEN]; |
b563b388 JM |
4498 | u8 dialog_token; |
4499 | struct wpabuf *resp_tlvs; | |
4500 | char *pos, *pos2; | |
4501 | size_t len; | |
4502 | ||
4503 | pos = os_strchr(cmd, ' '); | |
4504 | if (pos == NULL) | |
4505 | return -1; | |
4506 | *pos++ = '\0'; | |
4507 | freq = atoi(cmd); | |
4508 | if (freq == 0) | |
4509 | return -1; | |
4510 | ||
d25f7212 | 4511 | if (hwaddr_aton(pos, dst)) |
b563b388 | 4512 | return -1; |
b563b388 JM |
4513 | pos += 17; |
4514 | if (*pos != ' ') | |
4515 | return -1; | |
4516 | pos++; | |
4517 | ||
4518 | pos2 = os_strchr(pos, ' '); | |
4519 | if (pos2 == NULL) | |
4520 | return -1; | |
4521 | *pos2++ = '\0'; | |
4522 | dialog_token = atoi(pos); | |
4523 | ||
4524 | len = os_strlen(pos2); | |
4525 | if (len & 1) | |
4526 | return -1; | |
4527 | len /= 2; | |
4528 | resp_tlvs = wpabuf_alloc(len); | |
4529 | if (resp_tlvs == NULL) | |
4530 | return -1; | |
4531 | if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) { | |
4532 | wpabuf_free(resp_tlvs); | |
4533 | return -1; | |
4534 | } | |
4535 | ||
4536 | wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs); | |
4537 | wpabuf_free(resp_tlvs); | |
4538 | return 0; | |
4539 | } | |
4540 | ||
4541 | ||
4542 | static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s, | |
4543 | char *cmd) | |
4544 | { | |
28ef705d GB |
4545 | if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1")) |
4546 | return -1; | |
b563b388 JM |
4547 | wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd); |
4548 | return 0; | |
4549 | } | |
4550 | ||
4551 | ||
4552 | static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s, | |
4553 | char *cmd) | |
4554 | { | |
4555 | char *pos; | |
4556 | size_t len; | |
4557 | struct wpabuf *query, *resp; | |
4558 | ||
4559 | pos = os_strchr(cmd, ' '); | |
4560 | if (pos == NULL) | |
4561 | return -1; | |
4562 | *pos++ = '\0'; | |
4563 | ||
4564 | len = os_strlen(cmd); | |
4565 | if (len & 1) | |
4566 | return -1; | |
4567 | len /= 2; | |
4568 | query = wpabuf_alloc(len); | |
4569 | if (query == NULL) | |
4570 | return -1; | |
4571 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | |
4572 | wpabuf_free(query); | |
4573 | return -1; | |
4574 | } | |
4575 | ||
4576 | len = os_strlen(pos); | |
4577 | if (len & 1) { | |
4578 | wpabuf_free(query); | |
4579 | return -1; | |
4580 | } | |
4581 | len /= 2; | |
4582 | resp = wpabuf_alloc(len); | |
4583 | if (resp == NULL) { | |
4584 | wpabuf_free(query); | |
4585 | return -1; | |
4586 | } | |
4587 | if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) { | |
4588 | wpabuf_free(query); | |
4589 | wpabuf_free(resp); | |
4590 | return -1; | |
4591 | } | |
4592 | ||
4593 | if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) { | |
4594 | wpabuf_free(query); | |
4595 | wpabuf_free(resp); | |
4596 | return -1; | |
4597 | } | |
4598 | return 0; | |
4599 | } | |
4600 | ||
4601 | ||
4602 | static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd) | |
4603 | { | |
4604 | char *pos; | |
4605 | u8 version; | |
4606 | ||
4607 | pos = os_strchr(cmd, ' '); | |
4608 | if (pos == NULL) | |
4609 | return -1; | |
4610 | *pos++ = '\0'; | |
4611 | ||
4612 | if (hexstr2bin(cmd, &version, 1) < 0) | |
4613 | return -1; | |
4614 | ||
4615 | return wpas_p2p_service_add_upnp(wpa_s, version, pos); | |
4616 | } | |
4617 | ||
4618 | ||
4619 | static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd) | |
4620 | { | |
4621 | char *pos; | |
4622 | ||
4623 | pos = os_strchr(cmd, ' '); | |
4624 | if (pos == NULL) | |
4625 | return -1; | |
4626 | *pos++ = '\0'; | |
4627 | ||
4628 | if (os_strcmp(cmd, "bonjour") == 0) | |
4629 | return p2p_ctrl_service_add_bonjour(wpa_s, pos); | |
4630 | if (os_strcmp(cmd, "upnp") == 0) | |
4631 | return p2p_ctrl_service_add_upnp(wpa_s, pos); | |
4632 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | |
4633 | return -1; | |
4634 | } | |
4635 | ||
4636 | ||
4637 | static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s, | |
4638 | char *cmd) | |
4639 | { | |
4640 | size_t len; | |
4641 | struct wpabuf *query; | |
4642 | int ret; | |
4643 | ||
4644 | len = os_strlen(cmd); | |
4645 | if (len & 1) | |
4646 | return -1; | |
4647 | len /= 2; | |
4648 | query = wpabuf_alloc(len); | |
4649 | if (query == NULL) | |
4650 | return -1; | |
4651 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | |
4652 | wpabuf_free(query); | |
4653 | return -1; | |
4654 | } | |
4655 | ||
4656 | ret = wpas_p2p_service_del_bonjour(wpa_s, query); | |
4657 | wpabuf_free(query); | |
4658 | return ret; | |
4659 | } | |
4660 | ||
4661 | ||
4662 | static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd) | |
4663 | { | |
4664 | char *pos; | |
4665 | u8 version; | |
4666 | ||
4667 | pos = os_strchr(cmd, ' '); | |
4668 | if (pos == NULL) | |
4669 | return -1; | |
4670 | *pos++ = '\0'; | |
4671 | ||
4672 | if (hexstr2bin(cmd, &version, 1) < 0) | |
4673 | return -1; | |
4674 | ||
4675 | return wpas_p2p_service_del_upnp(wpa_s, version, pos); | |
4676 | } | |
4677 | ||
4678 | ||
4679 | static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd) | |
4680 | { | |
4681 | char *pos; | |
4682 | ||
4683 | pos = os_strchr(cmd, ' '); | |
4684 | if (pos == NULL) | |
4685 | return -1; | |
4686 | *pos++ = '\0'; | |
4687 | ||
4688 | if (os_strcmp(cmd, "bonjour") == 0) | |
4689 | return p2p_ctrl_service_del_bonjour(wpa_s, pos); | |
4690 | if (os_strcmp(cmd, "upnp") == 0) | |
4691 | return p2p_ctrl_service_del_upnp(wpa_s, pos); | |
4692 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | |
4693 | return -1; | |
4694 | } | |
4695 | ||
4696 | ||
4697 | static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd) | |
4698 | { | |
4699 | u8 addr[ETH_ALEN]; | |
4700 | ||
4701 | /* <addr> */ | |
4702 | ||
4703 | if (hwaddr_aton(cmd, addr)) | |
4704 | return -1; | |
4705 | ||
4706 | return wpas_p2p_reject(wpa_s, addr); | |
4707 | } | |
4708 | ||
4709 | ||
4710 | static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd) | |
4711 | { | |
4712 | char *pos; | |
4713 | int id; | |
4714 | struct wpa_ssid *ssid; | |
54c61e6e | 4715 | u8 *_peer = NULL, peer[ETH_ALEN]; |
f5877af0 | 4716 | int freq = 0, pref_freq = 0; |
20ea1ca4 | 4717 | int ht40, vht; |
b563b388 JM |
4718 | |
4719 | id = atoi(cmd); | |
4720 | pos = os_strstr(cmd, " peer="); | |
4721 | if (pos) { | |
4722 | pos += 6; | |
4723 | if (hwaddr_aton(pos, peer)) | |
4724 | return -1; | |
54c61e6e | 4725 | _peer = peer; |
b563b388 JM |
4726 | } |
4727 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
4728 | if (ssid == NULL || ssid->disabled != 2) { | |
4729 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
4730 | "for persistent P2P group", | |
4731 | id); | |
4732 | return -1; | |
4733 | } | |
4734 | ||
4d32c0c4 JM |
4735 | pos = os_strstr(cmd, " freq="); |
4736 | if (pos) { | |
4737 | pos += 6; | |
4738 | freq = atoi(pos); | |
4739 | if (freq <= 0) | |
4740 | return -1; | |
4741 | } | |
4742 | ||
f5877af0 JM |
4743 | pos = os_strstr(cmd, " pref="); |
4744 | if (pos) { | |
4745 | pos += 6; | |
4746 | pref_freq = atoi(pos); | |
4747 | if (pref_freq <= 0) | |
4748 | return -1; | |
4749 | } | |
4750 | ||
20ea1ca4 EP |
4751 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
4752 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | |
4753 | vht; | |
4d32c0c4 | 4754 | |
20ea1ca4 EP |
4755 | return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht, |
4756 | pref_freq); | |
b563b388 JM |
4757 | } |
4758 | ||
4759 | ||
4760 | static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd) | |
4761 | { | |
4762 | char *pos; | |
4763 | u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL; | |
4764 | ||
4765 | pos = os_strstr(cmd, " peer="); | |
4766 | if (!pos) | |
4767 | return -1; | |
4768 | ||
4769 | *pos = '\0'; | |
4770 | pos += 6; | |
4771 | if (hwaddr_aton(pos, peer)) { | |
4772 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos); | |
4773 | return -1; | |
4774 | } | |
4775 | ||
4776 | pos = os_strstr(pos, " go_dev_addr="); | |
4777 | if (pos) { | |
4778 | pos += 13; | |
4779 | if (hwaddr_aton(pos, go_dev_addr)) { | |
4780 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", | |
4781 | pos); | |
4782 | return -1; | |
4783 | } | |
4784 | go_dev = go_dev_addr; | |
4785 | } | |
4786 | ||
4787 | return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev); | |
4788 | } | |
4789 | ||
4790 | ||
4791 | static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd) | |
4792 | { | |
4793 | if (os_strncmp(cmd, "persistent=", 11) == 0) | |
4794 | return p2p_ctrl_invite_persistent(wpa_s, cmd + 11); | |
4795 | if (os_strncmp(cmd, "group=", 6) == 0) | |
4796 | return p2p_ctrl_invite_group(wpa_s, cmd + 6); | |
4797 | ||
4798 | return -1; | |
4799 | } | |
4800 | ||
4801 | ||
4802 | static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, | |
20ea1ca4 EP |
4803 | char *cmd, int freq, int ht40, |
4804 | int vht) | |
b563b388 JM |
4805 | { |
4806 | int id; | |
4807 | struct wpa_ssid *ssid; | |
4808 | ||
4809 | id = atoi(cmd); | |
4810 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
4811 | if (ssid == NULL || ssid->disabled != 2) { | |
4812 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
4813 | "for persistent P2P group", | |
4814 | id); | |
4815 | return -1; | |
4816 | } | |
4817 | ||
062a7c0d | 4818 | return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht, |
20ea1ca4 | 4819 | NULL, 0); |
b563b388 JM |
4820 | } |
4821 | ||
4822 | ||
4823 | static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) | |
4824 | { | |
20ea1ca4 | 4825 | int freq = 0, ht40, vht; |
b563b388 JM |
4826 | char *pos; |
4827 | ||
4828 | pos = os_strstr(cmd, "freq="); | |
4829 | if (pos) | |
4830 | freq = atoi(pos + 5); | |
4831 | ||
20ea1ca4 EP |
4832 | vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht; |
4833 | ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | |
4834 | vht; | |
7aeac985 | 4835 | |
b563b388 | 4836 | if (os_strncmp(cmd, "persistent=", 11) == 0) |
7aeac985 | 4837 | return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq, |
20ea1ca4 | 4838 | ht40, vht); |
b563b388 JM |
4839 | if (os_strcmp(cmd, "persistent") == 0 || |
4840 | os_strncmp(cmd, "persistent ", 11) == 0) | |
20ea1ca4 | 4841 | return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht); |
b563b388 | 4842 | if (os_strncmp(cmd, "freq=", 5) == 0) |
20ea1ca4 | 4843 | return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht); |
7aeac985 | 4844 | if (ht40) |
20ea1ca4 | 4845 | return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht); |
b563b388 JM |
4846 | |
4847 | wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'", | |
4848 | cmd); | |
4849 | return -1; | |
4850 | } | |
4851 | ||
4852 | ||
4853 | static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd, | |
4854 | char *buf, size_t buflen) | |
4855 | { | |
4856 | u8 addr[ETH_ALEN], *addr_ptr; | |
b3ffc80b JM |
4857 | int next, res; |
4858 | const struct p2p_peer_info *info; | |
4859 | char *pos, *end; | |
4860 | char devtype[WPS_DEV_TYPE_BUFSIZE]; | |
87f841a1 | 4861 | struct wpa_ssid *ssid; |
f3989ced | 4862 | size_t i; |
b563b388 JM |
4863 | |
4864 | if (!wpa_s->global->p2p) | |
4865 | return -1; | |
4866 | ||
4867 | if (os_strcmp(cmd, "FIRST") == 0) { | |
4868 | addr_ptr = NULL; | |
4869 | next = 0; | |
4870 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | |
4871 | if (hwaddr_aton(cmd + 5, addr) < 0) | |
4872 | return -1; | |
4873 | addr_ptr = addr; | |
4874 | next = 1; | |
4875 | } else { | |
4876 | if (hwaddr_aton(cmd, addr) < 0) | |
4877 | return -1; | |
4878 | addr_ptr = addr; | |
4879 | next = 0; | |
4880 | } | |
4881 | ||
b3ffc80b JM |
4882 | info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next); |
4883 | if (info == NULL) | |
4884 | return -1; | |
4885 | ||
4886 | pos = buf; | |
4887 | end = buf + buflen; | |
4888 | ||
4889 | res = os_snprintf(pos, end - pos, MACSTR "\n" | |
4890 | "pri_dev_type=%s\n" | |
4891 | "device_name=%s\n" | |
4892 | "manufacturer=%s\n" | |
4893 | "model_name=%s\n" | |
4894 | "model_number=%s\n" | |
4895 | "serial_number=%s\n" | |
4896 | "config_methods=0x%x\n" | |
4897 | "dev_capab=0x%x\n" | |
4898 | "group_capab=0x%x\n" | |
4899 | "level=%d\n", | |
4900 | MAC2STR(info->p2p_device_addr), | |
4901 | wps_dev_type_bin2str(info->pri_dev_type, | |
4902 | devtype, sizeof(devtype)), | |
4903 | info->device_name, | |
4904 | info->manufacturer, | |
4905 | info->model_name, | |
4906 | info->model_number, | |
4907 | info->serial_number, | |
4908 | info->config_methods, | |
4909 | info->dev_capab, | |
4910 | info->group_capab, | |
4911 | info->level); | |
4912 | if (res < 0 || res >= end - pos) | |
4913 | return pos - buf; | |
4914 | pos += res; | |
4915 | ||
f3989ced JM |
4916 | for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++) |
4917 | { | |
4918 | const u8 *t; | |
4919 | t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN]; | |
4920 | res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n", | |
4921 | wps_dev_type_bin2str(t, devtype, | |
4922 | sizeof(devtype))); | |
4923 | if (res < 0 || res >= end - pos) | |
4924 | return pos - buf; | |
4925 | pos += res; | |
4926 | } | |
4927 | ||
c427ac92 | 4928 | ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0); |
87f841a1 JM |
4929 | if (ssid) { |
4930 | res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id); | |
4931 | if (res < 0 || res >= end - pos) | |
4932 | return pos - buf; | |
4933 | pos += res; | |
4934 | } | |
4935 | ||
b3ffc80b JM |
4936 | res = p2p_get_peer_info_txt(info, pos, end - pos); |
4937 | if (res < 0) | |
87f841a1 | 4938 | return pos - buf; |
b3ffc80b JM |
4939 | pos += res; |
4940 | ||
71a0e395 JM |
4941 | if (info->vendor_elems) { |
4942 | res = os_snprintf(pos, end - pos, "vendor_elems="); | |
4943 | if (res < 0 || res >= end - pos) | |
4944 | return pos - buf; | |
4945 | pos += res; | |
4946 | ||
4947 | pos += wpa_snprintf_hex(pos, end - pos, | |
4948 | wpabuf_head(info->vendor_elems), | |
4949 | wpabuf_len(info->vendor_elems)); | |
4950 | ||
4951 | res = os_snprintf(pos, end - pos, "\n"); | |
4952 | if (res < 0 || res >= end - pos) | |
4953 | return pos - buf; | |
4954 | pos += res; | |
4955 | } | |
4956 | ||
b3ffc80b | 4957 | return pos - buf; |
b563b388 JM |
4958 | } |
4959 | ||
4960 | ||
6f3bc72b JM |
4961 | static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s, |
4962 | const char *param) | |
4963 | { | |
af8a827b | 4964 | unsigned int i; |
6f3bc72b JM |
4965 | |
4966 | if (wpa_s->global->p2p == NULL) | |
4967 | return -1; | |
4968 | ||
af8a827b JM |
4969 | if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0) |
4970 | return -1; | |
6f3bc72b | 4971 | |
af8a827b JM |
4972 | for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) { |
4973 | struct wpa_freq_range *freq; | |
4974 | freq = &wpa_s->global->p2p_disallow_freq.range[i]; | |
6f3bc72b | 4975 | wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u", |
af8a827b | 4976 | freq->min, freq->max); |
6f3bc72b JM |
4977 | } |
4978 | ||
6f3bc72b JM |
4979 | wpas_p2p_update_channel_list(wpa_s); |
4980 | return 0; | |
4981 | } | |
4982 | ||
4983 | ||
b563b388 JM |
4984 | static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) |
4985 | { | |
4986 | char *param; | |
4987 | ||
4988 | if (wpa_s->global->p2p == NULL) | |
4989 | return -1; | |
4990 | ||
4991 | param = os_strchr(cmd, ' '); | |
4992 | if (param == NULL) | |
4993 | return -1; | |
4994 | *param++ = '\0'; | |
4995 | ||
4996 | if (os_strcmp(cmd, "discoverability") == 0) { | |
4997 | p2p_set_client_discoverability(wpa_s->global->p2p, | |
4998 | atoi(param)); | |
4999 | return 0; | |
5000 | } | |
5001 | ||
5002 | if (os_strcmp(cmd, "managed") == 0) { | |
5003 | p2p_set_managed_oper(wpa_s->global->p2p, atoi(param)); | |
5004 | return 0; | |
5005 | } | |
5006 | ||
5007 | if (os_strcmp(cmd, "listen_channel") == 0) { | |
5008 | return p2p_set_listen_channel(wpa_s->global->p2p, 81, | |
e3bd6e9d | 5009 | atoi(param), 1); |
b563b388 JM |
5010 | } |
5011 | ||
5012 | if (os_strcmp(cmd, "ssid_postfix") == 0) { | |
5013 | return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param, | |
5014 | os_strlen(param)); | |
5015 | } | |
5016 | ||
5017 | if (os_strcmp(cmd, "noa") == 0) { | |
5018 | char *pos; | |
5019 | int count, start, duration; | |
5020 | /* GO NoA parameters: count,start_offset(ms),duration(ms) */ | |
5021 | count = atoi(param); | |
5022 | pos = os_strchr(param, ','); | |
5023 | if (pos == NULL) | |
5024 | return -1; | |
5025 | pos++; | |
5026 | start = atoi(pos); | |
5027 | pos = os_strchr(pos, ','); | |
5028 | if (pos == NULL) | |
5029 | return -1; | |
5030 | pos++; | |
5031 | duration = atoi(pos); | |
5032 | if (count < 0 || count > 255 || start < 0 || duration < 0) | |
5033 | return -1; | |
5034 | if (count == 0 && duration > 0) | |
5035 | return -1; | |
5036 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d " | |
5037 | "start=%d duration=%d", count, start, duration); | |
aefb53bd | 5038 | return wpas_p2p_set_noa(wpa_s, count, start, duration); |
b563b388 JM |
5039 | } |
5040 | ||
c381508d JM |
5041 | if (os_strcmp(cmd, "ps") == 0) |
5042 | return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1); | |
5043 | ||
5044 | if (os_strcmp(cmd, "oppps") == 0) | |
5045 | return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1); | |
5046 | ||
5047 | if (os_strcmp(cmd, "ctwindow") == 0) | |
5048 | return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param)); | |
5049 | ||
b563b388 JM |
5050 | if (os_strcmp(cmd, "disabled") == 0) { |
5051 | wpa_s->global->p2p_disabled = atoi(param); | |
5052 | wpa_printf(MSG_DEBUG, "P2P functionality %s", | |
5053 | wpa_s->global->p2p_disabled ? | |
5054 | "disabled" : "enabled"); | |
5055 | if (wpa_s->global->p2p_disabled) { | |
5056 | wpas_p2p_stop_find(wpa_s); | |
108def93 | 5057 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
b563b388 JM |
5058 | p2p_flush(wpa_s->global->p2p); |
5059 | } | |
5060 | return 0; | |
5061 | } | |
5062 | ||
b9cfc09a JJ |
5063 | if (os_strcmp(cmd, "conc_pref") == 0) { |
5064 | if (os_strcmp(param, "sta") == 0) | |
5065 | wpa_s->global->conc_pref = WPA_CONC_PREF_STA; | |
5066 | else if (os_strcmp(param, "p2p") == 0) | |
5067 | wpa_s->global->conc_pref = WPA_CONC_PREF_P2P; | |
5068 | else { | |
5069 | wpa_printf(MSG_INFO, "Invalid conc_pref value"); | |
5070 | return -1; | |
5071 | } | |
5072 | wpa_printf(MSG_DEBUG, "Single channel concurrency preference: " | |
5073 | "%s", param); | |
5074 | return 0; | |
5075 | } | |
5076 | ||
6e6963ea JM |
5077 | if (os_strcmp(cmd, "force_long_sd") == 0) { |
5078 | wpa_s->force_long_sd = atoi(param); | |
5079 | return 0; | |
5080 | } | |
5081 | ||
80c9582a JM |
5082 | if (os_strcmp(cmd, "peer_filter") == 0) { |
5083 | u8 addr[ETH_ALEN]; | |
5084 | if (hwaddr_aton(param, addr)) | |
5085 | return -1; | |
5086 | p2p_set_peer_filter(wpa_s->global->p2p, addr); | |
5087 | return 0; | |
5088 | } | |
5089 | ||
72044390 JM |
5090 | if (os_strcmp(cmd, "cross_connect") == 0) |
5091 | return wpas_p2p_set_cross_connect(wpa_s, atoi(param)); | |
5092 | ||
eea2fd9e JM |
5093 | if (os_strcmp(cmd, "go_apsd") == 0) { |
5094 | if (os_strcmp(param, "disable") == 0) | |
5095 | wpa_s->set_ap_uapsd = 0; | |
5096 | else { | |
5097 | wpa_s->set_ap_uapsd = 1; | |
5098 | wpa_s->ap_uapsd = atoi(param); | |
5099 | } | |
5100 | return 0; | |
5101 | } | |
5102 | ||
5103 | if (os_strcmp(cmd, "client_apsd") == 0) { | |
5104 | if (os_strcmp(param, "disable") == 0) | |
5105 | wpa_s->set_sta_uapsd = 0; | |
5106 | else { | |
5107 | int be, bk, vi, vo; | |
5108 | char *pos; | |
5109 | /* format: BE,BK,VI,VO;max SP Length */ | |
5110 | be = atoi(param); | |
5111 | pos = os_strchr(param, ','); | |
5112 | if (pos == NULL) | |
5113 | return -1; | |
5114 | pos++; | |
5115 | bk = atoi(pos); | |
5116 | pos = os_strchr(pos, ','); | |
5117 | if (pos == NULL) | |
5118 | return -1; | |
5119 | pos++; | |
5120 | vi = atoi(pos); | |
5121 | pos = os_strchr(pos, ','); | |
5122 | if (pos == NULL) | |
5123 | return -1; | |
5124 | pos++; | |
5125 | vo = atoi(pos); | |
5126 | /* ignore max SP Length for now */ | |
5127 | ||
5128 | wpa_s->set_sta_uapsd = 1; | |
5129 | wpa_s->sta_uapsd = 0; | |
5130 | if (be) | |
5131 | wpa_s->sta_uapsd |= BIT(0); | |
5132 | if (bk) | |
5133 | wpa_s->sta_uapsd |= BIT(1); | |
5134 | if (vi) | |
5135 | wpa_s->sta_uapsd |= BIT(2); | |
5136 | if (vo) | |
5137 | wpa_s->sta_uapsd |= BIT(3); | |
5138 | } | |
5139 | return 0; | |
5140 | } | |
5141 | ||
6f3bc72b JM |
5142 | if (os_strcmp(cmd, "disallow_freq") == 0) |
5143 | return p2p_ctrl_disallow_freq(wpa_s, param); | |
5144 | ||
96beff11 JM |
5145 | if (os_strcmp(cmd, "disc_int") == 0) { |
5146 | int min_disc_int, max_disc_int, max_disc_tu; | |
5147 | char *pos; | |
5148 | ||
5149 | pos = param; | |
5150 | ||
5151 | min_disc_int = atoi(pos); | |
5152 | pos = os_strchr(pos, ' '); | |
5153 | if (pos == NULL) | |
5154 | return -1; | |
5155 | *pos++ = '\0'; | |
5156 | ||
5157 | max_disc_int = atoi(pos); | |
5158 | pos = os_strchr(pos, ' '); | |
5159 | if (pos == NULL) | |
5160 | return -1; | |
5161 | *pos++ = '\0'; | |
5162 | ||
5163 | max_disc_tu = atoi(pos); | |
5164 | ||
5165 | return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int, | |
5166 | max_disc_int, max_disc_tu); | |
5167 | } | |
5168 | ||
05766ed8 JM |
5169 | if (os_strcmp(cmd, "per_sta_psk") == 0) { |
5170 | wpa_s->global->p2p_per_sta_psk = !!atoi(param); | |
5171 | return 0; | |
5172 | } | |
5173 | ||
c4f87a70 JM |
5174 | #ifdef CONFIG_WPS_NFC |
5175 | if (os_strcmp(cmd, "nfc_tag") == 0) | |
5176 | return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param)); | |
5177 | #endif /* CONFIG_WPS_NFC */ | |
5178 | ||
201b0f5f JM |
5179 | if (os_strcmp(cmd, "disable_ip_addr_req") == 0) { |
5180 | wpa_s->p2p_disable_ip_addr_req = !!atoi(param); | |
5181 | return 0; | |
5182 | } | |
5183 | ||
b563b388 JM |
5184 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", |
5185 | cmd); | |
5186 | ||
5187 | return -1; | |
5188 | } | |
5189 | ||
5190 | ||
acb54643 JM |
5191 | static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s) |
5192 | { | |
5193 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); | |
5194 | wpa_s->force_long_sd = 0; | |
477b082c | 5195 | wpas_p2p_stop_find(wpa_s); |
acb54643 JM |
5196 | if (wpa_s->global->p2p) |
5197 | p2p_flush(wpa_s->global->p2p); | |
5198 | } | |
5199 | ||
5200 | ||
b563b388 JM |
5201 | static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd) |
5202 | { | |
5203 | char *pos, *pos2; | |
5204 | unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0; | |
5205 | ||
5206 | if (cmd[0]) { | |
5207 | pos = os_strchr(cmd, ' '); | |
5208 | if (pos == NULL) | |
5209 | return -1; | |
5210 | *pos++ = '\0'; | |
5211 | dur1 = atoi(cmd); | |
5212 | ||
5213 | pos2 = os_strchr(pos, ' '); | |
5214 | if (pos2) | |
5215 | *pos2++ = '\0'; | |
5216 | int1 = atoi(pos); | |
5217 | } else | |
5218 | pos2 = NULL; | |
5219 | ||
5220 | if (pos2) { | |
5221 | pos = os_strchr(pos2, ' '); | |
5222 | if (pos == NULL) | |
5223 | return -1; | |
5224 | *pos++ = '\0'; | |
5225 | dur2 = atoi(pos2); | |
5226 | int2 = atoi(pos); | |
5227 | } | |
5228 | ||
5229 | return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2); | |
5230 | } | |
5231 | ||
5232 | ||
5233 | static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) | |
5234 | { | |
5235 | char *pos; | |
5236 | unsigned int period = 0, interval = 0; | |
5237 | ||
5238 | if (cmd[0]) { | |
5239 | pos = os_strchr(cmd, ' '); | |
5240 | if (pos == NULL) | |
5241 | return -1; | |
5242 | *pos++ = '\0'; | |
5243 | period = atoi(cmd); | |
5244 | interval = atoi(pos); | |
5245 | } | |
5246 | ||
5247 | return wpas_p2p_ext_listen(wpa_s, period, interval); | |
5248 | } | |
5249 | ||
f2c56602 JM |
5250 | |
5251 | static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd) | |
5252 | { | |
5253 | const char *pos; | |
5254 | u8 peer[ETH_ALEN]; | |
5255 | int iface_addr = 0; | |
5256 | ||
5257 | pos = cmd; | |
5258 | if (os_strncmp(pos, "iface=", 6) == 0) { | |
5259 | iface_addr = 1; | |
5260 | pos += 6; | |
5261 | } | |
5262 | if (hwaddr_aton(pos, peer)) | |
5263 | return -1; | |
5264 | ||
5265 | wpas_p2p_remove_client(wpa_s, peer, iface_addr); | |
5266 | return 0; | |
5267 | } | |
5268 | ||
b563b388 JM |
5269 | #endif /* CONFIG_P2P */ |
5270 | ||
5271 | ||
356d1488 JM |
5272 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val) |
5273 | { | |
5274 | struct wpa_freq_range_list ranges; | |
5275 | int *freqs = NULL; | |
5276 | struct hostapd_hw_modes *mode; | |
5277 | u16 i; | |
5278 | ||
5279 | if (wpa_s->hw.modes == NULL) | |
5280 | return NULL; | |
5281 | ||
5282 | os_memset(&ranges, 0, sizeof(ranges)); | |
5283 | if (freq_range_list_parse(&ranges, val) < 0) | |
5284 | return NULL; | |
5285 | ||
5286 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
5287 | int j; | |
5288 | ||
5289 | mode = &wpa_s->hw.modes[i]; | |
5290 | for (j = 0; j < mode->num_channels; j++) { | |
5291 | unsigned int freq; | |
5292 | ||
5293 | if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED) | |
5294 | continue; | |
5295 | ||
5296 | freq = mode->channels[j].freq; | |
5297 | if (!freq_range_list_includes(&ranges, freq)) | |
5298 | continue; | |
5299 | ||
5300 | int_array_add_unique(&freqs, freq); | |
5301 | } | |
5302 | } | |
5303 | ||
5304 | os_free(ranges.range); | |
5305 | return freqs; | |
5306 | } | |
5307 | ||
5308 | ||
afc064fe | 5309 | #ifdef CONFIG_INTERWORKING |
356d1488 JM |
5310 | |
5311 | static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param) | |
5312 | { | |
5313 | int auto_sel = 0; | |
5314 | int *freqs = NULL; | |
5315 | ||
5316 | if (param) { | |
5317 | char *pos; | |
5318 | ||
5319 | auto_sel = os_strstr(param, "auto") != NULL; | |
5320 | ||
5321 | pos = os_strstr(param, "freq="); | |
5322 | if (pos) { | |
5323 | freqs = freq_range_to_channel_list(wpa_s, pos + 5); | |
5324 | if (freqs == NULL) | |
5325 | return -1; | |
5326 | } | |
5327 | ||
5328 | } | |
5329 | ||
5330 | return interworking_select(wpa_s, auto_sel, freqs); | |
5331 | } | |
5332 | ||
5333 | ||
b02fe7ff JM |
5334 | static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst) |
5335 | { | |
5336 | u8 bssid[ETH_ALEN]; | |
5337 | struct wpa_bss *bss; | |
5338 | ||
5339 | if (hwaddr_aton(dst, bssid)) { | |
5340 | wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst); | |
5341 | return -1; | |
5342 | } | |
5343 | ||
5344 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
5345 | if (bss == NULL) { | |
5346 | wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR, | |
5347 | MAC2STR(bssid)); | |
5348 | return -1; | |
5349 | } | |
5350 | ||
5351 | return interworking_connect(wpa_s, bss); | |
5352 | } | |
5353 | ||
5354 | ||
afc064fe JM |
5355 | static int get_anqp(struct wpa_supplicant *wpa_s, char *dst) |
5356 | { | |
5357 | u8 dst_addr[ETH_ALEN]; | |
5358 | int used; | |
5359 | char *pos; | |
5360 | #define MAX_ANQP_INFO_ID 100 | |
5361 | u16 id[MAX_ANQP_INFO_ID]; | |
5362 | size_t num_id = 0; | |
cf28c66b | 5363 | u32 subtypes = 0; |
afc064fe JM |
5364 | |
5365 | used = hwaddr_aton2(dst, dst_addr); | |
5366 | if (used < 0) | |
5367 | return -1; | |
5368 | pos = dst + used; | |
5369 | while (num_id < MAX_ANQP_INFO_ID) { | |
cf28c66b DS |
5370 | if (os_strncmp(pos, "hs20:", 5) == 0) { |
5371 | #ifdef CONFIG_HS20 | |
5372 | int num = atoi(pos + 5); | |
5373 | if (num <= 0 || num > 31) | |
5374 | return -1; | |
5375 | subtypes |= BIT(num); | |
5376 | #else /* CONFIG_HS20 */ | |
5377 | return -1; | |
5378 | #endif /* CONFIG_HS20 */ | |
5379 | } else { | |
5380 | id[num_id] = atoi(pos); | |
5381 | if (id[num_id]) | |
5382 | num_id++; | |
5383 | } | |
afc064fe JM |
5384 | pos = os_strchr(pos + 1, ','); |
5385 | if (pos == NULL) | |
5386 | break; | |
5387 | pos++; | |
5388 | } | |
5389 | ||
5390 | if (num_id == 0) | |
5391 | return -1; | |
5392 | ||
cf28c66b | 5393 | return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes); |
afc064fe | 5394 | } |
b1f12296 JM |
5395 | |
5396 | ||
5397 | static int gas_request(struct wpa_supplicant *wpa_s, char *cmd) | |
5398 | { | |
5399 | u8 dst_addr[ETH_ALEN]; | |
5400 | struct wpabuf *advproto, *query = NULL; | |
5401 | int used, ret = -1; | |
5402 | char *pos, *end; | |
5403 | size_t len; | |
5404 | ||
5405 | used = hwaddr_aton2(cmd, dst_addr); | |
5406 | if (used < 0) | |
5407 | return -1; | |
5408 | ||
5409 | pos = cmd + used; | |
5410 | while (*pos == ' ') | |
5411 | pos++; | |
5412 | ||
5413 | /* Advertisement Protocol ID */ | |
5414 | end = os_strchr(pos, ' '); | |
5415 | if (end) | |
5416 | len = end - pos; | |
5417 | else | |
5418 | len = os_strlen(pos); | |
5419 | if (len & 0x01) | |
5420 | return -1; | |
5421 | len /= 2; | |
5422 | if (len == 0) | |
5423 | return -1; | |
5424 | advproto = wpabuf_alloc(len); | |
5425 | if (advproto == NULL) | |
5426 | return -1; | |
5427 | if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0) | |
5428 | goto fail; | |
5429 | ||
5430 | if (end) { | |
5431 | /* Optional Query Request */ | |
5432 | pos = end + 1; | |
5433 | while (*pos == ' ') | |
5434 | pos++; | |
5435 | ||
5436 | len = os_strlen(pos); | |
5437 | if (len) { | |
5438 | if (len & 0x01) | |
5439 | goto fail; | |
5440 | len /= 2; | |
5441 | if (len == 0) | |
5442 | goto fail; | |
5443 | query = wpabuf_alloc(len); | |
5444 | if (query == NULL) | |
5445 | goto fail; | |
5446 | if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0) | |
5447 | goto fail; | |
5448 | } | |
5449 | } | |
5450 | ||
5451 | ret = gas_send_request(wpa_s, dst_addr, advproto, query); | |
5452 | ||
5453 | fail: | |
5454 | wpabuf_free(advproto); | |
5455 | wpabuf_free(query); | |
5456 | ||
5457 | return ret; | |
5458 | } | |
5459 | ||
5460 | ||
5461 | static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf, | |
5462 | size_t buflen) | |
5463 | { | |
5464 | u8 addr[ETH_ALEN]; | |
5465 | int dialog_token; | |
5466 | int used; | |
5467 | char *pos; | |
5468 | size_t resp_len, start, requested_len; | |
b6a9590b JM |
5469 | struct wpabuf *resp; |
5470 | int ret; | |
b1f12296 JM |
5471 | |
5472 | used = hwaddr_aton2(cmd, addr); | |
5473 | if (used < 0) | |
5474 | return -1; | |
5475 | ||
5476 | pos = cmd + used; | |
5477 | while (*pos == ' ') | |
5478 | pos++; | |
5479 | dialog_token = atoi(pos); | |
5480 | ||
b6a9590b JM |
5481 | if (wpa_s->last_gas_resp && |
5482 | os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 && | |
5483 | dialog_token == wpa_s->last_gas_dialog_token) | |
5484 | resp = wpa_s->last_gas_resp; | |
5485 | else if (wpa_s->prev_gas_resp && | |
5486 | os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 && | |
5487 | dialog_token == wpa_s->prev_gas_dialog_token) | |
5488 | resp = wpa_s->prev_gas_resp; | |
5489 | else | |
b1f12296 JM |
5490 | return -1; |
5491 | ||
b6a9590b | 5492 | resp_len = wpabuf_len(resp); |
b1f12296 JM |
5493 | start = 0; |
5494 | requested_len = resp_len; | |
5495 | ||
5496 | pos = os_strchr(pos, ' '); | |
5497 | if (pos) { | |
5498 | start = atoi(pos); | |
5499 | if (start > resp_len) | |
5500 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); | |
5501 | pos = os_strchr(pos, ','); | |
5502 | if (pos == NULL) | |
5503 | return -1; | |
5504 | pos++; | |
5505 | requested_len = atoi(pos); | |
5506 | if (start + requested_len > resp_len) | |
5507 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); | |
5508 | } | |
5509 | ||
5510 | if (requested_len * 2 + 1 > buflen) | |
5511 | return os_snprintf(buf, buflen, "FAIL-Too long response"); | |
5512 | ||
b6a9590b JM |
5513 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start, |
5514 | requested_len); | |
5515 | ||
5516 | if (start + requested_len == resp_len) { | |
5517 | /* | |
5518 | * Free memory by dropping the response after it has been | |
5519 | * fetched. | |
5520 | */ | |
5521 | if (resp == wpa_s->prev_gas_resp) { | |
5522 | wpabuf_free(wpa_s->prev_gas_resp); | |
5523 | wpa_s->prev_gas_resp = NULL; | |
5524 | } else { | |
5525 | wpabuf_free(wpa_s->last_gas_resp); | |
5526 | wpa_s->last_gas_resp = NULL; | |
5527 | } | |
5528 | } | |
5529 | ||
5530 | return ret; | |
b1f12296 | 5531 | } |
afc064fe JM |
5532 | #endif /* CONFIG_INTERWORKING */ |
5533 | ||
5534 | ||
a8918e86 JK |
5535 | #ifdef CONFIG_HS20 |
5536 | ||
5537 | static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst) | |
5538 | { | |
5539 | u8 dst_addr[ETH_ALEN]; | |
5540 | int used; | |
5541 | char *pos; | |
5542 | u32 subtypes = 0; | |
5543 | ||
5544 | used = hwaddr_aton2(dst, dst_addr); | |
5545 | if (used < 0) | |
5546 | return -1; | |
5547 | pos = dst + used; | |
5548 | for (;;) { | |
5549 | int num = atoi(pos); | |
5550 | if (num <= 0 || num > 31) | |
5551 | return -1; | |
5552 | subtypes |= BIT(num); | |
5553 | pos = os_strchr(pos + 1, ','); | |
5554 | if (pos == NULL) | |
5555 | break; | |
5556 | pos++; | |
5557 | } | |
5558 | ||
5559 | if (subtypes == 0) | |
5560 | return -1; | |
5561 | ||
5562 | return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0); | |
5563 | } | |
5564 | ||
5565 | ||
5566 | static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s, | |
5567 | const u8 *addr, const char *realm) | |
5568 | { | |
5569 | u8 *buf; | |
5570 | size_t rlen, len; | |
5571 | int ret; | |
5572 | ||
5573 | rlen = os_strlen(realm); | |
5574 | len = 3 + rlen; | |
5575 | buf = os_malloc(len); | |
5576 | if (buf == NULL) | |
5577 | return -1; | |
5578 | buf[0] = 1; /* NAI Home Realm Count */ | |
5579 | buf[1] = 0; /* Formatted in accordance with RFC 4282 */ | |
5580 | buf[2] = rlen; | |
5581 | os_memcpy(buf + 3, realm, rlen); | |
5582 | ||
5583 | ret = hs20_anqp_send_req(wpa_s, addr, | |
5584 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | |
5585 | buf, len); | |
5586 | ||
5587 | os_free(buf); | |
5588 | ||
5589 | return ret; | |
5590 | } | |
5591 | ||
5592 | ||
5593 | static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s, | |
5594 | char *dst) | |
5595 | { | |
5596 | struct wpa_cred *cred = wpa_s->conf->cred; | |
5597 | u8 dst_addr[ETH_ALEN]; | |
5598 | int used; | |
5599 | u8 *buf; | |
5600 | size_t len; | |
5601 | int ret; | |
5602 | ||
5603 | used = hwaddr_aton2(dst, dst_addr); | |
5604 | if (used < 0) | |
5605 | return -1; | |
5606 | ||
5607 | while (dst[used] == ' ') | |
5608 | used++; | |
5609 | if (os_strncmp(dst + used, "realm=", 6) == 0) | |
5610 | return hs20_nai_home_realm_list(wpa_s, dst_addr, | |
5611 | dst + used + 6); | |
5612 | ||
5613 | len = os_strlen(dst + used); | |
5614 | ||
5615 | if (len == 0 && cred && cred->realm) | |
5616 | return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm); | |
5617 | ||
0e87e798 | 5618 | if (len & 1) |
a8918e86 JK |
5619 | return -1; |
5620 | len /= 2; | |
5621 | buf = os_malloc(len); | |
5622 | if (buf == NULL) | |
5623 | return -1; | |
5624 | if (hexstr2bin(dst + used, buf, len) < 0) { | |
5625 | os_free(buf); | |
5626 | return -1; | |
5627 | } | |
5628 | ||
5629 | ret = hs20_anqp_send_req(wpa_s, dst_addr, | |
5630 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | |
5631 | buf, len); | |
5632 | os_free(buf); | |
5633 | ||
5634 | return ret; | |
5635 | } | |
5636 | ||
184e110c JM |
5637 | |
5638 | static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd) | |
5639 | { | |
5640 | u8 dst_addr[ETH_ALEN]; | |
5641 | int used; | |
5642 | char *icon; | |
5643 | ||
5644 | used = hwaddr_aton2(cmd, dst_addr); | |
5645 | if (used < 0) | |
5646 | return -1; | |
5647 | ||
5648 | while (cmd[used] == ' ') | |
5649 | used++; | |
5650 | icon = &cmd[used]; | |
5651 | ||
b572df86 | 5652 | wpa_s->fetch_osu_icon_in_progress = 0; |
184e110c JM |
5653 | return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST), |
5654 | (u8 *) icon, os_strlen(icon)); | |
5655 | } | |
5656 | ||
a8918e86 JK |
5657 | #endif /* CONFIG_HS20 */ |
5658 | ||
5659 | ||
0d0a8ca1 AC |
5660 | static int wpa_supplicant_ctrl_iface_sta_autoconnect( |
5661 | struct wpa_supplicant *wpa_s, char *cmd) | |
5662 | { | |
5663 | wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0; | |
5664 | return 0; | |
5665 | } | |
5666 | ||
5667 | ||
bc5d330a TB |
5668 | #ifdef CONFIG_AUTOSCAN |
5669 | ||
5670 | static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s, | |
5671 | char *cmd) | |
5672 | { | |
5673 | enum wpa_states state = wpa_s->wpa_state; | |
5674 | char *new_params = NULL; | |
5675 | ||
5676 | if (os_strlen(cmd) > 0) { | |
5677 | new_params = os_strdup(cmd); | |
5678 | if (new_params == NULL) | |
5679 | return -1; | |
5680 | } | |
5681 | ||
5682 | os_free(wpa_s->conf->autoscan); | |
5683 | wpa_s->conf->autoscan = new_params; | |
5684 | ||
5685 | if (wpa_s->conf->autoscan == NULL) | |
5686 | autoscan_deinit(wpa_s); | |
5687 | else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) | |
99218999 | 5688 | autoscan_init(wpa_s, 1); |
99f00324 JM |
5689 | else if (state == WPA_SCANNING) |
5690 | wpa_supplicant_reinit_autoscan(wpa_s); | |
bc5d330a TB |
5691 | |
5692 | return 0; | |
5693 | } | |
5694 | ||
5695 | #endif /* CONFIG_AUTOSCAN */ | |
5696 | ||
5697 | ||
e9199e31 JM |
5698 | #ifdef CONFIG_WNM |
5699 | ||
5700 | static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd) | |
5701 | { | |
5702 | int enter; | |
5703 | int intval = 0; | |
5704 | char *pos; | |
cd0ef657 JM |
5705 | int ret; |
5706 | struct wpabuf *tfs_req = NULL; | |
e9199e31 JM |
5707 | |
5708 | if (os_strncmp(cmd, "enter", 5) == 0) | |
5709 | enter = 1; | |
5710 | else if (os_strncmp(cmd, "exit", 4) == 0) | |
5711 | enter = 0; | |
5712 | else | |
5713 | return -1; | |
5714 | ||
5715 | pos = os_strstr(cmd, " interval="); | |
5716 | if (pos) | |
5717 | intval = atoi(pos + 10); | |
5718 | ||
cd0ef657 JM |
5719 | pos = os_strstr(cmd, " tfs_req="); |
5720 | if (pos) { | |
5721 | char *end; | |
5722 | size_t len; | |
5723 | pos += 9; | |
5724 | end = os_strchr(pos, ' '); | |
5725 | if (end) | |
5726 | len = end - pos; | |
5727 | else | |
5728 | len = os_strlen(pos); | |
5729 | if (len & 1) | |
5730 | return -1; | |
5731 | len /= 2; | |
5732 | tfs_req = wpabuf_alloc(len); | |
5733 | if (tfs_req == NULL) | |
5734 | return -1; | |
5735 | if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) { | |
5736 | wpabuf_free(tfs_req); | |
5737 | return -1; | |
5738 | } | |
5739 | } | |
5740 | ||
df80a0cc JM |
5741 | ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER : |
5742 | WNM_SLEEP_MODE_EXIT, intval, | |
cd0ef657 JM |
5743 | tfs_req); |
5744 | wpabuf_free(tfs_req); | |
5745 | ||
5746 | return ret; | |
e9199e31 JM |
5747 | } |
5748 | ||
65bcd0a9 VK |
5749 | |
5750 | static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd) | |
5751 | { | |
5752 | int query_reason; | |
5753 | ||
5754 | query_reason = atoi(cmd); | |
5755 | ||
5756 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d", | |
5757 | query_reason); | |
5758 | ||
5759 | return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason); | |
5760 | } | |
5761 | ||
e9199e31 JM |
5762 | #endif /* CONFIG_WNM */ |
5763 | ||
5764 | ||
60b24b0d DS |
5765 | static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, |
5766 | size_t buflen) | |
5767 | { | |
5768 | struct wpa_signal_info si; | |
5769 | int ret; | |
2cc8d8f4 | 5770 | char *pos, *end; |
60b24b0d DS |
5771 | |
5772 | ret = wpa_drv_signal_poll(wpa_s, &si); | |
5773 | if (ret) | |
5774 | return -1; | |
5775 | ||
2cc8d8f4 AO |
5776 | pos = buf; |
5777 | end = buf + buflen; | |
5778 | ||
5779 | ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n" | |
60b24b0d DS |
5780 | "NOISE=%d\nFREQUENCY=%u\n", |
5781 | si.current_signal, si.current_txrate / 1000, | |
5782 | si.current_noise, si.frequency); | |
2cc8d8f4 | 5783 | if (ret < 0 || ret > end - pos) |
60b24b0d | 5784 | return -1; |
2cc8d8f4 AO |
5785 | pos += ret; |
5786 | ||
5787 | if (si.chanwidth != CHAN_WIDTH_UNKNOWN) { | |
5788 | ret = os_snprintf(pos, end - pos, "WIDTH=%s\n", | |
7a4a93b9 | 5789 | channel_width_to_string(si.chanwidth)); |
2cc8d8f4 AO |
5790 | if (ret < 0 || ret > end - pos) |
5791 | return -1; | |
5792 | pos += ret; | |
5793 | } | |
5794 | ||
5795 | if (si.center_frq1 > 0 && si.center_frq2 > 0) { | |
5796 | ret = os_snprintf(pos, end - pos, | |
5797 | "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n", | |
5798 | si.center_frq1, si.center_frq2); | |
5799 | if (ret < 0 || ret > end - pos) | |
5800 | return -1; | |
5801 | pos += ret; | |
5802 | } | |
5803 | ||
95783298 AO |
5804 | if (si.avg_signal) { |
5805 | ret = os_snprintf(pos, end - pos, | |
5806 | "AVG_RSSI=%d\n", si.avg_signal); | |
5807 | if (ret < 0 || ret >= end - pos) | |
5808 | return -1; | |
5809 | pos += ret; | |
5810 | } | |
5811 | ||
2cc8d8f4 | 5812 | return pos - buf; |
60b24b0d DS |
5813 | } |
5814 | ||
5815 | ||
dc7785f8 YZ |
5816 | static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf, |
5817 | size_t buflen) | |
5818 | { | |
5819 | struct hostap_sta_driver_data sta; | |
5820 | int ret; | |
5821 | ||
5822 | ret = wpa_drv_pktcnt_poll(wpa_s, &sta); | |
5823 | if (ret) | |
5824 | return -1; | |
5825 | ||
5826 | ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n", | |
5827 | sta.tx_packets, sta.tx_retry_failed, sta.rx_packets); | |
5828 | if (ret < 0 || (size_t) ret > buflen) | |
5829 | return -1; | |
5830 | return ret; | |
5831 | } | |
5832 | ||
5833 | ||
5e2c3490 JM |
5834 | #ifdef ANDROID |
5835 | static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd, | |
5836 | char *buf, size_t buflen) | |
5837 | { | |
5838 | int ret; | |
5839 | ||
5840 | ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen); | |
a94737ea DS |
5841 | if (ret == 0) { |
5842 | if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) { | |
5843 | struct p2p_data *p2p = wpa_s->global->p2p; | |
5844 | if (p2p) { | |
5845 | char country[3]; | |
5846 | country[0] = cmd[8]; | |
5847 | country[1] = cmd[9]; | |
5848 | country[2] = 0x04; | |
5849 | p2p_set_country(p2p, country); | |
5850 | } | |
5851 | } | |
5e2c3490 | 5852 | ret = os_snprintf(buf, buflen, "%s\n", "OK"); |
a94737ea | 5853 | } |
5e2c3490 JM |
5854 | return ret; |
5855 | } | |
5856 | #endif /* ANDROID */ | |
5857 | ||
5858 | ||
adef8948 BL |
5859 | static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd, |
5860 | char *buf, size_t buflen) | |
5861 | { | |
5862 | int ret; | |
5863 | char *pos; | |
5864 | u8 *data = NULL; | |
5865 | unsigned int vendor_id, subcmd; | |
5866 | struct wpabuf *reply; | |
5867 | size_t data_len = 0; | |
5868 | ||
5869 | /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */ | |
5870 | vendor_id = strtoul(cmd, &pos, 16); | |
5871 | if (!isblank(*pos)) | |
5872 | return -EINVAL; | |
5873 | ||
5874 | subcmd = strtoul(pos, &pos, 10); | |
5875 | ||
5876 | if (*pos != '\0') { | |
5877 | if (!isblank(*pos++)) | |
5878 | return -EINVAL; | |
5879 | data_len = os_strlen(pos); | |
5880 | } | |
5881 | ||
5882 | if (data_len) { | |
5883 | data_len /= 2; | |
5884 | data = os_malloc(data_len); | |
5885 | if (!data) | |
2cebdee6 | 5886 | return -1; |
adef8948 BL |
5887 | |
5888 | if (hexstr2bin(pos, data, data_len)) { | |
5889 | wpa_printf(MSG_DEBUG, | |
5890 | "Vendor command: wrong parameter format"); | |
5891 | os_free(data); | |
5892 | return -EINVAL; | |
5893 | } | |
5894 | } | |
5895 | ||
5896 | reply = wpabuf_alloc((buflen - 1) / 2); | |
5897 | if (!reply) { | |
5898 | os_free(data); | |
2cebdee6 | 5899 | return -1; |
adef8948 BL |
5900 | } |
5901 | ||
5902 | ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len, | |
5903 | reply); | |
5904 | ||
5905 | if (ret == 0) | |
5906 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply), | |
5907 | wpabuf_len(reply)); | |
5908 | ||
5909 | wpabuf_free(reply); | |
5910 | os_free(data); | |
5911 | ||
5912 | return ret; | |
5913 | } | |
5914 | ||
5915 | ||
acb54643 JM |
5916 | static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s) |
5917 | { | |
5918 | wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state"); | |
5919 | ||
5920 | #ifdef CONFIG_P2P | |
f05cee97 | 5921 | wpas_p2p_cancel(wpa_s); |
acb54643 JM |
5922 | wpas_p2p_stop_find(wpa_s); |
5923 | p2p_ctrl_flush(wpa_s); | |
5924 | wpas_p2p_group_remove(wpa_s, "*"); | |
3f45fc40 | 5925 | wpas_p2p_service_flush(wpa_s); |
083916c0 JM |
5926 | wpa_s->global->p2p_disabled = 0; |
5927 | wpa_s->global->p2p_per_sta_psk = 0; | |
78f0c933 | 5928 | wpa_s->conf->num_sec_device_types = 0; |
201b0f5f | 5929 | wpa_s->p2p_disable_ip_addr_req = 0; |
7bb70909 JM |
5930 | os_free(wpa_s->global->p2p_go_avoid_freq.range); |
5931 | wpa_s->global->p2p_go_avoid_freq.range = NULL; | |
acb54643 JM |
5932 | #endif /* CONFIG_P2P */ |
5933 | ||
5934 | #ifdef CONFIG_WPS_TESTING | |
5935 | wps_version_number = 0x20; | |
5936 | wps_testing_dummy_cred = 0; | |
91226e0d | 5937 | wps_corrupt_pkhash = 0; |
acb54643 JM |
5938 | #endif /* CONFIG_WPS_TESTING */ |
5939 | #ifdef CONFIG_WPS | |
7b02375a | 5940 | wpa_s->wps_fragment_size = 0; |
acb54643 JM |
5941 | wpas_wps_cancel(wpa_s); |
5942 | #endif /* CONFIG_WPS */ | |
7255983b | 5943 | wpa_s->after_wps = 0; |
4d9fb08d | 5944 | wpa_s->known_wps_freq = 0; |
acb54643 | 5945 | |
9d2cb3ec | 5946 | #ifdef CONFIG_TDLS |
acb54643 JM |
5947 | #ifdef CONFIG_TDLS_TESTING |
5948 | extern unsigned int tdls_testing; | |
5949 | tdls_testing = 0; | |
5950 | #endif /* CONFIG_TDLS_TESTING */ | |
acb54643 JM |
5951 | wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL); |
5952 | wpa_tdls_enable(wpa_s->wpa, 1); | |
5953 | #endif /* CONFIG_TDLS */ | |
5954 | ||
e78aaca0 JM |
5955 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL); |
5956 | wpa_supplicant_stop_countermeasures(wpa_s, NULL); | |
5957 | ||
acb54643 JM |
5958 | wpa_s->no_keep_alive = 0; |
5959 | ||
5960 | os_free(wpa_s->disallow_aps_bssid); | |
5961 | wpa_s->disallow_aps_bssid = NULL; | |
5962 | wpa_s->disallow_aps_bssid_count = 0; | |
5963 | os_free(wpa_s->disallow_aps_ssid); | |
5964 | wpa_s->disallow_aps_ssid = NULL; | |
5965 | wpa_s->disallow_aps_ssid_count = 0; | |
5966 | ||
5967 | wpa_s->set_sta_uapsd = 0; | |
5968 | wpa_s->sta_uapsd = 0; | |
5969 | ||
5970 | wpa_drv_radio_disable(wpa_s, 0); | |
5971 | ||
5972 | wpa_bss_flush(wpa_s); | |
5973 | wpa_blacklist_clear(wpa_s); | |
a8a7890d | 5974 | wpa_s->extra_blacklist_count = 0; |
acb54643 JM |
5975 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all"); |
5976 | wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all"); | |
d9bb2821 | 5977 | wpa_config_flush_blobs(wpa_s->conf); |
ea6e040c JM |
5978 | wpa_s->conf->auto_interworking = 0; |
5979 | wpa_s->conf->okc = 0; | |
04f7ecc6 | 5980 | |
b925506a JM |
5981 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
5982 | rsn_preauth_deinit(wpa_s->wpa); | |
5983 | ||
04f7ecc6 JM |
5984 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200); |
5985 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70); | |
5986 | wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60); | |
0d79b50a | 5987 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); |
b1ae396f | 5988 | |
b3253ebb | 5989 | radio_remove_works(wpa_s, NULL, 1); |
e3745228 | 5990 | wpa_s->ext_work_in_progress = 0; |
3d910ef4 JM |
5991 | |
5992 | wpa_s->next_ssid = NULL; | |
b572df86 JM |
5993 | |
5994 | #ifdef CONFIG_INTERWORKING | |
5995 | hs20_cancel_fetch_osu(wpa_s); | |
5996 | #endif /* CONFIG_INTERWORKING */ | |
60b893df JM |
5997 | |
5998 | wpa_s->ext_mgmt_frame_handling = 0; | |
9d4ff04a | 5999 | wpa_s->ext_eapol_frame_io = 0; |
1f94e4ee JM |
6000 | #ifdef CONFIG_TESTING_OPTIONS |
6001 | wpa_s->extra_roc_dur = 0; | |
6002 | #endif /* CONFIG_TESTING_OPTIONS */ | |
acb54643 JM |
6003 | } |
6004 | ||
6005 | ||
1f965e62 JM |
6006 | static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s, |
6007 | char *buf, size_t buflen) | |
6008 | { | |
6009 | struct wpa_radio_work *work; | |
6010 | char *pos, *end; | |
6011 | struct os_reltime now, diff; | |
6012 | ||
6013 | pos = buf; | |
6014 | end = buf + buflen; | |
6015 | ||
6016 | os_get_reltime(&now); | |
6017 | ||
6018 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) | |
6019 | { | |
6020 | int ret; | |
6021 | ||
6022 | os_reltime_sub(&now, &work->time, &diff); | |
6023 | ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n", | |
6024 | work->type, work->wpa_s->ifname, work->freq, | |
6025 | work->started, diff.sec, diff.usec); | |
6026 | if (ret < 0 || ret >= end - pos) | |
6027 | break; | |
6028 | pos += ret; | |
6029 | } | |
6030 | ||
6031 | return pos - buf; | |
6032 | } | |
6033 | ||
6034 | ||
6035 | static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx) | |
6036 | { | |
6037 | struct wpa_radio_work *work = eloop_ctx; | |
6038 | struct wpa_external_work *ework = work->ctx; | |
6039 | ||
6040 | wpa_dbg(work->wpa_s, MSG_DEBUG, | |
6041 | "Timing out external radio work %u (%s)", | |
6042 | ework->id, work->type); | |
6043 | wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id); | |
e3745228 | 6044 | work->wpa_s->ext_work_in_progress = 0; |
1f965e62 | 6045 | radio_work_done(work); |
df48efc5 | 6046 | os_free(ework); |
1f965e62 JM |
6047 | } |
6048 | ||
6049 | ||
6050 | static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit) | |
6051 | { | |
6052 | struct wpa_external_work *ework = work->ctx; | |
6053 | ||
6054 | if (deinit) { | |
b3253ebb AO |
6055 | if (work->started) |
6056 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, | |
6057 | work, NULL); | |
6058 | ||
1f965e62 JM |
6059 | os_free(ework); |
6060 | return; | |
6061 | } | |
6062 | ||
6063 | wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)", | |
6064 | ework->id, ework->type); | |
6065 | wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id); | |
e3745228 | 6066 | work->wpa_s->ext_work_in_progress = 1; |
1f965e62 JM |
6067 | if (!ework->timeout) |
6068 | ework->timeout = 10; | |
6069 | eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout, | |
6070 | work, NULL); | |
6071 | } | |
6072 | ||
6073 | ||
6074 | static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd, | |
6075 | char *buf, size_t buflen) | |
6076 | { | |
6077 | struct wpa_external_work *ework; | |
6078 | char *pos, *pos2; | |
6079 | size_t type_len; | |
6080 | int ret; | |
6081 | unsigned int freq = 0; | |
6082 | ||
6083 | /* format: <name> [freq=<MHz>] [timeout=<seconds>] */ | |
6084 | ||
6085 | ework = os_zalloc(sizeof(*ework)); | |
6086 | if (ework == NULL) | |
6087 | return -1; | |
6088 | ||
6089 | pos = os_strchr(cmd, ' '); | |
6090 | if (pos) { | |
6091 | type_len = pos - cmd; | |
6092 | pos++; | |
6093 | ||
6094 | pos2 = os_strstr(pos, "freq="); | |
6095 | if (pos2) | |
6096 | freq = atoi(pos2 + 5); | |
6097 | ||
6098 | pos2 = os_strstr(pos, "timeout="); | |
6099 | if (pos2) | |
6100 | ework->timeout = atoi(pos2 + 8); | |
6101 | } else { | |
6102 | type_len = os_strlen(cmd); | |
6103 | } | |
6104 | if (4 + type_len >= sizeof(ework->type)) | |
6105 | type_len = sizeof(ework->type) - 4 - 1; | |
6106 | os_strlcpy(ework->type, "ext:", sizeof(ework->type)); | |
6107 | os_memcpy(ework->type + 4, cmd, type_len); | |
6108 | ework->type[4 + type_len] = '\0'; | |
6109 | ||
6110 | wpa_s->ext_work_id++; | |
6111 | if (wpa_s->ext_work_id == 0) | |
6112 | wpa_s->ext_work_id++; | |
6113 | ework->id = wpa_s->ext_work_id; | |
6114 | ||
6115 | if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb, | |
6116 | ework) < 0) { | |
6117 | os_free(ework); | |
6118 | return -1; | |
6119 | } | |
6120 | ||
6121 | ret = os_snprintf(buf, buflen, "%u", ework->id); | |
6122 | if (ret < 0 || (size_t) ret >= buflen) | |
6123 | return -1; | |
6124 | return ret; | |
6125 | } | |
6126 | ||
6127 | ||
6128 | static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd) | |
6129 | { | |
6130 | struct wpa_radio_work *work; | |
6131 | unsigned int id = atoi(cmd); | |
6132 | ||
6133 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) | |
6134 | { | |
6135 | struct wpa_external_work *ework; | |
6136 | ||
6137 | if (os_strncmp(work->type, "ext:", 4) != 0) | |
6138 | continue; | |
6139 | ework = work->ctx; | |
6140 | if (id && ework->id != id) | |
6141 | continue; | |
6142 | wpa_dbg(wpa_s, MSG_DEBUG, | |
6143 | "Completed external radio work %u (%s)", | |
6144 | ework->id, ework->type); | |
6145 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL); | |
e3745228 | 6146 | wpa_s->ext_work_in_progress = 0; |
1f965e62 | 6147 | radio_work_done(work); |
6829da39 | 6148 | os_free(ework); |
1f965e62 JM |
6149 | return 3; /* "OK\n" */ |
6150 | } | |
6151 | ||
6152 | return -1; | |
6153 | } | |
6154 | ||
6155 | ||
6156 | static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd, | |
6157 | char *buf, size_t buflen) | |
6158 | { | |
6159 | if (os_strcmp(cmd, "show") == 0) | |
6160 | return wpas_ctrl_radio_work_show(wpa_s, buf, buflen); | |
6161 | if (os_strncmp(cmd, "add ", 4) == 0) | |
6162 | return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen); | |
6163 | if (os_strncmp(cmd, "done ", 5) == 0) | |
6164 | return wpas_ctrl_radio_work_done(wpa_s, cmd + 4); | |
6165 | return -1; | |
6166 | } | |
6167 | ||
6168 | ||
6169 | void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s) | |
6170 | { | |
6171 | struct wpa_radio_work *work, *tmp; | |
6172 | ||
a6cff8bf MS |
6173 | if (!wpa_s || !wpa_s->radio) |
6174 | return; | |
6175 | ||
1f965e62 JM |
6176 | dl_list_for_each_safe(work, tmp, &wpa_s->radio->work, |
6177 | struct wpa_radio_work, list) { | |
6178 | struct wpa_external_work *ework; | |
6179 | ||
6180 | if (os_strncmp(work->type, "ext:", 4) != 0) | |
6181 | continue; | |
6182 | ework = work->ctx; | |
6183 | wpa_dbg(wpa_s, MSG_DEBUG, | |
023b466d | 6184 | "Flushing%s external radio work %u (%s)", |
1f965e62 JM |
6185 | work->started ? " started" : "", ework->id, |
6186 | ework->type); | |
6187 | if (work->started) | |
6188 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, | |
6189 | work, NULL); | |
1f965e62 | 6190 | radio_work_done(work); |
df48efc5 | 6191 | os_free(ework); |
1f965e62 JM |
6192 | } |
6193 | } | |
6194 | ||
6195 | ||
bceb8431 JM |
6196 | static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx) |
6197 | { | |
6198 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
6199 | eapol_sm_notify_ctrl_response(wpa_s->eapol); | |
6200 | } | |
6201 | ||
6202 | ||
fee52342 JM |
6203 | static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val) |
6204 | { | |
fee52342 | 6205 | int *freqs = NULL; |
fee52342 | 6206 | |
356d1488 JM |
6207 | freqs = freq_range_to_channel_list(wpa_s, val); |
6208 | if (freqs == NULL) | |
fee52342 JM |
6209 | return -1; |
6210 | ||
fee52342 JM |
6211 | os_free(wpa_s->manual_scan_freqs); |
6212 | wpa_s->manual_scan_freqs = freqs; | |
6213 | ||
6214 | return 0; | |
6215 | } | |
6216 | ||
6217 | ||
6891f0e6 LJ |
6218 | static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value) |
6219 | { | |
6220 | const char *pos = value; | |
6221 | ||
6222 | while (pos) { | |
6223 | if (*pos == ' ' || *pos == '\0') | |
6224 | break; | |
6225 | if (wpa_s->scan_id_count == MAX_SCAN_ID) | |
6226 | return -1; | |
6227 | wpa_s->scan_id[wpa_s->scan_id_count++] = atoi(pos); | |
6228 | pos = os_strchr(pos, ','); | |
6229 | if (pos) | |
6230 | pos++; | |
6231 | } | |
6232 | ||
6233 | return 0; | |
6234 | } | |
6235 | ||
6236 | ||
fee52342 JM |
6237 | static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params, |
6238 | char *reply, int reply_size, int *reply_len) | |
6239 | { | |
6240 | char *pos; | |
6241 | ||
6242 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { | |
6243 | *reply_len = -1; | |
6244 | return; | |
6245 | } | |
6246 | ||
88c2d488 | 6247 | wpa_s->manual_scan_passive = 0; |
d81c73be | 6248 | wpa_s->manual_scan_use_id = 0; |
949938aa | 6249 | wpa_s->manual_scan_only_new = 0; |
6891f0e6 | 6250 | wpa_s->scan_id_count = 0; |
88c2d488 | 6251 | |
fee52342 JM |
6252 | if (params) { |
6253 | if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0) | |
6254 | wpa_s->scan_res_handler = scan_only_handler; | |
6255 | ||
6256 | pos = os_strstr(params, "freq="); | |
6257 | if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) { | |
6258 | *reply_len = -1; | |
6259 | return; | |
6260 | } | |
88c2d488 JM |
6261 | |
6262 | pos = os_strstr(params, "passive="); | |
6263 | if (pos) | |
6264 | wpa_s->manual_scan_passive = !!atoi(pos + 8); | |
d81c73be JM |
6265 | |
6266 | pos = os_strstr(params, "use_id="); | |
6267 | if (pos) | |
6268 | wpa_s->manual_scan_use_id = atoi(pos + 7); | |
949938aa JM |
6269 | |
6270 | pos = os_strstr(params, "only_new=1"); | |
6271 | if (pos) | |
6272 | wpa_s->manual_scan_only_new = 1; | |
6891f0e6 LJ |
6273 | |
6274 | pos = os_strstr(params, "scan_id="); | |
6275 | if (pos && scan_id_list_parse(wpa_s, pos + 8) < 0) { | |
6276 | *reply_len = -1; | |
6277 | return; | |
6278 | } | |
fee52342 JM |
6279 | } else { |
6280 | os_free(wpa_s->manual_scan_freqs); | |
6281 | wpa_s->manual_scan_freqs = NULL; | |
6282 | if (wpa_s->scan_res_handler == scan_only_handler) | |
6283 | wpa_s->scan_res_handler = NULL; | |
6284 | } | |
6285 | ||
6286 | if (!wpa_s->sched_scanning && !wpa_s->scanning && | |
6287 | ((wpa_s->wpa_state <= WPA_SCANNING) || | |
6288 | (wpa_s->wpa_state == WPA_COMPLETED))) { | |
6289 | wpa_s->normal_scans = 0; | |
6290 | wpa_s->scan_req = MANUAL_SCAN_REQ; | |
6291 | wpa_s->after_wps = 0; | |
6292 | wpa_s->known_wps_freq = 0; | |
6293 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
d81c73be JM |
6294 | if (wpa_s->manual_scan_use_id) { |
6295 | wpa_s->manual_scan_id++; | |
6296 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", | |
6297 | wpa_s->manual_scan_id); | |
6298 | *reply_len = os_snprintf(reply, reply_size, "%u\n", | |
6299 | wpa_s->manual_scan_id); | |
6300 | } | |
fee52342 JM |
6301 | } else if (wpa_s->sched_scanning) { |
6302 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed"); | |
6303 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
6304 | wpa_s->scan_req = MANUAL_SCAN_REQ; | |
6305 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
d81c73be JM |
6306 | if (wpa_s->manual_scan_use_id) { |
6307 | wpa_s->manual_scan_id++; | |
6308 | *reply_len = os_snprintf(reply, reply_size, "%u\n", | |
6309 | wpa_s->manual_scan_id); | |
6310 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", | |
6311 | wpa_s->manual_scan_id); | |
6312 | } | |
fee52342 JM |
6313 | } else { |
6314 | wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request"); | |
6315 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | |
6316 | } | |
6317 | } | |
6318 | ||
6319 | ||
60b893df JM |
6320 | #ifdef CONFIG_TESTING_OPTIONS |
6321 | ||
6322 | static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s, | |
6323 | unsigned int freq, const u8 *dst, | |
6324 | const u8 *src, const u8 *bssid, | |
6325 | const u8 *data, size_t data_len, | |
6326 | enum offchannel_send_action_result | |
6327 | result) | |
6328 | { | |
6329 | wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR | |
6330 | " src=" MACSTR " bssid=" MACSTR " result=%s", | |
6331 | freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid), | |
6332 | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? | |
6333 | "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? | |
6334 | "NO_ACK" : "FAILED")); | |
6335 | } | |
6336 | ||
6337 | ||
6338 | static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd) | |
6339 | { | |
6340 | char *pos, *param; | |
6341 | size_t len; | |
6342 | u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN]; | |
6343 | int res, used; | |
6344 | int freq = 0, no_cck = 0, wait_time = 0; | |
6345 | ||
6346 | /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1] | |
6347 | * <action=Action frame payload> */ | |
6348 | ||
6349 | wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd); | |
6350 | ||
6351 | pos = cmd; | |
6352 | used = hwaddr_aton2(pos, da); | |
6353 | if (used < 0) | |
6354 | return -1; | |
6355 | pos += used; | |
6356 | while (*pos == ' ') | |
6357 | pos++; | |
6358 | used = hwaddr_aton2(pos, bssid); | |
6359 | if (used < 0) | |
6360 | return -1; | |
6361 | pos += used; | |
6362 | ||
6363 | param = os_strstr(pos, " freq="); | |
6364 | if (param) { | |
6365 | param += 6; | |
6366 | freq = atoi(param); | |
6367 | } | |
6368 | ||
6369 | param = os_strstr(pos, " no_cck="); | |
6370 | if (param) { | |
6371 | param += 8; | |
6372 | no_cck = atoi(param); | |
6373 | } | |
6374 | ||
6375 | param = os_strstr(pos, " wait_time="); | |
6376 | if (param) { | |
6377 | param += 11; | |
6378 | wait_time = atoi(param); | |
6379 | } | |
6380 | ||
6381 | param = os_strstr(pos, " action="); | |
6382 | if (param == NULL) | |
6383 | return -1; | |
6384 | param += 8; | |
6385 | ||
6386 | len = os_strlen(param); | |
6387 | if (len & 1) | |
6388 | return -1; | |
6389 | len /= 2; | |
6390 | ||
6391 | buf = os_malloc(len); | |
6392 | if (buf == NULL) | |
6393 | return -1; | |
6394 | ||
6395 | if (hexstr2bin(param, buf, len) < 0) { | |
6396 | os_free(buf); | |
6397 | return -1; | |
6398 | } | |
6399 | ||
6400 | res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid, | |
6401 | buf, len, wait_time, | |
6402 | wpas_ctrl_iface_mgmt_tx_cb, no_cck); | |
6403 | os_free(buf); | |
6404 | return res; | |
6405 | } | |
6406 | ||
6407 | ||
6408 | static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s) | |
6409 | { | |
6410 | wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting"); | |
6411 | offchannel_send_action_done(wpa_s); | |
6412 | } | |
6413 | ||
ad12f2f4 JM |
6414 | |
6415 | static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd) | |
6416 | { | |
6417 | char *pos, *param; | |
6418 | union wpa_event_data event; | |
6419 | enum wpa_event_type ev; | |
6420 | ||
6421 | /* <event name> [parameters..] */ | |
6422 | ||
6423 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd); | |
6424 | ||
6425 | pos = cmd; | |
6426 | param = os_strchr(pos, ' '); | |
6427 | if (param) | |
6428 | *param++ = '\0'; | |
6429 | ||
6430 | os_memset(&event, 0, sizeof(event)); | |
6431 | ||
6432 | if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) { | |
6433 | ev = EVENT_INTERFACE_ENABLED; | |
6434 | } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) { | |
6435 | ev = EVENT_INTERFACE_DISABLED; | |
7bb70909 JM |
6436 | } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) { |
6437 | ev = EVENT_AVOID_FREQUENCIES; | |
6438 | if (param == NULL) | |
6439 | param = ""; | |
6440 | if (freq_range_list_parse(&event.freq_range, param) < 0) | |
6441 | return -1; | |
6442 | wpa_supplicant_event(wpa_s, ev, &event); | |
6443 | os_free(event.freq_range.range); | |
6444 | return 0; | |
ad12f2f4 JM |
6445 | } else { |
6446 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s", | |
6447 | cmd); | |
6448 | return -1; | |
6449 | } | |
6450 | ||
6451 | wpa_supplicant_event(wpa_s, ev, &event); | |
6452 | ||
6453 | return 0; | |
6454 | } | |
6455 | ||
9d4ff04a JM |
6456 | |
6457 | static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd) | |
6458 | { | |
6459 | char *pos; | |
6460 | u8 src[ETH_ALEN], *buf; | |
6461 | int used; | |
6462 | size_t len; | |
6463 | ||
6464 | wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd); | |
6465 | ||
6466 | pos = cmd; | |
6467 | used = hwaddr_aton2(pos, src); | |
6468 | if (used < 0) | |
6469 | return -1; | |
6470 | pos += used; | |
6471 | while (*pos == ' ') | |
6472 | pos++; | |
6473 | ||
6474 | len = os_strlen(pos); | |
6475 | if (len & 1) | |
6476 | return -1; | |
6477 | len /= 2; | |
6478 | ||
6479 | buf = os_malloc(len); | |
6480 | if (buf == NULL) | |
6481 | return -1; | |
6482 | ||
6483 | if (hexstr2bin(pos, buf, len) < 0) { | |
6484 | os_free(buf); | |
6485 | return -1; | |
6486 | } | |
6487 | ||
6488 | wpa_supplicant_rx_eapol(wpa_s, src, buf, len); | |
6489 | os_free(buf); | |
6490 | ||
6491 | return 0; | |
6492 | } | |
6493 | ||
4a6cc862 JM |
6494 | |
6495 | static u16 ipv4_hdr_checksum(const void *buf, size_t len) | |
6496 | { | |
6497 | size_t i; | |
6498 | u32 sum = 0; | |
6499 | const u16 *pos = buf; | |
6500 | ||
6501 | for (i = 0; i < len / 2; i++) | |
6502 | sum += *pos++; | |
6503 | ||
6504 | while (sum >> 16) | |
6505 | sum = (sum & 0xffff) + (sum >> 16); | |
6506 | ||
6507 | return sum ^ 0xffff; | |
6508 | } | |
6509 | ||
6510 | ||
6511 | #define HWSIM_PACKETLEN 1500 | |
6512 | #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header)) | |
6513 | ||
6514 | void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) | |
6515 | { | |
6516 | struct wpa_supplicant *wpa_s = ctx; | |
6517 | const struct ether_header *eth; | |
6518 | const struct iphdr *ip; | |
6519 | const u8 *pos; | |
6520 | unsigned int i; | |
6521 | ||
6522 | if (len != HWSIM_PACKETLEN) | |
6523 | return; | |
6524 | ||
6525 | eth = (const struct ether_header *) buf; | |
6526 | ip = (const struct iphdr *) (eth + 1); | |
6527 | pos = (const u8 *) (ip + 1); | |
6528 | ||
6529 | if (ip->ihl != 5 || ip->version != 4 || | |
6530 | ntohs(ip->tot_len) != HWSIM_IP_LEN) | |
6531 | return; | |
6532 | ||
6533 | for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) { | |
6534 | if (*pos != (u8) i) | |
6535 | return; | |
6536 | pos++; | |
6537 | } | |
6538 | ||
6539 | wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR, | |
6540 | MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost)); | |
6541 | } | |
6542 | ||
6543 | ||
6544 | static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s, | |
6545 | char *cmd) | |
6546 | { | |
6547 | int enabled = atoi(cmd); | |
6548 | ||
6549 | if (!enabled) { | |
6550 | if (wpa_s->l2_test) { | |
6551 | l2_packet_deinit(wpa_s->l2_test); | |
6552 | wpa_s->l2_test = NULL; | |
6553 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled"); | |
6554 | } | |
6555 | return 0; | |
6556 | } | |
6557 | ||
6558 | if (wpa_s->l2_test) | |
6559 | return 0; | |
6560 | ||
6561 | wpa_s->l2_test = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, | |
6562 | ETHERTYPE_IP, wpas_data_test_rx, | |
6563 | wpa_s, 1); | |
6564 | if (wpa_s->l2_test == NULL) | |
6565 | return -1; | |
6566 | ||
6567 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled"); | |
6568 | ||
6569 | return 0; | |
6570 | } | |
6571 | ||
6572 | ||
6573 | static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd) | |
6574 | { | |
6575 | u8 dst[ETH_ALEN], src[ETH_ALEN]; | |
6576 | char *pos; | |
6577 | int used; | |
6578 | long int val; | |
6579 | u8 tos; | |
6580 | u8 buf[HWSIM_PACKETLEN]; | |
6581 | struct ether_header *eth; | |
6582 | struct iphdr *ip; | |
6583 | u8 *dpos; | |
6584 | unsigned int i; | |
6585 | ||
6586 | if (wpa_s->l2_test == NULL) | |
6587 | return -1; | |
6588 | ||
6589 | /* format: <dst> <src> <tos> */ | |
6590 | ||
6591 | pos = cmd; | |
6592 | used = hwaddr_aton2(pos, dst); | |
6593 | if (used < 0) | |
6594 | return -1; | |
6595 | pos += used; | |
6596 | while (*pos == ' ') | |
6597 | pos++; | |
6598 | used = hwaddr_aton2(pos, src); | |
6599 | if (used < 0) | |
6600 | return -1; | |
6601 | pos += used; | |
6602 | ||
6603 | val = strtol(pos, NULL, 0); | |
6604 | if (val < 0 || val > 0xff) | |
6605 | return -1; | |
6606 | tos = val; | |
6607 | ||
6608 | eth = (struct ether_header *) buf; | |
6609 | os_memcpy(eth->ether_dhost, dst, ETH_ALEN); | |
6610 | os_memcpy(eth->ether_shost, src, ETH_ALEN); | |
6611 | eth->ether_type = htons(ETHERTYPE_IP); | |
6612 | ip = (struct iphdr *) (eth + 1); | |
6613 | os_memset(ip, 0, sizeof(*ip)); | |
6614 | ip->ihl = 5; | |
6615 | ip->version = 4; | |
6616 | ip->ttl = 64; | |
6617 | ip->tos = tos; | |
6618 | ip->tot_len = htons(HWSIM_IP_LEN); | |
6619 | ip->protocol = 1; | |
6620 | ip->saddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 1); | |
6621 | ip->daddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 2); | |
6622 | ip->check = ipv4_hdr_checksum(ip, sizeof(*ip)); | |
6623 | dpos = (u8 *) (ip + 1); | |
6624 | for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) | |
6625 | *dpos++ = i; | |
6626 | ||
6627 | if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, buf, | |
6628 | HWSIM_PACKETLEN) < 0) | |
6629 | return -1; | |
6630 | ||
6631 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR | |
6632 | " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos); | |
6633 | ||
6634 | return 0; | |
6635 | } | |
6636 | ||
fc0ef7c0 JM |
6637 | |
6638 | static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s, | |
6639 | char *cmd) | |
6640 | { | |
6641 | u8 *buf; | |
6642 | struct ether_header *eth; | |
6643 | struct l2_packet_data *l2 = NULL; | |
6644 | size_t len; | |
6645 | u16 ethertype; | |
6646 | int res = -1; | |
6647 | ||
6648 | len = os_strlen(cmd); | |
6649 | if (len & 1 || len < ETH_HLEN * 2) | |
6650 | return -1; | |
6651 | len /= 2; | |
6652 | ||
6653 | buf = os_malloc(len); | |
6654 | if (buf == NULL) | |
6655 | return -1; | |
6656 | ||
6657 | if (hexstr2bin(cmd, buf, len) < 0) | |
6658 | goto done; | |
6659 | ||
6660 | eth = (struct ether_header *) buf; | |
6661 | ethertype = ntohs(eth->ether_type); | |
6662 | ||
6663 | l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype, | |
6664 | wpas_data_test_rx, wpa_s, 1); | |
6665 | if (l2 == NULL) | |
6666 | goto done; | |
6667 | ||
6668 | res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len); | |
6669 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res); | |
6670 | done: | |
6671 | if (l2) | |
6672 | l2_packet_deinit(l2); | |
6673 | os_free(buf); | |
6674 | ||
6675 | return res < 0 ? -1 : 0; | |
6676 | } | |
6677 | ||
60b893df JM |
6678 | #endif /* CONFIG_TESTING_OPTIONS */ |
6679 | ||
6680 | ||
86bd36f0 JM |
6681 | static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant *wpa_s) |
6682 | { | |
6683 | unsigned int i; | |
6684 | char buf[30]; | |
6685 | ||
6686 | wpa_printf(MSG_DEBUG, "Update vendor elements"); | |
6687 | ||
6688 | for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) { | |
6689 | if (wpa_s->vendor_elem[i]) { | |
6690 | os_snprintf(buf, sizeof(buf), "frame[%u]", i); | |
6691 | wpa_hexdump_buf(MSG_DEBUG, buf, wpa_s->vendor_elem[i]); | |
6692 | } | |
6693 | } | |
6694 | ||
6695 | #ifdef CONFIG_P2P | |
6696 | if (wpa_s->parent == wpa_s && | |
6697 | wpa_s->global->p2p && | |
6698 | !wpa_s->global->p2p_disabled) | |
6699 | p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem); | |
6700 | #endif /* CONFIG_P2P */ | |
6701 | } | |
6702 | ||
6703 | ||
6704 | static struct wpa_supplicant * | |
6705 | wpas_ctrl_vendor_elem_iface(struct wpa_supplicant *wpa_s, | |
6706 | enum wpa_vendor_elem_frame frame) | |
6707 | { | |
6708 | switch (frame) { | |
6709 | #ifdef CONFIG_P2P | |
6710 | case VENDOR_ELEM_PROBE_REQ_P2P: | |
6711 | case VENDOR_ELEM_PROBE_RESP_P2P: | |
6712 | case VENDOR_ELEM_PROBE_RESP_P2P_GO: | |
6713 | case VENDOR_ELEM_BEACON_P2P_GO: | |
6714 | case VENDOR_ELEM_P2P_PD_REQ: | |
6715 | case VENDOR_ELEM_P2P_PD_RESP: | |
6716 | case VENDOR_ELEM_P2P_GO_NEG_REQ: | |
6717 | case VENDOR_ELEM_P2P_GO_NEG_RESP: | |
6718 | case VENDOR_ELEM_P2P_GO_NEG_CONF: | |
6719 | case VENDOR_ELEM_P2P_INV_REQ: | |
6720 | case VENDOR_ELEM_P2P_INV_RESP: | |
6721 | case VENDOR_ELEM_P2P_ASSOC_REQ: | |
6722 | return wpa_s->parent; | |
6723 | #endif /* CONFIG_P2P */ | |
6724 | default: | |
6725 | return wpa_s; | |
6726 | } | |
6727 | } | |
6728 | ||
6729 | ||
6730 | static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd) | |
6731 | { | |
6732 | char *pos = cmd; | |
6733 | int frame; | |
6734 | size_t len; | |
6735 | struct wpabuf *buf; | |
6736 | struct ieee802_11_elems elems; | |
6737 | ||
6738 | frame = atoi(pos); | |
6739 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | |
6740 | return -1; | |
6741 | wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame); | |
6742 | ||
6743 | pos = os_strchr(pos, ' '); | |
6744 | if (pos == NULL) | |
6745 | return -1; | |
6746 | pos++; | |
6747 | ||
6748 | len = os_strlen(pos); | |
6749 | if (len == 0) | |
6750 | return 0; | |
6751 | if (len & 1) | |
6752 | return -1; | |
6753 | len /= 2; | |
6754 | ||
6755 | buf = wpabuf_alloc(len); | |
6756 | if (buf == NULL) | |
6757 | return -1; | |
6758 | ||
6759 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { | |
6760 | wpabuf_free(buf); | |
6761 | return -1; | |
6762 | } | |
6763 | ||
6764 | if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) == | |
6765 | ParseFailed) { | |
6766 | wpabuf_free(buf); | |
6767 | return -1; | |
6768 | } | |
6769 | ||
6770 | if (wpa_s->vendor_elem[frame] == NULL) { | |
6771 | wpa_s->vendor_elem[frame] = buf; | |
6772 | wpas_ctrl_vendor_elem_update(wpa_s); | |
6773 | return 0; | |
6774 | } | |
6775 | ||
6776 | if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) { | |
6777 | wpabuf_free(buf); | |
6778 | return -1; | |
6779 | } | |
6780 | ||
6781 | wpabuf_put_buf(wpa_s->vendor_elem[frame], buf); | |
6782 | wpabuf_free(buf); | |
6783 | wpas_ctrl_vendor_elem_update(wpa_s); | |
6784 | ||
6785 | return 0; | |
6786 | } | |
6787 | ||
6788 | ||
6789 | static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd, | |
6790 | char *buf, size_t buflen) | |
6791 | { | |
6792 | int frame = atoi(cmd); | |
6793 | ||
6794 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | |
6795 | return -1; | |
6796 | wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame); | |
6797 | ||
6798 | if (wpa_s->vendor_elem[frame] == NULL) | |
6799 | return 0; | |
6800 | ||
6801 | return wpa_snprintf_hex(buf, buflen, | |
6802 | wpabuf_head_u8(wpa_s->vendor_elem[frame]), | |
6803 | wpabuf_len(wpa_s->vendor_elem[frame])); | |
6804 | } | |
6805 | ||
6806 | ||
6807 | static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd) | |
6808 | { | |
6809 | char *pos = cmd; | |
6810 | int frame; | |
6811 | size_t len; | |
6812 | u8 *buf; | |
6813 | struct ieee802_11_elems elems; | |
6814 | u8 *ie, *end; | |
6815 | ||
6816 | frame = atoi(pos); | |
6817 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | |
6818 | return -1; | |
6819 | wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame); | |
6820 | ||
6821 | pos = os_strchr(pos, ' '); | |
6822 | if (pos == NULL) | |
6823 | return -1; | |
6824 | pos++; | |
6825 | ||
6826 | if (*pos == '*') { | |
6827 | wpabuf_free(wpa_s->vendor_elem[frame]); | |
6828 | wpa_s->vendor_elem[frame] = NULL; | |
6829 | wpas_ctrl_vendor_elem_update(wpa_s); | |
6830 | return 0; | |
6831 | } | |
6832 | ||
6833 | if (wpa_s->vendor_elem[frame] == NULL) | |
6834 | return -1; | |
6835 | ||
6836 | len = os_strlen(pos); | |
6837 | if (len == 0) | |
6838 | return 0; | |
6839 | if (len & 1) | |
6840 | return -1; | |
6841 | len /= 2; | |
6842 | ||
6843 | buf = os_malloc(len); | |
6844 | if (buf == NULL) | |
6845 | return -1; | |
6846 | ||
6847 | if (hexstr2bin(pos, buf, len) < 0) { | |
6848 | os_free(buf); | |
6849 | return -1; | |
6850 | } | |
6851 | ||
6852 | if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) { | |
6853 | os_free(buf); | |
6854 | return -1; | |
6855 | } | |
6856 | ||
6857 | ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]); | |
6858 | end = ie + wpabuf_len(wpa_s->vendor_elem[frame]); | |
6859 | ||
6860 | for (; ie + 1 < end; ie += 2 + ie[1]) { | |
6861 | if (ie + len > end) | |
6862 | break; | |
6863 | if (os_memcmp(ie, buf, len) != 0) | |
6864 | continue; | |
6865 | ||
6866 | if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) { | |
6867 | wpabuf_free(wpa_s->vendor_elem[frame]); | |
6868 | wpa_s->vendor_elem[frame] = NULL; | |
6869 | } else { | |
6870 | os_memmove(ie, ie + len, | |
45d85015 | 6871 | end - (ie + len)); |
86bd36f0 JM |
6872 | wpa_s->vendor_elem[frame]->used -= len; |
6873 | } | |
6874 | os_free(buf); | |
6875 | wpas_ctrl_vendor_elem_update(wpa_s); | |
6876 | return 0; | |
6877 | } | |
6878 | ||
6879 | os_free(buf); | |
6880 | ||
6881 | return -1; | |
6882 | } | |
6883 | ||
6884 | ||
f4b8bfae AK |
6885 | static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep) |
6886 | { | |
6887 | struct wpa_supplicant *wpa_s = ctx; | |
6888 | ||
6889 | if (neighbor_rep) { | |
6890 | wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED | |
6891 | "length=%u", | |
6892 | (unsigned int) wpabuf_len(neighbor_rep)); | |
6893 | wpabuf_free(neighbor_rep); | |
6894 | } else { | |
6895 | wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED); | |
6896 | } | |
6897 | } | |
6898 | ||
6899 | ||
4c4b2305 AK |
6900 | static int wpas_ctrl_iface_send_neigbor_rep(struct wpa_supplicant *wpa_s, |
6901 | char *cmd) | |
f4b8bfae | 6902 | { |
4c4b2305 AK |
6903 | struct wpa_ssid ssid; |
6904 | struct wpa_ssid *ssid_p = NULL; | |
6905 | int ret = 0; | |
6906 | ||
6907 | if (os_strncmp(cmd, " ssid=", 6) == 0) { | |
6908 | ssid.ssid_len = os_strlen(cmd + 6); | |
6909 | if (ssid.ssid_len > 32) | |
6910 | return -1; | |
6911 | ssid.ssid = (u8 *) (cmd + 6); | |
6912 | ssid_p = &ssid; | |
6913 | } | |
6914 | ||
6915 | ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, | |
6916 | wpas_ctrl_neighbor_rep_cb, | |
6917 | wpa_s); | |
6918 | ||
6919 | return ret; | |
f4b8bfae AK |
6920 | } |
6921 | ||
6922 | ||
6fc6879b JM |
6923 | char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, |
6924 | char *buf, size_t *resp_len) | |
6925 | { | |
6926 | char *reply; | |
b563b388 | 6927 | const int reply_size = 4096; |
6fc6879b JM |
6928 | int reply_len; |
6929 | ||
6930 | if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 || | |
d31b5ac7 JM |
6931 | os_strncmp(buf, "SET_NETWORK ", 12) == 0) { |
6932 | if (wpa_debug_show_keys) | |
6933 | wpa_dbg(wpa_s, MSG_DEBUG, | |
6934 | "Control interface command '%s'", buf); | |
6935 | else | |
6936 | wpa_dbg(wpa_s, MSG_DEBUG, | |
6937 | "Control interface command '%s [REMOVED]'", | |
6938 | os_strncmp(buf, WPA_CTRL_RSP, | |
6939 | os_strlen(WPA_CTRL_RSP)) == 0 ? | |
6940 | WPA_CTRL_RSP : "SET_NETWORK"); | |
6941 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 || | |
679f2e7c | 6942 | os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) { |
6fc6879b JM |
6943 | wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", |
6944 | (const u8 *) buf, os_strlen(buf)); | |
6945 | } else { | |
235f69fc JM |
6946 | int level = MSG_DEBUG; |
6947 | if (os_strcmp(buf, "PING") == 0) | |
6948 | level = MSG_EXCESSIVE; | |
b470b2bf | 6949 | wpa_dbg(wpa_s, level, "Control interface command '%s'", buf); |
6fc6879b JM |
6950 | } |
6951 | ||
6952 | reply = os_malloc(reply_size); | |
6953 | if (reply == NULL) { | |
6954 | *resp_len = 1; | |
6955 | return NULL; | |
6956 | } | |
6957 | ||
6958 | os_memcpy(reply, "OK\n", 3); | |
6959 | reply_len = 3; | |
6960 | ||
6961 | if (os_strcmp(buf, "PING") == 0) { | |
6962 | os_memcpy(reply, "PONG\n", 5); | |
6963 | reply_len = 5; | |
0eed2a8d JD |
6964 | } else if (os_strcmp(buf, "IFNAME") == 0) { |
6965 | reply_len = os_strlen(wpa_s->ifname); | |
6966 | os_memcpy(reply, wpa_s->ifname, reply_len); | |
ac6912b5 BG |
6967 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
6968 | if (wpa_debug_reopen_file() < 0) | |
6969 | reply_len = -1; | |
77895cd9 JM |
6970 | } else if (os_strncmp(buf, "NOTE ", 5) == 0) { |
6971 | wpa_printf(MSG_INFO, "NOTE: %s", buf + 5); | |
6fc6879b JM |
6972 | } else if (os_strcmp(buf, "MIB") == 0) { |
6973 | reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); | |
6974 | if (reply_len >= 0) { | |
6975 | int res; | |
6976 | res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len, | |
6977 | reply_size - reply_len); | |
6978 | if (res < 0) | |
6979 | reply_len = -1; | |
6980 | else | |
6981 | reply_len += res; | |
6982 | } | |
6983 | } else if (os_strncmp(buf, "STATUS", 6) == 0) { | |
6984 | reply_len = wpa_supplicant_ctrl_iface_status( | |
6985 | wpa_s, buf + 6, reply, reply_size); | |
6986 | } else if (os_strcmp(buf, "PMKSA") == 0) { | |
540264a7 JM |
6987 | reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply, |
6988 | reply_size); | |
79e2b1cc AK |
6989 | } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) { |
6990 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); | |
6fc6879b JM |
6991 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
6992 | if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) | |
6993 | reply_len = -1; | |
acec8d32 JM |
6994 | } else if (os_strncmp(buf, "GET ", 4) == 0) { |
6995 | reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4, | |
6996 | reply, reply_size); | |
6fc6879b JM |
6997 | } else if (os_strcmp(buf, "LOGON") == 0) { |
6998 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); | |
6999 | } else if (os_strcmp(buf, "LOGOFF") == 0) { | |
7000 | eapol_sm_notify_logoff(wpa_s->eapol, TRUE); | |
7001 | } else if (os_strcmp(buf, "REASSOCIATE") == 0) { | |
8401a6b0 JM |
7002 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
7003 | reply_len = -1; | |
9796a86c JM |
7004 | else |
7005 | wpas_request_connection(wpa_s); | |
0f44ec8e PQ |
7006 | } else if (os_strcmp(buf, "REATTACH") == 0) { |
7007 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED || | |
7008 | !wpa_s->current_ssid) | |
7009 | reply_len = -1; | |
7010 | else { | |
7011 | wpa_s->reattach = 1; | |
7012 | wpas_request_connection(wpa_s); | |
7013 | } | |
6fc6879b | 7014 | } else if (os_strcmp(buf, "RECONNECT") == 0) { |
8401a6b0 JM |
7015 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
7016 | reply_len = -1; | |
9796a86c JM |
7017 | else if (wpa_s->disconnected) |
7018 | wpas_request_connection(wpa_s); | |
ec717917 | 7019 | #ifdef IEEE8021X_EAPOL |
6fc6879b JM |
7020 | } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { |
7021 | if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) | |
7022 | reply_len = -1; | |
ec717917 | 7023 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
7024 | #ifdef CONFIG_PEERKEY |
7025 | } else if (os_strncmp(buf, "STKSTART ", 9) == 0) { | |
7026 | if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9)) | |
7027 | reply_len = -1; | |
7028 | #endif /* CONFIG_PEERKEY */ | |
7029 | #ifdef CONFIG_IEEE80211R | |
7030 | } else if (os_strncmp(buf, "FT_DS ", 6) == 0) { | |
7031 | if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6)) | |
7032 | reply_len = -1; | |
7033 | #endif /* CONFIG_IEEE80211R */ | |
fcc60db4 JM |
7034 | #ifdef CONFIG_WPS |
7035 | } else if (os_strcmp(buf, "WPS_PBC") == 0) { | |
3152ff42 CWY |
7036 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL); |
7037 | if (res == -2) { | |
7038 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
7039 | reply_len = 17; | |
7040 | } else if (res) | |
fcc60db4 JM |
7041 | reply_len = -1; |
7042 | } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) { | |
3152ff42 CWY |
7043 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8); |
7044 | if (res == -2) { | |
7045 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
7046 | reply_len = 17; | |
7047 | } else if (res) | |
fcc60db4 JM |
7048 | reply_len = -1; |
7049 | } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) { | |
7050 | reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8, | |
7051 | reply, | |
7052 | reply_size); | |
3981cb3c JM |
7053 | } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) { |
7054 | reply_len = wpa_supplicant_ctrl_iface_wps_check_pin( | |
7055 | wpa_s, buf + 14, reply, reply_size); | |
2f9929ff AC |
7056 | } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { |
7057 | if (wpas_wps_cancel(wpa_s)) | |
7058 | reply_len = -1; | |
71892384 | 7059 | #ifdef CONFIG_WPS_NFC |
3f2c8ba6 JM |
7060 | } else if (os_strcmp(buf, "WPS_NFC") == 0) { |
7061 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL)) | |
7062 | reply_len = -1; | |
7063 | } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) { | |
7064 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8)) | |
7065 | reply_len = -1; | |
bbf41865 JM |
7066 | } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) { |
7067 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token( | |
7068 | wpa_s, buf + 21, reply, reply_size); | |
3f2c8ba6 JM |
7069 | } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) { |
7070 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token( | |
7071 | wpa_s, buf + 14, reply, reply_size); | |
d7645d23 JM |
7072 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) { |
7073 | if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s, | |
7074 | buf + 17)) | |
7075 | reply_len = -1; | |
e65552dd JM |
7076 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) { |
7077 | reply_len = wpas_ctrl_nfc_get_handover_req( | |
7078 | wpa_s, buf + 21, reply, reply_size); | |
7079 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) { | |
7080 | reply_len = wpas_ctrl_nfc_get_handover_sel( | |
7081 | wpa_s, buf + 21, reply, reply_size); | |
e4758827 JM |
7082 | } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) { |
7083 | if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20)) | |
7084 | reply_len = -1; | |
71892384 | 7085 | #endif /* CONFIG_WPS_NFC */ |
fcc60db4 JM |
7086 | } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) { |
7087 | if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8)) | |
7088 | reply_len = -1; | |
70d84f11 JM |
7089 | #ifdef CONFIG_AP |
7090 | } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) { | |
7091 | reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin( | |
7092 | wpa_s, buf + 11, reply, reply_size); | |
7093 | #endif /* CONFIG_AP */ | |
72df2f5f | 7094 | #ifdef CONFIG_WPS_ER |
e9bcfebf | 7095 | } else if (os_strcmp(buf, "WPS_ER_START") == 0) { |
08486685 JM |
7096 | if (wpas_wps_er_start(wpa_s, NULL)) |
7097 | reply_len = -1; | |
7098 | } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) { | |
7099 | if (wpas_wps_er_start(wpa_s, buf + 13)) | |
e9bcfebf JM |
7100 | reply_len = -1; |
7101 | } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) { | |
7102 | if (wpas_wps_er_stop(wpa_s)) | |
7103 | reply_len = -1; | |
72df2f5f JM |
7104 | } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) { |
7105 | if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11)) | |
7106 | reply_len = -1; | |
564cd7fa | 7107 | } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) { |
ed159ad4 JM |
7108 | int ret = wpas_wps_er_pbc(wpa_s, buf + 11); |
7109 | if (ret == -2) { | |
7110 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
7111 | reply_len = 17; | |
7112 | } else if (ret == -3) { | |
7113 | os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18); | |
7114 | reply_len = 18; | |
7115 | } else if (ret == -4) { | |
7116 | os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20); | |
7117 | reply_len = 20; | |
7118 | } else if (ret) | |
564cd7fa | 7119 | reply_len = -1; |
e64dcfd5 JM |
7120 | } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) { |
7121 | if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13)) | |
7122 | reply_len = -1; | |
ef10f473 JM |
7123 | } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) { |
7124 | if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s, | |
7125 | buf + 18)) | |
7126 | reply_len = -1; | |
7d6640a6 JM |
7127 | } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) { |
7128 | if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14)) | |
7129 | reply_len = -1; | |
1cea09a9 JM |
7130 | #ifdef CONFIG_WPS_NFC |
7131 | } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) { | |
7132 | reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | |
7133 | wpa_s, buf + 24, reply, reply_size); | |
7134 | #endif /* CONFIG_WPS_NFC */ | |
72df2f5f | 7135 | #endif /* CONFIG_WPS_ER */ |
fcc60db4 | 7136 | #endif /* CONFIG_WPS */ |
11ef8d35 JM |
7137 | #ifdef CONFIG_IBSS_RSN |
7138 | } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) { | |
7139 | if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) | |
7140 | reply_len = -1; | |
7141 | #endif /* CONFIG_IBSS_RSN */ | |
603a3f34 JL |
7142 | #ifdef CONFIG_MESH |
7143 | } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) { | |
7144 | if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15)) | |
7145 | reply_len = -1; | |
7146 | } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) { | |
7147 | if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s, | |
7148 | buf + 18)) | |
7149 | reply_len = -1; | |
7150 | #endif /* CONFIG_MESH */ | |
b563b388 JM |
7151 | #ifdef CONFIG_P2P |
7152 | } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { | |
7153 | if (p2p_ctrl_find(wpa_s, buf + 9)) | |
7154 | reply_len = -1; | |
7155 | } else if (os_strcmp(buf, "P2P_FIND") == 0) { | |
7156 | if (p2p_ctrl_find(wpa_s, "")) | |
7157 | reply_len = -1; | |
7158 | } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) { | |
7159 | wpas_p2p_stop_find(wpa_s); | |
7160 | } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) { | |
7161 | reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply, | |
7162 | reply_size); | |
7163 | } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) { | |
7164 | if (p2p_ctrl_listen(wpa_s, buf + 11)) | |
7165 | reply_len = -1; | |
7166 | } else if (os_strcmp(buf, "P2P_LISTEN") == 0) { | |
7167 | if (p2p_ctrl_listen(wpa_s, "")) | |
7168 | reply_len = -1; | |
7169 | } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) { | |
7170 | if (wpas_p2p_group_remove(wpa_s, buf + 17)) | |
7171 | reply_len = -1; | |
7172 | } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) { | |
20ea1ca4 | 7173 | if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0)) |
b563b388 JM |
7174 | reply_len = -1; |
7175 | } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) { | |
7176 | if (p2p_ctrl_group_add(wpa_s, buf + 14)) | |
7177 | reply_len = -1; | |
7178 | } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) { | |
7179 | if (p2p_ctrl_prov_disc(wpa_s, buf + 14)) | |
7180 | reply_len = -1; | |
7181 | } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) { | |
7182 | reply_len = p2p_get_passphrase(wpa_s, reply, reply_size); | |
7183 | } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) { | |
7184 | reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply, | |
7185 | reply_size); | |
7186 | } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) { | |
7187 | if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0) | |
7188 | reply_len = -1; | |
7189 | } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) { | |
7190 | if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0) | |
7191 | reply_len = -1; | |
7192 | } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) { | |
7193 | wpas_p2p_sd_service_update(wpa_s); | |
7194 | } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) { | |
7195 | if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0) | |
7196 | reply_len = -1; | |
7197 | } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) { | |
7198 | wpas_p2p_service_flush(wpa_s); | |
7199 | } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) { | |
7200 | if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0) | |
7201 | reply_len = -1; | |
7202 | } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) { | |
7203 | if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0) | |
7204 | reply_len = -1; | |
7205 | } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) { | |
7206 | if (p2p_ctrl_reject(wpa_s, buf + 11) < 0) | |
7207 | reply_len = -1; | |
7208 | } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) { | |
7209 | if (p2p_ctrl_invite(wpa_s, buf + 11) < 0) | |
7210 | reply_len = -1; | |
7211 | } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) { | |
7212 | reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply, | |
7213 | reply_size); | |
7214 | } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) { | |
7215 | if (p2p_ctrl_set(wpa_s, buf + 8) < 0) | |
7216 | reply_len = -1; | |
7217 | } else if (os_strcmp(buf, "P2P_FLUSH") == 0) { | |
acb54643 | 7218 | p2p_ctrl_flush(wpa_s); |
9d562b79 SS |
7219 | } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { |
7220 | if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) | |
7221 | reply_len = -1; | |
59eba7a2 JM |
7222 | } else if (os_strcmp(buf, "P2P_CANCEL") == 0) { |
7223 | if (wpas_p2p_cancel(wpa_s)) | |
7224 | reply_len = -1; | |
b563b388 JM |
7225 | } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) { |
7226 | if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0) | |
7227 | reply_len = -1; | |
7228 | } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) { | |
7229 | if (p2p_ctrl_presence_req(wpa_s, "") < 0) | |
7230 | reply_len = -1; | |
7231 | } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) { | |
7232 | if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0) | |
7233 | reply_len = -1; | |
7234 | } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) { | |
7235 | if (p2p_ctrl_ext_listen(wpa_s, "") < 0) | |
7236 | reply_len = -1; | |
f2c56602 JM |
7237 | } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) { |
7238 | if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0) | |
7239 | reply_len = -1; | |
b563b388 | 7240 | #endif /* CONFIG_P2P */ |
9675ce35 JM |
7241 | #ifdef CONFIG_WIFI_DISPLAY |
7242 | } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) { | |
7243 | if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0) | |
7244 | reply_len = -1; | |
7245 | } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) { | |
7246 | reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16, | |
7247 | reply, reply_size); | |
7248 | #endif /* CONFIG_WIFI_DISPLAY */ | |
afc064fe JM |
7249 | #ifdef CONFIG_INTERWORKING |
7250 | } else if (os_strcmp(buf, "FETCH_ANQP") == 0) { | |
7251 | if (interworking_fetch_anqp(wpa_s) < 0) | |
7252 | reply_len = -1; | |
7253 | } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) { | |
7254 | interworking_stop_fetch_anqp(wpa_s); | |
356d1488 JM |
7255 | } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) { |
7256 | if (ctrl_interworking_select(wpa_s, NULL) < 0) | |
7257 | reply_len = -1; | |
7258 | } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) { | |
7259 | if (ctrl_interworking_select(wpa_s, buf + 20) < 0) | |
b02fe7ff JM |
7260 | reply_len = -1; |
7261 | } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) { | |
7262 | if (ctrl_interworking_connect(wpa_s, buf + 21) < 0) | |
7263 | reply_len = -1; | |
afc064fe JM |
7264 | } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) { |
7265 | if (get_anqp(wpa_s, buf + 9) < 0) | |
7266 | reply_len = -1; | |
b1f12296 JM |
7267 | } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) { |
7268 | if (gas_request(wpa_s, buf + 12) < 0) | |
7269 | reply_len = -1; | |
7270 | } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) { | |
7271 | reply_len = gas_response_get(wpa_s, buf + 17, reply, | |
7272 | reply_size); | |
afc064fe | 7273 | #endif /* CONFIG_INTERWORKING */ |
a8918e86 JK |
7274 | #ifdef CONFIG_HS20 |
7275 | } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) { | |
7276 | if (get_hs20_anqp(wpa_s, buf + 14) < 0) | |
7277 | reply_len = -1; | |
7278 | } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) { | |
7279 | if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0) | |
7280 | reply_len = -1; | |
184e110c JM |
7281 | } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) { |
7282 | if (hs20_icon_request(wpa_s, buf + 18) < 0) | |
7283 | reply_len = -1; | |
b572df86 JM |
7284 | } else if (os_strcmp(buf, "FETCH_OSU") == 0) { |
7285 | if (hs20_fetch_osu(wpa_s) < 0) | |
7286 | reply_len = -1; | |
7287 | } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) { | |
7288 | hs20_cancel_fetch_osu(wpa_s); | |
a8918e86 | 7289 | #endif /* CONFIG_HS20 */ |
6fc6879b JM |
7290 | } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) |
7291 | { | |
7292 | if (wpa_supplicant_ctrl_iface_ctrl_rsp( | |
7293 | wpa_s, buf + os_strlen(WPA_CTRL_RSP))) | |
7294 | reply_len = -1; | |
bceb8431 JM |
7295 | else { |
7296 | /* | |
7297 | * Notify response from timeout to allow the control | |
7298 | * interface response to be sent first. | |
7299 | */ | |
7300 | eloop_register_timeout(0, 0, wpas_ctrl_eapol_response, | |
7301 | wpa_s, NULL); | |
7302 | } | |
6fc6879b JM |
7303 | } else if (os_strcmp(buf, "RECONFIGURE") == 0) { |
7304 | if (wpa_supplicant_reload_configuration(wpa_s)) | |
7305 | reply_len = -1; | |
7306 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | |
1a1bf008 | 7307 | wpa_supplicant_terminate_proc(wpa_s->global); |
6fc6879b JM |
7308 | } else if (os_strncmp(buf, "BSSID ", 6) == 0) { |
7309 | if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) | |
7310 | reply_len = -1; | |
9aa10e2b DS |
7311 | } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) { |
7312 | reply_len = wpa_supplicant_ctrl_iface_blacklist( | |
7313 | wpa_s, buf + 9, reply, reply_size); | |
0597a5b5 DS |
7314 | } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) { |
7315 | reply_len = wpa_supplicant_ctrl_iface_log_level( | |
7316 | wpa_s, buf + 9, reply, reply_size); | |
90903a77 VD |
7317 | } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) { |
7318 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | |
7319 | wpa_s, buf + 14, reply, reply_size); | |
6fc6879b JM |
7320 | } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { |
7321 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | |
90903a77 | 7322 | wpa_s, NULL, reply, reply_size); |
6fc6879b | 7323 | } else if (os_strcmp(buf, "DISCONNECT") == 0) { |
83df8149 JM |
7324 | #ifdef CONFIG_SME |
7325 | wpa_s->sme.prev_bssid_set = 0; | |
7326 | #endif /* CONFIG_SME */ | |
6fc6879b JM |
7327 | wpa_s->reassociate = 0; |
7328 | wpa_s->disconnected = 1; | |
6ad9c911 | 7329 | wpa_supplicant_cancel_sched_scan(wpa_s); |
d7ded758 | 7330 | wpa_supplicant_cancel_scan(wpa_s); |
cf4783e3 JM |
7331 | wpa_supplicant_deauthenticate(wpa_s, |
7332 | WLAN_REASON_DEAUTH_LEAVING); | |
fee52342 JM |
7333 | } else if (os_strcmp(buf, "SCAN") == 0) { |
7334 | wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len); | |
7335 | } else if (os_strncmp(buf, "SCAN ", 5) == 0) { | |
7336 | wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len); | |
6fc6879b JM |
7337 | } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { |
7338 | reply_len = wpa_supplicant_ctrl_iface_scan_results( | |
7339 | wpa_s, reply, reply_size); | |
7340 | } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { | |
7341 | if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) | |
7342 | reply_len = -1; | |
7343 | } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { | |
7344 | if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) | |
7345 | reply_len = -1; | |
7346 | } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { | |
7347 | if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) | |
7348 | reply_len = -1; | |
7349 | } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { | |
7350 | reply_len = wpa_supplicant_ctrl_iface_add_network( | |
7351 | wpa_s, reply, reply_size); | |
7352 | } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { | |
7353 | if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) | |
7354 | reply_len = -1; | |
7355 | } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { | |
7356 | if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) | |
7357 | reply_len = -1; | |
7358 | } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { | |
7359 | reply_len = wpa_supplicant_ctrl_iface_get_network( | |
7360 | wpa_s, buf + 12, reply, reply_size); | |
1c330a2f DS |
7361 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
7362 | if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12)) | |
7363 | reply_len = -1; | |
d94c9ee6 JM |
7364 | } else if (os_strcmp(buf, "LIST_CREDS") == 0) { |
7365 | reply_len = wpa_supplicant_ctrl_iface_list_creds( | |
7366 | wpa_s, reply, reply_size); | |
7367 | } else if (os_strcmp(buf, "ADD_CRED") == 0) { | |
7368 | reply_len = wpa_supplicant_ctrl_iface_add_cred( | |
7369 | wpa_s, reply, reply_size); | |
7370 | } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) { | |
7371 | if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12)) | |
7372 | reply_len = -1; | |
7373 | } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) { | |
7374 | if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9)) | |
7375 | reply_len = -1; | |
c880ab87 JM |
7376 | } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) { |
7377 | reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9, | |
7378 | reply, | |
7379 | reply_size); | |
6fc6879b JM |
7380 | #ifndef CONFIG_NO_CONFIG_WRITE |
7381 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | |
7382 | if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) | |
7383 | reply_len = -1; | |
7384 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
7385 | } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { | |
7386 | reply_len = wpa_supplicant_ctrl_iface_get_capability( | |
7387 | wpa_s, buf + 15, reply, reply_size); | |
7388 | } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { | |
7389 | if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) | |
7390 | reply_len = -1; | |
67b9bd08 DS |
7391 | } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) { |
7392 | if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14)) | |
7393 | reply_len = -1; | |
4b4a8ae5 JM |
7394 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
7395 | reply_len = wpa_supplicant_global_iface_list( | |
7396 | wpa_s->global, reply, reply_size); | |
6fc6879b JM |
7397 | } else if (os_strcmp(buf, "INTERFACES") == 0) { |
7398 | reply_len = wpa_supplicant_global_iface_interfaces( | |
7399 | wpa_s->global, reply, reply_size); | |
7400 | } else if (os_strncmp(buf, "BSS ", 4) == 0) { | |
7401 | reply_len = wpa_supplicant_ctrl_iface_bss( | |
7402 | wpa_s, buf + 4, reply, reply_size); | |
e653b622 JM |
7403 | #ifdef CONFIG_AP |
7404 | } else if (os_strcmp(buf, "STA-FIRST") == 0) { | |
7405 | reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size); | |
7406 | } else if (os_strncmp(buf, "STA ", 4) == 0) { | |
7407 | reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply, | |
7408 | reply_size); | |
7409 | } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { | |
7410 | reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply, | |
7411 | reply_size); | |
e60b2951 JJ |
7412 | } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) { |
7413 | if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15)) | |
7414 | reply_len = -1; | |
7415 | } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) { | |
7416 | if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13)) | |
7417 | reply_len = -1; | |
334bf36a AO |
7418 | } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) { |
7419 | if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12)) | |
7420 | reply_len = -1; | |
e653b622 | 7421 | #endif /* CONFIG_AP */ |
207ef3fb JM |
7422 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
7423 | wpas_notify_suspend(wpa_s->global); | |
7424 | } else if (os_strcmp(buf, "RESUME") == 0) { | |
7425 | wpas_notify_resume(wpa_s->global); | |
9ff4de6d | 7426 | #ifdef CONFIG_TESTING_OPTIONS |
32d5295f JM |
7427 | } else if (os_strcmp(buf, "DROP_SA") == 0) { |
7428 | wpa_supplicant_ctrl_iface_drop_sa(wpa_s); | |
9ff4de6d | 7429 | #endif /* CONFIG_TESTING_OPTIONS */ |
86d4f806 JM |
7430 | } else if (os_strncmp(buf, "ROAM ", 5) == 0) { |
7431 | if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) | |
7432 | reply_len = -1; | |
0d0a8ca1 AC |
7433 | } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { |
7434 | if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16)) | |
7435 | reply_len = -1; | |
78633c37 SL |
7436 | } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) { |
7437 | if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15)) | |
7438 | reply_len = -1; | |
7439 | } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) { | |
7440 | if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s, | |
7441 | buf + 17)) | |
7442 | reply_len = -1; | |
39ee845f DS |
7443 | } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) { |
7444 | if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10)) | |
7445 | reply_len = -1; | |
281ff0aa GP |
7446 | #ifdef CONFIG_TDLS |
7447 | } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) { | |
7448 | if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14)) | |
7449 | reply_len = -1; | |
7450 | } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) { | |
7451 | if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11)) | |
7452 | reply_len = -1; | |
7453 | } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) { | |
7454 | if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14)) | |
7455 | reply_len = -1; | |
7456 | #endif /* CONFIG_TDLS */ | |
8506ea6f MB |
7457 | } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) { |
7458 | reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size); | |
eb2f2088 MB |
7459 | } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) { |
7460 | if (wmm_ac_ctrl_addts(wpa_s, buf + 13)) | |
7461 | reply_len = -1; | |
7462 | } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) { | |
7463 | if (wmm_ac_ctrl_delts(wpa_s, buf + 13)) | |
7464 | reply_len = -1; | |
60b24b0d DS |
7465 | } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) { |
7466 | reply_len = wpa_supplicant_signal_poll(wpa_s, reply, | |
7467 | reply_size); | |
dc7785f8 YZ |
7468 | } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) { |
7469 | reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply, | |
7470 | reply_size); | |
bc5d330a TB |
7471 | #ifdef CONFIG_AUTOSCAN |
7472 | } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) { | |
7473 | if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9)) | |
7474 | reply_len = -1; | |
7475 | #endif /* CONFIG_AUTOSCAN */ | |
5e2c3490 JM |
7476 | #ifdef ANDROID |
7477 | } else if (os_strncmp(buf, "DRIVER ", 7) == 0) { | |
7478 | reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply, | |
7479 | reply_size); | |
7480 | #endif /* ANDROID */ | |
adef8948 BL |
7481 | } else if (os_strncmp(buf, "VENDOR ", 7) == 0) { |
7482 | reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply, | |
7483 | reply_size); | |
9482426e | 7484 | } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) { |
f5f37d3a | 7485 | pmksa_cache_clear_current(wpa_s->wpa); |
9482426e | 7486 | eapol_sm_request_reauth(wpa_s->eapol); |
e9199e31 JM |
7487 | #ifdef CONFIG_WNM |
7488 | } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) { | |
7489 | if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10)) | |
7490 | reply_len = -1; | |
65bcd0a9 VK |
7491 | } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) { |
7492 | if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10)) | |
7493 | reply_len = -1; | |
e9199e31 | 7494 | #endif /* CONFIG_WNM */ |
acb54643 JM |
7495 | } else if (os_strcmp(buf, "FLUSH") == 0) { |
7496 | wpa_supplicant_ctrl_iface_flush(wpa_s); | |
1f965e62 JM |
7497 | } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) { |
7498 | reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply, | |
7499 | reply_size); | |
60b893df JM |
7500 | #ifdef CONFIG_TESTING_OPTIONS |
7501 | } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) { | |
7502 | if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0) | |
7503 | reply_len = -1; | |
7504 | } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) { | |
7505 | wpas_ctrl_iface_mgmt_tx_done(wpa_s); | |
ad12f2f4 JM |
7506 | } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) { |
7507 | if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0) | |
7508 | reply_len = -1; | |
9d4ff04a JM |
7509 | } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) { |
7510 | if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0) | |
7511 | reply_len = -1; | |
4a6cc862 JM |
7512 | } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) { |
7513 | if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0) | |
7514 | reply_len = -1; | |
7515 | } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) { | |
7516 | if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0) | |
7517 | reply_len = -1; | |
fc0ef7c0 JM |
7518 | } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) { |
7519 | if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0) | |
7520 | reply_len = -1; | |
60b893df | 7521 | #endif /* CONFIG_TESTING_OPTIONS */ |
86bd36f0 JM |
7522 | } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) { |
7523 | if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0) | |
7524 | reply_len = -1; | |
7525 | } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) { | |
7526 | reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply, | |
7527 | reply_size); | |
7528 | } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) { | |
7529 | if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0) | |
7530 | reply_len = -1; | |
f4b8bfae | 7531 | } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) { |
4c4b2305 | 7532 | if (wpas_ctrl_iface_send_neigbor_rep(wpa_s, buf + 20)) |
f4b8bfae | 7533 | reply_len = -1; |
6fc6879b JM |
7534 | } else { |
7535 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | |
7536 | reply_len = 16; | |
7537 | } | |
7538 | ||
7539 | if (reply_len < 0) { | |
7540 | os_memcpy(reply, "FAIL\n", 5); | |
7541 | reply_len = 5; | |
7542 | } | |
7543 | ||
6fc6879b JM |
7544 | *resp_len = reply_len; |
7545 | return reply; | |
7546 | } | |
7547 | ||
7548 | ||
7549 | static int wpa_supplicant_global_iface_add(struct wpa_global *global, | |
7550 | char *cmd) | |
7551 | { | |
7552 | struct wpa_interface iface; | |
7553 | char *pos; | |
7554 | ||
7555 | /* | |
7556 | * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param> | |
7557 | * TAB<bridge_ifname> | |
7558 | */ | |
7559 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd); | |
7560 | ||
7561 | os_memset(&iface, 0, sizeof(iface)); | |
7562 | ||
7563 | do { | |
7564 | iface.ifname = pos = cmd; | |
7565 | pos = os_strchr(pos, '\t'); | |
7566 | if (pos) | |
7567 | *pos++ = '\0'; | |
7568 | if (iface.ifname[0] == '\0') | |
7569 | return -1; | |
7570 | if (pos == NULL) | |
7571 | break; | |
7572 | ||
7573 | iface.confname = pos; | |
7574 | pos = os_strchr(pos, '\t'); | |
7575 | if (pos) | |
7576 | *pos++ = '\0'; | |
7577 | if (iface.confname[0] == '\0') | |
7578 | iface.confname = NULL; | |
7579 | if (pos == NULL) | |
7580 | break; | |
7581 | ||
7582 | iface.driver = pos; | |
7583 | pos = os_strchr(pos, '\t'); | |
7584 | if (pos) | |
7585 | *pos++ = '\0'; | |
7586 | if (iface.driver[0] == '\0') | |
7587 | iface.driver = NULL; | |
7588 | if (pos == NULL) | |
7589 | break; | |
7590 | ||
7591 | iface.ctrl_interface = pos; | |
7592 | pos = os_strchr(pos, '\t'); | |
7593 | if (pos) | |
7594 | *pos++ = '\0'; | |
7595 | if (iface.ctrl_interface[0] == '\0') | |
7596 | iface.ctrl_interface = NULL; | |
7597 | if (pos == NULL) | |
7598 | break; | |
7599 | ||
7600 | iface.driver_param = pos; | |
7601 | pos = os_strchr(pos, '\t'); | |
7602 | if (pos) | |
7603 | *pos++ = '\0'; | |
7604 | if (iface.driver_param[0] == '\0') | |
7605 | iface.driver_param = NULL; | |
7606 | if (pos == NULL) | |
7607 | break; | |
7608 | ||
7609 | iface.bridge_ifname = pos; | |
7610 | pos = os_strchr(pos, '\t'); | |
7611 | if (pos) | |
7612 | *pos++ = '\0'; | |
7613 | if (iface.bridge_ifname[0] == '\0') | |
7614 | iface.bridge_ifname = NULL; | |
7615 | if (pos == NULL) | |
7616 | break; | |
7617 | } while (0); | |
7618 | ||
7619 | if (wpa_supplicant_get_iface(global, iface.ifname)) | |
7620 | return -1; | |
7621 | ||
7622 | return wpa_supplicant_add_iface(global, &iface) ? 0 : -1; | |
7623 | } | |
7624 | ||
7625 | ||
7626 | static int wpa_supplicant_global_iface_remove(struct wpa_global *global, | |
7627 | char *cmd) | |
7628 | { | |
7629 | struct wpa_supplicant *wpa_s; | |
7630 | ||
7631 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd); | |
7632 | ||
7633 | wpa_s = wpa_supplicant_get_iface(global, cmd); | |
7634 | if (wpa_s == NULL) | |
7635 | return -1; | |
df509539 | 7636 | return wpa_supplicant_remove_iface(global, wpa_s, 0); |
6fc6879b JM |
7637 | } |
7638 | ||
7639 | ||
4b4a8ae5 JM |
7640 | static void wpa_free_iface_info(struct wpa_interface_info *iface) |
7641 | { | |
7642 | struct wpa_interface_info *prev; | |
7643 | ||
7644 | while (iface) { | |
7645 | prev = iface; | |
7646 | iface = iface->next; | |
7647 | ||
7648 | os_free(prev->ifname); | |
7649 | os_free(prev->desc); | |
7650 | os_free(prev); | |
7651 | } | |
7652 | } | |
7653 | ||
7654 | ||
7655 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, | |
7656 | char *buf, int len) | |
7657 | { | |
7658 | int i, res; | |
7659 | struct wpa_interface_info *iface = NULL, *last = NULL, *tmp; | |
7660 | char *pos, *end; | |
7661 | ||
c5121837 JM |
7662 | for (i = 0; wpa_drivers[i]; i++) { |
7663 | struct wpa_driver_ops *drv = wpa_drivers[i]; | |
4b4a8ae5 JM |
7664 | if (drv->get_interfaces == NULL) |
7665 | continue; | |
5fbc1f27 | 7666 | tmp = drv->get_interfaces(global->drv_priv[i]); |
4b4a8ae5 JM |
7667 | if (tmp == NULL) |
7668 | continue; | |
7669 | ||
7670 | if (last == NULL) | |
7671 | iface = last = tmp; | |
7672 | else | |
7673 | last->next = tmp; | |
7674 | while (last->next) | |
7675 | last = last->next; | |
7676 | } | |
7677 | ||
7678 | pos = buf; | |
7679 | end = buf + len; | |
7680 | for (tmp = iface; tmp; tmp = tmp->next) { | |
7681 | res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n", | |
7682 | tmp->drv_name, tmp->ifname, | |
7683 | tmp->desc ? tmp->desc : ""); | |
7684 | if (res < 0 || res >= end - pos) { | |
7685 | *pos = '\0'; | |
7686 | break; | |
7687 | } | |
7688 | pos += res; | |
7689 | } | |
7690 | ||
7691 | wpa_free_iface_info(iface); | |
7692 | ||
7693 | return pos - buf; | |
7694 | } | |
7695 | ||
7696 | ||
6fc6879b JM |
7697 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
7698 | char *buf, int len) | |
7699 | { | |
7700 | int res; | |
7701 | char *pos, *end; | |
7702 | struct wpa_supplicant *wpa_s; | |
7703 | ||
7704 | wpa_s = global->ifaces; | |
7705 | pos = buf; | |
7706 | end = buf + len; | |
7707 | ||
7708 | while (wpa_s) { | |
7709 | res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname); | |
7710 | if (res < 0 || res >= end - pos) { | |
7711 | *pos = '\0'; | |
7712 | break; | |
7713 | } | |
7714 | pos += res; | |
7715 | wpa_s = wpa_s->next; | |
7716 | } | |
7717 | return pos - buf; | |
7718 | } | |
7719 | ||
7720 | ||
cf3bebf2 JM |
7721 | static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global, |
7722 | const char *ifname, | |
7723 | char *cmd, size_t *resp_len) | |
7724 | { | |
7725 | struct wpa_supplicant *wpa_s; | |
7726 | ||
7727 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
7728 | if (os_strcmp(ifname, wpa_s->ifname) == 0) | |
7729 | break; | |
7730 | } | |
7731 | ||
7732 | if (wpa_s == NULL) { | |
7733 | char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n"); | |
7734 | if (resp) | |
7735 | *resp_len = os_strlen(resp); | |
7736 | else | |
7737 | *resp_len = 1; | |
7738 | return resp; | |
7739 | } | |
7740 | ||
7741 | return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len); | |
7742 | } | |
7743 | ||
7744 | ||
576bce9c JM |
7745 | static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global, |
7746 | char *buf, size_t *resp_len) | |
7747 | { | |
7748 | #ifdef CONFIG_P2P | |
7749 | static const char * cmd[] = { | |
443427e4 | 7750 | "LIST_NETWORKS", |
576bce9c JM |
7751 | "P2P_FIND", |
7752 | "P2P_STOP_FIND", | |
7753 | "P2P_LISTEN", | |
7754 | "P2P_GROUP_ADD", | |
7755 | "P2P_GET_PASSPHRASE", | |
7756 | "P2P_SERVICE_UPDATE", | |
7757 | "P2P_SERVICE_FLUSH", | |
7758 | "P2P_FLUSH", | |
7759 | "P2P_CANCEL", | |
7760 | "P2P_PRESENCE_REQ", | |
7761 | "P2P_EXT_LISTEN", | |
7762 | NULL | |
7763 | }; | |
7764 | static const char * prefix[] = { | |
443427e4 DS |
7765 | #ifdef ANDROID |
7766 | "DRIVER ", | |
7767 | #endif /* ANDROID */ | |
7768 | "GET_NETWORK ", | |
7769 | "REMOVE_NETWORK ", | |
576bce9c JM |
7770 | "P2P_FIND ", |
7771 | "P2P_CONNECT ", | |
7772 | "P2P_LISTEN ", | |
7773 | "P2P_GROUP_REMOVE ", | |
7774 | "P2P_GROUP_ADD ", | |
7775 | "P2P_PROV_DISC ", | |
7776 | "P2P_SERV_DISC_REQ ", | |
7777 | "P2P_SERV_DISC_CANCEL_REQ ", | |
7778 | "P2P_SERV_DISC_RESP ", | |
7779 | "P2P_SERV_DISC_EXTERNAL ", | |
7780 | "P2P_SERVICE_ADD ", | |
7781 | "P2P_SERVICE_DEL ", | |
7782 | "P2P_REJECT ", | |
7783 | "P2P_INVITE ", | |
7784 | "P2P_PEER ", | |
7785 | "P2P_SET ", | |
7786 | "P2P_UNAUTHORIZE ", | |
7787 | "P2P_PRESENCE_REQ ", | |
7788 | "P2P_EXT_LISTEN ", | |
f2c56602 | 7789 | "P2P_REMOVE_CLIENT ", |
f3ff9487 AM |
7790 | "NFC_GET_HANDOVER_SEL ", |
7791 | "NFC_GET_HANDOVER_REQ ", | |
7792 | "NFC_REPORT_HANDOVER ", | |
576bce9c JM |
7793 | NULL |
7794 | }; | |
7795 | int found = 0; | |
7796 | int i; | |
7797 | ||
7798 | if (global->p2p_init_wpa_s == NULL) | |
7799 | return NULL; | |
7800 | ||
7801 | for (i = 0; !found && cmd[i]; i++) { | |
7802 | if (os_strcmp(buf, cmd[i]) == 0) | |
7803 | found = 1; | |
7804 | } | |
7805 | ||
7806 | for (i = 0; !found && prefix[i]; i++) { | |
7807 | if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0) | |
7808 | found = 1; | |
7809 | } | |
7810 | ||
7811 | if (found) | |
7812 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, | |
7813 | buf, resp_len); | |
7814 | #endif /* CONFIG_P2P */ | |
7815 | return NULL; | |
7816 | } | |
7817 | ||
7818 | ||
7819 | static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global, | |
7820 | char *buf, size_t *resp_len) | |
7821 | { | |
7822 | #ifdef CONFIG_WIFI_DISPLAY | |
7823 | if (global->p2p_init_wpa_s == NULL) | |
7824 | return NULL; | |
7825 | if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 || | |
7826 | os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) | |
7827 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, | |
7828 | buf, resp_len); | |
7829 | #endif /* CONFIG_WIFI_DISPLAY */ | |
7830 | return NULL; | |
7831 | } | |
7832 | ||
7833 | ||
7834 | static char * wpas_global_ctrl_iface_redir(struct wpa_global *global, | |
7835 | char *buf, size_t *resp_len) | |
7836 | { | |
7837 | char *ret; | |
7838 | ||
7839 | ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len); | |
7840 | if (ret) | |
7841 | return ret; | |
7842 | ||
7843 | ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len); | |
7844 | if (ret) | |
7845 | return ret; | |
7846 | ||
7847 | return NULL; | |
7848 | } | |
7849 | ||
7850 | ||
1b9b31c1 JM |
7851 | static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd) |
7852 | { | |
7853 | char *value; | |
7854 | ||
7855 | value = os_strchr(cmd, ' '); | |
7856 | if (value == NULL) | |
7857 | return -1; | |
7858 | *value++ = '\0'; | |
7859 | ||
7860 | wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value); | |
7861 | ||
7862 | #ifdef CONFIG_WIFI_DISPLAY | |
7863 | if (os_strcasecmp(cmd, "wifi_display") == 0) { | |
7864 | wifi_display_enable(global, !!atoi(value)); | |
7865 | return 0; | |
7866 | } | |
7867 | #endif /* CONFIG_WIFI_DISPLAY */ | |
7868 | ||
a7ca6dac JM |
7869 | /* Restore cmd to its original value to allow redirection */ |
7870 | value[-1] = ' '; | |
7871 | ||
1b9b31c1 JM |
7872 | return -1; |
7873 | } | |
7874 | ||
7875 | ||
42868f14 JM |
7876 | #ifndef CONFIG_NO_CONFIG_WRITE |
7877 | static int wpas_global_ctrl_iface_save_config(struct wpa_global *global) | |
7878 | { | |
d6b818ef | 7879 | int ret = 0, saved = 0; |
42868f14 JM |
7880 | struct wpa_supplicant *wpa_s; |
7881 | ||
7882 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
7883 | if (!wpa_s->conf->update_config) { | |
7884 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)"); | |
7885 | continue; | |
7886 | } | |
7887 | ||
7888 | if (wpa_config_write(wpa_s->confname, wpa_s->conf)) { | |
7889 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration"); | |
7890 | ret = 1; | |
7891 | } else { | |
7892 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated"); | |
d6b818ef | 7893 | saved++; |
42868f14 JM |
7894 | } |
7895 | } | |
7896 | ||
d6b818ef JM |
7897 | if (!saved && !ret) { |
7898 | wpa_dbg(wpa_s, MSG_DEBUG, | |
7899 | "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated"); | |
7900 | ret = 1; | |
7901 | } | |
7902 | ||
42868f14 JM |
7903 | return ret; |
7904 | } | |
7905 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
7906 | ||
7907 | ||
ae8c27f7 JM |
7908 | static int wpas_global_ctrl_iface_status(struct wpa_global *global, |
7909 | char *buf, size_t buflen) | |
7910 | { | |
7911 | char *pos, *end; | |
7912 | int ret; | |
7913 | struct wpa_supplicant *wpa_s; | |
7914 | ||
7915 | pos = buf; | |
7916 | end = buf + buflen; | |
7917 | ||
7918 | #ifdef CONFIG_P2P | |
4c559019 | 7919 | if (global->p2p && !global->p2p_disabled) { |
ae8c27f7 | 7920 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR |
4c559019 JM |
7921 | "\n" |
7922 | "p2p_state=%s\n", | |
7923 | MAC2STR(global->p2p_dev_addr), | |
7924 | p2p_get_state_txt(global->p2p)); | |
7925 | if (ret < 0 || ret >= end - pos) | |
7926 | return pos - buf; | |
7927 | pos += ret; | |
7928 | } else if (global->p2p) { | |
7929 | ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n"); | |
ae8c27f7 JM |
7930 | if (ret < 0 || ret >= end - pos) |
7931 | return pos - buf; | |
7932 | pos += ret; | |
7933 | } | |
7934 | #endif /* CONFIG_P2P */ | |
7935 | ||
7936 | #ifdef CONFIG_WIFI_DISPLAY | |
7937 | ret = os_snprintf(pos, end - pos, "wifi_display=%d\n", | |
7938 | !!global->wifi_display); | |
7939 | if (ret < 0 || ret >= end - pos) | |
7940 | return pos - buf; | |
7941 | pos += ret; | |
7942 | #endif /* CONFIG_WIFI_DISPLAY */ | |
7943 | ||
7944 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
7945 | ret = os_snprintf(pos, end - pos, "ifname=%s\n" | |
7946 | "address=" MACSTR "\n", | |
7947 | wpa_s->ifname, MAC2STR(wpa_s->own_addr)); | |
7948 | if (ret < 0 || ret >= end - pos) | |
7949 | return pos - buf; | |
7950 | pos += ret; | |
7951 | } | |
7952 | ||
7953 | return pos - buf; | |
7954 | } | |
7955 | ||
7956 | ||
6fc6879b JM |
7957 | char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, |
7958 | char *buf, size_t *resp_len) | |
7959 | { | |
7960 | char *reply; | |
7961 | const int reply_size = 2048; | |
7962 | int reply_len; | |
f4a0a82c | 7963 | int level = MSG_DEBUG; |
6fc6879b | 7964 | |
cf3bebf2 JM |
7965 | if (os_strncmp(buf, "IFNAME=", 7) == 0) { |
7966 | char *pos = os_strchr(buf + 7, ' '); | |
7967 | if (pos) { | |
7968 | *pos++ = '\0'; | |
7969 | return wpas_global_ctrl_iface_ifname(global, | |
7970 | buf + 7, pos, | |
7971 | resp_len); | |
7972 | } | |
7973 | } | |
7974 | ||
576bce9c JM |
7975 | reply = wpas_global_ctrl_iface_redir(global, buf, resp_len); |
7976 | if (reply) | |
7977 | return reply; | |
7978 | ||
f4a0a82c JM |
7979 | if (os_strcmp(buf, "PING") == 0) |
7980 | level = MSG_EXCESSIVE; | |
7981 | wpa_hexdump_ascii(level, "RX global ctrl_iface", | |
6fc6879b JM |
7982 | (const u8 *) buf, os_strlen(buf)); |
7983 | ||
7984 | reply = os_malloc(reply_size); | |
7985 | if (reply == NULL) { | |
7986 | *resp_len = 1; | |
7987 | return NULL; | |
7988 | } | |
7989 | ||
7990 | os_memcpy(reply, "OK\n", 3); | |
7991 | reply_len = 3; | |
7992 | ||
7993 | if (os_strcmp(buf, "PING") == 0) { | |
7994 | os_memcpy(reply, "PONG\n", 5); | |
7995 | reply_len = 5; | |
7996 | } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) { | |
7997 | if (wpa_supplicant_global_iface_add(global, buf + 14)) | |
7998 | reply_len = -1; | |
7999 | } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) { | |
8000 | if (wpa_supplicant_global_iface_remove(global, buf + 17)) | |
8001 | reply_len = -1; | |
4b4a8ae5 JM |
8002 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
8003 | reply_len = wpa_supplicant_global_iface_list( | |
8004 | global, reply, reply_size); | |
6fc6879b JM |
8005 | } else if (os_strcmp(buf, "INTERFACES") == 0) { |
8006 | reply_len = wpa_supplicant_global_iface_interfaces( | |
8007 | global, reply, reply_size); | |
8008 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | |
1a1bf008 | 8009 | wpa_supplicant_terminate_proc(global); |
207ef3fb JM |
8010 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
8011 | wpas_notify_suspend(global); | |
8012 | } else if (os_strcmp(buf, "RESUME") == 0) { | |
8013 | wpas_notify_resume(global); | |
1b9b31c1 | 8014 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
a7ca6dac JM |
8015 | if (wpas_global_ctrl_iface_set(global, buf + 4)) { |
8016 | #ifdef CONFIG_P2P | |
8017 | if (global->p2p_init_wpa_s) { | |
8018 | os_free(reply); | |
8019 | /* Check if P2P redirection would work for this | |
8020 | * command. */ | |
8021 | return wpa_supplicant_ctrl_iface_process( | |
8022 | global->p2p_init_wpa_s, | |
8023 | buf, resp_len); | |
8024 | } | |
8025 | #endif /* CONFIG_P2P */ | |
1b9b31c1 | 8026 | reply_len = -1; |
a7ca6dac | 8027 | } |
42868f14 JM |
8028 | #ifndef CONFIG_NO_CONFIG_WRITE |
8029 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | |
8030 | if (wpas_global_ctrl_iface_save_config(global)) | |
8031 | reply_len = -1; | |
8032 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
ae8c27f7 JM |
8033 | } else if (os_strcmp(buf, "STATUS") == 0) { |
8034 | reply_len = wpas_global_ctrl_iface_status(global, reply, | |
8035 | reply_size); | |
ea449b5b JM |
8036 | #ifdef CONFIG_MODULE_TESTS |
8037 | } else if (os_strcmp(buf, "MODULE_TESTS") == 0) { | |
8038 | int wpas_module_tests(void); | |
8039 | if (wpas_module_tests() < 0) | |
8040 | reply_len = -1; | |
8041 | #endif /* CONFIG_MODULE_TESTS */ | |
5f797376 JM |
8042 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
8043 | if (wpa_debug_reopen_file() < 0) | |
8044 | reply_len = -1; | |
6fc6879b JM |
8045 | } else { |
8046 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | |
8047 | reply_len = 16; | |
8048 | } | |
8049 | ||
8050 | if (reply_len < 0) { | |
8051 | os_memcpy(reply, "FAIL\n", 5); | |
8052 | reply_len = 5; | |
8053 | } | |
8054 | ||
8055 | *resp_len = reply_len; | |
8056 | return reply; | |
8057 | } |