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