]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant / Control interface (shared code for all backends) | |
5e3b5197 | 3 | * Copyright (c) 2004-2015, 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" |
a1651451 | 23 | #include "crypto/tls.h" |
9d4ff04a | 24 | #include "ap/hostapd.h" |
3a068632 JM |
25 | #include "eap_peer/eap.h" |
26 | #include "eapol_supp/eapol_supp_sm.h" | |
3acb5005 | 27 | #include "rsn_supp/wpa.h" |
3a068632 JM |
28 | #include "rsn_supp/preauth.h" |
29 | #include "rsn_supp/pmksa_cache.h" | |
30 | #include "l2_packet/l2_packet.h" | |
31 | #include "wps/wps.h" | |
df4cea89 | 32 | #include "fst/fst.h" |
3794af2d | 33 | #include "fst/fst_ctrl_iface.h" |
6fc6879b | 34 | #include "config.h" |
6fc6879b | 35 | #include "wpa_supplicant_i.h" |
2d5b792d | 36 | #include "driver_i.h" |
fcc60db4 | 37 | #include "wps_supplicant.h" |
11ef8d35 | 38 | #include "ibss_rsn.h" |
3ec97afe | 39 | #include "ap.h" |
b563b388 JM |
40 | #include "p2p_supplicant.h" |
41 | #include "p2p/p2p.h" | |
a8918e86 | 42 | #include "hs20_supplicant.h" |
9675ce35 | 43 | #include "wifi_display.h" |
8bac466b | 44 | #include "notify.h" |
3a068632 | 45 | #include "bss.h" |
9ba9fa07 | 46 | #include "scan.h" |
3a068632 | 47 | #include "ctrl_iface.h" |
afc064fe | 48 | #include "interworking.h" |
9aa10e2b | 49 | #include "blacklist.h" |
bc5d330a | 50 | #include "autoscan.h" |
e9199e31 | 51 | #include "wnm_sta.h" |
60b893df | 52 | #include "offchannel.h" |
7a4a93b9 | 53 | #include "drivers/driver.h" |
79070906 | 54 | #include "mesh.h" |
6fc6879b | 55 | |
4b4a8ae5 JM |
56 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
57 | char *buf, int len); | |
6fc6879b | 58 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
56e2fc2c | 59 | const char *input, |
6fc6879b | 60 | char *buf, int len); |
d3c9c35f DS |
61 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, |
62 | char *val); | |
6fc6879b | 63 | |
d445a5cd JM |
64 | static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val) |
65 | { | |
66 | char *pos; | |
67 | u8 addr[ETH_ALEN], *filter = NULL, *n; | |
68 | size_t count = 0; | |
69 | ||
70 | pos = val; | |
71 | while (pos) { | |
72 | if (*pos == '\0') | |
73 | break; | |
1485ec07 JM |
74 | if (hwaddr_aton(pos, addr)) { |
75 | os_free(filter); | |
d445a5cd | 76 | return -1; |
1485ec07 | 77 | } |
067ffa26 | 78 | n = os_realloc_array(filter, count + 1, ETH_ALEN); |
d445a5cd JM |
79 | if (n == NULL) { |
80 | os_free(filter); | |
81 | return -1; | |
82 | } | |
83 | filter = n; | |
84 | os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN); | |
85 | count++; | |
86 | ||
87 | pos = os_strchr(pos, ' '); | |
88 | if (pos) | |
89 | pos++; | |
90 | } | |
91 | ||
92 | wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN); | |
93 | os_free(wpa_s->bssid_filter); | |
94 | wpa_s->bssid_filter = filter; | |
95 | wpa_s->bssid_filter_count = count; | |
96 | ||
97 | return 0; | |
98 | } | |
99 | ||
100 | ||
6407f413 JM |
101 | static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val) |
102 | { | |
103 | char *pos; | |
104 | u8 addr[ETH_ALEN], *bssid = NULL, *n; | |
105 | struct wpa_ssid_value *ssid = NULL, *ns; | |
106 | size_t count = 0, ssid_count = 0; | |
107 | struct wpa_ssid *c; | |
108 | ||
109 | /* | |
65015b2d | 110 | * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | "" |
6407f413 JM |
111 | * SSID_SPEC ::= ssid <SSID_HEX> |
112 | * BSSID_SPEC ::= bssid <BSSID_HEX> | |
113 | */ | |
114 | ||
115 | pos = val; | |
116 | while (pos) { | |
117 | if (*pos == '\0') | |
118 | break; | |
119 | if (os_strncmp(pos, "bssid ", 6) == 0) { | |
120 | int res; | |
121 | pos += 6; | |
122 | res = hwaddr_aton2(pos, addr); | |
123 | if (res < 0) { | |
124 | os_free(ssid); | |
125 | os_free(bssid); | |
126 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " | |
127 | "BSSID value '%s'", pos); | |
128 | return -1; | |
129 | } | |
130 | pos += res; | |
131 | n = os_realloc_array(bssid, count + 1, ETH_ALEN); | |
132 | if (n == NULL) { | |
133 | os_free(ssid); | |
134 | os_free(bssid); | |
135 | return -1; | |
136 | } | |
137 | bssid = n; | |
138 | os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN); | |
139 | count++; | |
140 | } else if (os_strncmp(pos, "ssid ", 5) == 0) { | |
141 | char *end; | |
142 | pos += 5; | |
143 | ||
144 | end = pos; | |
145 | while (*end) { | |
146 | if (*end == '\0' || *end == ' ') | |
147 | break; | |
148 | end++; | |
149 | } | |
150 | ||
151 | ns = os_realloc_array(ssid, ssid_count + 1, | |
152 | sizeof(struct wpa_ssid_value)); | |
153 | if (ns == NULL) { | |
154 | os_free(ssid); | |
155 | os_free(bssid); | |
156 | return -1; | |
157 | } | |
158 | ssid = ns; | |
159 | ||
d9d1b952 JM |
160 | if ((end - pos) & 0x01 || |
161 | end - pos > 2 * SSID_MAX_LEN || | |
6407f413 JM |
162 | hexstr2bin(pos, ssid[ssid_count].ssid, |
163 | (end - pos) / 2) < 0) { | |
164 | os_free(ssid); | |
165 | os_free(bssid); | |
166 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " | |
167 | "SSID value '%s'", pos); | |
168 | return -1; | |
169 | } | |
170 | ssid[ssid_count].ssid_len = (end - pos) / 2; | |
171 | wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID", | |
172 | ssid[ssid_count].ssid, | |
173 | ssid[ssid_count].ssid_len); | |
174 | ssid_count++; | |
175 | pos = end; | |
176 | } else { | |
177 | wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value " | |
178 | "'%s'", pos); | |
179 | os_free(ssid); | |
180 | os_free(bssid); | |
181 | return -1; | |
182 | } | |
183 | ||
184 | pos = os_strchr(pos, ' '); | |
185 | if (pos) | |
186 | pos++; | |
187 | } | |
188 | ||
189 | wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN); | |
190 | os_free(wpa_s->disallow_aps_bssid); | |
191 | wpa_s->disallow_aps_bssid = bssid; | |
192 | wpa_s->disallow_aps_bssid_count = count; | |
193 | ||
194 | wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count); | |
195 | os_free(wpa_s->disallow_aps_ssid); | |
196 | wpa_s->disallow_aps_ssid = ssid; | |
197 | wpa_s->disallow_aps_ssid_count = ssid_count; | |
198 | ||
199 | if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING) | |
200 | return 0; | |
201 | ||
202 | c = wpa_s->current_ssid; | |
203 | if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS) | |
204 | return 0; | |
205 | ||
206 | if (!disallowed_bssid(wpa_s, wpa_s->bssid) && | |
207 | !disallowed_ssid(wpa_s, c->ssid, c->ssid_len)) | |
208 | return 0; | |
209 | ||
210 | wpa_printf(MSG_DEBUG, "Disconnect and try to find another network " | |
211 | "because current AP was marked disallowed"); | |
212 | ||
213 | #ifdef CONFIG_SME | |
214 | wpa_s->sme.prev_bssid_set = 0; | |
215 | #endif /* CONFIG_SME */ | |
216 | wpa_s->reassociate = 1; | |
c2805909 | 217 | wpa_s->own_disconnect_req = 1; |
6407f413 JM |
218 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
219 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
220 | ||
221 | return 0; | |
222 | } | |
223 | ||
224 | ||
1120e452 JM |
225 | #ifndef CONFIG_NO_CONFIG_BLOBS |
226 | static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos) | |
227 | { | |
228 | char *name = pos; | |
229 | struct wpa_config_blob *blob; | |
230 | size_t len; | |
231 | ||
232 | pos = os_strchr(pos, ' '); | |
233 | if (pos == NULL) | |
234 | return -1; | |
235 | *pos++ = '\0'; | |
236 | len = os_strlen(pos); | |
237 | if (len & 1) | |
238 | return -1; | |
239 | ||
240 | wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name); | |
241 | blob = os_zalloc(sizeof(*blob)); | |
242 | if (blob == NULL) | |
243 | return -1; | |
244 | blob->name = os_strdup(name); | |
245 | blob->data = os_malloc(len / 2); | |
246 | if (blob->name == NULL || blob->data == NULL) { | |
247 | wpa_config_free_blob(blob); | |
248 | return -1; | |
249 | } | |
250 | ||
251 | if (hexstr2bin(pos, blob->data, len / 2) < 0) { | |
252 | wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data"); | |
253 | wpa_config_free_blob(blob); | |
254 | return -1; | |
255 | } | |
256 | blob->len = len / 2; | |
257 | ||
258 | wpa_config_set_blob(wpa_s->conf, blob); | |
259 | ||
260 | return 0; | |
261 | } | |
262 | #endif /* CONFIG_NO_CONFIG_BLOBS */ | |
263 | ||
d3c9c35f DS |
264 | |
265 | static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd) | |
266 | { | |
267 | char *params; | |
268 | char *pos; | |
269 | int *freqs = NULL; | |
270 | int ret; | |
271 | ||
272 | if (atoi(cmd)) { | |
273 | params = os_strchr(cmd, ' '); | |
274 | os_free(wpa_s->manual_sched_scan_freqs); | |
275 | if (params) { | |
276 | params++; | |
277 | pos = os_strstr(params, "freq="); | |
278 | if (pos) | |
279 | freqs = freq_range_to_channel_list(wpa_s, | |
280 | pos + 5); | |
281 | } | |
282 | wpa_s->manual_sched_scan_freqs = freqs; | |
283 | ret = wpas_start_pno(wpa_s); | |
284 | } else { | |
285 | ret = wpas_stop_pno(wpa_s); | |
286 | } | |
287 | return ret; | |
288 | } | |
289 | ||
290 | ||
844dfeb8 SD |
291 | static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band) |
292 | { | |
293 | union wpa_event_data event; | |
294 | ||
295 | if (os_strcmp(band, "AUTO") == 0) | |
296 | wpa_s->setband = WPA_SETBAND_AUTO; | |
297 | else if (os_strcmp(band, "5G") == 0) | |
298 | wpa_s->setband = WPA_SETBAND_5G; | |
299 | else if (os_strcmp(band, "2G") == 0) | |
300 | wpa_s->setband = WPA_SETBAND_2G; | |
301 | else | |
302 | return -1; | |
303 | ||
304 | if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) { | |
305 | os_memset(&event, 0, sizeof(event)); | |
306 | event.channel_list_changed.initiator = REGDOM_SET_BY_USER; | |
307 | event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN; | |
308 | wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event); | |
309 | } | |
310 | ||
311 | return 0; | |
312 | } | |
313 | ||
314 | ||
4a742011 DS |
315 | static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s, |
316 | const char *cmd) | |
317 | { | |
318 | struct wpabuf *lci; | |
319 | ||
320 | if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) { | |
321 | wpabuf_free(wpa_s->lci); | |
322 | wpa_s->lci = NULL; | |
323 | return 0; | |
324 | } | |
325 | ||
326 | lci = wpabuf_parse_bin(cmd); | |
327 | if (!lci) | |
328 | return -1; | |
329 | ||
330 | if (os_get_reltime(&wpa_s->lci_time)) { | |
331 | wpabuf_free(lci); | |
332 | return -1; | |
333 | } | |
334 | ||
335 | wpabuf_free(wpa_s->lci); | |
336 | wpa_s->lci = lci; | |
337 | ||
338 | return 0; | |
339 | } | |
340 | ||
341 | ||
57c3a605 | 342 | static int |
343 | wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd) | |
344 | { | |
345 | int relative_rssi; | |
346 | ||
347 | if (os_strcmp(cmd, "disable") == 0) { | |
348 | wpa_s->srp.relative_rssi_set = 0; | |
349 | return 0; | |
350 | } | |
351 | ||
352 | relative_rssi = atoi(cmd); | |
353 | if (relative_rssi < 0 || relative_rssi > 100) | |
354 | return -1; | |
355 | wpa_s->srp.relative_rssi = relative_rssi; | |
356 | wpa_s->srp.relative_rssi_set = 1; | |
357 | return 0; | |
358 | } | |
359 | ||
360 | ||
361 | static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s, | |
362 | const char *cmd) | |
363 | { | |
364 | char *pos; | |
365 | int adjust_rssi; | |
366 | ||
367 | /* <band>:adjust_value */ | |
368 | pos = os_strchr(cmd, ':'); | |
369 | if (!pos) | |
370 | return -1; | |
371 | pos++; | |
372 | adjust_rssi = atoi(pos); | |
373 | if (adjust_rssi < -100 || adjust_rssi > 100) | |
374 | return -1; | |
375 | ||
376 | if (os_strncmp(cmd, "2G", 2) == 0) | |
377 | wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G; | |
378 | else if (os_strncmp(cmd, "5G", 2) == 0) | |
379 | wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G; | |
380 | else | |
381 | return -1; | |
382 | ||
383 | wpa_s->srp.relative_adjust_rssi = adjust_rssi; | |
384 | ||
385 | return 0; | |
386 | } | |
387 | ||
388 | ||
c6c41f6e JM |
389 | static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s, |
390 | const char *cmd) | |
391 | { | |
392 | struct wpabuf *ric_ies; | |
393 | ||
394 | if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) { | |
395 | wpabuf_free(wpa_s->ric_ies); | |
396 | wpa_s->ric_ies = NULL; | |
397 | return 0; | |
398 | } | |
399 | ||
400 | ric_ies = wpabuf_parse_bin(cmd); | |
401 | if (!ric_ies) | |
402 | return -1; | |
403 | ||
404 | wpabuf_free(wpa_s->ric_ies); | |
405 | wpa_s->ric_ies = ric_ies; | |
406 | ||
407 | return 0; | |
408 | } | |
409 | ||
410 | ||
6fc6879b JM |
411 | static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, |
412 | char *cmd) | |
413 | { | |
414 | char *value; | |
415 | int ret = 0; | |
416 | ||
417 | value = os_strchr(cmd, ' '); | |
418 | if (value == NULL) | |
419 | return -1; | |
420 | *value++ = '\0'; | |
421 | ||
422 | wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value); | |
423 | if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) { | |
424 | eapol_sm_configure(wpa_s->eapol, | |
425 | atoi(value), -1, -1, -1); | |
426 | } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) { | |
427 | eapol_sm_configure(wpa_s->eapol, | |
428 | -1, atoi(value), -1, -1); | |
429 | } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) { | |
430 | eapol_sm_configure(wpa_s->eapol, | |
431 | -1, -1, atoi(value), -1); | |
432 | } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) { | |
433 | eapol_sm_configure(wpa_s->eapol, | |
434 | -1, -1, -1, atoi(value)); | |
435 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) { | |
436 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, | |
b4bdeadf | 437 | atoi(value))) { |
6fc6879b | 438 | ret = -1; |
b4bdeadf JM |
439 | } else { |
440 | value[-1] = '='; | |
441 | wpa_config_process_global(wpa_s->conf, cmd, -1); | |
442 | } | |
6fc6879b JM |
443 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == |
444 | 0) { | |
445 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, | |
b4bdeadf | 446 | atoi(value))) { |
6fc6879b | 447 | ret = -1; |
b4bdeadf JM |
448 | } else { |
449 | value[-1] = '='; | |
450 | wpa_config_process_global(wpa_s->conf, cmd, -1); | |
451 | } | |
6fc6879b | 452 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) { |
b4bdeadf JM |
453 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, |
454 | atoi(value))) { | |
6fc6879b | 455 | ret = -1; |
b4bdeadf JM |
456 | } else { |
457 | value[-1] = '='; | |
458 | wpa_config_process_global(wpa_s->conf, cmd, -1); | |
459 | } | |
42f50264 JM |
460 | } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) { |
461 | wpa_s->wps_fragment_size = atoi(value); | |
b4e34f2f JM |
462 | #ifdef CONFIG_WPS_TESTING |
463 | } else if (os_strcasecmp(cmd, "wps_version_number") == 0) { | |
464 | long int val; | |
465 | val = strtol(value, NULL, 0); | |
466 | if (val < 0 || val > 0xff) { | |
467 | ret = -1; | |
468 | wpa_printf(MSG_DEBUG, "WPS: Invalid " | |
469 | "wps_version_number %ld", val); | |
470 | } else { | |
471 | wps_version_number = val; | |
472 | wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS " | |
473 | "version %u.%u", | |
474 | (wps_version_number & 0xf0) >> 4, | |
475 | wps_version_number & 0x0f); | |
476 | } | |
477 | } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) { | |
478 | wps_testing_dummy_cred = atoi(value); | |
479 | wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d", | |
480 | wps_testing_dummy_cred); | |
91226e0d JM |
481 | } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) { |
482 | wps_corrupt_pkhash = atoi(value); | |
483 | wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d", | |
484 | wps_corrupt_pkhash); | |
6e379c6c JM |
485 | } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) { |
486 | if (value[0] == '\0') { | |
487 | wps_force_auth_types_in_use = 0; | |
488 | } else { | |
489 | wps_force_auth_types = strtol(value, NULL, 0); | |
490 | wps_force_auth_types_in_use = 1; | |
491 | } | |
492 | } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) { | |
493 | if (value[0] == '\0') { | |
494 | wps_force_encr_types_in_use = 0; | |
495 | } else { | |
496 | wps_force_encr_types = strtol(value, NULL, 0); | |
497 | wps_force_encr_types_in_use = 1; | |
498 | } | |
b4e34f2f | 499 | #endif /* CONFIG_WPS_TESTING */ |
b6c79a99 JM |
500 | } else if (os_strcasecmp(cmd, "ampdu") == 0) { |
501 | if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0) | |
502 | ret = -1; | |
9d2cb3ec | 503 | #ifdef CONFIG_TDLS |
5b0e6ece JM |
504 | #ifdef CONFIG_TDLS_TESTING |
505 | } else if (os_strcasecmp(cmd, "tdls_testing") == 0) { | |
5b0e6ece JM |
506 | tdls_testing = strtol(value, NULL, 0); |
507 | wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing); | |
508 | #endif /* CONFIG_TDLS_TESTING */ | |
b8f64582 JM |
509 | } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) { |
510 | int disabled = atoi(value); | |
511 | wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled); | |
512 | if (disabled) { | |
513 | if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0) | |
514 | ret = -1; | |
515 | } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0) | |
516 | ret = -1; | |
517 | wpa_tdls_enable(wpa_s->wpa, !disabled); | |
518 | #endif /* CONFIG_TDLS */ | |
b5c68312 | 519 | } else if (os_strcasecmp(cmd, "pno") == 0) { |
d3c9c35f | 520 | ret = wpas_ctrl_pno(wpa_s, value); |
8b9d0bfa JM |
521 | } else if (os_strcasecmp(cmd, "radio_disabled") == 0) { |
522 | int disabled = atoi(value); | |
523 | if (wpa_drv_radio_disable(wpa_s, disabled) < 0) | |
524 | ret = -1; | |
525 | else if (disabled) | |
526 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | |
aa074a64 JM |
527 | } else if (os_strcasecmp(cmd, "uapsd") == 0) { |
528 | if (os_strcmp(value, "disable") == 0) | |
529 | wpa_s->set_sta_uapsd = 0; | |
530 | else { | |
531 | int be, bk, vi, vo; | |
532 | char *pos; | |
533 | /* format: BE,BK,VI,VO;max SP Length */ | |
534 | be = atoi(value); | |
535 | pos = os_strchr(value, ','); | |
536 | if (pos == NULL) | |
537 | return -1; | |
538 | pos++; | |
539 | bk = atoi(pos); | |
540 | pos = os_strchr(pos, ','); | |
541 | if (pos == NULL) | |
542 | return -1; | |
543 | pos++; | |
544 | vi = atoi(pos); | |
545 | pos = os_strchr(pos, ','); | |
546 | if (pos == NULL) | |
547 | return -1; | |
548 | pos++; | |
549 | vo = atoi(pos); | |
550 | /* ignore max SP Length for now */ | |
551 | ||
552 | wpa_s->set_sta_uapsd = 1; | |
553 | wpa_s->sta_uapsd = 0; | |
554 | if (be) | |
555 | wpa_s->sta_uapsd |= BIT(0); | |
556 | if (bk) | |
557 | wpa_s->sta_uapsd |= BIT(1); | |
558 | if (vi) | |
559 | wpa_s->sta_uapsd |= BIT(2); | |
560 | if (vo) | |
561 | wpa_s->sta_uapsd |= BIT(3); | |
562 | } | |
b2ff1681 JM |
563 | } else if (os_strcasecmp(cmd, "ps") == 0) { |
564 | ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1); | |
9675ce35 JM |
565 | #ifdef CONFIG_WIFI_DISPLAY |
566 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { | |
bab6677a JM |
567 | int enabled = !!atoi(value); |
568 | if (enabled && !wpa_s->global->p2p) | |
569 | ret = -1; | |
570 | else | |
571 | wifi_display_enable(wpa_s->global, enabled); | |
9675ce35 | 572 | #endif /* CONFIG_WIFI_DISPLAY */ |
d445a5cd JM |
573 | } else if (os_strcasecmp(cmd, "bssid_filter") == 0) { |
574 | ret = set_bssid_filter(wpa_s, value); | |
6407f413 JM |
575 | } else if (os_strcasecmp(cmd, "disallow_aps") == 0) { |
576 | ret = set_disallow_aps(wpa_s, value); | |
2ec535fd JM |
577 | } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) { |
578 | wpa_s->no_keep_alive = !!atoi(value); | |
60b893df JM |
579 | #ifdef CONFIG_TESTING_OPTIONS |
580 | } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) { | |
581 | wpa_s->ext_mgmt_frame_handling = !!atoi(value); | |
9d4ff04a JM |
582 | } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) { |
583 | wpa_s->ext_eapol_frame_io = !!atoi(value); | |
584 | #ifdef CONFIG_AP | |
585 | if (wpa_s->ap_iface) { | |
586 | wpa_s->ap_iface->bss[0]->ext_eapol_frame_io = | |
587 | wpa_s->ext_eapol_frame_io; | |
588 | } | |
589 | #endif /* CONFIG_AP */ | |
1f94e4ee JM |
590 | } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) { |
591 | wpa_s->extra_roc_dur = atoi(value); | |
911942ee JM |
592 | } else if (os_strcasecmp(cmd, "test_failure") == 0) { |
593 | wpa_s->test_failure = atoi(value); | |
ed7820b4 IP |
594 | } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) { |
595 | wpa_s->p2p_go_csa_on_inv = !!atoi(value); | |
02adead5 MK |
596 | } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) { |
597 | wpa_s->ignore_auth_resp = !!atoi(value); | |
6ad37d73 | 598 | } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) { |
599 | wpa_s->ignore_assoc_disallow = !!atoi(value); | |
a483c6f1 | 600 | } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) { |
601 | wpa_s->reject_btm_req_reason = atoi(value); | |
c06fca04 JM |
602 | } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) { |
603 | os_free(wpa_s->get_pref_freq_list_override); | |
604 | if (!value[0]) | |
605 | wpa_s->get_pref_freq_list_override = NULL; | |
606 | else | |
607 | wpa_s->get_pref_freq_list_override = os_strdup(value); | |
60b893df | 608 | #endif /* CONFIG_TESTING_OPTIONS */ |
1120e452 JM |
609 | #ifndef CONFIG_NO_CONFIG_BLOBS |
610 | } else if (os_strcmp(cmd, "blob") == 0) { | |
611 | ret = wpas_ctrl_set_blob(wpa_s, value); | |
612 | #endif /* CONFIG_NO_CONFIG_BLOBS */ | |
209702d4 | 613 | } else if (os_strcasecmp(cmd, "setband") == 0) { |
844dfeb8 | 614 | ret = wpas_ctrl_set_band(wpa_s, value); |
92c6e2e3 DS |
615 | #ifdef CONFIG_MBO |
616 | } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) { | |
617 | ret = wpas_mbo_update_non_pref_chan(wpa_s, value); | |
e3394c0e JM |
618 | if (ret == 0) { |
619 | value[-1] = '='; | |
620 | wpa_config_process_global(wpa_s->conf, cmd, -1); | |
621 | } | |
016082e9 AS |
622 | } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) { |
623 | wpas_mbo_update_cell_capa(wpa_s, atoi(value)); | |
92c6e2e3 | 624 | #endif /* CONFIG_MBO */ |
4a742011 DS |
625 | } else if (os_strcasecmp(cmd, "lci") == 0) { |
626 | ret = wpas_ctrl_iface_set_lci(wpa_s, value); | |
2e4e4fb7 SD |
627 | } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) { |
628 | ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value)); | |
57c3a605 | 629 | } else if (os_strcasecmp(cmd, "relative_rssi") == 0) { |
630 | ret = wpas_ctrl_set_relative_rssi(wpa_s, value); | |
631 | } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) { | |
632 | ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value); | |
c6c41f6e JM |
633 | } else if (os_strcasecmp(cmd, "ric_ies") == 0) { |
634 | ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value); | |
611aea7d JM |
635 | } else { |
636 | value[-1] = '='; | |
637 | ret = wpa_config_process_global(wpa_s->conf, cmd, -1); | |
638 | if (ret == 0) | |
639 | wpa_supplicant_update_config(wpa_s); | |
640 | } | |
6fc6879b JM |
641 | |
642 | return ret; | |
643 | } | |
644 | ||
645 | ||
acec8d32 JM |
646 | static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s, |
647 | char *cmd, char *buf, size_t buflen) | |
648 | { | |
6ce937b8 | 649 | int res = -1; |
acec8d32 JM |
650 | |
651 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd); | |
652 | ||
653 | if (os_strcmp(cmd, "version") == 0) { | |
654 | res = os_snprintf(buf, buflen, "%s", VERSION_STR); | |
6ce937b8 DS |
655 | } else if (os_strcasecmp(cmd, "country") == 0) { |
656 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) | |
657 | res = os_snprintf(buf, buflen, "%c%c", | |
658 | wpa_s->conf->country[0], | |
659 | wpa_s->conf->country[1]); | |
9675ce35 JM |
660 | #ifdef CONFIG_WIFI_DISPLAY |
661 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { | |
bab6677a JM |
662 | int enabled; |
663 | if (wpa_s->global->p2p == NULL || | |
664 | wpa_s->global->p2p_disabled) | |
665 | enabled = 0; | |
666 | else | |
667 | enabled = wpa_s->global->wifi_display; | |
668 | res = os_snprintf(buf, buflen, "%d", enabled); | |
9675ce35 | 669 | #endif /* CONFIG_WIFI_DISPLAY */ |
fa7ae950 JM |
670 | #ifdef CONFIG_TESTING_GET_GTK |
671 | } else if (os_strcmp(cmd, "gtk") == 0) { | |
672 | if (wpa_s->last_gtk_len == 0) | |
673 | return -1; | |
674 | res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk, | |
675 | wpa_s->last_gtk_len); | |
676 | return res; | |
677 | #endif /* CONFIG_TESTING_GET_GTK */ | |
a1651451 JM |
678 | } else if (os_strcmp(cmd, "tls_library") == 0) { |
679 | res = tls_get_library_version(buf, buflen); | |
10263dc2 OO |
680 | } else { |
681 | res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen); | |
acec8d32 JM |
682 | } |
683 | ||
1f102d3b | 684 | if (os_snprintf_error(buflen, res)) |
6ce937b8 DS |
685 | return -1; |
686 | return res; | |
acec8d32 JM |
687 | } |
688 | ||
689 | ||
ec717917 | 690 | #ifdef IEEE8021X_EAPOL |
6fc6879b JM |
691 | static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s, |
692 | char *addr) | |
693 | { | |
694 | u8 bssid[ETH_ALEN]; | |
695 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
696 | ||
697 | if (hwaddr_aton(addr, bssid)) { | |
698 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address " | |
699 | "'%s'", addr); | |
700 | return -1; | |
701 | } | |
702 | ||
703 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid)); | |
704 | rsn_preauth_deinit(wpa_s->wpa); | |
705 | if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL)) | |
706 | return -1; | |
707 | ||
708 | return 0; | |
709 | } | |
ec717917 | 710 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
711 | |
712 | ||
713 | #ifdef CONFIG_PEERKEY | |
714 | /* MLME-STKSTART.request(peer) */ | |
715 | static int wpa_supplicant_ctrl_iface_stkstart( | |
716 | struct wpa_supplicant *wpa_s, char *addr) | |
717 | { | |
718 | u8 peer[ETH_ALEN]; | |
719 | ||
720 | if (hwaddr_aton(addr, peer)) { | |
721 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid " | |
a7b6c422 | 722 | "address '%s'", addr); |
6fc6879b JM |
723 | return -1; |
724 | } | |
725 | ||
726 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR, | |
727 | MAC2STR(peer)); | |
728 | ||
729 | return wpa_sm_stkstart(wpa_s->wpa, peer); | |
730 | } | |
731 | #endif /* CONFIG_PEERKEY */ | |
732 | ||
733 | ||
281ff0aa GP |
734 | #ifdef CONFIG_TDLS |
735 | ||
736 | static int wpa_supplicant_ctrl_iface_tdls_discover( | |
737 | struct wpa_supplicant *wpa_s, char *addr) | |
738 | { | |
739 | u8 peer[ETH_ALEN]; | |
2d565a61 | 740 | int ret; |
281ff0aa GP |
741 | |
742 | if (hwaddr_aton(addr, peer)) { | |
743 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid " | |
744 | "address '%s'", addr); | |
745 | return -1; | |
746 | } | |
747 | ||
748 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR, | |
749 | MAC2STR(peer)); | |
750 | ||
2d565a61 AN |
751 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
752 | ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer); | |
753 | else | |
754 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); | |
755 | ||
756 | return ret; | |
281ff0aa GP |
757 | } |
758 | ||
759 | ||
760 | static int wpa_supplicant_ctrl_iface_tdls_setup( | |
761 | struct wpa_supplicant *wpa_s, char *addr) | |
762 | { | |
763 | u8 peer[ETH_ALEN]; | |
94377fbc | 764 | int ret; |
281ff0aa GP |
765 | |
766 | if (hwaddr_aton(addr, peer)) { | |
767 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid " | |
768 | "address '%s'", addr); | |
769 | return -1; | |
770 | } | |
771 | ||
772 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR, | |
773 | MAC2STR(peer)); | |
774 | ||
800d5872 SD |
775 | if ((wpa_s->conf->tdls_external_control) && |
776 | wpa_tdls_is_external_setup(wpa_s->wpa)) | |
777 | return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | |
778 | ||
3887878e SD |
779 | wpa_tdls_remove(wpa_s->wpa, peer); |
780 | ||
781 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | |
782 | ret = wpa_tdls_start(wpa_s->wpa, peer); | |
783 | else | |
784 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); | |
2d565a61 | 785 | |
94377fbc | 786 | return ret; |
281ff0aa GP |
787 | } |
788 | ||
789 | ||
790 | static int wpa_supplicant_ctrl_iface_tdls_teardown( | |
791 | struct wpa_supplicant *wpa_s, char *addr) | |
792 | { | |
793 | u8 peer[ETH_ALEN]; | |
4ed8d954 | 794 | int ret; |
281ff0aa | 795 | |
38ddccae AN |
796 | if (os_strcmp(addr, "*") == 0) { |
797 | /* remove everyone */ | |
798 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *"); | |
799 | wpa_tdls_teardown_peers(wpa_s->wpa); | |
800 | return 0; | |
801 | } | |
802 | ||
281ff0aa GP |
803 | if (hwaddr_aton(addr, peer)) { |
804 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid " | |
805 | "address '%s'", addr); | |
806 | return -1; | |
807 | } | |
808 | ||
809 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR, | |
810 | MAC2STR(peer)); | |
811 | ||
800d5872 SD |
812 | if ((wpa_s->conf->tdls_external_control) && |
813 | wpa_tdls_is_external_setup(wpa_s->wpa)) | |
814 | return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); | |
815 | ||
4ed8d954 AS |
816 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
817 | ret = wpa_tdls_teardown_link( | |
818 | wpa_s->wpa, peer, | |
819 | WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED); | |
820 | else | |
821 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); | |
822 | ||
823 | return ret; | |
281ff0aa GP |
824 | } |
825 | ||
6e9375e4 DS |
826 | |
827 | static int ctrl_iface_get_capability_tdls( | |
828 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
829 | { | |
830 | int ret; | |
831 | ||
832 | ret = os_snprintf(buf, buflen, "%s\n", | |
833 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ? | |
834 | (wpa_s->drv_flags & | |
835 | WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ? | |
836 | "EXTERNAL" : "INTERNAL") : "UNSUPPORTED"); | |
7bdd8981 | 837 | if (os_snprintf_error(buflen, ret)) |
6e9375e4 DS |
838 | return -1; |
839 | return ret; | |
840 | } | |
841 | ||
6b90deae AN |
842 | |
843 | static int wpa_supplicant_ctrl_iface_tdls_chan_switch( | |
844 | struct wpa_supplicant *wpa_s, char *cmd) | |
845 | { | |
846 | u8 peer[ETH_ALEN]; | |
847 | struct hostapd_freq_params freq_params; | |
848 | u8 oper_class; | |
849 | char *pos, *end; | |
850 | ||
851 | if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { | |
852 | wpa_printf(MSG_INFO, | |
853 | "tdls_chanswitch: Only supported with external setup"); | |
854 | return -1; | |
855 | } | |
856 | ||
857 | os_memset(&freq_params, 0, sizeof(freq_params)); | |
858 | ||
859 | pos = os_strchr(cmd, ' '); | |
860 | if (pos == NULL) | |
861 | return -1; | |
862 | *pos++ = '\0'; | |
863 | ||
864 | oper_class = strtol(pos, &end, 10); | |
865 | if (pos == end) { | |
866 | wpa_printf(MSG_INFO, | |
867 | "tdls_chanswitch: Invalid op class provided"); | |
868 | return -1; | |
869 | } | |
870 | ||
871 | pos = end; | |
872 | freq_params.freq = atoi(pos); | |
873 | if (freq_params.freq == 0) { | |
874 | wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided"); | |
875 | return -1; | |
876 | } | |
877 | ||
878 | #define SET_FREQ_SETTING(str) \ | |
879 | do { \ | |
880 | const char *pos2 = os_strstr(pos, " " #str "="); \ | |
881 | if (pos2) { \ | |
882 | pos2 += sizeof(" " #str "=") - 1; \ | |
883 | freq_params.str = atoi(pos2); \ | |
884 | } \ | |
885 | } while (0) | |
886 | ||
887 | SET_FREQ_SETTING(center_freq1); | |
888 | SET_FREQ_SETTING(center_freq2); | |
889 | SET_FREQ_SETTING(bandwidth); | |
890 | SET_FREQ_SETTING(sec_channel_offset); | |
891 | #undef SET_FREQ_SETTING | |
892 | ||
893 | freq_params.ht_enabled = !!os_strstr(pos, " ht"); | |
894 | freq_params.vht_enabled = !!os_strstr(pos, " vht"); | |
895 | ||
896 | if (hwaddr_aton(cmd, peer)) { | |
897 | wpa_printf(MSG_DEBUG, | |
898 | "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'", | |
899 | cmd); | |
900 | return -1; | |
901 | } | |
902 | ||
903 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR | |
904 | " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s", | |
905 | MAC2STR(peer), oper_class, freq_params.freq, | |
906 | freq_params.center_freq1, freq_params.center_freq2, | |
907 | freq_params.bandwidth, freq_params.sec_channel_offset, | |
908 | freq_params.ht_enabled ? " HT" : "", | |
909 | freq_params.vht_enabled ? " VHT" : ""); | |
910 | ||
911 | return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class, | |
912 | &freq_params); | |
913 | } | |
914 | ||
915 | ||
916 | static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch( | |
917 | struct wpa_supplicant *wpa_s, char *cmd) | |
918 | { | |
919 | u8 peer[ETH_ALEN]; | |
920 | ||
921 | if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { | |
922 | wpa_printf(MSG_INFO, | |
923 | "tdls_chanswitch: Only supported with external setup"); | |
924 | return -1; | |
925 | } | |
926 | ||
927 | if (hwaddr_aton(cmd, peer)) { | |
928 | wpa_printf(MSG_DEBUG, | |
929 | "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'", | |
930 | cmd); | |
931 | return -1; | |
932 | } | |
933 | ||
934 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR, | |
935 | MAC2STR(peer)); | |
936 | ||
937 | return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer); | |
938 | } | |
939 | ||
4504621f OG |
940 | |
941 | static int wpa_supplicant_ctrl_iface_tdls_link_status( | |
942 | struct wpa_supplicant *wpa_s, const char *addr, | |
943 | char *buf, size_t buflen) | |
944 | { | |
945 | u8 peer[ETH_ALEN]; | |
946 | const char *tdls_status; | |
947 | int ret; | |
948 | ||
949 | if (hwaddr_aton(addr, peer)) { | |
950 | wpa_printf(MSG_DEBUG, | |
951 | "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'", | |
952 | addr); | |
953 | return -1; | |
954 | } | |
955 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR, | |
956 | MAC2STR(peer)); | |
957 | ||
958 | tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer); | |
959 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status); | |
960 | ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status); | |
961 | if (os_snprintf_error(buflen, ret)) | |
962 | return -1; | |
963 | ||
964 | return ret; | |
965 | } | |
966 | ||
281ff0aa GP |
967 | #endif /* CONFIG_TDLS */ |
968 | ||
969 | ||
eb2f2088 MB |
970 | static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd) |
971 | { | |
972 | char *token, *context = NULL; | |
973 | struct wmm_ac_ts_setup_params params = { | |
974 | .tsid = 0xff, | |
975 | .direction = 0xff, | |
976 | }; | |
977 | ||
978 | while ((token = str_token(cmd, " ", &context))) { | |
979 | if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 || | |
980 | sscanf(token, "up=%i", ¶ms.user_priority) == 1 || | |
981 | sscanf(token, "nominal_msdu_size=%i", | |
982 | ¶ms.nominal_msdu_size) == 1 || | |
983 | sscanf(token, "mean_data_rate=%i", | |
984 | ¶ms.mean_data_rate) == 1 || | |
985 | sscanf(token, "min_phy_rate=%i", | |
986 | ¶ms.minimum_phy_rate) == 1 || | |
987 | sscanf(token, "sba=%i", | |
988 | ¶ms.surplus_bandwidth_allowance) == 1) | |
989 | continue; | |
990 | ||
991 | if (os_strcasecmp(token, "downlink") == 0) { | |
992 | params.direction = WMM_TSPEC_DIRECTION_DOWNLINK; | |
993 | } else if (os_strcasecmp(token, "uplink") == 0) { | |
994 | params.direction = WMM_TSPEC_DIRECTION_UPLINK; | |
995 | } else if (os_strcasecmp(token, "bidi") == 0) { | |
996 | params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL; | |
997 | } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) { | |
998 | params.fixed_nominal_msdu = 1; | |
999 | } else { | |
1000 | wpa_printf(MSG_DEBUG, | |
1001 | "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'", | |
1002 | token); | |
1003 | return -1; | |
1004 | } | |
1005 | ||
1006 | } | |
1007 | ||
1008 | return wpas_wmm_ac_addts(wpa_s, ¶ms); | |
1009 | } | |
1010 | ||
1011 | ||
1012 | static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd) | |
1013 | { | |
1014 | u8 tsid = atoi(cmd); | |
1015 | ||
1016 | return wpas_wmm_ac_delts(wpa_s, tsid); | |
1017 | } | |
1018 | ||
1019 | ||
6fc6879b JM |
1020 | #ifdef CONFIG_IEEE80211R |
1021 | static int wpa_supplicant_ctrl_iface_ft_ds( | |
1022 | struct wpa_supplicant *wpa_s, char *addr) | |
1023 | { | |
1024 | u8 target_ap[ETH_ALEN]; | |
76b7981d JM |
1025 | struct wpa_bss *bss; |
1026 | const u8 *mdie; | |
6fc6879b JM |
1027 | |
1028 | if (hwaddr_aton(addr, target_ap)) { | |
1029 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid " | |
a7b6c422 | 1030 | "address '%s'", addr); |
6fc6879b JM |
1031 | return -1; |
1032 | } | |
1033 | ||
1034 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap)); | |
1035 | ||
76b7981d JM |
1036 | bss = wpa_bss_get_bssid(wpa_s, target_ap); |
1037 | if (bss) | |
1038 | mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); | |
1039 | else | |
1040 | mdie = NULL; | |
1041 | ||
1042 | return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie); | |
6fc6879b JM |
1043 | } |
1044 | #endif /* CONFIG_IEEE80211R */ | |
1045 | ||
1046 | ||
fcc60db4 JM |
1047 | #ifdef CONFIG_WPS |
1048 | static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s, | |
1049 | char *cmd) | |
1050 | { | |
3ec97afe | 1051 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
ceb34f25 | 1052 | #ifdef CONFIG_P2P |
634ce802 | 1053 | u8 p2p_dev_addr[ETH_ALEN]; |
ceb34f25 | 1054 | #endif /* CONFIG_P2P */ |
634ce802 JM |
1055 | #ifdef CONFIG_AP |
1056 | u8 *_p2p_dev_addr = NULL; | |
1057 | #endif /* CONFIG_AP */ | |
fcc60db4 | 1058 | |
d601247c | 1059 | if (cmd == NULL || os_strcmp(cmd, "any") == 0) { |
3ec97afe | 1060 | _bssid = NULL; |
d601247c JM |
1061 | #ifdef CONFIG_P2P |
1062 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | |
1063 | if (hwaddr_aton(cmd + 13, p2p_dev_addr)) { | |
1064 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid " | |
1065 | "P2P Device Address '%s'", | |
1066 | cmd + 13); | |
1067 | return -1; | |
1068 | } | |
1069 | _p2p_dev_addr = p2p_dev_addr; | |
1070 | #endif /* CONFIG_P2P */ | |
1071 | } else if (hwaddr_aton(cmd, bssid)) { | |
fcc60db4 JM |
1072 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'", |
1073 | cmd); | |
1074 | return -1; | |
1075 | } | |
1076 | ||
3ec97afe JM |
1077 | #ifdef CONFIG_AP |
1078 | if (wpa_s->ap_iface) | |
d601247c | 1079 | return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr); |
3ec97afe JM |
1080 | #endif /* CONFIG_AP */ |
1081 | ||
9fa243b2 | 1082 | return wpas_wps_start_pbc(wpa_s, _bssid, 0); |
fcc60db4 JM |
1083 | } |
1084 | ||
1085 | ||
1086 | static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, | |
1087 | char *cmd, char *buf, | |
1088 | size_t buflen) | |
1089 | { | |
1090 | u8 bssid[ETH_ALEN], *_bssid = bssid; | |
1091 | char *pin; | |
1092 | int ret; | |
1093 | ||
1094 | pin = os_strchr(cmd, ' '); | |
1095 | if (pin) | |
1096 | *pin++ = '\0'; | |
1097 | ||
1098 | if (os_strcmp(cmd, "any") == 0) | |
1099 | _bssid = NULL; | |
98aa7ca5 | 1100 | else if (os_strcmp(cmd, "get") == 0) { |
98a516ea NL |
1101 | if (wps_generate_pin((unsigned int *) &ret) < 0) |
1102 | return -1; | |
98aa7ca5 JM |
1103 | goto done; |
1104 | } else if (hwaddr_aton(cmd, bssid)) { | |
3c1e2765 | 1105 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'", |
fcc60db4 JM |
1106 | cmd); |
1107 | return -1; | |
1108 | } | |
1109 | ||
3ec97afe | 1110 | #ifdef CONFIG_AP |
c423708f JM |
1111 | if (wpa_s->ap_iface) { |
1112 | int timeout = 0; | |
1113 | char *pos; | |
1114 | ||
1115 | if (pin) { | |
1116 | pos = os_strchr(pin, ' '); | |
1117 | if (pos) { | |
1118 | *pos++ = '\0'; | |
1119 | timeout = atoi(pos); | |
1120 | } | |
1121 | } | |
1122 | ||
3ec97afe | 1123 | return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, |
c423708f JM |
1124 | buf, buflen, timeout); |
1125 | } | |
3ec97afe JM |
1126 | #endif /* CONFIG_AP */ |
1127 | ||
fcc60db4 | 1128 | if (pin) { |
3c5126a4 JM |
1129 | ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0, |
1130 | DEV_PW_DEFAULT); | |
fcc60db4 JM |
1131 | if (ret < 0) |
1132 | return -1; | |
1133 | ret = os_snprintf(buf, buflen, "%s", pin); | |
d85e1fc8 | 1134 | if (os_snprintf_error(buflen, ret)) |
fcc60db4 JM |
1135 | return -1; |
1136 | return ret; | |
1137 | } | |
1138 | ||
3c5126a4 | 1139 | ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT); |
fcc60db4 JM |
1140 | if (ret < 0) |
1141 | return -1; | |
1142 | ||
98aa7ca5 | 1143 | done: |
fcc60db4 JM |
1144 | /* Return the generated PIN */ |
1145 | ret = os_snprintf(buf, buflen, "%08d", ret); | |
d85e1fc8 | 1146 | if (os_snprintf_error(buflen, ret)) |
fcc60db4 JM |
1147 | return -1; |
1148 | return ret; | |
1149 | } | |
1150 | ||
1151 | ||
3981cb3c JM |
1152 | static int wpa_supplicant_ctrl_iface_wps_check_pin( |
1153 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
1154 | { | |
1155 | char pin[9]; | |
1156 | size_t len; | |
1157 | char *pos; | |
1158 | int ret; | |
1159 | ||
1160 | wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN", | |
1161 | (u8 *) cmd, os_strlen(cmd)); | |
1162 | for (pos = cmd, len = 0; *pos != '\0'; pos++) { | |
1163 | if (*pos < '0' || *pos > '9') | |
1164 | continue; | |
1165 | pin[len++] = *pos; | |
1166 | if (len == 9) { | |
1167 | wpa_printf(MSG_DEBUG, "WPS: Too long PIN"); | |
1168 | return -1; | |
1169 | } | |
1170 | } | |
1171 | if (len != 4 && len != 8) { | |
1172 | wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len); | |
1173 | return -1; | |
1174 | } | |
1175 | pin[len] = '\0'; | |
1176 | ||
1177 | if (len == 8) { | |
1178 | unsigned int pin_val; | |
1179 | pin_val = atoi(pin); | |
1180 | if (!wps_pin_valid(pin_val)) { | |
1181 | wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit"); | |
1182 | ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n"); | |
d85e1fc8 | 1183 | if (os_snprintf_error(buflen, ret)) |
3981cb3c JM |
1184 | return -1; |
1185 | return ret; | |
1186 | } | |
1187 | } | |
1188 | ||
1189 | ret = os_snprintf(buf, buflen, "%s", pin); | |
d85e1fc8 | 1190 | if (os_snprintf_error(buflen, ret)) |
3981cb3c JM |
1191 | return -1; |
1192 | ||
1193 | return ret; | |
1194 | } | |
1195 | ||
1196 | ||
71892384 | 1197 | #ifdef CONFIG_WPS_NFC |
3f2c8ba6 JM |
1198 | |
1199 | static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s, | |
1200 | char *cmd) | |
1201 | { | |
1202 | u8 bssid[ETH_ALEN], *_bssid = bssid; | |
1203 | ||
1204 | if (cmd == NULL || cmd[0] == '\0') | |
1205 | _bssid = NULL; | |
1206 | else if (hwaddr_aton(cmd, bssid)) | |
1207 | return -1; | |
1208 | ||
23318bea | 1209 | return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL, |
91a65018 | 1210 | 0, 0); |
3f2c8ba6 JM |
1211 | } |
1212 | ||
1213 | ||
bbf41865 JM |
1214 | static int wpa_supplicant_ctrl_iface_wps_nfc_config_token( |
1215 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
1216 | { | |
1217 | int ndef; | |
1218 | struct wpabuf *buf; | |
1219 | int res; | |
88c8bf31 | 1220 | char *pos; |
bbf41865 | 1221 | |
88c8bf31 JM |
1222 | pos = os_strchr(cmd, ' '); |
1223 | if (pos) | |
1224 | *pos++ = '\0'; | |
bbf41865 JM |
1225 | if (os_strcmp(cmd, "WPS") == 0) |
1226 | ndef = 0; | |
1227 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1228 | ndef = 1; | |
1229 | else | |
1230 | return -1; | |
1231 | ||
88c8bf31 | 1232 | buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos); |
bbf41865 JM |
1233 | if (buf == NULL) |
1234 | return -1; | |
1235 | ||
1236 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1237 | wpabuf_len(buf)); | |
1238 | reply[res++] = '\n'; | |
1239 | reply[res] = '\0'; | |
1240 | ||
1241 | wpabuf_free(buf); | |
1242 | ||
1243 | return res; | |
1244 | } | |
1245 | ||
1246 | ||
3f2c8ba6 JM |
1247 | static int wpa_supplicant_ctrl_iface_wps_nfc_token( |
1248 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
1249 | { | |
1250 | int ndef; | |
1251 | struct wpabuf *buf; | |
1252 | int res; | |
1253 | ||
1254 | if (os_strcmp(cmd, "WPS") == 0) | |
1255 | ndef = 0; | |
1256 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1257 | ndef = 1; | |
1258 | else | |
1259 | return -1; | |
1260 | ||
1261 | buf = wpas_wps_nfc_token(wpa_s, ndef); | |
1262 | if (buf == NULL) | |
1263 | return -1; | |
1264 | ||
1265 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1266 | wpabuf_len(buf)); | |
1267 | reply[res++] = '\n'; | |
1268 | reply[res] = '\0'; | |
1269 | ||
1270 | wpabuf_free(buf); | |
1271 | ||
1272 | return res; | |
1273 | } | |
d7645d23 JM |
1274 | |
1275 | ||
1276 | static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read( | |
1277 | struct wpa_supplicant *wpa_s, char *pos) | |
1278 | { | |
1279 | size_t len; | |
1280 | struct wpabuf *buf; | |
1281 | int ret; | |
b56f6c88 JM |
1282 | char *freq; |
1283 | int forced_freq = 0; | |
1284 | ||
1285 | freq = strstr(pos, " freq="); | |
1286 | if (freq) { | |
1287 | *freq = '\0'; | |
1288 | freq += 6; | |
1289 | forced_freq = atoi(freq); | |
1290 | } | |
d7645d23 JM |
1291 | |
1292 | len = os_strlen(pos); | |
1293 | if (len & 0x01) | |
1294 | return -1; | |
1295 | len /= 2; | |
1296 | ||
1297 | buf = wpabuf_alloc(len); | |
1298 | if (buf == NULL) | |
1299 | return -1; | |
1300 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { | |
1301 | wpabuf_free(buf); | |
1302 | return -1; | |
1303 | } | |
1304 | ||
b56f6c88 | 1305 | ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq); |
d7645d23 JM |
1306 | wpabuf_free(buf); |
1307 | ||
1308 | return ret; | |
1309 | } | |
71892384 | 1310 | |
e65552dd JM |
1311 | |
1312 | static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s, | |
bbaaaee1 | 1313 | char *reply, size_t max_len, |
41f9ffb6 | 1314 | int ndef) |
e65552dd JM |
1315 | { |
1316 | struct wpabuf *buf; | |
1317 | int res; | |
1318 | ||
41f9ffb6 | 1319 | buf = wpas_wps_nfc_handover_req(wpa_s, ndef); |
e65552dd JM |
1320 | if (buf == NULL) |
1321 | return -1; | |
1322 | ||
1323 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1324 | wpabuf_len(buf)); | |
1325 | reply[res++] = '\n'; | |
1326 | reply[res] = '\0'; | |
1327 | ||
1328 | wpabuf_free(buf); | |
1329 | ||
1330 | return res; | |
1331 | } | |
1332 | ||
1333 | ||
88853aed | 1334 | #ifdef CONFIG_P2P |
93588780 JM |
1335 | static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s, |
1336 | char *reply, size_t max_len, | |
1337 | int ndef) | |
1338 | { | |
1339 | struct wpabuf *buf; | |
1340 | int res; | |
1341 | ||
1342 | buf = wpas_p2p_nfc_handover_req(wpa_s, ndef); | |
1343 | if (buf == NULL) { | |
1344 | wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request"); | |
1345 | return -1; | |
1346 | } | |
1347 | ||
1348 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1349 | wpabuf_len(buf)); | |
1350 | reply[res++] = '\n'; | |
1351 | reply[res] = '\0'; | |
1352 | ||
1353 | wpabuf_free(buf); | |
1354 | ||
1355 | return res; | |
1356 | } | |
88853aed | 1357 | #endif /* CONFIG_P2P */ |
93588780 JM |
1358 | |
1359 | ||
e65552dd JM |
1360 | static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s, |
1361 | char *cmd, char *reply, | |
1362 | size_t max_len) | |
1363 | { | |
1364 | char *pos; | |
41f9ffb6 | 1365 | int ndef; |
e65552dd JM |
1366 | |
1367 | pos = os_strchr(cmd, ' '); | |
1368 | if (pos == NULL) | |
1369 | return -1; | |
1370 | *pos++ = '\0'; | |
1371 | ||
41f9ffb6 JM |
1372 | if (os_strcmp(cmd, "WPS") == 0) |
1373 | ndef = 0; | |
1374 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1375 | ndef = 1; | |
1376 | else | |
e65552dd JM |
1377 | return -1; |
1378 | ||
bbaaaee1 | 1379 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
41f9ffb6 JM |
1380 | if (!ndef) |
1381 | return -1; | |
bbaaaee1 | 1382 | return wpas_ctrl_nfc_get_handover_req_wps( |
41f9ffb6 | 1383 | wpa_s, reply, max_len, ndef); |
e65552dd JM |
1384 | } |
1385 | ||
88853aed | 1386 | #ifdef CONFIG_P2P |
93588780 JM |
1387 | if (os_strcmp(pos, "P2P-CR") == 0) { |
1388 | return wpas_ctrl_nfc_get_handover_req_p2p( | |
1389 | wpa_s, reply, max_len, ndef); | |
1390 | } | |
88853aed | 1391 | #endif /* CONFIG_P2P */ |
93588780 | 1392 | |
e65552dd JM |
1393 | return -1; |
1394 | } | |
1395 | ||
1396 | ||
1397 | static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s, | |
5ab9a6a5 | 1398 | char *reply, size_t max_len, |
f3f2ba2e | 1399 | int ndef, int cr, char *uuid) |
e65552dd JM |
1400 | { |
1401 | struct wpabuf *buf; | |
1402 | int res; | |
1403 | ||
f3f2ba2e | 1404 | buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid); |
e65552dd JM |
1405 | if (buf == NULL) |
1406 | return -1; | |
1407 | ||
1408 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1409 | wpabuf_len(buf)); | |
1410 | reply[res++] = '\n'; | |
1411 | reply[res] = '\0'; | |
1412 | ||
1413 | wpabuf_free(buf); | |
1414 | ||
1415 | return res; | |
1416 | } | |
1417 | ||
1418 | ||
88853aed | 1419 | #ifdef CONFIG_P2P |
93588780 JM |
1420 | static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s, |
1421 | char *reply, size_t max_len, | |
1422 | int ndef, int tag) | |
1423 | { | |
1424 | struct wpabuf *buf; | |
1425 | int res; | |
1426 | ||
1427 | buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag); | |
1428 | if (buf == NULL) | |
1429 | return -1; | |
1430 | ||
1431 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1432 | wpabuf_len(buf)); | |
1433 | reply[res++] = '\n'; | |
1434 | reply[res] = '\0'; | |
1435 | ||
1436 | wpabuf_free(buf); | |
1437 | ||
1438 | return res; | |
1439 | } | |
88853aed | 1440 | #endif /* CONFIG_P2P */ |
93588780 JM |
1441 | |
1442 | ||
e65552dd JM |
1443 | static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s, |
1444 | char *cmd, char *reply, | |
1445 | size_t max_len) | |
1446 | { | |
f3f2ba2e | 1447 | char *pos, *pos2; |
5ab9a6a5 | 1448 | int ndef; |
e65552dd JM |
1449 | |
1450 | pos = os_strchr(cmd, ' '); | |
1451 | if (pos == NULL) | |
1452 | return -1; | |
1453 | *pos++ = '\0'; | |
1454 | ||
5ab9a6a5 JM |
1455 | if (os_strcmp(cmd, "WPS") == 0) |
1456 | ndef = 0; | |
1457 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1458 | ndef = 1; | |
1459 | else | |
e65552dd JM |
1460 | return -1; |
1461 | ||
f3f2ba2e JM |
1462 | pos2 = os_strchr(pos, ' '); |
1463 | if (pos2) | |
1464 | *pos2++ = '\0'; | |
5ab9a6a5 | 1465 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
93588780 JM |
1466 | if (!ndef) |
1467 | return -1; | |
5ab9a6a5 JM |
1468 | return wpas_ctrl_nfc_get_handover_sel_wps( |
1469 | wpa_s, reply, max_len, ndef, | |
f3f2ba2e | 1470 | os_strcmp(pos, "WPS-CR") == 0, pos2); |
e65552dd JM |
1471 | } |
1472 | ||
88853aed | 1473 | #ifdef CONFIG_P2P |
93588780 JM |
1474 | if (os_strcmp(pos, "P2P-CR") == 0) { |
1475 | return wpas_ctrl_nfc_get_handover_sel_p2p( | |
1476 | wpa_s, reply, max_len, ndef, 0); | |
1477 | } | |
1478 | ||
1479 | if (os_strcmp(pos, "P2P-CR-TAG") == 0) { | |
1480 | return wpas_ctrl_nfc_get_handover_sel_p2p( | |
1481 | wpa_s, reply, max_len, ndef, 1); | |
1482 | } | |
88853aed | 1483 | #endif /* CONFIG_P2P */ |
93588780 | 1484 | |
e65552dd JM |
1485 | return -1; |
1486 | } | |
1487 | ||
1488 | ||
e4758827 JM |
1489 | static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s, |
1490 | char *cmd) | |
1491 | { | |
1492 | size_t len; | |
1493 | struct wpabuf *req, *sel; | |
1494 | int ret; | |
1495 | char *pos, *role, *type, *pos2; | |
88853aed | 1496 | #ifdef CONFIG_P2P |
b56f6c88 JM |
1497 | char *freq; |
1498 | int forced_freq = 0; | |
1499 | ||
1500 | freq = strstr(cmd, " freq="); | |
1501 | if (freq) { | |
1502 | *freq = '\0'; | |
1503 | freq += 6; | |
1504 | forced_freq = atoi(freq); | |
1505 | } | |
88853aed | 1506 | #endif /* CONFIG_P2P */ |
e4758827 JM |
1507 | |
1508 | role = cmd; | |
1509 | pos = os_strchr(role, ' '); | |
73127764 JM |
1510 | if (pos == NULL) { |
1511 | wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report"); | |
e4758827 | 1512 | return -1; |
73127764 | 1513 | } |
e4758827 JM |
1514 | *pos++ = '\0'; |
1515 | ||
1516 | type = pos; | |
1517 | pos = os_strchr(type, ' '); | |
73127764 JM |
1518 | if (pos == NULL) { |
1519 | wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report"); | |
e4758827 | 1520 | return -1; |
73127764 | 1521 | } |
e4758827 JM |
1522 | *pos++ = '\0'; |
1523 | ||
1524 | pos2 = os_strchr(pos, ' '); | |
73127764 JM |
1525 | if (pos2 == NULL) { |
1526 | wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report"); | |
e4758827 | 1527 | return -1; |
73127764 | 1528 | } |
e4758827 JM |
1529 | *pos2++ = '\0'; |
1530 | ||
1531 | len = os_strlen(pos); | |
73127764 JM |
1532 | if (len & 0x01) { |
1533 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report"); | |
e4758827 | 1534 | return -1; |
73127764 | 1535 | } |
e4758827 JM |
1536 | len /= 2; |
1537 | ||
1538 | req = wpabuf_alloc(len); | |
73127764 JM |
1539 | if (req == NULL) { |
1540 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message"); | |
e4758827 | 1541 | return -1; |
73127764 | 1542 | } |
e4758827 | 1543 | if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) { |
73127764 | 1544 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report"); |
e4758827 JM |
1545 | wpabuf_free(req); |
1546 | return -1; | |
1547 | } | |
1548 | ||
1549 | len = os_strlen(pos2); | |
1550 | if (len & 0x01) { | |
73127764 | 1551 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report"); |
e4758827 JM |
1552 | wpabuf_free(req); |
1553 | return -1; | |
1554 | } | |
1555 | len /= 2; | |
1556 | ||
1557 | sel = wpabuf_alloc(len); | |
1558 | if (sel == NULL) { | |
73127764 | 1559 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message"); |
e4758827 JM |
1560 | wpabuf_free(req); |
1561 | return -1; | |
1562 | } | |
1563 | if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) { | |
73127764 | 1564 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report"); |
e4758827 JM |
1565 | wpabuf_free(req); |
1566 | wpabuf_free(sel); | |
1567 | return -1; | |
1568 | } | |
1569 | ||
73127764 JM |
1570 | wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d", |
1571 | role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel)); | |
1572 | ||
e4758827 JM |
1573 | if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) { |
1574 | ret = wpas_wps_nfc_report_handover(wpa_s, req, sel); | |
88853aed | 1575 | #ifdef CONFIG_AP |
d9507936 JM |
1576 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) |
1577 | { | |
1578 | ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel); | |
50d1f890 JM |
1579 | if (ret < 0) |
1580 | ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel); | |
88853aed JM |
1581 | #endif /* CONFIG_AP */ |
1582 | #ifdef CONFIG_P2P | |
db6ae69e JM |
1583 | } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0) |
1584 | { | |
b56f6c88 | 1585 | ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0); |
db6ae69e JM |
1586 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0) |
1587 | { | |
b56f6c88 JM |
1588 | ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel, |
1589 | forced_freq); | |
88853aed | 1590 | #endif /* CONFIG_P2P */ |
e4758827 JM |
1591 | } else { |
1592 | wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover " | |
1593 | "reported: role=%s type=%s", role, type); | |
1594 | ret = -1; | |
1595 | } | |
1596 | wpabuf_free(req); | |
1597 | wpabuf_free(sel); | |
1598 | ||
73127764 JM |
1599 | if (ret) |
1600 | wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages"); | |
1601 | ||
e4758827 JM |
1602 | return ret; |
1603 | } | |
1604 | ||
71892384 | 1605 | #endif /* CONFIG_WPS_NFC */ |
46bdb83a MH |
1606 | |
1607 | ||
fcc60db4 JM |
1608 | static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s, |
1609 | char *cmd) | |
1610 | { | |
129eb428 | 1611 | u8 bssid[ETH_ALEN]; |
fcc60db4 | 1612 | char *pin; |
52eb293d JM |
1613 | char *new_ssid; |
1614 | char *new_auth; | |
1615 | char *new_encr; | |
1616 | char *new_key; | |
1617 | struct wps_new_ap_settings ap; | |
fcc60db4 JM |
1618 | |
1619 | pin = os_strchr(cmd, ' '); | |
1620 | if (pin == NULL) | |
1621 | return -1; | |
1622 | *pin++ = '\0'; | |
1623 | ||
129eb428 | 1624 | if (hwaddr_aton(cmd, bssid)) { |
fcc60db4 JM |
1625 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'", |
1626 | cmd); | |
1627 | return -1; | |
1628 | } | |
1629 | ||
52eb293d JM |
1630 | new_ssid = os_strchr(pin, ' '); |
1631 | if (new_ssid == NULL) | |
129eb428 | 1632 | return wpas_wps_start_reg(wpa_s, bssid, pin, NULL); |
52eb293d JM |
1633 | *new_ssid++ = '\0'; |
1634 | ||
1635 | new_auth = os_strchr(new_ssid, ' '); | |
1636 | if (new_auth == NULL) | |
1637 | return -1; | |
1638 | *new_auth++ = '\0'; | |
1639 | ||
1640 | new_encr = os_strchr(new_auth, ' '); | |
1641 | if (new_encr == NULL) | |
1642 | return -1; | |
1643 | *new_encr++ = '\0'; | |
1644 | ||
1645 | new_key = os_strchr(new_encr, ' '); | |
1646 | if (new_key == NULL) | |
1647 | return -1; | |
1648 | *new_key++ = '\0'; | |
1649 | ||
1650 | os_memset(&ap, 0, sizeof(ap)); | |
1651 | ap.ssid_hex = new_ssid; | |
1652 | ap.auth = new_auth; | |
1653 | ap.encr = new_encr; | |
1654 | ap.key_hex = new_key; | |
129eb428 | 1655 | return wpas_wps_start_reg(wpa_s, bssid, pin, &ap); |
fcc60db4 | 1656 | } |
72df2f5f JM |
1657 | |
1658 | ||
70d84f11 JM |
1659 | #ifdef CONFIG_AP |
1660 | static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s, | |
1661 | char *cmd, char *buf, | |
1662 | size_t buflen) | |
1663 | { | |
1664 | int timeout = 300; | |
1665 | char *pos; | |
1666 | const char *pin_txt; | |
1667 | ||
1668 | if (!wpa_s->ap_iface) | |
1669 | return -1; | |
1670 | ||
1671 | pos = os_strchr(cmd, ' '); | |
1672 | if (pos) | |
1673 | *pos++ = '\0'; | |
1674 | ||
1675 | if (os_strcmp(cmd, "disable") == 0) { | |
1676 | wpas_wps_ap_pin_disable(wpa_s); | |
1677 | return os_snprintf(buf, buflen, "OK\n"); | |
1678 | } | |
1679 | ||
1680 | if (os_strcmp(cmd, "random") == 0) { | |
1681 | if (pos) | |
1682 | timeout = atoi(pos); | |
1683 | pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout); | |
1684 | if (pin_txt == NULL) | |
1685 | return -1; | |
1686 | return os_snprintf(buf, buflen, "%s", pin_txt); | |
1687 | } | |
1688 | ||
1689 | if (os_strcmp(cmd, "get") == 0) { | |
1690 | pin_txt = wpas_wps_ap_pin_get(wpa_s); | |
1691 | if (pin_txt == NULL) | |
1692 | return -1; | |
1693 | return os_snprintf(buf, buflen, "%s", pin_txt); | |
1694 | } | |
1695 | ||
1696 | if (os_strcmp(cmd, "set") == 0) { | |
1697 | char *pin; | |
1698 | if (pos == NULL) | |
1699 | return -1; | |
1700 | pin = pos; | |
1701 | pos = os_strchr(pos, ' '); | |
1702 | if (pos) { | |
1703 | *pos++ = '\0'; | |
1704 | timeout = atoi(pos); | |
1705 | } | |
1706 | if (os_strlen(pin) > buflen) | |
1707 | return -1; | |
1708 | if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0) | |
1709 | return -1; | |
1710 | return os_snprintf(buf, buflen, "%s", pin); | |
1711 | } | |
1712 | ||
1713 | return -1; | |
1714 | } | |
1715 | #endif /* CONFIG_AP */ | |
1716 | ||
1717 | ||
72df2f5f JM |
1718 | #ifdef CONFIG_WPS_ER |
1719 | static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s, | |
1720 | char *cmd) | |
1721 | { | |
31fcea93 JM |
1722 | char *uuid = cmd, *pin, *pos; |
1723 | u8 addr_buf[ETH_ALEN], *addr = NULL; | |
72df2f5f JM |
1724 | pin = os_strchr(uuid, ' '); |
1725 | if (pin == NULL) | |
1726 | return -1; | |
1727 | *pin++ = '\0'; | |
31fcea93 JM |
1728 | pos = os_strchr(pin, ' '); |
1729 | if (pos) { | |
1730 | *pos++ = '\0'; | |
1731 | if (hwaddr_aton(pos, addr_buf) == 0) | |
1732 | addr = addr_buf; | |
1733 | } | |
1734 | return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin); | |
72df2f5f | 1735 | } |
e64dcfd5 JM |
1736 | |
1737 | ||
1738 | static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s, | |
1739 | char *cmd) | |
1740 | { | |
1741 | char *uuid = cmd, *pin; | |
1742 | pin = os_strchr(uuid, ' '); | |
1743 | if (pin == NULL) | |
1744 | return -1; | |
1745 | *pin++ = '\0'; | |
1746 | return wpas_wps_er_learn(wpa_s, uuid, pin); | |
1747 | } | |
7d6640a6 JM |
1748 | |
1749 | ||
ef10f473 JM |
1750 | static int wpa_supplicant_ctrl_iface_wps_er_set_config( |
1751 | struct wpa_supplicant *wpa_s, char *cmd) | |
1752 | { | |
1753 | char *uuid = cmd, *id; | |
1754 | id = os_strchr(uuid, ' '); | |
1755 | if (id == NULL) | |
1756 | return -1; | |
1757 | *id++ = '\0'; | |
1758 | return wpas_wps_er_set_config(wpa_s, uuid, atoi(id)); | |
1759 | } | |
1760 | ||
1761 | ||
7d6640a6 JM |
1762 | static int wpa_supplicant_ctrl_iface_wps_er_config( |
1763 | struct wpa_supplicant *wpa_s, char *cmd) | |
1764 | { | |
1765 | char *pin; | |
1766 | char *new_ssid; | |
1767 | char *new_auth; | |
1768 | char *new_encr; | |
1769 | char *new_key; | |
1770 | struct wps_new_ap_settings ap; | |
1771 | ||
1772 | pin = os_strchr(cmd, ' '); | |
1773 | if (pin == NULL) | |
1774 | return -1; | |
1775 | *pin++ = '\0'; | |
1776 | ||
1777 | new_ssid = os_strchr(pin, ' '); | |
1778 | if (new_ssid == NULL) | |
1779 | return -1; | |
1780 | *new_ssid++ = '\0'; | |
1781 | ||
1782 | new_auth = os_strchr(new_ssid, ' '); | |
1783 | if (new_auth == NULL) | |
1784 | return -1; | |
1785 | *new_auth++ = '\0'; | |
1786 | ||
1787 | new_encr = os_strchr(new_auth, ' '); | |
1788 | if (new_encr == NULL) | |
1789 | return -1; | |
1790 | *new_encr++ = '\0'; | |
1791 | ||
1792 | new_key = os_strchr(new_encr, ' '); | |
1793 | if (new_key == NULL) | |
1794 | return -1; | |
1795 | *new_key++ = '\0'; | |
1796 | ||
1797 | os_memset(&ap, 0, sizeof(ap)); | |
1798 | ap.ssid_hex = new_ssid; | |
1799 | ap.auth = new_auth; | |
1800 | ap.encr = new_encr; | |
1801 | ap.key_hex = new_key; | |
1802 | return wpas_wps_er_config(wpa_s, cmd, pin, &ap); | |
1803 | } | |
1cea09a9 JM |
1804 | |
1805 | ||
1806 | #ifdef CONFIG_WPS_NFC | |
1807 | static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | |
1808 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
1809 | { | |
1810 | int ndef; | |
1811 | struct wpabuf *buf; | |
1812 | int res; | |
1813 | char *uuid; | |
1814 | ||
1815 | uuid = os_strchr(cmd, ' '); | |
1816 | if (uuid == NULL) | |
1817 | return -1; | |
1818 | *uuid++ = '\0'; | |
1819 | ||
1820 | if (os_strcmp(cmd, "WPS") == 0) | |
1821 | ndef = 0; | |
1822 | else if (os_strcmp(cmd, "NDEF") == 0) | |
1823 | ndef = 1; | |
1824 | else | |
1825 | return -1; | |
1826 | ||
1827 | buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid); | |
1828 | if (buf == NULL) | |
1829 | return -1; | |
1830 | ||
1831 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), | |
1832 | wpabuf_len(buf)); | |
1833 | reply[res++] = '\n'; | |
1834 | reply[res] = '\0'; | |
1835 | ||
1836 | wpabuf_free(buf); | |
1837 | ||
1838 | return res; | |
1839 | } | |
1840 | #endif /* CONFIG_WPS_NFC */ | |
72df2f5f JM |
1841 | #endif /* CONFIG_WPS_ER */ |
1842 | ||
fcc60db4 JM |
1843 | #endif /* CONFIG_WPS */ |
1844 | ||
1845 | ||
11ef8d35 JM |
1846 | #ifdef CONFIG_IBSS_RSN |
1847 | static int wpa_supplicant_ctrl_iface_ibss_rsn( | |
1848 | struct wpa_supplicant *wpa_s, char *addr) | |
1849 | { | |
1850 | u8 peer[ETH_ALEN]; | |
1851 | ||
1852 | if (hwaddr_aton(addr, peer)) { | |
1853 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid " | |
a7b6c422 | 1854 | "address '%s'", addr); |
11ef8d35 JM |
1855 | return -1; |
1856 | } | |
1857 | ||
1858 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR, | |
1859 | MAC2STR(peer)); | |
1860 | ||
1861 | return ibss_rsn_start(wpa_s->ibss_rsn, peer); | |
1862 | } | |
1863 | #endif /* CONFIG_IBSS_RSN */ | |
1864 | ||
1865 | ||
7de5688d DW |
1866 | static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, |
1867 | char *rsp) | |
1868 | { | |
1869 | #ifdef IEEE8021X_EAPOL | |
1870 | char *pos, *id_pos; | |
1871 | int id; | |
1872 | struct wpa_ssid *ssid; | |
1873 | ||
1874 | pos = os_strchr(rsp, '-'); | |
1875 | if (pos == NULL) | |
1876 | return -1; | |
1877 | *pos++ = '\0'; | |
1878 | id_pos = pos; | |
1879 | pos = os_strchr(pos, ':'); | |
1880 | if (pos == NULL) | |
1881 | return -1; | |
1882 | *pos++ = '\0'; | |
1883 | id = atoi(id_pos); | |
1884 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); | |
1885 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
1886 | (u8 *) pos, os_strlen(pos)); | |
1887 | ||
1888 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
1889 | if (ssid == NULL) { | |
1890 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
1891 | "to update", id); | |
1892 | return -1; | |
1893 | } | |
1894 | ||
1895 | return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp, | |
1896 | pos); | |
6fc6879b JM |
1897 | #else /* IEEE8021X_EAPOL */ |
1898 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); | |
1899 | return -1; | |
1900 | #endif /* IEEE8021X_EAPOL */ | |
1901 | } | |
1902 | ||
1903 | ||
1904 | static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, | |
1905 | const char *params, | |
1906 | char *buf, size_t buflen) | |
1907 | { | |
1908 | char *pos, *end, tmp[30]; | |
0bc13468 | 1909 | int res, verbose, wps, ret; |
f9cd147d JM |
1910 | #ifdef CONFIG_HS20 |
1911 | const u8 *hs20; | |
1912 | #endif /* CONFIG_HS20 */ | |
993a8654 JM |
1913 | const u8 *sess_id; |
1914 | size_t sess_id_len; | |
6fc6879b | 1915 | |
a771c07d JM |
1916 | if (os_strcmp(params, "-DRIVER") == 0) |
1917 | return wpa_drv_status(wpa_s, buf, buflen); | |
6fc6879b | 1918 | verbose = os_strcmp(params, "-VERBOSE") == 0; |
0bc13468 | 1919 | wps = os_strcmp(params, "-WPS") == 0; |
6fc6879b JM |
1920 | pos = buf; |
1921 | end = buf + buflen; | |
1922 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { | |
1923 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
1924 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | |
1925 | MAC2STR(wpa_s->bssid)); | |
d85e1fc8 | 1926 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
1927 | return pos - buf; |
1928 | pos += ret; | |
b6ebdfbe BP |
1929 | ret = os_snprintf(pos, end - pos, "freq=%u\n", |
1930 | wpa_s->assoc_freq); | |
d85e1fc8 | 1931 | if (os_snprintf_error(end - pos, ret)) |
b6ebdfbe BP |
1932 | return pos - buf; |
1933 | pos += ret; | |
6fc6879b JM |
1934 | if (ssid) { |
1935 | u8 *_ssid = ssid->ssid; | |
1936 | size_t ssid_len = ssid->ssid_len; | |
eaa8eefe | 1937 | u8 ssid_buf[SSID_MAX_LEN]; |
6fc6879b JM |
1938 | if (ssid_len == 0) { |
1939 | int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); | |
1940 | if (_res < 0) | |
1941 | ssid_len = 0; | |
1942 | else | |
1943 | ssid_len = _res; | |
1944 | _ssid = ssid_buf; | |
1945 | } | |
1946 | ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", | |
1947 | wpa_ssid_txt(_ssid, ssid_len), | |
1948 | ssid->id); | |
d85e1fc8 | 1949 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
1950 | return pos - buf; |
1951 | pos += ret; | |
1952 | ||
0bc13468 JM |
1953 | if (wps && ssid->passphrase && |
1954 | wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && | |
1955 | (ssid->mode == WPAS_MODE_AP || | |
1956 | ssid->mode == WPAS_MODE_P2P_GO)) { | |
1957 | ret = os_snprintf(pos, end - pos, | |
1958 | "passphrase=%s\n", | |
1959 | ssid->passphrase); | |
d85e1fc8 | 1960 | if (os_snprintf_error(end - pos, ret)) |
0bc13468 JM |
1961 | return pos - buf; |
1962 | pos += ret; | |
1963 | } | |
6fc6879b JM |
1964 | if (ssid->id_str) { |
1965 | ret = os_snprintf(pos, end - pos, | |
1966 | "id_str=%s\n", | |
1967 | ssid->id_str); | |
d85e1fc8 | 1968 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
1969 | return pos - buf; |
1970 | pos += ret; | |
1971 | } | |
0e15e529 JM |
1972 | |
1973 | switch (ssid->mode) { | |
d7dcba70 | 1974 | case WPAS_MODE_INFRA: |
0e15e529 JM |
1975 | ret = os_snprintf(pos, end - pos, |
1976 | "mode=station\n"); | |
1977 | break; | |
d7dcba70 | 1978 | case WPAS_MODE_IBSS: |
0e15e529 JM |
1979 | ret = os_snprintf(pos, end - pos, |
1980 | "mode=IBSS\n"); | |
1981 | break; | |
d7dcba70 | 1982 | case WPAS_MODE_AP: |
0e15e529 JM |
1983 | ret = os_snprintf(pos, end - pos, |
1984 | "mode=AP\n"); | |
1985 | break; | |
2c5d725c JM |
1986 | case WPAS_MODE_P2P_GO: |
1987 | ret = os_snprintf(pos, end - pos, | |
1988 | "mode=P2P GO\n"); | |
1989 | break; | |
1990 | case WPAS_MODE_P2P_GROUP_FORMATION: | |
1991 | ret = os_snprintf(pos, end - pos, | |
1992 | "mode=P2P GO - group " | |
1993 | "formation\n"); | |
1994 | break; | |
cee0be73 SB |
1995 | case WPAS_MODE_MESH: |
1996 | ret = os_snprintf(pos, end - pos, | |
1997 | "mode=mesh\n"); | |
1998 | break; | |
0e15e529 JM |
1999 | default: |
2000 | ret = 0; | |
2001 | break; | |
2002 | } | |
1f102d3b | 2003 | if (os_snprintf_error(end - pos, ret)) |
0e15e529 JM |
2004 | return pos - buf; |
2005 | pos += ret; | |
6fc6879b JM |
2006 | } |
2007 | ||
43fb5297 JM |
2008 | #ifdef CONFIG_AP |
2009 | if (wpa_s->ap_iface) { | |
2010 | pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos, | |
2011 | end - pos, | |
2012 | verbose); | |
2013 | } else | |
2014 | #endif /* CONFIG_AP */ | |
6fc6879b JM |
2015 | pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); |
2016 | } | |
afe73100 | 2017 | #ifdef CONFIG_SME |
4954c859 JM |
2018 | #ifdef CONFIG_SAE |
2019 | if (wpa_s->wpa_state >= WPA_ASSOCIATED && | |
e1ae5d74 JM |
2020 | #ifdef CONFIG_AP |
2021 | !wpa_s->ap_iface && | |
2022 | #endif /* CONFIG_AP */ | |
2023 | wpa_s->sme.sae.state == SAE_ACCEPTED) { | |
4954c859 JM |
2024 | ret = os_snprintf(pos, end - pos, "sae_group=%d\n", |
2025 | wpa_s->sme.sae.group); | |
d85e1fc8 | 2026 | if (os_snprintf_error(end - pos, ret)) |
4954c859 JM |
2027 | return pos - buf; |
2028 | pos += ret; | |
2029 | } | |
2030 | #endif /* CONFIG_SAE */ | |
afe73100 | 2031 | #endif /* CONFIG_SME */ |
6fc6879b JM |
2032 | ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", |
2033 | wpa_supplicant_state_txt(wpa_s->wpa_state)); | |
d85e1fc8 | 2034 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2035 | return pos - buf; |
2036 | pos += ret; | |
2037 | ||
2038 | if (wpa_s->l2 && | |
2039 | l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { | |
2040 | ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); | |
d85e1fc8 | 2041 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2042 | return pos - buf; |
2043 | pos += ret; | |
2044 | } | |
2045 | ||
d23bd894 JM |
2046 | #ifdef CONFIG_P2P |
2047 | if (wpa_s->global->p2p) { | |
2048 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR | |
2049 | "\n", MAC2STR(wpa_s->global->p2p_dev_addr)); | |
d85e1fc8 | 2050 | if (os_snprintf_error(end - pos, ret)) |
d23bd894 JM |
2051 | return pos - buf; |
2052 | pos += ret; | |
2053 | } | |
b21e2c84 | 2054 | #endif /* CONFIG_P2P */ |
6d4747a9 JM |
2055 | |
2056 | ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n", | |
2057 | MAC2STR(wpa_s->own_addr)); | |
d85e1fc8 | 2058 | if (os_snprintf_error(end - pos, ret)) |
6d4747a9 JM |
2059 | return pos - buf; |
2060 | pos += ret; | |
d23bd894 | 2061 | |
64855b96 JM |
2062 | #ifdef CONFIG_HS20 |
2063 | if (wpa_s->current_bss && | |
f9cd147d JM |
2064 | (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss, |
2065 | HS20_IE_VENDOR_TYPE)) && | |
4ed34f5a JM |
2066 | wpa_s->wpa_proto == WPA_PROTO_RSN && |
2067 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | |
f9cd147d JM |
2068 | int release = 1; |
2069 | if (hs20[1] >= 5) { | |
2070 | u8 rel_num = (hs20[6] & 0xf0) >> 4; | |
2071 | release = rel_num + 1; | |
2072 | } | |
2073 | ret = os_snprintf(pos, end - pos, "hs20=%d\n", release); | |
d85e1fc8 | 2074 | if (os_snprintf_error(end - pos, ret)) |
64855b96 JM |
2075 | return pos - buf; |
2076 | pos += ret; | |
2077 | } | |
e99b4f3a JM |
2078 | |
2079 | if (wpa_s->current_ssid) { | |
2080 | struct wpa_cred *cred; | |
2081 | char *type; | |
2082 | ||
2083 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { | |
463c8ffb JM |
2084 | size_t i; |
2085 | ||
e99b4f3a JM |
2086 | if (wpa_s->current_ssid->parent_cred != cred) |
2087 | continue; | |
e99b4f3a | 2088 | |
aa26ba68 | 2089 | if (cred->provisioning_sp) { |
463c8ffb | 2090 | ret = os_snprintf(pos, end - pos, |
aa26ba68 JM |
2091 | "provisioning_sp=%s\n", |
2092 | cred->provisioning_sp); | |
d85e1fc8 | 2093 | if (os_snprintf_error(end - pos, ret)) |
463c8ffb JM |
2094 | return pos - buf; |
2095 | pos += ret; | |
2096 | } | |
e99b4f3a | 2097 | |
aa26ba68 JM |
2098 | if (!cred->domain) |
2099 | goto no_domain; | |
2100 | ||
2101 | i = 0; | |
2102 | if (wpa_s->current_bss && wpa_s->current_bss->anqp) { | |
2103 | struct wpabuf *names = | |
2104 | wpa_s->current_bss->anqp->domain_name; | |
2105 | for (i = 0; names && i < cred->num_domain; i++) | |
2106 | { | |
2107 | if (domain_name_list_contains( | |
2108 | names, cred->domain[i], 1)) | |
2109 | break; | |
2110 | } | |
2111 | if (i == cred->num_domain) | |
2112 | i = 0; /* show first entry by default */ | |
2113 | } | |
2114 | ret = os_snprintf(pos, end - pos, "home_sp=%s\n", | |
2115 | cred->domain[i]); | |
d85e1fc8 | 2116 | if (os_snprintf_error(end - pos, ret)) |
aa26ba68 JM |
2117 | return pos - buf; |
2118 | pos += ret; | |
2119 | ||
2120 | no_domain: | |
e99b4f3a JM |
2121 | if (wpa_s->current_bss == NULL || |
2122 | wpa_s->current_bss->anqp == NULL) | |
2123 | res = -1; | |
2124 | else | |
2125 | res = interworking_home_sp_cred( | |
2126 | wpa_s, cred, | |
2127 | wpa_s->current_bss->anqp->domain_name); | |
2128 | if (res > 0) | |
2129 | type = "home"; | |
2130 | else if (res == 0) | |
2131 | type = "roaming"; | |
2132 | else | |
2133 | type = "unknown"; | |
2134 | ||
2135 | ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type); | |
d85e1fc8 | 2136 | if (os_snprintf_error(end - pos, ret)) |
e99b4f3a JM |
2137 | return pos - buf; |
2138 | pos += ret; | |
2139 | ||
2140 | break; | |
2141 | } | |
2142 | } | |
64855b96 JM |
2143 | #endif /* CONFIG_HS20 */ |
2144 | ||
56586197 JM |
2145 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
2146 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
6fc6879b JM |
2147 | res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, |
2148 | verbose); | |
2149 | if (res >= 0) | |
2150 | pos += res; | |
2151 | } | |
2152 | ||
7508c2ad BA |
2153 | #ifdef CONFIG_MACSEC |
2154 | res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos); | |
2155 | if (res > 0) | |
2156 | pos += res; | |
2157 | #endif /* CONFIG_MACSEC */ | |
2158 | ||
993a8654 JM |
2159 | sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len); |
2160 | if (sess_id) { | |
2161 | char *start = pos; | |
2162 | ||
2163 | ret = os_snprintf(pos, end - pos, "eap_session_id="); | |
2164 | if (os_snprintf_error(end - pos, ret)) | |
2165 | return start - buf; | |
2166 | pos += ret; | |
2167 | ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len); | |
2168 | if (ret <= 0) | |
2169 | return start - buf; | |
2170 | pos += ret; | |
2171 | ret = os_snprintf(pos, end - pos, "\n"); | |
2172 | if (os_snprintf_error(end - pos, ret)) | |
2173 | return start - buf; | |
2174 | pos += ret; | |
2175 | } | |
2176 | ||
6fc6879b JM |
2177 | res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); |
2178 | if (res >= 0) | |
2179 | pos += res; | |
2180 | ||
8aaafcee JM |
2181 | #ifdef CONFIG_WPS |
2182 | { | |
2183 | char uuid_str[100]; | |
2184 | uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str)); | |
2185 | ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str); | |
d85e1fc8 | 2186 | if (os_snprintf_error(end - pos, ret)) |
8aaafcee JM |
2187 | return pos - buf; |
2188 | pos += ret; | |
2189 | } | |
2190 | #endif /* CONFIG_WPS */ | |
2191 | ||
f6c2b8c3 | 2192 | #ifdef ANDROID |
a6ab82d7 | 2193 | /* |
2194 | * Allow using the STATUS command with default behavior, say for debug, | |
2195 | * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE | |
2196 | * events with STATUS-NO_EVENTS. | |
2197 | */ | |
2198 | if (os_strcmp(params, "-NO_EVENTS")) { | |
2199 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE | |
2200 | "id=%d state=%d BSSID=" MACSTR " SSID=%s", | |
2201 | wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, | |
2202 | wpa_s->wpa_state, | |
2203 | MAC2STR(wpa_s->bssid), | |
2204 | wpa_s->current_ssid && wpa_s->current_ssid->ssid ? | |
2205 | wpa_ssid_txt(wpa_s->current_ssid->ssid, | |
2206 | wpa_s->current_ssid->ssid_len) : ""); | |
2207 | if (wpa_s->wpa_state == WPA_COMPLETED) { | |
2208 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
2209 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED | |
2210 | "- connection to " MACSTR | |
2211 | " completed %s [id=%d id_str=%s]", | |
2212 | MAC2STR(wpa_s->bssid), "(auth)", | |
2213 | ssid ? ssid->id : -1, | |
2214 | ssid && ssid->id_str ? ssid->id_str : ""); | |
2215 | } | |
f6c2b8c3 DS |
2216 | } |
2217 | #endif /* ANDROID */ | |
2218 | ||
6fc6879b JM |
2219 | return pos - buf; |
2220 | } | |
2221 | ||
2222 | ||
2223 | static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, | |
2224 | char *cmd) | |
2225 | { | |
2226 | char *pos; | |
2227 | int id; | |
2228 | struct wpa_ssid *ssid; | |
2229 | u8 bssid[ETH_ALEN]; | |
2230 | ||
2231 | /* cmd: "<network id> <BSSID>" */ | |
2232 | pos = os_strchr(cmd, ' '); | |
2233 | if (pos == NULL) | |
2234 | return -1; | |
2235 | *pos++ = '\0'; | |
2236 | id = atoi(cmd); | |
2237 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); | |
2238 | if (hwaddr_aton(pos, bssid)) { | |
2239 | wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); | |
2240 | return -1; | |
2241 | } | |
2242 | ||
2243 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
2244 | if (ssid == NULL) { | |
2245 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
2246 | "to update", id); | |
2247 | return -1; | |
2248 | } | |
2249 | ||
2250 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); | |
a8e16edc | 2251 | ssid->bssid_set = !is_zero_ether_addr(bssid); |
6fc6879b JM |
2252 | |
2253 | return 0; | |
2254 | } | |
2255 | ||
2256 | ||
9aa10e2b DS |
2257 | static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s, |
2258 | char *cmd, char *buf, | |
2259 | size_t buflen) | |
2260 | { | |
2261 | u8 bssid[ETH_ALEN]; | |
2262 | struct wpa_blacklist *e; | |
2263 | char *pos, *end; | |
2264 | int ret; | |
2265 | ||
2266 | /* cmd: "BLACKLIST [<BSSID>]" */ | |
2267 | if (*cmd == '\0') { | |
2268 | pos = buf; | |
2269 | end = buf + buflen; | |
2270 | e = wpa_s->blacklist; | |
2271 | while (e) { | |
2272 | ret = os_snprintf(pos, end - pos, MACSTR "\n", | |
2273 | MAC2STR(e->bssid)); | |
d85e1fc8 | 2274 | if (os_snprintf_error(end - pos, ret)) |
9aa10e2b DS |
2275 | return pos - buf; |
2276 | pos += ret; | |
2277 | e = e->next; | |
2278 | } | |
2279 | return pos - buf; | |
2280 | } | |
2281 | ||
2282 | cmd++; | |
2283 | if (os_strncmp(cmd, "clear", 5) == 0) { | |
2284 | wpa_blacklist_clear(wpa_s); | |
2285 | os_memcpy(buf, "OK\n", 3); | |
2286 | return 3; | |
2287 | } | |
2288 | ||
2289 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd); | |
2290 | if (hwaddr_aton(cmd, bssid)) { | |
2291 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd); | |
2292 | return -1; | |
2293 | } | |
2294 | ||
2295 | /* | |
2296 | * Add the BSSID twice, so its count will be 2, causing it to be | |
2297 | * skipped when processing scan results. | |
2298 | */ | |
2299 | ret = wpa_blacklist_add(wpa_s, bssid); | |
bd8838a3 | 2300 | if (ret < 0) |
9aa10e2b DS |
2301 | return -1; |
2302 | ret = wpa_blacklist_add(wpa_s, bssid); | |
bd8838a3 | 2303 | if (ret < 0) |
9aa10e2b DS |
2304 | return -1; |
2305 | os_memcpy(buf, "OK\n", 3); | |
2306 | return 3; | |
2307 | } | |
2308 | ||
2309 | ||
0597a5b5 DS |
2310 | static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s, |
2311 | char *cmd, char *buf, | |
2312 | size_t buflen) | |
2313 | { | |
2314 | char *pos, *end, *stamp; | |
2315 | int ret; | |
2316 | ||
0597a5b5 DS |
2317 | /* cmd: "LOG_LEVEL [<level>]" */ |
2318 | if (*cmd == '\0') { | |
2319 | pos = buf; | |
2320 | end = buf + buflen; | |
2321 | ret = os_snprintf(pos, end - pos, "Current level: %s\n" | |
2322 | "Timestamp: %d\n", | |
2323 | debug_level_str(wpa_debug_level), | |
2324 | wpa_debug_timestamp); | |
d85e1fc8 | 2325 | if (os_snprintf_error(end - pos, ret)) |
0597a5b5 DS |
2326 | ret = 0; |
2327 | ||
2328 | return ret; | |
2329 | } | |
2330 | ||
2331 | while (*cmd == ' ') | |
2332 | cmd++; | |
2333 | ||
2334 | stamp = os_strchr(cmd, ' '); | |
2335 | if (stamp) { | |
2336 | *stamp++ = '\0'; | |
2337 | while (*stamp == ' ') { | |
2338 | stamp++; | |
2339 | } | |
2340 | } | |
2341 | ||
137b2939 | 2342 | if (os_strlen(cmd)) { |
0597a5b5 DS |
2343 | int level = str_to_debug_level(cmd); |
2344 | if (level < 0) | |
2345 | return -1; | |
2346 | wpa_debug_level = level; | |
2347 | } | |
2348 | ||
2349 | if (stamp && os_strlen(stamp)) | |
2350 | wpa_debug_timestamp = atoi(stamp); | |
2351 | ||
2352 | os_memcpy(buf, "OK\n", 3); | |
2353 | return 3; | |
2354 | } | |
2355 | ||
2356 | ||
6fc6879b | 2357 | static int wpa_supplicant_ctrl_iface_list_networks( |
90903a77 | 2358 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
6fc6879b | 2359 | { |
f34891a3 | 2360 | char *pos, *end, *prev; |
6fc6879b JM |
2361 | struct wpa_ssid *ssid; |
2362 | int ret; | |
2363 | ||
2364 | pos = buf; | |
2365 | end = buf + buflen; | |
2366 | ret = os_snprintf(pos, end - pos, | |
2367 | "network id / ssid / bssid / flags\n"); | |
d85e1fc8 | 2368 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2369 | return pos - buf; |
2370 | pos += ret; | |
2371 | ||
2372 | ssid = wpa_s->conf->ssid; | |
90903a77 VD |
2373 | |
2374 | /* skip over ssids until we find next one */ | |
2375 | if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) { | |
2376 | int last_id = atoi(cmd + 8); | |
2377 | if (last_id != -1) { | |
2378 | while (ssid != NULL && ssid->id <= last_id) { | |
2379 | ssid = ssid->next; | |
2380 | } | |
2381 | } | |
2382 | } | |
2383 | ||
6fc6879b | 2384 | while (ssid) { |
f34891a3 | 2385 | prev = pos; |
6fc6879b JM |
2386 | ret = os_snprintf(pos, end - pos, "%d\t%s", |
2387 | ssid->id, | |
2388 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | |
d85e1fc8 | 2389 | if (os_snprintf_error(end - pos, ret)) |
f34891a3 | 2390 | return prev - buf; |
6fc6879b JM |
2391 | pos += ret; |
2392 | if (ssid->bssid_set) { | |
2393 | ret = os_snprintf(pos, end - pos, "\t" MACSTR, | |
2394 | MAC2STR(ssid->bssid)); | |
2395 | } else { | |
2396 | ret = os_snprintf(pos, end - pos, "\tany"); | |
2397 | } | |
d85e1fc8 | 2398 | if (os_snprintf_error(end - pos, ret)) |
f34891a3 | 2399 | return prev - buf; |
6fc6879b | 2400 | pos += ret; |
00e5e3d5 | 2401 | ret = os_snprintf(pos, end - pos, "\t%s%s%s%s", |
6fc6879b JM |
2402 | ssid == wpa_s->current_ssid ? |
2403 | "[CURRENT]" : "", | |
4dac0245 | 2404 | ssid->disabled ? "[DISABLED]" : "", |
00e5e3d5 JM |
2405 | ssid->disabled_until.sec ? |
2406 | "[TEMP-DISABLED]" : "", | |
4dac0245 JM |
2407 | ssid->disabled == 2 ? "[P2P-PERSISTENT]" : |
2408 | ""); | |
d85e1fc8 | 2409 | if (os_snprintf_error(end - pos, ret)) |
f34891a3 | 2410 | return prev - buf; |
6fc6879b JM |
2411 | pos += ret; |
2412 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 2413 | if (os_snprintf_error(end - pos, ret)) |
f34891a3 | 2414 | return prev - buf; |
6fc6879b JM |
2415 | pos += ret; |
2416 | ||
2417 | ssid = ssid->next; | |
2418 | } | |
2419 | ||
2420 | return pos - buf; | |
2421 | } | |
2422 | ||
2423 | ||
2424 | static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) | |
2425 | { | |
0282a8c4 | 2426 | int ret; |
6fc6879b | 2427 | ret = os_snprintf(pos, end - pos, "-"); |
d85e1fc8 | 2428 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2429 | return pos; |
2430 | pos += ret; | |
0282a8c4 JM |
2431 | ret = wpa_write_ciphers(pos, end, cipher, "+"); |
2432 | if (ret < 0) | |
2433 | return pos; | |
2434 | pos += ret; | |
6fc6879b JM |
2435 | return pos; |
2436 | } | |
2437 | ||
2438 | ||
2439 | static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, | |
2440 | const u8 *ie, size_t ie_len) | |
2441 | { | |
2442 | struct wpa_ie_data data; | |
ea3b8c1d JM |
2443 | char *start; |
2444 | int ret; | |
6fc6879b JM |
2445 | |
2446 | ret = os_snprintf(pos, end - pos, "[%s-", proto); | |
d85e1fc8 | 2447 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2448 | return pos; |
2449 | pos += ret; | |
2450 | ||
2451 | if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { | |
2452 | ret = os_snprintf(pos, end - pos, "?]"); | |
d85e1fc8 | 2453 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2454 | return pos; |
2455 | pos += ret; | |
2456 | return pos; | |
2457 | } | |
2458 | ||
ea3b8c1d | 2459 | start = pos; |
6fc6879b | 2460 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { |
ea3b8c1d JM |
2461 | ret = os_snprintf(pos, end - pos, "%sEAP", |
2462 | pos == start ? "" : "+"); | |
d85e1fc8 | 2463 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2464 | return pos; |
2465 | pos += ret; | |
6fc6879b JM |
2466 | } |
2467 | if (data.key_mgmt & WPA_KEY_MGMT_PSK) { | |
ea3b8c1d JM |
2468 | ret = os_snprintf(pos, end - pos, "%sPSK", |
2469 | pos == start ? "" : "+"); | |
d85e1fc8 | 2470 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2471 | return pos; |
2472 | pos += ret; | |
6fc6879b JM |
2473 | } |
2474 | if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { | |
ea3b8c1d JM |
2475 | ret = os_snprintf(pos, end - pos, "%sNone", |
2476 | pos == start ? "" : "+"); | |
d85e1fc8 | 2477 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2478 | return pos; |
2479 | pos += ret; | |
6fc6879b | 2480 | } |
be6b29f6 JA |
2481 | if (data.key_mgmt & WPA_KEY_MGMT_SAE) { |
2482 | ret = os_snprintf(pos, end - pos, "%sSAE", | |
2483 | pos == start ? "" : "+"); | |
d85e1fc8 | 2484 | if (os_snprintf_error(end - pos, ret)) |
be6b29f6 JA |
2485 | return pos; |
2486 | pos += ret; | |
2487 | } | |
6fc6879b JM |
2488 | #ifdef CONFIG_IEEE80211R |
2489 | if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { | |
2490 | ret = os_snprintf(pos, end - pos, "%sFT/EAP", | |
ea3b8c1d | 2491 | pos == start ? "" : "+"); |
d85e1fc8 | 2492 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2493 | return pos; |
2494 | pos += ret; | |
6fc6879b JM |
2495 | } |
2496 | if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { | |
2497 | ret = os_snprintf(pos, end - pos, "%sFT/PSK", | |
ea3b8c1d | 2498 | pos == start ? "" : "+"); |
d85e1fc8 | 2499 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2500 | return pos; |
2501 | pos += ret; | |
6fc6879b | 2502 | } |
be6b29f6 JA |
2503 | if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) { |
2504 | ret = os_snprintf(pos, end - pos, "%sFT/SAE", | |
2505 | pos == start ? "" : "+"); | |
d85e1fc8 | 2506 | if (os_snprintf_error(end - pos, ret)) |
be6b29f6 JA |
2507 | return pos; |
2508 | pos += ret; | |
2509 | } | |
6fc6879b | 2510 | #endif /* CONFIG_IEEE80211R */ |
56586197 JM |
2511 | #ifdef CONFIG_IEEE80211W |
2512 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { | |
2513 | ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", | |
ea3b8c1d | 2514 | pos == start ? "" : "+"); |
d85e1fc8 | 2515 | if (os_snprintf_error(end - pos, ret)) |
56586197 JM |
2516 | return pos; |
2517 | pos += ret; | |
56586197 JM |
2518 | } |
2519 | if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { | |
2520 | ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", | |
ea3b8c1d | 2521 | pos == start ? "" : "+"); |
d85e1fc8 | 2522 | if (os_snprintf_error(end - pos, ret)) |
56586197 JM |
2523 | return pos; |
2524 | pos += ret; | |
56586197 JM |
2525 | } |
2526 | #endif /* CONFIG_IEEE80211W */ | |
6fc6879b | 2527 | |
5e3b5197 | 2528 | #ifdef CONFIG_SUITEB |
666497c8 JM |
2529 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
2530 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B", | |
2531 | pos == start ? "" : "+"); | |
d85e1fc8 | 2532 | if (os_snprintf_error(end - pos, ret)) |
666497c8 JM |
2533 | return pos; |
2534 | pos += ret; | |
2535 | } | |
5e3b5197 JM |
2536 | #endif /* CONFIG_SUITEB */ |
2537 | ||
2538 | #ifdef CONFIG_SUITEB192 | |
2539 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { | |
2540 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192", | |
2541 | pos == start ? "" : "+"); | |
2542 | if (os_snprintf_error(end - pos, ret)) | |
2543 | return pos; | |
2544 | pos += ret; | |
2545 | } | |
2546 | #endif /* CONFIG_SUITEB192 */ | |
666497c8 | 2547 | |
7147a834 JM |
2548 | #ifdef CONFIG_FILS |
2549 | if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) { | |
2550 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA256", | |
2551 | pos == start ? "" : "+"); | |
2552 | if (os_snprintf_error(end - pos, ret)) | |
2553 | return pos; | |
2554 | pos += ret; | |
2555 | } | |
2556 | if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) { | |
2557 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA384", | |
2558 | pos == start ? "" : "+"); | |
2559 | if (os_snprintf_error(end - pos, ret)) | |
2560 | return pos; | |
2561 | pos += ret; | |
2562 | } | |
2563 | #ifdef CONFIG_IEEE80211R | |
2564 | if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) { | |
2565 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256", | |
2566 | pos == start ? "" : "+"); | |
2567 | if (os_snprintf_error(end - pos, ret)) | |
2568 | return pos; | |
2569 | pos += ret; | |
2570 | } | |
2571 | if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) { | |
2572 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384", | |
2573 | pos == start ? "" : "+"); | |
2574 | if (os_snprintf_error(end - pos, ret)) | |
2575 | return pos; | |
2576 | pos += ret; | |
2577 | } | |
2578 | #endif /* CONFIG_IEEE80211R */ | |
2579 | #endif /* CONFIG_FILS */ | |
2580 | ||
a1ea1b45 JM |
2581 | #ifdef CONFIG_OWE |
2582 | if (data.key_mgmt & WPA_KEY_MGMT_OWE) { | |
2583 | ret = os_snprintf(pos, end - pos, "%sOWE", | |
2584 | pos == start ? "" : "+"); | |
2585 | if (os_snprintf_error(end - pos, ret)) | |
2586 | return pos; | |
2587 | pos += ret; | |
2588 | } | |
2589 | #endif /* CONFIG_OWE */ | |
2590 | ||
0f8385e6 BG |
2591 | if (data.key_mgmt & WPA_KEY_MGMT_OSEN) { |
2592 | ret = os_snprintf(pos, end - pos, "%sOSEN", | |
2593 | pos == start ? "" : "+"); | |
2594 | if (os_snprintf_error(end - pos, ret)) | |
2595 | return pos; | |
2596 | pos += ret; | |
2597 | } | |
2598 | ||
6fc6879b JM |
2599 | pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); |
2600 | ||
2601 | if (data.capabilities & WPA_CAPABILITY_PREAUTH) { | |
2602 | ret = os_snprintf(pos, end - pos, "-preauth"); | |
d85e1fc8 | 2603 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2604 | return pos; |
2605 | pos += ret; | |
2606 | } | |
2607 | ||
2608 | ret = os_snprintf(pos, end - pos, "]"); | |
d85e1fc8 | 2609 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2610 | return pos; |
2611 | pos += ret; | |
2612 | ||
2613 | return pos; | |
2614 | } | |
2615 | ||
3a068632 | 2616 | |
eef7d7a1 | 2617 | #ifdef CONFIG_WPS |
31fcea93 JM |
2618 | static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, |
2619 | char *pos, char *end, | |
3a068632 JM |
2620 | struct wpabuf *wps_ie) |
2621 | { | |
eef7d7a1 JM |
2622 | int ret; |
2623 | const char *txt; | |
2624 | ||
eef7d7a1 JM |
2625 | if (wps_ie == NULL) |
2626 | return pos; | |
eef7d7a1 JM |
2627 | if (wps_is_selected_pbc_registrar(wps_ie)) |
2628 | txt = "[WPS-PBC]"; | |
31fcea93 JM |
2629 | else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) |
2630 | txt = "[WPS-AUTH]"; | |
eef7d7a1 JM |
2631 | else if (wps_is_selected_pin_registrar(wps_ie)) |
2632 | txt = "[WPS-PIN]"; | |
2633 | else | |
2634 | txt = "[WPS]"; | |
2635 | ||
2636 | ret = os_snprintf(pos, end - pos, "%s", txt); | |
a80ba67a | 2637 | if (!os_snprintf_error(end - pos, ret)) |
eef7d7a1 JM |
2638 | pos += ret; |
2639 | wpabuf_free(wps_ie); | |
3a068632 JM |
2640 | return pos; |
2641 | } | |
2642 | #endif /* CONFIG_WPS */ | |
2643 | ||
2644 | ||
31fcea93 JM |
2645 | static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, |
2646 | char *pos, char *end, | |
16b71ac2 | 2647 | const struct wpa_bss *bss) |
3a068632 JM |
2648 | { |
2649 | #ifdef CONFIG_WPS | |
2650 | struct wpabuf *wps_ie; | |
2651 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); | |
31fcea93 | 2652 | return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); |
3a068632 | 2653 | #else /* CONFIG_WPS */ |
eef7d7a1 | 2654 | return pos; |
3a068632 | 2655 | #endif /* CONFIG_WPS */ |
eef7d7a1 JM |
2656 | } |
2657 | ||
6fc6879b JM |
2658 | |
2659 | /* Format one result on one text line into a buffer. */ | |
2660 | static int wpa_supplicant_ctrl_iface_scan_result( | |
31fcea93 | 2661 | struct wpa_supplicant *wpa_s, |
16b71ac2 | 2662 | const struct wpa_bss *bss, char *buf, size_t buflen) |
6fc6879b JM |
2663 | { |
2664 | char *pos, *end; | |
2665 | int ret; | |
0f8385e6 | 2666 | const u8 *ie, *ie2, *osen_ie, *p2p, *mesh; |
0c6b310e | 2667 | |
638d9456 | 2668 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
0c6b310e | 2669 | p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); |
bb50ae43 JM |
2670 | if (!p2p) |
2671 | p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE); | |
0c6b310e JM |
2672 | if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && |
2673 | os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == | |
2674 | 0) | |
2675 | return 0; /* Do not show P2P listen discovery results here */ | |
6fc6879b JM |
2676 | |
2677 | pos = buf; | |
2678 | end = buf + buflen; | |
2679 | ||
2680 | ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", | |
16b71ac2 | 2681 | MAC2STR(bss->bssid), bss->freq, bss->level); |
d85e1fc8 | 2682 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2683 | return -1; |
6fc6879b | 2684 | pos += ret; |
16b71ac2 | 2685 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
6fc6879b JM |
2686 | if (ie) |
2687 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); | |
16b71ac2 | 2688 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
638d9456 JA |
2689 | if (ie2) { |
2690 | pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2", | |
2691 | ie2, 2 + ie2[1]); | |
2692 | } | |
0f8385e6 BG |
2693 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
2694 | if (osen_ie) | |
2695 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", | |
2696 | osen_ie, 2 + osen_ie[1]); | |
31fcea93 | 2697 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
0f8385e6 | 2698 | if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) { |
6fc6879b | 2699 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
d85e1fc8 | 2700 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2701 | return -1; |
6fc6879b JM |
2702 | pos += ret; |
2703 | } | |
638d9456 JA |
2704 | if (mesh) { |
2705 | ret = os_snprintf(pos, end - pos, "[MESH]"); | |
d85e1fc8 | 2706 | if (os_snprintf_error(end - pos, ret)) |
638d9456 JA |
2707 | return -1; |
2708 | pos += ret; | |
2709 | } | |
e403ba85 BS |
2710 | if (bss_is_dmg(bss)) { |
2711 | const char *s; | |
2712 | ret = os_snprintf(pos, end - pos, "[DMG]"); | |
d85e1fc8 | 2713 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2714 | return -1; |
6fc6879b | 2715 | pos += ret; |
e403ba85 BS |
2716 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
2717 | case IEEE80211_CAP_DMG_IBSS: | |
2718 | s = "[IBSS]"; | |
2719 | break; | |
2720 | case IEEE80211_CAP_DMG_AP: | |
2721 | s = "[ESS]"; | |
2722 | break; | |
2723 | case IEEE80211_CAP_DMG_PBSS: | |
2724 | s = "[PBSS]"; | |
2725 | break; | |
2726 | default: | |
2727 | s = ""; | |
2728 | break; | |
2729 | } | |
2730 | ret = os_snprintf(pos, end - pos, "%s", s); | |
d85e1fc8 | 2731 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2732 | return -1; |
bd1af96a | 2733 | pos += ret; |
e403ba85 BS |
2734 | } else { |
2735 | if (bss->caps & IEEE80211_CAP_IBSS) { | |
2736 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | |
d85e1fc8 | 2737 | if (os_snprintf_error(end - pos, ret)) |
e403ba85 BS |
2738 | return -1; |
2739 | pos += ret; | |
2740 | } | |
2741 | if (bss->caps & IEEE80211_CAP_ESS) { | |
2742 | ret = os_snprintf(pos, end - pos, "[ESS]"); | |
d85e1fc8 | 2743 | if (os_snprintf_error(end - pos, ret)) |
e403ba85 BS |
2744 | return -1; |
2745 | pos += ret; | |
2746 | } | |
bd1af96a | 2747 | } |
0c6b310e JM |
2748 | if (p2p) { |
2749 | ret = os_snprintf(pos, end - pos, "[P2P]"); | |
d85e1fc8 | 2750 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2751 | return -1; |
0c6b310e JM |
2752 | pos += ret; |
2753 | } | |
64855b96 | 2754 | #ifdef CONFIG_HS20 |
4ed34f5a | 2755 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) { |
64855b96 | 2756 | ret = os_snprintf(pos, end - pos, "[HS20]"); |
d85e1fc8 | 2757 | if (os_snprintf_error(end - pos, ret)) |
64855b96 JM |
2758 | return -1; |
2759 | pos += ret; | |
2760 | } | |
2761 | #endif /* CONFIG_HS20 */ | |
7147a834 JM |
2762 | #ifdef CONFIG_FILS |
2763 | if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) { | |
2764 | ret = os_snprintf(pos, end - pos, "[FILS]"); | |
2765 | if (os_snprintf_error(end - pos, ret)) | |
2766 | return -1; | |
2767 | pos += ret; | |
2768 | } | |
2769 | #endif /* CONFIG_FILS */ | |
55de4d4b AN |
2770 | #ifdef CONFIG_FST |
2771 | if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) { | |
2772 | ret = os_snprintf(pos, end - pos, "[FST]"); | |
2773 | if (os_snprintf_error(end - pos, ret)) | |
2774 | return -1; | |
2775 | pos += ret; | |
2776 | } | |
2777 | #endif /* CONFIG_FST */ | |
6fc6879b | 2778 | |
6fc6879b | 2779 | ret = os_snprintf(pos, end - pos, "\t%s", |
16b71ac2 | 2780 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
d85e1fc8 | 2781 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2782 | return -1; |
6fc6879b JM |
2783 | pos += ret; |
2784 | ||
2785 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 2786 | if (os_snprintf_error(end - pos, ret)) |
fb0e5bd7 | 2787 | return -1; |
6fc6879b JM |
2788 | pos += ret; |
2789 | ||
2790 | return pos - buf; | |
2791 | } | |
2792 | ||
2793 | ||
2794 | static int wpa_supplicant_ctrl_iface_scan_results( | |
2795 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
2796 | { | |
2797 | char *pos, *end; | |
16b71ac2 | 2798 | struct wpa_bss *bss; |
6fc6879b | 2799 | int ret; |
6fc6879b JM |
2800 | |
2801 | pos = buf; | |
2802 | end = buf + buflen; | |
2803 | ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " | |
2804 | "flags / ssid\n"); | |
d85e1fc8 | 2805 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
2806 | return pos - buf; |
2807 | pos += ret; | |
2808 | ||
16b71ac2 | 2809 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
31fcea93 | 2810 | ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, |
6fc6879b JM |
2811 | end - pos); |
2812 | if (ret < 0 || ret >= end - pos) | |
2813 | return pos - buf; | |
2814 | pos += ret; | |
2815 | } | |
2816 | ||
2817 | return pos - buf; | |
2818 | } | |
2819 | ||
2820 | ||
603a3f34 JL |
2821 | #ifdef CONFIG_MESH |
2822 | ||
5b78493f MH |
2823 | static int wpa_supplicant_ctrl_iface_mesh_interface_add( |
2824 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | |
2825 | { | |
2826 | char *pos, ifname[IFNAMSIZ + 1]; | |
2827 | ||
2828 | ifname[0] = '\0'; | |
2829 | ||
2830 | pos = os_strstr(cmd, "ifname="); | |
2831 | if (pos) { | |
2832 | pos += 7; | |
2833 | os_strlcpy(ifname, pos, sizeof(ifname)); | |
2834 | } | |
2835 | ||
2836 | if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0) | |
2837 | return -1; | |
2838 | ||
2839 | os_strlcpy(reply, ifname, max_len); | |
2840 | return os_strlen(ifname); | |
2841 | } | |
2842 | ||
2843 | ||
603a3f34 JL |
2844 | static int wpa_supplicant_ctrl_iface_mesh_group_add( |
2845 | struct wpa_supplicant *wpa_s, char *cmd) | |
2846 | { | |
2847 | int id; | |
2848 | struct wpa_ssid *ssid; | |
2849 | ||
2850 | id = atoi(cmd); | |
2851 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id); | |
2852 | ||
2853 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
2854 | if (ssid == NULL) { | |
2855 | wpa_printf(MSG_DEBUG, | |
2856 | "CTRL_IFACE: Could not find network id=%d", id); | |
2857 | return -1; | |
2858 | } | |
2859 | if (ssid->mode != WPAS_MODE_MESH) { | |
2860 | wpa_printf(MSG_DEBUG, | |
2861 | "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network"); | |
2862 | return -1; | |
2863 | } | |
0c6099f3 MH |
2864 | if (ssid->key_mgmt != WPA_KEY_MGMT_NONE && |
2865 | ssid->key_mgmt != WPA_KEY_MGMT_SAE) { | |
2866 | wpa_printf(MSG_ERROR, | |
2867 | "CTRL_IFACE: key_mgmt for mesh network should be open or SAE"); | |
2868 | return -1; | |
2869 | } | |
603a3f34 JL |
2870 | |
2871 | /* | |
2872 | * TODO: If necessary write our own group_add function, | |
2873 | * for now we can reuse select_network | |
2874 | */ | |
2875 | wpa_supplicant_select_network(wpa_s, ssid); | |
2876 | ||
2877 | return 0; | |
2878 | } | |
2879 | ||
2880 | ||
2881 | static int wpa_supplicant_ctrl_iface_mesh_group_remove( | |
2882 | struct wpa_supplicant *wpa_s, char *cmd) | |
2883 | { | |
5b78493f MH |
2884 | struct wpa_supplicant *orig; |
2885 | struct wpa_global *global; | |
2886 | int found = 0; | |
2887 | ||
2888 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd); | |
2889 | ||
2890 | global = wpa_s->global; | |
2891 | orig = wpa_s; | |
2892 | ||
2893 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
2894 | if (os_strcmp(wpa_s->ifname, cmd) == 0) { | |
2895 | found = 1; | |
2896 | break; | |
2897 | } | |
2898 | } | |
2899 | if (!found) { | |
2900 | wpa_printf(MSG_ERROR, | |
2901 | "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found", | |
603a3f34 JL |
2902 | cmd); |
2903 | return -1; | |
2904 | } | |
5b78493f MH |
2905 | if (wpa_s->mesh_if_created && wpa_s == orig) { |
2906 | wpa_printf(MSG_ERROR, | |
2907 | "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself"); | |
2908 | return -1; | |
2909 | } | |
603a3f34 JL |
2910 | |
2911 | wpa_s->reassociate = 0; | |
2912 | wpa_s->disconnected = 1; | |
2913 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
2914 | wpa_supplicant_cancel_scan(wpa_s); | |
2915 | ||
2916 | /* | |
2917 | * TODO: If necessary write our own group_remove function, | |
2918 | * for now we can reuse deauthenticate | |
2919 | */ | |
2920 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
2921 | ||
5b78493f MH |
2922 | if (wpa_s->mesh_if_created) |
2923 | wpa_supplicant_remove_iface(global, wpa_s, 0); | |
2924 | ||
603a3f34 JL |
2925 | return 0; |
2926 | } | |
2927 | ||
e174ef34 MH |
2928 | |
2929 | static int wpa_supplicant_ctrl_iface_mesh_peer_remove( | |
2930 | struct wpa_supplicant *wpa_s, char *cmd) | |
2931 | { | |
2932 | u8 addr[ETH_ALEN]; | |
2933 | ||
2934 | if (hwaddr_aton(cmd, addr) < 0) | |
2935 | return -1; | |
2936 | ||
2937 | return wpas_mesh_peer_remove(wpa_s, addr); | |
2938 | } | |
2939 | ||
2604edbf MH |
2940 | |
2941 | static int wpa_supplicant_ctrl_iface_mesh_peer_add( | |
2942 | struct wpa_supplicant *wpa_s, char *cmd) | |
2943 | { | |
2944 | u8 addr[ETH_ALEN]; | |
9f2cf23e MH |
2945 | int duration; |
2946 | char *pos; | |
2947 | ||
2948 | pos = os_strstr(cmd, " duration="); | |
2949 | if (pos) { | |
2950 | *pos = '\0'; | |
2951 | duration = atoi(pos + 10); | |
2952 | } else { | |
2953 | duration = -1; | |
2954 | } | |
2604edbf MH |
2955 | |
2956 | if (hwaddr_aton(cmd, addr)) | |
2957 | return -1; | |
2958 | ||
9f2cf23e | 2959 | return wpas_mesh_peer_add(wpa_s, addr, duration); |
2604edbf MH |
2960 | } |
2961 | ||
603a3f34 JL |
2962 | #endif /* CONFIG_MESH */ |
2963 | ||
2964 | ||
6fc6879b JM |
2965 | static int wpa_supplicant_ctrl_iface_select_network( |
2966 | struct wpa_supplicant *wpa_s, char *cmd) | |
2967 | { | |
2968 | int id; | |
2969 | struct wpa_ssid *ssid; | |
204c9ac4 | 2970 | char *pos; |
6fc6879b JM |
2971 | |
2972 | /* cmd: "<network id>" or "any" */ | |
204c9ac4 | 2973 | if (os_strncmp(cmd, "any", 3) == 0) { |
6fc6879b | 2974 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); |
86b89452 WS |
2975 | ssid = NULL; |
2976 | } else { | |
2977 | id = atoi(cmd); | |
2978 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); | |
6fc6879b | 2979 | |
86b89452 WS |
2980 | ssid = wpa_config_get_network(wpa_s->conf, id); |
2981 | if (ssid == NULL) { | |
2982 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
2983 | "network id=%d", id); | |
2984 | return -1; | |
2985 | } | |
4dac0245 JM |
2986 | if (ssid->disabled == 2) { |
2987 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
2988 | "SELECT_NETWORK with persistent P2P group"); | |
2989 | return -1; | |
2990 | } | |
6fc6879b JM |
2991 | } |
2992 | ||
204c9ac4 DS |
2993 | pos = os_strstr(cmd, " freq="); |
2994 | if (pos) { | |
2995 | int *freqs = freq_range_to_channel_list(wpa_s, pos + 6); | |
2996 | if (freqs) { | |
88a44755 JM |
2997 | os_free(wpa_s->select_network_scan_freqs); |
2998 | wpa_s->select_network_scan_freqs = freqs; | |
204c9ac4 DS |
2999 | } |
3000 | } | |
3001 | ||
dfaf11d6 JM |
3002 | wpa_s->scan_min_time.sec = 0; |
3003 | wpa_s->scan_min_time.usec = 0; | |
86b89452 | 3004 | wpa_supplicant_select_network(wpa_s, ssid); |
6fc6879b JM |
3005 | |
3006 | return 0; | |
3007 | } | |
3008 | ||
3009 | ||
3010 | static int wpa_supplicant_ctrl_iface_enable_network( | |
3011 | struct wpa_supplicant *wpa_s, char *cmd) | |
3012 | { | |
3013 | int id; | |
3014 | struct wpa_ssid *ssid; | |
3015 | ||
3016 | /* cmd: "<network id>" or "all" */ | |
3017 | if (os_strcmp(cmd, "all") == 0) { | |
3018 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); | |
86b89452 WS |
3019 | ssid = NULL; |
3020 | } else { | |
3021 | id = atoi(cmd); | |
3022 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); | |
6fc6879b | 3023 | |
86b89452 WS |
3024 | ssid = wpa_config_get_network(wpa_s->conf, id); |
3025 | if (ssid == NULL) { | |
3026 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
3027 | "network id=%d", id); | |
3028 | return -1; | |
3029 | } | |
4dac0245 JM |
3030 | if (ssid->disabled == 2) { |
3031 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
3032 | "ENABLE_NETWORK with persistent P2P group"); | |
3033 | return -1; | |
3034 | } | |
84c78f95 JM |
3035 | |
3036 | if (os_strstr(cmd, " no-connect")) { | |
3037 | ssid->disabled = 0; | |
3038 | return 0; | |
3039 | } | |
6fc6879b | 3040 | } |
dfaf11d6 JM |
3041 | wpa_s->scan_min_time.sec = 0; |
3042 | wpa_s->scan_min_time.usec = 0; | |
86b89452 | 3043 | wpa_supplicant_enable_network(wpa_s, ssid); |
6fc6879b JM |
3044 | |
3045 | return 0; | |
3046 | } | |
3047 | ||
3048 | ||
3049 | static int wpa_supplicant_ctrl_iface_disable_network( | |
3050 | struct wpa_supplicant *wpa_s, char *cmd) | |
3051 | { | |
3052 | int id; | |
3053 | struct wpa_ssid *ssid; | |
3054 | ||
3055 | /* cmd: "<network id>" or "all" */ | |
3056 | if (os_strcmp(cmd, "all") == 0) { | |
3057 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); | |
86b89452 WS |
3058 | ssid = NULL; |
3059 | } else { | |
3060 | id = atoi(cmd); | |
3061 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); | |
6fc6879b | 3062 | |
86b89452 WS |
3063 | ssid = wpa_config_get_network(wpa_s->conf, id); |
3064 | if (ssid == NULL) { | |
3065 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
3066 | "network id=%d", id); | |
3067 | return -1; | |
3068 | } | |
4dac0245 JM |
3069 | if (ssid->disabled == 2) { |
3070 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | |
3071 | "DISABLE_NETWORK with persistent P2P " | |
3072 | "group"); | |
3073 | return -1; | |
3074 | } | |
6fc6879b | 3075 | } |
86b89452 | 3076 | wpa_supplicant_disable_network(wpa_s, ssid); |
6fc6879b JM |
3077 | |
3078 | return 0; | |
3079 | } | |
3080 | ||
3081 | ||
3082 | static int wpa_supplicant_ctrl_iface_add_network( | |
3083 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | |
3084 | { | |
3085 | struct wpa_ssid *ssid; | |
3086 | int ret; | |
3087 | ||
3088 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); | |
3089 | ||
d015bb05 | 3090 | ssid = wpa_supplicant_add_network(wpa_s); |
6fc6879b JM |
3091 | if (ssid == NULL) |
3092 | return -1; | |
8bac466b | 3093 | |
6fc6879b | 3094 | ret = os_snprintf(buf, buflen, "%d\n", ssid->id); |
d85e1fc8 | 3095 | if (os_snprintf_error(buflen, ret)) |
6fc6879b JM |
3096 | return -1; |
3097 | return ret; | |
3098 | } | |
3099 | ||
3100 | ||
3101 | static int wpa_supplicant_ctrl_iface_remove_network( | |
3102 | struct wpa_supplicant *wpa_s, char *cmd) | |
3103 | { | |
3104 | int id; | |
3105 | struct wpa_ssid *ssid; | |
d015bb05 | 3106 | int result; |
6fc6879b JM |
3107 | |
3108 | /* cmd: "<network id>" or "all" */ | |
3109 | if (os_strcmp(cmd, "all") == 0) { | |
3110 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); | |
725fc39e DS |
3111 | if (wpa_s->sched_scanning) |
3112 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
3113 | ||
d8a790b9 | 3114 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
6fc6879b | 3115 | if (wpa_s->current_ssid) { |
83df8149 JM |
3116 | #ifdef CONFIG_SME |
3117 | wpa_s->sme.prev_bssid_set = 0; | |
3118 | #endif /* CONFIG_SME */ | |
20a0b03d JM |
3119 | wpa_sm_set_config(wpa_s->wpa, NULL); |
3120 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | |
e66bcedd JM |
3121 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
3122 | wpa_s->own_disconnect_req = 1; | |
07783eaa JM |
3123 | wpa_supplicant_deauthenticate( |
3124 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
6fc6879b | 3125 | } |
391f4925 JK |
3126 | ssid = wpa_s->conf->ssid; |
3127 | while (ssid) { | |
3128 | struct wpa_ssid *remove_ssid = ssid; | |
3129 | id = ssid->id; | |
3130 | ssid = ssid->next; | |
c267753b JM |
3131 | if (wpa_s->last_ssid == remove_ssid) |
3132 | wpa_s->last_ssid = NULL; | |
391f4925 JK |
3133 | wpas_notify_network_removed(wpa_s, remove_ssid); |
3134 | wpa_config_remove_network(wpa_s->conf, id); | |
3135 | } | |
6fc6879b JM |
3136 | return 0; |
3137 | } | |
3138 | ||
3139 | id = atoi(cmd); | |
3140 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); | |
3141 | ||
d015bb05 RP |
3142 | result = wpa_supplicant_remove_network(wpa_s, id); |
3143 | if (result == -1) { | |
6fc6879b JM |
3144 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
3145 | "id=%d", id); | |
3146 | return -1; | |
3147 | } | |
d015bb05 | 3148 | if (result == -2) { |
59ff6653 DG |
3149 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the " |
3150 | "network id=%d", id); | |
3151 | return -1; | |
3152 | } | |
6fc6879b JM |
3153 | return 0; |
3154 | } | |
3155 | ||
3156 | ||
1c330a2f DS |
3157 | static int wpa_supplicant_ctrl_iface_update_network( |
3158 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, | |
3159 | char *name, char *value) | |
3160 | { | |
5cd317d3 BKB |
3161 | int ret; |
3162 | ||
3163 | ret = wpa_config_set(ssid, name, value, 0); | |
3164 | if (ret < 0) { | |
1c330a2f DS |
3165 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " |
3166 | "variable '%s'", name); | |
3167 | return -1; | |
3168 | } | |
5cd317d3 BKB |
3169 | if (ret == 1) |
3170 | return 0; /* No change to the previously configured value */ | |
1c330a2f DS |
3171 | |
3172 | if (os_strcmp(name, "bssid") != 0 && | |
c3dc68e8 | 3173 | os_strcmp(name, "priority") != 0) { |
1c330a2f DS |
3174 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
3175 | ||
c3dc68e8 JM |
3176 | if (wpa_s->current_ssid == ssid || |
3177 | wpa_s->current_ssid == NULL) { | |
3178 | /* | |
3179 | * Invalidate the EAP session cache if anything in the | |
3180 | * current or previously used configuration changes. | |
3181 | */ | |
3182 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
3183 | } | |
1c330a2f DS |
3184 | } |
3185 | ||
3186 | if ((os_strcmp(name, "psk") == 0 && | |
3187 | value[0] == '"' && ssid->ssid_len) || | |
3188 | (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) | |
3189 | wpa_config_update_psk(ssid); | |
3190 | else if (os_strcmp(name, "priority") == 0) | |
3191 | wpa_config_update_prio_list(wpa_s->conf); | |
3192 | ||
3193 | return 0; | |
3194 | } | |
3195 | ||
3196 | ||
6fc6879b JM |
3197 | static int wpa_supplicant_ctrl_iface_set_network( |
3198 | struct wpa_supplicant *wpa_s, char *cmd) | |
3199 | { | |
1e529832 | 3200 | int id, ret, prev_bssid_set, prev_disabled; |
6fc6879b JM |
3201 | struct wpa_ssid *ssid; |
3202 | char *name, *value; | |
0ef023e4 | 3203 | u8 prev_bssid[ETH_ALEN]; |
6fc6879b JM |
3204 | |
3205 | /* cmd: "<network id> <variable name> <value>" */ | |
3206 | name = os_strchr(cmd, ' '); | |
3207 | if (name == NULL) | |
3208 | return -1; | |
3209 | *name++ = '\0'; | |
3210 | ||
3211 | value = os_strchr(name, ' '); | |
3212 | if (value == NULL) | |
3213 | return -1; | |
3214 | *value++ = '\0'; | |
3215 | ||
3216 | id = atoi(cmd); | |
3217 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", | |
3218 | id, name); | |
3219 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
3220 | (u8 *) value, os_strlen(value)); | |
3221 | ||
3222 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
3223 | if (ssid == NULL) { | |
3224 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | |
3225 | "id=%d", id); | |
3226 | return -1; | |
3227 | } | |
3228 | ||
0ef023e4 | 3229 | prev_bssid_set = ssid->bssid_set; |
1e529832 | 3230 | prev_disabled = ssid->disabled; |
0ef023e4 JM |
3231 | os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN); |
3232 | ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name, | |
3233 | value); | |
3234 | if (ret == 0 && | |
3235 | (ssid->bssid_set != prev_bssid_set || | |
3236 | os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0)) | |
3237 | wpas_notify_network_bssid_set_changed(wpa_s, ssid); | |
1e529832 JM |
3238 | |
3239 | if (prev_disabled != ssid->disabled && | |
3240 | (prev_disabled == 2 || ssid->disabled == 2)) | |
3241 | wpas_notify_network_type_changed(wpa_s, ssid); | |
3242 | ||
0ef023e4 | 3243 | return ret; |
6fc6879b JM |
3244 | } |
3245 | ||
3246 | ||
3247 | static int wpa_supplicant_ctrl_iface_get_network( | |
3248 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
3249 | { | |
3250 | int id; | |
3251 | size_t res; | |
3252 | struct wpa_ssid *ssid; | |
3253 | char *name, *value; | |
3254 | ||
3255 | /* cmd: "<network id> <variable name>" */ | |
3256 | name = os_strchr(cmd, ' '); | |
3257 | if (name == NULL || buflen == 0) | |
3258 | return -1; | |
3259 | *name++ = '\0'; | |
3260 | ||
3261 | id = atoi(cmd); | |
8db9a79d | 3262 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'", |
6fc6879b JM |
3263 | id, name); |
3264 | ||
3265 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
3266 | if (ssid == NULL) { | |
8db9a79d | 3267 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network " |
6fc6879b JM |
3268 | "id=%d", id); |
3269 | return -1; | |
3270 | } | |
3271 | ||
3272 | value = wpa_config_get_no_key(ssid, name); | |
3273 | if (value == NULL) { | |
8db9a79d | 3274 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network " |
6fc6879b JM |
3275 | "variable '%s'", name); |
3276 | return -1; | |
3277 | } | |
3278 | ||
3279 | res = os_strlcpy(buf, value, buflen); | |
3280 | if (res >= buflen) { | |
3281 | os_free(value); | |
3282 | return -1; | |
3283 | } | |
3284 | ||
3285 | os_free(value); | |
3286 | ||
3287 | return res; | |
3288 | } | |
3289 | ||
3290 | ||
1c330a2f | 3291 | static int wpa_supplicant_ctrl_iface_dup_network( |
daae4995 AN |
3292 | struct wpa_supplicant *wpa_s, char *cmd, |
3293 | struct wpa_supplicant *dst_wpa_s) | |
1c330a2f DS |
3294 | { |
3295 | struct wpa_ssid *ssid_s, *ssid_d; | |
3296 | char *name, *id, *value; | |
3297 | int id_s, id_d, ret; | |
3298 | ||
3299 | /* cmd: "<src network id> <dst network id> <variable name>" */ | |
3300 | id = os_strchr(cmd, ' '); | |
3301 | if (id == NULL) | |
3302 | return -1; | |
3303 | *id++ = '\0'; | |
3304 | ||
3305 | name = os_strchr(id, ' '); | |
3306 | if (name == NULL) | |
3307 | return -1; | |
3308 | *name++ = '\0'; | |
3309 | ||
3310 | id_s = atoi(cmd); | |
3311 | id_d = atoi(id); | |
daae4995 AN |
3312 | |
3313 | wpa_printf(MSG_DEBUG, | |
3314 | "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'", | |
3315 | wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name); | |
1c330a2f DS |
3316 | |
3317 | ssid_s = wpa_config_get_network(wpa_s->conf, id_s); | |
3318 | if (ssid_s == NULL) { | |
3319 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
3320 | "network id=%d", id_s); | |
3321 | return -1; | |
3322 | } | |
3323 | ||
daae4995 | 3324 | ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d); |
1c330a2f DS |
3325 | if (ssid_d == NULL) { |
3326 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
c0541906 | 3327 | "network id=%d", id_d); |
1c330a2f DS |
3328 | return -1; |
3329 | } | |
3330 | ||
3331 | value = wpa_config_get(ssid_s, name); | |
3332 | if (value == NULL) { | |
3333 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " | |
3334 | "variable '%s'", name); | |
3335 | return -1; | |
3336 | } | |
3337 | ||
daae4995 | 3338 | ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name, |
1c330a2f DS |
3339 | value); |
3340 | ||
3341 | os_free(value); | |
3342 | ||
3343 | return ret; | |
3344 | } | |
3345 | ||
3346 | ||
d94c9ee6 JM |
3347 | static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s, |
3348 | char *buf, size_t buflen) | |
3349 | { | |
3350 | char *pos, *end; | |
3351 | struct wpa_cred *cred; | |
3352 | int ret; | |
3353 | ||
3354 | pos = buf; | |
3355 | end = buf + buflen; | |
3356 | ret = os_snprintf(pos, end - pos, | |
3357 | "cred id / realm / username / domain / imsi\n"); | |
d85e1fc8 | 3358 | if (os_snprintf_error(end - pos, ret)) |
d94c9ee6 JM |
3359 | return pos - buf; |
3360 | pos += ret; | |
3361 | ||
3362 | cred = wpa_s->conf->cred; | |
3363 | while (cred) { | |
3364 | ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n", | |
3365 | cred->id, cred->realm ? cred->realm : "", | |
3366 | cred->username ? cred->username : "", | |
463c8ffb | 3367 | cred->domain ? cred->domain[0] : "", |
d94c9ee6 | 3368 | cred->imsi ? cred->imsi : ""); |
d85e1fc8 | 3369 | if (os_snprintf_error(end - pos, ret)) |
d94c9ee6 JM |
3370 | return pos - buf; |
3371 | pos += ret; | |
3372 | ||
3373 | cred = cred->next; | |
3374 | } | |
3375 | ||
3376 | return pos - buf; | |
3377 | } | |
3378 | ||
3379 | ||
3380 | static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s, | |
3381 | char *buf, size_t buflen) | |
3382 | { | |
3383 | struct wpa_cred *cred; | |
3384 | int ret; | |
3385 | ||
3386 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED"); | |
3387 | ||
3388 | cred = wpa_config_add_cred(wpa_s->conf); | |
3389 | if (cred == NULL) | |
3390 | return -1; | |
3391 | ||
1619e9d5 JM |
3392 | wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id); |
3393 | ||
d94c9ee6 | 3394 | ret = os_snprintf(buf, buflen, "%d\n", cred->id); |
d85e1fc8 | 3395 | if (os_snprintf_error(buflen, ret)) |
d94c9ee6 JM |
3396 | return -1; |
3397 | return ret; | |
3398 | } | |
3399 | ||
3400 | ||
736d4f2d JM |
3401 | static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s, |
3402 | struct wpa_cred *cred) | |
3403 | { | |
3404 | struct wpa_ssid *ssid; | |
3405 | char str[20]; | |
1619e9d5 | 3406 | int id; |
736d4f2d | 3407 | |
1619e9d5 | 3408 | if (cred == NULL) { |
736d4f2d JM |
3409 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); |
3410 | return -1; | |
3411 | } | |
3412 | ||
1619e9d5 JM |
3413 | id = cred->id; |
3414 | if (wpa_config_remove_cred(wpa_s->conf, id) < 0) { | |
3415 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); | |
3416 | return -1; | |
3417 | } | |
3418 | ||
3419 | wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id); | |
3420 | ||
736d4f2d JM |
3421 | /* Remove any network entry created based on the removed credential */ |
3422 | ssid = wpa_s->conf->ssid; | |
3423 | while (ssid) { | |
3424 | if (ssid->parent_cred == cred) { | |
1d399771 JM |
3425 | int res; |
3426 | ||
736d4f2d JM |
3427 | wpa_printf(MSG_DEBUG, "Remove network id %d since it " |
3428 | "used the removed credential", ssid->id); | |
1d399771 JM |
3429 | res = os_snprintf(str, sizeof(str), "%d", ssid->id); |
3430 | if (os_snprintf_error(sizeof(str), res)) | |
3431 | str[sizeof(str) - 1] = '\0'; | |
736d4f2d JM |
3432 | ssid = ssid->next; |
3433 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, str); | |
3434 | } else | |
3435 | ssid = ssid->next; | |
3436 | } | |
3437 | ||
3438 | return 0; | |
3439 | } | |
3440 | ||
3441 | ||
d94c9ee6 JM |
3442 | static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s, |
3443 | char *cmd) | |
3444 | { | |
3445 | int id; | |
736d4f2d | 3446 | struct wpa_cred *cred, *prev; |
d94c9ee6 | 3447 | |
aa26ba68 JM |
3448 | /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or |
3449 | * "provisioning_sp=<FQDN> */ | |
d94c9ee6 JM |
3450 | if (os_strcmp(cmd, "all") == 0) { |
3451 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all"); | |
3452 | cred = wpa_s->conf->cred; | |
3453 | while (cred) { | |
736d4f2d | 3454 | prev = cred; |
d94c9ee6 | 3455 | cred = cred->next; |
736d4f2d | 3456 | wpas_ctrl_remove_cred(wpa_s, prev); |
d94c9ee6 JM |
3457 | } |
3458 | return 0; | |
3459 | } | |
3460 | ||
9afe52eb JM |
3461 | if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) { |
3462 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'", | |
3463 | cmd + 8); | |
3464 | cred = wpa_s->conf->cred; | |
3465 | while (cred) { | |
3466 | prev = cred; | |
3467 | cred = cred->next; | |
463c8ffb JM |
3468 | if (prev->domain) { |
3469 | size_t i; | |
3470 | for (i = 0; i < prev->num_domain; i++) { | |
3471 | if (os_strcmp(prev->domain[i], cmd + 8) | |
3472 | != 0) | |
3473 | continue; | |
3474 | wpas_ctrl_remove_cred(wpa_s, prev); | |
3475 | break; | |
3476 | } | |
3477 | } | |
9afe52eb JM |
3478 | } |
3479 | return 0; | |
3480 | } | |
3481 | ||
aa26ba68 JM |
3482 | if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) { |
3483 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'", | |
3484 | cmd + 16); | |
3485 | cred = wpa_s->conf->cred; | |
3486 | while (cred) { | |
3487 | prev = cred; | |
3488 | cred = cred->next; | |
3489 | if (prev->provisioning_sp && | |
3490 | os_strcmp(prev->provisioning_sp, cmd + 16) == 0) | |
3491 | wpas_ctrl_remove_cred(wpa_s, prev); | |
3492 | } | |
3493 | return 0; | |
3494 | } | |
3495 | ||
d94c9ee6 JM |
3496 | id = atoi(cmd); |
3497 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id); | |
3498 | ||
3499 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
736d4f2d | 3500 | return wpas_ctrl_remove_cred(wpa_s, cred); |
d94c9ee6 JM |
3501 | } |
3502 | ||
3503 | ||
3504 | static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s, | |
3505 | char *cmd) | |
3506 | { | |
3507 | int id; | |
3508 | struct wpa_cred *cred; | |
3509 | char *name, *value; | |
3510 | ||
3511 | /* cmd: "<cred id> <variable name> <value>" */ | |
3512 | name = os_strchr(cmd, ' '); | |
3513 | if (name == NULL) | |
3514 | return -1; | |
3515 | *name++ = '\0'; | |
3516 | ||
3517 | value = os_strchr(name, ' '); | |
3518 | if (value == NULL) | |
3519 | return -1; | |
3520 | *value++ = '\0'; | |
3521 | ||
3522 | id = atoi(cmd); | |
3523 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'", | |
3524 | id, name); | |
3525 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | |
3526 | (u8 *) value, os_strlen(value)); | |
3527 | ||
3528 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
3529 | if (cred == NULL) { | |
3530 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | |
3531 | id); | |
3532 | return -1; | |
3533 | } | |
3534 | ||
3535 | if (wpa_config_set_cred(cred, name, value, 0) < 0) { | |
3536 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred " | |
3537 | "variable '%s'", name); | |
3538 | return -1; | |
3539 | } | |
3540 | ||
1619e9d5 JM |
3541 | wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name); |
3542 | ||
d94c9ee6 JM |
3543 | return 0; |
3544 | } | |
3545 | ||
3546 | ||
c880ab87 JM |
3547 | static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s, |
3548 | char *cmd, char *buf, | |
3549 | size_t buflen) | |
3550 | { | |
3551 | int id; | |
3552 | size_t res; | |
3553 | struct wpa_cred *cred; | |
3554 | char *name, *value; | |
3555 | ||
3556 | /* cmd: "<cred id> <variable name>" */ | |
3557 | name = os_strchr(cmd, ' '); | |
3558 | if (name == NULL) | |
3559 | return -1; | |
3560 | *name++ = '\0'; | |
3561 | ||
3562 | id = atoi(cmd); | |
3563 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'", | |
3564 | id, name); | |
3565 | ||
3566 | cred = wpa_config_get_cred(wpa_s->conf, id); | |
3567 | if (cred == NULL) { | |
3568 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | |
3569 | id); | |
3570 | return -1; | |
3571 | } | |
3572 | ||
3573 | value = wpa_config_get_cred_no_key(cred, name); | |
3574 | if (value == NULL) { | |
3575 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'", | |
3576 | name); | |
3577 | return -1; | |
3578 | } | |
3579 | ||
3580 | res = os_strlcpy(buf, value, buflen); | |
3581 | if (res >= buflen) { | |
3582 | os_free(value); | |
3583 | return -1; | |
3584 | } | |
3585 | ||
3586 | os_free(value); | |
3587 | ||
3588 | return res; | |
3589 | } | |
3590 | ||
3591 | ||
6fc6879b JM |
3592 | #ifndef CONFIG_NO_CONFIG_WRITE |
3593 | static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s) | |
3594 | { | |
3595 | int ret; | |
3596 | ||
3597 | if (!wpa_s->conf->update_config) { | |
3598 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed " | |
3599 | "to update configuration (update_config=0)"); | |
3600 | return -1; | |
3601 | } | |
3602 | ||
3603 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); | |
3604 | if (ret) { | |
3605 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to " | |
3606 | "update configuration"); | |
3607 | } else { | |
3608 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration" | |
3609 | " updated"); | |
3610 | } | |
3611 | ||
3612 | return ret; | |
3613 | } | |
3614 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
3615 | ||
3616 | ||
4daa011b JM |
3617 | struct cipher_info { |
3618 | unsigned int capa; | |
3619 | const char *name; | |
3620 | int group_only; | |
3621 | }; | |
3622 | ||
3623 | static const struct cipher_info ciphers[] = { | |
3624 | { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 }, | |
3625 | { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 }, | |
3626 | { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 }, | |
3627 | { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 }, | |
3628 | { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 }, | |
3629 | { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 }, | |
3630 | { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 }, | |
3631 | { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 } | |
3632 | }; | |
3633 | ||
b5f045de JM |
3634 | static const struct cipher_info ciphers_group_mgmt[] = { |
3635 | { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 }, | |
3636 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 }, | |
3637 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 }, | |
3638 | { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 }, | |
3639 | }; | |
3640 | ||
4daa011b | 3641 | |
6fc6879b JM |
3642 | static int ctrl_iface_get_capability_pairwise(int res, char *strict, |
3643 | struct wpa_driver_capa *capa, | |
3644 | char *buf, size_t buflen) | |
3645 | { | |
ea3b8c1d | 3646 | int ret; |
6fc6879b JM |
3647 | char *pos, *end; |
3648 | size_t len; | |
4daa011b | 3649 | unsigned int i; |
6fc6879b JM |
3650 | |
3651 | pos = buf; | |
3652 | end = pos + buflen; | |
3653 | ||
3654 | if (res < 0) { | |
3655 | if (strict) | |
3656 | return 0; | |
3657 | len = os_strlcpy(buf, "CCMP TKIP NONE", buflen); | |
3658 | if (len >= buflen) | |
3659 | return -1; | |
3660 | return len; | |
3661 | } | |
3662 | ||
4daa011b JM |
3663 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
3664 | if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) { | |
3665 | ret = os_snprintf(pos, end - pos, "%s%s", | |
ea3b8c1d JM |
3666 | pos == buf ? "" : " ", |
3667 | ciphers[i].name); | |
d85e1fc8 | 3668 | if (os_snprintf_error(end - pos, ret)) |
4daa011b JM |
3669 | return pos - buf; |
3670 | pos += ret; | |
4daa011b | 3671 | } |
6fc6879b JM |
3672 | } |
3673 | ||
3674 | return pos - buf; | |
3675 | } | |
3676 | ||
3677 | ||
3678 | static int ctrl_iface_get_capability_group(int res, char *strict, | |
3679 | struct wpa_driver_capa *capa, | |
3680 | char *buf, size_t buflen) | |
3681 | { | |
ea3b8c1d | 3682 | int ret; |
6fc6879b JM |
3683 | char *pos, *end; |
3684 | size_t len; | |
4daa011b | 3685 | unsigned int i; |
6fc6879b JM |
3686 | |
3687 | pos = buf; | |
3688 | end = pos + buflen; | |
3689 | ||
3690 | if (res < 0) { | |
3691 | if (strict) | |
3692 | return 0; | |
3693 | len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen); | |
3694 | if (len >= buflen) | |
3695 | return -1; | |
3696 | return len; | |
3697 | } | |
3698 | ||
4daa011b JM |
3699 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
3700 | if (capa->enc & ciphers[i].capa) { | |
3701 | ret = os_snprintf(pos, end - pos, "%s%s", | |
ea3b8c1d JM |
3702 | pos == buf ? "" : " ", |
3703 | ciphers[i].name); | |
d85e1fc8 | 3704 | if (os_snprintf_error(end - pos, ret)) |
4daa011b JM |
3705 | return pos - buf; |
3706 | pos += ret; | |
4daa011b | 3707 | } |
6fc6879b JM |
3708 | } |
3709 | ||
3710 | return pos - buf; | |
3711 | } | |
3712 | ||
3713 | ||
b5f045de JM |
3714 | static int ctrl_iface_get_capability_group_mgmt(int res, char *strict, |
3715 | struct wpa_driver_capa *capa, | |
3716 | char *buf, size_t buflen) | |
3717 | { | |
3718 | int ret; | |
3719 | char *pos, *end; | |
3720 | unsigned int i; | |
3721 | ||
3722 | pos = buf; | |
3723 | end = pos + buflen; | |
3724 | ||
3725 | if (res < 0) | |
3726 | return 0; | |
3727 | ||
3728 | for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) { | |
3729 | if (capa->enc & ciphers_group_mgmt[i].capa) { | |
3730 | ret = os_snprintf(pos, end - pos, "%s%s", | |
3731 | pos == buf ? "" : " ", | |
3732 | ciphers_group_mgmt[i].name); | |
3733 | if (os_snprintf_error(end - pos, ret)) | |
3734 | return pos - buf; | |
3735 | pos += ret; | |
3736 | } | |
3737 | } | |
3738 | ||
3739 | return pos - buf; | |
3740 | } | |
3741 | ||
3742 | ||
6fc6879b JM |
3743 | static int ctrl_iface_get_capability_key_mgmt(int res, char *strict, |
3744 | struct wpa_driver_capa *capa, | |
3745 | char *buf, size_t buflen) | |
3746 | { | |
3747 | int ret; | |
3748 | char *pos, *end; | |
3749 | size_t len; | |
3750 | ||
3751 | pos = buf; | |
3752 | end = pos + buflen; | |
3753 | ||
3754 | if (res < 0) { | |
3755 | if (strict) | |
3756 | return 0; | |
3757 | len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE " | |
3758 | "NONE", buflen); | |
3759 | if (len >= buflen) | |
3760 | return -1; | |
3761 | return len; | |
3762 | } | |
3763 | ||
3764 | ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); | |
d85e1fc8 | 3765 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3766 | return pos - buf; |
3767 | pos += ret; | |
3768 | ||
3769 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
3770 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { | |
3771 | ret = os_snprintf(pos, end - pos, " WPA-EAP"); | |
d85e1fc8 | 3772 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3773 | return pos - buf; |
3774 | pos += ret; | |
3775 | } | |
3776 | ||
3777 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | |
3778 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
3779 | ret = os_snprintf(pos, end - pos, " WPA-PSK"); | |
d85e1fc8 | 3780 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3781 | return pos - buf; |
3782 | pos += ret; | |
3783 | } | |
3784 | ||
3785 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { | |
3786 | ret = os_snprintf(pos, end - pos, " WPA-NONE"); | |
d85e1fc8 | 3787 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3788 | return pos - buf; |
3789 | pos += ret; | |
3790 | } | |
3791 | ||
399e6135 JM |
3792 | #ifdef CONFIG_SUITEB |
3793 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) { | |
3794 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B"); | |
3795 | if (os_snprintf_error(end - pos, ret)) | |
3796 | return pos - buf; | |
3797 | pos += ret; | |
3798 | } | |
3799 | #endif /* CONFIG_SUITEB */ | |
3800 | #ifdef CONFIG_SUITEB192 | |
3801 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) { | |
3802 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192"); | |
3803 | if (os_snprintf_error(end - pos, ret)) | |
3804 | return pos - buf; | |
3805 | pos += ret; | |
3806 | } | |
3807 | #endif /* CONFIG_SUITEB192 */ | |
f9561868 JM |
3808 | #ifdef CONFIG_OWE |
3809 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) { | |
3810 | ret = os_snprintf(pos, end - pos, " OWE"); | |
3811 | if (os_snprintf_error(end - pos, ret)) | |
3812 | return pos - buf; | |
3813 | pos += ret; | |
3814 | } | |
3815 | #endif /* CONFIG_OWE */ | |
399e6135 | 3816 | |
6fc6879b JM |
3817 | return pos - buf; |
3818 | } | |
3819 | ||
3820 | ||
3821 | static int ctrl_iface_get_capability_proto(int res, char *strict, | |
3822 | struct wpa_driver_capa *capa, | |
3823 | char *buf, size_t buflen) | |
3824 | { | |
ea3b8c1d | 3825 | int ret; |
6fc6879b JM |
3826 | char *pos, *end; |
3827 | size_t len; | |
3828 | ||
3829 | pos = buf; | |
3830 | end = pos + buflen; | |
3831 | ||
3832 | if (res < 0) { | |
3833 | if (strict) | |
3834 | return 0; | |
3835 | len = os_strlcpy(buf, "RSN WPA", buflen); | |
3836 | if (len >= buflen) | |
3837 | return -1; | |
3838 | return len; | |
3839 | } | |
3840 | ||
3841 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | |
3842 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | |
ea3b8c1d JM |
3843 | ret = os_snprintf(pos, end - pos, "%sRSN", |
3844 | pos == buf ? "" : " "); | |
d85e1fc8 | 3845 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3846 | return pos - buf; |
3847 | pos += ret; | |
6fc6879b JM |
3848 | } |
3849 | ||
3850 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
3851 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { | |
ea3b8c1d JM |
3852 | ret = os_snprintf(pos, end - pos, "%sWPA", |
3853 | pos == buf ? "" : " "); | |
d85e1fc8 | 3854 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3855 | return pos - buf; |
3856 | pos += ret; | |
6fc6879b JM |
3857 | } |
3858 | ||
3859 | return pos - buf; | |
3860 | } | |
3861 | ||
3862 | ||
db5adfe7 JM |
3863 | static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s, |
3864 | int res, char *strict, | |
6fc6879b JM |
3865 | struct wpa_driver_capa *capa, |
3866 | char *buf, size_t buflen) | |
3867 | { | |
ea3b8c1d | 3868 | int ret; |
6fc6879b JM |
3869 | char *pos, *end; |
3870 | size_t len; | |
3871 | ||
3872 | pos = buf; | |
3873 | end = pos + buflen; | |
3874 | ||
3875 | if (res < 0) { | |
3876 | if (strict) | |
3877 | return 0; | |
3878 | len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen); | |
3879 | if (len >= buflen) | |
3880 | return -1; | |
3881 | return len; | |
3882 | } | |
3883 | ||
3884 | if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) { | |
ea3b8c1d JM |
3885 | ret = os_snprintf(pos, end - pos, "%sOPEN", |
3886 | pos == buf ? "" : " "); | |
d85e1fc8 | 3887 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3888 | return pos - buf; |
3889 | pos += ret; | |
6fc6879b JM |
3890 | } |
3891 | ||
3892 | if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) { | |
3893 | ret = os_snprintf(pos, end - pos, "%sSHARED", | |
ea3b8c1d | 3894 | pos == buf ? "" : " "); |
d85e1fc8 | 3895 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3896 | return pos - buf; |
3897 | pos += ret; | |
6fc6879b JM |
3898 | } |
3899 | ||
3900 | if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) { | |
ea3b8c1d JM |
3901 | ret = os_snprintf(pos, end - pos, "%sLEAP", |
3902 | pos == buf ? "" : " "); | |
d85e1fc8 | 3903 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
3904 | return pos - buf; |
3905 | pos += ret; | |
6fc6879b JM |
3906 | } |
3907 | ||
db5adfe7 JM |
3908 | #ifdef CONFIG_SAE |
3909 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) { | |
3910 | ret = os_snprintf(pos, end - pos, "%sSAE", | |
3911 | pos == buf ? "" : " "); | |
3912 | if (os_snprintf_error(end - pos, ret)) | |
3913 | return pos - buf; | |
3914 | pos += ret; | |
3915 | } | |
3916 | #endif /* CONFIG_SAE */ | |
3917 | ||
6fc6879b JM |
3918 | return pos - buf; |
3919 | } | |
3920 | ||
3921 | ||
65d52fc1 BR |
3922 | static int ctrl_iface_get_capability_modes(int res, char *strict, |
3923 | struct wpa_driver_capa *capa, | |
3924 | char *buf, size_t buflen) | |
3925 | { | |
ea3b8c1d | 3926 | int ret; |
65d52fc1 BR |
3927 | char *pos, *end; |
3928 | size_t len; | |
3929 | ||
3930 | pos = buf; | |
3931 | end = pos + buflen; | |
3932 | ||
3933 | if (res < 0) { | |
3934 | if (strict) | |
3935 | return 0; | |
3936 | len = os_strlcpy(buf, "IBSS AP", buflen); | |
3937 | if (len >= buflen) | |
3938 | return -1; | |
3939 | return len; | |
3940 | } | |
3941 | ||
3942 | if (capa->flags & WPA_DRIVER_FLAGS_IBSS) { | |
ea3b8c1d JM |
3943 | ret = os_snprintf(pos, end - pos, "%sIBSS", |
3944 | pos == buf ? "" : " "); | |
d85e1fc8 | 3945 | if (os_snprintf_error(end - pos, ret)) |
65d52fc1 BR |
3946 | return pos - buf; |
3947 | pos += ret; | |
65d52fc1 BR |
3948 | } |
3949 | ||
3950 | if (capa->flags & WPA_DRIVER_FLAGS_AP) { | |
ea3b8c1d JM |
3951 | ret = os_snprintf(pos, end - pos, "%sAP", |
3952 | pos == buf ? "" : " "); | |
d85e1fc8 | 3953 | if (os_snprintf_error(end - pos, ret)) |
65d52fc1 BR |
3954 | return pos - buf; |
3955 | pos += ret; | |
65d52fc1 BR |
3956 | } |
3957 | ||
cf08e9b1 JM |
3958 | #ifdef CONFIG_MESH |
3959 | if (capa->flags & WPA_DRIVER_FLAGS_MESH) { | |
3960 | ret = os_snprintf(pos, end - pos, "%sMESH", | |
3961 | pos == buf ? "" : " "); | |
3962 | if (os_snprintf_error(end - pos, ret)) | |
3963 | return pos - buf; | |
3964 | pos += ret; | |
3965 | } | |
3966 | #endif /* CONFIG_MESH */ | |
3967 | ||
65d52fc1 BR |
3968 | return pos - buf; |
3969 | } | |
3970 | ||
3971 | ||
35aa088a DS |
3972 | static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s, |
3973 | char *buf, size_t buflen) | |
3974 | { | |
3975 | struct hostapd_channel_data *chnl; | |
3976 | int ret, i, j; | |
3977 | char *pos, *end, *hmode; | |
3978 | ||
3979 | pos = buf; | |
3980 | end = pos + buflen; | |
3981 | ||
3982 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | |
3983 | switch (wpa_s->hw.modes[j].mode) { | |
3984 | case HOSTAPD_MODE_IEEE80211B: | |
3985 | hmode = "B"; | |
3986 | break; | |
3987 | case HOSTAPD_MODE_IEEE80211G: | |
3988 | hmode = "G"; | |
3989 | break; | |
3990 | case HOSTAPD_MODE_IEEE80211A: | |
3991 | hmode = "A"; | |
3992 | break; | |
7829894c VK |
3993 | case HOSTAPD_MODE_IEEE80211AD: |
3994 | hmode = "AD"; | |
3995 | break; | |
35aa088a DS |
3996 | default: |
3997 | continue; | |
3998 | } | |
3999 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode); | |
d85e1fc8 | 4000 | if (os_snprintf_error(end - pos, ret)) |
35aa088a DS |
4001 | return pos - buf; |
4002 | pos += ret; | |
4003 | chnl = wpa_s->hw.modes[j].channels; | |
4004 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | |
4005 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | |
4006 | continue; | |
4007 | ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan); | |
d85e1fc8 | 4008 | if (os_snprintf_error(end - pos, ret)) |
35aa088a DS |
4009 | return pos - buf; |
4010 | pos += ret; | |
4011 | } | |
4012 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4013 | if (os_snprintf_error(end - pos, ret)) |
35aa088a DS |
4014 | return pos - buf; |
4015 | pos += ret; | |
4016 | } | |
4017 | ||
4018 | return pos - buf; | |
4019 | } | |
4020 | ||
4021 | ||
06060522 BR |
4022 | static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s, |
4023 | char *buf, size_t buflen) | |
4024 | { | |
4025 | struct hostapd_channel_data *chnl; | |
4026 | int ret, i, j; | |
4027 | char *pos, *end, *hmode; | |
4028 | ||
4029 | pos = buf; | |
4030 | end = pos + buflen; | |
4031 | ||
4032 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | |
4033 | switch (wpa_s->hw.modes[j].mode) { | |
4034 | case HOSTAPD_MODE_IEEE80211B: | |
4035 | hmode = "B"; | |
4036 | break; | |
4037 | case HOSTAPD_MODE_IEEE80211G: | |
4038 | hmode = "G"; | |
4039 | break; | |
4040 | case HOSTAPD_MODE_IEEE80211A: | |
4041 | hmode = "A"; | |
4042 | break; | |
4043 | case HOSTAPD_MODE_IEEE80211AD: | |
4044 | hmode = "AD"; | |
4045 | break; | |
4046 | default: | |
4047 | continue; | |
4048 | } | |
4049 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n", | |
4050 | hmode); | |
d85e1fc8 | 4051 | if (os_snprintf_error(end - pos, ret)) |
06060522 BR |
4052 | return pos - buf; |
4053 | pos += ret; | |
4054 | chnl = wpa_s->hw.modes[j].channels; | |
4055 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | |
4056 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | |
4057 | continue; | |
0547124d | 4058 | ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n", |
06060522 | 4059 | chnl[i].chan, chnl[i].freq, |
0a443580 IP |
4060 | chnl[i].flag & HOSTAPD_CHAN_NO_IR ? |
4061 | " (NO_IR)" : "", | |
0547124d DS |
4062 | chnl[i].flag & HOSTAPD_CHAN_RADAR ? |
4063 | " (DFS)" : ""); | |
4064 | ||
d85e1fc8 | 4065 | if (os_snprintf_error(end - pos, ret)) |
06060522 BR |
4066 | return pos - buf; |
4067 | pos += ret; | |
4068 | } | |
4069 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4070 | if (os_snprintf_error(end - pos, ret)) |
06060522 BR |
4071 | return pos - buf; |
4072 | pos += ret; | |
4073 | } | |
4074 | ||
4075 | return pos - buf; | |
4076 | } | |
4077 | ||
4078 | ||
6fc6879b JM |
4079 | static int wpa_supplicant_ctrl_iface_get_capability( |
4080 | struct wpa_supplicant *wpa_s, const char *_field, char *buf, | |
4081 | size_t buflen) | |
4082 | { | |
4083 | struct wpa_driver_capa capa; | |
4084 | int res; | |
4085 | char *strict; | |
4086 | char field[30]; | |
4087 | size_t len; | |
4088 | ||
4089 | /* Determine whether or not strict checking was requested */ | |
4090 | len = os_strlcpy(field, _field, sizeof(field)); | |
4091 | if (len >= sizeof(field)) | |
4092 | return -1; | |
4093 | strict = os_strchr(field, ' '); | |
4094 | if (strict != NULL) { | |
4095 | *strict++ = '\0'; | |
4096 | if (os_strcmp(strict, "strict") != 0) | |
4097 | return -1; | |
4098 | } | |
4099 | ||
4100 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s", | |
4101 | field, strict ? strict : ""); | |
4102 | ||
4103 | if (os_strcmp(field, "eap") == 0) { | |
4104 | return eap_get_names(buf, buflen); | |
4105 | } | |
4106 | ||
4107 | res = wpa_drv_get_capa(wpa_s, &capa); | |
4108 | ||
4109 | if (os_strcmp(field, "pairwise") == 0) | |
4110 | return ctrl_iface_get_capability_pairwise(res, strict, &capa, | |
4111 | buf, buflen); | |
4112 | ||
4113 | if (os_strcmp(field, "group") == 0) | |
4114 | return ctrl_iface_get_capability_group(res, strict, &capa, | |
4115 | buf, buflen); | |
4116 | ||
b5f045de JM |
4117 | if (os_strcmp(field, "group_mgmt") == 0) |
4118 | return ctrl_iface_get_capability_group_mgmt(res, strict, &capa, | |
4119 | buf, buflen); | |
4120 | ||
6fc6879b JM |
4121 | if (os_strcmp(field, "key_mgmt") == 0) |
4122 | return ctrl_iface_get_capability_key_mgmt(res, strict, &capa, | |
4123 | buf, buflen); | |
4124 | ||
4125 | if (os_strcmp(field, "proto") == 0) | |
4126 | return ctrl_iface_get_capability_proto(res, strict, &capa, | |
4127 | buf, buflen); | |
4128 | ||
4129 | if (os_strcmp(field, "auth_alg") == 0) | |
db5adfe7 JM |
4130 | return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict, |
4131 | &capa, buf, buflen); | |
6fc6879b | 4132 | |
65d52fc1 BR |
4133 | if (os_strcmp(field, "modes") == 0) |
4134 | return ctrl_iface_get_capability_modes(res, strict, &capa, | |
4135 | buf, buflen); | |
4136 | ||
35aa088a DS |
4137 | if (os_strcmp(field, "channels") == 0) |
4138 | return ctrl_iface_get_capability_channels(wpa_s, buf, buflen); | |
4139 | ||
06060522 BR |
4140 | if (os_strcmp(field, "freq") == 0) |
4141 | return ctrl_iface_get_capability_freq(wpa_s, buf, buflen); | |
4142 | ||
6e9375e4 DS |
4143 | #ifdef CONFIG_TDLS |
4144 | if (os_strcmp(field, "tdls") == 0) | |
4145 | return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen); | |
4146 | #endif /* CONFIG_TDLS */ | |
4147 | ||
02a8d45a JM |
4148 | #ifdef CONFIG_ERP |
4149 | if (os_strcmp(field, "erp") == 0) { | |
4150 | res = os_snprintf(buf, buflen, "ERP"); | |
d85e1fc8 | 4151 | if (os_snprintf_error(buflen, res)) |
02a8d45a JM |
4152 | return -1; |
4153 | return res; | |
4154 | } | |
4155 | #endif /* CONFIG_EPR */ | |
4156 | ||
1e4f7bf5 JM |
4157 | #ifdef CONFIG_FIPS |
4158 | if (os_strcmp(field, "fips") == 0) { | |
4159 | res = os_snprintf(buf, buflen, "FIPS"); | |
4160 | if (os_snprintf_error(buflen, res)) | |
4161 | return -1; | |
4162 | return res; | |
4163 | } | |
4164 | #endif /* CONFIG_FIPS */ | |
4165 | ||
7d2f6743 JM |
4166 | #ifdef CONFIG_ACS |
4167 | if (os_strcmp(field, "acs") == 0) { | |
4168 | res = os_snprintf(buf, buflen, "ACS"); | |
4169 | if (os_snprintf_error(buflen, res)) | |
4170 | return -1; | |
4171 | return res; | |
4172 | } | |
4173 | #endif /* CONFIG_ACS */ | |
4174 | ||
379e2b4d | 4175 | #ifdef CONFIG_FILS |
061dac1d JM |
4176 | if (os_strcmp(field, "fils") == 0 && |
4177 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_FILS)) { | |
31e130f8 JM |
4178 | #ifdef CONFIG_FILS_SK_PFS |
4179 | res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS"); | |
4180 | #else /* CONFIG_FILS_SK_PFS */ | |
379e2b4d | 4181 | res = os_snprintf(buf, buflen, "FILS"); |
31e130f8 | 4182 | #endif /* CONFIG_FILS_SK_PFS */ |
379e2b4d JM |
4183 | if (os_snprintf_error(buflen, res)) |
4184 | return -1; | |
4185 | return res; | |
4186 | } | |
4187 | #endif /* CONFIG_FILS */ | |
4188 | ||
6fc6879b JM |
4189 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", |
4190 | field); | |
4191 | ||
4192 | return -1; | |
4193 | } | |
4194 | ||
4195 | ||
afc064fe JM |
4196 | #ifdef CONFIG_INTERWORKING |
4197 | static char * anqp_add_hex(char *pos, char *end, const char *title, | |
4198 | struct wpabuf *data) | |
4199 | { | |
4200 | char *start = pos; | |
4201 | size_t i; | |
4202 | int ret; | |
4203 | const u8 *d; | |
4204 | ||
4205 | if (data == NULL) | |
4206 | return start; | |
4207 | ||
4208 | ret = os_snprintf(pos, end - pos, "%s=", title); | |
d85e1fc8 | 4209 | if (os_snprintf_error(end - pos, ret)) |
afc064fe JM |
4210 | return start; |
4211 | pos += ret; | |
4212 | ||
4213 | d = wpabuf_head_u8(data); | |
4214 | for (i = 0; i < wpabuf_len(data); i++) { | |
4215 | ret = os_snprintf(pos, end - pos, "%02x", *d++); | |
d85e1fc8 | 4216 | if (os_snprintf_error(end - pos, ret)) |
afc064fe JM |
4217 | return start; |
4218 | pos += ret; | |
4219 | } | |
4220 | ||
4221 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4222 | if (os_snprintf_error(end - pos, ret)) |
afc064fe JM |
4223 | return start; |
4224 | pos += ret; | |
4225 | ||
4226 | return pos; | |
4227 | } | |
4228 | #endif /* CONFIG_INTERWORKING */ | |
4229 | ||
4230 | ||
b54f4339 JM |
4231 | #ifdef CONFIG_FILS |
4232 | static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end) | |
4233 | { | |
4234 | char *start = pos; | |
4235 | const u8 *ie, *ie_end; | |
4236 | u16 info, realms; | |
4237 | int ret; | |
4238 | ||
4239 | ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION); | |
4240 | if (!ie) | |
4241 | return 0; | |
4242 | ie_end = ie + 2 + ie[1]; | |
4243 | ie += 2; | |
4244 | if (ie_end - ie < 2) | |
4245 | return -1; | |
4246 | ||
4247 | info = WPA_GET_LE16(ie); | |
4248 | ie += 2; | |
4249 | ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info); | |
4250 | if (os_snprintf_error(end - pos, ret)) | |
4251 | return 0; | |
4252 | pos += ret; | |
4253 | ||
4254 | if (info & BIT(7)) { | |
4255 | /* Cache Identifier Included */ | |
4256 | if (ie_end - ie < 2) | |
4257 | return -1; | |
4258 | ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n", | |
4259 | ie[0], ie[1]); | |
4260 | if (os_snprintf_error(end - pos, ret)) | |
4261 | return 0; | |
4262 | pos += ret; | |
4263 | ie += 2; | |
4264 | } | |
4265 | ||
4266 | if (info & BIT(8)) { | |
4267 | /* HESSID Included */ | |
4268 | if (ie_end - ie < ETH_ALEN) | |
4269 | return -1; | |
4270 | ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n", | |
4271 | MAC2STR(ie)); | |
4272 | if (os_snprintf_error(end - pos, ret)) | |
4273 | return 0; | |
4274 | pos += ret; | |
4275 | ie += ETH_ALEN; | |
4276 | } | |
4277 | ||
4278 | realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3; | |
4279 | if (realms) { | |
4280 | if (ie_end - ie < realms * 2) | |
4281 | return -1; | |
4282 | ret = os_snprintf(pos, end - pos, "fils_realms="); | |
4283 | if (os_snprintf_error(end - pos, ret)) | |
4284 | return 0; | |
4285 | pos += ret; | |
4286 | ||
4287 | ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2); | |
4288 | if (ret <= 0) | |
4289 | return 0; | |
4290 | pos += ret; | |
4291 | ie += realms * 2; | |
4292 | ret = os_snprintf(pos, end - pos, "\n"); | |
4293 | if (os_snprintf_error(end - pos, ret)) | |
4294 | return 0; | |
4295 | pos += ret; | |
4296 | } | |
4297 | ||
4298 | return pos - start; | |
4299 | } | |
4300 | #endif /* CONFIG_FILS */ | |
4301 | ||
4302 | ||
61ce9085 | 4303 | static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
5f97dd1c | 4304 | unsigned long mask, char *buf, size_t buflen) |
6fc6879b | 4305 | { |
6fc6879b | 4306 | size_t i; |
6fc6879b JM |
4307 | int ret; |
4308 | char *pos, *end; | |
4a45dc19 | 4309 | const u8 *ie, *ie2, *osen_ie, *mesh; |
6fc6879b | 4310 | |
6fc6879b JM |
4311 | pos = buf; |
4312 | end = buf + buflen; | |
6fc6879b | 4313 | |
5f97dd1c DS |
4314 | if (mask & WPA_BSS_MASK_ID) { |
4315 | ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id); | |
d85e1fc8 | 4316 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4317 | return 0; |
6fc6879b JM |
4318 | pos += ret; |
4319 | } | |
4320 | ||
5f97dd1c DS |
4321 | if (mask & WPA_BSS_MASK_BSSID) { |
4322 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | |
4323 | MAC2STR(bss->bssid)); | |
d85e1fc8 | 4324 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4325 | return 0; |
4326 | pos += ret; | |
4327 | } | |
6fc6879b | 4328 | |
5f97dd1c DS |
4329 | if (mask & WPA_BSS_MASK_FREQ) { |
4330 | ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq); | |
d85e1fc8 | 4331 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4332 | return 0; |
4333 | pos += ret; | |
4334 | } | |
6fc6879b | 4335 | |
5f97dd1c DS |
4336 | if (mask & WPA_BSS_MASK_BEACON_INT) { |
4337 | ret = os_snprintf(pos, end - pos, "beacon_int=%d\n", | |
4338 | bss->beacon_int); | |
d85e1fc8 | 4339 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4340 | return 0; |
6fc6879b JM |
4341 | pos += ret; |
4342 | } | |
5f97dd1c DS |
4343 | |
4344 | if (mask & WPA_BSS_MASK_CAPABILITIES) { | |
4345 | ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n", | |
4346 | bss->caps); | |
d85e1fc8 | 4347 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4348 | return 0; |
6fc6879b JM |
4349 | pos += ret; |
4350 | } | |
5f97dd1c DS |
4351 | |
4352 | if (mask & WPA_BSS_MASK_QUAL) { | |
4353 | ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual); | |
d85e1fc8 | 4354 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4355 | return 0; |
bd1af96a JM |
4356 | pos += ret; |
4357 | } | |
5f97dd1c DS |
4358 | |
4359 | if (mask & WPA_BSS_MASK_NOISE) { | |
4360 | ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise); | |
d85e1fc8 | 4361 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c | 4362 | return 0; |
cc81110d JM |
4363 | pos += ret; |
4364 | } | |
6fc6879b | 4365 | |
5f97dd1c DS |
4366 | if (mask & WPA_BSS_MASK_LEVEL) { |
4367 | ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level); | |
d85e1fc8 | 4368 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4369 | return 0; |
4370 | pos += ret; | |
4371 | } | |
6fc6879b | 4372 | |
5f97dd1c DS |
4373 | if (mask & WPA_BSS_MASK_TSF) { |
4374 | ret = os_snprintf(pos, end - pos, "tsf=%016llu\n", | |
4375 | (unsigned long long) bss->tsf); | |
d85e1fc8 | 4376 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4377 | return 0; |
4378 | pos += ret; | |
4379 | } | |
4380 | ||
4381 | if (mask & WPA_BSS_MASK_AGE) { | |
acb69cec | 4382 | struct os_reltime now; |
5f97dd1c | 4383 | |
acb69cec | 4384 | os_get_reltime(&now); |
5f97dd1c DS |
4385 | ret = os_snprintf(pos, end - pos, "age=%d\n", |
4386 | (int) (now.sec - bss->last_update.sec)); | |
d85e1fc8 | 4387 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4388 | return 0; |
4389 | pos += ret; | |
4390 | } | |
4391 | ||
4392 | if (mask & WPA_BSS_MASK_IE) { | |
4393 | ret = os_snprintf(pos, end - pos, "ie="); | |
d85e1fc8 | 4394 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4395 | return 0; |
4396 | pos += ret; | |
4397 | ||
4398 | ie = (const u8 *) (bss + 1); | |
4399 | for (i = 0; i < bss->ie_len; i++) { | |
4400 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); | |
d85e1fc8 | 4401 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4402 | return 0; |
4403 | pos += ret; | |
4404 | } | |
4405 | ||
4406 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4407 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4408 | return 0; |
4409 | pos += ret; | |
4410 | } | |
4411 | ||
4412 | if (mask & WPA_BSS_MASK_FLAGS) { | |
4413 | ret = os_snprintf(pos, end - pos, "flags="); | |
d85e1fc8 | 4414 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4415 | return 0; |
4416 | pos += ret; | |
4417 | ||
4a45dc19 SD |
4418 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
4419 | ||
5f97dd1c DS |
4420 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
4421 | if (ie) | |
4422 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, | |
4423 | 2 + ie[1]); | |
4424 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); | |
4425 | if (ie2) | |
4a45dc19 SD |
4426 | pos = wpa_supplicant_ie_txt(pos, end, |
4427 | mesh ? "RSN" : "WPA2", ie2, | |
5f97dd1c | 4428 | 2 + ie2[1]); |
0f8385e6 BG |
4429 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
4430 | if (osen_ie) | |
4431 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", | |
4432 | osen_ie, 2 + osen_ie[1]); | |
5f97dd1c | 4433 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
0f8385e6 BG |
4434 | if (!ie && !ie2 && !osen_ie && |
4435 | (bss->caps & IEEE80211_CAP_PRIVACY)) { | |
5f97dd1c | 4436 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
d85e1fc8 | 4437 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4438 | return 0; |
4439 | pos += ret; | |
4440 | } | |
4a45dc19 SD |
4441 | |
4442 | if (mesh) { | |
4443 | ret = os_snprintf(pos, end - pos, "[MESH]"); | |
4444 | if (os_snprintf_error(end - pos, ret)) | |
4445 | return 0; | |
4446 | pos += ret; | |
4447 | } | |
4448 | ||
e403ba85 BS |
4449 | if (bss_is_dmg(bss)) { |
4450 | const char *s; | |
4451 | ret = os_snprintf(pos, end - pos, "[DMG]"); | |
d85e1fc8 | 4452 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4453 | return 0; |
4454 | pos += ret; | |
e403ba85 BS |
4455 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
4456 | case IEEE80211_CAP_DMG_IBSS: | |
4457 | s = "[IBSS]"; | |
4458 | break; | |
4459 | case IEEE80211_CAP_DMG_AP: | |
4460 | s = "[ESS]"; | |
4461 | break; | |
4462 | case IEEE80211_CAP_DMG_PBSS: | |
4463 | s = "[PBSS]"; | |
4464 | break; | |
4465 | default: | |
4466 | s = ""; | |
4467 | break; | |
4468 | } | |
4469 | ret = os_snprintf(pos, end - pos, "%s", s); | |
d85e1fc8 | 4470 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4471 | return 0; |
4472 | pos += ret; | |
e403ba85 BS |
4473 | } else { |
4474 | if (bss->caps & IEEE80211_CAP_IBSS) { | |
4475 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | |
d85e1fc8 | 4476 | if (os_snprintf_error(end - pos, ret)) |
e403ba85 BS |
4477 | return 0; |
4478 | pos += ret; | |
4479 | } | |
4480 | if (bss->caps & IEEE80211_CAP_ESS) { | |
4481 | ret = os_snprintf(pos, end - pos, "[ESS]"); | |
d85e1fc8 | 4482 | if (os_snprintf_error(end - pos, ret)) |
e403ba85 BS |
4483 | return 0; |
4484 | pos += ret; | |
4485 | } | |
5f97dd1c | 4486 | } |
bb50ae43 JM |
4487 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || |
4488 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { | |
5f97dd1c | 4489 | ret = os_snprintf(pos, end - pos, "[P2P]"); |
d85e1fc8 | 4490 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4491 | return 0; |
4492 | pos += ret; | |
4493 | } | |
64855b96 JM |
4494 | #ifdef CONFIG_HS20 |
4495 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) { | |
4496 | ret = os_snprintf(pos, end - pos, "[HS20]"); | |
d85e1fc8 | 4497 | if (os_snprintf_error(end - pos, ret)) |
ff486913 | 4498 | return 0; |
64855b96 JM |
4499 | pos += ret; |
4500 | } | |
4501 | #endif /* CONFIG_HS20 */ | |
7147a834 JM |
4502 | #ifdef CONFIG_FILS |
4503 | if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) { | |
4504 | ret = os_snprintf(pos, end - pos, "[FILS]"); | |
4505 | if (os_snprintf_error(end - pos, ret)) | |
4506 | return 0; | |
4507 | pos += ret; | |
4508 | } | |
4509 | #endif /* CONFIG_FILS */ | |
5f97dd1c DS |
4510 | |
4511 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4512 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4513 | return 0; |
4514 | pos += ret; | |
4515 | } | |
4516 | ||
4517 | if (mask & WPA_BSS_MASK_SSID) { | |
4518 | ret = os_snprintf(pos, end - pos, "ssid=%s\n", | |
4519 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | |
d85e1fc8 | 4520 | if (os_snprintf_error(end - pos, ret)) |
5f97dd1c DS |
4521 | return 0; |
4522 | pos += ret; | |
4523 | } | |
6fc6879b | 4524 | |
611ed491 | 4525 | #ifdef CONFIG_WPS |
5f97dd1c DS |
4526 | if (mask & WPA_BSS_MASK_WPS_SCAN) { |
4527 | ie = (const u8 *) (bss + 1); | |
4528 | ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end); | |
fc078be2 | 4529 | if (ret >= end - pos) |
5f97dd1c | 4530 | return 0; |
fc078be2 JM |
4531 | if (ret > 0) |
4532 | pos += ret; | |
5f97dd1c | 4533 | } |
611ed491 JM |
4534 | #endif /* CONFIG_WPS */ |
4535 | ||
0c6b310e | 4536 | #ifdef CONFIG_P2P |
5f97dd1c DS |
4537 | if (mask & WPA_BSS_MASK_P2P_SCAN) { |
4538 | ie = (const u8 *) (bss + 1); | |
4539 | ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end); | |
3b208346 | 4540 | if (ret >= end - pos) |
5f97dd1c | 4541 | return 0; |
3b208346 JA |
4542 | if (ret > 0) |
4543 | pos += ret; | |
5f97dd1c | 4544 | } |
0c6b310e JM |
4545 | #endif /* CONFIG_P2P */ |
4546 | ||
337c781f JM |
4547 | #ifdef CONFIG_WIFI_DISPLAY |
4548 | if (mask & WPA_BSS_MASK_WIFI_DISPLAY) { | |
4549 | struct wpabuf *wfd; | |
4550 | ie = (const u8 *) (bss + 1); | |
4551 | wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len, | |
4552 | WFD_IE_VENDOR_TYPE); | |
4553 | if (wfd) { | |
4554 | ret = os_snprintf(pos, end - pos, "wfd_subelems="); | |
d85e1fc8 | 4555 | if (os_snprintf_error(end - pos, ret)) { |
5e6aa04b | 4556 | wpabuf_free(wfd); |
ff486913 | 4557 | return 0; |
5e6aa04b | 4558 | } |
337c781f JM |
4559 | pos += ret; |
4560 | ||
4561 | pos += wpa_snprintf_hex(pos, end - pos, | |
4562 | wpabuf_head(wfd), | |
4563 | wpabuf_len(wfd)); | |
4564 | wpabuf_free(wfd); | |
4565 | ||
4566 | ret = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 4567 | if (os_snprintf_error(end - pos, ret)) |
ff486913 | 4568 | return 0; |
337c781f JM |
4569 | pos += ret; |
4570 | } | |
4571 | } | |
4572 | #endif /* CONFIG_WIFI_DISPLAY */ | |
4573 | ||
afc064fe | 4574 | #ifdef CONFIG_INTERWORKING |
476aed35 JM |
4575 | if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) { |
4576 | struct wpa_bss_anqp *anqp = bss->anqp; | |
8c4a1026 JM |
4577 | struct wpa_bss_anqp_elem *elem; |
4578 | ||
5ce6ac11 AN |
4579 | pos = anqp_add_hex(pos, end, "anqp_capability_list", |
4580 | anqp->capability_list); | |
5f97dd1c | 4581 | pos = anqp_add_hex(pos, end, "anqp_venue_name", |
476aed35 | 4582 | anqp->venue_name); |
5f97dd1c | 4583 | pos = anqp_add_hex(pos, end, "anqp_network_auth_type", |
476aed35 | 4584 | anqp->network_auth_type); |
5f97dd1c | 4585 | pos = anqp_add_hex(pos, end, "anqp_roaming_consortium", |
476aed35 | 4586 | anqp->roaming_consortium); |
5f97dd1c | 4587 | pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability", |
476aed35 | 4588 | anqp->ip_addr_type_availability); |
5f97dd1c | 4589 | pos = anqp_add_hex(pos, end, "anqp_nai_realm", |
476aed35 JM |
4590 | anqp->nai_realm); |
4591 | pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp); | |
5f97dd1c | 4592 | pos = anqp_add_hex(pos, end, "anqp_domain_name", |
476aed35 | 4593 | anqp->domain_name); |
9cad6186 JM |
4594 | pos = anqp_add_hex(pos, end, "anqp_fils_realm_info", |
4595 | anqp->fils_realm_info); | |
25471fe3 | 4596 | #ifdef CONFIG_HS20 |
185ada47 AN |
4597 | pos = anqp_add_hex(pos, end, "hs20_capability_list", |
4598 | anqp->hs20_capability_list); | |
25471fe3 | 4599 | pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name", |
476aed35 | 4600 | anqp->hs20_operator_friendly_name); |
25471fe3 | 4601 | pos = anqp_add_hex(pos, end, "hs20_wan_metrics", |
476aed35 | 4602 | anqp->hs20_wan_metrics); |
25471fe3 | 4603 | pos = anqp_add_hex(pos, end, "hs20_connection_capability", |
476aed35 | 4604 | anqp->hs20_connection_capability); |
1d2215fc JM |
4605 | pos = anqp_add_hex(pos, end, "hs20_operating_class", |
4606 | anqp->hs20_operating_class); | |
4607 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_list", | |
4608 | anqp->hs20_osu_providers_list); | |
25471fe3 | 4609 | #endif /* CONFIG_HS20 */ |
8c4a1026 JM |
4610 | |
4611 | dl_list_for_each(elem, &anqp->anqp_elems, | |
4612 | struct wpa_bss_anqp_elem, list) { | |
4613 | char title[20]; | |
4614 | ||
4615 | os_snprintf(title, sizeof(title), "anqp[%u]", | |
4616 | elem->infoid); | |
4617 | pos = anqp_add_hex(pos, end, title, elem->payload); | |
4618 | } | |
5f97dd1c | 4619 | } |
afc064fe JM |
4620 | #endif /* CONFIG_INTERWORKING */ |
4621 | ||
79070906 MH |
4622 | #ifdef CONFIG_MESH |
4623 | if (mask & WPA_BSS_MASK_MESH_SCAN) { | |
4624 | ie = (const u8 *) (bss + 1); | |
4625 | ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end); | |
3b208346 | 4626 | if (ret >= end - pos) |
79070906 | 4627 | return 0; |
3b208346 JA |
4628 | if (ret > 0) |
4629 | pos += ret; | |
79070906 MH |
4630 | } |
4631 | #endif /* CONFIG_MESH */ | |
4632 | ||
1d747e2a JM |
4633 | if (mask & WPA_BSS_MASK_SNR) { |
4634 | ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr); | |
4635 | if (os_snprintf_error(end - pos, ret)) | |
4636 | return 0; | |
4637 | pos += ret; | |
4638 | } | |
4639 | ||
4640 | if (mask & WPA_BSS_MASK_EST_THROUGHPUT) { | |
4641 | ret = os_snprintf(pos, end - pos, "est_throughput=%d\n", | |
4642 | bss->est_throughput); | |
4643 | if (os_snprintf_error(end - pos, ret)) | |
4644 | return 0; | |
4645 | pos += ret; | |
4646 | } | |
4647 | ||
3794af2d AN |
4648 | #ifdef CONFIG_FST |
4649 | if (mask & WPA_BSS_MASK_FST) { | |
4650 | ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos); | |
4651 | if (ret < 0 || ret >= end - pos) | |
4652 | return 0; | |
4653 | pos += ret; | |
4654 | } | |
4655 | #endif /* CONFIG_FST */ | |
4656 | ||
71ac9345 JM |
4657 | if (mask & WPA_BSS_MASK_UPDATE_IDX) { |
4658 | ret = os_snprintf(pos, end - pos, "update_idx=%u\n", | |
4659 | bss->last_update_idx); | |
4660 | if (os_snprintf_error(end - pos, ret)) | |
4661 | return 0; | |
4662 | pos += ret; | |
4663 | } | |
4664 | ||
19810d29 JM |
4665 | if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) { |
4666 | ret = os_snprintf(pos, end - pos, "beacon_ie="); | |
4667 | if (os_snprintf_error(end - pos, ret)) | |
4668 | return 0; | |
4669 | pos += ret; | |
4670 | ||
4671 | ie = (const u8 *) (bss + 1); | |
4672 | ie += bss->ie_len; | |
4673 | for (i = 0; i < bss->beacon_ie_len; i++) { | |
4674 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); | |
4675 | if (os_snprintf_error(end - pos, ret)) | |
4676 | return 0; | |
4677 | pos += ret; | |
4678 | } | |
4679 | ||
4680 | ret = os_snprintf(pos, end - pos, "\n"); | |
4681 | if (os_snprintf_error(end - pos, ret)) | |
4682 | return 0; | |
4683 | pos += ret; | |
4684 | } | |
4685 | ||
b54f4339 JM |
4686 | #ifdef CONFIG_FILS |
4687 | if (mask & WPA_BSS_MASK_FILS_INDICATION) { | |
4688 | ret = print_fils_indication(bss, pos, end); | |
4689 | if (ret < 0) | |
4690 | return 0; | |
4691 | pos += ret; | |
4692 | } | |
4693 | #endif /* CONFIG_FILS */ | |
4694 | ||
c6673429 DS |
4695 | if (mask & WPA_BSS_MASK_DELIM) { |
4696 | ret = os_snprintf(pos, end - pos, "====\n"); | |
d85e1fc8 | 4697 | if (os_snprintf_error(end - pos, ret)) |
c6673429 DS |
4698 | return 0; |
4699 | pos += ret; | |
4700 | } | |
4701 | ||
6fc6879b JM |
4702 | return pos - buf; |
4703 | } | |
4704 | ||
4705 | ||
61ce9085 DS |
4706 | static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s, |
4707 | const char *cmd, char *buf, | |
4708 | size_t buflen) | |
4709 | { | |
4710 | u8 bssid[ETH_ALEN]; | |
4711 | size_t i; | |
4712 | struct wpa_bss *bss; | |
eff1a95b DS |
4713 | struct wpa_bss *bsslast = NULL; |
4714 | struct dl_list *next; | |
4715 | int ret = 0; | |
4716 | int len; | |
1d399771 | 4717 | char *ctmp, *end = buf + buflen; |
5f97dd1c | 4718 | unsigned long mask = WPA_BSS_MASK_ALL; |
61ce9085 | 4719 | |
eff1a95b DS |
4720 | if (os_strncmp(cmd, "RANGE=", 6) == 0) { |
4721 | if (os_strncmp(cmd + 6, "ALL", 3) == 0) { | |
4722 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, | |
4723 | list_id); | |
4724 | bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss, | |
4725 | list_id); | |
4726 | } else { /* N1-N2 */ | |
4727 | unsigned int id1, id2; | |
4728 | ||
4729 | if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) { | |
4730 | wpa_printf(MSG_INFO, "Wrong BSS range " | |
4731 | "format"); | |
4732 | return 0; | |
4733 | } | |
4734 | ||
9f42d49c AS |
4735 | if (*(cmd + 6) == '-') |
4736 | id1 = 0; | |
4737 | else | |
4738 | id1 = atoi(cmd + 6); | |
4739 | ctmp++; | |
4740 | if (*ctmp >= '0' && *ctmp <= '9') | |
4741 | id2 = atoi(ctmp); | |
4742 | else | |
4743 | id2 = (unsigned int) -1; | |
4744 | bss = wpa_bss_get_id_range(wpa_s, id1, id2); | |
4745 | if (id2 == (unsigned int) -1) | |
eff1a95b DS |
4746 | bsslast = dl_list_last(&wpa_s->bss_id, |
4747 | struct wpa_bss, | |
4748 | list_id); | |
4749 | else { | |
4750 | bsslast = wpa_bss_get_id(wpa_s, id2); | |
4751 | if (bsslast == NULL && bss && id2 > id1) { | |
4752 | struct wpa_bss *tmp = bss; | |
4753 | for (;;) { | |
4754 | next = tmp->list_id.next; | |
4755 | if (next == &wpa_s->bss_id) | |
4756 | break; | |
4757 | tmp = dl_list_entry( | |
4758 | next, struct wpa_bss, | |
4759 | list_id); | |
4760 | if (tmp->id > id2) | |
4761 | break; | |
4762 | bsslast = tmp; | |
4763 | } | |
4764 | } | |
4765 | } | |
4766 | } | |
f330b4b4 | 4767 | } else if (os_strncmp(cmd, "FIRST", 5) == 0) |
51a0c3d4 | 4768 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id); |
cc03d0fe AS |
4769 | else if (os_strncmp(cmd, "LAST", 4) == 0) |
4770 | bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id); | |
61ce9085 DS |
4771 | else if (os_strncmp(cmd, "ID-", 3) == 0) { |
4772 | i = atoi(cmd + 3); | |
4773 | bss = wpa_bss_get_id(wpa_s, i); | |
4774 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | |
4775 | i = atoi(cmd + 5); | |
4776 | bss = wpa_bss_get_id(wpa_s, i); | |
4777 | if (bss) { | |
eff1a95b | 4778 | next = bss->list_id.next; |
61ce9085 DS |
4779 | if (next == &wpa_s->bss_id) |
4780 | bss = NULL; | |
4781 | else | |
4782 | bss = dl_list_entry(next, struct wpa_bss, | |
4783 | list_id); | |
4784 | } | |
9187b13a JC |
4785 | } else if (os_strncmp(cmd, "CURRENT", 7) == 0) { |
4786 | bss = wpa_s->current_bss; | |
61ce9085 DS |
4787 | #ifdef CONFIG_P2P |
4788 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | |
4789 | if (hwaddr_aton(cmd + 13, bssid) == 0) | |
4790 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid); | |
4791 | else | |
4792 | bss = NULL; | |
4793 | #endif /* CONFIG_P2P */ | |
4794 | } else if (hwaddr_aton(cmd, bssid) == 0) | |
4795 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
4796 | else { | |
4797 | struct wpa_bss *tmp; | |
4798 | i = atoi(cmd); | |
4799 | bss = NULL; | |
4800 | dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id) | |
4801 | { | |
4802 | if (i-- == 0) { | |
4803 | bss = tmp; | |
4804 | break; | |
4805 | } | |
4806 | } | |
4807 | } | |
4808 | ||
5f97dd1c DS |
4809 | if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) { |
4810 | mask = strtoul(ctmp + 5, NULL, 0x10); | |
4811 | if (mask == 0) | |
4812 | mask = WPA_BSS_MASK_ALL; | |
4813 | } | |
4814 | ||
61ce9085 DS |
4815 | if (bss == NULL) |
4816 | return 0; | |
4817 | ||
eff1a95b DS |
4818 | if (bsslast == NULL) |
4819 | bsslast = bss; | |
4820 | do { | |
4821 | len = print_bss_info(wpa_s, bss, mask, buf, buflen); | |
4822 | ret += len; | |
4823 | buf += len; | |
4824 | buflen -= len; | |
cfd42c94 DS |
4825 | if (bss == bsslast) { |
4826 | if ((mask & WPA_BSS_MASK_DELIM) && len && | |
4827 | (bss == dl_list_last(&wpa_s->bss_id, | |
1d399771 JM |
4828 | struct wpa_bss, list_id))) { |
4829 | int res; | |
4830 | ||
4831 | res = os_snprintf(buf - 5, end - buf + 5, | |
4832 | "####\n"); | |
4833 | if (os_snprintf_error(end - buf + 5, res)) { | |
4834 | wpa_printf(MSG_DEBUG, | |
4835 | "Could not add end delim"); | |
4836 | } | |
4837 | } | |
eff1a95b | 4838 | break; |
cfd42c94 | 4839 | } |
eff1a95b DS |
4840 | next = bss->list_id.next; |
4841 | if (next == &wpa_s->bss_id) | |
4842 | break; | |
4843 | bss = dl_list_entry(next, struct wpa_bss, list_id); | |
4844 | } while (bss && len); | |
4845 | ||
4846 | return ret; | |
61ce9085 DS |
4847 | } |
4848 | ||
4849 | ||
6fc6879b JM |
4850 | static int wpa_supplicant_ctrl_iface_ap_scan( |
4851 | struct wpa_supplicant *wpa_s, char *cmd) | |
4852 | { | |
4853 | int ap_scan = atoi(cmd); | |
86b89452 | 4854 | return wpa_supplicant_set_ap_scan(wpa_s, ap_scan); |
6fc6879b JM |
4855 | } |
4856 | ||
4857 | ||
67b9bd08 DS |
4858 | static int wpa_supplicant_ctrl_iface_scan_interval( |
4859 | struct wpa_supplicant *wpa_s, char *cmd) | |
4860 | { | |
4861 | int scan_int = atoi(cmd); | |
c6e86b63 | 4862 | return wpa_supplicant_set_scan_interval(wpa_s, scan_int); |
67b9bd08 DS |
4863 | } |
4864 | ||
4865 | ||
78633c37 SL |
4866 | static int wpa_supplicant_ctrl_iface_bss_expire_age( |
4867 | struct wpa_supplicant *wpa_s, char *cmd) | |
4868 | { | |
4869 | int expire_age = atoi(cmd); | |
4870 | return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age); | |
4871 | } | |
4872 | ||
4873 | ||
4874 | static int wpa_supplicant_ctrl_iface_bss_expire_count( | |
4875 | struct wpa_supplicant *wpa_s, char *cmd) | |
4876 | { | |
4877 | int expire_count = atoi(cmd); | |
4878 | return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count); | |
4879 | } | |
4880 | ||
4881 | ||
a1144000 | 4882 | static void wpa_supplicant_ctrl_iface_bss_flush( |
39ee845f DS |
4883 | struct wpa_supplicant *wpa_s, char *cmd) |
4884 | { | |
4885 | int flush_age = atoi(cmd); | |
4886 | ||
4887 | if (flush_age == 0) | |
4888 | wpa_bss_flush(wpa_s); | |
4889 | else | |
4890 | wpa_bss_flush_by_age(wpa_s, flush_age); | |
39ee845f DS |
4891 | } |
4892 | ||
4893 | ||
9ff4de6d | 4894 | #ifdef CONFIG_TESTING_OPTIONS |
32d5295f JM |
4895 | static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s) |
4896 | { | |
32d5295f JM |
4897 | wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication"); |
4898 | /* MLME-DELETEKEYS.request */ | |
0382097e JM |
4899 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0); |
4900 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0); | |
4901 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0); | |
4902 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0); | |
32d5295f | 4903 | #ifdef CONFIG_IEEE80211W |
0382097e JM |
4904 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0); |
4905 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0); | |
32d5295f JM |
4906 | #endif /* CONFIG_IEEE80211W */ |
4907 | ||
4908 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL, | |
4909 | 0); | |
4910 | /* MLME-SETPROTECTION.request(None) */ | |
4911 | wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid, | |
4912 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, | |
4913 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); | |
4914 | wpa_sm_drop_sa(wpa_s->wpa); | |
4915 | } | |
9ff4de6d | 4916 | #endif /* CONFIG_TESTING_OPTIONS */ |
32d5295f JM |
4917 | |
4918 | ||
86d4f806 JM |
4919 | static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s, |
4920 | char *addr) | |
4921 | { | |
90b8fc8f JM |
4922 | #ifdef CONFIG_NO_SCAN_PROCESSING |
4923 | return -1; | |
4924 | #else /* CONFIG_NO_SCAN_PROCESSING */ | |
86d4f806 JM |
4925 | u8 bssid[ETH_ALEN]; |
4926 | struct wpa_bss *bss; | |
4927 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
4928 | ||
4929 | if (hwaddr_aton(addr, bssid)) { | |
4930 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid " | |
4931 | "address '%s'", addr); | |
4932 | return -1; | |
4933 | } | |
4934 | ||
4935 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid)); | |
4936 | ||
2f9b66d3 JM |
4937 | if (!ssid) { |
4938 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network " | |
4939 | "configuration known for the target AP"); | |
4940 | return -1; | |
4941 | } | |
4942 | ||
4943 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); | |
86d4f806 JM |
4944 | if (!bss) { |
4945 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found " | |
4946 | "from BSS table"); | |
4947 | return -1; | |
4948 | } | |
4949 | ||
4950 | /* | |
4951 | * TODO: Find best network configuration block from configuration to | |
4952 | * allow roaming to other networks | |
4953 | */ | |
4954 | ||
86d4f806 JM |
4955 | wpa_s->reassociate = 1; |
4956 | wpa_supplicant_connect(wpa_s, bss, ssid); | |
4957 | ||
4958 | return 0; | |
90b8fc8f | 4959 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
86d4f806 JM |
4960 | } |
4961 | ||
4962 | ||
b563b388 JM |
4963 | #ifdef CONFIG_P2P |
4964 | static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd) | |
4965 | { | |
4966 | unsigned int timeout = atoi(cmd); | |
4967 | enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL; | |
6d92fa6e | 4968 | u8 dev_id[ETH_ALEN], *_dev_id = NULL; |
2b384109 | 4969 | u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL; |
6d92fa6e | 4970 | char *pos; |
05a77b3b | 4971 | unsigned int search_delay; |
9542f21f | 4972 | const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL; |
51775096 | 4973 | u8 seek_count = 0; |
fa9f381f | 4974 | int freq = 0; |
b563b388 | 4975 | |
e9eb648e JM |
4976 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
4977 | wpa_dbg(wpa_s, MSG_INFO, | |
4978 | "Reject P2P_FIND since interface is disabled"); | |
4979 | return -1; | |
4980 | } | |
b563b388 JM |
4981 | if (os_strstr(cmd, "type=social")) |
4982 | type = P2P_FIND_ONLY_SOCIAL; | |
4983 | else if (os_strstr(cmd, "type=progressive")) | |
4984 | type = P2P_FIND_PROGRESSIVE; | |
4985 | ||
6d92fa6e JM |
4986 | pos = os_strstr(cmd, "dev_id="); |
4987 | if (pos) { | |
4988 | pos += 7; | |
4989 | if (hwaddr_aton(pos, dev_id)) | |
4990 | return -1; | |
4991 | _dev_id = dev_id; | |
4992 | } | |
4993 | ||
2b384109 JM |
4994 | pos = os_strstr(cmd, "dev_type="); |
4995 | if (pos) { | |
4996 | pos += 9; | |
4997 | if (wps_dev_type_str2bin(pos, dev_type) < 0) | |
4998 | return -1; | |
4999 | _dev_type = dev_type; | |
5000 | } | |
5001 | ||
37448ede JM |
5002 | pos = os_strstr(cmd, "delay="); |
5003 | if (pos) { | |
5004 | pos += 6; | |
5005 | search_delay = atoi(pos); | |
05a77b3b JM |
5006 | } else |
5007 | search_delay = wpas_p2p_search_delay(wpa_s); | |
37448ede | 5008 | |
a9ea609c SM |
5009 | pos = os_strstr(cmd, "freq="); |
5010 | if (pos) { | |
5011 | pos += 5; | |
5012 | freq = atoi(pos); | |
5013 | if (freq <= 0) | |
5014 | return -1; | |
5015 | } | |
5016 | ||
51775096 BG |
5017 | /* Must be searched for last, because it adds nul termination */ |
5018 | pos = os_strstr(cmd, " seek="); | |
129b6216 JM |
5019 | if (pos) |
5020 | pos += 6; | |
51775096 BG |
5021 | while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) { |
5022 | char *term; | |
5023 | ||
129b6216 | 5024 | _seek[seek_count++] = pos; |
9542f21f | 5025 | seek = _seek; |
129b6216 JM |
5026 | term = os_strchr(pos, ' '); |
5027 | if (!term) | |
5028 | break; | |
5029 | *term = '\0'; | |
5030 | pos = os_strstr(term + 1, "seek="); | |
5031 | if (pos) | |
5032 | pos += 5; | |
51775096 | 5033 | } |
9542f21f JM |
5034 | if (seek_count > P2P_MAX_QUERY_HASH) { |
5035 | seek[0] = NULL; | |
5036 | seek_count = 1; | |
5037 | } | |
51775096 | 5038 | |
2b384109 | 5039 | return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type, |
fa9f381f | 5040 | _dev_id, search_delay, seek_count, seek, freq); |
b563b388 JM |
5041 | } |
5042 | ||
5043 | ||
e2b7fbf2 MS |
5044 | static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt) |
5045 | { | |
5046 | const char *last = NULL; | |
5047 | const char *token; | |
5048 | long int token_len; | |
5049 | unsigned int i; | |
5050 | ||
5051 | /* Expected predefined CPT names delimited by ':' */ | |
5052 | for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) { | |
5053 | if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) { | |
5054 | wpa_printf(MSG_ERROR, | |
5055 | "P2PS: CPT name list is too long, expected up to %d names", | |
5056 | P2PS_FEATURE_CAPAB_CPT_MAX); | |
5057 | cpt[0] = 0; | |
5058 | return -1; | |
5059 | } | |
5060 | ||
5061 | token_len = last - token; | |
5062 | ||
5063 | if (token_len == 3 && | |
5064 | os_memcmp(token, "UDP", token_len) == 0) { | |
5065 | cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; | |
5066 | } else if (token_len == 3 && | |
5067 | os_memcmp(token, "MAC", token_len) == 0) { | |
5068 | cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT; | |
5069 | } else { | |
5070 | wpa_printf(MSG_ERROR, | |
5071 | "P2PS: Unsupported CPT name '%s'", token); | |
5072 | cpt[0] = 0; | |
5073 | return -1; | |
5074 | } | |
5075 | ||
640b0b93 | 5076 | if (isblank((unsigned char) *last)) { |
e2b7fbf2 MS |
5077 | i++; |
5078 | break; | |
5079 | } | |
5080 | } | |
5081 | cpt[i] = 0; | |
5082 | return 0; | |
5083 | } | |
5084 | ||
5085 | ||
f309c18e KV |
5086 | static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd) |
5087 | { | |
5088 | struct p2ps_provision *p2ps_prov; | |
5089 | char *pos; | |
5090 | size_t info_len = 0; | |
5091 | char *info = NULL; | |
5092 | u8 role = P2PS_SETUP_NONE; | |
5093 | long long unsigned val; | |
0670de74 | 5094 | int i; |
f309c18e KV |
5095 | |
5096 | pos = os_strstr(cmd, "info="); | |
5097 | if (pos) { | |
5098 | pos += 5; | |
5099 | info_len = os_strlen(pos); | |
5100 | ||
5101 | if (info_len) { | |
5102 | info = os_malloc(info_len + 1); | |
5103 | if (info) { | |
5104 | info_len = utf8_unescape(pos, info_len, | |
5105 | info, info_len + 1); | |
5106 | } else | |
5107 | info_len = 0; | |
5108 | } | |
5109 | } | |
5110 | ||
5111 | p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1); | |
5112 | if (p2ps_prov == NULL) { | |
5113 | os_free(info); | |
5114 | return NULL; | |
5115 | } | |
5116 | ||
5117 | if (info) { | |
5118 | os_memcpy(p2ps_prov->info, info, info_len); | |
5119 | p2ps_prov->info[info_len] = '\0'; | |
5120 | os_free(info); | |
5121 | } | |
5122 | ||
5123 | pos = os_strstr(cmd, "status="); | |
5124 | if (pos) | |
5125 | p2ps_prov->status = atoi(pos + 7); | |
5126 | else | |
5127 | p2ps_prov->status = -1; | |
5128 | ||
5129 | pos = os_strstr(cmd, "adv_id="); | |
5130 | if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL) | |
5131 | goto invalid_args; | |
5132 | p2ps_prov->adv_id = val; | |
5133 | ||
5134 | pos = os_strstr(cmd, "method="); | |
5135 | if (pos) | |
5136 | p2ps_prov->method = strtol(pos + 7, NULL, 16); | |
5137 | else | |
5138 | p2ps_prov->method = 0; | |
5139 | ||
5140 | pos = os_strstr(cmd, "session="); | |
5141 | if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL) | |
5142 | goto invalid_args; | |
5143 | p2ps_prov->session_id = val; | |
5144 | ||
5145 | pos = os_strstr(cmd, "adv_mac="); | |
5146 | if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac)) | |
5147 | goto invalid_args; | |
5148 | ||
5149 | pos = os_strstr(cmd, "session_mac="); | |
5150 | if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac)) | |
5151 | goto invalid_args; | |
5152 | ||
0670de74 MS |
5153 | pos = os_strstr(cmd, "cpt="); |
5154 | if (pos) { | |
5155 | if (p2ps_ctrl_parse_cpt_priority(pos + 4, | |
5156 | p2ps_prov->cpt_priority)) | |
5157 | goto invalid_args; | |
5158 | } else { | |
5159 | p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; | |
5160 | } | |
5161 | ||
5162 | for (i = 0; p2ps_prov->cpt_priority[i]; i++) | |
5163 | p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i]; | |
5164 | ||
f309c18e KV |
5165 | /* force conncap with tstCap (no sanity checks) */ |
5166 | pos = os_strstr(cmd, "tstCap="); | |
5167 | if (pos) { | |
5168 | role = strtol(pos + 7, NULL, 16); | |
5169 | } else { | |
5170 | pos = os_strstr(cmd, "role="); | |
5171 | if (pos) { | |
5172 | role = strtol(pos + 5, NULL, 16); | |
5173 | if (role != P2PS_SETUP_CLIENT && | |
5174 | role != P2PS_SETUP_GROUP_OWNER) | |
5175 | role = P2PS_SETUP_NONE; | |
5176 | } | |
5177 | } | |
5178 | p2ps_prov->role = role; | |
5179 | ||
5180 | return p2ps_prov; | |
5181 | ||
5182 | invalid_args: | |
5183 | os_free(p2ps_prov); | |
5184 | return NULL; | |
5185 | } | |
5186 | ||
5187 | ||
5188 | static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd) | |
5189 | { | |
5190 | u8 addr[ETH_ALEN]; | |
5191 | struct p2ps_provision *p2ps_prov; | |
5192 | char *pos; | |
5193 | ||
5194 | /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */ | |
5195 | ||
5196 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); | |
5197 | ||
5198 | if (hwaddr_aton(cmd, addr)) | |
5199 | return -1; | |
5200 | ||
5201 | pos = cmd + 17; | |
5202 | if (*pos != ' ') | |
5203 | return -1; | |
5204 | ||
5205 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); | |
5206 | if (!p2ps_prov) | |
5207 | return -1; | |
5208 | ||
5209 | if (p2ps_prov->status < 0) { | |
5210 | os_free(p2ps_prov); | |
5211 | return -1; | |
5212 | } | |
5213 | ||
5214 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, | |
5215 | p2ps_prov); | |
5216 | } | |
5217 | ||
5218 | ||
5219 | static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd) | |
5220 | { | |
5221 | u8 addr[ETH_ALEN]; | |
5222 | struct p2ps_provision *p2ps_prov; | |
5223 | char *pos; | |
5224 | ||
5225 | /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap> | |
5226 | * session=<ses_id> mac=<ses_mac> [info=<infodata>] | |
5227 | */ | |
5228 | ||
5229 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); | |
5230 | if (hwaddr_aton(cmd, addr)) | |
5231 | return -1; | |
5232 | ||
5233 | pos = cmd + 17; | |
5234 | if (*pos != ' ') | |
5235 | return -1; | |
5236 | ||
5237 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); | |
5238 | if (!p2ps_prov) | |
5239 | return -1; | |
5240 | ||
93f22b45 MS |
5241 | p2ps_prov->pd_seeker = 1; |
5242 | ||
f309c18e KV |
5243 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, |
5244 | p2ps_prov); | |
5245 | } | |
5246 | ||
5247 | ||
c27f4c90 AK |
5248 | static int parse_freq(int chwidth, int freq2) |
5249 | { | |
5250 | if (freq2 < 0) | |
5251 | return -1; | |
5252 | if (freq2) | |
5253 | return VHT_CHANWIDTH_80P80MHZ; | |
5254 | ||
5255 | switch (chwidth) { | |
5256 | case 0: | |
5257 | case 20: | |
5258 | case 40: | |
5259 | return VHT_CHANWIDTH_USE_HT; | |
5260 | case 80: | |
5261 | return VHT_CHANWIDTH_80MHZ; | |
5262 | case 160: | |
5263 | return VHT_CHANWIDTH_160MHZ; | |
5264 | default: | |
5265 | wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d", | |
5266 | chwidth); | |
5267 | return -1; | |
5268 | } | |
5269 | } | |
5270 | ||
5271 | ||
b563b388 JM |
5272 | static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd, |
5273 | char *buf, size_t buflen) | |
5274 | { | |
5275 | u8 addr[ETH_ALEN]; | |
5276 | char *pos, *pos2; | |
5277 | char *pin = NULL; | |
5278 | enum p2p_wps_method wps_method; | |
5279 | int new_pin; | |
5280 | int ret; | |
23c84252 | 5281 | int persistent_group, persistent_id = -1; |
b563b388 JM |
5282 | int join; |
5283 | int auth; | |
b31be3a0 | 5284 | int automatic; |
b563b388 JM |
5285 | int go_intent = -1; |
5286 | int freq = 0; | |
3bc462cb | 5287 | int pd; |
c27f4c90 | 5288 | int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0; |
8edd9f10 JM |
5289 | u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL; |
5290 | size_t group_ssid_len = 0; | |
b563b388 | 5291 | |
bdf0518b JM |
5292 | if (!wpa_s->global->p2p_init_wpa_s) |
5293 | return -1; | |
5294 | if (wpa_s->global->p2p_init_wpa_s != wpa_s) { | |
5295 | wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s", | |
5296 | wpa_s->global->p2p_init_wpa_s->ifname); | |
5297 | wpa_s = wpa_s->global->p2p_init_wpa_s; | |
5298 | } | |
5299 | ||
4f88fc04 | 5300 | /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps] |
23c84252 | 5301 | * [persistent|persistent=<network id>] |
e2308e4b | 5302 | * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] |
8edd9f10 | 5303 | * [ht40] [vht] [auto] [ssid=<hexdump>] */ |
b563b388 JM |
5304 | |
5305 | if (hwaddr_aton(cmd, addr)) | |
5306 | return -1; | |
5307 | ||
5308 | pos = cmd + 17; | |
5309 | if (*pos != ' ') | |
5310 | return -1; | |
5311 | pos++; | |
5312 | ||
5313 | persistent_group = os_strstr(pos, " persistent") != NULL; | |
23c84252 JM |
5314 | pos2 = os_strstr(pos, " persistent="); |
5315 | if (pos2) { | |
5316 | struct wpa_ssid *ssid; | |
5317 | persistent_id = atoi(pos2 + 12); | |
5318 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); | |
5319 | if (ssid == NULL || ssid->disabled != 2 || | |
5320 | ssid->mode != WPAS_MODE_P2P_GO) { | |
5321 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | |
5322 | "SSID id=%d for persistent P2P group (GO)", | |
5323 | persistent_id); | |
5324 | return -1; | |
5325 | } | |
5326 | } | |
b563b388 JM |
5327 | join = os_strstr(pos, " join") != NULL; |
5328 | auth = os_strstr(pos, " auth") != NULL; | |
b31be3a0 | 5329 | automatic = os_strstr(pos, " auto") != NULL; |
3bc462cb | 5330 | pd = os_strstr(pos, " provdisc") != NULL; |
20ea1ca4 EP |
5331 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
5332 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | |
5333 | vht; | |
b563b388 JM |
5334 | |
5335 | pos2 = os_strstr(pos, " go_intent="); | |
5336 | if (pos2) { | |
5337 | pos2 += 11; | |
5338 | go_intent = atoi(pos2); | |
5339 | if (go_intent < 0 || go_intent > 15) | |
5340 | return -1; | |
5341 | } | |
5342 | ||
5343 | pos2 = os_strstr(pos, " freq="); | |
5344 | if (pos2) { | |
5345 | pos2 += 6; | |
5346 | freq = atoi(pos2); | |
5347 | if (freq <= 0) | |
5348 | return -1; | |
5349 | } | |
5350 | ||
c27f4c90 AK |
5351 | pos2 = os_strstr(pos, " freq2="); |
5352 | if (pos2) | |
5353 | freq2 = atoi(pos2 + 7); | |
5354 | ||
5355 | pos2 = os_strstr(pos, " max_oper_chwidth="); | |
5356 | if (pos2) | |
5357 | chwidth = atoi(pos2 + 18); | |
5358 | ||
5359 | max_oper_chwidth = parse_freq(chwidth, freq2); | |
5360 | if (max_oper_chwidth < 0) | |
5361 | return -1; | |
5362 | ||
8edd9f10 JM |
5363 | pos2 = os_strstr(pos, " ssid="); |
5364 | if (pos2) { | |
5365 | char *end; | |
5366 | ||
5367 | pos2 += 6; | |
5368 | end = os_strchr(pos2, ' '); | |
5369 | if (!end) | |
5370 | group_ssid_len = os_strlen(pos2) / 2; | |
5371 | else | |
5372 | group_ssid_len = (end - pos2) / 2; | |
5373 | if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN || | |
5374 | hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0) | |
5375 | return -1; | |
5376 | group_ssid = _group_ssid; | |
5377 | } | |
5378 | ||
b563b388 JM |
5379 | if (os_strncmp(pos, "pin", 3) == 0) { |
5380 | /* Request random PIN (to be displayed) and enable the PIN */ | |
5381 | wps_method = WPS_PIN_DISPLAY; | |
5382 | } else if (os_strncmp(pos, "pbc", 3) == 0) { | |
5383 | wps_method = WPS_PBC; | |
31d7fb14 PK |
5384 | } else if (os_strstr(pos, "p2ps") != NULL) { |
5385 | wps_method = WPS_P2PS; | |
b563b388 JM |
5386 | } else { |
5387 | pin = pos; | |
5388 | pos = os_strchr(pin, ' '); | |
5389 | wps_method = WPS_PIN_KEYPAD; | |
5390 | if (pos) { | |
5391 | *pos++ = '\0'; | |
07fecd39 | 5392 | if (os_strncmp(pos, "display", 7) == 0) |
b563b388 JM |
5393 | wps_method = WPS_PIN_DISPLAY; |
5394 | } | |
dcc33057 | 5395 | if (!wps_pin_str_valid(pin)) { |
36ebf7a1 MH |
5396 | os_memcpy(buf, "FAIL-INVALID-PIN\n", 17); |
5397 | return 17; | |
5398 | } | |
b563b388 JM |
5399 | } |
5400 | ||
5401 | new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method, | |
b31be3a0 | 5402 | persistent_group, automatic, join, |
c27f4c90 | 5403 | auth, go_intent, freq, freq2, persistent_id, |
8edd9f10 JM |
5404 | pd, ht40, vht, max_oper_chwidth, |
5405 | group_ssid, group_ssid_len); | |
d054a462 JM |
5406 | if (new_pin == -2) { |
5407 | os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25); | |
5408 | return 25; | |
5409 | } | |
5410 | if (new_pin == -3) { | |
5411 | os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25); | |
5412 | return 25; | |
5413 | } | |
b563b388 JM |
5414 | if (new_pin < 0) |
5415 | return -1; | |
5416 | if (wps_method == WPS_PIN_DISPLAY && pin == NULL) { | |
5417 | ret = os_snprintf(buf, buflen, "%08d", new_pin); | |
d85e1fc8 | 5418 | if (os_snprintf_error(buflen, ret)) |
b563b388 JM |
5419 | return -1; |
5420 | return ret; | |
5421 | } | |
5422 | ||
5423 | os_memcpy(buf, "OK\n", 3); | |
5424 | return 3; | |
5425 | } | |
5426 | ||
5427 | ||
5428 | static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd) | |
5429 | { | |
5430 | unsigned int timeout = atoi(cmd); | |
e9eb648e JM |
5431 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
5432 | wpa_dbg(wpa_s, MSG_INFO, | |
5433 | "Reject P2P_LISTEN since interface is disabled"); | |
5434 | return -1; | |
5435 | } | |
b563b388 JM |
5436 | return wpas_p2p_listen(wpa_s, timeout); |
5437 | } | |
5438 | ||
5439 | ||
5440 | static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) | |
5441 | { | |
5442 | u8 addr[ETH_ALEN]; | |
5443 | char *pos; | |
0918c4bf | 5444 | enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG; |
b563b388 | 5445 | |
0918c4bf | 5446 | /* <addr> <config method> [join|auto] */ |
b563b388 JM |
5447 | |
5448 | if (hwaddr_aton(cmd, addr)) | |
5449 | return -1; | |
5450 | ||
5451 | pos = cmd + 17; | |
5452 | if (*pos != ' ') | |
5453 | return -1; | |
5454 | pos++; | |
5455 | ||
0918c4bf JM |
5456 | if (os_strstr(pos, " join") != NULL) |
5457 | use = WPAS_P2P_PD_FOR_JOIN; | |
5458 | else if (os_strstr(pos, " auto") != NULL) | |
5459 | use = WPAS_P2P_PD_AUTO; | |
5460 | ||
6d908514 | 5461 | return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL); |
b563b388 JM |
5462 | } |
5463 | ||
5464 | ||
5465 | static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf, | |
5466 | size_t buflen) | |
5467 | { | |
5468 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
5469 | ||
5470 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || | |
5471 | ssid->passphrase == NULL) | |
5472 | return -1; | |
5473 | ||
5474 | os_strlcpy(buf, ssid->passphrase, buflen); | |
5475 | return os_strlen(buf); | |
5476 | } | |
5477 | ||
5478 | ||
5479 | static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd, | |
5480 | char *buf, size_t buflen) | |
5481 | { | |
5482 | u64 ref; | |
5483 | int res; | |
5484 | u8 dst_buf[ETH_ALEN], *dst; | |
5485 | struct wpabuf *tlvs; | |
5486 | char *pos; | |
5487 | size_t len; | |
5488 | ||
5489 | if (hwaddr_aton(cmd, dst_buf)) | |
5490 | return -1; | |
5491 | dst = dst_buf; | |
5492 | if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 && | |
5493 | dst[3] == 0 && dst[4] == 0 && dst[5] == 0) | |
5494 | dst = NULL; | |
5495 | pos = cmd + 17; | |
5496 | if (*pos != ' ') | |
5497 | return -1; | |
5498 | pos++; | |
5499 | ||
5500 | if (os_strncmp(pos, "upnp ", 5) == 0) { | |
5501 | u8 version; | |
5502 | pos += 5; | |
5503 | if (hexstr2bin(pos, &version, 1) < 0) | |
5504 | return -1; | |
5505 | pos += 2; | |
5506 | if (*pos != ' ') | |
5507 | return -1; | |
5508 | pos++; | |
7165c5dc | 5509 | ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos); |
347d6a5b JM |
5510 | #ifdef CONFIG_WIFI_DISPLAY |
5511 | } else if (os_strncmp(pos, "wifi-display ", 13) == 0) { | |
5512 | ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13); | |
5513 | #endif /* CONFIG_WIFI_DISPLAY */ | |
5a4102ce KV |
5514 | } else if (os_strncmp(pos, "asp ", 4) == 0) { |
5515 | char *svc_str; | |
5516 | char *svc_info = NULL; | |
5517 | u32 id; | |
5518 | ||
5519 | pos += 4; | |
5520 | if (sscanf(pos, "%x", &id) != 1 || id > 0xff) | |
5521 | return -1; | |
5522 | ||
5523 | pos = os_strchr(pos, ' '); | |
5524 | if (pos == NULL || pos[1] == '\0' || pos[1] == ' ') | |
5525 | return -1; | |
5526 | ||
5527 | svc_str = pos + 1; | |
5528 | ||
5529 | pos = os_strchr(svc_str, ' '); | |
5530 | ||
5531 | if (pos) | |
5532 | *pos++ = '\0'; | |
5533 | ||
5534 | /* All remaining data is the svc_info string */ | |
5535 | if (pos && pos[0] && pos[0] != ' ') { | |
5536 | len = os_strlen(pos); | |
5537 | ||
5538 | /* Unescape in place */ | |
5539 | len = utf8_unescape(pos, len, pos, len); | |
5540 | if (len > 0xff) | |
5541 | return -1; | |
5542 | ||
5543 | svc_info = pos; | |
5544 | } | |
5545 | ||
5546 | ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id, | |
5547 | svc_str, svc_info); | |
b563b388 JM |
5548 | } else { |
5549 | len = os_strlen(pos); | |
5550 | if (len & 1) | |
5551 | return -1; | |
5552 | len /= 2; | |
5553 | tlvs = wpabuf_alloc(len); | |
5554 | if (tlvs == NULL) | |
5555 | return -1; | |
5556 | if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) { | |
5557 | wpabuf_free(tlvs); | |
5558 | return -1; | |
5559 | } | |
5560 | ||
7165c5dc | 5561 | ref = wpas_p2p_sd_request(wpa_s, dst, tlvs); |
b563b388 JM |
5562 | wpabuf_free(tlvs); |
5563 | } | |
7165c5dc JM |
5564 | if (ref == 0) |
5565 | return -1; | |
b563b388 | 5566 | res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref); |
d85e1fc8 | 5567 | if (os_snprintf_error(buflen, res)) |
b563b388 JM |
5568 | return -1; |
5569 | return res; | |
5570 | } | |
5571 | ||
5572 | ||
5573 | static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s, | |
5574 | char *cmd) | |
5575 | { | |
5576 | long long unsigned val; | |
5577 | u64 req; | |
5578 | if (sscanf(cmd, "%llx", &val) != 1) | |
5579 | return -1; | |
5580 | req = val; | |
7165c5dc | 5581 | return wpas_p2p_sd_cancel_request(wpa_s, req); |
b563b388 JM |
5582 | } |
5583 | ||
5584 | ||
5585 | static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd) | |
5586 | { | |
5587 | int freq; | |
d25f7212 | 5588 | u8 dst[ETH_ALEN]; |
b563b388 JM |
5589 | u8 dialog_token; |
5590 | struct wpabuf *resp_tlvs; | |
5591 | char *pos, *pos2; | |
5592 | size_t len; | |
5593 | ||
5594 | pos = os_strchr(cmd, ' '); | |
5595 | if (pos == NULL) | |
5596 | return -1; | |
5597 | *pos++ = '\0'; | |
5598 | freq = atoi(cmd); | |
5599 | if (freq == 0) | |
5600 | return -1; | |
5601 | ||
d25f7212 | 5602 | if (hwaddr_aton(pos, dst)) |
b563b388 | 5603 | return -1; |
b563b388 JM |
5604 | pos += 17; |
5605 | if (*pos != ' ') | |
5606 | return -1; | |
5607 | pos++; | |
5608 | ||
5609 | pos2 = os_strchr(pos, ' '); | |
5610 | if (pos2 == NULL) | |
5611 | return -1; | |
5612 | *pos2++ = '\0'; | |
5613 | dialog_token = atoi(pos); | |
5614 | ||
5615 | len = os_strlen(pos2); | |
5616 | if (len & 1) | |
5617 | return -1; | |
5618 | len /= 2; | |
5619 | resp_tlvs = wpabuf_alloc(len); | |
5620 | if (resp_tlvs == NULL) | |
5621 | return -1; | |
5622 | if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) { | |
5623 | wpabuf_free(resp_tlvs); | |
5624 | return -1; | |
5625 | } | |
5626 | ||
5627 | wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs); | |
5628 | wpabuf_free(resp_tlvs); | |
5629 | return 0; | |
5630 | } | |
5631 | ||
5632 | ||
5633 | static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s, | |
5634 | char *cmd) | |
5635 | { | |
28ef705d GB |
5636 | if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1")) |
5637 | return -1; | |
b563b388 JM |
5638 | wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd); |
5639 | return 0; | |
5640 | } | |
5641 | ||
5642 | ||
5643 | static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s, | |
5644 | char *cmd) | |
5645 | { | |
5646 | char *pos; | |
5647 | size_t len; | |
5648 | struct wpabuf *query, *resp; | |
5649 | ||
5650 | pos = os_strchr(cmd, ' '); | |
5651 | if (pos == NULL) | |
5652 | return -1; | |
5653 | *pos++ = '\0'; | |
5654 | ||
5655 | len = os_strlen(cmd); | |
5656 | if (len & 1) | |
5657 | return -1; | |
5658 | len /= 2; | |
5659 | query = wpabuf_alloc(len); | |
5660 | if (query == NULL) | |
5661 | return -1; | |
5662 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | |
5663 | wpabuf_free(query); | |
5664 | return -1; | |
5665 | } | |
5666 | ||
5667 | len = os_strlen(pos); | |
5668 | if (len & 1) { | |
5669 | wpabuf_free(query); | |
5670 | return -1; | |
5671 | } | |
5672 | len /= 2; | |
5673 | resp = wpabuf_alloc(len); | |
5674 | if (resp == NULL) { | |
5675 | wpabuf_free(query); | |
5676 | return -1; | |
5677 | } | |
5678 | if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) { | |
5679 | wpabuf_free(query); | |
5680 | wpabuf_free(resp); | |
5681 | return -1; | |
5682 | } | |
5683 | ||
5684 | if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) { | |
5685 | wpabuf_free(query); | |
5686 | wpabuf_free(resp); | |
5687 | return -1; | |
5688 | } | |
5689 | return 0; | |
5690 | } | |
5691 | ||
5692 | ||
5693 | static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd) | |
5694 | { | |
5695 | char *pos; | |
5696 | u8 version; | |
5697 | ||
5698 | pos = os_strchr(cmd, ' '); | |
5699 | if (pos == NULL) | |
5700 | return -1; | |
5701 | *pos++ = '\0'; | |
5702 | ||
5703 | if (hexstr2bin(cmd, &version, 1) < 0) | |
5704 | return -1; | |
5705 | ||
5706 | return wpas_p2p_service_add_upnp(wpa_s, version, pos); | |
5707 | } | |
5708 | ||
5709 | ||
ae9d45f3 KV |
5710 | static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s, |
5711 | u8 replace, char *cmd) | |
5712 | { | |
5713 | char *pos; | |
5714 | char *adv_str; | |
5715 | u32 auto_accept, adv_id, svc_state, config_methods; | |
5716 | char *svc_info = NULL; | |
e2b7fbf2 MS |
5717 | char *cpt_prio_str; |
5718 | u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1]; | |
ae9d45f3 KV |
5719 | |
5720 | pos = os_strchr(cmd, ' '); | |
5721 | if (pos == NULL) | |
5722 | return -1; | |
5723 | *pos++ = '\0'; | |
5724 | ||
5725 | /* Auto-Accept value is mandatory, and must be one of the | |
5726 | * single values (0, 1, 2, 4) */ | |
5727 | auto_accept = atoi(cmd); | |
5728 | switch (auto_accept) { | |
5729 | case P2PS_SETUP_NONE: /* No auto-accept */ | |
5730 | case P2PS_SETUP_NEW: | |
5731 | case P2PS_SETUP_CLIENT: | |
5732 | case P2PS_SETUP_GROUP_OWNER: | |
5733 | break; | |
5734 | default: | |
5735 | return -1; | |
5736 | } | |
5737 | ||
5738 | /* Advertisement ID is mandatory */ | |
5739 | cmd = pos; | |
5740 | pos = os_strchr(cmd, ' '); | |
5741 | if (pos == NULL) | |
5742 | return -1; | |
5743 | *pos++ = '\0'; | |
5744 | ||
5745 | /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */ | |
5746 | if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0) | |
5747 | return -1; | |
5748 | ||
5749 | /* Only allow replacements if exist, and adds if not */ | |
5750 | if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) { | |
5751 | if (!replace) | |
5752 | return -1; | |
5753 | } else { | |
5754 | if (replace) | |
5755 | return -1; | |
5756 | } | |
5757 | ||
5758 | /* svc_state between 0 - 0xff is mandatory */ | |
5759 | if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff) | |
5760 | return -1; | |
5761 | ||
5762 | pos = os_strchr(pos, ' '); | |
5763 | if (pos == NULL) | |
5764 | return -1; | |
5765 | ||
5766 | /* config_methods is mandatory */ | |
5767 | pos++; | |
5768 | if (sscanf(pos, "%x", &config_methods) != 1) | |
5769 | return -1; | |
5770 | ||
5771 | if (!(config_methods & | |
5772 | (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS))) | |
5773 | return -1; | |
5774 | ||
5775 | pos = os_strchr(pos, ' '); | |
5776 | if (pos == NULL) | |
5777 | return -1; | |
5778 | ||
5779 | pos++; | |
5780 | adv_str = pos; | |
5781 | ||
5782 | /* Advertisement string is mandatory */ | |
5783 | if (!pos[0] || pos[0] == ' ') | |
5784 | return -1; | |
5785 | ||
5786 | /* Terminate svc string */ | |
5787 | pos = os_strchr(pos, ' '); | |
5788 | if (pos != NULL) | |
5789 | *pos++ = '\0'; | |
5790 | ||
e2b7fbf2 MS |
5791 | cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL; |
5792 | if (cpt_prio_str) { | |
5793 | pos = os_strchr(pos, ' '); | |
5794 | if (pos != NULL) | |
5795 | *pos++ = '\0'; | |
5796 | ||
5797 | if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio)) | |
5798 | return -1; | |
5799 | } else { | |
5800 | cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; | |
5801 | cpt_prio[1] = 0; | |
5802 | } | |
5803 | ||
ae9d45f3 KV |
5804 | /* Service and Response Information are optional */ |
5805 | if (pos && pos[0]) { | |
5806 | size_t len; | |
5807 | ||
5808 | /* Note the bare ' included, which cannot exist legally | |
5809 | * in unescaped string. */ | |
5810 | svc_info = os_strstr(pos, "svc_info='"); | |
5811 | ||
5812 | if (svc_info) { | |
5813 | svc_info += 9; | |
5814 | len = os_strlen(svc_info); | |
5815 | utf8_unescape(svc_info, len, svc_info, len); | |
5816 | } | |
5817 | } | |
5818 | ||
5819 | return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str, | |
5820 | (u8) svc_state, (u16) config_methods, | |
e2b7fbf2 | 5821 | svc_info, cpt_prio); |
ae9d45f3 KV |
5822 | } |
5823 | ||
5824 | ||
b563b388 JM |
5825 | static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd) |
5826 | { | |
5827 | char *pos; | |
5828 | ||
5829 | pos = os_strchr(cmd, ' '); | |
5830 | if (pos == NULL) | |
5831 | return -1; | |
5832 | *pos++ = '\0'; | |
5833 | ||
5834 | if (os_strcmp(cmd, "bonjour") == 0) | |
5835 | return p2p_ctrl_service_add_bonjour(wpa_s, pos); | |
5836 | if (os_strcmp(cmd, "upnp") == 0) | |
5837 | return p2p_ctrl_service_add_upnp(wpa_s, pos); | |
ae9d45f3 KV |
5838 | if (os_strcmp(cmd, "asp") == 0) |
5839 | return p2p_ctrl_service_add_asp(wpa_s, 0, pos); | |
b563b388 JM |
5840 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
5841 | return -1; | |
5842 | } | |
5843 | ||
5844 | ||
5845 | static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s, | |
5846 | char *cmd) | |
5847 | { | |
5848 | size_t len; | |
5849 | struct wpabuf *query; | |
5850 | int ret; | |
5851 | ||
5852 | len = os_strlen(cmd); | |
5853 | if (len & 1) | |
5854 | return -1; | |
5855 | len /= 2; | |
5856 | query = wpabuf_alloc(len); | |
5857 | if (query == NULL) | |
5858 | return -1; | |
5859 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | |
5860 | wpabuf_free(query); | |
5861 | return -1; | |
5862 | } | |
5863 | ||
5864 | ret = wpas_p2p_service_del_bonjour(wpa_s, query); | |
5865 | wpabuf_free(query); | |
5866 | return ret; | |
5867 | } | |
5868 | ||
5869 | ||
5870 | static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd) | |
5871 | { | |
5872 | char *pos; | |
5873 | u8 version; | |
5874 | ||
5875 | pos = os_strchr(cmd, ' '); | |
5876 | if (pos == NULL) | |
5877 | return -1; | |
5878 | *pos++ = '\0'; | |
5879 | ||
5880 | if (hexstr2bin(cmd, &version, 1) < 0) | |
5881 | return -1; | |
5882 | ||
5883 | return wpas_p2p_service_del_upnp(wpa_s, version, pos); | |
5884 | } | |
5885 | ||
5886 | ||
ae9d45f3 KV |
5887 | static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd) |
5888 | { | |
5889 | u32 adv_id; | |
5890 | ||
e9d28050 MS |
5891 | if (os_strcmp(cmd, "all") == 0) { |
5892 | wpas_p2p_service_flush_asp(wpa_s); | |
5893 | return 0; | |
5894 | } | |
5895 | ||
ae9d45f3 KV |
5896 | if (sscanf(cmd, "%x", &adv_id) != 1) |
5897 | return -1; | |
5898 | ||
5899 | return wpas_p2p_service_del_asp(wpa_s, adv_id); | |
5900 | } | |
5901 | ||
5902 | ||
b563b388 JM |
5903 | static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd) |
5904 | { | |
5905 | char *pos; | |
5906 | ||
5907 | pos = os_strchr(cmd, ' '); | |
5908 | if (pos == NULL) | |
5909 | return -1; | |
5910 | *pos++ = '\0'; | |
5911 | ||
5912 | if (os_strcmp(cmd, "bonjour") == 0) | |
5913 | return p2p_ctrl_service_del_bonjour(wpa_s, pos); | |
5914 | if (os_strcmp(cmd, "upnp") == 0) | |
5915 | return p2p_ctrl_service_del_upnp(wpa_s, pos); | |
ae9d45f3 KV |
5916 | if (os_strcmp(cmd, "asp") == 0) |
5917 | return p2p_ctrl_service_del_asp(wpa_s, pos); | |
5918 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | |
5919 | return -1; | |
5920 | } | |
5921 | ||
5922 | ||
5923 | static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd) | |
5924 | { | |
5925 | char *pos; | |
5926 | ||
5927 | pos = os_strchr(cmd, ' '); | |
5928 | if (pos == NULL) | |
5929 | return -1; | |
5930 | *pos++ = '\0'; | |
5931 | ||
5932 | if (os_strcmp(cmd, "asp") == 0) | |
5933 | return p2p_ctrl_service_add_asp(wpa_s, 1, pos); | |
5934 | ||
b563b388 JM |
5935 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
5936 | return -1; | |
5937 | } | |
5938 | ||
5939 | ||
5940 | static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd) | |
5941 | { | |
5942 | u8 addr[ETH_ALEN]; | |
5943 | ||
5944 | /* <addr> */ | |
5945 | ||
5946 | if (hwaddr_aton(cmd, addr)) | |
5947 | return -1; | |
5948 | ||
5949 | return wpas_p2p_reject(wpa_s, addr); | |
5950 | } | |
5951 | ||
5952 | ||
5953 | static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd) | |
5954 | { | |
5955 | char *pos; | |
5956 | int id; | |
5957 | struct wpa_ssid *ssid; | |
54c61e6e | 5958 | u8 *_peer = NULL, peer[ETH_ALEN]; |
f5877af0 | 5959 | int freq = 0, pref_freq = 0; |
c27f4c90 | 5960 | int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0; |
b563b388 JM |
5961 | |
5962 | id = atoi(cmd); | |
5963 | pos = os_strstr(cmd, " peer="); | |
5964 | if (pos) { | |
5965 | pos += 6; | |
5966 | if (hwaddr_aton(pos, peer)) | |
5967 | return -1; | |
54c61e6e | 5968 | _peer = peer; |
b563b388 JM |
5969 | } |
5970 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
5971 | if (ssid == NULL || ssid->disabled != 2) { | |
5972 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
5973 | "for persistent P2P group", | |
5974 | id); | |
5975 | return -1; | |
5976 | } | |
5977 | ||
4d32c0c4 JM |
5978 | pos = os_strstr(cmd, " freq="); |
5979 | if (pos) { | |
5980 | pos += 6; | |
5981 | freq = atoi(pos); | |
5982 | if (freq <= 0) | |
5983 | return -1; | |
5984 | } | |
5985 | ||
f5877af0 JM |
5986 | pos = os_strstr(cmd, " pref="); |
5987 | if (pos) { | |
5988 | pos += 6; | |
5989 | pref_freq = atoi(pos); | |
5990 | if (pref_freq <= 0) | |
5991 | return -1; | |
5992 | } | |
5993 | ||
20ea1ca4 EP |
5994 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
5995 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | |
5996 | vht; | |
4d32c0c4 | 5997 | |
c27f4c90 AK |
5998 | pos = os_strstr(cmd, "freq2="); |
5999 | if (pos) | |
6000 | freq2 = atoi(pos + 6); | |
6001 | ||
6002 | pos = os_strstr(cmd, " max_oper_chwidth="); | |
6003 | if (pos) | |
6004 | chwidth = atoi(pos + 18); | |
6005 | ||
6006 | max_oper_chwidth = parse_freq(chwidth, freq2); | |
6007 | if (max_oper_chwidth < 0) | |
6008 | return -1; | |
6009 | ||
6010 | return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht, | |
6011 | max_oper_chwidth, pref_freq); | |
b563b388 JM |
6012 | } |
6013 | ||
6014 | ||
6015 | static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd) | |
6016 | { | |
6017 | char *pos; | |
6018 | u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL; | |
6019 | ||
6020 | pos = os_strstr(cmd, " peer="); | |
6021 | if (!pos) | |
6022 | return -1; | |
6023 | ||
6024 | *pos = '\0'; | |
6025 | pos += 6; | |
6026 | if (hwaddr_aton(pos, peer)) { | |
6027 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos); | |
6028 | return -1; | |
6029 | } | |
6030 | ||
6031 | pos = os_strstr(pos, " go_dev_addr="); | |
6032 | if (pos) { | |
6033 | pos += 13; | |
6034 | if (hwaddr_aton(pos, go_dev_addr)) { | |
6035 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", | |
6036 | pos); | |
6037 | return -1; | |
6038 | } | |
6039 | go_dev = go_dev_addr; | |
6040 | } | |
6041 | ||
6042 | return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev); | |
6043 | } | |
6044 | ||
6045 | ||
6046 | static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd) | |
6047 | { | |
6048 | if (os_strncmp(cmd, "persistent=", 11) == 0) | |
6049 | return p2p_ctrl_invite_persistent(wpa_s, cmd + 11); | |
6050 | if (os_strncmp(cmd, "group=", 6) == 0) | |
6051 | return p2p_ctrl_invite_group(wpa_s, cmd + 6); | |
6052 | ||
6053 | return -1; | |
6054 | } | |
6055 | ||
6056 | ||
6057 | static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, | |
c27f4c90 AK |
6058 | int id, int freq, int vht_center_freq2, |
6059 | int ht40, int vht, int vht_chwidth) | |
b563b388 | 6060 | { |
b563b388 JM |
6061 | struct wpa_ssid *ssid; |
6062 | ||
b563b388 JM |
6063 | ssid = wpa_config_get_network(wpa_s->conf, id); |
6064 | if (ssid == NULL || ssid->disabled != 2) { | |
6065 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | |
6066 | "for persistent P2P group", | |
6067 | id); | |
6068 | return -1; | |
6069 | } | |
6070 | ||
c27f4c90 AK |
6071 | return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, |
6072 | vht_center_freq2, 0, ht40, vht, | |
6073 | vht_chwidth, NULL, 0, 0); | |
b563b388 JM |
6074 | } |
6075 | ||
6076 | ||
6077 | static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) | |
6078 | { | |
29292d53 EP |
6079 | int freq = 0, persistent = 0, group_id = -1; |
6080 | int vht = wpa_s->conf->p2p_go_vht; | |
6081 | int ht40 = wpa_s->conf->p2p_go_ht40 || vht; | |
c27f4c90 | 6082 | int max_oper_chwidth, chwidth = 0, freq2 = 0; |
29292d53 | 6083 | char *token, *context = NULL; |
e11776a5 | 6084 | |
29292d53 EP |
6085 | while ((token = str_token(cmd, " ", &context))) { |
6086 | if (sscanf(token, "freq=%d", &freq) == 1 || | |
c27f4c90 AK |
6087 | sscanf(token, "freq2=%d", &freq2) == 1 || |
6088 | sscanf(token, "persistent=%d", &group_id) == 1 || | |
6089 | sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) { | |
29292d53 EP |
6090 | continue; |
6091 | } else if (os_strcmp(token, "ht40") == 0) { | |
6092 | ht40 = 1; | |
6093 | } else if (os_strcmp(token, "vht") == 0) { | |
6094 | vht = 1; | |
6095 | ht40 = 1; | |
6096 | } else if (os_strcmp(token, "persistent") == 0) { | |
6097 | persistent = 1; | |
6098 | } else { | |
6099 | wpa_printf(MSG_DEBUG, | |
6100 | "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'", | |
6101 | token); | |
6102 | return -1; | |
6103 | } | |
e11776a5 PK |
6104 | } |
6105 | ||
c27f4c90 AK |
6106 | max_oper_chwidth = parse_freq(chwidth, freq2); |
6107 | if (max_oper_chwidth < 0) | |
6108 | return -1; | |
6109 | ||
29292d53 EP |
6110 | if (group_id >= 0) |
6111 | return p2p_ctrl_group_add_persistent(wpa_s, group_id, | |
c27f4c90 AK |
6112 | freq, freq2, ht40, vht, |
6113 | max_oper_chwidth); | |
29292d53 | 6114 | |
c27f4c90 AK |
6115 | return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht, |
6116 | max_oper_chwidth); | |
b563b388 JM |
6117 | } |
6118 | ||
6119 | ||
57b38882 PK |
6120 | static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd, |
6121 | char *buf, size_t buflen) | |
6122 | { | |
6123 | u8 dev_addr[ETH_ALEN]; | |
6124 | struct wpa_ssid *ssid; | |
6125 | int res; | |
6126 | const u8 *iaddr; | |
6127 | ||
6128 | ssid = wpa_s->current_ssid; | |
6129 | if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO || | |
6130 | hwaddr_aton(cmd, dev_addr)) | |
6131 | return -1; | |
6132 | ||
6133 | iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr); | |
6134 | if (!iaddr) | |
6135 | return -1; | |
6136 | res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr)); | |
6137 | if (os_snprintf_error(buflen, res)) | |
6138 | return -1; | |
6139 | return res; | |
6140 | } | |
6141 | ||
6142 | ||
f47f9361 SD |
6143 | static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global, |
6144 | const u8 *p2p_dev_addr) | |
6145 | { | |
6146 | struct wpa_supplicant *wpa_s; | |
6147 | ||
6148 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
6149 | if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr)) | |
6150 | return 1; | |
6151 | } | |
6152 | ||
6153 | return 0; | |
6154 | } | |
6155 | ||
6156 | ||
b563b388 JM |
6157 | static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd, |
6158 | char *buf, size_t buflen) | |
6159 | { | |
f47f9361 | 6160 | u8 addr[ETH_ALEN], *addr_ptr, group_capab; |
b3ffc80b JM |
6161 | int next, res; |
6162 | const struct p2p_peer_info *info; | |
6163 | char *pos, *end; | |
6164 | char devtype[WPS_DEV_TYPE_BUFSIZE]; | |
87f841a1 | 6165 | struct wpa_ssid *ssid; |
f3989ced | 6166 | size_t i; |
b563b388 JM |
6167 | |
6168 | if (!wpa_s->global->p2p) | |
6169 | return -1; | |
6170 | ||
6171 | if (os_strcmp(cmd, "FIRST") == 0) { | |
6172 | addr_ptr = NULL; | |
6173 | next = 0; | |
6174 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | |
6175 | if (hwaddr_aton(cmd + 5, addr) < 0) | |
6176 | return -1; | |
6177 | addr_ptr = addr; | |
6178 | next = 1; | |
6179 | } else { | |
6180 | if (hwaddr_aton(cmd, addr) < 0) | |
6181 | return -1; | |
6182 | addr_ptr = addr; | |
6183 | next = 0; | |
6184 | } | |
6185 | ||
b3ffc80b JM |
6186 | info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next); |
6187 | if (info == NULL) | |
6188 | return -1; | |
f47f9361 SD |
6189 | group_capab = info->group_capab; |
6190 | ||
6191 | if (group_capab && | |
6192 | !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) { | |
6193 | wpa_printf(MSG_DEBUG, | |
6194 | "P2P: Could not find any BSS with p2p_dev_addr " | |
6195 | MACSTR ", hence override group_capab from 0x%x to 0", | |
6196 | MAC2STR(info->p2p_device_addr), group_capab); | |
6197 | group_capab = 0; | |
6198 | } | |
b3ffc80b JM |
6199 | |
6200 | pos = buf; | |
6201 | end = buf + buflen; | |
6202 | ||
6203 | res = os_snprintf(pos, end - pos, MACSTR "\n" | |
6204 | "pri_dev_type=%s\n" | |
6205 | "device_name=%s\n" | |
6206 | "manufacturer=%s\n" | |
6207 | "model_name=%s\n" | |
6208 | "model_number=%s\n" | |
6209 | "serial_number=%s\n" | |
6210 | "config_methods=0x%x\n" | |
6211 | "dev_capab=0x%x\n" | |
6212 | "group_capab=0x%x\n" | |
6213 | "level=%d\n", | |
6214 | MAC2STR(info->p2p_device_addr), | |
6215 | wps_dev_type_bin2str(info->pri_dev_type, | |
6216 | devtype, sizeof(devtype)), | |
6217 | info->device_name, | |
6218 | info->manufacturer, | |
6219 | info->model_name, | |
6220 | info->model_number, | |
6221 | info->serial_number, | |
6222 | info->config_methods, | |
6223 | info->dev_capab, | |
f47f9361 | 6224 | group_capab, |
b3ffc80b | 6225 | info->level); |
d85e1fc8 | 6226 | if (os_snprintf_error(end - pos, res)) |
b3ffc80b JM |
6227 | return pos - buf; |
6228 | pos += res; | |
6229 | ||
f3989ced JM |
6230 | for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++) |
6231 | { | |
6232 | const u8 *t; | |
6233 | t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN]; | |
6234 | res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n", | |
6235 | wps_dev_type_bin2str(t, devtype, | |
6236 | sizeof(devtype))); | |
d85e1fc8 | 6237 | if (os_snprintf_error(end - pos, res)) |
f3989ced JM |
6238 | return pos - buf; |
6239 | pos += res; | |
6240 | } | |
6241 | ||
c427ac92 | 6242 | ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0); |
87f841a1 JM |
6243 | if (ssid) { |
6244 | res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id); | |
d85e1fc8 | 6245 | if (os_snprintf_error(end - pos, res)) |
87f841a1 JM |
6246 | return pos - buf; |
6247 | pos += res; | |
6248 | } | |
6249 | ||
b3ffc80b JM |
6250 | res = p2p_get_peer_info_txt(info, pos, end - pos); |
6251 | if (res < 0) | |
87f841a1 | 6252 | return pos - buf; |
b3ffc80b JM |
6253 | pos += res; |
6254 | ||
71a0e395 JM |
6255 | if (info->vendor_elems) { |
6256 | res = os_snprintf(pos, end - pos, "vendor_elems="); | |
d85e1fc8 | 6257 | if (os_snprintf_error(end - pos, res)) |
71a0e395 JM |
6258 | return pos - buf; |
6259 | pos += res; | |
6260 | ||
6261 | pos += wpa_snprintf_hex(pos, end - pos, | |
6262 | wpabuf_head(info->vendor_elems), | |
6263 | wpabuf_len(info->vendor_elems)); | |
6264 | ||
6265 | res = os_snprintf(pos, end - pos, "\n"); | |
d85e1fc8 | 6266 | if (os_snprintf_error(end - pos, res)) |
71a0e395 JM |
6267 | return pos - buf; |
6268 | pos += res; | |
6269 | } | |
6270 | ||
b3ffc80b | 6271 | return pos - buf; |
b563b388 JM |
6272 | } |
6273 | ||
6274 | ||
6f3bc72b JM |
6275 | static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s, |
6276 | const char *param) | |
6277 | { | |
af8a827b | 6278 | unsigned int i; |
6f3bc72b JM |
6279 | |
6280 | if (wpa_s->global->p2p == NULL) | |
6281 | return -1; | |
6282 | ||
af8a827b JM |
6283 | if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0) |
6284 | return -1; | |
6f3bc72b | 6285 | |
af8a827b JM |
6286 | for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) { |
6287 | struct wpa_freq_range *freq; | |
6288 | freq = &wpa_s->global->p2p_disallow_freq.range[i]; | |
6f3bc72b | 6289 | wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u", |
af8a827b | 6290 | freq->min, freq->max); |
6f3bc72b JM |
6291 | } |
6292 | ||
3a8f008a | 6293 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW); |
6f3bc72b JM |
6294 | return 0; |
6295 | } | |
6296 | ||
6297 | ||
b563b388 JM |
6298 | static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) |
6299 | { | |
6300 | char *param; | |
6301 | ||
6302 | if (wpa_s->global->p2p == NULL) | |
6303 | return -1; | |
6304 | ||
6305 | param = os_strchr(cmd, ' '); | |
6306 | if (param == NULL) | |
6307 | return -1; | |
6308 | *param++ = '\0'; | |
6309 | ||
6310 | if (os_strcmp(cmd, "discoverability") == 0) { | |
6311 | p2p_set_client_discoverability(wpa_s->global->p2p, | |
6312 | atoi(param)); | |
6313 | return 0; | |
6314 | } | |
6315 | ||
6316 | if (os_strcmp(cmd, "managed") == 0) { | |
6317 | p2p_set_managed_oper(wpa_s->global->p2p, atoi(param)); | |
6318 | return 0; | |
6319 | } | |
6320 | ||
6321 | if (os_strcmp(cmd, "listen_channel") == 0) { | |
dfe0745c LD |
6322 | char *pos; |
6323 | u8 channel, op_class; | |
6324 | ||
6325 | channel = atoi(param); | |
6326 | pos = os_strchr(param, ' '); | |
6327 | op_class = pos ? atoi(pos) : 81; | |
6328 | ||
6329 | return p2p_set_listen_channel(wpa_s->global->p2p, op_class, | |
6330 | channel, 1); | |
b563b388 JM |
6331 | } |
6332 | ||
6333 | if (os_strcmp(cmd, "ssid_postfix") == 0) { | |
6334 | return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param, | |
6335 | os_strlen(param)); | |
6336 | } | |
6337 | ||
6338 | if (os_strcmp(cmd, "noa") == 0) { | |
6339 | char *pos; | |
6340 | int count, start, duration; | |
6341 | /* GO NoA parameters: count,start_offset(ms),duration(ms) */ | |
6342 | count = atoi(param); | |
6343 | pos = os_strchr(param, ','); | |
6344 | if (pos == NULL) | |
6345 | return -1; | |
6346 | pos++; | |
6347 | start = atoi(pos); | |
6348 | pos = os_strchr(pos, ','); | |
6349 | if (pos == NULL) | |
6350 | return -1; | |
6351 | pos++; | |
6352 | duration = atoi(pos); | |
6353 | if (count < 0 || count > 255 || start < 0 || duration < 0) | |
6354 | return -1; | |
6355 | if (count == 0 && duration > 0) | |
6356 | return -1; | |
6357 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d " | |
6358 | "start=%d duration=%d", count, start, duration); | |
aefb53bd | 6359 | return wpas_p2p_set_noa(wpa_s, count, start, duration); |
b563b388 JM |
6360 | } |
6361 | ||
c381508d JM |
6362 | if (os_strcmp(cmd, "ps") == 0) |
6363 | return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1); | |
6364 | ||
6365 | if (os_strcmp(cmd, "oppps") == 0) | |
6366 | return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1); | |
6367 | ||
6368 | if (os_strcmp(cmd, "ctwindow") == 0) | |
6369 | return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param)); | |
6370 | ||
b563b388 JM |
6371 | if (os_strcmp(cmd, "disabled") == 0) { |
6372 | wpa_s->global->p2p_disabled = atoi(param); | |
6373 | wpa_printf(MSG_DEBUG, "P2P functionality %s", | |
6374 | wpa_s->global->p2p_disabled ? | |
6375 | "disabled" : "enabled"); | |
6376 | if (wpa_s->global->p2p_disabled) { | |
6377 | wpas_p2p_stop_find(wpa_s); | |
108def93 | 6378 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
b563b388 JM |
6379 | p2p_flush(wpa_s->global->p2p); |
6380 | } | |
6381 | return 0; | |
6382 | } | |
6383 | ||
b9cfc09a JJ |
6384 | if (os_strcmp(cmd, "conc_pref") == 0) { |
6385 | if (os_strcmp(param, "sta") == 0) | |
6386 | wpa_s->global->conc_pref = WPA_CONC_PREF_STA; | |
6387 | else if (os_strcmp(param, "p2p") == 0) | |
6388 | wpa_s->global->conc_pref = WPA_CONC_PREF_P2P; | |
6389 | else { | |
6390 | wpa_printf(MSG_INFO, "Invalid conc_pref value"); | |
6391 | return -1; | |
6392 | } | |
6393 | wpa_printf(MSG_DEBUG, "Single channel concurrency preference: " | |
6394 | "%s", param); | |
6395 | return 0; | |
6396 | } | |
6397 | ||
6e6963ea JM |
6398 | if (os_strcmp(cmd, "force_long_sd") == 0) { |
6399 | wpa_s->force_long_sd = atoi(param); | |
6400 | return 0; | |
6401 | } | |
6402 | ||
80c9582a JM |
6403 | if (os_strcmp(cmd, "peer_filter") == 0) { |
6404 | u8 addr[ETH_ALEN]; | |
6405 | if (hwaddr_aton(param, addr)) | |
6406 | return -1; | |
6407 | p2p_set_peer_filter(wpa_s->global->p2p, addr); | |
6408 | return 0; | |
6409 | } | |
6410 | ||
72044390 JM |
6411 | if (os_strcmp(cmd, "cross_connect") == 0) |
6412 | return wpas_p2p_set_cross_connect(wpa_s, atoi(param)); | |
6413 | ||
eea2fd9e JM |
6414 | if (os_strcmp(cmd, "go_apsd") == 0) { |
6415 | if (os_strcmp(param, "disable") == 0) | |
6416 | wpa_s->set_ap_uapsd = 0; | |
6417 | else { | |
6418 | wpa_s->set_ap_uapsd = 1; | |
6419 | wpa_s->ap_uapsd = atoi(param); | |
6420 | } | |
6421 | return 0; | |
6422 | } | |
6423 | ||
6424 | if (os_strcmp(cmd, "client_apsd") == 0) { | |
6425 | if (os_strcmp(param, "disable") == 0) | |
6426 | wpa_s->set_sta_uapsd = 0; | |
6427 | else { | |
6428 | int be, bk, vi, vo; | |
6429 | char *pos; | |
6430 | /* format: BE,BK,VI,VO;max SP Length */ | |
6431 | be = atoi(param); | |
6432 | pos = os_strchr(param, ','); | |
6433 | if (pos == NULL) | |
6434 | return -1; | |
6435 | pos++; | |
6436 | bk = atoi(pos); | |
6437 | pos = os_strchr(pos, ','); | |
6438 | if (pos == NULL) | |
6439 | return -1; | |
6440 | pos++; | |
6441 | vi = atoi(pos); | |
6442 | pos = os_strchr(pos, ','); | |
6443 | if (pos == NULL) | |
6444 | return -1; | |
6445 | pos++; | |
6446 | vo = atoi(pos); | |
6447 | /* ignore max SP Length for now */ | |
6448 | ||
6449 | wpa_s->set_sta_uapsd = 1; | |
6450 | wpa_s->sta_uapsd = 0; | |
6451 | if (be) | |
6452 | wpa_s->sta_uapsd |= BIT(0); | |
6453 | if (bk) | |
6454 | wpa_s->sta_uapsd |= BIT(1); | |
6455 | if (vi) | |
6456 | wpa_s->sta_uapsd |= BIT(2); | |
6457 | if (vo) | |
6458 | wpa_s->sta_uapsd |= BIT(3); | |
6459 | } | |
6460 | return 0; | |
6461 | } | |
6462 | ||
6f3bc72b JM |
6463 | if (os_strcmp(cmd, "disallow_freq") == 0) |
6464 | return p2p_ctrl_disallow_freq(wpa_s, param); | |
6465 | ||
96beff11 JM |
6466 | if (os_strcmp(cmd, "disc_int") == 0) { |
6467 | int min_disc_int, max_disc_int, max_disc_tu; | |
6468 | char *pos; | |
6469 | ||
6470 | pos = param; | |
6471 | ||
6472 | min_disc_int = atoi(pos); | |
6473 | pos = os_strchr(pos, ' '); | |
6474 | if (pos == NULL) | |
6475 | return -1; | |
6476 | *pos++ = '\0'; | |
6477 | ||
6478 | max_disc_int = atoi(pos); | |
6479 | pos = os_strchr(pos, ' '); | |
6480 | if (pos == NULL) | |
6481 | return -1; | |
6482 | *pos++ = '\0'; | |
6483 | ||
6484 | max_disc_tu = atoi(pos); | |
6485 | ||
6486 | return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int, | |
6487 | max_disc_int, max_disc_tu); | |
6488 | } | |
6489 | ||
05766ed8 JM |
6490 | if (os_strcmp(cmd, "per_sta_psk") == 0) { |
6491 | wpa_s->global->p2p_per_sta_psk = !!atoi(param); | |
6492 | return 0; | |
6493 | } | |
6494 | ||
c4f87a70 JM |
6495 | #ifdef CONFIG_WPS_NFC |
6496 | if (os_strcmp(cmd, "nfc_tag") == 0) | |
6497 | return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param)); | |
6498 | #endif /* CONFIG_WPS_NFC */ | |
6499 | ||
201b0f5f JM |
6500 | if (os_strcmp(cmd, "disable_ip_addr_req") == 0) { |
6501 | wpa_s->p2p_disable_ip_addr_req = !!atoi(param); | |
6502 | return 0; | |
6503 | } | |
6504 | ||
3a7819f0 JM |
6505 | if (os_strcmp(cmd, "override_pref_op_chan") == 0) { |
6506 | int op_class, chan; | |
6507 | ||
6508 | op_class = atoi(param); | |
6509 | param = os_strchr(param, ':'); | |
6510 | if (!param) | |
6511 | return -1; | |
6512 | param++; | |
6513 | chan = atoi(param); | |
6514 | p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class, | |
6515 | chan); | |
6516 | return 0; | |
6517 | } | |
6518 | ||
b563b388 JM |
6519 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", |
6520 | cmd); | |
6521 | ||
6522 | return -1; | |
6523 | } | |
6524 | ||
6525 | ||
acb54643 JM |
6526 | static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s) |
6527 | { | |
6528 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); | |
6529 | wpa_s->force_long_sd = 0; | |
477b082c | 6530 | wpas_p2p_stop_find(wpa_s); |
b9da88d6 | 6531 | wpa_s->parent->p2ps_method_config_any = 0; |
acb54643 JM |
6532 | if (wpa_s->global->p2p) |
6533 | p2p_flush(wpa_s->global->p2p); | |
6534 | } | |
6535 | ||
6536 | ||
b563b388 JM |
6537 | static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd) |
6538 | { | |
6539 | char *pos, *pos2; | |
6540 | unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0; | |
6541 | ||
6542 | if (cmd[0]) { | |
6543 | pos = os_strchr(cmd, ' '); | |
6544 | if (pos == NULL) | |
6545 | return -1; | |
6546 | *pos++ = '\0'; | |
6547 | dur1 = atoi(cmd); | |
6548 | ||
6549 | pos2 = os_strchr(pos, ' '); | |
6550 | if (pos2) | |
6551 | *pos2++ = '\0'; | |
6552 | int1 = atoi(pos); | |
6553 | } else | |
6554 | pos2 = NULL; | |
6555 | ||
6556 | if (pos2) { | |
6557 | pos = os_strchr(pos2, ' '); | |
6558 | if (pos == NULL) | |
6559 | return -1; | |
6560 | *pos++ = '\0'; | |
6561 | dur2 = atoi(pos2); | |
6562 | int2 = atoi(pos); | |
6563 | } | |
6564 | ||
6565 | return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2); | |
6566 | } | |
6567 | ||
6568 | ||
6569 | static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) | |
6570 | { | |
6571 | char *pos; | |
6572 | unsigned int period = 0, interval = 0; | |
6573 | ||
6574 | if (cmd[0]) { | |
6575 | pos = os_strchr(cmd, ' '); | |
6576 | if (pos == NULL) | |
6577 | return -1; | |
6578 | *pos++ = '\0'; | |
6579 | period = atoi(cmd); | |
6580 | interval = atoi(pos); | |
6581 | } | |
6582 | ||
6583 | return wpas_p2p_ext_listen(wpa_s, period, interval); | |
6584 | } | |
6585 | ||
f2c56602 JM |
6586 | |
6587 | static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd) | |
6588 | { | |
6589 | const char *pos; | |
6590 | u8 peer[ETH_ALEN]; | |
6591 | int iface_addr = 0; | |
6592 | ||
6593 | pos = cmd; | |
6594 | if (os_strncmp(pos, "iface=", 6) == 0) { | |
6595 | iface_addr = 1; | |
6596 | pos += 6; | |
6597 | } | |
6598 | if (hwaddr_aton(pos, peer)) | |
6599 | return -1; | |
6600 | ||
6601 | wpas_p2p_remove_client(wpa_s, peer, iface_addr); | |
6602 | return 0; | |
6603 | } | |
6604 | ||
a6f5b193 PX |
6605 | |
6606 | static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd) | |
6607 | { | |
6608 | int freq = 0, period = 0, interval = 0, count = 0; | |
6609 | ||
6610 | if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4) | |
6611 | { | |
6612 | wpa_printf(MSG_DEBUG, | |
6613 | "CTRL: Invalid P2P LO Start parameter: '%s'", cmd); | |
6614 | return -1; | |
6615 | } | |
6616 | ||
6617 | return wpas_p2p_lo_start(wpa_s, freq, period, interval, count); | |
6618 | } | |
6619 | ||
b563b388 JM |
6620 | #endif /* CONFIG_P2P */ |
6621 | ||
6622 | ||
356d1488 JM |
6623 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val) |
6624 | { | |
6625 | struct wpa_freq_range_list ranges; | |
6626 | int *freqs = NULL; | |
6627 | struct hostapd_hw_modes *mode; | |
6628 | u16 i; | |
6629 | ||
6630 | if (wpa_s->hw.modes == NULL) | |
6631 | return NULL; | |
6632 | ||
6633 | os_memset(&ranges, 0, sizeof(ranges)); | |
6634 | if (freq_range_list_parse(&ranges, val) < 0) | |
6635 | return NULL; | |
6636 | ||
6637 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
6638 | int j; | |
6639 | ||
6640 | mode = &wpa_s->hw.modes[i]; | |
6641 | for (j = 0; j < mode->num_channels; j++) { | |
6642 | unsigned int freq; | |
6643 | ||
6644 | if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED) | |
6645 | continue; | |
6646 | ||
6647 | freq = mode->channels[j].freq; | |
6648 | if (!freq_range_list_includes(&ranges, freq)) | |
6649 | continue; | |
6650 | ||
6651 | int_array_add_unique(&freqs, freq); | |
6652 | } | |
6653 | } | |
6654 | ||
6655 | os_free(ranges.range); | |
6656 | return freqs; | |
6657 | } | |
6658 | ||
6659 | ||
afc064fe | 6660 | #ifdef CONFIG_INTERWORKING |
356d1488 JM |
6661 | |
6662 | static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param) | |
6663 | { | |
6664 | int auto_sel = 0; | |
6665 | int *freqs = NULL; | |
6666 | ||
6667 | if (param) { | |
6668 | char *pos; | |
6669 | ||
6670 | auto_sel = os_strstr(param, "auto") != NULL; | |
6671 | ||
6672 | pos = os_strstr(param, "freq="); | |
6673 | if (pos) { | |
6674 | freqs = freq_range_to_channel_list(wpa_s, pos + 5); | |
6675 | if (freqs == NULL) | |
6676 | return -1; | |
6677 | } | |
6678 | ||
6679 | } | |
6680 | ||
6681 | return interworking_select(wpa_s, auto_sel, freqs); | |
6682 | } | |
6683 | ||
6684 | ||
f91a512f JM |
6685 | static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst, |
6686 | int only_add) | |
b02fe7ff JM |
6687 | { |
6688 | u8 bssid[ETH_ALEN]; | |
6689 | struct wpa_bss *bss; | |
6690 | ||
6691 | if (hwaddr_aton(dst, bssid)) { | |
6692 | wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst); | |
6693 | return -1; | |
6694 | } | |
6695 | ||
6696 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
6697 | if (bss == NULL) { | |
6698 | wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR, | |
6699 | MAC2STR(bssid)); | |
6700 | return -1; | |
6701 | } | |
6702 | ||
783b2a97 JM |
6703 | if (bss->ssid_len == 0) { |
6704 | int found = 0; | |
6705 | ||
6706 | wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR | |
6707 | " does not have SSID information", MAC2STR(bssid)); | |
6708 | ||
6709 | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, | |
6710 | list) { | |
6711 | if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 && | |
6712 | bss->ssid_len > 0) { | |
6713 | found = 1; | |
6714 | break; | |
6715 | } | |
6716 | } | |
6717 | ||
6718 | if (!found) | |
6719 | return -1; | |
6720 | wpa_printf(MSG_DEBUG, | |
6721 | "Found another matching BSS entry with SSID"); | |
6722 | } | |
6723 | ||
f91a512f | 6724 | return interworking_connect(wpa_s, bss, only_add); |
b02fe7ff JM |
6725 | } |
6726 | ||
6727 | ||
afc064fe JM |
6728 | static int get_anqp(struct wpa_supplicant *wpa_s, char *dst) |
6729 | { | |
6730 | u8 dst_addr[ETH_ALEN]; | |
6731 | int used; | |
6732 | char *pos; | |
6733 | #define MAX_ANQP_INFO_ID 100 | |
6734 | u16 id[MAX_ANQP_INFO_ID]; | |
6735 | size_t num_id = 0; | |
cf28c66b | 6736 | u32 subtypes = 0; |
2316cb35 | 6737 | u32 mbo_subtypes = 0; |
afc064fe JM |
6738 | |
6739 | used = hwaddr_aton2(dst, dst_addr); | |
6740 | if (used < 0) | |
6741 | return -1; | |
6742 | pos = dst + used; | |
b68d602d JM |
6743 | if (*pos == ' ') |
6744 | pos++; | |
afc064fe | 6745 | while (num_id < MAX_ANQP_INFO_ID) { |
cf28c66b DS |
6746 | if (os_strncmp(pos, "hs20:", 5) == 0) { |
6747 | #ifdef CONFIG_HS20 | |
6748 | int num = atoi(pos + 5); | |
6749 | if (num <= 0 || num > 31) | |
6750 | return -1; | |
6751 | subtypes |= BIT(num); | |
6752 | #else /* CONFIG_HS20 */ | |
6753 | return -1; | |
6754 | #endif /* CONFIG_HS20 */ | |
8f479174 | 6755 | } else if (os_strncmp(pos, "mbo:", 4) == 0) { |
6756 | #ifdef CONFIG_MBO | |
6757 | int num = atoi(pos + 4); | |
2316cb35 AS |
6758 | |
6759 | if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE) | |
8f479174 | 6760 | return -1; |
2316cb35 | 6761 | mbo_subtypes |= BIT(num); |
8f479174 | 6762 | #else /* CONFIG_MBO */ |
6763 | return -1; | |
6764 | #endif /* CONFIG_MBO */ | |
cf28c66b DS |
6765 | } else { |
6766 | id[num_id] = atoi(pos); | |
6767 | if (id[num_id]) | |
6768 | num_id++; | |
6769 | } | |
afc064fe JM |
6770 | pos = os_strchr(pos + 1, ','); |
6771 | if (pos == NULL) | |
6772 | break; | |
6773 | pos++; | |
6774 | } | |
6775 | ||
8ecf2231 | 6776 | if (num_id == 0 && !subtypes && !mbo_subtypes) |
afc064fe JM |
6777 | return -1; |
6778 | ||
8f479174 | 6779 | return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes, |
2316cb35 | 6780 | mbo_subtypes); |
afc064fe | 6781 | } |
b1f12296 JM |
6782 | |
6783 | ||
6784 | static int gas_request(struct wpa_supplicant *wpa_s, char *cmd) | |
6785 | { | |
6786 | u8 dst_addr[ETH_ALEN]; | |
6787 | struct wpabuf *advproto, *query = NULL; | |
6788 | int used, ret = -1; | |
6789 | char *pos, *end; | |
6790 | size_t len; | |
6791 | ||
6792 | used = hwaddr_aton2(cmd, dst_addr); | |
6793 | if (used < 0) | |
6794 | return -1; | |
6795 | ||
6796 | pos = cmd + used; | |
6797 | while (*pos == ' ') | |
6798 | pos++; | |
6799 | ||
6800 | /* Advertisement Protocol ID */ | |
6801 | end = os_strchr(pos, ' '); | |
6802 | if (end) | |
6803 | len = end - pos; | |
6804 | else | |
6805 | len = os_strlen(pos); | |
6806 | if (len & 0x01) | |
6807 | return -1; | |
6808 | len /= 2; | |
6809 | if (len == 0) | |
6810 | return -1; | |
6811 | advproto = wpabuf_alloc(len); | |
6812 | if (advproto == NULL) | |
6813 | return -1; | |
6814 | if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0) | |
6815 | goto fail; | |
6816 | ||
6817 | if (end) { | |
6818 | /* Optional Query Request */ | |
6819 | pos = end + 1; | |
6820 | while (*pos == ' ') | |
6821 | pos++; | |
6822 | ||
6823 | len = os_strlen(pos); | |
6824 | if (len) { | |
6825 | if (len & 0x01) | |
6826 | goto fail; | |
6827 | len /= 2; | |
6828 | if (len == 0) | |
6829 | goto fail; | |
6830 | query = wpabuf_alloc(len); | |
6831 | if (query == NULL) | |
6832 | goto fail; | |
6833 | if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0) | |
6834 | goto fail; | |
6835 | } | |
6836 | } | |
6837 | ||
6838 | ret = gas_send_request(wpa_s, dst_addr, advproto, query); | |
6839 | ||
6840 | fail: | |
6841 | wpabuf_free(advproto); | |
6842 | wpabuf_free(query); | |
6843 | ||
6844 | return ret; | |
6845 | } | |
6846 | ||
6847 | ||
6848 | static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf, | |
6849 | size_t buflen) | |
6850 | { | |
6851 | u8 addr[ETH_ALEN]; | |
6852 | int dialog_token; | |
6853 | int used; | |
6854 | char *pos; | |
6855 | size_t resp_len, start, requested_len; | |
b6a9590b JM |
6856 | struct wpabuf *resp; |
6857 | int ret; | |
b1f12296 JM |
6858 | |
6859 | used = hwaddr_aton2(cmd, addr); | |
6860 | if (used < 0) | |
6861 | return -1; | |
6862 | ||
6863 | pos = cmd + used; | |
6864 | while (*pos == ' ') | |
6865 | pos++; | |
6866 | dialog_token = atoi(pos); | |
6867 | ||
b6a9590b JM |
6868 | if (wpa_s->last_gas_resp && |
6869 | os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 && | |
6870 | dialog_token == wpa_s->last_gas_dialog_token) | |
6871 | resp = wpa_s->last_gas_resp; | |
6872 | else if (wpa_s->prev_gas_resp && | |
6873 | os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 && | |
6874 | dialog_token == wpa_s->prev_gas_dialog_token) | |
6875 | resp = wpa_s->prev_gas_resp; | |
6876 | else | |
b1f12296 JM |
6877 | return -1; |
6878 | ||
b6a9590b | 6879 | resp_len = wpabuf_len(resp); |
b1f12296 JM |
6880 | start = 0; |
6881 | requested_len = resp_len; | |
6882 | ||
6883 | pos = os_strchr(pos, ' '); | |
6884 | if (pos) { | |
6885 | start = atoi(pos); | |
6886 | if (start > resp_len) | |
6887 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); | |
6888 | pos = os_strchr(pos, ','); | |
6889 | if (pos == NULL) | |
6890 | return -1; | |
6891 | pos++; | |
6892 | requested_len = atoi(pos); | |
6893 | if (start + requested_len > resp_len) | |
6894 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); | |
6895 | } | |
6896 | ||
6897 | if (requested_len * 2 + 1 > buflen) | |
6898 | return os_snprintf(buf, buflen, "FAIL-Too long response"); | |
6899 | ||
b6a9590b JM |
6900 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start, |
6901 | requested_len); | |
6902 | ||
6903 | if (start + requested_len == resp_len) { | |
6904 | /* | |
6905 | * Free memory by dropping the response after it has been | |
6906 | * fetched. | |
6907 | */ | |
6908 | if (resp == wpa_s->prev_gas_resp) { | |
6909 | wpabuf_free(wpa_s->prev_gas_resp); | |
6910 | wpa_s->prev_gas_resp = NULL; | |
6911 | } else { | |
6912 | wpabuf_free(wpa_s->last_gas_resp); | |
6913 | wpa_s->last_gas_resp = NULL; | |
6914 | } | |
6915 | } | |
6916 | ||
6917 | return ret; | |
b1f12296 | 6918 | } |
afc064fe JM |
6919 | #endif /* CONFIG_INTERWORKING */ |
6920 | ||
6921 | ||
a8918e86 JK |
6922 | #ifdef CONFIG_HS20 |
6923 | ||
6924 | static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst) | |
6925 | { | |
6926 | u8 dst_addr[ETH_ALEN]; | |
6927 | int used; | |
6928 | char *pos; | |
6929 | u32 subtypes = 0; | |
6930 | ||
6931 | used = hwaddr_aton2(dst, dst_addr); | |
6932 | if (used < 0) | |
6933 | return -1; | |
6934 | pos = dst + used; | |
b68d602d JM |
6935 | if (*pos == ' ') |
6936 | pos++; | |
a8918e86 JK |
6937 | for (;;) { |
6938 | int num = atoi(pos); | |
6939 | if (num <= 0 || num > 31) | |
6940 | return -1; | |
6941 | subtypes |= BIT(num); | |
6942 | pos = os_strchr(pos + 1, ','); | |
6943 | if (pos == NULL) | |
6944 | break; | |
6945 | pos++; | |
6946 | } | |
6947 | ||
6948 | if (subtypes == 0) | |
6949 | return -1; | |
6950 | ||
8dd5c1b4 | 6951 | return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0); |
a8918e86 JK |
6952 | } |
6953 | ||
6954 | ||
6955 | static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s, | |
6956 | const u8 *addr, const char *realm) | |
6957 | { | |
6958 | u8 *buf; | |
6959 | size_t rlen, len; | |
6960 | int ret; | |
6961 | ||
6962 | rlen = os_strlen(realm); | |
6963 | len = 3 + rlen; | |
6964 | buf = os_malloc(len); | |
6965 | if (buf == NULL) | |
6966 | return -1; | |
6967 | buf[0] = 1; /* NAI Home Realm Count */ | |
6968 | buf[1] = 0; /* Formatted in accordance with RFC 4282 */ | |
6969 | buf[2] = rlen; | |
6970 | os_memcpy(buf + 3, realm, rlen); | |
6971 | ||
6972 | ret = hs20_anqp_send_req(wpa_s, addr, | |
6973 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | |
8dd5c1b4 | 6974 | buf, len, 0); |
a8918e86 JK |
6975 | |
6976 | os_free(buf); | |
6977 | ||
6978 | return ret; | |
6979 | } | |
6980 | ||
6981 | ||
6982 | static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s, | |
6983 | char *dst) | |
6984 | { | |
6985 | struct wpa_cred *cred = wpa_s->conf->cred; | |
6986 | u8 dst_addr[ETH_ALEN]; | |
6987 | int used; | |
6988 | u8 *buf; | |
6989 | size_t len; | |
6990 | int ret; | |
6991 | ||
6992 | used = hwaddr_aton2(dst, dst_addr); | |
6993 | if (used < 0) | |
6994 | return -1; | |
6995 | ||
6996 | while (dst[used] == ' ') | |
6997 | used++; | |
6998 | if (os_strncmp(dst + used, "realm=", 6) == 0) | |
6999 | return hs20_nai_home_realm_list(wpa_s, dst_addr, | |
7000 | dst + used + 6); | |
7001 | ||
7002 | len = os_strlen(dst + used); | |
7003 | ||
7004 | if (len == 0 && cred && cred->realm) | |
7005 | return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm); | |
7006 | ||
0e87e798 | 7007 | if (len & 1) |
a8918e86 JK |
7008 | return -1; |
7009 | len /= 2; | |
7010 | buf = os_malloc(len); | |
7011 | if (buf == NULL) | |
7012 | return -1; | |
7013 | if (hexstr2bin(dst + used, buf, len) < 0) { | |
7014 | os_free(buf); | |
7015 | return -1; | |
7016 | } | |
7017 | ||
7018 | ret = hs20_anqp_send_req(wpa_s, dst_addr, | |
7019 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | |
8dd5c1b4 | 7020 | buf, len, 0); |
a8918e86 JK |
7021 | os_free(buf); |
7022 | ||
7023 | return ret; | |
7024 | } | |
7025 | ||
184e110c | 7026 | |
8dd5c1b4 JN |
7027 | static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply, |
7028 | int buflen) | |
7029 | { | |
7030 | u8 dst_addr[ETH_ALEN]; | |
7031 | int used; | |
7032 | char *ctx = NULL, *icon, *poffset, *psize; | |
7033 | ||
7034 | used = hwaddr_aton2(cmd, dst_addr); | |
7035 | if (used < 0) | |
7036 | return -1; | |
7037 | cmd += used; | |
7038 | ||
7039 | icon = str_token(cmd, " ", &ctx); | |
7040 | poffset = str_token(cmd, " ", &ctx); | |
7041 | psize = str_token(cmd, " ", &ctx); | |
7042 | if (!icon || !poffset || !psize) | |
7043 | return -1; | |
7044 | ||
7045 | wpa_s->fetch_osu_icon_in_progress = 0; | |
7046 | return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize), | |
7047 | reply, buflen); | |
7048 | } | |
7049 | ||
7050 | ||
7051 | static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd) | |
7052 | { | |
7053 | u8 dst_addr[ETH_ALEN]; | |
7054 | int used; | |
7055 | char *icon; | |
7056 | ||
7057 | if (!cmd[0]) | |
7058 | return hs20_del_icon(wpa_s, NULL, NULL); | |
7059 | ||
7060 | used = hwaddr_aton2(cmd, dst_addr); | |
7061 | if (used < 0) | |
7062 | return -1; | |
7063 | ||
7064 | while (cmd[used] == ' ') | |
7065 | used++; | |
7066 | icon = cmd[used] ? &cmd[used] : NULL; | |
7067 | ||
7068 | return hs20_del_icon(wpa_s, dst_addr, icon); | |
7069 | } | |
7070 | ||
7071 | ||
7072 | static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem) | |
184e110c JM |
7073 | { |
7074 | u8 dst_addr[ETH_ALEN]; | |
7075 | int used; | |
7076 | char *icon; | |
7077 | ||
7078 | used = hwaddr_aton2(cmd, dst_addr); | |
7079 | if (used < 0) | |
7080 | return -1; | |
7081 | ||
7082 | while (cmd[used] == ' ') | |
7083 | used++; | |
7084 | icon = &cmd[used]; | |
7085 | ||
b572df86 | 7086 | wpa_s->fetch_osu_icon_in_progress = 0; |
184e110c | 7087 | return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST), |
8dd5c1b4 | 7088 | (u8 *) icon, os_strlen(icon), inmem); |
184e110c JM |
7089 | } |
7090 | ||
a8918e86 JK |
7091 | #endif /* CONFIG_HS20 */ |
7092 | ||
7093 | ||
bc5d330a TB |
7094 | #ifdef CONFIG_AUTOSCAN |
7095 | ||
7096 | static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s, | |
7097 | char *cmd) | |
7098 | { | |
7099 | enum wpa_states state = wpa_s->wpa_state; | |
7100 | char *new_params = NULL; | |
7101 | ||
7102 | if (os_strlen(cmd) > 0) { | |
7103 | new_params = os_strdup(cmd); | |
7104 | if (new_params == NULL) | |
7105 | return -1; | |
7106 | } | |
7107 | ||
7108 | os_free(wpa_s->conf->autoscan); | |
7109 | wpa_s->conf->autoscan = new_params; | |
7110 | ||
7111 | if (wpa_s->conf->autoscan == NULL) | |
7112 | autoscan_deinit(wpa_s); | |
7113 | else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) | |
99218999 | 7114 | autoscan_init(wpa_s, 1); |
99f00324 JM |
7115 | else if (state == WPA_SCANNING) |
7116 | wpa_supplicant_reinit_autoscan(wpa_s); | |
9d3f4a74 JM |
7117 | else |
7118 | wpa_printf(MSG_DEBUG, "No autoscan update in state %s", | |
7119 | wpa_supplicant_state_txt(state)); | |
bc5d330a TB |
7120 | |
7121 | return 0; | |
7122 | } | |
7123 | ||
7124 | #endif /* CONFIG_AUTOSCAN */ | |
7125 | ||
7126 | ||
e9199e31 JM |
7127 | #ifdef CONFIG_WNM |
7128 | ||
7129 | static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd) | |
7130 | { | |
7131 | int enter; | |
7132 | int intval = 0; | |
7133 | char *pos; | |
cd0ef657 JM |
7134 | int ret; |
7135 | struct wpabuf *tfs_req = NULL; | |
e9199e31 JM |
7136 | |
7137 | if (os_strncmp(cmd, "enter", 5) == 0) | |
7138 | enter = 1; | |
7139 | else if (os_strncmp(cmd, "exit", 4) == 0) | |
7140 | enter = 0; | |
7141 | else | |
7142 | return -1; | |
7143 | ||
7144 | pos = os_strstr(cmd, " interval="); | |
7145 | if (pos) | |
7146 | intval = atoi(pos + 10); | |
7147 | ||
cd0ef657 JM |
7148 | pos = os_strstr(cmd, " tfs_req="); |
7149 | if (pos) { | |
7150 | char *end; | |
7151 | size_t len; | |
7152 | pos += 9; | |
7153 | end = os_strchr(pos, ' '); | |
7154 | if (end) | |
7155 | len = end - pos; | |
7156 | else | |
7157 | len = os_strlen(pos); | |
7158 | if (len & 1) | |
7159 | return -1; | |
7160 | len /= 2; | |
7161 | tfs_req = wpabuf_alloc(len); | |
7162 | if (tfs_req == NULL) | |
7163 | return -1; | |
7164 | if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) { | |
7165 | wpabuf_free(tfs_req); | |
7166 | return -1; | |
7167 | } | |
7168 | } | |
7169 | ||
df80a0cc JM |
7170 | ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER : |
7171 | WNM_SLEEP_MODE_EXIT, intval, | |
cd0ef657 JM |
7172 | tfs_req); |
7173 | wpabuf_free(tfs_req); | |
7174 | ||
7175 | return ret; | |
e9199e31 JM |
7176 | } |
7177 | ||
65bcd0a9 VK |
7178 | |
7179 | static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd) | |
7180 | { | |
9a493fab | 7181 | int query_reason, list = 0; |
15ab61ed | 7182 | char *btm_candidates = NULL; |
65bcd0a9 VK |
7183 | |
7184 | query_reason = atoi(cmd); | |
7185 | ||
9a493fab AS |
7186 | cmd = os_strchr(cmd, ' '); |
7187 | if (cmd) { | |
15ab61ed | 7188 | if (os_strncmp(cmd, " list", 5) == 0) |
9a493fab | 7189 | list = 1; |
15ab61ed AS |
7190 | else |
7191 | btm_candidates = cmd; | |
9a493fab AS |
7192 | } |
7193 | ||
7194 | wpa_printf(MSG_DEBUG, | |
7195 | "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s", | |
7196 | query_reason, list ? " candidate list" : ""); | |
65bcd0a9 | 7197 | |
15ab61ed AS |
7198 | return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason, |
7199 | btm_candidates, | |
7200 | list); | |
65bcd0a9 VK |
7201 | } |
7202 | ||
e9199e31 JM |
7203 | #endif /* CONFIG_WNM */ |
7204 | ||
7205 | ||
60b24b0d DS |
7206 | static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, |
7207 | size_t buflen) | |
7208 | { | |
7209 | struct wpa_signal_info si; | |
7210 | int ret; | |
2cc8d8f4 | 7211 | char *pos, *end; |
60b24b0d DS |
7212 | |
7213 | ret = wpa_drv_signal_poll(wpa_s, &si); | |
7214 | if (ret) | |
7215 | return -1; | |
7216 | ||
2cc8d8f4 AO |
7217 | pos = buf; |
7218 | end = buf + buflen; | |
7219 | ||
7220 | ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n" | |
60b24b0d DS |
7221 | "NOISE=%d\nFREQUENCY=%u\n", |
7222 | si.current_signal, si.current_txrate / 1000, | |
7223 | si.current_noise, si.frequency); | |
7bdd8981 | 7224 | if (os_snprintf_error(end - pos, ret)) |
60b24b0d | 7225 | return -1; |
2cc8d8f4 AO |
7226 | pos += ret; |
7227 | ||
7228 | if (si.chanwidth != CHAN_WIDTH_UNKNOWN) { | |
7229 | ret = os_snprintf(pos, end - pos, "WIDTH=%s\n", | |
7a4a93b9 | 7230 | channel_width_to_string(si.chanwidth)); |
7bdd8981 | 7231 | if (os_snprintf_error(end - pos, ret)) |
2cc8d8f4 AO |
7232 | return -1; |
7233 | pos += ret; | |
7234 | } | |
7235 | ||
7236 | if (si.center_frq1 > 0 && si.center_frq2 > 0) { | |
7237 | ret = os_snprintf(pos, end - pos, | |
7238 | "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n", | |
7239 | si.center_frq1, si.center_frq2); | |
7bdd8981 | 7240 | if (os_snprintf_error(end - pos, ret)) |
2cc8d8f4 AO |
7241 | return -1; |
7242 | pos += ret; | |
7243 | } | |
7244 | ||
95783298 AO |
7245 | if (si.avg_signal) { |
7246 | ret = os_snprintf(pos, end - pos, | |
7247 | "AVG_RSSI=%d\n", si.avg_signal); | |
d85e1fc8 | 7248 | if (os_snprintf_error(end - pos, ret)) |
95783298 AO |
7249 | return -1; |
7250 | pos += ret; | |
7251 | } | |
7252 | ||
74fa78b2 JM |
7253 | if (si.avg_beacon_signal) { |
7254 | ret = os_snprintf(pos, end - pos, | |
7255 | "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal); | |
7256 | if (os_snprintf_error(end - pos, ret)) | |
7257 | return -1; | |
7258 | pos += ret; | |
7259 | } | |
7260 | ||
2cc8d8f4 | 7261 | return pos - buf; |
60b24b0d DS |
7262 | } |
7263 | ||
7264 | ||
96e8d831 DS |
7265 | static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s, |
7266 | const char *cmd) | |
7267 | { | |
7268 | const char *pos; | |
7269 | int threshold = 0; | |
7270 | int hysteresis = 0; | |
7271 | ||
7272 | if (wpa_s->bgscan && wpa_s->bgscan_priv) { | |
7273 | wpa_printf(MSG_DEBUG, | |
7274 | "Reject SIGNAL_MONITOR command - bgscan is active"); | |
7275 | return -1; | |
7276 | } | |
7277 | pos = os_strstr(cmd, "THRESHOLD="); | |
7278 | if (pos) | |
7279 | threshold = atoi(pos + 10); | |
7280 | pos = os_strstr(cmd, "HYSTERESIS="); | |
7281 | if (pos) | |
7282 | hysteresis = atoi(pos + 11); | |
7283 | return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis); | |
7284 | } | |
7285 | ||
7286 | ||
c06fca04 JM |
7287 | #ifdef CONFIG_TESTING_OPTIONS |
7288 | int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s, | |
7289 | enum wpa_driver_if_type if_type, | |
7290 | unsigned int *num, | |
7291 | unsigned int *freq_list) | |
7292 | { | |
7293 | char *pos = wpa_s->get_pref_freq_list_override; | |
7294 | char *end; | |
7295 | unsigned int count = 0; | |
7296 | ||
7297 | /* Override string format: | |
7298 | * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */ | |
7299 | ||
7300 | while (pos) { | |
7301 | if (atoi(pos) == (int) if_type) | |
7302 | break; | |
7303 | pos = os_strchr(pos, ' '); | |
7304 | if (pos) | |
7305 | pos++; | |
7306 | } | |
7307 | if (!pos) | |
7308 | return -1; | |
7309 | pos = os_strchr(pos, ':'); | |
7310 | if (!pos) | |
7311 | return -1; | |
7312 | pos++; | |
7313 | end = os_strchr(pos, ' '); | |
7314 | while (pos && (!end || pos < end) && count < *num) { | |
7315 | freq_list[count++] = atoi(pos); | |
7316 | pos = os_strchr(pos, ','); | |
7317 | if (pos) | |
7318 | pos++; | |
7319 | } | |
7320 | ||
7321 | *num = count; | |
7322 | return 0; | |
7323 | } | |
7324 | #endif /* CONFIG_TESTING_OPTIONS */ | |
7325 | ||
7326 | ||
98342208 AK |
7327 | static int wpas_ctrl_iface_get_pref_freq_list( |
7328 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | |
7329 | { | |
7330 | unsigned int freq_list[100], num = 100, i; | |
7331 | int ret; | |
7332 | enum wpa_driver_if_type iface_type; | |
7333 | char *pos, *end; | |
7334 | ||
7335 | pos = buf; | |
7336 | end = buf + buflen; | |
7337 | ||
7338 | /* buf: "<interface_type>" */ | |
7339 | if (os_strcmp(cmd, "STATION") == 0) | |
7340 | iface_type = WPA_IF_STATION; | |
7341 | else if (os_strcmp(cmd, "AP") == 0) | |
7342 | iface_type = WPA_IF_AP_BSS; | |
7343 | else if (os_strcmp(cmd, "P2P_GO") == 0) | |
7344 | iface_type = WPA_IF_P2P_GO; | |
7345 | else if (os_strcmp(cmd, "P2P_CLIENT") == 0) | |
7346 | iface_type = WPA_IF_P2P_CLIENT; | |
7347 | else if (os_strcmp(cmd, "IBSS") == 0) | |
7348 | iface_type = WPA_IF_IBSS; | |
7349 | else if (os_strcmp(cmd, "TDLS") == 0) | |
7350 | iface_type = WPA_IF_TDLS; | |
7351 | else | |
7352 | return -1; | |
7353 | ||
7354 | wpa_printf(MSG_DEBUG, | |
7355 | "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)", | |
7356 | iface_type, buf); | |
7357 | ||
7358 | ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list); | |
7359 | if (ret) | |
7360 | return -1; | |
7361 | ||
7362 | for (i = 0; i < num; i++) { | |
7363 | ret = os_snprintf(pos, end - pos, "%s%u", | |
7364 | i > 0 ? "," : "", freq_list[i]); | |
7365 | if (os_snprintf_error(end - pos, ret)) | |
7366 | return -1; | |
7367 | pos += ret; | |
7368 | } | |
7369 | ||
7370 | return pos - buf; | |
7371 | } | |
7372 | ||
7373 | ||
4d7aab78 EL |
7374 | static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s, |
7375 | char *buf, size_t buflen) | |
7376 | { | |
7377 | int ret, i; | |
7378 | char *pos, *end; | |
7379 | ||
7380 | ret = os_snprintf(buf, buflen, "%016llX:\n", | |
7381 | (long long unsigned) wpa_s->drv_flags); | |
7382 | if (os_snprintf_error(buflen, ret)) | |
7383 | return -1; | |
7384 | ||
7385 | pos = buf + ret; | |
7386 | end = buf + buflen; | |
7387 | ||
7388 | for (i = 0; i < 64; i++) { | |
7389 | if (wpa_s->drv_flags & (1LLU << i)) { | |
7390 | ret = os_snprintf(pos, end - pos, "%s\n", | |
7391 | driver_flag_to_string(1LLU << i)); | |
7392 | if (os_snprintf_error(end - pos, ret)) | |
7393 | return -1; | |
7394 | pos += ret; | |
7395 | } | |
7396 | } | |
7397 | ||
7398 | return pos - buf; | |
7399 | } | |
7400 | ||
7401 | ||
dc7785f8 YZ |
7402 | static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf, |
7403 | size_t buflen) | |
7404 | { | |
7405 | struct hostap_sta_driver_data sta; | |
7406 | int ret; | |
7407 | ||
7408 | ret = wpa_drv_pktcnt_poll(wpa_s, &sta); | |
7409 | if (ret) | |
7410 | return -1; | |
7411 | ||
7412 | ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n", | |
7413 | sta.tx_packets, sta.tx_retry_failed, sta.rx_packets); | |
7bdd8981 | 7414 | if (os_snprintf_error(buflen, ret)) |
dc7785f8 YZ |
7415 | return -1; |
7416 | return ret; | |
7417 | } | |
7418 | ||
7419 | ||
5e2c3490 JM |
7420 | #ifdef ANDROID |
7421 | static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd, | |
7422 | char *buf, size_t buflen) | |
7423 | { | |
7424 | int ret; | |
7425 | ||
7426 | ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen); | |
a94737ea DS |
7427 | if (ret == 0) { |
7428 | if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) { | |
7429 | struct p2p_data *p2p = wpa_s->global->p2p; | |
7430 | if (p2p) { | |
7431 | char country[3]; | |
7432 | country[0] = cmd[8]; | |
7433 | country[1] = cmd[9]; | |
7434 | country[2] = 0x04; | |
7435 | p2p_set_country(p2p, country); | |
7436 | } | |
7437 | } | |
5e2c3490 | 7438 | ret = os_snprintf(buf, buflen, "%s\n", "OK"); |
aaadd727 JM |
7439 | if (os_snprintf_error(buflen, ret)) |
7440 | ret = -1; | |
a94737ea | 7441 | } |
5e2c3490 JM |
7442 | return ret; |
7443 | } | |
7444 | #endif /* ANDROID */ | |
7445 | ||
7446 | ||
adef8948 BL |
7447 | static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd, |
7448 | char *buf, size_t buflen) | |
7449 | { | |
7450 | int ret; | |
7451 | char *pos; | |
7452 | u8 *data = NULL; | |
7453 | unsigned int vendor_id, subcmd; | |
7454 | struct wpabuf *reply; | |
7455 | size_t data_len = 0; | |
7456 | ||
7457 | /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */ | |
7458 | vendor_id = strtoul(cmd, &pos, 16); | |
640b0b93 | 7459 | if (!isblank((unsigned char) *pos)) |
adef8948 BL |
7460 | return -EINVAL; |
7461 | ||
7462 | subcmd = strtoul(pos, &pos, 10); | |
7463 | ||
7464 | if (*pos != '\0') { | |
640b0b93 | 7465 | if (!isblank((unsigned char) *pos++)) |
adef8948 BL |
7466 | return -EINVAL; |
7467 | data_len = os_strlen(pos); | |
7468 | } | |
7469 | ||
7470 | if (data_len) { | |
7471 | data_len /= 2; | |
7472 | data = os_malloc(data_len); | |
7473 | if (!data) | |
2cebdee6 | 7474 | return -1; |
adef8948 BL |
7475 | |
7476 | if (hexstr2bin(pos, data, data_len)) { | |
7477 | wpa_printf(MSG_DEBUG, | |
7478 | "Vendor command: wrong parameter format"); | |
7479 | os_free(data); | |
7480 | return -EINVAL; | |
7481 | } | |
7482 | } | |
7483 | ||
7484 | reply = wpabuf_alloc((buflen - 1) / 2); | |
7485 | if (!reply) { | |
7486 | os_free(data); | |
2cebdee6 | 7487 | return -1; |
adef8948 BL |
7488 | } |
7489 | ||
7490 | ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len, | |
7491 | reply); | |
7492 | ||
7493 | if (ret == 0) | |
7494 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply), | |
7495 | wpabuf_len(reply)); | |
7496 | ||
7497 | wpabuf_free(reply); | |
7498 | os_free(data); | |
7499 | ||
7500 | return ret; | |
7501 | } | |
7502 | ||
7503 | ||
acb54643 JM |
7504 | static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s) |
7505 | { | |
7e608d1d IP |
7506 | #ifdef CONFIG_P2P |
7507 | struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ? | |
7508 | wpa_s->global->p2p_init_wpa_s : wpa_s; | |
7509 | #endif /* CONFIG_P2P */ | |
7510 | ||
acb54643 JM |
7511 | wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state"); |
7512 | ||
6e374bd4 JM |
7513 | if (wpas_abort_ongoing_scan(wpa_s) == 0) |
7514 | wpa_s->ignore_post_flush_scan_res = 1; | |
53401e91 | 7515 | |
e9ccfc38 JM |
7516 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
7517 | /* | |
7518 | * Avoid possible auto connect re-connection on getting | |
7519 | * disconnected due to state flush. | |
7520 | */ | |
7521 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
7522 | } | |
7523 | ||
acb54643 | 7524 | #ifdef CONFIG_P2P |
1d20c66e | 7525 | wpas_p2p_group_remove(p2p_wpa_s, "*"); |
7e608d1d IP |
7526 | wpas_p2p_cancel(p2p_wpa_s); |
7527 | p2p_ctrl_flush(p2p_wpa_s); | |
7e608d1d IP |
7528 | wpas_p2p_service_flush(p2p_wpa_s); |
7529 | p2p_wpa_s->global->p2p_disabled = 0; | |
7530 | p2p_wpa_s->global->p2p_per_sta_psk = 0; | |
7531 | p2p_wpa_s->conf->num_sec_device_types = 0; | |
7532 | p2p_wpa_s->p2p_disable_ip_addr_req = 0; | |
7533 | os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range); | |
7534 | p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL; | |
85e152b6 | 7535 | p2p_wpa_s->global->p2p_go_avoid_freq.num = 0; |
9a58e521 | 7536 | p2p_wpa_s->global->pending_p2ps_group = 0; |
8bb8e6ed | 7537 | p2p_wpa_s->global->pending_p2ps_group_freq = 0; |
acb54643 JM |
7538 | #endif /* CONFIG_P2P */ |
7539 | ||
7540 | #ifdef CONFIG_WPS_TESTING | |
7541 | wps_version_number = 0x20; | |
7542 | wps_testing_dummy_cred = 0; | |
91226e0d | 7543 | wps_corrupt_pkhash = 0; |
6e379c6c JM |
7544 | wps_force_auth_types_in_use = 0; |
7545 | wps_force_encr_types_in_use = 0; | |
acb54643 JM |
7546 | #endif /* CONFIG_WPS_TESTING */ |
7547 | #ifdef CONFIG_WPS | |
7b02375a | 7548 | wpa_s->wps_fragment_size = 0; |
acb54643 | 7549 | wpas_wps_cancel(wpa_s); |
422ba11e | 7550 | wps_registrar_flush(wpa_s->wps->registrar); |
acb54643 | 7551 | #endif /* CONFIG_WPS */ |
7255983b | 7552 | wpa_s->after_wps = 0; |
4d9fb08d | 7553 | wpa_s->known_wps_freq = 0; |
acb54643 | 7554 | |
9d2cb3ec | 7555 | #ifdef CONFIG_TDLS |
acb54643 | 7556 | #ifdef CONFIG_TDLS_TESTING |
acb54643 JM |
7557 | tdls_testing = 0; |
7558 | #endif /* CONFIG_TDLS_TESTING */ | |
acb54643 JM |
7559 | wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL); |
7560 | wpa_tdls_enable(wpa_s->wpa, 1); | |
7561 | #endif /* CONFIG_TDLS */ | |
7562 | ||
e78aaca0 JM |
7563 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL); |
7564 | wpa_supplicant_stop_countermeasures(wpa_s, NULL); | |
7565 | ||
acb54643 | 7566 | wpa_s->no_keep_alive = 0; |
c2805909 | 7567 | wpa_s->own_disconnect_req = 0; |
acb54643 JM |
7568 | |
7569 | os_free(wpa_s->disallow_aps_bssid); | |
7570 | wpa_s->disallow_aps_bssid = NULL; | |
7571 | wpa_s->disallow_aps_bssid_count = 0; | |
7572 | os_free(wpa_s->disallow_aps_ssid); | |
7573 | wpa_s->disallow_aps_ssid = NULL; | |
7574 | wpa_s->disallow_aps_ssid_count = 0; | |
7575 | ||
7576 | wpa_s->set_sta_uapsd = 0; | |
7577 | wpa_s->sta_uapsd = 0; | |
7578 | ||
7579 | wpa_drv_radio_disable(wpa_s, 0); | |
acb54643 | 7580 | wpa_blacklist_clear(wpa_s); |
a8a7890d | 7581 | wpa_s->extra_blacklist_count = 0; |
acb54643 JM |
7582 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all"); |
7583 | wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all"); | |
d9bb2821 | 7584 | wpa_config_flush_blobs(wpa_s->conf); |
ea6e040c JM |
7585 | wpa_s->conf->auto_interworking = 0; |
7586 | wpa_s->conf->okc = 0; | |
04f7ecc6 | 7587 | |
b925506a JM |
7588 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
7589 | rsn_preauth_deinit(wpa_s->wpa); | |
7590 | ||
04f7ecc6 JM |
7591 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200); |
7592 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70); | |
7593 | wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60); | |
0d79b50a | 7594 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); |
b1ae396f | 7595 | |
b3253ebb | 7596 | radio_remove_works(wpa_s, NULL, 1); |
e3745228 | 7597 | wpa_s->ext_work_in_progress = 0; |
3d910ef4 JM |
7598 | |
7599 | wpa_s->next_ssid = NULL; | |
b572df86 JM |
7600 | |
7601 | #ifdef CONFIG_INTERWORKING | |
876e74aa | 7602 | #ifdef CONFIG_HS20 |
b572df86 | 7603 | hs20_cancel_fetch_osu(wpa_s); |
8dd5c1b4 | 7604 | hs20_del_icon(wpa_s, NULL, NULL); |
876e74aa | 7605 | #endif /* CONFIG_HS20 */ |
b572df86 | 7606 | #endif /* CONFIG_INTERWORKING */ |
60b893df JM |
7607 | |
7608 | wpa_s->ext_mgmt_frame_handling = 0; | |
9d4ff04a | 7609 | wpa_s->ext_eapol_frame_io = 0; |
1f94e4ee JM |
7610 | #ifdef CONFIG_TESTING_OPTIONS |
7611 | wpa_s->extra_roc_dur = 0; | |
911942ee | 7612 | wpa_s->test_failure = WPAS_TEST_FAILURE_NONE; |
ed7820b4 | 7613 | wpa_s->p2p_go_csa_on_inv = 0; |
02adead5 | 7614 | wpa_s->ignore_auth_resp = 0; |
6ad37d73 | 7615 | wpa_s->ignore_assoc_disallow = 0; |
a483c6f1 | 7616 | wpa_s->reject_btm_req_reason = 0; |
651c6a84 | 7617 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL); |
c06fca04 JM |
7618 | os_free(wpa_s->get_pref_freq_list_override); |
7619 | wpa_s->get_pref_freq_list_override = NULL; | |
1f94e4ee | 7620 | #endif /* CONFIG_TESTING_OPTIONS */ |
97cfe110 JM |
7621 | |
7622 | wpa_s->disconnected = 0; | |
b8db1dfc JM |
7623 | os_free(wpa_s->next_scan_freqs); |
7624 | wpa_s->next_scan_freqs = NULL; | |
88a44755 JM |
7625 | os_free(wpa_s->select_network_scan_freqs); |
7626 | wpa_s->select_network_scan_freqs = NULL; | |
6c699913 JM |
7627 | |
7628 | wpa_bss_flush(wpa_s); | |
7629 | if (!dl_list_empty(&wpa_s->bss)) { | |
7630 | wpa_printf(MSG_DEBUG, | |
7631 | "BSS table not empty after flush: %u entries, current_bss=%p bssid=" | |
7632 | MACSTR " pending_bssid=" MACSTR, | |
7633 | dl_list_len(&wpa_s->bss), wpa_s->current_bss, | |
7634 | MAC2STR(wpa_s->bssid), | |
7635 | MAC2STR(wpa_s->pending_bssid)); | |
7636 | } | |
9bd566a3 AS |
7637 | |
7638 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); | |
03ed0a52 | 7639 | wpa_s->wnmsleep_used = 0; |
ab6ab07a JM |
7640 | |
7641 | #ifdef CONFIG_SME | |
7642 | wpa_s->sme.last_unprot_disconnect.sec = 0; | |
7643 | #endif /* CONFIG_SME */ | |
c6c41f6e JM |
7644 | |
7645 | wpabuf_free(wpa_s->ric_ies); | |
7646 | wpa_s->ric_ies = NULL; | |
acb54643 JM |
7647 | } |
7648 | ||
7649 | ||
1f965e62 JM |
7650 | static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s, |
7651 | char *buf, size_t buflen) | |
7652 | { | |
7653 | struct wpa_radio_work *work; | |
7654 | char *pos, *end; | |
7655 | struct os_reltime now, diff; | |
7656 | ||
7657 | pos = buf; | |
7658 | end = buf + buflen; | |
7659 | ||
7660 | os_get_reltime(&now); | |
7661 | ||
7662 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) | |
7663 | { | |
7664 | int ret; | |
7665 | ||
7666 | os_reltime_sub(&now, &work->time, &diff); | |
7667 | ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n", | |
7668 | work->type, work->wpa_s->ifname, work->freq, | |
7669 | work->started, diff.sec, diff.usec); | |
d85e1fc8 | 7670 | if (os_snprintf_error(end - pos, ret)) |
1f965e62 JM |
7671 | break; |
7672 | pos += ret; | |
7673 | } | |
7674 | ||
7675 | return pos - buf; | |
7676 | } | |
7677 | ||
7678 | ||
7679 | static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx) | |
7680 | { | |
7681 | struct wpa_radio_work *work = eloop_ctx; | |
7682 | struct wpa_external_work *ework = work->ctx; | |
7683 | ||
7684 | wpa_dbg(work->wpa_s, MSG_DEBUG, | |
7685 | "Timing out external radio work %u (%s)", | |
7686 | ework->id, work->type); | |
7687 | wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id); | |
e3745228 | 7688 | work->wpa_s->ext_work_in_progress = 0; |
1f965e62 | 7689 | radio_work_done(work); |
df48efc5 | 7690 | os_free(ework); |
1f965e62 JM |
7691 | } |
7692 | ||
7693 | ||
7694 | static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit) | |
7695 | { | |
7696 | struct wpa_external_work *ework = work->ctx; | |
7697 | ||
7698 | if (deinit) { | |
b3253ebb AO |
7699 | if (work->started) |
7700 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, | |
7701 | work, NULL); | |
7702 | ||
7d1007a6 JM |
7703 | /* |
7704 | * work->type points to a buffer in ework, so need to replace | |
7705 | * that here with a fixed string to avoid use of freed memory | |
7706 | * in debug prints. | |
7707 | */ | |
7708 | work->type = "freed-ext-work"; | |
7709 | work->ctx = NULL; | |
1f965e62 JM |
7710 | os_free(ework); |
7711 | return; | |
7712 | } | |
7713 | ||
7714 | wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)", | |
7715 | ework->id, ework->type); | |
7716 | wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id); | |
e3745228 | 7717 | work->wpa_s->ext_work_in_progress = 1; |
1f965e62 JM |
7718 | if (!ework->timeout) |
7719 | ework->timeout = 10; | |
7720 | eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout, | |
7721 | work, NULL); | |
7722 | } | |
7723 | ||
7724 | ||
7725 | static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd, | |
7726 | char *buf, size_t buflen) | |
7727 | { | |
7728 | struct wpa_external_work *ework; | |
7729 | char *pos, *pos2; | |
7730 | size_t type_len; | |
7731 | int ret; | |
7732 | unsigned int freq = 0; | |
7733 | ||
7734 | /* format: <name> [freq=<MHz>] [timeout=<seconds>] */ | |
7735 | ||
7736 | ework = os_zalloc(sizeof(*ework)); | |
7737 | if (ework == NULL) | |
7738 | return -1; | |
7739 | ||
7740 | pos = os_strchr(cmd, ' '); | |
7741 | if (pos) { | |
7742 | type_len = pos - cmd; | |
7743 | pos++; | |
7744 | ||
7745 | pos2 = os_strstr(pos, "freq="); | |
7746 | if (pos2) | |
7747 | freq = atoi(pos2 + 5); | |
7748 | ||
7749 | pos2 = os_strstr(pos, "timeout="); | |
7750 | if (pos2) | |
7751 | ework->timeout = atoi(pos2 + 8); | |
7752 | } else { | |
7753 | type_len = os_strlen(cmd); | |
7754 | } | |
7755 | if (4 + type_len >= sizeof(ework->type)) | |
7756 | type_len = sizeof(ework->type) - 4 - 1; | |
7757 | os_strlcpy(ework->type, "ext:", sizeof(ework->type)); | |
7758 | os_memcpy(ework->type + 4, cmd, type_len); | |
7759 | ework->type[4 + type_len] = '\0'; | |
7760 | ||
7761 | wpa_s->ext_work_id++; | |
7762 | if (wpa_s->ext_work_id == 0) | |
7763 | wpa_s->ext_work_id++; | |
7764 | ework->id = wpa_s->ext_work_id; | |
7765 | ||
7766 | if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb, | |
7767 | ework) < 0) { | |
7768 | os_free(ework); | |
7769 | return -1; | |
7770 | } | |
7771 | ||
7772 | ret = os_snprintf(buf, buflen, "%u", ework->id); | |
d85e1fc8 | 7773 | if (os_snprintf_error(buflen, ret)) |
1f965e62 JM |
7774 | return -1; |
7775 | return ret; | |
7776 | } | |
7777 | ||
7778 | ||
7779 | static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd) | |
7780 | { | |
7781 | struct wpa_radio_work *work; | |
7782 | unsigned int id = atoi(cmd); | |
7783 | ||
7784 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) | |
7785 | { | |
7786 | struct wpa_external_work *ework; | |
7787 | ||
7788 | if (os_strncmp(work->type, "ext:", 4) != 0) | |
7789 | continue; | |
7790 | ework = work->ctx; | |
7791 | if (id && ework->id != id) | |
7792 | continue; | |
7793 | wpa_dbg(wpa_s, MSG_DEBUG, | |
7794 | "Completed external radio work %u (%s)", | |
7795 | ework->id, ework->type); | |
7796 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL); | |
e3745228 | 7797 | wpa_s->ext_work_in_progress = 0; |
1f965e62 | 7798 | radio_work_done(work); |
6829da39 | 7799 | os_free(ework); |
1f965e62 JM |
7800 | return 3; /* "OK\n" */ |
7801 | } | |
7802 | ||
7803 | return -1; | |
7804 | } | |
7805 | ||
7806 | ||
7807 | static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd, | |
7808 | char *buf, size_t buflen) | |
7809 | { | |
7810 | if (os_strcmp(cmd, "show") == 0) | |
7811 | return wpas_ctrl_radio_work_show(wpa_s, buf, buflen); | |
7812 | if (os_strncmp(cmd, "add ", 4) == 0) | |
7813 | return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen); | |
7814 | if (os_strncmp(cmd, "done ", 5) == 0) | |
7815 | return wpas_ctrl_radio_work_done(wpa_s, cmd + 4); | |
7816 | return -1; | |
7817 | } | |
7818 | ||
7819 | ||
7820 | void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s) | |
7821 | { | |
7822 | struct wpa_radio_work *work, *tmp; | |
7823 | ||
a6cff8bf MS |
7824 | if (!wpa_s || !wpa_s->radio) |
7825 | return; | |
7826 | ||
1f965e62 JM |
7827 | dl_list_for_each_safe(work, tmp, &wpa_s->radio->work, |
7828 | struct wpa_radio_work, list) { | |
7829 | struct wpa_external_work *ework; | |
7830 | ||
7831 | if (os_strncmp(work->type, "ext:", 4) != 0) | |
7832 | continue; | |
7833 | ework = work->ctx; | |
7834 | wpa_dbg(wpa_s, MSG_DEBUG, | |
023b466d | 7835 | "Flushing%s external radio work %u (%s)", |
1f965e62 JM |
7836 | work->started ? " started" : "", ework->id, |
7837 | ework->type); | |
7838 | if (work->started) | |
7839 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, | |
7840 | work, NULL); | |
1f965e62 | 7841 | radio_work_done(work); |
df48efc5 | 7842 | os_free(ework); |
1f965e62 JM |
7843 | } |
7844 | } | |
7845 | ||
7846 | ||
bceb8431 JM |
7847 | static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx) |
7848 | { | |
7849 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
7850 | eapol_sm_notify_ctrl_response(wpa_s->eapol); | |
7851 | } | |
7852 | ||
7853 | ||
43a66ecb JM |
7854 | static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value, |
7855 | unsigned int *scan_id_count, int scan_id[]) | |
6891f0e6 LJ |
7856 | { |
7857 | const char *pos = value; | |
7858 | ||
7859 | while (pos) { | |
7860 | if (*pos == ' ' || *pos == '\0') | |
7861 | break; | |
43a66ecb | 7862 | if (*scan_id_count == MAX_SCAN_ID) |
6891f0e6 | 7863 | return -1; |
43a66ecb | 7864 | scan_id[(*scan_id_count)++] = atoi(pos); |
6891f0e6 LJ |
7865 | pos = os_strchr(pos, ','); |
7866 | if (pos) | |
7867 | pos++; | |
7868 | } | |
7869 | ||
7870 | return 0; | |
7871 | } | |
7872 | ||
7873 | ||
fee52342 JM |
7874 | static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params, |
7875 | char *reply, int reply_size, int *reply_len) | |
7876 | { | |
7877 | char *pos; | |
43a66ecb JM |
7878 | unsigned int manual_scan_passive = 0; |
7879 | unsigned int manual_scan_use_id = 0; | |
7880 | unsigned int manual_scan_only_new = 0; | |
7881 | unsigned int scan_only = 0; | |
7882 | unsigned int scan_id_count = 0; | |
7883 | int scan_id[MAX_SCAN_ID]; | |
7884 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, | |
7885 | struct wpa_scan_results *scan_res); | |
7886 | int *manual_scan_freqs = NULL; | |
a80651d0 KV |
7887 | struct wpa_ssid_value *ssid = NULL, *ns; |
7888 | unsigned int ssid_count = 0; | |
fee52342 JM |
7889 | |
7890 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { | |
7891 | *reply_len = -1; | |
7892 | return; | |
7893 | } | |
7894 | ||
e69ae5ff JM |
7895 | if (radio_work_pending(wpa_s, "scan")) { |
7896 | wpa_printf(MSG_DEBUG, | |
7897 | "Pending scan scheduled - reject new request"); | |
7898 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | |
7899 | return; | |
7900 | } | |
7901 | ||
9772af66 NM |
7902 | #ifdef CONFIG_INTERWORKING |
7903 | if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) { | |
7904 | wpa_printf(MSG_DEBUG, | |
7905 | "Interworking select in progress - reject new scan"); | |
7906 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | |
7907 | return; | |
7908 | } | |
7909 | #endif /* CONFIG_INTERWORKING */ | |
7910 | ||
fee52342 JM |
7911 | if (params) { |
7912 | if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0) | |
43a66ecb | 7913 | scan_only = 1; |
fee52342 JM |
7914 | |
7915 | pos = os_strstr(params, "freq="); | |
43a66ecb JM |
7916 | if (pos) { |
7917 | manual_scan_freqs = freq_range_to_channel_list(wpa_s, | |
7918 | pos + 5); | |
7919 | if (manual_scan_freqs == NULL) { | |
7920 | *reply_len = -1; | |
7921 | goto done; | |
7922 | } | |
fee52342 | 7923 | } |
88c2d488 JM |
7924 | |
7925 | pos = os_strstr(params, "passive="); | |
7926 | if (pos) | |
43a66ecb | 7927 | manual_scan_passive = !!atoi(pos + 8); |
d81c73be JM |
7928 | |
7929 | pos = os_strstr(params, "use_id="); | |
7930 | if (pos) | |
43a66ecb | 7931 | manual_scan_use_id = atoi(pos + 7); |
949938aa JM |
7932 | |
7933 | pos = os_strstr(params, "only_new=1"); | |
7934 | if (pos) | |
43a66ecb | 7935 | manual_scan_only_new = 1; |
6891f0e6 LJ |
7936 | |
7937 | pos = os_strstr(params, "scan_id="); | |
43a66ecb JM |
7938 | if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count, |
7939 | scan_id) < 0) { | |
6891f0e6 | 7940 | *reply_len = -1; |
43a66ecb | 7941 | goto done; |
6891f0e6 | 7942 | } |
a80651d0 KV |
7943 | |
7944 | pos = params; | |
7945 | while (pos && *pos != '\0') { | |
7946 | if (os_strncmp(pos, "ssid ", 5) == 0) { | |
7947 | char *end; | |
7948 | ||
7949 | pos += 5; | |
7950 | end = pos; | |
7951 | while (*end) { | |
7952 | if (*end == '\0' || *end == ' ') | |
7953 | break; | |
7954 | end++; | |
7955 | } | |
7956 | ||
7957 | ns = os_realloc_array( | |
7958 | ssid, ssid_count + 1, | |
7959 | sizeof(struct wpa_ssid_value)); | |
7960 | if (ns == NULL) { | |
7961 | *reply_len = -1; | |
7962 | goto done; | |
7963 | } | |
7964 | ssid = ns; | |
7965 | ||
7966 | if ((end - pos) & 0x01 || | |
7967 | end - pos > 2 * SSID_MAX_LEN || | |
7968 | hexstr2bin(pos, ssid[ssid_count].ssid, | |
7969 | (end - pos) / 2) < 0) { | |
7970 | wpa_printf(MSG_DEBUG, | |
7971 | "Invalid SSID value '%s'", | |
7972 | pos); | |
7973 | *reply_len = -1; | |
7974 | goto done; | |
7975 | } | |
7976 | ssid[ssid_count].ssid_len = (end - pos) / 2; | |
7977 | wpa_hexdump_ascii(MSG_DEBUG, "scan SSID", | |
7978 | ssid[ssid_count].ssid, | |
7979 | ssid[ssid_count].ssid_len); | |
7980 | ssid_count++; | |
7981 | pos = end; | |
7982 | } | |
7983 | ||
7984 | pos = os_strchr(pos, ' '); | |
7985 | if (pos) | |
7986 | pos++; | |
7987 | } | |
7988 | } | |
7989 | ||
7990 | wpa_s->num_ssids_from_scan_req = ssid_count; | |
7991 | os_free(wpa_s->ssids_from_scan_req); | |
7992 | if (ssid_count) { | |
7993 | wpa_s->ssids_from_scan_req = ssid; | |
7994 | ssid = NULL; | |
7995 | } else { | |
7996 | wpa_s->ssids_from_scan_req = NULL; | |
fee52342 JM |
7997 | } |
7998 | ||
43a66ecb JM |
7999 | if (scan_only) |
8000 | scan_res_handler = scan_only_handler; | |
8001 | else if (wpa_s->scan_res_handler == scan_only_handler) | |
8002 | scan_res_handler = NULL; | |
8003 | else | |
8004 | scan_res_handler = wpa_s->scan_res_handler; | |
8005 | ||
fee52342 JM |
8006 | if (!wpa_s->sched_scanning && !wpa_s->scanning && |
8007 | ((wpa_s->wpa_state <= WPA_SCANNING) || | |
8008 | (wpa_s->wpa_state == WPA_COMPLETED))) { | |
43a66ecb JM |
8009 | wpa_s->manual_scan_passive = manual_scan_passive; |
8010 | wpa_s->manual_scan_use_id = manual_scan_use_id; | |
8011 | wpa_s->manual_scan_only_new = manual_scan_only_new; | |
8012 | wpa_s->scan_id_count = scan_id_count; | |
8013 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); | |
8014 | wpa_s->scan_res_handler = scan_res_handler; | |
8015 | os_free(wpa_s->manual_scan_freqs); | |
8016 | wpa_s->manual_scan_freqs = manual_scan_freqs; | |
8017 | manual_scan_freqs = NULL; | |
8018 | ||
fee52342 JM |
8019 | wpa_s->normal_scans = 0; |
8020 | wpa_s->scan_req = MANUAL_SCAN_REQ; | |
8021 | wpa_s->after_wps = 0; | |
8022 | wpa_s->known_wps_freq = 0; | |
8023 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
d81c73be JM |
8024 | if (wpa_s->manual_scan_use_id) { |
8025 | wpa_s->manual_scan_id++; | |
8026 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", | |
8027 | wpa_s->manual_scan_id); | |
8028 | *reply_len = os_snprintf(reply, reply_size, "%u\n", | |
8029 | wpa_s->manual_scan_id); | |
8030 | } | |
fee52342 | 8031 | } else if (wpa_s->sched_scanning) { |
43a66ecb JM |
8032 | wpa_s->manual_scan_passive = manual_scan_passive; |
8033 | wpa_s->manual_scan_use_id = manual_scan_use_id; | |
8034 | wpa_s->manual_scan_only_new = manual_scan_only_new; | |
8035 | wpa_s->scan_id_count = scan_id_count; | |
8036 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); | |
8037 | wpa_s->scan_res_handler = scan_res_handler; | |
8038 | os_free(wpa_s->manual_scan_freqs); | |
8039 | wpa_s->manual_scan_freqs = manual_scan_freqs; | |
8040 | manual_scan_freqs = NULL; | |
8041 | ||
fee52342 JM |
8042 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed"); |
8043 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
8044 | wpa_s->scan_req = MANUAL_SCAN_REQ; | |
8045 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
d81c73be JM |
8046 | if (wpa_s->manual_scan_use_id) { |
8047 | wpa_s->manual_scan_id++; | |
8048 | *reply_len = os_snprintf(reply, reply_size, "%u\n", | |
8049 | wpa_s->manual_scan_id); | |
8050 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", | |
8051 | wpa_s->manual_scan_id); | |
8052 | } | |
fee52342 JM |
8053 | } else { |
8054 | wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request"); | |
8055 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | |
8056 | } | |
43a66ecb JM |
8057 | |
8058 | done: | |
8059 | os_free(manual_scan_freqs); | |
a80651d0 | 8060 | os_free(ssid); |
fee52342 JM |
8061 | } |
8062 | ||
8063 | ||
60b893df JM |
8064 | #ifdef CONFIG_TESTING_OPTIONS |
8065 | ||
8066 | static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s, | |
8067 | unsigned int freq, const u8 *dst, | |
8068 | const u8 *src, const u8 *bssid, | |
8069 | const u8 *data, size_t data_len, | |
8070 | enum offchannel_send_action_result | |
8071 | result) | |
8072 | { | |
8073 | wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR | |
8074 | " src=" MACSTR " bssid=" MACSTR " result=%s", | |
8075 | freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid), | |
8076 | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? | |
8077 | "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? | |
8078 | "NO_ACK" : "FAILED")); | |
8079 | } | |
8080 | ||
8081 | ||
8082 | static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd) | |
8083 | { | |
8084 | char *pos, *param; | |
8085 | size_t len; | |
8086 | u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN]; | |
8087 | int res, used; | |
8088 | int freq = 0, no_cck = 0, wait_time = 0; | |
8089 | ||
8090 | /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1] | |
8091 | * <action=Action frame payload> */ | |
8092 | ||
8093 | wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd); | |
8094 | ||
8095 | pos = cmd; | |
8096 | used = hwaddr_aton2(pos, da); | |
8097 | if (used < 0) | |
8098 | return -1; | |
8099 | pos += used; | |
8100 | while (*pos == ' ') | |
8101 | pos++; | |
8102 | used = hwaddr_aton2(pos, bssid); | |
8103 | if (used < 0) | |
8104 | return -1; | |
8105 | pos += used; | |
8106 | ||
8107 | param = os_strstr(pos, " freq="); | |
8108 | if (param) { | |
8109 | param += 6; | |
8110 | freq = atoi(param); | |
8111 | } | |
8112 | ||
8113 | param = os_strstr(pos, " no_cck="); | |
8114 | if (param) { | |
8115 | param += 8; | |
8116 | no_cck = atoi(param); | |
8117 | } | |
8118 | ||
8119 | param = os_strstr(pos, " wait_time="); | |
8120 | if (param) { | |
8121 | param += 11; | |
8122 | wait_time = atoi(param); | |
8123 | } | |
8124 | ||
8125 | param = os_strstr(pos, " action="); | |
8126 | if (param == NULL) | |
8127 | return -1; | |
8128 | param += 8; | |
8129 | ||
8130 | len = os_strlen(param); | |
8131 | if (len & 1) | |
8132 | return -1; | |
8133 | len /= 2; | |
8134 | ||
8135 | buf = os_malloc(len); | |
8136 | if (buf == NULL) | |
8137 | return -1; | |
8138 | ||
8139 | if (hexstr2bin(param, buf, len) < 0) { | |
8140 | os_free(buf); | |
8141 | return -1; | |
8142 | } | |
8143 | ||
8144 | res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid, | |
8145 | buf, len, wait_time, | |
8146 | wpas_ctrl_iface_mgmt_tx_cb, no_cck); | |
8147 | os_free(buf); | |
8148 | return res; | |
8149 | } | |
8150 | ||
8151 | ||
8152 | static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s) | |
8153 | { | |
8154 | wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting"); | |
8155 | offchannel_send_action_done(wpa_s); | |
8156 | } | |
8157 | ||
ad12f2f4 | 8158 | |
4de70e23 JM |
8159 | static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s, |
8160 | char *cmd) | |
8161 | { | |
8162 | char *pos, *param; | |
8163 | size_t len; | |
8164 | u8 *buf; | |
8165 | int freq = 0, datarate = 0, ssi_signal = 0; | |
8166 | union wpa_event_data event; | |
8167 | ||
8168 | if (!wpa_s->ext_mgmt_frame_handling) | |
8169 | return -1; | |
8170 | ||
8171 | /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */ | |
8172 | ||
8173 | wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd); | |
8174 | ||
8175 | pos = cmd; | |
8176 | param = os_strstr(pos, "freq="); | |
8177 | if (param) { | |
8178 | param += 5; | |
8179 | freq = atoi(param); | |
8180 | } | |
8181 | ||
8182 | param = os_strstr(pos, " datarate="); | |
8183 | if (param) { | |
8184 | param += 10; | |
8185 | datarate = atoi(param); | |
8186 | } | |
8187 | ||
8188 | param = os_strstr(pos, " ssi_signal="); | |
8189 | if (param) { | |
8190 | param += 12; | |
8191 | ssi_signal = atoi(param); | |
8192 | } | |
8193 | ||
8194 | param = os_strstr(pos, " frame="); | |
8195 | if (param == NULL) | |
8196 | return -1; | |
8197 | param += 7; | |
8198 | ||
8199 | len = os_strlen(param); | |
8200 | if (len & 1) | |
8201 | return -1; | |
8202 | len /= 2; | |
8203 | ||
8204 | buf = os_malloc(len); | |
8205 | if (buf == NULL) | |
8206 | return -1; | |
8207 | ||
8208 | if (hexstr2bin(param, buf, len) < 0) { | |
8209 | os_free(buf); | |
8210 | return -1; | |
8211 | } | |
8212 | ||
8213 | os_memset(&event, 0, sizeof(event)); | |
8214 | event.rx_mgmt.freq = freq; | |
8215 | event.rx_mgmt.frame = buf; | |
8216 | event.rx_mgmt.frame_len = len; | |
8217 | event.rx_mgmt.ssi_signal = ssi_signal; | |
8218 | event.rx_mgmt.datarate = datarate; | |
8219 | wpa_s->ext_mgmt_frame_handling = 0; | |
8220 | wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event); | |
8221 | wpa_s->ext_mgmt_frame_handling = 1; | |
8222 | ||
8223 | os_free(buf); | |
8224 | ||
8225 | return 0; | |
8226 | } | |
8227 | ||
8228 | ||
e4a3e1d0 JM |
8229 | static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s, |
8230 | char *param) | |
8231 | { | |
8232 | struct wpa_scan_res *res; | |
8233 | struct os_reltime now; | |
8234 | char *pos, *end; | |
1fb4437c | 8235 | int ret = -1; |
e4a3e1d0 JM |
8236 | |
8237 | if (!param) | |
8238 | return -1; | |
8239 | ||
8240 | if (os_strcmp(param, "START") == 0) { | |
8241 | wpa_bss_update_start(wpa_s); | |
8242 | return 0; | |
8243 | } | |
8244 | ||
8245 | if (os_strcmp(param, "END") == 0) { | |
8246 | wpa_bss_update_end(wpa_s, NULL, 1); | |
8247 | return 0; | |
8248 | } | |
8249 | ||
8250 | if (os_strncmp(param, "BSS ", 4) != 0) | |
8251 | return -1; | |
8252 | param += 3; | |
8253 | ||
8254 | res = os_zalloc(sizeof(*res) + os_strlen(param) / 2); | |
8255 | if (!res) | |
8256 | return -1; | |
8257 | ||
8258 | pos = os_strstr(param, " flags="); | |
8259 | if (pos) | |
8260 | res->flags = strtol(pos + 7, NULL, 16); | |
8261 | ||
8262 | pos = os_strstr(param, " bssid="); | |
1fb4437c JM |
8263 | if (pos && hwaddr_aton(pos + 7, res->bssid)) |
8264 | goto fail; | |
e4a3e1d0 JM |
8265 | |
8266 | pos = os_strstr(param, " freq="); | |
8267 | if (pos) | |
8268 | res->freq = atoi(pos + 6); | |
8269 | ||
8270 | pos = os_strstr(param, " beacon_int="); | |
8271 | if (pos) | |
8272 | res->beacon_int = atoi(pos + 12); | |
8273 | ||
8274 | pos = os_strstr(param, " caps="); | |
8275 | if (pos) | |
8276 | res->caps = strtol(pos + 6, NULL, 16); | |
8277 | ||
8278 | pos = os_strstr(param, " qual="); | |
8279 | if (pos) | |
8280 | res->qual = atoi(pos + 6); | |
8281 | ||
8282 | pos = os_strstr(param, " noise="); | |
8283 | if (pos) | |
8284 | res->noise = atoi(pos + 7); | |
8285 | ||
8286 | pos = os_strstr(param, " level="); | |
8287 | if (pos) | |
8288 | res->level = atoi(pos + 7); | |
8289 | ||
8290 | pos = os_strstr(param, " tsf="); | |
8291 | if (pos) | |
8292 | res->tsf = strtoll(pos + 5, NULL, 16); | |
8293 | ||
8294 | pos = os_strstr(param, " age="); | |
8295 | if (pos) | |
8296 | res->age = atoi(pos + 5); | |
8297 | ||
8298 | pos = os_strstr(param, " est_throughput="); | |
8299 | if (pos) | |
8300 | res->est_throughput = atoi(pos + 16); | |
8301 | ||
8302 | pos = os_strstr(param, " snr="); | |
8303 | if (pos) | |
8304 | res->snr = atoi(pos + 5); | |
8305 | ||
8306 | pos = os_strstr(param, " parent_tsf="); | |
8307 | if (pos) | |
8308 | res->parent_tsf = strtoll(pos + 7, NULL, 16); | |
8309 | ||
8310 | pos = os_strstr(param, " tsf_bssid="); | |
1fb4437c JM |
8311 | if (pos && hwaddr_aton(pos + 11, res->tsf_bssid)) |
8312 | goto fail; | |
e4a3e1d0 JM |
8313 | |
8314 | pos = os_strstr(param, " ie="); | |
8315 | if (pos) { | |
8316 | pos += 4; | |
8317 | end = os_strchr(pos, ' '); | |
8318 | if (!end) | |
8319 | end = pos + os_strlen(pos); | |
8320 | res->ie_len = (end - pos) / 2; | |
1fb4437c JM |
8321 | if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len)) |
8322 | goto fail; | |
e4a3e1d0 JM |
8323 | } |
8324 | ||
8325 | pos = os_strstr(param, " beacon_ie="); | |
8326 | if (pos) { | |
8327 | pos += 11; | |
8328 | end = os_strchr(pos, ' '); | |
8329 | if (!end) | |
8330 | end = pos + os_strlen(pos); | |
8331 | res->beacon_ie_len = (end - pos) / 2; | |
1fb4437c JM |
8332 | if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len, |
8333 | res->beacon_ie_len)) | |
8334 | goto fail; | |
e4a3e1d0 JM |
8335 | } |
8336 | ||
8337 | os_get_reltime(&now); | |
8338 | wpa_bss_update_scan_res(wpa_s, res, &now); | |
1fb4437c JM |
8339 | ret = 0; |
8340 | fail: | |
e4a3e1d0 JM |
8341 | os_free(res); |
8342 | ||
1fb4437c | 8343 | return ret; |
e4a3e1d0 JM |
8344 | } |
8345 | ||
8346 | ||
ad12f2f4 JM |
8347 | static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd) |
8348 | { | |
8349 | char *pos, *param; | |
8350 | union wpa_event_data event; | |
8351 | enum wpa_event_type ev; | |
8352 | ||
8353 | /* <event name> [parameters..] */ | |
8354 | ||
8355 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd); | |
8356 | ||
8357 | pos = cmd; | |
8358 | param = os_strchr(pos, ' '); | |
8359 | if (param) | |
8360 | *param++ = '\0'; | |
8361 | ||
8362 | os_memset(&event, 0, sizeof(event)); | |
8363 | ||
8364 | if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) { | |
8365 | ev = EVENT_INTERFACE_ENABLED; | |
8366 | } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) { | |
8367 | ev = EVENT_INTERFACE_DISABLED; | |
7bb70909 JM |
8368 | } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) { |
8369 | ev = EVENT_AVOID_FREQUENCIES; | |
8370 | if (param == NULL) | |
8371 | param = ""; | |
8372 | if (freq_range_list_parse(&event.freq_range, param) < 0) | |
8373 | return -1; | |
8374 | wpa_supplicant_event(wpa_s, ev, &event); | |
8375 | os_free(event.freq_range.range); | |
8376 | return 0; | |
e4a3e1d0 JM |
8377 | } else if (os_strcmp(cmd, "SCAN_RES") == 0) { |
8378 | return wpas_ctrl_iface_driver_scan_res(wpa_s, param); | |
ad12f2f4 JM |
8379 | } else { |
8380 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s", | |
8381 | cmd); | |
8382 | return -1; | |
8383 | } | |
8384 | ||
8385 | wpa_supplicant_event(wpa_s, ev, &event); | |
8386 | ||
8387 | return 0; | |
8388 | } | |
8389 | ||
9d4ff04a JM |
8390 | |
8391 | static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd) | |
8392 | { | |
8393 | char *pos; | |
8394 | u8 src[ETH_ALEN], *buf; | |
8395 | int used; | |
8396 | size_t len; | |
8397 | ||
8398 | wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd); | |
8399 | ||
8400 | pos = cmd; | |
8401 | used = hwaddr_aton2(pos, src); | |
8402 | if (used < 0) | |
8403 | return -1; | |
8404 | pos += used; | |
8405 | while (*pos == ' ') | |
8406 | pos++; | |
8407 | ||
8408 | len = os_strlen(pos); | |
8409 | if (len & 1) | |
8410 | return -1; | |
8411 | len /= 2; | |
8412 | ||
8413 | buf = os_malloc(len); | |
8414 | if (buf == NULL) | |
8415 | return -1; | |
8416 | ||
8417 | if (hexstr2bin(pos, buf, len) < 0) { | |
8418 | os_free(buf); | |
8419 | return -1; | |
8420 | } | |
8421 | ||
8422 | wpa_supplicant_rx_eapol(wpa_s, src, buf, len); | |
8423 | os_free(buf); | |
8424 | ||
8425 | return 0; | |
8426 | } | |
8427 | ||
4a6cc862 JM |
8428 | |
8429 | static u16 ipv4_hdr_checksum(const void *buf, size_t len) | |
8430 | { | |
8431 | size_t i; | |
8432 | u32 sum = 0; | |
8433 | const u16 *pos = buf; | |
8434 | ||
8435 | for (i = 0; i < len / 2; i++) | |
8436 | sum += *pos++; | |
8437 | ||
8438 | while (sum >> 16) | |
8439 | sum = (sum & 0xffff) + (sum >> 16); | |
8440 | ||
8441 | return sum ^ 0xffff; | |
8442 | } | |
8443 | ||
8444 | ||
8445 | #define HWSIM_PACKETLEN 1500 | |
8446 | #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header)) | |
8447 | ||
0dbe22be JM |
8448 | static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, |
8449 | size_t len) | |
4a6cc862 JM |
8450 | { |
8451 | struct wpa_supplicant *wpa_s = ctx; | |
8452 | const struct ether_header *eth; | |
75352270 | 8453 | struct iphdr ip; |
4a6cc862 JM |
8454 | const u8 *pos; |
8455 | unsigned int i; | |
8456 | ||
8457 | if (len != HWSIM_PACKETLEN) | |
8458 | return; | |
8459 | ||
8460 | eth = (const struct ether_header *) buf; | |
75352270 JM |
8461 | os_memcpy(&ip, eth + 1, sizeof(ip)); |
8462 | pos = &buf[sizeof(*eth) + sizeof(ip)]; | |
4a6cc862 | 8463 | |
75352270 JM |
8464 | if (ip.ihl != 5 || ip.version != 4 || |
8465 | ntohs(ip.tot_len) != HWSIM_IP_LEN) | |
4a6cc862 JM |
8466 | return; |
8467 | ||
75352270 | 8468 | for (i = 0; i < HWSIM_IP_LEN - sizeof(ip); i++) { |
4a6cc862 JM |
8469 | if (*pos != (u8) i) |
8470 | return; | |
8471 | pos++; | |
8472 | } | |
8473 | ||
8474 | wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR, | |
8475 | MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost)); | |
8476 | } | |
8477 | ||
8478 | ||
8479 | static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s, | |
8480 | char *cmd) | |
8481 | { | |
8482 | int enabled = atoi(cmd); | |
ba91e920 MB |
8483 | char *pos; |
8484 | const char *ifname; | |
4a6cc862 JM |
8485 | |
8486 | if (!enabled) { | |
8487 | if (wpa_s->l2_test) { | |
8488 | l2_packet_deinit(wpa_s->l2_test); | |
8489 | wpa_s->l2_test = NULL; | |
8490 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled"); | |
8491 | } | |
8492 | return 0; | |
8493 | } | |
8494 | ||
8495 | if (wpa_s->l2_test) | |
8496 | return 0; | |
8497 | ||
ba91e920 MB |
8498 | pos = os_strstr(cmd, " ifname="); |
8499 | if (pos) | |
8500 | ifname = pos + 8; | |
8501 | else | |
8502 | ifname = wpa_s->ifname; | |
8503 | ||
8504 | wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr, | |
4a6cc862 JM |
8505 | ETHERTYPE_IP, wpas_data_test_rx, |
8506 | wpa_s, 1); | |
8507 | if (wpa_s->l2_test == NULL) | |
8508 | return -1; | |
8509 | ||
8510 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled"); | |
8511 | ||
8512 | return 0; | |
8513 | } | |
8514 | ||
8515 | ||
8516 | static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd) | |
8517 | { | |
8518 | u8 dst[ETH_ALEN], src[ETH_ALEN]; | |
8519 | char *pos; | |
8520 | int used; | |
8521 | long int val; | |
8522 | u8 tos; | |
75352270 | 8523 | u8 buf[2 + HWSIM_PACKETLEN]; |
4a6cc862 JM |
8524 | struct ether_header *eth; |
8525 | struct iphdr *ip; | |
8526 | u8 *dpos; | |
8527 | unsigned int i; | |
8528 | ||
8529 | if (wpa_s->l2_test == NULL) | |
8530 | return -1; | |
8531 | ||
8532 | /* format: <dst> <src> <tos> */ | |
8533 | ||
8534 | pos = cmd; | |
8535 | used = hwaddr_aton2(pos, dst); | |
8536 | if (used < 0) | |
8537 | return -1; | |
8538 | pos += used; | |
8539 | while (*pos == ' ') | |
8540 | pos++; | |
8541 | used = hwaddr_aton2(pos, src); | |
8542 | if (used < 0) | |
8543 | return -1; | |
8544 | pos += used; | |
8545 | ||
8546 | val = strtol(pos, NULL, 0); | |
8547 | if (val < 0 || val > 0xff) | |
8548 | return -1; | |
8549 | tos = val; | |
8550 | ||
75352270 | 8551 | eth = (struct ether_header *) &buf[2]; |
4a6cc862 JM |
8552 | os_memcpy(eth->ether_dhost, dst, ETH_ALEN); |
8553 | os_memcpy(eth->ether_shost, src, ETH_ALEN); | |
8554 | eth->ether_type = htons(ETHERTYPE_IP); | |
8555 | ip = (struct iphdr *) (eth + 1); | |
8556 | os_memset(ip, 0, sizeof(*ip)); | |
8557 | ip->ihl = 5; | |
8558 | ip->version = 4; | |
8559 | ip->ttl = 64; | |
8560 | ip->tos = tos; | |
8561 | ip->tot_len = htons(HWSIM_IP_LEN); | |
8562 | ip->protocol = 1; | |
66f1e078 JM |
8563 | ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1); |
8564 | ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2); | |
4a6cc862 JM |
8565 | ip->check = ipv4_hdr_checksum(ip, sizeof(*ip)); |
8566 | dpos = (u8 *) (ip + 1); | |
8567 | for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) | |
8568 | *dpos++ = i; | |
8569 | ||
75352270 | 8570 | if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2], |
4a6cc862 JM |
8571 | HWSIM_PACKETLEN) < 0) |
8572 | return -1; | |
8573 | ||
8574 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR | |
8575 | " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos); | |
8576 | ||
8577 | return 0; | |
8578 | } | |
8579 | ||
fc0ef7c0 JM |
8580 | |
8581 | static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s, | |
8582 | char *cmd) | |
8583 | { | |
8584 | u8 *buf; | |
8585 | struct ether_header *eth; | |
8586 | struct l2_packet_data *l2 = NULL; | |
8587 | size_t len; | |
8588 | u16 ethertype; | |
8589 | int res = -1; | |
8590 | ||
8591 | len = os_strlen(cmd); | |
8592 | if (len & 1 || len < ETH_HLEN * 2) | |
8593 | return -1; | |
8594 | len /= 2; | |
8595 | ||
8596 | buf = os_malloc(len); | |
8597 | if (buf == NULL) | |
8598 | return -1; | |
8599 | ||
8600 | if (hexstr2bin(cmd, buf, len) < 0) | |
8601 | goto done; | |
8602 | ||
8603 | eth = (struct ether_header *) buf; | |
8604 | ethertype = ntohs(eth->ether_type); | |
8605 | ||
8606 | l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype, | |
8607 | wpas_data_test_rx, wpa_s, 1); | |
8608 | if (l2 == NULL) | |
8609 | goto done; | |
8610 | ||
8611 | res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len); | |
8612 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res); | |
8613 | done: | |
8614 | if (l2) | |
8615 | l2_packet_deinit(l2); | |
8616 | os_free(buf); | |
8617 | ||
8618 | return res < 0 ? -1 : 0; | |
8619 | } | |
8620 | ||
a156ffda JM |
8621 | |
8622 | static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd) | |
8623 | { | |
8624 | #ifdef WPA_TRACE_BFD | |
a156ffda JM |
8625 | char *pos; |
8626 | ||
8627 | wpa_trace_fail_after = atoi(cmd); | |
8628 | pos = os_strchr(cmd, ':'); | |
8629 | if (pos) { | |
8630 | pos++; | |
8631 | os_strlcpy(wpa_trace_fail_func, pos, | |
8632 | sizeof(wpa_trace_fail_func)); | |
8633 | } else { | |
8634 | wpa_trace_fail_after = 0; | |
8635 | } | |
8636 | return 0; | |
8637 | #else /* WPA_TRACE_BFD */ | |
8638 | return -1; | |
8639 | #endif /* WPA_TRACE_BFD */ | |
8640 | } | |
8641 | ||
8642 | ||
8643 | static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s, | |
8644 | char *buf, size_t buflen) | |
8645 | { | |
8646 | #ifdef WPA_TRACE_BFD | |
a156ffda JM |
8647 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after, |
8648 | wpa_trace_fail_func); | |
8649 | #else /* WPA_TRACE_BFD */ | |
8650 | return -1; | |
8651 | #endif /* WPA_TRACE_BFD */ | |
8652 | } | |
8653 | ||
2da52565 JM |
8654 | |
8655 | static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd) | |
8656 | { | |
8657 | #ifdef WPA_TRACE_BFD | |
2da52565 JM |
8658 | char *pos; |
8659 | ||
8660 | wpa_trace_test_fail_after = atoi(cmd); | |
8661 | pos = os_strchr(cmd, ':'); | |
8662 | if (pos) { | |
8663 | pos++; | |
8664 | os_strlcpy(wpa_trace_test_fail_func, pos, | |
8665 | sizeof(wpa_trace_test_fail_func)); | |
8666 | } else { | |
8667 | wpa_trace_test_fail_after = 0; | |
8668 | } | |
8669 | return 0; | |
8670 | #else /* WPA_TRACE_BFD */ | |
8671 | return -1; | |
8672 | #endif /* WPA_TRACE_BFD */ | |
8673 | } | |
8674 | ||
8675 | ||
8676 | static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s, | |
8677 | char *buf, size_t buflen) | |
8678 | { | |
8679 | #ifdef WPA_TRACE_BFD | |
2da52565 JM |
8680 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after, |
8681 | wpa_trace_test_fail_func); | |
8682 | #else /* WPA_TRACE_BFD */ | |
8683 | return -1; | |
8684 | #endif /* WPA_TRACE_BFD */ | |
8685 | } | |
8686 | ||
a530fe77 JM |
8687 | |
8688 | static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx) | |
8689 | { | |
8690 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
8691 | int i, count = (intptr_t) timeout_ctx; | |
8692 | ||
8693 | wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages", | |
8694 | count); | |
8695 | for (i = 0; i < count; i++) { | |
8696 | wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d", | |
8697 | i + 1, count); | |
8698 | } | |
8699 | } | |
8700 | ||
8701 | ||
8702 | static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd) | |
8703 | { | |
8704 | int count; | |
8705 | ||
8706 | count = atoi(cmd); | |
8707 | if (count <= 0) | |
8708 | return -1; | |
8709 | ||
8710 | return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s, | |
8711 | (void *) (intptr_t) count); | |
8712 | } | |
8713 | ||
651c6a84 JM |
8714 | |
8715 | static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s, | |
8716 | const char *cmd) | |
8717 | { | |
8718 | struct wpabuf *buf; | |
8719 | size_t len; | |
8720 | ||
8721 | len = os_strlen(cmd); | |
8722 | if (len & 1) | |
8723 | return -1; | |
8724 | len /= 2; | |
8725 | ||
8726 | if (len == 0) { | |
8727 | buf = NULL; | |
8728 | } else { | |
8729 | buf = wpabuf_alloc(len); | |
8730 | if (buf == NULL) | |
8731 | return -1; | |
8732 | ||
8733 | if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) { | |
8734 | wpabuf_free(buf); | |
8735 | return -1; | |
8736 | } | |
8737 | } | |
8738 | ||
8739 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf); | |
8740 | return 0; | |
8741 | } | |
8742 | ||
60b893df JM |
8743 | #endif /* CONFIG_TESTING_OPTIONS */ |
8744 | ||
8745 | ||
86bd36f0 JM |
8746 | static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd) |
8747 | { | |
8748 | char *pos = cmd; | |
8749 | int frame; | |
8750 | size_t len; | |
8751 | struct wpabuf *buf; | |
8752 | struct ieee802_11_elems elems; | |
8753 | ||
8754 | frame = atoi(pos); | |
8755 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | |
8756 | return -1; | |
af041f99 | 8757 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
86bd36f0 JM |
8758 | |
8759 | pos = os_strchr(pos, ' '); | |
8760 | if (pos == NULL) | |
8761 | return -1; | |
8762 | pos++; | |
8763 | ||
8764 | len = os_strlen(pos); | |
8765 | if (len == 0) | |
8766 | return 0; | |
8767 | if (len & 1) | |
8768 | return -1; | |
8769 | len /= 2; | |
8770 | ||
8771 | buf = wpabuf_alloc(len); | |
8772 | if (buf == NULL) | |
8773 | return -1; | |
8774 | ||
8775 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { | |
8776 | wpabuf_free(buf); | |
8777 | return -1; | |
8778 | } | |
8779 | ||
8780 | if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) == | |
8781 | ParseFailed) { | |
8782 | wpabuf_free(buf); | |
8783 | return -1; | |
8784 | } | |
8785 | ||
8786 | if (wpa_s->vendor_elem[frame] == NULL) { | |
8787 | wpa_s->vendor_elem[frame] = buf; | |
af041f99 | 8788 | wpas_vendor_elem_update(wpa_s); |
86bd36f0 JM |
8789 | return 0; |
8790 | } | |
8791 | ||
8792 | if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) { | |
8793 | wpabuf_free(buf); | |
8794 | return -1; | |
8795 | } | |
8796 | ||
8797 | wpabuf_put_buf(wpa_s->vendor_elem[frame], buf); | |
8798 | wpabuf_free(buf); | |
af041f99 | 8799 | wpas_vendor_elem_update(wpa_s); |
86bd36f0 JM |
8800 | |
8801 | return 0; | |
8802 | } | |
8803 | ||
8804 | ||
8805 | static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd, | |
8806 | char *buf, size_t buflen) | |
8807 | { | |
8808 | int frame = atoi(cmd); | |
8809 | ||
8810 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | |
8811 | return -1; | |
af041f99 | 8812 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
86bd36f0 JM |
8813 | |
8814 | if (wpa_s->vendor_elem[frame] == NULL) | |
8815 | return 0; | |
8816 | ||
8817 | return wpa_snprintf_hex(buf, buflen, | |
8818 | wpabuf_head_u8(wpa_s->vendor_elem[frame]), | |
8819 | wpabuf_len(wpa_s->vendor_elem[frame])); | |
8820 | } | |
8821 | ||
8822 | ||
8823 | static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd) | |
8824 | { | |
8825 | char *pos = cmd; | |
8826 | int frame; | |
8827 | size_t len; | |
8828 | u8 *buf; | |
8829 | struct ieee802_11_elems elems; | |
af041f99 | 8830 | int res; |
86bd36f0 JM |
8831 | |
8832 | frame = atoi(pos); | |
8833 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | |
8834 | return -1; | |
af041f99 | 8835 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
86bd36f0 JM |
8836 | |
8837 | pos = os_strchr(pos, ' '); | |
8838 | if (pos == NULL) | |
8839 | return -1; | |
8840 | pos++; | |
8841 | ||
8842 | if (*pos == '*') { | |
8843 | wpabuf_free(wpa_s->vendor_elem[frame]); | |
8844 | wpa_s->vendor_elem[frame] = NULL; | |
af041f99 | 8845 | wpas_vendor_elem_update(wpa_s); |
86bd36f0 JM |
8846 | return 0; |
8847 | } | |
8848 | ||
8849 | if (wpa_s->vendor_elem[frame] == NULL) | |
8850 | return -1; | |
8851 | ||
8852 | len = os_strlen(pos); | |
8853 | if (len == 0) | |
8854 | return 0; | |
8855 | if (len & 1) | |
8856 | return -1; | |
8857 | len /= 2; | |
8858 | ||
8859 | buf = os_malloc(len); | |
8860 | if (buf == NULL) | |
8861 | return -1; | |
8862 | ||
8863 | if (hexstr2bin(pos, buf, len) < 0) { | |
8864 | os_free(buf); | |
8865 | return -1; | |
8866 | } | |
8867 | ||
8868 | if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) { | |
8869 | os_free(buf); | |
8870 | return -1; | |
8871 | } | |
8872 | ||
af041f99 | 8873 | res = wpas_vendor_elem_remove(wpa_s, frame, buf, len); |
86bd36f0 | 8874 | os_free(buf); |
af041f99 | 8875 | return res; |
86bd36f0 JM |
8876 | } |
8877 | ||
8878 | ||
f4b8bfae AK |
8879 | static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep) |
8880 | { | |
8881 | struct wpa_supplicant *wpa_s = ctx; | |
cf667c66 IP |
8882 | size_t len; |
8883 | const u8 *data; | |
f4b8bfae | 8884 | |
cf667c66 IP |
8885 | /* |
8886 | * Neighbor Report element (IEEE P802.11-REVmc/D5.0) | |
8887 | * BSSID[6] | |
8888 | * BSSID Information[4] | |
8889 | * Operating Class[1] | |
8890 | * Channel Number[1] | |
8891 | * PHY Type[1] | |
8892 | * Optional Subelements[variable] | |
8893 | */ | |
8894 | #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1) | |
8895 | ||
8896 | if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) { | |
f4b8bfae | 8897 | wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED); |
cf667c66 IP |
8898 | goto out; |
8899 | } | |
8900 | ||
8901 | data = wpabuf_head_u8(neighbor_rep); | |
8902 | len = wpabuf_len(neighbor_rep); | |
8903 | ||
8904 | while (len >= 2 + NR_IE_MIN_LEN) { | |
8905 | const u8 *nr; | |
8906 | char lci[256 * 2 + 1]; | |
8907 | char civic[256 * 2 + 1]; | |
8908 | u8 nr_len = data[1]; | |
8909 | const u8 *pos = data, *end; | |
8910 | ||
8911 | if (pos[0] != WLAN_EID_NEIGHBOR_REPORT || | |
8912 | nr_len < NR_IE_MIN_LEN) { | |
8913 | wpa_printf(MSG_DEBUG, | |
8914 | "CTRL: Invalid Neighbor Report element: id=%u len=%u", | |
8915 | data[0], nr_len); | |
8916 | goto out; | |
8917 | } | |
8918 | ||
8919 | if (2U + nr_len > len) { | |
8920 | wpa_printf(MSG_DEBUG, | |
8921 | "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u", | |
8922 | data[0], len, nr_len); | |
8923 | goto out; | |
8924 | } | |
8925 | pos += 2; | |
8926 | end = pos + nr_len; | |
8927 | ||
8928 | nr = pos; | |
8929 | pos += NR_IE_MIN_LEN; | |
8930 | ||
8931 | lci[0] = '\0'; | |
8932 | civic[0] = '\0'; | |
8933 | while (end - pos > 2) { | |
8934 | u8 s_id, s_len; | |
8935 | ||
8936 | s_id = *pos++; | |
8937 | s_len = *pos++; | |
8938 | if (s_len > end - pos) | |
8939 | goto out; | |
8940 | if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) { | |
8941 | /* Measurement Token[1] */ | |
8942 | /* Measurement Report Mode[1] */ | |
8943 | /* Measurement Type[1] */ | |
8944 | /* Measurement Report[variable] */ | |
8945 | switch (pos[2]) { | |
8946 | case MEASURE_TYPE_LCI: | |
8947 | if (lci[0]) | |
8948 | break; | |
8949 | wpa_snprintf_hex(lci, sizeof(lci), | |
8950 | pos, s_len); | |
8951 | break; | |
8952 | case MEASURE_TYPE_LOCATION_CIVIC: | |
8953 | if (civic[0]) | |
8954 | break; | |
8955 | wpa_snprintf_hex(civic, sizeof(civic), | |
8956 | pos, s_len); | |
8957 | break; | |
8958 | } | |
8959 | } | |
8960 | ||
8961 | pos += s_len; | |
8962 | } | |
8963 | ||
8964 | wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED | |
8965 | "bssid=" MACSTR | |
8966 | " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s", | |
8967 | MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN), | |
8968 | nr[ETH_ALEN + 4], nr[ETH_ALEN + 5], | |
8969 | nr[ETH_ALEN + 6], | |
8970 | lci[0] ? " lci=" : "", lci, | |
8971 | civic[0] ? " civic=" : "", civic); | |
8972 | ||
8973 | data = end; | |
8974 | len -= 2 + nr_len; | |
f4b8bfae | 8975 | } |
cf667c66 IP |
8976 | |
8977 | out: | |
8978 | wpabuf_free(neighbor_rep); | |
f4b8bfae AK |
8979 | } |
8980 | ||
8981 | ||
6a4f0ed7 JM |
8982 | static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s, |
8983 | char *cmd) | |
f4b8bfae | 8984 | { |
d41a5352 DS |
8985 | struct wpa_ssid_value ssid, *ssid_p = NULL; |
8986 | int ret, lci = 0, civic = 0; | |
8987 | char *ssid_s; | |
4c4b2305 | 8988 | |
d41a5352 DS |
8989 | ssid_s = os_strstr(cmd, "ssid="); |
8990 | if (ssid_s) { | |
8991 | if (ssid_parse(ssid_s + 5, &ssid)) { | |
8992 | wpa_printf(MSG_ERROR, | |
8993 | "CTRL: Send Neighbor Report: bad SSID"); | |
4c4b2305 | 8994 | return -1; |
d41a5352 DS |
8995 | } |
8996 | ||
4c4b2305 | 8997 | ssid_p = &ssid; |
d41a5352 DS |
8998 | |
8999 | /* | |
9000 | * Move cmd after the SSID text that may include "lci" or | |
9001 | * "civic". | |
9002 | */ | |
9003 | cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' '); | |
9004 | if (cmd) | |
9005 | cmd++; | |
9006 | ||
4c4b2305 AK |
9007 | } |
9008 | ||
d41a5352 DS |
9009 | if (cmd && os_strstr(cmd, "lci")) |
9010 | lci = 1; | |
9011 | ||
9012 | if (cmd && os_strstr(cmd, "civic")) | |
9013 | civic = 1; | |
9014 | ||
9015 | ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic, | |
4c4b2305 AK |
9016 | wpas_ctrl_neighbor_rep_cb, |
9017 | wpa_s); | |
9018 | ||
9019 | return ret; | |
f4b8bfae AK |
9020 | } |
9021 | ||
9022 | ||
65d9a5e2 JM |
9023 | static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s) |
9024 | { | |
9025 | eapol_sm_erp_flush(wpa_s->eapol); | |
9026 | return 0; | |
9027 | } | |
9028 | ||
9029 | ||
fb375883 IP |
9030 | static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s, |
9031 | char *cmd) | |
9032 | { | |
9033 | char *token, *context = NULL; | |
9034 | unsigned int enable = ~0, type = 0; | |
9035 | u8 _addr[ETH_ALEN], _mask[ETH_ALEN]; | |
9036 | u8 *addr = NULL, *mask = NULL; | |
9037 | ||
9038 | while ((token = str_token(cmd, " ", &context))) { | |
9039 | if (os_strcasecmp(token, "scan") == 0) { | |
9040 | type |= MAC_ADDR_RAND_SCAN; | |
9041 | } else if (os_strcasecmp(token, "sched") == 0) { | |
9042 | type |= MAC_ADDR_RAND_SCHED_SCAN; | |
9043 | } else if (os_strcasecmp(token, "pno") == 0) { | |
9044 | type |= MAC_ADDR_RAND_PNO; | |
9045 | } else if (os_strcasecmp(token, "all") == 0) { | |
9046 | type = wpa_s->mac_addr_rand_supported; | |
9047 | } else if (os_strncasecmp(token, "enable=", 7) == 0) { | |
9048 | enable = atoi(token + 7); | |
9049 | } else if (os_strncasecmp(token, "addr=", 5) == 0) { | |
9050 | addr = _addr; | |
9051 | if (hwaddr_aton(token + 5, addr)) { | |
9052 | wpa_printf(MSG_INFO, | |
9053 | "CTRL: Invalid MAC address: %s", | |
9054 | token); | |
9055 | return -1; | |
9056 | } | |
9057 | } else if (os_strncasecmp(token, "mask=", 5) == 0) { | |
9058 | mask = _mask; | |
9059 | if (hwaddr_aton(token + 5, mask)) { | |
9060 | wpa_printf(MSG_INFO, | |
9061 | "CTRL: Invalid MAC address mask: %s", | |
9062 | token); | |
9063 | return -1; | |
9064 | } | |
9065 | } else { | |
9066 | wpa_printf(MSG_INFO, | |
9067 | "CTRL: Invalid MAC_RAND_SCAN parameter: %s", | |
9068 | token); | |
9069 | return -1; | |
9070 | } | |
9071 | } | |
9072 | ||
9073 | if (!type) { | |
9074 | wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified"); | |
9075 | return -1; | |
9076 | } | |
9077 | ||
9078 | if ((wpa_s->mac_addr_rand_supported & type) != type) { | |
9079 | wpa_printf(MSG_INFO, | |
9080 | "CTRL: MAC_RAND_SCAN types=%u != supported=%u", | |
9081 | type, wpa_s->mac_addr_rand_supported); | |
9082 | return -1; | |
9083 | } | |
9084 | ||
9085 | if (enable > 1) { | |
9086 | wpa_printf(MSG_INFO, | |
9087 | "CTRL: MAC_RAND_SCAN enable=<0/1> not specified"); | |
9088 | return -1; | |
9089 | } | |
9090 | ||
9091 | if (!enable) { | |
9092 | wpas_mac_addr_rand_scan_clear(wpa_s, type); | |
9093 | if (wpa_s->pno) { | |
9094 | if (type & MAC_ADDR_RAND_PNO) { | |
9095 | wpas_stop_pno(wpa_s); | |
9096 | wpas_start_pno(wpa_s); | |
9097 | } | |
9098 | } else if (wpa_s->sched_scanning && | |
9099 | (type & MAC_ADDR_RAND_SCHED_SCAN)) { | |
5bb7327a | 9100 | wpas_scan_restart_sched_scan(wpa_s); |
fb375883 IP |
9101 | } |
9102 | return 0; | |
9103 | } | |
9104 | ||
9105 | if ((addr && !mask) || (!addr && mask)) { | |
9106 | wpa_printf(MSG_INFO, | |
9107 | "CTRL: MAC_RAND_SCAN invalid addr/mask combination"); | |
9108 | return -1; | |
9109 | } | |
9110 | ||
9111 | if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) { | |
9112 | wpa_printf(MSG_INFO, | |
9113 | "CTRL: MAC_RAND_SCAN cannot allow multicast address"); | |
9114 | return -1; | |
9115 | } | |
9116 | ||
9117 | if (type & MAC_ADDR_RAND_SCAN) { | |
9118 | wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN, | |
9119 | addr, mask); | |
9120 | } | |
9121 | ||
9122 | if (type & MAC_ADDR_RAND_SCHED_SCAN) { | |
9123 | wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN, | |
9124 | addr, mask); | |
9125 | ||
5bb7327a JM |
9126 | if (wpa_s->sched_scanning && !wpa_s->pno) |
9127 | wpas_scan_restart_sched_scan(wpa_s); | |
fb375883 IP |
9128 | } |
9129 | ||
9130 | if (type & MAC_ADDR_RAND_PNO) { | |
9131 | wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO, | |
9132 | addr, mask); | |
9133 | if (wpa_s->pno) { | |
9134 | wpas_stop_pno(wpa_s); | |
9135 | wpas_start_pno(wpa_s); | |
9136 | } | |
9137 | } | |
9138 | ||
9139 | return 0; | |
9140 | } | |
9141 | ||
9142 | ||
b8daac18 MH |
9143 | static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s, |
9144 | char *buf, size_t buflen) | |
9145 | { | |
9146 | size_t reply_len; | |
9147 | ||
9148 | reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen); | |
9149 | #ifdef CONFIG_AP | |
9150 | reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len], | |
9151 | buflen - reply_len); | |
9152 | #endif /* CONFIG_AP */ | |
9153 | return reply_len; | |
9154 | } | |
9155 | ||
9156 | ||
4c522c77 MH |
9157 | static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s) |
9158 | { | |
9159 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); | |
9160 | #ifdef CONFIG_AP | |
9161 | wpas_ap_pmksa_cache_flush(wpa_s); | |
9162 | #endif /* CONFIG_AP */ | |
9163 | } | |
9164 | ||
9165 | ||
3459381d JM |
9166 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
9167 | ||
9168 | static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s, | |
9169 | const char *cmd, char *buf, size_t buflen) | |
9170 | { | |
9171 | struct rsn_pmksa_cache_entry *entry; | |
9172 | struct wpa_ssid *ssid; | |
9173 | char *pos, *pos2, *end; | |
9174 | int ret; | |
9175 | struct os_reltime now; | |
9176 | ||
9177 | ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd)); | |
9178 | if (!ssid) | |
9179 | return -1; | |
9180 | ||
9181 | pos = buf; | |
9182 | end = buf + buflen; | |
9183 | ||
9184 | os_get_reltime(&now); | |
9185 | ||
9186 | /* | |
9187 | * Entry format: | |
9188 | * <BSSID> <PMKID> <PMK> <reauth_time in seconds> | |
9189 | * <expiration in seconds> <akmp> <opportunistic> | |
b7286c1b | 9190 | * [FILS Cache Identifier] |
3459381d JM |
9191 | */ |
9192 | ||
9193 | for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry; | |
9194 | entry = entry->next) { | |
9195 | if (entry->network_ctx != ssid) | |
9196 | continue; | |
9197 | ||
9198 | pos2 = pos; | |
9199 | ret = os_snprintf(pos2, end - pos2, MACSTR " ", | |
9200 | MAC2STR(entry->aa)); | |
9201 | if (os_snprintf_error(end - pos2, ret)) | |
9202 | break; | |
9203 | pos2 += ret; | |
9204 | ||
9205 | pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid, | |
9206 | PMKID_LEN); | |
9207 | ||
9208 | ret = os_snprintf(pos2, end - pos2, " "); | |
9209 | if (os_snprintf_error(end - pos2, ret)) | |
9210 | break; | |
9211 | pos2 += ret; | |
9212 | ||
9213 | pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk, | |
9214 | entry->pmk_len); | |
9215 | ||
9216 | ret = os_snprintf(pos2, end - pos2, " %d %d %d %d", | |
9217 | (int) (entry->reauth_time - now.sec), | |
9218 | (int) (entry->expiration - now.sec), | |
9219 | entry->akmp, | |
9220 | entry->opportunistic); | |
9221 | if (os_snprintf_error(end - pos2, ret)) | |
9222 | break; | |
9223 | pos2 += ret; | |
9224 | ||
b7286c1b JM |
9225 | if (entry->fils_cache_id_set) { |
9226 | ret = os_snprintf(pos2, end - pos2, " %02x%02x", | |
9227 | entry->fils_cache_id[0], | |
9228 | entry->fils_cache_id[1]); | |
9229 | if (os_snprintf_error(end - pos2, ret)) | |
9230 | break; | |
9231 | pos2 += ret; | |
9232 | } | |
9233 | ||
3459381d JM |
9234 | ret = os_snprintf(pos2, end - pos2, "\n"); |
9235 | if (os_snprintf_error(end - pos2, ret)) | |
9236 | break; | |
9237 | pos2 += ret; | |
9238 | ||
9239 | pos = pos2; | |
9240 | } | |
9241 | ||
9242 | return pos - buf; | |
9243 | } | |
9244 | ||
9245 | ||
9246 | static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s, | |
9247 | char *cmd) | |
9248 | { | |
9249 | struct rsn_pmksa_cache_entry *entry; | |
9250 | struct wpa_ssid *ssid; | |
9251 | char *pos, *pos2; | |
9252 | int ret = -1; | |
9253 | struct os_reltime now; | |
b7286c1b | 9254 | int reauth_time = 0, expiration = 0, i; |
3459381d JM |
9255 | |
9256 | /* | |
9257 | * Entry format: | |
9258 | * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds> | |
9259 | * <expiration in seconds> <akmp> <opportunistic> | |
b7286c1b | 9260 | * [FILS Cache Identifier] |
3459381d JM |
9261 | */ |
9262 | ||
9263 | ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd)); | |
9264 | if (!ssid) | |
9265 | return -1; | |
9266 | ||
9267 | pos = os_strchr(cmd, ' '); | |
9268 | if (!pos) | |
9269 | return -1; | |
9270 | pos++; | |
9271 | ||
9272 | entry = os_zalloc(sizeof(*entry)); | |
9273 | if (!entry) | |
9274 | return -1; | |
9275 | ||
9276 | if (hwaddr_aton(pos, entry->aa)) | |
9277 | goto fail; | |
9278 | ||
9279 | pos = os_strchr(pos, ' '); | |
9280 | if (!pos) | |
9281 | goto fail; | |
9282 | pos++; | |
9283 | ||
9284 | if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0) | |
9285 | goto fail; | |
9286 | ||
9287 | pos = os_strchr(pos, ' '); | |
9288 | if (!pos) | |
9289 | goto fail; | |
9290 | pos++; | |
9291 | ||
9292 | pos2 = os_strchr(pos, ' '); | |
9293 | if (!pos2) | |
9294 | goto fail; | |
9295 | entry->pmk_len = (pos2 - pos) / 2; | |
9296 | if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX || | |
9297 | hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0) | |
9298 | goto fail; | |
9299 | ||
9300 | pos = os_strchr(pos, ' '); | |
9301 | if (!pos) | |
9302 | goto fail; | |
9303 | pos++; | |
9304 | ||
9305 | if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration, | |
9306 | &entry->akmp, &entry->opportunistic) != 4) | |
9307 | goto fail; | |
b7286c1b JM |
9308 | for (i = 0; i < 4; i++) { |
9309 | pos = os_strchr(pos, ' '); | |
9310 | if (!pos) { | |
9311 | if (i < 3) | |
9312 | goto fail; | |
9313 | break; | |
9314 | } | |
9315 | pos++; | |
9316 | } | |
9317 | if (pos) { | |
9318 | if (hexstr2bin(pos, entry->fils_cache_id, | |
9319 | FILS_CACHE_ID_LEN) < 0) | |
9320 | goto fail; | |
9321 | entry->fils_cache_id_set = 1; | |
9322 | } | |
3459381d JM |
9323 | os_get_reltime(&now); |
9324 | entry->expiration = now.sec + expiration; | |
9325 | entry->reauth_time = now.sec + reauth_time; | |
9326 | ||
9327 | entry->network_ctx = ssid; | |
9328 | ||
9329 | wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry); | |
9330 | entry = NULL; | |
9331 | ret = 0; | |
9332 | fail: | |
9333 | os_free(entry); | |
9334 | return ret; | |
9335 | } | |
9336 | ||
4d77d80e MH |
9337 | |
9338 | #ifdef CONFIG_MESH | |
9339 | ||
9340 | static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s, | |
9341 | const char *cmd, char *buf, | |
9342 | size_t buflen) | |
9343 | { | |
9344 | u8 spa[ETH_ALEN]; | |
9345 | ||
9346 | if (!wpa_s->ifmsh) | |
9347 | return -1; | |
9348 | ||
9349 | if (os_strcasecmp(cmd, "any") == 0) | |
9350 | return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen); | |
9351 | ||
9352 | if (hwaddr_aton(cmd, spa)) | |
9353 | return -1; | |
9354 | ||
9355 | return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen); | |
9356 | } | |
9357 | ||
9358 | ||
9359 | static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s, | |
9360 | char *cmd) | |
9361 | { | |
9362 | /* | |
9363 | * We do not check mesh interface existance because PMKSA should be | |
9364 | * stored before wpa_s->ifmsh creation to suppress commit message | |
9365 | * creation. | |
9366 | */ | |
9367 | return wpas_ap_pmksa_cache_add_external(wpa_s, cmd); | |
9368 | } | |
9369 | ||
9370 | #endif /* CONFIG_MESH */ | |
3459381d JM |
9371 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
9372 | ||
9373 | ||
5732b770 JM |
9374 | #ifdef CONFIG_FILS |
9375 | static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s, | |
9376 | const char *cmd) | |
9377 | { | |
9378 | struct fils_hlp_req *req; | |
9379 | const char *pos; | |
9380 | ||
9381 | /* format: <dst> <packet starting from ethertype> */ | |
9382 | ||
9383 | req = os_zalloc(sizeof(*req)); | |
9384 | if (!req) | |
9385 | return -1; | |
9386 | ||
9387 | if (hwaddr_aton(cmd, req->dst)) | |
9388 | goto fail; | |
9389 | ||
9390 | pos = os_strchr(cmd, ' '); | |
9391 | if (!pos) | |
9392 | goto fail; | |
9393 | pos++; | |
9394 | req->pkt = wpabuf_parse_bin(pos); | |
9395 | if (!req->pkt) | |
9396 | goto fail; | |
9397 | ||
9398 | dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list); | |
9399 | return 0; | |
9400 | fail: | |
9401 | wpabuf_free(req->pkt); | |
9402 | os_free(req); | |
9403 | return -1; | |
9404 | } | |
9405 | #endif /* CONFIG_FILS */ | |
9406 | ||
9407 | ||
8db9a79d JM |
9408 | static int wpas_ctrl_cmd_debug_level(const char *cmd) |
9409 | { | |
9410 | if (os_strcmp(cmd, "PING") == 0 || | |
9411 | os_strncmp(cmd, "BSS ", 4) == 0 || | |
9412 | os_strncmp(cmd, "GET_NETWORK ", 12) == 0 || | |
9413 | os_strncmp(cmd, "STATUS", 6) == 0 || | |
9414 | os_strncmp(cmd, "STA ", 4) == 0 || | |
9415 | os_strncmp(cmd, "STA-", 4) == 0) | |
9416 | return MSG_EXCESSIVE; | |
9417 | return MSG_DEBUG; | |
9418 | } | |
9419 | ||
9420 | ||
6fc6879b JM |
9421 | char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, |
9422 | char *buf, size_t *resp_len) | |
9423 | { | |
9424 | char *reply; | |
b563b388 | 9425 | const int reply_size = 4096; |
6fc6879b JM |
9426 | int reply_len; |
9427 | ||
9428 | if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 || | |
d31b5ac7 JM |
9429 | os_strncmp(buf, "SET_NETWORK ", 12) == 0) { |
9430 | if (wpa_debug_show_keys) | |
9431 | wpa_dbg(wpa_s, MSG_DEBUG, | |
9432 | "Control interface command '%s'", buf); | |
9433 | else | |
9434 | wpa_dbg(wpa_s, MSG_DEBUG, | |
9435 | "Control interface command '%s [REMOVED]'", | |
9436 | os_strncmp(buf, WPA_CTRL_RSP, | |
9437 | os_strlen(WPA_CTRL_RSP)) == 0 ? | |
9438 | WPA_CTRL_RSP : "SET_NETWORK"); | |
9439 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 || | |
679f2e7c | 9440 | os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) { |
6fc6879b JM |
9441 | wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", |
9442 | (const u8 *) buf, os_strlen(buf)); | |
9443 | } else { | |
8db9a79d | 9444 | int level = wpas_ctrl_cmd_debug_level(buf); |
b470b2bf | 9445 | wpa_dbg(wpa_s, level, "Control interface command '%s'", buf); |
6fc6879b JM |
9446 | } |
9447 | ||
9448 | reply = os_malloc(reply_size); | |
9449 | if (reply == NULL) { | |
9450 | *resp_len = 1; | |
9451 | return NULL; | |
9452 | } | |
9453 | ||
9454 | os_memcpy(reply, "OK\n", 3); | |
9455 | reply_len = 3; | |
9456 | ||
9457 | if (os_strcmp(buf, "PING") == 0) { | |
9458 | os_memcpy(reply, "PONG\n", 5); | |
9459 | reply_len = 5; | |
0eed2a8d JD |
9460 | } else if (os_strcmp(buf, "IFNAME") == 0) { |
9461 | reply_len = os_strlen(wpa_s->ifname); | |
9462 | os_memcpy(reply, wpa_s->ifname, reply_len); | |
ac6912b5 BG |
9463 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
9464 | if (wpa_debug_reopen_file() < 0) | |
9465 | reply_len = -1; | |
77895cd9 JM |
9466 | } else if (os_strncmp(buf, "NOTE ", 5) == 0) { |
9467 | wpa_printf(MSG_INFO, "NOTE: %s", buf + 5); | |
6fc6879b JM |
9468 | } else if (os_strcmp(buf, "MIB") == 0) { |
9469 | reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); | |
9470 | if (reply_len >= 0) { | |
5ac73acf JM |
9471 | reply_len += eapol_sm_get_mib(wpa_s->eapol, |
9472 | reply + reply_len, | |
9473 | reply_size - reply_len); | |
6fc6879b JM |
9474 | } |
9475 | } else if (os_strncmp(buf, "STATUS", 6) == 0) { | |
9476 | reply_len = wpa_supplicant_ctrl_iface_status( | |
9477 | wpa_s, buf + 6, reply, reply_size); | |
9478 | } else if (os_strcmp(buf, "PMKSA") == 0) { | |
b8daac18 | 9479 | reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size); |
79e2b1cc | 9480 | } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) { |
4c522c77 | 9481 | wpas_ctrl_iface_pmksa_flush(wpa_s); |
3459381d JM |
9482 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
9483 | } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) { | |
9484 | reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10, | |
9485 | reply, reply_size); | |
9486 | } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) { | |
9487 | if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0) | |
9488 | reply_len = -1; | |
4d77d80e MH |
9489 | #ifdef CONFIG_MESH |
9490 | } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) { | |
9491 | reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15, | |
9492 | reply, reply_size); | |
9493 | } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) { | |
9494 | if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0) | |
9495 | reply_len = -1; | |
9496 | #endif /* CONFIG_MESH */ | |
3459381d | 9497 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
6fc6879b JM |
9498 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
9499 | if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) | |
9500 | reply_len = -1; | |
10263dc2 OO |
9501 | } else if (os_strncmp(buf, "DUMP", 4) == 0) { |
9502 | reply_len = wpa_config_dump_values(wpa_s->conf, | |
9503 | reply, reply_size); | |
acec8d32 JM |
9504 | } else if (os_strncmp(buf, "GET ", 4) == 0) { |
9505 | reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4, | |
9506 | reply, reply_size); | |
6fc6879b JM |
9507 | } else if (os_strcmp(buf, "LOGON") == 0) { |
9508 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); | |
9509 | } else if (os_strcmp(buf, "LOGOFF") == 0) { | |
9510 | eapol_sm_notify_logoff(wpa_s->eapol, TRUE); | |
9511 | } else if (os_strcmp(buf, "REASSOCIATE") == 0) { | |
8401a6b0 JM |
9512 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
9513 | reply_len = -1; | |
9796a86c JM |
9514 | else |
9515 | wpas_request_connection(wpa_s); | |
0f44ec8e PQ |
9516 | } else if (os_strcmp(buf, "REATTACH") == 0) { |
9517 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED || | |
9518 | !wpa_s->current_ssid) | |
9519 | reply_len = -1; | |
9520 | else { | |
9521 | wpa_s->reattach = 1; | |
9522 | wpas_request_connection(wpa_s); | |
9523 | } | |
6fc6879b | 9524 | } else if (os_strcmp(buf, "RECONNECT") == 0) { |
8401a6b0 JM |
9525 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
9526 | reply_len = -1; | |
9796a86c JM |
9527 | else if (wpa_s->disconnected) |
9528 | wpas_request_connection(wpa_s); | |
ec717917 | 9529 | #ifdef IEEE8021X_EAPOL |
6fc6879b JM |
9530 | } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { |
9531 | if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) | |
9532 | reply_len = -1; | |
ec717917 | 9533 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
9534 | #ifdef CONFIG_PEERKEY |
9535 | } else if (os_strncmp(buf, "STKSTART ", 9) == 0) { | |
9536 | if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9)) | |
9537 | reply_len = -1; | |
9538 | #endif /* CONFIG_PEERKEY */ | |
9539 | #ifdef CONFIG_IEEE80211R | |
9540 | } else if (os_strncmp(buf, "FT_DS ", 6) == 0) { | |
9541 | if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6)) | |
9542 | reply_len = -1; | |
9543 | #endif /* CONFIG_IEEE80211R */ | |
fcc60db4 JM |
9544 | #ifdef CONFIG_WPS |
9545 | } else if (os_strcmp(buf, "WPS_PBC") == 0) { | |
3152ff42 CWY |
9546 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL); |
9547 | if (res == -2) { | |
9548 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
9549 | reply_len = 17; | |
9550 | } else if (res) | |
fcc60db4 JM |
9551 | reply_len = -1; |
9552 | } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) { | |
3152ff42 CWY |
9553 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8); |
9554 | if (res == -2) { | |
9555 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
9556 | reply_len = 17; | |
9557 | } else if (res) | |
fcc60db4 JM |
9558 | reply_len = -1; |
9559 | } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) { | |
9560 | reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8, | |
9561 | reply, | |
9562 | reply_size); | |
3981cb3c JM |
9563 | } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) { |
9564 | reply_len = wpa_supplicant_ctrl_iface_wps_check_pin( | |
9565 | wpa_s, buf + 14, reply, reply_size); | |
2f9929ff AC |
9566 | } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { |
9567 | if (wpas_wps_cancel(wpa_s)) | |
9568 | reply_len = -1; | |
71892384 | 9569 | #ifdef CONFIG_WPS_NFC |
3f2c8ba6 JM |
9570 | } else if (os_strcmp(buf, "WPS_NFC") == 0) { |
9571 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL)) | |
9572 | reply_len = -1; | |
9573 | } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) { | |
9574 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8)) | |
9575 | reply_len = -1; | |
bbf41865 JM |
9576 | } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) { |
9577 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token( | |
9578 | wpa_s, buf + 21, reply, reply_size); | |
3f2c8ba6 JM |
9579 | } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) { |
9580 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token( | |
9581 | wpa_s, buf + 14, reply, reply_size); | |
d7645d23 JM |
9582 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) { |
9583 | if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s, | |
9584 | buf + 17)) | |
9585 | reply_len = -1; | |
e65552dd JM |
9586 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) { |
9587 | reply_len = wpas_ctrl_nfc_get_handover_req( | |
9588 | wpa_s, buf + 21, reply, reply_size); | |
9589 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) { | |
9590 | reply_len = wpas_ctrl_nfc_get_handover_sel( | |
9591 | wpa_s, buf + 21, reply, reply_size); | |
e4758827 JM |
9592 | } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) { |
9593 | if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20)) | |
9594 | reply_len = -1; | |
71892384 | 9595 | #endif /* CONFIG_WPS_NFC */ |
fcc60db4 JM |
9596 | } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) { |
9597 | if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8)) | |
9598 | reply_len = -1; | |
70d84f11 JM |
9599 | #ifdef CONFIG_AP |
9600 | } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) { | |
9601 | reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin( | |
9602 | wpa_s, buf + 11, reply, reply_size); | |
9603 | #endif /* CONFIG_AP */ | |
72df2f5f | 9604 | #ifdef CONFIG_WPS_ER |
e9bcfebf | 9605 | } else if (os_strcmp(buf, "WPS_ER_START") == 0) { |
08486685 JM |
9606 | if (wpas_wps_er_start(wpa_s, NULL)) |
9607 | reply_len = -1; | |
9608 | } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) { | |
9609 | if (wpas_wps_er_start(wpa_s, buf + 13)) | |
e9bcfebf JM |
9610 | reply_len = -1; |
9611 | } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) { | |
f77cedc1 | 9612 | wpas_wps_er_stop(wpa_s); |
72df2f5f JM |
9613 | } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) { |
9614 | if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11)) | |
9615 | reply_len = -1; | |
564cd7fa | 9616 | } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) { |
ed159ad4 JM |
9617 | int ret = wpas_wps_er_pbc(wpa_s, buf + 11); |
9618 | if (ret == -2) { | |
9619 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | |
9620 | reply_len = 17; | |
9621 | } else if (ret == -3) { | |
9622 | os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18); | |
9623 | reply_len = 18; | |
9624 | } else if (ret == -4) { | |
9625 | os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20); | |
9626 | reply_len = 20; | |
9627 | } else if (ret) | |
564cd7fa | 9628 | reply_len = -1; |
e64dcfd5 JM |
9629 | } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) { |
9630 | if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13)) | |
9631 | reply_len = -1; | |
ef10f473 JM |
9632 | } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) { |
9633 | if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s, | |
9634 | buf + 18)) | |
9635 | reply_len = -1; | |
7d6640a6 JM |
9636 | } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) { |
9637 | if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14)) | |
9638 | reply_len = -1; | |
1cea09a9 JM |
9639 | #ifdef CONFIG_WPS_NFC |
9640 | } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) { | |
9641 | reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | |
9642 | wpa_s, buf + 24, reply, reply_size); | |
9643 | #endif /* CONFIG_WPS_NFC */ | |
72df2f5f | 9644 | #endif /* CONFIG_WPS_ER */ |
fcc60db4 | 9645 | #endif /* CONFIG_WPS */ |
11ef8d35 JM |
9646 | #ifdef CONFIG_IBSS_RSN |
9647 | } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) { | |
9648 | if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) | |
9649 | reply_len = -1; | |
9650 | #endif /* CONFIG_IBSS_RSN */ | |
603a3f34 | 9651 | #ifdef CONFIG_MESH |
5b78493f MH |
9652 | } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) { |
9653 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( | |
9654 | wpa_s, buf + 19, reply, reply_size); | |
9655 | } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) { | |
9656 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( | |
9657 | wpa_s, "", reply, reply_size); | |
603a3f34 JL |
9658 | } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) { |
9659 | if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15)) | |
9660 | reply_len = -1; | |
9661 | } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) { | |
9662 | if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s, | |
9663 | buf + 18)) | |
9664 | reply_len = -1; | |
e174ef34 MH |
9665 | } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) { |
9666 | if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17)) | |
9667 | reply_len = -1; | |
2604edbf MH |
9668 | } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) { |
9669 | if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14)) | |
9670 | reply_len = -1; | |
603a3f34 | 9671 | #endif /* CONFIG_MESH */ |
b563b388 JM |
9672 | #ifdef CONFIG_P2P |
9673 | } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { | |
51775096 | 9674 | if (p2p_ctrl_find(wpa_s, buf + 8)) |
b563b388 JM |
9675 | reply_len = -1; |
9676 | } else if (os_strcmp(buf, "P2P_FIND") == 0) { | |
9677 | if (p2p_ctrl_find(wpa_s, "")) | |
9678 | reply_len = -1; | |
9679 | } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) { | |
9680 | wpas_p2p_stop_find(wpa_s); | |
f309c18e KV |
9681 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) { |
9682 | if (p2p_ctrl_asp_provision(wpa_s, buf + 18)) | |
9683 | reply_len = -1; | |
9684 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) { | |
9685 | if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23)) | |
9686 | reply_len = -1; | |
b563b388 JM |
9687 | } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) { |
9688 | reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply, | |
9689 | reply_size); | |
9690 | } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) { | |
9691 | if (p2p_ctrl_listen(wpa_s, buf + 11)) | |
9692 | reply_len = -1; | |
9693 | } else if (os_strcmp(buf, "P2P_LISTEN") == 0) { | |
9694 | if (p2p_ctrl_listen(wpa_s, "")) | |
9695 | reply_len = -1; | |
9696 | } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) { | |
9697 | if (wpas_p2p_group_remove(wpa_s, buf + 17)) | |
9698 | reply_len = -1; | |
9699 | } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) { | |
38dcc86c | 9700 | if (p2p_ctrl_group_add(wpa_s, "")) |
b563b388 JM |
9701 | reply_len = -1; |
9702 | } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) { | |
9703 | if (p2p_ctrl_group_add(wpa_s, buf + 14)) | |
9704 | reply_len = -1; | |
57b38882 PK |
9705 | } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) { |
9706 | reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply, | |
9707 | reply_size); | |
b563b388 JM |
9708 | } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) { |
9709 | if (p2p_ctrl_prov_disc(wpa_s, buf + 14)) | |
9710 | reply_len = -1; | |
9711 | } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) { | |
9712 | reply_len = p2p_get_passphrase(wpa_s, reply, reply_size); | |
9713 | } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) { | |
9714 | reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply, | |
9715 | reply_size); | |
9716 | } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) { | |
9717 | if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0) | |
9718 | reply_len = -1; | |
9719 | } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) { | |
9720 | if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0) | |
9721 | reply_len = -1; | |
9722 | } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) { | |
9723 | wpas_p2p_sd_service_update(wpa_s); | |
9724 | } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) { | |
9725 | if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0) | |
9726 | reply_len = -1; | |
9727 | } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) { | |
9728 | wpas_p2p_service_flush(wpa_s); | |
9729 | } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) { | |
9730 | if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0) | |
9731 | reply_len = -1; | |
9732 | } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) { | |
9733 | if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0) | |
9734 | reply_len = -1; | |
ae9d45f3 KV |
9735 | } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) { |
9736 | if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0) | |
9737 | reply_len = -1; | |
b563b388 JM |
9738 | } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) { |
9739 | if (p2p_ctrl_reject(wpa_s, buf + 11) < 0) | |
9740 | reply_len = -1; | |
9741 | } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) { | |
9742 | if (p2p_ctrl_invite(wpa_s, buf + 11) < 0) | |
9743 | reply_len = -1; | |
9744 | } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) { | |
9745 | reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply, | |
9746 | reply_size); | |
9747 | } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) { | |
9748 | if (p2p_ctrl_set(wpa_s, buf + 8) < 0) | |
9749 | reply_len = -1; | |
9750 | } else if (os_strcmp(buf, "P2P_FLUSH") == 0) { | |
acb54643 | 9751 | p2p_ctrl_flush(wpa_s); |
9d562b79 SS |
9752 | } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { |
9753 | if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) | |
9754 | reply_len = -1; | |
59eba7a2 JM |
9755 | } else if (os_strcmp(buf, "P2P_CANCEL") == 0) { |
9756 | if (wpas_p2p_cancel(wpa_s)) | |
9757 | reply_len = -1; | |
b563b388 JM |
9758 | } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) { |
9759 | if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0) | |
9760 | reply_len = -1; | |
9761 | } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) { | |
9762 | if (p2p_ctrl_presence_req(wpa_s, "") < 0) | |
9763 | reply_len = -1; | |
9764 | } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) { | |
9765 | if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0) | |
9766 | reply_len = -1; | |
9767 | } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) { | |
9768 | if (p2p_ctrl_ext_listen(wpa_s, "") < 0) | |
9769 | reply_len = -1; | |
f2c56602 JM |
9770 | } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) { |
9771 | if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0) | |
9772 | reply_len = -1; | |
a6f5b193 PX |
9773 | } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) { |
9774 | if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13)) | |
9775 | reply_len = -1; | |
9776 | } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) { | |
9777 | if (wpas_p2p_lo_stop(wpa_s)) | |
9778 | reply_len = -1; | |
b563b388 | 9779 | #endif /* CONFIG_P2P */ |
9675ce35 JM |
9780 | #ifdef CONFIG_WIFI_DISPLAY |
9781 | } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) { | |
9782 | if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0) | |
9783 | reply_len = -1; | |
9784 | } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) { | |
9785 | reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16, | |
9786 | reply, reply_size); | |
9787 | #endif /* CONFIG_WIFI_DISPLAY */ | |
afc064fe JM |
9788 | #ifdef CONFIG_INTERWORKING |
9789 | } else if (os_strcmp(buf, "FETCH_ANQP") == 0) { | |
9790 | if (interworking_fetch_anqp(wpa_s) < 0) | |
9791 | reply_len = -1; | |
9792 | } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) { | |
9793 | interworking_stop_fetch_anqp(wpa_s); | |
356d1488 JM |
9794 | } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) { |
9795 | if (ctrl_interworking_select(wpa_s, NULL) < 0) | |
9796 | reply_len = -1; | |
9797 | } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) { | |
9798 | if (ctrl_interworking_select(wpa_s, buf + 20) < 0) | |
b02fe7ff JM |
9799 | reply_len = -1; |
9800 | } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) { | |
f91a512f | 9801 | if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0) |
b02fe7ff | 9802 | reply_len = -1; |
f91a512f JM |
9803 | } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) { |
9804 | int id; | |
9805 | ||
9806 | id = ctrl_interworking_connect(wpa_s, buf + 25, 1); | |
9807 | if (id < 0) | |
9808 | reply_len = -1; | |
9809 | else { | |
9810 | reply_len = os_snprintf(reply, reply_size, "%d\n", id); | |
9811 | if (os_snprintf_error(reply_size, reply_len)) | |
9812 | reply_len = -1; | |
9813 | } | |
afc064fe JM |
9814 | } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) { |
9815 | if (get_anqp(wpa_s, buf + 9) < 0) | |
9816 | reply_len = -1; | |
b1f12296 JM |
9817 | } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) { |
9818 | if (gas_request(wpa_s, buf + 12) < 0) | |
9819 | reply_len = -1; | |
9820 | } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) { | |
9821 | reply_len = gas_response_get(wpa_s, buf + 17, reply, | |
9822 | reply_size); | |
afc064fe | 9823 | #endif /* CONFIG_INTERWORKING */ |
a8918e86 JK |
9824 | #ifdef CONFIG_HS20 |
9825 | } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) { | |
9826 | if (get_hs20_anqp(wpa_s, buf + 14) < 0) | |
9827 | reply_len = -1; | |
9828 | } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) { | |
9829 | if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0) | |
9830 | reply_len = -1; | |
184e110c | 9831 | } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) { |
8dd5c1b4 JN |
9832 | if (hs20_icon_request(wpa_s, buf + 18, 0) < 0) |
9833 | reply_len = -1; | |
9834 | } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) { | |
9835 | if (hs20_icon_request(wpa_s, buf + 14, 1) < 0) | |
9836 | reply_len = -1; | |
9837 | } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) { | |
9838 | reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size); | |
9839 | } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) { | |
9840 | if (del_hs20_icon(wpa_s, buf + 14) < 0) | |
184e110c | 9841 | reply_len = -1; |
b572df86 | 9842 | } else if (os_strcmp(buf, "FETCH_OSU") == 0) { |
dd20eabd JM |
9843 | if (hs20_fetch_osu(wpa_s, 0) < 0) |
9844 | reply_len = -1; | |
9845 | } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) { | |
9846 | if (hs20_fetch_osu(wpa_s, 1) < 0) | |
b572df86 JM |
9847 | reply_len = -1; |
9848 | } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) { | |
9849 | hs20_cancel_fetch_osu(wpa_s); | |
a8918e86 | 9850 | #endif /* CONFIG_HS20 */ |
6fc6879b JM |
9851 | } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) |
9852 | { | |
9853 | if (wpa_supplicant_ctrl_iface_ctrl_rsp( | |
9854 | wpa_s, buf + os_strlen(WPA_CTRL_RSP))) | |
9855 | reply_len = -1; | |
bceb8431 JM |
9856 | else { |
9857 | /* | |
9858 | * Notify response from timeout to allow the control | |
9859 | * interface response to be sent first. | |
9860 | */ | |
9861 | eloop_register_timeout(0, 0, wpas_ctrl_eapol_response, | |
9862 | wpa_s, NULL); | |
9863 | } | |
6fc6879b JM |
9864 | } else if (os_strcmp(buf, "RECONFIGURE") == 0) { |
9865 | if (wpa_supplicant_reload_configuration(wpa_s)) | |
9866 | reply_len = -1; | |
9867 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | |
1a1bf008 | 9868 | wpa_supplicant_terminate_proc(wpa_s->global); |
6fc6879b JM |
9869 | } else if (os_strncmp(buf, "BSSID ", 6) == 0) { |
9870 | if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) | |
9871 | reply_len = -1; | |
9aa10e2b DS |
9872 | } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) { |
9873 | reply_len = wpa_supplicant_ctrl_iface_blacklist( | |
9874 | wpa_s, buf + 9, reply, reply_size); | |
0597a5b5 DS |
9875 | } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) { |
9876 | reply_len = wpa_supplicant_ctrl_iface_log_level( | |
9877 | wpa_s, buf + 9, reply, reply_size); | |
90903a77 VD |
9878 | } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) { |
9879 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | |
9880 | wpa_s, buf + 14, reply, reply_size); | |
6fc6879b JM |
9881 | } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { |
9882 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | |
90903a77 | 9883 | wpa_s, NULL, reply, reply_size); |
6fc6879b | 9884 | } else if (os_strcmp(buf, "DISCONNECT") == 0) { |
5f040be4 | 9885 | wpas_request_disconnection(wpa_s); |
fee52342 JM |
9886 | } else if (os_strcmp(buf, "SCAN") == 0) { |
9887 | wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len); | |
9888 | } else if (os_strncmp(buf, "SCAN ", 5) == 0) { | |
9889 | wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len); | |
6fc6879b JM |
9890 | } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { |
9891 | reply_len = wpa_supplicant_ctrl_iface_scan_results( | |
9892 | wpa_s, reply, reply_size); | |
2ea2166d JM |
9893 | } else if (os_strcmp(buf, "ABORT_SCAN") == 0) { |
9894 | if (wpas_abort_ongoing_scan(wpa_s) < 0) | |
9895 | reply_len = -1; | |
6fc6879b JM |
9896 | } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { |
9897 | if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) | |
9898 | reply_len = -1; | |
9899 | } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { | |
9900 | if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) | |
9901 | reply_len = -1; | |
9902 | } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { | |
9903 | if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) | |
9904 | reply_len = -1; | |
9905 | } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { | |
9906 | reply_len = wpa_supplicant_ctrl_iface_add_network( | |
9907 | wpa_s, reply, reply_size); | |
9908 | } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { | |
9909 | if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) | |
9910 | reply_len = -1; | |
9911 | } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { | |
9912 | if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) | |
9913 | reply_len = -1; | |
9914 | } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { | |
9915 | reply_len = wpa_supplicant_ctrl_iface_get_network( | |
9916 | wpa_s, buf + 12, reply, reply_size); | |
1c330a2f | 9917 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
daae4995 AN |
9918 | if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12, |
9919 | wpa_s)) | |
1c330a2f | 9920 | reply_len = -1; |
d94c9ee6 JM |
9921 | } else if (os_strcmp(buf, "LIST_CREDS") == 0) { |
9922 | reply_len = wpa_supplicant_ctrl_iface_list_creds( | |
9923 | wpa_s, reply, reply_size); | |
9924 | } else if (os_strcmp(buf, "ADD_CRED") == 0) { | |
9925 | reply_len = wpa_supplicant_ctrl_iface_add_cred( | |
9926 | wpa_s, reply, reply_size); | |
9927 | } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) { | |
9928 | if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12)) | |
9929 | reply_len = -1; | |
9930 | } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) { | |
9931 | if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9)) | |
9932 | reply_len = -1; | |
c880ab87 JM |
9933 | } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) { |
9934 | reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9, | |
9935 | reply, | |
9936 | reply_size); | |
6fc6879b JM |
9937 | #ifndef CONFIG_NO_CONFIG_WRITE |
9938 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | |
9939 | if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) | |
9940 | reply_len = -1; | |
9941 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
9942 | } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { | |
9943 | reply_len = wpa_supplicant_ctrl_iface_get_capability( | |
9944 | wpa_s, buf + 15, reply, reply_size); | |
9945 | } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { | |
9946 | if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) | |
9947 | reply_len = -1; | |
67b9bd08 DS |
9948 | } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) { |
9949 | if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14)) | |
9950 | reply_len = -1; | |
4b4a8ae5 JM |
9951 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
9952 | reply_len = wpa_supplicant_global_iface_list( | |
9953 | wpa_s->global, reply, reply_size); | |
56e2fc2c | 9954 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { |
6fc6879b | 9955 | reply_len = wpa_supplicant_global_iface_interfaces( |
56e2fc2c | 9956 | wpa_s->global, buf + 10, reply, reply_size); |
6fc6879b JM |
9957 | } else if (os_strncmp(buf, "BSS ", 4) == 0) { |
9958 | reply_len = wpa_supplicant_ctrl_iface_bss( | |
9959 | wpa_s, buf + 4, reply, reply_size); | |
e653b622 JM |
9960 | #ifdef CONFIG_AP |
9961 | } else if (os_strcmp(buf, "STA-FIRST") == 0) { | |
9962 | reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size); | |
9963 | } else if (os_strncmp(buf, "STA ", 4) == 0) { | |
9964 | reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply, | |
9965 | reply_size); | |
9966 | } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { | |
9967 | reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply, | |
9968 | reply_size); | |
e60b2951 JJ |
9969 | } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) { |
9970 | if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15)) | |
9971 | reply_len = -1; | |
9972 | } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) { | |
9973 | if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13)) | |
9974 | reply_len = -1; | |
334bf36a AO |
9975 | } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) { |
9976 | if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12)) | |
9977 | reply_len = -1; | |
99650cad JM |
9978 | } else if (os_strcmp(buf, "STOP_AP") == 0) { |
9979 | if (wpas_ap_stop_ap(wpa_s)) | |
9980 | reply_len = -1; | |
e653b622 | 9981 | #endif /* CONFIG_AP */ |
207ef3fb JM |
9982 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
9983 | wpas_notify_suspend(wpa_s->global); | |
9984 | } else if (os_strcmp(buf, "RESUME") == 0) { | |
9985 | wpas_notify_resume(wpa_s->global); | |
9ff4de6d | 9986 | #ifdef CONFIG_TESTING_OPTIONS |
32d5295f JM |
9987 | } else if (os_strcmp(buf, "DROP_SA") == 0) { |
9988 | wpa_supplicant_ctrl_iface_drop_sa(wpa_s); | |
9ff4de6d | 9989 | #endif /* CONFIG_TESTING_OPTIONS */ |
86d4f806 JM |
9990 | } else if (os_strncmp(buf, "ROAM ", 5) == 0) { |
9991 | if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) | |
9992 | reply_len = -1; | |
0d0a8ca1 | 9993 | } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { |
5407c69d | 9994 | wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0; |
78633c37 SL |
9995 | } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) { |
9996 | if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15)) | |
9997 | reply_len = -1; | |
9998 | } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) { | |
9999 | if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s, | |
10000 | buf + 17)) | |
10001 | reply_len = -1; | |
39ee845f | 10002 | } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) { |
a1144000 | 10003 | wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10); |
281ff0aa GP |
10004 | #ifdef CONFIG_TDLS |
10005 | } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) { | |
10006 | if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14)) | |
10007 | reply_len = -1; | |
10008 | } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) { | |
10009 | if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11)) | |
10010 | reply_len = -1; | |
10011 | } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) { | |
10012 | if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14)) | |
10013 | reply_len = -1; | |
6b90deae AN |
10014 | } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) { |
10015 | if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s, | |
10016 | buf + 17)) | |
10017 | reply_len = -1; | |
10018 | } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) { | |
10019 | if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s, | |
10020 | buf + 24)) | |
10021 | reply_len = -1; | |
4504621f OG |
10022 | } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) { |
10023 | reply_len = wpa_supplicant_ctrl_iface_tdls_link_status( | |
10024 | wpa_s, buf + 17, reply, reply_size); | |
281ff0aa | 10025 | #endif /* CONFIG_TDLS */ |
8506ea6f MB |
10026 | } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) { |
10027 | reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size); | |
eb2f2088 MB |
10028 | } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) { |
10029 | if (wmm_ac_ctrl_addts(wpa_s, buf + 13)) | |
10030 | reply_len = -1; | |
10031 | } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) { | |
10032 | if (wmm_ac_ctrl_delts(wpa_s, buf + 13)) | |
10033 | reply_len = -1; | |
60b24b0d DS |
10034 | } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) { |
10035 | reply_len = wpa_supplicant_signal_poll(wpa_s, reply, | |
10036 | reply_size); | |
96e8d831 DS |
10037 | } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) { |
10038 | if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14)) | |
10039 | reply_len = -1; | |
dc7785f8 YZ |
10040 | } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) { |
10041 | reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply, | |
10042 | reply_size); | |
bc5d330a TB |
10043 | #ifdef CONFIG_AUTOSCAN |
10044 | } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) { | |
10045 | if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9)) | |
10046 | reply_len = -1; | |
10047 | #endif /* CONFIG_AUTOSCAN */ | |
4d7aab78 EL |
10048 | } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) { |
10049 | reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply, | |
10050 | reply_size); | |
5e2c3490 JM |
10051 | #ifdef ANDROID |
10052 | } else if (os_strncmp(buf, "DRIVER ", 7) == 0) { | |
10053 | reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply, | |
10054 | reply_size); | |
10055 | #endif /* ANDROID */ | |
adef8948 BL |
10056 | } else if (os_strncmp(buf, "VENDOR ", 7) == 0) { |
10057 | reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply, | |
10058 | reply_size); | |
9482426e | 10059 | } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) { |
f5f37d3a | 10060 | pmksa_cache_clear_current(wpa_s->wpa); |
9482426e | 10061 | eapol_sm_request_reauth(wpa_s->eapol); |
e9199e31 JM |
10062 | #ifdef CONFIG_WNM |
10063 | } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) { | |
10064 | if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10)) | |
10065 | reply_len = -1; | |
07565ab0 MG |
10066 | } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) { |
10067 | if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14)) | |
65bcd0a9 | 10068 | reply_len = -1; |
e9199e31 | 10069 | #endif /* CONFIG_WNM */ |
acb54643 JM |
10070 | } else if (os_strcmp(buf, "FLUSH") == 0) { |
10071 | wpa_supplicant_ctrl_iface_flush(wpa_s); | |
1f965e62 JM |
10072 | } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) { |
10073 | reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply, | |
10074 | reply_size); | |
60b893df JM |
10075 | #ifdef CONFIG_TESTING_OPTIONS |
10076 | } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) { | |
10077 | if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0) | |
10078 | reply_len = -1; | |
10079 | } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) { | |
10080 | wpas_ctrl_iface_mgmt_tx_done(wpa_s); | |
4de70e23 JM |
10081 | } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) { |
10082 | if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0) | |
10083 | reply_len = -1; | |
ad12f2f4 JM |
10084 | } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) { |
10085 | if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0) | |
10086 | reply_len = -1; | |
9d4ff04a JM |
10087 | } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) { |
10088 | if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0) | |
10089 | reply_len = -1; | |
4a6cc862 JM |
10090 | } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) { |
10091 | if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0) | |
10092 | reply_len = -1; | |
10093 | } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) { | |
10094 | if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0) | |
10095 | reply_len = -1; | |
fc0ef7c0 JM |
10096 | } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) { |
10097 | if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0) | |
10098 | reply_len = -1; | |
a156ffda JM |
10099 | } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) { |
10100 | if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0) | |
10101 | reply_len = -1; | |
10102 | } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) { | |
10103 | reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size); | |
2da52565 JM |
10104 | } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) { |
10105 | if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0) | |
10106 | reply_len = -1; | |
10107 | } else if (os_strcmp(buf, "GET_FAIL") == 0) { | |
10108 | reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size); | |
a530fe77 JM |
10109 | } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) { |
10110 | if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0) | |
10111 | reply_len = -1; | |
651c6a84 JM |
10112 | } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) { |
10113 | if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0) | |
10114 | reply_len = -1; | |
60b893df | 10115 | #endif /* CONFIG_TESTING_OPTIONS */ |
86bd36f0 JM |
10116 | } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) { |
10117 | if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0) | |
10118 | reply_len = -1; | |
10119 | } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) { | |
10120 | reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply, | |
10121 | reply_size); | |
10122 | } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) { | |
10123 | if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0) | |
10124 | reply_len = -1; | |
f4b8bfae | 10125 | } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) { |
6a4f0ed7 | 10126 | if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20)) |
f4b8bfae | 10127 | reply_len = -1; |
65d9a5e2 JM |
10128 | } else if (os_strcmp(buf, "ERP_FLUSH") == 0) { |
10129 | wpas_ctrl_iface_erp_flush(wpa_s); | |
fb375883 IP |
10130 | } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) { |
10131 | if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14)) | |
10132 | reply_len = -1; | |
98342208 AK |
10133 | } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) { |
10134 | reply_len = wpas_ctrl_iface_get_pref_freq_list( | |
10135 | wpa_s, buf + 19, reply, reply_size); | |
5732b770 JM |
10136 | #ifdef CONFIG_FILS |
10137 | } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) { | |
10138 | if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17)) | |
10139 | reply_len = -1; | |
10140 | } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) { | |
10141 | wpas_flush_fils_hlp_req(wpa_s); | |
10142 | #endif /* CONFIG_FILS */ | |
6fc6879b JM |
10143 | } else { |
10144 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | |
10145 | reply_len = 16; | |
10146 | } | |
10147 | ||
10148 | if (reply_len < 0) { | |
10149 | os_memcpy(reply, "FAIL\n", 5); | |
10150 | reply_len = 5; | |
10151 | } | |
10152 | ||
6fc6879b JM |
10153 | *resp_len = reply_len; |
10154 | return reply; | |
10155 | } | |
10156 | ||
10157 | ||
10158 | static int wpa_supplicant_global_iface_add(struct wpa_global *global, | |
10159 | char *cmd) | |
10160 | { | |
10161 | struct wpa_interface iface; | |
efa232f9 JJ |
10162 | char *pos, *extra; |
10163 | struct wpa_supplicant *wpa_s; | |
10164 | unsigned int create_iface = 0; | |
10165 | u8 mac_addr[ETH_ALEN]; | |
0f039e34 | 10166 | enum wpa_driver_if_type type = WPA_IF_STATION; |
6fc6879b JM |
10167 | |
10168 | /* | |
10169 | * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param> | |
0f039e34 | 10170 | * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]] |
6fc6879b JM |
10171 | */ |
10172 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd); | |
10173 | ||
10174 | os_memset(&iface, 0, sizeof(iface)); | |
10175 | ||
10176 | do { | |
10177 | iface.ifname = pos = cmd; | |
10178 | pos = os_strchr(pos, '\t'); | |
10179 | if (pos) | |
10180 | *pos++ = '\0'; | |
10181 | if (iface.ifname[0] == '\0') | |
10182 | return -1; | |
10183 | if (pos == NULL) | |
10184 | break; | |
10185 | ||
10186 | iface.confname = pos; | |
10187 | pos = os_strchr(pos, '\t'); | |
10188 | if (pos) | |
10189 | *pos++ = '\0'; | |
10190 | if (iface.confname[0] == '\0') | |
10191 | iface.confname = NULL; | |
10192 | if (pos == NULL) | |
10193 | break; | |
10194 | ||
10195 | iface.driver = pos; | |
10196 | pos = os_strchr(pos, '\t'); | |
10197 | if (pos) | |
10198 | *pos++ = '\0'; | |
10199 | if (iface.driver[0] == '\0') | |
10200 | iface.driver = NULL; | |
10201 | if (pos == NULL) | |
10202 | break; | |
10203 | ||
10204 | iface.ctrl_interface = pos; | |
10205 | pos = os_strchr(pos, '\t'); | |
10206 | if (pos) | |
10207 | *pos++ = '\0'; | |
10208 | if (iface.ctrl_interface[0] == '\0') | |
10209 | iface.ctrl_interface = NULL; | |
10210 | if (pos == NULL) | |
10211 | break; | |
10212 | ||
10213 | iface.driver_param = pos; | |
10214 | pos = os_strchr(pos, '\t'); | |
10215 | if (pos) | |
10216 | *pos++ = '\0'; | |
10217 | if (iface.driver_param[0] == '\0') | |
10218 | iface.driver_param = NULL; | |
10219 | if (pos == NULL) | |
10220 | break; | |
10221 | ||
10222 | iface.bridge_ifname = pos; | |
10223 | pos = os_strchr(pos, '\t'); | |
10224 | if (pos) | |
10225 | *pos++ = '\0'; | |
10226 | if (iface.bridge_ifname[0] == '\0') | |
10227 | iface.bridge_ifname = NULL; | |
10228 | if (pos == NULL) | |
10229 | break; | |
efa232f9 JJ |
10230 | |
10231 | extra = pos; | |
10232 | pos = os_strchr(pos, '\t'); | |
10233 | if (pos) | |
10234 | *pos++ = '\0'; | |
da3db681 BG |
10235 | if (!extra[0]) |
10236 | break; | |
10237 | ||
0f039e34 | 10238 | if (os_strcmp(extra, "create") == 0) { |
efa232f9 | 10239 | create_iface = 1; |
0f039e34 AS |
10240 | if (!pos) |
10241 | break; | |
10242 | ||
10243 | if (os_strcmp(pos, "sta") == 0) { | |
10244 | type = WPA_IF_STATION; | |
10245 | } else if (os_strcmp(pos, "ap") == 0) { | |
10246 | type = WPA_IF_AP_BSS; | |
10247 | } else { | |
10248 | wpa_printf(MSG_DEBUG, | |
10249 | "INTERFACE_ADD unsupported interface type: '%s'", | |
10250 | pos); | |
10251 | return -1; | |
10252 | } | |
10253 | } else { | |
da3db681 BG |
10254 | wpa_printf(MSG_DEBUG, |
10255 | "INTERFACE_ADD unsupported extra parameter: '%s'", | |
10256 | extra); | |
efa232f9 | 10257 | return -1; |
da3db681 | 10258 | } |
6fc6879b JM |
10259 | } while (0); |
10260 | ||
efa232f9 JJ |
10261 | if (create_iface) { |
10262 | wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'", | |
10263 | iface.ifname); | |
10264 | if (!global->ifaces) | |
10265 | return -1; | |
0f039e34 | 10266 | if (wpa_drv_if_add(global->ifaces, type, iface.ifname, |
efa232f9 JJ |
10267 | NULL, NULL, NULL, mac_addr, NULL) < 0) { |
10268 | wpa_printf(MSG_ERROR, | |
10269 | "CTRL_IFACE interface creation failed"); | |
10270 | return -1; | |
10271 | } | |
10272 | ||
10273 | wpa_printf(MSG_DEBUG, | |
10274 | "CTRL_IFACE interface '%s' created with MAC addr: " | |
10275 | MACSTR, iface.ifname, MAC2STR(mac_addr)); | |
10276 | } | |
10277 | ||
6fc6879b | 10278 | if (wpa_supplicant_get_iface(global, iface.ifname)) |
efa232f9 JJ |
10279 | goto fail; |
10280 | ||
10281 | wpa_s = wpa_supplicant_add_iface(global, &iface, NULL); | |
10282 | if (!wpa_s) | |
10283 | goto fail; | |
10284 | wpa_s->added_vif = create_iface; | |
10285 | return 0; | |
6fc6879b | 10286 | |
efa232f9 JJ |
10287 | fail: |
10288 | if (create_iface) | |
10289 | wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname); | |
10290 | return -1; | |
6fc6879b JM |
10291 | } |
10292 | ||
10293 | ||
10294 | static int wpa_supplicant_global_iface_remove(struct wpa_global *global, | |
10295 | char *cmd) | |
10296 | { | |
10297 | struct wpa_supplicant *wpa_s; | |
efa232f9 JJ |
10298 | int ret; |
10299 | unsigned int delete_iface; | |
6fc6879b JM |
10300 | |
10301 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd); | |
10302 | ||
10303 | wpa_s = wpa_supplicant_get_iface(global, cmd); | |
10304 | if (wpa_s == NULL) | |
10305 | return -1; | |
efa232f9 JJ |
10306 | delete_iface = wpa_s->added_vif; |
10307 | ret = wpa_supplicant_remove_iface(global, wpa_s, 0); | |
10308 | if (!ret && delete_iface) { | |
10309 | wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'", | |
10310 | cmd); | |
10311 | ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd); | |
10312 | } | |
10313 | return ret; | |
6fc6879b JM |
10314 | } |
10315 | ||
10316 | ||
4b4a8ae5 JM |
10317 | static void wpa_free_iface_info(struct wpa_interface_info *iface) |
10318 | { | |
10319 | struct wpa_interface_info *prev; | |
10320 | ||
10321 | while (iface) { | |
10322 | prev = iface; | |
10323 | iface = iface->next; | |
10324 | ||
10325 | os_free(prev->ifname); | |
10326 | os_free(prev->desc); | |
10327 | os_free(prev); | |
10328 | } | |
10329 | } | |
10330 | ||
10331 | ||
10332 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, | |
10333 | char *buf, int len) | |
10334 | { | |
10335 | int i, res; | |
10336 | struct wpa_interface_info *iface = NULL, *last = NULL, *tmp; | |
10337 | char *pos, *end; | |
10338 | ||
c5121837 | 10339 | for (i = 0; wpa_drivers[i]; i++) { |
8b423edb | 10340 | const struct wpa_driver_ops *drv = wpa_drivers[i]; |
4b4a8ae5 JM |
10341 | if (drv->get_interfaces == NULL) |
10342 | continue; | |
5fbc1f27 | 10343 | tmp = drv->get_interfaces(global->drv_priv[i]); |
4b4a8ae5 JM |
10344 | if (tmp == NULL) |
10345 | continue; | |
10346 | ||
10347 | if (last == NULL) | |
10348 | iface = last = tmp; | |
10349 | else | |
10350 | last->next = tmp; | |
10351 | while (last->next) | |
10352 | last = last->next; | |
10353 | } | |
10354 | ||
10355 | pos = buf; | |
10356 | end = buf + len; | |
10357 | for (tmp = iface; tmp; tmp = tmp->next) { | |
10358 | res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n", | |
10359 | tmp->drv_name, tmp->ifname, | |
10360 | tmp->desc ? tmp->desc : ""); | |
d85e1fc8 | 10361 | if (os_snprintf_error(end - pos, res)) { |
4b4a8ae5 JM |
10362 | *pos = '\0'; |
10363 | break; | |
10364 | } | |
10365 | pos += res; | |
10366 | } | |
10367 | ||
10368 | wpa_free_iface_info(iface); | |
10369 | ||
10370 | return pos - buf; | |
10371 | } | |
10372 | ||
10373 | ||
6fc6879b | 10374 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
56e2fc2c | 10375 | const char *input, |
6fc6879b JM |
10376 | char *buf, int len) |
10377 | { | |
10378 | int res; | |
10379 | char *pos, *end; | |
10380 | struct wpa_supplicant *wpa_s; | |
56e2fc2c JD |
10381 | int show_ctrl = 0; |
10382 | ||
10383 | if (input) | |
10384 | show_ctrl = !!os_strstr(input, "ctrl"); | |
6fc6879b JM |
10385 | |
10386 | wpa_s = global->ifaces; | |
10387 | pos = buf; | |
10388 | end = buf + len; | |
10389 | ||
10390 | while (wpa_s) { | |
56e2fc2c JD |
10391 | if (show_ctrl) |
10392 | res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n", | |
10393 | wpa_s->ifname, | |
10394 | wpa_s->conf->ctrl_interface ? | |
10395 | wpa_s->conf->ctrl_interface : "N/A"); | |
10396 | else | |
10397 | res = os_snprintf(pos, end - pos, "%s\n", | |
10398 | wpa_s->ifname); | |
10399 | ||
d85e1fc8 | 10400 | if (os_snprintf_error(end - pos, res)) { |
6fc6879b JM |
10401 | *pos = '\0'; |
10402 | break; | |
10403 | } | |
10404 | pos += res; | |
10405 | wpa_s = wpa_s->next; | |
10406 | } | |
10407 | return pos - buf; | |
10408 | } | |
10409 | ||
10410 | ||
cf3bebf2 JM |
10411 | static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global, |
10412 | const char *ifname, | |
10413 | char *cmd, size_t *resp_len) | |
10414 | { | |
10415 | struct wpa_supplicant *wpa_s; | |
10416 | ||
10417 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
10418 | if (os_strcmp(ifname, wpa_s->ifname) == 0) | |
10419 | break; | |
10420 | } | |
10421 | ||
10422 | if (wpa_s == NULL) { | |
10423 | char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n"); | |
10424 | if (resp) | |
10425 | *resp_len = os_strlen(resp); | |
10426 | else | |
10427 | *resp_len = 1; | |
10428 | return resp; | |
10429 | } | |
10430 | ||
10431 | return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len); | |
10432 | } | |
10433 | ||
10434 | ||
576bce9c JM |
10435 | static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global, |
10436 | char *buf, size_t *resp_len) | |
10437 | { | |
10438 | #ifdef CONFIG_P2P | |
10439 | static const char * cmd[] = { | |
443427e4 | 10440 | "LIST_NETWORKS", |
576bce9c JM |
10441 | "P2P_FIND", |
10442 | "P2P_STOP_FIND", | |
10443 | "P2P_LISTEN", | |
10444 | "P2P_GROUP_ADD", | |
10445 | "P2P_GET_PASSPHRASE", | |
10446 | "P2P_SERVICE_UPDATE", | |
10447 | "P2P_SERVICE_FLUSH", | |
10448 | "P2P_FLUSH", | |
10449 | "P2P_CANCEL", | |
10450 | "P2P_PRESENCE_REQ", | |
10451 | "P2P_EXT_LISTEN", | |
f2bc3448 DS |
10452 | #ifdef CONFIG_AP |
10453 | "STA-FIRST", | |
10454 | #endif /* CONFIG_AP */ | |
576bce9c JM |
10455 | NULL |
10456 | }; | |
10457 | static const char * prefix[] = { | |
443427e4 DS |
10458 | #ifdef ANDROID |
10459 | "DRIVER ", | |
10460 | #endif /* ANDROID */ | |
10461 | "GET_NETWORK ", | |
10462 | "REMOVE_NETWORK ", | |
576bce9c JM |
10463 | "P2P_FIND ", |
10464 | "P2P_CONNECT ", | |
10465 | "P2P_LISTEN ", | |
10466 | "P2P_GROUP_REMOVE ", | |
10467 | "P2P_GROUP_ADD ", | |
57b38882 | 10468 | "P2P_GROUP_MEMBER ", |
576bce9c JM |
10469 | "P2P_PROV_DISC ", |
10470 | "P2P_SERV_DISC_REQ ", | |
10471 | "P2P_SERV_DISC_CANCEL_REQ ", | |
10472 | "P2P_SERV_DISC_RESP ", | |
10473 | "P2P_SERV_DISC_EXTERNAL ", | |
10474 | "P2P_SERVICE_ADD ", | |
10475 | "P2P_SERVICE_DEL ", | |
87d5ef5a | 10476 | "P2P_SERVICE_REP ", |
576bce9c JM |
10477 | "P2P_REJECT ", |
10478 | "P2P_INVITE ", | |
10479 | "P2P_PEER ", | |
10480 | "P2P_SET ", | |
10481 | "P2P_UNAUTHORIZE ", | |
10482 | "P2P_PRESENCE_REQ ", | |
10483 | "P2P_EXT_LISTEN ", | |
f2c56602 | 10484 | "P2P_REMOVE_CLIENT ", |
8ad8bc5c DS |
10485 | "WPS_NFC_TOKEN ", |
10486 | "WPS_NFC_TAG_READ ", | |
f3ff9487 AM |
10487 | "NFC_GET_HANDOVER_SEL ", |
10488 | "NFC_GET_HANDOVER_REQ ", | |
10489 | "NFC_REPORT_HANDOVER ", | |
87d5ef5a KV |
10490 | "P2P_ASP_PROVISION ", |
10491 | "P2P_ASP_PROVISION_RESP ", | |
f2bc3448 DS |
10492 | #ifdef CONFIG_AP |
10493 | "STA ", | |
10494 | "STA-NEXT ", | |
10495 | #endif /* CONFIG_AP */ | |
576bce9c JM |
10496 | NULL |
10497 | }; | |
10498 | int found = 0; | |
10499 | int i; | |
10500 | ||
10501 | if (global->p2p_init_wpa_s == NULL) | |
10502 | return NULL; | |
10503 | ||
10504 | for (i = 0; !found && cmd[i]; i++) { | |
10505 | if (os_strcmp(buf, cmd[i]) == 0) | |
10506 | found = 1; | |
10507 | } | |
10508 | ||
10509 | for (i = 0; !found && prefix[i]; i++) { | |
10510 | if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0) | |
10511 | found = 1; | |
10512 | } | |
10513 | ||
10514 | if (found) | |
10515 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, | |
10516 | buf, resp_len); | |
10517 | #endif /* CONFIG_P2P */ | |
10518 | return NULL; | |
10519 | } | |
10520 | ||
10521 | ||
10522 | static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global, | |
10523 | char *buf, size_t *resp_len) | |
10524 | { | |
10525 | #ifdef CONFIG_WIFI_DISPLAY | |
10526 | if (global->p2p_init_wpa_s == NULL) | |
10527 | return NULL; | |
10528 | if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 || | |
10529 | os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) | |
10530 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, | |
10531 | buf, resp_len); | |
10532 | #endif /* CONFIG_WIFI_DISPLAY */ | |
10533 | return NULL; | |
10534 | } | |
10535 | ||
10536 | ||
10537 | static char * wpas_global_ctrl_iface_redir(struct wpa_global *global, | |
10538 | char *buf, size_t *resp_len) | |
10539 | { | |
10540 | char *ret; | |
10541 | ||
10542 | ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len); | |
10543 | if (ret) | |
10544 | return ret; | |
10545 | ||
10546 | ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len); | |
10547 | if (ret) | |
10548 | return ret; | |
10549 | ||
10550 | return NULL; | |
10551 | } | |
10552 | ||
10553 | ||
1b9b31c1 JM |
10554 | static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd) |
10555 | { | |
10556 | char *value; | |
10557 | ||
10558 | value = os_strchr(cmd, ' '); | |
10559 | if (value == NULL) | |
10560 | return -1; | |
10561 | *value++ = '\0'; | |
10562 | ||
10563 | wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value); | |
10564 | ||
10565 | #ifdef CONFIG_WIFI_DISPLAY | |
10566 | if (os_strcasecmp(cmd, "wifi_display") == 0) { | |
10567 | wifi_display_enable(global, !!atoi(value)); | |
10568 | return 0; | |
10569 | } | |
10570 | #endif /* CONFIG_WIFI_DISPLAY */ | |
10571 | ||
a7ca6dac JM |
10572 | /* Restore cmd to its original value to allow redirection */ |
10573 | value[-1] = ' '; | |
10574 | ||
1b9b31c1 JM |
10575 | return -1; |
10576 | } | |
10577 | ||
10578 | ||
daae4995 AN |
10579 | static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global, |
10580 | char *cmd) | |
10581 | { | |
10582 | struct wpa_supplicant *wpa_s[2]; /* src, dst */ | |
10583 | char *p; | |
10584 | unsigned int i; | |
10585 | ||
10586 | /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id> | |
10587 | * <variable name> */ | |
10588 | ||
10589 | for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) { | |
10590 | p = os_strchr(cmd, ' '); | |
10591 | if (p == NULL) | |
10592 | return -1; | |
10593 | *p = '\0'; | |
10594 | ||
10595 | wpa_s[i] = global->ifaces; | |
10596 | for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) { | |
10597 | if (os_strcmp(cmd, wpa_s[i]->ifname) == 0) | |
10598 | break; | |
10599 | } | |
10600 | ||
10601 | if (!wpa_s[i]) { | |
10602 | wpa_printf(MSG_DEBUG, | |
10603 | "CTRL_IFACE: Could not find iface=%s", cmd); | |
10604 | return -1; | |
10605 | } | |
10606 | ||
10607 | cmd = p + 1; | |
10608 | } | |
10609 | ||
10610 | return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]); | |
10611 | } | |
10612 | ||
10613 | ||
42868f14 JM |
10614 | #ifndef CONFIG_NO_CONFIG_WRITE |
10615 | static int wpas_global_ctrl_iface_save_config(struct wpa_global *global) | |
10616 | { | |
d6b818ef | 10617 | int ret = 0, saved = 0; |
42868f14 JM |
10618 | struct wpa_supplicant *wpa_s; |
10619 | ||
10620 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
10621 | if (!wpa_s->conf->update_config) { | |
10622 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)"); | |
10623 | continue; | |
10624 | } | |
10625 | ||
10626 | if (wpa_config_write(wpa_s->confname, wpa_s->conf)) { | |
10627 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration"); | |
10628 | ret = 1; | |
10629 | } else { | |
10630 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated"); | |
d6b818ef | 10631 | saved++; |
42868f14 JM |
10632 | } |
10633 | } | |
10634 | ||
d6b818ef JM |
10635 | if (!saved && !ret) { |
10636 | wpa_dbg(wpa_s, MSG_DEBUG, | |
10637 | "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated"); | |
10638 | ret = 1; | |
10639 | } | |
10640 | ||
42868f14 JM |
10641 | return ret; |
10642 | } | |
10643 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
10644 | ||
10645 | ||
ae8c27f7 JM |
10646 | static int wpas_global_ctrl_iface_status(struct wpa_global *global, |
10647 | char *buf, size_t buflen) | |
10648 | { | |
10649 | char *pos, *end; | |
10650 | int ret; | |
10651 | struct wpa_supplicant *wpa_s; | |
10652 | ||
10653 | pos = buf; | |
10654 | end = buf + buflen; | |
10655 | ||
10656 | #ifdef CONFIG_P2P | |
4c559019 | 10657 | if (global->p2p && !global->p2p_disabled) { |
ae8c27f7 | 10658 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR |
4c559019 JM |
10659 | "\n" |
10660 | "p2p_state=%s\n", | |
10661 | MAC2STR(global->p2p_dev_addr), | |
10662 | p2p_get_state_txt(global->p2p)); | |
d85e1fc8 | 10663 | if (os_snprintf_error(end - pos, ret)) |
4c559019 JM |
10664 | return pos - buf; |
10665 | pos += ret; | |
10666 | } else if (global->p2p) { | |
10667 | ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n"); | |
d85e1fc8 | 10668 | if (os_snprintf_error(end - pos, ret)) |
ae8c27f7 JM |
10669 | return pos - buf; |
10670 | pos += ret; | |
10671 | } | |
10672 | #endif /* CONFIG_P2P */ | |
10673 | ||
10674 | #ifdef CONFIG_WIFI_DISPLAY | |
10675 | ret = os_snprintf(pos, end - pos, "wifi_display=%d\n", | |
10676 | !!global->wifi_display); | |
d85e1fc8 | 10677 | if (os_snprintf_error(end - pos, ret)) |
ae8c27f7 JM |
10678 | return pos - buf; |
10679 | pos += ret; | |
10680 | #endif /* CONFIG_WIFI_DISPLAY */ | |
10681 | ||
10682 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
10683 | ret = os_snprintf(pos, end - pos, "ifname=%s\n" | |
10684 | "address=" MACSTR "\n", | |
10685 | wpa_s->ifname, MAC2STR(wpa_s->own_addr)); | |
d85e1fc8 | 10686 | if (os_snprintf_error(end - pos, ret)) |
ae8c27f7 JM |
10687 | return pos - buf; |
10688 | pos += ret; | |
10689 | } | |
10690 | ||
10691 | return pos - buf; | |
10692 | } | |
10693 | ||
10694 | ||
3794af2d AN |
10695 | #ifdef CONFIG_FST |
10696 | ||
10697 | static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global, | |
10698 | char *cmd, char *buf, | |
10699 | size_t reply_size) | |
10700 | { | |
10701 | char ifname[IFNAMSIZ + 1]; | |
10702 | struct fst_iface_cfg cfg; | |
10703 | struct wpa_supplicant *wpa_s; | |
10704 | struct fst_wpa_obj iface_obj; | |
10705 | ||
10706 | if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) { | |
10707 | wpa_s = wpa_supplicant_get_iface(global, ifname); | |
10708 | if (wpa_s) { | |
5dbd3bf9 JM |
10709 | if (wpa_s->fst) { |
10710 | wpa_printf(MSG_INFO, "FST: Already attached"); | |
10711 | return -1; | |
10712 | } | |
3794af2d AN |
10713 | fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj); |
10714 | wpa_s->fst = fst_attach(ifname, wpa_s->own_addr, | |
10715 | &iface_obj, &cfg); | |
10716 | if (wpa_s->fst) | |
10717 | return os_snprintf(buf, reply_size, "OK\n"); | |
10718 | } | |
10719 | } | |
10720 | ||
10721 | return -1; | |
10722 | } | |
10723 | ||
10724 | ||
10725 | static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global, | |
10726 | char *cmd, char *buf, | |
10727 | size_t reply_size) | |
10728 | { | |
10729 | char ifname[IFNAMSIZ + 1]; | |
10730 | struct wpa_supplicant *wpa_s; | |
10731 | ||
10732 | if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) { | |
10733 | wpa_s = wpa_supplicant_get_iface(global, ifname); | |
10734 | if (wpa_s) { | |
10735 | if (!fst_iface_detach(ifname)) { | |
10736 | wpa_s->fst = NULL; | |
10737 | return os_snprintf(buf, reply_size, "OK\n"); | |
10738 | } | |
10739 | } | |
10740 | } | |
10741 | ||
10742 | return -1; | |
10743 | } | |
10744 | ||
10745 | #endif /* CONFIG_FST */ | |
10746 | ||
10747 | ||
6fc6879b JM |
10748 | char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, |
10749 | char *buf, size_t *resp_len) | |
10750 | { | |
10751 | char *reply; | |
10752 | const int reply_size = 2048; | |
10753 | int reply_len; | |
f4a0a82c | 10754 | int level = MSG_DEBUG; |
6fc6879b | 10755 | |
cf3bebf2 JM |
10756 | if (os_strncmp(buf, "IFNAME=", 7) == 0) { |
10757 | char *pos = os_strchr(buf + 7, ' '); | |
10758 | if (pos) { | |
10759 | *pos++ = '\0'; | |
10760 | return wpas_global_ctrl_iface_ifname(global, | |
10761 | buf + 7, pos, | |
10762 | resp_len); | |
10763 | } | |
10764 | } | |
10765 | ||
576bce9c JM |
10766 | reply = wpas_global_ctrl_iface_redir(global, buf, resp_len); |
10767 | if (reply) | |
10768 | return reply; | |
10769 | ||
f4a0a82c JM |
10770 | if (os_strcmp(buf, "PING") == 0) |
10771 | level = MSG_EXCESSIVE; | |
10772 | wpa_hexdump_ascii(level, "RX global ctrl_iface", | |
6fc6879b JM |
10773 | (const u8 *) buf, os_strlen(buf)); |
10774 | ||
10775 | reply = os_malloc(reply_size); | |
10776 | if (reply == NULL) { | |
10777 | *resp_len = 1; | |
10778 | return NULL; | |
10779 | } | |
10780 | ||
10781 | os_memcpy(reply, "OK\n", 3); | |
10782 | reply_len = 3; | |
10783 | ||
10784 | if (os_strcmp(buf, "PING") == 0) { | |
10785 | os_memcpy(reply, "PONG\n", 5); | |
10786 | reply_len = 5; | |
10787 | } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) { | |
10788 | if (wpa_supplicant_global_iface_add(global, buf + 14)) | |
10789 | reply_len = -1; | |
10790 | } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) { | |
10791 | if (wpa_supplicant_global_iface_remove(global, buf + 17)) | |
10792 | reply_len = -1; | |
4b4a8ae5 JM |
10793 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
10794 | reply_len = wpa_supplicant_global_iface_list( | |
10795 | global, reply, reply_size); | |
56e2fc2c | 10796 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { |
6fc6879b | 10797 | reply_len = wpa_supplicant_global_iface_interfaces( |
56e2fc2c | 10798 | global, buf + 10, reply, reply_size); |
3794af2d AN |
10799 | #ifdef CONFIG_FST |
10800 | } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) { | |
10801 | reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11, | |
10802 | reply, | |
10803 | reply_size); | |
10804 | } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) { | |
10805 | reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11, | |
10806 | reply, | |
10807 | reply_size); | |
10808 | } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) { | |
10809 | reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size); | |
10810 | #endif /* CONFIG_FST */ | |
6fc6879b | 10811 | } else if (os_strcmp(buf, "TERMINATE") == 0) { |
1a1bf008 | 10812 | wpa_supplicant_terminate_proc(global); |
207ef3fb JM |
10813 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
10814 | wpas_notify_suspend(global); | |
10815 | } else if (os_strcmp(buf, "RESUME") == 0) { | |
10816 | wpas_notify_resume(global); | |
1b9b31c1 | 10817 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
a7ca6dac JM |
10818 | if (wpas_global_ctrl_iface_set(global, buf + 4)) { |
10819 | #ifdef CONFIG_P2P | |
10820 | if (global->p2p_init_wpa_s) { | |
10821 | os_free(reply); | |
10822 | /* Check if P2P redirection would work for this | |
10823 | * command. */ | |
10824 | return wpa_supplicant_ctrl_iface_process( | |
10825 | global->p2p_init_wpa_s, | |
10826 | buf, resp_len); | |
10827 | } | |
10828 | #endif /* CONFIG_P2P */ | |
1b9b31c1 | 10829 | reply_len = -1; |
a7ca6dac | 10830 | } |
daae4995 AN |
10831 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
10832 | if (wpas_global_ctrl_iface_dup_network(global, buf + 12)) | |
10833 | reply_len = -1; | |
42868f14 JM |
10834 | #ifndef CONFIG_NO_CONFIG_WRITE |
10835 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | |
10836 | if (wpas_global_ctrl_iface_save_config(global)) | |
10837 | reply_len = -1; | |
10838 | #endif /* CONFIG_NO_CONFIG_WRITE */ | |
ae8c27f7 JM |
10839 | } else if (os_strcmp(buf, "STATUS") == 0) { |
10840 | reply_len = wpas_global_ctrl_iface_status(global, reply, | |
10841 | reply_size); | |
ea449b5b JM |
10842 | #ifdef CONFIG_MODULE_TESTS |
10843 | } else if (os_strcmp(buf, "MODULE_TESTS") == 0) { | |
ea449b5b JM |
10844 | if (wpas_module_tests() < 0) |
10845 | reply_len = -1; | |
10846 | #endif /* CONFIG_MODULE_TESTS */ | |
5f797376 JM |
10847 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
10848 | if (wpa_debug_reopen_file() < 0) | |
10849 | reply_len = -1; | |
6fc6879b JM |
10850 | } else { |
10851 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | |
10852 | reply_len = 16; | |
10853 | } | |
10854 | ||
10855 | if (reply_len < 0) { | |
10856 | os_memcpy(reply, "FAIL\n", 5); | |
10857 | reply_len = 5; | |
10858 | } | |
10859 | ||
10860 | *resp_len = reply_len; | |
10861 | return reply; | |
10862 | } |