]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant / Control interface (shared code for all backends) | |
ed87f6a8 | 3 | * Copyright (c) 2004-2019, 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 | 10 | #ifdef CONFIG_TESTING_OPTIONS |
4a6cc862 JM |
11 | #include <netinet/ip.h> |
12 | #endif /* CONFIG_TESTING_OPTIONS */ | |
6fc6879b | 13 | |
3a068632 JM |
14 | #include "utils/common.h" |
15 | #include "utils/eloop.h" | |
8aaafcee | 16 | #include "utils/uuid.h" |
50a17a76 | 17 | #include "utils/module_tests.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" |
4b07484c | 22 | #ifdef CONFIG_DPP |
60239f60 | 23 | #include "common/dpp.h" |
4b07484c | 24 | #endif /* CONFIG_DPP */ |
a1651451 | 25 | #include "crypto/tls.h" |
9d4ff04a | 26 | #include "ap/hostapd.h" |
3a068632 JM |
27 | #include "eap_peer/eap.h" |
28 | #include "eapol_supp/eapol_supp_sm.h" | |
3acb5005 | 29 | #include "rsn_supp/wpa.h" |
3a068632 JM |
30 | #include "rsn_supp/preauth.h" |
31 | #include "rsn_supp/pmksa_cache.h" | |
32 | #include "l2_packet/l2_packet.h" | |
33 | #include "wps/wps.h" | |
df4cea89 | 34 | #include "fst/fst.h" |
3794af2d | 35 | #include "fst/fst_ctrl_iface.h" |
6fc6879b | 36 | #include "config.h" |
6fc6879b | 37 | #include "wpa_supplicant_i.h" |
2d5b792d | 38 | #include "driver_i.h" |
fcc60db4 | 39 | #include "wps_supplicant.h" |
11ef8d35 | 40 | #include "ibss_rsn.h" |
3ec97afe | 41 | #include "ap.h" |
b563b388 JM |
42 | #include "p2p_supplicant.h" |
43 | #include "p2p/p2p.h" | |
a8918e86 | 44 | #include "hs20_supplicant.h" |
9675ce35 | 45 | #include "wifi_display.h" |
8bac466b | 46 | #include "notify.h" |
3a068632 | 47 | #include "bss.h" |
9ba9fa07 | 48 | #include "scan.h" |
3a068632 | 49 | #include "ctrl_iface.h" |
afc064fe | 50 | #include "interworking.h" |
9aa10e2b | 51 | #include "blacklist.h" |
bc5d330a | 52 | #include "autoscan.h" |
e9199e31 | 53 | #include "wnm_sta.h" |
60b893df | 54 | #include "offchannel.h" |
7a4a93b9 | 55 | #include "drivers/driver.h" |
79070906 | 56 | #include "mesh.h" |
be27e185 | 57 | #include "dpp_supplicant.h" |
5c7d35ba | 58 | #include "sme.h" |
6fc6879b | 59 | |
7846e8d6 RM |
60 | #ifdef __NetBSD__ |
61 | #include <net/if_ether.h> | |
62 | #elif !defined(__CYGWIN__) && !defined(CONFIG_NATIVE_WINDOWS) | |
63 | #include <net/ethernet.h> | |
64 | #endif | |
65 | ||
4b4a8ae5 JM |
66 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
67 | char *buf, int len); | |
6fc6879b | 68 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
56e2fc2c | 69 | const char *input, |
6fc6879b | 70 | char *buf, int len); |
d3c9c35f DS |
71 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, |
72 | char *val); | |
6fc6879b | 73 | |
fe3e0bac | 74 | |
d445a5cd JM |
75 | static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val) |
76 | { | |
77 | char *pos; | |
78 | u8 addr[ETH_ALEN], *filter = NULL, *n; | |
79 | size_t count = 0; | |
80 | ||
81 | pos = val; | |
82 | while (pos) { | |
83 | if (*pos == '\0') | |
84 | break; | |
1485ec07 JM |
85 | if (hwaddr_aton(pos, addr)) { |
86 | os_free(filter); | |
d445a5cd | 87 | return -1; |
1485ec07 | 88 | } |
067ffa26 | 89 | n = os_realloc_array(filter, count + 1, ETH_ALEN); |
d445a5cd JM |
90 | if (n == NULL) { |
91 | os_free(filter); | |
92 | return -1; | |
93 | } | |
94 | filter = n; | |
95 | os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN); | |
96 | count++; | |
97 | ||
98 | pos = os_strchr(pos, ' '); | |
99 | if (pos) | |
100 | pos++; | |
101 | } | |
102 | ||
103 | wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN); | |
104 | os_free(wpa_s->bssid_filter); | |
105 | wpa_s->bssid_filter = filter; | |
106 | wpa_s->bssid_filter_count = count; | |
107 | ||
108 | return 0; | |
109 | } | |
110 | ||
111 | ||
6407f413 JM |
112 | static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val) |
113 | { | |
114 | char *pos; | |
115 | u8 addr[ETH_ALEN], *bssid = NULL, *n; | |
116 | struct wpa_ssid_value *ssid = NULL, *ns; | |
117 | size_t count = 0, ssid_count = 0; | |
118 | struct wpa_ssid *c; | |
119 | ||
120 | /* | |
65015b2d | 121 | * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | "" |
6407f413 JM |
122 | * SSID_SPEC ::= ssid <SSID_HEX> |
123 | * BSSID_SPEC ::= bssid <BSSID_HEX> | |
124 | */ | |
125 | ||
126 | pos = val; | |
127 | while (pos) { | |
128 | if (*pos == '\0') | |
129 | break; | |
130 | if (os_strncmp(pos, "bssid ", 6) == 0) { | |
131 | int res; | |
132 | pos += 6; | |
133 | res = hwaddr_aton2(pos, addr); | |
134 | if (res < 0) { | |
135 | os_free(ssid); | |
136 | os_free(bssid); | |
137 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " | |
138 | "BSSID value '%s'", pos); | |
139 | return -1; | |
140 | } | |
141 | pos += res; | |
142 | n = os_realloc_array(bssid, count + 1, ETH_ALEN); | |
143 | if (n == NULL) { | |
144 | os_free(ssid); | |
145 | os_free(bssid); | |
146 | return -1; | |
147 | } | |
148 | bssid = n; | |
149 | os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN); | |
150 | count++; | |
151 | } else if (os_strncmp(pos, "ssid ", 5) == 0) { | |
152 | char *end; | |
153 | pos += 5; | |
154 | ||
155 | end = pos; | |
156 | while (*end) { | |
157 | if (*end == '\0' || *end == ' ') | |
158 | break; | |
159 | end++; | |
160 | } | |
161 | ||
162 | ns = os_realloc_array(ssid, ssid_count + 1, | |
163 | sizeof(struct wpa_ssid_value)); | |
164 | if (ns == NULL) { | |
165 | os_free(ssid); | |
166 | os_free(bssid); | |
167 | return -1; | |
168 | } | |
169 | ssid = ns; | |
170 | ||
d9d1b952 JM |
171 | if ((end - pos) & 0x01 || |
172 | end - pos > 2 * SSID_MAX_LEN || | |
6407f413 JM |
173 | hexstr2bin(pos, ssid[ssid_count].ssid, |
174 | (end - pos) / 2) < 0) { | |
175 | os_free(ssid); | |
176 | os_free(bssid); | |
177 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " | |
178 | "SSID value '%s'", pos); | |
179 | return -1; | |
180 | } | |
181 | ssid[ssid_count].ssid_len = (end - pos) / 2; | |
182 | wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID", | |
183 | ssid[ssid_count].ssid, | |
184 | ssid[ssid_count].ssid_len); | |
185 | ssid_count++; | |
186 | pos = end; | |
187 | } else { | |
188 | wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value " | |
189 | "'%s'", pos); | |
190 | os_free(ssid); | |
191 | os_free(bssid); | |
192 | return -1; | |
193 | } | |
194 | ||
195 | pos = os_strchr(pos, ' '); | |
196 | if (pos) | |
197 | pos++; | |
198 | } | |
199 | ||
200 | wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN); | |
201 | os_free(wpa_s->disallow_aps_bssid); | |
202 | wpa_s->disallow_aps_bssid = bssid; | |
203 | wpa_s->disallow_aps_bssid_count = count; | |
204 | ||
205 | wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count); | |
206 | os_free(wpa_s->disallow_aps_ssid); | |
207 | wpa_s->disallow_aps_ssid = ssid; | |
208 | wpa_s->disallow_aps_ssid_count = ssid_count; | |
209 | ||
210 | if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING) | |
211 | return 0; | |
212 | ||
213 | c = wpa_s->current_ssid; | |
214 | if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS) | |
215 | return 0; | |
216 | ||
217 | if (!disallowed_bssid(wpa_s, wpa_s->bssid) && | |
218 | !disallowed_ssid(wpa_s, c->ssid, c->ssid_len)) | |
219 | return 0; | |
220 | ||
221 | wpa_printf(MSG_DEBUG, "Disconnect and try to find another network " | |
222 | "because current AP was marked disallowed"); | |
223 | ||
224 | #ifdef CONFIG_SME | |
225 | wpa_s->sme.prev_bssid_set = 0; | |
226 | #endif /* CONFIG_SME */ | |
227 | wpa_s->reassociate = 1; | |
c2805909 | 228 | wpa_s->own_disconnect_req = 1; |
6407f413 JM |
229 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
230 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
231 | ||
232 | return 0; | |
233 | } | |
234 | ||
235 | ||
1120e452 JM |
236 | #ifndef CONFIG_NO_CONFIG_BLOBS |
237 | static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos) | |
238 | { | |
239 | char *name = pos; | |
240 | struct wpa_config_blob *blob; | |
241 | size_t len; | |
242 | ||
243 | pos = os_strchr(pos, ' '); | |
244 | if (pos == NULL) | |
245 | return -1; | |
246 | *pos++ = '\0'; | |
247 | len = os_strlen(pos); | |
248 | if (len & 1) | |
249 | return -1; | |
250 | ||
251 | wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name); | |
252 | blob = os_zalloc(sizeof(*blob)); | |
253 | if (blob == NULL) | |
254 | return -1; | |
255 | blob->name = os_strdup(name); | |
256 | blob->data = os_malloc(len / 2); | |
257 | if (blob->name == NULL || blob->data == NULL) { | |
258 | wpa_config_free_blob(blob); | |
259 | return -1; | |
260 | } | |
261 | ||
262 | if (hexstr2bin(pos, blob->data, len / 2) < 0) { | |
263 | wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data"); | |
264 | wpa_config_free_blob(blob); | |
265 | return -1; | |
266 | } | |
267 | blob->len = len / 2; | |
268 | ||
269 | wpa_config_set_blob(wpa_s->conf, blob); | |
270 | ||
271 | return 0; | |
272 | } | |
273 | #endif /* CONFIG_NO_CONFIG_BLOBS */ | |
274 | ||
d3c9c35f DS |
275 | |
276 | static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd) | |
277 | { | |
278 | char *params; | |
279 | char *pos; | |
280 | int *freqs = NULL; | |
281 | int ret; | |
282 | ||
283 | if (atoi(cmd)) { | |
284 | params = os_strchr(cmd, ' '); | |
285 | os_free(wpa_s->manual_sched_scan_freqs); | |
286 | if (params) { | |
287 | params++; | |
288 | pos = os_strstr(params, "freq="); | |
289 | if (pos) | |
290 | freqs = freq_range_to_channel_list(wpa_s, | |
291 | pos + 5); | |
292 | } | |
293 | wpa_s->manual_sched_scan_freqs = freqs; | |
294 | ret = wpas_start_pno(wpa_s); | |
295 | } else { | |
296 | ret = wpas_stop_pno(wpa_s); | |
297 | } | |
298 | return ret; | |
299 | } | |
300 | ||
301 | ||
844dfeb8 SD |
302 | static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band) |
303 | { | |
304 | union wpa_event_data event; | |
305 | ||
306 | if (os_strcmp(band, "AUTO") == 0) | |
307 | wpa_s->setband = WPA_SETBAND_AUTO; | |
308 | else if (os_strcmp(band, "5G") == 0) | |
309 | wpa_s->setband = WPA_SETBAND_5G; | |
310 | else if (os_strcmp(band, "2G") == 0) | |
311 | wpa_s->setband = WPA_SETBAND_2G; | |
312 | else | |
313 | return -1; | |
314 | ||
315 | if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) { | |
316 | os_memset(&event, 0, sizeof(event)); | |
317 | event.channel_list_changed.initiator = REGDOM_SET_BY_USER; | |
318 | event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN; | |
319 | wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event); | |
320 | } | |
321 | ||
322 | return 0; | |
323 | } | |
324 | ||
325 | ||
4a742011 DS |
326 | static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s, |
327 | const char *cmd) | |
328 | { | |
329 | struct wpabuf *lci; | |
330 | ||
331 | if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) { | |
332 | wpabuf_free(wpa_s->lci); | |
333 | wpa_s->lci = NULL; | |
334 | return 0; | |
335 | } | |
336 | ||
337 | lci = wpabuf_parse_bin(cmd); | |
338 | if (!lci) | |
339 | return -1; | |
340 | ||
341 | if (os_get_reltime(&wpa_s->lci_time)) { | |
342 | wpabuf_free(lci); | |
343 | return -1; | |
344 | } | |
345 | ||
346 | wpabuf_free(wpa_s->lci); | |
347 | wpa_s->lci = lci; | |
348 | ||
349 | return 0; | |
350 | } | |
351 | ||
352 | ||
57c3a605 | 353 | static int |
354 | wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd) | |
355 | { | |
356 | int relative_rssi; | |
357 | ||
358 | if (os_strcmp(cmd, "disable") == 0) { | |
359 | wpa_s->srp.relative_rssi_set = 0; | |
360 | return 0; | |
361 | } | |
362 | ||
363 | relative_rssi = atoi(cmd); | |
364 | if (relative_rssi < 0 || relative_rssi > 100) | |
365 | return -1; | |
366 | wpa_s->srp.relative_rssi = relative_rssi; | |
367 | wpa_s->srp.relative_rssi_set = 1; | |
368 | return 0; | |
369 | } | |
370 | ||
371 | ||
372 | static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s, | |
373 | const char *cmd) | |
374 | { | |
375 | char *pos; | |
376 | int adjust_rssi; | |
377 | ||
378 | /* <band>:adjust_value */ | |
379 | pos = os_strchr(cmd, ':'); | |
380 | if (!pos) | |
381 | return -1; | |
382 | pos++; | |
383 | adjust_rssi = atoi(pos); | |
384 | if (adjust_rssi < -100 || adjust_rssi > 100) | |
385 | return -1; | |
386 | ||
387 | if (os_strncmp(cmd, "2G", 2) == 0) | |
388 | wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G; | |
389 | else if (os_strncmp(cmd, "5G", 2) == 0) | |
390 | wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G; | |
391 | else | |
392 | return -1; | |
393 | ||
394 | wpa_s->srp.relative_adjust_rssi = adjust_rssi; | |
395 | ||
396 | return 0; | |
397 | } | |
398 | ||
399 | ||
c6c41f6e JM |
400 | static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s, |
401 | const char *cmd) | |
402 | { | |
403 | struct wpabuf *ric_ies; | |
404 | ||
405 | if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) { | |
406 | wpabuf_free(wpa_s->ric_ies); | |
407 | wpa_s->ric_ies = NULL; | |
408 | return 0; | |
409 | } | |
410 | ||
411 | ric_ies = wpabuf_parse_bin(cmd); | |
412 | if (!ric_ies) | |
413 | return -1; | |
414 | ||
415 | wpabuf_free(wpa_s->ric_ies); | |
416 | wpa_s->ric_ies = ric_ies; | |
417 | ||
418 | return 0; | |
419 | } | |
420 | ||
421 | ||
6fc6879b JM |
422 | static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, |
423 | char *cmd) | |
424 | { | |
425 | char *value; | |
426 | int ret = 0; | |
427 | ||
428 | value = os_strchr(cmd, ' '); | |
429 | if (value == NULL) | |
430 | return -1; | |
431 | *value++ = '\0'; | |
432 | ||
433 | wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value); | |
434 | if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) { | |
435 | eapol_sm_configure(wpa_s->eapol, | |
436 | atoi(value), -1, -1, -1); | |
437 | } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) { | |
438 | eapol_sm_configure(wpa_s->eapol, | |
439 | -1, atoi(value), -1, -1); | |
440 | } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) { | |
441 | eapol_sm_configure(wpa_s->eapol, | |
442 | -1, -1, atoi(value), -1); | |
443 | } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) { | |
444 | eapol_sm_configure(wpa_s->eapol, | |
445 | -1, -1, -1, atoi(value)); | |
446 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) { | |
447 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, | |
b4bdeadf | 448 | atoi(value))) { |
6fc6879b | 449 | ret = -1; |
b4bdeadf JM |
450 | } else { |
451 | value[-1] = '='; | |
452 | wpa_config_process_global(wpa_s->conf, cmd, -1); | |
453 | } | |
6fc6879b JM |
454 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == |
455 | 0) { | |
456 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, | |
b4bdeadf | 457 | atoi(value))) { |
6fc6879b | 458 | ret = -1; |
b4bdeadf JM |
459 | } else { |
460 | value[-1] = '='; | |
461 | wpa_config_process_global(wpa_s->conf, cmd, -1); | |
462 | } | |
6fc6879b | 463 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) { |
b4bdeadf JM |
464 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, |
465 | atoi(value))) { | |
6fc6879b | 466 | ret = -1; |
b4bdeadf JM |
467 | } else { |
468 | value[-1] = '='; | |
469 | wpa_config_process_global(wpa_s->conf, cmd, -1); | |
470 | } | |
42f50264 JM |
471 | } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) { |
472 | wpa_s->wps_fragment_size = atoi(value); | |
b4e34f2f JM |
473 | #ifdef CONFIG_WPS_TESTING |
474 | } else if (os_strcasecmp(cmd, "wps_version_number") == 0) { | |
475 | long int val; | |
476 | val = strtol(value, NULL, 0); | |
477 | if (val < 0 || val > 0xff) { | |
478 | ret = -1; | |
479 | wpa_printf(MSG_DEBUG, "WPS: Invalid " | |
480 | "wps_version_number %ld", val); | |
481 | } else { | |
482 | wps_version_number = val; | |
483 | wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS " | |
484 | "version %u.%u", | |
485 | (wps_version_number & 0xf0) >> 4, | |
486 | wps_version_number & 0x0f); | |
487 | } | |
488 | } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) { | |
489 | wps_testing_dummy_cred = atoi(value); | |
490 | wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d", | |
491 | wps_testing_dummy_cred); | |
91226e0d JM |
492 | } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) { |
493 | wps_corrupt_pkhash = atoi(value); | |
494 | wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d", | |
495 | wps_corrupt_pkhash); | |
6e379c6c JM |
496 | } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) { |
497 | if (value[0] == '\0') { | |
498 | wps_force_auth_types_in_use = 0; | |
499 | } else { | |
500 | wps_force_auth_types = strtol(value, NULL, 0); | |
501 | wps_force_auth_types_in_use = 1; | |
502 | } | |
503 | } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) { | |
504 | if (value[0] == '\0') { | |
505 | wps_force_encr_types_in_use = 0; | |
506 | } else { | |
507 | wps_force_encr_types = strtol(value, NULL, 0); | |
508 | wps_force_encr_types_in_use = 1; | |
509 | } | |
b4e34f2f | 510 | #endif /* CONFIG_WPS_TESTING */ |
b6c79a99 JM |
511 | } else if (os_strcasecmp(cmd, "ampdu") == 0) { |
512 | if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0) | |
513 | ret = -1; | |
9d2cb3ec | 514 | #ifdef CONFIG_TDLS |
5b0e6ece JM |
515 | #ifdef CONFIG_TDLS_TESTING |
516 | } else if (os_strcasecmp(cmd, "tdls_testing") == 0) { | |
5b0e6ece JM |
517 | tdls_testing = strtol(value, NULL, 0); |
518 | wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing); | |
519 | #endif /* CONFIG_TDLS_TESTING */ | |
b8f64582 JM |
520 | } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) { |
521 | int disabled = atoi(value); | |
522 | wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled); | |
523 | if (disabled) { | |
524 | if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0) | |
525 | ret = -1; | |
526 | } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0) | |
527 | ret = -1; | |
528 | wpa_tdls_enable(wpa_s->wpa, !disabled); | |
529 | #endif /* CONFIG_TDLS */ | |
b5c68312 | 530 | } else if (os_strcasecmp(cmd, "pno") == 0) { |
d3c9c35f | 531 | ret = wpas_ctrl_pno(wpa_s, value); |
8b9d0bfa JM |
532 | } else if (os_strcasecmp(cmd, "radio_disabled") == 0) { |
533 | int disabled = atoi(value); | |
534 | if (wpa_drv_radio_disable(wpa_s, disabled) < 0) | |
535 | ret = -1; | |
536 | else if (disabled) | |
537 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | |
aa074a64 JM |
538 | } else if (os_strcasecmp(cmd, "uapsd") == 0) { |
539 | if (os_strcmp(value, "disable") == 0) | |
540 | wpa_s->set_sta_uapsd = 0; | |
541 | else { | |
542 | int be, bk, vi, vo; | |
543 | char *pos; | |
544 | /* format: BE,BK,VI,VO;max SP Length */ | |
545 | be = atoi(value); | |
546 | pos = os_strchr(value, ','); | |
547 | if (pos == NULL) | |
548 | return -1; | |
549 | pos++; | |
550 | bk = atoi(pos); | |
551 | pos = os_strchr(pos, ','); | |
552 | if (pos == NULL) | |
553 | return -1; | |
554 | pos++; | |
555 | vi = atoi(pos); | |
556 | pos = os_strchr(pos, ','); | |
557 | if (pos == NULL) | |
558 | return -1; | |
559 | pos++; | |
560 | vo = atoi(pos); | |
561 | /* ignore max SP Length for now */ | |
562 | ||
563 | wpa_s->set_sta_uapsd = 1; | |
564 | wpa_s->sta_uapsd = 0; | |
565 | if (be) | |
566 | wpa_s->sta_uapsd |= BIT(0); | |
567 | if (bk) | |
568 | wpa_s->sta_uapsd |= BIT(1); | |
569 | if (vi) | |
570 | wpa_s->sta_uapsd |= BIT(2); | |
571 | if (vo) | |
572 | wpa_s->sta_uapsd |= BIT(3); | |
573 | } | |
b2ff1681 JM |
574 | } else if (os_strcasecmp(cmd, "ps") == 0) { |
575 | ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1); | |
9675ce35 JM |
576 | #ifdef CONFIG_WIFI_DISPLAY |
577 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { | |
bab6677a JM |
578 | int enabled = !!atoi(value); |
579 | if (enabled && !wpa_s->global->p2p) | |
580 | ret = -1; | |
581 | else | |
582 | wifi_display_enable(wpa_s->global, enabled); | |
9675ce35 | 583 | #endif /* CONFIG_WIFI_DISPLAY */ |
d445a5cd JM |
584 | } else if (os_strcasecmp(cmd, "bssid_filter") == 0) { |
585 | ret = set_bssid_filter(wpa_s, value); | |
6407f413 JM |
586 | } else if (os_strcasecmp(cmd, "disallow_aps") == 0) { |
587 | ret = set_disallow_aps(wpa_s, value); | |
2ec535fd JM |
588 | } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) { |
589 | wpa_s->no_keep_alive = !!atoi(value); | |
b65b22d6 JM |
590 | #ifdef CONFIG_DPP |
591 | } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) { | |
592 | os_free(wpa_s->dpp_configurator_params); | |
593 | wpa_s->dpp_configurator_params = os_strdup(value); | |
f97ace34 JM |
594 | } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) { |
595 | wpa_s->dpp_init_max_tries = atoi(value); | |
596 | } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) { | |
597 | wpa_s->dpp_init_retry_time = atoi(value); | |
598 | } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) { | |
599 | wpa_s->dpp_resp_wait_time = atoi(value); | |
95b0104a JM |
600 | } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) { |
601 | wpa_s->dpp_resp_max_tries = atoi(value); | |
602 | } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) { | |
603 | wpa_s->dpp_resp_retry_time = atoi(value); | |
dc2f24f1 | 604 | #ifdef CONFIG_TESTING_OPTIONS |
2bdc47a9 JM |
605 | } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) { |
606 | if (hwaddr_aton(value, dpp_pkex_own_mac_override)) | |
607 | ret = -1; | |
608 | } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) { | |
609 | if (hwaddr_aton(value, dpp_pkex_peer_mac_override)) | |
610 | ret = -1; | |
acc555f9 JM |
611 | } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) { |
612 | size_t hex_len = os_strlen(value); | |
613 | ||
614 | if (hex_len > | |
615 | 2 * sizeof(dpp_pkex_ephemeral_key_override)) | |
616 | ret = -1; | |
617 | else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override, | |
618 | hex_len / 2)) | |
619 | ret = -1; | |
620 | else | |
621 | dpp_pkex_ephemeral_key_override_len = hex_len / 2; | |
f5526975 JM |
622 | } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) { |
623 | size_t hex_len = os_strlen(value); | |
624 | ||
625 | if (hex_len > 2 * sizeof(dpp_protocol_key_override)) | |
626 | ret = -1; | |
627 | else if (hexstr2bin(value, dpp_protocol_key_override, | |
628 | hex_len / 2)) | |
629 | ret = -1; | |
630 | else | |
631 | dpp_protocol_key_override_len = hex_len / 2; | |
055cd397 JM |
632 | } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) { |
633 | size_t hex_len = os_strlen(value); | |
634 | ||
635 | if (hex_len > 2 * sizeof(dpp_nonce_override)) | |
636 | ret = -1; | |
637 | else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2)) | |
638 | ret = -1; | |
639 | else | |
640 | dpp_nonce_override_len = hex_len / 2; | |
dc2f24f1 | 641 | #endif /* CONFIG_TESTING_OPTIONS */ |
b65b22d6 | 642 | #endif /* CONFIG_DPP */ |
60b893df JM |
643 | #ifdef CONFIG_TESTING_OPTIONS |
644 | } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) { | |
645 | wpa_s->ext_mgmt_frame_handling = !!atoi(value); | |
9d4ff04a JM |
646 | } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) { |
647 | wpa_s->ext_eapol_frame_io = !!atoi(value); | |
648 | #ifdef CONFIG_AP | |
649 | if (wpa_s->ap_iface) { | |
650 | wpa_s->ap_iface->bss[0]->ext_eapol_frame_io = | |
651 | wpa_s->ext_eapol_frame_io; | |
652 | } | |
653 | #endif /* CONFIG_AP */ | |
1f94e4ee JM |
654 | } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) { |
655 | wpa_s->extra_roc_dur = atoi(value); | |
911942ee JM |
656 | } else if (os_strcasecmp(cmd, "test_failure") == 0) { |
657 | wpa_s->test_failure = atoi(value); | |
ed7820b4 IP |
658 | } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) { |
659 | wpa_s->p2p_go_csa_on_inv = !!atoi(value); | |
02adead5 MK |
660 | } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) { |
661 | wpa_s->ignore_auth_resp = !!atoi(value); | |
6ad37d73 | 662 | } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) { |
663 | wpa_s->ignore_assoc_disallow = !!atoi(value); | |
178553b7 VK |
664 | wpa_drv_ignore_assoc_disallow(wpa_s, |
665 | wpa_s->ignore_assoc_disallow); | |
a483c6f1 | 666 | } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) { |
667 | wpa_s->reject_btm_req_reason = atoi(value); | |
c06fca04 JM |
668 | } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) { |
669 | os_free(wpa_s->get_pref_freq_list_override); | |
670 | if (!value[0]) | |
671 | wpa_s->get_pref_freq_list_override = NULL; | |
672 | else | |
673 | wpa_s->get_pref_freq_list_override = os_strdup(value); | |
a0f19e9c JM |
674 | } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) { |
675 | wpabuf_free(wpa_s->sae_commit_override); | |
676 | if (value[0] == '\0') | |
677 | wpa_s->sae_commit_override = NULL; | |
678 | else | |
679 | wpa_s->sae_commit_override = wpabuf_parse_bin(value); | |
461d39af JM |
680 | #ifdef CONFIG_DPP |
681 | } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) { | |
682 | os_free(wpa_s->dpp_config_obj_override); | |
b7dddab7 JM |
683 | if (value[0] == '\0') |
684 | wpa_s->dpp_config_obj_override = NULL; | |
685 | else | |
686 | wpa_s->dpp_config_obj_override = os_strdup(value); | |
461d39af JM |
687 | } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) { |
688 | os_free(wpa_s->dpp_discovery_override); | |
b7dddab7 JM |
689 | if (value[0] == '\0') |
690 | wpa_s->dpp_discovery_override = NULL; | |
691 | else | |
692 | wpa_s->dpp_discovery_override = os_strdup(value); | |
461d39af JM |
693 | } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) { |
694 | os_free(wpa_s->dpp_groups_override); | |
b7dddab7 JM |
695 | if (value[0] == '\0') |
696 | wpa_s->dpp_groups_override = NULL; | |
697 | else | |
698 | wpa_s->dpp_groups_override = os_strdup(value); | |
461d39af JM |
699 | } else if (os_strcasecmp(cmd, |
700 | "dpp_ignore_netaccesskey_mismatch") == 0) { | |
701 | wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value); | |
60239f60 JM |
702 | } else if (os_strcasecmp(cmd, "dpp_test") == 0) { |
703 | dpp_test = atoi(value); | |
461d39af | 704 | #endif /* CONFIG_DPP */ |
60b893df | 705 | #endif /* CONFIG_TESTING_OPTIONS */ |
d98038bb | 706 | #ifdef CONFIG_FILS |
707 | } else if (os_strcasecmp(cmd, "disable_fils") == 0) { | |
708 | wpa_s->disable_fils = !!atoi(value); | |
709 | wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils); | |
710 | wpa_supplicant_set_default_scan_ies(wpa_s); | |
711 | #endif /* CONFIG_FILS */ | |
1120e452 JM |
712 | #ifndef CONFIG_NO_CONFIG_BLOBS |
713 | } else if (os_strcmp(cmd, "blob") == 0) { | |
714 | ret = wpas_ctrl_set_blob(wpa_s, value); | |
715 | #endif /* CONFIG_NO_CONFIG_BLOBS */ | |
209702d4 | 716 | } else if (os_strcasecmp(cmd, "setband") == 0) { |
844dfeb8 | 717 | ret = wpas_ctrl_set_band(wpa_s, value); |
92c6e2e3 DS |
718 | #ifdef CONFIG_MBO |
719 | } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) { | |
720 | ret = wpas_mbo_update_non_pref_chan(wpa_s, value); | |
e3394c0e JM |
721 | if (ret == 0) { |
722 | value[-1] = '='; | |
723 | wpa_config_process_global(wpa_s->conf, cmd, -1); | |
724 | } | |
016082e9 AS |
725 | } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) { |
726 | wpas_mbo_update_cell_capa(wpa_s, atoi(value)); | |
332aadb8 AP |
727 | } else if (os_strcasecmp(cmd, "oce") == 0) { |
728 | wpa_s->conf->oce = atoi(value); | |
729 | if (wpa_s->conf->oce) { | |
730 | if ((wpa_s->conf->oce & OCE_STA) && | |
731 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA)) | |
732 | wpa_s->enable_oce = OCE_STA; | |
733 | ||
734 | if ((wpa_s->conf->oce & OCE_STA_CFON) && | |
735 | (wpa_s->drv_flags & | |
736 | WPA_DRIVER_FLAGS_OCE_STA_CFON)) { | |
737 | /* TODO: Need to add STA-CFON support */ | |
738 | wpa_printf(MSG_ERROR, | |
739 | "OCE STA-CFON feature is not yet supported"); | |
740 | return -1; | |
741 | } | |
742 | } else { | |
743 | wpa_s->enable_oce = 0; | |
744 | } | |
e37cea30 | 745 | wpa_supplicant_set_default_scan_ies(wpa_s); |
92c6e2e3 | 746 | #endif /* CONFIG_MBO */ |
4a742011 DS |
747 | } else if (os_strcasecmp(cmd, "lci") == 0) { |
748 | ret = wpas_ctrl_iface_set_lci(wpa_s, value); | |
2e4e4fb7 SD |
749 | } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) { |
750 | ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value)); | |
57c3a605 | 751 | } else if (os_strcasecmp(cmd, "relative_rssi") == 0) { |
752 | ret = wpas_ctrl_set_relative_rssi(wpa_s, value); | |
753 | } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) { | |
754 | ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value); | |
c6c41f6e JM |
755 | } else if (os_strcasecmp(cmd, "ric_ies") == 0) { |
756 | ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value); | |
9a72bfe9 AP |
757 | } else if (os_strcasecmp(cmd, "roaming") == 0) { |
758 | ret = wpa_drv_roaming(wpa_s, atoi(value), NULL); | |
d514b502 JM |
759 | #ifdef CONFIG_WNM |
760 | } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) { | |
761 | struct wpabuf *elems; | |
762 | ||
763 | elems = wpabuf_parse_bin(value); | |
764 | if (!elems) | |
765 | return -1; | |
766 | wnm_set_coloc_intf_elems(wpa_s, elems); | |
767 | #endif /* CONFIG_WNM */ | |
611aea7d JM |
768 | } else { |
769 | value[-1] = '='; | |
770 | ret = wpa_config_process_global(wpa_s->conf, cmd, -1); | |
771 | if (ret == 0) | |
772 | wpa_supplicant_update_config(wpa_s); | |
773 | } | |
6fc6879b JM |
774 | |
775 | return ret; | |
776 | } | |
777 | ||
778 | ||
acec8d32 JM |
779 | static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s, |
780 | char *cmd, char *buf, size_t buflen) | |
781 | { | |
6ce937b8 | 782 | int res = -1; |
acec8d32 JM |
783 | |
784 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd); | |
785 | ||
786 | if (os_strcmp(cmd, "version") == 0) { | |
787 | res = os_snprintf(buf, buflen, "%s", VERSION_STR); | |
6ce937b8 DS |
788 | } else if (os_strcasecmp(cmd, "country") == 0) { |
789 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) | |
790 | res = os_snprintf(buf, buflen, "%c%c", | |
791 | wpa_s->conf->country[0], | |
792 | wpa_s->conf->country[1]); | |
9675ce35 JM |
793 | #ifdef CONFIG_WIFI_DISPLAY |
794 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { | |
bab6677a JM |
795 | int enabled; |
796 | if (wpa_s->global->p2p == NULL || | |
797 | wpa_s->global->p2p_disabled) | |
798 | enabled = 0; | |
799 | else | |
800 | enabled = wpa_s->global->wifi_display; | |
801 | res = os_snprintf(buf, buflen, "%d", enabled); | |
9675ce35 | 802 | #endif /* CONFIG_WIFI_DISPLAY */ |
fa7ae950 JM |
803 | #ifdef CONFIG_TESTING_GET_GTK |
804 | } else if (os_strcmp(cmd, "gtk") == 0) { | |
805 | if (wpa_s->last_gtk_len == 0) | |
806 | return -1; | |
807 | res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk, | |
808 | wpa_s->last_gtk_len); | |
809 | return res; | |
810 | #endif /* CONFIG_TESTING_GET_GTK */ | |
a1651451 JM |
811 | } else if (os_strcmp(cmd, "tls_library") == 0) { |
812 | res = tls_get_library_version(buf, buflen); | |
bb06748f JM |
813 | #ifdef CONFIG_TESTING_OPTIONS |
814 | } else if (os_strcmp(cmd, "anonce") == 0) { | |
815 | return wpa_snprintf_hex(buf, buflen, | |
816 | wpa_sm_get_anonce(wpa_s->wpa), | |
817 | WPA_NONCE_LEN); | |
818 | #endif /* CONFIG_TESTING_OPTIONS */ | |
10263dc2 OO |
819 | } else { |
820 | res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen); | |
acec8d32 JM |
821 | } |
822 | ||
1f102d3b | 823 | if (os_snprintf_error(buflen, res)) |
6ce937b8 DS |
824 | return -1; |
825 | return res; | |
acec8d32 JM |
826 | } |
827 | ||
828 | ||
ec717917 | 829 | #ifdef IEEE8021X_EAPOL |
6fc6879b JM |
830 | static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s, |
831 | char *addr) | |
832 | { | |
833 | u8 bssid[ETH_ALEN]; | |
834 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
835 | ||
836 | if (hwaddr_aton(addr, bssid)) { | |
837 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address " | |
838 | "'%s'", addr); | |
839 | return -1; | |
840 | } | |
841 | ||
842 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid)); | |
843 | rsn_preauth_deinit(wpa_s->wpa); | |
844 | if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL)) | |
845 | return -1; | |
846 | ||
847 | return 0; | |
848 | } | |
ec717917 | 849 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
850 | |
851 | ||
281ff0aa GP |
852 | #ifdef CONFIG_TDLS |
853 | ||
854 | static int wpa_supplicant_ctrl_iface_tdls_discover( | |
855 | struct wpa_supplicant *wpa_s, char *addr) | |
856 | { | |
857 | u8 peer[ETH_ALEN]; | |
2d565a61 | 858 | int ret; |
281ff0aa GP |
859 | |
860 | if (hwaddr_aton(addr, peer)) { | |
861 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid " | |
862 | "address '%s'", addr); | |
863 | return -1; | |
864 | } | |
865 | ||
866 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR, | |
867 | MAC2STR(peer)); | |
868 | ||
2d565a61 AN |
869 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
870 | ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer); | |
871 | else | |
872 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); | |
873 | ||
874 | return ret; | |
281ff0aa GP |
875 | } |
876 | ||
877 | ||
878 | static int wpa_supplicant_ctrl_iface_tdls_setup( | |
879 | struct wpa_supplicant *wpa_s, char *addr) | |
880 | { | |
881 | u8 peer[ETH_ALEN]; | |
94377fbc | 882 | int ret; |
281ff0aa GP |
883 | |
884 | if (hwaddr_aton(addr, peer)) { | |
885 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid " | |
886 | "address '%s'", addr); | |
887 | return -1; | |
888 | } | |
889 | ||
890 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR, | |
891 | MAC2STR(peer)); | |
892 | ||
800d5872 SD |
893 | if ((wpa_s->conf->tdls_external_control) && |
894 | wpa_tdls_is_external_setup(wpa_s->wpa)) | |
895 | return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | |
896 | ||
3887878e SD |
897 | wpa_tdls_remove(wpa_s->wpa, peer); |
898 | ||
899 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | |
900 | ret = wpa_tdls_start(wpa_s->wpa, peer); | |
901 | else | |
902 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | |
2d565a61 | 903 | |
94377fbc | 904 | return ret; |
281ff0aa GP |
905 | } |
906 | ||
907 | ||
908 | static int wpa_supplicant_ctrl_iface_tdls_teardown( | |
909 | struct wpa_supplicant *wpa_s, char *addr) | |
910 | { | |
911 | u8 peer[ETH_ALEN]; | |
4ed8d954 | 912 | int ret; |
281ff0aa | 913 | |
38ddccae AN |
914 | if (os_strcmp(addr, "*") == 0) { |
915 | /* remove everyone */ | |
916 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *"); | |
917 | wpa_tdls_teardown_peers(wpa_s->wpa); | |
918 | return 0; | |
919 | } | |
920 | ||
281ff0aa GP |
921 | if (hwaddr_aton(addr, peer)) { |
922 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid " | |
923 | "address '%s'", addr); | |
924 | return -1; | |
925 | } | |
926 | ||
927 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR, | |
928 | MAC2STR(peer)); | |
929 | ||
800d5872 SD |
930 | if ((wpa_s->conf->tdls_external_control) && |
931 | wpa_tdls_is_external_setup(wpa_s->wpa)) | |
932 | return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); | |
933 | ||
4ed8d954 AS |
934 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
935 | ret = wpa_tdls_teardown_link( | |
936 | wpa_s->wpa, peer, | |
937 | WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED); | |
938 | else | |
939 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); | |
940 | ||
941 | return ret; | |
281ff0aa GP |
942 | } |
943 | ||
6e9375e4 DS |
944 | |
945 | static int ctrl_iface_get_capability_tdls( | |
946 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
947 | { | |
948 | int ret; | |
949 | ||
950 | ret = os_snprintf(buf, buflen, "%s\n", | |
951 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ? | |
952 | (wpa_s->drv_flags & | |
953 | WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ? | |
954 | "EXTERNAL" : "INTERNAL") : "UNSUPPORTED"); | |
7bdd8981 | 955 | if (os_snprintf_error(buflen, ret)) |
6e9375e4 DS |
956 | return -1; |
957 | return ret; | |
958 | } | |
959 | ||
6b90deae AN |
960 | |
961 | static int wpa_supplicant_ctrl_iface_tdls_chan_switch( | |
962 | struct wpa_supplicant *wpa_s, char *cmd) | |
963 | { | |
964 | u8 peer[ETH_ALEN]; | |
965 | struct hostapd_freq_params freq_params; | |
966 | u8 oper_class; | |
967 | char *pos, *end; | |
968 | ||
969 | if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { | |
970 | wpa_printf(MSG_INFO, | |
971 | "tdls_chanswitch: Only supported with external setup"); | |
972 | return -1; | |
973 | } | |
974 | ||
975 | os_memset(&freq_params, 0, sizeof(freq_params)); | |
976 | ||
977 | pos = os_strchr(cmd, ' '); | |
978 | if (pos == NULL) | |
979 | return -1; | |
980 | *pos++ = '\0'; | |
981 | ||
982 | oper_class = strtol(pos, &end, 10); | |
983 | if (pos == end) { | |
984 | wpa_printf(MSG_INFO, | |
985 | "tdls_chanswitch: Invalid op class provided"); | |
986 | return -1; | |
987 | } | |
988 | ||
989 | pos = end; | |
990 | freq_params.freq = atoi(pos); | |
991 | if (freq_params.freq == 0) { | |
992 | wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided"); | |
993 | return -1; | |
994 | } | |
995 | ||
996 | #define SET_FREQ_SETTING(str) \ | |
997 | do { \ | |
998 | const char *pos2 = os_strstr(pos, " " #str "="); \ | |
999 | if (pos2) { \ | |
1000 | pos2 += sizeof(" " #str "=") - 1; \ | |
1001 | freq_params.str = atoi(pos2); \ | |
1002 | } \ | |
1003 | } while (0) | |
1004 | ||
1005 | SET_FREQ_SETTING(center_freq1); | |
1006 | SET_FREQ_SETTING(center_freq2); | |
1007 | SET_FREQ_SETTING(bandwidth); | |
1008 | SET_FREQ_SETTING(sec_channel_offset); | |
1009 | #undef SET_FREQ_SETTING | |
1010 | ||
1011 | freq_params.ht_enabled = !!os_strstr(pos, " ht"); | |
1012 | freq_params.vht_enabled = !!os_strstr(pos, " vht"); | |
1013 | ||
1014 | if (hwaddr_aton(cmd, peer)) { | |
1015 | wpa_printf(MSG_DEBUG, | |
1016 | "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'", | |
1017 | cmd); | |
1018 | return -1; | |
1019 | } | |
1020 | ||
1021 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR | |
1022 | " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s", | |
1023 | MAC2STR(peer), oper_class, freq_params.freq, | |
1024 | freq_params.center_freq1, freq_params.center_freq2, | |
1025 | freq_params.bandwidth, freq_params.sec_channel_offset, | |
1026 | freq_params.ht_enabled ? " HT" : "", | |
1027 | freq_params.vht_enabled ? " VHT" : ""); | |
1028 | ||
1029 | return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class, | |
1030 | &freq_params); | |
1031 | } | |
1032 | ||
1033 | ||
1034 | static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch( | |
1035 | struct wpa_supplicant *wpa_s, char *cmd) | |
1036 | { | |
1037 | u8 peer[ETH_ALEN]; | |
1038 | ||
1039 | if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { | |
1040 | wpa_printf(MSG_INFO, | |
1041 | "tdls_chanswitch: Only supported with external setup"); | |
1042 | return -1; | |
1043 | } | |
1044 | ||
1045 | if (hwaddr_aton(cmd, peer)) { | |
1046 | wpa_printf(MSG_DEBUG, | |
1047 | "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'", | |
1048 | cmd); | |
1049 | return -1; | |
1050 | } | |
1051 | ||
1052 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR, | |
1053 | MAC2STR(peer)); | |
1054 | ||
1055 | return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer); | |
1056 | } | |
1057 | ||
4504621f OG |
1058 | |
1059 | static int wpa_supplicant_ctrl_iface_tdls_link_status( | |
1060 | struct wpa_supplicant *wpa_s, const char *addr, | |
1061 | char *buf, size_t buflen) | |
1062 | { | |
1063 | u8 peer[ETH_ALEN]; | |
1064 | const char *tdls_status; | |
1065 | int ret; | |
1066 | ||
1067 | if (hwaddr_aton(addr, peer)) { | |
1068 | wpa_printf(MSG_DEBUG, | |
1069 | "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'", | |
1070 | addr); | |
1071 | return -1; | |
1072 | } | |
1073 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR, | |
1074 | MAC2STR(peer)); | |
1075 | ||
1076 | tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer); | |
1077 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status); | |
1078 | ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status); | |
1079 | if (os_snprintf_error(buflen, ret)) | |
1080 | return -1; | |
1081 | ||
1082 | return ret; | |
1083 | } | |
1084 | ||
281ff0aa GP |
1085 | #endif /* CONFIG_TDLS */ |
1086 | ||
1087 | ||
eb2f2088 MB |
1088 | static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd) |
1089 | { | |
1090 | char *token, *context = NULL; | |
1091 | struct wmm_ac_ts_setup_params params = { | |
1092 | .tsid = 0xff, | |
1093 | .direction = 0xff, | |
1094 | }; | |
1095 | ||
1096 | while ((token = str_token(cmd, " ", &context))) { | |
1097 | if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 || | |
1098 | sscanf(token, "up=%i", ¶ms.user_priority) == 1 || | |
1099 | sscanf(token, "nominal_msdu_size=%i", | |
1100 | ¶ms.nominal_msdu_size) == 1 || | |
1101 | sscanf(token, "mean_data_rate=%i", | |
1102 | ¶ms.mean_data_rate) == 1 || | |
1103 | sscanf(token, "min_phy_rate=%i", | |
1104 | ¶ms.minimum_phy_rate) == 1 || | |
1105 | sscanf(token, "sba=%i", | |
1106 | ¶ms.surplus_bandwidth_allowance) == 1) | |
1107 | continue; | |
1108 | ||
1109 | if (os_strcasecmp(token, "downlink") == 0) { | |
1110 | params.direction = WMM_TSPEC_DIRECTION_DOWNLINK; | |
1111 | } else if (os_strcasecmp(token, "uplink") == 0) { | |
1112 | params.direction = WMM_TSPEC_DIRECTION_UPLINK; | |
1113 | } else if (os_strcasecmp(token, "bidi") == 0) { | |
1114 | params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL; | |
1115 | } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) { | |
1116 | params.fixed_nominal_msdu = 1; | |
1117 | } else { | |
1118 | wpa_printf(MSG_DEBUG, | |
1119 | "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'", | |
1120 | token); | |
1121 | return -1; | |
1122 | } | |
1123 | ||
1124 | } | |
1125 | ||
1126 | return wpas_wmm_ac_addts(wpa_s, ¶ms); | |
1127 | } | |
1128 | ||
1129 | ||
1130 | static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd) | |
1131 | { | |
1132 | u8 tsid = atoi(cmd); | |
1133 | ||
1134 | return wpas_wmm_ac_delts(wpa_s, tsid); | |
1135 | } | |
1136 | ||
1137 | ||
6fc6879b JM |
1138 | #ifdef CONFIG_IEEE80211R |
1139 | static int wpa_supplicant_ctrl_iface_ft_ds( | |
1140 | struct wpa_supplicant *wpa_s, char *addr) | |
1141 | { | |
1142 | u8 target_ap[ETH_ALEN]; | |
76b7981d JM |
1143 | struct wpa_bss *bss; |
1144 | const u8 *mdie; | |
6fc6879b JM |
1145 | |
1146 | if (hwaddr_aton(addr, target_ap)) { | |
1147 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid " | |
a7b6c422 | 1148 | "address '%s'", addr); |
6fc6879b JM |
1149 | return -1; |
1150 | } | |
1151 | ||
1152 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap)); | |
1153 | ||
76b7981d JM |
1154 | bss = wpa_bss_get_bssid(wpa_s, target_ap); |
1155 | if (bss) | |
1156 | mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); | |
1157 | else | |
1158 | mdie = NULL; | |
1159 | ||
1160 | return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie); | |
6fc6879b JM |
1161 | } |
1162 | #endif /* CONFIG_IEEE80211R */ | |
1163 | ||
1164 | ||
fcc60db4 JM |
1165 | #ifdef CONFIG_WPS |
1166 | static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s, | |
1167 | char *cmd) | |
1168 | { | |
3ec97afe | 1169 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
ceb34f25 | 1170 | #ifdef CONFIG_P2P |
634ce802 | 1171 | u8 p2p_dev_addr[ETH_ALEN]; |
ceb34f25 | 1172 | #endif /* CONFIG_P2P */ |
634ce802 JM |
1173 | #ifdef CONFIG_AP |
1174 | u8 *_p2p_dev_addr = NULL; | |
1175 | #endif /* CONFIG_AP */ | |
83ebf558 DL |
1176 | char *pos; |
1177 | int multi_ap = 0; | |
fcc60db4 | 1178 | |
83ebf558 DL |
1179 | if (!cmd || os_strcmp(cmd, "any") == 0 || |
1180 | os_strncmp(cmd, "any ", 4) == 0) { | |
3ec97afe | 1181 | _bssid = NULL; |
d601247c JM |
1182 | #ifdef CONFIG_P2P |
1183 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | |
1184 | if (hwaddr_aton(cmd + 13, p2p_dev_addr)) { | |
1185 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid " | |
1186 | "P2P Device Address '%s'", | |
1187 | cmd + 13); | |
1188 | return -1; | |
1189 | } | |
1190 | _p2p_dev_addr = p2p_dev_addr; | |
1191 | #endif /* CONFIG_P2P */ | |
83ebf558 DL |
1192 | } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) { |
1193 | _bssid = NULL; | |
1194 | multi_ap = atoi(cmd + 9); | |
d601247c | 1195 | } else if (hwaddr_aton(cmd, bssid)) { |
fcc60db4 JM |
1196 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'", |
1197 | cmd); | |
1198 | return -1; | |
1199 | } | |
1200 | ||
83ebf558 DL |
1201 | if (cmd) { |
1202 | pos = os_strstr(cmd, " multi_ap="); | |
1203 | if (pos) { | |
1204 | pos += 10; | |
1205 | multi_ap = atoi(pos); | |
1206 | } | |
1207 | } | |
1208 | ||
3ec97afe JM |
1209 | #ifdef CONFIG_AP |
1210 | if (wpa_s->ap_iface) | |
d601247c | 1211 | return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr); |
3ec97afe JM |
1212 | #endif /* CONFIG_AP */ |
1213 | ||
83ebf558 | 1214 | return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap); |
fcc60db4 JM |
1215 | } |
1216 | ||
1217 | ||
1218 | static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, | |
1219 | char *cmd, char *buf, | |
1220 | size_t buflen) | |
1221 | { | |
1222 | u8 bssid[ETH_ALEN], *_bssid = bssid; | |
1223 | char *pin; | |
1224 | int ret; | |
1225 | ||
1226 | pin = os_strchr(cmd, ' '); | |
1227 | if (pin) | |
1228 | *pin++ = '\0'; | |
1229 | ||
1230 | if (os_strcmp(cmd, "any") == 0) | |
1231 | _bssid = NULL; | |
98aa7ca5 | 1232 | else if (os_strcmp(cmd, "get") == 0) { |
98a516ea NL |
1233 | if (wps_generate_pin((unsigned int *) &ret) < 0) |
1234 | return -1; | |
98aa7ca5 JM |
1235 | goto done; |
1236 | } else if (hwaddr_aton(cmd, bssid)) { | |
3c1e2765 | 1237 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'", |
fcc60db4 JM |
1238 | cmd); |
1239 | return -1; | |
1240 | } | |
1241 | ||
3ec97afe | 1242 | #ifdef CONFIG_AP |
c423708f JM |
1243 | if (wpa_s->ap_iface) { |
1244 | int timeout = 0; | |
1245 | char *pos; | |
1246 | ||
1247 | if (pin) { | |
1248 | pos = os_strchr(pin, ' '); | |
1249 | if (pos) { | |
1250 | *pos++ = '\0'; | |
1251 | timeout = atoi(pos); | |
1252 | } | |
1253 | } | |
1254 | ||
3ec97afe | 1255 | return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, |
c423708f JM |
1256 | buf, buflen, timeout); |
1257 | } | |
3ec97afe JM |
1258 | #endif /* CONFIG_AP */ |
1259 | ||
fcc60db4 | 1260 | if (pin) { |
3c5126a4 JM |
1261 | ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0, |
1262 | DEV_PW_DEFAULT); | |
fcc60db4 JM |
1263 | if (ret < 0) |
1264 | return -1; | |
1265 | ret = os_snprintf(buf, buflen, "%s", pin); | |
d85e1fc8 | 1266 | if (os_snprintf_error(buflen, ret)) |
fcc60db4 JM |
1267 | return -1; |
1268 | return ret; | |
1269 | } | |
1270 | ||
3c5126a4 | 1271 | ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT); |
fcc60db4 JM |
1272 | if (ret < 0) |
1273 | return -1; | |
1274 | ||
98aa7ca5 | 1275 | done: |
fcc60db4 JM |
1276 | /* Return the generated PIN */ |
1277 | ret = os_snprintf(buf, buflen, "%08d", ret); | |
d85e1fc8 | 1278 | if (os_snprintf_error(buflen, ret)) |
fcc60db4 JM |
1279 | return -1; |
1280 | return ret; | |
1281 | } | |
1282 | ||
1283 | ||
3981cb3c JM |
1284 | static int wpa_supplicant_ctrl_iface_wps_check_pin( |
1285 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
1286 | { | |
1287 | char pin[9]; | |
1288 | size_t len; | |
1289 | char *pos; | |
1290 | int ret; | |
1291 | ||
1292 | wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN", | |
1293 | (u8 *) cmd, os_strlen(cmd)); | |
1294 | for (pos = cmd, len = 0; *pos != '\0'; pos++) { | |
1295 | if (*pos < '0' || *pos > '9') | |
1296 | continue; | |
1297 | pin[len++] = *pos; | |
1298 | if (len == 9) { | |
1299 | wpa_printf(MSG_DEBUG, "WPS: Too long PIN"); | |
1300 | return -1; | |
1301 | } | |
1302 | } | |
1303 | if (len != 4 && len != 8) { | |
1304 | wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len); | |
1305 | return -1; | |
1306 | } | |
1307 | pin[len] = '\0'; | |
1308 | ||
1309 | if (len == 8) { | |
1310 | unsigned int pin_val; | |
1311 | pin_val = atoi(pin); | |
1312 | if (!wps_pin_valid(pin_val)) { | |
1313 | wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit"); | |
1314 | ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n"); | |
d85e1fc8 | 1315 | if (os_snprintf_error(buflen, ret)) |
3981cb3c JM |
1316 | return -1; |
1317 | return ret; | |
1318 | } | |
1319 | } | |
1320 | ||
1321 | ret = os_snprintf(buf, buflen, "%s", pin); | |
d85e1fc8 | 1322 | if (os_snprintf_error(buflen, ret)) |
3981cb3c JM |
1323 | return -1; |
1324 | ||
1325 | return ret; | |
1326 | } | |
1327 | ||
1328 | ||
71892384 | 1329 | #ifdef CONFIG_WPS_NFC |
3f2c8ba6 JM |
1330 | |
1331 | static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s, | |
1332 | char *cmd) | |
1333 | { | |
1334 | u8 bssid[ETH_ALEN], *_bssid = bssid; | |
1335 | ||
1336 | if (cmd == NULL || cmd[0] == '\0') | |
1337 | _bssid = NULL; | |
1338 | else if (hwaddr_aton(cmd, bssid)) | |
1339 | return -1; | |
1340 | ||
23318bea | 1341 | return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL, |
91a65018 | 1342 | 0, 0); |
3f2c8ba6 JM |
1343 | } |
1344 | ||
1345 | ||
bbf41865 JM |
1346 | static int wpa_supplicant_ctrl_iface_wps_nfc_config_token( |
1347 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
1348 | { | |
1349 | int ndef; | |
1350 | struct wpabuf *buf; | |
1351 | int res; | |
88c8bf31 | 1352 | char *pos; |
bbf41865 | 1353 | |
88c8bf31 JM |
1354 | pos = os_strchr(cmd, ' '); |
1355 | if (pos) | |
1356 | *pos++ = '\0'; | |
bbf41865 JM |
1357 | if (os_strcmp(cmd, "WPS") == 0) |
1358 | ndef = 0; | |
1359 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1360 | ndef = 1; | |
1361 | else | |
1362 | return -1; | |
1363 | ||
88c8bf31 | 1364 | buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos); |
bbf41865 JM |
1365 | if (buf == NULL) |
1366 | return -1; | |
1367 | ||
1368 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1369 | wpabuf_len(buf)); | |
1370 | reply[res++] = '\n'; | |
1371 | reply[res] = '\0'; | |
1372 | ||
1373 | wpabuf_free(buf); | |
1374 | ||
1375 | return res; | |
1376 | } | |
1377 | ||
1378 | ||
3f2c8ba6 JM |
1379 | static int wpa_supplicant_ctrl_iface_wps_nfc_token( |
1380 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
1381 | { | |
1382 | int ndef; | |
1383 | struct wpabuf *buf; | |
1384 | int res; | |
1385 | ||
1386 | if (os_strcmp(cmd, "WPS") == 0) | |
1387 | ndef = 0; | |
1388 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1389 | ndef = 1; | |
1390 | else | |
1391 | return -1; | |
1392 | ||
1393 | buf = wpas_wps_nfc_token(wpa_s, ndef); | |
1394 | if (buf == NULL) | |
1395 | return -1; | |
1396 | ||
1397 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1398 | wpabuf_len(buf)); | |
1399 | reply[res++] = '\n'; | |
1400 | reply[res] = '\0'; | |
1401 | ||
1402 | wpabuf_free(buf); | |
1403 | ||
1404 | return res; | |
1405 | } | |
d7645d23 JM |
1406 | |
1407 | ||
1408 | static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read( | |
1409 | struct wpa_supplicant *wpa_s, char *pos) | |
1410 | { | |
1411 | size_t len; | |
1412 | struct wpabuf *buf; | |
1413 | int ret; | |
b56f6c88 JM |
1414 | char *freq; |
1415 | int forced_freq = 0; | |
1416 | ||
1417 | freq = strstr(pos, " freq="); | |
1418 | if (freq) { | |
1419 | *freq = '\0'; | |
1420 | freq += 6; | |
1421 | forced_freq = atoi(freq); | |
1422 | } | |
d7645d23 JM |
1423 | |
1424 | len = os_strlen(pos); | |
1425 | if (len & 0x01) | |
1426 | return -1; | |
1427 | len /= 2; | |
1428 | ||
1429 | buf = wpabuf_alloc(len); | |
1430 | if (buf == NULL) | |
1431 | return -1; | |
1432 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { | |
1433 | wpabuf_free(buf); | |
1434 | return -1; | |
1435 | } | |
1436 | ||
b56f6c88 | 1437 | ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq); |
d7645d23 JM |
1438 | wpabuf_free(buf); |
1439 | ||
1440 | return ret; | |
1441 | } | |
71892384 | 1442 | |
e65552dd JM |
1443 | |
1444 | static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s, | |
bbaaaee1 | 1445 | char *reply, size_t max_len, |
41f9ffb6 | 1446 | int ndef) |
e65552dd JM |
1447 | { |
1448 | struct wpabuf *buf; | |
1449 | int res; | |
1450 | ||
41f9ffb6 | 1451 | buf = wpas_wps_nfc_handover_req(wpa_s, ndef); |
e65552dd JM |
1452 | if (buf == NULL) |
1453 | return -1; | |
1454 | ||
1455 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1456 | wpabuf_len(buf)); | |
1457 | reply[res++] = '\n'; | |
1458 | reply[res] = '\0'; | |
1459 | ||
1460 | wpabuf_free(buf); | |
1461 | ||
1462 | return res; | |
1463 | } | |
1464 | ||
1465 | ||
88853aed | 1466 | #ifdef CONFIG_P2P |
93588780 JM |
1467 | static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s, |
1468 | char *reply, size_t max_len, | |
1469 | int ndef) | |
1470 | { | |
1471 | struct wpabuf *buf; | |
1472 | int res; | |
1473 | ||
1474 | buf = wpas_p2p_nfc_handover_req(wpa_s, ndef); | |
1475 | if (buf == NULL) { | |
1476 | wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request"); | |
1477 | return -1; | |
1478 | } | |
1479 | ||
1480 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1481 | wpabuf_len(buf)); | |
1482 | reply[res++] = '\n'; | |
1483 | reply[res] = '\0'; | |
1484 | ||
1485 | wpabuf_free(buf); | |
1486 | ||
1487 | return res; | |
1488 | } | |
88853aed | 1489 | #endif /* CONFIG_P2P */ |
93588780 JM |
1490 | |
1491 | ||
e65552dd JM |
1492 | static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s, |
1493 | char *cmd, char *reply, | |
1494 | size_t max_len) | |
1495 | { | |
1496 | char *pos; | |
41f9ffb6 | 1497 | int ndef; |
e65552dd JM |
1498 | |
1499 | pos = os_strchr(cmd, ' '); | |
1500 | if (pos == NULL) | |
1501 | return -1; | |
1502 | *pos++ = '\0'; | |
1503 | ||
41f9ffb6 JM |
1504 | if (os_strcmp(cmd, "WPS") == 0) |
1505 | ndef = 0; | |
1506 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1507 | ndef = 1; | |
1508 | else | |
e65552dd JM |
1509 | return -1; |
1510 | ||
bbaaaee1 | 1511 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
41f9ffb6 JM |
1512 | if (!ndef) |
1513 | return -1; | |
bbaaaee1 | 1514 | return wpas_ctrl_nfc_get_handover_req_wps( |
41f9ffb6 | 1515 | wpa_s, reply, max_len, ndef); |
e65552dd JM |
1516 | } |
1517 | ||
88853aed | 1518 | #ifdef CONFIG_P2P |
93588780 JM |
1519 | if (os_strcmp(pos, "P2P-CR") == 0) { |
1520 | return wpas_ctrl_nfc_get_handover_req_p2p( | |
1521 | wpa_s, reply, max_len, ndef); | |
1522 | } | |
88853aed | 1523 | #endif /* CONFIG_P2P */ |
93588780 | 1524 | |
e65552dd JM |
1525 | return -1; |
1526 | } | |
1527 | ||
1528 | ||
1529 | static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s, | |
5ab9a6a5 | 1530 | char *reply, size_t max_len, |
f3f2ba2e | 1531 | int ndef, int cr, char *uuid) |
e65552dd JM |
1532 | { |
1533 | struct wpabuf *buf; | |
1534 | int res; | |
1535 | ||
f3f2ba2e | 1536 | buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid); |
e65552dd JM |
1537 | if (buf == NULL) |
1538 | return -1; | |
1539 | ||
1540 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1541 | wpabuf_len(buf)); | |
1542 | reply[res++] = '\n'; | |
1543 | reply[res] = '\0'; | |
1544 | ||
1545 | wpabuf_free(buf); | |
1546 | ||
1547 | return res; | |
1548 | } | |
1549 | ||
1550 | ||
88853aed | 1551 | #ifdef CONFIG_P2P |
93588780 JM |
1552 | static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s, |
1553 | char *reply, size_t max_len, | |
1554 | int ndef, int tag) | |
1555 | { | |
1556 | struct wpabuf *buf; | |
1557 | int res; | |
1558 | ||
1559 | buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag); | |
1560 | if (buf == NULL) | |
1561 | return -1; | |
1562 | ||
1563 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1564 | wpabuf_len(buf)); | |
1565 | reply[res++] = '\n'; | |
1566 | reply[res] = '\0'; | |
1567 | ||
1568 | wpabuf_free(buf); | |
1569 | ||
1570 | return res; | |
1571 | } | |
88853aed | 1572 | #endif /* CONFIG_P2P */ |
93588780 JM |
1573 | |
1574 | ||
e65552dd JM |
1575 | static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s, |
1576 | char *cmd, char *reply, | |
1577 | size_t max_len) | |
1578 | { | |
f3f2ba2e | 1579 | char *pos, *pos2; |
5ab9a6a5 | 1580 | int ndef; |
e65552dd JM |
1581 | |
1582 | pos = os_strchr(cmd, ' '); | |
1583 | if (pos == NULL) | |
1584 | return -1; | |
1585 | *pos++ = '\0'; | |
1586 | ||
5ab9a6a5 JM |
1587 | if (os_strcmp(cmd, "WPS") == 0) |
1588 | ndef = 0; | |
1589 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1590 | ndef = 1; | |
1591 | else | |
e65552dd JM |
1592 | return -1; |
1593 | ||
f3f2ba2e JM |
1594 | pos2 = os_strchr(pos, ' '); |
1595 | if (pos2) | |
1596 | *pos2++ = '\0'; | |
5ab9a6a5 | 1597 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
93588780 JM |
1598 | if (!ndef) |
1599 | return -1; | |
5ab9a6a5 JM |
1600 | return wpas_ctrl_nfc_get_handover_sel_wps( |
1601 | wpa_s, reply, max_len, ndef, | |
f3f2ba2e | 1602 | os_strcmp(pos, "WPS-CR") == 0, pos2); |
e65552dd JM |
1603 | } |
1604 | ||
88853aed | 1605 | #ifdef CONFIG_P2P |
93588780 JM |
1606 | if (os_strcmp(pos, "P2P-CR") == 0) { |
1607 | return wpas_ctrl_nfc_get_handover_sel_p2p( | |
1608 | wpa_s, reply, max_len, ndef, 0); | |
1609 | } | |
1610 | ||
1611 | if (os_strcmp(pos, "P2P-CR-TAG") == 0) { | |
1612 | return wpas_ctrl_nfc_get_handover_sel_p2p( | |
1613 | wpa_s, reply, max_len, ndef, 1); | |
1614 | } | |
88853aed | 1615 | #endif /* CONFIG_P2P */ |
93588780 | 1616 | |
e65552dd JM |
1617 | return -1; |
1618 | } | |
1619 | ||
1620 | ||
e4758827 JM |
1621 | static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s, |
1622 | char *cmd) | |
1623 | { | |
1624 | size_t len; | |
1625 | struct wpabuf *req, *sel; | |
1626 | int ret; | |
1627 | char *pos, *role, *type, *pos2; | |
88853aed | 1628 | #ifdef CONFIG_P2P |
b56f6c88 JM |
1629 | char *freq; |
1630 | int forced_freq = 0; | |
1631 | ||
1632 | freq = strstr(cmd, " freq="); | |
1633 | if (freq) { | |
1634 | *freq = '\0'; | |
1635 | freq += 6; | |
1636 | forced_freq = atoi(freq); | |
1637 | } | |
88853aed | 1638 | #endif /* CONFIG_P2P */ |
e4758827 JM |
1639 | |
1640 | role = cmd; | |
1641 | pos = os_strchr(role, ' '); | |
73127764 JM |
1642 | if (pos == NULL) { |
1643 | wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report"); | |
e4758827 | 1644 | return -1; |
73127764 | 1645 | } |
e4758827 JM |
1646 | *pos++ = '\0'; |
1647 | ||
1648 | type = pos; | |
1649 | pos = os_strchr(type, ' '); | |
73127764 JM |
1650 | if (pos == NULL) { |
1651 | wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report"); | |
e4758827 | 1652 | return -1; |
73127764 | 1653 | } |
e4758827 JM |
1654 | *pos++ = '\0'; |
1655 | ||
1656 | pos2 = os_strchr(pos, ' '); | |
73127764 JM |
1657 | if (pos2 == NULL) { |
1658 | wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report"); | |
e4758827 | 1659 | return -1; |
73127764 | 1660 | } |
e4758827 JM |
1661 | *pos2++ = '\0'; |
1662 | ||
1663 | len = os_strlen(pos); | |
73127764 JM |
1664 | if (len & 0x01) { |
1665 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report"); | |
e4758827 | 1666 | return -1; |
73127764 | 1667 | } |
e4758827 JM |
1668 | len /= 2; |
1669 | ||
1670 | req = wpabuf_alloc(len); | |
73127764 JM |
1671 | if (req == NULL) { |
1672 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message"); | |
e4758827 | 1673 | return -1; |
73127764 | 1674 | } |
e4758827 | 1675 | if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) { |
73127764 | 1676 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report"); |
e4758827 JM |
1677 | wpabuf_free(req); |
1678 | return -1; | |
1679 | } | |
1680 | ||
1681 | len = os_strlen(pos2); | |
1682 | if (len & 0x01) { | |
73127764 | 1683 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report"); |
e4758827 JM |
1684 | wpabuf_free(req); |
1685 | return -1; | |
1686 | } | |
1687 | len /= 2; | |
1688 | ||
1689 | sel = wpabuf_alloc(len); | |
1690 | if (sel == NULL) { | |
73127764 | 1691 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message"); |
e4758827 JM |
1692 | wpabuf_free(req); |
1693 | return -1; | |
1694 | } | |
1695 | if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) { | |
73127764 | 1696 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report"); |
e4758827 JM |
1697 | wpabuf_free(req); |
1698 | wpabuf_free(sel); | |
1699 | return -1; | |
1700 | } | |
1701 | ||
73127764 JM |
1702 | wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d", |
1703 | role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel)); | |
1704 | ||
e4758827 JM |
1705 | if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) { |
1706 | ret = wpas_wps_nfc_report_handover(wpa_s, req, sel); | |
88853aed | 1707 | #ifdef CONFIG_AP |
d9507936 JM |
1708 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) |
1709 | { | |
1710 | ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel); | |
50d1f890 JM |
1711 | if (ret < 0) |
1712 | ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel); | |
88853aed JM |
1713 | #endif /* CONFIG_AP */ |
1714 | #ifdef CONFIG_P2P | |
db6ae69e JM |
1715 | } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0) |
1716 | { | |
b56f6c88 | 1717 | ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0); |
db6ae69e JM |
1718 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0) |
1719 | { | |
b56f6c88 JM |
1720 | ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel, |
1721 | forced_freq); | |
88853aed | 1722 | #endif /* CONFIG_P2P */ |
e4758827 JM |
1723 | } else { |
1724 | wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover " | |
1725 | "reported: role=%s type=%s", role, type); | |
1726 | ret = -1; | |
1727 | } | |
1728 | wpabuf_free(req); | |
1729 | wpabuf_free(sel); | |
1730 | ||
73127764 JM |
1731 | if (ret) |
1732 | wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages"); | |
1733 | ||
e4758827 JM |
1734 | return ret; |
1735 | } | |
1736 | ||
71892384 | 1737 | #endif /* CONFIG_WPS_NFC */ |
46bdb83a MH |
1738 | |
1739 | ||
fcc60db4 JM |
1740 | static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s, |
1741 | char *cmd) | |
1742 | { | |
129eb428 | 1743 | u8 bssid[ETH_ALEN]; |
fcc60db4 | 1744 | char *pin; |
52eb293d JM |
1745 | char *new_ssid; |
1746 | char *new_auth; | |
1747 | char *new_encr; | |
1748 | char *new_key; | |
1749 | struct wps_new_ap_settings ap; | |
fcc60db4 JM |
1750 | |
1751 | pin = os_strchr(cmd, ' '); | |
1752 | if (pin == NULL) | |
1753 | return -1; | |
1754 | *pin++ = '\0'; | |
1755 | ||
129eb428 | 1756 | if (hwaddr_aton(cmd, bssid)) { |
fcc60db4 JM |
1757 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'", |
1758 | cmd); | |
1759 | return -1; | |
1760 | } | |
1761 | ||
52eb293d JM |
1762 | new_ssid = os_strchr(pin, ' '); |
1763 | if (new_ssid == NULL) | |
129eb428 | 1764 | return wpas_wps_start_reg(wpa_s, bssid, pin, NULL); |
52eb293d JM |
1765 | *new_ssid++ = '\0'; |
1766 | ||
1767 | new_auth = os_strchr(new_ssid, ' '); | |
1768 | if (new_auth == NULL) | |
1769 | return -1; | |
1770 | *new_auth++ = '\0'; | |
1771 | ||
1772 | new_encr = os_strchr(new_auth, ' '); | |
1773 | if (new_encr == NULL) | |
1774 | return -1; | |
1775 | *new_encr++ = '\0'; | |
1776 | ||
1777 | new_key = os_strchr(new_encr, ' '); | |
1778 | if (new_key == NULL) | |
1779 | return -1; | |
1780 | *new_key++ = '\0'; | |
1781 | ||
1782 | os_memset(&ap, 0, sizeof(ap)); | |
1783 | ap.ssid_hex = new_ssid; | |
1784 | ap.auth = new_auth; | |
1785 | ap.encr = new_encr; | |
1786 | ap.key_hex = new_key; | |
129eb428 | 1787 | return wpas_wps_start_reg(wpa_s, bssid, pin, &ap); |
fcc60db4 | 1788 | } |
72df2f5f JM |
1789 | |
1790 | ||
70d84f11 JM |
1791 | #ifdef CONFIG_AP |
1792 | static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s, | |
1793 | char *cmd, char *buf, | |
1794 | size_t buflen) | |
1795 | { | |
1796 | int timeout = 300; | |
1797 | char *pos; | |
1798 | const char *pin_txt; | |
1799 | ||
1800 | if (!wpa_s->ap_iface) | |
1801 | return -1; | |
1802 | ||
1803 | pos = os_strchr(cmd, ' '); | |
1804 | if (pos) | |
1805 | *pos++ = '\0'; | |
1806 | ||
1807 | if (os_strcmp(cmd, "disable") == 0) { | |
1808 | wpas_wps_ap_pin_disable(wpa_s); | |
1809 | return os_snprintf(buf, buflen, "OK\n"); | |
1810 | } | |
1811 | ||
1812 | if (os_strcmp(cmd, "random") == 0) { | |
1813 | if (pos) | |
1814 | timeout = atoi(pos); | |
1815 | pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout); | |
1816 | if (pin_txt == NULL) | |
1817 | return -1; | |
1818 | return os_snprintf(buf, buflen, "%s", pin_txt); | |
1819 | } | |
1820 | ||
1821 | if (os_strcmp(cmd, "get") == 0) { | |
1822 | pin_txt = wpas_wps_ap_pin_get(wpa_s); | |
1823 | if (pin_txt == NULL) | |
1824 | return -1; | |
1825 | return os_snprintf(buf, buflen, "%s", pin_txt); | |
1826 | } | |
1827 | ||
1828 | if (os_strcmp(cmd, "set") == 0) { | |
1829 | char *pin; | |
1830 | if (pos == NULL) | |
1831 | return -1; | |
1832 | pin = pos; | |
1833 | pos = os_strchr(pos, ' '); | |
1834 | if (pos) { | |
1835 | *pos++ = '\0'; | |
1836 | timeout = atoi(pos); | |
1837 | } | |
1838 | if (os_strlen(pin) > buflen) | |
1839 | return -1; | |
1840 | if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0) | |
1841 | return -1; | |
1842 | return os_snprintf(buf, buflen, "%s", pin); | |
1843 | } | |
1844 | ||
1845 | return -1; | |
1846 | } | |
1847 | #endif /* CONFIG_AP */ | |
1848 | ||
1849 | ||
72df2f5f JM |
1850 | #ifdef CONFIG_WPS_ER |
1851 | static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s, | |
1852 | char *cmd) | |
1853 | { | |
31fcea93 JM |
1854 | char *uuid = cmd, *pin, *pos; |
1855 | u8 addr_buf[ETH_ALEN], *addr = NULL; | |
72df2f5f JM |
1856 | pin = os_strchr(uuid, ' '); |
1857 | if (pin == NULL) | |
1858 | return -1; | |
1859 | *pin++ = '\0'; | |
31fcea93 JM |
1860 | pos = os_strchr(pin, ' '); |
1861 | if (pos) { | |
1862 | *pos++ = '\0'; | |
1863 | if (hwaddr_aton(pos, addr_buf) == 0) | |
1864 | addr = addr_buf; | |
1865 | } | |
1866 | return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin); | |
72df2f5f | 1867 | } |
e64dcfd5 JM |
1868 | |
1869 | ||
1870 | static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s, | |
1871 | char *cmd) | |
1872 | { | |
1873 | char *uuid = cmd, *pin; | |
1874 | pin = os_strchr(uuid, ' '); | |
1875 | if (pin == NULL) | |
1876 | return -1; | |
1877 | *pin++ = '\0'; | |
1878 | return wpas_wps_er_learn(wpa_s, uuid, pin); | |
1879 | } | |
7d6640a6 JM |
1880 | |
1881 | ||
ef10f473 JM |
1882 | static int wpa_supplicant_ctrl_iface_wps_er_set_config( |
1883 | struct wpa_supplicant *wpa_s, char *cmd) | |
1884 | { | |
1885 | char *uuid = cmd, *id; | |
1886 | id = os_strchr(uuid, ' '); | |
1887 | if (id == NULL) | |
1888 | return -1; | |
1889 | *id++ = '\0'; | |
1890 | return wpas_wps_er_set_config(wpa_s, uuid, atoi(id)); | |
1891 | } | |
1892 | ||
1893 | ||
7d6640a6 JM |
1894 | static int wpa_supplicant_ctrl_iface_wps_er_config( |
1895 | struct wpa_supplicant *wpa_s, char *cmd) | |
1896 | { | |
1897 | char *pin; | |
1898 | char *new_ssid; | |
1899 | char *new_auth; | |
1900 | char *new_encr; | |
1901 | char *new_key; | |
1902 | struct wps_new_ap_settings ap; | |
1903 | ||
1904 | pin = os_strchr(cmd, ' '); | |
1905 | if (pin == NULL) | |
1906 | return -1; | |
1907 | *pin++ = '\0'; | |
1908 | ||
1909 | new_ssid = os_strchr(pin, ' '); | |
1910 | if (new_ssid == NULL) | |
1911 | return -1; | |
1912 | *new_ssid++ = '\0'; | |
1913 | ||
1914 | new_auth = os_strchr(new_ssid, ' '); | |
1915 | if (new_auth == NULL) | |
1916 | return -1; | |
1917 | *new_auth++ = '\0'; | |
1918 | ||
1919 | new_encr = os_strchr(new_auth, ' '); | |
1920 | if (new_encr == NULL) | |
1921 | return -1; | |
1922 | *new_encr++ = '\0'; | |
1923 | ||
1924 | new_key = os_strchr(new_encr, ' '); | |
1925 | if (new_key == NULL) | |
1926 | return -1; | |
1927 | *new_key++ = '\0'; | |
1928 | ||
1929 | os_memset(&ap, 0, sizeof(ap)); | |
1930 | ap.ssid_hex = new_ssid; | |
1931 | ap.auth = new_auth; | |
1932 | ap.encr = new_encr; | |
1933 | ap.key_hex = new_key; | |
1934 | return wpas_wps_er_config(wpa_s, cmd, pin, &ap); | |
1935 | } | |
1cea09a9 JM |
1936 | |
1937 | ||
1938 | #ifdef CONFIG_WPS_NFC | |
1939 | static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | |
1940 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
1941 | { | |
1942 | int ndef; | |
1943 | struct wpabuf *buf; | |
1944 | int res; | |
1945 | char *uuid; | |
1946 | ||
1947 | uuid = os_strchr(cmd, ' '); | |
1948 | if (uuid == NULL) | |
1949 | return -1; | |
1950 | *uuid++ = '\0'; | |
1951 | ||
1952 | if (os_strcmp(cmd, "WPS") == 0) | |
1953 | ndef = 0; | |
1954 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1955 | ndef = 1; | |
1956 | else | |
1957 | return -1; | |
1958 | ||
1959 | buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid); | |
1960 | if (buf == NULL) | |
1961 | return -1; | |
1962 | ||
1963 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1964 | wpabuf_len(buf)); | |
1965 | reply[res++] = '\n'; | |
1966 | reply[res] = '\0'; | |
1967 | ||
1968 | wpabuf_free(buf); | |
1969 | ||
1970 | return res; | |
1971 | } | |
1972 | #endif /* CONFIG_WPS_NFC */ | |
72df2f5f JM |
1973 | #endif /* CONFIG_WPS_ER */ |
1974 | ||
fcc60db4 JM |
1975 | #endif /* CONFIG_WPS */ |
1976 | ||
1977 | ||
11ef8d35 JM |
1978 | #ifdef CONFIG_IBSS_RSN |
1979 | static int wpa_supplicant_ctrl_iface_ibss_rsn( | |
1980 | struct wpa_supplicant *wpa_s, char *addr) | |
1981 | { | |
1982 | u8 peer[ETH_ALEN]; | |
1983 | ||
1984 | if (hwaddr_aton(addr, peer)) { | |
1985 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid " | |
a7b6c422 | 1986 | "address '%s'", addr); |
11ef8d35 JM |
1987 | return -1; |
1988 | } | |
1989 | ||
1990 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR, | |
1991 | MAC2STR(peer)); | |
1992 | ||
1993 | return ibss_rsn_start(wpa_s->ibss_rsn, peer); | |
1994 | } | |
1995 | #endif /* CONFIG_IBSS_RSN */ | |
1996 | ||
1997 | ||
7de5688d DW |
1998 | static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, |
1999 | char *rsp) | |
2000 | { | |
2001 | #ifdef IEEE8021X_EAPOL | |
2002 | char *pos, *id_pos; | |
2003 | int id; | |
2004 | struct wpa_ssid *ssid; | |
2005 | ||
2006 | pos = os_strchr(rsp, '-'); | |
2007 | if (pos == NULL) | |
2008 | return -1; | |
2009 | *pos++ = '\0'; | |
2010 | id_pos = pos; | |
2011 | pos = os_strchr(pos, ':'); | |
2012 | if (pos == NULL) | |
2013 | return -1; | |
2014 | *pos++ = '\0'; | |
2015 | id = atoi(id_pos); | |
2016 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); | |
2017 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
2018 | (u8 *) pos, os_strlen(pos)); | |
2019 | ||
2020 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
2021 | if (ssid == NULL) { | |
2022 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
2023 | "to update", id); | |
2024 | return -1; | |
2025 | } | |
2026 | ||
2027 | return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp, | |
2028 | pos); | |
6fc6879b JM |
2029 | #else /* IEEE8021X_EAPOL */ |
2030 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); | |
2031 | return -1; | |
2032 | #endif /* IEEE8021X_EAPOL */ | |
2033 | } | |
2034 | ||
2035 | ||
2036 | static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, | |
2037 | const char *params, | |
2038 | char *buf, size_t buflen) | |
2039 | { | |
2040 | char *pos, *end, tmp[30]; | |
0bc13468 | 2041 | int res, verbose, wps, ret; |
f9cd147d JM |
2042 | #ifdef CONFIG_HS20 |
2043 | const u8 *hs20; | |
2044 | #endif /* CONFIG_HS20 */ | |
993a8654 JM |
2045 | const u8 *sess_id; |
2046 | size_t sess_id_len; | |
6fc6879b | 2047 | |
a771c07d JM |
2048 | if (os_strcmp(params, "-DRIVER") == 0) |
2049 | return wpa_drv_status(wpa_s, buf, buflen); | |
6fc6879b | 2050 | verbose = os_strcmp(params, "-VERBOSE") == 0; |
0bc13468 | 2051 | wps = os_strcmp(params, "-WPS") == 0; |
6fc6879b JM |
2052 | pos = buf; |
2053 | end = buf + buflen; | |
2054 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { | |
2055 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
2056 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | |
2057 | MAC2STR(wpa_s->bssid)); | |
d85e1fc8 | 2058 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2059 | return pos - buf; |
2060 | pos += ret; | |
b6ebdfbe BP |
2061 | ret = os_snprintf(pos, end - pos, "freq=%u\n", |
2062 | wpa_s->assoc_freq); | |
d85e1fc8 | 2063 | if (os_snprintf_error(end - pos, ret)) |
b6ebdfbe BP |
2064 | return pos - buf; |
2065 | pos += ret; | |
6fc6879b JM |
2066 | if (ssid) { |
2067 | u8 *_ssid = ssid->ssid; | |
2068 | size_t ssid_len = ssid->ssid_len; | |
eaa8eefe | 2069 | u8 ssid_buf[SSID_MAX_LEN]; |
6fc6879b JM |
2070 | if (ssid_len == 0) { |
2071 | int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); | |
2072 | if (_res < 0) | |
2073 | ssid_len = 0; | |
2074 | else | |
2075 | ssid_len = _res; | |
2076 | _ssid = ssid_buf; | |
2077 | } | |
2078 | ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", | |
2079 | wpa_ssid_txt(_ssid, ssid_len), | |
2080 | ssid->id); | |
d85e1fc8 | 2081 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2082 | return pos - buf; |
2083 | pos += ret; | |
2084 | ||
0bc13468 JM |
2085 | if (wps && ssid->passphrase && |
2086 | wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && | |
2087 | (ssid->mode == WPAS_MODE_AP || | |
2088 | ssid->mode == WPAS_MODE_P2P_GO)) { | |
2089 | ret = os_snprintf(pos, end - pos, | |
2090 | "passphrase=%s\n", | |
2091 | ssid->passphrase); | |
d85e1fc8 | 2092 | if (os_snprintf_error(end - pos, ret)) |
0bc13468 JM |
2093 | return pos - buf; |
2094 | pos += ret; | |
2095 | } | |
6fc6879b JM |
2096 | if (ssid->id_str) { |
2097 | ret = os_snprintf(pos, end - pos, | |
2098 | "id_str=%s\n", | |
2099 | ssid->id_str); | |
d85e1fc8 | 2100 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2101 | return pos - buf; |
2102 | pos += ret; | |
2103 | } | |
0e15e529 JM |
2104 | |
2105 | switch (ssid->mode) { | |
d7dcba70 | 2106 | case WPAS_MODE_INFRA: |
0e15e529 JM |
2107 | ret = os_snprintf(pos, end - pos, |
2108 | "mode=station\n"); | |
2109 | break; | |
d7dcba70 | 2110 | case WPAS_MODE_IBSS: |
0e15e529 JM |
2111 | ret = os_snprintf(pos, end - pos, |
2112 | "mode=IBSS\n"); | |
2113 | break; | |
d7dcba70 | 2114 | case WPAS_MODE_AP: |
0e15e529 JM |
2115 | ret = os_snprintf(pos, end - pos, |
2116 | "mode=AP\n"); | |
2117 | break; | |
2c5d725c JM |
2118 | case WPAS_MODE_P2P_GO: |
2119 | ret = os_snprintf(pos, end - pos, | |
2120 | "mode=P2P GO\n"); | |
2121 | break; | |
2122 | case WPAS_MODE_P2P_GROUP_FORMATION: | |
2123 | ret = os_snprintf(pos, end - pos, | |
2124 | "mode=P2P GO - group " | |
2125 | "formation\n"); | |
2126 | break; | |
cee0be73 SB |
2127 | case WPAS_MODE_MESH: |
2128 | ret = os_snprintf(pos, end - pos, | |
2129 | "mode=mesh\n"); | |
2130 | break; | |
0e15e529 JM |
2131 | default: |
2132 | ret = 0; | |
2133 | break; | |
2134 | } | |
1f102d3b | 2135 | if (os_snprintf_error(end - pos, ret)) |
0e15e529 JM |
2136 | return pos - buf; |
2137 | pos += ret; | |
6fc6879b JM |
2138 | } |
2139 | ||
3f8ceff5 JM |
2140 | if (wpa_s->connection_set && |
2141 | (wpa_s->connection_ht || wpa_s->connection_vht || | |
2142 | wpa_s->connection_he)) { | |
2143 | ret = os_snprintf(pos, end - pos, | |
2144 | "wifi_generation=%u\n", | |
2145 | wpa_s->connection_he ? 6 : | |
2146 | (wpa_s->connection_vht ? 5 : 4)); | |
2147 | if (os_snprintf_error(end - pos, ret)) | |
2148 | return pos - buf; | |
2149 | pos += ret; | |
2150 | } | |
2151 | ||
43fb5297 JM |
2152 | #ifdef CONFIG_AP |
2153 | if (wpa_s->ap_iface) { | |
2154 | pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos, | |
2155 | end - pos, | |
2156 | verbose); | |
2157 | } else | |
2158 | #endif /* CONFIG_AP */ | |
6fc6879b JM |
2159 | pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); |
2160 | } | |
afe73100 | 2161 | #ifdef CONFIG_SME |
4954c859 JM |
2162 | #ifdef CONFIG_SAE |
2163 | if (wpa_s->wpa_state >= WPA_ASSOCIATED && | |
e1ae5d74 JM |
2164 | #ifdef CONFIG_AP |
2165 | !wpa_s->ap_iface && | |
2166 | #endif /* CONFIG_AP */ | |
2167 | wpa_s->sme.sae.state == SAE_ACCEPTED) { | |
4954c859 JM |
2168 | ret = os_snprintf(pos, end - pos, "sae_group=%d\n", |
2169 | wpa_s->sme.sae.group); | |
d85e1fc8 | 2170 | if (os_snprintf_error(end - pos, ret)) |
4954c859 JM |
2171 | return pos - buf; |
2172 | pos += ret; | |
2173 | } | |
2174 | #endif /* CONFIG_SAE */ | |
afe73100 | 2175 | #endif /* CONFIG_SME */ |
6fc6879b JM |
2176 | ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", |
2177 | wpa_supplicant_state_txt(wpa_s->wpa_state)); | |
d85e1fc8 | 2178 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2179 | return pos - buf; |
2180 | pos += ret; | |
2181 | ||
2182 | if (wpa_s->l2 && | |
2183 | l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { | |
2184 | ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); | |
d85e1fc8 | 2185 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2186 | return pos - buf; |
2187 | pos += ret; | |
2188 | } | |
2189 | ||
d23bd894 JM |
2190 | #ifdef CONFIG_P2P |
2191 | if (wpa_s->global->p2p) { | |
2192 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR | |
2193 | "\n", MAC2STR(wpa_s->global->p2p_dev_addr)); | |
d85e1fc8 | 2194 | if (os_snprintf_error(end - pos, ret)) |
d23bd894 JM |
2195 | return pos - buf; |
2196 | pos += ret; | |
2197 | } | |
b21e2c84 | 2198 | #endif /* CONFIG_P2P */ |
6d4747a9 JM |
2199 | |
2200 | ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n", | |
2201 | MAC2STR(wpa_s->own_addr)); | |
d85e1fc8 | 2202 | if (os_snprintf_error(end - pos, ret)) |
6d4747a9 JM |
2203 | return pos - buf; |
2204 | pos += ret; | |
d23bd894 | 2205 | |
64855b96 JM |
2206 | #ifdef CONFIG_HS20 |
2207 | if (wpa_s->current_bss && | |
f9cd147d JM |
2208 | (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss, |
2209 | HS20_IE_VENDOR_TYPE)) && | |
4ed34f5a JM |
2210 | wpa_s->wpa_proto == WPA_PROTO_RSN && |
2211 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | |
f9cd147d JM |
2212 | int release = 1; |
2213 | if (hs20[1] >= 5) { | |
2214 | u8 rel_num = (hs20[6] & 0xf0) >> 4; | |
2215 | release = rel_num + 1; | |
2216 | } | |
2217 | ret = os_snprintf(pos, end - pos, "hs20=%d\n", release); | |
d85e1fc8 | 2218 | if (os_snprintf_error(end - pos, ret)) |
64855b96 JM |
2219 | return pos - buf; |
2220 | pos += ret; | |
2221 | } | |
e99b4f3a JM |
2222 | |
2223 | if (wpa_s->current_ssid) { | |
2224 | struct wpa_cred *cred; | |
2225 | char *type; | |
2226 | ||
2227 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { | |
463c8ffb JM |
2228 | size_t i; |
2229 | ||
e99b4f3a JM |
2230 | if (wpa_s->current_ssid->parent_cred != cred) |
2231 | continue; | |
e99b4f3a | 2232 | |
aa26ba68 | 2233 | if (cred->provisioning_sp) { |
463c8ffb | 2234 | ret = os_snprintf(pos, end - pos, |
aa26ba68 JM |
2235 | "provisioning_sp=%s\n", |
2236 | cred->provisioning_sp); | |
d85e1fc8 | 2237 | if (os_snprintf_error(end - pos, ret)) |
463c8ffb JM |
2238 | return pos - buf; |
2239 | pos += ret; | |
2240 | } | |
e99b4f3a | 2241 | |
aa26ba68 JM |
2242 | if (!cred->domain) |
2243 | goto no_domain; | |
2244 | ||
2245 | i = 0; | |
2246 | if (wpa_s->current_bss && wpa_s->current_bss->anqp) { | |
2247 | struct wpabuf *names = | |
2248 | wpa_s->current_bss->anqp->domain_name; | |
2249 | for (i = 0; names && i < cred->num_domain; i++) | |
2250 | { | |
2251 | if (domain_name_list_contains( | |
2252 | names, cred->domain[i], 1)) | |
2253 | break; | |
2254 | } | |
2255 | if (i == cred->num_domain) | |
2256 | i = 0; /* show first entry by default */ | |
2257 | } | |
2258 | ret = os_snprintf(pos, end - pos, "home_sp=%s\n", | |
2259 | cred->domain[i]); | |
d85e1fc8 | 2260 | if (os_snprintf_error(end - pos, ret)) |
aa26ba68 JM |
2261 | return pos - buf; |
2262 | pos += ret; | |
2263 | ||
2264 | no_domain: | |
e99b4f3a JM |
2265 | if (wpa_s->current_bss == NULL || |
2266 | wpa_s->current_bss->anqp == NULL) | |
2267 | res = -1; | |
2268 | else | |
2269 | res = interworking_home_sp_cred( | |
2270 | wpa_s, cred, | |
2271 | wpa_s->current_bss->anqp->domain_name); | |
2272 | if (res > 0) | |
2273 | type = "home"; | |
2274 | else if (res == 0) | |
2275 | type = "roaming"; | |
2276 | else | |
2277 | type = "unknown"; | |
2278 | ||
2279 | ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type); | |
d85e1fc8 | 2280 | if (os_snprintf_error(end - pos, ret)) |
e99b4f3a JM |
2281 | return pos - buf; |
2282 | pos += ret; | |
2283 | ||
2284 | break; | |
2285 | } | |
2286 | } | |
64855b96 JM |
2287 | #endif /* CONFIG_HS20 */ |
2288 | ||
56586197 JM |
2289 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
2290 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
6fc6879b JM |
2291 | res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, |
2292 | verbose); | |
2293 | if (res >= 0) | |
2294 | pos += res; | |
2295 | } | |
2296 | ||
7508c2ad BA |
2297 | #ifdef CONFIG_MACSEC |
2298 | res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos); | |
2299 | if (res > 0) | |
2300 | pos += res; | |
2301 | #endif /* CONFIG_MACSEC */ | |
2302 | ||
993a8654 JM |
2303 | sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len); |
2304 | if (sess_id) { | |
2305 | char *start = pos; | |
2306 | ||
2307 | ret = os_snprintf(pos, end - pos, "eap_session_id="); | |
2308 | if (os_snprintf_error(end - pos, ret)) | |
2309 | return start - buf; | |
2310 | pos += ret; | |
2311 | ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len); | |
2312 | if (ret <= 0) | |
2313 | return start - buf; | |
2314 | pos += ret; | |
2315 | ret = os_snprintf(pos, end - pos, "\n"); | |
2316 | if (os_snprintf_error(end - pos, ret)) | |
2317 | return start - buf; | |
2318 | pos += ret; | |
2319 | } | |
2320 | ||
6fc6879b JM |
2321 | res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); |
2322 | if (res >= 0) | |
2323 | pos += res; | |
2324 | ||
8aaafcee JM |
2325 | #ifdef CONFIG_WPS |
2326 | { | |
2327 | char uuid_str[100]; | |
2328 | uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str)); | |
2329 | ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str); | |
d85e1fc8 | 2330 | if (os_snprintf_error(end - pos, ret)) |
8aaafcee JM |
2331 | return pos - buf; |
2332 | pos += ret; | |
2333 | } | |
2334 | #endif /* CONFIG_WPS */ | |
2335 | ||
d7f038de BP |
2336 | if (wpa_s->ieee80211ac) { |
2337 | ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n"); | |
2338 | if (os_snprintf_error(end - pos, ret)) | |
2339 | return pos - buf; | |
2340 | pos += ret; | |
2341 | } | |
2342 | ||
f6c2b8c3 | 2343 | #ifdef ANDROID |
a6ab82d7 | 2344 | /* |
2345 | * Allow using the STATUS command with default behavior, say for debug, | |
2346 | * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE | |
2347 | * events with STATUS-NO_EVENTS. | |
2348 | */ | |
2349 | if (os_strcmp(params, "-NO_EVENTS")) { | |
2350 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE | |
2351 | "id=%d state=%d BSSID=" MACSTR " SSID=%s", | |
2352 | wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, | |
2353 | wpa_s->wpa_state, | |
2354 | MAC2STR(wpa_s->bssid), | |
2355 | wpa_s->current_ssid && wpa_s->current_ssid->ssid ? | |
2356 | wpa_ssid_txt(wpa_s->current_ssid->ssid, | |
2357 | wpa_s->current_ssid->ssid_len) : ""); | |
2358 | if (wpa_s->wpa_state == WPA_COMPLETED) { | |
2359 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
2360 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED | |
2361 | "- connection to " MACSTR | |
2362 | " completed %s [id=%d id_str=%s]", | |
2363 | MAC2STR(wpa_s->bssid), "(auth)", | |
2364 | ssid ? ssid->id : -1, | |
2365 | ssid && ssid->id_str ? ssid->id_str : ""); | |
2366 | } | |
f6c2b8c3 DS |
2367 | } |
2368 | #endif /* ANDROID */ | |
2369 | ||
6fc6879b JM |
2370 | return pos - buf; |
2371 | } | |
2372 | ||
2373 | ||
2374 | static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, | |
2375 | char *cmd) | |
2376 | { | |
2377 | char *pos; | |
2378 | int id; | |
2379 | struct wpa_ssid *ssid; | |
2380 | u8 bssid[ETH_ALEN]; | |
2381 | ||
2382 | /* cmd: "<network id> <BSSID>" */ | |
2383 | pos = os_strchr(cmd, ' '); | |
2384 | if (pos == NULL) | |
2385 | return -1; | |
2386 | *pos++ = '\0'; | |
2387 | id = atoi(cmd); | |
2388 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); | |
2389 | if (hwaddr_aton(pos, bssid)) { | |
2390 | wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); | |
2391 | return -1; | |
2392 | } | |
2393 | ||
2394 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
2395 | if (ssid == NULL) { | |
2396 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
2397 | "to update", id); | |
2398 | return -1; | |
2399 | } | |
2400 | ||
2401 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); | |
a8e16edc | 2402 | ssid->bssid_set = !is_zero_ether_addr(bssid); |
6fc6879b JM |
2403 | |
2404 | return 0; | |
2405 | } | |
2406 | ||
2407 | ||
9aa10e2b DS |
2408 | static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s, |
2409 | char *cmd, char *buf, | |
2410 | size_t buflen) | |
2411 | { | |
2412 | u8 bssid[ETH_ALEN]; | |
2413 | struct wpa_blacklist *e; | |
2414 | char *pos, *end; | |
2415 | int ret; | |
2416 | ||
2417 | /* cmd: "BLACKLIST [<BSSID>]" */ | |
2418 | if (*cmd == '\0') { | |
2419 | pos = buf; | |
2420 | end = buf + buflen; | |
2421 | e = wpa_s->blacklist; | |
2422 | while (e) { | |
2423 | ret = os_snprintf(pos, end - pos, MACSTR "\n", | |
2424 | MAC2STR(e->bssid)); | |
d85e1fc8 | 2425 | if (os_snprintf_error(end - pos, ret)) |
9aa10e2b DS |
2426 | return pos - buf; |
2427 | pos += ret; | |
2428 | e = e->next; | |
2429 | } | |
2430 | return pos - buf; | |
2431 | } | |
2432 | ||
2433 | cmd++; | |
2434 | if (os_strncmp(cmd, "clear", 5) == 0) { | |
2435 | wpa_blacklist_clear(wpa_s); | |
2436 | os_memcpy(buf, "OK\n", 3); | |
2437 | return 3; | |
2438 | } | |
2439 | ||
2440 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd); | |
2441 | if (hwaddr_aton(cmd, bssid)) { | |
2442 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd); | |
2443 | return -1; | |
2444 | } | |
2445 | ||
2446 | /* | |
2447 | * Add the BSSID twice, so its count will be 2, causing it to be | |
2448 | * skipped when processing scan results. | |
2449 | */ | |
2450 | ret = wpa_blacklist_add(wpa_s, bssid); | |
bd8838a3 | 2451 | if (ret < 0) |
9aa10e2b DS |
2452 | return -1; |
2453 | ret = wpa_blacklist_add(wpa_s, bssid); | |
bd8838a3 | 2454 | if (ret < 0) |
9aa10e2b DS |
2455 | return -1; |
2456 | os_memcpy(buf, "OK\n", 3); | |
2457 | return 3; | |
2458 | } | |
2459 | ||
2460 | ||
0597a5b5 DS |
2461 | static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s, |
2462 | char *cmd, char *buf, | |
2463 | size_t buflen) | |
2464 | { | |
2465 | char *pos, *end, *stamp; | |
2466 | int ret; | |
2467 | ||
0597a5b5 DS |
2468 | /* cmd: "LOG_LEVEL [<level>]" */ |
2469 | if (*cmd == '\0') { | |
2470 | pos = buf; | |
2471 | end = buf + buflen; | |
2472 | ret = os_snprintf(pos, end - pos, "Current level: %s\n" | |
2473 | "Timestamp: %d\n", | |
2474 | debug_level_str(wpa_debug_level), | |
2475 | wpa_debug_timestamp); | |
d85e1fc8 | 2476 | if (os_snprintf_error(end - pos, ret)) |
0597a5b5 DS |
2477 | ret = 0; |
2478 | ||
2479 | return ret; | |
2480 | } | |
2481 | ||
2482 | while (*cmd == ' ') | |
2483 | cmd++; | |
2484 | ||
2485 | stamp = os_strchr(cmd, ' '); | |
2486 | if (stamp) { | |
2487 | *stamp++ = '\0'; | |
2488 | while (*stamp == ' ') { | |
2489 | stamp++; | |
2490 | } | |
2491 | } | |
2492 | ||
137b2939 | 2493 | if (os_strlen(cmd)) { |
0597a5b5 DS |
2494 | int level = str_to_debug_level(cmd); |
2495 | if (level < 0) | |
2496 | return -1; | |
2497 | wpa_debug_level = level; | |
2498 | } | |
2499 | ||
2500 | if (stamp && os_strlen(stamp)) | |
2501 | wpa_debug_timestamp = atoi(stamp); | |
2502 | ||
2503 | os_memcpy(buf, "OK\n", 3); | |
2504 | return 3; | |
2505 | } | |
2506 | ||
2507 | ||
6fc6879b | 2508 | static int wpa_supplicant_ctrl_iface_list_networks( |
90903a77 | 2509 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
6fc6879b | 2510 | { |
f34891a3 | 2511 | char *pos, *end, *prev; |
6fc6879b JM |
2512 | struct wpa_ssid *ssid; |
2513 | int ret; | |
2514 | ||
2515 | pos = buf; | |
2516 | end = buf + buflen; | |
2517 | ret = os_snprintf(pos, end - pos, | |
2518 | "network id / ssid / bssid / flags\n"); | |
d85e1fc8 | 2519 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2520 | return pos - buf; |
2521 | pos += ret; | |
2522 | ||
2523 | ssid = wpa_s->conf->ssid; | |
90903a77 VD |
2524 | |
2525 | /* skip over ssids until we find next one */ | |
2526 | if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) { | |
2527 | int last_id = atoi(cmd + 8); | |
2528 | if (last_id != -1) { | |
2529 | while (ssid != NULL && ssid->id <= last_id) { | |
2530 | ssid = ssid->next; | |
2531 | } | |
2532 | } | |
2533 | } | |
2534 | ||
6fc6879b | 2535 | while (ssid) { |
f34891a3 | 2536 | prev = pos; |
6fc6879b JM |
2537 | ret = os_snprintf(pos, end - pos, "%d\t%s", |
2538 | ssid->id, | |
2539 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | |
d85e1fc8 | 2540 | if (os_snprintf_error(end - pos, ret)) |
f34891a3 | 2541 | return prev - buf; |
6fc6879b JM |
2542 | pos += ret; |
2543 | if (ssid->bssid_set) { | |
2544 | ret = os_snprintf(pos, end - pos, "\t" MACSTR, | |
2545 | MAC2STR(ssid->bssid)); | |
2546 | } else { | |
2547 | ret = os_snprintf(pos, end - pos, "\tany"); | |
2548 | } | |
d85e1fc8 | 2549 | if (os_snprintf_error(end - pos, ret)) |
f34891a3 | 2550 | return prev - buf; |
6fc6879b | 2551 | pos += ret; |
00e5e3d5 | 2552 | ret = os_snprintf(pos, end - pos, "\t%s%s%s%s", |
6fc6879b JM |
2553 | ssid == wpa_s->current_ssid ? |
2554 | "[CURRENT]" : "", | |
4dac0245 | 2555 | ssid->disabled ? "[DISABLED]" : "", |
00e5e3d5 JM |
2556 | ssid->disabled_until.sec ? |
2557 | "[TEMP-DISABLED]" : "", | |
4dac0245 JM |
2558 | ssid->disabled == 2 ? "[P2P-PERSISTENT]" : |
2559 | ""); | |
d85e1fc8 | 2560 | if (os_snprintf_error(end - pos, ret)) |
f34891a3 | 2561 | return prev - buf; |
6fc6879b JM |
2562 | pos += ret; |
2563 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 2564 | if (os_snprintf_error(end - pos, ret)) |
f34891a3 | 2565 | return prev - buf; |
6fc6879b JM |
2566 | pos += ret; |
2567 | ||
2568 | ssid = ssid->next; | |
2569 | } | |
2570 | ||
2571 | return pos - buf; | |
2572 | } | |
2573 | ||
2574 | ||
2575 | static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) | |
2576 | { | |
0282a8c4 | 2577 | int ret; |
6fc6879b | 2578 | ret = os_snprintf(pos, end - pos, "-"); |
d85e1fc8 | 2579 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2580 | return pos; |
2581 | pos += ret; | |
0282a8c4 JM |
2582 | ret = wpa_write_ciphers(pos, end, cipher, "+"); |
2583 | if (ret < 0) | |
2584 | return pos; | |
2585 | pos += ret; | |
6fc6879b JM |
2586 | return pos; |
2587 | } | |
2588 | ||
2589 | ||
2590 | static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, | |
2591 | const u8 *ie, size_t ie_len) | |
2592 | { | |
2593 | struct wpa_ie_data data; | |
ea3b8c1d JM |
2594 | char *start; |
2595 | int ret; | |
6fc6879b JM |
2596 | |
2597 | ret = os_snprintf(pos, end - pos, "[%s-", proto); | |
d85e1fc8 | 2598 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2599 | return pos; |
2600 | pos += ret; | |
2601 | ||
2602 | if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { | |
2603 | ret = os_snprintf(pos, end - pos, "?]"); | |
d85e1fc8 | 2604 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2605 | return pos; |
2606 | pos += ret; | |
2607 | return pos; | |
2608 | } | |
2609 | ||
ea3b8c1d | 2610 | start = pos; |
6fc6879b | 2611 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { |
ea3b8c1d JM |
2612 | ret = os_snprintf(pos, end - pos, "%sEAP", |
2613 | pos == start ? "" : "+"); | |
d85e1fc8 | 2614 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2615 | return pos; |
2616 | pos += ret; | |
6fc6879b JM |
2617 | } |
2618 | if (data.key_mgmt & WPA_KEY_MGMT_PSK) { | |
ea3b8c1d JM |
2619 | ret = os_snprintf(pos, end - pos, "%sPSK", |
2620 | pos == start ? "" : "+"); | |
d85e1fc8 | 2621 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2622 | return pos; |
2623 | pos += ret; | |
6fc6879b JM |
2624 | } |
2625 | if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { | |
ea3b8c1d JM |
2626 | ret = os_snprintf(pos, end - pos, "%sNone", |
2627 | pos == start ? "" : "+"); | |
d85e1fc8 | 2628 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2629 | return pos; |
2630 | pos += ret; | |
6fc6879b | 2631 | } |
be6b29f6 JA |
2632 | if (data.key_mgmt & WPA_KEY_MGMT_SAE) { |
2633 | ret = os_snprintf(pos, end - pos, "%sSAE", | |
2634 | pos == start ? "" : "+"); | |
d85e1fc8 | 2635 | if (os_snprintf_error(end - pos, ret)) |
be6b29f6 JA |
2636 | return pos; |
2637 | pos += ret; | |
2638 | } | |
6fc6879b JM |
2639 | #ifdef CONFIG_IEEE80211R |
2640 | if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { | |
2641 | ret = os_snprintf(pos, end - pos, "%sFT/EAP", | |
ea3b8c1d | 2642 | pos == start ? "" : "+"); |
d85e1fc8 | 2643 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2644 | return pos; |
2645 | pos += ret; | |
6fc6879b JM |
2646 | } |
2647 | if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { | |
2648 | ret = os_snprintf(pos, end - pos, "%sFT/PSK", | |
ea3b8c1d | 2649 | pos == start ? "" : "+"); |
d85e1fc8 | 2650 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2651 | return pos; |
2652 | pos += ret; | |
6fc6879b | 2653 | } |
be6b29f6 JA |
2654 | if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) { |
2655 | ret = os_snprintf(pos, end - pos, "%sFT/SAE", | |
2656 | pos == start ? "" : "+"); | |
d85e1fc8 | 2657 | if (os_snprintf_error(end - pos, ret)) |
be6b29f6 JA |
2658 | return pos; |
2659 | pos += ret; | |
2660 | } | |
6fc6879b | 2661 | #endif /* CONFIG_IEEE80211R */ |
56586197 JM |
2662 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { |
2663 | ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", | |
ea3b8c1d | 2664 | pos == start ? "" : "+"); |
d85e1fc8 | 2665 | if (os_snprintf_error(end - pos, ret)) |
56586197 JM |
2666 | return pos; |
2667 | pos += ret; | |
56586197 JM |
2668 | } |
2669 | if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { | |
2670 | ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", | |
ea3b8c1d | 2671 | pos == start ? "" : "+"); |
d85e1fc8 | 2672 | if (os_snprintf_error(end - pos, ret)) |
56586197 JM |
2673 | return pos; |
2674 | pos += ret; | |
56586197 | 2675 | } |
6fc6879b | 2676 | |
5e3b5197 | 2677 | #ifdef CONFIG_SUITEB |
666497c8 JM |
2678 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
2679 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B", | |
2680 | pos == start ? "" : "+"); | |
d85e1fc8 | 2681 | if (os_snprintf_error(end - pos, ret)) |
666497c8 JM |
2682 | return pos; |
2683 | pos += ret; | |
2684 | } | |
5e3b5197 JM |
2685 | #endif /* CONFIG_SUITEB */ |
2686 | ||
2687 | #ifdef CONFIG_SUITEB192 | |
2688 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { | |
2689 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192", | |
2690 | pos == start ? "" : "+"); | |
2691 | if (os_snprintf_error(end - pos, ret)) | |
2692 | return pos; | |
2693 | pos += ret; | |
2694 | } | |
2695 | #endif /* CONFIG_SUITEB192 */ | |
666497c8 | 2696 | |
7147a834 JM |
2697 | #ifdef CONFIG_FILS |
2698 | if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) { | |
2699 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA256", | |
2700 | pos == start ? "" : "+"); | |
2701 | if (os_snprintf_error(end - pos, ret)) | |
2702 | return pos; | |
2703 | pos += ret; | |
2704 | } | |
2705 | if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) { | |
2706 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA384", | |
2707 | pos == start ? "" : "+"); | |
2708 | if (os_snprintf_error(end - pos, ret)) | |
2709 | return pos; | |
2710 | pos += ret; | |
2711 | } | |
2712 | #ifdef CONFIG_IEEE80211R | |
2713 | if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) { | |
2714 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256", | |
2715 | pos == start ? "" : "+"); | |
2716 | if (os_snprintf_error(end - pos, ret)) | |
2717 | return pos; | |
2718 | pos += ret; | |
2719 | } | |
2720 | if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) { | |
2721 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384", | |
2722 | pos == start ? "" : "+"); | |
2723 | if (os_snprintf_error(end - pos, ret)) | |
2724 | return pos; | |
2725 | pos += ret; | |
2726 | } | |
2727 | #endif /* CONFIG_IEEE80211R */ | |
2728 | #endif /* CONFIG_FILS */ | |
2729 | ||
a1ea1b45 JM |
2730 | #ifdef CONFIG_OWE |
2731 | if (data.key_mgmt & WPA_KEY_MGMT_OWE) { | |
2732 | ret = os_snprintf(pos, end - pos, "%sOWE", | |
2733 | pos == start ? "" : "+"); | |
2734 | if (os_snprintf_error(end - pos, ret)) | |
2735 | return pos; | |
2736 | pos += ret; | |
2737 | } | |
2738 | #endif /* CONFIG_OWE */ | |
2739 | ||
567da5bb JM |
2740 | #ifdef CONFIG_DPP |
2741 | if (data.key_mgmt & WPA_KEY_MGMT_DPP) { | |
2742 | ret = os_snprintf(pos, end - pos, "%sDPP", | |
2743 | pos == start ? "" : "+"); | |
2744 | if (os_snprintf_error(end - pos, ret)) | |
2745 | return pos; | |
2746 | pos += ret; | |
2747 | } | |
2748 | #endif /* CONFIG_DPP */ | |
2749 | ||
0f8385e6 BG |
2750 | if (data.key_mgmt & WPA_KEY_MGMT_OSEN) { |
2751 | ret = os_snprintf(pos, end - pos, "%sOSEN", | |
2752 | pos == start ? "" : "+"); | |
2753 | if (os_snprintf_error(end - pos, ret)) | |
2754 | return pos; | |
2755 | pos += ret; | |
2756 | } | |
2757 | ||
6fc6879b JM |
2758 | pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); |
2759 | ||
2760 | if (data.capabilities & WPA_CAPABILITY_PREAUTH) { | |
2761 | ret = os_snprintf(pos, end - pos, "-preauth"); | |
d85e1fc8 | 2762 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2763 | return pos; |
2764 | pos += ret; | |
2765 | } | |
2766 | ||
2767 | ret = os_snprintf(pos, end - pos, "]"); | |
d85e1fc8 | 2768 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2769 | return pos; |
2770 | pos += ret; | |
2771 | ||
2772 | return pos; | |
2773 | } | |
2774 | ||
3a068632 | 2775 | |
eef7d7a1 | 2776 | #ifdef CONFIG_WPS |
31fcea93 JM |
2777 | static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, |
2778 | char *pos, char *end, | |
3a068632 JM |
2779 | struct wpabuf *wps_ie) |
2780 | { | |
eef7d7a1 JM |
2781 | int ret; |
2782 | const char *txt; | |
2783 | ||
eef7d7a1 JM |
2784 | if (wps_ie == NULL) |
2785 | return pos; | |
eef7d7a1 JM |
2786 | if (wps_is_selected_pbc_registrar(wps_ie)) |
2787 | txt = "[WPS-PBC]"; | |
31fcea93 JM |
2788 | else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) |
2789 | txt = "[WPS-AUTH]"; | |
eef7d7a1 JM |
2790 | else if (wps_is_selected_pin_registrar(wps_ie)) |
2791 | txt = "[WPS-PIN]"; | |
2792 | else | |
2793 | txt = "[WPS]"; | |
2794 | ||
2795 | ret = os_snprintf(pos, end - pos, "%s", txt); | |
a80ba67a | 2796 | if (!os_snprintf_error(end - pos, ret)) |
eef7d7a1 JM |
2797 | pos += ret; |
2798 | wpabuf_free(wps_ie); | |
3a068632 JM |
2799 | return pos; |
2800 | } | |
2801 | #endif /* CONFIG_WPS */ | |
2802 | ||
2803 | ||
31fcea93 JM |
2804 | static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, |
2805 | char *pos, char *end, | |
16b71ac2 | 2806 | const struct wpa_bss *bss) |
3a068632 JM |
2807 | { |
2808 | #ifdef CONFIG_WPS | |
2809 | struct wpabuf *wps_ie; | |
2810 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); | |
31fcea93 | 2811 | return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); |
3a068632 | 2812 | #else /* CONFIG_WPS */ |
eef7d7a1 | 2813 | return pos; |
3a068632 | 2814 | #endif /* CONFIG_WPS */ |
eef7d7a1 JM |
2815 | } |
2816 | ||
6fc6879b JM |
2817 | |
2818 | /* Format one result on one text line into a buffer. */ | |
2819 | static int wpa_supplicant_ctrl_iface_scan_result( | |
31fcea93 | 2820 | struct wpa_supplicant *wpa_s, |
16b71ac2 | 2821 | const struct wpa_bss *bss, char *buf, size_t buflen) |
6fc6879b JM |
2822 | { |
2823 | char *pos, *end; | |
2824 | int ret; | |
e8b96490 | 2825 | const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe; |
0c6b310e | 2826 | |
638d9456 | 2827 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
0c6b310e | 2828 | p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); |
bb50ae43 JM |
2829 | if (!p2p) |
2830 | p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE); | |
0c6b310e JM |
2831 | if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && |
2832 | os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == | |
2833 | 0) | |
2834 | return 0; /* Do not show P2P listen discovery results here */ | |
6fc6879b JM |
2835 | |
2836 | pos = buf; | |
2837 | end = buf + buflen; | |
2838 | ||
2839 | ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", | |
16b71ac2 | 2840 | MAC2STR(bss->bssid), bss->freq, bss->level); |
d85e1fc8 | 2841 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2842 | return -1; |
6fc6879b | 2843 | pos += ret; |
16b71ac2 | 2844 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
6fc6879b JM |
2845 | if (ie) |
2846 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); | |
16b71ac2 | 2847 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
638d9456 JA |
2848 | if (ie2) { |
2849 | pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2", | |
2850 | ie2, 2 + ie2[1]); | |
2851 | } | |
0f8385e6 BG |
2852 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
2853 | if (osen_ie) | |
2854 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", | |
2855 | osen_ie, 2 + osen_ie[1]); | |
e8b96490 JM |
2856 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
2857 | if (owe) { | |
2858 | ret = os_snprintf(pos, end - pos, | |
2859 | ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]"); | |
2860 | if (os_snprintf_error(end - pos, ret)) | |
2861 | return -1; | |
2862 | pos += ret; | |
2863 | } | |
31fcea93 | 2864 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
0f8385e6 | 2865 | if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) { |
6fc6879b | 2866 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
d85e1fc8 | 2867 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2868 | return -1; |
6fc6879b JM |
2869 | pos += ret; |
2870 | } | |
638d9456 JA |
2871 | if (mesh) { |
2872 | ret = os_snprintf(pos, end - pos, "[MESH]"); | |
d85e1fc8 | 2873 | if (os_snprintf_error(end - pos, ret)) |
638d9456 JA |
2874 | return -1; |
2875 | pos += ret; | |
2876 | } | |
e403ba85 BS |
2877 | if (bss_is_dmg(bss)) { |
2878 | const char *s; | |
2879 | ret = os_snprintf(pos, end - pos, "[DMG]"); | |
d85e1fc8 | 2880 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2881 | return -1; |
6fc6879b | 2882 | pos += ret; |
e403ba85 BS |
2883 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
2884 | case IEEE80211_CAP_DMG_IBSS: | |
2885 | s = "[IBSS]"; | |
2886 | break; | |
2887 | case IEEE80211_CAP_DMG_AP: | |
2888 | s = "[ESS]"; | |
2889 | break; | |
2890 | case IEEE80211_CAP_DMG_PBSS: | |
2891 | s = "[PBSS]"; | |
2892 | break; | |
2893 | default: | |
2894 | s = ""; | |
2895 | break; | |
2896 | } | |
2897 | ret = os_snprintf(pos, end - pos, "%s", s); | |
d85e1fc8 | 2898 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2899 | return -1; |
bd1af96a | 2900 | pos += ret; |
e403ba85 BS |
2901 | } else { |
2902 | if (bss->caps & IEEE80211_CAP_IBSS) { | |
2903 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | |
d85e1fc8 | 2904 | if (os_snprintf_error(end - pos, ret)) |
e403ba85 BS |
2905 | return -1; |
2906 | pos += ret; | |
2907 | } | |
2908 | if (bss->caps & IEEE80211_CAP_ESS) { | |
2909 | ret = os_snprintf(pos, end - pos, "[ESS]"); | |
d85e1fc8 | 2910 | if (os_snprintf_error(end - pos, ret)) |
e403ba85 BS |
2911 | return -1; |
2912 | pos += ret; | |
2913 | } | |
bd1af96a | 2914 | } |
0c6b310e JM |
2915 | if (p2p) { |
2916 | ret = os_snprintf(pos, end - pos, "[P2P]"); | |
d85e1fc8 | 2917 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2918 | return -1; |
0c6b310e JM |
2919 | pos += ret; |
2920 | } | |
64855b96 | 2921 | #ifdef CONFIG_HS20 |
4ed34f5a | 2922 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) { |
64855b96 | 2923 | ret = os_snprintf(pos, end - pos, "[HS20]"); |
d85e1fc8 | 2924 | if (os_snprintf_error(end - pos, ret)) |
64855b96 JM |
2925 | return -1; |
2926 | pos += ret; | |
2927 | } | |
2928 | #endif /* CONFIG_HS20 */ | |
7147a834 JM |
2929 | #ifdef CONFIG_FILS |
2930 | if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) { | |
2931 | ret = os_snprintf(pos, end - pos, "[FILS]"); | |
2932 | if (os_snprintf_error(end - pos, ret)) | |
2933 | return -1; | |
2934 | pos += ret; | |
2935 | } | |
2936 | #endif /* CONFIG_FILS */ | |
55de4d4b AN |
2937 | #ifdef CONFIG_FST |
2938 | if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) { | |
2939 | ret = os_snprintf(pos, end - pos, "[FST]"); | |
2940 | if (os_snprintf_error(end - pos, ret)) | |
2941 | return -1; | |
2942 | pos += ret; | |
2943 | } | |
2944 | #endif /* CONFIG_FST */ | |
ed87f6a8 | 2945 | if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) { |
1f2c42cc JW |
2946 | ret = os_snprintf(pos, end - pos, "[UTF-8]"); |
2947 | if (os_snprintf_error(end - pos, ret)) | |
2948 | return -1; | |
2949 | pos += ret; | |
2950 | } | |
6fc6879b | 2951 | |
6fc6879b | 2952 | ret = os_snprintf(pos, end - pos, "\t%s", |
16b71ac2 | 2953 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
d85e1fc8 | 2954 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2955 | return -1; |
6fc6879b JM |
2956 | pos += ret; |
2957 | ||
2958 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 2959 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2960 | return -1; |
6fc6879b JM |
2961 | pos += ret; |
2962 | ||
2963 | return pos - buf; | |
2964 | } | |
2965 | ||
2966 | ||
2967 | static int wpa_supplicant_ctrl_iface_scan_results( | |
2968 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
2969 | { | |
2970 | char *pos, *end; | |
16b71ac2 | 2971 | struct wpa_bss *bss; |
6fc6879b | 2972 | int ret; |
6fc6879b JM |
2973 | |
2974 | pos = buf; | |
2975 | end = buf + buflen; | |
2976 | ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " | |
2977 | "flags / ssid\n"); | |
d85e1fc8 | 2978 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2979 | return pos - buf; |
2980 | pos += ret; | |
2981 | ||
16b71ac2 | 2982 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
31fcea93 | 2983 | ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, |
6fc6879b JM |
2984 | end - pos); |
2985 | if (ret < 0 || ret >= end - pos) | |
2986 | return pos - buf; | |
2987 | pos += ret; | |
2988 | } | |
2989 | ||
2990 | return pos - buf; | |
2991 | } | |
2992 | ||
2993 | ||
603a3f34 JL |
2994 | #ifdef CONFIG_MESH |
2995 | ||
5b78493f MH |
2996 | static int wpa_supplicant_ctrl_iface_mesh_interface_add( |
2997 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
2998 | { | |
2999 | char *pos, ifname[IFNAMSIZ + 1]; | |
3000 | ||
3001 | ifname[0] = '\0'; | |
3002 | ||
3003 | pos = os_strstr(cmd, "ifname="); | |
3004 | if (pos) { | |
3005 | pos += 7; | |
3006 | os_strlcpy(ifname, pos, sizeof(ifname)); | |
3007 | } | |
3008 | ||
3009 | if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0) | |
3010 | return -1; | |
3011 | ||
3012 | os_strlcpy(reply, ifname, max_len); | |
3013 | return os_strlen(ifname); | |
3014 | } | |
3015 | ||
3016 | ||
603a3f34 JL |
3017 | static int wpa_supplicant_ctrl_iface_mesh_group_add( |
3018 | struct wpa_supplicant *wpa_s, char *cmd) | |
3019 | { | |
3020 | int id; | |
3021 | struct wpa_ssid *ssid; | |
3022 | ||
3023 | id = atoi(cmd); | |
3024 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id); | |
3025 | ||
3026 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
3027 | if (ssid == NULL) { | |
3028 | wpa_printf(MSG_DEBUG, | |
3029 | "CTRL_IFACE: Could not find network id=%d", id); | |
3030 | return -1; | |
3031 | } | |
3032 | if (ssid->mode != WPAS_MODE_MESH) { | |
3033 | wpa_printf(MSG_DEBUG, | |
3034 | "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network"); | |
3035 | return -1; | |
3036 | } | |
0c6099f3 MH |
3037 | if (ssid->key_mgmt != WPA_KEY_MGMT_NONE && |
3038 | ssid->key_mgmt != WPA_KEY_MGMT_SAE) { | |
3039 | wpa_printf(MSG_ERROR, | |
3040 | "CTRL_IFACE: key_mgmt for mesh network should be open or SAE"); | |
3041 | return -1; | |
3042 | } | |
603a3f34 JL |
3043 | |
3044 | /* | |
3045 | * TODO: If necessary write our own group_add function, | |
3046 | * for now we can reuse select_network | |
3047 | */ | |
3048 | wpa_supplicant_select_network(wpa_s, ssid); | |
3049 | ||
3050 | return 0; | |
3051 | } | |
3052 | ||
3053 | ||
3054 | static int wpa_supplicant_ctrl_iface_mesh_group_remove( | |
3055 | struct wpa_supplicant *wpa_s, char *cmd) | |
3056 | { | |
5b78493f MH |
3057 | struct wpa_supplicant *orig; |
3058 | struct wpa_global *global; | |
3059 | int found = 0; | |
3060 | ||
3061 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd); | |
3062 | ||
3063 | global = wpa_s->global; | |
3064 | orig = wpa_s; | |
3065 | ||
3066 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
3067 | if (os_strcmp(wpa_s->ifname, cmd) == 0) { | |
3068 | found = 1; | |
3069 | break; | |
3070 | } | |
3071 | } | |
3072 | if (!found) { | |
3073 | wpa_printf(MSG_ERROR, | |
3074 | "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found", | |
603a3f34 JL |
3075 | cmd); |
3076 | return -1; | |
3077 | } | |
5b78493f MH |
3078 | if (wpa_s->mesh_if_created && wpa_s == orig) { |
3079 | wpa_printf(MSG_ERROR, | |
3080 | "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself"); | |
3081 | return -1; | |
3082 | } | |
603a3f34 JL |
3083 | |
3084 | wpa_s->reassociate = 0; | |
3085 | wpa_s->disconnected = 1; | |
3086 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
3087 | wpa_supplicant_cancel_scan(wpa_s); | |
3088 | ||
3089 | /* | |
3090 | * TODO: If necessary write our own group_remove function, | |
3091 | * for now we can reuse deauthenticate | |
3092 | */ | |
3093 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
3094 | ||
5b78493f MH |
3095 | if (wpa_s->mesh_if_created) |
3096 | wpa_supplicant_remove_iface(global, wpa_s, 0); | |
3097 | ||
603a3f34 JL |
3098 | return 0; |
3099 | } | |
3100 | ||
e174ef34 MH |
3101 | |
3102 | static int wpa_supplicant_ctrl_iface_mesh_peer_remove( | |
3103 | struct wpa_supplicant *wpa_s, char *cmd) | |
3104 | { | |
3105 | u8 addr[ETH_ALEN]; | |
3106 | ||
3107 | if (hwaddr_aton(cmd, addr) < 0) | |
3108 | return -1; | |
3109 | ||
3110 | return wpas_mesh_peer_remove(wpa_s, addr); | |
3111 | } | |
3112 | ||
2604edbf MH |
3113 | |
3114 | static int wpa_supplicant_ctrl_iface_mesh_peer_add( | |
3115 | struct wpa_supplicant *wpa_s, char *cmd) | |
3116 | { | |
3117 | u8 addr[ETH_ALEN]; | |
9f2cf23e MH |
3118 | int duration; |
3119 | char *pos; | |
3120 | ||
3121 | pos = os_strstr(cmd, " duration="); | |
3122 | if (pos) { | |
3123 | *pos = '\0'; | |
3124 | duration = atoi(pos + 10); | |
3125 | } else { | |
3126 | duration = -1; | |
3127 | } | |
2604edbf MH |
3128 | |
3129 | if (hwaddr_aton(cmd, addr)) | |
3130 | return -1; | |
3131 | ||
9f2cf23e | 3132 | return wpas_mesh_peer_add(wpa_s, addr, duration); |
2604edbf MH |
3133 | } |
3134 | ||
7ace4328 PKC |
3135 | |
3136 | static int wpa_supplicant_ctrl_iface_mesh_link_probe( | |
3137 | struct wpa_supplicant *wpa_s, char *cmd) | |
3138 | { | |
3139 | struct ether_header *eth; | |
3140 | u8 addr[ETH_ALEN]; | |
3141 | u8 *buf; | |
3142 | char *pos; | |
3143 | size_t payload_len = 0, len; | |
3144 | int ret = -1; | |
3145 | ||
3146 | if (hwaddr_aton(cmd, addr)) | |
3147 | return -1; | |
3148 | ||
3149 | pos = os_strstr(cmd, " payload="); | |
3150 | if (pos) { | |
3151 | pos = pos + 9; | |
3152 | payload_len = os_strlen(pos); | |
3153 | if (payload_len & 1) | |
3154 | return -1; | |
3155 | ||
3156 | payload_len /= 2; | |
3157 | } | |
3158 | ||
3159 | len = ETH_HLEN + payload_len; | |
3160 | buf = os_malloc(len); | |
3161 | if (!buf) | |
3162 | return -1; | |
3163 | ||
3164 | eth = (struct ether_header *) buf; | |
3165 | os_memcpy(eth->ether_dhost, addr, ETH_ALEN); | |
3166 | os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN); | |
3167 | eth->ether_type = htons(ETH_P_802_3); | |
3168 | ||
3169 | if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0) | |
3170 | goto fail; | |
3171 | ||
3172 | ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len); | |
3173 | fail: | |
3174 | os_free(buf); | |
3175 | return -ret; | |
3176 | } | |
3177 | ||
603a3f34 JL |
3178 | #endif /* CONFIG_MESH */ |
3179 | ||
3180 | ||
6fc6879b JM |
3181 | static int wpa_supplicant_ctrl_iface_select_network( |
3182 | struct wpa_supplicant *wpa_s, char *cmd) | |
3183 | { | |
3184 | int id; | |
3185 | struct wpa_ssid *ssid; | |
204c9ac4 | 3186 | char *pos; |
6fc6879b JM |
3187 | |
3188 | /* cmd: "<network id>" or "any" */ | |
204c9ac4 | 3189 | if (os_strncmp(cmd, "any", 3) == 0) { |
6fc6879b | 3190 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); |
86b89452 WS |
3191 | ssid = NULL; |
3192 | } else { | |
3193 | id = atoi(cmd); | |
3194 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); | |
6fc6879b | 3195 | |
86b89452 WS |
3196 | ssid = wpa_config_get_network(wpa_s->conf, id); |
3197 | if (ssid == NULL) { | |
3198 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
3199 | "network id=%d", id); | |
3200 | return -1; | |
3201 | } | |
4dac0245 JM |
3202 | if (ssid->disabled == 2) { |
3203 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
3204 | "SELECT_NETWORK with persistent P2P group"); | |
3205 | return -1; | |
3206 | } | |
6fc6879b JM |
3207 | } |
3208 | ||
204c9ac4 DS |
3209 | pos = os_strstr(cmd, " freq="); |
3210 | if (pos) { | |
3211 | int *freqs = freq_range_to_channel_list(wpa_s, pos + 6); | |
3212 | if (freqs) { | |
88a44755 JM |
3213 | os_free(wpa_s->select_network_scan_freqs); |
3214 | wpa_s->select_network_scan_freqs = freqs; | |
204c9ac4 DS |
3215 | } |
3216 | } | |
3217 | ||
dfaf11d6 JM |
3218 | wpa_s->scan_min_time.sec = 0; |
3219 | wpa_s->scan_min_time.usec = 0; | |
86b89452 | 3220 | wpa_supplicant_select_network(wpa_s, ssid); |
6fc6879b JM |
3221 | |
3222 | return 0; | |
3223 | } | |
3224 | ||
3225 | ||
3226 | static int wpa_supplicant_ctrl_iface_enable_network( | |
3227 | struct wpa_supplicant *wpa_s, char *cmd) | |
3228 | { | |
3229 | int id; | |
3230 | struct wpa_ssid *ssid; | |
3231 | ||
3232 | /* cmd: "<network id>" or "all" */ | |
3233 | if (os_strcmp(cmd, "all") == 0) { | |
3234 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); | |
86b89452 WS |
3235 | ssid = NULL; |
3236 | } else { | |
3237 | id = atoi(cmd); | |
3238 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); | |
6fc6879b | 3239 | |
86b89452 WS |
3240 | ssid = wpa_config_get_network(wpa_s->conf, id); |
3241 | if (ssid == NULL) { | |
3242 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
3243 | "network id=%d", id); | |
3244 | return -1; | |
3245 | } | |
4dac0245 JM |
3246 | if (ssid->disabled == 2) { |
3247 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
3248 | "ENABLE_NETWORK with persistent P2P group"); | |
3249 | return -1; | |
3250 | } | |
84c78f95 JM |
3251 | |
3252 | if (os_strstr(cmd, " no-connect")) { | |
3253 | ssid->disabled = 0; | |
3254 | return 0; | |
3255 | } | |
6fc6879b | 3256 | } |
dfaf11d6 JM |
3257 | wpa_s->scan_min_time.sec = 0; |
3258 | wpa_s->scan_min_time.usec = 0; | |
86b89452 | 3259 | wpa_supplicant_enable_network(wpa_s, ssid); |
6fc6879b JM |
3260 | |
3261 | return 0; | |
3262 | } | |
3263 | ||
3264 | ||
3265 | static int wpa_supplicant_ctrl_iface_disable_network( | |
3266 | struct wpa_supplicant *wpa_s, char *cmd) | |
3267 | { | |
3268 | int id; | |
3269 | struct wpa_ssid *ssid; | |
3270 | ||
3271 | /* cmd: "<network id>" or "all" */ | |
3272 | if (os_strcmp(cmd, "all") == 0) { | |
3273 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); | |
86b89452 WS |
3274 | ssid = NULL; |
3275 | } else { | |
3276 | id = atoi(cmd); | |
3277 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); | |
6fc6879b | 3278 | |
86b89452 WS |
3279 | ssid = wpa_config_get_network(wpa_s->conf, id); |
3280 | if (ssid == NULL) { | |
3281 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
3282 | "network id=%d", id); | |
3283 | return -1; | |
3284 | } | |
4dac0245 JM |
3285 | if (ssid->disabled == 2) { |
3286 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
3287 | "DISABLE_NETWORK with persistent P2P " | |
3288 | "group"); | |
3289 | return -1; | |
3290 | } | |
6fc6879b | 3291 | } |
86b89452 | 3292 | wpa_supplicant_disable_network(wpa_s, ssid); |
6fc6879b JM |
3293 | |
3294 | return 0; | |
3295 | } | |
3296 | ||
3297 | ||
3298 | static int wpa_supplicant_ctrl_iface_add_network( | |
3299 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
3300 | { | |
3301 | struct wpa_ssid *ssid; | |
3302 | int ret; | |
3303 | ||
3304 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); | |
3305 | ||
d015bb05 | 3306 | ssid = wpa_supplicant_add_network(wpa_s); |
6fc6879b JM |
3307 | if (ssid == NULL) |
3308 | return -1; | |
8bac466b | 3309 | |
6fc6879b | 3310 | ret = os_snprintf(buf, buflen, "%d\n", ssid->id); |
d85e1fc8 | 3311 | if (os_snprintf_error(buflen, ret)) |
6fc6879b JM |
3312 | return -1; |
3313 | return ret; | |
3314 | } | |
3315 | ||
3316 | ||
3317 | static int wpa_supplicant_ctrl_iface_remove_network( | |
3318 | struct wpa_supplicant *wpa_s, char *cmd) | |
3319 | { | |
3320 | int id; | |
3321 | struct wpa_ssid *ssid; | |
d015bb05 | 3322 | int result; |
6fc6879b JM |
3323 | |
3324 | /* cmd: "<network id>" or "all" */ | |
3325 | if (os_strcmp(cmd, "all") == 0) { | |
3326 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); | |
725fc39e DS |
3327 | if (wpa_s->sched_scanning) |
3328 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
3329 | ||
d8a790b9 | 3330 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
6fc6879b | 3331 | if (wpa_s->current_ssid) { |
83df8149 JM |
3332 | #ifdef CONFIG_SME |
3333 | wpa_s->sme.prev_bssid_set = 0; | |
3334 | #endif /* CONFIG_SME */ | |
20a0b03d JM |
3335 | wpa_sm_set_config(wpa_s->wpa, NULL); |
3336 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | |
e66bcedd JM |
3337 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
3338 | wpa_s->own_disconnect_req = 1; | |
07783eaa JM |
3339 | wpa_supplicant_deauthenticate( |
3340 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
6fc6879b | 3341 | } |
391f4925 JK |
3342 | ssid = wpa_s->conf->ssid; |
3343 | while (ssid) { | |
3344 | struct wpa_ssid *remove_ssid = ssid; | |
3345 | id = ssid->id; | |
3346 | ssid = ssid->next; | |
c267753b JM |
3347 | if (wpa_s->last_ssid == remove_ssid) |
3348 | wpa_s->last_ssid = NULL; | |
391f4925 JK |
3349 | wpas_notify_network_removed(wpa_s, remove_ssid); |
3350 | wpa_config_remove_network(wpa_s->conf, id); | |
3351 | } | |
6fc6879b JM |
3352 | return 0; |
3353 | } | |
3354 | ||
3355 | id = atoi(cmd); | |
3356 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); | |
3357 | ||
d015bb05 RP |
3358 | result = wpa_supplicant_remove_network(wpa_s, id); |
3359 | if (result == -1) { | |
6fc6879b JM |
3360 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
3361 | "id=%d", id); | |
3362 | return -1; | |
3363 | } | |
d015bb05 | 3364 | if (result == -2) { |
59ff6653 DG |
3365 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the " |
3366 | "network id=%d", id); | |
3367 | return -1; | |
3368 | } | |
6fc6879b JM |
3369 | return 0; |
3370 | } | |
3371 | ||
3372 | ||
1c330a2f DS |
3373 | static int wpa_supplicant_ctrl_iface_update_network( |
3374 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, | |
3375 | char *name, char *value) | |
3376 | { | |
5cd317d3 BKB |
3377 | int ret; |
3378 | ||
3379 | ret = wpa_config_set(ssid, name, value, 0); | |
3380 | if (ret < 0) { | |
1c330a2f DS |
3381 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " |
3382 | "variable '%s'", name); | |
3383 | return -1; | |
3384 | } | |
5cd317d3 BKB |
3385 | if (ret == 1) |
3386 | return 0; /* No change to the previously configured value */ | |
1c330a2f DS |
3387 | |
3388 | if (os_strcmp(name, "bssid") != 0 && | |
34ee12c5 | 3389 | os_strcmp(name, "bssid_hint") != 0 && |
c3dc68e8 | 3390 | os_strcmp(name, "priority") != 0) { |
1c330a2f DS |
3391 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
3392 | ||
c3dc68e8 JM |
3393 | if (wpa_s->current_ssid == ssid || |
3394 | wpa_s->current_ssid == NULL) { | |
3395 | /* | |
3396 | * Invalidate the EAP session cache if anything in the | |
3397 | * current or previously used configuration changes. | |
3398 | */ | |
3399 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
3400 | } | |
1c330a2f DS |
3401 | } |
3402 | ||
3403 | if ((os_strcmp(name, "psk") == 0 && | |
3404 | value[0] == '"' && ssid->ssid_len) || | |
3405 | (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) | |
3406 | wpa_config_update_psk(ssid); | |
3407 | else if (os_strcmp(name, "priority") == 0) | |
3408 | wpa_config_update_prio_list(wpa_s->conf); | |
3409 | ||
3410 | return 0; | |
3411 | } | |
3412 | ||
3413 | ||
6fc6879b JM |
3414 | static int wpa_supplicant_ctrl_iface_set_network( |
3415 | struct wpa_supplicant *wpa_s, char *cmd) | |
3416 | { | |
1e529832 | 3417 | int id, ret, prev_bssid_set, prev_disabled; |
6fc6879b JM |
3418 | struct wpa_ssid *ssid; |
3419 | char *name, *value; | |
0ef023e4 | 3420 | u8 prev_bssid[ETH_ALEN]; |
6fc6879b JM |
3421 | |
3422 | /* cmd: "<network id> <variable name> <value>" */ | |
3423 | name = os_strchr(cmd, ' '); | |
3424 | if (name == NULL) | |
3425 | return -1; | |
3426 | *name++ = '\0'; | |
3427 | ||
3428 | value = os_strchr(name, ' '); | |
3429 | if (value == NULL) | |
3430 | return -1; | |
3431 | *value++ = '\0'; | |
3432 | ||
3433 | id = atoi(cmd); | |
3434 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", | |
3435 | id, name); | |
3436 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
3437 | (u8 *) value, os_strlen(value)); | |
3438 | ||
3439 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
3440 | if (ssid == NULL) { | |
3441 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | |
3442 | "id=%d", id); | |
3443 | return -1; | |
3444 | } | |
3445 | ||
0ef023e4 | 3446 | prev_bssid_set = ssid->bssid_set; |
1e529832 | 3447 | prev_disabled = ssid->disabled; |
0ef023e4 JM |
3448 | os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN); |
3449 | ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name, | |
3450 | value); | |
3451 | if (ret == 0 && | |
3452 | (ssid->bssid_set != prev_bssid_set || | |
3453 | os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0)) | |
3454 | wpas_notify_network_bssid_set_changed(wpa_s, ssid); | |
1e529832 JM |
3455 | |
3456 | if (prev_disabled != ssid->disabled && | |
3457 | (prev_disabled == 2 || ssid->disabled == 2)) | |
3458 | wpas_notify_network_type_changed(wpa_s, ssid); | |
3459 | ||
0ef023e4 | 3460 | return ret; |
6fc6879b JM |
3461 | } |
3462 | ||
3463 | ||
3464 | static int wpa_supplicant_ctrl_iface_get_network( | |
3465 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
3466 | { | |
3467 | int id; | |
3468 | size_t res; | |
3469 | struct wpa_ssid *ssid; | |
3470 | char *name, *value; | |
3471 | ||
3472 | /* cmd: "<network id> <variable name>" */ | |
3473 | name = os_strchr(cmd, ' '); | |
3474 | if (name == NULL || buflen == 0) | |
3475 | return -1; | |
3476 | *name++ = '\0'; | |
3477 | ||
3478 | id = atoi(cmd); | |
8db9a79d | 3479 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'", |
6fc6879b JM |
3480 | id, name); |
3481 | ||
3482 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
3483 | if (ssid == NULL) { | |
8db9a79d | 3484 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network " |
6fc6879b JM |
3485 | "id=%d", id); |
3486 | return -1; | |
3487 | } | |
3488 | ||
3489 | value = wpa_config_get_no_key(ssid, name); | |
3490 | if (value == NULL) { | |
8db9a79d | 3491 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network " |
6fc6879b JM |
3492 | "variable '%s'", name); |
3493 | return -1; | |
3494 | } | |
3495 | ||
3496 | res = os_strlcpy(buf, value, buflen); | |
3497 | if (res >= buflen) { | |
3498 | os_free(value); | |
3499 | return -1; | |
3500 | } | |
3501 | ||
3502 | os_free(value); | |
3503 | ||
3504 | return res; | |
3505 | } | |
3506 | ||
3507 | ||
1c330a2f | 3508 | static int wpa_supplicant_ctrl_iface_dup_network( |
daae4995 AN |
3509 | struct wpa_supplicant *wpa_s, char *cmd, |
3510 | struct wpa_supplicant *dst_wpa_s) | |
1c330a2f DS |
3511 | { |
3512 | struct wpa_ssid *ssid_s, *ssid_d; | |
3513 | char *name, *id, *value; | |
3514 | int id_s, id_d, ret; | |
3515 | ||
3516 | /* cmd: "<src network id> <dst network id> <variable name>" */ | |
3517 | id = os_strchr(cmd, ' '); | |
3518 | if (id == NULL) | |
3519 | return -1; | |
3520 | *id++ = '\0'; | |
3521 | ||
3522 | name = os_strchr(id, ' '); | |
3523 | if (name == NULL) | |
3524 | return -1; | |
3525 | *name++ = '\0'; | |
3526 | ||
3527 | id_s = atoi(cmd); | |
3528 | id_d = atoi(id); | |
daae4995 AN |
3529 | |
3530 | wpa_printf(MSG_DEBUG, | |
3531 | "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'", | |
3532 | wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name); | |
1c330a2f DS |
3533 | |
3534 | ssid_s = wpa_config_get_network(wpa_s->conf, id_s); | |
3535 | if (ssid_s == NULL) { | |
3536 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
3537 | "network id=%d", id_s); | |
3538 | return -1; | |
3539 | } | |
3540 | ||
daae4995 | 3541 | ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d); |
1c330a2f DS |
3542 | if (ssid_d == NULL) { |
3543 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
c0541906 | 3544 | "network id=%d", id_d); |
1c330a2f DS |
3545 | return -1; |
3546 | } | |
3547 | ||
3548 | value = wpa_config_get(ssid_s, name); | |
3549 | if (value == NULL) { | |
3550 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " | |
3551 | "variable '%s'", name); | |
3552 | return -1; | |
3553 | } | |
3554 | ||
daae4995 | 3555 | ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name, |
1c330a2f DS |
3556 | value); |
3557 | ||
3558 | os_free(value); | |
3559 | ||
3560 | return ret; | |
3561 | } | |
3562 | ||
3563 | ||
d94c9ee6 JM |
3564 | static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s, |
3565 | char *buf, size_t buflen) | |
3566 | { | |
3567 | char *pos, *end; | |
3568 | struct wpa_cred *cred; | |
3569 | int ret; | |
3570 | ||
3571 | pos = buf; | |
3572 | end = buf + buflen; | |
3573 | ret = os_snprintf(pos, end - pos, | |
3574 | "cred id / realm / username / domain / imsi\n"); | |
d85e1fc8 | 3575 | if (os_snprintf_error(end - pos, ret)) |
d94c9ee6 JM |
3576 | return pos - buf; |
3577 | pos += ret; | |
3578 | ||
3579 | cred = wpa_s->conf->cred; | |
3580 | while (cred) { | |
3581 | ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n", | |
3582 | cred->id, cred->realm ? cred->realm : "", | |
3583 | cred->username ? cred->username : "", | |
463c8ffb | 3584 | cred->domain ? cred->domain[0] : "", |
d94c9ee6 | 3585 | cred->imsi ? cred->imsi : ""); |
d85e1fc8 | 3586 | if (os_snprintf_error(end - pos, ret)) |
d94c9ee6 JM |
3587 | return pos - buf; |
3588 | pos += ret; | |
3589 | ||
3590 | cred = cred->next; | |
3591 | } | |
3592 | ||
3593 | return pos - buf; | |
3594 | } | |
3595 | ||
3596 | ||
3597 | static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s, | |
3598 | char *buf, size_t buflen) | |
3599 | { | |
3600 | struct wpa_cred *cred; | |
3601 | int ret; | |
3602 | ||
3603 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED"); | |
3604 | ||
3605 | cred = wpa_config_add_cred(wpa_s->conf); | |
3606 | if (cred == NULL) | |
3607 | return -1; | |
3608 | ||
1619e9d5 JM |
3609 | wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id); |
3610 | ||
d94c9ee6 | 3611 | ret = os_snprintf(buf, buflen, "%d\n", cred->id); |
d85e1fc8 | 3612 | if (os_snprintf_error(buflen, ret)) |
d94c9ee6 JM |
3613 | return -1; |
3614 | return ret; | |
3615 | } | |
3616 | ||
3617 | ||
736d4f2d JM |
3618 | static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s, |
3619 | struct wpa_cred *cred) | |
3620 | { | |
3621 | struct wpa_ssid *ssid; | |
3622 | char str[20]; | |
1619e9d5 | 3623 | int id; |
736d4f2d | 3624 | |
1619e9d5 | 3625 | if (cred == NULL) { |
736d4f2d JM |
3626 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); |
3627 | return -1; | |
3628 | } | |
3629 | ||
1619e9d5 JM |
3630 | id = cred->id; |
3631 | if (wpa_config_remove_cred(wpa_s->conf, id) < 0) { | |
3632 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); | |
3633 | return -1; | |
3634 | } | |
3635 | ||
3636 | wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id); | |
3637 | ||
736d4f2d JM |
3638 | /* Remove any network entry created based on the removed credential */ |
3639 | ssid = wpa_s->conf->ssid; | |
3640 | while (ssid) { | |
3641 | if (ssid->parent_cred == cred) { | |
1d399771 JM |
3642 | int res; |
3643 | ||
736d4f2d JM |
3644 | wpa_printf(MSG_DEBUG, "Remove network id %d since it " |
3645 | "used the removed credential", ssid->id); | |
1d399771 JM |
3646 | res = os_snprintf(str, sizeof(str), "%d", ssid->id); |
3647 | if (os_snprintf_error(sizeof(str), res)) | |
3648 | str[sizeof(str) - 1] = '\0'; | |
736d4f2d JM |
3649 | ssid = ssid->next; |
3650 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, str); | |
3651 | } else | |
3652 | ssid = ssid->next; | |
3653 | } | |
3654 | ||
3655 | return 0; | |
3656 | } | |
3657 | ||
3658 | ||
d94c9ee6 JM |
3659 | static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s, |
3660 | char *cmd) | |
3661 | { | |
3662 | int id; | |
736d4f2d | 3663 | struct wpa_cred *cred, *prev; |
d94c9ee6 | 3664 | |
aa26ba68 JM |
3665 | /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or |
3666 | * "provisioning_sp=<FQDN> */ | |
d94c9ee6 JM |
3667 | if (os_strcmp(cmd, "all") == 0) { |
3668 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all"); | |
3669 | cred = wpa_s->conf->cred; | |
3670 | while (cred) { | |
736d4f2d | 3671 | prev = cred; |
d94c9ee6 | 3672 | cred = cred->next; |
736d4f2d | 3673 | wpas_ctrl_remove_cred(wpa_s, prev); |
d94c9ee6 JM |
3674 | } |
3675 | return 0; | |
3676 | } | |
3677 | ||
9afe52eb JM |
3678 | if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) { |
3679 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'", | |
3680 | cmd + 8); | |
3681 | cred = wpa_s->conf->cred; | |
3682 | while (cred) { | |
3683 | prev = cred; | |
3684 | cred = cred->next; | |
463c8ffb JM |
3685 | if (prev->domain) { |
3686 | size_t i; | |
3687 | for (i = 0; i < prev->num_domain; i++) { | |
3688 | if (os_strcmp(prev->domain[i], cmd + 8) | |
3689 | != 0) | |
3690 | continue; | |
3691 | wpas_ctrl_remove_cred(wpa_s, prev); | |
3692 | break; | |
3693 | } | |
3694 | } | |
9afe52eb JM |
3695 | } |
3696 | return 0; | |
3697 | } | |
3698 | ||
aa26ba68 JM |
3699 | if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) { |
3700 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'", | |
3701 | cmd + 16); | |
3702 | cred = wpa_s->conf->cred; | |
3703 | while (cred) { | |
3704 | prev = cred; | |
3705 | cred = cred->next; | |
3706 | if (prev->provisioning_sp && | |
3707 | os_strcmp(prev->provisioning_sp, cmd + 16) == 0) | |
3708 | wpas_ctrl_remove_cred(wpa_s, prev); | |
3709 | } | |
3710 | return 0; | |
3711 | } | |
3712 | ||
d94c9ee6 JM |
3713 | id = atoi(cmd); |
3714 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id); | |
3715 | ||
3716 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
736d4f2d | 3717 | return wpas_ctrl_remove_cred(wpa_s, cred); |
d94c9ee6 JM |
3718 | } |
3719 | ||
3720 | ||
3721 | static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s, | |
3722 | char *cmd) | |
3723 | { | |
3724 | int id; | |
3725 | struct wpa_cred *cred; | |
3726 | char *name, *value; | |
3727 | ||
3728 | /* cmd: "<cred id> <variable name> <value>" */ | |
3729 | name = os_strchr(cmd, ' '); | |
3730 | if (name == NULL) | |
3731 | return -1; | |
3732 | *name++ = '\0'; | |
3733 | ||
3734 | value = os_strchr(name, ' '); | |
3735 | if (value == NULL) | |
3736 | return -1; | |
3737 | *value++ = '\0'; | |
3738 | ||
3739 | id = atoi(cmd); | |
3740 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'", | |
3741 | id, name); | |
3742 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
3743 | (u8 *) value, os_strlen(value)); | |
3744 | ||
3745 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
3746 | if (cred == NULL) { | |
3747 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | |
3748 | id); | |
3749 | return -1; | |
3750 | } | |
3751 | ||
3752 | if (wpa_config_set_cred(cred, name, value, 0) < 0) { | |
3753 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred " | |
3754 | "variable '%s'", name); | |
3755 | return -1; | |
3756 | } | |
3757 | ||
1619e9d5 JM |
3758 | wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name); |
3759 | ||
d94c9ee6 JM |
3760 | return 0; |
3761 | } | |
3762 | ||
3763 | ||
c880ab87 JM |
3764 | static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s, |
3765 | char *cmd, char *buf, | |
3766 | size_t buflen) | |
3767 | { | |
3768 | int id; | |
3769 | size_t res; | |
3770 | struct wpa_cred *cred; | |
3771 | char *name, *value; | |
3772 | ||
3773 | /* cmd: "<cred id> <variable name>" */ | |
3774 | name = os_strchr(cmd, ' '); | |
3775 | if (name == NULL) | |
3776 | return -1; | |
3777 | *name++ = '\0'; | |
3778 | ||
3779 | id = atoi(cmd); | |
3780 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'", | |
3781 | id, name); | |
3782 | ||
3783 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
3784 | if (cred == NULL) { | |
3785 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | |
3786 | id); | |
3787 | return -1; | |
3788 | } | |
3789 | ||
3790 | value = wpa_config_get_cred_no_key(cred, name); | |
3791 | if (value == NULL) { | |
3792 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'", | |
3793 | name); | |
3794 | return -1; | |
3795 | } | |
3796 | ||
3797 | res = os_strlcpy(buf, value, buflen); | |
3798 | if (res >= buflen) { | |
3799 | os_free(value); | |
3800 | return -1; | |
3801 | } | |
3802 | ||
3803 | os_free(value); | |
3804 | ||
3805 | return res; | |
3806 | } | |
3807 | ||
3808 | ||
6fc6879b JM |
3809 | #ifndef CONFIG_NO_CONFIG_WRITE |
3810 | static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s) | |
3811 | { | |
3812 | int ret; | |
3813 | ||
3814 | if (!wpa_s->conf->update_config) { | |
3815 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed " | |
3816 | "to update configuration (update_config=0)"); | |
3817 | return -1; | |
3818 | } | |
3819 | ||
3820 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); | |
3821 | if (ret) { | |
3822 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to " | |
3823 | "update configuration"); | |
3824 | } else { | |
3825 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration" | |
3826 | " updated"); | |
3827 | } | |
3828 | ||
3829 | return ret; | |
3830 | } | |
3831 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
3832 | ||
3833 | ||
4daa011b JM |
3834 | struct cipher_info { |
3835 | unsigned int capa; | |
3836 | const char *name; | |
3837 | int group_only; | |
3838 | }; | |
3839 | ||
3840 | static const struct cipher_info ciphers[] = { | |
3841 | { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 }, | |
3842 | { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 }, | |
3843 | { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 }, | |
3844 | { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 }, | |
3845 | { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 }, | |
3846 | { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 }, | |
3847 | { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 }, | |
3848 | { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 } | |
3849 | }; | |
3850 | ||
b5f045de JM |
3851 | static const struct cipher_info ciphers_group_mgmt[] = { |
3852 | { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 }, | |
3853 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 }, | |
3854 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 }, | |
3855 | { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 }, | |
3856 | }; | |
3857 | ||
4daa011b | 3858 | |
6fc6879b JM |
3859 | static int ctrl_iface_get_capability_pairwise(int res, char *strict, |
3860 | struct wpa_driver_capa *capa, | |
3861 | char *buf, size_t buflen) | |
3862 | { | |
ea3b8c1d | 3863 | int ret; |
6fc6879b JM |
3864 | char *pos, *end; |
3865 | size_t len; | |
4daa011b | 3866 | unsigned int i; |
6fc6879b JM |
3867 | |
3868 | pos = buf; | |
3869 | end = pos + buflen; | |
3870 | ||
3871 | if (res < 0) { | |
3872 | if (strict) | |
3873 | return 0; | |
3874 | len = os_strlcpy(buf, "CCMP TKIP NONE", buflen); | |
3875 | if (len >= buflen) | |
3876 | return -1; | |
3877 | return len; | |
3878 | } | |
3879 | ||
4daa011b JM |
3880 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
3881 | if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) { | |
3882 | ret = os_snprintf(pos, end - pos, "%s%s", | |
ea3b8c1d JM |
3883 | pos == buf ? "" : " ", |
3884 | ciphers[i].name); | |
d85e1fc8 | 3885 | if (os_snprintf_error(end - pos, ret)) |
4daa011b JM |
3886 | return pos - buf; |
3887 | pos += ret; | |
4daa011b | 3888 | } |
6fc6879b JM |
3889 | } |
3890 | ||
3891 | return pos - buf; | |
3892 | } | |
3893 | ||
3894 | ||
3895 | static int ctrl_iface_get_capability_group(int res, char *strict, | |
3896 | struct wpa_driver_capa *capa, | |
3897 | char *buf, size_t buflen) | |
3898 | { | |
ea3b8c1d | 3899 | int ret; |
6fc6879b JM |
3900 | char *pos, *end; |
3901 | size_t len; | |
4daa011b | 3902 | unsigned int i; |
6fc6879b JM |
3903 | |
3904 | pos = buf; | |
3905 | end = pos + buflen; | |
3906 | ||
3907 | if (res < 0) { | |
3908 | if (strict) | |
3909 | return 0; | |
3910 | len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen); | |
3911 | if (len >= buflen) | |
3912 | return -1; | |
3913 | return len; | |
3914 | } | |
3915 | ||
4daa011b JM |
3916 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
3917 | if (capa->enc & ciphers[i].capa) { | |
3918 | ret = os_snprintf(pos, end - pos, "%s%s", | |
ea3b8c1d JM |
3919 | pos == buf ? "" : " ", |
3920 | ciphers[i].name); | |
d85e1fc8 | 3921 | if (os_snprintf_error(end - pos, ret)) |
4daa011b JM |
3922 | return pos - buf; |
3923 | pos += ret; | |
4daa011b | 3924 | } |
6fc6879b JM |
3925 | } |
3926 | ||
3927 | return pos - buf; | |
3928 | } | |
3929 | ||
3930 | ||
b5f045de JM |
3931 | static int ctrl_iface_get_capability_group_mgmt(int res, char *strict, |
3932 | struct wpa_driver_capa *capa, | |
3933 | char *buf, size_t buflen) | |
3934 | { | |
3935 | int ret; | |
3936 | char *pos, *end; | |
3937 | unsigned int i; | |
3938 | ||
3939 | pos = buf; | |
3940 | end = pos + buflen; | |
3941 | ||
3942 | if (res < 0) | |
3943 | return 0; | |
3944 | ||
3945 | for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) { | |
3946 | if (capa->enc & ciphers_group_mgmt[i].capa) { | |
3947 | ret = os_snprintf(pos, end - pos, "%s%s", | |
3948 | pos == buf ? "" : " ", | |
3949 | ciphers_group_mgmt[i].name); | |
3950 | if (os_snprintf_error(end - pos, ret)) | |
3951 | return pos - buf; | |
3952 | pos += ret; | |
3953 | } | |
3954 | } | |
3955 | ||
3956 | return pos - buf; | |
3957 | } | |
3958 | ||
3959 | ||
6fc6879b JM |
3960 | static int ctrl_iface_get_capability_key_mgmt(int res, char *strict, |
3961 | struct wpa_driver_capa *capa, | |
3962 | char *buf, size_t buflen) | |
3963 | { | |
3964 | int ret; | |
3965 | char *pos, *end; | |
3966 | size_t len; | |
3967 | ||
3968 | pos = buf; | |
3969 | end = pos + buflen; | |
3970 | ||
3971 | if (res < 0) { | |
3972 | if (strict) | |
3973 | return 0; | |
3974 | len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE " | |
3975 | "NONE", buflen); | |
3976 | if (len >= buflen) | |
3977 | return -1; | |
3978 | return len; | |
3979 | } | |
3980 | ||
3981 | ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); | |
d85e1fc8 | 3982 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3983 | return pos - buf; |
3984 | pos += ret; | |
3985 | ||
3986 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
3987 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { | |
3988 | ret = os_snprintf(pos, end - pos, " WPA-EAP"); | |
d85e1fc8 | 3989 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3990 | return pos - buf; |
3991 | pos += ret; | |
3992 | } | |
3993 | ||
3994 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | |
3995 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
3996 | ret = os_snprintf(pos, end - pos, " WPA-PSK"); | |
d85e1fc8 | 3997 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3998 | return pos - buf; |
3999 | pos += ret; | |
4000 | } | |
4001 | ||
4002 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { | |
4003 | ret = os_snprintf(pos, end - pos, " WPA-NONE"); | |
d85e1fc8 | 4004 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
4005 | return pos - buf; |
4006 | pos += ret; | |
4007 | } | |
4008 | ||
399e6135 JM |
4009 | #ifdef CONFIG_SUITEB |
4010 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) { | |
4011 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B"); | |
4012 | if (os_snprintf_error(end - pos, ret)) | |
4013 | return pos - buf; | |
4014 | pos += ret; | |
4015 | } | |
4016 | #endif /* CONFIG_SUITEB */ | |
4017 | #ifdef CONFIG_SUITEB192 | |
4018 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) { | |
4019 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192"); | |
4020 | if (os_snprintf_error(end - pos, ret)) | |
4021 | return pos - buf; | |
4022 | pos += ret; | |
4023 | } | |
4024 | #endif /* CONFIG_SUITEB192 */ | |
f9561868 JM |
4025 | #ifdef CONFIG_OWE |
4026 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) { | |
4027 | ret = os_snprintf(pos, end - pos, " OWE"); | |
4028 | if (os_snprintf_error(end - pos, ret)) | |
4029 | return pos - buf; | |
4030 | pos += ret; | |
4031 | } | |
4032 | #endif /* CONFIG_OWE */ | |
567da5bb JM |
4033 | #ifdef CONFIG_DPP |
4034 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) { | |
4035 | ret = os_snprintf(pos, end - pos, " DPP"); | |
4036 | if (os_snprintf_error(end - pos, ret)) | |
4037 | return pos - buf; | |
4038 | pos += ret; | |
4039 | } | |
4040 | #endif /* CONFIG_DPP */ | |
fe3e0bac VK |
4041 | #ifdef CONFIG_FILS |
4042 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) { | |
4043 | ret = os_snprintf(pos, end - pos, " FILS-SHA256"); | |
4044 | if (os_snprintf_error(end - pos, ret)) | |
4045 | return pos - buf; | |
4046 | pos += ret; | |
4047 | } | |
4048 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) { | |
4049 | ret = os_snprintf(pos, end - pos, " FILS-SHA384"); | |
4050 | if (os_snprintf_error(end - pos, ret)) | |
4051 | return pos - buf; | |
4052 | pos += ret; | |
4053 | } | |
4054 | #ifdef CONFIG_IEEE80211R | |
4055 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) { | |
4056 | ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256"); | |
4057 | if (os_snprintf_error(end - pos, ret)) | |
4058 | return pos - buf; | |
4059 | pos += ret; | |
4060 | } | |
4061 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) { | |
4062 | ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384"); | |
4063 | if (os_snprintf_error(end - pos, ret)) | |
4064 | return pos - buf; | |
4065 | pos += ret; | |
4066 | } | |
4067 | #endif /* CONFIG_IEEE80211R */ | |
4068 | #endif /* CONFIG_FILS */ | |
73f285da MH |
4069 | #ifdef CONFIG_IEEE80211R |
4070 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) { | |
4071 | ret = os_snprintf(pos, end - pos, " FT-PSK"); | |
4072 | if (os_snprintf_error(end - pos, ret)) | |
4073 | return pos - buf; | |
4074 | pos += ret; | |
4075 | } | |
4076 | #endif /* CONFIG_IEEE80211R */ | |
0fb292c0 JM |
4077 | #ifdef CONFIG_SAE |
4078 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) { | |
4079 | ret = os_snprintf(pos, end - pos, " SAE"); | |
4080 | if (os_snprintf_error(end - pos, ret)) | |
4081 | return pos - buf; | |
4082 | pos += ret; | |
4083 | } | |
4084 | #endif /* CONFIG_SAE */ | |
399e6135 | 4085 | |
6fc6879b JM |
4086 | return pos - buf; |
4087 | } | |
4088 | ||
4089 | ||
4090 | static int ctrl_iface_get_capability_proto(int res, char *strict, | |
4091 | struct wpa_driver_capa *capa, | |
4092 | char *buf, size_t buflen) | |
4093 | { | |
ea3b8c1d | 4094 | int ret; |
6fc6879b JM |
4095 | char *pos, *end; |
4096 | size_t len; | |
4097 | ||
4098 | pos = buf; | |
4099 | end = pos + buflen; | |
4100 | ||
4101 | if (res < 0) { | |
4102 | if (strict) | |
4103 | return 0; | |
4104 | len = os_strlcpy(buf, "RSN WPA", buflen); | |
4105 | if (len >= buflen) | |
4106 | return -1; | |
4107 | return len; | |
4108 | } | |
4109 | ||
4110 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | |
4111 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
ea3b8c1d JM |
4112 | ret = os_snprintf(pos, end - pos, "%sRSN", |
4113 | pos == buf ? "" : " "); | |
d85e1fc8 | 4114 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
4115 | return pos - buf; |
4116 | pos += ret; | |
6fc6879b JM |
4117 | } |
4118 | ||
4119 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
4120 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { | |
ea3b8c1d JM |
4121 | ret = os_snprintf(pos, end - pos, "%sWPA", |
4122 | pos == buf ? "" : " "); | |
d85e1fc8 | 4123 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
4124 | return pos - buf; |
4125 | pos += ret; | |
6fc6879b JM |
4126 | } |
4127 | ||
4128 | return pos - buf; | |
4129 | } | |
4130 | ||
4131 | ||
db5adfe7 JM |
4132 | static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s, |
4133 | int res, char *strict, | |
6fc6879b JM |
4134 | struct wpa_driver_capa *capa, |
4135 | char *buf, size_t buflen) | |
4136 | { | |
ea3b8c1d | 4137 | int ret; |
6fc6879b JM |
4138 | char *pos, *end; |
4139 | size_t len; | |
4140 | ||
4141 | pos = buf; | |
4142 | end = pos + buflen; | |
4143 | ||
4144 | if (res < 0) { | |
4145 | if (strict) | |
4146 | return 0; | |
4147 | len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen); | |
4148 | if (len >= buflen) | |
4149 | return -1; | |
4150 | return len; | |
4151 | } | |
4152 | ||
4153 | if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) { | |
ea3b8c1d JM |
4154 | ret = os_snprintf(pos, end - pos, "%sOPEN", |
4155 | pos == buf ? "" : " "); | |
d85e1fc8 | 4156 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
4157 | return pos - buf; |
4158 | pos += ret; | |
6fc6879b JM |
4159 | } |
4160 | ||
4161 | if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) { | |
4162 | ret = os_snprintf(pos, end - pos, "%sSHARED", | |
ea3b8c1d | 4163 | pos == buf ? "" : " "); |
d85e1fc8 | 4164 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
4165 | return pos - buf; |
4166 | pos += ret; | |
6fc6879b JM |
4167 | } |
4168 | ||
4169 | if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) { | |
ea3b8c1d JM |
4170 | ret = os_snprintf(pos, end - pos, "%sLEAP", |
4171 | pos == buf ? "" : " "); | |
d85e1fc8 | 4172 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
4173 | return pos - buf; |
4174 | pos += ret; | |
6fc6879b JM |
4175 | } |
4176 | ||
db5adfe7 JM |
4177 | #ifdef CONFIG_SAE |
4178 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) { | |
4179 | ret = os_snprintf(pos, end - pos, "%sSAE", | |
4180 | pos == buf ? "" : " "); | |
4181 | if (os_snprintf_error(end - pos, ret)) | |
4182 | return pos - buf; | |
4183 | pos += ret; | |
4184 | } | |
4185 | #endif /* CONFIG_SAE */ | |
4186 | ||
fe3e0bac VK |
4187 | #ifdef CONFIG_FILS |
4188 | if (wpa_is_fils_supported(wpa_s)) { | |
4189 | ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS", | |
4190 | pos == buf ? "" : " "); | |
4191 | if (os_snprintf_error(end - pos, ret)) | |
4192 | return pos - buf; | |
4193 | pos += ret; | |
4194 | } | |
4195 | ||
4196 | #ifdef CONFIG_FILS_SK_PFS | |
4197 | if (wpa_is_fils_sk_pfs_supported(wpa_s)) { | |
4198 | ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS", | |
4199 | pos == buf ? "" : " "); | |
4200 | if (os_snprintf_error(end - pos, ret)) | |
4201 | return pos - buf; | |
4202 | pos += ret; | |
4203 | } | |
4204 | #endif /* CONFIG_FILS_SK_PFS */ | |
4205 | #endif /* CONFIG_FILS */ | |
4206 | ||
6fc6879b JM |
4207 | return pos - buf; |
4208 | } | |
4209 | ||
4210 | ||
65d52fc1 BR |
4211 | static int ctrl_iface_get_capability_modes(int res, char *strict, |
4212 | struct wpa_driver_capa *capa, | |
4213 | char *buf, size_t buflen) | |
4214 | { | |
ea3b8c1d | 4215 | int ret; |
65d52fc1 BR |
4216 | char *pos, *end; |
4217 | size_t len; | |
4218 | ||
4219 | pos = buf; | |
4220 | end = pos + buflen; | |
4221 | ||
4222 | if (res < 0) { | |
4223 | if (strict) | |
4224 | return 0; | |
4225 | len = os_strlcpy(buf, "IBSS AP", buflen); | |
4226 | if (len >= buflen) | |
4227 | return -1; | |
4228 | return len; | |
4229 | } | |
4230 | ||
4231 | if (capa->flags & WPA_DRIVER_FLAGS_IBSS) { | |
ea3b8c1d JM |
4232 | ret = os_snprintf(pos, end - pos, "%sIBSS", |
4233 | pos == buf ? "" : " "); | |
d85e1fc8 | 4234 | if (os_snprintf_error(end - pos, ret)) |
65d52fc1 BR |
4235 | return pos - buf; |
4236 | pos += ret; | |
65d52fc1 BR |
4237 | } |
4238 | ||
4239 | if (capa->flags & WPA_DRIVER_FLAGS_AP) { | |
ea3b8c1d JM |
4240 | ret = os_snprintf(pos, end - pos, "%sAP", |
4241 | pos == buf ? "" : " "); | |
d85e1fc8 | 4242 | if (os_snprintf_error(end - pos, ret)) |
65d52fc1 BR |
4243 | return pos - buf; |
4244 | pos += ret; | |
65d52fc1 BR |
4245 | } |
4246 | ||
cf08e9b1 JM |
4247 | #ifdef CONFIG_MESH |
4248 | if (capa->flags & WPA_DRIVER_FLAGS_MESH) { | |
4249 | ret = os_snprintf(pos, end - pos, "%sMESH", | |
4250 | pos == buf ? "" : " "); | |
4251 | if (os_snprintf_error(end - pos, ret)) | |
4252 | return pos - buf; | |
4253 | pos += ret; | |
4254 | } | |
4255 | #endif /* CONFIG_MESH */ | |
4256 | ||
65d52fc1 BR |
4257 | return pos - buf; |
4258 | } | |
4259 | ||
4260 | ||
35aa088a DS |
4261 | static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s, |
4262 | char *buf, size_t buflen) | |
4263 | { | |
4264 | struct hostapd_channel_data *chnl; | |
4265 | int ret, i, j; | |
4266 | char *pos, *end, *hmode; | |
4267 | ||
4268 | pos = buf; | |
4269 | end = pos + buflen; | |
4270 | ||
4271 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | |
4272 | switch (wpa_s->hw.modes[j].mode) { | |
4273 | case HOSTAPD_MODE_IEEE80211B: | |
4274 | hmode = "B"; | |
4275 | break; | |
4276 | case HOSTAPD_MODE_IEEE80211G: | |
4277 | hmode = "G"; | |
4278 | break; | |
4279 | case HOSTAPD_MODE_IEEE80211A: | |
4280 | hmode = "A"; | |
4281 | break; | |
7829894c VK |
4282 | case HOSTAPD_MODE_IEEE80211AD: |
4283 | hmode = "AD"; | |
4284 | break; | |
35aa088a DS |
4285 | default: |
4286 | continue; | |
4287 | } | |
4288 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode); | |
d85e1fc8 | 4289 | if (os_snprintf_error(end - pos, ret)) |
35aa088a DS |
4290 | return pos - buf; |
4291 | pos += ret; | |
4292 | chnl = wpa_s->hw.modes[j].channels; | |
4293 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | |
4294 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | |
4295 | continue; | |
4296 | ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan); | |
d85e1fc8 | 4297 | if (os_snprintf_error(end - pos, ret)) |
35aa088a DS |
4298 | return pos - buf; |
4299 | pos += ret; | |
4300 | } | |
4301 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4302 | if (os_snprintf_error(end - pos, ret)) |
35aa088a DS |
4303 | return pos - buf; |
4304 | pos += ret; | |
4305 | } | |
4306 | ||
4307 | return pos - buf; | |
4308 | } | |
4309 | ||
4310 | ||
06060522 BR |
4311 | static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s, |
4312 | char *buf, size_t buflen) | |
4313 | { | |
4314 | struct hostapd_channel_data *chnl; | |
4315 | int ret, i, j; | |
4316 | char *pos, *end, *hmode; | |
4317 | ||
4318 | pos = buf; | |
4319 | end = pos + buflen; | |
4320 | ||
4321 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | |
4322 | switch (wpa_s->hw.modes[j].mode) { | |
4323 | case HOSTAPD_MODE_IEEE80211B: | |
4324 | hmode = "B"; | |
4325 | break; | |
4326 | case HOSTAPD_MODE_IEEE80211G: | |
4327 | hmode = "G"; | |
4328 | break; | |
4329 | case HOSTAPD_MODE_IEEE80211A: | |
4330 | hmode = "A"; | |
4331 | break; | |
4332 | case HOSTAPD_MODE_IEEE80211AD: | |
4333 | hmode = "AD"; | |
4334 | break; | |
4335 | default: | |
4336 | continue; | |
4337 | } | |
4338 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n", | |
4339 | hmode); | |
d85e1fc8 | 4340 | if (os_snprintf_error(end - pos, ret)) |
06060522 BR |
4341 | return pos - buf; |
4342 | pos += ret; | |
4343 | chnl = wpa_s->hw.modes[j].channels; | |
4344 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | |
4345 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | |
4346 | continue; | |
0547124d | 4347 | ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n", |
06060522 | 4348 | chnl[i].chan, chnl[i].freq, |
0a443580 IP |
4349 | chnl[i].flag & HOSTAPD_CHAN_NO_IR ? |
4350 | " (NO_IR)" : "", | |
0547124d DS |
4351 | chnl[i].flag & HOSTAPD_CHAN_RADAR ? |
4352 | " (DFS)" : ""); | |
4353 | ||
d85e1fc8 | 4354 | if (os_snprintf_error(end - pos, ret)) |
06060522 BR |
4355 | return pos - buf; |
4356 | pos += ret; | |
4357 | } | |
4358 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4359 | if (os_snprintf_error(end - pos, ret)) |
06060522 BR |
4360 | return pos - buf; |
4361 | pos += ret; | |
4362 | } | |
4363 | ||
4364 | return pos - buf; | |
4365 | } | |
4366 | ||
4367 | ||
6fc6879b JM |
4368 | static int wpa_supplicant_ctrl_iface_get_capability( |
4369 | struct wpa_supplicant *wpa_s, const char *_field, char *buf, | |
4370 | size_t buflen) | |
4371 | { | |
4372 | struct wpa_driver_capa capa; | |
4373 | int res; | |
4374 | char *strict; | |
4375 | char field[30]; | |
4376 | size_t len; | |
4377 | ||
4378 | /* Determine whether or not strict checking was requested */ | |
4379 | len = os_strlcpy(field, _field, sizeof(field)); | |
4380 | if (len >= sizeof(field)) | |
4381 | return -1; | |
4382 | strict = os_strchr(field, ' '); | |
4383 | if (strict != NULL) { | |
4384 | *strict++ = '\0'; | |
4385 | if (os_strcmp(strict, "strict") != 0) | |
4386 | return -1; | |
4387 | } | |
4388 | ||
4389 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s", | |
4390 | field, strict ? strict : ""); | |
4391 | ||
4392 | if (os_strcmp(field, "eap") == 0) { | |
4393 | return eap_get_names(buf, buflen); | |
4394 | } | |
4395 | ||
4396 | res = wpa_drv_get_capa(wpa_s, &capa); | |
4397 | ||
4398 | if (os_strcmp(field, "pairwise") == 0) | |
4399 | return ctrl_iface_get_capability_pairwise(res, strict, &capa, | |
4400 | buf, buflen); | |
4401 | ||
4402 | if (os_strcmp(field, "group") == 0) | |
4403 | return ctrl_iface_get_capability_group(res, strict, &capa, | |
4404 | buf, buflen); | |
4405 | ||
b5f045de JM |
4406 | if (os_strcmp(field, "group_mgmt") == 0) |
4407 | return ctrl_iface_get_capability_group_mgmt(res, strict, &capa, | |
4408 | buf, buflen); | |
4409 | ||
6fc6879b JM |
4410 | if (os_strcmp(field, "key_mgmt") == 0) |
4411 | return ctrl_iface_get_capability_key_mgmt(res, strict, &capa, | |
4412 | buf, buflen); | |
4413 | ||
4414 | if (os_strcmp(field, "proto") == 0) | |
4415 | return ctrl_iface_get_capability_proto(res, strict, &capa, | |
4416 | buf, buflen); | |
4417 | ||
4418 | if (os_strcmp(field, "auth_alg") == 0) | |
db5adfe7 JM |
4419 | return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict, |
4420 | &capa, buf, buflen); | |
6fc6879b | 4421 | |
65d52fc1 BR |
4422 | if (os_strcmp(field, "modes") == 0) |
4423 | return ctrl_iface_get_capability_modes(res, strict, &capa, | |
4424 | buf, buflen); | |
4425 | ||
35aa088a DS |
4426 | if (os_strcmp(field, "channels") == 0) |
4427 | return ctrl_iface_get_capability_channels(wpa_s, buf, buflen); | |
4428 | ||
06060522 BR |
4429 | if (os_strcmp(field, "freq") == 0) |
4430 | return ctrl_iface_get_capability_freq(wpa_s, buf, buflen); | |
4431 | ||
6e9375e4 DS |
4432 | #ifdef CONFIG_TDLS |
4433 | if (os_strcmp(field, "tdls") == 0) | |
4434 | return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen); | |
4435 | #endif /* CONFIG_TDLS */ | |
4436 | ||
02a8d45a JM |
4437 | #ifdef CONFIG_ERP |
4438 | if (os_strcmp(field, "erp") == 0) { | |
4439 | res = os_snprintf(buf, buflen, "ERP"); | |
d85e1fc8 | 4440 | if (os_snprintf_error(buflen, res)) |
02a8d45a JM |
4441 | return -1; |
4442 | return res; | |
4443 | } | |
4444 | #endif /* CONFIG_EPR */ | |
4445 | ||
1e4f7bf5 JM |
4446 | #ifdef CONFIG_FIPS |
4447 | if (os_strcmp(field, "fips") == 0) { | |
4448 | res = os_snprintf(buf, buflen, "FIPS"); | |
4449 | if (os_snprintf_error(buflen, res)) | |
4450 | return -1; | |
4451 | return res; | |
4452 | } | |
4453 | #endif /* CONFIG_FIPS */ | |
4454 | ||
7d2f6743 JM |
4455 | #ifdef CONFIG_ACS |
4456 | if (os_strcmp(field, "acs") == 0) { | |
4457 | res = os_snprintf(buf, buflen, "ACS"); | |
4458 | if (os_snprintf_error(buflen, res)) | |
4459 | return -1; | |
4460 | return res; | |
4461 | } | |
4462 | #endif /* CONFIG_ACS */ | |
4463 | ||
379e2b4d | 4464 | #ifdef CONFIG_FILS |
fe3e0bac | 4465 | if (os_strcmp(field, "fils") == 0) { |
31e130f8 | 4466 | #ifdef CONFIG_FILS_SK_PFS |
fe3e0bac VK |
4467 | if (wpa_is_fils_supported(wpa_s) && |
4468 | wpa_is_fils_sk_pfs_supported(wpa_s)) { | |
4469 | res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS"); | |
4470 | if (os_snprintf_error(buflen, res)) | |
4471 | return -1; | |
4472 | return res; | |
4473 | } | |
31e130f8 | 4474 | #endif /* CONFIG_FILS_SK_PFS */ |
fe3e0bac VK |
4475 | |
4476 | if (wpa_is_fils_supported(wpa_s)) { | |
4477 | res = os_snprintf(buf, buflen, "FILS"); | |
4478 | if (os_snprintf_error(buflen, res)) | |
4479 | return -1; | |
4480 | return res; | |
4481 | } | |
379e2b4d JM |
4482 | } |
4483 | #endif /* CONFIG_FILS */ | |
4484 | ||
2a93ecc8 JM |
4485 | if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) { |
4486 | res = os_snprintf(buf, buflen, "MULTIBSS-STA"); | |
4487 | if (os_snprintf_error(buflen, res)) | |
4488 | return -1; | |
4489 | return res; | |
4490 | } | |
4491 | ||
c98617b4 JM |
4492 | #ifdef CONFIG_DPP |
4493 | if (os_strcmp(field, "dpp") == 0) { | |
4494 | #ifdef CONFIG_DPP2 | |
4495 | res = os_snprintf(buf, buflen, "DPP=2"); | |
4496 | #else /* CONFIG_DPP2 */ | |
4497 | res = os_snprintf(buf, buflen, "DPP=1"); | |
4498 | #endif /* CONFIG_DPP2 */ | |
4499 | if (os_snprintf_error(buflen, res)) | |
4500 | return -1; | |
4501 | return res; | |
4502 | } | |
4503 | #endif /* CONFIG_DPP */ | |
4504 | ||
6fc6879b JM |
4505 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", |
4506 | field); | |
4507 | ||
4508 | return -1; | |
4509 | } | |
4510 | ||
4511 | ||
afc064fe JM |
4512 | #ifdef CONFIG_INTERWORKING |
4513 | static char * anqp_add_hex(char *pos, char *end, const char *title, | |
4514 | struct wpabuf *data) | |
4515 | { | |
4516 | char *start = pos; | |
4517 | size_t i; | |
4518 | int ret; | |
4519 | const u8 *d; | |
4520 | ||
4521 | if (data == NULL) | |
4522 | return start; | |
4523 | ||
4524 | ret = os_snprintf(pos, end - pos, "%s=", title); | |
d85e1fc8 | 4525 | if (os_snprintf_error(end - pos, ret)) |
afc064fe JM |
4526 | return start; |
4527 | pos += ret; | |
4528 | ||
4529 | d = wpabuf_head_u8(data); | |
4530 | for (i = 0; i < wpabuf_len(data); i++) { | |
4531 | ret = os_snprintf(pos, end - pos, "%02x", *d++); | |
d85e1fc8 | 4532 | if (os_snprintf_error(end - pos, ret)) |
afc064fe JM |
4533 | return start; |
4534 | pos += ret; | |
4535 | } | |
4536 | ||
4537 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4538 | if (os_snprintf_error(end - pos, ret)) |
afc064fe JM |
4539 | return start; |
4540 | pos += ret; | |
4541 | ||
4542 | return pos; | |
4543 | } | |
4544 | #endif /* CONFIG_INTERWORKING */ | |
4545 | ||
4546 | ||
b54f4339 JM |
4547 | #ifdef CONFIG_FILS |
4548 | static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end) | |
4549 | { | |
4550 | char *start = pos; | |
4551 | const u8 *ie, *ie_end; | |
4552 | u16 info, realms; | |
4553 | int ret; | |
4554 | ||
4555 | ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION); | |
4556 | if (!ie) | |
4557 | return 0; | |
4558 | ie_end = ie + 2 + ie[1]; | |
4559 | ie += 2; | |
4560 | if (ie_end - ie < 2) | |
4561 | return -1; | |
4562 | ||
4563 | info = WPA_GET_LE16(ie); | |
4564 | ie += 2; | |
4565 | ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info); | |
4566 | if (os_snprintf_error(end - pos, ret)) | |
4567 | return 0; | |
4568 | pos += ret; | |
4569 | ||
4570 | if (info & BIT(7)) { | |
4571 | /* Cache Identifier Included */ | |
4572 | if (ie_end - ie < 2) | |
4573 | return -1; | |
4574 | ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n", | |
4575 | ie[0], ie[1]); | |
4576 | if (os_snprintf_error(end - pos, ret)) | |
4577 | return 0; | |
4578 | pos += ret; | |
4579 | ie += 2; | |
4580 | } | |
4581 | ||
4582 | if (info & BIT(8)) { | |
4583 | /* HESSID Included */ | |
4584 | if (ie_end - ie < ETH_ALEN) | |
4585 | return -1; | |
4586 | ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n", | |
4587 | MAC2STR(ie)); | |
4588 | if (os_snprintf_error(end - pos, ret)) | |
4589 | return 0; | |
4590 | pos += ret; | |
4591 | ie += ETH_ALEN; | |
4592 | } | |
4593 | ||
4594 | realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3; | |
4595 | if (realms) { | |
4596 | if (ie_end - ie < realms * 2) | |
4597 | return -1; | |
4598 | ret = os_snprintf(pos, end - pos, "fils_realms="); | |
4599 | if (os_snprintf_error(end - pos, ret)) | |
4600 | return 0; | |
4601 | pos += ret; | |
4602 | ||
4603 | ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2); | |
4604 | if (ret <= 0) | |
4605 | return 0; | |
4606 | pos += ret; | |
4607 | ie += realms * 2; | |
4608 | ret = os_snprintf(pos, end - pos, "\n"); | |
4609 | if (os_snprintf_error(end - pos, ret)) | |
4610 | return 0; | |
4611 | pos += ret; | |
4612 | } | |
4613 | ||
4614 | return pos - start; | |
4615 | } | |
4616 | #endif /* CONFIG_FILS */ | |
4617 | ||
4618 | ||
61ce9085 | 4619 | static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
5f97dd1c | 4620 | unsigned long mask, char *buf, size_t buflen) |
6fc6879b | 4621 | { |
6fc6879b | 4622 | size_t i; |
6fc6879b JM |
4623 | int ret; |
4624 | char *pos, *end; | |
e8b96490 | 4625 | const u8 *ie, *ie2, *osen_ie, *mesh, *owe; |
6fc6879b | 4626 | |
6fc6879b JM |
4627 | pos = buf; |
4628 | end = buf + buflen; | |
6fc6879b | 4629 | |
5f97dd1c DS |
4630 | if (mask & WPA_BSS_MASK_ID) { |
4631 | ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id); | |
d85e1fc8 | 4632 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4633 | return 0; |
6fc6879b JM |
4634 | pos += ret; |
4635 | } | |
4636 | ||
5f97dd1c DS |
4637 | if (mask & WPA_BSS_MASK_BSSID) { |
4638 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | |
4639 | MAC2STR(bss->bssid)); | |
d85e1fc8 | 4640 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4641 | return 0; |
4642 | pos += ret; | |
4643 | } | |
6fc6879b | 4644 | |
5f97dd1c DS |
4645 | if (mask & WPA_BSS_MASK_FREQ) { |
4646 | ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq); | |
d85e1fc8 | 4647 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4648 | return 0; |
4649 | pos += ret; | |
4650 | } | |
6fc6879b | 4651 | |
5f97dd1c DS |
4652 | if (mask & WPA_BSS_MASK_BEACON_INT) { |
4653 | ret = os_snprintf(pos, end - pos, "beacon_int=%d\n", | |
4654 | bss->beacon_int); | |
d85e1fc8 | 4655 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4656 | return 0; |
6fc6879b JM |
4657 | pos += ret; |
4658 | } | |
5f97dd1c DS |
4659 | |
4660 | if (mask & WPA_BSS_MASK_CAPABILITIES) { | |
4661 | ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n", | |
4662 | bss->caps); | |
d85e1fc8 | 4663 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4664 | return 0; |
6fc6879b JM |
4665 | pos += ret; |
4666 | } | |
5f97dd1c DS |
4667 | |
4668 | if (mask & WPA_BSS_MASK_QUAL) { | |
4669 | ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual); | |
d85e1fc8 | 4670 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4671 | return 0; |
bd1af96a JM |
4672 | pos += ret; |
4673 | } | |
5f97dd1c DS |
4674 | |
4675 | if (mask & WPA_BSS_MASK_NOISE) { | |
4676 | ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise); | |
d85e1fc8 | 4677 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4678 | return 0; |
cc81110d JM |
4679 | pos += ret; |
4680 | } | |
6fc6879b | 4681 | |
5f97dd1c DS |
4682 | if (mask & WPA_BSS_MASK_LEVEL) { |
4683 | ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level); | |
d85e1fc8 | 4684 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4685 | return 0; |
4686 | pos += ret; | |
4687 | } | |
6fc6879b | 4688 | |
5f97dd1c DS |
4689 | if (mask & WPA_BSS_MASK_TSF) { |
4690 | ret = os_snprintf(pos, end - pos, "tsf=%016llu\n", | |
4691 | (unsigned long long) bss->tsf); | |
d85e1fc8 | 4692 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4693 | return 0; |
4694 | pos += ret; | |
4695 | } | |
4696 | ||
4697 | if (mask & WPA_BSS_MASK_AGE) { | |
acb69cec | 4698 | struct os_reltime now; |
5f97dd1c | 4699 | |
acb69cec | 4700 | os_get_reltime(&now); |
5f97dd1c DS |
4701 | ret = os_snprintf(pos, end - pos, "age=%d\n", |
4702 | (int) (now.sec - bss->last_update.sec)); | |
d85e1fc8 | 4703 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4704 | return 0; |
4705 | pos += ret; | |
4706 | } | |
4707 | ||
4708 | if (mask & WPA_BSS_MASK_IE) { | |
4709 | ret = os_snprintf(pos, end - pos, "ie="); | |
d85e1fc8 | 4710 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4711 | return 0; |
4712 | pos += ret; | |
4713 | ||
4714 | ie = (const u8 *) (bss + 1); | |
4715 | for (i = 0; i < bss->ie_len; i++) { | |
4716 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); | |
d85e1fc8 | 4717 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4718 | return 0; |
4719 | pos += ret; | |
4720 | } | |
4721 | ||
4722 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4723 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4724 | return 0; |
4725 | pos += ret; | |
4726 | } | |
4727 | ||
4728 | if (mask & WPA_BSS_MASK_FLAGS) { | |
4729 | ret = os_snprintf(pos, end - pos, "flags="); | |
d85e1fc8 | 4730 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4731 | return 0; |
4732 | pos += ret; | |
4733 | ||
4a45dc19 SD |
4734 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
4735 | ||
5f97dd1c DS |
4736 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
4737 | if (ie) | |
4738 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, | |
4739 | 2 + ie[1]); | |
4740 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); | |
4741 | if (ie2) | |
4a45dc19 SD |
4742 | pos = wpa_supplicant_ie_txt(pos, end, |
4743 | mesh ? "RSN" : "WPA2", ie2, | |
5f97dd1c | 4744 | 2 + ie2[1]); |
0f8385e6 BG |
4745 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
4746 | if (osen_ie) | |
4747 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", | |
4748 | osen_ie, 2 + osen_ie[1]); | |
e8b96490 JM |
4749 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
4750 | if (owe) { | |
4751 | ret = os_snprintf( | |
4752 | pos, end - pos, | |
4753 | ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]"); | |
4754 | if (os_snprintf_error(end - pos, ret)) | |
4755 | return 0; | |
4756 | pos += ret; | |
4757 | } | |
5f97dd1c | 4758 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
0f8385e6 BG |
4759 | if (!ie && !ie2 && !osen_ie && |
4760 | (bss->caps & IEEE80211_CAP_PRIVACY)) { | |
5f97dd1c | 4761 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
d85e1fc8 | 4762 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4763 | return 0; |
4764 | pos += ret; | |
4765 | } | |
4a45dc19 SD |
4766 | |
4767 | if (mesh) { | |
4768 | ret = os_snprintf(pos, end - pos, "[MESH]"); | |
4769 | if (os_snprintf_error(end - pos, ret)) | |
4770 | return 0; | |
4771 | pos += ret; | |
4772 | } | |
4773 | ||
e403ba85 BS |
4774 | if (bss_is_dmg(bss)) { |
4775 | const char *s; | |
4776 | ret = os_snprintf(pos, end - pos, "[DMG]"); | |
d85e1fc8 | 4777 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4778 | return 0; |
4779 | pos += ret; | |
e403ba85 BS |
4780 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
4781 | case IEEE80211_CAP_DMG_IBSS: | |
4782 | s = "[IBSS]"; | |
4783 | break; | |
4784 | case IEEE80211_CAP_DMG_AP: | |
4785 | s = "[ESS]"; | |
4786 | break; | |
4787 | case IEEE80211_CAP_DMG_PBSS: | |
4788 | s = "[PBSS]"; | |
4789 | break; | |
4790 | default: | |
4791 | s = ""; | |
4792 | break; | |
4793 | } | |
4794 | ret = os_snprintf(pos, end - pos, "%s", s); | |
d85e1fc8 | 4795 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4796 | return 0; |
4797 | pos += ret; | |
e403ba85 BS |
4798 | } else { |
4799 | if (bss->caps & IEEE80211_CAP_IBSS) { | |
4800 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | |
d85e1fc8 | 4801 | if (os_snprintf_error(end - pos, ret)) |
e403ba85 BS |
4802 | return 0; |
4803 | pos += ret; | |
4804 | } | |
4805 | if (bss->caps & IEEE80211_CAP_ESS) { | |
4806 | ret = os_snprintf(pos, end - pos, "[ESS]"); | |
d85e1fc8 | 4807 | if (os_snprintf_error(end - pos, ret)) |
e403ba85 BS |
4808 | return 0; |
4809 | pos += ret; | |
4810 | } | |
5f97dd1c | 4811 | } |
bb50ae43 JM |
4812 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || |
4813 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { | |
5f97dd1c | 4814 | ret = os_snprintf(pos, end - pos, "[P2P]"); |
d85e1fc8 | 4815 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4816 | return 0; |
4817 | pos += ret; | |
4818 | } | |
64855b96 JM |
4819 | #ifdef CONFIG_HS20 |
4820 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) { | |
4821 | ret = os_snprintf(pos, end - pos, "[HS20]"); | |
d85e1fc8 | 4822 | if (os_snprintf_error(end - pos, ret)) |
ff486913 | 4823 | return 0; |
64855b96 JM |
4824 | pos += ret; |
4825 | } | |
4826 | #endif /* CONFIG_HS20 */ | |
7147a834 JM |
4827 | #ifdef CONFIG_FILS |
4828 | if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) { | |
4829 | ret = os_snprintf(pos, end - pos, "[FILS]"); | |
4830 | if (os_snprintf_error(end - pos, ret)) | |
4831 | return 0; | |
4832 | pos += ret; | |
4833 | } | |
4834 | #endif /* CONFIG_FILS */ | |
e6b0898d JM |
4835 | #ifdef CONFIG_FST |
4836 | if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) { | |
4837 | ret = os_snprintf(pos, end - pos, "[FST]"); | |
4838 | if (os_snprintf_error(end - pos, ret)) | |
4839 | return 0; | |
4840 | pos += ret; | |
4841 | } | |
4842 | #endif /* CONFIG_FST */ | |
ed87f6a8 | 4843 | if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) { |
e6b0898d JM |
4844 | ret = os_snprintf(pos, end - pos, "[UTF-8]"); |
4845 | if (os_snprintf_error(end - pos, ret)) | |
4846 | return 0; | |
4847 | pos += ret; | |
4848 | } | |
5f97dd1c DS |
4849 | |
4850 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4851 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4852 | return 0; |
4853 | pos += ret; | |
4854 | } | |
4855 | ||
4856 | if (mask & WPA_BSS_MASK_SSID) { | |
4857 | ret = os_snprintf(pos, end - pos, "ssid=%s\n", | |
4858 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | |
d85e1fc8 | 4859 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4860 | return 0; |
4861 | pos += ret; | |
4862 | } | |
6fc6879b | 4863 | |
611ed491 | 4864 | #ifdef CONFIG_WPS |
5f97dd1c DS |
4865 | if (mask & WPA_BSS_MASK_WPS_SCAN) { |
4866 | ie = (const u8 *) (bss + 1); | |
4867 | ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end); | |
fc078be2 | 4868 | if (ret >= end - pos) |
5f97dd1c | 4869 | return 0; |
fc078be2 JM |
4870 | if (ret > 0) |
4871 | pos += ret; | |
5f97dd1c | 4872 | } |
611ed491 JM |
4873 | #endif /* CONFIG_WPS */ |
4874 | ||
0c6b310e | 4875 | #ifdef CONFIG_P2P |
5f97dd1c DS |
4876 | if (mask & WPA_BSS_MASK_P2P_SCAN) { |
4877 | ie = (const u8 *) (bss + 1); | |
4878 | ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end); | |
3b208346 | 4879 | if (ret >= end - pos) |
5f97dd1c | 4880 | return 0; |
3b208346 JA |
4881 | if (ret > 0) |
4882 | pos += ret; | |
5f97dd1c | 4883 | } |
0c6b310e JM |
4884 | #endif /* CONFIG_P2P */ |
4885 | ||
337c781f JM |
4886 | #ifdef CONFIG_WIFI_DISPLAY |
4887 | if (mask & WPA_BSS_MASK_WIFI_DISPLAY) { | |
4888 | struct wpabuf *wfd; | |
4889 | ie = (const u8 *) (bss + 1); | |
4890 | wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len, | |
4891 | WFD_IE_VENDOR_TYPE); | |
4892 | if (wfd) { | |
4893 | ret = os_snprintf(pos, end - pos, "wfd_subelems="); | |
d85e1fc8 | 4894 | if (os_snprintf_error(end - pos, ret)) { |
5e6aa04b | 4895 | wpabuf_free(wfd); |
ff486913 | 4896 | return 0; |
5e6aa04b | 4897 | } |
337c781f JM |
4898 | pos += ret; |
4899 | ||
4900 | pos += wpa_snprintf_hex(pos, end - pos, | |
4901 | wpabuf_head(wfd), | |
4902 | wpabuf_len(wfd)); | |
4903 | wpabuf_free(wfd); | |
4904 | ||
4905 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4906 | if (os_snprintf_error(end - pos, ret)) |
ff486913 | 4907 | return 0; |
337c781f JM |
4908 | pos += ret; |
4909 | } | |
4910 | } | |
4911 | #endif /* CONFIG_WIFI_DISPLAY */ | |
4912 | ||
afc064fe | 4913 | #ifdef CONFIG_INTERWORKING |
476aed35 JM |
4914 | if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) { |
4915 | struct wpa_bss_anqp *anqp = bss->anqp; | |
8c4a1026 JM |
4916 | struct wpa_bss_anqp_elem *elem; |
4917 | ||
5ce6ac11 AN |
4918 | pos = anqp_add_hex(pos, end, "anqp_capability_list", |
4919 | anqp->capability_list); | |
5f97dd1c | 4920 | pos = anqp_add_hex(pos, end, "anqp_venue_name", |
476aed35 | 4921 | anqp->venue_name); |
5f97dd1c | 4922 | pos = anqp_add_hex(pos, end, "anqp_network_auth_type", |
476aed35 | 4923 | anqp->network_auth_type); |
5f97dd1c | 4924 | pos = anqp_add_hex(pos, end, "anqp_roaming_consortium", |
476aed35 | 4925 | anqp->roaming_consortium); |
5f97dd1c | 4926 | pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability", |
476aed35 | 4927 | anqp->ip_addr_type_availability); |
5f97dd1c | 4928 | pos = anqp_add_hex(pos, end, "anqp_nai_realm", |
476aed35 JM |
4929 | anqp->nai_realm); |
4930 | pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp); | |
5f97dd1c | 4931 | pos = anqp_add_hex(pos, end, "anqp_domain_name", |
476aed35 | 4932 | anqp->domain_name); |
9cad6186 JM |
4933 | pos = anqp_add_hex(pos, end, "anqp_fils_realm_info", |
4934 | anqp->fils_realm_info); | |
25471fe3 | 4935 | #ifdef CONFIG_HS20 |
185ada47 AN |
4936 | pos = anqp_add_hex(pos, end, "hs20_capability_list", |
4937 | anqp->hs20_capability_list); | |
25471fe3 | 4938 | pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name", |
476aed35 | 4939 | anqp->hs20_operator_friendly_name); |
25471fe3 | 4940 | pos = anqp_add_hex(pos, end, "hs20_wan_metrics", |
476aed35 | 4941 | anqp->hs20_wan_metrics); |
25471fe3 | 4942 | pos = anqp_add_hex(pos, end, "hs20_connection_capability", |
476aed35 | 4943 | anqp->hs20_connection_capability); |
1d2215fc JM |
4944 | pos = anqp_add_hex(pos, end, "hs20_operating_class", |
4945 | anqp->hs20_operating_class); | |
4946 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_list", | |
4947 | anqp->hs20_osu_providers_list); | |
6a8a04d7 JM |
4948 | pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata", |
4949 | anqp->hs20_operator_icon_metadata); | |
baf4c863 JM |
4950 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list", |
4951 | anqp->hs20_osu_providers_nai_list); | |
25471fe3 | 4952 | #endif /* CONFIG_HS20 */ |
8c4a1026 JM |
4953 | |
4954 | dl_list_for_each(elem, &anqp->anqp_elems, | |
4955 | struct wpa_bss_anqp_elem, list) { | |
4956 | char title[20]; | |
4957 | ||
4958 | os_snprintf(title, sizeof(title), "anqp[%u]", | |
4959 | elem->infoid); | |
4960 | pos = anqp_add_hex(pos, end, title, elem->payload); | |
4961 | } | |
5f97dd1c | 4962 | } |
afc064fe JM |
4963 | #endif /* CONFIG_INTERWORKING */ |
4964 | ||
79070906 MH |
4965 | #ifdef CONFIG_MESH |
4966 | if (mask & WPA_BSS_MASK_MESH_SCAN) { | |
4967 | ie = (const u8 *) (bss + 1); | |
4968 | ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end); | |
3b208346 | 4969 | if (ret >= end - pos) |
79070906 | 4970 | return 0; |
3b208346 JA |
4971 | if (ret > 0) |
4972 | pos += ret; | |
79070906 MH |
4973 | } |
4974 | #endif /* CONFIG_MESH */ | |
4975 | ||
1d747e2a JM |
4976 | if (mask & WPA_BSS_MASK_SNR) { |
4977 | ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr); | |
4978 | if (os_snprintf_error(end - pos, ret)) | |
4979 | return 0; | |
4980 | pos += ret; | |
4981 | } | |
4982 | ||
4983 | if (mask & WPA_BSS_MASK_EST_THROUGHPUT) { | |
4984 | ret = os_snprintf(pos, end - pos, "est_throughput=%d\n", | |
4985 | bss->est_throughput); | |
4986 | if (os_snprintf_error(end - pos, ret)) | |
4987 | return 0; | |
4988 | pos += ret; | |
4989 | } | |
4990 | ||
3794af2d AN |
4991 | #ifdef CONFIG_FST |
4992 | if (mask & WPA_BSS_MASK_FST) { | |
4993 | ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos); | |
4994 | if (ret < 0 || ret >= end - pos) | |
4995 | return 0; | |
4996 | pos += ret; | |
4997 | } | |
4998 | #endif /* CONFIG_FST */ | |
4999 | ||
71ac9345 JM |
5000 | if (mask & WPA_BSS_MASK_UPDATE_IDX) { |
5001 | ret = os_snprintf(pos, end - pos, "update_idx=%u\n", | |
5002 | bss->last_update_idx); | |
5003 | if (os_snprintf_error(end - pos, ret)) | |
5004 | return 0; | |
5005 | pos += ret; | |
5006 | } | |
5007 | ||
19810d29 JM |
5008 | if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) { |
5009 | ret = os_snprintf(pos, end - pos, "beacon_ie="); | |
5010 | if (os_snprintf_error(end - pos, ret)) | |
5011 | return 0; | |
5012 | pos += ret; | |
5013 | ||
5014 | ie = (const u8 *) (bss + 1); | |
5015 | ie += bss->ie_len; | |
5016 | for (i = 0; i < bss->beacon_ie_len; i++) { | |
5017 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); | |
5018 | if (os_snprintf_error(end - pos, ret)) | |
5019 | return 0; | |
5020 | pos += ret; | |
5021 | } | |
5022 | ||
5023 | ret = os_snprintf(pos, end - pos, "\n"); | |
5024 | if (os_snprintf_error(end - pos, ret)) | |
5025 | return 0; | |
5026 | pos += ret; | |
5027 | } | |
5028 | ||
b54f4339 JM |
5029 | #ifdef CONFIG_FILS |
5030 | if (mask & WPA_BSS_MASK_FILS_INDICATION) { | |
5031 | ret = print_fils_indication(bss, pos, end); | |
5032 | if (ret < 0) | |
5033 | return 0; | |
5034 | pos += ret; | |
5035 | } | |
5036 | #endif /* CONFIG_FILS */ | |
5037 | ||
c6673429 DS |
5038 | if (mask & WPA_BSS_MASK_DELIM) { |
5039 | ret = os_snprintf(pos, end - pos, "====\n"); | |
d85e1fc8 | 5040 | if (os_snprintf_error(end - pos, ret)) |
c6673429 DS |
5041 | return 0; |
5042 | pos += ret; | |
5043 | } | |
5044 | ||
6fc6879b JM |
5045 | return pos - buf; |
5046 | } | |
5047 | ||
5048 | ||
61ce9085 DS |
5049 | static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s, |
5050 | const char *cmd, char *buf, | |
5051 | size_t buflen) | |
5052 | { | |
5053 | u8 bssid[ETH_ALEN]; | |
5054 | size_t i; | |
5055 | struct wpa_bss *bss; | |
eff1a95b DS |
5056 | struct wpa_bss *bsslast = NULL; |
5057 | struct dl_list *next; | |
5058 | int ret = 0; | |
5059 | int len; | |
1d399771 | 5060 | char *ctmp, *end = buf + buflen; |
5f97dd1c | 5061 | unsigned long mask = WPA_BSS_MASK_ALL; |
61ce9085 | 5062 | |
eff1a95b DS |
5063 | if (os_strncmp(cmd, "RANGE=", 6) == 0) { |
5064 | if (os_strncmp(cmd + 6, "ALL", 3) == 0) { | |
5065 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, | |
5066 | list_id); | |
5067 | bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss, | |
5068 | list_id); | |
5069 | } else { /* N1-N2 */ | |
5070 | unsigned int id1, id2; | |
5071 | ||
5072 | if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) { | |
5073 | wpa_printf(MSG_INFO, "Wrong BSS range " | |
5074 | "format"); | |
5075 | return 0; | |
5076 | } | |
5077 | ||
9f42d49c AS |
5078 | if (*(cmd + 6) == '-') |
5079 | id1 = 0; | |
5080 | else | |
5081 | id1 = atoi(cmd + 6); | |
5082 | ctmp++; | |
5083 | if (*ctmp >= '0' && *ctmp <= '9') | |
5084 | id2 = atoi(ctmp); | |
5085 | else | |
5086 | id2 = (unsigned int) -1; | |
5087 | bss = wpa_bss_get_id_range(wpa_s, id1, id2); | |
5088 | if (id2 == (unsigned int) -1) | |
eff1a95b DS |
5089 | bsslast = dl_list_last(&wpa_s->bss_id, |
5090 | struct wpa_bss, | |
5091 | list_id); | |
5092 | else { | |
5093 | bsslast = wpa_bss_get_id(wpa_s, id2); | |
5094 | if (bsslast == NULL && bss && id2 > id1) { | |
5095 | struct wpa_bss *tmp = bss; | |
5096 | for (;;) { | |
5097 | next = tmp->list_id.next; | |
5098 | if (next == &wpa_s->bss_id) | |
5099 | break; | |
5100 | tmp = dl_list_entry( | |
5101 | next, struct wpa_bss, | |
5102 | list_id); | |
5103 | if (tmp->id > id2) | |
5104 | break; | |
5105 | bsslast = tmp; | |
5106 | } | |
5107 | } | |
5108 | } | |
5109 | } | |
f330b4b4 | 5110 | } else if (os_strncmp(cmd, "FIRST", 5) == 0) |
51a0c3d4 | 5111 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id); |
cc03d0fe AS |
5112 | else if (os_strncmp(cmd, "LAST", 4) == 0) |
5113 | bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id); | |
61ce9085 DS |
5114 | else if (os_strncmp(cmd, "ID-", 3) == 0) { |
5115 | i = atoi(cmd + 3); | |
5116 | bss = wpa_bss_get_id(wpa_s, i); | |
5117 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | |
5118 | i = atoi(cmd + 5); | |
5119 | bss = wpa_bss_get_id(wpa_s, i); | |
5120 | if (bss) { | |
eff1a95b | 5121 | next = bss->list_id.next; |
61ce9085 DS |
5122 | if (next == &wpa_s->bss_id) |
5123 | bss = NULL; | |
5124 | else | |
5125 | bss = dl_list_entry(next, struct wpa_bss, | |
5126 | list_id); | |
5127 | } | |
9187b13a JC |
5128 | } else if (os_strncmp(cmd, "CURRENT", 7) == 0) { |
5129 | bss = wpa_s->current_bss; | |
61ce9085 DS |
5130 | #ifdef CONFIG_P2P |
5131 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | |
5132 | if (hwaddr_aton(cmd + 13, bssid) == 0) | |
5133 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid); | |
5134 | else | |
5135 | bss = NULL; | |
5136 | #endif /* CONFIG_P2P */ | |
5137 | } else if (hwaddr_aton(cmd, bssid) == 0) | |
5138 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
5139 | else { | |
5140 | struct wpa_bss *tmp; | |
5141 | i = atoi(cmd); | |
5142 | bss = NULL; | |
5143 | dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id) | |
5144 | { | |
01d01a31 | 5145 | if (i == 0) { |
61ce9085 DS |
5146 | bss = tmp; |
5147 | break; | |
5148 | } | |
01d01a31 | 5149 | i--; |
61ce9085 DS |
5150 | } |
5151 | } | |
5152 | ||
5f97dd1c DS |
5153 | if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) { |
5154 | mask = strtoul(ctmp + 5, NULL, 0x10); | |
5155 | if (mask == 0) | |
5156 | mask = WPA_BSS_MASK_ALL; | |
5157 | } | |
5158 | ||
61ce9085 DS |
5159 | if (bss == NULL) |
5160 | return 0; | |
5161 | ||
eff1a95b DS |
5162 | if (bsslast == NULL) |
5163 | bsslast = bss; | |
5164 | do { | |
5165 | len = print_bss_info(wpa_s, bss, mask, buf, buflen); | |
5166 | ret += len; | |
5167 | buf += len; | |
5168 | buflen -= len; | |
cfd42c94 DS |
5169 | if (bss == bsslast) { |
5170 | if ((mask & WPA_BSS_MASK_DELIM) && len && | |
5171 | (bss == dl_list_last(&wpa_s->bss_id, | |
1d399771 JM |
5172 | struct wpa_bss, list_id))) { |
5173 | int res; | |
5174 | ||
5175 | res = os_snprintf(buf - 5, end - buf + 5, | |
5176 | "####\n"); | |
5177 | if (os_snprintf_error(end - buf + 5, res)) { | |
5178 | wpa_printf(MSG_DEBUG, | |
5179 | "Could not add end delim"); | |
5180 | } | |
5181 | } | |
eff1a95b | 5182 | break; |
cfd42c94 | 5183 | } |
eff1a95b DS |
5184 | next = bss->list_id.next; |
5185 | if (next == &wpa_s->bss_id) | |
5186 | break; | |
5187 | bss = dl_list_entry(next, struct wpa_bss, list_id); | |
5188 | } while (bss && len); | |
5189 | ||
5190 | return ret; | |
61ce9085 DS |
5191 | } |
5192 | ||
5193 | ||
6fc6879b JM |
5194 | static int wpa_supplicant_ctrl_iface_ap_scan( |
5195 | struct wpa_supplicant *wpa_s, char *cmd) | |
5196 | { | |
5197 | int ap_scan = atoi(cmd); | |
86b89452 | 5198 | return wpa_supplicant_set_ap_scan(wpa_s, ap_scan); |
6fc6879b JM |
5199 | } |
5200 | ||
5201 | ||
67b9bd08 DS |
5202 | static int wpa_supplicant_ctrl_iface_scan_interval( |
5203 | struct wpa_supplicant *wpa_s, char *cmd) | |
5204 | { | |
5205 | int scan_int = atoi(cmd); | |
c6e86b63 | 5206 | return wpa_supplicant_set_scan_interval(wpa_s, scan_int); |
67b9bd08 DS |
5207 | } |
5208 | ||
5209 | ||
78633c37 SL |
5210 | static int wpa_supplicant_ctrl_iface_bss_expire_age( |
5211 | struct wpa_supplicant *wpa_s, char *cmd) | |
5212 | { | |
5213 | int expire_age = atoi(cmd); | |
5214 | return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age); | |
5215 | } | |
5216 | ||
5217 | ||
5218 | static int wpa_supplicant_ctrl_iface_bss_expire_count( | |
5219 | struct wpa_supplicant *wpa_s, char *cmd) | |
5220 | { | |
5221 | int expire_count = atoi(cmd); | |
5222 | return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count); | |
5223 | } | |
5224 | ||
5225 | ||
a1144000 | 5226 | static void wpa_supplicant_ctrl_iface_bss_flush( |
39ee845f DS |
5227 | struct wpa_supplicant *wpa_s, char *cmd) |
5228 | { | |
5229 | int flush_age = atoi(cmd); | |
5230 | ||
5231 | if (flush_age == 0) | |
5232 | wpa_bss_flush(wpa_s); | |
5233 | else | |
5234 | wpa_bss_flush_by_age(wpa_s, flush_age); | |
39ee845f DS |
5235 | } |
5236 | ||
5237 | ||
9ff4de6d | 5238 | #ifdef CONFIG_TESTING_OPTIONS |
32d5295f JM |
5239 | static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s) |
5240 | { | |
32d5295f JM |
5241 | wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication"); |
5242 | /* MLME-DELETEKEYS.request */ | |
0382097e JM |
5243 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0); |
5244 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0); | |
5245 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0); | |
5246 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0); | |
0382097e JM |
5247 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0); |
5248 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0); | |
32d5295f JM |
5249 | |
5250 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL, | |
5251 | 0); | |
5252 | /* MLME-SETPROTECTION.request(None) */ | |
5253 | wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid, | |
5254 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, | |
5255 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); | |
5256 | wpa_sm_drop_sa(wpa_s->wpa); | |
5257 | } | |
9ff4de6d | 5258 | #endif /* CONFIG_TESTING_OPTIONS */ |
32d5295f JM |
5259 | |
5260 | ||
86d4f806 JM |
5261 | static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s, |
5262 | char *addr) | |
5263 | { | |
90b8fc8f JM |
5264 | #ifdef CONFIG_NO_SCAN_PROCESSING |
5265 | return -1; | |
5266 | #else /* CONFIG_NO_SCAN_PROCESSING */ | |
86d4f806 JM |
5267 | u8 bssid[ETH_ALEN]; |
5268 | struct wpa_bss *bss; | |
5269 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
5270 | ||
5271 | if (hwaddr_aton(addr, bssid)) { | |
5272 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid " | |
5273 | "address '%s'", addr); | |
5274 | return -1; | |
5275 | } | |
5276 | ||
5277 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid)); | |
5278 | ||
2f9b66d3 JM |
5279 | if (!ssid) { |
5280 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network " | |
5281 | "configuration known for the target AP"); | |
5282 | return -1; | |
5283 | } | |
5284 | ||
5285 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); | |
86d4f806 JM |
5286 | if (!bss) { |
5287 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found " | |
5288 | "from BSS table"); | |
5289 | return -1; | |
5290 | } | |
5291 | ||
5292 | /* | |
5293 | * TODO: Find best network configuration block from configuration to | |
5294 | * allow roaming to other networks | |
5295 | */ | |
5296 | ||
86d4f806 JM |
5297 | wpa_s->reassociate = 1; |
5298 | wpa_supplicant_connect(wpa_s, bss, ssid); | |
5299 | ||
5300 | return 0; | |
90b8fc8f | 5301 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
86d4f806 JM |
5302 | } |
5303 | ||
5304 | ||
b563b388 JM |
5305 | #ifdef CONFIG_P2P |
5306 | static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd) | |
5307 | { | |
5308 | unsigned int timeout = atoi(cmd); | |
5309 | enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL; | |
6d92fa6e | 5310 | u8 dev_id[ETH_ALEN], *_dev_id = NULL; |
2b384109 | 5311 | u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL; |
6d92fa6e | 5312 | char *pos; |
05a77b3b | 5313 | unsigned int search_delay; |
9542f21f | 5314 | const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL; |
51775096 | 5315 | u8 seek_count = 0; |
fa9f381f | 5316 | int freq = 0; |
b563b388 | 5317 | |
e9eb648e JM |
5318 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
5319 | wpa_dbg(wpa_s, MSG_INFO, | |
5320 | "Reject P2P_FIND since interface is disabled"); | |
5321 | return -1; | |
5322 | } | |
b563b388 JM |
5323 | if (os_strstr(cmd, "type=social")) |
5324 | type = P2P_FIND_ONLY_SOCIAL; | |
5325 | else if (os_strstr(cmd, "type=progressive")) | |
5326 | type = P2P_FIND_PROGRESSIVE; | |
5327 | ||
6d92fa6e JM |
5328 | pos = os_strstr(cmd, "dev_id="); |
5329 | if (pos) { | |
5330 | pos += 7; | |
5331 | if (hwaddr_aton(pos, dev_id)) | |
5332 | return -1; | |
5333 | _dev_id = dev_id; | |
5334 | } | |
5335 | ||
2b384109 JM |
5336 | pos = os_strstr(cmd, "dev_type="); |
5337 | if (pos) { | |
5338 | pos += 9; | |
5339 | if (wps_dev_type_str2bin(pos, dev_type) < 0) | |
5340 | return -1; | |
5341 | _dev_type = dev_type; | |
5342 | } | |
5343 | ||
37448ede JM |
5344 | pos = os_strstr(cmd, "delay="); |
5345 | if (pos) { | |
5346 | pos += 6; | |
5347 | search_delay = atoi(pos); | |
05a77b3b JM |
5348 | } else |
5349 | search_delay = wpas_p2p_search_delay(wpa_s); | |
37448ede | 5350 | |
a9ea609c SM |
5351 | pos = os_strstr(cmd, "freq="); |
5352 | if (pos) { | |
5353 | pos += 5; | |
5354 | freq = atoi(pos); | |
5355 | if (freq <= 0) | |
5356 | return -1; | |
5357 | } | |
5358 | ||
51775096 BG |
5359 | /* Must be searched for last, because it adds nul termination */ |
5360 | pos = os_strstr(cmd, " seek="); | |
129b6216 JM |
5361 | if (pos) |
5362 | pos += 6; | |
51775096 BG |
5363 | while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) { |
5364 | char *term; | |
5365 | ||
129b6216 | 5366 | _seek[seek_count++] = pos; |
9542f21f | 5367 | seek = _seek; |
129b6216 JM |
5368 | term = os_strchr(pos, ' '); |
5369 | if (!term) | |
5370 | break; | |
5371 | *term = '\0'; | |
5372 | pos = os_strstr(term + 1, "seek="); | |
5373 | if (pos) | |
5374 | pos += 5; | |
51775096 | 5375 | } |
9542f21f JM |
5376 | if (seek_count > P2P_MAX_QUERY_HASH) { |
5377 | seek[0] = NULL; | |
5378 | seek_count = 1; | |
5379 | } | |
51775096 | 5380 | |
2b384109 | 5381 | return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type, |
fa9f381f | 5382 | _dev_id, search_delay, seek_count, seek, freq); |
b563b388 JM |
5383 | } |
5384 | ||
5385 | ||
e2b7fbf2 MS |
5386 | static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt) |
5387 | { | |
5388 | const char *last = NULL; | |
5389 | const char *token; | |
5390 | long int token_len; | |
5391 | unsigned int i; | |
5392 | ||
5393 | /* Expected predefined CPT names delimited by ':' */ | |
5394 | for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) { | |
5395 | if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) { | |
5396 | wpa_printf(MSG_ERROR, | |
5397 | "P2PS: CPT name list is too long, expected up to %d names", | |
5398 | P2PS_FEATURE_CAPAB_CPT_MAX); | |
5399 | cpt[0] = 0; | |
5400 | return -1; | |
5401 | } | |
5402 | ||
5403 | token_len = last - token; | |
5404 | ||
5405 | if (token_len == 3 && | |
5406 | os_memcmp(token, "UDP", token_len) == 0) { | |
5407 | cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; | |
5408 | } else if (token_len == 3 && | |
5409 | os_memcmp(token, "MAC", token_len) == 0) { | |
5410 | cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT; | |
5411 | } else { | |
5412 | wpa_printf(MSG_ERROR, | |
5413 | "P2PS: Unsupported CPT name '%s'", token); | |
5414 | cpt[0] = 0; | |
5415 | return -1; | |
5416 | } | |
5417 | ||
640b0b93 | 5418 | if (isblank((unsigned char) *last)) { |
e2b7fbf2 MS |
5419 | i++; |
5420 | break; | |
5421 | } | |
5422 | } | |
5423 | cpt[i] = 0; | |
5424 | return 0; | |
5425 | } | |
5426 | ||
5427 | ||
f309c18e KV |
5428 | static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd) |
5429 | { | |
5430 | struct p2ps_provision *p2ps_prov; | |
5431 | char *pos; | |
5432 | size_t info_len = 0; | |
5433 | char *info = NULL; | |
5434 | u8 role = P2PS_SETUP_NONE; | |
5435 | long long unsigned val; | |
0670de74 | 5436 | int i; |
f309c18e KV |
5437 | |
5438 | pos = os_strstr(cmd, "info="); | |
5439 | if (pos) { | |
5440 | pos += 5; | |
5441 | info_len = os_strlen(pos); | |
5442 | ||
5443 | if (info_len) { | |
5444 | info = os_malloc(info_len + 1); | |
5445 | if (info) { | |
5446 | info_len = utf8_unescape(pos, info_len, | |
5447 | info, info_len + 1); | |
5448 | } else | |
5449 | info_len = 0; | |
5450 | } | |
5451 | } | |
5452 | ||
5453 | p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1); | |
5454 | if (p2ps_prov == NULL) { | |
5455 | os_free(info); | |
5456 | return NULL; | |
5457 | } | |
5458 | ||
5459 | if (info) { | |
5460 | os_memcpy(p2ps_prov->info, info, info_len); | |
5461 | p2ps_prov->info[info_len] = '\0'; | |
5462 | os_free(info); | |
5463 | } | |
5464 | ||
5465 | pos = os_strstr(cmd, "status="); | |
5466 | if (pos) | |
5467 | p2ps_prov->status = atoi(pos + 7); | |
5468 | else | |
5469 | p2ps_prov->status = -1; | |
5470 | ||
5471 | pos = os_strstr(cmd, "adv_id="); | |
5472 | if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL) | |
5473 | goto invalid_args; | |
5474 | p2ps_prov->adv_id = val; | |
5475 | ||
5476 | pos = os_strstr(cmd, "method="); | |
5477 | if (pos) | |
5478 | p2ps_prov->method = strtol(pos + 7, NULL, 16); | |
5479 | else | |
5480 | p2ps_prov->method = 0; | |
5481 | ||
5482 | pos = os_strstr(cmd, "session="); | |
5483 | if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL) | |
5484 | goto invalid_args; | |
5485 | p2ps_prov->session_id = val; | |
5486 | ||
5487 | pos = os_strstr(cmd, "adv_mac="); | |
5488 | if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac)) | |
5489 | goto invalid_args; | |
5490 | ||
5491 | pos = os_strstr(cmd, "session_mac="); | |
5492 | if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac)) | |
5493 | goto invalid_args; | |
5494 | ||
0670de74 MS |
5495 | pos = os_strstr(cmd, "cpt="); |
5496 | if (pos) { | |
5497 | if (p2ps_ctrl_parse_cpt_priority(pos + 4, | |
5498 | p2ps_prov->cpt_priority)) | |
5499 | goto invalid_args; | |
5500 | } else { | |
5501 | p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; | |
5502 | } | |
5503 | ||
5504 | for (i = 0; p2ps_prov->cpt_priority[i]; i++) | |
5505 | p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i]; | |
5506 | ||
f309c18e KV |
5507 | /* force conncap with tstCap (no sanity checks) */ |
5508 | pos = os_strstr(cmd, "tstCap="); | |
5509 | if (pos) { | |
5510 | role = strtol(pos + 7, NULL, 16); | |
5511 | } else { | |
5512 | pos = os_strstr(cmd, "role="); | |
5513 | if (pos) { | |
5514 | role = strtol(pos + 5, NULL, 16); | |
5515 | if (role != P2PS_SETUP_CLIENT && | |
5516 | role != P2PS_SETUP_GROUP_OWNER) | |
5517 | role = P2PS_SETUP_NONE; | |
5518 | } | |
5519 | } | |
5520 | p2ps_prov->role = role; | |
5521 | ||
5522 | return p2ps_prov; | |
5523 | ||
5524 | invalid_args: | |
5525 | os_free(p2ps_prov); | |
5526 | return NULL; | |
5527 | } | |
5528 | ||
5529 | ||
5530 | static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd) | |
5531 | { | |
5532 | u8 addr[ETH_ALEN]; | |
5533 | struct p2ps_provision *p2ps_prov; | |
5534 | char *pos; | |
5535 | ||
5536 | /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */ | |
5537 | ||
5538 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); | |
5539 | ||
5540 | if (hwaddr_aton(cmd, addr)) | |
5541 | return -1; | |
5542 | ||
5543 | pos = cmd + 17; | |
5544 | if (*pos != ' ') | |
5545 | return -1; | |
5546 | ||
5547 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); | |
5548 | if (!p2ps_prov) | |
5549 | return -1; | |
5550 | ||
5551 | if (p2ps_prov->status < 0) { | |
5552 | os_free(p2ps_prov); | |
5553 | return -1; | |
5554 | } | |
5555 | ||
5556 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, | |
5557 | p2ps_prov); | |
5558 | } | |
5559 | ||
5560 | ||
5561 | static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd) | |
5562 | { | |
5563 | u8 addr[ETH_ALEN]; | |
5564 | struct p2ps_provision *p2ps_prov; | |
5565 | char *pos; | |
5566 | ||
5567 | /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap> | |
5568 | * session=<ses_id> mac=<ses_mac> [info=<infodata>] | |
5569 | */ | |
5570 | ||
5571 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); | |
5572 | if (hwaddr_aton(cmd, addr)) | |
5573 | return -1; | |
5574 | ||
5575 | pos = cmd + 17; | |
5576 | if (*pos != ' ') | |
5577 | return -1; | |
5578 | ||
5579 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); | |
5580 | if (!p2ps_prov) | |
5581 | return -1; | |
5582 | ||
93f22b45 MS |
5583 | p2ps_prov->pd_seeker = 1; |
5584 | ||
f309c18e KV |
5585 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, |
5586 | p2ps_prov); | |
5587 | } | |
5588 | ||
5589 | ||
c27f4c90 AK |
5590 | static int parse_freq(int chwidth, int freq2) |
5591 | { | |
5592 | if (freq2 < 0) | |
5593 | return -1; | |
5594 | if (freq2) | |
464dcfd0 | 5595 | return CHANWIDTH_80P80MHZ; |
c27f4c90 AK |
5596 | |
5597 | switch (chwidth) { | |
5598 | case 0: | |
5599 | case 20: | |
5600 | case 40: | |
464dcfd0 | 5601 | return CHANWIDTH_USE_HT; |
c27f4c90 | 5602 | case 80: |
464dcfd0 | 5603 | return CHANWIDTH_80MHZ; |
c27f4c90 | 5604 | case 160: |
464dcfd0 | 5605 | return CHANWIDTH_160MHZ; |
c27f4c90 AK |
5606 | default: |
5607 | wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d", | |
5608 | chwidth); | |
5609 | return -1; | |
5610 | } | |
5611 | } | |
5612 | ||
5613 | ||
b563b388 JM |
5614 | static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd, |
5615 | char *buf, size_t buflen) | |
5616 | { | |
5617 | u8 addr[ETH_ALEN]; | |
5618 | char *pos, *pos2; | |
5619 | char *pin = NULL; | |
5620 | enum p2p_wps_method wps_method; | |
5621 | int new_pin; | |
5622 | int ret; | |
23c84252 | 5623 | int persistent_group, persistent_id = -1; |
b563b388 JM |
5624 | int join; |
5625 | int auth; | |
b31be3a0 | 5626 | int automatic; |
b563b388 JM |
5627 | int go_intent = -1; |
5628 | int freq = 0; | |
3bc462cb | 5629 | int pd; |
c27f4c90 | 5630 | int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0; |
8edd9f10 JM |
5631 | u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL; |
5632 | size_t group_ssid_len = 0; | |
5a3319ab | 5633 | int he; |
b563b388 | 5634 | |
bdf0518b JM |
5635 | if (!wpa_s->global->p2p_init_wpa_s) |
5636 | return -1; | |
5637 | if (wpa_s->global->p2p_init_wpa_s != wpa_s) { | |
5638 | wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s", | |
5639 | wpa_s->global->p2p_init_wpa_s->ifname); | |
5640 | wpa_s = wpa_s->global->p2p_init_wpa_s; | |
5641 | } | |
5642 | ||
4f88fc04 | 5643 | /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps] |
23c84252 | 5644 | * [persistent|persistent=<network id>] |
e2308e4b | 5645 | * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] |
5a3319ab | 5646 | * [ht40] [vht] [he] [auto] [ssid=<hexdump>] */ |
b563b388 JM |
5647 | |
5648 | if (hwaddr_aton(cmd, addr)) | |
5649 | return -1; | |
5650 | ||
5651 | pos = cmd + 17; | |
5652 | if (*pos != ' ') | |
5653 | return -1; | |
5654 | pos++; | |
5655 | ||
5656 | persistent_group = os_strstr(pos, " persistent") != NULL; | |
23c84252 JM |
5657 | pos2 = os_strstr(pos, " persistent="); |
5658 | if (pos2) { | |
5659 | struct wpa_ssid *ssid; | |
5660 | persistent_id = atoi(pos2 + 12); | |
5661 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); | |
5662 | if (ssid == NULL || ssid->disabled != 2 || | |
5663 | ssid->mode != WPAS_MODE_P2P_GO) { | |
5664 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
5665 | "SSID id=%d for persistent P2P group (GO)", | |
5666 | persistent_id); | |
5667 | return -1; | |
5668 | } | |
5669 | } | |
b563b388 JM |
5670 | join = os_strstr(pos, " join") != NULL; |
5671 | auth = os_strstr(pos, " auth") != NULL; | |
b31be3a0 | 5672 | automatic = os_strstr(pos, " auto") != NULL; |
3bc462cb | 5673 | pd = os_strstr(pos, " provdisc") != NULL; |
20ea1ca4 EP |
5674 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
5675 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | |
5676 | vht; | |
5a3319ab | 5677 | he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he; |
b563b388 JM |
5678 | |
5679 | pos2 = os_strstr(pos, " go_intent="); | |
5680 | if (pos2) { | |
5681 | pos2 += 11; | |
5682 | go_intent = atoi(pos2); | |
5683 | if (go_intent < 0 || go_intent > 15) | |
5684 | return -1; | |
5685 | } | |
5686 | ||
5687 | pos2 = os_strstr(pos, " freq="); | |
5688 | if (pos2) { | |
5689 | pos2 += 6; | |
5690 | freq = atoi(pos2); | |
5691 | if (freq <= 0) | |
5692 | return -1; | |
5693 | } | |
5694 | ||
c27f4c90 AK |
5695 | pos2 = os_strstr(pos, " freq2="); |
5696 | if (pos2) | |
5697 | freq2 = atoi(pos2 + 7); | |
5698 | ||
5699 | pos2 = os_strstr(pos, " max_oper_chwidth="); | |
5700 | if (pos2) | |
5701 | chwidth = atoi(pos2 + 18); | |
5702 | ||
5703 | max_oper_chwidth = parse_freq(chwidth, freq2); | |
5704 | if (max_oper_chwidth < 0) | |
5705 | return -1; | |
5706 | ||
8edd9f10 JM |
5707 | pos2 = os_strstr(pos, " ssid="); |
5708 | if (pos2) { | |
5709 | char *end; | |
5710 | ||
5711 | pos2 += 6; | |
5712 | end = os_strchr(pos2, ' '); | |
5713 | if (!end) | |
5714 | group_ssid_len = os_strlen(pos2) / 2; | |
5715 | else | |
5716 | group_ssid_len = (end - pos2) / 2; | |
5717 | if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN || | |
5718 | hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0) | |
5719 | return -1; | |
5720 | group_ssid = _group_ssid; | |
5721 | } | |
5722 | ||
b563b388 JM |
5723 | if (os_strncmp(pos, "pin", 3) == 0) { |
5724 | /* Request random PIN (to be displayed) and enable the PIN */ | |
5725 | wps_method = WPS_PIN_DISPLAY; | |
5726 | } else if (os_strncmp(pos, "pbc", 3) == 0) { | |
5727 | wps_method = WPS_PBC; | |
31d7fb14 PK |
5728 | } else if (os_strstr(pos, "p2ps") != NULL) { |
5729 | wps_method = WPS_P2PS; | |
b563b388 JM |
5730 | } else { |
5731 | pin = pos; | |
5732 | pos = os_strchr(pin, ' '); | |
5733 | wps_method = WPS_PIN_KEYPAD; | |
5734 | if (pos) { | |
5735 | *pos++ = '\0'; | |
07fecd39 | 5736 | if (os_strncmp(pos, "display", 7) == 0) |
b563b388 JM |
5737 | wps_method = WPS_PIN_DISPLAY; |
5738 | } | |
dcc33057 | 5739 | if (!wps_pin_str_valid(pin)) { |
36ebf7a1 MH |
5740 | os_memcpy(buf, "FAIL-INVALID-PIN\n", 17); |
5741 | return 17; | |
5742 | } | |
b563b388 JM |
5743 | } |
5744 | ||
5745 | new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method, | |
b31be3a0 | 5746 | persistent_group, automatic, join, |
c27f4c90 | 5747 | auth, go_intent, freq, freq2, persistent_id, |
5a3319ab | 5748 | pd, ht40, vht, max_oper_chwidth, he, |
8edd9f10 | 5749 | group_ssid, group_ssid_len); |
d054a462 JM |
5750 | if (new_pin == -2) { |
5751 | os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25); | |
5752 | return 25; | |
5753 | } | |
5754 | if (new_pin == -3) { | |
5755 | os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25); | |
5756 | return 25; | |
5757 | } | |
b563b388 JM |
5758 | if (new_pin < 0) |
5759 | return -1; | |
5760 | if (wps_method == WPS_PIN_DISPLAY && pin == NULL) { | |
5761 | ret = os_snprintf(buf, buflen, "%08d", new_pin); | |
d85e1fc8 | 5762 | if (os_snprintf_error(buflen, ret)) |
b563b388 JM |
5763 | return -1; |
5764 | return ret; | |
5765 | } | |
5766 | ||
5767 | os_memcpy(buf, "OK\n", 3); | |
5768 | return 3; | |
5769 | } | |
5770 | ||
5771 | ||
5772 | static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd) | |
5773 | { | |
5774 | unsigned int timeout = atoi(cmd); | |
e9eb648e JM |
5775 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
5776 | wpa_dbg(wpa_s, MSG_INFO, | |
5777 | "Reject P2P_LISTEN since interface is disabled"); | |
5778 | return -1; | |
5779 | } | |
b563b388 JM |
5780 | return wpas_p2p_listen(wpa_s, timeout); |
5781 | } | |
5782 | ||
5783 | ||
5784 | static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) | |
5785 | { | |
5786 | u8 addr[ETH_ALEN]; | |
5787 | char *pos; | |
0918c4bf | 5788 | enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG; |
b563b388 | 5789 | |
0918c4bf | 5790 | /* <addr> <config method> [join|auto] */ |
b563b388 JM |
5791 | |
5792 | if (hwaddr_aton(cmd, addr)) | |
5793 | return -1; | |
5794 | ||
5795 | pos = cmd + 17; | |
5796 | if (*pos != ' ') | |
5797 | return -1; | |
5798 | pos++; | |
5799 | ||
0918c4bf JM |
5800 | if (os_strstr(pos, " join") != NULL) |
5801 | use = WPAS_P2P_PD_FOR_JOIN; | |
5802 | else if (os_strstr(pos, " auto") != NULL) | |
5803 | use = WPAS_P2P_PD_AUTO; | |
5804 | ||
6d908514 | 5805 | return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL); |
b563b388 JM |
5806 | } |
5807 | ||
5808 | ||
5809 | static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf, | |
5810 | size_t buflen) | |
5811 | { | |
5812 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
5813 | ||
5814 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || | |
5815 | ssid->passphrase == NULL) | |
5816 | return -1; | |
5817 | ||
5818 | os_strlcpy(buf, ssid->passphrase, buflen); | |
5819 | return os_strlen(buf); | |
5820 | } | |
5821 | ||
5822 | ||
5823 | static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd, | |
5824 | char *buf, size_t buflen) | |
5825 | { | |
5826 | u64 ref; | |
5827 | int res; | |
5828 | u8 dst_buf[ETH_ALEN], *dst; | |
5829 | struct wpabuf *tlvs; | |
5830 | char *pos; | |
5831 | size_t len; | |
5832 | ||
5833 | if (hwaddr_aton(cmd, dst_buf)) | |
5834 | return -1; | |
5835 | dst = dst_buf; | |
5836 | if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 && | |
5837 | dst[3] == 0 && dst[4] == 0 && dst[5] == 0) | |
5838 | dst = NULL; | |
5839 | pos = cmd + 17; | |
5840 | if (*pos != ' ') | |
5841 | return -1; | |
5842 | pos++; | |
5843 | ||
5844 | if (os_strncmp(pos, "upnp ", 5) == 0) { | |
5845 | u8 version; | |
5846 | pos += 5; | |
5847 | if (hexstr2bin(pos, &version, 1) < 0) | |
5848 | return -1; | |
5849 | pos += 2; | |
5850 | if (*pos != ' ') | |
5851 | return -1; | |
5852 | pos++; | |
7165c5dc | 5853 | ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos); |
347d6a5b JM |
5854 | #ifdef CONFIG_WIFI_DISPLAY |
5855 | } else if (os_strncmp(pos, "wifi-display ", 13) == 0) { | |
5856 | ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13); | |
5857 | #endif /* CONFIG_WIFI_DISPLAY */ | |
5a4102ce KV |
5858 | } else if (os_strncmp(pos, "asp ", 4) == 0) { |
5859 | char *svc_str; | |
5860 | char *svc_info = NULL; | |
5861 | u32 id; | |
5862 | ||
5863 | pos += 4; | |
5864 | if (sscanf(pos, "%x", &id) != 1 || id > 0xff) | |
5865 | return -1; | |
5866 | ||
5867 | pos = os_strchr(pos, ' '); | |
5868 | if (pos == NULL || pos[1] == '\0' || pos[1] == ' ') | |
5869 | return -1; | |
5870 | ||
5871 | svc_str = pos + 1; | |
5872 | ||
5873 | pos = os_strchr(svc_str, ' '); | |
5874 | ||
5875 | if (pos) | |
5876 | *pos++ = '\0'; | |
5877 | ||
5878 | /* All remaining data is the svc_info string */ | |
5879 | if (pos && pos[0] && pos[0] != ' ') { | |
5880 | len = os_strlen(pos); | |
5881 | ||
5882 | /* Unescape in place */ | |
5883 | len = utf8_unescape(pos, len, pos, len); | |
5884 | if (len > 0xff) | |
5885 | return -1; | |
5886 | ||
5887 | svc_info = pos; | |
5888 | } | |
5889 | ||
5890 | ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id, | |
5891 | svc_str, svc_info); | |
b563b388 JM |
5892 | } else { |
5893 | len = os_strlen(pos); | |
5894 | if (len & 1) | |
5895 | return -1; | |
5896 | len /= 2; | |
5897 | tlvs = wpabuf_alloc(len); | |
5898 | if (tlvs == NULL) | |
5899 | return -1; | |
5900 | if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) { | |
5901 | wpabuf_free(tlvs); | |
5902 | return -1; | |
5903 | } | |
5904 | ||
7165c5dc | 5905 | ref = wpas_p2p_sd_request(wpa_s, dst, tlvs); |
b563b388 JM |
5906 | wpabuf_free(tlvs); |
5907 | } | |
7165c5dc JM |
5908 | if (ref == 0) |
5909 | return -1; | |
b563b388 | 5910 | res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref); |
d85e1fc8 | 5911 | if (os_snprintf_error(buflen, res)) |
b563b388 JM |
5912 | return -1; |
5913 | return res; | |
5914 | } | |
5915 | ||
5916 | ||
5917 | static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s, | |
5918 | char *cmd) | |
5919 | { | |
5920 | long long unsigned val; | |
5921 | u64 req; | |
5922 | if (sscanf(cmd, "%llx", &val) != 1) | |
5923 | return -1; | |
5924 | req = val; | |
7165c5dc | 5925 | return wpas_p2p_sd_cancel_request(wpa_s, req); |
b563b388 JM |
5926 | } |
5927 | ||
5928 | ||
5929 | static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd) | |
5930 | { | |
5931 | int freq; | |
d25f7212 | 5932 | u8 dst[ETH_ALEN]; |
b563b388 JM |
5933 | u8 dialog_token; |
5934 | struct wpabuf *resp_tlvs; | |
5935 | char *pos, *pos2; | |
5936 | size_t len; | |
5937 | ||
5938 | pos = os_strchr(cmd, ' '); | |
5939 | if (pos == NULL) | |
5940 | return -1; | |
5941 | *pos++ = '\0'; | |
5942 | freq = atoi(cmd); | |
5943 | if (freq == 0) | |
5944 | return -1; | |
5945 | ||
d25f7212 | 5946 | if (hwaddr_aton(pos, dst)) |
b563b388 | 5947 | return -1; |
b563b388 JM |
5948 | pos += 17; |
5949 | if (*pos != ' ') | |
5950 | return -1; | |
5951 | pos++; | |
5952 | ||
5953 | pos2 = os_strchr(pos, ' '); | |
5954 | if (pos2 == NULL) | |
5955 | return -1; | |
5956 | *pos2++ = '\0'; | |
5957 | dialog_token = atoi(pos); | |
5958 | ||
5959 | len = os_strlen(pos2); | |
5960 | if (len & 1) | |
5961 | return -1; | |
5962 | len /= 2; | |
5963 | resp_tlvs = wpabuf_alloc(len); | |
5964 | if (resp_tlvs == NULL) | |
5965 | return -1; | |
5966 | if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) { | |
5967 | wpabuf_free(resp_tlvs); | |
5968 | return -1; | |
5969 | } | |
5970 | ||
5971 | wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs); | |
5972 | wpabuf_free(resp_tlvs); | |
5973 | return 0; | |
5974 | } | |
5975 | ||
5976 | ||
5977 | static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s, | |
5978 | char *cmd) | |
5979 | { | |
28ef705d GB |
5980 | if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1")) |
5981 | return -1; | |
b563b388 JM |
5982 | wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd); |
5983 | return 0; | |
5984 | } | |
5985 | ||
5986 | ||
5987 | static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s, | |
5988 | char *cmd) | |
5989 | { | |
5990 | char *pos; | |
5991 | size_t len; | |
5992 | struct wpabuf *query, *resp; | |
5993 | ||
5994 | pos = os_strchr(cmd, ' '); | |
5995 | if (pos == NULL) | |
5996 | return -1; | |
5997 | *pos++ = '\0'; | |
5998 | ||
5999 | len = os_strlen(cmd); | |
6000 | if (len & 1) | |
6001 | return -1; | |
6002 | len /= 2; | |
6003 | query = wpabuf_alloc(len); | |
6004 | if (query == NULL) | |
6005 | return -1; | |
6006 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | |
6007 | wpabuf_free(query); | |
6008 | return -1; | |
6009 | } | |
6010 | ||
6011 | len = os_strlen(pos); | |
6012 | if (len & 1) { | |
6013 | wpabuf_free(query); | |
6014 | return -1; | |
6015 | } | |
6016 | len /= 2; | |
6017 | resp = wpabuf_alloc(len); | |
6018 | if (resp == NULL) { | |
6019 | wpabuf_free(query); | |
6020 | return -1; | |
6021 | } | |
6022 | if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) { | |
6023 | wpabuf_free(query); | |
6024 | wpabuf_free(resp); | |
6025 | return -1; | |
6026 | } | |
6027 | ||
6028 | if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) { | |
6029 | wpabuf_free(query); | |
6030 | wpabuf_free(resp); | |
6031 | return -1; | |
6032 | } | |
6033 | return 0; | |
6034 | } | |
6035 | ||
6036 | ||
6037 | static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd) | |
6038 | { | |
6039 | char *pos; | |
6040 | u8 version; | |
6041 | ||
6042 | pos = os_strchr(cmd, ' '); | |
6043 | if (pos == NULL) | |
6044 | return -1; | |
6045 | *pos++ = '\0'; | |
6046 | ||
6047 | if (hexstr2bin(cmd, &version, 1) < 0) | |
6048 | return -1; | |
6049 | ||
6050 | return wpas_p2p_service_add_upnp(wpa_s, version, pos); | |
6051 | } | |
6052 | ||
6053 | ||
ae9d45f3 KV |
6054 | static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s, |
6055 | u8 replace, char *cmd) | |
6056 | { | |
6057 | char *pos; | |
6058 | char *adv_str; | |
6059 | u32 auto_accept, adv_id, svc_state, config_methods; | |
6060 | char *svc_info = NULL; | |
e2b7fbf2 MS |
6061 | char *cpt_prio_str; |
6062 | u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1]; | |
ae9d45f3 KV |
6063 | |
6064 | pos = os_strchr(cmd, ' '); | |
6065 | if (pos == NULL) | |
6066 | return -1; | |
6067 | *pos++ = '\0'; | |
6068 | ||
6069 | /* Auto-Accept value is mandatory, and must be one of the | |
6070 | * single values (0, 1, 2, 4) */ | |
6071 | auto_accept = atoi(cmd); | |
6072 | switch (auto_accept) { | |
6073 | case P2PS_SETUP_NONE: /* No auto-accept */ | |
6074 | case P2PS_SETUP_NEW: | |
6075 | case P2PS_SETUP_CLIENT: | |
6076 | case P2PS_SETUP_GROUP_OWNER: | |
6077 | break; | |
6078 | default: | |
6079 | return -1; | |
6080 | } | |
6081 | ||
6082 | /* Advertisement ID is mandatory */ | |
6083 | cmd = pos; | |
6084 | pos = os_strchr(cmd, ' '); | |
6085 | if (pos == NULL) | |
6086 | return -1; | |
6087 | *pos++ = '\0'; | |
6088 | ||
6089 | /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */ | |
6090 | if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0) | |
6091 | return -1; | |
6092 | ||
6093 | /* Only allow replacements if exist, and adds if not */ | |
6094 | if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) { | |
6095 | if (!replace) | |
6096 | return -1; | |
6097 | } else { | |
6098 | if (replace) | |
6099 | return -1; | |
6100 | } | |
6101 | ||
6102 | /* svc_state between 0 - 0xff is mandatory */ | |
6103 | if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff) | |
6104 | return -1; | |
6105 | ||
6106 | pos = os_strchr(pos, ' '); | |
6107 | if (pos == NULL) | |
6108 | return -1; | |
6109 | ||
6110 | /* config_methods is mandatory */ | |
6111 | pos++; | |
6112 | if (sscanf(pos, "%x", &config_methods) != 1) | |
6113 | return -1; | |
6114 | ||
6115 | if (!(config_methods & | |
6116 | (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS))) | |
6117 | return -1; | |
6118 | ||
6119 | pos = os_strchr(pos, ' '); | |
6120 | if (pos == NULL) | |
6121 | return -1; | |
6122 | ||
6123 | pos++; | |
6124 | adv_str = pos; | |
6125 | ||
6126 | /* Advertisement string is mandatory */ | |
6127 | if (!pos[0] || pos[0] == ' ') | |
6128 | return -1; | |
6129 | ||
6130 | /* Terminate svc string */ | |
6131 | pos = os_strchr(pos, ' '); | |
6132 | if (pos != NULL) | |
6133 | *pos++ = '\0'; | |
6134 | ||
e2b7fbf2 MS |
6135 | cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL; |
6136 | if (cpt_prio_str) { | |
6137 | pos = os_strchr(pos, ' '); | |
6138 | if (pos != NULL) | |
6139 | *pos++ = '\0'; | |
6140 | ||
6141 | if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio)) | |
6142 | return -1; | |
6143 | } else { | |
6144 | cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; | |
6145 | cpt_prio[1] = 0; | |
6146 | } | |
6147 | ||
ae9d45f3 KV |
6148 | /* Service and Response Information are optional */ |
6149 | if (pos && pos[0]) { | |
6150 | size_t len; | |
6151 | ||
6152 | /* Note the bare ' included, which cannot exist legally | |
6153 | * in unescaped string. */ | |
6154 | svc_info = os_strstr(pos, "svc_info='"); | |
6155 | ||
6156 | if (svc_info) { | |
6157 | svc_info += 9; | |
6158 | len = os_strlen(svc_info); | |
6159 | utf8_unescape(svc_info, len, svc_info, len); | |
6160 | } | |
6161 | } | |
6162 | ||
6163 | return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str, | |
6164 | (u8) svc_state, (u16) config_methods, | |
e2b7fbf2 | 6165 | svc_info, cpt_prio); |
ae9d45f3 KV |
6166 | } |
6167 | ||
6168 | ||
b563b388 JM |
6169 | static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd) |
6170 | { | |
6171 | char *pos; | |
6172 | ||
6173 | pos = os_strchr(cmd, ' '); | |
6174 | if (pos == NULL) | |
6175 | return -1; | |
6176 | *pos++ = '\0'; | |
6177 | ||
6178 | if (os_strcmp(cmd, "bonjour") == 0) | |
6179 | return p2p_ctrl_service_add_bonjour(wpa_s, pos); | |
6180 | if (os_strcmp(cmd, "upnp") == 0) | |
6181 | return p2p_ctrl_service_add_upnp(wpa_s, pos); | |
ae9d45f3 KV |
6182 | if (os_strcmp(cmd, "asp") == 0) |
6183 | return p2p_ctrl_service_add_asp(wpa_s, 0, pos); | |
b563b388 JM |
6184 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
6185 | return -1; | |
6186 | } | |
6187 | ||
6188 | ||
6189 | static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s, | |
6190 | char *cmd) | |
6191 | { | |
6192 | size_t len; | |
6193 | struct wpabuf *query; | |
6194 | int ret; | |
6195 | ||
6196 | len = os_strlen(cmd); | |
6197 | if (len & 1) | |
6198 | return -1; | |
6199 | len /= 2; | |
6200 | query = wpabuf_alloc(len); | |
6201 | if (query == NULL) | |
6202 | return -1; | |
6203 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | |
6204 | wpabuf_free(query); | |
6205 | return -1; | |
6206 | } | |
6207 | ||
6208 | ret = wpas_p2p_service_del_bonjour(wpa_s, query); | |
6209 | wpabuf_free(query); | |
6210 | return ret; | |
6211 | } | |
6212 | ||
6213 | ||
6214 | static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd) | |
6215 | { | |
6216 | char *pos; | |
6217 | u8 version; | |
6218 | ||
6219 | pos = os_strchr(cmd, ' '); | |
6220 | if (pos == NULL) | |
6221 | return -1; | |
6222 | *pos++ = '\0'; | |
6223 | ||
6224 | if (hexstr2bin(cmd, &version, 1) < 0) | |
6225 | return -1; | |
6226 | ||
6227 | return wpas_p2p_service_del_upnp(wpa_s, version, pos); | |
6228 | } | |
6229 | ||
6230 | ||
ae9d45f3 KV |
6231 | static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd) |
6232 | { | |
6233 | u32 adv_id; | |
6234 | ||
e9d28050 MS |
6235 | if (os_strcmp(cmd, "all") == 0) { |
6236 | wpas_p2p_service_flush_asp(wpa_s); | |
6237 | return 0; | |
6238 | } | |
6239 | ||
ae9d45f3 KV |
6240 | if (sscanf(cmd, "%x", &adv_id) != 1) |
6241 | return -1; | |
6242 | ||
6243 | return wpas_p2p_service_del_asp(wpa_s, adv_id); | |
6244 | } | |
6245 | ||
6246 | ||
b563b388 JM |
6247 | static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd) |
6248 | { | |
6249 | char *pos; | |
6250 | ||
6251 | pos = os_strchr(cmd, ' '); | |
6252 | if (pos == NULL) | |
6253 | return -1; | |
6254 | *pos++ = '\0'; | |
6255 | ||
6256 | if (os_strcmp(cmd, "bonjour") == 0) | |
6257 | return p2p_ctrl_service_del_bonjour(wpa_s, pos); | |
6258 | if (os_strcmp(cmd, "upnp") == 0) | |
6259 | return p2p_ctrl_service_del_upnp(wpa_s, pos); | |
ae9d45f3 KV |
6260 | if (os_strcmp(cmd, "asp") == 0) |
6261 | return p2p_ctrl_service_del_asp(wpa_s, pos); | |
6262 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | |
6263 | return -1; | |
6264 | } | |
6265 | ||
6266 | ||
6267 | static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd) | |
6268 | { | |
6269 | char *pos; | |
6270 | ||
6271 | pos = os_strchr(cmd, ' '); | |
6272 | if (pos == NULL) | |
6273 | return -1; | |
6274 | *pos++ = '\0'; | |
6275 | ||
6276 | if (os_strcmp(cmd, "asp") == 0) | |
6277 | return p2p_ctrl_service_add_asp(wpa_s, 1, pos); | |
6278 | ||
b563b388 JM |
6279 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
6280 | return -1; | |
6281 | } | |
6282 | ||
6283 | ||
6284 | static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd) | |
6285 | { | |
6286 | u8 addr[ETH_ALEN]; | |
6287 | ||
6288 | /* <addr> */ | |
6289 | ||
6290 | if (hwaddr_aton(cmd, addr)) | |
6291 | return -1; | |
6292 | ||
6293 | return wpas_p2p_reject(wpa_s, addr); | |
6294 | } | |
6295 | ||
6296 | ||
6297 | static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd) | |
6298 | { | |
6299 | char *pos; | |
6300 | int id; | |
6301 | struct wpa_ssid *ssid; | |
54c61e6e | 6302 | u8 *_peer = NULL, peer[ETH_ALEN]; |
f5877af0 | 6303 | int freq = 0, pref_freq = 0; |
5a3319ab | 6304 | int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0; |
b563b388 JM |
6305 | |
6306 | id = atoi(cmd); | |
6307 | pos = os_strstr(cmd, " peer="); | |
6308 | if (pos) { | |
6309 | pos += 6; | |
6310 | if (hwaddr_aton(pos, peer)) | |
6311 | return -1; | |
54c61e6e | 6312 | _peer = peer; |
b563b388 JM |
6313 | } |
6314 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
6315 | if (ssid == NULL || ssid->disabled != 2) { | |
6316 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
6317 | "for persistent P2P group", | |
6318 | id); | |
6319 | return -1; | |
6320 | } | |
6321 | ||
4d32c0c4 JM |
6322 | pos = os_strstr(cmd, " freq="); |
6323 | if (pos) { | |
6324 | pos += 6; | |
6325 | freq = atoi(pos); | |
6326 | if (freq <= 0) | |
6327 | return -1; | |
6328 | } | |
6329 | ||
f5877af0 JM |
6330 | pos = os_strstr(cmd, " pref="); |
6331 | if (pos) { | |
6332 | pos += 6; | |
6333 | pref_freq = atoi(pos); | |
6334 | if (pref_freq <= 0) | |
6335 | return -1; | |
6336 | } | |
6337 | ||
20ea1ca4 EP |
6338 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
6339 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | |
6340 | vht; | |
5a3319ab | 6341 | he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he; |
4d32c0c4 | 6342 | |
c27f4c90 AK |
6343 | pos = os_strstr(cmd, "freq2="); |
6344 | if (pos) | |
6345 | freq2 = atoi(pos + 6); | |
6346 | ||
6347 | pos = os_strstr(cmd, " max_oper_chwidth="); | |
6348 | if (pos) | |
6349 | chwidth = atoi(pos + 18); | |
6350 | ||
6351 | max_oper_chwidth = parse_freq(chwidth, freq2); | |
6352 | if (max_oper_chwidth < 0) | |
6353 | return -1; | |
6354 | ||
6355 | return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht, | |
5a3319ab | 6356 | max_oper_chwidth, pref_freq, he); |
b563b388 JM |
6357 | } |
6358 | ||
6359 | ||
6360 | static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd) | |
6361 | { | |
6362 | char *pos; | |
6363 | u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL; | |
6364 | ||
6365 | pos = os_strstr(cmd, " peer="); | |
6366 | if (!pos) | |
6367 | return -1; | |
6368 | ||
6369 | *pos = '\0'; | |
6370 | pos += 6; | |
6371 | if (hwaddr_aton(pos, peer)) { | |
6372 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos); | |
6373 | return -1; | |
6374 | } | |
6375 | ||
6376 | pos = os_strstr(pos, " go_dev_addr="); | |
6377 | if (pos) { | |
6378 | pos += 13; | |
6379 | if (hwaddr_aton(pos, go_dev_addr)) { | |
6380 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", | |
6381 | pos); | |
6382 | return -1; | |
6383 | } | |
6384 | go_dev = go_dev_addr; | |
6385 | } | |
6386 | ||
6387 | return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev); | |
6388 | } | |
6389 | ||
6390 | ||
6391 | static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd) | |
6392 | { | |
6393 | if (os_strncmp(cmd, "persistent=", 11) == 0) | |
6394 | return p2p_ctrl_invite_persistent(wpa_s, cmd + 11); | |
6395 | if (os_strncmp(cmd, "group=", 6) == 0) | |
6396 | return p2p_ctrl_invite_group(wpa_s, cmd + 6); | |
6397 | ||
6398 | return -1; | |
6399 | } | |
6400 | ||
6401 | ||
6402 | static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, | |
c27f4c90 | 6403 | int id, int freq, int vht_center_freq2, |
5a3319ab PX |
6404 | int ht40, int vht, int vht_chwidth, |
6405 | int he) | |
b563b388 | 6406 | { |
b563b388 JM |
6407 | struct wpa_ssid *ssid; |
6408 | ||
b563b388 JM |
6409 | ssid = wpa_config_get_network(wpa_s->conf, id); |
6410 | if (ssid == NULL || ssid->disabled != 2) { | |
6411 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
6412 | "for persistent P2P group", | |
6413 | id); | |
6414 | return -1; | |
6415 | } | |
6416 | ||
c27f4c90 AK |
6417 | return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, |
6418 | vht_center_freq2, 0, ht40, vht, | |
5a3319ab | 6419 | vht_chwidth, he, NULL, 0, 0); |
b563b388 JM |
6420 | } |
6421 | ||
6422 | ||
6423 | static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) | |
6424 | { | |
29292d53 EP |
6425 | int freq = 0, persistent = 0, group_id = -1; |
6426 | int vht = wpa_s->conf->p2p_go_vht; | |
6427 | int ht40 = wpa_s->conf->p2p_go_ht40 || vht; | |
5a3319ab | 6428 | int he = wpa_s->conf->p2p_go_he; |
c27f4c90 | 6429 | int max_oper_chwidth, chwidth = 0, freq2 = 0; |
29292d53 | 6430 | char *token, *context = NULL; |
37ed3254 SD |
6431 | #ifdef CONFIG_ACS |
6432 | int acs = 0; | |
6433 | #endif /* CONFIG_ACS */ | |
e11776a5 | 6434 | |
29292d53 | 6435 | while ((token = str_token(cmd, " ", &context))) { |
37ed3254 | 6436 | if (sscanf(token, "freq2=%d", &freq2) == 1 || |
c27f4c90 AK |
6437 | sscanf(token, "persistent=%d", &group_id) == 1 || |
6438 | sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) { | |
29292d53 | 6439 | continue; |
37ed3254 SD |
6440 | #ifdef CONFIG_ACS |
6441 | } else if (os_strcmp(token, "freq=acs") == 0) { | |
6442 | acs = 1; | |
6443 | #endif /* CONFIG_ACS */ | |
6444 | } else if (sscanf(token, "freq=%d", &freq) == 1) { | |
6445 | continue; | |
29292d53 EP |
6446 | } else if (os_strcmp(token, "ht40") == 0) { |
6447 | ht40 = 1; | |
6448 | } else if (os_strcmp(token, "vht") == 0) { | |
6449 | vht = 1; | |
6450 | ht40 = 1; | |
5a3319ab PX |
6451 | } else if (os_strcmp(token, "he") == 0) { |
6452 | he = 1; | |
29292d53 EP |
6453 | } else if (os_strcmp(token, "persistent") == 0) { |
6454 | persistent = 1; | |
6455 | } else { | |
6456 | wpa_printf(MSG_DEBUG, | |
6457 | "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'", | |
6458 | token); | |
6459 | return -1; | |
6460 | } | |
e11776a5 PK |
6461 | } |
6462 | ||
37ed3254 SD |
6463 | #ifdef CONFIG_ACS |
6464 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) && | |
6465 | (acs || freq == 2 || freq == 5)) { | |
6466 | if (freq == 2 && wpa_s->best_24_freq <= 0) { | |
6467 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G; | |
6468 | wpa_s->p2p_go_do_acs = 1; | |
6469 | freq = 0; | |
6470 | } else if (freq == 5 && wpa_s->best_5_freq <= 0) { | |
6471 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A; | |
6472 | wpa_s->p2p_go_do_acs = 1; | |
6473 | freq = 0; | |
6474 | } else { | |
6475 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY; | |
6476 | wpa_s->p2p_go_do_acs = 1; | |
6477 | } | |
2b7fa035 JS |
6478 | } else { |
6479 | wpa_s->p2p_go_do_acs = 0; | |
37ed3254 SD |
6480 | } |
6481 | #endif /* CONFIG_ACS */ | |
6482 | ||
c27f4c90 AK |
6483 | max_oper_chwidth = parse_freq(chwidth, freq2); |
6484 | if (max_oper_chwidth < 0) | |
6485 | return -1; | |
6486 | ||
29292d53 EP |
6487 | if (group_id >= 0) |
6488 | return p2p_ctrl_group_add_persistent(wpa_s, group_id, | |
c27f4c90 | 6489 | freq, freq2, ht40, vht, |
5a3319ab | 6490 | max_oper_chwidth, he); |
29292d53 | 6491 | |
c27f4c90 | 6492 | return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht, |
5a3319ab | 6493 | max_oper_chwidth, he); |
b563b388 JM |
6494 | } |
6495 | ||
6496 | ||
57b38882 PK |
6497 | static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd, |
6498 | char *buf, size_t buflen) | |
6499 | { | |
6500 | u8 dev_addr[ETH_ALEN]; | |
6501 | struct wpa_ssid *ssid; | |
6502 | int res; | |
6503 | const u8 *iaddr; | |
6504 | ||
6505 | ssid = wpa_s->current_ssid; | |
6506 | if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO || | |
6507 | hwaddr_aton(cmd, dev_addr)) | |
6508 | return -1; | |
6509 | ||
6510 | iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr); | |
6511 | if (!iaddr) | |
6512 | return -1; | |
6513 | res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr)); | |
6514 | if (os_snprintf_error(buflen, res)) | |
6515 | return -1; | |
6516 | return res; | |
6517 | } | |
6518 | ||
6519 | ||
f47f9361 SD |
6520 | static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global, |
6521 | const u8 *p2p_dev_addr) | |
6522 | { | |
6523 | struct wpa_supplicant *wpa_s; | |
6524 | ||
6525 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
6526 | if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr)) | |
6527 | return 1; | |
6528 | } | |
6529 | ||
6530 | return 0; | |
6531 | } | |
6532 | ||
6533 | ||
b563b388 JM |
6534 | static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd, |
6535 | char *buf, size_t buflen) | |
6536 | { | |
f47f9361 | 6537 | u8 addr[ETH_ALEN], *addr_ptr, group_capab; |
b3ffc80b JM |
6538 | int next, res; |
6539 | const struct p2p_peer_info *info; | |
6540 | char *pos, *end; | |
6541 | char devtype[WPS_DEV_TYPE_BUFSIZE]; | |
87f841a1 | 6542 | struct wpa_ssid *ssid; |
f3989ced | 6543 | size_t i; |
b563b388 JM |
6544 | |
6545 | if (!wpa_s->global->p2p) | |
6546 | return -1; | |
6547 | ||
6548 | if (os_strcmp(cmd, "FIRST") == 0) { | |
6549 | addr_ptr = NULL; | |
6550 | next = 0; | |
6551 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | |
6552 | if (hwaddr_aton(cmd + 5, addr) < 0) | |
6553 | return -1; | |
6554 | addr_ptr = addr; | |
6555 | next = 1; | |
6556 | } else { | |
6557 | if (hwaddr_aton(cmd, addr) < 0) | |
6558 | return -1; | |
6559 | addr_ptr = addr; | |
6560 | next = 0; | |
6561 | } | |
6562 | ||
b3ffc80b JM |
6563 | info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next); |
6564 | if (info == NULL) | |
6565 | return -1; | |
f47f9361 SD |
6566 | group_capab = info->group_capab; |
6567 | ||
6568 | if (group_capab && | |
6569 | !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) { | |
6570 | wpa_printf(MSG_DEBUG, | |
6571 | "P2P: Could not find any BSS with p2p_dev_addr " | |
6572 | MACSTR ", hence override group_capab from 0x%x to 0", | |
6573 | MAC2STR(info->p2p_device_addr), group_capab); | |
6574 | group_capab = 0; | |
6575 | } | |
b3ffc80b JM |
6576 | |
6577 | pos = buf; | |
6578 | end = buf + buflen; | |
6579 | ||
6580 | res = os_snprintf(pos, end - pos, MACSTR "\n" | |
6581 | "pri_dev_type=%s\n" | |
6582 | "device_name=%s\n" | |
6583 | "manufacturer=%s\n" | |
6584 | "model_name=%s\n" | |
6585 | "model_number=%s\n" | |
6586 | "serial_number=%s\n" | |
6587 | "config_methods=0x%x\n" | |
6588 | "dev_capab=0x%x\n" | |
6589 | "group_capab=0x%x\n" | |
6590 | "level=%d\n", | |
6591 | MAC2STR(info->p2p_device_addr), | |
6592 | wps_dev_type_bin2str(info->pri_dev_type, | |
6593 | devtype, sizeof(devtype)), | |
6594 | info->device_name, | |
6595 | info->manufacturer, | |
6596 | info->model_name, | |
6597 | info->model_number, | |
6598 | info->serial_number, | |
6599 | info->config_methods, | |
6600 | info->dev_capab, | |
f47f9361 | 6601 | group_capab, |
b3ffc80b | 6602 | info->level); |
d85e1fc8 | 6603 | if (os_snprintf_error(end - pos, res)) |
b3ffc80b JM |
6604 | return pos - buf; |
6605 | pos += res; | |
6606 | ||
f3989ced JM |
6607 | for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++) |
6608 | { | |
6609 | const u8 *t; | |
6610 | t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN]; | |
6611 | res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n", | |
6612 | wps_dev_type_bin2str(t, devtype, | |
6613 | sizeof(devtype))); | |
d85e1fc8 | 6614 | if (os_snprintf_error(end - pos, res)) |
f3989ced JM |
6615 | return pos - buf; |
6616 | pos += res; | |
6617 | } | |
6618 | ||
c427ac92 | 6619 | ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0); |
87f841a1 JM |
6620 | if (ssid) { |
6621 | res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id); | |
d85e1fc8 | 6622 | if (os_snprintf_error(end - pos, res)) |
87f841a1 JM |
6623 | return pos - buf; |
6624 | pos += res; | |
6625 | } | |
6626 | ||
b3ffc80b JM |
6627 | res = p2p_get_peer_info_txt(info, pos, end - pos); |
6628 | if (res < 0) | |
87f841a1 | 6629 | return pos - buf; |
b3ffc80b JM |
6630 | pos += res; |
6631 | ||
71a0e395 JM |
6632 | if (info->vendor_elems) { |
6633 | res = os_snprintf(pos, end - pos, "vendor_elems="); | |
d85e1fc8 | 6634 | if (os_snprintf_error(end - pos, res)) |
71a0e395 JM |
6635 | return pos - buf; |
6636 | pos += res; | |
6637 | ||
6638 | pos += wpa_snprintf_hex(pos, end - pos, | |
6639 | wpabuf_head(info->vendor_elems), | |
6640 | wpabuf_len(info->vendor_elems)); | |
6641 | ||
6642 | res = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 6643 | if (os_snprintf_error(end - pos, res)) |
71a0e395 JM |
6644 | return pos - buf; |
6645 | pos += res; | |
6646 | } | |
6647 | ||
b3ffc80b | 6648 | return pos - buf; |
b563b388 JM |
6649 | } |
6650 | ||
6651 | ||
6f3bc72b JM |
6652 | static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s, |
6653 | const char *param) | |
6654 | { | |
af8a827b | 6655 | unsigned int i; |
6f3bc72b JM |
6656 | |
6657 | if (wpa_s->global->p2p == NULL) | |
6658 | return -1; | |
6659 | ||
af8a827b JM |
6660 | if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0) |
6661 | return -1; | |
6f3bc72b | 6662 | |
af8a827b JM |
6663 | for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) { |
6664 | struct wpa_freq_range *freq; | |
6665 | freq = &wpa_s->global->p2p_disallow_freq.range[i]; | |
6f3bc72b | 6666 | wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u", |
af8a827b | 6667 | freq->min, freq->max); |
6f3bc72b JM |
6668 | } |
6669 | ||
3a8f008a | 6670 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW); |
6f3bc72b JM |
6671 | return 0; |
6672 | } | |
6673 | ||
6674 | ||
b563b388 JM |
6675 | static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) |
6676 | { | |
6677 | char *param; | |
6678 | ||
6679 | if (wpa_s->global->p2p == NULL) | |
6680 | return -1; | |
6681 | ||
6682 | param = os_strchr(cmd, ' '); | |
6683 | if (param == NULL) | |
6684 | return -1; | |
6685 | *param++ = '\0'; | |
6686 | ||
6687 | if (os_strcmp(cmd, "discoverability") == 0) { | |
6688 | p2p_set_client_discoverability(wpa_s->global->p2p, | |
6689 | atoi(param)); | |
6690 | return 0; | |
6691 | } | |
6692 | ||
6693 | if (os_strcmp(cmd, "managed") == 0) { | |
6694 | p2p_set_managed_oper(wpa_s->global->p2p, atoi(param)); | |
6695 | return 0; | |
6696 | } | |
6697 | ||
6698 | if (os_strcmp(cmd, "listen_channel") == 0) { | |
dfe0745c LD |
6699 | char *pos; |
6700 | u8 channel, op_class; | |
6701 | ||
6702 | channel = atoi(param); | |
6703 | pos = os_strchr(param, ' '); | |
6704 | op_class = pos ? atoi(pos) : 81; | |
6705 | ||
6706 | return p2p_set_listen_channel(wpa_s->global->p2p, op_class, | |
6707 | channel, 1); | |
b563b388 JM |
6708 | } |
6709 | ||
6710 | if (os_strcmp(cmd, "ssid_postfix") == 0) { | |
6711 | return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param, | |
6712 | os_strlen(param)); | |
6713 | } | |
6714 | ||
6715 | if (os_strcmp(cmd, "noa") == 0) { | |
6716 | char *pos; | |
6717 | int count, start, duration; | |
6718 | /* GO NoA parameters: count,start_offset(ms),duration(ms) */ | |
6719 | count = atoi(param); | |
6720 | pos = os_strchr(param, ','); | |
6721 | if (pos == NULL) | |
6722 | return -1; | |
6723 | pos++; | |
6724 | start = atoi(pos); | |
6725 | pos = os_strchr(pos, ','); | |
6726 | if (pos == NULL) | |
6727 | return -1; | |
6728 | pos++; | |
6729 | duration = atoi(pos); | |
6730 | if (count < 0 || count > 255 || start < 0 || duration < 0) | |
6731 | return -1; | |
6732 | if (count == 0 && duration > 0) | |
6733 | return -1; | |
6734 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d " | |
6735 | "start=%d duration=%d", count, start, duration); | |
aefb53bd | 6736 | return wpas_p2p_set_noa(wpa_s, count, start, duration); |
b563b388 JM |
6737 | } |
6738 | ||
c381508d JM |
6739 | if (os_strcmp(cmd, "ps") == 0) |
6740 | return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1); | |
6741 | ||
6742 | if (os_strcmp(cmd, "oppps") == 0) | |
6743 | return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1); | |
6744 | ||
6745 | if (os_strcmp(cmd, "ctwindow") == 0) | |
6746 | return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param)); | |
6747 | ||
b563b388 JM |
6748 | if (os_strcmp(cmd, "disabled") == 0) { |
6749 | wpa_s->global->p2p_disabled = atoi(param); | |
6750 | wpa_printf(MSG_DEBUG, "P2P functionality %s", | |
6751 | wpa_s->global->p2p_disabled ? | |
6752 | "disabled" : "enabled"); | |
6753 | if (wpa_s->global->p2p_disabled) { | |
6754 | wpas_p2p_stop_find(wpa_s); | |
108def93 | 6755 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
b563b388 JM |
6756 | p2p_flush(wpa_s->global->p2p); |
6757 | } | |
6758 | return 0; | |
6759 | } | |
6760 | ||
b9cfc09a JJ |
6761 | if (os_strcmp(cmd, "conc_pref") == 0) { |
6762 | if (os_strcmp(param, "sta") == 0) | |
6763 | wpa_s->global->conc_pref = WPA_CONC_PREF_STA; | |
6764 | else if (os_strcmp(param, "p2p") == 0) | |
6765 | wpa_s->global->conc_pref = WPA_CONC_PREF_P2P; | |
6766 | else { | |
6767 | wpa_printf(MSG_INFO, "Invalid conc_pref value"); | |
6768 | return -1; | |
6769 | } | |
6770 | wpa_printf(MSG_DEBUG, "Single channel concurrency preference: " | |
6771 | "%s", param); | |
6772 | return 0; | |
6773 | } | |
6774 | ||
6e6963ea JM |
6775 | if (os_strcmp(cmd, "force_long_sd") == 0) { |
6776 | wpa_s->force_long_sd = atoi(param); | |
6777 | return 0; | |
6778 | } | |
6779 | ||
80c9582a JM |
6780 | if (os_strcmp(cmd, "peer_filter") == 0) { |
6781 | u8 addr[ETH_ALEN]; | |
6782 | if (hwaddr_aton(param, addr)) | |
6783 | return -1; | |
6784 | p2p_set_peer_filter(wpa_s->global->p2p, addr); | |
6785 | return 0; | |
6786 | } | |
6787 | ||
72044390 JM |
6788 | if (os_strcmp(cmd, "cross_connect") == 0) |
6789 | return wpas_p2p_set_cross_connect(wpa_s, atoi(param)); | |
6790 | ||
eea2fd9e JM |
6791 | if (os_strcmp(cmd, "go_apsd") == 0) { |
6792 | if (os_strcmp(param, "disable") == 0) | |
6793 | wpa_s->set_ap_uapsd = 0; | |
6794 | else { | |
6795 | wpa_s->set_ap_uapsd = 1; | |
6796 | wpa_s->ap_uapsd = atoi(param); | |
6797 | } | |
6798 | return 0; | |
6799 | } | |
6800 | ||
6801 | if (os_strcmp(cmd, "client_apsd") == 0) { | |
6802 | if (os_strcmp(param, "disable") == 0) | |
6803 | wpa_s->set_sta_uapsd = 0; | |
6804 | else { | |
6805 | int be, bk, vi, vo; | |
6806 | char *pos; | |
6807 | /* format: BE,BK,VI,VO;max SP Length */ | |
6808 | be = atoi(param); | |
6809 | pos = os_strchr(param, ','); | |
6810 | if (pos == NULL) | |
6811 | return -1; | |
6812 | pos++; | |
6813 | bk = atoi(pos); | |
6814 | pos = os_strchr(pos, ','); | |
6815 | if (pos == NULL) | |
6816 | return -1; | |
6817 | pos++; | |
6818 | vi = atoi(pos); | |
6819 | pos = os_strchr(pos, ','); | |
6820 | if (pos == NULL) | |
6821 | return -1; | |
6822 | pos++; | |
6823 | vo = atoi(pos); | |
6824 | /* ignore max SP Length for now */ | |
6825 | ||
6826 | wpa_s->set_sta_uapsd = 1; | |
6827 | wpa_s->sta_uapsd = 0; | |
6828 | if (be) | |
6829 | wpa_s->sta_uapsd |= BIT(0); | |
6830 | if (bk) | |
6831 | wpa_s->sta_uapsd |= BIT(1); | |
6832 | if (vi) | |
6833 | wpa_s->sta_uapsd |= BIT(2); | |
6834 | if (vo) | |
6835 | wpa_s->sta_uapsd |= BIT(3); | |
6836 | } | |
6837 | return 0; | |
6838 | } | |
6839 | ||
6f3bc72b JM |
6840 | if (os_strcmp(cmd, "disallow_freq") == 0) |
6841 | return p2p_ctrl_disallow_freq(wpa_s, param); | |
6842 | ||
96beff11 JM |
6843 | if (os_strcmp(cmd, "disc_int") == 0) { |
6844 | int min_disc_int, max_disc_int, max_disc_tu; | |
6845 | char *pos; | |
6846 | ||
6847 | pos = param; | |
6848 | ||
6849 | min_disc_int = atoi(pos); | |
6850 | pos = os_strchr(pos, ' '); | |
6851 | if (pos == NULL) | |
6852 | return -1; | |
6853 | *pos++ = '\0'; | |
6854 | ||
6855 | max_disc_int = atoi(pos); | |
6856 | pos = os_strchr(pos, ' '); | |
6857 | if (pos == NULL) | |
6858 | return -1; | |
6859 | *pos++ = '\0'; | |
6860 | ||
6861 | max_disc_tu = atoi(pos); | |
6862 | ||
6863 | return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int, | |
6864 | max_disc_int, max_disc_tu); | |
6865 | } | |
6866 | ||
05766ed8 JM |
6867 | if (os_strcmp(cmd, "per_sta_psk") == 0) { |
6868 | wpa_s->global->p2p_per_sta_psk = !!atoi(param); | |
6869 | return 0; | |
6870 | } | |
6871 | ||
c4f87a70 JM |
6872 | #ifdef CONFIG_WPS_NFC |
6873 | if (os_strcmp(cmd, "nfc_tag") == 0) | |
6874 | return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param)); | |
6875 | #endif /* CONFIG_WPS_NFC */ | |
6876 | ||
201b0f5f JM |
6877 | if (os_strcmp(cmd, "disable_ip_addr_req") == 0) { |
6878 | wpa_s->p2p_disable_ip_addr_req = !!atoi(param); | |
6879 | return 0; | |
6880 | } | |
6881 | ||
3a7819f0 JM |
6882 | if (os_strcmp(cmd, "override_pref_op_chan") == 0) { |
6883 | int op_class, chan; | |
6884 | ||
6885 | op_class = atoi(param); | |
6886 | param = os_strchr(param, ':'); | |
6887 | if (!param) | |
6888 | return -1; | |
6889 | param++; | |
6890 | chan = atoi(param); | |
6891 | p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class, | |
6892 | chan); | |
6893 | return 0; | |
6894 | } | |
6895 | ||
b563b388 JM |
6896 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", |
6897 | cmd); | |
6898 | ||
6899 | return -1; | |
6900 | } | |
6901 | ||
6902 | ||
acb54643 JM |
6903 | static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s) |
6904 | { | |
6905 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); | |
6906 | wpa_s->force_long_sd = 0; | |
d02e4c8a AO |
6907 | |
6908 | #ifdef CONFIG_TESTING_OPTIONS | |
6909 | os_free(wpa_s->get_pref_freq_list_override); | |
6910 | wpa_s->get_pref_freq_list_override = NULL; | |
6911 | #endif /* CONFIG_TESTING_OPTIONS */ | |
6912 | ||
477b082c | 6913 | wpas_p2p_stop_find(wpa_s); |
b9da88d6 | 6914 | wpa_s->parent->p2ps_method_config_any = 0; |
acb54643 JM |
6915 | if (wpa_s->global->p2p) |
6916 | p2p_flush(wpa_s->global->p2p); | |
6917 | } | |
6918 | ||
6919 | ||
b563b388 JM |
6920 | static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd) |
6921 | { | |
6922 | char *pos, *pos2; | |
6923 | unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0; | |
6924 | ||
6925 | if (cmd[0]) { | |
6926 | pos = os_strchr(cmd, ' '); | |
6927 | if (pos == NULL) | |
6928 | return -1; | |
6929 | *pos++ = '\0'; | |
6930 | dur1 = atoi(cmd); | |
6931 | ||
6932 | pos2 = os_strchr(pos, ' '); | |
6933 | if (pos2) | |
6934 | *pos2++ = '\0'; | |
6935 | int1 = atoi(pos); | |
6936 | } else | |
6937 | pos2 = NULL; | |
6938 | ||
6939 | if (pos2) { | |
6940 | pos = os_strchr(pos2, ' '); | |
6941 | if (pos == NULL) | |
6942 | return -1; | |
6943 | *pos++ = '\0'; | |
6944 | dur2 = atoi(pos2); | |
6945 | int2 = atoi(pos); | |
6946 | } | |
6947 | ||
6948 | return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2); | |
6949 | } | |
6950 | ||
6951 | ||
6952 | static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) | |
6953 | { | |
6954 | char *pos; | |
6955 | unsigned int period = 0, interval = 0; | |
6956 | ||
6957 | if (cmd[0]) { | |
6958 | pos = os_strchr(cmd, ' '); | |
6959 | if (pos == NULL) | |
6960 | return -1; | |
6961 | *pos++ = '\0'; | |
6962 | period = atoi(cmd); | |
6963 | interval = atoi(pos); | |
6964 | } | |
6965 | ||
6966 | return wpas_p2p_ext_listen(wpa_s, period, interval); | |
6967 | } | |
6968 | ||
f2c56602 JM |
6969 | |
6970 | static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd) | |
6971 | { | |
6972 | const char *pos; | |
6973 | u8 peer[ETH_ALEN]; | |
6974 | int iface_addr = 0; | |
6975 | ||
6976 | pos = cmd; | |
6977 | if (os_strncmp(pos, "iface=", 6) == 0) { | |
6978 | iface_addr = 1; | |
6979 | pos += 6; | |
6980 | } | |
6981 | if (hwaddr_aton(pos, peer)) | |
6982 | return -1; | |
6983 | ||
6984 | wpas_p2p_remove_client(wpa_s, peer, iface_addr); | |
6985 | return 0; | |
6986 | } | |
6987 | ||
a6f5b193 PX |
6988 | |
6989 | static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd) | |
6990 | { | |
6991 | int freq = 0, period = 0, interval = 0, count = 0; | |
6992 | ||
6993 | if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4) | |
6994 | { | |
6995 | wpa_printf(MSG_DEBUG, | |
6996 | "CTRL: Invalid P2P LO Start parameter: '%s'", cmd); | |
6997 | return -1; | |
6998 | } | |
6999 | ||
7000 | return wpas_p2p_lo_start(wpa_s, freq, period, interval, count); | |
7001 | } | |
7002 | ||
b563b388 JM |
7003 | #endif /* CONFIG_P2P */ |
7004 | ||
7005 | ||
356d1488 JM |
7006 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val) |
7007 | { | |
7008 | struct wpa_freq_range_list ranges; | |
7009 | int *freqs = NULL; | |
7010 | struct hostapd_hw_modes *mode; | |
7011 | u16 i; | |
7012 | ||
7013 | if (wpa_s->hw.modes == NULL) | |
7014 | return NULL; | |
7015 | ||
7016 | os_memset(&ranges, 0, sizeof(ranges)); | |
7017 | if (freq_range_list_parse(&ranges, val) < 0) | |
7018 | return NULL; | |
7019 | ||
7020 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
7021 | int j; | |
7022 | ||
7023 | mode = &wpa_s->hw.modes[i]; | |
7024 | for (j = 0; j < mode->num_channels; j++) { | |
7025 | unsigned int freq; | |
7026 | ||
7027 | if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED) | |
7028 | continue; | |
7029 | ||
7030 | freq = mode->channels[j].freq; | |
7031 | if (!freq_range_list_includes(&ranges, freq)) | |
7032 | continue; | |
7033 | ||
7034 | int_array_add_unique(&freqs, freq); | |
7035 | } | |
7036 | } | |
7037 | ||
7038 | os_free(ranges.range); | |
7039 | return freqs; | |
7040 | } | |
7041 | ||
7042 | ||
afc064fe | 7043 | #ifdef CONFIG_INTERWORKING |
356d1488 JM |
7044 | |
7045 | static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param) | |
7046 | { | |
7047 | int auto_sel = 0; | |
7048 | int *freqs = NULL; | |
7049 | ||
7050 | if (param) { | |
7051 | char *pos; | |
7052 | ||
7053 | auto_sel = os_strstr(param, "auto") != NULL; | |
7054 | ||
7055 | pos = os_strstr(param, "freq="); | |
7056 | if (pos) { | |
7057 | freqs = freq_range_to_channel_list(wpa_s, pos + 5); | |
7058 | if (freqs == NULL) | |
7059 | return -1; | |
7060 | } | |
7061 | ||
7062 | } | |
7063 | ||
7064 | return interworking_select(wpa_s, auto_sel, freqs); | |
7065 | } | |
7066 | ||
7067 | ||
f91a512f JM |
7068 | static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst, |
7069 | int only_add) | |
b02fe7ff JM |
7070 | { |
7071 | u8 bssid[ETH_ALEN]; | |
7072 | struct wpa_bss *bss; | |
7073 | ||
7074 | if (hwaddr_aton(dst, bssid)) { | |
7075 | wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst); | |
7076 | return -1; | |
7077 | } | |
7078 | ||
7079 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
7080 | if (bss == NULL) { | |
7081 | wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR, | |
7082 | MAC2STR(bssid)); | |
7083 | return -1; | |
7084 | } | |
7085 | ||
783b2a97 JM |
7086 | if (bss->ssid_len == 0) { |
7087 | int found = 0; | |
7088 | ||
7089 | wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR | |
7090 | " does not have SSID information", MAC2STR(bssid)); | |
7091 | ||
7092 | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, | |
7093 | list) { | |
7094 | if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 && | |
7095 | bss->ssid_len > 0) { | |
7096 | found = 1; | |
7097 | break; | |
7098 | } | |
7099 | } | |
7100 | ||
7101 | if (!found) | |
7102 | return -1; | |
7103 | wpa_printf(MSG_DEBUG, | |
7104 | "Found another matching BSS entry with SSID"); | |
7105 | } | |
7106 | ||
f91a512f | 7107 | return interworking_connect(wpa_s, bss, only_add); |
b02fe7ff JM |
7108 | } |
7109 | ||
7110 | ||
afc064fe JM |
7111 | static int get_anqp(struct wpa_supplicant *wpa_s, char *dst) |
7112 | { | |
7113 | u8 dst_addr[ETH_ALEN]; | |
7114 | int used; | |
7115 | char *pos; | |
7116 | #define MAX_ANQP_INFO_ID 100 | |
7117 | u16 id[MAX_ANQP_INFO_ID]; | |
7118 | size_t num_id = 0; | |
cf28c66b | 7119 | u32 subtypes = 0; |
2316cb35 | 7120 | u32 mbo_subtypes = 0; |
afc064fe JM |
7121 | |
7122 | used = hwaddr_aton2(dst, dst_addr); | |
7123 | if (used < 0) | |
7124 | return -1; | |
7125 | pos = dst + used; | |
b68d602d JM |
7126 | if (*pos == ' ') |
7127 | pos++; | |
afc064fe | 7128 | while (num_id < MAX_ANQP_INFO_ID) { |
cf28c66b DS |
7129 | if (os_strncmp(pos, "hs20:", 5) == 0) { |
7130 | #ifdef CONFIG_HS20 | |
7131 | int num = atoi(pos + 5); | |
7132 | if (num <= 0 || num > 31) | |
7133 | return -1; | |
7134 | subtypes |= BIT(num); | |
7135 | #else /* CONFIG_HS20 */ | |
7136 | return -1; | |
7137 | #endif /* CONFIG_HS20 */ | |
8f479174 | 7138 | } else if (os_strncmp(pos, "mbo:", 4) == 0) { |
7139 | #ifdef CONFIG_MBO | |
7140 | int num = atoi(pos + 4); | |
2316cb35 AS |
7141 | |
7142 | if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE) | |
8f479174 | 7143 | return -1; |
2316cb35 | 7144 | mbo_subtypes |= BIT(num); |
8f479174 | 7145 | #else /* CONFIG_MBO */ |
7146 | return -1; | |
7147 | #endif /* CONFIG_MBO */ | |
cf28c66b DS |
7148 | } else { |
7149 | id[num_id] = atoi(pos); | |
7150 | if (id[num_id]) | |
7151 | num_id++; | |
7152 | } | |
afc064fe JM |
7153 | pos = os_strchr(pos + 1, ','); |
7154 | if (pos == NULL) | |
7155 | break; | |
7156 | pos++; | |
7157 | } | |
7158 | ||
8ecf2231 | 7159 | if (num_id == 0 && !subtypes && !mbo_subtypes) |
afc064fe JM |
7160 | return -1; |
7161 | ||
8f479174 | 7162 | return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes, |
2316cb35 | 7163 | mbo_subtypes); |
afc064fe | 7164 | } |
b1f12296 JM |
7165 | |
7166 | ||
7167 | static int gas_request(struct wpa_supplicant *wpa_s, char *cmd) | |
7168 | { | |
7169 | u8 dst_addr[ETH_ALEN]; | |
7170 | struct wpabuf *advproto, *query = NULL; | |
7171 | int used, ret = -1; | |
7172 | char *pos, *end; | |
7173 | size_t len; | |
7174 | ||
7175 | used = hwaddr_aton2(cmd, dst_addr); | |
7176 | if (used < 0) | |
7177 | return -1; | |
7178 | ||
7179 | pos = cmd + used; | |
7180 | while (*pos == ' ') | |
7181 | pos++; | |
7182 | ||
7183 | /* Advertisement Protocol ID */ | |
7184 | end = os_strchr(pos, ' '); | |
7185 | if (end) | |
7186 | len = end - pos; | |
7187 | else | |
7188 | len = os_strlen(pos); | |
7189 | if (len & 0x01) | |
7190 | return -1; | |
7191 | len /= 2; | |
7192 | if (len == 0) | |
7193 | return -1; | |
7194 | advproto = wpabuf_alloc(len); | |
7195 | if (advproto == NULL) | |
7196 | return -1; | |
7197 | if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0) | |
7198 | goto fail; | |
7199 | ||
7200 | if (end) { | |
7201 | /* Optional Query Request */ | |
7202 | pos = end + 1; | |
7203 | while (*pos == ' ') | |
7204 | pos++; | |
7205 | ||
7206 | len = os_strlen(pos); | |
7207 | if (len) { | |
7208 | if (len & 0x01) | |
7209 | goto fail; | |
7210 | len /= 2; | |
7211 | if (len == 0) | |
7212 | goto fail; | |
7213 | query = wpabuf_alloc(len); | |
7214 | if (query == NULL) | |
7215 | goto fail; | |
7216 | if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0) | |
7217 | goto fail; | |
7218 | } | |
7219 | } | |
7220 | ||
7221 | ret = gas_send_request(wpa_s, dst_addr, advproto, query); | |
7222 | ||
7223 | fail: | |
7224 | wpabuf_free(advproto); | |
7225 | wpabuf_free(query); | |
7226 | ||
7227 | return ret; | |
7228 | } | |
7229 | ||
7230 | ||
7231 | static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf, | |
7232 | size_t buflen) | |
7233 | { | |
7234 | u8 addr[ETH_ALEN]; | |
7235 | int dialog_token; | |
7236 | int used; | |
7237 | char *pos; | |
7238 | size_t resp_len, start, requested_len; | |
b6a9590b JM |
7239 | struct wpabuf *resp; |
7240 | int ret; | |
b1f12296 JM |
7241 | |
7242 | used = hwaddr_aton2(cmd, addr); | |
7243 | if (used < 0) | |
7244 | return -1; | |
7245 | ||
7246 | pos = cmd + used; | |
7247 | while (*pos == ' ') | |
7248 | pos++; | |
7249 | dialog_token = atoi(pos); | |
7250 | ||
b6a9590b JM |
7251 | if (wpa_s->last_gas_resp && |
7252 | os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 && | |
7253 | dialog_token == wpa_s->last_gas_dialog_token) | |
7254 | resp = wpa_s->last_gas_resp; | |
7255 | else if (wpa_s->prev_gas_resp && | |
7256 | os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 && | |
7257 | dialog_token == wpa_s->prev_gas_dialog_token) | |
7258 | resp = wpa_s->prev_gas_resp; | |
7259 | else | |
b1f12296 JM |
7260 | return -1; |
7261 | ||
b6a9590b | 7262 | resp_len = wpabuf_len(resp); |
b1f12296 JM |
7263 | start = 0; |
7264 | requested_len = resp_len; | |
7265 | ||
7266 | pos = os_strchr(pos, ' '); | |
7267 | if (pos) { | |
7268 | start = atoi(pos); | |
7269 | if (start > resp_len) | |
7270 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); | |
7271 | pos = os_strchr(pos, ','); | |
7272 | if (pos == NULL) | |
7273 | return -1; | |
7274 | pos++; | |
7275 | requested_len = atoi(pos); | |
7276 | if (start + requested_len > resp_len) | |
7277 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); | |
7278 | } | |
7279 | ||
7280 | if (requested_len * 2 + 1 > buflen) | |
7281 | return os_snprintf(buf, buflen, "FAIL-Too long response"); | |
7282 | ||
b6a9590b JM |
7283 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start, |
7284 | requested_len); | |
7285 | ||
7286 | if (start + requested_len == resp_len) { | |
7287 | /* | |
7288 | * Free memory by dropping the response after it has been | |
7289 | * fetched. | |
7290 | */ | |
7291 | if (resp == wpa_s->prev_gas_resp) { | |
7292 | wpabuf_free(wpa_s->prev_gas_resp); | |
7293 | wpa_s->prev_gas_resp = NULL; | |
7294 | } else { | |
7295 | wpabuf_free(wpa_s->last_gas_resp); | |
7296 | wpa_s->last_gas_resp = NULL; | |
7297 | } | |
7298 | } | |
7299 | ||
7300 | return ret; | |
b1f12296 | 7301 | } |
afc064fe JM |
7302 | #endif /* CONFIG_INTERWORKING */ |
7303 | ||
7304 | ||
a8918e86 JK |
7305 | #ifdef CONFIG_HS20 |
7306 | ||
7307 | static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst) | |
7308 | { | |
7309 | u8 dst_addr[ETH_ALEN]; | |
7310 | int used; | |
7311 | char *pos; | |
7312 | u32 subtypes = 0; | |
7313 | ||
7314 | used = hwaddr_aton2(dst, dst_addr); | |
7315 | if (used < 0) | |
7316 | return -1; | |
7317 | pos = dst + used; | |
b68d602d JM |
7318 | if (*pos == ' ') |
7319 | pos++; | |
a8918e86 JK |
7320 | for (;;) { |
7321 | int num = atoi(pos); | |
7322 | if (num <= 0 || num > 31) | |
7323 | return -1; | |
7324 | subtypes |= BIT(num); | |
7325 | pos = os_strchr(pos + 1, ','); | |
7326 | if (pos == NULL) | |
7327 | break; | |
7328 | pos++; | |
7329 | } | |
7330 | ||
7331 | if (subtypes == 0) | |
7332 | return -1; | |
7333 | ||
8dd5c1b4 | 7334 | return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0); |
a8918e86 JK |
7335 | } |
7336 | ||
7337 | ||
7338 | static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s, | |
7339 | const u8 *addr, const char *realm) | |
7340 | { | |
7341 | u8 *buf; | |
7342 | size_t rlen, len; | |
7343 | int ret; | |
7344 | ||
7345 | rlen = os_strlen(realm); | |
7346 | len = 3 + rlen; | |
7347 | buf = os_malloc(len); | |
7348 | if (buf == NULL) | |
7349 | return -1; | |
7350 | buf[0] = 1; /* NAI Home Realm Count */ | |
7351 | buf[1] = 0; /* Formatted in accordance with RFC 4282 */ | |
7352 | buf[2] = rlen; | |
7353 | os_memcpy(buf + 3, realm, rlen); | |
7354 | ||
7355 | ret = hs20_anqp_send_req(wpa_s, addr, | |
7356 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | |
8dd5c1b4 | 7357 | buf, len, 0); |
a8918e86 JK |
7358 | |
7359 | os_free(buf); | |
7360 | ||
7361 | return ret; | |
7362 | } | |
7363 | ||
7364 | ||
7365 | static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s, | |
7366 | char *dst) | |
7367 | { | |
7368 | struct wpa_cred *cred = wpa_s->conf->cred; | |
7369 | u8 dst_addr[ETH_ALEN]; | |
7370 | int used; | |
7371 | u8 *buf; | |
7372 | size_t len; | |
7373 | int ret; | |
7374 | ||
7375 | used = hwaddr_aton2(dst, dst_addr); | |
7376 | if (used < 0) | |
7377 | return -1; | |
7378 | ||
7379 | while (dst[used] == ' ') | |
7380 | used++; | |
7381 | if (os_strncmp(dst + used, "realm=", 6) == 0) | |
7382 | return hs20_nai_home_realm_list(wpa_s, dst_addr, | |
7383 | dst + used + 6); | |
7384 | ||
7385 | len = os_strlen(dst + used); | |
7386 | ||
7387 | if (len == 0 && cred && cred->realm) | |
7388 | return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm); | |
7389 | ||
0e87e798 | 7390 | if (len & 1) |
a8918e86 JK |
7391 | return -1; |
7392 | len /= 2; | |
7393 | buf = os_malloc(len); | |
7394 | if (buf == NULL) | |
7395 | return -1; | |
7396 | if (hexstr2bin(dst + used, buf, len) < 0) { | |
7397 | os_free(buf); | |
7398 | return -1; | |
7399 | } | |
7400 | ||
7401 | ret = hs20_anqp_send_req(wpa_s, dst_addr, | |
7402 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | |
8dd5c1b4 | 7403 | buf, len, 0); |
a8918e86 JK |
7404 | os_free(buf); |
7405 | ||
7406 | return ret; | |
7407 | } | |
7408 | ||
184e110c | 7409 | |
8dd5c1b4 JN |
7410 | static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply, |
7411 | int buflen) | |
7412 | { | |
7413 | u8 dst_addr[ETH_ALEN]; | |
7414 | int used; | |
7415 | char *ctx = NULL, *icon, *poffset, *psize; | |
7416 | ||
7417 | used = hwaddr_aton2(cmd, dst_addr); | |
7418 | if (used < 0) | |
7419 | return -1; | |
7420 | cmd += used; | |
7421 | ||
7422 | icon = str_token(cmd, " ", &ctx); | |
7423 | poffset = str_token(cmd, " ", &ctx); | |
7424 | psize = str_token(cmd, " ", &ctx); | |
7425 | if (!icon || !poffset || !psize) | |
7426 | return -1; | |
7427 | ||
7428 | wpa_s->fetch_osu_icon_in_progress = 0; | |
7429 | return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize), | |
7430 | reply, buflen); | |
7431 | } | |
7432 | ||
7433 | ||
7434 | static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd) | |
7435 | { | |
7436 | u8 dst_addr[ETH_ALEN]; | |
7437 | int used; | |
7438 | char *icon; | |
7439 | ||
7440 | if (!cmd[0]) | |
7441 | return hs20_del_icon(wpa_s, NULL, NULL); | |
7442 | ||
7443 | used = hwaddr_aton2(cmd, dst_addr); | |
7444 | if (used < 0) | |
7445 | return -1; | |
7446 | ||
7447 | while (cmd[used] == ' ') | |
7448 | used++; | |
7449 | icon = cmd[used] ? &cmd[used] : NULL; | |
7450 | ||
7451 | return hs20_del_icon(wpa_s, dst_addr, icon); | |
7452 | } | |
7453 | ||
7454 | ||
7455 | static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem) | |
184e110c JM |
7456 | { |
7457 | u8 dst_addr[ETH_ALEN]; | |
7458 | int used; | |
7459 | char *icon; | |
7460 | ||
7461 | used = hwaddr_aton2(cmd, dst_addr); | |
7462 | if (used < 0) | |
7463 | return -1; | |
7464 | ||
7465 | while (cmd[used] == ' ') | |
7466 | used++; | |
7467 | icon = &cmd[used]; | |
7468 | ||
b572df86 | 7469 | wpa_s->fetch_osu_icon_in_progress = 0; |
184e110c | 7470 | return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST), |
8dd5c1b4 | 7471 | (u8 *) icon, os_strlen(icon), inmem); |
184e110c JM |
7472 | } |
7473 | ||
a8918e86 JK |
7474 | #endif /* CONFIG_HS20 */ |
7475 | ||
7476 | ||
bc5d330a TB |
7477 | #ifdef CONFIG_AUTOSCAN |
7478 | ||
7479 | static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s, | |
7480 | char *cmd) | |
7481 | { | |
7482 | enum wpa_states state = wpa_s->wpa_state; | |
7483 | char *new_params = NULL; | |
7484 | ||
7485 | if (os_strlen(cmd) > 0) { | |
7486 | new_params = os_strdup(cmd); | |
7487 | if (new_params == NULL) | |
7488 | return -1; | |
7489 | } | |
7490 | ||
7491 | os_free(wpa_s->conf->autoscan); | |
7492 | wpa_s->conf->autoscan = new_params; | |
7493 | ||
7494 | if (wpa_s->conf->autoscan == NULL) | |
7495 | autoscan_deinit(wpa_s); | |
7496 | else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) | |
99218999 | 7497 | autoscan_init(wpa_s, 1); |
99f00324 JM |
7498 | else if (state == WPA_SCANNING) |
7499 | wpa_supplicant_reinit_autoscan(wpa_s); | |
9d3f4a74 JM |
7500 | else |
7501 | wpa_printf(MSG_DEBUG, "No autoscan update in state %s", | |
7502 | wpa_supplicant_state_txt(state)); | |
bc5d330a TB |
7503 | |
7504 | return 0; | |
7505 | } | |
7506 | ||
7507 | #endif /* CONFIG_AUTOSCAN */ | |
7508 | ||
7509 | ||
e9199e31 JM |
7510 | #ifdef CONFIG_WNM |
7511 | ||
7512 | static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd) | |
7513 | { | |
7514 | int enter; | |
7515 | int intval = 0; | |
7516 | char *pos; | |
cd0ef657 JM |
7517 | int ret; |
7518 | struct wpabuf *tfs_req = NULL; | |
e9199e31 JM |
7519 | |
7520 | if (os_strncmp(cmd, "enter", 5) == 0) | |
7521 | enter = 1; | |
7522 | else if (os_strncmp(cmd, "exit", 4) == 0) | |
7523 | enter = 0; | |
7524 | else | |
7525 | return -1; | |
7526 | ||
7527 | pos = os_strstr(cmd, " interval="); | |
7528 | if (pos) | |
7529 | intval = atoi(pos + 10); | |
7530 | ||
cd0ef657 JM |
7531 | pos = os_strstr(cmd, " tfs_req="); |
7532 | if (pos) { | |
7533 | char *end; | |
7534 | size_t len; | |
7535 | pos += 9; | |
7536 | end = os_strchr(pos, ' '); | |
7537 | if (end) | |
7538 | len = end - pos; | |
7539 | else | |
7540 | len = os_strlen(pos); | |
7541 | if (len & 1) | |
7542 | return -1; | |
7543 | len /= 2; | |
7544 | tfs_req = wpabuf_alloc(len); | |
7545 | if (tfs_req == NULL) | |
7546 | return -1; | |
7547 | if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) { | |
7548 | wpabuf_free(tfs_req); | |
7549 | return -1; | |
7550 | } | |
7551 | } | |
7552 | ||
df80a0cc JM |
7553 | ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER : |
7554 | WNM_SLEEP_MODE_EXIT, intval, | |
cd0ef657 JM |
7555 | tfs_req); |
7556 | wpabuf_free(tfs_req); | |
7557 | ||
7558 | return ret; | |
e9199e31 JM |
7559 | } |
7560 | ||
65bcd0a9 VK |
7561 | |
7562 | static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd) | |
7563 | { | |
9a493fab | 7564 | int query_reason, list = 0; |
15ab61ed | 7565 | char *btm_candidates = NULL; |
65bcd0a9 VK |
7566 | |
7567 | query_reason = atoi(cmd); | |
7568 | ||
9a493fab AS |
7569 | cmd = os_strchr(cmd, ' '); |
7570 | if (cmd) { | |
15ab61ed | 7571 | if (os_strncmp(cmd, " list", 5) == 0) |
9a493fab | 7572 | list = 1; |
15ab61ed AS |
7573 | else |
7574 | btm_candidates = cmd; | |
9a493fab AS |
7575 | } |
7576 | ||
7577 | wpa_printf(MSG_DEBUG, | |
7578 | "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s", | |
7579 | query_reason, list ? " candidate list" : ""); | |
65bcd0a9 | 7580 | |
15ab61ed AS |
7581 | return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason, |
7582 | btm_candidates, | |
7583 | list); | |
65bcd0a9 VK |
7584 | } |
7585 | ||
d514b502 JM |
7586 | |
7587 | static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s, | |
7588 | char *cmd) | |
7589 | { | |
7590 | struct wpabuf *elems; | |
7591 | int ret; | |
7592 | ||
7593 | elems = wpabuf_parse_bin(cmd); | |
7594 | if (!elems) | |
7595 | return -1; | |
7596 | ||
7597 | ret = wnm_send_coloc_intf_report(wpa_s, 0, elems); | |
7598 | wpabuf_free(elems); | |
7599 | return ret; | |
7600 | } | |
7601 | ||
e9199e31 JM |
7602 | #endif /* CONFIG_WNM */ |
7603 | ||
7604 | ||
60b24b0d DS |
7605 | static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, |
7606 | size_t buflen) | |
7607 | { | |
7608 | struct wpa_signal_info si; | |
7609 | int ret; | |
2cc8d8f4 | 7610 | char *pos, *end; |
60b24b0d DS |
7611 | |
7612 | ret = wpa_drv_signal_poll(wpa_s, &si); | |
7613 | if (ret) | |
7614 | return -1; | |
7615 | ||
2cc8d8f4 AO |
7616 | pos = buf; |
7617 | end = buf + buflen; | |
7618 | ||
7619 | ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n" | |
60b24b0d DS |
7620 | "NOISE=%d\nFREQUENCY=%u\n", |
7621 | si.current_signal, si.current_txrate / 1000, | |
7622 | si.current_noise, si.frequency); | |
7bdd8981 | 7623 | if (os_snprintf_error(end - pos, ret)) |
60b24b0d | 7624 | return -1; |
2cc8d8f4 AO |
7625 | pos += ret; |
7626 | ||
7627 | if (si.chanwidth != CHAN_WIDTH_UNKNOWN) { | |
7628 | ret = os_snprintf(pos, end - pos, "WIDTH=%s\n", | |
7a4a93b9 | 7629 | channel_width_to_string(si.chanwidth)); |
7bdd8981 | 7630 | if (os_snprintf_error(end - pos, ret)) |
2cc8d8f4 AO |
7631 | return -1; |
7632 | pos += ret; | |
7633 | } | |
7634 | ||
b55c623e BP |
7635 | if (si.center_frq1 > 0) { |
7636 | ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n", | |
7637 | si.center_frq1); | |
7638 | if (os_snprintf_error(end - pos, ret)) | |
7639 | return -1; | |
7640 | pos += ret; | |
7641 | } | |
7642 | ||
7643 | if (si.center_frq2 > 0) { | |
7644 | ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n", | |
7645 | si.center_frq2); | |
7bdd8981 | 7646 | if (os_snprintf_error(end - pos, ret)) |
2cc8d8f4 AO |
7647 | return -1; |
7648 | pos += ret; | |
7649 | } | |
7650 | ||
95783298 AO |
7651 | if (si.avg_signal) { |
7652 | ret = os_snprintf(pos, end - pos, | |
7653 | "AVG_RSSI=%d\n", si.avg_signal); | |
d85e1fc8 | 7654 | if (os_snprintf_error(end - pos, ret)) |
95783298 AO |
7655 | return -1; |
7656 | pos += ret; | |
7657 | } | |
7658 | ||
74fa78b2 JM |
7659 | if (si.avg_beacon_signal) { |
7660 | ret = os_snprintf(pos, end - pos, | |
7661 | "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal); | |
7662 | if (os_snprintf_error(end - pos, ret)) | |
7663 | return -1; | |
7664 | pos += ret; | |
7665 | } | |
7666 | ||
2cc8d8f4 | 7667 | return pos - buf; |
60b24b0d DS |
7668 | } |
7669 | ||
7670 | ||
96e8d831 DS |
7671 | static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s, |
7672 | const char *cmd) | |
7673 | { | |
7674 | const char *pos; | |
7675 | int threshold = 0; | |
7676 | int hysteresis = 0; | |
7677 | ||
7678 | if (wpa_s->bgscan && wpa_s->bgscan_priv) { | |
7679 | wpa_printf(MSG_DEBUG, | |
7680 | "Reject SIGNAL_MONITOR command - bgscan is active"); | |
7681 | return -1; | |
7682 | } | |
7683 | pos = os_strstr(cmd, "THRESHOLD="); | |
7684 | if (pos) | |
7685 | threshold = atoi(pos + 10); | |
7686 | pos = os_strstr(cmd, "HYSTERESIS="); | |
7687 | if (pos) | |
7688 | hysteresis = atoi(pos + 11); | |
7689 | return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis); | |
7690 | } | |
7691 | ||
7692 | ||
c06fca04 JM |
7693 | #ifdef CONFIG_TESTING_OPTIONS |
7694 | int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s, | |
7695 | enum wpa_driver_if_type if_type, | |
7696 | unsigned int *num, | |
7697 | unsigned int *freq_list) | |
7698 | { | |
7699 | char *pos = wpa_s->get_pref_freq_list_override; | |
7700 | char *end; | |
7701 | unsigned int count = 0; | |
7702 | ||
7703 | /* Override string format: | |
7704 | * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */ | |
7705 | ||
7706 | while (pos) { | |
7707 | if (atoi(pos) == (int) if_type) | |
7708 | break; | |
7709 | pos = os_strchr(pos, ' '); | |
7710 | if (pos) | |
7711 | pos++; | |
7712 | } | |
7713 | if (!pos) | |
7714 | return -1; | |
7715 | pos = os_strchr(pos, ':'); | |
7716 | if (!pos) | |
7717 | return -1; | |
7718 | pos++; | |
7719 | end = os_strchr(pos, ' '); | |
7720 | while (pos && (!end || pos < end) && count < *num) { | |
7721 | freq_list[count++] = atoi(pos); | |
7722 | pos = os_strchr(pos, ','); | |
7723 | if (pos) | |
7724 | pos++; | |
7725 | } | |
7726 | ||
7727 | *num = count; | |
7728 | return 0; | |
7729 | } | |
7730 | #endif /* CONFIG_TESTING_OPTIONS */ | |
7731 | ||
7732 | ||
98342208 AK |
7733 | static int wpas_ctrl_iface_get_pref_freq_list( |
7734 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
7735 | { | |
7736 | unsigned int freq_list[100], num = 100, i; | |
7737 | int ret; | |
7738 | enum wpa_driver_if_type iface_type; | |
7739 | char *pos, *end; | |
7740 | ||
7741 | pos = buf; | |
7742 | end = buf + buflen; | |
7743 | ||
7744 | /* buf: "<interface_type>" */ | |
7745 | if (os_strcmp(cmd, "STATION") == 0) | |
7746 | iface_type = WPA_IF_STATION; | |
7747 | else if (os_strcmp(cmd, "AP") == 0) | |
7748 | iface_type = WPA_IF_AP_BSS; | |
7749 | else if (os_strcmp(cmd, "P2P_GO") == 0) | |
7750 | iface_type = WPA_IF_P2P_GO; | |
7751 | else if (os_strcmp(cmd, "P2P_CLIENT") == 0) | |
7752 | iface_type = WPA_IF_P2P_CLIENT; | |
7753 | else if (os_strcmp(cmd, "IBSS") == 0) | |
7754 | iface_type = WPA_IF_IBSS; | |
7755 | else if (os_strcmp(cmd, "TDLS") == 0) | |
7756 | iface_type = WPA_IF_TDLS; | |
7757 | else | |
7758 | return -1; | |
7759 | ||
7760 | wpa_printf(MSG_DEBUG, | |
7761 | "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)", | |
e6ac47b4 | 7762 | iface_type, cmd); |
98342208 AK |
7763 | |
7764 | ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list); | |
7765 | if (ret) | |
7766 | return -1; | |
7767 | ||
7768 | for (i = 0; i < num; i++) { | |
7769 | ret = os_snprintf(pos, end - pos, "%s%u", | |
7770 | i > 0 ? "," : "", freq_list[i]); | |
7771 | if (os_snprintf_error(end - pos, ret)) | |
7772 | return -1; | |
7773 | pos += ret; | |
7774 | } | |
7775 | ||
7776 | return pos - buf; | |
7777 | } | |
7778 | ||
7779 | ||
4d7aab78 EL |
7780 | static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s, |
7781 | char *buf, size_t buflen) | |
7782 | { | |
7783 | int ret, i; | |
7784 | char *pos, *end; | |
7785 | ||
7786 | ret = os_snprintf(buf, buflen, "%016llX:\n", | |
7787 | (long long unsigned) wpa_s->drv_flags); | |
7788 | if (os_snprintf_error(buflen, ret)) | |
7789 | return -1; | |
7790 | ||
7791 | pos = buf + ret; | |
7792 | end = buf + buflen; | |
7793 | ||
7794 | for (i = 0; i < 64; i++) { | |
7795 | if (wpa_s->drv_flags & (1LLU << i)) { | |
7796 | ret = os_snprintf(pos, end - pos, "%s\n", | |
7797 | driver_flag_to_string(1LLU << i)); | |
7798 | if (os_snprintf_error(end - pos, ret)) | |
7799 | return -1; | |
7800 | pos += ret; | |
7801 | } | |
7802 | } | |
7803 | ||
7804 | return pos - buf; | |
7805 | } | |
7806 | ||
7807 | ||
dc7785f8 YZ |
7808 | static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf, |
7809 | size_t buflen) | |
7810 | { | |
7811 | struct hostap_sta_driver_data sta; | |
7812 | int ret; | |
7813 | ||
7814 | ret = wpa_drv_pktcnt_poll(wpa_s, &sta); | |
7815 | if (ret) | |
7816 | return -1; | |
7817 | ||
7818 | ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n", | |
7819 | sta.tx_packets, sta.tx_retry_failed, sta.rx_packets); | |
7bdd8981 | 7820 | if (os_snprintf_error(buflen, ret)) |
dc7785f8 YZ |
7821 | return -1; |
7822 | return ret; | |
7823 | } | |
7824 | ||
7825 | ||
5e2c3490 JM |
7826 | #ifdef ANDROID |
7827 | static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd, | |
7828 | char *buf, size_t buflen) | |
7829 | { | |
7830 | int ret; | |
7831 | ||
7832 | ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen); | |
a94737ea DS |
7833 | if (ret == 0) { |
7834 | if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) { | |
7835 | struct p2p_data *p2p = wpa_s->global->p2p; | |
7836 | if (p2p) { | |
7837 | char country[3]; | |
7838 | country[0] = cmd[8]; | |
7839 | country[1] = cmd[9]; | |
7840 | country[2] = 0x04; | |
7841 | p2p_set_country(p2p, country); | |
7842 | } | |
7843 | } | |
5e2c3490 | 7844 | ret = os_snprintf(buf, buflen, "%s\n", "OK"); |
aaadd727 JM |
7845 | if (os_snprintf_error(buflen, ret)) |
7846 | ret = -1; | |
a94737ea | 7847 | } |
5e2c3490 JM |
7848 | return ret; |
7849 | } | |
7850 | #endif /* ANDROID */ | |
7851 | ||
7852 | ||
adef8948 BL |
7853 | static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd, |
7854 | char *buf, size_t buflen) | |
7855 | { | |
7856 | int ret; | |
7857 | char *pos; | |
7858 | u8 *data = NULL; | |
7859 | unsigned int vendor_id, subcmd; | |
7860 | struct wpabuf *reply; | |
7861 | size_t data_len = 0; | |
7862 | ||
7863 | /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */ | |
7864 | vendor_id = strtoul(cmd, &pos, 16); | |
640b0b93 | 7865 | if (!isblank((unsigned char) *pos)) |
adef8948 BL |
7866 | return -EINVAL; |
7867 | ||
7868 | subcmd = strtoul(pos, &pos, 10); | |
7869 | ||
7870 | if (*pos != '\0') { | |
640b0b93 | 7871 | if (!isblank((unsigned char) *pos++)) |
adef8948 BL |
7872 | return -EINVAL; |
7873 | data_len = os_strlen(pos); | |
7874 | } | |
7875 | ||
7876 | if (data_len) { | |
7877 | data_len /= 2; | |
7878 | data = os_malloc(data_len); | |
7879 | if (!data) | |
2cebdee6 | 7880 | return -1; |
adef8948 BL |
7881 | |
7882 | if (hexstr2bin(pos, data, data_len)) { | |
7883 | wpa_printf(MSG_DEBUG, | |
7884 | "Vendor command: wrong parameter format"); | |
7885 | os_free(data); | |
7886 | return -EINVAL; | |
7887 | } | |
7888 | } | |
7889 | ||
7890 | reply = wpabuf_alloc((buflen - 1) / 2); | |
7891 | if (!reply) { | |
7892 | os_free(data); | |
2cebdee6 | 7893 | return -1; |
adef8948 BL |
7894 | } |
7895 | ||
7896 | ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len, | |
7897 | reply); | |
7898 | ||
7899 | if (ret == 0) | |
7900 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply), | |
7901 | wpabuf_len(reply)); | |
7902 | ||
7903 | wpabuf_free(reply); | |
7904 | os_free(data); | |
7905 | ||
7906 | return ret; | |
7907 | } | |
7908 | ||
7909 | ||
acb54643 JM |
7910 | static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s) |
7911 | { | |
7e608d1d IP |
7912 | #ifdef CONFIG_P2P |
7913 | struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ? | |
7914 | wpa_s->global->p2p_init_wpa_s : wpa_s; | |
7915 | #endif /* CONFIG_P2P */ | |
7916 | ||
acb54643 JM |
7917 | wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state"); |
7918 | ||
6e374bd4 JM |
7919 | if (wpas_abort_ongoing_scan(wpa_s) == 0) |
7920 | wpa_s->ignore_post_flush_scan_res = 1; | |
53401e91 | 7921 | |
e9ccfc38 JM |
7922 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
7923 | /* | |
7924 | * Avoid possible auto connect re-connection on getting | |
7925 | * disconnected due to state flush. | |
7926 | */ | |
7927 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
7928 | } | |
7929 | ||
acb54643 | 7930 | #ifdef CONFIG_P2P |
1d20c66e | 7931 | wpas_p2p_group_remove(p2p_wpa_s, "*"); |
7e608d1d IP |
7932 | wpas_p2p_cancel(p2p_wpa_s); |
7933 | p2p_ctrl_flush(p2p_wpa_s); | |
7e608d1d IP |
7934 | wpas_p2p_service_flush(p2p_wpa_s); |
7935 | p2p_wpa_s->global->p2p_disabled = 0; | |
7936 | p2p_wpa_s->global->p2p_per_sta_psk = 0; | |
7937 | p2p_wpa_s->conf->num_sec_device_types = 0; | |
7938 | p2p_wpa_s->p2p_disable_ip_addr_req = 0; | |
7939 | os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range); | |
7940 | p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL; | |
85e152b6 | 7941 | p2p_wpa_s->global->p2p_go_avoid_freq.num = 0; |
9a58e521 | 7942 | p2p_wpa_s->global->pending_p2ps_group = 0; |
8bb8e6ed | 7943 | p2p_wpa_s->global->pending_p2ps_group_freq = 0; |
acb54643 JM |
7944 | #endif /* CONFIG_P2P */ |
7945 | ||
7946 | #ifdef CONFIG_WPS_TESTING | |
7947 | wps_version_number = 0x20; | |
7948 | wps_testing_dummy_cred = 0; | |
91226e0d | 7949 | wps_corrupt_pkhash = 0; |
6e379c6c JM |
7950 | wps_force_auth_types_in_use = 0; |
7951 | wps_force_encr_types_in_use = 0; | |
acb54643 JM |
7952 | #endif /* CONFIG_WPS_TESTING */ |
7953 | #ifdef CONFIG_WPS | |
7b02375a | 7954 | wpa_s->wps_fragment_size = 0; |
acb54643 | 7955 | wpas_wps_cancel(wpa_s); |
422ba11e | 7956 | wps_registrar_flush(wpa_s->wps->registrar); |
acb54643 | 7957 | #endif /* CONFIG_WPS */ |
7255983b | 7958 | wpa_s->after_wps = 0; |
4d9fb08d | 7959 | wpa_s->known_wps_freq = 0; |
acb54643 | 7960 | |
30d27b04 JM |
7961 | #ifdef CONFIG_DPP |
7962 | wpas_dpp_deinit(wpa_s); | |
f97ace34 JM |
7963 | wpa_s->dpp_init_max_tries = 0; |
7964 | wpa_s->dpp_init_retry_time = 0; | |
7965 | wpa_s->dpp_resp_wait_time = 0; | |
95b0104a JM |
7966 | wpa_s->dpp_resp_max_tries = 0; |
7967 | wpa_s->dpp_resp_retry_time = 0; | |
dc2f24f1 | 7968 | #ifdef CONFIG_TESTING_OPTIONS |
2bdc47a9 JM |
7969 | os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN); |
7970 | os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN); | |
acc555f9 | 7971 | dpp_pkex_ephemeral_key_override_len = 0; |
f5526975 | 7972 | dpp_protocol_key_override_len = 0; |
055cd397 | 7973 | dpp_nonce_override_len = 0; |
dc2f24f1 | 7974 | #endif /* CONFIG_TESTING_OPTIONS */ |
30d27b04 JM |
7975 | #endif /* CONFIG_DPP */ |
7976 | ||
9d2cb3ec | 7977 | #ifdef CONFIG_TDLS |
acb54643 | 7978 | #ifdef CONFIG_TDLS_TESTING |
acb54643 JM |
7979 | tdls_testing = 0; |
7980 | #endif /* CONFIG_TDLS_TESTING */ | |
acb54643 JM |
7981 | wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL); |
7982 | wpa_tdls_enable(wpa_s->wpa, 1); | |
7983 | #endif /* CONFIG_TDLS */ | |
7984 | ||
e78aaca0 JM |
7985 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL); |
7986 | wpa_supplicant_stop_countermeasures(wpa_s, NULL); | |
7987 | ||
acb54643 | 7988 | wpa_s->no_keep_alive = 0; |
c2805909 | 7989 | wpa_s->own_disconnect_req = 0; |
acb54643 JM |
7990 | |
7991 | os_free(wpa_s->disallow_aps_bssid); | |
7992 | wpa_s->disallow_aps_bssid = NULL; | |
7993 | wpa_s->disallow_aps_bssid_count = 0; | |
7994 | os_free(wpa_s->disallow_aps_ssid); | |
7995 | wpa_s->disallow_aps_ssid = NULL; | |
7996 | wpa_s->disallow_aps_ssid_count = 0; | |
7997 | ||
7998 | wpa_s->set_sta_uapsd = 0; | |
7999 | wpa_s->sta_uapsd = 0; | |
8000 | ||
8001 | wpa_drv_radio_disable(wpa_s, 0); | |
acb54643 | 8002 | wpa_blacklist_clear(wpa_s); |
a8a7890d | 8003 | wpa_s->extra_blacklist_count = 0; |
acb54643 JM |
8004 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all"); |
8005 | wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all"); | |
d9bb2821 | 8006 | wpa_config_flush_blobs(wpa_s->conf); |
ea6e040c JM |
8007 | wpa_s->conf->auto_interworking = 0; |
8008 | wpa_s->conf->okc = 0; | |
04f7ecc6 | 8009 | |
b925506a JM |
8010 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
8011 | rsn_preauth_deinit(wpa_s->wpa); | |
8012 | ||
04f7ecc6 JM |
8013 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200); |
8014 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70); | |
8015 | wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60); | |
0d79b50a | 8016 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); |
b1ae396f | 8017 | |
b3253ebb | 8018 | radio_remove_works(wpa_s, NULL, 1); |
e3745228 | 8019 | wpa_s->ext_work_in_progress = 0; |
3d910ef4 JM |
8020 | |
8021 | wpa_s->next_ssid = NULL; | |
b572df86 JM |
8022 | |
8023 | #ifdef CONFIG_INTERWORKING | |
876e74aa | 8024 | #ifdef CONFIG_HS20 |
b572df86 | 8025 | hs20_cancel_fetch_osu(wpa_s); |
8dd5c1b4 | 8026 | hs20_del_icon(wpa_s, NULL, NULL); |
876e74aa | 8027 | #endif /* CONFIG_HS20 */ |
b572df86 | 8028 | #endif /* CONFIG_INTERWORKING */ |
60b893df JM |
8029 | |
8030 | wpa_s->ext_mgmt_frame_handling = 0; | |
9d4ff04a | 8031 | wpa_s->ext_eapol_frame_io = 0; |
1f94e4ee JM |
8032 | #ifdef CONFIG_TESTING_OPTIONS |
8033 | wpa_s->extra_roc_dur = 0; | |
911942ee | 8034 | wpa_s->test_failure = WPAS_TEST_FAILURE_NONE; |
ed7820b4 | 8035 | wpa_s->p2p_go_csa_on_inv = 0; |
02adead5 | 8036 | wpa_s->ignore_auth_resp = 0; |
6ad37d73 | 8037 | wpa_s->ignore_assoc_disallow = 0; |
daa40960 | 8038 | wpa_s->testing_resend_assoc = 0; |
a483c6f1 | 8039 | wpa_s->reject_btm_req_reason = 0; |
651c6a84 | 8040 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL); |
c06fca04 JM |
8041 | os_free(wpa_s->get_pref_freq_list_override); |
8042 | wpa_s->get_pref_freq_list_override = NULL; | |
a0f19e9c JM |
8043 | wpabuf_free(wpa_s->sae_commit_override); |
8044 | wpa_s->sae_commit_override = NULL; | |
60239f60 | 8045 | #ifdef CONFIG_DPP |
b7dddab7 JM |
8046 | os_free(wpa_s->dpp_config_obj_override); |
8047 | wpa_s->dpp_config_obj_override = NULL; | |
8048 | os_free(wpa_s->dpp_discovery_override); | |
8049 | wpa_s->dpp_discovery_override = NULL; | |
8050 | os_free(wpa_s->dpp_groups_override); | |
8051 | wpa_s->dpp_groups_override = NULL; | |
60239f60 JM |
8052 | dpp_test = DPP_TEST_DISABLED; |
8053 | #endif /* CONFIG_DPP */ | |
1f94e4ee | 8054 | #endif /* CONFIG_TESTING_OPTIONS */ |
97cfe110 JM |
8055 | |
8056 | wpa_s->disconnected = 0; | |
b8db1dfc JM |
8057 | os_free(wpa_s->next_scan_freqs); |
8058 | wpa_s->next_scan_freqs = NULL; | |
88a44755 JM |
8059 | os_free(wpa_s->select_network_scan_freqs); |
8060 | wpa_s->select_network_scan_freqs = NULL; | |
6c699913 JM |
8061 | |
8062 | wpa_bss_flush(wpa_s); | |
8063 | if (!dl_list_empty(&wpa_s->bss)) { | |
8064 | wpa_printf(MSG_DEBUG, | |
8065 | "BSS table not empty after flush: %u entries, current_bss=%p bssid=" | |
8066 | MACSTR " pending_bssid=" MACSTR, | |
8067 | dl_list_len(&wpa_s->bss), wpa_s->current_bss, | |
8068 | MAC2STR(wpa_s->bssid), | |
8069 | MAC2STR(wpa_s->pending_bssid)); | |
8070 | } | |
9bd566a3 AS |
8071 | |
8072 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); | |
03ed0a52 | 8073 | wpa_s->wnmsleep_used = 0; |
ab6ab07a JM |
8074 | |
8075 | #ifdef CONFIG_SME | |
8076 | wpa_s->sme.last_unprot_disconnect.sec = 0; | |
8077 | #endif /* CONFIG_SME */ | |
c6c41f6e JM |
8078 | |
8079 | wpabuf_free(wpa_s->ric_ies); | |
8080 | wpa_s->ric_ies = NULL; | |
32bb47fa JM |
8081 | |
8082 | wpa_supplicant_update_channel_list(wpa_s, NULL); | |
19677b77 BL |
8083 | |
8084 | free_bss_tmp_disallowed(wpa_s); | |
acb54643 JM |
8085 | } |
8086 | ||
8087 | ||
1f965e62 JM |
8088 | static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s, |
8089 | char *buf, size_t buflen) | |
8090 | { | |
8091 | struct wpa_radio_work *work; | |
8092 | char *pos, *end; | |
8093 | struct os_reltime now, diff; | |
8094 | ||
8095 | pos = buf; | |
8096 | end = buf + buflen; | |
8097 | ||
8098 | os_get_reltime(&now); | |
8099 | ||
8100 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) | |
8101 | { | |
8102 | int ret; | |
8103 | ||
8104 | os_reltime_sub(&now, &work->time, &diff); | |
8105 | ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n", | |
8106 | work->type, work->wpa_s->ifname, work->freq, | |
8107 | work->started, diff.sec, diff.usec); | |
d85e1fc8 | 8108 | if (os_snprintf_error(end - pos, ret)) |
1f965e62 JM |
8109 | break; |
8110 | pos += ret; | |
8111 | } | |
8112 | ||
8113 | return pos - buf; | |
8114 | } | |
8115 | ||
8116 | ||
8117 | static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx) | |
8118 | { | |
8119 | struct wpa_radio_work *work = eloop_ctx; | |
8120 | struct wpa_external_work *ework = work->ctx; | |
8121 | ||
8122 | wpa_dbg(work->wpa_s, MSG_DEBUG, | |
8123 | "Timing out external radio work %u (%s)", | |
8124 | ework->id, work->type); | |
8125 | wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id); | |
e3745228 | 8126 | work->wpa_s->ext_work_in_progress = 0; |
1f965e62 | 8127 | radio_work_done(work); |
df48efc5 | 8128 | os_free(ework); |
1f965e62 JM |
8129 | } |
8130 | ||
8131 | ||
8132 | static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit) | |
8133 | { | |
8134 | struct wpa_external_work *ework = work->ctx; | |
8135 | ||
8136 | if (deinit) { | |
b3253ebb AO |
8137 | if (work->started) |
8138 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, | |
8139 | work, NULL); | |
8140 | ||
7d1007a6 JM |
8141 | /* |
8142 | * work->type points to a buffer in ework, so need to replace | |
8143 | * that here with a fixed string to avoid use of freed memory | |
8144 | * in debug prints. | |
8145 | */ | |
8146 | work->type = "freed-ext-work"; | |
8147 | work->ctx = NULL; | |
1f965e62 JM |
8148 | os_free(ework); |
8149 | return; | |
8150 | } | |
8151 | ||
8152 | wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)", | |
8153 | ework->id, ework->type); | |
8154 | wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id); | |
e3745228 | 8155 | work->wpa_s->ext_work_in_progress = 1; |
1f965e62 JM |
8156 | if (!ework->timeout) |
8157 | ework->timeout = 10; | |
8158 | eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout, | |
8159 | work, NULL); | |
8160 | } | |
8161 | ||
8162 | ||
8163 | static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd, | |
8164 | char *buf, size_t buflen) | |
8165 | { | |
8166 | struct wpa_external_work *ework; | |
8167 | char *pos, *pos2; | |
8168 | size_t type_len; | |
8169 | int ret; | |
8170 | unsigned int freq = 0; | |
8171 | ||
8172 | /* format: <name> [freq=<MHz>] [timeout=<seconds>] */ | |
8173 | ||
8174 | ework = os_zalloc(sizeof(*ework)); | |
8175 | if (ework == NULL) | |
8176 | return -1; | |
8177 | ||
8178 | pos = os_strchr(cmd, ' '); | |
8179 | if (pos) { | |
8180 | type_len = pos - cmd; | |
8181 | pos++; | |
8182 | ||
8183 | pos2 = os_strstr(pos, "freq="); | |
8184 | if (pos2) | |
8185 | freq = atoi(pos2 + 5); | |
8186 | ||
8187 | pos2 = os_strstr(pos, "timeout="); | |
8188 | if (pos2) | |
8189 | ework->timeout = atoi(pos2 + 8); | |
8190 | } else { | |
8191 | type_len = os_strlen(cmd); | |
8192 | } | |
8193 | if (4 + type_len >= sizeof(ework->type)) | |
8194 | type_len = sizeof(ework->type) - 4 - 1; | |
8195 | os_strlcpy(ework->type, "ext:", sizeof(ework->type)); | |
8196 | os_memcpy(ework->type + 4, cmd, type_len); | |
8197 | ework->type[4 + type_len] = '\0'; | |
8198 | ||
8199 | wpa_s->ext_work_id++; | |
8200 | if (wpa_s->ext_work_id == 0) | |
8201 | wpa_s->ext_work_id++; | |
8202 | ework->id = wpa_s->ext_work_id; | |
8203 | ||
8204 | if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb, | |
8205 | ework) < 0) { | |
8206 | os_free(ework); | |
8207 | return -1; | |
8208 | } | |
8209 | ||
8210 | ret = os_snprintf(buf, buflen, "%u", ework->id); | |
d85e1fc8 | 8211 | if (os_snprintf_error(buflen, ret)) |
1f965e62 JM |
8212 | return -1; |
8213 | return ret; | |
8214 | } | |
8215 | ||
8216 | ||
8217 | static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd) | |
8218 | { | |
8219 | struct wpa_radio_work *work; | |
8220 | unsigned int id = atoi(cmd); | |
8221 | ||
8222 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) | |
8223 | { | |
8224 | struct wpa_external_work *ework; | |
8225 | ||
8226 | if (os_strncmp(work->type, "ext:", 4) != 0) | |
8227 | continue; | |
8228 | ework = work->ctx; | |
8229 | if (id && ework->id != id) | |
8230 | continue; | |
8231 | wpa_dbg(wpa_s, MSG_DEBUG, | |
8232 | "Completed external radio work %u (%s)", | |
8233 | ework->id, ework->type); | |
8234 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL); | |
e3745228 | 8235 | wpa_s->ext_work_in_progress = 0; |
1f965e62 | 8236 | radio_work_done(work); |
6829da39 | 8237 | os_free(ework); |
1f965e62 JM |
8238 | return 3; /* "OK\n" */ |
8239 | } | |
8240 | ||
8241 | return -1; | |
8242 | } | |
8243 | ||
8244 | ||
8245 | static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd, | |
8246 | char *buf, size_t buflen) | |
8247 | { | |
8248 | if (os_strcmp(cmd, "show") == 0) | |
8249 | return wpas_ctrl_radio_work_show(wpa_s, buf, buflen); | |
8250 | if (os_strncmp(cmd, "add ", 4) == 0) | |
8251 | return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen); | |
8252 | if (os_strncmp(cmd, "done ", 5) == 0) | |
8253 | return wpas_ctrl_radio_work_done(wpa_s, cmd + 4); | |
8254 | return -1; | |
8255 | } | |
8256 | ||
8257 | ||
8258 | void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s) | |
8259 | { | |
8260 | struct wpa_radio_work *work, *tmp; | |
8261 | ||
a6cff8bf MS |
8262 | if (!wpa_s || !wpa_s->radio) |
8263 | return; | |
8264 | ||
1f965e62 JM |
8265 | dl_list_for_each_safe(work, tmp, &wpa_s->radio->work, |
8266 | struct wpa_radio_work, list) { | |
8267 | struct wpa_external_work *ework; | |
8268 | ||
8269 | if (os_strncmp(work->type, "ext:", 4) != 0) | |
8270 | continue; | |
8271 | ework = work->ctx; | |
8272 | wpa_dbg(wpa_s, MSG_DEBUG, | |
023b466d | 8273 | "Flushing%s external radio work %u (%s)", |
1f965e62 JM |
8274 | work->started ? " started" : "", ework->id, |
8275 | ework->type); | |
8276 | if (work->started) | |
8277 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, | |
8278 | work, NULL); | |
1f965e62 | 8279 | radio_work_done(work); |
df48efc5 | 8280 | os_free(ework); |
1f965e62 JM |
8281 | } |
8282 | } | |
8283 | ||
8284 | ||
bceb8431 JM |
8285 | static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx) |
8286 | { | |
8287 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
8288 | eapol_sm_notify_ctrl_response(wpa_s->eapol); | |
8289 | } | |
8290 | ||
8291 | ||
43a66ecb JM |
8292 | static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value, |
8293 | unsigned int *scan_id_count, int scan_id[]) | |
6891f0e6 LJ |
8294 | { |
8295 | const char *pos = value; | |
8296 | ||
8297 | while (pos) { | |
8298 | if (*pos == ' ' || *pos == '\0') | |
8299 | break; | |
43a66ecb | 8300 | if (*scan_id_count == MAX_SCAN_ID) |
6891f0e6 | 8301 | return -1; |
43a66ecb | 8302 | scan_id[(*scan_id_count)++] = atoi(pos); |
6891f0e6 LJ |
8303 | pos = os_strchr(pos, ','); |
8304 | if (pos) | |
8305 | pos++; | |
8306 | } | |
8307 | ||
8308 | return 0; | |
8309 | } | |
8310 | ||
8311 | ||
fee52342 JM |
8312 | static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params, |
8313 | char *reply, int reply_size, int *reply_len) | |
8314 | { | |
8315 | char *pos; | |
43a66ecb JM |
8316 | unsigned int manual_scan_passive = 0; |
8317 | unsigned int manual_scan_use_id = 0; | |
8318 | unsigned int manual_scan_only_new = 0; | |
8319 | unsigned int scan_only = 0; | |
8320 | unsigned int scan_id_count = 0; | |
8321 | int scan_id[MAX_SCAN_ID]; | |
8322 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, | |
8323 | struct wpa_scan_results *scan_res); | |
8324 | int *manual_scan_freqs = NULL; | |
a80651d0 KV |
8325 | struct wpa_ssid_value *ssid = NULL, *ns; |
8326 | unsigned int ssid_count = 0; | |
fee52342 JM |
8327 | |
8328 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { | |
8329 | *reply_len = -1; | |
8330 | return; | |
8331 | } | |
8332 | ||
e69ae5ff JM |
8333 | if (radio_work_pending(wpa_s, "scan")) { |
8334 | wpa_printf(MSG_DEBUG, | |
8335 | "Pending scan scheduled - reject new request"); | |
8336 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | |
8337 | return; | |
8338 | } | |
8339 | ||
9772af66 NM |
8340 | #ifdef CONFIG_INTERWORKING |
8341 | if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) { | |
8342 | wpa_printf(MSG_DEBUG, | |
8343 | "Interworking select in progress - reject new scan"); | |
8344 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | |
8345 | return; | |
8346 | } | |
8347 | #endif /* CONFIG_INTERWORKING */ | |
8348 | ||
fee52342 JM |
8349 | if (params) { |
8350 | if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0) | |
43a66ecb | 8351 | scan_only = 1; |
fee52342 JM |
8352 | |
8353 | pos = os_strstr(params, "freq="); | |
43a66ecb JM |
8354 | if (pos) { |
8355 | manual_scan_freqs = freq_range_to_channel_list(wpa_s, | |
8356 | pos + 5); | |
8357 | if (manual_scan_freqs == NULL) { | |
8358 | *reply_len = -1; | |
8359 | goto done; | |
8360 | } | |
fee52342 | 8361 | } |
88c2d488 JM |
8362 | |
8363 | pos = os_strstr(params, "passive="); | |
8364 | if (pos) | |
43a66ecb | 8365 | manual_scan_passive = !!atoi(pos + 8); |
d81c73be JM |
8366 | |
8367 | pos = os_strstr(params, "use_id="); | |
8368 | if (pos) | |
43a66ecb | 8369 | manual_scan_use_id = atoi(pos + 7); |
949938aa JM |
8370 | |
8371 | pos = os_strstr(params, "only_new=1"); | |
8372 | if (pos) | |
43a66ecb | 8373 | manual_scan_only_new = 1; |
6891f0e6 LJ |
8374 | |
8375 | pos = os_strstr(params, "scan_id="); | |
43a66ecb JM |
8376 | if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count, |
8377 | scan_id) < 0) { | |
6891f0e6 | 8378 | *reply_len = -1; |
43a66ecb | 8379 | goto done; |
6891f0e6 | 8380 | } |
a80651d0 | 8381 | |
267fc0dd AP |
8382 | pos = os_strstr(params, "bssid="); |
8383 | if (pos) { | |
8384 | u8 bssid[ETH_ALEN]; | |
8385 | ||
8386 | pos += 6; | |
8387 | if (hwaddr_aton(pos, bssid)) { | |
8388 | wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos); | |
8389 | *reply_len = -1; | |
8390 | goto done; | |
8391 | } | |
8392 | os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN); | |
8393 | } | |
8394 | ||
a80651d0 KV |
8395 | pos = params; |
8396 | while (pos && *pos != '\0') { | |
8397 | if (os_strncmp(pos, "ssid ", 5) == 0) { | |
8398 | char *end; | |
8399 | ||
8400 | pos += 5; | |
8401 | end = pos; | |
8402 | while (*end) { | |
8403 | if (*end == '\0' || *end == ' ') | |
8404 | break; | |
8405 | end++; | |
8406 | } | |
8407 | ||
8408 | ns = os_realloc_array( | |
8409 | ssid, ssid_count + 1, | |
8410 | sizeof(struct wpa_ssid_value)); | |
8411 | if (ns == NULL) { | |
8412 | *reply_len = -1; | |
8413 | goto done; | |
8414 | } | |
8415 | ssid = ns; | |
8416 | ||
8417 | if ((end - pos) & 0x01 || | |
8418 | end - pos > 2 * SSID_MAX_LEN || | |
8419 | hexstr2bin(pos, ssid[ssid_count].ssid, | |
8420 | (end - pos) / 2) < 0) { | |
8421 | wpa_printf(MSG_DEBUG, | |
8422 | "Invalid SSID value '%s'", | |
8423 | pos); | |
8424 | *reply_len = -1; | |
8425 | goto done; | |
8426 | } | |
8427 | ssid[ssid_count].ssid_len = (end - pos) / 2; | |
8428 | wpa_hexdump_ascii(MSG_DEBUG, "scan SSID", | |
8429 | ssid[ssid_count].ssid, | |
8430 | ssid[ssid_count].ssid_len); | |
8431 | ssid_count++; | |
8432 | pos = end; | |
8433 | } | |
8434 | ||
8435 | pos = os_strchr(pos, ' '); | |
8436 | if (pos) | |
8437 | pos++; | |
8438 | } | |
8439 | } | |
8440 | ||
8441 | wpa_s->num_ssids_from_scan_req = ssid_count; | |
8442 | os_free(wpa_s->ssids_from_scan_req); | |
8443 | if (ssid_count) { | |
8444 | wpa_s->ssids_from_scan_req = ssid; | |
8445 | ssid = NULL; | |
8446 | } else { | |
8447 | wpa_s->ssids_from_scan_req = NULL; | |
fee52342 JM |
8448 | } |
8449 | ||
43a66ecb JM |
8450 | if (scan_only) |
8451 | scan_res_handler = scan_only_handler; | |
8452 | else if (wpa_s->scan_res_handler == scan_only_handler) | |
8453 | scan_res_handler = NULL; | |
8454 | else | |
8455 | scan_res_handler = wpa_s->scan_res_handler; | |
8456 | ||
fee52342 JM |
8457 | if (!wpa_s->sched_scanning && !wpa_s->scanning && |
8458 | ((wpa_s->wpa_state <= WPA_SCANNING) || | |
8459 | (wpa_s->wpa_state == WPA_COMPLETED))) { | |
43a66ecb JM |
8460 | wpa_s->manual_scan_passive = manual_scan_passive; |
8461 | wpa_s->manual_scan_use_id = manual_scan_use_id; | |
8462 | wpa_s->manual_scan_only_new = manual_scan_only_new; | |
8463 | wpa_s->scan_id_count = scan_id_count; | |
8464 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); | |
8465 | wpa_s->scan_res_handler = scan_res_handler; | |
8466 | os_free(wpa_s->manual_scan_freqs); | |
8467 | wpa_s->manual_scan_freqs = manual_scan_freqs; | |
8468 | manual_scan_freqs = NULL; | |
8469 | ||
fee52342 JM |
8470 | wpa_s->normal_scans = 0; |
8471 | wpa_s->scan_req = MANUAL_SCAN_REQ; | |
8472 | wpa_s->after_wps = 0; | |
8473 | wpa_s->known_wps_freq = 0; | |
8474 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
d81c73be JM |
8475 | if (wpa_s->manual_scan_use_id) { |
8476 | wpa_s->manual_scan_id++; | |
8477 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", | |
8478 | wpa_s->manual_scan_id); | |
8479 | *reply_len = os_snprintf(reply, reply_size, "%u\n", | |
8480 | wpa_s->manual_scan_id); | |
8481 | } | |
fee52342 | 8482 | } else if (wpa_s->sched_scanning) { |
43a66ecb JM |
8483 | wpa_s->manual_scan_passive = manual_scan_passive; |
8484 | wpa_s->manual_scan_use_id = manual_scan_use_id; | |
8485 | wpa_s->manual_scan_only_new = manual_scan_only_new; | |
8486 | wpa_s->scan_id_count = scan_id_count; | |
8487 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); | |
8488 | wpa_s->scan_res_handler = scan_res_handler; | |
8489 | os_free(wpa_s->manual_scan_freqs); | |
8490 | wpa_s->manual_scan_freqs = manual_scan_freqs; | |
8491 | manual_scan_freqs = NULL; | |
8492 | ||
fee52342 JM |
8493 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed"); |
8494 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
8495 | wpa_s->scan_req = MANUAL_SCAN_REQ; | |
8496 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
d81c73be JM |
8497 | if (wpa_s->manual_scan_use_id) { |
8498 | wpa_s->manual_scan_id++; | |
8499 | *reply_len = os_snprintf(reply, reply_size, "%u\n", | |
8500 | wpa_s->manual_scan_id); | |
8501 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", | |
8502 | wpa_s->manual_scan_id); | |
8503 | } | |
fee52342 JM |
8504 | } else { |
8505 | wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request"); | |
8506 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | |
8507 | } | |
43a66ecb JM |
8508 | |
8509 | done: | |
8510 | os_free(manual_scan_freqs); | |
a80651d0 | 8511 | os_free(ssid); |
fee52342 JM |
8512 | } |
8513 | ||
8514 | ||
60b893df JM |
8515 | #ifdef CONFIG_TESTING_OPTIONS |
8516 | ||
8517 | static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s, | |
8518 | unsigned int freq, const u8 *dst, | |
8519 | const u8 *src, const u8 *bssid, | |
8520 | const u8 *data, size_t data_len, | |
8521 | enum offchannel_send_action_result | |
8522 | result) | |
8523 | { | |
8524 | wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR | |
8525 | " src=" MACSTR " bssid=" MACSTR " result=%s", | |
8526 | freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid), | |
8527 | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? | |
8528 | "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? | |
8529 | "NO_ACK" : "FAILED")); | |
8530 | } | |
8531 | ||
8532 | ||
8533 | static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd) | |
8534 | { | |
8535 | char *pos, *param; | |
8536 | size_t len; | |
8537 | u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN]; | |
8538 | int res, used; | |
8539 | int freq = 0, no_cck = 0, wait_time = 0; | |
8540 | ||
8541 | /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1] | |
8542 | * <action=Action frame payload> */ | |
8543 | ||
8544 | wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd); | |
8545 | ||
8546 | pos = cmd; | |
8547 | used = hwaddr_aton2(pos, da); | |
8548 | if (used < 0) | |
8549 | return -1; | |
8550 | pos += used; | |
8551 | while (*pos == ' ') | |
8552 | pos++; | |
8553 | used = hwaddr_aton2(pos, bssid); | |
8554 | if (used < 0) | |
8555 | return -1; | |
8556 | pos += used; | |
8557 | ||
8558 | param = os_strstr(pos, " freq="); | |
8559 | if (param) { | |
8560 | param += 6; | |
8561 | freq = atoi(param); | |
8562 | } | |
8563 | ||
8564 | param = os_strstr(pos, " no_cck="); | |
8565 | if (param) { | |
8566 | param += 8; | |
8567 | no_cck = atoi(param); | |
8568 | } | |
8569 | ||
8570 | param = os_strstr(pos, " wait_time="); | |
8571 | if (param) { | |
8572 | param += 11; | |
8573 | wait_time = atoi(param); | |
8574 | } | |
8575 | ||
8576 | param = os_strstr(pos, " action="); | |
8577 | if (param == NULL) | |
8578 | return -1; | |
8579 | param += 8; | |
8580 | ||
8581 | len = os_strlen(param); | |
8582 | if (len & 1) | |
8583 | return -1; | |
8584 | len /= 2; | |
8585 | ||
8586 | buf = os_malloc(len); | |
8587 | if (buf == NULL) | |
8588 | return -1; | |
8589 | ||
8590 | if (hexstr2bin(param, buf, len) < 0) { | |
8591 | os_free(buf); | |
8592 | return -1; | |
8593 | } | |
8594 | ||
8595 | res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid, | |
8596 | buf, len, wait_time, | |
8597 | wpas_ctrl_iface_mgmt_tx_cb, no_cck); | |
8598 | os_free(buf); | |
8599 | return res; | |
8600 | } | |
8601 | ||
8602 | ||
8603 | static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s) | |
8604 | { | |
8605 | wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting"); | |
8606 | offchannel_send_action_done(wpa_s); | |
8607 | } | |
8608 | ||
ad12f2f4 | 8609 | |
4de70e23 JM |
8610 | static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s, |
8611 | char *cmd) | |
8612 | { | |
8613 | char *pos, *param; | |
8614 | size_t len; | |
8615 | u8 *buf; | |
8616 | int freq = 0, datarate = 0, ssi_signal = 0; | |
8617 | union wpa_event_data event; | |
8618 | ||
8619 | if (!wpa_s->ext_mgmt_frame_handling) | |
8620 | return -1; | |
8621 | ||
8622 | /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */ | |
8623 | ||
8624 | wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd); | |
8625 | ||
8626 | pos = cmd; | |
8627 | param = os_strstr(pos, "freq="); | |
8628 | if (param) { | |
8629 | param += 5; | |
8630 | freq = atoi(param); | |
8631 | } | |
8632 | ||
8633 | param = os_strstr(pos, " datarate="); | |
8634 | if (param) { | |
8635 | param += 10; | |
8636 | datarate = atoi(param); | |
8637 | } | |
8638 | ||
8639 | param = os_strstr(pos, " ssi_signal="); | |
8640 | if (param) { | |
8641 | param += 12; | |
8642 | ssi_signal = atoi(param); | |
8643 | } | |
8644 | ||
8645 | param = os_strstr(pos, " frame="); | |
8646 | if (param == NULL) | |
8647 | return -1; | |
8648 | param += 7; | |
8649 | ||
8650 | len = os_strlen(param); | |
8651 | if (len & 1) | |
8652 | return -1; | |
8653 | len /= 2; | |
8654 | ||
8655 | buf = os_malloc(len); | |
8656 | if (buf == NULL) | |
8657 | return -1; | |
8658 | ||
8659 | if (hexstr2bin(param, buf, len) < 0) { | |
8660 | os_free(buf); | |
8661 | return -1; | |
8662 | } | |
8663 | ||
8664 | os_memset(&event, 0, sizeof(event)); | |
8665 | event.rx_mgmt.freq = freq; | |
8666 | event.rx_mgmt.frame = buf; | |
8667 | event.rx_mgmt.frame_len = len; | |
8668 | event.rx_mgmt.ssi_signal = ssi_signal; | |
8669 | event.rx_mgmt.datarate = datarate; | |
8670 | wpa_s->ext_mgmt_frame_handling = 0; | |
8671 | wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event); | |
8672 | wpa_s->ext_mgmt_frame_handling = 1; | |
8673 | ||
8674 | os_free(buf); | |
8675 | ||
8676 | return 0; | |
8677 | } | |
8678 | ||
8679 | ||
e4a3e1d0 JM |
8680 | static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s, |
8681 | char *param) | |
8682 | { | |
8683 | struct wpa_scan_res *res; | |
8684 | struct os_reltime now; | |
8685 | char *pos, *end; | |
1fb4437c | 8686 | int ret = -1; |
e4a3e1d0 JM |
8687 | |
8688 | if (!param) | |
8689 | return -1; | |
8690 | ||
8691 | if (os_strcmp(param, "START") == 0) { | |
8692 | wpa_bss_update_start(wpa_s); | |
8693 | return 0; | |
8694 | } | |
8695 | ||
8696 | if (os_strcmp(param, "END") == 0) { | |
8697 | wpa_bss_update_end(wpa_s, NULL, 1); | |
8698 | return 0; | |
8699 | } | |
8700 | ||
8701 | if (os_strncmp(param, "BSS ", 4) != 0) | |
8702 | return -1; | |
8703 | param += 3; | |
8704 | ||
8705 | res = os_zalloc(sizeof(*res) + os_strlen(param) / 2); | |
8706 | if (!res) | |
8707 | return -1; | |
8708 | ||
8709 | pos = os_strstr(param, " flags="); | |
8710 | if (pos) | |
8711 | res->flags = strtol(pos + 7, NULL, 16); | |
8712 | ||
8713 | pos = os_strstr(param, " bssid="); | |
1fb4437c JM |
8714 | if (pos && hwaddr_aton(pos + 7, res->bssid)) |
8715 | goto fail; | |
e4a3e1d0 JM |
8716 | |
8717 | pos = os_strstr(param, " freq="); | |
8718 | if (pos) | |
8719 | res->freq = atoi(pos + 6); | |
8720 | ||
8721 | pos = os_strstr(param, " beacon_int="); | |
8722 | if (pos) | |
8723 | res->beacon_int = atoi(pos + 12); | |
8724 | ||
8725 | pos = os_strstr(param, " caps="); | |
8726 | if (pos) | |
8727 | res->caps = strtol(pos + 6, NULL, 16); | |
8728 | ||
8729 | pos = os_strstr(param, " qual="); | |
8730 | if (pos) | |
8731 | res->qual = atoi(pos + 6); | |
8732 | ||
8733 | pos = os_strstr(param, " noise="); | |
8734 | if (pos) | |
8735 | res->noise = atoi(pos + 7); | |
8736 | ||
8737 | pos = os_strstr(param, " level="); | |
8738 | if (pos) | |
8739 | res->level = atoi(pos + 7); | |
8740 | ||
8741 | pos = os_strstr(param, " tsf="); | |
8742 | if (pos) | |
8743 | res->tsf = strtoll(pos + 5, NULL, 16); | |
8744 | ||
8745 | pos = os_strstr(param, " age="); | |
8746 | if (pos) | |
8747 | res->age = atoi(pos + 5); | |
8748 | ||
8749 | pos = os_strstr(param, " est_throughput="); | |
8750 | if (pos) | |
8751 | res->est_throughput = atoi(pos + 16); | |
8752 | ||
8753 | pos = os_strstr(param, " snr="); | |
8754 | if (pos) | |
8755 | res->snr = atoi(pos + 5); | |
8756 | ||
8757 | pos = os_strstr(param, " parent_tsf="); | |
8758 | if (pos) | |
8759 | res->parent_tsf = strtoll(pos + 7, NULL, 16); | |
8760 | ||
8761 | pos = os_strstr(param, " tsf_bssid="); | |
1fb4437c JM |
8762 | if (pos && hwaddr_aton(pos + 11, res->tsf_bssid)) |
8763 | goto fail; | |
e4a3e1d0 JM |
8764 | |
8765 | pos = os_strstr(param, " ie="); | |
8766 | if (pos) { | |
8767 | pos += 4; | |
8768 | end = os_strchr(pos, ' '); | |
8769 | if (!end) | |
8770 | end = pos + os_strlen(pos); | |
8771 | res->ie_len = (end - pos) / 2; | |
1fb4437c JM |
8772 | if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len)) |
8773 | goto fail; | |
e4a3e1d0 JM |
8774 | } |
8775 | ||
8776 | pos = os_strstr(param, " beacon_ie="); | |
8777 | if (pos) { | |
8778 | pos += 11; | |
8779 | end = os_strchr(pos, ' '); | |
8780 | if (!end) | |
8781 | end = pos + os_strlen(pos); | |
8782 | res->beacon_ie_len = (end - pos) / 2; | |
1fb4437c JM |
8783 | if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len, |
8784 | res->beacon_ie_len)) | |
8785 | goto fail; | |
e4a3e1d0 JM |
8786 | } |
8787 | ||
8788 | os_get_reltime(&now); | |
8789 | wpa_bss_update_scan_res(wpa_s, res, &now); | |
1fb4437c JM |
8790 | ret = 0; |
8791 | fail: | |
e4a3e1d0 JM |
8792 | os_free(res); |
8793 | ||
1fb4437c | 8794 | return ret; |
e4a3e1d0 JM |
8795 | } |
8796 | ||
8797 | ||
ad12f2f4 JM |
8798 | static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd) |
8799 | { | |
8800 | char *pos, *param; | |
8801 | union wpa_event_data event; | |
8802 | enum wpa_event_type ev; | |
8803 | ||
8804 | /* <event name> [parameters..] */ | |
8805 | ||
8806 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd); | |
8807 | ||
8808 | pos = cmd; | |
8809 | param = os_strchr(pos, ' '); | |
8810 | if (param) | |
8811 | *param++ = '\0'; | |
8812 | ||
8813 | os_memset(&event, 0, sizeof(event)); | |
8814 | ||
8815 | if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) { | |
8816 | ev = EVENT_INTERFACE_ENABLED; | |
8817 | } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) { | |
8818 | ev = EVENT_INTERFACE_DISABLED; | |
7bb70909 JM |
8819 | } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) { |
8820 | ev = EVENT_AVOID_FREQUENCIES; | |
8821 | if (param == NULL) | |
8822 | param = ""; | |
8823 | if (freq_range_list_parse(&event.freq_range, param) < 0) | |
8824 | return -1; | |
8825 | wpa_supplicant_event(wpa_s, ev, &event); | |
8826 | os_free(event.freq_range.range); | |
8827 | return 0; | |
e4a3e1d0 JM |
8828 | } else if (os_strcmp(cmd, "SCAN_RES") == 0) { |
8829 | return wpas_ctrl_iface_driver_scan_res(wpa_s, param); | |
ad12f2f4 JM |
8830 | } else { |
8831 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s", | |
8832 | cmd); | |
8833 | return -1; | |
8834 | } | |
8835 | ||
8836 | wpa_supplicant_event(wpa_s, ev, &event); | |
8837 | ||
8838 | return 0; | |
8839 | } | |
8840 | ||
9d4ff04a JM |
8841 | |
8842 | static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd) | |
8843 | { | |
8844 | char *pos; | |
8845 | u8 src[ETH_ALEN], *buf; | |
8846 | int used; | |
8847 | size_t len; | |
8848 | ||
8849 | wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd); | |
8850 | ||
8851 | pos = cmd; | |
8852 | used = hwaddr_aton2(pos, src); | |
8853 | if (used < 0) | |
8854 | return -1; | |
8855 | pos += used; | |
8856 | while (*pos == ' ') | |
8857 | pos++; | |
8858 | ||
8859 | len = os_strlen(pos); | |
8860 | if (len & 1) | |
8861 | return -1; | |
8862 | len /= 2; | |
8863 | ||
8864 | buf = os_malloc(len); | |
8865 | if (buf == NULL) | |
8866 | return -1; | |
8867 | ||
8868 | if (hexstr2bin(pos, buf, len) < 0) { | |
8869 | os_free(buf); | |
8870 | return -1; | |
8871 | } | |
8872 | ||
8873 | wpa_supplicant_rx_eapol(wpa_s, src, buf, len); | |
8874 | os_free(buf); | |
8875 | ||
8876 | return 0; | |
8877 | } | |
8878 | ||
4a6cc862 JM |
8879 | |
8880 | static u16 ipv4_hdr_checksum(const void *buf, size_t len) | |
8881 | { | |
8882 | size_t i; | |
8883 | u32 sum = 0; | |
8884 | const u16 *pos = buf; | |
8885 | ||
8886 | for (i = 0; i < len / 2; i++) | |
8887 | sum += *pos++; | |
8888 | ||
8889 | while (sum >> 16) | |
8890 | sum = (sum & 0xffff) + (sum >> 16); | |
8891 | ||
8892 | return sum ^ 0xffff; | |
8893 | } | |
8894 | ||
8895 | ||
8896 | #define HWSIM_PACKETLEN 1500 | |
8897 | #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header)) | |
8898 | ||
0dbe22be JM |
8899 | static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, |
8900 | size_t len) | |
4a6cc862 JM |
8901 | { |
8902 | struct wpa_supplicant *wpa_s = ctx; | |
8903 | const struct ether_header *eth; | |
75352270 | 8904 | struct iphdr ip; |
4a6cc862 JM |
8905 | const u8 *pos; |
8906 | unsigned int i; | |
93701b4a | 8907 | char extra[30]; |
4a6cc862 | 8908 | |
93701b4a JM |
8909 | if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) { |
8910 | wpa_printf(MSG_DEBUG, | |
8911 | "test data: RX - ignore unexpected length %d", | |
8912 | (int) len); | |
4a6cc862 | 8913 | return; |
93701b4a | 8914 | } |
4a6cc862 JM |
8915 | |
8916 | eth = (const struct ether_header *) buf; | |
75352270 JM |
8917 | os_memcpy(&ip, eth + 1, sizeof(ip)); |
8918 | pos = &buf[sizeof(*eth) + sizeof(ip)]; | |
4a6cc862 | 8919 | |
75352270 | 8920 | if (ip.ihl != 5 || ip.version != 4 || |
93701b4a JM |
8921 | ntohs(ip.tot_len) > HWSIM_IP_LEN) { |
8922 | wpa_printf(MSG_DEBUG, | |
8923 | "test data: RX - ignore unexpect IP header"); | |
4a6cc862 | 8924 | return; |
93701b4a | 8925 | } |
4a6cc862 | 8926 | |
93701b4a JM |
8927 | for (i = 0; i < ntohs(ip.tot_len) - sizeof(ip); i++) { |
8928 | if (*pos != (u8) i) { | |
8929 | wpa_printf(MSG_DEBUG, | |
8930 | "test data: RX - ignore mismatching payload"); | |
4a6cc862 | 8931 | return; |
93701b4a | 8932 | } |
4a6cc862 JM |
8933 | pos++; |
8934 | } | |
93701b4a JM |
8935 | extra[0] = '\0'; |
8936 | if (ntohs(ip.tot_len) != HWSIM_IP_LEN) | |
8937 | os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.tot_len)); | |
8938 | wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s", | |
8939 | MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra); | |
4a6cc862 JM |
8940 | } |
8941 | ||
8942 | ||
8943 | static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s, | |
8944 | char *cmd) | |
8945 | { | |
8946 | int enabled = atoi(cmd); | |
ba91e920 MB |
8947 | char *pos; |
8948 | const char *ifname; | |
4a6cc862 JM |
8949 | |
8950 | if (!enabled) { | |
8951 | if (wpa_s->l2_test) { | |
8952 | l2_packet_deinit(wpa_s->l2_test); | |
8953 | wpa_s->l2_test = NULL; | |
8954 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled"); | |
8955 | } | |
8956 | return 0; | |
8957 | } | |
8958 | ||
8959 | if (wpa_s->l2_test) | |
8960 | return 0; | |
8961 | ||
ba91e920 MB |
8962 | pos = os_strstr(cmd, " ifname="); |
8963 | if (pos) | |
8964 | ifname = pos + 8; | |
8965 | else | |
8966 | ifname = wpa_s->ifname; | |
8967 | ||
8968 | wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr, | |
4a6cc862 JM |
8969 | ETHERTYPE_IP, wpas_data_test_rx, |
8970 | wpa_s, 1); | |
8971 | if (wpa_s->l2_test == NULL) | |
8972 | return -1; | |
8973 | ||
8974 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled"); | |
8975 | ||
8976 | return 0; | |
8977 | } | |
8978 | ||
8979 | ||
8980 | static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd) | |
8981 | { | |
8982 | u8 dst[ETH_ALEN], src[ETH_ALEN]; | |
93701b4a | 8983 | char *pos, *pos2; |
4a6cc862 JM |
8984 | int used; |
8985 | long int val; | |
8986 | u8 tos; | |
75352270 | 8987 | u8 buf[2 + HWSIM_PACKETLEN]; |
4a6cc862 JM |
8988 | struct ether_header *eth; |
8989 | struct iphdr *ip; | |
8990 | u8 *dpos; | |
8991 | unsigned int i; | |
93701b4a | 8992 | size_t send_len = HWSIM_IP_LEN; |
4a6cc862 JM |
8993 | |
8994 | if (wpa_s->l2_test == NULL) | |
8995 | return -1; | |
8996 | ||
93701b4a | 8997 | /* format: <dst> <src> <tos> [len=<length>] */ |
4a6cc862 JM |
8998 | |
8999 | pos = cmd; | |
9000 | used = hwaddr_aton2(pos, dst); | |
9001 | if (used < 0) | |
9002 | return -1; | |
9003 | pos += used; | |
9004 | while (*pos == ' ') | |
9005 | pos++; | |
9006 | used = hwaddr_aton2(pos, src); | |
9007 | if (used < 0) | |
9008 | return -1; | |
9009 | pos += used; | |
9010 | ||
93701b4a | 9011 | val = strtol(pos, &pos2, 0); |
4a6cc862 JM |
9012 | if (val < 0 || val > 0xff) |
9013 | return -1; | |
9014 | tos = val; | |
9015 | ||
93701b4a JM |
9016 | pos = os_strstr(pos2, " len="); |
9017 | if (pos) { | |
9018 | i = atoi(pos + 5); | |
9019 | if (i < sizeof(*ip) || i > HWSIM_IP_LEN) | |
9020 | return -1; | |
9021 | send_len = i; | |
9022 | } | |
9023 | ||
75352270 | 9024 | eth = (struct ether_header *) &buf[2]; |
4a6cc862 JM |
9025 | os_memcpy(eth->ether_dhost, dst, ETH_ALEN); |
9026 | os_memcpy(eth->ether_shost, src, ETH_ALEN); | |
9027 | eth->ether_type = htons(ETHERTYPE_IP); | |
9028 | ip = (struct iphdr *) (eth + 1); | |
9029 | os_memset(ip, 0, sizeof(*ip)); | |
9030 | ip->ihl = 5; | |
9031 | ip->version = 4; | |
9032 | ip->ttl = 64; | |
9033 | ip->tos = tos; | |
93701b4a | 9034 | ip->tot_len = htons(send_len); |
4a6cc862 | 9035 | ip->protocol = 1; |
66f1e078 JM |
9036 | ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1); |
9037 | ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2); | |
4a6cc862 JM |
9038 | ip->check = ipv4_hdr_checksum(ip, sizeof(*ip)); |
9039 | dpos = (u8 *) (ip + 1); | |
93701b4a | 9040 | for (i = 0; i < send_len - sizeof(*ip); i++) |
4a6cc862 JM |
9041 | *dpos++ = i; |
9042 | ||
75352270 | 9043 | if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2], |
93701b4a | 9044 | sizeof(struct ether_header) + send_len) < 0) |
4a6cc862 JM |
9045 | return -1; |
9046 | ||
9047 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR | |
9048 | " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos); | |
9049 | ||
9050 | return 0; | |
9051 | } | |
9052 | ||
fc0ef7c0 JM |
9053 | |
9054 | static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s, | |
9055 | char *cmd) | |
9056 | { | |
9057 | u8 *buf; | |
9058 | struct ether_header *eth; | |
9059 | struct l2_packet_data *l2 = NULL; | |
9060 | size_t len; | |
9061 | u16 ethertype; | |
9062 | int res = -1; | |
9063 | ||
9064 | len = os_strlen(cmd); | |
9065 | if (len & 1 || len < ETH_HLEN * 2) | |
9066 | return -1; | |
9067 | len /= 2; | |
9068 | ||
9069 | buf = os_malloc(len); | |
9070 | if (buf == NULL) | |
9071 | return -1; | |
9072 | ||
9073 | if (hexstr2bin(cmd, buf, len) < 0) | |
9074 | goto done; | |
9075 | ||
9076 | eth = (struct ether_header *) buf; | |
9077 | ethertype = ntohs(eth->ether_type); | |
9078 | ||
9079 | l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype, | |
9080 | wpas_data_test_rx, wpa_s, 1); | |
9081 | if (l2 == NULL) | |
9082 | goto done; | |
9083 | ||
9084 | res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len); | |
9085 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res); | |
9086 | done: | |
9087 | if (l2) | |
9088 | l2_packet_deinit(l2); | |
9089 | os_free(buf); | |
9090 | ||
9091 | return res < 0 ? -1 : 0; | |
9092 | } | |
9093 | ||
a156ffda JM |
9094 | |
9095 | static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd) | |
9096 | { | |
9097 | #ifdef WPA_TRACE_BFD | |
a156ffda JM |
9098 | char *pos; |
9099 | ||
9100 | wpa_trace_fail_after = atoi(cmd); | |
9101 | pos = os_strchr(cmd, ':'); | |
9102 | if (pos) { | |
9103 | pos++; | |
9104 | os_strlcpy(wpa_trace_fail_func, pos, | |
9105 | sizeof(wpa_trace_fail_func)); | |
9106 | } else { | |
9107 | wpa_trace_fail_after = 0; | |
9108 | } | |
9109 | return 0; | |
9110 | #else /* WPA_TRACE_BFD */ | |
9111 | return -1; | |
9112 | #endif /* WPA_TRACE_BFD */ | |
9113 | } | |
9114 | ||
9115 | ||
9116 | static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s, | |
9117 | char *buf, size_t buflen) | |
9118 | { | |
9119 | #ifdef WPA_TRACE_BFD | |
a156ffda JM |
9120 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after, |
9121 | wpa_trace_fail_func); | |
9122 | #else /* WPA_TRACE_BFD */ | |
9123 | return -1; | |
9124 | #endif /* WPA_TRACE_BFD */ | |
9125 | } | |
9126 | ||
2da52565 JM |
9127 | |
9128 | static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd) | |
9129 | { | |
9130 | #ifdef WPA_TRACE_BFD | |
2da52565 JM |
9131 | char *pos; |
9132 | ||
9133 | wpa_trace_test_fail_after = atoi(cmd); | |
9134 | pos = os_strchr(cmd, ':'); | |
9135 | if (pos) { | |
9136 | pos++; | |
9137 | os_strlcpy(wpa_trace_test_fail_func, pos, | |
9138 | sizeof(wpa_trace_test_fail_func)); | |
9139 | } else { | |
9140 | wpa_trace_test_fail_after = 0; | |
9141 | } | |
9142 | return 0; | |
9143 | #else /* WPA_TRACE_BFD */ | |
9144 | return -1; | |
9145 | #endif /* WPA_TRACE_BFD */ | |
9146 | } | |
9147 | ||
9148 | ||
9149 | static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s, | |
9150 | char *buf, size_t buflen) | |
9151 | { | |
9152 | #ifdef WPA_TRACE_BFD | |
2da52565 JM |
9153 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after, |
9154 | wpa_trace_test_fail_func); | |
9155 | #else /* WPA_TRACE_BFD */ | |
9156 | return -1; | |
9157 | #endif /* WPA_TRACE_BFD */ | |
9158 | } | |
9159 | ||
a530fe77 JM |
9160 | |
9161 | static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx) | |
9162 | { | |
9163 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
9164 | int i, count = (intptr_t) timeout_ctx; | |
9165 | ||
9166 | wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages", | |
9167 | count); | |
9168 | for (i = 0; i < count; i++) { | |
9169 | wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d", | |
9170 | i + 1, count); | |
9171 | } | |
9172 | } | |
9173 | ||
9174 | ||
9175 | static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd) | |
9176 | { | |
9177 | int count; | |
9178 | ||
9179 | count = atoi(cmd); | |
9180 | if (count <= 0) | |
9181 | return -1; | |
9182 | ||
9183 | return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s, | |
9184 | (void *) (intptr_t) count); | |
9185 | } | |
9186 | ||
651c6a84 JM |
9187 | |
9188 | static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s, | |
9189 | const char *cmd) | |
9190 | { | |
9191 | struct wpabuf *buf; | |
9192 | size_t len; | |
9193 | ||
9194 | len = os_strlen(cmd); | |
9195 | if (len & 1) | |
9196 | return -1; | |
9197 | len /= 2; | |
9198 | ||
9199 | if (len == 0) { | |
9200 | buf = NULL; | |
9201 | } else { | |
9202 | buf = wpabuf_alloc(len); | |
9203 | if (buf == NULL) | |
9204 | return -1; | |
9205 | ||
9206 | if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) { | |
9207 | wpabuf_free(buf); | |
9208 | return -1; | |
9209 | } | |
9210 | } | |
9211 | ||
9212 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf); | |
9213 | return 0; | |
9214 | } | |
9215 | ||
16579769 JM |
9216 | |
9217 | static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s) | |
9218 | { | |
9219 | u8 zero[WPA_TK_MAX_LEN]; | |
9220 | ||
9221 | if (wpa_s->last_tk_alg == WPA_ALG_NONE) | |
9222 | return -1; | |
9223 | ||
9224 | wpa_printf(MSG_INFO, "TESTING: Reset PN"); | |
9225 | os_memset(zero, 0, sizeof(zero)); | |
9226 | ||
9227 | /* First, use a zero key to avoid any possible duplicate key avoidance | |
9228 | * in the driver. */ | |
9229 | if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr, | |
9230 | wpa_s->last_tk_key_idx, 1, zero, 6, | |
9231 | zero, wpa_s->last_tk_len) < 0) | |
9232 | return -1; | |
9233 | ||
9234 | /* Set the previously configured key to reset its TSC/RSC */ | |
9235 | return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr, | |
9236 | wpa_s->last_tk_key_idx, 1, zero, 6, | |
9237 | wpa_s->last_tk, wpa_s->last_tk_len); | |
9238 | } | |
9239 | ||
751f5b29 JM |
9240 | |
9241 | static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd) | |
9242 | { | |
9243 | const char *pos = cmd; | |
9244 | int error, pairwise; | |
9245 | ||
9246 | error = atoi(pos); | |
9247 | pos = os_strchr(pos, ' '); | |
9248 | if (!pos) | |
9249 | return -1; | |
9250 | pairwise = atoi(pos); | |
9251 | wpa_sm_key_request(wpa_s->wpa, error, pairwise); | |
9252 | return 0; | |
9253 | } | |
9254 | ||
daa40960 JM |
9255 | |
9256 | static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s) | |
9257 | { | |
9258 | #ifdef CONFIG_SME | |
9259 | struct wpa_driver_associate_params params; | |
9260 | int ret; | |
9261 | ||
9262 | os_memset(¶ms, 0, sizeof(params)); | |
9263 | params.bssid = wpa_s->bssid; | |
9264 | params.ssid = wpa_s->sme.ssid; | |
9265 | params.ssid_len = wpa_s->sme.ssid_len; | |
9266 | params.freq.freq = wpa_s->sme.freq; | |
9267 | if (wpa_s->last_assoc_req_wpa_ie) { | |
9268 | params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie); | |
9269 | params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie); | |
9270 | } | |
9271 | params.pairwise_suite = wpa_s->pairwise_cipher; | |
9272 | params.group_suite = wpa_s->group_cipher; | |
9273 | params.mgmt_group_suite = wpa_s->mgmt_group_cipher; | |
9274 | params.key_mgmt_suite = wpa_s->key_mgmt; | |
9275 | params.wpa_proto = wpa_s->wpa_proto; | |
9276 | params.mgmt_frame_protection = wpa_s->sme.mfp; | |
9277 | params.rrm_used = wpa_s->rrm.rrm_used; | |
9278 | if (wpa_s->sme.prev_bssid_set) | |
9279 | params.prev_bssid = wpa_s->sme.prev_bssid; | |
9280 | wpa_printf(MSG_INFO, "TESTING: Resend association request"); | |
9281 | ret = wpa_drv_associate(wpa_s, ¶ms); | |
9282 | wpa_s->testing_resend_assoc = 1; | |
9283 | return ret; | |
9284 | #else /* CONFIG_SME */ | |
9285 | return -1; | |
9286 | #endif /* CONFIG_SME */ | |
9287 | } | |
9288 | ||
60b893df JM |
9289 | #endif /* CONFIG_TESTING_OPTIONS */ |
9290 | ||
9291 | ||
86bd36f0 JM |
9292 | static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd) |
9293 | { | |
9294 | char *pos = cmd; | |
9295 | int frame; | |
9296 | size_t len; | |
9297 | struct wpabuf *buf; | |
9298 | struct ieee802_11_elems elems; | |
9299 | ||
9300 | frame = atoi(pos); | |
9301 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | |
9302 | return -1; | |
af041f99 | 9303 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
86bd36f0 JM |
9304 | |
9305 | pos = os_strchr(pos, ' '); | |
9306 | if (pos == NULL) | |
9307 | return -1; | |
9308 | pos++; | |
9309 | ||
9310 | len = os_strlen(pos); | |
9311 | if (len == 0) | |
9312 | return 0; | |
9313 | if (len & 1) | |
9314 | return -1; | |
9315 | len /= 2; | |
9316 | ||
9317 | buf = wpabuf_alloc(len); | |
9318 | if (buf == NULL) | |
9319 | return -1; | |
9320 | ||
9321 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { | |
9322 | wpabuf_free(buf); | |
9323 | return -1; | |
9324 | } | |
9325 | ||
9326 | if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) == | |
9327 | ParseFailed) { | |
9328 | wpabuf_free(buf); | |
9329 | return -1; | |
9330 | } | |
9331 | ||
9332 | if (wpa_s->vendor_elem[frame] == NULL) { | |
9333 | wpa_s->vendor_elem[frame] = buf; | |
af041f99 | 9334 | wpas_vendor_elem_update(wpa_s); |
86bd36f0 JM |
9335 | return 0; |
9336 | } | |
9337 | ||
9338 | if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) { | |
9339 | wpabuf_free(buf); | |
9340 | return -1; | |
9341 | } | |
9342 | ||
9343 | wpabuf_put_buf(wpa_s->vendor_elem[frame], buf); | |
9344 | wpabuf_free(buf); | |
af041f99 | 9345 | wpas_vendor_elem_update(wpa_s); |
86bd36f0 JM |
9346 | |
9347 | return 0; | |
9348 | } | |
9349 | ||
9350 | ||
9351 | static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd, | |
9352 | char *buf, size_t buflen) | |
9353 | { | |
9354 | int frame = atoi(cmd); | |
9355 | ||
9356 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | |
9357 | return -1; | |
af041f99 | 9358 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
86bd36f0 JM |
9359 | |
9360 | if (wpa_s->vendor_elem[frame] == NULL) | |
9361 | return 0; | |
9362 | ||
9363 | return wpa_snprintf_hex(buf, buflen, | |
9364 | wpabuf_head_u8(wpa_s->vendor_elem[frame]), | |
9365 | wpabuf_len(wpa_s->vendor_elem[frame])); | |
9366 | } | |
9367 | ||
9368 | ||
9369 | static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd) | |
9370 | { | |
9371 | char *pos = cmd; | |
9372 | int frame; | |
9373 | size_t len; | |
9374 | u8 *buf; | |
9375 | struct ieee802_11_elems elems; | |
af041f99 | 9376 | int res; |
86bd36f0 JM |
9377 | |
9378 | frame = atoi(pos); | |
9379 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | |
9380 | return -1; | |
af041f99 | 9381 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
86bd36f0 JM |
9382 | |
9383 | pos = os_strchr(pos, ' '); | |
9384 | if (pos == NULL) | |
9385 | return -1; | |
9386 | pos++; | |
9387 | ||
9388 | if (*pos == '*') { | |
9389 | wpabuf_free(wpa_s->vendor_elem[frame]); | |
9390 | wpa_s->vendor_elem[frame] = NULL; | |
af041f99 | 9391 | wpas_vendor_elem_update(wpa_s); |
86bd36f0 JM |
9392 | return 0; |
9393 | } | |
9394 | ||
9395 | if (wpa_s->vendor_elem[frame] == NULL) | |
9396 | return -1; | |
9397 | ||
9398 | len = os_strlen(pos); | |
9399 | if (len == 0) | |
9400 | return 0; | |
9401 | if (len & 1) | |
9402 | return -1; | |
9403 | len /= 2; | |
9404 | ||
9405 | buf = os_malloc(len); | |
9406 | if (buf == NULL) | |
9407 | return -1; | |
9408 | ||
9409 | if (hexstr2bin(pos, buf, len) < 0) { | |
9410 | os_free(buf); | |
9411 | return -1; | |
9412 | } | |
9413 | ||
9414 | if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) { | |
9415 | os_free(buf); | |
9416 | return -1; | |
9417 | } | |
9418 | ||
af041f99 | 9419 | res = wpas_vendor_elem_remove(wpa_s, frame, buf, len); |
86bd36f0 | 9420 | os_free(buf); |
af041f99 | 9421 | return res; |
86bd36f0 JM |
9422 | } |
9423 | ||
9424 | ||
f4b8bfae AK |
9425 | static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep) |
9426 | { | |
9427 | struct wpa_supplicant *wpa_s = ctx; | |
cf667c66 IP |
9428 | size_t len; |
9429 | const u8 *data; | |
f4b8bfae | 9430 | |
cf667c66 IP |
9431 | /* |
9432 | * Neighbor Report element (IEEE P802.11-REVmc/D5.0) | |
9433 | * BSSID[6] | |
9434 | * BSSID Information[4] | |
9435 | * Operating Class[1] | |
9436 | * Channel Number[1] | |
9437 | * PHY Type[1] | |
9438 | * Optional Subelements[variable] | |
9439 | */ | |
9440 | #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1) | |
9441 | ||
9442 | if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) { | |
f4b8bfae | 9443 | wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED); |
cf667c66 IP |
9444 | goto out; |
9445 | } | |
9446 | ||
9447 | data = wpabuf_head_u8(neighbor_rep); | |
9448 | len = wpabuf_len(neighbor_rep); | |
9449 | ||
9450 | while (len >= 2 + NR_IE_MIN_LEN) { | |
9451 | const u8 *nr; | |
9452 | char lci[256 * 2 + 1]; | |
9453 | char civic[256 * 2 + 1]; | |
9454 | u8 nr_len = data[1]; | |
9455 | const u8 *pos = data, *end; | |
9456 | ||
9457 | if (pos[0] != WLAN_EID_NEIGHBOR_REPORT || | |
9458 | nr_len < NR_IE_MIN_LEN) { | |
9459 | wpa_printf(MSG_DEBUG, | |
9460 | "CTRL: Invalid Neighbor Report element: id=%u len=%u", | |
9461 | data[0], nr_len); | |
9462 | goto out; | |
9463 | } | |
9464 | ||
9465 | if (2U + nr_len > len) { | |
9466 | wpa_printf(MSG_DEBUG, | |
9467 | "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u", | |
9468 | data[0], len, nr_len); | |
9469 | goto out; | |
9470 | } | |
9471 | pos += 2; | |
9472 | end = pos + nr_len; | |
9473 | ||
9474 | nr = pos; | |
9475 | pos += NR_IE_MIN_LEN; | |
9476 | ||
9477 | lci[0] = '\0'; | |
9478 | civic[0] = '\0'; | |
9479 | while (end - pos > 2) { | |
9480 | u8 s_id, s_len; | |
9481 | ||
9482 | s_id = *pos++; | |
9483 | s_len = *pos++; | |
9484 | if (s_len > end - pos) | |
9485 | goto out; | |
9486 | if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) { | |
9487 | /* Measurement Token[1] */ | |
9488 | /* Measurement Report Mode[1] */ | |
9489 | /* Measurement Type[1] */ | |
9490 | /* Measurement Report[variable] */ | |
9491 | switch (pos[2]) { | |
9492 | case MEASURE_TYPE_LCI: | |
9493 | if (lci[0]) | |
9494 | break; | |
9495 | wpa_snprintf_hex(lci, sizeof(lci), | |
9496 | pos, s_len); | |
9497 | break; | |
9498 | case MEASURE_TYPE_LOCATION_CIVIC: | |
9499 | if (civic[0]) | |
9500 | break; | |
9501 | wpa_snprintf_hex(civic, sizeof(civic), | |
9502 | pos, s_len); | |
9503 | break; | |
9504 | } | |
9505 | } | |
9506 | ||
9507 | pos += s_len; | |
9508 | } | |
9509 | ||
9510 | wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED | |
9511 | "bssid=" MACSTR | |
9512 | " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s", | |
9513 | MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN), | |
9514 | nr[ETH_ALEN + 4], nr[ETH_ALEN + 5], | |
9515 | nr[ETH_ALEN + 6], | |
9516 | lci[0] ? " lci=" : "", lci, | |
9517 | civic[0] ? " civic=" : "", civic); | |
9518 | ||
9519 | data = end; | |
9520 | len -= 2 + nr_len; | |
f4b8bfae | 9521 | } |
cf667c66 IP |
9522 | |
9523 | out: | |
9524 | wpabuf_free(neighbor_rep); | |
f4b8bfae AK |
9525 | } |
9526 | ||
9527 | ||
6a4f0ed7 JM |
9528 | static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s, |
9529 | char *cmd) | |
f4b8bfae | 9530 | { |
d41a5352 DS |
9531 | struct wpa_ssid_value ssid, *ssid_p = NULL; |
9532 | int ret, lci = 0, civic = 0; | |
9533 | char *ssid_s; | |
4c4b2305 | 9534 | |
d41a5352 DS |
9535 | ssid_s = os_strstr(cmd, "ssid="); |
9536 | if (ssid_s) { | |
9537 | if (ssid_parse(ssid_s + 5, &ssid)) { | |
9538 | wpa_printf(MSG_ERROR, | |
9539 | "CTRL: Send Neighbor Report: bad SSID"); | |
4c4b2305 | 9540 | return -1; |
d41a5352 DS |
9541 | } |
9542 | ||
4c4b2305 | 9543 | ssid_p = &ssid; |
d41a5352 DS |
9544 | |
9545 | /* | |
9546 | * Move cmd after the SSID text that may include "lci" or | |
9547 | * "civic". | |
9548 | */ | |
9549 | cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' '); | |
9550 | if (cmd) | |
9551 | cmd++; | |
9552 | ||
4c4b2305 AK |
9553 | } |
9554 | ||
d41a5352 DS |
9555 | if (cmd && os_strstr(cmd, "lci")) |
9556 | lci = 1; | |
9557 | ||
9558 | if (cmd && os_strstr(cmd, "civic")) | |
9559 | civic = 1; | |
9560 | ||
9561 | ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic, | |
4c4b2305 AK |
9562 | wpas_ctrl_neighbor_rep_cb, |
9563 | wpa_s); | |
9564 | ||
9565 | return ret; | |
f4b8bfae AK |
9566 | } |
9567 | ||
9568 | ||
65d9a5e2 JM |
9569 | static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s) |
9570 | { | |
9571 | eapol_sm_erp_flush(wpa_s->eapol); | |
9572 | return 0; | |
9573 | } | |
9574 | ||
9575 | ||
fb375883 IP |
9576 | static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s, |
9577 | char *cmd) | |
9578 | { | |
9579 | char *token, *context = NULL; | |
9580 | unsigned int enable = ~0, type = 0; | |
9581 | u8 _addr[ETH_ALEN], _mask[ETH_ALEN]; | |
9582 | u8 *addr = NULL, *mask = NULL; | |
9583 | ||
9584 | while ((token = str_token(cmd, " ", &context))) { | |
9585 | if (os_strcasecmp(token, "scan") == 0) { | |
9586 | type |= MAC_ADDR_RAND_SCAN; | |
9587 | } else if (os_strcasecmp(token, "sched") == 0) { | |
9588 | type |= MAC_ADDR_RAND_SCHED_SCAN; | |
9589 | } else if (os_strcasecmp(token, "pno") == 0) { | |
9590 | type |= MAC_ADDR_RAND_PNO; | |
9591 | } else if (os_strcasecmp(token, "all") == 0) { | |
9592 | type = wpa_s->mac_addr_rand_supported; | |
9593 | } else if (os_strncasecmp(token, "enable=", 7) == 0) { | |
9594 | enable = atoi(token + 7); | |
9595 | } else if (os_strncasecmp(token, "addr=", 5) == 0) { | |
9596 | addr = _addr; | |
9597 | if (hwaddr_aton(token + 5, addr)) { | |
9598 | wpa_printf(MSG_INFO, | |
9599 | "CTRL: Invalid MAC address: %s", | |
9600 | token); | |
9601 | return -1; | |
9602 | } | |
9603 | } else if (os_strncasecmp(token, "mask=", 5) == 0) { | |
9604 | mask = _mask; | |
9605 | if (hwaddr_aton(token + 5, mask)) { | |
9606 | wpa_printf(MSG_INFO, | |
9607 | "CTRL: Invalid MAC address mask: %s", | |
9608 | token); | |
9609 | return -1; | |
9610 | } | |
9611 | } else { | |
9612 | wpa_printf(MSG_INFO, | |
9613 | "CTRL: Invalid MAC_RAND_SCAN parameter: %s", | |
9614 | token); | |
9615 | return -1; | |
9616 | } | |
9617 | } | |
9618 | ||
9619 | if (!type) { | |
9620 | wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified"); | |
9621 | return -1; | |
9622 | } | |
9623 | ||
fb375883 IP |
9624 | if (enable > 1) { |
9625 | wpa_printf(MSG_INFO, | |
9626 | "CTRL: MAC_RAND_SCAN enable=<0/1> not specified"); | |
9627 | return -1; | |
9628 | } | |
9629 | ||
91b6eba7 EC |
9630 | if (!enable) |
9631 | return wpas_disable_mac_addr_randomization(wpa_s, type); | |
fb375883 | 9632 | |
91b6eba7 | 9633 | return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask); |
fb375883 IP |
9634 | } |
9635 | ||
9636 | ||
b8daac18 MH |
9637 | static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s, |
9638 | char *buf, size_t buflen) | |
9639 | { | |
9640 | size_t reply_len; | |
9641 | ||
9642 | reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen); | |
9643 | #ifdef CONFIG_AP | |
9644 | reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len], | |
9645 | buflen - reply_len); | |
9646 | #endif /* CONFIG_AP */ | |
9647 | return reply_len; | |
9648 | } | |
9649 | ||
9650 | ||
4c522c77 MH |
9651 | static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s) |
9652 | { | |
9653 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); | |
9654 | #ifdef CONFIG_AP | |
9655 | wpas_ap_pmksa_cache_flush(wpa_s); | |
9656 | #endif /* CONFIG_AP */ | |
9657 | } | |
9658 | ||
9659 | ||
3459381d JM |
9660 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
9661 | ||
9662 | static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s, | |
9663 | const char *cmd, char *buf, size_t buflen) | |
9664 | { | |
9665 | struct rsn_pmksa_cache_entry *entry; | |
9666 | struct wpa_ssid *ssid; | |
9667 | char *pos, *pos2, *end; | |
9668 | int ret; | |
9669 | struct os_reltime now; | |
9670 | ||
9671 | ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd)); | |
9672 | if (!ssid) | |
9673 | return -1; | |
9674 | ||
9675 | pos = buf; | |
9676 | end = buf + buflen; | |
9677 | ||
9678 | os_get_reltime(&now); | |
9679 | ||
9680 | /* | |
9681 | * Entry format: | |
9682 | * <BSSID> <PMKID> <PMK> <reauth_time in seconds> | |
9683 | * <expiration in seconds> <akmp> <opportunistic> | |
b7286c1b | 9684 | * [FILS Cache Identifier] |
3459381d JM |
9685 | */ |
9686 | ||
9687 | for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry; | |
9688 | entry = entry->next) { | |
9689 | if (entry->network_ctx != ssid) | |
9690 | continue; | |
9691 | ||
9692 | pos2 = pos; | |
9693 | ret = os_snprintf(pos2, end - pos2, MACSTR " ", | |
9694 | MAC2STR(entry->aa)); | |
9695 | if (os_snprintf_error(end - pos2, ret)) | |
9696 | break; | |
9697 | pos2 += ret; | |
9698 | ||
9699 | pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid, | |
9700 | PMKID_LEN); | |
9701 | ||
9702 | ret = os_snprintf(pos2, end - pos2, " "); | |
9703 | if (os_snprintf_error(end - pos2, ret)) | |
9704 | break; | |
9705 | pos2 += ret; | |
9706 | ||
9707 | pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk, | |
9708 | entry->pmk_len); | |
9709 | ||
9710 | ret = os_snprintf(pos2, end - pos2, " %d %d %d %d", | |
9711 | (int) (entry->reauth_time - now.sec), | |
9712 | (int) (entry->expiration - now.sec), | |
9713 | entry->akmp, | |
9714 | entry->opportunistic); | |
9715 | if (os_snprintf_error(end - pos2, ret)) | |
9716 | break; | |
9717 | pos2 += ret; | |
9718 | ||
b7286c1b JM |
9719 | if (entry->fils_cache_id_set) { |
9720 | ret = os_snprintf(pos2, end - pos2, " %02x%02x", | |
9721 | entry->fils_cache_id[0], | |
9722 | entry->fils_cache_id[1]); | |
9723 | if (os_snprintf_error(end - pos2, ret)) | |
9724 | break; | |
9725 | pos2 += ret; | |
9726 | } | |
9727 | ||
3459381d JM |
9728 | ret = os_snprintf(pos2, end - pos2, "\n"); |
9729 | if (os_snprintf_error(end - pos2, ret)) | |
9730 | break; | |
9731 | pos2 += ret; | |
9732 | ||
9733 | pos = pos2; | |
9734 | } | |
9735 | ||
9736 | return pos - buf; | |
9737 | } | |
9738 | ||
9739 | ||
9740 | static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s, | |
9741 | char *cmd) | |
9742 | { | |
9743 | struct rsn_pmksa_cache_entry *entry; | |
9744 | struct wpa_ssid *ssid; | |
9745 | char *pos, *pos2; | |
9746 | int ret = -1; | |
9747 | struct os_reltime now; | |
b7286c1b | 9748 | int reauth_time = 0, expiration = 0, i; |
3459381d JM |
9749 | |
9750 | /* | |
9751 | * Entry format: | |
9752 | * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds> | |
9753 | * <expiration in seconds> <akmp> <opportunistic> | |
b7286c1b | 9754 | * [FILS Cache Identifier] |
3459381d JM |
9755 | */ |
9756 | ||
9757 | ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd)); | |
9758 | if (!ssid) | |
9759 | return -1; | |
9760 | ||
9761 | pos = os_strchr(cmd, ' '); | |
9762 | if (!pos) | |
9763 | return -1; | |
9764 | pos++; | |
9765 | ||
9766 | entry = os_zalloc(sizeof(*entry)); | |
9767 | if (!entry) | |
9768 | return -1; | |
9769 | ||
9770 | if (hwaddr_aton(pos, entry->aa)) | |
9771 | goto fail; | |
9772 | ||
9773 | pos = os_strchr(pos, ' '); | |
9774 | if (!pos) | |
9775 | goto fail; | |
9776 | pos++; | |
9777 | ||
9778 | if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0) | |
9779 | goto fail; | |
9780 | ||
9781 | pos = os_strchr(pos, ' '); | |
9782 | if (!pos) | |
9783 | goto fail; | |
9784 | pos++; | |
9785 | ||
9786 | pos2 = os_strchr(pos, ' '); | |
9787 | if (!pos2) | |
9788 | goto fail; | |
9789 | entry->pmk_len = (pos2 - pos) / 2; | |
9790 | if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX || | |
9791 | hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0) | |
9792 | goto fail; | |
9793 | ||
9794 | pos = os_strchr(pos, ' '); | |
9795 | if (!pos) | |
9796 | goto fail; | |
9797 | pos++; | |
9798 | ||
9799 | if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration, | |
9800 | &entry->akmp, &entry->opportunistic) != 4) | |
9801 | goto fail; | |
b7286c1b JM |
9802 | for (i = 0; i < 4; i++) { |
9803 | pos = os_strchr(pos, ' '); | |
9804 | if (!pos) { | |
9805 | if (i < 3) | |
9806 | goto fail; | |
9807 | break; | |
9808 | } | |
9809 | pos++; | |
9810 | } | |
9811 | if (pos) { | |
9812 | if (hexstr2bin(pos, entry->fils_cache_id, | |
9813 | FILS_CACHE_ID_LEN) < 0) | |
9814 | goto fail; | |
9815 | entry->fils_cache_id_set = 1; | |
9816 | } | |
3459381d JM |
9817 | os_get_reltime(&now); |
9818 | entry->expiration = now.sec + expiration; | |
9819 | entry->reauth_time = now.sec + reauth_time; | |
9820 | ||
9821 | entry->network_ctx = ssid; | |
9822 | ||
9823 | wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry); | |
9824 | entry = NULL; | |
9825 | ret = 0; | |
9826 | fail: | |
9827 | os_free(entry); | |
9828 | return ret; | |
9829 | } | |
9830 | ||
4d77d80e MH |
9831 | |
9832 | #ifdef CONFIG_MESH | |
9833 | ||
9834 | static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s, | |
9835 | const char *cmd, char *buf, | |
9836 | size_t buflen) | |
9837 | { | |
9838 | u8 spa[ETH_ALEN]; | |
9839 | ||
9840 | if (!wpa_s->ifmsh) | |
9841 | return -1; | |
9842 | ||
9843 | if (os_strcasecmp(cmd, "any") == 0) | |
9844 | return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen); | |
9845 | ||
9846 | if (hwaddr_aton(cmd, spa)) | |
9847 | return -1; | |
9848 | ||
9849 | return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen); | |
9850 | } | |
9851 | ||
9852 | ||
9853 | static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s, | |
9854 | char *cmd) | |
9855 | { | |
9856 | /* | |
9857 | * We do not check mesh interface existance because PMKSA should be | |
9858 | * stored before wpa_s->ifmsh creation to suppress commit message | |
9859 | * creation. | |
9860 | */ | |
9861 | return wpas_ap_pmksa_cache_add_external(wpa_s, cmd); | |
9862 | } | |
9863 | ||
9864 | #endif /* CONFIG_MESH */ | |
3459381d JM |
9865 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
9866 | ||
9867 | ||
5732b770 JM |
9868 | #ifdef CONFIG_FILS |
9869 | static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s, | |
9870 | const char *cmd) | |
9871 | { | |
9872 | struct fils_hlp_req *req; | |
9873 | const char *pos; | |
9874 | ||
9875 | /* format: <dst> <packet starting from ethertype> */ | |
9876 | ||
9877 | req = os_zalloc(sizeof(*req)); | |
9878 | if (!req) | |
9879 | return -1; | |
9880 | ||
9881 | if (hwaddr_aton(cmd, req->dst)) | |
9882 | goto fail; | |
9883 | ||
9884 | pos = os_strchr(cmd, ' '); | |
9885 | if (!pos) | |
9886 | goto fail; | |
9887 | pos++; | |
9888 | req->pkt = wpabuf_parse_bin(pos); | |
9889 | if (!req->pkt) | |
9890 | goto fail; | |
9891 | ||
9892 | dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list); | |
9893 | return 0; | |
9894 | fail: | |
9895 | wpabuf_free(req->pkt); | |
9896 | os_free(req); | |
9897 | return -1; | |
9898 | } | |
9899 | #endif /* CONFIG_FILS */ | |
9900 | ||
9901 | ||
8db9a79d JM |
9902 | static int wpas_ctrl_cmd_debug_level(const char *cmd) |
9903 | { | |
9904 | if (os_strcmp(cmd, "PING") == 0 || | |
9905 | os_strncmp(cmd, "BSS ", 4) == 0 || | |
9906 | os_strncmp(cmd, "GET_NETWORK ", 12) == 0 || | |
9907 | os_strncmp(cmd, "STATUS", 6) == 0 || | |
9908 | os_strncmp(cmd, "STA ", 4) == 0 || | |
9909 | os_strncmp(cmd, "STA-", 4) == 0) | |
9910 | return MSG_EXCESSIVE; | |
9911 | return MSG_DEBUG; | |
9912 | } | |
9913 | ||
9914 | ||
6fc6879b JM |
9915 | char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, |
9916 | char *buf, size_t *resp_len) | |
9917 | { | |
9918 | char *reply; | |
b563b388 | 9919 | const int reply_size = 4096; |
6fc6879b JM |
9920 | int reply_len; |
9921 | ||
9922 | if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 || | |
c10e0ccc JM |
9923 | os_strncmp(buf, "SET_NETWORK ", 12) == 0 || |
9924 | os_strncmp(buf, "PMKSA_ADD ", 10) == 0 || | |
9925 | os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) { | |
d31b5ac7 JM |
9926 | if (wpa_debug_show_keys) |
9927 | wpa_dbg(wpa_s, MSG_DEBUG, | |
9928 | "Control interface command '%s'", buf); | |
9929 | else | |
9930 | wpa_dbg(wpa_s, MSG_DEBUG, | |
9931 | "Control interface command '%s [REMOVED]'", | |
9932 | os_strncmp(buf, WPA_CTRL_RSP, | |
9933 | os_strlen(WPA_CTRL_RSP)) == 0 ? | |
c10e0ccc JM |
9934 | WPA_CTRL_RSP : |
9935 | (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ? | |
9936 | "SET_NETWORK" : "key-add")); | |
d31b5ac7 | 9937 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 || |
679f2e7c | 9938 | os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) { |
6fc6879b JM |
9939 | wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", |
9940 | (const u8 *) buf, os_strlen(buf)); | |
9941 | } else { | |
8db9a79d | 9942 | int level = wpas_ctrl_cmd_debug_level(buf); |
b470b2bf | 9943 | wpa_dbg(wpa_s, level, "Control interface command '%s'", buf); |
6fc6879b JM |
9944 | } |
9945 | ||
9946 | reply = os_malloc(reply_size); | |
9947 | if (reply == NULL) { | |
9948 | *resp_len = 1; | |
9949 | return NULL; | |
9950 | } | |
9951 | ||
9952 | os_memcpy(reply, "OK\n", 3); | |
9953 | reply_len = 3; | |
9954 | ||
9955 | if (os_strcmp(buf, "PING") == 0) { | |
9956 | os_memcpy(reply, "PONG\n", 5); | |
9957 | reply_len = 5; | |
0eed2a8d JD |
9958 | } else if (os_strcmp(buf, "IFNAME") == 0) { |
9959 | reply_len = os_strlen(wpa_s->ifname); | |
9960 | os_memcpy(reply, wpa_s->ifname, reply_len); | |
ac6912b5 BG |
9961 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
9962 | if (wpa_debug_reopen_file() < 0) | |
9963 | reply_len = -1; | |
77895cd9 JM |
9964 | } else if (os_strncmp(buf, "NOTE ", 5) == 0) { |
9965 | wpa_printf(MSG_INFO, "NOTE: %s", buf + 5); | |
6fc6879b JM |
9966 | } else if (os_strcmp(buf, "MIB") == 0) { |
9967 | reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); | |
9968 | if (reply_len >= 0) { | |
5ac73acf JM |
9969 | reply_len += eapol_sm_get_mib(wpa_s->eapol, |
9970 | reply + reply_len, | |
9971 | reply_size - reply_len); | |
948ba8c2 JM |
9972 | #ifdef CONFIG_MACSEC |
9973 | reply_len += ieee802_1x_kay_get_mib( | |
9974 | wpa_s->kay, reply + reply_len, | |
9975 | reply_size - reply_len); | |
9976 | #endif /* CONFIG_MACSEC */ | |
6fc6879b JM |
9977 | } |
9978 | } else if (os_strncmp(buf, "STATUS", 6) == 0) { | |
9979 | reply_len = wpa_supplicant_ctrl_iface_status( | |
9980 | wpa_s, buf + 6, reply, reply_size); | |
9981 | } else if (os_strcmp(buf, "PMKSA") == 0) { | |
b8daac18 | 9982 | reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size); |
79e2b1cc | 9983 | } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) { |
4c522c77 | 9984 | wpas_ctrl_iface_pmksa_flush(wpa_s); |
3459381d JM |
9985 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
9986 | } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) { | |
9987 | reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10, | |
9988 | reply, reply_size); | |
9989 | } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) { | |
9990 | if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0) | |
9991 | reply_len = -1; | |
4d77d80e MH |
9992 | #ifdef CONFIG_MESH |
9993 | } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) { | |
9994 | reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15, | |
9995 | reply, reply_size); | |
9996 | } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) { | |
9997 | if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0) | |
9998 | reply_len = -1; | |
9999 | #endif /* CONFIG_MESH */ | |
3459381d | 10000 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
6fc6879b JM |
10001 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
10002 | if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) | |
10003 | reply_len = -1; | |
10263dc2 OO |
10004 | } else if (os_strncmp(buf, "DUMP", 4) == 0) { |
10005 | reply_len = wpa_config_dump_values(wpa_s->conf, | |
10006 | reply, reply_size); | |
acec8d32 JM |
10007 | } else if (os_strncmp(buf, "GET ", 4) == 0) { |
10008 | reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4, | |
10009 | reply, reply_size); | |
6fc6879b JM |
10010 | } else if (os_strcmp(buf, "LOGON") == 0) { |
10011 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); | |
10012 | } else if (os_strcmp(buf, "LOGOFF") == 0) { | |
10013 | eapol_sm_notify_logoff(wpa_s->eapol, TRUE); | |
10014 | } else if (os_strcmp(buf, "REASSOCIATE") == 0) { | |
8401a6b0 JM |
10015 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
10016 | reply_len = -1; | |
9796a86c JM |
10017 | else |
10018 | wpas_request_connection(wpa_s); | |
0f44ec8e PQ |
10019 | } else if (os_strcmp(buf, "REATTACH") == 0) { |
10020 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED || | |
10021 | !wpa_s->current_ssid) | |
10022 | reply_len = -1; | |
10023 | else { | |
10024 | wpa_s->reattach = 1; | |
10025 | wpas_request_connection(wpa_s); | |
10026 | } | |
6fc6879b | 10027 | } else if (os_strcmp(buf, "RECONNECT") == 0) { |
8401a6b0 JM |
10028 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
10029 | reply_len = -1; | |
9796a86c JM |
10030 | else if (wpa_s->disconnected) |
10031 | wpas_request_connection(wpa_s); | |
ec717917 | 10032 | #ifdef IEEE8021X_EAPOL |
6fc6879b JM |
10033 | } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { |
10034 | if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) | |
10035 | reply_len = -1; | |
ec717917 | 10036 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
10037 | #ifdef CONFIG_IEEE80211R |
10038 | } else if (os_strncmp(buf, "FT_DS ", 6) == 0) { | |
10039 | if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6)) | |
10040 | reply_len = -1; | |
10041 | #endif /* CONFIG_IEEE80211R */ | |
fcc60db4 JM |
10042 | #ifdef CONFIG_WPS |
10043 | } else if (os_strcmp(buf, "WPS_PBC") == 0) { | |
3152ff42 CWY |
10044 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL); |
10045 | if (res == -2) { | |
10046 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
10047 | reply_len = 17; | |
10048 | } else if (res) | |
fcc60db4 JM |
10049 | reply_len = -1; |
10050 | } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) { | |
3152ff42 CWY |
10051 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8); |
10052 | if (res == -2) { | |
10053 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
10054 | reply_len = 17; | |
10055 | } else if (res) | |
fcc60db4 JM |
10056 | reply_len = -1; |
10057 | } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) { | |
10058 | reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8, | |
10059 | reply, | |
10060 | reply_size); | |
3981cb3c JM |
10061 | } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) { |
10062 | reply_len = wpa_supplicant_ctrl_iface_wps_check_pin( | |
10063 | wpa_s, buf + 14, reply, reply_size); | |
2f9929ff AC |
10064 | } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { |
10065 | if (wpas_wps_cancel(wpa_s)) | |
10066 | reply_len = -1; | |
71892384 | 10067 | #ifdef CONFIG_WPS_NFC |
3f2c8ba6 JM |
10068 | } else if (os_strcmp(buf, "WPS_NFC") == 0) { |
10069 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL)) | |
10070 | reply_len = -1; | |
10071 | } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) { | |
10072 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8)) | |
10073 | reply_len = -1; | |
bbf41865 JM |
10074 | } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) { |
10075 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token( | |
10076 | wpa_s, buf + 21, reply, reply_size); | |
3f2c8ba6 JM |
10077 | } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) { |
10078 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token( | |
10079 | wpa_s, buf + 14, reply, reply_size); | |
d7645d23 JM |
10080 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) { |
10081 | if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s, | |
10082 | buf + 17)) | |
10083 | reply_len = -1; | |
e65552dd JM |
10084 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) { |
10085 | reply_len = wpas_ctrl_nfc_get_handover_req( | |
10086 | wpa_s, buf + 21, reply, reply_size); | |
10087 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) { | |
10088 | reply_len = wpas_ctrl_nfc_get_handover_sel( | |
10089 | wpa_s, buf + 21, reply, reply_size); | |
e4758827 JM |
10090 | } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) { |
10091 | if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20)) | |
10092 | reply_len = -1; | |
71892384 | 10093 | #endif /* CONFIG_WPS_NFC */ |
fcc60db4 JM |
10094 | } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) { |
10095 | if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8)) | |
10096 | reply_len = -1; | |
70d84f11 JM |
10097 | #ifdef CONFIG_AP |
10098 | } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) { | |
10099 | reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin( | |
10100 | wpa_s, buf + 11, reply, reply_size); | |
10101 | #endif /* CONFIG_AP */ | |
72df2f5f | 10102 | #ifdef CONFIG_WPS_ER |
e9bcfebf | 10103 | } else if (os_strcmp(buf, "WPS_ER_START") == 0) { |
08486685 JM |
10104 | if (wpas_wps_er_start(wpa_s, NULL)) |
10105 | reply_len = -1; | |
10106 | } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) { | |
10107 | if (wpas_wps_er_start(wpa_s, buf + 13)) | |
e9bcfebf JM |
10108 | reply_len = -1; |
10109 | } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) { | |
f77cedc1 | 10110 | wpas_wps_er_stop(wpa_s); |
72df2f5f JM |
10111 | } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) { |
10112 | if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11)) | |
10113 | reply_len = -1; | |
564cd7fa | 10114 | } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) { |
ed159ad4 JM |
10115 | int ret = wpas_wps_er_pbc(wpa_s, buf + 11); |
10116 | if (ret == -2) { | |
10117 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
10118 | reply_len = 17; | |
10119 | } else if (ret == -3) { | |
10120 | os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18); | |
10121 | reply_len = 18; | |
10122 | } else if (ret == -4) { | |
10123 | os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20); | |
10124 | reply_len = 20; | |
10125 | } else if (ret) | |
564cd7fa | 10126 | reply_len = -1; |
e64dcfd5 JM |
10127 | } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) { |
10128 | if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13)) | |
10129 | reply_len = -1; | |
ef10f473 JM |
10130 | } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) { |
10131 | if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s, | |
10132 | buf + 18)) | |
10133 | reply_len = -1; | |
7d6640a6 JM |
10134 | } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) { |
10135 | if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14)) | |
10136 | reply_len = -1; | |
1cea09a9 JM |
10137 | #ifdef CONFIG_WPS_NFC |
10138 | } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) { | |
10139 | reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | |
10140 | wpa_s, buf + 24, reply, reply_size); | |
10141 | #endif /* CONFIG_WPS_NFC */ | |
72df2f5f | 10142 | #endif /* CONFIG_WPS_ER */ |
fcc60db4 | 10143 | #endif /* CONFIG_WPS */ |
11ef8d35 JM |
10144 | #ifdef CONFIG_IBSS_RSN |
10145 | } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) { | |
10146 | if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) | |
10147 | reply_len = -1; | |
10148 | #endif /* CONFIG_IBSS_RSN */ | |
603a3f34 | 10149 | #ifdef CONFIG_MESH |
5b78493f MH |
10150 | } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) { |
10151 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( | |
10152 | wpa_s, buf + 19, reply, reply_size); | |
10153 | } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) { | |
10154 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( | |
10155 | wpa_s, "", reply, reply_size); | |
603a3f34 JL |
10156 | } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) { |
10157 | if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15)) | |
10158 | reply_len = -1; | |
10159 | } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) { | |
10160 | if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s, | |
10161 | buf + 18)) | |
10162 | reply_len = -1; | |
e174ef34 MH |
10163 | } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) { |
10164 | if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17)) | |
10165 | reply_len = -1; | |
2604edbf MH |
10166 | } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) { |
10167 | if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14)) | |
10168 | reply_len = -1; | |
7ace4328 PKC |
10169 | } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) { |
10170 | if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16)) | |
10171 | reply_len = -1; | |
603a3f34 | 10172 | #endif /* CONFIG_MESH */ |
b563b388 JM |
10173 | #ifdef CONFIG_P2P |
10174 | } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { | |
51775096 | 10175 | if (p2p_ctrl_find(wpa_s, buf + 8)) |
b563b388 JM |
10176 | reply_len = -1; |
10177 | } else if (os_strcmp(buf, "P2P_FIND") == 0) { | |
10178 | if (p2p_ctrl_find(wpa_s, "")) | |
10179 | reply_len = -1; | |
10180 | } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) { | |
10181 | wpas_p2p_stop_find(wpa_s); | |
f309c18e KV |
10182 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) { |
10183 | if (p2p_ctrl_asp_provision(wpa_s, buf + 18)) | |
10184 | reply_len = -1; | |
10185 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) { | |
10186 | if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23)) | |
10187 | reply_len = -1; | |
b563b388 JM |
10188 | } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) { |
10189 | reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply, | |
10190 | reply_size); | |
10191 | } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) { | |
10192 | if (p2p_ctrl_listen(wpa_s, buf + 11)) | |
10193 | reply_len = -1; | |
10194 | } else if (os_strcmp(buf, "P2P_LISTEN") == 0) { | |
10195 | if (p2p_ctrl_listen(wpa_s, "")) | |
10196 | reply_len = -1; | |
10197 | } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) { | |
10198 | if (wpas_p2p_group_remove(wpa_s, buf + 17)) | |
10199 | reply_len = -1; | |
10200 | } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) { | |
38dcc86c | 10201 | if (p2p_ctrl_group_add(wpa_s, "")) |
b563b388 JM |
10202 | reply_len = -1; |
10203 | } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) { | |
10204 | if (p2p_ctrl_group_add(wpa_s, buf + 14)) | |
10205 | reply_len = -1; | |
57b38882 PK |
10206 | } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) { |
10207 | reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply, | |
10208 | reply_size); | |
b563b388 JM |
10209 | } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) { |
10210 | if (p2p_ctrl_prov_disc(wpa_s, buf + 14)) | |
10211 | reply_len = -1; | |
10212 | } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) { | |
10213 | reply_len = p2p_get_passphrase(wpa_s, reply, reply_size); | |
10214 | } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) { | |
10215 | reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply, | |
10216 | reply_size); | |
10217 | } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) { | |
10218 | if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0) | |
10219 | reply_len = -1; | |
10220 | } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) { | |
10221 | if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0) | |
10222 | reply_len = -1; | |
10223 | } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) { | |
10224 | wpas_p2p_sd_service_update(wpa_s); | |
10225 | } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) { | |
10226 | if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0) | |
10227 | reply_len = -1; | |
10228 | } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) { | |
10229 | wpas_p2p_service_flush(wpa_s); | |
10230 | } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) { | |
10231 | if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0) | |
10232 | reply_len = -1; | |
10233 | } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) { | |
10234 | if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0) | |
10235 | reply_len = -1; | |
ae9d45f3 KV |
10236 | } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) { |
10237 | if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0) | |
10238 | reply_len = -1; | |
b563b388 JM |
10239 | } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) { |
10240 | if (p2p_ctrl_reject(wpa_s, buf + 11) < 0) | |
10241 | reply_len = -1; | |
10242 | } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) { | |
10243 | if (p2p_ctrl_invite(wpa_s, buf + 11) < 0) | |
10244 | reply_len = -1; | |
10245 | } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) { | |
10246 | reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply, | |
10247 | reply_size); | |
10248 | } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) { | |
10249 | if (p2p_ctrl_set(wpa_s, buf + 8) < 0) | |
10250 | reply_len = -1; | |
10251 | } else if (os_strcmp(buf, "P2P_FLUSH") == 0) { | |
acb54643 | 10252 | p2p_ctrl_flush(wpa_s); |
9d562b79 SS |
10253 | } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { |
10254 | if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) | |
10255 | reply_len = -1; | |
59eba7a2 JM |
10256 | } else if (os_strcmp(buf, "P2P_CANCEL") == 0) { |
10257 | if (wpas_p2p_cancel(wpa_s)) | |
10258 | reply_len = -1; | |
b563b388 JM |
10259 | } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) { |
10260 | if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0) | |
10261 | reply_len = -1; | |
10262 | } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) { | |
10263 | if (p2p_ctrl_presence_req(wpa_s, "") < 0) | |
10264 | reply_len = -1; | |
10265 | } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) { | |
10266 | if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0) | |
10267 | reply_len = -1; | |
10268 | } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) { | |
10269 | if (p2p_ctrl_ext_listen(wpa_s, "") < 0) | |
10270 | reply_len = -1; | |
f2c56602 JM |
10271 | } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) { |
10272 | if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0) | |
10273 | reply_len = -1; | |
a6f5b193 PX |
10274 | } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) { |
10275 | if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13)) | |
10276 | reply_len = -1; | |
10277 | } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) { | |
10278 | if (wpas_p2p_lo_stop(wpa_s)) | |
10279 | reply_len = -1; | |
b563b388 | 10280 | #endif /* CONFIG_P2P */ |
9675ce35 JM |
10281 | #ifdef CONFIG_WIFI_DISPLAY |
10282 | } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) { | |
10283 | if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0) | |
10284 | reply_len = -1; | |
10285 | } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) { | |
10286 | reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16, | |
10287 | reply, reply_size); | |
10288 | #endif /* CONFIG_WIFI_DISPLAY */ | |
afc064fe JM |
10289 | #ifdef CONFIG_INTERWORKING |
10290 | } else if (os_strcmp(buf, "FETCH_ANQP") == 0) { | |
10291 | if (interworking_fetch_anqp(wpa_s) < 0) | |
10292 | reply_len = -1; | |
10293 | } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) { | |
10294 | interworking_stop_fetch_anqp(wpa_s); | |
356d1488 JM |
10295 | } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) { |
10296 | if (ctrl_interworking_select(wpa_s, NULL) < 0) | |
10297 | reply_len = -1; | |
10298 | } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) { | |
10299 | if (ctrl_interworking_select(wpa_s, buf + 20) < 0) | |
b02fe7ff JM |
10300 | reply_len = -1; |
10301 | } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) { | |
f91a512f | 10302 | if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0) |
b02fe7ff | 10303 | reply_len = -1; |
f91a512f JM |
10304 | } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) { |
10305 | int id; | |
10306 | ||
10307 | id = ctrl_interworking_connect(wpa_s, buf + 25, 1); | |
10308 | if (id < 0) | |
10309 | reply_len = -1; | |
10310 | else { | |
10311 | reply_len = os_snprintf(reply, reply_size, "%d\n", id); | |
10312 | if (os_snprintf_error(reply_size, reply_len)) | |
10313 | reply_len = -1; | |
10314 | } | |
afc064fe JM |
10315 | } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) { |
10316 | if (get_anqp(wpa_s, buf + 9) < 0) | |
10317 | reply_len = -1; | |
b1f12296 JM |
10318 | } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) { |
10319 | if (gas_request(wpa_s, buf + 12) < 0) | |
10320 | reply_len = -1; | |
10321 | } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) { | |
10322 | reply_len = gas_response_get(wpa_s, buf + 17, reply, | |
10323 | reply_size); | |
afc064fe | 10324 | #endif /* CONFIG_INTERWORKING */ |
a8918e86 JK |
10325 | #ifdef CONFIG_HS20 |
10326 | } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) { | |
10327 | if (get_hs20_anqp(wpa_s, buf + 14) < 0) | |
10328 | reply_len = -1; | |
10329 | } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) { | |
10330 | if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0) | |
10331 | reply_len = -1; | |
184e110c | 10332 | } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) { |
8dd5c1b4 JN |
10333 | if (hs20_icon_request(wpa_s, buf + 18, 0) < 0) |
10334 | reply_len = -1; | |
10335 | } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) { | |
10336 | if (hs20_icon_request(wpa_s, buf + 14, 1) < 0) | |
10337 | reply_len = -1; | |
10338 | } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) { | |
10339 | reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size); | |
10340 | } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) { | |
10341 | if (del_hs20_icon(wpa_s, buf + 14) < 0) | |
184e110c | 10342 | reply_len = -1; |
b572df86 | 10343 | } else if (os_strcmp(buf, "FETCH_OSU") == 0) { |
dd20eabd JM |
10344 | if (hs20_fetch_osu(wpa_s, 0) < 0) |
10345 | reply_len = -1; | |
10346 | } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) { | |
10347 | if (hs20_fetch_osu(wpa_s, 1) < 0) | |
b572df86 JM |
10348 | reply_len = -1; |
10349 | } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) { | |
10350 | hs20_cancel_fetch_osu(wpa_s); | |
a8918e86 | 10351 | #endif /* CONFIG_HS20 */ |
6fc6879b JM |
10352 | } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) |
10353 | { | |
10354 | if (wpa_supplicant_ctrl_iface_ctrl_rsp( | |
10355 | wpa_s, buf + os_strlen(WPA_CTRL_RSP))) | |
10356 | reply_len = -1; | |
bceb8431 JM |
10357 | else { |
10358 | /* | |
10359 | * Notify response from timeout to allow the control | |
10360 | * interface response to be sent first. | |
10361 | */ | |
10362 | eloop_register_timeout(0, 0, wpas_ctrl_eapol_response, | |
10363 | wpa_s, NULL); | |
10364 | } | |
6fc6879b JM |
10365 | } else if (os_strcmp(buf, "RECONFIGURE") == 0) { |
10366 | if (wpa_supplicant_reload_configuration(wpa_s)) | |
10367 | reply_len = -1; | |
10368 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | |
1a1bf008 | 10369 | wpa_supplicant_terminate_proc(wpa_s->global); |
6fc6879b JM |
10370 | } else if (os_strncmp(buf, "BSSID ", 6) == 0) { |
10371 | if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) | |
10372 | reply_len = -1; | |
9aa10e2b DS |
10373 | } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) { |
10374 | reply_len = wpa_supplicant_ctrl_iface_blacklist( | |
10375 | wpa_s, buf + 9, reply, reply_size); | |
0597a5b5 DS |
10376 | } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) { |
10377 | reply_len = wpa_supplicant_ctrl_iface_log_level( | |
10378 | wpa_s, buf + 9, reply, reply_size); | |
90903a77 VD |
10379 | } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) { |
10380 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | |
10381 | wpa_s, buf + 14, reply, reply_size); | |
6fc6879b JM |
10382 | } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { |
10383 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | |
90903a77 | 10384 | wpa_s, NULL, reply, reply_size); |
6fc6879b | 10385 | } else if (os_strcmp(buf, "DISCONNECT") == 0) { |
5f040be4 | 10386 | wpas_request_disconnection(wpa_s); |
fee52342 JM |
10387 | } else if (os_strcmp(buf, "SCAN") == 0) { |
10388 | wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len); | |
10389 | } else if (os_strncmp(buf, "SCAN ", 5) == 0) { | |
10390 | wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len); | |
6fc6879b JM |
10391 | } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { |
10392 | reply_len = wpa_supplicant_ctrl_iface_scan_results( | |
10393 | wpa_s, reply, reply_size); | |
2ea2166d JM |
10394 | } else if (os_strcmp(buf, "ABORT_SCAN") == 0) { |
10395 | if (wpas_abort_ongoing_scan(wpa_s) < 0) | |
10396 | reply_len = -1; | |
6fc6879b JM |
10397 | } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { |
10398 | if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) | |
10399 | reply_len = -1; | |
10400 | } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { | |
10401 | if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) | |
10402 | reply_len = -1; | |
10403 | } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { | |
10404 | if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) | |
10405 | reply_len = -1; | |
10406 | } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { | |
10407 | reply_len = wpa_supplicant_ctrl_iface_add_network( | |
10408 | wpa_s, reply, reply_size); | |
10409 | } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { | |
10410 | if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) | |
10411 | reply_len = -1; | |
10412 | } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { | |
10413 | if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) | |
10414 | reply_len = -1; | |
10415 | } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { | |
10416 | reply_len = wpa_supplicant_ctrl_iface_get_network( | |
10417 | wpa_s, buf + 12, reply, reply_size); | |
1c330a2f | 10418 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
daae4995 AN |
10419 | if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12, |
10420 | wpa_s)) | |
1c330a2f | 10421 | reply_len = -1; |
d94c9ee6 JM |
10422 | } else if (os_strcmp(buf, "LIST_CREDS") == 0) { |
10423 | reply_len = wpa_supplicant_ctrl_iface_list_creds( | |
10424 | wpa_s, reply, reply_size); | |
10425 | } else if (os_strcmp(buf, "ADD_CRED") == 0) { | |
10426 | reply_len = wpa_supplicant_ctrl_iface_add_cred( | |
10427 | wpa_s, reply, reply_size); | |
10428 | } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) { | |
10429 | if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12)) | |
10430 | reply_len = -1; | |
10431 | } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) { | |
10432 | if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9)) | |
10433 | reply_len = -1; | |
c880ab87 JM |
10434 | } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) { |
10435 | reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9, | |
10436 | reply, | |
10437 | reply_size); | |
6fc6879b JM |
10438 | #ifndef CONFIG_NO_CONFIG_WRITE |
10439 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | |
10440 | if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) | |
10441 | reply_len = -1; | |
10442 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
10443 | } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { | |
10444 | reply_len = wpa_supplicant_ctrl_iface_get_capability( | |
10445 | wpa_s, buf + 15, reply, reply_size); | |
10446 | } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { | |
10447 | if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) | |
10448 | reply_len = -1; | |
67b9bd08 DS |
10449 | } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) { |
10450 | if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14)) | |
10451 | reply_len = -1; | |
4b4a8ae5 JM |
10452 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
10453 | reply_len = wpa_supplicant_global_iface_list( | |
10454 | wpa_s->global, reply, reply_size); | |
56e2fc2c | 10455 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { |
6fc6879b | 10456 | reply_len = wpa_supplicant_global_iface_interfaces( |
56e2fc2c | 10457 | wpa_s->global, buf + 10, reply, reply_size); |
6fc6879b JM |
10458 | } else if (os_strncmp(buf, "BSS ", 4) == 0) { |
10459 | reply_len = wpa_supplicant_ctrl_iface_bss( | |
10460 | wpa_s, buf + 4, reply, reply_size); | |
e653b622 JM |
10461 | #ifdef CONFIG_AP |
10462 | } else if (os_strcmp(buf, "STA-FIRST") == 0) { | |
10463 | reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size); | |
10464 | } else if (os_strncmp(buf, "STA ", 4) == 0) { | |
10465 | reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply, | |
10466 | reply_size); | |
10467 | } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { | |
10468 | reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply, | |
10469 | reply_size); | |
e60b2951 JJ |
10470 | } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) { |
10471 | if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15)) | |
10472 | reply_len = -1; | |
10473 | } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) { | |
10474 | if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13)) | |
10475 | reply_len = -1; | |
334bf36a AO |
10476 | } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) { |
10477 | if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12)) | |
10478 | reply_len = -1; | |
99650cad JM |
10479 | } else if (os_strcmp(buf, "STOP_AP") == 0) { |
10480 | if (wpas_ap_stop_ap(wpa_s)) | |
10481 | reply_len = -1; | |
e653b622 | 10482 | #endif /* CONFIG_AP */ |
207ef3fb JM |
10483 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
10484 | wpas_notify_suspend(wpa_s->global); | |
10485 | } else if (os_strcmp(buf, "RESUME") == 0) { | |
10486 | wpas_notify_resume(wpa_s->global); | |
9ff4de6d | 10487 | #ifdef CONFIG_TESTING_OPTIONS |
32d5295f JM |
10488 | } else if (os_strcmp(buf, "DROP_SA") == 0) { |
10489 | wpa_supplicant_ctrl_iface_drop_sa(wpa_s); | |
9ff4de6d | 10490 | #endif /* CONFIG_TESTING_OPTIONS */ |
86d4f806 JM |
10491 | } else if (os_strncmp(buf, "ROAM ", 5) == 0) { |
10492 | if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) | |
10493 | reply_len = -1; | |
0d0a8ca1 | 10494 | } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { |
5407c69d | 10495 | wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0; |
78633c37 SL |
10496 | } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) { |
10497 | if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15)) | |
10498 | reply_len = -1; | |
10499 | } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) { | |
10500 | if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s, | |
10501 | buf + 17)) | |
10502 | reply_len = -1; | |
39ee845f | 10503 | } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) { |
a1144000 | 10504 | wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10); |
281ff0aa GP |
10505 | #ifdef CONFIG_TDLS |
10506 | } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) { | |
10507 | if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14)) | |
10508 | reply_len = -1; | |
10509 | } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) { | |
10510 | if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11)) | |
10511 | reply_len = -1; | |
10512 | } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) { | |
10513 | if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14)) | |
10514 | reply_len = -1; | |
6b90deae AN |
10515 | } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) { |
10516 | if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s, | |
10517 | buf + 17)) | |
10518 | reply_len = -1; | |
10519 | } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) { | |
10520 | if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s, | |
10521 | buf + 24)) | |
10522 | reply_len = -1; | |
4504621f OG |
10523 | } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) { |
10524 | reply_len = wpa_supplicant_ctrl_iface_tdls_link_status( | |
10525 | wpa_s, buf + 17, reply, reply_size); | |
281ff0aa | 10526 | #endif /* CONFIG_TDLS */ |
8506ea6f MB |
10527 | } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) { |
10528 | reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size); | |
eb2f2088 MB |
10529 | } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) { |
10530 | if (wmm_ac_ctrl_addts(wpa_s, buf + 13)) | |
10531 | reply_len = -1; | |
10532 | } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) { | |
10533 | if (wmm_ac_ctrl_delts(wpa_s, buf + 13)) | |
10534 | reply_len = -1; | |
60b24b0d DS |
10535 | } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) { |
10536 | reply_len = wpa_supplicant_signal_poll(wpa_s, reply, | |
10537 | reply_size); | |
96e8d831 DS |
10538 | } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) { |
10539 | if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14)) | |
10540 | reply_len = -1; | |
dc7785f8 YZ |
10541 | } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) { |
10542 | reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply, | |
10543 | reply_size); | |
bc5d330a TB |
10544 | #ifdef CONFIG_AUTOSCAN |
10545 | } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) { | |
10546 | if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9)) | |
10547 | reply_len = -1; | |
10548 | #endif /* CONFIG_AUTOSCAN */ | |
4d7aab78 EL |
10549 | } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) { |
10550 | reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply, | |
10551 | reply_size); | |
5e2c3490 JM |
10552 | #ifdef ANDROID |
10553 | } else if (os_strncmp(buf, "DRIVER ", 7) == 0) { | |
10554 | reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply, | |
10555 | reply_size); | |
10556 | #endif /* ANDROID */ | |
adef8948 BL |
10557 | } else if (os_strncmp(buf, "VENDOR ", 7) == 0) { |
10558 | reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply, | |
10559 | reply_size); | |
9482426e | 10560 | } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) { |
f5f37d3a | 10561 | pmksa_cache_clear_current(wpa_s->wpa); |
9482426e | 10562 | eapol_sm_request_reauth(wpa_s->eapol); |
e9199e31 JM |
10563 | #ifdef CONFIG_WNM |
10564 | } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) { | |
10565 | if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10)) | |
10566 | reply_len = -1; | |
07565ab0 MG |
10567 | } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) { |
10568 | if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14)) | |
65bcd0a9 | 10569 | reply_len = -1; |
d514b502 JM |
10570 | } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) { |
10571 | if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18)) | |
10572 | reply_len = -1; | |
e9199e31 | 10573 | #endif /* CONFIG_WNM */ |
acb54643 JM |
10574 | } else if (os_strcmp(buf, "FLUSH") == 0) { |
10575 | wpa_supplicant_ctrl_iface_flush(wpa_s); | |
1f965e62 JM |
10576 | } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) { |
10577 | reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply, | |
10578 | reply_size); | |
60b893df JM |
10579 | #ifdef CONFIG_TESTING_OPTIONS |
10580 | } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) { | |
10581 | if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0) | |
10582 | reply_len = -1; | |
10583 | } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) { | |
10584 | wpas_ctrl_iface_mgmt_tx_done(wpa_s); | |
4de70e23 JM |
10585 | } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) { |
10586 | if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0) | |
10587 | reply_len = -1; | |
ad12f2f4 JM |
10588 | } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) { |
10589 | if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0) | |
10590 | reply_len = -1; | |
9d4ff04a JM |
10591 | } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) { |
10592 | if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0) | |
10593 | reply_len = -1; | |
4a6cc862 JM |
10594 | } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) { |
10595 | if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0) | |
10596 | reply_len = -1; | |
10597 | } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) { | |
10598 | if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0) | |
10599 | reply_len = -1; | |
fc0ef7c0 JM |
10600 | } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) { |
10601 | if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0) | |
10602 | reply_len = -1; | |
a156ffda JM |
10603 | } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) { |
10604 | if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0) | |
10605 | reply_len = -1; | |
10606 | } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) { | |
10607 | reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size); | |
2da52565 JM |
10608 | } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) { |
10609 | if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0) | |
10610 | reply_len = -1; | |
10611 | } else if (os_strcmp(buf, "GET_FAIL") == 0) { | |
10612 | reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size); | |
a530fe77 JM |
10613 | } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) { |
10614 | if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0) | |
10615 | reply_len = -1; | |
651c6a84 JM |
10616 | } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) { |
10617 | if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0) | |
10618 | reply_len = -1; | |
16579769 JM |
10619 | } else if (os_strcmp(buf, "RESET_PN") == 0) { |
10620 | if (wpas_ctrl_reset_pn(wpa_s) < 0) | |
10621 | reply_len = -1; | |
751f5b29 JM |
10622 | } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) { |
10623 | if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0) | |
10624 | reply_len = -1; | |
daa40960 JM |
10625 | } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) { |
10626 | if (wpas_ctrl_resend_assoc(wpa_s) < 0) | |
10627 | reply_len = -1; | |
5c7d35ba MV |
10628 | } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) { |
10629 | sme_event_unprot_disconnect( | |
10630 | wpa_s, wpa_s->bssid, NULL, | |
10631 | WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA); | |
60b893df | 10632 | #endif /* CONFIG_TESTING_OPTIONS */ |
86bd36f0 JM |
10633 | } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) { |
10634 | if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0) | |
10635 | reply_len = -1; | |
10636 | } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) { | |
10637 | reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply, | |
10638 | reply_size); | |
10639 | } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) { | |
10640 | if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0) | |
10641 | reply_len = -1; | |
f4b8bfae | 10642 | } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) { |
6a4f0ed7 | 10643 | if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20)) |
f4b8bfae | 10644 | reply_len = -1; |
65d9a5e2 JM |
10645 | } else if (os_strcmp(buf, "ERP_FLUSH") == 0) { |
10646 | wpas_ctrl_iface_erp_flush(wpa_s); | |
fb375883 IP |
10647 | } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) { |
10648 | if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14)) | |
10649 | reply_len = -1; | |
98342208 AK |
10650 | } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) { |
10651 | reply_len = wpas_ctrl_iface_get_pref_freq_list( | |
10652 | wpa_s, buf + 19, reply, reply_size); | |
5732b770 JM |
10653 | #ifdef CONFIG_FILS |
10654 | } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) { | |
10655 | if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17)) | |
10656 | reply_len = -1; | |
10657 | } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) { | |
10658 | wpas_flush_fils_hlp_req(wpa_s); | |
10659 | #endif /* CONFIG_FILS */ | |
be27e185 JM |
10660 | #ifdef CONFIG_DPP |
10661 | } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) { | |
10662 | int res; | |
10663 | ||
10664 | res = wpas_dpp_qr_code(wpa_s, buf + 12); | |
10665 | if (res < 0) { | |
10666 | reply_len = -1; | |
10667 | } else { | |
10668 | reply_len = os_snprintf(reply, reply_size, "%d", res); | |
10669 | if (os_snprintf_error(reply_size, reply_len)) | |
10670 | reply_len = -1; | |
10671 | } | |
10672 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) { | |
10673 | int res; | |
10674 | ||
87d8435c | 10675 | res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18); |
be27e185 JM |
10676 | if (res < 0) { |
10677 | reply_len = -1; | |
10678 | } else { | |
10679 | reply_len = os_snprintf(reply, reply_size, "%d", res); | |
10680 | if (os_snprintf_error(reply_size, reply_len)) | |
10681 | reply_len = -1; | |
10682 | } | |
10683 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) { | |
87d8435c | 10684 | if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0) |
be27e185 JM |
10685 | reply_len = -1; |
10686 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) { | |
10687 | const char *uri; | |
10688 | ||
87d8435c | 10689 | uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22)); |
be27e185 JM |
10690 | if (!uri) { |
10691 | reply_len = -1; | |
10692 | } else { | |
10693 | reply_len = os_snprintf(reply, reply_size, "%s", uri); | |
10694 | if (os_snprintf_error(reply_size, reply_len)) | |
10695 | reply_len = -1; | |
10696 | } | |
6a7182a9 | 10697 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) { |
87d8435c JM |
10698 | reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19), |
10699 | reply, reply_size); | |
30d27b04 JM |
10700 | } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) { |
10701 | if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0) | |
10702 | reply_len = -1; | |
10703 | } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) { | |
10704 | if (wpas_dpp_listen(wpa_s, buf + 11) < 0) | |
10705 | reply_len = -1; | |
10706 | } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) { | |
c1d37739 | 10707 | wpas_dpp_stop(wpa_s); |
30d27b04 | 10708 | wpas_dpp_listen_stop(wpa_s); |
461d39af JM |
10709 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) { |
10710 | int res; | |
10711 | ||
87d8435c | 10712 | res = dpp_configurator_add(wpa_s->dpp, buf + 20); |
461d39af JM |
10713 | if (res < 0) { |
10714 | reply_len = -1; | |
10715 | } else { | |
10716 | reply_len = os_snprintf(reply, reply_size, "%d", res); | |
10717 | if (os_snprintf_error(reply_size, reply_len)) | |
10718 | reply_len = -1; | |
10719 | } | |
10720 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) { | |
87d8435c | 10721 | if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0) |
461d39af | 10722 | reply_len = -1; |
f522bb23 | 10723 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) { |
53d5de6f | 10724 | if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0) |
f522bb23 | 10725 | reply_len = -1; |
8179ae3a | 10726 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) { |
87d8435c JM |
10727 | reply_len = dpp_configurator_get_key_id(wpa_s->dpp, |
10728 | atoi(buf + 25), | |
10729 | reply, reply_size); | |
500ed7f0 JM |
10730 | } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) { |
10731 | int res; | |
10732 | ||
10733 | res = wpas_dpp_pkex_add(wpa_s, buf + 12); | |
10734 | if (res < 0) { | |
10735 | reply_len = -1; | |
10736 | } else { | |
10737 | reply_len = os_snprintf(reply, reply_size, "%d", res); | |
10738 | if (os_snprintf_error(reply_size, reply_len)) | |
10739 | reply_len = -1; | |
10740 | } | |
10741 | } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) { | |
10742 | if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0) | |
10743 | reply_len = -1; | |
c02dd10d JM |
10744 | #ifdef CONFIG_DPP2 |
10745 | } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) { | |
10746 | if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0) | |
10747 | reply_len = -1; | |
10748 | } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) { | |
10749 | if (wpas_dpp_controller_start(wpa_s, NULL) < 0) | |
10750 | reply_len = -1; | |
10751 | } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) { | |
10752 | dpp_controller_stop(wpa_s->dpp); | |
10753 | #endif /* CONFIG_DPP2 */ | |
be27e185 | 10754 | #endif /* CONFIG_DPP */ |
6fc6879b JM |
10755 | } else { |
10756 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | |
10757 | reply_len = 16; | |
10758 | } | |
10759 | ||
10760 | if (reply_len < 0) { | |
10761 | os_memcpy(reply, "FAIL\n", 5); | |
10762 | reply_len = 5; | |
10763 | } | |
10764 | ||
6fc6879b JM |
10765 | *resp_len = reply_len; |
10766 | return reply; | |
10767 | } | |
10768 | ||
10769 | ||
10770 | static int wpa_supplicant_global_iface_add(struct wpa_global *global, | |
10771 | char *cmd) | |
10772 | { | |
10773 | struct wpa_interface iface; | |
efa232f9 JJ |
10774 | char *pos, *extra; |
10775 | struct wpa_supplicant *wpa_s; | |
10776 | unsigned int create_iface = 0; | |
10777 | u8 mac_addr[ETH_ALEN]; | |
0f039e34 | 10778 | enum wpa_driver_if_type type = WPA_IF_STATION; |
6fc6879b JM |
10779 | |
10780 | /* | |
10781 | * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param> | |
0f039e34 | 10782 | * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]] |
6fc6879b JM |
10783 | */ |
10784 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd); | |
10785 | ||
10786 | os_memset(&iface, 0, sizeof(iface)); | |
10787 | ||
10788 | do { | |
10789 | iface.ifname = pos = cmd; | |
10790 | pos = os_strchr(pos, '\t'); | |
10791 | if (pos) | |
10792 | *pos++ = '\0'; | |
10793 | if (iface.ifname[0] == '\0') | |
10794 | return -1; | |
10795 | if (pos == NULL) | |
10796 | break; | |
10797 | ||
10798 | iface.confname = pos; | |
10799 | pos = os_strchr(pos, '\t'); | |
10800 | if (pos) | |
10801 | *pos++ = '\0'; | |
10802 | if (iface.confname[0] == '\0') | |
10803 | iface.confname = NULL; | |
10804 | if (pos == NULL) | |
10805 | break; | |
10806 | ||
10807 | iface.driver = pos; | |
10808 | pos = os_strchr(pos, '\t'); | |
10809 | if (pos) | |
10810 | *pos++ = '\0'; | |
10811 | if (iface.driver[0] == '\0') | |
10812 | iface.driver = NULL; | |
10813 | if (pos == NULL) | |
10814 | break; | |
10815 | ||
10816 | iface.ctrl_interface = pos; | |
10817 | pos = os_strchr(pos, '\t'); | |
10818 | if (pos) | |
10819 | *pos++ = '\0'; | |
10820 | if (iface.ctrl_interface[0] == '\0') | |
10821 | iface.ctrl_interface = NULL; | |
10822 | if (pos == NULL) | |
10823 | break; | |
10824 | ||
10825 | iface.driver_param = pos; | |
10826 | pos = os_strchr(pos, '\t'); | |
10827 | if (pos) | |
10828 | *pos++ = '\0'; | |
10829 | if (iface.driver_param[0] == '\0') | |
10830 | iface.driver_param = NULL; | |
10831 | if (pos == NULL) | |
10832 | break; | |
10833 | ||
10834 | iface.bridge_ifname = pos; | |
10835 | pos = os_strchr(pos, '\t'); | |
10836 | if (pos) | |
10837 | *pos++ = '\0'; | |
10838 | if (iface.bridge_ifname[0] == '\0') | |
10839 | iface.bridge_ifname = NULL; | |
10840 | if (pos == NULL) | |
10841 | break; | |
efa232f9 JJ |
10842 | |
10843 | extra = pos; | |
10844 | pos = os_strchr(pos, '\t'); | |
10845 | if (pos) | |
10846 | *pos++ = '\0'; | |
da3db681 BG |
10847 | if (!extra[0]) |
10848 | break; | |
10849 | ||
0f039e34 | 10850 | if (os_strcmp(extra, "create") == 0) { |
efa232f9 | 10851 | create_iface = 1; |
0f039e34 AS |
10852 | if (!pos) |
10853 | break; | |
10854 | ||
10855 | if (os_strcmp(pos, "sta") == 0) { | |
10856 | type = WPA_IF_STATION; | |
10857 | } else if (os_strcmp(pos, "ap") == 0) { | |
10858 | type = WPA_IF_AP_BSS; | |
10859 | } else { | |
10860 | wpa_printf(MSG_DEBUG, | |
10861 | "INTERFACE_ADD unsupported interface type: '%s'", | |
10862 | pos); | |
10863 | return -1; | |
10864 | } | |
10865 | } else { | |
da3db681 BG |
10866 | wpa_printf(MSG_DEBUG, |
10867 | "INTERFACE_ADD unsupported extra parameter: '%s'", | |
10868 | extra); | |
efa232f9 | 10869 | return -1; |
da3db681 | 10870 | } |
6fc6879b JM |
10871 | } while (0); |
10872 | ||
efa232f9 JJ |
10873 | if (create_iface) { |
10874 | wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'", | |
10875 | iface.ifname); | |
10876 | if (!global->ifaces) | |
10877 | return -1; | |
0f039e34 | 10878 | if (wpa_drv_if_add(global->ifaces, type, iface.ifname, |
efa232f9 JJ |
10879 | NULL, NULL, NULL, mac_addr, NULL) < 0) { |
10880 | wpa_printf(MSG_ERROR, | |
10881 | "CTRL_IFACE interface creation failed"); | |
10882 | return -1; | |
10883 | } | |
10884 | ||
10885 | wpa_printf(MSG_DEBUG, | |
10886 | "CTRL_IFACE interface '%s' created with MAC addr: " | |
10887 | MACSTR, iface.ifname, MAC2STR(mac_addr)); | |
10888 | } | |
10889 | ||
6fc6879b | 10890 | if (wpa_supplicant_get_iface(global, iface.ifname)) |
efa232f9 JJ |
10891 | goto fail; |
10892 | ||
10893 | wpa_s = wpa_supplicant_add_iface(global, &iface, NULL); | |
10894 | if (!wpa_s) | |
10895 | goto fail; | |
10896 | wpa_s->added_vif = create_iface; | |
10897 | return 0; | |
6fc6879b | 10898 | |
efa232f9 JJ |
10899 | fail: |
10900 | if (create_iface) | |
10901 | wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname); | |
10902 | return -1; | |
6fc6879b JM |
10903 | } |
10904 | ||
10905 | ||
10906 | static int wpa_supplicant_global_iface_remove(struct wpa_global *global, | |
10907 | char *cmd) | |
10908 | { | |
10909 | struct wpa_supplicant *wpa_s; | |
efa232f9 JJ |
10910 | int ret; |
10911 | unsigned int delete_iface; | |
6fc6879b JM |
10912 | |
10913 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd); | |
10914 | ||
10915 | wpa_s = wpa_supplicant_get_iface(global, cmd); | |
10916 | if (wpa_s == NULL) | |
10917 | return -1; | |
efa232f9 JJ |
10918 | delete_iface = wpa_s->added_vif; |
10919 | ret = wpa_supplicant_remove_iface(global, wpa_s, 0); | |
10920 | if (!ret && delete_iface) { | |
10921 | wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'", | |
10922 | cmd); | |
10923 | ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd); | |
10924 | } | |
10925 | return ret; | |
6fc6879b JM |
10926 | } |
10927 | ||
10928 | ||
4b4a8ae5 JM |
10929 | static void wpa_free_iface_info(struct wpa_interface_info *iface) |
10930 | { | |
10931 | struct wpa_interface_info *prev; | |
10932 | ||
10933 | while (iface) { | |
10934 | prev = iface; | |
10935 | iface = iface->next; | |
10936 | ||
10937 | os_free(prev->ifname); | |
10938 | os_free(prev->desc); | |
10939 | os_free(prev); | |
10940 | } | |
10941 | } | |
10942 | ||
10943 | ||
10944 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, | |
10945 | char *buf, int len) | |
10946 | { | |
10947 | int i, res; | |
10948 | struct wpa_interface_info *iface = NULL, *last = NULL, *tmp; | |
10949 | char *pos, *end; | |
10950 | ||
c5121837 | 10951 | for (i = 0; wpa_drivers[i]; i++) { |
8b423edb | 10952 | const struct wpa_driver_ops *drv = wpa_drivers[i]; |
4b4a8ae5 JM |
10953 | if (drv->get_interfaces == NULL) |
10954 | continue; | |
5fbc1f27 | 10955 | tmp = drv->get_interfaces(global->drv_priv[i]); |
4b4a8ae5 JM |
10956 | if (tmp == NULL) |
10957 | continue; | |
10958 | ||
10959 | if (last == NULL) | |
10960 | iface = last = tmp; | |
10961 | else | |
10962 | last->next = tmp; | |
10963 | while (last->next) | |
10964 | last = last->next; | |
10965 | } | |
10966 | ||
10967 | pos = buf; | |
10968 | end = buf + len; | |
10969 | for (tmp = iface; tmp; tmp = tmp->next) { | |
10970 | res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n", | |
10971 | tmp->drv_name, tmp->ifname, | |
10972 | tmp->desc ? tmp->desc : ""); | |
d85e1fc8 | 10973 | if (os_snprintf_error(end - pos, res)) { |
4b4a8ae5 JM |
10974 | *pos = '\0'; |
10975 | break; | |
10976 | } | |
10977 | pos += res; | |
10978 | } | |
10979 | ||
10980 | wpa_free_iface_info(iface); | |
10981 | ||
10982 | return pos - buf; | |
10983 | } | |
10984 | ||
10985 | ||
6fc6879b | 10986 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
56e2fc2c | 10987 | const char *input, |
6fc6879b JM |
10988 | char *buf, int len) |
10989 | { | |
10990 | int res; | |
10991 | char *pos, *end; | |
10992 | struct wpa_supplicant *wpa_s; | |
56e2fc2c JD |
10993 | int show_ctrl = 0; |
10994 | ||
10995 | if (input) | |
10996 | show_ctrl = !!os_strstr(input, "ctrl"); | |
6fc6879b JM |
10997 | |
10998 | wpa_s = global->ifaces; | |
10999 | pos = buf; | |
11000 | end = buf + len; | |
11001 | ||
11002 | while (wpa_s) { | |
56e2fc2c JD |
11003 | if (show_ctrl) |
11004 | res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n", | |
11005 | wpa_s->ifname, | |
11006 | wpa_s->conf->ctrl_interface ? | |
11007 | wpa_s->conf->ctrl_interface : "N/A"); | |
11008 | else | |
11009 | res = os_snprintf(pos, end - pos, "%s\n", | |
11010 | wpa_s->ifname); | |
11011 | ||
d85e1fc8 | 11012 | if (os_snprintf_error(end - pos, res)) { |
6fc6879b JM |
11013 | *pos = '\0'; |
11014 | break; | |
11015 | } | |
11016 | pos += res; | |
11017 | wpa_s = wpa_s->next; | |
11018 | } | |
11019 | return pos - buf; | |
11020 | } | |
11021 | ||
11022 | ||
cf3bebf2 JM |
11023 | static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global, |
11024 | const char *ifname, | |
11025 | char *cmd, size_t *resp_len) | |
11026 | { | |
11027 | struct wpa_supplicant *wpa_s; | |
11028 | ||
11029 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
11030 | if (os_strcmp(ifname, wpa_s->ifname) == 0) | |
11031 | break; | |
11032 | } | |
11033 | ||
11034 | if (wpa_s == NULL) { | |
11035 | char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n"); | |
11036 | if (resp) | |
11037 | *resp_len = os_strlen(resp); | |
11038 | else | |
11039 | *resp_len = 1; | |
11040 | return resp; | |
11041 | } | |
11042 | ||
11043 | return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len); | |
11044 | } | |
11045 | ||
11046 | ||
576bce9c JM |
11047 | static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global, |
11048 | char *buf, size_t *resp_len) | |
11049 | { | |
11050 | #ifdef CONFIG_P2P | |
11051 | static const char * cmd[] = { | |
443427e4 | 11052 | "LIST_NETWORKS", |
576bce9c JM |
11053 | "P2P_FIND", |
11054 | "P2P_STOP_FIND", | |
11055 | "P2P_LISTEN", | |
11056 | "P2P_GROUP_ADD", | |
11057 | "P2P_GET_PASSPHRASE", | |
11058 | "P2P_SERVICE_UPDATE", | |
11059 | "P2P_SERVICE_FLUSH", | |
11060 | "P2P_FLUSH", | |
11061 | "P2P_CANCEL", | |
11062 | "P2P_PRESENCE_REQ", | |
11063 | "P2P_EXT_LISTEN", | |
f2bc3448 DS |
11064 | #ifdef CONFIG_AP |
11065 | "STA-FIRST", | |
11066 | #endif /* CONFIG_AP */ | |
576bce9c JM |
11067 | NULL |
11068 | }; | |
11069 | static const char * prefix[] = { | |
443427e4 DS |
11070 | #ifdef ANDROID |
11071 | "DRIVER ", | |
11072 | #endif /* ANDROID */ | |
be1ece46 | 11073 | "GET_CAPABILITY ", |
443427e4 DS |
11074 | "GET_NETWORK ", |
11075 | "REMOVE_NETWORK ", | |
576bce9c JM |
11076 | "P2P_FIND ", |
11077 | "P2P_CONNECT ", | |
11078 | "P2P_LISTEN ", | |
11079 | "P2P_GROUP_REMOVE ", | |
11080 | "P2P_GROUP_ADD ", | |
57b38882 | 11081 | "P2P_GROUP_MEMBER ", |
576bce9c JM |
11082 | "P2P_PROV_DISC ", |
11083 | "P2P_SERV_DISC_REQ ", | |
11084 | "P2P_SERV_DISC_CANCEL_REQ ", | |
11085 | "P2P_SERV_DISC_RESP ", | |
11086 | "P2P_SERV_DISC_EXTERNAL ", | |
11087 | "P2P_SERVICE_ADD ", | |
11088 | "P2P_SERVICE_DEL ", | |
87d5ef5a | 11089 | "P2P_SERVICE_REP ", |
576bce9c JM |
11090 | "P2P_REJECT ", |
11091 | "P2P_INVITE ", | |
11092 | "P2P_PEER ", | |
11093 | "P2P_SET ", | |
11094 | "P2P_UNAUTHORIZE ", | |
11095 | "P2P_PRESENCE_REQ ", | |
11096 | "P2P_EXT_LISTEN ", | |
f2c56602 | 11097 | "P2P_REMOVE_CLIENT ", |
8ad8bc5c DS |
11098 | "WPS_NFC_TOKEN ", |
11099 | "WPS_NFC_TAG_READ ", | |
f3ff9487 AM |
11100 | "NFC_GET_HANDOVER_SEL ", |
11101 | "NFC_GET_HANDOVER_REQ ", | |
11102 | "NFC_REPORT_HANDOVER ", | |
87d5ef5a KV |
11103 | "P2P_ASP_PROVISION ", |
11104 | "P2P_ASP_PROVISION_RESP ", | |
f2bc3448 DS |
11105 | #ifdef CONFIG_AP |
11106 | "STA ", | |
11107 | "STA-NEXT ", | |
11108 | #endif /* CONFIG_AP */ | |
576bce9c JM |
11109 | NULL |
11110 | }; | |
11111 | int found = 0; | |
11112 | int i; | |
11113 | ||
11114 | if (global->p2p_init_wpa_s == NULL) | |
11115 | return NULL; | |
11116 | ||
11117 | for (i = 0; !found && cmd[i]; i++) { | |
11118 | if (os_strcmp(buf, cmd[i]) == 0) | |
11119 | found = 1; | |
11120 | } | |
11121 | ||
11122 | for (i = 0; !found && prefix[i]; i++) { | |
11123 | if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0) | |
11124 | found = 1; | |
11125 | } | |
11126 | ||
11127 | if (found) | |
11128 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, | |
11129 | buf, resp_len); | |
11130 | #endif /* CONFIG_P2P */ | |
11131 | return NULL; | |
11132 | } | |
11133 | ||
11134 | ||
11135 | static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global, | |
11136 | char *buf, size_t *resp_len) | |
11137 | { | |
11138 | #ifdef CONFIG_WIFI_DISPLAY | |
11139 | if (global->p2p_init_wpa_s == NULL) | |
11140 | return NULL; | |
11141 | if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 || | |
11142 | os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) | |
11143 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, | |
11144 | buf, resp_len); | |
11145 | #endif /* CONFIG_WIFI_DISPLAY */ | |
11146 | return NULL; | |
11147 | } | |
11148 | ||
11149 | ||
11150 | static char * wpas_global_ctrl_iface_redir(struct wpa_global *global, | |
11151 | char *buf, size_t *resp_len) | |
11152 | { | |
11153 | char *ret; | |
11154 | ||
11155 | ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len); | |
11156 | if (ret) | |
11157 | return ret; | |
11158 | ||
11159 | ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len); | |
11160 | if (ret) | |
11161 | return ret; | |
11162 | ||
11163 | return NULL; | |
11164 | } | |
11165 | ||
11166 | ||
1b9b31c1 JM |
11167 | static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd) |
11168 | { | |
11169 | char *value; | |
11170 | ||
11171 | value = os_strchr(cmd, ' '); | |
11172 | if (value == NULL) | |
11173 | return -1; | |
11174 | *value++ = '\0'; | |
11175 | ||
11176 | wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value); | |
11177 | ||
11178 | #ifdef CONFIG_WIFI_DISPLAY | |
11179 | if (os_strcasecmp(cmd, "wifi_display") == 0) { | |
11180 | wifi_display_enable(global, !!atoi(value)); | |
11181 | return 0; | |
11182 | } | |
11183 | #endif /* CONFIG_WIFI_DISPLAY */ | |
11184 | ||
a7ca6dac JM |
11185 | /* Restore cmd to its original value to allow redirection */ |
11186 | value[-1] = ' '; | |
11187 | ||
1b9b31c1 JM |
11188 | return -1; |
11189 | } | |
11190 | ||
11191 | ||
daae4995 AN |
11192 | static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global, |
11193 | char *cmd) | |
11194 | { | |
11195 | struct wpa_supplicant *wpa_s[2]; /* src, dst */ | |
11196 | char *p; | |
11197 | unsigned int i; | |
11198 | ||
11199 | /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id> | |
11200 | * <variable name> */ | |
11201 | ||
11202 | for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) { | |
11203 | p = os_strchr(cmd, ' '); | |
11204 | if (p == NULL) | |
11205 | return -1; | |
11206 | *p = '\0'; | |
11207 | ||
11208 | wpa_s[i] = global->ifaces; | |
11209 | for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) { | |
11210 | if (os_strcmp(cmd, wpa_s[i]->ifname) == 0) | |
11211 | break; | |
11212 | } | |
11213 | ||
11214 | if (!wpa_s[i]) { | |
11215 | wpa_printf(MSG_DEBUG, | |
11216 | "CTRL_IFACE: Could not find iface=%s", cmd); | |
11217 | return -1; | |
11218 | } | |
11219 | ||
11220 | cmd = p + 1; | |
11221 | } | |
11222 | ||
11223 | return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]); | |
11224 | } | |
11225 | ||
11226 | ||
42868f14 JM |
11227 | #ifndef CONFIG_NO_CONFIG_WRITE |
11228 | static int wpas_global_ctrl_iface_save_config(struct wpa_global *global) | |
11229 | { | |
d6b818ef | 11230 | int ret = 0, saved = 0; |
42868f14 JM |
11231 | struct wpa_supplicant *wpa_s; |
11232 | ||
11233 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
11234 | if (!wpa_s->conf->update_config) { | |
11235 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)"); | |
11236 | continue; | |
11237 | } | |
11238 | ||
11239 | if (wpa_config_write(wpa_s->confname, wpa_s->conf)) { | |
11240 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration"); | |
11241 | ret = 1; | |
11242 | } else { | |
11243 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated"); | |
d6b818ef | 11244 | saved++; |
42868f14 JM |
11245 | } |
11246 | } | |
11247 | ||
d6b818ef JM |
11248 | if (!saved && !ret) { |
11249 | wpa_dbg(wpa_s, MSG_DEBUG, | |
11250 | "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated"); | |
11251 | ret = 1; | |
11252 | } | |
11253 | ||
42868f14 JM |
11254 | return ret; |
11255 | } | |
11256 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
11257 | ||
11258 | ||
ae8c27f7 JM |
11259 | static int wpas_global_ctrl_iface_status(struct wpa_global *global, |
11260 | char *buf, size_t buflen) | |
11261 | { | |
11262 | char *pos, *end; | |
11263 | int ret; | |
11264 | struct wpa_supplicant *wpa_s; | |
11265 | ||
11266 | pos = buf; | |
11267 | end = buf + buflen; | |
11268 | ||
11269 | #ifdef CONFIG_P2P | |
4c559019 | 11270 | if (global->p2p && !global->p2p_disabled) { |
ae8c27f7 | 11271 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR |
4c559019 JM |
11272 | "\n" |
11273 | "p2p_state=%s\n", | |
11274 | MAC2STR(global->p2p_dev_addr), | |
11275 | p2p_get_state_txt(global->p2p)); | |
d85e1fc8 | 11276 | if (os_snprintf_error(end - pos, ret)) |
4c559019 JM |
11277 | return pos - buf; |
11278 | pos += ret; | |
11279 | } else if (global->p2p) { | |
11280 | ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n"); | |
d85e1fc8 | 11281 | if (os_snprintf_error(end - pos, ret)) |
ae8c27f7 JM |
11282 | return pos - buf; |
11283 | pos += ret; | |
11284 | } | |
11285 | #endif /* CONFIG_P2P */ | |
11286 | ||
11287 | #ifdef CONFIG_WIFI_DISPLAY | |
11288 | ret = os_snprintf(pos, end - pos, "wifi_display=%d\n", | |
11289 | !!global->wifi_display); | |
d85e1fc8 | 11290 | if (os_snprintf_error(end - pos, ret)) |
ae8c27f7 JM |
11291 | return pos - buf; |
11292 | pos += ret; | |
11293 | #endif /* CONFIG_WIFI_DISPLAY */ | |
11294 | ||
11295 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
11296 | ret = os_snprintf(pos, end - pos, "ifname=%s\n" | |
11297 | "address=" MACSTR "\n", | |
11298 | wpa_s->ifname, MAC2STR(wpa_s->own_addr)); | |
d85e1fc8 | 11299 | if (os_snprintf_error(end - pos, ret)) |
ae8c27f7 JM |
11300 | return pos - buf; |
11301 | pos += ret; | |
11302 | } | |
11303 | ||
11304 | return pos - buf; | |
11305 | } | |
11306 | ||
11307 | ||
3794af2d AN |
11308 | #ifdef CONFIG_FST |
11309 | ||
11310 | static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global, | |
11311 | char *cmd, char *buf, | |
11312 | size_t reply_size) | |
11313 | { | |
11314 | char ifname[IFNAMSIZ + 1]; | |
11315 | struct fst_iface_cfg cfg; | |
11316 | struct wpa_supplicant *wpa_s; | |
11317 | struct fst_wpa_obj iface_obj; | |
11318 | ||
11319 | if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) { | |
11320 | wpa_s = wpa_supplicant_get_iface(global, ifname); | |
11321 | if (wpa_s) { | |
5dbd3bf9 JM |
11322 | if (wpa_s->fst) { |
11323 | wpa_printf(MSG_INFO, "FST: Already attached"); | |
11324 | return -1; | |
11325 | } | |
3794af2d AN |
11326 | fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj); |
11327 | wpa_s->fst = fst_attach(ifname, wpa_s->own_addr, | |
11328 | &iface_obj, &cfg); | |
11329 | if (wpa_s->fst) | |
11330 | return os_snprintf(buf, reply_size, "OK\n"); | |
11331 | } | |
11332 | } | |
11333 | ||
11334 | return -1; | |
11335 | } | |
11336 | ||
11337 | ||
11338 | static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global, | |
11339 | char *cmd, char *buf, | |
11340 | size_t reply_size) | |
11341 | { | |
11342 | char ifname[IFNAMSIZ + 1]; | |
11343 | struct wpa_supplicant *wpa_s; | |
11344 | ||
11345 | if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) { | |
11346 | wpa_s = wpa_supplicant_get_iface(global, ifname); | |
11347 | if (wpa_s) { | |
11348 | if (!fst_iface_detach(ifname)) { | |
11349 | wpa_s->fst = NULL; | |
11350 | return os_snprintf(buf, reply_size, "OK\n"); | |
11351 | } | |
11352 | } | |
11353 | } | |
11354 | ||
11355 | return -1; | |
11356 | } | |
11357 | ||
11358 | #endif /* CONFIG_FST */ | |
11359 | ||
11360 | ||
6fc6879b JM |
11361 | char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, |
11362 | char *buf, size_t *resp_len) | |
11363 | { | |
11364 | char *reply; | |
11365 | const int reply_size = 2048; | |
11366 | int reply_len; | |
f4a0a82c | 11367 | int level = MSG_DEBUG; |
6fc6879b | 11368 | |
cf3bebf2 JM |
11369 | if (os_strncmp(buf, "IFNAME=", 7) == 0) { |
11370 | char *pos = os_strchr(buf + 7, ' '); | |
11371 | if (pos) { | |
11372 | *pos++ = '\0'; | |
11373 | return wpas_global_ctrl_iface_ifname(global, | |
11374 | buf + 7, pos, | |
11375 | resp_len); | |
11376 | } | |
11377 | } | |
11378 | ||
576bce9c JM |
11379 | reply = wpas_global_ctrl_iface_redir(global, buf, resp_len); |
11380 | if (reply) | |
11381 | return reply; | |
11382 | ||
f4a0a82c JM |
11383 | if (os_strcmp(buf, "PING") == 0) |
11384 | level = MSG_EXCESSIVE; | |
11385 | wpa_hexdump_ascii(level, "RX global ctrl_iface", | |
6fc6879b JM |
11386 | (const u8 *) buf, os_strlen(buf)); |
11387 | ||
11388 | reply = os_malloc(reply_size); | |
11389 | if (reply == NULL) { | |
11390 | *resp_len = 1; | |
11391 | return NULL; | |
11392 | } | |
11393 | ||
11394 | os_memcpy(reply, "OK\n", 3); | |
11395 | reply_len = 3; | |
11396 | ||
11397 | if (os_strcmp(buf, "PING") == 0) { | |
11398 | os_memcpy(reply, "PONG\n", 5); | |
11399 | reply_len = 5; | |
11400 | } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) { | |
11401 | if (wpa_supplicant_global_iface_add(global, buf + 14)) | |
11402 | reply_len = -1; | |
11403 | } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) { | |
11404 | if (wpa_supplicant_global_iface_remove(global, buf + 17)) | |
11405 | reply_len = -1; | |
4b4a8ae5 JM |
11406 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
11407 | reply_len = wpa_supplicant_global_iface_list( | |
11408 | global, reply, reply_size); | |
56e2fc2c | 11409 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { |
6fc6879b | 11410 | reply_len = wpa_supplicant_global_iface_interfaces( |
56e2fc2c | 11411 | global, buf + 10, reply, reply_size); |
3794af2d AN |
11412 | #ifdef CONFIG_FST |
11413 | } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) { | |
11414 | reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11, | |
11415 | reply, | |
11416 | reply_size); | |
11417 | } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) { | |
11418 | reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11, | |
11419 | reply, | |
11420 | reply_size); | |
11421 | } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) { | |
11422 | reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size); | |
11423 | #endif /* CONFIG_FST */ | |
6fc6879b | 11424 | } else if (os_strcmp(buf, "TERMINATE") == 0) { |
1a1bf008 | 11425 | wpa_supplicant_terminate_proc(global); |
207ef3fb JM |
11426 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
11427 | wpas_notify_suspend(global); | |
11428 | } else if (os_strcmp(buf, "RESUME") == 0) { | |
11429 | wpas_notify_resume(global); | |
1b9b31c1 | 11430 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
a7ca6dac JM |
11431 | if (wpas_global_ctrl_iface_set(global, buf + 4)) { |
11432 | #ifdef CONFIG_P2P | |
11433 | if (global->p2p_init_wpa_s) { | |
11434 | os_free(reply); | |
11435 | /* Check if P2P redirection would work for this | |
11436 | * command. */ | |
11437 | return wpa_supplicant_ctrl_iface_process( | |
11438 | global->p2p_init_wpa_s, | |
11439 | buf, resp_len); | |
11440 | } | |
11441 | #endif /* CONFIG_P2P */ | |
1b9b31c1 | 11442 | reply_len = -1; |
a7ca6dac | 11443 | } |
daae4995 AN |
11444 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
11445 | if (wpas_global_ctrl_iface_dup_network(global, buf + 12)) | |
11446 | reply_len = -1; | |
42868f14 JM |
11447 | #ifndef CONFIG_NO_CONFIG_WRITE |
11448 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | |
11449 | if (wpas_global_ctrl_iface_save_config(global)) | |
11450 | reply_len = -1; | |
11451 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
ae8c27f7 JM |
11452 | } else if (os_strcmp(buf, "STATUS") == 0) { |
11453 | reply_len = wpas_global_ctrl_iface_status(global, reply, | |
11454 | reply_size); | |
ea449b5b JM |
11455 | #ifdef CONFIG_MODULE_TESTS |
11456 | } else if (os_strcmp(buf, "MODULE_TESTS") == 0) { | |
ea449b5b JM |
11457 | if (wpas_module_tests() < 0) |
11458 | reply_len = -1; | |
11459 | #endif /* CONFIG_MODULE_TESTS */ | |
5f797376 JM |
11460 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
11461 | if (wpa_debug_reopen_file() < 0) | |
11462 | reply_len = -1; | |
6fc6879b JM |
11463 | } else { |
11464 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | |
11465 | reply_len = 16; | |
11466 | } | |
11467 | ||
11468 | if (reply_len < 0) { | |
11469 | os_memcpy(reply, "FAIL\n", 5); | |
11470 | reply_len = 5; | |
11471 | } | |
11472 | ||
11473 | *resp_len = reply_len; | |
11474 | return reply; | |
11475 | } |