| /* |
| * WPA Supplicant / Control interface (shared code for all backends) |
| * Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi> |
| * |
| * This software may be distributed under the terms of the BSD license. |
| * See README for more details. |
| */ |
| |
| #include "utils/includes.h" |
| #ifdef CONFIG_TESTING_OPTIONS |
| #include <net/ethernet.h> |
| #include <netinet/ip.h> |
| #endif /* CONFIG_TESTING_OPTIONS */ |
| |
| #include "utils/common.h" |
| #include "utils/eloop.h" |
| #include "utils/uuid.h" |
| #include "common/version.h" |
| #include "common/ieee802_11_defs.h" |
| #include "common/ieee802_11_common.h" |
| #include "common/wpa_ctrl.h" |
| #include "crypto/tls.h" |
| #include "ap/hostapd.h" |
| #include "eap_peer/eap.h" |
| #include "eapol_supp/eapol_supp_sm.h" |
| #include "rsn_supp/wpa.h" |
| #include "rsn_supp/preauth.h" |
| #include "rsn_supp/pmksa_cache.h" |
| #include "l2_packet/l2_packet.h" |
| #include "wps/wps.h" |
| #include "config.h" |
| #include "wpa_supplicant_i.h" |
| #include "driver_i.h" |
| #include "wps_supplicant.h" |
| #include "ibss_rsn.h" |
| #include "ap.h" |
| #include "p2p_supplicant.h" |
| #include "p2p/p2p.h" |
| #include "hs20_supplicant.h" |
| #include "wifi_display.h" |
| #include "notify.h" |
| #include "bss.h" |
| #include "scan.h" |
| #include "ctrl_iface.h" |
| #include "interworking.h" |
| #include "blacklist.h" |
| #include "autoscan.h" |
| #include "wnm_sta.h" |
| #include "offchannel.h" |
| #include "drivers/driver.h" |
| #include "mesh.h" |
| |
| static int wpa_supplicant_global_iface_list(struct wpa_global *global, |
| char *buf, int len); |
| static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, |
| char *buf, int len); |
| static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, |
| char *val); |
| |
| static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val) |
| { |
| char *pos; |
| u8 addr[ETH_ALEN], *filter = NULL, *n; |
| size_t count = 0; |
| |
| pos = val; |
| while (pos) { |
| if (*pos == '\0') |
| break; |
| if (hwaddr_aton(pos, addr)) { |
| os_free(filter); |
| return -1; |
| } |
| n = os_realloc_array(filter, count + 1, ETH_ALEN); |
| if (n == NULL) { |
| os_free(filter); |
| return -1; |
| } |
| filter = n; |
| os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN); |
| count++; |
| |
| pos = os_strchr(pos, ' '); |
| if (pos) |
| pos++; |
| } |
| |
| wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN); |
| os_free(wpa_s->bssid_filter); |
| wpa_s->bssid_filter = filter; |
| wpa_s->bssid_filter_count = count; |
| |
| return 0; |
| } |
| |
| |
| static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val) |
| { |
| char *pos; |
| u8 addr[ETH_ALEN], *bssid = NULL, *n; |
| struct wpa_ssid_value *ssid = NULL, *ns; |
| size_t count = 0, ssid_count = 0; |
| struct wpa_ssid *c; |
| |
| /* |
| * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | "" |
| * SSID_SPEC ::= ssid <SSID_HEX> |
| * BSSID_SPEC ::= bssid <BSSID_HEX> |
| */ |
| |
| pos = val; |
| while (pos) { |
| if (*pos == '\0') |
| break; |
| if (os_strncmp(pos, "bssid ", 6) == 0) { |
| int res; |
| pos += 6; |
| res = hwaddr_aton2(pos, addr); |
| if (res < 0) { |
| os_free(ssid); |
| os_free(bssid); |
| wpa_printf(MSG_DEBUG, "Invalid disallow_aps " |
| "BSSID value '%s'", pos); |
| return -1; |
| } |
| pos += res; |
| n = os_realloc_array(bssid, count + 1, ETH_ALEN); |
| if (n == NULL) { |
| os_free(ssid); |
| os_free(bssid); |
| return -1; |
| } |
| bssid = n; |
| os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN); |
| count++; |
| } else if (os_strncmp(pos, "ssid ", 5) == 0) { |
| char *end; |
| pos += 5; |
| |
| end = pos; |
| while (*end) { |
| if (*end == '\0' || *end == ' ') |
| break; |
| end++; |
| } |
| |
| ns = os_realloc_array(ssid, ssid_count + 1, |
| sizeof(struct wpa_ssid_value)); |
| if (ns == NULL) { |
| os_free(ssid); |
| os_free(bssid); |
| return -1; |
| } |
| ssid = ns; |
| |
| if ((end - pos) & 0x01 || |
| end - pos > 2 * SSID_MAX_LEN || |
| hexstr2bin(pos, ssid[ssid_count].ssid, |
| (end - pos) / 2) < 0) { |
| os_free(ssid); |
| os_free(bssid); |
| wpa_printf(MSG_DEBUG, "Invalid disallow_aps " |
| "SSID value '%s'", pos); |
| return -1; |
| } |
| ssid[ssid_count].ssid_len = (end - pos) / 2; |
| wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID", |
| ssid[ssid_count].ssid, |
| ssid[ssid_count].ssid_len); |
| ssid_count++; |
| pos = end; |
| } else { |
| wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value " |
| "'%s'", pos); |
| os_free(ssid); |
| os_free(bssid); |
| return -1; |
| } |
| |
| pos = os_strchr(pos, ' '); |
| if (pos) |
| pos++; |
| } |
| |
| wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN); |
| os_free(wpa_s->disallow_aps_bssid); |
| wpa_s->disallow_aps_bssid = bssid; |
| wpa_s->disallow_aps_bssid_count = count; |
| |
| wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count); |
| os_free(wpa_s->disallow_aps_ssid); |
| wpa_s->disallow_aps_ssid = ssid; |
| wpa_s->disallow_aps_ssid_count = ssid_count; |
| |
| if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING) |
| return 0; |
| |
| c = wpa_s->current_ssid; |
| if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS) |
| return 0; |
| |
| if (!disallowed_bssid(wpa_s, wpa_s->bssid) && |
| !disallowed_ssid(wpa_s, c->ssid, c->ssid_len)) |
| return 0; |
| |
| wpa_printf(MSG_DEBUG, "Disconnect and try to find another network " |
| "because current AP was marked disallowed"); |
| |
| #ifdef CONFIG_SME |
| wpa_s->sme.prev_bssid_set = 0; |
| #endif /* CONFIG_SME */ |
| wpa_s->reassociate = 1; |
| wpa_s->own_disconnect_req = 1; |
| wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| wpa_supplicant_req_scan(wpa_s, 0, 0); |
| |
| return 0; |
| } |
| |
| |
| #ifndef CONFIG_NO_CONFIG_BLOBS |
| static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos) |
| { |
| char *name = pos; |
| struct wpa_config_blob *blob; |
| size_t len; |
| |
| pos = os_strchr(pos, ' '); |
| if (pos == NULL) |
| return -1; |
| *pos++ = '\0'; |
| len = os_strlen(pos); |
| if (len & 1) |
| return -1; |
| |
| wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name); |
| blob = os_zalloc(sizeof(*blob)); |
| if (blob == NULL) |
| return -1; |
| blob->name = os_strdup(name); |
| blob->data = os_malloc(len / 2); |
| if (blob->name == NULL || blob->data == NULL) { |
| wpa_config_free_blob(blob); |
| return -1; |
| } |
| |
| if (hexstr2bin(pos, blob->data, len / 2) < 0) { |
| wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data"); |
| wpa_config_free_blob(blob); |
| return -1; |
| } |
| blob->len = len / 2; |
| |
| wpa_config_set_blob(wpa_s->conf, blob); |
| |
| return 0; |
| } |
| #endif /* CONFIG_NO_CONFIG_BLOBS */ |
| |
| |
| static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| char *params; |
| char *pos; |
| int *freqs = NULL; |
| int ret; |
| |
| if (atoi(cmd)) { |
| params = os_strchr(cmd, ' '); |
| os_free(wpa_s->manual_sched_scan_freqs); |
| if (params) { |
| params++; |
| pos = os_strstr(params, "freq="); |
| if (pos) |
| freqs = freq_range_to_channel_list(wpa_s, |
| pos + 5); |
| } |
| wpa_s->manual_sched_scan_freqs = freqs; |
| ret = wpas_start_pno(wpa_s); |
| } else { |
| ret = wpas_stop_pno(wpa_s); |
| } |
| return ret; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, |
| char *cmd) |
| { |
| char *value; |
| int ret = 0; |
| |
| value = os_strchr(cmd, ' '); |
| if (value == NULL) |
| return -1; |
| *value++ = '\0'; |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value); |
| if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) { |
| eapol_sm_configure(wpa_s->eapol, |
| atoi(value), -1, -1, -1); |
| } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) { |
| eapol_sm_configure(wpa_s->eapol, |
| -1, atoi(value), -1, -1); |
| } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) { |
| eapol_sm_configure(wpa_s->eapol, |
| -1, -1, atoi(value), -1); |
| } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) { |
| eapol_sm_configure(wpa_s->eapol, |
| -1, -1, -1, atoi(value)); |
| } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) { |
| if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, |
| atoi(value))) |
| ret = -1; |
| } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == |
| 0) { |
| if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, |
| atoi(value))) |
| ret = -1; |
| } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) { |
| if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value))) |
| ret = -1; |
| } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) { |
| wpa_s->wps_fragment_size = atoi(value); |
| #ifdef CONFIG_WPS_TESTING |
| } else if (os_strcasecmp(cmd, "wps_version_number") == 0) { |
| long int val; |
| val = strtol(value, NULL, 0); |
| if (val < 0 || val > 0xff) { |
| ret = -1; |
| wpa_printf(MSG_DEBUG, "WPS: Invalid " |
| "wps_version_number %ld", val); |
| } else { |
| wps_version_number = val; |
| wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS " |
| "version %u.%u", |
| (wps_version_number & 0xf0) >> 4, |
| wps_version_number & 0x0f); |
| } |
| } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) { |
| wps_testing_dummy_cred = atoi(value); |
| wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d", |
| wps_testing_dummy_cred); |
| } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) { |
| wps_corrupt_pkhash = atoi(value); |
| wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d", |
| wps_corrupt_pkhash); |
| #endif /* CONFIG_WPS_TESTING */ |
| } else if (os_strcasecmp(cmd, "ampdu") == 0) { |
| if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0) |
| ret = -1; |
| #ifdef CONFIG_TDLS |
| #ifdef CONFIG_TDLS_TESTING |
| } else if (os_strcasecmp(cmd, "tdls_testing") == 0) { |
| extern unsigned int tdls_testing; |
| tdls_testing = strtol(value, NULL, 0); |
| wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing); |
| #endif /* CONFIG_TDLS_TESTING */ |
| } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) { |
| int disabled = atoi(value); |
| wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled); |
| if (disabled) { |
| if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0) |
| ret = -1; |
| } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0) |
| ret = -1; |
| wpa_tdls_enable(wpa_s->wpa, !disabled); |
| #endif /* CONFIG_TDLS */ |
| } else if (os_strcasecmp(cmd, "pno") == 0) { |
| ret = wpas_ctrl_pno(wpa_s, value); |
| } else if (os_strcasecmp(cmd, "radio_disabled") == 0) { |
| int disabled = atoi(value); |
| if (wpa_drv_radio_disable(wpa_s, disabled) < 0) |
| ret = -1; |
| else if (disabled) |
| wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
| } else if (os_strcasecmp(cmd, "uapsd") == 0) { |
| if (os_strcmp(value, "disable") == 0) |
| wpa_s->set_sta_uapsd = 0; |
| else { |
| int be, bk, vi, vo; |
| char *pos; |
| /* format: BE,BK,VI,VO;max SP Length */ |
| be = atoi(value); |
| pos = os_strchr(value, ','); |
| if (pos == NULL) |
| return -1; |
| pos++; |
| bk = atoi(pos); |
| pos = os_strchr(pos, ','); |
| if (pos == NULL) |
| return -1; |
| pos++; |
| vi = atoi(pos); |
| pos = os_strchr(pos, ','); |
| if (pos == NULL) |
| return -1; |
| pos++; |
| vo = atoi(pos); |
| /* ignore max SP Length for now */ |
| |
| wpa_s->set_sta_uapsd = 1; |
| wpa_s->sta_uapsd = 0; |
| if (be) |
| wpa_s->sta_uapsd |= BIT(0); |
| if (bk) |
| wpa_s->sta_uapsd |= BIT(1); |
| if (vi) |
| wpa_s->sta_uapsd |= BIT(2); |
| if (vo) |
| wpa_s->sta_uapsd |= BIT(3); |
| } |
| } else if (os_strcasecmp(cmd, "ps") == 0) { |
| ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1); |
| #ifdef CONFIG_WIFI_DISPLAY |
| } else if (os_strcasecmp(cmd, "wifi_display") == 0) { |
| int enabled = !!atoi(value); |
| if (enabled && !wpa_s->global->p2p) |
| ret = -1; |
| else |
| wifi_display_enable(wpa_s->global, enabled); |
| #endif /* CONFIG_WIFI_DISPLAY */ |
| } else if (os_strcasecmp(cmd, "bssid_filter") == 0) { |
| ret = set_bssid_filter(wpa_s, value); |
| } else if (os_strcasecmp(cmd, "disallow_aps") == 0) { |
| ret = set_disallow_aps(wpa_s, value); |
| } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) { |
| wpa_s->no_keep_alive = !!atoi(value); |
| #ifdef CONFIG_TESTING_OPTIONS |
| } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) { |
| wpa_s->ext_mgmt_frame_handling = !!atoi(value); |
| } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) { |
| wpa_s->ext_eapol_frame_io = !!atoi(value); |
| #ifdef CONFIG_AP |
| if (wpa_s->ap_iface) { |
| wpa_s->ap_iface->bss[0]->ext_eapol_frame_io = |
| wpa_s->ext_eapol_frame_io; |
| } |
| #endif /* CONFIG_AP */ |
| } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) { |
| wpa_s->extra_roc_dur = atoi(value); |
| } else if (os_strcasecmp(cmd, "test_failure") == 0) { |
| wpa_s->test_failure = atoi(value); |
| #endif /* CONFIG_TESTING_OPTIONS */ |
| #ifndef CONFIG_NO_CONFIG_BLOBS |
| } else if (os_strcmp(cmd, "blob") == 0) { |
| ret = wpas_ctrl_set_blob(wpa_s, value); |
| #endif /* CONFIG_NO_CONFIG_BLOBS */ |
| } else if (os_strcasecmp(cmd, "setband") == 0) { |
| if (os_strcmp(value, "AUTO") == 0) |
| wpa_s->setband = WPA_SETBAND_AUTO; |
| else if (os_strcmp(value, "5G") == 0) |
| wpa_s->setband = WPA_SETBAND_5G; |
| else if (os_strcmp(value, "2G") == 0) |
| wpa_s->setband = WPA_SETBAND_2G; |
| else |
| ret = -1; |
| } else { |
| value[-1] = '='; |
| ret = wpa_config_process_global(wpa_s->conf, cmd, -1); |
| if (ret == 0) |
| wpa_supplicant_update_config(wpa_s); |
| } |
| |
| return ret; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s, |
| char *cmd, char *buf, size_t buflen) |
| { |
| int res = -1; |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd); |
| |
| if (os_strcmp(cmd, "version") == 0) { |
| res = os_snprintf(buf, buflen, "%s", VERSION_STR); |
| } else if (os_strcasecmp(cmd, "country") == 0) { |
| if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) |
| res = os_snprintf(buf, buflen, "%c%c", |
| wpa_s->conf->country[0], |
| wpa_s->conf->country[1]); |
| #ifdef CONFIG_WIFI_DISPLAY |
| } else if (os_strcasecmp(cmd, "wifi_display") == 0) { |
| int enabled; |
| if (wpa_s->global->p2p == NULL || |
| wpa_s->global->p2p_disabled) |
| enabled = 0; |
| else |
| enabled = wpa_s->global->wifi_display; |
| res = os_snprintf(buf, buflen, "%d", enabled); |
| #endif /* CONFIG_WIFI_DISPLAY */ |
| #ifdef CONFIG_TESTING_GET_GTK |
| } else if (os_strcmp(cmd, "gtk") == 0) { |
| if (wpa_s->last_gtk_len == 0) |
| return -1; |
| res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk, |
| wpa_s->last_gtk_len); |
| return res; |
| #endif /* CONFIG_TESTING_GET_GTK */ |
| } else if (os_strcmp(cmd, "tls_library") == 0) { |
| res = tls_get_library_version(buf, buflen); |
| } else { |
| res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen); |
| } |
| |
| if (os_snprintf_error(buflen, res)) |
| return -1; |
| return res; |
| } |
| |
| |
| #ifdef IEEE8021X_EAPOL |
| static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s, |
| char *addr) |
| { |
| u8 bssid[ETH_ALEN]; |
| struct wpa_ssid *ssid = wpa_s->current_ssid; |
| |
| if (hwaddr_aton(addr, bssid)) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address " |
| "'%s'", addr); |
| return -1; |
| } |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid)); |
| rsn_preauth_deinit(wpa_s->wpa); |
| if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL)) |
| return -1; |
| |
| return 0; |
| } |
| #endif /* IEEE8021X_EAPOL */ |
| |
| |
| #ifdef CONFIG_PEERKEY |
| /* MLME-STKSTART.request(peer) */ |
| static int wpa_supplicant_ctrl_iface_stkstart( |
| struct wpa_supplicant *wpa_s, char *addr) |
| { |
| u8 peer[ETH_ALEN]; |
| |
| if (hwaddr_aton(addr, peer)) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid " |
| "address '%s'", addr); |
| return -1; |
| } |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR, |
| MAC2STR(peer)); |
| |
| return wpa_sm_stkstart(wpa_s->wpa, peer); |
| } |
| #endif /* CONFIG_PEERKEY */ |
| |
| |
| #ifdef CONFIG_TDLS |
| |
| static int wpa_supplicant_ctrl_iface_tdls_discover( |
| struct wpa_supplicant *wpa_s, char *addr) |
| { |
| u8 peer[ETH_ALEN]; |
| int ret; |
| |
| if (hwaddr_aton(addr, peer)) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid " |
| "address '%s'", addr); |
| return -1; |
| } |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR, |
| MAC2STR(peer)); |
| |
| if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer); |
| else |
| ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer); |
| |
| return ret; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_tdls_setup( |
| struct wpa_supplicant *wpa_s, char *addr) |
| { |
| u8 peer[ETH_ALEN]; |
| int ret; |
| |
| if (hwaddr_aton(addr, peer)) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid " |
| "address '%s'", addr); |
| return -1; |
| } |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR, |
| MAC2STR(peer)); |
| |
| if ((wpa_s->conf->tdls_external_control) && |
| wpa_tdls_is_external_setup(wpa_s->wpa)) |
| return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); |
| |
| wpa_tdls_remove(wpa_s->wpa, peer); |
| |
| if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| ret = wpa_tdls_start(wpa_s->wpa, peer); |
| else |
| ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer); |
| |
| return ret; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_tdls_teardown( |
| struct wpa_supplicant *wpa_s, char *addr) |
| { |
| u8 peer[ETH_ALEN]; |
| int ret; |
| |
| if (os_strcmp(addr, "*") == 0) { |
| /* remove everyone */ |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *"); |
| wpa_tdls_teardown_peers(wpa_s->wpa); |
| return 0; |
| } |
| |
| if (hwaddr_aton(addr, peer)) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid " |
| "address '%s'", addr); |
| return -1; |
| } |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR, |
| MAC2STR(peer)); |
| |
| if ((wpa_s->conf->tdls_external_control) && |
| wpa_tdls_is_external_setup(wpa_s->wpa)) |
| return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); |
| |
| if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| ret = wpa_tdls_teardown_link( |
| wpa_s->wpa, peer, |
| WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED); |
| else |
| ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer); |
| |
| return ret; |
| } |
| |
| |
| static int ctrl_iface_get_capability_tdls( |
| struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| { |
| int ret; |
| |
| ret = os_snprintf(buf, buflen, "%s\n", |
| wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ? |
| (wpa_s->drv_flags & |
| WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ? |
| "EXTERNAL" : "INTERNAL") : "UNSUPPORTED"); |
| if (os_snprintf_error(buflen, ret)) |
| return -1; |
| return ret; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_tdls_chan_switch( |
| struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| u8 peer[ETH_ALEN]; |
| struct hostapd_freq_params freq_params; |
| u8 oper_class; |
| char *pos, *end; |
| |
| if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { |
| wpa_printf(MSG_INFO, |
| "tdls_chanswitch: Only supported with external setup"); |
| return -1; |
| } |
| |
| os_memset(&freq_params, 0, sizeof(freq_params)); |
| |
| pos = os_strchr(cmd, ' '); |
| if (pos == NULL) |
| return -1; |
| *pos++ = '\0'; |
| |
| oper_class = strtol(pos, &end, 10); |
| if (pos == end) { |
| wpa_printf(MSG_INFO, |
| "tdls_chanswitch: Invalid op class provided"); |
| return -1; |
| } |
| |
| pos = end; |
| freq_params.freq = atoi(pos); |
| if (freq_params.freq == 0) { |
| wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided"); |
| return -1; |
| } |
| |
| #define SET_FREQ_SETTING(str) \ |
| do { \ |
| const char *pos2 = os_strstr(pos, " " #str "="); \ |
| if (pos2) { \ |
| pos2 += sizeof(" " #str "=") - 1; \ |
| freq_params.str = atoi(pos2); \ |
| } \ |
| } while (0) |
| |
| SET_FREQ_SETTING(center_freq1); |
| SET_FREQ_SETTING(center_freq2); |
| SET_FREQ_SETTING(bandwidth); |
| SET_FREQ_SETTING(sec_channel_offset); |
| #undef SET_FREQ_SETTING |
| |
| freq_params.ht_enabled = !!os_strstr(pos, " ht"); |
| freq_params.vht_enabled = !!os_strstr(pos, " vht"); |
| |
| if (hwaddr_aton(cmd, peer)) { |
| wpa_printf(MSG_DEBUG, |
| "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'", |
| cmd); |
| return -1; |
| } |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR |
| " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s", |
| MAC2STR(peer), oper_class, freq_params.freq, |
| freq_params.center_freq1, freq_params.center_freq2, |
| freq_params.bandwidth, freq_params.sec_channel_offset, |
| freq_params.ht_enabled ? " HT" : "", |
| freq_params.vht_enabled ? " VHT" : ""); |
| |
| return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class, |
| &freq_params); |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch( |
| struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| u8 peer[ETH_ALEN]; |
| |
| if (!wpa_tdls_is_external_setup(wpa_s->wpa)) { |
| wpa_printf(MSG_INFO, |
| "tdls_chanswitch: Only supported with external setup"); |
| return -1; |
| } |
| |
| if (hwaddr_aton(cmd, peer)) { |
| wpa_printf(MSG_DEBUG, |
| "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'", |
| cmd); |
| return -1; |
| } |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR, |
| MAC2STR(peer)); |
| |
| return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer); |
| } |
| |
| #endif /* CONFIG_TDLS */ |
| |
| |
| static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| char *token, *context = NULL; |
| struct wmm_ac_ts_setup_params params = { |
| .tsid = 0xff, |
| .direction = 0xff, |
| }; |
| |
| while ((token = str_token(cmd, " ", &context))) { |
| if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 || |
| sscanf(token, "up=%i", ¶ms.user_priority) == 1 || |
| sscanf(token, "nominal_msdu_size=%i", |
| ¶ms.nominal_msdu_size) == 1 || |
| sscanf(token, "mean_data_rate=%i", |
| ¶ms.mean_data_rate) == 1 || |
| sscanf(token, "min_phy_rate=%i", |
| ¶ms.minimum_phy_rate) == 1 || |
| sscanf(token, "sba=%i", |
| ¶ms.surplus_bandwidth_allowance) == 1) |
| continue; |
| |
| if (os_strcasecmp(token, "downlink") == 0) { |
| params.direction = WMM_TSPEC_DIRECTION_DOWNLINK; |
| } else if (os_strcasecmp(token, "uplink") == 0) { |
| params.direction = WMM_TSPEC_DIRECTION_UPLINK; |
| } else if (os_strcasecmp(token, "bidi") == 0) { |
| params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL; |
| } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) { |
| params.fixed_nominal_msdu = 1; |
| } else { |
| wpa_printf(MSG_DEBUG, |
| "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'", |
| token); |
| return -1; |
| } |
| |
| } |
| |
| return wpas_wmm_ac_addts(wpa_s, ¶ms); |
| } |
| |
| |
| static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| u8 tsid = atoi(cmd); |
| |
| return wpas_wmm_ac_delts(wpa_s, tsid); |
| } |
| |
| |
| #ifdef CONFIG_IEEE80211R |
| static int wpa_supplicant_ctrl_iface_ft_ds( |
| struct wpa_supplicant *wpa_s, char *addr) |
| { |
| u8 target_ap[ETH_ALEN]; |
| struct wpa_bss *bss; |
| const u8 *mdie; |
| |
| if (hwaddr_aton(addr, target_ap)) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid " |
| "address '%s'", addr); |
| return -1; |
| } |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap)); |
| |
| bss = wpa_bss_get_bssid(wpa_s, target_ap); |
| if (bss) |
| mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); |
| else |
| mdie = NULL; |
| |
| return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie); |
| } |
| #endif /* CONFIG_IEEE80211R */ |
| |
| |
| #ifdef CONFIG_WPS |
| static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s, |
| char *cmd) |
| { |
| u8 bssid[ETH_ALEN], *_bssid = bssid; |
| #ifdef CONFIG_P2P |
| u8 p2p_dev_addr[ETH_ALEN]; |
| #endif /* CONFIG_P2P */ |
| #ifdef CONFIG_AP |
| u8 *_p2p_dev_addr = NULL; |
| #endif /* CONFIG_AP */ |
| |
| if (cmd == NULL || os_strcmp(cmd, "any") == 0) { |
| _bssid = NULL; |
| #ifdef CONFIG_P2P |
| } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) { |
| if (hwaddr_aton(cmd + 13, p2p_dev_addr)) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid " |
| "P2P Device Address '%s'", |
| cmd + 13); |
| return -1; |
| } |
| _p2p_dev_addr = p2p_dev_addr; |
| #endif /* CONFIG_P2P */ |
| } else if (hwaddr_aton(cmd, bssid)) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'", |
| cmd); |
| return -1; |
| } |
| |
| #ifdef CONFIG_AP |
| if (wpa_s->ap_iface) |
| return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr); |
| #endif /* CONFIG_AP */ |
| |
| return wpas_wps_start_pbc(wpa_s, _bssid, 0); |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, |
| char *cmd, char *buf, |
| size_t buflen) |
| { |
| u8 bssid[ETH_ALEN], *_bssid = bssid; |
| char *pin; |
| int ret; |
| |
| pin = os_strchr(cmd, ' '); |
| if (pin) |
| *pin++ = '\0'; |
| |
| if (os_strcmp(cmd, "any") == 0) |
| _bssid = NULL; |
| else if (os_strcmp(cmd, "get") == 0) { |
| ret = wps_generate_pin(); |
| goto done; |
| } else if (hwaddr_aton(cmd, bssid)) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'", |
| cmd); |
| return -1; |
| } |
| |
| #ifdef CONFIG_AP |
| if (wpa_s->ap_iface) { |
| int timeout = 0; |
| char *pos; |
| |
| if (pin) { |
| pos = os_strchr(pin, ' '); |
| if (pos) { |
| *pos++ = '\0'; |
| timeout = atoi(pos); |
| } |
| } |
| |
| return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, |
| buf, buflen, timeout); |
| } |
| #endif /* CONFIG_AP */ |
| |
| if (pin) { |
| ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0, |
| DEV_PW_DEFAULT); |
| if (ret < 0) |
| return -1; |
| ret = os_snprintf(buf, buflen, "%s", pin); |
| if (os_snprintf_error(buflen, ret)) |
| return -1; |
| return ret; |
| } |
| |
| ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT); |
| if (ret < 0) |
| return -1; |
| |
| done: |
| /* Return the generated PIN */ |
| ret = os_snprintf(buf, buflen, "%08d", ret); |
| if (os_snprintf_error(buflen, ret)) |
| return -1; |
| return ret; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_wps_check_pin( |
| struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| { |
| char pin[9]; |
| size_t len; |
| char *pos; |
| int ret; |
| |
| wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN", |
| (u8 *) cmd, os_strlen(cmd)); |
| for (pos = cmd, len = 0; *pos != '\0'; pos++) { |
| if (*pos < '0' || *pos > '9') |
| continue; |
| pin[len++] = *pos; |
| if (len == 9) { |
| wpa_printf(MSG_DEBUG, "WPS: Too long PIN"); |
| return -1; |
| } |
| } |
| if (len != 4 && len != 8) { |
| wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len); |
| return -1; |
| } |
| pin[len] = '\0'; |
| |
| if (len == 8) { |
| unsigned int pin_val; |
| pin_val = atoi(pin); |
| if (!wps_pin_valid(pin_val)) { |
| wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit"); |
| ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n"); |
| if (os_snprintf_error(buflen, ret)) |
| return -1; |
| return ret; |
| } |
| } |
| |
| ret = os_snprintf(buf, buflen, "%s", pin); |
| if (os_snprintf_error(buflen, ret)) |
| return -1; |
| |
| return ret; |
| } |
| |
| |
| #ifdef CONFIG_WPS_NFC |
| |
| static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s, |
| char *cmd) |
| { |
| u8 bssid[ETH_ALEN], *_bssid = bssid; |
| |
| if (cmd == NULL || cmd[0] == '\0') |
| _bssid = NULL; |
| else if (hwaddr_aton(cmd, bssid)) |
| return -1; |
| |
| return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL, |
| 0, 0); |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_wps_nfc_config_token( |
| struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| { |
| int ndef; |
| struct wpabuf *buf; |
| int res; |
| char *pos; |
| |
| pos = os_strchr(cmd, ' '); |
| if (pos) |
| *pos++ = '\0'; |
| if (os_strcmp(cmd, "WPS") == 0) |
| ndef = 0; |
| else if (os_strcmp(cmd, "NDEF") == 0) |
| ndef = 1; |
| else |
| return -1; |
| |
| buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos); |
| if (buf == NULL) |
| return -1; |
| |
| res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| wpabuf_len(buf)); |
| reply[res++] = '\n'; |
| reply[res] = '\0'; |
| |
| wpabuf_free(buf); |
| |
| return res; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_wps_nfc_token( |
| struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| { |
| int ndef; |
| struct wpabuf *buf; |
| int res; |
| |
| if (os_strcmp(cmd, "WPS") == 0) |
| ndef = 0; |
| else if (os_strcmp(cmd, "NDEF") == 0) |
| ndef = 1; |
| else |
| return -1; |
| |
| buf = wpas_wps_nfc_token(wpa_s, ndef); |
| if (buf == NULL) |
| return -1; |
| |
| res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| wpabuf_len(buf)); |
| reply[res++] = '\n'; |
| reply[res] = '\0'; |
| |
| wpabuf_free(buf); |
| |
| return res; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read( |
| struct wpa_supplicant *wpa_s, char *pos) |
| { |
| size_t len; |
| struct wpabuf *buf; |
| int ret; |
| char *freq; |
| int forced_freq = 0; |
| |
| freq = strstr(pos, " freq="); |
| if (freq) { |
| *freq = '\0'; |
| freq += 6; |
| forced_freq = atoi(freq); |
| } |
| |
| len = os_strlen(pos); |
| if (len & 0x01) |
| return -1; |
| len /= 2; |
| |
| buf = wpabuf_alloc(len); |
| if (buf == NULL) |
| return -1; |
| if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) { |
| wpabuf_free(buf); |
| return -1; |
| } |
| |
| ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq); |
| wpabuf_free(buf); |
| |
| return ret; |
| } |
| |
| |
| static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s, |
| char *reply, size_t max_len, |
| int ndef) |
| { |
| struct wpabuf *buf; |
| int res; |
| |
| buf = wpas_wps_nfc_handover_req(wpa_s, ndef); |
| if (buf == NULL) |
| return -1; |
| |
| res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| wpabuf_len(buf)); |
| reply[res++] = '\n'; |
| reply[res] = '\0'; |
| |
| wpabuf_free(buf); |
| |
| return res; |
| } |
| |
| |
| #ifdef CONFIG_P2P |
| static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s, |
| char *reply, size_t max_len, |
| int ndef) |
| { |
| struct wpabuf *buf; |
| int res; |
| |
| buf = wpas_p2p_nfc_handover_req(wpa_s, ndef); |
| if (buf == NULL) { |
| wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request"); |
| return -1; |
| } |
| |
| res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| wpabuf_len(buf)); |
| reply[res++] = '\n'; |
| reply[res] = '\0'; |
| |
| wpabuf_free(buf); |
| |
| return res; |
| } |
| #endif /* CONFIG_P2P */ |
| |
| |
| static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s, |
| char *cmd, char *reply, |
| size_t max_len) |
| { |
| char *pos; |
| int ndef; |
| |
| pos = os_strchr(cmd, ' '); |
| if (pos == NULL) |
| return -1; |
| *pos++ = '\0'; |
| |
| if (os_strcmp(cmd, "WPS") == 0) |
| ndef = 0; |
| else if (os_strcmp(cmd, "NDEF") == 0) |
| ndef = 1; |
| else |
| return -1; |
| |
| if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
| if (!ndef) |
| return -1; |
| return wpas_ctrl_nfc_get_handover_req_wps( |
| wpa_s, reply, max_len, ndef); |
| } |
| |
| #ifdef CONFIG_P2P |
| if (os_strcmp(pos, "P2P-CR") == 0) { |
| return wpas_ctrl_nfc_get_handover_req_p2p( |
| wpa_s, reply, max_len, ndef); |
| } |
| #endif /* CONFIG_P2P */ |
| |
| return -1; |
| } |
| |
| |
| static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s, |
| char *reply, size_t max_len, |
| int ndef, int cr, char *uuid) |
| { |
| struct wpabuf *buf; |
| int res; |
| |
| buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid); |
| if (buf == NULL) |
| return -1; |
| |
| res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| wpabuf_len(buf)); |
| reply[res++] = '\n'; |
| reply[res] = '\0'; |
| |
| wpabuf_free(buf); |
| |
| return res; |
| } |
| |
| |
| #ifdef CONFIG_P2P |
| static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s, |
| char *reply, size_t max_len, |
| int ndef, int tag) |
| { |
| struct wpabuf *buf; |
| int res; |
| |
| buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag); |
| if (buf == NULL) |
| return -1; |
| |
| res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| wpabuf_len(buf)); |
| reply[res++] = '\n'; |
| reply[res] = '\0'; |
| |
| wpabuf_free(buf); |
| |
| return res; |
| } |
| #endif /* CONFIG_P2P */ |
| |
| |
| static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s, |
| char *cmd, char *reply, |
| size_t max_len) |
| { |
| char *pos, *pos2; |
| int ndef; |
| |
| pos = os_strchr(cmd, ' '); |
| if (pos == NULL) |
| return -1; |
| *pos++ = '\0'; |
| |
| if (os_strcmp(cmd, "WPS") == 0) |
| ndef = 0; |
| else if (os_strcmp(cmd, "NDEF") == 0) |
| ndef = 1; |
| else |
| return -1; |
| |
| pos2 = os_strchr(pos, ' '); |
| if (pos2) |
| *pos2++ = '\0'; |
| if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) { |
| if (!ndef) |
| return -1; |
| return wpas_ctrl_nfc_get_handover_sel_wps( |
| wpa_s, reply, max_len, ndef, |
| os_strcmp(pos, "WPS-CR") == 0, pos2); |
| } |
| |
| #ifdef CONFIG_P2P |
| if (os_strcmp(pos, "P2P-CR") == 0) { |
| return wpas_ctrl_nfc_get_handover_sel_p2p( |
| wpa_s, reply, max_len, ndef, 0); |
| } |
| |
| if (os_strcmp(pos, "P2P-CR-TAG") == 0) { |
| return wpas_ctrl_nfc_get_handover_sel_p2p( |
| wpa_s, reply, max_len, ndef, 1); |
| } |
| #endif /* CONFIG_P2P */ |
| |
| return -1; |
| } |
| |
| |
| static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s, |
| char *cmd) |
| { |
| size_t len; |
| struct wpabuf *req, *sel; |
| int ret; |
| char *pos, *role, *type, *pos2; |
| #ifdef CONFIG_P2P |
| char *freq; |
| int forced_freq = 0; |
| |
| freq = strstr(cmd, " freq="); |
| if (freq) { |
| *freq = '\0'; |
| freq += 6; |
| forced_freq = atoi(freq); |
| } |
| #endif /* CONFIG_P2P */ |
| |
| role = cmd; |
| pos = os_strchr(role, ' '); |
| if (pos == NULL) { |
| wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report"); |
| return -1; |
| } |
| *pos++ = '\0'; |
| |
| type = pos; |
| pos = os_strchr(type, ' '); |
| if (pos == NULL) { |
| wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report"); |
| return -1; |
| } |
| *pos++ = '\0'; |
| |
| pos2 = os_strchr(pos, ' '); |
| if (pos2 == NULL) { |
| wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report"); |
| return -1; |
| } |
| *pos2++ = '\0'; |
| |
| len = os_strlen(pos); |
| if (len & 0x01) { |
| wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report"); |
| return -1; |
| } |
| len /= 2; |
| |
| req = wpabuf_alloc(len); |
| if (req == NULL) { |
| wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message"); |
| return -1; |
| } |
| if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) { |
| wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report"); |
| wpabuf_free(req); |
| return -1; |
| } |
| |
| len = os_strlen(pos2); |
| if (len & 0x01) { |
| wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report"); |
| wpabuf_free(req); |
| return -1; |
| } |
| len /= 2; |
| |
| sel = wpabuf_alloc(len); |
| if (sel == NULL) { |
| wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message"); |
| wpabuf_free(req); |
| return -1; |
| } |
| if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) { |
| wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report"); |
| wpabuf_free(req); |
| wpabuf_free(sel); |
| return -1; |
| } |
| |
| wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d", |
| role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel)); |
| |
| if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) { |
| ret = wpas_wps_nfc_report_handover(wpa_s, req, sel); |
| #ifdef CONFIG_AP |
| } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) |
| { |
| ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel); |
| if (ret < 0) |
| ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel); |
| #endif /* CONFIG_AP */ |
| #ifdef CONFIG_P2P |
| } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0) |
| { |
| ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0); |
| } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0) |
| { |
| ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel, |
| forced_freq); |
| #endif /* CONFIG_P2P */ |
| } else { |
| wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover " |
| "reported: role=%s type=%s", role, type); |
| ret = -1; |
| } |
| wpabuf_free(req); |
| wpabuf_free(sel); |
| |
| if (ret) |
| wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages"); |
| |
| return ret; |
| } |
| |
| #endif /* CONFIG_WPS_NFC */ |
| |
| |
| static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s, |
| char *cmd) |
| { |
| u8 bssid[ETH_ALEN]; |
| char *pin; |
| char *new_ssid; |
| char *new_auth; |
| char *new_encr; |
| char *new_key; |
| struct wps_new_ap_settings ap; |
| |
| pin = os_strchr(cmd, ' '); |
| if (pin == NULL) |
| return -1; |
| *pin++ = '\0'; |
| |
| if (hwaddr_aton(cmd, bssid)) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'", |
| cmd); |
| return -1; |
| } |
| |
| new_ssid = os_strchr(pin, ' '); |
| if (new_ssid == NULL) |
| return wpas_wps_start_reg(wpa_s, bssid, pin, NULL); |
| *new_ssid++ = '\0'; |
| |
| new_auth = os_strchr(new_ssid, ' '); |
| if (new_auth == NULL) |
| return -1; |
| *new_auth++ = '\0'; |
| |
| new_encr = os_strchr(new_auth, ' '); |
| if (new_encr == NULL) |
| return -1; |
| *new_encr++ = '\0'; |
| |
| new_key = os_strchr(new_encr, ' '); |
| if (new_key == NULL) |
| return -1; |
| *new_key++ = '\0'; |
| |
| os_memset(&ap, 0, sizeof(ap)); |
| ap.ssid_hex = new_ssid; |
| ap.auth = new_auth; |
| ap.encr = new_encr; |
| ap.key_hex = new_key; |
| return wpas_wps_start_reg(wpa_s, bssid, pin, &ap); |
| } |
| |
| |
| #ifdef CONFIG_AP |
| static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s, |
| char *cmd, char *buf, |
| size_t buflen) |
| { |
| int timeout = 300; |
| char *pos; |
| const char *pin_txt; |
| |
| if (!wpa_s->ap_iface) |
| return -1; |
| |
| pos = os_strchr(cmd, ' '); |
| if (pos) |
| *pos++ = '\0'; |
| |
| if (os_strcmp(cmd, "disable") == 0) { |
| wpas_wps_ap_pin_disable(wpa_s); |
| return os_snprintf(buf, buflen, "OK\n"); |
| } |
| |
| if (os_strcmp(cmd, "random") == 0) { |
| if (pos) |
| timeout = atoi(pos); |
| pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout); |
| if (pin_txt == NULL) |
| return -1; |
| return os_snprintf(buf, buflen, "%s", pin_txt); |
| } |
| |
| if (os_strcmp(cmd, "get") == 0) { |
| pin_txt = wpas_wps_ap_pin_get(wpa_s); |
| if (pin_txt == NULL) |
| return -1; |
| return os_snprintf(buf, buflen, "%s", pin_txt); |
| } |
| |
| if (os_strcmp(cmd, "set") == 0) { |
| char *pin; |
| if (pos == NULL) |
| return -1; |
| pin = pos; |
| pos = os_strchr(pos, ' '); |
| if (pos) { |
| *pos++ = '\0'; |
| timeout = atoi(pos); |
| } |
| if (os_strlen(pin) > buflen) |
| return -1; |
| if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0) |
| return -1; |
| return os_snprintf(buf, buflen, "%s", pin); |
| } |
| |
| return -1; |
| } |
| #endif /* CONFIG_AP */ |
| |
| |
| #ifdef CONFIG_WPS_ER |
| static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s, |
| char *cmd) |
| { |
| char *uuid = cmd, *pin, *pos; |
| u8 addr_buf[ETH_ALEN], *addr = NULL; |
| pin = os_strchr(uuid, ' '); |
| if (pin == NULL) |
| return -1; |
| *pin++ = '\0'; |
| pos = os_strchr(pin, ' '); |
| if (pos) { |
| *pos++ = '\0'; |
| if (hwaddr_aton(pos, addr_buf) == 0) |
| addr = addr_buf; |
| } |
| return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin); |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s, |
| char *cmd) |
| { |
| char *uuid = cmd, *pin; |
| pin = os_strchr(uuid, ' '); |
| if (pin == NULL) |
| return -1; |
| *pin++ = '\0'; |
| return wpas_wps_er_learn(wpa_s, uuid, pin); |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_wps_er_set_config( |
| struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| char *uuid = cmd, *id; |
| id = os_strchr(uuid, ' '); |
| if (id == NULL) |
| return -1; |
| *id++ = '\0'; |
| return wpas_wps_er_set_config(wpa_s, uuid, atoi(id)); |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_wps_er_config( |
| struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| char *pin; |
| char *new_ssid; |
| char *new_auth; |
| char *new_encr; |
| char *new_key; |
| struct wps_new_ap_settings ap; |
| |
| pin = os_strchr(cmd, ' '); |
| if (pin == NULL) |
| return -1; |
| *pin++ = '\0'; |
| |
| new_ssid = os_strchr(pin, ' '); |
| if (new_ssid == NULL) |
| return -1; |
| *new_ssid++ = '\0'; |
| |
| new_auth = os_strchr(new_ssid, ' '); |
| if (new_auth == NULL) |
| return -1; |
| *new_auth++ = '\0'; |
| |
| new_encr = os_strchr(new_auth, ' '); |
| if (new_encr == NULL) |
| return -1; |
| *new_encr++ = '\0'; |
| |
| new_key = os_strchr(new_encr, ' '); |
| if (new_key == NULL) |
| return -1; |
| *new_key++ = '\0'; |
| |
| os_memset(&ap, 0, sizeof(ap)); |
| ap.ssid_hex = new_ssid; |
| ap.auth = new_auth; |
| ap.encr = new_encr; |
| ap.key_hex = new_key; |
| return wpas_wps_er_config(wpa_s, cmd, pin, &ap); |
| } |
| |
| |
| #ifdef CONFIG_WPS_NFC |
| static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token( |
| struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| { |
| int ndef; |
| struct wpabuf *buf; |
| int res; |
| char *uuid; |
| |
| uuid = os_strchr(cmd, ' '); |
| if (uuid == NULL) |
| return -1; |
| *uuid++ = '\0'; |
| |
| if (os_strcmp(cmd, "WPS") == 0) |
| ndef = 0; |
| else if (os_strcmp(cmd, "NDEF") == 0) |
| ndef = 1; |
| else |
| return -1; |
| |
| buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid); |
| if (buf == NULL) |
| return -1; |
| |
| res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf), |
| wpabuf_len(buf)); |
| reply[res++] = '\n'; |
| reply[res] = '\0'; |
| |
| wpabuf_free(buf); |
| |
| return res; |
| } |
| #endif /* CONFIG_WPS_NFC */ |
| #endif /* CONFIG_WPS_ER */ |
| |
| #endif /* CONFIG_WPS */ |
| |
| |
| #ifdef CONFIG_IBSS_RSN |
| static int wpa_supplicant_ctrl_iface_ibss_rsn( |
| struct wpa_supplicant *wpa_s, char *addr) |
| { |
| u8 peer[ETH_ALEN]; |
| |
| if (hwaddr_aton(addr, peer)) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid " |
| "address '%s'", addr); |
| return -1; |
| } |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR, |
| MAC2STR(peer)); |
| |
| return ibss_rsn_start(wpa_s->ibss_rsn, peer); |
| } |
| #endif /* CONFIG_IBSS_RSN */ |
| |
| |
| static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, |
| char *rsp) |
| { |
| #ifdef IEEE8021X_EAPOL |
| char *pos, *id_pos; |
| int id; |
| struct wpa_ssid *ssid; |
| |
| pos = os_strchr(rsp, '-'); |
| if (pos == NULL) |
| return -1; |
| *pos++ = '\0'; |
| id_pos = pos; |
| pos = os_strchr(pos, ':'); |
| if (pos == NULL) |
| return -1; |
| *pos++ = '\0'; |
| id = atoi(id_pos); |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); |
| wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", |
| (u8 *) pos, os_strlen(pos)); |
| |
| ssid = wpa_config_get_network(wpa_s->conf, id); |
| if (ssid == NULL) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| "to update", id); |
| return -1; |
| } |
| |
| return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp, |
| pos); |
| #else /* IEEE8021X_EAPOL */ |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); |
| return -1; |
| #endif /* IEEE8021X_EAPOL */ |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, |
| const char *params, |
| char *buf, size_t buflen) |
| { |
| char *pos, *end, tmp[30]; |
| int res, verbose, wps, ret; |
| #ifdef CONFIG_HS20 |
| const u8 *hs20; |
| #endif /* CONFIG_HS20 */ |
| const u8 *sess_id; |
| size_t sess_id_len; |
| |
| if (os_strcmp(params, "-DRIVER") == 0) |
| return wpa_drv_status(wpa_s, buf, buflen); |
| verbose = os_strcmp(params, "-VERBOSE") == 0; |
| wps = os_strcmp(params, "-WPS") == 0; |
| pos = buf; |
| end = buf + buflen; |
| if (wpa_s->wpa_state >= WPA_ASSOCIATED) { |
| struct wpa_ssid *ssid = wpa_s->current_ssid; |
| ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", |
| MAC2STR(wpa_s->bssid)); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| ret = os_snprintf(pos, end - pos, "freq=%u\n", |
| wpa_s->assoc_freq); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| if (ssid) { |
| u8 *_ssid = ssid->ssid; |
| size_t ssid_len = ssid->ssid_len; |
| u8 ssid_buf[SSID_MAX_LEN]; |
| if (ssid_len == 0) { |
| int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); |
| if (_res < 0) |
| ssid_len = 0; |
| else |
| ssid_len = _res; |
| _ssid = ssid_buf; |
| } |
| ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", |
| wpa_ssid_txt(_ssid, ssid_len), |
| ssid->id); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| |
| if (wps && ssid->passphrase && |
| wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && |
| (ssid->mode == WPAS_MODE_AP || |
| ssid->mode == WPAS_MODE_P2P_GO)) { |
| ret = os_snprintf(pos, end - pos, |
| "passphrase=%s\n", |
| ssid->passphrase); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| } |
| if (ssid->id_str) { |
| ret = os_snprintf(pos, end - pos, |
| "id_str=%s\n", |
| ssid->id_str); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| } |
| |
| switch (ssid->mode) { |
| case WPAS_MODE_INFRA: |
| ret = os_snprintf(pos, end - pos, |
| "mode=station\n"); |
| break; |
| case WPAS_MODE_IBSS: |
| ret = os_snprintf(pos, end - pos, |
| "mode=IBSS\n"); |
| break; |
| case WPAS_MODE_AP: |
| ret = os_snprintf(pos, end - pos, |
| "mode=AP\n"); |
| break; |
| case WPAS_MODE_P2P_GO: |
| ret = os_snprintf(pos, end - pos, |
| "mode=P2P GO\n"); |
| break; |
| case WPAS_MODE_P2P_GROUP_FORMATION: |
| ret = os_snprintf(pos, end - pos, |
| "mode=P2P GO - group " |
| "formation\n"); |
| break; |
| default: |
| ret = 0; |
| break; |
| } |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| } |
| |
| #ifdef CONFIG_AP |
| if (wpa_s->ap_iface) { |
| pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos, |
| end - pos, |
| verbose); |
| } else |
| #endif /* CONFIG_AP */ |
| pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); |
| } |
| #ifdef CONFIG_SAE |
| if (wpa_s->wpa_state >= WPA_ASSOCIATED && |
| #ifdef CONFIG_AP |
| !wpa_s->ap_iface && |
| #endif /* CONFIG_AP */ |
| wpa_s->sme.sae.state == SAE_ACCEPTED) { |
| ret = os_snprintf(pos, end - pos, "sae_group=%d\n", |
| wpa_s->sme.sae.group); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| } |
| #endif /* CONFIG_SAE */ |
| ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", |
| wpa_supplicant_state_txt(wpa_s->wpa_state)); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| |
| if (wpa_s->l2 && |
| l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { |
| ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| } |
| |
| #ifdef CONFIG_P2P |
| if (wpa_s->global->p2p) { |
| ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR |
| "\n", MAC2STR(wpa_s->global->p2p_dev_addr)); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| } |
| #endif /* CONFIG_P2P */ |
| |
| ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n", |
| MAC2STR(wpa_s->own_addr)); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| |
| #ifdef CONFIG_HS20 |
| if (wpa_s->current_bss && |
| (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss, |
| HS20_IE_VENDOR_TYPE)) && |
| wpa_s->wpa_proto == WPA_PROTO_RSN && |
| wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
| int release = 1; |
| if (hs20[1] >= 5) { |
| u8 rel_num = (hs20[6] & 0xf0) >> 4; |
| release = rel_num + 1; |
| } |
| ret = os_snprintf(pos, end - pos, "hs20=%d\n", release); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| } |
| |
| if (wpa_s->current_ssid) { |
| struct wpa_cred *cred; |
| char *type; |
| |
| for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
| size_t i; |
| |
| if (wpa_s->current_ssid->parent_cred != cred) |
| continue; |
| |
| if (cred->provisioning_sp) { |
| ret = os_snprintf(pos, end - pos, |
| "provisioning_sp=%s\n", |
| cred->provisioning_sp); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| } |
| |
| if (!cred->domain) |
| goto no_domain; |
| |
| i = 0; |
| if (wpa_s->current_bss && wpa_s->current_bss->anqp) { |
| struct wpabuf *names = |
| wpa_s->current_bss->anqp->domain_name; |
| for (i = 0; names && i < cred->num_domain; i++) |
| { |
| if (domain_name_list_contains( |
| names, cred->domain[i], 1)) |
| break; |
| } |
| if (i == cred->num_domain) |
| i = 0; /* show first entry by default */ |
| } |
| ret = os_snprintf(pos, end - pos, "home_sp=%s\n", |
| cred->domain[i]); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| |
| no_domain: |
| if (wpa_s->current_bss == NULL || |
| wpa_s->current_bss->anqp == NULL) |
| res = -1; |
| else |
| res = interworking_home_sp_cred( |
| wpa_s, cred, |
| wpa_s->current_bss->anqp->domain_name); |
| if (res > 0) |
| type = "home"; |
| else if (res == 0) |
| type = "roaming"; |
| else |
| type = "unknown"; |
| |
| ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| |
| break; |
| } |
| } |
| #endif /* CONFIG_HS20 */ |
| |
| if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
| wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
| res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, |
| verbose); |
| if (res >= 0) |
| pos += res; |
| } |
| |
| sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len); |
| if (sess_id) { |
| char *start = pos; |
| |
| ret = os_snprintf(pos, end - pos, "eap_session_id="); |
| if (os_snprintf_error(end - pos, ret)) |
| return start - buf; |
| pos += ret; |
| ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len); |
| if (ret <= 0) |
| return start - buf; |
| pos += ret; |
| ret = os_snprintf(pos, end - pos, "\n"); |
| if (os_snprintf_error(end - pos, ret)) |
| return start - buf; |
| pos += ret; |
| } |
| |
| res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); |
| if (res >= 0) |
| pos += res; |
| |
| #ifdef CONFIG_WPS |
| { |
| char uuid_str[100]; |
| uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str)); |
| ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| } |
| #endif /* CONFIG_WPS */ |
| |
| #ifdef ANDROID |
| /* |
| * Allow using the STATUS command with default behavior, say for debug, |
| * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE |
| * events with STATUS-NO_EVENTS. |
| */ |
| if (os_strcmp(params, "-NO_EVENTS")) { |
| wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE |
| "id=%d state=%d BSSID=" MACSTR " SSID=%s", |
| wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, |
| wpa_s->wpa_state, |
| MAC2STR(wpa_s->bssid), |
| wpa_s->current_ssid && wpa_s->current_ssid->ssid ? |
| wpa_ssid_txt(wpa_s->current_ssid->ssid, |
| wpa_s->current_ssid->ssid_len) : ""); |
| if (wpa_s->wpa_state == WPA_COMPLETED) { |
| struct wpa_ssid *ssid = wpa_s->current_ssid; |
| wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED |
| "- connection to " MACSTR |
| " completed %s [id=%d id_str=%s]", |
| MAC2STR(wpa_s->bssid), "(auth)", |
| ssid ? ssid->id : -1, |
| ssid && ssid->id_str ? ssid->id_str : ""); |
| } |
| } |
| #endif /* ANDROID */ |
| |
| return pos - buf; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s, |
| char *cmd) |
| { |
| char *pos; |
| int id; |
| struct wpa_ssid *ssid; |
| u8 bssid[ETH_ALEN]; |
| |
| /* cmd: "<network id> <BSSID>" */ |
| pos = os_strchr(cmd, ' '); |
| if (pos == NULL) |
| return -1; |
| *pos++ = '\0'; |
| id = atoi(cmd); |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos); |
| if (hwaddr_aton(pos, bssid)) { |
| wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos); |
| return -1; |
| } |
| |
| ssid = wpa_config_get_network(wpa_s->conf, id); |
| if (ssid == NULL) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " |
| "to update", id); |
| return -1; |
| } |
| |
| os_memcpy(ssid->bssid, bssid, ETH_ALEN); |
| ssid->bssid_set = !is_zero_ether_addr(bssid); |
| |
| return 0; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s, |
| char *cmd, char *buf, |
| size_t buflen) |
| { |
| u8 bssid[ETH_ALEN]; |
| struct wpa_blacklist *e; |
| char *pos, *end; |
| int ret; |
| |
| /* cmd: "BLACKLIST [<BSSID>]" */ |
| if (*cmd == '\0') { |
| pos = buf; |
| end = buf + buflen; |
| e = wpa_s->blacklist; |
| while (e) { |
| ret = os_snprintf(pos, end - pos, MACSTR "\n", |
| MAC2STR(e->bssid)); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| e = e->next; |
| } |
| return pos - buf; |
| } |
| |
| cmd++; |
| if (os_strncmp(cmd, "clear", 5) == 0) { |
| wpa_blacklist_clear(wpa_s); |
| os_memcpy(buf, "OK\n", 3); |
| return 3; |
| } |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd); |
| if (hwaddr_aton(cmd, bssid)) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd); |
| return -1; |
| } |
| |
| /* |
| * Add the BSSID twice, so its count will be 2, causing it to be |
| * skipped when processing scan results. |
| */ |
| ret = wpa_blacklist_add(wpa_s, bssid); |
| if (ret < 0) |
| return -1; |
| ret = wpa_blacklist_add(wpa_s, bssid); |
| if (ret < 0) |
| return -1; |
| os_memcpy(buf, "OK\n", 3); |
| return 3; |
| } |
| |
| |
| static const char * debug_level_str(int level) |
| { |
| switch (level) { |
| case MSG_EXCESSIVE: |
| return "EXCESSIVE"; |
| case MSG_MSGDUMP: |
| return "MSGDUMP"; |
| case MSG_DEBUG: |
| return "DEBUG"; |
| case MSG_INFO: |
| return "INFO"; |
| case MSG_WARNING: |
| return "WARNING"; |
| case MSG_ERROR: |
| return "ERROR"; |
| default: |
| return "?"; |
| } |
| } |
| |
| |
| static int str_to_debug_level(const char *s) |
| { |
| if (os_strcasecmp(s, "EXCESSIVE") == 0) |
| return MSG_EXCESSIVE; |
| if (os_strcasecmp(s, "MSGDUMP") == 0) |
| return MSG_MSGDUMP; |
| if (os_strcasecmp(s, "DEBUG") == 0) |
| return MSG_DEBUG; |
| if (os_strcasecmp(s, "INFO") == 0) |
| return MSG_INFO; |
| if (os_strcasecmp(s, "WARNING") == 0) |
| return MSG_WARNING; |
| if (os_strcasecmp(s, "ERROR") == 0) |
| return MSG_ERROR; |
| return -1; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s, |
| char *cmd, char *buf, |
| size_t buflen) |
| { |
| char *pos, *end, *stamp; |
| int ret; |
| |
| /* cmd: "LOG_LEVEL [<level>]" */ |
| if (*cmd == '\0') { |
| pos = buf; |
| end = buf + buflen; |
| ret = os_snprintf(pos, end - pos, "Current level: %s\n" |
| "Timestamp: %d\n", |
| debug_level_str(wpa_debug_level), |
| wpa_debug_timestamp); |
| if (os_snprintf_error(end - pos, ret)) |
| ret = 0; |
| |
| return ret; |
| } |
| |
| while (*cmd == ' ') |
| cmd++; |
| |
| stamp = os_strchr(cmd, ' '); |
| if (stamp) { |
| *stamp++ = '\0'; |
| while (*stamp == ' ') { |
| stamp++; |
| } |
| } |
| |
| if (cmd && os_strlen(cmd)) { |
| int level = str_to_debug_level(cmd); |
| if (level < 0) |
| return -1; |
| wpa_debug_level = level; |
| } |
| |
| if (stamp && os_strlen(stamp)) |
| wpa_debug_timestamp = atoi(stamp); |
| |
| os_memcpy(buf, "OK\n", 3); |
| return 3; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_list_networks( |
| struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) |
| { |
| char *pos, *end, *prev; |
| struct wpa_ssid *ssid; |
| int ret; |
| |
| pos = buf; |
| end = buf + buflen; |
| ret = os_snprintf(pos, end - pos, |
| "network id / ssid / bssid / flags\n"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| |
| ssid = wpa_s->conf->ssid; |
| |
| /* skip over ssids until we find next one */ |
| if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) { |
| int last_id = atoi(cmd + 8); |
| if (last_id != -1) { |
| while (ssid != NULL && ssid->id <= last_id) { |
| ssid = ssid->next; |
| } |
| } |
| } |
| |
| while (ssid) { |
| prev = pos; |
| ret = os_snprintf(pos, end - pos, "%d\t%s", |
| ssid->id, |
| wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
| if (os_snprintf_error(end - pos, ret)) |
| return prev - buf; |
| pos += ret; |
| if (ssid->bssid_set) { |
| ret = os_snprintf(pos, end - pos, "\t" MACSTR, |
| MAC2STR(ssid->bssid)); |
| } else { |
| ret = os_snprintf(pos, end - pos, "\tany"); |
| } |
| if (os_snprintf_error(end - pos, ret)) |
| return prev - buf; |
| pos += ret; |
| ret = os_snprintf(pos, end - pos, "\t%s%s%s%s", |
| ssid == wpa_s->current_ssid ? |
| "[CURRENT]" : "", |
| ssid->disabled ? "[DISABLED]" : "", |
| ssid->disabled_until.sec ? |
| "[TEMP-DISABLED]" : "", |
| ssid->disabled == 2 ? "[P2P-PERSISTENT]" : |
| ""); |
| if (os_snprintf_error(end - pos, ret)) |
| return prev - buf; |
| pos += ret; |
| ret = os_snprintf(pos, end - pos, "\n"); |
| if (os_snprintf_error(end - pos, ret)) |
| return prev - buf; |
| pos += ret; |
| |
| ssid = ssid->next; |
| } |
| |
| return pos - buf; |
| } |
| |
| |
| static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher) |
| { |
| int ret; |
| ret = os_snprintf(pos, end - pos, "-"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| ret = wpa_write_ciphers(pos, end, cipher, "+"); |
| if (ret < 0) |
| return pos; |
| pos += ret; |
| return pos; |
| } |
| |
| |
| static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto, |
| const u8 *ie, size_t ie_len) |
| { |
| struct wpa_ie_data data; |
| char *start; |
| int ret; |
| |
| ret = os_snprintf(pos, end - pos, "[%s-", proto); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| |
| if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) { |
| ret = os_snprintf(pos, end - pos, "?]"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| return pos; |
| } |
| |
| start = pos; |
| if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) { |
| ret = os_snprintf(pos, end - pos, "%sEAP", |
| pos == start ? "" : "+"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| if (data.key_mgmt & WPA_KEY_MGMT_PSK) { |
| ret = os_snprintf(pos, end - pos, "%sPSK", |
| pos == start ? "" : "+"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) { |
| ret = os_snprintf(pos, end - pos, "%sNone", |
| pos == start ? "" : "+"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| if (data.key_mgmt & WPA_KEY_MGMT_SAE) { |
| ret = os_snprintf(pos, end - pos, "%sSAE", |
| pos == start ? "" : "+"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| #ifdef CONFIG_IEEE80211R |
| if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { |
| ret = os_snprintf(pos, end - pos, "%sFT/EAP", |
| pos == start ? "" : "+"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) { |
| ret = os_snprintf(pos, end - pos, "%sFT/PSK", |
| pos == start ? "" : "+"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) { |
| ret = os_snprintf(pos, end - pos, "%sFT/SAE", |
| pos == start ? "" : "+"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| #endif /* CONFIG_IEEE80211R */ |
| #ifdef CONFIG_IEEE80211W |
| if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { |
| ret = os_snprintf(pos, end - pos, "%sEAP-SHA256", |
| pos == start ? "" : "+"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { |
| ret = os_snprintf(pos, end - pos, "%sPSK-SHA256", |
| pos == start ? "" : "+"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| #endif /* CONFIG_IEEE80211W */ |
| |
| #ifdef CONFIG_SUITEB |
| if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
| ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B", |
| pos == start ? "" : "+"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| #endif /* CONFIG_SUITEB */ |
| |
| #ifdef CONFIG_SUITEB192 |
| if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
| ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192", |
| pos == start ? "" : "+"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| #endif /* CONFIG_SUITEB192 */ |
| |
| if (data.key_mgmt & WPA_KEY_MGMT_OSEN) { |
| ret = os_snprintf(pos, end - pos, "%sOSEN", |
| pos == start ? "" : "+"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| |
| pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher); |
| |
| if (data.capabilities & WPA_CAPABILITY_PREAUTH) { |
| ret = os_snprintf(pos, end - pos, "-preauth"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| } |
| |
| ret = os_snprintf(pos, end - pos, "]"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos; |
| pos += ret; |
| |
| return pos; |
| } |
| |
| |
| #ifdef CONFIG_WPS |
| static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s, |
| char *pos, char *end, |
| struct wpabuf *wps_ie) |
| { |
| int ret; |
| const char *txt; |
| |
| if (wps_ie == NULL) |
| return pos; |
| if (wps_is_selected_pbc_registrar(wps_ie)) |
| txt = "[WPS-PBC]"; |
| else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0)) |
| txt = "[WPS-AUTH]"; |
| else if (wps_is_selected_pin_registrar(wps_ie)) |
| txt = "[WPS-PIN]"; |
| else |
| txt = "[WPS]"; |
| |
| ret = os_snprintf(pos, end - pos, "%s", txt); |
| if (!os_snprintf_error(end - pos, ret)) |
| pos += ret; |
| wpabuf_free(wps_ie); |
| return pos; |
| } |
| #endif /* CONFIG_WPS */ |
| |
| |
| static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s, |
| char *pos, char *end, |
| const struct wpa_bss *bss) |
| { |
| #ifdef CONFIG_WPS |
| struct wpabuf *wps_ie; |
| wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
| return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie); |
| #else /* CONFIG_WPS */ |
| return pos; |
| #endif /* CONFIG_WPS */ |
| } |
| |
| |
| /* Format one result on one text line into a buffer. */ |
| static int wpa_supplicant_ctrl_iface_scan_result( |
| struct wpa_supplicant *wpa_s, |
| const struct wpa_bss *bss, char *buf, size_t buflen) |
| { |
| char *pos, *end; |
| int ret; |
| const u8 *ie, *ie2, *osen_ie, *p2p, *mesh; |
| |
| mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID); |
| p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); |
| if (!p2p) |
| p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE); |
| if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN && |
| os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == |
| 0) |
| return 0; /* Do not show P2P listen discovery results here */ |
| |
| pos = buf; |
| end = buf + buflen; |
| |
| ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t", |
| MAC2STR(bss->bssid), bss->freq, bss->level); |
| if (os_snprintf_error(end - pos, ret)) |
| return -1; |
| pos += ret; |
| ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| if (ie) |
| pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]); |
| ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| if (ie2) { |
| pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2", |
| ie2, 2 + ie2[1]); |
| } |
| osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
| if (osen_ie) |
| pos = wpa_supplicant_ie_txt(pos, end, "OSEN", |
| osen_ie, 2 + osen_ie[1]); |
| pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss); |
| if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) { |
| ret = os_snprintf(pos, end - pos, "[WEP]"); |
| if (os_snprintf_error(end - pos, ret)) |
| return -1; |
| pos += ret; |
| } |
| if (mesh) { |
| ret = os_snprintf(pos, end - pos, "[MESH]"); |
| if (os_snprintf_error(end - pos, ret)) |
| return -1; |
| pos += ret; |
| } |
| if (bss_is_dmg(bss)) { |
| const char *s; |
| ret = os_snprintf(pos, end - pos, "[DMG]"); |
| if (os_snprintf_error(end - pos, ret)) |
| return -1; |
| pos += ret; |
| switch (bss->caps & IEEE80211_CAP_DMG_MASK) { |
| case IEEE80211_CAP_DMG_IBSS: |
| s = "[IBSS]"; |
| break; |
| case IEEE80211_CAP_DMG_AP: |
| s = "[ESS]"; |
| break; |
| case IEEE80211_CAP_DMG_PBSS: |
| s = "[PBSS]"; |
| break; |
| default: |
| s = ""; |
| break; |
| } |
| ret = os_snprintf(pos, end - pos, "%s", s); |
| if (os_snprintf_error(end - pos, ret)) |
| return -1; |
| pos += ret; |
| } else { |
| if (bss->caps & IEEE80211_CAP_IBSS) { |
| ret = os_snprintf(pos, end - pos, "[IBSS]"); |
| if (os_snprintf_error(end - pos, ret)) |
| return -1; |
| pos += ret; |
| } |
| if (bss->caps & IEEE80211_CAP_ESS) { |
| ret = os_snprintf(pos, end - pos, "[ESS]"); |
| if (os_snprintf_error(end - pos, ret)) |
| return -1; |
| pos += ret; |
| } |
| } |
| if (p2p) { |
| ret = os_snprintf(pos, end - pos, "[P2P]"); |
| if (os_snprintf_error(end - pos, ret)) |
| return -1; |
| pos += ret; |
| } |
| #ifdef CONFIG_HS20 |
| if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) { |
| ret = os_snprintf(pos, end - pos, "[HS20]"); |
| if (os_snprintf_error(end - pos, ret)) |
| return -1; |
| pos += ret; |
| } |
| #endif /* CONFIG_HS20 */ |
| |
| ret = os_snprintf(pos, end - pos, "\t%s", |
| wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
| if (os_snprintf_error(end - pos, ret)) |
| return -1; |
| pos += ret; |
| |
| ret = os_snprintf(pos, end - pos, "\n"); |
| if (os_snprintf_error(end - pos, ret)) |
| return -1; |
| pos += ret; |
| |
| return pos - buf; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_scan_results( |
| struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| { |
| char *pos, *end; |
| struct wpa_bss *bss; |
| int ret; |
| |
| pos = buf; |
| end = buf + buflen; |
| ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / " |
| "flags / ssid\n"); |
| if (os_snprintf_error(end - pos, ret)) |
| return pos - buf; |
| pos += ret; |
| |
| dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
| ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos, |
| end - pos); |
| if (ret < 0 || ret >= end - pos) |
| return pos - buf; |
| pos += ret; |
| } |
| |
| return pos - buf; |
| } |
| |
| |
| #ifdef CONFIG_MESH |
| |
| static int wpa_supplicant_ctrl_iface_mesh_interface_add( |
| struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len) |
| { |
| char *pos, ifname[IFNAMSIZ + 1]; |
| |
| ifname[0] = '\0'; |
| |
| pos = os_strstr(cmd, "ifname="); |
| if (pos) { |
| pos += 7; |
| os_strlcpy(ifname, pos, sizeof(ifname)); |
| } |
| |
| if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0) |
| return -1; |
| |
| os_strlcpy(reply, ifname, max_len); |
| return os_strlen(ifname); |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_mesh_group_add( |
| struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| int id; |
| struct wpa_ssid *ssid; |
| |
| id = atoi(cmd); |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id); |
| |
| ssid = wpa_config_get_network(wpa_s->conf, id); |
| if (ssid == NULL) { |
| wpa_printf(MSG_DEBUG, |
| "CTRL_IFACE: Could not find network id=%d", id); |
| return -1; |
| } |
| if (ssid->mode != WPAS_MODE_MESH) { |
| wpa_printf(MSG_DEBUG, |
| "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network"); |
| return -1; |
| } |
| if (ssid->key_mgmt != WPA_KEY_MGMT_NONE && |
| ssid->key_mgmt != WPA_KEY_MGMT_SAE) { |
| wpa_printf(MSG_ERROR, |
| "CTRL_IFACE: key_mgmt for mesh network should be open or SAE"); |
| return -1; |
| } |
| |
| /* |
| * TODO: If necessary write our own group_add function, |
| * for now we can reuse select_network |
| */ |
| wpa_supplicant_select_network(wpa_s, ssid); |
| |
| return 0; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_mesh_group_remove( |
| struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| struct wpa_supplicant *orig; |
| struct wpa_global *global; |
| int found = 0; |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd); |
| |
| global = wpa_s->global; |
| orig = wpa_s; |
| |
| for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| if (os_strcmp(wpa_s->ifname, cmd) == 0) { |
| found = 1; |
| break; |
| } |
| } |
| if (!found) { |
| wpa_printf(MSG_ERROR, |
| "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found", |
| cmd); |
| return -1; |
| } |
| if (wpa_s->mesh_if_created && wpa_s == orig) { |
| wpa_printf(MSG_ERROR, |
| "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself"); |
| return -1; |
| } |
| |
| wpa_s->reassociate = 0; |
| wpa_s->disconnected = 1; |
| wpa_supplicant_cancel_sched_scan(wpa_s); |
| wpa_supplicant_cancel_scan(wpa_s); |
| |
| /* |
| * TODO: If necessary write our own group_remove function, |
| * for now we can reuse deauthenticate |
| */ |
| wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| |
| if (wpa_s->mesh_if_created) |
| wpa_supplicant_remove_iface(global, wpa_s, 0); |
| |
| return 0; |
| } |
| |
| #endif /* CONFIG_MESH */ |
| |
| |
| static int wpa_supplicant_ctrl_iface_select_network( |
| struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| int id; |
| struct wpa_ssid *ssid; |
| char *pos; |
| |
| /* cmd: "<network id>" or "any" */ |
| if (os_strncmp(cmd, "any", 3) == 0) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any"); |
| ssid = NULL; |
| } else { |
| id = atoi(cmd); |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id); |
| |
| ssid = wpa_config_get_network(wpa_s->conf, id); |
| if (ssid == NULL) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| "network id=%d", id); |
| return -1; |
| } |
| if (ssid->disabled == 2) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| "SELECT_NETWORK with persistent P2P group"); |
| return -1; |
| } |
| } |
| |
| pos = os_strstr(cmd, " freq="); |
| if (pos) { |
| int *freqs = freq_range_to_channel_list(wpa_s, pos + 6); |
| if (freqs) { |
| wpa_s->scan_req = MANUAL_SCAN_REQ; |
| os_free(wpa_s->manual_scan_freqs); |
| wpa_s->manual_scan_freqs = freqs; |
| } |
| } |
| |
| wpa_supplicant_select_network(wpa_s, ssid); |
| |
| return 0; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_enable_network( |
| struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| int id; |
| struct wpa_ssid *ssid; |
| |
| /* cmd: "<network id>" or "all" */ |
| if (os_strcmp(cmd, "all") == 0) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all"); |
| ssid = NULL; |
| } else { |
| id = atoi(cmd); |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id); |
| |
| ssid = wpa_config_get_network(wpa_s->conf, id); |
| if (ssid == NULL) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| "network id=%d", id); |
| return -1; |
| } |
| if (ssid->disabled == 2) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| "ENABLE_NETWORK with persistent P2P group"); |
| return -1; |
| } |
| |
| if (os_strstr(cmd, " no-connect")) { |
| ssid->disabled = 0; |
| return 0; |
| } |
| } |
| wpa_supplicant_enable_network(wpa_s, ssid); |
| |
| return 0; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_disable_network( |
| struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| int id; |
| struct wpa_ssid *ssid; |
| |
| /* cmd: "<network id>" or "all" */ |
| if (os_strcmp(cmd, "all") == 0) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all"); |
| ssid = NULL; |
| } else { |
| id = atoi(cmd); |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id); |
| |
| ssid = wpa_config_get_network(wpa_s->conf, id); |
| if (ssid == NULL) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " |
| "network id=%d", id); |
| return -1; |
| } |
| if (ssid->disabled == 2) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " |
| "DISABLE_NETWORK with persistent P2P " |
| "group"); |
| return -1; |
| } |
| } |
| wpa_supplicant_disable_network(wpa_s, ssid); |
| |
| return 0; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_add_network( |
| struct wpa_supplicant *wpa_s, char *buf, size_t buflen) |
| { |
| struct wpa_ssid *ssid; |
| int ret; |
| |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK"); |
| |
| ssid = wpa_config_add_network(wpa_s->conf); |
| if (ssid == NULL) |
| return -1; |
| |
| wpas_notify_network_added(wpa_s, ssid); |
| |
| ssid->disabled = 1; |
| wpa_config_set_network_defaults(ssid); |
| |
| ret = os_snprintf(buf, buflen, "%d\n", ssid->id); |
| if (os_snprintf_error(buflen, ret)) |
| return -1; |
| return ret; |
| } |
| |
| |
| static int wpa_supplicant_ctrl_iface_remove_network( |
| struct wpa_supplicant *wpa_s, char *cmd) |
| { |
| int id; |
| struct wpa_ssid *ssid; |
| int was_disabled; |
| |
| /* cmd: "<network id>" or "all" */ |
| if (os_strcmp(cmd, "all") == 0) { |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all"); |
| if (wpa_s->sched_scanning) |
| wpa_supplicant_cancel_sched_scan(wpa_s); |
| |
| eapol_sm_invalidate_cached_session(wpa_s->eapol); |
| if (wpa_s->current_ssid) { |
| #ifdef CONFIG_SME |
| wpa_s->sme.prev_bssid_set = 0; |
| #endif /* CONFIG_SME */ |
| wpa_sm_set_config(wpa_s->wpa, NULL); |
| eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
| wpa_s->own_disconnect_req = 1; |
| wpa_supplicant_deauthenticate( |
| wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| } |
| ssid = wpa_s->conf->ssid; |
| while (ssid) { |
| struct wpa_ssid *remove_ssid = ssid; |
| id = ssid->id; |
| ssid = ssid->next; |
| if (wpa_s->last_ssid == remove_ssid) |
| wpa_s->last_ssid = NULL; |
| wpas_notify_network_removed(wpa_s, remove_ssid); |
| wpa_config_remove_network(wpa_s->conf, id); |
| } |
| return 0; |
| } |
| |
| id = atoi(cmd); |
| wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id); |
| |
|