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 */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 25 | #include "common/ptksa_cache.h" |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 26 | #include "crypto/tls.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 27 | #include "ap/hostapd.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 28 | #include "eap_peer/eap.h" |
| 29 | #include "eapol_supp/eapol_supp_sm.h" |
| 30 | #include "rsn_supp/wpa.h" |
| 31 | #include "rsn_supp/preauth.h" |
| 32 | #include "rsn_supp/pmksa_cache.h" |
| 33 | #include "l2_packet/l2_packet.h" |
| 34 | #include "wps/wps.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 35 | #include "fst/fst.h" |
| 36 | #include "fst/fst_ctrl_iface.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 37 | #include "config.h" |
| 38 | #include "wpa_supplicant_i.h" |
| 39 | #include "driver_i.h" |
| 40 | #include "wps_supplicant.h" |
| 41 | #include "ibss_rsn.h" |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 42 | #include "wpas_glue.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 43 | #include "ap.h" |
| 44 | #include "p2p_supplicant.h" |
| 45 | #include "p2p/p2p.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 46 | #include "hs20_supplicant.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 47 | #include "wifi_display.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 48 | #include "notify.h" |
| 49 | #include "bss.h" |
| 50 | #include "scan.h" |
| 51 | #include "ctrl_iface.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 52 | #include "interworking.h" |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 53 | #include "bssid_ignore.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 54 | #include "autoscan.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 55 | #include "wnm_sta.h" |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 56 | #include "offchannel.h" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 57 | #include "drivers/driver.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 58 | #include "mesh.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 59 | #include "dpp_supplicant.h" |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 60 | #include "sme.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 61 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 62 | #ifdef __NetBSD__ |
| 63 | #include <net/if_ether.h> |
| 64 | #elif !defined(__CYGWIN__) && !defined(CONFIG_NATIVE_WINDOWS) |
| 65 | #include <net/ethernet.h> |
| 66 | #endif |
| 67 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 68 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
| 69 | char *buf, int len); |
| 70 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 71 | const char *input, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 72 | char *buf, int len); |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 73 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, |
| 74 | char *val); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 75 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 76 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 77 | static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val) |
| 78 | { |
| 79 | char *pos; |
| 80 | u8 addr[ETH_ALEN], *filter = NULL, *n; |
| 81 | size_t count = 0; |
| 82 | |
| 83 | pos = val; |
| 84 | while (pos) { |
| 85 | if (*pos == '\0') |
| 86 | break; |
| 87 | if (hwaddr_aton(pos, addr)) { |
| 88 | os_free(filter); |
| 89 | return -1; |
| 90 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 91 | n = os_realloc_array(filter, count + 1, ETH_ALEN); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 92 | if (n == NULL) { |
| 93 | os_free(filter); |
| 94 | return -1; |
| 95 | } |
| 96 | filter = n; |
| 97 | os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN); |
| 98 | count++; |
| 99 | |
| 100 | pos = os_strchr(pos, ' '); |
| 101 | if (pos) |
| 102 | pos++; |
| 103 | } |
| 104 | |
| 105 | wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN); |
| 106 | os_free(wpa_s->bssid_filter); |
| 107 | wpa_s->bssid_filter = filter; |
| 108 | wpa_s->bssid_filter_count = count; |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 114 | static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val) |
| 115 | { |
| 116 | char *pos; |
| 117 | u8 addr[ETH_ALEN], *bssid = NULL, *n; |
| 118 | struct wpa_ssid_value *ssid = NULL, *ns; |
| 119 | size_t count = 0, ssid_count = 0; |
| 120 | struct wpa_ssid *c; |
| 121 | |
| 122 | /* |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 123 | * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | "" |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 124 | * SSID_SPEC ::= ssid <SSID_HEX> |
| 125 | * BSSID_SPEC ::= bssid <BSSID_HEX> |
| 126 | */ |
| 127 | |
| 128 | pos = val; |
| 129 | while (pos) { |
| 130 | if (*pos == '\0') |
| 131 | break; |
| 132 | if (os_strncmp(pos, "bssid ", 6) == 0) { |
| 133 | int res; |
| 134 | pos += 6; |
| 135 | res = hwaddr_aton2(pos, addr); |
| 136 | if (res < 0) { |
| 137 | os_free(ssid); |
| 138 | os_free(bssid); |
| 139 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " |
| 140 | "BSSID value '%s'", pos); |
| 141 | return -1; |
| 142 | } |
| 143 | pos += res; |
| 144 | n = os_realloc_array(bssid, count + 1, ETH_ALEN); |
| 145 | if (n == NULL) { |
| 146 | os_free(ssid); |
| 147 | os_free(bssid); |
| 148 | return -1; |
| 149 | } |
| 150 | bssid = n; |
| 151 | os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN); |
| 152 | count++; |
| 153 | } else if (os_strncmp(pos, "ssid ", 5) == 0) { |
| 154 | char *end; |
| 155 | pos += 5; |
| 156 | |
| 157 | end = pos; |
| 158 | while (*end) { |
| 159 | if (*end == '\0' || *end == ' ') |
| 160 | break; |
| 161 | end++; |
| 162 | } |
| 163 | |
| 164 | ns = os_realloc_array(ssid, ssid_count + 1, |
| 165 | sizeof(struct wpa_ssid_value)); |
| 166 | if (ns == NULL) { |
| 167 | os_free(ssid); |
| 168 | os_free(bssid); |
| 169 | return -1; |
| 170 | } |
| 171 | ssid = ns; |
| 172 | |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 173 | if ((end - pos) & 0x01 || |
| 174 | end - pos > 2 * SSID_MAX_LEN || |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 175 | hexstr2bin(pos, ssid[ssid_count].ssid, |
| 176 | (end - pos) / 2) < 0) { |
| 177 | os_free(ssid); |
| 178 | os_free(bssid); |
| 179 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " |
| 180 | "SSID value '%s'", pos); |
| 181 | return -1; |
| 182 | } |
| 183 | ssid[ssid_count].ssid_len = (end - pos) / 2; |
| 184 | wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID", |
| 185 | ssid[ssid_count].ssid, |
| 186 | ssid[ssid_count].ssid_len); |
| 187 | ssid_count++; |
| 188 | pos = end; |
| 189 | } else { |
| 190 | wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value " |
| 191 | "'%s'", pos); |
| 192 | os_free(ssid); |
| 193 | os_free(bssid); |
| 194 | return -1; |
| 195 | } |
| 196 | |
| 197 | pos = os_strchr(pos, ' '); |
| 198 | if (pos) |
| 199 | pos++; |
| 200 | } |
| 201 | |
| 202 | wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN); |
| 203 | os_free(wpa_s->disallow_aps_bssid); |
| 204 | wpa_s->disallow_aps_bssid = bssid; |
| 205 | wpa_s->disallow_aps_bssid_count = count; |
| 206 | |
| 207 | wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count); |
| 208 | os_free(wpa_s->disallow_aps_ssid); |
| 209 | wpa_s->disallow_aps_ssid = ssid; |
| 210 | wpa_s->disallow_aps_ssid_count = ssid_count; |
| 211 | |
| 212 | if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING) |
| 213 | return 0; |
| 214 | |
| 215 | c = wpa_s->current_ssid; |
| 216 | if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS) |
| 217 | return 0; |
| 218 | |
| 219 | if (!disallowed_bssid(wpa_s, wpa_s->bssid) && |
| 220 | !disallowed_ssid(wpa_s, c->ssid, c->ssid_len)) |
| 221 | return 0; |
| 222 | |
| 223 | wpa_printf(MSG_DEBUG, "Disconnect and try to find another network " |
| 224 | "because current AP was marked disallowed"); |
| 225 | |
| 226 | #ifdef CONFIG_SME |
| 227 | wpa_s->sme.prev_bssid_set = 0; |
| 228 | #endif /* CONFIG_SME */ |
| 229 | wpa_s->reassociate = 1; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 230 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 231 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 232 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 238 | #ifndef CONFIG_NO_CONFIG_BLOBS |
| 239 | static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos) |
| 240 | { |
| 241 | char *name = pos; |
| 242 | struct wpa_config_blob *blob; |
| 243 | size_t len; |
| 244 | |
| 245 | pos = os_strchr(pos, ' '); |
| 246 | if (pos == NULL) |
| 247 | return -1; |
| 248 | *pos++ = '\0'; |
| 249 | len = os_strlen(pos); |
| 250 | if (len & 1) |
| 251 | return -1; |
| 252 | |
| 253 | wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name); |
| 254 | blob = os_zalloc(sizeof(*blob)); |
| 255 | if (blob == NULL) |
| 256 | return -1; |
| 257 | blob->name = os_strdup(name); |
| 258 | blob->data = os_malloc(len / 2); |
| 259 | if (blob->name == NULL || blob->data == NULL) { |
| 260 | wpa_config_free_blob(blob); |
| 261 | return -1; |
| 262 | } |
| 263 | |
| 264 | if (hexstr2bin(pos, blob->data, len / 2) < 0) { |
| 265 | wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data"); |
| 266 | wpa_config_free_blob(blob); |
| 267 | return -1; |
| 268 | } |
| 269 | blob->len = len / 2; |
| 270 | |
| 271 | wpa_config_set_blob(wpa_s->conf, blob); |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
| 276 | |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 277 | |
| 278 | static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd) |
| 279 | { |
| 280 | char *params; |
| 281 | char *pos; |
| 282 | int *freqs = NULL; |
| 283 | int ret; |
| 284 | |
| 285 | if (atoi(cmd)) { |
| 286 | params = os_strchr(cmd, ' '); |
| 287 | os_free(wpa_s->manual_sched_scan_freqs); |
| 288 | if (params) { |
| 289 | params++; |
| 290 | pos = os_strstr(params, "freq="); |
| 291 | if (pos) |
| 292 | freqs = freq_range_to_channel_list(wpa_s, |
| 293 | pos + 5); |
| 294 | } |
| 295 | wpa_s->manual_sched_scan_freqs = freqs; |
| 296 | ret = wpas_start_pno(wpa_s); |
| 297 | } else { |
| 298 | ret = wpas_stop_pno(wpa_s); |
| 299 | } |
| 300 | return ret; |
| 301 | } |
| 302 | |
| 303 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 304 | static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *bands) |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 305 | { |
| 306 | union wpa_event_data event; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 307 | u32 setband_mask = WPA_SETBAND_AUTO; |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 308 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 309 | /* |
| 310 | * For example: |
| 311 | * SET setband 2G,6G |
| 312 | * SET setband 5G |
| 313 | * SET setband AUTO |
| 314 | */ |
| 315 | if (!os_strstr(bands, "AUTO")) { |
| 316 | if (os_strstr(bands, "5G")) |
| 317 | setband_mask |= WPA_SETBAND_5G; |
| 318 | if (os_strstr(bands, "6G")) |
| 319 | setband_mask |= WPA_SETBAND_6G; |
| 320 | if (os_strstr(bands, "2G")) |
| 321 | setband_mask |= WPA_SETBAND_2G; |
| 322 | if (setband_mask == WPA_SETBAND_AUTO) |
| 323 | return -1; |
| 324 | } |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 325 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 326 | wpa_s->setband_mask = setband_mask; |
| 327 | if (wpa_drv_setband(wpa_s, wpa_s->setband_mask) == 0) { |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 328 | os_memset(&event, 0, sizeof(event)); |
| 329 | event.channel_list_changed.initiator = REGDOM_SET_BY_USER; |
| 330 | event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN; |
| 331 | wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event); |
| 332 | } |
| 333 | |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 338 | static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s, |
| 339 | const char *cmd) |
| 340 | { |
| 341 | struct wpabuf *lci; |
| 342 | |
| 343 | if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) { |
| 344 | wpabuf_free(wpa_s->lci); |
| 345 | wpa_s->lci = NULL; |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | lci = wpabuf_parse_bin(cmd); |
| 350 | if (!lci) |
| 351 | return -1; |
| 352 | |
| 353 | if (os_get_reltime(&wpa_s->lci_time)) { |
| 354 | wpabuf_free(lci); |
| 355 | return -1; |
| 356 | } |
| 357 | |
| 358 | wpabuf_free(wpa_s->lci); |
| 359 | wpa_s->lci = lci; |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 365 | static int |
| 366 | wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd) |
| 367 | { |
| 368 | int relative_rssi; |
| 369 | |
| 370 | if (os_strcmp(cmd, "disable") == 0) { |
| 371 | wpa_s->srp.relative_rssi_set = 0; |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | relative_rssi = atoi(cmd); |
| 376 | if (relative_rssi < 0 || relative_rssi > 100) |
| 377 | return -1; |
| 378 | wpa_s->srp.relative_rssi = relative_rssi; |
| 379 | wpa_s->srp.relative_rssi_set = 1; |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | |
| 384 | static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s, |
| 385 | const char *cmd) |
| 386 | { |
| 387 | char *pos; |
| 388 | int adjust_rssi; |
| 389 | |
| 390 | /* <band>:adjust_value */ |
| 391 | pos = os_strchr(cmd, ':'); |
| 392 | if (!pos) |
| 393 | return -1; |
| 394 | pos++; |
| 395 | adjust_rssi = atoi(pos); |
| 396 | if (adjust_rssi < -100 || adjust_rssi > 100) |
| 397 | return -1; |
| 398 | |
| 399 | if (os_strncmp(cmd, "2G", 2) == 0) |
| 400 | wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G; |
| 401 | else if (os_strncmp(cmd, "5G", 2) == 0) |
| 402 | wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G; |
| 403 | else |
| 404 | return -1; |
| 405 | |
| 406 | wpa_s->srp.relative_adjust_rssi = adjust_rssi; |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | |
| 412 | static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s, |
| 413 | const char *cmd) |
| 414 | { |
| 415 | struct wpabuf *ric_ies; |
| 416 | |
| 417 | if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) { |
| 418 | wpabuf_free(wpa_s->ric_ies); |
| 419 | wpa_s->ric_ies = NULL; |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | ric_ies = wpabuf_parse_bin(cmd); |
| 424 | if (!ric_ies) |
| 425 | return -1; |
| 426 | |
| 427 | wpabuf_free(wpa_s->ric_ies); |
| 428 | wpa_s->ric_ies = ric_ies; |
| 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 434 | #ifdef CONFIG_TESTING_OPTIONS |
| 435 | static int wpas_ctrl_iface_set_dso(struct wpa_supplicant *wpa_s, |
| 436 | const char *val) |
| 437 | { |
| 438 | u8 bssid[ETH_ALEN]; |
| 439 | const char *pos = val; |
| 440 | struct driver_signal_override *dso = NULL, *tmp, parsed; |
| 441 | |
| 442 | if (hwaddr_aton(pos, bssid)) |
| 443 | return -1; |
| 444 | pos = os_strchr(pos, ' '); |
| 445 | |
| 446 | dl_list_for_each(tmp, &wpa_s->drv_signal_override, |
| 447 | struct driver_signal_override, list) { |
| 448 | if (os_memcmp(bssid, tmp->bssid, ETH_ALEN) == 0) { |
| 449 | dso = tmp; |
| 450 | break; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | if (!pos) { |
| 455 | /* Remove existing entry */ |
| 456 | if (dso) { |
| 457 | dl_list_del(&dso->list); |
| 458 | os_free(dso); |
| 459 | } |
| 460 | return 0; |
| 461 | } |
| 462 | pos++; |
| 463 | |
| 464 | /* Update an existing entry or add a new one */ |
| 465 | os_memset(&parsed, 0, sizeof(parsed)); |
| 466 | if (sscanf(pos, "%d %d %d %d %d", |
| 467 | &parsed.si_current_signal, |
| 468 | &parsed.si_avg_signal, |
| 469 | &parsed.si_avg_beacon_signal, |
| 470 | &parsed.si_current_noise, |
| 471 | &parsed.scan_level) != 5) |
| 472 | return -1; |
| 473 | |
| 474 | if (!dso) { |
| 475 | dso = os_zalloc(sizeof(*dso)); |
| 476 | if (!dso) |
| 477 | return -1; |
| 478 | os_memcpy(dso->bssid, bssid, ETH_ALEN); |
| 479 | dl_list_add(&wpa_s->drv_signal_override, &dso->list); |
| 480 | } |
| 481 | dso->si_current_signal = parsed.si_current_signal; |
| 482 | dso->si_avg_signal = parsed.si_avg_signal; |
| 483 | dso->si_avg_beacon_signal = parsed.si_avg_beacon_signal; |
| 484 | dso->si_current_noise = parsed.si_current_noise; |
| 485 | dso->scan_level = parsed.scan_level; |
| 486 | |
| 487 | return 0; |
| 488 | } |
| 489 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 490 | |
| 491 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 492 | static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, |
| 493 | char *cmd) |
| 494 | { |
| 495 | char *value; |
| 496 | int ret = 0; |
| 497 | |
| 498 | value = os_strchr(cmd, ' '); |
| 499 | if (value == NULL) |
| 500 | return -1; |
| 501 | *value++ = '\0'; |
| 502 | |
| 503 | wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value); |
| 504 | if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) { |
| 505 | eapol_sm_configure(wpa_s->eapol, |
| 506 | atoi(value), -1, -1, -1); |
| 507 | } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) { |
| 508 | eapol_sm_configure(wpa_s->eapol, |
| 509 | -1, atoi(value), -1, -1); |
| 510 | } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) { |
| 511 | eapol_sm_configure(wpa_s->eapol, |
| 512 | -1, -1, atoi(value), -1); |
| 513 | } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) { |
| 514 | eapol_sm_configure(wpa_s->eapol, |
| 515 | -1, -1, -1, atoi(value)); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 516 | #ifdef CONFIG_TESTING_OPTIONS |
| 517 | } else if (os_strcasecmp(cmd, "EAPOL::portControl") == 0) { |
| 518 | if (os_strcmp(value, "Auto") == 0) |
| 519 | eapol_sm_notify_portControl(wpa_s->eapol, Auto); |
| 520 | else if (os_strcmp(value, "ForceUnauthorized") == 0) |
| 521 | eapol_sm_notify_portControl(wpa_s->eapol, |
| 522 | ForceUnauthorized); |
| 523 | else if (os_strcmp(value, "ForceAuthorized") == 0) |
| 524 | eapol_sm_notify_portControl(wpa_s->eapol, |
| 525 | ForceAuthorized); |
| 526 | else |
| 527 | ret = -1; |
| 528 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 529 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) { |
| 530 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 531 | atoi(value))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 532 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 533 | } else { |
| 534 | value[-1] = '='; |
| 535 | wpa_config_process_global(wpa_s->conf, cmd, -1); |
| 536 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 537 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == |
| 538 | 0) { |
| 539 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 540 | atoi(value))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 541 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 542 | } else { |
| 543 | value[-1] = '='; |
| 544 | wpa_config_process_global(wpa_s->conf, cmd, -1); |
| 545 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 546 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 547 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, |
| 548 | atoi(value))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 549 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 550 | } else { |
| 551 | value[-1] = '='; |
| 552 | wpa_config_process_global(wpa_s->conf, cmd, -1); |
| 553 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 554 | } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) { |
| 555 | wpa_s->wps_fragment_size = atoi(value); |
| 556 | #ifdef CONFIG_WPS_TESTING |
| 557 | } else if (os_strcasecmp(cmd, "wps_version_number") == 0) { |
| 558 | long int val; |
| 559 | val = strtol(value, NULL, 0); |
| 560 | if (val < 0 || val > 0xff) { |
| 561 | ret = -1; |
| 562 | wpa_printf(MSG_DEBUG, "WPS: Invalid " |
| 563 | "wps_version_number %ld", val); |
| 564 | } else { |
| 565 | wps_version_number = val; |
| 566 | wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS " |
| 567 | "version %u.%u", |
| 568 | (wps_version_number & 0xf0) >> 4, |
| 569 | wps_version_number & 0x0f); |
| 570 | } |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 571 | } else if (os_strcasecmp(cmd, "wps_testing_stub_cred") == 0) { |
| 572 | wps_testing_stub_cred = atoi(value); |
| 573 | wpa_printf(MSG_DEBUG, "WPS: Testing - stub_cred=%d", |
| 574 | wps_testing_stub_cred); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 575 | } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) { |
| 576 | wps_corrupt_pkhash = atoi(value); |
| 577 | wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d", |
| 578 | wps_corrupt_pkhash); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 579 | } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) { |
| 580 | if (value[0] == '\0') { |
| 581 | wps_force_auth_types_in_use = 0; |
| 582 | } else { |
| 583 | wps_force_auth_types = strtol(value, NULL, 0); |
| 584 | wps_force_auth_types_in_use = 1; |
| 585 | } |
| 586 | } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) { |
| 587 | if (value[0] == '\0') { |
| 588 | wps_force_encr_types_in_use = 0; |
| 589 | } else { |
| 590 | wps_force_encr_types = strtol(value, NULL, 0); |
| 591 | wps_force_encr_types_in_use = 1; |
| 592 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 593 | #endif /* CONFIG_WPS_TESTING */ |
| 594 | } else if (os_strcasecmp(cmd, "ampdu") == 0) { |
| 595 | if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0) |
| 596 | ret = -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 597 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 598 | #ifdef CONFIG_TDLS_TESTING |
| 599 | } else if (os_strcasecmp(cmd, "tdls_testing") == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 600 | tdls_testing = strtol(value, NULL, 0); |
| 601 | wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing); |
| 602 | #endif /* CONFIG_TDLS_TESTING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 603 | } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) { |
| 604 | int disabled = atoi(value); |
| 605 | wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled); |
| 606 | if (disabled) { |
| 607 | if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0) |
| 608 | ret = -1; |
| 609 | } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0) |
| 610 | ret = -1; |
| 611 | wpa_tdls_enable(wpa_s->wpa, !disabled); |
| 612 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 613 | } else if (os_strcasecmp(cmd, "pno") == 0) { |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 614 | ret = wpas_ctrl_pno(wpa_s, value); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 615 | } else if (os_strcasecmp(cmd, "radio_disabled") == 0) { |
| 616 | int disabled = atoi(value); |
| 617 | if (wpa_drv_radio_disable(wpa_s, disabled) < 0) |
| 618 | ret = -1; |
| 619 | else if (disabled) |
| 620 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
| 621 | } else if (os_strcasecmp(cmd, "uapsd") == 0) { |
| 622 | if (os_strcmp(value, "disable") == 0) |
| 623 | wpa_s->set_sta_uapsd = 0; |
| 624 | else { |
| 625 | int be, bk, vi, vo; |
| 626 | char *pos; |
| 627 | /* format: BE,BK,VI,VO;max SP Length */ |
| 628 | be = atoi(value); |
| 629 | pos = os_strchr(value, ','); |
| 630 | if (pos == NULL) |
| 631 | return -1; |
| 632 | pos++; |
| 633 | bk = atoi(pos); |
| 634 | pos = os_strchr(pos, ','); |
| 635 | if (pos == NULL) |
| 636 | return -1; |
| 637 | pos++; |
| 638 | vi = atoi(pos); |
| 639 | pos = os_strchr(pos, ','); |
| 640 | if (pos == NULL) |
| 641 | return -1; |
| 642 | pos++; |
| 643 | vo = atoi(pos); |
| 644 | /* ignore max SP Length for now */ |
| 645 | |
| 646 | wpa_s->set_sta_uapsd = 1; |
| 647 | wpa_s->sta_uapsd = 0; |
| 648 | if (be) |
| 649 | wpa_s->sta_uapsd |= BIT(0); |
| 650 | if (bk) |
| 651 | wpa_s->sta_uapsd |= BIT(1); |
| 652 | if (vi) |
| 653 | wpa_s->sta_uapsd |= BIT(2); |
| 654 | if (vo) |
| 655 | wpa_s->sta_uapsd |= BIT(3); |
| 656 | } |
Jouni Malinen | 21d6bc8 | 2012-04-10 16:17:59 -0700 | [diff] [blame] | 657 | } else if (os_strcasecmp(cmd, "ps") == 0) { |
| 658 | ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 659 | #ifdef CONFIG_WIFI_DISPLAY |
| 660 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { |
Dmitry Shmidt | ed003d2 | 2014-02-06 10:09:12 -0800 | [diff] [blame] | 661 | int enabled = !!atoi(value); |
| 662 | if (enabled && !wpa_s->global->p2p) |
| 663 | ret = -1; |
| 664 | else |
| 665 | wifi_display_enable(wpa_s->global, enabled); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 666 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 667 | } else if (os_strcasecmp(cmd, "bssid_filter") == 0) { |
| 668 | ret = set_bssid_filter(wpa_s, value); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 669 | } else if (os_strcasecmp(cmd, "disallow_aps") == 0) { |
| 670 | ret = set_disallow_aps(wpa_s, value); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 671 | } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) { |
| 672 | wpa_s->no_keep_alive = !!atoi(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 673 | #ifdef CONFIG_DPP |
| 674 | } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) { |
| 675 | os_free(wpa_s->dpp_configurator_params); |
| 676 | wpa_s->dpp_configurator_params = os_strdup(value); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 677 | #ifdef CONFIG_DPP2 |
| 678 | dpp_controller_set_params(wpa_s->dpp, value); |
| 679 | #endif /* CONFIG_DPP2 */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 680 | } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) { |
| 681 | wpa_s->dpp_init_max_tries = atoi(value); |
| 682 | } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) { |
| 683 | wpa_s->dpp_init_retry_time = atoi(value); |
| 684 | } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) { |
| 685 | wpa_s->dpp_resp_wait_time = atoi(value); |
| 686 | } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) { |
| 687 | wpa_s->dpp_resp_max_tries = atoi(value); |
| 688 | } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) { |
| 689 | wpa_s->dpp_resp_retry_time = atoi(value); |
| 690 | #ifdef CONFIG_TESTING_OPTIONS |
| 691 | } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) { |
| 692 | if (hwaddr_aton(value, dpp_pkex_own_mac_override)) |
| 693 | ret = -1; |
| 694 | } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) { |
| 695 | if (hwaddr_aton(value, dpp_pkex_peer_mac_override)) |
| 696 | ret = -1; |
| 697 | } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) { |
| 698 | size_t hex_len = os_strlen(value); |
| 699 | |
| 700 | if (hex_len > |
| 701 | 2 * sizeof(dpp_pkex_ephemeral_key_override)) |
| 702 | ret = -1; |
| 703 | else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override, |
| 704 | hex_len / 2)) |
| 705 | ret = -1; |
| 706 | else |
| 707 | dpp_pkex_ephemeral_key_override_len = hex_len / 2; |
| 708 | } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) { |
| 709 | size_t hex_len = os_strlen(value); |
| 710 | |
| 711 | if (hex_len > 2 * sizeof(dpp_protocol_key_override)) |
| 712 | ret = -1; |
| 713 | else if (hexstr2bin(value, dpp_protocol_key_override, |
| 714 | hex_len / 2)) |
| 715 | ret = -1; |
| 716 | else |
| 717 | dpp_protocol_key_override_len = hex_len / 2; |
| 718 | } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) { |
| 719 | size_t hex_len = os_strlen(value); |
| 720 | |
| 721 | if (hex_len > 2 * sizeof(dpp_nonce_override)) |
| 722 | ret = -1; |
| 723 | else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2)) |
| 724 | ret = -1; |
| 725 | else |
| 726 | dpp_nonce_override_len = hex_len / 2; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 727 | } else if (os_strcasecmp(cmd, "dpp_version_override") == 0) { |
| 728 | dpp_version_override = atoi(value); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 729 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 730 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 731 | #ifdef CONFIG_TESTING_OPTIONS |
| 732 | } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) { |
| 733 | wpa_s->ext_mgmt_frame_handling = !!atoi(value); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 734 | } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) { |
| 735 | wpa_s->ext_eapol_frame_io = !!atoi(value); |
| 736 | #ifdef CONFIG_AP |
| 737 | if (wpa_s->ap_iface) { |
| 738 | wpa_s->ap_iface->bss[0]->ext_eapol_frame_io = |
| 739 | wpa_s->ext_eapol_frame_io; |
| 740 | } |
| 741 | #endif /* CONFIG_AP */ |
| 742 | } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) { |
| 743 | wpa_s->extra_roc_dur = atoi(value); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 744 | } else if (os_strcasecmp(cmd, "test_failure") == 0) { |
| 745 | wpa_s->test_failure = atoi(value); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 746 | } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) { |
| 747 | wpa_s->p2p_go_csa_on_inv = !!atoi(value); |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 748 | } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) { |
| 749 | wpa_s->ignore_auth_resp = !!atoi(value); |
| 750 | } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) { |
| 751 | wpa_s->ignore_assoc_disallow = !!atoi(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 752 | wpa_drv_ignore_assoc_disallow(wpa_s, |
| 753 | wpa_s->ignore_assoc_disallow); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 754 | } else if (os_strcasecmp(cmd, "disable_sa_query") == 0) { |
| 755 | wpa_s->disable_sa_query = !!atoi(value); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 756 | } else if (os_strcasecmp(cmd, "ignore_sae_h2e_only") == 0) { |
| 757 | wpa_s->ignore_sae_h2e_only = !!atoi(value); |
| 758 | } else if (os_strcasecmp(cmd, "extra_sae_rejected_groups") == 0) { |
| 759 | char *pos; |
| 760 | |
| 761 | os_free(wpa_s->extra_sae_rejected_groups); |
| 762 | wpa_s->extra_sae_rejected_groups = NULL; |
| 763 | pos = value; |
| 764 | while (pos && pos[0]) { |
| 765 | int group; |
| 766 | |
| 767 | group = atoi(pos); |
| 768 | wpa_printf(MSG_DEBUG, |
| 769 | "TESTING: Extra rejection of SAE group %d", |
| 770 | group); |
| 771 | if (group) |
| 772 | int_array_add_unique( |
| 773 | &wpa_s->extra_sae_rejected_groups, |
| 774 | group); |
| 775 | pos = os_strchr(pos, ' '); |
| 776 | if (!pos) |
| 777 | break; |
| 778 | pos++; |
| 779 | } |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 780 | } else if (os_strcasecmp(cmd, "ft_rsnxe_used") == 0) { |
| 781 | wpa_s->ft_rsnxe_used = atoi(value); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 782 | } else if (os_strcasecmp(cmd, "oci_freq_override_eapol") == 0) { |
| 783 | wpa_s->oci_freq_override_eapol = atoi(value); |
| 784 | } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_req") == 0) { |
| 785 | wpa_s->oci_freq_override_saquery_req = atoi(value); |
| 786 | } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_resp") == 0) { |
| 787 | wpa_s->oci_freq_override_saquery_resp = atoi(value); |
| 788 | } else if (os_strcasecmp(cmd, "oci_freq_override_eapol_g2") == 0) { |
| 789 | wpa_s->oci_freq_override_eapol_g2 = atoi(value); |
| 790 | /* Populate value to wpa_sm if already associated. */ |
| 791 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_EAPOL_G2, |
| 792 | wpa_s->oci_freq_override_eapol_g2); |
| 793 | } else if (os_strcasecmp(cmd, "oci_freq_override_ft_assoc") == 0) { |
| 794 | wpa_s->oci_freq_override_ft_assoc = atoi(value); |
| 795 | /* Populate value to wpa_sm if already associated. */ |
| 796 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_FT_ASSOC, |
| 797 | wpa_s->oci_freq_override_ft_assoc); |
| 798 | } else if (os_strcasecmp(cmd, "oci_freq_override_fils_assoc") == 0) { |
| 799 | wpa_s->oci_freq_override_fils_assoc = atoi(value); |
| 800 | } else if (os_strcasecmp(cmd, "oci_freq_override_wnm_sleep") == 0) { |
| 801 | wpa_s->oci_freq_override_wnm_sleep = atoi(value); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 802 | } else if (os_strcasecmp(cmd, "rsne_override_eapol") == 0) { |
| 803 | wpabuf_free(wpa_s->rsne_override_eapol); |
| 804 | if (os_strcmp(value, "NULL") == 0) |
| 805 | wpa_s->rsne_override_eapol = NULL; |
| 806 | else |
| 807 | wpa_s->rsne_override_eapol = wpabuf_parse_bin(value); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 808 | } else if (os_strcasecmp(cmd, "rsnxe_override_assoc") == 0) { |
| 809 | wpabuf_free(wpa_s->rsnxe_override_assoc); |
| 810 | if (os_strcmp(value, "NULL") == 0) |
| 811 | wpa_s->rsnxe_override_assoc = NULL; |
| 812 | else |
| 813 | wpa_s->rsnxe_override_assoc = wpabuf_parse_bin(value); |
| 814 | } else if (os_strcasecmp(cmd, "rsnxe_override_eapol") == 0) { |
| 815 | wpabuf_free(wpa_s->rsnxe_override_eapol); |
| 816 | if (os_strcmp(value, "NULL") == 0) |
| 817 | wpa_s->rsnxe_override_eapol = NULL; |
| 818 | else |
| 819 | wpa_s->rsnxe_override_eapol = wpabuf_parse_bin(value); |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 820 | } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) { |
| 821 | wpa_s->reject_btm_req_reason = atoi(value); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 822 | } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) { |
| 823 | os_free(wpa_s->get_pref_freq_list_override); |
| 824 | if (!value[0]) |
| 825 | wpa_s->get_pref_freq_list_override = NULL; |
| 826 | else |
| 827 | wpa_s->get_pref_freq_list_override = os_strdup(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 828 | } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) { |
| 829 | wpabuf_free(wpa_s->sae_commit_override); |
| 830 | if (value[0] == '\0') |
| 831 | wpa_s->sae_commit_override = NULL; |
| 832 | else |
| 833 | wpa_s->sae_commit_override = wpabuf_parse_bin(value); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 834 | } else if (os_strcasecmp(cmd, "driver_signal_override") == 0) { |
| 835 | ret = wpas_ctrl_iface_set_dso(wpa_s, value); |
Jimmy Chen | aace8cd | 2021-04-13 14:55:52 +0800 | [diff] [blame] | 836 | } else if (os_strcasecmp(cmd, "force_hunting_and_pecking_pwe") == 0) { |
| 837 | wpa_s->force_hunting_and_pecking_pwe = (atoi(value) != 0) ? 1 : 0; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 838 | } else if (os_strcasecmp(cmd, "disable_scs_support") == 0) { |
| 839 | wpa_s->disable_scs_support = !!atoi(value); |
| 840 | } else if (os_strcasecmp(cmd, "disable_mscs_support") == 0) { |
| 841 | wpa_s->disable_mscs_support = !!atoi(value); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 842 | } else if (os_strcasecmp(cmd, "disable_eapol_g2_tx") == 0) { |
| 843 | wpa_s->disable_eapol_g2_tx = !!atoi(value); |
| 844 | /* Populate value to wpa_sm if already associated. */ |
| 845 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DISABLE_EAPOL_G2_TX, |
| 846 | wpa_s->disable_eapol_g2_tx); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 847 | #ifdef CONFIG_DPP |
| 848 | } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) { |
| 849 | os_free(wpa_s->dpp_config_obj_override); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 850 | if (value[0] == '\0') |
| 851 | wpa_s->dpp_config_obj_override = NULL; |
| 852 | else |
| 853 | wpa_s->dpp_config_obj_override = os_strdup(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 854 | } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) { |
| 855 | os_free(wpa_s->dpp_discovery_override); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 856 | if (value[0] == '\0') |
| 857 | wpa_s->dpp_discovery_override = NULL; |
| 858 | else |
| 859 | wpa_s->dpp_discovery_override = os_strdup(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 860 | } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) { |
| 861 | os_free(wpa_s->dpp_groups_override); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 862 | if (value[0] == '\0') |
| 863 | wpa_s->dpp_groups_override = NULL; |
| 864 | else |
| 865 | wpa_s->dpp_groups_override = os_strdup(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 866 | } else if (os_strcasecmp(cmd, |
| 867 | "dpp_ignore_netaccesskey_mismatch") == 0) { |
| 868 | wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value); |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 869 | } else if (os_strcasecmp(cmd, "dpp_discard_public_action") == 0) { |
| 870 | wpa_s->dpp_discard_public_action = atoi(value); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 871 | } else if (os_strcasecmp(cmd, "dpp_test") == 0) { |
| 872 | dpp_test = atoi(value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 873 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 874 | #endif /* CONFIG_TESTING_OPTIONS */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 875 | #ifdef CONFIG_FILS |
| 876 | } else if (os_strcasecmp(cmd, "disable_fils") == 0) { |
| 877 | wpa_s->disable_fils = !!atoi(value); |
| 878 | wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils); |
| 879 | wpa_supplicant_set_default_scan_ies(wpa_s); |
| 880 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 881 | #ifndef CONFIG_NO_CONFIG_BLOBS |
| 882 | } else if (os_strcmp(cmd, "blob") == 0) { |
| 883 | ret = wpas_ctrl_set_blob(wpa_s, value); |
| 884 | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 885 | } else if (os_strcasecmp(cmd, "setband") == 0) { |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 886 | ret = wpas_ctrl_set_band(wpa_s, value); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 887 | #ifdef CONFIG_MBO |
| 888 | } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) { |
| 889 | ret = wpas_mbo_update_non_pref_chan(wpa_s, value); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 890 | if (ret == 0) { |
| 891 | value[-1] = '='; |
| 892 | wpa_config_process_global(wpa_s->conf, cmd, -1); |
| 893 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 894 | } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) { |
| 895 | wpas_mbo_update_cell_capa(wpa_s, atoi(value)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 896 | } else if (os_strcasecmp(cmd, "oce") == 0) { |
| 897 | wpa_s->conf->oce = atoi(value); |
| 898 | if (wpa_s->conf->oce) { |
| 899 | if ((wpa_s->conf->oce & OCE_STA) && |
| 900 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA)) |
| 901 | wpa_s->enable_oce = OCE_STA; |
| 902 | |
| 903 | if ((wpa_s->conf->oce & OCE_STA_CFON) && |
| 904 | (wpa_s->drv_flags & |
| 905 | WPA_DRIVER_FLAGS_OCE_STA_CFON)) { |
| 906 | /* TODO: Need to add STA-CFON support */ |
| 907 | wpa_printf(MSG_ERROR, |
| 908 | "OCE STA-CFON feature is not yet supported"); |
| 909 | return -1; |
| 910 | } |
| 911 | } else { |
| 912 | wpa_s->enable_oce = 0; |
| 913 | } |
| 914 | wpa_supplicant_set_default_scan_ies(wpa_s); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 915 | #endif /* CONFIG_MBO */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 916 | } else if (os_strcasecmp(cmd, "lci") == 0) { |
| 917 | ret = wpas_ctrl_iface_set_lci(wpa_s, value); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 918 | } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) { |
| 919 | ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value)); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 920 | } else if (os_strcasecmp(cmd, "relative_rssi") == 0) { |
| 921 | ret = wpas_ctrl_set_relative_rssi(wpa_s, value); |
| 922 | } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) { |
| 923 | ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value); |
| 924 | } else if (os_strcasecmp(cmd, "ric_ies") == 0) { |
| 925 | ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 926 | } else if (os_strcasecmp(cmd, "roaming") == 0) { |
| 927 | ret = wpa_drv_roaming(wpa_s, atoi(value), NULL); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 928 | #ifdef CONFIG_WNM |
| 929 | } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) { |
| 930 | struct wpabuf *elems; |
| 931 | |
| 932 | elems = wpabuf_parse_bin(value); |
| 933 | if (!elems) |
| 934 | return -1; |
| 935 | wnm_set_coloc_intf_elems(wpa_s, elems); |
| 936 | #endif /* CONFIG_WNM */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 937 | } else if (os_strcasecmp(cmd, "enable_dscp_policy_capa") == 0) { |
| 938 | wpa_s->enable_dscp_policy_capa = !!atoi(value); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 939 | } else { |
| 940 | value[-1] = '='; |
| 941 | ret = wpa_config_process_global(wpa_s->conf, cmd, -1); |
| 942 | if (ret == 0) |
| 943 | wpa_supplicant_update_config(wpa_s); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 944 | else if (ret == 1) |
| 945 | ret = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | return ret; |
| 949 | } |
| 950 | |
| 951 | |
| 952 | static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s, |
| 953 | char *cmd, char *buf, size_t buflen) |
| 954 | { |
Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 955 | int res = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 956 | |
| 957 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd); |
| 958 | |
| 959 | if (os_strcmp(cmd, "version") == 0) { |
| 960 | res = os_snprintf(buf, buflen, "%s", VERSION_STR); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 961 | } else if (os_strcasecmp(cmd, "max_command_len") == 0) { |
| 962 | res = os_snprintf(buf, buflen, "%u", CTRL_IFACE_MAX_LEN); |
Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 963 | } else if (os_strcasecmp(cmd, "country") == 0) { |
| 964 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) |
| 965 | res = os_snprintf(buf, buflen, "%c%c", |
| 966 | wpa_s->conf->country[0], |
| 967 | wpa_s->conf->country[1]); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 968 | #ifdef CONFIG_WIFI_DISPLAY |
| 969 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { |
Dmitry Shmidt | ed003d2 | 2014-02-06 10:09:12 -0800 | [diff] [blame] | 970 | int enabled; |
| 971 | if (wpa_s->global->p2p == NULL || |
| 972 | wpa_s->global->p2p_disabled) |
| 973 | enabled = 0; |
| 974 | else |
| 975 | enabled = wpa_s->global->wifi_display; |
| 976 | res = os_snprintf(buf, buflen, "%d", enabled); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 977 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 978 | #ifdef CONFIG_TESTING_GET_GTK |
| 979 | } else if (os_strcmp(cmd, "gtk") == 0) { |
| 980 | if (wpa_s->last_gtk_len == 0) |
| 981 | return -1; |
| 982 | res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk, |
| 983 | wpa_s->last_gtk_len); |
| 984 | return res; |
| 985 | #endif /* CONFIG_TESTING_GET_GTK */ |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 986 | } else if (os_strcmp(cmd, "tls_library") == 0) { |
| 987 | res = tls_get_library_version(buf, buflen); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 988 | #ifdef CONFIG_TESTING_OPTIONS |
| 989 | } else if (os_strcmp(cmd, "anonce") == 0) { |
| 990 | return wpa_snprintf_hex(buf, buflen, |
| 991 | wpa_sm_get_anonce(wpa_s->wpa), |
| 992 | WPA_NONCE_LEN); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 993 | } else if (os_strcasecmp(cmd, "last_tk_key_idx") == 0) { |
| 994 | res = os_snprintf(buf, buflen, "%d", wpa_s->last_tk_key_idx); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 995 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 996 | } else { |
| 997 | res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 998 | } |
| 999 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1000 | if (os_snprintf_error(buflen, res)) |
Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 1001 | return -1; |
| 1002 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | |
| 1006 | #ifdef IEEE8021X_EAPOL |
| 1007 | static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s, |
| 1008 | char *addr) |
| 1009 | { |
| 1010 | u8 bssid[ETH_ALEN]; |
| 1011 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 1012 | |
| 1013 | if (hwaddr_aton(addr, bssid)) { |
| 1014 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address " |
| 1015 | "'%s'", addr); |
| 1016 | return -1; |
| 1017 | } |
| 1018 | |
| 1019 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid)); |
| 1020 | rsn_preauth_deinit(wpa_s->wpa); |
| 1021 | if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL)) |
| 1022 | return -1; |
| 1023 | |
| 1024 | return 0; |
| 1025 | } |
| 1026 | #endif /* IEEE8021X_EAPOL */ |
| 1027 | |
| 1028 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1029 | #ifdef CONFIG_TDLS |
| 1030 | |
| 1031 | static int wpa_supplicant_ctrl_iface_tdls_discover( |
| 1032 | struct wpa_supplicant *wpa_s, char *addr) |
| 1033 | { |
| 1034 | u8 peer[ETH_ALEN]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1035 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1036 | |
| 1037 | if (hwaddr_aton(addr, peer)) { |
| 1038 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid " |
| 1039 | "address '%s'", addr); |
| 1040 | return -1; |
| 1041 | } |
| 1042 | |
| 1043 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR, |
| 1044 | MAC2STR(peer)); |
| 1045 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1046 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 1047 | ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer); |
| 1048 | else |
| 1049 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); |
| 1050 | |
| 1051 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | |
| 1055 | static int wpa_supplicant_ctrl_iface_tdls_setup( |
| 1056 | struct wpa_supplicant *wpa_s, char *addr) |
| 1057 | { |
| 1058 | u8 peer[ETH_ALEN]; |
| 1059 | int ret; |
| 1060 | |
| 1061 | if (hwaddr_aton(addr, peer)) { |
| 1062 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid " |
| 1063 | "address '%s'", addr); |
| 1064 | return -1; |
| 1065 | } |
| 1066 | |
| 1067 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR, |
| 1068 | MAC2STR(peer)); |
| 1069 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1070 | if ((wpa_s->conf->tdls_external_control) && |
| 1071 | wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 1072 | return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); |
| 1073 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1074 | wpa_tdls_remove(wpa_s->wpa, peer); |
| 1075 | |
| 1076 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 1077 | ret = wpa_tdls_start(wpa_s->wpa, peer); |
| 1078 | else |
| 1079 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1080 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1081 | return ret; |
| 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | static int wpa_supplicant_ctrl_iface_tdls_teardown( |
| 1086 | struct wpa_supplicant *wpa_s, char *addr) |
| 1087 | { |
| 1088 | u8 peer[ETH_ALEN]; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 1089 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1090 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 1091 | if (os_strcmp(addr, "*") == 0) { |
| 1092 | /* remove everyone */ |
| 1093 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *"); |
| 1094 | wpa_tdls_teardown_peers(wpa_s->wpa); |
| 1095 | return 0; |
| 1096 | } |
| 1097 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1098 | if (hwaddr_aton(addr, peer)) { |
| 1099 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid " |
| 1100 | "address '%s'", addr); |
| 1101 | return -1; |
| 1102 | } |
| 1103 | |
| 1104 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR, |
| 1105 | MAC2STR(peer)); |
| 1106 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1107 | if ((wpa_s->conf->tdls_external_control) && |
| 1108 | wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 1109 | return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); |
| 1110 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 1111 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 1112 | ret = wpa_tdls_teardown_link( |
| 1113 | wpa_s->wpa, peer, |
| 1114 | WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED); |
| 1115 | else |
| 1116 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); |
| 1117 | |
| 1118 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1121 | |
| 1122 | static int ctrl_iface_get_capability_tdls( |
| 1123 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| 1124 | { |
| 1125 | int ret; |
| 1126 | |
| 1127 | ret = os_snprintf(buf, buflen, "%s\n", |
| 1128 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ? |
| 1129 | (wpa_s->drv_flags & |
| 1130 | WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ? |
| 1131 | "EXTERNAL" : "INTERNAL") : "UNSUPPORTED"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1132 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1133 | return -1; |
| 1134 | return ret; |
| 1135 | } |
| 1136 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1137 | |
| 1138 | static int wpa_supplicant_ctrl_iface_tdls_chan_switch( |
| 1139 | struct wpa_supplicant *wpa_s, char *cmd) |
| 1140 | { |
| 1141 | u8 peer[ETH_ALEN]; |
| 1142 | struct hostapd_freq_params freq_params; |
| 1143 | u8 oper_class; |
| 1144 | char *pos, *end; |
| 1145 | |
| 1146 | if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { |
| 1147 | wpa_printf(MSG_INFO, |
| 1148 | "tdls_chanswitch: Only supported with external setup"); |
| 1149 | return -1; |
| 1150 | } |
| 1151 | |
| 1152 | os_memset(&freq_params, 0, sizeof(freq_params)); |
| 1153 | |
| 1154 | pos = os_strchr(cmd, ' '); |
| 1155 | if (pos == NULL) |
| 1156 | return -1; |
| 1157 | *pos++ = '\0'; |
| 1158 | |
| 1159 | oper_class = strtol(pos, &end, 10); |
| 1160 | if (pos == end) { |
| 1161 | wpa_printf(MSG_INFO, |
| 1162 | "tdls_chanswitch: Invalid op class provided"); |
| 1163 | return -1; |
| 1164 | } |
| 1165 | |
| 1166 | pos = end; |
| 1167 | freq_params.freq = atoi(pos); |
| 1168 | if (freq_params.freq == 0) { |
| 1169 | wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided"); |
| 1170 | return -1; |
| 1171 | } |
| 1172 | |
| 1173 | #define SET_FREQ_SETTING(str) \ |
| 1174 | do { \ |
| 1175 | const char *pos2 = os_strstr(pos, " " #str "="); \ |
| 1176 | if (pos2) { \ |
| 1177 | pos2 += sizeof(" " #str "=") - 1; \ |
| 1178 | freq_params.str = atoi(pos2); \ |
| 1179 | } \ |
| 1180 | } while (0) |
| 1181 | |
| 1182 | SET_FREQ_SETTING(center_freq1); |
| 1183 | SET_FREQ_SETTING(center_freq2); |
| 1184 | SET_FREQ_SETTING(bandwidth); |
| 1185 | SET_FREQ_SETTING(sec_channel_offset); |
| 1186 | #undef SET_FREQ_SETTING |
| 1187 | |
| 1188 | freq_params.ht_enabled = !!os_strstr(pos, " ht"); |
| 1189 | freq_params.vht_enabled = !!os_strstr(pos, " vht"); |
| 1190 | |
| 1191 | if (hwaddr_aton(cmd, peer)) { |
| 1192 | wpa_printf(MSG_DEBUG, |
| 1193 | "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'", |
| 1194 | cmd); |
| 1195 | return -1; |
| 1196 | } |
| 1197 | |
| 1198 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR |
| 1199 | " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s", |
| 1200 | MAC2STR(peer), oper_class, freq_params.freq, |
| 1201 | freq_params.center_freq1, freq_params.center_freq2, |
| 1202 | freq_params.bandwidth, freq_params.sec_channel_offset, |
| 1203 | freq_params.ht_enabled ? " HT" : "", |
| 1204 | freq_params.vht_enabled ? " VHT" : ""); |
| 1205 | |
| 1206 | return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class, |
| 1207 | &freq_params); |
| 1208 | } |
| 1209 | |
| 1210 | |
| 1211 | static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch( |
| 1212 | struct wpa_supplicant *wpa_s, char *cmd) |
| 1213 | { |
| 1214 | u8 peer[ETH_ALEN]; |
| 1215 | |
| 1216 | if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { |
| 1217 | wpa_printf(MSG_INFO, |
| 1218 | "tdls_chanswitch: Only supported with external setup"); |
| 1219 | return -1; |
| 1220 | } |
| 1221 | |
| 1222 | if (hwaddr_aton(cmd, peer)) { |
| 1223 | wpa_printf(MSG_DEBUG, |
| 1224 | "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'", |
| 1225 | cmd); |
| 1226 | return -1; |
| 1227 | } |
| 1228 | |
| 1229 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR, |
| 1230 | MAC2STR(peer)); |
| 1231 | |
| 1232 | return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer); |
| 1233 | } |
| 1234 | |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 1235 | |
| 1236 | static int wpa_supplicant_ctrl_iface_tdls_link_status( |
| 1237 | struct wpa_supplicant *wpa_s, const char *addr, |
| 1238 | char *buf, size_t buflen) |
| 1239 | { |
| 1240 | u8 peer[ETH_ALEN]; |
| 1241 | const char *tdls_status; |
| 1242 | int ret; |
| 1243 | |
| 1244 | if (hwaddr_aton(addr, peer)) { |
| 1245 | wpa_printf(MSG_DEBUG, |
| 1246 | "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'", |
| 1247 | addr); |
| 1248 | return -1; |
| 1249 | } |
| 1250 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR, |
| 1251 | MAC2STR(peer)); |
| 1252 | |
| 1253 | tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer); |
| 1254 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status); |
| 1255 | ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status); |
| 1256 | if (os_snprintf_error(buflen, ret)) |
| 1257 | return -1; |
| 1258 | |
| 1259 | return ret; |
| 1260 | } |
| 1261 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1262 | #endif /* CONFIG_TDLS */ |
| 1263 | |
| 1264 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1265 | static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd) |
| 1266 | { |
| 1267 | char *token, *context = NULL; |
| 1268 | struct wmm_ac_ts_setup_params params = { |
| 1269 | .tsid = 0xff, |
| 1270 | .direction = 0xff, |
| 1271 | }; |
| 1272 | |
| 1273 | while ((token = str_token(cmd, " ", &context))) { |
| 1274 | if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 || |
| 1275 | sscanf(token, "up=%i", ¶ms.user_priority) == 1 || |
| 1276 | sscanf(token, "nominal_msdu_size=%i", |
| 1277 | ¶ms.nominal_msdu_size) == 1 || |
| 1278 | sscanf(token, "mean_data_rate=%i", |
| 1279 | ¶ms.mean_data_rate) == 1 || |
| 1280 | sscanf(token, "min_phy_rate=%i", |
| 1281 | ¶ms.minimum_phy_rate) == 1 || |
| 1282 | sscanf(token, "sba=%i", |
| 1283 | ¶ms.surplus_bandwidth_allowance) == 1) |
| 1284 | continue; |
| 1285 | |
| 1286 | if (os_strcasecmp(token, "downlink") == 0) { |
| 1287 | params.direction = WMM_TSPEC_DIRECTION_DOWNLINK; |
| 1288 | } else if (os_strcasecmp(token, "uplink") == 0) { |
| 1289 | params.direction = WMM_TSPEC_DIRECTION_UPLINK; |
| 1290 | } else if (os_strcasecmp(token, "bidi") == 0) { |
| 1291 | params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL; |
| 1292 | } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) { |
| 1293 | params.fixed_nominal_msdu = 1; |
| 1294 | } else { |
| 1295 | wpa_printf(MSG_DEBUG, |
| 1296 | "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'", |
| 1297 | token); |
| 1298 | return -1; |
| 1299 | } |
| 1300 | |
| 1301 | } |
| 1302 | |
| 1303 | return wpas_wmm_ac_addts(wpa_s, ¶ms); |
| 1304 | } |
| 1305 | |
| 1306 | |
| 1307 | static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd) |
| 1308 | { |
| 1309 | u8 tsid = atoi(cmd); |
| 1310 | |
| 1311 | return wpas_wmm_ac_delts(wpa_s, tsid); |
| 1312 | } |
| 1313 | |
| 1314 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1315 | #ifdef CONFIG_IEEE80211R |
| 1316 | static int wpa_supplicant_ctrl_iface_ft_ds( |
| 1317 | struct wpa_supplicant *wpa_s, char *addr) |
| 1318 | { |
| 1319 | u8 target_ap[ETH_ALEN]; |
| 1320 | struct wpa_bss *bss; |
| 1321 | const u8 *mdie; |
| 1322 | |
| 1323 | if (hwaddr_aton(addr, target_ap)) { |
| 1324 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid " |
| 1325 | "address '%s'", addr); |
| 1326 | return -1; |
| 1327 | } |
| 1328 | |
| 1329 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap)); |
| 1330 | |
| 1331 | bss = wpa_bss_get_bssid(wpa_s, target_ap); |
| 1332 | if (bss) |
| 1333 | mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); |
| 1334 | else |
| 1335 | mdie = NULL; |
| 1336 | |
| 1337 | return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie); |
| 1338 | } |
| 1339 | #endif /* CONFIG_IEEE80211R */ |
| 1340 | |
| 1341 | |
| 1342 | #ifdef CONFIG_WPS |
| 1343 | static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s, |
| 1344 | char *cmd) |
| 1345 | { |
| 1346 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1347 | #ifdef CONFIG_P2P |
| 1348 | u8 p2p_dev_addr[ETH_ALEN]; |
| 1349 | #endif /* CONFIG_P2P */ |
| 1350 | #ifdef CONFIG_AP |
| 1351 | u8 *_p2p_dev_addr = NULL; |
| 1352 | #endif /* CONFIG_AP */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1353 | char *pos; |
| 1354 | int multi_ap = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1355 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1356 | if (!cmd || os_strcmp(cmd, "any") == 0 || |
| 1357 | os_strncmp(cmd, "any ", 4) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1358 | _bssid = NULL; |
| 1359 | #ifdef CONFIG_P2P |
| 1360 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { |
| 1361 | if (hwaddr_aton(cmd + 13, p2p_dev_addr)) { |
| 1362 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid " |
| 1363 | "P2P Device Address '%s'", |
| 1364 | cmd + 13); |
| 1365 | return -1; |
| 1366 | } |
| 1367 | _p2p_dev_addr = p2p_dev_addr; |
| 1368 | #endif /* CONFIG_P2P */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1369 | } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) { |
| 1370 | _bssid = NULL; |
| 1371 | multi_ap = atoi(cmd + 9); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1372 | } else if (hwaddr_aton(cmd, bssid)) { |
| 1373 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'", |
| 1374 | cmd); |
| 1375 | return -1; |
| 1376 | } |
| 1377 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1378 | if (cmd) { |
| 1379 | pos = os_strstr(cmd, " multi_ap="); |
| 1380 | if (pos) { |
| 1381 | pos += 10; |
| 1382 | multi_ap = atoi(pos); |
| 1383 | } |
| 1384 | } |
| 1385 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1386 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1387 | if (wpa_s->ap_iface) |
| 1388 | return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr); |
| 1389 | #endif /* CONFIG_AP */ |
| 1390 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1391 | return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | |
| 1395 | static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, |
| 1396 | char *cmd, char *buf, |
| 1397 | size_t buflen) |
| 1398 | { |
| 1399 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
| 1400 | char *pin; |
| 1401 | int ret; |
| 1402 | |
| 1403 | pin = os_strchr(cmd, ' '); |
| 1404 | if (pin) |
| 1405 | *pin++ = '\0'; |
| 1406 | |
| 1407 | if (os_strcmp(cmd, "any") == 0) |
| 1408 | _bssid = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1409 | else if (os_strcmp(cmd, "get") == 0) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1410 | if (wps_generate_pin((unsigned int *) &ret) < 0) |
| 1411 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1412 | goto done; |
| 1413 | } else if (hwaddr_aton(cmd, bssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1414 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'", |
| 1415 | cmd); |
| 1416 | return -1; |
| 1417 | } |
| 1418 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1419 | #ifdef CONFIG_AP |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1420 | if (wpa_s->ap_iface) { |
| 1421 | int timeout = 0; |
| 1422 | char *pos; |
| 1423 | |
| 1424 | if (pin) { |
| 1425 | pos = os_strchr(pin, ' '); |
| 1426 | if (pos) { |
| 1427 | *pos++ = '\0'; |
| 1428 | timeout = atoi(pos); |
| 1429 | } |
| 1430 | } |
| 1431 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1432 | return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1433 | buf, buflen, timeout); |
| 1434 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1435 | #endif /* CONFIG_AP */ |
| 1436 | |
| 1437 | if (pin) { |
| 1438 | ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0, |
| 1439 | DEV_PW_DEFAULT); |
| 1440 | if (ret < 0) |
| 1441 | return -1; |
| 1442 | ret = os_snprintf(buf, buflen, "%s", pin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1443 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1444 | return -1; |
| 1445 | return ret; |
| 1446 | } |
| 1447 | |
| 1448 | ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT); |
| 1449 | if (ret < 0) |
| 1450 | return -1; |
| 1451 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1452 | done: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1453 | /* Return the generated PIN */ |
| 1454 | ret = os_snprintf(buf, buflen, "%08d", ret); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1455 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1456 | return -1; |
| 1457 | return ret; |
| 1458 | } |
| 1459 | |
| 1460 | |
| 1461 | static int wpa_supplicant_ctrl_iface_wps_check_pin( |
| 1462 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| 1463 | { |
| 1464 | char pin[9]; |
| 1465 | size_t len; |
| 1466 | char *pos; |
| 1467 | int ret; |
| 1468 | |
| 1469 | wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN", |
| 1470 | (u8 *) cmd, os_strlen(cmd)); |
| 1471 | for (pos = cmd, len = 0; *pos != '\0'; pos++) { |
| 1472 | if (*pos < '0' || *pos > '9') |
| 1473 | continue; |
| 1474 | pin[len++] = *pos; |
| 1475 | if (len == 9) { |
| 1476 | wpa_printf(MSG_DEBUG, "WPS: Too long PIN"); |
| 1477 | return -1; |
| 1478 | } |
| 1479 | } |
| 1480 | if (len != 4 && len != 8) { |
| 1481 | wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len); |
| 1482 | return -1; |
| 1483 | } |
| 1484 | pin[len] = '\0'; |
| 1485 | |
| 1486 | if (len == 8) { |
| 1487 | unsigned int pin_val; |
| 1488 | pin_val = atoi(pin); |
| 1489 | if (!wps_pin_valid(pin_val)) { |
| 1490 | wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit"); |
| 1491 | ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1492 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1493 | return -1; |
| 1494 | return ret; |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | ret = os_snprintf(buf, buflen, "%s", pin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1499 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1500 | return -1; |
| 1501 | |
| 1502 | return ret; |
| 1503 | } |
| 1504 | |
| 1505 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1506 | #ifdef CONFIG_WPS_NFC |
| 1507 | |
| 1508 | static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s, |
| 1509 | char *cmd) |
| 1510 | { |
| 1511 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
| 1512 | |
| 1513 | if (cmd == NULL || cmd[0] == '\0') |
| 1514 | _bssid = NULL; |
| 1515 | else if (hwaddr_aton(cmd, bssid)) |
| 1516 | return -1; |
| 1517 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1518 | return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL, |
| 1519 | 0, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1523 | static int wpa_supplicant_ctrl_iface_wps_nfc_config_token( |
| 1524 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| 1525 | { |
| 1526 | int ndef; |
| 1527 | struct wpabuf *buf; |
| 1528 | int res; |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1529 | char *pos; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1530 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1531 | pos = os_strchr(cmd, ' '); |
| 1532 | if (pos) |
| 1533 | *pos++ = '\0'; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1534 | if (os_strcmp(cmd, "WPS") == 0) |
| 1535 | ndef = 0; |
| 1536 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1537 | ndef = 1; |
| 1538 | else |
| 1539 | return -1; |
| 1540 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1541 | buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1542 | if (buf == NULL) |
| 1543 | return -1; |
| 1544 | |
| 1545 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1546 | wpabuf_len(buf)); |
| 1547 | reply[res++] = '\n'; |
| 1548 | reply[res] = '\0'; |
| 1549 | |
| 1550 | wpabuf_free(buf); |
| 1551 | |
| 1552 | return res; |
| 1553 | } |
| 1554 | |
| 1555 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1556 | static int wpa_supplicant_ctrl_iface_wps_nfc_token( |
| 1557 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| 1558 | { |
| 1559 | int ndef; |
| 1560 | struct wpabuf *buf; |
| 1561 | int res; |
| 1562 | |
| 1563 | if (os_strcmp(cmd, "WPS") == 0) |
| 1564 | ndef = 0; |
| 1565 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1566 | ndef = 1; |
| 1567 | else |
| 1568 | return -1; |
| 1569 | |
| 1570 | buf = wpas_wps_nfc_token(wpa_s, ndef); |
| 1571 | if (buf == NULL) |
| 1572 | return -1; |
| 1573 | |
| 1574 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1575 | wpabuf_len(buf)); |
| 1576 | reply[res++] = '\n'; |
| 1577 | reply[res] = '\0'; |
| 1578 | |
| 1579 | wpabuf_free(buf); |
| 1580 | |
| 1581 | return res; |
| 1582 | } |
| 1583 | |
| 1584 | |
| 1585 | static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read( |
| 1586 | struct wpa_supplicant *wpa_s, char *pos) |
| 1587 | { |
| 1588 | size_t len; |
| 1589 | struct wpabuf *buf; |
| 1590 | int ret; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1591 | char *freq; |
| 1592 | int forced_freq = 0; |
| 1593 | |
| 1594 | freq = strstr(pos, " freq="); |
| 1595 | if (freq) { |
| 1596 | *freq = '\0'; |
| 1597 | freq += 6; |
| 1598 | forced_freq = atoi(freq); |
| 1599 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1600 | |
| 1601 | len = os_strlen(pos); |
| 1602 | if (len & 0x01) |
| 1603 | return -1; |
| 1604 | len /= 2; |
| 1605 | |
| 1606 | buf = wpabuf_alloc(len); |
| 1607 | if (buf == NULL) |
| 1608 | return -1; |
| 1609 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { |
| 1610 | wpabuf_free(buf); |
| 1611 | return -1; |
| 1612 | } |
| 1613 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1614 | ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1615 | wpabuf_free(buf); |
| 1616 | |
| 1617 | return ret; |
| 1618 | } |
| 1619 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1620 | |
| 1621 | 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] | 1622 | char *reply, size_t max_len, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1623 | int ndef) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1624 | { |
| 1625 | struct wpabuf *buf; |
| 1626 | int res; |
| 1627 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1628 | buf = wpas_wps_nfc_handover_req(wpa_s, ndef); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1629 | if (buf == NULL) |
| 1630 | return -1; |
| 1631 | |
| 1632 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1633 | wpabuf_len(buf)); |
| 1634 | reply[res++] = '\n'; |
| 1635 | reply[res] = '\0'; |
| 1636 | |
| 1637 | wpabuf_free(buf); |
| 1638 | |
| 1639 | return res; |
| 1640 | } |
| 1641 | |
| 1642 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1643 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1644 | static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s, |
| 1645 | char *reply, size_t max_len, |
| 1646 | int ndef) |
| 1647 | { |
| 1648 | struct wpabuf *buf; |
| 1649 | int res; |
| 1650 | |
| 1651 | buf = wpas_p2p_nfc_handover_req(wpa_s, ndef); |
| 1652 | if (buf == NULL) { |
| 1653 | wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request"); |
| 1654 | return -1; |
| 1655 | } |
| 1656 | |
| 1657 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1658 | wpabuf_len(buf)); |
| 1659 | reply[res++] = '\n'; |
| 1660 | reply[res] = '\0'; |
| 1661 | |
| 1662 | wpabuf_free(buf); |
| 1663 | |
| 1664 | return res; |
| 1665 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1666 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1667 | |
| 1668 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1669 | static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s, |
| 1670 | char *cmd, char *reply, |
| 1671 | size_t max_len) |
| 1672 | { |
| 1673 | char *pos; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1674 | int ndef; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1675 | |
| 1676 | pos = os_strchr(cmd, ' '); |
| 1677 | if (pos == NULL) |
| 1678 | return -1; |
| 1679 | *pos++ = '\0'; |
| 1680 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1681 | if (os_strcmp(cmd, "WPS") == 0) |
| 1682 | ndef = 0; |
| 1683 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1684 | ndef = 1; |
| 1685 | else |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1686 | return -1; |
| 1687 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1688 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1689 | if (!ndef) |
| 1690 | return -1; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1691 | return wpas_ctrl_nfc_get_handover_req_wps( |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1692 | wpa_s, reply, max_len, ndef); |
| 1693 | } |
| 1694 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1695 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1696 | if (os_strcmp(pos, "P2P-CR") == 0) { |
| 1697 | return wpas_ctrl_nfc_get_handover_req_p2p( |
| 1698 | wpa_s, reply, max_len, ndef); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1699 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1700 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1701 | |
| 1702 | return -1; |
| 1703 | } |
| 1704 | |
| 1705 | |
| 1706 | 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] | 1707 | char *reply, size_t max_len, |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1708 | int ndef, int cr, char *uuid) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1709 | { |
| 1710 | struct wpabuf *buf; |
| 1711 | int res; |
| 1712 | |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1713 | buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1714 | if (buf == NULL) |
| 1715 | return -1; |
| 1716 | |
| 1717 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1718 | wpabuf_len(buf)); |
| 1719 | reply[res++] = '\n'; |
| 1720 | reply[res] = '\0'; |
| 1721 | |
| 1722 | wpabuf_free(buf); |
| 1723 | |
| 1724 | return res; |
| 1725 | } |
| 1726 | |
| 1727 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1728 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1729 | static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s, |
| 1730 | char *reply, size_t max_len, |
| 1731 | int ndef, int tag) |
| 1732 | { |
| 1733 | struct wpabuf *buf; |
| 1734 | int res; |
| 1735 | |
| 1736 | buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag); |
| 1737 | if (buf == NULL) |
| 1738 | return -1; |
| 1739 | |
| 1740 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1741 | wpabuf_len(buf)); |
| 1742 | reply[res++] = '\n'; |
| 1743 | reply[res] = '\0'; |
| 1744 | |
| 1745 | wpabuf_free(buf); |
| 1746 | |
| 1747 | return res; |
| 1748 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1749 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1750 | |
| 1751 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1752 | static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s, |
| 1753 | char *cmd, char *reply, |
| 1754 | size_t max_len) |
| 1755 | { |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1756 | char *pos, *pos2; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1757 | int ndef; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1758 | |
| 1759 | pos = os_strchr(cmd, ' '); |
| 1760 | if (pos == NULL) |
| 1761 | return -1; |
| 1762 | *pos++ = '\0'; |
| 1763 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1764 | if (os_strcmp(cmd, "WPS") == 0) |
| 1765 | ndef = 0; |
| 1766 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1767 | ndef = 1; |
| 1768 | else |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1769 | return -1; |
| 1770 | |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1771 | pos2 = os_strchr(pos, ' '); |
| 1772 | if (pos2) |
| 1773 | *pos2++ = '\0'; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1774 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1775 | if (!ndef) |
| 1776 | return -1; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1777 | return wpas_ctrl_nfc_get_handover_sel_wps( |
| 1778 | wpa_s, reply, max_len, ndef, |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1779 | os_strcmp(pos, "WPS-CR") == 0, pos2); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1780 | } |
| 1781 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1782 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1783 | if (os_strcmp(pos, "P2P-CR") == 0) { |
| 1784 | return wpas_ctrl_nfc_get_handover_sel_p2p( |
| 1785 | wpa_s, reply, max_len, ndef, 0); |
| 1786 | } |
| 1787 | |
| 1788 | if (os_strcmp(pos, "P2P-CR-TAG") == 0) { |
| 1789 | return wpas_ctrl_nfc_get_handover_sel_p2p( |
| 1790 | wpa_s, reply, max_len, ndef, 1); |
| 1791 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1792 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1793 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1794 | return -1; |
| 1795 | } |
| 1796 | |
| 1797 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1798 | static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s, |
| 1799 | char *cmd) |
| 1800 | { |
| 1801 | size_t len; |
| 1802 | struct wpabuf *req, *sel; |
| 1803 | int ret; |
| 1804 | char *pos, *role, *type, *pos2; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1805 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1806 | char *freq; |
| 1807 | int forced_freq = 0; |
| 1808 | |
| 1809 | freq = strstr(cmd, " freq="); |
| 1810 | if (freq) { |
| 1811 | *freq = '\0'; |
| 1812 | freq += 6; |
| 1813 | forced_freq = atoi(freq); |
| 1814 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1815 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1816 | |
| 1817 | role = cmd; |
| 1818 | pos = os_strchr(role, ' '); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1819 | if (pos == NULL) { |
| 1820 | wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1821 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1822 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1823 | *pos++ = '\0'; |
| 1824 | |
| 1825 | type = pos; |
| 1826 | pos = os_strchr(type, ' '); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1827 | if (pos == NULL) { |
| 1828 | wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1829 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1830 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1831 | *pos++ = '\0'; |
| 1832 | |
| 1833 | pos2 = os_strchr(pos, ' '); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1834 | if (pos2 == NULL) { |
| 1835 | wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1836 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1837 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1838 | *pos2++ = '\0'; |
| 1839 | |
| 1840 | len = os_strlen(pos); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1841 | if (len & 0x01) { |
| 1842 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1843 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1844 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1845 | len /= 2; |
| 1846 | |
| 1847 | req = wpabuf_alloc(len); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1848 | if (req == NULL) { |
| 1849 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1850 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1851 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1852 | if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1853 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1854 | wpabuf_free(req); |
| 1855 | return -1; |
| 1856 | } |
| 1857 | |
| 1858 | len = os_strlen(pos2); |
| 1859 | if (len & 0x01) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1860 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1861 | wpabuf_free(req); |
| 1862 | return -1; |
| 1863 | } |
| 1864 | len /= 2; |
| 1865 | |
| 1866 | sel = wpabuf_alloc(len); |
| 1867 | if (sel == NULL) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1868 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1869 | wpabuf_free(req); |
| 1870 | return -1; |
| 1871 | } |
| 1872 | if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1873 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1874 | wpabuf_free(req); |
| 1875 | wpabuf_free(sel); |
| 1876 | return -1; |
| 1877 | } |
| 1878 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1879 | wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d", |
| 1880 | role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel)); |
| 1881 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1882 | if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) { |
| 1883 | ret = wpas_wps_nfc_report_handover(wpa_s, req, sel); |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1884 | #ifdef CONFIG_AP |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1885 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) |
| 1886 | { |
| 1887 | ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel); |
| 1888 | if (ret < 0) |
| 1889 | ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel); |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1890 | #endif /* CONFIG_AP */ |
| 1891 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1892 | } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0) |
| 1893 | { |
| 1894 | ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0); |
| 1895 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0) |
| 1896 | { |
| 1897 | ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel, |
| 1898 | forced_freq); |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1899 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1900 | } else { |
| 1901 | wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover " |
| 1902 | "reported: role=%s type=%s", role, type); |
| 1903 | ret = -1; |
| 1904 | } |
| 1905 | wpabuf_free(req); |
| 1906 | wpabuf_free(sel); |
| 1907 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1908 | if (ret) |
| 1909 | wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages"); |
| 1910 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1911 | return ret; |
| 1912 | } |
| 1913 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1914 | #endif /* CONFIG_WPS_NFC */ |
| 1915 | |
| 1916 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1917 | static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s, |
| 1918 | char *cmd) |
| 1919 | { |
| 1920 | u8 bssid[ETH_ALEN]; |
| 1921 | char *pin; |
| 1922 | char *new_ssid; |
| 1923 | char *new_auth; |
| 1924 | char *new_encr; |
| 1925 | char *new_key; |
| 1926 | struct wps_new_ap_settings ap; |
| 1927 | |
| 1928 | pin = os_strchr(cmd, ' '); |
| 1929 | if (pin == NULL) |
| 1930 | return -1; |
| 1931 | *pin++ = '\0'; |
| 1932 | |
| 1933 | if (hwaddr_aton(cmd, bssid)) { |
| 1934 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'", |
| 1935 | cmd); |
| 1936 | return -1; |
| 1937 | } |
| 1938 | |
| 1939 | new_ssid = os_strchr(pin, ' '); |
| 1940 | if (new_ssid == NULL) |
| 1941 | return wpas_wps_start_reg(wpa_s, bssid, pin, NULL); |
| 1942 | *new_ssid++ = '\0'; |
| 1943 | |
| 1944 | new_auth = os_strchr(new_ssid, ' '); |
| 1945 | if (new_auth == NULL) |
| 1946 | return -1; |
| 1947 | *new_auth++ = '\0'; |
| 1948 | |
| 1949 | new_encr = os_strchr(new_auth, ' '); |
| 1950 | if (new_encr == NULL) |
| 1951 | return -1; |
| 1952 | *new_encr++ = '\0'; |
| 1953 | |
| 1954 | new_key = os_strchr(new_encr, ' '); |
| 1955 | if (new_key == NULL) |
| 1956 | return -1; |
| 1957 | *new_key++ = '\0'; |
| 1958 | |
| 1959 | os_memset(&ap, 0, sizeof(ap)); |
| 1960 | ap.ssid_hex = new_ssid; |
| 1961 | ap.auth = new_auth; |
| 1962 | ap.encr = new_encr; |
| 1963 | ap.key_hex = new_key; |
| 1964 | return wpas_wps_start_reg(wpa_s, bssid, pin, &ap); |
| 1965 | } |
| 1966 | |
| 1967 | |
| 1968 | #ifdef CONFIG_AP |
| 1969 | static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s, |
| 1970 | char *cmd, char *buf, |
| 1971 | size_t buflen) |
| 1972 | { |
| 1973 | int timeout = 300; |
| 1974 | char *pos; |
| 1975 | const char *pin_txt; |
| 1976 | |
| 1977 | if (!wpa_s->ap_iface) |
| 1978 | return -1; |
| 1979 | |
| 1980 | pos = os_strchr(cmd, ' '); |
| 1981 | if (pos) |
| 1982 | *pos++ = '\0'; |
| 1983 | |
| 1984 | if (os_strcmp(cmd, "disable") == 0) { |
| 1985 | wpas_wps_ap_pin_disable(wpa_s); |
| 1986 | return os_snprintf(buf, buflen, "OK\n"); |
| 1987 | } |
| 1988 | |
| 1989 | if (os_strcmp(cmd, "random") == 0) { |
| 1990 | if (pos) |
| 1991 | timeout = atoi(pos); |
| 1992 | pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout); |
| 1993 | if (pin_txt == NULL) |
| 1994 | return -1; |
| 1995 | return os_snprintf(buf, buflen, "%s", pin_txt); |
| 1996 | } |
| 1997 | |
| 1998 | if (os_strcmp(cmd, "get") == 0) { |
| 1999 | pin_txt = wpas_wps_ap_pin_get(wpa_s); |
| 2000 | if (pin_txt == NULL) |
| 2001 | return -1; |
| 2002 | return os_snprintf(buf, buflen, "%s", pin_txt); |
| 2003 | } |
| 2004 | |
| 2005 | if (os_strcmp(cmd, "set") == 0) { |
| 2006 | char *pin; |
| 2007 | if (pos == NULL) |
| 2008 | return -1; |
| 2009 | pin = pos; |
| 2010 | pos = os_strchr(pos, ' '); |
| 2011 | if (pos) { |
| 2012 | *pos++ = '\0'; |
| 2013 | timeout = atoi(pos); |
| 2014 | } |
| 2015 | if (os_strlen(pin) > buflen) |
| 2016 | return -1; |
| 2017 | if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0) |
| 2018 | return -1; |
| 2019 | return os_snprintf(buf, buflen, "%s", pin); |
| 2020 | } |
| 2021 | |
| 2022 | return -1; |
| 2023 | } |
| 2024 | #endif /* CONFIG_AP */ |
| 2025 | |
| 2026 | |
| 2027 | #ifdef CONFIG_WPS_ER |
| 2028 | static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s, |
| 2029 | char *cmd) |
| 2030 | { |
| 2031 | char *uuid = cmd, *pin, *pos; |
| 2032 | u8 addr_buf[ETH_ALEN], *addr = NULL; |
| 2033 | pin = os_strchr(uuid, ' '); |
| 2034 | if (pin == NULL) |
| 2035 | return -1; |
| 2036 | *pin++ = '\0'; |
| 2037 | pos = os_strchr(pin, ' '); |
| 2038 | if (pos) { |
| 2039 | *pos++ = '\0'; |
| 2040 | if (hwaddr_aton(pos, addr_buf) == 0) |
| 2041 | addr = addr_buf; |
| 2042 | } |
| 2043 | return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin); |
| 2044 | } |
| 2045 | |
| 2046 | |
| 2047 | static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s, |
| 2048 | char *cmd) |
| 2049 | { |
| 2050 | char *uuid = cmd, *pin; |
| 2051 | pin = os_strchr(uuid, ' '); |
| 2052 | if (pin == NULL) |
| 2053 | return -1; |
| 2054 | *pin++ = '\0'; |
| 2055 | return wpas_wps_er_learn(wpa_s, uuid, pin); |
| 2056 | } |
| 2057 | |
| 2058 | |
| 2059 | static int wpa_supplicant_ctrl_iface_wps_er_set_config( |
| 2060 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2061 | { |
| 2062 | char *uuid = cmd, *id; |
| 2063 | id = os_strchr(uuid, ' '); |
| 2064 | if (id == NULL) |
| 2065 | return -1; |
| 2066 | *id++ = '\0'; |
| 2067 | return wpas_wps_er_set_config(wpa_s, uuid, atoi(id)); |
| 2068 | } |
| 2069 | |
| 2070 | |
| 2071 | static int wpa_supplicant_ctrl_iface_wps_er_config( |
| 2072 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2073 | { |
| 2074 | char *pin; |
| 2075 | char *new_ssid; |
| 2076 | char *new_auth; |
| 2077 | char *new_encr; |
| 2078 | char *new_key; |
| 2079 | struct wps_new_ap_settings ap; |
| 2080 | |
| 2081 | pin = os_strchr(cmd, ' '); |
| 2082 | if (pin == NULL) |
| 2083 | return -1; |
| 2084 | *pin++ = '\0'; |
| 2085 | |
| 2086 | new_ssid = os_strchr(pin, ' '); |
| 2087 | if (new_ssid == NULL) |
| 2088 | return -1; |
| 2089 | *new_ssid++ = '\0'; |
| 2090 | |
| 2091 | new_auth = os_strchr(new_ssid, ' '); |
| 2092 | if (new_auth == NULL) |
| 2093 | return -1; |
| 2094 | *new_auth++ = '\0'; |
| 2095 | |
| 2096 | new_encr = os_strchr(new_auth, ' '); |
| 2097 | if (new_encr == NULL) |
| 2098 | return -1; |
| 2099 | *new_encr++ = '\0'; |
| 2100 | |
| 2101 | new_key = os_strchr(new_encr, ' '); |
| 2102 | if (new_key == NULL) |
| 2103 | return -1; |
| 2104 | *new_key++ = '\0'; |
| 2105 | |
| 2106 | os_memset(&ap, 0, sizeof(ap)); |
| 2107 | ap.ssid_hex = new_ssid; |
| 2108 | ap.auth = new_auth; |
| 2109 | ap.encr = new_encr; |
| 2110 | ap.key_hex = new_key; |
| 2111 | return wpas_wps_er_config(wpa_s, cmd, pin, &ap); |
| 2112 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2113 | |
| 2114 | |
| 2115 | #ifdef CONFIG_WPS_NFC |
| 2116 | static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( |
| 2117 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| 2118 | { |
| 2119 | int ndef; |
| 2120 | struct wpabuf *buf; |
| 2121 | int res; |
| 2122 | char *uuid; |
| 2123 | |
| 2124 | uuid = os_strchr(cmd, ' '); |
| 2125 | if (uuid == NULL) |
| 2126 | return -1; |
| 2127 | *uuid++ = '\0'; |
| 2128 | |
| 2129 | if (os_strcmp(cmd, "WPS") == 0) |
| 2130 | ndef = 0; |
| 2131 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 2132 | ndef = 1; |
| 2133 | else |
| 2134 | return -1; |
| 2135 | |
| 2136 | buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid); |
| 2137 | if (buf == NULL) |
| 2138 | return -1; |
| 2139 | |
| 2140 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 2141 | wpabuf_len(buf)); |
| 2142 | reply[res++] = '\n'; |
| 2143 | reply[res] = '\0'; |
| 2144 | |
| 2145 | wpabuf_free(buf); |
| 2146 | |
| 2147 | return res; |
| 2148 | } |
| 2149 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2150 | #endif /* CONFIG_WPS_ER */ |
| 2151 | |
| 2152 | #endif /* CONFIG_WPS */ |
| 2153 | |
| 2154 | |
| 2155 | #ifdef CONFIG_IBSS_RSN |
| 2156 | static int wpa_supplicant_ctrl_iface_ibss_rsn( |
| 2157 | struct wpa_supplicant *wpa_s, char *addr) |
| 2158 | { |
| 2159 | u8 peer[ETH_ALEN]; |
| 2160 | |
| 2161 | if (hwaddr_aton(addr, peer)) { |
| 2162 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid " |
| 2163 | "address '%s'", addr); |
| 2164 | return -1; |
| 2165 | } |
| 2166 | |
| 2167 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR, |
| 2168 | MAC2STR(peer)); |
| 2169 | |
| 2170 | return ibss_rsn_start(wpa_s->ibss_rsn, peer); |
| 2171 | } |
| 2172 | #endif /* CONFIG_IBSS_RSN */ |
| 2173 | |
| 2174 | |
| 2175 | static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, |
| 2176 | char *rsp) |
| 2177 | { |
| 2178 | #ifdef IEEE8021X_EAPOL |
| 2179 | char *pos, *id_pos; |
| 2180 | int id; |
| 2181 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2182 | |
| 2183 | pos = os_strchr(rsp, '-'); |
| 2184 | if (pos == NULL) |
| 2185 | return -1; |
| 2186 | *pos++ = '\0'; |
| 2187 | id_pos = pos; |
| 2188 | pos = os_strchr(pos, ':'); |
| 2189 | if (pos == NULL) |
| 2190 | return -1; |
| 2191 | *pos++ = '\0'; |
| 2192 | id = atoi(id_pos); |
| 2193 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); |
| 2194 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", |
| 2195 | (u8 *) pos, os_strlen(pos)); |
| 2196 | |
| 2197 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 2198 | if (ssid == NULL) { |
| 2199 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 2200 | "to update", id); |
| 2201 | return -1; |
| 2202 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2203 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2204 | return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp, |
| 2205 | pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2206 | #else /* IEEE8021X_EAPOL */ |
| 2207 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); |
| 2208 | return -1; |
| 2209 | #endif /* IEEE8021X_EAPOL */ |
| 2210 | } |
| 2211 | |
| 2212 | |
| 2213 | static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, |
| 2214 | const char *params, |
| 2215 | char *buf, size_t buflen) |
| 2216 | { |
| 2217 | char *pos, *end, tmp[30]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2218 | int res, verbose, wps, ret; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2219 | #ifdef CONFIG_HS20 |
| 2220 | const u8 *hs20; |
| 2221 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2222 | const u8 *sess_id; |
| 2223 | size_t sess_id_len; |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 2224 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2225 | if (os_strcmp(params, "-DRIVER") == 0) |
| 2226 | return wpa_drv_status(wpa_s, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2227 | verbose = os_strcmp(params, "-VERBOSE") == 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2228 | wps = os_strcmp(params, "-WPS") == 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2229 | pos = buf; |
| 2230 | end = buf + buflen; |
| 2231 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { |
| 2232 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 2233 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", |
| 2234 | MAC2STR(wpa_s->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2235 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2236 | return pos - buf; |
| 2237 | pos += ret; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2238 | ret = os_snprintf(pos, end - pos, "freq=%u\n", |
| 2239 | wpa_s->assoc_freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2240 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2241 | return pos - buf; |
| 2242 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2243 | if (ssid) { |
| 2244 | u8 *_ssid = ssid->ssid; |
| 2245 | size_t ssid_len = ssid->ssid_len; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 2246 | u8 ssid_buf[SSID_MAX_LEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2247 | if (ssid_len == 0) { |
| 2248 | int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); |
| 2249 | if (_res < 0) |
| 2250 | ssid_len = 0; |
| 2251 | else |
| 2252 | ssid_len = _res; |
| 2253 | _ssid = ssid_buf; |
| 2254 | } |
| 2255 | ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", |
| 2256 | wpa_ssid_txt(_ssid, ssid_len), |
| 2257 | ssid->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2258 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2259 | return pos - buf; |
| 2260 | pos += ret; |
| 2261 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2262 | if (wps && ssid->passphrase && |
| 2263 | wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && |
| 2264 | (ssid->mode == WPAS_MODE_AP || |
| 2265 | ssid->mode == WPAS_MODE_P2P_GO)) { |
| 2266 | ret = os_snprintf(pos, end - pos, |
| 2267 | "passphrase=%s\n", |
| 2268 | ssid->passphrase); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2269 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2270 | return pos - buf; |
| 2271 | pos += ret; |
| 2272 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2273 | if (ssid->id_str) { |
| 2274 | ret = os_snprintf(pos, end - pos, |
| 2275 | "id_str=%s\n", |
| 2276 | ssid->id_str); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2277 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2278 | return pos - buf; |
| 2279 | pos += ret; |
| 2280 | } |
| 2281 | |
| 2282 | switch (ssid->mode) { |
| 2283 | case WPAS_MODE_INFRA: |
| 2284 | ret = os_snprintf(pos, end - pos, |
| 2285 | "mode=station\n"); |
| 2286 | break; |
| 2287 | case WPAS_MODE_IBSS: |
| 2288 | ret = os_snprintf(pos, end - pos, |
| 2289 | "mode=IBSS\n"); |
| 2290 | break; |
| 2291 | case WPAS_MODE_AP: |
| 2292 | ret = os_snprintf(pos, end - pos, |
| 2293 | "mode=AP\n"); |
| 2294 | break; |
| 2295 | case WPAS_MODE_P2P_GO: |
| 2296 | ret = os_snprintf(pos, end - pos, |
| 2297 | "mode=P2P GO\n"); |
| 2298 | break; |
| 2299 | case WPAS_MODE_P2P_GROUP_FORMATION: |
| 2300 | ret = os_snprintf(pos, end - pos, |
| 2301 | "mode=P2P GO - group " |
| 2302 | "formation\n"); |
| 2303 | break; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 2304 | case WPAS_MODE_MESH: |
| 2305 | ret = os_snprintf(pos, end - pos, |
| 2306 | "mode=mesh\n"); |
| 2307 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2308 | default: |
| 2309 | ret = 0; |
| 2310 | break; |
| 2311 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2312 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2313 | return pos - buf; |
| 2314 | pos += ret; |
| 2315 | } |
| 2316 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2317 | if (wpa_s->connection_set && |
| 2318 | (wpa_s->connection_ht || wpa_s->connection_vht || |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2319 | wpa_s->connection_he || wpa_s->connection_eht)) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2320 | ret = os_snprintf(pos, end - pos, |
| 2321 | "wifi_generation=%u\n", |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2322 | wpa_s->connection_eht ? 7 : |
| 2323 | (wpa_s->connection_he ? 6 : |
| 2324 | (wpa_s->connection_vht ? 5 : 4))); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2325 | if (os_snprintf_error(end - pos, ret)) |
| 2326 | return pos - buf; |
| 2327 | pos += ret; |
| 2328 | } |
| 2329 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2330 | #ifdef CONFIG_AP |
| 2331 | if (wpa_s->ap_iface) { |
| 2332 | pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos, |
| 2333 | end - pos, |
| 2334 | verbose); |
| 2335 | } else |
| 2336 | #endif /* CONFIG_AP */ |
| 2337 | pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); |
| 2338 | } |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2339 | #ifdef CONFIG_SME |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2340 | #ifdef CONFIG_SAE |
| 2341 | if (wpa_s->wpa_state >= WPA_ASSOCIATED && |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2342 | #ifdef CONFIG_AP |
| 2343 | !wpa_s->ap_iface && |
| 2344 | #endif /* CONFIG_AP */ |
| 2345 | wpa_s->sme.sae.state == SAE_ACCEPTED) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2346 | ret = os_snprintf(pos, end - pos, "sae_group=%d\n" |
| 2347 | "sae_h2e=%d\n" |
| 2348 | "sae_pk=%d\n", |
| 2349 | wpa_s->sme.sae.group, |
| 2350 | wpa_s->sme.sae.h2e, |
| 2351 | wpa_s->sme.sae.pk); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2352 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2353 | return pos - buf; |
| 2354 | pos += ret; |
| 2355 | } |
| 2356 | #endif /* CONFIG_SAE */ |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2357 | #endif /* CONFIG_SME */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2358 | ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", |
| 2359 | wpa_supplicant_state_txt(wpa_s->wpa_state)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2360 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2361 | return pos - buf; |
| 2362 | pos += ret; |
| 2363 | |
| 2364 | if (wpa_s->l2 && |
| 2365 | l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { |
| 2366 | ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2367 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2368 | return pos - buf; |
| 2369 | pos += ret; |
| 2370 | } |
| 2371 | |
| 2372 | #ifdef CONFIG_P2P |
| 2373 | if (wpa_s->global->p2p) { |
| 2374 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR |
| 2375 | "\n", MAC2STR(wpa_s->global->p2p_dev_addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2376 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2377 | return pos - buf; |
| 2378 | pos += ret; |
| 2379 | } |
| 2380 | #endif /* CONFIG_P2P */ |
| 2381 | |
| 2382 | ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n", |
| 2383 | MAC2STR(wpa_s->own_addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2384 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2385 | return pos - buf; |
| 2386 | pos += ret; |
| 2387 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 2388 | if (wpa_s->valid_links) { |
| 2389 | ret = os_snprintf(pos, end - pos, "ap_mld_addr=" MACSTR "\n", |
| 2390 | MAC2STR(wpa_s->ap_mld_addr)); |
| 2391 | if (os_snprintf_error(end - pos, ret)) |
| 2392 | return pos - buf; |
| 2393 | pos += ret; |
| 2394 | } |
| 2395 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2396 | #ifdef CONFIG_HS20 |
| 2397 | if (wpa_s->current_bss && |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2398 | (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss, |
| 2399 | HS20_IE_VENDOR_TYPE)) && |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2400 | wpa_s->wpa_proto == WPA_PROTO_RSN && |
| 2401 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2402 | int release = 1; |
| 2403 | if (hs20[1] >= 5) { |
| 2404 | u8 rel_num = (hs20[6] & 0xf0) >> 4; |
| 2405 | release = rel_num + 1; |
| 2406 | } |
| 2407 | ret = os_snprintf(pos, end - pos, "hs20=%d\n", release); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2408 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2409 | return pos - buf; |
| 2410 | pos += ret; |
| 2411 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2412 | |
| 2413 | if (wpa_s->current_ssid) { |
| 2414 | struct wpa_cred *cred; |
| 2415 | char *type; |
| 2416 | |
| 2417 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2418 | size_t i; |
| 2419 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2420 | if (wpa_s->current_ssid->parent_cred != cred) |
| 2421 | continue; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2422 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2423 | if (cred->provisioning_sp) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2424 | ret = os_snprintf(pos, end - pos, |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2425 | "provisioning_sp=%s\n", |
| 2426 | cred->provisioning_sp); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2427 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2428 | return pos - buf; |
| 2429 | pos += ret; |
| 2430 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2431 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2432 | if (!cred->domain) |
| 2433 | goto no_domain; |
| 2434 | |
| 2435 | i = 0; |
| 2436 | if (wpa_s->current_bss && wpa_s->current_bss->anqp) { |
| 2437 | struct wpabuf *names = |
| 2438 | wpa_s->current_bss->anqp->domain_name; |
| 2439 | for (i = 0; names && i < cred->num_domain; i++) |
| 2440 | { |
| 2441 | if (domain_name_list_contains( |
| 2442 | names, cred->domain[i], 1)) |
| 2443 | break; |
| 2444 | } |
| 2445 | if (i == cred->num_domain) |
| 2446 | i = 0; /* show first entry by default */ |
| 2447 | } |
| 2448 | ret = os_snprintf(pos, end - pos, "home_sp=%s\n", |
| 2449 | cred->domain[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2450 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2451 | return pos - buf; |
| 2452 | pos += ret; |
| 2453 | |
| 2454 | no_domain: |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2455 | if (wpa_s->current_bss == NULL || |
| 2456 | wpa_s->current_bss->anqp == NULL) |
| 2457 | res = -1; |
| 2458 | else |
| 2459 | res = interworking_home_sp_cred( |
| 2460 | wpa_s, cred, |
| 2461 | wpa_s->current_bss->anqp->domain_name); |
| 2462 | if (res > 0) |
| 2463 | type = "home"; |
| 2464 | else if (res == 0) |
| 2465 | type = "roaming"; |
| 2466 | else |
| 2467 | type = "unknown"; |
| 2468 | |
| 2469 | ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2470 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2471 | return pos - buf; |
| 2472 | pos += ret; |
| 2473 | |
| 2474 | break; |
| 2475 | } |
| 2476 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2477 | #endif /* CONFIG_HS20 */ |
| 2478 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2479 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
| 2480 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
| 2481 | res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, |
| 2482 | verbose); |
| 2483 | if (res >= 0) |
| 2484 | pos += res; |
| 2485 | } |
| 2486 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2487 | #ifdef CONFIG_MACSEC |
| 2488 | res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos); |
| 2489 | if (res > 0) |
| 2490 | pos += res; |
| 2491 | #endif /* CONFIG_MACSEC */ |
| 2492 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2493 | sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len); |
| 2494 | if (sess_id) { |
| 2495 | char *start = pos; |
| 2496 | |
| 2497 | ret = os_snprintf(pos, end - pos, "eap_session_id="); |
| 2498 | if (os_snprintf_error(end - pos, ret)) |
| 2499 | return start - buf; |
| 2500 | pos += ret; |
| 2501 | ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len); |
| 2502 | if (ret <= 0) |
| 2503 | return start - buf; |
| 2504 | pos += ret; |
| 2505 | ret = os_snprintf(pos, end - pos, "\n"); |
| 2506 | if (os_snprintf_error(end - pos, ret)) |
| 2507 | return start - buf; |
| 2508 | pos += ret; |
| 2509 | } |
| 2510 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2511 | res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); |
| 2512 | if (res >= 0) |
| 2513 | pos += res; |
| 2514 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2515 | #ifdef CONFIG_WPS |
| 2516 | { |
| 2517 | char uuid_str[100]; |
| 2518 | uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str)); |
| 2519 | ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2520 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2521 | return pos - buf; |
| 2522 | pos += ret; |
| 2523 | } |
| 2524 | #endif /* CONFIG_WPS */ |
| 2525 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2526 | if (wpa_s->ieee80211ac) { |
| 2527 | ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n"); |
| 2528 | if (os_snprintf_error(end - pos, ret)) |
| 2529 | return pos - buf; |
| 2530 | pos += ret; |
| 2531 | } |
| 2532 | |
Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 2533 | #ifdef ANDROID |
vandwalle | ffc7018 | 2014-09-11 11:40:14 -0700 | [diff] [blame] | 2534 | /* |
| 2535 | * Allow using the STATUS command with default behavior, say for debug, |
| 2536 | * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE |
| 2537 | * events with STATUS-NO_EVENTS. |
| 2538 | */ |
| 2539 | if (os_strcmp(params, "-NO_EVENTS")) { |
| 2540 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE |
| 2541 | "id=%d state=%d BSSID=" MACSTR " SSID=%s", |
| 2542 | wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, |
| 2543 | wpa_s->wpa_state, |
| 2544 | MAC2STR(wpa_s->bssid), |
| 2545 | wpa_s->current_ssid && wpa_s->current_ssid->ssid ? |
| 2546 | wpa_ssid_txt(wpa_s->current_ssid->ssid, |
| 2547 | wpa_s->current_ssid->ssid_len) : ""); |
| 2548 | if (wpa_s->wpa_state == WPA_COMPLETED) { |
| 2549 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 2550 | char mld_addr[50]; |
| 2551 | |
| 2552 | mld_addr[0] = '\0'; |
| 2553 | if (wpa_s->valid_links) |
| 2554 | os_snprintf(mld_addr, sizeof(mld_addr), |
| 2555 | " ap_mld_addr=" MACSTR, |
| 2556 | MAC2STR(wpa_s->ap_mld_addr)); |
| 2557 | |
vandwalle | ffc7018 | 2014-09-11 11:40:14 -0700 | [diff] [blame] | 2558 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED |
| 2559 | "- connection to " MACSTR |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 2560 | " completed %s [id=%d id_str=%s]%s", |
vandwalle | ffc7018 | 2014-09-11 11:40:14 -0700 | [diff] [blame] | 2561 | MAC2STR(wpa_s->bssid), "(auth)", |
| 2562 | ssid ? ssid->id : -1, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 2563 | ssid && ssid->id_str ? ssid->id_str : "", |
| 2564 | mld_addr); |
vandwalle | ffc7018 | 2014-09-11 11:40:14 -0700 | [diff] [blame] | 2565 | } |
Irfan Sheriff | bf5edf4 | 2012-01-11 16:54:57 -0800 | [diff] [blame] | 2566 | } |
Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 2567 | #endif /* ANDROID */ |
| 2568 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2569 | return pos - buf; |
| 2570 | } |
| 2571 | |
| 2572 | |
| 2573 | static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, |
| 2574 | char *cmd) |
| 2575 | { |
| 2576 | char *pos; |
| 2577 | int id; |
| 2578 | struct wpa_ssid *ssid; |
| 2579 | u8 bssid[ETH_ALEN]; |
| 2580 | |
| 2581 | /* cmd: "<network id> <BSSID>" */ |
| 2582 | pos = os_strchr(cmd, ' '); |
| 2583 | if (pos == NULL) |
| 2584 | return -1; |
| 2585 | *pos++ = '\0'; |
| 2586 | id = atoi(cmd); |
| 2587 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); |
| 2588 | if (hwaddr_aton(pos, bssid)) { |
| 2589 | wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); |
| 2590 | return -1; |
| 2591 | } |
| 2592 | |
| 2593 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 2594 | if (ssid == NULL) { |
| 2595 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 2596 | "to update", id); |
| 2597 | return -1; |
| 2598 | } |
| 2599 | |
| 2600 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); |
| 2601 | ssid->bssid_set = !is_zero_ether_addr(bssid); |
| 2602 | |
| 2603 | return 0; |
| 2604 | } |
| 2605 | |
| 2606 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2607 | static int wpa_supplicant_ctrl_iface_bssid_ignore(struct wpa_supplicant *wpa_s, |
| 2608 | char *cmd, char *buf, |
| 2609 | size_t buflen) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2610 | { |
| 2611 | u8 bssid[ETH_ALEN]; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2612 | struct wpa_bssid_ignore *e; |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2613 | char *pos, *end; |
| 2614 | int ret; |
| 2615 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2616 | /* cmd: "BSSID_IGNORE [<BSSID>]" */ |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2617 | if (*cmd == '\0') { |
| 2618 | pos = buf; |
| 2619 | end = buf + buflen; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2620 | e = wpa_s->bssid_ignore; |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2621 | while (e) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2622 | ret = os_snprintf(pos, end - pos, MACSTR "\n", |
| 2623 | MAC2STR(e->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2624 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2625 | return pos - buf; |
| 2626 | pos += ret; |
| 2627 | e = e->next; |
| 2628 | } |
| 2629 | return pos - buf; |
| 2630 | } |
| 2631 | |
| 2632 | cmd++; |
| 2633 | if (os_strncmp(cmd, "clear", 5) == 0) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2634 | wpa_bssid_ignore_clear(wpa_s); |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2635 | os_memcpy(buf, "OK\n", 3); |
| 2636 | return 3; |
| 2637 | } |
| 2638 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2639 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: BSSID_IGNORE bssid='%s'", cmd); |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2640 | if (hwaddr_aton(cmd, bssid)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2641 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd); |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2642 | return -1; |
| 2643 | } |
| 2644 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2645 | /* |
| 2646 | * Add the BSSID twice, so its count will be 2, causing it to be |
| 2647 | * skipped when processing scan results. |
| 2648 | */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2649 | ret = wpa_bssid_ignore_add(wpa_s, bssid); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2650 | if (ret < 0) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2651 | return -1; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2652 | ret = wpa_bssid_ignore_add(wpa_s, bssid); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2653 | if (ret < 0) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2654 | return -1; |
| 2655 | os_memcpy(buf, "OK\n", 3); |
| 2656 | return 3; |
| 2657 | } |
| 2658 | |
| 2659 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2660 | static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s, |
| 2661 | char *cmd, char *buf, |
| 2662 | size_t buflen) |
| 2663 | { |
| 2664 | char *pos, *end, *stamp; |
| 2665 | int ret; |
| 2666 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2667 | /* cmd: "LOG_LEVEL [<level>]" */ |
| 2668 | if (*cmd == '\0') { |
| 2669 | pos = buf; |
| 2670 | end = buf + buflen; |
| 2671 | ret = os_snprintf(pos, end - pos, "Current level: %s\n" |
| 2672 | "Timestamp: %d\n", |
| 2673 | debug_level_str(wpa_debug_level), |
| 2674 | wpa_debug_timestamp); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2675 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2676 | ret = 0; |
| 2677 | |
| 2678 | return ret; |
| 2679 | } |
| 2680 | |
| 2681 | while (*cmd == ' ') |
| 2682 | cmd++; |
| 2683 | |
| 2684 | stamp = os_strchr(cmd, ' '); |
| 2685 | if (stamp) { |
| 2686 | *stamp++ = '\0'; |
| 2687 | while (*stamp == ' ') { |
| 2688 | stamp++; |
| 2689 | } |
| 2690 | } |
| 2691 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2692 | if (os_strlen(cmd)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2693 | int level = str_to_debug_level(cmd); |
| 2694 | if (level < 0) |
| 2695 | return -1; |
| 2696 | wpa_debug_level = level; |
| 2697 | } |
| 2698 | |
| 2699 | if (stamp && os_strlen(stamp)) |
| 2700 | wpa_debug_timestamp = atoi(stamp); |
| 2701 | |
| 2702 | os_memcpy(buf, "OK\n", 3); |
| 2703 | return 3; |
| 2704 | } |
| 2705 | |
| 2706 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2707 | static int wpa_supplicant_ctrl_iface_list_networks( |
Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 2708 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2709 | { |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2710 | char *pos, *end, *prev; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2711 | struct wpa_ssid *ssid; |
| 2712 | int ret; |
| 2713 | |
| 2714 | pos = buf; |
| 2715 | end = buf + buflen; |
| 2716 | ret = os_snprintf(pos, end - pos, |
| 2717 | "network id / ssid / bssid / flags\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2718 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2719 | return pos - buf; |
| 2720 | pos += ret; |
| 2721 | |
| 2722 | ssid = wpa_s->conf->ssid; |
Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 2723 | |
| 2724 | /* skip over ssids until we find next one */ |
| 2725 | if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) { |
| 2726 | int last_id = atoi(cmd + 8); |
| 2727 | if (last_id != -1) { |
| 2728 | while (ssid != NULL && ssid->id <= last_id) { |
| 2729 | ssid = ssid->next; |
| 2730 | } |
| 2731 | } |
| 2732 | } |
| 2733 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2734 | while (ssid) { |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2735 | prev = pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2736 | ret = os_snprintf(pos, end - pos, "%d\t%s", |
| 2737 | ssid->id, |
| 2738 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2739 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2740 | return prev - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2741 | pos += ret; |
| 2742 | if (ssid->bssid_set) { |
| 2743 | ret = os_snprintf(pos, end - pos, "\t" MACSTR, |
| 2744 | MAC2STR(ssid->bssid)); |
| 2745 | } else { |
| 2746 | ret = os_snprintf(pos, end - pos, "\tany"); |
| 2747 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2748 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2749 | return prev - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2750 | pos += ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2751 | ret = os_snprintf(pos, end - pos, "\t%s%s%s%s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2752 | ssid == wpa_s->current_ssid ? |
| 2753 | "[CURRENT]" : "", |
| 2754 | ssid->disabled ? "[DISABLED]" : "", |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2755 | ssid->disabled_until.sec ? |
| 2756 | "[TEMP-DISABLED]" : "", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2757 | ssid->disabled == 2 ? "[P2P-PERSISTENT]" : |
| 2758 | ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2759 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2760 | return prev - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2761 | pos += ret; |
| 2762 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2763 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2764 | return prev - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2765 | pos += ret; |
| 2766 | |
| 2767 | ssid = ssid->next; |
| 2768 | } |
| 2769 | |
| 2770 | return pos - buf; |
| 2771 | } |
| 2772 | |
| 2773 | |
| 2774 | static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) |
| 2775 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2776 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2777 | ret = os_snprintf(pos, end - pos, "-"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2778 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2779 | return pos; |
| 2780 | pos += ret; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2781 | ret = wpa_write_ciphers(pos, end, cipher, "+"); |
| 2782 | if (ret < 0) |
| 2783 | return pos; |
| 2784 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2785 | return pos; |
| 2786 | } |
| 2787 | |
| 2788 | |
| 2789 | static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, |
| 2790 | const u8 *ie, size_t ie_len) |
| 2791 | { |
| 2792 | struct wpa_ie_data data; |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2793 | char *start; |
| 2794 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2795 | |
| 2796 | ret = os_snprintf(pos, end - pos, "[%s-", proto); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2797 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2798 | return pos; |
| 2799 | pos += ret; |
| 2800 | |
| 2801 | if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { |
| 2802 | ret = os_snprintf(pos, end - pos, "?]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2803 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2804 | return pos; |
| 2805 | pos += ret; |
| 2806 | return pos; |
| 2807 | } |
| 2808 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2809 | start = pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2810 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2811 | ret = os_snprintf(pos, end - pos, "%sEAP", |
| 2812 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2813 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2814 | return pos; |
| 2815 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2816 | } |
| 2817 | if (data.key_mgmt & WPA_KEY_MGMT_PSK) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2818 | ret = os_snprintf(pos, end - pos, "%sPSK", |
| 2819 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2820 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2821 | return pos; |
| 2822 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2823 | } |
| 2824 | if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2825 | ret = os_snprintf(pos, end - pos, "%sNone", |
| 2826 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2827 | if (os_snprintf_error(end - pos, ret)) |
| 2828 | return pos; |
| 2829 | pos += ret; |
| 2830 | } |
| 2831 | if (data.key_mgmt & WPA_KEY_MGMT_SAE) { |
| 2832 | ret = os_snprintf(pos, end - pos, "%sSAE", |
| 2833 | pos == start ? "" : "+"); |
| 2834 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2835 | return pos; |
| 2836 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2837 | } |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 2838 | if (data.key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) { |
| 2839 | ret = os_snprintf(pos, end - pos, "%sSAE-EXT-KEY", |
| 2840 | pos == start ? "" : "+"); |
| 2841 | if (os_snprintf_error(end - pos, ret)) |
| 2842 | return pos; |
| 2843 | pos += ret; |
| 2844 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2845 | #ifdef CONFIG_IEEE80211R |
| 2846 | if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { |
| 2847 | ret = os_snprintf(pos, end - pos, "%sFT/EAP", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2848 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2849 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2850 | return pos; |
| 2851 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2852 | } |
| 2853 | if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { |
| 2854 | ret = os_snprintf(pos, end - pos, "%sFT/PSK", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2855 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2856 | if (os_snprintf_error(end - pos, ret)) |
| 2857 | return pos; |
| 2858 | pos += ret; |
| 2859 | } |
| 2860 | if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) { |
| 2861 | ret = os_snprintf(pos, end - pos, "%sFT/SAE", |
| 2862 | pos == start ? "" : "+"); |
| 2863 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2864 | return pos; |
| 2865 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2866 | } |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 2867 | if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE_EXT_KEY) { |
| 2868 | ret = os_snprintf(pos, end - pos, "%sFT/SAE-EXT-KEY", |
| 2869 | pos == start ? "" : "+"); |
| 2870 | if (os_snprintf_error(end - pos, ret)) |
| 2871 | return pos; |
| 2872 | pos += ret; |
| 2873 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2874 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2875 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { |
| 2876 | ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2877 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2878 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2879 | return pos; |
| 2880 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2881 | } |
| 2882 | if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { |
| 2883 | ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2884 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2885 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2886 | return pos; |
| 2887 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2888 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2889 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2890 | #ifdef CONFIG_SUITEB |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2891 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
| 2892 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B", |
| 2893 | pos == start ? "" : "+"); |
| 2894 | if (os_snprintf_error(end - pos, ret)) |
| 2895 | return pos; |
| 2896 | pos += ret; |
| 2897 | } |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2898 | #endif /* CONFIG_SUITEB */ |
| 2899 | |
| 2900 | #ifdef CONFIG_SUITEB192 |
| 2901 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
| 2902 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192", |
| 2903 | pos == start ? "" : "+"); |
| 2904 | if (os_snprintf_error(end - pos, ret)) |
| 2905 | return pos; |
| 2906 | pos += ret; |
| 2907 | } |
| 2908 | #endif /* CONFIG_SUITEB192 */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2909 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2910 | #ifdef CONFIG_FILS |
| 2911 | if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) { |
| 2912 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA256", |
| 2913 | pos == start ? "" : "+"); |
| 2914 | if (os_snprintf_error(end - pos, ret)) |
| 2915 | return pos; |
| 2916 | pos += ret; |
| 2917 | } |
| 2918 | if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) { |
| 2919 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA384", |
| 2920 | pos == start ? "" : "+"); |
| 2921 | if (os_snprintf_error(end - pos, ret)) |
| 2922 | return pos; |
| 2923 | pos += ret; |
| 2924 | } |
| 2925 | #ifdef CONFIG_IEEE80211R |
| 2926 | if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) { |
| 2927 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256", |
| 2928 | pos == start ? "" : "+"); |
| 2929 | if (os_snprintf_error(end - pos, ret)) |
| 2930 | return pos; |
| 2931 | pos += ret; |
| 2932 | } |
| 2933 | if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) { |
| 2934 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384", |
| 2935 | pos == start ? "" : "+"); |
| 2936 | if (os_snprintf_error(end - pos, ret)) |
| 2937 | return pos; |
| 2938 | pos += ret; |
| 2939 | } |
| 2940 | #endif /* CONFIG_IEEE80211R */ |
| 2941 | #endif /* CONFIG_FILS */ |
| 2942 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2943 | #ifdef CONFIG_OWE |
| 2944 | if (data.key_mgmt & WPA_KEY_MGMT_OWE) { |
| 2945 | ret = os_snprintf(pos, end - pos, "%sOWE", |
| 2946 | pos == start ? "" : "+"); |
| 2947 | if (os_snprintf_error(end - pos, ret)) |
| 2948 | return pos; |
| 2949 | pos += ret; |
| 2950 | } |
| 2951 | #endif /* CONFIG_OWE */ |
| 2952 | |
| 2953 | #ifdef CONFIG_DPP |
| 2954 | if (data.key_mgmt & WPA_KEY_MGMT_DPP) { |
| 2955 | ret = os_snprintf(pos, end - pos, "%sDPP", |
| 2956 | pos == start ? "" : "+"); |
| 2957 | if (os_snprintf_error(end - pos, ret)) |
| 2958 | return pos; |
| 2959 | pos += ret; |
| 2960 | } |
| 2961 | #endif /* CONFIG_DPP */ |
| 2962 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2963 | if (data.key_mgmt & WPA_KEY_MGMT_OSEN) { |
| 2964 | ret = os_snprintf(pos, end - pos, "%sOSEN", |
| 2965 | pos == start ? "" : "+"); |
| 2966 | if (os_snprintf_error(end - pos, ret)) |
| 2967 | return pos; |
| 2968 | pos += ret; |
| 2969 | } |
| 2970 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2971 | pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); |
| 2972 | |
| 2973 | if (data.capabilities & WPA_CAPABILITY_PREAUTH) { |
| 2974 | ret = os_snprintf(pos, end - pos, "-preauth"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2975 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2976 | return pos; |
| 2977 | pos += ret; |
| 2978 | } |
| 2979 | |
| 2980 | ret = os_snprintf(pos, end - pos, "]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2981 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2982 | return pos; |
| 2983 | pos += ret; |
| 2984 | |
| 2985 | return pos; |
| 2986 | } |
| 2987 | |
| 2988 | |
| 2989 | #ifdef CONFIG_WPS |
| 2990 | static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, |
| 2991 | char *pos, char *end, |
| 2992 | struct wpabuf *wps_ie) |
| 2993 | { |
| 2994 | int ret; |
| 2995 | const char *txt; |
| 2996 | |
| 2997 | if (wps_ie == NULL) |
| 2998 | return pos; |
| 2999 | if (wps_is_selected_pbc_registrar(wps_ie)) |
| 3000 | txt = "[WPS-PBC]"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3001 | else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) |
| 3002 | txt = "[WPS-AUTH]"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3003 | else if (wps_is_selected_pin_registrar(wps_ie)) |
| 3004 | txt = "[WPS-PIN]"; |
| 3005 | else |
| 3006 | txt = "[WPS]"; |
| 3007 | |
| 3008 | ret = os_snprintf(pos, end - pos, "%s", txt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3009 | if (!os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3010 | pos += ret; |
| 3011 | wpabuf_free(wps_ie); |
| 3012 | return pos; |
| 3013 | } |
| 3014 | #endif /* CONFIG_WPS */ |
| 3015 | |
| 3016 | |
| 3017 | static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, |
| 3018 | char *pos, char *end, |
| 3019 | const struct wpa_bss *bss) |
| 3020 | { |
| 3021 | #ifdef CONFIG_WPS |
| 3022 | struct wpabuf *wps_ie; |
| 3023 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
| 3024 | return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); |
| 3025 | #else /* CONFIG_WPS */ |
| 3026 | return pos; |
| 3027 | #endif /* CONFIG_WPS */ |
| 3028 | } |
| 3029 | |
| 3030 | |
| 3031 | /* Format one result on one text line into a buffer. */ |
| 3032 | static int wpa_supplicant_ctrl_iface_scan_result( |
| 3033 | struct wpa_supplicant *wpa_s, |
| 3034 | const struct wpa_bss *bss, char *buf, size_t buflen) |
| 3035 | { |
| 3036 | char *pos, *end; |
| 3037 | int ret; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3038 | const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe, *rsnxe; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3039 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3040 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3041 | p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 3042 | if (!p2p) |
| 3043 | p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3044 | if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && |
| 3045 | os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == |
| 3046 | 0) |
| 3047 | return 0; /* Do not show P2P listen discovery results here */ |
| 3048 | |
| 3049 | pos = buf; |
| 3050 | end = buf + buflen; |
| 3051 | |
| 3052 | ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", |
| 3053 | MAC2STR(bss->bssid), bss->freq, bss->level); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3054 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3055 | return -1; |
| 3056 | pos += ret; |
| 3057 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 3058 | if (ie) |
| 3059 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); |
| 3060 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3061 | if (ie2) { |
| 3062 | pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2", |
| 3063 | ie2, 2 + ie2[1]); |
| 3064 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3065 | rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3066 | if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) { |
| 3067 | ret = os_snprintf(pos, end - pos, "[SAE-H2E]"); |
| 3068 | if (os_snprintf_error(end - pos, ret)) |
| 3069 | return -1; |
| 3070 | pos += ret; |
| 3071 | } |
| 3072 | if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) { |
| 3073 | ret = os_snprintf(pos, end - pos, "[SAE-PK]"); |
| 3074 | if (os_snprintf_error(end - pos, ret)) |
| 3075 | return -1; |
| 3076 | pos += ret; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3077 | } |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 3078 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
| 3079 | if (osen_ie) |
| 3080 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", |
| 3081 | osen_ie, 2 + osen_ie[1]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3082 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
| 3083 | if (owe) { |
| 3084 | ret = os_snprintf(pos, end - pos, |
| 3085 | ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]"); |
| 3086 | if (os_snprintf_error(end - pos, ret)) |
| 3087 | return -1; |
| 3088 | pos += ret; |
| 3089 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3090 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 3091 | if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3092 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3093 | if (os_snprintf_error(end - pos, ret)) |
| 3094 | return -1; |
| 3095 | pos += ret; |
| 3096 | } |
| 3097 | if (mesh) { |
| 3098 | ret = os_snprintf(pos, end - pos, "[MESH]"); |
| 3099 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3100 | return -1; |
| 3101 | pos += ret; |
| 3102 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3103 | if (bss_is_dmg(bss)) { |
| 3104 | const char *s; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3105 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3106 | if (wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_EDMG_OPERATION)) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3107 | ret = os_snprintf(pos, end - pos, "[EDMG]"); |
| 3108 | if (os_snprintf_error(end - pos, ret)) |
| 3109 | return -1; |
| 3110 | pos += ret; |
| 3111 | } |
| 3112 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3113 | ret = os_snprintf(pos, end - pos, "[DMG]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3114 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3115 | return -1; |
| 3116 | pos += ret; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3117 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
| 3118 | case IEEE80211_CAP_DMG_IBSS: |
| 3119 | s = "[IBSS]"; |
| 3120 | break; |
| 3121 | case IEEE80211_CAP_DMG_AP: |
| 3122 | s = "[ESS]"; |
| 3123 | break; |
| 3124 | case IEEE80211_CAP_DMG_PBSS: |
| 3125 | s = "[PBSS]"; |
| 3126 | break; |
| 3127 | default: |
| 3128 | s = ""; |
| 3129 | break; |
| 3130 | } |
| 3131 | ret = os_snprintf(pos, end - pos, "%s", s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3132 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3133 | return -1; |
| 3134 | pos += ret; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3135 | } else { |
| 3136 | if (bss->caps & IEEE80211_CAP_IBSS) { |
| 3137 | ret = os_snprintf(pos, end - pos, "[IBSS]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3138 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3139 | return -1; |
| 3140 | pos += ret; |
| 3141 | } |
| 3142 | if (bss->caps & IEEE80211_CAP_ESS) { |
| 3143 | ret = os_snprintf(pos, end - pos, "[ESS]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3144 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3145 | return -1; |
| 3146 | pos += ret; |
| 3147 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3148 | } |
| 3149 | if (p2p) { |
| 3150 | ret = os_snprintf(pos, end - pos, "[P2P]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3151 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3152 | return -1; |
| 3153 | pos += ret; |
| 3154 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3155 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3156 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3157 | ret = os_snprintf(pos, end - pos, "[HS20]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3158 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3159 | return -1; |
| 3160 | pos += ret; |
| 3161 | } |
| 3162 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3163 | #ifdef CONFIG_FILS |
| 3164 | if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) { |
| 3165 | ret = os_snprintf(pos, end - pos, "[FILS]"); |
| 3166 | if (os_snprintf_error(end - pos, ret)) |
| 3167 | return -1; |
| 3168 | pos += ret; |
| 3169 | } |
| 3170 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3171 | #ifdef CONFIG_FST |
| 3172 | if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) { |
| 3173 | ret = os_snprintf(pos, end - pos, "[FST]"); |
| 3174 | if (os_snprintf_error(end - pos, ret)) |
| 3175 | return -1; |
| 3176 | pos += ret; |
| 3177 | } |
| 3178 | #endif /* CONFIG_FST */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3179 | if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) { |
| 3180 | ret = os_snprintf(pos, end - pos, "[UTF-8]"); |
| 3181 | if (os_snprintf_error(end - pos, ret)) |
| 3182 | return -1; |
| 3183 | pos += ret; |
| 3184 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3185 | |
| 3186 | ret = os_snprintf(pos, end - pos, "\t%s", |
| 3187 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3188 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3189 | return -1; |
| 3190 | pos += ret; |
| 3191 | |
| 3192 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3193 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3194 | return -1; |
| 3195 | pos += ret; |
| 3196 | |
| 3197 | return pos - buf; |
| 3198 | } |
| 3199 | |
| 3200 | |
| 3201 | static int wpa_supplicant_ctrl_iface_scan_results( |
| 3202 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| 3203 | { |
| 3204 | char *pos, *end; |
| 3205 | struct wpa_bss *bss; |
| 3206 | int ret; |
| 3207 | |
| 3208 | pos = buf; |
| 3209 | end = buf + buflen; |
| 3210 | ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " |
| 3211 | "flags / ssid\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3212 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3213 | return pos - buf; |
| 3214 | pos += ret; |
| 3215 | |
| 3216 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
| 3217 | ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, |
| 3218 | end - pos); |
| 3219 | if (ret < 0 || ret >= end - pos) |
| 3220 | return pos - buf; |
| 3221 | pos += ret; |
| 3222 | } |
| 3223 | |
| 3224 | return pos - buf; |
| 3225 | } |
| 3226 | |
| 3227 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3228 | #ifdef CONFIG_MESH |
| 3229 | |
| 3230 | static int wpa_supplicant_ctrl_iface_mesh_interface_add( |
| 3231 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| 3232 | { |
| 3233 | char *pos, ifname[IFNAMSIZ + 1]; |
| 3234 | |
| 3235 | ifname[0] = '\0'; |
| 3236 | |
| 3237 | pos = os_strstr(cmd, "ifname="); |
| 3238 | if (pos) { |
| 3239 | pos += 7; |
| 3240 | os_strlcpy(ifname, pos, sizeof(ifname)); |
| 3241 | } |
| 3242 | |
| 3243 | if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0) |
| 3244 | return -1; |
| 3245 | |
| 3246 | os_strlcpy(reply, ifname, max_len); |
| 3247 | return os_strlen(ifname); |
| 3248 | } |
| 3249 | |
| 3250 | |
| 3251 | static int wpa_supplicant_ctrl_iface_mesh_group_add( |
| 3252 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3253 | { |
| 3254 | int id; |
| 3255 | struct wpa_ssid *ssid; |
| 3256 | |
| 3257 | id = atoi(cmd); |
| 3258 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id); |
| 3259 | |
| 3260 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3261 | if (ssid == NULL) { |
| 3262 | wpa_printf(MSG_DEBUG, |
| 3263 | "CTRL_IFACE: Could not find network id=%d", id); |
| 3264 | return -1; |
| 3265 | } |
| 3266 | if (ssid->mode != WPAS_MODE_MESH) { |
| 3267 | wpa_printf(MSG_DEBUG, |
| 3268 | "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network"); |
| 3269 | return -1; |
| 3270 | } |
| 3271 | if (ssid->key_mgmt != WPA_KEY_MGMT_NONE && |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 3272 | ssid->key_mgmt != WPA_KEY_MGMT_SAE && |
| 3273 | ssid->key_mgmt != WPA_KEY_MGMT_SAE_EXT_KEY) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3274 | wpa_printf(MSG_ERROR, |
| 3275 | "CTRL_IFACE: key_mgmt for mesh network should be open or SAE"); |
| 3276 | return -1; |
| 3277 | } |
| 3278 | |
| 3279 | /* |
| 3280 | * TODO: If necessary write our own group_add function, |
| 3281 | * for now we can reuse select_network |
| 3282 | */ |
| 3283 | wpa_supplicant_select_network(wpa_s, ssid); |
| 3284 | |
| 3285 | return 0; |
| 3286 | } |
| 3287 | |
| 3288 | |
| 3289 | static int wpa_supplicant_ctrl_iface_mesh_group_remove( |
| 3290 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3291 | { |
| 3292 | struct wpa_supplicant *orig; |
| 3293 | struct wpa_global *global; |
| 3294 | int found = 0; |
| 3295 | |
| 3296 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd); |
| 3297 | |
| 3298 | global = wpa_s->global; |
| 3299 | orig = wpa_s; |
| 3300 | |
| 3301 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 3302 | if (os_strcmp(wpa_s->ifname, cmd) == 0) { |
| 3303 | found = 1; |
| 3304 | break; |
| 3305 | } |
| 3306 | } |
| 3307 | if (!found) { |
| 3308 | wpa_printf(MSG_ERROR, |
| 3309 | "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found", |
| 3310 | cmd); |
| 3311 | return -1; |
| 3312 | } |
| 3313 | if (wpa_s->mesh_if_created && wpa_s == orig) { |
| 3314 | wpa_printf(MSG_ERROR, |
| 3315 | "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself"); |
| 3316 | return -1; |
| 3317 | } |
| 3318 | |
| 3319 | wpa_s->reassociate = 0; |
| 3320 | wpa_s->disconnected = 1; |
| 3321 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 3322 | wpa_supplicant_cancel_scan(wpa_s); |
| 3323 | |
| 3324 | /* |
| 3325 | * TODO: If necessary write our own group_remove function, |
| 3326 | * for now we can reuse deauthenticate |
| 3327 | */ |
| 3328 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 3329 | |
| 3330 | if (wpa_s->mesh_if_created) |
| 3331 | wpa_supplicant_remove_iface(global, wpa_s, 0); |
| 3332 | |
| 3333 | return 0; |
| 3334 | } |
| 3335 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3336 | |
| 3337 | static int wpa_supplicant_ctrl_iface_mesh_peer_remove( |
| 3338 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3339 | { |
| 3340 | u8 addr[ETH_ALEN]; |
| 3341 | |
| 3342 | if (hwaddr_aton(cmd, addr) < 0) |
| 3343 | return -1; |
| 3344 | |
| 3345 | return wpas_mesh_peer_remove(wpa_s, addr); |
| 3346 | } |
| 3347 | |
| 3348 | |
| 3349 | static int wpa_supplicant_ctrl_iface_mesh_peer_add( |
| 3350 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3351 | { |
| 3352 | u8 addr[ETH_ALEN]; |
| 3353 | int duration; |
| 3354 | char *pos; |
| 3355 | |
| 3356 | pos = os_strstr(cmd, " duration="); |
| 3357 | if (pos) { |
| 3358 | *pos = '\0'; |
| 3359 | duration = atoi(pos + 10); |
| 3360 | } else { |
| 3361 | duration = -1; |
| 3362 | } |
| 3363 | |
| 3364 | if (hwaddr_aton(cmd, addr)) |
| 3365 | return -1; |
| 3366 | |
| 3367 | return wpas_mesh_peer_add(wpa_s, addr, duration); |
| 3368 | } |
| 3369 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3370 | |
| 3371 | static int wpa_supplicant_ctrl_iface_mesh_link_probe( |
| 3372 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3373 | { |
| 3374 | struct ether_header *eth; |
| 3375 | u8 addr[ETH_ALEN]; |
| 3376 | u8 *buf; |
| 3377 | char *pos; |
| 3378 | size_t payload_len = 0, len; |
| 3379 | int ret = -1; |
| 3380 | |
| 3381 | if (hwaddr_aton(cmd, addr)) |
| 3382 | return -1; |
| 3383 | |
| 3384 | pos = os_strstr(cmd, " payload="); |
| 3385 | if (pos) { |
| 3386 | pos = pos + 9; |
| 3387 | payload_len = os_strlen(pos); |
| 3388 | if (payload_len & 1) |
| 3389 | return -1; |
| 3390 | |
| 3391 | payload_len /= 2; |
| 3392 | } |
| 3393 | |
| 3394 | len = ETH_HLEN + payload_len; |
| 3395 | buf = os_malloc(len); |
| 3396 | if (!buf) |
| 3397 | return -1; |
| 3398 | |
| 3399 | eth = (struct ether_header *) buf; |
| 3400 | os_memcpy(eth->ether_dhost, addr, ETH_ALEN); |
| 3401 | os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN); |
| 3402 | eth->ether_type = htons(ETH_P_802_3); |
| 3403 | |
| 3404 | if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0) |
| 3405 | goto fail; |
| 3406 | |
| 3407 | ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len); |
| 3408 | fail: |
| 3409 | os_free(buf); |
| 3410 | return -ret; |
| 3411 | } |
| 3412 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3413 | #endif /* CONFIG_MESH */ |
| 3414 | |
| 3415 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3416 | static int wpa_supplicant_ctrl_iface_select_network( |
| 3417 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3418 | { |
| 3419 | int id; |
| 3420 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3421 | char *pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3422 | |
| 3423 | /* cmd: "<network id>" or "any" */ |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3424 | if (os_strncmp(cmd, "any", 3) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3425 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); |
| 3426 | ssid = NULL; |
| 3427 | } else { |
| 3428 | id = atoi(cmd); |
| 3429 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); |
| 3430 | |
| 3431 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3432 | if (ssid == NULL) { |
| 3433 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 3434 | "network id=%d", id); |
| 3435 | return -1; |
| 3436 | } |
| 3437 | if (ssid->disabled == 2) { |
| 3438 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| 3439 | "SELECT_NETWORK with persistent P2P group"); |
| 3440 | return -1; |
| 3441 | } |
| 3442 | } |
| 3443 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3444 | pos = os_strstr(cmd, " freq="); |
| 3445 | if (pos) { |
| 3446 | int *freqs = freq_range_to_channel_list(wpa_s, pos + 6); |
| 3447 | if (freqs) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3448 | os_free(wpa_s->select_network_scan_freqs); |
| 3449 | wpa_s->select_network_scan_freqs = freqs; |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3450 | } |
| 3451 | } |
| 3452 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3453 | wpa_s->scan_min_time.sec = 0; |
| 3454 | wpa_s->scan_min_time.usec = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3455 | wpa_supplicant_select_network(wpa_s, ssid); |
| 3456 | |
| 3457 | return 0; |
| 3458 | } |
| 3459 | |
| 3460 | |
| 3461 | static int wpa_supplicant_ctrl_iface_enable_network( |
| 3462 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3463 | { |
| 3464 | int id; |
| 3465 | struct wpa_ssid *ssid; |
| 3466 | |
| 3467 | /* cmd: "<network id>" or "all" */ |
| 3468 | if (os_strcmp(cmd, "all") == 0) { |
| 3469 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); |
| 3470 | ssid = NULL; |
| 3471 | } else { |
| 3472 | id = atoi(cmd); |
| 3473 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); |
| 3474 | |
| 3475 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3476 | if (ssid == NULL) { |
| 3477 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 3478 | "network id=%d", id); |
| 3479 | return -1; |
| 3480 | } |
| 3481 | if (ssid->disabled == 2) { |
| 3482 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| 3483 | "ENABLE_NETWORK with persistent P2P group"); |
| 3484 | return -1; |
| 3485 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3486 | |
| 3487 | if (os_strstr(cmd, " no-connect")) { |
| 3488 | ssid->disabled = 0; |
| 3489 | return 0; |
| 3490 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3491 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3492 | wpa_s->scan_min_time.sec = 0; |
| 3493 | wpa_s->scan_min_time.usec = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3494 | wpa_supplicant_enable_network(wpa_s, ssid); |
| 3495 | |
| 3496 | return 0; |
| 3497 | } |
| 3498 | |
| 3499 | |
| 3500 | static int wpa_supplicant_ctrl_iface_disable_network( |
| 3501 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3502 | { |
| 3503 | int id; |
| 3504 | struct wpa_ssid *ssid; |
| 3505 | |
| 3506 | /* cmd: "<network id>" or "all" */ |
| 3507 | if (os_strcmp(cmd, "all") == 0) { |
| 3508 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); |
| 3509 | ssid = NULL; |
| 3510 | } else { |
| 3511 | id = atoi(cmd); |
| 3512 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); |
| 3513 | |
| 3514 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3515 | if (ssid == NULL) { |
| 3516 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 3517 | "network id=%d", id); |
| 3518 | return -1; |
| 3519 | } |
| 3520 | if (ssid->disabled == 2) { |
| 3521 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| 3522 | "DISABLE_NETWORK with persistent P2P " |
| 3523 | "group"); |
| 3524 | return -1; |
| 3525 | } |
| 3526 | } |
| 3527 | wpa_supplicant_disable_network(wpa_s, ssid); |
| 3528 | |
| 3529 | return 0; |
| 3530 | } |
| 3531 | |
| 3532 | |
| 3533 | static int wpa_supplicant_ctrl_iface_add_network( |
| 3534 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| 3535 | { |
| 3536 | struct wpa_ssid *ssid; |
| 3537 | int ret; |
| 3538 | |
| 3539 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); |
| 3540 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3541 | ssid = wpa_supplicant_add_network(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3542 | if (ssid == NULL) |
| 3543 | return -1; |
| 3544 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3545 | ret = os_snprintf(buf, buflen, "%d\n", ssid->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3546 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3547 | return -1; |
| 3548 | return ret; |
| 3549 | } |
| 3550 | |
| 3551 | |
| 3552 | static int wpa_supplicant_ctrl_iface_remove_network( |
| 3553 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3554 | { |
| 3555 | int id; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3556 | int result; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3557 | |
| 3558 | /* cmd: "<network id>" or "all" */ |
| 3559 | if (os_strcmp(cmd, "all") == 0) { |
| 3560 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3561 | return wpa_supplicant_remove_all_networks(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3562 | } |
| 3563 | |
| 3564 | id = atoi(cmd); |
| 3565 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); |
| 3566 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3567 | result = wpa_supplicant_remove_network(wpa_s, id); |
| 3568 | if (result == -1) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3569 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
| 3570 | "id=%d", id); |
| 3571 | return -1; |
| 3572 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3573 | if (result == -2) { |
Deepthi Gowri | a831d78 | 2012-09-03 11:55:38 +0300 | [diff] [blame] | 3574 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the " |
| 3575 | "network id=%d", id); |
| 3576 | return -1; |
| 3577 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3578 | return 0; |
| 3579 | } |
| 3580 | |
| 3581 | |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3582 | static int wpa_supplicant_ctrl_iface_update_network( |
| 3583 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 3584 | char *name, char *value) |
| 3585 | { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3586 | int ret; |
| 3587 | |
| 3588 | ret = wpa_config_set(ssid, name, value, 0); |
| 3589 | if (ret < 0) { |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3590 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " |
| 3591 | "variable '%s'", name); |
| 3592 | return -1; |
| 3593 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3594 | if (ret == 1) |
| 3595 | return 0; /* No change to the previously configured value */ |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3596 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3597 | #ifdef CONFIG_BGSCAN |
| 3598 | if (os_strcmp(name, "bgscan") == 0) { |
| 3599 | /* |
| 3600 | * Reset the bgscan parameters for the current network and |
| 3601 | * return. There's no need to flush caches for bgscan parameter |
| 3602 | * changes. |
| 3603 | */ |
| 3604 | if (wpa_s->current_ssid == ssid && |
| 3605 | wpa_s->wpa_state == WPA_COMPLETED) |
| 3606 | wpa_supplicant_reset_bgscan(wpa_s); |
| 3607 | return 0; |
| 3608 | } |
| 3609 | #endif /* CONFIG_BGSCAN */ |
| 3610 | |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3611 | if (os_strcmp(name, "bssid") != 0 && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3612 | os_strcmp(name, "bssid_hint") != 0 && |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3613 | os_strcmp(name, "priority") != 0) { |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3614 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
| 3615 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3616 | if (wpa_s->current_ssid == ssid || |
| 3617 | wpa_s->current_ssid == NULL) { |
| 3618 | /* |
| 3619 | * Invalidate the EAP session cache if anything in the |
| 3620 | * current or previously used configuration changes. |
| 3621 | */ |
| 3622 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
| 3623 | } |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | if ((os_strcmp(name, "psk") == 0 && |
| 3627 | value[0] == '"' && ssid->ssid_len) || |
| 3628 | (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) |
| 3629 | wpa_config_update_psk(ssid); |
| 3630 | else if (os_strcmp(name, "priority") == 0) |
| 3631 | wpa_config_update_prio_list(wpa_s->conf); |
| 3632 | |
| 3633 | return 0; |
| 3634 | } |
| 3635 | |
| 3636 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3637 | static int wpa_supplicant_ctrl_iface_set_network( |
| 3638 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3639 | { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3640 | int id, ret, prev_bssid_set, prev_disabled; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3641 | struct wpa_ssid *ssid; |
| 3642 | char *name, *value; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3643 | u8 prev_bssid[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3644 | |
| 3645 | /* cmd: "<network id> <variable name> <value>" */ |
| 3646 | name = os_strchr(cmd, ' '); |
| 3647 | if (name == NULL) |
| 3648 | return -1; |
| 3649 | *name++ = '\0'; |
| 3650 | |
| 3651 | value = os_strchr(name, ' '); |
| 3652 | if (value == NULL) |
| 3653 | return -1; |
| 3654 | *value++ = '\0'; |
| 3655 | |
| 3656 | id = atoi(cmd); |
| 3657 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", |
| 3658 | id, name); |
| 3659 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", |
| 3660 | (u8 *) value, os_strlen(value)); |
| 3661 | |
| 3662 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3663 | if (ssid == NULL) { |
| 3664 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
| 3665 | "id=%d", id); |
| 3666 | return -1; |
| 3667 | } |
| 3668 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3669 | prev_bssid_set = ssid->bssid_set; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3670 | prev_disabled = ssid->disabled; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3671 | os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN); |
| 3672 | ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name, |
| 3673 | value); |
| 3674 | if (ret == 0 && |
| 3675 | (ssid->bssid_set != prev_bssid_set || |
| 3676 | os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0)) |
| 3677 | wpas_notify_network_bssid_set_changed(wpa_s, ssid); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3678 | |
| 3679 | if (prev_disabled != ssid->disabled && |
| 3680 | (prev_disabled == 2 || ssid->disabled == 2)) |
| 3681 | wpas_notify_network_type_changed(wpa_s, ssid); |
| 3682 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3683 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | |
| 3687 | static int wpa_supplicant_ctrl_iface_get_network( |
| 3688 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| 3689 | { |
| 3690 | int id; |
| 3691 | size_t res; |
| 3692 | struct wpa_ssid *ssid; |
| 3693 | char *name, *value; |
| 3694 | |
| 3695 | /* cmd: "<network id> <variable name>" */ |
| 3696 | name = os_strchr(cmd, ' '); |
| 3697 | if (name == NULL || buflen == 0) |
| 3698 | return -1; |
| 3699 | *name++ = '\0'; |
| 3700 | |
| 3701 | id = atoi(cmd); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3702 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3703 | id, name); |
| 3704 | |
| 3705 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3706 | if (ssid == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3707 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3708 | "id=%d", id); |
| 3709 | return -1; |
| 3710 | } |
| 3711 | |
| 3712 | value = wpa_config_get_no_key(ssid, name); |
| 3713 | if (value == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3714 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3715 | "variable '%s'", name); |
| 3716 | return -1; |
| 3717 | } |
| 3718 | |
| 3719 | res = os_strlcpy(buf, value, buflen); |
| 3720 | if (res >= buflen) { |
| 3721 | os_free(value); |
| 3722 | return -1; |
| 3723 | } |
| 3724 | |
| 3725 | os_free(value); |
| 3726 | |
| 3727 | return res; |
| 3728 | } |
| 3729 | |
| 3730 | |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3731 | static int wpa_supplicant_ctrl_iface_dup_network( |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3732 | struct wpa_supplicant *wpa_s, char *cmd, |
| 3733 | struct wpa_supplicant *dst_wpa_s) |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3734 | { |
| 3735 | struct wpa_ssid *ssid_s, *ssid_d; |
| 3736 | char *name, *id, *value; |
| 3737 | int id_s, id_d, ret; |
| 3738 | |
| 3739 | /* cmd: "<src network id> <dst network id> <variable name>" */ |
| 3740 | id = os_strchr(cmd, ' '); |
| 3741 | if (id == NULL) |
| 3742 | return -1; |
| 3743 | *id++ = '\0'; |
| 3744 | |
| 3745 | name = os_strchr(id, ' '); |
| 3746 | if (name == NULL) |
| 3747 | return -1; |
| 3748 | *name++ = '\0'; |
| 3749 | |
| 3750 | id_s = atoi(cmd); |
| 3751 | id_d = atoi(id); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3752 | |
| 3753 | wpa_printf(MSG_DEBUG, |
| 3754 | "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'", |
| 3755 | wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3756 | |
| 3757 | ssid_s = wpa_config_get_network(wpa_s->conf, id_s); |
| 3758 | if (ssid_s == NULL) { |
| 3759 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 3760 | "network id=%d", id_s); |
| 3761 | return -1; |
| 3762 | } |
| 3763 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3764 | ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3765 | if (ssid_d == NULL) { |
| 3766 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3767 | "network id=%d", id_d); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3768 | return -1; |
| 3769 | } |
| 3770 | |
| 3771 | value = wpa_config_get(ssid_s, name); |
| 3772 | if (value == NULL) { |
| 3773 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " |
| 3774 | "variable '%s'", name); |
| 3775 | return -1; |
| 3776 | } |
| 3777 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3778 | 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] | 3779 | value); |
| 3780 | |
| 3781 | os_free(value); |
| 3782 | |
| 3783 | return ret; |
| 3784 | } |
| 3785 | |
| 3786 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3787 | static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s, |
| 3788 | char *buf, size_t buflen) |
| 3789 | { |
| 3790 | char *pos, *end; |
| 3791 | struct wpa_cred *cred; |
| 3792 | int ret; |
| 3793 | |
| 3794 | pos = buf; |
| 3795 | end = buf + buflen; |
| 3796 | ret = os_snprintf(pos, end - pos, |
| 3797 | "cred id / realm / username / domain / imsi\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3798 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3799 | return pos - buf; |
| 3800 | pos += ret; |
| 3801 | |
| 3802 | cred = wpa_s->conf->cred; |
| 3803 | while (cred) { |
| 3804 | ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n", |
| 3805 | cred->id, cred->realm ? cred->realm : "", |
| 3806 | cred->username ? cred->username : "", |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3807 | cred->domain ? cred->domain[0] : "", |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3808 | cred->imsi ? cred->imsi : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3809 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3810 | return pos - buf; |
| 3811 | pos += ret; |
| 3812 | |
| 3813 | cred = cred->next; |
| 3814 | } |
| 3815 | |
| 3816 | return pos - buf; |
| 3817 | } |
| 3818 | |
| 3819 | |
| 3820 | static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s, |
| 3821 | char *buf, size_t buflen) |
| 3822 | { |
| 3823 | struct wpa_cred *cred; |
| 3824 | int ret; |
| 3825 | |
| 3826 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED"); |
| 3827 | |
| 3828 | cred = wpa_config_add_cred(wpa_s->conf); |
| 3829 | if (cred == NULL) |
| 3830 | return -1; |
| 3831 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3832 | wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id); |
| 3833 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3834 | ret = os_snprintf(buf, buflen, "%d\n", cred->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3835 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3836 | return -1; |
| 3837 | return ret; |
| 3838 | } |
| 3839 | |
| 3840 | |
| 3841 | static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s, |
| 3842 | char *cmd) |
| 3843 | { |
| 3844 | int id; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3845 | struct wpa_cred *cred, *prev; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3846 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3847 | /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or |
| 3848 | * "provisioning_sp=<FQDN> */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3849 | if (os_strcmp(cmd, "all") == 0) { |
| 3850 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all"); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3851 | return wpas_remove_all_creds(wpa_s); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3852 | } |
| 3853 | |
| 3854 | if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) { |
| 3855 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'", |
| 3856 | cmd + 8); |
| 3857 | cred = wpa_s->conf->cred; |
| 3858 | while (cred) { |
| 3859 | prev = cred; |
| 3860 | cred = cred->next; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3861 | if (prev->domain) { |
| 3862 | size_t i; |
| 3863 | for (i = 0; i < prev->num_domain; i++) { |
| 3864 | if (os_strcmp(prev->domain[i], cmd + 8) |
| 3865 | != 0) |
| 3866 | continue; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3867 | wpas_remove_cred(wpa_s, prev); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3868 | break; |
| 3869 | } |
| 3870 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3871 | } |
| 3872 | return 0; |
| 3873 | } |
| 3874 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3875 | if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) { |
| 3876 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'", |
| 3877 | cmd + 16); |
| 3878 | cred = wpa_s->conf->cred; |
| 3879 | while (cred) { |
| 3880 | prev = cred; |
| 3881 | cred = cred->next; |
| 3882 | if (prev->provisioning_sp && |
| 3883 | os_strcmp(prev->provisioning_sp, cmd + 16) == 0) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3884 | wpas_remove_cred(wpa_s, prev); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3885 | } |
| 3886 | return 0; |
| 3887 | } |
| 3888 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3889 | id = atoi(cmd); |
| 3890 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id); |
| 3891 | |
| 3892 | cred = wpa_config_get_cred(wpa_s->conf, id); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3893 | return wpas_remove_cred(wpa_s, cred); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | |
| 3897 | static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s, |
| 3898 | char *cmd) |
| 3899 | { |
| 3900 | int id; |
| 3901 | struct wpa_cred *cred; |
| 3902 | char *name, *value; |
| 3903 | |
| 3904 | /* cmd: "<cred id> <variable name> <value>" */ |
| 3905 | name = os_strchr(cmd, ' '); |
| 3906 | if (name == NULL) |
| 3907 | return -1; |
| 3908 | *name++ = '\0'; |
| 3909 | |
| 3910 | value = os_strchr(name, ' '); |
| 3911 | if (value == NULL) |
| 3912 | return -1; |
| 3913 | *value++ = '\0'; |
| 3914 | |
| 3915 | id = atoi(cmd); |
| 3916 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'", |
| 3917 | id, name); |
| 3918 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", |
| 3919 | (u8 *) value, os_strlen(value)); |
| 3920 | |
| 3921 | cred = wpa_config_get_cred(wpa_s->conf, id); |
| 3922 | if (cred == NULL) { |
| 3923 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", |
| 3924 | id); |
| 3925 | return -1; |
| 3926 | } |
| 3927 | |
| 3928 | if (wpa_config_set_cred(cred, name, value, 0) < 0) { |
| 3929 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred " |
| 3930 | "variable '%s'", name); |
| 3931 | return -1; |
| 3932 | } |
| 3933 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3934 | wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name); |
| 3935 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3936 | return 0; |
| 3937 | } |
| 3938 | |
| 3939 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3940 | static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s, |
| 3941 | char *cmd, char *buf, |
| 3942 | size_t buflen) |
| 3943 | { |
| 3944 | int id; |
| 3945 | size_t res; |
| 3946 | struct wpa_cred *cred; |
| 3947 | char *name, *value; |
| 3948 | |
| 3949 | /* cmd: "<cred id> <variable name>" */ |
| 3950 | name = os_strchr(cmd, ' '); |
| 3951 | if (name == NULL) |
| 3952 | return -1; |
| 3953 | *name++ = '\0'; |
| 3954 | |
| 3955 | id = atoi(cmd); |
| 3956 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'", |
| 3957 | id, name); |
| 3958 | |
| 3959 | cred = wpa_config_get_cred(wpa_s->conf, id); |
| 3960 | if (cred == NULL) { |
| 3961 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", |
| 3962 | id); |
| 3963 | return -1; |
| 3964 | } |
| 3965 | |
| 3966 | value = wpa_config_get_cred_no_key(cred, name); |
| 3967 | if (value == NULL) { |
| 3968 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'", |
| 3969 | name); |
| 3970 | return -1; |
| 3971 | } |
| 3972 | |
| 3973 | res = os_strlcpy(buf, value, buflen); |
| 3974 | if (res >= buflen) { |
| 3975 | os_free(value); |
| 3976 | return -1; |
| 3977 | } |
| 3978 | |
| 3979 | os_free(value); |
| 3980 | |
| 3981 | return res; |
| 3982 | } |
| 3983 | |
| 3984 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3985 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 3986 | static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s) |
| 3987 | { |
| 3988 | int ret; |
| 3989 | |
| 3990 | if (!wpa_s->conf->update_config) { |
| 3991 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed " |
| 3992 | "to update configuration (update_config=0)"); |
| 3993 | return -1; |
| 3994 | } |
| 3995 | |
| 3996 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); |
| 3997 | if (ret) { |
| 3998 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to " |
| 3999 | "update configuration"); |
| 4000 | } else { |
| 4001 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration" |
| 4002 | " updated"); |
| 4003 | } |
| 4004 | |
| 4005 | return ret; |
| 4006 | } |
| 4007 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 4008 | |
| 4009 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4010 | struct cipher_info { |
| 4011 | unsigned int capa; |
| 4012 | const char *name; |
| 4013 | int group_only; |
| 4014 | }; |
| 4015 | |
| 4016 | static const struct cipher_info ciphers[] = { |
| 4017 | { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 }, |
| 4018 | { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 }, |
| 4019 | { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 }, |
| 4020 | { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 }, |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4021 | #ifndef CONFIG_NO_TKIP |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4022 | { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 }, |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4023 | #endif /* CONFIG_NO_TKIP */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4024 | { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 }, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4025 | #ifdef CONFIG_WEP |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4026 | { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 }, |
| 4027 | { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4028 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4029 | }; |
| 4030 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4031 | static const struct cipher_info ciphers_group_mgmt[] = { |
| 4032 | { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 }, |
| 4033 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 }, |
| 4034 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 }, |
| 4035 | { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 }, |
| 4036 | }; |
| 4037 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4038 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4039 | static int ctrl_iface_get_capability_pairwise(int res, bool strict, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4040 | struct wpa_driver_capa *capa, |
| 4041 | char *buf, size_t buflen) |
| 4042 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4043 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4044 | char *pos, *end; |
| 4045 | size_t len; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4046 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4047 | |
| 4048 | pos = buf; |
| 4049 | end = pos + buflen; |
| 4050 | |
| 4051 | if (res < 0) { |
| 4052 | if (strict) |
| 4053 | return 0; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4054 | #ifdef CONFIG_NO_TKIP |
| 4055 | len = os_strlcpy(buf, "CCMP NONE", buflen); |
| 4056 | #else /* CONFIG_NO_TKIP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4057 | len = os_strlcpy(buf, "CCMP TKIP NONE", buflen); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4058 | #endif /* CONFIG_NO_TKIP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4059 | if (len >= buflen) |
| 4060 | return -1; |
| 4061 | return len; |
| 4062 | } |
| 4063 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4064 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
| 4065 | if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) { |
| 4066 | ret = os_snprintf(pos, end - pos, "%s%s", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4067 | pos == buf ? "" : " ", |
| 4068 | ciphers[i].name); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4069 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4070 | return pos - buf; |
| 4071 | pos += ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4072 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4073 | } |
| 4074 | |
| 4075 | return pos - buf; |
| 4076 | } |
| 4077 | |
| 4078 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4079 | static int ctrl_iface_get_capability_group(int res, bool strict, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4080 | struct wpa_driver_capa *capa, |
| 4081 | char *buf, size_t buflen) |
| 4082 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4083 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4084 | char *pos, *end; |
| 4085 | size_t len; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4086 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4087 | |
| 4088 | pos = buf; |
| 4089 | end = pos + buflen; |
| 4090 | |
| 4091 | if (res < 0) { |
| 4092 | if (strict) |
| 4093 | return 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4094 | #ifdef CONFIG_WEP |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4095 | #ifdef CONFIG_NO_TKIP |
| 4096 | len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen); |
| 4097 | #else /* CONFIG_NO_TKIP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4098 | len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4099 | #endif /* CONFIG_NO_TKIP */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4100 | #else /* CONFIG_WEP */ |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4101 | #ifdef CONFIG_NO_TKIP |
| 4102 | len = os_strlcpy(buf, "CCMP", buflen); |
| 4103 | #else /* CONFIG_NO_TKIP */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4104 | len = os_strlcpy(buf, "CCMP TKIP", buflen); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4105 | #endif /* CONFIG_NO_TKIP */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4106 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4107 | if (len >= buflen) |
| 4108 | return -1; |
| 4109 | return len; |
| 4110 | } |
| 4111 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4112 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
| 4113 | if (capa->enc & ciphers[i].capa) { |
| 4114 | ret = os_snprintf(pos, end - pos, "%s%s", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4115 | pos == buf ? "" : " ", |
| 4116 | ciphers[i].name); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4117 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4118 | return pos - buf; |
| 4119 | pos += ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4120 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | return pos - buf; |
| 4124 | } |
| 4125 | |
| 4126 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4127 | static int ctrl_iface_get_capability_group_mgmt(int res, bool strict, |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4128 | struct wpa_driver_capa *capa, |
| 4129 | char *buf, size_t buflen) |
| 4130 | { |
| 4131 | int ret; |
| 4132 | char *pos, *end; |
| 4133 | unsigned int i; |
| 4134 | |
| 4135 | pos = buf; |
| 4136 | end = pos + buflen; |
| 4137 | |
| 4138 | if (res < 0) |
| 4139 | return 0; |
| 4140 | |
| 4141 | for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) { |
| 4142 | if (capa->enc & ciphers_group_mgmt[i].capa) { |
| 4143 | ret = os_snprintf(pos, end - pos, "%s%s", |
| 4144 | pos == buf ? "" : " ", |
| 4145 | ciphers_group_mgmt[i].name); |
| 4146 | if (os_snprintf_error(end - pos, ret)) |
| 4147 | return pos - buf; |
| 4148 | pos += ret; |
| 4149 | } |
| 4150 | } |
| 4151 | |
| 4152 | return pos - buf; |
| 4153 | } |
| 4154 | |
| 4155 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4156 | static int iftype_str_to_index(const char *iftype_str) |
| 4157 | { |
| 4158 | if (!iftype_str) |
| 4159 | return WPA_IF_MAX; |
| 4160 | |
| 4161 | if (os_strcmp(iftype_str, "STATION") == 0) |
| 4162 | return WPA_IF_STATION; |
| 4163 | |
| 4164 | if (os_strcmp(iftype_str, "AP_VLAN") == 0) |
| 4165 | return WPA_IF_AP_VLAN; |
| 4166 | |
| 4167 | if (os_strcmp(iftype_str, "AP") == 0) |
| 4168 | return WPA_IF_AP_BSS; |
| 4169 | |
| 4170 | if (os_strcmp(iftype_str, "P2P_GO") == 0) |
| 4171 | return WPA_IF_P2P_GO; |
| 4172 | |
| 4173 | if (os_strcmp(iftype_str, "P2P_CLIENT") == 0) |
| 4174 | return WPA_IF_P2P_CLIENT; |
| 4175 | |
| 4176 | if (os_strcmp(iftype_str, "P2P_DEVICE") == 0) |
| 4177 | return WPA_IF_P2P_DEVICE; |
| 4178 | |
| 4179 | if (os_strcmp(iftype_str, "MESH") == 0) |
| 4180 | return WPA_IF_MESH; |
| 4181 | |
| 4182 | if (os_strcmp(iftype_str, "IBSS") == 0) |
| 4183 | return WPA_IF_IBSS; |
| 4184 | |
| 4185 | if (os_strcmp(iftype_str, "NAN") == 0) |
| 4186 | return WPA_IF_NAN; |
| 4187 | |
| 4188 | return WPA_IF_MAX; |
| 4189 | } |
| 4190 | |
| 4191 | |
| 4192 | static int ctrl_iface_get_capability_key_mgmt(int res, bool strict, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4193 | struct wpa_driver_capa *capa, |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4194 | const char *iftype_str, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4195 | char *buf, size_t buflen) |
| 4196 | { |
| 4197 | int ret; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4198 | unsigned int key_mgmt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4199 | char *pos, *end; |
| 4200 | size_t len; |
| 4201 | |
| 4202 | pos = buf; |
| 4203 | end = pos + buflen; |
| 4204 | |
| 4205 | if (res < 0) { |
| 4206 | if (strict) |
| 4207 | return 0; |
| 4208 | len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE " |
| 4209 | "NONE", buflen); |
| 4210 | if (len >= buflen) |
| 4211 | return -1; |
| 4212 | return len; |
| 4213 | } |
| 4214 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4215 | if (iftype_str) { |
| 4216 | enum wpa_driver_if_type iftype; |
| 4217 | |
| 4218 | iftype = iftype_str_to_index(iftype_str); |
| 4219 | if (iftype == WPA_IF_MAX) |
| 4220 | return -1; |
| 4221 | key_mgmt = capa->key_mgmt_iftype[iftype]; |
| 4222 | } else { |
| 4223 | key_mgmt = capa->key_mgmt; |
| 4224 | } |
| 4225 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4226 | ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4227 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4228 | return pos - buf; |
| 4229 | pos += ret; |
| 4230 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4231 | if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
| 4232 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4233 | ret = os_snprintf(pos, end - pos, " WPA-EAP"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4234 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4235 | return pos - buf; |
| 4236 | pos += ret; |
| 4237 | } |
| 4238 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4239 | if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | |
| 4240 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4241 | ret = os_snprintf(pos, end - pos, " WPA-PSK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4242 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4243 | return pos - buf; |
| 4244 | pos += ret; |
| 4245 | } |
| 4246 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4247 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4248 | ret = os_snprintf(pos, end - pos, " WPA-NONE"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4249 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4250 | return pos - buf; |
| 4251 | pos += ret; |
| 4252 | } |
| 4253 | |
Tanmay Garg | a7fd80d | 2020-05-18 15:52:44 +0530 | [diff] [blame] | 4254 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WAPI_PSK) { |
| 4255 | ret = os_snprintf(pos, end - pos, " WAPI-PSK"); |
| 4256 | if (os_snprintf_error(end - pos, ret)) |
| 4257 | return pos - buf; |
| 4258 | pos += ret; |
| 4259 | } |
| 4260 | |
| 4261 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE) { |
| 4262 | ret = os_snprintf(pos, end - pos, " TPK-HANDSHAKE"); |
| 4263 | if (os_snprintf_error(end - pos, ret)) |
| 4264 | return pos - buf; |
| 4265 | pos += ret; |
| 4266 | } |
| 4267 | |
| 4268 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_CCKM) { |
| 4269 | ret = os_snprintf(pos, end - pos, " CCKM"); |
| 4270 | if (os_snprintf_error(end - pos, ret)) |
| 4271 | return pos - buf; |
| 4272 | pos += ret; |
| 4273 | } |
| 4274 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4275 | #ifdef CONFIG_SUITEB |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4276 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4277 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B"); |
| 4278 | if (os_snprintf_error(end - pos, ret)) |
| 4279 | return pos - buf; |
| 4280 | pos += ret; |
| 4281 | } |
| 4282 | #endif /* CONFIG_SUITEB */ |
| 4283 | #ifdef CONFIG_SUITEB192 |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4284 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4285 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192"); |
| 4286 | if (os_snprintf_error(end - pos, ret)) |
| 4287 | return pos - buf; |
| 4288 | pos += ret; |
| 4289 | } |
| 4290 | #endif /* CONFIG_SUITEB192 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4291 | #ifdef CONFIG_OWE |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4292 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4293 | ret = os_snprintf(pos, end - pos, " OWE"); |
| 4294 | if (os_snprintf_error(end - pos, ret)) |
| 4295 | return pos - buf; |
| 4296 | pos += ret; |
| 4297 | } |
| 4298 | #endif /* CONFIG_OWE */ |
| 4299 | #ifdef CONFIG_DPP |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4300 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4301 | ret = os_snprintf(pos, end - pos, " DPP"); |
| 4302 | if (os_snprintf_error(end - pos, ret)) |
| 4303 | return pos - buf; |
| 4304 | pos += ret; |
| 4305 | } |
| 4306 | #endif /* CONFIG_DPP */ |
| 4307 | #ifdef CONFIG_FILS |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4308 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4309 | ret = os_snprintf(pos, end - pos, " FILS-SHA256"); |
| 4310 | if (os_snprintf_error(end - pos, ret)) |
| 4311 | return pos - buf; |
| 4312 | pos += ret; |
| 4313 | } |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4314 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4315 | ret = os_snprintf(pos, end - pos, " FILS-SHA384"); |
| 4316 | if (os_snprintf_error(end - pos, ret)) |
| 4317 | return pos - buf; |
| 4318 | pos += ret; |
| 4319 | } |
| 4320 | #ifdef CONFIG_IEEE80211R |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4321 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4322 | ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256"); |
| 4323 | if (os_snprintf_error(end - pos, ret)) |
| 4324 | return pos - buf; |
| 4325 | pos += ret; |
| 4326 | } |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4327 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4328 | ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384"); |
| 4329 | if (os_snprintf_error(end - pos, ret)) |
| 4330 | return pos - buf; |
| 4331 | pos += ret; |
| 4332 | } |
| 4333 | #endif /* CONFIG_IEEE80211R */ |
| 4334 | #endif /* CONFIG_FILS */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4335 | #ifdef CONFIG_IEEE80211R |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4336 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4337 | ret = os_snprintf(pos, end - pos, " FT-PSK"); |
| 4338 | if (os_snprintf_error(end - pos, ret)) |
| 4339 | return pos - buf; |
| 4340 | pos += ret; |
| 4341 | } |
Tanmay Garg | a7fd80d | 2020-05-18 15:52:44 +0530 | [diff] [blame] | 4342 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) { |
| 4343 | ret = os_snprintf(pos, end - pos, " FT-EAP"); |
| 4344 | if (os_snprintf_error(end - pos, ret)) |
| 4345 | return pos - buf; |
| 4346 | pos += ret; |
| 4347 | } |
| 4348 | #ifdef CONFIG_SAE |
| 4349 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE) { |
| 4350 | ret = os_snprintf(pos, end - pos, " FT-SAE"); |
| 4351 | if (os_snprintf_error(end - pos, ret)) |
| 4352 | return pos - buf; |
| 4353 | pos += ret; |
| 4354 | } |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 4355 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE_EXT_KEY) { |
| 4356 | ret = os_snprintf(pos, end - pos, " FT-SAE-EXT-KEY"); |
| 4357 | if (os_snprintf_error(end - pos, ret)) |
| 4358 | return pos - buf; |
| 4359 | pos += ret; |
| 4360 | } |
Tanmay Garg | a7fd80d | 2020-05-18 15:52:44 +0530 | [diff] [blame] | 4361 | #endif /* CONFIG_SAE */ |
| 4362 | #ifdef CONFIG_SHA384 |
| 4363 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384) { |
| 4364 | ret = os_snprintf(pos, end - pos, " FT-EAP-SHA384"); |
| 4365 | if (os_snprintf_error(end - pos, ret)) |
| 4366 | return pos - buf; |
| 4367 | pos += ret; |
| 4368 | } |
| 4369 | #endif /* CONFIG_SHA384 */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4370 | #endif /* CONFIG_IEEE80211R */ |
| 4371 | #ifdef CONFIG_SAE |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4372 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4373 | ret = os_snprintf(pos, end - pos, " SAE"); |
| 4374 | if (os_snprintf_error(end - pos, ret)) |
| 4375 | return pos - buf; |
| 4376 | pos += ret; |
| 4377 | } |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 4378 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE_EXT_KEY) { |
| 4379 | ret = os_snprintf(pos, end - pos, " SAE-EXT-KEY"); |
| 4380 | if (os_snprintf_error(end - pos, ret)) |
| 4381 | return pos - buf; |
| 4382 | pos += ret; |
| 4383 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4384 | #endif /* CONFIG_SAE */ |
Tanmay Garg | a7fd80d | 2020-05-18 15:52:44 +0530 | [diff] [blame] | 4385 | #ifdef CONFIG_SHA256 |
| 4386 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256) { |
| 4387 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SHA256"); |
| 4388 | if (os_snprintf_error(end - pos, ret)) |
| 4389 | return pos - buf; |
| 4390 | pos += ret; |
| 4391 | } |
| 4392 | |
| 4393 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256) { |
| 4394 | ret = os_snprintf(pos, end - pos, " WPA-PSK-SHA256"); |
| 4395 | if (os_snprintf_error(end - pos, ret)) |
| 4396 | return pos - buf; |
| 4397 | pos += ret; |
| 4398 | } |
| 4399 | #endif /* CONFIG_SHA256 */ |
| 4400 | #ifdef CONFIG_HS20 |
| 4401 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OSEN) { |
| 4402 | ret = os_snprintf(pos, end - pos, " OSEN"); |
| 4403 | if (os_snprintf_error(end - pos, ret)) |
| 4404 | return pos - buf; |
| 4405 | pos += ret; |
| 4406 | } |
| 4407 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4408 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4409 | return pos - buf; |
| 4410 | } |
| 4411 | |
| 4412 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4413 | static int ctrl_iface_get_capability_proto(int res, bool strict, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4414 | struct wpa_driver_capa *capa, |
| 4415 | char *buf, size_t buflen) |
| 4416 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4417 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4418 | char *pos, *end; |
| 4419 | size_t len; |
| 4420 | |
| 4421 | pos = buf; |
| 4422 | end = pos + buflen; |
| 4423 | |
| 4424 | if (res < 0) { |
| 4425 | if (strict) |
| 4426 | return 0; |
| 4427 | len = os_strlcpy(buf, "RSN WPA", buflen); |
| 4428 | if (len >= buflen) |
| 4429 | return -1; |
| 4430 | return len; |
| 4431 | } |
| 4432 | |
| 4433 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | |
| 4434 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4435 | ret = os_snprintf(pos, end - pos, "%sRSN", |
| 4436 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4437 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4438 | return pos - buf; |
| 4439 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
| 4443 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4444 | ret = os_snprintf(pos, end - pos, "%sWPA", |
| 4445 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4446 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4447 | return pos - buf; |
| 4448 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | return pos - buf; |
| 4452 | } |
| 4453 | |
| 4454 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4455 | 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] | 4456 | int res, bool strict, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4457 | struct wpa_driver_capa *capa, |
| 4458 | char *buf, size_t buflen) |
| 4459 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4460 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4461 | char *pos, *end; |
| 4462 | size_t len; |
| 4463 | |
| 4464 | pos = buf; |
| 4465 | end = pos + buflen; |
| 4466 | |
| 4467 | if (res < 0) { |
| 4468 | if (strict) |
| 4469 | return 0; |
| 4470 | len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen); |
| 4471 | if (len >= buflen) |
| 4472 | return -1; |
| 4473 | return len; |
| 4474 | } |
| 4475 | |
| 4476 | if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4477 | ret = os_snprintf(pos, end - pos, "%sOPEN", |
| 4478 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4479 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4480 | return pos - buf; |
| 4481 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4482 | } |
| 4483 | |
| 4484 | if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) { |
| 4485 | ret = os_snprintf(pos, end - pos, "%sSHARED", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4486 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4487 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4488 | return pos - buf; |
| 4489 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4493 | ret = os_snprintf(pos, end - pos, "%sLEAP", |
| 4494 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4495 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4496 | return pos - buf; |
| 4497 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4498 | } |
| 4499 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4500 | #ifdef CONFIG_SAE |
| 4501 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) { |
| 4502 | ret = os_snprintf(pos, end - pos, "%sSAE", |
| 4503 | pos == buf ? "" : " "); |
| 4504 | if (os_snprintf_error(end - pos, ret)) |
| 4505 | return pos - buf; |
| 4506 | pos += ret; |
| 4507 | } |
| 4508 | #endif /* CONFIG_SAE */ |
| 4509 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4510 | #ifdef CONFIG_FILS |
| 4511 | if (wpa_is_fils_supported(wpa_s)) { |
| 4512 | ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS", |
| 4513 | pos == buf ? "" : " "); |
| 4514 | if (os_snprintf_error(end - pos, ret)) |
| 4515 | return pos - buf; |
| 4516 | pos += ret; |
| 4517 | } |
| 4518 | |
| 4519 | #ifdef CONFIG_FILS_SK_PFS |
| 4520 | if (wpa_is_fils_sk_pfs_supported(wpa_s)) { |
| 4521 | ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS", |
| 4522 | pos == buf ? "" : " "); |
| 4523 | if (os_snprintf_error(end - pos, ret)) |
| 4524 | return pos - buf; |
| 4525 | pos += ret; |
| 4526 | } |
| 4527 | #endif /* CONFIG_FILS_SK_PFS */ |
| 4528 | #endif /* CONFIG_FILS */ |
| 4529 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4530 | #ifdef CONFIG_PASN |
| 4531 | ret = os_snprintf(pos, end - pos, "%sPASN", |
| 4532 | pos == buf ? "" : " "); |
| 4533 | if (os_snprintf_error(end - pos, ret)) |
| 4534 | return pos - buf; |
| 4535 | pos += ret; |
| 4536 | |
| 4537 | #endif /* CONFIG_PASN */ |
| 4538 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4539 | return pos - buf; |
| 4540 | } |
| 4541 | |
| 4542 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4543 | static int ctrl_iface_get_capability_modes(int res, bool strict, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4544 | struct wpa_driver_capa *capa, |
| 4545 | char *buf, size_t buflen) |
| 4546 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4547 | int ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4548 | char *pos, *end; |
| 4549 | size_t len; |
| 4550 | |
| 4551 | pos = buf; |
| 4552 | end = pos + buflen; |
| 4553 | |
| 4554 | if (res < 0) { |
| 4555 | if (strict) |
| 4556 | return 0; |
| 4557 | len = os_strlcpy(buf, "IBSS AP", buflen); |
| 4558 | if (len >= buflen) |
| 4559 | return -1; |
| 4560 | return len; |
| 4561 | } |
| 4562 | |
| 4563 | if (capa->flags & WPA_DRIVER_FLAGS_IBSS) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4564 | ret = os_snprintf(pos, end - pos, "%sIBSS", |
| 4565 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4566 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4567 | return pos - buf; |
| 4568 | pos += ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | if (capa->flags & WPA_DRIVER_FLAGS_AP) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4572 | ret = os_snprintf(pos, end - pos, "%sAP", |
| 4573 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4574 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4575 | return pos - buf; |
| 4576 | pos += ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4577 | } |
| 4578 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4579 | #ifdef CONFIG_MESH |
| 4580 | if (capa->flags & WPA_DRIVER_FLAGS_MESH) { |
| 4581 | ret = os_snprintf(pos, end - pos, "%sMESH", |
| 4582 | pos == buf ? "" : " "); |
| 4583 | if (os_snprintf_error(end - pos, ret)) |
| 4584 | return pos - buf; |
| 4585 | pos += ret; |
| 4586 | } |
| 4587 | #endif /* CONFIG_MESH */ |
| 4588 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4589 | return pos - buf; |
| 4590 | } |
| 4591 | |
| 4592 | |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4593 | static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s, |
| 4594 | char *buf, size_t buflen) |
| 4595 | { |
| 4596 | struct hostapd_channel_data *chnl; |
| 4597 | int ret, i, j; |
| 4598 | char *pos, *end, *hmode; |
| 4599 | |
| 4600 | pos = buf; |
| 4601 | end = pos + buflen; |
| 4602 | |
| 4603 | for (j = 0; j < wpa_s->hw.num_modes; j++) { |
| 4604 | switch (wpa_s->hw.modes[j].mode) { |
| 4605 | case HOSTAPD_MODE_IEEE80211B: |
| 4606 | hmode = "B"; |
| 4607 | break; |
| 4608 | case HOSTAPD_MODE_IEEE80211G: |
| 4609 | hmode = "G"; |
| 4610 | break; |
| 4611 | case HOSTAPD_MODE_IEEE80211A: |
| 4612 | hmode = "A"; |
| 4613 | break; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4614 | case HOSTAPD_MODE_IEEE80211AD: |
| 4615 | hmode = "AD"; |
| 4616 | break; |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4617 | default: |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4618 | continue; |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4619 | } |
| 4620 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4621 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4622 | return pos - buf; |
| 4623 | pos += ret; |
| 4624 | chnl = wpa_s->hw.modes[j].channels; |
| 4625 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4626 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) |
| 4627 | continue; |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4628 | ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4629 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4630 | return pos - buf; |
| 4631 | pos += ret; |
| 4632 | } |
| 4633 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4634 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4635 | return pos - buf; |
| 4636 | pos += ret; |
| 4637 | } |
| 4638 | |
| 4639 | return pos - buf; |
| 4640 | } |
| 4641 | |
| 4642 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4643 | static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s, |
| 4644 | char *buf, size_t buflen) |
| 4645 | { |
| 4646 | struct hostapd_channel_data *chnl; |
| 4647 | int ret, i, j; |
| 4648 | char *pos, *end, *hmode; |
| 4649 | |
| 4650 | pos = buf; |
| 4651 | end = pos + buflen; |
| 4652 | |
| 4653 | for (j = 0; j < wpa_s->hw.num_modes; j++) { |
| 4654 | switch (wpa_s->hw.modes[j].mode) { |
| 4655 | case HOSTAPD_MODE_IEEE80211B: |
| 4656 | hmode = "B"; |
| 4657 | break; |
| 4658 | case HOSTAPD_MODE_IEEE80211G: |
| 4659 | hmode = "G"; |
| 4660 | break; |
| 4661 | case HOSTAPD_MODE_IEEE80211A: |
| 4662 | hmode = "A"; |
| 4663 | break; |
| 4664 | case HOSTAPD_MODE_IEEE80211AD: |
| 4665 | hmode = "AD"; |
| 4666 | break; |
| 4667 | default: |
| 4668 | continue; |
| 4669 | } |
| 4670 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n", |
| 4671 | hmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4672 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4673 | return pos - buf; |
| 4674 | pos += ret; |
| 4675 | chnl = wpa_s->hw.modes[j].channels; |
| 4676 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { |
| 4677 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) |
| 4678 | continue; |
Dmitry Shmidt | 5da5e35 | 2014-02-03 13:30:46 -0800 | [diff] [blame] | 4679 | ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n", |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4680 | chnl[i].chan, chnl[i].freq, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4681 | chnl[i].flag & HOSTAPD_CHAN_NO_IR ? |
| 4682 | " (NO_IR)" : "", |
Dmitry Shmidt | 5da5e35 | 2014-02-03 13:30:46 -0800 | [diff] [blame] | 4683 | chnl[i].flag & HOSTAPD_CHAN_RADAR ? |
| 4684 | " (DFS)" : ""); |
| 4685 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4686 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4687 | return pos - buf; |
| 4688 | pos += ret; |
| 4689 | } |
| 4690 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4691 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4692 | return pos - buf; |
| 4693 | pos += ret; |
| 4694 | } |
| 4695 | |
| 4696 | return pos - buf; |
| 4697 | } |
| 4698 | |
| 4699 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4700 | static int wpa_supplicant_ctrl_iface_get_capability( |
| 4701 | struct wpa_supplicant *wpa_s, const char *_field, char *buf, |
| 4702 | size_t buflen) |
| 4703 | { |
| 4704 | struct wpa_driver_capa capa; |
| 4705 | int res; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4706 | char *next_param, *curr_param, *iftype = NULL; |
| 4707 | bool strict = false; |
| 4708 | char field[50]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4709 | size_t len; |
| 4710 | |
| 4711 | /* Determine whether or not strict checking was requested */ |
| 4712 | len = os_strlcpy(field, _field, sizeof(field)); |
| 4713 | if (len >= sizeof(field)) |
| 4714 | return -1; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4715 | |
| 4716 | next_param = os_strchr(field, ' '); |
| 4717 | while (next_param) { |
| 4718 | *next_param++ = '\0'; |
| 4719 | curr_param = next_param; |
| 4720 | next_param = os_strchr(next_param, ' '); |
| 4721 | |
| 4722 | if (next_param) |
| 4723 | *next_param = '\0'; |
| 4724 | |
| 4725 | if (os_strcmp(curr_param, "strict") == 0) |
| 4726 | strict = true; |
| 4727 | else if (os_strncmp(curr_param, "iftype=", 7) == 0) |
| 4728 | iftype = curr_param + 7; |
| 4729 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4730 | return -1; |
| 4731 | } |
| 4732 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4733 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'%s%s%s", |
| 4734 | field, iftype ? " iftype=" : "", iftype ? iftype : "", |
| 4735 | strict ? " strict" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4736 | |
| 4737 | if (os_strcmp(field, "eap") == 0) { |
| 4738 | return eap_get_names(buf, buflen); |
| 4739 | } |
| 4740 | |
| 4741 | res = wpa_drv_get_capa(wpa_s, &capa); |
| 4742 | |
| 4743 | if (os_strcmp(field, "pairwise") == 0) |
| 4744 | return ctrl_iface_get_capability_pairwise(res, strict, &capa, |
| 4745 | buf, buflen); |
| 4746 | |
| 4747 | if (os_strcmp(field, "group") == 0) |
| 4748 | return ctrl_iface_get_capability_group(res, strict, &capa, |
| 4749 | buf, buflen); |
| 4750 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4751 | if (os_strcmp(field, "group_mgmt") == 0) |
| 4752 | return ctrl_iface_get_capability_group_mgmt(res, strict, &capa, |
| 4753 | buf, buflen); |
| 4754 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4755 | if (os_strcmp(field, "key_mgmt") == 0) |
| 4756 | return ctrl_iface_get_capability_key_mgmt(res, strict, &capa, |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4757 | iftype, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4758 | |
| 4759 | if (os_strcmp(field, "proto") == 0) |
| 4760 | return ctrl_iface_get_capability_proto(res, strict, &capa, |
| 4761 | buf, buflen); |
| 4762 | |
| 4763 | if (os_strcmp(field, "auth_alg") == 0) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4764 | return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict, |
| 4765 | &capa, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4766 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4767 | if (os_strcmp(field, "modes") == 0) |
| 4768 | return ctrl_iface_get_capability_modes(res, strict, &capa, |
| 4769 | buf, buflen); |
| 4770 | |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4771 | if (os_strcmp(field, "channels") == 0) |
| 4772 | return ctrl_iface_get_capability_channels(wpa_s, buf, buflen); |
| 4773 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4774 | if (os_strcmp(field, "freq") == 0) |
| 4775 | return ctrl_iface_get_capability_freq(wpa_s, buf, buflen); |
| 4776 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 4777 | #ifdef CONFIG_TDLS |
| 4778 | if (os_strcmp(field, "tdls") == 0) |
| 4779 | return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen); |
| 4780 | #endif /* CONFIG_TDLS */ |
| 4781 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4782 | #ifdef CONFIG_ERP |
| 4783 | if (os_strcmp(field, "erp") == 0) { |
| 4784 | res = os_snprintf(buf, buflen, "ERP"); |
| 4785 | if (os_snprintf_error(buflen, res)) |
| 4786 | return -1; |
| 4787 | return res; |
| 4788 | } |
| 4789 | #endif /* CONFIG_EPR */ |
| 4790 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4791 | #ifdef CONFIG_FIPS |
| 4792 | if (os_strcmp(field, "fips") == 0) { |
| 4793 | res = os_snprintf(buf, buflen, "FIPS"); |
| 4794 | if (os_snprintf_error(buflen, res)) |
| 4795 | return -1; |
| 4796 | return res; |
| 4797 | } |
| 4798 | #endif /* CONFIG_FIPS */ |
| 4799 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 4800 | #ifdef CONFIG_ACS |
| 4801 | if (os_strcmp(field, "acs") == 0) { |
| 4802 | res = os_snprintf(buf, buflen, "ACS"); |
| 4803 | if (os_snprintf_error(buflen, res)) |
| 4804 | return -1; |
| 4805 | return res; |
| 4806 | } |
| 4807 | #endif /* CONFIG_ACS */ |
| 4808 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4809 | #ifdef CONFIG_FILS |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4810 | if (os_strcmp(field, "fils") == 0) { |
| 4811 | #ifdef CONFIG_FILS_SK_PFS |
| 4812 | if (wpa_is_fils_supported(wpa_s) && |
| 4813 | wpa_is_fils_sk_pfs_supported(wpa_s)) { |
| 4814 | res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS"); |
| 4815 | if (os_snprintf_error(buflen, res)) |
| 4816 | return -1; |
| 4817 | return res; |
| 4818 | } |
| 4819 | #endif /* CONFIG_FILS_SK_PFS */ |
| 4820 | |
| 4821 | if (wpa_is_fils_supported(wpa_s)) { |
| 4822 | res = os_snprintf(buf, buflen, "FILS"); |
| 4823 | if (os_snprintf_error(buflen, res)) |
| 4824 | return -1; |
| 4825 | return res; |
| 4826 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4827 | } |
| 4828 | #endif /* CONFIG_FILS */ |
| 4829 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4830 | if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) { |
| 4831 | res = os_snprintf(buf, buflen, "MULTIBSS-STA"); |
| 4832 | if (os_snprintf_error(buflen, res)) |
| 4833 | return -1; |
| 4834 | return res; |
| 4835 | } |
| 4836 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4837 | #ifdef CONFIG_DPP |
| 4838 | if (os_strcmp(field, "dpp") == 0) { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4839 | #ifdef CONFIG_DPP3 |
| 4840 | res = os_snprintf(buf, buflen, "DPP=3"); |
| 4841 | #elif defined(CONFIG_DPP2) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4842 | res = os_snprintf(buf, buflen, "DPP=2"); |
| 4843 | #else /* CONFIG_DPP2 */ |
| 4844 | res = os_snprintf(buf, buflen, "DPP=1"); |
| 4845 | #endif /* CONFIG_DPP2 */ |
| 4846 | if (os_snprintf_error(buflen, res)) |
| 4847 | return -1; |
| 4848 | return res; |
| 4849 | } |
| 4850 | #endif /* CONFIG_DPP */ |
| 4851 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4852 | #ifdef CONFIG_SAE |
| 4853 | if (os_strcmp(field, "sae") == 0 && |
| 4854 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) { |
| 4855 | #ifdef CONFIG_SAE_PK |
| 4856 | res = os_snprintf(buf, buflen, "H2E PK"); |
| 4857 | #else /* CONFIG_SAE_PK */ |
| 4858 | res = os_snprintf(buf, buflen, "H2E"); |
| 4859 | #endif /* CONFIG_SAE_PK */ |
| 4860 | if (os_snprintf_error(buflen, res)) |
| 4861 | return -1; |
| 4862 | return res; |
| 4863 | } |
| 4864 | #endif /* CONFIG_SAE */ |
| 4865 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4866 | #ifdef CONFIG_OCV |
| 4867 | if (os_strcmp(field, "ocv") == 0) { |
| 4868 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) || |
| 4869 | (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) |
| 4870 | res = os_snprintf(buf, buflen, "supported"); |
| 4871 | else |
| 4872 | res = os_snprintf(buf, buflen, "not supported"); |
| 4873 | if (os_snprintf_error(buflen, res)) |
| 4874 | return -1; |
| 4875 | return res; |
| 4876 | } |
| 4877 | #endif /* CONFIG_OCV */ |
| 4878 | |
| 4879 | if (os_strcmp(field, "beacon_prot") == 0) { |
| 4880 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) || |
| 4881 | (wpa_s->drv_flags2 & |
| 4882 | WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT)) |
| 4883 | res = os_snprintf(buf, buflen, "supported"); |
| 4884 | else |
| 4885 | res = os_snprintf(buf, buflen, "not supported"); |
| 4886 | if (os_snprintf_error(buflen, res)) |
| 4887 | return -1; |
| 4888 | return res; |
| 4889 | } |
| 4890 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4891 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", |
| 4892 | field); |
| 4893 | |
| 4894 | return -1; |
| 4895 | } |
| 4896 | |
| 4897 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4898 | #ifdef CONFIG_INTERWORKING |
| 4899 | static char * anqp_add_hex(char *pos, char *end, const char *title, |
| 4900 | struct wpabuf *data) |
| 4901 | { |
| 4902 | char *start = pos; |
| 4903 | size_t i; |
| 4904 | int ret; |
| 4905 | const u8 *d; |
| 4906 | |
| 4907 | if (data == NULL) |
| 4908 | return start; |
| 4909 | |
| 4910 | ret = os_snprintf(pos, end - pos, "%s=", title); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4911 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4912 | return start; |
| 4913 | pos += ret; |
| 4914 | |
| 4915 | d = wpabuf_head_u8(data); |
| 4916 | for (i = 0; i < wpabuf_len(data); i++) { |
| 4917 | ret = os_snprintf(pos, end - pos, "%02x", *d++); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4918 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4919 | return start; |
| 4920 | pos += ret; |
| 4921 | } |
| 4922 | |
| 4923 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4924 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4925 | return start; |
| 4926 | pos += ret; |
| 4927 | |
| 4928 | return pos; |
| 4929 | } |
| 4930 | #endif /* CONFIG_INTERWORKING */ |
| 4931 | |
| 4932 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4933 | #ifdef CONFIG_FILS |
| 4934 | static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end) |
| 4935 | { |
| 4936 | char *start = pos; |
| 4937 | const u8 *ie, *ie_end; |
| 4938 | u16 info, realms; |
| 4939 | int ret; |
| 4940 | |
| 4941 | ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION); |
| 4942 | if (!ie) |
| 4943 | return 0; |
| 4944 | ie_end = ie + 2 + ie[1]; |
| 4945 | ie += 2; |
| 4946 | if (ie_end - ie < 2) |
| 4947 | return -1; |
| 4948 | |
| 4949 | info = WPA_GET_LE16(ie); |
| 4950 | ie += 2; |
| 4951 | ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info); |
| 4952 | if (os_snprintf_error(end - pos, ret)) |
| 4953 | return 0; |
| 4954 | pos += ret; |
| 4955 | |
| 4956 | if (info & BIT(7)) { |
| 4957 | /* Cache Identifier Included */ |
| 4958 | if (ie_end - ie < 2) |
| 4959 | return -1; |
| 4960 | ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n", |
| 4961 | ie[0], ie[1]); |
| 4962 | if (os_snprintf_error(end - pos, ret)) |
| 4963 | return 0; |
| 4964 | pos += ret; |
| 4965 | ie += 2; |
| 4966 | } |
| 4967 | |
| 4968 | if (info & BIT(8)) { |
| 4969 | /* HESSID Included */ |
| 4970 | if (ie_end - ie < ETH_ALEN) |
| 4971 | return -1; |
| 4972 | ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n", |
| 4973 | MAC2STR(ie)); |
| 4974 | if (os_snprintf_error(end - pos, ret)) |
| 4975 | return 0; |
| 4976 | pos += ret; |
| 4977 | ie += ETH_ALEN; |
| 4978 | } |
| 4979 | |
| 4980 | realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3; |
| 4981 | if (realms) { |
| 4982 | if (ie_end - ie < realms * 2) |
| 4983 | return -1; |
| 4984 | ret = os_snprintf(pos, end - pos, "fils_realms="); |
| 4985 | if (os_snprintf_error(end - pos, ret)) |
| 4986 | return 0; |
| 4987 | pos += ret; |
| 4988 | |
| 4989 | ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2); |
| 4990 | if (ret <= 0) |
| 4991 | return 0; |
| 4992 | pos += ret; |
| 4993 | ie += realms * 2; |
| 4994 | ret = os_snprintf(pos, end - pos, "\n"); |
| 4995 | if (os_snprintf_error(end - pos, ret)) |
| 4996 | return 0; |
| 4997 | pos += ret; |
| 4998 | } |
| 4999 | |
| 5000 | return pos - start; |
| 5001 | } |
| 5002 | #endif /* CONFIG_FILS */ |
| 5003 | |
| 5004 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5005 | static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 5006 | unsigned long mask, char *buf, size_t buflen) |
| 5007 | { |
| 5008 | size_t i; |
| 5009 | int ret; |
| 5010 | char *pos, *end; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5011 | const u8 *ie, *ie2, *osen_ie, *mesh, *owe, *rsnxe; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5012 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5013 | pos = buf; |
| 5014 | end = buf + buflen; |
| 5015 | |
| 5016 | if (mask & WPA_BSS_MASK_ID) { |
| 5017 | ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id); |
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 | } |
| 5022 | |
| 5023 | if (mask & WPA_BSS_MASK_BSSID) { |
| 5024 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", |
| 5025 | MAC2STR(bss->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5026 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5027 | return 0; |
| 5028 | pos += ret; |
| 5029 | } |
| 5030 | |
| 5031 | if (mask & WPA_BSS_MASK_FREQ) { |
| 5032 | ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5033 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5034 | return 0; |
| 5035 | pos += ret; |
| 5036 | } |
| 5037 | |
| 5038 | if (mask & WPA_BSS_MASK_BEACON_INT) { |
| 5039 | ret = os_snprintf(pos, end - pos, "beacon_int=%d\n", |
| 5040 | bss->beacon_int); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5041 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5042 | return 0; |
| 5043 | pos += ret; |
| 5044 | } |
| 5045 | |
| 5046 | if (mask & WPA_BSS_MASK_CAPABILITIES) { |
| 5047 | ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n", |
| 5048 | bss->caps); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5049 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5050 | return 0; |
| 5051 | pos += ret; |
| 5052 | } |
| 5053 | |
| 5054 | if (mask & WPA_BSS_MASK_QUAL) { |
| 5055 | ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5056 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5057 | return 0; |
| 5058 | pos += ret; |
| 5059 | } |
| 5060 | |
| 5061 | if (mask & WPA_BSS_MASK_NOISE) { |
| 5062 | ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5063 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5064 | return 0; |
| 5065 | pos += ret; |
| 5066 | } |
| 5067 | |
| 5068 | if (mask & WPA_BSS_MASK_LEVEL) { |
| 5069 | ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5070 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5071 | return 0; |
| 5072 | pos += ret; |
| 5073 | } |
| 5074 | |
| 5075 | if (mask & WPA_BSS_MASK_TSF) { |
| 5076 | ret = os_snprintf(pos, end - pos, "tsf=%016llu\n", |
| 5077 | (unsigned long long) bss->tsf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5078 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5079 | return 0; |
| 5080 | pos += ret; |
| 5081 | } |
| 5082 | |
| 5083 | if (mask & WPA_BSS_MASK_AGE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5084 | struct os_reltime now; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5085 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5086 | os_get_reltime(&now); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5087 | ret = os_snprintf(pos, end - pos, "age=%d\n", |
| 5088 | (int) (now.sec - bss->last_update.sec)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5089 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5090 | return 0; |
| 5091 | pos += ret; |
| 5092 | } |
| 5093 | |
| 5094 | if (mask & WPA_BSS_MASK_IE) { |
| 5095 | ret = os_snprintf(pos, end - pos, "ie="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5096 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5097 | return 0; |
| 5098 | pos += ret; |
| 5099 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5100 | ie = wpa_bss_ie_ptr(bss); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5101 | for (i = 0; i < bss->ie_len; i++) { |
| 5102 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5103 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5104 | return 0; |
| 5105 | pos += ret; |
| 5106 | } |
| 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 | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5110 | return 0; |
| 5111 | pos += ret; |
| 5112 | } |
| 5113 | |
| 5114 | if (mask & WPA_BSS_MASK_FLAGS) { |
| 5115 | ret = os_snprintf(pos, end - pos, "flags="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5116 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5117 | return 0; |
| 5118 | pos += ret; |
| 5119 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5120 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
| 5121 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5122 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 5123 | if (ie) |
| 5124 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, |
| 5125 | 2 + ie[1]); |
| 5126 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 5127 | if (ie2) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5128 | pos = wpa_supplicant_ie_txt(pos, end, |
| 5129 | mesh ? "RSN" : "WPA2", ie2, |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5130 | 2 + ie2[1]); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5131 | rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5132 | if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) { |
| 5133 | ret = os_snprintf(pos, end - pos, "[SAE-H2E]"); |
| 5134 | if (os_snprintf_error(end - pos, ret)) |
| 5135 | return -1; |
| 5136 | pos += ret; |
| 5137 | } |
| 5138 | if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) { |
| 5139 | ret = os_snprintf(pos, end - pos, "[SAE-PK]"); |
| 5140 | if (os_snprintf_error(end - pos, ret)) |
| 5141 | return -1; |
| 5142 | pos += ret; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5143 | } |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 5144 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
| 5145 | if (osen_ie) |
| 5146 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", |
| 5147 | osen_ie, 2 + osen_ie[1]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5148 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
| 5149 | if (owe) { |
| 5150 | ret = os_snprintf( |
| 5151 | pos, end - pos, |
| 5152 | ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]"); |
| 5153 | if (os_snprintf_error(end - pos, ret)) |
| 5154 | return 0; |
| 5155 | pos += ret; |
| 5156 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5157 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 5158 | if (!ie && !ie2 && !osen_ie && |
| 5159 | (bss->caps & IEEE80211_CAP_PRIVACY)) { |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5160 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5161 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5162 | return 0; |
| 5163 | pos += ret; |
| 5164 | } |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5165 | |
| 5166 | if (mesh) { |
| 5167 | ret = os_snprintf(pos, end - pos, "[MESH]"); |
| 5168 | if (os_snprintf_error(end - pos, ret)) |
| 5169 | return 0; |
| 5170 | pos += ret; |
| 5171 | } |
| 5172 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5173 | if (bss_is_dmg(bss)) { |
| 5174 | const char *s; |
| 5175 | ret = os_snprintf(pos, end - pos, "[DMG]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5176 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5177 | return 0; |
| 5178 | pos += ret; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5179 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
| 5180 | case IEEE80211_CAP_DMG_IBSS: |
| 5181 | s = "[IBSS]"; |
| 5182 | break; |
| 5183 | case IEEE80211_CAP_DMG_AP: |
| 5184 | s = "[ESS]"; |
| 5185 | break; |
| 5186 | case IEEE80211_CAP_DMG_PBSS: |
| 5187 | s = "[PBSS]"; |
| 5188 | break; |
| 5189 | default: |
| 5190 | s = ""; |
| 5191 | break; |
| 5192 | } |
| 5193 | ret = os_snprintf(pos, end - pos, "%s", s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5194 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5195 | return 0; |
| 5196 | pos += ret; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5197 | } else { |
| 5198 | if (bss->caps & IEEE80211_CAP_IBSS) { |
| 5199 | ret = os_snprintf(pos, end - pos, "[IBSS]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5200 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5201 | return 0; |
| 5202 | pos += ret; |
| 5203 | } |
| 5204 | if (bss->caps & IEEE80211_CAP_ESS) { |
| 5205 | ret = os_snprintf(pos, end - pos, "[ESS]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5206 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5207 | return 0; |
| 5208 | pos += ret; |
| 5209 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5210 | } |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 5211 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || |
| 5212 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5213 | ret = os_snprintf(pos, end - pos, "[P2P]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5214 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5215 | return 0; |
| 5216 | pos += ret; |
| 5217 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5218 | #ifdef CONFIG_HS20 |
| 5219 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) { |
| 5220 | ret = os_snprintf(pos, end - pos, "[HS20]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5221 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5222 | return 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5223 | pos += ret; |
| 5224 | } |
| 5225 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5226 | #ifdef CONFIG_FILS |
| 5227 | if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) { |
| 5228 | ret = os_snprintf(pos, end - pos, "[FILS]"); |
| 5229 | if (os_snprintf_error(end - pos, ret)) |
| 5230 | return 0; |
| 5231 | pos += ret; |
| 5232 | } |
| 5233 | #endif /* CONFIG_FILS */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5234 | #ifdef CONFIG_FST |
| 5235 | if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) { |
| 5236 | ret = os_snprintf(pos, end - pos, "[FST]"); |
| 5237 | if (os_snprintf_error(end - pos, ret)) |
| 5238 | return 0; |
| 5239 | pos += ret; |
| 5240 | } |
| 5241 | #endif /* CONFIG_FST */ |
| 5242 | if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) { |
| 5243 | ret = os_snprintf(pos, end - pos, "[UTF-8]"); |
| 5244 | if (os_snprintf_error(end - pos, ret)) |
| 5245 | return 0; |
| 5246 | pos += ret; |
| 5247 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5248 | |
| 5249 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5250 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5251 | return 0; |
| 5252 | pos += ret; |
| 5253 | } |
| 5254 | |
| 5255 | if (mask & WPA_BSS_MASK_SSID) { |
| 5256 | ret = os_snprintf(pos, end - pos, "ssid=%s\n", |
| 5257 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5258 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5259 | return 0; |
| 5260 | pos += ret; |
| 5261 | } |
| 5262 | |
| 5263 | #ifdef CONFIG_WPS |
| 5264 | if (mask & WPA_BSS_MASK_WPS_SCAN) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5265 | ie = wpa_bss_ie_ptr(bss); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5266 | ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5267 | if (ret >= end - pos) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5268 | return 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5269 | if (ret > 0) |
| 5270 | pos += ret; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5271 | } |
| 5272 | #endif /* CONFIG_WPS */ |
| 5273 | |
| 5274 | #ifdef CONFIG_P2P |
| 5275 | if (mask & WPA_BSS_MASK_P2P_SCAN) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5276 | ie = wpa_bss_ie_ptr(bss); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5277 | ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5278 | if (ret >= end - pos) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5279 | return 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5280 | if (ret > 0) |
| 5281 | pos += ret; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5282 | } |
| 5283 | #endif /* CONFIG_P2P */ |
| 5284 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5285 | #ifdef CONFIG_WIFI_DISPLAY |
| 5286 | if (mask & WPA_BSS_MASK_WIFI_DISPLAY) { |
| 5287 | struct wpabuf *wfd; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5288 | |
| 5289 | ie = wpa_bss_ie_ptr(bss); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5290 | wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len, |
| 5291 | WFD_IE_VENDOR_TYPE); |
| 5292 | if (wfd) { |
| 5293 | ret = os_snprintf(pos, end - pos, "wfd_subelems="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5294 | if (os_snprintf_error(end - pos, ret)) { |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5295 | wpabuf_free(wfd); |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5296 | return 0; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5297 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5298 | pos += ret; |
| 5299 | |
| 5300 | pos += wpa_snprintf_hex(pos, end - pos, |
| 5301 | wpabuf_head(wfd), |
| 5302 | wpabuf_len(wfd)); |
| 5303 | wpabuf_free(wfd); |
| 5304 | |
| 5305 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5306 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5307 | return 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5308 | pos += ret; |
| 5309 | } |
| 5310 | } |
| 5311 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 5312 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5313 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5314 | if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) { |
| 5315 | struct wpa_bss_anqp *anqp = bss->anqp; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5316 | struct wpa_bss_anqp_elem *elem; |
| 5317 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5318 | pos = anqp_add_hex(pos, end, "anqp_capability_list", |
| 5319 | anqp->capability_list); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5320 | pos = anqp_add_hex(pos, end, "anqp_venue_name", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5321 | anqp->venue_name); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5322 | pos = anqp_add_hex(pos, end, "anqp_network_auth_type", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5323 | anqp->network_auth_type); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5324 | pos = anqp_add_hex(pos, end, "anqp_roaming_consortium", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5325 | anqp->roaming_consortium); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5326 | pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5327 | anqp->ip_addr_type_availability); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5328 | pos = anqp_add_hex(pos, end, "anqp_nai_realm", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5329 | anqp->nai_realm); |
| 5330 | pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5331 | pos = anqp_add_hex(pos, end, "anqp_domain_name", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5332 | anqp->domain_name); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5333 | pos = anqp_add_hex(pos, end, "anqp_fils_realm_info", |
| 5334 | anqp->fils_realm_info); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5335 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5336 | pos = anqp_add_hex(pos, end, "hs20_capability_list", |
| 5337 | anqp->hs20_capability_list); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5338 | pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5339 | anqp->hs20_operator_friendly_name); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5340 | pos = anqp_add_hex(pos, end, "hs20_wan_metrics", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5341 | anqp->hs20_wan_metrics); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5342 | pos = anqp_add_hex(pos, end, "hs20_connection_capability", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5343 | anqp->hs20_connection_capability); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5344 | pos = anqp_add_hex(pos, end, "hs20_operating_class", |
| 5345 | anqp->hs20_operating_class); |
| 5346 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_list", |
| 5347 | anqp->hs20_osu_providers_list); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5348 | pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata", |
| 5349 | anqp->hs20_operator_icon_metadata); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 5350 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list", |
| 5351 | anqp->hs20_osu_providers_nai_list); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5352 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5353 | |
| 5354 | dl_list_for_each(elem, &anqp->anqp_elems, |
| 5355 | struct wpa_bss_anqp_elem, list) { |
| 5356 | char title[20]; |
| 5357 | |
| 5358 | os_snprintf(title, sizeof(title), "anqp[%u]", |
| 5359 | elem->infoid); |
| 5360 | pos = anqp_add_hex(pos, end, title, elem->payload); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5361 | if (elem->protected_response) { |
| 5362 | ret = os_snprintf(pos, end - pos, |
| 5363 | "protected-anqp-info[%u]=1\n", |
| 5364 | elem->infoid); |
| 5365 | if (os_snprintf_error(end - pos, ret)) |
| 5366 | return 0; |
| 5367 | pos += ret; |
| 5368 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5369 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5370 | } |
| 5371 | #endif /* CONFIG_INTERWORKING */ |
| 5372 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5373 | #ifdef CONFIG_MESH |
| 5374 | if (mask & WPA_BSS_MASK_MESH_SCAN) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5375 | ie = wpa_bss_ie_ptr(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5376 | ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5377 | if (ret >= end - pos) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5378 | return 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5379 | if (ret > 0) |
| 5380 | pos += ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5381 | } |
| 5382 | #endif /* CONFIG_MESH */ |
| 5383 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5384 | if (mask & WPA_BSS_MASK_SNR) { |
| 5385 | ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr); |
| 5386 | if (os_snprintf_error(end - pos, ret)) |
| 5387 | return 0; |
| 5388 | pos += ret; |
| 5389 | } |
| 5390 | |
| 5391 | if (mask & WPA_BSS_MASK_EST_THROUGHPUT) { |
| 5392 | ret = os_snprintf(pos, end - pos, "est_throughput=%d\n", |
| 5393 | bss->est_throughput); |
| 5394 | if (os_snprintf_error(end - pos, ret)) |
| 5395 | return 0; |
| 5396 | pos += ret; |
| 5397 | } |
| 5398 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5399 | #ifdef CONFIG_FST |
| 5400 | if (mask & WPA_BSS_MASK_FST) { |
| 5401 | ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos); |
| 5402 | if (ret < 0 || ret >= end - pos) |
| 5403 | return 0; |
| 5404 | pos += ret; |
| 5405 | } |
| 5406 | #endif /* CONFIG_FST */ |
| 5407 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5408 | if (mask & WPA_BSS_MASK_UPDATE_IDX) { |
| 5409 | ret = os_snprintf(pos, end - pos, "update_idx=%u\n", |
| 5410 | bss->last_update_idx); |
| 5411 | if (os_snprintf_error(end - pos, ret)) |
| 5412 | return 0; |
| 5413 | pos += ret; |
| 5414 | } |
| 5415 | |
| 5416 | if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) { |
| 5417 | ret = os_snprintf(pos, end - pos, "beacon_ie="); |
| 5418 | if (os_snprintf_error(end - pos, ret)) |
| 5419 | return 0; |
| 5420 | pos += ret; |
| 5421 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5422 | ie = wpa_bss_ie_ptr(bss); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5423 | ie += bss->ie_len; |
| 5424 | for (i = 0; i < bss->beacon_ie_len; i++) { |
| 5425 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); |
| 5426 | if (os_snprintf_error(end - pos, ret)) |
| 5427 | return 0; |
| 5428 | pos += ret; |
| 5429 | } |
| 5430 | |
| 5431 | ret = os_snprintf(pos, end - pos, "\n"); |
| 5432 | if (os_snprintf_error(end - pos, ret)) |
| 5433 | return 0; |
| 5434 | pos += ret; |
| 5435 | } |
| 5436 | |
| 5437 | #ifdef CONFIG_FILS |
| 5438 | if (mask & WPA_BSS_MASK_FILS_INDICATION) { |
| 5439 | ret = print_fils_indication(bss, pos, end); |
| 5440 | if (ret < 0) |
| 5441 | return 0; |
| 5442 | pos += ret; |
| 5443 | } |
| 5444 | #endif /* CONFIG_FILS */ |
| 5445 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 5446 | if (!is_zero_ether_addr(bss->mld_addr)) { |
| 5447 | ret = os_snprintf(pos, end - pos, |
| 5448 | "ap_mld_addr=" MACSTR "\n", |
| 5449 | MAC2STR(bss->mld_addr)); |
| 5450 | if (os_snprintf_error(end - pos, ret)) |
| 5451 | return 0; |
| 5452 | pos += ret; |
| 5453 | } |
| 5454 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5455 | if (mask & WPA_BSS_MASK_DELIM) { |
| 5456 | ret = os_snprintf(pos, end - pos, "====\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5457 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5458 | return 0; |
| 5459 | pos += ret; |
| 5460 | } |
Irfan Sheriff | e2ea008 | 2012-08-13 10:56:16 -0700 | [diff] [blame] | 5461 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5462 | return pos - buf; |
| 5463 | } |
| 5464 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5465 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5466 | static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s, |
| 5467 | const char *cmd, char *buf, |
| 5468 | size_t buflen) |
| 5469 | { |
| 5470 | u8 bssid[ETH_ALEN]; |
| 5471 | size_t i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5472 | struct wpa_bss *bss; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5473 | struct wpa_bss *bsslast = NULL; |
| 5474 | struct dl_list *next; |
| 5475 | int ret = 0; |
| 5476 | int len; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5477 | char *ctmp, *end = buf + buflen; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5478 | unsigned long mask = WPA_BSS_MASK_ALL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5479 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5480 | if (os_strncmp(cmd, "RANGE=", 6) == 0) { |
| 5481 | if (os_strncmp(cmd + 6, "ALL", 3) == 0) { |
| 5482 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5483 | list_id); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5484 | bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss, |
| 5485 | list_id); |
| 5486 | } else { /* N1-N2 */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5487 | unsigned int id1, id2; |
| 5488 | |
| 5489 | if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) { |
| 5490 | wpa_printf(MSG_INFO, "Wrong BSS range " |
| 5491 | "format"); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5492 | return 0; |
| 5493 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5494 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5495 | if (*(cmd + 6) == '-') |
| 5496 | id1 = 0; |
| 5497 | else |
| 5498 | id1 = atoi(cmd + 6); |
| 5499 | ctmp++; |
| 5500 | if (*ctmp >= '0' && *ctmp <= '9') |
| 5501 | id2 = atoi(ctmp); |
| 5502 | else |
| 5503 | id2 = (unsigned int) -1; |
| 5504 | bss = wpa_bss_get_id_range(wpa_s, id1, id2); |
| 5505 | if (id2 == (unsigned int) -1) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5506 | bsslast = dl_list_last(&wpa_s->bss_id, |
| 5507 | struct wpa_bss, |
| 5508 | list_id); |
| 5509 | else { |
| 5510 | bsslast = wpa_bss_get_id(wpa_s, id2); |
| 5511 | if (bsslast == NULL && bss && id2 > id1) { |
| 5512 | struct wpa_bss *tmp = bss; |
| 5513 | for (;;) { |
| 5514 | next = tmp->list_id.next; |
| 5515 | if (next == &wpa_s->bss_id) |
| 5516 | break; |
| 5517 | tmp = dl_list_entry( |
| 5518 | next, struct wpa_bss, |
| 5519 | list_id); |
| 5520 | if (tmp->id > id2) |
| 5521 | break; |
| 5522 | bsslast = tmp; |
| 5523 | } |
| 5524 | } |
| 5525 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5526 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5527 | } else if (os_strncmp(cmd, "FIRST", 5) == 0) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5528 | 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] | 5529 | else if (os_strncmp(cmd, "LAST", 4) == 0) |
| 5530 | 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] | 5531 | else if (os_strncmp(cmd, "ID-", 3) == 0) { |
| 5532 | i = atoi(cmd + 3); |
| 5533 | bss = wpa_bss_get_id(wpa_s, i); |
| 5534 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { |
| 5535 | i = atoi(cmd + 5); |
| 5536 | bss = wpa_bss_get_id(wpa_s, i); |
| 5537 | if (bss) { |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5538 | next = bss->list_id.next; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5539 | if (next == &wpa_s->bss_id) |
| 5540 | bss = NULL; |
| 5541 | else |
| 5542 | bss = dl_list_entry(next, struct wpa_bss, |
| 5543 | list_id); |
| 5544 | } |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5545 | } else if (os_strncmp(cmd, "CURRENT", 7) == 0) { |
| 5546 | bss = wpa_s->current_bss; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5547 | #ifdef CONFIG_P2P |
| 5548 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { |
| 5549 | if (hwaddr_aton(cmd + 13, bssid) == 0) |
| 5550 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid); |
| 5551 | else |
| 5552 | bss = NULL; |
| 5553 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5554 | } else if (hwaddr_aton(cmd, bssid) == 0) |
| 5555 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 5556 | else { |
| 5557 | struct wpa_bss *tmp; |
| 5558 | i = atoi(cmd); |
| 5559 | bss = NULL; |
| 5560 | dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id) |
| 5561 | { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5562 | if (i == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5563 | bss = tmp; |
| 5564 | break; |
| 5565 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5566 | i--; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5567 | } |
| 5568 | } |
| 5569 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5570 | if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) { |
| 5571 | mask = strtoul(ctmp + 5, NULL, 0x10); |
| 5572 | if (mask == 0) |
| 5573 | mask = WPA_BSS_MASK_ALL; |
| 5574 | } |
| 5575 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5576 | if (bss == NULL) |
| 5577 | return 0; |
| 5578 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5579 | if (bsslast == NULL) |
| 5580 | bsslast = bss; |
| 5581 | do { |
| 5582 | len = print_bss_info(wpa_s, bss, mask, buf, buflen); |
| 5583 | ret += len; |
| 5584 | buf += len; |
| 5585 | buflen -= len; |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5586 | if (bss == bsslast) { |
| 5587 | if ((mask & WPA_BSS_MASK_DELIM) && len && |
| 5588 | (bss == dl_list_last(&wpa_s->bss_id, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5589 | struct wpa_bss, list_id))) { |
| 5590 | int res; |
| 5591 | |
| 5592 | res = os_snprintf(buf - 5, end - buf + 5, |
| 5593 | "####\n"); |
| 5594 | if (os_snprintf_error(end - buf + 5, res)) { |
| 5595 | wpa_printf(MSG_DEBUG, |
| 5596 | "Could not add end delim"); |
| 5597 | } |
| 5598 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5599 | break; |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5600 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5601 | next = bss->list_id.next; |
| 5602 | if (next == &wpa_s->bss_id) |
| 5603 | break; |
| 5604 | bss = dl_list_entry(next, struct wpa_bss, list_id); |
| 5605 | } while (bss && len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5606 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5607 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | |
| 5611 | static int wpa_supplicant_ctrl_iface_ap_scan( |
| 5612 | struct wpa_supplicant *wpa_s, char *cmd) |
| 5613 | { |
| 5614 | int ap_scan = atoi(cmd); |
| 5615 | return wpa_supplicant_set_ap_scan(wpa_s, ap_scan); |
| 5616 | } |
| 5617 | |
| 5618 | |
| 5619 | static int wpa_supplicant_ctrl_iface_scan_interval( |
| 5620 | struct wpa_supplicant *wpa_s, char *cmd) |
| 5621 | { |
| 5622 | int scan_int = atoi(cmd); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5623 | return wpa_supplicant_set_scan_interval(wpa_s, scan_int); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5624 | } |
| 5625 | |
| 5626 | |
| 5627 | static int wpa_supplicant_ctrl_iface_bss_expire_age( |
| 5628 | struct wpa_supplicant *wpa_s, char *cmd) |
| 5629 | { |
| 5630 | int expire_age = atoi(cmd); |
| 5631 | return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age); |
| 5632 | } |
| 5633 | |
| 5634 | |
| 5635 | static int wpa_supplicant_ctrl_iface_bss_expire_count( |
| 5636 | struct wpa_supplicant *wpa_s, char *cmd) |
| 5637 | { |
| 5638 | int expire_count = atoi(cmd); |
| 5639 | return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count); |
| 5640 | } |
| 5641 | |
| 5642 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5643 | static void wpa_supplicant_ctrl_iface_bss_flush( |
Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 5644 | struct wpa_supplicant *wpa_s, char *cmd) |
| 5645 | { |
| 5646 | int flush_age = atoi(cmd); |
| 5647 | |
| 5648 | if (flush_age == 0) |
| 5649 | wpa_bss_flush(wpa_s); |
| 5650 | else |
| 5651 | wpa_bss_flush_by_age(wpa_s, flush_age); |
Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 5652 | } |
| 5653 | |
| 5654 | |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 5655 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5656 | static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s) |
| 5657 | { |
| 5658 | wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication"); |
| 5659 | /* MLME-DELETEKEYS.request */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5660 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, |
| 5661 | 0, KEY_FLAG_GROUP); |
| 5662 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, |
| 5663 | 0, KEY_FLAG_GROUP); |
| 5664 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, |
| 5665 | 0, KEY_FLAG_GROUP); |
| 5666 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, |
| 5667 | 0, KEY_FLAG_GROUP); |
| 5668 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, |
| 5669 | 0, KEY_FLAG_GROUP); |
| 5670 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, |
| 5671 | 0, KEY_FLAG_GROUP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5672 | |
| 5673 | 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] | 5674 | 0, KEY_FLAG_PAIRWISE); |
| 5675 | if (wpa_sm_ext_key_id(wpa_s->wpa)) |
| 5676 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 1, 0, |
| 5677 | NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5678 | /* MLME-SETPROTECTION.request(None) */ |
| 5679 | wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid, |
| 5680 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, |
| 5681 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); |
| 5682 | wpa_sm_drop_sa(wpa_s->wpa); |
| 5683 | } |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 5684 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5685 | |
| 5686 | |
| 5687 | static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s, |
| 5688 | char *addr) |
| 5689 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5690 | #ifdef CONFIG_NO_SCAN_PROCESSING |
| 5691 | return -1; |
| 5692 | #else /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5693 | u8 bssid[ETH_ALEN]; |
| 5694 | struct wpa_bss *bss; |
| 5695 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5696 | struct wpa_radio_work *already_connecting; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5697 | |
| 5698 | if (hwaddr_aton(addr, bssid)) { |
| 5699 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid " |
| 5700 | "address '%s'", addr); |
| 5701 | return -1; |
| 5702 | } |
| 5703 | |
| 5704 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid)); |
| 5705 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5706 | if (!ssid) { |
| 5707 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network " |
| 5708 | "configuration known for the target AP"); |
| 5709 | return -1; |
| 5710 | } |
| 5711 | |
| 5712 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5713 | if (!bss) { |
| 5714 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found " |
| 5715 | "from BSS table"); |
| 5716 | return -1; |
| 5717 | } |
| 5718 | |
| 5719 | /* |
| 5720 | * TODO: Find best network configuration block from configuration to |
| 5721 | * allow roaming to other networks |
| 5722 | */ |
| 5723 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5724 | already_connecting = radio_work_pending(wpa_s, "sme-connect"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5725 | wpa_s->reassociate = 1; |
| 5726 | wpa_supplicant_connect(wpa_s, bss, ssid); |
| 5727 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5728 | /* |
| 5729 | * Indicate that an explicitly requested roam is in progress so scan |
| 5730 | * results that come in before the 'sme-connect' radio work gets |
| 5731 | * executed do not override the original connection attempt. |
| 5732 | */ |
| 5733 | if (!already_connecting && radio_work_pending(wpa_s, "sme-connect")) |
| 5734 | wpa_s->roam_in_progress = true; |
| 5735 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5736 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5737 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5738 | } |
| 5739 | |
| 5740 | |
| 5741 | #ifdef CONFIG_P2P |
| 5742 | static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd) |
| 5743 | { |
| 5744 | unsigned int timeout = atoi(cmd); |
| 5745 | enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5746 | u8 dev_id[ETH_ALEN], *_dev_id = NULL; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5747 | u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5748 | char *pos; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5749 | unsigned int search_delay; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5750 | const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5751 | u8 seek_count = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5752 | int freq = 0; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5753 | bool include_6ghz = false; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5754 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 5755 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 5756 | wpa_dbg(wpa_s, MSG_INFO, |
| 5757 | "Reject P2P_FIND since interface is disabled"); |
| 5758 | return -1; |
| 5759 | } |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5760 | |
| 5761 | if (os_strstr(cmd, " include_6ghz")) |
| 5762 | include_6ghz = true; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5763 | if (os_strstr(cmd, "type=social")) |
| 5764 | type = P2P_FIND_ONLY_SOCIAL; |
| 5765 | else if (os_strstr(cmd, "type=progressive")) |
| 5766 | type = P2P_FIND_PROGRESSIVE; |
| 5767 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5768 | pos = os_strstr(cmd, "dev_id="); |
| 5769 | if (pos) { |
| 5770 | pos += 7; |
| 5771 | if (hwaddr_aton(pos, dev_id)) |
| 5772 | return -1; |
| 5773 | _dev_id = dev_id; |
| 5774 | } |
| 5775 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5776 | pos = os_strstr(cmd, "dev_type="); |
| 5777 | if (pos) { |
| 5778 | pos += 9; |
| 5779 | if (wps_dev_type_str2bin(pos, dev_type) < 0) |
| 5780 | return -1; |
| 5781 | _dev_type = dev_type; |
| 5782 | } |
| 5783 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5784 | pos = os_strstr(cmd, "delay="); |
| 5785 | if (pos) { |
| 5786 | pos += 6; |
| 5787 | search_delay = atoi(pos); |
| 5788 | } else |
| 5789 | search_delay = wpas_p2p_search_delay(wpa_s); |
| 5790 | |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 5791 | pos = os_strstr(cmd, "freq="); |
| 5792 | if (pos) { |
| 5793 | pos += 5; |
| 5794 | freq = atoi(pos); |
| 5795 | if (freq <= 0) |
| 5796 | return -1; |
| 5797 | } |
| 5798 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5799 | /* Must be searched for last, because it adds nul termination */ |
| 5800 | pos = os_strstr(cmd, " seek="); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5801 | if (pos) |
| 5802 | pos += 6; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5803 | while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) { |
| 5804 | char *term; |
| 5805 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5806 | _seek[seek_count++] = pos; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5807 | seek = _seek; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5808 | term = os_strchr(pos, ' '); |
| 5809 | if (!term) |
| 5810 | break; |
| 5811 | *term = '\0'; |
| 5812 | pos = os_strstr(term + 1, "seek="); |
| 5813 | if (pos) |
| 5814 | pos += 5; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5815 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5816 | if (seek_count > P2P_MAX_QUERY_HASH) { |
| 5817 | seek[0] = NULL; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5818 | seek_count = 1; |
| 5819 | } |
| 5820 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5821 | return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5822 | _dev_id, search_delay, seek_count, seek, freq, |
| 5823 | include_6ghz); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5824 | } |
| 5825 | |
| 5826 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5827 | static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt) |
| 5828 | { |
| 5829 | const char *last = NULL; |
| 5830 | const char *token; |
| 5831 | long int token_len; |
| 5832 | unsigned int i; |
| 5833 | |
| 5834 | /* Expected predefined CPT names delimited by ':' */ |
| 5835 | for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) { |
| 5836 | if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) { |
| 5837 | wpa_printf(MSG_ERROR, |
| 5838 | "P2PS: CPT name list is too long, expected up to %d names", |
| 5839 | P2PS_FEATURE_CAPAB_CPT_MAX); |
| 5840 | cpt[0] = 0; |
| 5841 | return -1; |
| 5842 | } |
| 5843 | |
| 5844 | token_len = last - token; |
| 5845 | |
| 5846 | if (token_len == 3 && |
| 5847 | os_memcmp(token, "UDP", token_len) == 0) { |
| 5848 | cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; |
| 5849 | } else if (token_len == 3 && |
| 5850 | os_memcmp(token, "MAC", token_len) == 0) { |
| 5851 | cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT; |
| 5852 | } else { |
| 5853 | wpa_printf(MSG_ERROR, |
| 5854 | "P2PS: Unsupported CPT name '%s'", token); |
| 5855 | cpt[0] = 0; |
| 5856 | return -1; |
| 5857 | } |
| 5858 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5859 | if (isblank((unsigned char) *last)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5860 | i++; |
| 5861 | break; |
| 5862 | } |
| 5863 | } |
| 5864 | cpt[i] = 0; |
| 5865 | return 0; |
| 5866 | } |
| 5867 | |
| 5868 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5869 | static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd) |
| 5870 | { |
| 5871 | struct p2ps_provision *p2ps_prov; |
| 5872 | char *pos; |
| 5873 | size_t info_len = 0; |
| 5874 | char *info = NULL; |
| 5875 | u8 role = P2PS_SETUP_NONE; |
| 5876 | long long unsigned val; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5877 | int i; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5878 | |
| 5879 | pos = os_strstr(cmd, "info="); |
| 5880 | if (pos) { |
| 5881 | pos += 5; |
| 5882 | info_len = os_strlen(pos); |
| 5883 | |
| 5884 | if (info_len) { |
| 5885 | info = os_malloc(info_len + 1); |
| 5886 | if (info) { |
| 5887 | info_len = utf8_unescape(pos, info_len, |
| 5888 | info, info_len + 1); |
| 5889 | } else |
| 5890 | info_len = 0; |
| 5891 | } |
| 5892 | } |
| 5893 | |
| 5894 | p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1); |
| 5895 | if (p2ps_prov == NULL) { |
| 5896 | os_free(info); |
| 5897 | return NULL; |
| 5898 | } |
| 5899 | |
| 5900 | if (info) { |
| 5901 | os_memcpy(p2ps_prov->info, info, info_len); |
| 5902 | p2ps_prov->info[info_len] = '\0'; |
| 5903 | os_free(info); |
| 5904 | } |
| 5905 | |
| 5906 | pos = os_strstr(cmd, "status="); |
| 5907 | if (pos) |
| 5908 | p2ps_prov->status = atoi(pos + 7); |
| 5909 | else |
| 5910 | p2ps_prov->status = -1; |
| 5911 | |
| 5912 | pos = os_strstr(cmd, "adv_id="); |
| 5913 | if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL) |
| 5914 | goto invalid_args; |
| 5915 | p2ps_prov->adv_id = val; |
| 5916 | |
| 5917 | pos = os_strstr(cmd, "method="); |
| 5918 | if (pos) |
| 5919 | p2ps_prov->method = strtol(pos + 7, NULL, 16); |
| 5920 | else |
| 5921 | p2ps_prov->method = 0; |
| 5922 | |
| 5923 | pos = os_strstr(cmd, "session="); |
| 5924 | if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL) |
| 5925 | goto invalid_args; |
| 5926 | p2ps_prov->session_id = val; |
| 5927 | |
| 5928 | pos = os_strstr(cmd, "adv_mac="); |
| 5929 | if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac)) |
| 5930 | goto invalid_args; |
| 5931 | |
| 5932 | pos = os_strstr(cmd, "session_mac="); |
| 5933 | if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac)) |
| 5934 | goto invalid_args; |
| 5935 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5936 | pos = os_strstr(cmd, "cpt="); |
| 5937 | if (pos) { |
| 5938 | if (p2ps_ctrl_parse_cpt_priority(pos + 4, |
| 5939 | p2ps_prov->cpt_priority)) |
| 5940 | goto invalid_args; |
| 5941 | } else { |
| 5942 | p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; |
| 5943 | } |
| 5944 | |
| 5945 | for (i = 0; p2ps_prov->cpt_priority[i]; i++) |
| 5946 | p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i]; |
| 5947 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5948 | /* force conncap with tstCap (no validity checks) */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5949 | pos = os_strstr(cmd, "tstCap="); |
| 5950 | if (pos) { |
| 5951 | role = strtol(pos + 7, NULL, 16); |
| 5952 | } else { |
| 5953 | pos = os_strstr(cmd, "role="); |
| 5954 | if (pos) { |
| 5955 | role = strtol(pos + 5, NULL, 16); |
| 5956 | if (role != P2PS_SETUP_CLIENT && |
| 5957 | role != P2PS_SETUP_GROUP_OWNER) |
| 5958 | role = P2PS_SETUP_NONE; |
| 5959 | } |
| 5960 | } |
| 5961 | p2ps_prov->role = role; |
| 5962 | |
| 5963 | return p2ps_prov; |
| 5964 | |
| 5965 | invalid_args: |
| 5966 | os_free(p2ps_prov); |
| 5967 | return NULL; |
| 5968 | } |
| 5969 | |
| 5970 | |
| 5971 | static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd) |
| 5972 | { |
| 5973 | u8 addr[ETH_ALEN]; |
| 5974 | struct p2ps_provision *p2ps_prov; |
| 5975 | char *pos; |
| 5976 | |
| 5977 | /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */ |
| 5978 | |
| 5979 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); |
| 5980 | |
| 5981 | if (hwaddr_aton(cmd, addr)) |
| 5982 | return -1; |
| 5983 | |
| 5984 | pos = cmd + 17; |
| 5985 | if (*pos != ' ') |
| 5986 | return -1; |
| 5987 | |
| 5988 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); |
| 5989 | if (!p2ps_prov) |
| 5990 | return -1; |
| 5991 | |
| 5992 | if (p2ps_prov->status < 0) { |
| 5993 | os_free(p2ps_prov); |
| 5994 | return -1; |
| 5995 | } |
| 5996 | |
| 5997 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, |
| 5998 | p2ps_prov); |
| 5999 | } |
| 6000 | |
| 6001 | |
| 6002 | static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd) |
| 6003 | { |
| 6004 | u8 addr[ETH_ALEN]; |
| 6005 | struct p2ps_provision *p2ps_prov; |
| 6006 | char *pos; |
| 6007 | |
| 6008 | /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap> |
| 6009 | * session=<ses_id> mac=<ses_mac> [info=<infodata>] |
| 6010 | */ |
| 6011 | |
| 6012 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); |
| 6013 | if (hwaddr_aton(cmd, addr)) |
| 6014 | return -1; |
| 6015 | |
| 6016 | pos = cmd + 17; |
| 6017 | if (*pos != ' ') |
| 6018 | return -1; |
| 6019 | |
| 6020 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); |
| 6021 | if (!p2ps_prov) |
| 6022 | return -1; |
| 6023 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6024 | p2ps_prov->pd_seeker = 1; |
| 6025 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6026 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, |
| 6027 | p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6028 | } |
| 6029 | |
| 6030 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6031 | static int parse_freq(int chwidth, int freq2) |
| 6032 | { |
| 6033 | if (freq2 < 0) |
| 6034 | return -1; |
| 6035 | if (freq2) |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6036 | return CONF_OPER_CHWIDTH_80P80MHZ; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6037 | |
| 6038 | switch (chwidth) { |
| 6039 | case 0: |
| 6040 | case 20: |
| 6041 | case 40: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6042 | return CONF_OPER_CHWIDTH_USE_HT; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6043 | case 80: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6044 | return CONF_OPER_CHWIDTH_80MHZ; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6045 | case 160: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6046 | return CONF_OPER_CHWIDTH_160MHZ; |
| 6047 | case 320: |
| 6048 | return CONF_OPER_CHWIDTH_320MHZ; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6049 | default: |
| 6050 | wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d", |
| 6051 | chwidth); |
| 6052 | return -1; |
| 6053 | } |
| 6054 | } |
| 6055 | |
| 6056 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6057 | static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd, |
| 6058 | char *buf, size_t buflen) |
| 6059 | { |
| 6060 | u8 addr[ETH_ALEN]; |
| 6061 | char *pos, *pos2; |
| 6062 | char *pin = NULL; |
| 6063 | enum p2p_wps_method wps_method; |
| 6064 | int new_pin; |
| 6065 | int ret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6066 | int persistent_group, persistent_id = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6067 | int join; |
| 6068 | int auth; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6069 | int automatic; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6070 | int go_intent = -1; |
| 6071 | int freq = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6072 | int pd; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6073 | int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6074 | int edmg; |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6075 | u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL; |
| 6076 | size_t group_ssid_len = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6077 | int he; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6078 | bool allow_6ghz; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6079 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6080 | if (!wpa_s->global->p2p_init_wpa_s) |
| 6081 | return -1; |
| 6082 | if (wpa_s->global->p2p_init_wpa_s != wpa_s) { |
| 6083 | wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s", |
| 6084 | wpa_s->global->p2p_init_wpa_s->ifname); |
| 6085 | wpa_s = wpa_s->global->p2p_init_wpa_s; |
| 6086 | } |
| 6087 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6088 | /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps] |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6089 | * [persistent|persistent=<network id>] |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6090 | * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6091 | * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6092 | |
| 6093 | if (hwaddr_aton(cmd, addr)) |
| 6094 | return -1; |
| 6095 | |
| 6096 | pos = cmd + 17; |
| 6097 | if (*pos != ' ') |
| 6098 | return -1; |
| 6099 | pos++; |
| 6100 | |
| 6101 | persistent_group = os_strstr(pos, " persistent") != NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6102 | pos2 = os_strstr(pos, " persistent="); |
| 6103 | if (pos2) { |
| 6104 | struct wpa_ssid *ssid; |
| 6105 | persistent_id = atoi(pos2 + 12); |
| 6106 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); |
| 6107 | if (ssid == NULL || ssid->disabled != 2 || |
| 6108 | ssid->mode != WPAS_MODE_P2P_GO) { |
| 6109 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 6110 | "SSID id=%d for persistent P2P group (GO)", |
| 6111 | persistent_id); |
| 6112 | return -1; |
| 6113 | } |
| 6114 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6115 | join = os_strstr(pos, " join") != NULL; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6116 | allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6117 | auth = os_strstr(pos, " auth") != NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6118 | automatic = os_strstr(pos, " auto") != NULL; |
| 6119 | pd = os_strstr(pos, " provdisc") != NULL; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6120 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
| 6121 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || |
| 6122 | vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6123 | he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6124 | edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6125 | |
| 6126 | pos2 = os_strstr(pos, " go_intent="); |
| 6127 | if (pos2) { |
| 6128 | pos2 += 11; |
| 6129 | go_intent = atoi(pos2); |
| 6130 | if (go_intent < 0 || go_intent > 15) |
| 6131 | return -1; |
| 6132 | } |
| 6133 | |
| 6134 | pos2 = os_strstr(pos, " freq="); |
| 6135 | if (pos2) { |
| 6136 | pos2 += 6; |
| 6137 | freq = atoi(pos2); |
| 6138 | if (freq <= 0) |
| 6139 | return -1; |
| 6140 | } |
| 6141 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6142 | pos2 = os_strstr(pos, " freq2="); |
| 6143 | if (pos2) |
| 6144 | freq2 = atoi(pos2 + 7); |
| 6145 | |
| 6146 | pos2 = os_strstr(pos, " max_oper_chwidth="); |
| 6147 | if (pos2) |
| 6148 | chwidth = atoi(pos2 + 18); |
| 6149 | |
| 6150 | max_oper_chwidth = parse_freq(chwidth, freq2); |
| 6151 | if (max_oper_chwidth < 0) |
| 6152 | return -1; |
| 6153 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6154 | if (allow_6ghz && chwidth == 40) |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6155 | max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6156 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6157 | pos2 = os_strstr(pos, " ssid="); |
| 6158 | if (pos2) { |
| 6159 | char *end; |
| 6160 | |
| 6161 | pos2 += 6; |
| 6162 | end = os_strchr(pos2, ' '); |
| 6163 | if (!end) |
| 6164 | group_ssid_len = os_strlen(pos2) / 2; |
| 6165 | else |
| 6166 | group_ssid_len = (end - pos2) / 2; |
| 6167 | if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN || |
| 6168 | hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0) |
| 6169 | return -1; |
| 6170 | group_ssid = _group_ssid; |
| 6171 | } |
| 6172 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6173 | if (os_strncmp(pos, "pin", 3) == 0) { |
| 6174 | /* Request random PIN (to be displayed) and enable the PIN */ |
| 6175 | wps_method = WPS_PIN_DISPLAY; |
| 6176 | } else if (os_strncmp(pos, "pbc", 3) == 0) { |
| 6177 | wps_method = WPS_PBC; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6178 | } else if (os_strstr(pos, "p2ps") != NULL) { |
| 6179 | wps_method = WPS_P2PS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6180 | } else { |
| 6181 | pin = pos; |
| 6182 | pos = os_strchr(pin, ' '); |
| 6183 | wps_method = WPS_PIN_KEYPAD; |
| 6184 | if (pos) { |
| 6185 | *pos++ = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6186 | if (os_strncmp(pos, "display", 7) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6187 | wps_method = WPS_PIN_DISPLAY; |
| 6188 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6189 | if (!wps_pin_str_valid(pin)) { |
| 6190 | os_memcpy(buf, "FAIL-INVALID-PIN\n", 17); |
| 6191 | return 17; |
| 6192 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6193 | } |
| 6194 | |
| 6195 | new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6196 | persistent_group, automatic, join, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6197 | auth, go_intent, freq, freq2, persistent_id, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6198 | pd, ht40, vht, max_oper_chwidth, he, edmg, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6199 | group_ssid, group_ssid_len, allow_6ghz); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6200 | if (new_pin == -2) { |
| 6201 | os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25); |
| 6202 | return 25; |
| 6203 | } |
| 6204 | if (new_pin == -3) { |
| 6205 | os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25); |
| 6206 | return 25; |
| 6207 | } |
| 6208 | if (new_pin < 0) |
| 6209 | return -1; |
| 6210 | if (wps_method == WPS_PIN_DISPLAY && pin == NULL) { |
| 6211 | ret = os_snprintf(buf, buflen, "%08d", new_pin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6212 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6213 | return -1; |
| 6214 | return ret; |
| 6215 | } |
| 6216 | |
| 6217 | os_memcpy(buf, "OK\n", 3); |
| 6218 | return 3; |
| 6219 | } |
| 6220 | |
| 6221 | |
| 6222 | static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd) |
| 6223 | { |
| 6224 | unsigned int timeout = atoi(cmd); |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 6225 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 6226 | wpa_dbg(wpa_s, MSG_INFO, |
| 6227 | "Reject P2P_LISTEN since interface is disabled"); |
| 6228 | return -1; |
| 6229 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6230 | return wpas_p2p_listen(wpa_s, timeout); |
| 6231 | } |
| 6232 | |
| 6233 | |
| 6234 | static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) |
| 6235 | { |
| 6236 | u8 addr[ETH_ALEN]; |
| 6237 | char *pos; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6238 | 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] | 6239 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6240 | /* <addr> <config method> [join|auto] */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6241 | |
| 6242 | if (hwaddr_aton(cmd, addr)) |
| 6243 | return -1; |
| 6244 | |
| 6245 | pos = cmd + 17; |
| 6246 | if (*pos != ' ') |
| 6247 | return -1; |
| 6248 | pos++; |
| 6249 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6250 | if (os_strstr(pos, " join") != NULL) |
| 6251 | use = WPAS_P2P_PD_FOR_JOIN; |
| 6252 | else if (os_strstr(pos, " auto") != NULL) |
| 6253 | use = WPAS_P2P_PD_AUTO; |
| 6254 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6255 | return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6256 | } |
| 6257 | |
| 6258 | |
| 6259 | static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf, |
| 6260 | size_t buflen) |
| 6261 | { |
| 6262 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 6263 | |
| 6264 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 6265 | ssid->passphrase == NULL) |
| 6266 | return -1; |
| 6267 | |
| 6268 | os_strlcpy(buf, ssid->passphrase, buflen); |
| 6269 | return os_strlen(buf); |
| 6270 | } |
| 6271 | |
| 6272 | |
| 6273 | static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd, |
| 6274 | char *buf, size_t buflen) |
| 6275 | { |
| 6276 | u64 ref; |
| 6277 | int res; |
| 6278 | u8 dst_buf[ETH_ALEN], *dst; |
| 6279 | struct wpabuf *tlvs; |
| 6280 | char *pos; |
| 6281 | size_t len; |
| 6282 | |
| 6283 | if (hwaddr_aton(cmd, dst_buf)) |
| 6284 | return -1; |
| 6285 | dst = dst_buf; |
| 6286 | if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 && |
| 6287 | dst[3] == 0 && dst[4] == 0 && dst[5] == 0) |
| 6288 | dst = NULL; |
| 6289 | pos = cmd + 17; |
| 6290 | if (*pos != ' ') |
| 6291 | return -1; |
| 6292 | pos++; |
| 6293 | |
| 6294 | if (os_strncmp(pos, "upnp ", 5) == 0) { |
| 6295 | u8 version; |
| 6296 | pos += 5; |
| 6297 | if (hexstr2bin(pos, &version, 1) < 0) |
| 6298 | return -1; |
| 6299 | pos += 2; |
| 6300 | if (*pos != ' ') |
| 6301 | return -1; |
| 6302 | pos++; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6303 | ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6304 | #ifdef CONFIG_WIFI_DISPLAY |
| 6305 | } else if (os_strncmp(pos, "wifi-display ", 13) == 0) { |
| 6306 | ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13); |
| 6307 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6308 | } else if (os_strncmp(pos, "asp ", 4) == 0) { |
| 6309 | char *svc_str; |
| 6310 | char *svc_info = NULL; |
| 6311 | u32 id; |
| 6312 | |
| 6313 | pos += 4; |
| 6314 | if (sscanf(pos, "%x", &id) != 1 || id > 0xff) |
| 6315 | return -1; |
| 6316 | |
| 6317 | pos = os_strchr(pos, ' '); |
| 6318 | if (pos == NULL || pos[1] == '\0' || pos[1] == ' ') |
| 6319 | return -1; |
| 6320 | |
| 6321 | svc_str = pos + 1; |
| 6322 | |
| 6323 | pos = os_strchr(svc_str, ' '); |
| 6324 | |
| 6325 | if (pos) |
| 6326 | *pos++ = '\0'; |
| 6327 | |
| 6328 | /* All remaining data is the svc_info string */ |
| 6329 | if (pos && pos[0] && pos[0] != ' ') { |
| 6330 | len = os_strlen(pos); |
| 6331 | |
| 6332 | /* Unescape in place */ |
| 6333 | len = utf8_unescape(pos, len, pos, len); |
| 6334 | if (len > 0xff) |
| 6335 | return -1; |
| 6336 | |
| 6337 | svc_info = pos; |
| 6338 | } |
| 6339 | |
| 6340 | ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id, |
| 6341 | svc_str, svc_info); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6342 | } else { |
| 6343 | len = os_strlen(pos); |
| 6344 | if (len & 1) |
| 6345 | return -1; |
| 6346 | len /= 2; |
| 6347 | tlvs = wpabuf_alloc(len); |
| 6348 | if (tlvs == NULL) |
| 6349 | return -1; |
| 6350 | if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) { |
| 6351 | wpabuf_free(tlvs); |
| 6352 | return -1; |
| 6353 | } |
| 6354 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6355 | ref = wpas_p2p_sd_request(wpa_s, dst, tlvs); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6356 | wpabuf_free(tlvs); |
| 6357 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6358 | if (ref == 0) |
| 6359 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6360 | res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6361 | if (os_snprintf_error(buflen, res)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6362 | return -1; |
| 6363 | return res; |
| 6364 | } |
| 6365 | |
| 6366 | |
| 6367 | static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s, |
| 6368 | char *cmd) |
| 6369 | { |
| 6370 | long long unsigned val; |
| 6371 | u64 req; |
| 6372 | if (sscanf(cmd, "%llx", &val) != 1) |
| 6373 | return -1; |
| 6374 | req = val; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6375 | return wpas_p2p_sd_cancel_request(wpa_s, req); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6376 | } |
| 6377 | |
| 6378 | |
| 6379 | static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd) |
| 6380 | { |
| 6381 | int freq; |
| 6382 | u8 dst[ETH_ALEN]; |
| 6383 | u8 dialog_token; |
| 6384 | struct wpabuf *resp_tlvs; |
| 6385 | char *pos, *pos2; |
| 6386 | size_t len; |
| 6387 | |
| 6388 | pos = os_strchr(cmd, ' '); |
| 6389 | if (pos == NULL) |
| 6390 | return -1; |
| 6391 | *pos++ = '\0'; |
| 6392 | freq = atoi(cmd); |
| 6393 | if (freq == 0) |
| 6394 | return -1; |
| 6395 | |
| 6396 | if (hwaddr_aton(pos, dst)) |
| 6397 | return -1; |
| 6398 | pos += 17; |
| 6399 | if (*pos != ' ') |
| 6400 | return -1; |
| 6401 | pos++; |
| 6402 | |
| 6403 | pos2 = os_strchr(pos, ' '); |
| 6404 | if (pos2 == NULL) |
| 6405 | return -1; |
| 6406 | *pos2++ = '\0'; |
| 6407 | dialog_token = atoi(pos); |
| 6408 | |
| 6409 | len = os_strlen(pos2); |
| 6410 | if (len & 1) |
| 6411 | return -1; |
| 6412 | len /= 2; |
| 6413 | resp_tlvs = wpabuf_alloc(len); |
| 6414 | if (resp_tlvs == NULL) |
| 6415 | return -1; |
| 6416 | if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) { |
| 6417 | wpabuf_free(resp_tlvs); |
| 6418 | return -1; |
| 6419 | } |
| 6420 | |
| 6421 | wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs); |
| 6422 | wpabuf_free(resp_tlvs); |
| 6423 | return 0; |
| 6424 | } |
| 6425 | |
| 6426 | |
| 6427 | static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s, |
| 6428 | char *cmd) |
| 6429 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6430 | if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1")) |
| 6431 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6432 | wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd); |
| 6433 | return 0; |
| 6434 | } |
| 6435 | |
| 6436 | |
| 6437 | static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s, |
| 6438 | char *cmd) |
| 6439 | { |
| 6440 | char *pos; |
| 6441 | size_t len; |
| 6442 | struct wpabuf *query, *resp; |
| 6443 | |
| 6444 | pos = os_strchr(cmd, ' '); |
| 6445 | if (pos == NULL) |
| 6446 | return -1; |
| 6447 | *pos++ = '\0'; |
| 6448 | |
| 6449 | len = os_strlen(cmd); |
| 6450 | if (len & 1) |
| 6451 | return -1; |
| 6452 | len /= 2; |
| 6453 | query = wpabuf_alloc(len); |
| 6454 | if (query == NULL) |
| 6455 | return -1; |
| 6456 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { |
| 6457 | wpabuf_free(query); |
| 6458 | return -1; |
| 6459 | } |
| 6460 | |
| 6461 | len = os_strlen(pos); |
| 6462 | if (len & 1) { |
| 6463 | wpabuf_free(query); |
| 6464 | return -1; |
| 6465 | } |
| 6466 | len /= 2; |
| 6467 | resp = wpabuf_alloc(len); |
| 6468 | if (resp == NULL) { |
| 6469 | wpabuf_free(query); |
| 6470 | return -1; |
| 6471 | } |
| 6472 | if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) { |
| 6473 | wpabuf_free(query); |
| 6474 | wpabuf_free(resp); |
| 6475 | return -1; |
| 6476 | } |
| 6477 | |
| 6478 | if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) { |
| 6479 | wpabuf_free(query); |
| 6480 | wpabuf_free(resp); |
| 6481 | return -1; |
| 6482 | } |
| 6483 | return 0; |
| 6484 | } |
| 6485 | |
| 6486 | |
| 6487 | static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd) |
| 6488 | { |
| 6489 | char *pos; |
| 6490 | u8 version; |
| 6491 | |
| 6492 | pos = os_strchr(cmd, ' '); |
| 6493 | if (pos == NULL) |
| 6494 | return -1; |
| 6495 | *pos++ = '\0'; |
| 6496 | |
| 6497 | if (hexstr2bin(cmd, &version, 1) < 0) |
| 6498 | return -1; |
| 6499 | |
| 6500 | return wpas_p2p_service_add_upnp(wpa_s, version, pos); |
| 6501 | } |
| 6502 | |
| 6503 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6504 | static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s, |
| 6505 | u8 replace, char *cmd) |
| 6506 | { |
| 6507 | char *pos; |
| 6508 | char *adv_str; |
| 6509 | u32 auto_accept, adv_id, svc_state, config_methods; |
| 6510 | char *svc_info = NULL; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6511 | char *cpt_prio_str; |
| 6512 | u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1]; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6513 | |
| 6514 | pos = os_strchr(cmd, ' '); |
| 6515 | if (pos == NULL) |
| 6516 | return -1; |
| 6517 | *pos++ = '\0'; |
| 6518 | |
| 6519 | /* Auto-Accept value is mandatory, and must be one of the |
| 6520 | * single values (0, 1, 2, 4) */ |
| 6521 | auto_accept = atoi(cmd); |
| 6522 | switch (auto_accept) { |
| 6523 | case P2PS_SETUP_NONE: /* No auto-accept */ |
| 6524 | case P2PS_SETUP_NEW: |
| 6525 | case P2PS_SETUP_CLIENT: |
| 6526 | case P2PS_SETUP_GROUP_OWNER: |
| 6527 | break; |
| 6528 | default: |
| 6529 | return -1; |
| 6530 | } |
| 6531 | |
| 6532 | /* Advertisement ID is mandatory */ |
| 6533 | cmd = pos; |
| 6534 | pos = os_strchr(cmd, ' '); |
| 6535 | if (pos == NULL) |
| 6536 | return -1; |
| 6537 | *pos++ = '\0'; |
| 6538 | |
| 6539 | /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */ |
| 6540 | if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0) |
| 6541 | return -1; |
| 6542 | |
| 6543 | /* Only allow replacements if exist, and adds if not */ |
| 6544 | if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) { |
| 6545 | if (!replace) |
| 6546 | return -1; |
| 6547 | } else { |
| 6548 | if (replace) |
| 6549 | return -1; |
| 6550 | } |
| 6551 | |
| 6552 | /* svc_state between 0 - 0xff is mandatory */ |
| 6553 | if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff) |
| 6554 | return -1; |
| 6555 | |
| 6556 | pos = os_strchr(pos, ' '); |
| 6557 | if (pos == NULL) |
| 6558 | return -1; |
| 6559 | |
| 6560 | /* config_methods is mandatory */ |
| 6561 | pos++; |
| 6562 | if (sscanf(pos, "%x", &config_methods) != 1) |
| 6563 | return -1; |
| 6564 | |
| 6565 | if (!(config_methods & |
| 6566 | (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS))) |
| 6567 | return -1; |
| 6568 | |
| 6569 | pos = os_strchr(pos, ' '); |
| 6570 | if (pos == NULL) |
| 6571 | return -1; |
| 6572 | |
| 6573 | pos++; |
| 6574 | adv_str = pos; |
| 6575 | |
| 6576 | /* Advertisement string is mandatory */ |
| 6577 | if (!pos[0] || pos[0] == ' ') |
| 6578 | return -1; |
| 6579 | |
| 6580 | /* Terminate svc string */ |
| 6581 | pos = os_strchr(pos, ' '); |
| 6582 | if (pos != NULL) |
| 6583 | *pos++ = '\0'; |
| 6584 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6585 | cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL; |
| 6586 | if (cpt_prio_str) { |
| 6587 | pos = os_strchr(pos, ' '); |
| 6588 | if (pos != NULL) |
| 6589 | *pos++ = '\0'; |
| 6590 | |
| 6591 | if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio)) |
| 6592 | return -1; |
| 6593 | } else { |
| 6594 | cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; |
| 6595 | cpt_prio[1] = 0; |
| 6596 | } |
| 6597 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6598 | /* Service and Response Information are optional */ |
| 6599 | if (pos && pos[0]) { |
| 6600 | size_t len; |
| 6601 | |
| 6602 | /* Note the bare ' included, which cannot exist legally |
| 6603 | * in unescaped string. */ |
| 6604 | svc_info = os_strstr(pos, "svc_info='"); |
| 6605 | |
| 6606 | if (svc_info) { |
| 6607 | svc_info += 9; |
| 6608 | len = os_strlen(svc_info); |
| 6609 | utf8_unescape(svc_info, len, svc_info, len); |
| 6610 | } |
| 6611 | } |
| 6612 | |
| 6613 | return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str, |
| 6614 | (u8) svc_state, (u16) config_methods, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6615 | svc_info, cpt_prio); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6616 | } |
| 6617 | |
| 6618 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6619 | static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd) |
| 6620 | { |
| 6621 | char *pos; |
| 6622 | |
| 6623 | pos = os_strchr(cmd, ' '); |
| 6624 | if (pos == NULL) |
| 6625 | return -1; |
| 6626 | *pos++ = '\0'; |
| 6627 | |
| 6628 | if (os_strcmp(cmd, "bonjour") == 0) |
| 6629 | return p2p_ctrl_service_add_bonjour(wpa_s, pos); |
| 6630 | if (os_strcmp(cmd, "upnp") == 0) |
| 6631 | return p2p_ctrl_service_add_upnp(wpa_s, pos); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6632 | if (os_strcmp(cmd, "asp") == 0) |
| 6633 | return p2p_ctrl_service_add_asp(wpa_s, 0, pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6634 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
| 6635 | return -1; |
| 6636 | } |
| 6637 | |
| 6638 | |
| 6639 | static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s, |
| 6640 | char *cmd) |
| 6641 | { |
| 6642 | size_t len; |
| 6643 | struct wpabuf *query; |
| 6644 | int ret; |
| 6645 | |
| 6646 | len = os_strlen(cmd); |
| 6647 | if (len & 1) |
| 6648 | return -1; |
| 6649 | len /= 2; |
| 6650 | query = wpabuf_alloc(len); |
| 6651 | if (query == NULL) |
| 6652 | return -1; |
| 6653 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { |
| 6654 | wpabuf_free(query); |
| 6655 | return -1; |
| 6656 | } |
| 6657 | |
| 6658 | ret = wpas_p2p_service_del_bonjour(wpa_s, query); |
| 6659 | wpabuf_free(query); |
| 6660 | return ret; |
| 6661 | } |
| 6662 | |
| 6663 | |
| 6664 | static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd) |
| 6665 | { |
| 6666 | char *pos; |
| 6667 | u8 version; |
| 6668 | |
| 6669 | pos = os_strchr(cmd, ' '); |
| 6670 | if (pos == NULL) |
| 6671 | return -1; |
| 6672 | *pos++ = '\0'; |
| 6673 | |
| 6674 | if (hexstr2bin(cmd, &version, 1) < 0) |
| 6675 | return -1; |
| 6676 | |
| 6677 | return wpas_p2p_service_del_upnp(wpa_s, version, pos); |
| 6678 | } |
| 6679 | |
| 6680 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6681 | static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd) |
| 6682 | { |
| 6683 | u32 adv_id; |
| 6684 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 6685 | if (os_strcmp(cmd, "all") == 0) { |
| 6686 | wpas_p2p_service_flush_asp(wpa_s); |
| 6687 | return 0; |
| 6688 | } |
| 6689 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6690 | if (sscanf(cmd, "%x", &adv_id) != 1) |
| 6691 | return -1; |
| 6692 | |
| 6693 | return wpas_p2p_service_del_asp(wpa_s, adv_id); |
| 6694 | } |
| 6695 | |
| 6696 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6697 | static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd) |
| 6698 | { |
| 6699 | char *pos; |
| 6700 | |
| 6701 | pos = os_strchr(cmd, ' '); |
| 6702 | if (pos == NULL) |
| 6703 | return -1; |
| 6704 | *pos++ = '\0'; |
| 6705 | |
| 6706 | if (os_strcmp(cmd, "bonjour") == 0) |
| 6707 | return p2p_ctrl_service_del_bonjour(wpa_s, pos); |
| 6708 | if (os_strcmp(cmd, "upnp") == 0) |
| 6709 | return p2p_ctrl_service_del_upnp(wpa_s, pos); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6710 | if (os_strcmp(cmd, "asp") == 0) |
| 6711 | return p2p_ctrl_service_del_asp(wpa_s, pos); |
| 6712 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
| 6713 | return -1; |
| 6714 | } |
| 6715 | |
| 6716 | |
| 6717 | static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd) |
| 6718 | { |
| 6719 | char *pos; |
| 6720 | |
| 6721 | pos = os_strchr(cmd, ' '); |
| 6722 | if (pos == NULL) |
| 6723 | return -1; |
| 6724 | *pos++ = '\0'; |
| 6725 | |
| 6726 | if (os_strcmp(cmd, "asp") == 0) |
| 6727 | return p2p_ctrl_service_add_asp(wpa_s, 1, pos); |
| 6728 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6729 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
| 6730 | return -1; |
| 6731 | } |
| 6732 | |
| 6733 | |
| 6734 | static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd) |
| 6735 | { |
| 6736 | u8 addr[ETH_ALEN]; |
| 6737 | |
| 6738 | /* <addr> */ |
| 6739 | |
| 6740 | if (hwaddr_aton(cmd, addr)) |
| 6741 | return -1; |
| 6742 | |
| 6743 | return wpas_p2p_reject(wpa_s, addr); |
| 6744 | } |
| 6745 | |
| 6746 | |
| 6747 | static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd) |
| 6748 | { |
| 6749 | char *pos; |
| 6750 | int id; |
| 6751 | struct wpa_ssid *ssid; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6752 | u8 *_peer = NULL, peer[ETH_ALEN]; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6753 | int freq = 0, pref_freq = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6754 | int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6755 | int edmg; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6756 | bool allow_6ghz; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6757 | |
| 6758 | id = atoi(cmd); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6759 | pos = os_strstr(cmd, " peer="); |
| 6760 | if (pos) { |
| 6761 | pos += 6; |
| 6762 | if (hwaddr_aton(pos, peer)) |
| 6763 | return -1; |
| 6764 | _peer = peer; |
| 6765 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6766 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 6767 | if (ssid == NULL || ssid->disabled != 2) { |
| 6768 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 6769 | "for persistent P2P group", |
| 6770 | id); |
| 6771 | return -1; |
| 6772 | } |
| 6773 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 6774 | pos = os_strstr(cmd, " freq="); |
| 6775 | if (pos) { |
| 6776 | pos += 6; |
| 6777 | freq = atoi(pos); |
| 6778 | if (freq <= 0) |
| 6779 | return -1; |
| 6780 | } |
| 6781 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6782 | pos = os_strstr(cmd, " pref="); |
| 6783 | if (pos) { |
| 6784 | pos += 6; |
| 6785 | pref_freq = atoi(pos); |
| 6786 | if (pref_freq <= 0) |
| 6787 | return -1; |
| 6788 | } |
| 6789 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6790 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
| 6791 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || |
| 6792 | vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6793 | he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6794 | edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg; |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 6795 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6796 | pos = os_strstr(cmd, "freq2="); |
| 6797 | if (pos) |
| 6798 | freq2 = atoi(pos + 6); |
| 6799 | |
| 6800 | pos = os_strstr(cmd, " max_oper_chwidth="); |
| 6801 | if (pos) |
| 6802 | chwidth = atoi(pos + 18); |
| 6803 | |
| 6804 | max_oper_chwidth = parse_freq(chwidth, freq2); |
| 6805 | if (max_oper_chwidth < 0) |
| 6806 | return -1; |
| 6807 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6808 | allow_6ghz = os_strstr(cmd, " allow_6ghz") != NULL; |
| 6809 | |
| 6810 | if (allow_6ghz && chwidth == 40) |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6811 | max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6812 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6813 | return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6814 | max_oper_chwidth, pref_freq, he, edmg, |
| 6815 | allow_6ghz); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6816 | } |
| 6817 | |
| 6818 | |
| 6819 | static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd) |
| 6820 | { |
| 6821 | char *pos; |
| 6822 | u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6823 | bool allow_6ghz; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6824 | |
| 6825 | pos = os_strstr(cmd, " peer="); |
| 6826 | if (!pos) |
| 6827 | return -1; |
| 6828 | |
| 6829 | *pos = '\0'; |
| 6830 | pos += 6; |
| 6831 | if (hwaddr_aton(pos, peer)) { |
| 6832 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos); |
| 6833 | return -1; |
| 6834 | } |
| 6835 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6836 | allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL; |
| 6837 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6838 | pos = os_strstr(pos, " go_dev_addr="); |
| 6839 | if (pos) { |
| 6840 | pos += 13; |
| 6841 | if (hwaddr_aton(pos, go_dev_addr)) { |
| 6842 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", |
| 6843 | pos); |
| 6844 | return -1; |
| 6845 | } |
| 6846 | go_dev = go_dev_addr; |
| 6847 | } |
| 6848 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6849 | return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev, allow_6ghz); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6850 | } |
| 6851 | |
| 6852 | |
| 6853 | static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd) |
| 6854 | { |
| 6855 | if (os_strncmp(cmd, "persistent=", 11) == 0) |
| 6856 | return p2p_ctrl_invite_persistent(wpa_s, cmd + 11); |
| 6857 | if (os_strncmp(cmd, "group=", 6) == 0) |
| 6858 | return p2p_ctrl_invite_group(wpa_s, cmd + 6); |
| 6859 | |
| 6860 | return -1; |
| 6861 | } |
| 6862 | |
| 6863 | |
| 6864 | static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6865 | int id, int freq, int vht_center_freq2, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6866 | int ht40, int vht, int vht_chwidth, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6867 | int he, int edmg, bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6868 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6869 | struct wpa_ssid *ssid; |
| 6870 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6871 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 6872 | if (ssid == NULL || ssid->disabled != 2) { |
| 6873 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 6874 | "for persistent P2P group", |
| 6875 | id); |
| 6876 | return -1; |
| 6877 | } |
| 6878 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6879 | return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, |
| 6880 | vht_center_freq2, 0, ht40, vht, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6881 | vht_chwidth, he, edmg, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6882 | NULL, 0, 0, allow_6ghz); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6883 | } |
| 6884 | |
| 6885 | |
| 6886 | static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) |
| 6887 | { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6888 | int freq = 0, persistent = 0, group_id = -1; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6889 | bool allow_6ghz = false; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6890 | int vht = wpa_s->conf->p2p_go_vht; |
| 6891 | int ht40 = wpa_s->conf->p2p_go_ht40 || vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6892 | int he = wpa_s->conf->p2p_go_he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6893 | int edmg = wpa_s->conf->p2p_go_edmg; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6894 | int max_oper_chwidth, chwidth = 0, freq2 = 0; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6895 | char *token, *context = NULL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6896 | #ifdef CONFIG_ACS |
| 6897 | int acs = 0; |
| 6898 | #endif /* CONFIG_ACS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6899 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6900 | while ((token = str_token(cmd, " ", &context))) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6901 | if (sscanf(token, "freq2=%d", &freq2) == 1 || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6902 | sscanf(token, "persistent=%d", &group_id) == 1 || |
| 6903 | sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6904 | continue; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6905 | #ifdef CONFIG_ACS |
| 6906 | } else if (os_strcmp(token, "freq=acs") == 0) { |
| 6907 | acs = 1; |
| 6908 | #endif /* CONFIG_ACS */ |
| 6909 | } else if (sscanf(token, "freq=%d", &freq) == 1) { |
| 6910 | continue; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6911 | } else if (os_strcmp(token, "ht40") == 0) { |
| 6912 | ht40 = 1; |
| 6913 | } else if (os_strcmp(token, "vht") == 0) { |
| 6914 | vht = 1; |
| 6915 | ht40 = 1; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6916 | } else if (os_strcmp(token, "he") == 0) { |
| 6917 | he = 1; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6918 | } else if (os_strcmp(token, "edmg") == 0) { |
| 6919 | edmg = 1; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6920 | } else if (os_strcmp(token, "persistent") == 0) { |
| 6921 | persistent = 1; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6922 | } else if (os_strcmp(token, "allow_6ghz") == 0) { |
| 6923 | allow_6ghz = true; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6924 | } else { |
| 6925 | wpa_printf(MSG_DEBUG, |
| 6926 | "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'", |
| 6927 | token); |
| 6928 | return -1; |
| 6929 | } |
| 6930 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6931 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6932 | #ifdef CONFIG_ACS |
| 6933 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) && |
| 6934 | (acs || freq == 2 || freq == 5)) { |
| 6935 | if (freq == 2 && wpa_s->best_24_freq <= 0) { |
| 6936 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G; |
| 6937 | wpa_s->p2p_go_do_acs = 1; |
| 6938 | freq = 0; |
| 6939 | } else if (freq == 5 && wpa_s->best_5_freq <= 0) { |
| 6940 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A; |
| 6941 | wpa_s->p2p_go_do_acs = 1; |
| 6942 | freq = 0; |
| 6943 | } else { |
| 6944 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY; |
| 6945 | wpa_s->p2p_go_do_acs = 1; |
| 6946 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6947 | } else { |
| 6948 | wpa_s->p2p_go_do_acs = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6949 | } |
| 6950 | #endif /* CONFIG_ACS */ |
| 6951 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6952 | max_oper_chwidth = parse_freq(chwidth, freq2); |
| 6953 | if (max_oper_chwidth < 0) |
| 6954 | return -1; |
| 6955 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6956 | if (allow_6ghz && chwidth == 40) |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6957 | max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6958 | |
| 6959 | /* Allow DFS to be used for Autonomous GO */ |
| 6960 | wpa_s->p2p_go_allow_dfs = !!(wpa_s->drv_flags & |
| 6961 | WPA_DRIVER_FLAGS_DFS_OFFLOAD); |
| 6962 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6963 | if (group_id >= 0) |
| 6964 | return p2p_ctrl_group_add_persistent(wpa_s, group_id, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6965 | freq, freq2, ht40, vht, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6966 | max_oper_chwidth, he, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6967 | edmg, allow_6ghz); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6968 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6969 | return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6970 | max_oper_chwidth, he, edmg, allow_6ghz); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6971 | } |
| 6972 | |
| 6973 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6974 | static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd, |
| 6975 | char *buf, size_t buflen) |
| 6976 | { |
| 6977 | u8 dev_addr[ETH_ALEN]; |
| 6978 | struct wpa_ssid *ssid; |
| 6979 | int res; |
| 6980 | const u8 *iaddr; |
| 6981 | |
| 6982 | ssid = wpa_s->current_ssid; |
| 6983 | if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO || |
| 6984 | hwaddr_aton(cmd, dev_addr)) |
| 6985 | return -1; |
| 6986 | |
| 6987 | iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr); |
| 6988 | if (!iaddr) |
| 6989 | return -1; |
| 6990 | res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr)); |
| 6991 | if (os_snprintf_error(buflen, res)) |
| 6992 | return -1; |
| 6993 | return res; |
| 6994 | } |
| 6995 | |
| 6996 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 6997 | static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global, |
| 6998 | const u8 *p2p_dev_addr) |
| 6999 | { |
| 7000 | struct wpa_supplicant *wpa_s; |
| 7001 | |
| 7002 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 7003 | if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr)) |
| 7004 | return 1; |
| 7005 | } |
| 7006 | |
| 7007 | return 0; |
| 7008 | } |
| 7009 | |
| 7010 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7011 | static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd, |
| 7012 | char *buf, size_t buflen) |
| 7013 | { |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7014 | u8 addr[ETH_ALEN], *addr_ptr, group_capab; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7015 | int next, res; |
| 7016 | const struct p2p_peer_info *info; |
| 7017 | char *pos, *end; |
| 7018 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
| 7019 | struct wpa_ssid *ssid; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7020 | size_t i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7021 | |
| 7022 | if (!wpa_s->global->p2p) |
| 7023 | return -1; |
| 7024 | |
| 7025 | if (os_strcmp(cmd, "FIRST") == 0) { |
| 7026 | addr_ptr = NULL; |
| 7027 | next = 0; |
| 7028 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { |
| 7029 | if (hwaddr_aton(cmd + 5, addr) < 0) |
| 7030 | return -1; |
| 7031 | addr_ptr = addr; |
| 7032 | next = 1; |
| 7033 | } else { |
| 7034 | if (hwaddr_aton(cmd, addr) < 0) |
| 7035 | return -1; |
| 7036 | addr_ptr = addr; |
| 7037 | next = 0; |
| 7038 | } |
| 7039 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7040 | info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next); |
| 7041 | if (info == NULL) |
| 7042 | return -1; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7043 | group_capab = info->group_capab; |
| 7044 | |
| 7045 | if (group_capab && |
| 7046 | !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) { |
| 7047 | wpa_printf(MSG_DEBUG, |
| 7048 | "P2P: Could not find any BSS with p2p_dev_addr " |
| 7049 | MACSTR ", hence override group_capab from 0x%x to 0", |
| 7050 | MAC2STR(info->p2p_device_addr), group_capab); |
| 7051 | group_capab = 0; |
| 7052 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7053 | |
| 7054 | pos = buf; |
| 7055 | end = buf + buflen; |
| 7056 | |
| 7057 | res = os_snprintf(pos, end - pos, MACSTR "\n" |
| 7058 | "pri_dev_type=%s\n" |
| 7059 | "device_name=%s\n" |
| 7060 | "manufacturer=%s\n" |
| 7061 | "model_name=%s\n" |
| 7062 | "model_number=%s\n" |
| 7063 | "serial_number=%s\n" |
| 7064 | "config_methods=0x%x\n" |
| 7065 | "dev_capab=0x%x\n" |
| 7066 | "group_capab=0x%x\n" |
| 7067 | "level=%d\n", |
| 7068 | MAC2STR(info->p2p_device_addr), |
| 7069 | wps_dev_type_bin2str(info->pri_dev_type, |
| 7070 | devtype, sizeof(devtype)), |
| 7071 | info->device_name, |
| 7072 | info->manufacturer, |
| 7073 | info->model_name, |
| 7074 | info->model_number, |
| 7075 | info->serial_number, |
| 7076 | info->config_methods, |
| 7077 | info->dev_capab, |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7078 | group_capab, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7079 | info->level); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7080 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7081 | return pos - buf; |
| 7082 | pos += res; |
| 7083 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7084 | for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++) |
| 7085 | { |
| 7086 | const u8 *t; |
| 7087 | t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN]; |
| 7088 | res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n", |
| 7089 | wps_dev_type_bin2str(t, devtype, |
| 7090 | sizeof(devtype))); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7091 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7092 | return pos - buf; |
| 7093 | pos += res; |
| 7094 | } |
| 7095 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7096 | 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] | 7097 | if (ssid) { |
| 7098 | res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7099 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7100 | return pos - buf; |
| 7101 | pos += res; |
| 7102 | } |
| 7103 | |
| 7104 | res = p2p_get_peer_info_txt(info, pos, end - pos); |
| 7105 | if (res < 0) |
| 7106 | return pos - buf; |
| 7107 | pos += res; |
| 7108 | |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 7109 | if (info->vendor_elems) { |
| 7110 | res = os_snprintf(pos, end - pos, "vendor_elems="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7111 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 7112 | return pos - buf; |
| 7113 | pos += res; |
| 7114 | |
| 7115 | pos += wpa_snprintf_hex(pos, end - pos, |
| 7116 | wpabuf_head(info->vendor_elems), |
| 7117 | wpabuf_len(info->vendor_elems)); |
| 7118 | |
| 7119 | res = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7120 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 7121 | return pos - buf; |
| 7122 | pos += res; |
| 7123 | } |
| 7124 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7125 | return pos - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7126 | } |
| 7127 | |
| 7128 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7129 | static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s, |
| 7130 | const char *param) |
| 7131 | { |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 7132 | unsigned int i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7133 | |
| 7134 | if (wpa_s->global->p2p == NULL) |
| 7135 | return -1; |
| 7136 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 7137 | if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0) |
| 7138 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7139 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 7140 | for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) { |
| 7141 | struct wpa_freq_range *freq; |
| 7142 | freq = &wpa_s->global->p2p_disallow_freq.range[i]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7143 | wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u", |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 7144 | freq->min, freq->max); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7145 | } |
| 7146 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7147 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7148 | return 0; |
| 7149 | } |
| 7150 | |
| 7151 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7152 | static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) |
| 7153 | { |
| 7154 | char *param; |
| 7155 | |
| 7156 | if (wpa_s->global->p2p == NULL) |
| 7157 | return -1; |
| 7158 | |
| 7159 | param = os_strchr(cmd, ' '); |
| 7160 | if (param == NULL) |
| 7161 | return -1; |
| 7162 | *param++ = '\0'; |
| 7163 | |
| 7164 | if (os_strcmp(cmd, "discoverability") == 0) { |
| 7165 | p2p_set_client_discoverability(wpa_s->global->p2p, |
| 7166 | atoi(param)); |
| 7167 | return 0; |
| 7168 | } |
| 7169 | |
| 7170 | if (os_strcmp(cmd, "managed") == 0) { |
| 7171 | p2p_set_managed_oper(wpa_s->global->p2p, atoi(param)); |
| 7172 | return 0; |
| 7173 | } |
| 7174 | |
| 7175 | if (os_strcmp(cmd, "listen_channel") == 0) { |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 7176 | char *pos; |
| 7177 | u8 channel, op_class; |
| 7178 | |
| 7179 | channel = atoi(param); |
| 7180 | pos = os_strchr(param, ' '); |
| 7181 | op_class = pos ? atoi(pos) : 81; |
| 7182 | |
| 7183 | return p2p_set_listen_channel(wpa_s->global->p2p, op_class, |
| 7184 | channel, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7185 | } |
| 7186 | |
| 7187 | if (os_strcmp(cmd, "ssid_postfix") == 0) { |
| 7188 | return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param, |
| 7189 | os_strlen(param)); |
| 7190 | } |
| 7191 | |
| 7192 | if (os_strcmp(cmd, "noa") == 0) { |
| 7193 | char *pos; |
| 7194 | int count, start, duration; |
| 7195 | /* GO NoA parameters: count,start_offset(ms),duration(ms) */ |
| 7196 | count = atoi(param); |
| 7197 | pos = os_strchr(param, ','); |
| 7198 | if (pos == NULL) |
| 7199 | return -1; |
| 7200 | pos++; |
| 7201 | start = atoi(pos); |
| 7202 | pos = os_strchr(pos, ','); |
| 7203 | if (pos == NULL) |
| 7204 | return -1; |
| 7205 | pos++; |
| 7206 | duration = atoi(pos); |
| 7207 | if (count < 0 || count > 255 || start < 0 || duration < 0) |
| 7208 | return -1; |
| 7209 | if (count == 0 && duration > 0) |
| 7210 | return -1; |
| 7211 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d " |
| 7212 | "start=%d duration=%d", count, start, duration); |
| 7213 | return wpas_p2p_set_noa(wpa_s, count, start, duration); |
| 7214 | } |
| 7215 | |
| 7216 | if (os_strcmp(cmd, "ps") == 0) |
| 7217 | return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1); |
| 7218 | |
| 7219 | if (os_strcmp(cmd, "oppps") == 0) |
| 7220 | return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1); |
| 7221 | |
| 7222 | if (os_strcmp(cmd, "ctwindow") == 0) |
| 7223 | return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param)); |
| 7224 | |
| 7225 | if (os_strcmp(cmd, "disabled") == 0) { |
| 7226 | wpa_s->global->p2p_disabled = atoi(param); |
| 7227 | wpa_printf(MSG_DEBUG, "P2P functionality %s", |
| 7228 | wpa_s->global->p2p_disabled ? |
| 7229 | "disabled" : "enabled"); |
| 7230 | if (wpa_s->global->p2p_disabled) { |
| 7231 | wpas_p2p_stop_find(wpa_s); |
| 7232 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
| 7233 | p2p_flush(wpa_s->global->p2p); |
| 7234 | } |
| 7235 | return 0; |
| 7236 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7237 | |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 7238 | if (os_strcmp(cmd, "conc_pref") == 0) { |
| 7239 | if (os_strcmp(param, "sta") == 0) |
| 7240 | wpa_s->global->conc_pref = WPA_CONC_PREF_STA; |
| 7241 | else if (os_strcmp(param, "p2p") == 0) |
| 7242 | wpa_s->global->conc_pref = WPA_CONC_PREF_P2P; |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 7243 | else { |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 7244 | wpa_printf(MSG_INFO, "Invalid conc_pref value"); |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 7245 | return -1; |
| 7246 | } |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 7247 | wpa_printf(MSG_DEBUG, "Single channel concurrency preference: " |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7248 | "%s", param); |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 7249 | return 0; |
| 7250 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7251 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7252 | if (os_strcmp(cmd, "force_long_sd") == 0) { |
| 7253 | wpa_s->force_long_sd = atoi(param); |
| 7254 | return 0; |
| 7255 | } |
| 7256 | |
| 7257 | if (os_strcmp(cmd, "peer_filter") == 0) { |
| 7258 | u8 addr[ETH_ALEN]; |
| 7259 | if (hwaddr_aton(param, addr)) |
| 7260 | return -1; |
| 7261 | p2p_set_peer_filter(wpa_s->global->p2p, addr); |
| 7262 | return 0; |
| 7263 | } |
| 7264 | |
| 7265 | if (os_strcmp(cmd, "cross_connect") == 0) |
| 7266 | return wpas_p2p_set_cross_connect(wpa_s, atoi(param)); |
| 7267 | |
| 7268 | if (os_strcmp(cmd, "go_apsd") == 0) { |
| 7269 | if (os_strcmp(param, "disable") == 0) |
| 7270 | wpa_s->set_ap_uapsd = 0; |
| 7271 | else { |
| 7272 | wpa_s->set_ap_uapsd = 1; |
| 7273 | wpa_s->ap_uapsd = atoi(param); |
| 7274 | } |
| 7275 | return 0; |
| 7276 | } |
| 7277 | |
| 7278 | if (os_strcmp(cmd, "client_apsd") == 0) { |
| 7279 | if (os_strcmp(param, "disable") == 0) |
| 7280 | wpa_s->set_sta_uapsd = 0; |
| 7281 | else { |
| 7282 | int be, bk, vi, vo; |
| 7283 | char *pos; |
| 7284 | /* format: BE,BK,VI,VO;max SP Length */ |
| 7285 | be = atoi(param); |
| 7286 | pos = os_strchr(param, ','); |
| 7287 | if (pos == NULL) |
| 7288 | return -1; |
| 7289 | pos++; |
| 7290 | bk = atoi(pos); |
| 7291 | pos = os_strchr(pos, ','); |
| 7292 | if (pos == NULL) |
| 7293 | return -1; |
| 7294 | pos++; |
| 7295 | vi = atoi(pos); |
| 7296 | pos = os_strchr(pos, ','); |
| 7297 | if (pos == NULL) |
| 7298 | return -1; |
| 7299 | pos++; |
| 7300 | vo = atoi(pos); |
| 7301 | /* ignore max SP Length for now */ |
| 7302 | |
| 7303 | wpa_s->set_sta_uapsd = 1; |
| 7304 | wpa_s->sta_uapsd = 0; |
| 7305 | if (be) |
| 7306 | wpa_s->sta_uapsd |= BIT(0); |
| 7307 | if (bk) |
| 7308 | wpa_s->sta_uapsd |= BIT(1); |
| 7309 | if (vi) |
| 7310 | wpa_s->sta_uapsd |= BIT(2); |
| 7311 | if (vo) |
| 7312 | wpa_s->sta_uapsd |= BIT(3); |
| 7313 | } |
| 7314 | return 0; |
| 7315 | } |
| 7316 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7317 | if (os_strcmp(cmd, "disallow_freq") == 0) |
| 7318 | return p2p_ctrl_disallow_freq(wpa_s, param); |
| 7319 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7320 | if (os_strcmp(cmd, "disc_int") == 0) { |
| 7321 | int min_disc_int, max_disc_int, max_disc_tu; |
| 7322 | char *pos; |
| 7323 | |
| 7324 | pos = param; |
| 7325 | |
| 7326 | min_disc_int = atoi(pos); |
| 7327 | pos = os_strchr(pos, ' '); |
| 7328 | if (pos == NULL) |
| 7329 | return -1; |
| 7330 | *pos++ = '\0'; |
| 7331 | |
| 7332 | max_disc_int = atoi(pos); |
| 7333 | pos = os_strchr(pos, ' '); |
| 7334 | if (pos == NULL) |
| 7335 | return -1; |
| 7336 | *pos++ = '\0'; |
| 7337 | |
| 7338 | max_disc_tu = atoi(pos); |
| 7339 | |
| 7340 | return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int, |
| 7341 | max_disc_int, max_disc_tu); |
| 7342 | } |
| 7343 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7344 | if (os_strcmp(cmd, "per_sta_psk") == 0) { |
| 7345 | wpa_s->global->p2p_per_sta_psk = !!atoi(param); |
| 7346 | return 0; |
| 7347 | } |
| 7348 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7349 | #ifdef CONFIG_WPS_NFC |
| 7350 | if (os_strcmp(cmd, "nfc_tag") == 0) |
| 7351 | return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param)); |
| 7352 | #endif /* CONFIG_WPS_NFC */ |
| 7353 | |
| 7354 | if (os_strcmp(cmd, "disable_ip_addr_req") == 0) { |
| 7355 | wpa_s->p2p_disable_ip_addr_req = !!atoi(param); |
| 7356 | return 0; |
| 7357 | } |
| 7358 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7359 | if (os_strcmp(cmd, "override_pref_op_chan") == 0) { |
| 7360 | int op_class, chan; |
| 7361 | |
| 7362 | op_class = atoi(param); |
| 7363 | param = os_strchr(param, ':'); |
| 7364 | if (!param) |
| 7365 | return -1; |
| 7366 | param++; |
| 7367 | chan = atoi(param); |
| 7368 | p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class, |
| 7369 | chan); |
| 7370 | return 0; |
| 7371 | } |
| 7372 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7373 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", |
| 7374 | cmd); |
| 7375 | |
| 7376 | return -1; |
| 7377 | } |
| 7378 | |
| 7379 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7380 | static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s) |
| 7381 | { |
| 7382 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
| 7383 | wpa_s->force_long_sd = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7384 | |
| 7385 | #ifdef CONFIG_TESTING_OPTIONS |
| 7386 | os_free(wpa_s->get_pref_freq_list_override); |
| 7387 | wpa_s->get_pref_freq_list_override = NULL; |
| 7388 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7389 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7390 | wpas_p2p_stop_find(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7391 | wpa_s->parent->p2ps_method_config_any = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7392 | if (wpa_s->global->p2p) |
| 7393 | p2p_flush(wpa_s->global->p2p); |
| 7394 | } |
| 7395 | |
| 7396 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7397 | static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd) |
| 7398 | { |
| 7399 | char *pos, *pos2; |
| 7400 | unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0; |
| 7401 | |
| 7402 | if (cmd[0]) { |
| 7403 | pos = os_strchr(cmd, ' '); |
| 7404 | if (pos == NULL) |
| 7405 | return -1; |
| 7406 | *pos++ = '\0'; |
| 7407 | dur1 = atoi(cmd); |
| 7408 | |
| 7409 | pos2 = os_strchr(pos, ' '); |
| 7410 | if (pos2) |
| 7411 | *pos2++ = '\0'; |
| 7412 | int1 = atoi(pos); |
| 7413 | } else |
| 7414 | pos2 = NULL; |
| 7415 | |
| 7416 | if (pos2) { |
| 7417 | pos = os_strchr(pos2, ' '); |
| 7418 | if (pos == NULL) |
| 7419 | return -1; |
| 7420 | *pos++ = '\0'; |
| 7421 | dur2 = atoi(pos2); |
| 7422 | int2 = atoi(pos); |
| 7423 | } |
| 7424 | |
| 7425 | return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2); |
| 7426 | } |
| 7427 | |
| 7428 | |
| 7429 | static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) |
| 7430 | { |
| 7431 | char *pos; |
| 7432 | unsigned int period = 0, interval = 0; |
| 7433 | |
| 7434 | if (cmd[0]) { |
| 7435 | pos = os_strchr(cmd, ' '); |
| 7436 | if (pos == NULL) |
| 7437 | return -1; |
| 7438 | *pos++ = '\0'; |
| 7439 | period = atoi(cmd); |
| 7440 | interval = atoi(pos); |
| 7441 | } |
| 7442 | |
| 7443 | return wpas_p2p_ext_listen(wpa_s, period, interval); |
| 7444 | } |
| 7445 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7446 | |
| 7447 | static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd) |
| 7448 | { |
| 7449 | const char *pos; |
| 7450 | u8 peer[ETH_ALEN]; |
| 7451 | int iface_addr = 0; |
| 7452 | |
| 7453 | pos = cmd; |
| 7454 | if (os_strncmp(pos, "iface=", 6) == 0) { |
| 7455 | iface_addr = 1; |
| 7456 | pos += 6; |
| 7457 | } |
| 7458 | if (hwaddr_aton(pos, peer)) |
| 7459 | return -1; |
| 7460 | |
| 7461 | wpas_p2p_remove_client(wpa_s, peer, iface_addr); |
| 7462 | return 0; |
| 7463 | } |
| 7464 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7465 | |
| 7466 | static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd) |
| 7467 | { |
| 7468 | int freq = 0, period = 0, interval = 0, count = 0; |
| 7469 | |
| 7470 | if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4) |
| 7471 | { |
| 7472 | wpa_printf(MSG_DEBUG, |
| 7473 | "CTRL: Invalid P2P LO Start parameter: '%s'", cmd); |
| 7474 | return -1; |
| 7475 | } |
| 7476 | |
| 7477 | return wpas_p2p_lo_start(wpa_s, freq, period, interval, count); |
| 7478 | } |
| 7479 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7480 | #endif /* CONFIG_P2P */ |
| 7481 | |
| 7482 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7483 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val) |
| 7484 | { |
| 7485 | struct wpa_freq_range_list ranges; |
| 7486 | int *freqs = NULL; |
| 7487 | struct hostapd_hw_modes *mode; |
| 7488 | u16 i; |
| 7489 | |
| 7490 | if (wpa_s->hw.modes == NULL) |
| 7491 | return NULL; |
| 7492 | |
| 7493 | os_memset(&ranges, 0, sizeof(ranges)); |
| 7494 | if (freq_range_list_parse(&ranges, val) < 0) |
| 7495 | return NULL; |
| 7496 | |
| 7497 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 7498 | int j; |
| 7499 | |
| 7500 | mode = &wpa_s->hw.modes[i]; |
| 7501 | for (j = 0; j < mode->num_channels; j++) { |
| 7502 | unsigned int freq; |
| 7503 | |
| 7504 | if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED) |
| 7505 | continue; |
| 7506 | |
| 7507 | freq = mode->channels[j].freq; |
| 7508 | if (!freq_range_list_includes(&ranges, freq)) |
| 7509 | continue; |
| 7510 | |
| 7511 | int_array_add_unique(&freqs, freq); |
| 7512 | } |
| 7513 | } |
| 7514 | |
| 7515 | os_free(ranges.range); |
| 7516 | return freqs; |
| 7517 | } |
| 7518 | |
| 7519 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7520 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7521 | |
| 7522 | static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param) |
| 7523 | { |
| 7524 | int auto_sel = 0; |
| 7525 | int *freqs = NULL; |
| 7526 | |
| 7527 | if (param) { |
| 7528 | char *pos; |
| 7529 | |
| 7530 | auto_sel = os_strstr(param, "auto") != NULL; |
| 7531 | |
| 7532 | pos = os_strstr(param, "freq="); |
| 7533 | if (pos) { |
| 7534 | freqs = freq_range_to_channel_list(wpa_s, pos + 5); |
| 7535 | if (freqs == NULL) |
| 7536 | return -1; |
| 7537 | } |
| 7538 | |
| 7539 | } |
| 7540 | |
| 7541 | return interworking_select(wpa_s, auto_sel, freqs); |
| 7542 | } |
| 7543 | |
| 7544 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7545 | static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst, |
| 7546 | int only_add) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7547 | { |
| 7548 | u8 bssid[ETH_ALEN]; |
| 7549 | struct wpa_bss *bss; |
| 7550 | |
| 7551 | if (hwaddr_aton(dst, bssid)) { |
| 7552 | wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst); |
| 7553 | return -1; |
| 7554 | } |
| 7555 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7556 | bss = wpa_bss_get_bssid_latest(wpa_s, bssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7557 | if (bss == NULL) { |
| 7558 | wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR, |
| 7559 | MAC2STR(bssid)); |
| 7560 | return -1; |
| 7561 | } |
| 7562 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7563 | if (bss->ssid_len == 0) { |
| 7564 | int found = 0; |
| 7565 | |
| 7566 | wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR |
| 7567 | " does not have SSID information", MAC2STR(bssid)); |
| 7568 | |
| 7569 | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, |
| 7570 | list) { |
| 7571 | if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 && |
| 7572 | bss->ssid_len > 0) { |
| 7573 | found = 1; |
| 7574 | break; |
| 7575 | } |
| 7576 | } |
| 7577 | |
| 7578 | if (!found) |
| 7579 | return -1; |
| 7580 | wpa_printf(MSG_DEBUG, |
| 7581 | "Found another matching BSS entry with SSID"); |
| 7582 | } |
| 7583 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7584 | return interworking_connect(wpa_s, bss, only_add); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7585 | } |
| 7586 | |
| 7587 | |
| 7588 | static int get_anqp(struct wpa_supplicant *wpa_s, char *dst) |
| 7589 | { |
| 7590 | u8 dst_addr[ETH_ALEN]; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7591 | int used, freq = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7592 | char *pos; |
| 7593 | #define MAX_ANQP_INFO_ID 100 |
| 7594 | u16 id[MAX_ANQP_INFO_ID]; |
| 7595 | size_t num_id = 0; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7596 | u32 subtypes = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7597 | u32 mbo_subtypes = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7598 | |
| 7599 | used = hwaddr_aton2(dst, dst_addr); |
| 7600 | if (used < 0) |
| 7601 | return -1; |
| 7602 | pos = dst + used; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7603 | if (*pos == ' ') |
| 7604 | pos++; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7605 | |
| 7606 | if (os_strncmp(pos, "freq=", 5) == 0) { |
| 7607 | freq = atoi(pos + 5); |
| 7608 | pos = os_strchr(pos, ' '); |
| 7609 | if (!pos) |
| 7610 | return -1; |
| 7611 | pos++; |
| 7612 | } |
| 7613 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7614 | while (num_id < MAX_ANQP_INFO_ID) { |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7615 | if (os_strncmp(pos, "hs20:", 5) == 0) { |
| 7616 | #ifdef CONFIG_HS20 |
| 7617 | int num = atoi(pos + 5); |
| 7618 | if (num <= 0 || num > 31) |
| 7619 | return -1; |
| 7620 | subtypes |= BIT(num); |
| 7621 | #else /* CONFIG_HS20 */ |
| 7622 | return -1; |
| 7623 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7624 | } else if (os_strncmp(pos, "mbo:", 4) == 0) { |
| 7625 | #ifdef CONFIG_MBO |
| 7626 | int num = atoi(pos + 4); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7627 | |
| 7628 | if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7629 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7630 | mbo_subtypes |= BIT(num); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7631 | #else /* CONFIG_MBO */ |
| 7632 | return -1; |
| 7633 | #endif /* CONFIG_MBO */ |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7634 | } else { |
| 7635 | id[num_id] = atoi(pos); |
| 7636 | if (id[num_id]) |
| 7637 | num_id++; |
| 7638 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7639 | pos = os_strchr(pos + 1, ','); |
| 7640 | if (pos == NULL) |
| 7641 | break; |
| 7642 | pos++; |
| 7643 | } |
| 7644 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7645 | if (num_id == 0 && !subtypes && !mbo_subtypes) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7646 | return -1; |
| 7647 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7648 | return anqp_send_req(wpa_s, dst_addr, freq, id, num_id, subtypes, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7649 | mbo_subtypes); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7650 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7651 | |
| 7652 | |
| 7653 | static int gas_request(struct wpa_supplicant *wpa_s, char *cmd) |
| 7654 | { |
| 7655 | u8 dst_addr[ETH_ALEN]; |
| 7656 | struct wpabuf *advproto, *query = NULL; |
| 7657 | int used, ret = -1; |
| 7658 | char *pos, *end; |
| 7659 | size_t len; |
| 7660 | |
| 7661 | used = hwaddr_aton2(cmd, dst_addr); |
| 7662 | if (used < 0) |
| 7663 | return -1; |
| 7664 | |
| 7665 | pos = cmd + used; |
| 7666 | while (*pos == ' ') |
| 7667 | pos++; |
| 7668 | |
| 7669 | /* Advertisement Protocol ID */ |
| 7670 | end = os_strchr(pos, ' '); |
| 7671 | if (end) |
| 7672 | len = end - pos; |
| 7673 | else |
| 7674 | len = os_strlen(pos); |
| 7675 | if (len & 0x01) |
| 7676 | return -1; |
| 7677 | len /= 2; |
| 7678 | if (len == 0) |
| 7679 | return -1; |
| 7680 | advproto = wpabuf_alloc(len); |
| 7681 | if (advproto == NULL) |
| 7682 | return -1; |
| 7683 | if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0) |
| 7684 | goto fail; |
| 7685 | |
| 7686 | if (end) { |
| 7687 | /* Optional Query Request */ |
| 7688 | pos = end + 1; |
| 7689 | while (*pos == ' ') |
| 7690 | pos++; |
| 7691 | |
| 7692 | len = os_strlen(pos); |
| 7693 | if (len) { |
| 7694 | if (len & 0x01) |
| 7695 | goto fail; |
| 7696 | len /= 2; |
| 7697 | if (len == 0) |
| 7698 | goto fail; |
| 7699 | query = wpabuf_alloc(len); |
| 7700 | if (query == NULL) |
| 7701 | goto fail; |
| 7702 | if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0) |
| 7703 | goto fail; |
| 7704 | } |
| 7705 | } |
| 7706 | |
| 7707 | ret = gas_send_request(wpa_s, dst_addr, advproto, query); |
| 7708 | |
| 7709 | fail: |
| 7710 | wpabuf_free(advproto); |
| 7711 | wpabuf_free(query); |
| 7712 | |
| 7713 | return ret; |
| 7714 | } |
| 7715 | |
| 7716 | |
| 7717 | static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf, |
| 7718 | size_t buflen) |
| 7719 | { |
| 7720 | u8 addr[ETH_ALEN]; |
| 7721 | int dialog_token; |
| 7722 | int used; |
| 7723 | char *pos; |
| 7724 | size_t resp_len, start, requested_len; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7725 | struct wpabuf *resp; |
| 7726 | int ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7727 | |
| 7728 | used = hwaddr_aton2(cmd, addr); |
| 7729 | if (used < 0) |
| 7730 | return -1; |
| 7731 | |
| 7732 | pos = cmd + used; |
| 7733 | while (*pos == ' ') |
| 7734 | pos++; |
| 7735 | dialog_token = atoi(pos); |
| 7736 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7737 | if (wpa_s->last_gas_resp && |
| 7738 | os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 && |
| 7739 | dialog_token == wpa_s->last_gas_dialog_token) |
| 7740 | resp = wpa_s->last_gas_resp; |
| 7741 | else if (wpa_s->prev_gas_resp && |
| 7742 | os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 && |
| 7743 | dialog_token == wpa_s->prev_gas_dialog_token) |
| 7744 | resp = wpa_s->prev_gas_resp; |
| 7745 | else |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7746 | return -1; |
| 7747 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7748 | resp_len = wpabuf_len(resp); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7749 | start = 0; |
| 7750 | requested_len = resp_len; |
| 7751 | |
| 7752 | pos = os_strchr(pos, ' '); |
| 7753 | if (pos) { |
| 7754 | start = atoi(pos); |
| 7755 | if (start > resp_len) |
| 7756 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); |
| 7757 | pos = os_strchr(pos, ','); |
| 7758 | if (pos == NULL) |
| 7759 | return -1; |
| 7760 | pos++; |
| 7761 | requested_len = atoi(pos); |
| 7762 | if (start + requested_len > resp_len) |
| 7763 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); |
| 7764 | } |
| 7765 | |
| 7766 | if (requested_len * 2 + 1 > buflen) |
| 7767 | return os_snprintf(buf, buflen, "FAIL-Too long response"); |
| 7768 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7769 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start, |
| 7770 | requested_len); |
| 7771 | |
| 7772 | if (start + requested_len == resp_len) { |
| 7773 | /* |
| 7774 | * Free memory by dropping the response after it has been |
| 7775 | * fetched. |
| 7776 | */ |
| 7777 | if (resp == wpa_s->prev_gas_resp) { |
| 7778 | wpabuf_free(wpa_s->prev_gas_resp); |
| 7779 | wpa_s->prev_gas_resp = NULL; |
| 7780 | } else { |
| 7781 | wpabuf_free(wpa_s->last_gas_resp); |
| 7782 | wpa_s->last_gas_resp = NULL; |
| 7783 | } |
| 7784 | } |
| 7785 | |
| 7786 | return ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7787 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7788 | #endif /* CONFIG_INTERWORKING */ |
| 7789 | |
| 7790 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7791 | #ifdef CONFIG_HS20 |
| 7792 | |
| 7793 | static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst) |
| 7794 | { |
| 7795 | u8 dst_addr[ETH_ALEN]; |
| 7796 | int used; |
| 7797 | char *pos; |
| 7798 | u32 subtypes = 0; |
| 7799 | |
| 7800 | used = hwaddr_aton2(dst, dst_addr); |
| 7801 | if (used < 0) |
| 7802 | return -1; |
| 7803 | pos = dst + used; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7804 | if (*pos == ' ') |
| 7805 | pos++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7806 | for (;;) { |
| 7807 | int num = atoi(pos); |
| 7808 | if (num <= 0 || num > 31) |
| 7809 | return -1; |
| 7810 | subtypes |= BIT(num); |
| 7811 | pos = os_strchr(pos + 1, ','); |
| 7812 | if (pos == NULL) |
| 7813 | break; |
| 7814 | pos++; |
| 7815 | } |
| 7816 | |
| 7817 | if (subtypes == 0) |
| 7818 | return -1; |
| 7819 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7820 | 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] | 7821 | } |
| 7822 | |
| 7823 | |
| 7824 | static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s, |
| 7825 | const u8 *addr, const char *realm) |
| 7826 | { |
| 7827 | u8 *buf; |
| 7828 | size_t rlen, len; |
| 7829 | int ret; |
| 7830 | |
| 7831 | rlen = os_strlen(realm); |
| 7832 | len = 3 + rlen; |
| 7833 | buf = os_malloc(len); |
| 7834 | if (buf == NULL) |
| 7835 | return -1; |
| 7836 | buf[0] = 1; /* NAI Home Realm Count */ |
| 7837 | buf[1] = 0; /* Formatted in accordance with RFC 4282 */ |
| 7838 | buf[2] = rlen; |
| 7839 | os_memcpy(buf + 3, realm, rlen); |
| 7840 | |
| 7841 | ret = hs20_anqp_send_req(wpa_s, addr, |
| 7842 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7843 | buf, len, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7844 | |
| 7845 | os_free(buf); |
| 7846 | |
| 7847 | return ret; |
| 7848 | } |
| 7849 | |
| 7850 | |
| 7851 | static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s, |
| 7852 | char *dst) |
| 7853 | { |
| 7854 | struct wpa_cred *cred = wpa_s->conf->cred; |
| 7855 | u8 dst_addr[ETH_ALEN]; |
| 7856 | int used; |
| 7857 | u8 *buf; |
| 7858 | size_t len; |
| 7859 | int ret; |
| 7860 | |
| 7861 | used = hwaddr_aton2(dst, dst_addr); |
| 7862 | if (used < 0) |
| 7863 | return -1; |
| 7864 | |
| 7865 | while (dst[used] == ' ') |
| 7866 | used++; |
| 7867 | if (os_strncmp(dst + used, "realm=", 6) == 0) |
| 7868 | return hs20_nai_home_realm_list(wpa_s, dst_addr, |
| 7869 | dst + used + 6); |
| 7870 | |
| 7871 | len = os_strlen(dst + used); |
| 7872 | |
| 7873 | if (len == 0 && cred && cred->realm) |
| 7874 | return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm); |
| 7875 | |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 7876 | if (len & 1) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7877 | return -1; |
| 7878 | len /= 2; |
| 7879 | buf = os_malloc(len); |
| 7880 | if (buf == NULL) |
| 7881 | return -1; |
| 7882 | if (hexstr2bin(dst + used, buf, len) < 0) { |
| 7883 | os_free(buf); |
| 7884 | return -1; |
| 7885 | } |
| 7886 | |
| 7887 | ret = hs20_anqp_send_req(wpa_s, dst_addr, |
| 7888 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7889 | buf, len, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7890 | os_free(buf); |
| 7891 | |
| 7892 | return ret; |
| 7893 | } |
| 7894 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 7895 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7896 | static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply, |
| 7897 | int buflen) |
| 7898 | { |
| 7899 | u8 dst_addr[ETH_ALEN]; |
| 7900 | int used; |
| 7901 | char *ctx = NULL, *icon, *poffset, *psize; |
| 7902 | |
| 7903 | used = hwaddr_aton2(cmd, dst_addr); |
| 7904 | if (used < 0) |
| 7905 | return -1; |
| 7906 | cmd += used; |
| 7907 | |
| 7908 | icon = str_token(cmd, " ", &ctx); |
| 7909 | poffset = str_token(cmd, " ", &ctx); |
| 7910 | psize = str_token(cmd, " ", &ctx); |
| 7911 | if (!icon || !poffset || !psize) |
| 7912 | return -1; |
| 7913 | |
| 7914 | wpa_s->fetch_osu_icon_in_progress = 0; |
| 7915 | return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize), |
| 7916 | reply, buflen); |
| 7917 | } |
| 7918 | |
| 7919 | |
| 7920 | static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd) |
| 7921 | { |
| 7922 | u8 dst_addr[ETH_ALEN]; |
| 7923 | int used; |
| 7924 | char *icon; |
| 7925 | |
| 7926 | if (!cmd[0]) |
| 7927 | return hs20_del_icon(wpa_s, NULL, NULL); |
| 7928 | |
| 7929 | used = hwaddr_aton2(cmd, dst_addr); |
| 7930 | if (used < 0) |
| 7931 | return -1; |
| 7932 | |
| 7933 | while (cmd[used] == ' ') |
| 7934 | used++; |
| 7935 | icon = cmd[used] ? &cmd[used] : NULL; |
| 7936 | |
| 7937 | return hs20_del_icon(wpa_s, dst_addr, icon); |
| 7938 | } |
| 7939 | |
| 7940 | |
| 7941 | 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] | 7942 | { |
| 7943 | u8 dst_addr[ETH_ALEN]; |
| 7944 | int used; |
| 7945 | char *icon; |
| 7946 | |
| 7947 | used = hwaddr_aton2(cmd, dst_addr); |
| 7948 | if (used < 0) |
| 7949 | return -1; |
| 7950 | |
| 7951 | while (cmd[used] == ' ') |
| 7952 | used++; |
| 7953 | icon = &cmd[used]; |
| 7954 | |
| 7955 | wpa_s->fetch_osu_icon_in_progress = 0; |
| 7956 | 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] | 7957 | (u8 *) icon, os_strlen(icon), inmem); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 7958 | } |
| 7959 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7960 | #endif /* CONFIG_HS20 */ |
| 7961 | |
| 7962 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7963 | #ifdef CONFIG_AUTOSCAN |
| 7964 | |
| 7965 | static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s, |
| 7966 | char *cmd) |
| 7967 | { |
| 7968 | enum wpa_states state = wpa_s->wpa_state; |
| 7969 | char *new_params = NULL; |
| 7970 | |
| 7971 | if (os_strlen(cmd) > 0) { |
| 7972 | new_params = os_strdup(cmd); |
| 7973 | if (new_params == NULL) |
| 7974 | return -1; |
| 7975 | } |
| 7976 | |
| 7977 | os_free(wpa_s->conf->autoscan); |
| 7978 | wpa_s->conf->autoscan = new_params; |
| 7979 | |
| 7980 | if (wpa_s->conf->autoscan == NULL) |
| 7981 | autoscan_deinit(wpa_s); |
| 7982 | else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) |
| 7983 | autoscan_init(wpa_s, 1); |
| 7984 | else if (state == WPA_SCANNING) |
| 7985 | wpa_supplicant_reinit_autoscan(wpa_s); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7986 | else |
| 7987 | wpa_printf(MSG_DEBUG, "No autoscan update in state %s", |
| 7988 | wpa_supplicant_state_txt(state)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7989 | |
| 7990 | return 0; |
| 7991 | } |
| 7992 | |
| 7993 | #endif /* CONFIG_AUTOSCAN */ |
| 7994 | |
| 7995 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7996 | #ifdef CONFIG_WNM |
| 7997 | |
| 7998 | static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd) |
| 7999 | { |
| 8000 | int enter; |
| 8001 | int intval = 0; |
| 8002 | char *pos; |
| 8003 | int ret; |
| 8004 | struct wpabuf *tfs_req = NULL; |
| 8005 | |
| 8006 | if (os_strncmp(cmd, "enter", 5) == 0) |
| 8007 | enter = 1; |
| 8008 | else if (os_strncmp(cmd, "exit", 4) == 0) |
| 8009 | enter = 0; |
| 8010 | else |
| 8011 | return -1; |
| 8012 | |
| 8013 | pos = os_strstr(cmd, " interval="); |
| 8014 | if (pos) |
| 8015 | intval = atoi(pos + 10); |
| 8016 | |
| 8017 | pos = os_strstr(cmd, " tfs_req="); |
| 8018 | if (pos) { |
| 8019 | char *end; |
| 8020 | size_t len; |
| 8021 | pos += 9; |
| 8022 | end = os_strchr(pos, ' '); |
| 8023 | if (end) |
| 8024 | len = end - pos; |
| 8025 | else |
| 8026 | len = os_strlen(pos); |
| 8027 | if (len & 1) |
| 8028 | return -1; |
| 8029 | len /= 2; |
| 8030 | tfs_req = wpabuf_alloc(len); |
| 8031 | if (tfs_req == NULL) |
| 8032 | return -1; |
| 8033 | if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) { |
| 8034 | wpabuf_free(tfs_req); |
| 8035 | return -1; |
| 8036 | } |
| 8037 | } |
| 8038 | |
| 8039 | ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER : |
| 8040 | WNM_SLEEP_MODE_EXIT, intval, |
| 8041 | tfs_req); |
| 8042 | wpabuf_free(tfs_req); |
| 8043 | |
| 8044 | return ret; |
| 8045 | } |
| 8046 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 8047 | |
| 8048 | static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd) |
| 8049 | { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8050 | int query_reason, list = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8051 | char *btm_candidates = NULL; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 8052 | |
| 8053 | query_reason = atoi(cmd); |
| 8054 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8055 | cmd = os_strchr(cmd, ' '); |
| 8056 | if (cmd) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8057 | if (os_strncmp(cmd, " list", 5) == 0) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8058 | list = 1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8059 | else |
| 8060 | btm_candidates = cmd; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8061 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 8062 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8063 | wpa_printf(MSG_DEBUG, |
| 8064 | "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s", |
| 8065 | query_reason, list ? " candidate list" : ""); |
| 8066 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8067 | return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason, |
| 8068 | btm_candidates, |
| 8069 | list); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 8070 | } |
| 8071 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 8072 | |
| 8073 | static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s, |
| 8074 | char *cmd) |
| 8075 | { |
| 8076 | struct wpabuf *elems; |
| 8077 | int ret; |
| 8078 | |
| 8079 | elems = wpabuf_parse_bin(cmd); |
| 8080 | if (!elems) |
| 8081 | return -1; |
| 8082 | |
| 8083 | ret = wnm_send_coloc_intf_report(wpa_s, 0, elems); |
| 8084 | wpabuf_free(elems); |
| 8085 | return ret; |
| 8086 | } |
| 8087 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8088 | #endif /* CONFIG_WNM */ |
| 8089 | |
| 8090 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8091 | static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, |
| 8092 | size_t buflen) |
| 8093 | { |
| 8094 | struct wpa_signal_info si; |
| 8095 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8096 | char *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8097 | |
| 8098 | ret = wpa_drv_signal_poll(wpa_s, &si); |
| 8099 | if (ret) |
| 8100 | return -1; |
| 8101 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8102 | pos = buf; |
| 8103 | end = buf + buflen; |
| 8104 | |
| 8105 | ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8106 | "NOISE=%d\nFREQUENCY=%u\n", |
| 8107 | si.current_signal, si.current_txrate / 1000, |
| 8108 | si.current_noise, si.frequency); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8109 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8110 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8111 | pos += ret; |
| 8112 | |
| 8113 | if (si.chanwidth != CHAN_WIDTH_UNKNOWN) { |
| 8114 | ret = os_snprintf(pos, end - pos, "WIDTH=%s\n", |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8115 | channel_width_to_string(si.chanwidth)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8116 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8117 | return -1; |
| 8118 | pos += ret; |
| 8119 | } |
| 8120 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8121 | if (si.center_frq1 > 0) { |
| 8122 | ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n", |
| 8123 | si.center_frq1); |
| 8124 | if (os_snprintf_error(end - pos, ret)) |
| 8125 | return -1; |
| 8126 | pos += ret; |
| 8127 | } |
| 8128 | |
| 8129 | if (si.center_frq2 > 0) { |
| 8130 | ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n", |
| 8131 | si.center_frq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8132 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8133 | return -1; |
| 8134 | pos += ret; |
| 8135 | } |
| 8136 | |
| 8137 | if (si.avg_signal) { |
| 8138 | ret = os_snprintf(pos, end - pos, |
| 8139 | "AVG_RSSI=%d\n", si.avg_signal); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8140 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8141 | return -1; |
| 8142 | pos += ret; |
| 8143 | } |
| 8144 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 8145 | if (si.avg_beacon_signal) { |
| 8146 | ret = os_snprintf(pos, end - pos, |
| 8147 | "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal); |
| 8148 | if (os_snprintf_error(end - pos, ret)) |
| 8149 | return -1; |
| 8150 | pos += ret; |
| 8151 | } |
| 8152 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8153 | return pos - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8154 | } |
| 8155 | |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 8156 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 8157 | static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s, |
| 8158 | const char *cmd) |
| 8159 | { |
| 8160 | const char *pos; |
| 8161 | int threshold = 0; |
| 8162 | int hysteresis = 0; |
| 8163 | |
| 8164 | if (wpa_s->bgscan && wpa_s->bgscan_priv) { |
| 8165 | wpa_printf(MSG_DEBUG, |
| 8166 | "Reject SIGNAL_MONITOR command - bgscan is active"); |
| 8167 | return -1; |
| 8168 | } |
| 8169 | pos = os_strstr(cmd, "THRESHOLD="); |
| 8170 | if (pos) |
| 8171 | threshold = atoi(pos + 10); |
| 8172 | pos = os_strstr(cmd, "HYSTERESIS="); |
| 8173 | if (pos) |
| 8174 | hysteresis = atoi(pos + 11); |
| 8175 | return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis); |
| 8176 | } |
| 8177 | |
| 8178 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8179 | #ifdef CONFIG_TESTING_OPTIONS |
| 8180 | int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s, |
| 8181 | enum wpa_driver_if_type if_type, |
| 8182 | unsigned int *num, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8183 | struct weighted_pcl *freq_list) |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8184 | { |
| 8185 | char *pos = wpa_s->get_pref_freq_list_override; |
| 8186 | char *end; |
| 8187 | unsigned int count = 0; |
| 8188 | |
| 8189 | /* Override string format: |
| 8190 | * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */ |
| 8191 | |
| 8192 | while (pos) { |
| 8193 | if (atoi(pos) == (int) if_type) |
| 8194 | break; |
| 8195 | pos = os_strchr(pos, ' '); |
| 8196 | if (pos) |
| 8197 | pos++; |
| 8198 | } |
| 8199 | if (!pos) |
| 8200 | return -1; |
| 8201 | pos = os_strchr(pos, ':'); |
| 8202 | if (!pos) |
| 8203 | return -1; |
| 8204 | pos++; |
| 8205 | end = os_strchr(pos, ' '); |
| 8206 | while (pos && (!end || pos < end) && count < *num) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8207 | freq_list[count].freq = atoi(pos); |
| 8208 | freq_list[count++].flag = WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8209 | pos = os_strchr(pos, ','); |
| 8210 | if (pos) |
| 8211 | pos++; |
| 8212 | } |
| 8213 | |
| 8214 | *num = count; |
| 8215 | return 0; |
| 8216 | } |
| 8217 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8218 | |
| 8219 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8220 | static int wpas_ctrl_iface_get_pref_freq_list( |
| 8221 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| 8222 | { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8223 | unsigned int num = 100, i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8224 | int ret; |
| 8225 | enum wpa_driver_if_type iface_type; |
| 8226 | char *pos, *end; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8227 | struct weighted_pcl freq_list[100]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8228 | |
| 8229 | pos = buf; |
| 8230 | end = buf + buflen; |
| 8231 | |
| 8232 | /* buf: "<interface_type>" */ |
| 8233 | if (os_strcmp(cmd, "STATION") == 0) |
| 8234 | iface_type = WPA_IF_STATION; |
| 8235 | else if (os_strcmp(cmd, "AP") == 0) |
| 8236 | iface_type = WPA_IF_AP_BSS; |
| 8237 | else if (os_strcmp(cmd, "P2P_GO") == 0) |
| 8238 | iface_type = WPA_IF_P2P_GO; |
| 8239 | else if (os_strcmp(cmd, "P2P_CLIENT") == 0) |
| 8240 | iface_type = WPA_IF_P2P_CLIENT; |
| 8241 | else if (os_strcmp(cmd, "IBSS") == 0) |
| 8242 | iface_type = WPA_IF_IBSS; |
| 8243 | else if (os_strcmp(cmd, "TDLS") == 0) |
| 8244 | iface_type = WPA_IF_TDLS; |
| 8245 | else |
| 8246 | return -1; |
| 8247 | |
| 8248 | wpa_printf(MSG_DEBUG, |
| 8249 | "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)", |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8250 | iface_type, cmd); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8251 | |
| 8252 | ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list); |
| 8253 | if (ret) |
| 8254 | return -1; |
| 8255 | |
| 8256 | for (i = 0; i < num; i++) { |
| 8257 | ret = os_snprintf(pos, end - pos, "%s%u", |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8258 | i > 0 ? "," : "", freq_list[i].freq); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8259 | if (os_snprintf_error(end - pos, ret)) |
| 8260 | return -1; |
| 8261 | pos += ret; |
| 8262 | } |
| 8263 | |
| 8264 | return pos - buf; |
| 8265 | } |
| 8266 | |
| 8267 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8268 | static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s, |
| 8269 | char *buf, size_t buflen) |
| 8270 | { |
| 8271 | int ret, i; |
| 8272 | char *pos, *end; |
| 8273 | |
| 8274 | ret = os_snprintf(buf, buflen, "%016llX:\n", |
| 8275 | (long long unsigned) wpa_s->drv_flags); |
| 8276 | if (os_snprintf_error(buflen, ret)) |
| 8277 | return -1; |
| 8278 | |
| 8279 | pos = buf + ret; |
| 8280 | end = buf + buflen; |
| 8281 | |
| 8282 | for (i = 0; i < 64; i++) { |
| 8283 | if (wpa_s->drv_flags & (1LLU << i)) { |
| 8284 | ret = os_snprintf(pos, end - pos, "%s\n", |
| 8285 | driver_flag_to_string(1LLU << i)); |
| 8286 | if (os_snprintf_error(end - pos, ret)) |
| 8287 | return -1; |
| 8288 | pos += ret; |
| 8289 | } |
| 8290 | } |
| 8291 | |
| 8292 | return pos - buf; |
| 8293 | } |
| 8294 | |
| 8295 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8296 | static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s, |
| 8297 | char *buf, size_t buflen) |
| 8298 | { |
| 8299 | int ret, i; |
| 8300 | char *pos, *end; |
| 8301 | |
| 8302 | ret = os_snprintf(buf, buflen, "%016llX:\n", |
| 8303 | (long long unsigned) wpa_s->drv_flags2); |
| 8304 | if (os_snprintf_error(buflen, ret)) |
| 8305 | return -1; |
| 8306 | |
| 8307 | pos = buf + ret; |
| 8308 | end = buf + buflen; |
| 8309 | |
| 8310 | for (i = 0; i < 64; i++) { |
| 8311 | if (wpa_s->drv_flags2 & (1LLU << i)) { |
| 8312 | ret = os_snprintf(pos, end - pos, "%s\n", |
| 8313 | driver_flag2_to_string(1LLU << i)); |
| 8314 | if (os_snprintf_error(end - pos, ret)) |
| 8315 | return -1; |
| 8316 | pos += ret; |
| 8317 | } |
| 8318 | } |
| 8319 | |
| 8320 | return pos - buf; |
| 8321 | } |
| 8322 | |
| 8323 | |
Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 8324 | static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf, |
| 8325 | size_t buflen) |
| 8326 | { |
| 8327 | struct hostap_sta_driver_data sta; |
| 8328 | int ret; |
| 8329 | |
| 8330 | ret = wpa_drv_pktcnt_poll(wpa_s, &sta); |
| 8331 | if (ret) |
| 8332 | return -1; |
| 8333 | |
| 8334 | ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n", |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 8335 | sta.tx_packets, sta.tx_retry_failed, sta.rx_packets); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8336 | if (os_snprintf_error(buflen, ret)) |
Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 8337 | return -1; |
| 8338 | return ret; |
| 8339 | } |
| 8340 | |
| 8341 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8342 | #ifdef ANDROID |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 8343 | static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd, |
| 8344 | char *buf, size_t buflen) |
| 8345 | { |
| 8346 | int ret; |
| 8347 | |
| 8348 | ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen); |
Dmitry Shmidt | 9432e12 | 2013-09-12 12:39:30 -0700 | [diff] [blame] | 8349 | if (ret == 0) { |
| 8350 | if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) { |
| 8351 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 8352 | if (p2p) { |
| 8353 | char country[3]; |
| 8354 | country[0] = cmd[8]; |
| 8355 | country[1] = cmd[9]; |
| 8356 | country[2] = 0x04; |
| 8357 | p2p_set_country(p2p, country); |
| 8358 | } |
| 8359 | } |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8360 | ret = os_snprintf(buf, buflen, "%s\n", "OK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8361 | if (os_snprintf_error(buflen, ret)) |
| 8362 | ret = -1; |
Dmitry Shmidt | 9432e12 | 2013-09-12 12:39:30 -0700 | [diff] [blame] | 8363 | } |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 8364 | return ret; |
| 8365 | } |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8366 | #endif /* ANDROID */ |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 8367 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 8368 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8369 | static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd, |
| 8370 | char *buf, size_t buflen) |
| 8371 | { |
| 8372 | int ret; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8373 | char *pos, *temp = NULL; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8374 | u8 *data = NULL; |
| 8375 | unsigned int vendor_id, subcmd; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8376 | enum nested_attr nested_attr_flag = NESTED_ATTR_UNSPECIFIED; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8377 | struct wpabuf *reply; |
| 8378 | size_t data_len = 0; |
| 8379 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8380 | /** |
| 8381 | * cmd: <vendor id> <subcommand id> [<hex formatted data>] |
| 8382 | * [nested=<0|1>] |
| 8383 | */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8384 | vendor_id = strtoul(cmd, &pos, 16); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8385 | if (!isblank((unsigned char) *pos)) |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8386 | return -EINVAL; |
| 8387 | |
| 8388 | subcmd = strtoul(pos, &pos, 10); |
| 8389 | |
| 8390 | if (*pos != '\0') { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8391 | if (!isblank((unsigned char) *pos++)) |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8392 | return -EINVAL; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8393 | |
| 8394 | temp = os_strchr(pos, ' '); |
| 8395 | data_len = temp ? (size_t) (temp - pos) : os_strlen(pos); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8396 | } |
| 8397 | |
| 8398 | if (data_len) { |
| 8399 | data_len /= 2; |
| 8400 | data = os_malloc(data_len); |
| 8401 | if (!data) |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8402 | return -1; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8403 | |
| 8404 | if (hexstr2bin(pos, data, data_len)) { |
| 8405 | wpa_printf(MSG_DEBUG, |
| 8406 | "Vendor command: wrong parameter format"); |
| 8407 | os_free(data); |
| 8408 | return -EINVAL; |
| 8409 | } |
| 8410 | } |
| 8411 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8412 | pos = os_strstr(cmd, "nested="); |
| 8413 | if (pos) |
| 8414 | nested_attr_flag = atoi(pos + 7) ? NESTED_ATTR_USED : |
| 8415 | NESTED_ATTR_NOT_USED; |
| 8416 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8417 | reply = wpabuf_alloc((buflen - 1) / 2); |
| 8418 | if (!reply) { |
| 8419 | os_free(data); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8420 | return -1; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8421 | } |
| 8422 | |
| 8423 | ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8424 | nested_attr_flag, reply); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8425 | |
| 8426 | if (ret == 0) |
| 8427 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply), |
| 8428 | wpabuf_len(reply)); |
| 8429 | |
| 8430 | wpabuf_free(reply); |
| 8431 | os_free(data); |
| 8432 | |
| 8433 | return ret; |
| 8434 | } |
| 8435 | |
| 8436 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8437 | static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s) |
| 8438 | { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8439 | #ifdef CONFIG_P2P |
| 8440 | struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ? |
| 8441 | wpa_s->global->p2p_init_wpa_s : wpa_s; |
| 8442 | #endif /* CONFIG_P2P */ |
| 8443 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8444 | wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state"); |
| 8445 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 8446 | if (wpas_abort_ongoing_scan(wpa_s) == 0) |
| 8447 | wpa_s->ignore_post_flush_scan_res = 1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8448 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8449 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 8450 | /* |
| 8451 | * Avoid possible auto connect re-connection on getting |
| 8452 | * disconnected due to state flush. |
| 8453 | */ |
| 8454 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 8455 | } |
| 8456 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8457 | #ifdef CONFIG_P2P |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8458 | wpas_p2p_group_remove(p2p_wpa_s, "*"); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8459 | wpas_p2p_cancel(p2p_wpa_s); |
| 8460 | p2p_ctrl_flush(p2p_wpa_s); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8461 | wpas_p2p_service_flush(p2p_wpa_s); |
| 8462 | p2p_wpa_s->global->p2p_disabled = 0; |
| 8463 | p2p_wpa_s->global->p2p_per_sta_psk = 0; |
| 8464 | p2p_wpa_s->conf->num_sec_device_types = 0; |
| 8465 | p2p_wpa_s->p2p_disable_ip_addr_req = 0; |
| 8466 | os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range); |
| 8467 | p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8468 | p2p_wpa_s->global->p2p_go_avoid_freq.num = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8469 | p2p_wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8470 | p2p_wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8471 | #endif /* CONFIG_P2P */ |
| 8472 | |
| 8473 | #ifdef CONFIG_WPS_TESTING |
| 8474 | wps_version_number = 0x20; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8475 | wps_testing_stub_cred = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 8476 | wps_corrupt_pkhash = 0; |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8477 | wps_force_auth_types_in_use = 0; |
| 8478 | wps_force_encr_types_in_use = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8479 | #endif /* CONFIG_WPS_TESTING */ |
| 8480 | #ifdef CONFIG_WPS |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8481 | wpa_s->wps_fragment_size = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8482 | wpas_wps_cancel(wpa_s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8483 | wps_registrar_flush(wpa_s->wps->registrar); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8484 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8485 | wpa_s->after_wps = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8486 | wpa_s->known_wps_freq = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8487 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8488 | #ifdef CONFIG_DPP |
| 8489 | wpas_dpp_deinit(wpa_s); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8490 | wpa_s->dpp_init_max_tries = 0; |
| 8491 | wpa_s->dpp_init_retry_time = 0; |
| 8492 | wpa_s->dpp_resp_wait_time = 0; |
| 8493 | wpa_s->dpp_resp_max_tries = 0; |
| 8494 | wpa_s->dpp_resp_retry_time = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8495 | #ifdef CONFIG_DPP2 |
| 8496 | wpas_dpp_chirp_stop(wpa_s); |
| 8497 | wpa_s->dpp_pfs_fallback = 0; |
| 8498 | #endif /* CONFIG_DPP2 */ |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 8499 | #ifdef CONFIG_DPP3 |
| 8500 | { |
| 8501 | int i; |
| 8502 | |
| 8503 | for (i = 0; i < DPP_PB_INFO_COUNT; i++) { |
| 8504 | struct dpp_pb_info *info; |
| 8505 | |
| 8506 | info = &wpa_s->dpp_pb[i]; |
| 8507 | info->rx_time.sec = 0; |
| 8508 | info->rx_time.usec = 0; |
| 8509 | } |
| 8510 | } |
| 8511 | #endif /* CONFIG_DPP3 */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8512 | #ifdef CONFIG_TESTING_OPTIONS |
| 8513 | os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN); |
| 8514 | os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN); |
| 8515 | dpp_pkex_ephemeral_key_override_len = 0; |
| 8516 | dpp_protocol_key_override_len = 0; |
| 8517 | dpp_nonce_override_len = 0; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8518 | #ifdef CONFIG_DPP3 |
| 8519 | dpp_version_override = 3; |
| 8520 | #elif defined(CONFIG_DPP2) |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 8521 | dpp_version_override = 2; |
| 8522 | #else /* CONFIG_DPP2 */ |
| 8523 | dpp_version_override = 1; |
| 8524 | #endif /* CONFIG_DPP2 */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8525 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8526 | #endif /* CONFIG_DPP */ |
| 8527 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8528 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8529 | #ifdef CONFIG_TDLS_TESTING |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8530 | tdls_testing = 0; |
| 8531 | #endif /* CONFIG_TDLS_TESTING */ |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8532 | wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL); |
| 8533 | wpa_tdls_enable(wpa_s->wpa, 1); |
| 8534 | #endif /* CONFIG_TDLS */ |
| 8535 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8536 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL); |
| 8537 | wpa_supplicant_stop_countermeasures(wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8538 | wpa_s->last_michael_mic_error.sec = 0; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8539 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8540 | wpa_s->no_keep_alive = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 8541 | wpa_s->own_disconnect_req = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8542 | wpa_s->own_reconnect_req = 0; |
| 8543 | wpa_s->deny_ptk0_rekey = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8544 | |
| 8545 | os_free(wpa_s->disallow_aps_bssid); |
| 8546 | wpa_s->disallow_aps_bssid = NULL; |
| 8547 | wpa_s->disallow_aps_bssid_count = 0; |
| 8548 | os_free(wpa_s->disallow_aps_ssid); |
| 8549 | wpa_s->disallow_aps_ssid = NULL; |
| 8550 | wpa_s->disallow_aps_ssid_count = 0; |
| 8551 | |
| 8552 | wpa_s->set_sta_uapsd = 0; |
| 8553 | wpa_s->sta_uapsd = 0; |
| 8554 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8555 | wpa_s->consecutive_conn_failures = 0; |
| 8556 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8557 | wpa_drv_radio_disable(wpa_s, 0); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8558 | wpa_bssid_ignore_clear(wpa_s); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8559 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all"); |
| 8560 | wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all"); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 8561 | wpa_config_flush_blobs(wpa_s->conf); |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 8562 | wpa_s->conf->auto_interworking = 0; |
| 8563 | wpa_s->conf->okc = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8564 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8565 | ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8566 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
| 8567 | rsn_preauth_deinit(wpa_s->wpa); |
| 8568 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8569 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200); |
| 8570 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70); |
| 8571 | wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 8572 | eapol_sm_notify_logoff(wpa_s->eapol, false); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8573 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 8574 | radio_remove_works(wpa_s, NULL, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8575 | wpa_s->ext_work_in_progress = 0; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8576 | |
| 8577 | wpa_s->next_ssid = NULL; |
| 8578 | |
| 8579 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8580 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8581 | hs20_cancel_fetch_osu(wpa_s); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 8582 | hs20_del_icon(wpa_s, NULL, NULL); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8583 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8584 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 8585 | |
| 8586 | wpa_s->ext_mgmt_frame_handling = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8587 | wpa_s->ext_eapol_frame_io = 0; |
| 8588 | #ifdef CONFIG_TESTING_OPTIONS |
| 8589 | wpa_s->extra_roc_dur = 0; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8590 | wpa_s->test_failure = WPAS_TEST_FAILURE_NONE; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8591 | wpa_s->p2p_go_csa_on_inv = 0; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8592 | wpa_s->ignore_auth_resp = 0; |
| 8593 | wpa_s->ignore_assoc_disallow = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8594 | wpa_s->disable_sa_query = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8595 | wpa_s->testing_resend_assoc = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8596 | wpa_s->ignore_sae_h2e_only = 0; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8597 | wpa_s->ft_rsnxe_used = 0; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8598 | wpa_s->reject_btm_req_reason = 0; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8599 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8600 | os_free(wpa_s->get_pref_freq_list_override); |
| 8601 | wpa_s->get_pref_freq_list_override = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8602 | wpabuf_free(wpa_s->sae_commit_override); |
| 8603 | wpa_s->sae_commit_override = NULL; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8604 | os_free(wpa_s->extra_sae_rejected_groups); |
| 8605 | wpa_s->extra_sae_rejected_groups = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8606 | wpabuf_free(wpa_s->rsne_override_eapol); |
| 8607 | wpa_s->rsne_override_eapol = NULL; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8608 | wpabuf_free(wpa_s->rsnxe_override_assoc); |
| 8609 | wpa_s->rsnxe_override_assoc = NULL; |
| 8610 | wpabuf_free(wpa_s->rsnxe_override_eapol); |
| 8611 | wpa_s->rsnxe_override_eapol = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8612 | wpas_clear_driver_signal_override(wpa_s); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8613 | wpa_s->disable_scs_support = 0; |
| 8614 | wpa_s->disable_mscs_support = 0; |
| 8615 | wpa_s->enable_dscp_policy_capa = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8616 | wpa_s->oci_freq_override_eapol = 0; |
| 8617 | wpa_s->oci_freq_override_saquery_req = 0; |
| 8618 | wpa_s->oci_freq_override_saquery_resp = 0; |
| 8619 | wpa_s->oci_freq_override_eapol_g2 = 0; |
| 8620 | wpa_s->oci_freq_override_ft_assoc = 0; |
| 8621 | wpa_s->oci_freq_override_fils_assoc = 0; |
| 8622 | wpa_s->oci_freq_override_wnm_sleep = 0; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 8623 | wpa_s->disable_eapol_g2_tx = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8624 | #ifdef CONFIG_DPP |
| 8625 | os_free(wpa_s->dpp_config_obj_override); |
| 8626 | wpa_s->dpp_config_obj_override = NULL; |
| 8627 | os_free(wpa_s->dpp_discovery_override); |
| 8628 | wpa_s->dpp_discovery_override = NULL; |
| 8629 | os_free(wpa_s->dpp_groups_override); |
| 8630 | wpa_s->dpp_groups_override = NULL; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8631 | wpa_s->dpp_ignore_netaccesskey_mismatch = 0; |
| 8632 | wpa_s->dpp_discard_public_action = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8633 | dpp_test = DPP_TEST_DISABLED; |
| 8634 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8635 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8636 | |
| 8637 | wpa_s->disconnected = 0; |
| 8638 | os_free(wpa_s->next_scan_freqs); |
| 8639 | wpa_s->next_scan_freqs = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8640 | os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN); |
| 8641 | wpa_s->next_scan_bssid_wildcard_ssid = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8642 | os_free(wpa_s->select_network_scan_freqs); |
| 8643 | wpa_s->select_network_scan_freqs = NULL; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8644 | os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data)); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8645 | |
| 8646 | wpa_bss_flush(wpa_s); |
| 8647 | if (!dl_list_empty(&wpa_s->bss)) { |
| 8648 | wpa_printf(MSG_DEBUG, |
| 8649 | "BSS table not empty after flush: %u entries, current_bss=%p bssid=" |
| 8650 | MACSTR " pending_bssid=" MACSTR, |
| 8651 | dl_list_len(&wpa_s->bss), wpa_s->current_bss, |
| 8652 | MAC2STR(wpa_s->bssid), |
| 8653 | MAC2STR(wpa_s->pending_bssid)); |
| 8654 | } |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8655 | |
| 8656 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
Dmitry Shmidt | b70d0bb | 2015-11-16 10:43:06 -0800 | [diff] [blame] | 8657 | wpa_s->wnmsleep_used = 0; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8658 | |
| 8659 | #ifdef CONFIG_SME |
| 8660 | wpa_s->sme.last_unprot_disconnect.sec = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8661 | wpa_s->sme.auth_alg = 0; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8662 | #endif /* CONFIG_SME */ |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8663 | |
| 8664 | wpabuf_free(wpa_s->ric_ies); |
| 8665 | wpa_s->ric_ies = NULL; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8666 | |
| 8667 | wpa_supplicant_update_channel_list(wpa_s, NULL); |
| 8668 | |
| 8669 | free_bss_tmp_disallowed(wpa_s); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8670 | |
| 8671 | os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8672 | |
| 8673 | #ifdef CONFIG_PASN |
| 8674 | wpas_pasn_auth_stop(wpa_s); |
| 8675 | #endif /* CONFIG_PASN */ |
| 8676 | |
| 8677 | if (wpa_s->mac_addr_changed && wpa_s->conf->mac_addr == 0) |
| 8678 | wpas_restore_permanent_mac_addr(wpa_s); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 8679 | |
| 8680 | wpa_s->conf->ignore_old_scan_res = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8681 | } |
| 8682 | |
| 8683 | |
| 8684 | static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s, |
| 8685 | char *buf, size_t buflen) |
| 8686 | { |
| 8687 | struct wpa_radio_work *work; |
| 8688 | char *pos, *end; |
| 8689 | struct os_reltime now, diff; |
| 8690 | |
| 8691 | pos = buf; |
| 8692 | end = buf + buflen; |
| 8693 | |
| 8694 | os_get_reltime(&now); |
| 8695 | |
| 8696 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) |
| 8697 | { |
| 8698 | int ret; |
| 8699 | |
| 8700 | os_reltime_sub(&now, &work->time, &diff); |
| 8701 | ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n", |
| 8702 | work->type, work->wpa_s->ifname, work->freq, |
| 8703 | work->started, diff.sec, diff.usec); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8704 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8705 | break; |
| 8706 | pos += ret; |
| 8707 | } |
| 8708 | |
| 8709 | return pos - buf; |
| 8710 | } |
| 8711 | |
| 8712 | |
| 8713 | static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx) |
| 8714 | { |
| 8715 | struct wpa_radio_work *work = eloop_ctx; |
| 8716 | struct wpa_external_work *ework = work->ctx; |
| 8717 | |
| 8718 | wpa_dbg(work->wpa_s, MSG_DEBUG, |
| 8719 | "Timing out external radio work %u (%s)", |
| 8720 | ework->id, work->type); |
| 8721 | 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] | 8722 | work->wpa_s->ext_work_in_progress = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8723 | radio_work_done(work); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8724 | os_free(ework); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8725 | } |
| 8726 | |
| 8727 | |
| 8728 | static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit) |
| 8729 | { |
| 8730 | struct wpa_external_work *ework = work->ctx; |
| 8731 | |
| 8732 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 8733 | if (work->started) |
| 8734 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, |
| 8735 | work, NULL); |
| 8736 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8737 | /* |
| 8738 | * work->type points to a buffer in ework, so need to replace |
| 8739 | * that here with a fixed string to avoid use of freed memory |
| 8740 | * in debug prints. |
| 8741 | */ |
| 8742 | work->type = "freed-ext-work"; |
| 8743 | work->ctx = NULL; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8744 | os_free(ework); |
| 8745 | return; |
| 8746 | } |
| 8747 | |
| 8748 | wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)", |
| 8749 | ework->id, ework->type); |
| 8750 | 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] | 8751 | work->wpa_s->ext_work_in_progress = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8752 | if (!ework->timeout) |
| 8753 | ework->timeout = 10; |
| 8754 | eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout, |
| 8755 | work, NULL); |
| 8756 | } |
| 8757 | |
| 8758 | |
| 8759 | static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd, |
| 8760 | char *buf, size_t buflen) |
| 8761 | { |
| 8762 | struct wpa_external_work *ework; |
| 8763 | char *pos, *pos2; |
| 8764 | size_t type_len; |
| 8765 | int ret; |
| 8766 | unsigned int freq = 0; |
| 8767 | |
| 8768 | /* format: <name> [freq=<MHz>] [timeout=<seconds>] */ |
| 8769 | |
| 8770 | ework = os_zalloc(sizeof(*ework)); |
| 8771 | if (ework == NULL) |
| 8772 | return -1; |
| 8773 | |
| 8774 | pos = os_strchr(cmd, ' '); |
| 8775 | if (pos) { |
| 8776 | type_len = pos - cmd; |
| 8777 | pos++; |
| 8778 | |
| 8779 | pos2 = os_strstr(pos, "freq="); |
| 8780 | if (pos2) |
| 8781 | freq = atoi(pos2 + 5); |
| 8782 | |
| 8783 | pos2 = os_strstr(pos, "timeout="); |
| 8784 | if (pos2) |
| 8785 | ework->timeout = atoi(pos2 + 8); |
| 8786 | } else { |
| 8787 | type_len = os_strlen(cmd); |
| 8788 | } |
| 8789 | if (4 + type_len >= sizeof(ework->type)) |
| 8790 | type_len = sizeof(ework->type) - 4 - 1; |
| 8791 | os_strlcpy(ework->type, "ext:", sizeof(ework->type)); |
| 8792 | os_memcpy(ework->type + 4, cmd, type_len); |
| 8793 | ework->type[4 + type_len] = '\0'; |
| 8794 | |
| 8795 | wpa_s->ext_work_id++; |
| 8796 | if (wpa_s->ext_work_id == 0) |
| 8797 | wpa_s->ext_work_id++; |
| 8798 | ework->id = wpa_s->ext_work_id; |
| 8799 | |
| 8800 | if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb, |
| 8801 | ework) < 0) { |
| 8802 | os_free(ework); |
| 8803 | return -1; |
| 8804 | } |
| 8805 | |
| 8806 | ret = os_snprintf(buf, buflen, "%u", ework->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8807 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8808 | return -1; |
| 8809 | return ret; |
| 8810 | } |
| 8811 | |
| 8812 | |
| 8813 | static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd) |
| 8814 | { |
| 8815 | struct wpa_radio_work *work; |
| 8816 | unsigned int id = atoi(cmd); |
| 8817 | |
| 8818 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) |
| 8819 | { |
| 8820 | struct wpa_external_work *ework; |
| 8821 | |
| 8822 | if (os_strncmp(work->type, "ext:", 4) != 0) |
| 8823 | continue; |
| 8824 | ework = work->ctx; |
| 8825 | if (id && ework->id != id) |
| 8826 | continue; |
| 8827 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8828 | "Completed external radio work %u (%s)", |
| 8829 | ework->id, ework->type); |
| 8830 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8831 | wpa_s->ext_work_in_progress = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8832 | radio_work_done(work); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 8833 | os_free(ework); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8834 | return 3; /* "OK\n" */ |
| 8835 | } |
| 8836 | |
| 8837 | return -1; |
| 8838 | } |
| 8839 | |
| 8840 | |
| 8841 | static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd, |
| 8842 | char *buf, size_t buflen) |
| 8843 | { |
| 8844 | if (os_strcmp(cmd, "show") == 0) |
| 8845 | return wpas_ctrl_radio_work_show(wpa_s, buf, buflen); |
| 8846 | if (os_strncmp(cmd, "add ", 4) == 0) |
| 8847 | return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen); |
| 8848 | if (os_strncmp(cmd, "done ", 5) == 0) |
| 8849 | return wpas_ctrl_radio_work_done(wpa_s, cmd + 4); |
| 8850 | return -1; |
| 8851 | } |
| 8852 | |
| 8853 | |
| 8854 | void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s) |
| 8855 | { |
| 8856 | struct wpa_radio_work *work, *tmp; |
| 8857 | |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 8858 | if (!wpa_s || !wpa_s->radio) |
| 8859 | return; |
| 8860 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8861 | dl_list_for_each_safe(work, tmp, &wpa_s->radio->work, |
| 8862 | struct wpa_radio_work, list) { |
| 8863 | struct wpa_external_work *ework; |
| 8864 | |
| 8865 | if (os_strncmp(work->type, "ext:", 4) != 0) |
| 8866 | continue; |
| 8867 | ework = work->ctx; |
| 8868 | wpa_dbg(wpa_s, MSG_DEBUG, |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 8869 | "Flushing%s external radio work %u (%s)", |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8870 | work->started ? " started" : "", ework->id, |
| 8871 | ework->type); |
| 8872 | if (work->started) |
| 8873 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, |
| 8874 | work, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8875 | radio_work_done(work); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8876 | os_free(ework); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8877 | } |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8878 | } |
| 8879 | |
| 8880 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8881 | static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx) |
| 8882 | { |
| 8883 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 8884 | eapol_sm_notify_ctrl_response(wpa_s->eapol); |
| 8885 | } |
| 8886 | |
| 8887 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8888 | static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value, |
| 8889 | unsigned int *scan_id_count, int scan_id[]) |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8890 | { |
| 8891 | const char *pos = value; |
| 8892 | |
| 8893 | while (pos) { |
| 8894 | if (*pos == ' ' || *pos == '\0') |
| 8895 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8896 | if (*scan_id_count == MAX_SCAN_ID) |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8897 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8898 | scan_id[(*scan_id_count)++] = atoi(pos); |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8899 | pos = os_strchr(pos, ','); |
| 8900 | if (pos) |
| 8901 | pos++; |
| 8902 | } |
| 8903 | |
| 8904 | return 0; |
| 8905 | } |
| 8906 | |
| 8907 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8908 | static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params, |
| 8909 | char *reply, int reply_size, int *reply_len) |
| 8910 | { |
| 8911 | char *pos; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8912 | unsigned int manual_scan_passive = 0; |
| 8913 | unsigned int manual_scan_use_id = 0; |
| 8914 | unsigned int manual_scan_only_new = 0; |
| 8915 | unsigned int scan_only = 0; |
| 8916 | unsigned int scan_id_count = 0; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8917 | unsigned int manual_non_coloc_6ghz = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8918 | int scan_id[MAX_SCAN_ID]; |
| 8919 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, |
| 8920 | struct wpa_scan_results *scan_res); |
| 8921 | int *manual_scan_freqs = NULL; |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 8922 | struct wpa_ssid_value *ssid = NULL, *ns; |
| 8923 | unsigned int ssid_count = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8924 | |
| 8925 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 8926 | *reply_len = -1; |
| 8927 | return; |
| 8928 | } |
| 8929 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8930 | if (radio_work_pending(wpa_s, "scan")) { |
| 8931 | wpa_printf(MSG_DEBUG, |
| 8932 | "Pending scan scheduled - reject new request"); |
| 8933 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); |
| 8934 | return; |
| 8935 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8936 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8937 | #ifdef CONFIG_INTERWORKING |
| 8938 | if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) { |
| 8939 | wpa_printf(MSG_DEBUG, |
| 8940 | "Interworking select in progress - reject new scan"); |
| 8941 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); |
| 8942 | return; |
| 8943 | } |
| 8944 | #endif /* CONFIG_INTERWORKING */ |
| 8945 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8946 | if (params) { |
| 8947 | if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8948 | scan_only = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8949 | |
| 8950 | pos = os_strstr(params, "freq="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8951 | if (pos) { |
| 8952 | manual_scan_freqs = freq_range_to_channel_list(wpa_s, |
| 8953 | pos + 5); |
| 8954 | if (manual_scan_freqs == NULL) { |
| 8955 | *reply_len = -1; |
| 8956 | goto done; |
| 8957 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8958 | } |
| 8959 | |
| 8960 | pos = os_strstr(params, "passive="); |
| 8961 | if (pos) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8962 | manual_scan_passive = !!atoi(pos + 8); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8963 | |
| 8964 | pos = os_strstr(params, "use_id="); |
| 8965 | if (pos) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8966 | manual_scan_use_id = atoi(pos + 7); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8967 | |
| 8968 | pos = os_strstr(params, "only_new=1"); |
| 8969 | if (pos) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8970 | manual_scan_only_new = 1; |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8971 | |
| 8972 | pos = os_strstr(params, "scan_id="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8973 | if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count, |
| 8974 | scan_id) < 0) { |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8975 | *reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8976 | goto done; |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8977 | } |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 8978 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8979 | pos = os_strstr(params, "bssid="); |
| 8980 | if (pos) { |
| 8981 | u8 bssid[ETH_ALEN]; |
| 8982 | |
| 8983 | pos += 6; |
| 8984 | if (hwaddr_aton(pos, bssid)) { |
| 8985 | wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos); |
| 8986 | *reply_len = -1; |
| 8987 | goto done; |
| 8988 | } |
| 8989 | os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8990 | |
| 8991 | wpa_s->next_scan_bssid_wildcard_ssid = |
| 8992 | os_strstr(params, "wildcard_ssid=1") != NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8993 | } |
| 8994 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8995 | pos = os_strstr(params, "non_coloc_6ghz="); |
| 8996 | if (pos) |
| 8997 | manual_non_coloc_6ghz = !!atoi(pos + 15); |
| 8998 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 8999 | pos = params; |
| 9000 | while (pos && *pos != '\0') { |
| 9001 | if (os_strncmp(pos, "ssid ", 5) == 0) { |
| 9002 | char *end; |
| 9003 | |
| 9004 | pos += 5; |
| 9005 | end = pos; |
| 9006 | while (*end) { |
| 9007 | if (*end == '\0' || *end == ' ') |
| 9008 | break; |
| 9009 | end++; |
| 9010 | } |
| 9011 | |
| 9012 | ns = os_realloc_array( |
| 9013 | ssid, ssid_count + 1, |
| 9014 | sizeof(struct wpa_ssid_value)); |
| 9015 | if (ns == NULL) { |
| 9016 | *reply_len = -1; |
| 9017 | goto done; |
| 9018 | } |
| 9019 | ssid = ns; |
| 9020 | |
| 9021 | if ((end - pos) & 0x01 || |
| 9022 | end - pos > 2 * SSID_MAX_LEN || |
| 9023 | hexstr2bin(pos, ssid[ssid_count].ssid, |
| 9024 | (end - pos) / 2) < 0) { |
| 9025 | wpa_printf(MSG_DEBUG, |
| 9026 | "Invalid SSID value '%s'", |
| 9027 | pos); |
| 9028 | *reply_len = -1; |
| 9029 | goto done; |
| 9030 | } |
| 9031 | ssid[ssid_count].ssid_len = (end - pos) / 2; |
| 9032 | wpa_hexdump_ascii(MSG_DEBUG, "scan SSID", |
| 9033 | ssid[ssid_count].ssid, |
| 9034 | ssid[ssid_count].ssid_len); |
| 9035 | ssid_count++; |
| 9036 | pos = end; |
| 9037 | } |
| 9038 | |
| 9039 | pos = os_strchr(pos, ' '); |
| 9040 | if (pos) |
| 9041 | pos++; |
| 9042 | } |
| 9043 | } |
| 9044 | |
| 9045 | wpa_s->num_ssids_from_scan_req = ssid_count; |
| 9046 | os_free(wpa_s->ssids_from_scan_req); |
| 9047 | if (ssid_count) { |
| 9048 | wpa_s->ssids_from_scan_req = ssid; |
| 9049 | ssid = NULL; |
| 9050 | } else { |
| 9051 | wpa_s->ssids_from_scan_req = NULL; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9052 | } |
| 9053 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9054 | if (scan_only) |
| 9055 | scan_res_handler = scan_only_handler; |
| 9056 | else if (wpa_s->scan_res_handler == scan_only_handler) |
| 9057 | scan_res_handler = NULL; |
| 9058 | else |
| 9059 | scan_res_handler = wpa_s->scan_res_handler; |
| 9060 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9061 | if (!wpa_s->sched_scanning && !wpa_s->scanning && |
| 9062 | ((wpa_s->wpa_state <= WPA_SCANNING) || |
| 9063 | (wpa_s->wpa_state == WPA_COMPLETED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9064 | wpa_s->manual_scan_passive = manual_scan_passive; |
| 9065 | wpa_s->manual_scan_use_id = manual_scan_use_id; |
| 9066 | wpa_s->manual_scan_only_new = manual_scan_only_new; |
| 9067 | wpa_s->scan_id_count = scan_id_count; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9068 | wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9069 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); |
| 9070 | wpa_s->scan_res_handler = scan_res_handler; |
| 9071 | os_free(wpa_s->manual_scan_freqs); |
| 9072 | wpa_s->manual_scan_freqs = manual_scan_freqs; |
| 9073 | manual_scan_freqs = NULL; |
| 9074 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9075 | wpa_s->normal_scans = 0; |
| 9076 | wpa_s->scan_req = MANUAL_SCAN_REQ; |
| 9077 | wpa_s->after_wps = 0; |
| 9078 | wpa_s->known_wps_freq = 0; |
| 9079 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 9080 | if (wpa_s->manual_scan_use_id) { |
| 9081 | wpa_s->manual_scan_id++; |
| 9082 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", |
| 9083 | wpa_s->manual_scan_id); |
| 9084 | *reply_len = os_snprintf(reply, reply_size, "%u\n", |
| 9085 | wpa_s->manual_scan_id); |
| 9086 | } |
| 9087 | } else if (wpa_s->sched_scanning) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9088 | wpa_s->manual_scan_passive = manual_scan_passive; |
| 9089 | wpa_s->manual_scan_use_id = manual_scan_use_id; |
| 9090 | wpa_s->manual_scan_only_new = manual_scan_only_new; |
| 9091 | wpa_s->scan_id_count = scan_id_count; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9092 | wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9093 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); |
| 9094 | wpa_s->scan_res_handler = scan_res_handler; |
| 9095 | os_free(wpa_s->manual_scan_freqs); |
| 9096 | wpa_s->manual_scan_freqs = manual_scan_freqs; |
| 9097 | manual_scan_freqs = NULL; |
| 9098 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9099 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed"); |
| 9100 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 9101 | wpa_s->scan_req = MANUAL_SCAN_REQ; |
| 9102 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 9103 | if (wpa_s->manual_scan_use_id) { |
| 9104 | wpa_s->manual_scan_id++; |
| 9105 | *reply_len = os_snprintf(reply, reply_size, "%u\n", |
| 9106 | wpa_s->manual_scan_id); |
| 9107 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", |
| 9108 | wpa_s->manual_scan_id); |
| 9109 | } |
| 9110 | } else { |
| 9111 | wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request"); |
| 9112 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); |
| 9113 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9114 | |
| 9115 | done: |
| 9116 | os_free(manual_scan_freqs); |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 9117 | os_free(ssid); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9118 | } |
| 9119 | |
| 9120 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 9121 | #ifdef CONFIG_TESTING_OPTIONS |
| 9122 | |
| 9123 | static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s, |
| 9124 | unsigned int freq, const u8 *dst, |
| 9125 | const u8 *src, const u8 *bssid, |
| 9126 | const u8 *data, size_t data_len, |
| 9127 | enum offchannel_send_action_result |
| 9128 | result) |
| 9129 | { |
| 9130 | wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR |
| 9131 | " src=" MACSTR " bssid=" MACSTR " result=%s", |
| 9132 | freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid), |
| 9133 | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? |
| 9134 | "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? |
| 9135 | "NO_ACK" : "FAILED")); |
| 9136 | } |
| 9137 | |
| 9138 | |
| 9139 | static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd) |
| 9140 | { |
| 9141 | char *pos, *param; |
| 9142 | size_t len; |
| 9143 | u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN]; |
| 9144 | int res, used; |
| 9145 | int freq = 0, no_cck = 0, wait_time = 0; |
| 9146 | |
| 9147 | /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1] |
| 9148 | * <action=Action frame payload> */ |
| 9149 | |
| 9150 | wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd); |
| 9151 | |
| 9152 | pos = cmd; |
| 9153 | used = hwaddr_aton2(pos, da); |
| 9154 | if (used < 0) |
| 9155 | return -1; |
| 9156 | pos += used; |
| 9157 | while (*pos == ' ') |
| 9158 | pos++; |
| 9159 | used = hwaddr_aton2(pos, bssid); |
| 9160 | if (used < 0) |
| 9161 | return -1; |
| 9162 | pos += used; |
| 9163 | |
| 9164 | param = os_strstr(pos, " freq="); |
| 9165 | if (param) { |
| 9166 | param += 6; |
| 9167 | freq = atoi(param); |
| 9168 | } |
| 9169 | |
| 9170 | param = os_strstr(pos, " no_cck="); |
| 9171 | if (param) { |
| 9172 | param += 8; |
| 9173 | no_cck = atoi(param); |
| 9174 | } |
| 9175 | |
| 9176 | param = os_strstr(pos, " wait_time="); |
| 9177 | if (param) { |
| 9178 | param += 11; |
| 9179 | wait_time = atoi(param); |
| 9180 | } |
| 9181 | |
| 9182 | param = os_strstr(pos, " action="); |
| 9183 | if (param == NULL) |
| 9184 | return -1; |
| 9185 | param += 8; |
| 9186 | |
| 9187 | len = os_strlen(param); |
| 9188 | if (len & 1) |
| 9189 | return -1; |
| 9190 | len /= 2; |
| 9191 | |
| 9192 | buf = os_malloc(len); |
| 9193 | if (buf == NULL) |
| 9194 | return -1; |
| 9195 | |
| 9196 | if (hexstr2bin(param, buf, len) < 0) { |
| 9197 | os_free(buf); |
| 9198 | return -1; |
| 9199 | } |
| 9200 | |
| 9201 | res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid, |
| 9202 | buf, len, wait_time, |
| 9203 | wpas_ctrl_iface_mgmt_tx_cb, no_cck); |
| 9204 | os_free(buf); |
| 9205 | return res; |
| 9206 | } |
| 9207 | |
| 9208 | |
| 9209 | static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s) |
| 9210 | { |
| 9211 | wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting"); |
| 9212 | offchannel_send_action_done(wpa_s); |
| 9213 | } |
| 9214 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 9215 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9216 | static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s, |
| 9217 | char *cmd) |
| 9218 | { |
| 9219 | char *pos, *param; |
| 9220 | size_t len; |
| 9221 | u8 *buf; |
| 9222 | int freq = 0, datarate = 0, ssi_signal = 0; |
| 9223 | union wpa_event_data event; |
| 9224 | |
| 9225 | if (!wpa_s->ext_mgmt_frame_handling) |
| 9226 | return -1; |
| 9227 | |
| 9228 | /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */ |
| 9229 | |
| 9230 | wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd); |
| 9231 | |
| 9232 | pos = cmd; |
| 9233 | param = os_strstr(pos, "freq="); |
| 9234 | if (param) { |
| 9235 | param += 5; |
| 9236 | freq = atoi(param); |
| 9237 | } |
| 9238 | |
| 9239 | param = os_strstr(pos, " datarate="); |
| 9240 | if (param) { |
| 9241 | param += 10; |
| 9242 | datarate = atoi(param); |
| 9243 | } |
| 9244 | |
| 9245 | param = os_strstr(pos, " ssi_signal="); |
| 9246 | if (param) { |
| 9247 | param += 12; |
| 9248 | ssi_signal = atoi(param); |
| 9249 | } |
| 9250 | |
| 9251 | param = os_strstr(pos, " frame="); |
| 9252 | if (param == NULL) |
| 9253 | return -1; |
| 9254 | param += 7; |
| 9255 | |
| 9256 | len = os_strlen(param); |
| 9257 | if (len & 1) |
| 9258 | return -1; |
| 9259 | len /= 2; |
| 9260 | |
| 9261 | buf = os_malloc(len); |
| 9262 | if (buf == NULL) |
| 9263 | return -1; |
| 9264 | |
| 9265 | if (hexstr2bin(param, buf, len) < 0) { |
| 9266 | os_free(buf); |
| 9267 | return -1; |
| 9268 | } |
| 9269 | |
| 9270 | os_memset(&event, 0, sizeof(event)); |
| 9271 | event.rx_mgmt.freq = freq; |
| 9272 | event.rx_mgmt.frame = buf; |
| 9273 | event.rx_mgmt.frame_len = len; |
| 9274 | event.rx_mgmt.ssi_signal = ssi_signal; |
| 9275 | event.rx_mgmt.datarate = datarate; |
| 9276 | wpa_s->ext_mgmt_frame_handling = 0; |
| 9277 | wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event); |
| 9278 | wpa_s->ext_mgmt_frame_handling = 1; |
| 9279 | |
| 9280 | os_free(buf); |
| 9281 | |
| 9282 | return 0; |
| 9283 | } |
| 9284 | |
| 9285 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9286 | static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s, |
| 9287 | char *param) |
| 9288 | { |
| 9289 | struct wpa_scan_res *res; |
| 9290 | struct os_reltime now; |
| 9291 | char *pos, *end; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9292 | int ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9293 | |
| 9294 | if (!param) |
| 9295 | return -1; |
| 9296 | |
| 9297 | if (os_strcmp(param, "START") == 0) { |
| 9298 | wpa_bss_update_start(wpa_s); |
| 9299 | return 0; |
| 9300 | } |
| 9301 | |
| 9302 | if (os_strcmp(param, "END") == 0) { |
| 9303 | wpa_bss_update_end(wpa_s, NULL, 1); |
| 9304 | return 0; |
| 9305 | } |
| 9306 | |
| 9307 | if (os_strncmp(param, "BSS ", 4) != 0) |
| 9308 | return -1; |
| 9309 | param += 3; |
| 9310 | |
| 9311 | res = os_zalloc(sizeof(*res) + os_strlen(param) / 2); |
| 9312 | if (!res) |
| 9313 | return -1; |
| 9314 | |
| 9315 | pos = os_strstr(param, " flags="); |
| 9316 | if (pos) |
| 9317 | res->flags = strtol(pos + 7, NULL, 16); |
| 9318 | |
| 9319 | pos = os_strstr(param, " bssid="); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9320 | if (pos && hwaddr_aton(pos + 7, res->bssid)) |
| 9321 | goto fail; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9322 | |
| 9323 | pos = os_strstr(param, " freq="); |
| 9324 | if (pos) |
| 9325 | res->freq = atoi(pos + 6); |
| 9326 | |
| 9327 | pos = os_strstr(param, " beacon_int="); |
| 9328 | if (pos) |
| 9329 | res->beacon_int = atoi(pos + 12); |
| 9330 | |
| 9331 | pos = os_strstr(param, " caps="); |
| 9332 | if (pos) |
| 9333 | res->caps = strtol(pos + 6, NULL, 16); |
| 9334 | |
| 9335 | pos = os_strstr(param, " qual="); |
| 9336 | if (pos) |
| 9337 | res->qual = atoi(pos + 6); |
| 9338 | |
| 9339 | pos = os_strstr(param, " noise="); |
| 9340 | if (pos) |
| 9341 | res->noise = atoi(pos + 7); |
| 9342 | |
| 9343 | pos = os_strstr(param, " level="); |
| 9344 | if (pos) |
| 9345 | res->level = atoi(pos + 7); |
| 9346 | |
| 9347 | pos = os_strstr(param, " tsf="); |
| 9348 | if (pos) |
| 9349 | res->tsf = strtoll(pos + 5, NULL, 16); |
| 9350 | |
| 9351 | pos = os_strstr(param, " age="); |
| 9352 | if (pos) |
| 9353 | res->age = atoi(pos + 5); |
| 9354 | |
| 9355 | pos = os_strstr(param, " est_throughput="); |
| 9356 | if (pos) |
| 9357 | res->est_throughput = atoi(pos + 16); |
| 9358 | |
| 9359 | pos = os_strstr(param, " snr="); |
| 9360 | if (pos) |
| 9361 | res->snr = atoi(pos + 5); |
| 9362 | |
| 9363 | pos = os_strstr(param, " parent_tsf="); |
| 9364 | if (pos) |
| 9365 | res->parent_tsf = strtoll(pos + 7, NULL, 16); |
| 9366 | |
| 9367 | pos = os_strstr(param, " tsf_bssid="); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9368 | if (pos && hwaddr_aton(pos + 11, res->tsf_bssid)) |
| 9369 | goto fail; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9370 | |
| 9371 | pos = os_strstr(param, " ie="); |
| 9372 | if (pos) { |
| 9373 | pos += 4; |
| 9374 | end = os_strchr(pos, ' '); |
| 9375 | if (!end) |
| 9376 | end = pos + os_strlen(pos); |
| 9377 | res->ie_len = (end - pos) / 2; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9378 | if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len)) |
| 9379 | goto fail; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9380 | } |
| 9381 | |
| 9382 | pos = os_strstr(param, " beacon_ie="); |
| 9383 | if (pos) { |
| 9384 | pos += 11; |
| 9385 | end = os_strchr(pos, ' '); |
| 9386 | if (!end) |
| 9387 | end = pos + os_strlen(pos); |
| 9388 | res->beacon_ie_len = (end - pos) / 2; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9389 | if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len, |
| 9390 | res->beacon_ie_len)) |
| 9391 | goto fail; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9392 | } |
| 9393 | |
| 9394 | os_get_reltime(&now); |
| 9395 | wpa_bss_update_scan_res(wpa_s, res, &now); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9396 | ret = 0; |
| 9397 | fail: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9398 | os_free(res); |
| 9399 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9400 | return ret; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9401 | } |
| 9402 | |
| 9403 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9404 | static int wpas_ctrl_iface_driver_event_assoc(struct wpa_supplicant *wpa_s, |
| 9405 | char *param) |
| 9406 | { |
| 9407 | union wpa_event_data event; |
| 9408 | struct assoc_info *ai; |
| 9409 | char *ctx = NULL; |
| 9410 | int ret = -1; |
| 9411 | struct wpabuf *req_ies = NULL; |
| 9412 | struct wpabuf *resp_ies = NULL; |
| 9413 | struct wpabuf *resp_frame = NULL; |
| 9414 | struct wpabuf *beacon_ies = NULL; |
| 9415 | struct wpabuf *key_replay_ctr = NULL; |
| 9416 | struct wpabuf *ptk_kck = NULL; |
| 9417 | struct wpabuf *ptk_kek = NULL; |
| 9418 | struct wpabuf *fils_pmk = NULL; |
| 9419 | char *str, *pos; |
| 9420 | u8 addr[ETH_ALEN]; |
| 9421 | u8 fils_pmkid[PMKID_LEN]; |
| 9422 | |
| 9423 | os_memset(&event, 0, sizeof(event)); |
| 9424 | ai = &event.assoc_info; |
| 9425 | |
| 9426 | while ((str = str_token(param, " ", &ctx))) { |
| 9427 | pos = os_strchr(str, '='); |
| 9428 | if (!pos) |
| 9429 | goto fail; |
| 9430 | *pos++ = '\0'; |
| 9431 | |
| 9432 | if (os_strcmp(str, "reassoc") == 0) { |
| 9433 | ai->reassoc = atoi(pos); |
| 9434 | } else if (os_strcmp(str, "req_ies") == 0) { |
| 9435 | wpabuf_free(req_ies); |
| 9436 | req_ies = wpabuf_parse_bin(pos); |
| 9437 | if (!req_ies) |
| 9438 | goto fail; |
| 9439 | ai->req_ies = wpabuf_head(req_ies); |
| 9440 | ai->req_ies_len = wpabuf_len(req_ies); |
| 9441 | } else if (os_strcmp(str, "resp_ies") == 0) { |
| 9442 | wpabuf_free(resp_ies); |
| 9443 | resp_ies = wpabuf_parse_bin(pos); |
| 9444 | if (!resp_ies) |
| 9445 | goto fail; |
| 9446 | ai->resp_ies = wpabuf_head(resp_ies); |
| 9447 | ai->resp_ies_len = wpabuf_len(resp_ies); |
| 9448 | } else if (os_strcmp(str, "resp_frame") == 0) { |
| 9449 | wpabuf_free(resp_frame); |
| 9450 | resp_frame = wpabuf_parse_bin(pos); |
| 9451 | if (!resp_frame) |
| 9452 | goto fail; |
| 9453 | ai->resp_frame = wpabuf_head(resp_frame); |
| 9454 | ai->resp_frame_len = wpabuf_len(resp_frame); |
| 9455 | } else if (os_strcmp(str, "beacon_ies") == 0) { |
| 9456 | wpabuf_free(beacon_ies); |
| 9457 | beacon_ies = wpabuf_parse_bin(pos); |
| 9458 | if (!beacon_ies) |
| 9459 | goto fail; |
| 9460 | ai->beacon_ies = wpabuf_head(beacon_ies); |
| 9461 | ai->beacon_ies_len = wpabuf_len(beacon_ies); |
| 9462 | } else if (os_strcmp(str, "freq") == 0) { |
| 9463 | ai->freq = atoi(pos); |
| 9464 | } else if (os_strcmp(str, "wmm::info_bitmap") == 0) { |
| 9465 | ai->wmm_params.info_bitmap = atoi(pos); |
| 9466 | } else if (os_strcmp(str, "wmm::uapsd_queues") == 0) { |
| 9467 | ai->wmm_params.uapsd_queues = atoi(pos); |
| 9468 | } else if (os_strcmp(str, "addr") == 0) { |
| 9469 | if (hwaddr_aton(pos, addr)) |
| 9470 | goto fail; |
| 9471 | ai->addr = addr; |
| 9472 | } else if (os_strcmp(str, "authorized") == 0) { |
| 9473 | ai->authorized = atoi(pos); |
| 9474 | } else if (os_strcmp(str, "key_replay_ctr") == 0) { |
| 9475 | wpabuf_free(key_replay_ctr); |
| 9476 | key_replay_ctr = wpabuf_parse_bin(pos); |
| 9477 | if (!key_replay_ctr) |
| 9478 | goto fail; |
| 9479 | ai->key_replay_ctr = wpabuf_head(key_replay_ctr); |
| 9480 | ai->key_replay_ctr_len = wpabuf_len(key_replay_ctr); |
| 9481 | } else if (os_strcmp(str, "ptk_kck") == 0) { |
| 9482 | wpabuf_free(ptk_kck); |
| 9483 | ptk_kck = wpabuf_parse_bin(pos); |
| 9484 | if (!ptk_kck) |
| 9485 | goto fail; |
| 9486 | ai->ptk_kck = wpabuf_head(ptk_kck); |
| 9487 | ai->ptk_kck_len = wpabuf_len(ptk_kck); |
| 9488 | } else if (os_strcmp(str, "ptk_kek") == 0) { |
| 9489 | wpabuf_free(ptk_kek); |
| 9490 | ptk_kek = wpabuf_parse_bin(pos); |
| 9491 | if (!ptk_kek) |
| 9492 | goto fail; |
| 9493 | ai->ptk_kek = wpabuf_head(ptk_kek); |
| 9494 | ai->ptk_kek_len = wpabuf_len(ptk_kek); |
| 9495 | } else if (os_strcmp(str, "subnet_status") == 0) { |
| 9496 | ai->subnet_status = atoi(pos); |
| 9497 | } else if (os_strcmp(str, "fils_erp_next_seq_num") == 0) { |
| 9498 | ai->fils_erp_next_seq_num = atoi(pos); |
| 9499 | } else if (os_strcmp(str, "fils_pmk") == 0) { |
| 9500 | wpabuf_free(fils_pmk); |
| 9501 | fils_pmk = wpabuf_parse_bin(pos); |
| 9502 | if (!fils_pmk) |
| 9503 | goto fail; |
| 9504 | ai->fils_pmk = wpabuf_head(fils_pmk); |
| 9505 | ai->fils_pmk_len = wpabuf_len(fils_pmk); |
| 9506 | } else if (os_strcmp(str, "fils_pmkid") == 0) { |
| 9507 | if (hexstr2bin(pos, fils_pmkid, PMKID_LEN) < 0) |
| 9508 | goto fail; |
| 9509 | ai->fils_pmkid = fils_pmkid; |
| 9510 | } else { |
| 9511 | goto fail; |
| 9512 | } |
| 9513 | } |
| 9514 | |
| 9515 | wpa_supplicant_event(wpa_s, EVENT_ASSOC, &event); |
| 9516 | ret = 0; |
| 9517 | fail: |
| 9518 | wpabuf_free(req_ies); |
| 9519 | wpabuf_free(resp_ies); |
| 9520 | wpabuf_free(resp_frame); |
| 9521 | wpabuf_free(beacon_ies); |
| 9522 | wpabuf_free(key_replay_ctr); |
| 9523 | wpabuf_free(ptk_kck); |
| 9524 | wpabuf_free(ptk_kek); |
| 9525 | wpabuf_free(fils_pmk); |
| 9526 | return ret; |
| 9527 | } |
| 9528 | |
| 9529 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 9530 | static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd) |
| 9531 | { |
| 9532 | char *pos, *param; |
| 9533 | union wpa_event_data event; |
| 9534 | enum wpa_event_type ev; |
| 9535 | |
| 9536 | /* <event name> [parameters..] */ |
| 9537 | |
| 9538 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd); |
| 9539 | |
| 9540 | pos = cmd; |
| 9541 | param = os_strchr(pos, ' '); |
| 9542 | if (param) |
| 9543 | *param++ = '\0'; |
| 9544 | |
| 9545 | os_memset(&event, 0, sizeof(event)); |
| 9546 | |
| 9547 | if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) { |
| 9548 | ev = EVENT_INTERFACE_ENABLED; |
| 9549 | } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) { |
| 9550 | ev = EVENT_INTERFACE_DISABLED; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 9551 | } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) { |
| 9552 | ev = EVENT_AVOID_FREQUENCIES; |
| 9553 | if (param == NULL) |
| 9554 | param = ""; |
| 9555 | if (freq_range_list_parse(&event.freq_range, param) < 0) |
| 9556 | return -1; |
| 9557 | wpa_supplicant_event(wpa_s, ev, &event); |
| 9558 | os_free(event.freq_range.range); |
| 9559 | return 0; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9560 | } else if (os_strcmp(cmd, "SCAN_RES") == 0) { |
| 9561 | return wpas_ctrl_iface_driver_scan_res(wpa_s, param); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9562 | } else if (os_strcmp(cmd, "ASSOC") == 0) { |
| 9563 | return wpas_ctrl_iface_driver_event_assoc(wpa_s, param); |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 9564 | } else { |
| 9565 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s", |
| 9566 | cmd); |
| 9567 | return -1; |
| 9568 | } |
| 9569 | |
| 9570 | wpa_supplicant_event(wpa_s, ev, &event); |
| 9571 | |
| 9572 | return 0; |
| 9573 | } |
| 9574 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9575 | |
| 9576 | static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd) |
| 9577 | { |
| 9578 | char *pos; |
| 9579 | u8 src[ETH_ALEN], *buf; |
| 9580 | int used; |
| 9581 | size_t len; |
| 9582 | |
| 9583 | wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd); |
| 9584 | |
| 9585 | pos = cmd; |
| 9586 | used = hwaddr_aton2(pos, src); |
| 9587 | if (used < 0) |
| 9588 | return -1; |
| 9589 | pos += used; |
| 9590 | while (*pos == ' ') |
| 9591 | pos++; |
| 9592 | |
| 9593 | len = os_strlen(pos); |
| 9594 | if (len & 1) |
| 9595 | return -1; |
| 9596 | len /= 2; |
| 9597 | |
| 9598 | buf = os_malloc(len); |
| 9599 | if (buf == NULL) |
| 9600 | return -1; |
| 9601 | |
| 9602 | if (hexstr2bin(pos, buf, len) < 0) { |
| 9603 | os_free(buf); |
| 9604 | return -1; |
| 9605 | } |
| 9606 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9607 | wpa_supplicant_rx_eapol(wpa_s, src, buf, len, FRAME_ENCRYPTION_UNKNOWN); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9608 | os_free(buf); |
| 9609 | |
| 9610 | return 0; |
| 9611 | } |
| 9612 | |
| 9613 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9614 | static int wpas_ctrl_iface_eapol_tx(struct wpa_supplicant *wpa_s, char *cmd) |
| 9615 | { |
| 9616 | char *pos; |
| 9617 | u8 dst[ETH_ALEN], *buf; |
| 9618 | int used, ret; |
| 9619 | size_t len; |
| 9620 | unsigned int prev; |
| 9621 | |
| 9622 | wpa_printf(MSG_DEBUG, "External EAPOL TX: %s", cmd); |
| 9623 | |
| 9624 | pos = cmd; |
| 9625 | used = hwaddr_aton2(pos, dst); |
| 9626 | if (used < 0) |
| 9627 | return -1; |
| 9628 | pos += used; |
| 9629 | while (*pos == ' ') |
| 9630 | pos++; |
| 9631 | |
| 9632 | len = os_strlen(pos); |
| 9633 | if (len & 1) |
| 9634 | return -1; |
| 9635 | len /= 2; |
| 9636 | |
| 9637 | buf = os_malloc(len); |
| 9638 | if (!buf || hexstr2bin(pos, buf, len) < 0) { |
| 9639 | os_free(buf); |
| 9640 | return -1; |
| 9641 | } |
| 9642 | |
| 9643 | prev = wpa_s->ext_eapol_frame_io; |
| 9644 | wpa_s->ext_eapol_frame_io = 0; |
| 9645 | ret = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, buf, len); |
| 9646 | wpa_s->ext_eapol_frame_io = prev; |
| 9647 | os_free(buf); |
| 9648 | |
| 9649 | return ret; |
| 9650 | } |
| 9651 | |
| 9652 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9653 | static u16 ipv4_hdr_checksum(const void *buf, size_t len) |
| 9654 | { |
| 9655 | size_t i; |
| 9656 | u32 sum = 0; |
| 9657 | const u16 *pos = buf; |
| 9658 | |
| 9659 | for (i = 0; i < len / 2; i++) |
| 9660 | sum += *pos++; |
| 9661 | |
| 9662 | while (sum >> 16) |
| 9663 | sum = (sum & 0xffff) + (sum >> 16); |
| 9664 | |
| 9665 | return sum ^ 0xffff; |
| 9666 | } |
| 9667 | |
| 9668 | |
| 9669 | #define HWSIM_PACKETLEN 1500 |
| 9670 | #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header)) |
| 9671 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 9672 | static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, |
| 9673 | size_t len) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9674 | { |
| 9675 | struct wpa_supplicant *wpa_s = ctx; |
| 9676 | const struct ether_header *eth; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9677 | struct ip ip; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9678 | const u8 *pos; |
| 9679 | unsigned int i; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9680 | char extra[30]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9681 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9682 | if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) { |
| 9683 | wpa_printf(MSG_DEBUG, |
| 9684 | "test data: RX - ignore unexpected length %d", |
| 9685 | (int) len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9686 | return; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9687 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9688 | |
| 9689 | eth = (const struct ether_header *) buf; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9690 | os_memcpy(&ip, eth + 1, sizeof(ip)); |
| 9691 | pos = &buf[sizeof(*eth) + sizeof(ip)]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9692 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9693 | 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] | 9694 | wpa_printf(MSG_DEBUG, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9695 | "test data: RX - ignore unexpected IP header"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9696 | return; |
Hai Shalom | 39bc25d | 2019-02-06 16:32:13 -0800 | [diff] [blame] | 9697 | } |
Hai Shalom | bf6e0ba | 2019-02-11 12:01:50 -0800 | [diff] [blame] | 9698 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9699 | for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9700 | if (*pos != (u8) i) { |
| 9701 | wpa_printf(MSG_DEBUG, |
| 9702 | "test data: RX - ignore mismatching payload"); |
| 9703 | return; |
| 9704 | } |
| 9705 | pos++; |
| 9706 | } |
| 9707 | extra[0] = '\0'; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9708 | if (ntohs(ip.ip_len) != HWSIM_IP_LEN) |
| 9709 | os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len)); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9710 | wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s", |
| 9711 | MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9712 | } |
| 9713 | |
| 9714 | |
| 9715 | static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s, |
| 9716 | char *cmd) |
| 9717 | { |
| 9718 | int enabled = atoi(cmd); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 9719 | char *pos; |
| 9720 | const char *ifname; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9721 | |
| 9722 | if (!enabled) { |
| 9723 | if (wpa_s->l2_test) { |
| 9724 | l2_packet_deinit(wpa_s->l2_test); |
| 9725 | wpa_s->l2_test = NULL; |
| 9726 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled"); |
| 9727 | } |
| 9728 | return 0; |
| 9729 | } |
| 9730 | |
| 9731 | if (wpa_s->l2_test) |
| 9732 | return 0; |
| 9733 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 9734 | pos = os_strstr(cmd, " ifname="); |
| 9735 | if (pos) |
| 9736 | ifname = pos + 8; |
| 9737 | else |
| 9738 | ifname = wpa_s->ifname; |
| 9739 | |
| 9740 | wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9741 | ETHERTYPE_IP, wpas_data_test_rx, |
| 9742 | wpa_s, 1); |
| 9743 | if (wpa_s->l2_test == NULL) |
| 9744 | return -1; |
| 9745 | |
| 9746 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled"); |
| 9747 | |
| 9748 | return 0; |
| 9749 | } |
| 9750 | |
| 9751 | |
| 9752 | static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd) |
| 9753 | { |
| 9754 | u8 dst[ETH_ALEN], src[ETH_ALEN]; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9755 | char *pos, *pos2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9756 | int used; |
| 9757 | long int val; |
| 9758 | u8 tos; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9759 | u8 buf[2 + HWSIM_PACKETLEN]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9760 | struct ether_header *eth; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9761 | struct ip *ip; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9762 | u8 *dpos; |
| 9763 | unsigned int i; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9764 | size_t send_len = HWSIM_IP_LEN; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9765 | |
| 9766 | if (wpa_s->l2_test == NULL) |
| 9767 | return -1; |
| 9768 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9769 | /* format: <dst> <src> <tos> [len=<length>] */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9770 | |
| 9771 | pos = cmd; |
| 9772 | used = hwaddr_aton2(pos, dst); |
| 9773 | if (used < 0) |
| 9774 | return -1; |
| 9775 | pos += used; |
| 9776 | while (*pos == ' ') |
| 9777 | pos++; |
| 9778 | used = hwaddr_aton2(pos, src); |
| 9779 | if (used < 0) |
| 9780 | return -1; |
| 9781 | pos += used; |
| 9782 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9783 | val = strtol(pos, &pos2, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9784 | if (val < 0 || val > 0xff) |
| 9785 | return -1; |
| 9786 | tos = val; |
| 9787 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9788 | pos = os_strstr(pos2, " len="); |
| 9789 | if (pos) { |
| 9790 | i = atoi(pos + 5); |
| 9791 | if (i < sizeof(*ip) || i > HWSIM_IP_LEN) |
| 9792 | return -1; |
| 9793 | send_len = i; |
| 9794 | } |
| 9795 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9796 | eth = (struct ether_header *) &buf[2]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9797 | os_memcpy(eth->ether_dhost, dst, ETH_ALEN); |
| 9798 | os_memcpy(eth->ether_shost, src, ETH_ALEN); |
| 9799 | eth->ether_type = htons(ETHERTYPE_IP); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9800 | ip = (struct ip *) (eth + 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9801 | os_memset(ip, 0, sizeof(*ip)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9802 | ip->ip_hl = 5; |
| 9803 | ip->ip_v = 4; |
| 9804 | ip->ip_ttl = 64; |
| 9805 | ip->ip_tos = tos; |
| 9806 | ip->ip_len = htons(send_len); |
| 9807 | ip->ip_p = 1; |
| 9808 | ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1); |
| 9809 | ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2); |
| 9810 | ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9811 | dpos = (u8 *) (ip + 1); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9812 | for (i = 0; i < send_len - sizeof(*ip); i++) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9813 | *dpos++ = i; |
| 9814 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9815 | 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] | 9816 | sizeof(struct ether_header) + send_len) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9817 | return -1; |
| 9818 | |
| 9819 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR |
| 9820 | " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos); |
| 9821 | |
| 9822 | return 0; |
| 9823 | } |
| 9824 | |
| 9825 | |
| 9826 | static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s, |
| 9827 | char *cmd) |
| 9828 | { |
| 9829 | u8 *buf; |
| 9830 | struct ether_header *eth; |
| 9831 | struct l2_packet_data *l2 = NULL; |
| 9832 | size_t len; |
| 9833 | u16 ethertype; |
| 9834 | int res = -1; |
| 9835 | |
| 9836 | len = os_strlen(cmd); |
| 9837 | if (len & 1 || len < ETH_HLEN * 2) |
| 9838 | return -1; |
| 9839 | len /= 2; |
| 9840 | |
| 9841 | buf = os_malloc(len); |
| 9842 | if (buf == NULL) |
| 9843 | return -1; |
| 9844 | |
| 9845 | if (hexstr2bin(cmd, buf, len) < 0) |
| 9846 | goto done; |
| 9847 | |
| 9848 | eth = (struct ether_header *) buf; |
| 9849 | ethertype = ntohs(eth->ether_type); |
| 9850 | |
| 9851 | l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype, |
| 9852 | wpas_data_test_rx, wpa_s, 1); |
| 9853 | if (l2 == NULL) |
| 9854 | goto done; |
| 9855 | |
| 9856 | res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len); |
| 9857 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res); |
| 9858 | done: |
| 9859 | if (l2) |
| 9860 | l2_packet_deinit(l2); |
| 9861 | os_free(buf); |
| 9862 | |
| 9863 | return res < 0 ? -1 : 0; |
| 9864 | } |
| 9865 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9866 | |
| 9867 | static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd) |
| 9868 | { |
| 9869 | #ifdef WPA_TRACE_BFD |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9870 | char *pos; |
| 9871 | |
| 9872 | wpa_trace_fail_after = atoi(cmd); |
| 9873 | pos = os_strchr(cmd, ':'); |
| 9874 | if (pos) { |
| 9875 | pos++; |
| 9876 | os_strlcpy(wpa_trace_fail_func, pos, |
| 9877 | sizeof(wpa_trace_fail_func)); |
| 9878 | } else { |
| 9879 | wpa_trace_fail_after = 0; |
| 9880 | } |
| 9881 | return 0; |
| 9882 | #else /* WPA_TRACE_BFD */ |
| 9883 | return -1; |
| 9884 | #endif /* WPA_TRACE_BFD */ |
| 9885 | } |
| 9886 | |
| 9887 | |
| 9888 | static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s, |
| 9889 | char *buf, size_t buflen) |
| 9890 | { |
| 9891 | #ifdef WPA_TRACE_BFD |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9892 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after, |
| 9893 | wpa_trace_fail_func); |
| 9894 | #else /* WPA_TRACE_BFD */ |
| 9895 | return -1; |
| 9896 | #endif /* WPA_TRACE_BFD */ |
| 9897 | } |
| 9898 | |
Jouni Malinen | c481836 | 2015-10-04 11:45:13 +0300 | [diff] [blame] | 9899 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9900 | static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd) |
| 9901 | { |
| 9902 | #ifdef WPA_TRACE_BFD |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9903 | char *pos; |
| 9904 | |
| 9905 | wpa_trace_test_fail_after = atoi(cmd); |
| 9906 | pos = os_strchr(cmd, ':'); |
| 9907 | if (pos) { |
| 9908 | pos++; |
| 9909 | os_strlcpy(wpa_trace_test_fail_func, pos, |
| 9910 | sizeof(wpa_trace_test_fail_func)); |
| 9911 | } else { |
| 9912 | wpa_trace_test_fail_after = 0; |
| 9913 | } |
| 9914 | return 0; |
| 9915 | #else /* WPA_TRACE_BFD */ |
| 9916 | return -1; |
| 9917 | #endif /* WPA_TRACE_BFD */ |
| 9918 | } |
| 9919 | |
| 9920 | |
| 9921 | static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s, |
| 9922 | char *buf, size_t buflen) |
| 9923 | { |
| 9924 | #ifdef WPA_TRACE_BFD |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9925 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after, |
| 9926 | wpa_trace_test_fail_func); |
| 9927 | #else /* WPA_TRACE_BFD */ |
| 9928 | return -1; |
| 9929 | #endif /* WPA_TRACE_BFD */ |
| 9930 | } |
| 9931 | |
| 9932 | |
Jouni Malinen | c481836 | 2015-10-04 11:45:13 +0300 | [diff] [blame] | 9933 | static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx) |
| 9934 | { |
| 9935 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9936 | int i, count = (intptr_t) timeout_ctx; |
| 9937 | |
| 9938 | wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages", |
| 9939 | count); |
| 9940 | for (i = 0; i < count; i++) { |
| 9941 | wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d", |
| 9942 | i + 1, count); |
| 9943 | } |
| 9944 | } |
| 9945 | |
| 9946 | |
| 9947 | static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd) |
| 9948 | { |
| 9949 | int count; |
| 9950 | |
| 9951 | count = atoi(cmd); |
| 9952 | if (count <= 0) |
| 9953 | return -1; |
| 9954 | |
| 9955 | return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s, |
| 9956 | (void *) (intptr_t) count); |
| 9957 | } |
| 9958 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 9959 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9960 | static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s, |
| 9961 | const char *cmd) |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9962 | { |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9963 | struct wpabuf *buf; |
| 9964 | size_t len; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9965 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9966 | len = os_strlen(cmd); |
| 9967 | if (len & 1) |
| 9968 | return -1; |
| 9969 | len /= 2; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9970 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9971 | if (len == 0) { |
| 9972 | buf = NULL; |
| 9973 | } else { |
| 9974 | buf = wpabuf_alloc(len); |
| 9975 | if (buf == NULL) |
| 9976 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9977 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9978 | if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) { |
| 9979 | wpabuf_free(buf); |
| 9980 | return -1; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9981 | } |
| 9982 | } |
| 9983 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9984 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf); |
| 9985 | return 0; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9986 | } |
| 9987 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9988 | |
| 9989 | static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s) |
| 9990 | { |
| 9991 | u8 zero[WPA_TK_MAX_LEN]; |
| 9992 | |
| 9993 | if (wpa_s->last_tk_alg == WPA_ALG_NONE) |
| 9994 | return -1; |
| 9995 | |
| 9996 | wpa_printf(MSG_INFO, "TESTING: Reset PN"); |
| 9997 | os_memset(zero, 0, sizeof(zero)); |
| 9998 | |
| 9999 | /* First, use a zero key to avoid any possible duplicate key avoidance |
| 10000 | * in the driver. */ |
| 10001 | if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr, |
| 10002 | wpa_s->last_tk_key_idx, 1, zero, 6, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10003 | zero, wpa_s->last_tk_len, |
| 10004 | KEY_FLAG_PAIRWISE_RX_TX) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10005 | return -1; |
| 10006 | |
| 10007 | /* Set the previously configured key to reset its TSC/RSC */ |
| 10008 | return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr, |
| 10009 | wpa_s->last_tk_key_idx, 1, zero, 6, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10010 | wpa_s->last_tk, wpa_s->last_tk_len, |
| 10011 | KEY_FLAG_PAIRWISE_RX_TX); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10012 | } |
| 10013 | |
| 10014 | |
| 10015 | static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd) |
| 10016 | { |
| 10017 | const char *pos = cmd; |
| 10018 | int error, pairwise; |
| 10019 | |
| 10020 | error = atoi(pos); |
| 10021 | pos = os_strchr(pos, ' '); |
| 10022 | if (!pos) |
| 10023 | return -1; |
| 10024 | pairwise = atoi(pos); |
| 10025 | wpa_sm_key_request(wpa_s->wpa, error, pairwise); |
| 10026 | return 0; |
| 10027 | } |
| 10028 | |
| 10029 | |
| 10030 | static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s) |
| 10031 | { |
| 10032 | #ifdef CONFIG_SME |
| 10033 | struct wpa_driver_associate_params params; |
| 10034 | int ret; |
| 10035 | |
| 10036 | os_memset(¶ms, 0, sizeof(params)); |
| 10037 | params.bssid = wpa_s->bssid; |
| 10038 | params.ssid = wpa_s->sme.ssid; |
| 10039 | params.ssid_len = wpa_s->sme.ssid_len; |
| 10040 | params.freq.freq = wpa_s->sme.freq; |
| 10041 | if (wpa_s->last_assoc_req_wpa_ie) { |
| 10042 | params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie); |
| 10043 | params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie); |
| 10044 | } |
| 10045 | params.pairwise_suite = wpa_s->pairwise_cipher; |
| 10046 | params.group_suite = wpa_s->group_cipher; |
| 10047 | params.mgmt_group_suite = wpa_s->mgmt_group_cipher; |
| 10048 | params.key_mgmt_suite = wpa_s->key_mgmt; |
| 10049 | params.wpa_proto = wpa_s->wpa_proto; |
| 10050 | params.mgmt_frame_protection = wpa_s->sme.mfp; |
| 10051 | params.rrm_used = wpa_s->rrm.rrm_used; |
| 10052 | if (wpa_s->sme.prev_bssid_set) |
| 10053 | params.prev_bssid = wpa_s->sme.prev_bssid; |
| 10054 | wpa_printf(MSG_INFO, "TESTING: Resend association request"); |
| 10055 | ret = wpa_drv_associate(wpa_s, ¶ms); |
| 10056 | wpa_s->testing_resend_assoc = 1; |
| 10057 | return ret; |
| 10058 | #else /* CONFIG_SME */ |
| 10059 | return -1; |
| 10060 | #endif /* CONFIG_SME */ |
| 10061 | } |
| 10062 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10063 | |
| 10064 | static int wpas_ctrl_iface_send_twt_setup(struct wpa_supplicant *wpa_s, |
| 10065 | const char *cmd) |
| 10066 | { |
| 10067 | u8 dtok = 1; |
| 10068 | int exponent = 10; |
| 10069 | int mantissa = 8192; |
| 10070 | u8 min_twt = 255; |
| 10071 | unsigned long long twt = 0; |
| 10072 | bool requestor = true; |
| 10073 | int setup_cmd = 0; |
| 10074 | bool trigger = true; |
| 10075 | bool implicit = true; |
| 10076 | bool flow_type = true; |
| 10077 | int flow_id = 0; |
| 10078 | bool protection = false; |
| 10079 | u8 twt_channel = 0; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 10080 | u8 control = BIT(4); /* Control field (IEEE Std 802.11ax-2021, |
| 10081 | * Figure 9-687 - Control field format): |
| 10082 | * B4 = TWT Information Frame Disabled */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10083 | const char *tok_s; |
| 10084 | |
| 10085 | tok_s = os_strstr(cmd, " dialog="); |
| 10086 | if (tok_s) |
| 10087 | dtok = atoi(tok_s + os_strlen(" dialog=")); |
| 10088 | |
| 10089 | tok_s = os_strstr(cmd, " exponent="); |
| 10090 | if (tok_s) |
| 10091 | exponent = atoi(tok_s + os_strlen(" exponent=")); |
| 10092 | |
| 10093 | tok_s = os_strstr(cmd, " mantissa="); |
| 10094 | if (tok_s) |
| 10095 | mantissa = atoi(tok_s + os_strlen(" mantissa=")); |
| 10096 | |
| 10097 | tok_s = os_strstr(cmd, " min_twt="); |
| 10098 | if (tok_s) |
| 10099 | min_twt = atoi(tok_s + os_strlen(" min_twt=")); |
| 10100 | |
| 10101 | tok_s = os_strstr(cmd, " setup_cmd="); |
| 10102 | if (tok_s) |
| 10103 | setup_cmd = atoi(tok_s + os_strlen(" setup_cmd=")); |
| 10104 | |
| 10105 | tok_s = os_strstr(cmd, " twt="); |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 10106 | if (tok_s && |
| 10107 | sscanf(tok_s + os_strlen(" twt="), "%llu", &twt) != 1) |
| 10108 | return -1; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10109 | |
| 10110 | tok_s = os_strstr(cmd, " requestor="); |
| 10111 | if (tok_s) |
| 10112 | requestor = atoi(tok_s + os_strlen(" requestor=")); |
| 10113 | |
| 10114 | tok_s = os_strstr(cmd, " trigger="); |
| 10115 | if (tok_s) |
| 10116 | trigger = atoi(tok_s + os_strlen(" trigger=")); |
| 10117 | |
| 10118 | tok_s = os_strstr(cmd, " implicit="); |
| 10119 | if (tok_s) |
| 10120 | implicit = atoi(tok_s + os_strlen(" implicit=")); |
| 10121 | |
| 10122 | tok_s = os_strstr(cmd, " flow_type="); |
| 10123 | if (tok_s) |
| 10124 | flow_type = atoi(tok_s + os_strlen(" flow_type=")); |
| 10125 | |
| 10126 | tok_s = os_strstr(cmd, " flow_id="); |
| 10127 | if (tok_s) |
| 10128 | flow_id = atoi(tok_s + os_strlen(" flow_id=")); |
| 10129 | |
| 10130 | tok_s = os_strstr(cmd, " protection="); |
| 10131 | if (tok_s) |
| 10132 | protection = atoi(tok_s + os_strlen(" protection=")); |
| 10133 | |
| 10134 | tok_s = os_strstr(cmd, " twt_channel="); |
| 10135 | if (tok_s) |
| 10136 | twt_channel = atoi(tok_s + os_strlen(" twt_channel=")); |
| 10137 | |
| 10138 | tok_s = os_strstr(cmd, " control="); |
| 10139 | if (tok_s) |
| 10140 | control = atoi(tok_s + os_strlen(" control=")); |
| 10141 | |
| 10142 | return wpas_twt_send_setup(wpa_s, dtok, exponent, mantissa, min_twt, |
| 10143 | setup_cmd, twt, requestor, trigger, implicit, |
| 10144 | flow_type, flow_id, protection, twt_channel, |
| 10145 | control); |
| 10146 | } |
| 10147 | |
| 10148 | |
| 10149 | static int wpas_ctrl_iface_send_twt_teardown(struct wpa_supplicant *wpa_s, |
| 10150 | const char *cmd) |
| 10151 | { |
| 10152 | u8 flags = 0x1; |
| 10153 | const char *tok_s; |
| 10154 | |
| 10155 | tok_s = os_strstr(cmd, " flags="); |
| 10156 | if (tok_s) |
| 10157 | flags = atoi(tok_s + os_strlen(" flags=")); |
| 10158 | |
| 10159 | return wpas_twt_send_teardown(wpa_s, flags); |
| 10160 | } |
| 10161 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10162 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10163 | |
| 10164 | |
| 10165 | static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd) |
| 10166 | { |
| 10167 | char *pos = cmd; |
| 10168 | int frame; |
| 10169 | size_t len; |
| 10170 | struct wpabuf *buf; |
| 10171 | struct ieee802_11_elems elems; |
| 10172 | |
| 10173 | frame = atoi(pos); |
| 10174 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) |
| 10175 | return -1; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10176 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10177 | |
| 10178 | pos = os_strchr(pos, ' '); |
| 10179 | if (pos == NULL) |
| 10180 | return -1; |
| 10181 | pos++; |
| 10182 | |
| 10183 | len = os_strlen(pos); |
| 10184 | if (len == 0) |
| 10185 | return 0; |
| 10186 | if (len & 1) |
| 10187 | return -1; |
| 10188 | len /= 2; |
| 10189 | |
| 10190 | buf = wpabuf_alloc(len); |
| 10191 | if (buf == NULL) |
| 10192 | return -1; |
| 10193 | |
| 10194 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { |
| 10195 | wpabuf_free(buf); |
| 10196 | return -1; |
| 10197 | } |
| 10198 | |
| 10199 | if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) == |
| 10200 | ParseFailed) { |
| 10201 | wpabuf_free(buf); |
| 10202 | return -1; |
| 10203 | } |
| 10204 | |
| 10205 | if (wpa_s->vendor_elem[frame] == NULL) { |
| 10206 | wpa_s->vendor_elem[frame] = buf; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10207 | goto update_ies; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10208 | } |
| 10209 | |
| 10210 | if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) { |
| 10211 | wpabuf_free(buf); |
| 10212 | return -1; |
| 10213 | } |
| 10214 | |
| 10215 | wpabuf_put_buf(wpa_s->vendor_elem[frame], buf); |
| 10216 | wpabuf_free(buf); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10217 | |
| 10218 | update_ies: |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10219 | wpas_vendor_elem_update(wpa_s); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10220 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10221 | if (frame == VENDOR_ELEM_PROBE_REQ || |
| 10222 | frame == VENDOR_ELEM_PROBE_REQ_P2P) |
| 10223 | wpa_supplicant_set_default_scan_ies(wpa_s); |
| 10224 | |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10225 | return 0; |
| 10226 | } |
| 10227 | |
| 10228 | |
| 10229 | static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd, |
| 10230 | char *buf, size_t buflen) |
| 10231 | { |
| 10232 | int frame = atoi(cmd); |
| 10233 | |
| 10234 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) |
| 10235 | return -1; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10236 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10237 | |
| 10238 | if (wpa_s->vendor_elem[frame] == NULL) |
| 10239 | return 0; |
| 10240 | |
| 10241 | return wpa_snprintf_hex(buf, buflen, |
| 10242 | wpabuf_head_u8(wpa_s->vendor_elem[frame]), |
| 10243 | wpabuf_len(wpa_s->vendor_elem[frame])); |
| 10244 | } |
| 10245 | |
| 10246 | |
| 10247 | static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd) |
| 10248 | { |
| 10249 | char *pos = cmd; |
| 10250 | int frame; |
| 10251 | size_t len; |
| 10252 | u8 *buf; |
| 10253 | struct ieee802_11_elems elems; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10254 | int res; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10255 | |
| 10256 | frame = atoi(pos); |
| 10257 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) |
| 10258 | return -1; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10259 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10260 | |
| 10261 | pos = os_strchr(pos, ' '); |
| 10262 | if (pos == NULL) |
| 10263 | return -1; |
| 10264 | pos++; |
| 10265 | |
| 10266 | if (*pos == '*') { |
| 10267 | wpabuf_free(wpa_s->vendor_elem[frame]); |
| 10268 | wpa_s->vendor_elem[frame] = NULL; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10269 | wpas_vendor_elem_update(wpa_s); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10270 | return 0; |
| 10271 | } |
| 10272 | |
| 10273 | if (wpa_s->vendor_elem[frame] == NULL) |
| 10274 | return -1; |
| 10275 | |
| 10276 | len = os_strlen(pos); |
| 10277 | if (len == 0) |
| 10278 | return 0; |
| 10279 | if (len & 1) |
| 10280 | return -1; |
| 10281 | len /= 2; |
| 10282 | |
| 10283 | buf = os_malloc(len); |
| 10284 | if (buf == NULL) |
| 10285 | return -1; |
| 10286 | |
| 10287 | if (hexstr2bin(pos, buf, len) < 0) { |
| 10288 | os_free(buf); |
| 10289 | return -1; |
| 10290 | } |
| 10291 | |
| 10292 | if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) { |
| 10293 | os_free(buf); |
| 10294 | return -1; |
| 10295 | } |
| 10296 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10297 | res = wpas_vendor_elem_remove(wpa_s, frame, buf, len); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10298 | os_free(buf); |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10299 | return res; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10300 | } |
| 10301 | |
| 10302 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10303 | static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep) |
| 10304 | { |
| 10305 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10306 | size_t len; |
| 10307 | const u8 *data; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10308 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10309 | /* |
| 10310 | * Neighbor Report element (IEEE P802.11-REVmc/D5.0) |
| 10311 | * BSSID[6] |
| 10312 | * BSSID Information[4] |
| 10313 | * Operating Class[1] |
| 10314 | * Channel Number[1] |
| 10315 | * PHY Type[1] |
| 10316 | * Optional Subelements[variable] |
| 10317 | */ |
| 10318 | #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1) |
| 10319 | |
| 10320 | if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10321 | wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10322 | goto out; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10323 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10324 | |
| 10325 | data = wpabuf_head_u8(neighbor_rep); |
| 10326 | len = wpabuf_len(neighbor_rep); |
| 10327 | |
| 10328 | while (len >= 2 + NR_IE_MIN_LEN) { |
| 10329 | const u8 *nr; |
| 10330 | char lci[256 * 2 + 1]; |
| 10331 | char civic[256 * 2 + 1]; |
| 10332 | u8 nr_len = data[1]; |
| 10333 | const u8 *pos = data, *end; |
| 10334 | |
| 10335 | if (pos[0] != WLAN_EID_NEIGHBOR_REPORT || |
| 10336 | nr_len < NR_IE_MIN_LEN) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10337 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10338 | "CTRL: Invalid Neighbor Report element: id=%u len=%u", |
| 10339 | data[0], nr_len); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10340 | goto out; |
| 10341 | } |
| 10342 | |
| 10343 | if (2U + nr_len > len) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10344 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10345 | "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u", |
| 10346 | data[0], len, nr_len); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10347 | goto out; |
| 10348 | } |
| 10349 | pos += 2; |
| 10350 | end = pos + nr_len; |
| 10351 | |
| 10352 | nr = pos; |
| 10353 | pos += NR_IE_MIN_LEN; |
| 10354 | |
| 10355 | lci[0] = '\0'; |
| 10356 | civic[0] = '\0'; |
| 10357 | while (end - pos > 2) { |
| 10358 | u8 s_id, s_len; |
| 10359 | |
| 10360 | s_id = *pos++; |
| 10361 | s_len = *pos++; |
| 10362 | if (s_len > end - pos) |
| 10363 | goto out; |
| 10364 | if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) { |
| 10365 | /* Measurement Token[1] */ |
| 10366 | /* Measurement Report Mode[1] */ |
| 10367 | /* Measurement Type[1] */ |
| 10368 | /* Measurement Report[variable] */ |
| 10369 | switch (pos[2]) { |
| 10370 | case MEASURE_TYPE_LCI: |
| 10371 | if (lci[0]) |
| 10372 | break; |
| 10373 | wpa_snprintf_hex(lci, sizeof(lci), |
| 10374 | pos, s_len); |
| 10375 | break; |
| 10376 | case MEASURE_TYPE_LOCATION_CIVIC: |
| 10377 | if (civic[0]) |
| 10378 | break; |
| 10379 | wpa_snprintf_hex(civic, sizeof(civic), |
| 10380 | pos, s_len); |
| 10381 | break; |
| 10382 | } |
| 10383 | } |
| 10384 | |
| 10385 | pos += s_len; |
| 10386 | } |
| 10387 | |
| 10388 | wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED |
| 10389 | "bssid=" MACSTR |
| 10390 | " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s", |
| 10391 | MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN), |
| 10392 | nr[ETH_ALEN + 4], nr[ETH_ALEN + 5], |
| 10393 | nr[ETH_ALEN + 6], |
| 10394 | lci[0] ? " lci=" : "", lci, |
| 10395 | civic[0] ? " civic=" : "", civic); |
| 10396 | |
| 10397 | data = end; |
| 10398 | len -= 2 + nr_len; |
| 10399 | } |
| 10400 | |
| 10401 | out: |
| 10402 | wpabuf_free(neighbor_rep); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10403 | } |
| 10404 | |
| 10405 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10406 | static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s, |
| 10407 | char *cmd) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10408 | { |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10409 | struct wpa_ssid_value ssid, *ssid_p = NULL; |
| 10410 | int ret, lci = 0, civic = 0; |
| 10411 | char *ssid_s; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10412 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10413 | ssid_s = os_strstr(cmd, "ssid="); |
| 10414 | if (ssid_s) { |
| 10415 | if (ssid_parse(ssid_s + 5, &ssid)) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10416 | wpa_msg(wpa_s, MSG_INFO, |
| 10417 | "CTRL: Send Neighbor Report: bad SSID"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10418 | return -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10419 | } |
| 10420 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10421 | ssid_p = &ssid; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10422 | |
| 10423 | /* |
| 10424 | * Move cmd after the SSID text that may include "lci" or |
| 10425 | * "civic". |
| 10426 | */ |
| 10427 | cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' '); |
| 10428 | if (cmd) |
| 10429 | cmd++; |
| 10430 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10431 | } |
| 10432 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10433 | if (cmd && os_strstr(cmd, "lci")) |
| 10434 | lci = 1; |
| 10435 | |
| 10436 | if (cmd && os_strstr(cmd, "civic")) |
| 10437 | civic = 1; |
| 10438 | |
| 10439 | 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] | 10440 | wpas_ctrl_neighbor_rep_cb, |
| 10441 | wpa_s); |
| 10442 | |
| 10443 | return ret; |
| 10444 | } |
| 10445 | |
| 10446 | |
| 10447 | static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s) |
| 10448 | { |
| 10449 | eapol_sm_erp_flush(wpa_s->eapol); |
| 10450 | return 0; |
| 10451 | } |
| 10452 | |
| 10453 | |
| 10454 | static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s, |
| 10455 | char *cmd) |
| 10456 | { |
| 10457 | char *token, *context = NULL; |
| 10458 | unsigned int enable = ~0, type = 0; |
| 10459 | u8 _addr[ETH_ALEN], _mask[ETH_ALEN]; |
| 10460 | u8 *addr = NULL, *mask = NULL; |
| 10461 | |
| 10462 | while ((token = str_token(cmd, " ", &context))) { |
| 10463 | if (os_strcasecmp(token, "scan") == 0) { |
| 10464 | type |= MAC_ADDR_RAND_SCAN; |
| 10465 | } else if (os_strcasecmp(token, "sched") == 0) { |
| 10466 | type |= MAC_ADDR_RAND_SCHED_SCAN; |
| 10467 | } else if (os_strcasecmp(token, "pno") == 0) { |
| 10468 | type |= MAC_ADDR_RAND_PNO; |
| 10469 | } else if (os_strcasecmp(token, "all") == 0) { |
| 10470 | type = wpa_s->mac_addr_rand_supported; |
| 10471 | } else if (os_strncasecmp(token, "enable=", 7) == 0) { |
| 10472 | enable = atoi(token + 7); |
| 10473 | } else if (os_strncasecmp(token, "addr=", 5) == 0) { |
| 10474 | addr = _addr; |
| 10475 | if (hwaddr_aton(token + 5, addr)) { |
| 10476 | wpa_printf(MSG_INFO, |
| 10477 | "CTRL: Invalid MAC address: %s", |
| 10478 | token); |
| 10479 | return -1; |
| 10480 | } |
| 10481 | } else if (os_strncasecmp(token, "mask=", 5) == 0) { |
| 10482 | mask = _mask; |
| 10483 | if (hwaddr_aton(token + 5, mask)) { |
| 10484 | wpa_printf(MSG_INFO, |
| 10485 | "CTRL: Invalid MAC address mask: %s", |
| 10486 | token); |
| 10487 | return -1; |
| 10488 | } |
| 10489 | } else { |
| 10490 | wpa_printf(MSG_INFO, |
| 10491 | "CTRL: Invalid MAC_RAND_SCAN parameter: %s", |
| 10492 | token); |
| 10493 | return -1; |
| 10494 | } |
| 10495 | } |
| 10496 | |
| 10497 | if (!type) { |
| 10498 | wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified"); |
| 10499 | return -1; |
| 10500 | } |
| 10501 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10502 | if (enable > 1) { |
| 10503 | wpa_printf(MSG_INFO, |
| 10504 | "CTRL: MAC_RAND_SCAN enable=<0/1> not specified"); |
| 10505 | return -1; |
| 10506 | } |
| 10507 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10508 | if (!enable) |
| 10509 | return wpas_disable_mac_addr_randomization(wpa_s, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10510 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10511 | return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10512 | } |
| 10513 | |
| 10514 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 10515 | static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s, |
| 10516 | char *buf, size_t buflen) |
| 10517 | { |
| 10518 | size_t reply_len; |
| 10519 | |
| 10520 | reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen); |
| 10521 | #ifdef CONFIG_AP |
| 10522 | reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len], |
| 10523 | buflen - reply_len); |
| 10524 | #endif /* CONFIG_AP */ |
| 10525 | return reply_len; |
| 10526 | } |
| 10527 | |
| 10528 | |
| 10529 | static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s) |
| 10530 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10531 | ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 10532 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
| 10533 | #ifdef CONFIG_AP |
| 10534 | wpas_ap_pmksa_cache_flush(wpa_s); |
| 10535 | #endif /* CONFIG_AP */ |
| 10536 | } |
| 10537 | |
| 10538 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10539 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
| 10540 | |
| 10541 | static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s, |
| 10542 | const char *cmd, char *buf, size_t buflen) |
| 10543 | { |
| 10544 | struct rsn_pmksa_cache_entry *entry; |
| 10545 | struct wpa_ssid *ssid; |
| 10546 | char *pos, *pos2, *end; |
| 10547 | int ret; |
| 10548 | struct os_reltime now; |
| 10549 | |
| 10550 | ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd)); |
| 10551 | if (!ssid) |
| 10552 | return -1; |
| 10553 | |
| 10554 | pos = buf; |
| 10555 | end = buf + buflen; |
| 10556 | |
| 10557 | os_get_reltime(&now); |
| 10558 | |
| 10559 | /* |
| 10560 | * Entry format: |
| 10561 | * <BSSID> <PMKID> <PMK> <reauth_time in seconds> |
| 10562 | * <expiration in seconds> <akmp> <opportunistic> |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10563 | * [FILS Cache Identifier] |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10564 | */ |
| 10565 | |
| 10566 | for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry; |
| 10567 | entry = entry->next) { |
| 10568 | if (entry->network_ctx != ssid) |
| 10569 | continue; |
| 10570 | |
| 10571 | pos2 = pos; |
| 10572 | ret = os_snprintf(pos2, end - pos2, MACSTR " ", |
| 10573 | MAC2STR(entry->aa)); |
| 10574 | if (os_snprintf_error(end - pos2, ret)) |
| 10575 | break; |
| 10576 | pos2 += ret; |
| 10577 | |
| 10578 | pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid, |
| 10579 | PMKID_LEN); |
| 10580 | |
| 10581 | ret = os_snprintf(pos2, end - pos2, " "); |
| 10582 | if (os_snprintf_error(end - pos2, ret)) |
| 10583 | break; |
| 10584 | pos2 += ret; |
| 10585 | |
| 10586 | pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk, |
| 10587 | entry->pmk_len); |
| 10588 | |
| 10589 | ret = os_snprintf(pos2, end - pos2, " %d %d %d %d", |
| 10590 | (int) (entry->reauth_time - now.sec), |
| 10591 | (int) (entry->expiration - now.sec), |
| 10592 | entry->akmp, |
| 10593 | entry->opportunistic); |
| 10594 | if (os_snprintf_error(end - pos2, ret)) |
| 10595 | break; |
| 10596 | pos2 += ret; |
| 10597 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10598 | if (entry->fils_cache_id_set) { |
| 10599 | ret = os_snprintf(pos2, end - pos2, " %02x%02x", |
| 10600 | entry->fils_cache_id[0], |
| 10601 | entry->fils_cache_id[1]); |
| 10602 | if (os_snprintf_error(end - pos2, ret)) |
| 10603 | break; |
| 10604 | pos2 += ret; |
| 10605 | } |
| 10606 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10607 | ret = os_snprintf(pos2, end - pos2, "\n"); |
| 10608 | if (os_snprintf_error(end - pos2, ret)) |
| 10609 | break; |
| 10610 | pos2 += ret; |
| 10611 | |
| 10612 | pos = pos2; |
| 10613 | } |
| 10614 | |
| 10615 | return pos - buf; |
| 10616 | } |
| 10617 | |
| 10618 | |
| 10619 | static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s, |
| 10620 | char *cmd) |
| 10621 | { |
| 10622 | struct rsn_pmksa_cache_entry *entry; |
| 10623 | struct wpa_ssid *ssid; |
| 10624 | char *pos, *pos2; |
| 10625 | int ret = -1; |
| 10626 | struct os_reltime now; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10627 | int reauth_time = 0, expiration = 0, i; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10628 | |
| 10629 | /* |
| 10630 | * Entry format: |
| 10631 | * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds> |
| 10632 | * <expiration in seconds> <akmp> <opportunistic> |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10633 | * [FILS Cache Identifier] |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10634 | */ |
| 10635 | |
| 10636 | ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd)); |
| 10637 | if (!ssid) |
| 10638 | return -1; |
| 10639 | |
| 10640 | pos = os_strchr(cmd, ' '); |
| 10641 | if (!pos) |
| 10642 | return -1; |
| 10643 | pos++; |
| 10644 | |
| 10645 | entry = os_zalloc(sizeof(*entry)); |
| 10646 | if (!entry) |
| 10647 | return -1; |
| 10648 | |
| 10649 | if (hwaddr_aton(pos, entry->aa)) |
| 10650 | goto fail; |
| 10651 | |
| 10652 | pos = os_strchr(pos, ' '); |
| 10653 | if (!pos) |
| 10654 | goto fail; |
| 10655 | pos++; |
| 10656 | |
| 10657 | if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0) |
| 10658 | goto fail; |
| 10659 | |
| 10660 | pos = os_strchr(pos, ' '); |
| 10661 | if (!pos) |
| 10662 | goto fail; |
| 10663 | pos++; |
| 10664 | |
| 10665 | pos2 = os_strchr(pos, ' '); |
| 10666 | if (!pos2) |
| 10667 | goto fail; |
| 10668 | entry->pmk_len = (pos2 - pos) / 2; |
| 10669 | if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX || |
| 10670 | hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0) |
| 10671 | goto fail; |
| 10672 | |
| 10673 | pos = os_strchr(pos, ' '); |
| 10674 | if (!pos) |
| 10675 | goto fail; |
| 10676 | pos++; |
| 10677 | |
| 10678 | if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration, |
| 10679 | &entry->akmp, &entry->opportunistic) != 4) |
| 10680 | goto fail; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10681 | if (reauth_time > expiration) |
| 10682 | goto fail; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10683 | for (i = 0; i < 4; i++) { |
| 10684 | pos = os_strchr(pos, ' '); |
| 10685 | if (!pos) { |
| 10686 | if (i < 3) |
| 10687 | goto fail; |
| 10688 | break; |
| 10689 | } |
| 10690 | pos++; |
| 10691 | } |
| 10692 | if (pos) { |
| 10693 | if (hexstr2bin(pos, entry->fils_cache_id, |
| 10694 | FILS_CACHE_ID_LEN) < 0) |
| 10695 | goto fail; |
| 10696 | entry->fils_cache_id_set = 1; |
| 10697 | } |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10698 | os_get_reltime(&now); |
| 10699 | entry->expiration = now.sec + expiration; |
| 10700 | entry->reauth_time = now.sec + reauth_time; |
| 10701 | |
| 10702 | entry->network_ctx = ssid; |
| 10703 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10704 | entry->external = true; |
| 10705 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10706 | wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry); |
| 10707 | entry = NULL; |
| 10708 | ret = 0; |
| 10709 | fail: |
| 10710 | os_free(entry); |
| 10711 | return ret; |
| 10712 | } |
| 10713 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10714 | |
| 10715 | #ifdef CONFIG_MESH |
| 10716 | |
| 10717 | static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s, |
| 10718 | const char *cmd, char *buf, |
| 10719 | size_t buflen) |
| 10720 | { |
| 10721 | u8 spa[ETH_ALEN]; |
| 10722 | |
| 10723 | if (!wpa_s->ifmsh) |
| 10724 | return -1; |
| 10725 | |
| 10726 | if (os_strcasecmp(cmd, "any") == 0) |
| 10727 | return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen); |
| 10728 | |
| 10729 | if (hwaddr_aton(cmd, spa)) |
| 10730 | return -1; |
| 10731 | |
| 10732 | return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen); |
| 10733 | } |
| 10734 | |
| 10735 | |
| 10736 | static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s, |
| 10737 | char *cmd) |
| 10738 | { |
| 10739 | /* |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10740 | * We do not check mesh interface existence because PMKSA should be |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10741 | * stored before wpa_s->ifmsh creation to suppress commit message |
| 10742 | * creation. |
| 10743 | */ |
| 10744 | return wpas_ap_pmksa_cache_add_external(wpa_s, cmd); |
| 10745 | } |
| 10746 | |
| 10747 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10748 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
| 10749 | |
| 10750 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10751 | #ifdef CONFIG_FILS |
| 10752 | static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s, |
| 10753 | const char *cmd) |
| 10754 | { |
| 10755 | struct fils_hlp_req *req; |
| 10756 | const char *pos; |
| 10757 | |
| 10758 | /* format: <dst> <packet starting from ethertype> */ |
| 10759 | |
| 10760 | req = os_zalloc(sizeof(*req)); |
| 10761 | if (!req) |
| 10762 | return -1; |
| 10763 | |
| 10764 | if (hwaddr_aton(cmd, req->dst)) |
| 10765 | goto fail; |
| 10766 | |
| 10767 | pos = os_strchr(cmd, ' '); |
| 10768 | if (!pos) |
| 10769 | goto fail; |
| 10770 | pos++; |
| 10771 | req->pkt = wpabuf_parse_bin(pos); |
| 10772 | if (!req->pkt) |
| 10773 | goto fail; |
| 10774 | |
| 10775 | dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list); |
| 10776 | return 0; |
| 10777 | fail: |
| 10778 | wpabuf_free(req->pkt); |
| 10779 | os_free(req); |
| 10780 | return -1; |
| 10781 | } |
| 10782 | #endif /* CONFIG_FILS */ |
| 10783 | |
| 10784 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 10785 | int wpas_ctrl_cmd_debug_level(const char *cmd) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10786 | { |
| 10787 | if (os_strcmp(cmd, "PING") == 0 || |
| 10788 | os_strncmp(cmd, "BSS ", 4) == 0 || |
| 10789 | os_strncmp(cmd, "GET_NETWORK ", 12) == 0 || |
| 10790 | os_strncmp(cmd, "STATUS", 6) == 0 || |
| 10791 | os_strncmp(cmd, "STA ", 4) == 0 || |
| 10792 | os_strncmp(cmd, "STA-", 4) == 0) |
| 10793 | return MSG_EXCESSIVE; |
| 10794 | return MSG_DEBUG; |
| 10795 | } |
| 10796 | |
| 10797 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10798 | static int wpas_ctrl_iface_configure_mscs(struct wpa_supplicant *wpa_s, |
| 10799 | const char *cmd) |
| 10800 | { |
| 10801 | size_t frame_classifier_len; |
| 10802 | const char *pos, *end; |
| 10803 | struct robust_av_data *robust_av = &wpa_s->robust_av; |
| 10804 | int val; |
| 10805 | |
| 10806 | /* |
| 10807 | * format: |
| 10808 | * <add|remove|change> [up_bitmap=<hex byte>] [up_limit=<integer>] |
| 10809 | * [stream_timeout=<in TUs>] [frame_classifier=<hex bytes>] |
| 10810 | */ |
| 10811 | os_memset(robust_av, 0, sizeof(struct robust_av_data)); |
| 10812 | if (os_strncmp(cmd, "add ", 4) == 0) { |
| 10813 | robust_av->request_type = SCS_REQ_ADD; |
| 10814 | } else if (os_strcmp(cmd, "remove") == 0) { |
| 10815 | robust_av->request_type = SCS_REQ_REMOVE; |
| 10816 | robust_av->valid_config = false; |
| 10817 | return wpas_send_mscs_req(wpa_s); |
| 10818 | } else if (os_strncmp(cmd, "change ", 7) == 0) { |
| 10819 | robust_av->request_type = SCS_REQ_CHANGE; |
| 10820 | } else { |
| 10821 | return -1; |
| 10822 | } |
| 10823 | |
| 10824 | pos = os_strstr(cmd, "up_bitmap="); |
| 10825 | if (!pos) |
| 10826 | return -1; |
| 10827 | |
| 10828 | val = hex2byte(pos + 10); |
| 10829 | if (val < 0) |
| 10830 | return -1; |
| 10831 | robust_av->up_bitmap = val; |
| 10832 | |
| 10833 | pos = os_strstr(cmd, "up_limit="); |
| 10834 | if (!pos) |
| 10835 | return -1; |
| 10836 | |
| 10837 | robust_av->up_limit = atoi(pos + 9); |
| 10838 | |
| 10839 | pos = os_strstr(cmd, "stream_timeout="); |
| 10840 | if (!pos) |
| 10841 | return -1; |
| 10842 | |
| 10843 | robust_av->stream_timeout = atoi(pos + 15); |
| 10844 | if (robust_av->stream_timeout == 0) |
| 10845 | return -1; |
| 10846 | |
| 10847 | pos = os_strstr(cmd, "frame_classifier="); |
| 10848 | if (!pos) |
| 10849 | return -1; |
| 10850 | |
| 10851 | pos += 17; |
| 10852 | end = os_strchr(pos, ' '); |
| 10853 | if (!end) |
| 10854 | end = pos + os_strlen(pos); |
| 10855 | |
| 10856 | frame_classifier_len = (end - pos) / 2; |
| 10857 | if (frame_classifier_len > sizeof(robust_av->frame_classifier) || |
| 10858 | hexstr2bin(pos, robust_av->frame_classifier, frame_classifier_len)) |
| 10859 | return -1; |
| 10860 | |
| 10861 | robust_av->frame_classifier_len = frame_classifier_len; |
| 10862 | robust_av->valid_config = true; |
| 10863 | |
| 10864 | return wpas_send_mscs_req(wpa_s); |
| 10865 | } |
| 10866 | |
| 10867 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10868 | #ifdef CONFIG_PASN |
| 10869 | static int wpas_ctrl_iface_pasn_start(struct wpa_supplicant *wpa_s, char *cmd) |
| 10870 | { |
| 10871 | char *token, *context = NULL; |
| 10872 | u8 bssid[ETH_ALEN]; |
| 10873 | int akmp = -1, cipher = -1, got_bssid = 0; |
| 10874 | u16 group = 0xFFFF; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10875 | u8 *comeback = NULL; |
| 10876 | size_t comeback_len = 0; |
| 10877 | int id = 0, ret = -1; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10878 | |
| 10879 | /* |
| 10880 | * Entry format: bssid=<BSSID> akmp=<AKMP> cipher=<CIPHER> group=<group> |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10881 | * [comeback=<hexdump>] |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10882 | */ |
| 10883 | while ((token = str_token(cmd, " ", &context))) { |
| 10884 | if (os_strncmp(token, "bssid=", 6) == 0) { |
| 10885 | if (hwaddr_aton(token + 6, bssid)) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10886 | goto out; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10887 | got_bssid = 1; |
| 10888 | } else if (os_strcmp(token, "akmp=PASN") == 0) { |
| 10889 | akmp = WPA_KEY_MGMT_PASN; |
| 10890 | #ifdef CONFIG_IEEE80211R |
| 10891 | } else if (os_strcmp(token, "akmp=FT-PSK") == 0) { |
| 10892 | akmp = WPA_KEY_MGMT_FT_PSK; |
| 10893 | } else if (os_strcmp(token, "akmp=FT-EAP-SHA384") == 0) { |
| 10894 | akmp = WPA_KEY_MGMT_FT_IEEE8021X_SHA384; |
| 10895 | } else if (os_strcmp(token, "akmp=FT-EAP") == 0) { |
| 10896 | akmp = WPA_KEY_MGMT_FT_IEEE8021X; |
| 10897 | #endif /* CONFIG_IEEE80211R */ |
| 10898 | #ifdef CONFIG_SAE |
| 10899 | } else if (os_strcmp(token, "akmp=SAE") == 0) { |
| 10900 | akmp = WPA_KEY_MGMT_SAE; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 10901 | } else if (os_strcmp(token, "akmp=SAE-EXT-KEY") == 0) { |
| 10902 | akmp = WPA_KEY_MGMT_SAE_EXT_KEY; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10903 | #endif /* CONFIG_SAE */ |
| 10904 | #ifdef CONFIG_FILS |
| 10905 | } else if (os_strcmp(token, "akmp=FILS-SHA256") == 0) { |
| 10906 | akmp = WPA_KEY_MGMT_FILS_SHA256; |
| 10907 | } else if (os_strcmp(token, "akmp=FILS-SHA384") == 0) { |
| 10908 | akmp = WPA_KEY_MGMT_FILS_SHA384; |
| 10909 | #endif /* CONFIG_FILS */ |
| 10910 | } else if (os_strcmp(token, "cipher=CCMP-256") == 0) { |
| 10911 | cipher = WPA_CIPHER_CCMP_256; |
| 10912 | } else if (os_strcmp(token, "cipher=GCMP-256") == 0) { |
| 10913 | cipher = WPA_CIPHER_GCMP_256; |
| 10914 | } else if (os_strcmp(token, "cipher=CCMP") == 0) { |
| 10915 | cipher = WPA_CIPHER_CCMP; |
| 10916 | } else if (os_strcmp(token, "cipher=GCMP") == 0) { |
| 10917 | cipher = WPA_CIPHER_GCMP; |
| 10918 | } else if (os_strncmp(token, "group=", 6) == 0) { |
| 10919 | group = atoi(token + 6); |
| 10920 | } else if (os_strncmp(token, "nid=", 4) == 0) { |
| 10921 | id = atoi(token + 4); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10922 | } else if (os_strncmp(token, "comeback=", 9) == 0) { |
| 10923 | comeback_len = os_strlen(token + 9); |
| 10924 | if (comeback || !comeback_len || comeback_len % 2) |
| 10925 | goto out; |
| 10926 | |
| 10927 | comeback_len /= 2; |
| 10928 | comeback = os_malloc(comeback_len); |
| 10929 | if (!comeback || |
| 10930 | hexstr2bin(token + 9, comeback, comeback_len)) |
| 10931 | goto out; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10932 | } else { |
| 10933 | wpa_printf(MSG_DEBUG, |
| 10934 | "CTRL: PASN Invalid parameter: '%s'", |
| 10935 | token); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10936 | goto out; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10937 | } |
| 10938 | } |
| 10939 | |
| 10940 | if (!got_bssid || akmp == -1 || cipher == -1 || group == 0xFFFF) { |
| 10941 | wpa_printf(MSG_DEBUG,"CTRL: PASN missing parameter"); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10942 | goto out; |
| 10943 | } |
| 10944 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 10945 | ret = wpas_pasn_auth_start(wpa_s, wpa_s->own_addr, bssid, akmp, cipher, |
| 10946 | group, id, comeback, comeback_len); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10947 | out: |
| 10948 | os_free(comeback); |
| 10949 | return ret; |
| 10950 | } |
| 10951 | |
| 10952 | |
| 10953 | static int wpas_ctrl_iface_pasn_deauthenticate(struct wpa_supplicant *wpa_s, |
| 10954 | const char *cmd) |
| 10955 | { |
| 10956 | u8 bssid[ETH_ALEN]; |
| 10957 | |
| 10958 | if (os_strncmp(cmd, "bssid=", 6) != 0 || hwaddr_aton(cmd + 6, bssid)) { |
| 10959 | wpa_printf(MSG_DEBUG, |
| 10960 | "CTRL: PASN_DEAUTH without valid BSSID"); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10961 | return -1; |
| 10962 | } |
| 10963 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 10964 | return wpas_pasn_deauthenticate(wpa_s, wpa_s->own_addr, bssid); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10965 | } |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10966 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10967 | #endif /* CONFIG_PASN */ |
| 10968 | |
| 10969 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10970 | static int set_type4_frame_classifier(const char *cmd, |
| 10971 | struct type4_params *param) |
| 10972 | { |
| 10973 | const char *pos, *end; |
| 10974 | u8 classifier_mask = 0; |
| 10975 | int ret; |
| 10976 | char addr[INET6_ADDRSTRLEN]; |
| 10977 | size_t alen; |
| 10978 | |
| 10979 | if (os_strstr(cmd, "ip_version=ipv4")) { |
| 10980 | param->ip_version = IPV4; |
| 10981 | } else if (os_strstr(cmd, "ip_version=ipv6")) { |
| 10982 | param->ip_version = IPV6; |
| 10983 | } else { |
| 10984 | wpa_printf(MSG_ERROR, "IP version missing/invalid"); |
| 10985 | return -1; |
| 10986 | } |
| 10987 | |
| 10988 | classifier_mask |= BIT(0); |
| 10989 | |
| 10990 | pos = os_strstr(cmd, "src_ip="); |
| 10991 | if (pos) { |
| 10992 | pos += 7; |
| 10993 | end = os_strchr(pos, ' '); |
| 10994 | if (!end) |
| 10995 | end = pos + os_strlen(pos); |
| 10996 | |
| 10997 | alen = end - pos; |
| 10998 | if (alen >= INET6_ADDRSTRLEN) |
| 10999 | return -1; |
| 11000 | os_memcpy(addr, pos, alen); |
| 11001 | addr[alen] = '\0'; |
| 11002 | if (param->ip_version == IPV4) |
| 11003 | ret = inet_pton(AF_INET, addr, |
| 11004 | ¶m->ip_params.v4.src_ip); |
| 11005 | else |
| 11006 | ret = inet_pton(AF_INET6, addr, |
| 11007 | ¶m->ip_params.v6.src_ip); |
| 11008 | |
| 11009 | if (ret != 1) { |
| 11010 | wpa_printf(MSG_ERROR, |
| 11011 | "Error converting src IP address to binary ret=%d", |
| 11012 | ret); |
| 11013 | return -1; |
| 11014 | } |
| 11015 | |
| 11016 | classifier_mask |= BIT(1); |
| 11017 | } |
| 11018 | |
| 11019 | pos = os_strstr(cmd, "dst_ip="); |
| 11020 | if (pos) { |
| 11021 | pos += 7; |
| 11022 | end = os_strchr(pos, ' '); |
| 11023 | if (!end) |
| 11024 | end = pos + os_strlen(pos); |
| 11025 | |
| 11026 | alen = end - pos; |
| 11027 | if (alen >= INET6_ADDRSTRLEN) |
| 11028 | return -1; |
| 11029 | os_memcpy(addr, pos, alen); |
| 11030 | addr[alen] = '\0'; |
| 11031 | if (param->ip_version == IPV4) |
| 11032 | ret = inet_pton(AF_INET, addr, |
| 11033 | ¶m->ip_params.v4.dst_ip); |
| 11034 | else |
| 11035 | ret = inet_pton(AF_INET6, addr, |
| 11036 | ¶m->ip_params.v6.dst_ip); |
| 11037 | |
| 11038 | if (ret != 1) { |
| 11039 | wpa_printf(MSG_ERROR, |
| 11040 | "Error converting dst IP address to binary ret=%d", |
| 11041 | ret); |
| 11042 | return -1; |
| 11043 | } |
| 11044 | |
| 11045 | classifier_mask |= BIT(2); |
| 11046 | } |
| 11047 | |
| 11048 | pos = os_strstr(cmd, "src_port="); |
| 11049 | if (pos && atoi(pos + 9) > 0) { |
| 11050 | if (param->ip_version == IPV4) |
| 11051 | param->ip_params.v4.src_port = atoi(pos + 9); |
| 11052 | else |
| 11053 | param->ip_params.v6.src_port = atoi(pos + 9); |
| 11054 | classifier_mask |= BIT(3); |
| 11055 | } |
| 11056 | |
| 11057 | pos = os_strstr(cmd, "dst_port="); |
| 11058 | if (pos && atoi(pos + 9) > 0) { |
| 11059 | if (param->ip_version == IPV4) |
| 11060 | param->ip_params.v4.dst_port = atoi(pos + 9); |
| 11061 | else |
| 11062 | param->ip_params.v6.dst_port = atoi(pos + 9); |
| 11063 | classifier_mask |= BIT(4); |
| 11064 | } |
| 11065 | |
| 11066 | pos = os_strstr(cmd, "dscp="); |
| 11067 | if (pos && atoi(pos + 5) > 0) { |
| 11068 | if (param->ip_version == IPV4) |
| 11069 | param->ip_params.v4.dscp = atoi(pos + 5); |
| 11070 | else |
| 11071 | param->ip_params.v6.dscp = atoi(pos + 5); |
| 11072 | classifier_mask |= BIT(5); |
| 11073 | } |
| 11074 | |
| 11075 | if (param->ip_version == IPV4) { |
| 11076 | pos = os_strstr(cmd, "protocol="); |
| 11077 | if (pos) { |
| 11078 | if (os_strstr(pos, "udp")) { |
| 11079 | param->ip_params.v4.protocol = 17; |
| 11080 | } else if (os_strstr(pos, "tcp")) { |
| 11081 | param->ip_params.v4.protocol = 6; |
| 11082 | } else if (os_strstr(pos, "esp")) { |
| 11083 | param->ip_params.v4.protocol = 50; |
| 11084 | } else { |
| 11085 | wpa_printf(MSG_ERROR, "Invalid protocol"); |
| 11086 | return -1; |
| 11087 | } |
| 11088 | classifier_mask |= BIT(6); |
| 11089 | } |
| 11090 | } else { |
| 11091 | pos = os_strstr(cmd, "next_header="); |
| 11092 | if (pos) { |
| 11093 | if (os_strstr(pos, "udp")) { |
| 11094 | param->ip_params.v6.next_header = 17; |
| 11095 | } else if (os_strstr(pos, "tcp")) { |
| 11096 | param->ip_params.v6.next_header = 6; |
| 11097 | } else if (os_strstr(pos, "esp")) { |
| 11098 | param->ip_params.v6.next_header = 50; |
| 11099 | } else { |
| 11100 | wpa_printf(MSG_ERROR, "Invalid next header"); |
| 11101 | return -1; |
| 11102 | } |
| 11103 | |
| 11104 | classifier_mask |= BIT(6); |
| 11105 | } |
| 11106 | |
| 11107 | pos = os_strstr(cmd, "flow_label="); |
| 11108 | if (pos) { |
| 11109 | pos += 11; |
| 11110 | end = os_strchr(pos, ' '); |
| 11111 | if (!end) |
| 11112 | end = pos + os_strlen(pos); |
| 11113 | |
| 11114 | if (end - pos != 6 || |
| 11115 | hexstr2bin(pos, param->ip_params.v6.flow_label, |
| 11116 | 3) || |
| 11117 | param->ip_params.v6.flow_label[0] > 0x0F) { |
| 11118 | wpa_printf(MSG_ERROR, "Invalid flow label"); |
| 11119 | return -1; |
| 11120 | } |
| 11121 | |
| 11122 | classifier_mask |= BIT(7); |
| 11123 | } |
| 11124 | } |
| 11125 | |
| 11126 | param->classifier_mask = classifier_mask; |
| 11127 | return 0; |
| 11128 | } |
| 11129 | |
| 11130 | |
| 11131 | static int set_type10_frame_classifier(const char *cmd, |
| 11132 | struct type10_params *param) |
| 11133 | { |
| 11134 | const char *pos, *end; |
| 11135 | size_t filter_len; |
| 11136 | |
| 11137 | pos = os_strstr(cmd, "prot_instance="); |
| 11138 | if (!pos) { |
| 11139 | wpa_printf(MSG_ERROR, "Protocol instance missing"); |
| 11140 | return -1; |
| 11141 | } |
| 11142 | param->prot_instance = atoi(pos + 14); |
| 11143 | |
| 11144 | pos = os_strstr(cmd, "prot_number="); |
| 11145 | if (!pos) { |
| 11146 | wpa_printf(MSG_ERROR, "Protocol number missing"); |
| 11147 | return -1; |
| 11148 | } |
| 11149 | if (os_strstr(pos, "udp")) { |
| 11150 | param->prot_number = 17; |
| 11151 | } else if (os_strstr(pos, "tcp")) { |
| 11152 | param->prot_number = 6; |
| 11153 | } else if (os_strstr(pos, "esp")) { |
| 11154 | param->prot_number = 50; |
| 11155 | } else { |
| 11156 | wpa_printf(MSG_ERROR, "Invalid protocol number"); |
| 11157 | return -1; |
| 11158 | } |
| 11159 | |
| 11160 | pos = os_strstr(cmd, "filter_value="); |
| 11161 | if (!pos) { |
| 11162 | wpa_printf(MSG_ERROR, |
| 11163 | "Classifier parameter filter_value missing"); |
| 11164 | return -1; |
| 11165 | } |
| 11166 | |
| 11167 | pos += 13; |
| 11168 | end = os_strchr(pos, ' '); |
| 11169 | if (!end) |
| 11170 | end = pos + os_strlen(pos); |
| 11171 | |
| 11172 | filter_len = (end - pos) / 2; |
| 11173 | param->filter_value = os_malloc(filter_len); |
| 11174 | if (!param->filter_value) |
| 11175 | return -1; |
| 11176 | |
| 11177 | if (hexstr2bin(pos, param->filter_value, filter_len)) { |
| 11178 | wpa_printf(MSG_ERROR, "Invalid filter_value %s", pos); |
| 11179 | goto free; |
| 11180 | } |
| 11181 | |
| 11182 | pos = os_strstr(cmd, "filter_mask="); |
| 11183 | if (!pos) { |
| 11184 | wpa_printf(MSG_ERROR, |
| 11185 | "Classifier parameter filter_mask missing"); |
| 11186 | goto free; |
| 11187 | } |
| 11188 | |
| 11189 | pos += 12; |
| 11190 | end = os_strchr(pos, ' '); |
| 11191 | if (!end) |
| 11192 | end = pos + os_strlen(pos); |
| 11193 | |
| 11194 | if (filter_len != (size_t) (end - pos) / 2) { |
| 11195 | wpa_printf(MSG_ERROR, |
| 11196 | "Filter mask length mismatch expected=%zu received=%zu", |
| 11197 | filter_len, (size_t) (end - pos) / 2); |
| 11198 | goto free; |
| 11199 | } |
| 11200 | |
| 11201 | param->filter_mask = os_malloc(filter_len); |
| 11202 | if (!param->filter_mask) |
| 11203 | goto free; |
| 11204 | |
| 11205 | if (hexstr2bin(pos, param->filter_mask, filter_len)) { |
| 11206 | wpa_printf(MSG_ERROR, "Invalid filter mask %s", pos); |
| 11207 | os_free(param->filter_mask); |
| 11208 | param->filter_mask = NULL; |
| 11209 | goto free; |
| 11210 | } |
| 11211 | |
| 11212 | param->filter_len = filter_len; |
| 11213 | return 0; |
| 11214 | free: |
| 11215 | os_free(param->filter_value); |
| 11216 | param->filter_value = NULL; |
| 11217 | return -1; |
| 11218 | } |
| 11219 | |
| 11220 | |
| 11221 | static int scs_parse_type4(struct tclas_element *elem, const char *pos) |
| 11222 | { |
| 11223 | struct type4_params type4_param = { 0 }; |
| 11224 | |
| 11225 | if (set_type4_frame_classifier(pos, &type4_param) == -1) { |
| 11226 | wpa_printf(MSG_ERROR, "Failed to set frame_classifier 4"); |
| 11227 | return -1; |
| 11228 | } |
| 11229 | |
| 11230 | os_memcpy(&elem->frame_classifier.type4_param, |
| 11231 | &type4_param, sizeof(struct type4_params)); |
| 11232 | return 0; |
| 11233 | } |
| 11234 | |
| 11235 | |
| 11236 | static int scs_parse_type10(struct tclas_element *elem, const char *pos) |
| 11237 | { |
| 11238 | struct type10_params type10_param = { 0 }; |
| 11239 | |
| 11240 | if (set_type10_frame_classifier(pos, &type10_param) == -1) { |
| 11241 | wpa_printf(MSG_ERROR, "Failed to set frame_classifier 10"); |
| 11242 | return -1; |
| 11243 | } |
| 11244 | |
| 11245 | os_memcpy(&elem->frame_classifier.type10_param, |
| 11246 | &type10_param, sizeof(struct type10_params)); |
| 11247 | return 0; |
| 11248 | } |
| 11249 | |
| 11250 | |
| 11251 | static int wpas_ctrl_iface_configure_scs(struct wpa_supplicant *wpa_s, |
| 11252 | char *cmd) |
| 11253 | { |
| 11254 | char *pos1, *pos; |
| 11255 | struct scs_robust_av_data *scs_data = &wpa_s->scs_robust_av_req; |
| 11256 | struct scs_desc_elem desc_elem = { 0 }; |
| 11257 | int val; |
| 11258 | unsigned int num_scs_desc = 0; |
| 11259 | |
| 11260 | if (wpa_s->ongoing_scs_req) { |
| 11261 | wpa_printf(MSG_ERROR, "%s: SCS Request already in queue", |
| 11262 | __func__); |
| 11263 | return -1; |
| 11264 | } |
| 11265 | |
| 11266 | /** |
| 11267 | * format: |
| 11268 | * [scs_id=<decimal number>] <add|remove|change> [scs_up=<0-7>] |
| 11269 | * [classifier_type=<4|10>] |
| 11270 | * [classifier params based on classifier type] |
| 11271 | * [tclas_processing=<0|1>] [scs_id=<decimal number>] ... |
| 11272 | */ |
| 11273 | pos1 = os_strstr(cmd, "scs_id="); |
| 11274 | if (!pos1) { |
| 11275 | wpa_printf(MSG_ERROR, "SCSID not present"); |
| 11276 | return -1; |
| 11277 | } |
| 11278 | |
| 11279 | free_up_scs_desc(scs_data); |
| 11280 | |
| 11281 | while (pos1) { |
| 11282 | struct scs_desc_elem *n1; |
| 11283 | struct active_scs_elem *active_scs_desc; |
| 11284 | char *next_scs_desc; |
| 11285 | unsigned int num_tclas_elem = 0; |
| 11286 | bool scsid_active = false; |
| 11287 | |
| 11288 | desc_elem.scs_id = atoi(pos1 + 7); |
| 11289 | pos1 += 7; |
| 11290 | |
| 11291 | next_scs_desc = os_strstr(pos1, "scs_id="); |
| 11292 | if (next_scs_desc) { |
| 11293 | char temp[20]; |
| 11294 | |
| 11295 | os_snprintf(temp, sizeof(temp), "scs_id=%d ", |
| 11296 | desc_elem.scs_id); |
| 11297 | if (os_strstr(next_scs_desc, temp)) { |
| 11298 | wpa_printf(MSG_ERROR, |
| 11299 | "Multiple SCS descriptors configured with same SCSID(=%d)", |
| 11300 | desc_elem.scs_id); |
| 11301 | goto free_scs_desc; |
| 11302 | } |
| 11303 | pos1[next_scs_desc - pos1 - 1] = '\0'; |
| 11304 | } |
| 11305 | |
| 11306 | dl_list_for_each(active_scs_desc, &wpa_s->active_scs_ids, |
| 11307 | struct active_scs_elem, list) { |
| 11308 | if (desc_elem.scs_id == active_scs_desc->scs_id) { |
| 11309 | scsid_active = true; |
| 11310 | break; |
| 11311 | } |
| 11312 | } |
| 11313 | |
| 11314 | if (os_strstr(pos1, "add ")) { |
| 11315 | desc_elem.request_type = SCS_REQ_ADD; |
| 11316 | if (scsid_active) { |
| 11317 | wpa_printf(MSG_ERROR, "SCSID %d already active", |
| 11318 | desc_elem.scs_id); |
| 11319 | return -1; |
| 11320 | } |
| 11321 | } else if (os_strstr(pos1, "remove")) { |
| 11322 | desc_elem.request_type = SCS_REQ_REMOVE; |
| 11323 | if (!scsid_active) { |
| 11324 | wpa_printf(MSG_ERROR, "SCSID %d not active", |
| 11325 | desc_elem.scs_id); |
| 11326 | return -1; |
| 11327 | } |
| 11328 | goto scs_desc_end; |
| 11329 | } else if (os_strstr(pos1, "change ")) { |
| 11330 | desc_elem.request_type = SCS_REQ_CHANGE; |
| 11331 | if (!scsid_active) { |
| 11332 | wpa_printf(MSG_ERROR, "SCSID %d not active", |
| 11333 | desc_elem.scs_id); |
| 11334 | return -1; |
| 11335 | } |
| 11336 | } else { |
| 11337 | wpa_printf(MSG_ERROR, "SCS Request type invalid"); |
| 11338 | goto free_scs_desc; |
| 11339 | } |
| 11340 | |
| 11341 | pos1 = os_strstr(pos1, "scs_up="); |
| 11342 | if (!pos1) { |
| 11343 | wpa_printf(MSG_ERROR, |
| 11344 | "Intra-Access user priority not present"); |
| 11345 | goto free_scs_desc; |
| 11346 | } |
| 11347 | |
| 11348 | val = atoi(pos1 + 7); |
| 11349 | if (val < 0 || val > 7) { |
| 11350 | wpa_printf(MSG_ERROR, |
| 11351 | "Intra-Access user priority invalid %d", |
| 11352 | val); |
| 11353 | goto free_scs_desc; |
| 11354 | } |
| 11355 | |
| 11356 | desc_elem.intra_access_priority = val; |
| 11357 | desc_elem.scs_up_avail = true; |
| 11358 | |
| 11359 | pos = os_strstr(pos1, "classifier_type="); |
| 11360 | if (!pos) { |
| 11361 | wpa_printf(MSG_ERROR, "classifier type empty"); |
| 11362 | goto free_scs_desc; |
| 11363 | } |
| 11364 | |
| 11365 | while (pos) { |
| 11366 | struct tclas_element elem = { 0 }, *n; |
| 11367 | char *next_tclas_elem; |
| 11368 | |
| 11369 | val = atoi(pos + 16); |
| 11370 | if (val != 4 && val != 10) { |
| 11371 | wpa_printf(MSG_ERROR, |
| 11372 | "classifier type invalid %d", val); |
| 11373 | goto free_scs_desc; |
| 11374 | } |
| 11375 | |
| 11376 | elem.classifier_type = val; |
| 11377 | pos += 16; |
| 11378 | |
| 11379 | next_tclas_elem = os_strstr(pos, "classifier_type="); |
| 11380 | if (next_tclas_elem) { |
| 11381 | pos1 = next_tclas_elem; |
| 11382 | pos[next_tclas_elem - pos - 1] = '\0'; |
| 11383 | } |
| 11384 | |
| 11385 | switch (val) { |
| 11386 | case 4: |
| 11387 | if (scs_parse_type4(&elem, pos) < 0) |
| 11388 | goto free_scs_desc; |
| 11389 | break; |
| 11390 | case 10: |
| 11391 | if (scs_parse_type10(&elem, pos) < 0) |
| 11392 | goto free_scs_desc; |
| 11393 | break; |
| 11394 | } |
| 11395 | |
| 11396 | n = os_realloc(desc_elem.tclas_elems, |
| 11397 | (num_tclas_elem + 1) * sizeof(elem)); |
| 11398 | if (!n) |
| 11399 | goto free_scs_desc; |
| 11400 | |
| 11401 | desc_elem.tclas_elems = n; |
| 11402 | os_memcpy((u8 *) desc_elem.tclas_elems + |
| 11403 | num_tclas_elem * sizeof(elem), |
| 11404 | &elem, sizeof(elem)); |
| 11405 | num_tclas_elem++; |
| 11406 | desc_elem.num_tclas_elem = num_tclas_elem; |
| 11407 | pos = next_tclas_elem; |
| 11408 | } |
| 11409 | |
| 11410 | if (desc_elem.num_tclas_elem > 1) { |
| 11411 | pos1 = os_strstr(pos1, "tclas_processing="); |
| 11412 | if (!pos1) { |
| 11413 | wpa_printf(MSG_ERROR, "tclas_processing empty"); |
| 11414 | goto free_scs_desc; |
| 11415 | } |
| 11416 | |
| 11417 | val = atoi(pos1 + 17); |
| 11418 | if (val != 0 && val != 1) { |
| 11419 | wpa_printf(MSG_ERROR, |
| 11420 | "tclas_processing invalid"); |
| 11421 | goto free_scs_desc; |
| 11422 | } |
| 11423 | |
| 11424 | desc_elem.tclas_processing = val; |
| 11425 | } |
| 11426 | |
| 11427 | scs_desc_end: |
| 11428 | n1 = os_realloc(scs_data->scs_desc_elems, (num_scs_desc + 1) * |
| 11429 | sizeof(struct scs_desc_elem)); |
| 11430 | if (!n1) |
| 11431 | goto free_scs_desc; |
| 11432 | |
| 11433 | scs_data->scs_desc_elems = n1; |
| 11434 | os_memcpy((u8 *) scs_data->scs_desc_elems + num_scs_desc * |
| 11435 | sizeof(desc_elem), &desc_elem, sizeof(desc_elem)); |
| 11436 | num_scs_desc++; |
| 11437 | scs_data->num_scs_desc = num_scs_desc; |
| 11438 | pos1 = next_scs_desc; |
| 11439 | os_memset(&desc_elem, 0, sizeof(desc_elem)); |
| 11440 | } |
| 11441 | |
| 11442 | return wpas_send_scs_req(wpa_s); |
| 11443 | |
| 11444 | free_scs_desc: |
| 11445 | free_up_tclas_elem(&desc_elem); |
| 11446 | free_up_scs_desc(scs_data); |
| 11447 | return -1; |
| 11448 | } |
| 11449 | |
| 11450 | |
| 11451 | static int wpas_ctrl_iface_send_dscp_resp(struct wpa_supplicant *wpa_s, |
| 11452 | const char *cmd) |
| 11453 | { |
| 11454 | char *pos; |
| 11455 | struct dscp_policy_status *policy = NULL, *n; |
| 11456 | int num_policies = 0, ret = -1; |
| 11457 | struct dscp_resp_data resp_data; |
| 11458 | |
| 11459 | /* |
| 11460 | * format: |
| 11461 | * <[reset]>/<[solicited] [policy_id=1 status=0...]> [more] |
| 11462 | */ |
| 11463 | |
| 11464 | os_memset(&resp_data, 0, sizeof(resp_data)); |
| 11465 | |
| 11466 | resp_data.more = os_strstr(cmd, "more") != NULL; |
| 11467 | |
| 11468 | if (os_strstr(cmd, "reset")) { |
| 11469 | resp_data.reset = true; |
| 11470 | resp_data.solicited = false; |
| 11471 | goto send_resp; |
| 11472 | } |
| 11473 | |
| 11474 | resp_data.solicited = os_strstr(cmd, "solicited") != NULL; |
| 11475 | |
| 11476 | pos = os_strstr(cmd, "policy_id="); |
| 11477 | while (pos) { |
| 11478 | n = os_realloc(policy, (num_policies + 1) * sizeof(*policy)); |
| 11479 | if (!n) |
| 11480 | goto fail; |
| 11481 | |
| 11482 | policy = n; |
| 11483 | pos += 10; |
| 11484 | policy[num_policies].id = atoi(pos); |
| 11485 | if (policy[num_policies].id == 0) { |
| 11486 | wpa_printf(MSG_ERROR, "DSCP: Invalid policy id"); |
| 11487 | goto fail; |
| 11488 | } |
| 11489 | |
| 11490 | pos = os_strstr(pos, "status="); |
| 11491 | if (!pos) { |
| 11492 | wpa_printf(MSG_ERROR, |
| 11493 | "DSCP: Status is not found for a policy"); |
| 11494 | goto fail; |
| 11495 | } |
| 11496 | |
| 11497 | pos += 7; |
| 11498 | policy[num_policies].status = atoi(pos); |
| 11499 | num_policies++; |
| 11500 | |
| 11501 | pos = os_strstr(pos, "policy_id"); |
| 11502 | } |
| 11503 | |
| 11504 | resp_data.policy = policy; |
| 11505 | resp_data.num_policies = num_policies; |
| 11506 | send_resp: |
| 11507 | ret = wpas_send_dscp_response(wpa_s, &resp_data); |
| 11508 | if (ret) |
| 11509 | wpa_printf(MSG_ERROR, "DSCP: Failed to send DSCP response"); |
| 11510 | fail: |
| 11511 | os_free(policy); |
| 11512 | return ret; |
| 11513 | } |
| 11514 | |
| 11515 | |
| 11516 | static int wpas_ctrl_iface_send_dscp_query(struct wpa_supplicant *wpa_s, |
| 11517 | const char *cmd) |
| 11518 | { |
| 11519 | char *pos; |
| 11520 | |
| 11521 | /* |
| 11522 | * format: |
| 11523 | * Wildcard DSCP query |
| 11524 | * <wildcard> |
| 11525 | * |
| 11526 | * DSCP query with a domain name attribute: |
| 11527 | * [domain_name=<string>] |
| 11528 | */ |
| 11529 | |
| 11530 | if (os_strstr(cmd, "wildcard")) { |
| 11531 | wpa_printf(MSG_DEBUG, "QM: Send wildcard DSCP policy query"); |
| 11532 | return wpas_send_dscp_query(wpa_s, NULL, 0); |
| 11533 | } |
| 11534 | |
| 11535 | pos = os_strstr(cmd, "domain_name="); |
| 11536 | if (!pos || !os_strlen(pos + 12)) { |
| 11537 | wpa_printf(MSG_ERROR, "QM: Domain name not preset"); |
| 11538 | return -1; |
| 11539 | } |
| 11540 | |
| 11541 | return wpas_send_dscp_query(wpa_s, pos + 12, os_strlen(pos + 12)); |
| 11542 | } |
| 11543 | |
| 11544 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 11545 | static int wpas_ctrl_iface_mlo_signal_poll(struct wpa_supplicant *wpa_s, |
| 11546 | char *buf, size_t buflen) |
| 11547 | { |
| 11548 | int ret, i; |
| 11549 | char *pos, *end; |
| 11550 | struct wpa_mlo_signal_info mlo_si; |
| 11551 | |
| 11552 | if (!wpa_s->valid_links) |
| 11553 | return -1; |
| 11554 | |
| 11555 | ret = wpa_drv_mlo_signal_poll(wpa_s, &mlo_si); |
| 11556 | if (ret) |
| 11557 | return -1; |
| 11558 | |
| 11559 | pos = buf; |
| 11560 | end = buf + buflen; |
| 11561 | |
| 11562 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 11563 | if (!(mlo_si.valid_links & BIT(i))) |
| 11564 | continue; |
| 11565 | |
| 11566 | ret = os_snprintf(pos, end - pos, |
| 11567 | "LINK_ID=%d\nRSSI=%d\nLINKSPEED=%d\n" |
| 11568 | "NOISE=%d\nFREQUENCY=%u\n", |
| 11569 | i, mlo_si.links[i].current_signal, |
| 11570 | mlo_si.links[i].current_txrate / 1000, |
| 11571 | mlo_si.links[i].current_noise, |
| 11572 | mlo_si.links[i].frequency); |
| 11573 | if (os_snprintf_error(end - pos, ret)) |
| 11574 | return -1; |
| 11575 | pos += ret; |
| 11576 | |
| 11577 | if (mlo_si.links[i].chanwidth != CHAN_WIDTH_UNKNOWN) { |
| 11578 | ret = os_snprintf(pos, end - pos, "WIDTH=%s\n", |
| 11579 | channel_width_to_string( |
| 11580 | mlo_si.links[i].chanwidth)); |
| 11581 | if (os_snprintf_error(end - pos, ret)) |
| 11582 | return -1; |
| 11583 | pos += ret; |
| 11584 | } |
| 11585 | |
| 11586 | if (mlo_si.links[i].center_frq1 > 0) { |
| 11587 | ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n", |
| 11588 | mlo_si.links[i].center_frq1); |
| 11589 | if (os_snprintf_error(end - pos, ret)) |
| 11590 | return -1; |
| 11591 | pos += ret; |
| 11592 | } |
| 11593 | |
| 11594 | if (mlo_si.links[i].center_frq2 > 0) { |
| 11595 | ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n", |
| 11596 | mlo_si.links[i].center_frq2); |
| 11597 | if (os_snprintf_error(end - pos, ret)) |
| 11598 | return -1; |
| 11599 | pos += ret; |
| 11600 | } |
| 11601 | |
| 11602 | if (mlo_si.links[i].avg_signal) { |
| 11603 | ret = os_snprintf(pos, end - pos, |
| 11604 | "AVG_RSSI=%d\n", |
| 11605 | mlo_si.links[i].avg_signal); |
| 11606 | if (os_snprintf_error(end - pos, ret)) |
| 11607 | return -1; |
| 11608 | pos += ret; |
| 11609 | } |
| 11610 | |
| 11611 | if (mlo_si.links[i].avg_beacon_signal) { |
| 11612 | ret = os_snprintf(pos, end - pos, |
| 11613 | "AVG_BEACON_RSSI=%d\n", |
| 11614 | mlo_si.links[i].avg_beacon_signal); |
| 11615 | if (os_snprintf_error(end - pos, ret)) |
| 11616 | return -1; |
| 11617 | pos += ret; |
| 11618 | } |
| 11619 | } |
| 11620 | |
| 11621 | return pos - buf; |
| 11622 | } |
| 11623 | |
| 11624 | |
| 11625 | static int wpas_ctrl_iface_mlo_status(struct wpa_supplicant *wpa_s, |
| 11626 | char *buf, size_t buflen) |
| 11627 | { |
| 11628 | int ret, i; |
| 11629 | char *pos, *end; |
| 11630 | |
| 11631 | if (!wpa_s->valid_links) |
| 11632 | return -1; |
| 11633 | |
| 11634 | pos = buf; |
| 11635 | end = buf + buflen; |
| 11636 | |
| 11637 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 11638 | if (!(wpa_s->valid_links & BIT(i))) |
| 11639 | continue; |
| 11640 | |
| 11641 | ret = os_snprintf(pos, end - pos, "link_id=%d\nfreq=%u\n" |
| 11642 | "ap_link_addr=" MACSTR |
| 11643 | "\nsta_link_addr=" MACSTR "\n", |
| 11644 | i, wpa_s->links[i].freq, |
| 11645 | MAC2STR(wpa_s->links[i].bssid), |
| 11646 | MAC2STR(wpa_s->links[i].addr)); |
| 11647 | if (os_snprintf_error(end - pos, ret)) |
| 11648 | return pos - buf; |
| 11649 | pos += ret; |
| 11650 | } |
| 11651 | |
| 11652 | return pos - buf; |
| 11653 | } |
| 11654 | |
| 11655 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11656 | char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, |
| 11657 | char *buf, size_t *resp_len) |
| 11658 | { |
| 11659 | char *reply; |
| 11660 | const int reply_size = 4096; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11661 | int reply_len; |
| 11662 | |
| 11663 | 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] | 11664 | os_strncmp(buf, "SET_NETWORK ", 12) == 0 || |
| 11665 | os_strncmp(buf, "PMKSA_ADD ", 10) == 0 || |
| 11666 | os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11667 | if (wpa_debug_show_keys) |
| 11668 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11669 | "Control interface command '%s'", buf); |
| 11670 | else |
| 11671 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11672 | "Control interface command '%s [REMOVED]'", |
| 11673 | os_strncmp(buf, WPA_CTRL_RSP, |
| 11674 | os_strlen(WPA_CTRL_RSP)) == 0 ? |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11675 | WPA_CTRL_RSP : |
| 11676 | (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ? |
| 11677 | "SET_NETWORK" : "key-add")); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11678 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 || |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 11679 | os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11680 | wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", |
| 11681 | (const u8 *) buf, os_strlen(buf)); |
| 11682 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11683 | int level = wpas_ctrl_cmd_debug_level(buf); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 11684 | wpa_dbg(wpa_s, level, "Control interface command '%s'", buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11685 | } |
| 11686 | |
| 11687 | reply = os_malloc(reply_size); |
| 11688 | if (reply == NULL) { |
| 11689 | *resp_len = 1; |
| 11690 | return NULL; |
| 11691 | } |
| 11692 | |
| 11693 | os_memcpy(reply, "OK\n", 3); |
| 11694 | reply_len = 3; |
| 11695 | |
| 11696 | if (os_strcmp(buf, "PING") == 0) { |
| 11697 | os_memcpy(reply, "PONG\n", 5); |
| 11698 | reply_len = 5; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 11699 | } else if (os_strcmp(buf, "IFNAME") == 0) { |
| 11700 | reply_len = os_strlen(wpa_s->ifname); |
| 11701 | os_memcpy(reply, wpa_s->ifname, reply_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11702 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
| 11703 | if (wpa_debug_reopen_file() < 0) |
| 11704 | reply_len = -1; |
| 11705 | } else if (os_strncmp(buf, "NOTE ", 5) == 0) { |
| 11706 | wpa_printf(MSG_INFO, "NOTE: %s", buf + 5); |
| 11707 | } else if (os_strcmp(buf, "MIB") == 0) { |
| 11708 | reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); |
| 11709 | if (reply_len >= 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11710 | reply_len += eapol_sm_get_mib(wpa_s->eapol, |
| 11711 | reply + reply_len, |
| 11712 | reply_size - reply_len); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11713 | #ifdef CONFIG_MACSEC |
| 11714 | reply_len += ieee802_1x_kay_get_mib( |
| 11715 | wpa_s->kay, reply + reply_len, |
| 11716 | reply_size - reply_len); |
| 11717 | #endif /* CONFIG_MACSEC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11718 | } |
| 11719 | } else if (os_strncmp(buf, "STATUS", 6) == 0) { |
| 11720 | reply_len = wpa_supplicant_ctrl_iface_status( |
| 11721 | wpa_s, buf + 6, reply, reply_size); |
| 11722 | } else if (os_strcmp(buf, "PMKSA") == 0) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 11723 | reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11724 | } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 11725 | wpas_ctrl_iface_pmksa_flush(wpa_s); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 11726 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
| 11727 | } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) { |
| 11728 | reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10, |
| 11729 | reply, reply_size); |
| 11730 | } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) { |
| 11731 | if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0) |
| 11732 | reply_len = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 11733 | #ifdef CONFIG_MESH |
| 11734 | } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) { |
| 11735 | reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15, |
| 11736 | reply, reply_size); |
| 11737 | } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) { |
| 11738 | if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0) |
| 11739 | reply_len = -1; |
| 11740 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 11741 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11742 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
| 11743 | if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) |
| 11744 | reply_len = -1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 11745 | } else if (os_strncmp(buf, "DUMP", 4) == 0) { |
| 11746 | reply_len = wpa_config_dump_values(wpa_s->conf, |
| 11747 | reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11748 | } else if (os_strncmp(buf, "GET ", 4) == 0) { |
| 11749 | reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4, |
| 11750 | reply, reply_size); |
| 11751 | } else if (os_strcmp(buf, "LOGON") == 0) { |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 11752 | eapol_sm_notify_logoff(wpa_s->eapol, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11753 | } else if (os_strcmp(buf, "LOGOFF") == 0) { |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 11754 | eapol_sm_notify_logoff(wpa_s->eapol, true); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11755 | } else if (os_strcmp(buf, "REASSOCIATE") == 0) { |
| 11756 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 11757 | reply_len = -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 11758 | else |
| 11759 | wpas_request_connection(wpa_s); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 11760 | } else if (os_strcmp(buf, "REATTACH") == 0) { |
| 11761 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED || |
| 11762 | !wpa_s->current_ssid) |
| 11763 | reply_len = -1; |
| 11764 | else { |
| 11765 | wpa_s->reattach = 1; |
| 11766 | wpas_request_connection(wpa_s); |
| 11767 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11768 | } else if (os_strcmp(buf, "RECONNECT") == 0) { |
| 11769 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 11770 | reply_len = -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 11771 | else if (wpa_s->disconnected) |
| 11772 | wpas_request_connection(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11773 | #ifdef IEEE8021X_EAPOL |
| 11774 | } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { |
| 11775 | if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) |
| 11776 | reply_len = -1; |
| 11777 | #endif /* IEEE8021X_EAPOL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11778 | #ifdef CONFIG_IEEE80211R |
| 11779 | } else if (os_strncmp(buf, "FT_DS ", 6) == 0) { |
| 11780 | if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6)) |
| 11781 | reply_len = -1; |
| 11782 | #endif /* CONFIG_IEEE80211R */ |
| 11783 | #ifdef CONFIG_WPS |
| 11784 | } else if (os_strcmp(buf, "WPS_PBC") == 0) { |
| 11785 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL); |
| 11786 | if (res == -2) { |
| 11787 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); |
| 11788 | reply_len = 17; |
| 11789 | } else if (res) |
| 11790 | reply_len = -1; |
| 11791 | } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) { |
| 11792 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8); |
| 11793 | if (res == -2) { |
| 11794 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); |
| 11795 | reply_len = 17; |
| 11796 | } else if (res) |
| 11797 | reply_len = -1; |
| 11798 | } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) { |
| 11799 | reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8, |
| 11800 | reply, |
| 11801 | reply_size); |
| 11802 | } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) { |
| 11803 | reply_len = wpa_supplicant_ctrl_iface_wps_check_pin( |
| 11804 | wpa_s, buf + 14, reply, reply_size); |
| 11805 | } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { |
| 11806 | if (wpas_wps_cancel(wpa_s)) |
| 11807 | reply_len = -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11808 | #ifdef CONFIG_WPS_NFC |
| 11809 | } else if (os_strcmp(buf, "WPS_NFC") == 0) { |
| 11810 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL)) |
| 11811 | reply_len = -1; |
| 11812 | } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) { |
| 11813 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8)) |
| 11814 | reply_len = -1; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 11815 | } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) { |
| 11816 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token( |
| 11817 | wpa_s, buf + 21, reply, reply_size); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11818 | } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) { |
| 11819 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token( |
| 11820 | wpa_s, buf + 14, reply, reply_size); |
| 11821 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) { |
| 11822 | if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s, |
| 11823 | buf + 17)) |
| 11824 | reply_len = -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 11825 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) { |
| 11826 | reply_len = wpas_ctrl_nfc_get_handover_req( |
| 11827 | wpa_s, buf + 21, reply, reply_size); |
| 11828 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) { |
| 11829 | reply_len = wpas_ctrl_nfc_get_handover_sel( |
| 11830 | wpa_s, buf + 21, reply, reply_size); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 11831 | } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) { |
| 11832 | if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20)) |
| 11833 | reply_len = -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11834 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11835 | } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) { |
| 11836 | if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8)) |
| 11837 | reply_len = -1; |
| 11838 | #ifdef CONFIG_AP |
| 11839 | } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) { |
| 11840 | reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin( |
| 11841 | wpa_s, buf + 11, reply, reply_size); |
| 11842 | #endif /* CONFIG_AP */ |
| 11843 | #ifdef CONFIG_WPS_ER |
| 11844 | } else if (os_strcmp(buf, "WPS_ER_START") == 0) { |
| 11845 | if (wpas_wps_er_start(wpa_s, NULL)) |
| 11846 | reply_len = -1; |
| 11847 | } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) { |
| 11848 | if (wpas_wps_er_start(wpa_s, buf + 13)) |
| 11849 | reply_len = -1; |
| 11850 | } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11851 | wpas_wps_er_stop(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11852 | } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) { |
| 11853 | if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11)) |
| 11854 | reply_len = -1; |
| 11855 | } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) { |
| 11856 | int ret = wpas_wps_er_pbc(wpa_s, buf + 11); |
| 11857 | if (ret == -2) { |
| 11858 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); |
| 11859 | reply_len = 17; |
| 11860 | } else if (ret == -3) { |
| 11861 | os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18); |
| 11862 | reply_len = 18; |
| 11863 | } else if (ret == -4) { |
| 11864 | os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20); |
| 11865 | reply_len = 20; |
| 11866 | } else if (ret) |
| 11867 | reply_len = -1; |
| 11868 | } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) { |
| 11869 | if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13)) |
| 11870 | reply_len = -1; |
| 11871 | } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) { |
| 11872 | if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s, |
| 11873 | buf + 18)) |
| 11874 | reply_len = -1; |
| 11875 | } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) { |
| 11876 | if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14)) |
| 11877 | reply_len = -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11878 | #ifdef CONFIG_WPS_NFC |
| 11879 | } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) { |
| 11880 | reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( |
| 11881 | wpa_s, buf + 24, reply, reply_size); |
| 11882 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11883 | #endif /* CONFIG_WPS_ER */ |
| 11884 | #endif /* CONFIG_WPS */ |
| 11885 | #ifdef CONFIG_IBSS_RSN |
| 11886 | } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) { |
| 11887 | if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) |
| 11888 | reply_len = -1; |
| 11889 | #endif /* CONFIG_IBSS_RSN */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11890 | #ifdef CONFIG_MESH |
| 11891 | } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) { |
| 11892 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( |
| 11893 | wpa_s, buf + 19, reply, reply_size); |
| 11894 | } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) { |
| 11895 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( |
| 11896 | wpa_s, "", reply, reply_size); |
| 11897 | } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) { |
| 11898 | if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15)) |
| 11899 | reply_len = -1; |
| 11900 | } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) { |
| 11901 | if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s, |
| 11902 | buf + 18)) |
| 11903 | reply_len = -1; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 11904 | } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) { |
| 11905 | if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17)) |
| 11906 | reply_len = -1; |
| 11907 | } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) { |
| 11908 | if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14)) |
| 11909 | reply_len = -1; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11910 | } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) { |
| 11911 | if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16)) |
| 11912 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11913 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11914 | #ifdef CONFIG_P2P |
| 11915 | } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 11916 | if (p2p_ctrl_find(wpa_s, buf + 8)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11917 | reply_len = -1; |
| 11918 | } else if (os_strcmp(buf, "P2P_FIND") == 0) { |
| 11919 | if (p2p_ctrl_find(wpa_s, "")) |
| 11920 | reply_len = -1; |
| 11921 | } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) { |
| 11922 | wpas_p2p_stop_find(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 11923 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) { |
| 11924 | if (p2p_ctrl_asp_provision(wpa_s, buf + 18)) |
| 11925 | reply_len = -1; |
| 11926 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) { |
| 11927 | if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23)) |
| 11928 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11929 | } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) { |
| 11930 | reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply, |
| 11931 | reply_size); |
| 11932 | } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) { |
| 11933 | if (p2p_ctrl_listen(wpa_s, buf + 11)) |
| 11934 | reply_len = -1; |
| 11935 | } else if (os_strcmp(buf, "P2P_LISTEN") == 0) { |
| 11936 | if (p2p_ctrl_listen(wpa_s, "")) |
| 11937 | reply_len = -1; |
| 11938 | } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) { |
| 11939 | if (wpas_p2p_group_remove(wpa_s, buf + 17)) |
| 11940 | reply_len = -1; |
| 11941 | } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 11942 | if (p2p_ctrl_group_add(wpa_s, "")) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11943 | reply_len = -1; |
| 11944 | } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) { |
| 11945 | if (p2p_ctrl_group_add(wpa_s, buf + 14)) |
| 11946 | reply_len = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11947 | } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) { |
| 11948 | reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply, |
| 11949 | reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11950 | } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) { |
| 11951 | if (p2p_ctrl_prov_disc(wpa_s, buf + 14)) |
| 11952 | reply_len = -1; |
| 11953 | } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) { |
| 11954 | reply_len = p2p_get_passphrase(wpa_s, reply, reply_size); |
| 11955 | } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) { |
| 11956 | reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply, |
| 11957 | reply_size); |
| 11958 | } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) { |
| 11959 | if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0) |
| 11960 | reply_len = -1; |
| 11961 | } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) { |
| 11962 | if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0) |
| 11963 | reply_len = -1; |
| 11964 | } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) { |
| 11965 | wpas_p2p_sd_service_update(wpa_s); |
| 11966 | } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) { |
| 11967 | if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0) |
| 11968 | reply_len = -1; |
| 11969 | } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) { |
| 11970 | wpas_p2p_service_flush(wpa_s); |
| 11971 | } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) { |
| 11972 | if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0) |
| 11973 | reply_len = -1; |
| 11974 | } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) { |
| 11975 | if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0) |
| 11976 | reply_len = -1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 11977 | } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) { |
| 11978 | if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0) |
| 11979 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11980 | } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) { |
| 11981 | if (p2p_ctrl_reject(wpa_s, buf + 11) < 0) |
| 11982 | reply_len = -1; |
| 11983 | } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) { |
| 11984 | if (p2p_ctrl_invite(wpa_s, buf + 11) < 0) |
| 11985 | reply_len = -1; |
| 11986 | } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) { |
| 11987 | reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply, |
| 11988 | reply_size); |
| 11989 | } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) { |
| 11990 | if (p2p_ctrl_set(wpa_s, buf + 8) < 0) |
| 11991 | reply_len = -1; |
| 11992 | } else if (os_strcmp(buf, "P2P_FLUSH") == 0) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 11993 | p2p_ctrl_flush(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11994 | } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { |
| 11995 | if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) |
| 11996 | reply_len = -1; |
| 11997 | } else if (os_strcmp(buf, "P2P_CANCEL") == 0) { |
| 11998 | if (wpas_p2p_cancel(wpa_s)) |
| 11999 | reply_len = -1; |
| 12000 | } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) { |
| 12001 | if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0) |
| 12002 | reply_len = -1; |
| 12003 | } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) { |
| 12004 | if (p2p_ctrl_presence_req(wpa_s, "") < 0) |
| 12005 | reply_len = -1; |
| 12006 | } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) { |
| 12007 | if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0) |
| 12008 | reply_len = -1; |
| 12009 | } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) { |
| 12010 | if (p2p_ctrl_ext_listen(wpa_s, "") < 0) |
| 12011 | reply_len = -1; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 12012 | } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) { |
| 12013 | if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0) |
| 12014 | reply_len = -1; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12015 | } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) { |
| 12016 | if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13)) |
| 12017 | reply_len = -1; |
| 12018 | } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) { |
| 12019 | if (wpas_p2p_lo_stop(wpa_s)) |
| 12020 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12021 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 12022 | #ifdef CONFIG_WIFI_DISPLAY |
| 12023 | } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) { |
| 12024 | if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0) |
| 12025 | reply_len = -1; |
| 12026 | } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) { |
| 12027 | reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16, |
| 12028 | reply, reply_size); |
| 12029 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12030 | #ifdef CONFIG_INTERWORKING |
| 12031 | } else if (os_strcmp(buf, "FETCH_ANQP") == 0) { |
| 12032 | if (interworking_fetch_anqp(wpa_s) < 0) |
| 12033 | reply_len = -1; |
| 12034 | } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) { |
| 12035 | interworking_stop_fetch_anqp(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 12036 | } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) { |
| 12037 | if (ctrl_interworking_select(wpa_s, NULL) < 0) |
| 12038 | reply_len = -1; |
| 12039 | } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) { |
| 12040 | if (ctrl_interworking_select(wpa_s, buf + 20) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12041 | reply_len = -1; |
| 12042 | } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 12043 | if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12044 | reply_len = -1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 12045 | } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) { |
| 12046 | int id; |
| 12047 | |
| 12048 | id = ctrl_interworking_connect(wpa_s, buf + 25, 1); |
| 12049 | if (id < 0) |
| 12050 | reply_len = -1; |
| 12051 | else { |
| 12052 | reply_len = os_snprintf(reply, reply_size, "%d\n", id); |
| 12053 | if (os_snprintf_error(reply_size, reply_len)) |
| 12054 | reply_len = -1; |
| 12055 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12056 | } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) { |
| 12057 | if (get_anqp(wpa_s, buf + 9) < 0) |
| 12058 | reply_len = -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 12059 | } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) { |
| 12060 | if (gas_request(wpa_s, buf + 12) < 0) |
| 12061 | reply_len = -1; |
| 12062 | } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) { |
| 12063 | reply_len = gas_response_get(wpa_s, buf + 17, reply, |
| 12064 | reply_size); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12065 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 12066 | #ifdef CONFIG_HS20 |
| 12067 | } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) { |
| 12068 | if (get_hs20_anqp(wpa_s, buf + 14) < 0) |
| 12069 | reply_len = -1; |
| 12070 | } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) { |
| 12071 | if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0) |
| 12072 | reply_len = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 12073 | } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 12074 | if (hs20_icon_request(wpa_s, buf + 18, 0) < 0) |
| 12075 | reply_len = -1; |
| 12076 | } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) { |
| 12077 | if (hs20_icon_request(wpa_s, buf + 14, 1) < 0) |
| 12078 | reply_len = -1; |
| 12079 | } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) { |
| 12080 | reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size); |
| 12081 | } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) { |
| 12082 | if (del_hs20_icon(wpa_s, buf + 14) < 0) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 12083 | reply_len = -1; |
| 12084 | } else if (os_strcmp(buf, "FETCH_OSU") == 0) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12085 | if (hs20_fetch_osu(wpa_s, 0) < 0) |
| 12086 | reply_len = -1; |
| 12087 | } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) { |
| 12088 | if (hs20_fetch_osu(wpa_s, 1) < 0) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 12089 | reply_len = -1; |
| 12090 | } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) { |
| 12091 | hs20_cancel_fetch_osu(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 12092 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12093 | } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) |
| 12094 | { |
| 12095 | if (wpa_supplicant_ctrl_iface_ctrl_rsp( |
| 12096 | wpa_s, buf + os_strlen(WPA_CTRL_RSP))) |
| 12097 | reply_len = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 12098 | else { |
| 12099 | /* |
| 12100 | * Notify response from timeout to allow the control |
| 12101 | * interface response to be sent first. |
| 12102 | */ |
| 12103 | eloop_register_timeout(0, 0, wpas_ctrl_eapol_response, |
| 12104 | wpa_s, NULL); |
| 12105 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12106 | } else if (os_strcmp(buf, "RECONFIGURE") == 0) { |
| 12107 | if (wpa_supplicant_reload_configuration(wpa_s)) |
| 12108 | reply_len = -1; |
| 12109 | } else if (os_strcmp(buf, "TERMINATE") == 0) { |
| 12110 | wpa_supplicant_terminate_proc(wpa_s->global); |
| 12111 | } else if (os_strncmp(buf, "BSSID ", 6) == 0) { |
| 12112 | if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) |
| 12113 | reply_len = -1; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12114 | } else if (os_strncmp(buf, "BSSID_IGNORE", 12) == 0) { |
| 12115 | reply_len = wpa_supplicant_ctrl_iface_bssid_ignore( |
| 12116 | wpa_s, buf + 12, reply, reply_size); |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 12117 | } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12118 | /* deprecated backwards compatibility alias for BSSID_IGNORE */ |
| 12119 | reply_len = wpa_supplicant_ctrl_iface_bssid_ignore( |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12120 | wpa_s, buf + 9, reply, reply_size); |
| 12121 | } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) { |
| 12122 | reply_len = wpa_supplicant_ctrl_iface_log_level( |
| 12123 | wpa_s, buf + 9, reply, reply_size); |
Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 12124 | } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) { |
| 12125 | reply_len = wpa_supplicant_ctrl_iface_list_networks( |
| 12126 | wpa_s, buf + 14, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12127 | } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { |
| 12128 | reply_len = wpa_supplicant_ctrl_iface_list_networks( |
Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 12129 | wpa_s, NULL, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12130 | } else if (os_strcmp(buf, "DISCONNECT") == 0) { |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 12131 | wpas_request_disconnection(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 12132 | } else if (os_strcmp(buf, "SCAN") == 0) { |
| 12133 | wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len); |
| 12134 | } else if (os_strncmp(buf, "SCAN ", 5) == 0) { |
| 12135 | wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12136 | } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { |
| 12137 | reply_len = wpa_supplicant_ctrl_iface_scan_results( |
| 12138 | wpa_s, reply, reply_size); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 12139 | } else if (os_strcmp(buf, "ABORT_SCAN") == 0) { |
| 12140 | if (wpas_abort_ongoing_scan(wpa_s) < 0) |
| 12141 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12142 | } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { |
| 12143 | if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) |
| 12144 | reply_len = -1; |
| 12145 | } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { |
| 12146 | if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) |
| 12147 | reply_len = -1; |
| 12148 | } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { |
| 12149 | if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) |
| 12150 | reply_len = -1; |
| 12151 | } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { |
| 12152 | reply_len = wpa_supplicant_ctrl_iface_add_network( |
| 12153 | wpa_s, reply, reply_size); |
| 12154 | } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { |
| 12155 | if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) |
| 12156 | reply_len = -1; |
| 12157 | } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { |
| 12158 | if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) |
| 12159 | reply_len = -1; |
| 12160 | } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { |
| 12161 | reply_len = wpa_supplicant_ctrl_iface_get_network( |
| 12162 | wpa_s, buf + 12, reply, reply_size); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 12163 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12164 | if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12, |
| 12165 | wpa_s)) |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 12166 | reply_len = -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 12167 | } else if (os_strcmp(buf, "LIST_CREDS") == 0) { |
| 12168 | reply_len = wpa_supplicant_ctrl_iface_list_creds( |
| 12169 | wpa_s, reply, reply_size); |
| 12170 | } else if (os_strcmp(buf, "ADD_CRED") == 0) { |
| 12171 | reply_len = wpa_supplicant_ctrl_iface_add_cred( |
| 12172 | wpa_s, reply, reply_size); |
| 12173 | } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) { |
| 12174 | if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12)) |
| 12175 | reply_len = -1; |
| 12176 | } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) { |
| 12177 | if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9)) |
| 12178 | reply_len = -1; |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 12179 | } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) { |
| 12180 | reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9, |
| 12181 | reply, |
| 12182 | reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12183 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 12184 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { |
| 12185 | if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) |
| 12186 | reply_len = -1; |
| 12187 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 12188 | } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { |
| 12189 | reply_len = wpa_supplicant_ctrl_iface_get_capability( |
| 12190 | wpa_s, buf + 15, reply, reply_size); |
| 12191 | } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { |
| 12192 | if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) |
| 12193 | reply_len = -1; |
| 12194 | } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) { |
| 12195 | if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14)) |
| 12196 | reply_len = -1; |
| 12197 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
| 12198 | reply_len = wpa_supplicant_global_iface_list( |
| 12199 | wpa_s->global, reply, reply_size); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 12200 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12201 | reply_len = wpa_supplicant_global_iface_interfaces( |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 12202 | wpa_s->global, buf + 10, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12203 | } else if (os_strncmp(buf, "BSS ", 4) == 0) { |
| 12204 | reply_len = wpa_supplicant_ctrl_iface_bss( |
| 12205 | wpa_s, buf + 4, reply, reply_size); |
| 12206 | #ifdef CONFIG_AP |
| 12207 | } else if (os_strcmp(buf, "STA-FIRST") == 0) { |
| 12208 | reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size); |
| 12209 | } else if (os_strncmp(buf, "STA ", 4) == 0) { |
| 12210 | reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply, |
| 12211 | reply_size); |
| 12212 | } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { |
| 12213 | reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply, |
| 12214 | reply_size); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 12215 | } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) { |
| 12216 | if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15)) |
| 12217 | reply_len = -1; |
| 12218 | } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) { |
| 12219 | if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13)) |
| 12220 | reply_len = -1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 12221 | } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) { |
| 12222 | if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12)) |
| 12223 | reply_len = -1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 12224 | } else if (os_strcmp(buf, "STOP_AP") == 0) { |
| 12225 | if (wpas_ap_stop_ap(wpa_s)) |
| 12226 | reply_len = -1; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12227 | } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) { |
| 12228 | if (wpas_ap_update_beacon(wpa_s)) |
| 12229 | reply_len = -1; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 12230 | } else if (os_strncmp(buf, "ACCEPT_ACL ", 11) == 0) { |
| 12231 | if (os_strncmp(buf + 11, "ADD_MAC ", 8) == 0) { |
| 12232 | if (ap_ctrl_iface_acl_add_mac(wpa_s, |
| 12233 | DENY_UNLESS_ACCEPTED, |
| 12234 | buf + 19) || |
| 12235 | ap_ctrl_iface_set_acl(wpa_s)) |
| 12236 | reply_len = -1; |
| 12237 | } else if (os_strncmp((buf + 11), "DEL_MAC ", 8) == 0) { |
| 12238 | if (ap_ctrl_iface_acl_del_mac(wpa_s, |
| 12239 | DENY_UNLESS_ACCEPTED, |
| 12240 | buf + 19) || |
| 12241 | ap_ctrl_iface_set_acl(wpa_s) || |
| 12242 | ap_ctrl_iface_disassoc_accept_mac(wpa_s)) |
| 12243 | reply_len = -1; |
| 12244 | } else if (os_strcmp(buf + 11, "SHOW") == 0) { |
| 12245 | reply_len = ap_ctrl_iface_acl_show_mac( |
| 12246 | wpa_s, DENY_UNLESS_ACCEPTED, |
| 12247 | reply, reply_size); |
| 12248 | } else if (os_strcmp(buf + 11, "CLEAR") == 0) { |
| 12249 | ap_ctrl_iface_acl_clear_list(wpa_s, |
| 12250 | DENY_UNLESS_ACCEPTED); |
| 12251 | if (ap_ctrl_iface_set_acl(wpa_s) || |
| 12252 | ap_ctrl_iface_disassoc_accept_mac(wpa_s)) |
| 12253 | reply_len = -1; |
| 12254 | } else { |
| 12255 | reply_len = -1; |
| 12256 | } |
| 12257 | } else if (os_strncmp(buf, "DENY_ACL ", 9) == 0) { |
| 12258 | if (os_strncmp(buf + 9, "ADD_MAC ", 8) == 0) { |
| 12259 | if (ap_ctrl_iface_acl_add_mac(wpa_s, |
| 12260 | ACCEPT_UNLESS_DENIED, |
| 12261 | buf + 17) || |
| 12262 | ap_ctrl_iface_set_acl(wpa_s) || |
| 12263 | ap_ctrl_iface_disassoc_deny_mac(wpa_s)) |
| 12264 | reply_len = -1; |
| 12265 | } else if (os_strncmp(buf + 9, "DEL_MAC ", 8) == 0) { |
| 12266 | if (ap_ctrl_iface_acl_del_mac(wpa_s, |
| 12267 | ACCEPT_UNLESS_DENIED, |
| 12268 | buf + 17) || |
| 12269 | ap_ctrl_iface_set_acl(wpa_s)) |
| 12270 | reply_len = -1; |
| 12271 | } else if (os_strcmp(buf + 9, "SHOW") == 0) { |
| 12272 | reply_len = ap_ctrl_iface_acl_show_mac( |
| 12273 | wpa_s, ACCEPT_UNLESS_DENIED, reply, reply_size); |
| 12274 | } else if (os_strcmp(buf + 9, "CLEAR") == 0) { |
| 12275 | ap_ctrl_iface_acl_clear_list(wpa_s, |
| 12276 | ACCEPT_UNLESS_DENIED); |
| 12277 | if (ap_ctrl_iface_set_acl(wpa_s)) |
| 12278 | reply_len = -1; |
| 12279 | } else { |
| 12280 | reply_len = -1; |
| 12281 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12282 | #endif /* CONFIG_AP */ |
| 12283 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
| 12284 | wpas_notify_suspend(wpa_s->global); |
| 12285 | } else if (os_strcmp(buf, "RESUME") == 0) { |
| 12286 | wpas_notify_resume(wpa_s->global); |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 12287 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12288 | } else if (os_strcmp(buf, "DROP_SA") == 0) { |
| 12289 | wpa_supplicant_ctrl_iface_drop_sa(wpa_s); |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 12290 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12291 | } else if (os_strncmp(buf, "ROAM ", 5) == 0) { |
| 12292 | if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) |
| 12293 | reply_len = -1; |
| 12294 | } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12295 | wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12296 | } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) { |
| 12297 | if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15)) |
| 12298 | reply_len = -1; |
| 12299 | } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) { |
| 12300 | if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s, |
| 12301 | buf + 17)) |
| 12302 | reply_len = -1; |
Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 12303 | } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12304 | wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12305 | #ifdef CONFIG_TDLS |
| 12306 | } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) { |
| 12307 | if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14)) |
| 12308 | reply_len = -1; |
| 12309 | } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) { |
| 12310 | if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11)) |
| 12311 | reply_len = -1; |
| 12312 | } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) { |
| 12313 | if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14)) |
| 12314 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12315 | } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) { |
| 12316 | if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s, |
| 12317 | buf + 17)) |
| 12318 | reply_len = -1; |
| 12319 | } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) { |
| 12320 | if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s, |
| 12321 | buf + 24)) |
| 12322 | reply_len = -1; |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 12323 | } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) { |
| 12324 | reply_len = wpa_supplicant_ctrl_iface_tdls_link_status( |
| 12325 | wpa_s, buf + 17, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12326 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12327 | } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) { |
| 12328 | reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size); |
| 12329 | } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) { |
| 12330 | if (wmm_ac_ctrl_addts(wpa_s, buf + 13)) |
| 12331 | reply_len = -1; |
| 12332 | } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) { |
| 12333 | if (wmm_ac_ctrl_delts(wpa_s, buf + 13)) |
| 12334 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12335 | } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) { |
| 12336 | reply_len = wpa_supplicant_signal_poll(wpa_s, reply, |
| 12337 | reply_size); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 12338 | } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) { |
| 12339 | if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14)) |
| 12340 | reply_len = -1; |
Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 12341 | } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) { |
| 12342 | reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply, |
| 12343 | reply_size); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 12344 | #ifdef CONFIG_AUTOSCAN |
| 12345 | } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) { |
| 12346 | if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9)) |
| 12347 | reply_len = -1; |
| 12348 | #endif /* CONFIG_AUTOSCAN */ |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12349 | } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) { |
| 12350 | reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply, |
| 12351 | reply_size); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 12352 | } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) { |
| 12353 | reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply, |
| 12354 | reply_size); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 12355 | #ifdef ANDROID |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 12356 | } else if (os_strncmp(buf, "DRIVER ", 7) == 0) { |
| 12357 | reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply, |
| 12358 | reply_size); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 12359 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 12360 | } else if (os_strncmp(buf, "VENDOR ", 7) == 0) { |
| 12361 | reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply, |
| 12362 | reply_size); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12363 | } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 12364 | pmksa_cache_clear_current(wpa_s->wpa); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12365 | eapol_sm_request_reauth(wpa_s->eapol); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 12366 | #ifdef CONFIG_WNM |
| 12367 | } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) { |
| 12368 | if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10)) |
| 12369 | reply_len = -1; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 12370 | } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) { |
| 12371 | if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14)) |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 12372 | reply_len = -1; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 12373 | } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) { |
| 12374 | if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18)) |
| 12375 | reply_len = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 12376 | #endif /* CONFIG_WNM */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 12377 | #ifdef CONFIG_WNM_AP |
| 12378 | } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) { |
| 12379 | if (ap_ctrl_iface_disassoc_imminent(wpa_s, buf + 18)) |
| 12380 | reply_len = -1; |
| 12381 | } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) { |
| 12382 | if (ap_ctrl_iface_ess_disassoc(wpa_s, buf + 13)) |
| 12383 | reply_len = -1; |
| 12384 | } else if (os_strncmp(buf, "BSS_TM_REQ ", 11) == 0) { |
| 12385 | if (ap_ctrl_iface_bss_tm_req(wpa_s, buf + 11)) |
| 12386 | reply_len = -1; |
| 12387 | #endif /* CONFIG_WNM_AP */ |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 12388 | } else if (os_strcmp(buf, "FLUSH") == 0) { |
| 12389 | wpa_supplicant_ctrl_iface_flush(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 12390 | } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) { |
| 12391 | reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply, |
| 12392 | reply_size); |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 12393 | #ifdef CONFIG_TESTING_OPTIONS |
| 12394 | } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) { |
| 12395 | if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0) |
| 12396 | reply_len = -1; |
| 12397 | } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) { |
| 12398 | wpas_ctrl_iface_mgmt_tx_done(wpa_s); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12399 | } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) { |
| 12400 | if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0) |
| 12401 | reply_len = -1; |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 12402 | } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) { |
| 12403 | if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0) |
| 12404 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12405 | } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) { |
| 12406 | if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0) |
| 12407 | reply_len = -1; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12408 | } else if (os_strncmp(buf, "EAPOL_TX ", 9) == 0) { |
| 12409 | if (wpas_ctrl_iface_eapol_tx(wpa_s, buf + 9) < 0) |
| 12410 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12411 | } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) { |
| 12412 | if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0) |
| 12413 | reply_len = -1; |
| 12414 | } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) { |
| 12415 | if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0) |
| 12416 | reply_len = -1; |
| 12417 | } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) { |
| 12418 | if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0) |
| 12419 | reply_len = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 12420 | } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) { |
| 12421 | if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0) |
| 12422 | reply_len = -1; |
| 12423 | } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) { |
| 12424 | reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12425 | } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) { |
| 12426 | if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0) |
| 12427 | reply_len = -1; |
| 12428 | } else if (os_strcmp(buf, "GET_FAIL") == 0) { |
| 12429 | reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size); |
Jouni Malinen | c481836 | 2015-10-04 11:45:13 +0300 | [diff] [blame] | 12430 | } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) { |
| 12431 | if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0) |
| 12432 | reply_len = -1; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 12433 | } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) { |
| 12434 | if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0) |
| 12435 | reply_len = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12436 | } else if (os_strcmp(buf, "RESET_PN") == 0) { |
| 12437 | if (wpas_ctrl_reset_pn(wpa_s) < 0) |
| 12438 | reply_len = -1; |
| 12439 | } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) { |
| 12440 | if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0) |
| 12441 | reply_len = -1; |
| 12442 | } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) { |
| 12443 | if (wpas_ctrl_resend_assoc(wpa_s) < 0) |
| 12444 | reply_len = -1; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12445 | } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) { |
| 12446 | sme_event_unprot_disconnect( |
| 12447 | wpa_s, wpa_s->bssid, NULL, |
| 12448 | WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12449 | } else if (os_strncmp(buf, "TWT_SETUP ", 10) == 0) { |
| 12450 | if (wpas_ctrl_iface_send_twt_setup(wpa_s, buf + 9)) |
| 12451 | reply_len = -1; |
| 12452 | } else if (os_strcmp(buf, "TWT_SETUP") == 0) { |
| 12453 | if (wpas_ctrl_iface_send_twt_setup(wpa_s, "")) |
| 12454 | reply_len = -1; |
| 12455 | } else if (os_strncmp(buf, "TWT_TEARDOWN ", 13) == 0) { |
| 12456 | if (wpas_ctrl_iface_send_twt_teardown(wpa_s, buf + 12)) |
| 12457 | reply_len = -1; |
| 12458 | } else if (os_strcmp(buf, "TWT_TEARDOWN") == 0) { |
| 12459 | if (wpas_ctrl_iface_send_twt_teardown(wpa_s, "")) |
| 12460 | reply_len = -1; |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 12461 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 12462 | } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) { |
| 12463 | if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0) |
| 12464 | reply_len = -1; |
| 12465 | } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) { |
| 12466 | reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply, |
| 12467 | reply_size); |
| 12468 | } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) { |
| 12469 | if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0) |
| 12470 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12471 | } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) { |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12472 | if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12473 | reply_len = -1; |
| 12474 | } else if (os_strcmp(buf, "ERP_FLUSH") == 0) { |
| 12475 | wpas_ctrl_iface_erp_flush(wpa_s); |
| 12476 | } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) { |
| 12477 | if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14)) |
| 12478 | reply_len = -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12479 | } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) { |
| 12480 | reply_len = wpas_ctrl_iface_get_pref_freq_list( |
| 12481 | wpa_s, buf + 19, reply, reply_size); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 12482 | #ifdef CONFIG_FILS |
| 12483 | } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) { |
| 12484 | if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17)) |
| 12485 | reply_len = -1; |
| 12486 | } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) { |
| 12487 | wpas_flush_fils_hlp_req(wpa_s); |
| 12488 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12489 | #ifdef CONFIG_DPP |
| 12490 | } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) { |
| 12491 | int res; |
| 12492 | |
| 12493 | res = wpas_dpp_qr_code(wpa_s, buf + 12); |
| 12494 | if (res < 0) { |
| 12495 | reply_len = -1; |
| 12496 | } else { |
| 12497 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 12498 | if (os_snprintf_error(reply_size, reply_len)) |
| 12499 | reply_len = -1; |
| 12500 | } |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 12501 | } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) { |
| 12502 | int res; |
| 12503 | |
| 12504 | res = wpas_dpp_nfc_uri(wpa_s, buf + 12); |
| 12505 | if (res < 0) { |
| 12506 | reply_len = -1; |
| 12507 | } else { |
| 12508 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 12509 | if (os_snprintf_error(reply_size, reply_len)) |
| 12510 | reply_len = -1; |
| 12511 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12512 | } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) { |
| 12513 | int res; |
| 12514 | |
| 12515 | res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20); |
| 12516 | if (res < 0) { |
| 12517 | reply_len = -1; |
| 12518 | } else { |
| 12519 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 12520 | if (os_snprintf_error(reply_size, reply_len)) |
| 12521 | reply_len = -1; |
| 12522 | } |
| 12523 | } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) { |
| 12524 | int res; |
| 12525 | |
| 12526 | res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20); |
| 12527 | if (res < 0) { |
| 12528 | reply_len = -1; |
| 12529 | } else { |
| 12530 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 12531 | if (os_snprintf_error(reply_size, reply_len)) |
| 12532 | reply_len = -1; |
| 12533 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12534 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) { |
| 12535 | int res; |
| 12536 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12537 | res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12538 | if (res < 0) { |
| 12539 | reply_len = -1; |
| 12540 | } else { |
| 12541 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 12542 | if (os_snprintf_error(reply_size, reply_len)) |
| 12543 | reply_len = -1; |
| 12544 | } |
| 12545 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12546 | if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12547 | reply_len = -1; |
| 12548 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) { |
| 12549 | const char *uri; |
| 12550 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12551 | uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12552 | if (!uri) { |
| 12553 | reply_len = -1; |
| 12554 | } else { |
| 12555 | reply_len = os_snprintf(reply, reply_size, "%s", uri); |
| 12556 | if (os_snprintf_error(reply_size, reply_len)) |
| 12557 | reply_len = -1; |
| 12558 | } |
| 12559 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12560 | reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19), |
| 12561 | reply, reply_size); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12562 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) { |
| 12563 | if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18), |
| 12564 | os_strchr(buf + 18, ' ')) < 0) |
| 12565 | reply_len = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12566 | } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) { |
| 12567 | if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0) |
| 12568 | reply_len = -1; |
| 12569 | } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) { |
| 12570 | if (wpas_dpp_listen(wpa_s, buf + 11) < 0) |
| 12571 | reply_len = -1; |
| 12572 | } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12573 | wpas_dpp_stop(wpa_s); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12574 | wpas_dpp_listen_stop(wpa_s); |
| 12575 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) { |
| 12576 | int res; |
| 12577 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12578 | res = dpp_configurator_add(wpa_s->dpp, buf + 20); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12579 | if (res < 0) { |
| 12580 | reply_len = -1; |
| 12581 | } else { |
| 12582 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 12583 | if (os_snprintf_error(reply_size, reply_len)) |
| 12584 | reply_len = -1; |
| 12585 | } |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 12586 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SET ", 21) == 0) { |
| 12587 | if (dpp_configurator_set(wpa_s->dpp, buf + 20) < 0) |
| 12588 | reply_len = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12589 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12590 | if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12591 | reply_len = -1; |
| 12592 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12593 | if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12594 | reply_len = -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12595 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12596 | reply_len = dpp_configurator_get_key_id(wpa_s->dpp, |
| 12597 | atoi(buf + 25), |
| 12598 | reply, reply_size); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12599 | } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) { |
| 12600 | int res; |
| 12601 | |
| 12602 | res = wpas_dpp_pkex_add(wpa_s, buf + 12); |
| 12603 | if (res < 0) { |
| 12604 | reply_len = -1; |
| 12605 | } else { |
| 12606 | reply_len = os_snprintf(reply, reply_size, "%d", res); |
| 12607 | if (os_snprintf_error(reply_size, reply_len)) |
| 12608 | reply_len = -1; |
| 12609 | } |
| 12610 | } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) { |
| 12611 | if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0) |
| 12612 | reply_len = -1; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12613 | } else if (os_strncmp(buf, "DPP_CONF_SET ", 13) == 0) { |
| 12614 | if (wpas_dpp_conf_set(wpa_s, buf + 12) < 0) |
| 12615 | reply_len = -1; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 12616 | #ifdef CONFIG_DPP2 |
| 12617 | } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) { |
| 12618 | if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0) |
| 12619 | reply_len = -1; |
| 12620 | } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) { |
| 12621 | if (wpas_dpp_controller_start(wpa_s, NULL) < 0) |
| 12622 | reply_len = -1; |
| 12623 | } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) { |
| 12624 | dpp_controller_stop(wpa_s->dpp); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12625 | } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) { |
| 12626 | if (wpas_dpp_chirp(wpa_s, buf + 9) < 0) |
| 12627 | reply_len = -1; |
| 12628 | } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) { |
| 12629 | wpas_dpp_chirp_stop(wpa_s); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 12630 | } else if (os_strncmp(buf, "DPP_RECONFIG ", 13) == 0) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12631 | if (wpas_dpp_reconfig(wpa_s, buf + 13) < 0) |
| 12632 | reply_len = -1; |
| 12633 | } else if (os_strncmp(buf, "DPP_CA_SET ", 11) == 0) { |
| 12634 | if (wpas_dpp_ca_set(wpa_s, buf + 10) < 0) |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 12635 | reply_len = -1; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 12636 | #endif /* CONFIG_DPP2 */ |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 12637 | #ifdef CONFIG_DPP3 |
| 12638 | } else if (os_strcmp(buf, "DPP_PUSH_BUTTON") == 0) { |
| 12639 | if (wpas_dpp_push_button(wpa_s, NULL) < 0) |
| 12640 | reply_len = -1; |
| 12641 | } else if (os_strncmp(buf, "DPP_PUSH_BUTTON ", 16) == 0) { |
| 12642 | if (wpas_dpp_push_button(wpa_s, buf + 15) < 0) |
| 12643 | reply_len = -1; |
| 12644 | #endif /* CONFIG_DPP3 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12645 | #endif /* CONFIG_DPP */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12646 | } else if (os_strncmp(buf, "MSCS ", 5) == 0) { |
| 12647 | if (wpas_ctrl_iface_configure_mscs(wpa_s, buf + 5)) |
| 12648 | reply_len = -1; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12649 | #ifdef CONFIG_PASN |
| 12650 | } else if (os_strncmp(buf, "PASN_START ", 11) == 0) { |
| 12651 | if (wpas_ctrl_iface_pasn_start(wpa_s, buf + 11) < 0) |
| 12652 | reply_len = -1; |
| 12653 | } else if (os_strcmp(buf, "PASN_STOP") == 0) { |
| 12654 | wpas_pasn_auth_stop(wpa_s); |
| 12655 | } else if (os_strcmp(buf, "PTKSA_CACHE_LIST") == 0) { |
| 12656 | reply_len = ptksa_cache_list(wpa_s->ptksa, reply, reply_size); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12657 | } else if (os_strncmp(buf, "PASN_DEAUTH ", 12) == 0) { |
| 12658 | if (wpas_ctrl_iface_pasn_deauthenticate(wpa_s, buf + 12) < 0) |
| 12659 | reply_len = -1; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12660 | #endif /* CONFIG_PASN */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12661 | } else if (os_strncmp(buf, "SCS ", 4) == 0) { |
| 12662 | if (wpas_ctrl_iface_configure_scs(wpa_s, buf + 4)) |
| 12663 | reply_len = -1; |
| 12664 | } else if (os_strncmp(buf, "DSCP_RESP ", 10) == 0) { |
| 12665 | if (wpas_ctrl_iface_send_dscp_resp(wpa_s, buf + 10)) |
| 12666 | reply_len = -1; |
| 12667 | } else if (os_strncmp(buf, "DSCP_QUERY ", 11) == 0) { |
| 12668 | if (wpas_ctrl_iface_send_dscp_query(wpa_s, buf + 11)) |
| 12669 | reply_len = -1; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame^] | 12670 | } else if (os_strcmp(buf, "MLO_STATUS") == 0) { |
| 12671 | reply_len = wpas_ctrl_iface_mlo_status(wpa_s, reply, |
| 12672 | reply_size); |
| 12673 | } else if (os_strcmp(buf, "MLO_SIGNAL_POLL") == 0) { |
| 12674 | reply_len = wpas_ctrl_iface_mlo_signal_poll(wpa_s, reply, |
| 12675 | reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12676 | } else { |
| 12677 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); |
| 12678 | reply_len = 16; |
| 12679 | } |
| 12680 | |
| 12681 | if (reply_len < 0) { |
| 12682 | os_memcpy(reply, "FAIL\n", 5); |
| 12683 | reply_len = 5; |
| 12684 | } |
| 12685 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12686 | *resp_len = reply_len; |
| 12687 | return reply; |
| 12688 | } |
| 12689 | |
| 12690 | |
| 12691 | static int wpa_supplicant_global_iface_add(struct wpa_global *global, |
| 12692 | char *cmd) |
| 12693 | { |
| 12694 | struct wpa_interface iface; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12695 | char *pos, *extra; |
| 12696 | struct wpa_supplicant *wpa_s; |
| 12697 | unsigned int create_iface = 0; |
| 12698 | u8 mac_addr[ETH_ALEN]; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 12699 | enum wpa_driver_if_type type = WPA_IF_STATION; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12700 | |
| 12701 | /* |
| 12702 | * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param> |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 12703 | * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]] |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12704 | */ |
| 12705 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd); |
| 12706 | |
| 12707 | os_memset(&iface, 0, sizeof(iface)); |
| 12708 | |
| 12709 | do { |
| 12710 | iface.ifname = pos = cmd; |
| 12711 | pos = os_strchr(pos, '\t'); |
| 12712 | if (pos) |
| 12713 | *pos++ = '\0'; |
| 12714 | if (iface.ifname[0] == '\0') |
| 12715 | return -1; |
| 12716 | if (pos == NULL) |
| 12717 | break; |
| 12718 | |
| 12719 | iface.confname = pos; |
| 12720 | pos = os_strchr(pos, '\t'); |
| 12721 | if (pos) |
| 12722 | *pos++ = '\0'; |
| 12723 | if (iface.confname[0] == '\0') |
| 12724 | iface.confname = NULL; |
| 12725 | if (pos == NULL) |
| 12726 | break; |
| 12727 | |
| 12728 | iface.driver = pos; |
| 12729 | pos = os_strchr(pos, '\t'); |
| 12730 | if (pos) |
| 12731 | *pos++ = '\0'; |
| 12732 | if (iface.driver[0] == '\0') |
| 12733 | iface.driver = NULL; |
| 12734 | if (pos == NULL) |
| 12735 | break; |
| 12736 | |
| 12737 | iface.ctrl_interface = pos; |
| 12738 | pos = os_strchr(pos, '\t'); |
| 12739 | if (pos) |
| 12740 | *pos++ = '\0'; |
| 12741 | if (iface.ctrl_interface[0] == '\0') |
| 12742 | iface.ctrl_interface = NULL; |
| 12743 | if (pos == NULL) |
| 12744 | break; |
| 12745 | |
| 12746 | iface.driver_param = pos; |
| 12747 | pos = os_strchr(pos, '\t'); |
| 12748 | if (pos) |
| 12749 | *pos++ = '\0'; |
| 12750 | if (iface.driver_param[0] == '\0') |
| 12751 | iface.driver_param = NULL; |
| 12752 | if (pos == NULL) |
| 12753 | break; |
| 12754 | |
| 12755 | iface.bridge_ifname = pos; |
| 12756 | pos = os_strchr(pos, '\t'); |
| 12757 | if (pos) |
| 12758 | *pos++ = '\0'; |
| 12759 | if (iface.bridge_ifname[0] == '\0') |
| 12760 | iface.bridge_ifname = NULL; |
| 12761 | if (pos == NULL) |
| 12762 | break; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12763 | |
| 12764 | extra = pos; |
| 12765 | pos = os_strchr(pos, '\t'); |
| 12766 | if (pos) |
| 12767 | *pos++ = '\0'; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 12768 | if (!extra[0]) |
| 12769 | break; |
| 12770 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 12771 | if (os_strcmp(extra, "create") == 0) { |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12772 | create_iface = 1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 12773 | if (!pos) |
| 12774 | break; |
| 12775 | |
| 12776 | if (os_strcmp(pos, "sta") == 0) { |
| 12777 | type = WPA_IF_STATION; |
| 12778 | } else if (os_strcmp(pos, "ap") == 0) { |
| 12779 | type = WPA_IF_AP_BSS; |
| 12780 | } else { |
| 12781 | wpa_printf(MSG_DEBUG, |
| 12782 | "INTERFACE_ADD unsupported interface type: '%s'", |
| 12783 | pos); |
| 12784 | return -1; |
| 12785 | } |
| 12786 | } else { |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 12787 | wpa_printf(MSG_DEBUG, |
| 12788 | "INTERFACE_ADD unsupported extra parameter: '%s'", |
| 12789 | extra); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12790 | return -1; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 12791 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12792 | } while (0); |
| 12793 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12794 | if (create_iface) { |
| 12795 | wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'", |
| 12796 | iface.ifname); |
| 12797 | if (!global->ifaces) |
| 12798 | return -1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 12799 | if (wpa_drv_if_add(global->ifaces, type, iface.ifname, |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12800 | NULL, NULL, NULL, mac_addr, NULL) < 0) { |
| 12801 | wpa_printf(MSG_ERROR, |
| 12802 | "CTRL_IFACE interface creation failed"); |
| 12803 | return -1; |
| 12804 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12805 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12806 | wpa_printf(MSG_DEBUG, |
| 12807 | "CTRL_IFACE interface '%s' created with MAC addr: " |
| 12808 | MACSTR, iface.ifname, MAC2STR(mac_addr)); |
| 12809 | } |
| 12810 | |
| 12811 | if (wpa_supplicant_get_iface(global, iface.ifname)) |
| 12812 | goto fail; |
| 12813 | |
| 12814 | wpa_s = wpa_supplicant_add_iface(global, &iface, NULL); |
| 12815 | if (!wpa_s) |
| 12816 | goto fail; |
| 12817 | wpa_s->added_vif = create_iface; |
| 12818 | return 0; |
| 12819 | |
| 12820 | fail: |
| 12821 | if (create_iface) |
| 12822 | wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname); |
| 12823 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12824 | } |
| 12825 | |
| 12826 | |
| 12827 | static int wpa_supplicant_global_iface_remove(struct wpa_global *global, |
| 12828 | char *cmd) |
| 12829 | { |
| 12830 | struct wpa_supplicant *wpa_s; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12831 | int ret; |
| 12832 | unsigned int delete_iface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12833 | |
| 12834 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd); |
| 12835 | |
| 12836 | wpa_s = wpa_supplicant_get_iface(global, cmd); |
| 12837 | if (wpa_s == NULL) |
| 12838 | return -1; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12839 | delete_iface = wpa_s->added_vif; |
| 12840 | ret = wpa_supplicant_remove_iface(global, wpa_s, 0); |
| 12841 | if (!ret && delete_iface) { |
| 12842 | wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'", |
| 12843 | cmd); |
| 12844 | ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd); |
| 12845 | } |
| 12846 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12847 | } |
| 12848 | |
| 12849 | |
| 12850 | static void wpa_free_iface_info(struct wpa_interface_info *iface) |
| 12851 | { |
| 12852 | struct wpa_interface_info *prev; |
| 12853 | |
| 12854 | while (iface) { |
| 12855 | prev = iface; |
| 12856 | iface = iface->next; |
| 12857 | |
| 12858 | os_free(prev->ifname); |
| 12859 | os_free(prev->desc); |
| 12860 | os_free(prev); |
| 12861 | } |
| 12862 | } |
| 12863 | |
| 12864 | |
| 12865 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
| 12866 | char *buf, int len) |
| 12867 | { |
| 12868 | int i, res; |
| 12869 | struct wpa_interface_info *iface = NULL, *last = NULL, *tmp; |
| 12870 | char *pos, *end; |
| 12871 | |
| 12872 | for (i = 0; wpa_drivers[i]; i++) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 12873 | const struct wpa_driver_ops *drv = wpa_drivers[i]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12874 | if (drv->get_interfaces == NULL) |
| 12875 | continue; |
| 12876 | tmp = drv->get_interfaces(global->drv_priv[i]); |
| 12877 | if (tmp == NULL) |
| 12878 | continue; |
| 12879 | |
| 12880 | if (last == NULL) |
| 12881 | iface = last = tmp; |
| 12882 | else |
| 12883 | last->next = tmp; |
| 12884 | while (last->next) |
| 12885 | last = last->next; |
| 12886 | } |
| 12887 | |
| 12888 | pos = buf; |
| 12889 | end = buf + len; |
| 12890 | for (tmp = iface; tmp; tmp = tmp->next) { |
| 12891 | res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n", |
| 12892 | tmp->drv_name, tmp->ifname, |
| 12893 | tmp->desc ? tmp->desc : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12894 | if (os_snprintf_error(end - pos, res)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12895 | *pos = '\0'; |
| 12896 | break; |
| 12897 | } |
| 12898 | pos += res; |
| 12899 | } |
| 12900 | |
| 12901 | wpa_free_iface_info(iface); |
| 12902 | |
| 12903 | return pos - buf; |
| 12904 | } |
| 12905 | |
| 12906 | |
| 12907 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 12908 | const char *input, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12909 | char *buf, int len) |
| 12910 | { |
| 12911 | int res; |
| 12912 | char *pos, *end; |
| 12913 | struct wpa_supplicant *wpa_s; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 12914 | int show_ctrl = 0; |
| 12915 | |
| 12916 | if (input) |
| 12917 | show_ctrl = !!os_strstr(input, "ctrl"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12918 | |
| 12919 | wpa_s = global->ifaces; |
| 12920 | pos = buf; |
| 12921 | end = buf + len; |
| 12922 | |
| 12923 | while (wpa_s) { |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 12924 | if (show_ctrl) |
| 12925 | res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n", |
| 12926 | wpa_s->ifname, |
| 12927 | wpa_s->conf->ctrl_interface ? |
| 12928 | wpa_s->conf->ctrl_interface : "N/A"); |
| 12929 | else |
| 12930 | res = os_snprintf(pos, end - pos, "%s\n", |
| 12931 | wpa_s->ifname); |
| 12932 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12933 | if (os_snprintf_error(end - pos, res)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12934 | *pos = '\0'; |
| 12935 | break; |
| 12936 | } |
| 12937 | pos += res; |
| 12938 | wpa_s = wpa_s->next; |
| 12939 | } |
| 12940 | return pos - buf; |
| 12941 | } |
| 12942 | |
| 12943 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 12944 | static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global, |
| 12945 | const char *ifname, |
| 12946 | char *cmd, size_t *resp_len) |
| 12947 | { |
| 12948 | struct wpa_supplicant *wpa_s; |
| 12949 | |
| 12950 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 12951 | if (os_strcmp(ifname, wpa_s->ifname) == 0) |
| 12952 | break; |
| 12953 | } |
| 12954 | |
| 12955 | if (wpa_s == NULL) { |
| 12956 | char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n"); |
| 12957 | if (resp) |
| 12958 | *resp_len = os_strlen(resp); |
| 12959 | else |
| 12960 | *resp_len = 1; |
| 12961 | return resp; |
| 12962 | } |
| 12963 | |
| 12964 | return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len); |
| 12965 | } |
| 12966 | |
| 12967 | |
| 12968 | static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global, |
| 12969 | char *buf, size_t *resp_len) |
| 12970 | { |
| 12971 | #ifdef CONFIG_P2P |
| 12972 | static const char * cmd[] = { |
Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 12973 | "LIST_NETWORKS", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 12974 | "P2P_FIND", |
| 12975 | "P2P_STOP_FIND", |
| 12976 | "P2P_LISTEN", |
| 12977 | "P2P_GROUP_ADD", |
| 12978 | "P2P_GET_PASSPHRASE", |
| 12979 | "P2P_SERVICE_UPDATE", |
| 12980 | "P2P_SERVICE_FLUSH", |
| 12981 | "P2P_FLUSH", |
| 12982 | "P2P_CANCEL", |
| 12983 | "P2P_PRESENCE_REQ", |
| 12984 | "P2P_EXT_LISTEN", |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 12985 | #ifdef CONFIG_AP |
| 12986 | "STA-FIRST", |
| 12987 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 12988 | NULL |
| 12989 | }; |
| 12990 | static const char * prefix[] = { |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 12991 | #ifdef ANDROID |
Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 12992 | "DRIVER ", |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 12993 | #endif /* ANDROID */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12994 | "GET_CAPABILITY ", |
Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 12995 | "GET_NETWORK ", |
| 12996 | "REMOVE_NETWORK ", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 12997 | "P2P_FIND ", |
| 12998 | "P2P_CONNECT ", |
| 12999 | "P2P_LISTEN ", |
| 13000 | "P2P_GROUP_REMOVE ", |
| 13001 | "P2P_GROUP_ADD ", |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 13002 | "P2P_GROUP_MEMBER ", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 13003 | "P2P_PROV_DISC ", |
| 13004 | "P2P_SERV_DISC_REQ ", |
| 13005 | "P2P_SERV_DISC_CANCEL_REQ ", |
| 13006 | "P2P_SERV_DISC_RESP ", |
| 13007 | "P2P_SERV_DISC_EXTERNAL ", |
| 13008 | "P2P_SERVICE_ADD ", |
| 13009 | "P2P_SERVICE_DEL ", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 13010 | "P2P_SERVICE_REP ", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 13011 | "P2P_REJECT ", |
| 13012 | "P2P_INVITE ", |
| 13013 | "P2P_PEER ", |
| 13014 | "P2P_SET ", |
| 13015 | "P2P_UNAUTHORIZE ", |
| 13016 | "P2P_PRESENCE_REQ ", |
| 13017 | "P2P_EXT_LISTEN ", |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 13018 | "P2P_REMOVE_CLIENT ", |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 13019 | "WPS_NFC_TOKEN ", |
| 13020 | "WPS_NFC_TAG_READ ", |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 13021 | "NFC_GET_HANDOVER_SEL ", |
| 13022 | "NFC_GET_HANDOVER_REQ ", |
| 13023 | "NFC_REPORT_HANDOVER ", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 13024 | "P2P_ASP_PROVISION ", |
| 13025 | "P2P_ASP_PROVISION_RESP ", |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 13026 | #ifdef CONFIG_AP |
| 13027 | "STA ", |
| 13028 | "STA-NEXT ", |
| 13029 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 13030 | NULL |
| 13031 | }; |
| 13032 | int found = 0; |
| 13033 | int i; |
| 13034 | |
| 13035 | if (global->p2p_init_wpa_s == NULL) |
| 13036 | return NULL; |
| 13037 | |
| 13038 | for (i = 0; !found && cmd[i]; i++) { |
| 13039 | if (os_strcmp(buf, cmd[i]) == 0) |
| 13040 | found = 1; |
| 13041 | } |
| 13042 | |
| 13043 | for (i = 0; !found && prefix[i]; i++) { |
| 13044 | if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0) |
| 13045 | found = 1; |
| 13046 | } |
| 13047 | |
| 13048 | if (found) |
| 13049 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, |
| 13050 | buf, resp_len); |
| 13051 | #endif /* CONFIG_P2P */ |
| 13052 | return NULL; |
| 13053 | } |
| 13054 | |
| 13055 | |
| 13056 | static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global, |
| 13057 | char *buf, size_t *resp_len) |
| 13058 | { |
| 13059 | #ifdef CONFIG_WIFI_DISPLAY |
| 13060 | if (global->p2p_init_wpa_s == NULL) |
| 13061 | return NULL; |
| 13062 | if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 || |
| 13063 | os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) |
| 13064 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, |
| 13065 | buf, resp_len); |
| 13066 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 13067 | return NULL; |
| 13068 | } |
| 13069 | |
| 13070 | |
| 13071 | static char * wpas_global_ctrl_iface_redir(struct wpa_global *global, |
| 13072 | char *buf, size_t *resp_len) |
| 13073 | { |
| 13074 | char *ret; |
| 13075 | |
| 13076 | ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len); |
| 13077 | if (ret) |
| 13078 | return ret; |
| 13079 | |
| 13080 | ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len); |
| 13081 | if (ret) |
| 13082 | return ret; |
| 13083 | |
| 13084 | return NULL; |
| 13085 | } |
| 13086 | |
| 13087 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13088 | static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd) |
| 13089 | { |
| 13090 | char *value; |
| 13091 | |
| 13092 | value = os_strchr(cmd, ' '); |
| 13093 | if (value == NULL) |
| 13094 | return -1; |
| 13095 | *value++ = '\0'; |
| 13096 | |
| 13097 | wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value); |
| 13098 | |
| 13099 | #ifdef CONFIG_WIFI_DISPLAY |
| 13100 | if (os_strcasecmp(cmd, "wifi_display") == 0) { |
| 13101 | wifi_display_enable(global, !!atoi(value)); |
| 13102 | return 0; |
| 13103 | } |
| 13104 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 13105 | |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 13106 | /* Restore cmd to its original value to allow redirection */ |
| 13107 | value[-1] = ' '; |
| 13108 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13109 | return -1; |
| 13110 | } |
| 13111 | |
| 13112 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13113 | static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global, |
| 13114 | char *cmd) |
| 13115 | { |
| 13116 | struct wpa_supplicant *wpa_s[2]; /* src, dst */ |
| 13117 | char *p; |
| 13118 | unsigned int i; |
| 13119 | |
| 13120 | /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id> |
| 13121 | * <variable name> */ |
| 13122 | |
| 13123 | for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) { |
| 13124 | p = os_strchr(cmd, ' '); |
| 13125 | if (p == NULL) |
| 13126 | return -1; |
| 13127 | *p = '\0'; |
| 13128 | |
| 13129 | wpa_s[i] = global->ifaces; |
| 13130 | for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) { |
| 13131 | if (os_strcmp(cmd, wpa_s[i]->ifname) == 0) |
| 13132 | break; |
| 13133 | } |
| 13134 | |
| 13135 | if (!wpa_s[i]) { |
| 13136 | wpa_printf(MSG_DEBUG, |
| 13137 | "CTRL_IFACE: Could not find iface=%s", cmd); |
| 13138 | return -1; |
| 13139 | } |
| 13140 | |
| 13141 | cmd = p + 1; |
| 13142 | } |
| 13143 | |
| 13144 | return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]); |
| 13145 | } |
| 13146 | |
| 13147 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13148 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 13149 | static int wpas_global_ctrl_iface_save_config(struct wpa_global *global) |
| 13150 | { |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 13151 | int ret = 0, saved = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13152 | struct wpa_supplicant *wpa_s; |
| 13153 | |
| 13154 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 13155 | if (!wpa_s->conf->update_config) { |
| 13156 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)"); |
| 13157 | continue; |
| 13158 | } |
| 13159 | |
| 13160 | if (wpa_config_write(wpa_s->confname, wpa_s->conf)) { |
| 13161 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration"); |
| 13162 | ret = 1; |
| 13163 | } else { |
| 13164 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated"); |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 13165 | saved++; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13166 | } |
| 13167 | } |
| 13168 | |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 13169 | if (!saved && !ret) { |
| 13170 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 13171 | "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated"); |
| 13172 | ret = 1; |
| 13173 | } |
| 13174 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13175 | return ret; |
| 13176 | } |
| 13177 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 13178 | |
| 13179 | |
| 13180 | static int wpas_global_ctrl_iface_status(struct wpa_global *global, |
| 13181 | char *buf, size_t buflen) |
| 13182 | { |
| 13183 | char *pos, *end; |
| 13184 | int ret; |
| 13185 | struct wpa_supplicant *wpa_s; |
| 13186 | |
| 13187 | pos = buf; |
| 13188 | end = buf + buflen; |
| 13189 | |
| 13190 | #ifdef CONFIG_P2P |
| 13191 | if (global->p2p && !global->p2p_disabled) { |
| 13192 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR |
| 13193 | "\n" |
| 13194 | "p2p_state=%s\n", |
| 13195 | MAC2STR(global->p2p_dev_addr), |
| 13196 | p2p_get_state_txt(global->p2p)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13197 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13198 | return pos - buf; |
| 13199 | pos += ret; |
| 13200 | } else if (global->p2p) { |
| 13201 | ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13202 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13203 | return pos - buf; |
| 13204 | pos += ret; |
| 13205 | } |
| 13206 | #endif /* CONFIG_P2P */ |
| 13207 | |
| 13208 | #ifdef CONFIG_WIFI_DISPLAY |
| 13209 | ret = os_snprintf(pos, end - pos, "wifi_display=%d\n", |
| 13210 | !!global->wifi_display); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13211 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13212 | return pos - buf; |
| 13213 | pos += ret; |
| 13214 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 13215 | |
| 13216 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 13217 | ret = os_snprintf(pos, end - pos, "ifname=%s\n" |
| 13218 | "address=" MACSTR "\n", |
| 13219 | wpa_s->ifname, MAC2STR(wpa_s->own_addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13220 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13221 | return pos - buf; |
| 13222 | pos += ret; |
| 13223 | } |
| 13224 | |
| 13225 | return pos - buf; |
| 13226 | } |
| 13227 | |
| 13228 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13229 | #ifdef CONFIG_FST |
| 13230 | |
| 13231 | static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global, |
| 13232 | char *cmd, char *buf, |
| 13233 | size_t reply_size) |
| 13234 | { |
| 13235 | char ifname[IFNAMSIZ + 1]; |
| 13236 | struct fst_iface_cfg cfg; |
| 13237 | struct wpa_supplicant *wpa_s; |
| 13238 | struct fst_wpa_obj iface_obj; |
| 13239 | |
| 13240 | if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) { |
| 13241 | wpa_s = wpa_supplicant_get_iface(global, ifname); |
| 13242 | if (wpa_s) { |
| 13243 | if (wpa_s->fst) { |
| 13244 | wpa_printf(MSG_INFO, "FST: Already attached"); |
| 13245 | return -1; |
| 13246 | } |
| 13247 | fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj); |
| 13248 | wpa_s->fst = fst_attach(ifname, wpa_s->own_addr, |
| 13249 | &iface_obj, &cfg); |
| 13250 | if (wpa_s->fst) |
| 13251 | return os_snprintf(buf, reply_size, "OK\n"); |
| 13252 | } |
| 13253 | } |
| 13254 | |
| 13255 | return -1; |
| 13256 | } |
| 13257 | |
| 13258 | |
| 13259 | static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global, |
| 13260 | char *cmd, char *buf, |
| 13261 | size_t reply_size) |
| 13262 | { |
| 13263 | char ifname[IFNAMSIZ + 1]; |
| 13264 | struct wpa_supplicant *wpa_s; |
| 13265 | |
| 13266 | if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) { |
| 13267 | wpa_s = wpa_supplicant_get_iface(global, ifname); |
| 13268 | if (wpa_s) { |
| 13269 | if (!fst_iface_detach(ifname)) { |
| 13270 | wpa_s->fst = NULL; |
| 13271 | return os_snprintf(buf, reply_size, "OK\n"); |
| 13272 | } |
| 13273 | } |
| 13274 | } |
| 13275 | |
| 13276 | return -1; |
| 13277 | } |
| 13278 | |
| 13279 | #endif /* CONFIG_FST */ |
| 13280 | |
| 13281 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13282 | char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, |
| 13283 | char *buf, size_t *resp_len) |
| 13284 | { |
| 13285 | char *reply; |
| 13286 | const int reply_size = 2048; |
| 13287 | int reply_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13288 | int level = MSG_DEBUG; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13289 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 13290 | if (os_strncmp(buf, "IFNAME=", 7) == 0) { |
| 13291 | char *pos = os_strchr(buf + 7, ' '); |
| 13292 | if (pos) { |
| 13293 | *pos++ = '\0'; |
| 13294 | return wpas_global_ctrl_iface_ifname(global, |
| 13295 | buf + 7, pos, |
| 13296 | resp_len); |
| 13297 | } |
| 13298 | } |
| 13299 | |
| 13300 | reply = wpas_global_ctrl_iface_redir(global, buf, resp_len); |
| 13301 | if (reply) |
| 13302 | return reply; |
| 13303 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13304 | if (os_strcmp(buf, "PING") == 0) |
| 13305 | level = MSG_EXCESSIVE; |
| 13306 | wpa_hexdump_ascii(level, "RX global ctrl_iface", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13307 | (const u8 *) buf, os_strlen(buf)); |
| 13308 | |
| 13309 | reply = os_malloc(reply_size); |
| 13310 | if (reply == NULL) { |
| 13311 | *resp_len = 1; |
| 13312 | return NULL; |
| 13313 | } |
| 13314 | |
| 13315 | os_memcpy(reply, "OK\n", 3); |
| 13316 | reply_len = 3; |
| 13317 | |
| 13318 | if (os_strcmp(buf, "PING") == 0) { |
| 13319 | os_memcpy(reply, "PONG\n", 5); |
| 13320 | reply_len = 5; |
| 13321 | } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) { |
| 13322 | if (wpa_supplicant_global_iface_add(global, buf + 14)) |
| 13323 | reply_len = -1; |
| 13324 | } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) { |
| 13325 | if (wpa_supplicant_global_iface_remove(global, buf + 17)) |
| 13326 | reply_len = -1; |
| 13327 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
| 13328 | reply_len = wpa_supplicant_global_iface_list( |
| 13329 | global, reply, reply_size); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 13330 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13331 | reply_len = wpa_supplicant_global_iface_interfaces( |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 13332 | global, buf + 10, reply, reply_size); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13333 | #ifdef CONFIG_FST |
| 13334 | } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) { |
| 13335 | reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11, |
| 13336 | reply, |
| 13337 | reply_size); |
| 13338 | } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) { |
| 13339 | reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11, |
| 13340 | reply, |
| 13341 | reply_size); |
| 13342 | } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) { |
| 13343 | reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size); |
| 13344 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13345 | } else if (os_strcmp(buf, "TERMINATE") == 0) { |
| 13346 | wpa_supplicant_terminate_proc(global); |
| 13347 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
| 13348 | wpas_notify_suspend(global); |
| 13349 | } else if (os_strcmp(buf, "RESUME") == 0) { |
| 13350 | wpas_notify_resume(global); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13351 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 13352 | if (wpas_global_ctrl_iface_set(global, buf + 4)) { |
| 13353 | #ifdef CONFIG_P2P |
| 13354 | if (global->p2p_init_wpa_s) { |
| 13355 | os_free(reply); |
| 13356 | /* Check if P2P redirection would work for this |
| 13357 | * command. */ |
| 13358 | return wpa_supplicant_ctrl_iface_process( |
| 13359 | global->p2p_init_wpa_s, |
| 13360 | buf, resp_len); |
| 13361 | } |
| 13362 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13363 | reply_len = -1; |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 13364 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13365 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
| 13366 | if (wpas_global_ctrl_iface_dup_network(global, buf + 12)) |
| 13367 | reply_len = -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13368 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 13369 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { |
| 13370 | if (wpas_global_ctrl_iface_save_config(global)) |
| 13371 | reply_len = -1; |
| 13372 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 13373 | } else if (os_strcmp(buf, "STATUS") == 0) { |
| 13374 | reply_len = wpas_global_ctrl_iface_status(global, reply, |
| 13375 | reply_size); |
Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 13376 | #ifdef CONFIG_MODULE_TESTS |
| 13377 | } else if (os_strcmp(buf, "MODULE_TESTS") == 0) { |
Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 13378 | if (wpas_module_tests() < 0) |
| 13379 | reply_len = -1; |
| 13380 | #endif /* CONFIG_MODULE_TESTS */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13381 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
| 13382 | if (wpa_debug_reopen_file() < 0) |
| 13383 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13384 | } else { |
| 13385 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); |
| 13386 | reply_len = 16; |
| 13387 | } |
| 13388 | |
| 13389 | if (reply_len < 0) { |
| 13390 | os_memcpy(reply, "FAIL\n", 5); |
| 13391 | reply_len = 5; |
| 13392 | } |
| 13393 | |
| 13394 | *resp_len = reply_len; |
| 13395 | return reply; |
| 13396 | } |