]>
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 JM |
10 | #ifdef CONFIG_TESTING_OPTIONS |
11 | #include <net/ethernet.h> | |
12 | #include <netinet/ip.h> | |
13 | #endif /* CONFIG_TESTING_OPTIONS */ | |
6fc6879b | 14 | |
3a068632 JM |
15 | #include "utils/common.h" |
16 | #include "utils/eloop.h" | |
8aaafcee | 17 | #include "utils/uuid.h" |
50a17a76 | 18 | #include "utils/module_tests.h" |
acec8d32 | 19 | #include "common/version.h" |
3a068632 | 20 | #include "common/ieee802_11_defs.h" |
337c781f | 21 | #include "common/ieee802_11_common.h" |
3a068632 | 22 | #include "common/wpa_ctrl.h" |
4b07484c | 23 | #ifdef CONFIG_DPP |
60239f60 | 24 | #include "common/dpp.h" |
4b07484c | 25 | #endif /* CONFIG_DPP */ |
a1651451 | 26 | #include "crypto/tls.h" |
9d4ff04a | 27 | #include "ap/hostapd.h" |
3a068632 JM |
28 | #include "eap_peer/eap.h" |
29 | #include "eapol_supp/eapol_supp_sm.h" | |
3acb5005 | 30 | #include "rsn_supp/wpa.h" |
3a068632 JM |
31 | #include "rsn_supp/preauth.h" |
32 | #include "rsn_supp/pmksa_cache.h" | |
33 | #include "l2_packet/l2_packet.h" | |
34 | #include "wps/wps.h" | |
df4cea89 | 35 | #include "fst/fst.h" |
3794af2d | 36 | #include "fst/fst_ctrl_iface.h" |
6fc6879b | 37 | #include "config.h" |
6fc6879b | 38 | #include "wpa_supplicant_i.h" |
2d5b792d | 39 | #include "driver_i.h" |
fcc60db4 | 40 | #include "wps_supplicant.h" |
11ef8d35 | 41 | #include "ibss_rsn.h" |
3ec97afe | 42 | #include "ap.h" |
b563b388 JM |
43 | #include "p2p_supplicant.h" |
44 | #include "p2p/p2p.h" | |
a8918e86 | 45 | #include "hs20_supplicant.h" |
9675ce35 | 46 | #include "wifi_display.h" |
8bac466b | 47 | #include "notify.h" |
3a068632 | 48 | #include "bss.h" |
9ba9fa07 | 49 | #include "scan.h" |
3a068632 | 50 | #include "ctrl_iface.h" |
afc064fe | 51 | #include "interworking.h" |
9aa10e2b | 52 | #include "blacklist.h" |
bc5d330a | 53 | #include "autoscan.h" |
e9199e31 | 54 | #include "wnm_sta.h" |
60b893df | 55 | #include "offchannel.h" |
7a4a93b9 | 56 | #include "drivers/driver.h" |
79070906 | 57 | #include "mesh.h" |
be27e185 | 58 | #include "dpp_supplicant.h" |
5c7d35ba | 59 | #include "sme.h" |
6fc6879b | 60 | |
4b4a8ae5 JM |
61 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
62 | char *buf, int len); | |
6fc6879b | 63 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
56e2fc2c | 64 | const char *input, |
6fc6879b | 65 | char *buf, int len); |
d3c9c35f DS |
66 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, |
67 | char *val); | |
6fc6879b | 68 | |
fe3e0bac | 69 | |
d445a5cd JM |
70 | static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val) |
71 | { | |
72 | char *pos; | |
73 | u8 addr[ETH_ALEN], *filter = NULL, *n; | |
74 | size_t count = 0; | |
75 | ||
76 | pos = val; | |
77 | while (pos) { | |
78 | if (*pos == '\0') | |
79 | break; | |
1485ec07 JM |
80 | if (hwaddr_aton(pos, addr)) { |
81 | os_free(filter); | |
d445a5cd | 82 | return -1; |
1485ec07 | 83 | } |
067ffa26 | 84 | n = os_realloc_array(filter, count + 1, ETH_ALEN); |
d445a5cd JM |
85 | if (n == NULL) { |
86 | os_free(filter); | |
87 | return -1; | |
88 | } | |
89 | filter = n; | |
90 | os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN); | |
91 | count++; | |
92 | ||
93 | pos = os_strchr(pos, ' '); | |
94 | if (pos) | |
95 | pos++; | |
96 | } | |
97 | ||
98 | wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN); | |
99 | os_free(wpa_s->bssid_filter); | |
100 | wpa_s->bssid_filter = filter; | |
101 | wpa_s->bssid_filter_count = count; | |
102 | ||
103 | return 0; | |
104 | } | |
105 | ||
106 | ||
6407f413 JM |
107 | static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val) |
108 | { | |
109 | char *pos; | |
110 | u8 addr[ETH_ALEN], *bssid = NULL, *n; | |
111 | struct wpa_ssid_value *ssid = NULL, *ns; | |
112 | size_t count = 0, ssid_count = 0; | |
113 | struct wpa_ssid *c; | |
114 | ||
115 | /* | |
65015b2d | 116 | * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | "" |
6407f413 JM |
117 | * SSID_SPEC ::= ssid <SSID_HEX> |
118 | * BSSID_SPEC ::= bssid <BSSID_HEX> | |
119 | */ | |
120 | ||
121 | pos = val; | |
122 | while (pos) { | |
123 | if (*pos == '\0') | |
124 | break; | |
125 | if (os_strncmp(pos, "bssid ", 6) == 0) { | |
126 | int res; | |
127 | pos += 6; | |
128 | res = hwaddr_aton2(pos, addr); | |
129 | if (res < 0) { | |
130 | os_free(ssid); | |
131 | os_free(bssid); | |
132 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " | |
133 | "BSSID value '%s'", pos); | |
134 | return -1; | |
135 | } | |
136 | pos += res; | |
137 | n = os_realloc_array(bssid, count + 1, ETH_ALEN); | |
138 | if (n == NULL) { | |
139 | os_free(ssid); | |
140 | os_free(bssid); | |
141 | return -1; | |
142 | } | |
143 | bssid = n; | |
144 | os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN); | |
145 | count++; | |
146 | } else if (os_strncmp(pos, "ssid ", 5) == 0) { | |
147 | char *end; | |
148 | pos += 5; | |
149 | ||
150 | end = pos; | |
151 | while (*end) { | |
152 | if (*end == '\0' || *end == ' ') | |
153 | break; | |
154 | end++; | |
155 | } | |
156 | ||
157 | ns = os_realloc_array(ssid, ssid_count + 1, | |
158 | sizeof(struct wpa_ssid_value)); | |
159 | if (ns == NULL) { | |
160 | os_free(ssid); | |
161 | os_free(bssid); | |
162 | return -1; | |
163 | } | |
164 | ssid = ns; | |
165 | ||
d9d1b952 JM |
166 | if ((end - pos) & 0x01 || |
167 | end - pos > 2 * SSID_MAX_LEN || | |
6407f413 JM |
168 | hexstr2bin(pos, ssid[ssid_count].ssid, |
169 | (end - pos) / 2) < 0) { | |
170 | os_free(ssid); | |
171 | os_free(bssid); | |
172 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " | |
173 | "SSID value '%s'", pos); | |
174 | return -1; | |
175 | } | |
176 | ssid[ssid_count].ssid_len = (end - pos) / 2; | |
177 | wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID", | |
178 | ssid[ssid_count].ssid, | |
179 | ssid[ssid_count].ssid_len); | |
180 | ssid_count++; | |
181 | pos = end; | |
182 | } else { | |
183 | wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value " | |
184 | "'%s'", pos); | |
185 | os_free(ssid); | |
186 | os_free(bssid); | |
187 | return -1; | |
188 | } | |
189 | ||
190 | pos = os_strchr(pos, ' '); | |
191 | if (pos) | |
192 | pos++; | |
193 | } | |
194 | ||
195 | wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN); | |
196 | os_free(wpa_s->disallow_aps_bssid); | |
197 | wpa_s->disallow_aps_bssid = bssid; | |
198 | wpa_s->disallow_aps_bssid_count = count; | |
199 | ||
200 | wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count); | |
201 | os_free(wpa_s->disallow_aps_ssid); | |
202 | wpa_s->disallow_aps_ssid = ssid; | |
203 | wpa_s->disallow_aps_ssid_count = ssid_count; | |
204 | ||
205 | if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING) | |
206 | return 0; | |
207 | ||
208 | c = wpa_s->current_ssid; | |
209 | if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS) | |
210 | return 0; | |
211 | ||
212 | if (!disallowed_bssid(wpa_s, wpa_s->bssid) && | |
213 | !disallowed_ssid(wpa_s, c->ssid, c->ssid_len)) | |
214 | return 0; | |
215 | ||
216 | wpa_printf(MSG_DEBUG, "Disconnect and try to find another network " | |
217 | "because current AP was marked disallowed"); | |
218 | ||
219 | #ifdef CONFIG_SME | |
220 | wpa_s->sme.prev_bssid_set = 0; | |
221 | #endif /* CONFIG_SME */ | |
222 | wpa_s->reassociate = 1; | |
c2805909 | 223 | wpa_s->own_disconnect_req = 1; |
6407f413 JM |
224 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
225 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
226 | ||
227 | return 0; | |
228 | } | |
229 | ||
230 | ||
1120e452 JM |
231 | #ifndef CONFIG_NO_CONFIG_BLOBS |
232 | static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos) | |
233 | { | |
234 | char *name = pos; | |
235 | struct wpa_config_blob *blob; | |
236 | size_t len; | |
237 | ||
238 | pos = os_strchr(pos, ' '); | |
239 | if (pos == NULL) | |
240 | return -1; | |
241 | *pos++ = '\0'; | |
242 | len = os_strlen(pos); | |
243 | if (len & 1) | |
244 | return -1; | |
245 | ||
246 | wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name); | |
247 | blob = os_zalloc(sizeof(*blob)); | |
248 | if (blob == NULL) | |
249 | return -1; | |
250 | blob->name = os_strdup(name); | |
251 | blob->data = os_malloc(len / 2); | |
252 | if (blob->name == NULL || blob->data == NULL) { | |
253 | wpa_config_free_blob(blob); | |
254 | return -1; | |
255 | } | |
256 | ||
257 | if (hexstr2bin(pos, blob->data, len / 2) < 0) { | |
258 | wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data"); | |
259 | wpa_config_free_blob(blob); | |
260 | return -1; | |
261 | } | |
262 | blob->len = len / 2; | |
263 | ||
264 | wpa_config_set_blob(wpa_s->conf, blob); | |
265 | ||
266 | return 0; | |
267 | } | |
268 | #endif /* CONFIG_NO_CONFIG_BLOBS */ | |
269 | ||
d3c9c35f DS |
270 | |
271 | static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd) | |
272 | { | |
273 | char *params; | |
274 | char *pos; | |
275 | int *freqs = NULL; | |
276 | int ret; | |
277 | ||
278 | if (atoi(cmd)) { | |
279 | params = os_strchr(cmd, ' '); | |
280 | os_free(wpa_s->manual_sched_scan_freqs); | |
281 | if (params) { | |
282 | params++; | |
283 | pos = os_strstr(params, "freq="); | |
284 | if (pos) | |
285 | freqs = freq_range_to_channel_list(wpa_s, | |
286 | pos + 5); | |
287 | } | |
288 | wpa_s->manual_sched_scan_freqs = freqs; | |
289 | ret = wpas_start_pno(wpa_s); | |
290 | } else { | |
291 | ret = wpas_stop_pno(wpa_s); | |
292 | } | |
293 | return ret; | |
294 | } | |
295 | ||
296 | ||
844dfeb8 SD |
297 | static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band) |
298 | { | |
299 | union wpa_event_data event; | |
300 | ||
301 | if (os_strcmp(band, "AUTO") == 0) | |
302 | wpa_s->setband = WPA_SETBAND_AUTO; | |
303 | else if (os_strcmp(band, "5G") == 0) | |
304 | wpa_s->setband = WPA_SETBAND_5G; | |
305 | else if (os_strcmp(band, "2G") == 0) | |
306 | wpa_s->setband = WPA_SETBAND_2G; | |
307 | else | |
308 | return -1; | |
309 | ||
310 | if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) { | |
311 | os_memset(&event, 0, sizeof(event)); | |
312 | event.channel_list_changed.initiator = REGDOM_SET_BY_USER; | |
313 | event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN; | |
314 | wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event); | |
315 | } | |
316 | ||
317 | return 0; | |
318 | } | |
319 | ||
320 | ||
4a742011 DS |
321 | static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s, |
322 | const char *cmd) | |
323 | { | |
324 | struct wpabuf *lci; | |
325 | ||
326 | if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) { | |
327 | wpabuf_free(wpa_s->lci); | |
328 | wpa_s->lci = NULL; | |
329 | return 0; | |
330 | } | |
331 | ||
332 | lci = wpabuf_parse_bin(cmd); | |
333 | if (!lci) | |
334 | return -1; | |
335 | ||
336 | if (os_get_reltime(&wpa_s->lci_time)) { | |
337 | wpabuf_free(lci); | |
338 | return -1; | |
339 | } | |
340 | ||
341 | wpabuf_free(wpa_s->lci); | |
342 | wpa_s->lci = lci; | |
343 | ||
344 | return 0; | |
345 | } | |
346 | ||
347 | ||
57c3a605 | 348 | static int |
349 | wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd) | |
350 | { | |
351 | int relative_rssi; | |
352 | ||
353 | if (os_strcmp(cmd, "disable") == 0) { | |
354 | wpa_s->srp.relative_rssi_set = 0; | |
355 | return 0; | |
356 | } | |
357 | ||
358 | relative_rssi = atoi(cmd); | |
359 | if (relative_rssi < 0 || relative_rssi > 100) | |
360 | return -1; | |
361 | wpa_s->srp.relative_rssi = relative_rssi; | |
362 | wpa_s->srp.relative_rssi_set = 1; | |
363 | return 0; | |
364 | } | |
365 | ||
366 | ||
367 | static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s, | |
368 | const char *cmd) | |
369 | { | |
370 | char *pos; | |
371 | int adjust_rssi; | |
372 | ||
373 | /* <band>:adjust_value */ | |
374 | pos = os_strchr(cmd, ':'); | |
375 | if (!pos) | |
376 | return -1; | |
377 | pos++; | |
378 | adjust_rssi = atoi(pos); | |
379 | if (adjust_rssi < -100 || adjust_rssi > 100) | |
380 | return -1; | |
381 | ||
382 | if (os_strncmp(cmd, "2G", 2) == 0) | |
383 | wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G; | |
384 | else if (os_strncmp(cmd, "5G", 2) == 0) | |
385 | wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G; | |
386 | else | |
387 | return -1; | |
388 | ||
389 | wpa_s->srp.relative_adjust_rssi = adjust_rssi; | |
390 | ||
391 | return 0; | |
392 | } | |
393 | ||
394 | ||
c6c41f6e JM |
395 | static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s, |
396 | const char *cmd) | |
397 | { | |
398 | struct wpabuf *ric_ies; | |
399 | ||
400 | if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) { | |
401 | wpabuf_free(wpa_s->ric_ies); | |
402 | wpa_s->ric_ies = NULL; | |
403 | return 0; | |
404 | } | |
405 | ||
406 | ric_ies = wpabuf_parse_bin(cmd); | |
407 | if (!ric_ies) | |
408 | return -1; | |
409 | ||
410 | wpabuf_free(wpa_s->ric_ies); | |
411 | wpa_s->ric_ies = ric_ies; | |
412 | ||
413 | return 0; | |
414 | } | |
415 | ||
416 | ||
6fc6879b JM |
417 | static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, |
418 | char *cmd) | |
419 | { | |
420 | char *value; | |
421 | int ret = 0; | |
422 | ||
423 | value = os_strchr(cmd, ' '); | |
424 | if (value == NULL) | |
425 | return -1; | |
426 | *value++ = '\0'; | |
427 | ||
428 | wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value); | |
429 | if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) { | |
430 | eapol_sm_configure(wpa_s->eapol, | |
431 | atoi(value), -1, -1, -1); | |
432 | } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) { | |
433 | eapol_sm_configure(wpa_s->eapol, | |
434 | -1, atoi(value), -1, -1); | |
435 | } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) { | |
436 | eapol_sm_configure(wpa_s->eapol, | |
437 | -1, -1, atoi(value), -1); | |
438 | } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) { | |
439 | eapol_sm_configure(wpa_s->eapol, | |
440 | -1, -1, -1, atoi(value)); | |
441 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) { | |
442 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, | |
b4bdeadf | 443 | atoi(value))) { |
6fc6879b | 444 | ret = -1; |
b4bdeadf JM |
445 | } else { |
446 | value[-1] = '='; | |
447 | wpa_config_process_global(wpa_s->conf, cmd, -1); | |
448 | } | |
6fc6879b JM |
449 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == |
450 | 0) { | |
451 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, | |
b4bdeadf | 452 | atoi(value))) { |
6fc6879b | 453 | ret = -1; |
b4bdeadf JM |
454 | } else { |
455 | value[-1] = '='; | |
456 | wpa_config_process_global(wpa_s->conf, cmd, -1); | |
457 | } | |
6fc6879b | 458 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) { |
b4bdeadf JM |
459 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, |
460 | atoi(value))) { | |
6fc6879b | 461 | ret = -1; |
b4bdeadf JM |
462 | } else { |
463 | value[-1] = '='; | |
464 | wpa_config_process_global(wpa_s->conf, cmd, -1); | |
465 | } | |
42f50264 JM |
466 | } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) { |
467 | wpa_s->wps_fragment_size = atoi(value); | |
b4e34f2f JM |
468 | #ifdef CONFIG_WPS_TESTING |
469 | } else if (os_strcasecmp(cmd, "wps_version_number") == 0) { | |
470 | long int val; | |
471 | val = strtol(value, NULL, 0); | |
472 | if (val < 0 || val > 0xff) { | |
473 | ret = -1; | |
474 | wpa_printf(MSG_DEBUG, "WPS: Invalid " | |
475 | "wps_version_number %ld", val); | |
476 | } else { | |
477 | wps_version_number = val; | |
478 | wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS " | |
479 | "version %u.%u", | |
480 | (wps_version_number & 0xf0) >> 4, | |
481 | wps_version_number & 0x0f); | |
482 | } | |
483 | } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) { | |
484 | wps_testing_dummy_cred = atoi(value); | |
485 | wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d", | |
486 | wps_testing_dummy_cred); | |
91226e0d JM |
487 | } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) { |
488 | wps_corrupt_pkhash = atoi(value); | |
489 | wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d", | |
490 | wps_corrupt_pkhash); | |
6e379c6c JM |
491 | } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) { |
492 | if (value[0] == '\0') { | |
493 | wps_force_auth_types_in_use = 0; | |
494 | } else { | |
495 | wps_force_auth_types = strtol(value, NULL, 0); | |
496 | wps_force_auth_types_in_use = 1; | |
497 | } | |
498 | } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) { | |
499 | if (value[0] == '\0') { | |
500 | wps_force_encr_types_in_use = 0; | |
501 | } else { | |
502 | wps_force_encr_types = strtol(value, NULL, 0); | |
503 | wps_force_encr_types_in_use = 1; | |
504 | } | |
b4e34f2f | 505 | #endif /* CONFIG_WPS_TESTING */ |
b6c79a99 JM |
506 | } else if (os_strcasecmp(cmd, "ampdu") == 0) { |
507 | if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0) | |
508 | ret = -1; | |
9d2cb3ec | 509 | #ifdef CONFIG_TDLS |
5b0e6ece JM |
510 | #ifdef CONFIG_TDLS_TESTING |
511 | } else if (os_strcasecmp(cmd, "tdls_testing") == 0) { | |
5b0e6ece JM |
512 | tdls_testing = strtol(value, NULL, 0); |
513 | wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing); | |
514 | #endif /* CONFIG_TDLS_TESTING */ | |
b8f64582 JM |
515 | } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) { |
516 | int disabled = atoi(value); | |
517 | wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled); | |
518 | if (disabled) { | |
519 | if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0) | |
520 | ret = -1; | |
521 | } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0) | |
522 | ret = -1; | |
523 | wpa_tdls_enable(wpa_s->wpa, !disabled); | |
524 | #endif /* CONFIG_TDLS */ | |
b5c68312 | 525 | } else if (os_strcasecmp(cmd, "pno") == 0) { |
d3c9c35f | 526 | ret = wpas_ctrl_pno(wpa_s, value); |
8b9d0bfa JM |
527 | } else if (os_strcasecmp(cmd, "radio_disabled") == 0) { |
528 | int disabled = atoi(value); | |
529 | if (wpa_drv_radio_disable(wpa_s, disabled) < 0) | |
530 | ret = -1; | |
531 | else if (disabled) | |
532 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | |
aa074a64 JM |
533 | } else if (os_strcasecmp(cmd, "uapsd") == 0) { |
534 | if (os_strcmp(value, "disable") == 0) | |
535 | wpa_s->set_sta_uapsd = 0; | |
536 | else { | |
537 | int be, bk, vi, vo; | |
538 | char *pos; | |
539 | /* format: BE,BK,VI,VO;max SP Length */ | |
540 | be = atoi(value); | |
541 | pos = os_strchr(value, ','); | |
542 | if (pos == NULL) | |
543 | return -1; | |
544 | pos++; | |
545 | bk = atoi(pos); | |
546 | pos = os_strchr(pos, ','); | |
547 | if (pos == NULL) | |
548 | return -1; | |
549 | pos++; | |
550 | vi = atoi(pos); | |
551 | pos = os_strchr(pos, ','); | |
552 | if (pos == NULL) | |
553 | return -1; | |
554 | pos++; | |
555 | vo = atoi(pos); | |
556 | /* ignore max SP Length for now */ | |
557 | ||
558 | wpa_s->set_sta_uapsd = 1; | |
559 | wpa_s->sta_uapsd = 0; | |
560 | if (be) | |
561 | wpa_s->sta_uapsd |= BIT(0); | |
562 | if (bk) | |
563 | wpa_s->sta_uapsd |= BIT(1); | |
564 | if (vi) | |
565 | wpa_s->sta_uapsd |= BIT(2); | |
566 | if (vo) | |
567 | wpa_s->sta_uapsd |= BIT(3); | |
568 | } | |
b2ff1681 JM |
569 | } else if (os_strcasecmp(cmd, "ps") == 0) { |
570 | ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1); | |
9675ce35 JM |
571 | #ifdef CONFIG_WIFI_DISPLAY |
572 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { | |
bab6677a JM |
573 | int enabled = !!atoi(value); |
574 | if (enabled && !wpa_s->global->p2p) | |
575 | ret = -1; | |
576 | else | |
577 | wifi_display_enable(wpa_s->global, enabled); | |
9675ce35 | 578 | #endif /* CONFIG_WIFI_DISPLAY */ |
d445a5cd JM |
579 | } else if (os_strcasecmp(cmd, "bssid_filter") == 0) { |
580 | ret = set_bssid_filter(wpa_s, value); | |
6407f413 JM |
581 | } else if (os_strcasecmp(cmd, "disallow_aps") == 0) { |
582 | ret = set_disallow_aps(wpa_s, value); | |
2ec535fd JM |
583 | } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) { |
584 | wpa_s->no_keep_alive = !!atoi(value); | |
b65b22d6 JM |
585 | #ifdef CONFIG_DPP |
586 | } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) { | |
587 | os_free(wpa_s->dpp_configurator_params); | |
588 | wpa_s->dpp_configurator_params = os_strdup(value); | |
f97ace34 JM |
589 | } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) { |
590 | wpa_s->dpp_init_max_tries = atoi(value); | |
591 | } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) { | |
592 | wpa_s->dpp_init_retry_time = atoi(value); | |
593 | } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) { | |
594 | wpa_s->dpp_resp_wait_time = atoi(value); | |
95b0104a JM |
595 | } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) { |
596 | wpa_s->dpp_resp_max_tries = atoi(value); | |
597 | } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) { | |
598 | wpa_s->dpp_resp_retry_time = atoi(value); | |
dc2f24f1 | 599 | #ifdef CONFIG_TESTING_OPTIONS |
2bdc47a9 JM |
600 | } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) { |
601 | if (hwaddr_aton(value, dpp_pkex_own_mac_override)) | |
602 | ret = -1; | |
603 | } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) { | |
604 | if (hwaddr_aton(value, dpp_pkex_peer_mac_override)) | |
605 | ret = -1; | |
acc555f9 JM |
606 | } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) { |
607 | size_t hex_len = os_strlen(value); | |
608 | ||
609 | if (hex_len > | |
610 | 2 * sizeof(dpp_pkex_ephemeral_key_override)) | |
611 | ret = -1; | |
612 | else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override, | |
613 | hex_len / 2)) | |
614 | ret = -1; | |
615 | else | |
616 | dpp_pkex_ephemeral_key_override_len = hex_len / 2; | |
f5526975 JM |
617 | } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) { |
618 | size_t hex_len = os_strlen(value); | |
619 | ||
620 | if (hex_len > 2 * sizeof(dpp_protocol_key_override)) | |
621 | ret = -1; | |
622 | else if (hexstr2bin(value, dpp_protocol_key_override, | |
623 | hex_len / 2)) | |
624 | ret = -1; | |
625 | else | |
626 | dpp_protocol_key_override_len = hex_len / 2; | |
055cd397 JM |
627 | } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) { |
628 | size_t hex_len = os_strlen(value); | |
629 | ||
630 | if (hex_len > 2 * sizeof(dpp_nonce_override)) | |
631 | ret = -1; | |
632 | else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2)) | |
633 | ret = -1; | |
634 | else | |
635 | dpp_nonce_override_len = hex_len / 2; | |
dc2f24f1 | 636 | #endif /* CONFIG_TESTING_OPTIONS */ |
b65b22d6 | 637 | #endif /* CONFIG_DPP */ |
60b893df JM |
638 | #ifdef CONFIG_TESTING_OPTIONS |
639 | } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) { | |
640 | wpa_s->ext_mgmt_frame_handling = !!atoi(value); | |
9d4ff04a JM |
641 | } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) { |
642 | wpa_s->ext_eapol_frame_io = !!atoi(value); | |
643 | #ifdef CONFIG_AP | |
644 | if (wpa_s->ap_iface) { | |
645 | wpa_s->ap_iface->bss[0]->ext_eapol_frame_io = | |
646 | wpa_s->ext_eapol_frame_io; | |
647 | } | |
648 | #endif /* CONFIG_AP */ | |
1f94e4ee JM |
649 | } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) { |
650 | wpa_s->extra_roc_dur = atoi(value); | |
911942ee JM |
651 | } else if (os_strcasecmp(cmd, "test_failure") == 0) { |
652 | wpa_s->test_failure = atoi(value); | |
ed7820b4 IP |
653 | } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) { |
654 | wpa_s->p2p_go_csa_on_inv = !!atoi(value); | |
02adead5 MK |
655 | } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) { |
656 | wpa_s->ignore_auth_resp = !!atoi(value); | |
6ad37d73 | 657 | } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) { |
658 | wpa_s->ignore_assoc_disallow = !!atoi(value); | |
178553b7 VK |
659 | wpa_drv_ignore_assoc_disallow(wpa_s, |
660 | wpa_s->ignore_assoc_disallow); | |
a483c6f1 | 661 | } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) { |
662 | wpa_s->reject_btm_req_reason = atoi(value); | |
c06fca04 JM |
663 | } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) { |
664 | os_free(wpa_s->get_pref_freq_list_override); | |
665 | if (!value[0]) | |
666 | wpa_s->get_pref_freq_list_override = NULL; | |
667 | else | |
668 | wpa_s->get_pref_freq_list_override = os_strdup(value); | |
a0f19e9c JM |
669 | } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) { |
670 | wpabuf_free(wpa_s->sae_commit_override); | |
671 | if (value[0] == '\0') | |
672 | wpa_s->sae_commit_override = NULL; | |
673 | else | |
674 | wpa_s->sae_commit_override = wpabuf_parse_bin(value); | |
461d39af JM |
675 | #ifdef CONFIG_DPP |
676 | } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) { | |
677 | os_free(wpa_s->dpp_config_obj_override); | |
b7dddab7 JM |
678 | if (value[0] == '\0') |
679 | wpa_s->dpp_config_obj_override = NULL; | |
680 | else | |
681 | wpa_s->dpp_config_obj_override = os_strdup(value); | |
461d39af JM |
682 | } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) { |
683 | os_free(wpa_s->dpp_discovery_override); | |
b7dddab7 JM |
684 | if (value[0] == '\0') |
685 | wpa_s->dpp_discovery_override = NULL; | |
686 | else | |
687 | wpa_s->dpp_discovery_override = os_strdup(value); | |
461d39af JM |
688 | } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) { |
689 | os_free(wpa_s->dpp_groups_override); | |
b7dddab7 JM |
690 | if (value[0] == '\0') |
691 | wpa_s->dpp_groups_override = NULL; | |
692 | else | |
693 | wpa_s->dpp_groups_override = os_strdup(value); | |
461d39af JM |
694 | } else if (os_strcasecmp(cmd, |
695 | "dpp_ignore_netaccesskey_mismatch") == 0) { | |
696 | wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value); | |
60239f60 JM |
697 | } else if (os_strcasecmp(cmd, "dpp_test") == 0) { |
698 | dpp_test = atoi(value); | |
461d39af | 699 | #endif /* CONFIG_DPP */ |
60b893df | 700 | #endif /* CONFIG_TESTING_OPTIONS */ |
d98038bb | 701 | #ifdef CONFIG_FILS |
702 | } else if (os_strcasecmp(cmd, "disable_fils") == 0) { | |
703 | wpa_s->disable_fils = !!atoi(value); | |
704 | wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils); | |
705 | wpa_supplicant_set_default_scan_ies(wpa_s); | |
706 | #endif /* CONFIG_FILS */ | |
1120e452 JM |
707 | #ifndef CONFIG_NO_CONFIG_BLOBS |
708 | } else if (os_strcmp(cmd, "blob") == 0) { | |
709 | ret = wpas_ctrl_set_blob(wpa_s, value); | |
710 | #endif /* CONFIG_NO_CONFIG_BLOBS */ | |
209702d4 | 711 | } else if (os_strcasecmp(cmd, "setband") == 0) { |
844dfeb8 | 712 | ret = wpas_ctrl_set_band(wpa_s, value); |
92c6e2e3 DS |
713 | #ifdef CONFIG_MBO |
714 | } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) { | |
715 | ret = wpas_mbo_update_non_pref_chan(wpa_s, value); | |
e3394c0e JM |
716 | if (ret == 0) { |
717 | value[-1] = '='; | |
718 | wpa_config_process_global(wpa_s->conf, cmd, -1); | |
719 | } | |
016082e9 AS |
720 | } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) { |
721 | wpas_mbo_update_cell_capa(wpa_s, atoi(value)); | |
332aadb8 AP |
722 | } else if (os_strcasecmp(cmd, "oce") == 0) { |
723 | wpa_s->conf->oce = atoi(value); | |
724 | if (wpa_s->conf->oce) { | |
725 | if ((wpa_s->conf->oce & OCE_STA) && | |
726 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA)) | |
727 | wpa_s->enable_oce = OCE_STA; | |
728 | ||
729 | if ((wpa_s->conf->oce & OCE_STA_CFON) && | |
730 | (wpa_s->drv_flags & | |
731 | WPA_DRIVER_FLAGS_OCE_STA_CFON)) { | |
732 | /* TODO: Need to add STA-CFON support */ | |
733 | wpa_printf(MSG_ERROR, | |
734 | "OCE STA-CFON feature is not yet supported"); | |
735 | return -1; | |
736 | } | |
737 | } else { | |
738 | wpa_s->enable_oce = 0; | |
739 | } | |
e37cea30 | 740 | wpa_supplicant_set_default_scan_ies(wpa_s); |
92c6e2e3 | 741 | #endif /* CONFIG_MBO */ |
4a742011 DS |
742 | } else if (os_strcasecmp(cmd, "lci") == 0) { |
743 | ret = wpas_ctrl_iface_set_lci(wpa_s, value); | |
2e4e4fb7 SD |
744 | } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) { |
745 | ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value)); | |
57c3a605 | 746 | } else if (os_strcasecmp(cmd, "relative_rssi") == 0) { |
747 | ret = wpas_ctrl_set_relative_rssi(wpa_s, value); | |
748 | } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) { | |
749 | ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value); | |
c6c41f6e JM |
750 | } else if (os_strcasecmp(cmd, "ric_ies") == 0) { |
751 | ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value); | |
9a72bfe9 AP |
752 | } else if (os_strcasecmp(cmd, "roaming") == 0) { |
753 | ret = wpa_drv_roaming(wpa_s, atoi(value), NULL); | |
d514b502 JM |
754 | #ifdef CONFIG_WNM |
755 | } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) { | |
756 | struct wpabuf *elems; | |
757 | ||
758 | elems = wpabuf_parse_bin(value); | |
759 | if (!elems) | |
760 | return -1; | |
761 | wnm_set_coloc_intf_elems(wpa_s, elems); | |
762 | #endif /* CONFIG_WNM */ | |
611aea7d JM |
763 | } else { |
764 | value[-1] = '='; | |
765 | ret = wpa_config_process_global(wpa_s->conf, cmd, -1); | |
766 | if (ret == 0) | |
767 | wpa_supplicant_update_config(wpa_s); | |
768 | } | |
6fc6879b JM |
769 | |
770 | return ret; | |
771 | } | |
772 | ||
773 | ||
acec8d32 JM |
774 | static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s, |
775 | char *cmd, char *buf, size_t buflen) | |
776 | { | |
6ce937b8 | 777 | int res = -1; |
acec8d32 JM |
778 | |
779 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd); | |
780 | ||
781 | if (os_strcmp(cmd, "version") == 0) { | |
782 | res = os_snprintf(buf, buflen, "%s", VERSION_STR); | |
6ce937b8 DS |
783 | } else if (os_strcasecmp(cmd, "country") == 0) { |
784 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) | |
785 | res = os_snprintf(buf, buflen, "%c%c", | |
786 | wpa_s->conf->country[0], | |
787 | wpa_s->conf->country[1]); | |
9675ce35 JM |
788 | #ifdef CONFIG_WIFI_DISPLAY |
789 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { | |
bab6677a JM |
790 | int enabled; |
791 | if (wpa_s->global->p2p == NULL || | |
792 | wpa_s->global->p2p_disabled) | |
793 | enabled = 0; | |
794 | else | |
795 | enabled = wpa_s->global->wifi_display; | |
796 | res = os_snprintf(buf, buflen, "%d", enabled); | |
9675ce35 | 797 | #endif /* CONFIG_WIFI_DISPLAY */ |
fa7ae950 JM |
798 | #ifdef CONFIG_TESTING_GET_GTK |
799 | } else if (os_strcmp(cmd, "gtk") == 0) { | |
800 | if (wpa_s->last_gtk_len == 0) | |
801 | return -1; | |
802 | res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk, | |
803 | wpa_s->last_gtk_len); | |
804 | return res; | |
805 | #endif /* CONFIG_TESTING_GET_GTK */ | |
a1651451 JM |
806 | } else if (os_strcmp(cmd, "tls_library") == 0) { |
807 | res = tls_get_library_version(buf, buflen); | |
bb06748f JM |
808 | #ifdef CONFIG_TESTING_OPTIONS |
809 | } else if (os_strcmp(cmd, "anonce") == 0) { | |
810 | return wpa_snprintf_hex(buf, buflen, | |
811 | wpa_sm_get_anonce(wpa_s->wpa), | |
812 | WPA_NONCE_LEN); | |
813 | #endif /* CONFIG_TESTING_OPTIONS */ | |
10263dc2 OO |
814 | } else { |
815 | res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen); | |
acec8d32 JM |
816 | } |
817 | ||
1f102d3b | 818 | if (os_snprintf_error(buflen, res)) |
6ce937b8 DS |
819 | return -1; |
820 | return res; | |
acec8d32 JM |
821 | } |
822 | ||
823 | ||
ec717917 | 824 | #ifdef IEEE8021X_EAPOL |
6fc6879b JM |
825 | static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s, |
826 | char *addr) | |
827 | { | |
828 | u8 bssid[ETH_ALEN]; | |
829 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
830 | ||
831 | if (hwaddr_aton(addr, bssid)) { | |
832 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address " | |
833 | "'%s'", addr); | |
834 | return -1; | |
835 | } | |
836 | ||
837 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid)); | |
838 | rsn_preauth_deinit(wpa_s->wpa); | |
839 | if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL)) | |
840 | return -1; | |
841 | ||
842 | return 0; | |
843 | } | |
ec717917 | 844 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
845 | |
846 | ||
281ff0aa GP |
847 | #ifdef CONFIG_TDLS |
848 | ||
849 | static int wpa_supplicant_ctrl_iface_tdls_discover( | |
850 | struct wpa_supplicant *wpa_s, char *addr) | |
851 | { | |
852 | u8 peer[ETH_ALEN]; | |
2d565a61 | 853 | int ret; |
281ff0aa GP |
854 | |
855 | if (hwaddr_aton(addr, peer)) { | |
856 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid " | |
857 | "address '%s'", addr); | |
858 | return -1; | |
859 | } | |
860 | ||
861 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR, | |
862 | MAC2STR(peer)); | |
863 | ||
2d565a61 AN |
864 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
865 | ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer); | |
866 | else | |
867 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); | |
868 | ||
869 | return ret; | |
281ff0aa GP |
870 | } |
871 | ||
872 | ||
873 | static int wpa_supplicant_ctrl_iface_tdls_setup( | |
874 | struct wpa_supplicant *wpa_s, char *addr) | |
875 | { | |
876 | u8 peer[ETH_ALEN]; | |
94377fbc | 877 | int ret; |
281ff0aa GP |
878 | |
879 | if (hwaddr_aton(addr, peer)) { | |
880 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid " | |
881 | "address '%s'", addr); | |
882 | return -1; | |
883 | } | |
884 | ||
885 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR, | |
886 | MAC2STR(peer)); | |
887 | ||
800d5872 SD |
888 | if ((wpa_s->conf->tdls_external_control) && |
889 | wpa_tdls_is_external_setup(wpa_s->wpa)) | |
890 | return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | |
891 | ||
3887878e SD |
892 | wpa_tdls_remove(wpa_s->wpa, peer); |
893 | ||
894 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | |
895 | ret = wpa_tdls_start(wpa_s->wpa, peer); | |
896 | else | |
897 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | |
2d565a61 | 898 | |
94377fbc | 899 | return ret; |
281ff0aa GP |
900 | } |
901 | ||
902 | ||
903 | static int wpa_supplicant_ctrl_iface_tdls_teardown( | |
904 | struct wpa_supplicant *wpa_s, char *addr) | |
905 | { | |
906 | u8 peer[ETH_ALEN]; | |
4ed8d954 | 907 | int ret; |
281ff0aa | 908 | |
38ddccae AN |
909 | if (os_strcmp(addr, "*") == 0) { |
910 | /* remove everyone */ | |
911 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *"); | |
912 | wpa_tdls_teardown_peers(wpa_s->wpa); | |
913 | return 0; | |
914 | } | |
915 | ||
281ff0aa GP |
916 | if (hwaddr_aton(addr, peer)) { |
917 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid " | |
918 | "address '%s'", addr); | |
919 | return -1; | |
920 | } | |
921 | ||
922 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR, | |
923 | MAC2STR(peer)); | |
924 | ||
800d5872 SD |
925 | if ((wpa_s->conf->tdls_external_control) && |
926 | wpa_tdls_is_external_setup(wpa_s->wpa)) | |
927 | return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); | |
928 | ||
4ed8d954 AS |
929 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
930 | ret = wpa_tdls_teardown_link( | |
931 | wpa_s->wpa, peer, | |
932 | WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED); | |
933 | else | |
934 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); | |
935 | ||
936 | return ret; | |
281ff0aa GP |
937 | } |
938 | ||
6e9375e4 DS |
939 | |
940 | static int ctrl_iface_get_capability_tdls( | |
941 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
942 | { | |
943 | int ret; | |
944 | ||
945 | ret = os_snprintf(buf, buflen, "%s\n", | |
946 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ? | |
947 | (wpa_s->drv_flags & | |
948 | WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ? | |
949 | "EXTERNAL" : "INTERNAL") : "UNSUPPORTED"); | |
7bdd8981 | 950 | if (os_snprintf_error(buflen, ret)) |
6e9375e4 DS |
951 | return -1; |
952 | return ret; | |
953 | } | |
954 | ||
6b90deae AN |
955 | |
956 | static int wpa_supplicant_ctrl_iface_tdls_chan_switch( | |
957 | struct wpa_supplicant *wpa_s, char *cmd) | |
958 | { | |
959 | u8 peer[ETH_ALEN]; | |
960 | struct hostapd_freq_params freq_params; | |
961 | u8 oper_class; | |
962 | char *pos, *end; | |
963 | ||
964 | if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { | |
965 | wpa_printf(MSG_INFO, | |
966 | "tdls_chanswitch: Only supported with external setup"); | |
967 | return -1; | |
968 | } | |
969 | ||
970 | os_memset(&freq_params, 0, sizeof(freq_params)); | |
971 | ||
972 | pos = os_strchr(cmd, ' '); | |
973 | if (pos == NULL) | |
974 | return -1; | |
975 | *pos++ = '\0'; | |
976 | ||
977 | oper_class = strtol(pos, &end, 10); | |
978 | if (pos == end) { | |
979 | wpa_printf(MSG_INFO, | |
980 | "tdls_chanswitch: Invalid op class provided"); | |
981 | return -1; | |
982 | } | |
983 | ||
984 | pos = end; | |
985 | freq_params.freq = atoi(pos); | |
986 | if (freq_params.freq == 0) { | |
987 | wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided"); | |
988 | return -1; | |
989 | } | |
990 | ||
991 | #define SET_FREQ_SETTING(str) \ | |
992 | do { \ | |
993 | const char *pos2 = os_strstr(pos, " " #str "="); \ | |
994 | if (pos2) { \ | |
995 | pos2 += sizeof(" " #str "=") - 1; \ | |
996 | freq_params.str = atoi(pos2); \ | |
997 | } \ | |
998 | } while (0) | |
999 | ||
1000 | SET_FREQ_SETTING(center_freq1); | |
1001 | SET_FREQ_SETTING(center_freq2); | |
1002 | SET_FREQ_SETTING(bandwidth); | |
1003 | SET_FREQ_SETTING(sec_channel_offset); | |
1004 | #undef SET_FREQ_SETTING | |
1005 | ||
1006 | freq_params.ht_enabled = !!os_strstr(pos, " ht"); | |
1007 | freq_params.vht_enabled = !!os_strstr(pos, " vht"); | |
1008 | ||
1009 | if (hwaddr_aton(cmd, peer)) { | |
1010 | wpa_printf(MSG_DEBUG, | |
1011 | "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'", | |
1012 | cmd); | |
1013 | return -1; | |
1014 | } | |
1015 | ||
1016 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR | |
1017 | " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s", | |
1018 | MAC2STR(peer), oper_class, freq_params.freq, | |
1019 | freq_params.center_freq1, freq_params.center_freq2, | |
1020 | freq_params.bandwidth, freq_params.sec_channel_offset, | |
1021 | freq_params.ht_enabled ? " HT" : "", | |
1022 | freq_params.vht_enabled ? " VHT" : ""); | |
1023 | ||
1024 | return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class, | |
1025 | &freq_params); | |
1026 | } | |
1027 | ||
1028 | ||
1029 | static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch( | |
1030 | struct wpa_supplicant *wpa_s, char *cmd) | |
1031 | { | |
1032 | u8 peer[ETH_ALEN]; | |
1033 | ||
1034 | if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { | |
1035 | wpa_printf(MSG_INFO, | |
1036 | "tdls_chanswitch: Only supported with external setup"); | |
1037 | return -1; | |
1038 | } | |
1039 | ||
1040 | if (hwaddr_aton(cmd, peer)) { | |
1041 | wpa_printf(MSG_DEBUG, | |
1042 | "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'", | |
1043 | cmd); | |
1044 | return -1; | |
1045 | } | |
1046 | ||
1047 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR, | |
1048 | MAC2STR(peer)); | |
1049 | ||
1050 | return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer); | |
1051 | } | |
1052 | ||
4504621f OG |
1053 | |
1054 | static int wpa_supplicant_ctrl_iface_tdls_link_status( | |
1055 | struct wpa_supplicant *wpa_s, const char *addr, | |
1056 | char *buf, size_t buflen) | |
1057 | { | |
1058 | u8 peer[ETH_ALEN]; | |
1059 | const char *tdls_status; | |
1060 | int ret; | |
1061 | ||
1062 | if (hwaddr_aton(addr, peer)) { | |
1063 | wpa_printf(MSG_DEBUG, | |
1064 | "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'", | |
1065 | addr); | |
1066 | return -1; | |
1067 | } | |
1068 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR, | |
1069 | MAC2STR(peer)); | |
1070 | ||
1071 | tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer); | |
1072 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status); | |
1073 | ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status); | |
1074 | if (os_snprintf_error(buflen, ret)) | |
1075 | return -1; | |
1076 | ||
1077 | return ret; | |
1078 | } | |
1079 | ||
281ff0aa GP |
1080 | #endif /* CONFIG_TDLS */ |
1081 | ||
1082 | ||
eb2f2088 MB |
1083 | static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd) |
1084 | { | |
1085 | char *token, *context = NULL; | |
1086 | struct wmm_ac_ts_setup_params params = { | |
1087 | .tsid = 0xff, | |
1088 | .direction = 0xff, | |
1089 | }; | |
1090 | ||
1091 | while ((token = str_token(cmd, " ", &context))) { | |
1092 | if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 || | |
1093 | sscanf(token, "up=%i", ¶ms.user_priority) == 1 || | |
1094 | sscanf(token, "nominal_msdu_size=%i", | |
1095 | ¶ms.nominal_msdu_size) == 1 || | |
1096 | sscanf(token, "mean_data_rate=%i", | |
1097 | ¶ms.mean_data_rate) == 1 || | |
1098 | sscanf(token, "min_phy_rate=%i", | |
1099 | ¶ms.minimum_phy_rate) == 1 || | |
1100 | sscanf(token, "sba=%i", | |
1101 | ¶ms.surplus_bandwidth_allowance) == 1) | |
1102 | continue; | |
1103 | ||
1104 | if (os_strcasecmp(token, "downlink") == 0) { | |
1105 | params.direction = WMM_TSPEC_DIRECTION_DOWNLINK; | |
1106 | } else if (os_strcasecmp(token, "uplink") == 0) { | |
1107 | params.direction = WMM_TSPEC_DIRECTION_UPLINK; | |
1108 | } else if (os_strcasecmp(token, "bidi") == 0) { | |
1109 | params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL; | |
1110 | } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) { | |
1111 | params.fixed_nominal_msdu = 1; | |
1112 | } else { | |
1113 | wpa_printf(MSG_DEBUG, | |
1114 | "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'", | |
1115 | token); | |
1116 | return -1; | |
1117 | } | |
1118 | ||
1119 | } | |
1120 | ||
1121 | return wpas_wmm_ac_addts(wpa_s, ¶ms); | |
1122 | } | |
1123 | ||
1124 | ||
1125 | static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd) | |
1126 | { | |
1127 | u8 tsid = atoi(cmd); | |
1128 | ||
1129 | return wpas_wmm_ac_delts(wpa_s, tsid); | |
1130 | } | |
1131 | ||
1132 | ||
6fc6879b JM |
1133 | #ifdef CONFIG_IEEE80211R |
1134 | static int wpa_supplicant_ctrl_iface_ft_ds( | |
1135 | struct wpa_supplicant *wpa_s, char *addr) | |
1136 | { | |
1137 | u8 target_ap[ETH_ALEN]; | |
76b7981d JM |
1138 | struct wpa_bss *bss; |
1139 | const u8 *mdie; | |
6fc6879b JM |
1140 | |
1141 | if (hwaddr_aton(addr, target_ap)) { | |
1142 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid " | |
a7b6c422 | 1143 | "address '%s'", addr); |
6fc6879b JM |
1144 | return -1; |
1145 | } | |
1146 | ||
1147 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap)); | |
1148 | ||
76b7981d JM |
1149 | bss = wpa_bss_get_bssid(wpa_s, target_ap); |
1150 | if (bss) | |
1151 | mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); | |
1152 | else | |
1153 | mdie = NULL; | |
1154 | ||
1155 | return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie); | |
6fc6879b JM |
1156 | } |
1157 | #endif /* CONFIG_IEEE80211R */ | |
1158 | ||
1159 | ||
fcc60db4 JM |
1160 | #ifdef CONFIG_WPS |
1161 | static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s, | |
1162 | char *cmd) | |
1163 | { | |
3ec97afe | 1164 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
ceb34f25 | 1165 | #ifdef CONFIG_P2P |
634ce802 | 1166 | u8 p2p_dev_addr[ETH_ALEN]; |
ceb34f25 | 1167 | #endif /* CONFIG_P2P */ |
634ce802 JM |
1168 | #ifdef CONFIG_AP |
1169 | u8 *_p2p_dev_addr = NULL; | |
1170 | #endif /* CONFIG_AP */ | |
fcc60db4 | 1171 | |
d601247c | 1172 | if (cmd == NULL || os_strcmp(cmd, "any") == 0) { |
3ec97afe | 1173 | _bssid = NULL; |
d601247c JM |
1174 | #ifdef CONFIG_P2P |
1175 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | |
1176 | if (hwaddr_aton(cmd + 13, p2p_dev_addr)) { | |
1177 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid " | |
1178 | "P2P Device Address '%s'", | |
1179 | cmd + 13); | |
1180 | return -1; | |
1181 | } | |
1182 | _p2p_dev_addr = p2p_dev_addr; | |
1183 | #endif /* CONFIG_P2P */ | |
1184 | } else if (hwaddr_aton(cmd, bssid)) { | |
fcc60db4 JM |
1185 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'", |
1186 | cmd); | |
1187 | return -1; | |
1188 | } | |
1189 | ||
3ec97afe JM |
1190 | #ifdef CONFIG_AP |
1191 | if (wpa_s->ap_iface) | |
d601247c | 1192 | return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr); |
3ec97afe JM |
1193 | #endif /* CONFIG_AP */ |
1194 | ||
9fa243b2 | 1195 | return wpas_wps_start_pbc(wpa_s, _bssid, 0); |
fcc60db4 JM |
1196 | } |
1197 | ||
1198 | ||
1199 | static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, | |
1200 | char *cmd, char *buf, | |
1201 | size_t buflen) | |
1202 | { | |
1203 | u8 bssid[ETH_ALEN], *_bssid = bssid; | |
1204 | char *pin; | |
1205 | int ret; | |
1206 | ||
1207 | pin = os_strchr(cmd, ' '); | |
1208 | if (pin) | |
1209 | *pin++ = '\0'; | |
1210 | ||
1211 | if (os_strcmp(cmd, "any") == 0) | |
1212 | _bssid = NULL; | |
98aa7ca5 | 1213 | else if (os_strcmp(cmd, "get") == 0) { |
98a516ea NL |
1214 | if (wps_generate_pin((unsigned int *) &ret) < 0) |
1215 | return -1; | |
98aa7ca5 JM |
1216 | goto done; |
1217 | } else if (hwaddr_aton(cmd, bssid)) { | |
3c1e2765 | 1218 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'", |
fcc60db4 JM |
1219 | cmd); |
1220 | return -1; | |
1221 | } | |
1222 | ||
3ec97afe | 1223 | #ifdef CONFIG_AP |
c423708f JM |
1224 | if (wpa_s->ap_iface) { |
1225 | int timeout = 0; | |
1226 | char *pos; | |
1227 | ||
1228 | if (pin) { | |
1229 | pos = os_strchr(pin, ' '); | |
1230 | if (pos) { | |
1231 | *pos++ = '\0'; | |
1232 | timeout = atoi(pos); | |
1233 | } | |
1234 | } | |
1235 | ||
3ec97afe | 1236 | return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, |
c423708f JM |
1237 | buf, buflen, timeout); |
1238 | } | |
3ec97afe JM |
1239 | #endif /* CONFIG_AP */ |
1240 | ||
fcc60db4 | 1241 | if (pin) { |
3c5126a4 JM |
1242 | ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0, |
1243 | DEV_PW_DEFAULT); | |
fcc60db4 JM |
1244 | if (ret < 0) |
1245 | return -1; | |
1246 | ret = os_snprintf(buf, buflen, "%s", pin); | |
d85e1fc8 | 1247 | if (os_snprintf_error(buflen, ret)) |
fcc60db4 JM |
1248 | return -1; |
1249 | return ret; | |
1250 | } | |
1251 | ||
3c5126a4 | 1252 | ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT); |
fcc60db4 JM |
1253 | if (ret < 0) |
1254 | return -1; | |
1255 | ||
98aa7ca5 | 1256 | done: |
fcc60db4 JM |
1257 | /* Return the generated PIN */ |
1258 | ret = os_snprintf(buf, buflen, "%08d", ret); | |
d85e1fc8 | 1259 | if (os_snprintf_error(buflen, ret)) |
fcc60db4 JM |
1260 | return -1; |
1261 | return ret; | |
1262 | } | |
1263 | ||
1264 | ||
3981cb3c JM |
1265 | static int wpa_supplicant_ctrl_iface_wps_check_pin( |
1266 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
1267 | { | |
1268 | char pin[9]; | |
1269 | size_t len; | |
1270 | char *pos; | |
1271 | int ret; | |
1272 | ||
1273 | wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN", | |
1274 | (u8 *) cmd, os_strlen(cmd)); | |
1275 | for (pos = cmd, len = 0; *pos != '\0'; pos++) { | |
1276 | if (*pos < '0' || *pos > '9') | |
1277 | continue; | |
1278 | pin[len++] = *pos; | |
1279 | if (len == 9) { | |
1280 | wpa_printf(MSG_DEBUG, "WPS: Too long PIN"); | |
1281 | return -1; | |
1282 | } | |
1283 | } | |
1284 | if (len != 4 && len != 8) { | |
1285 | wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len); | |
1286 | return -1; | |
1287 | } | |
1288 | pin[len] = '\0'; | |
1289 | ||
1290 | if (len == 8) { | |
1291 | unsigned int pin_val; | |
1292 | pin_val = atoi(pin); | |
1293 | if (!wps_pin_valid(pin_val)) { | |
1294 | wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit"); | |
1295 | ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n"); | |
d85e1fc8 | 1296 | if (os_snprintf_error(buflen, ret)) |
3981cb3c JM |
1297 | return -1; |
1298 | return ret; | |
1299 | } | |
1300 | } | |
1301 | ||
1302 | ret = os_snprintf(buf, buflen, "%s", pin); | |
d85e1fc8 | 1303 | if (os_snprintf_error(buflen, ret)) |
3981cb3c JM |
1304 | return -1; |
1305 | ||
1306 | return ret; | |
1307 | } | |
1308 | ||
1309 | ||
71892384 | 1310 | #ifdef CONFIG_WPS_NFC |
3f2c8ba6 JM |
1311 | |
1312 | static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s, | |
1313 | char *cmd) | |
1314 | { | |
1315 | u8 bssid[ETH_ALEN], *_bssid = bssid; | |
1316 | ||
1317 | if (cmd == NULL || cmd[0] == '\0') | |
1318 | _bssid = NULL; | |
1319 | else if (hwaddr_aton(cmd, bssid)) | |
1320 | return -1; | |
1321 | ||
23318bea | 1322 | return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL, |
91a65018 | 1323 | 0, 0); |
3f2c8ba6 JM |
1324 | } |
1325 | ||
1326 | ||
bbf41865 JM |
1327 | static int wpa_supplicant_ctrl_iface_wps_nfc_config_token( |
1328 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
1329 | { | |
1330 | int ndef; | |
1331 | struct wpabuf *buf; | |
1332 | int res; | |
88c8bf31 | 1333 | char *pos; |
bbf41865 | 1334 | |
88c8bf31 JM |
1335 | pos = os_strchr(cmd, ' '); |
1336 | if (pos) | |
1337 | *pos++ = '\0'; | |
bbf41865 JM |
1338 | if (os_strcmp(cmd, "WPS") == 0) |
1339 | ndef = 0; | |
1340 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1341 | ndef = 1; | |
1342 | else | |
1343 | return -1; | |
1344 | ||
88c8bf31 | 1345 | buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos); |
bbf41865 JM |
1346 | if (buf == NULL) |
1347 | return -1; | |
1348 | ||
1349 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1350 | wpabuf_len(buf)); | |
1351 | reply[res++] = '\n'; | |
1352 | reply[res] = '\0'; | |
1353 | ||
1354 | wpabuf_free(buf); | |
1355 | ||
1356 | return res; | |
1357 | } | |
1358 | ||
1359 | ||
3f2c8ba6 JM |
1360 | static int wpa_supplicant_ctrl_iface_wps_nfc_token( |
1361 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
1362 | { | |
1363 | int ndef; | |
1364 | struct wpabuf *buf; | |
1365 | int res; | |
1366 | ||
1367 | if (os_strcmp(cmd, "WPS") == 0) | |
1368 | ndef = 0; | |
1369 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1370 | ndef = 1; | |
1371 | else | |
1372 | return -1; | |
1373 | ||
1374 | buf = wpas_wps_nfc_token(wpa_s, ndef); | |
1375 | if (buf == NULL) | |
1376 | return -1; | |
1377 | ||
1378 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1379 | wpabuf_len(buf)); | |
1380 | reply[res++] = '\n'; | |
1381 | reply[res] = '\0'; | |
1382 | ||
1383 | wpabuf_free(buf); | |
1384 | ||
1385 | return res; | |
1386 | } | |
d7645d23 JM |
1387 | |
1388 | ||
1389 | static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read( | |
1390 | struct wpa_supplicant *wpa_s, char *pos) | |
1391 | { | |
1392 | size_t len; | |
1393 | struct wpabuf *buf; | |
1394 | int ret; | |
b56f6c88 JM |
1395 | char *freq; |
1396 | int forced_freq = 0; | |
1397 | ||
1398 | freq = strstr(pos, " freq="); | |
1399 | if (freq) { | |
1400 | *freq = '\0'; | |
1401 | freq += 6; | |
1402 | forced_freq = atoi(freq); | |
1403 | } | |
d7645d23 JM |
1404 | |
1405 | len = os_strlen(pos); | |
1406 | if (len & 0x01) | |
1407 | return -1; | |
1408 | len /= 2; | |
1409 | ||
1410 | buf = wpabuf_alloc(len); | |
1411 | if (buf == NULL) | |
1412 | return -1; | |
1413 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { | |
1414 | wpabuf_free(buf); | |
1415 | return -1; | |
1416 | } | |
1417 | ||
b56f6c88 | 1418 | ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq); |
d7645d23 JM |
1419 | wpabuf_free(buf); |
1420 | ||
1421 | return ret; | |
1422 | } | |
71892384 | 1423 | |
e65552dd JM |
1424 | |
1425 | static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s, | |
bbaaaee1 | 1426 | char *reply, size_t max_len, |
41f9ffb6 | 1427 | int ndef) |
e65552dd JM |
1428 | { |
1429 | struct wpabuf *buf; | |
1430 | int res; | |
1431 | ||
41f9ffb6 | 1432 | buf = wpas_wps_nfc_handover_req(wpa_s, ndef); |
e65552dd JM |
1433 | if (buf == NULL) |
1434 | return -1; | |
1435 | ||
1436 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1437 | wpabuf_len(buf)); | |
1438 | reply[res++] = '\n'; | |
1439 | reply[res] = '\0'; | |
1440 | ||
1441 | wpabuf_free(buf); | |
1442 | ||
1443 | return res; | |
1444 | } | |
1445 | ||
1446 | ||
88853aed | 1447 | #ifdef CONFIG_P2P |
93588780 JM |
1448 | static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s, |
1449 | char *reply, size_t max_len, | |
1450 | int ndef) | |
1451 | { | |
1452 | struct wpabuf *buf; | |
1453 | int res; | |
1454 | ||
1455 | buf = wpas_p2p_nfc_handover_req(wpa_s, ndef); | |
1456 | if (buf == NULL) { | |
1457 | wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request"); | |
1458 | return -1; | |
1459 | } | |
1460 | ||
1461 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1462 | wpabuf_len(buf)); | |
1463 | reply[res++] = '\n'; | |
1464 | reply[res] = '\0'; | |
1465 | ||
1466 | wpabuf_free(buf); | |
1467 | ||
1468 | return res; | |
1469 | } | |
88853aed | 1470 | #endif /* CONFIG_P2P */ |
93588780 JM |
1471 | |
1472 | ||
e65552dd JM |
1473 | static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s, |
1474 | char *cmd, char *reply, | |
1475 | size_t max_len) | |
1476 | { | |
1477 | char *pos; | |
41f9ffb6 | 1478 | int ndef; |
e65552dd JM |
1479 | |
1480 | pos = os_strchr(cmd, ' '); | |
1481 | if (pos == NULL) | |
1482 | return -1; | |
1483 | *pos++ = '\0'; | |
1484 | ||
41f9ffb6 JM |
1485 | if (os_strcmp(cmd, "WPS") == 0) |
1486 | ndef = 0; | |
1487 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1488 | ndef = 1; | |
1489 | else | |
e65552dd JM |
1490 | return -1; |
1491 | ||
bbaaaee1 | 1492 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
41f9ffb6 JM |
1493 | if (!ndef) |
1494 | return -1; | |
bbaaaee1 | 1495 | return wpas_ctrl_nfc_get_handover_req_wps( |
41f9ffb6 | 1496 | wpa_s, reply, max_len, ndef); |
e65552dd JM |
1497 | } |
1498 | ||
88853aed | 1499 | #ifdef CONFIG_P2P |
93588780 JM |
1500 | if (os_strcmp(pos, "P2P-CR") == 0) { |
1501 | return wpas_ctrl_nfc_get_handover_req_p2p( | |
1502 | wpa_s, reply, max_len, ndef); | |
1503 | } | |
88853aed | 1504 | #endif /* CONFIG_P2P */ |
93588780 | 1505 | |
e65552dd JM |
1506 | return -1; |
1507 | } | |
1508 | ||
1509 | ||
1510 | static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s, | |
5ab9a6a5 | 1511 | char *reply, size_t max_len, |
f3f2ba2e | 1512 | int ndef, int cr, char *uuid) |
e65552dd JM |
1513 | { |
1514 | struct wpabuf *buf; | |
1515 | int res; | |
1516 | ||
f3f2ba2e | 1517 | buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid); |
e65552dd JM |
1518 | if (buf == NULL) |
1519 | return -1; | |
1520 | ||
1521 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1522 | wpabuf_len(buf)); | |
1523 | reply[res++] = '\n'; | |
1524 | reply[res] = '\0'; | |
1525 | ||
1526 | wpabuf_free(buf); | |
1527 | ||
1528 | return res; | |
1529 | } | |
1530 | ||
1531 | ||
88853aed | 1532 | #ifdef CONFIG_P2P |
93588780 JM |
1533 | static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s, |
1534 | char *reply, size_t max_len, | |
1535 | int ndef, int tag) | |
1536 | { | |
1537 | struct wpabuf *buf; | |
1538 | int res; | |
1539 | ||
1540 | buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag); | |
1541 | if (buf == NULL) | |
1542 | return -1; | |
1543 | ||
1544 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1545 | wpabuf_len(buf)); | |
1546 | reply[res++] = '\n'; | |
1547 | reply[res] = '\0'; | |
1548 | ||
1549 | wpabuf_free(buf); | |
1550 | ||
1551 | return res; | |
1552 | } | |
88853aed | 1553 | #endif /* CONFIG_P2P */ |
93588780 JM |
1554 | |
1555 | ||
e65552dd JM |
1556 | static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s, |
1557 | char *cmd, char *reply, | |
1558 | size_t max_len) | |
1559 | { | |
f3f2ba2e | 1560 | char *pos, *pos2; |
5ab9a6a5 | 1561 | int ndef; |
e65552dd JM |
1562 | |
1563 | pos = os_strchr(cmd, ' '); | |
1564 | if (pos == NULL) | |
1565 | return -1; | |
1566 | *pos++ = '\0'; | |
1567 | ||
5ab9a6a5 JM |
1568 | if (os_strcmp(cmd, "WPS") == 0) |
1569 | ndef = 0; | |
1570 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1571 | ndef = 1; | |
1572 | else | |
e65552dd JM |
1573 | return -1; |
1574 | ||
f3f2ba2e JM |
1575 | pos2 = os_strchr(pos, ' '); |
1576 | if (pos2) | |
1577 | *pos2++ = '\0'; | |
5ab9a6a5 | 1578 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
93588780 JM |
1579 | if (!ndef) |
1580 | return -1; | |
5ab9a6a5 JM |
1581 | return wpas_ctrl_nfc_get_handover_sel_wps( |
1582 | wpa_s, reply, max_len, ndef, | |
f3f2ba2e | 1583 | os_strcmp(pos, "WPS-CR") == 0, pos2); |
e65552dd JM |
1584 | } |
1585 | ||
88853aed | 1586 | #ifdef CONFIG_P2P |
93588780 JM |
1587 | if (os_strcmp(pos, "P2P-CR") == 0) { |
1588 | return wpas_ctrl_nfc_get_handover_sel_p2p( | |
1589 | wpa_s, reply, max_len, ndef, 0); | |
1590 | } | |
1591 | ||
1592 | if (os_strcmp(pos, "P2P-CR-TAG") == 0) { | |
1593 | return wpas_ctrl_nfc_get_handover_sel_p2p( | |
1594 | wpa_s, reply, max_len, ndef, 1); | |
1595 | } | |
88853aed | 1596 | #endif /* CONFIG_P2P */ |
93588780 | 1597 | |
e65552dd JM |
1598 | return -1; |
1599 | } | |
1600 | ||
1601 | ||
e4758827 JM |
1602 | static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s, |
1603 | char *cmd) | |
1604 | { | |
1605 | size_t len; | |
1606 | struct wpabuf *req, *sel; | |
1607 | int ret; | |
1608 | char *pos, *role, *type, *pos2; | |
88853aed | 1609 | #ifdef CONFIG_P2P |
b56f6c88 JM |
1610 | char *freq; |
1611 | int forced_freq = 0; | |
1612 | ||
1613 | freq = strstr(cmd, " freq="); | |
1614 | if (freq) { | |
1615 | *freq = '\0'; | |
1616 | freq += 6; | |
1617 | forced_freq = atoi(freq); | |
1618 | } | |
88853aed | 1619 | #endif /* CONFIG_P2P */ |
e4758827 JM |
1620 | |
1621 | role = cmd; | |
1622 | pos = os_strchr(role, ' '); | |
73127764 JM |
1623 | if (pos == NULL) { |
1624 | wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report"); | |
e4758827 | 1625 | return -1; |
73127764 | 1626 | } |
e4758827 JM |
1627 | *pos++ = '\0'; |
1628 | ||
1629 | type = pos; | |
1630 | pos = os_strchr(type, ' '); | |
73127764 JM |
1631 | if (pos == NULL) { |
1632 | wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report"); | |
e4758827 | 1633 | return -1; |
73127764 | 1634 | } |
e4758827 JM |
1635 | *pos++ = '\0'; |
1636 | ||
1637 | pos2 = os_strchr(pos, ' '); | |
73127764 JM |
1638 | if (pos2 == NULL) { |
1639 | wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report"); | |
e4758827 | 1640 | return -1; |
73127764 | 1641 | } |
e4758827 JM |
1642 | *pos2++ = '\0'; |
1643 | ||
1644 | len = os_strlen(pos); | |
73127764 JM |
1645 | if (len & 0x01) { |
1646 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report"); | |
e4758827 | 1647 | return -1; |
73127764 | 1648 | } |
e4758827 JM |
1649 | len /= 2; |
1650 | ||
1651 | req = wpabuf_alloc(len); | |
73127764 JM |
1652 | if (req == NULL) { |
1653 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message"); | |
e4758827 | 1654 | return -1; |
73127764 | 1655 | } |
e4758827 | 1656 | if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) { |
73127764 | 1657 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report"); |
e4758827 JM |
1658 | wpabuf_free(req); |
1659 | return -1; | |
1660 | } | |
1661 | ||
1662 | len = os_strlen(pos2); | |
1663 | if (len & 0x01) { | |
73127764 | 1664 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report"); |
e4758827 JM |
1665 | wpabuf_free(req); |
1666 | return -1; | |
1667 | } | |
1668 | len /= 2; | |
1669 | ||
1670 | sel = wpabuf_alloc(len); | |
1671 | if (sel == NULL) { | |
73127764 | 1672 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message"); |
e4758827 JM |
1673 | wpabuf_free(req); |
1674 | return -1; | |
1675 | } | |
1676 | if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) { | |
73127764 | 1677 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report"); |
e4758827 JM |
1678 | wpabuf_free(req); |
1679 | wpabuf_free(sel); | |
1680 | return -1; | |
1681 | } | |
1682 | ||
73127764 JM |
1683 | wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d", |
1684 | role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel)); | |
1685 | ||
e4758827 JM |
1686 | if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) { |
1687 | ret = wpas_wps_nfc_report_handover(wpa_s, req, sel); | |
88853aed | 1688 | #ifdef CONFIG_AP |
d9507936 JM |
1689 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) |
1690 | { | |
1691 | ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel); | |
50d1f890 JM |
1692 | if (ret < 0) |
1693 | ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel); | |
88853aed JM |
1694 | #endif /* CONFIG_AP */ |
1695 | #ifdef CONFIG_P2P | |
db6ae69e JM |
1696 | } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0) |
1697 | { | |
b56f6c88 | 1698 | ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0); |
db6ae69e JM |
1699 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0) |
1700 | { | |
b56f6c88 JM |
1701 | ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel, |
1702 | forced_freq); | |
88853aed | 1703 | #endif /* CONFIG_P2P */ |
e4758827 JM |
1704 | } else { |
1705 | wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover " | |
1706 | "reported: role=%s type=%s", role, type); | |
1707 | ret = -1; | |
1708 | } | |
1709 | wpabuf_free(req); | |
1710 | wpabuf_free(sel); | |
1711 | ||
73127764 JM |
1712 | if (ret) |
1713 | wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages"); | |
1714 | ||
e4758827 JM |
1715 | return ret; |
1716 | } | |
1717 | ||
71892384 | 1718 | #endif /* CONFIG_WPS_NFC */ |
46bdb83a MH |
1719 | |
1720 | ||
fcc60db4 JM |
1721 | static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s, |
1722 | char *cmd) | |
1723 | { | |
129eb428 | 1724 | u8 bssid[ETH_ALEN]; |
fcc60db4 | 1725 | char *pin; |
52eb293d JM |
1726 | char *new_ssid; |
1727 | char *new_auth; | |
1728 | char *new_encr; | |
1729 | char *new_key; | |
1730 | struct wps_new_ap_settings ap; | |
fcc60db4 JM |
1731 | |
1732 | pin = os_strchr(cmd, ' '); | |
1733 | if (pin == NULL) | |
1734 | return -1; | |
1735 | *pin++ = '\0'; | |
1736 | ||
129eb428 | 1737 | if (hwaddr_aton(cmd, bssid)) { |
fcc60db4 JM |
1738 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'", |
1739 | cmd); | |
1740 | return -1; | |
1741 | } | |
1742 | ||
52eb293d JM |
1743 | new_ssid = os_strchr(pin, ' '); |
1744 | if (new_ssid == NULL) | |
129eb428 | 1745 | return wpas_wps_start_reg(wpa_s, bssid, pin, NULL); |
52eb293d JM |
1746 | *new_ssid++ = '\0'; |
1747 | ||
1748 | new_auth = os_strchr(new_ssid, ' '); | |
1749 | if (new_auth == NULL) | |
1750 | return -1; | |
1751 | *new_auth++ = '\0'; | |
1752 | ||
1753 | new_encr = os_strchr(new_auth, ' '); | |
1754 | if (new_encr == NULL) | |
1755 | return -1; | |
1756 | *new_encr++ = '\0'; | |
1757 | ||
1758 | new_key = os_strchr(new_encr, ' '); | |
1759 | if (new_key == NULL) | |
1760 | return -1; | |
1761 | *new_key++ = '\0'; | |
1762 | ||
1763 | os_memset(&ap, 0, sizeof(ap)); | |
1764 | ap.ssid_hex = new_ssid; | |
1765 | ap.auth = new_auth; | |
1766 | ap.encr = new_encr; | |
1767 | ap.key_hex = new_key; | |
129eb428 | 1768 | return wpas_wps_start_reg(wpa_s, bssid, pin, &ap); |
fcc60db4 | 1769 | } |
72df2f5f JM |
1770 | |
1771 | ||
70d84f11 JM |
1772 | #ifdef CONFIG_AP |
1773 | static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s, | |
1774 | char *cmd, char *buf, | |
1775 | size_t buflen) | |
1776 | { | |
1777 | int timeout = 300; | |
1778 | char *pos; | |
1779 | const char *pin_txt; | |
1780 | ||
1781 | if (!wpa_s->ap_iface) | |
1782 | return -1; | |
1783 | ||
1784 | pos = os_strchr(cmd, ' '); | |
1785 | if (pos) | |
1786 | *pos++ = '\0'; | |
1787 | ||
1788 | if (os_strcmp(cmd, "disable") == 0) { | |
1789 | wpas_wps_ap_pin_disable(wpa_s); | |
1790 | return os_snprintf(buf, buflen, "OK\n"); | |
1791 | } | |
1792 | ||
1793 | if (os_strcmp(cmd, "random") == 0) { | |
1794 | if (pos) | |
1795 | timeout = atoi(pos); | |
1796 | pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout); | |
1797 | if (pin_txt == NULL) | |
1798 | return -1; | |
1799 | return os_snprintf(buf, buflen, "%s", pin_txt); | |
1800 | } | |
1801 | ||
1802 | if (os_strcmp(cmd, "get") == 0) { | |
1803 | pin_txt = wpas_wps_ap_pin_get(wpa_s); | |
1804 | if (pin_txt == NULL) | |
1805 | return -1; | |
1806 | return os_snprintf(buf, buflen, "%s", pin_txt); | |
1807 | } | |
1808 | ||
1809 | if (os_strcmp(cmd, "set") == 0) { | |
1810 | char *pin; | |
1811 | if (pos == NULL) | |
1812 | return -1; | |
1813 | pin = pos; | |
1814 | pos = os_strchr(pos, ' '); | |
1815 | if (pos) { | |
1816 | *pos++ = '\0'; | |
1817 | timeout = atoi(pos); | |
1818 | } | |
1819 | if (os_strlen(pin) > buflen) | |
1820 | return -1; | |
1821 | if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0) | |
1822 | return -1; | |
1823 | return os_snprintf(buf, buflen, "%s", pin); | |
1824 | } | |
1825 | ||
1826 | return -1; | |
1827 | } | |
1828 | #endif /* CONFIG_AP */ | |
1829 | ||
1830 | ||
72df2f5f JM |
1831 | #ifdef CONFIG_WPS_ER |
1832 | static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s, | |
1833 | char *cmd) | |
1834 | { | |
31fcea93 JM |
1835 | char *uuid = cmd, *pin, *pos; |
1836 | u8 addr_buf[ETH_ALEN], *addr = NULL; | |
72df2f5f JM |
1837 | pin = os_strchr(uuid, ' '); |
1838 | if (pin == NULL) | |
1839 | return -1; | |
1840 | *pin++ = '\0'; | |
31fcea93 JM |
1841 | pos = os_strchr(pin, ' '); |
1842 | if (pos) { | |
1843 | *pos++ = '\0'; | |
1844 | if (hwaddr_aton(pos, addr_buf) == 0) | |
1845 | addr = addr_buf; | |
1846 | } | |
1847 | return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin); | |
72df2f5f | 1848 | } |
e64dcfd5 JM |
1849 | |
1850 | ||
1851 | static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s, | |
1852 | char *cmd) | |
1853 | { | |
1854 | char *uuid = cmd, *pin; | |
1855 | pin = os_strchr(uuid, ' '); | |
1856 | if (pin == NULL) | |
1857 | return -1; | |
1858 | *pin++ = '\0'; | |
1859 | return wpas_wps_er_learn(wpa_s, uuid, pin); | |
1860 | } | |
7d6640a6 JM |
1861 | |
1862 | ||
ef10f473 JM |
1863 | static int wpa_supplicant_ctrl_iface_wps_er_set_config( |
1864 | struct wpa_supplicant *wpa_s, char *cmd) | |
1865 | { | |
1866 | char *uuid = cmd, *id; | |
1867 | id = os_strchr(uuid, ' '); | |
1868 | if (id == NULL) | |
1869 | return -1; | |
1870 | *id++ = '\0'; | |
1871 | return wpas_wps_er_set_config(wpa_s, uuid, atoi(id)); | |
1872 | } | |
1873 | ||
1874 | ||
7d6640a6 JM |
1875 | static int wpa_supplicant_ctrl_iface_wps_er_config( |
1876 | struct wpa_supplicant *wpa_s, char *cmd) | |
1877 | { | |
1878 | char *pin; | |
1879 | char *new_ssid; | |
1880 | char *new_auth; | |
1881 | char *new_encr; | |
1882 | char *new_key; | |
1883 | struct wps_new_ap_settings ap; | |
1884 | ||
1885 | pin = os_strchr(cmd, ' '); | |
1886 | if (pin == NULL) | |
1887 | return -1; | |
1888 | *pin++ = '\0'; | |
1889 | ||
1890 | new_ssid = os_strchr(pin, ' '); | |
1891 | if (new_ssid == NULL) | |
1892 | return -1; | |
1893 | *new_ssid++ = '\0'; | |
1894 | ||
1895 | new_auth = os_strchr(new_ssid, ' '); | |
1896 | if (new_auth == NULL) | |
1897 | return -1; | |
1898 | *new_auth++ = '\0'; | |
1899 | ||
1900 | new_encr = os_strchr(new_auth, ' '); | |
1901 | if (new_encr == NULL) | |
1902 | return -1; | |
1903 | *new_encr++ = '\0'; | |
1904 | ||
1905 | new_key = os_strchr(new_encr, ' '); | |
1906 | if (new_key == NULL) | |
1907 | return -1; | |
1908 | *new_key++ = '\0'; | |
1909 | ||
1910 | os_memset(&ap, 0, sizeof(ap)); | |
1911 | ap.ssid_hex = new_ssid; | |
1912 | ap.auth = new_auth; | |
1913 | ap.encr = new_encr; | |
1914 | ap.key_hex = new_key; | |
1915 | return wpas_wps_er_config(wpa_s, cmd, pin, &ap); | |
1916 | } | |
1cea09a9 JM |
1917 | |
1918 | ||
1919 | #ifdef CONFIG_WPS_NFC | |
1920 | static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | |
1921 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
1922 | { | |
1923 | int ndef; | |
1924 | struct wpabuf *buf; | |
1925 | int res; | |
1926 | char *uuid; | |
1927 | ||
1928 | uuid = os_strchr(cmd, ' '); | |
1929 | if (uuid == NULL) | |
1930 | return -1; | |
1931 | *uuid++ = '\0'; | |
1932 | ||
1933 | if (os_strcmp(cmd, "WPS") == 0) | |
1934 | ndef = 0; | |
1935 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1936 | ndef = 1; | |
1937 | else | |
1938 | return -1; | |
1939 | ||
1940 | buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid); | |
1941 | if (buf == NULL) | |
1942 | return -1; | |
1943 | ||
1944 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1945 | wpabuf_len(buf)); | |
1946 | reply[res++] = '\n'; | |
1947 | reply[res] = '\0'; | |
1948 | ||
1949 | wpabuf_free(buf); | |
1950 | ||
1951 | return res; | |
1952 | } | |
1953 | #endif /* CONFIG_WPS_NFC */ | |
72df2f5f JM |
1954 | #endif /* CONFIG_WPS_ER */ |
1955 | ||
fcc60db4 JM |
1956 | #endif /* CONFIG_WPS */ |
1957 | ||
1958 | ||
11ef8d35 JM |
1959 | #ifdef CONFIG_IBSS_RSN |
1960 | static int wpa_supplicant_ctrl_iface_ibss_rsn( | |
1961 | struct wpa_supplicant *wpa_s, char *addr) | |
1962 | { | |
1963 | u8 peer[ETH_ALEN]; | |
1964 | ||
1965 | if (hwaddr_aton(addr, peer)) { | |
1966 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid " | |
a7b6c422 | 1967 | "address '%s'", addr); |
11ef8d35 JM |
1968 | return -1; |
1969 | } | |
1970 | ||
1971 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR, | |
1972 | MAC2STR(peer)); | |
1973 | ||
1974 | return ibss_rsn_start(wpa_s->ibss_rsn, peer); | |
1975 | } | |
1976 | #endif /* CONFIG_IBSS_RSN */ | |
1977 | ||
1978 | ||
7de5688d DW |
1979 | static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, |
1980 | char *rsp) | |
1981 | { | |
1982 | #ifdef IEEE8021X_EAPOL | |
1983 | char *pos, *id_pos; | |
1984 | int id; | |
1985 | struct wpa_ssid *ssid; | |
1986 | ||
1987 | pos = os_strchr(rsp, '-'); | |
1988 | if (pos == NULL) | |
1989 | return -1; | |
1990 | *pos++ = '\0'; | |
1991 | id_pos = pos; | |
1992 | pos = os_strchr(pos, ':'); | |
1993 | if (pos == NULL) | |
1994 | return -1; | |
1995 | *pos++ = '\0'; | |
1996 | id = atoi(id_pos); | |
1997 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); | |
1998 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
1999 | (u8 *) pos, os_strlen(pos)); | |
2000 | ||
2001 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
2002 | if (ssid == NULL) { | |
2003 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
2004 | "to update", id); | |
2005 | return -1; | |
2006 | } | |
2007 | ||
2008 | return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp, | |
2009 | pos); | |
6fc6879b JM |
2010 | #else /* IEEE8021X_EAPOL */ |
2011 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); | |
2012 | return -1; | |
2013 | #endif /* IEEE8021X_EAPOL */ | |
2014 | } | |
2015 | ||
2016 | ||
2017 | static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, | |
2018 | const char *params, | |
2019 | char *buf, size_t buflen) | |
2020 | { | |
2021 | char *pos, *end, tmp[30]; | |
0bc13468 | 2022 | int res, verbose, wps, ret; |
f9cd147d JM |
2023 | #ifdef CONFIG_HS20 |
2024 | const u8 *hs20; | |
2025 | #endif /* CONFIG_HS20 */ | |
993a8654 JM |
2026 | const u8 *sess_id; |
2027 | size_t sess_id_len; | |
6fc6879b | 2028 | |
a771c07d JM |
2029 | if (os_strcmp(params, "-DRIVER") == 0) |
2030 | return wpa_drv_status(wpa_s, buf, buflen); | |
6fc6879b | 2031 | verbose = os_strcmp(params, "-VERBOSE") == 0; |
0bc13468 | 2032 | wps = os_strcmp(params, "-WPS") == 0; |
6fc6879b JM |
2033 | pos = buf; |
2034 | end = buf + buflen; | |
2035 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { | |
2036 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
2037 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | |
2038 | MAC2STR(wpa_s->bssid)); | |
d85e1fc8 | 2039 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2040 | return pos - buf; |
2041 | pos += ret; | |
b6ebdfbe BP |
2042 | ret = os_snprintf(pos, end - pos, "freq=%u\n", |
2043 | wpa_s->assoc_freq); | |
d85e1fc8 | 2044 | if (os_snprintf_error(end - pos, ret)) |
b6ebdfbe BP |
2045 | return pos - buf; |
2046 | pos += ret; | |
6fc6879b JM |
2047 | if (ssid) { |
2048 | u8 *_ssid = ssid->ssid; | |
2049 | size_t ssid_len = ssid->ssid_len; | |
eaa8eefe | 2050 | u8 ssid_buf[SSID_MAX_LEN]; |
6fc6879b JM |
2051 | if (ssid_len == 0) { |
2052 | int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); | |
2053 | if (_res < 0) | |
2054 | ssid_len = 0; | |
2055 | else | |
2056 | ssid_len = _res; | |
2057 | _ssid = ssid_buf; | |
2058 | } | |
2059 | ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", | |
2060 | wpa_ssid_txt(_ssid, ssid_len), | |
2061 | ssid->id); | |
d85e1fc8 | 2062 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2063 | return pos - buf; |
2064 | pos += ret; | |
2065 | ||
0bc13468 JM |
2066 | if (wps && ssid->passphrase && |
2067 | wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && | |
2068 | (ssid->mode == WPAS_MODE_AP || | |
2069 | ssid->mode == WPAS_MODE_P2P_GO)) { | |
2070 | ret = os_snprintf(pos, end - pos, | |
2071 | "passphrase=%s\n", | |
2072 | ssid->passphrase); | |
d85e1fc8 | 2073 | if (os_snprintf_error(end - pos, ret)) |
0bc13468 JM |
2074 | return pos - buf; |
2075 | pos += ret; | |
2076 | } | |
6fc6879b JM |
2077 | if (ssid->id_str) { |
2078 | ret = os_snprintf(pos, end - pos, | |
2079 | "id_str=%s\n", | |
2080 | ssid->id_str); | |
d85e1fc8 | 2081 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2082 | return pos - buf; |
2083 | pos += ret; | |
2084 | } | |
0e15e529 JM |
2085 | |
2086 | switch (ssid->mode) { | |
d7dcba70 | 2087 | case WPAS_MODE_INFRA: |
0e15e529 JM |
2088 | ret = os_snprintf(pos, end - pos, |
2089 | "mode=station\n"); | |
2090 | break; | |
d7dcba70 | 2091 | case WPAS_MODE_IBSS: |
0e15e529 JM |
2092 | ret = os_snprintf(pos, end - pos, |
2093 | "mode=IBSS\n"); | |
2094 | break; | |
d7dcba70 | 2095 | case WPAS_MODE_AP: |
0e15e529 JM |
2096 | ret = os_snprintf(pos, end - pos, |
2097 | "mode=AP\n"); | |
2098 | break; | |
2c5d725c JM |
2099 | case WPAS_MODE_P2P_GO: |
2100 | ret = os_snprintf(pos, end - pos, | |
2101 | "mode=P2P GO\n"); | |
2102 | break; | |
2103 | case WPAS_MODE_P2P_GROUP_FORMATION: | |
2104 | ret = os_snprintf(pos, end - pos, | |
2105 | "mode=P2P GO - group " | |
2106 | "formation\n"); | |
2107 | break; | |
cee0be73 SB |
2108 | case WPAS_MODE_MESH: |
2109 | ret = os_snprintf(pos, end - pos, | |
2110 | "mode=mesh\n"); | |
2111 | break; | |
0e15e529 JM |
2112 | default: |
2113 | ret = 0; | |
2114 | break; | |
2115 | } | |
1f102d3b | 2116 | if (os_snprintf_error(end - pos, ret)) |
0e15e529 JM |
2117 | return pos - buf; |
2118 | pos += ret; | |
6fc6879b JM |
2119 | } |
2120 | ||
3f8ceff5 JM |
2121 | if (wpa_s->connection_set && |
2122 | (wpa_s->connection_ht || wpa_s->connection_vht || | |
2123 | wpa_s->connection_he)) { | |
2124 | ret = os_snprintf(pos, end - pos, | |
2125 | "wifi_generation=%u\n", | |
2126 | wpa_s->connection_he ? 6 : | |
2127 | (wpa_s->connection_vht ? 5 : 4)); | |
2128 | if (os_snprintf_error(end - pos, ret)) | |
2129 | return pos - buf; | |
2130 | pos += ret; | |
2131 | } | |
2132 | ||
43fb5297 JM |
2133 | #ifdef CONFIG_AP |
2134 | if (wpa_s->ap_iface) { | |
2135 | pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos, | |
2136 | end - pos, | |
2137 | verbose); | |
2138 | } else | |
2139 | #endif /* CONFIG_AP */ | |
6fc6879b JM |
2140 | pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); |
2141 | } | |
afe73100 | 2142 | #ifdef CONFIG_SME |
4954c859 JM |
2143 | #ifdef CONFIG_SAE |
2144 | if (wpa_s->wpa_state >= WPA_ASSOCIATED && | |
e1ae5d74 JM |
2145 | #ifdef CONFIG_AP |
2146 | !wpa_s->ap_iface && | |
2147 | #endif /* CONFIG_AP */ | |
2148 | wpa_s->sme.sae.state == SAE_ACCEPTED) { | |
4954c859 JM |
2149 | ret = os_snprintf(pos, end - pos, "sae_group=%d\n", |
2150 | wpa_s->sme.sae.group); | |
d85e1fc8 | 2151 | if (os_snprintf_error(end - pos, ret)) |
4954c859 JM |
2152 | return pos - buf; |
2153 | pos += ret; | |
2154 | } | |
2155 | #endif /* CONFIG_SAE */ | |
afe73100 | 2156 | #endif /* CONFIG_SME */ |
6fc6879b JM |
2157 | ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", |
2158 | wpa_supplicant_state_txt(wpa_s->wpa_state)); | |
d85e1fc8 | 2159 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2160 | return pos - buf; |
2161 | pos += ret; | |
2162 | ||
2163 | if (wpa_s->l2 && | |
2164 | l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { | |
2165 | ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); | |
d85e1fc8 | 2166 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2167 | return pos - buf; |
2168 | pos += ret; | |
2169 | } | |
2170 | ||
d23bd894 JM |
2171 | #ifdef CONFIG_P2P |
2172 | if (wpa_s->global->p2p) { | |
2173 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR | |
2174 | "\n", MAC2STR(wpa_s->global->p2p_dev_addr)); | |
d85e1fc8 | 2175 | if (os_snprintf_error(end - pos, ret)) |
d23bd894 JM |
2176 | return pos - buf; |
2177 | pos += ret; | |
2178 | } | |
b21e2c84 | 2179 | #endif /* CONFIG_P2P */ |
6d4747a9 JM |
2180 | |
2181 | ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n", | |
2182 | MAC2STR(wpa_s->own_addr)); | |
d85e1fc8 | 2183 | if (os_snprintf_error(end - pos, ret)) |
6d4747a9 JM |
2184 | return pos - buf; |
2185 | pos += ret; | |
d23bd894 | 2186 | |
64855b96 JM |
2187 | #ifdef CONFIG_HS20 |
2188 | if (wpa_s->current_bss && | |
f9cd147d JM |
2189 | (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss, |
2190 | HS20_IE_VENDOR_TYPE)) && | |
4ed34f5a JM |
2191 | wpa_s->wpa_proto == WPA_PROTO_RSN && |
2192 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | |
f9cd147d JM |
2193 | int release = 1; |
2194 | if (hs20[1] >= 5) { | |
2195 | u8 rel_num = (hs20[6] & 0xf0) >> 4; | |
2196 | release = rel_num + 1; | |
2197 | } | |
2198 | ret = os_snprintf(pos, end - pos, "hs20=%d\n", release); | |
d85e1fc8 | 2199 | if (os_snprintf_error(end - pos, ret)) |
64855b96 JM |
2200 | return pos - buf; |
2201 | pos += ret; | |
2202 | } | |
e99b4f3a JM |
2203 | |
2204 | if (wpa_s->current_ssid) { | |
2205 | struct wpa_cred *cred; | |
2206 | char *type; | |
2207 | ||
2208 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { | |
463c8ffb JM |
2209 | size_t i; |
2210 | ||
e99b4f3a JM |
2211 | if (wpa_s->current_ssid->parent_cred != cred) |
2212 | continue; | |
e99b4f3a | 2213 | |
aa26ba68 | 2214 | if (cred->provisioning_sp) { |
463c8ffb | 2215 | ret = os_snprintf(pos, end - pos, |
aa26ba68 JM |
2216 | "provisioning_sp=%s\n", |
2217 | cred->provisioning_sp); | |
d85e1fc8 | 2218 | if (os_snprintf_error(end - pos, ret)) |
463c8ffb JM |
2219 | return pos - buf; |
2220 | pos += ret; | |
2221 | } | |
e99b4f3a | 2222 | |
aa26ba68 JM |
2223 | if (!cred->domain) |
2224 | goto no_domain; | |
2225 | ||
2226 | i = 0; | |
2227 | if (wpa_s->current_bss && wpa_s->current_bss->anqp) { | |
2228 | struct wpabuf *names = | |
2229 | wpa_s->current_bss->anqp->domain_name; | |
2230 | for (i = 0; names && i < cred->num_domain; i++) | |
2231 | { | |
2232 | if (domain_name_list_contains( | |
2233 | names, cred->domain[i], 1)) | |
2234 | break; | |
2235 | } | |
2236 | if (i == cred->num_domain) | |
2237 | i = 0; /* show first entry by default */ | |
2238 | } | |
2239 | ret = os_snprintf(pos, end - pos, "home_sp=%s\n", | |
2240 | cred->domain[i]); | |
d85e1fc8 | 2241 | if (os_snprintf_error(end - pos, ret)) |
aa26ba68 JM |
2242 | return pos - buf; |
2243 | pos += ret; | |
2244 | ||
2245 | no_domain: | |
e99b4f3a JM |
2246 | if (wpa_s->current_bss == NULL || |
2247 | wpa_s->current_bss->anqp == NULL) | |
2248 | res = -1; | |
2249 | else | |
2250 | res = interworking_home_sp_cred( | |
2251 | wpa_s, cred, | |
2252 | wpa_s->current_bss->anqp->domain_name); | |
2253 | if (res > 0) | |
2254 | type = "home"; | |
2255 | else if (res == 0) | |
2256 | type = "roaming"; | |
2257 | else | |
2258 | type = "unknown"; | |
2259 | ||
2260 | ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type); | |
d85e1fc8 | 2261 | if (os_snprintf_error(end - pos, ret)) |
e99b4f3a JM |
2262 | return pos - buf; |
2263 | pos += ret; | |
2264 | ||
2265 | break; | |
2266 | } | |
2267 | } | |
64855b96 JM |
2268 | #endif /* CONFIG_HS20 */ |
2269 | ||
56586197 JM |
2270 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
2271 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
6fc6879b JM |
2272 | res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, |
2273 | verbose); | |
2274 | if (res >= 0) | |
2275 | pos += res; | |
2276 | } | |
2277 | ||
7508c2ad BA |
2278 | #ifdef CONFIG_MACSEC |
2279 | res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos); | |
2280 | if (res > 0) | |
2281 | pos += res; | |
2282 | #endif /* CONFIG_MACSEC */ | |
2283 | ||
993a8654 JM |
2284 | sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len); |
2285 | if (sess_id) { | |
2286 | char *start = pos; | |
2287 | ||
2288 | ret = os_snprintf(pos, end - pos, "eap_session_id="); | |
2289 | if (os_snprintf_error(end - pos, ret)) | |
2290 | return start - buf; | |
2291 | pos += ret; | |
2292 | ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len); | |
2293 | if (ret <= 0) | |
2294 | return start - buf; | |
2295 | pos += ret; | |
2296 | ret = os_snprintf(pos, end - pos, "\n"); | |
2297 | if (os_snprintf_error(end - pos, ret)) | |
2298 | return start - buf; | |
2299 | pos += ret; | |
2300 | } | |
2301 | ||
6fc6879b JM |
2302 | res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); |
2303 | if (res >= 0) | |
2304 | pos += res; | |
2305 | ||
8aaafcee JM |
2306 | #ifdef CONFIG_WPS |
2307 | { | |
2308 | char uuid_str[100]; | |
2309 | uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str)); | |
2310 | ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str); | |
d85e1fc8 | 2311 | if (os_snprintf_error(end - pos, ret)) |
8aaafcee JM |
2312 | return pos - buf; |
2313 | pos += ret; | |
2314 | } | |
2315 | #endif /* CONFIG_WPS */ | |
2316 | ||
d7f038de BP |
2317 | if (wpa_s->ieee80211ac) { |
2318 | ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n"); | |
2319 | if (os_snprintf_error(end - pos, ret)) | |
2320 | return pos - buf; | |
2321 | pos += ret; | |
2322 | } | |
2323 | ||
f6c2b8c3 | 2324 | #ifdef ANDROID |
a6ab82d7 | 2325 | /* |
2326 | * Allow using the STATUS command with default behavior, say for debug, | |
2327 | * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE | |
2328 | * events with STATUS-NO_EVENTS. | |
2329 | */ | |
2330 | if (os_strcmp(params, "-NO_EVENTS")) { | |
2331 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE | |
2332 | "id=%d state=%d BSSID=" MACSTR " SSID=%s", | |
2333 | wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, | |
2334 | wpa_s->wpa_state, | |
2335 | MAC2STR(wpa_s->bssid), | |
2336 | wpa_s->current_ssid && wpa_s->current_ssid->ssid ? | |
2337 | wpa_ssid_txt(wpa_s->current_ssid->ssid, | |
2338 | wpa_s->current_ssid->ssid_len) : ""); | |
2339 | if (wpa_s->wpa_state == WPA_COMPLETED) { | |
2340 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
2341 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED | |
2342 | "- connection to " MACSTR | |
2343 | " completed %s [id=%d id_str=%s]", | |
2344 | MAC2STR(wpa_s->bssid), "(auth)", | |
2345 | ssid ? ssid->id : -1, | |
2346 | ssid && ssid->id_str ? ssid->id_str : ""); | |
2347 | } | |
f6c2b8c3 DS |
2348 | } |
2349 | #endif /* ANDROID */ | |
2350 | ||
6fc6879b JM |
2351 | return pos - buf; |
2352 | } | |
2353 | ||
2354 | ||
2355 | static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, | |
2356 | char *cmd) | |
2357 | { | |
2358 | char *pos; | |
2359 | int id; | |
2360 | struct wpa_ssid *ssid; | |
2361 | u8 bssid[ETH_ALEN]; | |
2362 | ||
2363 | /* cmd: "<network id> <BSSID>" */ | |
2364 | pos = os_strchr(cmd, ' '); | |
2365 | if (pos == NULL) | |
2366 | return -1; | |
2367 | *pos++ = '\0'; | |
2368 | id = atoi(cmd); | |
2369 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); | |
2370 | if (hwaddr_aton(pos, bssid)) { | |
2371 | wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); | |
2372 | return -1; | |
2373 | } | |
2374 | ||
2375 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
2376 | if (ssid == NULL) { | |
2377 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
2378 | "to update", id); | |
2379 | return -1; | |
2380 | } | |
2381 | ||
2382 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); | |
a8e16edc | 2383 | ssid->bssid_set = !is_zero_ether_addr(bssid); |
6fc6879b JM |
2384 | |
2385 | return 0; | |
2386 | } | |
2387 | ||
2388 | ||
9aa10e2b DS |
2389 | static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s, |
2390 | char *cmd, char *buf, | |
2391 | size_t buflen) | |
2392 | { | |
2393 | u8 bssid[ETH_ALEN]; | |
2394 | struct wpa_blacklist *e; | |
2395 | char *pos, *end; | |
2396 | int ret; | |
2397 | ||
2398 | /* cmd: "BLACKLIST [<BSSID>]" */ | |
2399 | if (*cmd == '\0') { | |
2400 | pos = buf; | |
2401 | end = buf + buflen; | |
2402 | e = wpa_s->blacklist; | |
2403 | while (e) { | |
2404 | ret = os_snprintf(pos, end - pos, MACSTR "\n", | |
2405 | MAC2STR(e->bssid)); | |
d85e1fc8 | 2406 | if (os_snprintf_error(end - pos, ret)) |
9aa10e2b DS |
2407 | return pos - buf; |
2408 | pos += ret; | |
2409 | e = e->next; | |
2410 | } | |
2411 | return pos - buf; | |
2412 | } | |
2413 | ||
2414 | cmd++; | |
2415 | if (os_strncmp(cmd, "clear", 5) == 0) { | |
2416 | wpa_blacklist_clear(wpa_s); | |
2417 | os_memcpy(buf, "OK\n", 3); | |
2418 | return 3; | |
2419 | } | |
2420 | ||
2421 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd); | |
2422 | if (hwaddr_aton(cmd, bssid)) { | |
2423 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd); | |
2424 | return -1; | |
2425 | } | |
2426 | ||
2427 | /* | |
2428 | * Add the BSSID twice, so its count will be 2, causing it to be | |
2429 | * skipped when processing scan results. | |
2430 | */ | |
2431 | ret = wpa_blacklist_add(wpa_s, bssid); | |
bd8838a3 | 2432 | if (ret < 0) |
9aa10e2b DS |
2433 | return -1; |
2434 | ret = wpa_blacklist_add(wpa_s, bssid); | |
bd8838a3 | 2435 | if (ret < 0) |
9aa10e2b DS |
2436 | return -1; |
2437 | os_memcpy(buf, "OK\n", 3); | |
2438 | return 3; | |
2439 | } | |
2440 | ||
2441 | ||
0597a5b5 DS |
2442 | static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s, |
2443 | char *cmd, char *buf, | |
2444 | size_t buflen) | |
2445 | { | |
2446 | char *pos, *end, *stamp; | |
2447 | int ret; | |
2448 | ||
0597a5b5 DS |
2449 | /* cmd: "LOG_LEVEL [<level>]" */ |
2450 | if (*cmd == '\0') { | |
2451 | pos = buf; | |
2452 | end = buf + buflen; | |
2453 | ret = os_snprintf(pos, end - pos, "Current level: %s\n" | |
2454 | "Timestamp: %d\n", | |
2455 | debug_level_str(wpa_debug_level), | |
2456 | wpa_debug_timestamp); | |
d85e1fc8 | 2457 | if (os_snprintf_error(end - pos, ret)) |
0597a5b5 DS |
2458 | ret = 0; |
2459 | ||
2460 | return ret; | |
2461 | } | |
2462 | ||
2463 | while (*cmd == ' ') | |
2464 | cmd++; | |
2465 | ||
2466 | stamp = os_strchr(cmd, ' '); | |
2467 | if (stamp) { | |
2468 | *stamp++ = '\0'; | |
2469 | while (*stamp == ' ') { | |
2470 | stamp++; | |
2471 | } | |
2472 | } | |
2473 | ||
137b2939 | 2474 | if (os_strlen(cmd)) { |
0597a5b5 DS |
2475 | int level = str_to_debug_level(cmd); |
2476 | if (level < 0) | |
2477 | return -1; | |
2478 | wpa_debug_level = level; | |
2479 | } | |
2480 | ||
2481 | if (stamp && os_strlen(stamp)) | |
2482 | wpa_debug_timestamp = atoi(stamp); | |
2483 | ||
2484 | os_memcpy(buf, "OK\n", 3); | |
2485 | return 3; | |
2486 | } | |
2487 | ||
2488 | ||
6fc6879b | 2489 | static int wpa_supplicant_ctrl_iface_list_networks( |
90903a77 | 2490 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
6fc6879b | 2491 | { |
f34891a3 | 2492 | char *pos, *end, *prev; |
6fc6879b JM |
2493 | struct wpa_ssid *ssid; |
2494 | int ret; | |
2495 | ||
2496 | pos = buf; | |
2497 | end = buf + buflen; | |
2498 | ret = os_snprintf(pos, end - pos, | |
2499 | "network id / ssid / bssid / flags\n"); | |
d85e1fc8 | 2500 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2501 | return pos - buf; |
2502 | pos += ret; | |
2503 | ||
2504 | ssid = wpa_s->conf->ssid; | |
90903a77 VD |
2505 | |
2506 | /* skip over ssids until we find next one */ | |
2507 | if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) { | |
2508 | int last_id = atoi(cmd + 8); | |
2509 | if (last_id != -1) { | |
2510 | while (ssid != NULL && ssid->id <= last_id) { | |
2511 | ssid = ssid->next; | |
2512 | } | |
2513 | } | |
2514 | } | |
2515 | ||
6fc6879b | 2516 | while (ssid) { |
f34891a3 | 2517 | prev = pos; |
6fc6879b JM |
2518 | ret = os_snprintf(pos, end - pos, "%d\t%s", |
2519 | ssid->id, | |
2520 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | |
d85e1fc8 | 2521 | if (os_snprintf_error(end - pos, ret)) |
f34891a3 | 2522 | return prev - buf; |
6fc6879b JM |
2523 | pos += ret; |
2524 | if (ssid->bssid_set) { | |
2525 | ret = os_snprintf(pos, end - pos, "\t" MACSTR, | |
2526 | MAC2STR(ssid->bssid)); | |
2527 | } else { | |
2528 | ret = os_snprintf(pos, end - pos, "\tany"); | |
2529 | } | |
d85e1fc8 | 2530 | if (os_snprintf_error(end - pos, ret)) |
f34891a3 | 2531 | return prev - buf; |
6fc6879b | 2532 | pos += ret; |
00e5e3d5 | 2533 | ret = os_snprintf(pos, end - pos, "\t%s%s%s%s", |
6fc6879b JM |
2534 | ssid == wpa_s->current_ssid ? |
2535 | "[CURRENT]" : "", | |
4dac0245 | 2536 | ssid->disabled ? "[DISABLED]" : "", |
00e5e3d5 JM |
2537 | ssid->disabled_until.sec ? |
2538 | "[TEMP-DISABLED]" : "", | |
4dac0245 JM |
2539 | ssid->disabled == 2 ? "[P2P-PERSISTENT]" : |
2540 | ""); | |
d85e1fc8 | 2541 | if (os_snprintf_error(end - pos, ret)) |
f34891a3 | 2542 | return prev - buf; |
6fc6879b JM |
2543 | pos += ret; |
2544 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 2545 | if (os_snprintf_error(end - pos, ret)) |
f34891a3 | 2546 | return prev - buf; |
6fc6879b JM |
2547 | pos += ret; |
2548 | ||
2549 | ssid = ssid->next; | |
2550 | } | |
2551 | ||
2552 | return pos - buf; | |
2553 | } | |
2554 | ||
2555 | ||
2556 | static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) | |
2557 | { | |
0282a8c4 | 2558 | int ret; |
6fc6879b | 2559 | ret = os_snprintf(pos, end - pos, "-"); |
d85e1fc8 | 2560 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2561 | return pos; |
2562 | pos += ret; | |
0282a8c4 JM |
2563 | ret = wpa_write_ciphers(pos, end, cipher, "+"); |
2564 | if (ret < 0) | |
2565 | return pos; | |
2566 | pos += ret; | |
6fc6879b JM |
2567 | return pos; |
2568 | } | |
2569 | ||
2570 | ||
2571 | static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, | |
2572 | const u8 *ie, size_t ie_len) | |
2573 | { | |
2574 | struct wpa_ie_data data; | |
ea3b8c1d JM |
2575 | char *start; |
2576 | int ret; | |
6fc6879b JM |
2577 | |
2578 | ret = os_snprintf(pos, end - pos, "[%s-", proto); | |
d85e1fc8 | 2579 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2580 | return pos; |
2581 | pos += ret; | |
2582 | ||
2583 | if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { | |
2584 | ret = os_snprintf(pos, end - pos, "?]"); | |
d85e1fc8 | 2585 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2586 | return pos; |
2587 | pos += ret; | |
2588 | return pos; | |
2589 | } | |
2590 | ||
ea3b8c1d | 2591 | start = pos; |
6fc6879b | 2592 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { |
ea3b8c1d JM |
2593 | ret = os_snprintf(pos, end - pos, "%sEAP", |
2594 | pos == start ? "" : "+"); | |
d85e1fc8 | 2595 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2596 | return pos; |
2597 | pos += ret; | |
6fc6879b JM |
2598 | } |
2599 | if (data.key_mgmt & WPA_KEY_MGMT_PSK) { | |
ea3b8c1d JM |
2600 | ret = os_snprintf(pos, end - pos, "%sPSK", |
2601 | pos == start ? "" : "+"); | |
d85e1fc8 | 2602 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2603 | return pos; |
2604 | pos += ret; | |
6fc6879b JM |
2605 | } |
2606 | if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { | |
ea3b8c1d JM |
2607 | ret = os_snprintf(pos, end - pos, "%sNone", |
2608 | pos == start ? "" : "+"); | |
d85e1fc8 | 2609 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2610 | return pos; |
2611 | pos += ret; | |
6fc6879b | 2612 | } |
be6b29f6 JA |
2613 | if (data.key_mgmt & WPA_KEY_MGMT_SAE) { |
2614 | ret = os_snprintf(pos, end - pos, "%sSAE", | |
2615 | pos == start ? "" : "+"); | |
d85e1fc8 | 2616 | if (os_snprintf_error(end - pos, ret)) |
be6b29f6 JA |
2617 | return pos; |
2618 | pos += ret; | |
2619 | } | |
6fc6879b JM |
2620 | #ifdef CONFIG_IEEE80211R |
2621 | if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { | |
2622 | ret = os_snprintf(pos, end - pos, "%sFT/EAP", | |
ea3b8c1d | 2623 | pos == start ? "" : "+"); |
d85e1fc8 | 2624 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2625 | return pos; |
2626 | pos += ret; | |
6fc6879b JM |
2627 | } |
2628 | if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { | |
2629 | ret = os_snprintf(pos, end - pos, "%sFT/PSK", | |
ea3b8c1d | 2630 | pos == start ? "" : "+"); |
d85e1fc8 | 2631 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2632 | return pos; |
2633 | pos += ret; | |
6fc6879b | 2634 | } |
be6b29f6 JA |
2635 | if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) { |
2636 | ret = os_snprintf(pos, end - pos, "%sFT/SAE", | |
2637 | pos == start ? "" : "+"); | |
d85e1fc8 | 2638 | if (os_snprintf_error(end - pos, ret)) |
be6b29f6 JA |
2639 | return pos; |
2640 | pos += ret; | |
2641 | } | |
6fc6879b | 2642 | #endif /* CONFIG_IEEE80211R */ |
56586197 JM |
2643 | #ifdef CONFIG_IEEE80211W |
2644 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { | |
2645 | ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", | |
ea3b8c1d | 2646 | pos == start ? "" : "+"); |
d85e1fc8 | 2647 | if (os_snprintf_error(end - pos, ret)) |
56586197 JM |
2648 | return pos; |
2649 | pos += ret; | |
56586197 JM |
2650 | } |
2651 | if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { | |
2652 | ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", | |
ea3b8c1d | 2653 | pos == start ? "" : "+"); |
d85e1fc8 | 2654 | if (os_snprintf_error(end - pos, ret)) |
56586197 JM |
2655 | return pos; |
2656 | pos += ret; | |
56586197 JM |
2657 | } |
2658 | #endif /* CONFIG_IEEE80211W */ | |
6fc6879b | 2659 | |
5e3b5197 | 2660 | #ifdef CONFIG_SUITEB |
666497c8 JM |
2661 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
2662 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B", | |
2663 | pos == start ? "" : "+"); | |
d85e1fc8 | 2664 | if (os_snprintf_error(end - pos, ret)) |
666497c8 JM |
2665 | return pos; |
2666 | pos += ret; | |
2667 | } | |
5e3b5197 JM |
2668 | #endif /* CONFIG_SUITEB */ |
2669 | ||
2670 | #ifdef CONFIG_SUITEB192 | |
2671 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { | |
2672 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192", | |
2673 | pos == start ? "" : "+"); | |
2674 | if (os_snprintf_error(end - pos, ret)) | |
2675 | return pos; | |
2676 | pos += ret; | |
2677 | } | |
2678 | #endif /* CONFIG_SUITEB192 */ | |
666497c8 | 2679 | |
7147a834 JM |
2680 | #ifdef CONFIG_FILS |
2681 | if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) { | |
2682 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA256", | |
2683 | pos == start ? "" : "+"); | |
2684 | if (os_snprintf_error(end - pos, ret)) | |
2685 | return pos; | |
2686 | pos += ret; | |
2687 | } | |
2688 | if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) { | |
2689 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA384", | |
2690 | pos == start ? "" : "+"); | |
2691 | if (os_snprintf_error(end - pos, ret)) | |
2692 | return pos; | |
2693 | pos += ret; | |
2694 | } | |
2695 | #ifdef CONFIG_IEEE80211R | |
2696 | if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) { | |
2697 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256", | |
2698 | pos == start ? "" : "+"); | |
2699 | if (os_snprintf_error(end - pos, ret)) | |
2700 | return pos; | |
2701 | pos += ret; | |
2702 | } | |
2703 | if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) { | |
2704 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384", | |
2705 | pos == start ? "" : "+"); | |
2706 | if (os_snprintf_error(end - pos, ret)) | |
2707 | return pos; | |
2708 | pos += ret; | |
2709 | } | |
2710 | #endif /* CONFIG_IEEE80211R */ | |
2711 | #endif /* CONFIG_FILS */ | |
2712 | ||
a1ea1b45 JM |
2713 | #ifdef CONFIG_OWE |
2714 | if (data.key_mgmt & WPA_KEY_MGMT_OWE) { | |
2715 | ret = os_snprintf(pos, end - pos, "%sOWE", | |
2716 | pos == start ? "" : "+"); | |
2717 | if (os_snprintf_error(end - pos, ret)) | |
2718 | return pos; | |
2719 | pos += ret; | |
2720 | } | |
2721 | #endif /* CONFIG_OWE */ | |
2722 | ||
567da5bb JM |
2723 | #ifdef CONFIG_DPP |
2724 | if (data.key_mgmt & WPA_KEY_MGMT_DPP) { | |
2725 | ret = os_snprintf(pos, end - pos, "%sDPP", | |
2726 | pos == start ? "" : "+"); | |
2727 | if (os_snprintf_error(end - pos, ret)) | |
2728 | return pos; | |
2729 | pos += ret; | |
2730 | } | |
2731 | #endif /* CONFIG_DPP */ | |
2732 | ||
0f8385e6 BG |
2733 | if (data.key_mgmt & WPA_KEY_MGMT_OSEN) { |
2734 | ret = os_snprintf(pos, end - pos, "%sOSEN", | |
2735 | pos == start ? "" : "+"); | |
2736 | if (os_snprintf_error(end - pos, ret)) | |
2737 | return pos; | |
2738 | pos += ret; | |
2739 | } | |
2740 | ||
6fc6879b JM |
2741 | pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); |
2742 | ||
2743 | if (data.capabilities & WPA_CAPABILITY_PREAUTH) { | |
2744 | ret = os_snprintf(pos, end - pos, "-preauth"); | |
d85e1fc8 | 2745 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2746 | return pos; |
2747 | pos += ret; | |
2748 | } | |
2749 | ||
2750 | ret = os_snprintf(pos, end - pos, "]"); | |
d85e1fc8 | 2751 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2752 | return pos; |
2753 | pos += ret; | |
2754 | ||
2755 | return pos; | |
2756 | } | |
2757 | ||
3a068632 | 2758 | |
eef7d7a1 | 2759 | #ifdef CONFIG_WPS |
31fcea93 JM |
2760 | static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, |
2761 | char *pos, char *end, | |
3a068632 JM |
2762 | struct wpabuf *wps_ie) |
2763 | { | |
eef7d7a1 JM |
2764 | int ret; |
2765 | const char *txt; | |
2766 | ||
eef7d7a1 JM |
2767 | if (wps_ie == NULL) |
2768 | return pos; | |
eef7d7a1 JM |
2769 | if (wps_is_selected_pbc_registrar(wps_ie)) |
2770 | txt = "[WPS-PBC]"; | |
31fcea93 JM |
2771 | else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) |
2772 | txt = "[WPS-AUTH]"; | |
eef7d7a1 JM |
2773 | else if (wps_is_selected_pin_registrar(wps_ie)) |
2774 | txt = "[WPS-PIN]"; | |
2775 | else | |
2776 | txt = "[WPS]"; | |
2777 | ||
2778 | ret = os_snprintf(pos, end - pos, "%s", txt); | |
a80ba67a | 2779 | if (!os_snprintf_error(end - pos, ret)) |
eef7d7a1 JM |
2780 | pos += ret; |
2781 | wpabuf_free(wps_ie); | |
3a068632 JM |
2782 | return pos; |
2783 | } | |
2784 | #endif /* CONFIG_WPS */ | |
2785 | ||
2786 | ||
31fcea93 JM |
2787 | static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, |
2788 | char *pos, char *end, | |
16b71ac2 | 2789 | const struct wpa_bss *bss) |
3a068632 JM |
2790 | { |
2791 | #ifdef CONFIG_WPS | |
2792 | struct wpabuf *wps_ie; | |
2793 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); | |
31fcea93 | 2794 | return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); |
3a068632 | 2795 | #else /* CONFIG_WPS */ |
eef7d7a1 | 2796 | return pos; |
3a068632 | 2797 | #endif /* CONFIG_WPS */ |
eef7d7a1 JM |
2798 | } |
2799 | ||
6fc6879b JM |
2800 | |
2801 | /* Format one result on one text line into a buffer. */ | |
2802 | static int wpa_supplicant_ctrl_iface_scan_result( | |
31fcea93 | 2803 | struct wpa_supplicant *wpa_s, |
16b71ac2 | 2804 | const struct wpa_bss *bss, char *buf, size_t buflen) |
6fc6879b JM |
2805 | { |
2806 | char *pos, *end; | |
2807 | int ret; | |
e8b96490 | 2808 | const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe; |
0c6b310e | 2809 | |
638d9456 | 2810 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
0c6b310e | 2811 | p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); |
bb50ae43 JM |
2812 | if (!p2p) |
2813 | p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE); | |
0c6b310e JM |
2814 | if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && |
2815 | os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == | |
2816 | 0) | |
2817 | return 0; /* Do not show P2P listen discovery results here */ | |
6fc6879b JM |
2818 | |
2819 | pos = buf; | |
2820 | end = buf + buflen; | |
2821 | ||
2822 | ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", | |
16b71ac2 | 2823 | MAC2STR(bss->bssid), bss->freq, bss->level); |
d85e1fc8 | 2824 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2825 | return -1; |
6fc6879b | 2826 | pos += ret; |
16b71ac2 | 2827 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
6fc6879b JM |
2828 | if (ie) |
2829 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); | |
16b71ac2 | 2830 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
638d9456 JA |
2831 | if (ie2) { |
2832 | pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2", | |
2833 | ie2, 2 + ie2[1]); | |
2834 | } | |
0f8385e6 BG |
2835 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
2836 | if (osen_ie) | |
2837 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", | |
2838 | osen_ie, 2 + osen_ie[1]); | |
e8b96490 JM |
2839 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
2840 | if (owe) { | |
2841 | ret = os_snprintf(pos, end - pos, | |
2842 | ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]"); | |
2843 | if (os_snprintf_error(end - pos, ret)) | |
2844 | return -1; | |
2845 | pos += ret; | |
2846 | } | |
31fcea93 | 2847 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
0f8385e6 | 2848 | if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) { |
6fc6879b | 2849 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
d85e1fc8 | 2850 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2851 | return -1; |
6fc6879b JM |
2852 | pos += ret; |
2853 | } | |
638d9456 JA |
2854 | if (mesh) { |
2855 | ret = os_snprintf(pos, end - pos, "[MESH]"); | |
d85e1fc8 | 2856 | if (os_snprintf_error(end - pos, ret)) |
638d9456 JA |
2857 | return -1; |
2858 | pos += ret; | |
2859 | } | |
e403ba85 BS |
2860 | if (bss_is_dmg(bss)) { |
2861 | const char *s; | |
2862 | ret = os_snprintf(pos, end - pos, "[DMG]"); | |
d85e1fc8 | 2863 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2864 | return -1; |
6fc6879b | 2865 | pos += ret; |
e403ba85 BS |
2866 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
2867 | case IEEE80211_CAP_DMG_IBSS: | |
2868 | s = "[IBSS]"; | |
2869 | break; | |
2870 | case IEEE80211_CAP_DMG_AP: | |
2871 | s = "[ESS]"; | |
2872 | break; | |
2873 | case IEEE80211_CAP_DMG_PBSS: | |
2874 | s = "[PBSS]"; | |
2875 | break; | |
2876 | default: | |
2877 | s = ""; | |
2878 | break; | |
2879 | } | |
2880 | ret = os_snprintf(pos, end - pos, "%s", s); | |
d85e1fc8 | 2881 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2882 | return -1; |
bd1af96a | 2883 | pos += ret; |
e403ba85 BS |
2884 | } else { |
2885 | if (bss->caps & IEEE80211_CAP_IBSS) { | |
2886 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | |
d85e1fc8 | 2887 | if (os_snprintf_error(end - pos, ret)) |
e403ba85 BS |
2888 | return -1; |
2889 | pos += ret; | |
2890 | } | |
2891 | if (bss->caps & IEEE80211_CAP_ESS) { | |
2892 | ret = os_snprintf(pos, end - pos, "[ESS]"); | |
d85e1fc8 | 2893 | if (os_snprintf_error(end - pos, ret)) |
e403ba85 BS |
2894 | return -1; |
2895 | pos += ret; | |
2896 | } | |
bd1af96a | 2897 | } |
0c6b310e JM |
2898 | if (p2p) { |
2899 | ret = os_snprintf(pos, end - pos, "[P2P]"); | |
d85e1fc8 | 2900 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2901 | return -1; |
0c6b310e JM |
2902 | pos += ret; |
2903 | } | |
64855b96 | 2904 | #ifdef CONFIG_HS20 |
4ed34f5a | 2905 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) { |
64855b96 | 2906 | ret = os_snprintf(pos, end - pos, "[HS20]"); |
d85e1fc8 | 2907 | if (os_snprintf_error(end - pos, ret)) |
64855b96 JM |
2908 | return -1; |
2909 | pos += ret; | |
2910 | } | |
2911 | #endif /* CONFIG_HS20 */ | |
7147a834 JM |
2912 | #ifdef CONFIG_FILS |
2913 | if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) { | |
2914 | ret = os_snprintf(pos, end - pos, "[FILS]"); | |
2915 | if (os_snprintf_error(end - pos, ret)) | |
2916 | return -1; | |
2917 | pos += ret; | |
2918 | } | |
2919 | #endif /* CONFIG_FILS */ | |
55de4d4b AN |
2920 | #ifdef CONFIG_FST |
2921 | if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) { | |
2922 | ret = os_snprintf(pos, end - pos, "[FST]"); | |
2923 | if (os_snprintf_error(end - pos, ret)) | |
2924 | return -1; | |
2925 | pos += ret; | |
2926 | } | |
2927 | #endif /* CONFIG_FST */ | |
ed87f6a8 | 2928 | if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) { |
1f2c42cc JW |
2929 | ret = os_snprintf(pos, end - pos, "[UTF-8]"); |
2930 | if (os_snprintf_error(end - pos, ret)) | |
2931 | return -1; | |
2932 | pos += ret; | |
2933 | } | |
6fc6879b | 2934 | |
6fc6879b | 2935 | ret = os_snprintf(pos, end - pos, "\t%s", |
16b71ac2 | 2936 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
d85e1fc8 | 2937 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2938 | return -1; |
6fc6879b JM |
2939 | pos += ret; |
2940 | ||
2941 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 2942 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2943 | return -1; |
6fc6879b JM |
2944 | pos += ret; |
2945 | ||
2946 | return pos - buf; | |
2947 | } | |
2948 | ||
2949 | ||
2950 | static int wpa_supplicant_ctrl_iface_scan_results( | |
2951 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
2952 | { | |
2953 | char *pos, *end; | |
16b71ac2 | 2954 | struct wpa_bss *bss; |
6fc6879b | 2955 | int ret; |
6fc6879b JM |
2956 | |
2957 | pos = buf; | |
2958 | end = buf + buflen; | |
2959 | ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " | |
2960 | "flags / ssid\n"); | |
d85e1fc8 | 2961 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2962 | return pos - buf; |
2963 | pos += ret; | |
2964 | ||
16b71ac2 | 2965 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
31fcea93 | 2966 | ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, |
6fc6879b JM |
2967 | end - pos); |
2968 | if (ret < 0 || ret >= end - pos) | |
2969 | return pos - buf; | |
2970 | pos += ret; | |
2971 | } | |
2972 | ||
2973 | return pos - buf; | |
2974 | } | |
2975 | ||
2976 | ||
603a3f34 JL |
2977 | #ifdef CONFIG_MESH |
2978 | ||
5b78493f MH |
2979 | static int wpa_supplicant_ctrl_iface_mesh_interface_add( |
2980 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
2981 | { | |
2982 | char *pos, ifname[IFNAMSIZ + 1]; | |
2983 | ||
2984 | ifname[0] = '\0'; | |
2985 | ||
2986 | pos = os_strstr(cmd, "ifname="); | |
2987 | if (pos) { | |
2988 | pos += 7; | |
2989 | os_strlcpy(ifname, pos, sizeof(ifname)); | |
2990 | } | |
2991 | ||
2992 | if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0) | |
2993 | return -1; | |
2994 | ||
2995 | os_strlcpy(reply, ifname, max_len); | |
2996 | return os_strlen(ifname); | |
2997 | } | |
2998 | ||
2999 | ||
603a3f34 JL |
3000 | static int wpa_supplicant_ctrl_iface_mesh_group_add( |
3001 | struct wpa_supplicant *wpa_s, char *cmd) | |
3002 | { | |
3003 | int id; | |
3004 | struct wpa_ssid *ssid; | |
3005 | ||
3006 | id = atoi(cmd); | |
3007 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id); | |
3008 | ||
3009 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
3010 | if (ssid == NULL) { | |
3011 | wpa_printf(MSG_DEBUG, | |
3012 | "CTRL_IFACE: Could not find network id=%d", id); | |
3013 | return -1; | |
3014 | } | |
3015 | if (ssid->mode != WPAS_MODE_MESH) { | |
3016 | wpa_printf(MSG_DEBUG, | |
3017 | "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network"); | |
3018 | return -1; | |
3019 | } | |
0c6099f3 MH |
3020 | if (ssid->key_mgmt != WPA_KEY_MGMT_NONE && |
3021 | ssid->key_mgmt != WPA_KEY_MGMT_SAE) { | |
3022 | wpa_printf(MSG_ERROR, | |
3023 | "CTRL_IFACE: key_mgmt for mesh network should be open or SAE"); | |
3024 | return -1; | |
3025 | } | |
603a3f34 JL |
3026 | |
3027 | /* | |
3028 | * TODO: If necessary write our own group_add function, | |
3029 | * for now we can reuse select_network | |
3030 | */ | |
3031 | wpa_supplicant_select_network(wpa_s, ssid); | |
3032 | ||
3033 | return 0; | |
3034 | } | |
3035 | ||
3036 | ||
3037 | static int wpa_supplicant_ctrl_iface_mesh_group_remove( | |
3038 | struct wpa_supplicant *wpa_s, char *cmd) | |
3039 | { | |
5b78493f MH |
3040 | struct wpa_supplicant *orig; |
3041 | struct wpa_global *global; | |
3042 | int found = 0; | |
3043 | ||
3044 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd); | |
3045 | ||
3046 | global = wpa_s->global; | |
3047 | orig = wpa_s; | |
3048 | ||
3049 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
3050 | if (os_strcmp(wpa_s->ifname, cmd) == 0) { | |
3051 | found = 1; | |
3052 | break; | |
3053 | } | |
3054 | } | |
3055 | if (!found) { | |
3056 | wpa_printf(MSG_ERROR, | |
3057 | "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found", | |
603a3f34 JL |
3058 | cmd); |
3059 | return -1; | |
3060 | } | |
5b78493f MH |
3061 | if (wpa_s->mesh_if_created && wpa_s == orig) { |
3062 | wpa_printf(MSG_ERROR, | |
3063 | "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself"); | |
3064 | return -1; | |
3065 | } | |
603a3f34 JL |
3066 | |
3067 | wpa_s->reassociate = 0; | |
3068 | wpa_s->disconnected = 1; | |
3069 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
3070 | wpa_supplicant_cancel_scan(wpa_s); | |
3071 | ||
3072 | /* | |
3073 | * TODO: If necessary write our own group_remove function, | |
3074 | * for now we can reuse deauthenticate | |
3075 | */ | |
3076 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
3077 | ||
5b78493f MH |
3078 | if (wpa_s->mesh_if_created) |
3079 | wpa_supplicant_remove_iface(global, wpa_s, 0); | |
3080 | ||
603a3f34 JL |
3081 | return 0; |
3082 | } | |
3083 | ||
e174ef34 MH |
3084 | |
3085 | static int wpa_supplicant_ctrl_iface_mesh_peer_remove( | |
3086 | struct wpa_supplicant *wpa_s, char *cmd) | |
3087 | { | |
3088 | u8 addr[ETH_ALEN]; | |
3089 | ||
3090 | if (hwaddr_aton(cmd, addr) < 0) | |
3091 | return -1; | |
3092 | ||
3093 | return wpas_mesh_peer_remove(wpa_s, addr); | |
3094 | } | |
3095 | ||
2604edbf MH |
3096 | |
3097 | static int wpa_supplicant_ctrl_iface_mesh_peer_add( | |
3098 | struct wpa_supplicant *wpa_s, char *cmd) | |
3099 | { | |
3100 | u8 addr[ETH_ALEN]; | |
9f2cf23e MH |
3101 | int duration; |
3102 | char *pos; | |
3103 | ||
3104 | pos = os_strstr(cmd, " duration="); | |
3105 | if (pos) { | |
3106 | *pos = '\0'; | |
3107 | duration = atoi(pos + 10); | |
3108 | } else { | |
3109 | duration = -1; | |
3110 | } | |
2604edbf MH |
3111 | |
3112 | if (hwaddr_aton(cmd, addr)) | |
3113 | return -1; | |
3114 | ||
9f2cf23e | 3115 | return wpas_mesh_peer_add(wpa_s, addr, duration); |
2604edbf MH |
3116 | } |
3117 | ||
603a3f34 JL |
3118 | #endif /* CONFIG_MESH */ |
3119 | ||
3120 | ||
6fc6879b JM |
3121 | static int wpa_supplicant_ctrl_iface_select_network( |
3122 | struct wpa_supplicant *wpa_s, char *cmd) | |
3123 | { | |
3124 | int id; | |
3125 | struct wpa_ssid *ssid; | |
204c9ac4 | 3126 | char *pos; |
6fc6879b JM |
3127 | |
3128 | /* cmd: "<network id>" or "any" */ | |
204c9ac4 | 3129 | if (os_strncmp(cmd, "any", 3) == 0) { |
6fc6879b | 3130 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); |
86b89452 WS |
3131 | ssid = NULL; |
3132 | } else { | |
3133 | id = atoi(cmd); | |
3134 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); | |
6fc6879b | 3135 | |
86b89452 WS |
3136 | ssid = wpa_config_get_network(wpa_s->conf, id); |
3137 | if (ssid == NULL) { | |
3138 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
3139 | "network id=%d", id); | |
3140 | return -1; | |
3141 | } | |
4dac0245 JM |
3142 | if (ssid->disabled == 2) { |
3143 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
3144 | "SELECT_NETWORK with persistent P2P group"); | |
3145 | return -1; | |
3146 | } | |
6fc6879b JM |
3147 | } |
3148 | ||
204c9ac4 DS |
3149 | pos = os_strstr(cmd, " freq="); |
3150 | if (pos) { | |
3151 | int *freqs = freq_range_to_channel_list(wpa_s, pos + 6); | |
3152 | if (freqs) { | |
88a44755 JM |
3153 | os_free(wpa_s->select_network_scan_freqs); |
3154 | wpa_s->select_network_scan_freqs = freqs; | |
204c9ac4 DS |
3155 | } |
3156 | } | |
3157 | ||
dfaf11d6 JM |
3158 | wpa_s->scan_min_time.sec = 0; |
3159 | wpa_s->scan_min_time.usec = 0; | |
86b89452 | 3160 | wpa_supplicant_select_network(wpa_s, ssid); |
6fc6879b JM |
3161 | |
3162 | return 0; | |
3163 | } | |
3164 | ||
3165 | ||
3166 | static int wpa_supplicant_ctrl_iface_enable_network( | |
3167 | struct wpa_supplicant *wpa_s, char *cmd) | |
3168 | { | |
3169 | int id; | |
3170 | struct wpa_ssid *ssid; | |
3171 | ||
3172 | /* cmd: "<network id>" or "all" */ | |
3173 | if (os_strcmp(cmd, "all") == 0) { | |
3174 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); | |
86b89452 WS |
3175 | ssid = NULL; |
3176 | } else { | |
3177 | id = atoi(cmd); | |
3178 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); | |
6fc6879b | 3179 | |
86b89452 WS |
3180 | ssid = wpa_config_get_network(wpa_s->conf, id); |
3181 | if (ssid == NULL) { | |
3182 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
3183 | "network id=%d", id); | |
3184 | return -1; | |
3185 | } | |
4dac0245 JM |
3186 | if (ssid->disabled == 2) { |
3187 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
3188 | "ENABLE_NETWORK with persistent P2P group"); | |
3189 | return -1; | |
3190 | } | |
84c78f95 JM |
3191 | |
3192 | if (os_strstr(cmd, " no-connect")) { | |
3193 | ssid->disabled = 0; | |
3194 | return 0; | |
3195 | } | |
6fc6879b | 3196 | } |
dfaf11d6 JM |
3197 | wpa_s->scan_min_time.sec = 0; |
3198 | wpa_s->scan_min_time.usec = 0; | |
86b89452 | 3199 | wpa_supplicant_enable_network(wpa_s, ssid); |
6fc6879b JM |
3200 | |
3201 | return 0; | |
3202 | } | |
3203 | ||
3204 | ||
3205 | static int wpa_supplicant_ctrl_iface_disable_network( | |
3206 | struct wpa_supplicant *wpa_s, char *cmd) | |
3207 | { | |
3208 | int id; | |
3209 | struct wpa_ssid *ssid; | |
3210 | ||
3211 | /* cmd: "<network id>" or "all" */ | |
3212 | if (os_strcmp(cmd, "all") == 0) { | |
3213 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); | |
86b89452 WS |
3214 | ssid = NULL; |
3215 | } else { | |
3216 | id = atoi(cmd); | |
3217 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); | |
6fc6879b | 3218 | |
86b89452 WS |
3219 | ssid = wpa_config_get_network(wpa_s->conf, id); |
3220 | if (ssid == NULL) { | |
3221 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
3222 | "network id=%d", id); | |
3223 | return -1; | |
3224 | } | |
4dac0245 JM |
3225 | if (ssid->disabled == 2) { |
3226 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
3227 | "DISABLE_NETWORK with persistent P2P " | |
3228 | "group"); | |
3229 | return -1; | |
3230 | } | |
6fc6879b | 3231 | } |
86b89452 | 3232 | wpa_supplicant_disable_network(wpa_s, ssid); |
6fc6879b JM |
3233 | |
3234 | return 0; | |
3235 | } | |
3236 | ||
3237 | ||
3238 | static int wpa_supplicant_ctrl_iface_add_network( | |
3239 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
3240 | { | |
3241 | struct wpa_ssid *ssid; | |
3242 | int ret; | |
3243 | ||
3244 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); | |
3245 | ||
d015bb05 | 3246 | ssid = wpa_supplicant_add_network(wpa_s); |
6fc6879b JM |
3247 | if (ssid == NULL) |
3248 | return -1; | |
8bac466b | 3249 | |
6fc6879b | 3250 | ret = os_snprintf(buf, buflen, "%d\n", ssid->id); |
d85e1fc8 | 3251 | if (os_snprintf_error(buflen, ret)) |
6fc6879b JM |
3252 | return -1; |
3253 | return ret; | |
3254 | } | |
3255 | ||
3256 | ||
3257 | static int wpa_supplicant_ctrl_iface_remove_network( | |
3258 | struct wpa_supplicant *wpa_s, char *cmd) | |
3259 | { | |
3260 | int id; | |
3261 | struct wpa_ssid *ssid; | |
d015bb05 | 3262 | int result; |
6fc6879b JM |
3263 | |
3264 | /* cmd: "<network id>" or "all" */ | |
3265 | if (os_strcmp(cmd, "all") == 0) { | |
3266 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); | |
725fc39e DS |
3267 | if (wpa_s->sched_scanning) |
3268 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
3269 | ||
d8a790b9 | 3270 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
6fc6879b | 3271 | if (wpa_s->current_ssid) { |
83df8149 JM |
3272 | #ifdef CONFIG_SME |
3273 | wpa_s->sme.prev_bssid_set = 0; | |
3274 | #endif /* CONFIG_SME */ | |
20a0b03d JM |
3275 | wpa_sm_set_config(wpa_s->wpa, NULL); |
3276 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | |
e66bcedd JM |
3277 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
3278 | wpa_s->own_disconnect_req = 1; | |
07783eaa JM |
3279 | wpa_supplicant_deauthenticate( |
3280 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
6fc6879b | 3281 | } |
391f4925 JK |
3282 | ssid = wpa_s->conf->ssid; |
3283 | while (ssid) { | |
3284 | struct wpa_ssid *remove_ssid = ssid; | |
3285 | id = ssid->id; | |
3286 | ssid = ssid->next; | |
c267753b JM |
3287 | if (wpa_s->last_ssid == remove_ssid) |
3288 | wpa_s->last_ssid = NULL; | |
391f4925 JK |
3289 | wpas_notify_network_removed(wpa_s, remove_ssid); |
3290 | wpa_config_remove_network(wpa_s->conf, id); | |
3291 | } | |
6fc6879b JM |
3292 | return 0; |
3293 | } | |
3294 | ||
3295 | id = atoi(cmd); | |
3296 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); | |
3297 | ||
d015bb05 RP |
3298 | result = wpa_supplicant_remove_network(wpa_s, id); |
3299 | if (result == -1) { | |
6fc6879b JM |
3300 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
3301 | "id=%d", id); | |
3302 | return -1; | |
3303 | } | |
d015bb05 | 3304 | if (result == -2) { |
59ff6653 DG |
3305 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the " |
3306 | "network id=%d", id); | |
3307 | return -1; | |
3308 | } | |
6fc6879b JM |
3309 | return 0; |
3310 | } | |
3311 | ||
3312 | ||
1c330a2f DS |
3313 | static int wpa_supplicant_ctrl_iface_update_network( |
3314 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, | |
3315 | char *name, char *value) | |
3316 | { | |
5cd317d3 BKB |
3317 | int ret; |
3318 | ||
3319 | ret = wpa_config_set(ssid, name, value, 0); | |
3320 | if (ret < 0) { | |
1c330a2f DS |
3321 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " |
3322 | "variable '%s'", name); | |
3323 | return -1; | |
3324 | } | |
5cd317d3 BKB |
3325 | if (ret == 1) |
3326 | return 0; /* No change to the previously configured value */ | |
1c330a2f DS |
3327 | |
3328 | if (os_strcmp(name, "bssid") != 0 && | |
34ee12c5 | 3329 | os_strcmp(name, "bssid_hint") != 0 && |
c3dc68e8 | 3330 | os_strcmp(name, "priority") != 0) { |
1c330a2f DS |
3331 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
3332 | ||
c3dc68e8 JM |
3333 | if (wpa_s->current_ssid == ssid || |
3334 | wpa_s->current_ssid == NULL) { | |
3335 | /* | |
3336 | * Invalidate the EAP session cache if anything in the | |
3337 | * current or previously used configuration changes. | |
3338 | */ | |
3339 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
3340 | } | |
1c330a2f DS |
3341 | } |
3342 | ||
3343 | if ((os_strcmp(name, "psk") == 0 && | |
3344 | value[0] == '"' && ssid->ssid_len) || | |
3345 | (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) | |
3346 | wpa_config_update_psk(ssid); | |
3347 | else if (os_strcmp(name, "priority") == 0) | |
3348 | wpa_config_update_prio_list(wpa_s->conf); | |
3349 | ||
3350 | return 0; | |
3351 | } | |
3352 | ||
3353 | ||
6fc6879b JM |
3354 | static int wpa_supplicant_ctrl_iface_set_network( |
3355 | struct wpa_supplicant *wpa_s, char *cmd) | |
3356 | { | |
1e529832 | 3357 | int id, ret, prev_bssid_set, prev_disabled; |
6fc6879b JM |
3358 | struct wpa_ssid *ssid; |
3359 | char *name, *value; | |
0ef023e4 | 3360 | u8 prev_bssid[ETH_ALEN]; |
6fc6879b JM |
3361 | |
3362 | /* cmd: "<network id> <variable name> <value>" */ | |
3363 | name = os_strchr(cmd, ' '); | |
3364 | if (name == NULL) | |
3365 | return -1; | |
3366 | *name++ = '\0'; | |
3367 | ||
3368 | value = os_strchr(name, ' '); | |
3369 | if (value == NULL) | |
3370 | return -1; | |
3371 | *value++ = '\0'; | |
3372 | ||
3373 | id = atoi(cmd); | |
3374 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", | |
3375 | id, name); | |
3376 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
3377 | (u8 *) value, os_strlen(value)); | |
3378 | ||
3379 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
3380 | if (ssid == NULL) { | |
3381 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | |
3382 | "id=%d", id); | |
3383 | return -1; | |
3384 | } | |
3385 | ||
0ef023e4 | 3386 | prev_bssid_set = ssid->bssid_set; |
1e529832 | 3387 | prev_disabled = ssid->disabled; |
0ef023e4 JM |
3388 | os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN); |
3389 | ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name, | |
3390 | value); | |
3391 | if (ret == 0 && | |
3392 | (ssid->bssid_set != prev_bssid_set || | |
3393 | os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0)) | |
3394 | wpas_notify_network_bssid_set_changed(wpa_s, ssid); | |
1e529832 JM |
3395 | |
3396 | if (prev_disabled != ssid->disabled && | |
3397 | (prev_disabled == 2 || ssid->disabled == 2)) | |
3398 | wpas_notify_network_type_changed(wpa_s, ssid); | |
3399 | ||
0ef023e4 | 3400 | return ret; |
6fc6879b JM |
3401 | } |
3402 | ||
3403 | ||
3404 | static int wpa_supplicant_ctrl_iface_get_network( | |
3405 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
3406 | { | |
3407 | int id; | |
3408 | size_t res; | |
3409 | struct wpa_ssid *ssid; | |
3410 | char *name, *value; | |
3411 | ||
3412 | /* cmd: "<network id> <variable name>" */ | |
3413 | name = os_strchr(cmd, ' '); | |
3414 | if (name == NULL || buflen == 0) | |
3415 | return -1; | |
3416 | *name++ = '\0'; | |
3417 | ||
3418 | id = atoi(cmd); | |
8db9a79d | 3419 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'", |
6fc6879b JM |
3420 | id, name); |
3421 | ||
3422 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
3423 | if (ssid == NULL) { | |
8db9a79d | 3424 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network " |
6fc6879b JM |
3425 | "id=%d", id); |
3426 | return -1; | |
3427 | } | |
3428 | ||
3429 | value = wpa_config_get_no_key(ssid, name); | |
3430 | if (value == NULL) { | |
8db9a79d | 3431 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network " |
6fc6879b JM |
3432 | "variable '%s'", name); |
3433 | return -1; | |
3434 | } | |
3435 | ||
3436 | res = os_strlcpy(buf, value, buflen); | |
3437 | if (res >= buflen) { | |
3438 | os_free(value); | |
3439 | return -1; | |
3440 | } | |
3441 | ||
3442 | os_free(value); | |
3443 | ||
3444 | return res; | |
3445 | } | |
3446 | ||
3447 | ||
1c330a2f | 3448 | static int wpa_supplicant_ctrl_iface_dup_network( |
daae4995 AN |
3449 | struct wpa_supplicant *wpa_s, char *cmd, |
3450 | struct wpa_supplicant *dst_wpa_s) | |
1c330a2f DS |
3451 | { |
3452 | struct wpa_ssid *ssid_s, *ssid_d; | |
3453 | char *name, *id, *value; | |
3454 | int id_s, id_d, ret; | |
3455 | ||
3456 | /* cmd: "<src network id> <dst network id> <variable name>" */ | |
3457 | id = os_strchr(cmd, ' '); | |
3458 | if (id == NULL) | |
3459 | return -1; | |
3460 | *id++ = '\0'; | |
3461 | ||
3462 | name = os_strchr(id, ' '); | |
3463 | if (name == NULL) | |
3464 | return -1; | |
3465 | *name++ = '\0'; | |
3466 | ||
3467 | id_s = atoi(cmd); | |
3468 | id_d = atoi(id); | |
daae4995 AN |
3469 | |
3470 | wpa_printf(MSG_DEBUG, | |
3471 | "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'", | |
3472 | wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name); | |
1c330a2f DS |
3473 | |
3474 | ssid_s = wpa_config_get_network(wpa_s->conf, id_s); | |
3475 | if (ssid_s == NULL) { | |
3476 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
3477 | "network id=%d", id_s); | |
3478 | return -1; | |
3479 | } | |
3480 | ||
daae4995 | 3481 | ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d); |
1c330a2f DS |
3482 | if (ssid_d == NULL) { |
3483 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
c0541906 | 3484 | "network id=%d", id_d); |
1c330a2f DS |
3485 | return -1; |
3486 | } | |
3487 | ||
3488 | value = wpa_config_get(ssid_s, name); | |
3489 | if (value == NULL) { | |
3490 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " | |
3491 | "variable '%s'", name); | |
3492 | return -1; | |
3493 | } | |
3494 | ||
daae4995 | 3495 | ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name, |
1c330a2f DS |
3496 | value); |
3497 | ||
3498 | os_free(value); | |
3499 | ||
3500 | return ret; | |
3501 | } | |
3502 | ||
3503 | ||
d94c9ee6 JM |
3504 | static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s, |
3505 | char *buf, size_t buflen) | |
3506 | { | |
3507 | char *pos, *end; | |
3508 | struct wpa_cred *cred; | |
3509 | int ret; | |
3510 | ||
3511 | pos = buf; | |
3512 | end = buf + buflen; | |
3513 | ret = os_snprintf(pos, end - pos, | |
3514 | "cred id / realm / username / domain / imsi\n"); | |
d85e1fc8 | 3515 | if (os_snprintf_error(end - pos, ret)) |
d94c9ee6 JM |
3516 | return pos - buf; |
3517 | pos += ret; | |
3518 | ||
3519 | cred = wpa_s->conf->cred; | |
3520 | while (cred) { | |
3521 | ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n", | |
3522 | cred->id, cred->realm ? cred->realm : "", | |
3523 | cred->username ? cred->username : "", | |
463c8ffb | 3524 | cred->domain ? cred->domain[0] : "", |
d94c9ee6 | 3525 | cred->imsi ? cred->imsi : ""); |
d85e1fc8 | 3526 | if (os_snprintf_error(end - pos, ret)) |
d94c9ee6 JM |
3527 | return pos - buf; |
3528 | pos += ret; | |
3529 | ||
3530 | cred = cred->next; | |
3531 | } | |
3532 | ||
3533 | return pos - buf; | |
3534 | } | |
3535 | ||
3536 | ||
3537 | static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s, | |
3538 | char *buf, size_t buflen) | |
3539 | { | |
3540 | struct wpa_cred *cred; | |
3541 | int ret; | |
3542 | ||
3543 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED"); | |
3544 | ||
3545 | cred = wpa_config_add_cred(wpa_s->conf); | |
3546 | if (cred == NULL) | |
3547 | return -1; | |
3548 | ||
1619e9d5 JM |
3549 | wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id); |
3550 | ||
d94c9ee6 | 3551 | ret = os_snprintf(buf, buflen, "%d\n", cred->id); |
d85e1fc8 | 3552 | if (os_snprintf_error(buflen, ret)) |
d94c9ee6 JM |
3553 | return -1; |
3554 | return ret; | |
3555 | } | |
3556 | ||
3557 | ||
736d4f2d JM |
3558 | static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s, |
3559 | struct wpa_cred *cred) | |
3560 | { | |
3561 | struct wpa_ssid *ssid; | |
3562 | char str[20]; | |
1619e9d5 | 3563 | int id; |
736d4f2d | 3564 | |
1619e9d5 | 3565 | if (cred == NULL) { |
736d4f2d JM |
3566 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); |
3567 | return -1; | |
3568 | } | |
3569 | ||
1619e9d5 JM |
3570 | id = cred->id; |
3571 | if (wpa_config_remove_cred(wpa_s->conf, id) < 0) { | |
3572 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); | |
3573 | return -1; | |
3574 | } | |
3575 | ||
3576 | wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id); | |
3577 | ||
736d4f2d JM |
3578 | /* Remove any network entry created based on the removed credential */ |
3579 | ssid = wpa_s->conf->ssid; | |
3580 | while (ssid) { | |
3581 | if (ssid->parent_cred == cred) { | |
1d399771 JM |
3582 | int res; |
3583 | ||
736d4f2d JM |
3584 | wpa_printf(MSG_DEBUG, "Remove network id %d since it " |
3585 | "used the removed credential", ssid->id); | |
1d399771 JM |
3586 | res = os_snprintf(str, sizeof(str), "%d", ssid->id); |
3587 | if (os_snprintf_error(sizeof(str), res)) | |
3588 | str[sizeof(str) - 1] = '\0'; | |
736d4f2d JM |
3589 | ssid = ssid->next; |
3590 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, str); | |
3591 | } else | |
3592 | ssid = ssid->next; | |
3593 | } | |
3594 | ||
3595 | return 0; | |
3596 | } | |
3597 | ||
3598 | ||
d94c9ee6 JM |
3599 | static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s, |
3600 | char *cmd) | |
3601 | { | |
3602 | int id; | |
736d4f2d | 3603 | struct wpa_cred *cred, *prev; |
d94c9ee6 | 3604 | |
aa26ba68 JM |
3605 | /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or |
3606 | * "provisioning_sp=<FQDN> */ | |
d94c9ee6 JM |
3607 | if (os_strcmp(cmd, "all") == 0) { |
3608 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all"); | |
3609 | cred = wpa_s->conf->cred; | |
3610 | while (cred) { | |
736d4f2d | 3611 | prev = cred; |
d94c9ee6 | 3612 | cred = cred->next; |
736d4f2d | 3613 | wpas_ctrl_remove_cred(wpa_s, prev); |
d94c9ee6 JM |
3614 | } |
3615 | return 0; | |
3616 | } | |
3617 | ||
9afe52eb JM |
3618 | if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) { |
3619 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'", | |
3620 | cmd + 8); | |
3621 | cred = wpa_s->conf->cred; | |
3622 | while (cred) { | |
3623 | prev = cred; | |
3624 | cred = cred->next; | |
463c8ffb JM |
3625 | if (prev->domain) { |
3626 | size_t i; | |
3627 | for (i = 0; i < prev->num_domain; i++) { | |
3628 | if (os_strcmp(prev->domain[i], cmd + 8) | |
3629 | != 0) | |
3630 | continue; | |
3631 | wpas_ctrl_remove_cred(wpa_s, prev); | |
3632 | break; | |
3633 | } | |
3634 | } | |
9afe52eb JM |
3635 | } |
3636 | return 0; | |
3637 | } | |
3638 | ||
aa26ba68 JM |
3639 | if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) { |
3640 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'", | |
3641 | cmd + 16); | |
3642 | cred = wpa_s->conf->cred; | |
3643 | while (cred) { | |
3644 | prev = cred; | |
3645 | cred = cred->next; | |
3646 | if (prev->provisioning_sp && | |
3647 | os_strcmp(prev->provisioning_sp, cmd + 16) == 0) | |
3648 | wpas_ctrl_remove_cred(wpa_s, prev); | |
3649 | } | |
3650 | return 0; | |
3651 | } | |
3652 | ||
d94c9ee6 JM |
3653 | id = atoi(cmd); |
3654 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id); | |
3655 | ||
3656 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
736d4f2d | 3657 | return wpas_ctrl_remove_cred(wpa_s, cred); |
d94c9ee6 JM |
3658 | } |
3659 | ||
3660 | ||
3661 | static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s, | |
3662 | char *cmd) | |
3663 | { | |
3664 | int id; | |
3665 | struct wpa_cred *cred; | |
3666 | char *name, *value; | |
3667 | ||
3668 | /* cmd: "<cred id> <variable name> <value>" */ | |
3669 | name = os_strchr(cmd, ' '); | |
3670 | if (name == NULL) | |
3671 | return -1; | |
3672 | *name++ = '\0'; | |
3673 | ||
3674 | value = os_strchr(name, ' '); | |
3675 | if (value == NULL) | |
3676 | return -1; | |
3677 | *value++ = '\0'; | |
3678 | ||
3679 | id = atoi(cmd); | |
3680 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'", | |
3681 | id, name); | |
3682 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
3683 | (u8 *) value, os_strlen(value)); | |
3684 | ||
3685 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
3686 | if (cred == NULL) { | |
3687 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | |
3688 | id); | |
3689 | return -1; | |
3690 | } | |
3691 | ||
3692 | if (wpa_config_set_cred(cred, name, value, 0) < 0) { | |
3693 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred " | |
3694 | "variable '%s'", name); | |
3695 | return -1; | |
3696 | } | |
3697 | ||
1619e9d5 JM |
3698 | wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name); |
3699 | ||
d94c9ee6 JM |
3700 | return 0; |
3701 | } | |
3702 | ||
3703 | ||
c880ab87 JM |
3704 | static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s, |
3705 | char *cmd, char *buf, | |
3706 | size_t buflen) | |
3707 | { | |
3708 | int id; | |
3709 | size_t res; | |
3710 | struct wpa_cred *cred; | |
3711 | char *name, *value; | |
3712 | ||
3713 | /* cmd: "<cred id> <variable name>" */ | |
3714 | name = os_strchr(cmd, ' '); | |
3715 | if (name == NULL) | |
3716 | return -1; | |
3717 | *name++ = '\0'; | |
3718 | ||
3719 | id = atoi(cmd); | |
3720 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'", | |
3721 | id, name); | |
3722 | ||
3723 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
3724 | if (cred == NULL) { | |
3725 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | |
3726 | id); | |
3727 | return -1; | |
3728 | } | |
3729 | ||
3730 | value = wpa_config_get_cred_no_key(cred, name); | |
3731 | if (value == NULL) { | |
3732 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'", | |
3733 | name); | |
3734 | return -1; | |
3735 | } | |
3736 | ||
3737 | res = os_strlcpy(buf, value, buflen); | |
3738 | if (res >= buflen) { | |
3739 | os_free(value); | |
3740 | return -1; | |
3741 | } | |
3742 | ||
3743 | os_free(value); | |
3744 | ||
3745 | return res; | |
3746 | } | |
3747 | ||
3748 | ||
6fc6879b JM |
3749 | #ifndef CONFIG_NO_CONFIG_WRITE |
3750 | static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s) | |
3751 | { | |
3752 | int ret; | |
3753 | ||
3754 | if (!wpa_s->conf->update_config) { | |
3755 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed " | |
3756 | "to update configuration (update_config=0)"); | |
3757 | return -1; | |
3758 | } | |
3759 | ||
3760 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); | |
3761 | if (ret) { | |
3762 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to " | |
3763 | "update configuration"); | |
3764 | } else { | |
3765 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration" | |
3766 | " updated"); | |
3767 | } | |
3768 | ||
3769 | return ret; | |
3770 | } | |
3771 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
3772 | ||
3773 | ||
4daa011b JM |
3774 | struct cipher_info { |
3775 | unsigned int capa; | |
3776 | const char *name; | |
3777 | int group_only; | |
3778 | }; | |
3779 | ||
3780 | static const struct cipher_info ciphers[] = { | |
3781 | { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 }, | |
3782 | { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 }, | |
3783 | { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 }, | |
3784 | { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 }, | |
3785 | { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 }, | |
3786 | { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 }, | |
3787 | { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 }, | |
3788 | { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 } | |
3789 | }; | |
3790 | ||
b5f045de JM |
3791 | static const struct cipher_info ciphers_group_mgmt[] = { |
3792 | { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 }, | |
3793 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 }, | |
3794 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 }, | |
3795 | { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 }, | |
3796 | }; | |
3797 | ||
4daa011b | 3798 | |
6fc6879b JM |
3799 | static int ctrl_iface_get_capability_pairwise(int res, char *strict, |
3800 | struct wpa_driver_capa *capa, | |
3801 | char *buf, size_t buflen) | |
3802 | { | |
ea3b8c1d | 3803 | int ret; |
6fc6879b JM |
3804 | char *pos, *end; |
3805 | size_t len; | |
4daa011b | 3806 | unsigned int i; |
6fc6879b JM |
3807 | |
3808 | pos = buf; | |
3809 | end = pos + buflen; | |
3810 | ||
3811 | if (res < 0) { | |
3812 | if (strict) | |
3813 | return 0; | |
3814 | len = os_strlcpy(buf, "CCMP TKIP NONE", buflen); | |
3815 | if (len >= buflen) | |
3816 | return -1; | |
3817 | return len; | |
3818 | } | |
3819 | ||
4daa011b JM |
3820 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
3821 | if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) { | |
3822 | ret = os_snprintf(pos, end - pos, "%s%s", | |
ea3b8c1d JM |
3823 | pos == buf ? "" : " ", |
3824 | ciphers[i].name); | |
d85e1fc8 | 3825 | if (os_snprintf_error(end - pos, ret)) |
4daa011b JM |
3826 | return pos - buf; |
3827 | pos += ret; | |
4daa011b | 3828 | } |
6fc6879b JM |
3829 | } |
3830 | ||
3831 | return pos - buf; | |
3832 | } | |
3833 | ||
3834 | ||
3835 | static int ctrl_iface_get_capability_group(int res, char *strict, | |
3836 | struct wpa_driver_capa *capa, | |
3837 | char *buf, size_t buflen) | |
3838 | { | |
ea3b8c1d | 3839 | int ret; |
6fc6879b JM |
3840 | char *pos, *end; |
3841 | size_t len; | |
4daa011b | 3842 | unsigned int i; |
6fc6879b JM |
3843 | |
3844 | pos = buf; | |
3845 | end = pos + buflen; | |
3846 | ||
3847 | if (res < 0) { | |
3848 | if (strict) | |
3849 | return 0; | |
3850 | len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen); | |
3851 | if (len >= buflen) | |
3852 | return -1; | |
3853 | return len; | |
3854 | } | |
3855 | ||
4daa011b JM |
3856 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
3857 | if (capa->enc & ciphers[i].capa) { | |
3858 | ret = os_snprintf(pos, end - pos, "%s%s", | |
ea3b8c1d JM |
3859 | pos == buf ? "" : " ", |
3860 | ciphers[i].name); | |
d85e1fc8 | 3861 | if (os_snprintf_error(end - pos, ret)) |
4daa011b JM |
3862 | return pos - buf; |
3863 | pos += ret; | |
4daa011b | 3864 | } |
6fc6879b JM |
3865 | } |
3866 | ||
3867 | return pos - buf; | |
3868 | } | |
3869 | ||
3870 | ||
b5f045de JM |
3871 | static int ctrl_iface_get_capability_group_mgmt(int res, char *strict, |
3872 | struct wpa_driver_capa *capa, | |
3873 | char *buf, size_t buflen) | |
3874 | { | |
3875 | int ret; | |
3876 | char *pos, *end; | |
3877 | unsigned int i; | |
3878 | ||
3879 | pos = buf; | |
3880 | end = pos + buflen; | |
3881 | ||
3882 | if (res < 0) | |
3883 | return 0; | |
3884 | ||
3885 | for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) { | |
3886 | if (capa->enc & ciphers_group_mgmt[i].capa) { | |
3887 | ret = os_snprintf(pos, end - pos, "%s%s", | |
3888 | pos == buf ? "" : " ", | |
3889 | ciphers_group_mgmt[i].name); | |
3890 | if (os_snprintf_error(end - pos, ret)) | |
3891 | return pos - buf; | |
3892 | pos += ret; | |
3893 | } | |
3894 | } | |
3895 | ||
3896 | return pos - buf; | |
3897 | } | |
3898 | ||
3899 | ||
6fc6879b JM |
3900 | static int ctrl_iface_get_capability_key_mgmt(int res, char *strict, |
3901 | struct wpa_driver_capa *capa, | |
3902 | char *buf, size_t buflen) | |
3903 | { | |
3904 | int ret; | |
3905 | char *pos, *end; | |
3906 | size_t len; | |
3907 | ||
3908 | pos = buf; | |
3909 | end = pos + buflen; | |
3910 | ||
3911 | if (res < 0) { | |
3912 | if (strict) | |
3913 | return 0; | |
3914 | len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE " | |
3915 | "NONE", buflen); | |
3916 | if (len >= buflen) | |
3917 | return -1; | |
3918 | return len; | |
3919 | } | |
3920 | ||
3921 | ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); | |
d85e1fc8 | 3922 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3923 | return pos - buf; |
3924 | pos += ret; | |
3925 | ||
3926 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
3927 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { | |
3928 | ret = os_snprintf(pos, end - pos, " WPA-EAP"); | |
d85e1fc8 | 3929 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3930 | return pos - buf; |
3931 | pos += ret; | |
3932 | } | |
3933 | ||
3934 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | |
3935 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
3936 | ret = os_snprintf(pos, end - pos, " WPA-PSK"); | |
d85e1fc8 | 3937 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3938 | return pos - buf; |
3939 | pos += ret; | |
3940 | } | |
3941 | ||
3942 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { | |
3943 | ret = os_snprintf(pos, end - pos, " WPA-NONE"); | |
d85e1fc8 | 3944 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3945 | return pos - buf; |
3946 | pos += ret; | |
3947 | } | |
3948 | ||
399e6135 JM |
3949 | #ifdef CONFIG_SUITEB |
3950 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) { | |
3951 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B"); | |
3952 | if (os_snprintf_error(end - pos, ret)) | |
3953 | return pos - buf; | |
3954 | pos += ret; | |
3955 | } | |
3956 | #endif /* CONFIG_SUITEB */ | |
3957 | #ifdef CONFIG_SUITEB192 | |
3958 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) { | |
3959 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192"); | |
3960 | if (os_snprintf_error(end - pos, ret)) | |
3961 | return pos - buf; | |
3962 | pos += ret; | |
3963 | } | |
3964 | #endif /* CONFIG_SUITEB192 */ | |
f9561868 JM |
3965 | #ifdef CONFIG_OWE |
3966 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) { | |
3967 | ret = os_snprintf(pos, end - pos, " OWE"); | |
3968 | if (os_snprintf_error(end - pos, ret)) | |
3969 | return pos - buf; | |
3970 | pos += ret; | |
3971 | } | |
3972 | #endif /* CONFIG_OWE */ | |
567da5bb JM |
3973 | #ifdef CONFIG_DPP |
3974 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) { | |
3975 | ret = os_snprintf(pos, end - pos, " DPP"); | |
3976 | if (os_snprintf_error(end - pos, ret)) | |
3977 | return pos - buf; | |
3978 | pos += ret; | |
3979 | } | |
3980 | #endif /* CONFIG_DPP */ | |
fe3e0bac VK |
3981 | #ifdef CONFIG_FILS |
3982 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) { | |
3983 | ret = os_snprintf(pos, end - pos, " FILS-SHA256"); | |
3984 | if (os_snprintf_error(end - pos, ret)) | |
3985 | return pos - buf; | |
3986 | pos += ret; | |
3987 | } | |
3988 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) { | |
3989 | ret = os_snprintf(pos, end - pos, " FILS-SHA384"); | |
3990 | if (os_snprintf_error(end - pos, ret)) | |
3991 | return pos - buf; | |
3992 | pos += ret; | |
3993 | } | |
3994 | #ifdef CONFIG_IEEE80211R | |
3995 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) { | |
3996 | ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256"); | |
3997 | if (os_snprintf_error(end - pos, ret)) | |
3998 | return pos - buf; | |
3999 | pos += ret; | |
4000 | } | |
4001 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) { | |
4002 | ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384"); | |
4003 | if (os_snprintf_error(end - pos, ret)) | |
4004 | return pos - buf; | |
4005 | pos += ret; | |
4006 | } | |
4007 | #endif /* CONFIG_IEEE80211R */ | |
4008 | #endif /* CONFIG_FILS */ | |
73f285da MH |
4009 | #ifdef CONFIG_IEEE80211R |
4010 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) { | |
4011 | ret = os_snprintf(pos, end - pos, " FT-PSK"); | |
4012 | if (os_snprintf_error(end - pos, ret)) | |
4013 | return pos - buf; | |
4014 | pos += ret; | |
4015 | } | |
4016 | #endif /* CONFIG_IEEE80211R */ | |
0fb292c0 JM |
4017 | #ifdef CONFIG_SAE |
4018 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) { | |
4019 | ret = os_snprintf(pos, end - pos, " SAE"); | |
4020 | if (os_snprintf_error(end - pos, ret)) | |
4021 | return pos - buf; | |
4022 | pos += ret; | |
4023 | } | |
4024 | #endif /* CONFIG_SAE */ | |
399e6135 | 4025 | |
6fc6879b JM |
4026 | return pos - buf; |
4027 | } | |
4028 | ||
4029 | ||
4030 | static int ctrl_iface_get_capability_proto(int res, char *strict, | |
4031 | struct wpa_driver_capa *capa, | |
4032 | char *buf, size_t buflen) | |
4033 | { | |
ea3b8c1d | 4034 | int ret; |
6fc6879b JM |
4035 | char *pos, *end; |
4036 | size_t len; | |
4037 | ||
4038 | pos = buf; | |
4039 | end = pos + buflen; | |
4040 | ||
4041 | if (res < 0) { | |
4042 | if (strict) | |
4043 | return 0; | |
4044 | len = os_strlcpy(buf, "RSN WPA", buflen); | |
4045 | if (len >= buflen) | |
4046 | return -1; | |
4047 | return len; | |
4048 | } | |
4049 | ||
4050 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | |
4051 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
ea3b8c1d JM |
4052 | ret = os_snprintf(pos, end - pos, "%sRSN", |
4053 | pos == buf ? "" : " "); | |
d85e1fc8 | 4054 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
4055 | return pos - buf; |
4056 | pos += ret; | |
6fc6879b JM |
4057 | } |
4058 | ||
4059 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
4060 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { | |
ea3b8c1d JM |
4061 | ret = os_snprintf(pos, end - pos, "%sWPA", |
4062 | pos == buf ? "" : " "); | |
d85e1fc8 | 4063 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
4064 | return pos - buf; |
4065 | pos += ret; | |
6fc6879b JM |
4066 | } |
4067 | ||
4068 | return pos - buf; | |
4069 | } | |
4070 | ||
4071 | ||
db5adfe7 JM |
4072 | static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s, |
4073 | int res, char *strict, | |
6fc6879b JM |
4074 | struct wpa_driver_capa *capa, |
4075 | char *buf, size_t buflen) | |
4076 | { | |
ea3b8c1d | 4077 | int ret; |
6fc6879b JM |
4078 | char *pos, *end; |
4079 | size_t len; | |
4080 | ||
4081 | pos = buf; | |
4082 | end = pos + buflen; | |
4083 | ||
4084 | if (res < 0) { | |
4085 | if (strict) | |
4086 | return 0; | |
4087 | len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen); | |
4088 | if (len >= buflen) | |
4089 | return -1; | |
4090 | return len; | |
4091 | } | |
4092 | ||
4093 | if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) { | |
ea3b8c1d JM |
4094 | ret = os_snprintf(pos, end - pos, "%sOPEN", |
4095 | pos == buf ? "" : " "); | |
d85e1fc8 | 4096 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
4097 | return pos - buf; |
4098 | pos += ret; | |
6fc6879b JM |
4099 | } |
4100 | ||
4101 | if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) { | |
4102 | ret = os_snprintf(pos, end - pos, "%sSHARED", | |
ea3b8c1d | 4103 | pos == buf ? "" : " "); |
d85e1fc8 | 4104 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
4105 | return pos - buf; |
4106 | pos += ret; | |
6fc6879b JM |
4107 | } |
4108 | ||
4109 | if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) { | |
ea3b8c1d JM |
4110 | ret = os_snprintf(pos, end - pos, "%sLEAP", |
4111 | pos == buf ? "" : " "); | |
d85e1fc8 | 4112 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
4113 | return pos - buf; |
4114 | pos += ret; | |
6fc6879b JM |
4115 | } |
4116 | ||
db5adfe7 JM |
4117 | #ifdef CONFIG_SAE |
4118 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) { | |
4119 | ret = os_snprintf(pos, end - pos, "%sSAE", | |
4120 | pos == buf ? "" : " "); | |
4121 | if (os_snprintf_error(end - pos, ret)) | |
4122 | return pos - buf; | |
4123 | pos += ret; | |
4124 | } | |
4125 | #endif /* CONFIG_SAE */ | |
4126 | ||
fe3e0bac VK |
4127 | #ifdef CONFIG_FILS |
4128 | if (wpa_is_fils_supported(wpa_s)) { | |
4129 | ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS", | |
4130 | pos == buf ? "" : " "); | |
4131 | if (os_snprintf_error(end - pos, ret)) | |
4132 | return pos - buf; | |
4133 | pos += ret; | |
4134 | } | |
4135 | ||
4136 | #ifdef CONFIG_FILS_SK_PFS | |
4137 | if (wpa_is_fils_sk_pfs_supported(wpa_s)) { | |
4138 | ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS", | |
4139 | pos == buf ? "" : " "); | |
4140 | if (os_snprintf_error(end - pos, ret)) | |
4141 | return pos - buf; | |
4142 | pos += ret; | |
4143 | } | |
4144 | #endif /* CONFIG_FILS_SK_PFS */ | |
4145 | #endif /* CONFIG_FILS */ | |
4146 | ||
6fc6879b JM |
4147 | return pos - buf; |
4148 | } | |
4149 | ||
4150 | ||
65d52fc1 BR |
4151 | static int ctrl_iface_get_capability_modes(int res, char *strict, |
4152 | struct wpa_driver_capa *capa, | |
4153 | char *buf, size_t buflen) | |
4154 | { | |
ea3b8c1d | 4155 | int ret; |
65d52fc1 BR |
4156 | char *pos, *end; |
4157 | size_t len; | |
4158 | ||
4159 | pos = buf; | |
4160 | end = pos + buflen; | |
4161 | ||
4162 | if (res < 0) { | |
4163 | if (strict) | |
4164 | return 0; | |
4165 | len = os_strlcpy(buf, "IBSS AP", buflen); | |
4166 | if (len >= buflen) | |
4167 | return -1; | |
4168 | return len; | |
4169 | } | |
4170 | ||
4171 | if (capa->flags & WPA_DRIVER_FLAGS_IBSS) { | |
ea3b8c1d JM |
4172 | ret = os_snprintf(pos, end - pos, "%sIBSS", |
4173 | pos == buf ? "" : " "); | |
d85e1fc8 | 4174 | if (os_snprintf_error(end - pos, ret)) |
65d52fc1 BR |
4175 | return pos - buf; |
4176 | pos += ret; | |
65d52fc1 BR |
4177 | } |
4178 | ||
4179 | if (capa->flags & WPA_DRIVER_FLAGS_AP) { | |
ea3b8c1d JM |
4180 | ret = os_snprintf(pos, end - pos, "%sAP", |
4181 | pos == buf ? "" : " "); | |
d85e1fc8 | 4182 | if (os_snprintf_error(end - pos, ret)) |
65d52fc1 BR |
4183 | return pos - buf; |
4184 | pos += ret; | |
65d52fc1 BR |
4185 | } |
4186 | ||
cf08e9b1 JM |
4187 | #ifdef CONFIG_MESH |
4188 | if (capa->flags & WPA_DRIVER_FLAGS_MESH) { | |
4189 | ret = os_snprintf(pos, end - pos, "%sMESH", | |
4190 | pos == buf ? "" : " "); | |
4191 | if (os_snprintf_error(end - pos, ret)) | |
4192 | return pos - buf; | |
4193 | pos += ret; | |
4194 | } | |
4195 | #endif /* CONFIG_MESH */ | |
4196 | ||
65d52fc1 BR |
4197 | return pos - buf; |
4198 | } | |
4199 | ||
4200 | ||
35aa088a DS |
4201 | static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s, |
4202 | char *buf, size_t buflen) | |
4203 | { | |
4204 | struct hostapd_channel_data *chnl; | |
4205 | int ret, i, j; | |
4206 | char *pos, *end, *hmode; | |
4207 | ||
4208 | pos = buf; | |
4209 | end = pos + buflen; | |
4210 | ||
4211 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | |
4212 | switch (wpa_s->hw.modes[j].mode) { | |
4213 | case HOSTAPD_MODE_IEEE80211B: | |
4214 | hmode = "B"; | |
4215 | break; | |
4216 | case HOSTAPD_MODE_IEEE80211G: | |
4217 | hmode = "G"; | |
4218 | break; | |
4219 | case HOSTAPD_MODE_IEEE80211A: | |
4220 | hmode = "A"; | |
4221 | break; | |
7829894c VK |
4222 | case HOSTAPD_MODE_IEEE80211AD: |
4223 | hmode = "AD"; | |
4224 | break; | |
35aa088a DS |
4225 | default: |
4226 | continue; | |
4227 | } | |
4228 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode); | |
d85e1fc8 | 4229 | if (os_snprintf_error(end - pos, ret)) |
35aa088a DS |
4230 | return pos - buf; |
4231 | pos += ret; | |
4232 | chnl = wpa_s->hw.modes[j].channels; | |
4233 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | |
4234 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | |
4235 | continue; | |
4236 | ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan); | |
d85e1fc8 | 4237 | if (os_snprintf_error(end - pos, ret)) |
35aa088a DS |
4238 | return pos - buf; |
4239 | pos += ret; | |
4240 | } | |
4241 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4242 | if (os_snprintf_error(end - pos, ret)) |
35aa088a DS |
4243 | return pos - buf; |
4244 | pos += ret; | |
4245 | } | |
4246 | ||
4247 | return pos - buf; | |
4248 | } | |
4249 | ||
4250 | ||
06060522 BR |
4251 | static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s, |
4252 | char *buf, size_t buflen) | |
4253 | { | |
4254 | struct hostapd_channel_data *chnl; | |
4255 | int ret, i, j; | |
4256 | char *pos, *end, *hmode; | |
4257 | ||
4258 | pos = buf; | |
4259 | end = pos + buflen; | |
4260 | ||
4261 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | |
4262 | switch (wpa_s->hw.modes[j].mode) { | |
4263 | case HOSTAPD_MODE_IEEE80211B: | |
4264 | hmode = "B"; | |
4265 | break; | |
4266 | case HOSTAPD_MODE_IEEE80211G: | |
4267 | hmode = "G"; | |
4268 | break; | |
4269 | case HOSTAPD_MODE_IEEE80211A: | |
4270 | hmode = "A"; | |
4271 | break; | |
4272 | case HOSTAPD_MODE_IEEE80211AD: | |
4273 | hmode = "AD"; | |
4274 | break; | |
4275 | default: | |
4276 | continue; | |
4277 | } | |
4278 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n", | |
4279 | hmode); | |
d85e1fc8 | 4280 | if (os_snprintf_error(end - pos, ret)) |
06060522 BR |
4281 | return pos - buf; |
4282 | pos += ret; | |
4283 | chnl = wpa_s->hw.modes[j].channels; | |
4284 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | |
4285 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | |
4286 | continue; | |
0547124d | 4287 | ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n", |
06060522 | 4288 | chnl[i].chan, chnl[i].freq, |
0a443580 IP |
4289 | chnl[i].flag & HOSTAPD_CHAN_NO_IR ? |
4290 | " (NO_IR)" : "", | |
0547124d DS |
4291 | chnl[i].flag & HOSTAPD_CHAN_RADAR ? |
4292 | " (DFS)" : ""); | |
4293 | ||
d85e1fc8 | 4294 | if (os_snprintf_error(end - pos, ret)) |
06060522 BR |
4295 | return pos - buf; |
4296 | pos += ret; | |
4297 | } | |
4298 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4299 | if (os_snprintf_error(end - pos, ret)) |
06060522 BR |
4300 | return pos - buf; |
4301 | pos += ret; | |
4302 | } | |
4303 | ||
4304 | return pos - buf; | |
4305 | } | |
4306 | ||
4307 | ||
6fc6879b JM |
4308 | static int wpa_supplicant_ctrl_iface_get_capability( |
4309 | struct wpa_supplicant *wpa_s, const char *_field, char *buf, | |
4310 | size_t buflen) | |
4311 | { | |
4312 | struct wpa_driver_capa capa; | |
4313 | int res; | |
4314 | char *strict; | |
4315 | char field[30]; | |
4316 | size_t len; | |
4317 | ||
4318 | /* Determine whether or not strict checking was requested */ | |
4319 | len = os_strlcpy(field, _field, sizeof(field)); | |
4320 | if (len >= sizeof(field)) | |
4321 | return -1; | |
4322 | strict = os_strchr(field, ' '); | |
4323 | if (strict != NULL) { | |
4324 | *strict++ = '\0'; | |
4325 | if (os_strcmp(strict, "strict") != 0) | |
4326 | return -1; | |
4327 | } | |
4328 | ||
4329 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s", | |
4330 | field, strict ? strict : ""); | |
4331 | ||
4332 | if (os_strcmp(field, "eap") == 0) { | |
4333 | return eap_get_names(buf, buflen); | |
4334 | } | |
4335 | ||
4336 | res = wpa_drv_get_capa(wpa_s, &capa); | |
4337 | ||
4338 | if (os_strcmp(field, "pairwise") == 0) | |
4339 | return ctrl_iface_get_capability_pairwise(res, strict, &capa, | |
4340 | buf, buflen); | |
4341 | ||
4342 | if (os_strcmp(field, "group") == 0) | |
4343 | return ctrl_iface_get_capability_group(res, strict, &capa, | |
4344 | buf, buflen); | |
4345 | ||
b5f045de JM |
4346 | if (os_strcmp(field, "group_mgmt") == 0) |
4347 | return ctrl_iface_get_capability_group_mgmt(res, strict, &capa, | |
4348 | buf, buflen); | |
4349 | ||
6fc6879b JM |
4350 | if (os_strcmp(field, "key_mgmt") == 0) |
4351 | return ctrl_iface_get_capability_key_mgmt(res, strict, &capa, | |
4352 | buf, buflen); | |
4353 | ||
4354 | if (os_strcmp(field, "proto") == 0) | |
4355 | return ctrl_iface_get_capability_proto(res, strict, &capa, | |
4356 | buf, buflen); | |
4357 | ||
4358 | if (os_strcmp(field, "auth_alg") == 0) | |
db5adfe7 JM |
4359 | return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict, |
4360 | &capa, buf, buflen); | |
6fc6879b | 4361 | |
65d52fc1 BR |
4362 | if (os_strcmp(field, "modes") == 0) |
4363 | return ctrl_iface_get_capability_modes(res, strict, &capa, | |
4364 | buf, buflen); | |
4365 | ||
35aa088a DS |
4366 | if (os_strcmp(field, "channels") == 0) |
4367 | return ctrl_iface_get_capability_channels(wpa_s, buf, buflen); | |
4368 | ||
06060522 BR |
4369 | if (os_strcmp(field, "freq") == 0) |
4370 | return ctrl_iface_get_capability_freq(wpa_s, buf, buflen); | |
4371 | ||
6e9375e4 DS |
4372 | #ifdef CONFIG_TDLS |
4373 | if (os_strcmp(field, "tdls") == 0) | |
4374 | return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen); | |
4375 | #endif /* CONFIG_TDLS */ | |
4376 | ||
02a8d45a JM |
4377 | #ifdef CONFIG_ERP |
4378 | if (os_strcmp(field, "erp") == 0) { | |
4379 | res = os_snprintf(buf, buflen, "ERP"); | |
d85e1fc8 | 4380 | if (os_snprintf_error(buflen, res)) |
02a8d45a JM |
4381 | return -1; |
4382 | return res; | |
4383 | } | |
4384 | #endif /* CONFIG_EPR */ | |
4385 | ||
1e4f7bf5 JM |
4386 | #ifdef CONFIG_FIPS |
4387 | if (os_strcmp(field, "fips") == 0) { | |
4388 | res = os_snprintf(buf, buflen, "FIPS"); | |
4389 | if (os_snprintf_error(buflen, res)) | |
4390 | return -1; | |
4391 | return res; | |
4392 | } | |
4393 | #endif /* CONFIG_FIPS */ | |
4394 | ||
7d2f6743 JM |
4395 | #ifdef CONFIG_ACS |
4396 | if (os_strcmp(field, "acs") == 0) { | |
4397 | res = os_snprintf(buf, buflen, "ACS"); | |
4398 | if (os_snprintf_error(buflen, res)) | |
4399 | return -1; | |
4400 | return res; | |
4401 | } | |
4402 | #endif /* CONFIG_ACS */ | |
4403 | ||
379e2b4d | 4404 | #ifdef CONFIG_FILS |
fe3e0bac | 4405 | if (os_strcmp(field, "fils") == 0) { |
31e130f8 | 4406 | #ifdef CONFIG_FILS_SK_PFS |
fe3e0bac VK |
4407 | if (wpa_is_fils_supported(wpa_s) && |
4408 | wpa_is_fils_sk_pfs_supported(wpa_s)) { | |
4409 | res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS"); | |
4410 | if (os_snprintf_error(buflen, res)) | |
4411 | return -1; | |
4412 | return res; | |
4413 | } | |
31e130f8 | 4414 | #endif /* CONFIG_FILS_SK_PFS */ |
fe3e0bac VK |
4415 | |
4416 | if (wpa_is_fils_supported(wpa_s)) { | |
4417 | res = os_snprintf(buf, buflen, "FILS"); | |
4418 | if (os_snprintf_error(buflen, res)) | |
4419 | return -1; | |
4420 | return res; | |
4421 | } | |
379e2b4d JM |
4422 | } |
4423 | #endif /* CONFIG_FILS */ | |
4424 | ||
2a93ecc8 JM |
4425 | if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) { |
4426 | res = os_snprintf(buf, buflen, "MULTIBSS-STA"); | |
4427 | if (os_snprintf_error(buflen, res)) | |
4428 | return -1; | |
4429 | return res; | |
4430 | } | |
4431 | ||
6fc6879b JM |
4432 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", |
4433 | field); | |
4434 | ||
4435 | return -1; | |
4436 | } | |
4437 | ||
4438 | ||
afc064fe JM |
4439 | #ifdef CONFIG_INTERWORKING |
4440 | static char * anqp_add_hex(char *pos, char *end, const char *title, | |
4441 | struct wpabuf *data) | |
4442 | { | |
4443 | char *start = pos; | |
4444 | size_t i; | |
4445 | int ret; | |
4446 | const u8 *d; | |
4447 | ||
4448 | if (data == NULL) | |
4449 | return start; | |
4450 | ||
4451 | ret = os_snprintf(pos, end - pos, "%s=", title); | |
d85e1fc8 | 4452 | if (os_snprintf_error(end - pos, ret)) |
afc064fe JM |
4453 | return start; |
4454 | pos += ret; | |
4455 | ||
4456 | d = wpabuf_head_u8(data); | |
4457 | for (i = 0; i < wpabuf_len(data); i++) { | |
4458 | ret = os_snprintf(pos, end - pos, "%02x", *d++); | |
d85e1fc8 | 4459 | if (os_snprintf_error(end - pos, ret)) |
afc064fe JM |
4460 | return start; |
4461 | pos += ret; | |
4462 | } | |
4463 | ||
4464 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4465 | if (os_snprintf_error(end - pos, ret)) |
afc064fe JM |
4466 | return start; |
4467 | pos += ret; | |
4468 | ||
4469 | return pos; | |
4470 | } | |
4471 | #endif /* CONFIG_INTERWORKING */ | |
4472 | ||
4473 | ||
b54f4339 JM |
4474 | #ifdef CONFIG_FILS |
4475 | static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end) | |
4476 | { | |
4477 | char *start = pos; | |
4478 | const u8 *ie, *ie_end; | |
4479 | u16 info, realms; | |
4480 | int ret; | |
4481 | ||
4482 | ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION); | |
4483 | if (!ie) | |
4484 | return 0; | |
4485 | ie_end = ie + 2 + ie[1]; | |
4486 | ie += 2; | |
4487 | if (ie_end - ie < 2) | |
4488 | return -1; | |
4489 | ||
4490 | info = WPA_GET_LE16(ie); | |
4491 | ie += 2; | |
4492 | ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info); | |
4493 | if (os_snprintf_error(end - pos, ret)) | |
4494 | return 0; | |
4495 | pos += ret; | |
4496 | ||
4497 | if (info & BIT(7)) { | |
4498 | /* Cache Identifier Included */ | |
4499 | if (ie_end - ie < 2) | |
4500 | return -1; | |
4501 | ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n", | |
4502 | ie[0], ie[1]); | |
4503 | if (os_snprintf_error(end - pos, ret)) | |
4504 | return 0; | |
4505 | pos += ret; | |
4506 | ie += 2; | |
4507 | } | |
4508 | ||
4509 | if (info & BIT(8)) { | |
4510 | /* HESSID Included */ | |
4511 | if (ie_end - ie < ETH_ALEN) | |
4512 | return -1; | |
4513 | ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n", | |
4514 | MAC2STR(ie)); | |
4515 | if (os_snprintf_error(end - pos, ret)) | |
4516 | return 0; | |
4517 | pos += ret; | |
4518 | ie += ETH_ALEN; | |
4519 | } | |
4520 | ||
4521 | realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3; | |
4522 | if (realms) { | |
4523 | if (ie_end - ie < realms * 2) | |
4524 | return -1; | |
4525 | ret = os_snprintf(pos, end - pos, "fils_realms="); | |
4526 | if (os_snprintf_error(end - pos, ret)) | |
4527 | return 0; | |
4528 | pos += ret; | |
4529 | ||
4530 | ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2); | |
4531 | if (ret <= 0) | |
4532 | return 0; | |
4533 | pos += ret; | |
4534 | ie += realms * 2; | |
4535 | ret = os_snprintf(pos, end - pos, "\n"); | |
4536 | if (os_snprintf_error(end - pos, ret)) | |
4537 | return 0; | |
4538 | pos += ret; | |
4539 | } | |
4540 | ||
4541 | return pos - start; | |
4542 | } | |
4543 | #endif /* CONFIG_FILS */ | |
4544 | ||
4545 | ||
61ce9085 | 4546 | static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
5f97dd1c | 4547 | unsigned long mask, char *buf, size_t buflen) |
6fc6879b | 4548 | { |
6fc6879b | 4549 | size_t i; |
6fc6879b JM |
4550 | int ret; |
4551 | char *pos, *end; | |
e8b96490 | 4552 | const u8 *ie, *ie2, *osen_ie, *mesh, *owe; |
6fc6879b | 4553 | |
6fc6879b JM |
4554 | pos = buf; |
4555 | end = buf + buflen; | |
6fc6879b | 4556 | |
5f97dd1c DS |
4557 | if (mask & WPA_BSS_MASK_ID) { |
4558 | ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id); | |
d85e1fc8 | 4559 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4560 | return 0; |
6fc6879b JM |
4561 | pos += ret; |
4562 | } | |
4563 | ||
5f97dd1c DS |
4564 | if (mask & WPA_BSS_MASK_BSSID) { |
4565 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | |
4566 | MAC2STR(bss->bssid)); | |
d85e1fc8 | 4567 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4568 | return 0; |
4569 | pos += ret; | |
4570 | } | |
6fc6879b | 4571 | |
5f97dd1c DS |
4572 | if (mask & WPA_BSS_MASK_FREQ) { |
4573 | ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq); | |
d85e1fc8 | 4574 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4575 | return 0; |
4576 | pos += ret; | |
4577 | } | |
6fc6879b | 4578 | |
5f97dd1c DS |
4579 | if (mask & WPA_BSS_MASK_BEACON_INT) { |
4580 | ret = os_snprintf(pos, end - pos, "beacon_int=%d\n", | |
4581 | bss->beacon_int); | |
d85e1fc8 | 4582 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4583 | return 0; |
6fc6879b JM |
4584 | pos += ret; |
4585 | } | |
5f97dd1c DS |
4586 | |
4587 | if (mask & WPA_BSS_MASK_CAPABILITIES) { | |
4588 | ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n", | |
4589 | bss->caps); | |
d85e1fc8 | 4590 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4591 | return 0; |
6fc6879b JM |
4592 | pos += ret; |
4593 | } | |
5f97dd1c DS |
4594 | |
4595 | if (mask & WPA_BSS_MASK_QUAL) { | |
4596 | ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual); | |
d85e1fc8 | 4597 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4598 | return 0; |
bd1af96a JM |
4599 | pos += ret; |
4600 | } | |
5f97dd1c DS |
4601 | |
4602 | if (mask & WPA_BSS_MASK_NOISE) { | |
4603 | ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise); | |
d85e1fc8 | 4604 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4605 | return 0; |
cc81110d JM |
4606 | pos += ret; |
4607 | } | |
6fc6879b | 4608 | |
5f97dd1c DS |
4609 | if (mask & WPA_BSS_MASK_LEVEL) { |
4610 | ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level); | |
d85e1fc8 | 4611 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4612 | return 0; |
4613 | pos += ret; | |
4614 | } | |
6fc6879b | 4615 | |
5f97dd1c DS |
4616 | if (mask & WPA_BSS_MASK_TSF) { |
4617 | ret = os_snprintf(pos, end - pos, "tsf=%016llu\n", | |
4618 | (unsigned long long) bss->tsf); | |
d85e1fc8 | 4619 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4620 | return 0; |
4621 | pos += ret; | |
4622 | } | |
4623 | ||
4624 | if (mask & WPA_BSS_MASK_AGE) { | |
acb69cec | 4625 | struct os_reltime now; |
5f97dd1c | 4626 | |
acb69cec | 4627 | os_get_reltime(&now); |
5f97dd1c DS |
4628 | ret = os_snprintf(pos, end - pos, "age=%d\n", |
4629 | (int) (now.sec - bss->last_update.sec)); | |
d85e1fc8 | 4630 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4631 | return 0; |
4632 | pos += ret; | |
4633 | } | |
4634 | ||
4635 | if (mask & WPA_BSS_MASK_IE) { | |
4636 | ret = os_snprintf(pos, end - pos, "ie="); | |
d85e1fc8 | 4637 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4638 | return 0; |
4639 | pos += ret; | |
4640 | ||
4641 | ie = (const u8 *) (bss + 1); | |
4642 | for (i = 0; i < bss->ie_len; i++) { | |
4643 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); | |
d85e1fc8 | 4644 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4645 | return 0; |
4646 | pos += ret; | |
4647 | } | |
4648 | ||
4649 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4650 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4651 | return 0; |
4652 | pos += ret; | |
4653 | } | |
4654 | ||
4655 | if (mask & WPA_BSS_MASK_FLAGS) { | |
4656 | ret = os_snprintf(pos, end - pos, "flags="); | |
d85e1fc8 | 4657 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4658 | return 0; |
4659 | pos += ret; | |
4660 | ||
4a45dc19 SD |
4661 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
4662 | ||
5f97dd1c DS |
4663 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
4664 | if (ie) | |
4665 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, | |
4666 | 2 + ie[1]); | |
4667 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); | |
4668 | if (ie2) | |
4a45dc19 SD |
4669 | pos = wpa_supplicant_ie_txt(pos, end, |
4670 | mesh ? "RSN" : "WPA2", ie2, | |
5f97dd1c | 4671 | 2 + ie2[1]); |
0f8385e6 BG |
4672 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
4673 | if (osen_ie) | |
4674 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", | |
4675 | osen_ie, 2 + osen_ie[1]); | |
e8b96490 JM |
4676 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
4677 | if (owe) { | |
4678 | ret = os_snprintf( | |
4679 | pos, end - pos, | |
4680 | ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]"); | |
4681 | if (os_snprintf_error(end - pos, ret)) | |
4682 | return 0; | |
4683 | pos += ret; | |
4684 | } | |
5f97dd1c | 4685 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
0f8385e6 BG |
4686 | if (!ie && !ie2 && !osen_ie && |
4687 | (bss->caps & IEEE80211_CAP_PRIVACY)) { | |
5f97dd1c | 4688 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
d85e1fc8 | 4689 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4690 | return 0; |
4691 | pos += ret; | |
4692 | } | |
4a45dc19 SD |
4693 | |
4694 | if (mesh) { | |
4695 | ret = os_snprintf(pos, end - pos, "[MESH]"); | |
4696 | if (os_snprintf_error(end - pos, ret)) | |
4697 | return 0; | |
4698 | pos += ret; | |
4699 | } | |
4700 | ||
e403ba85 BS |
4701 | if (bss_is_dmg(bss)) { |
4702 | const char *s; | |
4703 | ret = os_snprintf(pos, end - pos, "[DMG]"); | |
d85e1fc8 | 4704 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4705 | return 0; |
4706 | pos += ret; | |
e403ba85 BS |
4707 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
4708 | case IEEE80211_CAP_DMG_IBSS: | |
4709 | s = "[IBSS]"; | |
4710 | break; | |
4711 | case IEEE80211_CAP_DMG_AP: | |
4712 | s = "[ESS]"; | |
4713 | break; | |
4714 | case IEEE80211_CAP_DMG_PBSS: | |
4715 | s = "[PBSS]"; | |
4716 | break; | |
4717 | default: | |
4718 | s = ""; | |
4719 | break; | |
4720 | } | |
4721 | ret = os_snprintf(pos, end - pos, "%s", s); | |
d85e1fc8 | 4722 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4723 | return 0; |
4724 | pos += ret; | |
e403ba85 BS |
4725 | } else { |
4726 | if (bss->caps & IEEE80211_CAP_IBSS) { | |
4727 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | |
d85e1fc8 | 4728 | if (os_snprintf_error(end - pos, ret)) |
e403ba85 BS |
4729 | return 0; |
4730 | pos += ret; | |
4731 | } | |
4732 | if (bss->caps & IEEE80211_CAP_ESS) { | |
4733 | ret = os_snprintf(pos, end - pos, "[ESS]"); | |
d85e1fc8 | 4734 | if (os_snprintf_error(end - pos, ret)) |
e403ba85 BS |
4735 | return 0; |
4736 | pos += ret; | |
4737 | } | |
5f97dd1c | 4738 | } |
bb50ae43 JM |
4739 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || |
4740 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { | |
5f97dd1c | 4741 | ret = os_snprintf(pos, end - pos, "[P2P]"); |
d85e1fc8 | 4742 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4743 | return 0; |
4744 | pos += ret; | |
4745 | } | |
64855b96 JM |
4746 | #ifdef CONFIG_HS20 |
4747 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) { | |
4748 | ret = os_snprintf(pos, end - pos, "[HS20]"); | |
d85e1fc8 | 4749 | if (os_snprintf_error(end - pos, ret)) |
ff486913 | 4750 | return 0; |
64855b96 JM |
4751 | pos += ret; |
4752 | } | |
4753 | #endif /* CONFIG_HS20 */ | |
7147a834 JM |
4754 | #ifdef CONFIG_FILS |
4755 | if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) { | |
4756 | ret = os_snprintf(pos, end - pos, "[FILS]"); | |
4757 | if (os_snprintf_error(end - pos, ret)) | |
4758 | return 0; | |
4759 | pos += ret; | |
4760 | } | |
4761 | #endif /* CONFIG_FILS */ | |
e6b0898d JM |
4762 | #ifdef CONFIG_FST |
4763 | if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) { | |
4764 | ret = os_snprintf(pos, end - pos, "[FST]"); | |
4765 | if (os_snprintf_error(end - pos, ret)) | |
4766 | return 0; | |
4767 | pos += ret; | |
4768 | } | |
4769 | #endif /* CONFIG_FST */ | |
ed87f6a8 | 4770 | if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) { |
e6b0898d JM |
4771 | ret = os_snprintf(pos, end - pos, "[UTF-8]"); |
4772 | if (os_snprintf_error(end - pos, ret)) | |
4773 | return 0; | |
4774 | pos += ret; | |
4775 | } | |
5f97dd1c DS |
4776 | |
4777 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4778 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4779 | return 0; |
4780 | pos += ret; | |
4781 | } | |
4782 | ||
4783 | if (mask & WPA_BSS_MASK_SSID) { | |
4784 | ret = os_snprintf(pos, end - pos, "ssid=%s\n", | |
4785 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | |
d85e1fc8 | 4786 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4787 | return 0; |
4788 | pos += ret; | |
4789 | } | |
6fc6879b | 4790 | |
611ed491 | 4791 | #ifdef CONFIG_WPS |
5f97dd1c DS |
4792 | if (mask & WPA_BSS_MASK_WPS_SCAN) { |
4793 | ie = (const u8 *) (bss + 1); | |
4794 | ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end); | |
fc078be2 | 4795 | if (ret >= end - pos) |
5f97dd1c | 4796 | return 0; |
fc078be2 JM |
4797 | if (ret > 0) |
4798 | pos += ret; | |
5f97dd1c | 4799 | } |
611ed491 JM |
4800 | #endif /* CONFIG_WPS */ |
4801 | ||
0c6b310e | 4802 | #ifdef CONFIG_P2P |
5f97dd1c DS |
4803 | if (mask & WPA_BSS_MASK_P2P_SCAN) { |
4804 | ie = (const u8 *) (bss + 1); | |
4805 | ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end); | |
3b208346 | 4806 | if (ret >= end - pos) |
5f97dd1c | 4807 | return 0; |
3b208346 JA |
4808 | if (ret > 0) |
4809 | pos += ret; | |
5f97dd1c | 4810 | } |
0c6b310e JM |
4811 | #endif /* CONFIG_P2P */ |
4812 | ||
337c781f JM |
4813 | #ifdef CONFIG_WIFI_DISPLAY |
4814 | if (mask & WPA_BSS_MASK_WIFI_DISPLAY) { | |
4815 | struct wpabuf *wfd; | |
4816 | ie = (const u8 *) (bss + 1); | |
4817 | wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len, | |
4818 | WFD_IE_VENDOR_TYPE); | |
4819 | if (wfd) { | |
4820 | ret = os_snprintf(pos, end - pos, "wfd_subelems="); | |
d85e1fc8 | 4821 | if (os_snprintf_error(end - pos, ret)) { |
5e6aa04b | 4822 | wpabuf_free(wfd); |
ff486913 | 4823 | return 0; |
5e6aa04b | 4824 | } |
337c781f JM |
4825 | pos += ret; |
4826 | ||
4827 | pos += wpa_snprintf_hex(pos, end - pos, | |
4828 | wpabuf_head(wfd), | |
4829 | wpabuf_len(wfd)); | |
4830 | wpabuf_free(wfd); | |
4831 | ||
4832 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4833 | if (os_snprintf_error(end - pos, ret)) |
ff486913 | 4834 | return 0; |
337c781f JM |
4835 | pos += ret; |
4836 | } | |
4837 | } | |
4838 | #endif /* CONFIG_WIFI_DISPLAY */ | |
4839 | ||
afc064fe | 4840 | #ifdef CONFIG_INTERWORKING |
476aed35 JM |
4841 | if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) { |
4842 | struct wpa_bss_anqp *anqp = bss->anqp; | |
8c4a1026 JM |
4843 | struct wpa_bss_anqp_elem *elem; |
4844 | ||
5ce6ac11 AN |
4845 | pos = anqp_add_hex(pos, end, "anqp_capability_list", |
4846 | anqp->capability_list); | |
5f97dd1c | 4847 | pos = anqp_add_hex(pos, end, "anqp_venue_name", |
476aed35 | 4848 | anqp->venue_name); |
5f97dd1c | 4849 | pos = anqp_add_hex(pos, end, "anqp_network_auth_type", |
476aed35 | 4850 | anqp->network_auth_type); |
5f97dd1c | 4851 | pos = anqp_add_hex(pos, end, "anqp_roaming_consortium", |
476aed35 | 4852 | anqp->roaming_consortium); |
5f97dd1c | 4853 | pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability", |
476aed35 | 4854 | anqp->ip_addr_type_availability); |
5f97dd1c | 4855 | pos = anqp_add_hex(pos, end, "anqp_nai_realm", |
476aed35 JM |
4856 | anqp->nai_realm); |
4857 | pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp); | |
5f97dd1c | 4858 | pos = anqp_add_hex(pos, end, "anqp_domain_name", |
476aed35 | 4859 | anqp->domain_name); |
9cad6186 JM |
4860 | pos = anqp_add_hex(pos, end, "anqp_fils_realm_info", |
4861 | anqp->fils_realm_info); | |
25471fe3 | 4862 | #ifdef CONFIG_HS20 |
185ada47 AN |
4863 | pos = anqp_add_hex(pos, end, "hs20_capability_list", |
4864 | anqp->hs20_capability_list); | |
25471fe3 | 4865 | pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name", |
476aed35 | 4866 | anqp->hs20_operator_friendly_name); |
25471fe3 | 4867 | pos = anqp_add_hex(pos, end, "hs20_wan_metrics", |
476aed35 | 4868 | anqp->hs20_wan_metrics); |
25471fe3 | 4869 | pos = anqp_add_hex(pos, end, "hs20_connection_capability", |
476aed35 | 4870 | anqp->hs20_connection_capability); |
1d2215fc JM |
4871 | pos = anqp_add_hex(pos, end, "hs20_operating_class", |
4872 | anqp->hs20_operating_class); | |
4873 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_list", | |
4874 | anqp->hs20_osu_providers_list); | |
6a8a04d7 JM |
4875 | pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata", |
4876 | anqp->hs20_operator_icon_metadata); | |
baf4c863 JM |
4877 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list", |
4878 | anqp->hs20_osu_providers_nai_list); | |
25471fe3 | 4879 | #endif /* CONFIG_HS20 */ |
8c4a1026 JM |
4880 | |
4881 | dl_list_for_each(elem, &anqp->anqp_elems, | |
4882 | struct wpa_bss_anqp_elem, list) { | |
4883 | char title[20]; | |
4884 | ||
4885 | os_snprintf(title, sizeof(title), "anqp[%u]", | |
4886 | elem->infoid); | |
4887 | pos = anqp_add_hex(pos, end, title, elem->payload); | |
4888 | } | |
5f97dd1c | 4889 | } |
afc064fe JM |
4890 | #endif /* CONFIG_INTERWORKING */ |
4891 | ||
79070906 MH |
4892 | #ifdef CONFIG_MESH |
4893 | if (mask & WPA_BSS_MASK_MESH_SCAN) { | |
4894 | ie = (const u8 *) (bss + 1); | |
4895 | ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end); | |
3b208346 | 4896 | if (ret >= end - pos) |
79070906 | 4897 | return 0; |
3b208346 JA |
4898 | if (ret > 0) |
4899 | pos += ret; | |
79070906 MH |
4900 | } |
4901 | #endif /* CONFIG_MESH */ | |
4902 | ||
1d747e2a JM |
4903 | if (mask & WPA_BSS_MASK_SNR) { |
4904 | ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr); | |
4905 | if (os_snprintf_error(end - pos, ret)) | |
4906 | return 0; | |
4907 | pos += ret; | |
4908 | } | |
4909 | ||
4910 | if (mask & WPA_BSS_MASK_EST_THROUGHPUT) { | |
4911 | ret = os_snprintf(pos, end - pos, "est_throughput=%d\n", | |
4912 | bss->est_throughput); | |
4913 | if (os_snprintf_error(end - pos, ret)) | |
4914 | return 0; | |
4915 | pos += ret; | |
4916 | } | |
4917 | ||
3794af2d AN |
4918 | #ifdef CONFIG_FST |
4919 | if (mask & WPA_BSS_MASK_FST) { | |
4920 | ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos); | |
4921 | if (ret < 0 || ret >= end - pos) | |
4922 | return 0; | |
4923 | pos += ret; | |
4924 | } | |
4925 | #endif /* CONFIG_FST */ | |
4926 | ||
71ac9345 JM |
4927 | if (mask & WPA_BSS_MASK_UPDATE_IDX) { |
4928 | ret = os_snprintf(pos, end - pos, "update_idx=%u\n", | |
4929 | bss->last_update_idx); | |
4930 | if (os_snprintf_error(end - pos, ret)) | |
4931 | return 0; | |
4932 | pos += ret; | |
4933 | } | |
4934 | ||
19810d29 JM |
4935 | if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) { |
4936 | ret = os_snprintf(pos, end - pos, "beacon_ie="); | |
4937 | if (os_snprintf_error(end - pos, ret)) | |
4938 | return 0; | |
4939 | pos += ret; | |
4940 | ||
4941 | ie = (const u8 *) (bss + 1); | |
4942 | ie += bss->ie_len; | |
4943 | for (i = 0; i < bss->beacon_ie_len; i++) { | |
4944 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); | |
4945 | if (os_snprintf_error(end - pos, ret)) | |
4946 | return 0; | |
4947 | pos += ret; | |
4948 | } | |
4949 | ||
4950 | ret = os_snprintf(pos, end - pos, "\n"); | |
4951 | if (os_snprintf_error(end - pos, ret)) | |
4952 | return 0; | |
4953 | pos += ret; | |
4954 | } | |
4955 | ||
b54f4339 JM |
4956 | #ifdef CONFIG_FILS |
4957 | if (mask & WPA_BSS_MASK_FILS_INDICATION) { | |
4958 | ret = print_fils_indication(bss, pos, end); | |
4959 | if (ret < 0) | |
4960 | return 0; | |
4961 | pos += ret; | |
4962 | } | |
4963 | #endif /* CONFIG_FILS */ | |
4964 | ||
c6673429 DS |
4965 | if (mask & WPA_BSS_MASK_DELIM) { |
4966 | ret = os_snprintf(pos, end - pos, "====\n"); | |
d85e1fc8 | 4967 | if (os_snprintf_error(end - pos, ret)) |
c6673429 DS |
4968 | return 0; |
4969 | pos += ret; | |
4970 | } | |
4971 | ||
6fc6879b JM |
4972 | return pos - buf; |
4973 | } | |
4974 | ||
4975 | ||
61ce9085 DS |
4976 | static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s, |
4977 | const char *cmd, char *buf, | |
4978 | size_t buflen) | |
4979 | { | |
4980 | u8 bssid[ETH_ALEN]; | |
4981 | size_t i; | |
4982 | struct wpa_bss *bss; | |
eff1a95b DS |
4983 | struct wpa_bss *bsslast = NULL; |
4984 | struct dl_list *next; | |
4985 | int ret = 0; | |
4986 | int len; | |
1d399771 | 4987 | char *ctmp, *end = buf + buflen; |
5f97dd1c | 4988 | unsigned long mask = WPA_BSS_MASK_ALL; |
61ce9085 | 4989 | |
eff1a95b DS |
4990 | if (os_strncmp(cmd, "RANGE=", 6) == 0) { |
4991 | if (os_strncmp(cmd + 6, "ALL", 3) == 0) { | |
4992 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, | |
4993 | list_id); | |
4994 | bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss, | |
4995 | list_id); | |
4996 | } else { /* N1-N2 */ | |
4997 | unsigned int id1, id2; | |
4998 | ||
4999 | if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) { | |
5000 | wpa_printf(MSG_INFO, "Wrong BSS range " | |
5001 | "format"); | |
5002 | return 0; | |
5003 | } | |
5004 | ||
9f42d49c AS |
5005 | if (*(cmd + 6) == '-') |
5006 | id1 = 0; | |
5007 | else | |
5008 | id1 = atoi(cmd + 6); | |
5009 | ctmp++; | |
5010 | if (*ctmp >= '0' && *ctmp <= '9') | |
5011 | id2 = atoi(ctmp); | |
5012 | else | |
5013 | id2 = (unsigned int) -1; | |
5014 | bss = wpa_bss_get_id_range(wpa_s, id1, id2); | |
5015 | if (id2 == (unsigned int) -1) | |
eff1a95b DS |
5016 | bsslast = dl_list_last(&wpa_s->bss_id, |
5017 | struct wpa_bss, | |
5018 | list_id); | |
5019 | else { | |
5020 | bsslast = wpa_bss_get_id(wpa_s, id2); | |
5021 | if (bsslast == NULL && bss && id2 > id1) { | |
5022 | struct wpa_bss *tmp = bss; | |
5023 | for (;;) { | |
5024 | next = tmp->list_id.next; | |
5025 | if (next == &wpa_s->bss_id) | |
5026 | break; | |
5027 | tmp = dl_list_entry( | |
5028 | next, struct wpa_bss, | |
5029 | list_id); | |
5030 | if (tmp->id > id2) | |
5031 | break; | |
5032 | bsslast = tmp; | |
5033 | } | |
5034 | } | |
5035 | } | |
5036 | } | |
f330b4b4 | 5037 | } else if (os_strncmp(cmd, "FIRST", 5) == 0) |
51a0c3d4 | 5038 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id); |
cc03d0fe AS |
5039 | else if (os_strncmp(cmd, "LAST", 4) == 0) |
5040 | bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id); | |
61ce9085 DS |
5041 | else if (os_strncmp(cmd, "ID-", 3) == 0) { |
5042 | i = atoi(cmd + 3); | |
5043 | bss = wpa_bss_get_id(wpa_s, i); | |
5044 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | |
5045 | i = atoi(cmd + 5); | |
5046 | bss = wpa_bss_get_id(wpa_s, i); | |
5047 | if (bss) { | |
eff1a95b | 5048 | next = bss->list_id.next; |
61ce9085 DS |
5049 | if (next == &wpa_s->bss_id) |
5050 | bss = NULL; | |
5051 | else | |
5052 | bss = dl_list_entry(next, struct wpa_bss, | |
5053 | list_id); | |
5054 | } | |
9187b13a JC |
5055 | } else if (os_strncmp(cmd, "CURRENT", 7) == 0) { |
5056 | bss = wpa_s->current_bss; | |
61ce9085 DS |
5057 | #ifdef CONFIG_P2P |
5058 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | |
5059 | if (hwaddr_aton(cmd + 13, bssid) == 0) | |
5060 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid); | |
5061 | else | |
5062 | bss = NULL; | |
5063 | #endif /* CONFIG_P2P */ | |
5064 | } else if (hwaddr_aton(cmd, bssid) == 0) | |
5065 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
5066 | else { | |
5067 | struct wpa_bss *tmp; | |
5068 | i = atoi(cmd); | |
5069 | bss = NULL; | |
5070 | dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id) | |
5071 | { | |
5072 | if (i-- == 0) { | |
5073 | bss = tmp; | |
5074 | break; | |
5075 | } | |
5076 | } | |
5077 | } | |
5078 | ||
5f97dd1c DS |
5079 | if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) { |
5080 | mask = strtoul(ctmp + 5, NULL, 0x10); | |
5081 | if (mask == 0) | |
5082 | mask = WPA_BSS_MASK_ALL; | |
5083 | } | |
5084 | ||
61ce9085 DS |
5085 | if (bss == NULL) |
5086 | return 0; | |
5087 | ||
eff1a95b DS |
5088 | if (bsslast == NULL) |
5089 | bsslast = bss; | |
5090 | do { | |
5091 | len = print_bss_info(wpa_s, bss, mask, buf, buflen); | |
5092 | ret += len; | |
5093 | buf += len; | |
5094 | buflen -= len; | |
cfd42c94 DS |
5095 | if (bss == bsslast) { |
5096 | if ((mask & WPA_BSS_MASK_DELIM) && len && | |
5097 | (bss == dl_list_last(&wpa_s->bss_id, | |
1d399771 JM |
5098 | struct wpa_bss, list_id))) { |
5099 | int res; | |
5100 | ||
5101 | res = os_snprintf(buf - 5, end - buf + 5, | |
5102 | "####\n"); | |
5103 | if (os_snprintf_error(end - buf + 5, res)) { | |
5104 | wpa_printf(MSG_DEBUG, | |
5105 | "Could not add end delim"); | |
5106 | } | |
5107 | } | |
eff1a95b | 5108 | break; |
cfd42c94 | 5109 | } |
eff1a95b DS |
5110 | next = bss->list_id.next; |
5111 | if (next == &wpa_s->bss_id) | |
5112 | break; | |
5113 | bss = dl_list_entry(next, struct wpa_bss, list_id); | |
5114 | } while (bss && len); | |
5115 | ||
5116 | return ret; | |
61ce9085 DS |
5117 | } |
5118 | ||
5119 | ||
6fc6879b JM |
5120 | static int wpa_supplicant_ctrl_iface_ap_scan( |
5121 | struct wpa_supplicant *wpa_s, char *cmd) | |
5122 | { | |
5123 | int ap_scan = atoi(cmd); | |
86b89452 | 5124 | return wpa_supplicant_set_ap_scan(wpa_s, ap_scan); |
6fc6879b JM |
5125 | } |
5126 | ||
5127 | ||
67b9bd08 DS |
5128 | static int wpa_supplicant_ctrl_iface_scan_interval( |
5129 | struct wpa_supplicant *wpa_s, char *cmd) | |
5130 | { | |
5131 | int scan_int = atoi(cmd); | |
c6e86b63 | 5132 | return wpa_supplicant_set_scan_interval(wpa_s, scan_int); |
67b9bd08 DS |
5133 | } |
5134 | ||
5135 | ||
78633c37 SL |
5136 | static int wpa_supplicant_ctrl_iface_bss_expire_age( |
5137 | struct wpa_supplicant *wpa_s, char *cmd) | |
5138 | { | |
5139 | int expire_age = atoi(cmd); | |
5140 | return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age); | |
5141 | } | |
5142 | ||
5143 | ||
5144 | static int wpa_supplicant_ctrl_iface_bss_expire_count( | |
5145 | struct wpa_supplicant *wpa_s, char *cmd) | |
5146 | { | |
5147 | int expire_count = atoi(cmd); | |
5148 | return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count); | |
5149 | } | |
5150 | ||
5151 | ||
a1144000 | 5152 | static void wpa_supplicant_ctrl_iface_bss_flush( |
39ee845f DS |
5153 | struct wpa_supplicant *wpa_s, char *cmd) |
5154 | { | |
5155 | int flush_age = atoi(cmd); | |
5156 | ||
5157 | if (flush_age == 0) | |
5158 | wpa_bss_flush(wpa_s); | |
5159 | else | |
5160 | wpa_bss_flush_by_age(wpa_s, flush_age); | |
39ee845f DS |
5161 | } |
5162 | ||
5163 | ||
9ff4de6d | 5164 | #ifdef CONFIG_TESTING_OPTIONS |
32d5295f JM |
5165 | static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s) |
5166 | { | |
32d5295f JM |
5167 | wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication"); |
5168 | /* MLME-DELETEKEYS.request */ | |
0382097e JM |
5169 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0); |
5170 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0); | |
5171 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0); | |
5172 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0); | |
32d5295f | 5173 | #ifdef CONFIG_IEEE80211W |
0382097e JM |
5174 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0); |
5175 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0); | |
32d5295f JM |
5176 | #endif /* CONFIG_IEEE80211W */ |
5177 | ||
5178 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL, | |
5179 | 0); | |
5180 | /* MLME-SETPROTECTION.request(None) */ | |
5181 | wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid, | |
5182 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, | |
5183 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); | |
5184 | wpa_sm_drop_sa(wpa_s->wpa); | |
5185 | } | |
9ff4de6d | 5186 | #endif /* CONFIG_TESTING_OPTIONS */ |
32d5295f JM |
5187 | |
5188 | ||
86d4f806 JM |
5189 | static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s, |
5190 | char *addr) | |
5191 | { | |
90b8fc8f JM |
5192 | #ifdef CONFIG_NO_SCAN_PROCESSING |
5193 | return -1; | |
5194 | #else /* CONFIG_NO_SCAN_PROCESSING */ | |
86d4f806 JM |
5195 | u8 bssid[ETH_ALEN]; |
5196 | struct wpa_bss *bss; | |
5197 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
5198 | ||
5199 | if (hwaddr_aton(addr, bssid)) { | |
5200 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid " | |
5201 | "address '%s'", addr); | |
5202 | return -1; | |
5203 | } | |
5204 | ||
5205 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid)); | |
5206 | ||
2f9b66d3 JM |
5207 | if (!ssid) { |
5208 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network " | |
5209 | "configuration known for the target AP"); | |
5210 | return -1; | |
5211 | } | |
5212 | ||
5213 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); | |
86d4f806 JM |
5214 | if (!bss) { |
5215 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found " | |
5216 | "from BSS table"); | |
5217 | return -1; | |
5218 | } | |
5219 | ||
5220 | /* | |
5221 | * TODO: Find best network configuration block from configuration to | |
5222 | * allow roaming to other networks | |
5223 | */ | |
5224 | ||
86d4f806 JM |
5225 | wpa_s->reassociate = 1; |
5226 | wpa_supplicant_connect(wpa_s, bss, ssid); | |
5227 | ||
5228 | return 0; | |
90b8fc8f | 5229 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
86d4f806 JM |
5230 | } |
5231 | ||
5232 | ||
b563b388 JM |
5233 | #ifdef CONFIG_P2P |
5234 | static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd) | |
5235 | { | |
5236 | unsigned int timeout = atoi(cmd); | |
5237 | enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL; | |
6d92fa6e | 5238 | u8 dev_id[ETH_ALEN], *_dev_id = NULL; |
2b384109 | 5239 | u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL; |
6d92fa6e | 5240 | char *pos; |
05a77b3b | 5241 | unsigned int search_delay; |
9542f21f | 5242 | const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL; |
51775096 | 5243 | u8 seek_count = 0; |
fa9f381f | 5244 | int freq = 0; |
b563b388 | 5245 | |
e9eb648e JM |
5246 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
5247 | wpa_dbg(wpa_s, MSG_INFO, | |
5248 | "Reject P2P_FIND since interface is disabled"); | |
5249 | return -1; | |
5250 | } | |
b563b388 JM |
5251 | if (os_strstr(cmd, "type=social")) |
5252 | type = P2P_FIND_ONLY_SOCIAL; | |
5253 | else if (os_strstr(cmd, "type=progressive")) | |
5254 | type = P2P_FIND_PROGRESSIVE; | |
5255 | ||
6d92fa6e JM |
5256 | pos = os_strstr(cmd, "dev_id="); |
5257 | if (pos) { | |
5258 | pos += 7; | |
5259 | if (hwaddr_aton(pos, dev_id)) | |
5260 | return -1; | |
5261 | _dev_id = dev_id; | |
5262 | } | |
5263 | ||
2b384109 JM |
5264 | pos = os_strstr(cmd, "dev_type="); |
5265 | if (pos) { | |
5266 | pos += 9; | |
5267 | if (wps_dev_type_str2bin(pos, dev_type) < 0) | |
5268 | return -1; | |
5269 | _dev_type = dev_type; | |
5270 | } | |
5271 | ||
37448ede JM |
5272 | pos = os_strstr(cmd, "delay="); |
5273 | if (pos) { | |
5274 | pos += 6; | |
5275 | search_delay = atoi(pos); | |
05a77b3b JM |
5276 | } else |
5277 | search_delay = wpas_p2p_search_delay(wpa_s); | |
37448ede | 5278 | |
a9ea609c SM |
5279 | pos = os_strstr(cmd, "freq="); |
5280 | if (pos) { | |
5281 | pos += 5; | |
5282 | freq = atoi(pos); | |
5283 | if (freq <= 0) | |
5284 | return -1; | |
5285 | } | |
5286 | ||
51775096 BG |
5287 | /* Must be searched for last, because it adds nul termination */ |
5288 | pos = os_strstr(cmd, " seek="); | |
129b6216 JM |
5289 | if (pos) |
5290 | pos += 6; | |
51775096 BG |
5291 | while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) { |
5292 | char *term; | |
5293 | ||
129b6216 | 5294 | _seek[seek_count++] = pos; |
9542f21f | 5295 | seek = _seek; |
129b6216 JM |
5296 | term = os_strchr(pos, ' '); |
5297 | if (!term) | |
5298 | break; | |
5299 | *term = '\0'; | |
5300 | pos = os_strstr(term + 1, "seek="); | |
5301 | if (pos) | |
5302 | pos += 5; | |
51775096 | 5303 | } |
9542f21f JM |
5304 | if (seek_count > P2P_MAX_QUERY_HASH) { |
5305 | seek[0] = NULL; | |
5306 | seek_count = 1; | |
5307 | } | |
51775096 | 5308 | |
2b384109 | 5309 | return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type, |
fa9f381f | 5310 | _dev_id, search_delay, seek_count, seek, freq); |
b563b388 JM |
5311 | } |
5312 | ||
5313 | ||
e2b7fbf2 MS |
5314 | static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt) |
5315 | { | |
5316 | const char *last = NULL; | |
5317 | const char *token; | |
5318 | long int token_len; | |
5319 | unsigned int i; | |
5320 | ||
5321 | /* Expected predefined CPT names delimited by ':' */ | |
5322 | for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) { | |
5323 | if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) { | |
5324 | wpa_printf(MSG_ERROR, | |
5325 | "P2PS: CPT name list is too long, expected up to %d names", | |
5326 | P2PS_FEATURE_CAPAB_CPT_MAX); | |
5327 | cpt[0] = 0; | |
5328 | return -1; | |
5329 | } | |
5330 | ||
5331 | token_len = last - token; | |
5332 | ||
5333 | if (token_len == 3 && | |
5334 | os_memcmp(token, "UDP", token_len) == 0) { | |
5335 | cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; | |
5336 | } else if (token_len == 3 && | |
5337 | os_memcmp(token, "MAC", token_len) == 0) { | |
5338 | cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT; | |
5339 | } else { | |
5340 | wpa_printf(MSG_ERROR, | |
5341 | "P2PS: Unsupported CPT name '%s'", token); | |
5342 | cpt[0] = 0; | |
5343 | return -1; | |
5344 | } | |
5345 | ||
640b0b93 | 5346 | if (isblank((unsigned char) *last)) { |
e2b7fbf2 MS |
5347 | i++; |
5348 | break; | |
5349 | } | |
5350 | } | |
5351 | cpt[i] = 0; | |
5352 | return 0; | |
5353 | } | |
5354 | ||
5355 | ||
f309c18e KV |
5356 | static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd) |
5357 | { | |
5358 | struct p2ps_provision *p2ps_prov; | |
5359 | char *pos; | |
5360 | size_t info_len = 0; | |
5361 | char *info = NULL; | |
5362 | u8 role = P2PS_SETUP_NONE; | |
5363 | long long unsigned val; | |
0670de74 | 5364 | int i; |
f309c18e KV |
5365 | |
5366 | pos = os_strstr(cmd, "info="); | |
5367 | if (pos) { | |
5368 | pos += 5; | |
5369 | info_len = os_strlen(pos); | |
5370 | ||
5371 | if (info_len) { | |
5372 | info = os_malloc(info_len + 1); | |
5373 | if (info) { | |
5374 | info_len = utf8_unescape(pos, info_len, | |
5375 | info, info_len + 1); | |
5376 | } else | |
5377 | info_len = 0; | |
5378 | } | |
5379 | } | |
5380 | ||
5381 | p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1); | |
5382 | if (p2ps_prov == NULL) { | |
5383 | os_free(info); | |
5384 | return NULL; | |
5385 | } | |
5386 | ||
5387 | if (info) { | |
5388 | os_memcpy(p2ps_prov->info, info, info_len); | |
5389 | p2ps_prov->info[info_len] = '\0'; | |
5390 | os_free(info); | |
5391 | } | |
5392 | ||
5393 | pos = os_strstr(cmd, "status="); | |
5394 | if (pos) | |
5395 | p2ps_prov->status = atoi(pos + 7); | |
5396 | else | |
5397 | p2ps_prov->status = -1; | |
5398 | ||
5399 | pos = os_strstr(cmd, "adv_id="); | |
5400 | if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL) | |
5401 | goto invalid_args; | |
5402 | p2ps_prov->adv_id = val; | |
5403 | ||
5404 | pos = os_strstr(cmd, "method="); | |
5405 | if (pos) | |
5406 | p2ps_prov->method = strtol(pos + 7, NULL, 16); | |
5407 | else | |
5408 | p2ps_prov->method = 0; | |
5409 | ||
5410 | pos = os_strstr(cmd, "session="); | |
5411 | if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL) | |
5412 | goto invalid_args; | |
5413 | p2ps_prov->session_id = val; | |
5414 | ||
5415 | pos = os_strstr(cmd, "adv_mac="); | |
5416 | if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac)) | |
5417 | goto invalid_args; | |
5418 | ||
5419 | pos = os_strstr(cmd, "session_mac="); | |
5420 | if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac)) | |
5421 | goto invalid_args; | |
5422 | ||
0670de74 MS |
5423 | pos = os_strstr(cmd, "cpt="); |
5424 | if (pos) { | |
5425 | if (p2ps_ctrl_parse_cpt_priority(pos + 4, | |
5426 | p2ps_prov->cpt_priority)) | |
5427 | goto invalid_args; | |
5428 | } else { | |
5429 | p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; | |
5430 | } | |
5431 | ||
5432 | for (i = 0; p2ps_prov->cpt_priority[i]; i++) | |
5433 | p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i]; | |
5434 | ||
f309c18e KV |
5435 | /* force conncap with tstCap (no sanity checks) */ |
5436 | pos = os_strstr(cmd, "tstCap="); | |
5437 | if (pos) { | |
5438 | role = strtol(pos + 7, NULL, 16); | |
5439 | } else { | |
5440 | pos = os_strstr(cmd, "role="); | |
5441 | if (pos) { | |
5442 | role = strtol(pos + 5, NULL, 16); | |
5443 | if (role != P2PS_SETUP_CLIENT && | |
5444 | role != P2PS_SETUP_GROUP_OWNER) | |
5445 | role = P2PS_SETUP_NONE; | |
5446 | } | |
5447 | } | |
5448 | p2ps_prov->role = role; | |
5449 | ||
5450 | return p2ps_prov; | |
5451 | ||
5452 | invalid_args: | |
5453 | os_free(p2ps_prov); | |
5454 | return NULL; | |
5455 | } | |
5456 | ||
5457 | ||
5458 | static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd) | |
5459 | { | |
5460 | u8 addr[ETH_ALEN]; | |
5461 | struct p2ps_provision *p2ps_prov; | |
5462 | char *pos; | |
5463 | ||
5464 | /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */ | |
5465 | ||
5466 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); | |
5467 | ||
5468 | if (hwaddr_aton(cmd, addr)) | |
5469 | return -1; | |
5470 | ||
5471 | pos = cmd + 17; | |
5472 | if (*pos != ' ') | |
5473 | return -1; | |
5474 | ||
5475 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); | |
5476 | if (!p2ps_prov) | |
5477 | return -1; | |
5478 | ||
5479 | if (p2ps_prov->status < 0) { | |
5480 | os_free(p2ps_prov); | |
5481 | return -1; | |
5482 | } | |
5483 | ||
5484 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, | |
5485 | p2ps_prov); | |
5486 | } | |
5487 | ||
5488 | ||
5489 | static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd) | |
5490 | { | |
5491 | u8 addr[ETH_ALEN]; | |
5492 | struct p2ps_provision *p2ps_prov; | |
5493 | char *pos; | |
5494 | ||
5495 | /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap> | |
5496 | * session=<ses_id> mac=<ses_mac> [info=<infodata>] | |
5497 | */ | |
5498 | ||
5499 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); | |
5500 | if (hwaddr_aton(cmd, addr)) | |
5501 | return -1; | |
5502 | ||
5503 | pos = cmd + 17; | |
5504 | if (*pos != ' ') | |
5505 | return -1; | |
5506 | ||
5507 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); | |
5508 | if (!p2ps_prov) | |
5509 | return -1; | |
5510 | ||
93f22b45 MS |
5511 | p2ps_prov->pd_seeker = 1; |
5512 | ||
f309c18e KV |
5513 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, |
5514 | p2ps_prov); | |
5515 | } | |
5516 | ||
5517 | ||
c27f4c90 AK |
5518 | static int parse_freq(int chwidth, int freq2) |
5519 | { | |
5520 | if (freq2 < 0) | |
5521 | return -1; | |
5522 | if (freq2) | |
5523 | return VHT_CHANWIDTH_80P80MHZ; | |
5524 | ||
5525 | switch (chwidth) { | |
5526 | case 0: | |
5527 | case 20: | |
5528 | case 40: | |
5529 | return VHT_CHANWIDTH_USE_HT; | |
5530 | case 80: | |
5531 | return VHT_CHANWIDTH_80MHZ; | |
5532 | case 160: | |
5533 | return VHT_CHANWIDTH_160MHZ; | |
5534 | default: | |
5535 | wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d", | |
5536 | chwidth); | |
5537 | return -1; | |
5538 | } | |
5539 | } | |
5540 | ||
5541 | ||
b563b388 JM |
5542 | static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd, |
5543 | char *buf, size_t buflen) | |
5544 | { | |
5545 | u8 addr[ETH_ALEN]; | |
5546 | char *pos, *pos2; | |
5547 | char *pin = NULL; | |
5548 | enum p2p_wps_method wps_method; | |
5549 | int new_pin; | |
5550 | int ret; | |
23c84252 | 5551 | int persistent_group, persistent_id = -1; |
b563b388 JM |
5552 | int join; |
5553 | int auth; | |
b31be3a0 | 5554 | int automatic; |
b563b388 JM |
5555 | int go_intent = -1; |
5556 | int freq = 0; | |
3bc462cb | 5557 | int pd; |
c27f4c90 | 5558 | int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0; |
8edd9f10 JM |
5559 | u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL; |
5560 | size_t group_ssid_len = 0; | |
5a3319ab | 5561 | int he; |
b563b388 | 5562 | |
bdf0518b JM |
5563 | if (!wpa_s->global->p2p_init_wpa_s) |
5564 | return -1; | |
5565 | if (wpa_s->global->p2p_init_wpa_s != wpa_s) { | |
5566 | wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s", | |
5567 | wpa_s->global->p2p_init_wpa_s->ifname); | |
5568 | wpa_s = wpa_s->global->p2p_init_wpa_s; | |
5569 | } | |
5570 | ||
4f88fc04 | 5571 | /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps] |
23c84252 | 5572 | * [persistent|persistent=<network id>] |
e2308e4b | 5573 | * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] |
5a3319ab | 5574 | * [ht40] [vht] [he] [auto] [ssid=<hexdump>] */ |
b563b388 JM |
5575 | |
5576 | if (hwaddr_aton(cmd, addr)) | |
5577 | return -1; | |
5578 | ||
5579 | pos = cmd + 17; | |
5580 | if (*pos != ' ') | |
5581 | return -1; | |
5582 | pos++; | |
5583 | ||
5584 | persistent_group = os_strstr(pos, " persistent") != NULL; | |
23c84252 JM |
5585 | pos2 = os_strstr(pos, " persistent="); |
5586 | if (pos2) { | |
5587 | struct wpa_ssid *ssid; | |
5588 | persistent_id = atoi(pos2 + 12); | |
5589 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); | |
5590 | if (ssid == NULL || ssid->disabled != 2 || | |
5591 | ssid->mode != WPAS_MODE_P2P_GO) { | |
5592 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
5593 | "SSID id=%d for persistent P2P group (GO)", | |
5594 | persistent_id); | |
5595 | return -1; | |
5596 | } | |
5597 | } | |
b563b388 JM |
5598 | join = os_strstr(pos, " join") != NULL; |
5599 | auth = os_strstr(pos, " auth") != NULL; | |
b31be3a0 | 5600 | automatic = os_strstr(pos, " auto") != NULL; |
3bc462cb | 5601 | pd = os_strstr(pos, " provdisc") != NULL; |
20ea1ca4 EP |
5602 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
5603 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | |
5604 | vht; | |
5a3319ab | 5605 | he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he; |
b563b388 JM |
5606 | |
5607 | pos2 = os_strstr(pos, " go_intent="); | |
5608 | if (pos2) { | |
5609 | pos2 += 11; | |
5610 | go_intent = atoi(pos2); | |
5611 | if (go_intent < 0 || go_intent > 15) | |
5612 | return -1; | |
5613 | } | |
5614 | ||
5615 | pos2 = os_strstr(pos, " freq="); | |
5616 | if (pos2) { | |
5617 | pos2 += 6; | |
5618 | freq = atoi(pos2); | |
5619 | if (freq <= 0) | |
5620 | return -1; | |
5621 | } | |
5622 | ||
c27f4c90 AK |
5623 | pos2 = os_strstr(pos, " freq2="); |
5624 | if (pos2) | |
5625 | freq2 = atoi(pos2 + 7); | |
5626 | ||
5627 | pos2 = os_strstr(pos, " max_oper_chwidth="); | |
5628 | if (pos2) | |
5629 | chwidth = atoi(pos2 + 18); | |
5630 | ||
5631 | max_oper_chwidth = parse_freq(chwidth, freq2); | |
5632 | if (max_oper_chwidth < 0) | |
5633 | return -1; | |
5634 | ||
8edd9f10 JM |
5635 | pos2 = os_strstr(pos, " ssid="); |
5636 | if (pos2) { | |
5637 | char *end; | |
5638 | ||
5639 | pos2 += 6; | |
5640 | end = os_strchr(pos2, ' '); | |
5641 | if (!end) | |
5642 | group_ssid_len = os_strlen(pos2) / 2; | |
5643 | else | |
5644 | group_ssid_len = (end - pos2) / 2; | |
5645 | if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN || | |
5646 | hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0) | |
5647 | return -1; | |
5648 | group_ssid = _group_ssid; | |
5649 | } | |
5650 | ||
b563b388 JM |
5651 | if (os_strncmp(pos, "pin", 3) == 0) { |
5652 | /* Request random PIN (to be displayed) and enable the PIN */ | |
5653 | wps_method = WPS_PIN_DISPLAY; | |
5654 | } else if (os_strncmp(pos, "pbc", 3) == 0) { | |
5655 | wps_method = WPS_PBC; | |
31d7fb14 PK |
5656 | } else if (os_strstr(pos, "p2ps") != NULL) { |
5657 | wps_method = WPS_P2PS; | |
b563b388 JM |
5658 | } else { |
5659 | pin = pos; | |
5660 | pos = os_strchr(pin, ' '); | |
5661 | wps_method = WPS_PIN_KEYPAD; | |
5662 | if (pos) { | |
5663 | *pos++ = '\0'; | |
07fecd39 | 5664 | if (os_strncmp(pos, "display", 7) == 0) |
b563b388 JM |
5665 | wps_method = WPS_PIN_DISPLAY; |
5666 | } | |
dcc33057 | 5667 | if (!wps_pin_str_valid(pin)) { |
36ebf7a1 MH |
5668 | os_memcpy(buf, "FAIL-INVALID-PIN\n", 17); |
5669 | return 17; | |
5670 | } | |
b563b388 JM |
5671 | } |
5672 | ||
5673 | new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method, | |
b31be3a0 | 5674 | persistent_group, automatic, join, |
c27f4c90 | 5675 | auth, go_intent, freq, freq2, persistent_id, |
5a3319ab | 5676 | pd, ht40, vht, max_oper_chwidth, he, |
8edd9f10 | 5677 | group_ssid, group_ssid_len); |
d054a462 JM |
5678 | if (new_pin == -2) { |
5679 | os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25); | |
5680 | return 25; | |
5681 | } | |
5682 | if (new_pin == -3) { | |
5683 | os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25); | |
5684 | return 25; | |
5685 | } | |
b563b388 JM |
5686 | if (new_pin < 0) |
5687 | return -1; | |
5688 | if (wps_method == WPS_PIN_DISPLAY && pin == NULL) { | |
5689 | ret = os_snprintf(buf, buflen, "%08d", new_pin); | |
d85e1fc8 | 5690 | if (os_snprintf_error(buflen, ret)) |
b563b388 JM |
5691 | return -1; |
5692 | return ret; | |
5693 | } | |
5694 | ||
5695 | os_memcpy(buf, "OK\n", 3); | |
5696 | return 3; | |
5697 | } | |
5698 | ||
5699 | ||
5700 | static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd) | |
5701 | { | |
5702 | unsigned int timeout = atoi(cmd); | |
e9eb648e JM |
5703 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
5704 | wpa_dbg(wpa_s, MSG_INFO, | |
5705 | "Reject P2P_LISTEN since interface is disabled"); | |
5706 | return -1; | |
5707 | } | |
b563b388 JM |
5708 | return wpas_p2p_listen(wpa_s, timeout); |
5709 | } | |
5710 | ||
5711 | ||
5712 | static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) | |
5713 | { | |
5714 | u8 addr[ETH_ALEN]; | |
5715 | char *pos; | |
0918c4bf | 5716 | enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG; |
b563b388 | 5717 | |
0918c4bf | 5718 | /* <addr> <config method> [join|auto] */ |
b563b388 JM |
5719 | |
5720 | if (hwaddr_aton(cmd, addr)) | |
5721 | return -1; | |
5722 | ||
5723 | pos = cmd + 17; | |
5724 | if (*pos != ' ') | |
5725 | return -1; | |
5726 | pos++; | |
5727 | ||
0918c4bf JM |
5728 | if (os_strstr(pos, " join") != NULL) |
5729 | use = WPAS_P2P_PD_FOR_JOIN; | |
5730 | else if (os_strstr(pos, " auto") != NULL) | |
5731 | use = WPAS_P2P_PD_AUTO; | |
5732 | ||
6d908514 | 5733 | return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL); |
b563b388 JM |
5734 | } |
5735 | ||
5736 | ||
5737 | static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf, | |
5738 | size_t buflen) | |
5739 | { | |
5740 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
5741 | ||
5742 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || | |
5743 | ssid->passphrase == NULL) | |
5744 | return -1; | |
5745 | ||
5746 | os_strlcpy(buf, ssid->passphrase, buflen); | |
5747 | return os_strlen(buf); | |
5748 | } | |
5749 | ||
5750 | ||
5751 | static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd, | |
5752 | char *buf, size_t buflen) | |
5753 | { | |
5754 | u64 ref; | |
5755 | int res; | |
5756 | u8 dst_buf[ETH_ALEN], *dst; | |
5757 | struct wpabuf *tlvs; | |
5758 | char *pos; | |
5759 | size_t len; | |
5760 | ||
5761 | if (hwaddr_aton(cmd, dst_buf)) | |
5762 | return -1; | |
5763 | dst = dst_buf; | |
5764 | if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 && | |
5765 | dst[3] == 0 && dst[4] == 0 && dst[5] == 0) | |
5766 | dst = NULL; | |
5767 | pos = cmd + 17; | |
5768 | if (*pos != ' ') | |
5769 | return -1; | |
5770 | pos++; | |
5771 | ||
5772 | if (os_strncmp(pos, "upnp ", 5) == 0) { | |
5773 | u8 version; | |
5774 | pos += 5; | |
5775 | if (hexstr2bin(pos, &version, 1) < 0) | |
5776 | return -1; | |
5777 | pos += 2; | |
5778 | if (*pos != ' ') | |
5779 | return -1; | |
5780 | pos++; | |
7165c5dc | 5781 | ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos); |
347d6a5b JM |
5782 | #ifdef CONFIG_WIFI_DISPLAY |
5783 | } else if (os_strncmp(pos, "wifi-display ", 13) == 0) { | |
5784 | ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13); | |
5785 | #endif /* CONFIG_WIFI_DISPLAY */ | |
5a4102ce KV |
5786 | } else if (os_strncmp(pos, "asp ", 4) == 0) { |
5787 | char *svc_str; | |
5788 | char *svc_info = NULL; | |
5789 | u32 id; | |
5790 | ||
5791 | pos += 4; | |
5792 | if (sscanf(pos, "%x", &id) != 1 || id > 0xff) | |
5793 | return -1; | |
5794 | ||
5795 | pos = os_strchr(pos, ' '); | |
5796 | if (pos == NULL || pos[1] == '\0' || pos[1] == ' ') | |
5797 | return -1; | |
5798 | ||
5799 | svc_str = pos + 1; | |
5800 | ||
5801 | pos = os_strchr(svc_str, ' '); | |
5802 | ||
5803 | if (pos) | |
5804 | *pos++ = '\0'; | |
5805 | ||
5806 | /* All remaining data is the svc_info string */ | |
5807 | if (pos && pos[0] && pos[0] != ' ') { | |
5808 | len = os_strlen(pos); | |
5809 | ||
5810 | /* Unescape in place */ | |
5811 | len = utf8_unescape(pos, len, pos, len); | |
5812 | if (len > 0xff) | |
5813 | return -1; | |
5814 | ||
5815 | svc_info = pos; | |
5816 | } | |
5817 | ||
5818 | ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id, | |
5819 | svc_str, svc_info); | |
b563b388 JM |
5820 | } else { |
5821 | len = os_strlen(pos); | |
5822 | if (len & 1) | |
5823 | return -1; | |
5824 | len /= 2; | |
5825 | tlvs = wpabuf_alloc(len); | |
5826 | if (tlvs == NULL) | |
5827 | return -1; | |
5828 | if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) { | |
5829 | wpabuf_free(tlvs); | |
5830 | return -1; | |
5831 | } | |
5832 | ||
7165c5dc | 5833 | ref = wpas_p2p_sd_request(wpa_s, dst, tlvs); |
b563b388 JM |
5834 | wpabuf_free(tlvs); |
5835 | } | |
7165c5dc JM |
5836 | if (ref == 0) |
5837 | return -1; | |
b563b388 | 5838 | res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref); |
d85e1fc8 | 5839 | if (os_snprintf_error(buflen, res)) |
b563b388 JM |
5840 | return -1; |
5841 | return res; | |
5842 | } | |
5843 | ||
5844 | ||
5845 | static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s, | |
5846 | char *cmd) | |
5847 | { | |
5848 | long long unsigned val; | |
5849 | u64 req; | |
5850 | if (sscanf(cmd, "%llx", &val) != 1) | |
5851 | return -1; | |
5852 | req = val; | |
7165c5dc | 5853 | return wpas_p2p_sd_cancel_request(wpa_s, req); |
b563b388 JM |
5854 | } |
5855 | ||
5856 | ||
5857 | static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd) | |
5858 | { | |
5859 | int freq; | |
d25f7212 | 5860 | u8 dst[ETH_ALEN]; |
b563b388 JM |
5861 | u8 dialog_token; |
5862 | struct wpabuf *resp_tlvs; | |
5863 | char *pos, *pos2; | |
5864 | size_t len; | |
5865 | ||
5866 | pos = os_strchr(cmd, ' '); | |
5867 | if (pos == NULL) | |
5868 | return -1; | |
5869 | *pos++ = '\0'; | |
5870 | freq = atoi(cmd); | |
5871 | if (freq == 0) | |
5872 | return -1; | |
5873 | ||
d25f7212 | 5874 | if (hwaddr_aton(pos, dst)) |
b563b388 | 5875 | return -1; |
b563b388 JM |
5876 | pos += 17; |
5877 | if (*pos != ' ') | |
5878 | return -1; | |
5879 | pos++; | |
5880 | ||
5881 | pos2 = os_strchr(pos, ' '); | |
5882 | if (pos2 == NULL) | |
5883 | return -1; | |
5884 | *pos2++ = '\0'; | |
5885 | dialog_token = atoi(pos); | |
5886 | ||
5887 | len = os_strlen(pos2); | |
5888 | if (len & 1) | |
5889 | return -1; | |
5890 | len /= 2; | |
5891 | resp_tlvs = wpabuf_alloc(len); | |
5892 | if (resp_tlvs == NULL) | |
5893 | return -1; | |
5894 | if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) { | |
5895 | wpabuf_free(resp_tlvs); | |
5896 | return -1; | |
5897 | } | |
5898 | ||
5899 | wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs); | |
5900 | wpabuf_free(resp_tlvs); | |
5901 | return 0; | |
5902 | } | |
5903 | ||
5904 | ||
5905 | static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s, | |
5906 | char *cmd) | |
5907 | { | |
28ef705d GB |
5908 | if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1")) |
5909 | return -1; | |
b563b388 JM |
5910 | wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd); |
5911 | return 0; | |
5912 | } | |
5913 | ||
5914 | ||
5915 | static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s, | |
5916 | char *cmd) | |
5917 | { | |
5918 | char *pos; | |
5919 | size_t len; | |
5920 | struct wpabuf *query, *resp; | |
5921 | ||
5922 | pos = os_strchr(cmd, ' '); | |
5923 | if (pos == NULL) | |
5924 | return -1; | |
5925 | *pos++ = '\0'; | |
5926 | ||
5927 | len = os_strlen(cmd); | |
5928 | if (len & 1) | |
5929 | return -1; | |
5930 | len /= 2; | |
5931 | query = wpabuf_alloc(len); | |
5932 | if (query == NULL) | |
5933 | return -1; | |
5934 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | |
5935 | wpabuf_free(query); | |
5936 | return -1; | |
5937 | } | |
5938 | ||
5939 | len = os_strlen(pos); | |
5940 | if (len & 1) { | |
5941 | wpabuf_free(query); | |
5942 | return -1; | |
5943 | } | |
5944 | len /= 2; | |
5945 | resp = wpabuf_alloc(len); | |
5946 | if (resp == NULL) { | |
5947 | wpabuf_free(query); | |
5948 | return -1; | |
5949 | } | |
5950 | if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) { | |
5951 | wpabuf_free(query); | |
5952 | wpabuf_free(resp); | |
5953 | return -1; | |
5954 | } | |
5955 | ||
5956 | if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) { | |
5957 | wpabuf_free(query); | |
5958 | wpabuf_free(resp); | |
5959 | return -1; | |
5960 | } | |
5961 | return 0; | |
5962 | } | |
5963 | ||
5964 | ||
5965 | static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd) | |
5966 | { | |
5967 | char *pos; | |
5968 | u8 version; | |
5969 | ||
5970 | pos = os_strchr(cmd, ' '); | |
5971 | if (pos == NULL) | |
5972 | return -1; | |
5973 | *pos++ = '\0'; | |
5974 | ||
5975 | if (hexstr2bin(cmd, &version, 1) < 0) | |
5976 | return -1; | |
5977 | ||
5978 | return wpas_p2p_service_add_upnp(wpa_s, version, pos); | |
5979 | } | |
5980 | ||
5981 | ||
ae9d45f3 KV |
5982 | static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s, |
5983 | u8 replace, char *cmd) | |
5984 | { | |
5985 | char *pos; | |
5986 | char *adv_str; | |
5987 | u32 auto_accept, adv_id, svc_state, config_methods; | |
5988 | char *svc_info = NULL; | |
e2b7fbf2 MS |
5989 | char *cpt_prio_str; |
5990 | u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1]; | |
ae9d45f3 KV |
5991 | |
5992 | pos = os_strchr(cmd, ' '); | |
5993 | if (pos == NULL) | |
5994 | return -1; | |
5995 | *pos++ = '\0'; | |
5996 | ||
5997 | /* Auto-Accept value is mandatory, and must be one of the | |
5998 | * single values (0, 1, 2, 4) */ | |
5999 | auto_accept = atoi(cmd); | |
6000 | switch (auto_accept) { | |
6001 | case P2PS_SETUP_NONE: /* No auto-accept */ | |
6002 | case P2PS_SETUP_NEW: | |
6003 | case P2PS_SETUP_CLIENT: | |
6004 | case P2PS_SETUP_GROUP_OWNER: | |
6005 | break; | |
6006 | default: | |
6007 | return -1; | |
6008 | } | |
6009 | ||
6010 | /* Advertisement ID is mandatory */ | |
6011 | cmd = pos; | |
6012 | pos = os_strchr(cmd, ' '); | |
6013 | if (pos == NULL) | |
6014 | return -1; | |
6015 | *pos++ = '\0'; | |
6016 | ||
6017 | /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */ | |
6018 | if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0) | |
6019 | return -1; | |
6020 | ||
6021 | /* Only allow replacements if exist, and adds if not */ | |
6022 | if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) { | |
6023 | if (!replace) | |
6024 | return -1; | |
6025 | } else { | |
6026 | if (replace) | |
6027 | return -1; | |
6028 | } | |
6029 | ||
6030 | /* svc_state between 0 - 0xff is mandatory */ | |
6031 | if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff) | |
6032 | return -1; | |
6033 | ||
6034 | pos = os_strchr(pos, ' '); | |
6035 | if (pos == NULL) | |
6036 | return -1; | |
6037 | ||
6038 | /* config_methods is mandatory */ | |
6039 | pos++; | |
6040 | if (sscanf(pos, "%x", &config_methods) != 1) | |
6041 | return -1; | |
6042 | ||
6043 | if (!(config_methods & | |
6044 | (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS))) | |
6045 | return -1; | |
6046 | ||
6047 | pos = os_strchr(pos, ' '); | |
6048 | if (pos == NULL) | |
6049 | return -1; | |
6050 | ||
6051 | pos++; | |
6052 | adv_str = pos; | |
6053 | ||
6054 | /* Advertisement string is mandatory */ | |
6055 | if (!pos[0] || pos[0] == ' ') | |
6056 | return -1; | |
6057 | ||
6058 | /* Terminate svc string */ | |
6059 | pos = os_strchr(pos, ' '); | |
6060 | if (pos != NULL) | |
6061 | *pos++ = '\0'; | |
6062 | ||
e2b7fbf2 MS |
6063 | cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL; |
6064 | if (cpt_prio_str) { | |
6065 | pos = os_strchr(pos, ' '); | |
6066 | if (pos != NULL) | |
6067 | *pos++ = '\0'; | |
6068 | ||
6069 | if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio)) | |
6070 | return -1; | |
6071 | } else { | |
6072 | cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; | |
6073 | cpt_prio[1] = 0; | |
6074 | } | |
6075 | ||
ae9d45f3 KV |
6076 | /* Service and Response Information are optional */ |
6077 | if (pos && pos[0]) { | |
6078 | size_t len; | |
6079 | ||
6080 | /* Note the bare ' included, which cannot exist legally | |
6081 | * in unescaped string. */ | |
6082 | svc_info = os_strstr(pos, "svc_info='"); | |
6083 | ||
6084 | if (svc_info) { | |
6085 | svc_info += 9; | |
6086 | len = os_strlen(svc_info); | |
6087 | utf8_unescape(svc_info, len, svc_info, len); | |
6088 | } | |
6089 | } | |
6090 | ||
6091 | return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str, | |
6092 | (u8) svc_state, (u16) config_methods, | |
e2b7fbf2 | 6093 | svc_info, cpt_prio); |
ae9d45f3 KV |
6094 | } |
6095 | ||
6096 | ||
b563b388 JM |
6097 | static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd) |
6098 | { | |
6099 | char *pos; | |
6100 | ||
6101 | pos = os_strchr(cmd, ' '); | |
6102 | if (pos == NULL) | |
6103 | return -1; | |
6104 | *pos++ = '\0'; | |
6105 | ||
6106 | if (os_strcmp(cmd, "bonjour") == 0) | |
6107 | return p2p_ctrl_service_add_bonjour(wpa_s, pos); | |
6108 | if (os_strcmp(cmd, "upnp") == 0) | |
6109 | return p2p_ctrl_service_add_upnp(wpa_s, pos); | |
ae9d45f3 KV |
6110 | if (os_strcmp(cmd, "asp") == 0) |
6111 | return p2p_ctrl_service_add_asp(wpa_s, 0, pos); | |
b563b388 JM |
6112 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
6113 | return -1; | |
6114 | } | |
6115 | ||
6116 | ||
6117 | static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s, | |
6118 | char *cmd) | |
6119 | { | |
6120 | size_t len; | |
6121 | struct wpabuf *query; | |
6122 | int ret; | |
6123 | ||
6124 | len = os_strlen(cmd); | |
6125 | if (len & 1) | |
6126 | return -1; | |
6127 | len /= 2; | |
6128 | query = wpabuf_alloc(len); | |
6129 | if (query == NULL) | |
6130 | return -1; | |
6131 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | |
6132 | wpabuf_free(query); | |
6133 | return -1; | |
6134 | } | |
6135 | ||
6136 | ret = wpas_p2p_service_del_bonjour(wpa_s, query); | |
6137 | wpabuf_free(query); | |
6138 | return ret; | |
6139 | } | |
6140 | ||
6141 | ||
6142 | static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd) | |
6143 | { | |
6144 | char *pos; | |
6145 | u8 version; | |
6146 | ||
6147 | pos = os_strchr(cmd, ' '); | |
6148 | if (pos == NULL) | |
6149 | return -1; | |
6150 | *pos++ = '\0'; | |
6151 | ||
6152 | if (hexstr2bin(cmd, &version, 1) < 0) | |
6153 | return -1; | |
6154 | ||
6155 | return wpas_p2p_service_del_upnp(wpa_s, version, pos); | |
6156 | } | |
6157 | ||
6158 | ||
ae9d45f3 KV |
6159 | static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd) |
6160 | { | |
6161 | u32 adv_id; | |
6162 | ||
e9d28050 MS |
6163 | if (os_strcmp(cmd, "all") == 0) { |
6164 | wpas_p2p_service_flush_asp(wpa_s); | |
6165 | return 0; | |
6166 | } | |
6167 | ||
ae9d45f3 KV |
6168 | if (sscanf(cmd, "%x", &adv_id) != 1) |
6169 | return -1; | |
6170 | ||
6171 | return wpas_p2p_service_del_asp(wpa_s, adv_id); | |
6172 | } | |
6173 | ||
6174 | ||
b563b388 JM |
6175 | static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd) |
6176 | { | |
6177 | char *pos; | |
6178 | ||
6179 | pos = os_strchr(cmd, ' '); | |
6180 | if (pos == NULL) | |
6181 | return -1; | |
6182 | *pos++ = '\0'; | |
6183 | ||
6184 | if (os_strcmp(cmd, "bonjour") == 0) | |
6185 | return p2p_ctrl_service_del_bonjour(wpa_s, pos); | |
6186 | if (os_strcmp(cmd, "upnp") == 0) | |
6187 | return p2p_ctrl_service_del_upnp(wpa_s, pos); | |
ae9d45f3 KV |
6188 | if (os_strcmp(cmd, "asp") == 0) |
6189 | return p2p_ctrl_service_del_asp(wpa_s, pos); | |
6190 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | |
6191 | return -1; | |
6192 | } | |
6193 | ||
6194 | ||
6195 | static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd) | |
6196 | { | |
6197 | char *pos; | |
6198 | ||
6199 | pos = os_strchr(cmd, ' '); | |
6200 | if (pos == NULL) | |
6201 | return -1; | |
6202 | *pos++ = '\0'; | |
6203 | ||
6204 | if (os_strcmp(cmd, "asp") == 0) | |
6205 | return p2p_ctrl_service_add_asp(wpa_s, 1, pos); | |
6206 | ||
b563b388 JM |
6207 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
6208 | return -1; | |
6209 | } | |
6210 | ||
6211 | ||
6212 | static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd) | |
6213 | { | |
6214 | u8 addr[ETH_ALEN]; | |
6215 | ||
6216 | /* <addr> */ | |
6217 | ||
6218 | if (hwaddr_aton(cmd, addr)) | |
6219 | return -1; | |
6220 | ||
6221 | return wpas_p2p_reject(wpa_s, addr); | |
6222 | } | |
6223 | ||
6224 | ||
6225 | static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd) | |
6226 | { | |
6227 | char *pos; | |
6228 | int id; | |
6229 | struct wpa_ssid *ssid; | |
54c61e6e | 6230 | u8 *_peer = NULL, peer[ETH_ALEN]; |
f5877af0 | 6231 | int freq = 0, pref_freq = 0; |
5a3319ab | 6232 | int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0; |
b563b388 JM |
6233 | |
6234 | id = atoi(cmd); | |
6235 | pos = os_strstr(cmd, " peer="); | |
6236 | if (pos) { | |
6237 | pos += 6; | |
6238 | if (hwaddr_aton(pos, peer)) | |
6239 | return -1; | |
54c61e6e | 6240 | _peer = peer; |
b563b388 JM |
6241 | } |
6242 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
6243 | if (ssid == NULL || ssid->disabled != 2) { | |
6244 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
6245 | "for persistent P2P group", | |
6246 | id); | |
6247 | return -1; | |
6248 | } | |
6249 | ||
4d32c0c4 JM |
6250 | pos = os_strstr(cmd, " freq="); |
6251 | if (pos) { | |
6252 | pos += 6; | |
6253 | freq = atoi(pos); | |
6254 | if (freq <= 0) | |
6255 | return -1; | |
6256 | } | |
6257 | ||
f5877af0 JM |
6258 | pos = os_strstr(cmd, " pref="); |
6259 | if (pos) { | |
6260 | pos += 6; | |
6261 | pref_freq = atoi(pos); | |
6262 | if (pref_freq <= 0) | |
6263 | return -1; | |
6264 | } | |
6265 | ||
20ea1ca4 EP |
6266 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
6267 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | |
6268 | vht; | |
5a3319ab | 6269 | he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he; |
4d32c0c4 | 6270 | |
c27f4c90 AK |
6271 | pos = os_strstr(cmd, "freq2="); |
6272 | if (pos) | |
6273 | freq2 = atoi(pos + 6); | |
6274 | ||
6275 | pos = os_strstr(cmd, " max_oper_chwidth="); | |
6276 | if (pos) | |
6277 | chwidth = atoi(pos + 18); | |
6278 | ||
6279 | max_oper_chwidth = parse_freq(chwidth, freq2); | |
6280 | if (max_oper_chwidth < 0) | |
6281 | return -1; | |
6282 | ||
6283 | return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht, | |
5a3319ab | 6284 | max_oper_chwidth, pref_freq, he); |
b563b388 JM |
6285 | } |
6286 | ||
6287 | ||
6288 | static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd) | |
6289 | { | |
6290 | char *pos; | |
6291 | u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL; | |
6292 | ||
6293 | pos = os_strstr(cmd, " peer="); | |
6294 | if (!pos) | |
6295 | return -1; | |
6296 | ||
6297 | *pos = '\0'; | |
6298 | pos += 6; | |
6299 | if (hwaddr_aton(pos, peer)) { | |
6300 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos); | |
6301 | return -1; | |
6302 | } | |
6303 | ||
6304 | pos = os_strstr(pos, " go_dev_addr="); | |
6305 | if (pos) { | |
6306 | pos += 13; | |
6307 | if (hwaddr_aton(pos, go_dev_addr)) { | |
6308 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", | |
6309 | pos); | |
6310 | return -1; | |
6311 | } | |
6312 | go_dev = go_dev_addr; | |
6313 | } | |
6314 | ||
6315 | return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev); | |
6316 | } | |
6317 | ||
6318 | ||
6319 | static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd) | |
6320 | { | |
6321 | if (os_strncmp(cmd, "persistent=", 11) == 0) | |
6322 | return p2p_ctrl_invite_persistent(wpa_s, cmd + 11); | |
6323 | if (os_strncmp(cmd, "group=", 6) == 0) | |
6324 | return p2p_ctrl_invite_group(wpa_s, cmd + 6); | |
6325 | ||
6326 | return -1; | |
6327 | } | |
6328 | ||
6329 | ||
6330 | static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, | |
c27f4c90 | 6331 | int id, int freq, int vht_center_freq2, |
5a3319ab PX |
6332 | int ht40, int vht, int vht_chwidth, |
6333 | int he) | |
b563b388 | 6334 | { |
b563b388 JM |
6335 | struct wpa_ssid *ssid; |
6336 | ||
b563b388 JM |
6337 | ssid = wpa_config_get_network(wpa_s->conf, id); |
6338 | if (ssid == NULL || ssid->disabled != 2) { | |
6339 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
6340 | "for persistent P2P group", | |
6341 | id); | |
6342 | return -1; | |
6343 | } | |
6344 | ||
c27f4c90 AK |
6345 | return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, |
6346 | vht_center_freq2, 0, ht40, vht, | |
5a3319ab | 6347 | vht_chwidth, he, NULL, 0, 0); |
b563b388 JM |
6348 | } |
6349 | ||
6350 | ||
6351 | static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) | |
6352 | { | |
29292d53 EP |
6353 | int freq = 0, persistent = 0, group_id = -1; |
6354 | int vht = wpa_s->conf->p2p_go_vht; | |
6355 | int ht40 = wpa_s->conf->p2p_go_ht40 || vht; | |
5a3319ab | 6356 | int he = wpa_s->conf->p2p_go_he; |
c27f4c90 | 6357 | int max_oper_chwidth, chwidth = 0, freq2 = 0; |
29292d53 | 6358 | char *token, *context = NULL; |
37ed3254 SD |
6359 | #ifdef CONFIG_ACS |
6360 | int acs = 0; | |
6361 | #endif /* CONFIG_ACS */ | |
e11776a5 | 6362 | |
29292d53 | 6363 | while ((token = str_token(cmd, " ", &context))) { |
37ed3254 | 6364 | if (sscanf(token, "freq2=%d", &freq2) == 1 || |
c27f4c90 AK |
6365 | sscanf(token, "persistent=%d", &group_id) == 1 || |
6366 | sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) { | |
29292d53 | 6367 | continue; |
37ed3254 SD |
6368 | #ifdef CONFIG_ACS |
6369 | } else if (os_strcmp(token, "freq=acs") == 0) { | |
6370 | acs = 1; | |
6371 | #endif /* CONFIG_ACS */ | |
6372 | } else if (sscanf(token, "freq=%d", &freq) == 1) { | |
6373 | continue; | |
29292d53 EP |
6374 | } else if (os_strcmp(token, "ht40") == 0) { |
6375 | ht40 = 1; | |
6376 | } else if (os_strcmp(token, "vht") == 0) { | |
6377 | vht = 1; | |
6378 | ht40 = 1; | |
5a3319ab PX |
6379 | } else if (os_strcmp(token, "he") == 0) { |
6380 | he = 1; | |
29292d53 EP |
6381 | } else if (os_strcmp(token, "persistent") == 0) { |
6382 | persistent = 1; | |
6383 | } else { | |
6384 | wpa_printf(MSG_DEBUG, | |
6385 | "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'", | |
6386 | token); | |
6387 | return -1; | |
6388 | } | |
e11776a5 PK |
6389 | } |
6390 | ||
37ed3254 SD |
6391 | #ifdef CONFIG_ACS |
6392 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) && | |
6393 | (acs || freq == 2 || freq == 5)) { | |
6394 | if (freq == 2 && wpa_s->best_24_freq <= 0) { | |
6395 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G; | |
6396 | wpa_s->p2p_go_do_acs = 1; | |
6397 | freq = 0; | |
6398 | } else if (freq == 5 && wpa_s->best_5_freq <= 0) { | |
6399 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A; | |
6400 | wpa_s->p2p_go_do_acs = 1; | |
6401 | freq = 0; | |
6402 | } else { | |
6403 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY; | |
6404 | wpa_s->p2p_go_do_acs = 1; | |
6405 | } | |
6406 | } | |
6407 | #endif /* CONFIG_ACS */ | |
6408 | ||
c27f4c90 AK |
6409 | max_oper_chwidth = parse_freq(chwidth, freq2); |
6410 | if (max_oper_chwidth < 0) | |
6411 | return -1; | |
6412 | ||
29292d53 EP |
6413 | if (group_id >= 0) |
6414 | return p2p_ctrl_group_add_persistent(wpa_s, group_id, | |
c27f4c90 | 6415 | freq, freq2, ht40, vht, |
5a3319ab | 6416 | max_oper_chwidth, he); |
29292d53 | 6417 | |
c27f4c90 | 6418 | return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht, |
5a3319ab | 6419 | max_oper_chwidth, he); |
b563b388 JM |
6420 | } |
6421 | ||
6422 | ||
57b38882 PK |
6423 | static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd, |
6424 | char *buf, size_t buflen) | |
6425 | { | |
6426 | u8 dev_addr[ETH_ALEN]; | |
6427 | struct wpa_ssid *ssid; | |
6428 | int res; | |
6429 | const u8 *iaddr; | |
6430 | ||
6431 | ssid = wpa_s->current_ssid; | |
6432 | if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO || | |
6433 | hwaddr_aton(cmd, dev_addr)) | |
6434 | return -1; | |
6435 | ||
6436 | iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr); | |
6437 | if (!iaddr) | |
6438 | return -1; | |
6439 | res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr)); | |
6440 | if (os_snprintf_error(buflen, res)) | |
6441 | return -1; | |
6442 | return res; | |
6443 | } | |
6444 | ||
6445 | ||
f47f9361 SD |
6446 | static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global, |
6447 | const u8 *p2p_dev_addr) | |
6448 | { | |
6449 | struct wpa_supplicant *wpa_s; | |
6450 | ||
6451 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
6452 | if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr)) | |
6453 | return 1; | |
6454 | } | |
6455 | ||
6456 | return 0; | |
6457 | } | |
6458 | ||
6459 | ||
b563b388 JM |
6460 | static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd, |
6461 | char *buf, size_t buflen) | |
6462 | { | |
f47f9361 | 6463 | u8 addr[ETH_ALEN], *addr_ptr, group_capab; |
b3ffc80b JM |
6464 | int next, res; |
6465 | const struct p2p_peer_info *info; | |
6466 | char *pos, *end; | |
6467 | char devtype[WPS_DEV_TYPE_BUFSIZE]; | |
87f841a1 | 6468 | struct wpa_ssid *ssid; |
f3989ced | 6469 | size_t i; |
b563b388 JM |
6470 | |
6471 | if (!wpa_s->global->p2p) | |
6472 | return -1; | |
6473 | ||
6474 | if (os_strcmp(cmd, "FIRST") == 0) { | |
6475 | addr_ptr = NULL; | |
6476 | next = 0; | |
6477 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | |
6478 | if (hwaddr_aton(cmd + 5, addr) < 0) | |
6479 | return -1; | |
6480 | addr_ptr = addr; | |
6481 | next = 1; | |
6482 | } else { | |
6483 | if (hwaddr_aton(cmd, addr) < 0) | |
6484 | return -1; | |
6485 | addr_ptr = addr; | |
6486 | next = 0; | |
6487 | } | |
6488 | ||
b3ffc80b JM |
6489 | info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next); |
6490 | if (info == NULL) | |
6491 | return -1; | |
f47f9361 SD |
6492 | group_capab = info->group_capab; |
6493 | ||
6494 | if (group_capab && | |
6495 | !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) { | |
6496 | wpa_printf(MSG_DEBUG, | |
6497 | "P2P: Could not find any BSS with p2p_dev_addr " | |
6498 | MACSTR ", hence override group_capab from 0x%x to 0", | |
6499 | MAC2STR(info->p2p_device_addr), group_capab); | |
6500 | group_capab = 0; | |
6501 | } | |
b3ffc80b JM |
6502 | |
6503 | pos = buf; | |
6504 | end = buf + buflen; | |
6505 | ||
6506 | res = os_snprintf(pos, end - pos, MACSTR "\n" | |
6507 | "pri_dev_type=%s\n" | |
6508 | "device_name=%s\n" | |
6509 | "manufacturer=%s\n" | |
6510 | "model_name=%s\n" | |
6511 | "model_number=%s\n" | |
6512 | "serial_number=%s\n" | |
6513 | "config_methods=0x%x\n" | |
6514 | "dev_capab=0x%x\n" | |
6515 | "group_capab=0x%x\n" | |
6516 | "level=%d\n", | |
6517 | MAC2STR(info->p2p_device_addr), | |
6518 | wps_dev_type_bin2str(info->pri_dev_type, | |
6519 | devtype, sizeof(devtype)), | |
6520 | info->device_name, | |
6521 | info->manufacturer, | |
6522 | info->model_name, | |
6523 | info->model_number, | |
6524 | info->serial_number, | |
6525 | info->config_methods, | |
6526 | info->dev_capab, | |
f47f9361 | 6527 | group_capab, |
b3ffc80b | 6528 | info->level); |
d85e1fc8 | 6529 | if (os_snprintf_error(end - pos, res)) |
b3ffc80b JM |
6530 | return pos - buf; |
6531 | pos += res; | |
6532 | ||
f3989ced JM |
6533 | for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++) |
6534 | { | |
6535 | const u8 *t; | |
6536 | t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN]; | |
6537 | res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n", | |
6538 | wps_dev_type_bin2str(t, devtype, | |
6539 | sizeof(devtype))); | |
d85e1fc8 | 6540 | if (os_snprintf_error(end - pos, res)) |
f3989ced JM |
6541 | return pos - buf; |
6542 | pos += res; | |
6543 | } | |
6544 | ||
c427ac92 | 6545 | ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0); |
87f841a1 JM |
6546 | if (ssid) { |
6547 | res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id); | |
d85e1fc8 | 6548 | if (os_snprintf_error(end - pos, res)) |
87f841a1 JM |
6549 | return pos - buf; |
6550 | pos += res; | |
6551 | } | |
6552 | ||
b3ffc80b JM |
6553 | res = p2p_get_peer_info_txt(info, pos, end - pos); |
6554 | if (res < 0) | |
87f841a1 | 6555 | return pos - buf; |
b3ffc80b JM |
6556 | pos += res; |
6557 | ||
71a0e395 JM |
6558 | if (info->vendor_elems) { |
6559 | res = os_snprintf(pos, end - pos, "vendor_elems="); | |
d85e1fc8 | 6560 | if (os_snprintf_error(end - pos, res)) |
71a0e395 JM |
6561 | return pos - buf; |
6562 | pos += res; | |
6563 | ||
6564 | pos += wpa_snprintf_hex(pos, end - pos, | |
6565 | wpabuf_head(info->vendor_elems), | |
6566 | wpabuf_len(info->vendor_elems)); | |
6567 | ||
6568 | res = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 6569 | if (os_snprintf_error(end - pos, res)) |
71a0e395 JM |
6570 | return pos - buf; |
6571 | pos += res; | |
6572 | } | |
6573 | ||
b3ffc80b | 6574 | return pos - buf; |
b563b388 JM |
6575 | } |
6576 | ||
6577 | ||
6f3bc72b JM |
6578 | static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s, |
6579 | const char *param) | |
6580 | { | |
af8a827b | 6581 | unsigned int i; |
6f3bc72b JM |
6582 | |
6583 | if (wpa_s->global->p2p == NULL) | |
6584 | return -1; | |
6585 | ||
af8a827b JM |
6586 | if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0) |
6587 | return -1; | |
6f3bc72b | 6588 | |
af8a827b JM |
6589 | for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) { |
6590 | struct wpa_freq_range *freq; | |
6591 | freq = &wpa_s->global->p2p_disallow_freq.range[i]; | |
6f3bc72b | 6592 | wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u", |
af8a827b | 6593 | freq->min, freq->max); |
6f3bc72b JM |
6594 | } |
6595 | ||
3a8f008a | 6596 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW); |
6f3bc72b JM |
6597 | return 0; |
6598 | } | |
6599 | ||
6600 | ||
b563b388 JM |
6601 | static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) |
6602 | { | |
6603 | char *param; | |
6604 | ||
6605 | if (wpa_s->global->p2p == NULL) | |
6606 | return -1; | |
6607 | ||
6608 | param = os_strchr(cmd, ' '); | |
6609 | if (param == NULL) | |
6610 | return -1; | |
6611 | *param++ = '\0'; | |
6612 | ||
6613 | if (os_strcmp(cmd, "discoverability") == 0) { | |
6614 | p2p_set_client_discoverability(wpa_s->global->p2p, | |
6615 | atoi(param)); | |
6616 | return 0; | |
6617 | } | |
6618 | ||
6619 | if (os_strcmp(cmd, "managed") == 0) { | |
6620 | p2p_set_managed_oper(wpa_s->global->p2p, atoi(param)); | |
6621 | return 0; | |
6622 | } | |
6623 | ||
6624 | if (os_strcmp(cmd, "listen_channel") == 0) { | |
dfe0745c LD |
6625 | char *pos; |
6626 | u8 channel, op_class; | |
6627 | ||
6628 | channel = atoi(param); | |
6629 | pos = os_strchr(param, ' '); | |
6630 | op_class = pos ? atoi(pos) : 81; | |
6631 | ||
6632 | return p2p_set_listen_channel(wpa_s->global->p2p, op_class, | |
6633 | channel, 1); | |
b563b388 JM |
6634 | } |
6635 | ||
6636 | if (os_strcmp(cmd, "ssid_postfix") == 0) { | |
6637 | return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param, | |
6638 | os_strlen(param)); | |
6639 | } | |
6640 | ||
6641 | if (os_strcmp(cmd, "noa") == 0) { | |
6642 | char *pos; | |
6643 | int count, start, duration; | |
6644 | /* GO NoA parameters: count,start_offset(ms),duration(ms) */ | |
6645 | count = atoi(param); | |
6646 | pos = os_strchr(param, ','); | |
6647 | if (pos == NULL) | |
6648 | return -1; | |
6649 | pos++; | |
6650 | start = atoi(pos); | |
6651 | pos = os_strchr(pos, ','); | |
6652 | if (pos == NULL) | |
6653 | return -1; | |
6654 | pos++; | |
6655 | duration = atoi(pos); | |
6656 | if (count < 0 || count > 255 || start < 0 || duration < 0) | |
6657 | return -1; | |
6658 | if (count == 0 && duration > 0) | |
6659 | return -1; | |
6660 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d " | |
6661 | "start=%d duration=%d", count, start, duration); | |
aefb53bd | 6662 | return wpas_p2p_set_noa(wpa_s, count, start, duration); |
b563b388 JM |
6663 | } |
6664 | ||
c381508d JM |
6665 | if (os_strcmp(cmd, "ps") == 0) |
6666 | return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1); | |
6667 | ||
6668 | if (os_strcmp(cmd, "oppps") == 0) | |
6669 | return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1); | |
6670 | ||
6671 | if (os_strcmp(cmd, "ctwindow") == 0) | |
6672 | return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param)); | |
6673 | ||
b563b388 JM |
6674 | if (os_strcmp(cmd, "disabled") == 0) { |
6675 | wpa_s->global->p2p_disabled = atoi(param); | |
6676 | wpa_printf(MSG_DEBUG, "P2P functionality %s", | |
6677 | wpa_s->global->p2p_disabled ? | |
6678 | "disabled" : "enabled"); | |
6679 | if (wpa_s->global->p2p_disabled) { | |
6680 | wpas_p2p_stop_find(wpa_s); | |
108def93 | 6681 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
b563b388 JM |
6682 | p2p_flush(wpa_s->global->p2p); |
6683 | } | |
6684 | return 0; | |
6685 | } | |
6686 | ||
b9cfc09a JJ |
6687 | if (os_strcmp(cmd, "conc_pref") == 0) { |
6688 | if (os_strcmp(param, "sta") == 0) | |
6689 | wpa_s->global->conc_pref = WPA_CONC_PREF_STA; | |
6690 | else if (os_strcmp(param, "p2p") == 0) | |
6691 | wpa_s->global->conc_pref = WPA_CONC_PREF_P2P; | |
6692 | else { | |
6693 | wpa_printf(MSG_INFO, "Invalid conc_pref value"); | |
6694 | return -1; | |
6695 | } | |
6696 | wpa_printf(MSG_DEBUG, "Single channel concurrency preference: " | |
6697 | "%s", param); | |
6698 | return 0; | |
6699 | } | |
6700 | ||
6e6963ea JM |
6701 | if (os_strcmp(cmd, "force_long_sd") == 0) { |
6702 | wpa_s->force_long_sd = atoi(param); | |
6703 | return 0; | |
6704 | } | |
6705 | ||
80c9582a JM |
6706 | if (os_strcmp(cmd, "peer_filter") == 0) { |
6707 | u8 addr[ETH_ALEN]; | |
6708 | if (hwaddr_aton(param, addr)) | |
6709 | return -1; | |
6710 | p2p_set_peer_filter(wpa_s->global->p2p, addr); | |
6711 | return 0; | |
6712 | } | |
6713 | ||
72044390 JM |
6714 | if (os_strcmp(cmd, "cross_connect") == 0) |
6715 | return wpas_p2p_set_cross_connect(wpa_s, atoi(param)); | |
6716 | ||
eea2fd9e JM |
6717 | if (os_strcmp(cmd, "go_apsd") == 0) { |
6718 | if (os_strcmp(param, "disable") == 0) | |
6719 | wpa_s->set_ap_uapsd = 0; | |
6720 | else { | |
6721 | wpa_s->set_ap_uapsd = 1; | |
6722 | wpa_s->ap_uapsd = atoi(param); | |
6723 | } | |
6724 | return 0; | |
6725 | } | |
6726 | ||
6727 | if (os_strcmp(cmd, "client_apsd") == 0) { | |
6728 | if (os_strcmp(param, "disable") == 0) | |
6729 | wpa_s->set_sta_uapsd = 0; | |
6730 | else { | |
6731 | int be, bk, vi, vo; | |
6732 | char *pos; | |
6733 | /* format: BE,BK,VI,VO;max SP Length */ | |
6734 | be = atoi(param); | |
6735 | pos = os_strchr(param, ','); | |
6736 | if (pos == NULL) | |
6737 | return -1; | |
6738 | pos++; | |
6739 | bk = atoi(pos); | |
6740 | pos = os_strchr(pos, ','); | |
6741 | if (pos == NULL) | |
6742 | return -1; | |
6743 | pos++; | |
6744 | vi = atoi(pos); | |
6745 | pos = os_strchr(pos, ','); | |
6746 | if (pos == NULL) | |
6747 | return -1; | |
6748 | pos++; | |
6749 | vo = atoi(pos); | |
6750 | /* ignore max SP Length for now */ | |
6751 | ||
6752 | wpa_s->set_sta_uapsd = 1; | |
6753 | wpa_s->sta_uapsd = 0; | |
6754 | if (be) | |
6755 | wpa_s->sta_uapsd |= BIT(0); | |
6756 | if (bk) | |
6757 | wpa_s->sta_uapsd |= BIT(1); | |
6758 | if (vi) | |
6759 | wpa_s->sta_uapsd |= BIT(2); | |
6760 | if (vo) | |
6761 | wpa_s->sta_uapsd |= BIT(3); | |
6762 | } | |
6763 | return 0; | |
6764 | } | |
6765 | ||
6f3bc72b JM |
6766 | if (os_strcmp(cmd, "disallow_freq") == 0) |
6767 | return p2p_ctrl_disallow_freq(wpa_s, param); | |
6768 | ||
96beff11 JM |
6769 | if (os_strcmp(cmd, "disc_int") == 0) { |
6770 | int min_disc_int, max_disc_int, max_disc_tu; | |
6771 | char *pos; | |
6772 | ||
6773 | pos = param; | |
6774 | ||
6775 | min_disc_int = atoi(pos); | |
6776 | pos = os_strchr(pos, ' '); | |
6777 | if (pos == NULL) | |
6778 | return -1; | |
6779 | *pos++ = '\0'; | |
6780 | ||
6781 | max_disc_int = atoi(pos); | |
6782 | pos = os_strchr(pos, ' '); | |
6783 | if (pos == NULL) | |
6784 | return -1; | |
6785 | *pos++ = '\0'; | |
6786 | ||
6787 | max_disc_tu = atoi(pos); | |
6788 | ||
6789 | return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int, | |
6790 | max_disc_int, max_disc_tu); | |
6791 | } | |
6792 | ||
05766ed8 JM |
6793 | if (os_strcmp(cmd, "per_sta_psk") == 0) { |
6794 | wpa_s->global->p2p_per_sta_psk = !!atoi(param); | |
6795 | return 0; | |
6796 | } | |
6797 | ||
c4f87a70 JM |
6798 | #ifdef CONFIG_WPS_NFC |
6799 | if (os_strcmp(cmd, "nfc_tag") == 0) | |
6800 | return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param)); | |
6801 | #endif /* CONFIG_WPS_NFC */ | |
6802 | ||
201b0f5f JM |
6803 | if (os_strcmp(cmd, "disable_ip_addr_req") == 0) { |
6804 | wpa_s->p2p_disable_ip_addr_req = !!atoi(param); | |
6805 | return 0; | |
6806 | } | |
6807 | ||
3a7819f0 JM |
6808 | if (os_strcmp(cmd, "override_pref_op_chan") == 0) { |
6809 | int op_class, chan; | |
6810 | ||
6811 | op_class = atoi(param); | |
6812 | param = os_strchr(param, ':'); | |
6813 | if (!param) | |
6814 | return -1; | |
6815 | param++; | |
6816 | chan = atoi(param); | |
6817 | p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class, | |
6818 | chan); | |
6819 | return 0; | |
6820 | } | |
6821 | ||
b563b388 JM |
6822 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", |
6823 | cmd); | |
6824 | ||
6825 | return -1; | |
6826 | } | |
6827 | ||
6828 | ||
acb54643 JM |
6829 | static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s) |
6830 | { | |
6831 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); | |
6832 | wpa_s->force_long_sd = 0; | |
d02e4c8a AO |
6833 | |
6834 | #ifdef CONFIG_TESTING_OPTIONS | |
6835 | os_free(wpa_s->get_pref_freq_list_override); | |
6836 | wpa_s->get_pref_freq_list_override = NULL; | |
6837 | #endif /* CONFIG_TESTING_OPTIONS */ | |
6838 | ||
477b082c | 6839 | wpas_p2p_stop_find(wpa_s); |
b9da88d6 | 6840 | wpa_s->parent->p2ps_method_config_any = 0; |
acb54643 JM |
6841 | if (wpa_s->global->p2p) |
6842 | p2p_flush(wpa_s->global->p2p); | |
6843 | } | |
6844 | ||
6845 | ||
b563b388 JM |
6846 | static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd) |
6847 | { | |
6848 | char *pos, *pos2; | |
6849 | unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0; | |
6850 | ||
6851 | if (cmd[0]) { | |
6852 | pos = os_strchr(cmd, ' '); | |
6853 | if (pos == NULL) | |
6854 | return -1; | |
6855 | *pos++ = '\0'; | |
6856 | dur1 = atoi(cmd); | |
6857 | ||
6858 | pos2 = os_strchr(pos, ' '); | |
6859 | if (pos2) | |
6860 | *pos2++ = '\0'; | |
6861 | int1 = atoi(pos); | |
6862 | } else | |
6863 | pos2 = NULL; | |
6864 | ||
6865 | if (pos2) { | |
6866 | pos = os_strchr(pos2, ' '); | |
6867 | if (pos == NULL) | |
6868 | return -1; | |
6869 | *pos++ = '\0'; | |
6870 | dur2 = atoi(pos2); | |
6871 | int2 = atoi(pos); | |
6872 | } | |
6873 | ||
6874 | return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2); | |
6875 | } | |
6876 | ||
6877 | ||
6878 | static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) | |
6879 | { | |
6880 | char *pos; | |
6881 | unsigned int period = 0, interval = 0; | |
6882 | ||
6883 | if (cmd[0]) { | |
6884 | pos = os_strchr(cmd, ' '); | |
6885 | if (pos == NULL) | |
6886 | return -1; | |
6887 | *pos++ = '\0'; | |
6888 | period = atoi(cmd); | |
6889 | interval = atoi(pos); | |
6890 | } | |
6891 | ||
6892 | return wpas_p2p_ext_listen(wpa_s, period, interval); | |
6893 | } | |
6894 | ||
f2c56602 JM |
6895 | |
6896 | static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd) | |
6897 | { | |
6898 | const char *pos; | |
6899 | u8 peer[ETH_ALEN]; | |
6900 | int iface_addr = 0; | |
6901 | ||
6902 | pos = cmd; | |
6903 | if (os_strncmp(pos, "iface=", 6) == 0) { | |
6904 | iface_addr = 1; | |
6905 | pos += 6; | |
6906 | } | |
6907 | if (hwaddr_aton(pos, peer)) | |
6908 | return -1; | |
6909 | ||
6910 | wpas_p2p_remove_client(wpa_s, peer, iface_addr); | |
6911 | return 0; | |
6912 | } | |
6913 | ||
a6f5b193 PX |
6914 | |
6915 | static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd) | |
6916 | { | |
6917 | int freq = 0, period = 0, interval = 0, count = 0; | |
6918 | ||
6919 | if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4) | |
6920 | { | |
6921 | wpa_printf(MSG_DEBUG, | |
6922 | "CTRL: Invalid P2P LO Start parameter: '%s'", cmd); | |
6923 | return -1; | |
6924 | } | |
6925 | ||
6926 | return wpas_p2p_lo_start(wpa_s, freq, period, interval, count); | |
6927 | } | |
6928 | ||
b563b388 JM |
6929 | #endif /* CONFIG_P2P */ |
6930 | ||
6931 | ||
356d1488 JM |
6932 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val) |
6933 | { | |
6934 | struct wpa_freq_range_list ranges; | |
6935 | int *freqs = NULL; | |
6936 | struct hostapd_hw_modes *mode; | |
6937 | u16 i; | |
6938 | ||
6939 | if (wpa_s->hw.modes == NULL) | |
6940 | return NULL; | |
6941 | ||
6942 | os_memset(&ranges, 0, sizeof(ranges)); | |
6943 | if (freq_range_list_parse(&ranges, val) < 0) | |
6944 | return NULL; | |
6945 | ||
6946 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
6947 | int j; | |
6948 | ||
6949 | mode = &wpa_s->hw.modes[i]; | |
6950 | for (j = 0; j < mode->num_channels; j++) { | |
6951 | unsigned int freq; | |
6952 | ||
6953 | if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED) | |
6954 | continue; | |
6955 | ||
6956 | freq = mode->channels[j].freq; | |
6957 | if (!freq_range_list_includes(&ranges, freq)) | |
6958 | continue; | |
6959 | ||
6960 | int_array_add_unique(&freqs, freq); | |
6961 | } | |
6962 | } | |
6963 | ||
6964 | os_free(ranges.range); | |
6965 | return freqs; | |
6966 | } | |
6967 | ||
6968 | ||
afc064fe | 6969 | #ifdef CONFIG_INTERWORKING |
356d1488 JM |
6970 | |
6971 | static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param) | |
6972 | { | |
6973 | int auto_sel = 0; | |
6974 | int *freqs = NULL; | |
6975 | ||
6976 | if (param) { | |
6977 | char *pos; | |
6978 | ||
6979 | auto_sel = os_strstr(param, "auto") != NULL; | |
6980 | ||
6981 | pos = os_strstr(param, "freq="); | |
6982 | if (pos) { | |
6983 | freqs = freq_range_to_channel_list(wpa_s, pos + 5); | |
6984 | if (freqs == NULL) | |
6985 | return -1; | |
6986 | } | |
6987 | ||
6988 | } | |
6989 | ||
6990 | return interworking_select(wpa_s, auto_sel, freqs); | |
6991 | } | |
6992 | ||
6993 | ||
f91a512f JM |
6994 | static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst, |
6995 | int only_add) | |
b02fe7ff JM |
6996 | { |
6997 | u8 bssid[ETH_ALEN]; | |
6998 | struct wpa_bss *bss; | |
6999 | ||
7000 | if (hwaddr_aton(dst, bssid)) { | |
7001 | wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst); | |
7002 | return -1; | |
7003 | } | |
7004 | ||
7005 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
7006 | if (bss == NULL) { | |
7007 | wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR, | |
7008 | MAC2STR(bssid)); | |
7009 | return -1; | |
7010 | } | |
7011 | ||
783b2a97 JM |
7012 | if (bss->ssid_len == 0) { |
7013 | int found = 0; | |
7014 | ||
7015 | wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR | |
7016 | " does not have SSID information", MAC2STR(bssid)); | |
7017 | ||
7018 | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, | |
7019 | list) { | |
7020 | if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 && | |
7021 | bss->ssid_len > 0) { | |
7022 | found = 1; | |
7023 | break; | |
7024 | } | |
7025 | } | |
7026 | ||
7027 | if (!found) | |
7028 | return -1; | |
7029 | wpa_printf(MSG_DEBUG, | |
7030 | "Found another matching BSS entry with SSID"); | |
7031 | } | |
7032 | ||
f91a512f | 7033 | return interworking_connect(wpa_s, bss, only_add); |
b02fe7ff JM |
7034 | } |
7035 | ||
7036 | ||
afc064fe JM |
7037 | static int get_anqp(struct wpa_supplicant *wpa_s, char *dst) |
7038 | { | |
7039 | u8 dst_addr[ETH_ALEN]; | |
7040 | int used; | |
7041 | char *pos; | |
7042 | #define MAX_ANQP_INFO_ID 100 | |
7043 | u16 id[MAX_ANQP_INFO_ID]; | |
7044 | size_t num_id = 0; | |
cf28c66b | 7045 | u32 subtypes = 0; |
2316cb35 | 7046 | u32 mbo_subtypes = 0; |
afc064fe JM |
7047 | |
7048 | used = hwaddr_aton2(dst, dst_addr); | |
7049 | if (used < 0) | |
7050 | return -1; | |
7051 | pos = dst + used; | |
b68d602d JM |
7052 | if (*pos == ' ') |
7053 | pos++; | |
afc064fe | 7054 | while (num_id < MAX_ANQP_INFO_ID) { |
cf28c66b DS |
7055 | if (os_strncmp(pos, "hs20:", 5) == 0) { |
7056 | #ifdef CONFIG_HS20 | |
7057 | int num = atoi(pos + 5); | |
7058 | if (num <= 0 || num > 31) | |
7059 | return -1; | |
7060 | subtypes |= BIT(num); | |
7061 | #else /* CONFIG_HS20 */ | |
7062 | return -1; | |
7063 | #endif /* CONFIG_HS20 */ | |
8f479174 | 7064 | } else if (os_strncmp(pos, "mbo:", 4) == 0) { |
7065 | #ifdef CONFIG_MBO | |
7066 | int num = atoi(pos + 4); | |
2316cb35 AS |
7067 | |
7068 | if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE) | |
8f479174 | 7069 | return -1; |
2316cb35 | 7070 | mbo_subtypes |= BIT(num); |
8f479174 | 7071 | #else /* CONFIG_MBO */ |
7072 | return -1; | |
7073 | #endif /* CONFIG_MBO */ | |
cf28c66b DS |
7074 | } else { |
7075 | id[num_id] = atoi(pos); | |
7076 | if (id[num_id]) | |
7077 | num_id++; | |
7078 | } | |
afc064fe JM |
7079 | pos = os_strchr(pos + 1, ','); |
7080 | if (pos == NULL) | |
7081 | break; | |
7082 | pos++; | |
7083 | } | |
7084 | ||
8ecf2231 | 7085 | if (num_id == 0 && !subtypes && !mbo_subtypes) |
afc064fe JM |
7086 | return -1; |
7087 | ||
8f479174 | 7088 | return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes, |
2316cb35 | 7089 | mbo_subtypes); |
afc064fe | 7090 | } |
b1f12296 JM |
7091 | |
7092 | ||
7093 | static int gas_request(struct wpa_supplicant *wpa_s, char *cmd) | |
7094 | { | |
7095 | u8 dst_addr[ETH_ALEN]; | |
7096 | struct wpabuf *advproto, *query = NULL; | |
7097 | int used, ret = -1; | |
7098 | char *pos, *end; | |
7099 | size_t len; | |
7100 | ||
7101 | used = hwaddr_aton2(cmd, dst_addr); | |
7102 | if (used < 0) | |
7103 | return -1; | |
7104 | ||
7105 | pos = cmd + used; | |
7106 | while (*pos == ' ') | |
7107 | pos++; | |
7108 | ||
7109 | /* Advertisement Protocol ID */ | |
7110 | end = os_strchr(pos, ' '); | |
7111 | if (end) | |
7112 | len = end - pos; | |
7113 | else | |
7114 | len = os_strlen(pos); | |
7115 | if (len & 0x01) | |
7116 | return -1; | |
7117 | len /= 2; | |
7118 | if (len == 0) | |
7119 | return -1; | |
7120 | advproto = wpabuf_alloc(len); | |
7121 | if (advproto == NULL) | |
7122 | return -1; | |
7123 | if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0) | |
7124 | goto fail; | |
7125 | ||
7126 | if (end) { | |
7127 | /* Optional Query Request */ | |
7128 | pos = end + 1; | |
7129 | while (*pos == ' ') | |
7130 | pos++; | |
7131 | ||
7132 | len = os_strlen(pos); | |
7133 | if (len) { | |
7134 | if (len & 0x01) | |
7135 | goto fail; | |
7136 | len /= 2; | |
7137 | if (len == 0) | |
7138 | goto fail; | |
7139 | query = wpabuf_alloc(len); | |
7140 | if (query == NULL) | |
7141 | goto fail; | |
7142 | if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0) | |
7143 | goto fail; | |
7144 | } | |
7145 | } | |
7146 | ||
7147 | ret = gas_send_request(wpa_s, dst_addr, advproto, query); | |
7148 | ||
7149 | fail: | |
7150 | wpabuf_free(advproto); | |
7151 | wpabuf_free(query); | |
7152 | ||
7153 | return ret; | |
7154 | } | |
7155 | ||
7156 | ||
7157 | static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf, | |
7158 | size_t buflen) | |
7159 | { | |
7160 | u8 addr[ETH_ALEN]; | |
7161 | int dialog_token; | |
7162 | int used; | |
7163 | char *pos; | |
7164 | size_t resp_len, start, requested_len; | |
b6a9590b JM |
7165 | struct wpabuf *resp; |
7166 | int ret; | |
b1f12296 JM |
7167 | |
7168 | used = hwaddr_aton2(cmd, addr); | |
7169 | if (used < 0) | |
7170 | return -1; | |
7171 | ||
7172 | pos = cmd + used; | |
7173 | while (*pos == ' ') | |
7174 | pos++; | |
7175 | dialog_token = atoi(pos); | |
7176 | ||
b6a9590b JM |
7177 | if (wpa_s->last_gas_resp && |
7178 | os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 && | |
7179 | dialog_token == wpa_s->last_gas_dialog_token) | |
7180 | resp = wpa_s->last_gas_resp; | |
7181 | else if (wpa_s->prev_gas_resp && | |
7182 | os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 && | |
7183 | dialog_token == wpa_s->prev_gas_dialog_token) | |
7184 | resp = wpa_s->prev_gas_resp; | |
7185 | else | |
b1f12296 JM |
7186 | return -1; |
7187 | ||
b6a9590b | 7188 | resp_len = wpabuf_len(resp); |
b1f12296 JM |
7189 | start = 0; |
7190 | requested_len = resp_len; | |
7191 | ||
7192 | pos = os_strchr(pos, ' '); | |
7193 | if (pos) { | |
7194 | start = atoi(pos); | |
7195 | if (start > resp_len) | |
7196 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); | |
7197 | pos = os_strchr(pos, ','); | |
7198 | if (pos == NULL) | |
7199 | return -1; | |
7200 | pos++; | |
7201 | requested_len = atoi(pos); | |
7202 | if (start + requested_len > resp_len) | |
7203 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); | |
7204 | } | |
7205 | ||
7206 | if (requested_len * 2 + 1 > buflen) | |
7207 | return os_snprintf(buf, buflen, "FAIL-Too long response"); | |
7208 | ||
b6a9590b JM |
7209 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start, |
7210 | requested_len); | |
7211 | ||
7212 | if (start + requested_len == resp_len) { | |
7213 | /* | |
7214 | * Free memory by dropping the response after it has been | |
7215 | * fetched. | |
7216 | */ | |
7217 | if (resp == wpa_s->prev_gas_resp) { | |
7218 | wpabuf_free(wpa_s->prev_gas_resp); | |
7219 | wpa_s->prev_gas_resp = NULL; | |
7220 | } else { | |
7221 | wpabuf_free(wpa_s->last_gas_resp); | |
7222 | wpa_s->last_gas_resp = NULL; | |
7223 | } | |
7224 | } | |
7225 | ||
7226 | return ret; | |
b1f12296 | 7227 | } |
afc064fe JM |
7228 | #endif /* CONFIG_INTERWORKING */ |
7229 | ||
7230 | ||
a8918e86 JK |
7231 | #ifdef CONFIG_HS20 |
7232 | ||
7233 | static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst) | |
7234 | { | |
7235 | u8 dst_addr[ETH_ALEN]; | |
7236 | int used; | |
7237 | char *pos; | |
7238 | u32 subtypes = 0; | |
7239 | ||
7240 | used = hwaddr_aton2(dst, dst_addr); | |
7241 | if (used < 0) | |
7242 | return -1; | |
7243 | pos = dst + used; | |
b68d602d JM |
7244 | if (*pos == ' ') |
7245 | pos++; | |
a8918e86 JK |
7246 | for (;;) { |
7247 | int num = atoi(pos); | |
7248 | if (num <= 0 || num > 31) | |
7249 | return -1; | |
7250 | subtypes |= BIT(num); | |
7251 | pos = os_strchr(pos + 1, ','); | |
7252 | if (pos == NULL) | |
7253 | break; | |
7254 | pos++; | |
7255 | } | |
7256 | ||
7257 | if (subtypes == 0) | |
7258 | return -1; | |
7259 | ||
8dd5c1b4 | 7260 | return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0); |
a8918e86 JK |
7261 | } |
7262 | ||
7263 | ||
7264 | static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s, | |
7265 | const u8 *addr, const char *realm) | |
7266 | { | |
7267 | u8 *buf; | |
7268 | size_t rlen, len; | |
7269 | int ret; | |
7270 | ||
7271 | rlen = os_strlen(realm); | |
7272 | len = 3 + rlen; | |
7273 | buf = os_malloc(len); | |
7274 | if (buf == NULL) | |
7275 | return -1; | |
7276 | buf[0] = 1; /* NAI Home Realm Count */ | |
7277 | buf[1] = 0; /* Formatted in accordance with RFC 4282 */ | |
7278 | buf[2] = rlen; | |
7279 | os_memcpy(buf + 3, realm, rlen); | |
7280 | ||
7281 | ret = hs20_anqp_send_req(wpa_s, addr, | |
7282 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | |
8dd5c1b4 | 7283 | buf, len, 0); |
a8918e86 JK |
7284 | |
7285 | os_free(buf); | |
7286 | ||
7287 | return ret; | |
7288 | } | |
7289 | ||
7290 | ||
7291 | static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s, | |
7292 | char *dst) | |
7293 | { | |
7294 | struct wpa_cred *cred = wpa_s->conf->cred; | |
7295 | u8 dst_addr[ETH_ALEN]; | |
7296 | int used; | |
7297 | u8 *buf; | |
7298 | size_t len; | |
7299 | int ret; | |
7300 | ||
7301 | used = hwaddr_aton2(dst, dst_addr); | |
7302 | if (used < 0) | |
7303 | return -1; | |
7304 | ||
7305 | while (dst[used] == ' ') | |
7306 | used++; | |
7307 | if (os_strncmp(dst + used, "realm=", 6) == 0) | |
7308 | return hs20_nai_home_realm_list(wpa_s, dst_addr, | |
7309 | dst + used + 6); | |
7310 | ||
7311 | len = os_strlen(dst + used); | |
7312 | ||
7313 | if (len == 0 && cred && cred->realm) | |
7314 | return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm); | |
7315 | ||
0e87e798 | 7316 | if (len & 1) |
a8918e86 JK |
7317 | return -1; |
7318 | len /= 2; | |
7319 | buf = os_malloc(len); | |
7320 | if (buf == NULL) | |
7321 | return -1; | |
7322 | if (hexstr2bin(dst + used, buf, len) < 0) { | |
7323 | os_free(buf); | |
7324 | return -1; | |
7325 | } | |
7326 | ||
7327 | ret = hs20_anqp_send_req(wpa_s, dst_addr, | |
7328 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | |
8dd5c1b4 | 7329 | buf, len, 0); |
a8918e86 JK |
7330 | os_free(buf); |
7331 | ||
7332 | return ret; | |
7333 | } | |
7334 | ||
184e110c | 7335 | |
8dd5c1b4 JN |
7336 | static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply, |
7337 | int buflen) | |
7338 | { | |
7339 | u8 dst_addr[ETH_ALEN]; | |
7340 | int used; | |
7341 | char *ctx = NULL, *icon, *poffset, *psize; | |
7342 | ||
7343 | used = hwaddr_aton2(cmd, dst_addr); | |
7344 | if (used < 0) | |
7345 | return -1; | |
7346 | cmd += used; | |
7347 | ||
7348 | icon = str_token(cmd, " ", &ctx); | |
7349 | poffset = str_token(cmd, " ", &ctx); | |
7350 | psize = str_token(cmd, " ", &ctx); | |
7351 | if (!icon || !poffset || !psize) | |
7352 | return -1; | |
7353 | ||
7354 | wpa_s->fetch_osu_icon_in_progress = 0; | |
7355 | return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize), | |
7356 | reply, buflen); | |
7357 | } | |
7358 | ||
7359 | ||
7360 | static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd) | |
7361 | { | |
7362 | u8 dst_addr[ETH_ALEN]; | |
7363 | int used; | |
7364 | char *icon; | |
7365 | ||
7366 | if (!cmd[0]) | |
7367 | return hs20_del_icon(wpa_s, NULL, NULL); | |
7368 | ||
7369 | used = hwaddr_aton2(cmd, dst_addr); | |
7370 | if (used < 0) | |
7371 | return -1; | |
7372 | ||
7373 | while (cmd[used] == ' ') | |
7374 | used++; | |
7375 | icon = cmd[used] ? &cmd[used] : NULL; | |
7376 | ||
7377 | return hs20_del_icon(wpa_s, dst_addr, icon); | |
7378 | } | |
7379 | ||
7380 | ||
7381 | static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem) | |
184e110c JM |
7382 | { |
7383 | u8 dst_addr[ETH_ALEN]; | |
7384 | int used; | |
7385 | char *icon; | |
7386 | ||
7387 | used = hwaddr_aton2(cmd, dst_addr); | |
7388 | if (used < 0) | |
7389 | return -1; | |
7390 | ||
7391 | while (cmd[used] == ' ') | |
7392 | used++; | |
7393 | icon = &cmd[used]; | |
7394 | ||
b572df86 | 7395 | wpa_s->fetch_osu_icon_in_progress = 0; |
184e110c | 7396 | return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST), |
8dd5c1b4 | 7397 | (u8 *) icon, os_strlen(icon), inmem); |
184e110c JM |
7398 | } |
7399 | ||
a8918e86 JK |
7400 | #endif /* CONFIG_HS20 */ |
7401 | ||
7402 | ||
bc5d330a TB |
7403 | #ifdef CONFIG_AUTOSCAN |
7404 | ||
7405 | static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s, | |
7406 | char *cmd) | |
7407 | { | |
7408 | enum wpa_states state = wpa_s->wpa_state; | |
7409 | char *new_params = NULL; | |
7410 | ||
7411 | if (os_strlen(cmd) > 0) { | |
7412 | new_params = os_strdup(cmd); | |
7413 | if (new_params == NULL) | |
7414 | return -1; | |
7415 | } | |
7416 | ||
7417 | os_free(wpa_s->conf->autoscan); | |
7418 | wpa_s->conf->autoscan = new_params; | |
7419 | ||
7420 | if (wpa_s->conf->autoscan == NULL) | |
7421 | autoscan_deinit(wpa_s); | |
7422 | else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) | |
99218999 | 7423 | autoscan_init(wpa_s, 1); |
99f00324 JM |
7424 | else if (state == WPA_SCANNING) |
7425 | wpa_supplicant_reinit_autoscan(wpa_s); | |
9d3f4a74 JM |
7426 | else |
7427 | wpa_printf(MSG_DEBUG, "No autoscan update in state %s", | |
7428 | wpa_supplicant_state_txt(state)); | |
bc5d330a TB |
7429 | |
7430 | return 0; | |
7431 | } | |
7432 | ||
7433 | #endif /* CONFIG_AUTOSCAN */ | |
7434 | ||
7435 | ||
e9199e31 JM |
7436 | #ifdef CONFIG_WNM |
7437 | ||
7438 | static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd) | |
7439 | { | |
7440 | int enter; | |
7441 | int intval = 0; | |
7442 | char *pos; | |
cd0ef657 JM |
7443 | int ret; |
7444 | struct wpabuf *tfs_req = NULL; | |
e9199e31 JM |
7445 | |
7446 | if (os_strncmp(cmd, "enter", 5) == 0) | |
7447 | enter = 1; | |
7448 | else if (os_strncmp(cmd, "exit", 4) == 0) | |
7449 | enter = 0; | |
7450 | else | |
7451 | return -1; | |
7452 | ||
7453 | pos = os_strstr(cmd, " interval="); | |
7454 | if (pos) | |
7455 | intval = atoi(pos + 10); | |
7456 | ||
cd0ef657 JM |
7457 | pos = os_strstr(cmd, " tfs_req="); |
7458 | if (pos) { | |
7459 | char *end; | |
7460 | size_t len; | |
7461 | pos += 9; | |
7462 | end = os_strchr(pos, ' '); | |
7463 | if (end) | |
7464 | len = end - pos; | |
7465 | else | |
7466 | len = os_strlen(pos); | |
7467 | if (len & 1) | |
7468 | return -1; | |
7469 | len /= 2; | |
7470 | tfs_req = wpabuf_alloc(len); | |
7471 | if (tfs_req == NULL) | |
7472 | return -1; | |
7473 | if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) { | |
7474 | wpabuf_free(tfs_req); | |
7475 | return -1; | |
7476 | } | |
7477 | } | |
7478 | ||
df80a0cc JM |
7479 | ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER : |
7480 | WNM_SLEEP_MODE_EXIT, intval, | |
cd0ef657 JM |
7481 | tfs_req); |
7482 | wpabuf_free(tfs_req); | |
7483 | ||
7484 | return ret; | |
e9199e31 JM |
7485 | } |
7486 | ||
65bcd0a9 VK |
7487 | |
7488 | static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd) | |
7489 | { | |
9a493fab | 7490 | int query_reason, list = 0; |
15ab61ed | 7491 | char *btm_candidates = NULL; |
65bcd0a9 VK |
7492 | |
7493 | query_reason = atoi(cmd); | |
7494 | ||
9a493fab AS |
7495 | cmd = os_strchr(cmd, ' '); |
7496 | if (cmd) { | |
15ab61ed | 7497 | if (os_strncmp(cmd, " list", 5) == 0) |
9a493fab | 7498 | list = 1; |
15ab61ed AS |
7499 | else |
7500 | btm_candidates = cmd; | |
9a493fab AS |
7501 | } |
7502 | ||
7503 | wpa_printf(MSG_DEBUG, | |
7504 | "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s", | |
7505 | query_reason, list ? " candidate list" : ""); | |
65bcd0a9 | 7506 | |
15ab61ed AS |
7507 | return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason, |
7508 | btm_candidates, | |
7509 | list); | |
65bcd0a9 VK |
7510 | } |
7511 | ||
d514b502 JM |
7512 | |
7513 | static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s, | |
7514 | char *cmd) | |
7515 | { | |
7516 | struct wpabuf *elems; | |
7517 | int ret; | |
7518 | ||
7519 | elems = wpabuf_parse_bin(cmd); | |
7520 | if (!elems) | |
7521 | return -1; | |
7522 | ||
7523 | ret = wnm_send_coloc_intf_report(wpa_s, 0, elems); | |
7524 | wpabuf_free(elems); | |
7525 | return ret; | |
7526 | } | |
7527 | ||
e9199e31 JM |
7528 | #endif /* CONFIG_WNM */ |
7529 | ||
7530 | ||
60b24b0d DS |
7531 | static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, |
7532 | size_t buflen) | |
7533 | { | |
7534 | struct wpa_signal_info si; | |
7535 | int ret; | |
2cc8d8f4 | 7536 | char *pos, *end; |
60b24b0d DS |
7537 | |
7538 | ret = wpa_drv_signal_poll(wpa_s, &si); | |
7539 | if (ret) | |
7540 | return -1; | |
7541 | ||
2cc8d8f4 AO |
7542 | pos = buf; |
7543 | end = buf + buflen; | |
7544 | ||
7545 | ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n" | |
60b24b0d DS |
7546 | "NOISE=%d\nFREQUENCY=%u\n", |
7547 | si.current_signal, si.current_txrate / 1000, | |
7548 | si.current_noise, si.frequency); | |
7bdd8981 | 7549 | if (os_snprintf_error(end - pos, ret)) |
60b24b0d | 7550 | return -1; |
2cc8d8f4 AO |
7551 | pos += ret; |
7552 | ||
7553 | if (si.chanwidth != CHAN_WIDTH_UNKNOWN) { | |
7554 | ret = os_snprintf(pos, end - pos, "WIDTH=%s\n", | |
7a4a93b9 | 7555 | channel_width_to_string(si.chanwidth)); |
7bdd8981 | 7556 | if (os_snprintf_error(end - pos, ret)) |
2cc8d8f4 AO |
7557 | return -1; |
7558 | pos += ret; | |
7559 | } | |
7560 | ||
b55c623e BP |
7561 | if (si.center_frq1 > 0) { |
7562 | ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n", | |
7563 | si.center_frq1); | |
7564 | if (os_snprintf_error(end - pos, ret)) | |
7565 | return -1; | |
7566 | pos += ret; | |
7567 | } | |
7568 | ||
7569 | if (si.center_frq2 > 0) { | |
7570 | ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n", | |
7571 | si.center_frq2); | |
7bdd8981 | 7572 | if (os_snprintf_error(end - pos, ret)) |
2cc8d8f4 AO |
7573 | return -1; |
7574 | pos += ret; | |
7575 | } | |
7576 | ||
95783298 AO |
7577 | if (si.avg_signal) { |
7578 | ret = os_snprintf(pos, end - pos, | |
7579 | "AVG_RSSI=%d\n", si.avg_signal); | |
d85e1fc8 | 7580 | if (os_snprintf_error(end - pos, ret)) |
95783298 AO |
7581 | return -1; |
7582 | pos += ret; | |
7583 | } | |
7584 | ||
74fa78b2 JM |
7585 | if (si.avg_beacon_signal) { |
7586 | ret = os_snprintf(pos, end - pos, | |
7587 | "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal); | |
7588 | if (os_snprintf_error(end - pos, ret)) | |
7589 | return -1; | |
7590 | pos += ret; | |
7591 | } | |
7592 | ||
2cc8d8f4 | 7593 | return pos - buf; |
60b24b0d DS |
7594 | } |
7595 | ||
7596 | ||
96e8d831 DS |
7597 | static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s, |
7598 | const char *cmd) | |
7599 | { | |
7600 | const char *pos; | |
7601 | int threshold = 0; | |
7602 | int hysteresis = 0; | |
7603 | ||
7604 | if (wpa_s->bgscan && wpa_s->bgscan_priv) { | |
7605 | wpa_printf(MSG_DEBUG, | |
7606 | "Reject SIGNAL_MONITOR command - bgscan is active"); | |
7607 | return -1; | |
7608 | } | |
7609 | pos = os_strstr(cmd, "THRESHOLD="); | |
7610 | if (pos) | |
7611 | threshold = atoi(pos + 10); | |
7612 | pos = os_strstr(cmd, "HYSTERESIS="); | |
7613 | if (pos) | |
7614 | hysteresis = atoi(pos + 11); | |
7615 | return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis); | |
7616 | } | |
7617 | ||
7618 | ||
c06fca04 JM |
7619 | #ifdef CONFIG_TESTING_OPTIONS |
7620 | int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s, | |
7621 | enum wpa_driver_if_type if_type, | |
7622 | unsigned int *num, | |
7623 | unsigned int *freq_list) | |
7624 | { | |
7625 | char *pos = wpa_s->get_pref_freq_list_override; | |
7626 | char *end; | |
7627 | unsigned int count = 0; | |
7628 | ||
7629 | /* Override string format: | |
7630 | * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */ | |
7631 | ||
7632 | while (pos) { | |
7633 | if (atoi(pos) == (int) if_type) | |
7634 | break; | |
7635 | pos = os_strchr(pos, ' '); | |
7636 | if (pos) | |
7637 | pos++; | |
7638 | } | |
7639 | if (!pos) | |
7640 | return -1; | |
7641 | pos = os_strchr(pos, ':'); | |
7642 | if (!pos) | |
7643 | return -1; | |
7644 | pos++; | |
7645 | end = os_strchr(pos, ' '); | |
7646 | while (pos && (!end || pos < end) && count < *num) { | |
7647 | freq_list[count++] = atoi(pos); | |
7648 | pos = os_strchr(pos, ','); | |
7649 | if (pos) | |
7650 | pos++; | |
7651 | } | |
7652 | ||
7653 | *num = count; | |
7654 | return 0; | |
7655 | } | |
7656 | #endif /* CONFIG_TESTING_OPTIONS */ | |
7657 | ||
7658 | ||
98342208 AK |
7659 | static int wpas_ctrl_iface_get_pref_freq_list( |
7660 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
7661 | { | |
7662 | unsigned int freq_list[100], num = 100, i; | |
7663 | int ret; | |
7664 | enum wpa_driver_if_type iface_type; | |
7665 | char *pos, *end; | |
7666 | ||
7667 | pos = buf; | |
7668 | end = buf + buflen; | |
7669 | ||
7670 | /* buf: "<interface_type>" */ | |
7671 | if (os_strcmp(cmd, "STATION") == 0) | |
7672 | iface_type = WPA_IF_STATION; | |
7673 | else if (os_strcmp(cmd, "AP") == 0) | |
7674 | iface_type = WPA_IF_AP_BSS; | |
7675 | else if (os_strcmp(cmd, "P2P_GO") == 0) | |
7676 | iface_type = WPA_IF_P2P_GO; | |
7677 | else if (os_strcmp(cmd, "P2P_CLIENT") == 0) | |
7678 | iface_type = WPA_IF_P2P_CLIENT; | |
7679 | else if (os_strcmp(cmd, "IBSS") == 0) | |
7680 | iface_type = WPA_IF_IBSS; | |
7681 | else if (os_strcmp(cmd, "TDLS") == 0) | |
7682 | iface_type = WPA_IF_TDLS; | |
7683 | else | |
7684 | return -1; | |
7685 | ||
7686 | wpa_printf(MSG_DEBUG, | |
7687 | "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)", | |
7688 | iface_type, buf); | |
7689 | ||
7690 | ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list); | |
7691 | if (ret) | |
7692 | return -1; | |
7693 | ||
7694 | for (i = 0; i < num; i++) { | |
7695 | ret = os_snprintf(pos, end - pos, "%s%u", | |
7696 | i > 0 ? "," : "", freq_list[i]); | |
7697 | if (os_snprintf_error(end - pos, ret)) | |
7698 | return -1; | |
7699 | pos += ret; | |
7700 | } | |
7701 | ||
7702 | return pos - buf; | |
7703 | } | |
7704 | ||
7705 | ||
4d7aab78 EL |
7706 | static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s, |
7707 | char *buf, size_t buflen) | |
7708 | { | |
7709 | int ret, i; | |
7710 | char *pos, *end; | |
7711 | ||
7712 | ret = os_snprintf(buf, buflen, "%016llX:\n", | |
7713 | (long long unsigned) wpa_s->drv_flags); | |
7714 | if (os_snprintf_error(buflen, ret)) | |
7715 | return -1; | |
7716 | ||
7717 | pos = buf + ret; | |
7718 | end = buf + buflen; | |
7719 | ||
7720 | for (i = 0; i < 64; i++) { | |
7721 | if (wpa_s->drv_flags & (1LLU << i)) { | |
7722 | ret = os_snprintf(pos, end - pos, "%s\n", | |
7723 | driver_flag_to_string(1LLU << i)); | |
7724 | if (os_snprintf_error(end - pos, ret)) | |
7725 | return -1; | |
7726 | pos += ret; | |
7727 | } | |
7728 | } | |
7729 | ||
7730 | return pos - buf; | |
7731 | } | |
7732 | ||
7733 | ||
dc7785f8 YZ |
7734 | static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf, |
7735 | size_t buflen) | |
7736 | { | |
7737 | struct hostap_sta_driver_data sta; | |
7738 | int ret; | |
7739 | ||
7740 | ret = wpa_drv_pktcnt_poll(wpa_s, &sta); | |
7741 | if (ret) | |
7742 | return -1; | |
7743 | ||
7744 | ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n", | |
7745 | sta.tx_packets, sta.tx_retry_failed, sta.rx_packets); | |
7bdd8981 | 7746 | if (os_snprintf_error(buflen, ret)) |
dc7785f8 YZ |
7747 | return -1; |
7748 | return ret; | |
7749 | } | |
7750 | ||
7751 | ||
5e2c3490 JM |
7752 | #ifdef ANDROID |
7753 | static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd, | |
7754 | char *buf, size_t buflen) | |
7755 | { | |
7756 | int ret; | |
7757 | ||
7758 | ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen); | |
a94737ea DS |
7759 | if (ret == 0) { |
7760 | if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) { | |
7761 | struct p2p_data *p2p = wpa_s->global->p2p; | |
7762 | if (p2p) { | |
7763 | char country[3]; | |
7764 | country[0] = cmd[8]; | |
7765 | country[1] = cmd[9]; | |
7766 | country[2] = 0x04; | |
7767 | p2p_set_country(p2p, country); | |
7768 | } | |
7769 | } | |
5e2c3490 | 7770 | ret = os_snprintf(buf, buflen, "%s\n", "OK"); |
aaadd727 JM |
7771 | if (os_snprintf_error(buflen, ret)) |
7772 | ret = -1; | |
a94737ea | 7773 | } |
5e2c3490 JM |
7774 | return ret; |
7775 | } | |
7776 | #endif /* ANDROID */ | |
7777 | ||
7778 | ||
adef8948 BL |
7779 | static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd, |
7780 | char *buf, size_t buflen) | |
7781 | { | |
7782 | int ret; | |
7783 | char *pos; | |
7784 | u8 *data = NULL; | |
7785 | unsigned int vendor_id, subcmd; | |
7786 | struct wpabuf *reply; | |
7787 | size_t data_len = 0; | |
7788 | ||
7789 | /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */ | |
7790 | vendor_id = strtoul(cmd, &pos, 16); | |
640b0b93 | 7791 | if (!isblank((unsigned char) *pos)) |
adef8948 BL |
7792 | return -EINVAL; |
7793 | ||
7794 | subcmd = strtoul(pos, &pos, 10); | |
7795 | ||
7796 | if (*pos != '\0') { | |
640b0b93 | 7797 | if (!isblank((unsigned char) *pos++)) |
adef8948 BL |
7798 | return -EINVAL; |
7799 | data_len = os_strlen(pos); | |
7800 | } | |
7801 | ||
7802 | if (data_len) { | |
7803 | data_len /= 2; | |
7804 | data = os_malloc(data_len); | |
7805 | if (!data) | |
2cebdee6 | 7806 | return -1; |
adef8948 BL |
7807 | |
7808 | if (hexstr2bin(pos, data, data_len)) { | |
7809 | wpa_printf(MSG_DEBUG, | |
7810 | "Vendor command: wrong parameter format"); | |
7811 | os_free(data); | |
7812 | return -EINVAL; | |
7813 | } | |
7814 | } | |
7815 | ||
7816 | reply = wpabuf_alloc((buflen - 1) / 2); | |
7817 | if (!reply) { | |
7818 | os_free(data); | |
2cebdee6 | 7819 | return -1; |
adef8948 BL |
7820 | } |
7821 | ||
7822 | ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len, | |
7823 | reply); | |
7824 | ||
7825 | if (ret == 0) | |
7826 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply), | |
7827 | wpabuf_len(reply)); | |
7828 | ||
7829 | wpabuf_free(reply); | |
7830 | os_free(data); | |
7831 | ||
7832 | return ret; | |
7833 | } | |
7834 | ||
7835 | ||
acb54643 JM |
7836 | static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s) |
7837 | { | |
7e608d1d IP |
7838 | #ifdef CONFIG_P2P |
7839 | struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ? | |
7840 | wpa_s->global->p2p_init_wpa_s : wpa_s; | |
7841 | #endif /* CONFIG_P2P */ | |
7842 | ||
acb54643 JM |
7843 | wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state"); |
7844 | ||
6e374bd4 JM |
7845 | if (wpas_abort_ongoing_scan(wpa_s) == 0) |
7846 | wpa_s->ignore_post_flush_scan_res = 1; | |
53401e91 | 7847 | |
e9ccfc38 JM |
7848 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
7849 | /* | |
7850 | * Avoid possible auto connect re-connection on getting | |
7851 | * disconnected due to state flush. | |
7852 | */ | |
7853 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
7854 | } | |
7855 | ||
acb54643 | 7856 | #ifdef CONFIG_P2P |
1d20c66e | 7857 | wpas_p2p_group_remove(p2p_wpa_s, "*"); |
7e608d1d IP |
7858 | wpas_p2p_cancel(p2p_wpa_s); |
7859 | p2p_ctrl_flush(p2p_wpa_s); | |
7e608d1d IP |
7860 | wpas_p2p_service_flush(p2p_wpa_s); |
7861 | p2p_wpa_s->global->p2p_disabled = 0; | |
7862 | p2p_wpa_s->global->p2p_per_sta_psk = 0; | |
7863 | p2p_wpa_s->conf->num_sec_device_types = 0; | |
7864 | p2p_wpa_s->p2p_disable_ip_addr_req = 0; | |
7865 | os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range); | |
7866 | p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL; | |
85e152b6 | 7867 | p2p_wpa_s->global->p2p_go_avoid_freq.num = 0; |
9a58e521 | 7868 | p2p_wpa_s->global->pending_p2ps_group = 0; |
8bb8e6ed | 7869 | p2p_wpa_s->global->pending_p2ps_group_freq = 0; |
acb54643 JM |
7870 | #endif /* CONFIG_P2P */ |
7871 | ||
7872 | #ifdef CONFIG_WPS_TESTING | |
7873 | wps_version_number = 0x20; | |
7874 | wps_testing_dummy_cred = 0; | |
91226e0d | 7875 | wps_corrupt_pkhash = 0; |
6e379c6c JM |
7876 | wps_force_auth_types_in_use = 0; |
7877 | wps_force_encr_types_in_use = 0; | |
acb54643 JM |
7878 | #endif /* CONFIG_WPS_TESTING */ |
7879 | #ifdef CONFIG_WPS | |
7b02375a | 7880 | wpa_s->wps_fragment_size = 0; |
acb54643 | 7881 | wpas_wps_cancel(wpa_s); |
422ba11e | 7882 | wps_registrar_flush(wpa_s->wps->registrar); |
acb54643 | 7883 | #endif /* CONFIG_WPS */ |
7255983b | 7884 | wpa_s->after_wps = 0; |
4d9fb08d | 7885 | wpa_s->known_wps_freq = 0; |
acb54643 | 7886 | |
30d27b04 JM |
7887 | #ifdef CONFIG_DPP |
7888 | wpas_dpp_deinit(wpa_s); | |
f97ace34 JM |
7889 | wpa_s->dpp_init_max_tries = 0; |
7890 | wpa_s->dpp_init_retry_time = 0; | |
7891 | wpa_s->dpp_resp_wait_time = 0; | |
95b0104a JM |
7892 | wpa_s->dpp_resp_max_tries = 0; |
7893 | wpa_s->dpp_resp_retry_time = 0; | |
dc2f24f1 | 7894 | #ifdef CONFIG_TESTING_OPTIONS |
2bdc47a9 JM |
7895 | os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN); |
7896 | os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN); | |
acc555f9 | 7897 | dpp_pkex_ephemeral_key_override_len = 0; |
f5526975 | 7898 | dpp_protocol_key_override_len = 0; |
055cd397 | 7899 | dpp_nonce_override_len = 0; |
dc2f24f1 | 7900 | #endif /* CONFIG_TESTING_OPTIONS */ |
30d27b04 JM |
7901 | #endif /* CONFIG_DPP */ |
7902 | ||
9d2cb3ec | 7903 | #ifdef CONFIG_TDLS |
acb54643 | 7904 | #ifdef CONFIG_TDLS_TESTING |
acb54643 JM |
7905 | tdls_testing = 0; |
7906 | #endif /* CONFIG_TDLS_TESTING */ | |
acb54643 JM |
7907 | wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL); |
7908 | wpa_tdls_enable(wpa_s->wpa, 1); | |
7909 | #endif /* CONFIG_TDLS */ | |
7910 | ||
e78aaca0 JM |
7911 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL); |
7912 | wpa_supplicant_stop_countermeasures(wpa_s, NULL); | |
7913 | ||
acb54643 | 7914 | wpa_s->no_keep_alive = 0; |
c2805909 | 7915 | wpa_s->own_disconnect_req = 0; |
acb54643 JM |
7916 | |
7917 | os_free(wpa_s->disallow_aps_bssid); | |
7918 | wpa_s->disallow_aps_bssid = NULL; | |
7919 | wpa_s->disallow_aps_bssid_count = 0; | |
7920 | os_free(wpa_s->disallow_aps_ssid); | |
7921 | wpa_s->disallow_aps_ssid = NULL; | |
7922 | wpa_s->disallow_aps_ssid_count = 0; | |
7923 | ||
7924 | wpa_s->set_sta_uapsd = 0; | |
7925 | wpa_s->sta_uapsd = 0; | |
7926 | ||
7927 | wpa_drv_radio_disable(wpa_s, 0); | |
acb54643 | 7928 | wpa_blacklist_clear(wpa_s); |
a8a7890d | 7929 | wpa_s->extra_blacklist_count = 0; |
acb54643 JM |
7930 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all"); |
7931 | wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all"); | |
d9bb2821 | 7932 | wpa_config_flush_blobs(wpa_s->conf); |
ea6e040c JM |
7933 | wpa_s->conf->auto_interworking = 0; |
7934 | wpa_s->conf->okc = 0; | |
04f7ecc6 | 7935 | |
b925506a JM |
7936 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
7937 | rsn_preauth_deinit(wpa_s->wpa); | |
7938 | ||
04f7ecc6 JM |
7939 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200); |
7940 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70); | |
7941 | wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60); | |
0d79b50a | 7942 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); |
b1ae396f | 7943 | |
b3253ebb | 7944 | radio_remove_works(wpa_s, NULL, 1); |
e3745228 | 7945 | wpa_s->ext_work_in_progress = 0; |
3d910ef4 JM |
7946 | |
7947 | wpa_s->next_ssid = NULL; | |
b572df86 JM |
7948 | |
7949 | #ifdef CONFIG_INTERWORKING | |
876e74aa | 7950 | #ifdef CONFIG_HS20 |
b572df86 | 7951 | hs20_cancel_fetch_osu(wpa_s); |
8dd5c1b4 | 7952 | hs20_del_icon(wpa_s, NULL, NULL); |
876e74aa | 7953 | #endif /* CONFIG_HS20 */ |
b572df86 | 7954 | #endif /* CONFIG_INTERWORKING */ |
60b893df JM |
7955 | |
7956 | wpa_s->ext_mgmt_frame_handling = 0; | |
9d4ff04a | 7957 | wpa_s->ext_eapol_frame_io = 0; |
1f94e4ee JM |
7958 | #ifdef CONFIG_TESTING_OPTIONS |
7959 | wpa_s->extra_roc_dur = 0; | |
911942ee | 7960 | wpa_s->test_failure = WPAS_TEST_FAILURE_NONE; |
ed7820b4 | 7961 | wpa_s->p2p_go_csa_on_inv = 0; |
02adead5 | 7962 | wpa_s->ignore_auth_resp = 0; |
6ad37d73 | 7963 | wpa_s->ignore_assoc_disallow = 0; |
daa40960 | 7964 | wpa_s->testing_resend_assoc = 0; |
a483c6f1 | 7965 | wpa_s->reject_btm_req_reason = 0; |
651c6a84 | 7966 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL); |
c06fca04 JM |
7967 | os_free(wpa_s->get_pref_freq_list_override); |
7968 | wpa_s->get_pref_freq_list_override = NULL; | |
a0f19e9c JM |
7969 | wpabuf_free(wpa_s->sae_commit_override); |
7970 | wpa_s->sae_commit_override = NULL; | |
60239f60 | 7971 | #ifdef CONFIG_DPP |
b7dddab7 JM |
7972 | os_free(wpa_s->dpp_config_obj_override); |
7973 | wpa_s->dpp_config_obj_override = NULL; | |
7974 | os_free(wpa_s->dpp_discovery_override); | |
7975 | wpa_s->dpp_discovery_override = NULL; | |
7976 | os_free(wpa_s->dpp_groups_override); | |
7977 | wpa_s->dpp_groups_override = NULL; | |
60239f60 JM |
7978 | dpp_test = DPP_TEST_DISABLED; |
7979 | #endif /* CONFIG_DPP */ | |
1f94e4ee | 7980 | #endif /* CONFIG_TESTING_OPTIONS */ |
97cfe110 JM |
7981 | |
7982 | wpa_s->disconnected = 0; | |
b8db1dfc JM |
7983 | os_free(wpa_s->next_scan_freqs); |
7984 | wpa_s->next_scan_freqs = NULL; | |
88a44755 JM |
7985 | os_free(wpa_s->select_network_scan_freqs); |
7986 | wpa_s->select_network_scan_freqs = NULL; | |
6c699913 JM |
7987 | |
7988 | wpa_bss_flush(wpa_s); | |
7989 | if (!dl_list_empty(&wpa_s->bss)) { | |
7990 | wpa_printf(MSG_DEBUG, | |
7991 | "BSS table not empty after flush: %u entries, current_bss=%p bssid=" | |
7992 | MACSTR " pending_bssid=" MACSTR, | |
7993 | dl_list_len(&wpa_s->bss), wpa_s->current_bss, | |
7994 | MAC2STR(wpa_s->bssid), | |
7995 | MAC2STR(wpa_s->pending_bssid)); | |
7996 | } | |
9bd566a3 AS |
7997 | |
7998 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); | |
03ed0a52 | 7999 | wpa_s->wnmsleep_used = 0; |
ab6ab07a JM |
8000 | |
8001 | #ifdef CONFIG_SME | |
8002 | wpa_s->sme.last_unprot_disconnect.sec = 0; | |
8003 | #endif /* CONFIG_SME */ | |
c6c41f6e JM |
8004 | |
8005 | wpabuf_free(wpa_s->ric_ies); | |
8006 | wpa_s->ric_ies = NULL; | |
32bb47fa JM |
8007 | |
8008 | wpa_supplicant_update_channel_list(wpa_s, NULL); | |
19677b77 BL |
8009 | |
8010 | free_bss_tmp_disallowed(wpa_s); | |
acb54643 JM |
8011 | } |
8012 | ||
8013 | ||
1f965e62 JM |
8014 | static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s, |
8015 | char *buf, size_t buflen) | |
8016 | { | |
8017 | struct wpa_radio_work *work; | |
8018 | char *pos, *end; | |
8019 | struct os_reltime now, diff; | |
8020 | ||
8021 | pos = buf; | |
8022 | end = buf + buflen; | |
8023 | ||
8024 | os_get_reltime(&now); | |
8025 | ||
8026 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) | |
8027 | { | |
8028 | int ret; | |
8029 | ||
8030 | os_reltime_sub(&now, &work->time, &diff); | |
8031 | ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n", | |
8032 | work->type, work->wpa_s->ifname, work->freq, | |
8033 | work->started, diff.sec, diff.usec); | |
d85e1fc8 | 8034 | if (os_snprintf_error(end - pos, ret)) |
1f965e62 JM |
8035 | break; |
8036 | pos += ret; | |
8037 | } | |
8038 | ||
8039 | return pos - buf; | |
8040 | } | |
8041 | ||
8042 | ||
8043 | static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx) | |
8044 | { | |
8045 | struct wpa_radio_work *work = eloop_ctx; | |
8046 | struct wpa_external_work *ework = work->ctx; | |
8047 | ||
8048 | wpa_dbg(work->wpa_s, MSG_DEBUG, | |
8049 | "Timing out external radio work %u (%s)", | |
8050 | ework->id, work->type); | |
8051 | wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id); | |
e3745228 | 8052 | work->wpa_s->ext_work_in_progress = 0; |
1f965e62 | 8053 | radio_work_done(work); |
df48efc5 | 8054 | os_free(ework); |
1f965e62 JM |
8055 | } |
8056 | ||
8057 | ||
8058 | static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit) | |
8059 | { | |
8060 | struct wpa_external_work *ework = work->ctx; | |
8061 | ||
8062 | if (deinit) { | |
b3253ebb AO |
8063 | if (work->started) |
8064 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, | |
8065 | work, NULL); | |
8066 | ||
7d1007a6 JM |
8067 | /* |
8068 | * work->type points to a buffer in ework, so need to replace | |
8069 | * that here with a fixed string to avoid use of freed memory | |
8070 | * in debug prints. | |
8071 | */ | |
8072 | work->type = "freed-ext-work"; | |
8073 | work->ctx = NULL; | |
1f965e62 JM |
8074 | os_free(ework); |
8075 | return; | |
8076 | } | |
8077 | ||
8078 | wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)", | |
8079 | ework->id, ework->type); | |
8080 | wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id); | |
e3745228 | 8081 | work->wpa_s->ext_work_in_progress = 1; |
1f965e62 JM |
8082 | if (!ework->timeout) |
8083 | ework->timeout = 10; | |
8084 | eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout, | |
8085 | work, NULL); | |
8086 | } | |
8087 | ||
8088 | ||
8089 | static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd, | |
8090 | char *buf, size_t buflen) | |
8091 | { | |
8092 | struct wpa_external_work *ework; | |
8093 | char *pos, *pos2; | |
8094 | size_t type_len; | |
8095 | int ret; | |
8096 | unsigned int freq = 0; | |
8097 | ||
8098 | /* format: <name> [freq=<MHz>] [timeout=<seconds>] */ | |
8099 | ||
8100 | ework = os_zalloc(sizeof(*ework)); | |
8101 | if (ework == NULL) | |
8102 | return -1; | |
8103 | ||
8104 | pos = os_strchr(cmd, ' '); | |
8105 | if (pos) { | |
8106 | type_len = pos - cmd; | |
8107 | pos++; | |
8108 | ||
8109 | pos2 = os_strstr(pos, "freq="); | |
8110 | if (pos2) | |
8111 | freq = atoi(pos2 + 5); | |
8112 | ||
8113 | pos2 = os_strstr(pos, "timeout="); | |
8114 | if (pos2) | |
8115 | ework->timeout = atoi(pos2 + 8); | |
8116 | } else { | |
8117 | type_len = os_strlen(cmd); | |
8118 | } | |
8119 | if (4 + type_len >= sizeof(ework->type)) | |
8120 | type_len = sizeof(ework->type) - 4 - 1; | |
8121 | os_strlcpy(ework->type, "ext:", sizeof(ework->type)); | |
8122 | os_memcpy(ework->type + 4, cmd, type_len); | |
8123 | ework->type[4 + type_len] = '\0'; | |
8124 | ||
8125 | wpa_s->ext_work_id++; | |
8126 | if (wpa_s->ext_work_id == 0) | |
8127 | wpa_s->ext_work_id++; | |
8128 | ework->id = wpa_s->ext_work_id; | |
8129 | ||
8130 | if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb, | |
8131 | ework) < 0) { | |
8132 | os_free(ework); | |
8133 | return -1; | |
8134 | } | |
8135 | ||
8136 | ret = os_snprintf(buf, buflen, "%u", ework->id); | |
d85e1fc8 | 8137 | if (os_snprintf_error(buflen, ret)) |
1f965e62 JM |
8138 | return -1; |
8139 | return ret; | |
8140 | } | |
8141 | ||
8142 | ||
8143 | static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd) | |
8144 | { | |
8145 | struct wpa_radio_work *work; | |
8146 | unsigned int id = atoi(cmd); | |
8147 | ||
8148 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) | |
8149 | { | |
8150 | struct wpa_external_work *ework; | |
8151 | ||
8152 | if (os_strncmp(work->type, "ext:", 4) != 0) | |
8153 | continue; | |
8154 | ework = work->ctx; | |
8155 | if (id && ework->id != id) | |
8156 | continue; | |
8157 | wpa_dbg(wpa_s, MSG_DEBUG, | |
8158 | "Completed external radio work %u (%s)", | |
8159 | ework->id, ework->type); | |
8160 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL); | |
e3745228 | 8161 | wpa_s->ext_work_in_progress = 0; |
1f965e62 | 8162 | radio_work_done(work); |
6829da39 | 8163 | os_free(ework); |
1f965e62 JM |
8164 | return 3; /* "OK\n" */ |
8165 | } | |
8166 | ||
8167 | return -1; | |
8168 | } | |
8169 | ||
8170 | ||
8171 | static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd, | |
8172 | char *buf, size_t buflen) | |
8173 | { | |
8174 | if (os_strcmp(cmd, "show") == 0) | |
8175 | return wpas_ctrl_radio_work_show(wpa_s, buf, buflen); | |
8176 | if (os_strncmp(cmd, "add ", 4) == 0) | |
8177 | return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen); | |
8178 | if (os_strncmp(cmd, "done ", 5) == 0) | |
8179 | return wpas_ctrl_radio_work_done(wpa_s, cmd + 4); | |
8180 | return -1; | |
8181 | } | |
8182 | ||
8183 | ||
8184 | void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s) | |
8185 | { | |
8186 | struct wpa_radio_work *work, *tmp; | |
8187 | ||
a6cff8bf MS |
8188 | if (!wpa_s || !wpa_s->radio) |
8189 | return; | |
8190 | ||
1f965e62 JM |
8191 | dl_list_for_each_safe(work, tmp, &wpa_s->radio->work, |
8192 | struct wpa_radio_work, list) { | |
8193 | struct wpa_external_work *ework; | |
8194 | ||
8195 | if (os_strncmp(work->type, "ext:", 4) != 0) | |
8196 | continue; | |
8197 | ework = work->ctx; | |
8198 | wpa_dbg(wpa_s, MSG_DEBUG, | |
023b466d | 8199 | "Flushing%s external radio work %u (%s)", |
1f965e62 JM |
8200 | work->started ? " started" : "", ework->id, |
8201 | ework->type); | |
8202 | if (work->started) | |
8203 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, | |
8204 | work, NULL); | |
1f965e62 | 8205 | radio_work_done(work); |
df48efc5 | 8206 | os_free(ework); |
1f965e62 JM |
8207 | } |
8208 | } | |
8209 | ||
8210 | ||
bceb8431 JM |
8211 | static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx) |
8212 | { | |
8213 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
8214 | eapol_sm_notify_ctrl_response(wpa_s->eapol); | |
8215 | } | |
8216 | ||
8217 | ||
43a66ecb JM |
8218 | static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value, |
8219 | unsigned int *scan_id_count, int scan_id[]) | |
6891f0e6 LJ |
8220 | { |
8221 | const char *pos = value; | |
8222 | ||
8223 | while (pos) { | |
8224 | if (*pos == ' ' || *pos == '\0') | |
8225 | break; | |
43a66ecb | 8226 | if (*scan_id_count == MAX_SCAN_ID) |
6891f0e6 | 8227 | return -1; |
43a66ecb | 8228 | scan_id[(*scan_id_count)++] = atoi(pos); |
6891f0e6 LJ |
8229 | pos = os_strchr(pos, ','); |
8230 | if (pos) | |
8231 | pos++; | |
8232 | } | |
8233 | ||
8234 | return 0; | |
8235 | } | |
8236 | ||
8237 | ||
fee52342 JM |
8238 | static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params, |
8239 | char *reply, int reply_size, int *reply_len) | |
8240 | { | |
8241 | char *pos; | |
43a66ecb JM |
8242 | unsigned int manual_scan_passive = 0; |
8243 | unsigned int manual_scan_use_id = 0; | |
8244 | unsigned int manual_scan_only_new = 0; | |
8245 | unsigned int scan_only = 0; | |
8246 | unsigned int scan_id_count = 0; | |
8247 | int scan_id[MAX_SCAN_ID]; | |
8248 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, | |
8249 | struct wpa_scan_results *scan_res); | |
8250 | int *manual_scan_freqs = NULL; | |
a80651d0 KV |
8251 | struct wpa_ssid_value *ssid = NULL, *ns; |
8252 | unsigned int ssid_count = 0; | |
fee52342 JM |
8253 | |
8254 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { | |
8255 | *reply_len = -1; | |
8256 | return; | |
8257 | } | |
8258 | ||
e69ae5ff JM |
8259 | if (radio_work_pending(wpa_s, "scan")) { |
8260 | wpa_printf(MSG_DEBUG, | |
8261 | "Pending scan scheduled - reject new request"); | |
8262 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | |
8263 | return; | |
8264 | } | |
8265 | ||
9772af66 NM |
8266 | #ifdef CONFIG_INTERWORKING |
8267 | if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) { | |
8268 | wpa_printf(MSG_DEBUG, | |
8269 | "Interworking select in progress - reject new scan"); | |
8270 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | |
8271 | return; | |
8272 | } | |
8273 | #endif /* CONFIG_INTERWORKING */ | |
8274 | ||
fee52342 JM |
8275 | if (params) { |
8276 | if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0) | |
43a66ecb | 8277 | scan_only = 1; |
fee52342 JM |
8278 | |
8279 | pos = os_strstr(params, "freq="); | |
43a66ecb JM |
8280 | if (pos) { |
8281 | manual_scan_freqs = freq_range_to_channel_list(wpa_s, | |
8282 | pos + 5); | |
8283 | if (manual_scan_freqs == NULL) { | |
8284 | *reply_len = -1; | |
8285 | goto done; | |
8286 | } | |
fee52342 | 8287 | } |
88c2d488 JM |
8288 | |
8289 | pos = os_strstr(params, "passive="); | |
8290 | if (pos) | |
43a66ecb | 8291 | manual_scan_passive = !!atoi(pos + 8); |
d81c73be JM |
8292 | |
8293 | pos = os_strstr(params, "use_id="); | |
8294 | if (pos) | |
43a66ecb | 8295 | manual_scan_use_id = atoi(pos + 7); |
949938aa JM |
8296 | |
8297 | pos = os_strstr(params, "only_new=1"); | |
8298 | if (pos) | |
43a66ecb | 8299 | manual_scan_only_new = 1; |
6891f0e6 LJ |
8300 | |
8301 | pos = os_strstr(params, "scan_id="); | |
43a66ecb JM |
8302 | if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count, |
8303 | scan_id) < 0) { | |
6891f0e6 | 8304 | *reply_len = -1; |
43a66ecb | 8305 | goto done; |
6891f0e6 | 8306 | } |
a80651d0 | 8307 | |
267fc0dd AP |
8308 | pos = os_strstr(params, "bssid="); |
8309 | if (pos) { | |
8310 | u8 bssid[ETH_ALEN]; | |
8311 | ||
8312 | pos += 6; | |
8313 | if (hwaddr_aton(pos, bssid)) { | |
8314 | wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos); | |
8315 | *reply_len = -1; | |
8316 | goto done; | |
8317 | } | |
8318 | os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN); | |
8319 | } | |
8320 | ||
a80651d0 KV |
8321 | pos = params; |
8322 | while (pos && *pos != '\0') { | |
8323 | if (os_strncmp(pos, "ssid ", 5) == 0) { | |
8324 | char *end; | |
8325 | ||
8326 | pos += 5; | |
8327 | end = pos; | |
8328 | while (*end) { | |
8329 | if (*end == '\0' || *end == ' ') | |
8330 | break; | |
8331 | end++; | |
8332 | } | |
8333 | ||
8334 | ns = os_realloc_array( | |
8335 | ssid, ssid_count + 1, | |
8336 | sizeof(struct wpa_ssid_value)); | |
8337 | if (ns == NULL) { | |
8338 | *reply_len = -1; | |
8339 | goto done; | |
8340 | } | |
8341 | ssid = ns; | |
8342 | ||
8343 | if ((end - pos) & 0x01 || | |
8344 | end - pos > 2 * SSID_MAX_LEN || | |
8345 | hexstr2bin(pos, ssid[ssid_count].ssid, | |
8346 | (end - pos) / 2) < 0) { | |
8347 | wpa_printf(MSG_DEBUG, | |
8348 | "Invalid SSID value '%s'", | |
8349 | pos); | |
8350 | *reply_len = -1; | |
8351 | goto done; | |
8352 | } | |
8353 | ssid[ssid_count].ssid_len = (end - pos) / 2; | |
8354 | wpa_hexdump_ascii(MSG_DEBUG, "scan SSID", | |
8355 | ssid[ssid_count].ssid, | |
8356 | ssid[ssid_count].ssid_len); | |
8357 | ssid_count++; | |
8358 | pos = end; | |
8359 | } | |
8360 | ||
8361 | pos = os_strchr(pos, ' '); | |
8362 | if (pos) | |
8363 | pos++; | |
8364 | } | |
8365 | } | |
8366 | ||
8367 | wpa_s->num_ssids_from_scan_req = ssid_count; | |
8368 | os_free(wpa_s->ssids_from_scan_req); | |
8369 | if (ssid_count) { | |
8370 | wpa_s->ssids_from_scan_req = ssid; | |
8371 | ssid = NULL; | |
8372 | } else { | |
8373 | wpa_s->ssids_from_scan_req = NULL; | |
fee52342 JM |
8374 | } |
8375 | ||
43a66ecb JM |
8376 | if (scan_only) |
8377 | scan_res_handler = scan_only_handler; | |
8378 | else if (wpa_s->scan_res_handler == scan_only_handler) | |
8379 | scan_res_handler = NULL; | |
8380 | else | |
8381 | scan_res_handler = wpa_s->scan_res_handler; | |
8382 | ||
fee52342 JM |
8383 | if (!wpa_s->sched_scanning && !wpa_s->scanning && |
8384 | ((wpa_s->wpa_state <= WPA_SCANNING) || | |
8385 | (wpa_s->wpa_state == WPA_COMPLETED))) { | |
43a66ecb JM |
8386 | wpa_s->manual_scan_passive = manual_scan_passive; |
8387 | wpa_s->manual_scan_use_id = manual_scan_use_id; | |
8388 | wpa_s->manual_scan_only_new = manual_scan_only_new; | |
8389 | wpa_s->scan_id_count = scan_id_count; | |
8390 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); | |
8391 | wpa_s->scan_res_handler = scan_res_handler; | |
8392 | os_free(wpa_s->manual_scan_freqs); | |
8393 | wpa_s->manual_scan_freqs = manual_scan_freqs; | |
8394 | manual_scan_freqs = NULL; | |
8395 | ||
fee52342 JM |
8396 | wpa_s->normal_scans = 0; |
8397 | wpa_s->scan_req = MANUAL_SCAN_REQ; | |
8398 | wpa_s->after_wps = 0; | |
8399 | wpa_s->known_wps_freq = 0; | |
8400 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
d81c73be JM |
8401 | if (wpa_s->manual_scan_use_id) { |
8402 | wpa_s->manual_scan_id++; | |
8403 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", | |
8404 | wpa_s->manual_scan_id); | |
8405 | *reply_len = os_snprintf(reply, reply_size, "%u\n", | |
8406 | wpa_s->manual_scan_id); | |
8407 | } | |
fee52342 | 8408 | } else if (wpa_s->sched_scanning) { |
43a66ecb JM |
8409 | wpa_s->manual_scan_passive = manual_scan_passive; |
8410 | wpa_s->manual_scan_use_id = manual_scan_use_id; | |
8411 | wpa_s->manual_scan_only_new = manual_scan_only_new; | |
8412 | wpa_s->scan_id_count = scan_id_count; | |
8413 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); | |
8414 | wpa_s->scan_res_handler = scan_res_handler; | |
8415 | os_free(wpa_s->manual_scan_freqs); | |
8416 | wpa_s->manual_scan_freqs = manual_scan_freqs; | |
8417 | manual_scan_freqs = NULL; | |
8418 | ||
fee52342 JM |
8419 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed"); |
8420 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
8421 | wpa_s->scan_req = MANUAL_SCAN_REQ; | |
8422 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
d81c73be JM |
8423 | if (wpa_s->manual_scan_use_id) { |
8424 | wpa_s->manual_scan_id++; | |
8425 | *reply_len = os_snprintf(reply, reply_size, "%u\n", | |
8426 | wpa_s->manual_scan_id); | |
8427 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", | |
8428 | wpa_s->manual_scan_id); | |
8429 | } | |
fee52342 JM |
8430 | } else { |
8431 | wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request"); | |
8432 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | |
8433 | } | |
43a66ecb JM |
8434 | |
8435 | done: | |
8436 | os_free(manual_scan_freqs); | |
a80651d0 | 8437 | os_free(ssid); |
fee52342 JM |
8438 | } |
8439 | ||
8440 | ||
60b893df JM |
8441 | #ifdef CONFIG_TESTING_OPTIONS |
8442 | ||
8443 | static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s, | |
8444 | unsigned int freq, const u8 *dst, | |
8445 | const u8 *src, const u8 *bssid, | |
8446 | const u8 *data, size_t data_len, | |
8447 | enum offchannel_send_action_result | |
8448 | result) | |
8449 | { | |
8450 | wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR | |
8451 | " src=" MACSTR " bssid=" MACSTR " result=%s", | |
8452 | freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid), | |
8453 | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? | |
8454 | "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? | |
8455 | "NO_ACK" : "FAILED")); | |
8456 | } | |
8457 | ||
8458 | ||
8459 | static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd) | |
8460 | { | |
8461 | char *pos, *param; | |
8462 | size_t len; | |
8463 | u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN]; | |
8464 | int res, used; | |
8465 | int freq = 0, no_cck = 0, wait_time = 0; | |
8466 | ||
8467 | /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1] | |
8468 | * <action=Action frame payload> */ | |
8469 | ||
8470 | wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd); | |
8471 | ||
8472 | pos = cmd; | |
8473 | used = hwaddr_aton2(pos, da); | |
8474 | if (used < 0) | |
8475 | return -1; | |
8476 | pos += used; | |
8477 | while (*pos == ' ') | |
8478 | pos++; | |
8479 | used = hwaddr_aton2(pos, bssid); | |
8480 | if (used < 0) | |
8481 | return -1; | |
8482 | pos += used; | |
8483 | ||
8484 | param = os_strstr(pos, " freq="); | |
8485 | if (param) { | |
8486 | param += 6; | |
8487 | freq = atoi(param); | |
8488 | } | |
8489 | ||
8490 | param = os_strstr(pos, " no_cck="); | |
8491 | if (param) { | |
8492 | param += 8; | |
8493 | no_cck = atoi(param); | |
8494 | } | |
8495 | ||
8496 | param = os_strstr(pos, " wait_time="); | |
8497 | if (param) { | |
8498 | param += 11; | |
8499 | wait_time = atoi(param); | |
8500 | } | |
8501 | ||
8502 | param = os_strstr(pos, " action="); | |
8503 | if (param == NULL) | |
8504 | return -1; | |
8505 | param += 8; | |
8506 | ||
8507 | len = os_strlen(param); | |
8508 | if (len & 1) | |
8509 | return -1; | |
8510 | len /= 2; | |
8511 | ||
8512 | buf = os_malloc(len); | |
8513 | if (buf == NULL) | |
8514 | return -1; | |
8515 | ||
8516 | if (hexstr2bin(param, buf, len) < 0) { | |
8517 | os_free(buf); | |
8518 | return -1; | |
8519 | } | |
8520 | ||
8521 | res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid, | |
8522 | buf, len, wait_time, | |
8523 | wpas_ctrl_iface_mgmt_tx_cb, no_cck); | |
8524 | os_free(buf); | |
8525 | return res; | |
8526 | } | |
8527 | ||
8528 | ||
8529 | static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s) | |
8530 | { | |
8531 | wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting"); | |
8532 | offchannel_send_action_done(wpa_s); | |
8533 | } | |
8534 | ||
ad12f2f4 | 8535 | |
4de70e23 JM |
8536 | static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s, |
8537 | char *cmd) | |
8538 | { | |
8539 | char *pos, *param; | |
8540 | size_t len; | |
8541 | u8 *buf; | |
8542 | int freq = 0, datarate = 0, ssi_signal = 0; | |
8543 | union wpa_event_data event; | |
8544 | ||
8545 | if (!wpa_s->ext_mgmt_frame_handling) | |
8546 | return -1; | |
8547 | ||
8548 | /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */ | |
8549 | ||
8550 | wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd); | |
8551 | ||
8552 | pos = cmd; | |
8553 | param = os_strstr(pos, "freq="); | |
8554 | if (param) { | |
8555 | param += 5; | |
8556 | freq = atoi(param); | |
8557 | } | |
8558 | ||
8559 | param = os_strstr(pos, " datarate="); | |
8560 | if (param) { | |
8561 | param += 10; | |
8562 | datarate = atoi(param); | |
8563 | } | |
8564 | ||
8565 | param = os_strstr(pos, " ssi_signal="); | |
8566 | if (param) { | |
8567 | param += 12; | |
8568 | ssi_signal = atoi(param); | |
8569 | } | |
8570 | ||
8571 | param = os_strstr(pos, " frame="); | |
8572 | if (param == NULL) | |
8573 | return -1; | |
8574 | param += 7; | |
8575 | ||
8576 | len = os_strlen(param); | |
8577 | if (len & 1) | |
8578 | return -1; | |
8579 | len /= 2; | |
8580 | ||
8581 | buf = os_malloc(len); | |
8582 | if (buf == NULL) | |
8583 | return -1; | |
8584 | ||
8585 | if (hexstr2bin(param, buf, len) < 0) { | |
8586 | os_free(buf); | |
8587 | return -1; | |
8588 | } | |
8589 | ||
8590 | os_memset(&event, 0, sizeof(event)); | |
8591 | event.rx_mgmt.freq = freq; | |
8592 | event.rx_mgmt.frame = buf; | |
8593 | event.rx_mgmt.frame_len = len; | |
8594 | event.rx_mgmt.ssi_signal = ssi_signal; | |
8595 | event.rx_mgmt.datarate = datarate; | |
8596 | wpa_s->ext_mgmt_frame_handling = 0; | |
8597 | wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event); | |
8598 | wpa_s->ext_mgmt_frame_handling = 1; | |
8599 | ||
8600 | os_free(buf); | |
8601 | ||
8602 | return 0; | |
8603 | } | |
8604 | ||
8605 | ||
e4a3e1d0 JM |
8606 | static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s, |
8607 | char *param) | |
8608 | { | |
8609 | struct wpa_scan_res *res; | |
8610 | struct os_reltime now; | |
8611 | char *pos, *end; | |
1fb4437c | 8612 | int ret = -1; |
e4a3e1d0 JM |
8613 | |
8614 | if (!param) | |
8615 | return -1; | |
8616 | ||
8617 | if (os_strcmp(param, "START") == 0) { | |
8618 | wpa_bss_update_start(wpa_s); | |
8619 | return 0; | |
8620 | } | |
8621 | ||
8622 | if (os_strcmp(param, "END") == 0) { | |
8623 | wpa_bss_update_end(wpa_s, NULL, 1); | |
8624 | return 0; | |
8625 | } | |
8626 | ||
8627 | if (os_strncmp(param, "BSS ", 4) != 0) | |
8628 | return -1; | |
8629 | param += 3; | |
8630 | ||
8631 | res = os_zalloc(sizeof(*res) + os_strlen(param) / 2); | |
8632 | if (!res) | |
8633 | return -1; | |
8634 | ||
8635 | pos = os_strstr(param, " flags="); | |
8636 | if (pos) | |
8637 | res->flags = strtol(pos + 7, NULL, 16); | |
8638 | ||
8639 | pos = os_strstr(param, " bssid="); | |
1fb4437c JM |
8640 | if (pos && hwaddr_aton(pos + 7, res->bssid)) |
8641 | goto fail; | |
e4a3e1d0 JM |
8642 | |
8643 | pos = os_strstr(param, " freq="); | |
8644 | if (pos) | |
8645 | res->freq = atoi(pos + 6); | |
8646 | ||
8647 | pos = os_strstr(param, " beacon_int="); | |
8648 | if (pos) | |
8649 | res->beacon_int = atoi(pos + 12); | |
8650 | ||
8651 | pos = os_strstr(param, " caps="); | |
8652 | if (pos) | |
8653 | res->caps = strtol(pos + 6, NULL, 16); | |
8654 | ||
8655 | pos = os_strstr(param, " qual="); | |
8656 | if (pos) | |
8657 | res->qual = atoi(pos + 6); | |
8658 | ||
8659 | pos = os_strstr(param, " noise="); | |
8660 | if (pos) | |
8661 | res->noise = atoi(pos + 7); | |
8662 | ||
8663 | pos = os_strstr(param, " level="); | |
8664 | if (pos) | |
8665 | res->level = atoi(pos + 7); | |
8666 | ||
8667 | pos = os_strstr(param, " tsf="); | |
8668 | if (pos) | |
8669 | res->tsf = strtoll(pos + 5, NULL, 16); | |
8670 | ||
8671 | pos = os_strstr(param, " age="); | |
8672 | if (pos) | |
8673 | res->age = atoi(pos + 5); | |
8674 | ||
8675 | pos = os_strstr(param, " est_throughput="); | |
8676 | if (pos) | |
8677 | res->est_throughput = atoi(pos + 16); | |
8678 | ||
8679 | pos = os_strstr(param, " snr="); | |
8680 | if (pos) | |
8681 | res->snr = atoi(pos + 5); | |
8682 | ||
8683 | pos = os_strstr(param, " parent_tsf="); | |
8684 | if (pos) | |
8685 | res->parent_tsf = strtoll(pos + 7, NULL, 16); | |
8686 | ||
8687 | pos = os_strstr(param, " tsf_bssid="); | |
1fb4437c JM |
8688 | if (pos && hwaddr_aton(pos + 11, res->tsf_bssid)) |
8689 | goto fail; | |
e4a3e1d0 JM |
8690 | |
8691 | pos = os_strstr(param, " ie="); | |
8692 | if (pos) { | |
8693 | pos += 4; | |
8694 | end = os_strchr(pos, ' '); | |
8695 | if (!end) | |
8696 | end = pos + os_strlen(pos); | |
8697 | res->ie_len = (end - pos) / 2; | |
1fb4437c JM |
8698 | if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len)) |
8699 | goto fail; | |
e4a3e1d0 JM |
8700 | } |
8701 | ||
8702 | pos = os_strstr(param, " beacon_ie="); | |
8703 | if (pos) { | |
8704 | pos += 11; | |
8705 | end = os_strchr(pos, ' '); | |
8706 | if (!end) | |
8707 | end = pos + os_strlen(pos); | |
8708 | res->beacon_ie_len = (end - pos) / 2; | |
1fb4437c JM |
8709 | if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len, |
8710 | res->beacon_ie_len)) | |
8711 | goto fail; | |
e4a3e1d0 JM |
8712 | } |
8713 | ||
8714 | os_get_reltime(&now); | |
8715 | wpa_bss_update_scan_res(wpa_s, res, &now); | |
1fb4437c JM |
8716 | ret = 0; |
8717 | fail: | |
e4a3e1d0 JM |
8718 | os_free(res); |
8719 | ||
1fb4437c | 8720 | return ret; |
e4a3e1d0 JM |
8721 | } |
8722 | ||
8723 | ||
ad12f2f4 JM |
8724 | static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd) |
8725 | { | |
8726 | char *pos, *param; | |
8727 | union wpa_event_data event; | |
8728 | enum wpa_event_type ev; | |
8729 | ||
8730 | /* <event name> [parameters..] */ | |
8731 | ||
8732 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd); | |
8733 | ||
8734 | pos = cmd; | |
8735 | param = os_strchr(pos, ' '); | |
8736 | if (param) | |
8737 | *param++ = '\0'; | |
8738 | ||
8739 | os_memset(&event, 0, sizeof(event)); | |
8740 | ||
8741 | if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) { | |
8742 | ev = EVENT_INTERFACE_ENABLED; | |
8743 | } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) { | |
8744 | ev = EVENT_INTERFACE_DISABLED; | |
7bb70909 JM |
8745 | } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) { |
8746 | ev = EVENT_AVOID_FREQUENCIES; | |
8747 | if (param == NULL) | |
8748 | param = ""; | |
8749 | if (freq_range_list_parse(&event.freq_range, param) < 0) | |
8750 | return -1; | |
8751 | wpa_supplicant_event(wpa_s, ev, &event); | |
8752 | os_free(event.freq_range.range); | |
8753 | return 0; | |
e4a3e1d0 JM |
8754 | } else if (os_strcmp(cmd, "SCAN_RES") == 0) { |
8755 | return wpas_ctrl_iface_driver_scan_res(wpa_s, param); | |
ad12f2f4 JM |
8756 | } else { |
8757 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s", | |
8758 | cmd); | |
8759 | return -1; | |
8760 | } | |
8761 | ||
8762 | wpa_supplicant_event(wpa_s, ev, &event); | |
8763 | ||
8764 | return 0; | |
8765 | } | |
8766 | ||
9d4ff04a JM |
8767 | |
8768 | static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd) | |
8769 | { | |
8770 | char *pos; | |
8771 | u8 src[ETH_ALEN], *buf; | |
8772 | int used; | |
8773 | size_t len; | |
8774 | ||
8775 | wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd); | |
8776 | ||
8777 | pos = cmd; | |
8778 | used = hwaddr_aton2(pos, src); | |
8779 | if (used < 0) | |
8780 | return -1; | |
8781 | pos += used; | |
8782 | while (*pos == ' ') | |
8783 | pos++; | |
8784 | ||
8785 | len = os_strlen(pos); | |
8786 | if (len & 1) | |
8787 | return -1; | |
8788 | len /= 2; | |
8789 | ||
8790 | buf = os_malloc(len); | |
8791 | if (buf == NULL) | |
8792 | return -1; | |
8793 | ||
8794 | if (hexstr2bin(pos, buf, len) < 0) { | |
8795 | os_free(buf); | |
8796 | return -1; | |
8797 | } | |
8798 | ||
8799 | wpa_supplicant_rx_eapol(wpa_s, src, buf, len); | |
8800 | os_free(buf); | |
8801 | ||
8802 | return 0; | |
8803 | } | |
8804 | ||
4a6cc862 JM |
8805 | |
8806 | static u16 ipv4_hdr_checksum(const void *buf, size_t len) | |
8807 | { | |
8808 | size_t i; | |
8809 | u32 sum = 0; | |
8810 | const u16 *pos = buf; | |
8811 | ||
8812 | for (i = 0; i < len / 2; i++) | |
8813 | sum += *pos++; | |
8814 | ||
8815 | while (sum >> 16) | |
8816 | sum = (sum & 0xffff) + (sum >> 16); | |
8817 | ||
8818 | return sum ^ 0xffff; | |
8819 | } | |
8820 | ||
8821 | ||
8822 | #define HWSIM_PACKETLEN 1500 | |
8823 | #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header)) | |
8824 | ||
0dbe22be JM |
8825 | static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, |
8826 | size_t len) | |
4a6cc862 JM |
8827 | { |
8828 | struct wpa_supplicant *wpa_s = ctx; | |
8829 | const struct ether_header *eth; | |
75352270 | 8830 | struct iphdr ip; |
4a6cc862 JM |
8831 | const u8 *pos; |
8832 | unsigned int i; | |
93701b4a | 8833 | char extra[30]; |
4a6cc862 | 8834 | |
93701b4a JM |
8835 | if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) { |
8836 | wpa_printf(MSG_DEBUG, | |
8837 | "test data: RX - ignore unexpected length %d", | |
8838 | (int) len); | |
4a6cc862 | 8839 | return; |
93701b4a | 8840 | } |
4a6cc862 JM |
8841 | |
8842 | eth = (const struct ether_header *) buf; | |
75352270 JM |
8843 | os_memcpy(&ip, eth + 1, sizeof(ip)); |
8844 | pos = &buf[sizeof(*eth) + sizeof(ip)]; | |
4a6cc862 | 8845 | |
75352270 | 8846 | if (ip.ihl != 5 || ip.version != 4 || |
93701b4a JM |
8847 | ntohs(ip.tot_len) > HWSIM_IP_LEN) { |
8848 | wpa_printf(MSG_DEBUG, | |
8849 | "test data: RX - ignore unexpect IP header"); | |
4a6cc862 | 8850 | return; |
93701b4a | 8851 | } |
4a6cc862 | 8852 | |
93701b4a JM |
8853 | for (i = 0; i < ntohs(ip.tot_len) - sizeof(ip); i++) { |
8854 | if (*pos != (u8) i) { | |
8855 | wpa_printf(MSG_DEBUG, | |
8856 | "test data: RX - ignore mismatching payload"); | |
4a6cc862 | 8857 | return; |
93701b4a | 8858 | } |
4a6cc862 JM |
8859 | pos++; |
8860 | } | |
93701b4a JM |
8861 | extra[0] = '\0'; |
8862 | if (ntohs(ip.tot_len) != HWSIM_IP_LEN) | |
8863 | os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.tot_len)); | |
8864 | wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s", | |
8865 | MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra); | |
4a6cc862 JM |
8866 | } |
8867 | ||
8868 | ||
8869 | static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s, | |
8870 | char *cmd) | |
8871 | { | |
8872 | int enabled = atoi(cmd); | |
ba91e920 MB |
8873 | char *pos; |
8874 | const char *ifname; | |
4a6cc862 JM |
8875 | |
8876 | if (!enabled) { | |
8877 | if (wpa_s->l2_test) { | |
8878 | l2_packet_deinit(wpa_s->l2_test); | |
8879 | wpa_s->l2_test = NULL; | |
8880 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled"); | |
8881 | } | |
8882 | return 0; | |
8883 | } | |
8884 | ||
8885 | if (wpa_s->l2_test) | |
8886 | return 0; | |
8887 | ||
ba91e920 MB |
8888 | pos = os_strstr(cmd, " ifname="); |
8889 | if (pos) | |
8890 | ifname = pos + 8; | |
8891 | else | |
8892 | ifname = wpa_s->ifname; | |
8893 | ||
8894 | wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr, | |
4a6cc862 JM |
8895 | ETHERTYPE_IP, wpas_data_test_rx, |
8896 | wpa_s, 1); | |
8897 | if (wpa_s->l2_test == NULL) | |
8898 | return -1; | |
8899 | ||
8900 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled"); | |
8901 | ||
8902 | return 0; | |
8903 | } | |
8904 | ||
8905 | ||
8906 | static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd) | |
8907 | { | |
8908 | u8 dst[ETH_ALEN], src[ETH_ALEN]; | |
93701b4a | 8909 | char *pos, *pos2; |
4a6cc862 JM |
8910 | int used; |
8911 | long int val; | |
8912 | u8 tos; | |
75352270 | 8913 | u8 buf[2 + HWSIM_PACKETLEN]; |
4a6cc862 JM |
8914 | struct ether_header *eth; |
8915 | struct iphdr *ip; | |
8916 | u8 *dpos; | |
8917 | unsigned int i; | |
93701b4a | 8918 | size_t send_len = HWSIM_IP_LEN; |
4a6cc862 JM |
8919 | |
8920 | if (wpa_s->l2_test == NULL) | |
8921 | return -1; | |
8922 | ||
93701b4a | 8923 | /* format: <dst> <src> <tos> [len=<length>] */ |
4a6cc862 JM |
8924 | |
8925 | pos = cmd; | |
8926 | used = hwaddr_aton2(pos, dst); | |
8927 | if (used < 0) | |
8928 | return -1; | |
8929 | pos += used; | |
8930 | while (*pos == ' ') | |
8931 | pos++; | |
8932 | used = hwaddr_aton2(pos, src); | |
8933 | if (used < 0) | |
8934 | return -1; | |
8935 | pos += used; | |
8936 | ||
93701b4a | 8937 | val = strtol(pos, &pos2, 0); |
4a6cc862 JM |
8938 | if (val < 0 || val > 0xff) |
8939 | return -1; | |
8940 | tos = val; | |
8941 | ||
93701b4a JM |
8942 | pos = os_strstr(pos2, " len="); |
8943 | if (pos) { | |
8944 | i = atoi(pos + 5); | |
8945 | if (i < sizeof(*ip) || i > HWSIM_IP_LEN) | |
8946 | return -1; | |
8947 | send_len = i; | |
8948 | } | |
8949 | ||
75352270 | 8950 | eth = (struct ether_header *) &buf[2]; |
4a6cc862 JM |
8951 | os_memcpy(eth->ether_dhost, dst, ETH_ALEN); |
8952 | os_memcpy(eth->ether_shost, src, ETH_ALEN); | |
8953 | eth->ether_type = htons(ETHERTYPE_IP); | |
8954 | ip = (struct iphdr *) (eth + 1); | |
8955 | os_memset(ip, 0, sizeof(*ip)); | |
8956 | ip->ihl = 5; | |
8957 | ip->version = 4; | |
8958 | ip->ttl = 64; | |
8959 | ip->tos = tos; | |
93701b4a | 8960 | ip->tot_len = htons(send_len); |
4a6cc862 | 8961 | ip->protocol = 1; |
66f1e078 JM |
8962 | ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1); |
8963 | ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2); | |
4a6cc862 JM |
8964 | ip->check = ipv4_hdr_checksum(ip, sizeof(*ip)); |
8965 | dpos = (u8 *) (ip + 1); | |
93701b4a | 8966 | for (i = 0; i < send_len - sizeof(*ip); i++) |
4a6cc862 JM |
8967 | *dpos++ = i; |
8968 | ||
75352270 | 8969 | if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2], |
93701b4a | 8970 | sizeof(struct ether_header) + send_len) < 0) |
4a6cc862 JM |
8971 | return -1; |
8972 | ||
8973 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR | |
8974 | " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos); | |
8975 | ||
8976 | return 0; | |
8977 | } | |
8978 | ||
fc0ef7c0 JM |
8979 | |
8980 | static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s, | |
8981 | char *cmd) | |
8982 | { | |
8983 | u8 *buf; | |
8984 | struct ether_header *eth; | |
8985 | struct l2_packet_data *l2 = NULL; | |
8986 | size_t len; | |
8987 | u16 ethertype; | |
8988 | int res = -1; | |
8989 | ||
8990 | len = os_strlen(cmd); | |
8991 | if (len & 1 || len < ETH_HLEN * 2) | |
8992 | return -1; | |
8993 | len /= 2; | |
8994 | ||
8995 | buf = os_malloc(len); | |
8996 | if (buf == NULL) | |
8997 | return -1; | |
8998 | ||
8999 | if (hexstr2bin(cmd, buf, len) < 0) | |
9000 | goto done; | |
9001 | ||
9002 | eth = (struct ether_header *) buf; | |
9003 | ethertype = ntohs(eth->ether_type); | |
9004 | ||
9005 | l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype, | |
9006 | wpas_data_test_rx, wpa_s, 1); | |
9007 | if (l2 == NULL) | |
9008 | goto done; | |
9009 | ||
9010 | res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len); | |
9011 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res); | |
9012 | done: | |
9013 | if (l2) | |
9014 | l2_packet_deinit(l2); | |
9015 | os_free(buf); | |
9016 | ||
9017 | return res < 0 ? -1 : 0; | |
9018 | } | |
9019 | ||
a156ffda JM |
9020 | |
9021 | static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd) | |
9022 | { | |
9023 | #ifdef WPA_TRACE_BFD | |
a156ffda JM |
9024 | char *pos; |
9025 | ||
9026 | wpa_trace_fail_after = atoi(cmd); | |
9027 | pos = os_strchr(cmd, ':'); | |
9028 | if (pos) { | |
9029 | pos++; | |
9030 | os_strlcpy(wpa_trace_fail_func, pos, | |
9031 | sizeof(wpa_trace_fail_func)); | |
9032 | } else { | |
9033 | wpa_trace_fail_after = 0; | |
9034 | } | |
9035 | return 0; | |
9036 | #else /* WPA_TRACE_BFD */ | |
9037 | return -1; | |
9038 | #endif /* WPA_TRACE_BFD */ | |
9039 | } | |
9040 | ||
9041 | ||
9042 | static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s, | |
9043 | char *buf, size_t buflen) | |
9044 | { | |
9045 | #ifdef WPA_TRACE_BFD | |
a156ffda JM |
9046 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after, |
9047 | wpa_trace_fail_func); | |
9048 | #else /* WPA_TRACE_BFD */ | |
9049 | return -1; | |
9050 | #endif /* WPA_TRACE_BFD */ | |
9051 | } | |
9052 | ||
2da52565 JM |
9053 | |
9054 | static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd) | |
9055 | { | |
9056 | #ifdef WPA_TRACE_BFD | |
2da52565 JM |
9057 | char *pos; |
9058 | ||
9059 | wpa_trace_test_fail_after = atoi(cmd); | |
9060 | pos = os_strchr(cmd, ':'); | |
9061 | if (pos) { | |
9062 | pos++; | |
9063 | os_strlcpy(wpa_trace_test_fail_func, pos, | |
9064 | sizeof(wpa_trace_test_fail_func)); | |
9065 | } else { | |
9066 | wpa_trace_test_fail_after = 0; | |
9067 | } | |
9068 | return 0; | |
9069 | #else /* WPA_TRACE_BFD */ | |
9070 | return -1; | |
9071 | #endif /* WPA_TRACE_BFD */ | |
9072 | } | |
9073 | ||
9074 | ||
9075 | static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s, | |
9076 | char *buf, size_t buflen) | |
9077 | { | |
9078 | #ifdef WPA_TRACE_BFD | |
2da52565 JM |
9079 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after, |
9080 | wpa_trace_test_fail_func); | |
9081 | #else /* WPA_TRACE_BFD */ | |
9082 | return -1; | |
9083 | #endif /* WPA_TRACE_BFD */ | |
9084 | } | |
9085 | ||
a530fe77 JM |
9086 | |
9087 | static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx) | |
9088 | { | |
9089 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
9090 | int i, count = (intptr_t) timeout_ctx; | |
9091 | ||
9092 | wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages", | |
9093 | count); | |
9094 | for (i = 0; i < count; i++) { | |
9095 | wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d", | |
9096 | i + 1, count); | |
9097 | } | |
9098 | } | |
9099 | ||
9100 | ||
9101 | static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd) | |
9102 | { | |
9103 | int count; | |
9104 | ||
9105 | count = atoi(cmd); | |
9106 | if (count <= 0) | |
9107 | return -1; | |
9108 | ||
9109 | return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s, | |
9110 | (void *) (intptr_t) count); | |
9111 | } | |
9112 | ||
651c6a84 JM |
9113 | |
9114 | static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s, | |
9115 | const char *cmd) | |
9116 | { | |
9117 | struct wpabuf *buf; | |
9118 | size_t len; | |
9119 | ||
9120 | len = os_strlen(cmd); | |
9121 | if (len & 1) | |
9122 | return -1; | |
9123 | len /= 2; | |
9124 | ||
9125 | if (len == 0) { | |
9126 | buf = NULL; | |
9127 | } else { | |
9128 | buf = wpabuf_alloc(len); | |
9129 | if (buf == NULL) | |
9130 | return -1; | |
9131 | ||
9132 | if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) { | |
9133 | wpabuf_free(buf); | |
9134 | return -1; | |
9135 | } | |
9136 | } | |
9137 | ||
9138 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf); | |
9139 | return 0; | |
9140 | } | |
9141 | ||
16579769 JM |
9142 | |
9143 | static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s) | |
9144 | { | |
9145 | u8 zero[WPA_TK_MAX_LEN]; | |
9146 | ||
9147 | if (wpa_s->last_tk_alg == WPA_ALG_NONE) | |
9148 | return -1; | |
9149 | ||
9150 | wpa_printf(MSG_INFO, "TESTING: Reset PN"); | |
9151 | os_memset(zero, 0, sizeof(zero)); | |
9152 | ||
9153 | /* First, use a zero key to avoid any possible duplicate key avoidance | |
9154 | * in the driver. */ | |
9155 | if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr, | |
9156 | wpa_s->last_tk_key_idx, 1, zero, 6, | |
9157 | zero, wpa_s->last_tk_len) < 0) | |
9158 | return -1; | |
9159 | ||
9160 | /* Set the previously configured key to reset its TSC/RSC */ | |
9161 | return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr, | |
9162 | wpa_s->last_tk_key_idx, 1, zero, 6, | |
9163 | wpa_s->last_tk, wpa_s->last_tk_len); | |
9164 | } | |
9165 | ||
751f5b29 JM |
9166 | |
9167 | static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd) | |
9168 | { | |
9169 | const char *pos = cmd; | |
9170 | int error, pairwise; | |
9171 | ||
9172 | error = atoi(pos); | |
9173 | pos = os_strchr(pos, ' '); | |
9174 | if (!pos) | |
9175 | return -1; | |
9176 | pairwise = atoi(pos); | |
9177 | wpa_sm_key_request(wpa_s->wpa, error, pairwise); | |
9178 | return 0; | |
9179 | } | |
9180 | ||
daa40960 JM |
9181 | |
9182 | static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s) | |
9183 | { | |
9184 | #ifdef CONFIG_SME | |
9185 | struct wpa_driver_associate_params params; | |
9186 | int ret; | |
9187 | ||
9188 | os_memset(¶ms, 0, sizeof(params)); | |
9189 | params.bssid = wpa_s->bssid; | |
9190 | params.ssid = wpa_s->sme.ssid; | |
9191 | params.ssid_len = wpa_s->sme.ssid_len; | |
9192 | params.freq.freq = wpa_s->sme.freq; | |
9193 | if (wpa_s->last_assoc_req_wpa_ie) { | |
9194 | params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie); | |
9195 | params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie); | |
9196 | } | |
9197 | params.pairwise_suite = wpa_s->pairwise_cipher; | |
9198 | params.group_suite = wpa_s->group_cipher; | |
9199 | params.mgmt_group_suite = wpa_s->mgmt_group_cipher; | |
9200 | params.key_mgmt_suite = wpa_s->key_mgmt; | |
9201 | params.wpa_proto = wpa_s->wpa_proto; | |
9202 | params.mgmt_frame_protection = wpa_s->sme.mfp; | |
9203 | params.rrm_used = wpa_s->rrm.rrm_used; | |
9204 | if (wpa_s->sme.prev_bssid_set) | |
9205 | params.prev_bssid = wpa_s->sme.prev_bssid; | |
9206 | wpa_printf(MSG_INFO, "TESTING: Resend association request"); | |
9207 | ret = wpa_drv_associate(wpa_s, ¶ms); | |
9208 | wpa_s->testing_resend_assoc = 1; | |
9209 | return ret; | |
9210 | #else /* CONFIG_SME */ | |
9211 | return -1; | |
9212 | #endif /* CONFIG_SME */ | |
9213 | } | |
9214 | ||
60b893df JM |
9215 | #endif /* CONFIG_TESTING_OPTIONS */ |
9216 | ||
9217 | ||
86bd36f0 JM |
9218 | static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd) |
9219 | { | |
9220 | char *pos = cmd; | |
9221 | int frame; | |
9222 | size_t len; | |
9223 | struct wpabuf *buf; | |
9224 | struct ieee802_11_elems elems; | |
9225 | ||
9226 | frame = atoi(pos); | |
9227 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | |
9228 | return -1; | |
af041f99 | 9229 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
86bd36f0 JM |
9230 | |
9231 | pos = os_strchr(pos, ' '); | |
9232 | if (pos == NULL) | |
9233 | return -1; | |
9234 | pos++; | |
9235 | ||
9236 | len = os_strlen(pos); | |
9237 | if (len == 0) | |
9238 | return 0; | |
9239 | if (len & 1) | |
9240 | return -1; | |
9241 | len /= 2; | |
9242 | ||
9243 | buf = wpabuf_alloc(len); | |
9244 | if (buf == NULL) | |
9245 | return -1; | |
9246 | ||
9247 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { | |
9248 | wpabuf_free(buf); | |
9249 | return -1; | |
9250 | } | |
9251 | ||
9252 | if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) == | |
9253 | ParseFailed) { | |
9254 | wpabuf_free(buf); | |
9255 | return -1; | |
9256 | } | |
9257 | ||
9258 | if (wpa_s->vendor_elem[frame] == NULL) { | |
9259 | wpa_s->vendor_elem[frame] = buf; | |
af041f99 | 9260 | wpas_vendor_elem_update(wpa_s); |
86bd36f0 JM |
9261 | return 0; |
9262 | } | |
9263 | ||
9264 | if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) { | |
9265 | wpabuf_free(buf); | |
9266 | return -1; | |
9267 | } | |
9268 | ||
9269 | wpabuf_put_buf(wpa_s->vendor_elem[frame], buf); | |
9270 | wpabuf_free(buf); | |
af041f99 | 9271 | wpas_vendor_elem_update(wpa_s); |
86bd36f0 JM |
9272 | |
9273 | return 0; | |
9274 | } | |
9275 | ||
9276 | ||
9277 | static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd, | |
9278 | char *buf, size_t buflen) | |
9279 | { | |
9280 | int frame = atoi(cmd); | |
9281 | ||
9282 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | |
9283 | return -1; | |
af041f99 | 9284 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
86bd36f0 JM |
9285 | |
9286 | if (wpa_s->vendor_elem[frame] == NULL) | |
9287 | return 0; | |
9288 | ||
9289 | return wpa_snprintf_hex(buf, buflen, | |
9290 | wpabuf_head_u8(wpa_s->vendor_elem[frame]), | |
9291 | wpabuf_len(wpa_s->vendor_elem[frame])); | |
9292 | } | |
9293 | ||
9294 | ||
9295 | static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd) | |
9296 | { | |
9297 | char *pos = cmd; | |
9298 | int frame; | |
9299 | size_t len; | |
9300 | u8 *buf; | |
9301 | struct ieee802_11_elems elems; | |
af041f99 | 9302 | int res; |
86bd36f0 JM |
9303 | |
9304 | frame = atoi(pos); | |
9305 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | |
9306 | return -1; | |
af041f99 | 9307 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
86bd36f0 JM |
9308 | |
9309 | pos = os_strchr(pos, ' '); | |
9310 | if (pos == NULL) | |
9311 | return -1; | |
9312 | pos++; | |
9313 | ||
9314 | if (*pos == '*') { | |
9315 | wpabuf_free(wpa_s->vendor_elem[frame]); | |
9316 | wpa_s->vendor_elem[frame] = NULL; | |
af041f99 | 9317 | wpas_vendor_elem_update(wpa_s); |
86bd36f0 JM |
9318 | return 0; |
9319 | } | |
9320 | ||
9321 | if (wpa_s->vendor_elem[frame] == NULL) | |
9322 | return -1; | |
9323 | ||
9324 | len = os_strlen(pos); | |
9325 | if (len == 0) | |
9326 | return 0; | |
9327 | if (len & 1) | |
9328 | return -1; | |
9329 | len /= 2; | |
9330 | ||
9331 | buf = os_malloc(len); | |
9332 | if (buf == NULL) | |
9333 | return -1; | |
9334 | ||
9335 | if (hexstr2bin(pos, buf, len) < 0) { | |
9336 | os_free(buf); | |
9337 | return -1; | |
9338 | } | |
9339 | ||
9340 | if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) { | |
9341 | os_free(buf); | |
9342 | return -1; | |
9343 | } | |
9344 | ||
af041f99 | 9345 | res = wpas_vendor_elem_remove(wpa_s, frame, buf, len); |
86bd36f0 | 9346 | os_free(buf); |
af041f99 | 9347 | return res; |
86bd36f0 JM |
9348 | } |
9349 | ||
9350 | ||
f4b8bfae AK |
9351 | static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep) |
9352 | { | |
9353 | struct wpa_supplicant *wpa_s = ctx; | |
cf667c66 IP |
9354 | size_t len; |
9355 | const u8 *data; | |
f4b8bfae | 9356 | |
cf667c66 IP |
9357 | /* |
9358 | * Neighbor Report element (IEEE P802.11-REVmc/D5.0) | |
9359 | * BSSID[6] | |
9360 | * BSSID Information[4] | |
9361 | * Operating Class[1] | |
9362 | * Channel Number[1] | |
9363 | * PHY Type[1] | |
9364 | * Optional Subelements[variable] | |
9365 | */ | |
9366 | #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1) | |
9367 | ||
9368 | if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) { | |
f4b8bfae | 9369 | wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED); |
cf667c66 IP |
9370 | goto out; |
9371 | } | |
9372 | ||
9373 | data = wpabuf_head_u8(neighbor_rep); | |
9374 | len = wpabuf_len(neighbor_rep); | |
9375 | ||
9376 | while (len >= 2 + NR_IE_MIN_LEN) { | |
9377 | const u8 *nr; | |
9378 | char lci[256 * 2 + 1]; | |
9379 | char civic[256 * 2 + 1]; | |
9380 | u8 nr_len = data[1]; | |
9381 | const u8 *pos = data, *end; | |
9382 | ||
9383 | if (pos[0] != WLAN_EID_NEIGHBOR_REPORT || | |
9384 | nr_len < NR_IE_MIN_LEN) { | |
9385 | wpa_printf(MSG_DEBUG, | |
9386 | "CTRL: Invalid Neighbor Report element: id=%u len=%u", | |
9387 | data[0], nr_len); | |
9388 | goto out; | |
9389 | } | |
9390 | ||
9391 | if (2U + nr_len > len) { | |
9392 | wpa_printf(MSG_DEBUG, | |
9393 | "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u", | |
9394 | data[0], len, nr_len); | |
9395 | goto out; | |
9396 | } | |
9397 | pos += 2; | |
9398 | end = pos + nr_len; | |
9399 | ||
9400 | nr = pos; | |
9401 | pos += NR_IE_MIN_LEN; | |
9402 | ||
9403 | lci[0] = '\0'; | |
9404 | civic[0] = '\0'; | |
9405 | while (end - pos > 2) { | |
9406 | u8 s_id, s_len; | |
9407 | ||
9408 | s_id = *pos++; | |
9409 | s_len = *pos++; | |
9410 | if (s_len > end - pos) | |
9411 | goto out; | |
9412 | if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) { | |
9413 | /* Measurement Token[1] */ | |
9414 | /* Measurement Report Mode[1] */ | |
9415 | /* Measurement Type[1] */ | |
9416 | /* Measurement Report[variable] */ | |
9417 | switch (pos[2]) { | |
9418 | case MEASURE_TYPE_LCI: | |
9419 | if (lci[0]) | |
9420 | break; | |
9421 | wpa_snprintf_hex(lci, sizeof(lci), | |
9422 | pos, s_len); | |
9423 | break; | |
9424 | case MEASURE_TYPE_LOCATION_CIVIC: | |
9425 | if (civic[0]) | |
9426 | break; | |
9427 | wpa_snprintf_hex(civic, sizeof(civic), | |
9428 | pos, s_len); | |
9429 | break; | |
9430 | } | |
9431 | } | |
9432 | ||
9433 | pos += s_len; | |
9434 | } | |
9435 | ||
9436 | wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED | |
9437 | "bssid=" MACSTR | |
9438 | " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s", | |
9439 | MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN), | |
9440 | nr[ETH_ALEN + 4], nr[ETH_ALEN + 5], | |
9441 | nr[ETH_ALEN + 6], | |
9442 | lci[0] ? " lci=" : "", lci, | |
9443 | civic[0] ? " civic=" : "", civic); | |
9444 | ||
9445 | data = end; | |
9446 | len -= 2 + nr_len; | |
f4b8bfae | 9447 | } |
cf667c66 IP |
9448 | |
9449 | out: | |
9450 | wpabuf_free(neighbor_rep); | |
f4b8bfae AK |
9451 | } |
9452 | ||
9453 | ||
6a4f0ed7 JM |
9454 | static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s, |
9455 | char *cmd) | |
f4b8bfae | 9456 | { |
d41a5352 DS |
9457 | struct wpa_ssid_value ssid, *ssid_p = NULL; |
9458 | int ret, lci = 0, civic = 0; | |
9459 | char *ssid_s; | |
4c4b2305 | 9460 | |
d41a5352 DS |
9461 | ssid_s = os_strstr(cmd, "ssid="); |
9462 | if (ssid_s) { | |
9463 | if (ssid_parse(ssid_s + 5, &ssid)) { | |
9464 | wpa_printf(MSG_ERROR, | |
9465 | "CTRL: Send Neighbor Report: bad SSID"); | |
4c4b2305 | 9466 | return -1; |
d41a5352 DS |
9467 | } |
9468 | ||
4c4b2305 | 9469 | ssid_p = &ssid; |
d41a5352 DS |
9470 | |
9471 | /* | |
9472 | * Move cmd after the SSID text that may include "lci" or | |
9473 | * "civic". | |
9474 | */ | |
9475 | cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' '); | |
9476 | if (cmd) | |
9477 | cmd++; | |
9478 | ||
4c4b2305 AK |
9479 | } |
9480 | ||
d41a5352 DS |
9481 | if (cmd && os_strstr(cmd, "lci")) |
9482 | lci = 1; | |
9483 | ||
9484 | if (cmd && os_strstr(cmd, "civic")) | |
9485 | civic = 1; | |
9486 | ||
9487 | ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic, | |
4c4b2305 AK |
9488 | wpas_ctrl_neighbor_rep_cb, |
9489 | wpa_s); | |
9490 | ||
9491 | return ret; | |
f4b8bfae AK |
9492 | } |
9493 | ||
9494 | ||
65d9a5e2 JM |
9495 | static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s) |
9496 | { | |
9497 | eapol_sm_erp_flush(wpa_s->eapol); | |
9498 | return 0; | |
9499 | } | |
9500 | ||
9501 | ||
fb375883 IP |
9502 | static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s, |
9503 | char *cmd) | |
9504 | { | |
9505 | char *token, *context = NULL; | |
9506 | unsigned int enable = ~0, type = 0; | |
9507 | u8 _addr[ETH_ALEN], _mask[ETH_ALEN]; | |
9508 | u8 *addr = NULL, *mask = NULL; | |
9509 | ||
9510 | while ((token = str_token(cmd, " ", &context))) { | |
9511 | if (os_strcasecmp(token, "scan") == 0) { | |
9512 | type |= MAC_ADDR_RAND_SCAN; | |
9513 | } else if (os_strcasecmp(token, "sched") == 0) { | |
9514 | type |= MAC_ADDR_RAND_SCHED_SCAN; | |
9515 | } else if (os_strcasecmp(token, "pno") == 0) { | |
9516 | type |= MAC_ADDR_RAND_PNO; | |
9517 | } else if (os_strcasecmp(token, "all") == 0) { | |
9518 | type = wpa_s->mac_addr_rand_supported; | |
9519 | } else if (os_strncasecmp(token, "enable=", 7) == 0) { | |
9520 | enable = atoi(token + 7); | |
9521 | } else if (os_strncasecmp(token, "addr=", 5) == 0) { | |
9522 | addr = _addr; | |
9523 | if (hwaddr_aton(token + 5, addr)) { | |
9524 | wpa_printf(MSG_INFO, | |
9525 | "CTRL: Invalid MAC address: %s", | |
9526 | token); | |
9527 | return -1; | |
9528 | } | |
9529 | } else if (os_strncasecmp(token, "mask=", 5) == 0) { | |
9530 | mask = _mask; | |
9531 | if (hwaddr_aton(token + 5, mask)) { | |
9532 | wpa_printf(MSG_INFO, | |
9533 | "CTRL: Invalid MAC address mask: %s", | |
9534 | token); | |
9535 | return -1; | |
9536 | } | |
9537 | } else { | |
9538 | wpa_printf(MSG_INFO, | |
9539 | "CTRL: Invalid MAC_RAND_SCAN parameter: %s", | |
9540 | token); | |
9541 | return -1; | |
9542 | } | |
9543 | } | |
9544 | ||
9545 | if (!type) { | |
9546 | wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified"); | |
9547 | return -1; | |
9548 | } | |
9549 | ||
fb375883 IP |
9550 | if (enable > 1) { |
9551 | wpa_printf(MSG_INFO, | |
9552 | "CTRL: MAC_RAND_SCAN enable=<0/1> not specified"); | |
9553 | return -1; | |
9554 | } | |
9555 | ||
9556 | if (!enable) { | |
9557 | wpas_mac_addr_rand_scan_clear(wpa_s, type); | |
9558 | if (wpa_s->pno) { | |
9559 | if (type & MAC_ADDR_RAND_PNO) { | |
9560 | wpas_stop_pno(wpa_s); | |
9561 | wpas_start_pno(wpa_s); | |
9562 | } | |
9563 | } else if (wpa_s->sched_scanning && | |
9564 | (type & MAC_ADDR_RAND_SCHED_SCAN)) { | |
5bb7327a | 9565 | wpas_scan_restart_sched_scan(wpa_s); |
fb375883 IP |
9566 | } |
9567 | return 0; | |
9568 | } | |
9569 | ||
9570 | if ((addr && !mask) || (!addr && mask)) { | |
9571 | wpa_printf(MSG_INFO, | |
9572 | "CTRL: MAC_RAND_SCAN invalid addr/mask combination"); | |
9573 | return -1; | |
9574 | } | |
9575 | ||
9576 | if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) { | |
9577 | wpa_printf(MSG_INFO, | |
9578 | "CTRL: MAC_RAND_SCAN cannot allow multicast address"); | |
9579 | return -1; | |
9580 | } | |
9581 | ||
9582 | if (type & MAC_ADDR_RAND_SCAN) { | |
1e591df0 LD |
9583 | if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN, |
9584 | addr, mask)) | |
9585 | return -1; | |
fb375883 IP |
9586 | } |
9587 | ||
9588 | if (type & MAC_ADDR_RAND_SCHED_SCAN) { | |
1e591df0 LD |
9589 | if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN, |
9590 | addr, mask)) | |
9591 | return -1; | |
fb375883 | 9592 | |
5bb7327a JM |
9593 | if (wpa_s->sched_scanning && !wpa_s->pno) |
9594 | wpas_scan_restart_sched_scan(wpa_s); | |
fb375883 IP |
9595 | } |
9596 | ||
9597 | if (type & MAC_ADDR_RAND_PNO) { | |
1e591df0 LD |
9598 | if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO, |
9599 | addr, mask)) | |
9600 | return -1; | |
9601 | ||
fb375883 IP |
9602 | if (wpa_s->pno) { |
9603 | wpas_stop_pno(wpa_s); | |
9604 | wpas_start_pno(wpa_s); | |
9605 | } | |
9606 | } | |
9607 | ||
9608 | return 0; | |
9609 | } | |
9610 | ||
9611 | ||
b8daac18 MH |
9612 | static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s, |
9613 | char *buf, size_t buflen) | |
9614 | { | |
9615 | size_t reply_len; | |
9616 | ||
9617 | reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen); | |
9618 | #ifdef CONFIG_AP | |
9619 | reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len], | |
9620 | buflen - reply_len); | |
9621 | #endif /* CONFIG_AP */ | |
9622 | return reply_len; | |
9623 | } | |
9624 | ||
9625 | ||
4c522c77 MH |
9626 | static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s) |
9627 | { | |
9628 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); | |
9629 | #ifdef CONFIG_AP | |
9630 | wpas_ap_pmksa_cache_flush(wpa_s); | |
9631 | #endif /* CONFIG_AP */ | |
9632 | } | |
9633 | ||
9634 | ||
3459381d JM |
9635 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
9636 | ||
9637 | static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s, | |
9638 | const char *cmd, char *buf, size_t buflen) | |
9639 | { | |
9640 | struct rsn_pmksa_cache_entry *entry; | |
9641 | struct wpa_ssid *ssid; | |
9642 | char *pos, *pos2, *end; | |
9643 | int ret; | |
9644 | struct os_reltime now; | |
9645 | ||
9646 | ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd)); | |
9647 | if (!ssid) | |
9648 | return -1; | |
9649 | ||
9650 | pos = buf; | |
9651 | end = buf + buflen; | |
9652 | ||
9653 | os_get_reltime(&now); | |
9654 | ||
9655 | /* | |
9656 | * Entry format: | |
9657 | * <BSSID> <PMKID> <PMK> <reauth_time in seconds> | |
9658 | * <expiration in seconds> <akmp> <opportunistic> | |
b7286c1b | 9659 | * [FILS Cache Identifier] |
3459381d JM |
9660 | */ |
9661 | ||
9662 | for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry; | |
9663 | entry = entry->next) { | |
9664 | if (entry->network_ctx != ssid) | |
9665 | continue; | |
9666 | ||
9667 | pos2 = pos; | |
9668 | ret = os_snprintf(pos2, end - pos2, MACSTR " ", | |
9669 | MAC2STR(entry->aa)); | |
9670 | if (os_snprintf_error(end - pos2, ret)) | |
9671 | break; | |
9672 | pos2 += ret; | |
9673 | ||
9674 | pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid, | |
9675 | PMKID_LEN); | |
9676 | ||
9677 | ret = os_snprintf(pos2, end - pos2, " "); | |
9678 | if (os_snprintf_error(end - pos2, ret)) | |
9679 | break; | |
9680 | pos2 += ret; | |
9681 | ||
9682 | pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk, | |
9683 | entry->pmk_len); | |
9684 | ||
9685 | ret = os_snprintf(pos2, end - pos2, " %d %d %d %d", | |
9686 | (int) (entry->reauth_time - now.sec), | |
9687 | (int) (entry->expiration - now.sec), | |
9688 | entry->akmp, | |
9689 | entry->opportunistic); | |
9690 | if (os_snprintf_error(end - pos2, ret)) | |
9691 | break; | |
9692 | pos2 += ret; | |
9693 | ||
b7286c1b JM |
9694 | if (entry->fils_cache_id_set) { |
9695 | ret = os_snprintf(pos2, end - pos2, " %02x%02x", | |
9696 | entry->fils_cache_id[0], | |
9697 | entry->fils_cache_id[1]); | |
9698 | if (os_snprintf_error(end - pos2, ret)) | |
9699 | break; | |
9700 | pos2 += ret; | |
9701 | } | |
9702 | ||
3459381d JM |
9703 | ret = os_snprintf(pos2, end - pos2, "\n"); |
9704 | if (os_snprintf_error(end - pos2, ret)) | |
9705 | break; | |
9706 | pos2 += ret; | |
9707 | ||
9708 | pos = pos2; | |
9709 | } | |
9710 | ||
9711 | return pos - buf; | |
9712 | } | |
9713 | ||
9714 | ||
9715 | static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s, | |
9716 | char *cmd) | |
9717 | { | |
9718 | struct rsn_pmksa_cache_entry *entry; | |
9719 | struct wpa_ssid *ssid; | |
9720 | char *pos, *pos2; | |
9721 | int ret = -1; | |
9722 | struct os_reltime now; | |
b7286c1b | 9723 | int reauth_time = 0, expiration = 0, i; |
3459381d JM |
9724 | |
9725 | /* | |
9726 | * Entry format: | |
9727 | * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds> | |
9728 | * <expiration in seconds> <akmp> <opportunistic> | |
b7286c1b | 9729 | * [FILS Cache Identifier] |
3459381d JM |
9730 | */ |
9731 | ||
9732 | ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd)); | |
9733 | if (!ssid) | |
9734 | return -1; | |
9735 | ||
9736 | pos = os_strchr(cmd, ' '); | |
9737 | if (!pos) | |
9738 | return -1; | |
9739 | pos++; | |
9740 | ||
9741 | entry = os_zalloc(sizeof(*entry)); | |
9742 | if (!entry) | |
9743 | return -1; | |
9744 | ||
9745 | if (hwaddr_aton(pos, entry->aa)) | |
9746 | goto fail; | |
9747 | ||
9748 | pos = os_strchr(pos, ' '); | |
9749 | if (!pos) | |
9750 | goto fail; | |
9751 | pos++; | |
9752 | ||
9753 | if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0) | |
9754 | goto fail; | |
9755 | ||
9756 | pos = os_strchr(pos, ' '); | |
9757 | if (!pos) | |
9758 | goto fail; | |
9759 | pos++; | |
9760 | ||
9761 | pos2 = os_strchr(pos, ' '); | |
9762 | if (!pos2) | |
9763 | goto fail; | |
9764 | entry->pmk_len = (pos2 - pos) / 2; | |
9765 | if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX || | |
9766 | hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0) | |
9767 | goto fail; | |
9768 | ||
9769 | pos = os_strchr(pos, ' '); | |
9770 | if (!pos) | |
9771 | goto fail; | |
9772 | pos++; | |
9773 | ||
9774 | if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration, | |
9775 | &entry->akmp, &entry->opportunistic) != 4) | |
9776 | goto fail; | |
b7286c1b JM |
9777 | for (i = 0; i < 4; i++) { |
9778 | pos = os_strchr(pos, ' '); | |
9779 | if (!pos) { | |
9780 | if (i < 3) | |
9781 | goto fail; | |
9782 | break; | |
9783 | } | |
9784 | pos++; | |
9785 | } | |
9786 | if (pos) { | |
9787 | if (hexstr2bin(pos, entry->fils_cache_id, | |
9788 | FILS_CACHE_ID_LEN) < 0) | |
9789 | goto fail; | |
9790 | entry->fils_cache_id_set = 1; | |
9791 | } | |
3459381d JM |
9792 | os_get_reltime(&now); |
9793 | entry->expiration = now.sec + expiration; | |
9794 | entry->reauth_time = now.sec + reauth_time; | |
9795 | ||
9796 | entry->network_ctx = ssid; | |
9797 | ||
9798 | wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry); | |
9799 | entry = NULL; | |
9800 | ret = 0; | |
9801 | fail: | |
9802 | os_free(entry); | |
9803 | return ret; | |
9804 | } | |
9805 | ||
4d77d80e MH |
9806 | |
9807 | #ifdef CONFIG_MESH | |
9808 | ||
9809 | static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s, | |
9810 | const char *cmd, char *buf, | |
9811 | size_t buflen) | |
9812 | { | |
9813 | u8 spa[ETH_ALEN]; | |
9814 | ||
9815 | if (!wpa_s->ifmsh) | |
9816 | return -1; | |
9817 | ||
9818 | if (os_strcasecmp(cmd, "any") == 0) | |
9819 | return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen); | |
9820 | ||
9821 | if (hwaddr_aton(cmd, spa)) | |
9822 | return -1; | |
9823 | ||
9824 | return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen); | |
9825 | } | |
9826 | ||
9827 | ||
9828 | static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s, | |
9829 | char *cmd) | |
9830 | { | |
9831 | /* | |
9832 | * We do not check mesh interface existance because PMKSA should be | |
9833 | * stored before wpa_s->ifmsh creation to suppress commit message | |
9834 | * creation. | |
9835 | */ | |
9836 | return wpas_ap_pmksa_cache_add_external(wpa_s, cmd); | |
9837 | } | |
9838 | ||
9839 | #endif /* CONFIG_MESH */ | |
3459381d JM |
9840 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
9841 | ||
9842 | ||
5732b770 JM |
9843 | #ifdef CONFIG_FILS |
9844 | static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s, | |
9845 | const char *cmd) | |
9846 | { | |
9847 | struct fils_hlp_req *req; | |
9848 | const char *pos; | |
9849 | ||
9850 | /* format: <dst> <packet starting from ethertype> */ | |
9851 | ||
9852 | req = os_zalloc(sizeof(*req)); | |
9853 | if (!req) | |
9854 | return -1; | |
9855 | ||
9856 | if (hwaddr_aton(cmd, req->dst)) | |
9857 | goto fail; | |
9858 | ||
9859 | pos = os_strchr(cmd, ' '); | |
9860 | if (!pos) | |
9861 | goto fail; | |
9862 | pos++; | |
9863 | req->pkt = wpabuf_parse_bin(pos); | |
9864 | if (!req->pkt) | |
9865 | goto fail; | |
9866 | ||
9867 | dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list); | |
9868 | return 0; | |
9869 | fail: | |
9870 | wpabuf_free(req->pkt); | |
9871 | os_free(req); | |
9872 | return -1; | |
9873 | } | |
9874 | #endif /* CONFIG_FILS */ | |
9875 | ||
9876 | ||
8db9a79d JM |
9877 | static int wpas_ctrl_cmd_debug_level(const char *cmd) |
9878 | { | |
9879 | if (os_strcmp(cmd, "PING") == 0 || | |
9880 | os_strncmp(cmd, "BSS ", 4) == 0 || | |
9881 | os_strncmp(cmd, "GET_NETWORK ", 12) == 0 || | |
9882 | os_strncmp(cmd, "STATUS", 6) == 0 || | |
9883 | os_strncmp(cmd, "STA ", 4) == 0 || | |
9884 | os_strncmp(cmd, "STA-", 4) == 0) | |
9885 | return MSG_EXCESSIVE; | |
9886 | return MSG_DEBUG; | |
9887 | } | |
9888 | ||
9889 | ||
6fc6879b JM |
9890 | char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, |
9891 | char *buf, size_t *resp_len) | |
9892 | { | |
9893 | char *reply; | |
b563b388 | 9894 | const int reply_size = 4096; |
6fc6879b JM |
9895 | int reply_len; |
9896 | ||
9897 | if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 || | |
c10e0ccc JM |
9898 | os_strncmp(buf, "SET_NETWORK ", 12) == 0 || |
9899 | os_strncmp(buf, "PMKSA_ADD ", 10) == 0 || | |
9900 | os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) { | |
d31b5ac7 JM |
9901 | if (wpa_debug_show_keys) |
9902 | wpa_dbg(wpa_s, MSG_DEBUG, | |
9903 | "Control interface command '%s'", buf); | |
9904 | else | |
9905 | wpa_dbg(wpa_s, MSG_DEBUG, | |
9906 | "Control interface command '%s [REMOVED]'", | |
9907 | os_strncmp(buf, WPA_CTRL_RSP, | |
9908 | os_strlen(WPA_CTRL_RSP)) == 0 ? | |
c10e0ccc JM |
9909 | WPA_CTRL_RSP : |
9910 | (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ? | |
9911 | "SET_NETWORK" : "key-add")); | |
d31b5ac7 | 9912 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 || |
679f2e7c | 9913 | os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) { |
6fc6879b JM |
9914 | wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", |
9915 | (const u8 *) buf, os_strlen(buf)); | |
9916 | } else { | |
8db9a79d | 9917 | int level = wpas_ctrl_cmd_debug_level(buf); |
b470b2bf | 9918 | wpa_dbg(wpa_s, level, "Control interface command '%s'", buf); |
6fc6879b JM |
9919 | } |
9920 | ||
9921 | reply = os_malloc(reply_size); | |
9922 | if (reply == NULL) { | |
9923 | *resp_len = 1; | |
9924 | return NULL; | |
9925 | } | |
9926 | ||
9927 | os_memcpy(reply, "OK\n", 3); | |
9928 | reply_len = 3; | |
9929 | ||
9930 | if (os_strcmp(buf, "PING") == 0) { | |
9931 | os_memcpy(reply, "PONG\n", 5); | |
9932 | reply_len = 5; | |
0eed2a8d JD |
9933 | } else if (os_strcmp(buf, "IFNAME") == 0) { |
9934 | reply_len = os_strlen(wpa_s->ifname); | |
9935 | os_memcpy(reply, wpa_s->ifname, reply_len); | |
ac6912b5 BG |
9936 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
9937 | if (wpa_debug_reopen_file() < 0) | |
9938 | reply_len = -1; | |
77895cd9 JM |
9939 | } else if (os_strncmp(buf, "NOTE ", 5) == 0) { |
9940 | wpa_printf(MSG_INFO, "NOTE: %s", buf + 5); | |
6fc6879b JM |
9941 | } else if (os_strcmp(buf, "MIB") == 0) { |
9942 | reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); | |
9943 | if (reply_len >= 0) { | |
5ac73acf JM |
9944 | reply_len += eapol_sm_get_mib(wpa_s->eapol, |
9945 | reply + reply_len, | |
9946 | reply_size - reply_len); | |
948ba8c2 JM |
9947 | #ifdef CONFIG_MACSEC |
9948 | reply_len += ieee802_1x_kay_get_mib( | |
9949 | wpa_s->kay, reply + reply_len, | |
9950 | reply_size - reply_len); | |
9951 | #endif /* CONFIG_MACSEC */ | |
6fc6879b JM |
9952 | } |
9953 | } else if (os_strncmp(buf, "STATUS", 6) == 0) { | |
9954 | reply_len = wpa_supplicant_ctrl_iface_status( | |
9955 | wpa_s, buf + 6, reply, reply_size); | |
9956 | } else if (os_strcmp(buf, "PMKSA") == 0) { | |
b8daac18 | 9957 | reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size); |
79e2b1cc | 9958 | } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) { |
4c522c77 | 9959 | wpas_ctrl_iface_pmksa_flush(wpa_s); |
3459381d JM |
9960 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
9961 | } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) { | |
9962 | reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10, | |
9963 | reply, reply_size); | |
9964 | } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) { | |
9965 | if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0) | |
9966 | reply_len = -1; | |
4d77d80e MH |
9967 | #ifdef CONFIG_MESH |
9968 | } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) { | |
9969 | reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15, | |
9970 | reply, reply_size); | |
9971 | } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) { | |
9972 | if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0) | |
9973 | reply_len = -1; | |
9974 | #endif /* CONFIG_MESH */ | |
3459381d | 9975 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
6fc6879b JM |
9976 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
9977 | if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) | |
9978 | reply_len = -1; | |
10263dc2 OO |
9979 | } else if (os_strncmp(buf, "DUMP", 4) == 0) { |
9980 | reply_len = wpa_config_dump_values(wpa_s->conf, | |
9981 | reply, reply_size); | |
acec8d32 JM |
9982 | } else if (os_strncmp(buf, "GET ", 4) == 0) { |
9983 | reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4, | |
9984 | reply, reply_size); | |
6fc6879b JM |
9985 | } else if (os_strcmp(buf, "LOGON") == 0) { |
9986 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); | |
9987 | } else if (os_strcmp(buf, "LOGOFF") == 0) { | |
9988 | eapol_sm_notify_logoff(wpa_s->eapol, TRUE); | |
9989 | } else if (os_strcmp(buf, "REASSOCIATE") == 0) { | |
8401a6b0 JM |
9990 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
9991 | reply_len = -1; | |
9796a86c JM |
9992 | else |
9993 | wpas_request_connection(wpa_s); | |
0f44ec8e PQ |
9994 | } else if (os_strcmp(buf, "REATTACH") == 0) { |
9995 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED || | |
9996 | !wpa_s->current_ssid) | |
9997 | reply_len = -1; | |
9998 | else { | |
9999 | wpa_s->reattach = 1; | |
10000 | wpas_request_connection(wpa_s); | |
10001 | } | |
6fc6879b | 10002 | } else if (os_strcmp(buf, "RECONNECT") == 0) { |
8401a6b0 JM |
10003 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
10004 | reply_len = -1; | |
9796a86c JM |
10005 | else if (wpa_s->disconnected) |
10006 | wpas_request_connection(wpa_s); | |
ec717917 | 10007 | #ifdef IEEE8021X_EAPOL |
6fc6879b JM |
10008 | } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { |
10009 | if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) | |
10010 | reply_len = -1; | |
ec717917 | 10011 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
10012 | #ifdef CONFIG_IEEE80211R |
10013 | } else if (os_strncmp(buf, "FT_DS ", 6) == 0) { | |
10014 | if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6)) | |
10015 | reply_len = -1; | |
10016 | #endif /* CONFIG_IEEE80211R */ | |
fcc60db4 JM |
10017 | #ifdef CONFIG_WPS |
10018 | } else if (os_strcmp(buf, "WPS_PBC") == 0) { | |
3152ff42 CWY |
10019 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL); |
10020 | if (res == -2) { | |
10021 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
10022 | reply_len = 17; | |
10023 | } else if (res) | |
fcc60db4 JM |
10024 | reply_len = -1; |
10025 | } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) { | |
3152ff42 CWY |
10026 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8); |
10027 | if (res == -2) { | |
10028 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
10029 | reply_len = 17; | |
10030 | } else if (res) | |
fcc60db4 JM |
10031 | reply_len = -1; |
10032 | } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) { | |
10033 | reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8, | |
10034 | reply, | |
10035 | reply_size); | |
3981cb3c JM |
10036 | } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) { |
10037 | reply_len = wpa_supplicant_ctrl_iface_wps_check_pin( | |
10038 | wpa_s, buf + 14, reply, reply_size); | |
2f9929ff AC |
10039 | } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { |
10040 | if (wpas_wps_cancel(wpa_s)) | |
10041 | reply_len = -1; | |
71892384 | 10042 | #ifdef CONFIG_WPS_NFC |
3f2c8ba6 JM |
10043 | } else if (os_strcmp(buf, "WPS_NFC") == 0) { |
10044 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL)) | |
10045 | reply_len = -1; | |
10046 | } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) { | |
10047 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8)) | |
10048 | reply_len = -1; | |
bbf41865 JM |
10049 | } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) { |
10050 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token( | |
10051 | wpa_s, buf + 21, reply, reply_size); | |
3f2c8ba6 JM |
10052 | } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) { |
10053 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token( | |
10054 | wpa_s, buf + 14, reply, reply_size); | |
d7645d23 JM |
10055 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) { |
10056 | if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s, | |
10057 | buf + 17)) | |
10058 | reply_len = -1; | |
e65552dd JM |
10059 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) { |
10060 | reply_len = wpas_ctrl_nfc_get_handover_req( | |
10061 | wpa_s, buf + 21, reply, reply_size); | |
10062 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) { | |
10063 | reply_len = wpas_ctrl_nfc_get_handover_sel( | |
10064 | wpa_s, buf + 21, reply, reply_size); | |
e4758827 JM |
10065 | } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) { |
10066 | if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20)) | |
10067 | reply_len = -1; | |
71892384 | 10068 | #endif /* CONFIG_WPS_NFC */ |
fcc60db4 JM |
10069 | } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) { |
10070 | if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8)) | |
10071 | reply_len = -1; | |
70d84f11 JM |
10072 | #ifdef CONFIG_AP |
10073 | } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) { | |
10074 | reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin( | |
10075 | wpa_s, buf + 11, reply, reply_size); | |
10076 | #endif /* CONFIG_AP */ | |
72df2f5f | 10077 | #ifdef CONFIG_WPS_ER |
e9bcfebf | 10078 | } else if (os_strcmp(buf, "WPS_ER_START") == 0) { |
08486685 JM |
10079 | if (wpas_wps_er_start(wpa_s, NULL)) |
10080 | reply_len = -1; | |
10081 | } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) { | |
10082 | if (wpas_wps_er_start(wpa_s, buf + 13)) | |
e9bcfebf JM |
10083 | reply_len = -1; |
10084 | } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) { | |
f77cedc1 | 10085 | wpas_wps_er_stop(wpa_s); |
72df2f5f JM |
10086 | } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) { |
10087 | if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11)) | |
10088 | reply_len = -1; | |
564cd7fa | 10089 | } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) { |
ed159ad4 JM |
10090 | int ret = wpas_wps_er_pbc(wpa_s, buf + 11); |
10091 | if (ret == -2) { | |
10092 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
10093 | reply_len = 17; | |
10094 | } else if (ret == -3) { | |
10095 | os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18); | |
10096 | reply_len = 18; | |
10097 | } else if (ret == -4) { | |
10098 | os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20); | |
10099 | reply_len = 20; | |
10100 | } else if (ret) | |
564cd7fa | 10101 | reply_len = -1; |
e64dcfd5 JM |
10102 | } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) { |
10103 | if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13)) | |
10104 | reply_len = -1; | |
ef10f473 JM |
10105 | } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) { |
10106 | if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s, | |
10107 | buf + 18)) | |
10108 | reply_len = -1; | |
7d6640a6 JM |
10109 | } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) { |
10110 | if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14)) | |
10111 | reply_len = -1; | |
1cea09a9 JM |
10112 | #ifdef CONFIG_WPS_NFC |
10113 | } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) { | |
10114 | reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | |
10115 | wpa_s, buf + 24, reply, reply_size); | |
10116 | #endif /* CONFIG_WPS_NFC */ | |
72df2f5f | 10117 | #endif /* CONFIG_WPS_ER */ |
fcc60db4 | 10118 | #endif /* CONFIG_WPS */ |
11ef8d35 JM |
10119 | #ifdef CONFIG_IBSS_RSN |
10120 | } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) { | |
10121 | if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) | |
10122 | reply_len = -1; | |
10123 | #endif /* CONFIG_IBSS_RSN */ | |
603a3f34 | 10124 | #ifdef CONFIG_MESH |
5b78493f MH |
10125 | } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) { |
10126 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( | |
10127 | wpa_s, buf + 19, reply, reply_size); | |
10128 | } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) { | |
10129 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( | |
10130 | wpa_s, "", reply, reply_size); | |
603a3f34 JL |
10131 | } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) { |
10132 | if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15)) | |
10133 | reply_len = -1; | |
10134 | } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) { | |
10135 | if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s, | |
10136 | buf + 18)) | |
10137 | reply_len = -1; | |
e174ef34 MH |
10138 | } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) { |
10139 | if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17)) | |
10140 | reply_len = -1; | |
2604edbf MH |
10141 | } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) { |
10142 | if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14)) | |
10143 | reply_len = -1; | |
603a3f34 | 10144 | #endif /* CONFIG_MESH */ |
b563b388 JM |
10145 | #ifdef CONFIG_P2P |
10146 | } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { | |
51775096 | 10147 | if (p2p_ctrl_find(wpa_s, buf + 8)) |
b563b388 JM |
10148 | reply_len = -1; |
10149 | } else if (os_strcmp(buf, "P2P_FIND") == 0) { | |
10150 | if (p2p_ctrl_find(wpa_s, "")) | |
10151 | reply_len = -1; | |
10152 | } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) { | |
10153 | wpas_p2p_stop_find(wpa_s); | |
f309c18e KV |
10154 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) { |
10155 | if (p2p_ctrl_asp_provision(wpa_s, buf + 18)) | |
10156 | reply_len = -1; | |
10157 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) { | |
10158 | if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23)) | |
10159 | reply_len = -1; | |
b563b388 JM |
10160 | } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) { |
10161 | reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply, | |
10162 | reply_size); | |
10163 | } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) { | |
10164 | if (p2p_ctrl_listen(wpa_s, buf + 11)) | |
10165 | reply_len = -1; | |
10166 | } else if (os_strcmp(buf, "P2P_LISTEN") == 0) { | |
10167 | if (p2p_ctrl_listen(wpa_s, "")) | |
10168 | reply_len = -1; | |
10169 | } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) { | |
10170 | if (wpas_p2p_group_remove(wpa_s, buf + 17)) | |
10171 | reply_len = -1; | |
10172 | } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) { | |
38dcc86c | 10173 | if (p2p_ctrl_group_add(wpa_s, "")) |
b563b388 JM |
10174 | reply_len = -1; |
10175 | } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) { | |
10176 | if (p2p_ctrl_group_add(wpa_s, buf + 14)) | |
10177 | reply_len = -1; | |
57b38882 PK |
10178 | } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) { |
10179 | reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply, | |
10180 | reply_size); | |
b563b388 JM |
10181 | } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) { |
10182 | if (p2p_ctrl_prov_disc(wpa_s, buf + 14)) | |
10183 | reply_len = -1; | |
10184 | } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) { | |
10185 | reply_len = p2p_get_passphrase(wpa_s, reply, reply_size); | |
10186 | } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) { | |
10187 | reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply, | |
10188 | reply_size); | |
10189 | } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) { | |
10190 | if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0) | |
10191 | reply_len = -1; | |
10192 | } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) { | |
10193 | if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0) | |
10194 | reply_len = -1; | |
10195 | } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) { | |
10196 | wpas_p2p_sd_service_update(wpa_s); | |
10197 | } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) { | |
10198 | if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0) | |
10199 | reply_len = -1; | |
10200 | } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) { | |
10201 | wpas_p2p_service_flush(wpa_s); | |
10202 | } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) { | |
10203 | if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0) | |
10204 | reply_len = -1; | |
10205 | } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) { | |
10206 | if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0) | |
10207 | reply_len = -1; | |
ae9d45f3 KV |
10208 | } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) { |
10209 | if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0) | |
10210 | reply_len = -1; | |
b563b388 JM |
10211 | } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) { |
10212 | if (p2p_ctrl_reject(wpa_s, buf + 11) < 0) | |
10213 | reply_len = -1; | |
10214 | } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) { | |
10215 | if (p2p_ctrl_invite(wpa_s, buf + 11) < 0) | |
10216 | reply_len = -1; | |
10217 | } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) { | |
10218 | reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply, | |
10219 | reply_size); | |
10220 | } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) { | |
10221 | if (p2p_ctrl_set(wpa_s, buf + 8) < 0) | |
10222 | reply_len = -1; | |
10223 | } else if (os_strcmp(buf, "P2P_FLUSH") == 0) { | |
acb54643 | 10224 | p2p_ctrl_flush(wpa_s); |
9d562b79 SS |
10225 | } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { |
10226 | if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) | |
10227 | reply_len = -1; | |
59eba7a2 JM |
10228 | } else if (os_strcmp(buf, "P2P_CANCEL") == 0) { |
10229 | if (wpas_p2p_cancel(wpa_s)) | |
10230 | reply_len = -1; | |
b563b388 JM |
10231 | } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) { |
10232 | if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0) | |
10233 | reply_len = -1; | |
10234 | } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) { | |
10235 | if (p2p_ctrl_presence_req(wpa_s, "") < 0) | |
10236 | reply_len = -1; | |
10237 | } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) { | |
10238 | if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0) | |
10239 | reply_len = -1; | |
10240 | } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) { | |
10241 | if (p2p_ctrl_ext_listen(wpa_s, "") < 0) | |
10242 | reply_len = -1; | |
f2c56602 JM |
10243 | } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) { |
10244 | if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0) | |
10245 | reply_len = -1; | |
a6f5b193 PX |
10246 | } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) { |
10247 | if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13)) | |
10248 | reply_len = -1; | |
10249 | } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) { | |
10250 | if (wpas_p2p_lo_stop(wpa_s)) | |
10251 | reply_len = -1; | |
b563b388 | 10252 | #endif /* CONFIG_P2P */ |
9675ce35 JM |
10253 | #ifdef CONFIG_WIFI_DISPLAY |
10254 | } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) { | |
10255 | if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0) | |
10256 | reply_len = -1; | |
10257 | } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) { | |
10258 | reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16, | |
10259 | reply, reply_size); | |
10260 | #endif /* CONFIG_WIFI_DISPLAY */ | |
afc064fe JM |
10261 | #ifdef CONFIG_INTERWORKING |
10262 | } else if (os_strcmp(buf, "FETCH_ANQP") == 0) { | |
10263 | if (interworking_fetch_anqp(wpa_s) < 0) | |
10264 | reply_len = -1; | |
10265 | } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) { | |
10266 | interworking_stop_fetch_anqp(wpa_s); | |
356d1488 JM |
10267 | } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) { |
10268 | if (ctrl_interworking_select(wpa_s, NULL) < 0) | |
10269 | reply_len = -1; | |
10270 | } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) { | |
10271 | if (ctrl_interworking_select(wpa_s, buf + 20) < 0) | |
b02fe7ff JM |
10272 | reply_len = -1; |
10273 | } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) { | |
f91a512f | 10274 | if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0) |
b02fe7ff | 10275 | reply_len = -1; |
f91a512f JM |
10276 | } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) { |
10277 | int id; | |
10278 | ||
10279 | id = ctrl_interworking_connect(wpa_s, buf + 25, 1); | |
10280 | if (id < 0) | |
10281 | reply_len = -1; | |
10282 | else { | |
10283 | reply_len = os_snprintf(reply, reply_size, "%d\n", id); | |
10284 | if (os_snprintf_error(reply_size, reply_len)) | |
10285 | reply_len = -1; | |
10286 | } | |
afc064fe JM |
10287 | } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) { |
10288 | if (get_anqp(wpa_s, buf + 9) < 0) | |
10289 | reply_len = -1; | |
b1f12296 JM |
10290 | } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) { |
10291 | if (gas_request(wpa_s, buf + 12) < 0) | |
10292 | reply_len = -1; | |
10293 | } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) { | |
10294 | reply_len = gas_response_get(wpa_s, buf + 17, reply, | |
10295 | reply_size); | |
afc064fe | 10296 | #endif /* CONFIG_INTERWORKING */ |
a8918e86 JK |
10297 | #ifdef CONFIG_HS20 |
10298 | } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) { | |
10299 | if (get_hs20_anqp(wpa_s, buf + 14) < 0) | |
10300 | reply_len = -1; | |
10301 | } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) { | |
10302 | if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0) | |
10303 | reply_len = -1; | |
184e110c | 10304 | } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) { |
8dd5c1b4 JN |
10305 | if (hs20_icon_request(wpa_s, buf + 18, 0) < 0) |
10306 | reply_len = -1; | |
10307 | } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) { | |
10308 | if (hs20_icon_request(wpa_s, buf + 14, 1) < 0) | |
10309 | reply_len = -1; | |
10310 | } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) { | |
10311 | reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size); | |
10312 | } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) { | |
10313 | if (del_hs20_icon(wpa_s, buf + 14) < 0) | |
184e110c | 10314 | reply_len = -1; |
b572df86 | 10315 | } else if (os_strcmp(buf, "FETCH_OSU") == 0) { |
dd20eabd JM |
10316 | if (hs20_fetch_osu(wpa_s, 0) < 0) |
10317 | reply_len = -1; | |
10318 | } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) { | |
10319 | if (hs20_fetch_osu(wpa_s, 1) < 0) | |
b572df86 JM |
10320 | reply_len = -1; |
10321 | } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) { | |
10322 | hs20_cancel_fetch_osu(wpa_s); | |
a8918e86 | 10323 | #endif /* CONFIG_HS20 */ |
6fc6879b JM |
10324 | } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) |
10325 | { | |
10326 | if (wpa_supplicant_ctrl_iface_ctrl_rsp( | |
10327 | wpa_s, buf + os_strlen(WPA_CTRL_RSP))) | |
10328 | reply_len = -1; | |
bceb8431 JM |
10329 | else { |
10330 | /* | |
10331 | * Notify response from timeout to allow the control | |
10332 | * interface response to be sent first. | |
10333 | */ | |
10334 | eloop_register_timeout(0, 0, wpas_ctrl_eapol_response, | |
10335 | wpa_s, NULL); | |
10336 | } | |
6fc6879b JM |
10337 | } else if (os_strcmp(buf, "RECONFIGURE") == 0) { |
10338 | if (wpa_supplicant_reload_configuration(wpa_s)) | |
10339 | reply_len = -1; | |
10340 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | |
1a1bf008 | 10341 | wpa_supplicant_terminate_proc(wpa_s->global); |
6fc6879b JM |
10342 | } else if (os_strncmp(buf, "BSSID ", 6) == 0) { |
10343 | if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) | |
10344 | reply_len = -1; | |
9aa10e2b DS |
10345 | } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) { |
10346 | reply_len = wpa_supplicant_ctrl_iface_blacklist( | |
10347 | wpa_s, buf + 9, reply, reply_size); | |
0597a5b5 DS |
10348 | } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) { |
10349 | reply_len = wpa_supplicant_ctrl_iface_log_level( | |
10350 | wpa_s, buf + 9, reply, reply_size); | |
90903a77 VD |
10351 | } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) { |
10352 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | |
10353 | wpa_s, buf + 14, reply, reply_size); | |
6fc6879b JM |
10354 | } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { |
10355 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | |
90903a77 | 10356 | wpa_s, NULL, reply, reply_size); |
6fc6879b | 10357 | } else if (os_strcmp(buf, "DISCONNECT") == 0) { |
5f040be4 | 10358 | wpas_request_disconnection(wpa_s); |
fee52342 JM |
10359 | } else if (os_strcmp(buf, "SCAN") == 0) { |
10360 | wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len); | |
10361 | } else if (os_strncmp(buf, "SCAN ", 5) == 0) { | |
10362 | wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len); | |
6fc6879b JM |
10363 | } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { |
10364 | reply_len = wpa_supplicant_ctrl_iface_scan_results( | |
10365 | wpa_s, reply, reply_size); | |
2ea2166d JM |
10366 | } else if (os_strcmp(buf, "ABORT_SCAN") == 0) { |
10367 | if (wpas_abort_ongoing_scan(wpa_s) < 0) | |
10368 | reply_len = -1; | |
6fc6879b JM |
10369 | } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { |
10370 | if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) | |
10371 | reply_len = -1; | |
10372 | } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { | |
10373 | if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) | |
10374 | reply_len = -1; | |
10375 | } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { | |
10376 | if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) | |
10377 | reply_len = -1; | |
10378 | } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { | |
10379 | reply_len = wpa_supplicant_ctrl_iface_add_network( | |
10380 | wpa_s, reply, reply_size); | |
10381 | } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { | |
10382 | if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) | |
10383 | reply_len = -1; | |
10384 | } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { | |
10385 | if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) | |
10386 | reply_len = -1; | |
10387 | } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { | |
10388 | reply_len = wpa_supplicant_ctrl_iface_get_network( | |
10389 | wpa_s, buf + 12, reply, reply_size); | |
1c330a2f | 10390 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
daae4995 AN |
10391 | if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12, |
10392 | wpa_s)) | |
1c330a2f | 10393 | reply_len = -1; |
d94c9ee6 JM |
10394 | } else if (os_strcmp(buf, "LIST_CREDS") == 0) { |
10395 | reply_len = wpa_supplicant_ctrl_iface_list_creds( | |
10396 | wpa_s, reply, reply_size); | |
10397 | } else if (os_strcmp(buf, "ADD_CRED") == 0) { | |
10398 | reply_len = wpa_supplicant_ctrl_iface_add_cred( | |
10399 | wpa_s, reply, reply_size); | |
10400 | } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) { | |
10401 | if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12)) | |
10402 | reply_len = -1; | |
10403 | } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) { | |
10404 | if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9)) | |
10405 | reply_len = -1; | |
c880ab87 JM |
10406 | } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) { |
10407 | reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9, | |
10408 | reply, | |
10409 | reply_size); | |
6fc6879b JM |
10410 | #ifndef CONFIG_NO_CONFIG_WRITE |
10411 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | |
10412 | if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) | |
10413 | reply_len = -1; | |
10414 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
10415 | } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { | |
10416 | reply_len = wpa_supplicant_ctrl_iface_get_capability( | |
10417 | wpa_s, buf + 15, reply, reply_size); | |
10418 | } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { | |
10419 | if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) | |
10420 | reply_len = -1; | |
67b9bd08 DS |
10421 | } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) { |
10422 | if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14)) | |
10423 | reply_len = -1; | |
4b4a8ae5 JM |
10424 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
10425 | reply_len = wpa_supplicant_global_iface_list( | |
10426 | wpa_s->global, reply, reply_size); | |
56e2fc2c | 10427 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { |
6fc6879b | 10428 | reply_len = wpa_supplicant_global_iface_interfaces( |
56e2fc2c | 10429 | wpa_s->global, buf + 10, reply, reply_size); |
6fc6879b JM |
10430 | } else if (os_strncmp(buf, "BSS ", 4) == 0) { |
10431 | reply_len = wpa_supplicant_ctrl_iface_bss( | |
10432 | wpa_s, buf + 4, reply, reply_size); | |
e653b622 JM |
10433 | #ifdef CONFIG_AP |
10434 | } else if (os_strcmp(buf, "STA-FIRST") == 0) { | |
10435 | reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size); | |
10436 | } else if (os_strncmp(buf, "STA ", 4) == 0) { | |
10437 | reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply, | |
10438 | reply_size); | |
10439 | } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { | |
10440 | reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply, | |
10441 | reply_size); | |
e60b2951 JJ |
10442 | } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) { |
10443 | if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15)) | |
10444 | reply_len = -1; | |
10445 | } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) { | |
10446 | if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13)) | |
10447 | reply_len = -1; | |
334bf36a AO |
10448 | } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) { |
10449 | if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12)) | |
10450 | reply_len = -1; | |
99650cad JM |
10451 | } else if (os_strcmp(buf, "STOP_AP") == 0) { |
10452 | if (wpas_ap_stop_ap(wpa_s)) | |
10453 | reply_len = -1; | |
e653b622 | 10454 | #endif /* CONFIG_AP */ |
207ef3fb JM |
10455 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
10456 | wpas_notify_suspend(wpa_s->global); | |
10457 | } else if (os_strcmp(buf, "RESUME") == 0) { | |
10458 | wpas_notify_resume(wpa_s->global); | |
9ff4de6d | 10459 | #ifdef CONFIG_TESTING_OPTIONS |
32d5295f JM |
10460 | } else if (os_strcmp(buf, "DROP_SA") == 0) { |
10461 | wpa_supplicant_ctrl_iface_drop_sa(wpa_s); | |
9ff4de6d | 10462 | #endif /* CONFIG_TESTING_OPTIONS */ |
86d4f806 JM |
10463 | } else if (os_strncmp(buf, "ROAM ", 5) == 0) { |
10464 | if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) | |
10465 | reply_len = -1; | |
0d0a8ca1 | 10466 | } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { |
5407c69d | 10467 | wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0; |
78633c37 SL |
10468 | } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) { |
10469 | if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15)) | |
10470 | reply_len = -1; | |
10471 | } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) { | |
10472 | if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s, | |
10473 | buf + 17)) | |
10474 | reply_len = -1; | |
39ee845f | 10475 | } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) { |
a1144000 | 10476 | wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10); |
281ff0aa GP |
10477 | #ifdef CONFIG_TDLS |
10478 | } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) { | |
10479 | if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14)) | |
10480 | reply_len = -1; | |
10481 | } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) { | |
10482 | if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11)) | |
10483 | reply_len = -1; | |
10484 | } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) { | |
10485 | if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14)) | |
10486 | reply_len = -1; | |
6b90deae AN |
10487 | } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) { |
10488 | if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s, | |
10489 | buf + 17)) | |
10490 | reply_len = -1; | |
10491 | } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) { | |
10492 | if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s, | |
10493 | buf + 24)) | |
10494 | reply_len = -1; | |
4504621f OG |
10495 | } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) { |
10496 | reply_len = wpa_supplicant_ctrl_iface_tdls_link_status( | |
10497 | wpa_s, buf + 17, reply, reply_size); | |
281ff0aa | 10498 | #endif /* CONFIG_TDLS */ |
8506ea6f MB |
10499 | } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) { |
10500 | reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size); | |
eb2f2088 MB |
10501 | } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) { |
10502 | if (wmm_ac_ctrl_addts(wpa_s, buf + 13)) | |
10503 | reply_len = -1; | |
10504 | } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) { | |
10505 | if (wmm_ac_ctrl_delts(wpa_s, buf + 13)) | |
10506 | reply_len = -1; | |
60b24b0d DS |
10507 | } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) { |
10508 | reply_len = wpa_supplicant_signal_poll(wpa_s, reply, | |
10509 | reply_size); | |
96e8d831 DS |
10510 | } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) { |
10511 | if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14)) | |
10512 | reply_len = -1; | |
dc7785f8 YZ |
10513 | } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) { |
10514 | reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply, | |
10515 | reply_size); | |
bc5d330a TB |
10516 | #ifdef CONFIG_AUTOSCAN |
10517 | } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) { | |
10518 | if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9)) | |
10519 | reply_len = -1; | |
10520 | #endif /* CONFIG_AUTOSCAN */ | |
4d7aab78 EL |
10521 | } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) { |
10522 | reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply, | |
10523 | reply_size); | |
5e2c3490 JM |
10524 | #ifdef ANDROID |
10525 | } else if (os_strncmp(buf, "DRIVER ", 7) == 0) { | |
10526 | reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply, | |
10527 | reply_size); | |
10528 | #endif /* ANDROID */ | |
adef8948 BL |
10529 | } else if (os_strncmp(buf, "VENDOR ", 7) == 0) { |
10530 | reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply, | |
10531 | reply_size); | |
9482426e | 10532 | } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) { |
f5f37d3a | 10533 | pmksa_cache_clear_current(wpa_s->wpa); |
9482426e | 10534 | eapol_sm_request_reauth(wpa_s->eapol); |
e9199e31 JM |
10535 | #ifdef CONFIG_WNM |
10536 | } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) { | |
10537 | if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10)) | |
10538 | reply_len = -1; | |
07565ab0 MG |
10539 | } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) { |
10540 | if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14)) | |
65bcd0a9 | 10541 | reply_len = -1; |
d514b502 JM |
10542 | } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) { |
10543 | if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18)) | |
10544 | reply_len = -1; | |
e9199e31 | 10545 | #endif /* CONFIG_WNM */ |
acb54643 JM |
10546 | } else if (os_strcmp(buf, "FLUSH") == 0) { |
10547 | wpa_supplicant_ctrl_iface_flush(wpa_s); | |
1f965e62 JM |
10548 | } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) { |
10549 | reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply, | |
10550 | reply_size); | |
60b893df JM |
10551 | #ifdef CONFIG_TESTING_OPTIONS |
10552 | } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) { | |
10553 | if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0) | |
10554 | reply_len = -1; | |
10555 | } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) { | |
10556 | wpas_ctrl_iface_mgmt_tx_done(wpa_s); | |
4de70e23 JM |
10557 | } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) { |
10558 | if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0) | |
10559 | reply_len = -1; | |
ad12f2f4 JM |
10560 | } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) { |
10561 | if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0) | |
10562 | reply_len = -1; | |
9d4ff04a JM |
10563 | } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) { |
10564 | if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0) | |
10565 | reply_len = -1; | |
4a6cc862 JM |
10566 | } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) { |
10567 | if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0) | |
10568 | reply_len = -1; | |
10569 | } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) { | |
10570 | if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0) | |
10571 | reply_len = -1; | |
fc0ef7c0 JM |
10572 | } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) { |
10573 | if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0) | |
10574 | reply_len = -1; | |
a156ffda JM |
10575 | } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) { |
10576 | if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0) | |
10577 | reply_len = -1; | |
10578 | } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) { | |
10579 | reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size); | |
2da52565 JM |
10580 | } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) { |
10581 | if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0) | |
10582 | reply_len = -1; | |
10583 | } else if (os_strcmp(buf, "GET_FAIL") == 0) { | |
10584 | reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size); | |
a530fe77 JM |
10585 | } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) { |
10586 | if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0) | |
10587 | reply_len = -1; | |
651c6a84 JM |
10588 | } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) { |
10589 | if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0) | |
10590 | reply_len = -1; | |
16579769 JM |
10591 | } else if (os_strcmp(buf, "RESET_PN") == 0) { |
10592 | if (wpas_ctrl_reset_pn(wpa_s) < 0) | |
10593 | reply_len = -1; | |
751f5b29 JM |
10594 | } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) { |
10595 | if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0) | |
10596 | reply_len = -1; | |
daa40960 JM |
10597 | } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) { |
10598 | if (wpas_ctrl_resend_assoc(wpa_s) < 0) | |
10599 | reply_len = -1; | |
c85249aa | 10600 | #ifdef CONFIG_IEEE80211W |
5c7d35ba MV |
10601 | } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) { |
10602 | sme_event_unprot_disconnect( | |
10603 | wpa_s, wpa_s->bssid, NULL, | |
10604 | WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA); | |
c85249aa | 10605 | #endif /* CONFIG_IEEE80211W */ |
60b893df | 10606 | #endif /* CONFIG_TESTING_OPTIONS */ |
86bd36f0 JM |
10607 | } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) { |
10608 | if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0) | |
10609 | reply_len = -1; | |
10610 | } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) { | |
10611 | reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply, | |
10612 | reply_size); | |
10613 | } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) { | |
10614 | if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0) | |
10615 | reply_len = -1; | |
f4b8bfae | 10616 | } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) { |
6a4f0ed7 | 10617 | if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20)) |
f4b8bfae | 10618 | reply_len = -1; |
65d9a5e2 JM |
10619 | } else if (os_strcmp(buf, "ERP_FLUSH") == 0) { |
10620 | wpas_ctrl_iface_erp_flush(wpa_s); | |
fb375883 IP |
10621 | } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) { |
10622 | if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14)) | |
10623 | reply_len = -1; | |
98342208 AK |
10624 | } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) { |
10625 | reply_len = wpas_ctrl_iface_get_pref_freq_list( | |
10626 | wpa_s, buf + 19, reply, reply_size); | |
5732b770 JM |
10627 | #ifdef CONFIG_FILS |
10628 | } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) { | |
10629 | if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17)) | |
10630 | reply_len = -1; | |
10631 | } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) { | |
10632 | wpas_flush_fils_hlp_req(wpa_s); | |
10633 | #endif /* CONFIG_FILS */ | |
be27e185 JM |
10634 | #ifdef CONFIG_DPP |
10635 | } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) { | |
10636 | int res; | |
10637 | ||
10638 | res = wpas_dpp_qr_code(wpa_s, buf + 12); | |
10639 | if (res < 0) { | |
10640 | reply_len = -1; | |
10641 | } else { | |
10642 | reply_len = os_snprintf(reply, reply_size, "%d", res); | |
10643 | if (os_snprintf_error(reply_size, reply_len)) | |
10644 | reply_len = -1; | |
10645 | } | |
10646 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) { | |
10647 | int res; | |
10648 | ||
10649 | res = wpas_dpp_bootstrap_gen(wpa_s, buf + 18); | |
10650 | if (res < 0) { | |
10651 | reply_len = -1; | |
10652 | } else { | |
10653 | reply_len = os_snprintf(reply, reply_size, "%d", res); | |
10654 | if (os_snprintf_error(reply_size, reply_len)) | |
10655 | reply_len = -1; | |
10656 | } | |
10657 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) { | |
10658 | if (wpas_dpp_bootstrap_remove(wpa_s, buf + 21) < 0) | |
10659 | reply_len = -1; | |
10660 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) { | |
10661 | const char *uri; | |
10662 | ||
10663 | uri = wpas_dpp_bootstrap_get_uri(wpa_s, atoi(buf + 22)); | |
10664 | if (!uri) { | |
10665 | reply_len = -1; | |
10666 | } else { | |
10667 | reply_len = os_snprintf(reply, reply_size, "%s", uri); | |
10668 | if (os_snprintf_error(reply_size, reply_len)) | |
10669 | reply_len = -1; | |
10670 | } | |
6a7182a9 JM |
10671 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) { |
10672 | reply_len = wpas_dpp_bootstrap_info(wpa_s, atoi(buf + 19), | |
10673 | reply, reply_size); | |
30d27b04 JM |
10674 | } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) { |
10675 | if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0) | |
10676 | reply_len = -1; | |
10677 | } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) { | |
10678 | if (wpas_dpp_listen(wpa_s, buf + 11) < 0) | |
10679 | reply_len = -1; | |
10680 | } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) { | |
c1d37739 | 10681 | wpas_dpp_stop(wpa_s); |
30d27b04 | 10682 | wpas_dpp_listen_stop(wpa_s); |
461d39af JM |
10683 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) { |
10684 | int res; | |
10685 | ||
10686 | res = wpas_dpp_configurator_add(wpa_s, buf + 20); | |
10687 | if (res < 0) { | |
10688 | reply_len = -1; | |
10689 | } else { | |
10690 | reply_len = os_snprintf(reply, reply_size, "%d", res); | |
10691 | if (os_snprintf_error(reply_size, reply_len)) | |
10692 | reply_len = -1; | |
10693 | } | |
10694 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) { | |
10695 | if (wpas_dpp_configurator_remove(wpa_s, buf + 24) < 0) | |
10696 | reply_len = -1; | |
f522bb23 | 10697 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) { |
53d5de6f | 10698 | if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0) |
f522bb23 | 10699 | reply_len = -1; |
8179ae3a PK |
10700 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) { |
10701 | reply_len = wpas_dpp_configurator_get_key(wpa_s, atoi(buf + 25), | |
10702 | reply, reply_size); | |
500ed7f0 JM |
10703 | } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) { |
10704 | int res; | |
10705 | ||
10706 | res = wpas_dpp_pkex_add(wpa_s, buf + 12); | |
10707 | if (res < 0) { | |
10708 | reply_len = -1; | |
10709 | } else { | |
10710 | reply_len = os_snprintf(reply, reply_size, "%d", res); | |
10711 | if (os_snprintf_error(reply_size, reply_len)) | |
10712 | reply_len = -1; | |
10713 | } | |
10714 | } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) { | |
10715 | if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0) | |
10716 | reply_len = -1; | |
be27e185 | 10717 | #endif /* CONFIG_DPP */ |
6fc6879b JM |
10718 | } else { |
10719 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | |
10720 | reply_len = 16; | |
10721 | } | |
10722 | ||
10723 | if (reply_len < 0) { | |
10724 | os_memcpy(reply, "FAIL\n", 5); | |
10725 | reply_len = 5; | |
10726 | } | |
10727 | ||
6fc6879b JM |
10728 | *resp_len = reply_len; |
10729 | return reply; | |
10730 | } | |
10731 | ||
10732 | ||
10733 | static int wpa_supplicant_global_iface_add(struct wpa_global *global, | |
10734 | char *cmd) | |
10735 | { | |
10736 | struct wpa_interface iface; | |
efa232f9 JJ |
10737 | char *pos, *extra; |
10738 | struct wpa_supplicant *wpa_s; | |
10739 | unsigned int create_iface = 0; | |
10740 | u8 mac_addr[ETH_ALEN]; | |
0f039e34 | 10741 | enum wpa_driver_if_type type = WPA_IF_STATION; |
6fc6879b JM |
10742 | |
10743 | /* | |
10744 | * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param> | |
0f039e34 | 10745 | * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]] |
6fc6879b JM |
10746 | */ |
10747 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd); | |
10748 | ||
10749 | os_memset(&iface, 0, sizeof(iface)); | |
10750 | ||
10751 | do { | |
10752 | iface.ifname = pos = cmd; | |
10753 | pos = os_strchr(pos, '\t'); | |
10754 | if (pos) | |
10755 | *pos++ = '\0'; | |
10756 | if (iface.ifname[0] == '\0') | |
10757 | return -1; | |
10758 | if (pos == NULL) | |
10759 | break; | |
10760 | ||
10761 | iface.confname = pos; | |
10762 | pos = os_strchr(pos, '\t'); | |
10763 | if (pos) | |
10764 | *pos++ = '\0'; | |
10765 | if (iface.confname[0] == '\0') | |
10766 | iface.confname = NULL; | |
10767 | if (pos == NULL) | |
10768 | break; | |
10769 | ||
10770 | iface.driver = pos; | |
10771 | pos = os_strchr(pos, '\t'); | |
10772 | if (pos) | |
10773 | *pos++ = '\0'; | |
10774 | if (iface.driver[0] == '\0') | |
10775 | iface.driver = NULL; | |
10776 | if (pos == NULL) | |
10777 | break; | |
10778 | ||
10779 | iface.ctrl_interface = pos; | |
10780 | pos = os_strchr(pos, '\t'); | |
10781 | if (pos) | |
10782 | *pos++ = '\0'; | |
10783 | if (iface.ctrl_interface[0] == '\0') | |
10784 | iface.ctrl_interface = NULL; | |
10785 | if (pos == NULL) | |
10786 | break; | |
10787 | ||
10788 | iface.driver_param = pos; | |
10789 | pos = os_strchr(pos, '\t'); | |
10790 | if (pos) | |
10791 | *pos++ = '\0'; | |
10792 | if (iface.driver_param[0] == '\0') | |
10793 | iface.driver_param = NULL; | |
10794 | if (pos == NULL) | |
10795 | break; | |
10796 | ||
10797 | iface.bridge_ifname = pos; | |
10798 | pos = os_strchr(pos, '\t'); | |
10799 | if (pos) | |
10800 | *pos++ = '\0'; | |
10801 | if (iface.bridge_ifname[0] == '\0') | |
10802 | iface.bridge_ifname = NULL; | |
10803 | if (pos == NULL) | |
10804 | break; | |
efa232f9 JJ |
10805 | |
10806 | extra = pos; | |
10807 | pos = os_strchr(pos, '\t'); | |
10808 | if (pos) | |
10809 | *pos++ = '\0'; | |
da3db681 BG |
10810 | if (!extra[0]) |
10811 | break; | |
10812 | ||
0f039e34 | 10813 | if (os_strcmp(extra, "create") == 0) { |
efa232f9 | 10814 | create_iface = 1; |
0f039e34 AS |
10815 | if (!pos) |
10816 | break; | |
10817 | ||
10818 | if (os_strcmp(pos, "sta") == 0) { | |
10819 | type = WPA_IF_STATION; | |
10820 | } else if (os_strcmp(pos, "ap") == 0) { | |
10821 | type = WPA_IF_AP_BSS; | |
10822 | } else { | |
10823 | wpa_printf(MSG_DEBUG, | |
10824 | "INTERFACE_ADD unsupported interface type: '%s'", | |
10825 | pos); | |
10826 | return -1; | |
10827 | } | |
10828 | } else { | |
da3db681 BG |
10829 | wpa_printf(MSG_DEBUG, |
10830 | "INTERFACE_ADD unsupported extra parameter: '%s'", | |
10831 | extra); | |
efa232f9 | 10832 | return -1; |
da3db681 | 10833 | } |
6fc6879b JM |
10834 | } while (0); |
10835 | ||
efa232f9 JJ |
10836 | if (create_iface) { |
10837 | wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'", | |
10838 | iface.ifname); | |
10839 | if (!global->ifaces) | |
10840 | return -1; | |
0f039e34 | 10841 | if (wpa_drv_if_add(global->ifaces, type, iface.ifname, |
efa232f9 JJ |
10842 | NULL, NULL, NULL, mac_addr, NULL) < 0) { |
10843 | wpa_printf(MSG_ERROR, | |
10844 | "CTRL_IFACE interface creation failed"); | |
10845 | return -1; | |
10846 | } | |
10847 | ||
10848 | wpa_printf(MSG_DEBUG, | |
10849 | "CTRL_IFACE interface '%s' created with MAC addr: " | |
10850 | MACSTR, iface.ifname, MAC2STR(mac_addr)); | |
10851 | } | |
10852 | ||
6fc6879b | 10853 | if (wpa_supplicant_get_iface(global, iface.ifname)) |
efa232f9 JJ |
10854 | goto fail; |
10855 | ||
10856 | wpa_s = wpa_supplicant_add_iface(global, &iface, NULL); | |
10857 | if (!wpa_s) | |
10858 | goto fail; | |
10859 | wpa_s->added_vif = create_iface; | |
10860 | return 0; | |
6fc6879b | 10861 | |
efa232f9 JJ |
10862 | fail: |
10863 | if (create_iface) | |
10864 | wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname); | |
10865 | return -1; | |
6fc6879b JM |
10866 | } |
10867 | ||
10868 | ||
10869 | static int wpa_supplicant_global_iface_remove(struct wpa_global *global, | |
10870 | char *cmd) | |
10871 | { | |
10872 | struct wpa_supplicant *wpa_s; | |
efa232f9 JJ |
10873 | int ret; |
10874 | unsigned int delete_iface; | |
6fc6879b JM |
10875 | |
10876 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd); | |
10877 | ||
10878 | wpa_s = wpa_supplicant_get_iface(global, cmd); | |
10879 | if (wpa_s == NULL) | |
10880 | return -1; | |
efa232f9 JJ |
10881 | delete_iface = wpa_s->added_vif; |
10882 | ret = wpa_supplicant_remove_iface(global, wpa_s, 0); | |
10883 | if (!ret && delete_iface) { | |
10884 | wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'", | |
10885 | cmd); | |
10886 | ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd); | |
10887 | } | |
10888 | return ret; | |
6fc6879b JM |
10889 | } |
10890 | ||
10891 | ||
4b4a8ae5 JM |
10892 | static void wpa_free_iface_info(struct wpa_interface_info *iface) |
10893 | { | |
10894 | struct wpa_interface_info *prev; | |
10895 | ||
10896 | while (iface) { | |
10897 | prev = iface; | |
10898 | iface = iface->next; | |
10899 | ||
10900 | os_free(prev->ifname); | |
10901 | os_free(prev->desc); | |
10902 | os_free(prev); | |
10903 | } | |
10904 | } | |
10905 | ||
10906 | ||
10907 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, | |
10908 | char *buf, int len) | |
10909 | { | |
10910 | int i, res; | |
10911 | struct wpa_interface_info *iface = NULL, *last = NULL, *tmp; | |
10912 | char *pos, *end; | |
10913 | ||
c5121837 | 10914 | for (i = 0; wpa_drivers[i]; i++) { |
8b423edb | 10915 | const struct wpa_driver_ops *drv = wpa_drivers[i]; |
4b4a8ae5 JM |
10916 | if (drv->get_interfaces == NULL) |
10917 | continue; | |
5fbc1f27 | 10918 | tmp = drv->get_interfaces(global->drv_priv[i]); |
4b4a8ae5 JM |
10919 | if (tmp == NULL) |
10920 | continue; | |
10921 | ||
10922 | if (last == NULL) | |
10923 | iface = last = tmp; | |
10924 | else | |
10925 | last->next = tmp; | |
10926 | while (last->next) | |
10927 | last = last->next; | |
10928 | } | |
10929 | ||
10930 | pos = buf; | |
10931 | end = buf + len; | |
10932 | for (tmp = iface; tmp; tmp = tmp->next) { | |
10933 | res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n", | |
10934 | tmp->drv_name, tmp->ifname, | |
10935 | tmp->desc ? tmp->desc : ""); | |
d85e1fc8 | 10936 | if (os_snprintf_error(end - pos, res)) { |
4b4a8ae5 JM |
10937 | *pos = '\0'; |
10938 | break; | |
10939 | } | |
10940 | pos += res; | |
10941 | } | |
10942 | ||
10943 | wpa_free_iface_info(iface); | |
10944 | ||
10945 | return pos - buf; | |
10946 | } | |
10947 | ||
10948 | ||
6fc6879b | 10949 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
56e2fc2c | 10950 | const char *input, |
6fc6879b JM |
10951 | char *buf, int len) |
10952 | { | |
10953 | int res; | |
10954 | char *pos, *end; | |
10955 | struct wpa_supplicant *wpa_s; | |
56e2fc2c JD |
10956 | int show_ctrl = 0; |
10957 | ||
10958 | if (input) | |
10959 | show_ctrl = !!os_strstr(input, "ctrl"); | |
6fc6879b JM |
10960 | |
10961 | wpa_s = global->ifaces; | |
10962 | pos = buf; | |
10963 | end = buf + len; | |
10964 | ||
10965 | while (wpa_s) { | |
56e2fc2c JD |
10966 | if (show_ctrl) |
10967 | res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n", | |
10968 | wpa_s->ifname, | |
10969 | wpa_s->conf->ctrl_interface ? | |
10970 | wpa_s->conf->ctrl_interface : "N/A"); | |
10971 | else | |
10972 | res = os_snprintf(pos, end - pos, "%s\n", | |
10973 | wpa_s->ifname); | |
10974 | ||
d85e1fc8 | 10975 | if (os_snprintf_error(end - pos, res)) { |
6fc6879b JM |
10976 | *pos = '\0'; |
10977 | break; | |
10978 | } | |
10979 | pos += res; | |
10980 | wpa_s = wpa_s->next; | |
10981 | } | |
10982 | return pos - buf; | |
10983 | } | |
10984 | ||
10985 | ||
cf3bebf2 JM |
10986 | static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global, |
10987 | const char *ifname, | |
10988 | char *cmd, size_t *resp_len) | |
10989 | { | |
10990 | struct wpa_supplicant *wpa_s; | |
10991 | ||
10992 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
10993 | if (os_strcmp(ifname, wpa_s->ifname) == 0) | |
10994 | break; | |
10995 | } | |
10996 | ||
10997 | if (wpa_s == NULL) { | |
10998 | char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n"); | |
10999 | if (resp) | |
11000 | *resp_len = os_strlen(resp); | |
11001 | else | |
11002 | *resp_len = 1; | |
11003 | return resp; | |
11004 | } | |
11005 | ||
11006 | return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len); | |
11007 | } | |
11008 | ||
11009 | ||
576bce9c JM |
11010 | static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global, |
11011 | char *buf, size_t *resp_len) | |
11012 | { | |
11013 | #ifdef CONFIG_P2P | |
11014 | static const char * cmd[] = { | |
443427e4 | 11015 | "LIST_NETWORKS", |
576bce9c JM |
11016 | "P2P_FIND", |
11017 | "P2P_STOP_FIND", | |
11018 | "P2P_LISTEN", | |
11019 | "P2P_GROUP_ADD", | |
11020 | "P2P_GET_PASSPHRASE", | |
11021 | "P2P_SERVICE_UPDATE", | |
11022 | "P2P_SERVICE_FLUSH", | |
11023 | "P2P_FLUSH", | |
11024 | "P2P_CANCEL", | |
11025 | "P2P_PRESENCE_REQ", | |
11026 | "P2P_EXT_LISTEN", | |
f2bc3448 DS |
11027 | #ifdef CONFIG_AP |
11028 | "STA-FIRST", | |
11029 | #endif /* CONFIG_AP */ | |
576bce9c JM |
11030 | NULL |
11031 | }; | |
11032 | static const char * prefix[] = { | |
443427e4 DS |
11033 | #ifdef ANDROID |
11034 | "DRIVER ", | |
11035 | #endif /* ANDROID */ | |
be1ece46 | 11036 | "GET_CAPABILITY ", |
443427e4 DS |
11037 | "GET_NETWORK ", |
11038 | "REMOVE_NETWORK ", | |
576bce9c JM |
11039 | "P2P_FIND ", |
11040 | "P2P_CONNECT ", | |
11041 | "P2P_LISTEN ", | |
11042 | "P2P_GROUP_REMOVE ", | |
11043 | "P2P_GROUP_ADD ", | |
57b38882 | 11044 | "P2P_GROUP_MEMBER ", |
576bce9c JM |
11045 | "P2P_PROV_DISC ", |
11046 | "P2P_SERV_DISC_REQ ", | |
11047 | "P2P_SERV_DISC_CANCEL_REQ ", | |
11048 | "P2P_SERV_DISC_RESP ", | |
11049 | "P2P_SERV_DISC_EXTERNAL ", | |
11050 | "P2P_SERVICE_ADD ", | |
11051 | "P2P_SERVICE_DEL ", | |
87d5ef5a | 11052 | "P2P_SERVICE_REP ", |
576bce9c JM |
11053 | "P2P_REJECT ", |
11054 | "P2P_INVITE ", | |
11055 | "P2P_PEER ", | |
11056 | "P2P_SET ", | |
11057 | "P2P_UNAUTHORIZE ", | |
11058 | "P2P_PRESENCE_REQ ", | |
11059 | "P2P_EXT_LISTEN ", | |
f2c56602 | 11060 | "P2P_REMOVE_CLIENT ", |
8ad8bc5c DS |
11061 | "WPS_NFC_TOKEN ", |
11062 | "WPS_NFC_TAG_READ ", | |
f3ff9487 AM |
11063 | "NFC_GET_HANDOVER_SEL ", |
11064 | "NFC_GET_HANDOVER_REQ ", | |
11065 | "NFC_REPORT_HANDOVER ", | |
87d5ef5a KV |
11066 | "P2P_ASP_PROVISION ", |
11067 | "P2P_ASP_PROVISION_RESP ", | |
f2bc3448 DS |
11068 | #ifdef CONFIG_AP |
11069 | "STA ", | |
11070 | "STA-NEXT ", | |
11071 | #endif /* CONFIG_AP */ | |
576bce9c JM |
11072 | NULL |
11073 | }; | |
11074 | int found = 0; | |
11075 | int i; | |
11076 | ||
11077 | if (global->p2p_init_wpa_s == NULL) | |
11078 | return NULL; | |
11079 | ||
11080 | for (i = 0; !found && cmd[i]; i++) { | |
11081 | if (os_strcmp(buf, cmd[i]) == 0) | |
11082 | found = 1; | |
11083 | } | |
11084 | ||
11085 | for (i = 0; !found && prefix[i]; i++) { | |
11086 | if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0) | |
11087 | found = 1; | |
11088 | } | |
11089 | ||
11090 | if (found) | |
11091 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, | |
11092 | buf, resp_len); | |
11093 | #endif /* CONFIG_P2P */ | |
11094 | return NULL; | |
11095 | } | |
11096 | ||
11097 | ||
11098 | static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global, | |
11099 | char *buf, size_t *resp_len) | |
11100 | { | |
11101 | #ifdef CONFIG_WIFI_DISPLAY | |
11102 | if (global->p2p_init_wpa_s == NULL) | |
11103 | return NULL; | |
11104 | if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 || | |
11105 | os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) | |
11106 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, | |
11107 | buf, resp_len); | |
11108 | #endif /* CONFIG_WIFI_DISPLAY */ | |
11109 | return NULL; | |
11110 | } | |
11111 | ||
11112 | ||
11113 | static char * wpas_global_ctrl_iface_redir(struct wpa_global *global, | |
11114 | char *buf, size_t *resp_len) | |
11115 | { | |
11116 | char *ret; | |
11117 | ||
11118 | ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len); | |
11119 | if (ret) | |
11120 | return ret; | |
11121 | ||
11122 | ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len); | |
11123 | if (ret) | |
11124 | return ret; | |
11125 | ||
11126 | return NULL; | |
11127 | } | |
11128 | ||
11129 | ||
1b9b31c1 JM |
11130 | static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd) |
11131 | { | |
11132 | char *value; | |
11133 | ||
11134 | value = os_strchr(cmd, ' '); | |
11135 | if (value == NULL) | |
11136 | return -1; | |
11137 | *value++ = '\0'; | |
11138 | ||
11139 | wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value); | |
11140 | ||
11141 | #ifdef CONFIG_WIFI_DISPLAY | |
11142 | if (os_strcasecmp(cmd, "wifi_display") == 0) { | |
11143 | wifi_display_enable(global, !!atoi(value)); | |
11144 | return 0; | |
11145 | } | |
11146 | #endif /* CONFIG_WIFI_DISPLAY */ | |
11147 | ||
a7ca6dac JM |
11148 | /* Restore cmd to its original value to allow redirection */ |
11149 | value[-1] = ' '; | |
11150 | ||
1b9b31c1 JM |
11151 | return -1; |
11152 | } | |
11153 | ||
11154 | ||
daae4995 AN |
11155 | static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global, |
11156 | char *cmd) | |
11157 | { | |
11158 | struct wpa_supplicant *wpa_s[2]; /* src, dst */ | |
11159 | char *p; | |
11160 | unsigned int i; | |
11161 | ||
11162 | /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id> | |
11163 | * <variable name> */ | |
11164 | ||
11165 | for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) { | |
11166 | p = os_strchr(cmd, ' '); | |
11167 | if (p == NULL) | |
11168 | return -1; | |
11169 | *p = '\0'; | |
11170 | ||
11171 | wpa_s[i] = global->ifaces; | |
11172 | for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) { | |
11173 | if (os_strcmp(cmd, wpa_s[i]->ifname) == 0) | |
11174 | break; | |
11175 | } | |
11176 | ||
11177 | if (!wpa_s[i]) { | |
11178 | wpa_printf(MSG_DEBUG, | |
11179 | "CTRL_IFACE: Could not find iface=%s", cmd); | |
11180 | return -1; | |
11181 | } | |
11182 | ||
11183 | cmd = p + 1; | |
11184 | } | |
11185 | ||
11186 | return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]); | |
11187 | } | |
11188 | ||
11189 | ||
42868f14 JM |
11190 | #ifndef CONFIG_NO_CONFIG_WRITE |
11191 | static int wpas_global_ctrl_iface_save_config(struct wpa_global *global) | |
11192 | { | |
d6b818ef | 11193 | int ret = 0, saved = 0; |
42868f14 JM |
11194 | struct wpa_supplicant *wpa_s; |
11195 | ||
11196 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
11197 | if (!wpa_s->conf->update_config) { | |
11198 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)"); | |
11199 | continue; | |
11200 | } | |
11201 | ||
11202 | if (wpa_config_write(wpa_s->confname, wpa_s->conf)) { | |
11203 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration"); | |
11204 | ret = 1; | |
11205 | } else { | |
11206 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated"); | |
d6b818ef | 11207 | saved++; |
42868f14 JM |
11208 | } |
11209 | } | |
11210 | ||
d6b818ef JM |
11211 | if (!saved && !ret) { |
11212 | wpa_dbg(wpa_s, MSG_DEBUG, | |
11213 | "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated"); | |
11214 | ret = 1; | |
11215 | } | |
11216 | ||
42868f14 JM |
11217 | return ret; |
11218 | } | |
11219 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
11220 | ||
11221 | ||
ae8c27f7 JM |
11222 | static int wpas_global_ctrl_iface_status(struct wpa_global *global, |
11223 | char *buf, size_t buflen) | |
11224 | { | |
11225 | char *pos, *end; | |
11226 | int ret; | |
11227 | struct wpa_supplicant *wpa_s; | |
11228 | ||
11229 | pos = buf; | |
11230 | end = buf + buflen; | |
11231 | ||
11232 | #ifdef CONFIG_P2P | |
4c559019 | 11233 | if (global->p2p && !global->p2p_disabled) { |
ae8c27f7 | 11234 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR |
4c559019 JM |
11235 | "\n" |
11236 | "p2p_state=%s\n", | |
11237 | MAC2STR(global->p2p_dev_addr), | |
11238 | p2p_get_state_txt(global->p2p)); | |
d85e1fc8 | 11239 | if (os_snprintf_error(end - pos, ret)) |
4c559019 JM |
11240 | return pos - buf; |
11241 | pos += ret; | |
11242 | } else if (global->p2p) { | |
11243 | ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n"); | |
d85e1fc8 | 11244 | if (os_snprintf_error(end - pos, ret)) |
ae8c27f7 JM |
11245 | return pos - buf; |
11246 | pos += ret; | |
11247 | } | |
11248 | #endif /* CONFIG_P2P */ | |
11249 | ||
11250 | #ifdef CONFIG_WIFI_DISPLAY | |
11251 | ret = os_snprintf(pos, end - pos, "wifi_display=%d\n", | |
11252 | !!global->wifi_display); | |
d85e1fc8 | 11253 | if (os_snprintf_error(end - pos, ret)) |
ae8c27f7 JM |
11254 | return pos - buf; |
11255 | pos += ret; | |
11256 | #endif /* CONFIG_WIFI_DISPLAY */ | |
11257 | ||
11258 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
11259 | ret = os_snprintf(pos, end - pos, "ifname=%s\n" | |
11260 | "address=" MACSTR "\n", | |
11261 | wpa_s->ifname, MAC2STR(wpa_s->own_addr)); | |
d85e1fc8 | 11262 | if (os_snprintf_error(end - pos, ret)) |
ae8c27f7 JM |
11263 | return pos - buf; |
11264 | pos += ret; | |
11265 | } | |
11266 | ||
11267 | return pos - buf; | |
11268 | } | |
11269 | ||
11270 | ||
3794af2d AN |
11271 | #ifdef CONFIG_FST |
11272 | ||
11273 | static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global, | |
11274 | char *cmd, char *buf, | |
11275 | size_t reply_size) | |
11276 | { | |
11277 | char ifname[IFNAMSIZ + 1]; | |
11278 | struct fst_iface_cfg cfg; | |
11279 | struct wpa_supplicant *wpa_s; | |
11280 | struct fst_wpa_obj iface_obj; | |
11281 | ||
11282 | if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) { | |
11283 | wpa_s = wpa_supplicant_get_iface(global, ifname); | |
11284 | if (wpa_s) { | |
5dbd3bf9 JM |
11285 | if (wpa_s->fst) { |
11286 | wpa_printf(MSG_INFO, "FST: Already attached"); | |
11287 | return -1; | |
11288 | } | |
3794af2d AN |
11289 | fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj); |
11290 | wpa_s->fst = fst_attach(ifname, wpa_s->own_addr, | |
11291 | &iface_obj, &cfg); | |
11292 | if (wpa_s->fst) | |
11293 | return os_snprintf(buf, reply_size, "OK\n"); | |
11294 | } | |
11295 | } | |
11296 | ||
11297 | return -1; | |
11298 | } | |
11299 | ||
11300 | ||
11301 | static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global, | |
11302 | char *cmd, char *buf, | |
11303 | size_t reply_size) | |
11304 | { | |
11305 | char ifname[IFNAMSIZ + 1]; | |
11306 | struct wpa_supplicant *wpa_s; | |
11307 | ||
11308 | if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) { | |
11309 | wpa_s = wpa_supplicant_get_iface(global, ifname); | |
11310 | if (wpa_s) { | |
11311 | if (!fst_iface_detach(ifname)) { | |
11312 | wpa_s->fst = NULL; | |
11313 | return os_snprintf(buf, reply_size, "OK\n"); | |
11314 | } | |
11315 | } | |
11316 | } | |
11317 | ||
11318 | return -1; | |
11319 | } | |
11320 | ||
11321 | #endif /* CONFIG_FST */ | |
11322 | ||
11323 | ||
6fc6879b JM |
11324 | char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, |
11325 | char *buf, size_t *resp_len) | |
11326 | { | |
11327 | char *reply; | |
11328 | const int reply_size = 2048; | |
11329 | int reply_len; | |
f4a0a82c | 11330 | int level = MSG_DEBUG; |
6fc6879b | 11331 | |
cf3bebf2 JM |
11332 | if (os_strncmp(buf, "IFNAME=", 7) == 0) { |
11333 | char *pos = os_strchr(buf + 7, ' '); | |
11334 | if (pos) { | |
11335 | *pos++ = '\0'; | |
11336 | return wpas_global_ctrl_iface_ifname(global, | |
11337 | buf + 7, pos, | |
11338 | resp_len); | |
11339 | } | |
11340 | } | |
11341 | ||
576bce9c JM |
11342 | reply = wpas_global_ctrl_iface_redir(global, buf, resp_len); |
11343 | if (reply) | |
11344 | return reply; | |
11345 | ||
f4a0a82c JM |
11346 | if (os_strcmp(buf, "PING") == 0) |
11347 | level = MSG_EXCESSIVE; | |
11348 | wpa_hexdump_ascii(level, "RX global ctrl_iface", | |
6fc6879b JM |
11349 | (const u8 *) buf, os_strlen(buf)); |
11350 | ||
11351 | reply = os_malloc(reply_size); | |
11352 | if (reply == NULL) { | |
11353 | *resp_len = 1; | |
11354 | return NULL; | |
11355 | } | |
11356 | ||
11357 | os_memcpy(reply, "OK\n", 3); | |
11358 | reply_len = 3; | |
11359 | ||
11360 | if (os_strcmp(buf, "PING") == 0) { | |
11361 | os_memcpy(reply, "PONG\n", 5); | |
11362 | reply_len = 5; | |
11363 | } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) { | |
11364 | if (wpa_supplicant_global_iface_add(global, buf + 14)) | |
11365 | reply_len = -1; | |
11366 | } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) { | |
11367 | if (wpa_supplicant_global_iface_remove(global, buf + 17)) | |
11368 | reply_len = -1; | |
4b4a8ae5 JM |
11369 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
11370 | reply_len = wpa_supplicant_global_iface_list( | |
11371 | global, reply, reply_size); | |
56e2fc2c | 11372 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { |
6fc6879b | 11373 | reply_len = wpa_supplicant_global_iface_interfaces( |
56e2fc2c | 11374 | global, buf + 10, reply, reply_size); |
3794af2d AN |
11375 | #ifdef CONFIG_FST |
11376 | } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) { | |
11377 | reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11, | |
11378 | reply, | |
11379 | reply_size); | |
11380 | } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) { | |
11381 | reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11, | |
11382 | reply, | |
11383 | reply_size); | |
11384 | } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) { | |
11385 | reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size); | |
11386 | #endif /* CONFIG_FST */ | |
6fc6879b | 11387 | } else if (os_strcmp(buf, "TERMINATE") == 0) { |
1a1bf008 | 11388 | wpa_supplicant_terminate_proc(global); |
207ef3fb JM |
11389 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
11390 | wpas_notify_suspend(global); | |
11391 | } else if (os_strcmp(buf, "RESUME") == 0) { | |
11392 | wpas_notify_resume(global); | |
1b9b31c1 | 11393 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
a7ca6dac JM |
11394 | if (wpas_global_ctrl_iface_set(global, buf + 4)) { |
11395 | #ifdef CONFIG_P2P | |
11396 | if (global->p2p_init_wpa_s) { | |
11397 | os_free(reply); | |
11398 | /* Check if P2P redirection would work for this | |
11399 | * command. */ | |
11400 | return wpa_supplicant_ctrl_iface_process( | |
11401 | global->p2p_init_wpa_s, | |
11402 | buf, resp_len); | |
11403 | } | |
11404 | #endif /* CONFIG_P2P */ | |
1b9b31c1 | 11405 | reply_len = -1; |
a7ca6dac | 11406 | } |
daae4995 AN |
11407 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
11408 | if (wpas_global_ctrl_iface_dup_network(global, buf + 12)) | |
11409 | reply_len = -1; | |
42868f14 JM |
11410 | #ifndef CONFIG_NO_CONFIG_WRITE |
11411 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | |
11412 | if (wpas_global_ctrl_iface_save_config(global)) | |
11413 | reply_len = -1; | |
11414 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
ae8c27f7 JM |
11415 | } else if (os_strcmp(buf, "STATUS") == 0) { |
11416 | reply_len = wpas_global_ctrl_iface_status(global, reply, | |
11417 | reply_size); | |
ea449b5b JM |
11418 | #ifdef CONFIG_MODULE_TESTS |
11419 | } else if (os_strcmp(buf, "MODULE_TESTS") == 0) { | |
ea449b5b JM |
11420 | if (wpas_module_tests() < 0) |
11421 | reply_len = -1; | |
11422 | #endif /* CONFIG_MODULE_TESTS */ | |
5f797376 JM |
11423 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
11424 | if (wpa_debug_reopen_file() < 0) | |
11425 | reply_len = -1; | |
6fc6879b JM |
11426 | } else { |
11427 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | |
11428 | reply_len = 16; | |
11429 | } | |
11430 | ||
11431 | if (reply_len < 0) { | |
11432 | os_memcpy(reply, "FAIL\n", 5); | |
11433 | reply_len = 5; | |
11434 | } | |
11435 | ||
11436 | *resp_len = reply_len; | |
11437 | return reply; | |
11438 | } |