Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * WPA Supplicant / Control interface (shared code for all backends) |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3 | * Copyright (c) 2004-2015, 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 |
| 11 | #include <net/ethernet.h> |
| 12 | #include <netinet/ip.h> |
| 13 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14 | |
| 15 | #include "utils/common.h" |
| 16 | #include "utils/eloop.h" |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 17 | #include "utils/uuid.h" |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 18 | #include "utils/module_tests.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 19 | #include "common/version.h" |
| 20 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 21 | #include "common/ieee802_11_common.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 22 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 23 | #include "crypto/tls.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 24 | #include "ap/hostapd.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 25 | #include "eap_peer/eap.h" |
| 26 | #include "eapol_supp/eapol_supp_sm.h" |
| 27 | #include "rsn_supp/wpa.h" |
| 28 | #include "rsn_supp/preauth.h" |
| 29 | #include "rsn_supp/pmksa_cache.h" |
| 30 | #include "l2_packet/l2_packet.h" |
| 31 | #include "wps/wps.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 32 | #include "fst/fst.h" |
| 33 | #include "fst/fst_ctrl_iface.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 34 | #include "config.h" |
| 35 | #include "wpa_supplicant_i.h" |
| 36 | #include "driver_i.h" |
| 37 | #include "wps_supplicant.h" |
| 38 | #include "ibss_rsn.h" |
| 39 | #include "ap.h" |
| 40 | #include "p2p_supplicant.h" |
| 41 | #include "p2p/p2p.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 42 | #include "hs20_supplicant.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 43 | #include "wifi_display.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 44 | #include "notify.h" |
| 45 | #include "bss.h" |
| 46 | #include "scan.h" |
| 47 | #include "ctrl_iface.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 48 | #include "interworking.h" |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 49 | #include "blacklist.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 50 | #include "autoscan.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 51 | #include "wnm_sta.h" |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 52 | #include "offchannel.h" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 53 | #include "drivers/driver.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 54 | #include "mesh.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 55 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 56 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
| 57 | char *buf, int len); |
| 58 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 59 | const char *input, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 60 | char *buf, int len); |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 61 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, |
| 62 | char *val); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 63 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 64 | static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val) |
| 65 | { |
| 66 | char *pos; |
| 67 | u8 addr[ETH_ALEN], *filter = NULL, *n; |
| 68 | size_t count = 0; |
| 69 | |
| 70 | pos = val; |
| 71 | while (pos) { |
| 72 | if (*pos == '\0') |
| 73 | break; |
| 74 | if (hwaddr_aton(pos, addr)) { |
| 75 | os_free(filter); |
| 76 | return -1; |
| 77 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 78 | n = os_realloc_array(filter, count + 1, ETH_ALEN); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 79 | if (n == NULL) { |
| 80 | os_free(filter); |
| 81 | return -1; |
| 82 | } |
| 83 | filter = n; |
| 84 | os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN); |
| 85 | count++; |
| 86 | |
| 87 | pos = os_strchr(pos, ' '); |
| 88 | if (pos) |
| 89 | pos++; |
| 90 | } |
| 91 | |
| 92 | wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN); |
| 93 | os_free(wpa_s->bssid_filter); |
| 94 | wpa_s->bssid_filter = filter; |
| 95 | wpa_s->bssid_filter_count = count; |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 101 | static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val) |
| 102 | { |
| 103 | char *pos; |
| 104 | u8 addr[ETH_ALEN], *bssid = NULL, *n; |
| 105 | struct wpa_ssid_value *ssid = NULL, *ns; |
| 106 | size_t count = 0, ssid_count = 0; |
| 107 | struct wpa_ssid *c; |
| 108 | |
| 109 | /* |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 110 | * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | "" |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 111 | * SSID_SPEC ::= ssid <SSID_HEX> |
| 112 | * BSSID_SPEC ::= bssid <BSSID_HEX> |
| 113 | */ |
| 114 | |
| 115 | pos = val; |
| 116 | while (pos) { |
| 117 | if (*pos == '\0') |
| 118 | break; |
| 119 | if (os_strncmp(pos, "bssid ", 6) == 0) { |
| 120 | int res; |
| 121 | pos += 6; |
| 122 | res = hwaddr_aton2(pos, addr); |
| 123 | if (res < 0) { |
| 124 | os_free(ssid); |
| 125 | os_free(bssid); |
| 126 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " |
| 127 | "BSSID value '%s'", pos); |
| 128 | return -1; |
| 129 | } |
| 130 | pos += res; |
| 131 | n = os_realloc_array(bssid, count + 1, ETH_ALEN); |
| 132 | if (n == NULL) { |
| 133 | os_free(ssid); |
| 134 | os_free(bssid); |
| 135 | return -1; |
| 136 | } |
| 137 | bssid = n; |
| 138 | os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN); |
| 139 | count++; |
| 140 | } else if (os_strncmp(pos, "ssid ", 5) == 0) { |
| 141 | char *end; |
| 142 | pos += 5; |
| 143 | |
| 144 | end = pos; |
| 145 | while (*end) { |
| 146 | if (*end == '\0' || *end == ' ') |
| 147 | break; |
| 148 | end++; |
| 149 | } |
| 150 | |
| 151 | ns = os_realloc_array(ssid, ssid_count + 1, |
| 152 | sizeof(struct wpa_ssid_value)); |
| 153 | if (ns == NULL) { |
| 154 | os_free(ssid); |
| 155 | os_free(bssid); |
| 156 | return -1; |
| 157 | } |
| 158 | ssid = ns; |
| 159 | |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 160 | if ((end - pos) & 0x01 || |
| 161 | end - pos > 2 * SSID_MAX_LEN || |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 162 | hexstr2bin(pos, ssid[ssid_count].ssid, |
| 163 | (end - pos) / 2) < 0) { |
| 164 | os_free(ssid); |
| 165 | os_free(bssid); |
| 166 | wpa_printf(MSG_DEBUG, "Invalid disallow_aps " |
| 167 | "SSID value '%s'", pos); |
| 168 | return -1; |
| 169 | } |
| 170 | ssid[ssid_count].ssid_len = (end - pos) / 2; |
| 171 | wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID", |
| 172 | ssid[ssid_count].ssid, |
| 173 | ssid[ssid_count].ssid_len); |
| 174 | ssid_count++; |
| 175 | pos = end; |
| 176 | } else { |
| 177 | wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value " |
| 178 | "'%s'", pos); |
| 179 | os_free(ssid); |
| 180 | os_free(bssid); |
| 181 | return -1; |
| 182 | } |
| 183 | |
| 184 | pos = os_strchr(pos, ' '); |
| 185 | if (pos) |
| 186 | pos++; |
| 187 | } |
| 188 | |
| 189 | wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN); |
| 190 | os_free(wpa_s->disallow_aps_bssid); |
| 191 | wpa_s->disallow_aps_bssid = bssid; |
| 192 | wpa_s->disallow_aps_bssid_count = count; |
| 193 | |
| 194 | wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count); |
| 195 | os_free(wpa_s->disallow_aps_ssid); |
| 196 | wpa_s->disallow_aps_ssid = ssid; |
| 197 | wpa_s->disallow_aps_ssid_count = ssid_count; |
| 198 | |
| 199 | if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING) |
| 200 | return 0; |
| 201 | |
| 202 | c = wpa_s->current_ssid; |
| 203 | if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS) |
| 204 | return 0; |
| 205 | |
| 206 | if (!disallowed_bssid(wpa_s, wpa_s->bssid) && |
| 207 | !disallowed_ssid(wpa_s, c->ssid, c->ssid_len)) |
| 208 | return 0; |
| 209 | |
| 210 | wpa_printf(MSG_DEBUG, "Disconnect and try to find another network " |
| 211 | "because current AP was marked disallowed"); |
| 212 | |
| 213 | #ifdef CONFIG_SME |
| 214 | wpa_s->sme.prev_bssid_set = 0; |
| 215 | #endif /* CONFIG_SME */ |
| 216 | wpa_s->reassociate = 1; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 217 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 218 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 219 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 225 | #ifndef CONFIG_NO_CONFIG_BLOBS |
| 226 | static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos) |
| 227 | { |
| 228 | char *name = pos; |
| 229 | struct wpa_config_blob *blob; |
| 230 | size_t len; |
| 231 | |
| 232 | pos = os_strchr(pos, ' '); |
| 233 | if (pos == NULL) |
| 234 | return -1; |
| 235 | *pos++ = '\0'; |
| 236 | len = os_strlen(pos); |
| 237 | if (len & 1) |
| 238 | return -1; |
| 239 | |
| 240 | wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name); |
| 241 | blob = os_zalloc(sizeof(*blob)); |
| 242 | if (blob == NULL) |
| 243 | return -1; |
| 244 | blob->name = os_strdup(name); |
| 245 | blob->data = os_malloc(len / 2); |
| 246 | if (blob->name == NULL || blob->data == NULL) { |
| 247 | wpa_config_free_blob(blob); |
| 248 | return -1; |
| 249 | } |
| 250 | |
| 251 | if (hexstr2bin(pos, blob->data, len / 2) < 0) { |
| 252 | wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data"); |
| 253 | wpa_config_free_blob(blob); |
| 254 | return -1; |
| 255 | } |
| 256 | blob->len = len / 2; |
| 257 | |
| 258 | wpa_config_set_blob(wpa_s->conf, blob); |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
| 263 | |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 264 | |
| 265 | static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd) |
| 266 | { |
| 267 | char *params; |
| 268 | char *pos; |
| 269 | int *freqs = NULL; |
| 270 | int ret; |
| 271 | |
| 272 | if (atoi(cmd)) { |
| 273 | params = os_strchr(cmd, ' '); |
| 274 | os_free(wpa_s->manual_sched_scan_freqs); |
| 275 | if (params) { |
| 276 | params++; |
| 277 | pos = os_strstr(params, "freq="); |
| 278 | if (pos) |
| 279 | freqs = freq_range_to_channel_list(wpa_s, |
| 280 | pos + 5); |
| 281 | } |
| 282 | wpa_s->manual_sched_scan_freqs = freqs; |
| 283 | ret = wpas_start_pno(wpa_s); |
| 284 | } else { |
| 285 | ret = wpas_stop_pno(wpa_s); |
| 286 | } |
| 287 | return ret; |
| 288 | } |
| 289 | |
| 290 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 291 | static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band) |
| 292 | { |
| 293 | union wpa_event_data event; |
| 294 | |
| 295 | if (os_strcmp(band, "AUTO") == 0) |
| 296 | wpa_s->setband = WPA_SETBAND_AUTO; |
| 297 | else if (os_strcmp(band, "5G") == 0) |
| 298 | wpa_s->setband = WPA_SETBAND_5G; |
| 299 | else if (os_strcmp(band, "2G") == 0) |
| 300 | wpa_s->setband = WPA_SETBAND_2G; |
| 301 | else |
| 302 | return -1; |
| 303 | |
| 304 | if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) { |
| 305 | os_memset(&event, 0, sizeof(event)); |
| 306 | event.channel_list_changed.initiator = REGDOM_SET_BY_USER; |
| 307 | event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN; |
| 308 | wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event); |
| 309 | } |
| 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 315 | static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s, |
| 316 | const char *cmd) |
| 317 | { |
| 318 | struct wpabuf *lci; |
| 319 | |
| 320 | if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) { |
| 321 | wpabuf_free(wpa_s->lci); |
| 322 | wpa_s->lci = NULL; |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | lci = wpabuf_parse_bin(cmd); |
| 327 | if (!lci) |
| 328 | return -1; |
| 329 | |
| 330 | if (os_get_reltime(&wpa_s->lci_time)) { |
| 331 | wpabuf_free(lci); |
| 332 | return -1; |
| 333 | } |
| 334 | |
| 335 | wpabuf_free(wpa_s->lci); |
| 336 | wpa_s->lci = lci; |
| 337 | |
| 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 342 | static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, |
| 343 | char *cmd) |
| 344 | { |
| 345 | char *value; |
| 346 | int ret = 0; |
| 347 | |
| 348 | value = os_strchr(cmd, ' '); |
| 349 | if (value == NULL) |
| 350 | return -1; |
| 351 | *value++ = '\0'; |
| 352 | |
| 353 | wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value); |
| 354 | if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) { |
| 355 | eapol_sm_configure(wpa_s->eapol, |
| 356 | atoi(value), -1, -1, -1); |
| 357 | } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) { |
| 358 | eapol_sm_configure(wpa_s->eapol, |
| 359 | -1, atoi(value), -1, -1); |
| 360 | } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) { |
| 361 | eapol_sm_configure(wpa_s->eapol, |
| 362 | -1, -1, atoi(value), -1); |
| 363 | } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) { |
| 364 | eapol_sm_configure(wpa_s->eapol, |
| 365 | -1, -1, -1, atoi(value)); |
| 366 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) { |
| 367 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, |
| 368 | atoi(value))) |
| 369 | ret = -1; |
| 370 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == |
| 371 | 0) { |
| 372 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, |
| 373 | atoi(value))) |
| 374 | ret = -1; |
| 375 | } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) { |
| 376 | if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value))) |
| 377 | ret = -1; |
| 378 | } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) { |
| 379 | wpa_s->wps_fragment_size = atoi(value); |
| 380 | #ifdef CONFIG_WPS_TESTING |
| 381 | } else if (os_strcasecmp(cmd, "wps_version_number") == 0) { |
| 382 | long int val; |
| 383 | val = strtol(value, NULL, 0); |
| 384 | if (val < 0 || val > 0xff) { |
| 385 | ret = -1; |
| 386 | wpa_printf(MSG_DEBUG, "WPS: Invalid " |
| 387 | "wps_version_number %ld", val); |
| 388 | } else { |
| 389 | wps_version_number = val; |
| 390 | wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS " |
| 391 | "version %u.%u", |
| 392 | (wps_version_number & 0xf0) >> 4, |
| 393 | wps_version_number & 0x0f); |
| 394 | } |
| 395 | } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) { |
| 396 | wps_testing_dummy_cred = atoi(value); |
| 397 | wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d", |
| 398 | wps_testing_dummy_cred); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 399 | } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) { |
| 400 | wps_corrupt_pkhash = atoi(value); |
| 401 | wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d", |
| 402 | wps_corrupt_pkhash); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 403 | } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) { |
| 404 | if (value[0] == '\0') { |
| 405 | wps_force_auth_types_in_use = 0; |
| 406 | } else { |
| 407 | wps_force_auth_types = strtol(value, NULL, 0); |
| 408 | wps_force_auth_types_in_use = 1; |
| 409 | } |
| 410 | } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) { |
| 411 | if (value[0] == '\0') { |
| 412 | wps_force_encr_types_in_use = 0; |
| 413 | } else { |
| 414 | wps_force_encr_types = strtol(value, NULL, 0); |
| 415 | wps_force_encr_types_in_use = 1; |
| 416 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 417 | #endif /* CONFIG_WPS_TESTING */ |
| 418 | } else if (os_strcasecmp(cmd, "ampdu") == 0) { |
| 419 | if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0) |
| 420 | ret = -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 421 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 422 | #ifdef CONFIG_TDLS_TESTING |
| 423 | } else if (os_strcasecmp(cmd, "tdls_testing") == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 424 | tdls_testing = strtol(value, NULL, 0); |
| 425 | wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing); |
| 426 | #endif /* CONFIG_TDLS_TESTING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 427 | } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) { |
| 428 | int disabled = atoi(value); |
| 429 | wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled); |
| 430 | if (disabled) { |
| 431 | if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0) |
| 432 | ret = -1; |
| 433 | } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0) |
| 434 | ret = -1; |
| 435 | wpa_tdls_enable(wpa_s->wpa, !disabled); |
| 436 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 437 | } else if (os_strcasecmp(cmd, "pno") == 0) { |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 438 | ret = wpas_ctrl_pno(wpa_s, value); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 439 | } else if (os_strcasecmp(cmd, "radio_disabled") == 0) { |
| 440 | int disabled = atoi(value); |
| 441 | if (wpa_drv_radio_disable(wpa_s, disabled) < 0) |
| 442 | ret = -1; |
| 443 | else if (disabled) |
| 444 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
| 445 | } else if (os_strcasecmp(cmd, "uapsd") == 0) { |
| 446 | if (os_strcmp(value, "disable") == 0) |
| 447 | wpa_s->set_sta_uapsd = 0; |
| 448 | else { |
| 449 | int be, bk, vi, vo; |
| 450 | char *pos; |
| 451 | /* format: BE,BK,VI,VO;max SP Length */ |
| 452 | be = atoi(value); |
| 453 | pos = os_strchr(value, ','); |
| 454 | if (pos == NULL) |
| 455 | return -1; |
| 456 | pos++; |
| 457 | bk = atoi(pos); |
| 458 | pos = os_strchr(pos, ','); |
| 459 | if (pos == NULL) |
| 460 | return -1; |
| 461 | pos++; |
| 462 | vi = atoi(pos); |
| 463 | pos = os_strchr(pos, ','); |
| 464 | if (pos == NULL) |
| 465 | return -1; |
| 466 | pos++; |
| 467 | vo = atoi(pos); |
| 468 | /* ignore max SP Length for now */ |
| 469 | |
| 470 | wpa_s->set_sta_uapsd = 1; |
| 471 | wpa_s->sta_uapsd = 0; |
| 472 | if (be) |
| 473 | wpa_s->sta_uapsd |= BIT(0); |
| 474 | if (bk) |
| 475 | wpa_s->sta_uapsd |= BIT(1); |
| 476 | if (vi) |
| 477 | wpa_s->sta_uapsd |= BIT(2); |
| 478 | if (vo) |
| 479 | wpa_s->sta_uapsd |= BIT(3); |
| 480 | } |
Jouni Malinen | 21d6bc8 | 2012-04-10 16:17:59 -0700 | [diff] [blame] | 481 | } else if (os_strcasecmp(cmd, "ps") == 0) { |
| 482 | ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 483 | #ifdef CONFIG_WIFI_DISPLAY |
| 484 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { |
Dmitry Shmidt | ed003d2 | 2014-02-06 10:09:12 -0800 | [diff] [blame] | 485 | int enabled = !!atoi(value); |
| 486 | if (enabled && !wpa_s->global->p2p) |
| 487 | ret = -1; |
| 488 | else |
| 489 | wifi_display_enable(wpa_s->global, enabled); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 490 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 491 | } else if (os_strcasecmp(cmd, "bssid_filter") == 0) { |
| 492 | ret = set_bssid_filter(wpa_s, value); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 493 | } else if (os_strcasecmp(cmd, "disallow_aps") == 0) { |
| 494 | ret = set_disallow_aps(wpa_s, value); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 495 | } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) { |
| 496 | wpa_s->no_keep_alive = !!atoi(value); |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 497 | #ifdef CONFIG_TESTING_OPTIONS |
| 498 | } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) { |
| 499 | wpa_s->ext_mgmt_frame_handling = !!atoi(value); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 500 | } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) { |
| 501 | wpa_s->ext_eapol_frame_io = !!atoi(value); |
| 502 | #ifdef CONFIG_AP |
| 503 | if (wpa_s->ap_iface) { |
| 504 | wpa_s->ap_iface->bss[0]->ext_eapol_frame_io = |
| 505 | wpa_s->ext_eapol_frame_io; |
| 506 | } |
| 507 | #endif /* CONFIG_AP */ |
| 508 | } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) { |
| 509 | wpa_s->extra_roc_dur = atoi(value); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 510 | } else if (os_strcasecmp(cmd, "test_failure") == 0) { |
| 511 | wpa_s->test_failure = atoi(value); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 512 | } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) { |
| 513 | wpa_s->p2p_go_csa_on_inv = !!atoi(value); |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame^] | 514 | } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) { |
| 515 | wpa_s->ignore_auth_resp = !!atoi(value); |
| 516 | } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) { |
| 517 | wpa_s->ignore_assoc_disallow = !!atoi(value); |
| 518 | } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) { |
| 519 | wpa_s->reject_btm_req_reason = atoi(value); |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 520 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 521 | #ifndef CONFIG_NO_CONFIG_BLOBS |
| 522 | } else if (os_strcmp(cmd, "blob") == 0) { |
| 523 | ret = wpas_ctrl_set_blob(wpa_s, value); |
| 524 | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 525 | } else if (os_strcasecmp(cmd, "setband") == 0) { |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 526 | ret = wpas_ctrl_set_band(wpa_s, value); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 527 | #ifdef CONFIG_MBO |
| 528 | } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) { |
| 529 | ret = wpas_mbo_update_non_pref_chan(wpa_s, value); |
| 530 | } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) { |
| 531 | wpas_mbo_update_cell_capa(wpa_s, atoi(value)); |
| 532 | #endif /* CONFIG_MBO */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 533 | } else if (os_strcasecmp(cmd, "lci") == 0) { |
| 534 | ret = wpas_ctrl_iface_set_lci(wpa_s, value); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 535 | } else { |
| 536 | value[-1] = '='; |
| 537 | ret = wpa_config_process_global(wpa_s->conf, cmd, -1); |
| 538 | if (ret == 0) |
| 539 | wpa_supplicant_update_config(wpa_s); |
| 540 | } |
| 541 | |
| 542 | return ret; |
| 543 | } |
| 544 | |
| 545 | |
| 546 | static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s, |
| 547 | char *cmd, char *buf, size_t buflen) |
| 548 | { |
Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 549 | int res = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 550 | |
| 551 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd); |
| 552 | |
| 553 | if (os_strcmp(cmd, "version") == 0) { |
| 554 | res = os_snprintf(buf, buflen, "%s", VERSION_STR); |
Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 555 | } else if (os_strcasecmp(cmd, "country") == 0) { |
| 556 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) |
| 557 | res = os_snprintf(buf, buflen, "%c%c", |
| 558 | wpa_s->conf->country[0], |
| 559 | wpa_s->conf->country[1]); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 560 | #ifdef CONFIG_WIFI_DISPLAY |
| 561 | } else if (os_strcasecmp(cmd, "wifi_display") == 0) { |
Dmitry Shmidt | ed003d2 | 2014-02-06 10:09:12 -0800 | [diff] [blame] | 562 | int enabled; |
| 563 | if (wpa_s->global->p2p == NULL || |
| 564 | wpa_s->global->p2p_disabled) |
| 565 | enabled = 0; |
| 566 | else |
| 567 | enabled = wpa_s->global->wifi_display; |
| 568 | res = os_snprintf(buf, buflen, "%d", enabled); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 569 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 570 | #ifdef CONFIG_TESTING_GET_GTK |
| 571 | } else if (os_strcmp(cmd, "gtk") == 0) { |
| 572 | if (wpa_s->last_gtk_len == 0) |
| 573 | return -1; |
| 574 | res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk, |
| 575 | wpa_s->last_gtk_len); |
| 576 | return res; |
| 577 | #endif /* CONFIG_TESTING_GET_GTK */ |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 578 | } else if (os_strcmp(cmd, "tls_library") == 0) { |
| 579 | res = tls_get_library_version(buf, buflen); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 580 | } else { |
| 581 | res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 584 | if (os_snprintf_error(buflen, res)) |
Dmitry Shmidt | 6f3bdcf | 2011-04-19 16:42:47 -0700 | [diff] [blame] | 585 | return -1; |
| 586 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | |
| 590 | #ifdef IEEE8021X_EAPOL |
| 591 | static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s, |
| 592 | char *addr) |
| 593 | { |
| 594 | u8 bssid[ETH_ALEN]; |
| 595 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 596 | |
| 597 | if (hwaddr_aton(addr, bssid)) { |
| 598 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address " |
| 599 | "'%s'", addr); |
| 600 | return -1; |
| 601 | } |
| 602 | |
| 603 | wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid)); |
| 604 | rsn_preauth_deinit(wpa_s->wpa); |
| 605 | if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL)) |
| 606 | return -1; |
| 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | #endif /* IEEE8021X_EAPOL */ |
| 611 | |
| 612 | |
| 613 | #ifdef CONFIG_PEERKEY |
| 614 | /* MLME-STKSTART.request(peer) */ |
| 615 | static int wpa_supplicant_ctrl_iface_stkstart( |
| 616 | struct wpa_supplicant *wpa_s, char *addr) |
| 617 | { |
| 618 | u8 peer[ETH_ALEN]; |
| 619 | |
| 620 | if (hwaddr_aton(addr, peer)) { |
| 621 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid " |
| 622 | "address '%s'", addr); |
| 623 | return -1; |
| 624 | } |
| 625 | |
| 626 | wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR, |
| 627 | MAC2STR(peer)); |
| 628 | |
| 629 | return wpa_sm_stkstart(wpa_s->wpa, peer); |
| 630 | } |
| 631 | #endif /* CONFIG_PEERKEY */ |
| 632 | |
| 633 | |
| 634 | #ifdef CONFIG_TDLS |
| 635 | |
| 636 | static int wpa_supplicant_ctrl_iface_tdls_discover( |
| 637 | struct wpa_supplicant *wpa_s, char *addr) |
| 638 | { |
| 639 | u8 peer[ETH_ALEN]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 640 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 641 | |
| 642 | if (hwaddr_aton(addr, peer)) { |
| 643 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid " |
| 644 | "address '%s'", addr); |
| 645 | return -1; |
| 646 | } |
| 647 | |
| 648 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR, |
| 649 | MAC2STR(peer)); |
| 650 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 651 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 652 | ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer); |
| 653 | else |
| 654 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); |
| 655 | |
| 656 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | |
| 660 | static int wpa_supplicant_ctrl_iface_tdls_setup( |
| 661 | struct wpa_supplicant *wpa_s, char *addr) |
| 662 | { |
| 663 | u8 peer[ETH_ALEN]; |
| 664 | int ret; |
| 665 | |
| 666 | if (hwaddr_aton(addr, peer)) { |
| 667 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid " |
| 668 | "address '%s'", addr); |
| 669 | return -1; |
| 670 | } |
| 671 | |
| 672 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR, |
| 673 | MAC2STR(peer)); |
| 674 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 675 | if ((wpa_s->conf->tdls_external_control) && |
| 676 | wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 677 | return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); |
| 678 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 679 | wpa_tdls_remove(wpa_s->wpa, peer); |
| 680 | |
| 681 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 682 | ret = wpa_tdls_start(wpa_s->wpa, peer); |
| 683 | else |
| 684 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 685 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 686 | return ret; |
| 687 | } |
| 688 | |
| 689 | |
| 690 | static int wpa_supplicant_ctrl_iface_tdls_teardown( |
| 691 | struct wpa_supplicant *wpa_s, char *addr) |
| 692 | { |
| 693 | u8 peer[ETH_ALEN]; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 694 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 695 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 696 | if (os_strcmp(addr, "*") == 0) { |
| 697 | /* remove everyone */ |
| 698 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *"); |
| 699 | wpa_tdls_teardown_peers(wpa_s->wpa); |
| 700 | return 0; |
| 701 | } |
| 702 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 703 | if (hwaddr_aton(addr, peer)) { |
| 704 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid " |
| 705 | "address '%s'", addr); |
| 706 | return -1; |
| 707 | } |
| 708 | |
| 709 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR, |
| 710 | MAC2STR(peer)); |
| 711 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 712 | if ((wpa_s->conf->tdls_external_control) && |
| 713 | wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 714 | return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); |
| 715 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 716 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 717 | ret = wpa_tdls_teardown_link( |
| 718 | wpa_s->wpa, peer, |
| 719 | WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED); |
| 720 | else |
| 721 | ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); |
| 722 | |
| 723 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 726 | |
| 727 | static int ctrl_iface_get_capability_tdls( |
| 728 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| 729 | { |
| 730 | int ret; |
| 731 | |
| 732 | ret = os_snprintf(buf, buflen, "%s\n", |
| 733 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ? |
| 734 | (wpa_s->drv_flags & |
| 735 | WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ? |
| 736 | "EXTERNAL" : "INTERNAL") : "UNSUPPORTED"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 737 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 738 | return -1; |
| 739 | return ret; |
| 740 | } |
| 741 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 742 | |
| 743 | static int wpa_supplicant_ctrl_iface_tdls_chan_switch( |
| 744 | struct wpa_supplicant *wpa_s, char *cmd) |
| 745 | { |
| 746 | u8 peer[ETH_ALEN]; |
| 747 | struct hostapd_freq_params freq_params; |
| 748 | u8 oper_class; |
| 749 | char *pos, *end; |
| 750 | |
| 751 | if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { |
| 752 | wpa_printf(MSG_INFO, |
| 753 | "tdls_chanswitch: Only supported with external setup"); |
| 754 | return -1; |
| 755 | } |
| 756 | |
| 757 | os_memset(&freq_params, 0, sizeof(freq_params)); |
| 758 | |
| 759 | pos = os_strchr(cmd, ' '); |
| 760 | if (pos == NULL) |
| 761 | return -1; |
| 762 | *pos++ = '\0'; |
| 763 | |
| 764 | oper_class = strtol(pos, &end, 10); |
| 765 | if (pos == end) { |
| 766 | wpa_printf(MSG_INFO, |
| 767 | "tdls_chanswitch: Invalid op class provided"); |
| 768 | return -1; |
| 769 | } |
| 770 | |
| 771 | pos = end; |
| 772 | freq_params.freq = atoi(pos); |
| 773 | if (freq_params.freq == 0) { |
| 774 | wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided"); |
| 775 | return -1; |
| 776 | } |
| 777 | |
| 778 | #define SET_FREQ_SETTING(str) \ |
| 779 | do { \ |
| 780 | const char *pos2 = os_strstr(pos, " " #str "="); \ |
| 781 | if (pos2) { \ |
| 782 | pos2 += sizeof(" " #str "=") - 1; \ |
| 783 | freq_params.str = atoi(pos2); \ |
| 784 | } \ |
| 785 | } while (0) |
| 786 | |
| 787 | SET_FREQ_SETTING(center_freq1); |
| 788 | SET_FREQ_SETTING(center_freq2); |
| 789 | SET_FREQ_SETTING(bandwidth); |
| 790 | SET_FREQ_SETTING(sec_channel_offset); |
| 791 | #undef SET_FREQ_SETTING |
| 792 | |
| 793 | freq_params.ht_enabled = !!os_strstr(pos, " ht"); |
| 794 | freq_params.vht_enabled = !!os_strstr(pos, " vht"); |
| 795 | |
| 796 | if (hwaddr_aton(cmd, peer)) { |
| 797 | wpa_printf(MSG_DEBUG, |
| 798 | "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'", |
| 799 | cmd); |
| 800 | return -1; |
| 801 | } |
| 802 | |
| 803 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR |
| 804 | " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s", |
| 805 | MAC2STR(peer), oper_class, freq_params.freq, |
| 806 | freq_params.center_freq1, freq_params.center_freq2, |
| 807 | freq_params.bandwidth, freq_params.sec_channel_offset, |
| 808 | freq_params.ht_enabled ? " HT" : "", |
| 809 | freq_params.vht_enabled ? " VHT" : ""); |
| 810 | |
| 811 | return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class, |
| 812 | &freq_params); |
| 813 | } |
| 814 | |
| 815 | |
| 816 | static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch( |
| 817 | struct wpa_supplicant *wpa_s, char *cmd) |
| 818 | { |
| 819 | u8 peer[ETH_ALEN]; |
| 820 | |
| 821 | if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { |
| 822 | wpa_printf(MSG_INFO, |
| 823 | "tdls_chanswitch: Only supported with external setup"); |
| 824 | return -1; |
| 825 | } |
| 826 | |
| 827 | if (hwaddr_aton(cmd, peer)) { |
| 828 | wpa_printf(MSG_DEBUG, |
| 829 | "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'", |
| 830 | cmd); |
| 831 | return -1; |
| 832 | } |
| 833 | |
| 834 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR, |
| 835 | MAC2STR(peer)); |
| 836 | |
| 837 | return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer); |
| 838 | } |
| 839 | |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 840 | |
| 841 | static int wpa_supplicant_ctrl_iface_tdls_link_status( |
| 842 | struct wpa_supplicant *wpa_s, const char *addr, |
| 843 | char *buf, size_t buflen) |
| 844 | { |
| 845 | u8 peer[ETH_ALEN]; |
| 846 | const char *tdls_status; |
| 847 | int ret; |
| 848 | |
| 849 | if (hwaddr_aton(addr, peer)) { |
| 850 | wpa_printf(MSG_DEBUG, |
| 851 | "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'", |
| 852 | addr); |
| 853 | return -1; |
| 854 | } |
| 855 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR, |
| 856 | MAC2STR(peer)); |
| 857 | |
| 858 | tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer); |
| 859 | wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status); |
| 860 | ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status); |
| 861 | if (os_snprintf_error(buflen, ret)) |
| 862 | return -1; |
| 863 | |
| 864 | return ret; |
| 865 | } |
| 866 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 867 | #endif /* CONFIG_TDLS */ |
| 868 | |
| 869 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 870 | static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd) |
| 871 | { |
| 872 | char *token, *context = NULL; |
| 873 | struct wmm_ac_ts_setup_params params = { |
| 874 | .tsid = 0xff, |
| 875 | .direction = 0xff, |
| 876 | }; |
| 877 | |
| 878 | while ((token = str_token(cmd, " ", &context))) { |
| 879 | if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 || |
| 880 | sscanf(token, "up=%i", ¶ms.user_priority) == 1 || |
| 881 | sscanf(token, "nominal_msdu_size=%i", |
| 882 | ¶ms.nominal_msdu_size) == 1 || |
| 883 | sscanf(token, "mean_data_rate=%i", |
| 884 | ¶ms.mean_data_rate) == 1 || |
| 885 | sscanf(token, "min_phy_rate=%i", |
| 886 | ¶ms.minimum_phy_rate) == 1 || |
| 887 | sscanf(token, "sba=%i", |
| 888 | ¶ms.surplus_bandwidth_allowance) == 1) |
| 889 | continue; |
| 890 | |
| 891 | if (os_strcasecmp(token, "downlink") == 0) { |
| 892 | params.direction = WMM_TSPEC_DIRECTION_DOWNLINK; |
| 893 | } else if (os_strcasecmp(token, "uplink") == 0) { |
| 894 | params.direction = WMM_TSPEC_DIRECTION_UPLINK; |
| 895 | } else if (os_strcasecmp(token, "bidi") == 0) { |
| 896 | params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL; |
| 897 | } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) { |
| 898 | params.fixed_nominal_msdu = 1; |
| 899 | } else { |
| 900 | wpa_printf(MSG_DEBUG, |
| 901 | "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'", |
| 902 | token); |
| 903 | return -1; |
| 904 | } |
| 905 | |
| 906 | } |
| 907 | |
| 908 | return wpas_wmm_ac_addts(wpa_s, ¶ms); |
| 909 | } |
| 910 | |
| 911 | |
| 912 | static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd) |
| 913 | { |
| 914 | u8 tsid = atoi(cmd); |
| 915 | |
| 916 | return wpas_wmm_ac_delts(wpa_s, tsid); |
| 917 | } |
| 918 | |
| 919 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 920 | #ifdef CONFIG_IEEE80211R |
| 921 | static int wpa_supplicant_ctrl_iface_ft_ds( |
| 922 | struct wpa_supplicant *wpa_s, char *addr) |
| 923 | { |
| 924 | u8 target_ap[ETH_ALEN]; |
| 925 | struct wpa_bss *bss; |
| 926 | const u8 *mdie; |
| 927 | |
| 928 | if (hwaddr_aton(addr, target_ap)) { |
| 929 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid " |
| 930 | "address '%s'", addr); |
| 931 | return -1; |
| 932 | } |
| 933 | |
| 934 | wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap)); |
| 935 | |
| 936 | bss = wpa_bss_get_bssid(wpa_s, target_ap); |
| 937 | if (bss) |
| 938 | mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); |
| 939 | else |
| 940 | mdie = NULL; |
| 941 | |
| 942 | return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie); |
| 943 | } |
| 944 | #endif /* CONFIG_IEEE80211R */ |
| 945 | |
| 946 | |
| 947 | #ifdef CONFIG_WPS |
| 948 | static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s, |
| 949 | char *cmd) |
| 950 | { |
| 951 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 952 | #ifdef CONFIG_P2P |
| 953 | u8 p2p_dev_addr[ETH_ALEN]; |
| 954 | #endif /* CONFIG_P2P */ |
| 955 | #ifdef CONFIG_AP |
| 956 | u8 *_p2p_dev_addr = NULL; |
| 957 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 958 | |
Dmitry Shmidt | c0a8db0 | 2013-11-08 11:18:33 -0800 | [diff] [blame] | 959 | if (cmd == NULL || os_strcmp(cmd, "any") == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 960 | _bssid = NULL; |
| 961 | #ifdef CONFIG_P2P |
| 962 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { |
| 963 | if (hwaddr_aton(cmd + 13, p2p_dev_addr)) { |
| 964 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid " |
| 965 | "P2P Device Address '%s'", |
| 966 | cmd + 13); |
| 967 | return -1; |
| 968 | } |
| 969 | _p2p_dev_addr = p2p_dev_addr; |
| 970 | #endif /* CONFIG_P2P */ |
| 971 | } else if (hwaddr_aton(cmd, bssid)) { |
| 972 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'", |
| 973 | cmd); |
| 974 | return -1; |
| 975 | } |
| 976 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 977 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 978 | if (wpa_s->ap_iface) |
| 979 | return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr); |
| 980 | #endif /* CONFIG_AP */ |
| 981 | |
| 982 | return wpas_wps_start_pbc(wpa_s, _bssid, 0); |
| 983 | } |
| 984 | |
| 985 | |
| 986 | static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, |
| 987 | char *cmd, char *buf, |
| 988 | size_t buflen) |
| 989 | { |
| 990 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
| 991 | char *pin; |
| 992 | int ret; |
| 993 | |
| 994 | pin = os_strchr(cmd, ' '); |
| 995 | if (pin) |
| 996 | *pin++ = '\0'; |
| 997 | |
| 998 | if (os_strcmp(cmd, "any") == 0) |
| 999 | _bssid = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1000 | else if (os_strcmp(cmd, "get") == 0) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1001 | if (wps_generate_pin((unsigned int *) &ret) < 0) |
| 1002 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1003 | goto done; |
| 1004 | } else if (hwaddr_aton(cmd, bssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1005 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'", |
| 1006 | cmd); |
| 1007 | return -1; |
| 1008 | } |
| 1009 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1010 | #ifdef CONFIG_AP |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1011 | if (wpa_s->ap_iface) { |
| 1012 | int timeout = 0; |
| 1013 | char *pos; |
| 1014 | |
| 1015 | if (pin) { |
| 1016 | pos = os_strchr(pin, ' '); |
| 1017 | if (pos) { |
| 1018 | *pos++ = '\0'; |
| 1019 | timeout = atoi(pos); |
| 1020 | } |
| 1021 | } |
| 1022 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1023 | return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1024 | buf, buflen, timeout); |
| 1025 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1026 | #endif /* CONFIG_AP */ |
| 1027 | |
| 1028 | if (pin) { |
| 1029 | ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0, |
| 1030 | DEV_PW_DEFAULT); |
| 1031 | if (ret < 0) |
| 1032 | return -1; |
| 1033 | ret = os_snprintf(buf, buflen, "%s", pin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1034 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1035 | return -1; |
| 1036 | return ret; |
| 1037 | } |
| 1038 | |
| 1039 | ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT); |
| 1040 | if (ret < 0) |
| 1041 | return -1; |
| 1042 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1043 | done: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1044 | /* Return the generated PIN */ |
| 1045 | ret = os_snprintf(buf, buflen, "%08d", ret); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1046 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1047 | return -1; |
| 1048 | return ret; |
| 1049 | } |
| 1050 | |
| 1051 | |
| 1052 | static int wpa_supplicant_ctrl_iface_wps_check_pin( |
| 1053 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| 1054 | { |
| 1055 | char pin[9]; |
| 1056 | size_t len; |
| 1057 | char *pos; |
| 1058 | int ret; |
| 1059 | |
| 1060 | wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN", |
| 1061 | (u8 *) cmd, os_strlen(cmd)); |
| 1062 | for (pos = cmd, len = 0; *pos != '\0'; pos++) { |
| 1063 | if (*pos < '0' || *pos > '9') |
| 1064 | continue; |
| 1065 | pin[len++] = *pos; |
| 1066 | if (len == 9) { |
| 1067 | wpa_printf(MSG_DEBUG, "WPS: Too long PIN"); |
| 1068 | return -1; |
| 1069 | } |
| 1070 | } |
| 1071 | if (len != 4 && len != 8) { |
| 1072 | wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len); |
| 1073 | return -1; |
| 1074 | } |
| 1075 | pin[len] = '\0'; |
| 1076 | |
| 1077 | if (len == 8) { |
| 1078 | unsigned int pin_val; |
| 1079 | pin_val = atoi(pin); |
| 1080 | if (!wps_pin_valid(pin_val)) { |
| 1081 | wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit"); |
| 1082 | ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1083 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1084 | return -1; |
| 1085 | return ret; |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | ret = os_snprintf(buf, buflen, "%s", pin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1090 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1091 | return -1; |
| 1092 | |
| 1093 | return ret; |
| 1094 | } |
| 1095 | |
| 1096 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1097 | #ifdef CONFIG_WPS_NFC |
| 1098 | |
| 1099 | static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s, |
| 1100 | char *cmd) |
| 1101 | { |
| 1102 | u8 bssid[ETH_ALEN], *_bssid = bssid; |
| 1103 | |
| 1104 | if (cmd == NULL || cmd[0] == '\0') |
| 1105 | _bssid = NULL; |
| 1106 | else if (hwaddr_aton(cmd, bssid)) |
| 1107 | return -1; |
| 1108 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1109 | return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL, |
| 1110 | 0, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1114 | static int wpa_supplicant_ctrl_iface_wps_nfc_config_token( |
| 1115 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| 1116 | { |
| 1117 | int ndef; |
| 1118 | struct wpabuf *buf; |
| 1119 | int res; |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1120 | char *pos; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1121 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1122 | pos = os_strchr(cmd, ' '); |
| 1123 | if (pos) |
| 1124 | *pos++ = '\0'; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1125 | if (os_strcmp(cmd, "WPS") == 0) |
| 1126 | ndef = 0; |
| 1127 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1128 | ndef = 1; |
| 1129 | else |
| 1130 | return -1; |
| 1131 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1132 | buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1133 | if (buf == NULL) |
| 1134 | return -1; |
| 1135 | |
| 1136 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1137 | wpabuf_len(buf)); |
| 1138 | reply[res++] = '\n'; |
| 1139 | reply[res] = '\0'; |
| 1140 | |
| 1141 | wpabuf_free(buf); |
| 1142 | |
| 1143 | return res; |
| 1144 | } |
| 1145 | |
| 1146 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1147 | static int wpa_supplicant_ctrl_iface_wps_nfc_token( |
| 1148 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| 1149 | { |
| 1150 | int ndef; |
| 1151 | struct wpabuf *buf; |
| 1152 | int res; |
| 1153 | |
| 1154 | if (os_strcmp(cmd, "WPS") == 0) |
| 1155 | ndef = 0; |
| 1156 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1157 | ndef = 1; |
| 1158 | else |
| 1159 | return -1; |
| 1160 | |
| 1161 | buf = wpas_wps_nfc_token(wpa_s, ndef); |
| 1162 | if (buf == NULL) |
| 1163 | return -1; |
| 1164 | |
| 1165 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1166 | wpabuf_len(buf)); |
| 1167 | reply[res++] = '\n'; |
| 1168 | reply[res] = '\0'; |
| 1169 | |
| 1170 | wpabuf_free(buf); |
| 1171 | |
| 1172 | return res; |
| 1173 | } |
| 1174 | |
| 1175 | |
| 1176 | static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read( |
| 1177 | struct wpa_supplicant *wpa_s, char *pos) |
| 1178 | { |
| 1179 | size_t len; |
| 1180 | struct wpabuf *buf; |
| 1181 | int ret; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1182 | char *freq; |
| 1183 | int forced_freq = 0; |
| 1184 | |
| 1185 | freq = strstr(pos, " freq="); |
| 1186 | if (freq) { |
| 1187 | *freq = '\0'; |
| 1188 | freq += 6; |
| 1189 | forced_freq = atoi(freq); |
| 1190 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1191 | |
| 1192 | len = os_strlen(pos); |
| 1193 | if (len & 0x01) |
| 1194 | return -1; |
| 1195 | len /= 2; |
| 1196 | |
| 1197 | buf = wpabuf_alloc(len); |
| 1198 | if (buf == NULL) |
| 1199 | return -1; |
| 1200 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { |
| 1201 | wpabuf_free(buf); |
| 1202 | return -1; |
| 1203 | } |
| 1204 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1205 | ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1206 | wpabuf_free(buf); |
| 1207 | |
| 1208 | return ret; |
| 1209 | } |
| 1210 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1211 | |
| 1212 | 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] | 1213 | char *reply, size_t max_len, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1214 | int ndef) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1215 | { |
| 1216 | struct wpabuf *buf; |
| 1217 | int res; |
| 1218 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1219 | buf = wpas_wps_nfc_handover_req(wpa_s, ndef); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1220 | if (buf == NULL) |
| 1221 | return -1; |
| 1222 | |
| 1223 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1224 | wpabuf_len(buf)); |
| 1225 | reply[res++] = '\n'; |
| 1226 | reply[res] = '\0'; |
| 1227 | |
| 1228 | wpabuf_free(buf); |
| 1229 | |
| 1230 | return res; |
| 1231 | } |
| 1232 | |
| 1233 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1234 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1235 | static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s, |
| 1236 | char *reply, size_t max_len, |
| 1237 | int ndef) |
| 1238 | { |
| 1239 | struct wpabuf *buf; |
| 1240 | int res; |
| 1241 | |
| 1242 | buf = wpas_p2p_nfc_handover_req(wpa_s, ndef); |
| 1243 | if (buf == NULL) { |
| 1244 | wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request"); |
| 1245 | return -1; |
| 1246 | } |
| 1247 | |
| 1248 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1249 | wpabuf_len(buf)); |
| 1250 | reply[res++] = '\n'; |
| 1251 | reply[res] = '\0'; |
| 1252 | |
| 1253 | wpabuf_free(buf); |
| 1254 | |
| 1255 | return res; |
| 1256 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1257 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1258 | |
| 1259 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1260 | static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s, |
| 1261 | char *cmd, char *reply, |
| 1262 | size_t max_len) |
| 1263 | { |
| 1264 | char *pos; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1265 | int ndef; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1266 | |
| 1267 | pos = os_strchr(cmd, ' '); |
| 1268 | if (pos == NULL) |
| 1269 | return -1; |
| 1270 | *pos++ = '\0'; |
| 1271 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1272 | if (os_strcmp(cmd, "WPS") == 0) |
| 1273 | ndef = 0; |
| 1274 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1275 | ndef = 1; |
| 1276 | else |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1277 | return -1; |
| 1278 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1279 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1280 | if (!ndef) |
| 1281 | return -1; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1282 | return wpas_ctrl_nfc_get_handover_req_wps( |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1283 | wpa_s, reply, max_len, ndef); |
| 1284 | } |
| 1285 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1286 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1287 | if (os_strcmp(pos, "P2P-CR") == 0) { |
| 1288 | return wpas_ctrl_nfc_get_handover_req_p2p( |
| 1289 | wpa_s, reply, max_len, ndef); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1290 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1291 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1292 | |
| 1293 | return -1; |
| 1294 | } |
| 1295 | |
| 1296 | |
| 1297 | 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] | 1298 | char *reply, size_t max_len, |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1299 | int ndef, int cr, char *uuid) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1300 | { |
| 1301 | struct wpabuf *buf; |
| 1302 | int res; |
| 1303 | |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1304 | buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1305 | if (buf == NULL) |
| 1306 | return -1; |
| 1307 | |
| 1308 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1309 | wpabuf_len(buf)); |
| 1310 | reply[res++] = '\n'; |
| 1311 | reply[res] = '\0'; |
| 1312 | |
| 1313 | wpabuf_free(buf); |
| 1314 | |
| 1315 | return res; |
| 1316 | } |
| 1317 | |
| 1318 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1319 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1320 | static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s, |
| 1321 | char *reply, size_t max_len, |
| 1322 | int ndef, int tag) |
| 1323 | { |
| 1324 | struct wpabuf *buf; |
| 1325 | int res; |
| 1326 | |
| 1327 | buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag); |
| 1328 | if (buf == NULL) |
| 1329 | return -1; |
| 1330 | |
| 1331 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1332 | wpabuf_len(buf)); |
| 1333 | reply[res++] = '\n'; |
| 1334 | reply[res] = '\0'; |
| 1335 | |
| 1336 | wpabuf_free(buf); |
| 1337 | |
| 1338 | return res; |
| 1339 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1340 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1341 | |
| 1342 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1343 | static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s, |
| 1344 | char *cmd, char *reply, |
| 1345 | size_t max_len) |
| 1346 | { |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1347 | char *pos, *pos2; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1348 | int ndef; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1349 | |
| 1350 | pos = os_strchr(cmd, ' '); |
| 1351 | if (pos == NULL) |
| 1352 | return -1; |
| 1353 | *pos++ = '\0'; |
| 1354 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1355 | if (os_strcmp(cmd, "WPS") == 0) |
| 1356 | ndef = 0; |
| 1357 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1358 | ndef = 1; |
| 1359 | else |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1360 | return -1; |
| 1361 | |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1362 | pos2 = os_strchr(pos, ' '); |
| 1363 | if (pos2) |
| 1364 | *pos2++ = '\0'; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1365 | if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1366 | if (!ndef) |
| 1367 | return -1; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1368 | return wpas_ctrl_nfc_get_handover_sel_wps( |
| 1369 | wpa_s, reply, max_len, ndef, |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 1370 | os_strcmp(pos, "WPS-CR") == 0, pos2); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1371 | } |
| 1372 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1373 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1374 | if (os_strcmp(pos, "P2P-CR") == 0) { |
| 1375 | return wpas_ctrl_nfc_get_handover_sel_p2p( |
| 1376 | wpa_s, reply, max_len, ndef, 0); |
| 1377 | } |
| 1378 | |
| 1379 | if (os_strcmp(pos, "P2P-CR-TAG") == 0) { |
| 1380 | return wpas_ctrl_nfc_get_handover_sel_p2p( |
| 1381 | wpa_s, reply, max_len, ndef, 1); |
| 1382 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1383 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1384 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1385 | return -1; |
| 1386 | } |
| 1387 | |
| 1388 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1389 | static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s, |
| 1390 | char *cmd) |
| 1391 | { |
| 1392 | size_t len; |
| 1393 | struct wpabuf *req, *sel; |
| 1394 | int ret; |
| 1395 | char *pos, *role, *type, *pos2; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1396 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1397 | char *freq; |
| 1398 | int forced_freq = 0; |
| 1399 | |
| 1400 | freq = strstr(cmd, " freq="); |
| 1401 | if (freq) { |
| 1402 | *freq = '\0'; |
| 1403 | freq += 6; |
| 1404 | forced_freq = atoi(freq); |
| 1405 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1406 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1407 | |
| 1408 | role = cmd; |
| 1409 | pos = os_strchr(role, ' '); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1410 | if (pos == NULL) { |
| 1411 | wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1412 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1413 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1414 | *pos++ = '\0'; |
| 1415 | |
| 1416 | type = pos; |
| 1417 | pos = os_strchr(type, ' '); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1418 | if (pos == NULL) { |
| 1419 | wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1420 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1421 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1422 | *pos++ = '\0'; |
| 1423 | |
| 1424 | pos2 = os_strchr(pos, ' '); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1425 | if (pos2 == NULL) { |
| 1426 | wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1427 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1428 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1429 | *pos2++ = '\0'; |
| 1430 | |
| 1431 | len = os_strlen(pos); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1432 | if (len & 0x01) { |
| 1433 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1434 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1435 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1436 | len /= 2; |
| 1437 | |
| 1438 | req = wpabuf_alloc(len); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1439 | if (req == NULL) { |
| 1440 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1441 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1442 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1443 | if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1444 | wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1445 | wpabuf_free(req); |
| 1446 | return -1; |
| 1447 | } |
| 1448 | |
| 1449 | len = os_strlen(pos2); |
| 1450 | if (len & 0x01) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1451 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1452 | wpabuf_free(req); |
| 1453 | return -1; |
| 1454 | } |
| 1455 | len /= 2; |
| 1456 | |
| 1457 | sel = wpabuf_alloc(len); |
| 1458 | if (sel == NULL) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1459 | wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1460 | wpabuf_free(req); |
| 1461 | return -1; |
| 1462 | } |
| 1463 | if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1464 | wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1465 | wpabuf_free(req); |
| 1466 | wpabuf_free(sel); |
| 1467 | return -1; |
| 1468 | } |
| 1469 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1470 | wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d", |
| 1471 | role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel)); |
| 1472 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1473 | if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) { |
| 1474 | ret = wpas_wps_nfc_report_handover(wpa_s, req, sel); |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1475 | #ifdef CONFIG_AP |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1476 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) |
| 1477 | { |
| 1478 | ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel); |
| 1479 | if (ret < 0) |
| 1480 | ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel); |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1481 | #endif /* CONFIG_AP */ |
| 1482 | #ifdef CONFIG_P2P |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1483 | } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0) |
| 1484 | { |
| 1485 | ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0); |
| 1486 | } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0) |
| 1487 | { |
| 1488 | ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel, |
| 1489 | forced_freq); |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1490 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1491 | } else { |
| 1492 | wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover " |
| 1493 | "reported: role=%s type=%s", role, type); |
| 1494 | ret = -1; |
| 1495 | } |
| 1496 | wpabuf_free(req); |
| 1497 | wpabuf_free(sel); |
| 1498 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1499 | if (ret) |
| 1500 | wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages"); |
| 1501 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1502 | return ret; |
| 1503 | } |
| 1504 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1505 | #endif /* CONFIG_WPS_NFC */ |
| 1506 | |
| 1507 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1508 | static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s, |
| 1509 | char *cmd) |
| 1510 | { |
| 1511 | u8 bssid[ETH_ALEN]; |
| 1512 | char *pin; |
| 1513 | char *new_ssid; |
| 1514 | char *new_auth; |
| 1515 | char *new_encr; |
| 1516 | char *new_key; |
| 1517 | struct wps_new_ap_settings ap; |
| 1518 | |
| 1519 | pin = os_strchr(cmd, ' '); |
| 1520 | if (pin == NULL) |
| 1521 | return -1; |
| 1522 | *pin++ = '\0'; |
| 1523 | |
| 1524 | if (hwaddr_aton(cmd, bssid)) { |
| 1525 | wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'", |
| 1526 | cmd); |
| 1527 | return -1; |
| 1528 | } |
| 1529 | |
| 1530 | new_ssid = os_strchr(pin, ' '); |
| 1531 | if (new_ssid == NULL) |
| 1532 | return wpas_wps_start_reg(wpa_s, bssid, pin, NULL); |
| 1533 | *new_ssid++ = '\0'; |
| 1534 | |
| 1535 | new_auth = os_strchr(new_ssid, ' '); |
| 1536 | if (new_auth == NULL) |
| 1537 | return -1; |
| 1538 | *new_auth++ = '\0'; |
| 1539 | |
| 1540 | new_encr = os_strchr(new_auth, ' '); |
| 1541 | if (new_encr == NULL) |
| 1542 | return -1; |
| 1543 | *new_encr++ = '\0'; |
| 1544 | |
| 1545 | new_key = os_strchr(new_encr, ' '); |
| 1546 | if (new_key == NULL) |
| 1547 | return -1; |
| 1548 | *new_key++ = '\0'; |
| 1549 | |
| 1550 | os_memset(&ap, 0, sizeof(ap)); |
| 1551 | ap.ssid_hex = new_ssid; |
| 1552 | ap.auth = new_auth; |
| 1553 | ap.encr = new_encr; |
| 1554 | ap.key_hex = new_key; |
| 1555 | return wpas_wps_start_reg(wpa_s, bssid, pin, &ap); |
| 1556 | } |
| 1557 | |
| 1558 | |
| 1559 | #ifdef CONFIG_AP |
| 1560 | static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s, |
| 1561 | char *cmd, char *buf, |
| 1562 | size_t buflen) |
| 1563 | { |
| 1564 | int timeout = 300; |
| 1565 | char *pos; |
| 1566 | const char *pin_txt; |
| 1567 | |
| 1568 | if (!wpa_s->ap_iface) |
| 1569 | return -1; |
| 1570 | |
| 1571 | pos = os_strchr(cmd, ' '); |
| 1572 | if (pos) |
| 1573 | *pos++ = '\0'; |
| 1574 | |
| 1575 | if (os_strcmp(cmd, "disable") == 0) { |
| 1576 | wpas_wps_ap_pin_disable(wpa_s); |
| 1577 | return os_snprintf(buf, buflen, "OK\n"); |
| 1578 | } |
| 1579 | |
| 1580 | if (os_strcmp(cmd, "random") == 0) { |
| 1581 | if (pos) |
| 1582 | timeout = atoi(pos); |
| 1583 | pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout); |
| 1584 | if (pin_txt == NULL) |
| 1585 | return -1; |
| 1586 | return os_snprintf(buf, buflen, "%s", pin_txt); |
| 1587 | } |
| 1588 | |
| 1589 | if (os_strcmp(cmd, "get") == 0) { |
| 1590 | pin_txt = wpas_wps_ap_pin_get(wpa_s); |
| 1591 | if (pin_txt == NULL) |
| 1592 | return -1; |
| 1593 | return os_snprintf(buf, buflen, "%s", pin_txt); |
| 1594 | } |
| 1595 | |
| 1596 | if (os_strcmp(cmd, "set") == 0) { |
| 1597 | char *pin; |
| 1598 | if (pos == NULL) |
| 1599 | return -1; |
| 1600 | pin = pos; |
| 1601 | pos = os_strchr(pos, ' '); |
| 1602 | if (pos) { |
| 1603 | *pos++ = '\0'; |
| 1604 | timeout = atoi(pos); |
| 1605 | } |
| 1606 | if (os_strlen(pin) > buflen) |
| 1607 | return -1; |
| 1608 | if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0) |
| 1609 | return -1; |
| 1610 | return os_snprintf(buf, buflen, "%s", pin); |
| 1611 | } |
| 1612 | |
| 1613 | return -1; |
| 1614 | } |
| 1615 | #endif /* CONFIG_AP */ |
| 1616 | |
| 1617 | |
| 1618 | #ifdef CONFIG_WPS_ER |
| 1619 | static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s, |
| 1620 | char *cmd) |
| 1621 | { |
| 1622 | char *uuid = cmd, *pin, *pos; |
| 1623 | u8 addr_buf[ETH_ALEN], *addr = NULL; |
| 1624 | pin = os_strchr(uuid, ' '); |
| 1625 | if (pin == NULL) |
| 1626 | return -1; |
| 1627 | *pin++ = '\0'; |
| 1628 | pos = os_strchr(pin, ' '); |
| 1629 | if (pos) { |
| 1630 | *pos++ = '\0'; |
| 1631 | if (hwaddr_aton(pos, addr_buf) == 0) |
| 1632 | addr = addr_buf; |
| 1633 | } |
| 1634 | return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin); |
| 1635 | } |
| 1636 | |
| 1637 | |
| 1638 | static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s, |
| 1639 | char *cmd) |
| 1640 | { |
| 1641 | char *uuid = cmd, *pin; |
| 1642 | pin = os_strchr(uuid, ' '); |
| 1643 | if (pin == NULL) |
| 1644 | return -1; |
| 1645 | *pin++ = '\0'; |
| 1646 | return wpas_wps_er_learn(wpa_s, uuid, pin); |
| 1647 | } |
| 1648 | |
| 1649 | |
| 1650 | static int wpa_supplicant_ctrl_iface_wps_er_set_config( |
| 1651 | struct wpa_supplicant *wpa_s, char *cmd) |
| 1652 | { |
| 1653 | char *uuid = cmd, *id; |
| 1654 | id = os_strchr(uuid, ' '); |
| 1655 | if (id == NULL) |
| 1656 | return -1; |
| 1657 | *id++ = '\0'; |
| 1658 | return wpas_wps_er_set_config(wpa_s, uuid, atoi(id)); |
| 1659 | } |
| 1660 | |
| 1661 | |
| 1662 | static int wpa_supplicant_ctrl_iface_wps_er_config( |
| 1663 | struct wpa_supplicant *wpa_s, char *cmd) |
| 1664 | { |
| 1665 | char *pin; |
| 1666 | char *new_ssid; |
| 1667 | char *new_auth; |
| 1668 | char *new_encr; |
| 1669 | char *new_key; |
| 1670 | struct wps_new_ap_settings ap; |
| 1671 | |
| 1672 | pin = os_strchr(cmd, ' '); |
| 1673 | if (pin == NULL) |
| 1674 | return -1; |
| 1675 | *pin++ = '\0'; |
| 1676 | |
| 1677 | new_ssid = os_strchr(pin, ' '); |
| 1678 | if (new_ssid == NULL) |
| 1679 | return -1; |
| 1680 | *new_ssid++ = '\0'; |
| 1681 | |
| 1682 | new_auth = os_strchr(new_ssid, ' '); |
| 1683 | if (new_auth == NULL) |
| 1684 | return -1; |
| 1685 | *new_auth++ = '\0'; |
| 1686 | |
| 1687 | new_encr = os_strchr(new_auth, ' '); |
| 1688 | if (new_encr == NULL) |
| 1689 | return -1; |
| 1690 | *new_encr++ = '\0'; |
| 1691 | |
| 1692 | new_key = os_strchr(new_encr, ' '); |
| 1693 | if (new_key == NULL) |
| 1694 | return -1; |
| 1695 | *new_key++ = '\0'; |
| 1696 | |
| 1697 | os_memset(&ap, 0, sizeof(ap)); |
| 1698 | ap.ssid_hex = new_ssid; |
| 1699 | ap.auth = new_auth; |
| 1700 | ap.encr = new_encr; |
| 1701 | ap.key_hex = new_key; |
| 1702 | return wpas_wps_er_config(wpa_s, cmd, pin, &ap); |
| 1703 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1704 | |
| 1705 | |
| 1706 | #ifdef CONFIG_WPS_NFC |
| 1707 | static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( |
| 1708 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| 1709 | { |
| 1710 | int ndef; |
| 1711 | struct wpabuf *buf; |
| 1712 | int res; |
| 1713 | char *uuid; |
| 1714 | |
| 1715 | uuid = os_strchr(cmd, ' '); |
| 1716 | if (uuid == NULL) |
| 1717 | return -1; |
| 1718 | *uuid++ = '\0'; |
| 1719 | |
| 1720 | if (os_strcmp(cmd, "WPS") == 0) |
| 1721 | ndef = 0; |
| 1722 | else if (os_strcmp(cmd, "NDEF") == 0) |
| 1723 | ndef = 1; |
| 1724 | else |
| 1725 | return -1; |
| 1726 | |
| 1727 | buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid); |
| 1728 | if (buf == NULL) |
| 1729 | return -1; |
| 1730 | |
| 1731 | res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| 1732 | wpabuf_len(buf)); |
| 1733 | reply[res++] = '\n'; |
| 1734 | reply[res] = '\0'; |
| 1735 | |
| 1736 | wpabuf_free(buf); |
| 1737 | |
| 1738 | return res; |
| 1739 | } |
| 1740 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1741 | #endif /* CONFIG_WPS_ER */ |
| 1742 | |
| 1743 | #endif /* CONFIG_WPS */ |
| 1744 | |
| 1745 | |
| 1746 | #ifdef CONFIG_IBSS_RSN |
| 1747 | static int wpa_supplicant_ctrl_iface_ibss_rsn( |
| 1748 | struct wpa_supplicant *wpa_s, char *addr) |
| 1749 | { |
| 1750 | u8 peer[ETH_ALEN]; |
| 1751 | |
| 1752 | if (hwaddr_aton(addr, peer)) { |
| 1753 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid " |
| 1754 | "address '%s'", addr); |
| 1755 | return -1; |
| 1756 | } |
| 1757 | |
| 1758 | wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR, |
| 1759 | MAC2STR(peer)); |
| 1760 | |
| 1761 | return ibss_rsn_start(wpa_s->ibss_rsn, peer); |
| 1762 | } |
| 1763 | #endif /* CONFIG_IBSS_RSN */ |
| 1764 | |
| 1765 | |
| 1766 | static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, |
| 1767 | char *rsp) |
| 1768 | { |
| 1769 | #ifdef IEEE8021X_EAPOL |
| 1770 | char *pos, *id_pos; |
| 1771 | int id; |
| 1772 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1773 | |
| 1774 | pos = os_strchr(rsp, '-'); |
| 1775 | if (pos == NULL) |
| 1776 | return -1; |
| 1777 | *pos++ = '\0'; |
| 1778 | id_pos = pos; |
| 1779 | pos = os_strchr(pos, ':'); |
| 1780 | if (pos == NULL) |
| 1781 | return -1; |
| 1782 | *pos++ = '\0'; |
| 1783 | id = atoi(id_pos); |
| 1784 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); |
| 1785 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", |
| 1786 | (u8 *) pos, os_strlen(pos)); |
| 1787 | |
| 1788 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 1789 | if (ssid == NULL) { |
| 1790 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 1791 | "to update", id); |
| 1792 | return -1; |
| 1793 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1794 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1795 | return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp, |
| 1796 | pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1797 | #else /* IEEE8021X_EAPOL */ |
| 1798 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); |
| 1799 | return -1; |
| 1800 | #endif /* IEEE8021X_EAPOL */ |
| 1801 | } |
| 1802 | |
| 1803 | |
| 1804 | static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, |
| 1805 | const char *params, |
| 1806 | char *buf, size_t buflen) |
| 1807 | { |
| 1808 | char *pos, *end, tmp[30]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1809 | int res, verbose, wps, ret; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1810 | #ifdef CONFIG_HS20 |
| 1811 | const u8 *hs20; |
| 1812 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1813 | const u8 *sess_id; |
| 1814 | size_t sess_id_len; |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1815 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1816 | if (os_strcmp(params, "-DRIVER") == 0) |
| 1817 | return wpa_drv_status(wpa_s, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1818 | verbose = os_strcmp(params, "-VERBOSE") == 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1819 | wps = os_strcmp(params, "-WPS") == 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1820 | pos = buf; |
| 1821 | end = buf + buflen; |
| 1822 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { |
| 1823 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 1824 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", |
| 1825 | MAC2STR(wpa_s->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1826 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1827 | return pos - buf; |
| 1828 | pos += ret; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1829 | ret = os_snprintf(pos, end - pos, "freq=%u\n", |
| 1830 | wpa_s->assoc_freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1831 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1832 | return pos - buf; |
| 1833 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1834 | if (ssid) { |
| 1835 | u8 *_ssid = ssid->ssid; |
| 1836 | size_t ssid_len = ssid->ssid_len; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1837 | u8 ssid_buf[SSID_MAX_LEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1838 | if (ssid_len == 0) { |
| 1839 | int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); |
| 1840 | if (_res < 0) |
| 1841 | ssid_len = 0; |
| 1842 | else |
| 1843 | ssid_len = _res; |
| 1844 | _ssid = ssid_buf; |
| 1845 | } |
| 1846 | ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", |
| 1847 | wpa_ssid_txt(_ssid, ssid_len), |
| 1848 | ssid->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1849 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1850 | return pos - buf; |
| 1851 | pos += ret; |
| 1852 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1853 | if (wps && ssid->passphrase && |
| 1854 | wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && |
| 1855 | (ssid->mode == WPAS_MODE_AP || |
| 1856 | ssid->mode == WPAS_MODE_P2P_GO)) { |
| 1857 | ret = os_snprintf(pos, end - pos, |
| 1858 | "passphrase=%s\n", |
| 1859 | ssid->passphrase); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1860 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1861 | return pos - buf; |
| 1862 | pos += ret; |
| 1863 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1864 | if (ssid->id_str) { |
| 1865 | ret = os_snprintf(pos, end - pos, |
| 1866 | "id_str=%s\n", |
| 1867 | ssid->id_str); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1868 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1869 | return pos - buf; |
| 1870 | pos += ret; |
| 1871 | } |
| 1872 | |
| 1873 | switch (ssid->mode) { |
| 1874 | case WPAS_MODE_INFRA: |
| 1875 | ret = os_snprintf(pos, end - pos, |
| 1876 | "mode=station\n"); |
| 1877 | break; |
| 1878 | case WPAS_MODE_IBSS: |
| 1879 | ret = os_snprintf(pos, end - pos, |
| 1880 | "mode=IBSS\n"); |
| 1881 | break; |
| 1882 | case WPAS_MODE_AP: |
| 1883 | ret = os_snprintf(pos, end - pos, |
| 1884 | "mode=AP\n"); |
| 1885 | break; |
| 1886 | case WPAS_MODE_P2P_GO: |
| 1887 | ret = os_snprintf(pos, end - pos, |
| 1888 | "mode=P2P GO\n"); |
| 1889 | break; |
| 1890 | case WPAS_MODE_P2P_GROUP_FORMATION: |
| 1891 | ret = os_snprintf(pos, end - pos, |
| 1892 | "mode=P2P GO - group " |
| 1893 | "formation\n"); |
| 1894 | break; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame^] | 1895 | case WPAS_MODE_MESH: |
| 1896 | ret = os_snprintf(pos, end - pos, |
| 1897 | "mode=mesh\n"); |
| 1898 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1899 | default: |
| 1900 | ret = 0; |
| 1901 | break; |
| 1902 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1903 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1904 | return pos - buf; |
| 1905 | pos += ret; |
| 1906 | } |
| 1907 | |
| 1908 | #ifdef CONFIG_AP |
| 1909 | if (wpa_s->ap_iface) { |
| 1910 | pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos, |
| 1911 | end - pos, |
| 1912 | verbose); |
| 1913 | } else |
| 1914 | #endif /* CONFIG_AP */ |
| 1915 | pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); |
| 1916 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1917 | #ifdef CONFIG_SAE |
| 1918 | if (wpa_s->wpa_state >= WPA_ASSOCIATED && |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1919 | #ifdef CONFIG_AP |
| 1920 | !wpa_s->ap_iface && |
| 1921 | #endif /* CONFIG_AP */ |
| 1922 | wpa_s->sme.sae.state == SAE_ACCEPTED) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1923 | ret = os_snprintf(pos, end - pos, "sae_group=%d\n", |
| 1924 | wpa_s->sme.sae.group); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1925 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1926 | return pos - buf; |
| 1927 | pos += ret; |
| 1928 | } |
| 1929 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1930 | ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", |
| 1931 | wpa_supplicant_state_txt(wpa_s->wpa_state)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1932 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1933 | return pos - buf; |
| 1934 | pos += ret; |
| 1935 | |
| 1936 | if (wpa_s->l2 && |
| 1937 | l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { |
| 1938 | ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1939 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1940 | return pos - buf; |
| 1941 | pos += ret; |
| 1942 | } |
| 1943 | |
| 1944 | #ifdef CONFIG_P2P |
| 1945 | if (wpa_s->global->p2p) { |
| 1946 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR |
| 1947 | "\n", MAC2STR(wpa_s->global->p2p_dev_addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1948 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1949 | return pos - buf; |
| 1950 | pos += ret; |
| 1951 | } |
| 1952 | #endif /* CONFIG_P2P */ |
| 1953 | |
| 1954 | ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n", |
| 1955 | MAC2STR(wpa_s->own_addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1956 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1957 | return pos - buf; |
| 1958 | pos += ret; |
| 1959 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1960 | #ifdef CONFIG_HS20 |
| 1961 | if (wpa_s->current_bss && |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1962 | (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss, |
| 1963 | HS20_IE_VENDOR_TYPE)) && |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1964 | wpa_s->wpa_proto == WPA_PROTO_RSN && |
| 1965 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1966 | int release = 1; |
| 1967 | if (hs20[1] >= 5) { |
| 1968 | u8 rel_num = (hs20[6] & 0xf0) >> 4; |
| 1969 | release = rel_num + 1; |
| 1970 | } |
| 1971 | ret = os_snprintf(pos, end - pos, "hs20=%d\n", release); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1972 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1973 | return pos - buf; |
| 1974 | pos += ret; |
| 1975 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1976 | |
| 1977 | if (wpa_s->current_ssid) { |
| 1978 | struct wpa_cred *cred; |
| 1979 | char *type; |
| 1980 | |
| 1981 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1982 | size_t i; |
| 1983 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1984 | if (wpa_s->current_ssid->parent_cred != cred) |
| 1985 | continue; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1986 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1987 | if (cred->provisioning_sp) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1988 | ret = os_snprintf(pos, end - pos, |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1989 | "provisioning_sp=%s\n", |
| 1990 | cred->provisioning_sp); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1991 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1992 | return pos - buf; |
| 1993 | pos += ret; |
| 1994 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1995 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1996 | if (!cred->domain) |
| 1997 | goto no_domain; |
| 1998 | |
| 1999 | i = 0; |
| 2000 | if (wpa_s->current_bss && wpa_s->current_bss->anqp) { |
| 2001 | struct wpabuf *names = |
| 2002 | wpa_s->current_bss->anqp->domain_name; |
| 2003 | for (i = 0; names && i < cred->num_domain; i++) |
| 2004 | { |
| 2005 | if (domain_name_list_contains( |
| 2006 | names, cred->domain[i], 1)) |
| 2007 | break; |
| 2008 | } |
| 2009 | if (i == cred->num_domain) |
| 2010 | i = 0; /* show first entry by default */ |
| 2011 | } |
| 2012 | ret = os_snprintf(pos, end - pos, "home_sp=%s\n", |
| 2013 | cred->domain[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2014 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2015 | return pos - buf; |
| 2016 | pos += ret; |
| 2017 | |
| 2018 | no_domain: |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2019 | if (wpa_s->current_bss == NULL || |
| 2020 | wpa_s->current_bss->anqp == NULL) |
| 2021 | res = -1; |
| 2022 | else |
| 2023 | res = interworking_home_sp_cred( |
| 2024 | wpa_s, cred, |
| 2025 | wpa_s->current_bss->anqp->domain_name); |
| 2026 | if (res > 0) |
| 2027 | type = "home"; |
| 2028 | else if (res == 0) |
| 2029 | type = "roaming"; |
| 2030 | else |
| 2031 | type = "unknown"; |
| 2032 | |
| 2033 | ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2034 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2035 | return pos - buf; |
| 2036 | pos += ret; |
| 2037 | |
| 2038 | break; |
| 2039 | } |
| 2040 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2041 | #endif /* CONFIG_HS20 */ |
| 2042 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2043 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
| 2044 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
| 2045 | res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, |
| 2046 | verbose); |
| 2047 | if (res >= 0) |
| 2048 | pos += res; |
| 2049 | } |
| 2050 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2051 | sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len); |
| 2052 | if (sess_id) { |
| 2053 | char *start = pos; |
| 2054 | |
| 2055 | ret = os_snprintf(pos, end - pos, "eap_session_id="); |
| 2056 | if (os_snprintf_error(end - pos, ret)) |
| 2057 | return start - buf; |
| 2058 | pos += ret; |
| 2059 | ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len); |
| 2060 | if (ret <= 0) |
| 2061 | return start - buf; |
| 2062 | pos += ret; |
| 2063 | ret = os_snprintf(pos, end - pos, "\n"); |
| 2064 | if (os_snprintf_error(end - pos, ret)) |
| 2065 | return start - buf; |
| 2066 | pos += ret; |
| 2067 | } |
| 2068 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2069 | res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); |
| 2070 | if (res >= 0) |
| 2071 | pos += res; |
| 2072 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2073 | #ifdef CONFIG_WPS |
| 2074 | { |
| 2075 | char uuid_str[100]; |
| 2076 | uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str)); |
| 2077 | ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2078 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2079 | return pos - buf; |
| 2080 | pos += ret; |
| 2081 | } |
| 2082 | #endif /* CONFIG_WPS */ |
| 2083 | |
Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 2084 | #ifdef ANDROID |
vandwalle | ffc7018 | 2014-09-11 11:40:14 -0700 | [diff] [blame] | 2085 | /* |
| 2086 | * Allow using the STATUS command with default behavior, say for debug, |
| 2087 | * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE |
| 2088 | * events with STATUS-NO_EVENTS. |
| 2089 | */ |
| 2090 | if (os_strcmp(params, "-NO_EVENTS")) { |
| 2091 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE |
| 2092 | "id=%d state=%d BSSID=" MACSTR " SSID=%s", |
| 2093 | wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, |
| 2094 | wpa_s->wpa_state, |
| 2095 | MAC2STR(wpa_s->bssid), |
| 2096 | wpa_s->current_ssid && wpa_s->current_ssid->ssid ? |
| 2097 | wpa_ssid_txt(wpa_s->current_ssid->ssid, |
| 2098 | wpa_s->current_ssid->ssid_len) : ""); |
| 2099 | if (wpa_s->wpa_state == WPA_COMPLETED) { |
| 2100 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 2101 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED |
| 2102 | "- connection to " MACSTR |
| 2103 | " completed %s [id=%d id_str=%s]", |
| 2104 | MAC2STR(wpa_s->bssid), "(auth)", |
| 2105 | ssid ? ssid->id : -1, |
| 2106 | ssid && ssid->id_str ? ssid->id_str : ""); |
| 2107 | } |
Irfan Sheriff | bf5edf4 | 2012-01-11 16:54:57 -0800 | [diff] [blame] | 2108 | } |
Dmitry Shmidt | 2fd7fa6 | 2011-12-19 11:19:09 -0800 | [diff] [blame] | 2109 | #endif /* ANDROID */ |
| 2110 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2111 | return pos - buf; |
| 2112 | } |
| 2113 | |
| 2114 | |
| 2115 | static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, |
| 2116 | char *cmd) |
| 2117 | { |
| 2118 | char *pos; |
| 2119 | int id; |
| 2120 | struct wpa_ssid *ssid; |
| 2121 | u8 bssid[ETH_ALEN]; |
| 2122 | |
| 2123 | /* cmd: "<network id> <BSSID>" */ |
| 2124 | pos = os_strchr(cmd, ' '); |
| 2125 | if (pos == NULL) |
| 2126 | return -1; |
| 2127 | *pos++ = '\0'; |
| 2128 | id = atoi(cmd); |
| 2129 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); |
| 2130 | if (hwaddr_aton(pos, bssid)) { |
| 2131 | wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); |
| 2132 | return -1; |
| 2133 | } |
| 2134 | |
| 2135 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 2136 | if (ssid == NULL) { |
| 2137 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 2138 | "to update", id); |
| 2139 | return -1; |
| 2140 | } |
| 2141 | |
| 2142 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); |
| 2143 | ssid->bssid_set = !is_zero_ether_addr(bssid); |
| 2144 | |
| 2145 | return 0; |
| 2146 | } |
| 2147 | |
| 2148 | |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2149 | static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2150 | char *cmd, char *buf, |
| 2151 | size_t buflen) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2152 | { |
| 2153 | u8 bssid[ETH_ALEN]; |
| 2154 | struct wpa_blacklist *e; |
| 2155 | char *pos, *end; |
| 2156 | int ret; |
| 2157 | |
| 2158 | /* cmd: "BLACKLIST [<BSSID>]" */ |
| 2159 | if (*cmd == '\0') { |
| 2160 | pos = buf; |
| 2161 | end = buf + buflen; |
| 2162 | e = wpa_s->blacklist; |
| 2163 | while (e) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2164 | ret = os_snprintf(pos, end - pos, MACSTR "\n", |
| 2165 | MAC2STR(e->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2166 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2167 | return pos - buf; |
| 2168 | pos += ret; |
| 2169 | e = e->next; |
| 2170 | } |
| 2171 | return pos - buf; |
| 2172 | } |
| 2173 | |
| 2174 | cmd++; |
| 2175 | if (os_strncmp(cmd, "clear", 5) == 0) { |
| 2176 | wpa_blacklist_clear(wpa_s); |
| 2177 | os_memcpy(buf, "OK\n", 3); |
| 2178 | return 3; |
| 2179 | } |
| 2180 | |
| 2181 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd); |
| 2182 | if (hwaddr_aton(cmd, bssid)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2183 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd); |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2184 | return -1; |
| 2185 | } |
| 2186 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2187 | /* |
| 2188 | * Add the BSSID twice, so its count will be 2, causing it to be |
| 2189 | * skipped when processing scan results. |
| 2190 | */ |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2191 | ret = wpa_blacklist_add(wpa_s, bssid); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2192 | if (ret < 0) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2193 | return -1; |
| 2194 | ret = wpa_blacklist_add(wpa_s, bssid); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2195 | if (ret < 0) |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 2196 | return -1; |
| 2197 | os_memcpy(buf, "OK\n", 3); |
| 2198 | return 3; |
| 2199 | } |
| 2200 | |
| 2201 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2202 | static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s, |
| 2203 | char *cmd, char *buf, |
| 2204 | size_t buflen) |
| 2205 | { |
| 2206 | char *pos, *end, *stamp; |
| 2207 | int ret; |
| 2208 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2209 | /* cmd: "LOG_LEVEL [<level>]" */ |
| 2210 | if (*cmd == '\0') { |
| 2211 | pos = buf; |
| 2212 | end = buf + buflen; |
| 2213 | ret = os_snprintf(pos, end - pos, "Current level: %s\n" |
| 2214 | "Timestamp: %d\n", |
| 2215 | debug_level_str(wpa_debug_level), |
| 2216 | wpa_debug_timestamp); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2217 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2218 | ret = 0; |
| 2219 | |
| 2220 | return ret; |
| 2221 | } |
| 2222 | |
| 2223 | while (*cmd == ' ') |
| 2224 | cmd++; |
| 2225 | |
| 2226 | stamp = os_strchr(cmd, ' '); |
| 2227 | if (stamp) { |
| 2228 | *stamp++ = '\0'; |
| 2229 | while (*stamp == ' ') { |
| 2230 | stamp++; |
| 2231 | } |
| 2232 | } |
| 2233 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2234 | if (os_strlen(cmd)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2235 | int level = str_to_debug_level(cmd); |
| 2236 | if (level < 0) |
| 2237 | return -1; |
| 2238 | wpa_debug_level = level; |
| 2239 | } |
| 2240 | |
| 2241 | if (stamp && os_strlen(stamp)) |
| 2242 | wpa_debug_timestamp = atoi(stamp); |
| 2243 | |
| 2244 | os_memcpy(buf, "OK\n", 3); |
| 2245 | return 3; |
| 2246 | } |
| 2247 | |
| 2248 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2249 | static int wpa_supplicant_ctrl_iface_list_networks( |
Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 2250 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2251 | { |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2252 | char *pos, *end, *prev; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2253 | struct wpa_ssid *ssid; |
| 2254 | int ret; |
| 2255 | |
| 2256 | pos = buf; |
| 2257 | end = buf + buflen; |
| 2258 | ret = os_snprintf(pos, end - pos, |
| 2259 | "network id / ssid / bssid / flags\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2260 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2261 | return pos - buf; |
| 2262 | pos += ret; |
| 2263 | |
| 2264 | ssid = wpa_s->conf->ssid; |
Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 2265 | |
| 2266 | /* skip over ssids until we find next one */ |
| 2267 | if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) { |
| 2268 | int last_id = atoi(cmd + 8); |
| 2269 | if (last_id != -1) { |
| 2270 | while (ssid != NULL && ssid->id <= last_id) { |
| 2271 | ssid = ssid->next; |
| 2272 | } |
| 2273 | } |
| 2274 | } |
| 2275 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2276 | while (ssid) { |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2277 | prev = pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2278 | ret = os_snprintf(pos, end - pos, "%d\t%s", |
| 2279 | ssid->id, |
| 2280 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2281 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2282 | return prev - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2283 | pos += ret; |
| 2284 | if (ssid->bssid_set) { |
| 2285 | ret = os_snprintf(pos, end - pos, "\t" MACSTR, |
| 2286 | MAC2STR(ssid->bssid)); |
| 2287 | } else { |
| 2288 | ret = os_snprintf(pos, end - pos, "\tany"); |
| 2289 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2290 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2291 | return prev - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2292 | pos += ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2293 | ret = os_snprintf(pos, end - pos, "\t%s%s%s%s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2294 | ssid == wpa_s->current_ssid ? |
| 2295 | "[CURRENT]" : "", |
| 2296 | ssid->disabled ? "[DISABLED]" : "", |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2297 | ssid->disabled_until.sec ? |
| 2298 | "[TEMP-DISABLED]" : "", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2299 | ssid->disabled == 2 ? "[P2P-PERSISTENT]" : |
| 2300 | ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2301 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2302 | return prev - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2303 | pos += ret; |
| 2304 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2305 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 9e37fc2 | 2014-12-03 11:48:46 -0800 | [diff] [blame] | 2306 | return prev - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2307 | pos += ret; |
| 2308 | |
| 2309 | ssid = ssid->next; |
| 2310 | } |
| 2311 | |
| 2312 | return pos - buf; |
| 2313 | } |
| 2314 | |
| 2315 | |
| 2316 | static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) |
| 2317 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2318 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2319 | ret = os_snprintf(pos, end - pos, "-"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2320 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2321 | return pos; |
| 2322 | pos += ret; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2323 | ret = wpa_write_ciphers(pos, end, cipher, "+"); |
| 2324 | if (ret < 0) |
| 2325 | return pos; |
| 2326 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2327 | return pos; |
| 2328 | } |
| 2329 | |
| 2330 | |
| 2331 | static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, |
| 2332 | const u8 *ie, size_t ie_len) |
| 2333 | { |
| 2334 | struct wpa_ie_data data; |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2335 | char *start; |
| 2336 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2337 | |
| 2338 | ret = os_snprintf(pos, end - pos, "[%s-", proto); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2339 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2340 | return pos; |
| 2341 | pos += ret; |
| 2342 | |
| 2343 | if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { |
| 2344 | ret = os_snprintf(pos, end - pos, "?]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2345 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2346 | return pos; |
| 2347 | pos += ret; |
| 2348 | return pos; |
| 2349 | } |
| 2350 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2351 | start = pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2352 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2353 | ret = os_snprintf(pos, end - pos, "%sEAP", |
| 2354 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2355 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2356 | return pos; |
| 2357 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2358 | } |
| 2359 | if (data.key_mgmt & WPA_KEY_MGMT_PSK) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2360 | ret = os_snprintf(pos, end - pos, "%sPSK", |
| 2361 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2362 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2363 | return pos; |
| 2364 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2365 | } |
| 2366 | if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2367 | ret = os_snprintf(pos, end - pos, "%sNone", |
| 2368 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2369 | if (os_snprintf_error(end - pos, ret)) |
| 2370 | return pos; |
| 2371 | pos += ret; |
| 2372 | } |
| 2373 | if (data.key_mgmt & WPA_KEY_MGMT_SAE) { |
| 2374 | ret = os_snprintf(pos, end - pos, "%sSAE", |
| 2375 | pos == start ? "" : "+"); |
| 2376 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2377 | return pos; |
| 2378 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2379 | } |
| 2380 | #ifdef CONFIG_IEEE80211R |
| 2381 | if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { |
| 2382 | ret = os_snprintf(pos, end - pos, "%sFT/EAP", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2383 | pos == start ? "" : "+"); |
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; |
| 2386 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2387 | } |
| 2388 | if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { |
| 2389 | ret = os_snprintf(pos, end - pos, "%sFT/PSK", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2390 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2391 | if (os_snprintf_error(end - pos, ret)) |
| 2392 | return pos; |
| 2393 | pos += ret; |
| 2394 | } |
| 2395 | if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) { |
| 2396 | ret = os_snprintf(pos, end - pos, "%sFT/SAE", |
| 2397 | pos == start ? "" : "+"); |
| 2398 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2399 | return pos; |
| 2400 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2401 | } |
| 2402 | #endif /* CONFIG_IEEE80211R */ |
| 2403 | #ifdef CONFIG_IEEE80211W |
| 2404 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { |
| 2405 | ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2406 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2407 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2408 | return pos; |
| 2409 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2410 | } |
| 2411 | if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { |
| 2412 | ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 2413 | pos == start ? "" : "+"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2414 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2415 | return pos; |
| 2416 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2417 | } |
| 2418 | #endif /* CONFIG_IEEE80211W */ |
| 2419 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2420 | #ifdef CONFIG_SUITEB |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2421 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
| 2422 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B", |
| 2423 | pos == start ? "" : "+"); |
| 2424 | if (os_snprintf_error(end - pos, ret)) |
| 2425 | return pos; |
| 2426 | pos += ret; |
| 2427 | } |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2428 | #endif /* CONFIG_SUITEB */ |
| 2429 | |
| 2430 | #ifdef CONFIG_SUITEB192 |
| 2431 | if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
| 2432 | ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192", |
| 2433 | pos == start ? "" : "+"); |
| 2434 | if (os_snprintf_error(end - pos, ret)) |
| 2435 | return pos; |
| 2436 | pos += ret; |
| 2437 | } |
| 2438 | #endif /* CONFIG_SUITEB192 */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2439 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2440 | if (data.key_mgmt & WPA_KEY_MGMT_OSEN) { |
| 2441 | ret = os_snprintf(pos, end - pos, "%sOSEN", |
| 2442 | pos == start ? "" : "+"); |
| 2443 | if (os_snprintf_error(end - pos, ret)) |
| 2444 | return pos; |
| 2445 | pos += ret; |
| 2446 | } |
| 2447 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2448 | pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); |
| 2449 | |
| 2450 | if (data.capabilities & WPA_CAPABILITY_PREAUTH) { |
| 2451 | ret = os_snprintf(pos, end - pos, "-preauth"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2452 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2453 | return pos; |
| 2454 | pos += ret; |
| 2455 | } |
| 2456 | |
| 2457 | ret = os_snprintf(pos, end - pos, "]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2458 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2459 | return pos; |
| 2460 | pos += ret; |
| 2461 | |
| 2462 | return pos; |
| 2463 | } |
| 2464 | |
| 2465 | |
| 2466 | #ifdef CONFIG_WPS |
| 2467 | static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, |
| 2468 | char *pos, char *end, |
| 2469 | struct wpabuf *wps_ie) |
| 2470 | { |
| 2471 | int ret; |
| 2472 | const char *txt; |
| 2473 | |
| 2474 | if (wps_ie == NULL) |
| 2475 | return pos; |
| 2476 | if (wps_is_selected_pbc_registrar(wps_ie)) |
| 2477 | txt = "[WPS-PBC]"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2478 | else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) |
| 2479 | txt = "[WPS-AUTH]"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2480 | else if (wps_is_selected_pin_registrar(wps_ie)) |
| 2481 | txt = "[WPS-PIN]"; |
| 2482 | else |
| 2483 | txt = "[WPS]"; |
| 2484 | |
| 2485 | ret = os_snprintf(pos, end - pos, "%s", txt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2486 | if (!os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2487 | pos += ret; |
| 2488 | wpabuf_free(wps_ie); |
| 2489 | return pos; |
| 2490 | } |
| 2491 | #endif /* CONFIG_WPS */ |
| 2492 | |
| 2493 | |
| 2494 | static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, |
| 2495 | char *pos, char *end, |
| 2496 | const struct wpa_bss *bss) |
| 2497 | { |
| 2498 | #ifdef CONFIG_WPS |
| 2499 | struct wpabuf *wps_ie; |
| 2500 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
| 2501 | return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); |
| 2502 | #else /* CONFIG_WPS */ |
| 2503 | return pos; |
| 2504 | #endif /* CONFIG_WPS */ |
| 2505 | } |
| 2506 | |
| 2507 | |
| 2508 | /* Format one result on one text line into a buffer. */ |
| 2509 | static int wpa_supplicant_ctrl_iface_scan_result( |
| 2510 | struct wpa_supplicant *wpa_s, |
| 2511 | const struct wpa_bss *bss, char *buf, size_t buflen) |
| 2512 | { |
| 2513 | char *pos, *end; |
| 2514 | int ret; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2515 | const u8 *ie, *ie2, *osen_ie, *p2p, *mesh; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2516 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2517 | mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2518 | p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2519 | if (!p2p) |
| 2520 | p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2521 | if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && |
| 2522 | os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == |
| 2523 | 0) |
| 2524 | return 0; /* Do not show P2P listen discovery results here */ |
| 2525 | |
| 2526 | pos = buf; |
| 2527 | end = buf + buflen; |
| 2528 | |
| 2529 | ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", |
| 2530 | MAC2STR(bss->bssid), bss->freq, bss->level); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2531 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2532 | return -1; |
| 2533 | pos += ret; |
| 2534 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 2535 | if (ie) |
| 2536 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); |
| 2537 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2538 | if (ie2) { |
| 2539 | pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2", |
| 2540 | ie2, 2 + ie2[1]); |
| 2541 | } |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2542 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
| 2543 | if (osen_ie) |
| 2544 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", |
| 2545 | osen_ie, 2 + osen_ie[1]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2546 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 2547 | if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2548 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2549 | if (os_snprintf_error(end - pos, ret)) |
| 2550 | return -1; |
| 2551 | pos += ret; |
| 2552 | } |
| 2553 | if (mesh) { |
| 2554 | ret = os_snprintf(pos, end - pos, "[MESH]"); |
| 2555 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2556 | return -1; |
| 2557 | pos += ret; |
| 2558 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 2559 | if (bss_is_dmg(bss)) { |
| 2560 | const char *s; |
| 2561 | ret = os_snprintf(pos, end - pos, "[DMG]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2562 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2563 | return -1; |
| 2564 | pos += ret; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 2565 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
| 2566 | case IEEE80211_CAP_DMG_IBSS: |
| 2567 | s = "[IBSS]"; |
| 2568 | break; |
| 2569 | case IEEE80211_CAP_DMG_AP: |
| 2570 | s = "[ESS]"; |
| 2571 | break; |
| 2572 | case IEEE80211_CAP_DMG_PBSS: |
| 2573 | s = "[PBSS]"; |
| 2574 | break; |
| 2575 | default: |
| 2576 | s = ""; |
| 2577 | break; |
| 2578 | } |
| 2579 | ret = os_snprintf(pos, end - pos, "%s", s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2580 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2581 | return -1; |
| 2582 | pos += ret; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 2583 | } else { |
| 2584 | if (bss->caps & IEEE80211_CAP_IBSS) { |
| 2585 | ret = os_snprintf(pos, end - pos, "[IBSS]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2586 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 2587 | return -1; |
| 2588 | pos += ret; |
| 2589 | } |
| 2590 | if (bss->caps & IEEE80211_CAP_ESS) { |
| 2591 | ret = os_snprintf(pos, end - pos, "[ESS]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2592 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 2593 | return -1; |
| 2594 | pos += ret; |
| 2595 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2596 | } |
| 2597 | if (p2p) { |
| 2598 | ret = os_snprintf(pos, end - pos, "[P2P]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2599 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2600 | return -1; |
| 2601 | pos += ret; |
| 2602 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2603 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2604 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2605 | ret = os_snprintf(pos, end - pos, "[HS20]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2606 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2607 | return -1; |
| 2608 | pos += ret; |
| 2609 | } |
| 2610 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2611 | #ifdef CONFIG_FST |
| 2612 | if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) { |
| 2613 | ret = os_snprintf(pos, end - pos, "[FST]"); |
| 2614 | if (os_snprintf_error(end - pos, ret)) |
| 2615 | return -1; |
| 2616 | pos += ret; |
| 2617 | } |
| 2618 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2619 | |
| 2620 | ret = os_snprintf(pos, end - pos, "\t%s", |
| 2621 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2622 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2623 | return -1; |
| 2624 | pos += ret; |
| 2625 | |
| 2626 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2627 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2628 | return -1; |
| 2629 | pos += ret; |
| 2630 | |
| 2631 | return pos - buf; |
| 2632 | } |
| 2633 | |
| 2634 | |
| 2635 | static int wpa_supplicant_ctrl_iface_scan_results( |
| 2636 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| 2637 | { |
| 2638 | char *pos, *end; |
| 2639 | struct wpa_bss *bss; |
| 2640 | int ret; |
| 2641 | |
| 2642 | pos = buf; |
| 2643 | end = buf + buflen; |
| 2644 | ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " |
| 2645 | "flags / ssid\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2646 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2647 | return pos - buf; |
| 2648 | pos += ret; |
| 2649 | |
| 2650 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
| 2651 | ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, |
| 2652 | end - pos); |
| 2653 | if (ret < 0 || ret >= end - pos) |
| 2654 | return pos - buf; |
| 2655 | pos += ret; |
| 2656 | } |
| 2657 | |
| 2658 | return pos - buf; |
| 2659 | } |
| 2660 | |
| 2661 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2662 | #ifdef CONFIG_MESH |
| 2663 | |
| 2664 | static int wpa_supplicant_ctrl_iface_mesh_interface_add( |
| 2665 | struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| 2666 | { |
| 2667 | char *pos, ifname[IFNAMSIZ + 1]; |
| 2668 | |
| 2669 | ifname[0] = '\0'; |
| 2670 | |
| 2671 | pos = os_strstr(cmd, "ifname="); |
| 2672 | if (pos) { |
| 2673 | pos += 7; |
| 2674 | os_strlcpy(ifname, pos, sizeof(ifname)); |
| 2675 | } |
| 2676 | |
| 2677 | if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0) |
| 2678 | return -1; |
| 2679 | |
| 2680 | os_strlcpy(reply, ifname, max_len); |
| 2681 | return os_strlen(ifname); |
| 2682 | } |
| 2683 | |
| 2684 | |
| 2685 | static int wpa_supplicant_ctrl_iface_mesh_group_add( |
| 2686 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2687 | { |
| 2688 | int id; |
| 2689 | struct wpa_ssid *ssid; |
| 2690 | |
| 2691 | id = atoi(cmd); |
| 2692 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id); |
| 2693 | |
| 2694 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 2695 | if (ssid == NULL) { |
| 2696 | wpa_printf(MSG_DEBUG, |
| 2697 | "CTRL_IFACE: Could not find network id=%d", id); |
| 2698 | return -1; |
| 2699 | } |
| 2700 | if (ssid->mode != WPAS_MODE_MESH) { |
| 2701 | wpa_printf(MSG_DEBUG, |
| 2702 | "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network"); |
| 2703 | return -1; |
| 2704 | } |
| 2705 | if (ssid->key_mgmt != WPA_KEY_MGMT_NONE && |
| 2706 | ssid->key_mgmt != WPA_KEY_MGMT_SAE) { |
| 2707 | wpa_printf(MSG_ERROR, |
| 2708 | "CTRL_IFACE: key_mgmt for mesh network should be open or SAE"); |
| 2709 | return -1; |
| 2710 | } |
| 2711 | |
| 2712 | /* |
| 2713 | * TODO: If necessary write our own group_add function, |
| 2714 | * for now we can reuse select_network |
| 2715 | */ |
| 2716 | wpa_supplicant_select_network(wpa_s, ssid); |
| 2717 | |
| 2718 | return 0; |
| 2719 | } |
| 2720 | |
| 2721 | |
| 2722 | static int wpa_supplicant_ctrl_iface_mesh_group_remove( |
| 2723 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2724 | { |
| 2725 | struct wpa_supplicant *orig; |
| 2726 | struct wpa_global *global; |
| 2727 | int found = 0; |
| 2728 | |
| 2729 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd); |
| 2730 | |
| 2731 | global = wpa_s->global; |
| 2732 | orig = wpa_s; |
| 2733 | |
| 2734 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 2735 | if (os_strcmp(wpa_s->ifname, cmd) == 0) { |
| 2736 | found = 1; |
| 2737 | break; |
| 2738 | } |
| 2739 | } |
| 2740 | if (!found) { |
| 2741 | wpa_printf(MSG_ERROR, |
| 2742 | "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found", |
| 2743 | cmd); |
| 2744 | return -1; |
| 2745 | } |
| 2746 | if (wpa_s->mesh_if_created && wpa_s == orig) { |
| 2747 | wpa_printf(MSG_ERROR, |
| 2748 | "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself"); |
| 2749 | return -1; |
| 2750 | } |
| 2751 | |
| 2752 | wpa_s->reassociate = 0; |
| 2753 | wpa_s->disconnected = 1; |
| 2754 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 2755 | wpa_supplicant_cancel_scan(wpa_s); |
| 2756 | |
| 2757 | /* |
| 2758 | * TODO: If necessary write our own group_remove function, |
| 2759 | * for now we can reuse deauthenticate |
| 2760 | */ |
| 2761 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 2762 | |
| 2763 | if (wpa_s->mesh_if_created) |
| 2764 | wpa_supplicant_remove_iface(global, wpa_s, 0); |
| 2765 | |
| 2766 | return 0; |
| 2767 | } |
| 2768 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 2769 | |
| 2770 | static int wpa_supplicant_ctrl_iface_mesh_peer_remove( |
| 2771 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2772 | { |
| 2773 | u8 addr[ETH_ALEN]; |
| 2774 | |
| 2775 | if (hwaddr_aton(cmd, addr) < 0) |
| 2776 | return -1; |
| 2777 | |
| 2778 | return wpas_mesh_peer_remove(wpa_s, addr); |
| 2779 | } |
| 2780 | |
| 2781 | |
| 2782 | static int wpa_supplicant_ctrl_iface_mesh_peer_add( |
| 2783 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2784 | { |
| 2785 | u8 addr[ETH_ALEN]; |
| 2786 | int duration; |
| 2787 | char *pos; |
| 2788 | |
| 2789 | pos = os_strstr(cmd, " duration="); |
| 2790 | if (pos) { |
| 2791 | *pos = '\0'; |
| 2792 | duration = atoi(pos + 10); |
| 2793 | } else { |
| 2794 | duration = -1; |
| 2795 | } |
| 2796 | |
| 2797 | if (hwaddr_aton(cmd, addr)) |
| 2798 | return -1; |
| 2799 | |
| 2800 | return wpas_mesh_peer_add(wpa_s, addr, duration); |
| 2801 | } |
| 2802 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2803 | #endif /* CONFIG_MESH */ |
| 2804 | |
| 2805 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2806 | static int wpa_supplicant_ctrl_iface_select_network( |
| 2807 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2808 | { |
| 2809 | int id; |
| 2810 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 2811 | char *pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2812 | |
| 2813 | /* cmd: "<network id>" or "any" */ |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 2814 | if (os_strncmp(cmd, "any", 3) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2815 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); |
| 2816 | ssid = NULL; |
| 2817 | } else { |
| 2818 | id = atoi(cmd); |
| 2819 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); |
| 2820 | |
| 2821 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 2822 | if (ssid == NULL) { |
| 2823 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 2824 | "network id=%d", id); |
| 2825 | return -1; |
| 2826 | } |
| 2827 | if (ssid->disabled == 2) { |
| 2828 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| 2829 | "SELECT_NETWORK with persistent P2P group"); |
| 2830 | return -1; |
| 2831 | } |
| 2832 | } |
| 2833 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 2834 | pos = os_strstr(cmd, " freq="); |
| 2835 | if (pos) { |
| 2836 | int *freqs = freq_range_to_channel_list(wpa_s, pos + 6); |
| 2837 | if (freqs) { |
| 2838 | wpa_s->scan_req = MANUAL_SCAN_REQ; |
| 2839 | os_free(wpa_s->manual_scan_freqs); |
| 2840 | wpa_s->manual_scan_freqs = freqs; |
| 2841 | } |
| 2842 | } |
| 2843 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2844 | wpa_s->scan_min_time.sec = 0; |
| 2845 | wpa_s->scan_min_time.usec = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2846 | wpa_supplicant_select_network(wpa_s, ssid); |
| 2847 | |
| 2848 | return 0; |
| 2849 | } |
| 2850 | |
| 2851 | |
| 2852 | static int wpa_supplicant_ctrl_iface_enable_network( |
| 2853 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2854 | { |
| 2855 | int id; |
| 2856 | struct wpa_ssid *ssid; |
| 2857 | |
| 2858 | /* cmd: "<network id>" or "all" */ |
| 2859 | if (os_strcmp(cmd, "all") == 0) { |
| 2860 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); |
| 2861 | ssid = NULL; |
| 2862 | } else { |
| 2863 | id = atoi(cmd); |
| 2864 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); |
| 2865 | |
| 2866 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 2867 | if (ssid == NULL) { |
| 2868 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 2869 | "network id=%d", id); |
| 2870 | return -1; |
| 2871 | } |
| 2872 | if (ssid->disabled == 2) { |
| 2873 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| 2874 | "ENABLE_NETWORK with persistent P2P group"); |
| 2875 | return -1; |
| 2876 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2877 | |
| 2878 | if (os_strstr(cmd, " no-connect")) { |
| 2879 | ssid->disabled = 0; |
| 2880 | return 0; |
| 2881 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2882 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2883 | wpa_s->scan_min_time.sec = 0; |
| 2884 | wpa_s->scan_min_time.usec = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2885 | wpa_supplicant_enable_network(wpa_s, ssid); |
| 2886 | |
| 2887 | return 0; |
| 2888 | } |
| 2889 | |
| 2890 | |
| 2891 | static int wpa_supplicant_ctrl_iface_disable_network( |
| 2892 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2893 | { |
| 2894 | int id; |
| 2895 | struct wpa_ssid *ssid; |
| 2896 | |
| 2897 | /* cmd: "<network id>" or "all" */ |
| 2898 | if (os_strcmp(cmd, "all") == 0) { |
| 2899 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); |
| 2900 | ssid = NULL; |
| 2901 | } else { |
| 2902 | id = atoi(cmd); |
| 2903 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); |
| 2904 | |
| 2905 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 2906 | if (ssid == NULL) { |
| 2907 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 2908 | "network id=%d", id); |
| 2909 | return -1; |
| 2910 | } |
| 2911 | if (ssid->disabled == 2) { |
| 2912 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| 2913 | "DISABLE_NETWORK with persistent P2P " |
| 2914 | "group"); |
| 2915 | return -1; |
| 2916 | } |
| 2917 | } |
| 2918 | wpa_supplicant_disable_network(wpa_s, ssid); |
| 2919 | |
| 2920 | return 0; |
| 2921 | } |
| 2922 | |
| 2923 | |
| 2924 | static int wpa_supplicant_ctrl_iface_add_network( |
| 2925 | struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| 2926 | { |
| 2927 | struct wpa_ssid *ssid; |
| 2928 | int ret; |
| 2929 | |
| 2930 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); |
| 2931 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 2932 | ssid = wpa_supplicant_add_network(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2933 | if (ssid == NULL) |
| 2934 | return -1; |
| 2935 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2936 | ret = os_snprintf(buf, buflen, "%d\n", ssid->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2937 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2938 | return -1; |
| 2939 | return ret; |
| 2940 | } |
| 2941 | |
| 2942 | |
| 2943 | static int wpa_supplicant_ctrl_iface_remove_network( |
| 2944 | struct wpa_supplicant *wpa_s, char *cmd) |
| 2945 | { |
| 2946 | int id; |
| 2947 | struct wpa_ssid *ssid; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 2948 | int result; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2949 | |
| 2950 | /* cmd: "<network id>" or "all" */ |
| 2951 | if (os_strcmp(cmd, "all") == 0) { |
| 2952 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2953 | if (wpa_s->sched_scanning) |
| 2954 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 2955 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2956 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2957 | if (wpa_s->current_ssid) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2958 | #ifdef CONFIG_SME |
| 2959 | wpa_s->sme.prev_bssid_set = 0; |
| 2960 | #endif /* CONFIG_SME */ |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2961 | wpa_sm_set_config(wpa_s->wpa, NULL); |
| 2962 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2963 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
| 2964 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2965 | wpa_supplicant_deauthenticate( |
| 2966 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2967 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2968 | ssid = wpa_s->conf->ssid; |
| 2969 | while (ssid) { |
| 2970 | struct wpa_ssid *remove_ssid = ssid; |
| 2971 | id = ssid->id; |
| 2972 | ssid = ssid->next; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2973 | if (wpa_s->last_ssid == remove_ssid) |
| 2974 | wpa_s->last_ssid = NULL; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2975 | wpas_notify_network_removed(wpa_s, remove_ssid); |
| 2976 | wpa_config_remove_network(wpa_s->conf, id); |
| 2977 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2978 | return 0; |
| 2979 | } |
| 2980 | |
| 2981 | id = atoi(cmd); |
| 2982 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); |
| 2983 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 2984 | result = wpa_supplicant_remove_network(wpa_s, id); |
| 2985 | if (result == -1) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2986 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
| 2987 | "id=%d", id); |
| 2988 | return -1; |
| 2989 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 2990 | if (result == -2) { |
Deepthi Gowri | a831d78 | 2012-09-03 11:55:38 +0300 | [diff] [blame] | 2991 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the " |
| 2992 | "network id=%d", id); |
| 2993 | return -1; |
| 2994 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2995 | return 0; |
| 2996 | } |
| 2997 | |
| 2998 | |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 2999 | static int wpa_supplicant_ctrl_iface_update_network( |
| 3000 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 3001 | char *name, char *value) |
| 3002 | { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3003 | int ret; |
| 3004 | |
| 3005 | ret = wpa_config_set(ssid, name, value, 0); |
| 3006 | if (ret < 0) { |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3007 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " |
| 3008 | "variable '%s'", name); |
| 3009 | return -1; |
| 3010 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3011 | if (ret == 1) |
| 3012 | return 0; /* No change to the previously configured value */ |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3013 | |
| 3014 | if (os_strcmp(name, "bssid") != 0 && |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3015 | os_strcmp(name, "priority") != 0) { |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3016 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
| 3017 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3018 | if (wpa_s->current_ssid == ssid || |
| 3019 | wpa_s->current_ssid == NULL) { |
| 3020 | /* |
| 3021 | * Invalidate the EAP session cache if anything in the |
| 3022 | * current or previously used configuration changes. |
| 3023 | */ |
| 3024 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
| 3025 | } |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3026 | } |
| 3027 | |
| 3028 | if ((os_strcmp(name, "psk") == 0 && |
| 3029 | value[0] == '"' && ssid->ssid_len) || |
| 3030 | (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) |
| 3031 | wpa_config_update_psk(ssid); |
| 3032 | else if (os_strcmp(name, "priority") == 0) |
| 3033 | wpa_config_update_prio_list(wpa_s->conf); |
| 3034 | |
| 3035 | return 0; |
| 3036 | } |
| 3037 | |
| 3038 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3039 | static int wpa_supplicant_ctrl_iface_set_network( |
| 3040 | struct wpa_supplicant *wpa_s, char *cmd) |
| 3041 | { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3042 | int id, ret, prev_bssid_set, prev_disabled; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3043 | struct wpa_ssid *ssid; |
| 3044 | char *name, *value; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3045 | u8 prev_bssid[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3046 | |
| 3047 | /* cmd: "<network id> <variable name> <value>" */ |
| 3048 | name = os_strchr(cmd, ' '); |
| 3049 | if (name == NULL) |
| 3050 | return -1; |
| 3051 | *name++ = '\0'; |
| 3052 | |
| 3053 | value = os_strchr(name, ' '); |
| 3054 | if (value == NULL) |
| 3055 | return -1; |
| 3056 | *value++ = '\0'; |
| 3057 | |
| 3058 | id = atoi(cmd); |
| 3059 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", |
| 3060 | id, name); |
| 3061 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", |
| 3062 | (u8 *) value, os_strlen(value)); |
| 3063 | |
| 3064 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3065 | if (ssid == NULL) { |
| 3066 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " |
| 3067 | "id=%d", id); |
| 3068 | return -1; |
| 3069 | } |
| 3070 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3071 | prev_bssid_set = ssid->bssid_set; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3072 | prev_disabled = ssid->disabled; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3073 | os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN); |
| 3074 | ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name, |
| 3075 | value); |
| 3076 | if (ret == 0 && |
| 3077 | (ssid->bssid_set != prev_bssid_set || |
| 3078 | os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0)) |
| 3079 | wpas_notify_network_bssid_set_changed(wpa_s, ssid); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3080 | |
| 3081 | if (prev_disabled != ssid->disabled && |
| 3082 | (prev_disabled == 2 || ssid->disabled == 2)) |
| 3083 | wpas_notify_network_type_changed(wpa_s, ssid); |
| 3084 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3085 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | |
| 3089 | static int wpa_supplicant_ctrl_iface_get_network( |
| 3090 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| 3091 | { |
| 3092 | int id; |
| 3093 | size_t res; |
| 3094 | struct wpa_ssid *ssid; |
| 3095 | char *name, *value; |
| 3096 | |
| 3097 | /* cmd: "<network id> <variable name>" */ |
| 3098 | name = os_strchr(cmd, ' '); |
| 3099 | if (name == NULL || buflen == 0) |
| 3100 | return -1; |
| 3101 | *name++ = '\0'; |
| 3102 | |
| 3103 | id = atoi(cmd); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3104 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3105 | id, name); |
| 3106 | |
| 3107 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 3108 | if (ssid == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3109 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3110 | "id=%d", id); |
| 3111 | return -1; |
| 3112 | } |
| 3113 | |
| 3114 | value = wpa_config_get_no_key(ssid, name); |
| 3115 | if (value == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3116 | wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3117 | "variable '%s'", name); |
| 3118 | return -1; |
| 3119 | } |
| 3120 | |
| 3121 | res = os_strlcpy(buf, value, buflen); |
| 3122 | if (res >= buflen) { |
| 3123 | os_free(value); |
| 3124 | return -1; |
| 3125 | } |
| 3126 | |
| 3127 | os_free(value); |
| 3128 | |
| 3129 | return res; |
| 3130 | } |
| 3131 | |
| 3132 | |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3133 | static int wpa_supplicant_ctrl_iface_dup_network( |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3134 | struct wpa_supplicant *wpa_s, char *cmd, |
| 3135 | struct wpa_supplicant *dst_wpa_s) |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3136 | { |
| 3137 | struct wpa_ssid *ssid_s, *ssid_d; |
| 3138 | char *name, *id, *value; |
| 3139 | int id_s, id_d, ret; |
| 3140 | |
| 3141 | /* cmd: "<src network id> <dst network id> <variable name>" */ |
| 3142 | id = os_strchr(cmd, ' '); |
| 3143 | if (id == NULL) |
| 3144 | return -1; |
| 3145 | *id++ = '\0'; |
| 3146 | |
| 3147 | name = os_strchr(id, ' '); |
| 3148 | if (name == NULL) |
| 3149 | return -1; |
| 3150 | *name++ = '\0'; |
| 3151 | |
| 3152 | id_s = atoi(cmd); |
| 3153 | id_d = atoi(id); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3154 | |
| 3155 | wpa_printf(MSG_DEBUG, |
| 3156 | "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'", |
| 3157 | wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3158 | |
| 3159 | ssid_s = wpa_config_get_network(wpa_s->conf, id_s); |
| 3160 | if (ssid_s == NULL) { |
| 3161 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 3162 | "network id=%d", id_s); |
| 3163 | return -1; |
| 3164 | } |
| 3165 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3166 | ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3167 | if (ssid_d == NULL) { |
| 3168 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3169 | "network id=%d", id_d); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 3170 | return -1; |
| 3171 | } |
| 3172 | |
| 3173 | value = wpa_config_get(ssid_s, name); |
| 3174 | if (value == NULL) { |
| 3175 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network " |
| 3176 | "variable '%s'", name); |
| 3177 | return -1; |
| 3178 | } |
| 3179 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3180 | 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] | 3181 | value); |
| 3182 | |
| 3183 | os_free(value); |
| 3184 | |
| 3185 | return ret; |
| 3186 | } |
| 3187 | |
| 3188 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3189 | static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s, |
| 3190 | char *buf, size_t buflen) |
| 3191 | { |
| 3192 | char *pos, *end; |
| 3193 | struct wpa_cred *cred; |
| 3194 | int ret; |
| 3195 | |
| 3196 | pos = buf; |
| 3197 | end = buf + buflen; |
| 3198 | ret = os_snprintf(pos, end - pos, |
| 3199 | "cred id / realm / username / domain / imsi\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3200 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3201 | return pos - buf; |
| 3202 | pos += ret; |
| 3203 | |
| 3204 | cred = wpa_s->conf->cred; |
| 3205 | while (cred) { |
| 3206 | ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n", |
| 3207 | cred->id, cred->realm ? cred->realm : "", |
| 3208 | cred->username ? cred->username : "", |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3209 | cred->domain ? cred->domain[0] : "", |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3210 | cred->imsi ? cred->imsi : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3211 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3212 | return pos - buf; |
| 3213 | pos += ret; |
| 3214 | |
| 3215 | cred = cred->next; |
| 3216 | } |
| 3217 | |
| 3218 | return pos - buf; |
| 3219 | } |
| 3220 | |
| 3221 | |
| 3222 | static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s, |
| 3223 | char *buf, size_t buflen) |
| 3224 | { |
| 3225 | struct wpa_cred *cred; |
| 3226 | int ret; |
| 3227 | |
| 3228 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED"); |
| 3229 | |
| 3230 | cred = wpa_config_add_cred(wpa_s->conf); |
| 3231 | if (cred == NULL) |
| 3232 | return -1; |
| 3233 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3234 | wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id); |
| 3235 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3236 | ret = os_snprintf(buf, buflen, "%d\n", cred->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3237 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3238 | return -1; |
| 3239 | return ret; |
| 3240 | } |
| 3241 | |
| 3242 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3243 | static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s, |
| 3244 | struct wpa_cred *cred) |
| 3245 | { |
| 3246 | struct wpa_ssid *ssid; |
| 3247 | char str[20]; |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3248 | int id; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3249 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3250 | if (cred == NULL) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3251 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); |
| 3252 | return -1; |
| 3253 | } |
| 3254 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3255 | id = cred->id; |
| 3256 | if (wpa_config_remove_cred(wpa_s->conf, id) < 0) { |
| 3257 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred"); |
| 3258 | return -1; |
| 3259 | } |
| 3260 | |
| 3261 | wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id); |
| 3262 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3263 | /* Remove any network entry created based on the removed credential */ |
| 3264 | ssid = wpa_s->conf->ssid; |
| 3265 | while (ssid) { |
| 3266 | if (ssid->parent_cred == cred) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3267 | int res; |
| 3268 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3269 | wpa_printf(MSG_DEBUG, "Remove network id %d since it " |
| 3270 | "used the removed credential", ssid->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3271 | res = os_snprintf(str, sizeof(str), "%d", ssid->id); |
| 3272 | if (os_snprintf_error(sizeof(str), res)) |
| 3273 | str[sizeof(str) - 1] = '\0'; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3274 | ssid = ssid->next; |
| 3275 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, str); |
| 3276 | } else |
| 3277 | ssid = ssid->next; |
| 3278 | } |
| 3279 | |
| 3280 | return 0; |
| 3281 | } |
| 3282 | |
| 3283 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3284 | static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s, |
| 3285 | char *cmd) |
| 3286 | { |
| 3287 | int id; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3288 | struct wpa_cred *cred, *prev; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3289 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3290 | /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or |
| 3291 | * "provisioning_sp=<FQDN> */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3292 | if (os_strcmp(cmd, "all") == 0) { |
| 3293 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all"); |
| 3294 | cred = wpa_s->conf->cred; |
| 3295 | while (cred) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3296 | prev = cred; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3297 | cred = cred->next; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3298 | wpas_ctrl_remove_cred(wpa_s, prev); |
| 3299 | } |
| 3300 | return 0; |
| 3301 | } |
| 3302 | |
| 3303 | if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) { |
| 3304 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'", |
| 3305 | cmd + 8); |
| 3306 | cred = wpa_s->conf->cred; |
| 3307 | while (cred) { |
| 3308 | prev = cred; |
| 3309 | cred = cred->next; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3310 | if (prev->domain) { |
| 3311 | size_t i; |
| 3312 | for (i = 0; i < prev->num_domain; i++) { |
| 3313 | if (os_strcmp(prev->domain[i], cmd + 8) |
| 3314 | != 0) |
| 3315 | continue; |
| 3316 | wpas_ctrl_remove_cred(wpa_s, prev); |
| 3317 | break; |
| 3318 | } |
| 3319 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3320 | } |
| 3321 | return 0; |
| 3322 | } |
| 3323 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3324 | if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) { |
| 3325 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'", |
| 3326 | cmd + 16); |
| 3327 | cred = wpa_s->conf->cred; |
| 3328 | while (cred) { |
| 3329 | prev = cred; |
| 3330 | cred = cred->next; |
| 3331 | if (prev->provisioning_sp && |
| 3332 | os_strcmp(prev->provisioning_sp, cmd + 16) == 0) |
| 3333 | wpas_ctrl_remove_cred(wpa_s, prev); |
| 3334 | } |
| 3335 | return 0; |
| 3336 | } |
| 3337 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3338 | id = atoi(cmd); |
| 3339 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id); |
| 3340 | |
| 3341 | cred = wpa_config_get_cred(wpa_s->conf, id); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3342 | return wpas_ctrl_remove_cred(wpa_s, cred); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | |
| 3346 | static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s, |
| 3347 | char *cmd) |
| 3348 | { |
| 3349 | int id; |
| 3350 | struct wpa_cred *cred; |
| 3351 | char *name, *value; |
| 3352 | |
| 3353 | /* cmd: "<cred id> <variable name> <value>" */ |
| 3354 | name = os_strchr(cmd, ' '); |
| 3355 | if (name == NULL) |
| 3356 | return -1; |
| 3357 | *name++ = '\0'; |
| 3358 | |
| 3359 | value = os_strchr(name, ' '); |
| 3360 | if (value == NULL) |
| 3361 | return -1; |
| 3362 | *value++ = '\0'; |
| 3363 | |
| 3364 | id = atoi(cmd); |
| 3365 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'", |
| 3366 | id, name); |
| 3367 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", |
| 3368 | (u8 *) value, os_strlen(value)); |
| 3369 | |
| 3370 | cred = wpa_config_get_cred(wpa_s->conf, id); |
| 3371 | if (cred == NULL) { |
| 3372 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", |
| 3373 | id); |
| 3374 | return -1; |
| 3375 | } |
| 3376 | |
| 3377 | if (wpa_config_set_cred(cred, name, value, 0) < 0) { |
| 3378 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred " |
| 3379 | "variable '%s'", name); |
| 3380 | return -1; |
| 3381 | } |
| 3382 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3383 | wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name); |
| 3384 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3385 | return 0; |
| 3386 | } |
| 3387 | |
| 3388 | |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 3389 | static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s, |
| 3390 | char *cmd, char *buf, |
| 3391 | size_t buflen) |
| 3392 | { |
| 3393 | int id; |
| 3394 | size_t res; |
| 3395 | struct wpa_cred *cred; |
| 3396 | char *name, *value; |
| 3397 | |
| 3398 | /* cmd: "<cred id> <variable name>" */ |
| 3399 | name = os_strchr(cmd, ' '); |
| 3400 | if (name == NULL) |
| 3401 | return -1; |
| 3402 | *name++ = '\0'; |
| 3403 | |
| 3404 | id = atoi(cmd); |
| 3405 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'", |
| 3406 | id, name); |
| 3407 | |
| 3408 | cred = wpa_config_get_cred(wpa_s->conf, id); |
| 3409 | if (cred == NULL) { |
| 3410 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d", |
| 3411 | id); |
| 3412 | return -1; |
| 3413 | } |
| 3414 | |
| 3415 | value = wpa_config_get_cred_no_key(cred, name); |
| 3416 | if (value == NULL) { |
| 3417 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'", |
| 3418 | name); |
| 3419 | return -1; |
| 3420 | } |
| 3421 | |
| 3422 | res = os_strlcpy(buf, value, buflen); |
| 3423 | if (res >= buflen) { |
| 3424 | os_free(value); |
| 3425 | return -1; |
| 3426 | } |
| 3427 | |
| 3428 | os_free(value); |
| 3429 | |
| 3430 | return res; |
| 3431 | } |
| 3432 | |
| 3433 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3434 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 3435 | static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s) |
| 3436 | { |
| 3437 | int ret; |
| 3438 | |
| 3439 | if (!wpa_s->conf->update_config) { |
| 3440 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed " |
| 3441 | "to update configuration (update_config=0)"); |
| 3442 | return -1; |
| 3443 | } |
| 3444 | |
| 3445 | ret = wpa_config_write(wpa_s->confname, wpa_s->conf); |
| 3446 | if (ret) { |
| 3447 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to " |
| 3448 | "update configuration"); |
| 3449 | } else { |
| 3450 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration" |
| 3451 | " updated"); |
| 3452 | } |
| 3453 | |
| 3454 | return ret; |
| 3455 | } |
| 3456 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 3457 | |
| 3458 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3459 | struct cipher_info { |
| 3460 | unsigned int capa; |
| 3461 | const char *name; |
| 3462 | int group_only; |
| 3463 | }; |
| 3464 | |
| 3465 | static const struct cipher_info ciphers[] = { |
| 3466 | { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 }, |
| 3467 | { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 }, |
| 3468 | { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 }, |
| 3469 | { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 }, |
| 3470 | { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 }, |
| 3471 | { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 }, |
| 3472 | { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 }, |
| 3473 | { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 } |
| 3474 | }; |
| 3475 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3476 | static const struct cipher_info ciphers_group_mgmt[] = { |
| 3477 | { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 }, |
| 3478 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 }, |
| 3479 | { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 }, |
| 3480 | { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 }, |
| 3481 | }; |
| 3482 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3483 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3484 | static int ctrl_iface_get_capability_pairwise(int res, char *strict, |
| 3485 | struct wpa_driver_capa *capa, |
| 3486 | char *buf, size_t buflen) |
| 3487 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3488 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3489 | char *pos, *end; |
| 3490 | size_t len; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3491 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3492 | |
| 3493 | pos = buf; |
| 3494 | end = pos + buflen; |
| 3495 | |
| 3496 | if (res < 0) { |
| 3497 | if (strict) |
| 3498 | return 0; |
| 3499 | len = os_strlcpy(buf, "CCMP TKIP NONE", buflen); |
| 3500 | if (len >= buflen) |
| 3501 | return -1; |
| 3502 | return len; |
| 3503 | } |
| 3504 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3505 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
| 3506 | if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) { |
| 3507 | ret = os_snprintf(pos, end - pos, "%s%s", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3508 | pos == buf ? "" : " ", |
| 3509 | ciphers[i].name); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3510 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3511 | return pos - buf; |
| 3512 | pos += ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3513 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | return pos - buf; |
| 3517 | } |
| 3518 | |
| 3519 | |
| 3520 | static int ctrl_iface_get_capability_group(int res, char *strict, |
| 3521 | struct wpa_driver_capa *capa, |
| 3522 | char *buf, size_t buflen) |
| 3523 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3524 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3525 | char *pos, *end; |
| 3526 | size_t len; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3527 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3528 | |
| 3529 | pos = buf; |
| 3530 | end = pos + buflen; |
| 3531 | |
| 3532 | if (res < 0) { |
| 3533 | if (strict) |
| 3534 | return 0; |
| 3535 | len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen); |
| 3536 | if (len >= buflen) |
| 3537 | return -1; |
| 3538 | return len; |
| 3539 | } |
| 3540 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3541 | for (i = 0; i < ARRAY_SIZE(ciphers); i++) { |
| 3542 | if (capa->enc & ciphers[i].capa) { |
| 3543 | ret = os_snprintf(pos, end - pos, "%s%s", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3544 | pos == buf ? "" : " ", |
| 3545 | ciphers[i].name); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3546 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3547 | return pos - buf; |
| 3548 | pos += ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3549 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | return pos - buf; |
| 3553 | } |
| 3554 | |
| 3555 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3556 | static int ctrl_iface_get_capability_group_mgmt(int res, char *strict, |
| 3557 | struct wpa_driver_capa *capa, |
| 3558 | char *buf, size_t buflen) |
| 3559 | { |
| 3560 | int ret; |
| 3561 | char *pos, *end; |
| 3562 | unsigned int i; |
| 3563 | |
| 3564 | pos = buf; |
| 3565 | end = pos + buflen; |
| 3566 | |
| 3567 | if (res < 0) |
| 3568 | return 0; |
| 3569 | |
| 3570 | for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) { |
| 3571 | if (capa->enc & ciphers_group_mgmt[i].capa) { |
| 3572 | ret = os_snprintf(pos, end - pos, "%s%s", |
| 3573 | pos == buf ? "" : " ", |
| 3574 | ciphers_group_mgmt[i].name); |
| 3575 | if (os_snprintf_error(end - pos, ret)) |
| 3576 | return pos - buf; |
| 3577 | pos += ret; |
| 3578 | } |
| 3579 | } |
| 3580 | |
| 3581 | return pos - buf; |
| 3582 | } |
| 3583 | |
| 3584 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3585 | static int ctrl_iface_get_capability_key_mgmt(int res, char *strict, |
| 3586 | struct wpa_driver_capa *capa, |
| 3587 | char *buf, size_t buflen) |
| 3588 | { |
| 3589 | int ret; |
| 3590 | char *pos, *end; |
| 3591 | size_t len; |
| 3592 | |
| 3593 | pos = buf; |
| 3594 | end = pos + buflen; |
| 3595 | |
| 3596 | if (res < 0) { |
| 3597 | if (strict) |
| 3598 | return 0; |
| 3599 | len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE " |
| 3600 | "NONE", buflen); |
| 3601 | if (len >= buflen) |
| 3602 | return -1; |
| 3603 | return len; |
| 3604 | } |
| 3605 | |
| 3606 | ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3607 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3608 | return pos - buf; |
| 3609 | pos += ret; |
| 3610 | |
| 3611 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
| 3612 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { |
| 3613 | ret = os_snprintf(pos, end - pos, " WPA-EAP"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3614 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3615 | return pos - buf; |
| 3616 | pos += ret; |
| 3617 | } |
| 3618 | |
| 3619 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | |
| 3620 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { |
| 3621 | ret = os_snprintf(pos, end - pos, " WPA-PSK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3622 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3623 | return pos - buf; |
| 3624 | pos += ret; |
| 3625 | } |
| 3626 | |
| 3627 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { |
| 3628 | ret = os_snprintf(pos, end - pos, " WPA-NONE"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3629 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3630 | return pos - buf; |
| 3631 | pos += ret; |
| 3632 | } |
| 3633 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3634 | #ifdef CONFIG_SUITEB |
| 3635 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) { |
| 3636 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B"); |
| 3637 | if (os_snprintf_error(end - pos, ret)) |
| 3638 | return pos - buf; |
| 3639 | pos += ret; |
| 3640 | } |
| 3641 | #endif /* CONFIG_SUITEB */ |
| 3642 | #ifdef CONFIG_SUITEB192 |
| 3643 | if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) { |
| 3644 | ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192"); |
| 3645 | if (os_snprintf_error(end - pos, ret)) |
| 3646 | return pos - buf; |
| 3647 | pos += ret; |
| 3648 | } |
| 3649 | #endif /* CONFIG_SUITEB192 */ |
| 3650 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3651 | return pos - buf; |
| 3652 | } |
| 3653 | |
| 3654 | |
| 3655 | static int ctrl_iface_get_capability_proto(int res, char *strict, |
| 3656 | struct wpa_driver_capa *capa, |
| 3657 | char *buf, size_t buflen) |
| 3658 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3659 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3660 | char *pos, *end; |
| 3661 | size_t len; |
| 3662 | |
| 3663 | pos = buf; |
| 3664 | end = pos + buflen; |
| 3665 | |
| 3666 | if (res < 0) { |
| 3667 | if (strict) |
| 3668 | return 0; |
| 3669 | len = os_strlcpy(buf, "RSN WPA", buflen); |
| 3670 | if (len >= buflen) |
| 3671 | return -1; |
| 3672 | return len; |
| 3673 | } |
| 3674 | |
| 3675 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | |
| 3676 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3677 | ret = os_snprintf(pos, end - pos, "%sRSN", |
| 3678 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3679 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3680 | return pos - buf; |
| 3681 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
| 3685 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3686 | ret = os_snprintf(pos, end - pos, "%sWPA", |
| 3687 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3688 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3689 | return pos - buf; |
| 3690 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3691 | } |
| 3692 | |
| 3693 | return pos - buf; |
| 3694 | } |
| 3695 | |
| 3696 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3697 | static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s, |
| 3698 | int res, char *strict, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3699 | struct wpa_driver_capa *capa, |
| 3700 | char *buf, size_t buflen) |
| 3701 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3702 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3703 | char *pos, *end; |
| 3704 | size_t len; |
| 3705 | |
| 3706 | pos = buf; |
| 3707 | end = pos + buflen; |
| 3708 | |
| 3709 | if (res < 0) { |
| 3710 | if (strict) |
| 3711 | return 0; |
| 3712 | len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen); |
| 3713 | if (len >= buflen) |
| 3714 | return -1; |
| 3715 | return len; |
| 3716 | } |
| 3717 | |
| 3718 | if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3719 | ret = os_snprintf(pos, end - pos, "%sOPEN", |
| 3720 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3721 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3722 | return pos - buf; |
| 3723 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) { |
| 3727 | ret = os_snprintf(pos, end - pos, "%sSHARED", |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3728 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3729 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3730 | return pos - buf; |
| 3731 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3735 | ret = os_snprintf(pos, end - pos, "%sLEAP", |
| 3736 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3737 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3738 | return pos - buf; |
| 3739 | pos += ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3740 | } |
| 3741 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3742 | #ifdef CONFIG_SAE |
| 3743 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) { |
| 3744 | ret = os_snprintf(pos, end - pos, "%sSAE", |
| 3745 | pos == buf ? "" : " "); |
| 3746 | if (os_snprintf_error(end - pos, ret)) |
| 3747 | return pos - buf; |
| 3748 | pos += ret; |
| 3749 | } |
| 3750 | #endif /* CONFIG_SAE */ |
| 3751 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3752 | return pos - buf; |
| 3753 | } |
| 3754 | |
| 3755 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3756 | static int ctrl_iface_get_capability_modes(int res, char *strict, |
| 3757 | struct wpa_driver_capa *capa, |
| 3758 | char *buf, size_t buflen) |
| 3759 | { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3760 | int ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3761 | char *pos, *end; |
| 3762 | size_t len; |
| 3763 | |
| 3764 | pos = buf; |
| 3765 | end = pos + buflen; |
| 3766 | |
| 3767 | if (res < 0) { |
| 3768 | if (strict) |
| 3769 | return 0; |
| 3770 | len = os_strlcpy(buf, "IBSS AP", buflen); |
| 3771 | if (len >= buflen) |
| 3772 | return -1; |
| 3773 | return len; |
| 3774 | } |
| 3775 | |
| 3776 | if (capa->flags & WPA_DRIVER_FLAGS_IBSS) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3777 | ret = os_snprintf(pos, end - pos, "%sIBSS", |
| 3778 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3779 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3780 | return pos - buf; |
| 3781 | pos += ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | if (capa->flags & WPA_DRIVER_FLAGS_AP) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3785 | ret = os_snprintf(pos, end - pos, "%sAP", |
| 3786 | pos == buf ? "" : " "); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3787 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3788 | return pos - buf; |
| 3789 | pos += ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3790 | } |
| 3791 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3792 | #ifdef CONFIG_MESH |
| 3793 | if (capa->flags & WPA_DRIVER_FLAGS_MESH) { |
| 3794 | ret = os_snprintf(pos, end - pos, "%sMESH", |
| 3795 | pos == buf ? "" : " "); |
| 3796 | if (os_snprintf_error(end - pos, ret)) |
| 3797 | return pos - buf; |
| 3798 | pos += ret; |
| 3799 | } |
| 3800 | #endif /* CONFIG_MESH */ |
| 3801 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3802 | return pos - buf; |
| 3803 | } |
| 3804 | |
| 3805 | |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3806 | static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s, |
| 3807 | char *buf, size_t buflen) |
| 3808 | { |
| 3809 | struct hostapd_channel_data *chnl; |
| 3810 | int ret, i, j; |
| 3811 | char *pos, *end, *hmode; |
| 3812 | |
| 3813 | pos = buf; |
| 3814 | end = pos + buflen; |
| 3815 | |
| 3816 | for (j = 0; j < wpa_s->hw.num_modes; j++) { |
| 3817 | switch (wpa_s->hw.modes[j].mode) { |
| 3818 | case HOSTAPD_MODE_IEEE80211B: |
| 3819 | hmode = "B"; |
| 3820 | break; |
| 3821 | case HOSTAPD_MODE_IEEE80211G: |
| 3822 | hmode = "G"; |
| 3823 | break; |
| 3824 | case HOSTAPD_MODE_IEEE80211A: |
| 3825 | hmode = "A"; |
| 3826 | break; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3827 | case HOSTAPD_MODE_IEEE80211AD: |
| 3828 | hmode = "AD"; |
| 3829 | break; |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3830 | default: |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3831 | continue; |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3832 | } |
| 3833 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3834 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3835 | return pos - buf; |
| 3836 | pos += ret; |
| 3837 | chnl = wpa_s->hw.modes[j].channels; |
| 3838 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3839 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) |
| 3840 | continue; |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3841 | ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3842 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3843 | return pos - buf; |
| 3844 | pos += ret; |
| 3845 | } |
| 3846 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3847 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3848 | return pos - buf; |
| 3849 | pos += ret; |
| 3850 | } |
| 3851 | |
| 3852 | return pos - buf; |
| 3853 | } |
| 3854 | |
| 3855 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3856 | static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s, |
| 3857 | char *buf, size_t buflen) |
| 3858 | { |
| 3859 | struct hostapd_channel_data *chnl; |
| 3860 | int ret, i, j; |
| 3861 | char *pos, *end, *hmode; |
| 3862 | |
| 3863 | pos = buf; |
| 3864 | end = pos + buflen; |
| 3865 | |
| 3866 | for (j = 0; j < wpa_s->hw.num_modes; j++) { |
| 3867 | switch (wpa_s->hw.modes[j].mode) { |
| 3868 | case HOSTAPD_MODE_IEEE80211B: |
| 3869 | hmode = "B"; |
| 3870 | break; |
| 3871 | case HOSTAPD_MODE_IEEE80211G: |
| 3872 | hmode = "G"; |
| 3873 | break; |
| 3874 | case HOSTAPD_MODE_IEEE80211A: |
| 3875 | hmode = "A"; |
| 3876 | break; |
| 3877 | case HOSTAPD_MODE_IEEE80211AD: |
| 3878 | hmode = "AD"; |
| 3879 | break; |
| 3880 | default: |
| 3881 | continue; |
| 3882 | } |
| 3883 | ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n", |
| 3884 | hmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3885 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3886 | return pos - buf; |
| 3887 | pos += ret; |
| 3888 | chnl = wpa_s->hw.modes[j].channels; |
| 3889 | for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) { |
| 3890 | if (chnl[i].flag & HOSTAPD_CHAN_DISABLED) |
| 3891 | continue; |
Dmitry Shmidt | 5da5e35 | 2014-02-03 13:30:46 -0800 | [diff] [blame] | 3892 | ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n", |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3893 | chnl[i].chan, chnl[i].freq, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3894 | chnl[i].flag & HOSTAPD_CHAN_NO_IR ? |
| 3895 | " (NO_IR)" : "", |
Dmitry Shmidt | 5da5e35 | 2014-02-03 13:30:46 -0800 | [diff] [blame] | 3896 | chnl[i].flag & HOSTAPD_CHAN_RADAR ? |
| 3897 | " (DFS)" : ""); |
| 3898 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3899 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3900 | return pos - buf; |
| 3901 | pos += ret; |
| 3902 | } |
| 3903 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3904 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3905 | return pos - buf; |
| 3906 | pos += ret; |
| 3907 | } |
| 3908 | |
| 3909 | return pos - buf; |
| 3910 | } |
| 3911 | |
| 3912 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3913 | static int wpa_supplicant_ctrl_iface_get_capability( |
| 3914 | struct wpa_supplicant *wpa_s, const char *_field, char *buf, |
| 3915 | size_t buflen) |
| 3916 | { |
| 3917 | struct wpa_driver_capa capa; |
| 3918 | int res; |
| 3919 | char *strict; |
| 3920 | char field[30]; |
| 3921 | size_t len; |
| 3922 | |
| 3923 | /* Determine whether or not strict checking was requested */ |
| 3924 | len = os_strlcpy(field, _field, sizeof(field)); |
| 3925 | if (len >= sizeof(field)) |
| 3926 | return -1; |
| 3927 | strict = os_strchr(field, ' '); |
| 3928 | if (strict != NULL) { |
| 3929 | *strict++ = '\0'; |
| 3930 | if (os_strcmp(strict, "strict") != 0) |
| 3931 | return -1; |
| 3932 | } |
| 3933 | |
| 3934 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s", |
| 3935 | field, strict ? strict : ""); |
| 3936 | |
| 3937 | if (os_strcmp(field, "eap") == 0) { |
| 3938 | return eap_get_names(buf, buflen); |
| 3939 | } |
| 3940 | |
| 3941 | res = wpa_drv_get_capa(wpa_s, &capa); |
| 3942 | |
| 3943 | if (os_strcmp(field, "pairwise") == 0) |
| 3944 | return ctrl_iface_get_capability_pairwise(res, strict, &capa, |
| 3945 | buf, buflen); |
| 3946 | |
| 3947 | if (os_strcmp(field, "group") == 0) |
| 3948 | return ctrl_iface_get_capability_group(res, strict, &capa, |
| 3949 | buf, buflen); |
| 3950 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3951 | if (os_strcmp(field, "group_mgmt") == 0) |
| 3952 | return ctrl_iface_get_capability_group_mgmt(res, strict, &capa, |
| 3953 | buf, buflen); |
| 3954 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3955 | if (os_strcmp(field, "key_mgmt") == 0) |
| 3956 | return ctrl_iface_get_capability_key_mgmt(res, strict, &capa, |
| 3957 | buf, buflen); |
| 3958 | |
| 3959 | if (os_strcmp(field, "proto") == 0) |
| 3960 | return ctrl_iface_get_capability_proto(res, strict, &capa, |
| 3961 | buf, buflen); |
| 3962 | |
| 3963 | if (os_strcmp(field, "auth_alg") == 0) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3964 | return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict, |
| 3965 | &capa, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3966 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3967 | if (os_strcmp(field, "modes") == 0) |
| 3968 | return ctrl_iface_get_capability_modes(res, strict, &capa, |
| 3969 | buf, buflen); |
| 3970 | |
Dmitry Shmidt | 0e6d08e | 2012-07-10 12:49:30 -0700 | [diff] [blame] | 3971 | if (os_strcmp(field, "channels") == 0) |
| 3972 | return ctrl_iface_get_capability_channels(wpa_s, buf, buflen); |
| 3973 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3974 | if (os_strcmp(field, "freq") == 0) |
| 3975 | return ctrl_iface_get_capability_freq(wpa_s, buf, buflen); |
| 3976 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 3977 | #ifdef CONFIG_TDLS |
| 3978 | if (os_strcmp(field, "tdls") == 0) |
| 3979 | return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen); |
| 3980 | #endif /* CONFIG_TDLS */ |
| 3981 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3982 | #ifdef CONFIG_ERP |
| 3983 | if (os_strcmp(field, "erp") == 0) { |
| 3984 | res = os_snprintf(buf, buflen, "ERP"); |
| 3985 | if (os_snprintf_error(buflen, res)) |
| 3986 | return -1; |
| 3987 | return res; |
| 3988 | } |
| 3989 | #endif /* CONFIG_EPR */ |
| 3990 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3991 | #ifdef CONFIG_FIPS |
| 3992 | if (os_strcmp(field, "fips") == 0) { |
| 3993 | res = os_snprintf(buf, buflen, "FIPS"); |
| 3994 | if (os_snprintf_error(buflen, res)) |
| 3995 | return -1; |
| 3996 | return res; |
| 3997 | } |
| 3998 | #endif /* CONFIG_FIPS */ |
| 3999 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 4000 | #ifdef CONFIG_ACS |
| 4001 | if (os_strcmp(field, "acs") == 0) { |
| 4002 | res = os_snprintf(buf, buflen, "ACS"); |
| 4003 | if (os_snprintf_error(buflen, res)) |
| 4004 | return -1; |
| 4005 | return res; |
| 4006 | } |
| 4007 | #endif /* CONFIG_ACS */ |
| 4008 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4009 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", |
| 4010 | field); |
| 4011 | |
| 4012 | return -1; |
| 4013 | } |
| 4014 | |
| 4015 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4016 | #ifdef CONFIG_INTERWORKING |
| 4017 | static char * anqp_add_hex(char *pos, char *end, const char *title, |
| 4018 | struct wpabuf *data) |
| 4019 | { |
| 4020 | char *start = pos; |
| 4021 | size_t i; |
| 4022 | int ret; |
| 4023 | const u8 *d; |
| 4024 | |
| 4025 | if (data == NULL) |
| 4026 | return start; |
| 4027 | |
| 4028 | ret = os_snprintf(pos, end - pos, "%s=", title); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4029 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4030 | return start; |
| 4031 | pos += ret; |
| 4032 | |
| 4033 | d = wpabuf_head_u8(data); |
| 4034 | for (i = 0; i < wpabuf_len(data); i++) { |
| 4035 | ret = os_snprintf(pos, end - pos, "%02x", *d++); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4036 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4037 | return start; |
| 4038 | pos += ret; |
| 4039 | } |
| 4040 | |
| 4041 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4042 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4043 | return start; |
| 4044 | pos += ret; |
| 4045 | |
| 4046 | return pos; |
| 4047 | } |
| 4048 | #endif /* CONFIG_INTERWORKING */ |
| 4049 | |
| 4050 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4051 | static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 4052 | unsigned long mask, char *buf, size_t buflen) |
| 4053 | { |
| 4054 | size_t i; |
| 4055 | int ret; |
| 4056 | char *pos, *end; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 4057 | const u8 *ie, *ie2, *osen_ie; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4058 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4059 | pos = buf; |
| 4060 | end = buf + buflen; |
| 4061 | |
| 4062 | if (mask & WPA_BSS_MASK_ID) { |
| 4063 | ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4064 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4065 | return 0; |
| 4066 | pos += ret; |
| 4067 | } |
| 4068 | |
| 4069 | if (mask & WPA_BSS_MASK_BSSID) { |
| 4070 | ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", |
| 4071 | MAC2STR(bss->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4072 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4073 | return 0; |
| 4074 | pos += ret; |
| 4075 | } |
| 4076 | |
| 4077 | if (mask & WPA_BSS_MASK_FREQ) { |
| 4078 | ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4079 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4080 | return 0; |
| 4081 | pos += ret; |
| 4082 | } |
| 4083 | |
| 4084 | if (mask & WPA_BSS_MASK_BEACON_INT) { |
| 4085 | ret = os_snprintf(pos, end - pos, "beacon_int=%d\n", |
| 4086 | bss->beacon_int); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4087 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4088 | return 0; |
| 4089 | pos += ret; |
| 4090 | } |
| 4091 | |
| 4092 | if (mask & WPA_BSS_MASK_CAPABILITIES) { |
| 4093 | ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n", |
| 4094 | bss->caps); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4095 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4096 | return 0; |
| 4097 | pos += ret; |
| 4098 | } |
| 4099 | |
| 4100 | if (mask & WPA_BSS_MASK_QUAL) { |
| 4101 | ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4102 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4103 | return 0; |
| 4104 | pos += ret; |
| 4105 | } |
| 4106 | |
| 4107 | if (mask & WPA_BSS_MASK_NOISE) { |
| 4108 | ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4109 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4110 | return 0; |
| 4111 | pos += ret; |
| 4112 | } |
| 4113 | |
| 4114 | if (mask & WPA_BSS_MASK_LEVEL) { |
| 4115 | ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4116 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4117 | return 0; |
| 4118 | pos += ret; |
| 4119 | } |
| 4120 | |
| 4121 | if (mask & WPA_BSS_MASK_TSF) { |
| 4122 | ret = os_snprintf(pos, end - pos, "tsf=%016llu\n", |
| 4123 | (unsigned long long) bss->tsf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4124 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4125 | return 0; |
| 4126 | pos += ret; |
| 4127 | } |
| 4128 | |
| 4129 | if (mask & WPA_BSS_MASK_AGE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4130 | struct os_reltime now; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4131 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4132 | os_get_reltime(&now); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4133 | ret = os_snprintf(pos, end - pos, "age=%d\n", |
| 4134 | (int) (now.sec - bss->last_update.sec)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4135 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4136 | return 0; |
| 4137 | pos += ret; |
| 4138 | } |
| 4139 | |
| 4140 | if (mask & WPA_BSS_MASK_IE) { |
| 4141 | ret = os_snprintf(pos, end - pos, "ie="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4142 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4143 | return 0; |
| 4144 | pos += ret; |
| 4145 | |
| 4146 | ie = (const u8 *) (bss + 1); |
| 4147 | for (i = 0; i < bss->ie_len; i++) { |
| 4148 | ret = os_snprintf(pos, end - pos, "%02x", *ie++); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4149 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4150 | return 0; |
| 4151 | pos += ret; |
| 4152 | } |
| 4153 | |
| 4154 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4155 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4156 | return 0; |
| 4157 | pos += ret; |
| 4158 | } |
| 4159 | |
| 4160 | if (mask & WPA_BSS_MASK_FLAGS) { |
| 4161 | ret = os_snprintf(pos, end - pos, "flags="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4162 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4163 | return 0; |
| 4164 | pos += ret; |
| 4165 | |
| 4166 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 4167 | if (ie) |
| 4168 | pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, |
| 4169 | 2 + ie[1]); |
| 4170 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 4171 | if (ie2) |
| 4172 | pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, |
| 4173 | 2 + ie2[1]); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 4174 | osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
| 4175 | if (osen_ie) |
| 4176 | pos = wpa_supplicant_ie_txt(pos, end, "OSEN", |
| 4177 | osen_ie, 2 + osen_ie[1]); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4178 | pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 4179 | if (!ie && !ie2 && !osen_ie && |
| 4180 | (bss->caps & IEEE80211_CAP_PRIVACY)) { |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4181 | ret = os_snprintf(pos, end - pos, "[WEP]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4182 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4183 | return 0; |
| 4184 | pos += ret; |
| 4185 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4186 | if (bss_is_dmg(bss)) { |
| 4187 | const char *s; |
| 4188 | ret = os_snprintf(pos, end - pos, "[DMG]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4189 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4190 | return 0; |
| 4191 | pos += ret; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4192 | switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
| 4193 | case IEEE80211_CAP_DMG_IBSS: |
| 4194 | s = "[IBSS]"; |
| 4195 | break; |
| 4196 | case IEEE80211_CAP_DMG_AP: |
| 4197 | s = "[ESS]"; |
| 4198 | break; |
| 4199 | case IEEE80211_CAP_DMG_PBSS: |
| 4200 | s = "[PBSS]"; |
| 4201 | break; |
| 4202 | default: |
| 4203 | s = ""; |
| 4204 | break; |
| 4205 | } |
| 4206 | ret = os_snprintf(pos, end - pos, "%s", s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4207 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4208 | return 0; |
| 4209 | pos += ret; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4210 | } else { |
| 4211 | if (bss->caps & IEEE80211_CAP_IBSS) { |
| 4212 | ret = os_snprintf(pos, end - pos, "[IBSS]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4213 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4214 | return 0; |
| 4215 | pos += ret; |
| 4216 | } |
| 4217 | if (bss->caps & IEEE80211_CAP_ESS) { |
| 4218 | ret = os_snprintf(pos, end - pos, "[ESS]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4219 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4220 | return 0; |
| 4221 | pos += ret; |
| 4222 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4223 | } |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 4224 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || |
| 4225 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4226 | ret = os_snprintf(pos, end - pos, "[P2P]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4227 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4228 | return 0; |
| 4229 | pos += ret; |
| 4230 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4231 | #ifdef CONFIG_HS20 |
| 4232 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) { |
| 4233 | ret = os_snprintf(pos, end - pos, "[HS20]"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4234 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 4235 | return 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4236 | pos += ret; |
| 4237 | } |
| 4238 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4239 | |
| 4240 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4241 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4242 | return 0; |
| 4243 | pos += ret; |
| 4244 | } |
| 4245 | |
| 4246 | if (mask & WPA_BSS_MASK_SSID) { |
| 4247 | ret = os_snprintf(pos, end - pos, "ssid=%s\n", |
| 4248 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4249 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4250 | return 0; |
| 4251 | pos += ret; |
| 4252 | } |
| 4253 | |
| 4254 | #ifdef CONFIG_WPS |
| 4255 | if (mask & WPA_BSS_MASK_WPS_SCAN) { |
| 4256 | ie = (const u8 *) (bss + 1); |
| 4257 | ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4258 | if (ret >= end - pos) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4259 | return 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4260 | if (ret > 0) |
| 4261 | pos += ret; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4262 | } |
| 4263 | #endif /* CONFIG_WPS */ |
| 4264 | |
| 4265 | #ifdef CONFIG_P2P |
| 4266 | if (mask & WPA_BSS_MASK_P2P_SCAN) { |
| 4267 | ie = (const u8 *) (bss + 1); |
| 4268 | ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 4269 | if (ret >= end - pos) |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4270 | return 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 4271 | if (ret > 0) |
| 4272 | pos += ret; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4273 | } |
| 4274 | #endif /* CONFIG_P2P */ |
| 4275 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4276 | #ifdef CONFIG_WIFI_DISPLAY |
| 4277 | if (mask & WPA_BSS_MASK_WIFI_DISPLAY) { |
| 4278 | struct wpabuf *wfd; |
| 4279 | ie = (const u8 *) (bss + 1); |
| 4280 | wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len, |
| 4281 | WFD_IE_VENDOR_TYPE); |
| 4282 | if (wfd) { |
| 4283 | ret = os_snprintf(pos, end - pos, "wfd_subelems="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4284 | if (os_snprintf_error(end - pos, ret)) { |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4285 | wpabuf_free(wfd); |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 4286 | return 0; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4287 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4288 | pos += ret; |
| 4289 | |
| 4290 | pos += wpa_snprintf_hex(pos, end - pos, |
| 4291 | wpabuf_head(wfd), |
| 4292 | wpabuf_len(wfd)); |
| 4293 | wpabuf_free(wfd); |
| 4294 | |
| 4295 | ret = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4296 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 4297 | return 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4298 | pos += ret; |
| 4299 | } |
| 4300 | } |
| 4301 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 4302 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4303 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 4304 | if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) { |
| 4305 | struct wpa_bss_anqp *anqp = bss->anqp; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4306 | struct wpa_bss_anqp_elem *elem; |
| 4307 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4308 | pos = anqp_add_hex(pos, end, "anqp_capability_list", |
| 4309 | anqp->capability_list); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4310 | pos = anqp_add_hex(pos, end, "anqp_venue_name", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 4311 | anqp->venue_name); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4312 | pos = anqp_add_hex(pos, end, "anqp_network_auth_type", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 4313 | anqp->network_auth_type); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4314 | pos = anqp_add_hex(pos, end, "anqp_roaming_consortium", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 4315 | anqp->roaming_consortium); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4316 | pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 4317 | anqp->ip_addr_type_availability); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4318 | pos = anqp_add_hex(pos, end, "anqp_nai_realm", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 4319 | anqp->nai_realm); |
| 4320 | pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4321 | pos = anqp_add_hex(pos, end, "anqp_domain_name", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 4322 | anqp->domain_name); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4323 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4324 | pos = anqp_add_hex(pos, end, "hs20_capability_list", |
| 4325 | anqp->hs20_capability_list); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4326 | pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 4327 | anqp->hs20_operator_friendly_name); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4328 | pos = anqp_add_hex(pos, end, "hs20_wan_metrics", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 4329 | anqp->hs20_wan_metrics); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4330 | pos = anqp_add_hex(pos, end, "hs20_connection_capability", |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 4331 | anqp->hs20_connection_capability); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4332 | pos = anqp_add_hex(pos, end, "hs20_operating_class", |
| 4333 | anqp->hs20_operating_class); |
| 4334 | pos = anqp_add_hex(pos, end, "hs20_osu_providers_list", |
| 4335 | anqp->hs20_osu_providers_list); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4336 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4337 | |
| 4338 | dl_list_for_each(elem, &anqp->anqp_elems, |
| 4339 | struct wpa_bss_anqp_elem, list) { |
| 4340 | char title[20]; |
| 4341 | |
| 4342 | os_snprintf(title, sizeof(title), "anqp[%u]", |
| 4343 | elem->infoid); |
| 4344 | pos = anqp_add_hex(pos, end, title, elem->payload); |
| 4345 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4346 | } |
| 4347 | #endif /* CONFIG_INTERWORKING */ |
| 4348 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4349 | #ifdef CONFIG_MESH |
| 4350 | if (mask & WPA_BSS_MASK_MESH_SCAN) { |
| 4351 | ie = (const u8 *) (bss + 1); |
| 4352 | ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 4353 | if (ret >= end - pos) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4354 | return 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 4355 | if (ret > 0) |
| 4356 | pos += ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4357 | } |
| 4358 | #endif /* CONFIG_MESH */ |
| 4359 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4360 | if (mask & WPA_BSS_MASK_SNR) { |
| 4361 | ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr); |
| 4362 | if (os_snprintf_error(end - pos, ret)) |
| 4363 | return 0; |
| 4364 | pos += ret; |
| 4365 | } |
| 4366 | |
| 4367 | if (mask & WPA_BSS_MASK_EST_THROUGHPUT) { |
| 4368 | ret = os_snprintf(pos, end - pos, "est_throughput=%d\n", |
| 4369 | bss->est_throughput); |
| 4370 | if (os_snprintf_error(end - pos, ret)) |
| 4371 | return 0; |
| 4372 | pos += ret; |
| 4373 | } |
| 4374 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4375 | #ifdef CONFIG_FST |
| 4376 | if (mask & WPA_BSS_MASK_FST) { |
| 4377 | ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos); |
| 4378 | if (ret < 0 || ret >= end - pos) |
| 4379 | return 0; |
| 4380 | pos += ret; |
| 4381 | } |
| 4382 | #endif /* CONFIG_FST */ |
| 4383 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 4384 | if (mask & WPA_BSS_MASK_DELIM) { |
| 4385 | ret = os_snprintf(pos, end - pos, "====\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4386 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 4387 | return 0; |
| 4388 | pos += ret; |
| 4389 | } |
Irfan Sheriff | e2ea008 | 2012-08-13 10:56:16 -0700 | [diff] [blame] | 4390 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4391 | return pos - buf; |
| 4392 | } |
| 4393 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4394 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4395 | static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s, |
| 4396 | const char *cmd, char *buf, |
| 4397 | size_t buflen) |
| 4398 | { |
| 4399 | u8 bssid[ETH_ALEN]; |
| 4400 | size_t i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4401 | struct wpa_bss *bss; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4402 | struct wpa_bss *bsslast = NULL; |
| 4403 | struct dl_list *next; |
| 4404 | int ret = 0; |
| 4405 | int len; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4406 | char *ctmp, *end = buf + buflen; |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4407 | unsigned long mask = WPA_BSS_MASK_ALL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4408 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4409 | if (os_strncmp(cmd, "RANGE=", 6) == 0) { |
| 4410 | if (os_strncmp(cmd + 6, "ALL", 3) == 0) { |
| 4411 | bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4412 | list_id); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4413 | bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss, |
| 4414 | list_id); |
| 4415 | } else { /* N1-N2 */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4416 | unsigned int id1, id2; |
| 4417 | |
| 4418 | if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) { |
| 4419 | wpa_printf(MSG_INFO, "Wrong BSS range " |
| 4420 | "format"); |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4421 | return 0; |
| 4422 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4423 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4424 | if (*(cmd + 6) == '-') |
| 4425 | id1 = 0; |
| 4426 | else |
| 4427 | id1 = atoi(cmd + 6); |
| 4428 | ctmp++; |
| 4429 | if (*ctmp >= '0' && *ctmp <= '9') |
| 4430 | id2 = atoi(ctmp); |
| 4431 | else |
| 4432 | id2 = (unsigned int) -1; |
| 4433 | bss = wpa_bss_get_id_range(wpa_s, id1, id2); |
| 4434 | if (id2 == (unsigned int) -1) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4435 | bsslast = dl_list_last(&wpa_s->bss_id, |
| 4436 | struct wpa_bss, |
| 4437 | list_id); |
| 4438 | else { |
| 4439 | bsslast = wpa_bss_get_id(wpa_s, id2); |
| 4440 | if (bsslast == NULL && bss && id2 > id1) { |
| 4441 | struct wpa_bss *tmp = bss; |
| 4442 | for (;;) { |
| 4443 | next = tmp->list_id.next; |
| 4444 | if (next == &wpa_s->bss_id) |
| 4445 | break; |
| 4446 | tmp = dl_list_entry( |
| 4447 | next, struct wpa_bss, |
| 4448 | list_id); |
| 4449 | if (tmp->id > id2) |
| 4450 | break; |
| 4451 | bsslast = tmp; |
| 4452 | } |
| 4453 | } |
| 4454 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4455 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4456 | } else if (os_strncmp(cmd, "FIRST", 5) == 0) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4457 | 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] | 4458 | else if (os_strncmp(cmd, "LAST", 4) == 0) |
| 4459 | 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] | 4460 | else if (os_strncmp(cmd, "ID-", 3) == 0) { |
| 4461 | i = atoi(cmd + 3); |
| 4462 | bss = wpa_bss_get_id(wpa_s, i); |
| 4463 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { |
| 4464 | i = atoi(cmd + 5); |
| 4465 | bss = wpa_bss_get_id(wpa_s, i); |
| 4466 | if (bss) { |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4467 | next = bss->list_id.next; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4468 | if (next == &wpa_s->bss_id) |
| 4469 | bss = NULL; |
| 4470 | else |
| 4471 | bss = dl_list_entry(next, struct wpa_bss, |
| 4472 | list_id); |
| 4473 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4474 | #ifdef CONFIG_P2P |
| 4475 | } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { |
| 4476 | if (hwaddr_aton(cmd + 13, bssid) == 0) |
| 4477 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid); |
| 4478 | else |
| 4479 | bss = NULL; |
| 4480 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4481 | } else if (hwaddr_aton(cmd, bssid) == 0) |
| 4482 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 4483 | else { |
| 4484 | struct wpa_bss *tmp; |
| 4485 | i = atoi(cmd); |
| 4486 | bss = NULL; |
| 4487 | dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id) |
| 4488 | { |
| 4489 | if (i-- == 0) { |
| 4490 | bss = tmp; |
| 4491 | break; |
| 4492 | } |
| 4493 | } |
| 4494 | } |
| 4495 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4496 | if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) { |
| 4497 | mask = strtoul(ctmp + 5, NULL, 0x10); |
| 4498 | if (mask == 0) |
| 4499 | mask = WPA_BSS_MASK_ALL; |
| 4500 | } |
| 4501 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4502 | if (bss == NULL) |
| 4503 | return 0; |
| 4504 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4505 | if (bsslast == NULL) |
| 4506 | bsslast = bss; |
| 4507 | do { |
| 4508 | len = print_bss_info(wpa_s, bss, mask, buf, buflen); |
| 4509 | ret += len; |
| 4510 | buf += len; |
| 4511 | buflen -= len; |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 4512 | if (bss == bsslast) { |
| 4513 | if ((mask & WPA_BSS_MASK_DELIM) && len && |
| 4514 | (bss == dl_list_last(&wpa_s->bss_id, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4515 | struct wpa_bss, list_id))) { |
| 4516 | int res; |
| 4517 | |
| 4518 | res = os_snprintf(buf - 5, end - buf + 5, |
| 4519 | "####\n"); |
| 4520 | if (os_snprintf_error(end - buf + 5, res)) { |
| 4521 | wpa_printf(MSG_DEBUG, |
| 4522 | "Could not add end delim"); |
| 4523 | } |
| 4524 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4525 | break; |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 4526 | } |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4527 | next = bss->list_id.next; |
| 4528 | if (next == &wpa_s->bss_id) |
| 4529 | break; |
| 4530 | bss = dl_list_entry(next, struct wpa_bss, list_id); |
| 4531 | } while (bss && len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4532 | |
Dmitry Shmidt | f2df2f2 | 2012-03-26 12:43:26 -0700 | [diff] [blame] | 4533 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4534 | } |
| 4535 | |
| 4536 | |
| 4537 | static int wpa_supplicant_ctrl_iface_ap_scan( |
| 4538 | struct wpa_supplicant *wpa_s, char *cmd) |
| 4539 | { |
| 4540 | int ap_scan = atoi(cmd); |
| 4541 | return wpa_supplicant_set_ap_scan(wpa_s, ap_scan); |
| 4542 | } |
| 4543 | |
| 4544 | |
| 4545 | static int wpa_supplicant_ctrl_iface_scan_interval( |
| 4546 | struct wpa_supplicant *wpa_s, char *cmd) |
| 4547 | { |
| 4548 | int scan_int = atoi(cmd); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4549 | return wpa_supplicant_set_scan_interval(wpa_s, scan_int); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | |
| 4553 | static int wpa_supplicant_ctrl_iface_bss_expire_age( |
| 4554 | struct wpa_supplicant *wpa_s, char *cmd) |
| 4555 | { |
| 4556 | int expire_age = atoi(cmd); |
| 4557 | return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age); |
| 4558 | } |
| 4559 | |
| 4560 | |
| 4561 | static int wpa_supplicant_ctrl_iface_bss_expire_count( |
| 4562 | struct wpa_supplicant *wpa_s, char *cmd) |
| 4563 | { |
| 4564 | int expire_count = atoi(cmd); |
| 4565 | return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count); |
| 4566 | } |
| 4567 | |
| 4568 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4569 | static void wpa_supplicant_ctrl_iface_bss_flush( |
Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 4570 | struct wpa_supplicant *wpa_s, char *cmd) |
| 4571 | { |
| 4572 | int flush_age = atoi(cmd); |
| 4573 | |
| 4574 | if (flush_age == 0) |
| 4575 | wpa_bss_flush(wpa_s); |
| 4576 | else |
| 4577 | wpa_bss_flush_by_age(wpa_s, flush_age); |
Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 4578 | } |
| 4579 | |
| 4580 | |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 4581 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4582 | static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s) |
| 4583 | { |
| 4584 | wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication"); |
| 4585 | /* MLME-DELETEKEYS.request */ |
| 4586 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0); |
| 4587 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0); |
| 4588 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0); |
| 4589 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0); |
| 4590 | #ifdef CONFIG_IEEE80211W |
| 4591 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0); |
| 4592 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0); |
| 4593 | #endif /* CONFIG_IEEE80211W */ |
| 4594 | |
| 4595 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL, |
| 4596 | 0); |
| 4597 | /* MLME-SETPROTECTION.request(None) */ |
| 4598 | wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid, |
| 4599 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, |
| 4600 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); |
| 4601 | wpa_sm_drop_sa(wpa_s->wpa); |
| 4602 | } |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 4603 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4604 | |
| 4605 | |
| 4606 | static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s, |
| 4607 | char *addr) |
| 4608 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4609 | #ifdef CONFIG_NO_SCAN_PROCESSING |
| 4610 | return -1; |
| 4611 | #else /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4612 | u8 bssid[ETH_ALEN]; |
| 4613 | struct wpa_bss *bss; |
| 4614 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 4615 | |
| 4616 | if (hwaddr_aton(addr, bssid)) { |
| 4617 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid " |
| 4618 | "address '%s'", addr); |
| 4619 | return -1; |
| 4620 | } |
| 4621 | |
| 4622 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid)); |
| 4623 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 4624 | if (!ssid) { |
| 4625 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network " |
| 4626 | "configuration known for the target AP"); |
| 4627 | return -1; |
| 4628 | } |
| 4629 | |
| 4630 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4631 | if (!bss) { |
| 4632 | wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found " |
| 4633 | "from BSS table"); |
| 4634 | return -1; |
| 4635 | } |
| 4636 | |
| 4637 | /* |
| 4638 | * TODO: Find best network configuration block from configuration to |
| 4639 | * allow roaming to other networks |
| 4640 | */ |
| 4641 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4642 | wpa_s->reassociate = 1; |
| 4643 | wpa_supplicant_connect(wpa_s, bss, ssid); |
| 4644 | |
| 4645 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4646 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | |
| 4650 | #ifdef CONFIG_P2P |
| 4651 | static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd) |
| 4652 | { |
| 4653 | unsigned int timeout = atoi(cmd); |
| 4654 | enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4655 | u8 dev_id[ETH_ALEN], *_dev_id = NULL; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4656 | u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4657 | char *pos; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4658 | unsigned int search_delay; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4659 | const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4660 | u8 seek_count = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4661 | int freq = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4662 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 4663 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 4664 | wpa_dbg(wpa_s, MSG_INFO, |
| 4665 | "Reject P2P_FIND since interface is disabled"); |
| 4666 | return -1; |
| 4667 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4668 | if (os_strstr(cmd, "type=social")) |
| 4669 | type = P2P_FIND_ONLY_SOCIAL; |
| 4670 | else if (os_strstr(cmd, "type=progressive")) |
| 4671 | type = P2P_FIND_PROGRESSIVE; |
| 4672 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4673 | pos = os_strstr(cmd, "dev_id="); |
| 4674 | if (pos) { |
| 4675 | pos += 7; |
| 4676 | if (hwaddr_aton(pos, dev_id)) |
| 4677 | return -1; |
| 4678 | _dev_id = dev_id; |
| 4679 | } |
| 4680 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4681 | pos = os_strstr(cmd, "dev_type="); |
| 4682 | if (pos) { |
| 4683 | pos += 9; |
| 4684 | if (wps_dev_type_str2bin(pos, dev_type) < 0) |
| 4685 | return -1; |
| 4686 | _dev_type = dev_type; |
| 4687 | } |
| 4688 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4689 | pos = os_strstr(cmd, "delay="); |
| 4690 | if (pos) { |
| 4691 | pos += 6; |
| 4692 | search_delay = atoi(pos); |
| 4693 | } else |
| 4694 | search_delay = wpas_p2p_search_delay(wpa_s); |
| 4695 | |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 4696 | pos = os_strstr(cmd, "freq="); |
| 4697 | if (pos) { |
| 4698 | pos += 5; |
| 4699 | freq = atoi(pos); |
| 4700 | if (freq <= 0) |
| 4701 | return -1; |
| 4702 | } |
| 4703 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4704 | /* Must be searched for last, because it adds nul termination */ |
| 4705 | pos = os_strstr(cmd, " seek="); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 4706 | if (pos) |
| 4707 | pos += 6; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4708 | while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) { |
| 4709 | char *term; |
| 4710 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 4711 | _seek[seek_count++] = pos; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4712 | seek = _seek; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 4713 | term = os_strchr(pos, ' '); |
| 4714 | if (!term) |
| 4715 | break; |
| 4716 | *term = '\0'; |
| 4717 | pos = os_strstr(term + 1, "seek="); |
| 4718 | if (pos) |
| 4719 | pos += 5; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4720 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4721 | if (seek_count > P2P_MAX_QUERY_HASH) { |
| 4722 | seek[0] = NULL; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4723 | seek_count = 1; |
| 4724 | } |
| 4725 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4726 | return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type, |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4727 | _dev_id, search_delay, seek_count, seek, freq); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4731 | static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt) |
| 4732 | { |
| 4733 | const char *last = NULL; |
| 4734 | const char *token; |
| 4735 | long int token_len; |
| 4736 | unsigned int i; |
| 4737 | |
| 4738 | /* Expected predefined CPT names delimited by ':' */ |
| 4739 | for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) { |
| 4740 | if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) { |
| 4741 | wpa_printf(MSG_ERROR, |
| 4742 | "P2PS: CPT name list is too long, expected up to %d names", |
| 4743 | P2PS_FEATURE_CAPAB_CPT_MAX); |
| 4744 | cpt[0] = 0; |
| 4745 | return -1; |
| 4746 | } |
| 4747 | |
| 4748 | token_len = last - token; |
| 4749 | |
| 4750 | if (token_len == 3 && |
| 4751 | os_memcmp(token, "UDP", token_len) == 0) { |
| 4752 | cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; |
| 4753 | } else if (token_len == 3 && |
| 4754 | os_memcmp(token, "MAC", token_len) == 0) { |
| 4755 | cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT; |
| 4756 | } else { |
| 4757 | wpa_printf(MSG_ERROR, |
| 4758 | "P2PS: Unsupported CPT name '%s'", token); |
| 4759 | cpt[0] = 0; |
| 4760 | return -1; |
| 4761 | } |
| 4762 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4763 | if (isblank((unsigned char) *last)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4764 | i++; |
| 4765 | break; |
| 4766 | } |
| 4767 | } |
| 4768 | cpt[i] = 0; |
| 4769 | return 0; |
| 4770 | } |
| 4771 | |
| 4772 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4773 | static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd) |
| 4774 | { |
| 4775 | struct p2ps_provision *p2ps_prov; |
| 4776 | char *pos; |
| 4777 | size_t info_len = 0; |
| 4778 | char *info = NULL; |
| 4779 | u8 role = P2PS_SETUP_NONE; |
| 4780 | long long unsigned val; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4781 | int i; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4782 | |
| 4783 | pos = os_strstr(cmd, "info="); |
| 4784 | if (pos) { |
| 4785 | pos += 5; |
| 4786 | info_len = os_strlen(pos); |
| 4787 | |
| 4788 | if (info_len) { |
| 4789 | info = os_malloc(info_len + 1); |
| 4790 | if (info) { |
| 4791 | info_len = utf8_unescape(pos, info_len, |
| 4792 | info, info_len + 1); |
| 4793 | } else |
| 4794 | info_len = 0; |
| 4795 | } |
| 4796 | } |
| 4797 | |
| 4798 | p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1); |
| 4799 | if (p2ps_prov == NULL) { |
| 4800 | os_free(info); |
| 4801 | return NULL; |
| 4802 | } |
| 4803 | |
| 4804 | if (info) { |
| 4805 | os_memcpy(p2ps_prov->info, info, info_len); |
| 4806 | p2ps_prov->info[info_len] = '\0'; |
| 4807 | os_free(info); |
| 4808 | } |
| 4809 | |
| 4810 | pos = os_strstr(cmd, "status="); |
| 4811 | if (pos) |
| 4812 | p2ps_prov->status = atoi(pos + 7); |
| 4813 | else |
| 4814 | p2ps_prov->status = -1; |
| 4815 | |
| 4816 | pos = os_strstr(cmd, "adv_id="); |
| 4817 | if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL) |
| 4818 | goto invalid_args; |
| 4819 | p2ps_prov->adv_id = val; |
| 4820 | |
| 4821 | pos = os_strstr(cmd, "method="); |
| 4822 | if (pos) |
| 4823 | p2ps_prov->method = strtol(pos + 7, NULL, 16); |
| 4824 | else |
| 4825 | p2ps_prov->method = 0; |
| 4826 | |
| 4827 | pos = os_strstr(cmd, "session="); |
| 4828 | if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL) |
| 4829 | goto invalid_args; |
| 4830 | p2ps_prov->session_id = val; |
| 4831 | |
| 4832 | pos = os_strstr(cmd, "adv_mac="); |
| 4833 | if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac)) |
| 4834 | goto invalid_args; |
| 4835 | |
| 4836 | pos = os_strstr(cmd, "session_mac="); |
| 4837 | if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac)) |
| 4838 | goto invalid_args; |
| 4839 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4840 | pos = os_strstr(cmd, "cpt="); |
| 4841 | if (pos) { |
| 4842 | if (p2ps_ctrl_parse_cpt_priority(pos + 4, |
| 4843 | p2ps_prov->cpt_priority)) |
| 4844 | goto invalid_args; |
| 4845 | } else { |
| 4846 | p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; |
| 4847 | } |
| 4848 | |
| 4849 | for (i = 0; p2ps_prov->cpt_priority[i]; i++) |
| 4850 | p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i]; |
| 4851 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4852 | /* force conncap with tstCap (no sanity checks) */ |
| 4853 | pos = os_strstr(cmd, "tstCap="); |
| 4854 | if (pos) { |
| 4855 | role = strtol(pos + 7, NULL, 16); |
| 4856 | } else { |
| 4857 | pos = os_strstr(cmd, "role="); |
| 4858 | if (pos) { |
| 4859 | role = strtol(pos + 5, NULL, 16); |
| 4860 | if (role != P2PS_SETUP_CLIENT && |
| 4861 | role != P2PS_SETUP_GROUP_OWNER) |
| 4862 | role = P2PS_SETUP_NONE; |
| 4863 | } |
| 4864 | } |
| 4865 | p2ps_prov->role = role; |
| 4866 | |
| 4867 | return p2ps_prov; |
| 4868 | |
| 4869 | invalid_args: |
| 4870 | os_free(p2ps_prov); |
| 4871 | return NULL; |
| 4872 | } |
| 4873 | |
| 4874 | |
| 4875 | static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd) |
| 4876 | { |
| 4877 | u8 addr[ETH_ALEN]; |
| 4878 | struct p2ps_provision *p2ps_prov; |
| 4879 | char *pos; |
| 4880 | |
| 4881 | /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */ |
| 4882 | |
| 4883 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); |
| 4884 | |
| 4885 | if (hwaddr_aton(cmd, addr)) |
| 4886 | return -1; |
| 4887 | |
| 4888 | pos = cmd + 17; |
| 4889 | if (*pos != ' ') |
| 4890 | return -1; |
| 4891 | |
| 4892 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); |
| 4893 | if (!p2ps_prov) |
| 4894 | return -1; |
| 4895 | |
| 4896 | if (p2ps_prov->status < 0) { |
| 4897 | os_free(p2ps_prov); |
| 4898 | return -1; |
| 4899 | } |
| 4900 | |
| 4901 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, |
| 4902 | p2ps_prov); |
| 4903 | } |
| 4904 | |
| 4905 | |
| 4906 | static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd) |
| 4907 | { |
| 4908 | u8 addr[ETH_ALEN]; |
| 4909 | struct p2ps_provision *p2ps_prov; |
| 4910 | char *pos; |
| 4911 | |
| 4912 | /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap> |
| 4913 | * session=<ses_id> mac=<ses_mac> [info=<infodata>] |
| 4914 | */ |
| 4915 | |
| 4916 | wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); |
| 4917 | if (hwaddr_aton(cmd, addr)) |
| 4918 | return -1; |
| 4919 | |
| 4920 | pos = cmd + 17; |
| 4921 | if (*pos != ' ') |
| 4922 | return -1; |
| 4923 | |
| 4924 | p2ps_prov = p2p_parse_asp_provision_cmd(pos); |
| 4925 | if (!p2ps_prov) |
| 4926 | return -1; |
| 4927 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4928 | p2ps_prov->pd_seeker = 1; |
| 4929 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4930 | return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP, |
| 4931 | p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4935 | static int parse_freq(int chwidth, int freq2) |
| 4936 | { |
| 4937 | if (freq2 < 0) |
| 4938 | return -1; |
| 4939 | if (freq2) |
| 4940 | return VHT_CHANWIDTH_80P80MHZ; |
| 4941 | |
| 4942 | switch (chwidth) { |
| 4943 | case 0: |
| 4944 | case 20: |
| 4945 | case 40: |
| 4946 | return VHT_CHANWIDTH_USE_HT; |
| 4947 | case 80: |
| 4948 | return VHT_CHANWIDTH_80MHZ; |
| 4949 | case 160: |
| 4950 | return VHT_CHANWIDTH_160MHZ; |
| 4951 | default: |
| 4952 | wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d", |
| 4953 | chwidth); |
| 4954 | return -1; |
| 4955 | } |
| 4956 | } |
| 4957 | |
| 4958 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4959 | static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd, |
| 4960 | char *buf, size_t buflen) |
| 4961 | { |
| 4962 | u8 addr[ETH_ALEN]; |
| 4963 | char *pos, *pos2; |
| 4964 | char *pin = NULL; |
| 4965 | enum p2p_wps_method wps_method; |
| 4966 | int new_pin; |
| 4967 | int ret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4968 | int persistent_group, persistent_id = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4969 | int join; |
| 4970 | int auth; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4971 | int automatic; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4972 | int go_intent = -1; |
| 4973 | int freq = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4974 | int pd; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4975 | int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0; |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4976 | u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL; |
| 4977 | size_t group_ssid_len = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4978 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4979 | if (!wpa_s->global->p2p_init_wpa_s) |
| 4980 | return -1; |
| 4981 | if (wpa_s->global->p2p_init_wpa_s != wpa_s) { |
| 4982 | wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s", |
| 4983 | wpa_s->global->p2p_init_wpa_s->ifname); |
| 4984 | wpa_s = wpa_s->global->p2p_init_wpa_s; |
| 4985 | } |
| 4986 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4987 | /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps] |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4988 | * [persistent|persistent=<network id>] |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4989 | * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4990 | * [ht40] [vht] [auto] [ssid=<hexdump>] */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4991 | |
| 4992 | if (hwaddr_aton(cmd, addr)) |
| 4993 | return -1; |
| 4994 | |
| 4995 | pos = cmd + 17; |
| 4996 | if (*pos != ' ') |
| 4997 | return -1; |
| 4998 | pos++; |
| 4999 | |
| 5000 | persistent_group = os_strstr(pos, " persistent") != NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5001 | pos2 = os_strstr(pos, " persistent="); |
| 5002 | if (pos2) { |
| 5003 | struct wpa_ssid *ssid; |
| 5004 | persistent_id = atoi(pos2 + 12); |
| 5005 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); |
| 5006 | if (ssid == NULL || ssid->disabled != 2 || |
| 5007 | ssid->mode != WPAS_MODE_P2P_GO) { |
| 5008 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| 5009 | "SSID id=%d for persistent P2P group (GO)", |
| 5010 | persistent_id); |
| 5011 | return -1; |
| 5012 | } |
| 5013 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5014 | join = os_strstr(pos, " join") != NULL; |
| 5015 | auth = os_strstr(pos, " auth") != NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5016 | automatic = os_strstr(pos, " auto") != NULL; |
| 5017 | pd = os_strstr(pos, " provdisc") != NULL; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5018 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
| 5019 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || |
| 5020 | vht; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5021 | |
| 5022 | pos2 = os_strstr(pos, " go_intent="); |
| 5023 | if (pos2) { |
| 5024 | pos2 += 11; |
| 5025 | go_intent = atoi(pos2); |
| 5026 | if (go_intent < 0 || go_intent > 15) |
| 5027 | return -1; |
| 5028 | } |
| 5029 | |
| 5030 | pos2 = os_strstr(pos, " freq="); |
| 5031 | if (pos2) { |
| 5032 | pos2 += 6; |
| 5033 | freq = atoi(pos2); |
| 5034 | if (freq <= 0) |
| 5035 | return -1; |
| 5036 | } |
| 5037 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5038 | pos2 = os_strstr(pos, " freq2="); |
| 5039 | if (pos2) |
| 5040 | freq2 = atoi(pos2 + 7); |
| 5041 | |
| 5042 | pos2 = os_strstr(pos, " max_oper_chwidth="); |
| 5043 | if (pos2) |
| 5044 | chwidth = atoi(pos2 + 18); |
| 5045 | |
| 5046 | max_oper_chwidth = parse_freq(chwidth, freq2); |
| 5047 | if (max_oper_chwidth < 0) |
| 5048 | return -1; |
| 5049 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5050 | pos2 = os_strstr(pos, " ssid="); |
| 5051 | if (pos2) { |
| 5052 | char *end; |
| 5053 | |
| 5054 | pos2 += 6; |
| 5055 | end = os_strchr(pos2, ' '); |
| 5056 | if (!end) |
| 5057 | group_ssid_len = os_strlen(pos2) / 2; |
| 5058 | else |
| 5059 | group_ssid_len = (end - pos2) / 2; |
| 5060 | if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN || |
| 5061 | hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0) |
| 5062 | return -1; |
| 5063 | group_ssid = _group_ssid; |
| 5064 | } |
| 5065 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5066 | if (os_strncmp(pos, "pin", 3) == 0) { |
| 5067 | /* Request random PIN (to be displayed) and enable the PIN */ |
| 5068 | wps_method = WPS_PIN_DISPLAY; |
| 5069 | } else if (os_strncmp(pos, "pbc", 3) == 0) { |
| 5070 | wps_method = WPS_PBC; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5071 | } else if (os_strstr(pos, "p2ps") != NULL) { |
| 5072 | wps_method = WPS_P2PS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5073 | } else { |
| 5074 | pin = pos; |
| 5075 | pos = os_strchr(pin, ' '); |
| 5076 | wps_method = WPS_PIN_KEYPAD; |
| 5077 | if (pos) { |
| 5078 | *pos++ = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5079 | if (os_strncmp(pos, "display", 7) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5080 | wps_method = WPS_PIN_DISPLAY; |
| 5081 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5082 | if (!wps_pin_str_valid(pin)) { |
| 5083 | os_memcpy(buf, "FAIL-INVALID-PIN\n", 17); |
| 5084 | return 17; |
| 5085 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5086 | } |
| 5087 | |
| 5088 | new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5089 | persistent_group, automatic, join, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5090 | auth, go_intent, freq, freq2, persistent_id, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5091 | pd, ht40, vht, max_oper_chwidth, |
| 5092 | group_ssid, group_ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5093 | if (new_pin == -2) { |
| 5094 | os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25); |
| 5095 | return 25; |
| 5096 | } |
| 5097 | if (new_pin == -3) { |
| 5098 | os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25); |
| 5099 | return 25; |
| 5100 | } |
| 5101 | if (new_pin < 0) |
| 5102 | return -1; |
| 5103 | if (wps_method == WPS_PIN_DISPLAY && pin == NULL) { |
| 5104 | ret = os_snprintf(buf, buflen, "%08d", new_pin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5105 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5106 | return -1; |
| 5107 | return ret; |
| 5108 | } |
| 5109 | |
| 5110 | os_memcpy(buf, "OK\n", 3); |
| 5111 | return 3; |
| 5112 | } |
| 5113 | |
| 5114 | |
| 5115 | static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd) |
| 5116 | { |
| 5117 | unsigned int timeout = atoi(cmd); |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 5118 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 5119 | wpa_dbg(wpa_s, MSG_INFO, |
| 5120 | "Reject P2P_LISTEN since interface is disabled"); |
| 5121 | return -1; |
| 5122 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5123 | return wpas_p2p_listen(wpa_s, timeout); |
| 5124 | } |
| 5125 | |
| 5126 | |
| 5127 | static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd) |
| 5128 | { |
| 5129 | u8 addr[ETH_ALEN]; |
| 5130 | char *pos; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5131 | 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] | 5132 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5133 | /* <addr> <config method> [join|auto] */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5134 | |
| 5135 | if (hwaddr_aton(cmd, addr)) |
| 5136 | return -1; |
| 5137 | |
| 5138 | pos = cmd + 17; |
| 5139 | if (*pos != ' ') |
| 5140 | return -1; |
| 5141 | pos++; |
| 5142 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5143 | if (os_strstr(pos, " join") != NULL) |
| 5144 | use = WPAS_P2P_PD_FOR_JOIN; |
| 5145 | else if (os_strstr(pos, " auto") != NULL) |
| 5146 | use = WPAS_P2P_PD_AUTO; |
| 5147 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5148 | return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5149 | } |
| 5150 | |
| 5151 | |
| 5152 | static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf, |
| 5153 | size_t buflen) |
| 5154 | { |
| 5155 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 5156 | |
| 5157 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 5158 | ssid->passphrase == NULL) |
| 5159 | return -1; |
| 5160 | |
| 5161 | os_strlcpy(buf, ssid->passphrase, buflen); |
| 5162 | return os_strlen(buf); |
| 5163 | } |
| 5164 | |
| 5165 | |
| 5166 | static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd, |
| 5167 | char *buf, size_t buflen) |
| 5168 | { |
| 5169 | u64 ref; |
| 5170 | int res; |
| 5171 | u8 dst_buf[ETH_ALEN], *dst; |
| 5172 | struct wpabuf *tlvs; |
| 5173 | char *pos; |
| 5174 | size_t len; |
| 5175 | |
| 5176 | if (hwaddr_aton(cmd, dst_buf)) |
| 5177 | return -1; |
| 5178 | dst = dst_buf; |
| 5179 | if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 && |
| 5180 | dst[3] == 0 && dst[4] == 0 && dst[5] == 0) |
| 5181 | dst = NULL; |
| 5182 | pos = cmd + 17; |
| 5183 | if (*pos != ' ') |
| 5184 | return -1; |
| 5185 | pos++; |
| 5186 | |
| 5187 | if (os_strncmp(pos, "upnp ", 5) == 0) { |
| 5188 | u8 version; |
| 5189 | pos += 5; |
| 5190 | if (hexstr2bin(pos, &version, 1) < 0) |
| 5191 | return -1; |
| 5192 | pos += 2; |
| 5193 | if (*pos != ' ') |
| 5194 | return -1; |
| 5195 | pos++; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5196 | ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5197 | #ifdef CONFIG_WIFI_DISPLAY |
| 5198 | } else if (os_strncmp(pos, "wifi-display ", 13) == 0) { |
| 5199 | ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13); |
| 5200 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5201 | } else if (os_strncmp(pos, "asp ", 4) == 0) { |
| 5202 | char *svc_str; |
| 5203 | char *svc_info = NULL; |
| 5204 | u32 id; |
| 5205 | |
| 5206 | pos += 4; |
| 5207 | if (sscanf(pos, "%x", &id) != 1 || id > 0xff) |
| 5208 | return -1; |
| 5209 | |
| 5210 | pos = os_strchr(pos, ' '); |
| 5211 | if (pos == NULL || pos[1] == '\0' || pos[1] == ' ') |
| 5212 | return -1; |
| 5213 | |
| 5214 | svc_str = pos + 1; |
| 5215 | |
| 5216 | pos = os_strchr(svc_str, ' '); |
| 5217 | |
| 5218 | if (pos) |
| 5219 | *pos++ = '\0'; |
| 5220 | |
| 5221 | /* All remaining data is the svc_info string */ |
| 5222 | if (pos && pos[0] && pos[0] != ' ') { |
| 5223 | len = os_strlen(pos); |
| 5224 | |
| 5225 | /* Unescape in place */ |
| 5226 | len = utf8_unescape(pos, len, pos, len); |
| 5227 | if (len > 0xff) |
| 5228 | return -1; |
| 5229 | |
| 5230 | svc_info = pos; |
| 5231 | } |
| 5232 | |
| 5233 | ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id, |
| 5234 | svc_str, svc_info); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5235 | } else { |
| 5236 | len = os_strlen(pos); |
| 5237 | if (len & 1) |
| 5238 | return -1; |
| 5239 | len /= 2; |
| 5240 | tlvs = wpabuf_alloc(len); |
| 5241 | if (tlvs == NULL) |
| 5242 | return -1; |
| 5243 | if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) { |
| 5244 | wpabuf_free(tlvs); |
| 5245 | return -1; |
| 5246 | } |
| 5247 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5248 | ref = wpas_p2p_sd_request(wpa_s, dst, tlvs); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5249 | wpabuf_free(tlvs); |
| 5250 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5251 | if (ref == 0) |
| 5252 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5253 | res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5254 | if (os_snprintf_error(buflen, res)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5255 | return -1; |
| 5256 | return res; |
| 5257 | } |
| 5258 | |
| 5259 | |
| 5260 | static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s, |
| 5261 | char *cmd) |
| 5262 | { |
| 5263 | long long unsigned val; |
| 5264 | u64 req; |
| 5265 | if (sscanf(cmd, "%llx", &val) != 1) |
| 5266 | return -1; |
| 5267 | req = val; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5268 | return wpas_p2p_sd_cancel_request(wpa_s, req); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5269 | } |
| 5270 | |
| 5271 | |
| 5272 | static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd) |
| 5273 | { |
| 5274 | int freq; |
| 5275 | u8 dst[ETH_ALEN]; |
| 5276 | u8 dialog_token; |
| 5277 | struct wpabuf *resp_tlvs; |
| 5278 | char *pos, *pos2; |
| 5279 | size_t len; |
| 5280 | |
| 5281 | pos = os_strchr(cmd, ' '); |
| 5282 | if (pos == NULL) |
| 5283 | return -1; |
| 5284 | *pos++ = '\0'; |
| 5285 | freq = atoi(cmd); |
| 5286 | if (freq == 0) |
| 5287 | return -1; |
| 5288 | |
| 5289 | if (hwaddr_aton(pos, dst)) |
| 5290 | return -1; |
| 5291 | pos += 17; |
| 5292 | if (*pos != ' ') |
| 5293 | return -1; |
| 5294 | pos++; |
| 5295 | |
| 5296 | pos2 = os_strchr(pos, ' '); |
| 5297 | if (pos2 == NULL) |
| 5298 | return -1; |
| 5299 | *pos2++ = '\0'; |
| 5300 | dialog_token = atoi(pos); |
| 5301 | |
| 5302 | len = os_strlen(pos2); |
| 5303 | if (len & 1) |
| 5304 | return -1; |
| 5305 | len /= 2; |
| 5306 | resp_tlvs = wpabuf_alloc(len); |
| 5307 | if (resp_tlvs == NULL) |
| 5308 | return -1; |
| 5309 | if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) { |
| 5310 | wpabuf_free(resp_tlvs); |
| 5311 | return -1; |
| 5312 | } |
| 5313 | |
| 5314 | wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs); |
| 5315 | wpabuf_free(resp_tlvs); |
| 5316 | return 0; |
| 5317 | } |
| 5318 | |
| 5319 | |
| 5320 | static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s, |
| 5321 | char *cmd) |
| 5322 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5323 | if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1")) |
| 5324 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5325 | wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd); |
| 5326 | return 0; |
| 5327 | } |
| 5328 | |
| 5329 | |
| 5330 | static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s, |
| 5331 | char *cmd) |
| 5332 | { |
| 5333 | char *pos; |
| 5334 | size_t len; |
| 5335 | struct wpabuf *query, *resp; |
| 5336 | |
| 5337 | pos = os_strchr(cmd, ' '); |
| 5338 | if (pos == NULL) |
| 5339 | return -1; |
| 5340 | *pos++ = '\0'; |
| 5341 | |
| 5342 | len = os_strlen(cmd); |
| 5343 | if (len & 1) |
| 5344 | return -1; |
| 5345 | len /= 2; |
| 5346 | query = wpabuf_alloc(len); |
| 5347 | if (query == NULL) |
| 5348 | return -1; |
| 5349 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { |
| 5350 | wpabuf_free(query); |
| 5351 | return -1; |
| 5352 | } |
| 5353 | |
| 5354 | len = os_strlen(pos); |
| 5355 | if (len & 1) { |
| 5356 | wpabuf_free(query); |
| 5357 | return -1; |
| 5358 | } |
| 5359 | len /= 2; |
| 5360 | resp = wpabuf_alloc(len); |
| 5361 | if (resp == NULL) { |
| 5362 | wpabuf_free(query); |
| 5363 | return -1; |
| 5364 | } |
| 5365 | if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) { |
| 5366 | wpabuf_free(query); |
| 5367 | wpabuf_free(resp); |
| 5368 | return -1; |
| 5369 | } |
| 5370 | |
| 5371 | if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) { |
| 5372 | wpabuf_free(query); |
| 5373 | wpabuf_free(resp); |
| 5374 | return -1; |
| 5375 | } |
| 5376 | return 0; |
| 5377 | } |
| 5378 | |
| 5379 | |
| 5380 | static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd) |
| 5381 | { |
| 5382 | char *pos; |
| 5383 | u8 version; |
| 5384 | |
| 5385 | pos = os_strchr(cmd, ' '); |
| 5386 | if (pos == NULL) |
| 5387 | return -1; |
| 5388 | *pos++ = '\0'; |
| 5389 | |
| 5390 | if (hexstr2bin(cmd, &version, 1) < 0) |
| 5391 | return -1; |
| 5392 | |
| 5393 | return wpas_p2p_service_add_upnp(wpa_s, version, pos); |
| 5394 | } |
| 5395 | |
| 5396 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5397 | static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s, |
| 5398 | u8 replace, char *cmd) |
| 5399 | { |
| 5400 | char *pos; |
| 5401 | char *adv_str; |
| 5402 | u32 auto_accept, adv_id, svc_state, config_methods; |
| 5403 | char *svc_info = NULL; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5404 | char *cpt_prio_str; |
| 5405 | u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1]; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5406 | |
| 5407 | pos = os_strchr(cmd, ' '); |
| 5408 | if (pos == NULL) |
| 5409 | return -1; |
| 5410 | *pos++ = '\0'; |
| 5411 | |
| 5412 | /* Auto-Accept value is mandatory, and must be one of the |
| 5413 | * single values (0, 1, 2, 4) */ |
| 5414 | auto_accept = atoi(cmd); |
| 5415 | switch (auto_accept) { |
| 5416 | case P2PS_SETUP_NONE: /* No auto-accept */ |
| 5417 | case P2PS_SETUP_NEW: |
| 5418 | case P2PS_SETUP_CLIENT: |
| 5419 | case P2PS_SETUP_GROUP_OWNER: |
| 5420 | break; |
| 5421 | default: |
| 5422 | return -1; |
| 5423 | } |
| 5424 | |
| 5425 | /* Advertisement ID is mandatory */ |
| 5426 | cmd = pos; |
| 5427 | pos = os_strchr(cmd, ' '); |
| 5428 | if (pos == NULL) |
| 5429 | return -1; |
| 5430 | *pos++ = '\0'; |
| 5431 | |
| 5432 | /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */ |
| 5433 | if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0) |
| 5434 | return -1; |
| 5435 | |
| 5436 | /* Only allow replacements if exist, and adds if not */ |
| 5437 | if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) { |
| 5438 | if (!replace) |
| 5439 | return -1; |
| 5440 | } else { |
| 5441 | if (replace) |
| 5442 | return -1; |
| 5443 | } |
| 5444 | |
| 5445 | /* svc_state between 0 - 0xff is mandatory */ |
| 5446 | if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff) |
| 5447 | return -1; |
| 5448 | |
| 5449 | pos = os_strchr(pos, ' '); |
| 5450 | if (pos == NULL) |
| 5451 | return -1; |
| 5452 | |
| 5453 | /* config_methods is mandatory */ |
| 5454 | pos++; |
| 5455 | if (sscanf(pos, "%x", &config_methods) != 1) |
| 5456 | return -1; |
| 5457 | |
| 5458 | if (!(config_methods & |
| 5459 | (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS))) |
| 5460 | return -1; |
| 5461 | |
| 5462 | pos = os_strchr(pos, ' '); |
| 5463 | if (pos == NULL) |
| 5464 | return -1; |
| 5465 | |
| 5466 | pos++; |
| 5467 | adv_str = pos; |
| 5468 | |
| 5469 | /* Advertisement string is mandatory */ |
| 5470 | if (!pos[0] || pos[0] == ' ') |
| 5471 | return -1; |
| 5472 | |
| 5473 | /* Terminate svc string */ |
| 5474 | pos = os_strchr(pos, ' '); |
| 5475 | if (pos != NULL) |
| 5476 | *pos++ = '\0'; |
| 5477 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5478 | cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL; |
| 5479 | if (cpt_prio_str) { |
| 5480 | pos = os_strchr(pos, ' '); |
| 5481 | if (pos != NULL) |
| 5482 | *pos++ = '\0'; |
| 5483 | |
| 5484 | if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio)) |
| 5485 | return -1; |
| 5486 | } else { |
| 5487 | cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT; |
| 5488 | cpt_prio[1] = 0; |
| 5489 | } |
| 5490 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5491 | /* Service and Response Information are optional */ |
| 5492 | if (pos && pos[0]) { |
| 5493 | size_t len; |
| 5494 | |
| 5495 | /* Note the bare ' included, which cannot exist legally |
| 5496 | * in unescaped string. */ |
| 5497 | svc_info = os_strstr(pos, "svc_info='"); |
| 5498 | |
| 5499 | if (svc_info) { |
| 5500 | svc_info += 9; |
| 5501 | len = os_strlen(svc_info); |
| 5502 | utf8_unescape(svc_info, len, svc_info, len); |
| 5503 | } |
| 5504 | } |
| 5505 | |
| 5506 | return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str, |
| 5507 | (u8) svc_state, (u16) config_methods, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5508 | svc_info, cpt_prio); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5509 | } |
| 5510 | |
| 5511 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5512 | static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd) |
| 5513 | { |
| 5514 | char *pos; |
| 5515 | |
| 5516 | pos = os_strchr(cmd, ' '); |
| 5517 | if (pos == NULL) |
| 5518 | return -1; |
| 5519 | *pos++ = '\0'; |
| 5520 | |
| 5521 | if (os_strcmp(cmd, "bonjour") == 0) |
| 5522 | return p2p_ctrl_service_add_bonjour(wpa_s, pos); |
| 5523 | if (os_strcmp(cmd, "upnp") == 0) |
| 5524 | return p2p_ctrl_service_add_upnp(wpa_s, pos); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5525 | if (os_strcmp(cmd, "asp") == 0) |
| 5526 | return p2p_ctrl_service_add_asp(wpa_s, 0, pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5527 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
| 5528 | return -1; |
| 5529 | } |
| 5530 | |
| 5531 | |
| 5532 | static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s, |
| 5533 | char *cmd) |
| 5534 | { |
| 5535 | size_t len; |
| 5536 | struct wpabuf *query; |
| 5537 | int ret; |
| 5538 | |
| 5539 | len = os_strlen(cmd); |
| 5540 | if (len & 1) |
| 5541 | return -1; |
| 5542 | len /= 2; |
| 5543 | query = wpabuf_alloc(len); |
| 5544 | if (query == NULL) |
| 5545 | return -1; |
| 5546 | if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) { |
| 5547 | wpabuf_free(query); |
| 5548 | return -1; |
| 5549 | } |
| 5550 | |
| 5551 | ret = wpas_p2p_service_del_bonjour(wpa_s, query); |
| 5552 | wpabuf_free(query); |
| 5553 | return ret; |
| 5554 | } |
| 5555 | |
| 5556 | |
| 5557 | static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd) |
| 5558 | { |
| 5559 | char *pos; |
| 5560 | u8 version; |
| 5561 | |
| 5562 | pos = os_strchr(cmd, ' '); |
| 5563 | if (pos == NULL) |
| 5564 | return -1; |
| 5565 | *pos++ = '\0'; |
| 5566 | |
| 5567 | if (hexstr2bin(cmd, &version, 1) < 0) |
| 5568 | return -1; |
| 5569 | |
| 5570 | return wpas_p2p_service_del_upnp(wpa_s, version, pos); |
| 5571 | } |
| 5572 | |
| 5573 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5574 | static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd) |
| 5575 | { |
| 5576 | u32 adv_id; |
| 5577 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 5578 | if (os_strcmp(cmd, "all") == 0) { |
| 5579 | wpas_p2p_service_flush_asp(wpa_s); |
| 5580 | return 0; |
| 5581 | } |
| 5582 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5583 | if (sscanf(cmd, "%x", &adv_id) != 1) |
| 5584 | return -1; |
| 5585 | |
| 5586 | return wpas_p2p_service_del_asp(wpa_s, adv_id); |
| 5587 | } |
| 5588 | |
| 5589 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5590 | static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd) |
| 5591 | { |
| 5592 | char *pos; |
| 5593 | |
| 5594 | pos = os_strchr(cmd, ' '); |
| 5595 | if (pos == NULL) |
| 5596 | return -1; |
| 5597 | *pos++ = '\0'; |
| 5598 | |
| 5599 | if (os_strcmp(cmd, "bonjour") == 0) |
| 5600 | return p2p_ctrl_service_del_bonjour(wpa_s, pos); |
| 5601 | if (os_strcmp(cmd, "upnp") == 0) |
| 5602 | return p2p_ctrl_service_del_upnp(wpa_s, pos); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5603 | if (os_strcmp(cmd, "asp") == 0) |
| 5604 | return p2p_ctrl_service_del_asp(wpa_s, pos); |
| 5605 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
| 5606 | return -1; |
| 5607 | } |
| 5608 | |
| 5609 | |
| 5610 | static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd) |
| 5611 | { |
| 5612 | char *pos; |
| 5613 | |
| 5614 | pos = os_strchr(cmd, ' '); |
| 5615 | if (pos == NULL) |
| 5616 | return -1; |
| 5617 | *pos++ = '\0'; |
| 5618 | |
| 5619 | if (os_strcmp(cmd, "asp") == 0) |
| 5620 | return p2p_ctrl_service_add_asp(wpa_s, 1, pos); |
| 5621 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5622 | wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd); |
| 5623 | return -1; |
| 5624 | } |
| 5625 | |
| 5626 | |
| 5627 | static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd) |
| 5628 | { |
| 5629 | u8 addr[ETH_ALEN]; |
| 5630 | |
| 5631 | /* <addr> */ |
| 5632 | |
| 5633 | if (hwaddr_aton(cmd, addr)) |
| 5634 | return -1; |
| 5635 | |
| 5636 | return wpas_p2p_reject(wpa_s, addr); |
| 5637 | } |
| 5638 | |
| 5639 | |
| 5640 | static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd) |
| 5641 | { |
| 5642 | char *pos; |
| 5643 | int id; |
| 5644 | struct wpa_ssid *ssid; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5645 | u8 *_peer = NULL, peer[ETH_ALEN]; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5646 | int freq = 0, pref_freq = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5647 | int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5648 | |
| 5649 | id = atoi(cmd); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5650 | pos = os_strstr(cmd, " peer="); |
| 5651 | if (pos) { |
| 5652 | pos += 6; |
| 5653 | if (hwaddr_aton(pos, peer)) |
| 5654 | return -1; |
| 5655 | _peer = peer; |
| 5656 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5657 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 5658 | if (ssid == NULL || ssid->disabled != 2) { |
| 5659 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 5660 | "for persistent P2P group", |
| 5661 | id); |
| 5662 | return -1; |
| 5663 | } |
| 5664 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 5665 | pos = os_strstr(cmd, " freq="); |
| 5666 | if (pos) { |
| 5667 | pos += 6; |
| 5668 | freq = atoi(pos); |
| 5669 | if (freq <= 0) |
| 5670 | return -1; |
| 5671 | } |
| 5672 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5673 | pos = os_strstr(cmd, " pref="); |
| 5674 | if (pos) { |
| 5675 | pos += 6; |
| 5676 | pref_freq = atoi(pos); |
| 5677 | if (pref_freq <= 0) |
| 5678 | return -1; |
| 5679 | } |
| 5680 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5681 | vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht; |
| 5682 | ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 || |
| 5683 | vht; |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 5684 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5685 | pos = os_strstr(cmd, "freq2="); |
| 5686 | if (pos) |
| 5687 | freq2 = atoi(pos + 6); |
| 5688 | |
| 5689 | pos = os_strstr(cmd, " max_oper_chwidth="); |
| 5690 | if (pos) |
| 5691 | chwidth = atoi(pos + 18); |
| 5692 | |
| 5693 | max_oper_chwidth = parse_freq(chwidth, freq2); |
| 5694 | if (max_oper_chwidth < 0) |
| 5695 | return -1; |
| 5696 | |
| 5697 | return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht, |
| 5698 | max_oper_chwidth, pref_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5699 | } |
| 5700 | |
| 5701 | |
| 5702 | static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd) |
| 5703 | { |
| 5704 | char *pos; |
| 5705 | u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL; |
| 5706 | |
| 5707 | pos = os_strstr(cmd, " peer="); |
| 5708 | if (!pos) |
| 5709 | return -1; |
| 5710 | |
| 5711 | *pos = '\0'; |
| 5712 | pos += 6; |
| 5713 | if (hwaddr_aton(pos, peer)) { |
| 5714 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos); |
| 5715 | return -1; |
| 5716 | } |
| 5717 | |
| 5718 | pos = os_strstr(pos, " go_dev_addr="); |
| 5719 | if (pos) { |
| 5720 | pos += 13; |
| 5721 | if (hwaddr_aton(pos, go_dev_addr)) { |
| 5722 | wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", |
| 5723 | pos); |
| 5724 | return -1; |
| 5725 | } |
| 5726 | go_dev = go_dev_addr; |
| 5727 | } |
| 5728 | |
| 5729 | return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev); |
| 5730 | } |
| 5731 | |
| 5732 | |
| 5733 | static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd) |
| 5734 | { |
| 5735 | if (os_strncmp(cmd, "persistent=", 11) == 0) |
| 5736 | return p2p_ctrl_invite_persistent(wpa_s, cmd + 11); |
| 5737 | if (os_strncmp(cmd, "group=", 6) == 0) |
| 5738 | return p2p_ctrl_invite_group(wpa_s, cmd + 6); |
| 5739 | |
| 5740 | return -1; |
| 5741 | } |
| 5742 | |
| 5743 | |
| 5744 | static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5745 | int id, int freq, int vht_center_freq2, |
| 5746 | int ht40, int vht, int vht_chwidth) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5747 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5748 | struct wpa_ssid *ssid; |
| 5749 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5750 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 5751 | if (ssid == NULL || ssid->disabled != 2) { |
| 5752 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| 5753 | "for persistent P2P group", |
| 5754 | id); |
| 5755 | return -1; |
| 5756 | } |
| 5757 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5758 | return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, |
| 5759 | vht_center_freq2, 0, ht40, vht, |
| 5760 | vht_chwidth, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5761 | } |
| 5762 | |
| 5763 | |
| 5764 | static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd) |
| 5765 | { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5766 | int freq = 0, persistent = 0, group_id = -1; |
| 5767 | int vht = wpa_s->conf->p2p_go_vht; |
| 5768 | int ht40 = wpa_s->conf->p2p_go_ht40 || vht; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5769 | int max_oper_chwidth, chwidth = 0, freq2 = 0; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5770 | char *token, *context = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5771 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5772 | while ((token = str_token(cmd, " ", &context))) { |
| 5773 | if (sscanf(token, "freq=%d", &freq) == 1 || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5774 | sscanf(token, "freq2=%d", &freq2) == 1 || |
| 5775 | sscanf(token, "persistent=%d", &group_id) == 1 || |
| 5776 | sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5777 | continue; |
| 5778 | } else if (os_strcmp(token, "ht40") == 0) { |
| 5779 | ht40 = 1; |
| 5780 | } else if (os_strcmp(token, "vht") == 0) { |
| 5781 | vht = 1; |
| 5782 | ht40 = 1; |
| 5783 | } else if (os_strcmp(token, "persistent") == 0) { |
| 5784 | persistent = 1; |
| 5785 | } else { |
| 5786 | wpa_printf(MSG_DEBUG, |
| 5787 | "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'", |
| 5788 | token); |
| 5789 | return -1; |
| 5790 | } |
| 5791 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5792 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5793 | max_oper_chwidth = parse_freq(chwidth, freq2); |
| 5794 | if (max_oper_chwidth < 0) |
| 5795 | return -1; |
| 5796 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5797 | if (group_id >= 0) |
| 5798 | return p2p_ctrl_group_add_persistent(wpa_s, group_id, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5799 | freq, freq2, ht40, vht, |
| 5800 | max_oper_chwidth); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5801 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5802 | return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht, |
| 5803 | max_oper_chwidth); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5804 | } |
| 5805 | |
| 5806 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5807 | static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd, |
| 5808 | char *buf, size_t buflen) |
| 5809 | { |
| 5810 | u8 dev_addr[ETH_ALEN]; |
| 5811 | struct wpa_ssid *ssid; |
| 5812 | int res; |
| 5813 | const u8 *iaddr; |
| 5814 | |
| 5815 | ssid = wpa_s->current_ssid; |
| 5816 | if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO || |
| 5817 | hwaddr_aton(cmd, dev_addr)) |
| 5818 | return -1; |
| 5819 | |
| 5820 | iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr); |
| 5821 | if (!iaddr) |
| 5822 | return -1; |
| 5823 | res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr)); |
| 5824 | if (os_snprintf_error(buflen, res)) |
| 5825 | return -1; |
| 5826 | return res; |
| 5827 | } |
| 5828 | |
| 5829 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5830 | static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd, |
| 5831 | char *buf, size_t buflen) |
| 5832 | { |
| 5833 | u8 addr[ETH_ALEN], *addr_ptr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5834 | int next, res; |
| 5835 | const struct p2p_peer_info *info; |
| 5836 | char *pos, *end; |
| 5837 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
| 5838 | struct wpa_ssid *ssid; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5839 | size_t i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5840 | |
| 5841 | if (!wpa_s->global->p2p) |
| 5842 | return -1; |
| 5843 | |
| 5844 | if (os_strcmp(cmd, "FIRST") == 0) { |
| 5845 | addr_ptr = NULL; |
| 5846 | next = 0; |
| 5847 | } else if (os_strncmp(cmd, "NEXT-", 5) == 0) { |
| 5848 | if (hwaddr_aton(cmd + 5, addr) < 0) |
| 5849 | return -1; |
| 5850 | addr_ptr = addr; |
| 5851 | next = 1; |
| 5852 | } else { |
| 5853 | if (hwaddr_aton(cmd, addr) < 0) |
| 5854 | return -1; |
| 5855 | addr_ptr = addr; |
| 5856 | next = 0; |
| 5857 | } |
| 5858 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5859 | info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next); |
| 5860 | if (info == NULL) |
| 5861 | return -1; |
| 5862 | |
| 5863 | pos = buf; |
| 5864 | end = buf + buflen; |
| 5865 | |
| 5866 | res = os_snprintf(pos, end - pos, MACSTR "\n" |
| 5867 | "pri_dev_type=%s\n" |
| 5868 | "device_name=%s\n" |
| 5869 | "manufacturer=%s\n" |
| 5870 | "model_name=%s\n" |
| 5871 | "model_number=%s\n" |
| 5872 | "serial_number=%s\n" |
| 5873 | "config_methods=0x%x\n" |
| 5874 | "dev_capab=0x%x\n" |
| 5875 | "group_capab=0x%x\n" |
| 5876 | "level=%d\n", |
| 5877 | MAC2STR(info->p2p_device_addr), |
| 5878 | wps_dev_type_bin2str(info->pri_dev_type, |
| 5879 | devtype, sizeof(devtype)), |
| 5880 | info->device_name, |
| 5881 | info->manufacturer, |
| 5882 | info->model_name, |
| 5883 | info->model_number, |
| 5884 | info->serial_number, |
| 5885 | info->config_methods, |
| 5886 | info->dev_capab, |
| 5887 | info->group_capab, |
| 5888 | info->level); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5889 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5890 | return pos - buf; |
| 5891 | pos += res; |
| 5892 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5893 | for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++) |
| 5894 | { |
| 5895 | const u8 *t; |
| 5896 | t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN]; |
| 5897 | res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n", |
| 5898 | wps_dev_type_bin2str(t, devtype, |
| 5899 | sizeof(devtype))); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5900 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5901 | return pos - buf; |
| 5902 | pos += res; |
| 5903 | } |
| 5904 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5905 | 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] | 5906 | if (ssid) { |
| 5907 | res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5908 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5909 | return pos - buf; |
| 5910 | pos += res; |
| 5911 | } |
| 5912 | |
| 5913 | res = p2p_get_peer_info_txt(info, pos, end - pos); |
| 5914 | if (res < 0) |
| 5915 | return pos - buf; |
| 5916 | pos += res; |
| 5917 | |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 5918 | if (info->vendor_elems) { |
| 5919 | res = os_snprintf(pos, end - pos, "vendor_elems="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5920 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 5921 | return pos - buf; |
| 5922 | pos += res; |
| 5923 | |
| 5924 | pos += wpa_snprintf_hex(pos, end - pos, |
| 5925 | wpabuf_head(info->vendor_elems), |
| 5926 | wpabuf_len(info->vendor_elems)); |
| 5927 | |
| 5928 | res = os_snprintf(pos, end - pos, "\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5929 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 5930 | return pos - buf; |
| 5931 | pos += res; |
| 5932 | } |
| 5933 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5934 | return pos - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5935 | } |
| 5936 | |
| 5937 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5938 | static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s, |
| 5939 | const char *param) |
| 5940 | { |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 5941 | unsigned int i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5942 | |
| 5943 | if (wpa_s->global->p2p == NULL) |
| 5944 | return -1; |
| 5945 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 5946 | if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0) |
| 5947 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5948 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 5949 | for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) { |
| 5950 | struct wpa_freq_range *freq; |
| 5951 | freq = &wpa_s->global->p2p_disallow_freq.range[i]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5952 | wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u", |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 5953 | freq->min, freq->max); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5954 | } |
| 5955 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5956 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5957 | return 0; |
| 5958 | } |
| 5959 | |
| 5960 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5961 | static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) |
| 5962 | { |
| 5963 | char *param; |
| 5964 | |
| 5965 | if (wpa_s->global->p2p == NULL) |
| 5966 | return -1; |
| 5967 | |
| 5968 | param = os_strchr(cmd, ' '); |
| 5969 | if (param == NULL) |
| 5970 | return -1; |
| 5971 | *param++ = '\0'; |
| 5972 | |
| 5973 | if (os_strcmp(cmd, "discoverability") == 0) { |
| 5974 | p2p_set_client_discoverability(wpa_s->global->p2p, |
| 5975 | atoi(param)); |
| 5976 | return 0; |
| 5977 | } |
| 5978 | |
| 5979 | if (os_strcmp(cmd, "managed") == 0) { |
| 5980 | p2p_set_managed_oper(wpa_s->global->p2p, atoi(param)); |
| 5981 | return 0; |
| 5982 | } |
| 5983 | |
| 5984 | if (os_strcmp(cmd, "listen_channel") == 0) { |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 5985 | char *pos; |
| 5986 | u8 channel, op_class; |
| 5987 | |
| 5988 | channel = atoi(param); |
| 5989 | pos = os_strchr(param, ' '); |
| 5990 | op_class = pos ? atoi(pos) : 81; |
| 5991 | |
| 5992 | return p2p_set_listen_channel(wpa_s->global->p2p, op_class, |
| 5993 | channel, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5994 | } |
| 5995 | |
| 5996 | if (os_strcmp(cmd, "ssid_postfix") == 0) { |
| 5997 | return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param, |
| 5998 | os_strlen(param)); |
| 5999 | } |
| 6000 | |
| 6001 | if (os_strcmp(cmd, "noa") == 0) { |
| 6002 | char *pos; |
| 6003 | int count, start, duration; |
| 6004 | /* GO NoA parameters: count,start_offset(ms),duration(ms) */ |
| 6005 | count = atoi(param); |
| 6006 | pos = os_strchr(param, ','); |
| 6007 | if (pos == NULL) |
| 6008 | return -1; |
| 6009 | pos++; |
| 6010 | start = atoi(pos); |
| 6011 | pos = os_strchr(pos, ','); |
| 6012 | if (pos == NULL) |
| 6013 | return -1; |
| 6014 | pos++; |
| 6015 | duration = atoi(pos); |
| 6016 | if (count < 0 || count > 255 || start < 0 || duration < 0) |
| 6017 | return -1; |
| 6018 | if (count == 0 && duration > 0) |
| 6019 | return -1; |
| 6020 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d " |
| 6021 | "start=%d duration=%d", count, start, duration); |
| 6022 | return wpas_p2p_set_noa(wpa_s, count, start, duration); |
| 6023 | } |
| 6024 | |
| 6025 | if (os_strcmp(cmd, "ps") == 0) |
| 6026 | return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1); |
| 6027 | |
| 6028 | if (os_strcmp(cmd, "oppps") == 0) |
| 6029 | return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1); |
| 6030 | |
| 6031 | if (os_strcmp(cmd, "ctwindow") == 0) |
| 6032 | return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param)); |
| 6033 | |
| 6034 | if (os_strcmp(cmd, "disabled") == 0) { |
| 6035 | wpa_s->global->p2p_disabled = atoi(param); |
| 6036 | wpa_printf(MSG_DEBUG, "P2P functionality %s", |
| 6037 | wpa_s->global->p2p_disabled ? |
| 6038 | "disabled" : "enabled"); |
| 6039 | if (wpa_s->global->p2p_disabled) { |
| 6040 | wpas_p2p_stop_find(wpa_s); |
| 6041 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
| 6042 | p2p_flush(wpa_s->global->p2p); |
| 6043 | } |
| 6044 | return 0; |
| 6045 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6046 | |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 6047 | if (os_strcmp(cmd, "conc_pref") == 0) { |
| 6048 | if (os_strcmp(param, "sta") == 0) |
| 6049 | wpa_s->global->conc_pref = WPA_CONC_PREF_STA; |
| 6050 | else if (os_strcmp(param, "p2p") == 0) |
| 6051 | wpa_s->global->conc_pref = WPA_CONC_PREF_P2P; |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 6052 | else { |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 6053 | wpa_printf(MSG_INFO, "Invalid conc_pref value"); |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 6054 | return -1; |
| 6055 | } |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 6056 | wpa_printf(MSG_DEBUG, "Single channel concurrency preference: " |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6057 | "%s", param); |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 6058 | return 0; |
| 6059 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6060 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6061 | if (os_strcmp(cmd, "force_long_sd") == 0) { |
| 6062 | wpa_s->force_long_sd = atoi(param); |
| 6063 | return 0; |
| 6064 | } |
| 6065 | |
| 6066 | if (os_strcmp(cmd, "peer_filter") == 0) { |
| 6067 | u8 addr[ETH_ALEN]; |
| 6068 | if (hwaddr_aton(param, addr)) |
| 6069 | return -1; |
| 6070 | p2p_set_peer_filter(wpa_s->global->p2p, addr); |
| 6071 | return 0; |
| 6072 | } |
| 6073 | |
| 6074 | if (os_strcmp(cmd, "cross_connect") == 0) |
| 6075 | return wpas_p2p_set_cross_connect(wpa_s, atoi(param)); |
| 6076 | |
| 6077 | if (os_strcmp(cmd, "go_apsd") == 0) { |
| 6078 | if (os_strcmp(param, "disable") == 0) |
| 6079 | wpa_s->set_ap_uapsd = 0; |
| 6080 | else { |
| 6081 | wpa_s->set_ap_uapsd = 1; |
| 6082 | wpa_s->ap_uapsd = atoi(param); |
| 6083 | } |
| 6084 | return 0; |
| 6085 | } |
| 6086 | |
| 6087 | if (os_strcmp(cmd, "client_apsd") == 0) { |
| 6088 | if (os_strcmp(param, "disable") == 0) |
| 6089 | wpa_s->set_sta_uapsd = 0; |
| 6090 | else { |
| 6091 | int be, bk, vi, vo; |
| 6092 | char *pos; |
| 6093 | /* format: BE,BK,VI,VO;max SP Length */ |
| 6094 | be = atoi(param); |
| 6095 | pos = os_strchr(param, ','); |
| 6096 | if (pos == NULL) |
| 6097 | return -1; |
| 6098 | pos++; |
| 6099 | bk = atoi(pos); |
| 6100 | pos = os_strchr(pos, ','); |
| 6101 | if (pos == NULL) |
| 6102 | return -1; |
| 6103 | pos++; |
| 6104 | vi = atoi(pos); |
| 6105 | pos = os_strchr(pos, ','); |
| 6106 | if (pos == NULL) |
| 6107 | return -1; |
| 6108 | pos++; |
| 6109 | vo = atoi(pos); |
| 6110 | /* ignore max SP Length for now */ |
| 6111 | |
| 6112 | wpa_s->set_sta_uapsd = 1; |
| 6113 | wpa_s->sta_uapsd = 0; |
| 6114 | if (be) |
| 6115 | wpa_s->sta_uapsd |= BIT(0); |
| 6116 | if (bk) |
| 6117 | wpa_s->sta_uapsd |= BIT(1); |
| 6118 | if (vi) |
| 6119 | wpa_s->sta_uapsd |= BIT(2); |
| 6120 | if (vo) |
| 6121 | wpa_s->sta_uapsd |= BIT(3); |
| 6122 | } |
| 6123 | return 0; |
| 6124 | } |
| 6125 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6126 | if (os_strcmp(cmd, "disallow_freq") == 0) |
| 6127 | return p2p_ctrl_disallow_freq(wpa_s, param); |
| 6128 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6129 | if (os_strcmp(cmd, "disc_int") == 0) { |
| 6130 | int min_disc_int, max_disc_int, max_disc_tu; |
| 6131 | char *pos; |
| 6132 | |
| 6133 | pos = param; |
| 6134 | |
| 6135 | min_disc_int = atoi(pos); |
| 6136 | pos = os_strchr(pos, ' '); |
| 6137 | if (pos == NULL) |
| 6138 | return -1; |
| 6139 | *pos++ = '\0'; |
| 6140 | |
| 6141 | max_disc_int = atoi(pos); |
| 6142 | pos = os_strchr(pos, ' '); |
| 6143 | if (pos == NULL) |
| 6144 | return -1; |
| 6145 | *pos++ = '\0'; |
| 6146 | |
| 6147 | max_disc_tu = atoi(pos); |
| 6148 | |
| 6149 | return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int, |
| 6150 | max_disc_int, max_disc_tu); |
| 6151 | } |
| 6152 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6153 | if (os_strcmp(cmd, "per_sta_psk") == 0) { |
| 6154 | wpa_s->global->p2p_per_sta_psk = !!atoi(param); |
| 6155 | return 0; |
| 6156 | } |
| 6157 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6158 | #ifdef CONFIG_WPS_NFC |
| 6159 | if (os_strcmp(cmd, "nfc_tag") == 0) |
| 6160 | return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param)); |
| 6161 | #endif /* CONFIG_WPS_NFC */ |
| 6162 | |
| 6163 | if (os_strcmp(cmd, "disable_ip_addr_req") == 0) { |
| 6164 | wpa_s->p2p_disable_ip_addr_req = !!atoi(param); |
| 6165 | return 0; |
| 6166 | } |
| 6167 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6168 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", |
| 6169 | cmd); |
| 6170 | |
| 6171 | return -1; |
| 6172 | } |
| 6173 | |
| 6174 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 6175 | static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s) |
| 6176 | { |
| 6177 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
| 6178 | wpa_s->force_long_sd = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6179 | wpas_p2p_stop_find(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6180 | wpa_s->parent->p2ps_method_config_any = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 6181 | if (wpa_s->global->p2p) |
| 6182 | p2p_flush(wpa_s->global->p2p); |
| 6183 | } |
| 6184 | |
| 6185 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6186 | static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd) |
| 6187 | { |
| 6188 | char *pos, *pos2; |
| 6189 | unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0; |
| 6190 | |
| 6191 | if (cmd[0]) { |
| 6192 | pos = os_strchr(cmd, ' '); |
| 6193 | if (pos == NULL) |
| 6194 | return -1; |
| 6195 | *pos++ = '\0'; |
| 6196 | dur1 = atoi(cmd); |
| 6197 | |
| 6198 | pos2 = os_strchr(pos, ' '); |
| 6199 | if (pos2) |
| 6200 | *pos2++ = '\0'; |
| 6201 | int1 = atoi(pos); |
| 6202 | } else |
| 6203 | pos2 = NULL; |
| 6204 | |
| 6205 | if (pos2) { |
| 6206 | pos = os_strchr(pos2, ' '); |
| 6207 | if (pos == NULL) |
| 6208 | return -1; |
| 6209 | *pos++ = '\0'; |
| 6210 | dur2 = atoi(pos2); |
| 6211 | int2 = atoi(pos); |
| 6212 | } |
| 6213 | |
| 6214 | return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2); |
| 6215 | } |
| 6216 | |
| 6217 | |
| 6218 | static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd) |
| 6219 | { |
| 6220 | char *pos; |
| 6221 | unsigned int period = 0, interval = 0; |
| 6222 | |
| 6223 | if (cmd[0]) { |
| 6224 | pos = os_strchr(cmd, ' '); |
| 6225 | if (pos == NULL) |
| 6226 | return -1; |
| 6227 | *pos++ = '\0'; |
| 6228 | period = atoi(cmd); |
| 6229 | interval = atoi(pos); |
| 6230 | } |
| 6231 | |
| 6232 | return wpas_p2p_ext_listen(wpa_s, period, interval); |
| 6233 | } |
| 6234 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6235 | |
| 6236 | static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd) |
| 6237 | { |
| 6238 | const char *pos; |
| 6239 | u8 peer[ETH_ALEN]; |
| 6240 | int iface_addr = 0; |
| 6241 | |
| 6242 | pos = cmd; |
| 6243 | if (os_strncmp(pos, "iface=", 6) == 0) { |
| 6244 | iface_addr = 1; |
| 6245 | pos += 6; |
| 6246 | } |
| 6247 | if (hwaddr_aton(pos, peer)) |
| 6248 | return -1; |
| 6249 | |
| 6250 | wpas_p2p_remove_client(wpa_s, peer, iface_addr); |
| 6251 | return 0; |
| 6252 | } |
| 6253 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 6254 | |
| 6255 | static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd) |
| 6256 | { |
| 6257 | int freq = 0, period = 0, interval = 0, count = 0; |
| 6258 | |
| 6259 | if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4) |
| 6260 | { |
| 6261 | wpa_printf(MSG_DEBUG, |
| 6262 | "CTRL: Invalid P2P LO Start parameter: '%s'", cmd); |
| 6263 | return -1; |
| 6264 | } |
| 6265 | |
| 6266 | return wpas_p2p_lo_start(wpa_s, freq, period, interval, count); |
| 6267 | } |
| 6268 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6269 | #endif /* CONFIG_P2P */ |
| 6270 | |
| 6271 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6272 | static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val) |
| 6273 | { |
| 6274 | struct wpa_freq_range_list ranges; |
| 6275 | int *freqs = NULL; |
| 6276 | struct hostapd_hw_modes *mode; |
| 6277 | u16 i; |
| 6278 | |
| 6279 | if (wpa_s->hw.modes == NULL) |
| 6280 | return NULL; |
| 6281 | |
| 6282 | os_memset(&ranges, 0, sizeof(ranges)); |
| 6283 | if (freq_range_list_parse(&ranges, val) < 0) |
| 6284 | return NULL; |
| 6285 | |
| 6286 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 6287 | int j; |
| 6288 | |
| 6289 | mode = &wpa_s->hw.modes[i]; |
| 6290 | for (j = 0; j < mode->num_channels; j++) { |
| 6291 | unsigned int freq; |
| 6292 | |
| 6293 | if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED) |
| 6294 | continue; |
| 6295 | |
| 6296 | freq = mode->channels[j].freq; |
| 6297 | if (!freq_range_list_includes(&ranges, freq)) |
| 6298 | continue; |
| 6299 | |
| 6300 | int_array_add_unique(&freqs, freq); |
| 6301 | } |
| 6302 | } |
| 6303 | |
| 6304 | os_free(ranges.range); |
| 6305 | return freqs; |
| 6306 | } |
| 6307 | |
| 6308 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6309 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6310 | |
| 6311 | static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param) |
| 6312 | { |
| 6313 | int auto_sel = 0; |
| 6314 | int *freqs = NULL; |
| 6315 | |
| 6316 | if (param) { |
| 6317 | char *pos; |
| 6318 | |
| 6319 | auto_sel = os_strstr(param, "auto") != NULL; |
| 6320 | |
| 6321 | pos = os_strstr(param, "freq="); |
| 6322 | if (pos) { |
| 6323 | freqs = freq_range_to_channel_list(wpa_s, pos + 5); |
| 6324 | if (freqs == NULL) |
| 6325 | return -1; |
| 6326 | } |
| 6327 | |
| 6328 | } |
| 6329 | |
| 6330 | return interworking_select(wpa_s, auto_sel, freqs); |
| 6331 | } |
| 6332 | |
| 6333 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6334 | static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst, |
| 6335 | int only_add) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6336 | { |
| 6337 | u8 bssid[ETH_ALEN]; |
| 6338 | struct wpa_bss *bss; |
| 6339 | |
| 6340 | if (hwaddr_aton(dst, bssid)) { |
| 6341 | wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst); |
| 6342 | return -1; |
| 6343 | } |
| 6344 | |
| 6345 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 6346 | if (bss == NULL) { |
| 6347 | wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR, |
| 6348 | MAC2STR(bssid)); |
| 6349 | return -1; |
| 6350 | } |
| 6351 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6352 | if (bss->ssid_len == 0) { |
| 6353 | int found = 0; |
| 6354 | |
| 6355 | wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR |
| 6356 | " does not have SSID information", MAC2STR(bssid)); |
| 6357 | |
| 6358 | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, |
| 6359 | list) { |
| 6360 | if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 && |
| 6361 | bss->ssid_len > 0) { |
| 6362 | found = 1; |
| 6363 | break; |
| 6364 | } |
| 6365 | } |
| 6366 | |
| 6367 | if (!found) |
| 6368 | return -1; |
| 6369 | wpa_printf(MSG_DEBUG, |
| 6370 | "Found another matching BSS entry with SSID"); |
| 6371 | } |
| 6372 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6373 | return interworking_connect(wpa_s, bss, only_add); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6374 | } |
| 6375 | |
| 6376 | |
| 6377 | static int get_anqp(struct wpa_supplicant *wpa_s, char *dst) |
| 6378 | { |
| 6379 | u8 dst_addr[ETH_ALEN]; |
| 6380 | int used; |
| 6381 | char *pos; |
| 6382 | #define MAX_ANQP_INFO_ID 100 |
| 6383 | u16 id[MAX_ANQP_INFO_ID]; |
| 6384 | size_t num_id = 0; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6385 | u32 subtypes = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6386 | |
| 6387 | used = hwaddr_aton2(dst, dst_addr); |
| 6388 | if (used < 0) |
| 6389 | return -1; |
| 6390 | pos = dst + used; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6391 | if (*pos == ' ') |
| 6392 | pos++; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6393 | while (num_id < MAX_ANQP_INFO_ID) { |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6394 | if (os_strncmp(pos, "hs20:", 5) == 0) { |
| 6395 | #ifdef CONFIG_HS20 |
| 6396 | int num = atoi(pos + 5); |
| 6397 | if (num <= 0 || num > 31) |
| 6398 | return -1; |
| 6399 | subtypes |= BIT(num); |
| 6400 | #else /* CONFIG_HS20 */ |
| 6401 | return -1; |
| 6402 | #endif /* CONFIG_HS20 */ |
| 6403 | } else { |
| 6404 | id[num_id] = atoi(pos); |
| 6405 | if (id[num_id]) |
| 6406 | num_id++; |
| 6407 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6408 | pos = os_strchr(pos + 1, ','); |
| 6409 | if (pos == NULL) |
| 6410 | break; |
| 6411 | pos++; |
| 6412 | } |
| 6413 | |
| 6414 | if (num_id == 0) |
| 6415 | return -1; |
| 6416 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6417 | return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6418 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6419 | |
| 6420 | |
| 6421 | static int gas_request(struct wpa_supplicant *wpa_s, char *cmd) |
| 6422 | { |
| 6423 | u8 dst_addr[ETH_ALEN]; |
| 6424 | struct wpabuf *advproto, *query = NULL; |
| 6425 | int used, ret = -1; |
| 6426 | char *pos, *end; |
| 6427 | size_t len; |
| 6428 | |
| 6429 | used = hwaddr_aton2(cmd, dst_addr); |
| 6430 | if (used < 0) |
| 6431 | return -1; |
| 6432 | |
| 6433 | pos = cmd + used; |
| 6434 | while (*pos == ' ') |
| 6435 | pos++; |
| 6436 | |
| 6437 | /* Advertisement Protocol ID */ |
| 6438 | end = os_strchr(pos, ' '); |
| 6439 | if (end) |
| 6440 | len = end - pos; |
| 6441 | else |
| 6442 | len = os_strlen(pos); |
| 6443 | if (len & 0x01) |
| 6444 | return -1; |
| 6445 | len /= 2; |
| 6446 | if (len == 0) |
| 6447 | return -1; |
| 6448 | advproto = wpabuf_alloc(len); |
| 6449 | if (advproto == NULL) |
| 6450 | return -1; |
| 6451 | if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0) |
| 6452 | goto fail; |
| 6453 | |
| 6454 | if (end) { |
| 6455 | /* Optional Query Request */ |
| 6456 | pos = end + 1; |
| 6457 | while (*pos == ' ') |
| 6458 | pos++; |
| 6459 | |
| 6460 | len = os_strlen(pos); |
| 6461 | if (len) { |
| 6462 | if (len & 0x01) |
| 6463 | goto fail; |
| 6464 | len /= 2; |
| 6465 | if (len == 0) |
| 6466 | goto fail; |
| 6467 | query = wpabuf_alloc(len); |
| 6468 | if (query == NULL) |
| 6469 | goto fail; |
| 6470 | if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0) |
| 6471 | goto fail; |
| 6472 | } |
| 6473 | } |
| 6474 | |
| 6475 | ret = gas_send_request(wpa_s, dst_addr, advproto, query); |
| 6476 | |
| 6477 | fail: |
| 6478 | wpabuf_free(advproto); |
| 6479 | wpabuf_free(query); |
| 6480 | |
| 6481 | return ret; |
| 6482 | } |
| 6483 | |
| 6484 | |
| 6485 | static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf, |
| 6486 | size_t buflen) |
| 6487 | { |
| 6488 | u8 addr[ETH_ALEN]; |
| 6489 | int dialog_token; |
| 6490 | int used; |
| 6491 | char *pos; |
| 6492 | size_t resp_len, start, requested_len; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6493 | struct wpabuf *resp; |
| 6494 | int ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6495 | |
| 6496 | used = hwaddr_aton2(cmd, addr); |
| 6497 | if (used < 0) |
| 6498 | return -1; |
| 6499 | |
| 6500 | pos = cmd + used; |
| 6501 | while (*pos == ' ') |
| 6502 | pos++; |
| 6503 | dialog_token = atoi(pos); |
| 6504 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6505 | if (wpa_s->last_gas_resp && |
| 6506 | os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 && |
| 6507 | dialog_token == wpa_s->last_gas_dialog_token) |
| 6508 | resp = wpa_s->last_gas_resp; |
| 6509 | else if (wpa_s->prev_gas_resp && |
| 6510 | os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 && |
| 6511 | dialog_token == wpa_s->prev_gas_dialog_token) |
| 6512 | resp = wpa_s->prev_gas_resp; |
| 6513 | else |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6514 | return -1; |
| 6515 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6516 | resp_len = wpabuf_len(resp); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6517 | start = 0; |
| 6518 | requested_len = resp_len; |
| 6519 | |
| 6520 | pos = os_strchr(pos, ' '); |
| 6521 | if (pos) { |
| 6522 | start = atoi(pos); |
| 6523 | if (start > resp_len) |
| 6524 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); |
| 6525 | pos = os_strchr(pos, ','); |
| 6526 | if (pos == NULL) |
| 6527 | return -1; |
| 6528 | pos++; |
| 6529 | requested_len = atoi(pos); |
| 6530 | if (start + requested_len > resp_len) |
| 6531 | return os_snprintf(buf, buflen, "FAIL-Invalid range"); |
| 6532 | } |
| 6533 | |
| 6534 | if (requested_len * 2 + 1 > buflen) |
| 6535 | return os_snprintf(buf, buflen, "FAIL-Too long response"); |
| 6536 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6537 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start, |
| 6538 | requested_len); |
| 6539 | |
| 6540 | if (start + requested_len == resp_len) { |
| 6541 | /* |
| 6542 | * Free memory by dropping the response after it has been |
| 6543 | * fetched. |
| 6544 | */ |
| 6545 | if (resp == wpa_s->prev_gas_resp) { |
| 6546 | wpabuf_free(wpa_s->prev_gas_resp); |
| 6547 | wpa_s->prev_gas_resp = NULL; |
| 6548 | } else { |
| 6549 | wpabuf_free(wpa_s->last_gas_resp); |
| 6550 | wpa_s->last_gas_resp = NULL; |
| 6551 | } |
| 6552 | } |
| 6553 | |
| 6554 | return ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6555 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6556 | #endif /* CONFIG_INTERWORKING */ |
| 6557 | |
| 6558 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6559 | #ifdef CONFIG_HS20 |
| 6560 | |
| 6561 | static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst) |
| 6562 | { |
| 6563 | u8 dst_addr[ETH_ALEN]; |
| 6564 | int used; |
| 6565 | char *pos; |
| 6566 | u32 subtypes = 0; |
| 6567 | |
| 6568 | used = hwaddr_aton2(dst, dst_addr); |
| 6569 | if (used < 0) |
| 6570 | return -1; |
| 6571 | pos = dst + used; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6572 | if (*pos == ' ') |
| 6573 | pos++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6574 | for (;;) { |
| 6575 | int num = atoi(pos); |
| 6576 | if (num <= 0 || num > 31) |
| 6577 | return -1; |
| 6578 | subtypes |= BIT(num); |
| 6579 | pos = os_strchr(pos + 1, ','); |
| 6580 | if (pos == NULL) |
| 6581 | break; |
| 6582 | pos++; |
| 6583 | } |
| 6584 | |
| 6585 | if (subtypes == 0) |
| 6586 | return -1; |
| 6587 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 6588 | 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] | 6589 | } |
| 6590 | |
| 6591 | |
| 6592 | static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s, |
| 6593 | const u8 *addr, const char *realm) |
| 6594 | { |
| 6595 | u8 *buf; |
| 6596 | size_t rlen, len; |
| 6597 | int ret; |
| 6598 | |
| 6599 | rlen = os_strlen(realm); |
| 6600 | len = 3 + rlen; |
| 6601 | buf = os_malloc(len); |
| 6602 | if (buf == NULL) |
| 6603 | return -1; |
| 6604 | buf[0] = 1; /* NAI Home Realm Count */ |
| 6605 | buf[1] = 0; /* Formatted in accordance with RFC 4282 */ |
| 6606 | buf[2] = rlen; |
| 6607 | os_memcpy(buf + 3, realm, rlen); |
| 6608 | |
| 6609 | ret = hs20_anqp_send_req(wpa_s, addr, |
| 6610 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 6611 | buf, len, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6612 | |
| 6613 | os_free(buf); |
| 6614 | |
| 6615 | return ret; |
| 6616 | } |
| 6617 | |
| 6618 | |
| 6619 | static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s, |
| 6620 | char *dst) |
| 6621 | { |
| 6622 | struct wpa_cred *cred = wpa_s->conf->cred; |
| 6623 | u8 dst_addr[ETH_ALEN]; |
| 6624 | int used; |
| 6625 | u8 *buf; |
| 6626 | size_t len; |
| 6627 | int ret; |
| 6628 | |
| 6629 | used = hwaddr_aton2(dst, dst_addr); |
| 6630 | if (used < 0) |
| 6631 | return -1; |
| 6632 | |
| 6633 | while (dst[used] == ' ') |
| 6634 | used++; |
| 6635 | if (os_strncmp(dst + used, "realm=", 6) == 0) |
| 6636 | return hs20_nai_home_realm_list(wpa_s, dst_addr, |
| 6637 | dst + used + 6); |
| 6638 | |
| 6639 | len = os_strlen(dst + used); |
| 6640 | |
| 6641 | if (len == 0 && cred && cred->realm) |
| 6642 | return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm); |
| 6643 | |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 6644 | if (len & 1) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6645 | return -1; |
| 6646 | len /= 2; |
| 6647 | buf = os_malloc(len); |
| 6648 | if (buf == NULL) |
| 6649 | return -1; |
| 6650 | if (hexstr2bin(dst + used, buf, len) < 0) { |
| 6651 | os_free(buf); |
| 6652 | return -1; |
| 6653 | } |
| 6654 | |
| 6655 | ret = hs20_anqp_send_req(wpa_s, dst_addr, |
| 6656 | BIT(HS20_STYPE_NAI_HOME_REALM_QUERY), |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 6657 | buf, len, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6658 | os_free(buf); |
| 6659 | |
| 6660 | return ret; |
| 6661 | } |
| 6662 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 6663 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 6664 | static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply, |
| 6665 | int buflen) |
| 6666 | { |
| 6667 | u8 dst_addr[ETH_ALEN]; |
| 6668 | int used; |
| 6669 | char *ctx = NULL, *icon, *poffset, *psize; |
| 6670 | |
| 6671 | used = hwaddr_aton2(cmd, dst_addr); |
| 6672 | if (used < 0) |
| 6673 | return -1; |
| 6674 | cmd += used; |
| 6675 | |
| 6676 | icon = str_token(cmd, " ", &ctx); |
| 6677 | poffset = str_token(cmd, " ", &ctx); |
| 6678 | psize = str_token(cmd, " ", &ctx); |
| 6679 | if (!icon || !poffset || !psize) |
| 6680 | return -1; |
| 6681 | |
| 6682 | wpa_s->fetch_osu_icon_in_progress = 0; |
| 6683 | return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize), |
| 6684 | reply, buflen); |
| 6685 | } |
| 6686 | |
| 6687 | |
| 6688 | static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd) |
| 6689 | { |
| 6690 | u8 dst_addr[ETH_ALEN]; |
| 6691 | int used; |
| 6692 | char *icon; |
| 6693 | |
| 6694 | if (!cmd[0]) |
| 6695 | return hs20_del_icon(wpa_s, NULL, NULL); |
| 6696 | |
| 6697 | used = hwaddr_aton2(cmd, dst_addr); |
| 6698 | if (used < 0) |
| 6699 | return -1; |
| 6700 | |
| 6701 | while (cmd[used] == ' ') |
| 6702 | used++; |
| 6703 | icon = cmd[used] ? &cmd[used] : NULL; |
| 6704 | |
| 6705 | return hs20_del_icon(wpa_s, dst_addr, icon); |
| 6706 | } |
| 6707 | |
| 6708 | |
| 6709 | 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] | 6710 | { |
| 6711 | u8 dst_addr[ETH_ALEN]; |
| 6712 | int used; |
| 6713 | char *icon; |
| 6714 | |
| 6715 | used = hwaddr_aton2(cmd, dst_addr); |
| 6716 | if (used < 0) |
| 6717 | return -1; |
| 6718 | |
| 6719 | while (cmd[used] == ' ') |
| 6720 | used++; |
| 6721 | icon = &cmd[used]; |
| 6722 | |
| 6723 | wpa_s->fetch_osu_icon_in_progress = 0; |
| 6724 | 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] | 6725 | (u8 *) icon, os_strlen(icon), inmem); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 6726 | } |
| 6727 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6728 | #endif /* CONFIG_HS20 */ |
| 6729 | |
| 6730 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6731 | #ifdef CONFIG_AUTOSCAN |
| 6732 | |
| 6733 | static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s, |
| 6734 | char *cmd) |
| 6735 | { |
| 6736 | enum wpa_states state = wpa_s->wpa_state; |
| 6737 | char *new_params = NULL; |
| 6738 | |
| 6739 | if (os_strlen(cmd) > 0) { |
| 6740 | new_params = os_strdup(cmd); |
| 6741 | if (new_params == NULL) |
| 6742 | return -1; |
| 6743 | } |
| 6744 | |
| 6745 | os_free(wpa_s->conf->autoscan); |
| 6746 | wpa_s->conf->autoscan = new_params; |
| 6747 | |
| 6748 | if (wpa_s->conf->autoscan == NULL) |
| 6749 | autoscan_deinit(wpa_s); |
| 6750 | else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) |
| 6751 | autoscan_init(wpa_s, 1); |
| 6752 | else if (state == WPA_SCANNING) |
| 6753 | wpa_supplicant_reinit_autoscan(wpa_s); |
| 6754 | |
| 6755 | return 0; |
| 6756 | } |
| 6757 | |
| 6758 | #endif /* CONFIG_AUTOSCAN */ |
| 6759 | |
| 6760 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6761 | #ifdef CONFIG_WNM |
| 6762 | |
| 6763 | static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd) |
| 6764 | { |
| 6765 | int enter; |
| 6766 | int intval = 0; |
| 6767 | char *pos; |
| 6768 | int ret; |
| 6769 | struct wpabuf *tfs_req = NULL; |
| 6770 | |
| 6771 | if (os_strncmp(cmd, "enter", 5) == 0) |
| 6772 | enter = 1; |
| 6773 | else if (os_strncmp(cmd, "exit", 4) == 0) |
| 6774 | enter = 0; |
| 6775 | else |
| 6776 | return -1; |
| 6777 | |
| 6778 | pos = os_strstr(cmd, " interval="); |
| 6779 | if (pos) |
| 6780 | intval = atoi(pos + 10); |
| 6781 | |
| 6782 | pos = os_strstr(cmd, " tfs_req="); |
| 6783 | if (pos) { |
| 6784 | char *end; |
| 6785 | size_t len; |
| 6786 | pos += 9; |
| 6787 | end = os_strchr(pos, ' '); |
| 6788 | if (end) |
| 6789 | len = end - pos; |
| 6790 | else |
| 6791 | len = os_strlen(pos); |
| 6792 | if (len & 1) |
| 6793 | return -1; |
| 6794 | len /= 2; |
| 6795 | tfs_req = wpabuf_alloc(len); |
| 6796 | if (tfs_req == NULL) |
| 6797 | return -1; |
| 6798 | if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) { |
| 6799 | wpabuf_free(tfs_req); |
| 6800 | return -1; |
| 6801 | } |
| 6802 | } |
| 6803 | |
| 6804 | ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER : |
| 6805 | WNM_SLEEP_MODE_EXIT, intval, |
| 6806 | tfs_req); |
| 6807 | wpabuf_free(tfs_req); |
| 6808 | |
| 6809 | return ret; |
| 6810 | } |
| 6811 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 6812 | |
| 6813 | static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd) |
| 6814 | { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6815 | int query_reason, list = 0; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 6816 | |
| 6817 | query_reason = atoi(cmd); |
| 6818 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6819 | cmd = os_strchr(cmd, ' '); |
| 6820 | if (cmd) { |
| 6821 | cmd++; |
| 6822 | if (os_strncmp(cmd, "list", 4) == 0) { |
| 6823 | list = 1; |
| 6824 | } else { |
| 6825 | wpa_printf(MSG_DEBUG, "WNM Query: Invalid option %s", |
| 6826 | cmd); |
| 6827 | return -1; |
| 6828 | } |
| 6829 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 6830 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6831 | wpa_printf(MSG_DEBUG, |
| 6832 | "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s", |
| 6833 | query_reason, list ? " candidate list" : ""); |
| 6834 | |
| 6835 | return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason, list); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 6836 | } |
| 6837 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6838 | #endif /* CONFIG_WNM */ |
| 6839 | |
| 6840 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6841 | static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf, |
| 6842 | size_t buflen) |
| 6843 | { |
| 6844 | struct wpa_signal_info si; |
| 6845 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6846 | char *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6847 | |
| 6848 | ret = wpa_drv_signal_poll(wpa_s, &si); |
| 6849 | if (ret) |
| 6850 | return -1; |
| 6851 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6852 | pos = buf; |
| 6853 | end = buf + buflen; |
| 6854 | |
| 6855 | ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6856 | "NOISE=%d\nFREQUENCY=%u\n", |
| 6857 | si.current_signal, si.current_txrate / 1000, |
| 6858 | si.current_noise, si.frequency); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6859 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6860 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6861 | pos += ret; |
| 6862 | |
| 6863 | if (si.chanwidth != CHAN_WIDTH_UNKNOWN) { |
| 6864 | ret = os_snprintf(pos, end - pos, "WIDTH=%s\n", |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6865 | channel_width_to_string(si.chanwidth)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6866 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6867 | return -1; |
| 6868 | pos += ret; |
| 6869 | } |
| 6870 | |
| 6871 | if (si.center_frq1 > 0 && si.center_frq2 > 0) { |
| 6872 | ret = os_snprintf(pos, end - pos, |
| 6873 | "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n", |
| 6874 | si.center_frq1, si.center_frq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6875 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6876 | return -1; |
| 6877 | pos += ret; |
| 6878 | } |
| 6879 | |
| 6880 | if (si.avg_signal) { |
| 6881 | ret = os_snprintf(pos, end - pos, |
| 6882 | "AVG_RSSI=%d\n", si.avg_signal); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6883 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6884 | return -1; |
| 6885 | pos += ret; |
| 6886 | } |
| 6887 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 6888 | if (si.avg_beacon_signal) { |
| 6889 | ret = os_snprintf(pos, end - pos, |
| 6890 | "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal); |
| 6891 | if (os_snprintf_error(end - pos, ret)) |
| 6892 | return -1; |
| 6893 | pos += ret; |
| 6894 | } |
| 6895 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6896 | return pos - buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6897 | } |
| 6898 | |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6899 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 6900 | static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s, |
| 6901 | const char *cmd) |
| 6902 | { |
| 6903 | const char *pos; |
| 6904 | int threshold = 0; |
| 6905 | int hysteresis = 0; |
| 6906 | |
| 6907 | if (wpa_s->bgscan && wpa_s->bgscan_priv) { |
| 6908 | wpa_printf(MSG_DEBUG, |
| 6909 | "Reject SIGNAL_MONITOR command - bgscan is active"); |
| 6910 | return -1; |
| 6911 | } |
| 6912 | pos = os_strstr(cmd, "THRESHOLD="); |
| 6913 | if (pos) |
| 6914 | threshold = atoi(pos + 10); |
| 6915 | pos = os_strstr(cmd, "HYSTERESIS="); |
| 6916 | if (pos) |
| 6917 | hysteresis = atoi(pos + 11); |
| 6918 | return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis); |
| 6919 | } |
| 6920 | |
| 6921 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6922 | static int wpas_ctrl_iface_get_pref_freq_list( |
| 6923 | struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| 6924 | { |
| 6925 | unsigned int freq_list[100], num = 100, i; |
| 6926 | int ret; |
| 6927 | enum wpa_driver_if_type iface_type; |
| 6928 | char *pos, *end; |
| 6929 | |
| 6930 | pos = buf; |
| 6931 | end = buf + buflen; |
| 6932 | |
| 6933 | /* buf: "<interface_type>" */ |
| 6934 | if (os_strcmp(cmd, "STATION") == 0) |
| 6935 | iface_type = WPA_IF_STATION; |
| 6936 | else if (os_strcmp(cmd, "AP") == 0) |
| 6937 | iface_type = WPA_IF_AP_BSS; |
| 6938 | else if (os_strcmp(cmd, "P2P_GO") == 0) |
| 6939 | iface_type = WPA_IF_P2P_GO; |
| 6940 | else if (os_strcmp(cmd, "P2P_CLIENT") == 0) |
| 6941 | iface_type = WPA_IF_P2P_CLIENT; |
| 6942 | else if (os_strcmp(cmd, "IBSS") == 0) |
| 6943 | iface_type = WPA_IF_IBSS; |
| 6944 | else if (os_strcmp(cmd, "TDLS") == 0) |
| 6945 | iface_type = WPA_IF_TDLS; |
| 6946 | else |
| 6947 | return -1; |
| 6948 | |
| 6949 | wpa_printf(MSG_DEBUG, |
| 6950 | "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)", |
| 6951 | iface_type, buf); |
| 6952 | |
| 6953 | ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list); |
| 6954 | if (ret) |
| 6955 | return -1; |
| 6956 | |
| 6957 | for (i = 0; i < num; i++) { |
| 6958 | ret = os_snprintf(pos, end - pos, "%s%u", |
| 6959 | i > 0 ? "," : "", freq_list[i]); |
| 6960 | if (os_snprintf_error(end - pos, ret)) |
| 6961 | return -1; |
| 6962 | pos += ret; |
| 6963 | } |
| 6964 | |
| 6965 | return pos - buf; |
| 6966 | } |
| 6967 | |
| 6968 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 6969 | static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s, |
| 6970 | char *buf, size_t buflen) |
| 6971 | { |
| 6972 | int ret, i; |
| 6973 | char *pos, *end; |
| 6974 | |
| 6975 | ret = os_snprintf(buf, buflen, "%016llX:\n", |
| 6976 | (long long unsigned) wpa_s->drv_flags); |
| 6977 | if (os_snprintf_error(buflen, ret)) |
| 6978 | return -1; |
| 6979 | |
| 6980 | pos = buf + ret; |
| 6981 | end = buf + buflen; |
| 6982 | |
| 6983 | for (i = 0; i < 64; i++) { |
| 6984 | if (wpa_s->drv_flags & (1LLU << i)) { |
| 6985 | ret = os_snprintf(pos, end - pos, "%s\n", |
| 6986 | driver_flag_to_string(1LLU << i)); |
| 6987 | if (os_snprintf_error(end - pos, ret)) |
| 6988 | return -1; |
| 6989 | pos += ret; |
| 6990 | } |
| 6991 | } |
| 6992 | |
| 6993 | return pos - buf; |
| 6994 | } |
| 6995 | |
| 6996 | |
Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 6997 | static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf, |
| 6998 | size_t buflen) |
| 6999 | { |
| 7000 | struct hostap_sta_driver_data sta; |
| 7001 | int ret; |
| 7002 | |
| 7003 | ret = wpa_drv_pktcnt_poll(wpa_s, &sta); |
| 7004 | if (ret) |
| 7005 | return -1; |
| 7006 | |
| 7007 | ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n", |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7008 | sta.tx_packets, sta.tx_retry_failed, sta.rx_packets); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7009 | if (os_snprintf_error(buflen, ret)) |
Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 7010 | return -1; |
| 7011 | return ret; |
| 7012 | } |
| 7013 | |
| 7014 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7015 | #ifdef ANDROID |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 7016 | static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd, |
| 7017 | char *buf, size_t buflen) |
| 7018 | { |
| 7019 | int ret; |
| 7020 | |
| 7021 | ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen); |
Dmitry Shmidt | 9432e12 | 2013-09-12 12:39:30 -0700 | [diff] [blame] | 7022 | if (ret == 0) { |
| 7023 | if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) { |
| 7024 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 7025 | if (p2p) { |
| 7026 | char country[3]; |
| 7027 | country[0] = cmd[8]; |
| 7028 | country[1] = cmd[9]; |
| 7029 | country[2] = 0x04; |
| 7030 | p2p_set_country(p2p, country); |
| 7031 | } |
| 7032 | } |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7033 | ret = os_snprintf(buf, buflen, "%s\n", "OK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7034 | if (os_snprintf_error(buflen, ret)) |
| 7035 | ret = -1; |
Dmitry Shmidt | 9432e12 | 2013-09-12 12:39:30 -0700 | [diff] [blame] | 7036 | } |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 7037 | return ret; |
| 7038 | } |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7039 | #endif /* ANDROID */ |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 7040 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 7041 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7042 | static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd, |
| 7043 | char *buf, size_t buflen) |
| 7044 | { |
| 7045 | int ret; |
| 7046 | char *pos; |
| 7047 | u8 *data = NULL; |
| 7048 | unsigned int vendor_id, subcmd; |
| 7049 | struct wpabuf *reply; |
| 7050 | size_t data_len = 0; |
| 7051 | |
| 7052 | /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */ |
| 7053 | vendor_id = strtoul(cmd, &pos, 16); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7054 | if (!isblank((unsigned char) *pos)) |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7055 | return -EINVAL; |
| 7056 | |
| 7057 | subcmd = strtoul(pos, &pos, 10); |
| 7058 | |
| 7059 | if (*pos != '\0') { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7060 | if (!isblank((unsigned char) *pos++)) |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7061 | return -EINVAL; |
| 7062 | data_len = os_strlen(pos); |
| 7063 | } |
| 7064 | |
| 7065 | if (data_len) { |
| 7066 | data_len /= 2; |
| 7067 | data = os_malloc(data_len); |
| 7068 | if (!data) |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7069 | return -1; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7070 | |
| 7071 | if (hexstr2bin(pos, data, data_len)) { |
| 7072 | wpa_printf(MSG_DEBUG, |
| 7073 | "Vendor command: wrong parameter format"); |
| 7074 | os_free(data); |
| 7075 | return -EINVAL; |
| 7076 | } |
| 7077 | } |
| 7078 | |
| 7079 | reply = wpabuf_alloc((buflen - 1) / 2); |
| 7080 | if (!reply) { |
| 7081 | os_free(data); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7082 | return -1; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7083 | } |
| 7084 | |
| 7085 | ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len, |
| 7086 | reply); |
| 7087 | |
| 7088 | if (ret == 0) |
| 7089 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply), |
| 7090 | wpabuf_len(reply)); |
| 7091 | |
| 7092 | wpabuf_free(reply); |
| 7093 | os_free(data); |
| 7094 | |
| 7095 | return ret; |
| 7096 | } |
| 7097 | |
| 7098 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7099 | static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s) |
| 7100 | { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7101 | #ifdef CONFIG_P2P |
| 7102 | struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ? |
| 7103 | wpa_s->global->p2p_init_wpa_s : wpa_s; |
| 7104 | #endif /* CONFIG_P2P */ |
| 7105 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7106 | wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state"); |
| 7107 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7108 | wpas_abort_ongoing_scan(wpa_s); |
| 7109 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7110 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 7111 | /* |
| 7112 | * Avoid possible auto connect re-connection on getting |
| 7113 | * disconnected due to state flush. |
| 7114 | */ |
| 7115 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 7116 | } |
| 7117 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7118 | #ifdef CONFIG_P2P |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7119 | wpas_p2p_group_remove(p2p_wpa_s, "*"); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7120 | wpas_p2p_cancel(p2p_wpa_s); |
| 7121 | p2p_ctrl_flush(p2p_wpa_s); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7122 | wpas_p2p_service_flush(p2p_wpa_s); |
| 7123 | p2p_wpa_s->global->p2p_disabled = 0; |
| 7124 | p2p_wpa_s->global->p2p_per_sta_psk = 0; |
| 7125 | p2p_wpa_s->conf->num_sec_device_types = 0; |
| 7126 | p2p_wpa_s->p2p_disable_ip_addr_req = 0; |
| 7127 | os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range); |
| 7128 | p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7129 | p2p_wpa_s->global->p2p_go_avoid_freq.num = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7130 | p2p_wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7131 | p2p_wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7132 | #endif /* CONFIG_P2P */ |
| 7133 | |
| 7134 | #ifdef CONFIG_WPS_TESTING |
| 7135 | wps_version_number = 0x20; |
| 7136 | wps_testing_dummy_cred = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7137 | wps_corrupt_pkhash = 0; |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7138 | wps_force_auth_types_in_use = 0; |
| 7139 | wps_force_encr_types_in_use = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7140 | #endif /* CONFIG_WPS_TESTING */ |
| 7141 | #ifdef CONFIG_WPS |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7142 | wpa_s->wps_fragment_size = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7143 | wpas_wps_cancel(wpa_s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7144 | wps_registrar_flush(wpa_s->wps->registrar); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7145 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7146 | wpa_s->after_wps = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7147 | wpa_s->known_wps_freq = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7148 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7149 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7150 | #ifdef CONFIG_TDLS_TESTING |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7151 | tdls_testing = 0; |
| 7152 | #endif /* CONFIG_TDLS_TESTING */ |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7153 | wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL); |
| 7154 | wpa_tdls_enable(wpa_s->wpa, 1); |
| 7155 | #endif /* CONFIG_TDLS */ |
| 7156 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7157 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL); |
| 7158 | wpa_supplicant_stop_countermeasures(wpa_s, NULL); |
| 7159 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7160 | wpa_s->no_keep_alive = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 7161 | wpa_s->own_disconnect_req = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7162 | |
| 7163 | os_free(wpa_s->disallow_aps_bssid); |
| 7164 | wpa_s->disallow_aps_bssid = NULL; |
| 7165 | wpa_s->disallow_aps_bssid_count = 0; |
| 7166 | os_free(wpa_s->disallow_aps_ssid); |
| 7167 | wpa_s->disallow_aps_ssid = NULL; |
| 7168 | wpa_s->disallow_aps_ssid_count = 0; |
| 7169 | |
| 7170 | wpa_s->set_sta_uapsd = 0; |
| 7171 | wpa_s->sta_uapsd = 0; |
| 7172 | |
| 7173 | wpa_drv_radio_disable(wpa_s, 0); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7174 | wpa_blacklist_clear(wpa_s); |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 7175 | wpa_s->extra_blacklist_count = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7176 | wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all"); |
| 7177 | wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all"); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 7178 | wpa_config_flush_blobs(wpa_s->conf); |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 7179 | wpa_s->conf->auto_interworking = 0; |
| 7180 | wpa_s->conf->okc = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7181 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7182 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
| 7183 | rsn_preauth_deinit(wpa_s->wpa); |
| 7184 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7185 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200); |
| 7186 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70); |
| 7187 | wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60); |
| 7188 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); |
| 7189 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 7190 | radio_remove_works(wpa_s, NULL, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7191 | wpa_s->ext_work_in_progress = 0; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 7192 | |
| 7193 | wpa_s->next_ssid = NULL; |
| 7194 | |
| 7195 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7196 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 7197 | hs20_cancel_fetch_osu(wpa_s); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7198 | hs20_del_icon(wpa_s, NULL, NULL); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7199 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 7200 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 7201 | |
| 7202 | wpa_s->ext_mgmt_frame_handling = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7203 | wpa_s->ext_eapol_frame_io = 0; |
| 7204 | #ifdef CONFIG_TESTING_OPTIONS |
| 7205 | wpa_s->extra_roc_dur = 0; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7206 | wpa_s->test_failure = WPAS_TEST_FAILURE_NONE; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7207 | wpa_s->p2p_go_csa_on_inv = 0; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame^] | 7208 | wpa_s->ignore_auth_resp = 0; |
| 7209 | wpa_s->ignore_assoc_disallow = 0; |
| 7210 | wpa_s->reject_btm_req_reason = 0; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 7211 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7212 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7213 | |
| 7214 | wpa_s->disconnected = 0; |
| 7215 | os_free(wpa_s->next_scan_freqs); |
| 7216 | wpa_s->next_scan_freqs = NULL; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7217 | |
| 7218 | wpa_bss_flush(wpa_s); |
| 7219 | if (!dl_list_empty(&wpa_s->bss)) { |
| 7220 | wpa_printf(MSG_DEBUG, |
| 7221 | "BSS table not empty after flush: %u entries, current_bss=%p bssid=" |
| 7222 | MACSTR " pending_bssid=" MACSTR, |
| 7223 | dl_list_len(&wpa_s->bss), wpa_s->current_bss, |
| 7224 | MAC2STR(wpa_s->bssid), |
| 7225 | MAC2STR(wpa_s->pending_bssid)); |
| 7226 | } |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 7227 | |
| 7228 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
Dmitry Shmidt | b70d0bb | 2015-11-16 10:43:06 -0800 | [diff] [blame] | 7229 | wpa_s->wnmsleep_used = 0; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7230 | |
| 7231 | #ifdef CONFIG_SME |
| 7232 | wpa_s->sme.last_unprot_disconnect.sec = 0; |
| 7233 | #endif /* CONFIG_SME */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7234 | } |
| 7235 | |
| 7236 | |
| 7237 | static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s, |
| 7238 | char *buf, size_t buflen) |
| 7239 | { |
| 7240 | struct wpa_radio_work *work; |
| 7241 | char *pos, *end; |
| 7242 | struct os_reltime now, diff; |
| 7243 | |
| 7244 | pos = buf; |
| 7245 | end = buf + buflen; |
| 7246 | |
| 7247 | os_get_reltime(&now); |
| 7248 | |
| 7249 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) |
| 7250 | { |
| 7251 | int ret; |
| 7252 | |
| 7253 | os_reltime_sub(&now, &work->time, &diff); |
| 7254 | ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n", |
| 7255 | work->type, work->wpa_s->ifname, work->freq, |
| 7256 | work->started, diff.sec, diff.usec); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7257 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7258 | break; |
| 7259 | pos += ret; |
| 7260 | } |
| 7261 | |
| 7262 | return pos - buf; |
| 7263 | } |
| 7264 | |
| 7265 | |
| 7266 | static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx) |
| 7267 | { |
| 7268 | struct wpa_radio_work *work = eloop_ctx; |
| 7269 | struct wpa_external_work *ework = work->ctx; |
| 7270 | |
| 7271 | wpa_dbg(work->wpa_s, MSG_DEBUG, |
| 7272 | "Timing out external radio work %u (%s)", |
| 7273 | ework->id, work->type); |
| 7274 | 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] | 7275 | work->wpa_s->ext_work_in_progress = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7276 | radio_work_done(work); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7277 | os_free(ework); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7278 | } |
| 7279 | |
| 7280 | |
| 7281 | static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit) |
| 7282 | { |
| 7283 | struct wpa_external_work *ework = work->ctx; |
| 7284 | |
| 7285 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 7286 | if (work->started) |
| 7287 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, |
| 7288 | work, NULL); |
| 7289 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 7290 | /* |
| 7291 | * work->type points to a buffer in ework, so need to replace |
| 7292 | * that here with a fixed string to avoid use of freed memory |
| 7293 | * in debug prints. |
| 7294 | */ |
| 7295 | work->type = "freed-ext-work"; |
| 7296 | work->ctx = NULL; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7297 | os_free(ework); |
| 7298 | return; |
| 7299 | } |
| 7300 | |
| 7301 | wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)", |
| 7302 | ework->id, ework->type); |
| 7303 | 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] | 7304 | work->wpa_s->ext_work_in_progress = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7305 | if (!ework->timeout) |
| 7306 | ework->timeout = 10; |
| 7307 | eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout, |
| 7308 | work, NULL); |
| 7309 | } |
| 7310 | |
| 7311 | |
| 7312 | static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd, |
| 7313 | char *buf, size_t buflen) |
| 7314 | { |
| 7315 | struct wpa_external_work *ework; |
| 7316 | char *pos, *pos2; |
| 7317 | size_t type_len; |
| 7318 | int ret; |
| 7319 | unsigned int freq = 0; |
| 7320 | |
| 7321 | /* format: <name> [freq=<MHz>] [timeout=<seconds>] */ |
| 7322 | |
| 7323 | ework = os_zalloc(sizeof(*ework)); |
| 7324 | if (ework == NULL) |
| 7325 | return -1; |
| 7326 | |
| 7327 | pos = os_strchr(cmd, ' '); |
| 7328 | if (pos) { |
| 7329 | type_len = pos - cmd; |
| 7330 | pos++; |
| 7331 | |
| 7332 | pos2 = os_strstr(pos, "freq="); |
| 7333 | if (pos2) |
| 7334 | freq = atoi(pos2 + 5); |
| 7335 | |
| 7336 | pos2 = os_strstr(pos, "timeout="); |
| 7337 | if (pos2) |
| 7338 | ework->timeout = atoi(pos2 + 8); |
| 7339 | } else { |
| 7340 | type_len = os_strlen(cmd); |
| 7341 | } |
| 7342 | if (4 + type_len >= sizeof(ework->type)) |
| 7343 | type_len = sizeof(ework->type) - 4 - 1; |
| 7344 | os_strlcpy(ework->type, "ext:", sizeof(ework->type)); |
| 7345 | os_memcpy(ework->type + 4, cmd, type_len); |
| 7346 | ework->type[4 + type_len] = '\0'; |
| 7347 | |
| 7348 | wpa_s->ext_work_id++; |
| 7349 | if (wpa_s->ext_work_id == 0) |
| 7350 | wpa_s->ext_work_id++; |
| 7351 | ework->id = wpa_s->ext_work_id; |
| 7352 | |
| 7353 | if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb, |
| 7354 | ework) < 0) { |
| 7355 | os_free(ework); |
| 7356 | return -1; |
| 7357 | } |
| 7358 | |
| 7359 | ret = os_snprintf(buf, buflen, "%u", ework->id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7360 | if (os_snprintf_error(buflen, ret)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7361 | return -1; |
| 7362 | return ret; |
| 7363 | } |
| 7364 | |
| 7365 | |
| 7366 | static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd) |
| 7367 | { |
| 7368 | struct wpa_radio_work *work; |
| 7369 | unsigned int id = atoi(cmd); |
| 7370 | |
| 7371 | dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list) |
| 7372 | { |
| 7373 | struct wpa_external_work *ework; |
| 7374 | |
| 7375 | if (os_strncmp(work->type, "ext:", 4) != 0) |
| 7376 | continue; |
| 7377 | ework = work->ctx; |
| 7378 | if (id && ework->id != id) |
| 7379 | continue; |
| 7380 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7381 | "Completed external radio work %u (%s)", |
| 7382 | ework->id, ework->type); |
| 7383 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7384 | wpa_s->ext_work_in_progress = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7385 | radio_work_done(work); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 7386 | os_free(ework); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7387 | return 3; /* "OK\n" */ |
| 7388 | } |
| 7389 | |
| 7390 | return -1; |
| 7391 | } |
| 7392 | |
| 7393 | |
| 7394 | static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd, |
| 7395 | char *buf, size_t buflen) |
| 7396 | { |
| 7397 | if (os_strcmp(cmd, "show") == 0) |
| 7398 | return wpas_ctrl_radio_work_show(wpa_s, buf, buflen); |
| 7399 | if (os_strncmp(cmd, "add ", 4) == 0) |
| 7400 | return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen); |
| 7401 | if (os_strncmp(cmd, "done ", 5) == 0) |
| 7402 | return wpas_ctrl_radio_work_done(wpa_s, cmd + 4); |
| 7403 | return -1; |
| 7404 | } |
| 7405 | |
| 7406 | |
| 7407 | void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s) |
| 7408 | { |
| 7409 | struct wpa_radio_work *work, *tmp; |
| 7410 | |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 7411 | if (!wpa_s || !wpa_s->radio) |
| 7412 | return; |
| 7413 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7414 | dl_list_for_each_safe(work, tmp, &wpa_s->radio->work, |
| 7415 | struct wpa_radio_work, list) { |
| 7416 | struct wpa_external_work *ework; |
| 7417 | |
| 7418 | if (os_strncmp(work->type, "ext:", 4) != 0) |
| 7419 | continue; |
| 7420 | ework = work->ctx; |
| 7421 | wpa_dbg(wpa_s, MSG_DEBUG, |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 7422 | "Flushing%s external radio work %u (%s)", |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7423 | work->started ? " started" : "", ework->id, |
| 7424 | ework->type); |
| 7425 | if (work->started) |
| 7426 | eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, |
| 7427 | work, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7428 | radio_work_done(work); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7429 | os_free(ework); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7430 | } |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 7431 | } |
| 7432 | |
| 7433 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7434 | static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx) |
| 7435 | { |
| 7436 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 7437 | eapol_sm_notify_ctrl_response(wpa_s->eapol); |
| 7438 | } |
| 7439 | |
| 7440 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7441 | static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value, |
| 7442 | unsigned int *scan_id_count, int scan_id[]) |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 7443 | { |
| 7444 | const char *pos = value; |
| 7445 | |
| 7446 | while (pos) { |
| 7447 | if (*pos == ' ' || *pos == '\0') |
| 7448 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7449 | if (*scan_id_count == MAX_SCAN_ID) |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 7450 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7451 | scan_id[(*scan_id_count)++] = atoi(pos); |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 7452 | pos = os_strchr(pos, ','); |
| 7453 | if (pos) |
| 7454 | pos++; |
| 7455 | } |
| 7456 | |
| 7457 | return 0; |
| 7458 | } |
| 7459 | |
| 7460 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7461 | static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params, |
| 7462 | char *reply, int reply_size, int *reply_len) |
| 7463 | { |
| 7464 | char *pos; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7465 | unsigned int manual_scan_passive = 0; |
| 7466 | unsigned int manual_scan_use_id = 0; |
| 7467 | unsigned int manual_scan_only_new = 0; |
| 7468 | unsigned int scan_only = 0; |
| 7469 | unsigned int scan_id_count = 0; |
| 7470 | int scan_id[MAX_SCAN_ID]; |
| 7471 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, |
| 7472 | struct wpa_scan_results *scan_res); |
| 7473 | int *manual_scan_freqs = NULL; |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 7474 | struct wpa_ssid_value *ssid = NULL, *ns; |
| 7475 | unsigned int ssid_count = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7476 | |
| 7477 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 7478 | *reply_len = -1; |
| 7479 | return; |
| 7480 | } |
| 7481 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7482 | if (radio_work_pending(wpa_s, "scan")) { |
| 7483 | wpa_printf(MSG_DEBUG, |
| 7484 | "Pending scan scheduled - reject new request"); |
| 7485 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); |
| 7486 | return; |
| 7487 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7488 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 7489 | #ifdef CONFIG_INTERWORKING |
| 7490 | if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) { |
| 7491 | wpa_printf(MSG_DEBUG, |
| 7492 | "Interworking select in progress - reject new scan"); |
| 7493 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); |
| 7494 | return; |
| 7495 | } |
| 7496 | #endif /* CONFIG_INTERWORKING */ |
| 7497 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7498 | if (params) { |
| 7499 | if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7500 | scan_only = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7501 | |
| 7502 | pos = os_strstr(params, "freq="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7503 | if (pos) { |
| 7504 | manual_scan_freqs = freq_range_to_channel_list(wpa_s, |
| 7505 | pos + 5); |
| 7506 | if (manual_scan_freqs == NULL) { |
| 7507 | *reply_len = -1; |
| 7508 | goto done; |
| 7509 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7510 | } |
| 7511 | |
| 7512 | pos = os_strstr(params, "passive="); |
| 7513 | if (pos) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7514 | manual_scan_passive = !!atoi(pos + 8); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7515 | |
| 7516 | pos = os_strstr(params, "use_id="); |
| 7517 | if (pos) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7518 | manual_scan_use_id = atoi(pos + 7); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7519 | |
| 7520 | pos = os_strstr(params, "only_new=1"); |
| 7521 | if (pos) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7522 | manual_scan_only_new = 1; |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 7523 | |
| 7524 | pos = os_strstr(params, "scan_id="); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7525 | if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count, |
| 7526 | scan_id) < 0) { |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 7527 | *reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7528 | goto done; |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 7529 | } |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 7530 | |
| 7531 | pos = params; |
| 7532 | while (pos && *pos != '\0') { |
| 7533 | if (os_strncmp(pos, "ssid ", 5) == 0) { |
| 7534 | char *end; |
| 7535 | |
| 7536 | pos += 5; |
| 7537 | end = pos; |
| 7538 | while (*end) { |
| 7539 | if (*end == '\0' || *end == ' ') |
| 7540 | break; |
| 7541 | end++; |
| 7542 | } |
| 7543 | |
| 7544 | ns = os_realloc_array( |
| 7545 | ssid, ssid_count + 1, |
| 7546 | sizeof(struct wpa_ssid_value)); |
| 7547 | if (ns == NULL) { |
| 7548 | *reply_len = -1; |
| 7549 | goto done; |
| 7550 | } |
| 7551 | ssid = ns; |
| 7552 | |
| 7553 | if ((end - pos) & 0x01 || |
| 7554 | end - pos > 2 * SSID_MAX_LEN || |
| 7555 | hexstr2bin(pos, ssid[ssid_count].ssid, |
| 7556 | (end - pos) / 2) < 0) { |
| 7557 | wpa_printf(MSG_DEBUG, |
| 7558 | "Invalid SSID value '%s'", |
| 7559 | pos); |
| 7560 | *reply_len = -1; |
| 7561 | goto done; |
| 7562 | } |
| 7563 | ssid[ssid_count].ssid_len = (end - pos) / 2; |
| 7564 | wpa_hexdump_ascii(MSG_DEBUG, "scan SSID", |
| 7565 | ssid[ssid_count].ssid, |
| 7566 | ssid[ssid_count].ssid_len); |
| 7567 | ssid_count++; |
| 7568 | pos = end; |
| 7569 | } |
| 7570 | |
| 7571 | pos = os_strchr(pos, ' '); |
| 7572 | if (pos) |
| 7573 | pos++; |
| 7574 | } |
| 7575 | } |
| 7576 | |
| 7577 | wpa_s->num_ssids_from_scan_req = ssid_count; |
| 7578 | os_free(wpa_s->ssids_from_scan_req); |
| 7579 | if (ssid_count) { |
| 7580 | wpa_s->ssids_from_scan_req = ssid; |
| 7581 | ssid = NULL; |
| 7582 | } else { |
| 7583 | wpa_s->ssids_from_scan_req = NULL; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7584 | } |
| 7585 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7586 | if (scan_only) |
| 7587 | scan_res_handler = scan_only_handler; |
| 7588 | else if (wpa_s->scan_res_handler == scan_only_handler) |
| 7589 | scan_res_handler = NULL; |
| 7590 | else |
| 7591 | scan_res_handler = wpa_s->scan_res_handler; |
| 7592 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7593 | if (!wpa_s->sched_scanning && !wpa_s->scanning && |
| 7594 | ((wpa_s->wpa_state <= WPA_SCANNING) || |
| 7595 | (wpa_s->wpa_state == WPA_COMPLETED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7596 | wpa_s->manual_scan_passive = manual_scan_passive; |
| 7597 | wpa_s->manual_scan_use_id = manual_scan_use_id; |
| 7598 | wpa_s->manual_scan_only_new = manual_scan_only_new; |
| 7599 | wpa_s->scan_id_count = scan_id_count; |
| 7600 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); |
| 7601 | wpa_s->scan_res_handler = scan_res_handler; |
| 7602 | os_free(wpa_s->manual_scan_freqs); |
| 7603 | wpa_s->manual_scan_freqs = manual_scan_freqs; |
| 7604 | manual_scan_freqs = NULL; |
| 7605 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7606 | wpa_s->normal_scans = 0; |
| 7607 | wpa_s->scan_req = MANUAL_SCAN_REQ; |
| 7608 | wpa_s->after_wps = 0; |
| 7609 | wpa_s->known_wps_freq = 0; |
| 7610 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 7611 | if (wpa_s->manual_scan_use_id) { |
| 7612 | wpa_s->manual_scan_id++; |
| 7613 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", |
| 7614 | wpa_s->manual_scan_id); |
| 7615 | *reply_len = os_snprintf(reply, reply_size, "%u\n", |
| 7616 | wpa_s->manual_scan_id); |
| 7617 | } |
| 7618 | } else if (wpa_s->sched_scanning) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7619 | wpa_s->manual_scan_passive = manual_scan_passive; |
| 7620 | wpa_s->manual_scan_use_id = manual_scan_use_id; |
| 7621 | wpa_s->manual_scan_only_new = manual_scan_only_new; |
| 7622 | wpa_s->scan_id_count = scan_id_count; |
| 7623 | os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int)); |
| 7624 | wpa_s->scan_res_handler = scan_res_handler; |
| 7625 | os_free(wpa_s->manual_scan_freqs); |
| 7626 | wpa_s->manual_scan_freqs = manual_scan_freqs; |
| 7627 | manual_scan_freqs = NULL; |
| 7628 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7629 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed"); |
| 7630 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 7631 | wpa_s->scan_req = MANUAL_SCAN_REQ; |
| 7632 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 7633 | if (wpa_s->manual_scan_use_id) { |
| 7634 | wpa_s->manual_scan_id++; |
| 7635 | *reply_len = os_snprintf(reply, reply_size, "%u\n", |
| 7636 | wpa_s->manual_scan_id); |
| 7637 | wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u", |
| 7638 | wpa_s->manual_scan_id); |
| 7639 | } |
| 7640 | } else { |
| 7641 | wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request"); |
| 7642 | *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n"); |
| 7643 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7644 | |
| 7645 | done: |
| 7646 | os_free(manual_scan_freqs); |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 7647 | os_free(ssid); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7648 | } |
| 7649 | |
| 7650 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 7651 | #ifdef CONFIG_TESTING_OPTIONS |
| 7652 | |
| 7653 | static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s, |
| 7654 | unsigned int freq, const u8 *dst, |
| 7655 | const u8 *src, const u8 *bssid, |
| 7656 | const u8 *data, size_t data_len, |
| 7657 | enum offchannel_send_action_result |
| 7658 | result) |
| 7659 | { |
| 7660 | wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR |
| 7661 | " src=" MACSTR " bssid=" MACSTR " result=%s", |
| 7662 | freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid), |
| 7663 | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? |
| 7664 | "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? |
| 7665 | "NO_ACK" : "FAILED")); |
| 7666 | } |
| 7667 | |
| 7668 | |
| 7669 | static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd) |
| 7670 | { |
| 7671 | char *pos, *param; |
| 7672 | size_t len; |
| 7673 | u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN]; |
| 7674 | int res, used; |
| 7675 | int freq = 0, no_cck = 0, wait_time = 0; |
| 7676 | |
| 7677 | /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1] |
| 7678 | * <action=Action frame payload> */ |
| 7679 | |
| 7680 | wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd); |
| 7681 | |
| 7682 | pos = cmd; |
| 7683 | used = hwaddr_aton2(pos, da); |
| 7684 | if (used < 0) |
| 7685 | return -1; |
| 7686 | pos += used; |
| 7687 | while (*pos == ' ') |
| 7688 | pos++; |
| 7689 | used = hwaddr_aton2(pos, bssid); |
| 7690 | if (used < 0) |
| 7691 | return -1; |
| 7692 | pos += used; |
| 7693 | |
| 7694 | param = os_strstr(pos, " freq="); |
| 7695 | if (param) { |
| 7696 | param += 6; |
| 7697 | freq = atoi(param); |
| 7698 | } |
| 7699 | |
| 7700 | param = os_strstr(pos, " no_cck="); |
| 7701 | if (param) { |
| 7702 | param += 8; |
| 7703 | no_cck = atoi(param); |
| 7704 | } |
| 7705 | |
| 7706 | param = os_strstr(pos, " wait_time="); |
| 7707 | if (param) { |
| 7708 | param += 11; |
| 7709 | wait_time = atoi(param); |
| 7710 | } |
| 7711 | |
| 7712 | param = os_strstr(pos, " action="); |
| 7713 | if (param == NULL) |
| 7714 | return -1; |
| 7715 | param += 8; |
| 7716 | |
| 7717 | len = os_strlen(param); |
| 7718 | if (len & 1) |
| 7719 | return -1; |
| 7720 | len /= 2; |
| 7721 | |
| 7722 | buf = os_malloc(len); |
| 7723 | if (buf == NULL) |
| 7724 | return -1; |
| 7725 | |
| 7726 | if (hexstr2bin(param, buf, len) < 0) { |
| 7727 | os_free(buf); |
| 7728 | return -1; |
| 7729 | } |
| 7730 | |
| 7731 | res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid, |
| 7732 | buf, len, wait_time, |
| 7733 | wpas_ctrl_iface_mgmt_tx_cb, no_cck); |
| 7734 | os_free(buf); |
| 7735 | return res; |
| 7736 | } |
| 7737 | |
| 7738 | |
| 7739 | static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s) |
| 7740 | { |
| 7741 | wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting"); |
| 7742 | offchannel_send_action_done(wpa_s); |
| 7743 | } |
| 7744 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 7745 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 7746 | static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s, |
| 7747 | char *cmd) |
| 7748 | { |
| 7749 | char *pos, *param; |
| 7750 | size_t len; |
| 7751 | u8 *buf; |
| 7752 | int freq = 0, datarate = 0, ssi_signal = 0; |
| 7753 | union wpa_event_data event; |
| 7754 | |
| 7755 | if (!wpa_s->ext_mgmt_frame_handling) |
| 7756 | return -1; |
| 7757 | |
| 7758 | /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */ |
| 7759 | |
| 7760 | wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd); |
| 7761 | |
| 7762 | pos = cmd; |
| 7763 | param = os_strstr(pos, "freq="); |
| 7764 | if (param) { |
| 7765 | param += 5; |
| 7766 | freq = atoi(param); |
| 7767 | } |
| 7768 | |
| 7769 | param = os_strstr(pos, " datarate="); |
| 7770 | if (param) { |
| 7771 | param += 10; |
| 7772 | datarate = atoi(param); |
| 7773 | } |
| 7774 | |
| 7775 | param = os_strstr(pos, " ssi_signal="); |
| 7776 | if (param) { |
| 7777 | param += 12; |
| 7778 | ssi_signal = atoi(param); |
| 7779 | } |
| 7780 | |
| 7781 | param = os_strstr(pos, " frame="); |
| 7782 | if (param == NULL) |
| 7783 | return -1; |
| 7784 | param += 7; |
| 7785 | |
| 7786 | len = os_strlen(param); |
| 7787 | if (len & 1) |
| 7788 | return -1; |
| 7789 | len /= 2; |
| 7790 | |
| 7791 | buf = os_malloc(len); |
| 7792 | if (buf == NULL) |
| 7793 | return -1; |
| 7794 | |
| 7795 | if (hexstr2bin(param, buf, len) < 0) { |
| 7796 | os_free(buf); |
| 7797 | return -1; |
| 7798 | } |
| 7799 | |
| 7800 | os_memset(&event, 0, sizeof(event)); |
| 7801 | event.rx_mgmt.freq = freq; |
| 7802 | event.rx_mgmt.frame = buf; |
| 7803 | event.rx_mgmt.frame_len = len; |
| 7804 | event.rx_mgmt.ssi_signal = ssi_signal; |
| 7805 | event.rx_mgmt.datarate = datarate; |
| 7806 | wpa_s->ext_mgmt_frame_handling = 0; |
| 7807 | wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event); |
| 7808 | wpa_s->ext_mgmt_frame_handling = 1; |
| 7809 | |
| 7810 | os_free(buf); |
| 7811 | |
| 7812 | return 0; |
| 7813 | } |
| 7814 | |
| 7815 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 7816 | static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd) |
| 7817 | { |
| 7818 | char *pos, *param; |
| 7819 | union wpa_event_data event; |
| 7820 | enum wpa_event_type ev; |
| 7821 | |
| 7822 | /* <event name> [parameters..] */ |
| 7823 | |
| 7824 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd); |
| 7825 | |
| 7826 | pos = cmd; |
| 7827 | param = os_strchr(pos, ' '); |
| 7828 | if (param) |
| 7829 | *param++ = '\0'; |
| 7830 | |
| 7831 | os_memset(&event, 0, sizeof(event)); |
| 7832 | |
| 7833 | if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) { |
| 7834 | ev = EVENT_INTERFACE_ENABLED; |
| 7835 | } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) { |
| 7836 | ev = EVENT_INTERFACE_DISABLED; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7837 | } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) { |
| 7838 | ev = EVENT_AVOID_FREQUENCIES; |
| 7839 | if (param == NULL) |
| 7840 | param = ""; |
| 7841 | if (freq_range_list_parse(&event.freq_range, param) < 0) |
| 7842 | return -1; |
| 7843 | wpa_supplicant_event(wpa_s, ev, &event); |
| 7844 | os_free(event.freq_range.range); |
| 7845 | return 0; |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 7846 | } else { |
| 7847 | wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s", |
| 7848 | cmd); |
| 7849 | return -1; |
| 7850 | } |
| 7851 | |
| 7852 | wpa_supplicant_event(wpa_s, ev, &event); |
| 7853 | |
| 7854 | return 0; |
| 7855 | } |
| 7856 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7857 | |
| 7858 | static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd) |
| 7859 | { |
| 7860 | char *pos; |
| 7861 | u8 src[ETH_ALEN], *buf; |
| 7862 | int used; |
| 7863 | size_t len; |
| 7864 | |
| 7865 | wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd); |
| 7866 | |
| 7867 | pos = cmd; |
| 7868 | used = hwaddr_aton2(pos, src); |
| 7869 | if (used < 0) |
| 7870 | return -1; |
| 7871 | pos += used; |
| 7872 | while (*pos == ' ') |
| 7873 | pos++; |
| 7874 | |
| 7875 | len = os_strlen(pos); |
| 7876 | if (len & 1) |
| 7877 | return -1; |
| 7878 | len /= 2; |
| 7879 | |
| 7880 | buf = os_malloc(len); |
| 7881 | if (buf == NULL) |
| 7882 | return -1; |
| 7883 | |
| 7884 | if (hexstr2bin(pos, buf, len) < 0) { |
| 7885 | os_free(buf); |
| 7886 | return -1; |
| 7887 | } |
| 7888 | |
| 7889 | wpa_supplicant_rx_eapol(wpa_s, src, buf, len); |
| 7890 | os_free(buf); |
| 7891 | |
| 7892 | return 0; |
| 7893 | } |
| 7894 | |
| 7895 | |
| 7896 | static u16 ipv4_hdr_checksum(const void *buf, size_t len) |
| 7897 | { |
| 7898 | size_t i; |
| 7899 | u32 sum = 0; |
| 7900 | const u16 *pos = buf; |
| 7901 | |
| 7902 | for (i = 0; i < len / 2; i++) |
| 7903 | sum += *pos++; |
| 7904 | |
| 7905 | while (sum >> 16) |
| 7906 | sum = (sum & 0xffff) + (sum >> 16); |
| 7907 | |
| 7908 | return sum ^ 0xffff; |
| 7909 | } |
| 7910 | |
| 7911 | |
| 7912 | #define HWSIM_PACKETLEN 1500 |
| 7913 | #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header)) |
| 7914 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 7915 | static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, |
| 7916 | size_t len) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7917 | { |
| 7918 | struct wpa_supplicant *wpa_s = ctx; |
| 7919 | const struct ether_header *eth; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7920 | struct iphdr ip; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7921 | const u8 *pos; |
| 7922 | unsigned int i; |
| 7923 | |
| 7924 | if (len != HWSIM_PACKETLEN) |
| 7925 | return; |
| 7926 | |
| 7927 | eth = (const struct ether_header *) buf; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7928 | os_memcpy(&ip, eth + 1, sizeof(ip)); |
| 7929 | pos = &buf[sizeof(*eth) + sizeof(ip)]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7930 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7931 | if (ip.ihl != 5 || ip.version != 4 || |
| 7932 | ntohs(ip.tot_len) != HWSIM_IP_LEN) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7933 | return; |
| 7934 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7935 | for (i = 0; i < HWSIM_IP_LEN - sizeof(ip); i++) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7936 | if (*pos != (u8) i) |
| 7937 | return; |
| 7938 | pos++; |
| 7939 | } |
| 7940 | |
| 7941 | wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR, |
| 7942 | MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost)); |
| 7943 | } |
| 7944 | |
| 7945 | |
| 7946 | static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s, |
| 7947 | char *cmd) |
| 7948 | { |
| 7949 | int enabled = atoi(cmd); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7950 | char *pos; |
| 7951 | const char *ifname; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7952 | |
| 7953 | if (!enabled) { |
| 7954 | if (wpa_s->l2_test) { |
| 7955 | l2_packet_deinit(wpa_s->l2_test); |
| 7956 | wpa_s->l2_test = NULL; |
| 7957 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled"); |
| 7958 | } |
| 7959 | return 0; |
| 7960 | } |
| 7961 | |
| 7962 | if (wpa_s->l2_test) |
| 7963 | return 0; |
| 7964 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7965 | pos = os_strstr(cmd, " ifname="); |
| 7966 | if (pos) |
| 7967 | ifname = pos + 8; |
| 7968 | else |
| 7969 | ifname = wpa_s->ifname; |
| 7970 | |
| 7971 | wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7972 | ETHERTYPE_IP, wpas_data_test_rx, |
| 7973 | wpa_s, 1); |
| 7974 | if (wpa_s->l2_test == NULL) |
| 7975 | return -1; |
| 7976 | |
| 7977 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled"); |
| 7978 | |
| 7979 | return 0; |
| 7980 | } |
| 7981 | |
| 7982 | |
| 7983 | static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd) |
| 7984 | { |
| 7985 | u8 dst[ETH_ALEN], src[ETH_ALEN]; |
| 7986 | char *pos; |
| 7987 | int used; |
| 7988 | long int val; |
| 7989 | u8 tos; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7990 | u8 buf[2 + HWSIM_PACKETLEN]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7991 | struct ether_header *eth; |
| 7992 | struct iphdr *ip; |
| 7993 | u8 *dpos; |
| 7994 | unsigned int i; |
| 7995 | |
| 7996 | if (wpa_s->l2_test == NULL) |
| 7997 | return -1; |
| 7998 | |
| 7999 | /* format: <dst> <src> <tos> */ |
| 8000 | |
| 8001 | pos = cmd; |
| 8002 | used = hwaddr_aton2(pos, dst); |
| 8003 | if (used < 0) |
| 8004 | return -1; |
| 8005 | pos += used; |
| 8006 | while (*pos == ' ') |
| 8007 | pos++; |
| 8008 | used = hwaddr_aton2(pos, src); |
| 8009 | if (used < 0) |
| 8010 | return -1; |
| 8011 | pos += used; |
| 8012 | |
| 8013 | val = strtol(pos, NULL, 0); |
| 8014 | if (val < 0 || val > 0xff) |
| 8015 | return -1; |
| 8016 | tos = val; |
| 8017 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8018 | eth = (struct ether_header *) &buf[2]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8019 | os_memcpy(eth->ether_dhost, dst, ETH_ALEN); |
| 8020 | os_memcpy(eth->ether_shost, src, ETH_ALEN); |
| 8021 | eth->ether_type = htons(ETHERTYPE_IP); |
| 8022 | ip = (struct iphdr *) (eth + 1); |
| 8023 | os_memset(ip, 0, sizeof(*ip)); |
| 8024 | ip->ihl = 5; |
| 8025 | ip->version = 4; |
| 8026 | ip->ttl = 64; |
| 8027 | ip->tos = tos; |
| 8028 | ip->tot_len = htons(HWSIM_IP_LEN); |
| 8029 | ip->protocol = 1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8030 | ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1); |
| 8031 | ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8032 | ip->check = ipv4_hdr_checksum(ip, sizeof(*ip)); |
| 8033 | dpos = (u8 *) (ip + 1); |
| 8034 | for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) |
| 8035 | *dpos++ = i; |
| 8036 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8037 | if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2], |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8038 | HWSIM_PACKETLEN) < 0) |
| 8039 | return -1; |
| 8040 | |
| 8041 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR |
| 8042 | " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos); |
| 8043 | |
| 8044 | return 0; |
| 8045 | } |
| 8046 | |
| 8047 | |
| 8048 | static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s, |
| 8049 | char *cmd) |
| 8050 | { |
| 8051 | u8 *buf; |
| 8052 | struct ether_header *eth; |
| 8053 | struct l2_packet_data *l2 = NULL; |
| 8054 | size_t len; |
| 8055 | u16 ethertype; |
| 8056 | int res = -1; |
| 8057 | |
| 8058 | len = os_strlen(cmd); |
| 8059 | if (len & 1 || len < ETH_HLEN * 2) |
| 8060 | return -1; |
| 8061 | len /= 2; |
| 8062 | |
| 8063 | buf = os_malloc(len); |
| 8064 | if (buf == NULL) |
| 8065 | return -1; |
| 8066 | |
| 8067 | if (hexstr2bin(cmd, buf, len) < 0) |
| 8068 | goto done; |
| 8069 | |
| 8070 | eth = (struct ether_header *) buf; |
| 8071 | ethertype = ntohs(eth->ether_type); |
| 8072 | |
| 8073 | l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype, |
| 8074 | wpas_data_test_rx, wpa_s, 1); |
| 8075 | if (l2 == NULL) |
| 8076 | goto done; |
| 8077 | |
| 8078 | res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len); |
| 8079 | wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res); |
| 8080 | done: |
| 8081 | if (l2) |
| 8082 | l2_packet_deinit(l2); |
| 8083 | os_free(buf); |
| 8084 | |
| 8085 | return res < 0 ? -1 : 0; |
| 8086 | } |
| 8087 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8088 | |
| 8089 | static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd) |
| 8090 | { |
| 8091 | #ifdef WPA_TRACE_BFD |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8092 | char *pos; |
| 8093 | |
| 8094 | wpa_trace_fail_after = atoi(cmd); |
| 8095 | pos = os_strchr(cmd, ':'); |
| 8096 | if (pos) { |
| 8097 | pos++; |
| 8098 | os_strlcpy(wpa_trace_fail_func, pos, |
| 8099 | sizeof(wpa_trace_fail_func)); |
| 8100 | } else { |
| 8101 | wpa_trace_fail_after = 0; |
| 8102 | } |
| 8103 | return 0; |
| 8104 | #else /* WPA_TRACE_BFD */ |
| 8105 | return -1; |
| 8106 | #endif /* WPA_TRACE_BFD */ |
| 8107 | } |
| 8108 | |
| 8109 | |
| 8110 | static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s, |
| 8111 | char *buf, size_t buflen) |
| 8112 | { |
| 8113 | #ifdef WPA_TRACE_BFD |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8114 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after, |
| 8115 | wpa_trace_fail_func); |
| 8116 | #else /* WPA_TRACE_BFD */ |
| 8117 | return -1; |
| 8118 | #endif /* WPA_TRACE_BFD */ |
| 8119 | } |
| 8120 | |
Jouni Malinen | c481836 | 2015-10-04 11:45:13 +0300 | [diff] [blame] | 8121 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8122 | static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd) |
| 8123 | { |
| 8124 | #ifdef WPA_TRACE_BFD |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8125 | char *pos; |
| 8126 | |
| 8127 | wpa_trace_test_fail_after = atoi(cmd); |
| 8128 | pos = os_strchr(cmd, ':'); |
| 8129 | if (pos) { |
| 8130 | pos++; |
| 8131 | os_strlcpy(wpa_trace_test_fail_func, pos, |
| 8132 | sizeof(wpa_trace_test_fail_func)); |
| 8133 | } else { |
| 8134 | wpa_trace_test_fail_after = 0; |
| 8135 | } |
| 8136 | return 0; |
| 8137 | #else /* WPA_TRACE_BFD */ |
| 8138 | return -1; |
| 8139 | #endif /* WPA_TRACE_BFD */ |
| 8140 | } |
| 8141 | |
| 8142 | |
| 8143 | static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s, |
| 8144 | char *buf, size_t buflen) |
| 8145 | { |
| 8146 | #ifdef WPA_TRACE_BFD |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8147 | return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after, |
| 8148 | wpa_trace_test_fail_func); |
| 8149 | #else /* WPA_TRACE_BFD */ |
| 8150 | return -1; |
| 8151 | #endif /* WPA_TRACE_BFD */ |
| 8152 | } |
| 8153 | |
| 8154 | |
Jouni Malinen | c481836 | 2015-10-04 11:45:13 +0300 | [diff] [blame] | 8155 | static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx) |
| 8156 | { |
| 8157 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 8158 | int i, count = (intptr_t) timeout_ctx; |
| 8159 | |
| 8160 | wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages", |
| 8161 | count); |
| 8162 | for (i = 0; i < count; i++) { |
| 8163 | wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d", |
| 8164 | i + 1, count); |
| 8165 | } |
| 8166 | } |
| 8167 | |
| 8168 | |
| 8169 | static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd) |
| 8170 | { |
| 8171 | int count; |
| 8172 | |
| 8173 | count = atoi(cmd); |
| 8174 | if (count <= 0) |
| 8175 | return -1; |
| 8176 | |
| 8177 | return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s, |
| 8178 | (void *) (intptr_t) count); |
| 8179 | } |
| 8180 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 8181 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8182 | static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s, |
| 8183 | const char *cmd) |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8184 | { |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8185 | struct wpabuf *buf; |
| 8186 | size_t len; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8187 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8188 | len = os_strlen(cmd); |
| 8189 | if (len & 1) |
| 8190 | return -1; |
| 8191 | len /= 2; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8192 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8193 | if (len == 0) { |
| 8194 | buf = NULL; |
| 8195 | } else { |
| 8196 | buf = wpabuf_alloc(len); |
| 8197 | if (buf == NULL) |
| 8198 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8199 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8200 | if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) { |
| 8201 | wpabuf_free(buf); |
| 8202 | return -1; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8203 | } |
| 8204 | } |
| 8205 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8206 | wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf); |
| 8207 | return 0; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8208 | } |
| 8209 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8210 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8211 | |
| 8212 | |
| 8213 | static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd) |
| 8214 | { |
| 8215 | char *pos = cmd; |
| 8216 | int frame; |
| 8217 | size_t len; |
| 8218 | struct wpabuf *buf; |
| 8219 | struct ieee802_11_elems elems; |
| 8220 | |
| 8221 | frame = atoi(pos); |
| 8222 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) |
| 8223 | return -1; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8224 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8225 | |
| 8226 | pos = os_strchr(pos, ' '); |
| 8227 | if (pos == NULL) |
| 8228 | return -1; |
| 8229 | pos++; |
| 8230 | |
| 8231 | len = os_strlen(pos); |
| 8232 | if (len == 0) |
| 8233 | return 0; |
| 8234 | if (len & 1) |
| 8235 | return -1; |
| 8236 | len /= 2; |
| 8237 | |
| 8238 | buf = wpabuf_alloc(len); |
| 8239 | if (buf == NULL) |
| 8240 | return -1; |
| 8241 | |
| 8242 | if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { |
| 8243 | wpabuf_free(buf); |
| 8244 | return -1; |
| 8245 | } |
| 8246 | |
| 8247 | if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) == |
| 8248 | ParseFailed) { |
| 8249 | wpabuf_free(buf); |
| 8250 | return -1; |
| 8251 | } |
| 8252 | |
| 8253 | if (wpa_s->vendor_elem[frame] == NULL) { |
| 8254 | wpa_s->vendor_elem[frame] = buf; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8255 | wpas_vendor_elem_update(wpa_s); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8256 | return 0; |
| 8257 | } |
| 8258 | |
| 8259 | if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) { |
| 8260 | wpabuf_free(buf); |
| 8261 | return -1; |
| 8262 | } |
| 8263 | |
| 8264 | wpabuf_put_buf(wpa_s->vendor_elem[frame], buf); |
| 8265 | wpabuf_free(buf); |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8266 | wpas_vendor_elem_update(wpa_s); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8267 | |
| 8268 | return 0; |
| 8269 | } |
| 8270 | |
| 8271 | |
| 8272 | static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd, |
| 8273 | char *buf, size_t buflen) |
| 8274 | { |
| 8275 | int frame = atoi(cmd); |
| 8276 | |
| 8277 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) |
| 8278 | return -1; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8279 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8280 | |
| 8281 | if (wpa_s->vendor_elem[frame] == NULL) |
| 8282 | return 0; |
| 8283 | |
| 8284 | return wpa_snprintf_hex(buf, buflen, |
| 8285 | wpabuf_head_u8(wpa_s->vendor_elem[frame]), |
| 8286 | wpabuf_len(wpa_s->vendor_elem[frame])); |
| 8287 | } |
| 8288 | |
| 8289 | |
| 8290 | static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd) |
| 8291 | { |
| 8292 | char *pos = cmd; |
| 8293 | int frame; |
| 8294 | size_t len; |
| 8295 | u8 *buf; |
| 8296 | struct ieee802_11_elems elems; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8297 | int res; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8298 | |
| 8299 | frame = atoi(pos); |
| 8300 | if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES) |
| 8301 | return -1; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8302 | wpa_s = wpas_vendor_elem(wpa_s, frame); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8303 | |
| 8304 | pos = os_strchr(pos, ' '); |
| 8305 | if (pos == NULL) |
| 8306 | return -1; |
| 8307 | pos++; |
| 8308 | |
| 8309 | if (*pos == '*') { |
| 8310 | wpabuf_free(wpa_s->vendor_elem[frame]); |
| 8311 | wpa_s->vendor_elem[frame] = NULL; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8312 | wpas_vendor_elem_update(wpa_s); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8313 | return 0; |
| 8314 | } |
| 8315 | |
| 8316 | if (wpa_s->vendor_elem[frame] == NULL) |
| 8317 | return -1; |
| 8318 | |
| 8319 | len = os_strlen(pos); |
| 8320 | if (len == 0) |
| 8321 | return 0; |
| 8322 | if (len & 1) |
| 8323 | return -1; |
| 8324 | len /= 2; |
| 8325 | |
| 8326 | buf = os_malloc(len); |
| 8327 | if (buf == NULL) |
| 8328 | return -1; |
| 8329 | |
| 8330 | if (hexstr2bin(pos, buf, len) < 0) { |
| 8331 | os_free(buf); |
| 8332 | return -1; |
| 8333 | } |
| 8334 | |
| 8335 | if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) { |
| 8336 | os_free(buf); |
| 8337 | return -1; |
| 8338 | } |
| 8339 | |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8340 | res = wpas_vendor_elem_remove(wpa_s, frame, buf, len); |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8341 | os_free(buf); |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 8342 | return res; |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 8343 | } |
| 8344 | |
| 8345 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8346 | static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep) |
| 8347 | { |
| 8348 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8349 | size_t len; |
| 8350 | const u8 *data; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8351 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8352 | /* |
| 8353 | * Neighbor Report element (IEEE P802.11-REVmc/D5.0) |
| 8354 | * BSSID[6] |
| 8355 | * BSSID Information[4] |
| 8356 | * Operating Class[1] |
| 8357 | * Channel Number[1] |
| 8358 | * PHY Type[1] |
| 8359 | * Optional Subelements[variable] |
| 8360 | */ |
| 8361 | #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1) |
| 8362 | |
| 8363 | if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8364 | wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8365 | goto out; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8366 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8367 | |
| 8368 | data = wpabuf_head_u8(neighbor_rep); |
| 8369 | len = wpabuf_len(neighbor_rep); |
| 8370 | |
| 8371 | while (len >= 2 + NR_IE_MIN_LEN) { |
| 8372 | const u8 *nr; |
| 8373 | char lci[256 * 2 + 1]; |
| 8374 | char civic[256 * 2 + 1]; |
| 8375 | u8 nr_len = data[1]; |
| 8376 | const u8 *pos = data, *end; |
| 8377 | |
| 8378 | if (pos[0] != WLAN_EID_NEIGHBOR_REPORT || |
| 8379 | nr_len < NR_IE_MIN_LEN) { |
| 8380 | wpa_printf(MSG_DEBUG, |
| 8381 | "CTRL: Invalid Neighbor Report element: id=%u len=%u", |
| 8382 | data[0], nr_len); |
| 8383 | goto out; |
| 8384 | } |
| 8385 | |
| 8386 | if (2U + nr_len > len) { |
| 8387 | wpa_printf(MSG_DEBUG, |
| 8388 | "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u", |
| 8389 | data[0], len, nr_len); |
| 8390 | goto out; |
| 8391 | } |
| 8392 | pos += 2; |
| 8393 | end = pos + nr_len; |
| 8394 | |
| 8395 | nr = pos; |
| 8396 | pos += NR_IE_MIN_LEN; |
| 8397 | |
| 8398 | lci[0] = '\0'; |
| 8399 | civic[0] = '\0'; |
| 8400 | while (end - pos > 2) { |
| 8401 | u8 s_id, s_len; |
| 8402 | |
| 8403 | s_id = *pos++; |
| 8404 | s_len = *pos++; |
| 8405 | if (s_len > end - pos) |
| 8406 | goto out; |
| 8407 | if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) { |
| 8408 | /* Measurement Token[1] */ |
| 8409 | /* Measurement Report Mode[1] */ |
| 8410 | /* Measurement Type[1] */ |
| 8411 | /* Measurement Report[variable] */ |
| 8412 | switch (pos[2]) { |
| 8413 | case MEASURE_TYPE_LCI: |
| 8414 | if (lci[0]) |
| 8415 | break; |
| 8416 | wpa_snprintf_hex(lci, sizeof(lci), |
| 8417 | pos, s_len); |
| 8418 | break; |
| 8419 | case MEASURE_TYPE_LOCATION_CIVIC: |
| 8420 | if (civic[0]) |
| 8421 | break; |
| 8422 | wpa_snprintf_hex(civic, sizeof(civic), |
| 8423 | pos, s_len); |
| 8424 | break; |
| 8425 | } |
| 8426 | } |
| 8427 | |
| 8428 | pos += s_len; |
| 8429 | } |
| 8430 | |
| 8431 | wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED |
| 8432 | "bssid=" MACSTR |
| 8433 | " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s", |
| 8434 | MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN), |
| 8435 | nr[ETH_ALEN + 4], nr[ETH_ALEN + 5], |
| 8436 | nr[ETH_ALEN + 6], |
| 8437 | lci[0] ? " lci=" : "", lci, |
| 8438 | civic[0] ? " civic=" : "", civic); |
| 8439 | |
| 8440 | data = end; |
| 8441 | len -= 2 + nr_len; |
| 8442 | } |
| 8443 | |
| 8444 | out: |
| 8445 | wpabuf_free(neighbor_rep); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8446 | } |
| 8447 | |
| 8448 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8449 | static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s, |
| 8450 | char *cmd) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8451 | { |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8452 | struct wpa_ssid_value ssid, *ssid_p = NULL; |
| 8453 | int ret, lci = 0, civic = 0; |
| 8454 | char *ssid_s; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8455 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8456 | ssid_s = os_strstr(cmd, "ssid="); |
| 8457 | if (ssid_s) { |
| 8458 | if (ssid_parse(ssid_s + 5, &ssid)) { |
| 8459 | wpa_printf(MSG_ERROR, |
| 8460 | "CTRL: Send Neighbor Report: bad SSID"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8461 | return -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8462 | } |
| 8463 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8464 | ssid_p = &ssid; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8465 | |
| 8466 | /* |
| 8467 | * Move cmd after the SSID text that may include "lci" or |
| 8468 | * "civic". |
| 8469 | */ |
| 8470 | cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' '); |
| 8471 | if (cmd) |
| 8472 | cmd++; |
| 8473 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8474 | } |
| 8475 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8476 | if (cmd && os_strstr(cmd, "lci")) |
| 8477 | lci = 1; |
| 8478 | |
| 8479 | if (cmd && os_strstr(cmd, "civic")) |
| 8480 | civic = 1; |
| 8481 | |
| 8482 | 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] | 8483 | wpas_ctrl_neighbor_rep_cb, |
| 8484 | wpa_s); |
| 8485 | |
| 8486 | return ret; |
| 8487 | } |
| 8488 | |
| 8489 | |
| 8490 | static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s) |
| 8491 | { |
| 8492 | eapol_sm_erp_flush(wpa_s->eapol); |
| 8493 | return 0; |
| 8494 | } |
| 8495 | |
| 8496 | |
| 8497 | static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s, |
| 8498 | char *cmd) |
| 8499 | { |
| 8500 | char *token, *context = NULL; |
| 8501 | unsigned int enable = ~0, type = 0; |
| 8502 | u8 _addr[ETH_ALEN], _mask[ETH_ALEN]; |
| 8503 | u8 *addr = NULL, *mask = NULL; |
| 8504 | |
| 8505 | while ((token = str_token(cmd, " ", &context))) { |
| 8506 | if (os_strcasecmp(token, "scan") == 0) { |
| 8507 | type |= MAC_ADDR_RAND_SCAN; |
| 8508 | } else if (os_strcasecmp(token, "sched") == 0) { |
| 8509 | type |= MAC_ADDR_RAND_SCHED_SCAN; |
| 8510 | } else if (os_strcasecmp(token, "pno") == 0) { |
| 8511 | type |= MAC_ADDR_RAND_PNO; |
| 8512 | } else if (os_strcasecmp(token, "all") == 0) { |
| 8513 | type = wpa_s->mac_addr_rand_supported; |
| 8514 | } else if (os_strncasecmp(token, "enable=", 7) == 0) { |
| 8515 | enable = atoi(token + 7); |
| 8516 | } else if (os_strncasecmp(token, "addr=", 5) == 0) { |
| 8517 | addr = _addr; |
| 8518 | if (hwaddr_aton(token + 5, addr)) { |
| 8519 | wpa_printf(MSG_INFO, |
| 8520 | "CTRL: Invalid MAC address: %s", |
| 8521 | token); |
| 8522 | return -1; |
| 8523 | } |
| 8524 | } else if (os_strncasecmp(token, "mask=", 5) == 0) { |
| 8525 | mask = _mask; |
| 8526 | if (hwaddr_aton(token + 5, mask)) { |
| 8527 | wpa_printf(MSG_INFO, |
| 8528 | "CTRL: Invalid MAC address mask: %s", |
| 8529 | token); |
| 8530 | return -1; |
| 8531 | } |
| 8532 | } else { |
| 8533 | wpa_printf(MSG_INFO, |
| 8534 | "CTRL: Invalid MAC_RAND_SCAN parameter: %s", |
| 8535 | token); |
| 8536 | return -1; |
| 8537 | } |
| 8538 | } |
| 8539 | |
| 8540 | if (!type) { |
| 8541 | wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified"); |
| 8542 | return -1; |
| 8543 | } |
| 8544 | |
| 8545 | if ((wpa_s->mac_addr_rand_supported & type) != type) { |
| 8546 | wpa_printf(MSG_INFO, |
| 8547 | "CTRL: MAC_RAND_SCAN types=%u != supported=%u", |
| 8548 | type, wpa_s->mac_addr_rand_supported); |
| 8549 | return -1; |
| 8550 | } |
| 8551 | |
| 8552 | if (enable > 1) { |
| 8553 | wpa_printf(MSG_INFO, |
| 8554 | "CTRL: MAC_RAND_SCAN enable=<0/1> not specified"); |
| 8555 | return -1; |
| 8556 | } |
| 8557 | |
| 8558 | if (!enable) { |
| 8559 | wpas_mac_addr_rand_scan_clear(wpa_s, type); |
| 8560 | if (wpa_s->pno) { |
| 8561 | if (type & MAC_ADDR_RAND_PNO) { |
| 8562 | wpas_stop_pno(wpa_s); |
| 8563 | wpas_start_pno(wpa_s); |
| 8564 | } |
| 8565 | } else if (wpa_s->sched_scanning && |
| 8566 | (type & MAC_ADDR_RAND_SCHED_SCAN)) { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame^] | 8567 | wpas_scan_restart_sched_scan(wpa_s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8568 | } |
| 8569 | return 0; |
| 8570 | } |
| 8571 | |
| 8572 | if ((addr && !mask) || (!addr && mask)) { |
| 8573 | wpa_printf(MSG_INFO, |
| 8574 | "CTRL: MAC_RAND_SCAN invalid addr/mask combination"); |
| 8575 | return -1; |
| 8576 | } |
| 8577 | |
| 8578 | if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) { |
| 8579 | wpa_printf(MSG_INFO, |
| 8580 | "CTRL: MAC_RAND_SCAN cannot allow multicast address"); |
| 8581 | return -1; |
| 8582 | } |
| 8583 | |
| 8584 | if (type & MAC_ADDR_RAND_SCAN) { |
| 8585 | wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN, |
| 8586 | addr, mask); |
| 8587 | } |
| 8588 | |
| 8589 | if (type & MAC_ADDR_RAND_SCHED_SCAN) { |
| 8590 | wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN, |
| 8591 | addr, mask); |
| 8592 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame^] | 8593 | if (wpa_s->sched_scanning && !wpa_s->pno) |
| 8594 | wpas_scan_restart_sched_scan(wpa_s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8595 | } |
| 8596 | |
| 8597 | if (type & MAC_ADDR_RAND_PNO) { |
| 8598 | wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO, |
| 8599 | addr, mask); |
| 8600 | if (wpa_s->pno) { |
| 8601 | wpas_stop_pno(wpa_s); |
| 8602 | wpas_start_pno(wpa_s); |
| 8603 | } |
| 8604 | } |
| 8605 | |
| 8606 | return 0; |
| 8607 | } |
| 8608 | |
| 8609 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8610 | static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s, |
| 8611 | char *buf, size_t buflen) |
| 8612 | { |
| 8613 | size_t reply_len; |
| 8614 | |
| 8615 | reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen); |
| 8616 | #ifdef CONFIG_AP |
| 8617 | reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len], |
| 8618 | buflen - reply_len); |
| 8619 | #endif /* CONFIG_AP */ |
| 8620 | return reply_len; |
| 8621 | } |
| 8622 | |
| 8623 | |
| 8624 | static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s) |
| 8625 | { |
| 8626 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
| 8627 | #ifdef CONFIG_AP |
| 8628 | wpas_ap_pmksa_cache_flush(wpa_s); |
| 8629 | #endif /* CONFIG_AP */ |
| 8630 | } |
| 8631 | |
| 8632 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8633 | static int wpas_ctrl_cmd_debug_level(const char *cmd) |
| 8634 | { |
| 8635 | if (os_strcmp(cmd, "PING") == 0 || |
| 8636 | os_strncmp(cmd, "BSS ", 4) == 0 || |
| 8637 | os_strncmp(cmd, "GET_NETWORK ", 12) == 0 || |
| 8638 | os_strncmp(cmd, "STATUS", 6) == 0 || |
| 8639 | os_strncmp(cmd, "STA ", 4) == 0 || |
| 8640 | os_strncmp(cmd, "STA-", 4) == 0) |
| 8641 | return MSG_EXCESSIVE; |
| 8642 | return MSG_DEBUG; |
| 8643 | } |
| 8644 | |
| 8645 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8646 | char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, |
| 8647 | char *buf, size_t *resp_len) |
| 8648 | { |
| 8649 | char *reply; |
| 8650 | const int reply_size = 4096; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8651 | int reply_len; |
| 8652 | |
| 8653 | if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 || |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8654 | os_strncmp(buf, "SET_NETWORK ", 12) == 0) { |
| 8655 | if (wpa_debug_show_keys) |
| 8656 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8657 | "Control interface command '%s'", buf); |
| 8658 | else |
| 8659 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8660 | "Control interface command '%s [REMOVED]'", |
| 8661 | os_strncmp(buf, WPA_CTRL_RSP, |
| 8662 | os_strlen(WPA_CTRL_RSP)) == 0 ? |
| 8663 | WPA_CTRL_RSP : "SET_NETWORK"); |
| 8664 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 || |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 8665 | os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8666 | wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", |
| 8667 | (const u8 *) buf, os_strlen(buf)); |
| 8668 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8669 | int level = wpas_ctrl_cmd_debug_level(buf); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8670 | wpa_dbg(wpa_s, level, "Control interface command '%s'", buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8671 | } |
| 8672 | |
| 8673 | reply = os_malloc(reply_size); |
| 8674 | if (reply == NULL) { |
| 8675 | *resp_len = 1; |
| 8676 | return NULL; |
| 8677 | } |
| 8678 | |
| 8679 | os_memcpy(reply, "OK\n", 3); |
| 8680 | reply_len = 3; |
| 8681 | |
| 8682 | if (os_strcmp(buf, "PING") == 0) { |
| 8683 | os_memcpy(reply, "PONG\n", 5); |
| 8684 | reply_len = 5; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8685 | } else if (os_strcmp(buf, "IFNAME") == 0) { |
| 8686 | reply_len = os_strlen(wpa_s->ifname); |
| 8687 | os_memcpy(reply, wpa_s->ifname, reply_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8688 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
| 8689 | if (wpa_debug_reopen_file() < 0) |
| 8690 | reply_len = -1; |
| 8691 | } else if (os_strncmp(buf, "NOTE ", 5) == 0) { |
| 8692 | wpa_printf(MSG_INFO, "NOTE: %s", buf + 5); |
| 8693 | } else if (os_strcmp(buf, "MIB") == 0) { |
| 8694 | reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); |
| 8695 | if (reply_len >= 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8696 | reply_len += eapol_sm_get_mib(wpa_s->eapol, |
| 8697 | reply + reply_len, |
| 8698 | reply_size - reply_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8699 | } |
| 8700 | } else if (os_strncmp(buf, "STATUS", 6) == 0) { |
| 8701 | reply_len = wpa_supplicant_ctrl_iface_status( |
| 8702 | wpa_s, buf + 6, reply, reply_size); |
| 8703 | } else if (os_strcmp(buf, "PMKSA") == 0) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8704 | reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8705 | } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8706 | wpas_ctrl_iface_pmksa_flush(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8707 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
| 8708 | if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) |
| 8709 | reply_len = -1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8710 | } else if (os_strncmp(buf, "DUMP", 4) == 0) { |
| 8711 | reply_len = wpa_config_dump_values(wpa_s->conf, |
| 8712 | reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8713 | } else if (os_strncmp(buf, "GET ", 4) == 0) { |
| 8714 | reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4, |
| 8715 | reply, reply_size); |
| 8716 | } else if (os_strcmp(buf, "LOGON") == 0) { |
| 8717 | eapol_sm_notify_logoff(wpa_s->eapol, FALSE); |
| 8718 | } else if (os_strcmp(buf, "LOGOFF") == 0) { |
| 8719 | eapol_sm_notify_logoff(wpa_s->eapol, TRUE); |
| 8720 | } else if (os_strcmp(buf, "REASSOCIATE") == 0) { |
| 8721 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 8722 | reply_len = -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8723 | else |
| 8724 | wpas_request_connection(wpa_s); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 8725 | } else if (os_strcmp(buf, "REATTACH") == 0) { |
| 8726 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED || |
| 8727 | !wpa_s->current_ssid) |
| 8728 | reply_len = -1; |
| 8729 | else { |
| 8730 | wpa_s->reattach = 1; |
| 8731 | wpas_request_connection(wpa_s); |
| 8732 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8733 | } else if (os_strcmp(buf, "RECONNECT") == 0) { |
| 8734 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 8735 | reply_len = -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8736 | else if (wpa_s->disconnected) |
| 8737 | wpas_request_connection(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8738 | #ifdef IEEE8021X_EAPOL |
| 8739 | } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { |
| 8740 | if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) |
| 8741 | reply_len = -1; |
| 8742 | #endif /* IEEE8021X_EAPOL */ |
| 8743 | #ifdef CONFIG_PEERKEY |
| 8744 | } else if (os_strncmp(buf, "STKSTART ", 9) == 0) { |
| 8745 | if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9)) |
| 8746 | reply_len = -1; |
| 8747 | #endif /* CONFIG_PEERKEY */ |
| 8748 | #ifdef CONFIG_IEEE80211R |
| 8749 | } else if (os_strncmp(buf, "FT_DS ", 6) == 0) { |
| 8750 | if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6)) |
| 8751 | reply_len = -1; |
| 8752 | #endif /* CONFIG_IEEE80211R */ |
| 8753 | #ifdef CONFIG_WPS |
| 8754 | } else if (os_strcmp(buf, "WPS_PBC") == 0) { |
| 8755 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL); |
| 8756 | if (res == -2) { |
| 8757 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); |
| 8758 | reply_len = 17; |
| 8759 | } else if (res) |
| 8760 | reply_len = -1; |
| 8761 | } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) { |
| 8762 | int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8); |
| 8763 | if (res == -2) { |
| 8764 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); |
| 8765 | reply_len = 17; |
| 8766 | } else if (res) |
| 8767 | reply_len = -1; |
| 8768 | } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) { |
| 8769 | reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8, |
| 8770 | reply, |
| 8771 | reply_size); |
| 8772 | } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) { |
| 8773 | reply_len = wpa_supplicant_ctrl_iface_wps_check_pin( |
| 8774 | wpa_s, buf + 14, reply, reply_size); |
| 8775 | } else if (os_strcmp(buf, "WPS_CANCEL") == 0) { |
| 8776 | if (wpas_wps_cancel(wpa_s)) |
| 8777 | reply_len = -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8778 | #ifdef CONFIG_WPS_NFC |
| 8779 | } else if (os_strcmp(buf, "WPS_NFC") == 0) { |
| 8780 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL)) |
| 8781 | reply_len = -1; |
| 8782 | } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) { |
| 8783 | if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8)) |
| 8784 | reply_len = -1; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8785 | } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) { |
| 8786 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token( |
| 8787 | wpa_s, buf + 21, reply, reply_size); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8788 | } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) { |
| 8789 | reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token( |
| 8790 | wpa_s, buf + 14, reply, reply_size); |
| 8791 | } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) { |
| 8792 | if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s, |
| 8793 | buf + 17)) |
| 8794 | reply_len = -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8795 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) { |
| 8796 | reply_len = wpas_ctrl_nfc_get_handover_req( |
| 8797 | wpa_s, buf + 21, reply, reply_size); |
| 8798 | } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) { |
| 8799 | reply_len = wpas_ctrl_nfc_get_handover_sel( |
| 8800 | wpa_s, buf + 21, reply, reply_size); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8801 | } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) { |
| 8802 | if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20)) |
| 8803 | reply_len = -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8804 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8805 | } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) { |
| 8806 | if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8)) |
| 8807 | reply_len = -1; |
| 8808 | #ifdef CONFIG_AP |
| 8809 | } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) { |
| 8810 | reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin( |
| 8811 | wpa_s, buf + 11, reply, reply_size); |
| 8812 | #endif /* CONFIG_AP */ |
| 8813 | #ifdef CONFIG_WPS_ER |
| 8814 | } else if (os_strcmp(buf, "WPS_ER_START") == 0) { |
| 8815 | if (wpas_wps_er_start(wpa_s, NULL)) |
| 8816 | reply_len = -1; |
| 8817 | } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) { |
| 8818 | if (wpas_wps_er_start(wpa_s, buf + 13)) |
| 8819 | reply_len = -1; |
| 8820 | } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8821 | wpas_wps_er_stop(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8822 | } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) { |
| 8823 | if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11)) |
| 8824 | reply_len = -1; |
| 8825 | } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) { |
| 8826 | int ret = wpas_wps_er_pbc(wpa_s, buf + 11); |
| 8827 | if (ret == -2) { |
| 8828 | os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17); |
| 8829 | reply_len = 17; |
| 8830 | } else if (ret == -3) { |
| 8831 | os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18); |
| 8832 | reply_len = 18; |
| 8833 | } else if (ret == -4) { |
| 8834 | os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20); |
| 8835 | reply_len = 20; |
| 8836 | } else if (ret) |
| 8837 | reply_len = -1; |
| 8838 | } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) { |
| 8839 | if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13)) |
| 8840 | reply_len = -1; |
| 8841 | } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) { |
| 8842 | if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s, |
| 8843 | buf + 18)) |
| 8844 | reply_len = -1; |
| 8845 | } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) { |
| 8846 | if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14)) |
| 8847 | reply_len = -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8848 | #ifdef CONFIG_WPS_NFC |
| 8849 | } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) { |
| 8850 | reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( |
| 8851 | wpa_s, buf + 24, reply, reply_size); |
| 8852 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8853 | #endif /* CONFIG_WPS_ER */ |
| 8854 | #endif /* CONFIG_WPS */ |
| 8855 | #ifdef CONFIG_IBSS_RSN |
| 8856 | } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) { |
| 8857 | if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) |
| 8858 | reply_len = -1; |
| 8859 | #endif /* CONFIG_IBSS_RSN */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8860 | #ifdef CONFIG_MESH |
| 8861 | } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) { |
| 8862 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( |
| 8863 | wpa_s, buf + 19, reply, reply_size); |
| 8864 | } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) { |
| 8865 | reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add( |
| 8866 | wpa_s, "", reply, reply_size); |
| 8867 | } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) { |
| 8868 | if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15)) |
| 8869 | reply_len = -1; |
| 8870 | } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) { |
| 8871 | if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s, |
| 8872 | buf + 18)) |
| 8873 | reply_len = -1; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8874 | } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) { |
| 8875 | if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17)) |
| 8876 | reply_len = -1; |
| 8877 | } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) { |
| 8878 | if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14)) |
| 8879 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8880 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8881 | #ifdef CONFIG_P2P |
| 8882 | } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8883 | if (p2p_ctrl_find(wpa_s, buf + 8)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8884 | reply_len = -1; |
| 8885 | } else if (os_strcmp(buf, "P2P_FIND") == 0) { |
| 8886 | if (p2p_ctrl_find(wpa_s, "")) |
| 8887 | reply_len = -1; |
| 8888 | } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) { |
| 8889 | wpas_p2p_stop_find(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8890 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) { |
| 8891 | if (p2p_ctrl_asp_provision(wpa_s, buf + 18)) |
| 8892 | reply_len = -1; |
| 8893 | } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) { |
| 8894 | if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23)) |
| 8895 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8896 | } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) { |
| 8897 | reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply, |
| 8898 | reply_size); |
| 8899 | } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) { |
| 8900 | if (p2p_ctrl_listen(wpa_s, buf + 11)) |
| 8901 | reply_len = -1; |
| 8902 | } else if (os_strcmp(buf, "P2P_LISTEN") == 0) { |
| 8903 | if (p2p_ctrl_listen(wpa_s, "")) |
| 8904 | reply_len = -1; |
| 8905 | } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) { |
| 8906 | if (wpas_p2p_group_remove(wpa_s, buf + 17)) |
| 8907 | reply_len = -1; |
| 8908 | } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8909 | if (p2p_ctrl_group_add(wpa_s, "")) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8910 | reply_len = -1; |
| 8911 | } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) { |
| 8912 | if (p2p_ctrl_group_add(wpa_s, buf + 14)) |
| 8913 | reply_len = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8914 | } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) { |
| 8915 | reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply, |
| 8916 | reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8917 | } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) { |
| 8918 | if (p2p_ctrl_prov_disc(wpa_s, buf + 14)) |
| 8919 | reply_len = -1; |
| 8920 | } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) { |
| 8921 | reply_len = p2p_get_passphrase(wpa_s, reply, reply_size); |
| 8922 | } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) { |
| 8923 | reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply, |
| 8924 | reply_size); |
| 8925 | } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) { |
| 8926 | if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0) |
| 8927 | reply_len = -1; |
| 8928 | } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) { |
| 8929 | if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0) |
| 8930 | reply_len = -1; |
| 8931 | } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) { |
| 8932 | wpas_p2p_sd_service_update(wpa_s); |
| 8933 | } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) { |
| 8934 | if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0) |
| 8935 | reply_len = -1; |
| 8936 | } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) { |
| 8937 | wpas_p2p_service_flush(wpa_s); |
| 8938 | } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) { |
| 8939 | if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0) |
| 8940 | reply_len = -1; |
| 8941 | } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) { |
| 8942 | if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0) |
| 8943 | reply_len = -1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8944 | } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) { |
| 8945 | if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0) |
| 8946 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8947 | } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) { |
| 8948 | if (p2p_ctrl_reject(wpa_s, buf + 11) < 0) |
| 8949 | reply_len = -1; |
| 8950 | } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) { |
| 8951 | if (p2p_ctrl_invite(wpa_s, buf + 11) < 0) |
| 8952 | reply_len = -1; |
| 8953 | } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) { |
| 8954 | reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply, |
| 8955 | reply_size); |
| 8956 | } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) { |
| 8957 | if (p2p_ctrl_set(wpa_s, buf + 8) < 0) |
| 8958 | reply_len = -1; |
| 8959 | } else if (os_strcmp(buf, "P2P_FLUSH") == 0) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8960 | p2p_ctrl_flush(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8961 | } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) { |
| 8962 | if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0) |
| 8963 | reply_len = -1; |
| 8964 | } else if (os_strcmp(buf, "P2P_CANCEL") == 0) { |
| 8965 | if (wpas_p2p_cancel(wpa_s)) |
| 8966 | reply_len = -1; |
| 8967 | } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) { |
| 8968 | if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0) |
| 8969 | reply_len = -1; |
| 8970 | } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) { |
| 8971 | if (p2p_ctrl_presence_req(wpa_s, "") < 0) |
| 8972 | reply_len = -1; |
| 8973 | } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) { |
| 8974 | if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0) |
| 8975 | reply_len = -1; |
| 8976 | } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) { |
| 8977 | if (p2p_ctrl_ext_listen(wpa_s, "") < 0) |
| 8978 | reply_len = -1; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8979 | } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) { |
| 8980 | if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0) |
| 8981 | reply_len = -1; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8982 | } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) { |
| 8983 | if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13)) |
| 8984 | reply_len = -1; |
| 8985 | } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) { |
| 8986 | if (wpas_p2p_lo_stop(wpa_s)) |
| 8987 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8988 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8989 | #ifdef CONFIG_WIFI_DISPLAY |
| 8990 | } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) { |
| 8991 | if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0) |
| 8992 | reply_len = -1; |
| 8993 | } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) { |
| 8994 | reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16, |
| 8995 | reply, reply_size); |
| 8996 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8997 | #ifdef CONFIG_INTERWORKING |
| 8998 | } else if (os_strcmp(buf, "FETCH_ANQP") == 0) { |
| 8999 | if (interworking_fetch_anqp(wpa_s) < 0) |
| 9000 | reply_len = -1; |
| 9001 | } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) { |
| 9002 | interworking_stop_fetch_anqp(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9003 | } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) { |
| 9004 | if (ctrl_interworking_select(wpa_s, NULL) < 0) |
| 9005 | reply_len = -1; |
| 9006 | } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) { |
| 9007 | if (ctrl_interworking_select(wpa_s, buf + 20) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9008 | reply_len = -1; |
| 9009 | } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9010 | if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9011 | reply_len = -1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9012 | } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) { |
| 9013 | int id; |
| 9014 | |
| 9015 | id = ctrl_interworking_connect(wpa_s, buf + 25, 1); |
| 9016 | if (id < 0) |
| 9017 | reply_len = -1; |
| 9018 | else { |
| 9019 | reply_len = os_snprintf(reply, reply_size, "%d\n", id); |
| 9020 | if (os_snprintf_error(reply_size, reply_len)) |
| 9021 | reply_len = -1; |
| 9022 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9023 | } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) { |
| 9024 | if (get_anqp(wpa_s, buf + 9) < 0) |
| 9025 | reply_len = -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9026 | } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) { |
| 9027 | if (gas_request(wpa_s, buf + 12) < 0) |
| 9028 | reply_len = -1; |
| 9029 | } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) { |
| 9030 | reply_len = gas_response_get(wpa_s, buf + 17, reply, |
| 9031 | reply_size); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9032 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9033 | #ifdef CONFIG_HS20 |
| 9034 | } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) { |
| 9035 | if (get_hs20_anqp(wpa_s, buf + 14) < 0) |
| 9036 | reply_len = -1; |
| 9037 | } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) { |
| 9038 | if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0) |
| 9039 | reply_len = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 9040 | } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 9041 | if (hs20_icon_request(wpa_s, buf + 18, 0) < 0) |
| 9042 | reply_len = -1; |
| 9043 | } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) { |
| 9044 | if (hs20_icon_request(wpa_s, buf + 14, 1) < 0) |
| 9045 | reply_len = -1; |
| 9046 | } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) { |
| 9047 | reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size); |
| 9048 | } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) { |
| 9049 | if (del_hs20_icon(wpa_s, buf + 14) < 0) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 9050 | reply_len = -1; |
| 9051 | } else if (os_strcmp(buf, "FETCH_OSU") == 0) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9052 | if (hs20_fetch_osu(wpa_s, 0) < 0) |
| 9053 | reply_len = -1; |
| 9054 | } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) { |
| 9055 | if (hs20_fetch_osu(wpa_s, 1) < 0) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 9056 | reply_len = -1; |
| 9057 | } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) { |
| 9058 | hs20_cancel_fetch_osu(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9059 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9060 | } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) |
| 9061 | { |
| 9062 | if (wpa_supplicant_ctrl_iface_ctrl_rsp( |
| 9063 | wpa_s, buf + os_strlen(WPA_CTRL_RSP))) |
| 9064 | reply_len = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 9065 | else { |
| 9066 | /* |
| 9067 | * Notify response from timeout to allow the control |
| 9068 | * interface response to be sent first. |
| 9069 | */ |
| 9070 | eloop_register_timeout(0, 0, wpas_ctrl_eapol_response, |
| 9071 | wpa_s, NULL); |
| 9072 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9073 | } else if (os_strcmp(buf, "RECONFIGURE") == 0) { |
| 9074 | if (wpa_supplicant_reload_configuration(wpa_s)) |
| 9075 | reply_len = -1; |
| 9076 | } else if (os_strcmp(buf, "TERMINATE") == 0) { |
| 9077 | wpa_supplicant_terminate_proc(wpa_s->global); |
| 9078 | } else if (os_strncmp(buf, "BSSID ", 6) == 0) { |
| 9079 | if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) |
| 9080 | reply_len = -1; |
Dmitry Shmidt | e19501d | 2011-03-16 14:32:18 -0700 | [diff] [blame] | 9081 | } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9082 | reply_len = wpa_supplicant_ctrl_iface_blacklist( |
| 9083 | wpa_s, buf + 9, reply, reply_size); |
| 9084 | } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) { |
| 9085 | reply_len = wpa_supplicant_ctrl_iface_log_level( |
| 9086 | wpa_s, buf + 9, reply, reply_size); |
Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 9087 | } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) { |
| 9088 | reply_len = wpa_supplicant_ctrl_iface_list_networks( |
| 9089 | wpa_s, buf + 14, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9090 | } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { |
| 9091 | reply_len = wpa_supplicant_ctrl_iface_list_networks( |
Vinit Deshpande | da134e9 | 2014-12-02 10:59:29 -0800 | [diff] [blame] | 9092 | wpa_s, NULL, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9093 | } else if (os_strcmp(buf, "DISCONNECT") == 0) { |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 9094 | wpas_request_disconnection(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9095 | } else if (os_strcmp(buf, "SCAN") == 0) { |
| 9096 | wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len); |
| 9097 | } else if (os_strncmp(buf, "SCAN ", 5) == 0) { |
| 9098 | wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9099 | } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { |
| 9100 | reply_len = wpa_supplicant_ctrl_iface_scan_results( |
| 9101 | wpa_s, reply, reply_size); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9102 | } else if (os_strcmp(buf, "ABORT_SCAN") == 0) { |
| 9103 | if (wpas_abort_ongoing_scan(wpa_s) < 0) |
| 9104 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9105 | } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { |
| 9106 | if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) |
| 9107 | reply_len = -1; |
| 9108 | } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { |
| 9109 | if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) |
| 9110 | reply_len = -1; |
| 9111 | } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { |
| 9112 | if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) |
| 9113 | reply_len = -1; |
| 9114 | } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { |
| 9115 | reply_len = wpa_supplicant_ctrl_iface_add_network( |
| 9116 | wpa_s, reply, reply_size); |
| 9117 | } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { |
| 9118 | if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) |
| 9119 | reply_len = -1; |
| 9120 | } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { |
| 9121 | if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) |
| 9122 | reply_len = -1; |
| 9123 | } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { |
| 9124 | reply_len = wpa_supplicant_ctrl_iface_get_network( |
| 9125 | wpa_s, buf + 12, reply, reply_size); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 9126 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9127 | if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12, |
| 9128 | wpa_s)) |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 9129 | reply_len = -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9130 | } else if (os_strcmp(buf, "LIST_CREDS") == 0) { |
| 9131 | reply_len = wpa_supplicant_ctrl_iface_list_creds( |
| 9132 | wpa_s, reply, reply_size); |
| 9133 | } else if (os_strcmp(buf, "ADD_CRED") == 0) { |
| 9134 | reply_len = wpa_supplicant_ctrl_iface_add_cred( |
| 9135 | wpa_s, reply, reply_size); |
| 9136 | } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) { |
| 9137 | if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12)) |
| 9138 | reply_len = -1; |
| 9139 | } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) { |
| 9140 | if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9)) |
| 9141 | reply_len = -1; |
Dmitry Shmidt | 0cfd5f7 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 9142 | } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) { |
| 9143 | reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9, |
| 9144 | reply, |
| 9145 | reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9146 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 9147 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { |
| 9148 | if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) |
| 9149 | reply_len = -1; |
| 9150 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 9151 | } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { |
| 9152 | reply_len = wpa_supplicant_ctrl_iface_get_capability( |
| 9153 | wpa_s, buf + 15, reply, reply_size); |
| 9154 | } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { |
| 9155 | if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) |
| 9156 | reply_len = -1; |
| 9157 | } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) { |
| 9158 | if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14)) |
| 9159 | reply_len = -1; |
| 9160 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
| 9161 | reply_len = wpa_supplicant_global_iface_list( |
| 9162 | wpa_s->global, reply, reply_size); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 9163 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9164 | reply_len = wpa_supplicant_global_iface_interfaces( |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 9165 | wpa_s->global, buf + 10, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9166 | } else if (os_strncmp(buf, "BSS ", 4) == 0) { |
| 9167 | reply_len = wpa_supplicant_ctrl_iface_bss( |
| 9168 | wpa_s, buf + 4, reply, reply_size); |
| 9169 | #ifdef CONFIG_AP |
| 9170 | } else if (os_strcmp(buf, "STA-FIRST") == 0) { |
| 9171 | reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size); |
| 9172 | } else if (os_strncmp(buf, "STA ", 4) == 0) { |
| 9173 | reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply, |
| 9174 | reply_size); |
| 9175 | } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) { |
| 9176 | reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply, |
| 9177 | reply_size); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9178 | } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) { |
| 9179 | if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15)) |
| 9180 | reply_len = -1; |
| 9181 | } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) { |
| 9182 | if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13)) |
| 9183 | reply_len = -1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9184 | } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) { |
| 9185 | if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12)) |
| 9186 | reply_len = -1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9187 | } else if (os_strcmp(buf, "STOP_AP") == 0) { |
| 9188 | if (wpas_ap_stop_ap(wpa_s)) |
| 9189 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9190 | #endif /* CONFIG_AP */ |
| 9191 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
| 9192 | wpas_notify_suspend(wpa_s->global); |
| 9193 | } else if (os_strcmp(buf, "RESUME") == 0) { |
| 9194 | wpas_notify_resume(wpa_s->global); |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 9195 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9196 | } else if (os_strcmp(buf, "DROP_SA") == 0) { |
| 9197 | wpa_supplicant_ctrl_iface_drop_sa(wpa_s); |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 9198 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9199 | } else if (os_strncmp(buf, "ROAM ", 5) == 0) { |
| 9200 | if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5)) |
| 9201 | reply_len = -1; |
| 9202 | } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9203 | wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9204 | } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) { |
| 9205 | if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15)) |
| 9206 | reply_len = -1; |
| 9207 | } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) { |
| 9208 | if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s, |
| 9209 | buf + 17)) |
| 9210 | reply_len = -1; |
Dmitry Shmidt | f48e4f9 | 2012-08-24 11:14:44 -0700 | [diff] [blame] | 9211 | } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9212 | wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9213 | #ifdef CONFIG_TDLS |
| 9214 | } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) { |
| 9215 | if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14)) |
| 9216 | reply_len = -1; |
| 9217 | } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) { |
| 9218 | if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11)) |
| 9219 | reply_len = -1; |
| 9220 | } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) { |
| 9221 | if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14)) |
| 9222 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9223 | } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) { |
| 9224 | if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s, |
| 9225 | buf + 17)) |
| 9226 | reply_len = -1; |
| 9227 | } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) { |
| 9228 | if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s, |
| 9229 | buf + 24)) |
| 9230 | reply_len = -1; |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 9231 | } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) { |
| 9232 | reply_len = wpa_supplicant_ctrl_iface_tdls_link_status( |
| 9233 | wpa_s, buf + 17, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9234 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9235 | } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) { |
| 9236 | reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size); |
| 9237 | } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) { |
| 9238 | if (wmm_ac_ctrl_addts(wpa_s, buf + 13)) |
| 9239 | reply_len = -1; |
| 9240 | } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) { |
| 9241 | if (wmm_ac_ctrl_delts(wpa_s, buf + 13)) |
| 9242 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9243 | } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) { |
| 9244 | reply_len = wpa_supplicant_signal_poll(wpa_s, reply, |
| 9245 | reply_size); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 9246 | } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) { |
| 9247 | if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14)) |
| 9248 | reply_len = -1; |
Yuhao Zheng | fcd6f21 | 2012-07-27 10:37:52 -0700 | [diff] [blame] | 9249 | } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) { |
| 9250 | reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply, |
| 9251 | reply_size); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9252 | #ifdef CONFIG_AUTOSCAN |
| 9253 | } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) { |
| 9254 | if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9)) |
| 9255 | reply_len = -1; |
| 9256 | #endif /* CONFIG_AUTOSCAN */ |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9257 | } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) { |
| 9258 | reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply, |
| 9259 | reply_size); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9260 | #ifdef ANDROID |
Dmitry Shmidt | bd567ad | 2011-05-09 14:17:09 -0700 | [diff] [blame] | 9261 | } else if (os_strncmp(buf, "DRIVER ", 7) == 0) { |
| 9262 | reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply, |
| 9263 | reply_size); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9264 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9265 | } else if (os_strncmp(buf, "VENDOR ", 7) == 0) { |
| 9266 | reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply, |
| 9267 | reply_size); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9268 | } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 9269 | pmksa_cache_clear_current(wpa_s->wpa); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9270 | eapol_sm_request_reauth(wpa_s->eapol); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 9271 | #ifdef CONFIG_WNM |
| 9272 | } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) { |
| 9273 | if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10)) |
| 9274 | reply_len = -1; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 9275 | } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) { |
| 9276 | if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14)) |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 9277 | reply_len = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 9278 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 9279 | } else if (os_strcmp(buf, "FLUSH") == 0) { |
| 9280 | wpa_supplicant_ctrl_iface_flush(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9281 | } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) { |
| 9282 | reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply, |
| 9283 | reply_size); |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 9284 | #ifdef CONFIG_TESTING_OPTIONS |
| 9285 | } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) { |
| 9286 | if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0) |
| 9287 | reply_len = -1; |
| 9288 | } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) { |
| 9289 | wpas_ctrl_iface_mgmt_tx_done(wpa_s); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9290 | } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) { |
| 9291 | if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0) |
| 9292 | reply_len = -1; |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 9293 | } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) { |
| 9294 | if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0) |
| 9295 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9296 | } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) { |
| 9297 | if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0) |
| 9298 | reply_len = -1; |
| 9299 | } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) { |
| 9300 | if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0) |
| 9301 | reply_len = -1; |
| 9302 | } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) { |
| 9303 | if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0) |
| 9304 | reply_len = -1; |
| 9305 | } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) { |
| 9306 | if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0) |
| 9307 | reply_len = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9308 | } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) { |
| 9309 | if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0) |
| 9310 | reply_len = -1; |
| 9311 | } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) { |
| 9312 | reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9313 | } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) { |
| 9314 | if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0) |
| 9315 | reply_len = -1; |
| 9316 | } else if (os_strcmp(buf, "GET_FAIL") == 0) { |
| 9317 | reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size); |
Jouni Malinen | c481836 | 2015-10-04 11:45:13 +0300 | [diff] [blame] | 9318 | } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) { |
| 9319 | if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0) |
| 9320 | reply_len = -1; |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 9321 | } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) { |
| 9322 | if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0) |
| 9323 | reply_len = -1; |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 9324 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 9325 | } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) { |
| 9326 | if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0) |
| 9327 | reply_len = -1; |
| 9328 | } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) { |
| 9329 | reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply, |
| 9330 | reply_size); |
| 9331 | } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) { |
| 9332 | if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0) |
| 9333 | reply_len = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9334 | } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) { |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9335 | if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9336 | reply_len = -1; |
| 9337 | } else if (os_strcmp(buf, "ERP_FLUSH") == 0) { |
| 9338 | wpas_ctrl_iface_erp_flush(wpa_s); |
| 9339 | } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) { |
| 9340 | if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14)) |
| 9341 | reply_len = -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9342 | } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) { |
| 9343 | reply_len = wpas_ctrl_iface_get_pref_freq_list( |
| 9344 | wpa_s, buf + 19, reply, reply_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9345 | } else { |
| 9346 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); |
| 9347 | reply_len = 16; |
| 9348 | } |
| 9349 | |
| 9350 | if (reply_len < 0) { |
| 9351 | os_memcpy(reply, "FAIL\n", 5); |
| 9352 | reply_len = 5; |
| 9353 | } |
| 9354 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9355 | *resp_len = reply_len; |
| 9356 | return reply; |
| 9357 | } |
| 9358 | |
| 9359 | |
| 9360 | static int wpa_supplicant_global_iface_add(struct wpa_global *global, |
| 9361 | char *cmd) |
| 9362 | { |
| 9363 | struct wpa_interface iface; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 9364 | char *pos, *extra; |
| 9365 | struct wpa_supplicant *wpa_s; |
| 9366 | unsigned int create_iface = 0; |
| 9367 | u8 mac_addr[ETH_ALEN]; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9368 | enum wpa_driver_if_type type = WPA_IF_STATION; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9369 | |
| 9370 | /* |
| 9371 | * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param> |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9372 | * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]] |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9373 | */ |
| 9374 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd); |
| 9375 | |
| 9376 | os_memset(&iface, 0, sizeof(iface)); |
| 9377 | |
| 9378 | do { |
| 9379 | iface.ifname = pos = cmd; |
| 9380 | pos = os_strchr(pos, '\t'); |
| 9381 | if (pos) |
| 9382 | *pos++ = '\0'; |
| 9383 | if (iface.ifname[0] == '\0') |
| 9384 | return -1; |
| 9385 | if (pos == NULL) |
| 9386 | break; |
| 9387 | |
| 9388 | iface.confname = pos; |
| 9389 | pos = os_strchr(pos, '\t'); |
| 9390 | if (pos) |
| 9391 | *pos++ = '\0'; |
| 9392 | if (iface.confname[0] == '\0') |
| 9393 | iface.confname = NULL; |
| 9394 | if (pos == NULL) |
| 9395 | break; |
| 9396 | |
| 9397 | iface.driver = pos; |
| 9398 | pos = os_strchr(pos, '\t'); |
| 9399 | if (pos) |
| 9400 | *pos++ = '\0'; |
| 9401 | if (iface.driver[0] == '\0') |
| 9402 | iface.driver = NULL; |
| 9403 | if (pos == NULL) |
| 9404 | break; |
| 9405 | |
| 9406 | iface.ctrl_interface = pos; |
| 9407 | pos = os_strchr(pos, '\t'); |
| 9408 | if (pos) |
| 9409 | *pos++ = '\0'; |
| 9410 | if (iface.ctrl_interface[0] == '\0') |
| 9411 | iface.ctrl_interface = NULL; |
| 9412 | if (pos == NULL) |
| 9413 | break; |
| 9414 | |
| 9415 | iface.driver_param = pos; |
| 9416 | pos = os_strchr(pos, '\t'); |
| 9417 | if (pos) |
| 9418 | *pos++ = '\0'; |
| 9419 | if (iface.driver_param[0] == '\0') |
| 9420 | iface.driver_param = NULL; |
| 9421 | if (pos == NULL) |
| 9422 | break; |
| 9423 | |
| 9424 | iface.bridge_ifname = pos; |
| 9425 | pos = os_strchr(pos, '\t'); |
| 9426 | if (pos) |
| 9427 | *pos++ = '\0'; |
| 9428 | if (iface.bridge_ifname[0] == '\0') |
| 9429 | iface.bridge_ifname = NULL; |
| 9430 | if (pos == NULL) |
| 9431 | break; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 9432 | |
| 9433 | extra = pos; |
| 9434 | pos = os_strchr(pos, '\t'); |
| 9435 | if (pos) |
| 9436 | *pos++ = '\0'; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9437 | if (!extra[0]) |
| 9438 | break; |
| 9439 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9440 | if (os_strcmp(extra, "create") == 0) { |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 9441 | create_iface = 1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9442 | if (!pos) |
| 9443 | break; |
| 9444 | |
| 9445 | if (os_strcmp(pos, "sta") == 0) { |
| 9446 | type = WPA_IF_STATION; |
| 9447 | } else if (os_strcmp(pos, "ap") == 0) { |
| 9448 | type = WPA_IF_AP_BSS; |
| 9449 | } else { |
| 9450 | wpa_printf(MSG_DEBUG, |
| 9451 | "INTERFACE_ADD unsupported interface type: '%s'", |
| 9452 | pos); |
| 9453 | return -1; |
| 9454 | } |
| 9455 | } else { |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9456 | wpa_printf(MSG_DEBUG, |
| 9457 | "INTERFACE_ADD unsupported extra parameter: '%s'", |
| 9458 | extra); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 9459 | return -1; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9460 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9461 | } while (0); |
| 9462 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 9463 | if (create_iface) { |
| 9464 | wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'", |
| 9465 | iface.ifname); |
| 9466 | if (!global->ifaces) |
| 9467 | return -1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9468 | if (wpa_drv_if_add(global->ifaces, type, iface.ifname, |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 9469 | NULL, NULL, NULL, mac_addr, NULL) < 0) { |
| 9470 | wpa_printf(MSG_ERROR, |
| 9471 | "CTRL_IFACE interface creation failed"); |
| 9472 | return -1; |
| 9473 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9474 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 9475 | wpa_printf(MSG_DEBUG, |
| 9476 | "CTRL_IFACE interface '%s' created with MAC addr: " |
| 9477 | MACSTR, iface.ifname, MAC2STR(mac_addr)); |
| 9478 | } |
| 9479 | |
| 9480 | if (wpa_supplicant_get_iface(global, iface.ifname)) |
| 9481 | goto fail; |
| 9482 | |
| 9483 | wpa_s = wpa_supplicant_add_iface(global, &iface, NULL); |
| 9484 | if (!wpa_s) |
| 9485 | goto fail; |
| 9486 | wpa_s->added_vif = create_iface; |
| 9487 | return 0; |
| 9488 | |
| 9489 | fail: |
| 9490 | if (create_iface) |
| 9491 | wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname); |
| 9492 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9493 | } |
| 9494 | |
| 9495 | |
| 9496 | static int wpa_supplicant_global_iface_remove(struct wpa_global *global, |
| 9497 | char *cmd) |
| 9498 | { |
| 9499 | struct wpa_supplicant *wpa_s; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 9500 | int ret; |
| 9501 | unsigned int delete_iface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9502 | |
| 9503 | wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd); |
| 9504 | |
| 9505 | wpa_s = wpa_supplicant_get_iface(global, cmd); |
| 9506 | if (wpa_s == NULL) |
| 9507 | return -1; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 9508 | delete_iface = wpa_s->added_vif; |
| 9509 | ret = wpa_supplicant_remove_iface(global, wpa_s, 0); |
| 9510 | if (!ret && delete_iface) { |
| 9511 | wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'", |
| 9512 | cmd); |
| 9513 | ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd); |
| 9514 | } |
| 9515 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9516 | } |
| 9517 | |
| 9518 | |
| 9519 | static void wpa_free_iface_info(struct wpa_interface_info *iface) |
| 9520 | { |
| 9521 | struct wpa_interface_info *prev; |
| 9522 | |
| 9523 | while (iface) { |
| 9524 | prev = iface; |
| 9525 | iface = iface->next; |
| 9526 | |
| 9527 | os_free(prev->ifname); |
| 9528 | os_free(prev->desc); |
| 9529 | os_free(prev); |
| 9530 | } |
| 9531 | } |
| 9532 | |
| 9533 | |
| 9534 | static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
| 9535 | char *buf, int len) |
| 9536 | { |
| 9537 | int i, res; |
| 9538 | struct wpa_interface_info *iface = NULL, *last = NULL, *tmp; |
| 9539 | char *pos, *end; |
| 9540 | |
| 9541 | for (i = 0; wpa_drivers[i]; i++) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 9542 | const struct wpa_driver_ops *drv = wpa_drivers[i]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9543 | if (drv->get_interfaces == NULL) |
| 9544 | continue; |
| 9545 | tmp = drv->get_interfaces(global->drv_priv[i]); |
| 9546 | if (tmp == NULL) |
| 9547 | continue; |
| 9548 | |
| 9549 | if (last == NULL) |
| 9550 | iface = last = tmp; |
| 9551 | else |
| 9552 | last->next = tmp; |
| 9553 | while (last->next) |
| 9554 | last = last->next; |
| 9555 | } |
| 9556 | |
| 9557 | pos = buf; |
| 9558 | end = buf + len; |
| 9559 | for (tmp = iface; tmp; tmp = tmp->next) { |
| 9560 | res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n", |
| 9561 | tmp->drv_name, tmp->ifname, |
| 9562 | tmp->desc ? tmp->desc : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9563 | if (os_snprintf_error(end - pos, res)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9564 | *pos = '\0'; |
| 9565 | break; |
| 9566 | } |
| 9567 | pos += res; |
| 9568 | } |
| 9569 | |
| 9570 | wpa_free_iface_info(iface); |
| 9571 | |
| 9572 | return pos - buf; |
| 9573 | } |
| 9574 | |
| 9575 | |
| 9576 | static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 9577 | const char *input, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9578 | char *buf, int len) |
| 9579 | { |
| 9580 | int res; |
| 9581 | char *pos, *end; |
| 9582 | struct wpa_supplicant *wpa_s; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 9583 | int show_ctrl = 0; |
| 9584 | |
| 9585 | if (input) |
| 9586 | show_ctrl = !!os_strstr(input, "ctrl"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9587 | |
| 9588 | wpa_s = global->ifaces; |
| 9589 | pos = buf; |
| 9590 | end = buf + len; |
| 9591 | |
| 9592 | while (wpa_s) { |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 9593 | if (show_ctrl) |
| 9594 | res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n", |
| 9595 | wpa_s->ifname, |
| 9596 | wpa_s->conf->ctrl_interface ? |
| 9597 | wpa_s->conf->ctrl_interface : "N/A"); |
| 9598 | else |
| 9599 | res = os_snprintf(pos, end - pos, "%s\n", |
| 9600 | wpa_s->ifname); |
| 9601 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9602 | if (os_snprintf_error(end - pos, res)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9603 | *pos = '\0'; |
| 9604 | break; |
| 9605 | } |
| 9606 | pos += res; |
| 9607 | wpa_s = wpa_s->next; |
| 9608 | } |
| 9609 | return pos - buf; |
| 9610 | } |
| 9611 | |
| 9612 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 9613 | static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global, |
| 9614 | const char *ifname, |
| 9615 | char *cmd, size_t *resp_len) |
| 9616 | { |
| 9617 | struct wpa_supplicant *wpa_s; |
| 9618 | |
| 9619 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 9620 | if (os_strcmp(ifname, wpa_s->ifname) == 0) |
| 9621 | break; |
| 9622 | } |
| 9623 | |
| 9624 | if (wpa_s == NULL) { |
| 9625 | char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n"); |
| 9626 | if (resp) |
| 9627 | *resp_len = os_strlen(resp); |
| 9628 | else |
| 9629 | *resp_len = 1; |
| 9630 | return resp; |
| 9631 | } |
| 9632 | |
| 9633 | return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len); |
| 9634 | } |
| 9635 | |
| 9636 | |
| 9637 | static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global, |
| 9638 | char *buf, size_t *resp_len) |
| 9639 | { |
| 9640 | #ifdef CONFIG_P2P |
| 9641 | static const char * cmd[] = { |
Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 9642 | "LIST_NETWORKS", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 9643 | "P2P_FIND", |
| 9644 | "P2P_STOP_FIND", |
| 9645 | "P2P_LISTEN", |
| 9646 | "P2P_GROUP_ADD", |
| 9647 | "P2P_GET_PASSPHRASE", |
| 9648 | "P2P_SERVICE_UPDATE", |
| 9649 | "P2P_SERVICE_FLUSH", |
| 9650 | "P2P_FLUSH", |
| 9651 | "P2P_CANCEL", |
| 9652 | "P2P_PRESENCE_REQ", |
| 9653 | "P2P_EXT_LISTEN", |
| 9654 | NULL |
| 9655 | }; |
| 9656 | static const char * prefix[] = { |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 9657 | #ifdef ANDROID |
Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 9658 | "DRIVER ", |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 9659 | #endif /* ANDROID */ |
Dmitry Shmidt | 0c18dcd | 2013-08-16 15:29:47 -0700 | [diff] [blame] | 9660 | "GET_NETWORK ", |
| 9661 | "REMOVE_NETWORK ", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 9662 | "P2P_FIND ", |
| 9663 | "P2P_CONNECT ", |
| 9664 | "P2P_LISTEN ", |
| 9665 | "P2P_GROUP_REMOVE ", |
| 9666 | "P2P_GROUP_ADD ", |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9667 | "P2P_GROUP_MEMBER ", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 9668 | "P2P_PROV_DISC ", |
| 9669 | "P2P_SERV_DISC_REQ ", |
| 9670 | "P2P_SERV_DISC_CANCEL_REQ ", |
| 9671 | "P2P_SERV_DISC_RESP ", |
| 9672 | "P2P_SERV_DISC_EXTERNAL ", |
| 9673 | "P2P_SERVICE_ADD ", |
| 9674 | "P2P_SERVICE_DEL ", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 9675 | "P2P_SERVICE_REP ", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 9676 | "P2P_REJECT ", |
| 9677 | "P2P_INVITE ", |
| 9678 | "P2P_PEER ", |
| 9679 | "P2P_SET ", |
| 9680 | "P2P_UNAUTHORIZE ", |
| 9681 | "P2P_PRESENCE_REQ ", |
| 9682 | "P2P_EXT_LISTEN ", |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9683 | "P2P_REMOVE_CLIENT ", |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 9684 | "WPS_NFC_TOKEN ", |
| 9685 | "WPS_NFC_TAG_READ ", |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 9686 | "NFC_GET_HANDOVER_SEL ", |
| 9687 | "NFC_GET_HANDOVER_REQ ", |
| 9688 | "NFC_REPORT_HANDOVER ", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 9689 | "P2P_ASP_PROVISION ", |
| 9690 | "P2P_ASP_PROVISION_RESP ", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 9691 | NULL |
| 9692 | }; |
| 9693 | int found = 0; |
| 9694 | int i; |
| 9695 | |
| 9696 | if (global->p2p_init_wpa_s == NULL) |
| 9697 | return NULL; |
| 9698 | |
| 9699 | for (i = 0; !found && cmd[i]; i++) { |
| 9700 | if (os_strcmp(buf, cmd[i]) == 0) |
| 9701 | found = 1; |
| 9702 | } |
| 9703 | |
| 9704 | for (i = 0; !found && prefix[i]; i++) { |
| 9705 | if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0) |
| 9706 | found = 1; |
| 9707 | } |
| 9708 | |
| 9709 | if (found) |
| 9710 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, |
| 9711 | buf, resp_len); |
| 9712 | #endif /* CONFIG_P2P */ |
| 9713 | return NULL; |
| 9714 | } |
| 9715 | |
| 9716 | |
| 9717 | static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global, |
| 9718 | char *buf, size_t *resp_len) |
| 9719 | { |
| 9720 | #ifdef CONFIG_WIFI_DISPLAY |
| 9721 | if (global->p2p_init_wpa_s == NULL) |
| 9722 | return NULL; |
| 9723 | if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 || |
| 9724 | os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) |
| 9725 | return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s, |
| 9726 | buf, resp_len); |
| 9727 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 9728 | return NULL; |
| 9729 | } |
| 9730 | |
| 9731 | |
| 9732 | static char * wpas_global_ctrl_iface_redir(struct wpa_global *global, |
| 9733 | char *buf, size_t *resp_len) |
| 9734 | { |
| 9735 | char *ret; |
| 9736 | |
| 9737 | ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len); |
| 9738 | if (ret) |
| 9739 | return ret; |
| 9740 | |
| 9741 | ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len); |
| 9742 | if (ret) |
| 9743 | return ret; |
| 9744 | |
| 9745 | return NULL; |
| 9746 | } |
| 9747 | |
| 9748 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9749 | static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd) |
| 9750 | { |
| 9751 | char *value; |
| 9752 | |
| 9753 | value = os_strchr(cmd, ' '); |
| 9754 | if (value == NULL) |
| 9755 | return -1; |
| 9756 | *value++ = '\0'; |
| 9757 | |
| 9758 | wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value); |
| 9759 | |
| 9760 | #ifdef CONFIG_WIFI_DISPLAY |
| 9761 | if (os_strcasecmp(cmd, "wifi_display") == 0) { |
| 9762 | wifi_display_enable(global, !!atoi(value)); |
| 9763 | return 0; |
| 9764 | } |
| 9765 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 9766 | |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 9767 | /* Restore cmd to its original value to allow redirection */ |
| 9768 | value[-1] = ' '; |
| 9769 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9770 | return -1; |
| 9771 | } |
| 9772 | |
| 9773 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9774 | static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global, |
| 9775 | char *cmd) |
| 9776 | { |
| 9777 | struct wpa_supplicant *wpa_s[2]; /* src, dst */ |
| 9778 | char *p; |
| 9779 | unsigned int i; |
| 9780 | |
| 9781 | /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id> |
| 9782 | * <variable name> */ |
| 9783 | |
| 9784 | for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) { |
| 9785 | p = os_strchr(cmd, ' '); |
| 9786 | if (p == NULL) |
| 9787 | return -1; |
| 9788 | *p = '\0'; |
| 9789 | |
| 9790 | wpa_s[i] = global->ifaces; |
| 9791 | for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) { |
| 9792 | if (os_strcmp(cmd, wpa_s[i]->ifname) == 0) |
| 9793 | break; |
| 9794 | } |
| 9795 | |
| 9796 | if (!wpa_s[i]) { |
| 9797 | wpa_printf(MSG_DEBUG, |
| 9798 | "CTRL_IFACE: Could not find iface=%s", cmd); |
| 9799 | return -1; |
| 9800 | } |
| 9801 | |
| 9802 | cmd = p + 1; |
| 9803 | } |
| 9804 | |
| 9805 | return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]); |
| 9806 | } |
| 9807 | |
| 9808 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9809 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 9810 | static int wpas_global_ctrl_iface_save_config(struct wpa_global *global) |
| 9811 | { |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 9812 | int ret = 0, saved = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9813 | struct wpa_supplicant *wpa_s; |
| 9814 | |
| 9815 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 9816 | if (!wpa_s->conf->update_config) { |
| 9817 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)"); |
| 9818 | continue; |
| 9819 | } |
| 9820 | |
| 9821 | if (wpa_config_write(wpa_s->confname, wpa_s->conf)) { |
| 9822 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration"); |
| 9823 | ret = 1; |
| 9824 | } else { |
| 9825 | wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated"); |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 9826 | saved++; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9827 | } |
| 9828 | } |
| 9829 | |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 9830 | if (!saved && !ret) { |
| 9831 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9832 | "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated"); |
| 9833 | ret = 1; |
| 9834 | } |
| 9835 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9836 | return ret; |
| 9837 | } |
| 9838 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 9839 | |
| 9840 | |
| 9841 | static int wpas_global_ctrl_iface_status(struct wpa_global *global, |
| 9842 | char *buf, size_t buflen) |
| 9843 | { |
| 9844 | char *pos, *end; |
| 9845 | int ret; |
| 9846 | struct wpa_supplicant *wpa_s; |
| 9847 | |
| 9848 | pos = buf; |
| 9849 | end = buf + buflen; |
| 9850 | |
| 9851 | #ifdef CONFIG_P2P |
| 9852 | if (global->p2p && !global->p2p_disabled) { |
| 9853 | ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR |
| 9854 | "\n" |
| 9855 | "p2p_state=%s\n", |
| 9856 | MAC2STR(global->p2p_dev_addr), |
| 9857 | p2p_get_state_txt(global->p2p)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9858 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9859 | return pos - buf; |
| 9860 | pos += ret; |
| 9861 | } else if (global->p2p) { |
| 9862 | ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9863 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9864 | return pos - buf; |
| 9865 | pos += ret; |
| 9866 | } |
| 9867 | #endif /* CONFIG_P2P */ |
| 9868 | |
| 9869 | #ifdef CONFIG_WIFI_DISPLAY |
| 9870 | ret = os_snprintf(pos, end - pos, "wifi_display=%d\n", |
| 9871 | !!global->wifi_display); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9872 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9873 | return pos - buf; |
| 9874 | pos += ret; |
| 9875 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 9876 | |
| 9877 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 9878 | ret = os_snprintf(pos, end - pos, "ifname=%s\n" |
| 9879 | "address=" MACSTR "\n", |
| 9880 | wpa_s->ifname, MAC2STR(wpa_s->own_addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9881 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9882 | return pos - buf; |
| 9883 | pos += ret; |
| 9884 | } |
| 9885 | |
| 9886 | return pos - buf; |
| 9887 | } |
| 9888 | |
| 9889 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9890 | #ifdef CONFIG_FST |
| 9891 | |
| 9892 | static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global, |
| 9893 | char *cmd, char *buf, |
| 9894 | size_t reply_size) |
| 9895 | { |
| 9896 | char ifname[IFNAMSIZ + 1]; |
| 9897 | struct fst_iface_cfg cfg; |
| 9898 | struct wpa_supplicant *wpa_s; |
| 9899 | struct fst_wpa_obj iface_obj; |
| 9900 | |
| 9901 | if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) { |
| 9902 | wpa_s = wpa_supplicant_get_iface(global, ifname); |
| 9903 | if (wpa_s) { |
| 9904 | if (wpa_s->fst) { |
| 9905 | wpa_printf(MSG_INFO, "FST: Already attached"); |
| 9906 | return -1; |
| 9907 | } |
| 9908 | fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj); |
| 9909 | wpa_s->fst = fst_attach(ifname, wpa_s->own_addr, |
| 9910 | &iface_obj, &cfg); |
| 9911 | if (wpa_s->fst) |
| 9912 | return os_snprintf(buf, reply_size, "OK\n"); |
| 9913 | } |
| 9914 | } |
| 9915 | |
| 9916 | return -1; |
| 9917 | } |
| 9918 | |
| 9919 | |
| 9920 | static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global, |
| 9921 | char *cmd, char *buf, |
| 9922 | size_t reply_size) |
| 9923 | { |
| 9924 | char ifname[IFNAMSIZ + 1]; |
| 9925 | struct wpa_supplicant *wpa_s; |
| 9926 | |
| 9927 | if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) { |
| 9928 | wpa_s = wpa_supplicant_get_iface(global, ifname); |
| 9929 | if (wpa_s) { |
| 9930 | if (!fst_iface_detach(ifname)) { |
| 9931 | wpa_s->fst = NULL; |
| 9932 | return os_snprintf(buf, reply_size, "OK\n"); |
| 9933 | } |
| 9934 | } |
| 9935 | } |
| 9936 | |
| 9937 | return -1; |
| 9938 | } |
| 9939 | |
| 9940 | #endif /* CONFIG_FST */ |
| 9941 | |
| 9942 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9943 | char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global, |
| 9944 | char *buf, size_t *resp_len) |
| 9945 | { |
| 9946 | char *reply; |
| 9947 | const int reply_size = 2048; |
| 9948 | int reply_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9949 | int level = MSG_DEBUG; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9950 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 9951 | if (os_strncmp(buf, "IFNAME=", 7) == 0) { |
| 9952 | char *pos = os_strchr(buf + 7, ' '); |
| 9953 | if (pos) { |
| 9954 | *pos++ = '\0'; |
| 9955 | return wpas_global_ctrl_iface_ifname(global, |
| 9956 | buf + 7, pos, |
| 9957 | resp_len); |
| 9958 | } |
| 9959 | } |
| 9960 | |
| 9961 | reply = wpas_global_ctrl_iface_redir(global, buf, resp_len); |
| 9962 | if (reply) |
| 9963 | return reply; |
| 9964 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9965 | if (os_strcmp(buf, "PING") == 0) |
| 9966 | level = MSG_EXCESSIVE; |
| 9967 | wpa_hexdump_ascii(level, "RX global ctrl_iface", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9968 | (const u8 *) buf, os_strlen(buf)); |
| 9969 | |
| 9970 | reply = os_malloc(reply_size); |
| 9971 | if (reply == NULL) { |
| 9972 | *resp_len = 1; |
| 9973 | return NULL; |
| 9974 | } |
| 9975 | |
| 9976 | os_memcpy(reply, "OK\n", 3); |
| 9977 | reply_len = 3; |
| 9978 | |
| 9979 | if (os_strcmp(buf, "PING") == 0) { |
| 9980 | os_memcpy(reply, "PONG\n", 5); |
| 9981 | reply_len = 5; |
| 9982 | } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) { |
| 9983 | if (wpa_supplicant_global_iface_add(global, buf + 14)) |
| 9984 | reply_len = -1; |
| 9985 | } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) { |
| 9986 | if (wpa_supplicant_global_iface_remove(global, buf + 17)) |
| 9987 | reply_len = -1; |
| 9988 | } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) { |
| 9989 | reply_len = wpa_supplicant_global_iface_list( |
| 9990 | global, reply, reply_size); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 9991 | } else if (os_strncmp(buf, "INTERFACES", 10) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9992 | reply_len = wpa_supplicant_global_iface_interfaces( |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 9993 | global, buf + 10, reply, reply_size); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9994 | #ifdef CONFIG_FST |
| 9995 | } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) { |
| 9996 | reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11, |
| 9997 | reply, |
| 9998 | reply_size); |
| 9999 | } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) { |
| 10000 | reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11, |
| 10001 | reply, |
| 10002 | reply_size); |
| 10003 | } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) { |
| 10004 | reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size); |
| 10005 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10006 | } else if (os_strcmp(buf, "TERMINATE") == 0) { |
| 10007 | wpa_supplicant_terminate_proc(global); |
| 10008 | } else if (os_strcmp(buf, "SUSPEND") == 0) { |
| 10009 | wpas_notify_suspend(global); |
| 10010 | } else if (os_strcmp(buf, "RESUME") == 0) { |
| 10011 | wpas_notify_resume(global); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10012 | } else if (os_strncmp(buf, "SET ", 4) == 0) { |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 10013 | if (wpas_global_ctrl_iface_set(global, buf + 4)) { |
| 10014 | #ifdef CONFIG_P2P |
| 10015 | if (global->p2p_init_wpa_s) { |
| 10016 | os_free(reply); |
| 10017 | /* Check if P2P redirection would work for this |
| 10018 | * command. */ |
| 10019 | return wpa_supplicant_ctrl_iface_process( |
| 10020 | global->p2p_init_wpa_s, |
| 10021 | buf, resp_len); |
| 10022 | } |
| 10023 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10024 | reply_len = -1; |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 10025 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10026 | } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) { |
| 10027 | if (wpas_global_ctrl_iface_dup_network(global, buf + 12)) |
| 10028 | reply_len = -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10029 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 10030 | } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { |
| 10031 | if (wpas_global_ctrl_iface_save_config(global)) |
| 10032 | reply_len = -1; |
| 10033 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 10034 | } else if (os_strcmp(buf, "STATUS") == 0) { |
| 10035 | reply_len = wpas_global_ctrl_iface_status(global, reply, |
| 10036 | reply_size); |
Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 10037 | #ifdef CONFIG_MODULE_TESTS |
| 10038 | } else if (os_strcmp(buf, "MODULE_TESTS") == 0) { |
Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 10039 | if (wpas_module_tests() < 0) |
| 10040 | reply_len = -1; |
| 10041 | #endif /* CONFIG_MODULE_TESTS */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10042 | } else if (os_strncmp(buf, "RELOG", 5) == 0) { |
| 10043 | if (wpa_debug_reopen_file() < 0) |
| 10044 | reply_len = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10045 | } else { |
| 10046 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); |
| 10047 | reply_len = 16; |
| 10048 | } |
| 10049 | |
| 10050 | if (reply_len < 0) { |
| 10051 | os_memcpy(reply, "FAIL\n", 5); |
| 10052 | reply_len = 5; |
| 10053 | } |
| 10054 | |
| 10055 | *resp_len = reply_len; |
| 10056 | return reply; |
| 10057 | } |