| 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 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2388 | #ifdef CONFIG_HS20 | 
|  | 2389 | if (wpa_s->current_bss && | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2390 | (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss, | 
|  | 2391 | HS20_IE_VENDOR_TYPE)) && | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2392 | wpa_s->wpa_proto == WPA_PROTO_RSN && | 
|  | 2393 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2394 | int release = 1; | 
|  | 2395 | if (hs20[1] >= 5) { | 
|  | 2396 | u8 rel_num = (hs20[6] & 0xf0) >> 4; | 
|  | 2397 | release = rel_num + 1; | 
|  | 2398 | } | 
|  | 2399 | ret = os_snprintf(pos, end - pos, "hs20=%d\n", release); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2400 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2401 | return pos - buf; | 
|  | 2402 | pos += ret; | 
|  | 2403 | } | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2404 |  | 
|  | 2405 | if (wpa_s->current_ssid) { | 
|  | 2406 | struct wpa_cred *cred; | 
|  | 2407 | char *type; | 
|  | 2408 |  | 
|  | 2409 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2410 | size_t i; | 
|  | 2411 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2412 | if (wpa_s->current_ssid->parent_cred != cred) | 
|  | 2413 | continue; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2414 |  | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2415 | if (cred->provisioning_sp) { | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2416 | ret = os_snprintf(pos, end - pos, | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2417 | "provisioning_sp=%s\n", | 
|  | 2418 | cred->provisioning_sp); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2419 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2420 | return pos - buf; | 
|  | 2421 | pos += ret; | 
|  | 2422 | } | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2423 |  | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2424 | if (!cred->domain) | 
|  | 2425 | goto no_domain; | 
|  | 2426 |  | 
|  | 2427 | i = 0; | 
|  | 2428 | if (wpa_s->current_bss && wpa_s->current_bss->anqp) { | 
|  | 2429 | struct wpabuf *names = | 
|  | 2430 | wpa_s->current_bss->anqp->domain_name; | 
|  | 2431 | for (i = 0; names && i < cred->num_domain; i++) | 
|  | 2432 | { | 
|  | 2433 | if (domain_name_list_contains( | 
|  | 2434 | names, cred->domain[i], 1)) | 
|  | 2435 | break; | 
|  | 2436 | } | 
|  | 2437 | if (i == cred->num_domain) | 
|  | 2438 | i = 0; /* show first entry by default */ | 
|  | 2439 | } | 
|  | 2440 | ret = os_snprintf(pos, end - pos, "home_sp=%s\n", | 
|  | 2441 | cred->domain[i]); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2442 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2443 | return pos - buf; | 
|  | 2444 | pos += ret; | 
|  | 2445 |  | 
|  | 2446 | no_domain: | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2447 | if (wpa_s->current_bss == NULL || | 
|  | 2448 | wpa_s->current_bss->anqp == NULL) | 
|  | 2449 | res = -1; | 
|  | 2450 | else | 
|  | 2451 | res = interworking_home_sp_cred( | 
|  | 2452 | wpa_s, cred, | 
|  | 2453 | wpa_s->current_bss->anqp->domain_name); | 
|  | 2454 | if (res > 0) | 
|  | 2455 | type = "home"; | 
|  | 2456 | else if (res == 0) | 
|  | 2457 | type = "roaming"; | 
|  | 2458 | else | 
|  | 2459 | type = "unknown"; | 
|  | 2460 |  | 
|  | 2461 | ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2462 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2463 | return pos - buf; | 
|  | 2464 | pos += ret; | 
|  | 2465 |  | 
|  | 2466 | break; | 
|  | 2467 | } | 
|  | 2468 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2469 | #endif /* CONFIG_HS20 */ | 
|  | 2470 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2471 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || | 
|  | 2472 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | 
|  | 2473 | res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, | 
|  | 2474 | verbose); | 
|  | 2475 | if (res >= 0) | 
|  | 2476 | pos += res; | 
|  | 2477 | } | 
|  | 2478 |  | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2479 | #ifdef CONFIG_MACSEC | 
|  | 2480 | res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos); | 
|  | 2481 | if (res > 0) | 
|  | 2482 | pos += res; | 
|  | 2483 | #endif /* CONFIG_MACSEC */ | 
|  | 2484 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2485 | sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len); | 
|  | 2486 | if (sess_id) { | 
|  | 2487 | char *start = pos; | 
|  | 2488 |  | 
|  | 2489 | ret = os_snprintf(pos, end - pos, "eap_session_id="); | 
|  | 2490 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2491 | return start - buf; | 
|  | 2492 | pos += ret; | 
|  | 2493 | ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len); | 
|  | 2494 | if (ret <= 0) | 
|  | 2495 | return start - buf; | 
|  | 2496 | pos += ret; | 
|  | 2497 | ret = os_snprintf(pos, end - pos, "\n"); | 
|  | 2498 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2499 | return start - buf; | 
|  | 2500 | pos += ret; | 
|  | 2501 | } | 
|  | 2502 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2503 | res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); | 
|  | 2504 | if (res >= 0) | 
|  | 2505 | pos += res; | 
|  | 2506 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2507 | #ifdef CONFIG_WPS | 
|  | 2508 | { | 
|  | 2509 | char uuid_str[100]; | 
|  | 2510 | uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str)); | 
|  | 2511 | ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2512 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2513 | return pos - buf; | 
|  | 2514 | pos += ret; | 
|  | 2515 | } | 
|  | 2516 | #endif /* CONFIG_WPS */ | 
|  | 2517 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2518 | if (wpa_s->ieee80211ac) { | 
|  | 2519 | ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n"); | 
|  | 2520 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2521 | return pos - buf; | 
|  | 2522 | pos += ret; | 
|  | 2523 | } | 
|  | 2524 |  | 
| Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 2525 | #ifdef ANDROID | 
| vandwalle | ffc7018 | 2014-09-11 11:40:14 -0700 | [diff] [blame] | 2526 | /* | 
|  | 2527 | * Allow using the STATUS command with default behavior, say for debug, | 
|  | 2528 | * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE | 
|  | 2529 | * events with STATUS-NO_EVENTS. | 
|  | 2530 | */ | 
|  | 2531 | if (os_strcmp(params, "-NO_EVENTS")) { | 
|  | 2532 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE | 
|  | 2533 | "id=%d state=%d BSSID=" MACSTR " SSID=%s", | 
|  | 2534 | wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, | 
|  | 2535 | wpa_s->wpa_state, | 
|  | 2536 | MAC2STR(wpa_s->bssid), | 
|  | 2537 | wpa_s->current_ssid && wpa_s->current_ssid->ssid ? | 
|  | 2538 | wpa_ssid_txt(wpa_s->current_ssid->ssid, | 
|  | 2539 | wpa_s->current_ssid->ssid_len) : ""); | 
|  | 2540 | if (wpa_s->wpa_state == WPA_COMPLETED) { | 
|  | 2541 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
|  | 2542 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED | 
|  | 2543 | "- connection to " MACSTR | 
|  | 2544 | " completed %s [id=%d id_str=%s]", | 
|  | 2545 | MAC2STR(wpa_s->bssid), "(auth)", | 
|  | 2546 | ssid ? ssid->id : -1, | 
|  | 2547 | ssid && ssid->id_str ? ssid->id_str : ""); | 
|  | 2548 | } | 
| Irfan Sheriff | bf5edf4 | 2012-01-11 16:54:57 -0800 | [diff] [blame] | 2549 | } | 
| Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 2550 | #endif /* ANDROID */ | 
|  | 2551 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2552 | return pos - buf; | 
|  | 2553 | } | 
|  | 2554 |  | 
|  | 2555 |  | 
|  | 2556 | static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, | 
|  | 2557 | char *cmd) | 
|  | 2558 | { | 
|  | 2559 | char *pos; | 
|  | 2560 | int id; | 
|  | 2561 | struct wpa_ssid *ssid; | 
|  | 2562 | u8 bssid[ETH_ALEN]; | 
|  | 2563 |  | 
|  | 2564 | /* cmd: "<network id> <BSSID>" */ | 
|  | 2565 | pos = os_strchr(cmd, ' '); | 
|  | 2566 | if (pos == NULL) | 
|  | 2567 | return -1; | 
|  | 2568 | *pos++ = '\0'; | 
|  | 2569 | id = atoi(cmd); | 
|  | 2570 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); | 
|  | 2571 | if (hwaddr_aton(pos, bssid)) { | 
|  | 2572 | wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); | 
|  | 2573 | return -1; | 
|  | 2574 | } | 
|  | 2575 |  | 
|  | 2576 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 2577 | if (ssid == NULL) { | 
|  | 2578 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | 
|  | 2579 | "to update", id); | 
|  | 2580 | return -1; | 
|  | 2581 | } | 
|  | 2582 |  | 
|  | 2583 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); | 
|  | 2584 | ssid->bssid_set = !is_zero_ether_addr(bssid); | 
|  | 2585 |  | 
|  | 2586 | return 0; | 
|  | 2587 | } | 
|  | 2588 |  | 
|  | 2589 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2590 | static int wpa_supplicant_ctrl_iface_bssid_ignore(struct wpa_supplicant *wpa_s, | 
|  | 2591 | char *cmd, char *buf, | 
|  | 2592 | size_t buflen) | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2593 | { | 
|  | 2594 | u8 bssid[ETH_ALEN]; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2595 | struct wpa_bssid_ignore *e; | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2596 | char *pos, *end; | 
|  | 2597 | int ret; | 
|  | 2598 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2599 | /* cmd: "BSSID_IGNORE [<BSSID>]" */ | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2600 | if (*cmd == '\0') { | 
|  | 2601 | pos = buf; | 
|  | 2602 | end = buf + buflen; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2603 | e = wpa_s->bssid_ignore; | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2604 | while (e) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2605 | ret = os_snprintf(pos, end - pos, MACSTR "\n", | 
|  | 2606 | MAC2STR(e->bssid)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2607 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2608 | return pos - buf; | 
|  | 2609 | pos += ret; | 
|  | 2610 | e = e->next; | 
|  | 2611 | } | 
|  | 2612 | return pos - buf; | 
|  | 2613 | } | 
|  | 2614 |  | 
|  | 2615 | cmd++; | 
|  | 2616 | if (os_strncmp(cmd, "clear", 5) == 0) { | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2617 | wpa_bssid_ignore_clear(wpa_s); | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2618 | os_memcpy(buf, "OK\n", 3); | 
|  | 2619 | return 3; | 
|  | 2620 | } | 
|  | 2621 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2622 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: BSSID_IGNORE bssid='%s'", cmd); | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2623 | if (hwaddr_aton(cmd, bssid)) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2624 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd); | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2625 | return -1; | 
|  | 2626 | } | 
|  | 2627 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2628 | /* | 
|  | 2629 | * Add the BSSID twice, so its count will be 2, causing it to be | 
|  | 2630 | * skipped when processing scan results. | 
|  | 2631 | */ | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2632 | ret = wpa_bssid_ignore_add(wpa_s, bssid); | 
| Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2633 | if (ret < 0) | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2634 | return -1; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2635 | ret = wpa_bssid_ignore_add(wpa_s, bssid); | 
| Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2636 | if (ret < 0) | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2637 | return -1; | 
|  | 2638 | os_memcpy(buf, "OK\n", 3); | 
|  | 2639 | return 3; | 
|  | 2640 | } | 
|  | 2641 |  | 
|  | 2642 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2643 | static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s, | 
|  | 2644 | char *cmd, char *buf, | 
|  | 2645 | size_t buflen) | 
|  | 2646 | { | 
|  | 2647 | char *pos, *end, *stamp; | 
|  | 2648 | int ret; | 
|  | 2649 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2650 | /* cmd: "LOG_LEVEL [<level>]" */ | 
|  | 2651 | if (*cmd == '\0') { | 
|  | 2652 | pos = buf; | 
|  | 2653 | end = buf + buflen; | 
|  | 2654 | ret = os_snprintf(pos, end - pos, "Current level: %s\n" | 
|  | 2655 | "Timestamp: %d\n", | 
|  | 2656 | debug_level_str(wpa_debug_level), | 
|  | 2657 | wpa_debug_timestamp); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2658 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2659 | ret = 0; | 
|  | 2660 |  | 
|  | 2661 | return ret; | 
|  | 2662 | } | 
|  | 2663 |  | 
|  | 2664 | while (*cmd == ' ') | 
|  | 2665 | cmd++; | 
|  | 2666 |  | 
|  | 2667 | stamp = os_strchr(cmd, ' '); | 
|  | 2668 | if (stamp) { | 
|  | 2669 | *stamp++ = '\0'; | 
|  | 2670 | while (*stamp == ' ') { | 
|  | 2671 | stamp++; | 
|  | 2672 | } | 
|  | 2673 | } | 
|  | 2674 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2675 | if (os_strlen(cmd)) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2676 | int level = str_to_debug_level(cmd); | 
|  | 2677 | if (level < 0) | 
|  | 2678 | return -1; | 
|  | 2679 | wpa_debug_level = level; | 
|  | 2680 | } | 
|  | 2681 |  | 
|  | 2682 | if (stamp && os_strlen(stamp)) | 
|  | 2683 | wpa_debug_timestamp = atoi(stamp); | 
|  | 2684 |  | 
|  | 2685 | os_memcpy(buf, "OK\n", 3); | 
|  | 2686 | return 3; | 
|  | 2687 | } | 
|  | 2688 |  | 
|  | 2689 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2690 | static int wpa_supplicant_ctrl_iface_list_networks( | 
| Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 2691 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2692 | { | 
| Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2693 | char *pos, *end, *prev; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2694 | struct wpa_ssid *ssid; | 
|  | 2695 | int ret; | 
|  | 2696 |  | 
|  | 2697 | pos = buf; | 
|  | 2698 | end = buf + buflen; | 
|  | 2699 | ret = os_snprintf(pos, end - pos, | 
|  | 2700 | "network id / ssid / bssid / flags\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2701 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2702 | return pos - buf; | 
|  | 2703 | pos += ret; | 
|  | 2704 |  | 
|  | 2705 | ssid = wpa_s->conf->ssid; | 
| Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 2706 |  | 
|  | 2707 | /* skip over ssids until we find next one */ | 
|  | 2708 | if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) { | 
|  | 2709 | int last_id = atoi(cmd + 8); | 
|  | 2710 | if (last_id != -1) { | 
|  | 2711 | while (ssid != NULL && ssid->id <= last_id) { | 
|  | 2712 | ssid = ssid->next; | 
|  | 2713 | } | 
|  | 2714 | } | 
|  | 2715 | } | 
|  | 2716 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2717 | while (ssid) { | 
| Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2718 | prev = pos; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2719 | ret = os_snprintf(pos, end - pos, "%d\t%s", | 
|  | 2720 | ssid->id, | 
|  | 2721 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2722 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2723 | return prev - buf; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2724 | pos += ret; | 
|  | 2725 | if (ssid->bssid_set) { | 
|  | 2726 | ret = os_snprintf(pos, end - pos, "\t" MACSTR, | 
|  | 2727 | MAC2STR(ssid->bssid)); | 
|  | 2728 | } else { | 
|  | 2729 | ret = os_snprintf(pos, end - pos, "\tany"); | 
|  | 2730 | } | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2731 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2732 | return prev - buf; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2733 | pos += ret; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2734 | ret = os_snprintf(pos, end - pos, "\t%s%s%s%s", | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2735 | ssid == wpa_s->current_ssid ? | 
|  | 2736 | "[CURRENT]" : "", | 
|  | 2737 | ssid->disabled ? "[DISABLED]" : "", | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2738 | ssid->disabled_until.sec ? | 
|  | 2739 | "[TEMP-DISABLED]" : "", | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2740 | ssid->disabled == 2 ? "[P2P-PERSISTENT]" : | 
|  | 2741 | ""); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2742 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2743 | return prev - buf; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2744 | pos += ret; | 
|  | 2745 | ret = os_snprintf(pos, end - pos, "\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2746 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2747 | return prev - buf; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2748 | pos += ret; | 
|  | 2749 |  | 
|  | 2750 | ssid = ssid->next; | 
|  | 2751 | } | 
|  | 2752 |  | 
|  | 2753 | return pos - buf; | 
|  | 2754 | } | 
|  | 2755 |  | 
|  | 2756 |  | 
|  | 2757 | static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) | 
|  | 2758 | { | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2759 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2760 | ret = os_snprintf(pos, end - pos, "-"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2761 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2762 | return pos; | 
|  | 2763 | pos += ret; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2764 | ret = wpa_write_ciphers(pos, end, cipher, "+"); | 
|  | 2765 | if (ret < 0) | 
|  | 2766 | return pos; | 
|  | 2767 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2768 | return pos; | 
|  | 2769 | } | 
|  | 2770 |  | 
|  | 2771 |  | 
|  | 2772 | static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, | 
|  | 2773 | const u8 *ie, size_t ie_len) | 
|  | 2774 | { | 
|  | 2775 | struct wpa_ie_data data; | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2776 | char *start; | 
|  | 2777 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2778 |  | 
|  | 2779 | ret = os_snprintf(pos, end - pos, "[%s-", proto); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2780 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2781 | return pos; | 
|  | 2782 | pos += ret; | 
|  | 2783 |  | 
|  | 2784 | if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { | 
|  | 2785 | ret = os_snprintf(pos, end - pos, "?]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2786 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2787 | return pos; | 
|  | 2788 | pos += ret; | 
|  | 2789 | return pos; | 
|  | 2790 | } | 
|  | 2791 |  | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2792 | start = pos; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2793 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2794 | ret = os_snprintf(pos, end - pos, "%sEAP", | 
|  | 2795 | pos == start ? "" : "+"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2796 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2797 | return pos; | 
|  | 2798 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2799 | } | 
|  | 2800 | if (data.key_mgmt & WPA_KEY_MGMT_PSK) { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2801 | ret = os_snprintf(pos, end - pos, "%sPSK", | 
|  | 2802 | pos == start ? "" : "+"); | 
| 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; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2806 | } | 
|  | 2807 | if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2808 | ret = os_snprintf(pos, end - pos, "%sNone", | 
|  | 2809 | pos == start ? "" : "+"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2810 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2811 | return pos; | 
|  | 2812 | pos += ret; | 
|  | 2813 | } | 
|  | 2814 | if (data.key_mgmt & WPA_KEY_MGMT_SAE) { | 
|  | 2815 | ret = os_snprintf(pos, end - pos, "%sSAE", | 
|  | 2816 | pos == start ? "" : "+"); | 
|  | 2817 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2818 | return pos; | 
|  | 2819 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2820 | } | 
|  | 2821 | #ifdef CONFIG_IEEE80211R | 
|  | 2822 | if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { | 
|  | 2823 | ret = os_snprintf(pos, end - pos, "%sFT/EAP", | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2824 | pos == start ? "" : "+"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2825 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2826 | return pos; | 
|  | 2827 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2828 | } | 
|  | 2829 | if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { | 
|  | 2830 | ret = os_snprintf(pos, end - pos, "%sFT/PSK", | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2831 | pos == start ? "" : "+"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2832 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2833 | return pos; | 
|  | 2834 | pos += ret; | 
|  | 2835 | } | 
|  | 2836 | if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) { | 
|  | 2837 | ret = os_snprintf(pos, end - pos, "%sFT/SAE", | 
|  | 2838 | pos == start ? "" : "+"); | 
|  | 2839 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2840 | return pos; | 
|  | 2841 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2842 | } | 
|  | 2843 | #endif /* CONFIG_IEEE80211R */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2844 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { | 
|  | 2845 | ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2846 | pos == start ? "" : "+"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2847 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2848 | return pos; | 
|  | 2849 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2850 | } | 
|  | 2851 | if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { | 
|  | 2852 | ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2853 | pos == start ? "" : "+"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2854 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2855 | return pos; | 
|  | 2856 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2857 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2858 |  | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2859 | #ifdef CONFIG_SUITEB | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2860 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { | 
|  | 2861 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B", | 
|  | 2862 | pos == start ? "" : "+"); | 
|  | 2863 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2864 | return pos; | 
|  | 2865 | pos += ret; | 
|  | 2866 | } | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2867 | #endif /* CONFIG_SUITEB */ | 
|  | 2868 |  | 
|  | 2869 | #ifdef CONFIG_SUITEB192 | 
|  | 2870 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { | 
|  | 2871 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192", | 
|  | 2872 | pos == start ? "" : "+"); | 
|  | 2873 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2874 | return pos; | 
|  | 2875 | pos += ret; | 
|  | 2876 | } | 
|  | 2877 | #endif /* CONFIG_SUITEB192 */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2878 |  | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2879 | #ifdef CONFIG_FILS | 
|  | 2880 | if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) { | 
|  | 2881 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA256", | 
|  | 2882 | pos == start ? "" : "+"); | 
|  | 2883 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2884 | return pos; | 
|  | 2885 | pos += ret; | 
|  | 2886 | } | 
|  | 2887 | if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) { | 
|  | 2888 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA384", | 
|  | 2889 | pos == start ? "" : "+"); | 
|  | 2890 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2891 | return pos; | 
|  | 2892 | pos += ret; | 
|  | 2893 | } | 
|  | 2894 | #ifdef CONFIG_IEEE80211R | 
|  | 2895 | if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) { | 
|  | 2896 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256", | 
|  | 2897 | pos == start ? "" : "+"); | 
|  | 2898 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2899 | return pos; | 
|  | 2900 | pos += ret; | 
|  | 2901 | } | 
|  | 2902 | if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) { | 
|  | 2903 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384", | 
|  | 2904 | pos == start ? "" : "+"); | 
|  | 2905 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2906 | return pos; | 
|  | 2907 | pos += ret; | 
|  | 2908 | } | 
|  | 2909 | #endif /* CONFIG_IEEE80211R */ | 
|  | 2910 | #endif /* CONFIG_FILS */ | 
|  | 2911 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2912 | #ifdef CONFIG_OWE | 
|  | 2913 | if (data.key_mgmt & WPA_KEY_MGMT_OWE) { | 
|  | 2914 | ret = os_snprintf(pos, end - pos, "%sOWE", | 
|  | 2915 | pos == start ? "" : "+"); | 
|  | 2916 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2917 | return pos; | 
|  | 2918 | pos += ret; | 
|  | 2919 | } | 
|  | 2920 | #endif /* CONFIG_OWE */ | 
|  | 2921 |  | 
|  | 2922 | #ifdef CONFIG_DPP | 
|  | 2923 | if (data.key_mgmt & WPA_KEY_MGMT_DPP) { | 
|  | 2924 | ret = os_snprintf(pos, end - pos, "%sDPP", | 
|  | 2925 | pos == start ? "" : "+"); | 
|  | 2926 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2927 | return pos; | 
|  | 2928 | pos += ret; | 
|  | 2929 | } | 
|  | 2930 | #endif /* CONFIG_DPP */ | 
|  | 2931 |  | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2932 | if (data.key_mgmt & WPA_KEY_MGMT_OSEN) { | 
|  | 2933 | ret = os_snprintf(pos, end - pos, "%sOSEN", | 
|  | 2934 | pos == start ? "" : "+"); | 
|  | 2935 | if (os_snprintf_error(end - pos, ret)) | 
|  | 2936 | return pos; | 
|  | 2937 | pos += ret; | 
|  | 2938 | } | 
|  | 2939 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2940 | pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); | 
|  | 2941 |  | 
|  | 2942 | if (data.capabilities & WPA_CAPABILITY_PREAUTH) { | 
|  | 2943 | ret = os_snprintf(pos, end - pos, "-preauth"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2944 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2945 | return pos; | 
|  | 2946 | pos += ret; | 
|  | 2947 | } | 
|  | 2948 |  | 
|  | 2949 | ret = os_snprintf(pos, end - pos, "]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2950 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2951 | return pos; | 
|  | 2952 | pos += ret; | 
|  | 2953 |  | 
|  | 2954 | return pos; | 
|  | 2955 | } | 
|  | 2956 |  | 
|  | 2957 |  | 
|  | 2958 | #ifdef CONFIG_WPS | 
|  | 2959 | static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, | 
|  | 2960 | char *pos, char *end, | 
|  | 2961 | struct wpabuf *wps_ie) | 
|  | 2962 | { | 
|  | 2963 | int ret; | 
|  | 2964 | const char *txt; | 
|  | 2965 |  | 
|  | 2966 | if (wps_ie == NULL) | 
|  | 2967 | return pos; | 
|  | 2968 | if (wps_is_selected_pbc_registrar(wps_ie)) | 
|  | 2969 | txt = "[WPS-PBC]"; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2970 | else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) | 
|  | 2971 | txt = "[WPS-AUTH]"; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2972 | else if (wps_is_selected_pin_registrar(wps_ie)) | 
|  | 2973 | txt = "[WPS-PIN]"; | 
|  | 2974 | else | 
|  | 2975 | txt = "[WPS]"; | 
|  | 2976 |  | 
|  | 2977 | ret = os_snprintf(pos, end - pos, "%s", txt); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2978 | if (!os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2979 | pos += ret; | 
|  | 2980 | wpabuf_free(wps_ie); | 
|  | 2981 | return pos; | 
|  | 2982 | } | 
|  | 2983 | #endif /* CONFIG_WPS */ | 
|  | 2984 |  | 
|  | 2985 |  | 
|  | 2986 | static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, | 
|  | 2987 | char *pos, char *end, | 
|  | 2988 | const struct wpa_bss *bss) | 
|  | 2989 | { | 
|  | 2990 | #ifdef CONFIG_WPS | 
|  | 2991 | struct wpabuf *wps_ie; | 
|  | 2992 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); | 
|  | 2993 | return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); | 
|  | 2994 | #else /* CONFIG_WPS */ | 
|  | 2995 | return pos; | 
|  | 2996 | #endif /* CONFIG_WPS */ | 
|  | 2997 | } | 
|  | 2998 |  | 
|  | 2999 |  | 
|  | 3000 | /* Format one result on one text line into a buffer. */ | 
|  | 3001 | static int wpa_supplicant_ctrl_iface_scan_result( | 
|  | 3002 | struct wpa_supplicant *wpa_s, | 
|  | 3003 | const struct wpa_bss *bss, char *buf, size_t buflen) | 
|  | 3004 | { | 
|  | 3005 | char *pos, *end; | 
|  | 3006 | int ret; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3007 | const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe, *rsnxe; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3008 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3009 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3010 | p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); | 
| Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 3011 | if (!p2p) | 
|  | 3012 | p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3013 | if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && | 
|  | 3014 | os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == | 
|  | 3015 | 0) | 
|  | 3016 | return 0; /* Do not show P2P listen discovery results here */ | 
|  | 3017 |  | 
|  | 3018 | pos = buf; | 
|  | 3019 | end = buf + buflen; | 
|  | 3020 |  | 
|  | 3021 | ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", | 
|  | 3022 | MAC2STR(bss->bssid), bss->freq, bss->level); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3023 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3024 | return -1; | 
|  | 3025 | pos += ret; | 
|  | 3026 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | 
|  | 3027 | if (ie) | 
|  | 3028 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); | 
|  | 3029 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3030 | if (ie2) { | 
|  | 3031 | pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2", | 
|  | 3032 | ie2, 2 + ie2[1]); | 
|  | 3033 | } | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3034 | rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX); | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3035 | if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) { | 
|  | 3036 | ret = os_snprintf(pos, end - pos, "[SAE-H2E]"); | 
|  | 3037 | if (os_snprintf_error(end - pos, ret)) | 
|  | 3038 | return -1; | 
|  | 3039 | pos += ret; | 
|  | 3040 | } | 
|  | 3041 | if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) { | 
|  | 3042 | ret = os_snprintf(pos, end - pos, "[SAE-PK]"); | 
|  | 3043 | if (os_snprintf_error(end - pos, ret)) | 
|  | 3044 | return -1; | 
|  | 3045 | pos += ret; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3046 | } | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 3047 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); | 
|  | 3048 | if (osen_ie) | 
|  | 3049 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", | 
|  | 3050 | osen_ie, 2 + osen_ie[1]); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3051 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); | 
|  | 3052 | if (owe) { | 
|  | 3053 | ret = os_snprintf(pos, end - pos, | 
|  | 3054 | ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]"); | 
|  | 3055 | if (os_snprintf_error(end - pos, ret)) | 
|  | 3056 | return -1; | 
|  | 3057 | pos += ret; | 
|  | 3058 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3059 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 3060 | if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3061 | ret = os_snprintf(pos, end - pos, "[WEP]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3062 | if (os_snprintf_error(end - pos, ret)) | 
|  | 3063 | return -1; | 
|  | 3064 | pos += ret; | 
|  | 3065 | } | 
|  | 3066 | if (mesh) { | 
|  | 3067 | ret = os_snprintf(pos, end - pos, "[MESH]"); | 
|  | 3068 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3069 | return -1; | 
|  | 3070 | pos += ret; | 
|  | 3071 | } | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3072 | if (bss_is_dmg(bss)) { | 
|  | 3073 | const char *s; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3074 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3075 | if (wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_EDMG_OPERATION)) { | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3076 | ret = os_snprintf(pos, end - pos, "[EDMG]"); | 
|  | 3077 | if (os_snprintf_error(end - pos, ret)) | 
|  | 3078 | return -1; | 
|  | 3079 | pos += ret; | 
|  | 3080 | } | 
|  | 3081 |  | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3082 | ret = os_snprintf(pos, end - pos, "[DMG]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3083 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3084 | return -1; | 
|  | 3085 | pos += ret; | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3086 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { | 
|  | 3087 | case IEEE80211_CAP_DMG_IBSS: | 
|  | 3088 | s = "[IBSS]"; | 
|  | 3089 | break; | 
|  | 3090 | case IEEE80211_CAP_DMG_AP: | 
|  | 3091 | s = "[ESS]"; | 
|  | 3092 | break; | 
|  | 3093 | case IEEE80211_CAP_DMG_PBSS: | 
|  | 3094 | s = "[PBSS]"; | 
|  | 3095 | break; | 
|  | 3096 | default: | 
|  | 3097 | s = ""; | 
|  | 3098 | break; | 
|  | 3099 | } | 
|  | 3100 | ret = os_snprintf(pos, end - pos, "%s", s); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3101 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3102 | return -1; | 
|  | 3103 | pos += ret; | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3104 | } else { | 
|  | 3105 | if (bss->caps & IEEE80211_CAP_IBSS) { | 
|  | 3106 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3107 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3108 | return -1; | 
|  | 3109 | pos += ret; | 
|  | 3110 | } | 
|  | 3111 | if (bss->caps & IEEE80211_CAP_ESS) { | 
|  | 3112 | ret = os_snprintf(pos, end - pos, "[ESS]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3113 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3114 | return -1; | 
|  | 3115 | pos += ret; | 
|  | 3116 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3117 | } | 
|  | 3118 | if (p2p) { | 
|  | 3119 | ret = os_snprintf(pos, end - pos, "[P2P]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3120 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3121 | return -1; | 
|  | 3122 | pos += ret; | 
|  | 3123 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3124 | #ifdef CONFIG_HS20 | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3125 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3126 | ret = os_snprintf(pos, end - pos, "[HS20]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3127 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3128 | return -1; | 
|  | 3129 | pos += ret; | 
|  | 3130 | } | 
|  | 3131 | #endif /* CONFIG_HS20 */ | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3132 | #ifdef CONFIG_FILS | 
|  | 3133 | if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) { | 
|  | 3134 | ret = os_snprintf(pos, end - pos, "[FILS]"); | 
|  | 3135 | if (os_snprintf_error(end - pos, ret)) | 
|  | 3136 | return -1; | 
|  | 3137 | pos += ret; | 
|  | 3138 | } | 
|  | 3139 | #endif /* CONFIG_FILS */ | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3140 | #ifdef CONFIG_FST | 
|  | 3141 | if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) { | 
|  | 3142 | ret = os_snprintf(pos, end - pos, "[FST]"); | 
|  | 3143 | if (os_snprintf_error(end - pos, ret)) | 
|  | 3144 | return -1; | 
|  | 3145 | pos += ret; | 
|  | 3146 | } | 
|  | 3147 | #endif /* CONFIG_FST */ | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3148 | if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) { | 
|  | 3149 | ret = os_snprintf(pos, end - pos, "[UTF-8]"); | 
|  | 3150 | if (os_snprintf_error(end - pos, ret)) | 
|  | 3151 | return -1; | 
|  | 3152 | pos += ret; | 
|  | 3153 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3154 |  | 
|  | 3155 | ret = os_snprintf(pos, end - pos, "\t%s", | 
|  | 3156 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3157 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3158 | return -1; | 
|  | 3159 | pos += ret; | 
|  | 3160 |  | 
|  | 3161 | ret = os_snprintf(pos, end - pos, "\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3162 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3163 | return -1; | 
|  | 3164 | pos += ret; | 
|  | 3165 |  | 
|  | 3166 | return pos - buf; | 
|  | 3167 | } | 
|  | 3168 |  | 
|  | 3169 |  | 
|  | 3170 | static int wpa_supplicant_ctrl_iface_scan_results( | 
|  | 3171 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | 
|  | 3172 | { | 
|  | 3173 | char *pos, *end; | 
|  | 3174 | struct wpa_bss *bss; | 
|  | 3175 | int ret; | 
|  | 3176 |  | 
|  | 3177 | pos = buf; | 
|  | 3178 | end = buf + buflen; | 
|  | 3179 | ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " | 
|  | 3180 | "flags / ssid\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3181 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3182 | return pos - buf; | 
|  | 3183 | pos += ret; | 
|  | 3184 |  | 
|  | 3185 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { | 
|  | 3186 | ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, | 
|  | 3187 | end - pos); | 
|  | 3188 | if (ret < 0 || ret >= end - pos) | 
|  | 3189 | return pos - buf; | 
|  | 3190 | pos += ret; | 
|  | 3191 | } | 
|  | 3192 |  | 
|  | 3193 | return pos - buf; | 
|  | 3194 | } | 
|  | 3195 |  | 
|  | 3196 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3197 | #ifdef CONFIG_MESH | 
|  | 3198 |  | 
|  | 3199 | static int wpa_supplicant_ctrl_iface_mesh_interface_add( | 
|  | 3200 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) | 
|  | 3201 | { | 
|  | 3202 | char *pos, ifname[IFNAMSIZ + 1]; | 
|  | 3203 |  | 
|  | 3204 | ifname[0] = '\0'; | 
|  | 3205 |  | 
|  | 3206 | pos = os_strstr(cmd, "ifname="); | 
|  | 3207 | if (pos) { | 
|  | 3208 | pos += 7; | 
|  | 3209 | os_strlcpy(ifname, pos, sizeof(ifname)); | 
|  | 3210 | } | 
|  | 3211 |  | 
|  | 3212 | if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0) | 
|  | 3213 | return -1; | 
|  | 3214 |  | 
|  | 3215 | os_strlcpy(reply, ifname, max_len); | 
|  | 3216 | return os_strlen(ifname); | 
|  | 3217 | } | 
|  | 3218 |  | 
|  | 3219 |  | 
|  | 3220 | static int wpa_supplicant_ctrl_iface_mesh_group_add( | 
|  | 3221 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3222 | { | 
|  | 3223 | int id; | 
|  | 3224 | struct wpa_ssid *ssid; | 
|  | 3225 |  | 
|  | 3226 | id = atoi(cmd); | 
|  | 3227 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id); | 
|  | 3228 |  | 
|  | 3229 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 3230 | if (ssid == NULL) { | 
|  | 3231 | wpa_printf(MSG_DEBUG, | 
|  | 3232 | "CTRL_IFACE: Could not find network id=%d", id); | 
|  | 3233 | return -1; | 
|  | 3234 | } | 
|  | 3235 | if (ssid->mode != WPAS_MODE_MESH) { | 
|  | 3236 | wpa_printf(MSG_DEBUG, | 
|  | 3237 | "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network"); | 
|  | 3238 | return -1; | 
|  | 3239 | } | 
|  | 3240 | if (ssid->key_mgmt != WPA_KEY_MGMT_NONE && | 
|  | 3241 | ssid->key_mgmt != WPA_KEY_MGMT_SAE) { | 
|  | 3242 | wpa_printf(MSG_ERROR, | 
|  | 3243 | "CTRL_IFACE: key_mgmt for mesh network should be open or SAE"); | 
|  | 3244 | return -1; | 
|  | 3245 | } | 
|  | 3246 |  | 
|  | 3247 | /* | 
|  | 3248 | * TODO: If necessary write our own group_add function, | 
|  | 3249 | * for now we can reuse select_network | 
|  | 3250 | */ | 
|  | 3251 | wpa_supplicant_select_network(wpa_s, ssid); | 
|  | 3252 |  | 
|  | 3253 | return 0; | 
|  | 3254 | } | 
|  | 3255 |  | 
|  | 3256 |  | 
|  | 3257 | static int wpa_supplicant_ctrl_iface_mesh_group_remove( | 
|  | 3258 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3259 | { | 
|  | 3260 | struct wpa_supplicant *orig; | 
|  | 3261 | struct wpa_global *global; | 
|  | 3262 | int found = 0; | 
|  | 3263 |  | 
|  | 3264 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd); | 
|  | 3265 |  | 
|  | 3266 | global = wpa_s->global; | 
|  | 3267 | orig = wpa_s; | 
|  | 3268 |  | 
|  | 3269 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 3270 | if (os_strcmp(wpa_s->ifname, cmd) == 0) { | 
|  | 3271 | found = 1; | 
|  | 3272 | break; | 
|  | 3273 | } | 
|  | 3274 | } | 
|  | 3275 | if (!found) { | 
|  | 3276 | wpa_printf(MSG_ERROR, | 
|  | 3277 | "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found", | 
|  | 3278 | cmd); | 
|  | 3279 | return -1; | 
|  | 3280 | } | 
|  | 3281 | if (wpa_s->mesh_if_created && wpa_s == orig) { | 
|  | 3282 | wpa_printf(MSG_ERROR, | 
|  | 3283 | "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself"); | 
|  | 3284 | return -1; | 
|  | 3285 | } | 
|  | 3286 |  | 
|  | 3287 | wpa_s->reassociate = 0; | 
|  | 3288 | wpa_s->disconnected = 1; | 
|  | 3289 | wpa_supplicant_cancel_sched_scan(wpa_s); | 
|  | 3290 | wpa_supplicant_cancel_scan(wpa_s); | 
|  | 3291 |  | 
|  | 3292 | /* | 
|  | 3293 | * TODO: If necessary write our own group_remove function, | 
|  | 3294 | * for now we can reuse deauthenticate | 
|  | 3295 | */ | 
|  | 3296 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); | 
|  | 3297 |  | 
|  | 3298 | if (wpa_s->mesh_if_created) | 
|  | 3299 | wpa_supplicant_remove_iface(global, wpa_s, 0); | 
|  | 3300 |  | 
|  | 3301 | return 0; | 
|  | 3302 | } | 
|  | 3303 |  | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3304 |  | 
|  | 3305 | static int wpa_supplicant_ctrl_iface_mesh_peer_remove( | 
|  | 3306 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3307 | { | 
|  | 3308 | u8 addr[ETH_ALEN]; | 
|  | 3309 |  | 
|  | 3310 | if (hwaddr_aton(cmd, addr) < 0) | 
|  | 3311 | return -1; | 
|  | 3312 |  | 
|  | 3313 | return wpas_mesh_peer_remove(wpa_s, addr); | 
|  | 3314 | } | 
|  | 3315 |  | 
|  | 3316 |  | 
|  | 3317 | static int wpa_supplicant_ctrl_iface_mesh_peer_add( | 
|  | 3318 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3319 | { | 
|  | 3320 | u8 addr[ETH_ALEN]; | 
|  | 3321 | int duration; | 
|  | 3322 | char *pos; | 
|  | 3323 |  | 
|  | 3324 | pos = os_strstr(cmd, " duration="); | 
|  | 3325 | if (pos) { | 
|  | 3326 | *pos = '\0'; | 
|  | 3327 | duration = atoi(pos + 10); | 
|  | 3328 | } else { | 
|  | 3329 | duration = -1; | 
|  | 3330 | } | 
|  | 3331 |  | 
|  | 3332 | if (hwaddr_aton(cmd, addr)) | 
|  | 3333 | return -1; | 
|  | 3334 |  | 
|  | 3335 | return wpas_mesh_peer_add(wpa_s, addr, duration); | 
|  | 3336 | } | 
|  | 3337 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3338 |  | 
|  | 3339 | static int wpa_supplicant_ctrl_iface_mesh_link_probe( | 
|  | 3340 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3341 | { | 
|  | 3342 | struct ether_header *eth; | 
|  | 3343 | u8 addr[ETH_ALEN]; | 
|  | 3344 | u8 *buf; | 
|  | 3345 | char *pos; | 
|  | 3346 | size_t payload_len = 0, len; | 
|  | 3347 | int ret = -1; | 
|  | 3348 |  | 
|  | 3349 | if (hwaddr_aton(cmd, addr)) | 
|  | 3350 | return -1; | 
|  | 3351 |  | 
|  | 3352 | pos = os_strstr(cmd, " payload="); | 
|  | 3353 | if (pos) { | 
|  | 3354 | pos = pos + 9; | 
|  | 3355 | payload_len = os_strlen(pos); | 
|  | 3356 | if (payload_len & 1) | 
|  | 3357 | return -1; | 
|  | 3358 |  | 
|  | 3359 | payload_len /= 2; | 
|  | 3360 | } | 
|  | 3361 |  | 
|  | 3362 | len = ETH_HLEN + payload_len; | 
|  | 3363 | buf = os_malloc(len); | 
|  | 3364 | if (!buf) | 
|  | 3365 | return -1; | 
|  | 3366 |  | 
|  | 3367 | eth = (struct ether_header *) buf; | 
|  | 3368 | os_memcpy(eth->ether_dhost, addr, ETH_ALEN); | 
|  | 3369 | os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN); | 
|  | 3370 | eth->ether_type = htons(ETH_P_802_3); | 
|  | 3371 |  | 
|  | 3372 | if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0) | 
|  | 3373 | goto fail; | 
|  | 3374 |  | 
|  | 3375 | ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len); | 
|  | 3376 | fail: | 
|  | 3377 | os_free(buf); | 
|  | 3378 | return -ret; | 
|  | 3379 | } | 
|  | 3380 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3381 | #endif /* CONFIG_MESH */ | 
|  | 3382 |  | 
|  | 3383 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3384 | static int wpa_supplicant_ctrl_iface_select_network( | 
|  | 3385 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3386 | { | 
|  | 3387 | int id; | 
|  | 3388 | struct wpa_ssid *ssid; | 
| Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3389 | char *pos; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3390 |  | 
|  | 3391 | /* cmd: "<network id>" or "any" */ | 
| Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3392 | if (os_strncmp(cmd, "any", 3) == 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3393 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); | 
|  | 3394 | ssid = NULL; | 
|  | 3395 | } else { | 
|  | 3396 | id = atoi(cmd); | 
|  | 3397 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); | 
|  | 3398 |  | 
|  | 3399 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 3400 | if (ssid == NULL) { | 
|  | 3401 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | 
|  | 3402 | "network id=%d", id); | 
|  | 3403 | return -1; | 
|  | 3404 | } | 
|  | 3405 | if (ssid->disabled == 2) { | 
|  | 3406 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | 
|  | 3407 | "SELECT_NETWORK with persistent P2P group"); | 
|  | 3408 | return -1; | 
|  | 3409 | } | 
|  | 3410 | } | 
|  | 3411 |  | 
| Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3412 | pos = os_strstr(cmd, " freq="); | 
|  | 3413 | if (pos) { | 
|  | 3414 | int *freqs = freq_range_to_channel_list(wpa_s, pos + 6); | 
|  | 3415 | if (freqs) { | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3416 | os_free(wpa_s->select_network_scan_freqs); | 
|  | 3417 | wpa_s->select_network_scan_freqs = freqs; | 
| Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3418 | } | 
|  | 3419 | } | 
|  | 3420 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3421 | wpa_s->scan_min_time.sec = 0; | 
|  | 3422 | wpa_s->scan_min_time.usec = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3423 | wpa_supplicant_select_network(wpa_s, ssid); | 
|  | 3424 |  | 
|  | 3425 | return 0; | 
|  | 3426 | } | 
|  | 3427 |  | 
|  | 3428 |  | 
|  | 3429 | static int wpa_supplicant_ctrl_iface_enable_network( | 
|  | 3430 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3431 | { | 
|  | 3432 | int id; | 
|  | 3433 | struct wpa_ssid *ssid; | 
|  | 3434 |  | 
|  | 3435 | /* cmd: "<network id>" or "all" */ | 
|  | 3436 | if (os_strcmp(cmd, "all") == 0) { | 
|  | 3437 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); | 
|  | 3438 | ssid = NULL; | 
|  | 3439 | } else { | 
|  | 3440 | id = atoi(cmd); | 
|  | 3441 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); | 
|  | 3442 |  | 
|  | 3443 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 3444 | if (ssid == NULL) { | 
|  | 3445 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | 
|  | 3446 | "network id=%d", id); | 
|  | 3447 | return -1; | 
|  | 3448 | } | 
|  | 3449 | if (ssid->disabled == 2) { | 
|  | 3450 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | 
|  | 3451 | "ENABLE_NETWORK with persistent P2P group"); | 
|  | 3452 | return -1; | 
|  | 3453 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3454 |  | 
|  | 3455 | if (os_strstr(cmd, " no-connect")) { | 
|  | 3456 | ssid->disabled = 0; | 
|  | 3457 | return 0; | 
|  | 3458 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3459 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3460 | wpa_s->scan_min_time.sec = 0; | 
|  | 3461 | wpa_s->scan_min_time.usec = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3462 | wpa_supplicant_enable_network(wpa_s, ssid); | 
|  | 3463 |  | 
|  | 3464 | return 0; | 
|  | 3465 | } | 
|  | 3466 |  | 
|  | 3467 |  | 
|  | 3468 | static int wpa_supplicant_ctrl_iface_disable_network( | 
|  | 3469 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3470 | { | 
|  | 3471 | int id; | 
|  | 3472 | struct wpa_ssid *ssid; | 
|  | 3473 |  | 
|  | 3474 | /* cmd: "<network id>" or "all" */ | 
|  | 3475 | if (os_strcmp(cmd, "all") == 0) { | 
|  | 3476 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); | 
|  | 3477 | ssid = NULL; | 
|  | 3478 | } else { | 
|  | 3479 | id = atoi(cmd); | 
|  | 3480 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); | 
|  | 3481 |  | 
|  | 3482 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 3483 | if (ssid == NULL) { | 
|  | 3484 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | 
|  | 3485 | "network id=%d", id); | 
|  | 3486 | return -1; | 
|  | 3487 | } | 
|  | 3488 | if (ssid->disabled == 2) { | 
|  | 3489 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " | 
|  | 3490 | "DISABLE_NETWORK with persistent P2P " | 
|  | 3491 | "group"); | 
|  | 3492 | return -1; | 
|  | 3493 | } | 
|  | 3494 | } | 
|  | 3495 | wpa_supplicant_disable_network(wpa_s, ssid); | 
|  | 3496 |  | 
|  | 3497 | return 0; | 
|  | 3498 | } | 
|  | 3499 |  | 
|  | 3500 |  | 
|  | 3501 | static int wpa_supplicant_ctrl_iface_add_network( | 
|  | 3502 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) | 
|  | 3503 | { | 
|  | 3504 | struct wpa_ssid *ssid; | 
|  | 3505 | int ret; | 
|  | 3506 |  | 
|  | 3507 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); | 
|  | 3508 |  | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3509 | ssid = wpa_supplicant_add_network(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3510 | if (ssid == NULL) | 
|  | 3511 | return -1; | 
|  | 3512 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3513 | ret = os_snprintf(buf, buflen, "%d\n", ssid->id); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3514 | if (os_snprintf_error(buflen, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3515 | return -1; | 
|  | 3516 | return ret; | 
|  | 3517 | } | 
|  | 3518 |  | 
|  | 3519 |  | 
|  | 3520 | static int wpa_supplicant_ctrl_iface_remove_network( | 
|  | 3521 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3522 | { | 
|  | 3523 | int id; | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3524 | int result; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3525 |  | 
|  | 3526 | /* cmd: "<network id>" or "all" */ | 
|  | 3527 | if (os_strcmp(cmd, "all") == 0) { | 
|  | 3528 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3529 | return wpa_supplicant_remove_all_networks(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3530 | } | 
|  | 3531 |  | 
|  | 3532 | id = atoi(cmd); | 
|  | 3533 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); | 
|  | 3534 |  | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3535 | result = wpa_supplicant_remove_network(wpa_s, id); | 
|  | 3536 | if (result == -1) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3537 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | 
|  | 3538 | "id=%d", id); | 
|  | 3539 | return -1; | 
|  | 3540 | } | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3541 | if (result == -2) { | 
| Deepthi Gowri | a831d78 | 2012-09-03 11:55:38 +0300 | [diff] [blame] | 3542 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the " | 
|  | 3543 | "network id=%d", id); | 
|  | 3544 | return -1; | 
|  | 3545 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3546 | return 0; | 
|  | 3547 | } | 
|  | 3548 |  | 
|  | 3549 |  | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3550 | static int wpa_supplicant_ctrl_iface_update_network( | 
|  | 3551 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, | 
|  | 3552 | char *name, char *value) | 
|  | 3553 | { | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3554 | int ret; | 
|  | 3555 |  | 
|  | 3556 | ret = wpa_config_set(ssid, name, value, 0); | 
|  | 3557 | if (ret < 0) { | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3558 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " | 
|  | 3559 | "variable '%s'", name); | 
|  | 3560 | return -1; | 
|  | 3561 | } | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3562 | if (ret == 1) | 
|  | 3563 | return 0; /* No change to the previously configured value */ | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3564 |  | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3565 | #ifdef CONFIG_BGSCAN | 
|  | 3566 | if (os_strcmp(name, "bgscan") == 0) { | 
|  | 3567 | /* | 
|  | 3568 | * Reset the bgscan parameters for the current network and | 
|  | 3569 | * return. There's no need to flush caches for bgscan parameter | 
|  | 3570 | * changes. | 
|  | 3571 | */ | 
|  | 3572 | if (wpa_s->current_ssid == ssid && | 
|  | 3573 | wpa_s->wpa_state == WPA_COMPLETED) | 
|  | 3574 | wpa_supplicant_reset_bgscan(wpa_s); | 
|  | 3575 | return 0; | 
|  | 3576 | } | 
|  | 3577 | #endif /* CONFIG_BGSCAN */ | 
|  | 3578 |  | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3579 | if (os_strcmp(name, "bssid") != 0 && | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3580 | os_strcmp(name, "bssid_hint") != 0 && | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3581 | os_strcmp(name, "priority") != 0) { | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3582 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); | 
|  | 3583 |  | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3584 | if (wpa_s->current_ssid == ssid || | 
|  | 3585 | wpa_s->current_ssid == NULL) { | 
|  | 3586 | /* | 
|  | 3587 | * Invalidate the EAP session cache if anything in the | 
|  | 3588 | * current or previously used configuration changes. | 
|  | 3589 | */ | 
|  | 3590 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | 
|  | 3591 | } | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3592 | } | 
|  | 3593 |  | 
|  | 3594 | if ((os_strcmp(name, "psk") == 0 && | 
|  | 3595 | value[0] == '"' && ssid->ssid_len) || | 
|  | 3596 | (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) | 
|  | 3597 | wpa_config_update_psk(ssid); | 
|  | 3598 | else if (os_strcmp(name, "priority") == 0) | 
|  | 3599 | wpa_config_update_prio_list(wpa_s->conf); | 
|  | 3600 |  | 
|  | 3601 | return 0; | 
|  | 3602 | } | 
|  | 3603 |  | 
|  | 3604 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3605 | static int wpa_supplicant_ctrl_iface_set_network( | 
|  | 3606 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 3607 | { | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3608 | int id, ret, prev_bssid_set, prev_disabled; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3609 | struct wpa_ssid *ssid; | 
|  | 3610 | char *name, *value; | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3611 | u8 prev_bssid[ETH_ALEN]; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3612 |  | 
|  | 3613 | /* cmd: "<network id> <variable name> <value>" */ | 
|  | 3614 | name = os_strchr(cmd, ' '); | 
|  | 3615 | if (name == NULL) | 
|  | 3616 | return -1; | 
|  | 3617 | *name++ = '\0'; | 
|  | 3618 |  | 
|  | 3619 | value = os_strchr(name, ' '); | 
|  | 3620 | if (value == NULL) | 
|  | 3621 | return -1; | 
|  | 3622 | *value++ = '\0'; | 
|  | 3623 |  | 
|  | 3624 | id = atoi(cmd); | 
|  | 3625 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", | 
|  | 3626 | id, name); | 
|  | 3627 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | 
|  | 3628 | (u8 *) value, os_strlen(value)); | 
|  | 3629 |  | 
|  | 3630 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 3631 | if (ssid == NULL) { | 
|  | 3632 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " | 
|  | 3633 | "id=%d", id); | 
|  | 3634 | return -1; | 
|  | 3635 | } | 
|  | 3636 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3637 | prev_bssid_set = ssid->bssid_set; | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3638 | prev_disabled = ssid->disabled; | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3639 | os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN); | 
|  | 3640 | ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name, | 
|  | 3641 | value); | 
|  | 3642 | if (ret == 0 && | 
|  | 3643 | (ssid->bssid_set != prev_bssid_set || | 
|  | 3644 | os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0)) | 
|  | 3645 | wpas_notify_network_bssid_set_changed(wpa_s, ssid); | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3646 |  | 
|  | 3647 | if (prev_disabled != ssid->disabled && | 
|  | 3648 | (prev_disabled == 2 || ssid->disabled == 2)) | 
|  | 3649 | wpas_notify_network_type_changed(wpa_s, ssid); | 
|  | 3650 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3651 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3652 | } | 
|  | 3653 |  | 
|  | 3654 |  | 
|  | 3655 | static int wpa_supplicant_ctrl_iface_get_network( | 
|  | 3656 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | 
|  | 3657 | { | 
|  | 3658 | int id; | 
|  | 3659 | size_t res; | 
|  | 3660 | struct wpa_ssid *ssid; | 
|  | 3661 | char *name, *value; | 
|  | 3662 |  | 
|  | 3663 | /* cmd: "<network id> <variable name>" */ | 
|  | 3664 | name = os_strchr(cmd, ' '); | 
|  | 3665 | if (name == NULL || buflen == 0) | 
|  | 3666 | return -1; | 
|  | 3667 | *name++ = '\0'; | 
|  | 3668 |  | 
|  | 3669 | id = atoi(cmd); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3670 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'", | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3671 | id, name); | 
|  | 3672 |  | 
|  | 3673 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 3674 | if (ssid == NULL) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3675 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network " | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3676 | "id=%d", id); | 
|  | 3677 | return -1; | 
|  | 3678 | } | 
|  | 3679 |  | 
|  | 3680 | value = wpa_config_get_no_key(ssid, name); | 
|  | 3681 | if (value == NULL) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3682 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network " | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3683 | "variable '%s'", name); | 
|  | 3684 | return -1; | 
|  | 3685 | } | 
|  | 3686 |  | 
|  | 3687 | res = os_strlcpy(buf, value, buflen); | 
|  | 3688 | if (res >= buflen) { | 
|  | 3689 | os_free(value); | 
|  | 3690 | return -1; | 
|  | 3691 | } | 
|  | 3692 |  | 
|  | 3693 | os_free(value); | 
|  | 3694 |  | 
|  | 3695 | return res; | 
|  | 3696 | } | 
|  | 3697 |  | 
|  | 3698 |  | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3699 | static int wpa_supplicant_ctrl_iface_dup_network( | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3700 | struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 3701 | struct wpa_supplicant *dst_wpa_s) | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3702 | { | 
|  | 3703 | struct wpa_ssid *ssid_s, *ssid_d; | 
|  | 3704 | char *name, *id, *value; | 
|  | 3705 | int id_s, id_d, ret; | 
|  | 3706 |  | 
|  | 3707 | /* cmd: "<src network id> <dst network id> <variable name>" */ | 
|  | 3708 | id = os_strchr(cmd, ' '); | 
|  | 3709 | if (id == NULL) | 
|  | 3710 | return -1; | 
|  | 3711 | *id++ = '\0'; | 
|  | 3712 |  | 
|  | 3713 | name = os_strchr(id, ' '); | 
|  | 3714 | if (name == NULL) | 
|  | 3715 | return -1; | 
|  | 3716 | *name++ = '\0'; | 
|  | 3717 |  | 
|  | 3718 | id_s = atoi(cmd); | 
|  | 3719 | id_d = atoi(id); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3720 |  | 
|  | 3721 | wpa_printf(MSG_DEBUG, | 
|  | 3722 | "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'", | 
|  | 3723 | wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name); | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3724 |  | 
|  | 3725 | ssid_s = wpa_config_get_network(wpa_s->conf, id_s); | 
|  | 3726 | if (ssid_s == NULL) { | 
|  | 3727 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | 
|  | 3728 | "network id=%d", id_s); | 
|  | 3729 | return -1; | 
|  | 3730 | } | 
|  | 3731 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3732 | ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d); | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3733 | if (ssid_d == NULL) { | 
|  | 3734 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3735 | "network id=%d", id_d); | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3736 | return -1; | 
|  | 3737 | } | 
|  | 3738 |  | 
|  | 3739 | value = wpa_config_get(ssid_s, name); | 
|  | 3740 | if (value == NULL) { | 
|  | 3741 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " | 
|  | 3742 | "variable '%s'", name); | 
|  | 3743 | return -1; | 
|  | 3744 | } | 
|  | 3745 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3746 | 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] | 3747 | value); | 
|  | 3748 |  | 
|  | 3749 | os_free(value); | 
|  | 3750 |  | 
|  | 3751 | return ret; | 
|  | 3752 | } | 
|  | 3753 |  | 
|  | 3754 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3755 | static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s, | 
|  | 3756 | char *buf, size_t buflen) | 
|  | 3757 | { | 
|  | 3758 | char *pos, *end; | 
|  | 3759 | struct wpa_cred *cred; | 
|  | 3760 | int ret; | 
|  | 3761 |  | 
|  | 3762 | pos = buf; | 
|  | 3763 | end = buf + buflen; | 
|  | 3764 | ret = os_snprintf(pos, end - pos, | 
|  | 3765 | "cred id / realm / username / domain / imsi\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3766 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3767 | return pos - buf; | 
|  | 3768 | pos += ret; | 
|  | 3769 |  | 
|  | 3770 | cred = wpa_s->conf->cred; | 
|  | 3771 | while (cred) { | 
|  | 3772 | ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n", | 
|  | 3773 | cred->id, cred->realm ? cred->realm : "", | 
|  | 3774 | cred->username ? cred->username : "", | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3775 | cred->domain ? cred->domain[0] : "", | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3776 | cred->imsi ? cred->imsi : ""); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3777 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3778 | return pos - buf; | 
|  | 3779 | pos += ret; | 
|  | 3780 |  | 
|  | 3781 | cred = cred->next; | 
|  | 3782 | } | 
|  | 3783 |  | 
|  | 3784 | return pos - buf; | 
|  | 3785 | } | 
|  | 3786 |  | 
|  | 3787 |  | 
|  | 3788 | static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s, | 
|  | 3789 | char *buf, size_t buflen) | 
|  | 3790 | { | 
|  | 3791 | struct wpa_cred *cred; | 
|  | 3792 | int ret; | 
|  | 3793 |  | 
|  | 3794 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED"); | 
|  | 3795 |  | 
|  | 3796 | cred = wpa_config_add_cred(wpa_s->conf); | 
|  | 3797 | if (cred == NULL) | 
|  | 3798 | return -1; | 
|  | 3799 |  | 
| Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3800 | wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id); | 
|  | 3801 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3802 | ret = os_snprintf(buf, buflen, "%d\n", cred->id); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3803 | if (os_snprintf_error(buflen, ret)) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3804 | return -1; | 
|  | 3805 | return ret; | 
|  | 3806 | } | 
|  | 3807 |  | 
|  | 3808 |  | 
|  | 3809 | static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s, | 
|  | 3810 | char *cmd) | 
|  | 3811 | { | 
|  | 3812 | int id; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3813 | struct wpa_cred *cred, *prev; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3814 |  | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3815 | /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or | 
|  | 3816 | * "provisioning_sp=<FQDN> */ | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3817 | if (os_strcmp(cmd, "all") == 0) { | 
|  | 3818 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all"); | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3819 | return wpas_remove_all_creds(wpa_s); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3820 | } | 
|  | 3821 |  | 
|  | 3822 | if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) { | 
|  | 3823 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'", | 
|  | 3824 | cmd + 8); | 
|  | 3825 | cred = wpa_s->conf->cred; | 
|  | 3826 | while (cred) { | 
|  | 3827 | prev = cred; | 
|  | 3828 | cred = cred->next; | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3829 | if (prev->domain) { | 
|  | 3830 | size_t i; | 
|  | 3831 | for (i = 0; i < prev->num_domain; i++) { | 
|  | 3832 | if (os_strcmp(prev->domain[i], cmd + 8) | 
|  | 3833 | != 0) | 
|  | 3834 | continue; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3835 | wpas_remove_cred(wpa_s, prev); | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3836 | break; | 
|  | 3837 | } | 
|  | 3838 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3839 | } | 
|  | 3840 | return 0; | 
|  | 3841 | } | 
|  | 3842 |  | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3843 | if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) { | 
|  | 3844 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'", | 
|  | 3845 | cmd + 16); | 
|  | 3846 | cred = wpa_s->conf->cred; | 
|  | 3847 | while (cred) { | 
|  | 3848 | prev = cred; | 
|  | 3849 | cred = cred->next; | 
|  | 3850 | if (prev->provisioning_sp && | 
|  | 3851 | os_strcmp(prev->provisioning_sp, cmd + 16) == 0) | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3852 | wpas_remove_cred(wpa_s, prev); | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3853 | } | 
|  | 3854 | return 0; | 
|  | 3855 | } | 
|  | 3856 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3857 | id = atoi(cmd); | 
|  | 3858 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id); | 
|  | 3859 |  | 
|  | 3860 | cred = wpa_config_get_cred(wpa_s->conf, id); | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3861 | return wpas_remove_cred(wpa_s, cred); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3862 | } | 
|  | 3863 |  | 
|  | 3864 |  | 
|  | 3865 | static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s, | 
|  | 3866 | char *cmd) | 
|  | 3867 | { | 
|  | 3868 | int id; | 
|  | 3869 | struct wpa_cred *cred; | 
|  | 3870 | char *name, *value; | 
|  | 3871 |  | 
|  | 3872 | /* cmd: "<cred id> <variable name> <value>" */ | 
|  | 3873 | name = os_strchr(cmd, ' '); | 
|  | 3874 | if (name == NULL) | 
|  | 3875 | return -1; | 
|  | 3876 | *name++ = '\0'; | 
|  | 3877 |  | 
|  | 3878 | value = os_strchr(name, ' '); | 
|  | 3879 | if (value == NULL) | 
|  | 3880 | return -1; | 
|  | 3881 | *value++ = '\0'; | 
|  | 3882 |  | 
|  | 3883 | id = atoi(cmd); | 
|  | 3884 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'", | 
|  | 3885 | id, name); | 
|  | 3886 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", | 
|  | 3887 | (u8 *) value, os_strlen(value)); | 
|  | 3888 |  | 
|  | 3889 | cred = wpa_config_get_cred(wpa_s->conf, id); | 
|  | 3890 | if (cred == NULL) { | 
|  | 3891 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | 
|  | 3892 | id); | 
|  | 3893 | return -1; | 
|  | 3894 | } | 
|  | 3895 |  | 
|  | 3896 | if (wpa_config_set_cred(cred, name, value, 0) < 0) { | 
|  | 3897 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred " | 
|  | 3898 | "variable '%s'", name); | 
|  | 3899 | return -1; | 
|  | 3900 | } | 
|  | 3901 |  | 
| Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3902 | wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name); | 
|  | 3903 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3904 | return 0; | 
|  | 3905 | } | 
|  | 3906 |  | 
|  | 3907 |  | 
| Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3908 | static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s, | 
|  | 3909 | char *cmd, char *buf, | 
|  | 3910 | size_t buflen) | 
|  | 3911 | { | 
|  | 3912 | int id; | 
|  | 3913 | size_t res; | 
|  | 3914 | struct wpa_cred *cred; | 
|  | 3915 | char *name, *value; | 
|  | 3916 |  | 
|  | 3917 | /* cmd: "<cred id> <variable name>" */ | 
|  | 3918 | name = os_strchr(cmd, ' '); | 
|  | 3919 | if (name == NULL) | 
|  | 3920 | return -1; | 
|  | 3921 | *name++ = '\0'; | 
|  | 3922 |  | 
|  | 3923 | id = atoi(cmd); | 
|  | 3924 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'", | 
|  | 3925 | id, name); | 
|  | 3926 |  | 
|  | 3927 | cred = wpa_config_get_cred(wpa_s->conf, id); | 
|  | 3928 | if (cred == NULL) { | 
|  | 3929 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", | 
|  | 3930 | id); | 
|  | 3931 | return -1; | 
|  | 3932 | } | 
|  | 3933 |  | 
|  | 3934 | value = wpa_config_get_cred_no_key(cred, name); | 
|  | 3935 | if (value == NULL) { | 
|  | 3936 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'", | 
|  | 3937 | name); | 
|  | 3938 | return -1; | 
|  | 3939 | } | 
|  | 3940 |  | 
|  | 3941 | res = os_strlcpy(buf, value, buflen); | 
|  | 3942 | if (res >= buflen) { | 
|  | 3943 | os_free(value); | 
|  | 3944 | return -1; | 
|  | 3945 | } | 
|  | 3946 |  | 
|  | 3947 | os_free(value); | 
|  | 3948 |  | 
|  | 3949 | return res; | 
|  | 3950 | } | 
|  | 3951 |  | 
|  | 3952 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3953 | #ifndef CONFIG_NO_CONFIG_WRITE | 
|  | 3954 | static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s) | 
|  | 3955 | { | 
|  | 3956 | int ret; | 
|  | 3957 |  | 
|  | 3958 | if (!wpa_s->conf->update_config) { | 
|  | 3959 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed " | 
|  | 3960 | "to update configuration (update_config=0)"); | 
|  | 3961 | return -1; | 
|  | 3962 | } | 
|  | 3963 |  | 
|  | 3964 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); | 
|  | 3965 | if (ret) { | 
|  | 3966 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to " | 
|  | 3967 | "update configuration"); | 
|  | 3968 | } else { | 
|  | 3969 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration" | 
|  | 3970 | " updated"); | 
|  | 3971 | } | 
|  | 3972 |  | 
|  | 3973 | return ret; | 
|  | 3974 | } | 
|  | 3975 | #endif /* CONFIG_NO_CONFIG_WRITE */ | 
|  | 3976 |  | 
|  | 3977 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3978 | struct cipher_info { | 
|  | 3979 | unsigned int capa; | 
|  | 3980 | const char *name; | 
|  | 3981 | int group_only; | 
|  | 3982 | }; | 
|  | 3983 |  | 
|  | 3984 | static const struct cipher_info ciphers[] = { | 
|  | 3985 | { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 }, | 
|  | 3986 | { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 }, | 
|  | 3987 | { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 }, | 
|  | 3988 | { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 }, | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3989 | #ifndef CONFIG_NO_TKIP | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3990 | { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 }, | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3991 | #endif /* CONFIG_NO_TKIP */ | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3992 | { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 }, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3993 | #ifdef CONFIG_WEP | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3994 | { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 }, | 
|  | 3995 | { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 } | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3996 | #endif /* CONFIG_WEP */ | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3997 | }; | 
|  | 3998 |  | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3999 | static const struct cipher_info ciphers_group_mgmt[] = { | 
|  | 4000 | { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 }, | 
|  | 4001 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 }, | 
|  | 4002 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 }, | 
|  | 4003 | { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 }, | 
|  | 4004 | }; | 
|  | 4005 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4006 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4007 | static int ctrl_iface_get_capability_pairwise(int res, bool strict, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4008 | struct wpa_driver_capa *capa, | 
|  | 4009 | char *buf, size_t buflen) | 
|  | 4010 | { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4011 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4012 | char *pos, *end; | 
|  | 4013 | size_t len; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4014 | unsigned int i; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4015 |  | 
|  | 4016 | pos = buf; | 
|  | 4017 | end = pos + buflen; | 
|  | 4018 |  | 
|  | 4019 | if (res < 0) { | 
|  | 4020 | if (strict) | 
|  | 4021 | return 0; | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4022 | #ifdef CONFIG_NO_TKIP | 
|  | 4023 | len = os_strlcpy(buf, "CCMP NONE", buflen); | 
|  | 4024 | #else /* CONFIG_NO_TKIP */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4025 | len = os_strlcpy(buf, "CCMP TKIP NONE", buflen); | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4026 | #endif /* CONFIG_NO_TKIP */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4027 | if (len >= buflen) | 
|  | 4028 | return -1; | 
|  | 4029 | return len; | 
|  | 4030 | } | 
|  | 4031 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4032 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { | 
|  | 4033 | if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) { | 
|  | 4034 | ret = os_snprintf(pos, end - pos, "%s%s", | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4035 | pos == buf ? "" : " ", | 
|  | 4036 | ciphers[i].name); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4037 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4038 | return pos - buf; | 
|  | 4039 | pos += ret; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4040 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4041 | } | 
|  | 4042 |  | 
|  | 4043 | return pos - buf; | 
|  | 4044 | } | 
|  | 4045 |  | 
|  | 4046 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4047 | static int ctrl_iface_get_capability_group(int res, bool strict, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4048 | struct wpa_driver_capa *capa, | 
|  | 4049 | char *buf, size_t buflen) | 
|  | 4050 | { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4051 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4052 | char *pos, *end; | 
|  | 4053 | size_t len; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4054 | unsigned int i; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4055 |  | 
|  | 4056 | pos = buf; | 
|  | 4057 | end = pos + buflen; | 
|  | 4058 |  | 
|  | 4059 | if (res < 0) { | 
|  | 4060 | if (strict) | 
|  | 4061 | return 0; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4062 | #ifdef CONFIG_WEP | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4063 | #ifdef CONFIG_NO_TKIP | 
|  | 4064 | len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen); | 
|  | 4065 | #else /* CONFIG_NO_TKIP */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4066 | len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen); | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4067 | #endif /* CONFIG_NO_TKIP */ | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4068 | #else /* CONFIG_WEP */ | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4069 | #ifdef CONFIG_NO_TKIP | 
|  | 4070 | len = os_strlcpy(buf, "CCMP", buflen); | 
|  | 4071 | #else /* CONFIG_NO_TKIP */ | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4072 | len = os_strlcpy(buf, "CCMP TKIP", buflen); | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4073 | #endif /* CONFIG_NO_TKIP */ | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4074 | #endif /* CONFIG_WEP */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4075 | if (len >= buflen) | 
|  | 4076 | return -1; | 
|  | 4077 | return len; | 
|  | 4078 | } | 
|  | 4079 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4080 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { | 
|  | 4081 | if (capa->enc & ciphers[i].capa) { | 
|  | 4082 | ret = os_snprintf(pos, end - pos, "%s%s", | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4083 | pos == buf ? "" : " ", | 
|  | 4084 | ciphers[i].name); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4085 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4086 | return pos - buf; | 
|  | 4087 | pos += ret; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4088 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4089 | } | 
|  | 4090 |  | 
|  | 4091 | return pos - buf; | 
|  | 4092 | } | 
|  | 4093 |  | 
|  | 4094 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4095 | static int ctrl_iface_get_capability_group_mgmt(int res, bool strict, | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4096 | struct wpa_driver_capa *capa, | 
|  | 4097 | char *buf, size_t buflen) | 
|  | 4098 | { | 
|  | 4099 | int ret; | 
|  | 4100 | char *pos, *end; | 
|  | 4101 | unsigned int i; | 
|  | 4102 |  | 
|  | 4103 | pos = buf; | 
|  | 4104 | end = pos + buflen; | 
|  | 4105 |  | 
|  | 4106 | if (res < 0) | 
|  | 4107 | return 0; | 
|  | 4108 |  | 
|  | 4109 | for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) { | 
|  | 4110 | if (capa->enc & ciphers_group_mgmt[i].capa) { | 
|  | 4111 | ret = os_snprintf(pos, end - pos, "%s%s", | 
|  | 4112 | pos == buf ? "" : " ", | 
|  | 4113 | ciphers_group_mgmt[i].name); | 
|  | 4114 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4115 | return pos - buf; | 
|  | 4116 | pos += ret; | 
|  | 4117 | } | 
|  | 4118 | } | 
|  | 4119 |  | 
|  | 4120 | return pos - buf; | 
|  | 4121 | } | 
|  | 4122 |  | 
|  | 4123 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4124 | static int iftype_str_to_index(const char *iftype_str) | 
|  | 4125 | { | 
|  | 4126 | if (!iftype_str) | 
|  | 4127 | return WPA_IF_MAX; | 
|  | 4128 |  | 
|  | 4129 | if (os_strcmp(iftype_str, "STATION") == 0) | 
|  | 4130 | return WPA_IF_STATION; | 
|  | 4131 |  | 
|  | 4132 | if (os_strcmp(iftype_str, "AP_VLAN") == 0) | 
|  | 4133 | return WPA_IF_AP_VLAN; | 
|  | 4134 |  | 
|  | 4135 | if (os_strcmp(iftype_str, "AP") == 0) | 
|  | 4136 | return WPA_IF_AP_BSS; | 
|  | 4137 |  | 
|  | 4138 | if (os_strcmp(iftype_str, "P2P_GO") == 0) | 
|  | 4139 | return WPA_IF_P2P_GO; | 
|  | 4140 |  | 
|  | 4141 | if (os_strcmp(iftype_str, "P2P_CLIENT") == 0) | 
|  | 4142 | return WPA_IF_P2P_CLIENT; | 
|  | 4143 |  | 
|  | 4144 | if (os_strcmp(iftype_str, "P2P_DEVICE") == 0) | 
|  | 4145 | return WPA_IF_P2P_DEVICE; | 
|  | 4146 |  | 
|  | 4147 | if (os_strcmp(iftype_str, "MESH") == 0) | 
|  | 4148 | return WPA_IF_MESH; | 
|  | 4149 |  | 
|  | 4150 | if (os_strcmp(iftype_str, "IBSS") == 0) | 
|  | 4151 | return WPA_IF_IBSS; | 
|  | 4152 |  | 
|  | 4153 | if (os_strcmp(iftype_str, "NAN") == 0) | 
|  | 4154 | return WPA_IF_NAN; | 
|  | 4155 |  | 
|  | 4156 | return WPA_IF_MAX; | 
|  | 4157 | } | 
|  | 4158 |  | 
|  | 4159 |  | 
|  | 4160 | static int ctrl_iface_get_capability_key_mgmt(int res, bool strict, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4161 | struct wpa_driver_capa *capa, | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4162 | const char *iftype_str, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4163 | char *buf, size_t buflen) | 
|  | 4164 | { | 
|  | 4165 | int ret; | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4166 | unsigned int key_mgmt; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4167 | char *pos, *end; | 
|  | 4168 | size_t len; | 
|  | 4169 |  | 
|  | 4170 | pos = buf; | 
|  | 4171 | end = pos + buflen; | 
|  | 4172 |  | 
|  | 4173 | if (res < 0) { | 
|  | 4174 | if (strict) | 
|  | 4175 | return 0; | 
|  | 4176 | len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE " | 
|  | 4177 | "NONE", buflen); | 
|  | 4178 | if (len >= buflen) | 
|  | 4179 | return -1; | 
|  | 4180 | return len; | 
|  | 4181 | } | 
|  | 4182 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4183 | if (iftype_str) { | 
|  | 4184 | enum wpa_driver_if_type iftype; | 
|  | 4185 |  | 
|  | 4186 | iftype = iftype_str_to_index(iftype_str); | 
|  | 4187 | if (iftype == WPA_IF_MAX) | 
|  | 4188 | return -1; | 
|  | 4189 | key_mgmt = capa->key_mgmt_iftype[iftype]; | 
|  | 4190 | } else { | 
|  | 4191 | key_mgmt = capa->key_mgmt; | 
|  | 4192 | } | 
|  | 4193 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4194 | ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4195 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4196 | return pos - buf; | 
|  | 4197 | pos += ret; | 
|  | 4198 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4199 | if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | 
|  | 4200 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4201 | ret = os_snprintf(pos, end - pos, " WPA-EAP"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4202 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4203 | return pos - buf; | 
|  | 4204 | pos += ret; | 
|  | 4205 | } | 
|  | 4206 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4207 | if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | 
|  | 4208 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4209 | ret = os_snprintf(pos, end - pos, " WPA-PSK"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4210 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4211 | return pos - buf; | 
|  | 4212 | pos += ret; | 
|  | 4213 | } | 
|  | 4214 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4215 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4216 | ret = os_snprintf(pos, end - pos, " WPA-NONE"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4217 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4218 | return pos - buf; | 
|  | 4219 | pos += ret; | 
|  | 4220 | } | 
|  | 4221 |  | 
| Tanmay Garg | a7fd80d | 2020-05-18 15:52:44 +0530 | [diff] [blame] | 4222 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WAPI_PSK) { | 
|  | 4223 | ret = os_snprintf(pos, end - pos, " WAPI-PSK"); | 
|  | 4224 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4225 | return pos - buf; | 
|  | 4226 | pos += ret; | 
|  | 4227 | } | 
|  | 4228 |  | 
|  | 4229 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE) { | 
|  | 4230 | ret = os_snprintf(pos, end - pos, " TPK-HANDSHAKE"); | 
|  | 4231 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4232 | return pos - buf; | 
|  | 4233 | pos += ret; | 
|  | 4234 | } | 
|  | 4235 |  | 
|  | 4236 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_CCKM) { | 
|  | 4237 | ret = os_snprintf(pos, end - pos, " CCKM"); | 
|  | 4238 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4239 | return pos - buf; | 
|  | 4240 | pos += ret; | 
|  | 4241 | } | 
|  | 4242 |  | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4243 | #ifdef CONFIG_SUITEB | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4244 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) { | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4245 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B"); | 
|  | 4246 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4247 | return pos - buf; | 
|  | 4248 | pos += ret; | 
|  | 4249 | } | 
|  | 4250 | #endif /* CONFIG_SUITEB */ | 
|  | 4251 | #ifdef CONFIG_SUITEB192 | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4252 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) { | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4253 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192"); | 
|  | 4254 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4255 | return pos - buf; | 
|  | 4256 | pos += ret; | 
|  | 4257 | } | 
|  | 4258 | #endif /* CONFIG_SUITEB192 */ | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4259 | #ifdef CONFIG_OWE | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4260 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) { | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4261 | ret = os_snprintf(pos, end - pos, " OWE"); | 
|  | 4262 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4263 | return pos - buf; | 
|  | 4264 | pos += ret; | 
|  | 4265 | } | 
|  | 4266 | #endif /* CONFIG_OWE */ | 
|  | 4267 | #ifdef CONFIG_DPP | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4268 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) { | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4269 | ret = os_snprintf(pos, end - pos, " DPP"); | 
|  | 4270 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4271 | return pos - buf; | 
|  | 4272 | pos += ret; | 
|  | 4273 | } | 
|  | 4274 | #endif /* CONFIG_DPP */ | 
|  | 4275 | #ifdef CONFIG_FILS | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4276 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) { | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4277 | ret = os_snprintf(pos, end - pos, " FILS-SHA256"); | 
|  | 4278 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4279 | return pos - buf; | 
|  | 4280 | pos += ret; | 
|  | 4281 | } | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4282 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) { | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4283 | ret = os_snprintf(pos, end - pos, " FILS-SHA384"); | 
|  | 4284 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4285 | return pos - buf; | 
|  | 4286 | pos += ret; | 
|  | 4287 | } | 
|  | 4288 | #ifdef CONFIG_IEEE80211R | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4289 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) { | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4290 | ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256"); | 
|  | 4291 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4292 | return pos - buf; | 
|  | 4293 | pos += ret; | 
|  | 4294 | } | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4295 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) { | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4296 | ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384"); | 
|  | 4297 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4298 | return pos - buf; | 
|  | 4299 | pos += ret; | 
|  | 4300 | } | 
|  | 4301 | #endif /* CONFIG_IEEE80211R */ | 
|  | 4302 | #endif /* CONFIG_FILS */ | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4303 | #ifdef CONFIG_IEEE80211R | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4304 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4305 | ret = os_snprintf(pos, end - pos, " FT-PSK"); | 
|  | 4306 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4307 | return pos - buf; | 
|  | 4308 | pos += ret; | 
|  | 4309 | } | 
| Tanmay Garg | a7fd80d | 2020-05-18 15:52:44 +0530 | [diff] [blame] | 4310 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) { | 
|  | 4311 | ret = os_snprintf(pos, end - pos, " FT-EAP"); | 
|  | 4312 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4313 | return pos - buf; | 
|  | 4314 | pos += ret; | 
|  | 4315 | } | 
|  | 4316 | #ifdef CONFIG_SAE | 
|  | 4317 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE) { | 
|  | 4318 | ret = os_snprintf(pos, end - pos, " FT-SAE"); | 
|  | 4319 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4320 | return pos - buf; | 
|  | 4321 | pos += ret; | 
|  | 4322 | } | 
|  | 4323 | #endif /* CONFIG_SAE */ | 
|  | 4324 | #ifdef CONFIG_SHA384 | 
|  | 4325 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384) { | 
|  | 4326 | ret = os_snprintf(pos, end - pos, " FT-EAP-SHA384"); | 
|  | 4327 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4328 | return pos - buf; | 
|  | 4329 | pos += ret; | 
|  | 4330 | } | 
|  | 4331 | #endif /* CONFIG_SHA384 */ | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4332 | #endif /* CONFIG_IEEE80211R */ | 
|  | 4333 | #ifdef CONFIG_SAE | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4334 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4335 | ret = os_snprintf(pos, end - pos, " SAE"); | 
|  | 4336 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4337 | return pos - buf; | 
|  | 4338 | pos += ret; | 
|  | 4339 | } | 
|  | 4340 | #endif /* CONFIG_SAE */ | 
| Tanmay Garg | a7fd80d | 2020-05-18 15:52:44 +0530 | [diff] [blame] | 4341 | #ifdef CONFIG_SHA256 | 
|  | 4342 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256) { | 
|  | 4343 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SHA256"); | 
|  | 4344 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4345 | return pos - buf; | 
|  | 4346 | pos += ret; | 
|  | 4347 | } | 
|  | 4348 |  | 
|  | 4349 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256) { | 
|  | 4350 | ret = os_snprintf(pos, end - pos, " WPA-PSK-SHA256"); | 
|  | 4351 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4352 | return pos - buf; | 
|  | 4353 | pos += ret; | 
|  | 4354 | } | 
|  | 4355 | #endif /* CONFIG_SHA256 */ | 
|  | 4356 | #ifdef CONFIG_HS20 | 
|  | 4357 | if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OSEN) { | 
|  | 4358 | ret = os_snprintf(pos, end - pos, " OSEN"); | 
|  | 4359 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4360 | return pos - buf; | 
|  | 4361 | pos += ret; | 
|  | 4362 | } | 
|  | 4363 | #endif /* CONFIG_HS20 */ | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4364 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4365 | return pos - buf; | 
|  | 4366 | } | 
|  | 4367 |  | 
|  | 4368 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4369 | static int ctrl_iface_get_capability_proto(int res, bool strict, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4370 | struct wpa_driver_capa *capa, | 
|  | 4371 | char *buf, size_t buflen) | 
|  | 4372 | { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4373 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4374 | char *pos, *end; | 
|  | 4375 | size_t len; | 
|  | 4376 |  | 
|  | 4377 | pos = buf; | 
|  | 4378 | end = pos + buflen; | 
|  | 4379 |  | 
|  | 4380 | if (res < 0) { | 
|  | 4381 | if (strict) | 
|  | 4382 | return 0; | 
|  | 4383 | len = os_strlcpy(buf, "RSN WPA", buflen); | 
|  | 4384 | if (len >= buflen) | 
|  | 4385 | return -1; | 
|  | 4386 | return len; | 
|  | 4387 | } | 
|  | 4388 |  | 
|  | 4389 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | 
|  | 4390 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4391 | ret = os_snprintf(pos, end - pos, "%sRSN", | 
|  | 4392 | pos == buf ? "" : " "); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4393 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4394 | return pos - buf; | 
|  | 4395 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4396 | } | 
|  | 4397 |  | 
|  | 4398 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | | 
|  | 4399 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4400 | ret = os_snprintf(pos, end - pos, "%sWPA", | 
|  | 4401 | pos == buf ? "" : " "); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4402 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4403 | return pos - buf; | 
|  | 4404 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4405 | } | 
|  | 4406 |  | 
|  | 4407 | return pos - buf; | 
|  | 4408 | } | 
|  | 4409 |  | 
|  | 4410 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4411 | 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] | 4412 | int res, bool strict, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4413 | struct wpa_driver_capa *capa, | 
|  | 4414 | char *buf, size_t buflen) | 
|  | 4415 | { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4416 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4417 | char *pos, *end; | 
|  | 4418 | size_t len; | 
|  | 4419 |  | 
|  | 4420 | pos = buf; | 
|  | 4421 | end = pos + buflen; | 
|  | 4422 |  | 
|  | 4423 | if (res < 0) { | 
|  | 4424 | if (strict) | 
|  | 4425 | return 0; | 
|  | 4426 | len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen); | 
|  | 4427 | if (len >= buflen) | 
|  | 4428 | return -1; | 
|  | 4429 | return len; | 
|  | 4430 | } | 
|  | 4431 |  | 
|  | 4432 | if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4433 | ret = os_snprintf(pos, end - pos, "%sOPEN", | 
|  | 4434 | pos == buf ? "" : " "); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4435 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4436 | return pos - buf; | 
|  | 4437 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4438 | } | 
|  | 4439 |  | 
|  | 4440 | if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) { | 
|  | 4441 | ret = os_snprintf(pos, end - pos, "%sSHARED", | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4442 | pos == buf ? "" : " "); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4443 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4444 | return pos - buf; | 
|  | 4445 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4446 | } | 
|  | 4447 |  | 
|  | 4448 | if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4449 | ret = os_snprintf(pos, end - pos, "%sLEAP", | 
|  | 4450 | pos == buf ? "" : " "); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4451 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4452 | return pos - buf; | 
|  | 4453 | pos += ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4454 | } | 
|  | 4455 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4456 | #ifdef CONFIG_SAE | 
|  | 4457 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) { | 
|  | 4458 | ret = os_snprintf(pos, end - pos, "%sSAE", | 
|  | 4459 | pos == buf ? "" : " "); | 
|  | 4460 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4461 | return pos - buf; | 
|  | 4462 | pos += ret; | 
|  | 4463 | } | 
|  | 4464 | #endif /* CONFIG_SAE */ | 
|  | 4465 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4466 | #ifdef CONFIG_FILS | 
|  | 4467 | if (wpa_is_fils_supported(wpa_s)) { | 
|  | 4468 | ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS", | 
|  | 4469 | pos == buf ? "" : " "); | 
|  | 4470 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4471 | return pos - buf; | 
|  | 4472 | pos += ret; | 
|  | 4473 | } | 
|  | 4474 |  | 
|  | 4475 | #ifdef CONFIG_FILS_SK_PFS | 
|  | 4476 | if (wpa_is_fils_sk_pfs_supported(wpa_s)) { | 
|  | 4477 | ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS", | 
|  | 4478 | pos == buf ? "" : " "); | 
|  | 4479 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4480 | return pos - buf; | 
|  | 4481 | pos += ret; | 
|  | 4482 | } | 
|  | 4483 | #endif /* CONFIG_FILS_SK_PFS */ | 
|  | 4484 | #endif /* CONFIG_FILS */ | 
|  | 4485 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4486 | #ifdef CONFIG_PASN | 
|  | 4487 | ret = os_snprintf(pos, end - pos, "%sPASN", | 
|  | 4488 | pos == buf ? "" : " "); | 
|  | 4489 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4490 | return pos - buf; | 
|  | 4491 | pos += ret; | 
|  | 4492 |  | 
|  | 4493 | #endif /* CONFIG_PASN */ | 
|  | 4494 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4495 | return pos - buf; | 
|  | 4496 | } | 
|  | 4497 |  | 
|  | 4498 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4499 | static int ctrl_iface_get_capability_modes(int res, bool strict, | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4500 | struct wpa_driver_capa *capa, | 
|  | 4501 | char *buf, size_t buflen) | 
|  | 4502 | { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4503 | int ret; | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4504 | char *pos, *end; | 
|  | 4505 | size_t len; | 
|  | 4506 |  | 
|  | 4507 | pos = buf; | 
|  | 4508 | end = pos + buflen; | 
|  | 4509 |  | 
|  | 4510 | if (res < 0) { | 
|  | 4511 | if (strict) | 
|  | 4512 | return 0; | 
|  | 4513 | len = os_strlcpy(buf, "IBSS AP", buflen); | 
|  | 4514 | if (len >= buflen) | 
|  | 4515 | return -1; | 
|  | 4516 | return len; | 
|  | 4517 | } | 
|  | 4518 |  | 
|  | 4519 | if (capa->flags & WPA_DRIVER_FLAGS_IBSS) { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4520 | ret = os_snprintf(pos, end - pos, "%sIBSS", | 
|  | 4521 | pos == buf ? "" : " "); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4522 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4523 | return pos - buf; | 
|  | 4524 | pos += ret; | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4525 | } | 
|  | 4526 |  | 
|  | 4527 | if (capa->flags & WPA_DRIVER_FLAGS_AP) { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 4528 | ret = os_snprintf(pos, end - pos, "%sAP", | 
|  | 4529 | pos == buf ? "" : " "); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4530 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4531 | return pos - buf; | 
|  | 4532 | pos += ret; | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4533 | } | 
|  | 4534 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4535 | #ifdef CONFIG_MESH | 
|  | 4536 | if (capa->flags & WPA_DRIVER_FLAGS_MESH) { | 
|  | 4537 | ret = os_snprintf(pos, end - pos, "%sMESH", | 
|  | 4538 | pos == buf ? "" : " "); | 
|  | 4539 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4540 | return pos - buf; | 
|  | 4541 | pos += ret; | 
|  | 4542 | } | 
|  | 4543 | #endif /* CONFIG_MESH */ | 
|  | 4544 |  | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4545 | return pos - buf; | 
|  | 4546 | } | 
|  | 4547 |  | 
|  | 4548 |  | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4549 | static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s, | 
|  | 4550 | char *buf, size_t buflen) | 
|  | 4551 | { | 
|  | 4552 | struct hostapd_channel_data *chnl; | 
|  | 4553 | int ret, i, j; | 
|  | 4554 | char *pos, *end, *hmode; | 
|  | 4555 |  | 
|  | 4556 | pos = buf; | 
|  | 4557 | end = pos + buflen; | 
|  | 4558 |  | 
|  | 4559 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | 
|  | 4560 | switch (wpa_s->hw.modes[j].mode) { | 
|  | 4561 | case HOSTAPD_MODE_IEEE80211B: | 
|  | 4562 | hmode = "B"; | 
|  | 4563 | break; | 
|  | 4564 | case HOSTAPD_MODE_IEEE80211G: | 
|  | 4565 | hmode = "G"; | 
|  | 4566 | break; | 
|  | 4567 | case HOSTAPD_MODE_IEEE80211A: | 
|  | 4568 | hmode = "A"; | 
|  | 4569 | break; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4570 | case HOSTAPD_MODE_IEEE80211AD: | 
|  | 4571 | hmode = "AD"; | 
|  | 4572 | break; | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4573 | default: | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4574 | continue; | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4575 | } | 
|  | 4576 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4577 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4578 | return pos - buf; | 
|  | 4579 | pos += ret; | 
|  | 4580 | chnl = wpa_s->hw.modes[j].channels; | 
|  | 4581 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4582 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | 
|  | 4583 | continue; | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4584 | ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4585 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4586 | return pos - buf; | 
|  | 4587 | pos += ret; | 
|  | 4588 | } | 
|  | 4589 | ret = os_snprintf(pos, end - pos, "\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4590 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4591 | return pos - buf; | 
|  | 4592 | pos += ret; | 
|  | 4593 | } | 
|  | 4594 |  | 
|  | 4595 | return pos - buf; | 
|  | 4596 | } | 
|  | 4597 |  | 
|  | 4598 |  | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4599 | static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s, | 
|  | 4600 | char *buf, size_t buflen) | 
|  | 4601 | { | 
|  | 4602 | struct hostapd_channel_data *chnl; | 
|  | 4603 | int ret, i, j; | 
|  | 4604 | char *pos, *end, *hmode; | 
|  | 4605 |  | 
|  | 4606 | pos = buf; | 
|  | 4607 | end = pos + buflen; | 
|  | 4608 |  | 
|  | 4609 | for (j = 0; j < wpa_s->hw.num_modes; j++) { | 
|  | 4610 | switch (wpa_s->hw.modes[j].mode) { | 
|  | 4611 | case HOSTAPD_MODE_IEEE80211B: | 
|  | 4612 | hmode = "B"; | 
|  | 4613 | break; | 
|  | 4614 | case HOSTAPD_MODE_IEEE80211G: | 
|  | 4615 | hmode = "G"; | 
|  | 4616 | break; | 
|  | 4617 | case HOSTAPD_MODE_IEEE80211A: | 
|  | 4618 | hmode = "A"; | 
|  | 4619 | break; | 
|  | 4620 | case HOSTAPD_MODE_IEEE80211AD: | 
|  | 4621 | hmode = "AD"; | 
|  | 4622 | break; | 
|  | 4623 | default: | 
|  | 4624 | continue; | 
|  | 4625 | } | 
|  | 4626 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n", | 
|  | 4627 | hmode); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4628 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4629 | return pos - buf; | 
|  | 4630 | pos += ret; | 
|  | 4631 | chnl = wpa_s->hw.modes[j].channels; | 
|  | 4632 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { | 
|  | 4633 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) | 
|  | 4634 | continue; | 
| Dmitry Shmidt | 5da5e35 | 2014-02-03 13:30:46 -0800 | [diff] [blame] | 4635 | ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n", | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4636 | chnl[i].chan, chnl[i].freq, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4637 | chnl[i].flag & HOSTAPD_CHAN_NO_IR ? | 
|  | 4638 | " (NO_IR)" : "", | 
| Dmitry Shmidt | 5da5e35 | 2014-02-03 13:30:46 -0800 | [diff] [blame] | 4639 | chnl[i].flag & HOSTAPD_CHAN_RADAR ? | 
|  | 4640 | " (DFS)" : ""); | 
|  | 4641 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4642 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4643 | return pos - buf; | 
|  | 4644 | pos += ret; | 
|  | 4645 | } | 
|  | 4646 | ret = os_snprintf(pos, end - pos, "\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4647 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4648 | return pos - buf; | 
|  | 4649 | pos += ret; | 
|  | 4650 | } | 
|  | 4651 |  | 
|  | 4652 | return pos - buf; | 
|  | 4653 | } | 
|  | 4654 |  | 
|  | 4655 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4656 | static int wpa_supplicant_ctrl_iface_get_capability( | 
|  | 4657 | struct wpa_supplicant *wpa_s, const char *_field, char *buf, | 
|  | 4658 | size_t buflen) | 
|  | 4659 | { | 
|  | 4660 | struct wpa_driver_capa capa; | 
|  | 4661 | int res; | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4662 | char *next_param, *curr_param, *iftype = NULL; | 
|  | 4663 | bool strict = false; | 
|  | 4664 | char field[50]; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4665 | size_t len; | 
|  | 4666 |  | 
|  | 4667 | /* Determine whether or not strict checking was requested */ | 
|  | 4668 | len = os_strlcpy(field, _field, sizeof(field)); | 
|  | 4669 | if (len >= sizeof(field)) | 
|  | 4670 | return -1; | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4671 |  | 
|  | 4672 | next_param = os_strchr(field, ' '); | 
|  | 4673 | while (next_param) { | 
|  | 4674 | *next_param++ = '\0'; | 
|  | 4675 | curr_param = next_param; | 
|  | 4676 | next_param = os_strchr(next_param, ' '); | 
|  | 4677 |  | 
|  | 4678 | if (next_param) | 
|  | 4679 | *next_param = '\0'; | 
|  | 4680 |  | 
|  | 4681 | if (os_strcmp(curr_param, "strict") == 0) | 
|  | 4682 | strict = true; | 
|  | 4683 | else if (os_strncmp(curr_param, "iftype=", 7) == 0) | 
|  | 4684 | iftype = curr_param + 7; | 
|  | 4685 | else | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4686 | return -1; | 
|  | 4687 | } | 
|  | 4688 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4689 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'%s%s%s", | 
|  | 4690 | field, iftype ? " iftype=" : "", iftype ? iftype : "", | 
|  | 4691 | strict ? " strict" : ""); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4692 |  | 
|  | 4693 | if (os_strcmp(field, "eap") == 0) { | 
|  | 4694 | return eap_get_names(buf, buflen); | 
|  | 4695 | } | 
|  | 4696 |  | 
|  | 4697 | res = wpa_drv_get_capa(wpa_s, &capa); | 
|  | 4698 |  | 
|  | 4699 | if (os_strcmp(field, "pairwise") == 0) | 
|  | 4700 | return ctrl_iface_get_capability_pairwise(res, strict, &capa, | 
|  | 4701 | buf, buflen); | 
|  | 4702 |  | 
|  | 4703 | if (os_strcmp(field, "group") == 0) | 
|  | 4704 | return ctrl_iface_get_capability_group(res, strict, &capa, | 
|  | 4705 | buf, buflen); | 
|  | 4706 |  | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4707 | if (os_strcmp(field, "group_mgmt") == 0) | 
|  | 4708 | return ctrl_iface_get_capability_group_mgmt(res, strict, &capa, | 
|  | 4709 | buf, buflen); | 
|  | 4710 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4711 | if (os_strcmp(field, "key_mgmt") == 0) | 
|  | 4712 | return ctrl_iface_get_capability_key_mgmt(res, strict, &capa, | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4713 | iftype, buf, buflen); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4714 |  | 
|  | 4715 | if (os_strcmp(field, "proto") == 0) | 
|  | 4716 | return ctrl_iface_get_capability_proto(res, strict, &capa, | 
|  | 4717 | buf, buflen); | 
|  | 4718 |  | 
|  | 4719 | if (os_strcmp(field, "auth_alg") == 0) | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4720 | return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict, | 
|  | 4721 | &capa, buf, buflen); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4722 |  | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4723 | if (os_strcmp(field, "modes") == 0) | 
|  | 4724 | return ctrl_iface_get_capability_modes(res, strict, &capa, | 
|  | 4725 | buf, buflen); | 
|  | 4726 |  | 
| Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 4727 | if (os_strcmp(field, "channels") == 0) | 
|  | 4728 | return ctrl_iface_get_capability_channels(wpa_s, buf, buflen); | 
|  | 4729 |  | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4730 | if (os_strcmp(field, "freq") == 0) | 
|  | 4731 | return ctrl_iface_get_capability_freq(wpa_s, buf, buflen); | 
|  | 4732 |  | 
| Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 4733 | #ifdef CONFIG_TDLS | 
|  | 4734 | if (os_strcmp(field, "tdls") == 0) | 
|  | 4735 | return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen); | 
|  | 4736 | #endif /* CONFIG_TDLS */ | 
|  | 4737 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4738 | #ifdef CONFIG_ERP | 
|  | 4739 | if (os_strcmp(field, "erp") == 0) { | 
|  | 4740 | res = os_snprintf(buf, buflen, "ERP"); | 
|  | 4741 | if (os_snprintf_error(buflen, res)) | 
|  | 4742 | return -1; | 
|  | 4743 | return res; | 
|  | 4744 | } | 
|  | 4745 | #endif /* CONFIG_EPR */ | 
|  | 4746 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4747 | #ifdef CONFIG_FIPS | 
|  | 4748 | if (os_strcmp(field, "fips") == 0) { | 
|  | 4749 | res = os_snprintf(buf, buflen, "FIPS"); | 
|  | 4750 | if (os_snprintf_error(buflen, res)) | 
|  | 4751 | return -1; | 
|  | 4752 | return res; | 
|  | 4753 | } | 
|  | 4754 | #endif /* CONFIG_FIPS */ | 
|  | 4755 |  | 
| Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 4756 | #ifdef CONFIG_ACS | 
|  | 4757 | if (os_strcmp(field, "acs") == 0) { | 
|  | 4758 | res = os_snprintf(buf, buflen, "ACS"); | 
|  | 4759 | if (os_snprintf_error(buflen, res)) | 
|  | 4760 | return -1; | 
|  | 4761 | return res; | 
|  | 4762 | } | 
|  | 4763 | #endif /* CONFIG_ACS */ | 
|  | 4764 |  | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4765 | #ifdef CONFIG_FILS | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4766 | if (os_strcmp(field, "fils") == 0) { | 
|  | 4767 | #ifdef CONFIG_FILS_SK_PFS | 
|  | 4768 | if (wpa_is_fils_supported(wpa_s) && | 
|  | 4769 | wpa_is_fils_sk_pfs_supported(wpa_s)) { | 
|  | 4770 | res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS"); | 
|  | 4771 | if (os_snprintf_error(buflen, res)) | 
|  | 4772 | return -1; | 
|  | 4773 | return res; | 
|  | 4774 | } | 
|  | 4775 | #endif /* CONFIG_FILS_SK_PFS */ | 
|  | 4776 |  | 
|  | 4777 | if (wpa_is_fils_supported(wpa_s)) { | 
|  | 4778 | res = os_snprintf(buf, buflen, "FILS"); | 
|  | 4779 | if (os_snprintf_error(buflen, res)) | 
|  | 4780 | return -1; | 
|  | 4781 | return res; | 
|  | 4782 | } | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4783 | } | 
|  | 4784 | #endif /* CONFIG_FILS */ | 
|  | 4785 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4786 | if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) { | 
|  | 4787 | res = os_snprintf(buf, buflen, "MULTIBSS-STA"); | 
|  | 4788 | if (os_snprintf_error(buflen, res)) | 
|  | 4789 | return -1; | 
|  | 4790 | return res; | 
|  | 4791 | } | 
|  | 4792 |  | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4793 | #ifdef CONFIG_DPP | 
|  | 4794 | if (os_strcmp(field, "dpp") == 0) { | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4795 | #ifdef CONFIG_DPP3 | 
|  | 4796 | res = os_snprintf(buf, buflen, "DPP=3"); | 
|  | 4797 | #elif defined(CONFIG_DPP2) | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4798 | res = os_snprintf(buf, buflen, "DPP=2"); | 
|  | 4799 | #else /* CONFIG_DPP2 */ | 
|  | 4800 | res = os_snprintf(buf, buflen, "DPP=1"); | 
|  | 4801 | #endif /* CONFIG_DPP2 */ | 
|  | 4802 | if (os_snprintf_error(buflen, res)) | 
|  | 4803 | return -1; | 
|  | 4804 | return res; | 
|  | 4805 | } | 
|  | 4806 | #endif /* CONFIG_DPP */ | 
|  | 4807 |  | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4808 | #ifdef CONFIG_SAE | 
|  | 4809 | if (os_strcmp(field, "sae") == 0 && | 
|  | 4810 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) { | 
|  | 4811 | #ifdef CONFIG_SAE_PK | 
|  | 4812 | res = os_snprintf(buf, buflen, "H2E PK"); | 
|  | 4813 | #else /* CONFIG_SAE_PK */ | 
|  | 4814 | res = os_snprintf(buf, buflen, "H2E"); | 
|  | 4815 | #endif /* CONFIG_SAE_PK */ | 
|  | 4816 | if (os_snprintf_error(buflen, res)) | 
|  | 4817 | return -1; | 
|  | 4818 | return res; | 
|  | 4819 | } | 
|  | 4820 | #endif /* CONFIG_SAE */ | 
|  | 4821 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4822 | #ifdef CONFIG_OCV | 
|  | 4823 | if (os_strcmp(field, "ocv") == 0) { | 
|  | 4824 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) || | 
|  | 4825 | (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) | 
|  | 4826 | res = os_snprintf(buf, buflen, "supported"); | 
|  | 4827 | else | 
|  | 4828 | res = os_snprintf(buf, buflen, "not supported"); | 
|  | 4829 | if (os_snprintf_error(buflen, res)) | 
|  | 4830 | return -1; | 
|  | 4831 | return res; | 
|  | 4832 | } | 
|  | 4833 | #endif /* CONFIG_OCV */ | 
|  | 4834 |  | 
|  | 4835 | if (os_strcmp(field, "beacon_prot") == 0) { | 
|  | 4836 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) || | 
|  | 4837 | (wpa_s->drv_flags2 & | 
|  | 4838 | WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT)) | 
|  | 4839 | res = os_snprintf(buf, buflen, "supported"); | 
|  | 4840 | else | 
|  | 4841 | res = os_snprintf(buf, buflen, "not supported"); | 
|  | 4842 | if (os_snprintf_error(buflen, res)) | 
|  | 4843 | return -1; | 
|  | 4844 | return res; | 
|  | 4845 | } | 
|  | 4846 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4847 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", | 
|  | 4848 | field); | 
|  | 4849 |  | 
|  | 4850 | return -1; | 
|  | 4851 | } | 
|  | 4852 |  | 
|  | 4853 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4854 | #ifdef CONFIG_INTERWORKING | 
|  | 4855 | static char * anqp_add_hex(char *pos, char *end, const char *title, | 
|  | 4856 | struct wpabuf *data) | 
|  | 4857 | { | 
|  | 4858 | char *start = pos; | 
|  | 4859 | size_t i; | 
|  | 4860 | int ret; | 
|  | 4861 | const u8 *d; | 
|  | 4862 |  | 
|  | 4863 | if (data == NULL) | 
|  | 4864 | return start; | 
|  | 4865 |  | 
|  | 4866 | ret = os_snprintf(pos, end - pos, "%s=", title); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4867 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4868 | return start; | 
|  | 4869 | pos += ret; | 
|  | 4870 |  | 
|  | 4871 | d = wpabuf_head_u8(data); | 
|  | 4872 | for (i = 0; i < wpabuf_len(data); i++) { | 
|  | 4873 | ret = os_snprintf(pos, end - pos, "%02x", *d++); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4874 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4875 | return start; | 
|  | 4876 | pos += ret; | 
|  | 4877 | } | 
|  | 4878 |  | 
|  | 4879 | ret = os_snprintf(pos, end - pos, "\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4880 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4881 | return start; | 
|  | 4882 | pos += ret; | 
|  | 4883 |  | 
|  | 4884 | return pos; | 
|  | 4885 | } | 
|  | 4886 | #endif /* CONFIG_INTERWORKING */ | 
|  | 4887 |  | 
|  | 4888 |  | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4889 | #ifdef CONFIG_FILS | 
|  | 4890 | static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end) | 
|  | 4891 | { | 
|  | 4892 | char *start = pos; | 
|  | 4893 | const u8 *ie, *ie_end; | 
|  | 4894 | u16 info, realms; | 
|  | 4895 | int ret; | 
|  | 4896 |  | 
|  | 4897 | ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION); | 
|  | 4898 | if (!ie) | 
|  | 4899 | return 0; | 
|  | 4900 | ie_end = ie + 2 + ie[1]; | 
|  | 4901 | ie += 2; | 
|  | 4902 | if (ie_end - ie < 2) | 
|  | 4903 | return -1; | 
|  | 4904 |  | 
|  | 4905 | info = WPA_GET_LE16(ie); | 
|  | 4906 | ie += 2; | 
|  | 4907 | ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info); | 
|  | 4908 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4909 | return 0; | 
|  | 4910 | pos += ret; | 
|  | 4911 |  | 
|  | 4912 | if (info & BIT(7)) { | 
|  | 4913 | /* Cache Identifier Included */ | 
|  | 4914 | if (ie_end - ie < 2) | 
|  | 4915 | return -1; | 
|  | 4916 | ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n", | 
|  | 4917 | ie[0], ie[1]); | 
|  | 4918 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4919 | return 0; | 
|  | 4920 | pos += ret; | 
|  | 4921 | ie += 2; | 
|  | 4922 | } | 
|  | 4923 |  | 
|  | 4924 | if (info & BIT(8)) { | 
|  | 4925 | /* HESSID Included */ | 
|  | 4926 | if (ie_end - ie < ETH_ALEN) | 
|  | 4927 | return -1; | 
|  | 4928 | ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n", | 
|  | 4929 | MAC2STR(ie)); | 
|  | 4930 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4931 | return 0; | 
|  | 4932 | pos += ret; | 
|  | 4933 | ie += ETH_ALEN; | 
|  | 4934 | } | 
|  | 4935 |  | 
|  | 4936 | realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3; | 
|  | 4937 | if (realms) { | 
|  | 4938 | if (ie_end - ie < realms * 2) | 
|  | 4939 | return -1; | 
|  | 4940 | ret = os_snprintf(pos, end - pos, "fils_realms="); | 
|  | 4941 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4942 | return 0; | 
|  | 4943 | pos += ret; | 
|  | 4944 |  | 
|  | 4945 | ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2); | 
|  | 4946 | if (ret <= 0) | 
|  | 4947 | return 0; | 
|  | 4948 | pos += ret; | 
|  | 4949 | ie += realms * 2; | 
|  | 4950 | ret = os_snprintf(pos, end - pos, "\n"); | 
|  | 4951 | if (os_snprintf_error(end - pos, ret)) | 
|  | 4952 | return 0; | 
|  | 4953 | pos += ret; | 
|  | 4954 | } | 
|  | 4955 |  | 
|  | 4956 | return pos - start; | 
|  | 4957 | } | 
|  | 4958 | #endif /* CONFIG_FILS */ | 
|  | 4959 |  | 
|  | 4960 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4961 | static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, | 
|  | 4962 | unsigned long mask, char *buf, size_t buflen) | 
|  | 4963 | { | 
|  | 4964 | size_t i; | 
|  | 4965 | int ret; | 
|  | 4966 | char *pos, *end; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4967 | const u8 *ie, *ie2, *osen_ie, *mesh, *owe, *rsnxe; | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4968 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4969 | pos = buf; | 
|  | 4970 | end = buf + buflen; | 
|  | 4971 |  | 
|  | 4972 | if (mask & WPA_BSS_MASK_ID) { | 
|  | 4973 | ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4974 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4975 | return 0; | 
|  | 4976 | pos += ret; | 
|  | 4977 | } | 
|  | 4978 |  | 
|  | 4979 | if (mask & WPA_BSS_MASK_BSSID) { | 
|  | 4980 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", | 
|  | 4981 | MAC2STR(bss->bssid)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4982 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4983 | return 0; | 
|  | 4984 | pos += ret; | 
|  | 4985 | } | 
|  | 4986 |  | 
|  | 4987 | if (mask & WPA_BSS_MASK_FREQ) { | 
|  | 4988 | ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4989 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4990 | return 0; | 
|  | 4991 | pos += ret; | 
|  | 4992 | } | 
|  | 4993 |  | 
|  | 4994 | if (mask & WPA_BSS_MASK_BEACON_INT) { | 
|  | 4995 | ret = os_snprintf(pos, end - pos, "beacon_int=%d\n", | 
|  | 4996 | bss->beacon_int); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4997 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4998 | return 0; | 
|  | 4999 | pos += ret; | 
|  | 5000 | } | 
|  | 5001 |  | 
|  | 5002 | if (mask & WPA_BSS_MASK_CAPABILITIES) { | 
|  | 5003 | ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n", | 
|  | 5004 | bss->caps); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5005 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5006 | return 0; | 
|  | 5007 | pos += ret; | 
|  | 5008 | } | 
|  | 5009 |  | 
|  | 5010 | if (mask & WPA_BSS_MASK_QUAL) { | 
|  | 5011 | ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5012 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5013 | return 0; | 
|  | 5014 | pos += ret; | 
|  | 5015 | } | 
|  | 5016 |  | 
|  | 5017 | if (mask & WPA_BSS_MASK_NOISE) { | 
|  | 5018 | ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5019 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5020 | return 0; | 
|  | 5021 | pos += ret; | 
|  | 5022 | } | 
|  | 5023 |  | 
|  | 5024 | if (mask & WPA_BSS_MASK_LEVEL) { | 
|  | 5025 | ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level); | 
| 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_TSF) { | 
|  | 5032 | ret = os_snprintf(pos, end - pos, "tsf=%016llu\n", | 
|  | 5033 | (unsigned long long) bss->tsf); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5034 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5035 | return 0; | 
|  | 5036 | pos += ret; | 
|  | 5037 | } | 
|  | 5038 |  | 
|  | 5039 | if (mask & WPA_BSS_MASK_AGE) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5040 | struct os_reltime now; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5041 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5042 | os_get_reltime(&now); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5043 | ret = os_snprintf(pos, end - pos, "age=%d\n", | 
|  | 5044 | (int) (now.sec - bss->last_update.sec)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5045 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5046 | return 0; | 
|  | 5047 | pos += ret; | 
|  | 5048 | } | 
|  | 5049 |  | 
|  | 5050 | if (mask & WPA_BSS_MASK_IE) { | 
|  | 5051 | ret = os_snprintf(pos, end - pos, "ie="); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5052 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5053 | return 0; | 
|  | 5054 | pos += ret; | 
|  | 5055 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5056 | ie = wpa_bss_ie_ptr(bss); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5057 | for (i = 0; i < bss->ie_len; i++) { | 
|  | 5058 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5059 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5060 | return 0; | 
|  | 5061 | pos += ret; | 
|  | 5062 | } | 
|  | 5063 |  | 
|  | 5064 | ret = os_snprintf(pos, end - pos, "\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5065 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5066 | return 0; | 
|  | 5067 | pos += ret; | 
|  | 5068 | } | 
|  | 5069 |  | 
|  | 5070 | if (mask & WPA_BSS_MASK_FLAGS) { | 
|  | 5071 | ret = os_snprintf(pos, end - pos, "flags="); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5072 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5073 | return 0; | 
|  | 5074 | pos += ret; | 
|  | 5075 |  | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5076 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); | 
|  | 5077 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5078 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | 
|  | 5079 | if (ie) | 
|  | 5080 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, | 
|  | 5081 | 2 + ie[1]); | 
|  | 5082 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); | 
|  | 5083 | if (ie2) | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5084 | pos = wpa_supplicant_ie_txt(pos, end, | 
|  | 5085 | mesh ? "RSN" : "WPA2", ie2, | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5086 | 2 + ie2[1]); | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5087 | rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX); | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5088 | if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) { | 
|  | 5089 | ret = os_snprintf(pos, end - pos, "[SAE-H2E]"); | 
|  | 5090 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5091 | return -1; | 
|  | 5092 | pos += ret; | 
|  | 5093 | } | 
|  | 5094 | if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) { | 
|  | 5095 | ret = os_snprintf(pos, end - pos, "[SAE-PK]"); | 
|  | 5096 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5097 | return -1; | 
|  | 5098 | pos += ret; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5099 | } | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 5100 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); | 
|  | 5101 | if (osen_ie) | 
|  | 5102 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", | 
|  | 5103 | osen_ie, 2 + osen_ie[1]); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5104 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); | 
|  | 5105 | if (owe) { | 
|  | 5106 | ret = os_snprintf( | 
|  | 5107 | pos, end - pos, | 
|  | 5108 | ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]"); | 
|  | 5109 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5110 | return 0; | 
|  | 5111 | pos += ret; | 
|  | 5112 | } | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5113 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 5114 | if (!ie && !ie2 && !osen_ie && | 
|  | 5115 | (bss->caps & IEEE80211_CAP_PRIVACY)) { | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5116 | ret = os_snprintf(pos, end - pos, "[WEP]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5117 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5118 | return 0; | 
|  | 5119 | pos += ret; | 
|  | 5120 | } | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5121 |  | 
|  | 5122 | if (mesh) { | 
|  | 5123 | ret = os_snprintf(pos, end - pos, "[MESH]"); | 
|  | 5124 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5125 | return 0; | 
|  | 5126 | pos += ret; | 
|  | 5127 | } | 
|  | 5128 |  | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5129 | if (bss_is_dmg(bss)) { | 
|  | 5130 | const char *s; | 
|  | 5131 | ret = os_snprintf(pos, end - pos, "[DMG]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5132 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5133 | return 0; | 
|  | 5134 | pos += ret; | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5135 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { | 
|  | 5136 | case IEEE80211_CAP_DMG_IBSS: | 
|  | 5137 | s = "[IBSS]"; | 
|  | 5138 | break; | 
|  | 5139 | case IEEE80211_CAP_DMG_AP: | 
|  | 5140 | s = "[ESS]"; | 
|  | 5141 | break; | 
|  | 5142 | case IEEE80211_CAP_DMG_PBSS: | 
|  | 5143 | s = "[PBSS]"; | 
|  | 5144 | break; | 
|  | 5145 | default: | 
|  | 5146 | s = ""; | 
|  | 5147 | break; | 
|  | 5148 | } | 
|  | 5149 | ret = os_snprintf(pos, end - pos, "%s", s); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5150 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5151 | return 0; | 
|  | 5152 | pos += ret; | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5153 | } else { | 
|  | 5154 | if (bss->caps & IEEE80211_CAP_IBSS) { | 
|  | 5155 | ret = os_snprintf(pos, end - pos, "[IBSS]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5156 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5157 | return 0; | 
|  | 5158 | pos += ret; | 
|  | 5159 | } | 
|  | 5160 | if (bss->caps & IEEE80211_CAP_ESS) { | 
|  | 5161 | ret = os_snprintf(pos, end - pos, "[ESS]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5162 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5163 | return 0; | 
|  | 5164 | pos += ret; | 
|  | 5165 | } | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5166 | } | 
| Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 5167 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || | 
|  | 5168 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5169 | ret = os_snprintf(pos, end - pos, "[P2P]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5170 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5171 | return 0; | 
|  | 5172 | pos += ret; | 
|  | 5173 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5174 | #ifdef CONFIG_HS20 | 
|  | 5175 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) { | 
|  | 5176 | ret = os_snprintf(pos, end - pos, "[HS20]"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5177 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5178 | return 0; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5179 | pos += ret; | 
|  | 5180 | } | 
|  | 5181 | #endif /* CONFIG_HS20 */ | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5182 | #ifdef CONFIG_FILS | 
|  | 5183 | if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) { | 
|  | 5184 | ret = os_snprintf(pos, end - pos, "[FILS]"); | 
|  | 5185 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5186 | return 0; | 
|  | 5187 | pos += ret; | 
|  | 5188 | } | 
|  | 5189 | #endif /* CONFIG_FILS */ | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5190 | #ifdef CONFIG_FST | 
|  | 5191 | if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) { | 
|  | 5192 | ret = os_snprintf(pos, end - pos, "[FST]"); | 
|  | 5193 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5194 | return 0; | 
|  | 5195 | pos += ret; | 
|  | 5196 | } | 
|  | 5197 | #endif /* CONFIG_FST */ | 
|  | 5198 | if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) { | 
|  | 5199 | ret = os_snprintf(pos, end - pos, "[UTF-8]"); | 
|  | 5200 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5201 | return 0; | 
|  | 5202 | pos += ret; | 
|  | 5203 | } | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5204 |  | 
|  | 5205 | ret = os_snprintf(pos, end - pos, "\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5206 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5207 | return 0; | 
|  | 5208 | pos += ret; | 
|  | 5209 | } | 
|  | 5210 |  | 
|  | 5211 | if (mask & WPA_BSS_MASK_SSID) { | 
|  | 5212 | ret = os_snprintf(pos, end - pos, "ssid=%s\n", | 
|  | 5213 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | 
| 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 | } | 
|  | 5218 |  | 
|  | 5219 | #ifdef CONFIG_WPS | 
|  | 5220 | if (mask & WPA_BSS_MASK_WPS_SCAN) { | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5221 | ie = wpa_bss_ie_ptr(bss); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5222 | ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5223 | if (ret >= end - pos) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5224 | return 0; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5225 | if (ret > 0) | 
|  | 5226 | pos += ret; | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5227 | } | 
|  | 5228 | #endif /* CONFIG_WPS */ | 
|  | 5229 |  | 
|  | 5230 | #ifdef CONFIG_P2P | 
|  | 5231 | if (mask & WPA_BSS_MASK_P2P_SCAN) { | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5232 | ie = wpa_bss_ie_ptr(bss); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5233 | ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end); | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5234 | if (ret >= end - pos) | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5235 | return 0; | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5236 | if (ret > 0) | 
|  | 5237 | pos += ret; | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5238 | } | 
|  | 5239 | #endif /* CONFIG_P2P */ | 
|  | 5240 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5241 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 5242 | if (mask & WPA_BSS_MASK_WIFI_DISPLAY) { | 
|  | 5243 | struct wpabuf *wfd; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5244 |  | 
|  | 5245 | ie = wpa_bss_ie_ptr(bss); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5246 | wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len, | 
|  | 5247 | WFD_IE_VENDOR_TYPE); | 
|  | 5248 | if (wfd) { | 
|  | 5249 | ret = os_snprintf(pos, end - pos, "wfd_subelems="); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5250 | if (os_snprintf_error(end - pos, ret)) { | 
| Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5251 | wpabuf_free(wfd); | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5252 | return 0; | 
| Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5253 | } | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5254 | pos += ret; | 
|  | 5255 |  | 
|  | 5256 | pos += wpa_snprintf_hex(pos, end - pos, | 
|  | 5257 | wpabuf_head(wfd), | 
|  | 5258 | wpabuf_len(wfd)); | 
|  | 5259 | wpabuf_free(wfd); | 
|  | 5260 |  | 
|  | 5261 | ret = os_snprintf(pos, end - pos, "\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5262 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5263 | return 0; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5264 | pos += ret; | 
|  | 5265 | } | 
|  | 5266 | } | 
|  | 5267 | #endif /* CONFIG_WIFI_DISPLAY */ | 
|  | 5268 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5269 | #ifdef CONFIG_INTERWORKING | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5270 | if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) { | 
|  | 5271 | struct wpa_bss_anqp *anqp = bss->anqp; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5272 | struct wpa_bss_anqp_elem *elem; | 
|  | 5273 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5274 | pos = anqp_add_hex(pos, end, "anqp_capability_list", | 
|  | 5275 | anqp->capability_list); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5276 | pos = anqp_add_hex(pos, end, "anqp_venue_name", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5277 | anqp->venue_name); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5278 | pos = anqp_add_hex(pos, end, "anqp_network_auth_type", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5279 | anqp->network_auth_type); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5280 | pos = anqp_add_hex(pos, end, "anqp_roaming_consortium", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5281 | anqp->roaming_consortium); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5282 | pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5283 | anqp->ip_addr_type_availability); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5284 | pos = anqp_add_hex(pos, end, "anqp_nai_realm", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5285 | anqp->nai_realm); | 
|  | 5286 | pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5287 | pos = anqp_add_hex(pos, end, "anqp_domain_name", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5288 | anqp->domain_name); | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5289 | pos = anqp_add_hex(pos, end, "anqp_fils_realm_info", | 
|  | 5290 | anqp->fils_realm_info); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5291 | #ifdef CONFIG_HS20 | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5292 | pos = anqp_add_hex(pos, end, "hs20_capability_list", | 
|  | 5293 | anqp->hs20_capability_list); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5294 | pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5295 | anqp->hs20_operator_friendly_name); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5296 | pos = anqp_add_hex(pos, end, "hs20_wan_metrics", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5297 | anqp->hs20_wan_metrics); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5298 | pos = anqp_add_hex(pos, end, "hs20_connection_capability", | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 5299 | anqp->hs20_connection_capability); | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5300 | pos = anqp_add_hex(pos, end, "hs20_operating_class", | 
|  | 5301 | anqp->hs20_operating_class); | 
|  | 5302 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_list", | 
|  | 5303 | anqp->hs20_osu_providers_list); | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5304 | pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata", | 
|  | 5305 | anqp->hs20_operator_icon_metadata); | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 5306 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list", | 
|  | 5307 | anqp->hs20_osu_providers_nai_list); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5308 | #endif /* CONFIG_HS20 */ | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5309 |  | 
|  | 5310 | dl_list_for_each(elem, &anqp->anqp_elems, | 
|  | 5311 | struct wpa_bss_anqp_elem, list) { | 
|  | 5312 | char title[20]; | 
|  | 5313 |  | 
|  | 5314 | os_snprintf(title, sizeof(title), "anqp[%u]", | 
|  | 5315 | elem->infoid); | 
|  | 5316 | pos = anqp_add_hex(pos, end, title, elem->payload); | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5317 | if (elem->protected_response) { | 
|  | 5318 | ret = os_snprintf(pos, end - pos, | 
|  | 5319 | "protected-anqp-info[%u]=1\n", | 
|  | 5320 | elem->infoid); | 
|  | 5321 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5322 | return 0; | 
|  | 5323 | pos += ret; | 
|  | 5324 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5325 | } | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5326 | } | 
|  | 5327 | #endif /* CONFIG_INTERWORKING */ | 
|  | 5328 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5329 | #ifdef CONFIG_MESH | 
|  | 5330 | if (mask & WPA_BSS_MASK_MESH_SCAN) { | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5331 | ie = wpa_bss_ie_ptr(bss); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5332 | ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end); | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5333 | if (ret >= end - pos) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5334 | return 0; | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5335 | if (ret > 0) | 
|  | 5336 | pos += ret; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5337 | } | 
|  | 5338 | #endif /* CONFIG_MESH */ | 
|  | 5339 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5340 | if (mask & WPA_BSS_MASK_SNR) { | 
|  | 5341 | ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr); | 
|  | 5342 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5343 | return 0; | 
|  | 5344 | pos += ret; | 
|  | 5345 | } | 
|  | 5346 |  | 
|  | 5347 | if (mask & WPA_BSS_MASK_EST_THROUGHPUT) { | 
|  | 5348 | ret = os_snprintf(pos, end - pos, "est_throughput=%d\n", | 
|  | 5349 | bss->est_throughput); | 
|  | 5350 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5351 | return 0; | 
|  | 5352 | pos += ret; | 
|  | 5353 | } | 
|  | 5354 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5355 | #ifdef CONFIG_FST | 
|  | 5356 | if (mask & WPA_BSS_MASK_FST) { | 
|  | 5357 | ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos); | 
|  | 5358 | if (ret < 0 || ret >= end - pos) | 
|  | 5359 | return 0; | 
|  | 5360 | pos += ret; | 
|  | 5361 | } | 
|  | 5362 | #endif /* CONFIG_FST */ | 
|  | 5363 |  | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5364 | if (mask & WPA_BSS_MASK_UPDATE_IDX) { | 
|  | 5365 | ret = os_snprintf(pos, end - pos, "update_idx=%u\n", | 
|  | 5366 | bss->last_update_idx); | 
|  | 5367 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5368 | return 0; | 
|  | 5369 | pos += ret; | 
|  | 5370 | } | 
|  | 5371 |  | 
|  | 5372 | if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) { | 
|  | 5373 | ret = os_snprintf(pos, end - pos, "beacon_ie="); | 
|  | 5374 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5375 | return 0; | 
|  | 5376 | pos += ret; | 
|  | 5377 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5378 | ie = wpa_bss_ie_ptr(bss); | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5379 | ie += bss->ie_len; | 
|  | 5380 | for (i = 0; i < bss->beacon_ie_len; i++) { | 
|  | 5381 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); | 
|  | 5382 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5383 | return 0; | 
|  | 5384 | pos += ret; | 
|  | 5385 | } | 
|  | 5386 |  | 
|  | 5387 | ret = os_snprintf(pos, end - pos, "\n"); | 
|  | 5388 | if (os_snprintf_error(end - pos, ret)) | 
|  | 5389 | return 0; | 
|  | 5390 | pos += ret; | 
|  | 5391 | } | 
|  | 5392 |  | 
|  | 5393 | #ifdef CONFIG_FILS | 
|  | 5394 | if (mask & WPA_BSS_MASK_FILS_INDICATION) { | 
|  | 5395 | ret = print_fils_indication(bss, pos, end); | 
|  | 5396 | if (ret < 0) | 
|  | 5397 | return 0; | 
|  | 5398 | pos += ret; | 
|  | 5399 | } | 
|  | 5400 | #endif /* CONFIG_FILS */ | 
|  | 5401 |  | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5402 | if (mask & WPA_BSS_MASK_DELIM) { | 
|  | 5403 | ret = os_snprintf(pos, end - pos, "====\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5404 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5405 | return 0; | 
|  | 5406 | pos += ret; | 
|  | 5407 | } | 
| Irfan Sheriff | e2ea008 | 2012-08-13 10:56:16 -0700 | [diff] [blame] | 5408 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5409 | return pos - buf; | 
|  | 5410 | } | 
|  | 5411 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5412 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5413 | static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s, | 
|  | 5414 | const char *cmd, char *buf, | 
|  | 5415 | size_t buflen) | 
|  | 5416 | { | 
|  | 5417 | u8 bssid[ETH_ALEN]; | 
|  | 5418 | size_t i; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5419 | struct wpa_bss *bss; | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5420 | struct wpa_bss *bsslast = NULL; | 
|  | 5421 | struct dl_list *next; | 
|  | 5422 | int ret = 0; | 
|  | 5423 | int len; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5424 | char *ctmp, *end = buf + buflen; | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5425 | unsigned long mask = WPA_BSS_MASK_ALL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5426 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5427 | if (os_strncmp(cmd, "RANGE=", 6) == 0) { | 
|  | 5428 | if (os_strncmp(cmd + 6, "ALL", 3) == 0) { | 
|  | 5429 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5430 | list_id); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5431 | bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss, | 
|  | 5432 | list_id); | 
|  | 5433 | } else { /* N1-N2 */ | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5434 | unsigned int id1, id2; | 
|  | 5435 |  | 
|  | 5436 | if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) { | 
|  | 5437 | wpa_printf(MSG_INFO, "Wrong BSS range " | 
|  | 5438 | "format"); | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5439 | return 0; | 
|  | 5440 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5441 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5442 | if (*(cmd + 6) == '-') | 
|  | 5443 | id1 = 0; | 
|  | 5444 | else | 
|  | 5445 | id1 = atoi(cmd + 6); | 
|  | 5446 | ctmp++; | 
|  | 5447 | if (*ctmp >= '0' && *ctmp <= '9') | 
|  | 5448 | id2 = atoi(ctmp); | 
|  | 5449 | else | 
|  | 5450 | id2 = (unsigned int) -1; | 
|  | 5451 | bss = wpa_bss_get_id_range(wpa_s, id1, id2); | 
|  | 5452 | if (id2 == (unsigned int) -1) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5453 | bsslast = dl_list_last(&wpa_s->bss_id, | 
|  | 5454 | struct wpa_bss, | 
|  | 5455 | list_id); | 
|  | 5456 | else { | 
|  | 5457 | bsslast = wpa_bss_get_id(wpa_s, id2); | 
|  | 5458 | if (bsslast == NULL && bss && id2 > id1) { | 
|  | 5459 | struct wpa_bss *tmp = bss; | 
|  | 5460 | for (;;) { | 
|  | 5461 | next = tmp->list_id.next; | 
|  | 5462 | if (next == &wpa_s->bss_id) | 
|  | 5463 | break; | 
|  | 5464 | tmp = dl_list_entry( | 
|  | 5465 | next, struct wpa_bss, | 
|  | 5466 | list_id); | 
|  | 5467 | if (tmp->id > id2) | 
|  | 5468 | break; | 
|  | 5469 | bsslast = tmp; | 
|  | 5470 | } | 
|  | 5471 | } | 
|  | 5472 | } | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5473 | } | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5474 | } else if (os_strncmp(cmd, "FIRST", 5) == 0) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5475 | 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] | 5476 | else if (os_strncmp(cmd, "LAST", 4) == 0) | 
|  | 5477 | 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] | 5478 | else if (os_strncmp(cmd, "ID-", 3) == 0) { | 
|  | 5479 | i = atoi(cmd + 3); | 
|  | 5480 | bss = wpa_bss_get_id(wpa_s, i); | 
|  | 5481 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | 
|  | 5482 | i = atoi(cmd + 5); | 
|  | 5483 | bss = wpa_bss_get_id(wpa_s, i); | 
|  | 5484 | if (bss) { | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5485 | next = bss->list_id.next; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5486 | if (next == &wpa_s->bss_id) | 
|  | 5487 | bss = NULL; | 
|  | 5488 | else | 
|  | 5489 | bss = dl_list_entry(next, struct wpa_bss, | 
|  | 5490 | list_id); | 
|  | 5491 | } | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5492 | } else if (os_strncmp(cmd, "CURRENT", 7) == 0) { | 
|  | 5493 | bss = wpa_s->current_bss; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5494 | #ifdef CONFIG_P2P | 
|  | 5495 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { | 
|  | 5496 | if (hwaddr_aton(cmd + 13, bssid) == 0) | 
|  | 5497 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid); | 
|  | 5498 | else | 
|  | 5499 | bss = NULL; | 
|  | 5500 | #endif /* CONFIG_P2P */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5501 | } else if (hwaddr_aton(cmd, bssid) == 0) | 
|  | 5502 | bss = wpa_bss_get_bssid(wpa_s, bssid); | 
|  | 5503 | else { | 
|  | 5504 | struct wpa_bss *tmp; | 
|  | 5505 | i = atoi(cmd); | 
|  | 5506 | bss = NULL; | 
|  | 5507 | dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id) | 
|  | 5508 | { | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5509 | if (i == 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5510 | bss = tmp; | 
|  | 5511 | break; | 
|  | 5512 | } | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5513 | i--; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5514 | } | 
|  | 5515 | } | 
|  | 5516 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5517 | if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) { | 
|  | 5518 | mask = strtoul(ctmp + 5, NULL, 0x10); | 
|  | 5519 | if (mask == 0) | 
|  | 5520 | mask = WPA_BSS_MASK_ALL; | 
|  | 5521 | } | 
|  | 5522 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5523 | if (bss == NULL) | 
|  | 5524 | return 0; | 
|  | 5525 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5526 | if (bsslast == NULL) | 
|  | 5527 | bsslast = bss; | 
|  | 5528 | do { | 
|  | 5529 | len = print_bss_info(wpa_s, bss, mask, buf, buflen); | 
|  | 5530 | ret += len; | 
|  | 5531 | buf += len; | 
|  | 5532 | buflen -= len; | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5533 | if (bss == bsslast) { | 
|  | 5534 | if ((mask & WPA_BSS_MASK_DELIM) && len && | 
|  | 5535 | (bss == dl_list_last(&wpa_s->bss_id, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5536 | struct wpa_bss, list_id))) { | 
|  | 5537 | int res; | 
|  | 5538 |  | 
|  | 5539 | res = os_snprintf(buf - 5, end - buf + 5, | 
|  | 5540 | "####\n"); | 
|  | 5541 | if (os_snprintf_error(end - buf + 5, res)) { | 
|  | 5542 | wpa_printf(MSG_DEBUG, | 
|  | 5543 | "Could not add end delim"); | 
|  | 5544 | } | 
|  | 5545 | } | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5546 | break; | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5547 | } | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5548 | next = bss->list_id.next; | 
|  | 5549 | if (next == &wpa_s->bss_id) | 
|  | 5550 | break; | 
|  | 5551 | bss = dl_list_entry(next, struct wpa_bss, list_id); | 
|  | 5552 | } while (bss && len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5553 |  | 
| Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 5554 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5555 | } | 
|  | 5556 |  | 
|  | 5557 |  | 
|  | 5558 | static int wpa_supplicant_ctrl_iface_ap_scan( | 
|  | 5559 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 5560 | { | 
|  | 5561 | int ap_scan = atoi(cmd); | 
|  | 5562 | return wpa_supplicant_set_ap_scan(wpa_s, ap_scan); | 
|  | 5563 | } | 
|  | 5564 |  | 
|  | 5565 |  | 
|  | 5566 | static int wpa_supplicant_ctrl_iface_scan_interval( | 
|  | 5567 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 5568 | { | 
|  | 5569 | int scan_int = atoi(cmd); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5570 | return wpa_supplicant_set_scan_interval(wpa_s, scan_int); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5571 | } | 
|  | 5572 |  | 
|  | 5573 |  | 
|  | 5574 | static int wpa_supplicant_ctrl_iface_bss_expire_age( | 
|  | 5575 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 5576 | { | 
|  | 5577 | int expire_age = atoi(cmd); | 
|  | 5578 | return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age); | 
|  | 5579 | } | 
|  | 5580 |  | 
|  | 5581 |  | 
|  | 5582 | static int wpa_supplicant_ctrl_iface_bss_expire_count( | 
|  | 5583 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 5584 | { | 
|  | 5585 | int expire_count = atoi(cmd); | 
|  | 5586 | return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count); | 
|  | 5587 | } | 
|  | 5588 |  | 
|  | 5589 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5590 | static void wpa_supplicant_ctrl_iface_bss_flush( | 
| Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 5591 | struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 5592 | { | 
|  | 5593 | int flush_age = atoi(cmd); | 
|  | 5594 |  | 
|  | 5595 | if (flush_age == 0) | 
|  | 5596 | wpa_bss_flush(wpa_s); | 
|  | 5597 | else | 
|  | 5598 | wpa_bss_flush_by_age(wpa_s, flush_age); | 
| Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 5599 | } | 
|  | 5600 |  | 
|  | 5601 |  | 
| Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 5602 | #ifdef CONFIG_TESTING_OPTIONS | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5603 | static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s) | 
|  | 5604 | { | 
|  | 5605 | wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication"); | 
|  | 5606 | /* MLME-DELETEKEYS.request */ | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5607 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, | 
|  | 5608 | 0, KEY_FLAG_GROUP); | 
|  | 5609 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, | 
|  | 5610 | 0, KEY_FLAG_GROUP); | 
|  | 5611 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, | 
|  | 5612 | 0, KEY_FLAG_GROUP); | 
|  | 5613 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, | 
|  | 5614 | 0, KEY_FLAG_GROUP); | 
|  | 5615 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, | 
|  | 5616 | 0, KEY_FLAG_GROUP); | 
|  | 5617 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, | 
|  | 5618 | 0, KEY_FLAG_GROUP); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5619 |  | 
|  | 5620 | 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] | 5621 | 0, KEY_FLAG_PAIRWISE); | 
|  | 5622 | if (wpa_sm_ext_key_id(wpa_s->wpa)) | 
|  | 5623 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 1, 0, | 
|  | 5624 | NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5625 | /* MLME-SETPROTECTION.request(None) */ | 
|  | 5626 | wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid, | 
|  | 5627 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, | 
|  | 5628 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); | 
|  | 5629 | wpa_sm_drop_sa(wpa_s->wpa); | 
|  | 5630 | } | 
| Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 5631 | #endif /* CONFIG_TESTING_OPTIONS */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5632 |  | 
|  | 5633 |  | 
|  | 5634 | static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s, | 
|  | 5635 | char *addr) | 
|  | 5636 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5637 | #ifdef CONFIG_NO_SCAN_PROCESSING | 
|  | 5638 | return -1; | 
|  | 5639 | #else /* CONFIG_NO_SCAN_PROCESSING */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5640 | u8 bssid[ETH_ALEN]; | 
|  | 5641 | struct wpa_bss *bss; | 
|  | 5642 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5643 | struct wpa_radio_work *already_connecting; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5644 |  | 
|  | 5645 | if (hwaddr_aton(addr, bssid)) { | 
|  | 5646 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid " | 
|  | 5647 | "address '%s'", addr); | 
|  | 5648 | return -1; | 
|  | 5649 | } | 
|  | 5650 |  | 
|  | 5651 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid)); | 
|  | 5652 |  | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5653 | if (!ssid) { | 
|  | 5654 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network " | 
|  | 5655 | "configuration known for the target AP"); | 
|  | 5656 | return -1; | 
|  | 5657 | } | 
|  | 5658 |  | 
|  | 5659 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5660 | if (!bss) { | 
|  | 5661 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found " | 
|  | 5662 | "from BSS table"); | 
|  | 5663 | return -1; | 
|  | 5664 | } | 
|  | 5665 |  | 
|  | 5666 | /* | 
|  | 5667 | * TODO: Find best network configuration block from configuration to | 
|  | 5668 | * allow roaming to other networks | 
|  | 5669 | */ | 
|  | 5670 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5671 | already_connecting = radio_work_pending(wpa_s, "sme-connect"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5672 | wpa_s->reassociate = 1; | 
|  | 5673 | wpa_supplicant_connect(wpa_s, bss, ssid); | 
|  | 5674 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5675 | /* | 
|  | 5676 | * Indicate that an explicitly requested roam is in progress so scan | 
|  | 5677 | * results that come in before the 'sme-connect' radio work gets | 
|  | 5678 | * executed do not override the original connection attempt. | 
|  | 5679 | */ | 
|  | 5680 | if (!already_connecting && radio_work_pending(wpa_s, "sme-connect")) | 
|  | 5681 | wpa_s->roam_in_progress = true; | 
|  | 5682 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5683 | return 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5684 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5685 | } | 
|  | 5686 |  | 
|  | 5687 |  | 
|  | 5688 | #ifdef CONFIG_P2P | 
|  | 5689 | static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 5690 | { | 
|  | 5691 | unsigned int timeout = atoi(cmd); | 
|  | 5692 | enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5693 | u8 dev_id[ETH_ALEN], *_dev_id = NULL; | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5694 | u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5695 | char *pos; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5696 | unsigned int search_delay; | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5697 | const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5698 | u8 seek_count = 0; | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5699 | int freq = 0; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5700 | bool include_6ghz = false; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5701 |  | 
| Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 5702 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { | 
|  | 5703 | wpa_dbg(wpa_s, MSG_INFO, | 
|  | 5704 | "Reject P2P_FIND since interface is disabled"); | 
|  | 5705 | return -1; | 
|  | 5706 | } | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5707 |  | 
|  | 5708 | if (os_strstr(cmd, " include_6ghz")) | 
|  | 5709 | include_6ghz = true; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5710 | if (os_strstr(cmd, "type=social")) | 
|  | 5711 | type = P2P_FIND_ONLY_SOCIAL; | 
|  | 5712 | else if (os_strstr(cmd, "type=progressive")) | 
|  | 5713 | type = P2P_FIND_PROGRESSIVE; | 
|  | 5714 |  | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5715 | pos = os_strstr(cmd, "dev_id="); | 
|  | 5716 | if (pos) { | 
|  | 5717 | pos += 7; | 
|  | 5718 | if (hwaddr_aton(pos, dev_id)) | 
|  | 5719 | return -1; | 
|  | 5720 | _dev_id = dev_id; | 
|  | 5721 | } | 
|  | 5722 |  | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5723 | pos = os_strstr(cmd, "dev_type="); | 
|  | 5724 | if (pos) { | 
|  | 5725 | pos += 9; | 
|  | 5726 | if (wps_dev_type_str2bin(pos, dev_type) < 0) | 
|  | 5727 | return -1; | 
|  | 5728 | _dev_type = dev_type; | 
|  | 5729 | } | 
|  | 5730 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5731 | pos = os_strstr(cmd, "delay="); | 
|  | 5732 | if (pos) { | 
|  | 5733 | pos += 6; | 
|  | 5734 | search_delay = atoi(pos); | 
|  | 5735 | } else | 
|  | 5736 | search_delay = wpas_p2p_search_delay(wpa_s); | 
|  | 5737 |  | 
| Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 5738 | pos = os_strstr(cmd, "freq="); | 
|  | 5739 | if (pos) { | 
|  | 5740 | pos += 5; | 
|  | 5741 | freq = atoi(pos); | 
|  | 5742 | if (freq <= 0) | 
|  | 5743 | return -1; | 
|  | 5744 | } | 
|  | 5745 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5746 | /* Must be searched for last, because it adds nul termination */ | 
|  | 5747 | pos = os_strstr(cmd, " seek="); | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5748 | if (pos) | 
|  | 5749 | pos += 6; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5750 | while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) { | 
|  | 5751 | char *term; | 
|  | 5752 |  | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5753 | _seek[seek_count++] = pos; | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5754 | seek = _seek; | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5755 | term = os_strchr(pos, ' '); | 
|  | 5756 | if (!term) | 
|  | 5757 | break; | 
|  | 5758 | *term = '\0'; | 
|  | 5759 | pos = os_strstr(term + 1, "seek="); | 
|  | 5760 | if (pos) | 
|  | 5761 | pos += 5; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5762 | } | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5763 | if (seek_count > P2P_MAX_QUERY_HASH) { | 
|  | 5764 | seek[0] = NULL; | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5765 | seek_count = 1; | 
|  | 5766 | } | 
|  | 5767 |  | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5768 | 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] | 5769 | _dev_id, search_delay, seek_count, seek, freq, | 
|  | 5770 | include_6ghz); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5771 | } | 
|  | 5772 |  | 
|  | 5773 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5774 | static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt) | 
|  | 5775 | { | 
|  | 5776 | const char *last = NULL; | 
|  | 5777 | const char *token; | 
|  | 5778 | long int token_len; | 
|  | 5779 | unsigned int i; | 
|  | 5780 |  | 
|  | 5781 | /* Expected predefined CPT names delimited by ':' */ | 
|  | 5782 | for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) { | 
|  | 5783 | if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) { | 
|  | 5784 | wpa_printf(MSG_ERROR, | 
|  | 5785 | "P2PS: CPT name list is too long, expected up to %d names", | 
|  | 5786 | P2PS_FEATURE_CAPAB_CPT_MAX); | 
|  | 5787 | cpt[0] = 0; | 
|  | 5788 | return -1; | 
|  | 5789 | } | 
|  | 5790 |  | 
|  | 5791 | token_len = last - token; | 
|  | 5792 |  | 
|  | 5793 | if (token_len  == 3 && | 
|  | 5794 | os_memcmp(token, "UDP", token_len) == 0) { | 
|  | 5795 | cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; | 
|  | 5796 | } else if (token_len == 3 && | 
|  | 5797 | os_memcmp(token, "MAC", token_len) == 0) { | 
|  | 5798 | cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT; | 
|  | 5799 | } else { | 
|  | 5800 | wpa_printf(MSG_ERROR, | 
|  | 5801 | "P2PS: Unsupported CPT name '%s'", token); | 
|  | 5802 | cpt[0] = 0; | 
|  | 5803 | return -1; | 
|  | 5804 | } | 
|  | 5805 |  | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5806 | if (isblank((unsigned char) *last)) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5807 | i++; | 
|  | 5808 | break; | 
|  | 5809 | } | 
|  | 5810 | } | 
|  | 5811 | cpt[i] = 0; | 
|  | 5812 | return 0; | 
|  | 5813 | } | 
|  | 5814 |  | 
|  | 5815 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5816 | static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd) | 
|  | 5817 | { | 
|  | 5818 | struct p2ps_provision *p2ps_prov; | 
|  | 5819 | char *pos; | 
|  | 5820 | size_t info_len = 0; | 
|  | 5821 | char *info = NULL; | 
|  | 5822 | u8 role = P2PS_SETUP_NONE; | 
|  | 5823 | long long unsigned val; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5824 | int i; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5825 |  | 
|  | 5826 | pos = os_strstr(cmd, "info="); | 
|  | 5827 | if (pos) { | 
|  | 5828 | pos += 5; | 
|  | 5829 | info_len = os_strlen(pos); | 
|  | 5830 |  | 
|  | 5831 | if (info_len) { | 
|  | 5832 | info = os_malloc(info_len + 1); | 
|  | 5833 | if (info) { | 
|  | 5834 | info_len = utf8_unescape(pos, info_len, | 
|  | 5835 | info, info_len + 1); | 
|  | 5836 | } else | 
|  | 5837 | info_len = 0; | 
|  | 5838 | } | 
|  | 5839 | } | 
|  | 5840 |  | 
|  | 5841 | p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1); | 
|  | 5842 | if (p2ps_prov == NULL) { | 
|  | 5843 | os_free(info); | 
|  | 5844 | return NULL; | 
|  | 5845 | } | 
|  | 5846 |  | 
|  | 5847 | if (info) { | 
|  | 5848 | os_memcpy(p2ps_prov->info, info, info_len); | 
|  | 5849 | p2ps_prov->info[info_len] = '\0'; | 
|  | 5850 | os_free(info); | 
|  | 5851 | } | 
|  | 5852 |  | 
|  | 5853 | pos = os_strstr(cmd, "status="); | 
|  | 5854 | if (pos) | 
|  | 5855 | p2ps_prov->status = atoi(pos + 7); | 
|  | 5856 | else | 
|  | 5857 | p2ps_prov->status = -1; | 
|  | 5858 |  | 
|  | 5859 | pos = os_strstr(cmd, "adv_id="); | 
|  | 5860 | if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL) | 
|  | 5861 | goto invalid_args; | 
|  | 5862 | p2ps_prov->adv_id = val; | 
|  | 5863 |  | 
|  | 5864 | pos = os_strstr(cmd, "method="); | 
|  | 5865 | if (pos) | 
|  | 5866 | p2ps_prov->method = strtol(pos + 7, NULL, 16); | 
|  | 5867 | else | 
|  | 5868 | p2ps_prov->method = 0; | 
|  | 5869 |  | 
|  | 5870 | pos = os_strstr(cmd, "session="); | 
|  | 5871 | if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL) | 
|  | 5872 | goto invalid_args; | 
|  | 5873 | p2ps_prov->session_id = val; | 
|  | 5874 |  | 
|  | 5875 | pos = os_strstr(cmd, "adv_mac="); | 
|  | 5876 | if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac)) | 
|  | 5877 | goto invalid_args; | 
|  | 5878 |  | 
|  | 5879 | pos = os_strstr(cmd, "session_mac="); | 
|  | 5880 | if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac)) | 
|  | 5881 | goto invalid_args; | 
|  | 5882 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5883 | pos = os_strstr(cmd, "cpt="); | 
|  | 5884 | if (pos) { | 
|  | 5885 | if (p2ps_ctrl_parse_cpt_priority(pos + 4, | 
|  | 5886 | p2ps_prov->cpt_priority)) | 
|  | 5887 | goto invalid_args; | 
|  | 5888 | } else { | 
|  | 5889 | p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; | 
|  | 5890 | } | 
|  | 5891 |  | 
|  | 5892 | for (i = 0; p2ps_prov->cpt_priority[i]; i++) | 
|  | 5893 | p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i]; | 
|  | 5894 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5895 | /* force conncap with tstCap (no validity checks) */ | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5896 | pos = os_strstr(cmd, "tstCap="); | 
|  | 5897 | if (pos) { | 
|  | 5898 | role = strtol(pos + 7, NULL, 16); | 
|  | 5899 | } else { | 
|  | 5900 | pos = os_strstr(cmd, "role="); | 
|  | 5901 | if (pos) { | 
|  | 5902 | role = strtol(pos + 5, NULL, 16); | 
|  | 5903 | if (role != P2PS_SETUP_CLIENT && | 
|  | 5904 | role != P2PS_SETUP_GROUP_OWNER) | 
|  | 5905 | role = P2PS_SETUP_NONE; | 
|  | 5906 | } | 
|  | 5907 | } | 
|  | 5908 | p2ps_prov->role = role; | 
|  | 5909 |  | 
|  | 5910 | return p2ps_prov; | 
|  | 5911 |  | 
|  | 5912 | invalid_args: | 
|  | 5913 | os_free(p2ps_prov); | 
|  | 5914 | return NULL; | 
|  | 5915 | } | 
|  | 5916 |  | 
|  | 5917 |  | 
|  | 5918 | static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 5919 | { | 
|  | 5920 | u8 addr[ETH_ALEN]; | 
|  | 5921 | struct p2ps_provision *p2ps_prov; | 
|  | 5922 | char *pos; | 
|  | 5923 |  | 
|  | 5924 | /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */ | 
|  | 5925 |  | 
|  | 5926 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); | 
|  | 5927 |  | 
|  | 5928 | if (hwaddr_aton(cmd, addr)) | 
|  | 5929 | return -1; | 
|  | 5930 |  | 
|  | 5931 | pos = cmd + 17; | 
|  | 5932 | if (*pos != ' ') | 
|  | 5933 | return -1; | 
|  | 5934 |  | 
|  | 5935 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); | 
|  | 5936 | if (!p2ps_prov) | 
|  | 5937 | return -1; | 
|  | 5938 |  | 
|  | 5939 | if (p2ps_prov->status < 0) { | 
|  | 5940 | os_free(p2ps_prov); | 
|  | 5941 | return -1; | 
|  | 5942 | } | 
|  | 5943 |  | 
|  | 5944 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, | 
|  | 5945 | p2ps_prov); | 
|  | 5946 | } | 
|  | 5947 |  | 
|  | 5948 |  | 
|  | 5949 | static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 5950 | { | 
|  | 5951 | u8 addr[ETH_ALEN]; | 
|  | 5952 | struct p2ps_provision *p2ps_prov; | 
|  | 5953 | char *pos; | 
|  | 5954 |  | 
|  | 5955 | /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap> | 
|  | 5956 | *        session=<ses_id> mac=<ses_mac> [info=<infodata>] | 
|  | 5957 | */ | 
|  | 5958 |  | 
|  | 5959 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); | 
|  | 5960 | if (hwaddr_aton(cmd, addr)) | 
|  | 5961 | return -1; | 
|  | 5962 |  | 
|  | 5963 | pos = cmd + 17; | 
|  | 5964 | if (*pos != ' ') | 
|  | 5965 | return -1; | 
|  | 5966 |  | 
|  | 5967 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); | 
|  | 5968 | if (!p2ps_prov) | 
|  | 5969 | return -1; | 
|  | 5970 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5971 | p2ps_prov->pd_seeker = 1; | 
|  | 5972 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5973 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, | 
|  | 5974 | p2ps_prov); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5975 | } | 
|  | 5976 |  | 
|  | 5977 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5978 | static int parse_freq(int chwidth, int freq2) | 
|  | 5979 | { | 
|  | 5980 | if (freq2 < 0) | 
|  | 5981 | return -1; | 
|  | 5982 | if (freq2) | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5983 | return CONF_OPER_CHWIDTH_80P80MHZ; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5984 |  | 
|  | 5985 | switch (chwidth) { | 
|  | 5986 | case 0: | 
|  | 5987 | case 20: | 
|  | 5988 | case 40: | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5989 | return CONF_OPER_CHWIDTH_USE_HT; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5990 | case 80: | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5991 | return CONF_OPER_CHWIDTH_80MHZ; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5992 | case 160: | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5993 | return CONF_OPER_CHWIDTH_160MHZ; | 
|  | 5994 | case 320: | 
|  | 5995 | return CONF_OPER_CHWIDTH_320MHZ; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5996 | default: | 
|  | 5997 | wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d", | 
|  | 5998 | chwidth); | 
|  | 5999 | return -1; | 
|  | 6000 | } | 
|  | 6001 | } | 
|  | 6002 |  | 
|  | 6003 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6004 | static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 6005 | char *buf, size_t buflen) | 
|  | 6006 | { | 
|  | 6007 | u8 addr[ETH_ALEN]; | 
|  | 6008 | char *pos, *pos2; | 
|  | 6009 | char *pin = NULL; | 
|  | 6010 | enum p2p_wps_method wps_method; | 
|  | 6011 | int new_pin; | 
|  | 6012 | int ret; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6013 | int persistent_group, persistent_id = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6014 | int join; | 
|  | 6015 | int auth; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6016 | int automatic; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6017 | int go_intent = -1; | 
|  | 6018 | int freq = 0; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6019 | int pd; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6020 | int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6021 | int edmg; | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6022 | u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL; | 
|  | 6023 | size_t group_ssid_len = 0; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6024 | int he; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6025 | bool allow_6ghz; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6026 |  | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6027 | if (!wpa_s->global->p2p_init_wpa_s) | 
|  | 6028 | return -1; | 
|  | 6029 | if (wpa_s->global->p2p_init_wpa_s != wpa_s) { | 
|  | 6030 | wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s", | 
|  | 6031 | wpa_s->global->p2p_init_wpa_s->ifname); | 
|  | 6032 | wpa_s = wpa_s->global->p2p_init_wpa_s; | 
|  | 6033 | } | 
|  | 6034 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6035 | /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps] | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6036 | * [persistent|persistent=<network id>] | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6037 | * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6038 | * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6039 |  | 
|  | 6040 | if (hwaddr_aton(cmd, addr)) | 
|  | 6041 | return -1; | 
|  | 6042 |  | 
|  | 6043 | pos = cmd + 17; | 
|  | 6044 | if (*pos != ' ') | 
|  | 6045 | return -1; | 
|  | 6046 | pos++; | 
|  | 6047 |  | 
|  | 6048 | persistent_group = os_strstr(pos, " persistent") != NULL; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6049 | pos2 = os_strstr(pos, " persistent="); | 
|  | 6050 | if (pos2) { | 
|  | 6051 | struct wpa_ssid *ssid; | 
|  | 6052 | persistent_id = atoi(pos2 + 12); | 
|  | 6053 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); | 
|  | 6054 | if (ssid == NULL || ssid->disabled != 2 || | 
|  | 6055 | ssid->mode != WPAS_MODE_P2P_GO) { | 
|  | 6056 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " | 
|  | 6057 | "SSID id=%d for persistent P2P group (GO)", | 
|  | 6058 | persistent_id); | 
|  | 6059 | return -1; | 
|  | 6060 | } | 
|  | 6061 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6062 | join = os_strstr(pos, " join") != NULL; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6063 | allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6064 | auth = os_strstr(pos, " auth") != NULL; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6065 | automatic = os_strstr(pos, " auto") != NULL; | 
|  | 6066 | pd = os_strstr(pos, " provdisc") != NULL; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6067 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; | 
|  | 6068 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | 
|  | 6069 | vht; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6070 | he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6071 | edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6072 |  | 
|  | 6073 | pos2 = os_strstr(pos, " go_intent="); | 
|  | 6074 | if (pos2) { | 
|  | 6075 | pos2 += 11; | 
|  | 6076 | go_intent = atoi(pos2); | 
|  | 6077 | if (go_intent < 0 || go_intent > 15) | 
|  | 6078 | return -1; | 
|  | 6079 | } | 
|  | 6080 |  | 
|  | 6081 | pos2 = os_strstr(pos, " freq="); | 
|  | 6082 | if (pos2) { | 
|  | 6083 | pos2 += 6; | 
|  | 6084 | freq = atoi(pos2); | 
|  | 6085 | if (freq <= 0) | 
|  | 6086 | return -1; | 
|  | 6087 | } | 
|  | 6088 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6089 | pos2 = os_strstr(pos, " freq2="); | 
|  | 6090 | if (pos2) | 
|  | 6091 | freq2 = atoi(pos2 + 7); | 
|  | 6092 |  | 
|  | 6093 | pos2 = os_strstr(pos, " max_oper_chwidth="); | 
|  | 6094 | if (pos2) | 
|  | 6095 | chwidth = atoi(pos2 + 18); | 
|  | 6096 |  | 
|  | 6097 | max_oper_chwidth = parse_freq(chwidth, freq2); | 
|  | 6098 | if (max_oper_chwidth < 0) | 
|  | 6099 | return -1; | 
|  | 6100 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6101 | if (allow_6ghz && chwidth == 40) | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6102 | max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6103 |  | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6104 | pos2 = os_strstr(pos, " ssid="); | 
|  | 6105 | if (pos2) { | 
|  | 6106 | char *end; | 
|  | 6107 |  | 
|  | 6108 | pos2 += 6; | 
|  | 6109 | end = os_strchr(pos2, ' '); | 
|  | 6110 | if (!end) | 
|  | 6111 | group_ssid_len = os_strlen(pos2) / 2; | 
|  | 6112 | else | 
|  | 6113 | group_ssid_len = (end - pos2) / 2; | 
|  | 6114 | if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN || | 
|  | 6115 | hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0) | 
|  | 6116 | return -1; | 
|  | 6117 | group_ssid = _group_ssid; | 
|  | 6118 | } | 
|  | 6119 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6120 | if (os_strncmp(pos, "pin", 3) == 0) { | 
|  | 6121 | /* Request random PIN (to be displayed) and enable the PIN */ | 
|  | 6122 | wps_method = WPS_PIN_DISPLAY; | 
|  | 6123 | } else if (os_strncmp(pos, "pbc", 3) == 0) { | 
|  | 6124 | wps_method = WPS_PBC; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6125 | } else if (os_strstr(pos, "p2ps") != NULL) { | 
|  | 6126 | wps_method = WPS_P2PS; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6127 | } else { | 
|  | 6128 | pin = pos; | 
|  | 6129 | pos = os_strchr(pin, ' '); | 
|  | 6130 | wps_method = WPS_PIN_KEYPAD; | 
|  | 6131 | if (pos) { | 
|  | 6132 | *pos++ = '\0'; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6133 | if (os_strncmp(pos, "display", 7) == 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6134 | wps_method = WPS_PIN_DISPLAY; | 
|  | 6135 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6136 | if (!wps_pin_str_valid(pin)) { | 
|  | 6137 | os_memcpy(buf, "FAIL-INVALID-PIN\n", 17); | 
|  | 6138 | return 17; | 
|  | 6139 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6140 | } | 
|  | 6141 |  | 
|  | 6142 | new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6143 | persistent_group, automatic, join, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6144 | auth, go_intent, freq, freq2, persistent_id, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6145 | pd, ht40, vht, max_oper_chwidth, he, edmg, | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6146 | group_ssid, group_ssid_len, allow_6ghz); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6147 | if (new_pin == -2) { | 
|  | 6148 | os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25); | 
|  | 6149 | return 25; | 
|  | 6150 | } | 
|  | 6151 | if (new_pin == -3) { | 
|  | 6152 | os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25); | 
|  | 6153 | return 25; | 
|  | 6154 | } | 
|  | 6155 | if (new_pin < 0) | 
|  | 6156 | return -1; | 
|  | 6157 | if (wps_method == WPS_PIN_DISPLAY && pin == NULL) { | 
|  | 6158 | ret = os_snprintf(buf, buflen, "%08d", new_pin); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6159 | if (os_snprintf_error(buflen, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6160 | return -1; | 
|  | 6161 | return ret; | 
|  | 6162 | } | 
|  | 6163 |  | 
|  | 6164 | os_memcpy(buf, "OK\n", 3); | 
|  | 6165 | return 3; | 
|  | 6166 | } | 
|  | 6167 |  | 
|  | 6168 |  | 
|  | 6169 | static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6170 | { | 
|  | 6171 | unsigned int timeout = atoi(cmd); | 
| Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 6172 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { | 
|  | 6173 | wpa_dbg(wpa_s, MSG_INFO, | 
|  | 6174 | "Reject P2P_LISTEN since interface is disabled"); | 
|  | 6175 | return -1; | 
|  | 6176 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6177 | return wpas_p2p_listen(wpa_s, timeout); | 
|  | 6178 | } | 
|  | 6179 |  | 
|  | 6180 |  | 
|  | 6181 | static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6182 | { | 
|  | 6183 | u8 addr[ETH_ALEN]; | 
|  | 6184 | char *pos; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6185 | 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] | 6186 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6187 | /* <addr> <config method> [join|auto] */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6188 |  | 
|  | 6189 | if (hwaddr_aton(cmd, addr)) | 
|  | 6190 | return -1; | 
|  | 6191 |  | 
|  | 6192 | pos = cmd + 17; | 
|  | 6193 | if (*pos != ' ') | 
|  | 6194 | return -1; | 
|  | 6195 | pos++; | 
|  | 6196 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6197 | if (os_strstr(pos, " join") != NULL) | 
|  | 6198 | use = WPAS_P2P_PD_FOR_JOIN; | 
|  | 6199 | else if (os_strstr(pos, " auto") != NULL) | 
|  | 6200 | use = WPAS_P2P_PD_AUTO; | 
|  | 6201 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6202 | return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6203 | } | 
|  | 6204 |  | 
|  | 6205 |  | 
|  | 6206 | static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf, | 
|  | 6207 | size_t buflen) | 
|  | 6208 | { | 
|  | 6209 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
|  | 6210 |  | 
|  | 6211 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || | 
|  | 6212 | ssid->passphrase == NULL) | 
|  | 6213 | return -1; | 
|  | 6214 |  | 
|  | 6215 | os_strlcpy(buf, ssid->passphrase, buflen); | 
|  | 6216 | return os_strlen(buf); | 
|  | 6217 | } | 
|  | 6218 |  | 
|  | 6219 |  | 
|  | 6220 | static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 6221 | char *buf, size_t buflen) | 
|  | 6222 | { | 
|  | 6223 | u64 ref; | 
|  | 6224 | int res; | 
|  | 6225 | u8 dst_buf[ETH_ALEN], *dst; | 
|  | 6226 | struct wpabuf *tlvs; | 
|  | 6227 | char *pos; | 
|  | 6228 | size_t len; | 
|  | 6229 |  | 
|  | 6230 | if (hwaddr_aton(cmd, dst_buf)) | 
|  | 6231 | return -1; | 
|  | 6232 | dst = dst_buf; | 
|  | 6233 | if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 && | 
|  | 6234 | dst[3] == 0 && dst[4] == 0 && dst[5] == 0) | 
|  | 6235 | dst = NULL; | 
|  | 6236 | pos = cmd + 17; | 
|  | 6237 | if (*pos != ' ') | 
|  | 6238 | return -1; | 
|  | 6239 | pos++; | 
|  | 6240 |  | 
|  | 6241 | if (os_strncmp(pos, "upnp ", 5) == 0) { | 
|  | 6242 | u8 version; | 
|  | 6243 | pos += 5; | 
|  | 6244 | if (hexstr2bin(pos, &version, 1) < 0) | 
|  | 6245 | return -1; | 
|  | 6246 | pos += 2; | 
|  | 6247 | if (*pos != ' ') | 
|  | 6248 | return -1; | 
|  | 6249 | pos++; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6250 | ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6251 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 6252 | } else if (os_strncmp(pos, "wifi-display ", 13) == 0) { | 
|  | 6253 | ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13); | 
|  | 6254 | #endif /* CONFIG_WIFI_DISPLAY */ | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6255 | } else if (os_strncmp(pos, "asp ", 4) == 0) { | 
|  | 6256 | char *svc_str; | 
|  | 6257 | char *svc_info = NULL; | 
|  | 6258 | u32 id; | 
|  | 6259 |  | 
|  | 6260 | pos += 4; | 
|  | 6261 | if (sscanf(pos, "%x", &id) != 1 || id > 0xff) | 
|  | 6262 | return -1; | 
|  | 6263 |  | 
|  | 6264 | pos = os_strchr(pos, ' '); | 
|  | 6265 | if (pos == NULL || pos[1] == '\0' || pos[1] == ' ') | 
|  | 6266 | return -1; | 
|  | 6267 |  | 
|  | 6268 | svc_str = pos + 1; | 
|  | 6269 |  | 
|  | 6270 | pos = os_strchr(svc_str, ' '); | 
|  | 6271 |  | 
|  | 6272 | if (pos) | 
|  | 6273 | *pos++ = '\0'; | 
|  | 6274 |  | 
|  | 6275 | /* All remaining data is the svc_info string */ | 
|  | 6276 | if (pos && pos[0] && pos[0] != ' ') { | 
|  | 6277 | len = os_strlen(pos); | 
|  | 6278 |  | 
|  | 6279 | /* Unescape in place */ | 
|  | 6280 | len = utf8_unescape(pos, len, pos, len); | 
|  | 6281 | if (len > 0xff) | 
|  | 6282 | return -1; | 
|  | 6283 |  | 
|  | 6284 | svc_info = pos; | 
|  | 6285 | } | 
|  | 6286 |  | 
|  | 6287 | ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id, | 
|  | 6288 | svc_str, svc_info); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6289 | } else { | 
|  | 6290 | len = os_strlen(pos); | 
|  | 6291 | if (len & 1) | 
|  | 6292 | return -1; | 
|  | 6293 | len /= 2; | 
|  | 6294 | tlvs = wpabuf_alloc(len); | 
|  | 6295 | if (tlvs == NULL) | 
|  | 6296 | return -1; | 
|  | 6297 | if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) { | 
|  | 6298 | wpabuf_free(tlvs); | 
|  | 6299 | return -1; | 
|  | 6300 | } | 
|  | 6301 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6302 | ref = wpas_p2p_sd_request(wpa_s, dst, tlvs); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6303 | wpabuf_free(tlvs); | 
|  | 6304 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6305 | if (ref == 0) | 
|  | 6306 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6307 | res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6308 | if (os_snprintf_error(buflen, res)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6309 | return -1; | 
|  | 6310 | return res; | 
|  | 6311 | } | 
|  | 6312 |  | 
|  | 6313 |  | 
|  | 6314 | static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s, | 
|  | 6315 | char *cmd) | 
|  | 6316 | { | 
|  | 6317 | long long unsigned val; | 
|  | 6318 | u64 req; | 
|  | 6319 | if (sscanf(cmd, "%llx", &val) != 1) | 
|  | 6320 | return -1; | 
|  | 6321 | req = val; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6322 | return wpas_p2p_sd_cancel_request(wpa_s, req); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6323 | } | 
|  | 6324 |  | 
|  | 6325 |  | 
|  | 6326 | static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6327 | { | 
|  | 6328 | int freq; | 
|  | 6329 | u8 dst[ETH_ALEN]; | 
|  | 6330 | u8 dialog_token; | 
|  | 6331 | struct wpabuf *resp_tlvs; | 
|  | 6332 | char *pos, *pos2; | 
|  | 6333 | size_t len; | 
|  | 6334 |  | 
|  | 6335 | pos = os_strchr(cmd, ' '); | 
|  | 6336 | if (pos == NULL) | 
|  | 6337 | return -1; | 
|  | 6338 | *pos++ = '\0'; | 
|  | 6339 | freq = atoi(cmd); | 
|  | 6340 | if (freq == 0) | 
|  | 6341 | return -1; | 
|  | 6342 |  | 
|  | 6343 | if (hwaddr_aton(pos, dst)) | 
|  | 6344 | return -1; | 
|  | 6345 | pos += 17; | 
|  | 6346 | if (*pos != ' ') | 
|  | 6347 | return -1; | 
|  | 6348 | pos++; | 
|  | 6349 |  | 
|  | 6350 | pos2 = os_strchr(pos, ' '); | 
|  | 6351 | if (pos2 == NULL) | 
|  | 6352 | return -1; | 
|  | 6353 | *pos2++ = '\0'; | 
|  | 6354 | dialog_token = atoi(pos); | 
|  | 6355 |  | 
|  | 6356 | len = os_strlen(pos2); | 
|  | 6357 | if (len & 1) | 
|  | 6358 | return -1; | 
|  | 6359 | len /= 2; | 
|  | 6360 | resp_tlvs = wpabuf_alloc(len); | 
|  | 6361 | if (resp_tlvs == NULL) | 
|  | 6362 | return -1; | 
|  | 6363 | if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) { | 
|  | 6364 | wpabuf_free(resp_tlvs); | 
|  | 6365 | return -1; | 
|  | 6366 | } | 
|  | 6367 |  | 
|  | 6368 | wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs); | 
|  | 6369 | wpabuf_free(resp_tlvs); | 
|  | 6370 | return 0; | 
|  | 6371 | } | 
|  | 6372 |  | 
|  | 6373 |  | 
|  | 6374 | static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s, | 
|  | 6375 | char *cmd) | 
|  | 6376 | { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6377 | if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1")) | 
|  | 6378 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6379 | wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd); | 
|  | 6380 | return 0; | 
|  | 6381 | } | 
|  | 6382 |  | 
|  | 6383 |  | 
|  | 6384 | static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s, | 
|  | 6385 | char *cmd) | 
|  | 6386 | { | 
|  | 6387 | char *pos; | 
|  | 6388 | size_t len; | 
|  | 6389 | struct wpabuf *query, *resp; | 
|  | 6390 |  | 
|  | 6391 | pos = os_strchr(cmd, ' '); | 
|  | 6392 | if (pos == NULL) | 
|  | 6393 | return -1; | 
|  | 6394 | *pos++ = '\0'; | 
|  | 6395 |  | 
|  | 6396 | len = os_strlen(cmd); | 
|  | 6397 | if (len & 1) | 
|  | 6398 | return -1; | 
|  | 6399 | len /= 2; | 
|  | 6400 | query = wpabuf_alloc(len); | 
|  | 6401 | if (query == NULL) | 
|  | 6402 | return -1; | 
|  | 6403 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | 
|  | 6404 | wpabuf_free(query); | 
|  | 6405 | return -1; | 
|  | 6406 | } | 
|  | 6407 |  | 
|  | 6408 | len = os_strlen(pos); | 
|  | 6409 | if (len & 1) { | 
|  | 6410 | wpabuf_free(query); | 
|  | 6411 | return -1; | 
|  | 6412 | } | 
|  | 6413 | len /= 2; | 
|  | 6414 | resp = wpabuf_alloc(len); | 
|  | 6415 | if (resp == NULL) { | 
|  | 6416 | wpabuf_free(query); | 
|  | 6417 | return -1; | 
|  | 6418 | } | 
|  | 6419 | if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) { | 
|  | 6420 | wpabuf_free(query); | 
|  | 6421 | wpabuf_free(resp); | 
|  | 6422 | return -1; | 
|  | 6423 | } | 
|  | 6424 |  | 
|  | 6425 | if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) { | 
|  | 6426 | wpabuf_free(query); | 
|  | 6427 | wpabuf_free(resp); | 
|  | 6428 | return -1; | 
|  | 6429 | } | 
|  | 6430 | return 0; | 
|  | 6431 | } | 
|  | 6432 |  | 
|  | 6433 |  | 
|  | 6434 | static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6435 | { | 
|  | 6436 | char *pos; | 
|  | 6437 | u8 version; | 
|  | 6438 |  | 
|  | 6439 | pos = os_strchr(cmd, ' '); | 
|  | 6440 | if (pos == NULL) | 
|  | 6441 | return -1; | 
|  | 6442 | *pos++ = '\0'; | 
|  | 6443 |  | 
|  | 6444 | if (hexstr2bin(cmd, &version, 1) < 0) | 
|  | 6445 | return -1; | 
|  | 6446 |  | 
|  | 6447 | return wpas_p2p_service_add_upnp(wpa_s, version, pos); | 
|  | 6448 | } | 
|  | 6449 |  | 
|  | 6450 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6451 | static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s, | 
|  | 6452 | u8 replace, char *cmd) | 
|  | 6453 | { | 
|  | 6454 | char *pos; | 
|  | 6455 | char *adv_str; | 
|  | 6456 | u32 auto_accept, adv_id, svc_state, config_methods; | 
|  | 6457 | char *svc_info = NULL; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6458 | char *cpt_prio_str; | 
|  | 6459 | u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1]; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6460 |  | 
|  | 6461 | pos = os_strchr(cmd, ' '); | 
|  | 6462 | if (pos == NULL) | 
|  | 6463 | return -1; | 
|  | 6464 | *pos++ = '\0'; | 
|  | 6465 |  | 
|  | 6466 | /* Auto-Accept value is mandatory, and must be one of the | 
|  | 6467 | * single values (0, 1, 2, 4) */ | 
|  | 6468 | auto_accept = atoi(cmd); | 
|  | 6469 | switch (auto_accept) { | 
|  | 6470 | case P2PS_SETUP_NONE: /* No auto-accept */ | 
|  | 6471 | case P2PS_SETUP_NEW: | 
|  | 6472 | case P2PS_SETUP_CLIENT: | 
|  | 6473 | case P2PS_SETUP_GROUP_OWNER: | 
|  | 6474 | break; | 
|  | 6475 | default: | 
|  | 6476 | return -1; | 
|  | 6477 | } | 
|  | 6478 |  | 
|  | 6479 | /* Advertisement ID is mandatory */ | 
|  | 6480 | cmd = pos; | 
|  | 6481 | pos = os_strchr(cmd, ' '); | 
|  | 6482 | if (pos == NULL) | 
|  | 6483 | return -1; | 
|  | 6484 | *pos++ = '\0'; | 
|  | 6485 |  | 
|  | 6486 | /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */ | 
|  | 6487 | if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0) | 
|  | 6488 | return -1; | 
|  | 6489 |  | 
|  | 6490 | /* Only allow replacements if exist, and adds if not */ | 
|  | 6491 | if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) { | 
|  | 6492 | if (!replace) | 
|  | 6493 | return -1; | 
|  | 6494 | } else { | 
|  | 6495 | if (replace) | 
|  | 6496 | return -1; | 
|  | 6497 | } | 
|  | 6498 |  | 
|  | 6499 | /* svc_state between 0 - 0xff is mandatory */ | 
|  | 6500 | if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff) | 
|  | 6501 | return -1; | 
|  | 6502 |  | 
|  | 6503 | pos = os_strchr(pos, ' '); | 
|  | 6504 | if (pos == NULL) | 
|  | 6505 | return -1; | 
|  | 6506 |  | 
|  | 6507 | /* config_methods is mandatory */ | 
|  | 6508 | pos++; | 
|  | 6509 | if (sscanf(pos, "%x", &config_methods) != 1) | 
|  | 6510 | return -1; | 
|  | 6511 |  | 
|  | 6512 | if (!(config_methods & | 
|  | 6513 | (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS))) | 
|  | 6514 | return -1; | 
|  | 6515 |  | 
|  | 6516 | pos = os_strchr(pos, ' '); | 
|  | 6517 | if (pos == NULL) | 
|  | 6518 | return -1; | 
|  | 6519 |  | 
|  | 6520 | pos++; | 
|  | 6521 | adv_str = pos; | 
|  | 6522 |  | 
|  | 6523 | /* Advertisement string is mandatory */ | 
|  | 6524 | if (!pos[0] || pos[0] == ' ') | 
|  | 6525 | return -1; | 
|  | 6526 |  | 
|  | 6527 | /* Terminate svc string */ | 
|  | 6528 | pos = os_strchr(pos, ' '); | 
|  | 6529 | if (pos != NULL) | 
|  | 6530 | *pos++ = '\0'; | 
|  | 6531 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6532 | cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL; | 
|  | 6533 | if (cpt_prio_str) { | 
|  | 6534 | pos = os_strchr(pos, ' '); | 
|  | 6535 | if (pos != NULL) | 
|  | 6536 | *pos++ = '\0'; | 
|  | 6537 |  | 
|  | 6538 | if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio)) | 
|  | 6539 | return -1; | 
|  | 6540 | } else { | 
|  | 6541 | cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; | 
|  | 6542 | cpt_prio[1] = 0; | 
|  | 6543 | } | 
|  | 6544 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6545 | /* Service and Response Information are optional */ | 
|  | 6546 | if (pos && pos[0]) { | 
|  | 6547 | size_t len; | 
|  | 6548 |  | 
|  | 6549 | /* Note the bare ' included, which cannot exist legally | 
|  | 6550 | * in unescaped string. */ | 
|  | 6551 | svc_info = os_strstr(pos, "svc_info='"); | 
|  | 6552 |  | 
|  | 6553 | if (svc_info) { | 
|  | 6554 | svc_info += 9; | 
|  | 6555 | len = os_strlen(svc_info); | 
|  | 6556 | utf8_unescape(svc_info, len, svc_info, len); | 
|  | 6557 | } | 
|  | 6558 | } | 
|  | 6559 |  | 
|  | 6560 | return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str, | 
|  | 6561 | (u8) svc_state, (u16) config_methods, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6562 | svc_info, cpt_prio); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6563 | } | 
|  | 6564 |  | 
|  | 6565 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6566 | static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6567 | { | 
|  | 6568 | char *pos; | 
|  | 6569 |  | 
|  | 6570 | pos = os_strchr(cmd, ' '); | 
|  | 6571 | if (pos == NULL) | 
|  | 6572 | return -1; | 
|  | 6573 | *pos++ = '\0'; | 
|  | 6574 |  | 
|  | 6575 | if (os_strcmp(cmd, "bonjour") == 0) | 
|  | 6576 | return p2p_ctrl_service_add_bonjour(wpa_s, pos); | 
|  | 6577 | if (os_strcmp(cmd, "upnp") == 0) | 
|  | 6578 | return p2p_ctrl_service_add_upnp(wpa_s, pos); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6579 | if (os_strcmp(cmd, "asp") == 0) | 
|  | 6580 | return p2p_ctrl_service_add_asp(wpa_s, 0, pos); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6581 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | 
|  | 6582 | return -1; | 
|  | 6583 | } | 
|  | 6584 |  | 
|  | 6585 |  | 
|  | 6586 | static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s, | 
|  | 6587 | char *cmd) | 
|  | 6588 | { | 
|  | 6589 | size_t len; | 
|  | 6590 | struct wpabuf *query; | 
|  | 6591 | int ret; | 
|  | 6592 |  | 
|  | 6593 | len = os_strlen(cmd); | 
|  | 6594 | if (len & 1) | 
|  | 6595 | return -1; | 
|  | 6596 | len /= 2; | 
|  | 6597 | query = wpabuf_alloc(len); | 
|  | 6598 | if (query == NULL) | 
|  | 6599 | return -1; | 
|  | 6600 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { | 
|  | 6601 | wpabuf_free(query); | 
|  | 6602 | return -1; | 
|  | 6603 | } | 
|  | 6604 |  | 
|  | 6605 | ret = wpas_p2p_service_del_bonjour(wpa_s, query); | 
|  | 6606 | wpabuf_free(query); | 
|  | 6607 | return ret; | 
|  | 6608 | } | 
|  | 6609 |  | 
|  | 6610 |  | 
|  | 6611 | static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6612 | { | 
|  | 6613 | char *pos; | 
|  | 6614 | u8 version; | 
|  | 6615 |  | 
|  | 6616 | pos = os_strchr(cmd, ' '); | 
|  | 6617 | if (pos == NULL) | 
|  | 6618 | return -1; | 
|  | 6619 | *pos++ = '\0'; | 
|  | 6620 |  | 
|  | 6621 | if (hexstr2bin(cmd, &version, 1) < 0) | 
|  | 6622 | return -1; | 
|  | 6623 |  | 
|  | 6624 | return wpas_p2p_service_del_upnp(wpa_s, version, pos); | 
|  | 6625 | } | 
|  | 6626 |  | 
|  | 6627 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6628 | static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6629 | { | 
|  | 6630 | u32 adv_id; | 
|  | 6631 |  | 
| Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 6632 | if (os_strcmp(cmd, "all") == 0) { | 
|  | 6633 | wpas_p2p_service_flush_asp(wpa_s); | 
|  | 6634 | return 0; | 
|  | 6635 | } | 
|  | 6636 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6637 | if (sscanf(cmd, "%x", &adv_id) != 1) | 
|  | 6638 | return -1; | 
|  | 6639 |  | 
|  | 6640 | return wpas_p2p_service_del_asp(wpa_s, adv_id); | 
|  | 6641 | } | 
|  | 6642 |  | 
|  | 6643 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6644 | static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6645 | { | 
|  | 6646 | char *pos; | 
|  | 6647 |  | 
|  | 6648 | pos = os_strchr(cmd, ' '); | 
|  | 6649 | if (pos == NULL) | 
|  | 6650 | return -1; | 
|  | 6651 | *pos++ = '\0'; | 
|  | 6652 |  | 
|  | 6653 | if (os_strcmp(cmd, "bonjour") == 0) | 
|  | 6654 | return p2p_ctrl_service_del_bonjour(wpa_s, pos); | 
|  | 6655 | if (os_strcmp(cmd, "upnp") == 0) | 
|  | 6656 | return p2p_ctrl_service_del_upnp(wpa_s, pos); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6657 | if (os_strcmp(cmd, "asp") == 0) | 
|  | 6658 | return p2p_ctrl_service_del_asp(wpa_s, pos); | 
|  | 6659 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | 
|  | 6660 | return -1; | 
|  | 6661 | } | 
|  | 6662 |  | 
|  | 6663 |  | 
|  | 6664 | static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6665 | { | 
|  | 6666 | char *pos; | 
|  | 6667 |  | 
|  | 6668 | pos = os_strchr(cmd, ' '); | 
|  | 6669 | if (pos == NULL) | 
|  | 6670 | return -1; | 
|  | 6671 | *pos++ = '\0'; | 
|  | 6672 |  | 
|  | 6673 | if (os_strcmp(cmd, "asp") == 0) | 
|  | 6674 | return p2p_ctrl_service_add_asp(wpa_s, 1, pos); | 
|  | 6675 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6676 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); | 
|  | 6677 | return -1; | 
|  | 6678 | } | 
|  | 6679 |  | 
|  | 6680 |  | 
|  | 6681 | static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6682 | { | 
|  | 6683 | u8 addr[ETH_ALEN]; | 
|  | 6684 |  | 
|  | 6685 | /* <addr> */ | 
|  | 6686 |  | 
|  | 6687 | if (hwaddr_aton(cmd, addr)) | 
|  | 6688 | return -1; | 
|  | 6689 |  | 
|  | 6690 | return wpas_p2p_reject(wpa_s, addr); | 
|  | 6691 | } | 
|  | 6692 |  | 
|  | 6693 |  | 
|  | 6694 | static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6695 | { | 
|  | 6696 | char *pos; | 
|  | 6697 | int id; | 
|  | 6698 | struct wpa_ssid *ssid; | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6699 | u8 *_peer = NULL, peer[ETH_ALEN]; | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6700 | int freq = 0, pref_freq = 0; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6701 | int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6702 | int edmg; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6703 | bool allow_6ghz; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6704 |  | 
|  | 6705 | id = atoi(cmd); | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6706 | pos = os_strstr(cmd, " peer="); | 
|  | 6707 | if (pos) { | 
|  | 6708 | pos += 6; | 
|  | 6709 | if (hwaddr_aton(pos, peer)) | 
|  | 6710 | return -1; | 
|  | 6711 | _peer = peer; | 
|  | 6712 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6713 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 6714 | if (ssid == NULL || ssid->disabled != 2) { | 
|  | 6715 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | 
|  | 6716 | "for persistent P2P group", | 
|  | 6717 | id); | 
|  | 6718 | return -1; | 
|  | 6719 | } | 
|  | 6720 |  | 
| Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 6721 | pos = os_strstr(cmd, " freq="); | 
|  | 6722 | if (pos) { | 
|  | 6723 | pos += 6; | 
|  | 6724 | freq = atoi(pos); | 
|  | 6725 | if (freq <= 0) | 
|  | 6726 | return -1; | 
|  | 6727 | } | 
|  | 6728 |  | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6729 | pos = os_strstr(cmd, " pref="); | 
|  | 6730 | if (pos) { | 
|  | 6731 | pos += 6; | 
|  | 6732 | pref_freq = atoi(pos); | 
|  | 6733 | if (pref_freq <= 0) | 
|  | 6734 | return -1; | 
|  | 6735 | } | 
|  | 6736 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6737 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; | 
|  | 6738 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || | 
|  | 6739 | vht; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6740 | he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6741 | edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg; | 
| Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 6742 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6743 | pos = os_strstr(cmd, "freq2="); | 
|  | 6744 | if (pos) | 
|  | 6745 | freq2 = atoi(pos + 6); | 
|  | 6746 |  | 
|  | 6747 | pos = os_strstr(cmd, " max_oper_chwidth="); | 
|  | 6748 | if (pos) | 
|  | 6749 | chwidth = atoi(pos + 18); | 
|  | 6750 |  | 
|  | 6751 | max_oper_chwidth = parse_freq(chwidth, freq2); | 
|  | 6752 | if (max_oper_chwidth < 0) | 
|  | 6753 | return -1; | 
|  | 6754 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6755 | allow_6ghz = os_strstr(cmd, " allow_6ghz") != NULL; | 
|  | 6756 |  | 
|  | 6757 | if (allow_6ghz && chwidth == 40) | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6758 | max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6759 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6760 | 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] | 6761 | max_oper_chwidth, pref_freq, he, edmg, | 
|  | 6762 | allow_6ghz); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6763 | } | 
|  | 6764 |  | 
|  | 6765 |  | 
|  | 6766 | static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6767 | { | 
|  | 6768 | char *pos; | 
|  | 6769 | u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6770 | bool allow_6ghz; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6771 |  | 
|  | 6772 | pos = os_strstr(cmd, " peer="); | 
|  | 6773 | if (!pos) | 
|  | 6774 | return -1; | 
|  | 6775 |  | 
|  | 6776 | *pos = '\0'; | 
|  | 6777 | pos += 6; | 
|  | 6778 | if (hwaddr_aton(pos, peer)) { | 
|  | 6779 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos); | 
|  | 6780 | return -1; | 
|  | 6781 | } | 
|  | 6782 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6783 | allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL; | 
|  | 6784 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6785 | pos = os_strstr(pos, " go_dev_addr="); | 
|  | 6786 | if (pos) { | 
|  | 6787 | pos += 13; | 
|  | 6788 | if (hwaddr_aton(pos, go_dev_addr)) { | 
|  | 6789 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", | 
|  | 6790 | pos); | 
|  | 6791 | return -1; | 
|  | 6792 | } | 
|  | 6793 | go_dev = go_dev_addr; | 
|  | 6794 | } | 
|  | 6795 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6796 | 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] | 6797 | } | 
|  | 6798 |  | 
|  | 6799 |  | 
|  | 6800 | static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6801 | { | 
|  | 6802 | if (os_strncmp(cmd, "persistent=", 11) == 0) | 
|  | 6803 | return p2p_ctrl_invite_persistent(wpa_s, cmd + 11); | 
|  | 6804 | if (os_strncmp(cmd, "group=", 6) == 0) | 
|  | 6805 | return p2p_ctrl_invite_group(wpa_s, cmd + 6); | 
|  | 6806 |  | 
|  | 6807 | return -1; | 
|  | 6808 | } | 
|  | 6809 |  | 
|  | 6810 |  | 
|  | 6811 | static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6812 | int id, int freq, int vht_center_freq2, | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6813 | int ht40, int vht, int vht_chwidth, | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6814 | int he, int edmg, bool allow_6ghz) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6815 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6816 | struct wpa_ssid *ssid; | 
|  | 6817 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6818 | ssid = wpa_config_get_network(wpa_s->conf, id); | 
|  | 6819 | if (ssid == NULL || ssid->disabled != 2) { | 
|  | 6820 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " | 
|  | 6821 | "for persistent P2P group", | 
|  | 6822 | id); | 
|  | 6823 | return -1; | 
|  | 6824 | } | 
|  | 6825 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6826 | return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, | 
|  | 6827 | vht_center_freq2, 0, ht40, vht, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6828 | vht_chwidth, he, edmg, | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6829 | NULL, 0, 0, allow_6ghz); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6830 | } | 
|  | 6831 |  | 
|  | 6832 |  | 
|  | 6833 | static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 6834 | { | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6835 | int freq = 0, persistent = 0, group_id = -1; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6836 | bool allow_6ghz = false; | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6837 | int vht = wpa_s->conf->p2p_go_vht; | 
|  | 6838 | int ht40 = wpa_s->conf->p2p_go_ht40 || vht; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6839 | int he = wpa_s->conf->p2p_go_he; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6840 | int edmg = wpa_s->conf->p2p_go_edmg; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6841 | int max_oper_chwidth, chwidth = 0, freq2 = 0; | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6842 | char *token, *context = NULL; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6843 | #ifdef CONFIG_ACS | 
|  | 6844 | int acs = 0; | 
|  | 6845 | #endif /* CONFIG_ACS */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6846 |  | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6847 | while ((token = str_token(cmd, " ", &context))) { | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6848 | if (sscanf(token, "freq2=%d", &freq2) == 1 || | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6849 | sscanf(token, "persistent=%d", &group_id) == 1 || | 
|  | 6850 | sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) { | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6851 | continue; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6852 | #ifdef CONFIG_ACS | 
|  | 6853 | } else if (os_strcmp(token, "freq=acs") == 0) { | 
|  | 6854 | acs = 1; | 
|  | 6855 | #endif /* CONFIG_ACS */ | 
|  | 6856 | } else if (sscanf(token, "freq=%d", &freq) == 1) { | 
|  | 6857 | continue; | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6858 | } else if (os_strcmp(token, "ht40") == 0) { | 
|  | 6859 | ht40 = 1; | 
|  | 6860 | } else if (os_strcmp(token, "vht") == 0) { | 
|  | 6861 | vht = 1; | 
|  | 6862 | ht40 = 1; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6863 | } else if (os_strcmp(token, "he") == 0) { | 
|  | 6864 | he = 1; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6865 | } else if (os_strcmp(token, "edmg") == 0) { | 
|  | 6866 | edmg = 1; | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6867 | } else if (os_strcmp(token, "persistent") == 0) { | 
|  | 6868 | persistent = 1; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6869 | } else if (os_strcmp(token, "allow_6ghz") == 0) { | 
|  | 6870 | allow_6ghz = true; | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6871 | } else { | 
|  | 6872 | wpa_printf(MSG_DEBUG, | 
|  | 6873 | "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'", | 
|  | 6874 | token); | 
|  | 6875 | return -1; | 
|  | 6876 | } | 
|  | 6877 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6878 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6879 | #ifdef CONFIG_ACS | 
|  | 6880 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) && | 
|  | 6881 | (acs || freq == 2 || freq == 5)) { | 
|  | 6882 | if (freq == 2 && wpa_s->best_24_freq <= 0) { | 
|  | 6883 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G; | 
|  | 6884 | wpa_s->p2p_go_do_acs = 1; | 
|  | 6885 | freq = 0; | 
|  | 6886 | } else if (freq == 5 && wpa_s->best_5_freq <= 0) { | 
|  | 6887 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A; | 
|  | 6888 | wpa_s->p2p_go_do_acs = 1; | 
|  | 6889 | freq = 0; | 
|  | 6890 | } else { | 
|  | 6891 | wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY; | 
|  | 6892 | wpa_s->p2p_go_do_acs = 1; | 
|  | 6893 | } | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6894 | } else { | 
|  | 6895 | wpa_s->p2p_go_do_acs = 0; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6896 | } | 
|  | 6897 | #endif /* CONFIG_ACS */ | 
|  | 6898 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6899 | max_oper_chwidth = parse_freq(chwidth, freq2); | 
|  | 6900 | if (max_oper_chwidth < 0) | 
|  | 6901 | return -1; | 
|  | 6902 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6903 | if (allow_6ghz && chwidth == 40) | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6904 | max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6905 |  | 
|  | 6906 | /* Allow DFS to be used for Autonomous GO */ | 
|  | 6907 | wpa_s->p2p_go_allow_dfs = !!(wpa_s->drv_flags & | 
|  | 6908 | WPA_DRIVER_FLAGS_DFS_OFFLOAD); | 
|  | 6909 |  | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6910 | if (group_id >= 0) | 
|  | 6911 | return p2p_ctrl_group_add_persistent(wpa_s, group_id, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6912 | freq, freq2, ht40, vht, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6913 | max_oper_chwidth, he, | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6914 | edmg, allow_6ghz); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6915 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6916 | return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht, | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6917 | max_oper_chwidth, he, edmg, allow_6ghz); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6918 | } | 
|  | 6919 |  | 
|  | 6920 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6921 | static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd, | 
|  | 6922 | char *buf, size_t buflen) | 
|  | 6923 | { | 
|  | 6924 | u8 dev_addr[ETH_ALEN]; | 
|  | 6925 | struct wpa_ssid *ssid; | 
|  | 6926 | int res; | 
|  | 6927 | const u8 *iaddr; | 
|  | 6928 |  | 
|  | 6929 | ssid = wpa_s->current_ssid; | 
|  | 6930 | if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO || | 
|  | 6931 | hwaddr_aton(cmd, dev_addr)) | 
|  | 6932 | return -1; | 
|  | 6933 |  | 
|  | 6934 | iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr); | 
|  | 6935 | if (!iaddr) | 
|  | 6936 | return -1; | 
|  | 6937 | res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr)); | 
|  | 6938 | if (os_snprintf_error(buflen, res)) | 
|  | 6939 | return -1; | 
|  | 6940 | return res; | 
|  | 6941 | } | 
|  | 6942 |  | 
|  | 6943 |  | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 6944 | static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global, | 
|  | 6945 | const u8 *p2p_dev_addr) | 
|  | 6946 | { | 
|  | 6947 | struct wpa_supplicant *wpa_s; | 
|  | 6948 |  | 
|  | 6949 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 6950 | if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr)) | 
|  | 6951 | return 1; | 
|  | 6952 | } | 
|  | 6953 |  | 
|  | 6954 | return 0; | 
|  | 6955 | } | 
|  | 6956 |  | 
|  | 6957 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6958 | static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 6959 | char *buf, size_t buflen) | 
|  | 6960 | { | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 6961 | u8 addr[ETH_ALEN], *addr_ptr, group_capab; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6962 | int next, res; | 
|  | 6963 | const struct p2p_peer_info *info; | 
|  | 6964 | char *pos, *end; | 
|  | 6965 | char devtype[WPS_DEV_TYPE_BUFSIZE]; | 
|  | 6966 | struct wpa_ssid *ssid; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6967 | size_t i; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6968 |  | 
|  | 6969 | if (!wpa_s->global->p2p) | 
|  | 6970 | return -1; | 
|  | 6971 |  | 
|  | 6972 | if (os_strcmp(cmd, "FIRST") == 0) { | 
|  | 6973 | addr_ptr = NULL; | 
|  | 6974 | next = 0; | 
|  | 6975 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { | 
|  | 6976 | if (hwaddr_aton(cmd + 5, addr) < 0) | 
|  | 6977 | return -1; | 
|  | 6978 | addr_ptr = addr; | 
|  | 6979 | next = 1; | 
|  | 6980 | } else { | 
|  | 6981 | if (hwaddr_aton(cmd, addr) < 0) | 
|  | 6982 | return -1; | 
|  | 6983 | addr_ptr = addr; | 
|  | 6984 | next = 0; | 
|  | 6985 | } | 
|  | 6986 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6987 | info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next); | 
|  | 6988 | if (info == NULL) | 
|  | 6989 | return -1; | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 6990 | group_capab = info->group_capab; | 
|  | 6991 |  | 
|  | 6992 | if (group_capab && | 
|  | 6993 | !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) { | 
|  | 6994 | wpa_printf(MSG_DEBUG, | 
|  | 6995 | "P2P: Could not find any BSS with p2p_dev_addr " | 
|  | 6996 | MACSTR ", hence override group_capab from 0x%x to 0", | 
|  | 6997 | MAC2STR(info->p2p_device_addr), group_capab); | 
|  | 6998 | group_capab = 0; | 
|  | 6999 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7000 |  | 
|  | 7001 | pos = buf; | 
|  | 7002 | end = buf + buflen; | 
|  | 7003 |  | 
|  | 7004 | res = os_snprintf(pos, end - pos, MACSTR "\n" | 
|  | 7005 | "pri_dev_type=%s\n" | 
|  | 7006 | "device_name=%s\n" | 
|  | 7007 | "manufacturer=%s\n" | 
|  | 7008 | "model_name=%s\n" | 
|  | 7009 | "model_number=%s\n" | 
|  | 7010 | "serial_number=%s\n" | 
|  | 7011 | "config_methods=0x%x\n" | 
|  | 7012 | "dev_capab=0x%x\n" | 
|  | 7013 | "group_capab=0x%x\n" | 
|  | 7014 | "level=%d\n", | 
|  | 7015 | MAC2STR(info->p2p_device_addr), | 
|  | 7016 | wps_dev_type_bin2str(info->pri_dev_type, | 
|  | 7017 | devtype, sizeof(devtype)), | 
|  | 7018 | info->device_name, | 
|  | 7019 | info->manufacturer, | 
|  | 7020 | info->model_name, | 
|  | 7021 | info->model_number, | 
|  | 7022 | info->serial_number, | 
|  | 7023 | info->config_methods, | 
|  | 7024 | info->dev_capab, | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7025 | group_capab, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7026 | info->level); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7027 | if (os_snprintf_error(end - pos, res)) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7028 | return pos - buf; | 
|  | 7029 | pos += res; | 
|  | 7030 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7031 | for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++) | 
|  | 7032 | { | 
|  | 7033 | const u8 *t; | 
|  | 7034 | t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN]; | 
|  | 7035 | res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n", | 
|  | 7036 | wps_dev_type_bin2str(t, devtype, | 
|  | 7037 | sizeof(devtype))); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7038 | if (os_snprintf_error(end - pos, res)) | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7039 | return pos - buf; | 
|  | 7040 | pos += res; | 
|  | 7041 | } | 
|  | 7042 |  | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7043 | 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] | 7044 | if (ssid) { | 
|  | 7045 | res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7046 | if (os_snprintf_error(end - pos, res)) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7047 | return pos - buf; | 
|  | 7048 | pos += res; | 
|  | 7049 | } | 
|  | 7050 |  | 
|  | 7051 | res = p2p_get_peer_info_txt(info, pos, end - pos); | 
|  | 7052 | if (res < 0) | 
|  | 7053 | return pos - buf; | 
|  | 7054 | pos += res; | 
|  | 7055 |  | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 7056 | if (info->vendor_elems) { | 
|  | 7057 | res = os_snprintf(pos, end - pos, "vendor_elems="); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7058 | if (os_snprintf_error(end - pos, res)) | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 7059 | return pos - buf; | 
|  | 7060 | pos += res; | 
|  | 7061 |  | 
|  | 7062 | pos += wpa_snprintf_hex(pos, end - pos, | 
|  | 7063 | wpabuf_head(info->vendor_elems), | 
|  | 7064 | wpabuf_len(info->vendor_elems)); | 
|  | 7065 |  | 
|  | 7066 | res = os_snprintf(pos, end - pos, "\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7067 | if (os_snprintf_error(end - pos, res)) | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 7068 | return pos - buf; | 
|  | 7069 | pos += res; | 
|  | 7070 | } | 
|  | 7071 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7072 | return pos - buf; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7073 | } | 
|  | 7074 |  | 
|  | 7075 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7076 | static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s, | 
|  | 7077 | const char *param) | 
|  | 7078 | { | 
| Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 7079 | unsigned int i; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7080 |  | 
|  | 7081 | if (wpa_s->global->p2p == NULL) | 
|  | 7082 | return -1; | 
|  | 7083 |  | 
| Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 7084 | if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0) | 
|  | 7085 | return -1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7086 |  | 
| Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 7087 | for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) { | 
|  | 7088 | struct wpa_freq_range *freq; | 
|  | 7089 | freq = &wpa_s->global->p2p_disallow_freq.range[i]; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7090 | wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u", | 
| Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 7091 | freq->min, freq->max); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7092 | } | 
|  | 7093 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7094 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7095 | return 0; | 
|  | 7096 | } | 
|  | 7097 |  | 
|  | 7098 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7099 | static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 7100 | { | 
|  | 7101 | char *param; | 
|  | 7102 |  | 
|  | 7103 | if (wpa_s->global->p2p == NULL) | 
|  | 7104 | return -1; | 
|  | 7105 |  | 
|  | 7106 | param = os_strchr(cmd, ' '); | 
|  | 7107 | if (param == NULL) | 
|  | 7108 | return -1; | 
|  | 7109 | *param++ = '\0'; | 
|  | 7110 |  | 
|  | 7111 | if (os_strcmp(cmd, "discoverability") == 0) { | 
|  | 7112 | p2p_set_client_discoverability(wpa_s->global->p2p, | 
|  | 7113 | atoi(param)); | 
|  | 7114 | return 0; | 
|  | 7115 | } | 
|  | 7116 |  | 
|  | 7117 | if (os_strcmp(cmd, "managed") == 0) { | 
|  | 7118 | p2p_set_managed_oper(wpa_s->global->p2p, atoi(param)); | 
|  | 7119 | return 0; | 
|  | 7120 | } | 
|  | 7121 |  | 
|  | 7122 | if (os_strcmp(cmd, "listen_channel") == 0) { | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 7123 | char *pos; | 
|  | 7124 | u8 channel, op_class; | 
|  | 7125 |  | 
|  | 7126 | channel = atoi(param); | 
|  | 7127 | pos = os_strchr(param, ' '); | 
|  | 7128 | op_class = pos ? atoi(pos) : 81; | 
|  | 7129 |  | 
|  | 7130 | return p2p_set_listen_channel(wpa_s->global->p2p, op_class, | 
|  | 7131 | channel, 1); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7132 | } | 
|  | 7133 |  | 
|  | 7134 | if (os_strcmp(cmd, "ssid_postfix") == 0) { | 
|  | 7135 | return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param, | 
|  | 7136 | os_strlen(param)); | 
|  | 7137 | } | 
|  | 7138 |  | 
|  | 7139 | if (os_strcmp(cmd, "noa") == 0) { | 
|  | 7140 | char *pos; | 
|  | 7141 | int count, start, duration; | 
|  | 7142 | /* GO NoA parameters: count,start_offset(ms),duration(ms) */ | 
|  | 7143 | count = atoi(param); | 
|  | 7144 | pos = os_strchr(param, ','); | 
|  | 7145 | if (pos == NULL) | 
|  | 7146 | return -1; | 
|  | 7147 | pos++; | 
|  | 7148 | start = atoi(pos); | 
|  | 7149 | pos = os_strchr(pos, ','); | 
|  | 7150 | if (pos == NULL) | 
|  | 7151 | return -1; | 
|  | 7152 | pos++; | 
|  | 7153 | duration = atoi(pos); | 
|  | 7154 | if (count < 0 || count > 255 || start < 0 || duration < 0) | 
|  | 7155 | return -1; | 
|  | 7156 | if (count == 0 && duration > 0) | 
|  | 7157 | return -1; | 
|  | 7158 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d " | 
|  | 7159 | "start=%d duration=%d", count, start, duration); | 
|  | 7160 | return wpas_p2p_set_noa(wpa_s, count, start, duration); | 
|  | 7161 | } | 
|  | 7162 |  | 
|  | 7163 | if (os_strcmp(cmd, "ps") == 0) | 
|  | 7164 | return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1); | 
|  | 7165 |  | 
|  | 7166 | if (os_strcmp(cmd, "oppps") == 0) | 
|  | 7167 | return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1); | 
|  | 7168 |  | 
|  | 7169 | if (os_strcmp(cmd, "ctwindow") == 0) | 
|  | 7170 | return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param)); | 
|  | 7171 |  | 
|  | 7172 | if (os_strcmp(cmd, "disabled") == 0) { | 
|  | 7173 | wpa_s->global->p2p_disabled = atoi(param); | 
|  | 7174 | wpa_printf(MSG_DEBUG, "P2P functionality %s", | 
|  | 7175 | wpa_s->global->p2p_disabled ? | 
|  | 7176 | "disabled" : "enabled"); | 
|  | 7177 | if (wpa_s->global->p2p_disabled) { | 
|  | 7178 | wpas_p2p_stop_find(wpa_s); | 
|  | 7179 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); | 
|  | 7180 | p2p_flush(wpa_s->global->p2p); | 
|  | 7181 | } | 
|  | 7182 | return 0; | 
|  | 7183 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7184 |  | 
| Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 7185 | if (os_strcmp(cmd, "conc_pref") == 0) { | 
|  | 7186 | if (os_strcmp(param, "sta") == 0) | 
|  | 7187 | wpa_s->global->conc_pref = WPA_CONC_PREF_STA; | 
|  | 7188 | else if (os_strcmp(param, "p2p") == 0) | 
|  | 7189 | wpa_s->global->conc_pref = WPA_CONC_PREF_P2P; | 
| Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 7190 | else { | 
| Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 7191 | wpa_printf(MSG_INFO, "Invalid conc_pref value"); | 
| Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 7192 | return -1; | 
|  | 7193 | } | 
| Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 7194 | wpa_printf(MSG_DEBUG, "Single channel concurrency preference: " | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7195 | "%s", param); | 
| Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 7196 | return 0; | 
|  | 7197 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7198 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7199 | if (os_strcmp(cmd, "force_long_sd") == 0) { | 
|  | 7200 | wpa_s->force_long_sd = atoi(param); | 
|  | 7201 | return 0; | 
|  | 7202 | } | 
|  | 7203 |  | 
|  | 7204 | if (os_strcmp(cmd, "peer_filter") == 0) { | 
|  | 7205 | u8 addr[ETH_ALEN]; | 
|  | 7206 | if (hwaddr_aton(param, addr)) | 
|  | 7207 | return -1; | 
|  | 7208 | p2p_set_peer_filter(wpa_s->global->p2p, addr); | 
|  | 7209 | return 0; | 
|  | 7210 | } | 
|  | 7211 |  | 
|  | 7212 | if (os_strcmp(cmd, "cross_connect") == 0) | 
|  | 7213 | return wpas_p2p_set_cross_connect(wpa_s, atoi(param)); | 
|  | 7214 |  | 
|  | 7215 | if (os_strcmp(cmd, "go_apsd") == 0) { | 
|  | 7216 | if (os_strcmp(param, "disable") == 0) | 
|  | 7217 | wpa_s->set_ap_uapsd = 0; | 
|  | 7218 | else { | 
|  | 7219 | wpa_s->set_ap_uapsd = 1; | 
|  | 7220 | wpa_s->ap_uapsd = atoi(param); | 
|  | 7221 | } | 
|  | 7222 | return 0; | 
|  | 7223 | } | 
|  | 7224 |  | 
|  | 7225 | if (os_strcmp(cmd, "client_apsd") == 0) { | 
|  | 7226 | if (os_strcmp(param, "disable") == 0) | 
|  | 7227 | wpa_s->set_sta_uapsd = 0; | 
|  | 7228 | else { | 
|  | 7229 | int be, bk, vi, vo; | 
|  | 7230 | char *pos; | 
|  | 7231 | /* format: BE,BK,VI,VO;max SP Length */ | 
|  | 7232 | be = atoi(param); | 
|  | 7233 | pos = os_strchr(param, ','); | 
|  | 7234 | if (pos == NULL) | 
|  | 7235 | return -1; | 
|  | 7236 | pos++; | 
|  | 7237 | bk = atoi(pos); | 
|  | 7238 | pos = os_strchr(pos, ','); | 
|  | 7239 | if (pos == NULL) | 
|  | 7240 | return -1; | 
|  | 7241 | pos++; | 
|  | 7242 | vi = atoi(pos); | 
|  | 7243 | pos = os_strchr(pos, ','); | 
|  | 7244 | if (pos == NULL) | 
|  | 7245 | return -1; | 
|  | 7246 | pos++; | 
|  | 7247 | vo = atoi(pos); | 
|  | 7248 | /* ignore max SP Length for now */ | 
|  | 7249 |  | 
|  | 7250 | wpa_s->set_sta_uapsd = 1; | 
|  | 7251 | wpa_s->sta_uapsd = 0; | 
|  | 7252 | if (be) | 
|  | 7253 | wpa_s->sta_uapsd |= BIT(0); | 
|  | 7254 | if (bk) | 
|  | 7255 | wpa_s->sta_uapsd |= BIT(1); | 
|  | 7256 | if (vi) | 
|  | 7257 | wpa_s->sta_uapsd |= BIT(2); | 
|  | 7258 | if (vo) | 
|  | 7259 | wpa_s->sta_uapsd |= BIT(3); | 
|  | 7260 | } | 
|  | 7261 | return 0; | 
|  | 7262 | } | 
|  | 7263 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7264 | if (os_strcmp(cmd, "disallow_freq") == 0) | 
|  | 7265 | return p2p_ctrl_disallow_freq(wpa_s, param); | 
|  | 7266 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7267 | if (os_strcmp(cmd, "disc_int") == 0) { | 
|  | 7268 | int min_disc_int, max_disc_int, max_disc_tu; | 
|  | 7269 | char *pos; | 
|  | 7270 |  | 
|  | 7271 | pos = param; | 
|  | 7272 |  | 
|  | 7273 | min_disc_int = atoi(pos); | 
|  | 7274 | pos = os_strchr(pos, ' '); | 
|  | 7275 | if (pos == NULL) | 
|  | 7276 | return -1; | 
|  | 7277 | *pos++ = '\0'; | 
|  | 7278 |  | 
|  | 7279 | max_disc_int = atoi(pos); | 
|  | 7280 | pos = os_strchr(pos, ' '); | 
|  | 7281 | if (pos == NULL) | 
|  | 7282 | return -1; | 
|  | 7283 | *pos++ = '\0'; | 
|  | 7284 |  | 
|  | 7285 | max_disc_tu = atoi(pos); | 
|  | 7286 |  | 
|  | 7287 | return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int, | 
|  | 7288 | max_disc_int, max_disc_tu); | 
|  | 7289 | } | 
|  | 7290 |  | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7291 | if (os_strcmp(cmd, "per_sta_psk") == 0) { | 
|  | 7292 | wpa_s->global->p2p_per_sta_psk = !!atoi(param); | 
|  | 7293 | return 0; | 
|  | 7294 | } | 
|  | 7295 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7296 | #ifdef CONFIG_WPS_NFC | 
|  | 7297 | if (os_strcmp(cmd, "nfc_tag") == 0) | 
|  | 7298 | return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param)); | 
|  | 7299 | #endif /* CONFIG_WPS_NFC */ | 
|  | 7300 |  | 
|  | 7301 | if (os_strcmp(cmd, "disable_ip_addr_req") == 0) { | 
|  | 7302 | wpa_s->p2p_disable_ip_addr_req = !!atoi(param); | 
|  | 7303 | return 0; | 
|  | 7304 | } | 
|  | 7305 |  | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7306 | if (os_strcmp(cmd, "override_pref_op_chan") == 0) { | 
|  | 7307 | int op_class, chan; | 
|  | 7308 |  | 
|  | 7309 | op_class = atoi(param); | 
|  | 7310 | param = os_strchr(param, ':'); | 
|  | 7311 | if (!param) | 
|  | 7312 | return -1; | 
|  | 7313 | param++; | 
|  | 7314 | chan = atoi(param); | 
|  | 7315 | p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class, | 
|  | 7316 | chan); | 
|  | 7317 | return 0; | 
|  | 7318 | } | 
|  | 7319 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7320 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", | 
|  | 7321 | cmd); | 
|  | 7322 |  | 
|  | 7323 | return -1; | 
|  | 7324 | } | 
|  | 7325 |  | 
|  | 7326 |  | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7327 | static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s) | 
|  | 7328 | { | 
|  | 7329 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); | 
|  | 7330 | wpa_s->force_long_sd = 0; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7331 |  | 
|  | 7332 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 7333 | os_free(wpa_s->get_pref_freq_list_override); | 
|  | 7334 | wpa_s->get_pref_freq_list_override = NULL; | 
|  | 7335 | #endif /* CONFIG_TESTING_OPTIONS */ | 
|  | 7336 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7337 | wpas_p2p_stop_find(wpa_s); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7338 | wpa_s->parent->p2ps_method_config_any = 0; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7339 | if (wpa_s->global->p2p) | 
|  | 7340 | p2p_flush(wpa_s->global->p2p); | 
|  | 7341 | } | 
|  | 7342 |  | 
|  | 7343 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7344 | static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 7345 | { | 
|  | 7346 | char *pos, *pos2; | 
|  | 7347 | unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0; | 
|  | 7348 |  | 
|  | 7349 | if (cmd[0]) { | 
|  | 7350 | pos = os_strchr(cmd, ' '); | 
|  | 7351 | if (pos == NULL) | 
|  | 7352 | return -1; | 
|  | 7353 | *pos++ = '\0'; | 
|  | 7354 | dur1 = atoi(cmd); | 
|  | 7355 |  | 
|  | 7356 | pos2 = os_strchr(pos, ' '); | 
|  | 7357 | if (pos2) | 
|  | 7358 | *pos2++ = '\0'; | 
|  | 7359 | int1 = atoi(pos); | 
|  | 7360 | } else | 
|  | 7361 | pos2 = NULL; | 
|  | 7362 |  | 
|  | 7363 | if (pos2) { | 
|  | 7364 | pos = os_strchr(pos2, ' '); | 
|  | 7365 | if (pos == NULL) | 
|  | 7366 | return -1; | 
|  | 7367 | *pos++ = '\0'; | 
|  | 7368 | dur2 = atoi(pos2); | 
|  | 7369 | int2 = atoi(pos); | 
|  | 7370 | } | 
|  | 7371 |  | 
|  | 7372 | return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2); | 
|  | 7373 | } | 
|  | 7374 |  | 
|  | 7375 |  | 
|  | 7376 | static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 7377 | { | 
|  | 7378 | char *pos; | 
|  | 7379 | unsigned int period = 0, interval = 0; | 
|  | 7380 |  | 
|  | 7381 | if (cmd[0]) { | 
|  | 7382 | pos = os_strchr(cmd, ' '); | 
|  | 7383 | if (pos == NULL) | 
|  | 7384 | return -1; | 
|  | 7385 | *pos++ = '\0'; | 
|  | 7386 | period = atoi(cmd); | 
|  | 7387 | interval = atoi(pos); | 
|  | 7388 | } | 
|  | 7389 |  | 
|  | 7390 | return wpas_p2p_ext_listen(wpa_s, period, interval); | 
|  | 7391 | } | 
|  | 7392 |  | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7393 |  | 
|  | 7394 | static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd) | 
|  | 7395 | { | 
|  | 7396 | const char *pos; | 
|  | 7397 | u8 peer[ETH_ALEN]; | 
|  | 7398 | int iface_addr = 0; | 
|  | 7399 |  | 
|  | 7400 | pos = cmd; | 
|  | 7401 | if (os_strncmp(pos, "iface=", 6) == 0) { | 
|  | 7402 | iface_addr = 1; | 
|  | 7403 | pos += 6; | 
|  | 7404 | } | 
|  | 7405 | if (hwaddr_aton(pos, peer)) | 
|  | 7406 | return -1; | 
|  | 7407 |  | 
|  | 7408 | wpas_p2p_remove_client(wpa_s, peer, iface_addr); | 
|  | 7409 | return 0; | 
|  | 7410 | } | 
|  | 7411 |  | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7412 |  | 
|  | 7413 | static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 7414 | { | 
|  | 7415 | int freq = 0, period = 0, interval = 0, count = 0; | 
|  | 7416 |  | 
|  | 7417 | if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4) | 
|  | 7418 | { | 
|  | 7419 | wpa_printf(MSG_DEBUG, | 
|  | 7420 | "CTRL: Invalid P2P LO Start parameter: '%s'", cmd); | 
|  | 7421 | return -1; | 
|  | 7422 | } | 
|  | 7423 |  | 
|  | 7424 | return wpas_p2p_lo_start(wpa_s, freq, period, interval, count); | 
|  | 7425 | } | 
|  | 7426 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7427 | #endif /* CONFIG_P2P */ | 
|  | 7428 |  | 
|  | 7429 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7430 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val) | 
|  | 7431 | { | 
|  | 7432 | struct wpa_freq_range_list ranges; | 
|  | 7433 | int *freqs = NULL; | 
|  | 7434 | struct hostapd_hw_modes *mode; | 
|  | 7435 | u16 i; | 
|  | 7436 |  | 
|  | 7437 | if (wpa_s->hw.modes == NULL) | 
|  | 7438 | return NULL; | 
|  | 7439 |  | 
|  | 7440 | os_memset(&ranges, 0, sizeof(ranges)); | 
|  | 7441 | if (freq_range_list_parse(&ranges, val) < 0) | 
|  | 7442 | return NULL; | 
|  | 7443 |  | 
|  | 7444 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | 
|  | 7445 | int j; | 
|  | 7446 |  | 
|  | 7447 | mode = &wpa_s->hw.modes[i]; | 
|  | 7448 | for (j = 0; j < mode->num_channels; j++) { | 
|  | 7449 | unsigned int freq; | 
|  | 7450 |  | 
|  | 7451 | if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED) | 
|  | 7452 | continue; | 
|  | 7453 |  | 
|  | 7454 | freq = mode->channels[j].freq; | 
|  | 7455 | if (!freq_range_list_includes(&ranges, freq)) | 
|  | 7456 | continue; | 
|  | 7457 |  | 
|  | 7458 | int_array_add_unique(&freqs, freq); | 
|  | 7459 | } | 
|  | 7460 | } | 
|  | 7461 |  | 
|  | 7462 | os_free(ranges.range); | 
|  | 7463 | return freqs; | 
|  | 7464 | } | 
|  | 7465 |  | 
|  | 7466 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7467 | #ifdef CONFIG_INTERWORKING | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7468 |  | 
|  | 7469 | static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param) | 
|  | 7470 | { | 
|  | 7471 | int auto_sel = 0; | 
|  | 7472 | int *freqs = NULL; | 
|  | 7473 |  | 
|  | 7474 | if (param) { | 
|  | 7475 | char *pos; | 
|  | 7476 |  | 
|  | 7477 | auto_sel = os_strstr(param, "auto") != NULL; | 
|  | 7478 |  | 
|  | 7479 | pos = os_strstr(param, "freq="); | 
|  | 7480 | if (pos) { | 
|  | 7481 | freqs = freq_range_to_channel_list(wpa_s, pos + 5); | 
|  | 7482 | if (freqs == NULL) | 
|  | 7483 | return -1; | 
|  | 7484 | } | 
|  | 7485 |  | 
|  | 7486 | } | 
|  | 7487 |  | 
|  | 7488 | return interworking_select(wpa_s, auto_sel, freqs); | 
|  | 7489 | } | 
|  | 7490 |  | 
|  | 7491 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7492 | static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst, | 
|  | 7493 | int only_add) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7494 | { | 
|  | 7495 | u8 bssid[ETH_ALEN]; | 
|  | 7496 | struct wpa_bss *bss; | 
|  | 7497 |  | 
|  | 7498 | if (hwaddr_aton(dst, bssid)) { | 
|  | 7499 | wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst); | 
|  | 7500 | return -1; | 
|  | 7501 | } | 
|  | 7502 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7503 | bss = wpa_bss_get_bssid_latest(wpa_s, bssid); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7504 | if (bss == NULL) { | 
|  | 7505 | wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR, | 
|  | 7506 | MAC2STR(bssid)); | 
|  | 7507 | return -1; | 
|  | 7508 | } | 
|  | 7509 |  | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7510 | if (bss->ssid_len == 0) { | 
|  | 7511 | int found = 0; | 
|  | 7512 |  | 
|  | 7513 | wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR | 
|  | 7514 | " does not have SSID information", MAC2STR(bssid)); | 
|  | 7515 |  | 
|  | 7516 | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, | 
|  | 7517 | list) { | 
|  | 7518 | if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 && | 
|  | 7519 | bss->ssid_len > 0) { | 
|  | 7520 | found = 1; | 
|  | 7521 | break; | 
|  | 7522 | } | 
|  | 7523 | } | 
|  | 7524 |  | 
|  | 7525 | if (!found) | 
|  | 7526 | return -1; | 
|  | 7527 | wpa_printf(MSG_DEBUG, | 
|  | 7528 | "Found another matching BSS entry with SSID"); | 
|  | 7529 | } | 
|  | 7530 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7531 | return interworking_connect(wpa_s, bss, only_add); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7532 | } | 
|  | 7533 |  | 
|  | 7534 |  | 
|  | 7535 | static int get_anqp(struct wpa_supplicant *wpa_s, char *dst) | 
|  | 7536 | { | 
|  | 7537 | u8 dst_addr[ETH_ALEN]; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7538 | int used, freq = 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7539 | char *pos; | 
|  | 7540 | #define MAX_ANQP_INFO_ID 100 | 
|  | 7541 | u16 id[MAX_ANQP_INFO_ID]; | 
|  | 7542 | size_t num_id = 0; | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7543 | u32 subtypes = 0; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7544 | u32 mbo_subtypes = 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7545 |  | 
|  | 7546 | used = hwaddr_aton2(dst, dst_addr); | 
|  | 7547 | if (used < 0) | 
|  | 7548 | return -1; | 
|  | 7549 | pos = dst + used; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7550 | if (*pos == ' ') | 
|  | 7551 | pos++; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7552 |  | 
|  | 7553 | if (os_strncmp(pos, "freq=", 5) == 0) { | 
|  | 7554 | freq = atoi(pos + 5); | 
|  | 7555 | pos = os_strchr(pos, ' '); | 
|  | 7556 | if (!pos) | 
|  | 7557 | return -1; | 
|  | 7558 | pos++; | 
|  | 7559 | } | 
|  | 7560 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7561 | while (num_id < MAX_ANQP_INFO_ID) { | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7562 | if (os_strncmp(pos, "hs20:", 5) == 0) { | 
|  | 7563 | #ifdef CONFIG_HS20 | 
|  | 7564 | int num = atoi(pos + 5); | 
|  | 7565 | if (num <= 0 || num > 31) | 
|  | 7566 | return -1; | 
|  | 7567 | subtypes |= BIT(num); | 
|  | 7568 | #else /* CONFIG_HS20 */ | 
|  | 7569 | return -1; | 
|  | 7570 | #endif /* CONFIG_HS20 */ | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7571 | } else if (os_strncmp(pos, "mbo:", 4) == 0) { | 
|  | 7572 | #ifdef CONFIG_MBO | 
|  | 7573 | int num = atoi(pos + 4); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7574 |  | 
|  | 7575 | if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE) | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7576 | return -1; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7577 | mbo_subtypes |= BIT(num); | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7578 | #else /* CONFIG_MBO */ | 
|  | 7579 | return -1; | 
|  | 7580 | #endif /* CONFIG_MBO */ | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7581 | } else { | 
|  | 7582 | id[num_id] = atoi(pos); | 
|  | 7583 | if (id[num_id]) | 
|  | 7584 | num_id++; | 
|  | 7585 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7586 | pos = os_strchr(pos + 1, ','); | 
|  | 7587 | if (pos == NULL) | 
|  | 7588 | break; | 
|  | 7589 | pos++; | 
|  | 7590 | } | 
|  | 7591 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7592 | if (num_id == 0 && !subtypes && !mbo_subtypes) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7593 | return -1; | 
|  | 7594 |  | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7595 | 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] | 7596 | mbo_subtypes); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7597 | } | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7598 |  | 
|  | 7599 |  | 
|  | 7600 | static int gas_request(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 7601 | { | 
|  | 7602 | u8 dst_addr[ETH_ALEN]; | 
|  | 7603 | struct wpabuf *advproto, *query = NULL; | 
|  | 7604 | int used, ret = -1; | 
|  | 7605 | char *pos, *end; | 
|  | 7606 | size_t len; | 
|  | 7607 |  | 
|  | 7608 | used = hwaddr_aton2(cmd, dst_addr); | 
|  | 7609 | if (used < 0) | 
|  | 7610 | return -1; | 
|  | 7611 |  | 
|  | 7612 | pos = cmd + used; | 
|  | 7613 | while (*pos == ' ') | 
|  | 7614 | pos++; | 
|  | 7615 |  | 
|  | 7616 | /* Advertisement Protocol ID */ | 
|  | 7617 | end = os_strchr(pos, ' '); | 
|  | 7618 | if (end) | 
|  | 7619 | len = end - pos; | 
|  | 7620 | else | 
|  | 7621 | len = os_strlen(pos); | 
|  | 7622 | if (len & 0x01) | 
|  | 7623 | return -1; | 
|  | 7624 | len /= 2; | 
|  | 7625 | if (len == 0) | 
|  | 7626 | return -1; | 
|  | 7627 | advproto = wpabuf_alloc(len); | 
|  | 7628 | if (advproto == NULL) | 
|  | 7629 | return -1; | 
|  | 7630 | if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0) | 
|  | 7631 | goto fail; | 
|  | 7632 |  | 
|  | 7633 | if (end) { | 
|  | 7634 | /* Optional Query Request */ | 
|  | 7635 | pos = end + 1; | 
|  | 7636 | while (*pos == ' ') | 
|  | 7637 | pos++; | 
|  | 7638 |  | 
|  | 7639 | len = os_strlen(pos); | 
|  | 7640 | if (len) { | 
|  | 7641 | if (len & 0x01) | 
|  | 7642 | goto fail; | 
|  | 7643 | len /= 2; | 
|  | 7644 | if (len == 0) | 
|  | 7645 | goto fail; | 
|  | 7646 | query = wpabuf_alloc(len); | 
|  | 7647 | if (query == NULL) | 
|  | 7648 | goto fail; | 
|  | 7649 | if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0) | 
|  | 7650 | goto fail; | 
|  | 7651 | } | 
|  | 7652 | } | 
|  | 7653 |  | 
|  | 7654 | ret = gas_send_request(wpa_s, dst_addr, advproto, query); | 
|  | 7655 |  | 
|  | 7656 | fail: | 
|  | 7657 | wpabuf_free(advproto); | 
|  | 7658 | wpabuf_free(query); | 
|  | 7659 |  | 
|  | 7660 | return ret; | 
|  | 7661 | } | 
|  | 7662 |  | 
|  | 7663 |  | 
|  | 7664 | static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf, | 
|  | 7665 | size_t buflen) | 
|  | 7666 | { | 
|  | 7667 | u8 addr[ETH_ALEN]; | 
|  | 7668 | int dialog_token; | 
|  | 7669 | int used; | 
|  | 7670 | char *pos; | 
|  | 7671 | size_t resp_len, start, requested_len; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7672 | struct wpabuf *resp; | 
|  | 7673 | int ret; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7674 |  | 
|  | 7675 | used = hwaddr_aton2(cmd, addr); | 
|  | 7676 | if (used < 0) | 
|  | 7677 | return -1; | 
|  | 7678 |  | 
|  | 7679 | pos = cmd + used; | 
|  | 7680 | while (*pos == ' ') | 
|  | 7681 | pos++; | 
|  | 7682 | dialog_token = atoi(pos); | 
|  | 7683 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7684 | if (wpa_s->last_gas_resp && | 
|  | 7685 | os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 && | 
|  | 7686 | dialog_token == wpa_s->last_gas_dialog_token) | 
|  | 7687 | resp = wpa_s->last_gas_resp; | 
|  | 7688 | else if (wpa_s->prev_gas_resp && | 
|  | 7689 | os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 && | 
|  | 7690 | dialog_token == wpa_s->prev_gas_dialog_token) | 
|  | 7691 | resp = wpa_s->prev_gas_resp; | 
|  | 7692 | else | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7693 | return -1; | 
|  | 7694 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7695 | resp_len = wpabuf_len(resp); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7696 | start = 0; | 
|  | 7697 | requested_len = resp_len; | 
|  | 7698 |  | 
|  | 7699 | pos = os_strchr(pos, ' '); | 
|  | 7700 | if (pos) { | 
|  | 7701 | start = atoi(pos); | 
|  | 7702 | if (start > resp_len) | 
|  | 7703 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); | 
|  | 7704 | pos = os_strchr(pos, ','); | 
|  | 7705 | if (pos == NULL) | 
|  | 7706 | return -1; | 
|  | 7707 | pos++; | 
|  | 7708 | requested_len = atoi(pos); | 
|  | 7709 | if (start + requested_len > resp_len) | 
|  | 7710 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); | 
|  | 7711 | } | 
|  | 7712 |  | 
|  | 7713 | if (requested_len * 2 + 1 > buflen) | 
|  | 7714 | return os_snprintf(buf, buflen, "FAIL-Too long response"); | 
|  | 7715 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7716 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start, | 
|  | 7717 | requested_len); | 
|  | 7718 |  | 
|  | 7719 | if (start + requested_len == resp_len) { | 
|  | 7720 | /* | 
|  | 7721 | * Free memory by dropping the response after it has been | 
|  | 7722 | * fetched. | 
|  | 7723 | */ | 
|  | 7724 | if (resp == wpa_s->prev_gas_resp) { | 
|  | 7725 | wpabuf_free(wpa_s->prev_gas_resp); | 
|  | 7726 | wpa_s->prev_gas_resp = NULL; | 
|  | 7727 | } else { | 
|  | 7728 | wpabuf_free(wpa_s->last_gas_resp); | 
|  | 7729 | wpa_s->last_gas_resp = NULL; | 
|  | 7730 | } | 
|  | 7731 | } | 
|  | 7732 |  | 
|  | 7733 | return ret; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7734 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7735 | #endif /* CONFIG_INTERWORKING */ | 
|  | 7736 |  | 
|  | 7737 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7738 | #ifdef CONFIG_HS20 | 
|  | 7739 |  | 
|  | 7740 | static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst) | 
|  | 7741 | { | 
|  | 7742 | u8 dst_addr[ETH_ALEN]; | 
|  | 7743 | int used; | 
|  | 7744 | char *pos; | 
|  | 7745 | u32 subtypes = 0; | 
|  | 7746 |  | 
|  | 7747 | used = hwaddr_aton2(dst, dst_addr); | 
|  | 7748 | if (used < 0) | 
|  | 7749 | return -1; | 
|  | 7750 | pos = dst + used; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7751 | if (*pos == ' ') | 
|  | 7752 | pos++; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7753 | for (;;) { | 
|  | 7754 | int num = atoi(pos); | 
|  | 7755 | if (num <= 0 || num > 31) | 
|  | 7756 | return -1; | 
|  | 7757 | subtypes |= BIT(num); | 
|  | 7758 | pos = os_strchr(pos + 1, ','); | 
|  | 7759 | if (pos == NULL) | 
|  | 7760 | break; | 
|  | 7761 | pos++; | 
|  | 7762 | } | 
|  | 7763 |  | 
|  | 7764 | if (subtypes == 0) | 
|  | 7765 | return -1; | 
|  | 7766 |  | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7767 | 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] | 7768 | } | 
|  | 7769 |  | 
|  | 7770 |  | 
|  | 7771 | static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s, | 
|  | 7772 | const u8 *addr, const char *realm) | 
|  | 7773 | { | 
|  | 7774 | u8 *buf; | 
|  | 7775 | size_t rlen, len; | 
|  | 7776 | int ret; | 
|  | 7777 |  | 
|  | 7778 | rlen = os_strlen(realm); | 
|  | 7779 | len = 3 + rlen; | 
|  | 7780 | buf = os_malloc(len); | 
|  | 7781 | if (buf == NULL) | 
|  | 7782 | return -1; | 
|  | 7783 | buf[0] = 1; /* NAI Home Realm Count */ | 
|  | 7784 | buf[1] = 0; /* Formatted in accordance with RFC 4282 */ | 
|  | 7785 | buf[2] = rlen; | 
|  | 7786 | os_memcpy(buf + 3, realm, rlen); | 
|  | 7787 |  | 
|  | 7788 | ret = hs20_anqp_send_req(wpa_s, addr, | 
|  | 7789 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7790 | buf, len, 0); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7791 |  | 
|  | 7792 | os_free(buf); | 
|  | 7793 |  | 
|  | 7794 | return ret; | 
|  | 7795 | } | 
|  | 7796 |  | 
|  | 7797 |  | 
|  | 7798 | static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s, | 
|  | 7799 | char *dst) | 
|  | 7800 | { | 
|  | 7801 | struct wpa_cred *cred = wpa_s->conf->cred; | 
|  | 7802 | u8 dst_addr[ETH_ALEN]; | 
|  | 7803 | int used; | 
|  | 7804 | u8 *buf; | 
|  | 7805 | size_t len; | 
|  | 7806 | int ret; | 
|  | 7807 |  | 
|  | 7808 | used = hwaddr_aton2(dst, dst_addr); | 
|  | 7809 | if (used < 0) | 
|  | 7810 | return -1; | 
|  | 7811 |  | 
|  | 7812 | while (dst[used] == ' ') | 
|  | 7813 | used++; | 
|  | 7814 | if (os_strncmp(dst + used, "realm=", 6) == 0) | 
|  | 7815 | return hs20_nai_home_realm_list(wpa_s, dst_addr, | 
|  | 7816 | dst + used + 6); | 
|  | 7817 |  | 
|  | 7818 | len = os_strlen(dst + used); | 
|  | 7819 |  | 
|  | 7820 | if (len == 0 && cred && cred->realm) | 
|  | 7821 | return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm); | 
|  | 7822 |  | 
| Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 7823 | if (len & 1) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7824 | return -1; | 
|  | 7825 | len /= 2; | 
|  | 7826 | buf = os_malloc(len); | 
|  | 7827 | if (buf == NULL) | 
|  | 7828 | return -1; | 
|  | 7829 | if (hexstr2bin(dst + used, buf, len) < 0) { | 
|  | 7830 | os_free(buf); | 
|  | 7831 | return -1; | 
|  | 7832 | } | 
|  | 7833 |  | 
|  | 7834 | ret = hs20_anqp_send_req(wpa_s, dst_addr, | 
|  | 7835 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7836 | buf, len, 0); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7837 | os_free(buf); | 
|  | 7838 |  | 
|  | 7839 | return ret; | 
|  | 7840 | } | 
|  | 7841 |  | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 7842 |  | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7843 | static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply, | 
|  | 7844 | int buflen) | 
|  | 7845 | { | 
|  | 7846 | u8 dst_addr[ETH_ALEN]; | 
|  | 7847 | int used; | 
|  | 7848 | char *ctx = NULL, *icon, *poffset, *psize; | 
|  | 7849 |  | 
|  | 7850 | used = hwaddr_aton2(cmd, dst_addr); | 
|  | 7851 | if (used < 0) | 
|  | 7852 | return -1; | 
|  | 7853 | cmd += used; | 
|  | 7854 |  | 
|  | 7855 | icon = str_token(cmd, " ", &ctx); | 
|  | 7856 | poffset = str_token(cmd, " ", &ctx); | 
|  | 7857 | psize = str_token(cmd, " ", &ctx); | 
|  | 7858 | if (!icon || !poffset || !psize) | 
|  | 7859 | return -1; | 
|  | 7860 |  | 
|  | 7861 | wpa_s->fetch_osu_icon_in_progress = 0; | 
|  | 7862 | return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize), | 
|  | 7863 | reply, buflen); | 
|  | 7864 | } | 
|  | 7865 |  | 
|  | 7866 |  | 
|  | 7867 | static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 7868 | { | 
|  | 7869 | u8 dst_addr[ETH_ALEN]; | 
|  | 7870 | int used; | 
|  | 7871 | char *icon; | 
|  | 7872 |  | 
|  | 7873 | if (!cmd[0]) | 
|  | 7874 | return hs20_del_icon(wpa_s, NULL, NULL); | 
|  | 7875 |  | 
|  | 7876 | used = hwaddr_aton2(cmd, dst_addr); | 
|  | 7877 | if (used < 0) | 
|  | 7878 | return -1; | 
|  | 7879 |  | 
|  | 7880 | while (cmd[used] == ' ') | 
|  | 7881 | used++; | 
|  | 7882 | icon = cmd[used] ? &cmd[used] : NULL; | 
|  | 7883 |  | 
|  | 7884 | return hs20_del_icon(wpa_s, dst_addr, icon); | 
|  | 7885 | } | 
|  | 7886 |  | 
|  | 7887 |  | 
|  | 7888 | 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] | 7889 | { | 
|  | 7890 | u8 dst_addr[ETH_ALEN]; | 
|  | 7891 | int used; | 
|  | 7892 | char *icon; | 
|  | 7893 |  | 
|  | 7894 | used = hwaddr_aton2(cmd, dst_addr); | 
|  | 7895 | if (used < 0) | 
|  | 7896 | return -1; | 
|  | 7897 |  | 
|  | 7898 | while (cmd[used] == ' ') | 
|  | 7899 | used++; | 
|  | 7900 | icon = &cmd[used]; | 
|  | 7901 |  | 
|  | 7902 | wpa_s->fetch_osu_icon_in_progress = 0; | 
|  | 7903 | 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] | 7904 | (u8 *) icon, os_strlen(icon), inmem); | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 7905 | } | 
|  | 7906 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7907 | #endif /* CONFIG_HS20 */ | 
|  | 7908 |  | 
|  | 7909 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7910 | #ifdef CONFIG_AUTOSCAN | 
|  | 7911 |  | 
|  | 7912 | static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s, | 
|  | 7913 | char *cmd) | 
|  | 7914 | { | 
|  | 7915 | enum wpa_states state = wpa_s->wpa_state; | 
|  | 7916 | char *new_params = NULL; | 
|  | 7917 |  | 
|  | 7918 | if (os_strlen(cmd) > 0) { | 
|  | 7919 | new_params = os_strdup(cmd); | 
|  | 7920 | if (new_params == NULL) | 
|  | 7921 | return -1; | 
|  | 7922 | } | 
|  | 7923 |  | 
|  | 7924 | os_free(wpa_s->conf->autoscan); | 
|  | 7925 | wpa_s->conf->autoscan = new_params; | 
|  | 7926 |  | 
|  | 7927 | if (wpa_s->conf->autoscan == NULL) | 
|  | 7928 | autoscan_deinit(wpa_s); | 
|  | 7929 | else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) | 
|  | 7930 | autoscan_init(wpa_s, 1); | 
|  | 7931 | else if (state == WPA_SCANNING) | 
|  | 7932 | wpa_supplicant_reinit_autoscan(wpa_s); | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 7933 | else | 
|  | 7934 | wpa_printf(MSG_DEBUG, "No autoscan update in state %s", | 
|  | 7935 | wpa_supplicant_state_txt(state)); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7936 |  | 
|  | 7937 | return 0; | 
|  | 7938 | } | 
|  | 7939 |  | 
|  | 7940 | #endif /* CONFIG_AUTOSCAN */ | 
|  | 7941 |  | 
|  | 7942 |  | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7943 | #ifdef CONFIG_WNM | 
|  | 7944 |  | 
|  | 7945 | static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 7946 | { | 
|  | 7947 | int enter; | 
|  | 7948 | int intval = 0; | 
|  | 7949 | char *pos; | 
|  | 7950 | int ret; | 
|  | 7951 | struct wpabuf *tfs_req = NULL; | 
|  | 7952 |  | 
|  | 7953 | if (os_strncmp(cmd, "enter", 5) == 0) | 
|  | 7954 | enter = 1; | 
|  | 7955 | else if (os_strncmp(cmd, "exit", 4) == 0) | 
|  | 7956 | enter = 0; | 
|  | 7957 | else | 
|  | 7958 | return -1; | 
|  | 7959 |  | 
|  | 7960 | pos = os_strstr(cmd, " interval="); | 
|  | 7961 | if (pos) | 
|  | 7962 | intval = atoi(pos + 10); | 
|  | 7963 |  | 
|  | 7964 | pos = os_strstr(cmd, " tfs_req="); | 
|  | 7965 | if (pos) { | 
|  | 7966 | char *end; | 
|  | 7967 | size_t len; | 
|  | 7968 | pos += 9; | 
|  | 7969 | end = os_strchr(pos, ' '); | 
|  | 7970 | if (end) | 
|  | 7971 | len = end - pos; | 
|  | 7972 | else | 
|  | 7973 | len = os_strlen(pos); | 
|  | 7974 | if (len & 1) | 
|  | 7975 | return -1; | 
|  | 7976 | len /= 2; | 
|  | 7977 | tfs_req = wpabuf_alloc(len); | 
|  | 7978 | if (tfs_req == NULL) | 
|  | 7979 | return -1; | 
|  | 7980 | if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) { | 
|  | 7981 | wpabuf_free(tfs_req); | 
|  | 7982 | return -1; | 
|  | 7983 | } | 
|  | 7984 | } | 
|  | 7985 |  | 
|  | 7986 | ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER : | 
|  | 7987 | WNM_SLEEP_MODE_EXIT, intval, | 
|  | 7988 | tfs_req); | 
|  | 7989 | wpabuf_free(tfs_req); | 
|  | 7990 |  | 
|  | 7991 | return ret; | 
|  | 7992 | } | 
|  | 7993 |  | 
| Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 7994 |  | 
|  | 7995 | static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 7996 | { | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7997 | int query_reason, list = 0; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7998 | char *btm_candidates = NULL; | 
| Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 7999 |  | 
|  | 8000 | query_reason = atoi(cmd); | 
|  | 8001 |  | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8002 | cmd = os_strchr(cmd, ' '); | 
|  | 8003 | if (cmd) { | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8004 | if (os_strncmp(cmd, " list", 5) == 0) | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8005 | list = 1; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8006 | else | 
|  | 8007 | btm_candidates = cmd; | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8008 | } | 
| Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 8009 |  | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8010 | wpa_printf(MSG_DEBUG, | 
|  | 8011 | "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s", | 
|  | 8012 | query_reason, list ? " candidate list" : ""); | 
|  | 8013 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8014 | return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason, | 
|  | 8015 | btm_candidates, | 
|  | 8016 | list); | 
| Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 8017 | } | 
|  | 8018 |  | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 8019 |  | 
|  | 8020 | static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s, | 
|  | 8021 | char *cmd) | 
|  | 8022 | { | 
|  | 8023 | struct wpabuf *elems; | 
|  | 8024 | int ret; | 
|  | 8025 |  | 
|  | 8026 | elems = wpabuf_parse_bin(cmd); | 
|  | 8027 | if (!elems) | 
|  | 8028 | return -1; | 
|  | 8029 |  | 
|  | 8030 | ret = wnm_send_coloc_intf_report(wpa_s, 0, elems); | 
|  | 8031 | wpabuf_free(elems); | 
|  | 8032 | return ret; | 
|  | 8033 | } | 
|  | 8034 |  | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8035 | #endif /* CONFIG_WNM */ | 
|  | 8036 |  | 
|  | 8037 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8038 | static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, | 
|  | 8039 | size_t buflen) | 
|  | 8040 | { | 
|  | 8041 | struct wpa_signal_info si; | 
|  | 8042 | int ret; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8043 | char *pos, *end; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8044 |  | 
|  | 8045 | ret = wpa_drv_signal_poll(wpa_s, &si); | 
|  | 8046 | if (ret) | 
|  | 8047 | return -1; | 
|  | 8048 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8049 | pos = buf; | 
|  | 8050 | end = buf + buflen; | 
|  | 8051 |  | 
|  | 8052 | ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n" | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8053 | "NOISE=%d\nFREQUENCY=%u\n", | 
|  | 8054 | si.current_signal, si.current_txrate / 1000, | 
|  | 8055 | si.current_noise, si.frequency); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8056 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8057 | return -1; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8058 | pos += ret; | 
|  | 8059 |  | 
|  | 8060 | if (si.chanwidth != CHAN_WIDTH_UNKNOWN) { | 
|  | 8061 | ret = os_snprintf(pos, end - pos, "WIDTH=%s\n", | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8062 | channel_width_to_string(si.chanwidth)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8063 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8064 | return -1; | 
|  | 8065 | pos += ret; | 
|  | 8066 | } | 
|  | 8067 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8068 | if (si.center_frq1 > 0) { | 
|  | 8069 | ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n", | 
|  | 8070 | si.center_frq1); | 
|  | 8071 | if (os_snprintf_error(end - pos, ret)) | 
|  | 8072 | return -1; | 
|  | 8073 | pos += ret; | 
|  | 8074 | } | 
|  | 8075 |  | 
|  | 8076 | if (si.center_frq2 > 0) { | 
|  | 8077 | ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n", | 
|  | 8078 | si.center_frq2); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8079 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8080 | return -1; | 
|  | 8081 | pos += ret; | 
|  | 8082 | } | 
|  | 8083 |  | 
|  | 8084 | if (si.avg_signal) { | 
|  | 8085 | ret = os_snprintf(pos, end - pos, | 
|  | 8086 | "AVG_RSSI=%d\n", si.avg_signal); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8087 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8088 | return -1; | 
|  | 8089 | pos += ret; | 
|  | 8090 | } | 
|  | 8091 |  | 
| Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 8092 | if (si.avg_beacon_signal) { | 
|  | 8093 | ret = os_snprintf(pos, end - pos, | 
|  | 8094 | "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal); | 
|  | 8095 | if (os_snprintf_error(end - pos, ret)) | 
|  | 8096 | return -1; | 
|  | 8097 | pos += ret; | 
|  | 8098 | } | 
|  | 8099 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8100 | return pos - buf; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8101 | } | 
|  | 8102 |  | 
| Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 8103 |  | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 8104 | static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s, | 
|  | 8105 | const char *cmd) | 
|  | 8106 | { | 
|  | 8107 | const char *pos; | 
|  | 8108 | int threshold = 0; | 
|  | 8109 | int hysteresis = 0; | 
|  | 8110 |  | 
|  | 8111 | if (wpa_s->bgscan && wpa_s->bgscan_priv) { | 
|  | 8112 | wpa_printf(MSG_DEBUG, | 
|  | 8113 | "Reject SIGNAL_MONITOR command - bgscan is active"); | 
|  | 8114 | return -1; | 
|  | 8115 | } | 
|  | 8116 | pos = os_strstr(cmd, "THRESHOLD="); | 
|  | 8117 | if (pos) | 
|  | 8118 | threshold = atoi(pos + 10); | 
|  | 8119 | pos = os_strstr(cmd, "HYSTERESIS="); | 
|  | 8120 | if (pos) | 
|  | 8121 | hysteresis = atoi(pos + 11); | 
|  | 8122 | return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis); | 
|  | 8123 | } | 
|  | 8124 |  | 
|  | 8125 |  | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8126 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 8127 | int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s, | 
|  | 8128 | enum wpa_driver_if_type if_type, | 
|  | 8129 | unsigned int *num, | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8130 | struct weighted_pcl *freq_list) | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8131 | { | 
|  | 8132 | char *pos = wpa_s->get_pref_freq_list_override; | 
|  | 8133 | char *end; | 
|  | 8134 | unsigned int count = 0; | 
|  | 8135 |  | 
|  | 8136 | /* Override string format: | 
|  | 8137 | *  <if_type1>:<freq1>,<freq2>,... <if_type2>:... */ | 
|  | 8138 |  | 
|  | 8139 | while (pos) { | 
|  | 8140 | if (atoi(pos) == (int) if_type) | 
|  | 8141 | break; | 
|  | 8142 | pos = os_strchr(pos, ' '); | 
|  | 8143 | if (pos) | 
|  | 8144 | pos++; | 
|  | 8145 | } | 
|  | 8146 | if (!pos) | 
|  | 8147 | return -1; | 
|  | 8148 | pos = os_strchr(pos, ':'); | 
|  | 8149 | if (!pos) | 
|  | 8150 | return -1; | 
|  | 8151 | pos++; | 
|  | 8152 | end = os_strchr(pos, ' '); | 
|  | 8153 | while (pos && (!end || pos < end) && count < *num) { | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8154 | freq_list[count].freq = atoi(pos); | 
|  | 8155 | freq_list[count++].flag = WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI; | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8156 | pos = os_strchr(pos, ','); | 
|  | 8157 | if (pos) | 
|  | 8158 | pos++; | 
|  | 8159 | } | 
|  | 8160 |  | 
|  | 8161 | *num = count; | 
|  | 8162 | return 0; | 
|  | 8163 | } | 
|  | 8164 | #endif /* CONFIG_TESTING_OPTIONS */ | 
|  | 8165 |  | 
|  | 8166 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8167 | static int wpas_ctrl_iface_get_pref_freq_list( | 
|  | 8168 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) | 
|  | 8169 | { | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8170 | unsigned int num = 100, i; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8171 | int ret; | 
|  | 8172 | enum wpa_driver_if_type iface_type; | 
|  | 8173 | char *pos, *end; | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8174 | struct weighted_pcl freq_list[100]; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8175 |  | 
|  | 8176 | pos = buf; | 
|  | 8177 | end = buf + buflen; | 
|  | 8178 |  | 
|  | 8179 | /* buf: "<interface_type>" */ | 
|  | 8180 | if (os_strcmp(cmd, "STATION") == 0) | 
|  | 8181 | iface_type = WPA_IF_STATION; | 
|  | 8182 | else if (os_strcmp(cmd, "AP") == 0) | 
|  | 8183 | iface_type = WPA_IF_AP_BSS; | 
|  | 8184 | else if (os_strcmp(cmd, "P2P_GO") == 0) | 
|  | 8185 | iface_type = WPA_IF_P2P_GO; | 
|  | 8186 | else if (os_strcmp(cmd, "P2P_CLIENT") == 0) | 
|  | 8187 | iface_type = WPA_IF_P2P_CLIENT; | 
|  | 8188 | else if (os_strcmp(cmd, "IBSS") == 0) | 
|  | 8189 | iface_type = WPA_IF_IBSS; | 
|  | 8190 | else if (os_strcmp(cmd, "TDLS") == 0) | 
|  | 8191 | iface_type = WPA_IF_TDLS; | 
|  | 8192 | else | 
|  | 8193 | return -1; | 
|  | 8194 |  | 
|  | 8195 | wpa_printf(MSG_DEBUG, | 
|  | 8196 | "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)", | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8197 | iface_type, cmd); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8198 |  | 
|  | 8199 | ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list); | 
|  | 8200 | if (ret) | 
|  | 8201 | return -1; | 
|  | 8202 |  | 
|  | 8203 | for (i = 0; i < num; i++) { | 
|  | 8204 | ret = os_snprintf(pos, end - pos, "%s%u", | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8205 | i > 0 ? "," : "", freq_list[i].freq); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8206 | if (os_snprintf_error(end - pos, ret)) | 
|  | 8207 | return -1; | 
|  | 8208 | pos += ret; | 
|  | 8209 | } | 
|  | 8210 |  | 
|  | 8211 | return pos - buf; | 
|  | 8212 | } | 
|  | 8213 |  | 
|  | 8214 |  | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8215 | static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s, | 
|  | 8216 | char *buf, size_t buflen) | 
|  | 8217 | { | 
|  | 8218 | int ret, i; | 
|  | 8219 | char *pos, *end; | 
|  | 8220 |  | 
|  | 8221 | ret = os_snprintf(buf, buflen, "%016llX:\n", | 
|  | 8222 | (long long unsigned) wpa_s->drv_flags); | 
|  | 8223 | if (os_snprintf_error(buflen, ret)) | 
|  | 8224 | return -1; | 
|  | 8225 |  | 
|  | 8226 | pos = buf + ret; | 
|  | 8227 | end = buf + buflen; | 
|  | 8228 |  | 
|  | 8229 | for (i = 0; i < 64; i++) { | 
|  | 8230 | if (wpa_s->drv_flags & (1LLU << i)) { | 
|  | 8231 | ret = os_snprintf(pos, end - pos, "%s\n", | 
|  | 8232 | driver_flag_to_string(1LLU << i)); | 
|  | 8233 | if (os_snprintf_error(end - pos, ret)) | 
|  | 8234 | return -1; | 
|  | 8235 | pos += ret; | 
|  | 8236 | } | 
|  | 8237 | } | 
|  | 8238 |  | 
|  | 8239 | return pos - buf; | 
|  | 8240 | } | 
|  | 8241 |  | 
|  | 8242 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8243 | static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s, | 
|  | 8244 | char *buf, size_t buflen) | 
|  | 8245 | { | 
|  | 8246 | int ret, i; | 
|  | 8247 | char *pos, *end; | 
|  | 8248 |  | 
|  | 8249 | ret = os_snprintf(buf, buflen, "%016llX:\n", | 
|  | 8250 | (long long unsigned) wpa_s->drv_flags2); | 
|  | 8251 | if (os_snprintf_error(buflen, ret)) | 
|  | 8252 | return -1; | 
|  | 8253 |  | 
|  | 8254 | pos = buf + ret; | 
|  | 8255 | end = buf + buflen; | 
|  | 8256 |  | 
|  | 8257 | for (i = 0; i < 64; i++) { | 
|  | 8258 | if (wpa_s->drv_flags2 & (1LLU << i)) { | 
|  | 8259 | ret = os_snprintf(pos, end - pos, "%s\n", | 
|  | 8260 | driver_flag2_to_string(1LLU << i)); | 
|  | 8261 | if (os_snprintf_error(end - pos, ret)) | 
|  | 8262 | return -1; | 
|  | 8263 | pos += ret; | 
|  | 8264 | } | 
|  | 8265 | } | 
|  | 8266 |  | 
|  | 8267 | return pos - buf; | 
|  | 8268 | } | 
|  | 8269 |  | 
|  | 8270 |  | 
| Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 8271 | static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf, | 
|  | 8272 | size_t buflen) | 
|  | 8273 | { | 
|  | 8274 | struct hostap_sta_driver_data sta; | 
|  | 8275 | int ret; | 
|  | 8276 |  | 
|  | 8277 | ret = wpa_drv_pktcnt_poll(wpa_s, &sta); | 
|  | 8278 | if (ret) | 
|  | 8279 | return -1; | 
|  | 8280 |  | 
|  | 8281 | ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n", | 
| Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 8282 | sta.tx_packets, sta.tx_retry_failed, sta.rx_packets); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8283 | if (os_snprintf_error(buflen, ret)) | 
| Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 8284 | return -1; | 
|  | 8285 | return ret; | 
|  | 8286 | } | 
|  | 8287 |  | 
|  | 8288 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8289 | #ifdef ANDROID | 
| Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 8290 | static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 8291 | char *buf, size_t buflen) | 
|  | 8292 | { | 
|  | 8293 | int ret; | 
|  | 8294 |  | 
|  | 8295 | ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen); | 
| Dmitry Shmidt | 9432e12 | 2013-09-12 12:39:30 -0700 | [diff] [blame] | 8296 | if (ret == 0) { | 
|  | 8297 | if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) { | 
|  | 8298 | struct p2p_data *p2p = wpa_s->global->p2p; | 
|  | 8299 | if (p2p) { | 
|  | 8300 | char country[3]; | 
|  | 8301 | country[0] = cmd[8]; | 
|  | 8302 | country[1] = cmd[9]; | 
|  | 8303 | country[2] = 0x04; | 
|  | 8304 | p2p_set_country(p2p, country); | 
|  | 8305 | } | 
|  | 8306 | } | 
| Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8307 | ret = os_snprintf(buf, buflen, "%s\n", "OK"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8308 | if (os_snprintf_error(buflen, ret)) | 
|  | 8309 | ret = -1; | 
| Dmitry Shmidt | 9432e12 | 2013-09-12 12:39:30 -0700 | [diff] [blame] | 8310 | } | 
| Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 8311 | return ret; | 
|  | 8312 | } | 
| Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8313 | #endif /* ANDROID */ | 
| Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 8314 |  | 
| Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 8315 |  | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8316 | static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 8317 | char *buf, size_t buflen) | 
|  | 8318 | { | 
|  | 8319 | int ret; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8320 | char *pos, *temp = NULL; | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8321 | u8 *data = NULL; | 
|  | 8322 | unsigned int vendor_id, subcmd; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8323 | enum nested_attr nested_attr_flag = NESTED_ATTR_UNSPECIFIED; | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8324 | struct wpabuf *reply; | 
|  | 8325 | size_t data_len = 0; | 
|  | 8326 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8327 | /** | 
|  | 8328 | * cmd: <vendor id> <subcommand id> [<hex formatted data>] | 
|  | 8329 | * [nested=<0|1>] | 
|  | 8330 | */ | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8331 | vendor_id = strtoul(cmd, &pos, 16); | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8332 | if (!isblank((unsigned char) *pos)) | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8333 | return -EINVAL; | 
|  | 8334 |  | 
|  | 8335 | subcmd = strtoul(pos, &pos, 10); | 
|  | 8336 |  | 
|  | 8337 | if (*pos != '\0') { | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8338 | if (!isblank((unsigned char) *pos++)) | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8339 | return -EINVAL; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8340 |  | 
|  | 8341 | temp = os_strchr(pos, ' '); | 
|  | 8342 | data_len = temp ? (size_t) (temp - pos) : os_strlen(pos); | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8343 | } | 
|  | 8344 |  | 
|  | 8345 | if (data_len) { | 
|  | 8346 | data_len /= 2; | 
|  | 8347 | data = os_malloc(data_len); | 
|  | 8348 | if (!data) | 
| Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8349 | return -1; | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8350 |  | 
|  | 8351 | if (hexstr2bin(pos, data, data_len)) { | 
|  | 8352 | wpa_printf(MSG_DEBUG, | 
|  | 8353 | "Vendor command: wrong parameter format"); | 
|  | 8354 | os_free(data); | 
|  | 8355 | return -EINVAL; | 
|  | 8356 | } | 
|  | 8357 | } | 
|  | 8358 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8359 | pos = os_strstr(cmd, "nested="); | 
|  | 8360 | if (pos) | 
|  | 8361 | nested_attr_flag = atoi(pos + 7) ? NESTED_ATTR_USED : | 
|  | 8362 | NESTED_ATTR_NOT_USED; | 
|  | 8363 |  | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8364 | reply = wpabuf_alloc((buflen - 1) / 2); | 
|  | 8365 | if (!reply) { | 
|  | 8366 | os_free(data); | 
| Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8367 | return -1; | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8368 | } | 
|  | 8369 |  | 
|  | 8370 | 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] | 8371 | nested_attr_flag, reply); | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8372 |  | 
|  | 8373 | if (ret == 0) | 
|  | 8374 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply), | 
|  | 8375 | wpabuf_len(reply)); | 
|  | 8376 |  | 
|  | 8377 | wpabuf_free(reply); | 
|  | 8378 | os_free(data); | 
|  | 8379 |  | 
|  | 8380 | return ret; | 
|  | 8381 | } | 
|  | 8382 |  | 
|  | 8383 |  | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8384 | static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s) | 
|  | 8385 | { | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8386 | #ifdef CONFIG_P2P | 
|  | 8387 | struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ? | 
|  | 8388 | wpa_s->global->p2p_init_wpa_s : wpa_s; | 
|  | 8389 | #endif /* CONFIG_P2P */ | 
|  | 8390 |  | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8391 | wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state"); | 
|  | 8392 |  | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 8393 | if (wpas_abort_ongoing_scan(wpa_s) == 0) | 
|  | 8394 | wpa_s->ignore_post_flush_scan_res = 1; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8395 |  | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8396 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { | 
|  | 8397 | /* | 
|  | 8398 | * Avoid possible auto connect re-connection on getting | 
|  | 8399 | * disconnected due to state flush. | 
|  | 8400 | */ | 
|  | 8401 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | 
|  | 8402 | } | 
|  | 8403 |  | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8404 | #ifdef CONFIG_P2P | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8405 | wpas_p2p_group_remove(p2p_wpa_s, "*"); | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8406 | wpas_p2p_cancel(p2p_wpa_s); | 
|  | 8407 | p2p_ctrl_flush(p2p_wpa_s); | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8408 | wpas_p2p_service_flush(p2p_wpa_s); | 
|  | 8409 | p2p_wpa_s->global->p2p_disabled = 0; | 
|  | 8410 | p2p_wpa_s->global->p2p_per_sta_psk = 0; | 
|  | 8411 | p2p_wpa_s->conf->num_sec_device_types = 0; | 
|  | 8412 | p2p_wpa_s->p2p_disable_ip_addr_req = 0; | 
|  | 8413 | os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range); | 
|  | 8414 | p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8415 | p2p_wpa_s->global->p2p_go_avoid_freq.num = 0; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8416 | p2p_wpa_s->global->pending_p2ps_group = 0; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8417 | p2p_wpa_s->global->pending_p2ps_group_freq = 0; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8418 | #endif /* CONFIG_P2P */ | 
|  | 8419 |  | 
|  | 8420 | #ifdef CONFIG_WPS_TESTING | 
|  | 8421 | wps_version_number = 0x20; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8422 | wps_testing_stub_cred = 0; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 8423 | wps_corrupt_pkhash = 0; | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8424 | wps_force_auth_types_in_use = 0; | 
|  | 8425 | wps_force_encr_types_in_use = 0; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8426 | #endif /* CONFIG_WPS_TESTING */ | 
|  | 8427 | #ifdef CONFIG_WPS | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8428 | wpa_s->wps_fragment_size = 0; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8429 | wpas_wps_cancel(wpa_s); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8430 | wps_registrar_flush(wpa_s->wps->registrar); | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8431 | #endif /* CONFIG_WPS */ | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8432 | wpa_s->after_wps = 0; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8433 | wpa_s->known_wps_freq = 0; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8434 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8435 | #ifdef CONFIG_DPP | 
|  | 8436 | wpas_dpp_deinit(wpa_s); | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8437 | wpa_s->dpp_init_max_tries = 0; | 
|  | 8438 | wpa_s->dpp_init_retry_time = 0; | 
|  | 8439 | wpa_s->dpp_resp_wait_time = 0; | 
|  | 8440 | wpa_s->dpp_resp_max_tries = 0; | 
|  | 8441 | wpa_s->dpp_resp_retry_time = 0; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8442 | #ifdef CONFIG_DPP2 | 
|  | 8443 | wpas_dpp_chirp_stop(wpa_s); | 
|  | 8444 | wpa_s->dpp_pfs_fallback = 0; | 
|  | 8445 | #endif /* CONFIG_DPP2 */ | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8446 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 8447 | os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN); | 
|  | 8448 | os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN); | 
|  | 8449 | dpp_pkex_ephemeral_key_override_len = 0; | 
|  | 8450 | dpp_protocol_key_override_len = 0; | 
|  | 8451 | dpp_nonce_override_len = 0; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8452 | #ifdef CONFIG_DPP3 | 
|  | 8453 | dpp_version_override = 3; | 
|  | 8454 | #elif defined(CONFIG_DPP2) | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 8455 | dpp_version_override = 2; | 
|  | 8456 | #else /* CONFIG_DPP2 */ | 
|  | 8457 | dpp_version_override = 1; | 
|  | 8458 | #endif /* CONFIG_DPP2 */ | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8459 | #endif /* CONFIG_TESTING_OPTIONS */ | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8460 | #endif /* CONFIG_DPP */ | 
|  | 8461 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8462 | #ifdef CONFIG_TDLS | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8463 | #ifdef CONFIG_TDLS_TESTING | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8464 | tdls_testing = 0; | 
|  | 8465 | #endif /* CONFIG_TDLS_TESTING */ | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8466 | wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL); | 
|  | 8467 | wpa_tdls_enable(wpa_s->wpa, 1); | 
|  | 8468 | #endif /* CONFIG_TDLS */ | 
|  | 8469 |  | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8470 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL); | 
|  | 8471 | wpa_supplicant_stop_countermeasures(wpa_s, NULL); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8472 | wpa_s->last_michael_mic_error.sec = 0; | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8473 |  | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8474 | wpa_s->no_keep_alive = 0; | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 8475 | wpa_s->own_disconnect_req = 0; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8476 | wpa_s->own_reconnect_req = 0; | 
|  | 8477 | wpa_s->deny_ptk0_rekey = 0; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8478 |  | 
|  | 8479 | os_free(wpa_s->disallow_aps_bssid); | 
|  | 8480 | wpa_s->disallow_aps_bssid = NULL; | 
|  | 8481 | wpa_s->disallow_aps_bssid_count = 0; | 
|  | 8482 | os_free(wpa_s->disallow_aps_ssid); | 
|  | 8483 | wpa_s->disallow_aps_ssid = NULL; | 
|  | 8484 | wpa_s->disallow_aps_ssid_count = 0; | 
|  | 8485 |  | 
|  | 8486 | wpa_s->set_sta_uapsd = 0; | 
|  | 8487 | wpa_s->sta_uapsd = 0; | 
|  | 8488 |  | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8489 | wpa_s->consecutive_conn_failures = 0; | 
|  | 8490 |  | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8491 | wpa_drv_radio_disable(wpa_s, 0); | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8492 | wpa_bssid_ignore_clear(wpa_s); | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8493 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all"); | 
|  | 8494 | wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all"); | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 8495 | wpa_config_flush_blobs(wpa_s->conf); | 
| Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 8496 | wpa_s->conf->auto_interworking = 0; | 
|  | 8497 | wpa_s->conf->okc = 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8498 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8499 | ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8500 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); | 
|  | 8501 | rsn_preauth_deinit(wpa_s->wpa); | 
|  | 8502 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8503 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200); | 
|  | 8504 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70); | 
|  | 8505 | wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60); | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 8506 | eapol_sm_notify_logoff(wpa_s->eapol, false); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8507 |  | 
| Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 8508 | radio_remove_works(wpa_s, NULL, 1); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8509 | wpa_s->ext_work_in_progress = 0; | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8510 |  | 
|  | 8511 | wpa_s->next_ssid = NULL; | 
|  | 8512 |  | 
|  | 8513 | #ifdef CONFIG_INTERWORKING | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8514 | #ifdef CONFIG_HS20 | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8515 | hs20_cancel_fetch_osu(wpa_s); | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 8516 | hs20_del_icon(wpa_s, NULL, NULL); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8517 | #endif /* CONFIG_HS20 */ | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8518 | #endif /* CONFIG_INTERWORKING */ | 
| Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 8519 |  | 
|  | 8520 | wpa_s->ext_mgmt_frame_handling = 0; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8521 | wpa_s->ext_eapol_frame_io = 0; | 
|  | 8522 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 8523 | wpa_s->extra_roc_dur = 0; | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8524 | wpa_s->test_failure = WPAS_TEST_FAILURE_NONE; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8525 | wpa_s->p2p_go_csa_on_inv = 0; | 
| Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8526 | wpa_s->ignore_auth_resp = 0; | 
|  | 8527 | wpa_s->ignore_assoc_disallow = 0; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8528 | wpa_s->disable_sa_query = 0; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8529 | wpa_s->testing_resend_assoc = 0; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8530 | wpa_s->ignore_sae_h2e_only = 0; | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8531 | wpa_s->ft_rsnxe_used = 0; | 
| Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8532 | wpa_s->reject_btm_req_reason = 0; | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8533 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL); | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8534 | os_free(wpa_s->get_pref_freq_list_override); | 
|  | 8535 | wpa_s->get_pref_freq_list_override = NULL; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8536 | wpabuf_free(wpa_s->sae_commit_override); | 
|  | 8537 | wpa_s->sae_commit_override = NULL; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8538 | os_free(wpa_s->extra_sae_rejected_groups); | 
|  | 8539 | wpa_s->extra_sae_rejected_groups = NULL; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8540 | wpabuf_free(wpa_s->rsne_override_eapol); | 
|  | 8541 | wpa_s->rsne_override_eapol = NULL; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8542 | wpabuf_free(wpa_s->rsnxe_override_assoc); | 
|  | 8543 | wpa_s->rsnxe_override_assoc = NULL; | 
|  | 8544 | wpabuf_free(wpa_s->rsnxe_override_eapol); | 
|  | 8545 | wpa_s->rsnxe_override_eapol = NULL; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8546 | wpas_clear_driver_signal_override(wpa_s); | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8547 | wpa_s->disable_scs_support = 0; | 
|  | 8548 | wpa_s->disable_mscs_support = 0; | 
|  | 8549 | wpa_s->enable_dscp_policy_capa = 0; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8550 | wpa_s->oci_freq_override_eapol = 0; | 
|  | 8551 | wpa_s->oci_freq_override_saquery_req = 0; | 
|  | 8552 | wpa_s->oci_freq_override_saquery_resp = 0; | 
|  | 8553 | wpa_s->oci_freq_override_eapol_g2 = 0; | 
|  | 8554 | wpa_s->oci_freq_override_ft_assoc = 0; | 
|  | 8555 | wpa_s->oci_freq_override_fils_assoc = 0; | 
|  | 8556 | wpa_s->oci_freq_override_wnm_sleep = 0; | 
| Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 8557 | wpa_s->disable_eapol_g2_tx = 0; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8558 | #ifdef CONFIG_DPP | 
|  | 8559 | os_free(wpa_s->dpp_config_obj_override); | 
|  | 8560 | wpa_s->dpp_config_obj_override = NULL; | 
|  | 8561 | os_free(wpa_s->dpp_discovery_override); | 
|  | 8562 | wpa_s->dpp_discovery_override = NULL; | 
|  | 8563 | os_free(wpa_s->dpp_groups_override); | 
|  | 8564 | wpa_s->dpp_groups_override = NULL; | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8565 | wpa_s->dpp_ignore_netaccesskey_mismatch = 0; | 
|  | 8566 | wpa_s->dpp_discard_public_action = 0; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8567 | dpp_test = DPP_TEST_DISABLED; | 
|  | 8568 | #endif /* CONFIG_DPP */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8569 | #endif /* CONFIG_TESTING_OPTIONS */ | 
|  | 8570 |  | 
|  | 8571 | wpa_s->disconnected = 0; | 
|  | 8572 | os_free(wpa_s->next_scan_freqs); | 
|  | 8573 | wpa_s->next_scan_freqs = NULL; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8574 | os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN); | 
|  | 8575 | wpa_s->next_scan_bssid_wildcard_ssid = 0; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8576 | os_free(wpa_s->select_network_scan_freqs); | 
|  | 8577 | wpa_s->select_network_scan_freqs = NULL; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8578 | os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data)); | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8579 |  | 
|  | 8580 | wpa_bss_flush(wpa_s); | 
|  | 8581 | if (!dl_list_empty(&wpa_s->bss)) { | 
|  | 8582 | wpa_printf(MSG_DEBUG, | 
|  | 8583 | "BSS table not empty after flush: %u entries, current_bss=%p bssid=" | 
|  | 8584 | MACSTR " pending_bssid=" MACSTR, | 
|  | 8585 | dl_list_len(&wpa_s->bss), wpa_s->current_bss, | 
|  | 8586 | MAC2STR(wpa_s->bssid), | 
|  | 8587 | MAC2STR(wpa_s->pending_bssid)); | 
|  | 8588 | } | 
| Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8589 |  | 
|  | 8590 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); | 
| Dmitry Shmidt | b70d0bb | 2015-11-16 10:43:06 -0800 | [diff] [blame] | 8591 | wpa_s->wnmsleep_used = 0; | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8592 |  | 
|  | 8593 | #ifdef CONFIG_SME | 
|  | 8594 | wpa_s->sme.last_unprot_disconnect.sec = 0; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8595 | wpa_s->sme.auth_alg = 0; | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8596 | #endif /* CONFIG_SME */ | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8597 |  | 
|  | 8598 | wpabuf_free(wpa_s->ric_ies); | 
|  | 8599 | wpa_s->ric_ies = NULL; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8600 |  | 
|  | 8601 | wpa_supplicant_update_channel_list(wpa_s, NULL); | 
|  | 8602 |  | 
|  | 8603 | free_bss_tmp_disallowed(wpa_s); | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8604 |  | 
|  | 8605 | os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data)); | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8606 |  | 
|  | 8607 | #ifdef CONFIG_PASN | 
|  | 8608 | wpas_pasn_auth_stop(wpa_s); | 
|  | 8609 | #endif /* CONFIG_PASN */ | 
|  | 8610 |  | 
|  | 8611 | if (wpa_s->mac_addr_changed && wpa_s->conf->mac_addr == 0) | 
|  | 8612 | wpas_restore_permanent_mac_addr(wpa_s); | 
| Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 8613 |  | 
|  | 8614 | wpa_s->conf->ignore_old_scan_res = 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8615 | } | 
|  | 8616 |  | 
|  | 8617 |  | 
|  | 8618 | static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s, | 
|  | 8619 | char *buf, size_t buflen) | 
|  | 8620 | { | 
|  | 8621 | struct wpa_radio_work *work; | 
|  | 8622 | char *pos, *end; | 
|  | 8623 | struct os_reltime now, diff; | 
|  | 8624 |  | 
|  | 8625 | pos = buf; | 
|  | 8626 | end = buf + buflen; | 
|  | 8627 |  | 
|  | 8628 | os_get_reltime(&now); | 
|  | 8629 |  | 
|  | 8630 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) | 
|  | 8631 | { | 
|  | 8632 | int ret; | 
|  | 8633 |  | 
|  | 8634 | os_reltime_sub(&now, &work->time, &diff); | 
|  | 8635 | ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n", | 
|  | 8636 | work->type, work->wpa_s->ifname, work->freq, | 
|  | 8637 | work->started, diff.sec, diff.usec); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8638 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8639 | break; | 
|  | 8640 | pos += ret; | 
|  | 8641 | } | 
|  | 8642 |  | 
|  | 8643 | return pos - buf; | 
|  | 8644 | } | 
|  | 8645 |  | 
|  | 8646 |  | 
|  | 8647 | static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx) | 
|  | 8648 | { | 
|  | 8649 | struct wpa_radio_work *work = eloop_ctx; | 
|  | 8650 | struct wpa_external_work *ework = work->ctx; | 
|  | 8651 |  | 
|  | 8652 | wpa_dbg(work->wpa_s, MSG_DEBUG, | 
|  | 8653 | "Timing out external radio work %u (%s)", | 
|  | 8654 | ework->id, work->type); | 
|  | 8655 | 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] | 8656 | work->wpa_s->ext_work_in_progress = 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8657 | radio_work_done(work); | 
| Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8658 | os_free(ework); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8659 | } | 
|  | 8660 |  | 
|  | 8661 |  | 
|  | 8662 | static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit) | 
|  | 8663 | { | 
|  | 8664 | struct wpa_external_work *ework = work->ctx; | 
|  | 8665 |  | 
|  | 8666 | if (deinit) { | 
| Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 8667 | if (work->started) | 
|  | 8668 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, | 
|  | 8669 | work, NULL); | 
|  | 8670 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8671 | /* | 
|  | 8672 | * work->type points to a buffer in ework, so need to replace | 
|  | 8673 | * that here with a fixed string to avoid use of freed memory | 
|  | 8674 | * in debug prints. | 
|  | 8675 | */ | 
|  | 8676 | work->type = "freed-ext-work"; | 
|  | 8677 | work->ctx = NULL; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8678 | os_free(ework); | 
|  | 8679 | return; | 
|  | 8680 | } | 
|  | 8681 |  | 
|  | 8682 | wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)", | 
|  | 8683 | ework->id, ework->type); | 
|  | 8684 | 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] | 8685 | work->wpa_s->ext_work_in_progress = 1; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8686 | if (!ework->timeout) | 
|  | 8687 | ework->timeout = 10; | 
|  | 8688 | eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout, | 
|  | 8689 | work, NULL); | 
|  | 8690 | } | 
|  | 8691 |  | 
|  | 8692 |  | 
|  | 8693 | static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 8694 | char *buf, size_t buflen) | 
|  | 8695 | { | 
|  | 8696 | struct wpa_external_work *ework; | 
|  | 8697 | char *pos, *pos2; | 
|  | 8698 | size_t type_len; | 
|  | 8699 | int ret; | 
|  | 8700 | unsigned int freq = 0; | 
|  | 8701 |  | 
|  | 8702 | /* format: <name> [freq=<MHz>] [timeout=<seconds>] */ | 
|  | 8703 |  | 
|  | 8704 | ework = os_zalloc(sizeof(*ework)); | 
|  | 8705 | if (ework == NULL) | 
|  | 8706 | return -1; | 
|  | 8707 |  | 
|  | 8708 | pos = os_strchr(cmd, ' '); | 
|  | 8709 | if (pos) { | 
|  | 8710 | type_len = pos - cmd; | 
|  | 8711 | pos++; | 
|  | 8712 |  | 
|  | 8713 | pos2 = os_strstr(pos, "freq="); | 
|  | 8714 | if (pos2) | 
|  | 8715 | freq = atoi(pos2 + 5); | 
|  | 8716 |  | 
|  | 8717 | pos2 = os_strstr(pos, "timeout="); | 
|  | 8718 | if (pos2) | 
|  | 8719 | ework->timeout = atoi(pos2 + 8); | 
|  | 8720 | } else { | 
|  | 8721 | type_len = os_strlen(cmd); | 
|  | 8722 | } | 
|  | 8723 | if (4 + type_len >= sizeof(ework->type)) | 
|  | 8724 | type_len = sizeof(ework->type) - 4 - 1; | 
|  | 8725 | os_strlcpy(ework->type, "ext:", sizeof(ework->type)); | 
|  | 8726 | os_memcpy(ework->type + 4, cmd, type_len); | 
|  | 8727 | ework->type[4 + type_len] = '\0'; | 
|  | 8728 |  | 
|  | 8729 | wpa_s->ext_work_id++; | 
|  | 8730 | if (wpa_s->ext_work_id == 0) | 
|  | 8731 | wpa_s->ext_work_id++; | 
|  | 8732 | ework->id = wpa_s->ext_work_id; | 
|  | 8733 |  | 
|  | 8734 | if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb, | 
|  | 8735 | ework) < 0) { | 
|  | 8736 | os_free(ework); | 
|  | 8737 | return -1; | 
|  | 8738 | } | 
|  | 8739 |  | 
|  | 8740 | ret = os_snprintf(buf, buflen, "%u", ework->id); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8741 | if (os_snprintf_error(buflen, ret)) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8742 | return -1; | 
|  | 8743 | return ret; | 
|  | 8744 | } | 
|  | 8745 |  | 
|  | 8746 |  | 
|  | 8747 | static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 8748 | { | 
|  | 8749 | struct wpa_radio_work *work; | 
|  | 8750 | unsigned int id = atoi(cmd); | 
|  | 8751 |  | 
|  | 8752 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) | 
|  | 8753 | { | 
|  | 8754 | struct wpa_external_work *ework; | 
|  | 8755 |  | 
|  | 8756 | if (os_strncmp(work->type, "ext:", 4) != 0) | 
|  | 8757 | continue; | 
|  | 8758 | ework = work->ctx; | 
|  | 8759 | if (id && ework->id != id) | 
|  | 8760 | continue; | 
|  | 8761 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 8762 | "Completed external radio work %u (%s)", | 
|  | 8763 | ework->id, ework->type); | 
|  | 8764 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8765 | wpa_s->ext_work_in_progress = 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8766 | radio_work_done(work); | 
| Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 8767 | os_free(ework); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8768 | return 3; /* "OK\n" */ | 
|  | 8769 | } | 
|  | 8770 |  | 
|  | 8771 | return -1; | 
|  | 8772 | } | 
|  | 8773 |  | 
|  | 8774 |  | 
|  | 8775 | static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 8776 | char *buf, size_t buflen) | 
|  | 8777 | { | 
|  | 8778 | if (os_strcmp(cmd, "show") == 0) | 
|  | 8779 | return wpas_ctrl_radio_work_show(wpa_s, buf, buflen); | 
|  | 8780 | if (os_strncmp(cmd, "add ", 4) == 0) | 
|  | 8781 | return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen); | 
|  | 8782 | if (os_strncmp(cmd, "done ", 5) == 0) | 
|  | 8783 | return wpas_ctrl_radio_work_done(wpa_s, cmd + 4); | 
|  | 8784 | return -1; | 
|  | 8785 | } | 
|  | 8786 |  | 
|  | 8787 |  | 
|  | 8788 | void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s) | 
|  | 8789 | { | 
|  | 8790 | struct wpa_radio_work *work, *tmp; | 
|  | 8791 |  | 
| Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 8792 | if (!wpa_s || !wpa_s->radio) | 
|  | 8793 | return; | 
|  | 8794 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8795 | dl_list_for_each_safe(work, tmp, &wpa_s->radio->work, | 
|  | 8796 | struct wpa_radio_work, list) { | 
|  | 8797 | struct wpa_external_work *ework; | 
|  | 8798 |  | 
|  | 8799 | if (os_strncmp(work->type, "ext:", 4) != 0) | 
|  | 8800 | continue; | 
|  | 8801 | ework = work->ctx; | 
|  | 8802 | wpa_dbg(wpa_s, MSG_DEBUG, | 
| Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 8803 | "Flushing%s external radio work %u (%s)", | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8804 | work->started ? " started" : "", ework->id, | 
|  | 8805 | ework->type); | 
|  | 8806 | if (work->started) | 
|  | 8807 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, | 
|  | 8808 | work, NULL); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8809 | radio_work_done(work); | 
| Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8810 | os_free(ework); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8811 | } | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8812 | } | 
|  | 8813 |  | 
|  | 8814 |  | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8815 | static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx) | 
|  | 8816 | { | 
|  | 8817 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
|  | 8818 | eapol_sm_notify_ctrl_response(wpa_s->eapol); | 
|  | 8819 | } | 
|  | 8820 |  | 
|  | 8821 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8822 | static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value, | 
|  | 8823 | unsigned int *scan_id_count, int scan_id[]) | 
| Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8824 | { | 
|  | 8825 | const char *pos = value; | 
|  | 8826 |  | 
|  | 8827 | while (pos) { | 
|  | 8828 | if (*pos == ' ' || *pos == '\0') | 
|  | 8829 | break; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8830 | if (*scan_id_count == MAX_SCAN_ID) | 
| Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8831 | return -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8832 | scan_id[(*scan_id_count)++] = atoi(pos); | 
| Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8833 | pos = os_strchr(pos, ','); | 
|  | 8834 | if (pos) | 
|  | 8835 | pos++; | 
|  | 8836 | } | 
|  | 8837 |  | 
|  | 8838 | return 0; | 
|  | 8839 | } | 
|  | 8840 |  | 
|  | 8841 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8842 | static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params, | 
|  | 8843 | char *reply, int reply_size, int *reply_len) | 
|  | 8844 | { | 
|  | 8845 | char *pos; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8846 | unsigned int manual_scan_passive = 0; | 
|  | 8847 | unsigned int manual_scan_use_id = 0; | 
|  | 8848 | unsigned int manual_scan_only_new = 0; | 
|  | 8849 | unsigned int scan_only = 0; | 
|  | 8850 | unsigned int scan_id_count = 0; | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8851 | unsigned int manual_non_coloc_6ghz = 0; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8852 | int scan_id[MAX_SCAN_ID]; | 
|  | 8853 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, | 
|  | 8854 | struct wpa_scan_results *scan_res); | 
|  | 8855 | int *manual_scan_freqs = NULL; | 
| Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 8856 | struct wpa_ssid_value *ssid = NULL, *ns; | 
|  | 8857 | unsigned int ssid_count = 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8858 |  | 
|  | 8859 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { | 
|  | 8860 | *reply_len = -1; | 
|  | 8861 | return; | 
|  | 8862 | } | 
|  | 8863 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8864 | if (radio_work_pending(wpa_s, "scan")) { | 
|  | 8865 | wpa_printf(MSG_DEBUG, | 
|  | 8866 | "Pending scan scheduled - reject new request"); | 
|  | 8867 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | 
|  | 8868 | return; | 
|  | 8869 | } | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8870 |  | 
| Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8871 | #ifdef CONFIG_INTERWORKING | 
|  | 8872 | if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) { | 
|  | 8873 | wpa_printf(MSG_DEBUG, | 
|  | 8874 | "Interworking select in progress - reject new scan"); | 
|  | 8875 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | 
|  | 8876 | return; | 
|  | 8877 | } | 
|  | 8878 | #endif /* CONFIG_INTERWORKING */ | 
|  | 8879 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8880 | if (params) { | 
|  | 8881 | if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8882 | scan_only = 1; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8883 |  | 
|  | 8884 | pos = os_strstr(params, "freq="); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8885 | if (pos) { | 
|  | 8886 | manual_scan_freqs = freq_range_to_channel_list(wpa_s, | 
|  | 8887 | pos + 5); | 
|  | 8888 | if (manual_scan_freqs == NULL) { | 
|  | 8889 | *reply_len = -1; | 
|  | 8890 | goto done; | 
|  | 8891 | } | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8892 | } | 
|  | 8893 |  | 
|  | 8894 | pos = os_strstr(params, "passive="); | 
|  | 8895 | if (pos) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8896 | manual_scan_passive = !!atoi(pos + 8); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8897 |  | 
|  | 8898 | pos = os_strstr(params, "use_id="); | 
|  | 8899 | if (pos) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8900 | manual_scan_use_id = atoi(pos + 7); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8901 |  | 
|  | 8902 | pos = os_strstr(params, "only_new=1"); | 
|  | 8903 | if (pos) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8904 | manual_scan_only_new = 1; | 
| Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8905 |  | 
|  | 8906 | pos = os_strstr(params, "scan_id="); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8907 | if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count, | 
|  | 8908 | scan_id) < 0) { | 
| Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8909 | *reply_len = -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8910 | goto done; | 
| Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 8911 | } | 
| Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 8912 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8913 | pos = os_strstr(params, "bssid="); | 
|  | 8914 | if (pos) { | 
|  | 8915 | u8 bssid[ETH_ALEN]; | 
|  | 8916 |  | 
|  | 8917 | pos += 6; | 
|  | 8918 | if (hwaddr_aton(pos, bssid)) { | 
|  | 8919 | wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos); | 
|  | 8920 | *reply_len = -1; | 
|  | 8921 | goto done; | 
|  | 8922 | } | 
|  | 8923 | os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8924 |  | 
|  | 8925 | wpa_s->next_scan_bssid_wildcard_ssid = | 
|  | 8926 | os_strstr(params, "wildcard_ssid=1") != NULL; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8927 | } | 
|  | 8928 |  | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8929 | pos = os_strstr(params, "non_coloc_6ghz="); | 
|  | 8930 | if (pos) | 
|  | 8931 | manual_non_coloc_6ghz = !!atoi(pos + 15); | 
|  | 8932 |  | 
| Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 8933 | pos = params; | 
|  | 8934 | while (pos && *pos != '\0') { | 
|  | 8935 | if (os_strncmp(pos, "ssid ", 5) == 0) { | 
|  | 8936 | char *end; | 
|  | 8937 |  | 
|  | 8938 | pos += 5; | 
|  | 8939 | end = pos; | 
|  | 8940 | while (*end) { | 
|  | 8941 | if (*end == '\0' || *end == ' ') | 
|  | 8942 | break; | 
|  | 8943 | end++; | 
|  | 8944 | } | 
|  | 8945 |  | 
|  | 8946 | ns = os_realloc_array( | 
|  | 8947 | ssid, ssid_count + 1, | 
|  | 8948 | sizeof(struct wpa_ssid_value)); | 
|  | 8949 | if (ns == NULL) { | 
|  | 8950 | *reply_len = -1; | 
|  | 8951 | goto done; | 
|  | 8952 | } | 
|  | 8953 | ssid = ns; | 
|  | 8954 |  | 
|  | 8955 | if ((end - pos) & 0x01 || | 
|  | 8956 | end - pos > 2 * SSID_MAX_LEN || | 
|  | 8957 | hexstr2bin(pos, ssid[ssid_count].ssid, | 
|  | 8958 | (end - pos) / 2) < 0) { | 
|  | 8959 | wpa_printf(MSG_DEBUG, | 
|  | 8960 | "Invalid SSID value '%s'", | 
|  | 8961 | pos); | 
|  | 8962 | *reply_len = -1; | 
|  | 8963 | goto done; | 
|  | 8964 | } | 
|  | 8965 | ssid[ssid_count].ssid_len = (end - pos) / 2; | 
|  | 8966 | wpa_hexdump_ascii(MSG_DEBUG, "scan SSID", | 
|  | 8967 | ssid[ssid_count].ssid, | 
|  | 8968 | ssid[ssid_count].ssid_len); | 
|  | 8969 | ssid_count++; | 
|  | 8970 | pos = end; | 
|  | 8971 | } | 
|  | 8972 |  | 
|  | 8973 | pos = os_strchr(pos, ' '); | 
|  | 8974 | if (pos) | 
|  | 8975 | pos++; | 
|  | 8976 | } | 
|  | 8977 | } | 
|  | 8978 |  | 
|  | 8979 | wpa_s->num_ssids_from_scan_req = ssid_count; | 
|  | 8980 | os_free(wpa_s->ssids_from_scan_req); | 
|  | 8981 | if (ssid_count) { | 
|  | 8982 | wpa_s->ssids_from_scan_req = ssid; | 
|  | 8983 | ssid = NULL; | 
|  | 8984 | } else { | 
|  | 8985 | wpa_s->ssids_from_scan_req = NULL; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8986 | } | 
|  | 8987 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8988 | if (scan_only) | 
|  | 8989 | scan_res_handler = scan_only_handler; | 
|  | 8990 | else if (wpa_s->scan_res_handler == scan_only_handler) | 
|  | 8991 | scan_res_handler = NULL; | 
|  | 8992 | else | 
|  | 8993 | scan_res_handler = wpa_s->scan_res_handler; | 
|  | 8994 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8995 | if (!wpa_s->sched_scanning && !wpa_s->scanning && | 
|  | 8996 | ((wpa_s->wpa_state <= WPA_SCANNING) || | 
|  | 8997 | (wpa_s->wpa_state == WPA_COMPLETED))) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8998 | wpa_s->manual_scan_passive = manual_scan_passive; | 
|  | 8999 | wpa_s->manual_scan_use_id = manual_scan_use_id; | 
|  | 9000 | wpa_s->manual_scan_only_new = manual_scan_only_new; | 
|  | 9001 | wpa_s->scan_id_count = scan_id_count; | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9002 | wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9003 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); | 
|  | 9004 | wpa_s->scan_res_handler = scan_res_handler; | 
|  | 9005 | os_free(wpa_s->manual_scan_freqs); | 
|  | 9006 | wpa_s->manual_scan_freqs = manual_scan_freqs; | 
|  | 9007 | manual_scan_freqs = NULL; | 
|  | 9008 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9009 | wpa_s->normal_scans = 0; | 
|  | 9010 | wpa_s->scan_req = MANUAL_SCAN_REQ; | 
|  | 9011 | wpa_s->after_wps = 0; | 
|  | 9012 | wpa_s->known_wps_freq = 0; | 
|  | 9013 | wpa_supplicant_req_scan(wpa_s, 0, 0); | 
|  | 9014 | if (wpa_s->manual_scan_use_id) { | 
|  | 9015 | wpa_s->manual_scan_id++; | 
|  | 9016 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", | 
|  | 9017 | wpa_s->manual_scan_id); | 
|  | 9018 | *reply_len = os_snprintf(reply, reply_size, "%u\n", | 
|  | 9019 | wpa_s->manual_scan_id); | 
|  | 9020 | } | 
|  | 9021 | } else if (wpa_s->sched_scanning) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9022 | wpa_s->manual_scan_passive = manual_scan_passive; | 
|  | 9023 | wpa_s->manual_scan_use_id = manual_scan_use_id; | 
|  | 9024 | wpa_s->manual_scan_only_new = manual_scan_only_new; | 
|  | 9025 | wpa_s->scan_id_count = scan_id_count; | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9026 | wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9027 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); | 
|  | 9028 | wpa_s->scan_res_handler = scan_res_handler; | 
|  | 9029 | os_free(wpa_s->manual_scan_freqs); | 
|  | 9030 | wpa_s->manual_scan_freqs = manual_scan_freqs; | 
|  | 9031 | manual_scan_freqs = NULL; | 
|  | 9032 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9033 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed"); | 
|  | 9034 | wpa_supplicant_cancel_sched_scan(wpa_s); | 
|  | 9035 | wpa_s->scan_req = MANUAL_SCAN_REQ; | 
|  | 9036 | wpa_supplicant_req_scan(wpa_s, 0, 0); | 
|  | 9037 | if (wpa_s->manual_scan_use_id) { | 
|  | 9038 | wpa_s->manual_scan_id++; | 
|  | 9039 | *reply_len = os_snprintf(reply, reply_size, "%u\n", | 
|  | 9040 | wpa_s->manual_scan_id); | 
|  | 9041 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", | 
|  | 9042 | wpa_s->manual_scan_id); | 
|  | 9043 | } | 
|  | 9044 | } else { | 
|  | 9045 | wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request"); | 
|  | 9046 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); | 
|  | 9047 | } | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9048 |  | 
|  | 9049 | done: | 
|  | 9050 | os_free(manual_scan_freqs); | 
| Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 9051 | os_free(ssid); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9052 | } | 
|  | 9053 |  | 
|  | 9054 |  | 
| Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 9055 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 9056 |  | 
|  | 9057 | static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s, | 
|  | 9058 | unsigned int freq, const u8 *dst, | 
|  | 9059 | const u8 *src, const u8 *bssid, | 
|  | 9060 | const u8 *data, size_t data_len, | 
|  | 9061 | enum offchannel_send_action_result | 
|  | 9062 | result) | 
|  | 9063 | { | 
|  | 9064 | wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR | 
|  | 9065 | " src=" MACSTR " bssid=" MACSTR " result=%s", | 
|  | 9066 | freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid), | 
|  | 9067 | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? | 
|  | 9068 | "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? | 
|  | 9069 | "NO_ACK" : "FAILED")); | 
|  | 9070 | } | 
|  | 9071 |  | 
|  | 9072 |  | 
|  | 9073 | static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 9074 | { | 
|  | 9075 | char *pos, *param; | 
|  | 9076 | size_t len; | 
|  | 9077 | u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN]; | 
|  | 9078 | int res, used; | 
|  | 9079 | int freq = 0, no_cck = 0, wait_time = 0; | 
|  | 9080 |  | 
|  | 9081 | /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1] | 
|  | 9082 | *    <action=Action frame payload> */ | 
|  | 9083 |  | 
|  | 9084 | wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd); | 
|  | 9085 |  | 
|  | 9086 | pos = cmd; | 
|  | 9087 | used = hwaddr_aton2(pos, da); | 
|  | 9088 | if (used < 0) | 
|  | 9089 | return -1; | 
|  | 9090 | pos += used; | 
|  | 9091 | while (*pos == ' ') | 
|  | 9092 | pos++; | 
|  | 9093 | used = hwaddr_aton2(pos, bssid); | 
|  | 9094 | if (used < 0) | 
|  | 9095 | return -1; | 
|  | 9096 | pos += used; | 
|  | 9097 |  | 
|  | 9098 | param = os_strstr(pos, " freq="); | 
|  | 9099 | if (param) { | 
|  | 9100 | param += 6; | 
|  | 9101 | freq = atoi(param); | 
|  | 9102 | } | 
|  | 9103 |  | 
|  | 9104 | param = os_strstr(pos, " no_cck="); | 
|  | 9105 | if (param) { | 
|  | 9106 | param += 8; | 
|  | 9107 | no_cck = atoi(param); | 
|  | 9108 | } | 
|  | 9109 |  | 
|  | 9110 | param = os_strstr(pos, " wait_time="); | 
|  | 9111 | if (param) { | 
|  | 9112 | param += 11; | 
|  | 9113 | wait_time = atoi(param); | 
|  | 9114 | } | 
|  | 9115 |  | 
|  | 9116 | param = os_strstr(pos, " action="); | 
|  | 9117 | if (param == NULL) | 
|  | 9118 | return -1; | 
|  | 9119 | param += 8; | 
|  | 9120 |  | 
|  | 9121 | len = os_strlen(param); | 
|  | 9122 | if (len & 1) | 
|  | 9123 | return -1; | 
|  | 9124 | len /= 2; | 
|  | 9125 |  | 
|  | 9126 | buf = os_malloc(len); | 
|  | 9127 | if (buf == NULL) | 
|  | 9128 | return -1; | 
|  | 9129 |  | 
|  | 9130 | if (hexstr2bin(param, buf, len) < 0) { | 
|  | 9131 | os_free(buf); | 
|  | 9132 | return -1; | 
|  | 9133 | } | 
|  | 9134 |  | 
|  | 9135 | res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid, | 
|  | 9136 | buf, len, wait_time, | 
|  | 9137 | wpas_ctrl_iface_mgmt_tx_cb, no_cck); | 
|  | 9138 | os_free(buf); | 
|  | 9139 | return res; | 
|  | 9140 | } | 
|  | 9141 |  | 
|  | 9142 |  | 
|  | 9143 | static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s) | 
|  | 9144 | { | 
|  | 9145 | wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting"); | 
|  | 9146 | offchannel_send_action_done(wpa_s); | 
|  | 9147 | } | 
|  | 9148 |  | 
| Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 9149 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9150 | static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s, | 
|  | 9151 | char *cmd) | 
|  | 9152 | { | 
|  | 9153 | char *pos, *param; | 
|  | 9154 | size_t len; | 
|  | 9155 | u8 *buf; | 
|  | 9156 | int freq = 0, datarate = 0, ssi_signal = 0; | 
|  | 9157 | union wpa_event_data event; | 
|  | 9158 |  | 
|  | 9159 | if (!wpa_s->ext_mgmt_frame_handling) | 
|  | 9160 | return -1; | 
|  | 9161 |  | 
|  | 9162 | /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */ | 
|  | 9163 |  | 
|  | 9164 | wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd); | 
|  | 9165 |  | 
|  | 9166 | pos = cmd; | 
|  | 9167 | param = os_strstr(pos, "freq="); | 
|  | 9168 | if (param) { | 
|  | 9169 | param += 5; | 
|  | 9170 | freq = atoi(param); | 
|  | 9171 | } | 
|  | 9172 |  | 
|  | 9173 | param = os_strstr(pos, " datarate="); | 
|  | 9174 | if (param) { | 
|  | 9175 | param += 10; | 
|  | 9176 | datarate = atoi(param); | 
|  | 9177 | } | 
|  | 9178 |  | 
|  | 9179 | param = os_strstr(pos, " ssi_signal="); | 
|  | 9180 | if (param) { | 
|  | 9181 | param += 12; | 
|  | 9182 | ssi_signal = atoi(param); | 
|  | 9183 | } | 
|  | 9184 |  | 
|  | 9185 | param = os_strstr(pos, " frame="); | 
|  | 9186 | if (param == NULL) | 
|  | 9187 | return -1; | 
|  | 9188 | param += 7; | 
|  | 9189 |  | 
|  | 9190 | len = os_strlen(param); | 
|  | 9191 | if (len & 1) | 
|  | 9192 | return -1; | 
|  | 9193 | len /= 2; | 
|  | 9194 |  | 
|  | 9195 | buf = os_malloc(len); | 
|  | 9196 | if (buf == NULL) | 
|  | 9197 | return -1; | 
|  | 9198 |  | 
|  | 9199 | if (hexstr2bin(param, buf, len) < 0) { | 
|  | 9200 | os_free(buf); | 
|  | 9201 | return -1; | 
|  | 9202 | } | 
|  | 9203 |  | 
|  | 9204 | os_memset(&event, 0, sizeof(event)); | 
|  | 9205 | event.rx_mgmt.freq = freq; | 
|  | 9206 | event.rx_mgmt.frame = buf; | 
|  | 9207 | event.rx_mgmt.frame_len = len; | 
|  | 9208 | event.rx_mgmt.ssi_signal = ssi_signal; | 
|  | 9209 | event.rx_mgmt.datarate = datarate; | 
|  | 9210 | wpa_s->ext_mgmt_frame_handling = 0; | 
|  | 9211 | wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event); | 
|  | 9212 | wpa_s->ext_mgmt_frame_handling = 1; | 
|  | 9213 |  | 
|  | 9214 | os_free(buf); | 
|  | 9215 |  | 
|  | 9216 | return 0; | 
|  | 9217 | } | 
|  | 9218 |  | 
|  | 9219 |  | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9220 | static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s, | 
|  | 9221 | char *param) | 
|  | 9222 | { | 
|  | 9223 | struct wpa_scan_res *res; | 
|  | 9224 | struct os_reltime now; | 
|  | 9225 | char *pos, *end; | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9226 | int ret = -1; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9227 |  | 
|  | 9228 | if (!param) | 
|  | 9229 | return -1; | 
|  | 9230 |  | 
|  | 9231 | if (os_strcmp(param, "START") == 0) { | 
|  | 9232 | wpa_bss_update_start(wpa_s); | 
|  | 9233 | return 0; | 
|  | 9234 | } | 
|  | 9235 |  | 
|  | 9236 | if (os_strcmp(param, "END") == 0) { | 
|  | 9237 | wpa_bss_update_end(wpa_s, NULL, 1); | 
|  | 9238 | return 0; | 
|  | 9239 | } | 
|  | 9240 |  | 
|  | 9241 | if (os_strncmp(param, "BSS ", 4) != 0) | 
|  | 9242 | return -1; | 
|  | 9243 | param += 3; | 
|  | 9244 |  | 
|  | 9245 | res = os_zalloc(sizeof(*res) + os_strlen(param) / 2); | 
|  | 9246 | if (!res) | 
|  | 9247 | return -1; | 
|  | 9248 |  | 
|  | 9249 | pos = os_strstr(param, " flags="); | 
|  | 9250 | if (pos) | 
|  | 9251 | res->flags = strtol(pos + 7, NULL, 16); | 
|  | 9252 |  | 
|  | 9253 | pos = os_strstr(param, " bssid="); | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9254 | if (pos && hwaddr_aton(pos + 7, res->bssid)) | 
|  | 9255 | goto fail; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9256 |  | 
|  | 9257 | pos = os_strstr(param, " freq="); | 
|  | 9258 | if (pos) | 
|  | 9259 | res->freq = atoi(pos + 6); | 
|  | 9260 |  | 
|  | 9261 | pos = os_strstr(param, " beacon_int="); | 
|  | 9262 | if (pos) | 
|  | 9263 | res->beacon_int = atoi(pos + 12); | 
|  | 9264 |  | 
|  | 9265 | pos = os_strstr(param, " caps="); | 
|  | 9266 | if (pos) | 
|  | 9267 | res->caps = strtol(pos + 6, NULL, 16); | 
|  | 9268 |  | 
|  | 9269 | pos = os_strstr(param, " qual="); | 
|  | 9270 | if (pos) | 
|  | 9271 | res->qual = atoi(pos + 6); | 
|  | 9272 |  | 
|  | 9273 | pos = os_strstr(param, " noise="); | 
|  | 9274 | if (pos) | 
|  | 9275 | res->noise = atoi(pos + 7); | 
|  | 9276 |  | 
|  | 9277 | pos = os_strstr(param, " level="); | 
|  | 9278 | if (pos) | 
|  | 9279 | res->level = atoi(pos + 7); | 
|  | 9280 |  | 
|  | 9281 | pos = os_strstr(param, " tsf="); | 
|  | 9282 | if (pos) | 
|  | 9283 | res->tsf = strtoll(pos + 5, NULL, 16); | 
|  | 9284 |  | 
|  | 9285 | pos = os_strstr(param, " age="); | 
|  | 9286 | if (pos) | 
|  | 9287 | res->age = atoi(pos + 5); | 
|  | 9288 |  | 
|  | 9289 | pos = os_strstr(param, " est_throughput="); | 
|  | 9290 | if (pos) | 
|  | 9291 | res->est_throughput = atoi(pos + 16); | 
|  | 9292 |  | 
|  | 9293 | pos = os_strstr(param, " snr="); | 
|  | 9294 | if (pos) | 
|  | 9295 | res->snr = atoi(pos + 5); | 
|  | 9296 |  | 
|  | 9297 | pos = os_strstr(param, " parent_tsf="); | 
|  | 9298 | if (pos) | 
|  | 9299 | res->parent_tsf = strtoll(pos + 7, NULL, 16); | 
|  | 9300 |  | 
|  | 9301 | pos = os_strstr(param, " tsf_bssid="); | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9302 | if (pos && hwaddr_aton(pos + 11, res->tsf_bssid)) | 
|  | 9303 | goto fail; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9304 |  | 
|  | 9305 | pos = os_strstr(param, " ie="); | 
|  | 9306 | if (pos) { | 
|  | 9307 | pos += 4; | 
|  | 9308 | end = os_strchr(pos, ' '); | 
|  | 9309 | if (!end) | 
|  | 9310 | end = pos + os_strlen(pos); | 
|  | 9311 | res->ie_len = (end - pos) / 2; | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9312 | if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len)) | 
|  | 9313 | goto fail; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9314 | } | 
|  | 9315 |  | 
|  | 9316 | pos = os_strstr(param, " beacon_ie="); | 
|  | 9317 | if (pos) { | 
|  | 9318 | pos += 11; | 
|  | 9319 | end = os_strchr(pos, ' '); | 
|  | 9320 | if (!end) | 
|  | 9321 | end = pos + os_strlen(pos); | 
|  | 9322 | res->beacon_ie_len = (end - pos) / 2; | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9323 | if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len, | 
|  | 9324 | res->beacon_ie_len)) | 
|  | 9325 | goto fail; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9326 | } | 
|  | 9327 |  | 
|  | 9328 | os_get_reltime(&now); | 
|  | 9329 | wpa_bss_update_scan_res(wpa_s, res, &now); | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9330 | ret = 0; | 
|  | 9331 | fail: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9332 | os_free(res); | 
|  | 9333 |  | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 9334 | return ret; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9335 | } | 
|  | 9336 |  | 
|  | 9337 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9338 | static int wpas_ctrl_iface_driver_event_assoc(struct wpa_supplicant *wpa_s, | 
|  | 9339 | char *param) | 
|  | 9340 | { | 
|  | 9341 | union wpa_event_data event; | 
|  | 9342 | struct assoc_info *ai; | 
|  | 9343 | char *ctx = NULL; | 
|  | 9344 | int ret = -1; | 
|  | 9345 | struct wpabuf *req_ies = NULL; | 
|  | 9346 | struct wpabuf *resp_ies = NULL; | 
|  | 9347 | struct wpabuf *resp_frame = NULL; | 
|  | 9348 | struct wpabuf *beacon_ies = NULL; | 
|  | 9349 | struct wpabuf *key_replay_ctr = NULL; | 
|  | 9350 | struct wpabuf *ptk_kck = NULL; | 
|  | 9351 | struct wpabuf *ptk_kek = NULL; | 
|  | 9352 | struct wpabuf *fils_pmk = NULL; | 
|  | 9353 | char *str, *pos; | 
|  | 9354 | u8 addr[ETH_ALEN]; | 
|  | 9355 | u8 fils_pmkid[PMKID_LEN]; | 
|  | 9356 |  | 
|  | 9357 | os_memset(&event, 0, sizeof(event)); | 
|  | 9358 | ai = &event.assoc_info; | 
|  | 9359 |  | 
|  | 9360 | while ((str = str_token(param, " ", &ctx))) { | 
|  | 9361 | pos = os_strchr(str, '='); | 
|  | 9362 | if (!pos) | 
|  | 9363 | goto fail; | 
|  | 9364 | *pos++ = '\0'; | 
|  | 9365 |  | 
|  | 9366 | if (os_strcmp(str, "reassoc") == 0) { | 
|  | 9367 | ai->reassoc = atoi(pos); | 
|  | 9368 | } else if (os_strcmp(str, "req_ies") == 0) { | 
|  | 9369 | wpabuf_free(req_ies); | 
|  | 9370 | req_ies = wpabuf_parse_bin(pos); | 
|  | 9371 | if (!req_ies) | 
|  | 9372 | goto fail; | 
|  | 9373 | ai->req_ies = wpabuf_head(req_ies); | 
|  | 9374 | ai->req_ies_len = wpabuf_len(req_ies); | 
|  | 9375 | } else if (os_strcmp(str, "resp_ies") == 0) { | 
|  | 9376 | wpabuf_free(resp_ies); | 
|  | 9377 | resp_ies = wpabuf_parse_bin(pos); | 
|  | 9378 | if (!resp_ies) | 
|  | 9379 | goto fail; | 
|  | 9380 | ai->resp_ies = wpabuf_head(resp_ies); | 
|  | 9381 | ai->resp_ies_len = wpabuf_len(resp_ies); | 
|  | 9382 | } else if (os_strcmp(str, "resp_frame") == 0) { | 
|  | 9383 | wpabuf_free(resp_frame); | 
|  | 9384 | resp_frame = wpabuf_parse_bin(pos); | 
|  | 9385 | if (!resp_frame) | 
|  | 9386 | goto fail; | 
|  | 9387 | ai->resp_frame = wpabuf_head(resp_frame); | 
|  | 9388 | ai->resp_frame_len = wpabuf_len(resp_frame); | 
|  | 9389 | } else if (os_strcmp(str, "beacon_ies") == 0) { | 
|  | 9390 | wpabuf_free(beacon_ies); | 
|  | 9391 | beacon_ies = wpabuf_parse_bin(pos); | 
|  | 9392 | if (!beacon_ies) | 
|  | 9393 | goto fail; | 
|  | 9394 | ai->beacon_ies = wpabuf_head(beacon_ies); | 
|  | 9395 | ai->beacon_ies_len = wpabuf_len(beacon_ies); | 
|  | 9396 | } else if (os_strcmp(str, "freq") == 0) { | 
|  | 9397 | ai->freq = atoi(pos); | 
|  | 9398 | } else if (os_strcmp(str, "wmm::info_bitmap") == 0) { | 
|  | 9399 | ai->wmm_params.info_bitmap = atoi(pos); | 
|  | 9400 | } else if (os_strcmp(str, "wmm::uapsd_queues") == 0) { | 
|  | 9401 | ai->wmm_params.uapsd_queues = atoi(pos); | 
|  | 9402 | } else if (os_strcmp(str, "addr") == 0) { | 
|  | 9403 | if (hwaddr_aton(pos, addr)) | 
|  | 9404 | goto fail; | 
|  | 9405 | ai->addr = addr; | 
|  | 9406 | } else if (os_strcmp(str, "authorized") == 0) { | 
|  | 9407 | ai->authorized = atoi(pos); | 
|  | 9408 | } else if (os_strcmp(str, "key_replay_ctr") == 0) { | 
|  | 9409 | wpabuf_free(key_replay_ctr); | 
|  | 9410 | key_replay_ctr = wpabuf_parse_bin(pos); | 
|  | 9411 | if (!key_replay_ctr) | 
|  | 9412 | goto fail; | 
|  | 9413 | ai->key_replay_ctr = wpabuf_head(key_replay_ctr); | 
|  | 9414 | ai->key_replay_ctr_len = wpabuf_len(key_replay_ctr); | 
|  | 9415 | } else if (os_strcmp(str, "ptk_kck") == 0) { | 
|  | 9416 | wpabuf_free(ptk_kck); | 
|  | 9417 | ptk_kck = wpabuf_parse_bin(pos); | 
|  | 9418 | if (!ptk_kck) | 
|  | 9419 | goto fail; | 
|  | 9420 | ai->ptk_kck = wpabuf_head(ptk_kck); | 
|  | 9421 | ai->ptk_kck_len = wpabuf_len(ptk_kck); | 
|  | 9422 | } else if (os_strcmp(str, "ptk_kek") == 0) { | 
|  | 9423 | wpabuf_free(ptk_kek); | 
|  | 9424 | ptk_kek = wpabuf_parse_bin(pos); | 
|  | 9425 | if (!ptk_kek) | 
|  | 9426 | goto fail; | 
|  | 9427 | ai->ptk_kek = wpabuf_head(ptk_kek); | 
|  | 9428 | ai->ptk_kek_len = wpabuf_len(ptk_kek); | 
|  | 9429 | } else if (os_strcmp(str, "subnet_status") == 0) { | 
|  | 9430 | ai->subnet_status = atoi(pos); | 
|  | 9431 | } else if (os_strcmp(str, "fils_erp_next_seq_num") == 0) { | 
|  | 9432 | ai->fils_erp_next_seq_num = atoi(pos); | 
|  | 9433 | } else if (os_strcmp(str, "fils_pmk") == 0) { | 
|  | 9434 | wpabuf_free(fils_pmk); | 
|  | 9435 | fils_pmk = wpabuf_parse_bin(pos); | 
|  | 9436 | if (!fils_pmk) | 
|  | 9437 | goto fail; | 
|  | 9438 | ai->fils_pmk = wpabuf_head(fils_pmk); | 
|  | 9439 | ai->fils_pmk_len = wpabuf_len(fils_pmk); | 
|  | 9440 | } else if (os_strcmp(str, "fils_pmkid") == 0) { | 
|  | 9441 | if (hexstr2bin(pos, fils_pmkid, PMKID_LEN) < 0) | 
|  | 9442 | goto fail; | 
|  | 9443 | ai->fils_pmkid = fils_pmkid; | 
|  | 9444 | } else { | 
|  | 9445 | goto fail; | 
|  | 9446 | } | 
|  | 9447 | } | 
|  | 9448 |  | 
|  | 9449 | wpa_supplicant_event(wpa_s, EVENT_ASSOC, &event); | 
|  | 9450 | ret = 0; | 
|  | 9451 | fail: | 
|  | 9452 | wpabuf_free(req_ies); | 
|  | 9453 | wpabuf_free(resp_ies); | 
|  | 9454 | wpabuf_free(resp_frame); | 
|  | 9455 | wpabuf_free(beacon_ies); | 
|  | 9456 | wpabuf_free(key_replay_ctr); | 
|  | 9457 | wpabuf_free(ptk_kck); | 
|  | 9458 | wpabuf_free(ptk_kek); | 
|  | 9459 | wpabuf_free(fils_pmk); | 
|  | 9460 | return ret; | 
|  | 9461 | } | 
|  | 9462 |  | 
|  | 9463 |  | 
| Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 9464 | static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 9465 | { | 
|  | 9466 | char *pos, *param; | 
|  | 9467 | union wpa_event_data event; | 
|  | 9468 | enum wpa_event_type ev; | 
|  | 9469 |  | 
|  | 9470 | /* <event name> [parameters..] */ | 
|  | 9471 |  | 
|  | 9472 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd); | 
|  | 9473 |  | 
|  | 9474 | pos = cmd; | 
|  | 9475 | param = os_strchr(pos, ' '); | 
|  | 9476 | if (param) | 
|  | 9477 | *param++ = '\0'; | 
|  | 9478 |  | 
|  | 9479 | os_memset(&event, 0, sizeof(event)); | 
|  | 9480 |  | 
|  | 9481 | if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) { | 
|  | 9482 | ev = EVENT_INTERFACE_ENABLED; | 
|  | 9483 | } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) { | 
|  | 9484 | ev = EVENT_INTERFACE_DISABLED; | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 9485 | } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) { | 
|  | 9486 | ev = EVENT_AVOID_FREQUENCIES; | 
|  | 9487 | if (param == NULL) | 
|  | 9488 | param = ""; | 
|  | 9489 | if (freq_range_list_parse(&event.freq_range, param) < 0) | 
|  | 9490 | return -1; | 
|  | 9491 | wpa_supplicant_event(wpa_s, ev, &event); | 
|  | 9492 | os_free(event.freq_range.range); | 
|  | 9493 | return 0; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9494 | } else if (os_strcmp(cmd, "SCAN_RES") == 0) { | 
|  | 9495 | return wpas_ctrl_iface_driver_scan_res(wpa_s, param); | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9496 | } else if (os_strcmp(cmd, "ASSOC") == 0) { | 
|  | 9497 | return wpas_ctrl_iface_driver_event_assoc(wpa_s, param); | 
| Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 9498 | } else { | 
|  | 9499 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s", | 
|  | 9500 | cmd); | 
|  | 9501 | return -1; | 
|  | 9502 | } | 
|  | 9503 |  | 
|  | 9504 | wpa_supplicant_event(wpa_s, ev, &event); | 
|  | 9505 |  | 
|  | 9506 | return 0; | 
|  | 9507 | } | 
|  | 9508 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9509 |  | 
|  | 9510 | static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 9511 | { | 
|  | 9512 | char *pos; | 
|  | 9513 | u8 src[ETH_ALEN], *buf; | 
|  | 9514 | int used; | 
|  | 9515 | size_t len; | 
|  | 9516 |  | 
|  | 9517 | wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd); | 
|  | 9518 |  | 
|  | 9519 | pos = cmd; | 
|  | 9520 | used = hwaddr_aton2(pos, src); | 
|  | 9521 | if (used < 0) | 
|  | 9522 | return -1; | 
|  | 9523 | pos += used; | 
|  | 9524 | while (*pos == ' ') | 
|  | 9525 | pos++; | 
|  | 9526 |  | 
|  | 9527 | len = os_strlen(pos); | 
|  | 9528 | if (len & 1) | 
|  | 9529 | return -1; | 
|  | 9530 | len /= 2; | 
|  | 9531 |  | 
|  | 9532 | buf = os_malloc(len); | 
|  | 9533 | if (buf == NULL) | 
|  | 9534 | return -1; | 
|  | 9535 |  | 
|  | 9536 | if (hexstr2bin(pos, buf, len) < 0) { | 
|  | 9537 | os_free(buf); | 
|  | 9538 | return -1; | 
|  | 9539 | } | 
|  | 9540 |  | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9541 | wpa_supplicant_rx_eapol(wpa_s, src, buf, len, FRAME_ENCRYPTION_UNKNOWN); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9542 | os_free(buf); | 
|  | 9543 |  | 
|  | 9544 | return 0; | 
|  | 9545 | } | 
|  | 9546 |  | 
|  | 9547 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9548 | static int wpas_ctrl_iface_eapol_tx(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 9549 | { | 
|  | 9550 | char *pos; | 
|  | 9551 | u8 dst[ETH_ALEN], *buf; | 
|  | 9552 | int used, ret; | 
|  | 9553 | size_t len; | 
|  | 9554 | unsigned int prev; | 
|  | 9555 |  | 
|  | 9556 | wpa_printf(MSG_DEBUG, "External EAPOL TX: %s", cmd); | 
|  | 9557 |  | 
|  | 9558 | pos = cmd; | 
|  | 9559 | used = hwaddr_aton2(pos, dst); | 
|  | 9560 | if (used < 0) | 
|  | 9561 | return -1; | 
|  | 9562 | pos += used; | 
|  | 9563 | while (*pos == ' ') | 
|  | 9564 | pos++; | 
|  | 9565 |  | 
|  | 9566 | len = os_strlen(pos); | 
|  | 9567 | if (len & 1) | 
|  | 9568 | return -1; | 
|  | 9569 | len /= 2; | 
|  | 9570 |  | 
|  | 9571 | buf = os_malloc(len); | 
|  | 9572 | if (!buf || hexstr2bin(pos, buf, len) < 0) { | 
|  | 9573 | os_free(buf); | 
|  | 9574 | return -1; | 
|  | 9575 | } | 
|  | 9576 |  | 
|  | 9577 | prev = wpa_s->ext_eapol_frame_io; | 
|  | 9578 | wpa_s->ext_eapol_frame_io = 0; | 
|  | 9579 | ret = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, buf, len); | 
|  | 9580 | wpa_s->ext_eapol_frame_io = prev; | 
|  | 9581 | os_free(buf); | 
|  | 9582 |  | 
|  | 9583 | return ret; | 
|  | 9584 | } | 
|  | 9585 |  | 
|  | 9586 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9587 | static u16 ipv4_hdr_checksum(const void *buf, size_t len) | 
|  | 9588 | { | 
|  | 9589 | size_t i; | 
|  | 9590 | u32 sum = 0; | 
|  | 9591 | const u16 *pos = buf; | 
|  | 9592 |  | 
|  | 9593 | for (i = 0; i < len / 2; i++) | 
|  | 9594 | sum += *pos++; | 
|  | 9595 |  | 
|  | 9596 | while (sum >> 16) | 
|  | 9597 | sum = (sum & 0xffff) + (sum >> 16); | 
|  | 9598 |  | 
|  | 9599 | return sum ^ 0xffff; | 
|  | 9600 | } | 
|  | 9601 |  | 
|  | 9602 |  | 
|  | 9603 | #define HWSIM_PACKETLEN 1500 | 
|  | 9604 | #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header)) | 
|  | 9605 |  | 
| Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 9606 | static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, | 
|  | 9607 | size_t len) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9608 | { | 
|  | 9609 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 9610 | const struct ether_header *eth; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9611 | struct ip ip; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9612 | const u8 *pos; | 
|  | 9613 | unsigned int i; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9614 | char extra[30]; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9615 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9616 | if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) { | 
|  | 9617 | wpa_printf(MSG_DEBUG, | 
|  | 9618 | "test data: RX - ignore unexpected length %d", | 
|  | 9619 | (int) len); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9620 | return; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9621 | } | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9622 |  | 
|  | 9623 | eth = (const struct ether_header *) buf; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9624 | os_memcpy(&ip, eth + 1, sizeof(ip)); | 
|  | 9625 | pos = &buf[sizeof(*eth) + sizeof(ip)]; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9626 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9627 | 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] | 9628 | wpa_printf(MSG_DEBUG, | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9629 | "test data: RX - ignore unexpected IP header"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9630 | return; | 
| Hai Shalom | 39bc25d | 2019-02-06 16:32:13 -0800 | [diff] [blame] | 9631 | } | 
| Hai Shalom | bf6e0ba | 2019-02-11 12:01:50 -0800 | [diff] [blame] | 9632 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9633 | for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9634 | if (*pos != (u8) i) { | 
|  | 9635 | wpa_printf(MSG_DEBUG, | 
|  | 9636 | "test data: RX - ignore mismatching payload"); | 
|  | 9637 | return; | 
|  | 9638 | } | 
|  | 9639 | pos++; | 
|  | 9640 | } | 
|  | 9641 | extra[0] = '\0'; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9642 | if (ntohs(ip.ip_len) != HWSIM_IP_LEN) | 
|  | 9643 | os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len)); | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9644 | wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s", | 
|  | 9645 | MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9646 | } | 
|  | 9647 |  | 
|  | 9648 |  | 
|  | 9649 | static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s, | 
|  | 9650 | char *cmd) | 
|  | 9651 | { | 
|  | 9652 | int enabled = atoi(cmd); | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 9653 | char *pos; | 
|  | 9654 | const char *ifname; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9655 |  | 
|  | 9656 | if (!enabled) { | 
|  | 9657 | if (wpa_s->l2_test) { | 
|  | 9658 | l2_packet_deinit(wpa_s->l2_test); | 
|  | 9659 | wpa_s->l2_test = NULL; | 
|  | 9660 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled"); | 
|  | 9661 | } | 
|  | 9662 | return 0; | 
|  | 9663 | } | 
|  | 9664 |  | 
|  | 9665 | if (wpa_s->l2_test) | 
|  | 9666 | return 0; | 
|  | 9667 |  | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 9668 | pos = os_strstr(cmd, " ifname="); | 
|  | 9669 | if (pos) | 
|  | 9670 | ifname = pos + 8; | 
|  | 9671 | else | 
|  | 9672 | ifname = wpa_s->ifname; | 
|  | 9673 |  | 
|  | 9674 | wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9675 | ETHERTYPE_IP, wpas_data_test_rx, | 
|  | 9676 | wpa_s, 1); | 
|  | 9677 | if (wpa_s->l2_test == NULL) | 
|  | 9678 | return -1; | 
|  | 9679 |  | 
|  | 9680 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled"); | 
|  | 9681 |  | 
|  | 9682 | return 0; | 
|  | 9683 | } | 
|  | 9684 |  | 
|  | 9685 |  | 
|  | 9686 | static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 9687 | { | 
|  | 9688 | u8 dst[ETH_ALEN], src[ETH_ALEN]; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9689 | char *pos, *pos2; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9690 | int used; | 
|  | 9691 | long int val; | 
|  | 9692 | u8 tos; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9693 | u8 buf[2 + HWSIM_PACKETLEN]; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9694 | struct ether_header *eth; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9695 | struct ip *ip; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9696 | u8 *dpos; | 
|  | 9697 | unsigned int i; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9698 | size_t send_len = HWSIM_IP_LEN; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9699 |  | 
|  | 9700 | if (wpa_s->l2_test == NULL) | 
|  | 9701 | return -1; | 
|  | 9702 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9703 | /* format: <dst> <src> <tos> [len=<length>] */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9704 |  | 
|  | 9705 | pos = cmd; | 
|  | 9706 | used = hwaddr_aton2(pos, dst); | 
|  | 9707 | if (used < 0) | 
|  | 9708 | return -1; | 
|  | 9709 | pos += used; | 
|  | 9710 | while (*pos == ' ') | 
|  | 9711 | pos++; | 
|  | 9712 | used = hwaddr_aton2(pos, src); | 
|  | 9713 | if (used < 0) | 
|  | 9714 | return -1; | 
|  | 9715 | pos += used; | 
|  | 9716 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9717 | val = strtol(pos, &pos2, 0); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9718 | if (val < 0 || val > 0xff) | 
|  | 9719 | return -1; | 
|  | 9720 | tos = val; | 
|  | 9721 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9722 | pos = os_strstr(pos2, " len="); | 
|  | 9723 | if (pos) { | 
|  | 9724 | i = atoi(pos + 5); | 
|  | 9725 | if (i < sizeof(*ip) || i > HWSIM_IP_LEN) | 
|  | 9726 | return -1; | 
|  | 9727 | send_len = i; | 
|  | 9728 | } | 
|  | 9729 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9730 | eth = (struct ether_header *) &buf[2]; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9731 | os_memcpy(eth->ether_dhost, dst, ETH_ALEN); | 
|  | 9732 | os_memcpy(eth->ether_shost, src, ETH_ALEN); | 
|  | 9733 | eth->ether_type = htons(ETHERTYPE_IP); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9734 | ip = (struct ip *) (eth + 1); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9735 | os_memset(ip, 0, sizeof(*ip)); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9736 | ip->ip_hl = 5; | 
|  | 9737 | ip->ip_v = 4; | 
|  | 9738 | ip->ip_ttl = 64; | 
|  | 9739 | ip->ip_tos = tos; | 
|  | 9740 | ip->ip_len = htons(send_len); | 
|  | 9741 | ip->ip_p = 1; | 
|  | 9742 | ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1); | 
|  | 9743 | ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2); | 
|  | 9744 | ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9745 | dpos = (u8 *) (ip + 1); | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9746 | for (i = 0; i < send_len - sizeof(*ip); i++) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9747 | *dpos++ = i; | 
|  | 9748 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9749 | 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] | 9750 | sizeof(struct ether_header) + send_len) < 0) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9751 | return -1; | 
|  | 9752 |  | 
|  | 9753 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR | 
|  | 9754 | " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos); | 
|  | 9755 |  | 
|  | 9756 | return 0; | 
|  | 9757 | } | 
|  | 9758 |  | 
|  | 9759 |  | 
|  | 9760 | static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s, | 
|  | 9761 | char *cmd) | 
|  | 9762 | { | 
|  | 9763 | u8 *buf; | 
|  | 9764 | struct ether_header *eth; | 
|  | 9765 | struct l2_packet_data *l2 = NULL; | 
|  | 9766 | size_t len; | 
|  | 9767 | u16 ethertype; | 
|  | 9768 | int res = -1; | 
|  | 9769 |  | 
|  | 9770 | len = os_strlen(cmd); | 
|  | 9771 | if (len & 1 || len < ETH_HLEN * 2) | 
|  | 9772 | return -1; | 
|  | 9773 | len /= 2; | 
|  | 9774 |  | 
|  | 9775 | buf = os_malloc(len); | 
|  | 9776 | if (buf == NULL) | 
|  | 9777 | return -1; | 
|  | 9778 |  | 
|  | 9779 | if (hexstr2bin(cmd, buf, len) < 0) | 
|  | 9780 | goto done; | 
|  | 9781 |  | 
|  | 9782 | eth = (struct ether_header *) buf; | 
|  | 9783 | ethertype = ntohs(eth->ether_type); | 
|  | 9784 |  | 
|  | 9785 | l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype, | 
|  | 9786 | wpas_data_test_rx, wpa_s, 1); | 
|  | 9787 | if (l2 == NULL) | 
|  | 9788 | goto done; | 
|  | 9789 |  | 
|  | 9790 | res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len); | 
|  | 9791 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res); | 
|  | 9792 | done: | 
|  | 9793 | if (l2) | 
|  | 9794 | l2_packet_deinit(l2); | 
|  | 9795 | os_free(buf); | 
|  | 9796 |  | 
|  | 9797 | return res < 0 ? -1 : 0; | 
|  | 9798 | } | 
|  | 9799 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9800 |  | 
|  | 9801 | static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 9802 | { | 
|  | 9803 | #ifdef WPA_TRACE_BFD | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9804 | char *pos; | 
|  | 9805 |  | 
|  | 9806 | wpa_trace_fail_after = atoi(cmd); | 
|  | 9807 | pos = os_strchr(cmd, ':'); | 
|  | 9808 | if (pos) { | 
|  | 9809 | pos++; | 
|  | 9810 | os_strlcpy(wpa_trace_fail_func, pos, | 
|  | 9811 | sizeof(wpa_trace_fail_func)); | 
|  | 9812 | } else { | 
|  | 9813 | wpa_trace_fail_after = 0; | 
|  | 9814 | } | 
|  | 9815 | return 0; | 
|  | 9816 | #else /* WPA_TRACE_BFD */ | 
|  | 9817 | return -1; | 
|  | 9818 | #endif /* WPA_TRACE_BFD */ | 
|  | 9819 | } | 
|  | 9820 |  | 
|  | 9821 |  | 
|  | 9822 | static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s, | 
|  | 9823 | char *buf, size_t buflen) | 
|  | 9824 | { | 
|  | 9825 | #ifdef WPA_TRACE_BFD | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9826 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after, | 
|  | 9827 | wpa_trace_fail_func); | 
|  | 9828 | #else /* WPA_TRACE_BFD */ | 
|  | 9829 | return -1; | 
|  | 9830 | #endif /* WPA_TRACE_BFD */ | 
|  | 9831 | } | 
|  | 9832 |  | 
| Jouni Malinen | c481836 | 2015-10-04 11:45:13 +0300 | [diff] [blame] | 9833 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9834 | static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 9835 | { | 
|  | 9836 | #ifdef WPA_TRACE_BFD | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9837 | char *pos; | 
|  | 9838 |  | 
|  | 9839 | wpa_trace_test_fail_after = atoi(cmd); | 
|  | 9840 | pos = os_strchr(cmd, ':'); | 
|  | 9841 | if (pos) { | 
|  | 9842 | pos++; | 
|  | 9843 | os_strlcpy(wpa_trace_test_fail_func, pos, | 
|  | 9844 | sizeof(wpa_trace_test_fail_func)); | 
|  | 9845 | } else { | 
|  | 9846 | wpa_trace_test_fail_after = 0; | 
|  | 9847 | } | 
|  | 9848 | return 0; | 
|  | 9849 | #else /* WPA_TRACE_BFD */ | 
|  | 9850 | return -1; | 
|  | 9851 | #endif /* WPA_TRACE_BFD */ | 
|  | 9852 | } | 
|  | 9853 |  | 
|  | 9854 |  | 
|  | 9855 | static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s, | 
|  | 9856 | char *buf, size_t buflen) | 
|  | 9857 | { | 
|  | 9858 | #ifdef WPA_TRACE_BFD | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9859 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after, | 
|  | 9860 | wpa_trace_test_fail_func); | 
|  | 9861 | #else /* WPA_TRACE_BFD */ | 
|  | 9862 | return -1; | 
|  | 9863 | #endif /* WPA_TRACE_BFD */ | 
|  | 9864 | } | 
|  | 9865 |  | 
|  | 9866 |  | 
| Jouni Malinen | c481836 | 2015-10-04 11:45:13 +0300 | [diff] [blame] | 9867 | static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx) | 
|  | 9868 | { | 
|  | 9869 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
|  | 9870 | int i, count = (intptr_t) timeout_ctx; | 
|  | 9871 |  | 
|  | 9872 | wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages", | 
|  | 9873 | count); | 
|  | 9874 | for (i = 0; i < count; i++) { | 
|  | 9875 | wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d", | 
|  | 9876 | i + 1, count); | 
|  | 9877 | } | 
|  | 9878 | } | 
|  | 9879 |  | 
|  | 9880 |  | 
|  | 9881 | static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd) | 
|  | 9882 | { | 
|  | 9883 | int count; | 
|  | 9884 |  | 
|  | 9885 | count = atoi(cmd); | 
|  | 9886 | if (count <= 0) | 
|  | 9887 | return -1; | 
|  | 9888 |  | 
|  | 9889 | return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s, | 
|  | 9890 | (void *) (intptr_t) count); | 
|  | 9891 | } | 
|  | 9892 |  | 
| Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 9893 |  | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9894 | static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s, | 
|  | 9895 | const char *cmd) | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9896 | { | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9897 | struct wpabuf *buf; | 
|  | 9898 | size_t len; | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9899 |  | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9900 | len = os_strlen(cmd); | 
|  | 9901 | if (len & 1) | 
|  | 9902 | return -1; | 
|  | 9903 | len /= 2; | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9904 |  | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9905 | if (len == 0) { | 
|  | 9906 | buf = NULL; | 
|  | 9907 | } else { | 
|  | 9908 | buf = wpabuf_alloc(len); | 
|  | 9909 | if (buf == NULL) | 
|  | 9910 | return -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9911 |  | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9912 | if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) { | 
|  | 9913 | wpabuf_free(buf); | 
|  | 9914 | return -1; | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9915 | } | 
|  | 9916 | } | 
|  | 9917 |  | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9918 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf); | 
|  | 9919 | return 0; | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9920 | } | 
|  | 9921 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9922 |  | 
|  | 9923 | static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s) | 
|  | 9924 | { | 
|  | 9925 | u8 zero[WPA_TK_MAX_LEN]; | 
|  | 9926 |  | 
|  | 9927 | if (wpa_s->last_tk_alg == WPA_ALG_NONE) | 
|  | 9928 | return -1; | 
|  | 9929 |  | 
|  | 9930 | wpa_printf(MSG_INFO, "TESTING: Reset PN"); | 
|  | 9931 | os_memset(zero, 0, sizeof(zero)); | 
|  | 9932 |  | 
|  | 9933 | /* First, use a zero key to avoid any possible duplicate key avoidance | 
|  | 9934 | * in the driver. */ | 
|  | 9935 | if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr, | 
|  | 9936 | wpa_s->last_tk_key_idx, 1, zero, 6, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9937 | zero, wpa_s->last_tk_len, | 
|  | 9938 | KEY_FLAG_PAIRWISE_RX_TX) < 0) | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9939 | return -1; | 
|  | 9940 |  | 
|  | 9941 | /* Set the previously configured key to reset its TSC/RSC */ | 
|  | 9942 | return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr, | 
|  | 9943 | wpa_s->last_tk_key_idx, 1, zero, 6, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9944 | wpa_s->last_tk, wpa_s->last_tk_len, | 
|  | 9945 | KEY_FLAG_PAIRWISE_RX_TX); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9946 | } | 
|  | 9947 |  | 
|  | 9948 |  | 
|  | 9949 | static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd) | 
|  | 9950 | { | 
|  | 9951 | const char *pos = cmd; | 
|  | 9952 | int error, pairwise; | 
|  | 9953 |  | 
|  | 9954 | error = atoi(pos); | 
|  | 9955 | pos = os_strchr(pos, ' '); | 
|  | 9956 | if (!pos) | 
|  | 9957 | return -1; | 
|  | 9958 | pairwise = atoi(pos); | 
|  | 9959 | wpa_sm_key_request(wpa_s->wpa, error, pairwise); | 
|  | 9960 | return 0; | 
|  | 9961 | } | 
|  | 9962 |  | 
|  | 9963 |  | 
|  | 9964 | static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s) | 
|  | 9965 | { | 
|  | 9966 | #ifdef CONFIG_SME | 
|  | 9967 | struct wpa_driver_associate_params params; | 
|  | 9968 | int ret; | 
|  | 9969 |  | 
|  | 9970 | os_memset(¶ms, 0, sizeof(params)); | 
|  | 9971 | params.bssid = wpa_s->bssid; | 
|  | 9972 | params.ssid = wpa_s->sme.ssid; | 
|  | 9973 | params.ssid_len = wpa_s->sme.ssid_len; | 
|  | 9974 | params.freq.freq = wpa_s->sme.freq; | 
|  | 9975 | if (wpa_s->last_assoc_req_wpa_ie) { | 
|  | 9976 | params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie); | 
|  | 9977 | params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie); | 
|  | 9978 | } | 
|  | 9979 | params.pairwise_suite = wpa_s->pairwise_cipher; | 
|  | 9980 | params.group_suite = wpa_s->group_cipher; | 
|  | 9981 | params.mgmt_group_suite = wpa_s->mgmt_group_cipher; | 
|  | 9982 | params.key_mgmt_suite = wpa_s->key_mgmt; | 
|  | 9983 | params.wpa_proto = wpa_s->wpa_proto; | 
|  | 9984 | params.mgmt_frame_protection = wpa_s->sme.mfp; | 
|  | 9985 | params.rrm_used = wpa_s->rrm.rrm_used; | 
|  | 9986 | if (wpa_s->sme.prev_bssid_set) | 
|  | 9987 | params.prev_bssid = wpa_s->sme.prev_bssid; | 
|  | 9988 | wpa_printf(MSG_INFO, "TESTING: Resend association request"); | 
|  | 9989 | ret = wpa_drv_associate(wpa_s, ¶ms); | 
|  | 9990 | wpa_s->testing_resend_assoc = 1; | 
|  | 9991 | return ret; | 
|  | 9992 | #else /* CONFIG_SME */ | 
|  | 9993 | return -1; | 
|  | 9994 | #endif /* CONFIG_SME */ | 
|  | 9995 | } | 
|  | 9996 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9997 |  | 
|  | 9998 | static int wpas_ctrl_iface_send_twt_setup(struct wpa_supplicant *wpa_s, | 
|  | 9999 | const char *cmd) | 
|  | 10000 | { | 
|  | 10001 | u8 dtok = 1; | 
|  | 10002 | int exponent = 10; | 
|  | 10003 | int mantissa = 8192; | 
|  | 10004 | u8 min_twt = 255; | 
|  | 10005 | unsigned long long twt = 0; | 
|  | 10006 | bool requestor = true; | 
|  | 10007 | int setup_cmd = 0; | 
|  | 10008 | bool trigger = true; | 
|  | 10009 | bool implicit = true; | 
|  | 10010 | bool flow_type = true; | 
|  | 10011 | int flow_id = 0; | 
|  | 10012 | bool protection = false; | 
|  | 10013 | u8 twt_channel = 0; | 
| Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 10014 | u8 control = BIT(4); /* Control field (IEEE Std 802.11ax-2021, | 
|  | 10015 | * Figure 9-687 - Control field format): | 
|  | 10016 | * B4 = TWT Information Frame Disabled */ | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10017 | const char *tok_s; | 
|  | 10018 |  | 
|  | 10019 | tok_s = os_strstr(cmd, " dialog="); | 
|  | 10020 | if (tok_s) | 
|  | 10021 | dtok = atoi(tok_s + os_strlen(" dialog=")); | 
|  | 10022 |  | 
|  | 10023 | tok_s = os_strstr(cmd, " exponent="); | 
|  | 10024 | if (tok_s) | 
|  | 10025 | exponent = atoi(tok_s + os_strlen(" exponent=")); | 
|  | 10026 |  | 
|  | 10027 | tok_s = os_strstr(cmd, " mantissa="); | 
|  | 10028 | if (tok_s) | 
|  | 10029 | mantissa = atoi(tok_s + os_strlen(" mantissa=")); | 
|  | 10030 |  | 
|  | 10031 | tok_s = os_strstr(cmd, " min_twt="); | 
|  | 10032 | if (tok_s) | 
|  | 10033 | min_twt = atoi(tok_s + os_strlen(" min_twt=")); | 
|  | 10034 |  | 
|  | 10035 | tok_s = os_strstr(cmd, " setup_cmd="); | 
|  | 10036 | if (tok_s) | 
|  | 10037 | setup_cmd = atoi(tok_s + os_strlen(" setup_cmd=")); | 
|  | 10038 |  | 
|  | 10039 | tok_s = os_strstr(cmd, " twt="); | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 10040 | if (tok_s && | 
|  | 10041 | sscanf(tok_s + os_strlen(" twt="), "%llu", &twt) != 1) | 
|  | 10042 | return -1; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10043 |  | 
|  | 10044 | tok_s = os_strstr(cmd, " requestor="); | 
|  | 10045 | if (tok_s) | 
|  | 10046 | requestor = atoi(tok_s + os_strlen(" requestor=")); | 
|  | 10047 |  | 
|  | 10048 | tok_s = os_strstr(cmd, " trigger="); | 
|  | 10049 | if (tok_s) | 
|  | 10050 | trigger = atoi(tok_s + os_strlen(" trigger=")); | 
|  | 10051 |  | 
|  | 10052 | tok_s = os_strstr(cmd, " implicit="); | 
|  | 10053 | if (tok_s) | 
|  | 10054 | implicit = atoi(tok_s + os_strlen(" implicit=")); | 
|  | 10055 |  | 
|  | 10056 | tok_s = os_strstr(cmd, " flow_type="); | 
|  | 10057 | if (tok_s) | 
|  | 10058 | flow_type = atoi(tok_s + os_strlen(" flow_type=")); | 
|  | 10059 |  | 
|  | 10060 | tok_s = os_strstr(cmd, " flow_id="); | 
|  | 10061 | if (tok_s) | 
|  | 10062 | flow_id = atoi(tok_s + os_strlen(" flow_id=")); | 
|  | 10063 |  | 
|  | 10064 | tok_s = os_strstr(cmd, " protection="); | 
|  | 10065 | if (tok_s) | 
|  | 10066 | protection = atoi(tok_s + os_strlen(" protection=")); | 
|  | 10067 |  | 
|  | 10068 | tok_s = os_strstr(cmd, " twt_channel="); | 
|  | 10069 | if (tok_s) | 
|  | 10070 | twt_channel = atoi(tok_s + os_strlen(" twt_channel=")); | 
|  | 10071 |  | 
|  | 10072 | tok_s = os_strstr(cmd, " control="); | 
|  | 10073 | if (tok_s) | 
|  | 10074 | control = atoi(tok_s + os_strlen(" control=")); | 
|  | 10075 |  | 
|  | 10076 | return wpas_twt_send_setup(wpa_s, dtok, exponent, mantissa, min_twt, | 
|  | 10077 | setup_cmd, twt, requestor, trigger, implicit, | 
|  | 10078 | flow_type, flow_id, protection, twt_channel, | 
|  | 10079 | control); | 
|  | 10080 | } | 
|  | 10081 |  | 
|  | 10082 |  | 
|  | 10083 | static int wpas_ctrl_iface_send_twt_teardown(struct wpa_supplicant *wpa_s, | 
|  | 10084 | const char *cmd) | 
|  | 10085 | { | 
|  | 10086 | u8 flags = 0x1; | 
|  | 10087 | const char *tok_s; | 
|  | 10088 |  | 
|  | 10089 | tok_s = os_strstr(cmd, " flags="); | 
|  | 10090 | if (tok_s) | 
|  | 10091 | flags = atoi(tok_s + os_strlen(" flags=")); | 
|  | 10092 |  | 
|  | 10093 | return wpas_twt_send_teardown(wpa_s, flags); | 
|  | 10094 | } | 
|  | 10095 |  | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10096 | #endif /* CONFIG_TESTING_OPTIONS */ | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10097 |  | 
|  | 10098 |  | 
|  | 10099 | static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 10100 | { | 
|  | 10101 | char *pos = cmd; | 
|  | 10102 | int frame; | 
|  | 10103 | size_t len; | 
|  | 10104 | struct wpabuf *buf; | 
|  | 10105 | struct ieee802_11_elems elems; | 
|  | 10106 |  | 
|  | 10107 | frame = atoi(pos); | 
|  | 10108 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | 
|  | 10109 | return -1; | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10110 | wpa_s = wpas_vendor_elem(wpa_s, frame); | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10111 |  | 
|  | 10112 | pos = os_strchr(pos, ' '); | 
|  | 10113 | if (pos == NULL) | 
|  | 10114 | return -1; | 
|  | 10115 | pos++; | 
|  | 10116 |  | 
|  | 10117 | len = os_strlen(pos); | 
|  | 10118 | if (len == 0) | 
|  | 10119 | return 0; | 
|  | 10120 | if (len & 1) | 
|  | 10121 | return -1; | 
|  | 10122 | len /= 2; | 
|  | 10123 |  | 
|  | 10124 | buf = wpabuf_alloc(len); | 
|  | 10125 | if (buf == NULL) | 
|  | 10126 | return -1; | 
|  | 10127 |  | 
|  | 10128 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { | 
|  | 10129 | wpabuf_free(buf); | 
|  | 10130 | return -1; | 
|  | 10131 | } | 
|  | 10132 |  | 
|  | 10133 | if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) == | 
|  | 10134 | ParseFailed) { | 
|  | 10135 | wpabuf_free(buf); | 
|  | 10136 | return -1; | 
|  | 10137 | } | 
|  | 10138 |  | 
|  | 10139 | if (wpa_s->vendor_elem[frame] == NULL) { | 
|  | 10140 | wpa_s->vendor_elem[frame] = buf; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10141 | goto update_ies; | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10142 | } | 
|  | 10143 |  | 
|  | 10144 | if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) { | 
|  | 10145 | wpabuf_free(buf); | 
|  | 10146 | return -1; | 
|  | 10147 | } | 
|  | 10148 |  | 
|  | 10149 | wpabuf_put_buf(wpa_s->vendor_elem[frame], buf); | 
|  | 10150 | wpabuf_free(buf); | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10151 |  | 
|  | 10152 | update_ies: | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10153 | wpas_vendor_elem_update(wpa_s); | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10154 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10155 | if (frame == VENDOR_ELEM_PROBE_REQ || | 
|  | 10156 | frame == VENDOR_ELEM_PROBE_REQ_P2P) | 
|  | 10157 | wpa_supplicant_set_default_scan_ies(wpa_s); | 
|  | 10158 |  | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10159 | return 0; | 
|  | 10160 | } | 
|  | 10161 |  | 
|  | 10162 |  | 
|  | 10163 | static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd, | 
|  | 10164 | char *buf, size_t buflen) | 
|  | 10165 | { | 
|  | 10166 | int frame = atoi(cmd); | 
|  | 10167 |  | 
|  | 10168 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | 
|  | 10169 | return -1; | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10170 | wpa_s = wpas_vendor_elem(wpa_s, frame); | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10171 |  | 
|  | 10172 | if (wpa_s->vendor_elem[frame] == NULL) | 
|  | 10173 | return 0; | 
|  | 10174 |  | 
|  | 10175 | return wpa_snprintf_hex(buf, buflen, | 
|  | 10176 | wpabuf_head_u8(wpa_s->vendor_elem[frame]), | 
|  | 10177 | wpabuf_len(wpa_s->vendor_elem[frame])); | 
|  | 10178 | } | 
|  | 10179 |  | 
|  | 10180 |  | 
|  | 10181 | static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 10182 | { | 
|  | 10183 | char *pos = cmd; | 
|  | 10184 | int frame; | 
|  | 10185 | size_t len; | 
|  | 10186 | u8 *buf; | 
|  | 10187 | struct ieee802_11_elems elems; | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10188 | int res; | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10189 |  | 
|  | 10190 | frame = atoi(pos); | 
|  | 10191 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) | 
|  | 10192 | return -1; | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10193 | wpa_s = wpas_vendor_elem(wpa_s, frame); | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10194 |  | 
|  | 10195 | pos = os_strchr(pos, ' '); | 
|  | 10196 | if (pos == NULL) | 
|  | 10197 | return -1; | 
|  | 10198 | pos++; | 
|  | 10199 |  | 
|  | 10200 | if (*pos == '*') { | 
|  | 10201 | wpabuf_free(wpa_s->vendor_elem[frame]); | 
|  | 10202 | wpa_s->vendor_elem[frame] = NULL; | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10203 | wpas_vendor_elem_update(wpa_s); | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10204 | return 0; | 
|  | 10205 | } | 
|  | 10206 |  | 
|  | 10207 | if (wpa_s->vendor_elem[frame] == NULL) | 
|  | 10208 | return -1; | 
|  | 10209 |  | 
|  | 10210 | len = os_strlen(pos); | 
|  | 10211 | if (len == 0) | 
|  | 10212 | return 0; | 
|  | 10213 | if (len & 1) | 
|  | 10214 | return -1; | 
|  | 10215 | len /= 2; | 
|  | 10216 |  | 
|  | 10217 | buf = os_malloc(len); | 
|  | 10218 | if (buf == NULL) | 
|  | 10219 | return -1; | 
|  | 10220 |  | 
|  | 10221 | if (hexstr2bin(pos, buf, len) < 0) { | 
|  | 10222 | os_free(buf); | 
|  | 10223 | return -1; | 
|  | 10224 | } | 
|  | 10225 |  | 
|  | 10226 | if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) { | 
|  | 10227 | os_free(buf); | 
|  | 10228 | return -1; | 
|  | 10229 | } | 
|  | 10230 |  | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10231 | res = wpas_vendor_elem_remove(wpa_s, frame, buf, len); | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10232 | os_free(buf); | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 10233 | return res; | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 10234 | } | 
|  | 10235 |  | 
|  | 10236 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10237 | static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep) | 
|  | 10238 | { | 
|  | 10239 | struct wpa_supplicant *wpa_s = ctx; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10240 | size_t len; | 
|  | 10241 | const u8 *data; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10242 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10243 | /* | 
|  | 10244 | * Neighbor Report element (IEEE P802.11-REVmc/D5.0) | 
|  | 10245 | * BSSID[6] | 
|  | 10246 | * BSSID Information[4] | 
|  | 10247 | * Operating Class[1] | 
|  | 10248 | * Channel Number[1] | 
|  | 10249 | * PHY Type[1] | 
|  | 10250 | * Optional Subelements[variable] | 
|  | 10251 | */ | 
|  | 10252 | #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1) | 
|  | 10253 |  | 
|  | 10254 | if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10255 | wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED); | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10256 | goto out; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10257 | } | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10258 |  | 
|  | 10259 | data = wpabuf_head_u8(neighbor_rep); | 
|  | 10260 | len = wpabuf_len(neighbor_rep); | 
|  | 10261 |  | 
|  | 10262 | while (len >= 2 + NR_IE_MIN_LEN) { | 
|  | 10263 | const u8 *nr; | 
|  | 10264 | char lci[256 * 2 + 1]; | 
|  | 10265 | char civic[256 * 2 + 1]; | 
|  | 10266 | u8 nr_len = data[1]; | 
|  | 10267 | const u8 *pos = data, *end; | 
|  | 10268 |  | 
|  | 10269 | if (pos[0] != WLAN_EID_NEIGHBOR_REPORT || | 
|  | 10270 | nr_len < NR_IE_MIN_LEN) { | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10271 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 10272 | "CTRL: Invalid Neighbor Report element: id=%u len=%u", | 
|  | 10273 | data[0], nr_len); | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10274 | goto out; | 
|  | 10275 | } | 
|  | 10276 |  | 
|  | 10277 | if (2U + nr_len > len) { | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10278 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 10279 | "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u", | 
|  | 10280 | data[0], len, nr_len); | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10281 | goto out; | 
|  | 10282 | } | 
|  | 10283 | pos += 2; | 
|  | 10284 | end = pos + nr_len; | 
|  | 10285 |  | 
|  | 10286 | nr = pos; | 
|  | 10287 | pos += NR_IE_MIN_LEN; | 
|  | 10288 |  | 
|  | 10289 | lci[0] = '\0'; | 
|  | 10290 | civic[0] = '\0'; | 
|  | 10291 | while (end - pos > 2) { | 
|  | 10292 | u8 s_id, s_len; | 
|  | 10293 |  | 
|  | 10294 | s_id = *pos++; | 
|  | 10295 | s_len = *pos++; | 
|  | 10296 | if (s_len > end - pos) | 
|  | 10297 | goto out; | 
|  | 10298 | if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) { | 
|  | 10299 | /* Measurement Token[1] */ | 
|  | 10300 | /* Measurement Report Mode[1] */ | 
|  | 10301 | /* Measurement Type[1] */ | 
|  | 10302 | /* Measurement Report[variable] */ | 
|  | 10303 | switch (pos[2]) { | 
|  | 10304 | case MEASURE_TYPE_LCI: | 
|  | 10305 | if (lci[0]) | 
|  | 10306 | break; | 
|  | 10307 | wpa_snprintf_hex(lci, sizeof(lci), | 
|  | 10308 | pos, s_len); | 
|  | 10309 | break; | 
|  | 10310 | case MEASURE_TYPE_LOCATION_CIVIC: | 
|  | 10311 | if (civic[0]) | 
|  | 10312 | break; | 
|  | 10313 | wpa_snprintf_hex(civic, sizeof(civic), | 
|  | 10314 | pos, s_len); | 
|  | 10315 | break; | 
|  | 10316 | } | 
|  | 10317 | } | 
|  | 10318 |  | 
|  | 10319 | pos += s_len; | 
|  | 10320 | } | 
|  | 10321 |  | 
|  | 10322 | wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED | 
|  | 10323 | "bssid=" MACSTR | 
|  | 10324 | " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s", | 
|  | 10325 | MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN), | 
|  | 10326 | nr[ETH_ALEN + 4], nr[ETH_ALEN + 5], | 
|  | 10327 | nr[ETH_ALEN + 6], | 
|  | 10328 | lci[0] ? " lci=" : "", lci, | 
|  | 10329 | civic[0] ? " civic=" : "", civic); | 
|  | 10330 |  | 
|  | 10331 | data = end; | 
|  | 10332 | len -= 2 + nr_len; | 
|  | 10333 | } | 
|  | 10334 |  | 
|  | 10335 | out: | 
|  | 10336 | wpabuf_free(neighbor_rep); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10337 | } | 
|  | 10338 |  | 
|  | 10339 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10340 | static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s, | 
|  | 10341 | char *cmd) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10342 | { | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10343 | struct wpa_ssid_value ssid, *ssid_p = NULL; | 
|  | 10344 | int ret, lci = 0, civic = 0; | 
|  | 10345 | char *ssid_s; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10346 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10347 | ssid_s = os_strstr(cmd, "ssid="); | 
|  | 10348 | if (ssid_s) { | 
|  | 10349 | if (ssid_parse(ssid_s + 5, &ssid)) { | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10350 | wpa_msg(wpa_s, MSG_INFO, | 
|  | 10351 | "CTRL: Send Neighbor Report: bad SSID"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10352 | return -1; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10353 | } | 
|  | 10354 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10355 | ssid_p = &ssid; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10356 |  | 
|  | 10357 | /* | 
|  | 10358 | * Move cmd after the SSID text that may include "lci" or | 
|  | 10359 | * "civic". | 
|  | 10360 | */ | 
|  | 10361 | cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' '); | 
|  | 10362 | if (cmd) | 
|  | 10363 | cmd++; | 
|  | 10364 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10365 | } | 
|  | 10366 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10367 | if (cmd && os_strstr(cmd, "lci")) | 
|  | 10368 | lci = 1; | 
|  | 10369 |  | 
|  | 10370 | if (cmd && os_strstr(cmd, "civic")) | 
|  | 10371 | civic = 1; | 
|  | 10372 |  | 
|  | 10373 | 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] | 10374 | wpas_ctrl_neighbor_rep_cb, | 
|  | 10375 | wpa_s); | 
|  | 10376 |  | 
|  | 10377 | return ret; | 
|  | 10378 | } | 
|  | 10379 |  | 
|  | 10380 |  | 
|  | 10381 | static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s) | 
|  | 10382 | { | 
|  | 10383 | eapol_sm_erp_flush(wpa_s->eapol); | 
|  | 10384 | return 0; | 
|  | 10385 | } | 
|  | 10386 |  | 
|  | 10387 |  | 
|  | 10388 | static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s, | 
|  | 10389 | char *cmd) | 
|  | 10390 | { | 
|  | 10391 | char *token, *context = NULL; | 
|  | 10392 | unsigned int enable = ~0, type = 0; | 
|  | 10393 | u8 _addr[ETH_ALEN], _mask[ETH_ALEN]; | 
|  | 10394 | u8 *addr = NULL, *mask = NULL; | 
|  | 10395 |  | 
|  | 10396 | while ((token = str_token(cmd, " ", &context))) { | 
|  | 10397 | if (os_strcasecmp(token, "scan") == 0) { | 
|  | 10398 | type |= MAC_ADDR_RAND_SCAN; | 
|  | 10399 | } else if (os_strcasecmp(token, "sched") == 0) { | 
|  | 10400 | type |= MAC_ADDR_RAND_SCHED_SCAN; | 
|  | 10401 | } else if (os_strcasecmp(token, "pno") == 0) { | 
|  | 10402 | type |= MAC_ADDR_RAND_PNO; | 
|  | 10403 | } else if (os_strcasecmp(token, "all") == 0) { | 
|  | 10404 | type = wpa_s->mac_addr_rand_supported; | 
|  | 10405 | } else if (os_strncasecmp(token, "enable=", 7) == 0) { | 
|  | 10406 | enable = atoi(token + 7); | 
|  | 10407 | } else if (os_strncasecmp(token, "addr=", 5) == 0) { | 
|  | 10408 | addr = _addr; | 
|  | 10409 | if (hwaddr_aton(token + 5, addr)) { | 
|  | 10410 | wpa_printf(MSG_INFO, | 
|  | 10411 | "CTRL: Invalid MAC address: %s", | 
|  | 10412 | token); | 
|  | 10413 | return -1; | 
|  | 10414 | } | 
|  | 10415 | } else if (os_strncasecmp(token, "mask=", 5) == 0) { | 
|  | 10416 | mask = _mask; | 
|  | 10417 | if (hwaddr_aton(token + 5, mask)) { | 
|  | 10418 | wpa_printf(MSG_INFO, | 
|  | 10419 | "CTRL: Invalid MAC address mask: %s", | 
|  | 10420 | token); | 
|  | 10421 | return -1; | 
|  | 10422 | } | 
|  | 10423 | } else { | 
|  | 10424 | wpa_printf(MSG_INFO, | 
|  | 10425 | "CTRL: Invalid MAC_RAND_SCAN parameter: %s", | 
|  | 10426 | token); | 
|  | 10427 | return -1; | 
|  | 10428 | } | 
|  | 10429 | } | 
|  | 10430 |  | 
|  | 10431 | if (!type) { | 
|  | 10432 | wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified"); | 
|  | 10433 | return -1; | 
|  | 10434 | } | 
|  | 10435 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10436 | if (enable > 1) { | 
|  | 10437 | wpa_printf(MSG_INFO, | 
|  | 10438 | "CTRL: MAC_RAND_SCAN enable=<0/1> not specified"); | 
|  | 10439 | return -1; | 
|  | 10440 | } | 
|  | 10441 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10442 | if (!enable) | 
|  | 10443 | return wpas_disable_mac_addr_randomization(wpa_s, type); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10444 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10445 | return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10446 | } | 
|  | 10447 |  | 
|  | 10448 |  | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 10449 | static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s, | 
|  | 10450 | char *buf, size_t buflen) | 
|  | 10451 | { | 
|  | 10452 | size_t reply_len; | 
|  | 10453 |  | 
|  | 10454 | reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen); | 
|  | 10455 | #ifdef CONFIG_AP | 
|  | 10456 | reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len], | 
|  | 10457 | buflen - reply_len); | 
|  | 10458 | #endif /* CONFIG_AP */ | 
|  | 10459 | return reply_len; | 
|  | 10460 | } | 
|  | 10461 |  | 
|  | 10462 |  | 
|  | 10463 | static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s) | 
|  | 10464 | { | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10465 | ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE); | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 10466 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); | 
|  | 10467 | #ifdef CONFIG_AP | 
|  | 10468 | wpas_ap_pmksa_cache_flush(wpa_s); | 
|  | 10469 | #endif /* CONFIG_AP */ | 
|  | 10470 | } | 
|  | 10471 |  | 
|  | 10472 |  | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10473 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL | 
|  | 10474 |  | 
|  | 10475 | static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s, | 
|  | 10476 | const char *cmd, char *buf, size_t buflen) | 
|  | 10477 | { | 
|  | 10478 | struct rsn_pmksa_cache_entry *entry; | 
|  | 10479 | struct wpa_ssid *ssid; | 
|  | 10480 | char *pos, *pos2, *end; | 
|  | 10481 | int ret; | 
|  | 10482 | struct os_reltime now; | 
|  | 10483 |  | 
|  | 10484 | ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd)); | 
|  | 10485 | if (!ssid) | 
|  | 10486 | return -1; | 
|  | 10487 |  | 
|  | 10488 | pos = buf; | 
|  | 10489 | end = buf + buflen; | 
|  | 10490 |  | 
|  | 10491 | os_get_reltime(&now); | 
|  | 10492 |  | 
|  | 10493 | /* | 
|  | 10494 | * Entry format: | 
|  | 10495 | * <BSSID> <PMKID> <PMK> <reauth_time in seconds> | 
|  | 10496 | * <expiration in seconds> <akmp> <opportunistic> | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10497 | * [FILS Cache Identifier] | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10498 | */ | 
|  | 10499 |  | 
|  | 10500 | for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry; | 
|  | 10501 | entry = entry->next) { | 
|  | 10502 | if (entry->network_ctx != ssid) | 
|  | 10503 | continue; | 
|  | 10504 |  | 
|  | 10505 | pos2 = pos; | 
|  | 10506 | ret = os_snprintf(pos2, end - pos2, MACSTR " ", | 
|  | 10507 | MAC2STR(entry->aa)); | 
|  | 10508 | if (os_snprintf_error(end - pos2, ret)) | 
|  | 10509 | break; | 
|  | 10510 | pos2 += ret; | 
|  | 10511 |  | 
|  | 10512 | pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid, | 
|  | 10513 | PMKID_LEN); | 
|  | 10514 |  | 
|  | 10515 | ret = os_snprintf(pos2, end - pos2, " "); | 
|  | 10516 | if (os_snprintf_error(end - pos2, ret)) | 
|  | 10517 | break; | 
|  | 10518 | pos2 += ret; | 
|  | 10519 |  | 
|  | 10520 | pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk, | 
|  | 10521 | entry->pmk_len); | 
|  | 10522 |  | 
|  | 10523 | ret = os_snprintf(pos2, end - pos2, " %d %d %d %d", | 
|  | 10524 | (int) (entry->reauth_time - now.sec), | 
|  | 10525 | (int) (entry->expiration - now.sec), | 
|  | 10526 | entry->akmp, | 
|  | 10527 | entry->opportunistic); | 
|  | 10528 | if (os_snprintf_error(end - pos2, ret)) | 
|  | 10529 | break; | 
|  | 10530 | pos2 += ret; | 
|  | 10531 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10532 | if (entry->fils_cache_id_set) { | 
|  | 10533 | ret = os_snprintf(pos2, end - pos2, " %02x%02x", | 
|  | 10534 | entry->fils_cache_id[0], | 
|  | 10535 | entry->fils_cache_id[1]); | 
|  | 10536 | if (os_snprintf_error(end - pos2, ret)) | 
|  | 10537 | break; | 
|  | 10538 | pos2 += ret; | 
|  | 10539 | } | 
|  | 10540 |  | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10541 | ret = os_snprintf(pos2, end - pos2, "\n"); | 
|  | 10542 | if (os_snprintf_error(end - pos2, ret)) | 
|  | 10543 | break; | 
|  | 10544 | pos2 += ret; | 
|  | 10545 |  | 
|  | 10546 | pos = pos2; | 
|  | 10547 | } | 
|  | 10548 |  | 
|  | 10549 | return pos - buf; | 
|  | 10550 | } | 
|  | 10551 |  | 
|  | 10552 |  | 
|  | 10553 | static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s, | 
|  | 10554 | char *cmd) | 
|  | 10555 | { | 
|  | 10556 | struct rsn_pmksa_cache_entry *entry; | 
|  | 10557 | struct wpa_ssid *ssid; | 
|  | 10558 | char *pos, *pos2; | 
|  | 10559 | int ret = -1; | 
|  | 10560 | struct os_reltime now; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10561 | int reauth_time = 0, expiration = 0, i; | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10562 |  | 
|  | 10563 | /* | 
|  | 10564 | * Entry format: | 
|  | 10565 | * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds> | 
|  | 10566 | * <expiration in seconds> <akmp> <opportunistic> | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10567 | * [FILS Cache Identifier] | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10568 | */ | 
|  | 10569 |  | 
|  | 10570 | ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd)); | 
|  | 10571 | if (!ssid) | 
|  | 10572 | return -1; | 
|  | 10573 |  | 
|  | 10574 | pos = os_strchr(cmd, ' '); | 
|  | 10575 | if (!pos) | 
|  | 10576 | return -1; | 
|  | 10577 | pos++; | 
|  | 10578 |  | 
|  | 10579 | entry = os_zalloc(sizeof(*entry)); | 
|  | 10580 | if (!entry) | 
|  | 10581 | return -1; | 
|  | 10582 |  | 
|  | 10583 | if (hwaddr_aton(pos, entry->aa)) | 
|  | 10584 | goto fail; | 
|  | 10585 |  | 
|  | 10586 | pos = os_strchr(pos, ' '); | 
|  | 10587 | if (!pos) | 
|  | 10588 | goto fail; | 
|  | 10589 | pos++; | 
|  | 10590 |  | 
|  | 10591 | if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0) | 
|  | 10592 | goto fail; | 
|  | 10593 |  | 
|  | 10594 | pos = os_strchr(pos, ' '); | 
|  | 10595 | if (!pos) | 
|  | 10596 | goto fail; | 
|  | 10597 | pos++; | 
|  | 10598 |  | 
|  | 10599 | pos2 = os_strchr(pos, ' '); | 
|  | 10600 | if (!pos2) | 
|  | 10601 | goto fail; | 
|  | 10602 | entry->pmk_len = (pos2 - pos) / 2; | 
|  | 10603 | if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX || | 
|  | 10604 | hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0) | 
|  | 10605 | goto fail; | 
|  | 10606 |  | 
|  | 10607 | pos = os_strchr(pos, ' '); | 
|  | 10608 | if (!pos) | 
|  | 10609 | goto fail; | 
|  | 10610 | pos++; | 
|  | 10611 |  | 
|  | 10612 | if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration, | 
|  | 10613 | &entry->akmp, &entry->opportunistic) != 4) | 
|  | 10614 | goto fail; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10615 | if (reauth_time > expiration) | 
|  | 10616 | goto fail; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10617 | for (i = 0; i < 4; i++) { | 
|  | 10618 | pos = os_strchr(pos, ' '); | 
|  | 10619 | if (!pos) { | 
|  | 10620 | if (i < 3) | 
|  | 10621 | goto fail; | 
|  | 10622 | break; | 
|  | 10623 | } | 
|  | 10624 | pos++; | 
|  | 10625 | } | 
|  | 10626 | if (pos) { | 
|  | 10627 | if (hexstr2bin(pos, entry->fils_cache_id, | 
|  | 10628 | FILS_CACHE_ID_LEN) < 0) | 
|  | 10629 | goto fail; | 
|  | 10630 | entry->fils_cache_id_set = 1; | 
|  | 10631 | } | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10632 | os_get_reltime(&now); | 
|  | 10633 | entry->expiration = now.sec + expiration; | 
|  | 10634 | entry->reauth_time = now.sec + reauth_time; | 
|  | 10635 |  | 
|  | 10636 | entry->network_ctx = ssid; | 
|  | 10637 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10638 | entry->external = true; | 
|  | 10639 |  | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10640 | wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry); | 
|  | 10641 | entry = NULL; | 
|  | 10642 | ret = 0; | 
|  | 10643 | fail: | 
|  | 10644 | os_free(entry); | 
|  | 10645 | return ret; | 
|  | 10646 | } | 
|  | 10647 |  | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10648 |  | 
|  | 10649 | #ifdef CONFIG_MESH | 
|  | 10650 |  | 
|  | 10651 | static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s, | 
|  | 10652 | const char *cmd, char *buf, | 
|  | 10653 | size_t buflen) | 
|  | 10654 | { | 
|  | 10655 | u8 spa[ETH_ALEN]; | 
|  | 10656 |  | 
|  | 10657 | if (!wpa_s->ifmsh) | 
|  | 10658 | return -1; | 
|  | 10659 |  | 
|  | 10660 | if (os_strcasecmp(cmd, "any") == 0) | 
|  | 10661 | return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen); | 
|  | 10662 |  | 
|  | 10663 | if (hwaddr_aton(cmd, spa)) | 
|  | 10664 | return -1; | 
|  | 10665 |  | 
|  | 10666 | return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen); | 
|  | 10667 | } | 
|  | 10668 |  | 
|  | 10669 |  | 
|  | 10670 | static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s, | 
|  | 10671 | char *cmd) | 
|  | 10672 | { | 
|  | 10673 | /* | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10674 | * We do not check mesh interface existence because PMKSA should be | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10675 | * stored before wpa_s->ifmsh creation to suppress commit message | 
|  | 10676 | * creation. | 
|  | 10677 | */ | 
|  | 10678 | return wpas_ap_pmksa_cache_add_external(wpa_s, cmd); | 
|  | 10679 | } | 
|  | 10680 |  | 
|  | 10681 | #endif /* CONFIG_MESH */ | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 10682 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ | 
|  | 10683 |  | 
|  | 10684 |  | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 10685 | #ifdef CONFIG_FILS | 
|  | 10686 | static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s, | 
|  | 10687 | const char *cmd) | 
|  | 10688 | { | 
|  | 10689 | struct fils_hlp_req *req; | 
|  | 10690 | const char *pos; | 
|  | 10691 |  | 
|  | 10692 | /* format: <dst> <packet starting from ethertype> */ | 
|  | 10693 |  | 
|  | 10694 | req = os_zalloc(sizeof(*req)); | 
|  | 10695 | if (!req) | 
|  | 10696 | return -1; | 
|  | 10697 |  | 
|  | 10698 | if (hwaddr_aton(cmd, req->dst)) | 
|  | 10699 | goto fail; | 
|  | 10700 |  | 
|  | 10701 | pos = os_strchr(cmd, ' '); | 
|  | 10702 | if (!pos) | 
|  | 10703 | goto fail; | 
|  | 10704 | pos++; | 
|  | 10705 | req->pkt = wpabuf_parse_bin(pos); | 
|  | 10706 | if (!req->pkt) | 
|  | 10707 | goto fail; | 
|  | 10708 |  | 
|  | 10709 | dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list); | 
|  | 10710 | return 0; | 
|  | 10711 | fail: | 
|  | 10712 | wpabuf_free(req->pkt); | 
|  | 10713 | os_free(req); | 
|  | 10714 | return -1; | 
|  | 10715 | } | 
|  | 10716 | #endif /* CONFIG_FILS */ | 
|  | 10717 |  | 
|  | 10718 |  | 
| Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 10719 | int wpas_ctrl_cmd_debug_level(const char *cmd) | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10720 | { | 
|  | 10721 | if (os_strcmp(cmd, "PING") == 0 || | 
|  | 10722 | os_strncmp(cmd, "BSS ", 4) == 0 || | 
|  | 10723 | os_strncmp(cmd, "GET_NETWORK ", 12) == 0 || | 
|  | 10724 | os_strncmp(cmd, "STATUS", 6) == 0 || | 
|  | 10725 | os_strncmp(cmd, "STA ", 4) == 0 || | 
|  | 10726 | os_strncmp(cmd, "STA-", 4) == 0) | 
|  | 10727 | return MSG_EXCESSIVE; | 
|  | 10728 | return MSG_DEBUG; | 
|  | 10729 | } | 
|  | 10730 |  | 
|  | 10731 |  | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10732 | static int wpas_ctrl_iface_configure_mscs(struct wpa_supplicant *wpa_s, | 
|  | 10733 | const char *cmd) | 
|  | 10734 | { | 
|  | 10735 | size_t frame_classifier_len; | 
|  | 10736 | const char *pos, *end; | 
|  | 10737 | struct robust_av_data *robust_av = &wpa_s->robust_av; | 
|  | 10738 | int val; | 
|  | 10739 |  | 
|  | 10740 | /* | 
|  | 10741 | * format: | 
|  | 10742 | * <add|remove|change> [up_bitmap=<hex byte>] [up_limit=<integer>] | 
|  | 10743 | * [stream_timeout=<in TUs>] [frame_classifier=<hex bytes>] | 
|  | 10744 | */ | 
|  | 10745 | os_memset(robust_av, 0, sizeof(struct robust_av_data)); | 
|  | 10746 | if (os_strncmp(cmd, "add ", 4) == 0) { | 
|  | 10747 | robust_av->request_type = SCS_REQ_ADD; | 
|  | 10748 | } else if (os_strcmp(cmd, "remove") == 0) { | 
|  | 10749 | robust_av->request_type = SCS_REQ_REMOVE; | 
|  | 10750 | robust_av->valid_config = false; | 
|  | 10751 | return wpas_send_mscs_req(wpa_s); | 
|  | 10752 | } else if (os_strncmp(cmd, "change ", 7) == 0) { | 
|  | 10753 | robust_av->request_type = SCS_REQ_CHANGE; | 
|  | 10754 | } else { | 
|  | 10755 | return -1; | 
|  | 10756 | } | 
|  | 10757 |  | 
|  | 10758 | pos = os_strstr(cmd, "up_bitmap="); | 
|  | 10759 | if (!pos) | 
|  | 10760 | return -1; | 
|  | 10761 |  | 
|  | 10762 | val = hex2byte(pos + 10); | 
|  | 10763 | if (val < 0) | 
|  | 10764 | return -1; | 
|  | 10765 | robust_av->up_bitmap = val; | 
|  | 10766 |  | 
|  | 10767 | pos = os_strstr(cmd, "up_limit="); | 
|  | 10768 | if (!pos) | 
|  | 10769 | return -1; | 
|  | 10770 |  | 
|  | 10771 | robust_av->up_limit = atoi(pos + 9); | 
|  | 10772 |  | 
|  | 10773 | pos = os_strstr(cmd, "stream_timeout="); | 
|  | 10774 | if (!pos) | 
|  | 10775 | return -1; | 
|  | 10776 |  | 
|  | 10777 | robust_av->stream_timeout = atoi(pos + 15); | 
|  | 10778 | if (robust_av->stream_timeout == 0) | 
|  | 10779 | return -1; | 
|  | 10780 |  | 
|  | 10781 | pos = os_strstr(cmd, "frame_classifier="); | 
|  | 10782 | if (!pos) | 
|  | 10783 | return -1; | 
|  | 10784 |  | 
|  | 10785 | pos += 17; | 
|  | 10786 | end = os_strchr(pos, ' '); | 
|  | 10787 | if (!end) | 
|  | 10788 | end = pos + os_strlen(pos); | 
|  | 10789 |  | 
|  | 10790 | frame_classifier_len = (end - pos) / 2; | 
|  | 10791 | if (frame_classifier_len > sizeof(robust_av->frame_classifier) || | 
|  | 10792 | hexstr2bin(pos, robust_av->frame_classifier, frame_classifier_len)) | 
|  | 10793 | return -1; | 
|  | 10794 |  | 
|  | 10795 | robust_av->frame_classifier_len = frame_classifier_len; | 
|  | 10796 | robust_av->valid_config = true; | 
|  | 10797 |  | 
|  | 10798 | return wpas_send_mscs_req(wpa_s); | 
|  | 10799 | } | 
|  | 10800 |  | 
|  | 10801 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10802 | #ifdef CONFIG_PASN | 
|  | 10803 | static int wpas_ctrl_iface_pasn_start(struct wpa_supplicant *wpa_s, char *cmd) | 
|  | 10804 | { | 
|  | 10805 | char *token, *context = NULL; | 
|  | 10806 | u8 bssid[ETH_ALEN]; | 
|  | 10807 | int akmp = -1, cipher = -1, got_bssid = 0; | 
|  | 10808 | u16 group = 0xFFFF; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10809 | u8 *comeback = NULL; | 
|  | 10810 | size_t comeback_len = 0; | 
|  | 10811 | int id = 0, ret = -1; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10812 |  | 
|  | 10813 | /* | 
|  | 10814 | * Entry format: bssid=<BSSID> akmp=<AKMP> cipher=<CIPHER> group=<group> | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10815 | *    [comeback=<hexdump>] | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10816 | */ | 
|  | 10817 | while ((token = str_token(cmd, " ", &context))) { | 
|  | 10818 | if (os_strncmp(token, "bssid=", 6) == 0) { | 
|  | 10819 | if (hwaddr_aton(token + 6, bssid)) | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10820 | goto out; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10821 | got_bssid = 1; | 
|  | 10822 | } else if (os_strcmp(token, "akmp=PASN") == 0) { | 
|  | 10823 | akmp = WPA_KEY_MGMT_PASN; | 
|  | 10824 | #ifdef CONFIG_IEEE80211R | 
|  | 10825 | } else if (os_strcmp(token, "akmp=FT-PSK") == 0) { | 
|  | 10826 | akmp = WPA_KEY_MGMT_FT_PSK; | 
|  | 10827 | } else if (os_strcmp(token, "akmp=FT-EAP-SHA384") == 0) { | 
|  | 10828 | akmp = WPA_KEY_MGMT_FT_IEEE8021X_SHA384; | 
|  | 10829 | } else if (os_strcmp(token, "akmp=FT-EAP") == 0) { | 
|  | 10830 | akmp = WPA_KEY_MGMT_FT_IEEE8021X; | 
|  | 10831 | #endif /* CONFIG_IEEE80211R */ | 
|  | 10832 | #ifdef CONFIG_SAE | 
|  | 10833 | } else if (os_strcmp(token, "akmp=SAE") == 0) { | 
|  | 10834 | akmp = WPA_KEY_MGMT_SAE; | 
|  | 10835 | #endif /* CONFIG_SAE */ | 
|  | 10836 | #ifdef CONFIG_FILS | 
|  | 10837 | } else if (os_strcmp(token, "akmp=FILS-SHA256") == 0) { | 
|  | 10838 | akmp = WPA_KEY_MGMT_FILS_SHA256; | 
|  | 10839 | } else if (os_strcmp(token, "akmp=FILS-SHA384") == 0) { | 
|  | 10840 | akmp = WPA_KEY_MGMT_FILS_SHA384; | 
|  | 10841 | #endif /* CONFIG_FILS */ | 
|  | 10842 | } else if (os_strcmp(token, "cipher=CCMP-256") == 0) { | 
|  | 10843 | cipher = WPA_CIPHER_CCMP_256; | 
|  | 10844 | } else if (os_strcmp(token, "cipher=GCMP-256") == 0) { | 
|  | 10845 | cipher = WPA_CIPHER_GCMP_256; | 
|  | 10846 | } else if (os_strcmp(token, "cipher=CCMP") == 0) { | 
|  | 10847 | cipher = WPA_CIPHER_CCMP; | 
|  | 10848 | } else if (os_strcmp(token, "cipher=GCMP") == 0) { | 
|  | 10849 | cipher = WPA_CIPHER_GCMP; | 
|  | 10850 | } else if (os_strncmp(token, "group=", 6) == 0) { | 
|  | 10851 | group = atoi(token + 6); | 
|  | 10852 | } else if (os_strncmp(token, "nid=", 4) == 0) { | 
|  | 10853 | id = atoi(token + 4); | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10854 | } else if (os_strncmp(token, "comeback=", 9) == 0) { | 
|  | 10855 | comeback_len = os_strlen(token + 9); | 
|  | 10856 | if (comeback || !comeback_len || comeback_len % 2) | 
|  | 10857 | goto out; | 
|  | 10858 |  | 
|  | 10859 | comeback_len /= 2; | 
|  | 10860 | comeback = os_malloc(comeback_len); | 
|  | 10861 | if (!comeback || | 
|  | 10862 | hexstr2bin(token + 9, comeback, comeback_len)) | 
|  | 10863 | goto out; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10864 | } else { | 
|  | 10865 | wpa_printf(MSG_DEBUG, | 
|  | 10866 | "CTRL: PASN Invalid parameter: '%s'", | 
|  | 10867 | token); | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10868 | goto out; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10869 | } | 
|  | 10870 | } | 
|  | 10871 |  | 
|  | 10872 | if (!got_bssid || akmp == -1 || cipher == -1 || group == 0xFFFF) { | 
|  | 10873 | wpa_printf(MSG_DEBUG,"CTRL: PASN missing parameter"); | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10874 | goto out; | 
|  | 10875 | } | 
|  | 10876 |  | 
|  | 10877 | ret = wpas_pasn_auth_start(wpa_s, bssid, akmp, cipher, group, id, | 
|  | 10878 | comeback, comeback_len); | 
|  | 10879 | out: | 
|  | 10880 | os_free(comeback); | 
|  | 10881 | return ret; | 
|  | 10882 | } | 
|  | 10883 |  | 
|  | 10884 |  | 
|  | 10885 | static int wpas_ctrl_iface_pasn_deauthenticate(struct wpa_supplicant *wpa_s, | 
|  | 10886 | const char *cmd) | 
|  | 10887 | { | 
|  | 10888 | u8 bssid[ETH_ALEN]; | 
|  | 10889 |  | 
|  | 10890 | if (os_strncmp(cmd, "bssid=", 6) != 0 || hwaddr_aton(cmd + 6, bssid)) { | 
|  | 10891 | wpa_printf(MSG_DEBUG, | 
|  | 10892 | "CTRL: PASN_DEAUTH without valid BSSID"); | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10893 | return -1; | 
|  | 10894 | } | 
|  | 10895 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10896 | return wpas_pasn_deauthenticate(wpa_s, bssid); | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10897 | } | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10898 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10899 | #endif /* CONFIG_PASN */ | 
|  | 10900 |  | 
|  | 10901 |  | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10902 | static int set_type4_frame_classifier(const char *cmd, | 
|  | 10903 | struct type4_params *param) | 
|  | 10904 | { | 
|  | 10905 | const char *pos, *end; | 
|  | 10906 | u8 classifier_mask = 0; | 
|  | 10907 | int ret; | 
|  | 10908 | char addr[INET6_ADDRSTRLEN]; | 
|  | 10909 | size_t alen; | 
|  | 10910 |  | 
|  | 10911 | if (os_strstr(cmd, "ip_version=ipv4")) { | 
|  | 10912 | param->ip_version = IPV4; | 
|  | 10913 | } else if (os_strstr(cmd, "ip_version=ipv6")) { | 
|  | 10914 | param->ip_version = IPV6; | 
|  | 10915 | } else { | 
|  | 10916 | wpa_printf(MSG_ERROR, "IP version missing/invalid"); | 
|  | 10917 | return -1; | 
|  | 10918 | } | 
|  | 10919 |  | 
|  | 10920 | classifier_mask |= BIT(0); | 
|  | 10921 |  | 
|  | 10922 | pos = os_strstr(cmd, "src_ip="); | 
|  | 10923 | if (pos) { | 
|  | 10924 | pos += 7; | 
|  | 10925 | end = os_strchr(pos, ' '); | 
|  | 10926 | if (!end) | 
|  | 10927 | end = pos + os_strlen(pos); | 
|  | 10928 |  | 
|  | 10929 | alen = end - pos; | 
|  | 10930 | if (alen >= INET6_ADDRSTRLEN) | 
|  | 10931 | return -1; | 
|  | 10932 | os_memcpy(addr, pos, alen); | 
|  | 10933 | addr[alen] = '\0'; | 
|  | 10934 | if (param->ip_version == IPV4) | 
|  | 10935 | ret = inet_pton(AF_INET, addr, | 
|  | 10936 | ¶m->ip_params.v4.src_ip); | 
|  | 10937 | else | 
|  | 10938 | ret = inet_pton(AF_INET6, addr, | 
|  | 10939 | ¶m->ip_params.v6.src_ip); | 
|  | 10940 |  | 
|  | 10941 | if (ret != 1) { | 
|  | 10942 | wpa_printf(MSG_ERROR, | 
|  | 10943 | "Error converting src IP address to binary ret=%d", | 
|  | 10944 | ret); | 
|  | 10945 | return -1; | 
|  | 10946 | } | 
|  | 10947 |  | 
|  | 10948 | classifier_mask |= BIT(1); | 
|  | 10949 | } | 
|  | 10950 |  | 
|  | 10951 | pos = os_strstr(cmd, "dst_ip="); | 
|  | 10952 | if (pos) { | 
|  | 10953 | pos += 7; | 
|  | 10954 | end = os_strchr(pos, ' '); | 
|  | 10955 | if (!end) | 
|  | 10956 | end = pos + os_strlen(pos); | 
|  | 10957 |  | 
|  | 10958 | alen = end - pos; | 
|  | 10959 | if (alen >= INET6_ADDRSTRLEN) | 
|  | 10960 | return -1; | 
|  | 10961 | os_memcpy(addr, pos, alen); | 
|  | 10962 | addr[alen] = '\0'; | 
|  | 10963 | if (param->ip_version == IPV4) | 
|  | 10964 | ret = inet_pton(AF_INET, addr, | 
|  | 10965 | ¶m->ip_params.v4.dst_ip); | 
|  | 10966 | else | 
|  | 10967 | ret = inet_pton(AF_INET6, addr, | 
|  | 10968 | ¶m->ip_params.v6.dst_ip); | 
|  | 10969 |  | 
|  | 10970 | if (ret != 1) { | 
|  | 10971 | wpa_printf(MSG_ERROR, | 
|  | 10972 | "Error converting dst IP address to binary ret=%d", | 
|  | 10973 | ret); | 
|  | 10974 | return -1; | 
|  | 10975 | } | 
|  | 10976 |  | 
|  | 10977 | classifier_mask |= BIT(2); | 
|  | 10978 | } | 
|  | 10979 |  | 
|  | 10980 | pos = os_strstr(cmd, "src_port="); | 
|  | 10981 | if (pos && atoi(pos + 9) > 0) { | 
|  | 10982 | if (param->ip_version == IPV4) | 
|  | 10983 | param->ip_params.v4.src_port = atoi(pos + 9); | 
|  | 10984 | else | 
|  | 10985 | param->ip_params.v6.src_port = atoi(pos + 9); | 
|  | 10986 | classifier_mask |= BIT(3); | 
|  | 10987 | } | 
|  | 10988 |  | 
|  | 10989 | pos = os_strstr(cmd, "dst_port="); | 
|  | 10990 | if (pos && atoi(pos + 9) > 0) { | 
|  | 10991 | if (param->ip_version == IPV4) | 
|  | 10992 | param->ip_params.v4.dst_port = atoi(pos + 9); | 
|  | 10993 | else | 
|  | 10994 | param->ip_params.v6.dst_port = atoi(pos + 9); | 
|  | 10995 | classifier_mask |= BIT(4); | 
|  | 10996 | } | 
|  | 10997 |  | 
|  | 10998 | pos = os_strstr(cmd, "dscp="); | 
|  | 10999 | if (pos && atoi(pos + 5) > 0) { | 
|  | 11000 | if (param->ip_version == IPV4) | 
|  | 11001 | param->ip_params.v4.dscp = atoi(pos + 5); | 
|  | 11002 | else | 
|  | 11003 | param->ip_params.v6.dscp = atoi(pos + 5); | 
|  | 11004 | classifier_mask |= BIT(5); | 
|  | 11005 | } | 
|  | 11006 |  | 
|  | 11007 | if (param->ip_version == IPV4) { | 
|  | 11008 | pos = os_strstr(cmd, "protocol="); | 
|  | 11009 | if (pos) { | 
|  | 11010 | if (os_strstr(pos, "udp")) { | 
|  | 11011 | param->ip_params.v4.protocol = 17; | 
|  | 11012 | } else if (os_strstr(pos, "tcp")) { | 
|  | 11013 | param->ip_params.v4.protocol = 6; | 
|  | 11014 | } else if (os_strstr(pos, "esp")) { | 
|  | 11015 | param->ip_params.v4.protocol = 50; | 
|  | 11016 | } else { | 
|  | 11017 | wpa_printf(MSG_ERROR, "Invalid protocol"); | 
|  | 11018 | return -1; | 
|  | 11019 | } | 
|  | 11020 | classifier_mask |= BIT(6); | 
|  | 11021 | } | 
|  | 11022 | } else { | 
|  | 11023 | pos = os_strstr(cmd, "next_header="); | 
|  | 11024 | if (pos) { | 
|  | 11025 | if (os_strstr(pos, "udp")) { | 
|  | 11026 | param->ip_params.v6.next_header = 17; | 
|  | 11027 | } else if (os_strstr(pos, "tcp")) { | 
|  | 11028 | param->ip_params.v6.next_header = 6; | 
|  | 11029 | } else if (os_strstr(pos, "esp")) { | 
|  | 11030 | param->ip_params.v6.next_header = 50; | 
|  | 11031 | } else { | 
|  | 11032 | wpa_printf(MSG_ERROR, "Invalid next header"); | 
|  | 11033 | return -1; | 
|  | 11034 | } | 
|  | 11035 |  | 
|  | 11036 | classifier_mask |= BIT(6); | 
|  | 11037 | } | 
|  | 11038 |  | 
|  | 11039 | pos = os_strstr(cmd, "flow_label="); | 
|  | 11040 | if (pos) { | 
|  | 11041 | pos += 11; | 
|  | 11042 | end = os_strchr(pos, ' '); | 
|  | 11043 | if (!end) | 
|  | 11044 | end = pos + os_strlen(pos); | 
|  | 11045 |  | 
|  | 11046 | if (end - pos != 6 || | 
|  | 11047 | hexstr2bin(pos, param->ip_params.v6.flow_label, | 
|  | 11048 | 3) || | 
|  | 11049 | param->ip_params.v6.flow_label[0] > 0x0F) { | 
|  | 11050 | wpa_printf(MSG_ERROR, "Invalid flow label"); | 
|  | 11051 | return -1; | 
|  | 11052 | } | 
|  | 11053 |  | 
|  | 11054 | classifier_mask |= BIT(7); | 
|  | 11055 | } | 
|  | 11056 | } | 
|  | 11057 |  | 
|  | 11058 | param->classifier_mask = classifier_mask; | 
|  | 11059 | return 0; | 
|  | 11060 | } | 
|  | 11061 |  | 
|  | 11062 |  | 
|  | 11063 | static int set_type10_frame_classifier(const char *cmd, | 
|  | 11064 | struct type10_params *param) | 
|  | 11065 | { | 
|  | 11066 | const char *pos, *end; | 
|  | 11067 | size_t filter_len; | 
|  | 11068 |  | 
|  | 11069 | pos = os_strstr(cmd, "prot_instance="); | 
|  | 11070 | if (!pos) { | 
|  | 11071 | wpa_printf(MSG_ERROR, "Protocol instance missing"); | 
|  | 11072 | return -1; | 
|  | 11073 | } | 
|  | 11074 | param->prot_instance = atoi(pos + 14); | 
|  | 11075 |  | 
|  | 11076 | pos = os_strstr(cmd, "prot_number="); | 
|  | 11077 | if (!pos) { | 
|  | 11078 | wpa_printf(MSG_ERROR, "Protocol number missing"); | 
|  | 11079 | return -1; | 
|  | 11080 | } | 
|  | 11081 | if (os_strstr(pos, "udp")) { | 
|  | 11082 | param->prot_number = 17; | 
|  | 11083 | } else if (os_strstr(pos, "tcp")) { | 
|  | 11084 | param->prot_number = 6; | 
|  | 11085 | } else if (os_strstr(pos, "esp")) { | 
|  | 11086 | param->prot_number = 50; | 
|  | 11087 | } else { | 
|  | 11088 | wpa_printf(MSG_ERROR, "Invalid protocol number"); | 
|  | 11089 | return -1; | 
|  | 11090 | } | 
|  | 11091 |  | 
|  | 11092 | pos = os_strstr(cmd, "filter_value="); | 
|  | 11093 | if (!pos) { | 
|  | 11094 | wpa_printf(MSG_ERROR, | 
|  | 11095 | "Classifier parameter filter_value missing"); | 
|  | 11096 | return -1; | 
|  | 11097 | } | 
|  | 11098 |  | 
|  | 11099 | pos += 13; | 
|  | 11100 | end = os_strchr(pos, ' '); | 
|  | 11101 | if (!end) | 
|  | 11102 | end = pos + os_strlen(pos); | 
|  | 11103 |  | 
|  | 11104 | filter_len = (end - pos) / 2; | 
|  | 11105 | param->filter_value = os_malloc(filter_len); | 
|  | 11106 | if (!param->filter_value) | 
|  | 11107 | return -1; | 
|  | 11108 |  | 
|  | 11109 | if (hexstr2bin(pos, param->filter_value, filter_len)) { | 
|  | 11110 | wpa_printf(MSG_ERROR, "Invalid filter_value %s", pos); | 
|  | 11111 | goto free; | 
|  | 11112 | } | 
|  | 11113 |  | 
|  | 11114 | pos = os_strstr(cmd, "filter_mask="); | 
|  | 11115 | if (!pos) { | 
|  | 11116 | wpa_printf(MSG_ERROR, | 
|  | 11117 | "Classifier parameter filter_mask missing"); | 
|  | 11118 | goto free; | 
|  | 11119 | } | 
|  | 11120 |  | 
|  | 11121 | pos += 12; | 
|  | 11122 | end = os_strchr(pos, ' '); | 
|  | 11123 | if (!end) | 
|  | 11124 | end = pos + os_strlen(pos); | 
|  | 11125 |  | 
|  | 11126 | if (filter_len != (size_t) (end - pos) / 2) { | 
|  | 11127 | wpa_printf(MSG_ERROR, | 
|  | 11128 | "Filter mask length mismatch expected=%zu received=%zu", | 
|  | 11129 | filter_len, (size_t) (end - pos) / 2); | 
|  | 11130 | goto free; | 
|  | 11131 | } | 
|  | 11132 |  | 
|  | 11133 | param->filter_mask = os_malloc(filter_len); | 
|  | 11134 | if (!param->filter_mask) | 
|  | 11135 | goto free; | 
|  | 11136 |  | 
|  | 11137 | if (hexstr2bin(pos, param->filter_mask, filter_len)) { | 
|  | 11138 | wpa_printf(MSG_ERROR, "Invalid filter mask %s", pos); | 
|  | 11139 | os_free(param->filter_mask); | 
|  | 11140 | param->filter_mask = NULL; | 
|  | 11141 | goto free; | 
|  | 11142 | } | 
|  | 11143 |  | 
|  | 11144 | param->filter_len = filter_len; | 
|  | 11145 | return 0; | 
|  | 11146 | free: | 
|  | 11147 | os_free(param->filter_value); | 
|  | 11148 | param->filter_value = NULL; | 
|  | 11149 | return -1; | 
|  | 11150 | } | 
|  | 11151 |  | 
|  | 11152 |  | 
|  | 11153 | static int scs_parse_type4(struct tclas_element *elem, const char *pos) | 
|  | 11154 | { | 
|  | 11155 | struct type4_params type4_param = { 0 }; | 
|  | 11156 |  | 
|  | 11157 | if (set_type4_frame_classifier(pos, &type4_param) == -1) { | 
|  | 11158 | wpa_printf(MSG_ERROR, "Failed to set frame_classifier 4"); | 
|  | 11159 | return -1; | 
|  | 11160 | } | 
|  | 11161 |  | 
|  | 11162 | os_memcpy(&elem->frame_classifier.type4_param, | 
|  | 11163 | &type4_param, sizeof(struct type4_params)); | 
|  | 11164 | return 0; | 
|  | 11165 | } | 
|  | 11166 |  | 
|  | 11167 |  | 
|  | 11168 | static int scs_parse_type10(struct tclas_element *elem, const char *pos) | 
|  | 11169 | { | 
|  | 11170 | struct type10_params type10_param = { 0 }; | 
|  | 11171 |  | 
|  | 11172 | if (set_type10_frame_classifier(pos, &type10_param) == -1) { | 
|  | 11173 | wpa_printf(MSG_ERROR, "Failed to set frame_classifier 10"); | 
|  | 11174 | return -1; | 
|  | 11175 | } | 
|  | 11176 |  | 
|  | 11177 | os_memcpy(&elem->frame_classifier.type10_param, | 
|  | 11178 | &type10_param, sizeof(struct type10_params)); | 
|  | 11179 | return 0; | 
|  | 11180 | } | 
|  | 11181 |  | 
|  | 11182 |  | 
|  | 11183 | static int wpas_ctrl_iface_configure_scs(struct wpa_supplicant *wpa_s, | 
|  | 11184 | char *cmd) | 
|  | 11185 | { | 
|  | 11186 | char *pos1, *pos; | 
|  | 11187 | struct scs_robust_av_data *scs_data = &wpa_s->scs_robust_av_req; | 
|  | 11188 | struct scs_desc_elem desc_elem = { 0 }; | 
|  | 11189 | int val; | 
|  | 11190 | unsigned int num_scs_desc = 0; | 
|  | 11191 |  | 
|  | 11192 | if (wpa_s->ongoing_scs_req) { | 
|  | 11193 | wpa_printf(MSG_ERROR, "%s: SCS Request already in queue", | 
|  | 11194 | __func__); | 
|  | 11195 | return -1; | 
|  | 11196 | } | 
|  | 11197 |  | 
|  | 11198 | /** | 
|  | 11199 | * format: | 
|  | 11200 | * [scs_id=<decimal number>] <add|remove|change> [scs_up=<0-7>] | 
|  | 11201 | * [classifier_type=<4|10>] | 
|  | 11202 | * [classifier params based on classifier type] | 
|  | 11203 | * [tclas_processing=<0|1>] [scs_id=<decimal number>] ... | 
|  | 11204 | */ | 
|  | 11205 | pos1 = os_strstr(cmd, "scs_id="); | 
|  | 11206 | if (!pos1) { | 
|  | 11207 | wpa_printf(MSG_ERROR, "SCSID not present"); | 
|  | 11208 | return -1; | 
|  | 11209 | } | 
|  | 11210 |  | 
|  | 11211 | free_up_scs_desc(scs_data); | 
|  | 11212 |  | 
|  | 11213 | while (pos1) { | 
|  | 11214 | struct scs_desc_elem *n1; | 
|  | 11215 | struct active_scs_elem *active_scs_desc; | 
|  | 11216 | char *next_scs_desc; | 
|  | 11217 | unsigned int num_tclas_elem = 0; | 
|  | 11218 | bool scsid_active = false; | 
|  | 11219 |  | 
|  | 11220 | desc_elem.scs_id = atoi(pos1 + 7); | 
|  | 11221 | pos1 += 7; | 
|  | 11222 |  | 
|  | 11223 | next_scs_desc = os_strstr(pos1, "scs_id="); | 
|  | 11224 | if (next_scs_desc) { | 
|  | 11225 | char temp[20]; | 
|  | 11226 |  | 
|  | 11227 | os_snprintf(temp, sizeof(temp), "scs_id=%d ", | 
|  | 11228 | desc_elem.scs_id); | 
|  | 11229 | if (os_strstr(next_scs_desc, temp)) { | 
|  | 11230 | wpa_printf(MSG_ERROR, | 
|  | 11231 | "Multiple SCS descriptors configured with same SCSID(=%d)", | 
|  | 11232 | desc_elem.scs_id); | 
|  | 11233 | goto free_scs_desc; | 
|  | 11234 | } | 
|  | 11235 | pos1[next_scs_desc - pos1 - 1] = '\0'; | 
|  | 11236 | } | 
|  | 11237 |  | 
|  | 11238 | dl_list_for_each(active_scs_desc, &wpa_s->active_scs_ids, | 
|  | 11239 | struct active_scs_elem, list) { | 
|  | 11240 | if (desc_elem.scs_id == active_scs_desc->scs_id) { | 
|  | 11241 | scsid_active = true; | 
|  | 11242 | break; | 
|  | 11243 | } | 
|  | 11244 | } | 
|  | 11245 |  | 
|  | 11246 | if (os_strstr(pos1, "add ")) { | 
|  | 11247 | desc_elem.request_type = SCS_REQ_ADD; | 
|  | 11248 | if (scsid_active) { | 
|  | 11249 | wpa_printf(MSG_ERROR, "SCSID %d already active", | 
|  | 11250 | desc_elem.scs_id); | 
|  | 11251 | return -1; | 
|  | 11252 | } | 
|  | 11253 | } else if (os_strstr(pos1, "remove")) { | 
|  | 11254 | desc_elem.request_type = SCS_REQ_REMOVE; | 
|  | 11255 | if (!scsid_active) { | 
|  | 11256 | wpa_printf(MSG_ERROR, "SCSID %d not active", | 
|  | 11257 | desc_elem.scs_id); | 
|  | 11258 | return -1; | 
|  | 11259 | } | 
|  | 11260 | goto scs_desc_end; | 
|  | 11261 | } else if (os_strstr(pos1, "change ")) { | 
|  | 11262 | desc_elem.request_type = SCS_REQ_CHANGE; | 
|  | 11263 | if (!scsid_active) { | 
|  | 11264 | wpa_printf(MSG_ERROR, "SCSID %d not active", | 
|  | 11265 | desc_elem.scs_id); | 
|  | 11266 | return -1; | 
|  | 11267 | } | 
|  | 11268 | } else { | 
|  | 11269 | wpa_printf(MSG_ERROR, "SCS Request type invalid"); | 
|  | 11270 | goto free_scs_desc; | 
|  | 11271 | } | 
|  | 11272 |  | 
|  | 11273 | pos1 = os_strstr(pos1, "scs_up="); | 
|  | 11274 | if (!pos1) { | 
|  | 11275 | wpa_printf(MSG_ERROR, | 
|  | 11276 | "Intra-Access user priority not present"); | 
|  | 11277 | goto free_scs_desc; | 
|  | 11278 | } | 
|  | 11279 |  | 
|  | 11280 | val = atoi(pos1 + 7); | 
|  | 11281 | if (val < 0 || val > 7) { | 
|  | 11282 | wpa_printf(MSG_ERROR, | 
|  | 11283 | "Intra-Access user priority invalid %d", | 
|  | 11284 | val); | 
|  | 11285 | goto free_scs_desc; | 
|  | 11286 | } | 
|  | 11287 |  | 
|  | 11288 | desc_elem.intra_access_priority = val; | 
|  | 11289 | desc_elem.scs_up_avail = true; | 
|  | 11290 |  | 
|  | 11291 | pos = os_strstr(pos1, "classifier_type="); | 
|  | 11292 | if (!pos) { | 
|  | 11293 | wpa_printf(MSG_ERROR, "classifier type empty"); | 
|  | 11294 | goto free_scs_desc; | 
|  | 11295 | } | 
|  | 11296 |  | 
|  | 11297 | while (pos) { | 
|  | 11298 | struct tclas_element elem = { 0 }, *n; | 
|  | 11299 | char *next_tclas_elem; | 
|  | 11300 |  | 
|  | 11301 | val = atoi(pos + 16); | 
|  | 11302 | if (val != 4 && val != 10) { | 
|  | 11303 | wpa_printf(MSG_ERROR, | 
|  | 11304 | "classifier type invalid %d", val); | 
|  | 11305 | goto free_scs_desc; | 
|  | 11306 | } | 
|  | 11307 |  | 
|  | 11308 | elem.classifier_type = val; | 
|  | 11309 | pos += 16; | 
|  | 11310 |  | 
|  | 11311 | next_tclas_elem = os_strstr(pos, "classifier_type="); | 
|  | 11312 | if (next_tclas_elem) { | 
|  | 11313 | pos1 = next_tclas_elem; | 
|  | 11314 | pos[next_tclas_elem - pos - 1] = '\0'; | 
|  | 11315 | } | 
|  | 11316 |  | 
|  | 11317 | switch (val) { | 
|  | 11318 | case 4: | 
|  | 11319 | if (scs_parse_type4(&elem, pos) < 0) | 
|  | 11320 | goto free_scs_desc; | 
|  | 11321 | break; | 
|  | 11322 | case 10: | 
|  | 11323 | if (scs_parse_type10(&elem, pos) < 0) | 
|  | 11324 | goto free_scs_desc; | 
|  | 11325 | break; | 
|  | 11326 | } | 
|  | 11327 |  | 
|  | 11328 | n = os_realloc(desc_elem.tclas_elems, | 
|  | 11329 | (num_tclas_elem + 1) * sizeof(elem)); | 
|  | 11330 | if (!n) | 
|  | 11331 | goto free_scs_desc; | 
|  | 11332 |  | 
|  | 11333 | desc_elem.tclas_elems = n; | 
|  | 11334 | os_memcpy((u8 *) desc_elem.tclas_elems + | 
|  | 11335 | num_tclas_elem * sizeof(elem), | 
|  | 11336 | &elem, sizeof(elem)); | 
|  | 11337 | num_tclas_elem++; | 
|  | 11338 | desc_elem.num_tclas_elem = num_tclas_elem; | 
|  | 11339 | pos = next_tclas_elem; | 
|  | 11340 | } | 
|  | 11341 |  | 
|  | 11342 | if (desc_elem.num_tclas_elem > 1) { | 
|  | 11343 | pos1 = os_strstr(pos1, "tclas_processing="); | 
|  | 11344 | if (!pos1) { | 
|  | 11345 | wpa_printf(MSG_ERROR, "tclas_processing empty"); | 
|  | 11346 | goto free_scs_desc; | 
|  | 11347 | } | 
|  | 11348 |  | 
|  | 11349 | val = atoi(pos1 + 17); | 
|  | 11350 | if (val != 0 && val != 1) { | 
|  | 11351 | wpa_printf(MSG_ERROR, | 
|  | 11352 | "tclas_processing invalid"); | 
|  | 11353 | goto free_scs_desc; | 
|  | 11354 | } | 
|  | 11355 |  | 
|  | 11356 | desc_elem.tclas_processing = val; | 
|  | 11357 | } | 
|  | 11358 |  | 
|  | 11359 | scs_desc_end: | 
|  | 11360 | n1 = os_realloc(scs_data->scs_desc_elems, (num_scs_desc + 1) * | 
|  | 11361 | sizeof(struct scs_desc_elem)); | 
|  | 11362 | if (!n1) | 
|  | 11363 | goto free_scs_desc; | 
|  | 11364 |  | 
|  | 11365 | scs_data->scs_desc_elems = n1; | 
|  | 11366 | os_memcpy((u8 *) scs_data->scs_desc_elems + num_scs_desc * | 
|  | 11367 | sizeof(desc_elem), &desc_elem, sizeof(desc_elem)); | 
|  | 11368 | num_scs_desc++; | 
|  | 11369 | scs_data->num_scs_desc = num_scs_desc; | 
|  | 11370 | pos1 = next_scs_desc; | 
|  | 11371 | os_memset(&desc_elem, 0, sizeof(desc_elem)); | 
|  | 11372 | } | 
|  | 11373 |  | 
|  | 11374 | return wpas_send_scs_req(wpa_s); | 
|  | 11375 |  | 
|  | 11376 | free_scs_desc: | 
|  | 11377 | free_up_tclas_elem(&desc_elem); | 
|  | 11378 | free_up_scs_desc(scs_data); | 
|  | 11379 | return -1; | 
|  | 11380 | } | 
|  | 11381 |  | 
|  | 11382 |  | 
|  | 11383 | static int wpas_ctrl_iface_send_dscp_resp(struct wpa_supplicant *wpa_s, | 
|  | 11384 | const char *cmd) | 
|  | 11385 | { | 
|  | 11386 | char *pos; | 
|  | 11387 | struct dscp_policy_status *policy = NULL, *n; | 
|  | 11388 | int num_policies = 0, ret = -1; | 
|  | 11389 | struct dscp_resp_data resp_data; | 
|  | 11390 |  | 
|  | 11391 | /* | 
|  | 11392 | * format: | 
|  | 11393 | * <[reset]>/<[solicited] [policy_id=1 status=0...]> [more] | 
|  | 11394 | */ | 
|  | 11395 |  | 
|  | 11396 | os_memset(&resp_data, 0, sizeof(resp_data)); | 
|  | 11397 |  | 
|  | 11398 | resp_data.more = os_strstr(cmd, "more") != NULL; | 
|  | 11399 |  | 
|  | 11400 | if (os_strstr(cmd, "reset")) { | 
|  | 11401 | resp_data.reset = true; | 
|  | 11402 | resp_data.solicited = false; | 
|  | 11403 | goto send_resp; | 
|  | 11404 | } | 
|  | 11405 |  | 
|  | 11406 | resp_data.solicited = os_strstr(cmd, "solicited") != NULL; | 
|  | 11407 |  | 
|  | 11408 | pos = os_strstr(cmd, "policy_id="); | 
|  | 11409 | while (pos) { | 
|  | 11410 | n = os_realloc(policy, (num_policies + 1) * sizeof(*policy)); | 
|  | 11411 | if (!n) | 
|  | 11412 | goto fail; | 
|  | 11413 |  | 
|  | 11414 | policy = n; | 
|  | 11415 | pos += 10; | 
|  | 11416 | policy[num_policies].id = atoi(pos); | 
|  | 11417 | if (policy[num_policies].id == 0) { | 
|  | 11418 | wpa_printf(MSG_ERROR, "DSCP: Invalid policy id"); | 
|  | 11419 | goto fail; | 
|  | 11420 | } | 
|  | 11421 |  | 
|  | 11422 | pos = os_strstr(pos, "status="); | 
|  | 11423 | if (!pos) { | 
|  | 11424 | wpa_printf(MSG_ERROR, | 
|  | 11425 | "DSCP: Status is not found for a policy"); | 
|  | 11426 | goto fail; | 
|  | 11427 | } | 
|  | 11428 |  | 
|  | 11429 | pos += 7; | 
|  | 11430 | policy[num_policies].status = atoi(pos); | 
|  | 11431 | num_policies++; | 
|  | 11432 |  | 
|  | 11433 | pos = os_strstr(pos, "policy_id"); | 
|  | 11434 | } | 
|  | 11435 |  | 
|  | 11436 | resp_data.policy = policy; | 
|  | 11437 | resp_data.num_policies = num_policies; | 
|  | 11438 | send_resp: | 
|  | 11439 | ret = wpas_send_dscp_response(wpa_s, &resp_data); | 
|  | 11440 | if (ret) | 
|  | 11441 | wpa_printf(MSG_ERROR, "DSCP: Failed to send DSCP response"); | 
|  | 11442 | fail: | 
|  | 11443 | os_free(policy); | 
|  | 11444 | return ret; | 
|  | 11445 | } | 
|  | 11446 |  | 
|  | 11447 |  | 
|  | 11448 | static int wpas_ctrl_iface_send_dscp_query(struct wpa_supplicant *wpa_s, | 
|  | 11449 | const char *cmd) | 
|  | 11450 | { | 
|  | 11451 | char *pos; | 
|  | 11452 |  | 
|  | 11453 | /* | 
|  | 11454 | * format: | 
|  | 11455 | * Wildcard DSCP query | 
|  | 11456 | * <wildcard> | 
|  | 11457 | * | 
|  | 11458 | * DSCP query with a domain name attribute: | 
|  | 11459 | * [domain_name=<string>] | 
|  | 11460 | */ | 
|  | 11461 |  | 
|  | 11462 | if (os_strstr(cmd, "wildcard")) { | 
|  | 11463 | wpa_printf(MSG_DEBUG, "QM: Send wildcard DSCP policy query"); | 
|  | 11464 | return wpas_send_dscp_query(wpa_s, NULL, 0); | 
|  | 11465 | } | 
|  | 11466 |  | 
|  | 11467 | pos = os_strstr(cmd, "domain_name="); | 
|  | 11468 | if (!pos || !os_strlen(pos + 12)) { | 
|  | 11469 | wpa_printf(MSG_ERROR, "QM: Domain name not preset"); | 
|  | 11470 | return -1; | 
|  | 11471 | } | 
|  | 11472 |  | 
|  | 11473 | return wpas_send_dscp_query(wpa_s, pos + 12, os_strlen(pos + 12)); | 
|  | 11474 | } | 
|  | 11475 |  | 
|  | 11476 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11477 | char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, | 
|  | 11478 | char *buf, size_t *resp_len) | 
|  | 11479 | { | 
|  | 11480 | char *reply; | 
|  | 11481 | const int reply_size = 4096; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11482 | int reply_len; | 
|  | 11483 |  | 
|  | 11484 | 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] | 11485 | os_strncmp(buf, "SET_NETWORK ", 12) == 0 || | 
|  | 11486 | os_strncmp(buf, "PMKSA_ADD ", 10) == 0 || | 
|  | 11487 | os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11488 | if (wpa_debug_show_keys) | 
|  | 11489 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 11490 | "Control interface command '%s'", buf); | 
|  | 11491 | else | 
|  | 11492 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 11493 | "Control interface command '%s [REMOVED]'", | 
|  | 11494 | os_strncmp(buf, WPA_CTRL_RSP, | 
|  | 11495 | os_strlen(WPA_CTRL_RSP)) == 0 ? | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11496 | WPA_CTRL_RSP : | 
|  | 11497 | (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ? | 
|  | 11498 | "SET_NETWORK" : "key-add")); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11499 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 || | 
| Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 11500 | os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11501 | wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", | 
|  | 11502 | (const u8 *) buf, os_strlen(buf)); | 
|  | 11503 | } else { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11504 | int level = wpas_ctrl_cmd_debug_level(buf); | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 11505 | wpa_dbg(wpa_s, level, "Control interface command '%s'", buf); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11506 | } | 
|  | 11507 |  | 
|  | 11508 | reply = os_malloc(reply_size); | 
|  | 11509 | if (reply == NULL) { | 
|  | 11510 | *resp_len = 1; | 
|  | 11511 | return NULL; | 
|  | 11512 | } | 
|  | 11513 |  | 
|  | 11514 | os_memcpy(reply, "OK\n", 3); | 
|  | 11515 | reply_len = 3; | 
|  | 11516 |  | 
|  | 11517 | if (os_strcmp(buf, "PING") == 0) { | 
|  | 11518 | os_memcpy(reply, "PONG\n", 5); | 
|  | 11519 | reply_len = 5; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 11520 | } else if (os_strcmp(buf, "IFNAME") == 0) { | 
|  | 11521 | reply_len = os_strlen(wpa_s->ifname); | 
|  | 11522 | os_memcpy(reply, wpa_s->ifname, reply_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11523 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { | 
|  | 11524 | if (wpa_debug_reopen_file() < 0) | 
|  | 11525 | reply_len = -1; | 
|  | 11526 | } else if (os_strncmp(buf, "NOTE ", 5) == 0) { | 
|  | 11527 | wpa_printf(MSG_INFO, "NOTE: %s", buf + 5); | 
|  | 11528 | } else if (os_strcmp(buf, "MIB") == 0) { | 
|  | 11529 | reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); | 
|  | 11530 | if (reply_len >= 0) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11531 | reply_len += eapol_sm_get_mib(wpa_s->eapol, | 
|  | 11532 | reply + reply_len, | 
|  | 11533 | reply_size - reply_len); | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11534 | #ifdef CONFIG_MACSEC | 
|  | 11535 | reply_len += ieee802_1x_kay_get_mib( | 
|  | 11536 | wpa_s->kay, reply + reply_len, | 
|  | 11537 | reply_size - reply_len); | 
|  | 11538 | #endif /* CONFIG_MACSEC */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11539 | } | 
|  | 11540 | } else if (os_strncmp(buf, "STATUS", 6) == 0) { | 
|  | 11541 | reply_len = wpa_supplicant_ctrl_iface_status( | 
|  | 11542 | wpa_s, buf + 6, reply, reply_size); | 
|  | 11543 | } else if (os_strcmp(buf, "PMKSA") == 0) { | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 11544 | reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size); | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11545 | } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) { | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 11546 | wpas_ctrl_iface_pmksa_flush(wpa_s); | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 11547 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL | 
|  | 11548 | } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) { | 
|  | 11549 | reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10, | 
|  | 11550 | reply, reply_size); | 
|  | 11551 | } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) { | 
|  | 11552 | if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0) | 
|  | 11553 | reply_len = -1; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 11554 | #ifdef CONFIG_MESH | 
|  | 11555 | } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) { | 
|  | 11556 | reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15, | 
|  | 11557 | reply, reply_size); | 
|  | 11558 | } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) { | 
|  | 11559 | if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0) | 
|  | 11560 | reply_len = -1; | 
|  | 11561 | #endif /* CONFIG_MESH */ | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 11562 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11563 | } else if (os_strncmp(buf, "SET ", 4) == 0) { | 
|  | 11564 | if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) | 
|  | 11565 | reply_len = -1; | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 11566 | } else if (os_strncmp(buf, "DUMP", 4) == 0) { | 
|  | 11567 | reply_len = wpa_config_dump_values(wpa_s->conf, | 
|  | 11568 | reply, reply_size); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11569 | } else if (os_strncmp(buf, "GET ", 4) == 0) { | 
|  | 11570 | reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4, | 
|  | 11571 | reply, reply_size); | 
|  | 11572 | } else if (os_strcmp(buf, "LOGON") == 0) { | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 11573 | eapol_sm_notify_logoff(wpa_s->eapol, false); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11574 | } else if (os_strcmp(buf, "LOGOFF") == 0) { | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 11575 | eapol_sm_notify_logoff(wpa_s->eapol, true); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11576 | } else if (os_strcmp(buf, "REASSOCIATE") == 0) { | 
|  | 11577 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) | 
|  | 11578 | reply_len = -1; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 11579 | else | 
|  | 11580 | wpas_request_connection(wpa_s); | 
| Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 11581 | } else if (os_strcmp(buf, "REATTACH") == 0) { | 
|  | 11582 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED || | 
|  | 11583 | !wpa_s->current_ssid) | 
|  | 11584 | reply_len = -1; | 
|  | 11585 | else { | 
|  | 11586 | wpa_s->reattach = 1; | 
|  | 11587 | wpas_request_connection(wpa_s); | 
|  | 11588 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11589 | } else if (os_strcmp(buf, "RECONNECT") == 0) { | 
|  | 11590 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) | 
|  | 11591 | reply_len = -1; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 11592 | else if (wpa_s->disconnected) | 
|  | 11593 | wpas_request_connection(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11594 | #ifdef IEEE8021X_EAPOL | 
|  | 11595 | } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { | 
|  | 11596 | if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) | 
|  | 11597 | reply_len = -1; | 
|  | 11598 | #endif /* IEEE8021X_EAPOL */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11599 | #ifdef CONFIG_IEEE80211R | 
|  | 11600 | } else if (os_strncmp(buf, "FT_DS ", 6) == 0) { | 
|  | 11601 | if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6)) | 
|  | 11602 | reply_len = -1; | 
|  | 11603 | #endif /* CONFIG_IEEE80211R */ | 
|  | 11604 | #ifdef CONFIG_WPS | 
|  | 11605 | } else if (os_strcmp(buf, "WPS_PBC") == 0) { | 
|  | 11606 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL); | 
|  | 11607 | if (res == -2) { | 
|  | 11608 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | 
|  | 11609 | reply_len = 17; | 
|  | 11610 | } else if (res) | 
|  | 11611 | reply_len = -1; | 
|  | 11612 | } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) { | 
|  | 11613 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8); | 
|  | 11614 | if (res == -2) { | 
|  | 11615 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | 
|  | 11616 | reply_len = 17; | 
|  | 11617 | } else if (res) | 
|  | 11618 | reply_len = -1; | 
|  | 11619 | } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) { | 
|  | 11620 | reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8, | 
|  | 11621 | reply, | 
|  | 11622 | reply_size); | 
|  | 11623 | } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) { | 
|  | 11624 | reply_len = wpa_supplicant_ctrl_iface_wps_check_pin( | 
|  | 11625 | wpa_s, buf + 14, reply, reply_size); | 
|  | 11626 | } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { | 
|  | 11627 | if (wpas_wps_cancel(wpa_s)) | 
|  | 11628 | reply_len = -1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11629 | #ifdef CONFIG_WPS_NFC | 
|  | 11630 | } else if (os_strcmp(buf, "WPS_NFC") == 0) { | 
|  | 11631 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL)) | 
|  | 11632 | reply_len = -1; | 
|  | 11633 | } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) { | 
|  | 11634 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8)) | 
|  | 11635 | reply_len = -1; | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 11636 | } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) { | 
|  | 11637 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token( | 
|  | 11638 | wpa_s, buf + 21, reply, reply_size); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11639 | } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) { | 
|  | 11640 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token( | 
|  | 11641 | wpa_s, buf + 14, reply, reply_size); | 
|  | 11642 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) { | 
|  | 11643 | if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s, | 
|  | 11644 | buf + 17)) | 
|  | 11645 | reply_len = -1; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 11646 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) { | 
|  | 11647 | reply_len = wpas_ctrl_nfc_get_handover_req( | 
|  | 11648 | wpa_s, buf + 21, reply, reply_size); | 
|  | 11649 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) { | 
|  | 11650 | reply_len = wpas_ctrl_nfc_get_handover_sel( | 
|  | 11651 | wpa_s, buf + 21, reply, reply_size); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 11652 | } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) { | 
|  | 11653 | if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20)) | 
|  | 11654 | reply_len = -1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11655 | #endif /* CONFIG_WPS_NFC */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11656 | } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) { | 
|  | 11657 | if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8)) | 
|  | 11658 | reply_len = -1; | 
|  | 11659 | #ifdef CONFIG_AP | 
|  | 11660 | } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) { | 
|  | 11661 | reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin( | 
|  | 11662 | wpa_s, buf + 11, reply, reply_size); | 
|  | 11663 | #endif /* CONFIG_AP */ | 
|  | 11664 | #ifdef CONFIG_WPS_ER | 
|  | 11665 | } else if (os_strcmp(buf, "WPS_ER_START") == 0) { | 
|  | 11666 | if (wpas_wps_er_start(wpa_s, NULL)) | 
|  | 11667 | reply_len = -1; | 
|  | 11668 | } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) { | 
|  | 11669 | if (wpas_wps_er_start(wpa_s, buf + 13)) | 
|  | 11670 | reply_len = -1; | 
|  | 11671 | } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11672 | wpas_wps_er_stop(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11673 | } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) { | 
|  | 11674 | if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11)) | 
|  | 11675 | reply_len = -1; | 
|  | 11676 | } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) { | 
|  | 11677 | int ret = wpas_wps_er_pbc(wpa_s, buf + 11); | 
|  | 11678 | if (ret == -2) { | 
|  | 11679 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); | 
|  | 11680 | reply_len = 17; | 
|  | 11681 | } else if (ret == -3) { | 
|  | 11682 | os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18); | 
|  | 11683 | reply_len = 18; | 
|  | 11684 | } else if (ret == -4) { | 
|  | 11685 | os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20); | 
|  | 11686 | reply_len = 20; | 
|  | 11687 | } else if (ret) | 
|  | 11688 | reply_len = -1; | 
|  | 11689 | } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) { | 
|  | 11690 | if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13)) | 
|  | 11691 | reply_len = -1; | 
|  | 11692 | } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) { | 
|  | 11693 | if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s, | 
|  | 11694 | buf + 18)) | 
|  | 11695 | reply_len = -1; | 
|  | 11696 | } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) { | 
|  | 11697 | if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14)) | 
|  | 11698 | reply_len = -1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11699 | #ifdef CONFIG_WPS_NFC | 
|  | 11700 | } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) { | 
|  | 11701 | reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( | 
|  | 11702 | wpa_s, buf + 24, reply, reply_size); | 
|  | 11703 | #endif /* CONFIG_WPS_NFC */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11704 | #endif /* CONFIG_WPS_ER */ | 
|  | 11705 | #endif /* CONFIG_WPS */ | 
|  | 11706 | #ifdef CONFIG_IBSS_RSN | 
|  | 11707 | } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) { | 
|  | 11708 | if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) | 
|  | 11709 | reply_len = -1; | 
|  | 11710 | #endif /* CONFIG_IBSS_RSN */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11711 | #ifdef CONFIG_MESH | 
|  | 11712 | } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) { | 
|  | 11713 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( | 
|  | 11714 | wpa_s, buf + 19, reply, reply_size); | 
|  | 11715 | } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) { | 
|  | 11716 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( | 
|  | 11717 | wpa_s, "", reply, reply_size); | 
|  | 11718 | } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) { | 
|  | 11719 | if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15)) | 
|  | 11720 | reply_len = -1; | 
|  | 11721 | } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) { | 
|  | 11722 | if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s, | 
|  | 11723 | buf + 18)) | 
|  | 11724 | reply_len = -1; | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 11725 | } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) { | 
|  | 11726 | if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17)) | 
|  | 11727 | reply_len = -1; | 
|  | 11728 | } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) { | 
|  | 11729 | if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14)) | 
|  | 11730 | reply_len = -1; | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11731 | } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) { | 
|  | 11732 | if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16)) | 
|  | 11733 | reply_len = -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11734 | #endif /* CONFIG_MESH */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11735 | #ifdef CONFIG_P2P | 
|  | 11736 | } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 11737 | if (p2p_ctrl_find(wpa_s, buf + 8)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11738 | reply_len = -1; | 
|  | 11739 | } else if (os_strcmp(buf, "P2P_FIND") == 0) { | 
|  | 11740 | if (p2p_ctrl_find(wpa_s, "")) | 
|  | 11741 | reply_len = -1; | 
|  | 11742 | } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) { | 
|  | 11743 | wpas_p2p_stop_find(wpa_s); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 11744 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) { | 
|  | 11745 | if (p2p_ctrl_asp_provision(wpa_s, buf + 18)) | 
|  | 11746 | reply_len = -1; | 
|  | 11747 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) { | 
|  | 11748 | if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23)) | 
|  | 11749 | reply_len = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11750 | } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) { | 
|  | 11751 | reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply, | 
|  | 11752 | reply_size); | 
|  | 11753 | } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) { | 
|  | 11754 | if (p2p_ctrl_listen(wpa_s, buf + 11)) | 
|  | 11755 | reply_len = -1; | 
|  | 11756 | } else if (os_strcmp(buf, "P2P_LISTEN") == 0) { | 
|  | 11757 | if (p2p_ctrl_listen(wpa_s, "")) | 
|  | 11758 | reply_len = -1; | 
|  | 11759 | } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) { | 
|  | 11760 | if (wpas_p2p_group_remove(wpa_s, buf + 17)) | 
|  | 11761 | reply_len = -1; | 
|  | 11762 | } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) { | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 11763 | if (p2p_ctrl_group_add(wpa_s, "")) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11764 | reply_len = -1; | 
|  | 11765 | } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) { | 
|  | 11766 | if (p2p_ctrl_group_add(wpa_s, buf + 14)) | 
|  | 11767 | reply_len = -1; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11768 | } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) { | 
|  | 11769 | reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply, | 
|  | 11770 | reply_size); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11771 | } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) { | 
|  | 11772 | if (p2p_ctrl_prov_disc(wpa_s, buf + 14)) | 
|  | 11773 | reply_len = -1; | 
|  | 11774 | } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) { | 
|  | 11775 | reply_len = p2p_get_passphrase(wpa_s, reply, reply_size); | 
|  | 11776 | } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) { | 
|  | 11777 | reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply, | 
|  | 11778 | reply_size); | 
|  | 11779 | } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) { | 
|  | 11780 | if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0) | 
|  | 11781 | reply_len = -1; | 
|  | 11782 | } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) { | 
|  | 11783 | if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0) | 
|  | 11784 | reply_len = -1; | 
|  | 11785 | } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) { | 
|  | 11786 | wpas_p2p_sd_service_update(wpa_s); | 
|  | 11787 | } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) { | 
|  | 11788 | if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0) | 
|  | 11789 | reply_len = -1; | 
|  | 11790 | } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) { | 
|  | 11791 | wpas_p2p_service_flush(wpa_s); | 
|  | 11792 | } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) { | 
|  | 11793 | if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0) | 
|  | 11794 | reply_len = -1; | 
|  | 11795 | } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) { | 
|  | 11796 | if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0) | 
|  | 11797 | reply_len = -1; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 11798 | } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) { | 
|  | 11799 | if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0) | 
|  | 11800 | reply_len = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11801 | } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) { | 
|  | 11802 | if (p2p_ctrl_reject(wpa_s, buf + 11) < 0) | 
|  | 11803 | reply_len = -1; | 
|  | 11804 | } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) { | 
|  | 11805 | if (p2p_ctrl_invite(wpa_s, buf + 11) < 0) | 
|  | 11806 | reply_len = -1; | 
|  | 11807 | } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) { | 
|  | 11808 | reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply, | 
|  | 11809 | reply_size); | 
|  | 11810 | } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) { | 
|  | 11811 | if (p2p_ctrl_set(wpa_s, buf + 8) < 0) | 
|  | 11812 | reply_len = -1; | 
|  | 11813 | } else if (os_strcmp(buf, "P2P_FLUSH") == 0) { | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 11814 | p2p_ctrl_flush(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11815 | } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { | 
|  | 11816 | if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) | 
|  | 11817 | reply_len = -1; | 
|  | 11818 | } else if (os_strcmp(buf, "P2P_CANCEL") == 0) { | 
|  | 11819 | if (wpas_p2p_cancel(wpa_s)) | 
|  | 11820 | reply_len = -1; | 
|  | 11821 | } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) { | 
|  | 11822 | if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0) | 
|  | 11823 | reply_len = -1; | 
|  | 11824 | } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) { | 
|  | 11825 | if (p2p_ctrl_presence_req(wpa_s, "") < 0) | 
|  | 11826 | reply_len = -1; | 
|  | 11827 | } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) { | 
|  | 11828 | if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0) | 
|  | 11829 | reply_len = -1; | 
|  | 11830 | } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) { | 
|  | 11831 | if (p2p_ctrl_ext_listen(wpa_s, "") < 0) | 
|  | 11832 | reply_len = -1; | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 11833 | } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) { | 
|  | 11834 | if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0) | 
|  | 11835 | reply_len = -1; | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11836 | } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) { | 
|  | 11837 | if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13)) | 
|  | 11838 | reply_len = -1; | 
|  | 11839 | } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) { | 
|  | 11840 | if (wpas_p2p_lo_stop(wpa_s)) | 
|  | 11841 | reply_len = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11842 | #endif /* CONFIG_P2P */ | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 11843 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 11844 | } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) { | 
|  | 11845 | if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0) | 
|  | 11846 | reply_len = -1; | 
|  | 11847 | } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) { | 
|  | 11848 | reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16, | 
|  | 11849 | reply, reply_size); | 
|  | 11850 | #endif /* CONFIG_WIFI_DISPLAY */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11851 | #ifdef CONFIG_INTERWORKING | 
|  | 11852 | } else if (os_strcmp(buf, "FETCH_ANQP") == 0) { | 
|  | 11853 | if (interworking_fetch_anqp(wpa_s) < 0) | 
|  | 11854 | reply_len = -1; | 
|  | 11855 | } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) { | 
|  | 11856 | interworking_stop_fetch_anqp(wpa_s); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11857 | } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) { | 
|  | 11858 | if (ctrl_interworking_select(wpa_s, NULL) < 0) | 
|  | 11859 | reply_len = -1; | 
|  | 11860 | } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) { | 
|  | 11861 | if (ctrl_interworking_select(wpa_s, buf + 20) < 0) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11862 | reply_len = -1; | 
|  | 11863 | } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) { | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 11864 | if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11865 | reply_len = -1; | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 11866 | } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) { | 
|  | 11867 | int id; | 
|  | 11868 |  | 
|  | 11869 | id = ctrl_interworking_connect(wpa_s, buf + 25, 1); | 
|  | 11870 | if (id < 0) | 
|  | 11871 | reply_len = -1; | 
|  | 11872 | else { | 
|  | 11873 | reply_len = os_snprintf(reply, reply_size, "%d\n", id); | 
|  | 11874 | if (os_snprintf_error(reply_size, reply_len)) | 
|  | 11875 | reply_len = -1; | 
|  | 11876 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11877 | } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) { | 
|  | 11878 | if (get_anqp(wpa_s, buf + 9) < 0) | 
|  | 11879 | reply_len = -1; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 11880 | } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) { | 
|  | 11881 | if (gas_request(wpa_s, buf + 12) < 0) | 
|  | 11882 | reply_len = -1; | 
|  | 11883 | } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) { | 
|  | 11884 | reply_len = gas_response_get(wpa_s, buf + 17, reply, | 
|  | 11885 | reply_size); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11886 | #endif /* CONFIG_INTERWORKING */ | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11887 | #ifdef CONFIG_HS20 | 
|  | 11888 | } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) { | 
|  | 11889 | if (get_hs20_anqp(wpa_s, buf + 14) < 0) | 
|  | 11890 | reply_len = -1; | 
|  | 11891 | } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) { | 
|  | 11892 | if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0) | 
|  | 11893 | reply_len = -1; | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 11894 | } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) { | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 11895 | if (hs20_icon_request(wpa_s, buf + 18, 0) < 0) | 
|  | 11896 | reply_len = -1; | 
|  | 11897 | } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) { | 
|  | 11898 | if (hs20_icon_request(wpa_s, buf + 14, 1) < 0) | 
|  | 11899 | reply_len = -1; | 
|  | 11900 | } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) { | 
|  | 11901 | reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size); | 
|  | 11902 | } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) { | 
|  | 11903 | if (del_hs20_icon(wpa_s, buf + 14) < 0) | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 11904 | reply_len = -1; | 
|  | 11905 | } else if (os_strcmp(buf, "FETCH_OSU") == 0) { | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11906 | if (hs20_fetch_osu(wpa_s, 0) < 0) | 
|  | 11907 | reply_len = -1; | 
|  | 11908 | } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) { | 
|  | 11909 | if (hs20_fetch_osu(wpa_s, 1) < 0) | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 11910 | reply_len = -1; | 
|  | 11911 | } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) { | 
|  | 11912 | hs20_cancel_fetch_osu(wpa_s); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11913 | #endif /* CONFIG_HS20 */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11914 | } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) | 
|  | 11915 | { | 
|  | 11916 | if (wpa_supplicant_ctrl_iface_ctrl_rsp( | 
|  | 11917 | wpa_s, buf + os_strlen(WPA_CTRL_RSP))) | 
|  | 11918 | reply_len = -1; | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 11919 | else { | 
|  | 11920 | /* | 
|  | 11921 | * Notify response from timeout to allow the control | 
|  | 11922 | * interface response to be sent first. | 
|  | 11923 | */ | 
|  | 11924 | eloop_register_timeout(0, 0, wpas_ctrl_eapol_response, | 
|  | 11925 | wpa_s, NULL); | 
|  | 11926 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11927 | } else if (os_strcmp(buf, "RECONFIGURE") == 0) { | 
|  | 11928 | if (wpa_supplicant_reload_configuration(wpa_s)) | 
|  | 11929 | reply_len = -1; | 
|  | 11930 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | 
|  | 11931 | wpa_supplicant_terminate_proc(wpa_s->global); | 
|  | 11932 | } else if (os_strncmp(buf, "BSSID ", 6) == 0) { | 
|  | 11933 | if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) | 
|  | 11934 | reply_len = -1; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11935 | } else if (os_strncmp(buf, "BSSID_IGNORE", 12) == 0) { | 
|  | 11936 | reply_len = wpa_supplicant_ctrl_iface_bssid_ignore( | 
|  | 11937 | wpa_s, buf + 12, reply, reply_size); | 
| Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 11938 | } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) { | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11939 | /* deprecated backwards compatibility alias for BSSID_IGNORE */ | 
|  | 11940 | reply_len = wpa_supplicant_ctrl_iface_bssid_ignore( | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11941 | wpa_s, buf + 9, reply, reply_size); | 
|  | 11942 | } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) { | 
|  | 11943 | reply_len = wpa_supplicant_ctrl_iface_log_level( | 
|  | 11944 | wpa_s, buf + 9, reply, reply_size); | 
| Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 11945 | } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) { | 
|  | 11946 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | 
|  | 11947 | wpa_s, buf + 14, reply, reply_size); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11948 | } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { | 
|  | 11949 | reply_len = wpa_supplicant_ctrl_iface_list_networks( | 
| Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 11950 | wpa_s, NULL, reply, reply_size); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11951 | } else if (os_strcmp(buf, "DISCONNECT") == 0) { | 
| Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 11952 | wpas_request_disconnection(wpa_s); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11953 | } else if (os_strcmp(buf, "SCAN") == 0) { | 
|  | 11954 | wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len); | 
|  | 11955 | } else if (os_strncmp(buf, "SCAN ", 5) == 0) { | 
|  | 11956 | wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11957 | } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { | 
|  | 11958 | reply_len = wpa_supplicant_ctrl_iface_scan_results( | 
|  | 11959 | wpa_s, reply, reply_size); | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 11960 | } else if (os_strcmp(buf, "ABORT_SCAN") == 0) { | 
|  | 11961 | if (wpas_abort_ongoing_scan(wpa_s) < 0) | 
|  | 11962 | reply_len = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11963 | } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { | 
|  | 11964 | if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) | 
|  | 11965 | reply_len = -1; | 
|  | 11966 | } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { | 
|  | 11967 | if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) | 
|  | 11968 | reply_len = -1; | 
|  | 11969 | } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { | 
|  | 11970 | if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) | 
|  | 11971 | reply_len = -1; | 
|  | 11972 | } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { | 
|  | 11973 | reply_len = wpa_supplicant_ctrl_iface_add_network( | 
|  | 11974 | wpa_s, reply, reply_size); | 
|  | 11975 | } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { | 
|  | 11976 | if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) | 
|  | 11977 | reply_len = -1; | 
|  | 11978 | } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { | 
|  | 11979 | if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) | 
|  | 11980 | reply_len = -1; | 
|  | 11981 | } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { | 
|  | 11982 | reply_len = wpa_supplicant_ctrl_iface_get_network( | 
|  | 11983 | wpa_s, buf + 12, reply, reply_size); | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 11984 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11985 | if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12, | 
|  | 11986 | wpa_s)) | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 11987 | reply_len = -1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11988 | } else if (os_strcmp(buf, "LIST_CREDS") == 0) { | 
|  | 11989 | reply_len = wpa_supplicant_ctrl_iface_list_creds( | 
|  | 11990 | wpa_s, reply, reply_size); | 
|  | 11991 | } else if (os_strcmp(buf, "ADD_CRED") == 0) { | 
|  | 11992 | reply_len = wpa_supplicant_ctrl_iface_add_cred( | 
|  | 11993 | wpa_s, reply, reply_size); | 
|  | 11994 | } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) { | 
|  | 11995 | if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12)) | 
|  | 11996 | reply_len = -1; | 
|  | 11997 | } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) { | 
|  | 11998 | if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9)) | 
|  | 11999 | reply_len = -1; | 
| Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 12000 | } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) { | 
|  | 12001 | reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9, | 
|  | 12002 | reply, | 
|  | 12003 | reply_size); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12004 | #ifndef CONFIG_NO_CONFIG_WRITE | 
|  | 12005 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | 
|  | 12006 | if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) | 
|  | 12007 | reply_len = -1; | 
|  | 12008 | #endif /* CONFIG_NO_CONFIG_WRITE */ | 
|  | 12009 | } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { | 
|  | 12010 | reply_len = wpa_supplicant_ctrl_iface_get_capability( | 
|  | 12011 | wpa_s, buf + 15, reply, reply_size); | 
|  | 12012 | } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { | 
|  | 12013 | if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) | 
|  | 12014 | reply_len = -1; | 
|  | 12015 | } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) { | 
|  | 12016 | if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14)) | 
|  | 12017 | reply_len = -1; | 
|  | 12018 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { | 
|  | 12019 | reply_len = wpa_supplicant_global_iface_list( | 
|  | 12020 | wpa_s->global, reply, reply_size); | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 12021 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12022 | reply_len = wpa_supplicant_global_iface_interfaces( | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 12023 | wpa_s->global, buf + 10, reply, reply_size); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12024 | } else if (os_strncmp(buf, "BSS ", 4) == 0) { | 
|  | 12025 | reply_len = wpa_supplicant_ctrl_iface_bss( | 
|  | 12026 | wpa_s, buf + 4, reply, reply_size); | 
|  | 12027 | #ifdef CONFIG_AP | 
|  | 12028 | } else if (os_strcmp(buf, "STA-FIRST") == 0) { | 
|  | 12029 | reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size); | 
|  | 12030 | } else if (os_strncmp(buf, "STA ", 4) == 0) { | 
|  | 12031 | reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply, | 
|  | 12032 | reply_size); | 
|  | 12033 | } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { | 
|  | 12034 | reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply, | 
|  | 12035 | reply_size); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 12036 | } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) { | 
|  | 12037 | if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15)) | 
|  | 12038 | reply_len = -1; | 
|  | 12039 | } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) { | 
|  | 12040 | if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13)) | 
|  | 12041 | reply_len = -1; | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 12042 | } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) { | 
|  | 12043 | if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12)) | 
|  | 12044 | reply_len = -1; | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 12045 | } else if (os_strcmp(buf, "STOP_AP") == 0) { | 
|  | 12046 | if (wpas_ap_stop_ap(wpa_s)) | 
|  | 12047 | reply_len = -1; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12048 | } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) { | 
|  | 12049 | if (wpas_ap_update_beacon(wpa_s)) | 
|  | 12050 | reply_len = -1; | 
| Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 12051 | } else if (os_strncmp(buf, "ACCEPT_ACL ", 11) == 0) { | 
|  | 12052 | if (os_strncmp(buf + 11, "ADD_MAC ", 8) == 0) { | 
|  | 12053 | if (ap_ctrl_iface_acl_add_mac(wpa_s, | 
|  | 12054 | DENY_UNLESS_ACCEPTED, | 
|  | 12055 | buf + 19) || | 
|  | 12056 | ap_ctrl_iface_set_acl(wpa_s)) | 
|  | 12057 | reply_len = -1; | 
|  | 12058 | } else if (os_strncmp((buf + 11), "DEL_MAC ", 8) == 0) { | 
|  | 12059 | if (ap_ctrl_iface_acl_del_mac(wpa_s, | 
|  | 12060 | DENY_UNLESS_ACCEPTED, | 
|  | 12061 | buf + 19) || | 
|  | 12062 | ap_ctrl_iface_set_acl(wpa_s) || | 
|  | 12063 | ap_ctrl_iface_disassoc_accept_mac(wpa_s)) | 
|  | 12064 | reply_len = -1; | 
|  | 12065 | } else if (os_strcmp(buf + 11, "SHOW") == 0) { | 
|  | 12066 | reply_len = ap_ctrl_iface_acl_show_mac( | 
|  | 12067 | wpa_s, DENY_UNLESS_ACCEPTED, | 
|  | 12068 | reply, reply_size); | 
|  | 12069 | } else if (os_strcmp(buf + 11, "CLEAR") == 0) { | 
|  | 12070 | ap_ctrl_iface_acl_clear_list(wpa_s, | 
|  | 12071 | DENY_UNLESS_ACCEPTED); | 
|  | 12072 | if (ap_ctrl_iface_set_acl(wpa_s) || | 
|  | 12073 | ap_ctrl_iface_disassoc_accept_mac(wpa_s)) | 
|  | 12074 | reply_len = -1; | 
|  | 12075 | } else { | 
|  | 12076 | reply_len = -1; | 
|  | 12077 | } | 
|  | 12078 | } else if (os_strncmp(buf, "DENY_ACL ", 9) == 0) { | 
|  | 12079 | if (os_strncmp(buf + 9, "ADD_MAC ", 8) == 0) { | 
|  | 12080 | if (ap_ctrl_iface_acl_add_mac(wpa_s, | 
|  | 12081 | ACCEPT_UNLESS_DENIED, | 
|  | 12082 | buf + 17) || | 
|  | 12083 | ap_ctrl_iface_set_acl(wpa_s) || | 
|  | 12084 | ap_ctrl_iface_disassoc_deny_mac(wpa_s)) | 
|  | 12085 | reply_len = -1; | 
|  | 12086 | } else if (os_strncmp(buf + 9, "DEL_MAC ", 8) == 0) { | 
|  | 12087 | if (ap_ctrl_iface_acl_del_mac(wpa_s, | 
|  | 12088 | ACCEPT_UNLESS_DENIED, | 
|  | 12089 | buf + 17) || | 
|  | 12090 | ap_ctrl_iface_set_acl(wpa_s)) | 
|  | 12091 | reply_len = -1; | 
|  | 12092 | } else if (os_strcmp(buf + 9, "SHOW") == 0) { | 
|  | 12093 | reply_len = ap_ctrl_iface_acl_show_mac( | 
|  | 12094 | wpa_s, ACCEPT_UNLESS_DENIED, reply, reply_size); | 
|  | 12095 | } else if (os_strcmp(buf + 9, "CLEAR") == 0) { | 
|  | 12096 | ap_ctrl_iface_acl_clear_list(wpa_s, | 
|  | 12097 | ACCEPT_UNLESS_DENIED); | 
|  | 12098 | if (ap_ctrl_iface_set_acl(wpa_s)) | 
|  | 12099 | reply_len = -1; | 
|  | 12100 | } else { | 
|  | 12101 | reply_len = -1; | 
|  | 12102 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12103 | #endif /* CONFIG_AP */ | 
|  | 12104 | } else if (os_strcmp(buf, "SUSPEND") == 0) { | 
|  | 12105 | wpas_notify_suspend(wpa_s->global); | 
|  | 12106 | } else if (os_strcmp(buf, "RESUME") == 0) { | 
|  | 12107 | wpas_notify_resume(wpa_s->global); | 
| Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 12108 | #ifdef CONFIG_TESTING_OPTIONS | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12109 | } else if (os_strcmp(buf, "DROP_SA") == 0) { | 
|  | 12110 | wpa_supplicant_ctrl_iface_drop_sa(wpa_s); | 
| Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 12111 | #endif /* CONFIG_TESTING_OPTIONS */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12112 | } else if (os_strncmp(buf, "ROAM ", 5) == 0) { | 
|  | 12113 | if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) | 
|  | 12114 | reply_len = -1; | 
|  | 12115 | } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12116 | wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12117 | } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) { | 
|  | 12118 | if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15)) | 
|  | 12119 | reply_len = -1; | 
|  | 12120 | } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) { | 
|  | 12121 | if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s, | 
|  | 12122 | buf + 17)) | 
|  | 12123 | reply_len = -1; | 
| Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 12124 | } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12125 | wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12126 | #ifdef CONFIG_TDLS | 
|  | 12127 | } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) { | 
|  | 12128 | if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14)) | 
|  | 12129 | reply_len = -1; | 
|  | 12130 | } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) { | 
|  | 12131 | if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11)) | 
|  | 12132 | reply_len = -1; | 
|  | 12133 | } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) { | 
|  | 12134 | if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14)) | 
|  | 12135 | reply_len = -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12136 | } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) { | 
|  | 12137 | if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s, | 
|  | 12138 | buf + 17)) | 
|  | 12139 | reply_len = -1; | 
|  | 12140 | } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) { | 
|  | 12141 | if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s, | 
|  | 12142 | buf + 24)) | 
|  | 12143 | reply_len = -1; | 
| Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 12144 | } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) { | 
|  | 12145 | reply_len = wpa_supplicant_ctrl_iface_tdls_link_status( | 
|  | 12146 | wpa_s, buf + 17, reply, reply_size); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12147 | #endif /* CONFIG_TDLS */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12148 | } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) { | 
|  | 12149 | reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size); | 
|  | 12150 | } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) { | 
|  | 12151 | if (wmm_ac_ctrl_addts(wpa_s, buf + 13)) | 
|  | 12152 | reply_len = -1; | 
|  | 12153 | } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) { | 
|  | 12154 | if (wmm_ac_ctrl_delts(wpa_s, buf + 13)) | 
|  | 12155 | reply_len = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12156 | } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) { | 
|  | 12157 | reply_len = wpa_supplicant_signal_poll(wpa_s, reply, | 
|  | 12158 | reply_size); | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 12159 | } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) { | 
|  | 12160 | if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14)) | 
|  | 12161 | reply_len = -1; | 
| Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 12162 | } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) { | 
|  | 12163 | reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply, | 
|  | 12164 | reply_size); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 12165 | #ifdef CONFIG_AUTOSCAN | 
|  | 12166 | } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) { | 
|  | 12167 | if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9)) | 
|  | 12168 | reply_len = -1; | 
|  | 12169 | #endif /* CONFIG_AUTOSCAN */ | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12170 | } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) { | 
|  | 12171 | reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply, | 
|  | 12172 | reply_size); | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 12173 | } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) { | 
|  | 12174 | reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply, | 
|  | 12175 | reply_size); | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 12176 | #ifdef ANDROID | 
| Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 12177 | } else if (os_strncmp(buf, "DRIVER ", 7) == 0) { | 
|  | 12178 | reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply, | 
|  | 12179 | reply_size); | 
| Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 12180 | #endif /* ANDROID */ | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 12181 | } else if (os_strncmp(buf, "VENDOR ", 7) == 0) { | 
|  | 12182 | reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply, | 
|  | 12183 | reply_size); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12184 | } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) { | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 12185 | pmksa_cache_clear_current(wpa_s->wpa); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12186 | eapol_sm_request_reauth(wpa_s->eapol); | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 12187 | #ifdef CONFIG_WNM | 
|  | 12188 | } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) { | 
|  | 12189 | if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10)) | 
|  | 12190 | reply_len = -1; | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 12191 | } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) { | 
|  | 12192 | if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14)) | 
| Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 12193 | reply_len = -1; | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 12194 | } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) { | 
|  | 12195 | if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18)) | 
|  | 12196 | reply_len = -1; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 12197 | #endif /* CONFIG_WNM */ | 
| Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 12198 | #ifdef CONFIG_WNM_AP | 
|  | 12199 | } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) { | 
|  | 12200 | if (ap_ctrl_iface_disassoc_imminent(wpa_s, buf + 18)) | 
|  | 12201 | reply_len = -1; | 
|  | 12202 | } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) { | 
|  | 12203 | if (ap_ctrl_iface_ess_disassoc(wpa_s, buf + 13)) | 
|  | 12204 | reply_len = -1; | 
|  | 12205 | } else if (os_strncmp(buf, "BSS_TM_REQ ", 11) == 0) { | 
|  | 12206 | if (ap_ctrl_iface_bss_tm_req(wpa_s, buf + 11)) | 
|  | 12207 | reply_len = -1; | 
|  | 12208 | #endif /* CONFIG_WNM_AP */ | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 12209 | } else if (os_strcmp(buf, "FLUSH") == 0) { | 
|  | 12210 | wpa_supplicant_ctrl_iface_flush(wpa_s); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 12211 | } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) { | 
|  | 12212 | reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply, | 
|  | 12213 | reply_size); | 
| Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 12214 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 12215 | } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) { | 
|  | 12216 | if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0) | 
|  | 12217 | reply_len = -1; | 
|  | 12218 | } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) { | 
|  | 12219 | wpas_ctrl_iface_mgmt_tx_done(wpa_s); | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12220 | } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) { | 
|  | 12221 | if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0) | 
|  | 12222 | reply_len = -1; | 
| Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 12223 | } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) { | 
|  | 12224 | if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0) | 
|  | 12225 | reply_len = -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12226 | } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) { | 
|  | 12227 | if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0) | 
|  | 12228 | reply_len = -1; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12229 | } else if (os_strncmp(buf, "EAPOL_TX ", 9) == 0) { | 
|  | 12230 | if (wpas_ctrl_iface_eapol_tx(wpa_s, buf + 9) < 0) | 
|  | 12231 | reply_len = -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12232 | } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) { | 
|  | 12233 | if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0) | 
|  | 12234 | reply_len = -1; | 
|  | 12235 | } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) { | 
|  | 12236 | if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0) | 
|  | 12237 | reply_len = -1; | 
|  | 12238 | } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) { | 
|  | 12239 | if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0) | 
|  | 12240 | reply_len = -1; | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 12241 | } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) { | 
|  | 12242 | if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0) | 
|  | 12243 | reply_len = -1; | 
|  | 12244 | } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) { | 
|  | 12245 | reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12246 | } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) { | 
|  | 12247 | if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0) | 
|  | 12248 | reply_len = -1; | 
|  | 12249 | } else if (os_strcmp(buf, "GET_FAIL") == 0) { | 
|  | 12250 | reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size); | 
| Jouni Malinen | c481836 | 2015-10-04 11:45:13 +0300 | [diff] [blame] | 12251 | } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) { | 
|  | 12252 | if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0) | 
|  | 12253 | reply_len = -1; | 
| Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 12254 | } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) { | 
|  | 12255 | if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0) | 
|  | 12256 | reply_len = -1; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12257 | } else if (os_strcmp(buf, "RESET_PN") == 0) { | 
|  | 12258 | if (wpas_ctrl_reset_pn(wpa_s) < 0) | 
|  | 12259 | reply_len = -1; | 
|  | 12260 | } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) { | 
|  | 12261 | if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0) | 
|  | 12262 | reply_len = -1; | 
|  | 12263 | } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) { | 
|  | 12264 | if (wpas_ctrl_resend_assoc(wpa_s) < 0) | 
|  | 12265 | reply_len = -1; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12266 | } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) { | 
|  | 12267 | sme_event_unprot_disconnect( | 
|  | 12268 | wpa_s, wpa_s->bssid, NULL, | 
|  | 12269 | WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA); | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12270 | } else if (os_strncmp(buf, "TWT_SETUP ", 10) == 0) { | 
|  | 12271 | if (wpas_ctrl_iface_send_twt_setup(wpa_s, buf + 9)) | 
|  | 12272 | reply_len = -1; | 
|  | 12273 | } else if (os_strcmp(buf, "TWT_SETUP") == 0) { | 
|  | 12274 | if (wpas_ctrl_iface_send_twt_setup(wpa_s, "")) | 
|  | 12275 | reply_len = -1; | 
|  | 12276 | } else if (os_strncmp(buf, "TWT_TEARDOWN ", 13) == 0) { | 
|  | 12277 | if (wpas_ctrl_iface_send_twt_teardown(wpa_s, buf + 12)) | 
|  | 12278 | reply_len = -1; | 
|  | 12279 | } else if (os_strcmp(buf, "TWT_TEARDOWN") == 0) { | 
|  | 12280 | if (wpas_ctrl_iface_send_twt_teardown(wpa_s, "")) | 
|  | 12281 | reply_len = -1; | 
| Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 12282 | #endif /* CONFIG_TESTING_OPTIONS */ | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 12283 | } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) { | 
|  | 12284 | if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0) | 
|  | 12285 | reply_len = -1; | 
|  | 12286 | } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) { | 
|  | 12287 | reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply, | 
|  | 12288 | reply_size); | 
|  | 12289 | } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) { | 
|  | 12290 | if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0) | 
|  | 12291 | reply_len = -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12292 | } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) { | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12293 | if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12294 | reply_len = -1; | 
|  | 12295 | } else if (os_strcmp(buf, "ERP_FLUSH") == 0) { | 
|  | 12296 | wpas_ctrl_iface_erp_flush(wpa_s); | 
|  | 12297 | } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) { | 
|  | 12298 | if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14)) | 
|  | 12299 | reply_len = -1; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12300 | } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) { | 
|  | 12301 | reply_len = wpas_ctrl_iface_get_pref_freq_list( | 
|  | 12302 | wpa_s, buf + 19, reply, reply_size); | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 12303 | #ifdef CONFIG_FILS | 
|  | 12304 | } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) { | 
|  | 12305 | if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17)) | 
|  | 12306 | reply_len = -1; | 
|  | 12307 | } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) { | 
|  | 12308 | wpas_flush_fils_hlp_req(wpa_s); | 
|  | 12309 | #endif /* CONFIG_FILS */ | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12310 | #ifdef CONFIG_DPP | 
|  | 12311 | } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) { | 
|  | 12312 | int res; | 
|  | 12313 |  | 
|  | 12314 | res = wpas_dpp_qr_code(wpa_s, buf + 12); | 
|  | 12315 | if (res < 0) { | 
|  | 12316 | reply_len = -1; | 
|  | 12317 | } else { | 
|  | 12318 | reply_len = os_snprintf(reply, reply_size, "%d", res); | 
|  | 12319 | if (os_snprintf_error(reply_size, reply_len)) | 
|  | 12320 | reply_len = -1; | 
|  | 12321 | } | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 12322 | } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) { | 
|  | 12323 | int res; | 
|  | 12324 |  | 
|  | 12325 | res = wpas_dpp_nfc_uri(wpa_s, buf + 12); | 
|  | 12326 | if (res < 0) { | 
|  | 12327 | reply_len = -1; | 
|  | 12328 | } else { | 
|  | 12329 | reply_len = os_snprintf(reply, reply_size, "%d", res); | 
|  | 12330 | if (os_snprintf_error(reply_size, reply_len)) | 
|  | 12331 | reply_len = -1; | 
|  | 12332 | } | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12333 | } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) { | 
|  | 12334 | int res; | 
|  | 12335 |  | 
|  | 12336 | res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20); | 
|  | 12337 | if (res < 0) { | 
|  | 12338 | reply_len = -1; | 
|  | 12339 | } else { | 
|  | 12340 | reply_len = os_snprintf(reply, reply_size, "%d", res); | 
|  | 12341 | if (os_snprintf_error(reply_size, reply_len)) | 
|  | 12342 | reply_len = -1; | 
|  | 12343 | } | 
|  | 12344 | } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) { | 
|  | 12345 | int res; | 
|  | 12346 |  | 
|  | 12347 | res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20); | 
|  | 12348 | if (res < 0) { | 
|  | 12349 | reply_len = -1; | 
|  | 12350 | } else { | 
|  | 12351 | reply_len = os_snprintf(reply, reply_size, "%d", res); | 
|  | 12352 | if (os_snprintf_error(reply_size, reply_len)) | 
|  | 12353 | reply_len = -1; | 
|  | 12354 | } | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12355 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) { | 
|  | 12356 | int res; | 
|  | 12357 |  | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12358 | res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12359 | if (res < 0) { | 
|  | 12360 | reply_len = -1; | 
|  | 12361 | } else { | 
|  | 12362 | reply_len = os_snprintf(reply, reply_size, "%d", res); | 
|  | 12363 | if (os_snprintf_error(reply_size, reply_len)) | 
|  | 12364 | reply_len = -1; | 
|  | 12365 | } | 
|  | 12366 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) { | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12367 | if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0) | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12368 | reply_len = -1; | 
|  | 12369 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) { | 
|  | 12370 | const char *uri; | 
|  | 12371 |  | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12372 | uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22)); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12373 | if (!uri) { | 
|  | 12374 | reply_len = -1; | 
|  | 12375 | } else { | 
|  | 12376 | reply_len = os_snprintf(reply, reply_size, "%s", uri); | 
|  | 12377 | if (os_snprintf_error(reply_size, reply_len)) | 
|  | 12378 | reply_len = -1; | 
|  | 12379 | } | 
|  | 12380 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) { | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12381 | reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19), | 
|  | 12382 | reply, reply_size); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12383 | } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) { | 
|  | 12384 | if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18), | 
|  | 12385 | os_strchr(buf + 18, ' ')) < 0) | 
|  | 12386 | reply_len = -1; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12387 | } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) { | 
|  | 12388 | if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0) | 
|  | 12389 | reply_len = -1; | 
|  | 12390 | } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) { | 
|  | 12391 | if (wpas_dpp_listen(wpa_s, buf + 11) < 0) | 
|  | 12392 | reply_len = -1; | 
|  | 12393 | } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) { | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12394 | wpas_dpp_stop(wpa_s); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12395 | wpas_dpp_listen_stop(wpa_s); | 
|  | 12396 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) { | 
|  | 12397 | int res; | 
|  | 12398 |  | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12399 | res = dpp_configurator_add(wpa_s->dpp, buf + 20); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12400 | if (res < 0) { | 
|  | 12401 | reply_len = -1; | 
|  | 12402 | } else { | 
|  | 12403 | reply_len = os_snprintf(reply, reply_size, "%d", res); | 
|  | 12404 | if (os_snprintf_error(reply_size, reply_len)) | 
|  | 12405 | reply_len = -1; | 
|  | 12406 | } | 
| Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 12407 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SET ", 21) == 0) { | 
|  | 12408 | if (dpp_configurator_set(wpa_s->dpp, buf + 20) < 0) | 
|  | 12409 | reply_len = -1; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12410 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) { | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12411 | if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0) | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12412 | reply_len = -1; | 
|  | 12413 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12414 | if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0) | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12415 | reply_len = -1; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12416 | } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) { | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 12417 | reply_len = dpp_configurator_get_key_id(wpa_s->dpp, | 
|  | 12418 | atoi(buf + 25), | 
|  | 12419 | reply, reply_size); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12420 | } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) { | 
|  | 12421 | int res; | 
|  | 12422 |  | 
|  | 12423 | res = wpas_dpp_pkex_add(wpa_s, buf + 12); | 
|  | 12424 | if (res < 0) { | 
|  | 12425 | reply_len = -1; | 
|  | 12426 | } else { | 
|  | 12427 | reply_len = os_snprintf(reply, reply_size, "%d", res); | 
|  | 12428 | if (os_snprintf_error(reply_size, reply_len)) | 
|  | 12429 | reply_len = -1; | 
|  | 12430 | } | 
|  | 12431 | } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) { | 
|  | 12432 | if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0) | 
|  | 12433 | reply_len = -1; | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12434 | } else if (os_strncmp(buf, "DPP_CONF_SET ", 13) == 0) { | 
|  | 12435 | if (wpas_dpp_conf_set(wpa_s, buf + 12) < 0) | 
|  | 12436 | reply_len = -1; | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 12437 | #ifdef CONFIG_DPP2 | 
|  | 12438 | } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) { | 
|  | 12439 | if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0) | 
|  | 12440 | reply_len = -1; | 
|  | 12441 | } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) { | 
|  | 12442 | if (wpas_dpp_controller_start(wpa_s, NULL) < 0) | 
|  | 12443 | reply_len = -1; | 
|  | 12444 | } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) { | 
|  | 12445 | dpp_controller_stop(wpa_s->dpp); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12446 | } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) { | 
|  | 12447 | if (wpas_dpp_chirp(wpa_s, buf + 9) < 0) | 
|  | 12448 | reply_len = -1; | 
|  | 12449 | } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) { | 
|  | 12450 | wpas_dpp_chirp_stop(wpa_s); | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 12451 | } else if (os_strncmp(buf, "DPP_RECONFIG ", 13) == 0) { | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12452 | if (wpas_dpp_reconfig(wpa_s, buf + 13) < 0) | 
|  | 12453 | reply_len = -1; | 
|  | 12454 | } else if (os_strncmp(buf, "DPP_CA_SET ", 11) == 0) { | 
|  | 12455 | if (wpas_dpp_ca_set(wpa_s, buf + 10) < 0) | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 12456 | reply_len = -1; | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 12457 | #endif /* CONFIG_DPP2 */ | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12458 | #endif /* CONFIG_DPP */ | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12459 | } else if (os_strncmp(buf, "MSCS ", 5) == 0) { | 
|  | 12460 | if (wpas_ctrl_iface_configure_mscs(wpa_s, buf + 5)) | 
|  | 12461 | reply_len = -1; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12462 | #ifdef CONFIG_PASN | 
|  | 12463 | } else if (os_strncmp(buf, "PASN_START ", 11) == 0) { | 
|  | 12464 | if (wpas_ctrl_iface_pasn_start(wpa_s, buf + 11) < 0) | 
|  | 12465 | reply_len = -1; | 
|  | 12466 | } else if (os_strcmp(buf, "PASN_STOP") == 0) { | 
|  | 12467 | wpas_pasn_auth_stop(wpa_s); | 
|  | 12468 | } else if (os_strcmp(buf, "PTKSA_CACHE_LIST") == 0) { | 
|  | 12469 | reply_len = ptksa_cache_list(wpa_s->ptksa, reply, reply_size); | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12470 | } else if (os_strncmp(buf, "PASN_DEAUTH ", 12) == 0) { | 
|  | 12471 | if (wpas_ctrl_iface_pasn_deauthenticate(wpa_s, buf + 12) < 0) | 
|  | 12472 | reply_len = -1; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12473 | #endif /* CONFIG_PASN */ | 
| Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12474 | } else if (os_strncmp(buf, "SCS ", 4) == 0) { | 
|  | 12475 | if (wpas_ctrl_iface_configure_scs(wpa_s, buf + 4)) | 
|  | 12476 | reply_len = -1; | 
|  | 12477 | } else if (os_strncmp(buf, "DSCP_RESP ", 10) == 0) { | 
|  | 12478 | if (wpas_ctrl_iface_send_dscp_resp(wpa_s, buf + 10)) | 
|  | 12479 | reply_len = -1; | 
|  | 12480 | } else if (os_strncmp(buf, "DSCP_QUERY ", 11) == 0) { | 
|  | 12481 | if (wpas_ctrl_iface_send_dscp_query(wpa_s, buf + 11)) | 
|  | 12482 | reply_len = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12483 | } else { | 
|  | 12484 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | 
|  | 12485 | reply_len = 16; | 
|  | 12486 | } | 
|  | 12487 |  | 
|  | 12488 | if (reply_len < 0) { | 
|  | 12489 | os_memcpy(reply, "FAIL\n", 5); | 
|  | 12490 | reply_len = 5; | 
|  | 12491 | } | 
|  | 12492 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12493 | *resp_len = reply_len; | 
|  | 12494 | return reply; | 
|  | 12495 | } | 
|  | 12496 |  | 
|  | 12497 |  | 
|  | 12498 | static int wpa_supplicant_global_iface_add(struct wpa_global *global, | 
|  | 12499 | char *cmd) | 
|  | 12500 | { | 
|  | 12501 | struct wpa_interface iface; | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12502 | char *pos, *extra; | 
|  | 12503 | struct wpa_supplicant *wpa_s; | 
|  | 12504 | unsigned int create_iface = 0; | 
|  | 12505 | u8 mac_addr[ETH_ALEN]; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 12506 | enum wpa_driver_if_type type = WPA_IF_STATION; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12507 |  | 
|  | 12508 | /* | 
|  | 12509 | * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param> | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 12510 | * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]] | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12511 | */ | 
|  | 12512 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd); | 
|  | 12513 |  | 
|  | 12514 | os_memset(&iface, 0, sizeof(iface)); | 
|  | 12515 |  | 
|  | 12516 | do { | 
|  | 12517 | iface.ifname = pos = cmd; | 
|  | 12518 | pos = os_strchr(pos, '\t'); | 
|  | 12519 | if (pos) | 
|  | 12520 | *pos++ = '\0'; | 
|  | 12521 | if (iface.ifname[0] == '\0') | 
|  | 12522 | return -1; | 
|  | 12523 | if (pos == NULL) | 
|  | 12524 | break; | 
|  | 12525 |  | 
|  | 12526 | iface.confname = pos; | 
|  | 12527 | pos = os_strchr(pos, '\t'); | 
|  | 12528 | if (pos) | 
|  | 12529 | *pos++ = '\0'; | 
|  | 12530 | if (iface.confname[0] == '\0') | 
|  | 12531 | iface.confname = NULL; | 
|  | 12532 | if (pos == NULL) | 
|  | 12533 | break; | 
|  | 12534 |  | 
|  | 12535 | iface.driver = pos; | 
|  | 12536 | pos = os_strchr(pos, '\t'); | 
|  | 12537 | if (pos) | 
|  | 12538 | *pos++ = '\0'; | 
|  | 12539 | if (iface.driver[0] == '\0') | 
|  | 12540 | iface.driver = NULL; | 
|  | 12541 | if (pos == NULL) | 
|  | 12542 | break; | 
|  | 12543 |  | 
|  | 12544 | iface.ctrl_interface = pos; | 
|  | 12545 | pos = os_strchr(pos, '\t'); | 
|  | 12546 | if (pos) | 
|  | 12547 | *pos++ = '\0'; | 
|  | 12548 | if (iface.ctrl_interface[0] == '\0') | 
|  | 12549 | iface.ctrl_interface = NULL; | 
|  | 12550 | if (pos == NULL) | 
|  | 12551 | break; | 
|  | 12552 |  | 
|  | 12553 | iface.driver_param = pos; | 
|  | 12554 | pos = os_strchr(pos, '\t'); | 
|  | 12555 | if (pos) | 
|  | 12556 | *pos++ = '\0'; | 
|  | 12557 | if (iface.driver_param[0] == '\0') | 
|  | 12558 | iface.driver_param = NULL; | 
|  | 12559 | if (pos == NULL) | 
|  | 12560 | break; | 
|  | 12561 |  | 
|  | 12562 | iface.bridge_ifname = pos; | 
|  | 12563 | pos = os_strchr(pos, '\t'); | 
|  | 12564 | if (pos) | 
|  | 12565 | *pos++ = '\0'; | 
|  | 12566 | if (iface.bridge_ifname[0] == '\0') | 
|  | 12567 | iface.bridge_ifname = NULL; | 
|  | 12568 | if (pos == NULL) | 
|  | 12569 | break; | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12570 |  | 
|  | 12571 | extra = pos; | 
|  | 12572 | pos = os_strchr(pos, '\t'); | 
|  | 12573 | if (pos) | 
|  | 12574 | *pos++ = '\0'; | 
| Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 12575 | if (!extra[0]) | 
|  | 12576 | break; | 
|  | 12577 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 12578 | if (os_strcmp(extra, "create") == 0) { | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12579 | create_iface = 1; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 12580 | if (!pos) | 
|  | 12581 | break; | 
|  | 12582 |  | 
|  | 12583 | if (os_strcmp(pos, "sta") == 0) { | 
|  | 12584 | type = WPA_IF_STATION; | 
|  | 12585 | } else if (os_strcmp(pos, "ap") == 0) { | 
|  | 12586 | type = WPA_IF_AP_BSS; | 
|  | 12587 | } else { | 
|  | 12588 | wpa_printf(MSG_DEBUG, | 
|  | 12589 | "INTERFACE_ADD unsupported interface type: '%s'", | 
|  | 12590 | pos); | 
|  | 12591 | return -1; | 
|  | 12592 | } | 
|  | 12593 | } else { | 
| Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 12594 | wpa_printf(MSG_DEBUG, | 
|  | 12595 | "INTERFACE_ADD unsupported extra parameter: '%s'", | 
|  | 12596 | extra); | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12597 | return -1; | 
| Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 12598 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12599 | } while (0); | 
|  | 12600 |  | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12601 | if (create_iface) { | 
|  | 12602 | wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'", | 
|  | 12603 | iface.ifname); | 
|  | 12604 | if (!global->ifaces) | 
|  | 12605 | return -1; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 12606 | if (wpa_drv_if_add(global->ifaces, type, iface.ifname, | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12607 | NULL, NULL, NULL, mac_addr, NULL) < 0) { | 
|  | 12608 | wpa_printf(MSG_ERROR, | 
|  | 12609 | "CTRL_IFACE interface creation failed"); | 
|  | 12610 | return -1; | 
|  | 12611 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12612 |  | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12613 | wpa_printf(MSG_DEBUG, | 
|  | 12614 | "CTRL_IFACE interface '%s' created with MAC addr: " | 
|  | 12615 | MACSTR, iface.ifname, MAC2STR(mac_addr)); | 
|  | 12616 | } | 
|  | 12617 |  | 
|  | 12618 | if (wpa_supplicant_get_iface(global, iface.ifname)) | 
|  | 12619 | goto fail; | 
|  | 12620 |  | 
|  | 12621 | wpa_s = wpa_supplicant_add_iface(global, &iface, NULL); | 
|  | 12622 | if (!wpa_s) | 
|  | 12623 | goto fail; | 
|  | 12624 | wpa_s->added_vif = create_iface; | 
|  | 12625 | return 0; | 
|  | 12626 |  | 
|  | 12627 | fail: | 
|  | 12628 | if (create_iface) | 
|  | 12629 | wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname); | 
|  | 12630 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12631 | } | 
|  | 12632 |  | 
|  | 12633 |  | 
|  | 12634 | static int wpa_supplicant_global_iface_remove(struct wpa_global *global, | 
|  | 12635 | char *cmd) | 
|  | 12636 | { | 
|  | 12637 | struct wpa_supplicant *wpa_s; | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12638 | int ret; | 
|  | 12639 | unsigned int delete_iface; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12640 |  | 
|  | 12641 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd); | 
|  | 12642 |  | 
|  | 12643 | wpa_s = wpa_supplicant_get_iface(global, cmd); | 
|  | 12644 | if (wpa_s == NULL) | 
|  | 12645 | return -1; | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 12646 | delete_iface = wpa_s->added_vif; | 
|  | 12647 | ret = wpa_supplicant_remove_iface(global, wpa_s, 0); | 
|  | 12648 | if (!ret && delete_iface) { | 
|  | 12649 | wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'", | 
|  | 12650 | cmd); | 
|  | 12651 | ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd); | 
|  | 12652 | } | 
|  | 12653 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12654 | } | 
|  | 12655 |  | 
|  | 12656 |  | 
|  | 12657 | static void wpa_free_iface_info(struct wpa_interface_info *iface) | 
|  | 12658 | { | 
|  | 12659 | struct wpa_interface_info *prev; | 
|  | 12660 |  | 
|  | 12661 | while (iface) { | 
|  | 12662 | prev = iface; | 
|  | 12663 | iface = iface->next; | 
|  | 12664 |  | 
|  | 12665 | os_free(prev->ifname); | 
|  | 12666 | os_free(prev->desc); | 
|  | 12667 | os_free(prev); | 
|  | 12668 | } | 
|  | 12669 | } | 
|  | 12670 |  | 
|  | 12671 |  | 
|  | 12672 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, | 
|  | 12673 | char *buf, int len) | 
|  | 12674 | { | 
|  | 12675 | int i, res; | 
|  | 12676 | struct wpa_interface_info *iface = NULL, *last = NULL, *tmp; | 
|  | 12677 | char *pos, *end; | 
|  | 12678 |  | 
|  | 12679 | for (i = 0; wpa_drivers[i]; i++) { | 
| Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 12680 | const struct wpa_driver_ops *drv = wpa_drivers[i]; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12681 | if (drv->get_interfaces == NULL) | 
|  | 12682 | continue; | 
|  | 12683 | tmp = drv->get_interfaces(global->drv_priv[i]); | 
|  | 12684 | if (tmp == NULL) | 
|  | 12685 | continue; | 
|  | 12686 |  | 
|  | 12687 | if (last == NULL) | 
|  | 12688 | iface = last = tmp; | 
|  | 12689 | else | 
|  | 12690 | last->next = tmp; | 
|  | 12691 | while (last->next) | 
|  | 12692 | last = last->next; | 
|  | 12693 | } | 
|  | 12694 |  | 
|  | 12695 | pos = buf; | 
|  | 12696 | end = buf + len; | 
|  | 12697 | for (tmp = iface; tmp; tmp = tmp->next) { | 
|  | 12698 | res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n", | 
|  | 12699 | tmp->drv_name, tmp->ifname, | 
|  | 12700 | tmp->desc ? tmp->desc : ""); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12701 | if (os_snprintf_error(end - pos, res)) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12702 | *pos = '\0'; | 
|  | 12703 | break; | 
|  | 12704 | } | 
|  | 12705 | pos += res; | 
|  | 12706 | } | 
|  | 12707 |  | 
|  | 12708 | wpa_free_iface_info(iface); | 
|  | 12709 |  | 
|  | 12710 | return pos - buf; | 
|  | 12711 | } | 
|  | 12712 |  | 
|  | 12713 |  | 
|  | 12714 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 12715 | const char *input, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12716 | char *buf, int len) | 
|  | 12717 | { | 
|  | 12718 | int res; | 
|  | 12719 | char *pos, *end; | 
|  | 12720 | struct wpa_supplicant *wpa_s; | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 12721 | int show_ctrl = 0; | 
|  | 12722 |  | 
|  | 12723 | if (input) | 
|  | 12724 | show_ctrl = !!os_strstr(input, "ctrl"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12725 |  | 
|  | 12726 | wpa_s = global->ifaces; | 
|  | 12727 | pos = buf; | 
|  | 12728 | end = buf + len; | 
|  | 12729 |  | 
|  | 12730 | while (wpa_s) { | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 12731 | if (show_ctrl) | 
|  | 12732 | res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n", | 
|  | 12733 | wpa_s->ifname, | 
|  | 12734 | wpa_s->conf->ctrl_interface ? | 
|  | 12735 | wpa_s->conf->ctrl_interface : "N/A"); | 
|  | 12736 | else | 
|  | 12737 | res = os_snprintf(pos, end - pos, "%s\n", | 
|  | 12738 | wpa_s->ifname); | 
|  | 12739 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12740 | if (os_snprintf_error(end - pos, res)) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12741 | *pos = '\0'; | 
|  | 12742 | break; | 
|  | 12743 | } | 
|  | 12744 | pos += res; | 
|  | 12745 | wpa_s = wpa_s->next; | 
|  | 12746 | } | 
|  | 12747 | return pos - buf; | 
|  | 12748 | } | 
|  | 12749 |  | 
|  | 12750 |  | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 12751 | static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global, | 
|  | 12752 | const char *ifname, | 
|  | 12753 | char *cmd, size_t *resp_len) | 
|  | 12754 | { | 
|  | 12755 | struct wpa_supplicant *wpa_s; | 
|  | 12756 |  | 
|  | 12757 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 12758 | if (os_strcmp(ifname, wpa_s->ifname) == 0) | 
|  | 12759 | break; | 
|  | 12760 | } | 
|  | 12761 |  | 
|  | 12762 | if (wpa_s == NULL) { | 
|  | 12763 | char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n"); | 
|  | 12764 | if (resp) | 
|  | 12765 | *resp_len = os_strlen(resp); | 
|  | 12766 | else | 
|  | 12767 | *resp_len = 1; | 
|  | 12768 | return resp; | 
|  | 12769 | } | 
|  | 12770 |  | 
|  | 12771 | return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len); | 
|  | 12772 | } | 
|  | 12773 |  | 
|  | 12774 |  | 
|  | 12775 | static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global, | 
|  | 12776 | char *buf, size_t *resp_len) | 
|  | 12777 | { | 
|  | 12778 | #ifdef CONFIG_P2P | 
|  | 12779 | static const char * cmd[] = { | 
| Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 12780 | "LIST_NETWORKS", | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 12781 | "P2P_FIND", | 
|  | 12782 | "P2P_STOP_FIND", | 
|  | 12783 | "P2P_LISTEN", | 
|  | 12784 | "P2P_GROUP_ADD", | 
|  | 12785 | "P2P_GET_PASSPHRASE", | 
|  | 12786 | "P2P_SERVICE_UPDATE", | 
|  | 12787 | "P2P_SERVICE_FLUSH", | 
|  | 12788 | "P2P_FLUSH", | 
|  | 12789 | "P2P_CANCEL", | 
|  | 12790 | "P2P_PRESENCE_REQ", | 
|  | 12791 | "P2P_EXT_LISTEN", | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 12792 | #ifdef CONFIG_AP | 
|  | 12793 | "STA-FIRST", | 
|  | 12794 | #endif /* CONFIG_AP */ | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 12795 | NULL | 
|  | 12796 | }; | 
|  | 12797 | static const char * prefix[] = { | 
| Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 12798 | #ifdef ANDROID | 
| Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 12799 | "DRIVER ", | 
| Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 12800 | #endif /* ANDROID */ | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12801 | "GET_CAPABILITY ", | 
| Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 12802 | "GET_NETWORK ", | 
|  | 12803 | "REMOVE_NETWORK ", | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 12804 | "P2P_FIND ", | 
|  | 12805 | "P2P_CONNECT ", | 
|  | 12806 | "P2P_LISTEN ", | 
|  | 12807 | "P2P_GROUP_REMOVE ", | 
|  | 12808 | "P2P_GROUP_ADD ", | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12809 | "P2P_GROUP_MEMBER ", | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 12810 | "P2P_PROV_DISC ", | 
|  | 12811 | "P2P_SERV_DISC_REQ ", | 
|  | 12812 | "P2P_SERV_DISC_CANCEL_REQ ", | 
|  | 12813 | "P2P_SERV_DISC_RESP ", | 
|  | 12814 | "P2P_SERV_DISC_EXTERNAL ", | 
|  | 12815 | "P2P_SERVICE_ADD ", | 
|  | 12816 | "P2P_SERVICE_DEL ", | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 12817 | "P2P_SERVICE_REP ", | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 12818 | "P2P_REJECT ", | 
|  | 12819 | "P2P_INVITE ", | 
|  | 12820 | "P2P_PEER ", | 
|  | 12821 | "P2P_SET ", | 
|  | 12822 | "P2P_UNAUTHORIZE ", | 
|  | 12823 | "P2P_PRESENCE_REQ ", | 
|  | 12824 | "P2P_EXT_LISTEN ", | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 12825 | "P2P_REMOVE_CLIENT ", | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 12826 | "WPS_NFC_TOKEN ", | 
|  | 12827 | "WPS_NFC_TAG_READ ", | 
| Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 12828 | "NFC_GET_HANDOVER_SEL ", | 
|  | 12829 | "NFC_GET_HANDOVER_REQ ", | 
|  | 12830 | "NFC_REPORT_HANDOVER ", | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 12831 | "P2P_ASP_PROVISION ", | 
|  | 12832 | "P2P_ASP_PROVISION_RESP ", | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 12833 | #ifdef CONFIG_AP | 
|  | 12834 | "STA ", | 
|  | 12835 | "STA-NEXT ", | 
|  | 12836 | #endif /* CONFIG_AP */ | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 12837 | NULL | 
|  | 12838 | }; | 
|  | 12839 | int found = 0; | 
|  | 12840 | int i; | 
|  | 12841 |  | 
|  | 12842 | if (global->p2p_init_wpa_s == NULL) | 
|  | 12843 | return NULL; | 
|  | 12844 |  | 
|  | 12845 | for (i = 0; !found && cmd[i]; i++) { | 
|  | 12846 | if (os_strcmp(buf, cmd[i]) == 0) | 
|  | 12847 | found = 1; | 
|  | 12848 | } | 
|  | 12849 |  | 
|  | 12850 | for (i = 0; !found && prefix[i]; i++) { | 
|  | 12851 | if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0) | 
|  | 12852 | found = 1; | 
|  | 12853 | } | 
|  | 12854 |  | 
|  | 12855 | if (found) | 
|  | 12856 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, | 
|  | 12857 | buf, resp_len); | 
|  | 12858 | #endif /* CONFIG_P2P */ | 
|  | 12859 | return NULL; | 
|  | 12860 | } | 
|  | 12861 |  | 
|  | 12862 |  | 
|  | 12863 | static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global, | 
|  | 12864 | char *buf, size_t *resp_len) | 
|  | 12865 | { | 
|  | 12866 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 12867 | if (global->p2p_init_wpa_s == NULL) | 
|  | 12868 | return NULL; | 
|  | 12869 | if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 || | 
|  | 12870 | os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) | 
|  | 12871 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, | 
|  | 12872 | buf, resp_len); | 
|  | 12873 | #endif /* CONFIG_WIFI_DISPLAY */ | 
|  | 12874 | return NULL; | 
|  | 12875 | } | 
|  | 12876 |  | 
|  | 12877 |  | 
|  | 12878 | static char * wpas_global_ctrl_iface_redir(struct wpa_global *global, | 
|  | 12879 | char *buf, size_t *resp_len) | 
|  | 12880 | { | 
|  | 12881 | char *ret; | 
|  | 12882 |  | 
|  | 12883 | ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len); | 
|  | 12884 | if (ret) | 
|  | 12885 | return ret; | 
|  | 12886 |  | 
|  | 12887 | ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len); | 
|  | 12888 | if (ret) | 
|  | 12889 | return ret; | 
|  | 12890 |  | 
|  | 12891 | return NULL; | 
|  | 12892 | } | 
|  | 12893 |  | 
|  | 12894 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 12895 | static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd) | 
|  | 12896 | { | 
|  | 12897 | char *value; | 
|  | 12898 |  | 
|  | 12899 | value = os_strchr(cmd, ' '); | 
|  | 12900 | if (value == NULL) | 
|  | 12901 | return -1; | 
|  | 12902 | *value++ = '\0'; | 
|  | 12903 |  | 
|  | 12904 | wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value); | 
|  | 12905 |  | 
|  | 12906 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 12907 | if (os_strcasecmp(cmd, "wifi_display") == 0) { | 
|  | 12908 | wifi_display_enable(global, !!atoi(value)); | 
|  | 12909 | return 0; | 
|  | 12910 | } | 
|  | 12911 | #endif /* CONFIG_WIFI_DISPLAY */ | 
|  | 12912 |  | 
| Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 12913 | /* Restore cmd to its original value to allow redirection */ | 
|  | 12914 | value[-1] = ' '; | 
|  | 12915 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 12916 | return -1; | 
|  | 12917 | } | 
|  | 12918 |  | 
|  | 12919 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12920 | static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global, | 
|  | 12921 | char *cmd) | 
|  | 12922 | { | 
|  | 12923 | struct wpa_supplicant *wpa_s[2]; /* src, dst */ | 
|  | 12924 | char *p; | 
|  | 12925 | unsigned int i; | 
|  | 12926 |  | 
|  | 12927 | /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id> | 
|  | 12928 | * <variable name> */ | 
|  | 12929 |  | 
|  | 12930 | for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) { | 
|  | 12931 | p = os_strchr(cmd, ' '); | 
|  | 12932 | if (p == NULL) | 
|  | 12933 | return -1; | 
|  | 12934 | *p = '\0'; | 
|  | 12935 |  | 
|  | 12936 | wpa_s[i] = global->ifaces; | 
|  | 12937 | for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) { | 
|  | 12938 | if (os_strcmp(cmd, wpa_s[i]->ifname) == 0) | 
|  | 12939 | break; | 
|  | 12940 | } | 
|  | 12941 |  | 
|  | 12942 | if (!wpa_s[i]) { | 
|  | 12943 | wpa_printf(MSG_DEBUG, | 
|  | 12944 | "CTRL_IFACE: Could not find iface=%s", cmd); | 
|  | 12945 | return -1; | 
|  | 12946 | } | 
|  | 12947 |  | 
|  | 12948 | cmd = p + 1; | 
|  | 12949 | } | 
|  | 12950 |  | 
|  | 12951 | return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]); | 
|  | 12952 | } | 
|  | 12953 |  | 
|  | 12954 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 12955 | #ifndef CONFIG_NO_CONFIG_WRITE | 
|  | 12956 | static int wpas_global_ctrl_iface_save_config(struct wpa_global *global) | 
|  | 12957 | { | 
| Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 12958 | int ret = 0, saved = 0; | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 12959 | struct wpa_supplicant *wpa_s; | 
|  | 12960 |  | 
|  | 12961 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 12962 | if (!wpa_s->conf->update_config) { | 
|  | 12963 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)"); | 
|  | 12964 | continue; | 
|  | 12965 | } | 
|  | 12966 |  | 
|  | 12967 | if (wpa_config_write(wpa_s->confname, wpa_s->conf)) { | 
|  | 12968 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration"); | 
|  | 12969 | ret = 1; | 
|  | 12970 | } else { | 
|  | 12971 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated"); | 
| Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 12972 | saved++; | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 12973 | } | 
|  | 12974 | } | 
|  | 12975 |  | 
| Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 12976 | if (!saved && !ret) { | 
|  | 12977 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 12978 | "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated"); | 
|  | 12979 | ret = 1; | 
|  | 12980 | } | 
|  | 12981 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 12982 | return ret; | 
|  | 12983 | } | 
|  | 12984 | #endif /* CONFIG_NO_CONFIG_WRITE */ | 
|  | 12985 |  | 
|  | 12986 |  | 
|  | 12987 | static int wpas_global_ctrl_iface_status(struct wpa_global *global, | 
|  | 12988 | char *buf, size_t buflen) | 
|  | 12989 | { | 
|  | 12990 | char *pos, *end; | 
|  | 12991 | int ret; | 
|  | 12992 | struct wpa_supplicant *wpa_s; | 
|  | 12993 |  | 
|  | 12994 | pos = buf; | 
|  | 12995 | end = buf + buflen; | 
|  | 12996 |  | 
|  | 12997 | #ifdef CONFIG_P2P | 
|  | 12998 | if (global->p2p && !global->p2p_disabled) { | 
|  | 12999 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR | 
|  | 13000 | "\n" | 
|  | 13001 | "p2p_state=%s\n", | 
|  | 13002 | MAC2STR(global->p2p_dev_addr), | 
|  | 13003 | p2p_get_state_txt(global->p2p)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13004 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13005 | return pos - buf; | 
|  | 13006 | pos += ret; | 
|  | 13007 | } else if (global->p2p) { | 
|  | 13008 | ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13009 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13010 | return pos - buf; | 
|  | 13011 | pos += ret; | 
|  | 13012 | } | 
|  | 13013 | #endif /* CONFIG_P2P */ | 
|  | 13014 |  | 
|  | 13015 | #ifdef CONFIG_WIFI_DISPLAY | 
|  | 13016 | ret = os_snprintf(pos, end - pos, "wifi_display=%d\n", | 
|  | 13017 | !!global->wifi_display); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13018 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13019 | return pos - buf; | 
|  | 13020 | pos += ret; | 
|  | 13021 | #endif /* CONFIG_WIFI_DISPLAY */ | 
|  | 13022 |  | 
|  | 13023 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 13024 | ret = os_snprintf(pos, end - pos, "ifname=%s\n" | 
|  | 13025 | "address=" MACSTR "\n", | 
|  | 13026 | wpa_s->ifname, MAC2STR(wpa_s->own_addr)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13027 | if (os_snprintf_error(end - pos, ret)) | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13028 | return pos - buf; | 
|  | 13029 | pos += ret; | 
|  | 13030 | } | 
|  | 13031 |  | 
|  | 13032 | return pos - buf; | 
|  | 13033 | } | 
|  | 13034 |  | 
|  | 13035 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13036 | #ifdef CONFIG_FST | 
|  | 13037 |  | 
|  | 13038 | static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global, | 
|  | 13039 | char *cmd, char *buf, | 
|  | 13040 | size_t reply_size) | 
|  | 13041 | { | 
|  | 13042 | char ifname[IFNAMSIZ + 1]; | 
|  | 13043 | struct fst_iface_cfg cfg; | 
|  | 13044 | struct wpa_supplicant *wpa_s; | 
|  | 13045 | struct fst_wpa_obj iface_obj; | 
|  | 13046 |  | 
|  | 13047 | if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) { | 
|  | 13048 | wpa_s = wpa_supplicant_get_iface(global, ifname); | 
|  | 13049 | if (wpa_s) { | 
|  | 13050 | if (wpa_s->fst) { | 
|  | 13051 | wpa_printf(MSG_INFO, "FST: Already attached"); | 
|  | 13052 | return -1; | 
|  | 13053 | } | 
|  | 13054 | fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj); | 
|  | 13055 | wpa_s->fst = fst_attach(ifname, wpa_s->own_addr, | 
|  | 13056 | &iface_obj, &cfg); | 
|  | 13057 | if (wpa_s->fst) | 
|  | 13058 | return os_snprintf(buf, reply_size, "OK\n"); | 
|  | 13059 | } | 
|  | 13060 | } | 
|  | 13061 |  | 
|  | 13062 | return -1; | 
|  | 13063 | } | 
|  | 13064 |  | 
|  | 13065 |  | 
|  | 13066 | static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global, | 
|  | 13067 | char *cmd, char *buf, | 
|  | 13068 | size_t reply_size) | 
|  | 13069 | { | 
|  | 13070 | char ifname[IFNAMSIZ + 1]; | 
|  | 13071 | struct wpa_supplicant *wpa_s; | 
|  | 13072 |  | 
|  | 13073 | if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) { | 
|  | 13074 | wpa_s = wpa_supplicant_get_iface(global, ifname); | 
|  | 13075 | if (wpa_s) { | 
|  | 13076 | if (!fst_iface_detach(ifname)) { | 
|  | 13077 | wpa_s->fst = NULL; | 
|  | 13078 | return os_snprintf(buf, reply_size, "OK\n"); | 
|  | 13079 | } | 
|  | 13080 | } | 
|  | 13081 | } | 
|  | 13082 |  | 
|  | 13083 | return -1; | 
|  | 13084 | } | 
|  | 13085 |  | 
|  | 13086 | #endif /* CONFIG_FST */ | 
|  | 13087 |  | 
|  | 13088 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13089 | char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, | 
|  | 13090 | char *buf, size_t *resp_len) | 
|  | 13091 | { | 
|  | 13092 | char *reply; | 
|  | 13093 | const int reply_size = 2048; | 
|  | 13094 | int reply_len; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13095 | int level = MSG_DEBUG; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13096 |  | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 13097 | if (os_strncmp(buf, "IFNAME=", 7) == 0) { | 
|  | 13098 | char *pos = os_strchr(buf + 7, ' '); | 
|  | 13099 | if (pos) { | 
|  | 13100 | *pos++ = '\0'; | 
|  | 13101 | return wpas_global_ctrl_iface_ifname(global, | 
|  | 13102 | buf + 7, pos, | 
|  | 13103 | resp_len); | 
|  | 13104 | } | 
|  | 13105 | } | 
|  | 13106 |  | 
|  | 13107 | reply = wpas_global_ctrl_iface_redir(global, buf, resp_len); | 
|  | 13108 | if (reply) | 
|  | 13109 | return reply; | 
|  | 13110 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 13111 | if (os_strcmp(buf, "PING") == 0) | 
|  | 13112 | level = MSG_EXCESSIVE; | 
|  | 13113 | wpa_hexdump_ascii(level, "RX global ctrl_iface", | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13114 | (const u8 *) buf, os_strlen(buf)); | 
|  | 13115 |  | 
|  | 13116 | reply = os_malloc(reply_size); | 
|  | 13117 | if (reply == NULL) { | 
|  | 13118 | *resp_len = 1; | 
|  | 13119 | return NULL; | 
|  | 13120 | } | 
|  | 13121 |  | 
|  | 13122 | os_memcpy(reply, "OK\n", 3); | 
|  | 13123 | reply_len = 3; | 
|  | 13124 |  | 
|  | 13125 | if (os_strcmp(buf, "PING") == 0) { | 
|  | 13126 | os_memcpy(reply, "PONG\n", 5); | 
|  | 13127 | reply_len = 5; | 
|  | 13128 | } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) { | 
|  | 13129 | if (wpa_supplicant_global_iface_add(global, buf + 14)) | 
|  | 13130 | reply_len = -1; | 
|  | 13131 | } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) { | 
|  | 13132 | if (wpa_supplicant_global_iface_remove(global, buf + 17)) | 
|  | 13133 | reply_len = -1; | 
|  | 13134 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { | 
|  | 13135 | reply_len = wpa_supplicant_global_iface_list( | 
|  | 13136 | global, reply, reply_size); | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 13137 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13138 | reply_len = wpa_supplicant_global_iface_interfaces( | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 13139 | global, buf + 10, reply, reply_size); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13140 | #ifdef CONFIG_FST | 
|  | 13141 | } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) { | 
|  | 13142 | reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11, | 
|  | 13143 | reply, | 
|  | 13144 | reply_size); | 
|  | 13145 | } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) { | 
|  | 13146 | reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11, | 
|  | 13147 | reply, | 
|  | 13148 | reply_size); | 
|  | 13149 | } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) { | 
|  | 13150 | reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size); | 
|  | 13151 | #endif /* CONFIG_FST */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13152 | } else if (os_strcmp(buf, "TERMINATE") == 0) { | 
|  | 13153 | wpa_supplicant_terminate_proc(global); | 
|  | 13154 | } else if (os_strcmp(buf, "SUSPEND") == 0) { | 
|  | 13155 | wpas_notify_suspend(global); | 
|  | 13156 | } else if (os_strcmp(buf, "RESUME") == 0) { | 
|  | 13157 | wpas_notify_resume(global); | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13158 | } else if (os_strncmp(buf, "SET ", 4) == 0) { | 
| Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 13159 | if (wpas_global_ctrl_iface_set(global, buf + 4)) { | 
|  | 13160 | #ifdef CONFIG_P2P | 
|  | 13161 | if (global->p2p_init_wpa_s) { | 
|  | 13162 | os_free(reply); | 
|  | 13163 | /* Check if P2P redirection would work for this | 
|  | 13164 | * command. */ | 
|  | 13165 | return wpa_supplicant_ctrl_iface_process( | 
|  | 13166 | global->p2p_init_wpa_s, | 
|  | 13167 | buf, resp_len); | 
|  | 13168 | } | 
|  | 13169 | #endif /* CONFIG_P2P */ | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13170 | reply_len = -1; | 
| Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 13171 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13172 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { | 
|  | 13173 | if (wpas_global_ctrl_iface_dup_network(global, buf + 12)) | 
|  | 13174 | reply_len = -1; | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 13175 | #ifndef CONFIG_NO_CONFIG_WRITE | 
|  | 13176 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { | 
|  | 13177 | if (wpas_global_ctrl_iface_save_config(global)) | 
|  | 13178 | reply_len = -1; | 
|  | 13179 | #endif /* CONFIG_NO_CONFIG_WRITE */ | 
|  | 13180 | } else if (os_strcmp(buf, "STATUS") == 0) { | 
|  | 13181 | reply_len = wpas_global_ctrl_iface_status(global, reply, | 
|  | 13182 | reply_size); | 
| Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 13183 | #ifdef CONFIG_MODULE_TESTS | 
|  | 13184 | } else if (os_strcmp(buf, "MODULE_TESTS") == 0) { | 
| Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 13185 | if (wpas_module_tests() < 0) | 
|  | 13186 | reply_len = -1; | 
|  | 13187 | #endif /* CONFIG_MODULE_TESTS */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 13188 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { | 
|  | 13189 | if (wpa_debug_reopen_file() < 0) | 
|  | 13190 | reply_len = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13191 | } else { | 
|  | 13192 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); | 
|  | 13193 | reply_len = 16; | 
|  | 13194 | } | 
|  | 13195 |  | 
|  | 13196 | if (reply_len < 0) { | 
|  | 13197 | os_memcpy(reply, "FAIL\n", 5); | 
|  | 13198 | reply_len = 5; | 
|  | 13199 | } | 
|  | 13200 |  | 
|  | 13201 | *resp_len = reply_len; | 
|  | 13202 | return reply; | 
|  | 13203 | } |