Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * WPA Supplicant / Control interface (shared code for all backends) |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3 | * Copyright (c) 2004-2020, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "utils/includes.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11 | #include <netinet/ip.h> |
| 12 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13 | |
| 14 | #include "utils/common.h" |
| 15 | #include "utils/eloop.h" |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 16 | #include "utils/uuid.h" |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 17 | #include "utils/module_tests.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 18 | #include "common/version.h" |
| 19 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 20 | #include "common/ieee802_11_common.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 21 | #include "common/wpa_ctrl.h" |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 22 | #ifdef CONFIG_DPP |
| 23 | #include "common/dpp.h" |
| 24 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 25 | #include "crypto/tls.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 26 | #include "ap/hostapd.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 27 | #include "eap_peer/eap.h" |
| 28 | #include "eapol_supp/eapol_supp_sm.h" |
| 29 | #include "rsn_supp/wpa.h" |
| 30 | #include "rsn_supp/preauth.h" |
| 31 | #include "rsn_supp/pmksa_cache.h" |
| 32 | #include "l2_packet/l2_packet.h" |
| 33 | #include "wps/wps.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 34 | #include "fst/fst.h" |
| 35 | #include "fst/fst_ctrl_iface.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 36 | #include "config.h" |
| 37 | #include "wpa_supplicant_i.h" |
| 38 | #include "driver_i.h" |
| 39 | #include "wps_supplicant.h" |
| 40 | #include "ibss_rsn.h" |
| 41 | #include "ap.h" |
| 42 | #include "p2p_supplicant.h" |
| 43 | #include "p2p/p2p.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 44 | #include "hs20_supplicant.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 45 | #include "wifi_display.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 46 | #include "notify.h" |
| 47 | #include "bss.h" |
| 48 | #include "scan.h" |
| 49 | #include "ctrl_iface.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 50 | #include "interworking.h" |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 51 | #include "blacklist.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 52 | #include "autoscan.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 53 | #include "wnm_sta.h" |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 54 | #include "offchannel.h" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 55 | #include "drivers/driver.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 56 | #include "mesh.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 57 | #include "dpp_supplicant.h" |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 58 | #include "sme.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 59 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 60 | #ifdef __NetBSD__ |
| 61 | #include <net/if_ether.h> |
| 62 | #elif !defined(__CYGWIN__) && !defined(CONFIG_NATIVE_WINDOWS) |
| 63 | #include <net/ethernet.h> |
| 64 | #endif |
| 65 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 66 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
| 67 | char *buf, int len); |
| 68 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 69 | const char *input, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 70 | char *buf, int len); |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 71 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, |
| 72 | char *val); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 73 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 74 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 75 | static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val) |
| 76 | { |
| 77 | char *pos; |
| 78 | u8 addr[ETH_ALEN], *filter = NULL, *n; |
| 79 | size_t count = 0; |
| 80 | |
| 81 | pos = val; |
| 82 | while (pos) { |
| 83 | if (*pos == '\0') |
| 84 | break; |
| 85 | if (hwaddr_aton(pos, addr)) { |
| 86 | os_free(filter); |
| 87 | return -1; |
| 88 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 89 | n = os_realloc_array(filter, count + 1, ETH_ALEN); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 90 | if (n == NULL) { |
| 91 | os_free(filter); |
| 92 | return -1; |
| 93 | } |
| 94 | filter = n; |
| 95 | os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN); |
| 96 | count++; |
| 97 | |
| 98 | pos = os_strchr(pos, ' '); |
| 99 | if (pos) |
| 100 | pos++; |
| 101 | } |
| 102 | |
| 103 | wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN); |
| 104 | os_free(wpa_s->bssid_filter); |
| 105 | wpa_s->bssid_filter = filter; |
| 106 | wpa_s->bssid_filter_count = count; |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 112 | static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val) |
| 113 | { |
| 114 | char *pos; |
| 115 | u8 addr[ETH_ALEN], *bssid = NULL, *n; |
| 116 | struct wpa_ssid_value *ssid = NULL, *ns; |
| 117 | size_t count = 0, ssid_count = 0; |
| 118 | struct wpa_ssid *c; |
| 119 | |
| 120 | /* |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 121 | * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | "" |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 122 | * SSID_SPEC ::= ssid <SSID_HEX> |
| 123 | * BSSID_SPEC ::= bssid <BSSID_HEX> |
| 124 | */ |
| 125 | |
| 126 | pos = val; |
| 127 | while (pos) { |
| 128 | if (*pos == '\0') |
| 129 | break; |
| 130 | if (os_strncmp(pos, "bssid ", 6) == 0) { |
| 131 | int res; |
| 132 | pos += 6; |
| 133 | res = hwaddr_aton2(pos, addr); |
| 134 | if (res < 0) { |
| 135 | os_free(ssid); |
| 136 | os_free(bssid); |
| 137 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " |
| 138 | "BSSID value '%s'", pos); |
| 139 | return -1; |
| 140 | } |
| 141 | pos += res; |
| 142 | n = os_realloc_array(bssid, count + 1, ETH_ALEN); |
| 143 | if (n == NULL) { |
| 144 | os_free(ssid); |
| 145 | os_free(bssid); |
| 146 | return -1; |
| 147 | } |
| 148 | bssid = n; |
| 149 | os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN); |
| 150 | count++; |
| 151 | } else if (os_strncmp(pos, "ssid ", 5) == 0) { |
| 152 | char *end; |
| 153 | pos += 5; |
| 154 | |
| 155 | end = pos; |
| 156 | while (*end) { |
| 157 | if (*end == '\0' || *end == ' ') |
| 158 | break; |
| 159 | end++; |
| 160 | } |
| 161 | |
| 162 | ns = os_realloc_array(ssid, ssid_count + 1, |
| 163 | sizeof(struct wpa_ssid_value)); |
| 164 | if (ns == NULL) { |
| 165 | os_free(ssid); |
| 166 | os_free(bssid); |
| 167 | return -1; |
| 168 | } |
| 169 | ssid = ns; |
| 170 | |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 171 | if ((end - pos) & 0x01 || |
| 172 | end - pos > 2 * SSID_MAX_LEN || |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 173 | hexstr2bin(pos, ssid[ssid_count].ssid, |
| 174 | (end - pos) / 2) < 0) { |
| 175 | os_free(ssid); |
| 176 | os_free(bssid); |
| 177 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " |
| 178 | "SSID value '%s'", pos); |
| 179 | return -1; |
| 180 | } |
| 181 | ssid[ssid_count].ssid_len = (end - pos) / 2; |
| 182 | wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID", |
| 183 | ssid[ssid_count].ssid, |
| 184 | ssid[ssid_count].ssid_len); |
| 185 | ssid_count++; |
| 186 | pos = end; |
| 187 | } else { |
| 188 | wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value " |
| 189 | "'%s'", pos); |
| 190 | os_free(ssid); |
| 191 | os_free(bssid); |
| 192 | return -1; |
| 193 | } |
| 194 | |
| 195 | pos = os_strchr(pos, ' '); |
| 196 | if (pos) |
| 197 | pos++; |
| 198 | } |
| 199 | |
| 200 | wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN); |
| 201 | os_free(wpa_s->disallow_aps_bssid); |
| 202 | wpa_s->disallow_aps_bssid = bssid; |
| 203 | wpa_s->disallow_aps_bssid_count = count; |
| 204 | |
| 205 | wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count); |
| 206 | os_free(wpa_s->disallow_aps_ssid); |
| 207 | wpa_s->disallow_aps_ssid = ssid; |
| 208 | wpa_s->disallow_aps_ssid_count = ssid_count; |
| 209 | |
| 210 | if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING) |
| 211 | return 0; |
| 212 | |
| 213 | c = wpa_s->current_ssid; |
| 214 | if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS) |
| 215 | return 0; |
| 216 | |
| 217 | if (!disallowed_bssid(wpa_s, wpa_s->bssid) && |
| 218 | !disallowed_ssid(wpa_s, c->ssid, c->ssid_len)) |
| 219 | return 0; |
| 220 | |
| 221 | wpa_printf(MSG_DEBUG, "Disconnect and try to find another network " |
| 222 | "because current AP was marked disallowed"); |
| 223 | |
| 224 | #ifdef CONFIG_SME |
| 225 | wpa_s->sme.prev_bssid_set = 0; |
| 226 | #endif /* CONFIG_SME */ |
| 227 | wpa_s->reassociate = 1; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 228 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 229 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 230 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 236 | #ifndef CONFIG_NO_CONFIG_BLOBS |
| 237 | static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos) |
| 238 | { |
| 239 | char *name = pos; |
| 240 | struct wpa_config_blob *blob; |
| 241 | size_t len; |
| 242 | |
| 243 | pos = os_strchr(pos, ' '); |
| 244 | if (pos == NULL) |
| 245 | return -1; |
| 246 | *pos++ = '\0'; |
| 247 | len = os_strlen(pos); |
| 248 | if (len & 1) |
| 249 | return -1; |
| 250 | |
| 251 | wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name); |
| 252 | blob = os_zalloc(sizeof(*blob)); |
| 253 | if (blob == NULL) |
| 254 | return -1; |
| 255 | blob->name = os_strdup(name); |
| 256 | blob->data = os_malloc(len / 2); |
| 257 | if (blob->name == NULL || blob->data == NULL) { |
| 258 | wpa_config_free_blob(blob); |
| 259 | return -1; |
| 260 | } |
| 261 | |
| 262 | if (hexstr2bin(pos, blob->data, len / 2) < 0) { |
| 263 | wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data"); |
| 264 | wpa_config_free_blob(blob); |
| 265 | return -1; |
| 266 | } |
| 267 | blob->len = len / 2; |
| 268 | |
| 269 | wpa_config_set_blob(wpa_s->conf, blob); |
| 270 | |
| 271 | return 0; |
| 272 | } |
| 273 | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
| 274 | |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 275 | |
| 276 | static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd) |
| 277 | { |
| 278 | char *params; |
| 279 | char *pos; |
| 280 | int *freqs = NULL; |
| 281 | int ret; |
| 282 | |
| 283 | if (atoi(cmd)) { |
| 284 | params = os_strchr(cmd, ' '); |
| 285 | os_free(wpa_s->manual_sched_scan_freqs); |
| 286 | if (params) { |
| 287 | params++; |
| 288 | pos = os_strstr(params, "freq="); |
| 289 | if (pos) |
| 290 | freqs = freq_range_to_channel_list(wpa_s, |
| 291 | pos + 5); |
| 292 | } |
| 293 | wpa_s->manual_sched_scan_freqs = freqs; |
| 294 | ret = wpas_start_pno(wpa_s); |
| 295 | } else { |
| 296 | ret = wpas_stop_pno(wpa_s); |
| 297 | } |
| 298 | return ret; |
| 299 | } |
| 300 | |
| 301 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 302 | static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band) |
| 303 | { |
| 304 | union wpa_event_data event; |
| 305 | |
| 306 | if (os_strcmp(band, "AUTO") == 0) |
| 307 | wpa_s->setband = WPA_SETBAND_AUTO; |
| 308 | else if (os_strcmp(band, "5G") == 0) |
| 309 | wpa_s->setband = WPA_SETBAND_5G; |
| 310 | else if (os_strcmp(band, "2G") == 0) |
| 311 | wpa_s->setband = WPA_SETBAND_2G; |
| 312 | else |
| 313 | return -1; |
| 314 | |
| 315 | if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) { |
| 316 | os_memset(&event, 0, sizeof(event)); |
| 317 | event.channel_list_changed.initiator = REGDOM_SET_BY_USER; |
| 318 | event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN; |
| 319 | wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event); |
| 320 | } |
| 321 | |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 326 | static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s, |
| 327 | const char *cmd) |
| 328 | { |
| 329 | struct wpabuf *lci; |
| 330 | |
| 331 | if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) { |
| 332 | wpabuf_free(wpa_s->lci); |
| 333 | wpa_s->lci = NULL; |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | lci = wpabuf_parse_bin(cmd); |
| 338 | if (!lci) |
| 339 | return -1; |
| 340 | |
| 341 | if (os_get_reltime(&wpa_s->lci_time)) { |
| 342 | wpabuf_free(lci); |
| 343 | return -1; |
| 344 | } |
| 345 | |
| 346 | wpabuf_free(wpa_s->lci); |
| 347 | wpa_s->lci = lci; |
| 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 353 | static int |
| 354 | wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd) |
| 355 | { |
| 356 | int relative_rssi; |
| 357 | |
| 358 | if (os_strcmp(cmd, "disable") == 0) { |
| 359 | wpa_s->srp.relative_rssi_set = 0; |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | relative_rssi = atoi(cmd); |
| 364 | if (relative_rssi < 0 || relative_rssi > 100) |
| 365 | return -1; |
| 366 | wpa_s->srp.relative_rssi = relative_rssi; |
| 367 | wpa_s->srp.relative_rssi_set = 1; |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | |
| 372 | static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s, |
| 373 | const char *cmd) |
| 374 | { |
| 375 | char *pos; |
| 376 | int adjust_rssi; |
| 377 | |
| 378 | /* <band>:adjust_value */ |
| 379 | pos = os_strchr(cmd, ':'); |
| 380 | if (!pos) |
| 381 | return -1; |
| 382 | pos++; |
| 383 | adjust_rssi = atoi(pos); |
| 384 | if (adjust_rssi < -100 || adjust_rssi > 100) |
| 385 | return -1; |
| 386 | |
| 387 | if (os_strncmp(cmd, "2G", 2) == 0) |
| 388 | wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G; |
| 389 | else if (os_strncmp(cmd, "5G", 2) == 0) |
| 390 | wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G; |
| 391 | else |
| 392 | return -1; |
| 393 | |
| 394 | wpa_s->srp.relative_adjust_rssi = adjust_rssi; |
| 395 | |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | |
| 400 | static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s, |
| 401 | const char *cmd) |
| 402 | { |
| 403 | struct wpabuf *ric_ies; |
| 404 | |
| 405 | if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) { |
| 406 | wpabuf_free(wpa_s->ric_ies); |
| 407 | wpa_s->ric_ies = NULL; |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | ric_ies = wpabuf_parse_bin(cmd); |
| 412 | if (!ric_ies) |
| 413 | return -1; |
| 414 | |
| 415 | wpabuf_free(wpa_s->ric_ies); |
| 416 | wpa_s->ric_ies = ric_ies; |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 422 | #ifdef CONFIG_TESTING_OPTIONS |
| 423 | static int wpas_ctrl_iface_set_dso(struct wpa_supplicant *wpa_s, |
| 424 | const char *val) |
| 425 | { |
| 426 | u8 bssid[ETH_ALEN]; |
| 427 | const char *pos = val; |
| 428 | struct driver_signal_override *dso = NULL, *tmp, parsed; |
| 429 | |
| 430 | if (hwaddr_aton(pos, bssid)) |
| 431 | return -1; |
| 432 | pos = os_strchr(pos, ' '); |
| 433 | |
| 434 | dl_list_for_each(tmp, &wpa_s->drv_signal_override, |
| 435 | struct driver_signal_override, list) { |
| 436 | if (os_memcmp(bssid, tmp->bssid, ETH_ALEN) == 0) { |
| 437 | dso = tmp; |
| 438 | break; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | if (!pos) { |
| 443 | /* Remove existing entry */ |
| 444 | if (dso) { |
| 445 | dl_list_del(&dso->list); |
| 446 | os_free(dso); |
| 447 | } |
| 448 | return 0; |
| 449 | } |
| 450 | pos++; |
| 451 | |
| 452 | /* Update an existing entry or add a new one */ |
| 453 | os_memset(&parsed, 0, sizeof(parsed)); |
| 454 | if (sscanf(pos, "%d %d %d %d %d", |
| 455 | &parsed.si_current_signal, |
| 456 | &parsed.si_avg_signal, |
| 457 | &parsed.si_avg_beacon_signal, |
| 458 | &parsed.si_current_noise, |
| 459 | &parsed.scan_level) != 5) |
| 460 | return -1; |
| 461 | |
| 462 | if (!dso) { |
| 463 | dso = os_zalloc(sizeof(*dso)); |
| 464 | if (!dso) |
| 465 | return -1; |
| 466 | os_memcpy(dso->bssid, bssid, ETH_ALEN); |
| 467 | dl_list_add(&wpa_s->drv_signal_override, &dso->list); |
| 468 | } |
| 469 | dso->si_current_signal = parsed.si_current_signal; |
| 470 | dso->si_avg_signal = parsed.si_avg_signal; |
| 471 | dso->si_avg_beacon_signal = parsed.si_avg_beacon_signal; |
| 472 | dso->si_current_noise = parsed.si_current_noise; |
| 473 | dso->scan_level = parsed.scan_level; |
| 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 478 | |
| 479 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 480 | static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, |
| 481 | char *cmd) |
| 482 | { |
| 483 | char *value; |
| 484 | int ret = 0; |
| 485 | |
| 486 | value = os_strchr(cmd, ' '); |
| 487 | if (value == NULL) |
| 488 | return -1; |
| 489 | *value++ = '\0'; |
| 490 | |
| 491 | wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value); |
| 492 | if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) { |
| 493 | eapol_sm_configure(wpa_s->eapol, |
| 494 | atoi(value), -1, -1, -1); |
| 495 | } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) { |
| 496 | eapol_sm_configure(wpa_s->eapol, |
| 497 | -1, atoi(value), -1, -1); |
| 498 | } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) { |
| 499 | eapol_sm_configure(wpa_s->eapol, |
| 500 | -1, -1, atoi(value), -1); |
| 501 | } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) { |
| 502 | eapol_sm_configure(wpa_s->eapol, |
| 503 | -1, -1, -1, atoi(value)); |
| 504 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) { |
| 505 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 506 | atoi(value))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 507 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 508 | } else { |
| 509 | value[-1] = '='; |
| 510 | wpa_config_process_global(wpa_s->conf, cmd, -1); |
| 511 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 512 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == |
| 513 | 0) { |
| 514 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 515 | atoi(value))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 516 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 517 | } else { |
| 518 | value[-1] = '='; |
| 519 | wpa_config_process_global(wpa_s->conf, cmd, -1); |
| 520 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 521 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 522 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, |
| 523 | atoi(value))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 524 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 525 | } else { |
| 526 | value[-1] = '='; |
| 527 | wpa_config_process_global(wpa_s->conf, cmd, -1); |
| 528 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 529 | } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) { |
| 530 | wpa_s->wps_fragment_size = atoi(value); |
| 531 | #ifdef CONFIG_WPS_TESTING |
| 532 | } else if (os_strcasecmp(cmd, "wps_version_number") == 0) { |
| 533 | long int val; |
| 534 | val = strtol(value, NULL, 0); |
| 535 | if (val < 0 || val > 0xff) { |
| 536 | ret = -1; |
| 537 | wpa_printf(MSG_DEBUG, "WPS: Invalid " |
| 538 | "wps_version_number %ld", val); |
| 539 | } else { |
| 540 | wps_version_number = val; |
| 541 | wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS " |
| 542 | "version %u.%u", |
| 543 | (wps_version_number & 0xf0) >> 4, |
| 544 | wps_version_number & 0x0f); |
| 545 | } |
| 546 | } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) { |
| 547 | wps_testing_dummy_cred = atoi(value); |
| 548 | wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d", |
| 549 | wps_testing_dummy_cred); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 550 | } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) { |
| 551 | wps_corrupt_pkhash = atoi(value); |
| 552 | wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d", |
| 553 | wps_corrupt_pkhash); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 554 | } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) { |
| 555 | if (value[0] == '\0') { |
| 556 | wps_force_auth_types_in_use = 0; |
| 557 | } else { |
| 558 | wps_force_auth_types = strtol(value, NULL, 0); |
| 559 | wps_force_auth_types_in_use = 1; |
| 560 | } |
| 561 | } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) { |
| 562 | if (value[0] == '\0') { |
| 563 | wps_force_encr_types_in_use = 0; |
| 564 | } else { |
| 565 | wps_force_encr_types = strtol(value, NULL, 0); |
| 566 | wps_force_encr_types_in_use = 1; |
| 567 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 568 | #endif /* CONFIG_WPS_TESTING */ |
| 569 | } else if (os_strcasecmp(cmd, "ampdu") == 0) { |
| 570 | if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0) |
| 571 | ret = -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 572 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 573 | #ifdef CONFIG_TDLS_TESTING |
| 574 | } else if (os_strcasecmp(cmd, "tdls_testing") == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 575 | tdls_testing = strtol(value, NULL, 0); |
| 576 | wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing); |
| 577 | #endif /* CONFIG_TDLS_TESTING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 578 | } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) { |
| 579 | int disabled = atoi(value); |
| 580 | wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled); |
| 581 | if (disabled) { |
| 582 | if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0) |
| 583 | ret = -1; |
| 584 | } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0) |
| 585 | ret = -1; |
| 586 | wpa_tdls_enable(wpa_s->wpa, !disabled); |
| 587 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 588 | } else if (os_strcasecmp(cmd, "pno") == 0) { |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 589 | ret = wpas_ctrl_pno(wpa_s, value); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 590 | } else if (os_strcasecmp(cmd, "radio_disabled") == 0) { |
| 591 | int disabled = atoi(value); |
| 592 | if (wpa_drv_radio_disable(wpa_s, disabled) < 0) |
| 593 | ret = -1; |
| 594 | else if (disabled) |
| 595 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
| 596 | } else if (os_strcasecmp(cmd, "uapsd") == 0) { |
| 597 | if (os_strcmp(value, "disable") == 0) |
| 598 | wpa_s->set_sta_uapsd = 0; |
| 599 | else { |
| 600 | int be, bk, vi, vo; |
| 601 | char *pos; |
| 602 | /* format: BE,BK,VI,VO;max SP Length */ |
| 603 | be = atoi(value); |
| 604 | pos = os_strchr(value, ','); |
| 605 | if (pos == NULL) |
| 606 | return -1; |
| 607 | pos++; |
| 608 | bk = atoi(pos); |
| 609 | pos = os_strchr(pos, ','); |
| 610 | if (pos == NULL) |
| 611 | return -1; |
| 612 | pos++; |
| 613 | vi = atoi(pos); |
| 614 | pos = os_strchr(pos, ','); |
| 615 | if (pos == NULL) |
| 616 | return -1; |
| 617 | pos++; |
| 618 | vo = atoi(pos); |
| 619 | /* ignore max SP Length for now */ |
| 620 | |
| 621 | wpa_s->set_sta_uapsd = 1; |
| 622 | wpa_s->sta_uapsd = 0; |
| 623 | if (be) |
| 624 | wpa_s->sta_uapsd |= BIT(0); |
| 625 | if (bk) |
| 626 | wpa_s->sta_uapsd |= BIT(1); |
| 627 | if (vi) |
| 628 | wpa_s->sta_uapsd |= BIT(2); |
| 629 | if (vo) |
| 630 | wpa_s->sta_uapsd |= BIT(3); |
| 631 | } |
Jouni Malinen | 21d6bc8 | 2012-04-10 16:17:59 -0700 | [diff] [blame] | 632 | } else if (os_strcasecmp(cmd, "ps") == 0) { |
| 633 | ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 634 | #ifdef CONFIG_WIFI_DISPLAY |
| 635 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { |
Dmitry Shmidt | ed003d2 | 2014-02-06 10:09:12 -0800 | [diff] [blame] | 636 | int enabled = !!atoi(value); |
| 637 | if (enabled && !wpa_s->global->p2p) |
| 638 | ret = -1; |
| 639 | else |
| 640 | wifi_display_enable(wpa_s->global, enabled); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 641 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 642 | } else if (os_strcasecmp(cmd, "bssid_filter") == 0) { |
| 643 | ret = set_bssid_filter(wpa_s, value); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 644 | } else if (os_strcasecmp(cmd, "disallow_aps") == 0) { |
| 645 | ret = set_disallow_aps(wpa_s, value); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 646 | } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) { |
| 647 | wpa_s->no_keep_alive = !!atoi(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 648 | #ifdef CONFIG_DPP |
| 649 | } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) { |
| 650 | os_free(wpa_s->dpp_configurator_params); |
| 651 | wpa_s->dpp_configurator_params = os_strdup(value); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 652 | } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) { |
| 653 | wpa_s->dpp_init_max_tries = atoi(value); |
| 654 | } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) { |
| 655 | wpa_s->dpp_init_retry_time = atoi(value); |
| 656 | } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) { |
| 657 | wpa_s->dpp_resp_wait_time = atoi(value); |
| 658 | } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) { |
| 659 | wpa_s->dpp_resp_max_tries = atoi(value); |
| 660 | } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) { |
| 661 | wpa_s->dpp_resp_retry_time = atoi(value); |
| 662 | #ifdef CONFIG_TESTING_OPTIONS |
| 663 | } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) { |
| 664 | if (hwaddr_aton(value, dpp_pkex_own_mac_override)) |
| 665 | ret = -1; |
| 666 | } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) { |
| 667 | if (hwaddr_aton(value, dpp_pkex_peer_mac_override)) |
| 668 | ret = -1; |
| 669 | } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) { |
| 670 | size_t hex_len = os_strlen(value); |
| 671 | |
| 672 | if (hex_len > |
| 673 | 2 * sizeof(dpp_pkex_ephemeral_key_override)) |
| 674 | ret = -1; |
| 675 | else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override, |
| 676 | hex_len / 2)) |
| 677 | ret = -1; |
| 678 | else |
| 679 | dpp_pkex_ephemeral_key_override_len = hex_len / 2; |
| 680 | } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) { |
| 681 | size_t hex_len = os_strlen(value); |
| 682 | |
| 683 | if (hex_len > 2 * sizeof(dpp_protocol_key_override)) |
| 684 | ret = -1; |
| 685 | else if (hexstr2bin(value, dpp_protocol_key_override, |
| 686 | hex_len / 2)) |
| 687 | ret = -1; |
| 688 | else |
| 689 | dpp_protocol_key_override_len = hex_len / 2; |
| 690 | } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) { |
| 691 | size_t hex_len = os_strlen(value); |
| 692 | |
| 693 | if (hex_len > 2 * sizeof(dpp_nonce_override)) |
| 694 | ret = -1; |
| 695 | else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2)) |
| 696 | ret = -1; |
| 697 | else |
| 698 | dpp_nonce_override_len = hex_len / 2; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 699 | } else if (os_strcasecmp(cmd, "dpp_version_override") == 0) { |
| 700 | dpp_version_override = atoi(value); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 701 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 702 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 703 | #ifdef CONFIG_TESTING_OPTIONS |
| 704 | } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) { |
| 705 | wpa_s->ext_mgmt_frame_handling = !!atoi(value); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 706 | } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) { |
| 707 | wpa_s->ext_eapol_frame_io = !!atoi(value); |
| 708 | #ifdef CONFIG_AP |
| 709 | if (wpa_s->ap_iface) { |
| 710 | wpa_s->ap_iface->bss[0]->ext_eapol_frame_io = |
| 711 | wpa_s->ext_eapol_frame_io; |
| 712 | } |
| 713 | #endif /* CONFIG_AP */ |
| 714 | } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) { |
| 715 | wpa_s->extra_roc_dur = atoi(value); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 716 | } else if (os_strcasecmp(cmd, "test_failure") == 0) { |
| 717 | wpa_s->test_failure = atoi(value); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 718 | } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) { |
| 719 | wpa_s->p2p_go_csa_on_inv = !!atoi(value); |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 720 | } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) { |
| 721 | wpa_s->ignore_auth_resp = !!atoi(value); |
| 722 | } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) { |
| 723 | wpa_s->ignore_assoc_disallow = !!atoi(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 724 | wpa_drv_ignore_assoc_disallow(wpa_s, |
| 725 | wpa_s->ignore_assoc_disallow); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 726 | } else if (os_strcasecmp(cmd, "disable_sa_query") == 0) { |
| 727 | wpa_s->disable_sa_query = !!atoi(value); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 728 | } else if (os_strcasecmp(cmd, "ignore_sae_h2e_only") == 0) { |
| 729 | wpa_s->ignore_sae_h2e_only = !!atoi(value); |
| 730 | } else if (os_strcasecmp(cmd, "extra_sae_rejected_groups") == 0) { |
| 731 | char *pos; |
| 732 | |
| 733 | os_free(wpa_s->extra_sae_rejected_groups); |
| 734 | wpa_s->extra_sae_rejected_groups = NULL; |
| 735 | pos = value; |
| 736 | while (pos && pos[0]) { |
| 737 | int group; |
| 738 | |
| 739 | group = atoi(pos); |
| 740 | wpa_printf(MSG_DEBUG, |
| 741 | "TESTING: Extra rejection of SAE group %d", |
| 742 | group); |
| 743 | if (group) |
| 744 | int_array_add_unique( |
| 745 | &wpa_s->extra_sae_rejected_groups, |
| 746 | group); |
| 747 | pos = os_strchr(pos, ' '); |
| 748 | if (!pos) |
| 749 | break; |
| 750 | pos++; |
| 751 | } |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 752 | } else if (os_strcasecmp(cmd, "ft_rsnxe_used") == 0) { |
| 753 | wpa_s->ft_rsnxe_used = atoi(value); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 754 | } else if (os_strcasecmp(cmd, "rsne_override_eapol") == 0) { |
| 755 | wpabuf_free(wpa_s->rsne_override_eapol); |
| 756 | if (os_strcmp(value, "NULL") == 0) |
| 757 | wpa_s->rsne_override_eapol = NULL; |
| 758 | else |
| 759 | wpa_s->rsne_override_eapol = wpabuf_parse_bin(value); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 760 | } else if (os_strcasecmp(cmd, "rsnxe_override_assoc") == 0) { |
| 761 | wpabuf_free(wpa_s->rsnxe_override_assoc); |
| 762 | if (os_strcmp(value, "NULL") == 0) |
| 763 | wpa_s->rsnxe_override_assoc = NULL; |
| 764 | else |
| 765 | wpa_s->rsnxe_override_assoc = wpabuf_parse_bin(value); |
| 766 | } else if (os_strcasecmp(cmd, "rsnxe_override_eapol") == 0) { |
| 767 | wpabuf_free(wpa_s->rsnxe_override_eapol); |
| 768 | if (os_strcmp(value, "NULL") == 0) |
| 769 | wpa_s->rsnxe_override_eapol = NULL; |
| 770 | else |
| 771 | wpa_s->rsnxe_override_eapol = wpabuf_parse_bin(value); |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 772 | } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) { |
| 773 | wpa_s->reject_btm_req_reason = atoi(value); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 774 | } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) { |
| 775 | os_free(wpa_s->get_pref_freq_list_override); |
| 776 | if (!value[0]) |
| 777 | wpa_s->get_pref_freq_list_override = NULL; |
| 778 | else |
| 779 | wpa_s->get_pref_freq_list_override = os_strdup(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 780 | } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) { |
| 781 | wpabuf_free(wpa_s->sae_commit_override); |
| 782 | if (value[0] == '\0') |
| 783 | wpa_s->sae_commit_override = NULL; |
| 784 | else |
| 785 | wpa_s->sae_commit_override = wpabuf_parse_bin(value); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 786 | } else if (os_strcasecmp(cmd, "driver_signal_override") == 0) { |
| 787 | ret = wpas_ctrl_iface_set_dso(wpa_s, value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 788 | #ifdef CONFIG_DPP |
| 789 | } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) { |
| 790 | os_free(wpa_s->dpp_config_obj_override); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 791 | if (value[0] == '\0') |
| 792 | wpa_s->dpp_config_obj_override = NULL; |
| 793 | else |
| 794 | wpa_s->dpp_config_obj_override = os_strdup(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 795 | } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) { |
| 796 | os_free(wpa_s->dpp_discovery_override); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 797 | if (value[0] == '\0') |
| 798 | wpa_s->dpp_discovery_override = NULL; |
| 799 | else |
| 800 | wpa_s->dpp_discovery_override = os_strdup(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 801 | } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) { |
| 802 | os_free(wpa_s->dpp_groups_override); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 803 | if (value[0] == '\0') |
| 804 | wpa_s->dpp_groups_override = NULL; |
| 805 | else |
| 806 | wpa_s->dpp_groups_override = os_strdup(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 807 | } else if (os_strcasecmp(cmd, |
| 808 | "dpp_ignore_netaccesskey_mismatch") == 0) { |
| 809 | wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 810 | } else if (os_strcasecmp(cmd, "dpp_test") == 0) { |
| 811 | dpp_test = atoi(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 812 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 813 | #endif /* CONFIG_TESTING_OPTIONS */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 814 | #ifdef CONFIG_FILS |
| 815 | } else if (os_strcasecmp(cmd, "disable_fils") == 0) { |
| 816 | wpa_s->disable_fils = !!atoi(value); |
| 817 | wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils); |
| 818 | wpa_supplicant_set_default_scan_ies(wpa_s); |
| 819 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 820 | #ifndef CONFIG_NO_CONFIG_BLOBS |
| 821 | } else if (os_strcmp(cmd, "blob") == 0) { |
| 822 | ret = wpas_ctrl_set_blob(wpa_s, value); |
| 823 | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 824 | } else if (os_strcasecmp(cmd, "setband") == 0) { |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 825 | ret = wpas_ctrl_set_band(wpa_s, value); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 826 | #ifdef CONFIG_MBO |
| 827 | } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) { |
| 828 | ret = wpas_mbo_update_non_pref_chan(wpa_s, value); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 829 | if (ret == 0) { |
| 830 | value[-1] = '='; |
| 831 | wpa_config_process_global(wpa_s->conf, cmd, -1); |
| 832 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 833 | } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) { |
| 834 | wpas_mbo_update_cell_capa(wpa_s, atoi(value)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 835 | } else if (os_strcasecmp(cmd, "oce") == 0) { |
| 836 | wpa_s->conf->oce = atoi(value); |
| 837 | if (wpa_s->conf->oce) { |
| 838 | if ((wpa_s->conf->oce & OCE_STA) && |
| 839 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA)) |
| 840 | wpa_s->enable_oce = OCE_STA; |
| 841 | |
| 842 | if ((wpa_s->conf->oce & OCE_STA_CFON) && |
| 843 | (wpa_s->drv_flags & |
| 844 | WPA_DRIVER_FLAGS_OCE_STA_CFON)) { |
| 845 | /* TODO: Need to add STA-CFON support */ |
| 846 | wpa_printf(MSG_ERROR, |
| 847 | "OCE STA-CFON feature is not yet supported"); |
| 848 | return -1; |
| 849 | } |
| 850 | } else { |
| 851 | wpa_s->enable_oce = 0; |
| 852 | } |
| 853 | wpa_supplicant_set_default_scan_ies(wpa_s); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 854 | #endif /* CONFIG_MBO */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 855 | } else if (os_strcasecmp(cmd, "lci") == 0) { |
| 856 | ret = wpas_ctrl_iface_set_lci(wpa_s, value); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 857 | } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) { |
| 858 | ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value)); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 859 | } else if (os_strcasecmp(cmd, "relative_rssi") == 0) { |
| 860 | ret = wpas_ctrl_set_relative_rssi(wpa_s, value); |
| 861 | } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) { |
| 862 | ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value); |
| 863 | } else if (os_strcasecmp(cmd, "ric_ies") == 0) { |
| 864 | ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 865 | } else if (os_strcasecmp(cmd, "roaming") == 0) { |
| 866 | ret = wpa_drv_roaming(wpa_s, atoi(value), NULL); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 867 | #ifdef CONFIG_WNM |
| 868 | } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) { |
| 869 | struct wpabuf *elems; |
| 870 | |
| 871 | elems = wpabuf_parse_bin(value); |
| 872 | if (!elems) |
| 873 | return -1; |
| 874 | wnm_set_coloc_intf_elems(wpa_s, elems); |
| 875 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 876 | } else { |
| 877 | value[-1] = '='; |
| 878 | ret = wpa_config_process_global(wpa_s->conf, cmd, -1); |
| 879 | if (ret == 0) |
| 880 | wpa_supplicant_update_config(wpa_s); |
| 881 | } |
| 882 | |
| 883 | return ret; |
| 884 | } |
| 885 | |
| 886 | |
| 887 | static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s, |
| 888 | char *cmd, char *buf, size_t buflen) |
| 889 | { |
Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 890 | int res = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 891 | |
| 892 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd); |
| 893 | |
| 894 | if (os_strcmp(cmd, "version") == 0) { |
| 895 | res = os_snprintf(buf, buflen, "%s", VERSION_STR); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 896 | } else if (os_strcasecmp(cmd, "max_command_len") == 0) { |
| 897 | res = os_snprintf(buf, buflen, "%u", CTRL_IFACE_MAX_LEN); |
Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 898 | } else if (os_strcasecmp(cmd, "country") == 0) { |
| 899 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) |
| 900 | res = os_snprintf(buf, buflen, "%c%c", |
| 901 | wpa_s->conf->country[0], |
| 902 | wpa_s->conf->country[1]); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 903 | #ifdef CONFIG_WIFI_DISPLAY |
| 904 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { |
Dmitry Shmidt | ed003d2 | 2014-02-06 10:09:12 -0800 | [diff] [blame] | 905 | int enabled; |
| 906 | if (wpa_s->global->p2p == NULL || |
| 907 | wpa_s->global->p2p_disabled) |
| 908 | enabled = 0; |
| 909 | else |
| 910 | enabled = wpa_s->global->wifi_display; |
| 911 | res = os_snprintf(buf, buflen, "%d", enabled); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 912 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 913 | #ifdef CONFIG_TESTING_GET_GTK |
| 914 | } else if (os_strcmp(cmd, "gtk") == 0) { |
| 915 | if (wpa_s->last_gtk_len == 0) |
| 916 | return -1; |
| 917 | res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk, |
| 918 | wpa_s->last_gtk_len); |
| 919 | return res; |
| 920 | #endif /* CONFIG_TESTING_GET_GTK */ |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 921 | } else if (os_strcmp(cmd, "tls_library") == 0) { |
| 922 | res = tls_get_library_version(buf, buflen); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 923 | #ifdef CONFIG_TESTING_OPTIONS |
| 924 | } else if (os_strcmp(cmd, "anonce") == 0) { |
| 925 | return wpa_snprintf_hex(buf, buflen, |
| 926 | wpa_sm_get_anonce(wpa_s->wpa), |
| 927 | WPA_NONCE_LEN); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 928 | } else if (os_strcasecmp(cmd, "last_tk_key_idx") == 0) { |
| 929 | res = os_snprintf(buf, buflen, "%d", wpa_s->last_tk_key_idx); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 930 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 931 | } else { |
| 932 | res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 935 | if (os_snprintf_error(buflen, res)) |
Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 936 | return -1; |
| 937 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | |
| 941 | #ifdef IEEE8021X_EAPOL |
| 942 | static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s, |
| 943 | char *addr) |
| 944 | { |
| 945 | u8 bssid[ETH_ALEN]; |
| 946 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 947 | |
| 948 | if (hwaddr_aton(addr, bssid)) { |
| 949 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address " |
| 950 | "'%s'", addr); |
| 951 | return -1; |
| 952 | } |
| 953 | |
| 954 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid)); |
| 955 | rsn_preauth_deinit(wpa_s->wpa); |
| 956 | if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL)) |
| 957 | return -1; |
| 958 | |
| 959 | return 0; |
| 960 | } |
| 961 | #endif /* IEEE8021X_EAPOL */ |
| 962 | |
| 963 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 964 | #ifdef CONFIG_TDLS |
| 965 | |
| 966 | static int wpa_supplicant_ctrl_iface_tdls_discover( |
| 967 | struct wpa_supplicant *wpa_s, char *addr) |
| 968 | { |
| 969 | u8 peer[ETH_ALEN]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 970 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 971 | |
| 972 | if (hwaddr_aton(addr, peer)) { |
| 973 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid " |
| 974 | "address '%s'", addr); |
| 975 | return -1; |
| 976 | } |
| 977 | |
| 978 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR, |
| 979 | MAC2STR(peer)); |
| 980 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 981 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 982 | ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer); |
| 983 | else |
| 984 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); |
| 985 | |
| 986 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | |
| 990 | static int wpa_supplicant_ctrl_iface_tdls_setup( |
| 991 | struct wpa_supplicant *wpa_s, char *addr) |
| 992 | { |
| 993 | u8 peer[ETH_ALEN]; |
| 994 | int ret; |
| 995 | |
| 996 | if (hwaddr_aton(addr, peer)) { |
| 997 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid " |
| 998 | "address '%s'", addr); |
| 999 | return -1; |
| 1000 | } |
| 1001 | |
| 1002 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR, |
| 1003 | MAC2STR(peer)); |
| 1004 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1005 | if ((wpa_s->conf->tdls_external_control) && |
| 1006 | wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 1007 | return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); |
| 1008 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1009 | wpa_tdls_remove(wpa_s->wpa, peer); |
| 1010 | |
| 1011 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 1012 | ret = wpa_tdls_start(wpa_s->wpa, peer); |
| 1013 | else |
| 1014 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1015 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1016 | return ret; |
| 1017 | } |
| 1018 | |
| 1019 | |
| 1020 | static int wpa_supplicant_ctrl_iface_tdls_teardown( |
| 1021 | struct wpa_supplicant *wpa_s, char *addr) |
| 1022 | { |
| 1023 | u8 peer[ETH_ALEN]; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 1024 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1025 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 1026 | if (os_strcmp(addr, "*") == 0) { |
| 1027 | /* remove everyone */ |
| 1028 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *"); |
| 1029 | wpa_tdls_teardown_peers(wpa_s->wpa); |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1033 | if (hwaddr_aton(addr, peer)) { |
| 1034 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid " |
| 1035 | "address '%s'", addr); |
| 1036 | return -1; |
| 1037 | } |
| 1038 | |
| 1039 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR, |
| 1040 | MAC2STR(peer)); |
| 1041 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1042 | if ((wpa_s->conf->tdls_external_control) && |
| 1043 | wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 1044 | return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); |
| 1045 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 1046 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 1047 | ret = wpa_tdls_teardown_link( |
| 1048 | wpa_s->wpa, peer, |
| 1049 | WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED); |
| 1050 | else |
| 1051 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); |
| 1052 | |
| 1053 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1056 | |
| 1057 | static int ctrl_iface_get_capability_tdls( |
| 1058 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| 1059 | { |
| 1060 | int ret; |
| 1061 | |
| 1062 | ret = os_snprintf(buf, buflen, "%s\n", |
| 1063 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ? |
| 1064 | (wpa_s->drv_flags & |
| 1065 | WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ? |
| 1066 | "EXTERNAL" : "INTERNAL") : "UNSUPPORTED"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1067 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1068 | return -1; |
| 1069 | return ret; |
| 1070 | } |
| 1071 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1072 | |
| 1073 | static int wpa_supplicant_ctrl_iface_tdls_chan_switch( |
| 1074 | struct wpa_supplicant *wpa_s, char *cmd) |
| 1075 | { |
| 1076 | u8 peer[ETH_ALEN]; |
| 1077 | struct hostapd_freq_params freq_params; |
| 1078 | u8 oper_class; |
| 1079 | char *pos, *end; |
| 1080 | |
| 1081 | if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { |
| 1082 | wpa_printf(MSG_INFO, |
| 1083 | "tdls_chanswitch: Only supported with external setup"); |
| 1084 | return -1; |
| 1085 | } |
| 1086 | |
| 1087 | os_memset(&freq_params, 0, sizeof(freq_params)); |
| 1088 | |
| 1089 | pos = os_strchr(cmd, ' '); |
| 1090 | if (pos == NULL) |
| 1091 | return -1; |
| 1092 | *pos++ = '\0'; |
| 1093 | |
| 1094 | oper_class = strtol(pos, &end, 10); |
| 1095 | if (pos == end) { |
| 1096 | wpa_printf(MSG_INFO, |
| 1097 | "tdls_chanswitch: Invalid op class provided"); |
| 1098 | return -1; |
| 1099 | } |
| 1100 | |
| 1101 | pos = end; |
| 1102 | freq_params.freq = atoi(pos); |
| 1103 | if (freq_params.freq == 0) { |
| 1104 | wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided"); |
| 1105 | return -1; |
| 1106 | } |
| 1107 | |
| 1108 | #define SET_FREQ_SETTING(str) \ |
| 1109 | do { \ |
| 1110 | const char *pos2 = os_strstr(pos, " " #str "="); \ |
| 1111 | if (pos2) { \ |
| 1112 | pos2 += sizeof(" " #str "=") - 1; \ |
| 1113 | freq_params.str = atoi(pos2); \ |
| 1114 | } \ |
| 1115 | } while (0) |
| 1116 | |
| 1117 | SET_FREQ_SETTING(center_freq1); |
| 1118 | SET_FREQ_SETTING(center_freq2); |
| 1119 | SET_FREQ_SETTING(bandwidth); |
| 1120 | SET_FREQ_SETTING(sec_channel_offset); |
| 1121 | #undef SET_FREQ_SETTING |
| 1122 | |
| 1123 | freq_params.ht_enabled = !!os_strstr(pos, " ht"); |
| 1124 | freq_params.vht_enabled = !!os_strstr(pos, " vht"); |
| 1125 | |
| 1126 | if (hwaddr_aton(cmd, peer)) { |
| 1127 | wpa_printf(MSG_DEBUG, |
| 1128 | "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'", |
| 1129 | cmd); |
| 1130 | return -1; |
| 1131 | } |
| 1132 | |
| 1133 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR |
| 1134 | " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s", |
| 1135 | MAC2STR(peer), oper_class, freq_params.freq, |
| 1136 | freq_params.center_freq1, freq_params.center_freq2, |
| 1137 | freq_params.bandwidth, freq_params.sec_channel_offset, |
| 1138 | freq_params.ht_enabled ? " HT" : "", |
| 1139 | freq_params.vht_enabled ? " VHT" : ""); |
| 1140 | |
| 1141 | return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class, |
| 1142 | &freq_params); |
| 1143 | } |
| 1144 | |
| 1145 | |
| 1146 | static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch( |
| 1147 | struct wpa_supplicant *wpa_s, char *cmd) |
| 1148 | { |
| 1149 | u8 peer[ETH_ALEN]; |
| 1150 | |
| 1151 | if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { |
| 1152 | wpa_printf(MSG_INFO, |
| 1153 | "tdls_chanswitch: Only supported with external setup"); |
| 1154 | return -1; |
| 1155 | } |
| 1156 | |
| 1157 | if (hwaddr_aton(cmd, peer)) { |
| 1158 | wpa_printf(MSG_DEBUG, |
| 1159 | "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'", |
| 1160 | cmd); |
| 1161 | return -1; |
| 1162 | } |
| 1163 | |
| 1164 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR, |
| 1165 | MAC2STR(peer)); |
| 1166 | |
| 1167 | return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer); |
| 1168 | } |
| 1169 | |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 1170 | |
| 1171 | static int wpa_supplicant_ctrl_iface_tdls_link_status( |
| 1172 | struct wpa_supplicant *wpa_s, const char *addr, |
| 1173 | char *buf, size_t buflen) |
| 1174 | { |
| 1175 | u8 peer[ETH_ALEN]; |
| 1176 | const char *tdls_status; |
| 1177 | int ret; |
| 1178 | |
| 1179 | if (hwaddr_aton(addr, peer)) { |
| 1180 | wpa_printf(MSG_DEBUG, |
| 1181 | "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'", |
| 1182 | addr); |
| 1183 | return -1; |
| 1184 | } |
| 1185 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR, |
| 1186 | MAC2STR(peer)); |
| 1187 | |
| 1188 | tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer); |
| 1189 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status); |
| 1190 | ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status); |
| 1191 | if (os_snprintf_error(buflen, ret)) |
| 1192 | return -1; |
| 1193 | |
| 1194 | return ret; |
| 1195 | } |
| 1196 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1197 | #endif /* CONFIG_TDLS */ |
| 1198 | |
| 1199 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1200 | static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd) |
| 1201 | { |
| 1202 | char *token, *context = NULL; |
| 1203 | struct wmm_ac_ts_setup_params params = { |
| 1204 | .tsid = 0xff, |
| 1205 | .direction = 0xff, |
| 1206 | }; |
| 1207 | |
| 1208 | while ((token = str_token(cmd, " ", &context))) { |
| 1209 | if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 || |
| 1210 | sscanf(token, "up=%i", ¶ms.user_priority) == 1 || |
| 1211 | sscanf(token, "nominal_msdu_size=%i", |
| 1212 | ¶ms.nominal_msdu_size) == 1 || |
| 1213 | sscanf(token, "mean_data_rate=%i", |
| 1214 | ¶ms.mean_data_rate) == 1 || |
| 1215 | sscanf(token, "min_phy_rate=%i", |
| 1216 | ¶ms.minimum_phy_rate) == 1 || |
| 1217 | sscanf(token, "sba=%i", |
| 1218 | ¶ms.surplus_bandwidth_allowance) == 1) |
| 1219 | continue; |
| 1220 | |
| 1221 | if (os_strcasecmp(token, "downlink") == 0) { |
| 1222 | params.direction = WMM_TSPEC_DIRECTION_DOWNLINK; |
| 1223 | } else if (os_strcasecmp(token, "uplink") == 0) { |
| 1224 | params.direction = WMM_TSPEC_DIRECTION_UPLINK; |
| 1225 | } else if (os_strcasecmp(token, "bidi") == 0) { |
| 1226 | params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL; |
| 1227 | } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) { |
| 1228 | params.fixed_nominal_msdu = 1; |
| 1229 | } else { |
| 1230 | wpa_printf(MSG_DEBUG, |
| 1231 | "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'", |
| 1232 | token); |
| 1233 | return -1; |
| 1234 | } |
| 1235 | |
| 1236 | } |
| 1237 | |
| 1238 | return wpas_wmm_ac_addts(wpa_s, ¶ms); |
| 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd) |
| 1243 | { |
| 1244 | u8 tsid = atoi(cmd); |
| 1245 | |
| 1246 | return wpas_wmm_ac_delts(wpa_s, tsid); |
| 1247 | } |
| 1248 | |
| 1249 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1250 | #ifdef CONFIG_IEEE80211R |
| 1251 | static int wpa_supplicant_ctrl_iface_ft_ds( |
| 1252 | struct wpa_supplicant *wpa_s, char *addr) |
| 1253 | { |
| 1254 | u8 target_ap[ETH_ALEN]; |
| 1255 | struct wpa_bss *bss; |
| 1256 | const u8 *mdie; |
| 1257 | |
| 1258 | if (hwaddr_aton(addr, target_ap)) { |
| 1259 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid " |
| 1260 | "address '%s'", addr); |
| 1261 | return -1; |
| 1262 | } |
| 1263 | |
| 1264 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap)); |
| 1265 | |
| 1266 | bss = wpa_bss_get_bssid(wpa_s, target_ap); |
| 1267 | if (bss) |
| 1268 | mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); |
| 1269 | else |
| 1270 | mdie = NULL; |
| 1271 | |
| 1272 | return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie); |
| 1273 | } |
| 1274 | #endif /* CONFIG_IEEE80211R */ |
| 1275 | |
| 1276 | |
| 1277 | #ifdef CONFIG_WPS |
| 1278 | static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s, |
| 1279 | char *cmd) |
| 1280 | { |
| 1281 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1282 | #ifdef CONFIG_P2P |
| 1283 | u8 p2p_dev_addr[ETH_ALEN]; |
| 1284 | #endif /* CONFIG_P2P */ |
| 1285 | #ifdef CONFIG_AP |
| 1286 | u8 *_p2p_dev_addr = NULL; |
| 1287 | #endif /* CONFIG_AP */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1288 | char *pos; |
| 1289 | int multi_ap = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1290 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1291 | if (!cmd || os_strcmp(cmd, "any") == 0 || |
| 1292 | os_strncmp(cmd, "any ", 4) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1293 | _bssid = NULL; |
| 1294 | #ifdef CONFIG_P2P |
| 1295 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { |
| 1296 | if (hwaddr_aton(cmd + 13, p2p_dev_addr)) { |
| 1297 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid " |
| 1298 | "P2P Device Address '%s'", |
| 1299 | cmd + 13); |
| 1300 | return -1; |
| 1301 | } |
| 1302 | _p2p_dev_addr = p2p_dev_addr; |
| 1303 | #endif /* CONFIG_P2P */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1304 | } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) { |
| 1305 | _bssid = NULL; |
| 1306 | multi_ap = atoi(cmd + 9); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1307 | } else if (hwaddr_aton(cmd, bssid)) { |
| 1308 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'", |
| 1309 | cmd); |
| 1310 | return -1; |
| 1311 | } |
| 1312 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1313 | if (cmd) { |
| 1314 | pos = os_strstr(cmd, " multi_ap="); |
| 1315 | if (pos) { |
| 1316 | pos += 10; |
| 1317 | multi_ap = atoi(pos); |
| 1318 | } |
| 1319 | } |
| 1320 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1321 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1322 | if (wpa_s->ap_iface) |
| 1323 | return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr); |
| 1324 | #endif /* CONFIG_AP */ |
| 1325 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1326 | return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | |
| 1330 | static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, |
| 1331 | char *cmd, char *buf, |
| 1332 | size_t buflen) |
| 1333 | { |
| 1334 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
| 1335 | char *pin; |
| 1336 | int ret; |
| 1337 | |
| 1338 | pin = os_strchr(cmd, ' '); |
| 1339 | if (pin) |
| 1340 | *pin++ = '\0'; |
| 1341 | |
| 1342 | if (os_strcmp(cmd, "any") == 0) |
| 1343 | _bssid = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1344 | else if (os_strcmp(cmd, "get") == 0) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1345 | if (wps_generate_pin((unsigned int *) &ret) < 0) |
| 1346 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1347 | goto done; |
| 1348 | } else if (hwaddr_aton(cmd, bssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1349 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'", |
| 1350 | cmd); |
| 1351 | return -1; |
| 1352 | } |
| 1353 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1354 | #ifdef CONFIG_AP |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1355 | if (wpa_s->ap_iface) { |
| 1356 | int timeout = 0; |
| 1357 | char *pos; |
| 1358 | |
| 1359 | if (pin) { |
| 1360 | pos = os_strchr(pin, ' '); |
| 1361 | if (pos) { |
| 1362 | *pos++ = '\0'; |
| 1363 | timeout = atoi(pos); |
| 1364 | } |
| 1365 | } |
| 1366 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1367 | return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1368 | buf, buflen, timeout); |
| 1369 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1370 | #endif /* CONFIG_AP */ |
| 1371 | |
| 1372 | if (pin) { |
| 1373 | ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0, |
| 1374 | DEV_PW_DEFAULT); |
| 1375 | if (ret < 0) |
| 1376 | return -1; |
| 1377 | ret = os_snprintf(buf, buflen, "%s", pin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1378 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1379 | return -1; |
| 1380 | return ret; |
| 1381 | } |
| 1382 | |
| 1383 | ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT); |
| 1384 | if (ret < 0) |
| 1385 | return -1; |
| 1386 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1387 | done: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1388 | /* Return the generated PIN */ |
| 1389 | ret = os_snprintf(buf, buflen, "%08d", ret); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1390 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1391 | return -1; |
| 1392 | return ret; |
| 1393 | } |
| 1394 | |
| 1395 | |
| 1396 | static int wpa_supplicant_ctrl_iface_wps_check_pin( |
| 1397 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| 1398 | { |
| 1399 | char pin[9]; |
| 1400 | size_t len; |
| 1401 | char *pos; |
| 1402 | int ret; |
| 1403 | |
| 1404 | wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN", |
| 1405 | (u8 *) cmd, os_strlen(cmd)); |
| 1406 | for (pos = cmd, len = 0; *pos != '\0'; pos++) { |
| 1407 | if (*pos < '0' || *pos > '9') |
| 1408 | continue; |
| 1409 | pin[len++] = *pos; |
| 1410 | if (len == 9) { |
| 1411 | wpa_printf(MSG_DEBUG, "WPS: Too long PIN"); |
| 1412 | return -1; |
| 1413 | } |
| 1414 | } |
| 1415 | if (len != 4 && len != 8) { |
| 1416 | wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len); |
| 1417 | return -1; |
| 1418 | } |
| 1419 | pin[len] = '\0'; |
| 1420 | |
| 1421 | if (len == 8) { |
| 1422 | unsigned int pin_val; |
| 1423 | pin_val = atoi(pin); |
| 1424 | if (!wps_pin_valid(pin_val)) { |
| 1425 | wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit"); |
| 1426 | ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1427 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1428 | return -1; |
| 1429 | return ret; |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | ret = os_snprintf(buf, buflen, "%s", pin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1434 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1435 | return -1; |
| 1436 | |
| 1437 | return ret; |
| 1438 | } |
| 1439 | |
| 1440 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1441 | #ifdef CONFIG_WPS_NFC |
| 1442 | |
| 1443 | static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s, |
| 1444 | char *cmd) |
| 1445 | { |
| 1446 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
| 1447 | |
| 1448 | if (cmd == NULL || cmd[0] == '\0') |
| 1449 | _bssid = NULL; |
| 1450 | else if (hwaddr_aton(cmd, bssid)) |
| 1451 | return -1; |
| 1452 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1453 | return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL, |
| 1454 | 0, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1458 | static int wpa_supplicant_ctrl_iface_wps_nfc_config_token( |
| 1459 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| 1460 | { |
| 1461 | int ndef; |
| 1462 | struct wpabuf *buf; |
| 1463 | int res; |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1464 | char *pos; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1465 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1466 | pos = os_strchr(cmd, ' '); |
| 1467 | if (pos) |
| 1468 | *pos++ = '\0'; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1469 | if (os_strcmp(cmd, "WPS") == 0) |
| 1470 | ndef = 0; |
| 1471 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1472 | ndef = 1; |
| 1473 | else |
| 1474 | return -1; |
| 1475 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1476 | buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1477 | if (buf == NULL) |
| 1478 | return -1; |
| 1479 | |
| 1480 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1481 | wpabuf_len(buf)); |
| 1482 | reply[res++] = '\n'; |
| 1483 | reply[res] = '\0'; |
| 1484 | |
| 1485 | wpabuf_free(buf); |
| 1486 | |
| 1487 | return res; |
| 1488 | } |
| 1489 | |
| 1490 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1491 | static int wpa_supplicant_ctrl_iface_wps_nfc_token( |
| 1492 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| 1493 | { |
| 1494 | int ndef; |
| 1495 | struct wpabuf *buf; |
| 1496 | int res; |
| 1497 | |
| 1498 | if (os_strcmp(cmd, "WPS") == 0) |
| 1499 | ndef = 0; |
| 1500 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1501 | ndef = 1; |
| 1502 | else |
| 1503 | return -1; |
| 1504 | |
| 1505 | buf = wpas_wps_nfc_token(wpa_s, ndef); |
| 1506 | if (buf == NULL) |
| 1507 | return -1; |
| 1508 | |
| 1509 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1510 | wpabuf_len(buf)); |
| 1511 | reply[res++] = '\n'; |
| 1512 | reply[res] = '\0'; |
| 1513 | |
| 1514 | wpabuf_free(buf); |
| 1515 | |
| 1516 | return res; |
| 1517 | } |
| 1518 | |
| 1519 | |
| 1520 | static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read( |
| 1521 | struct wpa_supplicant *wpa_s, char *pos) |
| 1522 | { |
| 1523 | size_t len; |
| 1524 | struct wpabuf *buf; |
| 1525 | int ret; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1526 | char *freq; |
| 1527 | int forced_freq = 0; |
| 1528 | |
| 1529 | freq = strstr(pos, " freq="); |
| 1530 | if (freq) { |
| 1531 | *freq = '\0'; |
| 1532 | freq += 6; |
| 1533 | forced_freq = atoi(freq); |
| 1534 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1535 | |
| 1536 | len = os_strlen(pos); |
| 1537 | if (len & 0x01) |
| 1538 | return -1; |
| 1539 | len /= 2; |
| 1540 | |
| 1541 | buf = wpabuf_alloc(len); |
| 1542 | if (buf == NULL) |
| 1543 | return -1; |
| 1544 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { |
| 1545 | wpabuf_free(buf); |
| 1546 | return -1; |
| 1547 | } |
| 1548 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1549 | ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1550 | wpabuf_free(buf); |
| 1551 | |
| 1552 | return ret; |
| 1553 | } |
| 1554 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1555 | |
| 1556 | static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1557 | char *reply, size_t max_len, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1558 | int ndef) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1559 | { |
| 1560 | struct wpabuf *buf; |
| 1561 | int res; |
| 1562 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1563 | buf = wpas_wps_nfc_handover_req(wpa_s, ndef); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1564 | if (buf == NULL) |
| 1565 | return -1; |
| 1566 | |
| 1567 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1568 | wpabuf_len(buf)); |
| 1569 | reply[res++] = '\n'; |
| 1570 | reply[res] = '\0'; |
| 1571 | |
| 1572 | wpabuf_free(buf); |
| 1573 | |
| 1574 | return res; |
| 1575 | } |
| 1576 | |
| 1577 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1578 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1579 | static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s, |
| 1580 | char *reply, size_t max_len, |
| 1581 | int ndef) |
| 1582 | { |
| 1583 | struct wpabuf *buf; |
| 1584 | int res; |
| 1585 | |
| 1586 | buf = wpas_p2p_nfc_handover_req(wpa_s, ndef); |
| 1587 | if (buf == NULL) { |
| 1588 | wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request"); |
| 1589 | return -1; |
| 1590 | } |
| 1591 | |
| 1592 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1593 | wpabuf_len(buf)); |
| 1594 | reply[res++] = '\n'; |
| 1595 | reply[res] = '\0'; |
| 1596 | |
| 1597 | wpabuf_free(buf); |
| 1598 | |
| 1599 | return res; |
| 1600 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1601 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1602 | |
| 1603 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1604 | static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s, |
| 1605 | char *cmd, char *reply, |
| 1606 | size_t max_len) |
| 1607 | { |
| 1608 | char *pos; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1609 | int ndef; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1610 | |
| 1611 | pos = os_strchr(cmd, ' '); |
| 1612 | if (pos == NULL) |
| 1613 | return -1; |
| 1614 | *pos++ = '\0'; |
| 1615 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1616 | if (os_strcmp(cmd, "WPS") == 0) |
| 1617 | ndef = 0; |
| 1618 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1619 | ndef = 1; |
| 1620 | else |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1621 | return -1; |
| 1622 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1623 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1624 | if (!ndef) |
| 1625 | return -1; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1626 | return wpas_ctrl_nfc_get_handover_req_wps( |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1627 | wpa_s, reply, max_len, ndef); |
| 1628 | } |
| 1629 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1630 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1631 | if (os_strcmp(pos, "P2P-CR") == 0) { |
| 1632 | return wpas_ctrl_nfc_get_handover_req_p2p( |
| 1633 | wpa_s, reply, max_len, ndef); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1634 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1635 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1636 | |
| 1637 | return -1; |
| 1638 | } |
| 1639 | |
| 1640 | |
| 1641 | static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1642 | char *reply, size_t max_len, |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1643 | int ndef, int cr, char *uuid) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1644 | { |
| 1645 | struct wpabuf *buf; |
| 1646 | int res; |
| 1647 | |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1648 | buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1649 | if (buf == NULL) |
| 1650 | return -1; |
| 1651 | |
| 1652 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1653 | wpabuf_len(buf)); |
| 1654 | reply[res++] = '\n'; |
| 1655 | reply[res] = '\0'; |
| 1656 | |
| 1657 | wpabuf_free(buf); |
| 1658 | |
| 1659 | return res; |
| 1660 | } |
| 1661 | |
| 1662 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1663 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1664 | static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s, |
| 1665 | char *reply, size_t max_len, |
| 1666 | int ndef, int tag) |
| 1667 | { |
| 1668 | struct wpabuf *buf; |
| 1669 | int res; |
| 1670 | |
| 1671 | buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag); |
| 1672 | if (buf == NULL) |
| 1673 | return -1; |
| 1674 | |
| 1675 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1676 | wpabuf_len(buf)); |
| 1677 | reply[res++] = '\n'; |
| 1678 | reply[res] = '\0'; |
| 1679 | |
| 1680 | wpabuf_free(buf); |
| 1681 | |
| 1682 | return res; |
| 1683 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1684 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1685 | |
| 1686 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1687 | static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s, |
| 1688 | char *cmd, char *reply, |
| 1689 | size_t max_len) |
| 1690 | { |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1691 | char *pos, *pos2; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1692 | int ndef; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1693 | |
| 1694 | pos = os_strchr(cmd, ' '); |
| 1695 | if (pos == NULL) |
| 1696 | return -1; |
| 1697 | *pos++ = '\0'; |
| 1698 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1699 | if (os_strcmp(cmd, "WPS") == 0) |
| 1700 | ndef = 0; |
| 1701 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1702 | ndef = 1; |
| 1703 | else |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1704 | return -1; |
| 1705 | |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1706 | pos2 = os_strchr(pos, ' '); |
| 1707 | if (pos2) |
| 1708 | *pos2++ = '\0'; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1709 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1710 | if (!ndef) |
| 1711 | return -1; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1712 | return wpas_ctrl_nfc_get_handover_sel_wps( |
| 1713 | wpa_s, reply, max_len, ndef, |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1714 | os_strcmp(pos, "WPS-CR") == 0, pos2); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1715 | } |
| 1716 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1717 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1718 | if (os_strcmp(pos, "P2P-CR") == 0) { |
| 1719 | return wpas_ctrl_nfc_get_handover_sel_p2p( |
| 1720 | wpa_s, reply, max_len, ndef, 0); |
| 1721 | } |
| 1722 | |
| 1723 | if (os_strcmp(pos, "P2P-CR-TAG") == 0) { |
| 1724 | return wpas_ctrl_nfc_get_handover_sel_p2p( |
| 1725 | wpa_s, reply, max_len, ndef, 1); |
| 1726 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1727 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1728 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1729 | return -1; |
| 1730 | } |
| 1731 | |
| 1732 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1733 | static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s, |
| 1734 | char *cmd) |
| 1735 | { |
| 1736 | size_t len; |
| 1737 | struct wpabuf *req, *sel; |
| 1738 | int ret; |
| 1739 | char *pos, *role, *type, *pos2; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1740 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1741 | char *freq; |
| 1742 | int forced_freq = 0; |
| 1743 | |
| 1744 | freq = strstr(cmd, " freq="); |
| 1745 | if (freq) { |
| 1746 | *freq = '\0'; |
| 1747 | freq += 6; |
| 1748 | forced_freq = atoi(freq); |
| 1749 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1750 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1751 | |
| 1752 | role = cmd; |
| 1753 | pos = os_strchr(role, ' '); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1754 | if (pos == NULL) { |
| 1755 | wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1756 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1757 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1758 | *pos++ = '\0'; |
| 1759 | |
| 1760 | type = pos; |
| 1761 | pos = os_strchr(type, ' '); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1762 | if (pos == NULL) { |
| 1763 | wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1764 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1765 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1766 | *pos++ = '\0'; |
| 1767 | |
| 1768 | pos2 = os_strchr(pos, ' '); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1769 | if (pos2 == NULL) { |
| 1770 | wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1771 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1772 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1773 | *pos2++ = '\0'; |
| 1774 | |
| 1775 | len = os_strlen(pos); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1776 | if (len & 0x01) { |
| 1777 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1778 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1779 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1780 | len /= 2; |
| 1781 | |
| 1782 | req = wpabuf_alloc(len); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1783 | if (req == NULL) { |
| 1784 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1785 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1786 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1787 | if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1788 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1789 | wpabuf_free(req); |
| 1790 | return -1; |
| 1791 | } |
| 1792 | |
| 1793 | len = os_strlen(pos2); |
| 1794 | if (len & 0x01) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1795 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1796 | wpabuf_free(req); |
| 1797 | return -1; |
| 1798 | } |
| 1799 | len /= 2; |
| 1800 | |
| 1801 | sel = wpabuf_alloc(len); |
| 1802 | if (sel == NULL) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1803 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1804 | wpabuf_free(req); |
| 1805 | return -1; |
| 1806 | } |
| 1807 | if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1808 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1809 | wpabuf_free(req); |
| 1810 | wpabuf_free(sel); |
| 1811 | return -1; |
| 1812 | } |
| 1813 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1814 | wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d", |
| 1815 | role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel)); |
| 1816 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1817 | if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) { |
| 1818 | ret = wpas_wps_nfc_report_handover(wpa_s, req, sel); |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1819 | #ifdef CONFIG_AP |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1820 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) |
| 1821 | { |
| 1822 | ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel); |
| 1823 | if (ret < 0) |
| 1824 | ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel); |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1825 | #endif /* CONFIG_AP */ |
| 1826 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1827 | } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0) |
| 1828 | { |
| 1829 | ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0); |
| 1830 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0) |
| 1831 | { |
| 1832 | ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel, |
| 1833 | forced_freq); |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1834 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1835 | } else { |
| 1836 | wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover " |
| 1837 | "reported: role=%s type=%s", role, type); |
| 1838 | ret = -1; |
| 1839 | } |
| 1840 | wpabuf_free(req); |
| 1841 | wpabuf_free(sel); |
| 1842 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1843 | if (ret) |
| 1844 | wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages"); |
| 1845 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1846 | return ret; |
| 1847 | } |
| 1848 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1849 | #endif /* CONFIG_WPS_NFC */ |
| 1850 | |
| 1851 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1852 | static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s, |
| 1853 | char *cmd) |
| 1854 | { |
| 1855 | u8 bssid[ETH_ALEN]; |
| 1856 | char *pin; |
| 1857 | char *new_ssid; |
| 1858 | char *new_auth; |
| 1859 | char *new_encr; |
| 1860 | char *new_key; |
| 1861 | struct wps_new_ap_settings ap; |
| 1862 | |
| 1863 | pin = os_strchr(cmd, ' '); |
| 1864 | if (pin == NULL) |
| 1865 | return -1; |
| 1866 | *pin++ = '\0'; |
| 1867 | |
| 1868 | if (hwaddr_aton(cmd, bssid)) { |
| 1869 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'", |
| 1870 | cmd); |
| 1871 | return -1; |
| 1872 | } |
| 1873 | |
| 1874 | new_ssid = os_strchr(pin, ' '); |
| 1875 | if (new_ssid == NULL) |
| 1876 | return wpas_wps_start_reg(wpa_s, bssid, pin, NULL); |
| 1877 | *new_ssid++ = '\0'; |
| 1878 | |
| 1879 | new_auth = os_strchr(new_ssid, ' '); |
| 1880 | if (new_auth == NULL) |
| 1881 | return -1; |
| 1882 | *new_auth++ = '\0'; |
| 1883 | |
| 1884 | new_encr = os_strchr(new_auth, ' '); |
| 1885 | if (new_encr == NULL) |
| 1886 | return -1; |
| 1887 | *new_encr++ = '\0'; |
| 1888 | |
| 1889 | new_key = os_strchr(new_encr, ' '); |
| 1890 | if (new_key == NULL) |
| 1891 | return -1; |
| 1892 | *new_key++ = '\0'; |
| 1893 | |
| 1894 | os_memset(&ap, 0, sizeof(ap)); |
| 1895 | ap.ssid_hex = new_ssid; |
| 1896 | ap.auth = new_auth; |
| 1897 | ap.encr = new_encr; |
| 1898 | ap.key_hex = new_key; |
| 1899 | return wpas_wps_start_reg(wpa_s, bssid, pin, &ap); |
| 1900 | } |
| 1901 | |
| 1902 | |
| 1903 | #ifdef CONFIG_AP |
| 1904 | static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s, |
| 1905 | char *cmd, char *buf, |
| 1906 | size_t buflen) |
| 1907 | { |
| 1908 | int timeout = 300; |
| 1909 | char *pos; |
| 1910 | const char *pin_txt; |
| 1911 | |
| 1912 | if (!wpa_s->ap_iface) |
| 1913 | return -1; |
| 1914 | |
| 1915 | pos = os_strchr(cmd, ' '); |
| 1916 | if (pos) |
| 1917 | *pos++ = '\0'; |
| 1918 | |
| 1919 | if (os_strcmp(cmd, "disable") == 0) { |
| 1920 | wpas_wps_ap_pin_disable(wpa_s); |
| 1921 | return os_snprintf(buf, buflen, "OK\n"); |
| 1922 | } |
| 1923 | |
| 1924 | if (os_strcmp(cmd, "random") == 0) { |
| 1925 | if (pos) |
| 1926 | timeout = atoi(pos); |
| 1927 | pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout); |
| 1928 | if (pin_txt == NULL) |
| 1929 | return -1; |
| 1930 | return os_snprintf(buf, buflen, "%s", pin_txt); |
| 1931 | } |
| 1932 | |
| 1933 | if (os_strcmp(cmd, "get") == 0) { |
| 1934 | pin_txt = wpas_wps_ap_pin_get(wpa_s); |
| 1935 | if (pin_txt == NULL) |
| 1936 | return -1; |
| 1937 | return os_snprintf(buf, buflen, "%s", pin_txt); |
| 1938 | } |
| 1939 | |
| 1940 | if (os_strcmp(cmd, "set") == 0) { |
| 1941 | char *pin; |
| 1942 | if (pos == NULL) |
| 1943 | return -1; |
| 1944 | pin = pos; |
| 1945 | pos = os_strchr(pos, ' '); |
| 1946 | if (pos) { |
| 1947 | *pos++ = '\0'; |
| 1948 | timeout = atoi(pos); |
| 1949 | } |
| 1950 | if (os_strlen(pin) > buflen) |
| 1951 | return -1; |
| 1952 | if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0) |
| 1953 | return -1; |
| 1954 | return os_snprintf(buf, buflen, "%s", pin); |
| 1955 | } |
| 1956 | |
| 1957 | return -1; |
| 1958 | } |
| 1959 | #endif /* CONFIG_AP */ |
| 1960 | |
| 1961 | |
| 1962 | #ifdef CONFIG_WPS_ER |
| 1963 | static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s, |
| 1964 | char *cmd) |
| 1965 | { |
| 1966 | char *uuid = cmd, *pin, *pos; |
| 1967 | u8 addr_buf[ETH_ALEN], *addr = NULL; |
| 1968 | pin = os_strchr(uuid, ' '); |
| 1969 | if (pin == NULL) |
| 1970 | return -1; |
| 1971 | *pin++ = '\0'; |
| 1972 | pos = os_strchr(pin, ' '); |
| 1973 | if (pos) { |
| 1974 | *pos++ = '\0'; |
| 1975 | if (hwaddr_aton(pos, addr_buf) == 0) |
| 1976 | addr = addr_buf; |
| 1977 | } |
| 1978 | return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin); |
| 1979 | } |
| 1980 | |
| 1981 | |
| 1982 | static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s, |
| 1983 | char *cmd) |
| 1984 | { |
| 1985 | char *uuid = cmd, *pin; |
| 1986 | pin = os_strchr(uuid, ' '); |
| 1987 | if (pin == NULL) |
| 1988 | return -1; |
| 1989 | *pin++ = '\0'; |
| 1990 | return wpas_wps_er_learn(wpa_s, uuid, pin); |
| 1991 | } |
| 1992 | |
| 1993 | |
| 1994 | static int wpa_supplicant_ctrl_iface_wps_er_set_config( |
| 1995 | struct wpa_supplicant *wpa_s, char *cmd) |
| 1996 | { |
| 1997 | char *uuid = cmd, *id; |
| 1998 | id = os_strchr(uuid, ' '); |
| 1999 | if (id == NULL) |
| 2000 | return -1; |
| 2001 | *id++ = '\0'; |
| 2002 | return wpas_wps_er_set_config(wpa_s, uuid, atoi(id)); |
| 2003 | } |
| 2004 | |
| 2005 | |
| 2006 | static int wpa_supplicant_ctrl_iface_wps_er_config( |
| 2007 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2008 | { |
| 2009 | char *pin; |
| 2010 | char *new_ssid; |
| 2011 | char *new_auth; |
| 2012 | char *new_encr; |
| 2013 | char *new_key; |
| 2014 | struct wps_new_ap_settings ap; |
| 2015 | |
| 2016 | pin = os_strchr(cmd, ' '); |
| 2017 | if (pin == NULL) |
| 2018 | return -1; |
| 2019 | *pin++ = '\0'; |
| 2020 | |
| 2021 | new_ssid = os_strchr(pin, ' '); |
| 2022 | if (new_ssid == NULL) |
| 2023 | return -1; |
| 2024 | *new_ssid++ = '\0'; |
| 2025 | |
| 2026 | new_auth = os_strchr(new_ssid, ' '); |
| 2027 | if (new_auth == NULL) |
| 2028 | return -1; |
| 2029 | *new_auth++ = '\0'; |
| 2030 | |
| 2031 | new_encr = os_strchr(new_auth, ' '); |
| 2032 | if (new_encr == NULL) |
| 2033 | return -1; |
| 2034 | *new_encr++ = '\0'; |
| 2035 | |
| 2036 | new_key = os_strchr(new_encr, ' '); |
| 2037 | if (new_key == NULL) |
| 2038 | return -1; |
| 2039 | *new_key++ = '\0'; |
| 2040 | |
| 2041 | os_memset(&ap, 0, sizeof(ap)); |
| 2042 | ap.ssid_hex = new_ssid; |
| 2043 | ap.auth = new_auth; |
| 2044 | ap.encr = new_encr; |
| 2045 | ap.key_hex = new_key; |
| 2046 | return wpas_wps_er_config(wpa_s, cmd, pin, &ap); |
| 2047 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2048 | |
| 2049 | |
| 2050 | #ifdef CONFIG_WPS_NFC |
| 2051 | static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( |
| 2052 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| 2053 | { |
| 2054 | int ndef; |
| 2055 | struct wpabuf *buf; |
| 2056 | int res; |
| 2057 | char *uuid; |
| 2058 | |
| 2059 | uuid = os_strchr(cmd, ' '); |
| 2060 | if (uuid == NULL) |
| 2061 | return -1; |
| 2062 | *uuid++ = '\0'; |
| 2063 | |
| 2064 | if (os_strcmp(cmd, "WPS") == 0) |
| 2065 | ndef = 0; |
| 2066 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 2067 | ndef = 1; |
| 2068 | else |
| 2069 | return -1; |
| 2070 | |
| 2071 | buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid); |
| 2072 | if (buf == NULL) |
| 2073 | return -1; |
| 2074 | |
| 2075 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 2076 | wpabuf_len(buf)); |
| 2077 | reply[res++] = '\n'; |
| 2078 | reply[res] = '\0'; |
| 2079 | |
| 2080 | wpabuf_free(buf); |
| 2081 | |
| 2082 | return res; |
| 2083 | } |
| 2084 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2085 | #endif /* CONFIG_WPS_ER */ |
| 2086 | |
| 2087 | #endif /* CONFIG_WPS */ |
| 2088 | |
| 2089 | |
| 2090 | #ifdef CONFIG_IBSS_RSN |
| 2091 | static int wpa_supplicant_ctrl_iface_ibss_rsn( |
| 2092 | struct wpa_supplicant *wpa_s, char *addr) |
| 2093 | { |
| 2094 | u8 peer[ETH_ALEN]; |
| 2095 | |
| 2096 | if (hwaddr_aton(addr, peer)) { |
| 2097 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid " |
| 2098 | "address '%s'", addr); |
| 2099 | return -1; |
| 2100 | } |
| 2101 | |
| 2102 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR, |
| 2103 | MAC2STR(peer)); |
| 2104 | |
| 2105 | return ibss_rsn_start(wpa_s->ibss_rsn, peer); |
| 2106 | } |
| 2107 | #endif /* CONFIG_IBSS_RSN */ |
| 2108 | |
| 2109 | |
| 2110 | static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, |
| 2111 | char *rsp) |
| 2112 | { |
| 2113 | #ifdef IEEE8021X_EAPOL |
| 2114 | char *pos, *id_pos; |
| 2115 | int id; |
| 2116 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2117 | |
| 2118 | pos = os_strchr(rsp, '-'); |
| 2119 | if (pos == NULL) |
| 2120 | return -1; |
| 2121 | *pos++ = '\0'; |
| 2122 | id_pos = pos; |
| 2123 | pos = os_strchr(pos, ':'); |
| 2124 | if (pos == NULL) |
| 2125 | return -1; |
| 2126 | *pos++ = '\0'; |
| 2127 | id = atoi(id_pos); |
| 2128 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); |
| 2129 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", |
| 2130 | (u8 *) pos, os_strlen(pos)); |
| 2131 | |
| 2132 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 2133 | if (ssid == NULL) { |
| 2134 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 2135 | "to update", id); |
| 2136 | return -1; |
| 2137 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2138 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2139 | return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp, |
| 2140 | pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2141 | #else /* IEEE8021X_EAPOL */ |
| 2142 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); |
| 2143 | return -1; |
| 2144 | #endif /* IEEE8021X_EAPOL */ |
| 2145 | } |
| 2146 | |
| 2147 | |
| 2148 | static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, |
| 2149 | const char *params, |
| 2150 | char *buf, size_t buflen) |
| 2151 | { |
| 2152 | char *pos, *end, tmp[30]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2153 | int res, verbose, wps, ret; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2154 | #ifdef CONFIG_HS20 |
| 2155 | const u8 *hs20; |
| 2156 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2157 | const u8 *sess_id; |
| 2158 | size_t sess_id_len; |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 2159 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2160 | if (os_strcmp(params, "-DRIVER") == 0) |
| 2161 | return wpa_drv_status(wpa_s, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2162 | verbose = os_strcmp(params, "-VERBOSE") == 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2163 | wps = os_strcmp(params, "-WPS") == 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2164 | pos = buf; |
| 2165 | end = buf + buflen; |
| 2166 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { |
| 2167 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 2168 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", |
| 2169 | MAC2STR(wpa_s->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2170 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2171 | return pos - buf; |
| 2172 | pos += ret; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2173 | ret = os_snprintf(pos, end - pos, "freq=%u\n", |
| 2174 | wpa_s->assoc_freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2175 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2176 | return pos - buf; |
| 2177 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2178 | if (ssid) { |
| 2179 | u8 *_ssid = ssid->ssid; |
| 2180 | size_t ssid_len = ssid->ssid_len; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 2181 | u8 ssid_buf[SSID_MAX_LEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2182 | if (ssid_len == 0) { |
| 2183 | int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); |
| 2184 | if (_res < 0) |
| 2185 | ssid_len = 0; |
| 2186 | else |
| 2187 | ssid_len = _res; |
| 2188 | _ssid = ssid_buf; |
| 2189 | } |
| 2190 | ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", |
| 2191 | wpa_ssid_txt(_ssid, ssid_len), |
| 2192 | ssid->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2193 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2194 | return pos - buf; |
| 2195 | pos += ret; |
| 2196 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2197 | if (wps && ssid->passphrase && |
| 2198 | wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && |
| 2199 | (ssid->mode == WPAS_MODE_AP || |
| 2200 | ssid->mode == WPAS_MODE_P2P_GO)) { |
| 2201 | ret = os_snprintf(pos, end - pos, |
| 2202 | "passphrase=%s\n", |
| 2203 | ssid->passphrase); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2204 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2205 | return pos - buf; |
| 2206 | pos += ret; |
| 2207 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2208 | if (ssid->id_str) { |
| 2209 | ret = os_snprintf(pos, end - pos, |
| 2210 | "id_str=%s\n", |
| 2211 | ssid->id_str); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2212 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2213 | return pos - buf; |
| 2214 | pos += ret; |
| 2215 | } |
| 2216 | |
| 2217 | switch (ssid->mode) { |
| 2218 | case WPAS_MODE_INFRA: |
| 2219 | ret = os_snprintf(pos, end - pos, |
| 2220 | "mode=station\n"); |
| 2221 | break; |
| 2222 | case WPAS_MODE_IBSS: |
| 2223 | ret = os_snprintf(pos, end - pos, |
| 2224 | "mode=IBSS\n"); |
| 2225 | break; |
| 2226 | case WPAS_MODE_AP: |
| 2227 | ret = os_snprintf(pos, end - pos, |
| 2228 | "mode=AP\n"); |
| 2229 | break; |
| 2230 | case WPAS_MODE_P2P_GO: |
| 2231 | ret = os_snprintf(pos, end - pos, |
| 2232 | "mode=P2P GO\n"); |
| 2233 | break; |
| 2234 | case WPAS_MODE_P2P_GROUP_FORMATION: |
| 2235 | ret = os_snprintf(pos, end - pos, |
| 2236 | "mode=P2P GO - group " |
| 2237 | "formation\n"); |
| 2238 | break; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 2239 | case WPAS_MODE_MESH: |
| 2240 | ret = os_snprintf(pos, end - pos, |
| 2241 | "mode=mesh\n"); |
| 2242 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2243 | default: |
| 2244 | ret = 0; |
| 2245 | break; |
| 2246 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2247 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2248 | return pos - buf; |
| 2249 | pos += ret; |
| 2250 | } |
| 2251 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2252 | if (wpa_s->connection_set && |
| 2253 | (wpa_s->connection_ht || wpa_s->connection_vht || |
| 2254 | wpa_s->connection_he)) { |
| 2255 | ret = os_snprintf(pos, end - pos, |
| 2256 | "wifi_generation=%u\n", |
| 2257 | wpa_s->connection_he ? 6 : |
| 2258 | (wpa_s->connection_vht ? 5 : 4)); |
| 2259 | if (os_snprintf_error(end - pos, ret)) |
| 2260 | return pos - buf; |
| 2261 | pos += ret; |
| 2262 | } |
| 2263 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2264 | #ifdef CONFIG_AP |
| 2265 | if (wpa_s->ap_iface) { |
| 2266 | pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos, |
| 2267 | end - pos, |
| 2268 | verbose); |
| 2269 | } else |
| 2270 | #endif /* CONFIG_AP */ |
| 2271 | pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); |
| 2272 | } |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2273 | #ifdef CONFIG_SME |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2274 | #ifdef CONFIG_SAE |
| 2275 | if (wpa_s->wpa_state >= WPA_ASSOCIATED && |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2276 | #ifdef CONFIG_AP |
| 2277 | !wpa_s->ap_iface && |
| 2278 | #endif /* CONFIG_AP */ |
| 2279 | wpa_s->sme.sae.state == SAE_ACCEPTED) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2280 | ret = os_snprintf(pos, end - pos, "sae_group=%d\n", |
| 2281 | wpa_s->sme.sae.group); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2282 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2283 | return pos - buf; |
| 2284 | pos += ret; |
| 2285 | } |
| 2286 | #endif /* CONFIG_SAE */ |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2287 | #endif /* CONFIG_SME */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2288 | ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", |
| 2289 | wpa_supplicant_state_txt(wpa_s->wpa_state)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2290 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2291 | return pos - buf; |
| 2292 | pos += ret; |
| 2293 | |
| 2294 | if (wpa_s->l2 && |
| 2295 | l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { |
| 2296 | ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2297 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2298 | return pos - buf; |
| 2299 | pos += ret; |
| 2300 | } |
| 2301 | |
| 2302 | #ifdef CONFIG_P2P |
| 2303 | if (wpa_s->global->p2p) { |
| 2304 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR |
| 2305 | "\n", MAC2STR(wpa_s->global->p2p_dev_addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2306 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2307 | return pos - buf; |
| 2308 | pos += ret; |
| 2309 | } |
| 2310 | #endif /* CONFIG_P2P */ |
| 2311 | |
| 2312 | ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n", |
| 2313 | MAC2STR(wpa_s->own_addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2314 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2315 | return pos - buf; |
| 2316 | pos += ret; |
| 2317 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2318 | #ifdef CONFIG_HS20 |
| 2319 | if (wpa_s->current_bss && |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2320 | (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss, |
| 2321 | HS20_IE_VENDOR_TYPE)) && |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2322 | wpa_s->wpa_proto == WPA_PROTO_RSN && |
| 2323 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2324 | int release = 1; |
| 2325 | if (hs20[1] >= 5) { |
| 2326 | u8 rel_num = (hs20[6] & 0xf0) >> 4; |
| 2327 | release = rel_num + 1; |
| 2328 | } |
| 2329 | ret = os_snprintf(pos, end - pos, "hs20=%d\n", release); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2330 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2331 | return pos - buf; |
| 2332 | pos += ret; |
| 2333 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2334 | |
| 2335 | if (wpa_s->current_ssid) { |
| 2336 | struct wpa_cred *cred; |
| 2337 | char *type; |
| 2338 | |
| 2339 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2340 | size_t i; |
| 2341 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2342 | if (wpa_s->current_ssid->parent_cred != cred) |
| 2343 | continue; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2344 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2345 | if (cred->provisioning_sp) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2346 | ret = os_snprintf(pos, end - pos, |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2347 | "provisioning_sp=%s\n", |
| 2348 | cred->provisioning_sp); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2349 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2350 | return pos - buf; |
| 2351 | pos += ret; |
| 2352 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2353 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2354 | if (!cred->domain) |
| 2355 | goto no_domain; |
| 2356 | |
| 2357 | i = 0; |
| 2358 | if (wpa_s->current_bss && wpa_s->current_bss->anqp) { |
| 2359 | struct wpabuf *names = |
| 2360 | wpa_s->current_bss->anqp->domain_name; |
| 2361 | for (i = 0; names && i < cred->num_domain; i++) |
| 2362 | { |
| 2363 | if (domain_name_list_contains( |
| 2364 | names, cred->domain[i], 1)) |
| 2365 | break; |
| 2366 | } |
| 2367 | if (i == cred->num_domain) |
| 2368 | i = 0; /* show first entry by default */ |
| 2369 | } |
| 2370 | ret = os_snprintf(pos, end - pos, "home_sp=%s\n", |
| 2371 | cred->domain[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2372 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2373 | return pos - buf; |
| 2374 | pos += ret; |
| 2375 | |
| 2376 | no_domain: |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2377 | if (wpa_s->current_bss == NULL || |
| 2378 | wpa_s->current_bss->anqp == NULL) |
| 2379 | res = -1; |
| 2380 | else |
| 2381 | res = interworking_home_sp_cred( |
| 2382 | wpa_s, cred, |
| 2383 | wpa_s->current_bss->anqp->domain_name); |
| 2384 | if (res > 0) |
| 2385 | type = "home"; |
| 2386 | else if (res == 0) |
| 2387 | type = "roaming"; |
| 2388 | else |
| 2389 | type = "unknown"; |
| 2390 | |
| 2391 | ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2392 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2393 | return pos - buf; |
| 2394 | pos += ret; |
| 2395 | |
| 2396 | break; |
| 2397 | } |
| 2398 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2399 | #endif /* CONFIG_HS20 */ |
| 2400 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2401 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
| 2402 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
| 2403 | res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, |
| 2404 | verbose); |
| 2405 | if (res >= 0) |
| 2406 | pos += res; |
| 2407 | } |
| 2408 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2409 | #ifdef CONFIG_MACSEC |
| 2410 | res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos); |
| 2411 | if (res > 0) |
| 2412 | pos += res; |
| 2413 | #endif /* CONFIG_MACSEC */ |
| 2414 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2415 | sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len); |
| 2416 | if (sess_id) { |
| 2417 | char *start = pos; |
| 2418 | |
| 2419 | ret = os_snprintf(pos, end - pos, "eap_session_id="); |
| 2420 | if (os_snprintf_error(end - pos, ret)) |
| 2421 | return start - buf; |
| 2422 | pos += ret; |
| 2423 | ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len); |
| 2424 | if (ret <= 0) |
| 2425 | return start - buf; |
| 2426 | pos += ret; |
| 2427 | ret = os_snprintf(pos, end - pos, "\n"); |
| 2428 | if (os_snprintf_error(end - pos, ret)) |
| 2429 | return start - buf; |
| 2430 | pos += ret; |
| 2431 | } |
| 2432 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2433 | res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); |
| 2434 | if (res >= 0) |
| 2435 | pos += res; |
| 2436 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2437 | #ifdef CONFIG_WPS |
| 2438 | { |
| 2439 | char uuid_str[100]; |
| 2440 | uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str)); |
| 2441 | ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2442 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2443 | return pos - buf; |
| 2444 | pos += ret; |
| 2445 | } |
| 2446 | #endif /* CONFIG_WPS */ |
| 2447 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2448 | if (wpa_s->ieee80211ac) { |
| 2449 | ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n"); |
| 2450 | if (os_snprintf_error(end - pos, ret)) |
| 2451 | return pos - buf; |
| 2452 | pos += ret; |
| 2453 | } |
| 2454 | |
Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 2455 | #ifdef ANDROID |
vandwalle | ffc7018 | 2014-09-11 11:40:14 -0700 | [diff] [blame] | 2456 | /* |
| 2457 | * Allow using the STATUS command with default behavior, say for debug, |
| 2458 | * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE |
| 2459 | * events with STATUS-NO_EVENTS. |
| 2460 | */ |
| 2461 | if (os_strcmp(params, "-NO_EVENTS")) { |
| 2462 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE |
| 2463 | "id=%d state=%d BSSID=" MACSTR " SSID=%s", |
| 2464 | wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, |
| 2465 | wpa_s->wpa_state, |
| 2466 | MAC2STR(wpa_s->bssid), |
| 2467 | wpa_s->current_ssid && wpa_s->current_ssid->ssid ? |
| 2468 | wpa_ssid_txt(wpa_s->current_ssid->ssid, |
| 2469 | wpa_s->current_ssid->ssid_len) : ""); |
| 2470 | if (wpa_s->wpa_state == WPA_COMPLETED) { |
| 2471 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 2472 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED |
| 2473 | "- connection to " MACSTR |
| 2474 | " completed %s [id=%d id_str=%s]", |
| 2475 | MAC2STR(wpa_s->bssid), "(auth)", |
| 2476 | ssid ? ssid->id : -1, |
| 2477 | ssid && ssid->id_str ? ssid->id_str : ""); |
| 2478 | } |
Irfan Sheriff | bf5edf4 | 2012-01-11 16:54:57 -0800 | [diff] [blame] | 2479 | } |
Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 2480 | #endif /* ANDROID */ |
| 2481 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2482 | return pos - buf; |
| 2483 | } |
| 2484 | |
| 2485 | |
| 2486 | static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, |
| 2487 | char *cmd) |
| 2488 | { |
| 2489 | char *pos; |
| 2490 | int id; |
| 2491 | struct wpa_ssid *ssid; |
| 2492 | u8 bssid[ETH_ALEN]; |
| 2493 | |
| 2494 | /* cmd: "<network id> <BSSID>" */ |
| 2495 | pos = os_strchr(cmd, ' '); |
| 2496 | if (pos == NULL) |
| 2497 | return -1; |
| 2498 | *pos++ = '\0'; |
| 2499 | id = atoi(cmd); |
| 2500 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); |
| 2501 | if (hwaddr_aton(pos, bssid)) { |
| 2502 | wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); |
| 2503 | return -1; |
| 2504 | } |
| 2505 | |
| 2506 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 2507 | if (ssid == NULL) { |
| 2508 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 2509 | "to update", id); |
| 2510 | return -1; |
| 2511 | } |
| 2512 | |
| 2513 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); |
| 2514 | ssid->bssid_set = !is_zero_ether_addr(bssid); |
| 2515 | |
| 2516 | return 0; |
| 2517 | } |
| 2518 | |
| 2519 | |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2520 | static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2521 | char *cmd, char *buf, |
| 2522 | size_t buflen) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2523 | { |
| 2524 | u8 bssid[ETH_ALEN]; |
| 2525 | struct wpa_blacklist *e; |
| 2526 | char *pos, *end; |
| 2527 | int ret; |
| 2528 | |
| 2529 | /* cmd: "BLACKLIST [<BSSID>]" */ |
| 2530 | if (*cmd == '\0') { |
| 2531 | pos = buf; |
| 2532 | end = buf + buflen; |
| 2533 | e = wpa_s->blacklist; |
| 2534 | while (e) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2535 | ret = os_snprintf(pos, end - pos, MACSTR "\n", |
| 2536 | MAC2STR(e->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2537 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2538 | return pos - buf; |
| 2539 | pos += ret; |
| 2540 | e = e->next; |
| 2541 | } |
| 2542 | return pos - buf; |
| 2543 | } |
| 2544 | |
| 2545 | cmd++; |
| 2546 | if (os_strncmp(cmd, "clear", 5) == 0) { |
| 2547 | wpa_blacklist_clear(wpa_s); |
| 2548 | os_memcpy(buf, "OK\n", 3); |
| 2549 | return 3; |
| 2550 | } |
| 2551 | |
| 2552 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd); |
| 2553 | if (hwaddr_aton(cmd, bssid)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2554 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd); |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2555 | return -1; |
| 2556 | } |
| 2557 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2558 | /* |
| 2559 | * Add the BSSID twice, so its count will be 2, causing it to be |
| 2560 | * skipped when processing scan results. |
| 2561 | */ |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2562 | ret = wpa_blacklist_add(wpa_s, bssid); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2563 | if (ret < 0) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2564 | return -1; |
| 2565 | ret = wpa_blacklist_add(wpa_s, bssid); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2566 | if (ret < 0) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2567 | return -1; |
| 2568 | os_memcpy(buf, "OK\n", 3); |
| 2569 | return 3; |
| 2570 | } |
| 2571 | |
| 2572 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2573 | static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s, |
| 2574 | char *cmd, char *buf, |
| 2575 | size_t buflen) |
| 2576 | { |
| 2577 | char *pos, *end, *stamp; |
| 2578 | int ret; |
| 2579 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2580 | /* cmd: "LOG_LEVEL [<level>]" */ |
| 2581 | if (*cmd == '\0') { |
| 2582 | pos = buf; |
| 2583 | end = buf + buflen; |
| 2584 | ret = os_snprintf(pos, end - pos, "Current level: %s\n" |
| 2585 | "Timestamp: %d\n", |
| 2586 | debug_level_str(wpa_debug_level), |
| 2587 | wpa_debug_timestamp); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2588 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2589 | ret = 0; |
| 2590 | |
| 2591 | return ret; |
| 2592 | } |
| 2593 | |
| 2594 | while (*cmd == ' ') |
| 2595 | cmd++; |
| 2596 | |
| 2597 | stamp = os_strchr(cmd, ' '); |
| 2598 | if (stamp) { |
| 2599 | *stamp++ = '\0'; |
| 2600 | while (*stamp == ' ') { |
| 2601 | stamp++; |
| 2602 | } |
| 2603 | } |
| 2604 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2605 | if (os_strlen(cmd)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2606 | int level = str_to_debug_level(cmd); |
| 2607 | if (level < 0) |
| 2608 | return -1; |
| 2609 | wpa_debug_level = level; |
| 2610 | } |
| 2611 | |
| 2612 | if (stamp && os_strlen(stamp)) |
| 2613 | wpa_debug_timestamp = atoi(stamp); |
| 2614 | |
| 2615 | os_memcpy(buf, "OK\n", 3); |
| 2616 | return 3; |
| 2617 | } |
| 2618 | |
| 2619 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2620 | static int wpa_supplicant_ctrl_iface_list_networks( |
Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 2621 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2622 | { |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2623 | char *pos, *end, *prev; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2624 | struct wpa_ssid *ssid; |
| 2625 | int ret; |
| 2626 | |
| 2627 | pos = buf; |
| 2628 | end = buf + buflen; |
| 2629 | ret = os_snprintf(pos, end - pos, |
| 2630 | "network id / ssid / bssid / flags\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2631 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2632 | return pos - buf; |
| 2633 | pos += ret; |
| 2634 | |
| 2635 | ssid = wpa_s->conf->ssid; |
Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 2636 | |
| 2637 | /* skip over ssids until we find next one */ |
| 2638 | if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) { |
| 2639 | int last_id = atoi(cmd + 8); |
| 2640 | if (last_id != -1) { |
| 2641 | while (ssid != NULL && ssid->id <= last_id) { |
| 2642 | ssid = ssid->next; |
| 2643 | } |
| 2644 | } |
| 2645 | } |
| 2646 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2647 | while (ssid) { |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2648 | prev = pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2649 | ret = os_snprintf(pos, end - pos, "%d\t%s", |
| 2650 | ssid->id, |
| 2651 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2652 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2653 | return prev - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2654 | pos += ret; |
| 2655 | if (ssid->bssid_set) { |
| 2656 | ret = os_snprintf(pos, end - pos, "\t" MACSTR, |
| 2657 | MAC2STR(ssid->bssid)); |
| 2658 | } else { |
| 2659 | ret = os_snprintf(pos, end - pos, "\tany"); |
| 2660 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2661 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2662 | return prev - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2663 | pos += ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2664 | ret = os_snprintf(pos, end - pos, "\t%s%s%s%s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2665 | ssid == wpa_s->current_ssid ? |
| 2666 | "[CURRENT]" : "", |
| 2667 | ssid->disabled ? "[DISABLED]" : "", |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2668 | ssid->disabled_until.sec ? |
| 2669 | "[TEMP-DISABLED]" : "", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2670 | ssid->disabled == 2 ? "[P2P-PERSISTENT]" : |
| 2671 | ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2672 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2673 | return prev - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2674 | pos += ret; |
| 2675 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2676 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2677 | return prev - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2678 | pos += ret; |
| 2679 | |
| 2680 | ssid = ssid->next; |
| 2681 | } |
| 2682 | |
| 2683 | return pos - buf; |
| 2684 | } |
| 2685 | |
| 2686 | |
| 2687 | static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) |
| 2688 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2689 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2690 | ret = os_snprintf(pos, end - pos, "-"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2691 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2692 | return pos; |
| 2693 | pos += ret; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2694 | ret = wpa_write_ciphers(pos, end, cipher, "+"); |
| 2695 | if (ret < 0) |
| 2696 | return pos; |
| 2697 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2698 | return pos; |
| 2699 | } |
| 2700 | |
| 2701 | |
| 2702 | static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, |
| 2703 | const u8 *ie, size_t ie_len) |
| 2704 | { |
| 2705 | struct wpa_ie_data data; |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2706 | char *start; |
| 2707 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2708 | |
| 2709 | ret = os_snprintf(pos, end - pos, "[%s-", proto); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2710 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2711 | return pos; |
| 2712 | pos += ret; |
| 2713 | |
| 2714 | if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { |
| 2715 | ret = os_snprintf(pos, end - pos, "?]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2716 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2717 | return pos; |
| 2718 | pos += ret; |
| 2719 | return pos; |
| 2720 | } |
| 2721 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2722 | start = pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2723 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2724 | ret = os_snprintf(pos, end - pos, "%sEAP", |
| 2725 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2726 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2727 | return pos; |
| 2728 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2729 | } |
| 2730 | if (data.key_mgmt & WPA_KEY_MGMT_PSK) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2731 | ret = os_snprintf(pos, end - pos, "%sPSK", |
| 2732 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2733 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2734 | return pos; |
| 2735 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2736 | } |
| 2737 | if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2738 | ret = os_snprintf(pos, end - pos, "%sNone", |
| 2739 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2740 | if (os_snprintf_error(end - pos, ret)) |
| 2741 | return pos; |
| 2742 | pos += ret; |
| 2743 | } |
| 2744 | if (data.key_mgmt & WPA_KEY_MGMT_SAE) { |
| 2745 | ret = os_snprintf(pos, end - pos, "%sSAE", |
| 2746 | pos == start ? "" : "+"); |
| 2747 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2748 | return pos; |
| 2749 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2750 | } |
| 2751 | #ifdef CONFIG_IEEE80211R |
| 2752 | if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { |
| 2753 | ret = os_snprintf(pos, end - pos, "%sFT/EAP", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2754 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2755 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2756 | return pos; |
| 2757 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2758 | } |
| 2759 | if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { |
| 2760 | ret = os_snprintf(pos, end - pos, "%sFT/PSK", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2761 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2762 | if (os_snprintf_error(end - pos, ret)) |
| 2763 | return pos; |
| 2764 | pos += ret; |
| 2765 | } |
| 2766 | if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) { |
| 2767 | ret = os_snprintf(pos, end - pos, "%sFT/SAE", |
| 2768 | pos == start ? "" : "+"); |
| 2769 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2770 | return pos; |
| 2771 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2772 | } |
| 2773 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2774 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { |
| 2775 | ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2776 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2777 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2778 | return pos; |
| 2779 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2780 | } |
| 2781 | if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { |
| 2782 | ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2783 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2784 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2785 | return pos; |
| 2786 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2787 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2788 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2789 | #ifdef CONFIG_SUITEB |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2790 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
| 2791 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B", |
| 2792 | pos == start ? "" : "+"); |
| 2793 | if (os_snprintf_error(end - pos, ret)) |
| 2794 | return pos; |
| 2795 | pos += ret; |
| 2796 | } |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2797 | #endif /* CONFIG_SUITEB */ |
| 2798 | |
| 2799 | #ifdef CONFIG_SUITEB192 |
| 2800 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
| 2801 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192", |
| 2802 | pos == start ? "" : "+"); |
| 2803 | if (os_snprintf_error(end - pos, ret)) |
| 2804 | return pos; |
| 2805 | pos += ret; |
| 2806 | } |
| 2807 | #endif /* CONFIG_SUITEB192 */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2808 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2809 | #ifdef CONFIG_FILS |
| 2810 | if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) { |
| 2811 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA256", |
| 2812 | pos == start ? "" : "+"); |
| 2813 | if (os_snprintf_error(end - pos, ret)) |
| 2814 | return pos; |
| 2815 | pos += ret; |
| 2816 | } |
| 2817 | if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) { |
| 2818 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA384", |
| 2819 | pos == start ? "" : "+"); |
| 2820 | if (os_snprintf_error(end - pos, ret)) |
| 2821 | return pos; |
| 2822 | pos += ret; |
| 2823 | } |
| 2824 | #ifdef CONFIG_IEEE80211R |
| 2825 | if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) { |
| 2826 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256", |
| 2827 | pos == start ? "" : "+"); |
| 2828 | if (os_snprintf_error(end - pos, ret)) |
| 2829 | return pos; |
| 2830 | pos += ret; |
| 2831 | } |
| 2832 | if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) { |
| 2833 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384", |
| 2834 | pos == start ? "" : "+"); |
| 2835 | if (os_snprintf_error(end - pos, ret)) |
| 2836 | return pos; |
| 2837 | pos += ret; |
| 2838 | } |
| 2839 | #endif /* CONFIG_IEEE80211R */ |
| 2840 | #endif /* CONFIG_FILS */ |
| 2841 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2842 | #ifdef CONFIG_OWE |
| 2843 | if (data.key_mgmt & WPA_KEY_MGMT_OWE) { |
| 2844 | ret = os_snprintf(pos, end - pos, "%sOWE", |
| 2845 | pos == start ? "" : "+"); |
| 2846 | if (os_snprintf_error(end - pos, ret)) |
| 2847 | return pos; |
| 2848 | pos += ret; |
| 2849 | } |
| 2850 | #endif /* CONFIG_OWE */ |
| 2851 | |
| 2852 | #ifdef CONFIG_DPP |
| 2853 | if (data.key_mgmt & WPA_KEY_MGMT_DPP) { |
| 2854 | ret = os_snprintf(pos, end - pos, "%sDPP", |
| 2855 | pos == start ? "" : "+"); |
| 2856 | if (os_snprintf_error(end - pos, ret)) |
| 2857 | return pos; |
| 2858 | pos += ret; |
| 2859 | } |
| 2860 | #endif /* CONFIG_DPP */ |
| 2861 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2862 | if (data.key_mgmt & WPA_KEY_MGMT_OSEN) { |
| 2863 | ret = os_snprintf(pos, end - pos, "%sOSEN", |
| 2864 | pos == start ? "" : "+"); |
| 2865 | if (os_snprintf_error(end - pos, ret)) |
| 2866 | return pos; |
| 2867 | pos += ret; |
| 2868 | } |
| 2869 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2870 | pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); |
| 2871 | |
| 2872 | if (data.capabilities & WPA_CAPABILITY_PREAUTH) { |
| 2873 | ret = os_snprintf(pos, end - pos, "-preauth"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2874 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2875 | return pos; |
| 2876 | pos += ret; |
| 2877 | } |
| 2878 | |
| 2879 | ret = os_snprintf(pos, end - pos, "]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2880 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2881 | return pos; |
| 2882 | pos += ret; |
| 2883 | |
| 2884 | return pos; |
| 2885 | } |
| 2886 | |
| 2887 | |
| 2888 | #ifdef CONFIG_WPS |
| 2889 | static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, |
| 2890 | char *pos, char *end, |
| 2891 | struct wpabuf *wps_ie) |
| 2892 | { |
| 2893 | int ret; |
| 2894 | const char *txt; |
| 2895 | |
| 2896 | if (wps_ie == NULL) |
| 2897 | return pos; |
| 2898 | if (wps_is_selected_pbc_registrar(wps_ie)) |
| 2899 | txt = "[WPS-PBC]"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2900 | else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) |
| 2901 | txt = "[WPS-AUTH]"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2902 | else if (wps_is_selected_pin_registrar(wps_ie)) |
| 2903 | txt = "[WPS-PIN]"; |
| 2904 | else |
| 2905 | txt = "[WPS]"; |
| 2906 | |
| 2907 | ret = os_snprintf(pos, end - pos, "%s", txt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2908 | if (!os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2909 | pos += ret; |
| 2910 | wpabuf_free(wps_ie); |
| 2911 | return pos; |
| 2912 | } |
| 2913 | #endif /* CONFIG_WPS */ |
| 2914 | |
| 2915 | |
| 2916 | static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, |
| 2917 | char *pos, char *end, |
| 2918 | const struct wpa_bss *bss) |
| 2919 | { |
| 2920 | #ifdef CONFIG_WPS |
| 2921 | struct wpabuf *wps_ie; |
| 2922 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
| 2923 | return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); |
| 2924 | #else /* CONFIG_WPS */ |
| 2925 | return pos; |
| 2926 | #endif /* CONFIG_WPS */ |
| 2927 | } |
| 2928 | |
| 2929 | |
| 2930 | /* Format one result on one text line into a buffer. */ |
| 2931 | static int wpa_supplicant_ctrl_iface_scan_result( |
| 2932 | struct wpa_supplicant *wpa_s, |
| 2933 | const struct wpa_bss *bss, char *buf, size_t buflen) |
| 2934 | { |
| 2935 | char *pos, *end; |
| 2936 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2937 | const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2938 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2939 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2940 | p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2941 | if (!p2p) |
| 2942 | p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2943 | if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && |
| 2944 | os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == |
| 2945 | 0) |
| 2946 | return 0; /* Do not show P2P listen discovery results here */ |
| 2947 | |
| 2948 | pos = buf; |
| 2949 | end = buf + buflen; |
| 2950 | |
| 2951 | ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", |
| 2952 | MAC2STR(bss->bssid), bss->freq, bss->level); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2953 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2954 | return -1; |
| 2955 | pos += ret; |
| 2956 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 2957 | if (ie) |
| 2958 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); |
| 2959 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2960 | if (ie2) { |
| 2961 | pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2", |
| 2962 | ie2, 2 + ie2[1]); |
| 2963 | } |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2964 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
| 2965 | if (osen_ie) |
| 2966 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", |
| 2967 | osen_ie, 2 + osen_ie[1]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2968 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
| 2969 | if (owe) { |
| 2970 | ret = os_snprintf(pos, end - pos, |
| 2971 | ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]"); |
| 2972 | if (os_snprintf_error(end - pos, ret)) |
| 2973 | return -1; |
| 2974 | pos += ret; |
| 2975 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2976 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2977 | if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2978 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2979 | if (os_snprintf_error(end - pos, ret)) |
| 2980 | return -1; |
| 2981 | pos += ret; |
| 2982 | } |
| 2983 | if (mesh) { |
| 2984 | ret = os_snprintf(pos, end - pos, "[MESH]"); |
| 2985 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2986 | return -1; |
| 2987 | pos += ret; |
| 2988 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 2989 | if (bss_is_dmg(bss)) { |
| 2990 | const char *s; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2991 | |
| 2992 | if (get_ie_ext((const u8 *) (bss + 1), bss->ie_len, |
| 2993 | WLAN_EID_EXT_EDMG_OPERATION)) { |
| 2994 | ret = os_snprintf(pos, end - pos, "[EDMG]"); |
| 2995 | if (os_snprintf_error(end - pos, ret)) |
| 2996 | return -1; |
| 2997 | pos += ret; |
| 2998 | } |
| 2999 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3000 | ret = os_snprintf(pos, end - pos, "[DMG]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3001 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3002 | return -1; |
| 3003 | pos += ret; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3004 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
| 3005 | case IEEE80211_CAP_DMG_IBSS: |
| 3006 | s = "[IBSS]"; |
| 3007 | break; |
| 3008 | case IEEE80211_CAP_DMG_AP: |
| 3009 | s = "[ESS]"; |
| 3010 | break; |
| 3011 | case IEEE80211_CAP_DMG_PBSS: |
| 3012 | s = "[PBSS]"; |
| 3013 | break; |
| 3014 | default: |
| 3015 | s = ""; |
| 3016 | break; |
| 3017 | } |
| 3018 | ret = os_snprintf(pos, end - pos, "%s", s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3019 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3020 | return -1; |
| 3021 | pos += ret; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3022 | } else { |
| 3023 | if (bss->caps & IEEE80211_CAP_IBSS) { |
| 3024 | ret = os_snprintf(pos, end - pos, "[IBSS]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3025 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3026 | return -1; |
| 3027 | pos += ret; |
| 3028 | } |
| 3029 | if (bss->caps & IEEE80211_CAP_ESS) { |
| 3030 | ret = os_snprintf(pos, end - pos, "[ESS]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3031 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3032 | return -1; |
| 3033 | pos += ret; |
| 3034 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3035 | } |
| 3036 | if (p2p) { |
| 3037 | ret = os_snprintf(pos, end - pos, "[P2P]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3038 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3039 | return -1; |
| 3040 | pos += ret; |
| 3041 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3042 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3043 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3044 | ret = os_snprintf(pos, end - pos, "[HS20]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3045 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3046 | return -1; |
| 3047 | pos += ret; |
| 3048 | } |
| 3049 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3050 | #ifdef CONFIG_FILS |
| 3051 | if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) { |
| 3052 | ret = os_snprintf(pos, end - pos, "[FILS]"); |
| 3053 | if (os_snprintf_error(end - pos, ret)) |
| 3054 | return -1; |
| 3055 | pos += ret; |
| 3056 | } |
| 3057 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3058 | #ifdef CONFIG_FST |
| 3059 | if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) { |
| 3060 | ret = os_snprintf(pos, end - pos, "[FST]"); |
| 3061 | if (os_snprintf_error(end - pos, ret)) |
| 3062 | return -1; |
| 3063 | pos += ret; |
| 3064 | } |
| 3065 | #endif /* CONFIG_FST */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3066 | if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) { |
| 3067 | ret = os_snprintf(pos, end - pos, "[UTF-8]"); |
| 3068 | if (os_snprintf_error(end - pos, ret)) |
| 3069 | return -1; |
| 3070 | pos += ret; |
| 3071 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3072 | |
| 3073 | ret = os_snprintf(pos, end - pos, "\t%s", |
| 3074 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3075 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3076 | return -1; |
| 3077 | pos += ret; |
| 3078 | |
| 3079 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3080 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3081 | return -1; |
| 3082 | pos += ret; |
| 3083 | |
| 3084 | return pos - buf; |
| 3085 | } |
| 3086 | |
| 3087 | |
| 3088 | static int wpa_supplicant_ctrl_iface_scan_results( |
| 3089 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| 3090 | { |
| 3091 | char *pos, *end; |
| 3092 | struct wpa_bss *bss; |
| 3093 | int ret; |
| 3094 | |
| 3095 | pos = buf; |
| 3096 | end = buf + buflen; |
| 3097 | ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " |
| 3098 | "flags / ssid\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3099 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3100 | return pos - buf; |
| 3101 | pos += ret; |
| 3102 | |
| 3103 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
| 3104 | ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, |
| 3105 | end - pos); |
| 3106 | if (ret < 0 || ret >= end - pos) |
| 3107 | return pos - buf; |
| 3108 | pos += ret; |
| 3109 | } |
| 3110 | |
| 3111 | return pos - buf; |
| 3112 | } |
| 3113 | |
| 3114 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3115 | #ifdef CONFIG_MESH |
| 3116 | |
| 3117 | static int wpa_supplicant_ctrl_iface_mesh_interface_add( |
| 3118 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| 3119 | { |
| 3120 | char *pos, ifname[IFNAMSIZ + 1]; |
| 3121 | |
| 3122 | ifname[0] = '\0'; |
| 3123 | |
| 3124 | pos = os_strstr(cmd, "ifname="); |
| 3125 | if (pos) { |
| 3126 | pos += 7; |
| 3127 | os_strlcpy(ifname, pos, sizeof(ifname)); |
| 3128 | } |
| 3129 | |
| 3130 | if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0) |
| 3131 | return -1; |
| 3132 | |
| 3133 | os_strlcpy(reply, ifname, max_len); |
| 3134 | return os_strlen(ifname); |
| 3135 | } |
| 3136 | |
| 3137 | |
| 3138 | static int wpa_supplicant_ctrl_iface_mesh_group_add( |
| 3139 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3140 | { |
| 3141 | int id; |
| 3142 | struct wpa_ssid *ssid; |
| 3143 | |
| 3144 | id = atoi(cmd); |
| 3145 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id); |
| 3146 | |
| 3147 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3148 | if (ssid == NULL) { |
| 3149 | wpa_printf(MSG_DEBUG, |
| 3150 | "CTRL_IFACE: Could not find network id=%d", id); |
| 3151 | return -1; |
| 3152 | } |
| 3153 | if (ssid->mode != WPAS_MODE_MESH) { |
| 3154 | wpa_printf(MSG_DEBUG, |
| 3155 | "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network"); |
| 3156 | return -1; |
| 3157 | } |
| 3158 | if (ssid->key_mgmt != WPA_KEY_MGMT_NONE && |
| 3159 | ssid->key_mgmt != WPA_KEY_MGMT_SAE) { |
| 3160 | wpa_printf(MSG_ERROR, |
| 3161 | "CTRL_IFACE: key_mgmt for mesh network should be open or SAE"); |
| 3162 | return -1; |
| 3163 | } |
| 3164 | |
| 3165 | /* |
| 3166 | * TODO: If necessary write our own group_add function, |
| 3167 | * for now we can reuse select_network |
| 3168 | */ |
| 3169 | wpa_supplicant_select_network(wpa_s, ssid); |
| 3170 | |
| 3171 | return 0; |
| 3172 | } |
| 3173 | |
| 3174 | |
| 3175 | static int wpa_supplicant_ctrl_iface_mesh_group_remove( |
| 3176 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3177 | { |
| 3178 | struct wpa_supplicant *orig; |
| 3179 | struct wpa_global *global; |
| 3180 | int found = 0; |
| 3181 | |
| 3182 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd); |
| 3183 | |
| 3184 | global = wpa_s->global; |
| 3185 | orig = wpa_s; |
| 3186 | |
| 3187 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 3188 | if (os_strcmp(wpa_s->ifname, cmd) == 0) { |
| 3189 | found = 1; |
| 3190 | break; |
| 3191 | } |
| 3192 | } |
| 3193 | if (!found) { |
| 3194 | wpa_printf(MSG_ERROR, |
| 3195 | "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found", |
| 3196 | cmd); |
| 3197 | return -1; |
| 3198 | } |
| 3199 | if (wpa_s->mesh_if_created && wpa_s == orig) { |
| 3200 | wpa_printf(MSG_ERROR, |
| 3201 | "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself"); |
| 3202 | return -1; |
| 3203 | } |
| 3204 | |
| 3205 | wpa_s->reassociate = 0; |
| 3206 | wpa_s->disconnected = 1; |
| 3207 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 3208 | wpa_supplicant_cancel_scan(wpa_s); |
| 3209 | |
| 3210 | /* |
| 3211 | * TODO: If necessary write our own group_remove function, |
| 3212 | * for now we can reuse deauthenticate |
| 3213 | */ |
| 3214 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 3215 | |
| 3216 | if (wpa_s->mesh_if_created) |
| 3217 | wpa_supplicant_remove_iface(global, wpa_s, 0); |
| 3218 | |
| 3219 | return 0; |
| 3220 | } |
| 3221 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3222 | |
| 3223 | static int wpa_supplicant_ctrl_iface_mesh_peer_remove( |
| 3224 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3225 | { |
| 3226 | u8 addr[ETH_ALEN]; |
| 3227 | |
| 3228 | if (hwaddr_aton(cmd, addr) < 0) |
| 3229 | return -1; |
| 3230 | |
| 3231 | return wpas_mesh_peer_remove(wpa_s, addr); |
| 3232 | } |
| 3233 | |
| 3234 | |
| 3235 | static int wpa_supplicant_ctrl_iface_mesh_peer_add( |
| 3236 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3237 | { |
| 3238 | u8 addr[ETH_ALEN]; |
| 3239 | int duration; |
| 3240 | char *pos; |
| 3241 | |
| 3242 | pos = os_strstr(cmd, " duration="); |
| 3243 | if (pos) { |
| 3244 | *pos = '\0'; |
| 3245 | duration = atoi(pos + 10); |
| 3246 | } else { |
| 3247 | duration = -1; |
| 3248 | } |
| 3249 | |
| 3250 | if (hwaddr_aton(cmd, addr)) |
| 3251 | return -1; |
| 3252 | |
| 3253 | return wpas_mesh_peer_add(wpa_s, addr, duration); |
| 3254 | } |
| 3255 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3256 | |
| 3257 | static int wpa_supplicant_ctrl_iface_mesh_link_probe( |
| 3258 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3259 | { |
| 3260 | struct ether_header *eth; |
| 3261 | u8 addr[ETH_ALEN]; |
| 3262 | u8 *buf; |
| 3263 | char *pos; |
| 3264 | size_t payload_len = 0, len; |
| 3265 | int ret = -1; |
| 3266 | |
| 3267 | if (hwaddr_aton(cmd, addr)) |
| 3268 | return -1; |
| 3269 | |
| 3270 | pos = os_strstr(cmd, " payload="); |
| 3271 | if (pos) { |
| 3272 | pos = pos + 9; |
| 3273 | payload_len = os_strlen(pos); |
| 3274 | if (payload_len & 1) |
| 3275 | return -1; |
| 3276 | |
| 3277 | payload_len /= 2; |
| 3278 | } |
| 3279 | |
| 3280 | len = ETH_HLEN + payload_len; |
| 3281 | buf = os_malloc(len); |
| 3282 | if (!buf) |
| 3283 | return -1; |
| 3284 | |
| 3285 | eth = (struct ether_header *) buf; |
| 3286 | os_memcpy(eth->ether_dhost, addr, ETH_ALEN); |
| 3287 | os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN); |
| 3288 | eth->ether_type = htons(ETH_P_802_3); |
| 3289 | |
| 3290 | if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0) |
| 3291 | goto fail; |
| 3292 | |
| 3293 | ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len); |
| 3294 | fail: |
| 3295 | os_free(buf); |
| 3296 | return -ret; |
| 3297 | } |
| 3298 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3299 | #endif /* CONFIG_MESH */ |
| 3300 | |
| 3301 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3302 | static int wpa_supplicant_ctrl_iface_select_network( |
| 3303 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3304 | { |
| 3305 | int id; |
| 3306 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3307 | char *pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3308 | |
| 3309 | /* cmd: "<network id>" or "any" */ |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3310 | if (os_strncmp(cmd, "any", 3) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3311 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); |
| 3312 | ssid = NULL; |
| 3313 | } else { |
| 3314 | id = atoi(cmd); |
| 3315 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); |
| 3316 | |
| 3317 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3318 | if (ssid == NULL) { |
| 3319 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 3320 | "network id=%d", id); |
| 3321 | return -1; |
| 3322 | } |
| 3323 | if (ssid->disabled == 2) { |
| 3324 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| 3325 | "SELECT_NETWORK with persistent P2P group"); |
| 3326 | return -1; |
| 3327 | } |
| 3328 | } |
| 3329 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3330 | pos = os_strstr(cmd, " freq="); |
| 3331 | if (pos) { |
| 3332 | int *freqs = freq_range_to_channel_list(wpa_s, pos + 6); |
| 3333 | if (freqs) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3334 | os_free(wpa_s->select_network_scan_freqs); |
| 3335 | wpa_s->select_network_scan_freqs = freqs; |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3336 | } |
| 3337 | } |
| 3338 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3339 | wpa_s->scan_min_time.sec = 0; |
| 3340 | wpa_s->scan_min_time.usec = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3341 | wpa_supplicant_select_network(wpa_s, ssid); |
| 3342 | |
| 3343 | return 0; |
| 3344 | } |
| 3345 | |
| 3346 | |
| 3347 | static int wpa_supplicant_ctrl_iface_enable_network( |
| 3348 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3349 | { |
| 3350 | int id; |
| 3351 | struct wpa_ssid *ssid; |
| 3352 | |
| 3353 | /* cmd: "<network id>" or "all" */ |
| 3354 | if (os_strcmp(cmd, "all") == 0) { |
| 3355 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); |
| 3356 | ssid = NULL; |
| 3357 | } else { |
| 3358 | id = atoi(cmd); |
| 3359 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); |
| 3360 | |
| 3361 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3362 | if (ssid == NULL) { |
| 3363 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 3364 | "network id=%d", id); |
| 3365 | return -1; |
| 3366 | } |
| 3367 | if (ssid->disabled == 2) { |
| 3368 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| 3369 | "ENABLE_NETWORK with persistent P2P group"); |
| 3370 | return -1; |
| 3371 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3372 | |
| 3373 | if (os_strstr(cmd, " no-connect")) { |
| 3374 | ssid->disabled = 0; |
| 3375 | return 0; |
| 3376 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3377 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3378 | wpa_s->scan_min_time.sec = 0; |
| 3379 | wpa_s->scan_min_time.usec = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3380 | wpa_supplicant_enable_network(wpa_s, ssid); |
| 3381 | |
| 3382 | return 0; |
| 3383 | } |
| 3384 | |
| 3385 | |
| 3386 | static int wpa_supplicant_ctrl_iface_disable_network( |
| 3387 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3388 | { |
| 3389 | int id; |
| 3390 | struct wpa_ssid *ssid; |
| 3391 | |
| 3392 | /* cmd: "<network id>" or "all" */ |
| 3393 | if (os_strcmp(cmd, "all") == 0) { |
| 3394 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); |
| 3395 | ssid = NULL; |
| 3396 | } else { |
| 3397 | id = atoi(cmd); |
| 3398 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); |
| 3399 | |
| 3400 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3401 | if (ssid == NULL) { |
| 3402 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 3403 | "network id=%d", id); |
| 3404 | return -1; |
| 3405 | } |
| 3406 | if (ssid->disabled == 2) { |
| 3407 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| 3408 | "DISABLE_NETWORK with persistent P2P " |
| 3409 | "group"); |
| 3410 | return -1; |
| 3411 | } |
| 3412 | } |
| 3413 | wpa_supplicant_disable_network(wpa_s, ssid); |
| 3414 | |
| 3415 | return 0; |
| 3416 | } |
| 3417 | |
| 3418 | |
| 3419 | static int wpa_supplicant_ctrl_iface_add_network( |
| 3420 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| 3421 | { |
| 3422 | struct wpa_ssid *ssid; |
| 3423 | int ret; |
| 3424 | |
| 3425 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); |
| 3426 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3427 | ssid = wpa_supplicant_add_network(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3428 | if (ssid == NULL) |
| 3429 | return -1; |
| 3430 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3431 | ret = os_snprintf(buf, buflen, "%d\n", ssid->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3432 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3433 | return -1; |
| 3434 | return ret; |
| 3435 | } |
| 3436 | |
| 3437 | |
| 3438 | static int wpa_supplicant_ctrl_iface_remove_network( |
| 3439 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3440 | { |
| 3441 | int id; |
| 3442 | struct wpa_ssid *ssid; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3443 | int result; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3444 | |
| 3445 | /* cmd: "<network id>" or "all" */ |
| 3446 | if (os_strcmp(cmd, "all") == 0) { |
| 3447 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3448 | if (wpa_s->sched_scanning) |
| 3449 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 3450 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3451 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3452 | if (wpa_s->current_ssid) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3453 | #ifdef CONFIG_SME |
| 3454 | wpa_s->sme.prev_bssid_set = 0; |
| 3455 | #endif /* CONFIG_SME */ |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 3456 | wpa_sm_set_config(wpa_s->wpa, NULL); |
| 3457 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 3458 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
| 3459 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3460 | wpa_supplicant_deauthenticate( |
| 3461 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3462 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3463 | ssid = wpa_s->conf->ssid; |
| 3464 | while (ssid) { |
| 3465 | struct wpa_ssid *remove_ssid = ssid; |
| 3466 | id = ssid->id; |
| 3467 | ssid = ssid->next; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3468 | if (wpa_s->last_ssid == remove_ssid) |
| 3469 | wpa_s->last_ssid = NULL; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3470 | wpas_notify_network_removed(wpa_s, remove_ssid); |
| 3471 | wpa_config_remove_network(wpa_s->conf, id); |
| 3472 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3473 | return 0; |
| 3474 | } |
| 3475 | |
| 3476 | id = atoi(cmd); |
| 3477 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); |
| 3478 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3479 | result = wpa_supplicant_remove_network(wpa_s, id); |
| 3480 | if (result == -1) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3481 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
| 3482 | "id=%d", id); |
| 3483 | return -1; |
| 3484 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3485 | if (result == -2) { |
Deepthi Gowri | a831d78 | 2012-09-03 11:55:38 +0300 | [diff] [blame] | 3486 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the " |
| 3487 | "network id=%d", id); |
| 3488 | return -1; |
| 3489 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3490 | return 0; |
| 3491 | } |
| 3492 | |
| 3493 | |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3494 | static int wpa_supplicant_ctrl_iface_update_network( |
| 3495 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 3496 | char *name, char *value) |
| 3497 | { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3498 | int ret; |
| 3499 | |
| 3500 | ret = wpa_config_set(ssid, name, value, 0); |
| 3501 | if (ret < 0) { |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3502 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " |
| 3503 | "variable '%s'", name); |
| 3504 | return -1; |
| 3505 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3506 | if (ret == 1) |
| 3507 | return 0; /* No change to the previously configured value */ |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3508 | |
| 3509 | if (os_strcmp(name, "bssid") != 0 && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3510 | os_strcmp(name, "bssid_hint") != 0 && |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3511 | os_strcmp(name, "priority") != 0) { |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3512 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
| 3513 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3514 | if (wpa_s->current_ssid == ssid || |
| 3515 | wpa_s->current_ssid == NULL) { |
| 3516 | /* |
| 3517 | * Invalidate the EAP session cache if anything in the |
| 3518 | * current or previously used configuration changes. |
| 3519 | */ |
| 3520 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
| 3521 | } |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | if ((os_strcmp(name, "psk") == 0 && |
| 3525 | value[0] == '"' && ssid->ssid_len) || |
| 3526 | (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) |
| 3527 | wpa_config_update_psk(ssid); |
| 3528 | else if (os_strcmp(name, "priority") == 0) |
| 3529 | wpa_config_update_prio_list(wpa_s->conf); |
| 3530 | |
| 3531 | return 0; |
| 3532 | } |
| 3533 | |
| 3534 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3535 | static int wpa_supplicant_ctrl_iface_set_network( |
| 3536 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3537 | { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3538 | int id, ret, prev_bssid_set, prev_disabled; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3539 | struct wpa_ssid *ssid; |
| 3540 | char *name, *value; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3541 | u8 prev_bssid[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3542 | |
| 3543 | /* cmd: "<network id> <variable name> <value>" */ |
| 3544 | name = os_strchr(cmd, ' '); |
| 3545 | if (name == NULL) |
| 3546 | return -1; |
| 3547 | *name++ = '\0'; |
| 3548 | |
| 3549 | value = os_strchr(name, ' '); |
| 3550 | if (value == NULL) |
| 3551 | return -1; |
| 3552 | *value++ = '\0'; |
| 3553 | |
| 3554 | id = atoi(cmd); |
| 3555 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", |
| 3556 | id, name); |
| 3557 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", |
| 3558 | (u8 *) value, os_strlen(value)); |
| 3559 | |
| 3560 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3561 | if (ssid == NULL) { |
| 3562 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
| 3563 | "id=%d", id); |
| 3564 | return -1; |
| 3565 | } |
| 3566 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3567 | prev_bssid_set = ssid->bssid_set; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3568 | prev_disabled = ssid->disabled; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3569 | os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN); |
| 3570 | ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name, |
| 3571 | value); |
| 3572 | if (ret == 0 && |
| 3573 | (ssid->bssid_set != prev_bssid_set || |
| 3574 | os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0)) |
| 3575 | wpas_notify_network_bssid_set_changed(wpa_s, ssid); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3576 | |
| 3577 | if (prev_disabled != ssid->disabled && |
| 3578 | (prev_disabled == 2 || ssid->disabled == 2)) |
| 3579 | wpas_notify_network_type_changed(wpa_s, ssid); |
| 3580 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3581 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | |
| 3585 | static int wpa_supplicant_ctrl_iface_get_network( |
| 3586 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| 3587 | { |
| 3588 | int id; |
| 3589 | size_t res; |
| 3590 | struct wpa_ssid *ssid; |
| 3591 | char *name, *value; |
| 3592 | |
| 3593 | /* cmd: "<network id> <variable name>" */ |
| 3594 | name = os_strchr(cmd, ' '); |
| 3595 | if (name == NULL || buflen == 0) |
| 3596 | return -1; |
| 3597 | *name++ = '\0'; |
| 3598 | |
| 3599 | id = atoi(cmd); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3600 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3601 | id, name); |
| 3602 | |
| 3603 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3604 | if (ssid == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3605 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3606 | "id=%d", id); |
| 3607 | return -1; |
| 3608 | } |
| 3609 | |
| 3610 | value = wpa_config_get_no_key(ssid, name); |
| 3611 | if (value == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3612 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3613 | "variable '%s'", name); |
| 3614 | return -1; |
| 3615 | } |
| 3616 | |
| 3617 | res = os_strlcpy(buf, value, buflen); |
| 3618 | if (res >= buflen) { |
| 3619 | os_free(value); |
| 3620 | return -1; |
| 3621 | } |
| 3622 | |
| 3623 | os_free(value); |
| 3624 | |
| 3625 | return res; |
| 3626 | } |
| 3627 | |
| 3628 | |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3629 | static int wpa_supplicant_ctrl_iface_dup_network( |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3630 | struct wpa_supplicant *wpa_s, char *cmd, |
| 3631 | struct wpa_supplicant *dst_wpa_s) |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3632 | { |
| 3633 | struct wpa_ssid *ssid_s, *ssid_d; |
| 3634 | char *name, *id, *value; |
| 3635 | int id_s, id_d, ret; |
| 3636 | |
| 3637 | /* cmd: "<src network id> <dst network id> <variable name>" */ |
| 3638 | id = os_strchr(cmd, ' '); |
| 3639 | if (id == NULL) |
| 3640 | return -1; |
| 3641 | *id++ = '\0'; |
| 3642 | |
| 3643 | name = os_strchr(id, ' '); |
| 3644 | if (name == NULL) |
| 3645 | return -1; |
| 3646 | *name++ = '\0'; |
| 3647 | |
| 3648 | id_s = atoi(cmd); |
| 3649 | id_d = atoi(id); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3650 | |
| 3651 | wpa_printf(MSG_DEBUG, |
| 3652 | "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'", |
| 3653 | wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3654 | |
| 3655 | ssid_s = wpa_config_get_network(wpa_s->conf, id_s); |
| 3656 | if (ssid_s == NULL) { |
| 3657 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 3658 | "network id=%d", id_s); |
| 3659 | return -1; |
| 3660 | } |
| 3661 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3662 | ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3663 | if (ssid_d == NULL) { |
| 3664 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3665 | "network id=%d", id_d); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3666 | return -1; |
| 3667 | } |
| 3668 | |
| 3669 | value = wpa_config_get(ssid_s, name); |
| 3670 | if (value == NULL) { |
| 3671 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " |
| 3672 | "variable '%s'", name); |
| 3673 | return -1; |
| 3674 | } |
| 3675 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3676 | ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name, |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3677 | value); |
| 3678 | |
| 3679 | os_free(value); |
| 3680 | |
| 3681 | return ret; |
| 3682 | } |
| 3683 | |
| 3684 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3685 | static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s, |
| 3686 | char *buf, size_t buflen) |
| 3687 | { |
| 3688 | char *pos, *end; |
| 3689 | struct wpa_cred *cred; |
| 3690 | int ret; |
| 3691 | |
| 3692 | pos = buf; |
| 3693 | end = buf + buflen; |
| 3694 | ret = os_snprintf(pos, end - pos, |
| 3695 | "cred id / realm / username / domain / imsi\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3696 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3697 | return pos - buf; |
| 3698 | pos += ret; |
| 3699 | |
| 3700 | cred = wpa_s->conf->cred; |
| 3701 | while (cred) { |
| 3702 | ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n", |
| 3703 | cred->id, cred->realm ? cred->realm : "", |
| 3704 | cred->username ? cred->username : "", |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3705 | cred->domain ? cred->domain[0] : "", |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3706 | cred->imsi ? cred->imsi : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3707 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3708 | return pos - buf; |
| 3709 | pos += ret; |
| 3710 | |
| 3711 | cred = cred->next; |
| 3712 | } |
| 3713 | |
| 3714 | return pos - buf; |
| 3715 | } |
| 3716 | |
| 3717 | |
| 3718 | static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s, |
| 3719 | char *buf, size_t buflen) |
| 3720 | { |
| 3721 | struct wpa_cred *cred; |
| 3722 | int ret; |
| 3723 | |
| 3724 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED"); |
| 3725 | |
| 3726 | cred = wpa_config_add_cred(wpa_s->conf); |
| 3727 | if (cred == NULL) |
| 3728 | return -1; |
| 3729 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3730 | wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id); |
| 3731 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3732 | ret = os_snprintf(buf, buflen, "%d\n", cred->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3733 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3734 | return -1; |
| 3735 | return ret; |
| 3736 | } |
| 3737 | |
| 3738 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3739 | static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s, |
| 3740 | struct wpa_cred *cred) |
| 3741 | { |
| 3742 | struct wpa_ssid *ssid; |
| 3743 | char str[20]; |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3744 | int id; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3745 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3746 | if (cred == NULL) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3747 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); |
| 3748 | return -1; |
| 3749 | } |
| 3750 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3751 | id = cred->id; |
| 3752 | if (wpa_config_remove_cred(wpa_s->conf, id) < 0) { |
| 3753 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); |
| 3754 | return -1; |
| 3755 | } |
| 3756 | |
| 3757 | wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id); |
| 3758 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3759 | /* Remove any network entry created based on the removed credential */ |
| 3760 | ssid = wpa_s->conf->ssid; |
| 3761 | while (ssid) { |
| 3762 | if (ssid->parent_cred == cred) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3763 | int res; |
| 3764 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3765 | wpa_printf(MSG_DEBUG, "Remove network id %d since it " |
| 3766 | "used the removed credential", ssid->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3767 | res = os_snprintf(str, sizeof(str), "%d", ssid->id); |
| 3768 | if (os_snprintf_error(sizeof(str), res)) |
| 3769 | str[sizeof(str) - 1] = '\0'; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3770 | ssid = ssid->next; |
| 3771 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, str); |
| 3772 | } else |
| 3773 | ssid = ssid->next; |
| 3774 | } |
| 3775 | |
| 3776 | return 0; |
| 3777 | } |
| 3778 | |
| 3779 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3780 | static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s, |
| 3781 | char *cmd) |
| 3782 | { |
| 3783 | int id; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3784 | struct wpa_cred *cred, *prev; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3785 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3786 | /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or |
| 3787 | * "provisioning_sp=<FQDN> */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3788 | if (os_strcmp(cmd, "all") == 0) { |
| 3789 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all"); |
| 3790 | cred = wpa_s->conf->cred; |
| 3791 | while (cred) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3792 | prev = cred; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3793 | cred = cred->next; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3794 | wpas_ctrl_remove_cred(wpa_s, prev); |
| 3795 | } |
| 3796 | return 0; |
| 3797 | } |
| 3798 | |
| 3799 | if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) { |
| 3800 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'", |
| 3801 | cmd + 8); |
| 3802 | cred = wpa_s->conf->cred; |
| 3803 | while (cred) { |
| 3804 | prev = cred; |
| 3805 | cred = cred->next; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3806 | if (prev->domain) { |
| 3807 | size_t i; |
| 3808 | for (i = 0; i < prev->num_domain; i++) { |
| 3809 | if (os_strcmp(prev->domain[i], cmd + 8) |
| 3810 | != 0) |
| 3811 | continue; |
| 3812 | wpas_ctrl_remove_cred(wpa_s, prev); |
| 3813 | break; |
| 3814 | } |
| 3815 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3816 | } |
| 3817 | return 0; |
| 3818 | } |
| 3819 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3820 | if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) { |
| 3821 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'", |
| 3822 | cmd + 16); |
| 3823 | cred = wpa_s->conf->cred; |
| 3824 | while (cred) { |
| 3825 | prev = cred; |
| 3826 | cred = cred->next; |
| 3827 | if (prev->provisioning_sp && |
| 3828 | os_strcmp(prev->provisioning_sp, cmd + 16) == 0) |
| 3829 | wpas_ctrl_remove_cred(wpa_s, prev); |
| 3830 | } |
| 3831 | return 0; |
| 3832 | } |
| 3833 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3834 | id = atoi(cmd); |
| 3835 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id); |
| 3836 | |
| 3837 | cred = wpa_config_get_cred(wpa_s->conf, id); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3838 | return wpas_ctrl_remove_cred(wpa_s, cred); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | |
| 3842 | static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s, |
| 3843 | char *cmd) |
| 3844 | { |
| 3845 | int id; |
| 3846 | struct wpa_cred *cred; |
| 3847 | char *name, *value; |
| 3848 | |
| 3849 | /* cmd: "<cred id> <variable name> <value>" */ |
| 3850 | name = os_strchr(cmd, ' '); |
| 3851 | if (name == NULL) |
| 3852 | return -1; |
| 3853 | *name++ = '\0'; |
| 3854 | |
| 3855 | value = os_strchr(name, ' '); |
| 3856 | if (value == NULL) |
| 3857 | return -1; |
| 3858 | *value++ = '\0'; |
| 3859 | |
| 3860 | id = atoi(cmd); |
| 3861 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'", |
| 3862 | id, name); |
| 3863 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", |
| 3864 | (u8 *) value, os_strlen(value)); |
| 3865 | |
| 3866 | cred = wpa_config_get_cred(wpa_s->conf, id); |
| 3867 | if (cred == NULL) { |
| 3868 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", |
| 3869 | id); |
| 3870 | return -1; |
| 3871 | } |
| 3872 | |
| 3873 | if (wpa_config_set_cred(cred, name, value, 0) < 0) { |
| 3874 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred " |
| 3875 | "variable '%s'", name); |
| 3876 | return -1; |
| 3877 | } |
| 3878 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3879 | wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name); |
| 3880 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3881 | return 0; |
| 3882 | } |
| 3883 | |
| 3884 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3885 | static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s, |
| 3886 | char *cmd, char *buf, |
| 3887 | size_t buflen) |
| 3888 | { |
| 3889 | int id; |
| 3890 | size_t res; |
| 3891 | struct wpa_cred *cred; |
| 3892 | char *name, *value; |
| 3893 | |
| 3894 | /* cmd: "<cred id> <variable name>" */ |
| 3895 | name = os_strchr(cmd, ' '); |
| 3896 | if (name == NULL) |
| 3897 | return -1; |
| 3898 | *name++ = '\0'; |
| 3899 | |
| 3900 | id = atoi(cmd); |
| 3901 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'", |
| 3902 | id, name); |
| 3903 | |
| 3904 | cred = wpa_config_get_cred(wpa_s->conf, id); |
| 3905 | if (cred == NULL) { |
| 3906 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", |
| 3907 | id); |
| 3908 | return -1; |
| 3909 | } |
| 3910 | |
| 3911 | value = wpa_config_get_cred_no_key(cred, name); |
| 3912 | if (value == NULL) { |
| 3913 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'", |
| 3914 | name); |
| 3915 | return -1; |
| 3916 | } |
| 3917 | |
| 3918 | res = os_strlcpy(buf, value, buflen); |
| 3919 | if (res >= buflen) { |
| 3920 | os_free(value); |
| 3921 | return -1; |
| 3922 | } |
| 3923 | |
| 3924 | os_free(value); |
| 3925 | |
| 3926 | return res; |
| 3927 | } |
| 3928 | |
| 3929 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3930 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 3931 | static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s) |
| 3932 | { |
| 3933 | int ret; |
| 3934 | |
| 3935 | if (!wpa_s->conf->update_config) { |
| 3936 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed " |
| 3937 | "to update configuration (update_config=0)"); |
| 3938 | return -1; |
| 3939 | } |
| 3940 | |
| 3941 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); |
| 3942 | if (ret) { |
| 3943 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to " |
| 3944 | "update configuration"); |
| 3945 | } else { |
| 3946 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration" |
| 3947 | " updated"); |
| 3948 | } |
| 3949 | |
| 3950 | return ret; |
| 3951 | } |
| 3952 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 3953 | |
| 3954 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3955 | struct cipher_info { |
| 3956 | unsigned int capa; |
| 3957 | const char *name; |
| 3958 | int group_only; |
| 3959 | }; |
| 3960 | |
| 3961 | static const struct cipher_info ciphers[] = { |
| 3962 | { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 }, |
| 3963 | { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 }, |
| 3964 | { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 }, |
| 3965 | { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 }, |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3966 | #ifndef CONFIG_NO_TKIP |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3967 | { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 }, |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3968 | #endif /* CONFIG_NO_TKIP */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3969 | { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 }, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3970 | #ifdef CONFIG_WEP |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3971 | { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 }, |
| 3972 | { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3973 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3974 | }; |
| 3975 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3976 | static const struct cipher_info ciphers_group_mgmt[] = { |
| 3977 | { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 }, |
| 3978 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 }, |
| 3979 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 }, |
| 3980 | { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 }, |
| 3981 | }; |
| 3982 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3983 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3984 | static int ctrl_iface_get_capability_pairwise(int res, bool strict, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3985 | struct wpa_driver_capa *capa, |
| 3986 | char *buf, size_t buflen) |
| 3987 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3988 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3989 | char *pos, *end; |
| 3990 | size_t len; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3991 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3992 | |
| 3993 | pos = buf; |
| 3994 | end = pos + buflen; |
| 3995 | |
| 3996 | if (res < 0) { |
| 3997 | if (strict) |
| 3998 | return 0; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3999 | #ifdef CONFIG_NO_TKIP |
| 4000 | len = os_strlcpy(buf, "CCMP NONE", buflen); |
| 4001 | #else /* CONFIG_NO_TKIP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4002 | len = os_strlcpy(buf, "CCMP TKIP NONE", buflen); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4003 | #endif /* CONFIG_NO_TKIP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4004 | if (len >= buflen) |
| 4005 | return -1; |
| 4006 | return len; |
| 4007 | } |
| 4008 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4009 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
| 4010 | if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) { |
| 4011 | ret = os_snprintf(pos, end - pos, "%s%s", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4012 | pos == buf ? "" : " ", |
| 4013 | ciphers[i].name); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4014 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4015 | return pos - buf; |
| 4016 | pos += ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4017 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4018 | } |
| 4019 | |
| 4020 | return pos - buf; |
| 4021 | } |
| 4022 | |
| 4023 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4024 | static int ctrl_iface_get_capability_group(int res, bool strict, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4025 | struct wpa_driver_capa *capa, |
| 4026 | char *buf, size_t buflen) |
| 4027 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4028 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4029 | char *pos, *end; |
| 4030 | size_t len; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4031 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4032 | |
| 4033 | pos = buf; |
| 4034 | end = pos + buflen; |
| 4035 | |
| 4036 | if (res < 0) { |
| 4037 | if (strict) |
| 4038 | return 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4039 | #ifdef CONFIG_WEP |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4040 | #ifdef CONFIG_NO_TKIP |
| 4041 | len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen); |
| 4042 | #else /* CONFIG_NO_TKIP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4043 | len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4044 | #endif /* CONFIG_NO_TKIP */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4045 | #else /* CONFIG_WEP */ |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4046 | #ifdef CONFIG_NO_TKIP |
| 4047 | len = os_strlcpy(buf, "CCMP", buflen); |
| 4048 | #else /* CONFIG_NO_TKIP */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4049 | len = os_strlcpy(buf, "CCMP TKIP", buflen); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4050 | #endif /* CONFIG_NO_TKIP */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4051 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4052 | if (len >= buflen) |
| 4053 | return -1; |
| 4054 | return len; |
| 4055 | } |
| 4056 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4057 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
| 4058 | if (capa->enc & ciphers[i].capa) { |
| 4059 | ret = os_snprintf(pos, end - pos, "%s%s", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4060 | pos == buf ? "" : " ", |
| 4061 | ciphers[i].name); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4062 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4063 | return pos - buf; |
| 4064 | pos += ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4065 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | return pos - buf; |
| 4069 | } |
| 4070 | |
| 4071 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4072 | static int ctrl_iface_get_capability_group_mgmt(int res, bool strict, |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4073 | struct wpa_driver_capa *capa, |
| 4074 | char *buf, size_t buflen) |
| 4075 | { |
| 4076 | int ret; |
| 4077 | char *pos, *end; |
| 4078 | unsigned int i; |
| 4079 | |
| 4080 | pos = buf; |
| 4081 | end = pos + buflen; |
| 4082 | |
| 4083 | if (res < 0) |
| 4084 | return 0; |
| 4085 | |
| 4086 | for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) { |
| 4087 | if (capa->enc & ciphers_group_mgmt[i].capa) { |
| 4088 | ret = os_snprintf(pos, end - pos, "%s%s", |
| 4089 | pos == buf ? "" : " ", |
| 4090 | ciphers_group_mgmt[i].name); |
| 4091 | if (os_snprintf_error(end - pos, ret)) |
| 4092 | return pos - buf; |
| 4093 | pos += ret; |
| 4094 | } |
| 4095 | } |
| 4096 | |
| 4097 | return pos - buf; |
| 4098 | } |
| 4099 | |
| 4100 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4101 | static int iftype_str_to_index(const char *iftype_str) |
| 4102 | { |
| 4103 | if (!iftype_str) |
| 4104 | return WPA_IF_MAX; |
| 4105 | |
| 4106 | if (os_strcmp(iftype_str, "STATION") == 0) |
| 4107 | return WPA_IF_STATION; |
| 4108 | |
| 4109 | if (os_strcmp(iftype_str, "AP_VLAN") == 0) |
| 4110 | return WPA_IF_AP_VLAN; |
| 4111 | |
| 4112 | if (os_strcmp(iftype_str, "AP") == 0) |
| 4113 | return WPA_IF_AP_BSS; |
| 4114 | |
| 4115 | if (os_strcmp(iftype_str, "P2P_GO") == 0) |
| 4116 | return WPA_IF_P2P_GO; |
| 4117 | |
| 4118 | if (os_strcmp(iftype_str, "P2P_CLIENT") == 0) |
| 4119 | return WPA_IF_P2P_CLIENT; |
| 4120 | |
| 4121 | if (os_strcmp(iftype_str, "P2P_DEVICE") == 0) |
| 4122 | return WPA_IF_P2P_DEVICE; |
| 4123 | |
| 4124 | if (os_strcmp(iftype_str, "MESH") == 0) |
| 4125 | return WPA_IF_MESH; |
| 4126 | |
| 4127 | if (os_strcmp(iftype_str, "IBSS") == 0) |
| 4128 | return WPA_IF_IBSS; |
| 4129 | |
| 4130 | if (os_strcmp(iftype_str, "NAN") == 0) |
| 4131 | return WPA_IF_NAN; |
| 4132 | |
| 4133 | return WPA_IF_MAX; |
| 4134 | } |
| 4135 | |
| 4136 | |
| 4137 | static int ctrl_iface_get_capability_key_mgmt(int res, bool strict, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4138 | struct wpa_driver_capa *capa, |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4139 | const char *iftype_str, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4140 | char *buf, size_t buflen) |
| 4141 | { |
| 4142 | int ret; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4143 | unsigned int key_mgmt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4144 | char *pos, *end; |
| 4145 | size_t len; |
| 4146 | |
| 4147 | pos = buf; |
| 4148 | end = pos + buflen; |
| 4149 | |
| 4150 | if (res < 0) { |
| 4151 | if (strict) |
| 4152 | return 0; |
| 4153 | len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE " |
| 4154 | "NONE", buflen); |
| 4155 | if (len >= buflen) |
| 4156 | return -1; |
| 4157 | return len; |
| 4158 | } |
| 4159 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4160 | if (iftype_str) { |
| 4161 | enum wpa_driver_if_type iftype; |
| 4162 | |
| 4163 | iftype = iftype_str_to_index(iftype_str); |
| 4164 | if (iftype == WPA_IF_MAX) |
| 4165 | return -1; |
| 4166 | key_mgmt = capa->key_mgmt_iftype[iftype]; |
| 4167 | } else { |
| 4168 | key_mgmt = capa->key_mgmt; |
| 4169 | } |
| 4170 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4171 | ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4172 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4173 | return pos - buf; |
| 4174 | pos += ret; |
| 4175 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4176 | if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
| 4177 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4178 | ret = os_snprintf(pos, end - pos, " WPA-EAP"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4179 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4180 | return pos - buf; |
| 4181 | pos += ret; |
| 4182 | } |
| 4183 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4184 | if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | |
| 4185 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4186 | ret = os_snprintf(pos, end - pos, " WPA-PSK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4187 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4188 | return pos - buf; |
| 4189 | pos += ret; |
| 4190 | } |
| 4191 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4192 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4193 | ret = os_snprintf(pos, end - pos, " WPA-NONE"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4194 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4195 | return pos - buf; |
| 4196 | pos += ret; |
| 4197 | } |
| 4198 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4199 | #ifdef CONFIG_SUITEB |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4200 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4201 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B"); |
| 4202 | if (os_snprintf_error(end - pos, ret)) |
| 4203 | return pos - buf; |
| 4204 | pos += ret; |
| 4205 | } |
| 4206 | #endif /* CONFIG_SUITEB */ |
| 4207 | #ifdef CONFIG_SUITEB192 |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4208 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4209 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192"); |
| 4210 | if (os_snprintf_error(end - pos, ret)) |
| 4211 | return pos - buf; |
| 4212 | pos += ret; |
| 4213 | } |
| 4214 | #endif /* CONFIG_SUITEB192 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4215 | #ifdef CONFIG_OWE |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4216 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4217 | ret = os_snprintf(pos, end - pos, " OWE"); |
| 4218 | if (os_snprintf_error(end - pos, ret)) |
| 4219 | return pos - buf; |
| 4220 | pos += ret; |
| 4221 | } |
| 4222 | #endif /* CONFIG_OWE */ |
| 4223 | #ifdef CONFIG_DPP |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4224 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4225 | ret = os_snprintf(pos, end - pos, " DPP"); |
| 4226 | if (os_snprintf_error(end - pos, ret)) |
| 4227 | return pos - buf; |
| 4228 | pos += ret; |
| 4229 | } |
| 4230 | #endif /* CONFIG_DPP */ |
| 4231 | #ifdef CONFIG_FILS |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4232 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4233 | ret = os_snprintf(pos, end - pos, " FILS-SHA256"); |
| 4234 | if (os_snprintf_error(end - pos, ret)) |
| 4235 | return pos - buf; |
| 4236 | pos += ret; |
| 4237 | } |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4238 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4239 | ret = os_snprintf(pos, end - pos, " FILS-SHA384"); |
| 4240 | if (os_snprintf_error(end - pos, ret)) |
| 4241 | return pos - buf; |
| 4242 | pos += ret; |
| 4243 | } |
| 4244 | #ifdef CONFIG_IEEE80211R |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4245 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4246 | ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256"); |
| 4247 | if (os_snprintf_error(end - pos, ret)) |
| 4248 | return pos - buf; |
| 4249 | pos += ret; |
| 4250 | } |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4251 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4252 | ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384"); |
| 4253 | if (os_snprintf_error(end - pos, ret)) |
| 4254 | return pos - buf; |
| 4255 | pos += ret; |
| 4256 | } |
| 4257 | #endif /* CONFIG_IEEE80211R */ |
| 4258 | #endif /* CONFIG_FILS */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4259 | #ifdef CONFIG_IEEE80211R |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4260 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4261 | ret = os_snprintf(pos, end - pos, " FT-PSK"); |
| 4262 | if (os_snprintf_error(end - pos, ret)) |
| 4263 | return pos - buf; |
| 4264 | pos += ret; |
| 4265 | } |
| 4266 | #endif /* CONFIG_IEEE80211R */ |
| 4267 | #ifdef CONFIG_SAE |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4268 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4269 | ret = os_snprintf(pos, end - pos, " SAE"); |
| 4270 | if (os_snprintf_error(end - pos, ret)) |
| 4271 | return pos - buf; |
| 4272 | pos += ret; |
| 4273 | } |
| 4274 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4275 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4276 | return pos - buf; |
| 4277 | } |
| 4278 | |
| 4279 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4280 | static int ctrl_iface_get_capability_proto(int res, bool strict, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4281 | struct wpa_driver_capa *capa, |
| 4282 | char *buf, size_t buflen) |
| 4283 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4284 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4285 | char *pos, *end; |
| 4286 | size_t len; |
| 4287 | |
| 4288 | pos = buf; |
| 4289 | end = pos + buflen; |
| 4290 | |
| 4291 | if (res < 0) { |
| 4292 | if (strict) |
| 4293 | return 0; |
| 4294 | len = os_strlcpy(buf, "RSN WPA", buflen); |
| 4295 | if (len >= buflen) |
| 4296 | return -1; |
| 4297 | return len; |
| 4298 | } |
| 4299 | |
| 4300 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | |
| 4301 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4302 | ret = os_snprintf(pos, end - pos, "%sRSN", |
| 4303 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4304 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4305 | return pos - buf; |
| 4306 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4307 | } |
| 4308 | |
| 4309 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
| 4310 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4311 | ret = os_snprintf(pos, end - pos, "%sWPA", |
| 4312 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4313 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4314 | return pos - buf; |
| 4315 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | return pos - buf; |
| 4319 | } |
| 4320 | |
| 4321 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4322 | static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s, |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4323 | int res, bool strict, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4324 | struct wpa_driver_capa *capa, |
| 4325 | char *buf, size_t buflen) |
| 4326 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4327 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4328 | char *pos, *end; |
| 4329 | size_t len; |
| 4330 | |
| 4331 | pos = buf; |
| 4332 | end = pos + buflen; |
| 4333 | |
| 4334 | if (res < 0) { |
| 4335 | if (strict) |
| 4336 | return 0; |
| 4337 | len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen); |
| 4338 | if (len >= buflen) |
| 4339 | return -1; |
| 4340 | return len; |
| 4341 | } |
| 4342 | |
| 4343 | if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4344 | ret = os_snprintf(pos, end - pos, "%sOPEN", |
| 4345 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4346 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4347 | return pos - buf; |
| 4348 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) { |
| 4352 | ret = os_snprintf(pos, end - pos, "%sSHARED", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4353 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4354 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4355 | return pos - buf; |
| 4356 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4360 | ret = os_snprintf(pos, end - pos, "%sLEAP", |
| 4361 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4362 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4363 | return pos - buf; |
| 4364 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4365 | } |
| 4366 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4367 | #ifdef CONFIG_SAE |
| 4368 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) { |
| 4369 | ret = os_snprintf(pos, end - pos, "%sSAE", |
| 4370 | pos == buf ? "" : " "); |
| 4371 | if (os_snprintf_error(end - pos, ret)) |
| 4372 | return pos - buf; |
| 4373 | pos += ret; |
| 4374 | } |
| 4375 | #endif /* CONFIG_SAE */ |
| 4376 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4377 | #ifdef CONFIG_FILS |
| 4378 | if (wpa_is_fils_supported(wpa_s)) { |
| 4379 | ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS", |
| 4380 | pos == buf ? "" : " "); |
| 4381 | if (os_snprintf_error(end - pos, ret)) |
| 4382 | return pos - buf; |
| 4383 | pos += ret; |
| 4384 | } |
| 4385 | |
| 4386 | #ifdef CONFIG_FILS_SK_PFS |
| 4387 | if (wpa_is_fils_sk_pfs_supported(wpa_s)) { |
| 4388 | ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS", |
| 4389 | pos == buf ? "" : " "); |
| 4390 | if (os_snprintf_error(end - pos, ret)) |
| 4391 | return pos - buf; |
| 4392 | pos += ret; |
| 4393 | } |
| 4394 | #endif /* CONFIG_FILS_SK_PFS */ |
| 4395 | #endif /* CONFIG_FILS */ |
| 4396 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4397 | return pos - buf; |
| 4398 | } |
| 4399 | |
| 4400 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4401 | static int ctrl_iface_get_capability_modes(int res, bool strict, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4402 | struct wpa_driver_capa *capa, |
| 4403 | char *buf, size_t buflen) |
| 4404 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4405 | int ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4406 | char *pos, *end; |
| 4407 | size_t len; |
| 4408 | |
| 4409 | pos = buf; |
| 4410 | end = pos + buflen; |
| 4411 | |
| 4412 | if (res < 0) { |
| 4413 | if (strict) |
| 4414 | return 0; |
| 4415 | len = os_strlcpy(buf, "IBSS AP", buflen); |
| 4416 | if (len >= buflen) |
| 4417 | return -1; |
| 4418 | return len; |
| 4419 | } |
| 4420 | |
| 4421 | if (capa->flags & WPA_DRIVER_FLAGS_IBSS) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4422 | ret = os_snprintf(pos, end - pos, "%sIBSS", |
| 4423 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4424 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4425 | return pos - buf; |
| 4426 | pos += ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4427 | } |
| 4428 | |
| 4429 | if (capa->flags & WPA_DRIVER_FLAGS_AP) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4430 | ret = os_snprintf(pos, end - pos, "%sAP", |
| 4431 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4432 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4433 | return pos - buf; |
| 4434 | pos += ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4435 | } |
| 4436 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4437 | #ifdef CONFIG_MESH |
| 4438 | if (capa->flags & WPA_DRIVER_FLAGS_MESH) { |
| 4439 | ret = os_snprintf(pos, end - pos, "%sMESH", |
| 4440 | pos == buf ? "" : " "); |
| 4441 | if (os_snprintf_error(end - pos, ret)) |
| 4442 | return pos - buf; |
| 4443 | pos += ret; |
| 4444 | } |
| 4445 | #endif /* CONFIG_MESH */ |
| 4446 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4447 | return pos - buf; |
| 4448 | } |
| 4449 | |
| 4450 | |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4451 | static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s, |
| 4452 | char *buf, size_t buflen) |
| 4453 | { |
| 4454 | struct hostapd_channel_data *chnl; |
| 4455 | int ret, i, j; |
| 4456 | char *pos, *end, *hmode; |
| 4457 | |
| 4458 | pos = buf; |
| 4459 | end = pos + buflen; |
| 4460 | |
| 4461 | for (j = 0; j < wpa_s->hw.num_modes; j++) { |
| 4462 | switch (wpa_s->hw.modes[j].mode) { |
| 4463 | case HOSTAPD_MODE_IEEE80211B: |
| 4464 | hmode = "B"; |
| 4465 | break; |
| 4466 | case HOSTAPD_MODE_IEEE80211G: |
| 4467 | hmode = "G"; |
| 4468 | break; |
| 4469 | case HOSTAPD_MODE_IEEE80211A: |
| 4470 | hmode = "A"; |
| 4471 | break; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4472 | case HOSTAPD_MODE_IEEE80211AD: |
| 4473 | hmode = "AD"; |
| 4474 | break; |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4475 | default: |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4476 | continue; |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4477 | } |
| 4478 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4479 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4480 | return pos - buf; |
| 4481 | pos += ret; |
| 4482 | chnl = wpa_s->hw.modes[j].channels; |
| 4483 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4484 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) |
| 4485 | continue; |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4486 | ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4487 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4488 | return pos - buf; |
| 4489 | pos += ret; |
| 4490 | } |
| 4491 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4492 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4493 | return pos - buf; |
| 4494 | pos += ret; |
| 4495 | } |
| 4496 | |
| 4497 | return pos - buf; |
| 4498 | } |
| 4499 | |
| 4500 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4501 | static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s, |
| 4502 | char *buf, size_t buflen) |
| 4503 | { |
| 4504 | struct hostapd_channel_data *chnl; |
| 4505 | int ret, i, j; |
| 4506 | char *pos, *end, *hmode; |
| 4507 | |
| 4508 | pos = buf; |
| 4509 | end = pos + buflen; |
| 4510 | |
| 4511 | for (j = 0; j < wpa_s->hw.num_modes; j++) { |
| 4512 | switch (wpa_s->hw.modes[j].mode) { |
| 4513 | case HOSTAPD_MODE_IEEE80211B: |
| 4514 | hmode = "B"; |
| 4515 | break; |
| 4516 | case HOSTAPD_MODE_IEEE80211G: |
| 4517 | hmode = "G"; |
| 4518 | break; |
| 4519 | case HOSTAPD_MODE_IEEE80211A: |
| 4520 | hmode = "A"; |
| 4521 | break; |
| 4522 | case HOSTAPD_MODE_IEEE80211AD: |
| 4523 | hmode = "AD"; |
| 4524 | break; |
| 4525 | default: |
| 4526 | continue; |
| 4527 | } |
| 4528 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n", |
| 4529 | hmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4530 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4531 | return pos - buf; |
| 4532 | pos += ret; |
| 4533 | chnl = wpa_s->hw.modes[j].channels; |
| 4534 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { |
| 4535 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) |
| 4536 | continue; |
Dmitry Shmidt | 5da5e35 | 2014-02-03 13:30:46 -0800 | [diff] [blame] | 4537 | ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n", |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4538 | chnl[i].chan, chnl[i].freq, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4539 | chnl[i].flag & HOSTAPD_CHAN_NO_IR ? |
| 4540 | " (NO_IR)" : "", |
Dmitry Shmidt | 5da5e35 | 2014-02-03 13:30:46 -0800 | [diff] [blame] | 4541 | chnl[i].flag & HOSTAPD_CHAN_RADAR ? |
| 4542 | " (DFS)" : ""); |
| 4543 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4544 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4545 | return pos - buf; |
| 4546 | pos += ret; |
| 4547 | } |
| 4548 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4549 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4550 | return pos - buf; |
| 4551 | pos += ret; |
| 4552 | } |
| 4553 | |
| 4554 | return pos - buf; |
| 4555 | } |
| 4556 | |
| 4557 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4558 | static int wpa_supplicant_ctrl_iface_get_capability( |
| 4559 | struct wpa_supplicant *wpa_s, const char *_field, char *buf, |
| 4560 | size_t buflen) |
| 4561 | { |
| 4562 | struct wpa_driver_capa capa; |
| 4563 | int res; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4564 | char *next_param, *curr_param, *iftype = NULL; |
| 4565 | bool strict = false; |
| 4566 | char field[50]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4567 | size_t len; |
| 4568 | |
| 4569 | /* Determine whether or not strict checking was requested */ |
| 4570 | len = os_strlcpy(field, _field, sizeof(field)); |
| 4571 | if (len >= sizeof(field)) |
| 4572 | return -1; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4573 | |
| 4574 | next_param = os_strchr(field, ' '); |
| 4575 | while (next_param) { |
| 4576 | *next_param++ = '\0'; |
| 4577 | curr_param = next_param; |
| 4578 | next_param = os_strchr(next_param, ' '); |
| 4579 | |
| 4580 | if (next_param) |
| 4581 | *next_param = '\0'; |
| 4582 | |
| 4583 | if (os_strcmp(curr_param, "strict") == 0) |
| 4584 | strict = true; |
| 4585 | else if (os_strncmp(curr_param, "iftype=", 7) == 0) |
| 4586 | iftype = curr_param + 7; |
| 4587 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4588 | return -1; |
| 4589 | } |
| 4590 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4591 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'%s%s%s", |
| 4592 | field, iftype ? " iftype=" : "", iftype ? iftype : "", |
| 4593 | strict ? " strict" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4594 | |
| 4595 | if (os_strcmp(field, "eap") == 0) { |
| 4596 | return eap_get_names(buf, buflen); |
| 4597 | } |
| 4598 | |
| 4599 | res = wpa_drv_get_capa(wpa_s, &capa); |
| 4600 | |
| 4601 | if (os_strcmp(field, "pairwise") == 0) |
| 4602 | return ctrl_iface_get_capability_pairwise(res, strict, &capa, |
| 4603 | buf, buflen); |
| 4604 | |
| 4605 | if (os_strcmp(field, "group") == 0) |
| 4606 | return ctrl_iface_get_capability_group(res, strict, &capa, |
| 4607 | buf, buflen); |
| 4608 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4609 | if (os_strcmp(field, "group_mgmt") == 0) |
| 4610 | return ctrl_iface_get_capability_group_mgmt(res, strict, &capa, |
| 4611 | buf, buflen); |
| 4612 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4613 | if (os_strcmp(field, "key_mgmt") == 0) |
| 4614 | return ctrl_iface_get_capability_key_mgmt(res, strict, &capa, |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4615 | iftype, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4616 | |
| 4617 | if (os_strcmp(field, "proto") == 0) |
| 4618 | return ctrl_iface_get_capability_proto(res, strict, &capa, |
| 4619 | buf, buflen); |
| 4620 | |
| 4621 | if (os_strcmp(field, "auth_alg") == 0) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4622 | return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict, |
| 4623 | &capa, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4624 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4625 | if (os_strcmp(field, "modes") == 0) |
| 4626 | return ctrl_iface_get_capability_modes(res, strict, &capa, |
| 4627 | buf, buflen); |
| 4628 | |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4629 | if (os_strcmp(field, "channels") == 0) |
| 4630 | return ctrl_iface_get_capability_channels(wpa_s, buf, buflen); |
| 4631 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4632 | if (os_strcmp(field, "freq") == 0) |
| 4633 | return ctrl_iface_get_capability_freq(wpa_s, buf, buflen); |
| 4634 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 4635 | #ifdef CONFIG_TDLS |
| 4636 | if (os_strcmp(field, "tdls") == 0) |
| 4637 | return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen); |
| 4638 | #endif /* CONFIG_TDLS */ |
| 4639 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4640 | #ifdef CONFIG_ERP |
| 4641 | if (os_strcmp(field, "erp") == 0) { |
| 4642 | res = os_snprintf(buf, buflen, "ERP"); |
| 4643 | if (os_snprintf_error(buflen, res)) |
| 4644 | return -1; |
| 4645 | return res; |
| 4646 | } |
| 4647 | #endif /* CONFIG_EPR */ |
| 4648 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4649 | #ifdef CONFIG_FIPS |
| 4650 | if (os_strcmp(field, "fips") == 0) { |
| 4651 | res = os_snprintf(buf, buflen, "FIPS"); |
| 4652 | if (os_snprintf_error(buflen, res)) |
| 4653 | return -1; |
| 4654 | return res; |
| 4655 | } |
| 4656 | #endif /* CONFIG_FIPS */ |
| 4657 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 4658 | #ifdef CONFIG_ACS |
| 4659 | if (os_strcmp(field, "acs") == 0) { |
| 4660 | res = os_snprintf(buf, buflen, "ACS"); |
| 4661 | if (os_snprintf_error(buflen, res)) |
| 4662 | return -1; |
| 4663 | return res; |
| 4664 | } |
| 4665 | #endif /* CONFIG_ACS */ |
| 4666 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4667 | #ifdef CONFIG_FILS |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4668 | if (os_strcmp(field, "fils") == 0) { |
| 4669 | #ifdef CONFIG_FILS_SK_PFS |
| 4670 | if (wpa_is_fils_supported(wpa_s) && |
| 4671 | wpa_is_fils_sk_pfs_supported(wpa_s)) { |
| 4672 | res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS"); |
| 4673 | if (os_snprintf_error(buflen, res)) |
| 4674 | return -1; |
| 4675 | return res; |
| 4676 | } |
| 4677 | #endif /* CONFIG_FILS_SK_PFS */ |
| 4678 | |
| 4679 | if (wpa_is_fils_supported(wpa_s)) { |
| 4680 | res = os_snprintf(buf, buflen, "FILS"); |
| 4681 | if (os_snprintf_error(buflen, res)) |
| 4682 | return -1; |
| 4683 | return res; |
| 4684 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4685 | } |
| 4686 | #endif /* CONFIG_FILS */ |
| 4687 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4688 | if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) { |
| 4689 | res = os_snprintf(buf, buflen, "MULTIBSS-STA"); |
| 4690 | if (os_snprintf_error(buflen, res)) |
| 4691 | return -1; |
| 4692 | return res; |
| 4693 | } |
| 4694 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4695 | #ifdef CONFIG_DPP |
| 4696 | if (os_strcmp(field, "dpp") == 0) { |
| 4697 | #ifdef CONFIG_DPP2 |
| 4698 | res = os_snprintf(buf, buflen, "DPP=2"); |
| 4699 | #else /* CONFIG_DPP2 */ |
| 4700 | res = os_snprintf(buf, buflen, "DPP=1"); |
| 4701 | #endif /* CONFIG_DPP2 */ |
| 4702 | if (os_snprintf_error(buflen, res)) |
| 4703 | return -1; |
| 4704 | return res; |
| 4705 | } |
| 4706 | #endif /* CONFIG_DPP */ |
| 4707 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4708 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", |
| 4709 | field); |
| 4710 | |
| 4711 | return -1; |
| 4712 | } |
| 4713 | |
| 4714 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4715 | #ifdef CONFIG_INTERWORKING |
| 4716 | static char * anqp_add_hex(char *pos, char *end, const char *title, |
| 4717 | struct wpabuf *data) |
| 4718 | { |
| 4719 | char *start = pos; |
| 4720 | size_t i; |
| 4721 | int ret; |
| 4722 | const u8 *d; |
| 4723 | |
| 4724 | if (data == NULL) |
| 4725 | return start; |
| 4726 | |
| 4727 | ret = os_snprintf(pos, end - pos, "%s=", title); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4728 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4729 | return start; |
| 4730 | pos += ret; |
| 4731 | |
| 4732 | d = wpabuf_head_u8(data); |
| 4733 | for (i = 0; i < wpabuf_len(data); i++) { |
| 4734 | ret = os_snprintf(pos, end - pos, "%02x", *d++); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4735 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4736 | return start; |
| 4737 | pos += ret; |
| 4738 | } |
| 4739 | |
| 4740 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4741 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4742 | return start; |
| 4743 | pos += ret; |
| 4744 | |
| 4745 | return pos; |
| 4746 | } |
| 4747 | #endif /* CONFIG_INTERWORKING */ |
| 4748 | |
| 4749 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4750 | #ifdef CONFIG_FILS |
| 4751 | static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end) |
| 4752 | { |
| 4753 | char *start = pos; |
| 4754 | const u8 *ie, *ie_end; |
| 4755 | u16 info, realms; |
| 4756 | int ret; |
| 4757 | |
| 4758 | ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION); |
| 4759 | if (!ie) |
| 4760 | return 0; |
| 4761 | ie_end = ie + 2 + ie[1]; |
| 4762 | ie += 2; |
| 4763 | if (ie_end - ie < 2) |
| 4764 | return -1; |
| 4765 | |
| 4766 | info = WPA_GET_LE16(ie); |
| 4767 | ie += 2; |
| 4768 | ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info); |
| 4769 | if (os_snprintf_error(end - pos, ret)) |
| 4770 | return 0; |
| 4771 | pos += ret; |
| 4772 | |
| 4773 | if (info & BIT(7)) { |
| 4774 | /* Cache Identifier Included */ |
| 4775 | if (ie_end - ie < 2) |
| 4776 | return -1; |
| 4777 | ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n", |
| 4778 | ie[0], ie[1]); |
| 4779 | if (os_snprintf_error(end - pos, ret)) |
| 4780 | return 0; |
| 4781 | pos += ret; |
| 4782 | ie += 2; |
| 4783 | } |
| 4784 | |
| 4785 | if (info & BIT(8)) { |
| 4786 | /* HESSID Included */ |
| 4787 | if (ie_end - ie < ETH_ALEN) |
| 4788 | return -1; |
| 4789 | ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n", |
| 4790 | MAC2STR(ie)); |
| 4791 | if (os_snprintf_error(end - pos, ret)) |
| 4792 | return 0; |
| 4793 | pos += ret; |
| 4794 | ie += ETH_ALEN; |
| 4795 | } |
| 4796 | |
| 4797 | realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3; |
| 4798 | if (realms) { |
| 4799 | if (ie_end - ie < realms * 2) |
| 4800 | return -1; |
| 4801 | ret = os_snprintf(pos, end - pos, "fils_realms="); |
| 4802 | if (os_snprintf_error(end - pos, ret)) |
| 4803 | return 0; |
| 4804 | pos += ret; |
| 4805 | |
| 4806 | ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2); |
| 4807 | if (ret <= 0) |
| 4808 | return 0; |
| 4809 | pos += ret; |
| 4810 | ie += realms * 2; |
| 4811 | ret = os_snprintf(pos, end - pos, "\n"); |
| 4812 | if (os_snprintf_error(end - pos, ret)) |
| 4813 | return 0; |
| 4814 | pos += ret; |
| 4815 | } |
| 4816 | |
| 4817 | return pos - start; |
| 4818 | } |
| 4819 | #endif /* CONFIG_FILS */ |
| 4820 | |
| 4821 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4822 | static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 4823 | unsigned long mask, char *buf, size_t buflen) |
| 4824 | { |
| 4825 | size_t i; |
| 4826 | int ret; |
| 4827 | char *pos, *end; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4828 | const u8 *ie, *ie2, *osen_ie, *mesh, *owe; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4829 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4830 | pos = buf; |
| 4831 | end = buf + buflen; |
| 4832 | |
| 4833 | if (mask & WPA_BSS_MASK_ID) { |
| 4834 | ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4835 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4836 | return 0; |
| 4837 | pos += ret; |
| 4838 | } |
| 4839 | |
| 4840 | if (mask & WPA_BSS_MASK_BSSID) { |
| 4841 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", |
| 4842 | MAC2STR(bss->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4843 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4844 | return 0; |
| 4845 | pos += ret; |
| 4846 | } |
| 4847 | |
| 4848 | if (mask & WPA_BSS_MASK_FREQ) { |
| 4849 | ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4850 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4851 | return 0; |
| 4852 | pos += ret; |
| 4853 | } |
| 4854 | |
| 4855 | if (mask & WPA_BSS_MASK_BEACON_INT) { |
| 4856 | ret = os_snprintf(pos, end - pos, "beacon_int=%d\n", |
| 4857 | bss->beacon_int); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4858 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4859 | return 0; |
| 4860 | pos += ret; |
| 4861 | } |
| 4862 | |
| 4863 | if (mask & WPA_BSS_MASK_CAPABILITIES) { |
| 4864 | ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n", |
| 4865 | bss->caps); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4866 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4867 | return 0; |
| 4868 | pos += ret; |
| 4869 | } |
| 4870 | |
| 4871 | if (mask & WPA_BSS_MASK_QUAL) { |
| 4872 | ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4873 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4874 | return 0; |
| 4875 | pos += ret; |
| 4876 | } |
| 4877 | |
| 4878 | if (mask & WPA_BSS_MASK_NOISE) { |
| 4879 | ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4880 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4881 | return 0; |
| 4882 | pos += ret; |
| 4883 | } |
| 4884 | |
| 4885 | if (mask & WPA_BSS_MASK_LEVEL) { |
| 4886 | ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4887 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4888 | return 0; |
| 4889 | pos += ret; |
| 4890 | } |
| 4891 | |
| 4892 | if (mask & WPA_BSS_MASK_TSF) { |
| 4893 | ret = os_snprintf(pos, end - pos, "tsf=%016llu\n", |
| 4894 | (unsigned long long) bss->tsf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4895 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4896 | return 0; |
| 4897 | pos += ret; |
| 4898 | } |
| 4899 | |
| 4900 | if (mask & WPA_BSS_MASK_AGE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4901 | struct os_reltime now; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4902 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4903 | os_get_reltime(&now); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4904 | ret = os_snprintf(pos, end - pos, "age=%d\n", |
| 4905 | (int) (now.sec - bss->last_update.sec)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4906 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4907 | return 0; |
| 4908 | pos += ret; |
| 4909 | } |
| 4910 | |
| 4911 | if (mask & WPA_BSS_MASK_IE) { |
| 4912 | ret = os_snprintf(pos, end - pos, "ie="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4913 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4914 | return 0; |
| 4915 | pos += ret; |
| 4916 | |
| 4917 | ie = (const u8 *) (bss + 1); |
| 4918 | for (i = 0; i < bss->ie_len; i++) { |
| 4919 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4920 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4921 | return 0; |
| 4922 | pos += ret; |
| 4923 | } |
| 4924 | |
| 4925 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4926 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4927 | return 0; |
| 4928 | pos += ret; |
| 4929 | } |
| 4930 | |
| 4931 | if (mask & WPA_BSS_MASK_FLAGS) { |
| 4932 | ret = os_snprintf(pos, end - pos, "flags="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4933 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4934 | return 0; |
| 4935 | pos += ret; |
| 4936 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4937 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
| 4938 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4939 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 4940 | if (ie) |
| 4941 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, |
| 4942 | 2 + ie[1]); |
| 4943 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 4944 | if (ie2) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4945 | pos = wpa_supplicant_ie_txt(pos, end, |
| 4946 | mesh ? "RSN" : "WPA2", ie2, |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4947 | 2 + ie2[1]); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 4948 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
| 4949 | if (osen_ie) |
| 4950 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", |
| 4951 | osen_ie, 2 + osen_ie[1]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4952 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
| 4953 | if (owe) { |
| 4954 | ret = os_snprintf( |
| 4955 | pos, end - pos, |
| 4956 | ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]"); |
| 4957 | if (os_snprintf_error(end - pos, ret)) |
| 4958 | return 0; |
| 4959 | pos += ret; |
| 4960 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4961 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 4962 | if (!ie && !ie2 && !osen_ie && |
| 4963 | (bss->caps & IEEE80211_CAP_PRIVACY)) { |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4964 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4965 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4966 | return 0; |
| 4967 | pos += ret; |
| 4968 | } |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4969 | |
| 4970 | if (mesh) { |
| 4971 | ret = os_snprintf(pos, end - pos, "[MESH]"); |
| 4972 | if (os_snprintf_error(end - pos, ret)) |
| 4973 | return 0; |
| 4974 | pos += ret; |
| 4975 | } |
| 4976 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4977 | if (bss_is_dmg(bss)) { |
| 4978 | const char *s; |
| 4979 | ret = os_snprintf(pos, end - pos, "[DMG]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4980 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4981 | return 0; |
| 4982 | pos += ret; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4983 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
| 4984 | case IEEE80211_CAP_DMG_IBSS: |
| 4985 | s = "[IBSS]"; |
| 4986 | break; |
| 4987 | case IEEE80211_CAP_DMG_AP: |
| 4988 | s = "[ESS]"; |
| 4989 | break; |
| 4990 | case IEEE80211_CAP_DMG_PBSS: |
| 4991 | s = "[PBSS]"; |
| 4992 | break; |
| 4993 | default: |
| 4994 | s = ""; |
| 4995 | break; |
| 4996 | } |
| 4997 | ret = os_snprintf(pos, end - pos, "%s", s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4998 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4999 | return 0; |
| 5000 | pos += ret; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5001 | } else { |
| 5002 | if (bss->caps & IEEE80211_CAP_IBSS) { |
| 5003 | ret = os_snprintf(pos, end - pos, "[IBSS]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5004 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5005 | return 0; |
| 5006 | pos += ret; |
| 5007 | } |
| 5008 | if (bss->caps & IEEE80211_CAP_ESS) { |
| 5009 | ret = os_snprintf(pos, end - pos, "[ESS]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5010 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5011 | return 0; |
| 5012 | pos += ret; |
| 5013 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5014 | } |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 5015 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || |
| 5016 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5017 | ret = os_snprintf(pos, end - pos, "[P2P]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5018 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5019 | return 0; |
| 5020 | pos += ret; |
| 5021 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5022 | #ifdef CONFIG_HS20 |
| 5023 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) { |
| 5024 | ret = os_snprintf(pos, end - pos, "[HS20]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5025 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5026 | return 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5027 | pos += ret; |
| 5028 | } |
| 5029 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5030 | #ifdef CONFIG_FILS |
| 5031 | if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) { |
| 5032 | ret = os_snprintf(pos, end - pos, "[FILS]"); |
| 5033 | if (os_snprintf_error(end - pos, ret)) |
| 5034 | return 0; |
| 5035 | pos += ret; |
| 5036 | } |
| 5037 | #endif /* CONFIG_FILS */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5038 | #ifdef CONFIG_FST |
| 5039 | if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) { |
| 5040 | ret = os_snprintf(pos, end - pos, "[FST]"); |
| 5041 | if (os_snprintf_error(end - pos, ret)) |
| 5042 | return 0; |
| 5043 | pos += ret; |
| 5044 | } |
| 5045 | #endif /* CONFIG_FST */ |
| 5046 | if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) { |
| 5047 | ret = os_snprintf(pos, end - pos, "[UTF-8]"); |
| 5048 | if (os_snprintf_error(end - pos, ret)) |
| 5049 | return 0; |
| 5050 | pos += ret; |
| 5051 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5052 | |
| 5053 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5054 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5055 | return 0; |
| 5056 | pos += ret; |
| 5057 | } |
| 5058 | |
| 5059 | if (mask & WPA_BSS_MASK_SSID) { |
| 5060 | ret = os_snprintf(pos, end - pos, "ssid=%s\n", |
| 5061 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5062 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5063 | return 0; |
| 5064 | pos += ret; |
| 5065 | } |
| 5066 | |
| 5067 | #ifdef CONFIG_WPS |
| 5068 | if (mask & WPA_BSS_MASK_WPS_SCAN) { |
| 5069 | ie = (const u8 *) (bss + 1); |
| 5070 | ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5071 | if (ret >= end - pos) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5072 | return 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5073 | if (ret > 0) |
| 5074 | pos += ret; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5075 | } |
| 5076 | #endif /* CONFIG_WPS */ |
| 5077 | |
| 5078 | #ifdef CONFIG_P2P |
| 5079 | if (mask & WPA_BSS_MASK_P2P_SCAN) { |
| 5080 | ie = (const u8 *) (bss + 1); |
| 5081 | ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5082 | if (ret >= end - pos) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5083 | return 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5084 | if (ret > 0) |
| 5085 | pos += ret; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5086 | } |
| 5087 | #endif /* CONFIG_P2P */ |
| 5088 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5089 | #ifdef CONFIG_WIFI_DISPLAY |
| 5090 | if (mask & WPA_BSS_MASK_WIFI_DISPLAY) { |
| 5091 | struct wpabuf *wfd; |
| 5092 | ie = (const u8 *) (bss + 1); |
| 5093 | wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len, |
| 5094 | WFD_IE_VENDOR_TYPE); |
| 5095 | if (wfd) { |
| 5096 | ret = os_snprintf(pos, end - pos, "wfd_subelems="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5097 | if (os_snprintf_error(end - pos, ret)) { |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5098 | wpabuf_free(wfd); |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5099 | return 0; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5100 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5101 | pos += ret; |
| 5102 | |
| 5103 | pos += wpa_snprintf_hex(pos, end - pos, |
| 5104 | wpabuf_head(wfd), |
| 5105 | wpabuf_len(wfd)); |
| 5106 | wpabuf_free(wfd); |
| 5107 | |
| 5108 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5109 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5110 | return 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5111 | pos += ret; |
| 5112 | } |
| 5113 | } |
| 5114 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 5115 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5116 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5117 | if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) { |
| 5118 | struct wpa_bss_anqp *anqp = bss->anqp; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5119 | struct wpa_bss_anqp_elem *elem; |
| 5120 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5121 | pos = anqp_add_hex(pos, end, "anqp_capability_list", |
| 5122 | anqp->capability_list); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5123 | pos = anqp_add_hex(pos, end, "anqp_venue_name", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5124 | anqp->venue_name); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5125 | pos = anqp_add_hex(pos, end, "anqp_network_auth_type", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5126 | anqp->network_auth_type); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5127 | pos = anqp_add_hex(pos, end, "anqp_roaming_consortium", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5128 | anqp->roaming_consortium); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5129 | pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5130 | anqp->ip_addr_type_availability); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5131 | pos = anqp_add_hex(pos, end, "anqp_nai_realm", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5132 | anqp->nai_realm); |
| 5133 | pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5134 | pos = anqp_add_hex(pos, end, "anqp_domain_name", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5135 | anqp->domain_name); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5136 | pos = anqp_add_hex(pos, end, "anqp_fils_realm_info", |
| 5137 | anqp->fils_realm_info); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5138 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5139 | pos = anqp_add_hex(pos, end, "hs20_capability_list", |
| 5140 | anqp->hs20_capability_list); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5141 | pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5142 | anqp->hs20_operator_friendly_name); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5143 | pos = anqp_add_hex(pos, end, "hs20_wan_metrics", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5144 | anqp->hs20_wan_metrics); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5145 | pos = anqp_add_hex(pos, end, "hs20_connection_capability", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5146 | anqp->hs20_connection_capability); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5147 | pos = anqp_add_hex(pos, end, "hs20_operating_class", |
| 5148 | anqp->hs20_operating_class); |
| 5149 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_list", |
| 5150 | anqp->hs20_osu_providers_list); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5151 | pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata", |
| 5152 | anqp->hs20_operator_icon_metadata); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 5153 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list", |
| 5154 | anqp->hs20_osu_providers_nai_list); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5155 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5156 | |
| 5157 | dl_list_for_each(elem, &anqp->anqp_elems, |
| 5158 | struct wpa_bss_anqp_elem, list) { |
| 5159 | char title[20]; |
| 5160 | |
| 5161 | os_snprintf(title, sizeof(title), "anqp[%u]", |
| 5162 | elem->infoid); |
| 5163 | pos = anqp_add_hex(pos, end, title, elem->payload); |
| 5164 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5165 | } |
| 5166 | #endif /* CONFIG_INTERWORKING */ |
| 5167 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5168 | #ifdef CONFIG_MESH |
| 5169 | if (mask & WPA_BSS_MASK_MESH_SCAN) { |
| 5170 | ie = (const u8 *) (bss + 1); |
| 5171 | ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5172 | if (ret >= end - pos) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5173 | return 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5174 | if (ret > 0) |
| 5175 | pos += ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5176 | } |
| 5177 | #endif /* CONFIG_MESH */ |
| 5178 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5179 | if (mask & WPA_BSS_MASK_SNR) { |
| 5180 | ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr); |
| 5181 | if (os_snprintf_error(end - pos, ret)) |
| 5182 | return 0; |
| 5183 | pos += ret; |
| 5184 | } |
| 5185 | |
| 5186 | if (mask & WPA_BSS_MASK_EST_THROUGHPUT) { |
| 5187 | ret = os_snprintf(pos, end - pos, "est_throughput=%d\n", |
| 5188 | bss->est_throughput); |
| 5189 | if (os_snprintf_error(end - pos, ret)) |
| 5190 | return 0; |
| 5191 | pos += ret; |
| 5192 | } |
| 5193 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5194 | #ifdef CONFIG_FST |
| 5195 | if (mask & WPA_BSS_MASK_FST) { |
| 5196 | ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos); |
| 5197 | if (ret < 0 || ret >= end - pos) |
| 5198 | return 0; |
| 5199 | pos += ret; |
| 5200 | } |
| 5201 | #endif /* CONFIG_FST */ |
| 5202 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5203 | if (mask & WPA_BSS_MASK_UPDATE_IDX) { |
| 5204 | ret = os_snprintf(pos, end - pos, "update_idx=%u\n", |
| 5205 | bss->last_update_idx); |
| 5206 | if (os_snprintf_error(end - pos, ret)) |
| 5207 | return 0; |
| 5208 | pos += ret; |
| 5209 | } |
| 5210 | |
| 5211 | if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) { |
| 5212 | ret = os_snprintf(pos, end - pos, "beacon_ie="); |
| 5213 | if (os_snprintf_error(end - pos, ret)) |
| 5214 | return 0; |
| 5215 | pos += ret; |
| 5216 | |
| 5217 | ie = (const u8 *) (bss + 1); |
| 5218 | ie += bss->ie_len; |
| 5219 | for (i = 0; i < bss->beacon_ie_len; i++) { |
| 5220 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); |
| 5221 | if (os_snprintf_error(end - pos, ret)) |
| 5222 | return 0; |
| 5223 | pos += ret; |
| 5224 | } |
| 5225 | |
| 5226 | ret = os_snprintf(pos, end - pos, "\n"); |
| 5227 | if (os_snprintf_error(end - pos, ret)) |
| 5228 | return 0; |
| 5229 | pos += ret; |
| 5230 | } |
| 5231 | |
| 5232 | #ifdef CONFIG_FILS |
| 5233 | if (mask & WPA_BSS_MASK_FILS_INDICATION) { |
| 5234 | ret = print_fils_indication(bss, pos, end); |
| 5235 | if (ret < 0) |
| 5236 | return 0; |
| 5237 | pos += ret; |
| 5238 | } |
| 5239 | #endif /* CONFIG_FILS */ |
| 5240 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5241 | if (mask & WPA_BSS_MASK_DELIM) { |
| 5242 | ret = os_snprintf(pos, end - pos, "====\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5243 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5244 | return 0; |
| 5245 | pos += ret; |
| 5246 | } |
Irfan Sheriff | e2ea008 | 2012-08-13 10:56:16 -0700 | [diff] [blame] | 5247 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5248 | return pos - buf; |
| 5249 | } |
| 5250 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5251 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5252 | static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s, |
| 5253 | const char *cmd, char *buf, |
| 5254 | size_t buflen) |
| 5255 | { |
| 5256 | u8 bssid[ETH_ALEN]; |
| 5257 | size_t i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5258 | struct wpa_bss *bss; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5259 | struct wpa_bss *bsslast = NULL; |
| 5260 | struct dl_list *next; |
| 5261 | int ret = 0; |
| 5262 | int len; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5263 | char *ctmp, *end = buf + buflen; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5264 | unsigned long mask = WPA_BSS_MASK_ALL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5265 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5266 | if (os_strncmp(cmd, "RANGE=", 6) == 0) { |
| 5267 | if (os_strncmp(cmd + 6, "ALL", 3) == 0) { |
| 5268 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5269 | list_id); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5270 | bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss, |
| 5271 | list_id); |
| 5272 | } else { /* N1-N2 */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5273 | unsigned int id1, id2; |
| 5274 | |
| 5275 | if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) { |
| 5276 | wpa_printf(MSG_INFO, "Wrong BSS range " |
| 5277 | "format"); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5278 | return 0; |
| 5279 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5280 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5281 | if (*(cmd + 6) == '-') |
| 5282 | id1 = 0; |
| 5283 | else |
| 5284 | id1 = atoi(cmd + 6); |
| 5285 | ctmp++; |
| 5286 | if (*ctmp >= '0' && *ctmp <= '9') |
| 5287 | id2 = atoi(ctmp); |
| 5288 | else |
| 5289 | id2 = (unsigned int) -1; |
| 5290 | bss = wpa_bss_get_id_range(wpa_s, id1, id2); |
| 5291 | if (id2 == (unsigned int) -1) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5292 | bsslast = dl_list_last(&wpa_s->bss_id, |
| 5293 | struct wpa_bss, |
| 5294 | list_id); |
| 5295 | else { |
| 5296 | bsslast = wpa_bss_get_id(wpa_s, id2); |
| 5297 | if (bsslast == NULL && bss && id2 > id1) { |
| 5298 | struct wpa_bss *tmp = bss; |
| 5299 | for (;;) { |
| 5300 | next = tmp->list_id.next; |
| 5301 | if (next == &wpa_s->bss_id) |
| 5302 | break; |
| 5303 | tmp = dl_list_entry( |
| 5304 | next, struct wpa_bss, |
| 5305 | list_id); |
| 5306 | if (tmp->id > id2) |
| 5307 | break; |
| 5308 | bsslast = tmp; |
| 5309 | } |
| 5310 | } |
| 5311 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5312 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5313 | } else if (os_strncmp(cmd, "FIRST", 5) == 0) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5314 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5315 | else if (os_strncmp(cmd, "LAST", 4) == 0) |
| 5316 | bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5317 | else if (os_strncmp(cmd, "ID-", 3) == 0) { |
| 5318 | i = atoi(cmd + 3); |
| 5319 | bss = wpa_bss_get_id(wpa_s, i); |
| 5320 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { |
| 5321 | i = atoi(cmd + 5); |
| 5322 | bss = wpa_bss_get_id(wpa_s, i); |
| 5323 | if (bss) { |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5324 | next = bss->list_id.next; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5325 | if (next == &wpa_s->bss_id) |
| 5326 | bss = NULL; |
| 5327 | else |
| 5328 | bss = dl_list_entry(next, struct wpa_bss, |
| 5329 | list_id); |
| 5330 | } |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5331 | } else if (os_strncmp(cmd, "CURRENT", 7) == 0) { |
| 5332 | bss = wpa_s->current_bss; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5333 | #ifdef CONFIG_P2P |
| 5334 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { |
| 5335 | if (hwaddr_aton(cmd + 13, bssid) == 0) |
| 5336 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid); |
| 5337 | else |
| 5338 | bss = NULL; |
| 5339 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5340 | } else if (hwaddr_aton(cmd, bssid) == 0) |
| 5341 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 5342 | else { |
| 5343 | struct wpa_bss *tmp; |
| 5344 | i = atoi(cmd); |
| 5345 | bss = NULL; |
| 5346 | dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id) |
| 5347 | { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5348 | if (i == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5349 | bss = tmp; |
| 5350 | break; |
| 5351 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5352 | i--; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5353 | } |
| 5354 | } |
| 5355 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5356 | if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) { |
| 5357 | mask = strtoul(ctmp + 5, NULL, 0x10); |
| 5358 | if (mask == 0) |
| 5359 | mask = WPA_BSS_MASK_ALL; |
| 5360 | } |
| 5361 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5362 | if (bss == NULL) |
| 5363 | return 0; |
| 5364 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5365 | if (bsslast == NULL) |
| 5366 | bsslast = bss; |
| 5367 | do { |
| 5368 | len = print_bss_info(wpa_s, bss, mask, buf, buflen); |
| 5369 | ret += len; |
| 5370 | buf += len; |
| 5371 | buflen -= len; |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5372 | if (bss == bsslast) { |
| 5373 | if ((mask & WPA_BSS_MASK_DELIM) && len && |
| 5374 | (bss == dl_list_last(&wpa_s->bss_id, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5375 | struct wpa_bss, list_id))) { |
| 5376 | int res; |
| 5377 | |
| 5378 | res = os_snprintf(buf - 5, end - buf + 5, |
| 5379 | "####\n"); |
| 5380 | if (os_snprintf_error(end - buf + 5, res)) { |
| 5381 | wpa_printf(MSG_DEBUG, |
| 5382 | "Could not add end delim"); |
| 5383 | } |
| 5384 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5385 | break; |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5386 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5387 | next = bss->list_id.next; |
| 5388 | if (next == &wpa_s->bss_id) |
| 5389 | break; |
| 5390 | bss = dl_list_entry(next, struct wpa_bss, list_id); |
| 5391 | } while (bss && len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5392 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5393 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | |
| 5397 | static int wpa_supplicant_ctrl_iface_ap_scan( |
| 5398 | struct wpa_supplicant *wpa_s, char *cmd) |
| 5399 | { |
| 5400 | int ap_scan = atoi(cmd); |
| 5401 | return wpa_supplicant_set_ap_scan(wpa_s, ap_scan); |
| 5402 | } |
| 5403 | |
| 5404 | |
| 5405 | static int wpa_supplicant_ctrl_iface_scan_interval( |
| 5406 | struct wpa_supplicant *wpa_s, char *cmd) |
| 5407 | { |
| 5408 | int scan_int = atoi(cmd); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5409 | return wpa_supplicant_set_scan_interval(wpa_s, scan_int); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | |
| 5413 | static int wpa_supplicant_ctrl_iface_bss_expire_age( |
| 5414 | struct wpa_supplicant *wpa_s, char *cmd) |
| 5415 | { |
| 5416 | int expire_age = atoi(cmd); |
| 5417 | return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age); |
| 5418 | } |
| 5419 | |
| 5420 | |
| 5421 | static int wpa_supplicant_ctrl_iface_bss_expire_count( |
| 5422 | struct wpa_supplicant *wpa_s, char *cmd) |
| 5423 | { |
| 5424 | int expire_count = atoi(cmd); |
| 5425 | return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count); |
| 5426 | } |
| 5427 | |
| 5428 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5429 | static void wpa_supplicant_ctrl_iface_bss_flush( |
Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 5430 | struct wpa_supplicant *wpa_s, char *cmd) |
| 5431 | { |
| 5432 | int flush_age = atoi(cmd); |
| 5433 | |
| 5434 | if (flush_age == 0) |
| 5435 | wpa_bss_flush(wpa_s); |
| 5436 | else |
| 5437 | wpa_bss_flush_by_age(wpa_s, flush_age); |
Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 5441 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5442 | static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s) |
| 5443 | { |
| 5444 | wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication"); |
| 5445 | /* MLME-DELETEKEYS.request */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5446 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, |
| 5447 | 0, KEY_FLAG_GROUP); |
| 5448 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, |
| 5449 | 0, KEY_FLAG_GROUP); |
| 5450 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, |
| 5451 | 0, KEY_FLAG_GROUP); |
| 5452 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, |
| 5453 | 0, KEY_FLAG_GROUP); |
| 5454 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, |
| 5455 | 0, KEY_FLAG_GROUP); |
| 5456 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, |
| 5457 | 0, KEY_FLAG_GROUP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5458 | |
| 5459 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5460 | 0, KEY_FLAG_PAIRWISE); |
| 5461 | if (wpa_sm_ext_key_id(wpa_s->wpa)) |
| 5462 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 1, 0, |
| 5463 | NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5464 | /* MLME-SETPROTECTION.request(None) */ |
| 5465 | wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid, |
| 5466 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, |
| 5467 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); |
| 5468 | wpa_sm_drop_sa(wpa_s->wpa); |
| 5469 | } |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 5470 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5471 | |
| 5472 | |
| 5473 | static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s, |
| 5474 | char *addr) |
| 5475 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5476 | #ifdef CONFIG_NO_SCAN_PROCESSING |
| 5477 | return -1; |
| 5478 | #else /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5479 | u8 bssid[ETH_ALEN]; |
| 5480 | struct wpa_bss *bss; |
| 5481 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 5482 | |
| 5483 | if (hwaddr_aton(addr, bssid)) { |
| 5484 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid " |
| 5485 | "address '%s'", addr); |
| 5486 | return -1; |
| 5487 | } |
| 5488 | |
| 5489 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid)); |
| 5490 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5491 | if (!ssid) { |
| 5492 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network " |
| 5493 | "configuration known for the target AP"); |
| 5494 | return -1; |
| 5495 | } |
| 5496 | |
| 5497 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5498 | if (!bss) { |
| 5499 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found " |
| 5500 | "from BSS table"); |
| 5501 | return -1; |
| 5502 | } |
| 5503 | |
| 5504 | /* |
| 5505 | * TODO: Find best network configuration block from configuration to |
| 5506 | * allow roaming to other networks |
| 5507 | */ |
| 5508 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5509 | wpa_s->reassociate = 1; |
| 5510 | wpa_supplicant_connect(wpa_s, bss, ssid); |
| 5511 | |
| 5512 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5513 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5514 | } |
| 5515 | |
| 5516 | |
| 5517 | #ifdef CONFIG_P2P |
| 5518 | static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd) |
| 5519 | { |
| 5520 | unsigned int timeout = atoi(cmd); |
| 5521 | enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5522 | u8 dev_id[ETH_ALEN], *_dev_id = NULL; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5523 | u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5524 | char *pos; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5525 | unsigned int search_delay; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5526 | const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5527 | u8 seek_count = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5528 | int freq = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5529 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 5530 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 5531 | wpa_dbg(wpa_s, MSG_INFO, |
| 5532 | "Reject P2P_FIND since interface is disabled"); |
| 5533 | return -1; |
| 5534 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5535 | if (os_strstr(cmd, "type=social")) |
| 5536 | type = P2P_FIND_ONLY_SOCIAL; |
| 5537 | else if (os_strstr(cmd, "type=progressive")) |
| 5538 | type = P2P_FIND_PROGRESSIVE; |
| 5539 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5540 | pos = os_strstr(cmd, "dev_id="); |
| 5541 | if (pos) { |
| 5542 | pos += 7; |
| 5543 | if (hwaddr_aton(pos, dev_id)) |
| 5544 | return -1; |
| 5545 | _dev_id = dev_id; |
| 5546 | } |
| 5547 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5548 | pos = os_strstr(cmd, "dev_type="); |
| 5549 | if (pos) { |
| 5550 | pos += 9; |
| 5551 | if (wps_dev_type_str2bin(pos, dev_type) < 0) |
| 5552 | return -1; |
| 5553 | _dev_type = dev_type; |
| 5554 | } |
| 5555 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5556 | pos = os_strstr(cmd, "delay="); |
| 5557 | if (pos) { |
| 5558 | pos += 6; |
| 5559 | search_delay = atoi(pos); |
| 5560 | } else |
| 5561 | search_delay = wpas_p2p_search_delay(wpa_s); |
| 5562 | |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 5563 | pos = os_strstr(cmd, "freq="); |
| 5564 | if (pos) { |
| 5565 | pos += 5; |
| 5566 | freq = atoi(pos); |
| 5567 | if (freq <= 0) |
| 5568 | return -1; |
| 5569 | } |
| 5570 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5571 | /* Must be searched for last, because it adds nul termination */ |
| 5572 | pos = os_strstr(cmd, " seek="); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5573 | if (pos) |
| 5574 | pos += 6; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5575 | while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) { |
| 5576 | char *term; |
| 5577 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5578 | _seek[seek_count++] = pos; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5579 | seek = _seek; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5580 | term = os_strchr(pos, ' '); |
| 5581 | if (!term) |
| 5582 | break; |
| 5583 | *term = '\0'; |
| 5584 | pos = os_strstr(term + 1, "seek="); |
| 5585 | if (pos) |
| 5586 | pos += 5; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5587 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5588 | if (seek_count > P2P_MAX_QUERY_HASH) { |
| 5589 | seek[0] = NULL; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5590 | seek_count = 1; |
| 5591 | } |
| 5592 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5593 | return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type, |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5594 | _dev_id, search_delay, seek_count, seek, freq); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5595 | } |
| 5596 | |
| 5597 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5598 | static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt) |
| 5599 | { |
| 5600 | const char *last = NULL; |
| 5601 | const char *token; |
| 5602 | long int token_len; |
| 5603 | unsigned int i; |
| 5604 | |
| 5605 | /* Expected predefined CPT names delimited by ':' */ |
| 5606 | for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) { |
| 5607 | if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) { |
| 5608 | wpa_printf(MSG_ERROR, |
| 5609 | "P2PS: CPT name list is too long, expected up to %d names", |
| 5610 | P2PS_FEATURE_CAPAB_CPT_MAX); |
| 5611 | cpt[0] = 0; |
| 5612 | return -1; |
| 5613 | } |
| 5614 | |
| 5615 | token_len = last - token; |
| 5616 | |
| 5617 | if (token_len == 3 && |
| 5618 | os_memcmp(token, "UDP", token_len) == 0) { |
| 5619 | cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; |
| 5620 | } else if (token_len == 3 && |
| 5621 | os_memcmp(token, "MAC", token_len) == 0) { |
| 5622 | cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT; |
| 5623 | } else { |
| 5624 | wpa_printf(MSG_ERROR, |
| 5625 | "P2PS: Unsupported CPT name '%s'", token); |
| 5626 | cpt[0] = 0; |
| 5627 | return -1; |
| 5628 | } |
| 5629 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5630 | if (isblank((unsigned char) *last)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5631 | i++; |
| 5632 | break; |
| 5633 | } |
| 5634 | } |
| 5635 | cpt[i] = 0; |
| 5636 | return 0; |
| 5637 | } |
| 5638 | |
| 5639 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5640 | static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd) |
| 5641 | { |
| 5642 | struct p2ps_provision *p2ps_prov; |
| 5643 | char *pos; |
| 5644 | size_t info_len = 0; |
| 5645 | char *info = NULL; |
| 5646 | u8 role = P2PS_SETUP_NONE; |
| 5647 | long long unsigned val; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5648 | int i; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5649 | |
| 5650 | pos = os_strstr(cmd, "info="); |
| 5651 | if (pos) { |
| 5652 | pos += 5; |
| 5653 | info_len = os_strlen(pos); |
| 5654 | |
| 5655 | if (info_len) { |
| 5656 | info = os_malloc(info_len + 1); |
| 5657 | if (info) { |
| 5658 | info_len = utf8_unescape(pos, info_len, |
| 5659 | info, info_len + 1); |
| 5660 | } else |
| 5661 | info_len = 0; |
| 5662 | } |
| 5663 | } |
| 5664 | |
| 5665 | p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1); |
| 5666 | if (p2ps_prov == NULL) { |
| 5667 | os_free(info); |
| 5668 | return NULL; |
| 5669 | } |
| 5670 | |
| 5671 | if (info) { |
| 5672 | os_memcpy(p2ps_prov->info, info, info_len); |
| 5673 | p2ps_prov->info[info_len] = '\0'; |
| 5674 | os_free(info); |
| 5675 | } |
| 5676 | |
| 5677 | pos = os_strstr(cmd, "status="); |
| 5678 | if (pos) |
| 5679 | p2ps_prov->status = atoi(pos + 7); |
| 5680 | else |
| 5681 | p2ps_prov->status = -1; |
| 5682 | |
| 5683 | pos = os_strstr(cmd, "adv_id="); |
| 5684 | if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL) |
| 5685 | goto invalid_args; |
| 5686 | p2ps_prov->adv_id = val; |
| 5687 | |
| 5688 | pos = os_strstr(cmd, "method="); |
| 5689 | if (pos) |
| 5690 | p2ps_prov->method = strtol(pos + 7, NULL, 16); |
| 5691 | else |
| 5692 | p2ps_prov->method = 0; |
| 5693 | |
| 5694 | pos = os_strstr(cmd, "session="); |
| 5695 | if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL) |
| 5696 | goto invalid_args; |
| 5697 | p2ps_prov->session_id = val; |
| 5698 | |
| 5699 | pos = os_strstr(cmd, "adv_mac="); |
| 5700 | if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac)) |
| 5701 | goto invalid_args; |
| 5702 | |
| 5703 | pos = os_strstr(cmd, "session_mac="); |
| 5704 | if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac)) |
| 5705 | goto invalid_args; |
| 5706 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5707 | pos = os_strstr(cmd, "cpt="); |
| 5708 | if (pos) { |
| 5709 | if (p2ps_ctrl_parse_cpt_priority(pos + 4, |
| 5710 | p2ps_prov->cpt_priority)) |
| 5711 | goto invalid_args; |
| 5712 | } else { |
| 5713 | p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; |
| 5714 | } |
| 5715 | |
| 5716 | for (i = 0; p2ps_prov->cpt_priority[i]; i++) |
| 5717 | p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i]; |
| 5718 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5719 | /* force conncap with tstCap (no sanity checks) */ |
| 5720 | pos = os_strstr(cmd, "tstCap="); |
| 5721 | if (pos) { |
| 5722 | role = strtol(pos + 7, NULL, 16); |
| 5723 | } else { |
| 5724 | pos = os_strstr(cmd, "role="); |
| 5725 | if (pos) { |
| 5726 | role = strtol(pos + 5, NULL, 16); |
| 5727 | if (role != P2PS_SETUP_CLIENT && |
| 5728 | role != P2PS_SETUP_GROUP_OWNER) |
| 5729 | role = P2PS_SETUP_NONE; |
| 5730 | } |
| 5731 | } |
| 5732 | p2ps_prov->role = role; |
| 5733 | |
| 5734 | return p2ps_prov; |
| 5735 | |
| 5736 | invalid_args: |
| 5737 | os_free(p2ps_prov); |
| 5738 | return NULL; |
| 5739 | } |
| 5740 | |
| 5741 | |
| 5742 | static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd) |
| 5743 | { |
| 5744 | u8 addr[ETH_ALEN]; |
| 5745 | struct p2ps_provision *p2ps_prov; |
| 5746 | char *pos; |
| 5747 | |
| 5748 | /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */ |
| 5749 | |
| 5750 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); |
| 5751 | |
| 5752 | if (hwaddr_aton(cmd, addr)) |
| 5753 | return -1; |
| 5754 | |
| 5755 | pos = cmd + 17; |
| 5756 | if (*pos != ' ') |
| 5757 | return -1; |
| 5758 | |
| 5759 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); |
| 5760 | if (!p2ps_prov) |
| 5761 | return -1; |
| 5762 | |
| 5763 | if (p2ps_prov->status < 0) { |
| 5764 | os_free(p2ps_prov); |
| 5765 | return -1; |
| 5766 | } |
| 5767 | |
| 5768 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, |
| 5769 | p2ps_prov); |
| 5770 | } |
| 5771 | |
| 5772 | |
| 5773 | static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd) |
| 5774 | { |
| 5775 | u8 addr[ETH_ALEN]; |
| 5776 | struct p2ps_provision *p2ps_prov; |
| 5777 | char *pos; |
| 5778 | |
| 5779 | /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap> |
| 5780 | * session=<ses_id> mac=<ses_mac> [info=<infodata>] |
| 5781 | */ |
| 5782 | |
| 5783 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); |
| 5784 | if (hwaddr_aton(cmd, addr)) |
| 5785 | return -1; |
| 5786 | |
| 5787 | pos = cmd + 17; |
| 5788 | if (*pos != ' ') |
| 5789 | return -1; |
| 5790 | |
| 5791 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); |
| 5792 | if (!p2ps_prov) |
| 5793 | return -1; |
| 5794 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5795 | p2ps_prov->pd_seeker = 1; |
| 5796 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5797 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, |
| 5798 | p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5799 | } |
| 5800 | |
| 5801 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5802 | static int parse_freq(int chwidth, int freq2) |
| 5803 | { |
| 5804 | if (freq2 < 0) |
| 5805 | return -1; |
| 5806 | if (freq2) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5807 | return CHANWIDTH_80P80MHZ; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5808 | |
| 5809 | switch (chwidth) { |
| 5810 | case 0: |
| 5811 | case 20: |
| 5812 | case 40: |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5813 | return CHANWIDTH_USE_HT; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5814 | case 80: |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5815 | return CHANWIDTH_80MHZ; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5816 | case 160: |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5817 | return CHANWIDTH_160MHZ; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5818 | default: |
| 5819 | wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d", |
| 5820 | chwidth); |
| 5821 | return -1; |
| 5822 | } |
| 5823 | } |
| 5824 | |
| 5825 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5826 | static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd, |
| 5827 | char *buf, size_t buflen) |
| 5828 | { |
| 5829 | u8 addr[ETH_ALEN]; |
| 5830 | char *pos, *pos2; |
| 5831 | char *pin = NULL; |
| 5832 | enum p2p_wps_method wps_method; |
| 5833 | int new_pin; |
| 5834 | int ret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5835 | int persistent_group, persistent_id = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5836 | int join; |
| 5837 | int auth; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5838 | int automatic; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5839 | int go_intent = -1; |
| 5840 | int freq = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5841 | int pd; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5842 | int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5843 | int edmg; |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5844 | u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL; |
| 5845 | size_t group_ssid_len = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5846 | int he; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5847 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5848 | if (!wpa_s->global->p2p_init_wpa_s) |
| 5849 | return -1; |
| 5850 | if (wpa_s->global->p2p_init_wpa_s != wpa_s) { |
| 5851 | wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s", |
| 5852 | wpa_s->global->p2p_init_wpa_s->ifname); |
| 5853 | wpa_s = wpa_s->global->p2p_init_wpa_s; |
| 5854 | } |
| 5855 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5856 | /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps] |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5857 | * [persistent|persistent=<network id>] |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5858 | * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5859 | * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5860 | |
| 5861 | if (hwaddr_aton(cmd, addr)) |
| 5862 | return -1; |
| 5863 | |
| 5864 | pos = cmd + 17; |
| 5865 | if (*pos != ' ') |
| 5866 | return -1; |
| 5867 | pos++; |
| 5868 | |
| 5869 | persistent_group = os_strstr(pos, " persistent") != NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5870 | pos2 = os_strstr(pos, " persistent="); |
| 5871 | if (pos2) { |
| 5872 | struct wpa_ssid *ssid; |
| 5873 | persistent_id = atoi(pos2 + 12); |
| 5874 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); |
| 5875 | if (ssid == NULL || ssid->disabled != 2 || |
| 5876 | ssid->mode != WPAS_MODE_P2P_GO) { |
| 5877 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 5878 | "SSID id=%d for persistent P2P group (GO)", |
| 5879 | persistent_id); |
| 5880 | return -1; |
| 5881 | } |
| 5882 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5883 | join = os_strstr(pos, " join") != NULL; |
| 5884 | auth = os_strstr(pos, " auth") != NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5885 | automatic = os_strstr(pos, " auto") != NULL; |
| 5886 | pd = os_strstr(pos, " provdisc") != NULL; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5887 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
| 5888 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || |
| 5889 | vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5890 | he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5891 | edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5892 | |
| 5893 | pos2 = os_strstr(pos, " go_intent="); |
| 5894 | if (pos2) { |
| 5895 | pos2 += 11; |
| 5896 | go_intent = atoi(pos2); |
| 5897 | if (go_intent < 0 || go_intent > 15) |
| 5898 | return -1; |
| 5899 | } |
| 5900 | |
| 5901 | pos2 = os_strstr(pos, " freq="); |
| 5902 | if (pos2) { |
| 5903 | pos2 += 6; |
| 5904 | freq = atoi(pos2); |
| 5905 | if (freq <= 0) |
| 5906 | return -1; |
| 5907 | } |
| 5908 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5909 | pos2 = os_strstr(pos, " freq2="); |
| 5910 | if (pos2) |
| 5911 | freq2 = atoi(pos2 + 7); |
| 5912 | |
| 5913 | pos2 = os_strstr(pos, " max_oper_chwidth="); |
| 5914 | if (pos2) |
| 5915 | chwidth = atoi(pos2 + 18); |
| 5916 | |
| 5917 | max_oper_chwidth = parse_freq(chwidth, freq2); |
| 5918 | if (max_oper_chwidth < 0) |
| 5919 | return -1; |
| 5920 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5921 | pos2 = os_strstr(pos, " ssid="); |
| 5922 | if (pos2) { |
| 5923 | char *end; |
| 5924 | |
| 5925 | pos2 += 6; |
| 5926 | end = os_strchr(pos2, ' '); |
| 5927 | if (!end) |
| 5928 | group_ssid_len = os_strlen(pos2) / 2; |
| 5929 | else |
| 5930 | group_ssid_len = (end - pos2) / 2; |
| 5931 | if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN || |
| 5932 | hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0) |
| 5933 | return -1; |
| 5934 | group_ssid = _group_ssid; |
| 5935 | } |
| 5936 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5937 | if (os_strncmp(pos, "pin", 3) == 0) { |
| 5938 | /* Request random PIN (to be displayed) and enable the PIN */ |
| 5939 | wps_method = WPS_PIN_DISPLAY; |
| 5940 | } else if (os_strncmp(pos, "pbc", 3) == 0) { |
| 5941 | wps_method = WPS_PBC; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5942 | } else if (os_strstr(pos, "p2ps") != NULL) { |
| 5943 | wps_method = WPS_P2PS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5944 | } else { |
| 5945 | pin = pos; |
| 5946 | pos = os_strchr(pin, ' '); |
| 5947 | wps_method = WPS_PIN_KEYPAD; |
| 5948 | if (pos) { |
| 5949 | *pos++ = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5950 | if (os_strncmp(pos, "display", 7) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5951 | wps_method = WPS_PIN_DISPLAY; |
| 5952 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5953 | if (!wps_pin_str_valid(pin)) { |
| 5954 | os_memcpy(buf, "FAIL-INVALID-PIN\n", 17); |
| 5955 | return 17; |
| 5956 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5957 | } |
| 5958 | |
| 5959 | new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5960 | persistent_group, automatic, join, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5961 | auth, go_intent, freq, freq2, persistent_id, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5962 | pd, ht40, vht, max_oper_chwidth, he, edmg, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5963 | group_ssid, group_ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5964 | if (new_pin == -2) { |
| 5965 | os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25); |
| 5966 | return 25; |
| 5967 | } |
| 5968 | if (new_pin == -3) { |
| 5969 | os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25); |
| 5970 | return 25; |
| 5971 | } |
| 5972 | if (new_pin < 0) |
| 5973 | return -1; |
| 5974 | if (wps_method == WPS_PIN_DISPLAY && pin == NULL) { |
| 5975 | ret = os_snprintf(buf, buflen, "%08d", new_pin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5976 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5977 | return -1; |
| 5978 | return ret; |
| 5979 | } |
| 5980 | |
| 5981 | os_memcpy(buf, "OK\n", 3); |
| 5982 | return 3; |
| 5983 | } |
| 5984 | |
| 5985 | |
| 5986 | static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd) |
| 5987 | { |
| 5988 | unsigned int timeout = atoi(cmd); |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 5989 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 5990 | wpa_dbg(wpa_s, MSG_INFO, |
| 5991 | "Reject P2P_LISTEN since interface is disabled"); |
| 5992 | return -1; |
| 5993 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5994 | return wpas_p2p_listen(wpa_s, timeout); |
| 5995 | } |
| 5996 | |
| 5997 | |
| 5998 | static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) |
| 5999 | { |
| 6000 | u8 addr[ETH_ALEN]; |
| 6001 | char *pos; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6002 | enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6003 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6004 | /* <addr> <config method> [join|auto] */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6005 | |
| 6006 | if (hwaddr_aton(cmd, addr)) |
| 6007 | return -1; |
| 6008 | |
| 6009 | pos = cmd + 17; |
| 6010 | if (*pos != ' ') |
| 6011 | return -1; |
| 6012 | pos++; |
| 6013 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6014 | if (os_strstr(pos, " join") != NULL) |
| 6015 | use = WPAS_P2P_PD_FOR_JOIN; |
| 6016 | else if (os_strstr(pos, " auto") != NULL) |
| 6017 | use = WPAS_P2P_PD_AUTO; |
| 6018 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6019 | return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | |
| 6023 | static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf, |
| 6024 | size_t buflen) |
| 6025 | { |
| 6026 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 6027 | |
| 6028 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 6029 | ssid->passphrase == NULL) |
| 6030 | return -1; |
| 6031 | |
| 6032 | os_strlcpy(buf, ssid->passphrase, buflen); |
| 6033 | return os_strlen(buf); |
| 6034 | } |
| 6035 | |
| 6036 | |
| 6037 | static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd, |
| 6038 | char *buf, size_t buflen) |
| 6039 | { |
| 6040 | u64 ref; |
| 6041 | int res; |
| 6042 | u8 dst_buf[ETH_ALEN], *dst; |
| 6043 | struct wpabuf *tlvs; |
| 6044 | char *pos; |
| 6045 | size_t len; |
| 6046 | |
| 6047 | if (hwaddr_aton(cmd, dst_buf)) |
| 6048 | return -1; |
| 6049 | dst = dst_buf; |
| 6050 | if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 && |
| 6051 | dst[3] == 0 && dst[4] == 0 && dst[5] == 0) |
| 6052 | dst = NULL; |
| 6053 | pos = cmd + 17; |
| 6054 | if (*pos != ' ') |
| 6055 | return -1; |
| 6056 | pos++; |
| 6057 | |
| 6058 | if (os_strncmp(pos, "upnp ", 5) == 0) { |
| 6059 | u8 version; |
| 6060 | pos += 5; |
| 6061 | if (hexstr2bin(pos, &version, 1) < 0) |
| 6062 | return -1; |
| 6063 | pos += 2; |
| 6064 | if (*pos != ' ') |
| 6065 | return -1; |
| 6066 | pos++; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6067 | ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6068 | #ifdef CONFIG_WIFI_DISPLAY |
| 6069 | } else if (os_strncmp(pos, "wifi-display ", 13) == 0) { |
| 6070 | ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13); |
| 6071 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6072 | } else if (os_strncmp(pos, "asp ", 4) == 0) { |
| 6073 | char *svc_str; |
| 6074 | char *svc_info = NULL; |
| 6075 | u32 id; |
| 6076 | |
| 6077 | pos += 4; |
| 6078 | if (sscanf(pos, "%x", &id) != 1 || id > 0xff) |
| 6079 | return -1; |
| 6080 | |
| 6081 | pos = os_strchr(pos, ' '); |
| 6082 | if (pos == NULL || pos[1] == '\0' || pos[1] == ' ') |
| 6083 | return -1; |
| 6084 | |
| 6085 | svc_str = pos + 1; |
| 6086 | |
| 6087 | pos = os_strchr(svc_str, ' '); |
| 6088 | |
| 6089 | if (pos) |
| 6090 | *pos++ = '\0'; |
| 6091 | |
| 6092 | /* All remaining data is the svc_info string */ |
| 6093 | if (pos && pos[0] && pos[0] != ' ') { |
| 6094 | len = os_strlen(pos); |
| 6095 | |
| 6096 | /* Unescape in place */ |
| 6097 | len = utf8_unescape(pos, len, pos, len); |
| 6098 | if (len > 0xff) |
| 6099 | return -1; |
| 6100 | |
| 6101 | svc_info = pos; |
| 6102 | } |
| 6103 | |
| 6104 | ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id, |
| 6105 | svc_str, svc_info); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6106 | } else { |
| 6107 | len = os_strlen(pos); |
| 6108 | if (len & 1) |
| 6109 | return -1; |
| 6110 | len /= 2; |
| 6111 | tlvs = wpabuf_alloc(len); |
| 6112 | if (tlvs == NULL) |
| 6113 | return -1; |
| 6114 | if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) { |
| 6115 | wpabuf_free(tlvs); |
| 6116 | return -1; |
| 6117 | } |
| 6118 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6119 | ref = wpas_p2p_sd_request(wpa_s, dst, tlvs); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6120 | wpabuf_free(tlvs); |
| 6121 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6122 | if (ref == 0) |
| 6123 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6124 | res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6125 | if (os_snprintf_error(buflen, res)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6126 | return -1; |
| 6127 | return res; |
| 6128 | } |
| 6129 | |
| 6130 | |
| 6131 | static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s, |
| 6132 | char *cmd) |
| 6133 | { |
| 6134 | long long unsigned val; |
| 6135 | u64 req; |
| 6136 | if (sscanf(cmd, "%llx", &val) != 1) |
| 6137 | return -1; |
| 6138 | req = val; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6139 | return wpas_p2p_sd_cancel_request(wpa_s, req); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6140 | } |
| 6141 | |
| 6142 | |
| 6143 | static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd) |
| 6144 | { |
| 6145 | int freq; |
| 6146 | u8 dst[ETH_ALEN]; |
| 6147 | u8 dialog_token; |
| 6148 | struct wpabuf *resp_tlvs; |
| 6149 | char *pos, *pos2; |
| 6150 | size_t len; |
| 6151 | |
| 6152 | pos = os_strchr(cmd, ' '); |
| 6153 | if (pos == NULL) |
| 6154 | return -1; |
| 6155 | *pos++ = '\0'; |
| 6156 | freq = atoi(cmd); |
| 6157 | if (freq == 0) |
| 6158 | return -1; |
| 6159 | |
| 6160 | if (hwaddr_aton(pos, dst)) |
| 6161 | return -1; |
| 6162 | pos += 17; |
| 6163 | if (*pos != ' ') |
| 6164 | return -1; |
| 6165 | pos++; |
| 6166 | |
| 6167 | pos2 = os_strchr(pos, ' '); |
| 6168 | if (pos2 == NULL) |
| 6169 | return -1; |
| 6170 | *pos2++ = '\0'; |
| 6171 | dialog_token = atoi(pos); |
| 6172 | |
| 6173 | len = os_strlen(pos2); |
| 6174 | if (len & 1) |
| 6175 | return -1; |
| 6176 | len /= 2; |
| 6177 | resp_tlvs = wpabuf_alloc(len); |
| 6178 | if (resp_tlvs == NULL) |
| 6179 | return -1; |
| 6180 | if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) { |
| 6181 | wpabuf_free(resp_tlvs); |
| 6182 | return -1; |
| 6183 | } |
| 6184 | |
| 6185 | wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs); |
| 6186 | wpabuf_free(resp_tlvs); |
| 6187 | return 0; |
| 6188 | } |
| 6189 | |
| 6190 | |
| 6191 | static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s, |
| 6192 | char *cmd) |
| 6193 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6194 | if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1")) |
| 6195 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6196 | wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd); |
| 6197 | return 0; |
| 6198 | } |
| 6199 | |
| 6200 | |
| 6201 | static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s, |
| 6202 | char *cmd) |
| 6203 | { |
| 6204 | char *pos; |
| 6205 | size_t len; |
| 6206 | struct wpabuf *query, *resp; |
| 6207 | |
| 6208 | pos = os_strchr(cmd, ' '); |
| 6209 | if (pos == NULL) |
| 6210 | return -1; |
| 6211 | *pos++ = '\0'; |
| 6212 | |
| 6213 | len = os_strlen(cmd); |
| 6214 | if (len & 1) |
| 6215 | return -1; |
| 6216 | len /= 2; |
| 6217 | query = wpabuf_alloc(len); |
| 6218 | if (query == NULL) |
| 6219 | return -1; |
| 6220 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { |
| 6221 | wpabuf_free(query); |
| 6222 | return -1; |
| 6223 | } |
| 6224 | |
| 6225 | len = os_strlen(pos); |
| 6226 | if (len & 1) { |
| 6227 | wpabuf_free(query); |
| 6228 | return -1; |
| 6229 | } |
| 6230 | len /= 2; |
| 6231 | resp = wpabuf_alloc(len); |
| 6232 | if (resp == NULL) { |
| 6233 | wpabuf_free(query); |
| 6234 | return -1; |
| 6235 | } |
| 6236 | if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) { |
| 6237 | wpabuf_free(query); |
| 6238 | wpabuf_free(resp); |
| 6239 | return -1; |
| 6240 | } |
| 6241 | |
| 6242 | if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) { |
| 6243 | wpabuf_free(query); |
| 6244 | wpabuf_free(resp); |
| 6245 | return -1; |
| 6246 | } |
| 6247 | return 0; |
| 6248 | } |
| 6249 | |
| 6250 | |
| 6251 | static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd) |
| 6252 | { |
| 6253 | char *pos; |
| 6254 | u8 version; |
| 6255 | |
| 6256 | pos = os_strchr(cmd, ' '); |
| 6257 | if (pos == NULL) |
| 6258 | return -1; |
| 6259 | *pos++ = '\0'; |
| 6260 | |
| 6261 | if (hexstr2bin(cmd, &version, 1) < 0) |
| 6262 | return -1; |
| 6263 | |
| 6264 | return wpas_p2p_service_add_upnp(wpa_s, version, pos); |
| 6265 | } |
| 6266 | |
| 6267 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6268 | static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s, |
| 6269 | u8 replace, char *cmd) |
| 6270 | { |
| 6271 | char *pos; |
| 6272 | char *adv_str; |
| 6273 | u32 auto_accept, adv_id, svc_state, config_methods; |
| 6274 | char *svc_info = NULL; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6275 | char *cpt_prio_str; |
| 6276 | u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1]; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6277 | |
| 6278 | pos = os_strchr(cmd, ' '); |
| 6279 | if (pos == NULL) |
| 6280 | return -1; |
| 6281 | *pos++ = '\0'; |
| 6282 | |
| 6283 | /* Auto-Accept value is mandatory, and must be one of the |
| 6284 | * single values (0, 1, 2, 4) */ |
| 6285 | auto_accept = atoi(cmd); |
| 6286 | switch (auto_accept) { |
| 6287 | case P2PS_SETUP_NONE: /* No auto-accept */ |
| 6288 | case P2PS_SETUP_NEW: |
| 6289 | case P2PS_SETUP_CLIENT: |
| 6290 | case P2PS_SETUP_GROUP_OWNER: |
| 6291 | break; |
| 6292 | default: |
| 6293 | return -1; |
| 6294 | } |
| 6295 | |
| 6296 | /* Advertisement ID is mandatory */ |
| 6297 | cmd = pos; |
| 6298 | pos = os_strchr(cmd, ' '); |
| 6299 | if (pos == NULL) |
| 6300 | return -1; |
| 6301 | *pos++ = '\0'; |
| 6302 | |
| 6303 | /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */ |
| 6304 | if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0) |
| 6305 | return -1; |
| 6306 | |
| 6307 | /* Only allow replacements if exist, and adds if not */ |
| 6308 | if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) { |
| 6309 | if (!replace) |
| 6310 | return -1; |
| 6311 | } else { |
| 6312 | if (replace) |
| 6313 | return -1; |
| 6314 | } |
| 6315 | |
| 6316 | /* svc_state between 0 - 0xff is mandatory */ |
| 6317 | if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff) |
| 6318 | return -1; |
| 6319 | |
| 6320 | pos = os_strchr(pos, ' '); |
| 6321 | if (pos == NULL) |
| 6322 | return -1; |
| 6323 | |
| 6324 | /* config_methods is mandatory */ |
| 6325 | pos++; |
| 6326 | if (sscanf(pos, "%x", &config_methods) != 1) |
| 6327 | return -1; |
| 6328 | |
| 6329 | if (!(config_methods & |
| 6330 | (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS))) |
| 6331 | return -1; |
| 6332 | |
| 6333 | pos = os_strchr(pos, ' '); |
| 6334 | if (pos == NULL) |
| 6335 | return -1; |
| 6336 | |
| 6337 | pos++; |
| 6338 | adv_str = pos; |
| 6339 | |
| 6340 | /* Advertisement string is mandatory */ |
| 6341 | if (!pos[0] || pos[0] == ' ') |
| 6342 | return -1; |
| 6343 | |
| 6344 | /* Terminate svc string */ |
| 6345 | pos = os_strchr(pos, ' '); |
| 6346 | if (pos != NULL) |
| 6347 | *pos++ = '\0'; |
| 6348 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6349 | cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL; |
| 6350 | if (cpt_prio_str) { |
| 6351 | pos = os_strchr(pos, ' '); |
| 6352 | if (pos != NULL) |
| 6353 | *pos++ = '\0'; |
| 6354 | |
| 6355 | if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio)) |
| 6356 | return -1; |
| 6357 | } else { |
| 6358 | cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; |
| 6359 | cpt_prio[1] = 0; |
| 6360 | } |
| 6361 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6362 | /* Service and Response Information are optional */ |
| 6363 | if (pos && pos[0]) { |
| 6364 | size_t len; |
| 6365 | |
| 6366 | /* Note the bare ' included, which cannot exist legally |
| 6367 | * in unescaped string. */ |
| 6368 | svc_info = os_strstr(pos, "svc_info='"); |
| 6369 | |
| 6370 | if (svc_info) { |
| 6371 | svc_info += 9; |
| 6372 | len = os_strlen(svc_info); |
| 6373 | utf8_unescape(svc_info, len, svc_info, len); |
| 6374 | } |
| 6375 | } |
| 6376 | |
| 6377 | return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str, |
| 6378 | (u8) svc_state, (u16) config_methods, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6379 | svc_info, cpt_prio); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6380 | } |
| 6381 | |
| 6382 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6383 | static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd) |
| 6384 | { |
| 6385 | char *pos; |
| 6386 | |
| 6387 | pos = os_strchr(cmd, ' '); |
| 6388 | if (pos == NULL) |
| 6389 | return -1; |
| 6390 | *pos++ = '\0'; |
| 6391 | |
| 6392 | if (os_strcmp(cmd, "bonjour") == 0) |
| 6393 | return p2p_ctrl_service_add_bonjour(wpa_s, pos); |
| 6394 | if (os_strcmp(cmd, "upnp") == 0) |
| 6395 | return p2p_ctrl_service_add_upnp(wpa_s, pos); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6396 | if (os_strcmp(cmd, "asp") == 0) |
| 6397 | return p2p_ctrl_service_add_asp(wpa_s, 0, pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6398 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
| 6399 | return -1; |
| 6400 | } |
| 6401 | |
| 6402 | |
| 6403 | static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s, |
| 6404 | char *cmd) |
| 6405 | { |
| 6406 | size_t len; |
| 6407 | struct wpabuf *query; |
| 6408 | int ret; |
| 6409 | |
| 6410 | len = os_strlen(cmd); |
| 6411 | if (len & 1) |
| 6412 | return -1; |
| 6413 | len /= 2; |
| 6414 | query = wpabuf_alloc(len); |
| 6415 | if (query == NULL) |
| 6416 | return -1; |
| 6417 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { |
| 6418 | wpabuf_free(query); |
| 6419 | return -1; |
| 6420 | } |
| 6421 | |
| 6422 | ret = wpas_p2p_service_del_bonjour(wpa_s, query); |
| 6423 | wpabuf_free(query); |
| 6424 | return ret; |
| 6425 | } |
| 6426 | |
| 6427 | |
| 6428 | static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd) |
| 6429 | { |
| 6430 | char *pos; |
| 6431 | u8 version; |
| 6432 | |
| 6433 | pos = os_strchr(cmd, ' '); |
| 6434 | if (pos == NULL) |
| 6435 | return -1; |
| 6436 | *pos++ = '\0'; |
| 6437 | |
| 6438 | if (hexstr2bin(cmd, &version, 1) < 0) |
| 6439 | return -1; |
| 6440 | |
| 6441 | return wpas_p2p_service_del_upnp(wpa_s, version, pos); |
| 6442 | } |
| 6443 | |
| 6444 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6445 | static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd) |
| 6446 | { |
| 6447 | u32 adv_id; |
| 6448 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 6449 | if (os_strcmp(cmd, "all") == 0) { |
| 6450 | wpas_p2p_service_flush_asp(wpa_s); |
| 6451 | return 0; |
| 6452 | } |
| 6453 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6454 | if (sscanf(cmd, "%x", &adv_id) != 1) |
| 6455 | return -1; |
| 6456 | |
| 6457 | return wpas_p2p_service_del_asp(wpa_s, adv_id); |
| 6458 | } |
| 6459 | |
| 6460 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6461 | static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd) |
| 6462 | { |
| 6463 | char *pos; |
| 6464 | |
| 6465 | pos = os_strchr(cmd, ' '); |
| 6466 | if (pos == NULL) |
| 6467 | return -1; |
| 6468 | *pos++ = '\0'; |
| 6469 | |
| 6470 | if (os_strcmp(cmd, "bonjour") == 0) |
| 6471 | return p2p_ctrl_service_del_bonjour(wpa_s, pos); |
| 6472 | if (os_strcmp(cmd, "upnp") == 0) |
| 6473 | return p2p_ctrl_service_del_upnp(wpa_s, pos); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6474 | if (os_strcmp(cmd, "asp") == 0) |
| 6475 | return p2p_ctrl_service_del_asp(wpa_s, pos); |
| 6476 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
| 6477 | return -1; |
| 6478 | } |
| 6479 | |
| 6480 | |
| 6481 | static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd) |
| 6482 | { |
| 6483 | char *pos; |
| 6484 | |
| 6485 | pos = os_strchr(cmd, ' '); |
| 6486 | if (pos == NULL) |
| 6487 | return -1; |
| 6488 | *pos++ = '\0'; |
| 6489 | |
| 6490 | if (os_strcmp(cmd, "asp") == 0) |
| 6491 | return p2p_ctrl_service_add_asp(wpa_s, 1, pos); |
| 6492 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6493 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
| 6494 | return -1; |
| 6495 | } |
| 6496 | |
| 6497 | |
| 6498 | static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd) |
| 6499 | { |
| 6500 | u8 addr[ETH_ALEN]; |
| 6501 | |
| 6502 | /* <addr> */ |
| 6503 | |
| 6504 | if (hwaddr_aton(cmd, addr)) |
| 6505 | return -1; |
| 6506 | |
| 6507 | return wpas_p2p_reject(wpa_s, addr); |
| 6508 | } |
| 6509 | |
| 6510 | |
| 6511 | static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd) |
| 6512 | { |
| 6513 | char *pos; |
| 6514 | int id; |
| 6515 | struct wpa_ssid *ssid; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6516 | u8 *_peer = NULL, peer[ETH_ALEN]; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6517 | int freq = 0, pref_freq = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6518 | int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6519 | int edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6520 | |
| 6521 | id = atoi(cmd); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6522 | pos = os_strstr(cmd, " peer="); |
| 6523 | if (pos) { |
| 6524 | pos += 6; |
| 6525 | if (hwaddr_aton(pos, peer)) |
| 6526 | return -1; |
| 6527 | _peer = peer; |
| 6528 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6529 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 6530 | if (ssid == NULL || ssid->disabled != 2) { |
| 6531 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 6532 | "for persistent P2P group", |
| 6533 | id); |
| 6534 | return -1; |
| 6535 | } |
| 6536 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 6537 | pos = os_strstr(cmd, " freq="); |
| 6538 | if (pos) { |
| 6539 | pos += 6; |
| 6540 | freq = atoi(pos); |
| 6541 | if (freq <= 0) |
| 6542 | return -1; |
| 6543 | } |
| 6544 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6545 | pos = os_strstr(cmd, " pref="); |
| 6546 | if (pos) { |
| 6547 | pos += 6; |
| 6548 | pref_freq = atoi(pos); |
| 6549 | if (pref_freq <= 0) |
| 6550 | return -1; |
| 6551 | } |
| 6552 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6553 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
| 6554 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || |
| 6555 | vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6556 | he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6557 | edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg; |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 6558 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6559 | pos = os_strstr(cmd, "freq2="); |
| 6560 | if (pos) |
| 6561 | freq2 = atoi(pos + 6); |
| 6562 | |
| 6563 | pos = os_strstr(cmd, " max_oper_chwidth="); |
| 6564 | if (pos) |
| 6565 | chwidth = atoi(pos + 18); |
| 6566 | |
| 6567 | max_oper_chwidth = parse_freq(chwidth, freq2); |
| 6568 | if (max_oper_chwidth < 0) |
| 6569 | return -1; |
| 6570 | |
| 6571 | return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6572 | max_oper_chwidth, pref_freq, he, edmg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6573 | } |
| 6574 | |
| 6575 | |
| 6576 | static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd) |
| 6577 | { |
| 6578 | char *pos; |
| 6579 | u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL; |
| 6580 | |
| 6581 | pos = os_strstr(cmd, " peer="); |
| 6582 | if (!pos) |
| 6583 | return -1; |
| 6584 | |
| 6585 | *pos = '\0'; |
| 6586 | pos += 6; |
| 6587 | if (hwaddr_aton(pos, peer)) { |
| 6588 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos); |
| 6589 | return -1; |
| 6590 | } |
| 6591 | |
| 6592 | pos = os_strstr(pos, " go_dev_addr="); |
| 6593 | if (pos) { |
| 6594 | pos += 13; |
| 6595 | if (hwaddr_aton(pos, go_dev_addr)) { |
| 6596 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", |
| 6597 | pos); |
| 6598 | return -1; |
| 6599 | } |
| 6600 | go_dev = go_dev_addr; |
| 6601 | } |
| 6602 | |
| 6603 | return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev); |
| 6604 | } |
| 6605 | |
| 6606 | |
| 6607 | static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd) |
| 6608 | { |
| 6609 | if (os_strncmp(cmd, "persistent=", 11) == 0) |
| 6610 | return p2p_ctrl_invite_persistent(wpa_s, cmd + 11); |
| 6611 | if (os_strncmp(cmd, "group=", 6) == 0) |
| 6612 | return p2p_ctrl_invite_group(wpa_s, cmd + 6); |
| 6613 | |
| 6614 | return -1; |
| 6615 | } |
| 6616 | |
| 6617 | |
| 6618 | static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6619 | int id, int freq, int vht_center_freq2, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6620 | int ht40, int vht, int vht_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6621 | int he, int edmg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6622 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6623 | struct wpa_ssid *ssid; |
| 6624 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6625 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 6626 | if (ssid == NULL || ssid->disabled != 2) { |
| 6627 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 6628 | "for persistent P2P group", |
| 6629 | id); |
| 6630 | return -1; |
| 6631 | } |
| 6632 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6633 | return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, |
| 6634 | vht_center_freq2, 0, ht40, vht, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6635 | vht_chwidth, he, edmg, |
| 6636 | NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6637 | } |
| 6638 | |
| 6639 | |
| 6640 | static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) |
| 6641 | { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6642 | int freq = 0, persistent = 0, group_id = -1; |
| 6643 | int vht = wpa_s->conf->p2p_go_vht; |
| 6644 | int ht40 = wpa_s->conf->p2p_go_ht40 || vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6645 | int he = wpa_s->conf->p2p_go_he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6646 | int edmg = wpa_s->conf->p2p_go_edmg; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6647 | int max_oper_chwidth, chwidth = 0, freq2 = 0; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6648 | char *token, *context = NULL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6649 | #ifdef CONFIG_ACS |
| 6650 | int acs = 0; |
| 6651 | #endif /* CONFIG_ACS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6652 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6653 | while ((token = str_token(cmd, " ", &context))) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6654 | if (sscanf(token, "freq2=%d", &freq2) == 1 || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6655 | sscanf(token, "persistent=%d", &group_id) == 1 || |
| 6656 | sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6657 | continue; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6658 | #ifdef CONFIG_ACS |
| 6659 | } else if (os_strcmp(token, "freq=acs") == 0) { |
| 6660 | acs = 1; |
| 6661 | #endif /* CONFIG_ACS */ |
| 6662 | } else if (sscanf(token, "freq=%d", &freq) == 1) { |
| 6663 | continue; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6664 | } else if (os_strcmp(token, "ht40") == 0) { |
| 6665 | ht40 = 1; |
| 6666 | } else if (os_strcmp(token, "vht") == 0) { |
| 6667 | vht = 1; |
| 6668 | ht40 = 1; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6669 | } else if (os_strcmp(token, "he") == 0) { |
| 6670 | he = 1; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6671 | } else if (os_strcmp(token, "edmg") == 0) { |
| 6672 | edmg = 1; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6673 | } else if (os_strcmp(token, "persistent") == 0) { |
| 6674 | persistent = 1; |
| 6675 | } else { |
| 6676 | wpa_printf(MSG_DEBUG, |
| 6677 | "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'", |
| 6678 | token); |
| 6679 | return -1; |
| 6680 | } |
| 6681 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6682 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6683 | #ifdef CONFIG_ACS |
| 6684 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) && |
| 6685 | (acs || freq == 2 || freq == 5)) { |
| 6686 | if (freq == 2 && wpa_s->best_24_freq <= 0) { |
| 6687 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G; |
| 6688 | wpa_s->p2p_go_do_acs = 1; |
| 6689 | freq = 0; |
| 6690 | } else if (freq == 5 && wpa_s->best_5_freq <= 0) { |
| 6691 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A; |
| 6692 | wpa_s->p2p_go_do_acs = 1; |
| 6693 | freq = 0; |
| 6694 | } else { |
| 6695 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY; |
| 6696 | wpa_s->p2p_go_do_acs = 1; |
| 6697 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6698 | } else { |
| 6699 | wpa_s->p2p_go_do_acs = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6700 | } |
| 6701 | #endif /* CONFIG_ACS */ |
| 6702 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6703 | max_oper_chwidth = parse_freq(chwidth, freq2); |
| 6704 | if (max_oper_chwidth < 0) |
| 6705 | return -1; |
| 6706 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6707 | if (group_id >= 0) |
| 6708 | return p2p_ctrl_group_add_persistent(wpa_s, group_id, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6709 | freq, freq2, ht40, vht, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6710 | max_oper_chwidth, he, |
| 6711 | edmg); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6712 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6713 | return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6714 | max_oper_chwidth, he, edmg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6715 | } |
| 6716 | |
| 6717 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6718 | static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd, |
| 6719 | char *buf, size_t buflen) |
| 6720 | { |
| 6721 | u8 dev_addr[ETH_ALEN]; |
| 6722 | struct wpa_ssid *ssid; |
| 6723 | int res; |
| 6724 | const u8 *iaddr; |
| 6725 | |
| 6726 | ssid = wpa_s->current_ssid; |
| 6727 | if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO || |
| 6728 | hwaddr_aton(cmd, dev_addr)) |
| 6729 | return -1; |
| 6730 | |
| 6731 | iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr); |
| 6732 | if (!iaddr) |
| 6733 | return -1; |
| 6734 | res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr)); |
| 6735 | if (os_snprintf_error(buflen, res)) |
| 6736 | return -1; |
| 6737 | return res; |
| 6738 | } |
| 6739 | |
| 6740 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 6741 | static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global, |
| 6742 | const u8 *p2p_dev_addr) |
| 6743 | { |
| 6744 | struct wpa_supplicant *wpa_s; |
| 6745 | |
| 6746 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 6747 | if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr)) |
| 6748 | return 1; |
| 6749 | } |
| 6750 | |
| 6751 | return 0; |
| 6752 | } |
| 6753 | |
| 6754 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6755 | static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd, |
| 6756 | char *buf, size_t buflen) |
| 6757 | { |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 6758 | u8 addr[ETH_ALEN], *addr_ptr, group_capab; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6759 | int next, res; |
| 6760 | const struct p2p_peer_info *info; |
| 6761 | char *pos, *end; |
| 6762 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
| 6763 | struct wpa_ssid *ssid; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6764 | size_t i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6765 | |
| 6766 | if (!wpa_s->global->p2p) |
| 6767 | return -1; |
| 6768 | |
| 6769 | if (os_strcmp(cmd, "FIRST") == 0) { |
| 6770 | addr_ptr = NULL; |
| 6771 | next = 0; |
| 6772 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { |
| 6773 | if (hwaddr_aton(cmd + 5, addr) < 0) |
| 6774 | return -1; |
| 6775 | addr_ptr = addr; |
| 6776 | next = 1; |
| 6777 | } else { |
| 6778 | if (hwaddr_aton(cmd, addr) < 0) |
| 6779 | return -1; |
| 6780 | addr_ptr = addr; |
| 6781 | next = 0; |
| 6782 | } |
| 6783 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6784 | info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next); |
| 6785 | if (info == NULL) |
| 6786 | return -1; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 6787 | group_capab = info->group_capab; |
| 6788 | |
| 6789 | if (group_capab && |
| 6790 | !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) { |
| 6791 | wpa_printf(MSG_DEBUG, |
| 6792 | "P2P: Could not find any BSS with p2p_dev_addr " |
| 6793 | MACSTR ", hence override group_capab from 0x%x to 0", |
| 6794 | MAC2STR(info->p2p_device_addr), group_capab); |
| 6795 | group_capab = 0; |
| 6796 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6797 | |
| 6798 | pos = buf; |
| 6799 | end = buf + buflen; |
| 6800 | |
| 6801 | res = os_snprintf(pos, end - pos, MACSTR "\n" |
| 6802 | "pri_dev_type=%s\n" |
| 6803 | "device_name=%s\n" |
| 6804 | "manufacturer=%s\n" |
| 6805 | "model_name=%s\n" |
| 6806 | "model_number=%s\n" |
| 6807 | "serial_number=%s\n" |
| 6808 | "config_methods=0x%x\n" |
| 6809 | "dev_capab=0x%x\n" |
| 6810 | "group_capab=0x%x\n" |
| 6811 | "level=%d\n", |
| 6812 | MAC2STR(info->p2p_device_addr), |
| 6813 | wps_dev_type_bin2str(info->pri_dev_type, |
| 6814 | devtype, sizeof(devtype)), |
| 6815 | info->device_name, |
| 6816 | info->manufacturer, |
| 6817 | info->model_name, |
| 6818 | info->model_number, |
| 6819 | info->serial_number, |
| 6820 | info->config_methods, |
| 6821 | info->dev_capab, |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 6822 | group_capab, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6823 | info->level); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6824 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6825 | return pos - buf; |
| 6826 | pos += res; |
| 6827 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6828 | for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++) |
| 6829 | { |
| 6830 | const u8 *t; |
| 6831 | t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN]; |
| 6832 | res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n", |
| 6833 | wps_dev_type_bin2str(t, devtype, |
| 6834 | sizeof(devtype))); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6835 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6836 | return pos - buf; |
| 6837 | pos += res; |
| 6838 | } |
| 6839 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6840 | ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6841 | if (ssid) { |
| 6842 | res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6843 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6844 | return pos - buf; |
| 6845 | pos += res; |
| 6846 | } |
| 6847 | |
| 6848 | res = p2p_get_peer_info_txt(info, pos, end - pos); |
| 6849 | if (res < 0) |
| 6850 | return pos - buf; |
| 6851 | pos += res; |
| 6852 | |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 6853 | if (info->vendor_elems) { |
| 6854 | res = os_snprintf(pos, end - pos, "vendor_elems="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6855 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 6856 | return pos - buf; |
| 6857 | pos += res; |
| 6858 | |
| 6859 | pos += wpa_snprintf_hex(pos, end - pos, |
| 6860 | wpabuf_head(info->vendor_elems), |
| 6861 | wpabuf_len(info->vendor_elems)); |
| 6862 | |
| 6863 | res = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6864 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 6865 | return pos - buf; |
| 6866 | pos += res; |
| 6867 | } |
| 6868 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6869 | return pos - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6870 | } |
| 6871 | |
| 6872 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6873 | static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s, |
| 6874 | const char *param) |
| 6875 | { |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 6876 | unsigned int i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6877 | |
| 6878 | if (wpa_s->global->p2p == NULL) |
| 6879 | return -1; |
| 6880 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 6881 | if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0) |
| 6882 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6883 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 6884 | for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) { |
| 6885 | struct wpa_freq_range *freq; |
| 6886 | freq = &wpa_s->global->p2p_disallow_freq.range[i]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6887 | wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u", |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 6888 | freq->min, freq->max); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6889 | } |
| 6890 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6891 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6892 | return 0; |
| 6893 | } |
| 6894 | |
| 6895 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6896 | static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) |
| 6897 | { |
| 6898 | char *param; |
| 6899 | |
| 6900 | if (wpa_s->global->p2p == NULL) |
| 6901 | return -1; |
| 6902 | |
| 6903 | param = os_strchr(cmd, ' '); |
| 6904 | if (param == NULL) |
| 6905 | return -1; |
| 6906 | *param++ = '\0'; |
| 6907 | |
| 6908 | if (os_strcmp(cmd, "discoverability") == 0) { |
| 6909 | p2p_set_client_discoverability(wpa_s->global->p2p, |
| 6910 | atoi(param)); |
| 6911 | return 0; |
| 6912 | } |
| 6913 | |
| 6914 | if (os_strcmp(cmd, "managed") == 0) { |
| 6915 | p2p_set_managed_oper(wpa_s->global->p2p, atoi(param)); |
| 6916 | return 0; |
| 6917 | } |
| 6918 | |
| 6919 | if (os_strcmp(cmd, "listen_channel") == 0) { |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6920 | char *pos; |
| 6921 | u8 channel, op_class; |
| 6922 | |
| 6923 | channel = atoi(param); |
| 6924 | pos = os_strchr(param, ' '); |
| 6925 | op_class = pos ? atoi(pos) : 81; |
| 6926 | |
| 6927 | return p2p_set_listen_channel(wpa_s->global->p2p, op_class, |
| 6928 | channel, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6929 | } |
| 6930 | |
| 6931 | if (os_strcmp(cmd, "ssid_postfix") == 0) { |
| 6932 | return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param, |
| 6933 | os_strlen(param)); |
| 6934 | } |
| 6935 | |
| 6936 | if (os_strcmp(cmd, "noa") == 0) { |
| 6937 | char *pos; |
| 6938 | int count, start, duration; |
| 6939 | /* GO NoA parameters: count,start_offset(ms),duration(ms) */ |
| 6940 | count = atoi(param); |
| 6941 | pos = os_strchr(param, ','); |
| 6942 | if (pos == NULL) |
| 6943 | return -1; |
| 6944 | pos++; |
| 6945 | start = atoi(pos); |
| 6946 | pos = os_strchr(pos, ','); |
| 6947 | if (pos == NULL) |
| 6948 | return -1; |
| 6949 | pos++; |
| 6950 | duration = atoi(pos); |
| 6951 | if (count < 0 || count > 255 || start < 0 || duration < 0) |
| 6952 | return -1; |
| 6953 | if (count == 0 && duration > 0) |
| 6954 | return -1; |
| 6955 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d " |
| 6956 | "start=%d duration=%d", count, start, duration); |
| 6957 | return wpas_p2p_set_noa(wpa_s, count, start, duration); |
| 6958 | } |
| 6959 | |
| 6960 | if (os_strcmp(cmd, "ps") == 0) |
| 6961 | return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1); |
| 6962 | |
| 6963 | if (os_strcmp(cmd, "oppps") == 0) |
| 6964 | return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1); |
| 6965 | |
| 6966 | if (os_strcmp(cmd, "ctwindow") == 0) |
| 6967 | return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param)); |
| 6968 | |
| 6969 | if (os_strcmp(cmd, "disabled") == 0) { |
| 6970 | wpa_s->global->p2p_disabled = atoi(param); |
| 6971 | wpa_printf(MSG_DEBUG, "P2P functionality %s", |
| 6972 | wpa_s->global->p2p_disabled ? |
| 6973 | "disabled" : "enabled"); |
| 6974 | if (wpa_s->global->p2p_disabled) { |
| 6975 | wpas_p2p_stop_find(wpa_s); |
| 6976 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
| 6977 | p2p_flush(wpa_s->global->p2p); |
| 6978 | } |
| 6979 | return 0; |
| 6980 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6981 | |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 6982 | if (os_strcmp(cmd, "conc_pref") == 0) { |
| 6983 | if (os_strcmp(param, "sta") == 0) |
| 6984 | wpa_s->global->conc_pref = WPA_CONC_PREF_STA; |
| 6985 | else if (os_strcmp(param, "p2p") == 0) |
| 6986 | wpa_s->global->conc_pref = WPA_CONC_PREF_P2P; |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 6987 | else { |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 6988 | wpa_printf(MSG_INFO, "Invalid conc_pref value"); |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 6989 | return -1; |
| 6990 | } |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 6991 | wpa_printf(MSG_DEBUG, "Single channel concurrency preference: " |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6992 | "%s", param); |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 6993 | return 0; |
| 6994 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6995 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6996 | if (os_strcmp(cmd, "force_long_sd") == 0) { |
| 6997 | wpa_s->force_long_sd = atoi(param); |
| 6998 | return 0; |
| 6999 | } |
| 7000 | |
| 7001 | if (os_strcmp(cmd, "peer_filter") == 0) { |
| 7002 | u8 addr[ETH_ALEN]; |
| 7003 | if (hwaddr_aton(param, addr)) |
| 7004 | return -1; |
| 7005 | p2p_set_peer_filter(wpa_s->global->p2p, addr); |
| 7006 | return 0; |
| 7007 | } |
| 7008 | |
| 7009 | if (os_strcmp(cmd, "cross_connect") == 0) |
| 7010 | return wpas_p2p_set_cross_connect(wpa_s, atoi(param)); |
| 7011 | |
| 7012 | if (os_strcmp(cmd, "go_apsd") == 0) { |
| 7013 | if (os_strcmp(param, "disable") == 0) |
| 7014 | wpa_s->set_ap_uapsd = 0; |
| 7015 | else { |
| 7016 | wpa_s->set_ap_uapsd = 1; |
| 7017 | wpa_s->ap_uapsd = atoi(param); |
| 7018 | } |
| 7019 | return 0; |
| 7020 | } |
| 7021 | |
| 7022 | if (os_strcmp(cmd, "client_apsd") == 0) { |
| 7023 | if (os_strcmp(param, "disable") == 0) |
| 7024 | wpa_s->set_sta_uapsd = 0; |
| 7025 | else { |
| 7026 | int be, bk, vi, vo; |
| 7027 | char *pos; |
| 7028 | /* format: BE,BK,VI,VO;max SP Length */ |
| 7029 | be = atoi(param); |
| 7030 | pos = os_strchr(param, ','); |
| 7031 | if (pos == NULL) |
| 7032 | return -1; |
| 7033 | pos++; |
| 7034 | bk = atoi(pos); |
| 7035 | pos = os_strchr(pos, ','); |
| 7036 | if (pos == NULL) |
| 7037 | return -1; |
| 7038 | pos++; |
| 7039 | vi = atoi(pos); |
| 7040 | pos = os_strchr(pos, ','); |
| 7041 | if (pos == NULL) |
| 7042 | return -1; |
| 7043 | pos++; |
| 7044 | vo = atoi(pos); |
| 7045 | /* ignore max SP Length for now */ |
| 7046 | |
| 7047 | wpa_s->set_sta_uapsd = 1; |
| 7048 | wpa_s->sta_uapsd = 0; |
| 7049 | if (be) |
| 7050 | wpa_s->sta_uapsd |= BIT(0); |
| 7051 | if (bk) |
| 7052 | wpa_s->sta_uapsd |= BIT(1); |
| 7053 | if (vi) |
| 7054 | wpa_s->sta_uapsd |= BIT(2); |
| 7055 | if (vo) |
| 7056 | wpa_s->sta_uapsd |= BIT(3); |
| 7057 | } |
| 7058 | return 0; |
| 7059 | } |
| 7060 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7061 | if (os_strcmp(cmd, "disallow_freq") == 0) |
| 7062 | return p2p_ctrl_disallow_freq(wpa_s, param); |
| 7063 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7064 | if (os_strcmp(cmd, "disc_int") == 0) { |
| 7065 | int min_disc_int, max_disc_int, max_disc_tu; |
| 7066 | char *pos; |
| 7067 | |
| 7068 | pos = param; |
| 7069 | |
| 7070 | min_disc_int = atoi(pos); |
| 7071 | pos = os_strchr(pos, ' '); |
| 7072 | if (pos == NULL) |
| 7073 | return -1; |
| 7074 | *pos++ = '\0'; |
| 7075 | |
| 7076 | max_disc_int = atoi(pos); |
| 7077 | pos = os_strchr(pos, ' '); |
| 7078 | if (pos == NULL) |
| 7079 | return -1; |
| 7080 | *pos++ = '\0'; |
| 7081 | |
| 7082 | max_disc_tu = atoi(pos); |
| 7083 | |
| 7084 | return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int, |
| 7085 | max_disc_int, max_disc_tu); |
| 7086 | } |
| 7087 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7088 | if (os_strcmp(cmd, "per_sta_psk") == 0) { |
| 7089 | wpa_s->global->p2p_per_sta_psk = !!atoi(param); |
| 7090 | return 0; |
| 7091 | } |
| 7092 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7093 | #ifdef CONFIG_WPS_NFC |
| 7094 | if (os_strcmp(cmd, "nfc_tag") == 0) |
| 7095 | return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param)); |
| 7096 | #endif /* CONFIG_WPS_NFC */ |
| 7097 | |
| 7098 | if (os_strcmp(cmd, "disable_ip_addr_req") == 0) { |
| 7099 | wpa_s->p2p_disable_ip_addr_req = !!atoi(param); |
| 7100 | return 0; |
| 7101 | } |
| 7102 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7103 | if (os_strcmp(cmd, "override_pref_op_chan") == 0) { |
| 7104 | int op_class, chan; |
| 7105 | |
| 7106 | op_class = atoi(param); |
| 7107 | param = os_strchr(param, ':'); |
| 7108 | if (!param) |
| 7109 | return -1; |
| 7110 | param++; |
| 7111 | chan = atoi(param); |
| 7112 | p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class, |
| 7113 | chan); |
| 7114 | return 0; |
| 7115 | } |
| 7116 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7117 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", |
| 7118 | cmd); |
| 7119 | |
| 7120 | return -1; |
| 7121 | } |
| 7122 | |
| 7123 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7124 | static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s) |
| 7125 | { |
| 7126 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
| 7127 | wpa_s->force_long_sd = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7128 | |
| 7129 | #ifdef CONFIG_TESTING_OPTIONS |
| 7130 | os_free(wpa_s->get_pref_freq_list_override); |
| 7131 | wpa_s->get_pref_freq_list_override = NULL; |
| 7132 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7133 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7134 | wpas_p2p_stop_find(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7135 | wpa_s->parent->p2ps_method_config_any = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7136 | if (wpa_s->global->p2p) |
| 7137 | p2p_flush(wpa_s->global->p2p); |
| 7138 | } |
| 7139 | |
| 7140 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7141 | static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd) |
| 7142 | { |
| 7143 | char *pos, *pos2; |
| 7144 | unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0; |
| 7145 | |
| 7146 | if (cmd[0]) { |
| 7147 | pos = os_strchr(cmd, ' '); |
| 7148 | if (pos == NULL) |
| 7149 | return -1; |
| 7150 | *pos++ = '\0'; |
| 7151 | dur1 = atoi(cmd); |
| 7152 | |
| 7153 | pos2 = os_strchr(pos, ' '); |
| 7154 | if (pos2) |
| 7155 | *pos2++ = '\0'; |
| 7156 | int1 = atoi(pos); |
| 7157 | } else |
| 7158 | pos2 = NULL; |
| 7159 | |
| 7160 | if (pos2) { |
| 7161 | pos = os_strchr(pos2, ' '); |
| 7162 | if (pos == NULL) |
| 7163 | return -1; |
| 7164 | *pos++ = '\0'; |
| 7165 | dur2 = atoi(pos2); |
| 7166 | int2 = atoi(pos); |
| 7167 | } |
| 7168 | |
| 7169 | return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2); |
| 7170 | } |
| 7171 | |
| 7172 | |
| 7173 | static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) |
| 7174 | { |
| 7175 | char *pos; |
| 7176 | unsigned int period = 0, interval = 0; |
| 7177 | |
| 7178 | if (cmd[0]) { |
| 7179 | pos = os_strchr(cmd, ' '); |
| 7180 | if (pos == NULL) |
| 7181 | return -1; |
| 7182 | *pos++ = '\0'; |
| 7183 | period = atoi(cmd); |
| 7184 | interval = atoi(pos); |
| 7185 | } |
| 7186 | |
| 7187 | return wpas_p2p_ext_listen(wpa_s, period, interval); |
| 7188 | } |
| 7189 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7190 | |
| 7191 | static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd) |
| 7192 | { |
| 7193 | const char *pos; |
| 7194 | u8 peer[ETH_ALEN]; |
| 7195 | int iface_addr = 0; |
| 7196 | |
| 7197 | pos = cmd; |
| 7198 | if (os_strncmp(pos, "iface=", 6) == 0) { |
| 7199 | iface_addr = 1; |
| 7200 | pos += 6; |
| 7201 | } |
| 7202 | if (hwaddr_aton(pos, peer)) |
| 7203 | return -1; |
| 7204 | |
| 7205 | wpas_p2p_remove_client(wpa_s, peer, iface_addr); |
| 7206 | return 0; |
| 7207 | } |
| 7208 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7209 | |
| 7210 | static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd) |
| 7211 | { |
| 7212 | int freq = 0, period = 0, interval = 0, count = 0; |
| 7213 | |
| 7214 | if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4) |
| 7215 | { |
| 7216 | wpa_printf(MSG_DEBUG, |
| 7217 | "CTRL: Invalid P2P LO Start parameter: '%s'", cmd); |
| 7218 | return -1; |
| 7219 | } |
| 7220 | |
| 7221 | return wpas_p2p_lo_start(wpa_s, freq, period, interval, count); |
| 7222 | } |
| 7223 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7224 | #endif /* CONFIG_P2P */ |
| 7225 | |
| 7226 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7227 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val) |
| 7228 | { |
| 7229 | struct wpa_freq_range_list ranges; |
| 7230 | int *freqs = NULL; |
| 7231 | struct hostapd_hw_modes *mode; |
| 7232 | u16 i; |
| 7233 | |
| 7234 | if (wpa_s->hw.modes == NULL) |
| 7235 | return NULL; |
| 7236 | |
| 7237 | os_memset(&ranges, 0, sizeof(ranges)); |
| 7238 | if (freq_range_list_parse(&ranges, val) < 0) |
| 7239 | return NULL; |
| 7240 | |
| 7241 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 7242 | int j; |
| 7243 | |
| 7244 | mode = &wpa_s->hw.modes[i]; |
| 7245 | for (j = 0; j < mode->num_channels; j++) { |
| 7246 | unsigned int freq; |
| 7247 | |
| 7248 | if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED) |
| 7249 | continue; |
| 7250 | |
| 7251 | freq = mode->channels[j].freq; |
| 7252 | if (!freq_range_list_includes(&ranges, freq)) |
| 7253 | continue; |
| 7254 | |
| 7255 | int_array_add_unique(&freqs, freq); |
| 7256 | } |
| 7257 | } |
| 7258 | |
| 7259 | os_free(ranges.range); |
| 7260 | return freqs; |
| 7261 | } |
| 7262 | |
| 7263 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7264 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7265 | |
| 7266 | static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param) |
| 7267 | { |
| 7268 | int auto_sel = 0; |
| 7269 | int *freqs = NULL; |
| 7270 | |
| 7271 | if (param) { |
| 7272 | char *pos; |
| 7273 | |
| 7274 | auto_sel = os_strstr(param, "auto") != NULL; |
| 7275 | |
| 7276 | pos = os_strstr(param, "freq="); |
| 7277 | if (pos) { |
| 7278 | freqs = freq_range_to_channel_list(wpa_s, pos + 5); |
| 7279 | if (freqs == NULL) |
| 7280 | return -1; |
| 7281 | } |
| 7282 | |
| 7283 | } |
| 7284 | |
| 7285 | return interworking_select(wpa_s, auto_sel, freqs); |
| 7286 | } |
| 7287 | |
| 7288 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7289 | static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst, |
| 7290 | int only_add) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7291 | { |
| 7292 | u8 bssid[ETH_ALEN]; |
| 7293 | struct wpa_bss *bss; |
| 7294 | |
| 7295 | if (hwaddr_aton(dst, bssid)) { |
| 7296 | wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst); |
| 7297 | return -1; |
| 7298 | } |
| 7299 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7300 | bss = wpa_bss_get_bssid_latest(wpa_s, bssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7301 | if (bss == NULL) { |
| 7302 | wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR, |
| 7303 | MAC2STR(bssid)); |
| 7304 | return -1; |
| 7305 | } |
| 7306 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7307 | if (bss->ssid_len == 0) { |
| 7308 | int found = 0; |
| 7309 | |
| 7310 | wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR |
| 7311 | " does not have SSID information", MAC2STR(bssid)); |
| 7312 | |
| 7313 | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, |
| 7314 | list) { |
| 7315 | if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 && |
| 7316 | bss->ssid_len > 0) { |
| 7317 | found = 1; |
| 7318 | break; |
| 7319 | } |
| 7320 | } |
| 7321 | |
| 7322 | if (!found) |
| 7323 | return -1; |
| 7324 | wpa_printf(MSG_DEBUG, |
| 7325 | "Found another matching BSS entry with SSID"); |
| 7326 | } |
| 7327 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7328 | return interworking_connect(wpa_s, bss, only_add); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7329 | } |
| 7330 | |
| 7331 | |
| 7332 | static int get_anqp(struct wpa_supplicant *wpa_s, char *dst) |
| 7333 | { |
| 7334 | u8 dst_addr[ETH_ALEN]; |
| 7335 | int used; |
| 7336 | char *pos; |
| 7337 | #define MAX_ANQP_INFO_ID 100 |
| 7338 | u16 id[MAX_ANQP_INFO_ID]; |
| 7339 | size_t num_id = 0; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7340 | u32 subtypes = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7341 | u32 mbo_subtypes = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7342 | |
| 7343 | used = hwaddr_aton2(dst, dst_addr); |
| 7344 | if (used < 0) |
| 7345 | return -1; |
| 7346 | pos = dst + used; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7347 | if (*pos == ' ') |
| 7348 | pos++; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7349 | while (num_id < MAX_ANQP_INFO_ID) { |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7350 | if (os_strncmp(pos, "hs20:", 5) == 0) { |
| 7351 | #ifdef CONFIG_HS20 |
| 7352 | int num = atoi(pos + 5); |
| 7353 | if (num <= 0 || num > 31) |
| 7354 | return -1; |
| 7355 | subtypes |= BIT(num); |
| 7356 | #else /* CONFIG_HS20 */ |
| 7357 | return -1; |
| 7358 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7359 | } else if (os_strncmp(pos, "mbo:", 4) == 0) { |
| 7360 | #ifdef CONFIG_MBO |
| 7361 | int num = atoi(pos + 4); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7362 | |
| 7363 | if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7364 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7365 | mbo_subtypes |= BIT(num); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7366 | #else /* CONFIG_MBO */ |
| 7367 | return -1; |
| 7368 | #endif /* CONFIG_MBO */ |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7369 | } else { |
| 7370 | id[num_id] = atoi(pos); |
| 7371 | if (id[num_id]) |
| 7372 | num_id++; |
| 7373 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7374 | pos = os_strchr(pos + 1, ','); |
| 7375 | if (pos == NULL) |
| 7376 | break; |
| 7377 | pos++; |
| 7378 | } |
| 7379 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7380 | if (num_id == 0 && !subtypes && !mbo_subtypes) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7381 | return -1; |
| 7382 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7383 | return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7384 | mbo_subtypes); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7385 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7386 | |
| 7387 | |
| 7388 | static int gas_request(struct wpa_supplicant *wpa_s, char *cmd) |
| 7389 | { |
| 7390 | u8 dst_addr[ETH_ALEN]; |
| 7391 | struct wpabuf *advproto, *query = NULL; |
| 7392 | int used, ret = -1; |
| 7393 | char *pos, *end; |
| 7394 | size_t len; |
| 7395 | |
| 7396 | used = hwaddr_aton2(cmd, dst_addr); |
| 7397 | if (used < 0) |
| 7398 | return -1; |
| 7399 | |
| 7400 | pos = cmd + used; |
| 7401 | while (*pos == ' ') |
| 7402 | pos++; |
| 7403 | |
| 7404 | /* Advertisement Protocol ID */ |
| 7405 | end = os_strchr(pos, ' '); |
| 7406 | if (end) |
| 7407 | len = end - pos; |
| 7408 | else |
| 7409 | len = os_strlen(pos); |
| 7410 | if (len & 0x01) |
| 7411 | return -1; |
| 7412 | len /= 2; |
| 7413 | if (len == 0) |
| 7414 | return -1; |
| 7415 | advproto = wpabuf_alloc(len); |
| 7416 | if (advproto == NULL) |
| 7417 | return -1; |
| 7418 | if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0) |
| 7419 | goto fail; |
| 7420 | |
| 7421 | if (end) { |
| 7422 | /* Optional Query Request */ |
| 7423 | pos = end + 1; |
| 7424 | while (*pos == ' ') |
| 7425 | pos++; |
| 7426 | |
| 7427 | len = os_strlen(pos); |
| 7428 | if (len) { |
| 7429 | if (len & 0x01) |
| 7430 | goto fail; |
| 7431 | len /= 2; |
| 7432 | if (len == 0) |
| 7433 | goto fail; |
| 7434 | query = wpabuf_alloc(len); |
| 7435 | if (query == NULL) |
| 7436 | goto fail; |
| 7437 | if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0) |
| 7438 | goto fail; |
| 7439 | } |
| 7440 | } |
| 7441 | |
| 7442 | ret = gas_send_request(wpa_s, dst_addr, advproto, query); |
| 7443 | |
| 7444 | fail: |
| 7445 | wpabuf_free(advproto); |
| 7446 | wpabuf_free(query); |
| 7447 | |
| 7448 | return ret; |
| 7449 | } |
| 7450 | |
| 7451 | |
| 7452 | static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf, |
| 7453 | size_t buflen) |
| 7454 | { |
| 7455 | u8 addr[ETH_ALEN]; |
| 7456 | int dialog_token; |
| 7457 | int used; |
| 7458 | char *pos; |
| 7459 | size_t resp_len, start, requested_len; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7460 | struct wpabuf *resp; |
| 7461 | int ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7462 | |
| 7463 | used = hwaddr_aton2(cmd, addr); |
| 7464 | if (used < 0) |
| 7465 | return -1; |
| 7466 | |
| 7467 | pos = cmd + used; |
| 7468 | while (*pos == ' ') |
| 7469 | pos++; |
| 7470 | dialog_token = atoi(pos); |
| 7471 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7472 | if (wpa_s->last_gas_resp && |
| 7473 | os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 && |
| 7474 | dialog_token == wpa_s->last_gas_dialog_token) |
| 7475 | resp = wpa_s->last_gas_resp; |
| 7476 | else if (wpa_s->prev_gas_resp && |
| 7477 | os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 && |
| 7478 | dialog_token == wpa_s->prev_gas_dialog_token) |
| 7479 | resp = wpa_s->prev_gas_resp; |
| 7480 | else |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7481 | return -1; |
| 7482 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7483 | resp_len = wpabuf_len(resp); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7484 | start = 0; |
| 7485 | requested_len = resp_len; |
| 7486 | |
| 7487 | pos = os_strchr(pos, ' '); |
| 7488 | if (pos) { |
| 7489 | start = atoi(pos); |
| 7490 | if (start > resp_len) |
| 7491 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); |
| 7492 | pos = os_strchr(pos, ','); |
| 7493 | if (pos == NULL) |
| 7494 | return -1; |
| 7495 | pos++; |
| 7496 | requested_len = atoi(pos); |
| 7497 | if (start + requested_len > resp_len) |
| 7498 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); |
| 7499 | } |
| 7500 | |
| 7501 | if (requested_len * 2 + 1 > buflen) |
| 7502 | return os_snprintf(buf, buflen, "FAIL-Too long response"); |
| 7503 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7504 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start, |
| 7505 | requested_len); |
| 7506 | |
| 7507 | if (start + requested_len == resp_len) { |
| 7508 | /* |
| 7509 | * Free memory by dropping the response after it has been |
| 7510 | * fetched. |
| 7511 | */ |
| 7512 | if (resp == wpa_s->prev_gas_resp) { |
| 7513 | wpabuf_free(wpa_s->prev_gas_resp); |
| 7514 | wpa_s->prev_gas_resp = NULL; |
| 7515 | } else { |
| 7516 | wpabuf_free(wpa_s->last_gas_resp); |
| 7517 | wpa_s->last_gas_resp = NULL; |
| 7518 | } |
| 7519 | } |
| 7520 | |
| 7521 | return ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7522 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7523 | #endif /* CONFIG_INTERWORKING */ |
| 7524 | |
| 7525 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7526 | #ifdef CONFIG_HS20 |
| 7527 | |
| 7528 | static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst) |
| 7529 | { |
| 7530 | u8 dst_addr[ETH_ALEN]; |
| 7531 | int used; |
| 7532 | char *pos; |
| 7533 | u32 subtypes = 0; |
| 7534 | |
| 7535 | used = hwaddr_aton2(dst, dst_addr); |
| 7536 | if (used < 0) |
| 7537 | return -1; |
| 7538 | pos = dst + used; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7539 | if (*pos == ' ') |
| 7540 | pos++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7541 | for (;;) { |
| 7542 | int num = atoi(pos); |
| 7543 | if (num <= 0 || num > 31) |
| 7544 | return -1; |
| 7545 | subtypes |= BIT(num); |
| 7546 | pos = os_strchr(pos + 1, ','); |
| 7547 | if (pos == NULL) |
| 7548 | break; |
| 7549 | pos++; |
| 7550 | } |
| 7551 | |
| 7552 | if (subtypes == 0) |
| 7553 | return -1; |
| 7554 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7555 | return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7556 | } |
| 7557 | |
| 7558 | |
| 7559 | static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s, |
| 7560 | const u8 *addr, const char *realm) |
| 7561 | { |
| 7562 | u8 *buf; |
| 7563 | size_t rlen, len; |
| 7564 | int ret; |
| 7565 | |
| 7566 | rlen = os_strlen(realm); |
| 7567 | len = 3 + rlen; |
| 7568 | buf = os_malloc(len); |
| 7569 | if (buf == NULL) |
| 7570 | return -1; |
| 7571 | buf[0] = 1; /* NAI Home Realm Count */ |
| 7572 | buf[1] = 0; /* Formatted in accordance with RFC 4282 */ |
| 7573 | buf[2] = rlen; |
| 7574 | os_memcpy(buf + 3, realm, rlen); |
| 7575 | |
| 7576 | ret = hs20_anqp_send_req(wpa_s, addr, |
| 7577 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7578 | buf, len, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7579 | |
| 7580 | os_free(buf); |
| 7581 | |
| 7582 | return ret; |
| 7583 | } |
| 7584 | |
| 7585 | |
| 7586 | static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s, |
| 7587 | char *dst) |
| 7588 | { |
| 7589 | struct wpa_cred *cred = wpa_s->conf->cred; |
| 7590 | u8 dst_addr[ETH_ALEN]; |
| 7591 | int used; |
| 7592 | u8 *buf; |
| 7593 | size_t len; |
| 7594 | int ret; |
| 7595 | |
| 7596 | used = hwaddr_aton2(dst, dst_addr); |
| 7597 | if (used < 0) |
| 7598 | return -1; |
| 7599 | |
| 7600 | while (dst[used] == ' ') |
| 7601 | used++; |
| 7602 | if (os_strncmp(dst + used, "realm=", 6) == 0) |
| 7603 | return hs20_nai_home_realm_list(wpa_s, dst_addr, |
| 7604 | dst + used + 6); |
| 7605 | |
| 7606 | len = os_strlen(dst + used); |
| 7607 | |
| 7608 | if (len == 0 && cred && cred->realm) |
| 7609 | return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm); |
| 7610 | |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 7611 | if (len & 1) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7612 | return -1; |
| 7613 | len /= 2; |
| 7614 | buf = os_malloc(len); |
| 7615 | if (buf == NULL) |
| 7616 | return -1; |
| 7617 | if (hexstr2bin(dst + used, buf, len) < 0) { |
| 7618 | os_free(buf); |
| 7619 | return -1; |
| 7620 | } |
| 7621 | |
| 7622 | ret = hs20_anqp_send_req(wpa_s, dst_addr, |
| 7623 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7624 | buf, len, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7625 | os_free(buf); |
| 7626 | |
| 7627 | return ret; |
| 7628 | } |
| 7629 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 7630 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7631 | static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply, |
| 7632 | int buflen) |
| 7633 | { |
| 7634 | u8 dst_addr[ETH_ALEN]; |
| 7635 | int used; |
| 7636 | char *ctx = NULL, *icon, *poffset, *psize; |
| 7637 | |
| 7638 | used = hwaddr_aton2(cmd, dst_addr); |
| 7639 | if (used < 0) |
| 7640 | return -1; |
| 7641 | cmd += used; |
| 7642 | |
| 7643 | icon = str_token(cmd, " ", &ctx); |
| 7644 | poffset = str_token(cmd, " ", &ctx); |
| 7645 | psize = str_token(cmd, " ", &ctx); |
| 7646 | if (!icon || !poffset || !psize) |
| 7647 | return -1; |
| 7648 | |
| 7649 | wpa_s->fetch_osu_icon_in_progress = 0; |
| 7650 | return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize), |
| 7651 | reply, buflen); |
| 7652 | } |
| 7653 | |
| 7654 | |
| 7655 | static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd) |
| 7656 | { |
| 7657 | u8 dst_addr[ETH_ALEN]; |
| 7658 | int used; |
| 7659 | char *icon; |
| 7660 | |
| 7661 | if (!cmd[0]) |
| 7662 | return hs20_del_icon(wpa_s, NULL, NULL); |
| 7663 | |
| 7664 | used = hwaddr_aton2(cmd, dst_addr); |
| 7665 | if (used < 0) |
| 7666 | return -1; |
| 7667 | |
| 7668 | while (cmd[used] == ' ') |
| 7669 | used++; |
| 7670 | icon = cmd[used] ? &cmd[used] : NULL; |
| 7671 | |
| 7672 | return hs20_del_icon(wpa_s, dst_addr, icon); |
| 7673 | } |
| 7674 | |
| 7675 | |
| 7676 | static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 7677 | { |
| 7678 | u8 dst_addr[ETH_ALEN]; |
| 7679 | int used; |
| 7680 | char *icon; |
| 7681 | |
| 7682 | used = hwaddr_aton2(cmd, dst_addr); |
| 7683 | if (used < 0) |
| 7684 | return -1; |
| 7685 | |
| 7686 | while (cmd[used] == ' ') |
| 7687 | used++; |
| 7688 | icon = &cmd[used]; |
| 7689 | |
| 7690 | wpa_s->fetch_osu_icon_in_progress = 0; |
| 7691 | return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST), |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7692 | (u8 *) icon, os_strlen(icon), inmem); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 7693 | } |
| 7694 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7695 | #endif /* CONFIG_HS20 */ |
| 7696 | |
| 7697 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7698 | #ifdef CONFIG_AUTOSCAN |
| 7699 | |
| 7700 | static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s, |
| 7701 | char *cmd) |
| 7702 | { |
| 7703 | enum wpa_states state = wpa_s->wpa_state; |
| 7704 | char *new_params = NULL; |
| 7705 | |
| 7706 | if (os_strlen(cmd) > 0) { |
| 7707 | new_params = os_strdup(cmd); |
| 7708 | if (new_params == NULL) |
| 7709 | return -1; |
| 7710 | } |
| 7711 | |
| 7712 | os_free(wpa_s->conf->autoscan); |
| 7713 | wpa_s->conf->autoscan = new_params; |
| 7714 | |
| 7715 | if (wpa_s->conf->autoscan == NULL) |
| 7716 | autoscan_deinit(wpa_s); |
| 7717 | else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) |
| 7718 | autoscan_init(wpa_s, 1); |
| 7719 | else if (state == WPA_SCANNING) |
| 7720 | wpa_supplicant_reinit_autoscan(wpa_s); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7721 | else |
| 7722 | wpa_printf(MSG_DEBUG, "No autoscan update in state %s", |
| 7723 | wpa_supplicant_state_txt(state)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7724 | |
| 7725 | return 0; |
| 7726 | } |
| 7727 | |
| 7728 | #endif /* CONFIG_AUTOSCAN */ |
| 7729 | |
| 7730 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7731 | #ifdef CONFIG_WNM |
| 7732 | |
| 7733 | static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd) |
| 7734 | { |
| 7735 | int enter; |
| 7736 | int intval = 0; |
| 7737 | char *pos; |
| 7738 | int ret; |
| 7739 | struct wpabuf *tfs_req = NULL; |
| 7740 | |
| 7741 | if (os_strncmp(cmd, "enter", 5) == 0) |
| 7742 | enter = 1; |
| 7743 | else if (os_strncmp(cmd, "exit", 4) == 0) |
| 7744 | enter = 0; |
| 7745 | else |
| 7746 | return -1; |
| 7747 | |
| 7748 | pos = os_strstr(cmd, " interval="); |
| 7749 | if (pos) |
| 7750 | intval = atoi(pos + 10); |
| 7751 | |
| 7752 | pos = os_strstr(cmd, " tfs_req="); |
| 7753 | if (pos) { |
| 7754 | char *end; |
| 7755 | size_t len; |
| 7756 | pos += 9; |
| 7757 | end = os_strchr(pos, ' '); |
| 7758 | if (end) |
| 7759 | len = end - pos; |
| 7760 | else |
| 7761 | len = os_strlen(pos); |
| 7762 | if (len & 1) |
| 7763 | return -1; |
| 7764 | len /= 2; |
| 7765 | tfs_req = wpabuf_alloc(len); |
| 7766 | if (tfs_req == NULL) |
| 7767 | return -1; |
| 7768 | if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) { |
| 7769 | wpabuf_free(tfs_req); |
| 7770 | return -1; |
| 7771 | } |
| 7772 | } |
| 7773 | |
| 7774 | ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER : |
| 7775 | WNM_SLEEP_MODE_EXIT, intval, |
| 7776 | tfs_req); |
| 7777 | wpabuf_free(tfs_req); |
| 7778 | |
| 7779 | return ret; |
| 7780 | } |
| 7781 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 7782 | |
| 7783 | static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd) |
| 7784 | { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7785 | int query_reason, list = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7786 | char *btm_candidates = NULL; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 7787 | |
| 7788 | query_reason = atoi(cmd); |
| 7789 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7790 | cmd = os_strchr(cmd, ' '); |
| 7791 | if (cmd) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7792 | if (os_strncmp(cmd, " list", 5) == 0) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7793 | list = 1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7794 | else |
| 7795 | btm_candidates = cmd; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7796 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 7797 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7798 | wpa_printf(MSG_DEBUG, |
| 7799 | "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s", |
| 7800 | query_reason, list ? " candidate list" : ""); |
| 7801 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7802 | return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason, |
| 7803 | btm_candidates, |
| 7804 | list); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 7805 | } |
| 7806 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 7807 | |
| 7808 | static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s, |
| 7809 | char *cmd) |
| 7810 | { |
| 7811 | struct wpabuf *elems; |
| 7812 | int ret; |
| 7813 | |
| 7814 | elems = wpabuf_parse_bin(cmd); |
| 7815 | if (!elems) |
| 7816 | return -1; |
| 7817 | |
| 7818 | ret = wnm_send_coloc_intf_report(wpa_s, 0, elems); |
| 7819 | wpabuf_free(elems); |
| 7820 | return ret; |
| 7821 | } |
| 7822 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7823 | #endif /* CONFIG_WNM */ |
| 7824 | |
| 7825 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7826 | static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, |
| 7827 | size_t buflen) |
| 7828 | { |
| 7829 | struct wpa_signal_info si; |
| 7830 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7831 | char *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7832 | |
| 7833 | ret = wpa_drv_signal_poll(wpa_s, &si); |
| 7834 | if (ret) |
| 7835 | return -1; |
| 7836 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7837 | pos = buf; |
| 7838 | end = buf + buflen; |
| 7839 | |
| 7840 | ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7841 | "NOISE=%d\nFREQUENCY=%u\n", |
| 7842 | si.current_signal, si.current_txrate / 1000, |
| 7843 | si.current_noise, si.frequency); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7844 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7845 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7846 | pos += ret; |
| 7847 | |
| 7848 | if (si.chanwidth != CHAN_WIDTH_UNKNOWN) { |
| 7849 | ret = os_snprintf(pos, end - pos, "WIDTH=%s\n", |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7850 | channel_width_to_string(si.chanwidth)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7851 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7852 | return -1; |
| 7853 | pos += ret; |
| 7854 | } |
| 7855 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7856 | if (si.center_frq1 > 0) { |
| 7857 | ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n", |
| 7858 | si.center_frq1); |
| 7859 | if (os_snprintf_error(end - pos, ret)) |
| 7860 | return -1; |
| 7861 | pos += ret; |
| 7862 | } |
| 7863 | |
| 7864 | if (si.center_frq2 > 0) { |
| 7865 | ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n", |
| 7866 | si.center_frq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7867 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7868 | return -1; |
| 7869 | pos += ret; |
| 7870 | } |
| 7871 | |
| 7872 | if (si.avg_signal) { |
| 7873 | ret = os_snprintf(pos, end - pos, |
| 7874 | "AVG_RSSI=%d\n", si.avg_signal); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7875 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7876 | return -1; |
| 7877 | pos += ret; |
| 7878 | } |
| 7879 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 7880 | if (si.avg_beacon_signal) { |
| 7881 | ret = os_snprintf(pos, end - pos, |
| 7882 | "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal); |
| 7883 | if (os_snprintf_error(end - pos, ret)) |
| 7884 | return -1; |
| 7885 | pos += ret; |
| 7886 | } |
| 7887 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7888 | return pos - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7889 | } |
| 7890 | |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7891 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7892 | static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s, |
| 7893 | const char *cmd) |
| 7894 | { |
| 7895 | const char *pos; |
| 7896 | int threshold = 0; |
| 7897 | int hysteresis = 0; |
| 7898 | |
| 7899 | if (wpa_s->bgscan && wpa_s->bgscan_priv) { |
| 7900 | wpa_printf(MSG_DEBUG, |
| 7901 | "Reject SIGNAL_MONITOR command - bgscan is active"); |
| 7902 | return -1; |
| 7903 | } |
| 7904 | pos = os_strstr(cmd, "THRESHOLD="); |
| 7905 | if (pos) |
| 7906 | threshold = atoi(pos + 10); |
| 7907 | pos = os_strstr(cmd, "HYSTERESIS="); |
| 7908 | if (pos) |
| 7909 | hysteresis = atoi(pos + 11); |
| 7910 | return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis); |
| 7911 | } |
| 7912 | |
| 7913 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7914 | #ifdef CONFIG_TESTING_OPTIONS |
| 7915 | int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s, |
| 7916 | enum wpa_driver_if_type if_type, |
| 7917 | unsigned int *num, |
| 7918 | unsigned int *freq_list) |
| 7919 | { |
| 7920 | char *pos = wpa_s->get_pref_freq_list_override; |
| 7921 | char *end; |
| 7922 | unsigned int count = 0; |
| 7923 | |
| 7924 | /* Override string format: |
| 7925 | * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */ |
| 7926 | |
| 7927 | while (pos) { |
| 7928 | if (atoi(pos) == (int) if_type) |
| 7929 | break; |
| 7930 | pos = os_strchr(pos, ' '); |
| 7931 | if (pos) |
| 7932 | pos++; |
| 7933 | } |
| 7934 | if (!pos) |
| 7935 | return -1; |
| 7936 | pos = os_strchr(pos, ':'); |
| 7937 | if (!pos) |
| 7938 | return -1; |
| 7939 | pos++; |
| 7940 | end = os_strchr(pos, ' '); |
| 7941 | while (pos && (!end || pos < end) && count < *num) { |
| 7942 | freq_list[count++] = atoi(pos); |
| 7943 | pos = os_strchr(pos, ','); |
| 7944 | if (pos) |
| 7945 | pos++; |
| 7946 | } |
| 7947 | |
| 7948 | *num = count; |
| 7949 | return 0; |
| 7950 | } |
| 7951 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7952 | |
| 7953 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7954 | static int wpas_ctrl_iface_get_pref_freq_list( |
| 7955 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| 7956 | { |
| 7957 | unsigned int freq_list[100], num = 100, i; |
| 7958 | int ret; |
| 7959 | enum wpa_driver_if_type iface_type; |
| 7960 | char *pos, *end; |
| 7961 | |
| 7962 | pos = buf; |
| 7963 | end = buf + buflen; |
| 7964 | |
| 7965 | /* buf: "<interface_type>" */ |
| 7966 | if (os_strcmp(cmd, "STATION") == 0) |
| 7967 | iface_type = WPA_IF_STATION; |
| 7968 | else if (os_strcmp(cmd, "AP") == 0) |
| 7969 | iface_type = WPA_IF_AP_BSS; |
| 7970 | else if (os_strcmp(cmd, "P2P_GO") == 0) |
| 7971 | iface_type = WPA_IF_P2P_GO; |
| 7972 | else if (os_strcmp(cmd, "P2P_CLIENT") == 0) |
| 7973 | iface_type = WPA_IF_P2P_CLIENT; |
| 7974 | else if (os_strcmp(cmd, "IBSS") == 0) |
| 7975 | iface_type = WPA_IF_IBSS; |
| 7976 | else if (os_strcmp(cmd, "TDLS") == 0) |
| 7977 | iface_type = WPA_IF_TDLS; |
| 7978 | else |
| 7979 | return -1; |
| 7980 | |
| 7981 | wpa_printf(MSG_DEBUG, |
| 7982 | "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)", |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7983 | iface_type, cmd); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7984 | |
| 7985 | ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list); |
| 7986 | if (ret) |
| 7987 | return -1; |
| 7988 | |
| 7989 | for (i = 0; i < num; i++) { |
| 7990 | ret = os_snprintf(pos, end - pos, "%s%u", |
| 7991 | i > 0 ? "," : "", freq_list[i]); |
| 7992 | if (os_snprintf_error(end - pos, ret)) |
| 7993 | return -1; |
| 7994 | pos += ret; |
| 7995 | } |
| 7996 | |
| 7997 | return pos - buf; |
| 7998 | } |
| 7999 | |
| 8000 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8001 | static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s, |
| 8002 | char *buf, size_t buflen) |
| 8003 | { |
| 8004 | int ret, i; |
| 8005 | char *pos, *end; |
| 8006 | |
| 8007 | ret = os_snprintf(buf, buflen, "%016llX:\n", |
| 8008 | (long long unsigned) wpa_s->drv_flags); |
| 8009 | if (os_snprintf_error(buflen, ret)) |
| 8010 | return -1; |
| 8011 | |
| 8012 | pos = buf + ret; |
| 8013 | end = buf + buflen; |
| 8014 | |
| 8015 | for (i = 0; i < 64; i++) { |
| 8016 | if (wpa_s->drv_flags & (1LLU << i)) { |
| 8017 | ret = os_snprintf(pos, end - pos, "%s\n", |
| 8018 | driver_flag_to_string(1LLU << i)); |
| 8019 | if (os_snprintf_error(end - pos, ret)) |
| 8020 | return -1; |
| 8021 | pos += ret; |
| 8022 | } |
| 8023 | } |
| 8024 | |
| 8025 | return pos - buf; |
| 8026 | } |
| 8027 | |
| 8028 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8029 | static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s, |
| 8030 | char *buf, size_t buflen) |
| 8031 | { |
| 8032 | int ret, i; |
| 8033 | char *pos, *end; |
| 8034 | |
| 8035 | ret = os_snprintf(buf, buflen, "%016llX:\n", |
| 8036 | (long long unsigned) wpa_s->drv_flags2); |
| 8037 | if (os_snprintf_error(buflen, ret)) |
| 8038 | return -1; |
| 8039 | |
| 8040 | pos = buf + ret; |
| 8041 | end = buf + buflen; |
| 8042 | |
| 8043 | for (i = 0; i < 64; i++) { |
| 8044 | if (wpa_s->drv_flags2 & (1LLU << i)) { |
| 8045 | ret = os_snprintf(pos, end - pos, "%s\n", |
| 8046 | driver_flag2_to_string(1LLU << i)); |
| 8047 | if (os_snprintf_error(end - pos, ret)) |
| 8048 | return -1; |
| 8049 | pos += ret; |
| 8050 | } |
| 8051 | } |
| 8052 | |
| 8053 | return pos - buf; |
| 8054 | } |
| 8055 | |
| 8056 | |
Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 8057 | static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf, |
| 8058 | size_t buflen) |
| 8059 | { |
| 8060 | struct hostap_sta_driver_data sta; |
| 8061 | int ret; |
| 8062 | |
| 8063 | ret = wpa_drv_pktcnt_poll(wpa_s, &sta); |
| 8064 | if (ret) |
| 8065 | return -1; |
| 8066 | |
| 8067 | ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n", |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 8068 | sta.tx_packets, sta.tx_retry_failed, sta.rx_packets); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8069 | if (os_snprintf_error(buflen, ret)) |
Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 8070 | return -1; |
| 8071 | return ret; |
| 8072 | } |
| 8073 | |
| 8074 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8075 | #ifdef ANDROID |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 8076 | static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd, |
| 8077 | char *buf, size_t buflen) |
| 8078 | { |
| 8079 | int ret; |
| 8080 | |
| 8081 | ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen); |
Dmitry Shmidt | 9432e12 | 2013-09-12 12:39:30 -0700 | [diff] [blame] | 8082 | if (ret == 0) { |
| 8083 | if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) { |
| 8084 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 8085 | if (p2p) { |
| 8086 | char country[3]; |
| 8087 | country[0] = cmd[8]; |
| 8088 | country[1] = cmd[9]; |
| 8089 | country[2] = 0x04; |
| 8090 | p2p_set_country(p2p, country); |
| 8091 | } |
| 8092 | } |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8093 | ret = os_snprintf(buf, buflen, "%s\n", "OK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8094 | if (os_snprintf_error(buflen, ret)) |
| 8095 | ret = -1; |
Dmitry Shmidt | 9432e12 | 2013-09-12 12:39:30 -0700 | [diff] [blame] | 8096 | } |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 8097 | return ret; |
| 8098 | } |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8099 | #endif /* ANDROID */ |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 8100 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 8101 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8102 | static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd, |
| 8103 | char *buf, size_t buflen) |
| 8104 | { |
| 8105 | int ret; |
| 8106 | char *pos; |
| 8107 | u8 *data = NULL; |
| 8108 | unsigned int vendor_id, subcmd; |
| 8109 | struct wpabuf *reply; |
| 8110 | size_t data_len = 0; |
| 8111 | |
| 8112 | /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */ |
| 8113 | vendor_id = strtoul(cmd, &pos, 16); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8114 | if (!isblank((unsigned char) *pos)) |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8115 | return -EINVAL; |
| 8116 | |
| 8117 | subcmd = strtoul(pos, &pos, 10); |
| 8118 | |
| 8119 | if (*pos != '\0') { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8120 | if (!isblank((unsigned char) *pos++)) |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8121 | return -EINVAL; |
| 8122 | data_len = os_strlen(pos); |
| 8123 | } |
| 8124 | |
| 8125 | if (data_len) { |
| 8126 | data_len /= 2; |
| 8127 | data = os_malloc(data_len); |
| 8128 | if (!data) |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8129 | return -1; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8130 | |
| 8131 | if (hexstr2bin(pos, data, data_len)) { |
| 8132 | wpa_printf(MSG_DEBUG, |
| 8133 | "Vendor command: wrong parameter format"); |
| 8134 | os_free(data); |
| 8135 | return -EINVAL; |
| 8136 | } |
| 8137 | } |
| 8138 | |
| 8139 | reply = wpabuf_alloc((buflen - 1) / 2); |
| 8140 | if (!reply) { |
| 8141 | os_free(data); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8142 | return -1; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8143 | } |
| 8144 | |
| 8145 | ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len, |
| 8146 | reply); |
| 8147 | |
| 8148 | if (ret == 0) |
| 8149 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply), |
| 8150 | wpabuf_len(reply)); |
| 8151 | |
| 8152 | wpabuf_free(reply); |
| 8153 | os_free(data); |
| 8154 | |
| 8155 | return ret; |
| 8156 | } |
| 8157 | |
| 8158 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8159 | static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s) |
| 8160 | { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8161 | #ifdef CONFIG_P2P |
| 8162 | struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ? |
| 8163 | wpa_s->global->p2p_init_wpa_s : wpa_s; |
| 8164 | #endif /* CONFIG_P2P */ |
| 8165 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8166 | wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state"); |
| 8167 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 8168 | if (wpas_abort_ongoing_scan(wpa_s) == 0) |
| 8169 | wpa_s->ignore_post_flush_scan_res = 1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8170 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8171 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 8172 | /* |
| 8173 | * Avoid possible auto connect re-connection on getting |
| 8174 | * disconnected due to state flush. |
| 8175 | */ |
| 8176 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 8177 | } |
| 8178 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8179 | #ifdef CONFIG_P2P |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8180 | wpas_p2p_group_remove(p2p_wpa_s, "*"); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8181 | wpas_p2p_cancel(p2p_wpa_s); |
| 8182 | p2p_ctrl_flush(p2p_wpa_s); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8183 | wpas_p2p_service_flush(p2p_wpa_s); |
| 8184 | p2p_wpa_s->global->p2p_disabled = 0; |
| 8185 | p2p_wpa_s->global->p2p_per_sta_psk = 0; |
| 8186 | p2p_wpa_s->conf->num_sec_device_types = 0; |
| 8187 | p2p_wpa_s->p2p_disable_ip_addr_req = 0; |
| 8188 | os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range); |
| 8189 | p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8190 | p2p_wpa_s->global->p2p_go_avoid_freq.num = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8191 | p2p_wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8192 | p2p_wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8193 | #endif /* CONFIG_P2P */ |
| 8194 | |
| 8195 | #ifdef CONFIG_WPS_TESTING |
| 8196 | wps_version_number = 0x20; |
| 8197 | wps_testing_dummy_cred = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 8198 | wps_corrupt_pkhash = 0; |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8199 | wps_force_auth_types_in_use = 0; |
| 8200 | wps_force_encr_types_in_use = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8201 | #endif /* CONFIG_WPS_TESTING */ |
| 8202 | #ifdef CONFIG_WPS |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8203 | wpa_s->wps_fragment_size = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8204 | wpas_wps_cancel(wpa_s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8205 | wps_registrar_flush(wpa_s->wps->registrar); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8206 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8207 | wpa_s->after_wps = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8208 | wpa_s->known_wps_freq = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8209 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8210 | #ifdef CONFIG_DPP |
| 8211 | wpas_dpp_deinit(wpa_s); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8212 | wpa_s->dpp_init_max_tries = 0; |
| 8213 | wpa_s->dpp_init_retry_time = 0; |
| 8214 | wpa_s->dpp_resp_wait_time = 0; |
| 8215 | wpa_s->dpp_resp_max_tries = 0; |
| 8216 | wpa_s->dpp_resp_retry_time = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8217 | #ifdef CONFIG_DPP2 |
| 8218 | wpas_dpp_chirp_stop(wpa_s); |
| 8219 | wpa_s->dpp_pfs_fallback = 0; |
| 8220 | #endif /* CONFIG_DPP2 */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8221 | #ifdef CONFIG_TESTING_OPTIONS |
| 8222 | os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN); |
| 8223 | os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN); |
| 8224 | dpp_pkex_ephemeral_key_override_len = 0; |
| 8225 | dpp_protocol_key_override_len = 0; |
| 8226 | dpp_nonce_override_len = 0; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 8227 | #ifdef CONFIG_DPP2 |
| 8228 | dpp_version_override = 2; |
| 8229 | #else /* CONFIG_DPP2 */ |
| 8230 | dpp_version_override = 1; |
| 8231 | #endif /* CONFIG_DPP2 */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8232 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8233 | #endif /* CONFIG_DPP */ |
| 8234 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8235 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8236 | #ifdef CONFIG_TDLS_TESTING |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8237 | tdls_testing = 0; |
| 8238 | #endif /* CONFIG_TDLS_TESTING */ |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8239 | wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL); |
| 8240 | wpa_tdls_enable(wpa_s->wpa, 1); |
| 8241 | #endif /* CONFIG_TDLS */ |
| 8242 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8243 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL); |
| 8244 | wpa_supplicant_stop_countermeasures(wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8245 | wpa_s->last_michael_mic_error.sec = 0; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8246 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8247 | wpa_s->no_keep_alive = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 8248 | wpa_s->own_disconnect_req = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8249 | wpa_s->own_reconnect_req = 0; |
| 8250 | wpa_s->deny_ptk0_rekey = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8251 | |
| 8252 | os_free(wpa_s->disallow_aps_bssid); |
| 8253 | wpa_s->disallow_aps_bssid = NULL; |
| 8254 | wpa_s->disallow_aps_bssid_count = 0; |
| 8255 | os_free(wpa_s->disallow_aps_ssid); |
| 8256 | wpa_s->disallow_aps_ssid = NULL; |
| 8257 | wpa_s->disallow_aps_ssid_count = 0; |
| 8258 | |
| 8259 | wpa_s->set_sta_uapsd = 0; |
| 8260 | wpa_s->sta_uapsd = 0; |
| 8261 | |
| 8262 | wpa_drv_radio_disable(wpa_s, 0); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8263 | wpa_blacklist_clear(wpa_s); |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 8264 | wpa_s->extra_blacklist_count = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8265 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all"); |
| 8266 | wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all"); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 8267 | wpa_config_flush_blobs(wpa_s->conf); |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 8268 | wpa_s->conf->auto_interworking = 0; |
| 8269 | wpa_s->conf->okc = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8270 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8271 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
| 8272 | rsn_preauth_deinit(wpa_s->wpa); |
| 8273 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8274 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200); |
| 8275 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70); |
| 8276 | wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 8277 | eapol_sm_notify_logoff(wpa_s->eapol, false); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8278 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 8279 | radio_remove_works(wpa_s, NULL, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8280 | wpa_s->ext_work_in_progress = 0; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8281 | |
| 8282 | wpa_s->next_ssid = NULL; |
| 8283 | |
| 8284 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8285 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8286 | hs20_cancel_fetch_osu(wpa_s); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 8287 | hs20_del_icon(wpa_s, NULL, NULL); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8288 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8289 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 8290 | |
| 8291 | wpa_s->ext_mgmt_frame_handling = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8292 | wpa_s->ext_eapol_frame_io = 0; |
| 8293 | #ifdef CONFIG_TESTING_OPTIONS |
| 8294 | wpa_s->extra_roc_dur = 0; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8295 | wpa_s->test_failure = WPAS_TEST_FAILURE_NONE; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8296 | wpa_s->p2p_go_csa_on_inv = 0; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8297 | wpa_s->ignore_auth_resp = 0; |
| 8298 | wpa_s->ignore_assoc_disallow = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8299 | wpa_s->disable_sa_query = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8300 | wpa_s->testing_resend_assoc = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8301 | wpa_s->ignore_sae_h2e_only = 0; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8302 | wpa_s->ft_rsnxe_used = 0; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8303 | wpa_s->reject_btm_req_reason = 0; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8304 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8305 | os_free(wpa_s->get_pref_freq_list_override); |
| 8306 | wpa_s->get_pref_freq_list_override = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8307 | wpabuf_free(wpa_s->sae_commit_override); |
| 8308 | wpa_s->sae_commit_override = NULL; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8309 | os_free(wpa_s->extra_sae_rejected_groups); |
| 8310 | wpa_s->extra_sae_rejected_groups = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8311 | wpabuf_free(wpa_s->rsne_override_eapol); |
| 8312 | wpa_s->rsne_override_eapol = NULL; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8313 | wpabuf_free(wpa_s->rsnxe_override_assoc); |
| 8314 | wpa_s->rsnxe_override_assoc = NULL; |
| 8315 | wpabuf_free(wpa_s->rsnxe_override_eapol); |
| 8316 | wpa_s->rsnxe_override_eapol = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8317 | wpas_clear_driver_signal_override(wpa_s); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8318 | #ifdef CONFIG_DPP |
| 8319 | os_free(wpa_s->dpp_config_obj_override); |
| 8320 | wpa_s->dpp_config_obj_override = NULL; |
| 8321 | os_free(wpa_s->dpp_discovery_override); |
| 8322 | wpa_s->dpp_discovery_override = NULL; |
| 8323 | os_free(wpa_s->dpp_groups_override); |
| 8324 | wpa_s->dpp_groups_override = NULL; |
| 8325 | dpp_test = DPP_TEST_DISABLED; |
| 8326 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8327 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8328 | |
| 8329 | wpa_s->disconnected = 0; |
| 8330 | os_free(wpa_s->next_scan_freqs); |
| 8331 | wpa_s->next_scan_freqs = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8332 | os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN); |
| 8333 | wpa_s->next_scan_bssid_wildcard_ssid = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8334 | os_free(wpa_s->select_network_scan_freqs); |
| 8335 | wpa_s->select_network_scan_freqs = NULL; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8336 | |
| 8337 | wpa_bss_flush(wpa_s); |
| 8338 | if (!dl_list_empty(&wpa_s->bss)) { |
| 8339 | wpa_printf(MSG_DEBUG, |
| 8340 | "BSS table not empty after flush: %u entries, current_bss=%p bssid=" |
| 8341 | MACSTR " pending_bssid=" MACSTR, |
| 8342 | dl_list_len(&wpa_s->bss), wpa_s->current_bss, |
| 8343 | MAC2STR(wpa_s->bssid), |
| 8344 | MAC2STR(wpa_s->pending_bssid)); |
| 8345 | } |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8346 | |
| 8347 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
Dmitry Shmidt | b70d0bb | 2015-11-16 10:43:06 -0800 | [diff] [blame] | 8348 | wpa_s->wnmsleep_used = 0; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8349 | |
| 8350 | #ifdef CONFIG_SME |
| 8351 | wpa_s->sme.last_unprot_disconnect.sec = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8352 | wpa_s->sme.auth_alg = 0; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8353 | #endif /* CONFIG_SME */ |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8354 | |
| 8355 | wpabuf_free(wpa_s->ric_ies); |
| 8356 | wpa_s->ric_ies = NULL; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8357 | |
| 8358 | wpa_supplicant_update_channel_list(wpa_s, NULL); |
| 8359 | |
| 8360 | free_bss_tmp_disallowed(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8361 | } |
| 8362 | |
| 8363 | |
| 8364 | static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s, |
| 8365 | char *buf, size_t buflen) |
| 8366 | { |
| 8367 | struct wpa_radio_work *work; |
| 8368 | char *pos, *end; |
| 8369 | struct os_reltime now, diff; |
| 8370 | |
| 8371 | pos = buf; |
| 8372 | end = buf + buflen; |
| 8373 | |
| 8374 | os_get_reltime(&now); |
| 8375 | |
| 8376 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) |
| 8377 | { |
| 8378 | int ret; |
| 8379 | |
| 8380 | os_reltime_sub(&now, &work->time, &diff); |
| 8381 | ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n", |
| 8382 | work->type, work->wpa_s->ifname, work->freq, |
| 8383 | work->started, diff.sec, diff.usec); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8384 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8385 | break; |
| 8386 | pos += ret; |
| 8387 | } |
| 8388 | |
| 8389 | return pos - buf; |
| 8390 | } |
| 8391 | |
| 8392 | |
| 8393 | static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx) |
| 8394 | { |
| 8395 | struct wpa_radio_work *work = eloop_ctx; |
| 8396 | struct wpa_external_work *ework = work->ctx; |
| 8397 | |
| 8398 | wpa_dbg(work->wpa_s, MSG_DEBUG, |
| 8399 | "Timing out external radio work %u (%s)", |
| 8400 | ework->id, work->type); |
| 8401 | wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8402 | work->wpa_s->ext_work_in_progress = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8403 | radio_work_done(work); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8404 | os_free(ework); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8405 | } |
| 8406 | |
| 8407 | |
| 8408 | static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit) |
| 8409 | { |
| 8410 | struct wpa_external_work *ework = work->ctx; |
| 8411 | |
| 8412 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 8413 | if (work->started) |
| 8414 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, |
| 8415 | work, NULL); |
| 8416 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8417 | /* |
| 8418 | * work->type points to a buffer in ework, so need to replace |
| 8419 | * that here with a fixed string to avoid use of freed memory |
| 8420 | * in debug prints. |
| 8421 | */ |
| 8422 | work->type = "freed-ext-work"; |
| 8423 | work->ctx = NULL; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8424 | os_free(ework); |
| 8425 | return; |
| 8426 | } |
| 8427 | |
| 8428 | wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)", |
| 8429 | ework->id, ework->type); |
| 8430 | wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8431 | work->wpa_s->ext_work_in_progress = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8432 | if (!ework->timeout) |
| 8433 | ework->timeout = 10; |
| 8434 | eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout, |
| 8435 | work, NULL); |
| 8436 | } |
| 8437 | |
| 8438 | |
| 8439 | static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd, |
| 8440 | char *buf, size_t buflen) |
| 8441 | { |
| 8442 | struct wpa_external_work *ework; |
| 8443 | char *pos, *pos2; |
| 8444 | size_t type_len; |
| 8445 | int ret; |
| 8446 | unsigned int freq = 0; |
| 8447 | |
| 8448 | /* format: <name> [freq=<MHz>] [timeout=<seconds>] */ |
| 8449 | |
| 8450 | ework = os_zalloc(sizeof(*ework)); |
| 8451 | if (ework == NULL) |
| 8452 | return -1; |
| 8453 | |
| 8454 | pos = os_strchr(cmd, ' '); |
| 8455 | if (pos) { |
| 8456 | type_len = pos - cmd; |
| 8457 | pos++; |
| 8458 | |
| 8459 | pos2 = os_strstr(pos, "freq="); |
| 8460 | if (pos2) |
| 8461 | freq = atoi(pos2 + 5); |
| 8462 | |
| 8463 | pos2 = os_strstr(pos, "timeout="); |
| 8464 | if (pos2) |
| 8465 | ework->timeout = atoi(pos2 + 8); |
| 8466 | } else { |
| 8467 | type_len = os_strlen(cmd); |
| 8468 | } |
| 8469 | if (4 + type_len >= sizeof(ework->type)) |
| 8470 | type_len = sizeof(ework->type) - 4 - 1; |
| 8471 | os_strlcpy(ework->type, "ext:", sizeof(ework->type)); |
| 8472 | os_memcpy(ework->type + 4, cmd, type_len); |
| 8473 | ework->type[4 + type_len] = '\0'; |
| 8474 | |
| 8475 | wpa_s->ext_work_id++; |
| 8476 | if (wpa_s->ext_work_id == 0) |
| 8477 | wpa_s->ext_work_id++; |
| 8478 | ework->id = wpa_s->ext_work_id; |
| 8479 | |
| 8480 | if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb, |
| 8481 | ework) < 0) { |
| 8482 | os_free(ework); |
| 8483 | return -1; |
| 8484 | } |
| 8485 | |
| 8486 | ret = os_snprintf(buf, buflen, "%u", ework->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8487 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8488 | return -1; |
| 8489 | return ret; |
| 8490 | } |
| 8491 | |
| 8492 | |
| 8493 | static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd) |
| 8494 | { |
| 8495 | struct wpa_radio_work *work; |
| 8496 | unsigned int id = atoi(cmd); |
| 8497 | |
| 8498 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) |
| 8499 | { |
| 8500 | struct wpa_external_work *ework; |
| 8501 | |
| 8502 | if (os_strncmp(work->type, "ext:", 4) != 0) |
| 8503 | continue; |
| 8504 | ework = work->ctx; |
| 8505 | if (id && ework->id != id) |
| 8506 | continue; |
| 8507 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8508 | "Completed external radio work %u (%s)", |
| 8509 | ework->id, ework->type); |
| 8510 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8511 | wpa_s->ext_work_in_progress = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8512 | radio_work_done(work); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 8513 | os_free(ework); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8514 | return 3; /* "OK\n" */ |
| 8515 | } |
| 8516 | |
| 8517 | return -1; |
| 8518 | } |
| 8519 | |
| 8520 | |
| 8521 | static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd, |
| 8522 | char *buf, size_t buflen) |
| 8523 | { |
| 8524 | if (os_strcmp(cmd, "show") == 0) |
| 8525 | return wpas_ctrl_radio_work_show(wpa_s, buf, buflen); |
| 8526 | if (os_strncmp(cmd, "add ", 4) == 0) |
| 8527 | return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen); |
| 8528 | if (os_strncmp(cmd, "done ", 5) == 0) |
| 8529 | return wpas_ctrl_radio_work_done(wpa_s, cmd + 4); |
| 8530 | return -1; |
| 8531 | } |
| 8532 | |
| 8533 | |
| 8534 | void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s) |
| 8535 | { |
| 8536 | struct wpa_radio_work *work, *tmp; |
| 8537 | |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 8538 | if (!wpa_s || !wpa_s->radio) |
| 8539 | return; |
| 8540 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8541 | dl_list_for_each_safe(work, tmp, &wpa_s->radio->work, |
| 8542 | struct wpa_radio_work, list) { |
| 8543 | struct wpa_external_work *ework; |
| 8544 | |
| 8545 | if (os_strncmp(work->type, "ext:", 4) != 0) |
| 8546 | continue; |
| 8547 | ework = work->ctx; |
| 8548 | wpa_dbg(wpa_s, MSG_DEBUG, |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 8549 | "Flushing%s external radio work %u (%s)", |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8550 | work->started ? " started" : "", ework->id, |
| 8551 | ework->type); |
| 8552 | if (work->started) |
| 8553 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, |
| 8554 | work, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8555 | radio_work_done(work); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8556 | os_free(ework); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8557 | } |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8558 | } |
| 8559 | |
| 8560 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8561 | static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx) |
| 8562 | { |
| 8563 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 8564 | eapol_sm_notify_ctrl_response(wpa_s->eapol); |
| 8565 | } |
| 8566 | |
| 8567 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8568 | static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value, |
| 8569 | unsigned int *scan_id_count, int scan_id[]) |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8570 | { |
| 8571 | const char *pos = value; |
| 8572 | |
| 8573 | while (pos) { |
| 8574 | if (*pos == ' ' || *pos == '\0') |
| 8575 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8576 | if (*scan_id_count == MAX_SCAN_ID) |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8577 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8578 | scan_id[(*scan_id_count)++] = atoi(pos); |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8579 | pos = os_strchr(pos, ','); |
| 8580 | if (pos) |
| 8581 | pos++; |
| 8582 | } |
| 8583 | |
| 8584 | return 0; |
| 8585 | } |
| 8586 | |
| 8587 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8588 | static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params, |
| 8589 | char *reply, int reply_size, int *reply_len) |
| 8590 | { |
| 8591 | char *pos; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8592 | unsigned int manual_scan_passive = 0; |
| 8593 | unsigned int manual_scan_use_id = 0; |
| 8594 | unsigned int manual_scan_only_new = 0; |
| 8595 | unsigned int scan_only = 0; |
| 8596 | unsigned int scan_id_count = 0; |
| 8597 | int scan_id[MAX_SCAN_ID]; |
| 8598 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, |
| 8599 | struct wpa_scan_results *scan_res); |
| 8600 | int *manual_scan_freqs = NULL; |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 8601 | struct wpa_ssid_value *ssid = NULL, *ns; |
| 8602 | unsigned int ssid_count = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8603 | |
| 8604 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 8605 | *reply_len = -1; |
| 8606 | return; |
| 8607 | } |
| 8608 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8609 | if (radio_work_pending(wpa_s, "scan")) { |
| 8610 | wpa_printf(MSG_DEBUG, |
| 8611 | "Pending scan scheduled - reject new request"); |
| 8612 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); |
| 8613 | return; |
| 8614 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8615 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8616 | #ifdef CONFIG_INTERWORKING |
| 8617 | if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) { |
| 8618 | wpa_printf(MSG_DEBUG, |
| 8619 | "Interworking select in progress - reject new scan"); |
| 8620 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); |
| 8621 | return; |
| 8622 | } |
| 8623 | #endif /* CONFIG_INTERWORKING */ |
| 8624 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8625 | if (params) { |
| 8626 | if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8627 | scan_only = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8628 | |
| 8629 | pos = os_strstr(params, "freq="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8630 | if (pos) { |
| 8631 | manual_scan_freqs = freq_range_to_channel_list(wpa_s, |
| 8632 | pos + 5); |
| 8633 | if (manual_scan_freqs == NULL) { |
| 8634 | *reply_len = -1; |
| 8635 | goto done; |
| 8636 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8637 | } |
| 8638 | |
| 8639 | pos = os_strstr(params, "passive="); |
| 8640 | if (pos) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8641 | manual_scan_passive = !!atoi(pos + 8); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8642 | |
| 8643 | pos = os_strstr(params, "use_id="); |
| 8644 | if (pos) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8645 | manual_scan_use_id = atoi(pos + 7); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8646 | |
| 8647 | pos = os_strstr(params, "only_new=1"); |
| 8648 | if (pos) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8649 | manual_scan_only_new = 1; |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8650 | |
| 8651 | pos = os_strstr(params, "scan_id="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8652 | if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count, |
| 8653 | scan_id) < 0) { |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8654 | *reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8655 | goto done; |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8656 | } |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 8657 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8658 | pos = os_strstr(params, "bssid="); |
| 8659 | if (pos) { |
| 8660 | u8 bssid[ETH_ALEN]; |
| 8661 | |
| 8662 | pos += 6; |
| 8663 | if (hwaddr_aton(pos, bssid)) { |
| 8664 | wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos); |
| 8665 | *reply_len = -1; |
| 8666 | goto done; |
| 8667 | } |
| 8668 | os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8669 | |
| 8670 | wpa_s->next_scan_bssid_wildcard_ssid = |
| 8671 | os_strstr(params, "wildcard_ssid=1") != NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8672 | } |
| 8673 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 8674 | pos = params; |
| 8675 | while (pos && *pos != '\0') { |
| 8676 | if (os_strncmp(pos, "ssid ", 5) == 0) { |
| 8677 | char *end; |
| 8678 | |
| 8679 | pos += 5; |
| 8680 | end = pos; |
| 8681 | while (*end) { |
| 8682 | if (*end == '\0' || *end == ' ') |
| 8683 | break; |
| 8684 | end++; |
| 8685 | } |
| 8686 | |
| 8687 | ns = os_realloc_array( |
| 8688 | ssid, ssid_count + 1, |
| 8689 | sizeof(struct wpa_ssid_value)); |
| 8690 | if (ns == NULL) { |
| 8691 | *reply_len = -1; |
| 8692 | goto done; |
| 8693 | } |
| 8694 | ssid = ns; |
| 8695 | |
| 8696 | if ((end - pos) & 0x01 || |
| 8697 | end - pos > 2 * SSID_MAX_LEN || |
| 8698 | hexstr2bin(pos, ssid[ssid_count].ssid, |
| 8699 | (end - pos) / 2) < 0) { |
| 8700 | wpa_printf(MSG_DEBUG, |
| 8701 | "Invalid SSID value '%s'", |
| 8702 | pos); |
| 8703 | *reply_len = -1; |
| 8704 | goto done; |
| 8705 | } |
| 8706 | ssid[ssid_count].ssid_len = (end - pos) / 2; |
| 8707 | wpa_hexdump_ascii(MSG_DEBUG, "scan SSID", |
| 8708 | ssid[ssid_count].ssid, |
| 8709 | ssid[ssid_count].ssid_len); |
| 8710 | ssid_count++; |
| 8711 | pos = end; |
| 8712 | } |
| 8713 | |
| 8714 | pos = os_strchr(pos, ' '); |
| 8715 | if (pos) |
| 8716 | pos++; |
| 8717 | } |
| 8718 | } |
| 8719 | |
| 8720 | wpa_s->num_ssids_from_scan_req = ssid_count; |
| 8721 | os_free(wpa_s->ssids_from_scan_req); |
| 8722 | if (ssid_count) { |
| 8723 | wpa_s->ssids_from_scan_req = ssid; |
| 8724 | ssid = NULL; |
| 8725 | } else { |
| 8726 | wpa_s->ssids_from_scan_req = NULL; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8727 | } |
| 8728 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8729 | if (scan_only) |
| 8730 | scan_res_handler = scan_only_handler; |
| 8731 | else if (wpa_s->scan_res_handler == scan_only_handler) |
| 8732 | scan_res_handler = NULL; |
| 8733 | else |
| 8734 | scan_res_handler = wpa_s->scan_res_handler; |
| 8735 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8736 | if (!wpa_s->sched_scanning && !wpa_s->scanning && |
| 8737 | ((wpa_s->wpa_state <= WPA_SCANNING) || |
| 8738 | (wpa_s->wpa_state == WPA_COMPLETED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8739 | wpa_s->manual_scan_passive = manual_scan_passive; |
| 8740 | wpa_s->manual_scan_use_id = manual_scan_use_id; |
| 8741 | wpa_s->manual_scan_only_new = manual_scan_only_new; |
| 8742 | wpa_s->scan_id_count = scan_id_count; |
| 8743 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); |
| 8744 | wpa_s->scan_res_handler = scan_res_handler; |
| 8745 | os_free(wpa_s->manual_scan_freqs); |
| 8746 | wpa_s->manual_scan_freqs = manual_scan_freqs; |
| 8747 | manual_scan_freqs = NULL; |
| 8748 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8749 | wpa_s->normal_scans = 0; |
| 8750 | wpa_s->scan_req = MANUAL_SCAN_REQ; |
| 8751 | wpa_s->after_wps = 0; |
| 8752 | wpa_s->known_wps_freq = 0; |
| 8753 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 8754 | if (wpa_s->manual_scan_use_id) { |
| 8755 | wpa_s->manual_scan_id++; |
| 8756 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", |
| 8757 | wpa_s->manual_scan_id); |
| 8758 | *reply_len = os_snprintf(reply, reply_size, "%u\n", |
| 8759 | wpa_s->manual_scan_id); |
| 8760 | } |
| 8761 | } else if (wpa_s->sched_scanning) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8762 | wpa_s->manual_scan_passive = manual_scan_passive; |
| 8763 | wpa_s->manual_scan_use_id = manual_scan_use_id; |
| 8764 | wpa_s->manual_scan_only_new = manual_scan_only_new; |
| 8765 | wpa_s->scan_id_count = scan_id_count; |
| 8766 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); |
| 8767 | wpa_s->scan_res_handler = scan_res_handler; |
| 8768 | os_free(wpa_s->manual_scan_freqs); |
| 8769 | wpa_s->manual_scan_freqs = manual_scan_freqs; |
| 8770 | manual_scan_freqs = NULL; |
| 8771 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8772 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed"); |
| 8773 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 8774 | wpa_s->scan_req = MANUAL_SCAN_REQ; |
| 8775 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 8776 | if (wpa_s->manual_scan_use_id) { |
| 8777 | wpa_s->manual_scan_id++; |
| 8778 | *reply_len = os_snprintf(reply, reply_size, "%u\n", |
| 8779 | wpa_s->manual_scan_id); |
| 8780 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", |
| 8781 | wpa_s->manual_scan_id); |
| 8782 | } |
| 8783 | } else { |
| 8784 | wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request"); |
| 8785 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); |
| 8786 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8787 | |
| 8788 | done: |
| 8789 | os_free(manual_scan_freqs); |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 8790 | os_free(ssid); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8791 | } |
| 8792 | |
| 8793 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 8794 | #ifdef CONFIG_TESTING_OPTIONS |
| 8795 | |
| 8796 | static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s, |
| 8797 | unsigned int freq, const u8 *dst, |
| 8798 | const u8 *src, const u8 *bssid, |
| 8799 | const u8 *data, size_t data_len, |
| 8800 | enum offchannel_send_action_result |
| 8801 | result) |
| 8802 | { |
| 8803 | wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR |
| 8804 | " src=" MACSTR " bssid=" MACSTR " result=%s", |
| 8805 | freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid), |
| 8806 | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? |
| 8807 | "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? |
| 8808 | "NO_ACK" : "FAILED")); |
| 8809 | } |
| 8810 | |
| 8811 | |
| 8812 | static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd) |
| 8813 | { |
| 8814 | char *pos, *param; |
| 8815 | size_t len; |
| 8816 | u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN]; |
| 8817 | int res, used; |
| 8818 | int freq = 0, no_cck = 0, wait_time = 0; |
| 8819 | |
| 8820 | /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1] |
| 8821 | * <action=Action frame payload> */ |
| 8822 | |
| 8823 | wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd); |
| 8824 | |
| 8825 | pos = cmd; |
| 8826 | used = hwaddr_aton2(pos, da); |
| 8827 | if (used < 0) |
| 8828 | return -1; |
| 8829 | pos += used; |
| 8830 | while (*pos == ' ') |
| 8831 | pos++; |
| 8832 | used = hwaddr_aton2(pos, bssid); |
| 8833 | if (used < 0) |
| 8834 | return -1; |
| 8835 | pos += used; |
| 8836 | |
| 8837 | param = os_strstr(pos, " freq="); |
| 8838 | if (param) { |
| 8839 | param += 6; |
| 8840 | freq = atoi(param); |
| 8841 | } |
| 8842 | |
| 8843 | param = os_strstr(pos, " no_cck="); |
| 8844 | if (param) { |
| 8845 | param += 8; |
| 8846 | no_cck = atoi(param); |
| 8847 | } |
| 8848 | |
| 8849 | param = os_strstr(pos, " wait_time="); |
| 8850 | if (param) { |
| 8851 | param += 11; |
| 8852 | wait_time = atoi(param); |
| 8853 | } |
| 8854 | |
| 8855 | param = os_strstr(pos, " action="); |
| 8856 | if (param == NULL) |
| 8857 | return -1; |
| 8858 | param += 8; |
| 8859 | |
| 8860 | len = os_strlen(param); |
| 8861 | if (len & 1) |
| 8862 | return -1; |
| 8863 | len /= 2; |
| 8864 | |
| 8865 | buf = os_malloc(len); |
| 8866 | if (buf == NULL) |
| 8867 | return -1; |
| 8868 | |
| 8869 | if (hexstr2bin(param, buf, len) < 0) { |
| 8870 | os_free(buf); |
| 8871 | return -1; |
| 8872 | } |
| 8873 | |
| 8874 | res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid, |
| 8875 | buf, len, wait_time, |
| 8876 | wpas_ctrl_iface_mgmt_tx_cb, no_cck); |
| 8877 | os_free(buf); |
| 8878 | return res; |
| 8879 | } |
| 8880 | |
| 8881 | |
| 8882 | static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s) |
| 8883 | { |
| 8884 | wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting"); |
| 8885 | offchannel_send_action_done(wpa_s); |
| 8886 | } |
| 8887 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 8888 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8889 | static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s, |
| 8890 | char *cmd) |
| 8891 | { |
| 8892 | char *pos, *param; |
| 8893 | size_t len; |
| 8894 | u8 *buf; |
| 8895 | int freq = 0, datarate = 0, ssi_signal = 0; |
| 8896 | union wpa_event_data event; |
| 8897 | |
| 8898 | if (!wpa_s->ext_mgmt_frame_handling) |
| 8899 | return -1; |
| 8900 | |
| 8901 | /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */ |
| 8902 | |
| 8903 | wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd); |
| 8904 | |
| 8905 | pos = cmd; |
| 8906 | param = os_strstr(pos, "freq="); |
| 8907 | if (param) { |
| 8908 | param += 5; |
| 8909 | freq = atoi(param); |
| 8910 | } |
| 8911 | |
| 8912 | param = os_strstr(pos, " datarate="); |
| 8913 | if (param) { |
| 8914 | param += 10; |
| 8915 | datarate = atoi(param); |
| 8916 | } |
| 8917 | |
| 8918 | param = os_strstr(pos, " ssi_signal="); |
| 8919 | if (param) { |
| 8920 | param += 12; |
| 8921 | ssi_signal = atoi(param); |
| 8922 | } |
| 8923 | |
| 8924 | param = os_strstr(pos, " frame="); |
| 8925 | if (param == NULL) |
| 8926 | return -1; |
| 8927 | param += 7; |
| 8928 | |
| 8929 | len = os_strlen(param); |
| 8930 | if (len & 1) |
| 8931 | return -1; |
| 8932 | len /= 2; |
| 8933 | |
| 8934 | buf = os_malloc(len); |
| 8935 | if (buf == NULL) |
| 8936 | return -1; |
| 8937 | |
| 8938 | if (hexstr2bin(param, buf, len) < 0) { |
| 8939 | os_free(buf); |
| 8940 | return -1; |
| 8941 | } |
| 8942 | |
| 8943 | os_memset(&event, 0, sizeof(event)); |
| 8944 | event.rx_mgmt.freq = freq; |
| 8945 | event.rx_mgmt.frame = buf; |
| 8946 | event.rx_mgmt.frame_len = len; |
| 8947 | event.rx_mgmt.ssi_signal = ssi_signal; |
| 8948 | event.rx_mgmt.datarate = datarate; |
| 8949 | wpa_s->ext_mgmt_frame_handling = 0; |
| 8950 | wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event); |
| 8951 | wpa_s->ext_mgmt_frame_handling = 1; |
| 8952 | |
| 8953 | os_free(buf); |
| 8954 | |
| 8955 | return 0; |
| 8956 | } |
| 8957 | |
| 8958 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8959 | static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s, |
| 8960 | char *param) |
| 8961 | { |
| 8962 | struct wpa_scan_res *res; |
| 8963 | struct os_reltime now; |
| 8964 | char *pos, *end; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8965 | int ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8966 | |
| 8967 | if (!param) |
| 8968 | return -1; |
| 8969 | |
| 8970 | if (os_strcmp(param, "START") == 0) { |
| 8971 | wpa_bss_update_start(wpa_s); |
| 8972 | return 0; |
| 8973 | } |
| 8974 | |
| 8975 | if (os_strcmp(param, "END") == 0) { |
| 8976 | wpa_bss_update_end(wpa_s, NULL, 1); |
| 8977 | return 0; |
| 8978 | } |
| 8979 | |
| 8980 | if (os_strncmp(param, "BSS ", 4) != 0) |
| 8981 | return -1; |
| 8982 | param += 3; |
| 8983 | |
| 8984 | res = os_zalloc(sizeof(*res) + os_strlen(param) / 2); |
| 8985 | if (!res) |
| 8986 | return -1; |
| 8987 | |
| 8988 | pos = os_strstr(param, " flags="); |
| 8989 | if (pos) |
| 8990 | res->flags = strtol(pos + 7, NULL, 16); |
| 8991 | |
| 8992 | pos = os_strstr(param, " bssid="); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8993 | if (pos && hwaddr_aton(pos + 7, res->bssid)) |
| 8994 | goto fail; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8995 | |
| 8996 | pos = os_strstr(param, " freq="); |
| 8997 | if (pos) |
| 8998 | res->freq = atoi(pos + 6); |
| 8999 | |
| 9000 | pos = os_strstr(param, " beacon_int="); |
| 9001 | if (pos) |
| 9002 | res->beacon_int = atoi(pos + 12); |
| 9003 | |
| 9004 | pos = os_strstr(param, " caps="); |
| 9005 | if (pos) |
| 9006 | res->caps = strtol(pos + 6, NULL, 16); |
| 9007 | |
| 9008 | pos = os_strstr(param, " qual="); |
| 9009 | if (pos) |
| 9010 | res->qual = atoi(pos + 6); |
| 9011 | |
| 9012 | pos = os_strstr(param, " noise="); |
| 9013 | if (pos) |
| 9014 | res->noise = atoi(pos + 7); |
| 9015 | |
| 9016 | pos = os_strstr(param, " level="); |
| 9017 | if (pos) |
| 9018 | res->level = atoi(pos + 7); |
| 9019 | |
| 9020 | pos = os_strstr(param, " tsf="); |
| 9021 | if (pos) |
| 9022 | res->tsf = strtoll(pos + 5, NULL, 16); |
| 9023 | |
| 9024 | pos = os_strstr(param, " age="); |
| 9025 | if (pos) |
| 9026 | res->age = atoi(pos + 5); |
| 9027 | |
| 9028 | pos = os_strstr(param, " est_throughput="); |
| 9029 | if (pos) |
| 9030 | res->est_throughput = atoi(pos + 16); |
| 9031 | |
| 9032 | pos = os_strstr(param, " snr="); |
| 9033 | if (pos) |
| 9034 | res->snr = atoi(pos + 5); |
| 9035 | |
| 9036 | pos = os_strstr(param, " parent_tsf="); |
| 9037 | if (pos) |
| 9038 | res->parent_tsf = strtoll(pos + 7, NULL, 16); |
| 9039 | |
| 9040 | pos = os_strstr(param, " tsf_bssid="); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9041 | if (pos && hwaddr_aton(pos + 11, res->tsf_bssid)) |
| 9042 | goto fail; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9043 | |
| 9044 | pos = os_strstr(param, " ie="); |
| 9045 | if (pos) { |
| 9046 | pos += 4; |
| 9047 | end = os_strchr(pos, ' '); |
| 9048 | if (!end) |
| 9049 | end = pos + os_strlen(pos); |
| 9050 | res->ie_len = (end - pos) / 2; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9051 | if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len)) |
| 9052 | goto fail; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9053 | } |
| 9054 | |
| 9055 | pos = os_strstr(param, " beacon_ie="); |
| 9056 | if (pos) { |
| 9057 | pos += 11; |
| 9058 | end = os_strchr(pos, ' '); |
| 9059 | if (!end) |
| 9060 | end = pos + os_strlen(pos); |
| 9061 | res->beacon_ie_len = (end - pos) / 2; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9062 | if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len, |
| 9063 | res->beacon_ie_len)) |
| 9064 | goto fail; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9065 | } |
| 9066 | |
| 9067 | os_get_reltime(&now); |
| 9068 | wpa_bss_update_scan_res(wpa_s, res, &now); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9069 | ret = 0; |
| 9070 | fail: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9071 | os_free(res); |
| 9072 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9073 | return ret; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9074 | } |
| 9075 | |
| 9076 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 9077 | static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd) |
| 9078 | { |
| 9079 | char *pos, *param; |
| 9080 | union wpa_event_data event; |
| 9081 | enum wpa_event_type ev; |
| 9082 | |
| 9083 | /* <event name> [parameters..] */ |
| 9084 | |
| 9085 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd); |
| 9086 | |
| 9087 | pos = cmd; |
| 9088 | param = os_strchr(pos, ' '); |
| 9089 | if (param) |
| 9090 | *param++ = '\0'; |
| 9091 | |
| 9092 | os_memset(&event, 0, sizeof(event)); |
| 9093 | |
| 9094 | if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) { |
| 9095 | ev = EVENT_INTERFACE_ENABLED; |
| 9096 | } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) { |
| 9097 | ev = EVENT_INTERFACE_DISABLED; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 9098 | } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) { |
| 9099 | ev = EVENT_AVOID_FREQUENCIES; |
| 9100 | if (param == NULL) |
| 9101 | param = ""; |
| 9102 | if (freq_range_list_parse(&event.freq_range, param) < 0) |
| 9103 | return -1; |
| 9104 | wpa_supplicant_event(wpa_s, ev, &event); |
| 9105 | os_free(event.freq_range.range); |
| 9106 | return 0; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9107 | } else if (os_strcmp(cmd, "SCAN_RES") == 0) { |
| 9108 | return wpas_ctrl_iface_driver_scan_res(wpa_s, param); |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 9109 | } else { |
| 9110 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s", |
| 9111 | cmd); |
| 9112 | return -1; |
| 9113 | } |
| 9114 | |
| 9115 | wpa_supplicant_event(wpa_s, ev, &event); |
| 9116 | |
| 9117 | return 0; |
| 9118 | } |
| 9119 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9120 | |
| 9121 | static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd) |
| 9122 | { |
| 9123 | char *pos; |
| 9124 | u8 src[ETH_ALEN], *buf; |
| 9125 | int used; |
| 9126 | size_t len; |
| 9127 | |
| 9128 | wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd); |
| 9129 | |
| 9130 | pos = cmd; |
| 9131 | used = hwaddr_aton2(pos, src); |
| 9132 | if (used < 0) |
| 9133 | return -1; |
| 9134 | pos += used; |
| 9135 | while (*pos == ' ') |
| 9136 | pos++; |
| 9137 | |
| 9138 | len = os_strlen(pos); |
| 9139 | if (len & 1) |
| 9140 | return -1; |
| 9141 | len /= 2; |
| 9142 | |
| 9143 | buf = os_malloc(len); |
| 9144 | if (buf == NULL) |
| 9145 | return -1; |
| 9146 | |
| 9147 | if (hexstr2bin(pos, buf, len) < 0) { |
| 9148 | os_free(buf); |
| 9149 | return -1; |
| 9150 | } |
| 9151 | |
| 9152 | wpa_supplicant_rx_eapol(wpa_s, src, buf, len); |
| 9153 | os_free(buf); |
| 9154 | |
| 9155 | return 0; |
| 9156 | } |
| 9157 | |
| 9158 | |
| 9159 | static u16 ipv4_hdr_checksum(const void *buf, size_t len) |
| 9160 | { |
| 9161 | size_t i; |
| 9162 | u32 sum = 0; |
| 9163 | const u16 *pos = buf; |
| 9164 | |
| 9165 | for (i = 0; i < len / 2; i++) |
| 9166 | sum += *pos++; |
| 9167 | |
| 9168 | while (sum >> 16) |
| 9169 | sum = (sum & 0xffff) + (sum >> 16); |
| 9170 | |
| 9171 | return sum ^ 0xffff; |
| 9172 | } |
| 9173 | |
| 9174 | |
| 9175 | #define HWSIM_PACKETLEN 1500 |
| 9176 | #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header)) |
| 9177 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 9178 | static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, |
| 9179 | size_t len) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9180 | { |
| 9181 | struct wpa_supplicant *wpa_s = ctx; |
| 9182 | const struct ether_header *eth; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9183 | struct ip ip; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9184 | const u8 *pos; |
| 9185 | unsigned int i; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9186 | char extra[30]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9187 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9188 | if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) { |
| 9189 | wpa_printf(MSG_DEBUG, |
| 9190 | "test data: RX - ignore unexpected length %d", |
| 9191 | (int) len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9192 | return; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9193 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9194 | |
| 9195 | eth = (const struct ether_header *) buf; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9196 | os_memcpy(&ip, eth + 1, sizeof(ip)); |
| 9197 | pos = &buf[sizeof(*eth) + sizeof(ip)]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9198 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9199 | if (ip.ip_hl != 5 || ip.ip_v != 4 || ntohs(ip.ip_len) > HWSIM_IP_LEN) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9200 | wpa_printf(MSG_DEBUG, |
| 9201 | "test data: RX - ignore unexpect IP header"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9202 | return; |
Hai Shalom | 39bc25d | 2019-02-06 16:32:13 -0800 | [diff] [blame] | 9203 | } |
Hai Shalom | bf6e0ba | 2019-02-11 12:01:50 -0800 | [diff] [blame] | 9204 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9205 | for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9206 | if (*pos != (u8) i) { |
| 9207 | wpa_printf(MSG_DEBUG, |
| 9208 | "test data: RX - ignore mismatching payload"); |
| 9209 | return; |
| 9210 | } |
| 9211 | pos++; |
| 9212 | } |
| 9213 | extra[0] = '\0'; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9214 | if (ntohs(ip.ip_len) != HWSIM_IP_LEN) |
| 9215 | os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len)); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9216 | wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s", |
| 9217 | MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9218 | } |
| 9219 | |
| 9220 | |
| 9221 | static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s, |
| 9222 | char *cmd) |
| 9223 | { |
| 9224 | int enabled = atoi(cmd); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 9225 | char *pos; |
| 9226 | const char *ifname; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9227 | |
| 9228 | if (!enabled) { |
| 9229 | if (wpa_s->l2_test) { |
| 9230 | l2_packet_deinit(wpa_s->l2_test); |
| 9231 | wpa_s->l2_test = NULL; |
| 9232 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled"); |
| 9233 | } |
| 9234 | return 0; |
| 9235 | } |
| 9236 | |
| 9237 | if (wpa_s->l2_test) |
| 9238 | return 0; |
| 9239 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 9240 | pos = os_strstr(cmd, " ifname="); |
| 9241 | if (pos) |
| 9242 | ifname = pos + 8; |
| 9243 | else |
| 9244 | ifname = wpa_s->ifname; |
| 9245 | |
| 9246 | wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9247 | ETHERTYPE_IP, wpas_data_test_rx, |
| 9248 | wpa_s, 1); |
| 9249 | if (wpa_s->l2_test == NULL) |
| 9250 | return -1; |
| 9251 | |
| 9252 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled"); |
| 9253 | |
| 9254 | return 0; |
| 9255 | } |
| 9256 | |
| 9257 | |
| 9258 | static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd) |
| 9259 | { |
| 9260 | u8 dst[ETH_ALEN], src[ETH_ALEN]; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9261 | char *pos, *pos2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9262 | int used; |
| 9263 | long int val; |
| 9264 | u8 tos; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9265 | u8 buf[2 + HWSIM_PACKETLEN]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9266 | struct ether_header *eth; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9267 | struct ip *ip; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9268 | u8 *dpos; |
| 9269 | unsigned int i; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9270 | size_t send_len = HWSIM_IP_LEN; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9271 | |
| 9272 | if (wpa_s->l2_test == NULL) |
| 9273 | return -1; |
| 9274 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9275 | /* format: <dst> <src> <tos> [len=<length>] */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9276 | |
| 9277 | pos = cmd; |
| 9278 | used = hwaddr_aton2(pos, dst); |
| 9279 | if (used < 0) |
| 9280 | return -1; |
| 9281 | pos += used; |
| 9282 | while (*pos == ' ') |
| 9283 | pos++; |
| 9284 | used = hwaddr_aton2(pos, src); |
| 9285 | if (used < 0) |
| 9286 | return -1; |
| 9287 | pos += used; |
| 9288 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9289 | val = strtol(pos, &pos2, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9290 | if (val < 0 || val > 0xff) |
| 9291 | return -1; |
| 9292 | tos = val; |
| 9293 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9294 | pos = os_strstr(pos2, " len="); |
| 9295 | if (pos) { |
| 9296 | i = atoi(pos + 5); |
| 9297 | if (i < sizeof(*ip) || i > HWSIM_IP_LEN) |
| 9298 | return -1; |
| 9299 | send_len = i; |
| 9300 | } |
| 9301 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9302 | eth = (struct ether_header *) &buf[2]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9303 | os_memcpy(eth->ether_dhost, dst, ETH_ALEN); |
| 9304 | os_memcpy(eth->ether_shost, src, ETH_ALEN); |
| 9305 | eth->ether_type = htons(ETHERTYPE_IP); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9306 | ip = (struct ip *) (eth + 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9307 | os_memset(ip, 0, sizeof(*ip)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9308 | ip->ip_hl = 5; |
| 9309 | ip->ip_v = 4; |
| 9310 | ip->ip_ttl = 64; |
| 9311 | ip->ip_tos = tos; |
| 9312 | ip->ip_len = htons(send_len); |
| 9313 | ip->ip_p = 1; |
| 9314 | ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1); |
| 9315 | ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2); |
| 9316 | ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9317 | dpos = (u8 *) (ip + 1); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9318 | for (i = 0; i < send_len - sizeof(*ip); i++) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9319 | *dpos++ = i; |
| 9320 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9321 | if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2], |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9322 | sizeof(struct ether_header) + send_len) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9323 | return -1; |
| 9324 | |
| 9325 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR |
| 9326 | " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos); |
| 9327 | |
| 9328 | return 0; |
| 9329 | } |
| 9330 | |
| 9331 | |
| 9332 | static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s, |
| 9333 | char *cmd) |
| 9334 | { |
| 9335 | u8 *buf; |
| 9336 | struct ether_header *eth; |
| 9337 | struct l2_packet_data *l2 = NULL; |
| 9338 | size_t len; |
| 9339 | u16 ethertype; |
| 9340 | int res = -1; |
| 9341 | |
| 9342 | len = os_strlen(cmd); |
| 9343 | if (len & 1 || len < ETH_HLEN * 2) |
| 9344 | return -1; |
| 9345 | len /= 2; |
| 9346 | |
| 9347 | buf = os_malloc(len); |
| 9348 | if (buf == NULL) |
| 9349 | return -1; |
| 9350 | |
| 9351 | if (hexstr2bin(cmd, buf, len) < 0) |
| 9352 | goto done; |
| 9353 | |
| 9354 | eth = (struct ether_header *) buf; |
| 9355 | ethertype = ntohs(eth->ether_type); |
| 9356 | |
| 9357 | l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype, |
| 9358 | wpas_data_test_rx, wpa_s, 1); |
| 9359 | if (l2 == NULL) |
| 9360 | goto done; |
| 9361 | |
| 9362 | res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len); |
| 9363 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res); |
| 9364 | done: |
| 9365 | if (l2) |
| 9366 | l2_packet_deinit(l2); |
| 9367 | os_free(buf); |
| 9368 | |
| 9369 | return res < 0 ? -1 : 0; |
| 9370 | } |
| 9371 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9372 | |
| 9373 | static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd) |
| 9374 | { |
| 9375 | #ifdef WPA_TRACE_BFD |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9376 | char *pos; |
| 9377 | |
| 9378 | wpa_trace_fail_after = atoi(cmd); |
| 9379 | pos = os_strchr(cmd, ':'); |
| 9380 | if (pos) { |
| 9381 | pos++; |
| 9382 | os_strlcpy(wpa_trace_fail_func, pos, |
| 9383 | sizeof(wpa_trace_fail_func)); |
| 9384 | } else { |
| 9385 | wpa_trace_fail_after = 0; |
| 9386 | } |
| 9387 | return 0; |
| 9388 | #else /* WPA_TRACE_BFD */ |
| 9389 | return -1; |
| 9390 | #endif /* WPA_TRACE_BFD */ |
| 9391 | } |
| 9392 | |
| 9393 | |
| 9394 | static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s, |
| 9395 | char *buf, size_t buflen) |
| 9396 | { |
| 9397 | #ifdef WPA_TRACE_BFD |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9398 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after, |
| 9399 | wpa_trace_fail_func); |
| 9400 | #else /* WPA_TRACE_BFD */ |
| 9401 | return -1; |
| 9402 | #endif /* WPA_TRACE_BFD */ |
| 9403 | } |
| 9404 | |
Jouni Malinen | c481836 | 2015-10-04 11:45:13 +0300 | [diff] [blame] | 9405 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9406 | static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd) |
| 9407 | { |
| 9408 | #ifdef WPA_TRACE_BFD |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9409 | char *pos; |
| 9410 | |
| 9411 | wpa_trace_test_fail_after = atoi(cmd); |
| 9412 | pos = os_strchr(cmd, ':'); |
| 9413 | if (pos) { |
| 9414 | pos++; |
| 9415 | os_strlcpy(wpa_trace_test_fail_func, pos, |
| 9416 | sizeof(wpa_trace_test_fail_func)); |
| 9417 | } else { |
| 9418 | wpa_trace_test_fail_after = 0; |
| 9419 | } |
| 9420 | return 0; |
| 9421 | #else /* WPA_TRACE_BFD */ |
| 9422 | return -1; |
| 9423 | #endif /* WPA_TRACE_BFD */ |
| 9424 | } |
| 9425 | |
| 9426 | |
| 9427 | static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s, |
| 9428 | char *buf, size_t buflen) |
| 9429 | { |
| 9430 | #ifdef WPA_TRACE_BFD |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9431 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after, |
| 9432 | wpa_trace_test_fail_func); |
| 9433 | #else /* WPA_TRACE_BFD */ |
| 9434 | return -1; |
| 9435 | #endif /* WPA_TRACE_BFD */ |
| 9436 | } |
| 9437 | |
| 9438 | |
Jouni Malinen | c481836 | 2015-10-04 11:45:13 +0300 | [diff] [blame] | 9439 | static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx) |
| 9440 | { |
| 9441 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9442 | int i, count = (intptr_t) timeout_ctx; |
| 9443 | |
| 9444 | wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages", |
| 9445 | count); |
| 9446 | for (i = 0; i < count; i++) { |
| 9447 | wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d", |
| 9448 | i + 1, count); |
| 9449 | } |
| 9450 | } |
| 9451 | |
| 9452 | |
| 9453 | static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd) |
| 9454 | { |
| 9455 | int count; |
| 9456 | |
| 9457 | count = atoi(cmd); |
| 9458 | if (count <= 0) |
| 9459 | return -1; |
| 9460 | |
| 9461 | return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s, |
| 9462 | (void *) (intptr_t) count); |
| 9463 | } |
| 9464 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 9465 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9466 | static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s, |
| 9467 | const char *cmd) |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9468 | { |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9469 | struct wpabuf *buf; |
| 9470 | size_t len; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9471 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9472 | len = os_strlen(cmd); |
| 9473 | if (len & 1) |
| 9474 | return -1; |
| 9475 | len /= 2; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9476 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9477 | if (len == 0) { |
| 9478 | buf = NULL; |
| 9479 | } else { |
| 9480 | buf = wpabuf_alloc(len); |
| 9481 | if (buf == NULL) |
| 9482 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9483 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9484 | if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) { |
| 9485 | wpabuf_free(buf); |
| 9486 | return -1; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9487 | } |
| 9488 | } |
| 9489 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9490 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf); |
| 9491 | return 0; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9492 | } |
| 9493 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9494 | |
| 9495 | static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s) |
| 9496 | { |
| 9497 | u8 zero[WPA_TK_MAX_LEN]; |
| 9498 | |
| 9499 | if (wpa_s->last_tk_alg == WPA_ALG_NONE) |
| 9500 | return -1; |
| 9501 | |
| 9502 | wpa_printf(MSG_INFO, "TESTING: Reset PN"); |
| 9503 | os_memset(zero, 0, sizeof(zero)); |
| 9504 | |
| 9505 | /* First, use a zero key to avoid any possible duplicate key avoidance |
| 9506 | * in the driver. */ |
| 9507 | if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr, |
| 9508 | wpa_s->last_tk_key_idx, 1, zero, 6, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9509 | zero, wpa_s->last_tk_len, |
| 9510 | KEY_FLAG_PAIRWISE_RX_TX) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9511 | return -1; |
| 9512 | |
| 9513 | /* Set the previously configured key to reset its TSC/RSC */ |
| 9514 | return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr, |
| 9515 | wpa_s->last_tk_key_idx, 1, zero, 6, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9516 | wpa_s->last_tk, wpa_s->last_tk_len, |
| 9517 | KEY_FLAG_PAIRWISE_RX_TX); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9518 | } |
| 9519 | |
| 9520 | |
| 9521 | static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd) |
| 9522 | { |
| 9523 | const char *pos = cmd; |
| 9524 | int error, pairwise; |
| 9525 | |
| 9526 | error = atoi(pos); |
| 9527 | pos = os_strchr(pos, ' '); |
| 9528 | if (!pos) |
| 9529 | return -1; |
| 9530 | pairwise = atoi(pos); |
| 9531 | wpa_sm_key_request(wpa_s->wpa, error, pairwise); |
| 9532 | return 0; |
| 9533 | } |
| 9534 | |
| 9535 | |
| 9536 | static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s) |
| 9537 | { |
| 9538 | #ifdef CONFIG_SME |
| 9539 | struct wpa_driver_associate_params params; |
| 9540 | int ret; |
| 9541 | |
| 9542 | os_memset(¶ms, 0, sizeof(params)); |
| 9543 | params.bssid = wpa_s->bssid; |
| 9544 | params.ssid = wpa_s->sme.ssid; |
| 9545 | params.ssid_len = wpa_s->sme.ssid_len; |
| 9546 | params.freq.freq = wpa_s->sme.freq; |
| 9547 | if (wpa_s->last_assoc_req_wpa_ie) { |
| 9548 | params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie); |
| 9549 | params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie); |
| 9550 | } |
| 9551 | params.pairwise_suite = wpa_s->pairwise_cipher; |
| 9552 | params.group_suite = wpa_s->group_cipher; |
| 9553 | params.mgmt_group_suite = wpa_s->mgmt_group_cipher; |
| 9554 | params.key_mgmt_suite = wpa_s->key_mgmt; |
| 9555 | params.wpa_proto = wpa_s->wpa_proto; |
| 9556 | params.mgmt_frame_protection = wpa_s->sme.mfp; |
| 9557 | params.rrm_used = wpa_s->rrm.rrm_used; |
| 9558 | if (wpa_s->sme.prev_bssid_set) |
| 9559 | params.prev_bssid = wpa_s->sme.prev_bssid; |
| 9560 | wpa_printf(MSG_INFO, "TESTING: Resend association request"); |
| 9561 | ret = wpa_drv_associate(wpa_s, ¶ms); |
| 9562 | wpa_s->testing_resend_assoc = 1; |
| 9563 | return ret; |
| 9564 | #else /* CONFIG_SME */ |
| 9565 | return -1; |
| 9566 | #endif /* CONFIG_SME */ |
| 9567 | } |
| 9568 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9569 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9570 | |
| 9571 | |
| 9572 | static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd) |
| 9573 | { |
| 9574 | char *pos = cmd; |
| 9575 | int frame; |
| 9576 | size_t len; |
| 9577 | struct wpabuf *buf; |
| 9578 | struct ieee802_11_elems elems; |
| 9579 | |
| 9580 | frame = atoi(pos); |
| 9581 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) |
| 9582 | return -1; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9583 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9584 | |
| 9585 | pos = os_strchr(pos, ' '); |
| 9586 | if (pos == NULL) |
| 9587 | return -1; |
| 9588 | pos++; |
| 9589 | |
| 9590 | len = os_strlen(pos); |
| 9591 | if (len == 0) |
| 9592 | return 0; |
| 9593 | if (len & 1) |
| 9594 | return -1; |
| 9595 | len /= 2; |
| 9596 | |
| 9597 | buf = wpabuf_alloc(len); |
| 9598 | if (buf == NULL) |
| 9599 | return -1; |
| 9600 | |
| 9601 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { |
| 9602 | wpabuf_free(buf); |
| 9603 | return -1; |
| 9604 | } |
| 9605 | |
| 9606 | if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) == |
| 9607 | ParseFailed) { |
| 9608 | wpabuf_free(buf); |
| 9609 | return -1; |
| 9610 | } |
| 9611 | |
| 9612 | if (wpa_s->vendor_elem[frame] == NULL) { |
| 9613 | wpa_s->vendor_elem[frame] = buf; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9614 | wpas_vendor_elem_update(wpa_s); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9615 | return 0; |
| 9616 | } |
| 9617 | |
| 9618 | if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) { |
| 9619 | wpabuf_free(buf); |
| 9620 | return -1; |
| 9621 | } |
| 9622 | |
| 9623 | wpabuf_put_buf(wpa_s->vendor_elem[frame], buf); |
| 9624 | wpabuf_free(buf); |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9625 | wpas_vendor_elem_update(wpa_s); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9626 | |
| 9627 | return 0; |
| 9628 | } |
| 9629 | |
| 9630 | |
| 9631 | static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd, |
| 9632 | char *buf, size_t buflen) |
| 9633 | { |
| 9634 | int frame = atoi(cmd); |
| 9635 | |
| 9636 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) |
| 9637 | return -1; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9638 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9639 | |
| 9640 | if (wpa_s->vendor_elem[frame] == NULL) |
| 9641 | return 0; |
| 9642 | |
| 9643 | return wpa_snprintf_hex(buf, buflen, |
| 9644 | wpabuf_head_u8(wpa_s->vendor_elem[frame]), |
| 9645 | wpabuf_len(wpa_s->vendor_elem[frame])); |
| 9646 | } |
| 9647 | |
| 9648 | |
| 9649 | static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd) |
| 9650 | { |
| 9651 | char *pos = cmd; |
| 9652 | int frame; |
| 9653 | size_t len; |
| 9654 | u8 *buf; |
| 9655 | struct ieee802_11_elems elems; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9656 | int res; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9657 | |
| 9658 | frame = atoi(pos); |
| 9659 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) |
| 9660 | return -1; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9661 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9662 | |
| 9663 | pos = os_strchr(pos, ' '); |
| 9664 | if (pos == NULL) |
| 9665 | return -1; |
| 9666 | pos++; |
| 9667 | |
| 9668 | if (*pos == '*') { |
| 9669 | wpabuf_free(wpa_s->vendor_elem[frame]); |
| 9670 | wpa_s->vendor_elem[frame] = NULL; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9671 | wpas_vendor_elem_update(wpa_s); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9672 | return 0; |
| 9673 | } |
| 9674 | |
| 9675 | if (wpa_s->vendor_elem[frame] == NULL) |
| 9676 | return -1; |
| 9677 | |
| 9678 | len = os_strlen(pos); |
| 9679 | if (len == 0) |
| 9680 | return 0; |
| 9681 | if (len & 1) |
| 9682 | return -1; |
| 9683 | len /= 2; |
| 9684 | |
| 9685 | buf = os_malloc(len); |
| 9686 | if (buf == NULL) |
| 9687 | return -1; |
| 9688 | |
| 9689 | if (hexstr2bin(pos, buf, len) < 0) { |
| 9690 | os_free(buf); |
| 9691 | return -1; |
| 9692 | } |
| 9693 | |
| 9694 | if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) { |
| 9695 | os_free(buf); |
| 9696 | return -1; |
| 9697 | } |
| 9698 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9699 | res = wpas_vendor_elem_remove(wpa_s, frame, buf, len); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9700 | os_free(buf); |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9701 | return res; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9702 | } |
| 9703 | |
| 9704 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9705 | static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep) |
| 9706 | { |
| 9707 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9708 | size_t len; |
| 9709 | const u8 *data; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9710 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9711 | /* |
| 9712 | * Neighbor Report element (IEEE P802.11-REVmc/D5.0) |
| 9713 | * BSSID[6] |
| 9714 | * BSSID Information[4] |
| 9715 | * Operating Class[1] |
| 9716 | * Channel Number[1] |
| 9717 | * PHY Type[1] |
| 9718 | * Optional Subelements[variable] |
| 9719 | */ |
| 9720 | #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1) |
| 9721 | |
| 9722 | if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9723 | wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9724 | goto out; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9725 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9726 | |
| 9727 | data = wpabuf_head_u8(neighbor_rep); |
| 9728 | len = wpabuf_len(neighbor_rep); |
| 9729 | |
| 9730 | while (len >= 2 + NR_IE_MIN_LEN) { |
| 9731 | const u8 *nr; |
| 9732 | char lci[256 * 2 + 1]; |
| 9733 | char civic[256 * 2 + 1]; |
| 9734 | u8 nr_len = data[1]; |
| 9735 | const u8 *pos = data, *end; |
| 9736 | |
| 9737 | if (pos[0] != WLAN_EID_NEIGHBOR_REPORT || |
| 9738 | nr_len < NR_IE_MIN_LEN) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9739 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9740 | "CTRL: Invalid Neighbor Report element: id=%u len=%u", |
| 9741 | data[0], nr_len); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9742 | goto out; |
| 9743 | } |
| 9744 | |
| 9745 | if (2U + nr_len > len) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9746 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9747 | "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u", |
| 9748 | data[0], len, nr_len); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9749 | goto out; |
| 9750 | } |
| 9751 | pos += 2; |
| 9752 | end = pos + nr_len; |
| 9753 | |
| 9754 | nr = pos; |
| 9755 | pos += NR_IE_MIN_LEN; |
| 9756 | |
| 9757 | lci[0] = '\0'; |
| 9758 | civic[0] = '\0'; |
| 9759 | while (end - pos > 2) { |
| 9760 | u8 s_id, s_len; |
| 9761 | |
| 9762 | s_id = *pos++; |
| 9763 | s_len = *pos++; |
| 9764 | if (s_len > end - pos) |
| 9765 | goto out; |
| 9766 | if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) { |
| 9767 | /* Measurement Token[1] */ |
| 9768 | /* Measurement Report Mode[1] */ |
| 9769 | /* Measurement Type[1] */ |
| 9770 | /* Measurement Report[variable] */ |
| 9771 | switch (pos[2]) { |
| 9772 | case MEASURE_TYPE_LCI: |
| 9773 | if (lci[0]) |
| 9774 | break; |
| 9775 | wpa_snprintf_hex(lci, sizeof(lci), |
| 9776 | pos, s_len); |
| 9777 | break; |
| 9778 | case MEASURE_TYPE_LOCATION_CIVIC: |
| 9779 | if (civic[0]) |
| 9780 | break; |
| 9781 | wpa_snprintf_hex(civic, sizeof(civic), |
| 9782 | pos, s_len); |
| 9783 | break; |
| 9784 | } |
| 9785 | } |
| 9786 | |
| 9787 | pos += s_len; |
| 9788 | } |
| 9789 | |
| 9790 | wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED |
| 9791 | "bssid=" MACSTR |
| 9792 | " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s", |
| 9793 | MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN), |
| 9794 | nr[ETH_ALEN + 4], nr[ETH_ALEN + 5], |
| 9795 | nr[ETH_ALEN + 6], |
| 9796 | lci[0] ? " lci=" : "", lci, |
| 9797 | civic[0] ? " civic=" : "", civic); |
| 9798 | |
| 9799 | data = end; |
| 9800 | len -= 2 + nr_len; |
| 9801 | } |
| 9802 | |
| 9803 | out: |
| 9804 | wpabuf_free(neighbor_rep); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9805 | } |
| 9806 | |
| 9807 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9808 | static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s, |
| 9809 | char *cmd) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9810 | { |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9811 | struct wpa_ssid_value ssid, *ssid_p = NULL; |
| 9812 | int ret, lci = 0, civic = 0; |
| 9813 | char *ssid_s; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9814 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9815 | ssid_s = os_strstr(cmd, "ssid="); |
| 9816 | if (ssid_s) { |
| 9817 | if (ssid_parse(ssid_s + 5, &ssid)) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9818 | wpa_msg(wpa_s, MSG_INFO, |
| 9819 | "CTRL: Send Neighbor Report: bad SSID"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9820 | return -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9821 | } |
| 9822 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9823 | ssid_p = &ssid; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9824 | |
| 9825 | /* |
| 9826 | * Move cmd after the SSID text that may include "lci" or |
| 9827 | * "civic". |
| 9828 | */ |
| 9829 | cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' '); |
| 9830 | if (cmd) |
| 9831 | cmd++; |
| 9832 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9833 | } |
| 9834 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9835 | if (cmd && os_strstr(cmd, "lci")) |
| 9836 | lci = 1; |
| 9837 | |
| 9838 | if (cmd && os_strstr(cmd, "civic")) |
| 9839 | civic = 1; |
| 9840 | |
| 9841 | ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9842 | wpas_ctrl_neighbor_rep_cb, |
| 9843 | wpa_s); |
| 9844 | |
| 9845 | return ret; |
| 9846 | } |
| 9847 | |
| 9848 | |
| 9849 | static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s) |
| 9850 | { |
| 9851 | eapol_sm_erp_flush(wpa_s->eapol); |
| 9852 | return 0; |
| 9853 | } |
| 9854 | |
| 9855 | |
| 9856 | static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s, |
| 9857 | char *cmd) |
| 9858 | { |
| 9859 | char *token, *context = NULL; |
| 9860 | unsigned int enable = ~0, type = 0; |
| 9861 | u8 _addr[ETH_ALEN], _mask[ETH_ALEN]; |
| 9862 | u8 *addr = NULL, *mask = NULL; |
| 9863 | |
| 9864 | while ((token = str_token(cmd, " ", &context))) { |
| 9865 | if (os_strcasecmp(token, "scan") == 0) { |
| 9866 | type |= MAC_ADDR_RAND_SCAN; |
| 9867 | } else if (os_strcasecmp(token, "sched") == 0) { |
| 9868 | type |= MAC_ADDR_RAND_SCHED_SCAN; |
| 9869 | } else if (os_strcasecmp(token, "pno") == 0) { |
| 9870 | type |= MAC_ADDR_RAND_PNO; |
| 9871 | } else if (os_strcasecmp(token, "all") == 0) { |
| 9872 | type = wpa_s->mac_addr_rand_supported; |
| 9873 | } else if (os_strncasecmp(token, "enable=", 7) == 0) { |
| 9874 | enable = atoi(token + 7); |
| 9875 | } else if (os_strncasecmp(token, "addr=", 5) == 0) { |
| 9876 | addr = _addr; |
| 9877 | if (hwaddr_aton(token + 5, addr)) { |
| 9878 | wpa_printf(MSG_INFO, |
| 9879 | "CTRL: Invalid MAC address: %s", |
| 9880 | token); |
| 9881 | return -1; |
| 9882 | } |
| 9883 | } else if (os_strncasecmp(token, "mask=", 5) == 0) { |
| 9884 | mask = _mask; |
| 9885 | if (hwaddr_aton(token + 5, mask)) { |
| 9886 | wpa_printf(MSG_INFO, |
| 9887 | "CTRL: Invalid MAC address mask: %s", |
| 9888 | token); |
| 9889 | return -1; |
| 9890 | } |
| 9891 | } else { |
| 9892 | wpa_printf(MSG_INFO, |
| 9893 | "CTRL: Invalid MAC_RAND_SCAN parameter: %s", |
| 9894 | token); |
| 9895 | return -1; |
| 9896 | } |
| 9897 | } |
| 9898 | |
| 9899 | if (!type) { |
| 9900 | wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified"); |
| 9901 | return -1; |
| 9902 | } |
| 9903 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9904 | if (enable > 1) { |
| 9905 | wpa_printf(MSG_INFO, |
| 9906 | "CTRL: MAC_RAND_SCAN enable=<0/1> not specified"); |
| 9907 | return -1; |
| 9908 | } |
| 9909 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9910 | if (!enable) |
| 9911 | return wpas_disable_mac_addr_randomization(wpa_s, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9912 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9913 | return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9914 | } |
| 9915 | |
| 9916 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 9917 | static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s, |
| 9918 | char *buf, size_t buflen) |
| 9919 | { |
| 9920 | size_t reply_len; |
| 9921 | |
| 9922 | reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen); |
| 9923 | #ifdef CONFIG_AP |
| 9924 | reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len], |
| 9925 | buflen - reply_len); |
| 9926 | #endif /* CONFIG_AP */ |
| 9927 | return reply_len; |
| 9928 | } |
| 9929 | |
| 9930 | |
| 9931 | static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s) |
| 9932 | { |
| 9933 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
| 9934 | #ifdef CONFIG_AP |
| 9935 | wpas_ap_pmksa_cache_flush(wpa_s); |
| 9936 | #endif /* CONFIG_AP */ |
| 9937 | } |
| 9938 | |
| 9939 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 9940 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
| 9941 | |
| 9942 | static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s, |
| 9943 | const char *cmd, char *buf, size_t buflen) |
| 9944 | { |
| 9945 | struct rsn_pmksa_cache_entry *entry; |
| 9946 | struct wpa_ssid *ssid; |
| 9947 | char *pos, *pos2, *end; |
| 9948 | int ret; |
| 9949 | struct os_reltime now; |
| 9950 | |
| 9951 | ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd)); |
| 9952 | if (!ssid) |
| 9953 | return -1; |
| 9954 | |
| 9955 | pos = buf; |
| 9956 | end = buf + buflen; |
| 9957 | |
| 9958 | os_get_reltime(&now); |
| 9959 | |
| 9960 | /* |
| 9961 | * Entry format: |
| 9962 | * <BSSID> <PMKID> <PMK> <reauth_time in seconds> |
| 9963 | * <expiration in seconds> <akmp> <opportunistic> |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9964 | * [FILS Cache Identifier] |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 9965 | */ |
| 9966 | |
| 9967 | for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry; |
| 9968 | entry = entry->next) { |
| 9969 | if (entry->network_ctx != ssid) |
| 9970 | continue; |
| 9971 | |
| 9972 | pos2 = pos; |
| 9973 | ret = os_snprintf(pos2, end - pos2, MACSTR " ", |
| 9974 | MAC2STR(entry->aa)); |
| 9975 | if (os_snprintf_error(end - pos2, ret)) |
| 9976 | break; |
| 9977 | pos2 += ret; |
| 9978 | |
| 9979 | pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid, |
| 9980 | PMKID_LEN); |
| 9981 | |
| 9982 | ret = os_snprintf(pos2, end - pos2, " "); |
| 9983 | if (os_snprintf_error(end - pos2, ret)) |
| 9984 | break; |
| 9985 | pos2 += ret; |
| 9986 | |
| 9987 | pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk, |
| 9988 | entry->pmk_len); |
| 9989 | |
| 9990 | ret = os_snprintf(pos2, end - pos2, " %d %d %d %d", |
| 9991 | (int) (entry->reauth_time - now.sec), |
| 9992 | (int) (entry->expiration - now.sec), |
| 9993 | entry->akmp, |
| 9994 | entry->opportunistic); |
| 9995 | if (os_snprintf_error(end - pos2, ret)) |
| 9996 | break; |
| 9997 | pos2 += ret; |
| 9998 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9999 | if (entry->fils_cache_id_set) { |
| 10000 | ret = os_snprintf(pos2, end - pos2, " %02x%02x", |
| 10001 | entry->fils_cache_id[0], |
| 10002 | entry->fils_cache_id[1]); |
| 10003 | if (os_snprintf_error(end - pos2, ret)) |
| 10004 | break; |
| 10005 | pos2 += ret; |
| 10006 | } |
| 10007 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10008 | ret = os_snprintf(pos2, end - pos2, "\n"); |
| 10009 | if (os_snprintf_error(end - pos2, ret)) |
| 10010 | break; |
| 10011 | pos2 += ret; |
| 10012 | |
| 10013 | pos = pos2; |
| 10014 | } |
| 10015 | |
| 10016 | return pos - buf; |
| 10017 | } |
| 10018 | |
| 10019 | |
| 10020 | static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s, |
| 10021 | char *cmd) |
| 10022 | { |
| 10023 | struct rsn_pmksa_cache_entry *entry; |
| 10024 | struct wpa_ssid *ssid; |
| 10025 | char *pos, *pos2; |
| 10026 | int ret = -1; |
| 10027 | struct os_reltime now; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10028 | int reauth_time = 0, expiration = 0, i; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10029 | |
| 10030 | /* |
| 10031 | * Entry format: |
| 10032 | * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds> |
| 10033 | * <expiration in seconds> <akmp> <opportunistic> |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10034 | * [FILS Cache Identifier] |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10035 | */ |
| 10036 | |
| 10037 | ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd)); |
| 10038 | if (!ssid) |
| 10039 | return -1; |
| 10040 | |
| 10041 | pos = os_strchr(cmd, ' '); |
| 10042 | if (!pos) |
| 10043 | return -1; |
| 10044 | pos++; |
| 10045 | |
| 10046 | entry = os_zalloc(sizeof(*entry)); |
| 10047 | if (!entry) |
| 10048 | return -1; |
| 10049 | |
| 10050 | if (hwaddr_aton(pos, entry->aa)) |
| 10051 | goto fail; |
| 10052 | |
| 10053 | pos = os_strchr(pos, ' '); |
| 10054 | if (!pos) |
| 10055 | goto fail; |
| 10056 | pos++; |
| 10057 | |
| 10058 | if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0) |
| 10059 | goto fail; |
| 10060 | |
| 10061 | pos = os_strchr(pos, ' '); |
| 10062 | if (!pos) |
| 10063 | goto fail; |
| 10064 | pos++; |
| 10065 | |
| 10066 | pos2 = os_strchr(pos, ' '); |
| 10067 | if (!pos2) |
| 10068 | goto fail; |
| 10069 | entry->pmk_len = (pos2 - pos) / 2; |
| 10070 | if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX || |
| 10071 | hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0) |
| 10072 | goto fail; |
| 10073 | |
| 10074 | pos = os_strchr(pos, ' '); |
| 10075 | if (!pos) |
| 10076 | goto fail; |
| 10077 | pos++; |
| 10078 | |
| 10079 | if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration, |
| 10080 | &entry->akmp, &entry->opportunistic) != 4) |
| 10081 | goto fail; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10082 | for (i = 0; i < 4; i++) { |
| 10083 | pos = os_strchr(pos, ' '); |
| 10084 | if (!pos) { |
| 10085 | if (i < 3) |
| 10086 | goto fail; |
| 10087 | break; |
| 10088 | } |
| 10089 | pos++; |
| 10090 | } |
| 10091 | if (pos) { |
| 10092 | if (hexstr2bin(pos, entry->fils_cache_id, |
| 10093 | FILS_CACHE_ID_LEN) < 0) |
| 10094 | goto fail; |
| 10095 | entry->fils_cache_id_set = 1; |
| 10096 | } |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10097 | os_get_reltime(&now); |
| 10098 | entry->expiration = now.sec + expiration; |
| 10099 | entry->reauth_time = now.sec + reauth_time; |
| 10100 | |
| 10101 | entry->network_ctx = ssid; |
| 10102 | |
| 10103 | wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry); |
| 10104 | entry = NULL; |
| 10105 | ret = 0; |
| 10106 | fail: |
| 10107 | os_free(entry); |
| 10108 | return ret; |
| 10109 | } |
| 10110 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10111 | |
| 10112 | #ifdef CONFIG_MESH |
| 10113 | |
| 10114 | static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s, |
| 10115 | const char *cmd, char *buf, |
| 10116 | size_t buflen) |
| 10117 | { |
| 10118 | u8 spa[ETH_ALEN]; |
| 10119 | |
| 10120 | if (!wpa_s->ifmsh) |
| 10121 | return -1; |
| 10122 | |
| 10123 | if (os_strcasecmp(cmd, "any") == 0) |
| 10124 | return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen); |
| 10125 | |
| 10126 | if (hwaddr_aton(cmd, spa)) |
| 10127 | return -1; |
| 10128 | |
| 10129 | return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen); |
| 10130 | } |
| 10131 | |
| 10132 | |
| 10133 | static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s, |
| 10134 | char *cmd) |
| 10135 | { |
| 10136 | /* |
| 10137 | * We do not check mesh interface existance because PMKSA should be |
| 10138 | * stored before wpa_s->ifmsh creation to suppress commit message |
| 10139 | * creation. |
| 10140 | */ |
| 10141 | return wpas_ap_pmksa_cache_add_external(wpa_s, cmd); |
| 10142 | } |
| 10143 | |
| 10144 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10145 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
| 10146 | |
| 10147 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10148 | #ifdef CONFIG_FILS |
| 10149 | static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s, |
| 10150 | const char *cmd) |
| 10151 | { |
| 10152 | struct fils_hlp_req *req; |
| 10153 | const char *pos; |
| 10154 | |
| 10155 | /* format: <dst> <packet starting from ethertype> */ |
| 10156 | |
| 10157 | req = os_zalloc(sizeof(*req)); |
| 10158 | if (!req) |
| 10159 | return -1; |
| 10160 | |
| 10161 | if (hwaddr_aton(cmd, req->dst)) |
| 10162 | goto fail; |
| 10163 | |
| 10164 | pos = os_strchr(cmd, ' '); |
| 10165 | if (!pos) |
| 10166 | goto fail; |
| 10167 | pos++; |
| 10168 | req->pkt = wpabuf_parse_bin(pos); |
| 10169 | if (!req->pkt) |
| 10170 | goto fail; |
| 10171 | |
| 10172 | dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list); |
| 10173 | return 0; |
| 10174 | fail: |
| 10175 | wpabuf_free(req->pkt); |
| 10176 | os_free(req); |
| 10177 | return -1; |
| 10178 | } |
| 10179 | #endif /* CONFIG_FILS */ |
| 10180 | |
| 10181 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10182 | static int wpas_ctrl_cmd_debug_level(const char *cmd) |
| 10183 | { |
| 10184 | if (os_strcmp(cmd, "PING") == 0 || |
| 10185 | os_strncmp(cmd, "BSS ", 4) == 0 || |
| 10186 | os_strncmp(cmd, "GET_NETWORK ", 12) == 0 || |
| 10187 | os_strncmp(cmd, "STATUS", 6) == 0 || |
| 10188 | os_strncmp(cmd, "STA ", 4) == 0 || |
| 10189 | os_strncmp(cmd, "STA-", 4) == 0) |
| 10190 | return MSG_EXCESSIVE; |
| 10191 | return MSG_DEBUG; |
| 10192 | } |
| 10193 | |
| 10194 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10195 | char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, |
| 10196 | char *buf, size_t *resp_len) |
| 10197 | { |
| 10198 | char *reply; |
| 10199 | const int reply_size = 4096; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10200 | int reply_len; |
| 10201 | |
| 10202 | if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10203 | os_strncmp(buf, "SET_NETWORK ", 12) == 0 || |
| 10204 | os_strncmp(buf, "PMKSA_ADD ", 10) == 0 || |
| 10205 | os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10206 | if (wpa_debug_show_keys) |
| 10207 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10208 | "Control interface command '%s'", buf); |
| 10209 | else |
| 10210 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10211 | "Control interface command '%s [REMOVED]'", |
| 10212 | os_strncmp(buf, WPA_CTRL_RSP, |
| 10213 | os_strlen(WPA_CTRL_RSP)) == 0 ? |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10214 | WPA_CTRL_RSP : |
| 10215 | (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ? |
| 10216 | "SET_NETWORK" : "key-add")); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10217 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 || |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 10218 | os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10219 | wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", |
| 10220 | (const u8 *) buf, os_strlen(buf)); |
| 10221 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10222 | int level = wpas_ctrl_cmd_debug_level(buf); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 10223 | wpa_dbg(wpa_s, level, "Control interface command '%s'", buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10224 | } |
| 10225 | |
| 10226 | reply = os_malloc(reply_size); |
| 10227 | if (reply == NULL) { |
| 10228 | *resp_len = 1; |
| 10229 | return NULL; |
| 10230 | } |
| 10231 | |
| 10232 | os_memcpy(reply, "OK\n", 3); |
| 10233 | reply_len = 3; |
| 10234 | |
| 10235 | if (os_strcmp(buf, "PING") == 0) { |
| 10236 | os_memcpy(reply, "PONG\n", 5); |
| 10237 | reply_len = 5; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10238 | } else if (os_strcmp(buf, "IFNAME") == 0) { |
| 10239 | reply_len = os_strlen(wpa_s->ifname); |
| 10240 | os_memcpy(reply, wpa_s->ifname, reply_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10241 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
| 10242 | if (wpa_debug_reopen_file() < 0) |
| 10243 | reply_len = -1; |
| 10244 | } else if (os_strncmp(buf, "NOTE ", 5) == 0) { |
| 10245 | wpa_printf(MSG_INFO, "NOTE: %s", buf + 5); |
| 10246 | } else if (os_strcmp(buf, "MIB") == 0) { |
| 10247 | reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); |
| 10248 | if (reply_len >= 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10249 | reply_len += eapol_sm_get_mib(wpa_s->eapol, |
| 10250 | reply + reply_len, |
| 10251 | reply_size - reply_len); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 10252 | #ifdef CONFIG_MACSEC |
| 10253 | reply_len += ieee802_1x_kay_get_mib( |
| 10254 | wpa_s->kay, reply + reply_len, |
| 10255 | reply_size - reply_len); |
| 10256 | #endif /* CONFIG_MACSEC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10257 | } |
| 10258 | } else if (os_strncmp(buf, "STATUS", 6) == 0) { |
| 10259 | reply_len = wpa_supplicant_ctrl_iface_status( |
| 10260 | wpa_s, buf + 6, reply, reply_size); |
| 10261 | } else if (os_strcmp(buf, "PMKSA") == 0) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 10262 | reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10263 | } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 10264 | wpas_ctrl_iface_pmksa_flush(wpa_s); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10265 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
| 10266 | } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) { |
| 10267 | reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10, |
| 10268 | reply, reply_size); |
| 10269 | } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) { |
| 10270 | if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0) |
| 10271 | reply_len = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10272 | #ifdef CONFIG_MESH |
| 10273 | } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) { |
| 10274 | reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15, |
| 10275 | reply, reply_size); |
| 10276 | } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) { |
| 10277 | if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0) |
| 10278 | reply_len = -1; |
| 10279 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10280 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10281 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
| 10282 | if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) |
| 10283 | reply_len = -1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10284 | } else if (os_strncmp(buf, "DUMP", 4) == 0) { |
| 10285 | reply_len = wpa_config_dump_values(wpa_s->conf, |
| 10286 | reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10287 | } else if (os_strncmp(buf, "GET ", 4) == 0) { |
| 10288 | reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4, |
| 10289 | reply, reply_size); |
| 10290 | } else if (os_strcmp(buf, "LOGON") == 0) { |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 10291 | eapol_sm_notify_logoff(wpa_s->eapol, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10292 | } else if (os_strcmp(buf, "LOGOFF") == 0) { |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 10293 | eapol_sm_notify_logoff(wpa_s->eapol, true); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10294 | } else if (os_strcmp(buf, "REASSOCIATE") == 0) { |
| 10295 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 10296 | reply_len = -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 10297 | else |
| 10298 | wpas_request_connection(wpa_s); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 10299 | } else if (os_strcmp(buf, "REATTACH") == 0) { |
| 10300 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED || |
| 10301 | !wpa_s->current_ssid) |
| 10302 | reply_len = -1; |
| 10303 | else { |
| 10304 | wpa_s->reattach = 1; |
| 10305 | wpas_request_connection(wpa_s); |
| 10306 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10307 | } else if (os_strcmp(buf, "RECONNECT") == 0) { |
| 10308 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 10309 | reply_len = -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 10310 | else if (wpa_s->disconnected) |
| 10311 | wpas_request_connection(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10312 | #ifdef IEEE8021X_EAPOL |
| 10313 | } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { |
| 10314 | if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) |
| 10315 | reply_len = -1; |
| 10316 | #endif /* IEEE8021X_EAPOL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10317 | #ifdef CONFIG_IEEE80211R |
| 10318 | } else if (os_strncmp(buf, "FT_DS ", 6) == 0) { |
| 10319 | if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6)) |
| 10320 | reply_len = -1; |
| 10321 | #endif /* CONFIG_IEEE80211R */ |
| 10322 | #ifdef CONFIG_WPS |
| 10323 | } else if (os_strcmp(buf, "WPS_PBC") == 0) { |
| 10324 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL); |
| 10325 | if (res == -2) { |
| 10326 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); |
| 10327 | reply_len = 17; |
| 10328 | } else if (res) |
| 10329 | reply_len = -1; |
| 10330 | } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) { |
| 10331 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8); |
| 10332 | if (res == -2) { |
| 10333 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); |
| 10334 | reply_len = 17; |
| 10335 | } else if (res) |
| 10336 | reply_len = -1; |
| 10337 | } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) { |
| 10338 | reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8, |
| 10339 | reply, |
| 10340 | reply_size); |
| 10341 | } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) { |
| 10342 | reply_len = wpa_supplicant_ctrl_iface_wps_check_pin( |
| 10343 | wpa_s, buf + 14, reply, reply_size); |
| 10344 | } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { |
| 10345 | if (wpas_wps_cancel(wpa_s)) |
| 10346 | reply_len = -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10347 | #ifdef CONFIG_WPS_NFC |
| 10348 | } else if (os_strcmp(buf, "WPS_NFC") == 0) { |
| 10349 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL)) |
| 10350 | reply_len = -1; |
| 10351 | } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) { |
| 10352 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8)) |
| 10353 | reply_len = -1; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 10354 | } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) { |
| 10355 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token( |
| 10356 | wpa_s, buf + 21, reply, reply_size); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10357 | } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) { |
| 10358 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token( |
| 10359 | wpa_s, buf + 14, reply, reply_size); |
| 10360 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) { |
| 10361 | if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s, |
| 10362 | buf + 17)) |
| 10363 | reply_len = -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 10364 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) { |
| 10365 | reply_len = wpas_ctrl_nfc_get_handover_req( |
| 10366 | wpa_s, buf + 21, reply, reply_size); |
| 10367 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) { |
| 10368 | reply_len = wpas_ctrl_nfc_get_handover_sel( |
| 10369 | wpa_s, buf + 21, reply, reply_size); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 10370 | } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) { |
| 10371 | if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20)) |
| 10372 | reply_len = -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10373 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10374 | } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) { |
| 10375 | if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8)) |
| 10376 | reply_len = -1; |
| 10377 | #ifdef CONFIG_AP |
| 10378 | } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) { |
| 10379 | reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin( |
| 10380 | wpa_s, buf + 11, reply, reply_size); |
| 10381 | #endif /* CONFIG_AP */ |
| 10382 | #ifdef CONFIG_WPS_ER |
| 10383 | } else if (os_strcmp(buf, "WPS_ER_START") == 0) { |
| 10384 | if (wpas_wps_er_start(wpa_s, NULL)) |
| 10385 | reply_len = -1; |
| 10386 | } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) { |
| 10387 | if (wpas_wps_er_start(wpa_s, buf + 13)) |
| 10388 | reply_len = -1; |
| 10389 | } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10390 | wpas_wps_er_stop(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10391 | } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) { |
| 10392 | if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11)) |
| 10393 | reply_len = -1; |
| 10394 | } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) { |
| 10395 | int ret = wpas_wps_er_pbc(wpa_s, buf + 11); |
| 10396 | if (ret == -2) { |
| 10397 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); |
| 10398 | reply_len = 17; |
| 10399 | } else if (ret == -3) { |
| 10400 | os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18); |
| 10401 | reply_len = 18; |
| 10402 | } else if (ret == -4) { |
| 10403 | os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20); |
| 10404 | reply_len = 20; |
| 10405 | } else if (ret) |
| 10406 | reply_len = -1; |
| 10407 | } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) { |
| 10408 | if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13)) |
| 10409 | reply_len = -1; |
| 10410 | } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) { |
| 10411 | if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s, |
| 10412 | buf + 18)) |
| 10413 | reply_len = -1; |
| 10414 | } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) { |
| 10415 | if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14)) |
| 10416 | reply_len = -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10417 | #ifdef CONFIG_WPS_NFC |
| 10418 | } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) { |
| 10419 | reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( |
| 10420 | wpa_s, buf + 24, reply, reply_size); |
| 10421 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10422 | #endif /* CONFIG_WPS_ER */ |
| 10423 | #endif /* CONFIG_WPS */ |
| 10424 | #ifdef CONFIG_IBSS_RSN |
| 10425 | } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) { |
| 10426 | if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) |
| 10427 | reply_len = -1; |
| 10428 | #endif /* CONFIG_IBSS_RSN */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10429 | #ifdef CONFIG_MESH |
| 10430 | } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) { |
| 10431 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( |
| 10432 | wpa_s, buf + 19, reply, reply_size); |
| 10433 | } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) { |
| 10434 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( |
| 10435 | wpa_s, "", reply, reply_size); |
| 10436 | } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) { |
| 10437 | if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15)) |
| 10438 | reply_len = -1; |
| 10439 | } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) { |
| 10440 | if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s, |
| 10441 | buf + 18)) |
| 10442 | reply_len = -1; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 10443 | } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) { |
| 10444 | if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17)) |
| 10445 | reply_len = -1; |
| 10446 | } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) { |
| 10447 | if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14)) |
| 10448 | reply_len = -1; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10449 | } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) { |
| 10450 | if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16)) |
| 10451 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10452 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10453 | #ifdef CONFIG_P2P |
| 10454 | } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 10455 | if (p2p_ctrl_find(wpa_s, buf + 8)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10456 | reply_len = -1; |
| 10457 | } else if (os_strcmp(buf, "P2P_FIND") == 0) { |
| 10458 | if (p2p_ctrl_find(wpa_s, "")) |
| 10459 | reply_len = -1; |
| 10460 | } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) { |
| 10461 | wpas_p2p_stop_find(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 10462 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) { |
| 10463 | if (p2p_ctrl_asp_provision(wpa_s, buf + 18)) |
| 10464 | reply_len = -1; |
| 10465 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) { |
| 10466 | if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23)) |
| 10467 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10468 | } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) { |
| 10469 | reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply, |
| 10470 | reply_size); |
| 10471 | } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) { |
| 10472 | if (p2p_ctrl_listen(wpa_s, buf + 11)) |
| 10473 | reply_len = -1; |
| 10474 | } else if (os_strcmp(buf, "P2P_LISTEN") == 0) { |
| 10475 | if (p2p_ctrl_listen(wpa_s, "")) |
| 10476 | reply_len = -1; |
| 10477 | } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) { |
| 10478 | if (wpas_p2p_group_remove(wpa_s, buf + 17)) |
| 10479 | reply_len = -1; |
| 10480 | } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 10481 | if (p2p_ctrl_group_add(wpa_s, "")) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10482 | reply_len = -1; |
| 10483 | } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) { |
| 10484 | if (p2p_ctrl_group_add(wpa_s, buf + 14)) |
| 10485 | reply_len = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10486 | } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) { |
| 10487 | reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply, |
| 10488 | reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10489 | } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) { |
| 10490 | if (p2p_ctrl_prov_disc(wpa_s, buf + 14)) |
| 10491 | reply_len = -1; |
| 10492 | } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) { |
| 10493 | reply_len = p2p_get_passphrase(wpa_s, reply, reply_size); |
| 10494 | } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) { |
| 10495 | reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply, |
| 10496 | reply_size); |
| 10497 | } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) { |
| 10498 | if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0) |
| 10499 | reply_len = -1; |
| 10500 | } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) { |
| 10501 | if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0) |
| 10502 | reply_len = -1; |
| 10503 | } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) { |
| 10504 | wpas_p2p_sd_service_update(wpa_s); |
| 10505 | } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) { |
| 10506 | if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0) |
| 10507 | reply_len = -1; |
| 10508 | } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) { |
| 10509 | wpas_p2p_service_flush(wpa_s); |
| 10510 | } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) { |
| 10511 | if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0) |
| 10512 | reply_len = -1; |
| 10513 | } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) { |
| 10514 | if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0) |
| 10515 | reply_len = -1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 10516 | } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) { |
| 10517 | if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0) |
| 10518 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10519 | } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) { |
| 10520 | if (p2p_ctrl_reject(wpa_s, buf + 11) < 0) |
| 10521 | reply_len = -1; |
| 10522 | } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) { |
| 10523 | if (p2p_ctrl_invite(wpa_s, buf + 11) < 0) |
| 10524 | reply_len = -1; |
| 10525 | } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) { |
| 10526 | reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply, |
| 10527 | reply_size); |
| 10528 | } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) { |
| 10529 | if (p2p_ctrl_set(wpa_s, buf + 8) < 0) |
| 10530 | reply_len = -1; |
| 10531 | } else if (os_strcmp(buf, "P2P_FLUSH") == 0) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 10532 | p2p_ctrl_flush(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10533 | } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { |
| 10534 | if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) |
| 10535 | reply_len = -1; |
| 10536 | } else if (os_strcmp(buf, "P2P_CANCEL") == 0) { |
| 10537 | if (wpas_p2p_cancel(wpa_s)) |
| 10538 | reply_len = -1; |
| 10539 | } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) { |
| 10540 | if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0) |
| 10541 | reply_len = -1; |
| 10542 | } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) { |
| 10543 | if (p2p_ctrl_presence_req(wpa_s, "") < 0) |
| 10544 | reply_len = -1; |
| 10545 | } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) { |
| 10546 | if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0) |
| 10547 | reply_len = -1; |
| 10548 | } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) { |
| 10549 | if (p2p_ctrl_ext_listen(wpa_s, "") < 0) |
| 10550 | reply_len = -1; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 10551 | } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) { |
| 10552 | if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0) |
| 10553 | reply_len = -1; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10554 | } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) { |
| 10555 | if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13)) |
| 10556 | reply_len = -1; |
| 10557 | } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) { |
| 10558 | if (wpas_p2p_lo_stop(wpa_s)) |
| 10559 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10560 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10561 | #ifdef CONFIG_WIFI_DISPLAY |
| 10562 | } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) { |
| 10563 | if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0) |
| 10564 | reply_len = -1; |
| 10565 | } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) { |
| 10566 | reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16, |
| 10567 | reply, reply_size); |
| 10568 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10569 | #ifdef CONFIG_INTERWORKING |
| 10570 | } else if (os_strcmp(buf, "FETCH_ANQP") == 0) { |
| 10571 | if (interworking_fetch_anqp(wpa_s) < 0) |
| 10572 | reply_len = -1; |
| 10573 | } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) { |
| 10574 | interworking_stop_fetch_anqp(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10575 | } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) { |
| 10576 | if (ctrl_interworking_select(wpa_s, NULL) < 0) |
| 10577 | reply_len = -1; |
| 10578 | } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) { |
| 10579 | if (ctrl_interworking_select(wpa_s, buf + 20) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10580 | reply_len = -1; |
| 10581 | } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10582 | if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10583 | reply_len = -1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10584 | } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) { |
| 10585 | int id; |
| 10586 | |
| 10587 | id = ctrl_interworking_connect(wpa_s, buf + 25, 1); |
| 10588 | if (id < 0) |
| 10589 | reply_len = -1; |
| 10590 | else { |
| 10591 | reply_len = os_snprintf(reply, reply_size, "%d\n", id); |
| 10592 | if (os_snprintf_error(reply_size, reply_len)) |
| 10593 | reply_len = -1; |
| 10594 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10595 | } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) { |
| 10596 | if (get_anqp(wpa_s, buf + 9) < 0) |
| 10597 | reply_len = -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10598 | } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) { |
| 10599 | if (gas_request(wpa_s, buf + 12) < 0) |
| 10600 | reply_len = -1; |
| 10601 | } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) { |
| 10602 | reply_len = gas_response_get(wpa_s, buf + 17, reply, |
| 10603 | reply_size); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10604 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10605 | #ifdef CONFIG_HS20 |
| 10606 | } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) { |
| 10607 | if (get_hs20_anqp(wpa_s, buf + 14) < 0) |
| 10608 | reply_len = -1; |
| 10609 | } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) { |
| 10610 | if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0) |
| 10611 | reply_len = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 10612 | } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 10613 | if (hs20_icon_request(wpa_s, buf + 18, 0) < 0) |
| 10614 | reply_len = -1; |
| 10615 | } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) { |
| 10616 | if (hs20_icon_request(wpa_s, buf + 14, 1) < 0) |
| 10617 | reply_len = -1; |
| 10618 | } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) { |
| 10619 | reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size); |
| 10620 | } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) { |
| 10621 | if (del_hs20_icon(wpa_s, buf + 14) < 0) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 10622 | reply_len = -1; |
| 10623 | } else if (os_strcmp(buf, "FETCH_OSU") == 0) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10624 | if (hs20_fetch_osu(wpa_s, 0) < 0) |
| 10625 | reply_len = -1; |
| 10626 | } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) { |
| 10627 | if (hs20_fetch_osu(wpa_s, 1) < 0) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 10628 | reply_len = -1; |
| 10629 | } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) { |
| 10630 | hs20_cancel_fetch_osu(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10631 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10632 | } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) |
| 10633 | { |
| 10634 | if (wpa_supplicant_ctrl_iface_ctrl_rsp( |
| 10635 | wpa_s, buf + os_strlen(WPA_CTRL_RSP))) |
| 10636 | reply_len = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 10637 | else { |
| 10638 | /* |
| 10639 | * Notify response from timeout to allow the control |
| 10640 | * interface response to be sent first. |
| 10641 | */ |
| 10642 | eloop_register_timeout(0, 0, wpas_ctrl_eapol_response, |
| 10643 | wpa_s, NULL); |
| 10644 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10645 | } else if (os_strcmp(buf, "RECONFIGURE") == 0) { |
| 10646 | if (wpa_supplicant_reload_configuration(wpa_s)) |
| 10647 | reply_len = -1; |
| 10648 | } else if (os_strcmp(buf, "TERMINATE") == 0) { |
| 10649 | wpa_supplicant_terminate_proc(wpa_s->global); |
| 10650 | } else if (os_strncmp(buf, "BSSID ", 6) == 0) { |
| 10651 | if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) |
| 10652 | reply_len = -1; |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 10653 | } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10654 | reply_len = wpa_supplicant_ctrl_iface_blacklist( |
| 10655 | wpa_s, buf + 9, reply, reply_size); |
| 10656 | } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) { |
| 10657 | reply_len = wpa_supplicant_ctrl_iface_log_level( |
| 10658 | wpa_s, buf + 9, reply, reply_size); |
Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 10659 | } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) { |
| 10660 | reply_len = wpa_supplicant_ctrl_iface_list_networks( |
| 10661 | wpa_s, buf + 14, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10662 | } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { |
| 10663 | reply_len = wpa_supplicant_ctrl_iface_list_networks( |
Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 10664 | wpa_s, NULL, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10665 | } else if (os_strcmp(buf, "DISCONNECT") == 0) { |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 10666 | wpas_request_disconnection(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10667 | } else if (os_strcmp(buf, "SCAN") == 0) { |
| 10668 | wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len); |
| 10669 | } else if (os_strncmp(buf, "SCAN ", 5) == 0) { |
| 10670 | wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10671 | } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { |
| 10672 | reply_len = wpa_supplicant_ctrl_iface_scan_results( |
| 10673 | wpa_s, reply, reply_size); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 10674 | } else if (os_strcmp(buf, "ABORT_SCAN") == 0) { |
| 10675 | if (wpas_abort_ongoing_scan(wpa_s) < 0) |
| 10676 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10677 | } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { |
| 10678 | if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) |
| 10679 | reply_len = -1; |
| 10680 | } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { |
| 10681 | if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) |
| 10682 | reply_len = -1; |
| 10683 | } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { |
| 10684 | if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) |
| 10685 | reply_len = -1; |
| 10686 | } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { |
| 10687 | reply_len = wpa_supplicant_ctrl_iface_add_network( |
| 10688 | wpa_s, reply, reply_size); |
| 10689 | } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { |
| 10690 | if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) |
| 10691 | reply_len = -1; |
| 10692 | } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { |
| 10693 | if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) |
| 10694 | reply_len = -1; |
| 10695 | } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { |
| 10696 | reply_len = wpa_supplicant_ctrl_iface_get_network( |
| 10697 | wpa_s, buf + 12, reply, reply_size); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 10698 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10699 | if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12, |
| 10700 | wpa_s)) |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 10701 | reply_len = -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10702 | } else if (os_strcmp(buf, "LIST_CREDS") == 0) { |
| 10703 | reply_len = wpa_supplicant_ctrl_iface_list_creds( |
| 10704 | wpa_s, reply, reply_size); |
| 10705 | } else if (os_strcmp(buf, "ADD_CRED") == 0) { |
| 10706 | reply_len = wpa_supplicant_ctrl_iface_add_cred( |
| 10707 | wpa_s, reply, reply_size); |
| 10708 | } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) { |
| 10709 | if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12)) |
| 10710 | reply_len = -1; |
| 10711 | } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) { |
| 10712 | if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9)) |
| 10713 | reply_len = -1; |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 10714 | } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) { |
| 10715 | reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9, |
| 10716 | reply, |
| 10717 | reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10718 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 10719 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { |
| 10720 | if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) |
| 10721 | reply_len = -1; |
| 10722 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 10723 | } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { |
| 10724 | reply_len = wpa_supplicant_ctrl_iface_get_capability( |
| 10725 | wpa_s, buf + 15, reply, reply_size); |
| 10726 | } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { |
| 10727 | if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) |
| 10728 | reply_len = -1; |
| 10729 | } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) { |
| 10730 | if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14)) |
| 10731 | reply_len = -1; |
| 10732 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
| 10733 | reply_len = wpa_supplicant_global_iface_list( |
| 10734 | wpa_s->global, reply, reply_size); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 10735 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10736 | reply_len = wpa_supplicant_global_iface_interfaces( |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 10737 | wpa_s->global, buf + 10, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10738 | } else if (os_strncmp(buf, "BSS ", 4) == 0) { |
| 10739 | reply_len = wpa_supplicant_ctrl_iface_bss( |
| 10740 | wpa_s, buf + 4, reply, reply_size); |
| 10741 | #ifdef CONFIG_AP |
| 10742 | } else if (os_strcmp(buf, "STA-FIRST") == 0) { |
| 10743 | reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size); |
| 10744 | } else if (os_strncmp(buf, "STA ", 4) == 0) { |
| 10745 | reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply, |
| 10746 | reply_size); |
| 10747 | } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { |
| 10748 | reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply, |
| 10749 | reply_size); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10750 | } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) { |
| 10751 | if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15)) |
| 10752 | reply_len = -1; |
| 10753 | } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) { |
| 10754 | if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13)) |
| 10755 | reply_len = -1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10756 | } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) { |
| 10757 | if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12)) |
| 10758 | reply_len = -1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10759 | } else if (os_strcmp(buf, "STOP_AP") == 0) { |
| 10760 | if (wpas_ap_stop_ap(wpa_s)) |
| 10761 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10762 | #endif /* CONFIG_AP */ |
| 10763 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
| 10764 | wpas_notify_suspend(wpa_s->global); |
| 10765 | } else if (os_strcmp(buf, "RESUME") == 0) { |
| 10766 | wpas_notify_resume(wpa_s->global); |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 10767 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10768 | } else if (os_strcmp(buf, "DROP_SA") == 0) { |
| 10769 | wpa_supplicant_ctrl_iface_drop_sa(wpa_s); |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 10770 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10771 | } else if (os_strncmp(buf, "ROAM ", 5) == 0) { |
| 10772 | if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) |
| 10773 | reply_len = -1; |
| 10774 | } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10775 | wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10776 | } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) { |
| 10777 | if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15)) |
| 10778 | reply_len = -1; |
| 10779 | } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) { |
| 10780 | if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s, |
| 10781 | buf + 17)) |
| 10782 | reply_len = -1; |
Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 10783 | } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10784 | wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10785 | #ifdef CONFIG_TDLS |
| 10786 | } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) { |
| 10787 | if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14)) |
| 10788 | reply_len = -1; |
| 10789 | } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) { |
| 10790 | if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11)) |
| 10791 | reply_len = -1; |
| 10792 | } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) { |
| 10793 | if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14)) |
| 10794 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10795 | } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) { |
| 10796 | if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s, |
| 10797 | buf + 17)) |
| 10798 | reply_len = -1; |
| 10799 | } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) { |
| 10800 | if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s, |
| 10801 | buf + 24)) |
| 10802 | reply_len = -1; |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 10803 | } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) { |
| 10804 | reply_len = wpa_supplicant_ctrl_iface_tdls_link_status( |
| 10805 | wpa_s, buf + 17, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10806 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10807 | } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) { |
| 10808 | reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size); |
| 10809 | } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) { |
| 10810 | if (wmm_ac_ctrl_addts(wpa_s, buf + 13)) |
| 10811 | reply_len = -1; |
| 10812 | } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) { |
| 10813 | if (wmm_ac_ctrl_delts(wpa_s, buf + 13)) |
| 10814 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10815 | } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) { |
| 10816 | reply_len = wpa_supplicant_signal_poll(wpa_s, reply, |
| 10817 | reply_size); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 10818 | } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) { |
| 10819 | if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14)) |
| 10820 | reply_len = -1; |
Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 10821 | } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) { |
| 10822 | reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply, |
| 10823 | reply_size); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10824 | #ifdef CONFIG_AUTOSCAN |
| 10825 | } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) { |
| 10826 | if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9)) |
| 10827 | reply_len = -1; |
| 10828 | #endif /* CONFIG_AUTOSCAN */ |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10829 | } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) { |
| 10830 | reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply, |
| 10831 | reply_size); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 10832 | } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) { |
| 10833 | reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply, |
| 10834 | reply_size); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 10835 | #ifdef ANDROID |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 10836 | } else if (os_strncmp(buf, "DRIVER ", 7) == 0) { |
| 10837 | reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply, |
| 10838 | reply_size); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 10839 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10840 | } else if (os_strncmp(buf, "VENDOR ", 7) == 0) { |
| 10841 | reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply, |
| 10842 | reply_size); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10843 | } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 10844 | pmksa_cache_clear_current(wpa_s->wpa); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10845 | eapol_sm_request_reauth(wpa_s->eapol); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 10846 | #ifdef CONFIG_WNM |
| 10847 | } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) { |
| 10848 | if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10)) |
| 10849 | reply_len = -1; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 10850 | } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) { |
| 10851 | if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14)) |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 10852 | reply_len = -1; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 10853 | } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) { |
| 10854 | if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18)) |
| 10855 | reply_len = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 10856 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 10857 | } else if (os_strcmp(buf, "FLUSH") == 0) { |
| 10858 | wpa_supplicant_ctrl_iface_flush(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10859 | } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) { |
| 10860 | reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply, |
| 10861 | reply_size); |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 10862 | #ifdef CONFIG_TESTING_OPTIONS |
| 10863 | } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) { |
| 10864 | if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0) |
| 10865 | reply_len = -1; |
| 10866 | } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) { |
| 10867 | wpas_ctrl_iface_mgmt_tx_done(wpa_s); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10868 | } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) { |
| 10869 | if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0) |
| 10870 | reply_len = -1; |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 10871 | } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) { |
| 10872 | if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0) |
| 10873 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10874 | } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) { |
| 10875 | if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0) |
| 10876 | reply_len = -1; |
| 10877 | } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) { |
| 10878 | if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0) |
| 10879 | reply_len = -1; |
| 10880 | } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) { |
| 10881 | if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0) |
| 10882 | reply_len = -1; |
| 10883 | } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) { |
| 10884 | if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0) |
| 10885 | reply_len = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 10886 | } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) { |
| 10887 | if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0) |
| 10888 | reply_len = -1; |
| 10889 | } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) { |
| 10890 | reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10891 | } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) { |
| 10892 | if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0) |
| 10893 | reply_len = -1; |
| 10894 | } else if (os_strcmp(buf, "GET_FAIL") == 0) { |
| 10895 | reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size); |
Jouni Malinen | c481836 | 2015-10-04 11:45:13 +0300 | [diff] [blame] | 10896 | } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) { |
| 10897 | if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0) |
| 10898 | reply_len = -1; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10899 | } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) { |
| 10900 | if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0) |
| 10901 | reply_len = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10902 | } else if (os_strcmp(buf, "RESET_PN") == 0) { |
| 10903 | if (wpas_ctrl_reset_pn(wpa_s) < 0) |
| 10904 | reply_len = -1; |
| 10905 | } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) { |
| 10906 | if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0) |
| 10907 | reply_len = -1; |
| 10908 | } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) { |
| 10909 | if (wpas_ctrl_resend_assoc(wpa_s) < 0) |
| 10910 | reply_len = -1; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 10911 | } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) { |
| 10912 | sme_event_unprot_disconnect( |
| 10913 | wpa_s, wpa_s->bssid, NULL, |
| 10914 | WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA); |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 10915 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10916 | } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) { |
| 10917 | if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0) |
| 10918 | reply_len = -1; |
| 10919 | } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) { |
| 10920 | reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply, |
| 10921 | reply_size); |
| 10922 | } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) { |
| 10923 | if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0) |
| 10924 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10925 | } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) { |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10926 | if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10927 | reply_len = -1; |
| 10928 | } else if (os_strcmp(buf, "ERP_FLUSH") == 0) { |
| 10929 | wpas_ctrl_iface_erp_flush(wpa_s); |
| 10930 | } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) { |
| 10931 | if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14)) |
| 10932 | reply_len = -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10933 | } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) { |
| 10934 | reply_len = wpas_ctrl_iface_get_pref_freq_list( |
| 10935 | wpa_s, buf + 19, reply, reply_size); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10936 | #ifdef CONFIG_FILS |
| 10937 | } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) { |
| 10938 | if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17)) |
| 10939 | reply_len = -1; |
| 10940 | } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) { |
| 10941 | wpas_flush_fils_hlp_req(wpa_s); |
| 10942 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10943 | #ifdef CONFIG_DPP |
| 10944 | } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) { |
| 10945 | int res; |
| 10946 | |
| 10947 | res = wpas_dpp_qr_code(wpa_s, buf + 12); |
| 10948 | if (res < 0) { |
| 10949 | reply_len = -1; |
| 10950 | } else { |
| 10951 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 10952 | if (os_snprintf_error(reply_size, reply_len)) |
| 10953 | reply_len = -1; |
| 10954 | } |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10955 | } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) { |
| 10956 | int res; |
| 10957 | |
| 10958 | res = wpas_dpp_nfc_uri(wpa_s, buf + 12); |
| 10959 | if (res < 0) { |
| 10960 | reply_len = -1; |
| 10961 | } else { |
| 10962 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 10963 | if (os_snprintf_error(reply_size, reply_len)) |
| 10964 | reply_len = -1; |
| 10965 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10966 | } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) { |
| 10967 | int res; |
| 10968 | |
| 10969 | res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20); |
| 10970 | if (res < 0) { |
| 10971 | reply_len = -1; |
| 10972 | } else { |
| 10973 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 10974 | if (os_snprintf_error(reply_size, reply_len)) |
| 10975 | reply_len = -1; |
| 10976 | } |
| 10977 | } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) { |
| 10978 | int res; |
| 10979 | |
| 10980 | res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20); |
| 10981 | if (res < 0) { |
| 10982 | reply_len = -1; |
| 10983 | } else { |
| 10984 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 10985 | if (os_snprintf_error(reply_size, reply_len)) |
| 10986 | reply_len = -1; |
| 10987 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10988 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) { |
| 10989 | int res; |
| 10990 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 10991 | res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10992 | if (res < 0) { |
| 10993 | reply_len = -1; |
| 10994 | } else { |
| 10995 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 10996 | if (os_snprintf_error(reply_size, reply_len)) |
| 10997 | reply_len = -1; |
| 10998 | } |
| 10999 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 11000 | if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11001 | reply_len = -1; |
| 11002 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) { |
| 11003 | const char *uri; |
| 11004 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 11005 | uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11006 | if (!uri) { |
| 11007 | reply_len = -1; |
| 11008 | } else { |
| 11009 | reply_len = os_snprintf(reply, reply_size, "%s", uri); |
| 11010 | if (os_snprintf_error(reply_size, reply_len)) |
| 11011 | reply_len = -1; |
| 11012 | } |
| 11013 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 11014 | reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19), |
| 11015 | reply, reply_size); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11016 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) { |
| 11017 | if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18), |
| 11018 | os_strchr(buf + 18, ' ')) < 0) |
| 11019 | reply_len = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11020 | } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) { |
| 11021 | if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0) |
| 11022 | reply_len = -1; |
| 11023 | } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) { |
| 11024 | if (wpas_dpp_listen(wpa_s, buf + 11) < 0) |
| 11025 | reply_len = -1; |
| 11026 | } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11027 | wpas_dpp_stop(wpa_s); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11028 | wpas_dpp_listen_stop(wpa_s); |
| 11029 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) { |
| 11030 | int res; |
| 11031 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 11032 | res = dpp_configurator_add(wpa_s->dpp, buf + 20); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11033 | if (res < 0) { |
| 11034 | reply_len = -1; |
| 11035 | } else { |
| 11036 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 11037 | if (os_snprintf_error(reply_size, reply_len)) |
| 11038 | reply_len = -1; |
| 11039 | } |
| 11040 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 11041 | if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11042 | reply_len = -1; |
| 11043 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11044 | if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11045 | reply_len = -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11046 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 11047 | reply_len = dpp_configurator_get_key_id(wpa_s->dpp, |
| 11048 | atoi(buf + 25), |
| 11049 | reply, reply_size); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11050 | } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) { |
| 11051 | int res; |
| 11052 | |
| 11053 | res = wpas_dpp_pkex_add(wpa_s, buf + 12); |
| 11054 | if (res < 0) { |
| 11055 | reply_len = -1; |
| 11056 | } else { |
| 11057 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 11058 | if (os_snprintf_error(reply_size, reply_len)) |
| 11059 | reply_len = -1; |
| 11060 | } |
| 11061 | } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) { |
| 11062 | if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0) |
| 11063 | reply_len = -1; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11064 | #ifdef CONFIG_DPP2 |
| 11065 | } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) { |
| 11066 | if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0) |
| 11067 | reply_len = -1; |
| 11068 | } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) { |
| 11069 | if (wpas_dpp_controller_start(wpa_s, NULL) < 0) |
| 11070 | reply_len = -1; |
| 11071 | } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) { |
| 11072 | dpp_controller_stop(wpa_s->dpp); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11073 | } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) { |
| 11074 | if (wpas_dpp_chirp(wpa_s, buf + 9) < 0) |
| 11075 | reply_len = -1; |
| 11076 | } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) { |
| 11077 | wpas_dpp_chirp_stop(wpa_s); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 11078 | } else if (os_strncmp(buf, "DPP_RECONFIG ", 13) == 0) { |
| 11079 | struct wpa_ssid *ssid; |
| 11080 | |
| 11081 | ssid = wpa_config_get_network(wpa_s->conf, atoi(buf + 13)); |
| 11082 | if (!ssid || wpas_dpp_reconfig(wpa_s, ssid) < 0) |
| 11083 | reply_len = -1; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11084 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11085 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11086 | } else { |
| 11087 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); |
| 11088 | reply_len = 16; |
| 11089 | } |
| 11090 | |
| 11091 | if (reply_len < 0) { |
| 11092 | os_memcpy(reply, "FAIL\n", 5); |
| 11093 | reply_len = 5; |
| 11094 | } |
| 11095 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11096 | *resp_len = reply_len; |
| 11097 | return reply; |
| 11098 | } |
| 11099 | |
| 11100 | |
| 11101 | static int wpa_supplicant_global_iface_add(struct wpa_global *global, |
| 11102 | char *cmd) |
| 11103 | { |
| 11104 | struct wpa_interface iface; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 11105 | char *pos, *extra; |
| 11106 | struct wpa_supplicant *wpa_s; |
| 11107 | unsigned int create_iface = 0; |
| 11108 | u8 mac_addr[ETH_ALEN]; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 11109 | enum wpa_driver_if_type type = WPA_IF_STATION; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11110 | |
| 11111 | /* |
| 11112 | * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param> |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 11113 | * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]] |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11114 | */ |
| 11115 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd); |
| 11116 | |
| 11117 | os_memset(&iface, 0, sizeof(iface)); |
| 11118 | |
| 11119 | do { |
| 11120 | iface.ifname = pos = cmd; |
| 11121 | pos = os_strchr(pos, '\t'); |
| 11122 | if (pos) |
| 11123 | *pos++ = '\0'; |
| 11124 | if (iface.ifname[0] == '\0') |
| 11125 | return -1; |
| 11126 | if (pos == NULL) |
| 11127 | break; |
| 11128 | |
| 11129 | iface.confname = pos; |
| 11130 | pos = os_strchr(pos, '\t'); |
| 11131 | if (pos) |
| 11132 | *pos++ = '\0'; |
| 11133 | if (iface.confname[0] == '\0') |
| 11134 | iface.confname = NULL; |
| 11135 | if (pos == NULL) |
| 11136 | break; |
| 11137 | |
| 11138 | iface.driver = pos; |
| 11139 | pos = os_strchr(pos, '\t'); |
| 11140 | if (pos) |
| 11141 | *pos++ = '\0'; |
| 11142 | if (iface.driver[0] == '\0') |
| 11143 | iface.driver = NULL; |
| 11144 | if (pos == NULL) |
| 11145 | break; |
| 11146 | |
| 11147 | iface.ctrl_interface = pos; |
| 11148 | pos = os_strchr(pos, '\t'); |
| 11149 | if (pos) |
| 11150 | *pos++ = '\0'; |
| 11151 | if (iface.ctrl_interface[0] == '\0') |
| 11152 | iface.ctrl_interface = NULL; |
| 11153 | if (pos == NULL) |
| 11154 | break; |
| 11155 | |
| 11156 | iface.driver_param = pos; |
| 11157 | pos = os_strchr(pos, '\t'); |
| 11158 | if (pos) |
| 11159 | *pos++ = '\0'; |
| 11160 | if (iface.driver_param[0] == '\0') |
| 11161 | iface.driver_param = NULL; |
| 11162 | if (pos == NULL) |
| 11163 | break; |
| 11164 | |
| 11165 | iface.bridge_ifname = pos; |
| 11166 | pos = os_strchr(pos, '\t'); |
| 11167 | if (pos) |
| 11168 | *pos++ = '\0'; |
| 11169 | if (iface.bridge_ifname[0] == '\0') |
| 11170 | iface.bridge_ifname = NULL; |
| 11171 | if (pos == NULL) |
| 11172 | break; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 11173 | |
| 11174 | extra = pos; |
| 11175 | pos = os_strchr(pos, '\t'); |
| 11176 | if (pos) |
| 11177 | *pos++ = '\0'; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 11178 | if (!extra[0]) |
| 11179 | break; |
| 11180 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 11181 | if (os_strcmp(extra, "create") == 0) { |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 11182 | create_iface = 1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 11183 | if (!pos) |
| 11184 | break; |
| 11185 | |
| 11186 | if (os_strcmp(pos, "sta") == 0) { |
| 11187 | type = WPA_IF_STATION; |
| 11188 | } else if (os_strcmp(pos, "ap") == 0) { |
| 11189 | type = WPA_IF_AP_BSS; |
| 11190 | } else { |
| 11191 | wpa_printf(MSG_DEBUG, |
| 11192 | "INTERFACE_ADD unsupported interface type: '%s'", |
| 11193 | pos); |
| 11194 | return -1; |
| 11195 | } |
| 11196 | } else { |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 11197 | wpa_printf(MSG_DEBUG, |
| 11198 | "INTERFACE_ADD unsupported extra parameter: '%s'", |
| 11199 | extra); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 11200 | return -1; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 11201 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11202 | } while (0); |
| 11203 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 11204 | if (create_iface) { |
| 11205 | wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'", |
| 11206 | iface.ifname); |
| 11207 | if (!global->ifaces) |
| 11208 | return -1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 11209 | if (wpa_drv_if_add(global->ifaces, type, iface.ifname, |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 11210 | NULL, NULL, NULL, mac_addr, NULL) < 0) { |
| 11211 | wpa_printf(MSG_ERROR, |
| 11212 | "CTRL_IFACE interface creation failed"); |
| 11213 | return -1; |
| 11214 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11215 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 11216 | wpa_printf(MSG_DEBUG, |
| 11217 | "CTRL_IFACE interface '%s' created with MAC addr: " |
| 11218 | MACSTR, iface.ifname, MAC2STR(mac_addr)); |
| 11219 | } |
| 11220 | |
| 11221 | if (wpa_supplicant_get_iface(global, iface.ifname)) |
| 11222 | goto fail; |
| 11223 | |
| 11224 | wpa_s = wpa_supplicant_add_iface(global, &iface, NULL); |
| 11225 | if (!wpa_s) |
| 11226 | goto fail; |
| 11227 | wpa_s->added_vif = create_iface; |
| 11228 | return 0; |
| 11229 | |
| 11230 | fail: |
| 11231 | if (create_iface) |
| 11232 | wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname); |
| 11233 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11234 | } |
| 11235 | |
| 11236 | |
| 11237 | static int wpa_supplicant_global_iface_remove(struct wpa_global *global, |
| 11238 | char *cmd) |
| 11239 | { |
| 11240 | struct wpa_supplicant *wpa_s; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 11241 | int ret; |
| 11242 | unsigned int delete_iface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11243 | |
| 11244 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd); |
| 11245 | |
| 11246 | wpa_s = wpa_supplicant_get_iface(global, cmd); |
| 11247 | if (wpa_s == NULL) |
| 11248 | return -1; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 11249 | delete_iface = wpa_s->added_vif; |
| 11250 | ret = wpa_supplicant_remove_iface(global, wpa_s, 0); |
| 11251 | if (!ret && delete_iface) { |
| 11252 | wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'", |
| 11253 | cmd); |
| 11254 | ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd); |
| 11255 | } |
| 11256 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11257 | } |
| 11258 | |
| 11259 | |
| 11260 | static void wpa_free_iface_info(struct wpa_interface_info *iface) |
| 11261 | { |
| 11262 | struct wpa_interface_info *prev; |
| 11263 | |
| 11264 | while (iface) { |
| 11265 | prev = iface; |
| 11266 | iface = iface->next; |
| 11267 | |
| 11268 | os_free(prev->ifname); |
| 11269 | os_free(prev->desc); |
| 11270 | os_free(prev); |
| 11271 | } |
| 11272 | } |
| 11273 | |
| 11274 | |
| 11275 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
| 11276 | char *buf, int len) |
| 11277 | { |
| 11278 | int i, res; |
| 11279 | struct wpa_interface_info *iface = NULL, *last = NULL, *tmp; |
| 11280 | char *pos, *end; |
| 11281 | |
| 11282 | for (i = 0; wpa_drivers[i]; i++) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 11283 | const struct wpa_driver_ops *drv = wpa_drivers[i]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11284 | if (drv->get_interfaces == NULL) |
| 11285 | continue; |
| 11286 | tmp = drv->get_interfaces(global->drv_priv[i]); |
| 11287 | if (tmp == NULL) |
| 11288 | continue; |
| 11289 | |
| 11290 | if (last == NULL) |
| 11291 | iface = last = tmp; |
| 11292 | else |
| 11293 | last->next = tmp; |
| 11294 | while (last->next) |
| 11295 | last = last->next; |
| 11296 | } |
| 11297 | |
| 11298 | pos = buf; |
| 11299 | end = buf + len; |
| 11300 | for (tmp = iface; tmp; tmp = tmp->next) { |
| 11301 | res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n", |
| 11302 | tmp->drv_name, tmp->ifname, |
| 11303 | tmp->desc ? tmp->desc : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11304 | if (os_snprintf_error(end - pos, res)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11305 | *pos = '\0'; |
| 11306 | break; |
| 11307 | } |
| 11308 | pos += res; |
| 11309 | } |
| 11310 | |
| 11311 | wpa_free_iface_info(iface); |
| 11312 | |
| 11313 | return pos - buf; |
| 11314 | } |
| 11315 | |
| 11316 | |
| 11317 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 11318 | const char *input, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11319 | char *buf, int len) |
| 11320 | { |
| 11321 | int res; |
| 11322 | char *pos, *end; |
| 11323 | struct wpa_supplicant *wpa_s; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 11324 | int show_ctrl = 0; |
| 11325 | |
| 11326 | if (input) |
| 11327 | show_ctrl = !!os_strstr(input, "ctrl"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11328 | |
| 11329 | wpa_s = global->ifaces; |
| 11330 | pos = buf; |
| 11331 | end = buf + len; |
| 11332 | |
| 11333 | while (wpa_s) { |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 11334 | if (show_ctrl) |
| 11335 | res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n", |
| 11336 | wpa_s->ifname, |
| 11337 | wpa_s->conf->ctrl_interface ? |
| 11338 | wpa_s->conf->ctrl_interface : "N/A"); |
| 11339 | else |
| 11340 | res = os_snprintf(pos, end - pos, "%s\n", |
| 11341 | wpa_s->ifname); |
| 11342 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11343 | if (os_snprintf_error(end - pos, res)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11344 | *pos = '\0'; |
| 11345 | break; |
| 11346 | } |
| 11347 | pos += res; |
| 11348 | wpa_s = wpa_s->next; |
| 11349 | } |
| 11350 | return pos - buf; |
| 11351 | } |
| 11352 | |
| 11353 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 11354 | static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global, |
| 11355 | const char *ifname, |
| 11356 | char *cmd, size_t *resp_len) |
| 11357 | { |
| 11358 | struct wpa_supplicant *wpa_s; |
| 11359 | |
| 11360 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 11361 | if (os_strcmp(ifname, wpa_s->ifname) == 0) |
| 11362 | break; |
| 11363 | } |
| 11364 | |
| 11365 | if (wpa_s == NULL) { |
| 11366 | char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n"); |
| 11367 | if (resp) |
| 11368 | *resp_len = os_strlen(resp); |
| 11369 | else |
| 11370 | *resp_len = 1; |
| 11371 | return resp; |
| 11372 | } |
| 11373 | |
| 11374 | return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len); |
| 11375 | } |
| 11376 | |
| 11377 | |
| 11378 | static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global, |
| 11379 | char *buf, size_t *resp_len) |
| 11380 | { |
| 11381 | #ifdef CONFIG_P2P |
| 11382 | static const char * cmd[] = { |
Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 11383 | "LIST_NETWORKS", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 11384 | "P2P_FIND", |
| 11385 | "P2P_STOP_FIND", |
| 11386 | "P2P_LISTEN", |
| 11387 | "P2P_GROUP_ADD", |
| 11388 | "P2P_GET_PASSPHRASE", |
| 11389 | "P2P_SERVICE_UPDATE", |
| 11390 | "P2P_SERVICE_FLUSH", |
| 11391 | "P2P_FLUSH", |
| 11392 | "P2P_CANCEL", |
| 11393 | "P2P_PRESENCE_REQ", |
| 11394 | "P2P_EXT_LISTEN", |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 11395 | #ifdef CONFIG_AP |
| 11396 | "STA-FIRST", |
| 11397 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 11398 | NULL |
| 11399 | }; |
| 11400 | static const char * prefix[] = { |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 11401 | #ifdef ANDROID |
Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 11402 | "DRIVER ", |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 11403 | #endif /* ANDROID */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11404 | "GET_CAPABILITY ", |
Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 11405 | "GET_NETWORK ", |
| 11406 | "REMOVE_NETWORK ", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 11407 | "P2P_FIND ", |
| 11408 | "P2P_CONNECT ", |
| 11409 | "P2P_LISTEN ", |
| 11410 | "P2P_GROUP_REMOVE ", |
| 11411 | "P2P_GROUP_ADD ", |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11412 | "P2P_GROUP_MEMBER ", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 11413 | "P2P_PROV_DISC ", |
| 11414 | "P2P_SERV_DISC_REQ ", |
| 11415 | "P2P_SERV_DISC_CANCEL_REQ ", |
| 11416 | "P2P_SERV_DISC_RESP ", |
| 11417 | "P2P_SERV_DISC_EXTERNAL ", |
| 11418 | "P2P_SERVICE_ADD ", |
| 11419 | "P2P_SERVICE_DEL ", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 11420 | "P2P_SERVICE_REP ", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 11421 | "P2P_REJECT ", |
| 11422 | "P2P_INVITE ", |
| 11423 | "P2P_PEER ", |
| 11424 | "P2P_SET ", |
| 11425 | "P2P_UNAUTHORIZE ", |
| 11426 | "P2P_PRESENCE_REQ ", |
| 11427 | "P2P_EXT_LISTEN ", |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 11428 | "P2P_REMOVE_CLIENT ", |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 11429 | "WPS_NFC_TOKEN ", |
| 11430 | "WPS_NFC_TAG_READ ", |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 11431 | "NFC_GET_HANDOVER_SEL ", |
| 11432 | "NFC_GET_HANDOVER_REQ ", |
| 11433 | "NFC_REPORT_HANDOVER ", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 11434 | "P2P_ASP_PROVISION ", |
| 11435 | "P2P_ASP_PROVISION_RESP ", |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 11436 | #ifdef CONFIG_AP |
| 11437 | "STA ", |
| 11438 | "STA-NEXT ", |
| 11439 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 11440 | NULL |
| 11441 | }; |
| 11442 | int found = 0; |
| 11443 | int i; |
| 11444 | |
| 11445 | if (global->p2p_init_wpa_s == NULL) |
| 11446 | return NULL; |
| 11447 | |
| 11448 | for (i = 0; !found && cmd[i]; i++) { |
| 11449 | if (os_strcmp(buf, cmd[i]) == 0) |
| 11450 | found = 1; |
| 11451 | } |
| 11452 | |
| 11453 | for (i = 0; !found && prefix[i]; i++) { |
| 11454 | if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0) |
| 11455 | found = 1; |
| 11456 | } |
| 11457 | |
| 11458 | if (found) |
| 11459 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, |
| 11460 | buf, resp_len); |
| 11461 | #endif /* CONFIG_P2P */ |
| 11462 | return NULL; |
| 11463 | } |
| 11464 | |
| 11465 | |
| 11466 | static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global, |
| 11467 | char *buf, size_t *resp_len) |
| 11468 | { |
| 11469 | #ifdef CONFIG_WIFI_DISPLAY |
| 11470 | if (global->p2p_init_wpa_s == NULL) |
| 11471 | return NULL; |
| 11472 | if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 || |
| 11473 | os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) |
| 11474 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, |
| 11475 | buf, resp_len); |
| 11476 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 11477 | return NULL; |
| 11478 | } |
| 11479 | |
| 11480 | |
| 11481 | static char * wpas_global_ctrl_iface_redir(struct wpa_global *global, |
| 11482 | char *buf, size_t *resp_len) |
| 11483 | { |
| 11484 | char *ret; |
| 11485 | |
| 11486 | ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len); |
| 11487 | if (ret) |
| 11488 | return ret; |
| 11489 | |
| 11490 | ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len); |
| 11491 | if (ret) |
| 11492 | return ret; |
| 11493 | |
| 11494 | return NULL; |
| 11495 | } |
| 11496 | |
| 11497 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11498 | static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd) |
| 11499 | { |
| 11500 | char *value; |
| 11501 | |
| 11502 | value = os_strchr(cmd, ' '); |
| 11503 | if (value == NULL) |
| 11504 | return -1; |
| 11505 | *value++ = '\0'; |
| 11506 | |
| 11507 | wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value); |
| 11508 | |
| 11509 | #ifdef CONFIG_WIFI_DISPLAY |
| 11510 | if (os_strcasecmp(cmd, "wifi_display") == 0) { |
| 11511 | wifi_display_enable(global, !!atoi(value)); |
| 11512 | return 0; |
| 11513 | } |
| 11514 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 11515 | |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 11516 | /* Restore cmd to its original value to allow redirection */ |
| 11517 | value[-1] = ' '; |
| 11518 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11519 | return -1; |
| 11520 | } |
| 11521 | |
| 11522 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11523 | static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global, |
| 11524 | char *cmd) |
| 11525 | { |
| 11526 | struct wpa_supplicant *wpa_s[2]; /* src, dst */ |
| 11527 | char *p; |
| 11528 | unsigned int i; |
| 11529 | |
| 11530 | /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id> |
| 11531 | * <variable name> */ |
| 11532 | |
| 11533 | for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) { |
| 11534 | p = os_strchr(cmd, ' '); |
| 11535 | if (p == NULL) |
| 11536 | return -1; |
| 11537 | *p = '\0'; |
| 11538 | |
| 11539 | wpa_s[i] = global->ifaces; |
| 11540 | for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) { |
| 11541 | if (os_strcmp(cmd, wpa_s[i]->ifname) == 0) |
| 11542 | break; |
| 11543 | } |
| 11544 | |
| 11545 | if (!wpa_s[i]) { |
| 11546 | wpa_printf(MSG_DEBUG, |
| 11547 | "CTRL_IFACE: Could not find iface=%s", cmd); |
| 11548 | return -1; |
| 11549 | } |
| 11550 | |
| 11551 | cmd = p + 1; |
| 11552 | } |
| 11553 | |
| 11554 | return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]); |
| 11555 | } |
| 11556 | |
| 11557 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11558 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 11559 | static int wpas_global_ctrl_iface_save_config(struct wpa_global *global) |
| 11560 | { |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 11561 | int ret = 0, saved = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11562 | struct wpa_supplicant *wpa_s; |
| 11563 | |
| 11564 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 11565 | if (!wpa_s->conf->update_config) { |
| 11566 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)"); |
| 11567 | continue; |
| 11568 | } |
| 11569 | |
| 11570 | if (wpa_config_write(wpa_s->confname, wpa_s->conf)) { |
| 11571 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration"); |
| 11572 | ret = 1; |
| 11573 | } else { |
| 11574 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated"); |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 11575 | saved++; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11576 | } |
| 11577 | } |
| 11578 | |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 11579 | if (!saved && !ret) { |
| 11580 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11581 | "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated"); |
| 11582 | ret = 1; |
| 11583 | } |
| 11584 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11585 | return ret; |
| 11586 | } |
| 11587 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 11588 | |
| 11589 | |
| 11590 | static int wpas_global_ctrl_iface_status(struct wpa_global *global, |
| 11591 | char *buf, size_t buflen) |
| 11592 | { |
| 11593 | char *pos, *end; |
| 11594 | int ret; |
| 11595 | struct wpa_supplicant *wpa_s; |
| 11596 | |
| 11597 | pos = buf; |
| 11598 | end = buf + buflen; |
| 11599 | |
| 11600 | #ifdef CONFIG_P2P |
| 11601 | if (global->p2p && !global->p2p_disabled) { |
| 11602 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR |
| 11603 | "\n" |
| 11604 | "p2p_state=%s\n", |
| 11605 | MAC2STR(global->p2p_dev_addr), |
| 11606 | p2p_get_state_txt(global->p2p)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11607 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11608 | return pos - buf; |
| 11609 | pos += ret; |
| 11610 | } else if (global->p2p) { |
| 11611 | ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11612 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11613 | return pos - buf; |
| 11614 | pos += ret; |
| 11615 | } |
| 11616 | #endif /* CONFIG_P2P */ |
| 11617 | |
| 11618 | #ifdef CONFIG_WIFI_DISPLAY |
| 11619 | ret = os_snprintf(pos, end - pos, "wifi_display=%d\n", |
| 11620 | !!global->wifi_display); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11621 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11622 | return pos - buf; |
| 11623 | pos += ret; |
| 11624 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 11625 | |
| 11626 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 11627 | ret = os_snprintf(pos, end - pos, "ifname=%s\n" |
| 11628 | "address=" MACSTR "\n", |
| 11629 | wpa_s->ifname, MAC2STR(wpa_s->own_addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11630 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11631 | return pos - buf; |
| 11632 | pos += ret; |
| 11633 | } |
| 11634 | |
| 11635 | return pos - buf; |
| 11636 | } |
| 11637 | |
| 11638 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11639 | #ifdef CONFIG_FST |
| 11640 | |
| 11641 | static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global, |
| 11642 | char *cmd, char *buf, |
| 11643 | size_t reply_size) |
| 11644 | { |
| 11645 | char ifname[IFNAMSIZ + 1]; |
| 11646 | struct fst_iface_cfg cfg; |
| 11647 | struct wpa_supplicant *wpa_s; |
| 11648 | struct fst_wpa_obj iface_obj; |
| 11649 | |
| 11650 | if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) { |
| 11651 | wpa_s = wpa_supplicant_get_iface(global, ifname); |
| 11652 | if (wpa_s) { |
| 11653 | if (wpa_s->fst) { |
| 11654 | wpa_printf(MSG_INFO, "FST: Already attached"); |
| 11655 | return -1; |
| 11656 | } |
| 11657 | fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj); |
| 11658 | wpa_s->fst = fst_attach(ifname, wpa_s->own_addr, |
| 11659 | &iface_obj, &cfg); |
| 11660 | if (wpa_s->fst) |
| 11661 | return os_snprintf(buf, reply_size, "OK\n"); |
| 11662 | } |
| 11663 | } |
| 11664 | |
| 11665 | return -1; |
| 11666 | } |
| 11667 | |
| 11668 | |
| 11669 | static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global, |
| 11670 | char *cmd, char *buf, |
| 11671 | size_t reply_size) |
| 11672 | { |
| 11673 | char ifname[IFNAMSIZ + 1]; |
| 11674 | struct wpa_supplicant *wpa_s; |
| 11675 | |
| 11676 | if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) { |
| 11677 | wpa_s = wpa_supplicant_get_iface(global, ifname); |
| 11678 | if (wpa_s) { |
| 11679 | if (!fst_iface_detach(ifname)) { |
| 11680 | wpa_s->fst = NULL; |
| 11681 | return os_snprintf(buf, reply_size, "OK\n"); |
| 11682 | } |
| 11683 | } |
| 11684 | } |
| 11685 | |
| 11686 | return -1; |
| 11687 | } |
| 11688 | |
| 11689 | #endif /* CONFIG_FST */ |
| 11690 | |
| 11691 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11692 | char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, |
| 11693 | char *buf, size_t *resp_len) |
| 11694 | { |
| 11695 | char *reply; |
| 11696 | const int reply_size = 2048; |
| 11697 | int reply_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11698 | int level = MSG_DEBUG; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11699 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 11700 | if (os_strncmp(buf, "IFNAME=", 7) == 0) { |
| 11701 | char *pos = os_strchr(buf + 7, ' '); |
| 11702 | if (pos) { |
| 11703 | *pos++ = '\0'; |
| 11704 | return wpas_global_ctrl_iface_ifname(global, |
| 11705 | buf + 7, pos, |
| 11706 | resp_len); |
| 11707 | } |
| 11708 | } |
| 11709 | |
| 11710 | reply = wpas_global_ctrl_iface_redir(global, buf, resp_len); |
| 11711 | if (reply) |
| 11712 | return reply; |
| 11713 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11714 | if (os_strcmp(buf, "PING") == 0) |
| 11715 | level = MSG_EXCESSIVE; |
| 11716 | wpa_hexdump_ascii(level, "RX global ctrl_iface", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11717 | (const u8 *) buf, os_strlen(buf)); |
| 11718 | |
| 11719 | reply = os_malloc(reply_size); |
| 11720 | if (reply == NULL) { |
| 11721 | *resp_len = 1; |
| 11722 | return NULL; |
| 11723 | } |
| 11724 | |
| 11725 | os_memcpy(reply, "OK\n", 3); |
| 11726 | reply_len = 3; |
| 11727 | |
| 11728 | if (os_strcmp(buf, "PING") == 0) { |
| 11729 | os_memcpy(reply, "PONG\n", 5); |
| 11730 | reply_len = 5; |
| 11731 | } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) { |
| 11732 | if (wpa_supplicant_global_iface_add(global, buf + 14)) |
| 11733 | reply_len = -1; |
| 11734 | } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) { |
| 11735 | if (wpa_supplicant_global_iface_remove(global, buf + 17)) |
| 11736 | reply_len = -1; |
| 11737 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
| 11738 | reply_len = wpa_supplicant_global_iface_list( |
| 11739 | global, reply, reply_size); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 11740 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11741 | reply_len = wpa_supplicant_global_iface_interfaces( |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 11742 | global, buf + 10, reply, reply_size); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11743 | #ifdef CONFIG_FST |
| 11744 | } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) { |
| 11745 | reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11, |
| 11746 | reply, |
| 11747 | reply_size); |
| 11748 | } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) { |
| 11749 | reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11, |
| 11750 | reply, |
| 11751 | reply_size); |
| 11752 | } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) { |
| 11753 | reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size); |
| 11754 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11755 | } else if (os_strcmp(buf, "TERMINATE") == 0) { |
| 11756 | wpa_supplicant_terminate_proc(global); |
| 11757 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
| 11758 | wpas_notify_suspend(global); |
| 11759 | } else if (os_strcmp(buf, "RESUME") == 0) { |
| 11760 | wpas_notify_resume(global); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11761 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 11762 | if (wpas_global_ctrl_iface_set(global, buf + 4)) { |
| 11763 | #ifdef CONFIG_P2P |
| 11764 | if (global->p2p_init_wpa_s) { |
| 11765 | os_free(reply); |
| 11766 | /* Check if P2P redirection would work for this |
| 11767 | * command. */ |
| 11768 | return wpa_supplicant_ctrl_iface_process( |
| 11769 | global->p2p_init_wpa_s, |
| 11770 | buf, resp_len); |
| 11771 | } |
| 11772 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11773 | reply_len = -1; |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 11774 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11775 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
| 11776 | if (wpas_global_ctrl_iface_dup_network(global, buf + 12)) |
| 11777 | reply_len = -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11778 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 11779 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { |
| 11780 | if (wpas_global_ctrl_iface_save_config(global)) |
| 11781 | reply_len = -1; |
| 11782 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 11783 | } else if (os_strcmp(buf, "STATUS") == 0) { |
| 11784 | reply_len = wpas_global_ctrl_iface_status(global, reply, |
| 11785 | reply_size); |
Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 11786 | #ifdef CONFIG_MODULE_TESTS |
| 11787 | } else if (os_strcmp(buf, "MODULE_TESTS") == 0) { |
Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 11788 | if (wpas_module_tests() < 0) |
| 11789 | reply_len = -1; |
| 11790 | #endif /* CONFIG_MODULE_TESTS */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11791 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
| 11792 | if (wpa_debug_reopen_file() < 0) |
| 11793 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11794 | } else { |
| 11795 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); |
| 11796 | reply_len = 16; |
| 11797 | } |
| 11798 | |
| 11799 | if (reply_len < 0) { |
| 11800 | os_memcpy(reply, "FAIL\n", 5); |
| 11801 | reply_len = 5; |
| 11802 | } |
| 11803 | |
| 11804 | *resp_len = reply_len; |
| 11805 | return reply; |
| 11806 | } |