blob: 7001f1d55a1d573ee6a0392a7ece2b4bea48bacf [file] [log] [blame]
/*
* Copyright (c) 2010 Broadcom Corporation
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* Toplevel file. Relies on dhd_linux.c to send commands to the dongle. */
#include "cfg80211.h"
#include <threads.h>
#include <zircon/status.h>
#include <algorithm>
#include <ddk/hw/wlan/wlaninfo.h>
#include <wlan/protocol/ieee80211.h>
#include <wlan/protocol/if-impl.h>
#include <wlan/protocol/mac.h>
#include "bits.h"
#include "brcmu_utils.h"
#include "brcmu_wifi.h"
#include "btcoex.h"
#include "common.h"
#include "core.h"
#include "debug.h"
#include "defs.h"
#include "feature.h"
#include "fwil.h"
#include "fwil_types.h"
#include "linuxisms.h"
#include "macros.h"
#include "netbuf.h"
#include "p2p.h"
#include "pno.h"
#include "proto.h"
#include "workqueue.h"
#define BRCMF_SCAN_IE_LEN_MAX 2048
#define WPA_OUI "\x00\x50\xF2" /* WPA OUI */
#define WPA_OUI_TYPE 1
#define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */
#define WME_OUI_TYPE 2
#define WPS_OUI_TYPE 4
#define VS_IE_FIXED_HDR_LEN 6
#define WPA_IE_VERSION_LEN 2
#define WPA_IE_MIN_OUI_LEN 4
#define WPA_IE_SUITE_COUNT_LEN 2
// IEEE Std. 802.11-2016, 9.4.2.1, Table 9-77
#define WLAN_IE_TYPE_SSID 0
#define WLAN_IE_TYPE_SUPP_RATES 1
#define WLAN_IE_TYPE_RSNE 48
#define WLAN_IE_TYPE_EXT_SUPP_RATES 50
/* IEEE Std. 802.11-2016, 9.4.2.25.2, Table 9-131 */
#define WPA_CIPHER_NONE 0 /* None */
#define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */
#define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */
/* RESERVED 3 */
#define WPA_CIPHER_CCMP_128 4 /* AES (CCM) */
#define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */
#define WPA_CIPHER_CMAC_128 6 /* BIP-CMAC-128 */
#define RSN_AKM_NONE 0 /* None (IBSS) */
#define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */
#define RSN_AKM_PSK 2 /* Pre-shared Key */
#define RSN_AKM_SHA256_1X 5 /* SHA256, 802.1X */
#define RSN_AKM_SHA256_PSK 6 /* SHA256, Pre-shared Key */
#define RSN_CAP_LEN 2 /* Length of RSN capabilities */
#define RSN_CAP_PTK_REPLAY_CNTR_MASK (BIT(2) | BIT(3))
#define RSN_CAP_MFPR_MASK BIT(6)
#define RSN_CAP_MFPC_MASK BIT(7)
#define RSN_PMKID_COUNT_LEN 2
#define VNDR_IE_CMD_LEN 4 /* length of the set command string :"add", "del" (+ NUL) */
#define VNDR_IE_COUNT_OFFSET 4
#define VNDR_IE_PKTFLAG_OFFSET 8
#define VNDR_IE_VSIE_OFFSET 12
#define VNDR_IE_HDR_SIZE 12
#define VNDR_IE_PARSE_LIMIT 5
#define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */
#define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */
#define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320
#define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400
#define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20
#define BRCMF_SCAN_CHANNEL_TIME 40
#define BRCMF_SCAN_UNASSOC_TIME 40
#define BRCMF_SCAN_PASSIVE_TIME 120
#define BRCMF_ND_INFO_TIMEOUT_MSEC 2000
#define BRCMF_ASSOC_PARAMS_FIXED_SIZE (sizeof(struct brcmf_assoc_params_le) - sizeof(uint16_t))
static bool check_vif_up(struct brcmf_cfg80211_vif* vif) {
if (!brcmf_test_bit_in_array(BRCMF_VIF_STATUS_READY, &vif->sme_state)) {
BRCMF_DBG(INFO, "device is not ready : status (%lu)\n", vif->sme_state.load());
return false;
}
return true;
}
static uint16_t __wl_rates[] = {
BRCM_RATE_1M, BRCM_RATE_2M, BRCM_RATE_5M5, BRCM_RATE_11M, BRCM_RATE_6M, BRCM_RATE_9M,
BRCM_RATE_12M, BRCM_RATE_18M, BRCM_RATE_24M, BRCM_RATE_36M, BRCM_RATE_48M, BRCM_RATE_54M,
};
#define wl_g_rates (__wl_rates + 0)
#define wl_g_rates_size countof(__wl_rates)
#define wl_a_rates (__wl_rates + 4)
#define wl_a_rates_size ((size_t)(wl_g_rates_size - 4))
/* Vendor specific ie. id = 221, oui and type defines exact ie */
struct brcmf_vs_tlv {
uint8_t id;
uint8_t len;
uint8_t oui[3];
uint8_t oui_type;
};
struct parsed_vndr_ie_info {
uint8_t* ie_ptr;
uint32_t ie_len; /* total length including id & length field */
struct brcmf_vs_tlv vndrie;
};
struct parsed_vndr_ies {
uint32_t count;
struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT];
};
static inline void fill_with_broadcast_addr(uint8_t* address) { memset(address, 0xff, ETH_ALEN); }
uint16_t channel_to_chanspec(struct brcmu_d11inf* d11inf, wlan_channel_t* ch) {
struct brcmu_chan ch_inf;
ch_inf.chnum = ch->primary;
switch (ch->cbw) {
case CBW20:
ch_inf.bw = BRCMU_CHAN_BW_20;
ch_inf.sb = BRCMU_CHAN_SB_NONE;
break;
case CBW40:
ch_inf.bw = BRCMU_CHAN_BW_40;
ch_inf.sb = BRCMU_CHAN_SB_U;
break;
case CBW40BELOW:
ch_inf.bw = BRCMU_CHAN_BW_40;
ch_inf.sb = BRCMU_CHAN_SB_L;
break;
case CBW80:
case CBW160:
case CBW80P80:
default:
BRCMF_ERR("unsupported channel width\n");
break;
}
// ch_info.band is handled by encchspec
d11inf->encchspec(&ch_inf);
return ch_inf.chspec;
}
/* Traverse a string of 1-byte tag/1-byte length/variable-length value
* triples, returning a pointer to the substring whose first element
* matches tag
*/
static const struct brcmf_tlv* brcmf_parse_tlvs(const void* buf, int buflen, uint key) {
const struct brcmf_tlv* elt = static_cast<decltype(elt)>(buf);
int totlen = buflen;
/* find tagged parameter */
while (totlen >= TLV_HDR_LEN) {
int len = elt->len;
/* validate remaining totlen */
if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN))) {
return elt;
}
elt = (struct brcmf_tlv*)((uint8_t*)elt + (len + TLV_HDR_LEN));
totlen -= (len + TLV_HDR_LEN);
}
return NULL;
}
static zx_status_t brcmf_vif_change_validate(struct brcmf_cfg80211_info* cfg,
struct brcmf_cfg80211_vif* vif, uint16_t new_type) {
struct brcmf_cfg80211_vif* pos;
bool check_combos = false;
zx_status_t ret = ZX_OK;
struct iface_combination_params params = {
.num_different_channels = 1,
};
list_for_every_entry (&cfg->vif_list, pos, struct brcmf_cfg80211_vif, list) {
if (pos == vif) {
params.iftype_num[new_type]++;
} else {
/* concurrent interfaces so need check combinations */
check_combos = true;
params.iftype_num[pos->wdev.iftype]++;
}
}
if (check_combos) {
ret = cfg80211_check_combinations(cfg->wiphy, &params);
}
return ret;
}
static zx_status_t brcmf_vif_add_validate(struct brcmf_cfg80211_info* cfg, uint16_t new_type) {
struct brcmf_cfg80211_vif* pos;
struct iface_combination_params params = {
.num_different_channels = 1,
};
list_for_every_entry (&cfg->vif_list, pos, struct brcmf_cfg80211_vif, list) {
params.iftype_num[pos->wdev.iftype]++;
}
params.iftype_num[new_type]++;
return cfg80211_check_combinations(cfg->wiphy, &params);
}
static void convert_key_from_CPU(struct brcmf_wsec_key* key, struct brcmf_wsec_key_le* key_le) {
key_le->index = key->index;
key_le->len = key->len;
key_le->algo = key->algo;
key_le->flags = key->flags;
key_le->rxiv.hi = key->rxiv.hi;
key_le->rxiv.lo = key->rxiv.lo;
key_le->iv_initialized = key->iv_initialized;
memcpy(key_le->data, key->data, sizeof(key->data));
memcpy(key_le->ea, key->ea, sizeof(key->ea));
}
static zx_status_t send_key_to_dongle(struct brcmf_if* ifp, struct brcmf_wsec_key* key) {
zx_status_t err;
struct brcmf_wsec_key_le key_le;
convert_key_from_CPU(key, &key_le);
brcmf_netdev_wait_pend8021x(ifp);
err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le, sizeof(key_le));
if (err != ZX_OK) {
BRCMF_ERR("wsec_key error (%d)\n", err);
}
return err;
}
static void brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev* wdev) {
struct brcmf_cfg80211_vif* vif;
struct brcmf_if* ifp;
vif = containerof(wdev, struct brcmf_cfg80211_vif, wdev);
ifp = vif->ifp;
if (wdev->iftype == WLAN_INFO_MAC_ROLE_AP) {
brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, ADDR_DIRECT);
} else {
brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, ADDR_INDIRECT);
}
}
static zx_status_t brcmf_get_first_free_bsscfgidx(struct brcmf_pub* drvr) {
int bsscfgidx;
for (bsscfgidx = 0; bsscfgidx < BRCMF_MAX_IFS; bsscfgidx++) {
/* bsscfgidx 1 is reserved for legacy P2P */
if (bsscfgidx == 1) {
continue;
}
if (!drvr->iflist[bsscfgidx]) {
return bsscfgidx;
}
}
return ZX_ERR_NO_MEMORY;
}
static zx_status_t brcmf_cfg80211_request_ap_if(struct brcmf_if* ifp) {
struct brcmf_mbss_ssid_le mbss_ssid_le;
int bsscfgidx;
zx_status_t err;
memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le));
bsscfgidx = brcmf_get_first_free_bsscfgidx(ifp->drvr);
if (bsscfgidx < 0) {
return bsscfgidx;
}
mbss_ssid_le.bsscfgidx = bsscfgidx;
mbss_ssid_le.SSID_len = 5;
sprintf((char*)mbss_ssid_le.SSID, "ssid%d", bsscfgidx);
err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le, sizeof(mbss_ssid_le));
if (err != ZX_OK) {
BRCMF_ERR("setting ssid failed %d\n", err);
}
return err;
}
/**
* brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS
*
* @wiphy: wiphy device of new interface.
* @name: name of the new interface.
* @params: contains mac address for AP device.
*/
static zx_status_t brcmf_ap_add_vif(struct wiphy* wiphy, const char* name,
struct vif_params* params, struct wireless_dev** dev_out) {
struct brcmf_cfg80211_info* cfg = wiphy_to_cfg(wiphy);
struct brcmf_if* ifp = cfg_to_if(cfg);
struct brcmf_cfg80211_vif* vif;
zx_status_t err;
if (brcmf_cfg80211_vif_event_armed(cfg)) {
return ZX_ERR_UNAVAILABLE;
}
BRCMF_DBG(INFO, "Adding vif \"%s\"\n", name);
err = brcmf_alloc_vif(cfg, WLAN_INFO_MAC_ROLE_AP, &vif);
if (err != ZX_OK) {
if (dev_out) {
*dev_out = NULL;
}
return err;
}
brcmf_cfg80211_arm_vif_event(cfg, vif, BRCMF_E_IF_ADD);
err = brcmf_cfg80211_request_ap_if(ifp);
if (err != ZX_OK) {
brcmf_cfg80211_disarm_vif_event(cfg);
goto fail;
}
/* wait for firmware event */
err = brcmf_cfg80211_wait_vif_event(cfg, ZX_MSEC(BRCMF_VIF_EVENT_TIMEOUT_MSEC));
brcmf_cfg80211_disarm_vif_event(cfg);
if (err != ZX_OK) {
BRCMF_ERR("timeout occurred\n");
err = ZX_ERR_IO;
goto fail;
}
/* interface created in firmware */
ifp = vif->ifp;
if (!ifp) {
BRCMF_ERR("no if pointer provided\n");
err = ZX_ERR_INVALID_ARGS;
goto fail;
}
strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
err = brcmf_net_attach(ifp, true);
if (err != ZX_OK) {
BRCMF_ERR("Registering netdevice failed\n");
brcmf_free_net_device(ifp->ndev);
goto fail;
}
if (dev_out) {
*dev_out = &ifp->vif->wdev;
}
return ZX_OK;
fail:
brcmf_free_vif(vif);
if (dev_out) {
*dev_out = NULL;
}
return err;
}
static bool brcmf_is_apmode(struct brcmf_cfg80211_vif* vif) {
uint16_t iftype;
iftype = vif->wdev.iftype;
return iftype == WLAN_INFO_MAC_ROLE_AP;
}
zx_status_t brcmf_cfg80211_add_iface(struct wiphy* wiphy, const char* name,
unsigned char name_assign_type, uint16_t type,
struct vif_params* params, struct wireless_dev** wdev_out) {
zx_status_t err;
BRCMF_DBG(TRACE, "enter: %s type %d\n", name, type);
err = brcmf_vif_add_validate(wiphy_to_cfg(wiphy), type);
if (err != ZX_OK) {
BRCMF_ERR("iface validation failed: err=%d\n", err);
if (wdev_out) {
*wdev_out = NULL;
}
return err;
}
switch (type) {
case WLAN_INFO_MAC_ROLE_AP:
err = brcmf_ap_add_vif(wiphy, name, params, wdev_out);
break;
default:
if (wdev_out) {
*wdev_out = NULL;
}
return ZX_ERR_INVALID_ARGS;
}
if (err != ZX_OK) {
BRCMF_ERR("add iface %s type %d failed: err=%d\n", name, type, err);
if (wdev_out) {
*wdev_out = NULL;
}
return err;
} else {
brcmf_cfg80211_update_proto_addr_mode(*wdev_out);
return ZX_OK;
}
}
static void brcmf_scan_config_mpc(struct brcmf_if* ifp, int mpc) {
if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC)) {
brcmf_set_mpc(ifp, mpc);
}
}
void brcmf_set_mpc(struct brcmf_if* ifp, int mpc) {
zx_status_t err = ZX_OK;
int32_t fw_err = 0;
if (check_vif_up(ifp->vif)) {
err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc, &fw_err);
if (err != ZX_OK) {
BRCMF_ERR("fail to set mpc: %s, fw err %s\n", zx_status_get_string(err),
brcmf_fil_get_errstr(fw_err));
return;
}
BRCMF_DBG(INFO, "MPC : %d\n", mpc);
}
}
static void brcmf_signal_scan_end(struct net_device* ndev, uint64_t txn_id,
uint8_t scan_result_code) {
wlanif_scan_end_t args;
args.txn_id = txn_id;
args.code = scan_result_code;
if (ndev->if_callbacks != NULL) {
BRCMF_DBG(SCAN, "Signaling on_scan_end with txn_id %ld and code %d", args.txn_id, args.code);
BRCMF_DBG(WLANIF, "Sending scan end event to SME. txn_id: %" PRIu64 ", result: %s\n",
args.txn_id,
args.code == WLAN_SCAN_RESULT_SUCCESS
? "success"
: args.code == WLAN_SCAN_RESULT_NOT_SUPPORTED
? "not supported"
: args.code == WLAN_SCAN_RESULT_INVALID_ARGS
? "invalid args"
: args.code == WLAN_SCAN_RESULT_INTERNAL_ERROR ? "internal error"
: "unknown");
ndev->if_callbacks->on_scan_end(ndev->if_callback_cookie, &args);
}
ndev->scan_busy = false;
}
zx_status_t brcmf_notify_escan_complete(struct brcmf_cfg80211_info* cfg, struct brcmf_if* ifp,
bool aborted, bool fw_abort) {
struct brcmf_scan_params_le params_le;
wlanif_scan_req_t* scan_request;
uint64_t reqid;
uint32_t bucket;
zx_status_t err = ZX_OK;
BRCMF_DBG(SCAN, "Enter\n");
/* clear scan request, because the FW abort can cause a second call */
/* to this function and might cause a double signal_scan_end */
scan_request = cfg->scan_request;
cfg->scan_request = NULL;
// Canceling if it's inactive is OK. Checking if it's active just invites race conditions.
brcmf_timer_stop(&cfg->escan_timeout);
if (fw_abort) {
/* Do a scan abort to stop the driver's scan engine */
BRCMF_DBG(SCAN, "ABORT scan in firmware\n");
memset(&params_le, 0, sizeof(params_le));
fill_with_broadcast_addr(params_le.bssid);
params_le.bss_type = DOT11_BSSTYPE_ANY;
params_le.scan_type = 0;
params_le.channel_num = 1;
params_le.nprobes = 1;
params_le.active_time = -1;
params_le.passive_time = -1;
params_le.home_time = -1;
/* Scan is aborted by setting channel_list[0] to -1 */
params_le.channel_list[0] = -1;
/* E-Scan (or anyother type) can be aborted by SCAN */
int32_t fwerr = 0;
err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, &params_le, sizeof(params_le), &fwerr);
if (err != ZX_OK) {
BRCMF_ERR("Scan abort failed: %s (fw err %s)\n", zx_status_get_string(err),
brcmf_fil_get_errstr(fwerr));
}
}
brcmf_scan_config_mpc(ifp, 1);
/*
* e-scan can be initiated internally
* which takes precedence.
*/
struct net_device* ndev = cfg_to_ndev(cfg);
if (cfg->int_escan_map) {
BRCMF_DBG(SCAN, "scheduled scan completed (%x)\n", cfg->int_escan_map);
while (cfg->int_escan_map) {
bucket = ffs(cfg->int_escan_map) - 1; // ffs() index is 1-based
cfg->int_escan_map &= ~BIT(bucket);
reqid = brcmf_pno_find_reqid_by_bucket(cfg->pno, bucket);
if (!aborted) {
// TODO(cphoenix): Figure out how to use internal reqid infrastructure, rather
// than storing it separately in wiphy->scan_txn_id.
BRCMF_DBG(SCAN, " * * report scan results: internal reqid=%lu\n", reqid);
brcmf_signal_scan_end(ndev, ndev->scan_txn_id, WLAN_SCAN_RESULT_SUCCESS);
}
}
} else if (scan_request) {
BRCMF_DBG(SCAN, "ESCAN Completed scan: %s\n", aborted ? "Aborted" : "Done");
brcmf_signal_scan_end(ndev, ndev->scan_txn_id,
aborted ? WLAN_SCAN_RESULT_INTERNAL_ERROR : WLAN_SCAN_RESULT_SUCCESS);
}
if (!brcmf_test_and_clear_bit_in_array(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
BRCMF_DBG(SCAN, "Scan complete, probably P2P scan\n");
}
return err;
}
static zx_status_t brcmf_cfg80211_change_iface(struct wiphy* wiphy, struct net_device* ndev,
uint16_t type, struct vif_params* params) {
struct brcmf_if* ifp = ndev_to_if(ndev);
struct brcmf_cfg80211_vif* vif = ifp->vif;
int32_t infra = 0;
int32_t ap = 0;
zx_status_t err = ZX_OK;
int32_t fw_err = 0;
BRCMF_DBG(TRACE, "Enter");
err = brcmf_vif_change_validate(wiphy_to_cfg(wiphy), vif, type);
if (err != ZX_OK) {
BRCMF_ERR("iface validation failed: err=%d\n", err);
return err;
}
switch (type) {
case WLAN_INFO_MAC_ROLE_CLIENT:
infra = 1;
break;
case WLAN_INFO_MAC_ROLE_AP:
ap = 1;
break;
default:
err = ZX_ERR_OUT_OF_RANGE;
goto done;
}
if (ap) {
BRCMF_DBG(INFO, "IF Type = AP\n");
} else {
err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra, &fw_err);
if (err != ZX_OK) {
BRCMF_ERR("WLC_SET_INFRA error: %s, fw err %s\n", zx_status_get_string(err),
brcmf_fil_get_errstr(fw_err));
err = ZX_ERR_UNAVAILABLE;
goto done;
}
BRCMF_DBG(INFO, "IF Type = Infra");
}
ndev->ieee80211_ptr->iftype = type;
brcmf_cfg80211_update_proto_addr_mode(&vif->wdev);
done:
BRCMF_DBG(TRACE, "Exit\n");
return err;
}
static void brcmf_escan_prep(struct brcmf_cfg80211_info* cfg,
struct brcmf_scan_params_le* params_le, wlanif_scan_req_t* request) {
uint32_t n_ssids;
uint32_t n_channels;
int32_t i;
int32_t offset;
uint16_t chanspec;
char* ptr;
struct brcmf_ssid_le ssid_le;
fill_with_broadcast_addr(params_le->bssid);
params_le->bss_type = DOT11_BSSTYPE_ANY;
if (request->scan_type == WLAN_SCAN_TYPE_ACTIVE) {
params_le->scan_type = BRCMF_SCANTYPE_ACTIVE;
} else {
params_le->scan_type = BRCMF_SCANTYPE_PASSIVE;
}
params_le->channel_num = 0;
params_le->nprobes = -1;
params_le->active_time = -1;
params_le->passive_time = -1;
params_le->home_time = -1;
params_le->ssid_le.SSID_len = request->ssid.len;
if (request->ssid.len <= sizeof(params_le->ssid_le.SSID)) {
memcpy(params_le->ssid_le.SSID, request->ssid.data, request->ssid.len);
} else {
memcpy(params_le->ssid_le.SSID, request->ssid.data, sizeof(params_le->ssid_le.SSID));
BRCMF_ERR("Scan request SSID size too large\n");
}
n_ssids = request->num_ssids;
n_channels = request->num_channels;
/* Copy channel array if applicable */
BRCMF_DBG(SCAN, "### List of channelspecs to scan ### %d\n", n_channels);
if (n_channels > 0) {
for (i = 0; i < (int32_t)n_channels; i++) {
wlan_channel_t wlan_chan;
wlan_chan.primary = request->channel_list[i];
wlan_chan.cbw = CBW20;
wlan_chan.secondary80 = 0;
chanspec = channel_to_chanspec(&cfg->d11inf, &wlan_chan);
BRCMF_DBG(SCAN, "Chan : %d, Channel spec: %x\n", request->channel_list[i], chanspec);
params_le->channel_list[i] = chanspec;
}
} else {
BRCMF_DBG(SCAN, "Scanning all channels\n");
}
/* Copy ssid array if applicable */
BRCMF_DBG(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids);
if (n_ssids > 0) {
if (params_le->scan_type == BRCMF_SCANTYPE_ACTIVE) {
offset = offsetof(struct brcmf_scan_params_le, channel_list) + n_channels * sizeof(uint16_t);
offset = roundup(offset, sizeof(uint32_t));
ptr = (char*)params_le + offset;
for (i = 0; i < (int32_t)n_ssids; i++) {
memset(&ssid_le, 0, sizeof(ssid_le));
ssid_le.SSID_len = request->ssid_list[i].len;
memcpy(ssid_le.SSID, request->ssid_list[i].data, request->ssid_list[i].len);
if (!ssid_le.SSID_len) {
BRCMF_DBG(SCAN, "%d: Broadcast scan\n", i);
} else {
BRCMF_DBG(SCAN, "%d: scan for %.32s size=%d\n", i, ssid_le.SSID, ssid_le.SSID_len);
}
memcpy(ptr, &ssid_le, sizeof(ssid_le));
ptr += sizeof(ssid_le);
}
} else {
BRCMF_ERR("SSID list received for passive scan\n");
}
}
/* Adding mask to channel numbers */
params_le->channel_num =
(n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) | (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK);
}
static zx_status_t brcmf_run_escan(struct brcmf_cfg80211_info* cfg, struct brcmf_if* ifp,
wlanif_scan_req_t* request) {
int32_t params_size =
BRCMF_SCAN_PARAMS_FIXED_SIZE + offsetof(struct brcmf_escan_params_le, params_le);
struct brcmf_escan_params_le* params;
zx_status_t err = ZX_OK;
int32_t fw_err = 0;
BRCMF_DBG(SCAN, "E-SCAN START\n");
if (request != NULL) {
/* Allocate space for populating ssids in struct */
params_size += sizeof(uint32_t) * ((request->num_channels + 1) / 2);
/* Allocate space for populating ssids in struct */
params_size += sizeof(struct brcmf_ssid_le) * request->num_ssids;
}
params = static_cast<decltype(params)>(calloc(1, params_size));
if (!params) {
err = ZX_ERR_NO_MEMORY;
goto exit;
}
ZX_ASSERT(params_size + sizeof("escan") < BRCMF_DCMD_MEDLEN);
brcmf_escan_prep(cfg, &params->params_le, request);
params->version = BRCMF_ESCAN_REQ_VERSION;
params->action = WL_ESCAN_ACTION_START;
params->sync_id = 0x1234;
err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size, &fw_err);
if (err != ZX_OK) {
if (err == ZX_ERR_UNAVAILABLE) {
BRCMF_DBG(INFO, "system busy : escan canceled\n");
} else {
BRCMF_ERR("escan failed: %s, fw err %s\n", zx_status_get_string(err),
brcmf_fil_get_errstr(fw_err));
}
}
free(params);
exit:
return err;
}
static zx_status_t brcmf_do_escan(struct brcmf_if* ifp, wlanif_scan_req_t* req) {
struct brcmf_cfg80211_info* cfg = ifp->drvr->config;
zx_status_t err;
struct brcmf_scan_results* results;
struct escan_info* escan = &cfg->escan_info;
BRCMF_DBG(SCAN, "Enter\n");
escan->ifp = ifp;
escan->wiphy = cfg->wiphy;
escan->escan_state = WL_ESCAN_STATE_SCANNING;
brcmf_scan_config_mpc(ifp, 0);
results = (struct brcmf_scan_results*)cfg->escan_info.escan_buf;
results->version = 0;
results->count = 0;
results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE;
err = escan->run(cfg, ifp, req);
if (err != ZX_OK) {
brcmf_scan_config_mpc(ifp, 1);
}
return err;
}
zx_status_t brcmf_cfg80211_scan(struct net_device* ndev, wlanif_scan_req_t* req) {
zx_status_t err;
BRCMF_DBG(TRACE, "Enter\n");
struct wireless_dev* wdev = ndev_to_wdev(ndev);
struct brcmf_cfg80211_vif* vif = containerof(wdev, struct brcmf_cfg80211_vif, wdev);
if (!check_vif_up(vif)) {
BRCMF_DBG(TEMP, "Vif not up");
return ZX_ERR_IO;
}
struct wiphy* wiphy = ndev_to_wiphy(ndev);
struct brcmf_cfg80211_info* cfg = wiphy_to_cfg(wiphy);
if (brcmf_test_bit_in_array(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
BRCMF_ERR("Scanning already: status (%lu)\n", cfg->scan_status.load());
return ZX_ERR_UNAVAILABLE;
}
if (brcmf_test_bit_in_array(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) {
BRCMF_ERR("Scanning being aborted: status (%lu)\n", cfg->scan_status.load());
return ZX_ERR_UNAVAILABLE;
}
if (brcmf_test_bit_in_array(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
BRCMF_ERR("Scanning suppressed: status (%lu)\n", cfg->scan_status.load());
return ZX_ERR_UNAVAILABLE;
}
if (brcmf_test_bit_in_array(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state)) {
BRCMF_ERR("Scan request suppressed: connect in progress (status: %lu)\n",
vif->sme_state.load());
return ZX_ERR_UNAVAILABLE;
}
/* If scan req comes for p2p0, send it over primary I/F */
if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) {
vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
}
BRCMF_DBG(SCAN, "START ESCAN\n");
cfg->scan_request = req;
brcmf_set_bit_in_array(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
cfg->escan_info.run = brcmf_run_escan;
err = brcmf_do_escan(vif->ifp, req);
if (err != ZX_OK) {
goto scan_out;
}
/* Arm scan timeout timer */
brcmf_timer_set(&cfg->escan_timeout, ZX_MSEC(BRCMF_ESCAN_TIMER_INTERVAL_MS));
return ZX_OK;
scan_out:
BRCMF_ERR("scan error (%d)\n", err);
brcmf_clear_bit_in_array(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
cfg->scan_request = NULL;
return err;
}
static void brcmf_init_prof(struct brcmf_cfg80211_profile* prof) { memset(prof, 0, sizeof(*prof)); }
static uint16_t brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg* e) {
uint16_t reason;
switch (e->event_code) {
case BRCMF_E_DEAUTH:
case BRCMF_E_DEAUTH_IND:
reason = WLAN_DEAUTH_REASON_LEAVING_NETWORK_DEAUTH;
break;
case BRCMF_E_DISASSOC_IND:
reason = WLAN_DEAUTH_REASON_LEAVING_NETWORK_DISASSOC;
break;
case BRCMF_E_LINK:
default:
reason = WLAN_DEAUTH_REASON_UNSPECIFIED;
break;
}
return reason;
}
static zx_status_t brcmf_set_pmk(struct brcmf_if* ifp, const uint8_t* pmk_data, uint16_t pmk_len) {
struct brcmf_wsec_pmk_le pmk;
int i;
zx_status_t err;
/* convert to firmware key format */
pmk.key_len = pmk_len << 1;
pmk.flags = BRCMF_WSEC_PASSPHRASE;
for (i = 0; i < pmk_len; i++) {
// TODO(cphoenix): Make sure handling of pmk keys is consistent with their being
// binary values, not ASCII chars.
snprintf((char*)&pmk.key[2 * i], 3, "%02x", pmk_data[i]);
}
/* store psk in firmware */
err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_WSEC_PMK, &pmk, sizeof(pmk), nullptr);
if (err != ZX_OK) {
BRCMF_ERR("failed to change PSK in firmware (len=%u)\n", pmk_len);
}
return err;
}
static void cfg80211_disconnected(struct brcmf_cfg80211_vif* vif, uint16_t reason) {
struct net_device* ndev = vif->wdev.netdev;
wlanif_deauth_indication_t ind;
memcpy(ind.peer_sta_address, vif->profile.bssid, ETH_ALEN);
ind.reason_code = reason;
BRCMF_DBG(WLANIF,
"Sending deauth indication to SME. address: " MAC_FMT_STR
", "
"reason: %" PRIu16 "\n",
MAC_FMT_ARGS(ind.peer_sta_address), ind.reason_code);
ndev->if_callbacks->deauth_ind(ndev->if_callback_cookie, &ind);
}
static void brcmf_link_down(struct brcmf_cfg80211_vif* vif, uint16_t reason) {
struct brcmf_cfg80211_info* cfg = wiphy_to_cfg(vif->wdev.wiphy);
zx_status_t err = ZX_OK;
BRCMF_DBG(TRACE, "Enter\n");
if (brcmf_test_and_clear_bit_in_array(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) {
BRCMF_DBG(INFO, "Call WLC_DISASSOC to stop excess roaming\n ");
int32_t fwerr = 0;
err = brcmf_fil_cmd_data_set(vif->ifp, BRCMF_C_DISASSOC, NULL, 0, &fwerr);
if (err != ZX_OK) {
BRCMF_ERR("WLC_DISASSOC failed: %s, fw err %s\n", zx_status_get_string(err),
brcmf_fil_get_errstr(fwerr));
}
if (vif->wdev.iftype == WLAN_INFO_MAC_ROLE_CLIENT) {
cfg80211_disconnected(vif, reason);
}
}
brcmf_clear_bit_in_array(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
brcmf_clear_bit_in_array(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
if (vif->profile.use_fwsup != BRCMF_PROFILE_FWSUP_NONE) {
brcmf_set_pmk(vif->ifp, NULL, 0);
vif->profile.use_fwsup = BRCMF_PROFILE_FWSUP_NONE;
}
BRCMF_DBG(TRACE, "Exit\n");
}
static zx_status_t brcmf_set_wpa_version(struct net_device* ndev, bool is_protected_bss) {
struct brcmf_cfg80211_profile* profile = ndev_to_prof(ndev);
struct brcmf_cfg80211_security* sec;
int32_t val = 0;
zx_status_t err = ZX_OK;
if (is_protected_bss) {
val = WPA2_AUTH_PSK; // | WPA2_AUTH_UNSPECIFIED;
} else {
val = WPA_AUTH_DISABLED;
}
BRCMF_DBG(CONN, "setting wpa_auth to 0x%0x\n", val);
err = brcmf_fil_bsscfg_int_set(ndev_to_if(ndev), "wpa_auth", val);
if (err != ZX_OK) {
BRCMF_ERR("set wpa_auth failed (%d)\n", err);
return err;
}
sec = &profile->sec;
// TODO(cphoenix): wpa_versions seems to be used only for WEP in brcmf_set_sharedkey(). Delete.
sec->wpa_versions = 0;
return err;
}
static zx_status_t brcmf_set_auth_type_open(struct net_device* ndev) {
struct brcmf_cfg80211_profile* profile = ndev_to_prof(ndev);
struct brcmf_cfg80211_security* sec;
int32_t val = 0;
zx_status_t err = ZX_OK;
err = brcmf_fil_bsscfg_int_set(ndev_to_if(ndev), "auth", val);
if (err != ZX_OK) {
BRCMF_ERR("set auth failed (%d)\n", err);
return err;
}
sec = &profile->sec;
sec->auth_type = 0;
return err;
}
static zx_status_t brcmf_set_wsec_mode(struct net_device* ndev, bool is_protected_bss) {
struct brcmf_cfg80211_profile* profile = ndev_to_prof(ndev);
struct brcmf_cfg80211_security* sec;
int32_t wsec;
zx_status_t err = ZX_OK;
if (is_protected_bss) {
wsec = AES_ENABLED;
} else {
wsec = 0;
}
err = brcmf_fil_bsscfg_int_set(ndev_to_if(ndev), "wsec", wsec);
if (err != ZX_OK) {
BRCMF_ERR("error (%d)\n", err);
return err;
}
sec = &profile->sec;
sec->cipher_pairwise = 0;
sec->cipher_group = 0;
return err;
}
// Retrieve information about the station with the specified MAC address. Note that
// association ID is only available when operating in AP mode (for our clients).
static zx_status_t brcmf_cfg80211_get_station(struct net_device* ndev, const uint8_t* mac,
struct brcmf_sta_info_le* sta_info_le) {
struct brcmf_if* ifp = ndev_to_if(ndev);
zx_status_t err = ZX_OK;
BRCMF_DBG(TRACE, "Enter, MAC %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3],
mac[4], mac[5]);
if (!check_vif_up(ifp->vif)) {
return ZX_ERR_IO;
}
memset(sta_info_le, 0, sizeof(*sta_info_le));
memcpy(sta_info_le, mac, ETH_ALEN);
// First, see if we have a TDLS peer
err = brcmf_fil_iovar_data_get(ifp, "tdls_sta_info", sta_info_le, sizeof(*sta_info_le), nullptr);
if (err != ZX_OK) {
int32_t fw_err = 0;
err = brcmf_fil_iovar_data_get(ifp, "sta_info", sta_info_le, sizeof(*sta_info_le), &fw_err);
if (err != ZX_OK) {
BRCMF_ERR("GET STA INFO failed: %s, fw err %s\n", zx_status_get_string(err),
brcmf_fil_get_errstr(fw_err));
}
}
BRCMF_DBG(TRACE, "Exit\n");
return err;
}
void brcmf_return_assoc_result(struct net_device* ndev, uint8_t result_code) {
wlanif_assoc_confirm_t conf;
conf.result_code = result_code;
BRCMF_DBG(TEMP, " * Hard-coding association_id to 42; this will likely break something!");
conf.association_id = 42; // TODO: Use brcmf_cfg80211_get_station() to get aid
BRCMF_DBG(WLANIF, "Sending assoc result to SME. result: %" PRIu8 ", aid: %" PRIu16 "\n",
conf.result_code, conf.association_id);
ndev->if_callbacks->assoc_conf(ndev->if_callback_cookie, &conf);
}
zx_status_t brcmf_cfg80211_connect(struct net_device* ndev, wlanif_assoc_req_t* req) {
struct brcmf_if* ifp = ndev_to_if(ndev);
struct brcmf_cfg80211_info* cfg = ifp->drvr->config;
struct brcmf_ext_join_params_le join_params;
uint16_t chanspec;
size_t join_params_size = 0;
const void* ie;
uint32_t ie_len;
zx_status_t err = ZX_OK;
uint32_t ssid_len = 0;
BRCMF_DBG(TRACE, "Enter\n");
if (!check_vif_up(ifp->vif)) {
return ZX_ERR_IO;
}
// Pass RSNE to firmware
ie_len = req->rsne_len;
ie = (req->rsne_len > 0) ? req->rsne : NULL;
brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len, nullptr);
// TODO(WLAN-733): We should be getting the IEs from SME. Passing a null entry seems
// to work for now, presumably because the firmware uses its defaults.
err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG, NULL, 0);
if (err != ZX_OK) {
BRCMF_ERR("Set Assoc REQ IE Failed\n");
} else {
BRCMF_DBG(TRACE, "Applied Vndr IEs for Assoc request\n");
}
brcmf_set_bit_in_array(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
chanspec = channel_to_chanspec(&cfg->d11inf, &ifp->bss.chan);
cfg->channel = chanspec;
// TODO(WLAN-733): Currently fails if a network only supports TKIP for its pairwise cipher
bool using_wpa = req->rsne_len != 0;
err = brcmf_set_wpa_version(ndev, using_wpa); // wpa_auth
if (err != ZX_OK) {
BRCMF_ERR("wl_set_wpa_version failed (%d)\n", err);
goto done;
}
// Open because we are using WPA2-PSK. With SAE support, this will need to change.
err = brcmf_set_auth_type_open(ndev);
if (err != ZX_OK) {
BRCMF_ERR("wl_set_auth_type failed (%d)\n", err);
goto done;
}
err = brcmf_set_wsec_mode(ndev, using_wpa);
if (err != ZX_OK) {
BRCMF_ERR("wl_set_set_cipher failed (%d)\n", err);
goto done;
}
ssid_len = min_t(uint32_t, ifp->bss.ssid.len, WLAN_MAX_SSID_LEN);
join_params_size = sizeof(join_params);
memset(&join_params, 0, join_params_size);
memcpy(&join_params.ssid_le.SSID, ifp->bss.ssid.data, ssid_len);
join_params.ssid_le.SSID_len = ssid_len;
memcpy(join_params.assoc_le.bssid, ifp->bss.bssid, ETH_ALEN);
join_params.assoc_le.chanspec_num = 1;
join_params.assoc_le.chanspec_list[0] = chanspec;
join_params.scan_le.scan_type = 0; // use default
join_params.scan_le.home_time = -1; // use default
/* Increase dwell time to receive probe response or detect beacon from target AP at a noisy
air only during connect command. */
join_params.scan_le.active_time = BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS;
join_params.scan_le.passive_time = BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS;
/* To sync with presence period of VSDB GO send probe request more frequently. Probe request
will be stopped when it gets probe response from target AP/GO. */
join_params.scan_le.nprobes =
BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS / BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS;
BRCMF_DBG(CONN, "Sending join request\n");
err = brcmf_fil_bsscfg_data_set(ifp, "join", &join_params, join_params_size);
if (err != ZX_OK) {
BRCMF_ERR("join failed (%d)\n", err);
}
done:
if (err != ZX_OK) {
brcmf_clear_bit_in_array(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
BRCMF_DBG(CONN, "Failed during join: %s", zx_status_get_string(err));
brcmf_return_assoc_result(ndev, WLAN_ASSOC_RESULT_REFUSED_REASON_UNSPECIFIED);
}
BRCMF_DBG(TRACE, "Exit\n");
return err;
}
static void brcmf_notify_deauth(struct net_device* ndev, uint8_t peer_sta_address[ETH_ALEN]) {
wlanif_deauth_confirm_t resp;
memcpy(resp.peer_sta_address, peer_sta_address, ETH_ALEN);
BRCMF_DBG(WLANIF, "Sending deauth confirm to SME. address: " MAC_FMT_STR "\n",
MAC_FMT_ARGS(peer_sta_address));
ndev->if_callbacks->deauth_conf(ndev->if_callback_cookie, &resp);
}
static void brcmf_notify_disassoc(struct net_device* ndev, zx_status_t status) {
wlanif_disassoc_confirm_t resp;
resp.status = status;
BRCMF_DBG(WLANIF, "Sending disassoc confirm to SME. status: %" PRIu32 "\n", status);
ndev->if_callbacks->disassoc_conf(ndev->if_callback_cookie, &resp);
}
static void brcmf_disconnect_done(struct brcmf_cfg80211_info* cfg) {
struct net_device* ndev = cfg_to_ndev(cfg);
struct brcmf_if* ifp = ndev_to_if(ndev);
struct brcmf_cfg80211_profile* profile = &ifp->vif->profile;
BRCMF_DBG(TRACE, "Enter\n");
if (brcmf_test_and_clear_bit_in_array(BRCMF_VIF_STATUS_DISCONNECTING, &ifp->vif->sme_state)) {
brcmf_timer_stop(&cfg->disconnect_timeout);
if (cfg->disconnect_mode == BRCMF_DISCONNECT_DEAUTH) {
brcmf_notify_deauth(ndev, profile->bssid);
} else {
brcmf_notify_disassoc(ndev, ZX_OK);
}
}
BRCMF_DBG(TRACE, "Exit\n");
}
static void brcmf_disconnect_timeout_worker(struct work_struct* work) {
struct brcmf_cfg80211_info* cfg =
containerof(work, struct brcmf_cfg80211_info, disconnect_timeout_work);
brcmf_disconnect_done(cfg);
}
static void brcmf_disconnect_timeout(void* data) {
struct brcmf_cfg80211_info* cfg = static_cast<decltype(cfg)>(data);
cfg->pub->irq_callback_lock.lock();
BRCMF_DBG(TRACE, "Enter\n");
workqueue_schedule_default(&cfg->disconnect_timeout_work);
cfg->pub->irq_callback_lock.unlock();
}
static zx_status_t brcmf_cfg80211_disconnect(struct net_device* ndev,
uint8_t peer_sta_address[ETH_ALEN],
uint16_t reason_code, bool deauthenticate) {
struct brcmf_if* ifp = ndev_to_if(ndev);
struct brcmf_cfg80211_profile* profile = &ifp->vif->profile;
struct brcmf_cfg80211_info* cfg = ifp->drvr->config;
struct brcmf_scb_val_le scbval;
zx_status_t status = ZX_OK;
int32_t fw_err = 0;
BRCMF_DBG(TRACE, "Enter. Reason code = %d\n", reason_code);
if (!check_vif_up(ifp->vif)) {
status = ZX_ERR_IO;
goto done;
}
if (!brcmf_test_bit_in_array(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state) &&
!brcmf_test_bit_in_array(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) {
status = ZX_ERR_BAD_STATE;
goto done;
}
if (memcmp(peer_sta_address, profile->bssid, ETH_ALEN)) {
status = ZX_ERR_INVALID_ARGS;
goto done;
}
brcmf_clear_bit_in_array(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
brcmf_clear_bit_in_array(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
BRCMF_DBG(CONN, "Disconnecting\n");
memcpy(&scbval.ea, peer_sta_address, ETH_ALEN);
scbval.val = reason_code;
cfg->disconnect_mode = deauthenticate ? BRCMF_DISCONNECT_DEAUTH : BRCMF_DISCONNECT_DISASSOC;
brcmf_set_bit_in_array(BRCMF_VIF_STATUS_DISCONNECTING, &ifp->vif->sme_state);
status = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC, &scbval, sizeof(scbval), &fw_err);
if (status != ZX_OK) {
BRCMF_ERR("Failed to disassociate: %s, fw err %s\n", zx_status_get_string(status),
brcmf_fil_get_errstr(fw_err));
goto done;
}
brcmf_timer_init(&cfg->disconnect_timeout, ifp->drvr->dispatcher, brcmf_disconnect_timeout, cfg);
brcmf_timer_set(&cfg->disconnect_timeout, BRCMF_DISCONNECT_TIMEOUT);
done:
BRCMF_DBG(TRACE, "Exit\n");
return status;
}
static zx_status_t brcmf_cfg80211_del_key(struct wiphy* wiphy, struct net_device* ndev,
uint8_t key_idx, bool pairwise, const uint8_t* mac_addr) {
struct brcmf_if* ifp = ndev_to_if(ndev);
struct brcmf_wsec_key* key;
zx_status_t err;
BRCMF_DBG(TRACE, "Enter\n");
BRCMF_DBG(CONN, "key index (%d)\n", key_idx);
if (!check_vif_up(ifp->vif)) {
return ZX_ERR_IO;
}
if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
/* we ignore this key index in this case */
return ZX_ERR_INVALID_ARGS;
}
key = &ifp->vif->profile.key[key_idx];
if (key->algo == CRYPTO_ALGO_OFF) {
BRCMF_DBG(CONN, "Ignore clearing of (never configured) key\n");
return ZX_ERR_BAD_STATE;
}
memset(key, 0, sizeof(*key));
key->index = (uint32_t)key_idx;
key->flags = BRCMF_PRIMARY_KEY;
/* Clear the key/index */
err = send_key_to_dongle(ifp, key);
BRCMF_DBG(TRACE, "Exit\n");
return err;
}
static zx_status_t brcmf_cfg80211_add_key(struct wiphy* wiphy, struct net_device* ndev,
set_key_descriptor_t* req) {
struct brcmf_if* ifp = ndev_to_if(ndev);
struct brcmf_wsec_key* key;
int32_t val;
int32_t wsec;
zx_status_t err;
bool ext_key;
uint8_t key_idx = req->key_id;
bool pairwise = (req->key_type == WLAN_KEY_TYPE_PAIRWISE);
const uint8_t* mac_addr = req->address;
BRCMF_DBG(TRACE, "Enter\n");
BRCMF_DBG(CONN, "key index (%d)\n", key_idx);
if (!check_vif_up(ifp->vif)) {
return ZX_ERR_IO;
}
if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
/* we ignore this key index in this case */
BRCMF_ERR("invalid key index (%d)\n", key_idx);
return ZX_ERR_INVALID_ARGS;
}
if (req->length == 0) {
return brcmf_cfg80211_del_key(wiphy, ndev, key_idx, pairwise, mac_addr);
}
if (req->length > sizeof(key->data)) {
BRCMF_ERR("Too long key length (%u)\n", req->length);
return ZX_ERR_INVALID_ARGS;
}
ext_key = false;
if (mac_addr && (req->cipher_suite_type != WPA_CIPHER_WEP_40) &&
(req->cipher_suite_type != WPA_CIPHER_WEP_104)) {
BRCMF_DBG(TRACE, "Ext key, mac %02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1],
mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
ext_key = true;
}
key = &ifp->vif->profile.key[key_idx];
memset(key, 0, sizeof(*key));
if ((ext_key) && (!address_is_multicast(mac_addr))) {
memcpy((char*)&key->ea, (void*)mac_addr, ETH_ALEN);
}
key->len = req->length;
key->index = key_idx;
memcpy(key->data, req->key, key->len);
if (!ext_key) {
key->flags = BRCMF_PRIMARY_KEY;
}
switch (req->cipher_suite_type) {
case WPA_CIPHER_WEP_40:
key->algo = CRYPTO_ALGO_WEP1;
val = WEP_ENABLED;
BRCMF_DBG(CONN, "WPA_CIPHER_WEP_40\n");
break;
case WPA_CIPHER_WEP_104:
key->algo = CRYPTO_ALGO_WEP128;
val = WEP_ENABLED;
BRCMF_DBG(CONN, "WPA_CIPHER_WEP_104\n");
break;
case WPA_CIPHER_TKIP:
/* Note: Linux swaps the Tx and Rx MICs in client mode, but this doesn't work for us (see
NET-1679). It's unclear why this would be necessary. */
key->algo = CRYPTO_ALGO_TKIP;
val = TKIP_ENABLED;
BRCMF_DBG(CONN, "WPA_CIPHER_TKIP\n");
break;
case WPA_CIPHER_CMAC_128:
key->algo = CRYPTO_ALGO_AES_CCM;
val = AES_ENABLED;
BRCMF_DBG(CONN, "WPA_CIPHER_CMAC_128\n");
break;
case WPA_CIPHER_CCMP_128:
key->algo = CRYPTO_ALGO_AES_CCM;
val = AES_ENABLED;
BRCMF_DBG(CONN, "WPA_CIPHER_CCMP_128\n");
break;
default:
BRCMF_ERR("Unsupported cipher (0x%x)\n", req->cipher_suite_type);
err = ZX_ERR_INVALID_ARGS;
goto done;
}
err = send_key_to_dongle(ifp, key);
if (ext_key || err != ZX_OK) {
goto done;
}
err = brcmf_fil_bsscfg_int_get(ifp, "wsec", (uint32_t*)&wsec); // TODO(cphoenix): This cast?!?
if (err != ZX_OK) {
BRCMF_ERR("get wsec error (%d)\n", err);
goto done;
}
wsec |= val;
err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
if (err != ZX_OK) {
BRCMF_ERR("set wsec error (%d)\n", err);
goto done;
}
done:
BRCMF_DBG(TRACE, "Exit\n");
return err;
}
static void brcmf_parse_ies(uint8_t* ie, size_t ie_len, wlanif_bss_description_t* bss) {
size_t offset = 0;
while (offset < ie_len) {
uint8_t type = ie[offset];
uint8_t length = ie[offset + 1];
switch (type) {
case WLAN_IE_TYPE_SSID: {
uint8_t ssid_len = std::min<uint8_t>(length, sizeof(bss->ssid.data));
memcpy(bss->ssid.data, ie + offset + 2, ssid_len);
bss->ssid.len = ssid_len;
break;
}
case WLAN_IE_TYPE_SUPP_RATES: {
uint8_t num_supp_rates = std::min<uint8_t>(length, WLAN_MAC_MAX_SUPP_RATES);
memcpy(bss->rates, ie + offset + 2, num_supp_rates);
bss->num_rates = num_supp_rates;
break;
}
case WLAN_IE_TYPE_EXT_SUPP_RATES: {
uint8_t num_ext_supp_rates = std::min<uint8_t>(length, WLAN_MAC_MAX_EXT_RATES);
memcpy(bss->rates + bss->num_rates, ie + offset + 2, num_ext_supp_rates);
bss->num_rates += num_ext_supp_rates;
break;
}
default:
break;
}
offset += length + 2;
}
}
static void brcmf_ies_extract_rsne(uint8_t* ie_chain, size_t ie_chain_len, uint8_t* rsne_data,
size_t* rsne_len) {
size_t offset = 0;
*rsne_len = 0;
while (offset < ie_chain_len) {
uint8_t type = ie_chain[offset];
uint8_t ie_total_length = ie_chain[offset + 1] + 2;
if (type == WLAN_IE_TYPE_RSNE) {
memcpy(rsne_data, &ie_chain[offset], ie_total_length);
*rsne_len = ie_total_length;
break;
}
offset += ie_total_length;
}
}
static void brcmf_iedump(uint8_t* ies, size_t total_len) {
size_t offset = 0;
while (offset + TLV_HDR_LEN <= total_len) {
uint8_t elem_type = ies[offset];
uint8_t elem_len = ies[offset + TLV_LEN_OFF];
offset += TLV_HDR_LEN;
if (offset + elem_len > total_len) {
break;
}
if (elem_type == 0) {
BRCMF_DBG_STRING_DUMP(true, ies + offset, elem_len, "IE 0 (name), len %d:", elem_len);
} else {
BRCMF_DBG_HEX_DUMP(true, ies + offset, elem_len, "IE %d, len %d:\n", elem_type, elem_len);
}
offset += elem_len;
}
if (offset != total_len) {
BRCMF_DBG(ALL, " * * Offset %ld didn't match length %ld", offset, total_len);
}
}
#define EAPOL_ETHERNET_TYPE_UINT16 0x8e88
void brcmf_cfg80211_rx(struct brcmf_if* ifp, struct brcmf_netbuf* packet) {
struct net_device* ndev = ifp->ndev;
THROTTLE(10, BRCMF_DBG_HEX_DUMP(BRCMF_IS_ON(BYTES) && BRCMF_IS_ON(DATA), packet->data,
std::min(packet->len, 64u),
"Data received (%d bytes, max 64 shown):\n", packet->len););
// IEEE Std. 802.3-2015, 3.1.1
uint16_t eth_type = ((uint16_t*)(packet->data))[6];
if (eth_type == EAPOL_ETHERNET_TYPE_UINT16) {
wlanif_eapol_indication_t eapol_ind;
// IEEE Std. 802.1X-2010, 11.3, Figure 11-1
memcpy(&eapol_ind.dst_addr, packet->data, ETH_ALEN);
memcpy(&eapol_ind.src_addr, packet->data + 6, ETH_ALEN);
eapol_ind.data_len = packet->len - 14;
eapol_ind.data = packet->data + 14;
BRCMF_DBG(WLANIF, "Sending EAPOL frame to SME. data_len: %zu\n", eapol_ind.data_len);
ndev->if_callbacks->eapol_ind(ndev->if_callback_cookie, &eapol_ind);
} else {
ndev->if_callbacks->data_recv(ndev->if_callback_cookie, packet->data, packet->len, 0);
}
brcmu_pkt_buf_free_netbuf(packet);
}
static void brcmf_return_scan_result(struct wiphy* wiphy, uint16_t channel, const uint8_t* bssid,
uint16_t capability, uint16_t interval, uint8_t* ie,
size_t ie_len, int16_t rssi_dbm) {
struct net_device* ndev = wiphy_to_ndev(wiphy);
wlanif_scan_result_t result = {};
if (!ndev->scan_busy) {
return;
}
result.txn_id = ndev->scan_txn_id;
memcpy(result.bss.bssid, bssid, ETH_ALEN);
brcmf_parse_ies(ie, ie_len, &result.bss);
brcmf_ies_extract_rsne(ie, ie_len, result.bss.rsne, &result.bss.rsne_len);
result.bss.bss_type = WLAN_BSS_TYPE_ANY_BSS;
result.bss.beacon_period = 0;
result.bss.dtim_period = 0;
result.bss.timestamp = 0;
result.bss.local_time = 0;
result.bss.cap = capability;
result.bss.chan.primary = (uint8_t)channel;
result.bss.chan.cbw = CBW20; // TODO(cphoenix): Don't hard-code this.
result.bss.rssi_dbm = std::min<int16_t>(0, std::max<int16_t>(-255, rssi_dbm));
result.bss.rcpi_dbmh = 0;
result.bss.rsni_dbh = 0;
BRCMF_DBG(SCAN, "Returning scan result %.*s, channel %d, dbm %d, id %lu", result.bss.ssid.len,
result.bss.ssid.data, channel, result.bss.rssi_dbm, result.txn_id);
ndev->if_callbacks->on_scan_result(ndev->if_callback_cookie, &result);
}
static zx_status_t brcmf_inform_single_bss(struct brcmf_cfg80211_info* cfg,
struct brcmf_bss_info_le* bi) {
struct wiphy* wiphy = cfg_to_wiphy(cfg);
struct brcmu_chan ch;
uint16_t channel;
uint16_t notify_capability;
uint16_t notify_interval;
uint8_t* notify_ie;
size_t notify_ielen;
int16_t notify_rssi_dbm;
if (bi->length > WL_BSS_INFO_MAX) {
BRCMF_ERR("Bss info is larger than buffer. Discarding\n");
BRCMF_DBG(TEMP, "Early return, due to length.");
return ZX_OK;
}
if (!bi->ctl_ch) {
ch.chspec = bi->chanspec;
cfg->d11inf.decchspec(&ch);
bi->ctl_ch = ch.control_ch_num;
}
channel = bi->ctl_ch;
notify_capability = bi->capability;
notify_interval = bi->beacon_period;
notify_ie = (uint8_t*)bi + bi->ie_offset;
notify_ielen = bi->ie_length;
notify_rssi_dbm = (int16_t)bi->RSSI;
BRCMF_DBG(CONN,
"Scan result received BSS: %02x:%02x:%02x:%02x:%02x:%02x"
" Channel: %3d Capability: %#6x Beacon interval: %5d Signal: %4d\n",
bi->BSSID[0], bi->BSSID[1], bi->BSSID[2], bi->BSSID[3], bi->BSSID[4], bi->BSSID[5],
channel, notify_capability, notify_interval, notify_rssi_dbm);
if (BRCMF_IS_ON(CONN) && BRCMF_IS_ON(BYTES)) {
brcmf_iedump(notify_ie, notify_ielen);
}
brcmf_return_scan_result(wiphy, (uint8_t)channel, (const uint8_t*)bi->BSSID, notify_capability,
notify_interval, notify_ie, notify_ielen, notify_rssi_dbm);
return ZX_OK;
}
static struct brcmf_bss_info_le* next_bss_le(struct brcmf_scan_results* list,
struct brcmf_bss_info_le* bss) {
if (bss == NULL) {
return list->bss_info_le;
}
return (struct brcmf_bss_info_le*)((unsigned long)bss + bss->length);
}
static zx_status_t brcmf_inform_bss(struct brcmf_cfg80211_info* cfg) {
struct brcmf_scan_results* bss_list;
struct brcmf_bss_info_le* bi = NULL; /* must be initialized */
zx_status_t err = ZX_OK;
int i;
bss_list = (struct brcmf_scan_results*)cfg->escan_info.escan_buf;
if (bss_list->count != 0 && bss_list->version != BRCMF_BSS_INFO_VERSION) {
BRCMF_ERR("Version %d != WL_BSS_INFO_VERSION\n", bss_list->version);
return ZX_ERR_NOT_SUPPORTED;
}
BRCMF_DBG(SCAN, "scanned AP count (%d), wiphy %p", bss_list->count, cfg_to_wiphy(cfg));
for (i = 0; i < (int32_t)bss_list->count; i++) {
bi = next_bss_le(bss_list, bi);
err = brcmf_inform_single_bss(cfg, bi);
if (err != ZX_OK) {
break;
}
}
return err;
}
void brcmf_abort_scanning(struct brcmf_cfg80211_info* cfg) {
struct escan_info* escan = &cfg->escan_info;
brcmf_set_bit_in_array(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
if (cfg->int_escan_map || cfg->scan_request) {
escan->escan_state = WL_ESCAN_STATE_IDLE;
brcmf_notify_escan_complete(cfg, escan->ifp, true, true);
}
brcmf_clear_bit_in_array(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
brcmf_clear_bit_in_array(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
}
static void brcmf_cfg80211_escan_timeout_worker(struct work_struct* work) {
struct brcmf_cfg80211_info* cfg =
containerof(work, struct brcmf_cfg80211_info, escan_timeout_work);
brcmf_inform_bss(cfg);
brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true);
}
static void brcmf_escan_timeout(void* data) {
struct brcmf_cfg80211_info* cfg = static_cast<decltype(cfg)>(data);
cfg->pub->irq_callback_lock.lock();
if (cfg->int_escan_map || cfg->scan_request) {
BRCMF_ERR("timer expired\n");
workqueue_schedule_default(&cfg->escan_timeout_work);
}
cfg->pub->irq_callback_lock.unlock();
}
static bool brcmf_compare_update_same_bss(struct brcmf_cfg80211_info* cfg,
struct brcmf_bss_info_le* bss,
struct brcmf_bss_info_le* bss_info_le) {
struct brcmu_chan ch_bss, ch_bss_info_le;
ch_bss.chspec = bss->chanspec;
cfg->d11inf.decchspec(&ch_bss);
ch_bss_info_le.chspec = bss_info_le->chanspec;
cfg->d11inf.decchspec(&ch_bss_info_le);
if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) && ch_bss.band == ch_bss_info_le.band &&
bss_info_le->SSID_len == bss->SSID_len &&
!memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) {
if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) ==
(bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) {
int16_t bss_rssi = bss->RSSI;
int16_t bss_info_rssi = bss_info_le->RSSI;
/* preserve max RSSI if the measurements are
* both on-channel or both off-channel
*/
if (bss_info_rssi > bss_rssi) {
bss->RSSI = bss_info_le->RSSI;
}
} else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) &&
(bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) {
/* preserve the on-channel rssi measurement
* if the new measurement is off channel
*/
bss->RSSI = bss_info_le->RSSI;
bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL;
}
return true;
}
return false;
}
static zx_status_t brcmf_cfg80211_escan_handler(struct brcmf_if* ifp,
const struct brcmf_event_msg* e, void* data) {
struct brcmf_cfg80211_info* cfg = ifp->drvr->config;
int32_t status;
struct brcmf_escan_result_le* escan_result_le;
uint32_t escan_buflen;
struct brcmf_bss_info_le* bss_info_le;
struct brcmf_bss_info_le* bss = NULL;
uint32_t bi_length = 0;
struct brcmf_scan_results* list = NULL;
uint32_t i;
bool aborted;
status = e->status;
if (status == BRCMF_E_STATUS_ABORT) {
goto exit;
}
if (!brcmf_test_bit_in_array(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
BRCMF_ERR("scan not ready, bsscfgidx=%d\n", ifp->bsscfgidx);
return ZX_ERR_UNAVAILABLE;
}
if (status == BRCMF_E_STATUS_PARTIAL) {
BRCMF_DBG(SCAN, "ESCAN Partial result\n");
if (e->datalen < sizeof(*escan_result_le)) {
BRCMF_ERR("invalid event data length\n");
goto exit;
}
escan_result_le = (struct brcmf_escan_result_le*)data;
if (!escan_result_le) {
BRCMF_ERR("Invalid escan result (NULL pointer)\n");
goto exit;
}
escan_buflen = escan_result_le->buflen;
if (escan_buflen > BRCMF_ESCAN_BUF_SIZE || escan_buflen > e->datalen ||
escan_buflen < sizeof(*escan_result_le)) {
BRCMF_ERR("Invalid escan buffer length: %d\n", escan_buflen);
goto exit;
}
if (escan_result_le->bss_count != 1) {
BRCMF_ERR("Invalid bss_count %d: ignoring\n", escan_result_le->bss_count);
goto exit;
}
bss_info_le = &escan_result_le->bss_info_le;
if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le)) {
goto exit;
}
if (!cfg->int_escan_map && !cfg->scan_request) {
BRCMF_DBG(SCAN, "result without cfg80211 request\n");
goto exit;
}
bi_length = bss_info_le->length;
if (bi_length != escan_buflen - WL_ESCAN_RESULTS_FIXED_SIZE) {
BRCMF_ERR("Ignoring invalid bss_info length: %d\n", bi_length);
goto exit;
}
list = (struct brcmf_scan_results*)cfg->escan_info.escan_buf;
if (bi_length > BRCMF_ESCAN_BUF_SIZE - list->buflen) {
BRCMF_ERR("Buffer is too small: ignoring\n");
goto exit;
}
for (i = 0; i < list->count; i++) {
bss =
bss ? (struct brcmf_bss_info_le*)((unsigned char*)bss + bss->length) : list->bss_info_le;
if (brcmf_compare_update_same_bss(cfg, bss, bss_info_le)) {
goto exit;
}
}
memcpy(&cfg->escan_info.escan_buf[list->buflen], bss_info_le, bi_length);
list->version = bss_info_le->version;
list->buflen += bi_length;
list->count++;
} else {
cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
if (brcmf_p2p_scan_finding_common_channel(cfg, NULL)) {
goto exit;
}
if (cfg->int_escan_map || cfg->scan_request) {
brcmf_inform_bss(cfg);
aborted = status != BRCMF_E_STATUS_SUCCESS;
brcmf_notify_escan_complete(cfg, ifp, aborted, false);
} else {
BRCMF_DBG(SCAN, "Ignored scan complete result 0x%x\n", status);
}
}
exit:
return ZX_OK;
}
static void brcmf_init_escan(struct brcmf_cfg80211_info* cfg) {
brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT, brcmf_cfg80211_escan_handler);
cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
/* Init scan_timeout timer */
cfg->escan_timeout.data = cfg;
brcmf_timer_init(&cfg->escan_timeout, cfg->pub->dispatcher, brcmf_escan_timeout, cfg);
workqueue_init_work(&cfg->escan_timeout_work, brcmf_cfg80211_escan_timeout_worker);
}
static wlanif_scan_req_t* brcmf_alloc_internal_escan_request(void) {
return static_cast<wlanif_scan_req_t*>(calloc(1, sizeof(wlanif_scan_req_t)));
}
static zx_status_t brcmf_internal_escan_add_info(wlanif_scan_req_t* req, uint8_t* ssid,
uint8_t ssid_len, uint8_t channel) {
size_t i;
for (i = 0; i < req->num_channels; i++) {
if (req->channel_list[i] == channel) {
break;
}
}
if (i == req->num_channels) {
if (req->num_channels < WLAN_INFO_CHANNEL_LIST_MAX_CHANNELS) {
req->channel_list[req->num_channels++] = channel;
} else {
BRCMF_ERR("escan channel list full, suppressing channel %d\n", channel);
}
}
for (i = 0; i < req->num_ssids; i++) {
if (req->ssid_list[i].len == ssid_len && !memcmp(req->ssid_list[i].data, ssid, ssid_len)) {
break;
}
}
if (i == req->num_ssids) {
if (req->num_ssids < WLAN_SCAN_MAX_SSIDS) {
memcpy(req->ssid_list[req->num_ssids].data, ssid, ssid_len);
req->ssid_list[req->num_ssids++].len = ssid_len;
} else {
BRCMF_ERR("escan ssid list full, suppressing '%.*s'\n", ssid_len, ssid);
}
}
return ZX_OK;
}
static zx_status_t brcmf_start_internal_escan(struct brcmf_if* ifp, uint32_t fwmap,
wlanif_scan_req_t* req) {
struct brcmf_cfg80211_info* cfg = ifp->drvr->config;
zx_status_t err;
if (brcmf_test_bit_in_array(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
if (cfg->int_escan_map) {
BRCMF_DBG(SCAN, "aborting internal scan: map=%u\n", cfg->int_escan_map);
}
/* Abort any on-going scan */
brcmf_abort_scanning(cfg);
}
BRCMF_DBG(SCAN, "start internal scan: map=%u\n", fwmap);
brcmf_set_bit_in_array(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
cfg->escan_info.run = brcmf_run_escan;
err = brcmf_do_escan(ifp, req);
if (err != ZX_OK) {
brcmf_clear_bit_in_array(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
return err;
}
cfg->int_escan_map = fwmap;
return ZX_OK;
}
static struct brcmf_pno_net_info_le* brcmf_get_netinfo_array(
struct brcmf_pno_scanresults_le* pfn_v1) {
struct brcmf_pno_scanresults_v2_le* pfn_v2;
struct brcmf_pno_net_info_le* netinfo;
switch (pfn_v1->version) {
default:
WARN_ON(1);
/* fall-thru */
case 1:
netinfo = (struct brcmf_pno_net_info_le*)(pfn_v1 + 1);
break;
case 2:
pfn_v2 = (struct brcmf_pno_scanresults_v2_le*)pfn_v1;
netinfo = (struct brcmf_pno_net_info_le*)(pfn_v2 + 1);
break;
}
return netinfo;
}
/* PFN result doesn't have all the info which are required by the supplicant
* (For e.g IEs) Do a target Escan so that sched scan results are reported
* via wl_inform_single_bss in the required format.
*/
static zx_status_t brcmf_notify_sched_scan_results(struct brcmf_if* ifp,
const struct brcmf_event_msg* e, void* data) {
struct brcmf_cfg80211_info* cfg = ifp->drvr->config;
struct net_device* ndev = cfg_to_ndev(cfg);
wlanif_scan_req_t* req = NULL;
struct brcmf_pno_net_info_le* netinfo;
struct brcmf_pno_net_info_le* netinfo_start;
int i;
zx_status_t err = ZX_OK;
struct brcmf_pno_scanresults_le* pfn_result;
uint32_t bucket_map;
uint32_t result_count;
uint32_t status;
uint32_t datalen;
BRCMF_DBG(SCAN, "Enter\n");
if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) {
BRCMF_DBG(SCAN, "Event data to small. Ignore\n");
return ZX_OK;
}
if (e->event_code == BRCMF_E_PFN_NET_LOST) {
BRCMF_DBG(SCAN, "PFN NET LOST event. Do Nothing\n");
return ZX_OK;
}
pfn_result = (struct brcmf_pno_scanresults_le*)data;
result_count = pfn_result->count;
status = pfn_result->status;
/* PFN event is limited to fit 512 bytes so we may get
* multiple NET_FOUND events. For now place a warning here.
*/
WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
BRCMF_DBG(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
if (!result_count) {
BRCMF_ERR("FALSE PNO Event. (pfn_count == 0)\n");
// TODO(cphoenix): err isn't set here. Should it be?
goto out_err;
}
netinfo_start = brcmf_get_netinfo_array(pfn_result);
datalen = e->datalen - ((char*)netinfo_start - (char*)pfn_result);
if (datalen < result_count * sizeof(*netinfo)) {
BRCMF_ERR("insufficient event data\n");
// TODO(cphoenix): err isn't set here. Should it be?
goto out_err;
}
req = brcmf_alloc_internal_escan_request();
if (!req) {
err = ZX_ERR_NO_MEMORY;
goto out_err;
}
bucket_map = 0;
for (i = 0; i < (int32_t)result_count; i++) {
netinfo = &netinfo_start[i];
if (netinfo->SSID_len > WLAN_MAX_SSID_LEN) {
netinfo->SSID_len = WLAN_MAX_SSID_LEN;
}
BRCMF_DBG(SCAN, "SSID:%.32s Channel:%d\n", netinfo->SSID, netinfo->channel);
bucket_map |= brcmf_pno_get_bucket_map(cfg->pno, netinfo);
err = brcmf_internal_escan_add_info(req, netinfo->SSID, netinfo->SSID_len, netinfo->channel);
if (err != ZX_OK) {
goto out_err;
}
}
if (!bucket_map) {
goto free_req;
}
err = brcmf_start_internal_escan(ifp, bucket_map, req);
if (err == ZX_OK) {
goto free_req;
}
out_err:
if (ndev->scan_busy) {
BRCMF_DBG(TEMP, "out_err %d, signaling scan end", err);
brcmf_signal_scan_end(ndev, ndev->scan_txn_id, WLAN_SCAN_RESULT_INTERNAL_ERROR);
}
free_req:
free(req);
return err;
}
static zx_status_t brcmf_configure_opensecurity(struct brcmf_if* ifp) {
zx_status_t err;
int32_t wpa_val;
/* set auth */
err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
if (err != ZX_OK) {
BRCMF_ERR("auth error %d\n", err);
return err;
}
/* set wsec */
err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
if (err != ZX_OK) {
BRCMF_ERR("wsec error %d\n", err);
return err;
}
/* set upper-layer auth */
wpa_val = WPA_AUTH_DISABLED;
err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_val);
if (err != ZX_OK) {
BRCMF_ERR("wpa_auth error %d\n", err);
return err;
}
return ZX_OK;
}
static bool brcmf_valid_wpa_oui(uint8_t* oui, bool is_rsn_ie) {
if (is_rsn_ie) {
return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
}
return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
}
static zx_status_t brcmf_configure_wpaie(struct brcmf_if* ifp, const struct brcmf_vs_tlv* wpa_ie,
bool is_rsn_ie) {
uint32_t auth = 0; /* d11 open authentication */
uint16_t count;
zx_status_t err = ZX_OK;
int32_t len;
uint32_t i;
uint32_t wsec;
uint32_t pval = 0;
uint32_t gval = 0;
uint32_t wpa_auth = 0;
uint32_t offset;
uint8_t* data;
uint16_t rsn_cap;
uint32_t wme_bss_disable;
uint32_t mfp;
BRCMF_DBG(TRACE, "Enter\n");
if (wpa_ie == NULL) {
goto exit;
}
len = wpa_ie->len + TLV_HDR_LEN;
data = (uint8_t*)wpa_ie;
offset = TLV_HDR_LEN;
if (!is_rsn_ie) {
offset += VS_IE_FIXED_HDR_LEN;
} else {
offset += WPA_IE_VERSION_LEN;
}
/* check for multicast cipher suite */
if ((int32_t)offset + WPA_IE_MIN_OUI_LEN > len) {
err = ZX_ERR_INVALID_ARGS;
BRCMF_ERR("no multicast cipher suite\n");
goto exit;
}
if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
err = ZX_ERR_INVALID_ARGS;
BRCMF_ERR("invalid OUI\n");
goto exit;
}
offset += TLV_OUI_LEN;
/* pick up multicast cipher */
switch (data[offset]) {
case WPA_CIPHER_NONE:
gval = 0;
break;
case WPA_CIPHER_WEP_40:
case WPA_CIPHER_WEP_104:
gval = WEP_ENABLED;
break;
case WPA_CIPHER_TKIP:
gval = TKIP_ENABLED;
break;
case WPA_CIPHER_CCMP_128:
gval = AES_ENABLED;
break;
default:
err = ZX_ERR_INVALID_ARGS;
BRCMF_ERR("Invalid multi cast cipher info\n");
goto exit;
}
offset++;
/* walk thru unicast cipher list and pick up what we recognize */
count = data[offset] + (data[offset + 1] << 8);
offset += WPA_IE_SUITE_COUNT_LEN;
/* Check for unicast suite(s) */
if ((int32_t)(offset + (WPA_IE_MIN_OUI_LEN * count)) > len) {
err = ZX_ERR_INVALID_ARGS;
BRCMF_ERR("no unicast cipher suite\n");
goto exit;
}
for (i = 0; i < count; i++) {
if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
err = ZX_ERR_INVALID_ARGS;
BRCMF_ERR("ivalid OUI\n");
goto exit;
}
offset += TLV_OUI_LEN;
switch (data[offset]) {
case WPA_CIPHER_NONE:
break;
case WPA_CIPHER_WEP_40:
case WPA_CIPHER_WEP_104:
pval |= WEP_ENABLED;
break;
case WPA_CIPHER_TKIP:
pval |= TKIP_ENABLED;
break;
case WPA_CIPHER_CCMP_128:
pval |= AES_ENABLED;
break;
default:
BRCMF_ERR("Invalid unicast security info\n");
}
offset++;
}
/* walk thru auth management suite list and pick up what we recognize */
count = data[offset] + (data[offset + 1] << 8);
offset += WPA_IE_SUITE_COUNT_LEN;
/* Check for auth key management suite(s) */
if ((int32_t)(offset + (WPA_IE_MIN_OUI_LEN * count)) > len) {
err = ZX_ERR_INVALID_ARGS;
BRCMF_ERR("no auth key mgmt suite\n");
goto exit;
}
for (i = 0; i < count; i++) {
if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
err = ZX_ERR_INVALID_ARGS;
BRCMF_ERR("ivalid OUI\n");
goto exit;
}
offset += TLV_OUI_LEN;
switch (data[offset]) {
case RSN_AKM_NONE:
BRCMF_DBG(TRACE, "RSN_AKM_NONE\n");
wpa_auth |= WPA_AUTH_NONE;
break;
case RSN_AKM_UNSPECIFIED:
BRCMF_DBG(TRACE, "RSN_AKM_UNSPECIFIED\n");
is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) : (wpa_auth |= WPA_AUTH_UNSPECIFIED);
break;
case RSN_AKM_PSK:
BRCMF_DBG(TRACE, "RSN_AKM_PSK\n");
is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) : (wpa_auth |= WPA_AUTH_PSK);
break;
case RSN_AKM_SHA256_PSK:
BRCMF_DBG(TRACE, "RSN_AKM_MFP_PSK\n");
wpa_auth |= WPA2_AUTH_PSK_SHA256;
break;
case RSN_AKM_SHA256_1X:
BRCMF_DBG(TRACE, "RSN_AKM_MFP_1X\n");
wpa_auth |= WPA2_AUTH_1X_SHA256;
break;
default:
BRCMF_ERR("Invalid key mgmt info\n");
}
offset++;
}
mfp = BRCMF_MFP_NONE;
if (is_rsn_ie) {
wme_bss_disable = 1;
if (((int32_t)offset + RSN_CAP_LEN) <= len) {
rsn_cap = data[offset] + (data[offset + 1] << 8);
if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK) {
wme_bss_disable = 0;
}
if (rsn_cap & RSN_CAP_MFPR_MASK) {
BRCMF_DBG(TRACE, "MFP Required\n");
mfp = BRCMF_MFP_REQUIRED;
/* Firmware only supports mfp required in
* combination with WPA2_AUTH_PSK_SHA256 or
* WPA2_AUTH_1X_SHA256.
*/
if (!(wpa_auth & (WPA2_AUTH_PSK_SHA256 | WPA2_AUTH_1X_SHA256))) {
err = ZX_ERR_INVALID_ARGS;
goto exit;
}
/* Firmware has requirement that WPA2_AUTH_PSK/
* WPA2_AUTH_UNSPECIFIED be set, if SHA256 OUI
* is to be included in the rsn ie.
*/
if (wpa_auth & WPA2_AUTH_PSK_SHA256) {
wpa_auth |= WPA2_AUTH_PSK;
} else if (wpa_auth & WPA2_AUTH_1X_SHA256) {
wpa_auth |= WPA2_AUTH_UNSPECIFIED;
}
} else if (rsn_cap & RSN_CAP_MFPC_MASK) {
BRCMF_DBG(TRACE, "MFP Capable\n");
mfp = BRCMF_MFP_CAPABLE;
}
}
offset += RSN_CAP_LEN;
/* set wme_bss_disable to sync RSN Capabilities */
err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable", wme_bss_disable);
if (err != ZX_OK) {
BRCMF_ERR("wme_bss_disable error %d\n", err);
goto exit;
}
/* Skip PMKID cnt as it is know to be 0 for AP. */
offset += RSN_PMKID_COUNT_LEN;
/* See if there is BIP wpa suite left for MFP */
if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP) &&
((int32_t)(offset + WPA_IE_MIN_OUI_LEN) <= len)) {
err = brcmf_fil_bsscfg_data_set(ifp, "bip", &data[offset], WPA_IE_MIN_OUI_LEN);
if (err != ZX_OK) {
BRCMF_ERR("bip error %d\n", err);
goto exit;
}
}
}
/* FOR WPS , set SES_OW_ENABLED */
wsec = (pval | gval | SES_OW_ENABLED);
/* set auth */
err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
if (err != ZX_OK) {
BRCMF_ERR("auth error %d\n", err);
goto exit;
}
/* set wsec */
err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
if (err != ZX_OK) {
BRCMF_ERR("wsec error %d\n", err);
goto exit;
}
/* Configure MFP, this needs to go after wsec otherwise the wsec command
* will overwrite the values set by MFP
*/
if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) {
err = brcmf_fil_bsscfg_int_set(ifp, "mfp", mfp);
if (err != ZX_OK) {
BRCMF_ERR("mfp error %s\n", zx_status_get_string(err));
goto exit;
}
}
/* set upper-layer auth */
err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
if (err != ZX_OK) {
BRCMF_ERR("wpa_auth error %d\n", err);
goto exit;
}
exit:
return err;
}
static zx_status_t brcmf_parse_vndr_ies(const uint8_t* vndr_ie_buf, uint32_t vndr_ie_len,
struct parsed_vndr_ies* vndr_ies) {
struct brcmf_vs_tlv* vndrie;
struct brcmf_tlv* ie;
struct parsed_vndr_ie_info* parsed_info;
int32_t remaining_len;
remaining_len = (int32_t)vndr_ie_len;
memset(vndr_ies, 0, sizeof(*vndr_ies));
ie = (struct brcmf_tlv*)vndr_ie_buf;
while (ie) {
if (ie->id != WLAN_EID_VENDOR_SPECIFIC) {
goto next;
}
vndrie = (struct brcmf_vs_tlv*)ie;
/* len should be bigger than OUI length + one */
if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
BRCMF_ERR("invalid vndr ie. length is too small %d\n", vndrie->len);
goto next;
}
/* if wpa or wme ie, do not add ie */
if (!memcmp(vndrie->oui, (uint8_t*)WPA_OUI, TLV_OUI_LEN) &&
((vndrie->oui_type == WPA_OUI_TYPE) || (vndrie->oui_type == WME_OUI_TYPE))) {
BRCMF_DBG(TRACE, "Found WPA/WME oui. Do not add it\n");
goto next;
}
parsed_info = &vndr_ies->ie_info[vndr_ies->count];
/* save vndr ie information */
parsed_info->ie_ptr = (uint8_t*)vndrie;
parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
vndr_ies->count++;
BRCMF_DBG(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n", parsed_info->vndrie.oui[0],
parsed_info->vndrie.oui[1], parsed_info->vndrie.oui[2], parsed_info->vndrie.oui_type);
if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT) {
break;
}
next:
remaining_len -= (ie->len + TLV_HDR_LEN);
if (remaining_len <= TLV_HDR_LEN) {
ie = NULL;
} else {
ie = (struct brcmf_tlv*)(((uint8_t*)ie) + ie->len + TLV_HDR_LEN);
}
}
return ZX_OK;
}
static uint32_t brcmf_vndr_ie(uint8_t* iebuf, int32_t pktflag, uint8_t* ie_ptr, uint32_t ie_len,
int8_t* add_del_cmd) {
strncpy((char*)iebuf, (char*)add_del_cmd, VNDR_IE_CMD_LEN - 1);
iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
*(uint32_t*)&iebuf[VNDR_IE_COUNT_OFFSET] = 1;
*(uint32_t*)&iebuf[VNDR_IE_PKTFLAG_OFFSET] = pktflag;
memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
return ie_len + VNDR_IE_HDR_SIZE;
}
zx_status_t brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif* vif, int32_t pktflag,
const uint8_t* vndr_ie_buf, uint32_t vndr_ie_len) {
struct brcmf_if* ifp;
struct vif_saved_ie* saved_ie;
zx_status_t err = ZX_OK;
uint8_t* iovar_ie_buf;
uint8_t* curr_ie_buf;
uint8_t* mgmt_ie_buf = NULL;
int mgmt_ie_buf_len;
uint32_t* mgmt_ie_len;
uint32_t del_add_ie_buf_len = 0;
uint32_t total_ie_buf_len = 0;
uint32_t parsed_ie_buf_len = 0;
struct parsed_vndr_ies old_vndr_ies;
struct parsed_vndr_ies new_vndr_ies;
struct parsed_vndr_ie_info* vndrie_info;
int32_t i;
uint8_t* ptr;
int remained_buf_len;
if (!vif) {
return ZX_ERR_IO_NOT_PRESENT;
}
ifp = vif->ifp;
saved_ie = &vif->saved_ie;
BRCMF_DBG(TRACE, "bsscfgidx %d, pktflag : 0x%02X\n", ifp->bsscfgidx, pktflag);
iovar_ie_buf = static_cast<decltype(iovar_ie_buf)>(calloc(1, WL_EXTRA_BUF_MAX));
if (!iovar_ie_buf) {
return ZX_ERR_NO_MEMORY;
}
curr_ie_buf = iovar_ie_buf;
switch (pktflag) {
case BRCMF_VNDR_IE_PRBREQ_FLAG:
mgmt_ie_buf = saved_ie->probe_req_ie;
mgmt_ie_len = &saved_ie->probe_req_ie_len;
mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
break;
case BRCMF_VNDR_IE_PRBRSP_FLAG:
mgmt_ie_buf = saved_ie->probe_res_ie;
mgmt_ie_len = &saved_ie->probe_res_ie_len;
mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
break;
case BRCMF_VNDR_IE_BEACON_FLAG:
mgmt_ie_buf = saved_ie->beacon_ie;
mgmt_ie_len = &saved_ie->beacon_ie_len;
mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
break;
case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
mgmt_ie_buf = saved_ie->assoc_req_ie;
mgmt_ie_len = &saved_ie->assoc_req_ie_len;
mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
break;
default:
err = ZX_ERR_WRONG_TYPE;
BRCMF_ERR("not suitable type\n");
goto exit;
}
if ((int)vndr_ie_len > mgmt_ie_buf_len) {
err = ZX_ERR_NO_MEMORY;
BRCMF_ERR("extra IE size too big\n");
goto exit;
}
/* parse and save new vndr_ie in curr_ie_buff before comparing it */
if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
ptr = curr_ie_buf;
brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
for (i = 0; i < (int32_t)new_vndr_ies.count; i++) {
vndrie_info = &new_vndr_ies.ie_info[i];
memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr, vndrie_info->ie_len);
parsed_ie_buf_len += vndrie_info->ie_len;
}
}
if (mgmt_ie_buf && *mgmt_ie_len) {
if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
(memcmp(mgmt_ie_buf, curr_ie_buf, parsed_ie_buf_len) == 0)) {
BRCMF_DBG(TRACE, "Previous mgmt IE equals to current IE\n");
goto exit;
}
/* parse old vndr_ie */
brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
/* make a command to delete old ie */
for (i = 0; i < (int32_t)old_vndr_ies.count; i++) {
vndrie_info = &old_vndr_ies.ie_info[i];
BRCMF_DBG(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n", vndrie_info->vndrie.id,
vndrie_info->vndrie.len, vndrie_info->vndrie.oui[0], vndrie_info->vndrie.oui[1],
vndrie_info->vndrie.oui[2]);
del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, vndrie_info->ie_ptr,
vndrie_info->ie_len, (int8_t*)"del");
curr_ie_buf += del_add_ie_buf_len;
total_ie_buf_len += del_add_ie_buf_len;
}
}
*mgmt_ie_len = 0;
/* Add if there is any extra IE */
if (mgmt_ie_buf && parsed_ie_buf_len) {
ptr = mgmt_ie_buf;
remained_buf_len = mgmt_ie_buf_len;
/* make a command to add new ie */
for (i = 0; i < (int32_t)new_vndr_ies.count; i++) {
vndrie_info = &new_vndr_ies.ie_info[i];
/* verify remained buf size before copy data */
if (remained_buf_len < (vndrie_info->vndrie.len + VNDR_IE_VSIE_OFFSET)) {
BRCMF_ERR("no space in mgmt_ie_buf: len left %d", remained_buf_len);
break;
}
remained_buf_len -= (vndrie_info->ie_len + VNDR_IE_VSIE_OFFSET);
BRCMF_DBG(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n", vndrie_info->vndrie.id,
vndrie_info->vndrie.len, vndrie_info->vndrie.oui[0], vndrie_info->vndrie.oui[1],
vndrie_info->vndrie.oui[2]);
del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, vndrie_info->ie_ptr,
vndrie_info->ie_len, (int8_t*)"add");
/* save the parsed IE in wl struct */
memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr, vndrie_info->ie_len);
*mgmt_ie_len += vndrie_info->ie_len;
curr_ie_buf += del_add_ie_buf_len;
total_ie_buf_len += del_add_ie_buf_len;
}
}
if (total_ie_buf_len) {
err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf, total_ie_buf_len);
if (err != ZX_OK) {
BRCMF_ERR("vndr ie set error : %d\n", err);
}
}
exit:
free(iovar_ie_buf);
return err;
}
zx_status_t brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif* vif) {
int32_t pktflags[] = {BRCMF_VNDR_IE_PRBREQ_FLAG, BRCMF_VNDR_IE_PRBRSP_FLAG,
BRCMF_VNDR_IE_BEACON_FLAG};
int i;
for (i = 0; i < (int)countof(pktflags); i++) {
brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
}
memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
return ZX_OK;
}
// Returns an MLME result code (WLAN_START_RESULT_*)
static uint8_t brcmf_cfg80211_start_ap(struct net_device* ndev, wlanif_start_req_t* req) {
if (req->bss_type != WLAN_BSS_TYPE_INFRASTRUCTURE) {
BRCMF_ERR("Attempt to start AP in unsupported mode (%d)\n", req->bss_type);
return WLAN_START_RESULT_NOT_SUPPORTED;
}
BRCMF_DBG(TRACE, "ssid: %*s beacon period: %d dtim_period: %d channel: %d rsne_len: %zd",
req->ssid.len, req->ssid.data, req->beacon_period, req->dtim_period, req->channel,
req->rsne_len);
struct brcmf_if* ifp = ndev_to_if(ndev);
if (ifp->vif->mbss) {
BRCMF_ERR("Mesh role not yet supported\n");
return WLAN_START_RESULT_NOT_SUPPORTED;
}
struct brcmf_cfg80211_info* cfg = ifp->drvr->config;
wlan_channel_t channel = {};
uint16_t chanspec = 0;
zx_status_t status;
int32_t fw_err = 0;
struct brcmf_ssid_le ssid_le;
memset(&ssid_le, 0, sizeof(ssid_le));
memcpy(ssid_le.SSID, req->ssid.data, req->ssid.len);
ssid_le.SSID_len = req->ssid.len;
brcmf_set_mpc(ifp, 0);
brcmf_configure_arp_nd_offload(ifp, false);
// Configure RSN IE
if (req->rsne_len != 0) {
struct brcmf_vs_tlv* tmp_ie = (struct brcmf_vs_tlv*)req->rsne;
status = brcmf_configure_wpaie(ifp, tmp_ie, true);
if (status != ZX_OK) {
BRCMF_ERR("Failed to install RSNE\n");
goto fail;
}
} else {
brcmf_configure_opensecurity(ifp);
}
status = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, req->beacon_period, &fw_err);
if (status != ZX_OK) {
BRCMF_ERR("Beacon Interval Set Error: %s, fw err %s\n", zx_status_get_string(status),
brcmf_fil_get_errstr(fw_err));
goto fail;
}
ifp->vif->profile.beacon_period = req->beacon_period;
status = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD, req->dtim_period, &fw_err);
if (status != ZX_OK) {
BRCMF_ERR("DTIM Interval Set Error: %s, fw err %s\n", zx_status_get_string(status),
brcmf_fil_get_errstr(fw_err));
goto fail;
}
status = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1, &fw_err);
if (status != ZX_OK) {
BRCMF_ERR("BRCMF_C_DOWN error %s, fw err %s\n", zx_status_get_string(status),
brcmf_fil_get_errstr(fw_err));
goto fail;
}
// Disable simultaneous STA/AP operation, aka Real Simultaneous Dual Band (RSDB)
brcmf_fil_iovar_int_set(ifp, "apsta", 0, nullptr);
status = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1, &fw_err);
if (status != ZX_OK) {
BRCMF_ERR("SET INFRA error %s, fw err %s\n", zx_status_get_string(status),
brcmf_fil_get_errstr(fw_err));
goto fail;
}
status = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1, &fw_err);
if (status != ZX_OK) {
BRCMF_ERR("setting AP mode failed %s, fw err %s\n", zx_status_get_string(status),
brcmf_fil_get_errstr(fw_err));
goto fail;
}
channel = {.primary = req->channel, .cbw = CBW20, .secondary80 = 0};
chanspec = channel_to_chanspec(&cfg->d11inf, &channel);
status = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec, &fw_err);
if (status != ZX_OK) {
BRCMF_ERR("Set Channel failed: chspec=%d, status=%s, fw_err=%s\n", chanspec,
zx_status_get_string(status), brcmf_fil_get_errstr(fw_err));
goto fail;
}
status = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1, &fw_err);
if (status != ZX_OK) {
BRCMF_ERR("BRCMF_C_UP error: %s, fw err %s\n", zx_status_get_string(status),
brcmf_fil_get_errstr(fw_err));
goto fail;
}
struct brcmf_join_params join_params;
memset(&join_params, 0, sizeof(join_params));
// join parameters starts with ssid
memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
// create softap
status =
brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, &join_params, sizeof(join_params), &fw_err);
if (status != ZX_OK) {
BRCMF_ERR("SET SSID error: %s, fw err %s\n", zx_status_get_string(status),
brcmf_fil_get_errstr(fw_err));
goto fail;
}
BRCMF_DBG(TRACE, "AP mode configuration complete\n");
brcmf_set_bit_in_array(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
brcmf_net_setcarrier(ifp, true);
return WLAN_START_RESULT_SUCCESS;
fail:
brcmf_set_mpc(ifp, 1);
brcmf_configure_arp_nd_offload(ifp, true);
return WLAN_START_RESULT_NOT_SUPPORTED;
}
// Returns an MLME result code (WLAN_STOP_RESULT_*)
static uint8_t brcmf_cfg80211_stop_ap(struct net_device* ndev, wlanif_stop_req_t* req) {
struct brcmf_if* ifp = ndev_to_if(ndev);
zx_status_t status;
int32_t fw_err = 0;
uint8_t result = WLAN_STOP_RESULT_SUCCESS;
struct brcmf_join_params join_params;
if (!brcmf_test_bit_in_array(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state)) {
BRCMF_ERR("attempt to stop already stopped AP\n");
return WLAN_STOP_RESULT_BSS_ALREADY_STOPPED;
}
memset(&join_params, 0, sizeof(join_params));
status =
brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, &join_params, sizeof(join_params), &fw_err);
if (status != ZX_OK) {
BRCMF_ERR("SET SSID error: %s, fw err %s\n", zx_status_get_string(status),
brcmf_fil_get_errstr(fw_err));
result = WLAN_STOP_RESULT_INTERNAL_ERROR;
}
status = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1, &fw_err);
if (status != ZX_OK) {
BRCMF_ERR("BRCMF_C_DOWN error: %s, fw err %s\n", zx_status_get_string(status),
brcmf_fil_get_errstr(fw_err));
result = WLAN_STOP_RESULT_INTERNAL_ERROR;
}
status = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0, &fw_err);
if (status != ZX_OK) {
BRCMF_ERR("setting AP mode failed: %s, fw err %s\n", zx_status_get_string(status),
brcmf_fil_get_errstr(fw_err));
result = WLAN_STOP_RESULT_INTERNAL_ERROR;