blob: e9eb33d486b77c4d1fc312ab29d4009f20a22598 [file] [log] [blame]
/*
* Linux cfg80211 driver
*
* Copyright (C) 1999-2014, Broadcom Corporation
*
* Unless you and Broadcom execute a separate written software license
* agreement governing use of this software, this software is licensed to you
* under the terms of the GNU General Public License version 2 (the "GPL"),
* available at http://www.broadcom.com/licenses/GPLv2.php, with the
* following added to such license:
*
* As a special exception, the copyright holders of this software give you
* permission to link this software with independent modules, and to copy and
* distribute the resulting executable under terms of your choice, provided that
* you also meet, for each linked independent module, the terms and conditions of
* the license of that module. An independent module is a module which is not
* derived from this software. The special exception does not apply to any
* modifications of the software.
*
* Notwithstanding the above, under no circumstances may you combine this
* software in any way with any other Broadcom software provided under a license
* other than the GPL, without Broadcom's express prior written consent.
*
* $Id: wl_cfg80211.c 477711 2014-05-14 08:45:17Z $
*/
/* */
#include <typedefs.h>
#include <linuxver.h>
#include <osl.h>
#include <linux/kernel.h>
#include <bcmutils.h>
#include <bcmwifi_channels.h>
#include <bcmendian.h>
#include <proto/ethernet.h>
#include <proto/802.11.h>
#include <linux/if_arp.h>
#include <asm/uaccess.h>
#include <dngl_stats.h>
#include <dhd.h>
#include <dhd_linux.h>
#include <dhdioctl.h>
#include <wlioctl.h>
#include <dhd_cfg80211.h>
#ifdef PNO_SUPPORT
#include <dhd_pno.h>
#endif /* PNO_SUPPORT */
#include <dhd_debug.h>
#include <proto/ethernet.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/netdevice.h>
#include <linux/sched.h>
#include <linux/etherdevice.h>
#include <linux/wireless.h>
#include <linux/ieee80211.h>
#include <linux/wait.h>
#include <net/cfg80211.h>
#include <net/rtnetlink.h>
#include <wlioctl.h>
#include <wldev_common.h>
#include <wl_cfg80211.h>
#include <wl_cfgp2p.h>
#include <wl_android.h>
#ifdef PROP_TXSTATUS
#include <dhd_wlfc.h>
#endif
#if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 13, 0)) || defined(WL_VENDOR_EXT_SUPPORT)
#include <wl_cfgvendor.h>
#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(3, 13, 0)) || defined(WL_VENDOR_EXT_SUPPORT) */
#ifdef WL11U
#if !defined(WL_ENABLE_P2P_IF) && !defined(WL_CFG80211_P2P_DEV_IF)
#error You should enable 'WL_ENABLE_P2P_IF' or 'WL_CFG80211_P2P_DEV_IF' \
according to Kernel version and is supported only in Android-JB
#endif /* !WL_ENABLE_P2P_IF && !WL_CFG80211_P2P_DEV_IF */
#endif /* WL11U */
#define IW_WSEC_ENABLED(wsec) ((wsec) & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED))
static struct device *cfg80211_parent_dev = NULL;
u32 wl_dbg_level = WL_DBG_ERR;
#define MAX_WAIT_TIME 1500
#define CHAN_INFO_LEN 128
#define IBSS_IF_NAME "ibss%d"
#ifdef VSDB
/* sleep time to keep STA's connecting or connection for continuous af tx or finding a peer */
#define DEFAULT_SLEEP_TIME_VSDB 120
#define OFF_CHAN_TIME_THRESHOLD_MS 200
#define AF_RETRY_DELAY_TIME 40
/* if sta is connected or connecting, sleep for a while before retry af tx or finding a peer */
#define WL_AF_TX_KEEP_PRI_CONNECTION_VSDB(cfg) \
do { \
if (wl_get_drv_status(cfg, CONNECTED, bcmcfg_to_prmry_ndev(cfg)) || \
wl_get_drv_status(cfg, CONNECTING, bcmcfg_to_prmry_ndev(cfg))) { \
OSL_SLEEP(DEFAULT_SLEEP_TIME_VSDB); \
} \
} while (0)
#else /* VSDB */
/* if not VSDB, do nothing */
#define WL_AF_TX_KEEP_PRI_CONNECTION_VSDB(cfg)
#endif /* VSDB */
#ifdef WL_CFG80211_SYNC_GON
#define WL_DRV_STATUS_SENDING_AF_FRM_EXT(cfg) \
(wl_get_drv_status_all(cfg, SENDING_ACT_FRM) || \
wl_get_drv_status_all(cfg, WAITING_NEXT_ACT_FRM_LISTEN))
#else
#define WL_DRV_STATUS_SENDING_AF_FRM_EXT(cfg) wl_get_drv_status_all(cfg, SENDING_ACT_FRM)
#endif /* WL_CFG80211_SYNC_GON */
#define WL_IS_P2P_DEV_EVENT(e) ((e->emsg.ifidx == 0) && \
(e->emsg.bsscfgidx == P2PAPI_BSSCFG_DEVICE))
#define DNGL_FUNC(func, parameters) func parameters
#define COEX_DHCP
#define WLAN_EID_SSID 0
#define CH_MIN_5G_CHANNEL 34
#define CH_MIN_2G_CHANNEL 1
/* This is to override regulatory domains defined in cfg80211 module (reg.c)
* By default world regulatory domain defined in reg.c puts the flags NL80211_RRF_PASSIVE_SCAN
* and NL80211_RRF_NO_IBSS for 5GHz channels (for 36..48 and 149..165).
* With respect to these flags, wpa_supplicant doesn't start p2p operations on 5GHz channels.
* All the chnages in world regulatory domain are to be done here.
*/
static const struct ieee80211_regdomain brcm_regdom = {
.n_reg_rules = 4,
.alpha2 = "99",
.reg_rules = {
/* IEEE 802.11b/g, channels 1..11 */
REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
/* If any */
/* IEEE 802.11 channel 14 - Only JP enables
* this and for 802.11b only
*/
REG_RULE(2484-10, 2484+10, 20, 6, 20, 0),
/* IEEE 802.11a, channel 36..64 */
REG_RULE(5150-10, 5350+10, 40, 6, 20, 0),
/* IEEE 802.11a, channel 100..165 */
REG_RULE(5470-10, 5850+10, 40, 6, 20, 0), }
};
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0)) && \
(defined(WL_IFACE_COMB_NUM_CHANNELS) || defined(WL_CFG80211_P2P_DEV_IF))
/*
* Possible interface combinations supported by driver
*
* ADHOC Mode - #ADHOC <= 1 on channels = 1
* SoftAP Mode - #AP <= 1 on channels = 1
* STA + P2P Mode - #STA <= 2, #{P2P-GO, P2P-client} <= 1, #P2P-device <= 1
* on channels = 2
*/
static const struct ieee80211_iface_limit common_if_limits[] = {
{
.max = 1,
.types = BIT(NL80211_IFTYPE_AP),
},
{
/*
* During P2P-GO removal, P2P-GO is first changed to STA and later only
* removed. So setting maximum possible number of STA interfaces according
* to kernel version.
*
* less than linux-3.8 - max:3 (wlan0 + p2p0 + group removal of p2p-p2p0-x)
* linux-3.8 and above - max:2 (wlan0 + group removal of p2p-wlan0-x)
*/
#ifdef WL_ENABLE_P2P_IF
.max = 3,
#else
.max = 2,
#endif /* WL_ENABLE_P2P_IF */
.types = BIT(NL80211_IFTYPE_STATION),
},
{
.max = 2,
.types = BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_CLIENT),
},
#if defined(WL_CFG80211_P2P_DEV_IF)
{
.max = 1,
.types = BIT(NL80211_IFTYPE_P2P_DEVICE),
},
#endif /* WL_CFG80211_P2P_DEV_IF */
{
.max = 1,
.types = BIT(NL80211_IFTYPE_ADHOC),
},
};
#ifdef BCM4330_CHIP
#define NUM_DIFF_CHANNELS 1
#else
#define NUM_DIFF_CHANNELS 2
#endif
static const struct ieee80211_iface_combination
common_iface_combinations[] = {
{
.num_different_channels = NUM_DIFF_CHANNELS,
.max_interfaces = 4,
.limits = common_if_limits,
.n_limits = ARRAY_SIZE(common_if_limits),
},
};
#endif /* LINUX_VER >= 3.0 && (WL_IFACE_COMB_NUM_CHANNELS || WL_CFG80211_P2P_DEV_IF) */
/* Data Element Definitions */
#define WPS_ID_CONFIG_METHODS 0x1008
#define WPS_ID_REQ_TYPE 0x103A
#define WPS_ID_DEVICE_NAME 0x1011
#define WPS_ID_VERSION 0x104A
#define WPS_ID_DEVICE_PWD_ID 0x1012
#define WPS_ID_REQ_DEV_TYPE 0x106A
#define WPS_ID_SELECTED_REGISTRAR_CONFIG_METHODS 0x1053
#define WPS_ID_PRIM_DEV_TYPE 0x1054
/* Device Password ID */
#define DEV_PW_DEFAULT 0x0000
#define DEV_PW_USER_SPECIFIED 0x0001,
#define DEV_PW_MACHINE_SPECIFIED 0x0002
#define DEV_PW_REKEY 0x0003
#define DEV_PW_PUSHBUTTON 0x0004
#define DEV_PW_REGISTRAR_SPECIFIED 0x0005
/* Config Methods */
#define WPS_CONFIG_USBA 0x0001
#define WPS_CONFIG_ETHERNET 0x0002
#define WPS_CONFIG_LABEL 0x0004
#define WPS_CONFIG_DISPLAY 0x0008
#define WPS_CONFIG_EXT_NFC_TOKEN 0x0010
#define WPS_CONFIG_INT_NFC_TOKEN 0x0020
#define WPS_CONFIG_NFC_INTERFACE 0x0040
#define WPS_CONFIG_PUSHBUTTON 0x0080
#define WPS_CONFIG_KEYPAD 0x0100
#define WPS_CONFIG_VIRT_PUSHBUTTON 0x0280
#define WPS_CONFIG_PHY_PUSHBUTTON 0x0480
#define WPS_CONFIG_VIRT_DISPLAY 0x2008
#define WPS_CONFIG_PHY_DISPLAY 0x4008
#define PM_BLOCK 1
#define PM_ENABLE 0
#ifdef MFP
#define WL_AKM_SUITE_MFP_1X 0x000FAC05
#define WL_AKM_SUITE_MFP_PSK 0x000FAC06
#endif /* MFP */
#ifndef IBSS_COALESCE_ALLOWED
#define IBSS_COALESCE_ALLOWED 0
#endif
#ifndef IBSS_INITIAL_SCAN_ALLOWED
#define IBSS_INITIAL_SCAN_ALLOWED 0
#endif
#define CUSTOM_RETRY_MASK 0xff000000 /* Mask for retry counter of custom dwell time */
/*
* cfg80211_ops api/callback list
*/
static s32 wl_frame_get_mgmt(u16 fc, const struct ether_addr *da,
const struct ether_addr *sa, const struct ether_addr *bssid,
u8 **pheader, u32 *body_len, u8 *pbody);
static s32 __wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
struct cfg80211_scan_request *request,
struct cfg80211_ssid *this_ssid);
#if defined(WL_CFG80211_P2P_DEV_IF)
static s32
wl_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request);
#else
static s32
wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
struct cfg80211_scan_request *request);
#endif /* WL_CFG80211_P2P_DEV_IF */
static s32 wl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed);
static bcm_struct_cfgdev* bcm_cfg80211_add_ibss_if(struct wiphy *wiphy, char *name);
static s32 bcm_cfg80211_del_ibss_if(struct wiphy *wiphy, bcm_struct_cfgdev *cfgdev);
static s32 wl_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
struct cfg80211_ibss_params *params);
static s32 wl_cfg80211_leave_ibss(struct wiphy *wiphy,
struct net_device *dev);
static s32 wl_cfg80211_get_station(struct wiphy *wiphy,
struct net_device *dev,
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
const
#endif
u8 *mac, struct station_info *sinfo);
static s32 wl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
struct net_device *dev, bool enabled,
s32 timeout);
static int wl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
struct cfg80211_connect_params *sme);
static s32 wl_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
u16 reason_code);
#if defined(WL_CFG80211_P2P_DEV_IF)
static s32
wl_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
enum nl80211_tx_power_setting type, s32 mbm);
#else
static s32
wl_cfg80211_set_tx_power(struct wiphy *wiphy,
enum nl80211_tx_power_setting type, s32 dbm);
#endif /* WL_CFG80211_P2P_DEV_IF */
#if defined(WL_CFG80211_P2P_DEV_IF)
static s32 wl_cfg80211_get_tx_power(struct wiphy *wiphy,
struct wireless_dev *wdev, s32 *dbm);
#else
static s32 wl_cfg80211_get_tx_power(struct wiphy *wiphy, s32 *dbm);
#endif /* WL_CFG80211_P2P_DEV_IF */
static s32 wl_cfg80211_config_default_key(struct wiphy *wiphy,
struct net_device *dev,
u8 key_idx, bool unicast, bool multicast);
static s32 wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
u8 key_idx, bool pairwise, const u8 *mac_addr,
struct key_params *params);
static s32 wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
u8 key_idx, bool pairwise, const u8 *mac_addr);
static s32 wl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *dev,
u8 key_idx, bool pairwise, const u8 *mac_addr,
void *cookie, void (*callback) (void *cookie,
struct key_params *params));
static s32 wl_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
struct net_device *dev, u8 key_idx);
static s32 wl_cfg80211_resume(struct wiphy *wiphy);
#if defined(WL_SUPPORT_BACKPORTED_KPATCHES) || (LINUX_VERSION_CODE >= KERNEL_VERSION(3, \
2, 0))
static s32 wl_cfg80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
bcm_struct_cfgdev *cfgdev, u64 cookie);
static s32 wl_cfg80211_del_station(struct wiphy *wiphy,
struct net_device *ndev,
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
const
#endif
u8 *mac_addr);
static s32 wl_cfg80211_change_station(struct wiphy *wiphy,
struct net_device *dev,
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
const
#endif
u8 *mac, struct station_parameters *params);
#endif /* WL_SUPPORT_BACKPORTED_KPATCHES || KERNEL_VER >= KERNEL_VERSION(3, 2, 0)) */
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39))
static s32 wl_cfg80211_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
#else
static s32 wl_cfg80211_suspend(struct wiphy *wiphy);
#endif
static s32 wl_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
struct cfg80211_pmksa *pmksa);
static s32 wl_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
struct cfg80211_pmksa *pmksa);
static s32 wl_cfg80211_flush_pmksa(struct wiphy *wiphy,
struct net_device *dev);
static void wl_cfg80211_scan_abort(struct bcm_cfg80211 *cfg);
static s32 wl_notify_escan_complete(struct bcm_cfg80211 *cfg,
struct net_device *ndev, bool aborted, bool fw_abort);
#if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 2, 0))
static s32 wl_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
const
#endif
u8 *peer, enum nl80211_tdls_operation oper);
#endif
#ifdef WL_SCHED_SCAN
static int wl_cfg80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev);
#endif
#if defined(DUAL_STA) || defined(DUAL_STA_STATIC_IF)
bcm_struct_cfgdev*
wl_cfg80211_create_iface(struct wiphy *wiphy, enum nl80211_iftype
iface_type, u8 *mac_addr, const char *name);
s32
wl_cfg80211_del_iface(struct wiphy *wiphy, bcm_struct_cfgdev *cfgdev);
#endif /* defined(DUAL_STA) || defined(DUAL_STA_STATIC_IF) */
/*
* event & event Q handlers for cfg80211 interfaces
*/
static s32 wl_create_event_handler(struct bcm_cfg80211 *cfg);
static void wl_destroy_event_handler(struct bcm_cfg80211 *cfg);
static s32 wl_event_handler(void *data);
static void wl_init_eq(struct bcm_cfg80211 *cfg);
static void wl_flush_eq(struct bcm_cfg80211 *cfg);
static unsigned long wl_lock_eq(struct bcm_cfg80211 *cfg);
static void wl_unlock_eq(struct bcm_cfg80211 *cfg, unsigned long flags);
static void wl_init_eq_lock(struct bcm_cfg80211 *cfg);
static void wl_init_event_handler(struct bcm_cfg80211 *cfg);
static struct wl_event_q *wl_deq_event(struct bcm_cfg80211 *cfg);
static s32 wl_enq_event(struct bcm_cfg80211 *cfg, struct net_device *ndev, u32 type,
const wl_event_msg_t *msg, void *data);
static void wl_put_event(struct wl_event_q *e);
static void wl_wakeup_event(struct bcm_cfg80211 *cfg);
static s32 wl_notify_connect_status_ap(struct bcm_cfg80211 *cfg, struct net_device *ndev,
const wl_event_msg_t *e, void *data);
static s32 wl_notify_connect_status(struct bcm_cfg80211 *cfg,
bcm_struct_cfgdev *cfgdev, const wl_event_msg_t *e, void *data);
static s32 wl_notify_roaming_status(struct bcm_cfg80211 *cfg,
bcm_struct_cfgdev *cfgdev, const wl_event_msg_t *e, void *data);
static s32 wl_notify_scan_status(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
const wl_event_msg_t *e, void *data);
static s32 wl_bss_connect_done(struct bcm_cfg80211 *cfg, struct net_device *ndev,
const wl_event_msg_t *e, void *data, bool completed);
static s32 wl_bss_roaming_done(struct bcm_cfg80211 *cfg, struct net_device *ndev,
const wl_event_msg_t *e, void *data);
static s32 wl_notify_mic_status(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
const wl_event_msg_t *e, void *data);
#ifdef BT_WIFI_HANDOVER
static s32 wl_notify_bt_wifi_handover_req(struct bcm_cfg80211 *cfg,
bcm_struct_cfgdev *cfgdev, const wl_event_msg_t *e, void *data);
#endif /* BT_WIFI_HANDOVER */
#ifdef WL_SCHED_SCAN
static s32
wl_notify_sched_scan_results(struct bcm_cfg80211 *cfg, struct net_device *ndev,
const wl_event_msg_t *e, void *data);
#endif /* WL_SCHED_SCAN */
#ifdef PNO_SUPPORT
static s32 wl_notify_pfn_status(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
const wl_event_msg_t *e, void *data);
#endif /* PNO_SUPPORT */
#ifdef GSCAN_SUPPORT
static s32 wl_notify_gscan_event(struct bcm_cfg80211 *wl, bcm_struct_cfgdev *cfgdev,
const wl_event_msg_t *e, void *data);
static s32 wl_handle_roam_exp_event(struct bcm_cfg80211 *wl, bcm_struct_cfgdev *cfgdev,
const wl_event_msg_t *e, void *data);
#endif /* GSCAN_SUPPORT */
static s32 wl_handle_rssi_monitor_event(struct bcm_cfg80211 *wl, bcm_struct_cfgdev *cfgdev,
const wl_event_msg_t *e, void *data);
static s32 wl_notifier_change_state(struct bcm_cfg80211 *cfg, struct net_info *_net_info,
enum wl_status state, bool set);
#ifdef WLTDLS
static s32 wl_tdls_event_handler(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
const wl_event_msg_t *e, void *data);
#endif /* WLTDLS */
/*
* register/deregister parent device
*/
static void wl_cfg80211_clear_parent_dev(void);
/*
* ioctl utilites
*/
/*
* cfg80211 set_wiphy_params utilities
*/
static s32 wl_set_frag(struct net_device *dev, u32 frag_threshold);
static s32 wl_set_rts(struct net_device *dev, u32 frag_threshold);
static s32 wl_set_retry(struct net_device *dev, u32 retry, bool l);
/*
* cfg profile utilities
*/
static s32 wl_update_prof(struct bcm_cfg80211 *cfg, struct net_device *ndev,
const wl_event_msg_t *e, void *data, s32 item);
static void *wl_read_prof(struct bcm_cfg80211 *cfg, struct net_device *ndev, s32 item);
static void wl_init_prof(struct bcm_cfg80211 *cfg, struct net_device *ndev);
/*
* cfg80211 connect utilites
*/
static s32 wl_set_wpa_version(struct net_device *dev,
struct cfg80211_connect_params *sme);
static s32 wl_set_auth_type(struct net_device *dev,
struct cfg80211_connect_params *sme);
static s32 wl_set_set_cipher(struct net_device *dev,
struct cfg80211_connect_params *sme);
static s32 wl_set_key_mgmt(struct net_device *dev,
struct cfg80211_connect_params *sme);
static s32 wl_set_set_sharedkey(struct net_device *dev,
struct cfg80211_connect_params *sme);
static s32 wl_get_assoc_ies(struct bcm_cfg80211 *cfg, struct net_device *ndev);
static void wl_ch_to_chanspec(int ch,
struct wl_join_params *join_params, size_t *join_params_size);
/*
* information element utilities
*/
static void wl_rst_ie(struct bcm_cfg80211 *cfg);
static __used s32 wl_add_ie(struct bcm_cfg80211 *cfg, u8 t, u8 l, u8 *v);
static void wl_update_hidden_ap_ie(struct wl_bss_info *bi, u8 *ie_stream, u32 *ie_size, bool roam);
static s32 wl_mrg_ie(struct bcm_cfg80211 *cfg, u8 *ie_stream, u16 ie_size);
static s32 wl_cp_ie(struct bcm_cfg80211 *cfg, u8 *dst, u16 dst_size);
static u32 wl_get_ielen(struct bcm_cfg80211 *cfg);
#ifdef MFP
static int wl_cfg80211_get_rsn_capa(bcm_tlv_t *wpa2ie, u8* capa);
#endif
#ifdef WL11U
bcm_tlv_t *
wl_cfg80211_find_interworking_ie(u8 *parse, u32 len);
static s32
wl_cfg80211_add_iw_ie(struct bcm_cfg80211 *cfg, struct net_device *ndev, s32 bssidx, s32 pktflag,
uint8 ie_id, uint8 *data, uint8 data_len);
#endif /* WL11U */
static s32 wl_setup_wiphy(struct wireless_dev *wdev, struct device *dev, void *data);
static void wl_free_wdev(struct bcm_cfg80211 *cfg);
#ifdef CONFIG_CFG80211_INTERNAL_REGDB
static void
wl_cfg80211_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request);
#endif /* CONFIG_CFG80211_INTERNAL_REGDB */
static s32 wl_inform_bss(struct bcm_cfg80211 *cfg);
static s32 wl_inform_single_bss(struct bcm_cfg80211 *cfg, struct wl_bss_info *bi, bool roam);
static s32 wl_update_bss_info(struct bcm_cfg80211 *cfg, struct net_device *ndev, bool roam);
static chanspec_t wl_cfg80211_get_shared_freq(struct wiphy *wiphy);
s32 wl_cfg80211_channel_to_freq(u32 channel);
static void wl_cfg80211_work_handler(struct work_struct *work);
static s32 wl_add_keyext(struct wiphy *wiphy, struct net_device *dev,
u8 key_idx, const u8 *mac_addr,
struct key_params *params);
/*
* key indianess swap utilities
*/
static void swap_key_from_BE(struct wl_wsec_key *key);
static void swap_key_to_BE(struct wl_wsec_key *key);
/*
* bcm_cfg80211 memory init/deinit utilities
*/
static s32 wl_init_priv_mem(struct bcm_cfg80211 *cfg);
static void wl_deinit_priv_mem(struct bcm_cfg80211 *cfg);
static void wl_delay(u32 ms);
/*
* ibss mode utilities
*/
static bool wl_is_ibssmode(struct bcm_cfg80211 *cfg, struct net_device *ndev);
static __used bool wl_is_ibssstarter(struct bcm_cfg80211 *cfg);
/*
* link up/down , default configuration utilities
*/
static s32 __wl_cfg80211_up(struct bcm_cfg80211 *cfg);
static s32 __wl_cfg80211_down(struct bcm_cfg80211 *cfg);
static bool wl_is_linkdown(struct bcm_cfg80211 *cfg, const wl_event_msg_t *e);
static bool wl_is_linkup(struct bcm_cfg80211 *cfg, const wl_event_msg_t *e,
struct net_device *ndev);
static bool wl_is_nonetwork(struct bcm_cfg80211 *cfg, const wl_event_msg_t *e);
static void wl_link_up(struct bcm_cfg80211 *cfg);
static void wl_link_down(struct bcm_cfg80211 *cfg);
static s32 wl_config_ifmode(struct bcm_cfg80211 *cfg, struct net_device *ndev, s32 iftype);
static void wl_init_conf(struct wl_conf *conf);
static s32 wl_cfg80211_handle_ifdel(struct bcm_cfg80211 *cfg, wl_if_event_info *if_event_info,
struct net_device* ndev);
int wl_cfg80211_get_ioctl_version(void);
/*
* find most significant bit set
*/
static __used u32 wl_find_msb(u16 bit16);
/*
* rfkill support
*/
static int wl_setup_rfkill(struct bcm_cfg80211 *cfg, bool setup);
static int wl_rfkill_set(void *data, bool blocked);
#ifdef DEBUGFS_CFG80211
static s32 wl_setup_debugfs(struct bcm_cfg80211 *cfg);
static s32 wl_free_debugfs(struct bcm_cfg80211 *cfg);
#endif
static wl_scan_params_t *wl_cfg80211_scan_alloc_params(int channel,
int nprobes, int *out_params_size);
static bool check_dev_role_integrity(struct bcm_cfg80211 *cfg, u32 dev_role);
#ifdef WL_CFG80211_ACL
/* ACL */
static int wl_cfg80211_set_mac_acl(struct wiphy *wiphy, struct net_device *cfgdev,
const struct cfg80211_acl_data *acl);
#endif /* WL_CFG80211_ACL */
static void wl_send_event(struct net_device *dev, uint32 event_type, uint32 status, uint32 reason);
/*
* Some external functions, TODO: move them to dhd_linux.h
*/
int dhd_add_monitor(char *name, struct net_device **new_ndev);
int dhd_del_monitor(struct net_device *ndev);
int dhd_monitor_init(void *dhd_pub);
int dhd_monitor_uninit(void);
int dhd_start_xmit(struct sk_buff *skb, struct net_device *net);
#ifdef ROAM_CHANNEL_CACHE
void init_roam(int ioctl_ver);
void reset_roam_cache(void);
void add_roam_cache(wl_bss_info_t *bi);
int get_roam_channel_list(int target_chan,
chanspec_t *channels, const wlc_ssid_t *ssid, int ioctl_ver);
void print_roam_cache(void);
void set_roam_band(int band);
void update_roam_cache(struct bcm_cfg80211 *cfg, int ioctl_ver);
#define MAX_ROAM_CACHE_NUM 100
#endif /* ROAM_CHANNEL_CACHE */
static int wl_cfg80211_delayed_roam(struct bcm_cfg80211 *cfg, struct net_device *ndev,
const struct ether_addr *bssid);
static s32 __wl_update_wiphybands(struct bcm_cfg80211 *cfg, bool notify);
static int bw2cap[] = { 0, 0, WLC_BW_CAP_20MHZ, WLC_BW_CAP_40MHZ, WLC_BW_CAP_80MHZ,
WLC_BW_CAP_160MHZ, WLC_BW_CAP_160MHZ };
#define RETURN_EIO_IF_NOT_UP(wlpriv) \
do { \
struct net_device *checkSysUpNDev = bcmcfg_to_prmry_ndev(wlpriv); \
if (unlikely(!wl_get_drv_status(wlpriv, READY, checkSysUpNDev))) { \
WL_INFORM(("device is not ready\n")); \
return -EIO; \
} \
} while (0)
#ifdef RSSI_OFFSET
static s32 wl_rssi_offset(s32 rssi)
{
rssi += RSSI_OFFSET;
if (rssi > 0)
rssi = 0;
return rssi;
}
#else
#define wl_rssi_offset(x) x
#endif
#define IS_WPA_AKM(akm) ((akm) == RSN_AKM_NONE || \
(akm) == RSN_AKM_UNSPECIFIED || \
(akm) == RSN_AKM_PSK)
extern int dhd_wait_pend8021x(struct net_device *dev);
#ifdef PROP_TXSTATUS_VSDB
extern int disable_proptx;
#endif /* PROP_TXSTATUS_VSDB */
#if (WL_DBG_LEVEL > 0)
#define WL_DBG_ESTR_MAX 50
static s8 wl_dbg_estr[][WL_DBG_ESTR_MAX] = {
"SET_SSID", "JOIN", "START", "AUTH", "AUTH_IND",
"DEAUTH", "DEAUTH_IND", "ASSOC", "ASSOC_IND", "REASSOC",
"REASSOC_IND", "DISASSOC", "DISASSOC_IND", "QUIET_START", "QUIET_END",
"BEACON_RX", "LINK", "MIC_ERROR", "NDIS_LINK", "ROAM",
"TXFAIL", "PMKID_CACHE", "RETROGRADE_TSF", "PRUNE", "AUTOAUTH",
"EAPOL_MSG", "SCAN_COMPLETE", "ADDTS_IND", "DELTS_IND", "BCNSENT_IND",
"BCNRX_MSG", "BCNLOST_MSG", "ROAM_PREP", "PFN_NET_FOUND",
"PFN_NET_LOST",
"RESET_COMPLETE", "JOIN_START", "ROAM_START", "ASSOC_START",
"IBSS_ASSOC",
"RADIO", "PSM_WATCHDOG", "WLC_E_CCX_ASSOC_START", "WLC_E_CCX_ASSOC_ABORT",
"PROBREQ_MSG",
"SCAN_CONFIRM_IND", "PSK_SUP", "COUNTRY_CODE_CHANGED",
"EXCEEDED_MEDIUM_TIME", "ICV_ERROR",
"UNICAST_DECODE_ERROR", "MULTICAST_DECODE_ERROR", "TRACE",
"WLC_E_BTA_HCI_EVENT", "IF", "WLC_E_P2P_DISC_LISTEN_COMPLETE",
"RSSI", "PFN_SCAN_COMPLETE", "WLC_E_EXTLOG_MSG",
"ACTION_FRAME", "ACTION_FRAME_COMPLETE", "WLC_E_PRE_ASSOC_IND",
"WLC_E_PRE_REASSOC_IND", "WLC_E_CHANNEL_ADOPTED", "WLC_E_AP_STARTED",
"WLC_E_DFS_AP_STOP", "WLC_E_DFS_AP_RESUME", "WLC_E_WAI_STA_EVENT",
"WLC_E_WAI_MSG", "WLC_E_ESCAN_RESULT", "WLC_E_ACTION_FRAME_OFF_CHAN_COMPLETE",
"WLC_E_PROBRESP_MSG", "WLC_E_P2P_PROBREQ_MSG", "WLC_E_DCS_REQUEST", "WLC_E_FIFO_CREDIT_MAP",
"WLC_E_ACTION_FRAME_RX", "WLC_E_WAKE_EVENT", "WLC_E_RM_COMPLETE"
};
#endif /* WL_DBG_LEVEL */
#define CHAN2G(_channel, _freq, _flags) { \
.band = IEEE80211_BAND_2GHZ, \
.center_freq = (_freq), \
.hw_value = (_channel), \
.flags = (_flags), \
.max_antenna_gain = 0, \
.max_power = 30, \
}
#define CHAN5G(_channel, _flags) { \
.band = IEEE80211_BAND_5GHZ, \
.center_freq = 5000 + (5 * (_channel)), \
.hw_value = (_channel), \
.flags = (_flags), \
.max_antenna_gain = 0, \
.max_power = 30, \
}
#define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
#define RATETAB_ENT(_rateid, _flags) \
{ \
.bitrate = RATE_TO_BASE100KBPS(_rateid), \
.hw_value = (_rateid), \
.flags = (_flags), \
}
static struct ieee80211_rate __wl_rates[] = {
RATETAB_ENT(DOT11_RATE_1M, 0),
RATETAB_ENT(DOT11_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
RATETAB_ENT(DOT11_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
RATETAB_ENT(DOT11_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
RATETAB_ENT(DOT11_RATE_6M, 0),
RATETAB_ENT(DOT11_RATE_9M, 0),
RATETAB_ENT(DOT11_RATE_12M, 0),
RATETAB_ENT(DOT11_RATE_18M, 0),
RATETAB_ENT(DOT11_RATE_24M, 0),
RATETAB_ENT(DOT11_RATE_36M, 0),
RATETAB_ENT(DOT11_RATE_48M, 0),
RATETAB_ENT(DOT11_RATE_54M, 0)
};
#define wl_a_rates (__wl_rates + 4)
#define wl_a_rates_size 8
#define wl_g_rates (__wl_rates + 0)
#define wl_g_rates_size 12
static struct ieee80211_channel __wl_2ghz_channels[] = {
CHAN2G(1, 2412, 0),
CHAN2G(2, 2417, 0),
CHAN2G(3, 2422, 0),
CHAN2G(4, 2427, 0),
CHAN2G(5, 2432, 0),
CHAN2G(6, 2437, 0),
CHAN2G(7, 2442, 0),
CHAN2G(8, 2447, 0),
CHAN2G(9, 2452, 0),
CHAN2G(10, 2457, 0),
CHAN2G(11, 2462, 0),
CHAN2G(12, 2467, 0),
CHAN2G(13, 2472, 0),
CHAN2G(14, 2484, 0)
};
static struct ieee80211_channel __wl_5ghz_a_channels[] = {
CHAN5G(34, 0), CHAN5G(36, 0),
CHAN5G(38, 0), CHAN5G(40, 0),
CHAN5G(42, 0), CHAN5G(44, 0),
CHAN5G(46, 0), CHAN5G(48, 0),
CHAN5G(52, 0), CHAN5G(56, 0),
CHAN5G(60, 0), CHAN5G(64, 0),
CHAN5G(100, 0), CHAN5G(104, 0),
CHAN5G(108, 0), CHAN5G(112, 0),
CHAN5G(116, 0), CHAN5G(120, 0),
CHAN5G(124, 0), CHAN5G(128, 0),
CHAN5G(132, 0), CHAN5G(136, 0),
CHAN5G(140, 0), CHAN5G(144, 0),
CHAN5G(149, 0), CHAN5G(153, 0),
CHAN5G(157, 0), CHAN5G(161, 0),
CHAN5G(165, 0)
};
static struct ieee80211_supported_band __wl_band_2ghz = {
.band = IEEE80211_BAND_2GHZ,
.channels = __wl_2ghz_channels,
.n_channels = ARRAY_SIZE(__wl_2ghz_channels),
.bitrates = wl_g_rates,
.n_bitrates = wl_g_rates_size
};
static struct ieee80211_supported_band __wl_band_5ghz_a = {
.band = IEEE80211_BAND_5GHZ,
.channels = __wl_5ghz_a_channels,
.n_channels = ARRAY_SIZE(__wl_5ghz_a_channels),
.bitrates = wl_a_rates,
.n_bitrates = wl_a_rates_size
};
static const u32 __wl_cipher_suites[] = {
WLAN_CIPHER_SUITE_WEP40,
WLAN_CIPHER_SUITE_WEP104,
WLAN_CIPHER_SUITE_TKIP,
WLAN_CIPHER_SUITE_CCMP,
WLAN_CIPHER_SUITE_AES_CMAC,
};
#ifdef WL_SUPPORT_ACS
/*
* The firmware code required for this feature to work is currently under
* BCMINTERNAL flag. In future if this is to enabled we need to bring the
* required firmware code out of the BCMINTERNAL flag.
*/
struct wl_dump_survey {
u32 obss;
u32 ibss;
u32 no_ctg;
u32 no_pckt;
u32 tx;
u32 idle;
};
#endif /* WL_SUPPORT_ACS */
#if defined(USE_DYNAMIC_MAXPKT_RXGLOM)
static int maxrxpktglom = 0;
#endif
/* IOCtl version read from targeted driver */
static int ioctl_version;
#ifdef DEBUGFS_CFG80211
#define S_SUBLOGLEVEL 20
static const struct {
u32 log_level;
char *sublogname;
} sublogname_map[] = {
{WL_DBG_ERR, "ERR"},
{WL_DBG_INFO, "INFO"},
{WL_DBG_DBG, "DBG"},
{WL_DBG_SCAN, "SCAN"},
{WL_DBG_TRACE, "TRACE"},
{WL_DBG_P2P_ACTION, "P2PACTION"}
};
#endif
static void wl_add_remove_pm_enable_work(struct bcm_cfg80211 *cfg, bool add_remove,
enum wl_handler_del_type type)
{
if (cfg == NULL)
return;
if (cfg->pm_enable_work_on) {
if (add_remove) {
schedule_delayed_work(&cfg->pm_enable_work,
msecs_to_jiffies(WL_PM_ENABLE_TIMEOUT));
} else {
cancel_delayed_work_sync(&cfg->pm_enable_work);
switch (type) {
case WL_HANDLER_MAINTAIN:
schedule_delayed_work(&cfg->pm_enable_work,
msecs_to_jiffies(WL_PM_ENABLE_TIMEOUT));
break;
case WL_HANDLER_PEND:
schedule_delayed_work(&cfg->pm_enable_work,
msecs_to_jiffies(WL_PM_ENABLE_TIMEOUT*2));
break;
case WL_HANDLER_DEL:
default:
cfg->pm_enable_work_on = false;
break;
}
}
}
}
/* Return a new chanspec given a legacy chanspec
* Returns INVCHANSPEC on error
*/
static chanspec_t
wl_chspec_from_legacy(chanspec_t legacy_chspec)
{
chanspec_t chspec;
/* get the channel number */
chspec = LCHSPEC_CHANNEL(legacy_chspec);
/* convert the band */
if (LCHSPEC_IS2G(legacy_chspec)) {
chspec |= WL_CHANSPEC_BAND_2G;
} else {
chspec |= WL_CHANSPEC_BAND_5G;
}
/* convert the bw and sideband */
if (LCHSPEC_IS20(legacy_chspec)) {
chspec |= WL_CHANSPEC_BW_20;
} else {
chspec |= WL_CHANSPEC_BW_40;
if (LCHSPEC_CTL_SB(legacy_chspec) == WL_LCHANSPEC_CTL_SB_LOWER) {
chspec |= WL_CHANSPEC_CTL_SB_L;
} else {
chspec |= WL_CHANSPEC_CTL_SB_U;
}
}
if (wf_chspec_malformed(chspec)) {
WL_ERR(("wl_chspec_from_legacy: output chanspec (0x%04X) malformed\n",
chspec));
return INVCHANSPEC;
}
return chspec;
}
/* Return a legacy chanspec given a new chanspec
* Returns INVCHANSPEC on error
*/
static chanspec_t
wl_chspec_to_legacy(chanspec_t chspec)
{
chanspec_t lchspec;
if (wf_chspec_malformed(chspec)) {
WL_ERR(("wl_chspec_to_legacy: input chanspec (0x%04X) malformed\n",
chspec));
return INVCHANSPEC;
}
/* get the channel number */
lchspec = CHSPEC_CHANNEL(chspec);
/* convert the band */
if (CHSPEC_IS2G(chspec)) {
lchspec |= WL_LCHANSPEC_BAND_2G;
} else {
lchspec |= WL_LCHANSPEC_BAND_5G;
}
/* convert the bw and sideband */
if (CHSPEC_IS20(chspec)) {
lchspec |= WL_LCHANSPEC_BW_20;
lchspec |= WL_LCHANSPEC_CTL_SB_NONE;
} else if (CHSPEC_IS40(chspec)) {
lchspec |= WL_LCHANSPEC_BW_40;
if (CHSPEC_CTL_SB(chspec) == WL_CHANSPEC_CTL_SB_L) {
lchspec |= WL_LCHANSPEC_CTL_SB_LOWER;
} else {
lchspec |= WL_LCHANSPEC_CTL_SB_UPPER;
}
} else {
/* cannot express the bandwidth */
char chanbuf[CHANSPEC_STR_LEN];
WL_ERR((
"wl_chspec_to_legacy: unable to convert chanspec %s (0x%04X) "
"to pre-11ac format\n",
wf_chspec_ntoa(chspec, chanbuf), chspec));
return INVCHANSPEC;
}
return lchspec;
}
/* given a chanspec value, do the endian and chanspec version conversion to
* a chanspec_t value
* Returns INVCHANSPEC on error
*/
static chanspec_t
wl_chspec_host_to_driver(chanspec_t chanspec)
{
if (ioctl_version == 1) {
chanspec = wl_chspec_to_legacy(chanspec);
if (chanspec == INVCHANSPEC) {
return chanspec;
}
}
chanspec = htodchanspec(chanspec);
return chanspec;
}
/* given a channel value, do the endian and chanspec version conversion to
* a chanspec_t value
* Returns INVCHANSPEC on error
*/
chanspec_t
wl_ch_host_to_driver(u16 channel)
{
chanspec_t chanspec;
chanspec = channel & WL_CHANSPEC_CHAN_MASK;
if (channel <= CH_MAX_2G_CHANNEL)
chanspec |= WL_CHANSPEC_BAND_2G;
else
chanspec |= WL_CHANSPEC_BAND_5G;
chanspec |= WL_CHANSPEC_BW_20;
chanspec |= WL_CHANSPEC_CTL_SB_NONE;
return wl_chspec_host_to_driver(chanspec);
}
/* given a chanspec value from the driver, do the endian and chanspec version conversion to
* a chanspec_t value
* Returns INVCHANSPEC on error
*/
static chanspec_t
wl_chspec_driver_to_host(chanspec_t chanspec)
{
chanspec = dtohchanspec(chanspec);
if (ioctl_version == 1) {
chanspec = wl_chspec_from_legacy(chanspec);
}
return chanspec;
}
/*
* convert ASCII string to MAC address (colon-delimited format)
* eg: 00:11:22:33:44:55
*/
int
wl_cfg80211_ether_atoe(const char *a, struct ether_addr *n)
{
char *c = NULL;
int count = 0;
memset(n, 0, ETHER_ADDR_LEN);
for (;;) {
n->octet[count++] = (uint8)simple_strtoul(a, &c, 16);
if (!*c++ || count == ETHER_ADDR_LEN)
break;
a = c;
}
return (count == ETHER_ADDR_LEN);
}
/* convert hex string buffer to binary */
int
wl_cfg80211_hex_str_to_bin(unsigned char *data, int dlen, char *str)
{
int count, slen;
int hvalue;
char tmp[3] = {0};
char *ptr = str, *endp = NULL;
if (!data || !str || !dlen) {
WL_DBG((" passed buffer is empty \n"));
return 0;
}
slen = strlen(str);
if (dlen * 2 < slen) {
WL_DBG((" destination buffer too short \n"));
return 0;
}
if (slen % 2) {
WL_DBG((" source buffer is of odd length \n"));
return 0;
}
for (count = 0; count < slen; count += 2) {
memcpy(tmp, ptr, 2);
hvalue = simple_strtol(tmp, &endp, 16);
if (*endp != '\0') {
WL_DBG((" non hexadecimal character encountered \n"));
return 0;
}
*data++ = (unsigned char)hvalue;
ptr += 2;
}
return (slen / 2);
}
/* There isn't a lot of sense in it, but you can transmit anything you like */
static const struct ieee80211_txrx_stypes
wl_cfg80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
[NL80211_IFTYPE_ADHOC] = {
.tx = 0xffff,
.rx = BIT(IEEE80211_STYPE_ACTION >> 4)
},
[NL80211_IFTYPE_STATION] = {
.tx = 0xffff,
.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
},
[NL80211_IFTYPE_AP] = {
.tx = 0xffff,
.rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
BIT(IEEE80211_STYPE_DISASSOC >> 4) |
BIT(IEEE80211_STYPE_AUTH >> 4) |
BIT(IEEE80211_STYPE_DEAUTH >> 4) |
BIT(IEEE80211_STYPE_ACTION >> 4)
},
[NL80211_IFTYPE_AP_VLAN] = {
/* copy AP */
.tx = 0xffff,
.rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
BIT(IEEE80211_STYPE_DISASSOC >> 4) |
BIT(IEEE80211_STYPE_AUTH >> 4) |
BIT(IEEE80211_STYPE_DEAUTH >> 4) |
BIT(IEEE80211_STYPE_ACTION >> 4)
},
[NL80211_IFTYPE_P2P_CLIENT] = {
.tx = 0xffff,
.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
},
[NL80211_IFTYPE_P2P_GO] = {
.tx = 0xffff,
.rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
BIT(IEEE80211_STYPE_DISASSOC >> 4) |
BIT(IEEE80211_STYPE_AUTH >> 4) |
BIT(IEEE80211_STYPE_DEAUTH >> 4) |
BIT(IEEE80211_STYPE_ACTION >> 4)
},
#if defined(WL_CFG80211_P2P_DEV_IF)
[NL80211_IFTYPE_P2P_DEVICE] = {
.tx = 0xffff,
.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
},
#endif /* WL_CFG80211_P2P_DEV_IF */
};
static void swap_key_from_BE(struct wl_wsec_key *key)
{
key->index = htod32(key->index);
key->len = htod32(key->len);
key->algo = htod32(key->algo);
key->flags = htod32(key->flags);
key->rxiv.hi = htod32(key->rxiv.hi);
key->rxiv.lo = htod16(key->rxiv.lo);
key->iv_initialized = htod32(key->iv_initialized);
}
static void swap_key_to_BE(struct wl_wsec_key *key)
{
key->index = dtoh32(key->index);
key->len = dtoh32(key->len);
key->algo = dtoh32(key->algo);
key->flags = dtoh32(key->flags);
key->rxiv.hi = dtoh32(key->rxiv.hi);
key->rxiv.lo = dtoh16(key->rxiv.lo);
key->iv_initialized = dtoh32(key->iv_initialized);
}
/* Dump the contents of the encoded wps ie buffer and get pbc value */
static void
wl_validate_wps_ie(char *wps_ie, s32 wps_ie_len, bool *pbc)
{
#define WPS_IE_FIXED_LEN 6
u16 len;
u8 *subel = NULL;
u16 subelt_id;
u16 subelt_len;
u16 val;
u8 *valptr = (uint8*) &val;
if (wps_ie == NULL || wps_ie_len < WPS_IE_FIXED_LEN) {
WL_ERR(("invalid argument : NULL\n"));
return;
}
len = (u16)wps_ie[TLV_LEN_OFF];
if (len > wps_ie_len) {
WL_ERR(("invalid length len %d, wps ie len %d\n", len, wps_ie_len));
return;
}
WL_DBG(("wps_ie len=%d\n", len));
len -= 4; /* for the WPS IE's OUI, oui_type fields */
subel = wps_ie + WPS_IE_FIXED_LEN;
while (len >= 4) { /* must have attr id, attr len fields */
valptr[0] = *subel++;
valptr[1] = *subel++;
subelt_id = HTON16(val);
valptr[0] = *subel++;
valptr[1] = *subel++;
subelt_len = HTON16(val);
len -= 4; /* for the attr id, attr len fields */
len -= subelt_len; /* for the remaining fields in this attribute */
WL_DBG((" subel=%p, subelt_id=0x%x subelt_len=%u\n",
subel, subelt_id, subelt_len));
if (subelt_id == WPS_ID_VERSION) {
WL_DBG((" attr WPS_ID_VERSION: %u\n", *subel));
} else if (subelt_id == WPS_ID_REQ_TYPE) {
WL_DBG((" attr WPS_ID_REQ_TYPE: %u\n", *subel));
} else if (subelt_id == WPS_ID_CONFIG_METHODS) {
valptr[0] = *subel;
valptr[1] = *(subel + 1);
WL_DBG((" attr WPS_ID_CONFIG_METHODS: %x\n", HTON16(val)));
} else if (subelt_id == WPS_ID_DEVICE_NAME) {
char devname[100];
memcpy(devname, subel, subelt_len);
devname[subelt_len] = '\0';
WL_DBG((" attr WPS_ID_DEVICE_NAME: %s (len %u)\n",
devname, subelt_len));
} else if (subelt_id == WPS_ID_DEVICE_PWD_ID) {
valptr[0] = *subel;
valptr[1] = *(subel + 1);
WL_DBG((" attr WPS_ID_DEVICE_PWD_ID: %u\n", HTON16(val)));
*pbc = (HTON16(val) == DEV_PW_PUSHBUTTON) ? true : false;
} else if (subelt_id == WPS_ID_PRIM_DEV_TYPE) {
valptr[0] = *subel;
valptr[1] = *(subel + 1);
WL_DBG((" attr WPS_ID_PRIM_DEV_TYPE: cat=%u \n", HTON16(val)));
valptr[0] = *(subel + 6);
valptr[1] = *(subel + 7);
WL_DBG((" attr WPS_ID_PRIM_DEV_TYPE: subcat=%u\n", HTON16(val)));
} else if (subelt_id == WPS_ID_REQ_DEV_TYPE) {
valptr[0] = *subel;
valptr[1] = *(subel + 1);
WL_DBG((" attr WPS_ID_REQ_DEV_TYPE: cat=%u\n", HTON16(val)));
valptr[0] = *(subel + 6);
valptr[1] = *(subel + 7);
WL_DBG((" attr WPS_ID_REQ_DEV_TYPE: subcat=%u\n", HTON16(val)));
} else if (subelt_id == WPS_ID_SELECTED_REGISTRAR_CONFIG_METHODS) {
valptr[0] = *subel;
valptr[1] = *(subel + 1);
WL_DBG((" attr WPS_ID_SELECTED_REGISTRAR_CONFIG_METHODS"
": cat=%u\n", HTON16(val)));
} else {
WL_DBG((" unknown attr 0x%x\n", subelt_id));
}
subel += subelt_len;
}
}
s32 wl_set_tx_power(struct net_device *dev,
enum nl80211_tx_power_setting type, s32 dbm)
{
s32 err = 0;
s32 disable = 0;
s32 txpwrqdbm;
struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
/* Make sure radio is off or on as far as software is concerned */
disable = WL_RADIO_SW_DISABLE << 16;
disable = htod32(disable);
err = wldev_ioctl(dev, WLC_SET_RADIO, &disable, sizeof(disable), true);
if (unlikely(err)) {
WL_ERR(("WLC_SET_RADIO error (%d)\n", err));
return err;
}
if (dbm > 0xffff)
dbm = 0xffff;
txpwrqdbm = dbm * 4;
err = wldev_iovar_setbuf_bsscfg(dev, "qtxpower", (void *)&txpwrqdbm,
sizeof(txpwrqdbm), cfg->ioctl_buf, WLC_IOCTL_SMLEN, 0,
&cfg->ioctl_buf_sync);
if (unlikely(err))
WL_ERR(("qtxpower error (%d)\n", err));
else
WL_ERR(("dBm=%d, txpwrqdbm=0x%x\n", dbm, txpwrqdbm));
return err;
}
s32 wl_get_tx_power(struct net_device *dev, s32 *dbm)
{
s32 err = 0;
s32 txpwrdbm;
struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
err = wldev_iovar_getbuf_bsscfg(dev, "qtxpower",
NULL, 0, cfg->ioctl_buf, WLC_IOCTL_SMLEN, 0, &cfg->ioctl_buf_sync);
if (unlikely(err)) {
WL_ERR(("error (%d)\n", err));
return err;
}
memcpy(&txpwrdbm, cfg->ioctl_buf, sizeof(txpwrdbm));
txpwrdbm = dtoh32(txpwrdbm);
*dbm = (txpwrdbm & ~WL_TXPWR_OVERRIDE) / 4;
WL_INFORM(("dBm=%d, txpwrdbm=0x%x\n", *dbm, txpwrdbm));
return err;
}
static chanspec_t wl_cfg80211_get_shared_freq(struct wiphy *wiphy)
{
chanspec_t chspec;
int err = 0;
struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
struct net_device *dev = bcmcfg_to_prmry_ndev(cfg);
struct ether_addr bssid;
struct wl_bss_info *bss = NULL;
if ((err = wldev_ioctl(dev, WLC_GET_BSSID, &bssid, sizeof(bssid), false))) {
/* STA interface is not associated. So start the new interface on a temp
* channel . Later proper channel will be applied by the above framework
* via set_channel (cfg80211 API).
*/
WL_DBG(("Not associated. Return a temp channel. \n"));
return wl_ch_host_to_driver(WL_P2P_TEMP_CHAN);
}
*(u32 *) cfg->extra_buf = htod32(WL_EXTRA_BUF_MAX);
if ((err = wldev_ioctl(dev, WLC_GET_BSS_INFO, cfg->extra_buf,
WL_EXTRA_BUF_MAX, false))) {
WL_ERR(("Failed to get associated bss info, use temp channel \n"));
chspec = wl_ch_host_to_driver(WL_P2P_TEMP_CHAN);
}
else {
bss = (struct wl_bss_info *) (cfg->extra_buf + 4);
chspec = bss->chanspec;
WL_DBG(("Valid BSS Found. chanspec:%d \n", chspec));
}
return chspec;
}
static bcm_struct_cfgdev *
wl_cfg80211_add_monitor_if(char *name)
{
#if defined(WL_ENABLE_P2P_IF) || defined(WL_CFG80211_P2P_DEV_IF)
WL_INFORM(("wl_cfg80211_add_monitor_if: No more support monitor interface\n"));
return ERR_PTR(-EOPNOTSUPP);
#else
struct net_device* ndev = NULL;
dhd_add_monitor(name, &ndev);
WL_INFORM(("wl_cfg80211_add_monitor_if net device returned: 0x%p\n", ndev));
return ndev_to_cfgdev(ndev);
#endif /* WL_ENABLE_P2P_IF || WL_CFG80211_P2P_DEV_IF */
}
static bcm_struct_cfgdev *
wl_cfg80211_add_virtual_iface(struct wiphy *wiphy,
#if defined(WL_CFG80211_P2P_DEV_IF)
const char *name,
#else
char *name,
#endif /* WL_CFG80211_P2P_DEV_IF */
enum nl80211_iftype type, u32 *flags,
struct vif_params *params)
{
s32 err;
s32 timeout = -1;
s32 wlif_type = -1;
s32 mode = 0;
s32 val = 0;
s32 dhd_mode = 0;
chanspec_t chspec;
struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
struct net_device *primary_ndev;
struct net_device *new_ndev;
struct ether_addr primary_mac;
#ifdef PROP_TXSTATUS_VSDB
#if defined(BCMSDIO)
s32 up = 1;
dhd_pub_t *dhd;
bool enabled;
#endif
#endif /* PROP_TXSTATUS_VSDB */
if (!cfg)
return ERR_PTR(-EINVAL);
#ifdef PROP_TXSTATUS_VSDB
#if defined(BCMSDIO)
dhd = (dhd_pub_t *)(cfg->pub);
#endif
#endif /* PROP_TXSTATUS_VSDB */
/* Use primary I/F for sending cmds down to firmware */
primary_ndev = bcmcfg_to_prmry_ndev(cfg);
if (unlikely(!wl_get_drv_status(cfg, READY, primary_ndev))) {
WL_ERR(("device is not ready\n"));
return ERR_PTR(-ENODEV);
}
WL_DBG(("if name: %s, type: %d\n", name, type));
switch (type) {
case NL80211_IFTYPE_ADHOC:
return bcm_cfg80211_add_ibss_if(wiphy, (char *)name);
case NL80211_IFTYPE_AP_VLAN:
case NL80211_IFTYPE_WDS:
case NL80211_IFTYPE_MESH_POINT:
WL_ERR(("Unsupported interface type\n"));
mode = WL_MODE_IBSS;
return NULL;
case NL80211_IFTYPE_MONITOR:
return wl_cfg80211_add_monitor_if((char *)name);
#if defined(WL_CFG80211_P2P_DEV_IF)
case NL80211_IFTYPE_P2P_DEVICE:
return wl_cfgp2p_add_p2p_disc_if(cfg);
#endif /* WL_CFG80211_P2P_DEV_IF */
case NL80211_IFTYPE_STATION:
#ifdef DUAL_STA
if (cfg->ibss_cfgdev) {
WL_ERR(("AIBSS is already operational. "
" AIBSS & DUALSTA can't be used together \n"));
return NULL;
}
if (!name) {
WL_ERR(("Interface name not provided \n"));
return NULL;
}
return wl_cfg80211_create_iface(cfg->wdev->wiphy,
NL80211_IFTYPE_STATION, NULL, name);
#endif /* DUAL_STA */
case NL80211_IFTYPE_P2P_CLIENT:
wlif_type = WL_P2P_IF_CLIENT;
mode = WL_MODE_BSS;
break;
case NL80211_IFTYPE_P2P_GO:
case NL80211_IFTYPE_AP:
wlif_type = WL_P2P_IF_GO;
mode = WL_MODE_AP;
break;
default:
WL_ERR(("Unsupported interface type\n"));
return NULL;
break;
}
if (!name) {
WL_ERR(("name is NULL\n"));
return NULL;
}
if (wl_cfgp2p_check_enabled(cfg) && (wlif_type != -1)) {
ASSERT(cfg->p2p); /* ensure expectation of p2p initialization */
#ifdef PROP_TXSTATUS_VSDB
#if defined(BCMSDIO)
if (!dhd)
return ERR_PTR(-ENODEV);
#endif
#endif /* PROP_TXSTATUS_VSDB */
if (!cfg->p2p)
return ERR_PTR(-ENODEV);
if (cfg->p2p && !cfg->p2p->on && strstr(name, WL_P2P_INTERFACE_PREFIX)) {
p2p_on(cfg) = true;
wl_cfgp2p_set_firm_p2p(cfg);
wl_cfgp2p_init_discovery(cfg);
get_primary_mac(cfg, &primary_mac);
wl_cfgp2p_generate_bss_mac(&primary_mac,
&cfg->p2p->dev_addr, &cfg->p2p->int_addr);
}
memset(cfg->p2p->vir_ifname, 0, IFNAMSIZ);
strncpy(cfg->p2p->vir_ifname, name, IFNAMSIZ - 1);
wl_cfg80211_scan_abort(cfg);
#ifdef PROP_TXSTATUS_VSDB
#if defined(BCMSDIO)
if (!cfg->wlfc_on && !disable_proptx) {
dhd_wlfc_get_enable(dhd, &enabled);
if (!enabled && dhd->op_mode != DHD_FLAG_HOSTAP_MODE &&
dhd->op_mode != DHD_FLAG_IBSS_MODE) {
dhd_wlfc_init(dhd);
err = wldev_ioctl(primary_ndev, WLC_UP, &up, sizeof(s32), true);
if (err < 0)
WL_ERR(("WLC_UP return err:%d\n", err));
}
cfg->wlfc_on = true;
}
#endif
#endif /* PROP_TXSTATUS_VSDB */
/* In concurrency case, STA may be already associated in a particular channel.
* so retrieve the current channel of primary interface and then start the virtual
* interface on that.
*/
chspec = wl_cfg80211_get_shared_freq(wiphy);
/* For P2P mode, use P2P-specific driver features to create the
* bss: "cfg p2p_ifadd"
*/
wl_set_p2p_status(cfg, IF_ADDING);
memset(&cfg->if_event_info, 0, sizeof(cfg->if_event_info));
if (wlif_type == WL_P2P_IF_GO)
wldev_iovar_setint(primary_ndev, "mpc", 0);
err = wl_cfgp2p_ifadd(cfg, &cfg->p2p->int_addr, htod32(wlif_type), chspec);
if (unlikely(err)) {
wl_clr_p2p_status(cfg, IF_ADDING);
WL_ERR((" virtual iface add failed (%d) \n", err));
return ERR_PTR(-ENOMEM);
}
timeout = wait_event_interruptible_timeout(cfg->netif_change_event,
(wl_get_p2p_status(cfg, IF_ADDING) == false),
msecs_to_jiffies(MAX_WAIT_TIME));
if (timeout > 0 && !wl_get_p2p_status(cfg, IF_ADDING) && cfg->if_event_info.valid) {
struct wireless_dev *vwdev;
int pm_mode = PM_ENABLE;
wl_if_event_info *event = &cfg->if_event_info;
/* IF_ADD event has come back, we can proceed to to register
* the new interface now, use the interface name provided by caller (thus
* ignore the one from wlc)
*/
strncpy(cfg->if_event_info.name, name, IFNAMSIZ - 1);
new_ndev = wl_cfg80211_allocate_if(cfg, event->ifidx, cfg->p2p->vir_ifname,
event->mac, event->bssidx);
if (new_ndev == NULL)
goto fail;
wl_to_p2p_bss_ndev(cfg, P2PAPI_BSSCFG_CONNECTION) = new_ndev;
wl_to_p2p_bss_bssidx(cfg, P2PAPI_BSSCFG_CONNECTION) = event->bssidx;
vwdev = kzalloc(sizeof(*vwdev), GFP_KERNEL);
if (unlikely(!vwdev)) {
WL_ERR(("Could not allocate wireless device\n"));
goto fail;
}
vwdev->wiphy = cfg->wdev->wiphy;
WL_INFORM(("virtual interface(%s) is created\n", cfg->p2p->vir_ifname));
vwdev->iftype = type;
vwdev->netdev = new_ndev;
new_ndev->ieee80211_ptr = vwdev;
SET_NETDEV_DEV(new_ndev, wiphy_dev(vwdev->wiphy));
wl_set_drv_status(cfg, READY, new_ndev);
cfg->p2p->vif_created = true;
wl_set_mode_by_netdev(cfg, new_ndev, mode);
if (wl_cfg80211_register_if(cfg, event->ifidx, new_ndev) != BCME_OK) {
wl_cfg80211_remove_if(cfg, event->ifidx, new_ndev);
goto fail;
}
wl_alloc_netinfo(cfg, new_ndev, vwdev, mode, pm_mode);
val = 1;
/* Disable firmware roaming for P2P interface */
wldev_iovar_setint(new_ndev, "roam_off", val);
if (mode != WL_MODE_AP)
wldev_iovar_setint(new_ndev, "buf_key_b4_m4", 1);
WL_ERR((" virtual interface(%s) is "
"created net attach done\n", cfg->p2p->vir_ifname));
if (mode == WL_MODE_AP)
wl_set_drv_status(cfg, CONNECTED, new_ndev);
if (type == NL80211_IFTYPE_P2P_CLIENT)
dhd_mode = DHD_FLAG_P2P_GC_MODE;
else if (type == NL80211_IFTYPE_P2P_GO)
dhd_mode = DHD_FLAG_P2P_GO_MODE;
DNGL_FUNC(dhd_cfg80211_set_p2p_info, (cfg, dhd_mode));
/* reinitialize completion to clear previous count */
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0))
INIT_COMPLETION(cfg->iface_disable);
#else
init_completion(&cfg->iface_disable);
#endif
return ndev_to_cfgdev(new_ndev);
} else {
wl_clr_p2p_status(cfg, IF_ADDING);
WL_ERR((" virtual interface(%s) is not created \n", cfg->p2p->vir_ifname));
memset(cfg->p2p->vir_ifname, '\0', IFNAMSIZ);
cfg->p2p->vif_created = false;
#ifdef PROP_TXSTATUS_VSDB
#if defined(BCMSDIO)
dhd_wlfc_get_enable(dhd, &enabled);
if (enabled && cfg->wlfc_on && dhd->op_mode != DHD_FLAG_HOSTAP_MODE &&
dhd->op_mode != DHD_FLAG_IBSS_MODE) {
dhd_wlfc_deinit(dhd);
cfg->wlfc_on = false;
}
#endif
#endif /* PROP_TXSTATUS_VSDB */
}
}
fail:
if (wlif_type == WL_P2P_IF_GO)
wldev_iovar_setint(primary_ndev, "mpc", 1);
return ERR_PTR(-ENODEV);
}
static s32
wl_cfg80211_del_virtual_iface(struct wiphy *wiphy, bcm_struct_cfgdev *cfgdev)
{
struct net_device *dev = NULL;
struct ether_addr p2p_mac;
struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
s32 timeout = -1;
s32 ret = 0;
s32 index = -1;
#ifdef CUSTOM_SET_CPUCORE
dhd_pub_t *dhd = (dhd_pub_t *)(cfg->pub);
#endif /* CUSTOM_SET_CPUCORE */
WL_DBG(("Enter\n"));
#ifdef CUSTOM_SET_CPUCORE
dhd->chan_isvht80 &= ~DHD_FLAG_P2P_MODE;
if (!(dhd->chan_isvht80))
dhd_set_cpucore(dhd, FALSE);
#endif /* CUSTOM_SET_CPUCORE */
#if defined(WL_CFG80211_P2P_DEV_IF)
if (cfgdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
return wl_cfgp2p_del_p2p_disc_if(cfgdev, cfg);
}
#endif /* WL_CFG80211_P2P_DEV_IF */
dev = cfgdev_to_wlc_ndev(cfgdev, cfg);
if (cfgdev == cfg->ibss_cfgdev)
return bcm_cfg80211_del_ibss_if(wiphy, cfgdev);
#ifdef DUAL_STA
if (cfgdev == cfg->bss_cfgdev)
return wl_cfg80211_del_iface(wiphy, cfgdev);
#endif /* DUAL_STA */
if (wl_cfgp2p_find_idx(cfg, dev, &index) != BCME_OK) {
WL_ERR(("Find p2p index from ndev(%p) failed\n", dev));
return BCME_ERROR;
}
if (wl_cfgp2p_check_enabled(cfg)) {
memcpy(p2p_mac.octet, cfg->p2p->int_addr.octet, ETHER_ADDR_LEN);
/* Clear GO_NEG_PHASE bit to take care of GO-NEG-FAIL cases
*/
WL_DBG(("P2P: GO_NEG_PHASE status cleared "));
wl_clr_p2p_status(cfg, GO_NEG_PHASE);
if (cfg->p2p->vif_created) {
if (wl_get_drv_status(cfg, SCANNING, dev)) {
wl_notify_escan_complete(cfg, dev, true, true);
}
wldev_iovar_setint(dev, "mpc", 1);
/* Delete pm_enable_work */
wl_add_remove_pm_enable_work(cfg, FALSE, WL_HANDLER_DEL);
/* for GC */
if (wl_get_drv_status(cfg, DISCONNECTING, dev) &&
(wl_get_mode_by_netdev(cfg, dev) != WL_MODE_AP)) {
WL_ERR(("Wait for Link Down event for GC !\n"));
wait_for_completion_timeout
(&cfg->iface_disable, msecs_to_jiffies(500));
}
memset(&cfg->if_event_info, 0, sizeof(cfg->if_event_info));
wl_set_p2p_status(cfg, IF_DELETING);
DNGL_FUNC(dhd_cfg80211_clean_p2p_info, (cfg));
/* for GO */
if (wl_get_mode_by_netdev(cfg, dev) == WL_MODE_AP) {
wl_add_remove_eventmsg(dev, WLC_E_PROBREQ_MSG, false);
/* disable interface before bsscfg free */
ret = wl_cfgp2p_ifdisable(cfg, &p2p_mac);
/* if fw doesn't support "ifdis",
do not wait for link down of ap mode
*/
if (ret == 0) {
WL_ERR(("Wait for Link Down event for GO !!!\n"));
wait_for_completion_timeout(&cfg->iface_disable,
msecs_to_jiffies(500));
} else if (ret != BCME_UNSUPPORTED) {
msleep(300);
}
}
wl_cfgp2p_clear_management_ie(cfg, index);
if (wl_get_mode_by_netdev(cfg, dev) != WL_MODE_AP)
wldev_iovar_setint(dev, "buf_key_b4_m4", 0);
/* delete interface after link down */
ret = wl_cfgp2p_ifdel(cfg, &p2p_mac);
if (ret != BCME_OK) {
struct net_device *ndev = bcmcfg_to_prmry_ndev(cfg);
WL_ERR(("p2p_ifdel failed, error %d, sent HANG event to %s\n",
ret, ndev->name));
#if defined(BCMDONGLEHOST) && defined(OEM_ANDROID)
net_os_send_hang_message(ndev);
#endif
} else {
/* Wait for IF_DEL operation to be finished */
timeout = wait_event_interruptible_timeout(cfg->netif_change_event,
(wl_get_p2p_status(cfg, IF_DELETING) == false),
msecs_to_jiffies(MAX_WAIT_TIME));
if (timeout > 0 && !wl_get_p2p_status(cfg, IF_DELETING) &&
cfg->if_event_info.valid) {
WL_DBG(("IFDEL operation done\n"));
wl_cfg80211_handle_ifdel(cfg, &cfg->if_event_info, dev);
} else {
WL_ERR(("IFDEL didn't complete properly\n"));
}
}
ret = dhd_del_monitor(dev);
if (wl_get_mode_by_netdev(cfg, dev) == WL_MODE_AP) {
DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_CANCEL((dhd_pub_t *)(cfg->pub));
}
}
}
return ret;
}
static s32
wl_cfg80211_change_virtual_iface(struct wiphy *wiphy, struct net_device *ndev,
enum nl80211_iftype type, u32 *flags,
struct vif_params *params)
{
s32 ap = 0;
s32 infra = 0;
s32 ibss = 0;
s32 wlif_type;
s32 mode = 0;
s32 err = BCME_OK;
chanspec_t chspec;
struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
dhd_pub_t *dhd = (dhd_pub_t *)(cfg->pub);
WL_DBG(("Enter type %d\n", type));
switch (type) {
case NL80211_IFTYPE_MONITOR:
case NL80211_IFTYPE_WDS:
case NL80211_IFTYPE_MESH_POINT:
ap = 1;
WL_ERR(("type (%d) : currently we do not support this type\n",
type));
break;
case NL80211_IFTYPE_ADHOC:
mode = WL_MODE_IBSS;
ibss = 1;
break;
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_P2P_CLIENT:
mode = WL_MODE_BSS;
infra = 1;
break;
case NL80211_IFTYPE_AP:
case NL80211_IFTYPE_AP_VLAN:
case NL80211_IFTYPE_P2P_GO:
mode = WL_MODE_AP;
ap = 1;
break;
default:
return -EINVAL;
}
if (!dhd)
return -EINVAL;
if (ap) {
wl_set_mode_by_netdev(cfg, ndev, mode);
if (wl_cfgp2p_check_enabled(cfg) && cfg->p2p->vif_created) {
WL_DBG(("p2p_vif_created (%d) p2p_on (%d)\n", cfg->p2p->vif_created,
p2p_on(cfg)));
wldev_iovar_setint(ndev, "mpc", 0);
wl_notify_escan_complete(cfg, ndev, true, true);
/* In concurrency case, STA may be already associated in a particular
* channel. so retrieve the current channel of primary interface and
* then start the virtual interface on that.
*/
chspec = wl_cfg80211_get_shared_freq(wiphy);
wlif_type = WL_P2P_IF_GO;
WL_ERR(("%s : ap (%d), infra (%d), iftype: (%d)\n",
ndev->name, ap, infra, type));
wl_set_p2p_status(cfg, IF_CHANGING);
wl_clr_p2p_status(cfg, IF_CHANGED);
wl_cfgp2p_ifchange(cfg, &cfg->p2p->int_addr, htod32(wlif_type), chspec);
wait_event_interruptible_timeout(cfg->netif_change_event,
(wl_get_p2p_status(cfg, IF_CHANGED) == true),
msecs_to_jiffies(MAX_WAIT_TIME));
wl_set_mode_by_netdev(cfg, ndev, mode);
dhd->op_mode &= ~DHD_FLAG_P2P_GC_MODE;
dhd->op_mode |= DHD_FLAG_P2P_GO_MODE;
wl_clr_p2p_status(cfg, IF_CHANGING);
wl_clr_p2p_status(cfg, IF_CHANGED);
if (mode == WL_MODE_AP)
wl_set_drv_status(cfg, CONNECTED, ndev);
} else if (ndev == bcmcfg_to_prmry_ndev(cfg) &&
!wl_get_drv_status(cfg, AP_CREATED, ndev)) {
wl_set_drv_status(cfg, AP_CREATING, ndev);
if (!cfg->ap_info &&
!(cfg->ap_info = kzalloc(sizeof(struct ap_info), GFP_KERNEL))) {
WL_ERR(("struct ap_saved_ie allocation failed\n"));
return -ENOMEM;
}
} else {
WL_ERR(("Cannot change the interface for GO or SOFTAP\n"));
return -EINVAL;
}
} else {
WL_DBG(("Change_virtual_iface for transition from GO/AP to client/STA"));
}
if (ibss) {
infra = 0;
wl_set_mode_by_netdev(cfg, ndev, mode);
err = wldev_ioctl(ndev, WLC_SET_INFRA, &infra, sizeof(s32), true);
if (err < 0) {
WL_ERR(("SET Adhoc error %d\n", err));
return -EINVAL;
}
}
ndev->ieee80211_ptr->iftype = type;
return 0;
}
s32
wl_cfg80211_notify_ifadd(struct net_device *dev, int ifidx, char *name, uint8 *mac, uint8 bssidx)
{
bool ifadd_expected = FALSE;
struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
/* P2P may send WLC_E_IF_ADD and/or WLC_E_IF_CHANGE during IF updating ("p2p_ifupd")
* redirect the IF_ADD event to ifchange as it is not a real "new" interface
*/
if (wl_get_p2p_status(cfg, IF_CHANGING))
return wl_cfg80211_notify_ifchange(dev, ifidx, name, mac, bssidx);
/* Okay, we are expecting IF_ADD (as IF_ADDING is true) */
if (wl_get_p2p_status(cfg, IF_ADDING)) {
ifadd_expected = TRUE;
wl_clr_p2p_status(cfg, IF_ADDING);
} else if (cfg->bss_pending_op) {
ifadd_expected = TRUE;
cfg->bss_pending_op = FALSE;
}
if (ifadd_expected) {
wl_if_event_info *if_event_info = &cfg->if_event_info;
if_event_info->valid = TRUE;
if_event_info->ifidx = ifidx;
if_event_info->bssidx = bssidx;
strncpy(if_event_info->name, name, IFNAMSIZ);
if_event_info->name[IFNAMSIZ] = '\0';
if (mac)
memcpy(if_event_info->mac, mac, ETHER_ADDR_LEN);
wake_up_interruptible(&cfg->netif_change_event);
return BCME_OK;
}
return BCME_ERROR;
}
s32
wl_cfg80211_notify_ifdel(struct net_device *dev, int ifidx, char *name, uint8 *mac, uint8 bssidx)
{
bool ifdel_expected = FALSE;
struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
wl_if_event_info *if_event_info = &cfg->if_event_info;
if (wl_get_p2p_status(cfg, IF_DELETING)) {
ifdel_expected = TRUE;
wl_clr_p2p_status(cfg, IF_DELETING);
} else if (cfg->bss_pending_op) {
ifdel_expected = TRUE;
cfg->bss_pending_op = FALSE;
}
if (ifdel_expected) {
if_event_info->valid = TRUE;
if_event_info->ifidx = ifidx;
if_event_info->bssidx = bssidx;
wake_up_interruptible(&cfg->netif_change_event);
return BCME_OK;
}
return BCME_ERROR;
}
s32
wl_cfg80211_notify_ifchange(struct net_device *dev, int ifidx, char *name, uint8 *mac, uint8 bssidx)
{
struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
if (wl_get_p2p_status(cfg, IF_CHANGING)) {
wl_set_p2p_status(cfg, IF_CHANGED);
wake_up_interruptible(&cfg->netif_change_event);
return BCME_OK;
}
return BCME_ERROR;
}
static s32 wl_cfg80211_handle_ifdel(struct bcm_cfg80211 *cfg, wl_if_event_info *if_event_info,
struct net_device* ndev)
{
s32 type = -1;
s32 bssidx = -1;
#ifdef PROP_TXSTATUS_VSDB
#if defined(BCMSDIO)
dhd_pub_t *dhd = (dhd_pub_t *)(cfg->pub);
bool enabled;
#endif
#endif /* PROP_TXSTATUS_VSDB */
bssidx = if_event_info->bssidx;
if (bssidx != wl_to_p2p_bss_bssidx(cfg, P2PAPI_BSSCFG_CONNECTION)) {
WL_ERR(("got IF_DEL for if %d, not owned by cfg driver\n", bssidx));
return BCME_ERROR;
}
if (p2p_is_on(cfg) && cfg->p2p->vif_created) {
if (cfg->scan_request && (cfg->escan_info.ndev == ndev)) {
/* Abort any pending scan requests */
cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
WL_DBG(("ESCAN COMPLETED\n"));
wl_notify_escan_complete(cfg, cfg->escan_info.ndev, true, false);
}
memset(cfg->p2p->vir_ifname, '\0', IFNAMSIZ);
if (wl_cfgp2p_find_type(cfg, bssidx, &type) != BCME_OK) {
WL_ERR(("Find p2p type from bssidx(%d) failed\n", bssidx));
return BCME_ERROR;
}
wl_clr_drv_status(cfg, CONNECTED, wl_to_p2p_bss_ndev(cfg, type));
wl_to_p2p_bss_ndev(cfg, type) = NULL;
wl_to_p2p_bss_bssidx(cfg, type) = WL_INVALID;
cfg->p2p->vif_created = false;
#ifdef PROP_TXSTATUS_VSDB
#if defined(BCMSDIO)
dhd_wlfc_get_enable(dhd, &enabled);
if (enabled && cfg->wlfc_on && dhd->op_mode != DHD_FLAG_HOSTAP_MODE &&
dhd->op_mode != DHD_FLAG_IBSS_MODE) {
dhd_wlfc_deinit(dhd);
cfg->wlfc_on = false;
}
#endif
#endif /* PROP_TXSTATUS_VSDB */
}
wl_cfg80211_remove_if(cfg, if_event_info->ifidx, ndev);
return BCME_OK;
}
/* Find listen channel */
static s32 wl_find_listen_channel(struct bcm_cfg80211 *cfg,
const u8 *ie, u32 ie_len)
{
wifi_p2p_ie_t *p2p_ie;
u8 *end, *pos;
s32 listen_channel;
pos = (u8 *)ie;
p2p_ie = wl_cfgp2p_find_p2pie(pos, ie_len);
if (p2p_ie == NULL)
return 0;
pos = p2p_ie->subelts;
end = p2p_ie->subelts + (p2p_ie->len - 4);
CFGP2P_DBG((" found p2p ie ! lenth %d \n",
p2p_ie->len));
while (pos < end) {
uint16 attr_len;
if (pos + 2 >= end) {
CFGP2P_DBG((" -- Invalid P2P attribute"));
return 0;
}
attr_len = ((uint16) (((pos + 1)[1] << 8) | (pos + 1)[0]));
if (pos + 3 + attr_len > end) {
CFGP2P_DBG(("P2P: Attribute underflow "
"(len=%u left=%d)",
attr_len, (int) (end - pos - 3)));
return 0;
}
/* if Listen Channel att id is 6 and the vailue is valid,
* return the listen channel
*/
if (pos[0] == 6) {
/* listen channel subel length format
* 1(id) + 2(len) + 3(country) + 1(op. class) + 1(chan num)
*/
listen_channel = pos[1 + 2 + 3 + 1];
if (listen_channel == SOCIAL_CHAN_1 ||
listen_channel == SOCIAL_CHAN_2 ||
listen_channel == SOCIAL_CHAN_3) {
CFGP2P_DBG((" Found my Listen Channel %d \n", listen_channel));
return listen_channel;
}
}
pos += 3 + attr_len;
}
return 0;
}
static void wl_scan_prep(struct bcm_cfg80211 *cfg, struct wl_scan_params *params, struct cfg80211_scan_request *request)
{
u32 n_ssids;
u32 n_channels;
u16 channel;
chanspec_t chanspec;
s32 i = 0, j = 0, offset;
char *ptr;
wlc_ssid_t ssid;
memcpy(&params->bssid, &ether_bcast, ETHER_ADDR_LEN);
params->bss_type = DOT11_BSSTYPE_ANY;
params->scan_type = 0;
params->nprobes = -1;
params->active_time = -1;
params->passive_time = -1;
params->home_time = -1;
params->channel_num = 0;
memset(&params->ssid, 0, sizeof(wlc_ssid_t));
WL_SCAN(("Preparing Scan request\n"));
WL_SCAN(("nprobes=%d\n", params->nprobes));
WL_SCAN(("active_time=%d\n", params->active_time));
WL_SCAN(("passive_time=%d\n", params->passive_time));
WL_SCAN(("home_time=%d\n", params->home_time));
WL_SCAN(("scan_type=%d\n", params->scan_type));
params->nprobes = htod32(params->nprobes);
params->active_time = htod32(params->active_time);
params->passive_time = htod32(params->passive_time);
params->home_time = htod32(params->home_time);
/* if request is null just exit so it will be all channel broadcast scan */
if (!request)
return;
n_ssids = request->n_ssids;
n_channels = request->n_channels;
/* Copy channel array if applicable */
WL_SCAN(("### List of channelspecs to scan ###\n"));
if (n_channels > 0) {
for (i = 0; i < n_channels; i++) {
chanspec = 0;
channel = ieee80211_frequency_to_channel(request->channels[i]->center_freq);
/* SKIP DFS channels for Secondary interface */
if ((cfg->escan_info.ndev != bcmcfg_to_prmry_ndev(cfg)) &&
(request->channels[i]->flags &
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
(IEEE80211_CHAN_RADAR | IEEE80211_CHAN_PASSIVE_SCAN)))
#else
(IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR)))
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0) */
continue;
if (request->channels[i]->band == IEEE80211_BAND_2GHZ) {
chanspec |= WL_CHANSPEC_BAND_2G;
} else {
chanspec |= WL_CHANSPEC_BAND_5G;
}
chanspec |= WL_CHANSPEC_BW_20;
chanspec |= WL_CHANSPEC_CTL_SB_NONE;
params->channel_list[j] = channel;
params->channel_list[j] &= WL_CHANSPEC_CHAN_MASK;
params->channel_list[j] |= chanspec;
WL_SCAN(("Chan : %d, Channel spec: %x \n",
channel, params->channel_list[j]));
params->channel_list[j] = wl_chspec_host_to_driver(params->channel_list[j]);
j++;
}
} else {
WL_SCAN(("Scanning all channels\n"));
}
n_channels = j;
/* Copy ssid array if applicable */
WL_SCAN(("### List of SSIDs to scan ###\n"));
if (n_ssids > 0) {
offset = offsetof(wl_scan_params_t, channel_list) + n_channels * sizeof(u16);
offset = roundup(offset, sizeof(u32));
ptr = (char*)params + offset;
for (i = 0; i < n_ssids; i++) {
memset(&ssid, 0, sizeof(wlc_ssid_t));
ssid.SSID_len = request->ssids[i].ssid_len;
memcpy(ssid.SSID, request->ssids[i].ssid, ssid.SSID_len);
if (!ssid.SSID_len)
WL_SCAN(("%d: Broadcast scan\n", i));
else
WL_SCAN(("%d: scan for %s size =%d\n", i,
ssid.SSID, ssid.SSID_len));
memcpy(ptr, &ssid, sizeof(wlc_ssid_t));
ptr += sizeof(wlc_ssid_t);
}
} else {
WL_SCAN(("Broadcast scan\n"));
}
/* Adding mask to channel numbers */
params->channel_num =
htod32((n_ssids << WL_SCAN_PARAMS_NSSID_SHIFT) |
(n_channels & WL_SCAN_PARAMS_COUNT_MASK));
if (n_channels == 1) {
params->active_time = htod32(WL_SCAN_CONNECT_DWELL_TIME_MS);
params->nprobes = htod32(params->active_time / WL_SCAN_JOIN_PROBE_INTERVAL_MS);
}
}
static s32
wl_get_valid_channels(struct net_device *ndev, u8 *valid_chan_list, s32 size)
{
wl_uint32_list_t *list;
s32 err = BCME_OK;
if (valid_chan_list == NULL || size <= 0)
return -ENOMEM;
memset(valid_chan_list, 0, size);
list = (wl_uint32_list_t *)(void *) valid_chan_list;
list->count = htod32(WL_NUMCHANNELS);
err = wldev_ioctl(ndev, WLC_GET_VALID_CHANNELS, valid_chan_list, size, false);
if (err != 0) {
WL_ERR(("get channels failed with %d\n", err));
}
return err;
}
#if defined(USE_INITIAL_2G_SCAN) || defined(USE_INITIAL_SHORT_DWELL_TIME)
#define FIRST_SCAN_ACTIVE_DWELL_TIME_MS 40
bool g_first_broadcast_scan = TRUE;
#endif /* USE_INITIAL_2G_SCAN || USE_INITIAL_SHORT_DWELL_TIME */
static s32
wl_run_escan(struct bcm_cfg80211 *cfg, struct net_device *ndev,
struct cfg80211_scan_request *request, uint16 action)
{
s32 err = BCME_OK;
u32 n_channels;
u32 n_ssids;
s32 params_size = (WL_SCAN_PARAMS_FIXED_SIZE + OFFSETOF(wl_escan_params_t, params));
wl_escan_params_t *params = NULL;
u8 chan_buf[sizeof(u32)*(WL_NUMCHANNELS + 1)];
u32 num_chans = 0;
s32 channel;
s32 n_valid_chan;
s32 search_state = WL_P2P_DISC_ST_SCAN;
u32 i, j, n_nodfs = 0;
u16 *default_chan_list = NULL;
wl_uint32_list_t *list;
struct net_device *dev = NULL;
dhd_pub_t *dhd = (dhd_pub_t *)(cfg->pub);
#if defined(USE_INITIAL_2G_SCAN) || defined(USE_INITIAL_SHORT_DWELL_TIME)
bool is_first_init_2g_scan = false;
#endif /* USE_INITIAL_2G_SCAN || USE_INITIAL_SHORT_DWELL_TIME */
p2p_scan_purpose_t p2p_scan_purpose = P2P_SCAN_PURPOSE_MIN;
WL_DBG(("Enter \n"));
/* scan request can come with empty request : perform all default scan */
if (!cfg) {
err = -EINVAL;
goto exit;
}
if (!wl_cfgp2p_check_enabled(cfg) || !p2p_scan(cfg)) {
/* LEGACY SCAN TRIGGER */
WL_SCAN((" LEGACY E-SCAN START\n"));
#if defined(USE_INITIAL_2G_SCAN) || defined(USE_INITIAL_SHORT_DWELL_TIME)
if (!request) {
err = -EINVAL;
goto exit;
}
if (ndev == bcmcfg_to_prmry_ndev(cfg) && g_first_broadcast_scan == true) {
#ifdef USE_INITIAL_2G_SCAN
struct ieee80211_channel tmp_channel_list[CH_MAX_2G_CHANNEL];
/* allow one 5G channel to add previous connected channel in 5G */
bool allow_one_5g_channel = TRUE;
j = 0;
for (i = 0; i < request->n_channels; i++) {
int tmp_chan = ieee80211_frequency_to_channel
(request->channels[i]->center_freq);
if (tmp_chan > CH_MAX_2G_CHANNEL) {
if (allow_one_5g_channel)
allow_one_5g_channel = FALSE;
else
continue;
}
if (j > CH_MAX_2G_CHANNEL) {
WL_ERR(("Index %d exceeds max 2.4GHz channels %d"
" and previous 5G connected channel\n",
j, CH_MAX_2G_CHANNEL));
break;
}
bcopy(request->channels[i], &tmp_channel_list[j],
sizeof(struct ieee80211_channel));
WL_SCAN(("channel of request->channels[%d]=%d\n", i, tmp_chan));
j++;
}
if ((j > 0) && (j <= CH_MAX_2G_CHANNEL)) {
for (i = 0; i < j; i++)
bcopy(&tmp_channel_list[i], request->channels[i],
sizeof(struct ieee80211_channel));
request->n_channels = j;
is_first_init_2g_scan = true;
}
else
WL_ERR(("Invalid number of 2.4GHz channels %d\n", j));
WL_SCAN(("request->n_channels=%d\n", request->n_channels));
#else /* USE_INITIAL_SHORT_DWELL_TIME */
is_first_init_2g_scan = true;
#endif /* USE_INITIAL_2G_SCAN */
g_first_broadcast_scan = false;
}
#endif /* USE_INITIAL_2G_SCAN || USE_INITIAL_SHORT_DWELL_TIME */
/* if scan request is not empty parse scan request paramters */
if (request != NULL) {
n_channels = request->n_channels;
n_ssids = request->n_ssids;
if (n_channels % 2)
/* If n_channels is odd, add a padd of u16 */
params_size += sizeof(u16) * (n_channels + 1);
else
params_size += sizeof(u16) * n_channels;
/* Allocate space for populating ssids in wl_escan_params_t struct */
params_size += sizeof(struct wlc_ssid) * n_ssids;
}
params = (wl_escan_params_t *) kzalloc(params_size, GFP_KERNEL);
if (params == NULL) {
err = -ENOMEM;
goto exit;
}
wl_scan_prep(cfg, &params->params, request);
#if defined(USE_INITIAL_2G_SCAN) || defined(USE_INITIAL_SHORT_DWELL_TIME)
/* Override active_time to reduce scan time if it's first bradcast scan. */
if (is_first_init_2g_scan)
params->params.active_time = FIRST_SCAN_ACTIVE_DWELL_TIME_MS;
#endif /* USE_INITIAL_2G_SCAN || USE_INITIAL_SHORT_DWELL_TIME */
params->version = htod32(ESCAN_REQ_VERSION);
params->action = htod16(action);
wl_escan_set_sync_id(params->sync_id, cfg);
wl_escan_set_type(cfg, WL_SCANTYPE_LEGACY);
if (params_size + sizeof("escan") >= WLC_IOCTL_MEDLEN) {
WL_ERR(("ioctl buffer length not sufficient\n"));
kfree(params);
err = -ENOMEM;
goto exit;
}
err = wldev_iovar_setbuf(ndev, "escan", params, params_size,
cfg->escan_ioctl_buf, WLC_IOCTL_MEDLEN, NULL);
if (unlikely(err)) {
if (err == BCME_EPERM)
/* Scan Not permitted at this point of time */
WL_DBG((" Escan not permitted at this time (%d)\n", err));
else
WL_ERR((" Escan set error (%d)\n", err));
} else {
DBG_EVENT_LOG(dhd, WIFI_EVENT_DRIVER_SCAN_REQUESTED);
}
kfree(params);
}
else if (p2p_is_on(cfg) && p2p_scan(cfg)) {
/* P2P SCAN TRIGGER */
s32 _freq = 0;
n_nodfs = 0;
if (request && request->n_channels) {
num_chans = request->n_channels;
WL_SCAN((" chann number : %d\n", num_chans));
default_chan_list = kzalloc(num_chans * sizeof(*default_chan_list),
GFP_KERNEL);
if (default_chan_list == NULL) {
WL_ERR(("channel list allocation failed \n"));
err = -ENOMEM;
goto exit;
}
if (!wl_get_valid_channels(ndev, chan_buf, sizeof(chan_buf))) {
list = (wl_uint32_list_t *) chan_buf;
n_valid_chan = dtoh32(list->count);
for (i = 0; i < num_chans; i++)
{
_freq = request->channels[i]->center_freq;
channel = ieee80211_frequency_to_channel(_freq);
/* ignore DFS channels */
if (request->channels[i]->flags &
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
(IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_RADAR))
#else
(IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_PASSIVE_SCAN))
#endif
continue;
for (j = 0; j < n_valid_chan; j++) {
/* allows only supported channel on
* current reguatory
*/
if (channel == (dtoh32(list->element[j])))
default_chan_list[n_nodfs++] =
channel;
}
}
}
if (num_chans == SOCIAL_CHAN_CNT && (
(default_chan_list[0] == SOCIAL_CHAN_1) &&
(default_chan_list[1] == SOCIAL_CHAN_2) &&
(default_chan_list[2] == SOCIAL_CHAN_3))) {
/* SOCIAL CHANNELS 1, 6, 11 */
search_state = WL_P2P_DISC_ST_SEARCH;
p2p_scan_purpose = P2P_SCAN_SOCIAL_CHANNEL;
WL_INFORM(("P2P SEARCH PHASE START \n"));
} else if ((dev = wl_to_p2p_bss_ndev(cfg, P2PAPI_BSSCFG_CONNECTION)) &&
(wl_get_mode_by_netdev(cfg, dev) == WL_MODE_AP)) {
/* If you are already a GO, then do SEARCH only */
WL_INFORM(("Already a GO. Do SEARCH Only"));
search_state = WL_P2P_DISC_ST_SEARCH;
num_chans = n_nodfs;
p2p_scan_purpose = P2P_SCAN_NORMAL;
} else if (num_chans == 1) {
p2p_scan_purpose = P2P_SCAN_CONNECT_TRY;
} else if (num_chans == SOCIAL_CHAN_CNT + 1) {
/* SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan supported by
* the supplicant
*/
p2p_scan_purpose = P2P_SCAN_SOCIAL_CHANNEL;
} else {
WL_INFORM(("P2P SCAN STATE START \n"));
num_chans = n_nodfs;
p2p_scan_purpose = P2P_SCAN_NORMAL;
}
} else {
err = -EINVAL;
goto exit;
}
err = wl_cfgp2p_escan(cfg, ndev, cfg->active_scan, num_chans, default_chan_list,
search_state, action,
wl_to_p2p_bss_bssidx(cfg, P2PAPI_BSSCFG_DEVICE), NULL,
p2p_scan_purpose);
if (!err)
cfg->p2p->search_state = search_state;
kfree(default_chan_list);
}
exit:
if (unlikely(err)) {
/* Don't print Error incase of Scan suppress */
if ((err == BCME_EPERM) && cfg->scan_suppressed)
WL_DBG(("Escan failed: Scan Suppressed \n"));
else
WL_ERR(("error (%d)\n", err));
}
return err;
}
static s32
wl_do_escan(struct bcm_cfg80211 *cfg, struct wiphy *wiphy, struct net_device *ndev,
struct cfg80211_scan_request *request)
{
s32 err = BCME_OK;
s32 passive_scan;
wl_scan_results_t *results;
WL_SCAN(("Enter \n"));
mutex_lock(&cfg->usr_sync);
results = wl_escan_get_buf(cfg, FALSE);
results->version = 0;
results->count = 0;
results->buflen = WL_SCAN_RESULTS_FIXED_SIZE;
cfg->escan_info.ndev = ndev;
cfg->escan_info.wiphy = wiphy;
cfg->escan_info.escan_state = WL_ESCAN_STATE_SCANING;
passive_scan = cfg->active_scan ? 0 : 1;
err = wldev_ioctl(ndev, WLC_SET_PASSIVE_SCAN,
&passive_scan, sizeof(passive_scan), true);
if (unlikely(err)) {
WL_ERR(("error (%d)\n", err));
goto exit;
}
err = wl_run_escan(cfg, ndev, request, WL_SCAN_ACTION_START);
exit:
mutex_unlock(&cfg->usr_sync);
return err;
}
static s32
__wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
struct cfg80211_scan_request *request,
struct cfg80211_ssid *this_ssid)
{
struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
struct cfg80211_ssid *ssids;
struct ether_addr primary_mac;
bool p2p_ssid;
#ifdef WL11U
bcm_tlv_t *interworking_ie;
#endif
s32 err = 0;
s32 bssidx = -1;
s32 i;
unsigned long flags;
static s32 busy_count = 0;
#ifdef WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST
struct net_device *remain_on_channel_ndev = NULL;
#endif
dhd_pub_t *dhd;
dhd = (dhd_pub_t *)(cfg->pub);
/*
* Hostapd triggers scan before starting automatic channel selection
* also Dump stats IOVAR scans each channel hence returning from here.
*/
if (dhd->op_mode & DHD_FLAG_HOSTAP_MODE) {
#ifdef WL_SUPPORT_ACS
WL_INFORM(("Scan Command at SoftAP mode\n"));
return 0;
#else
WL_ERR(("Invalid Scan Command at SoftAP mode\n"));
return -EINVAL;
#endif /* WL_SUPPORT_ACS */
}
ndev = ndev_to_wlc_ndev(ndev, cfg);
if (WL_DRV_STATUS_SENDING_AF_FRM_EXT(cfg)) {
WL_ERR(("Sending Action Frames. Try it again.\n"));
return -EAGAIN;
}
WL_DBG(("Enter wiphy (%p)\n", wiphy));
if (wl_get_drv_status_all(cfg, SCANNING)) {
if (cfg->scan_request == NULL) {
wl_clr_drv_status_all(cfg, SCANNING);
WL_DBG(("<<<<<<<<<<<Force Clear Scanning Status>>>>>>>>>>>\n"));
} else {
WL_ERR(("Scanning already\n"));
return -EAGAIN;
}
}
if (wl_get_drv_status(cfg, SCAN_ABORTING, ndev)) {
WL_ERR(("Scanning being aborted\n"));
return -EAGAIN;
}
if (request && request->n_ssids > WL_SCAN_PARAMS_SSID_MAX) {
WL_ERR(("request null or n_ssids > WL_SCAN_PARAMS_SSID_MAX\n"));
return -EOPNOTSUPP;
}
#ifdef WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST
remain_on_channel_ndev = wl_cfg80211_get_remain_on_channel_ndev(cfg);
if (remain_on_channel_ndev) {
WL_DBG(("Remain_on_channel bit is set, somehow it didn't get cleared\n"));
wl_notify_escan_complete(cfg, remain_on_channel_ndev, true, true);
}
#endif /* WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST */
/* Arm scan timeout timer */
mod_timer(&cfg->scan_timeout, jiffies + msecs_to_jiffies(WL_SCAN_TIMER_INTERVAL_MS));
if (request) { /* scan bss */
ssids = request->ssids;
p2p_ssid = false;
for (i = 0; i < request->n_ssids; i++) {
if (ssids[i].ssid_len &&
IS_P2P_SSID(ssids[i].ssid, ssids[i].ssid_len)) {
p2p_ssid = true;
break;
}
}
if (p2p_ssid) {
if (wl_cfgp2p_check_enabled(cfg)) {
/* p2p scan trigger */
if (p2p_on(cfg) == false) {
/* p2p on at the first time */
p2p_on(cfg) = true;
wl_cfgp2p_set_firm_p2p(cfg);
get_primary_mac(cfg, &primary_mac);
wl_cfgp2p_generate_bss_mac(&primary_mac,
&cfg->p2p->dev_addr, &cfg->p2p->int_addr);
}
wl_clr_p2p_status(cfg, GO_NEG_PHASE);
WL_DBG(("P2P: GO_NEG_PHASE status cleared \n"));
p2p_scan(cfg) = true;
}
} else {
/* legacy scan trigger
* So, we have to disable p2p discovery if p2p discovery is on
*/
if (wl_cfgp2p_check_enabled(cfg)) {
p2p_scan(cfg) = false;
/* If Netdevice is not equals to primary and p2p is on
* , we will do p2p scan using P2PAPI_BSSCFG_DEVICE.
*/
if (p2p_scan(cfg) == false) {
if (wl_get_p2p_status(cfg, DISCOVERY_ON)) {
err = wl_cfgp2p_discover_enable_search(cfg,
false);
if (unlikely(err)) {
goto scan_out;
}
}
}
}
if (!wl_cfgp2p_check_enabled(cfg) || !p2p_scan(cfg)) {
if (wl_cfgp2p_find_idx(cfg, ndev, &bssidx) != BCME_OK) {
WL_ERR(("Find p2p index from ndev(%p) failed\n",
ndev));
err = BCME_ERROR;
goto scan_out;
}
#ifdef WL11U
if ((interworking_ie = wl_cfg80211_find_interworking_ie(
(u8 *)request->ie, request->ie_len)) != NULL) {
err = wl_cfg80211_add_iw_ie(cfg, ndev, bssidx,
VNDR_IE_CUSTOM_FLAG, interworking_ie->id,
interworking_ie->data, interworking_ie->len);
if (unlikely(err)) {
goto scan_out;
}
} else if (cfg->iw_ie_len != 0) {
/* we have to clear IW IE and disable gratuitous APR */
wl_cfg80211_add_iw_ie(cfg, ndev, bssidx,
VNDR_IE_CUSTOM_FLAG,
DOT11_MNG_INTERWORKING_ID,
0, 0);
wldev_iovar_setint_bsscfg(ndev, "grat_arp", 0,
bssidx);
cfg->wl11u = FALSE;
/* we don't care about error */
}
#endif /* WL11U */
err = wl_cfgp2p_set_management_ie(cfg, ndev, bssidx,
VNDR_IE_PRBREQ_FLAG, (u8 *)request->ie,
request->ie_len);
if (unlikely(err)) {
goto scan_out;
}
}
}
} else { /* scan in ibss */
ssids = this_ssid;
}
cfg->scan_request = request;
wl_set_drv_status(cfg, SCANNING, ndev);
if (wl_cfgp2p_check_enabled(cfg)) {
if (p2p_on(cfg) && p2p_scan(cfg)) {
/* find my listen channel */
cfg->afx_hdl->my_listen_chan =
wl_find_listen_channel(cfg, request->ie,
request->ie_len);
err = wl_cfgp2p_enable_discovery(cfg, ndev,
request->ie, request->ie_len);
if (unlikely(err)) {
goto scan_out;
}
}
}
err = wl_do_escan(cfg, wiphy, ndev, request);
if (likely(!err))
goto scan_success;
else
goto scan_out;
scan_success:
busy_count = 0;
return 0;
scan_out:
if (err == BCME_BUSY || err == BCME_NOTREADY) {
WL_ERR(("Scan err = (%d), busy?%d", err, -EBUSY));
err = -EBUSY;
}
#define SCAN_EBUSY_RETRY_LIMIT 10
if (err == -EBUSY) {
if (busy_count++ > SCAN_EBUSY_RETRY_LIMIT) {
struct ether_addr bssid;
s32 ret = 0;
busy_count = 0;
WL_ERR(("Unusual continuous EBUSY error, %d %d %d %d %d %d %d %d %d\n",
wl_get_drv_status(cfg, SCANNING, ndev),
wl_get_drv_status(cfg, SCAN_ABORTING, ndev),
wl_get_drv_status(cfg, CONNECTING, ndev),
wl_get_drv_status(cfg, CONNECTED, ndev),
wl_get_drv_status(cfg, DISCONNECTING, ndev),
wl_get_drv_status(cfg, AP_CREATING, ndev),
wl_get_drv_status(cfg, AP_CREATED, ndev),
wl_get_drv_status(cfg, SENDING_ACT_FRM, ndev),
wl_get_drv_status(cfg, SENDING_ACT_FRM, ndev)));
bzero(&bssid, sizeof(bssid));
if ((ret = wldev_ioctl(ndev, WLC_GET_BSSID,
&bssid, ETHER_ADDR_LEN, false)) == 0)
WL_ERR(("FW is connected with " MACDBG "/n",
MAC2STRDBG(bssid.octet)));
else
WL_ERR(("GET BSSID failed with %d\n", ret));
wl_cfg80211_scan_abort(cfg);
}
} else {
busy_count = 0;
}
wl_clr_drv_status(cfg, SCANNING, ndev);
if (timer_pending(&cfg->scan_timeout))
del_timer_sync(&cfg->scan_timeout);
spin_lock_irqsave(&cfg->cfgdrv_lock, flags);
cfg->scan_request = NULL;
spin_unlock_irqrestore(&cfg->cfgdrv_lock, flags);
return err;
}
#if defined(WL_CFG80211_P2P_DEV_IF)
static s32
wl_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
#else
static s32
wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
struct cfg80211_scan_request *request)
#endif /* WL_CFG80211_P2P_DEV_IF */
{
s32 err = 0;
struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
#if defined(WL_CFG80211_P2P_DEV_IF)
struct net_device *ndev = wdev_to_wlc_ndev(request->wdev, cfg);
#endif /* WL_CFG80211_P2P_DEV_IF */
WL_DBG(("Enter \n"));
RETURN_EIO_IF_NOT_UP(cfg);
err = __wl_cfg80211_scan(wiphy, ndev, request, NULL);
if (unlikely(err)) {
if ((err == BCME_EPERM) && cfg->scan_suppressed)
WL_DBG(("scan not permitted at this time (%d)\n", err));
else
WL_ERR(("scan error (%d)\n", err));
return err;
}
return err;
}
static s32 wl_set_rts(struct net_device *dev, u32 rts_threshold)
{
s32 err = 0;
err = wldev_iovar_setint(dev, "rtsthresh", rts_threshold);
if (unlikely(err)) {
WL_ERR(("Error (%d)\n", err));
return err;
}
return err;
}
static s32 wl_set_frag(struct net_device *dev, u32 frag_threshold)
{
s32 err = 0;
err = wldev_iovar_setint_bsscfg(dev, "fragthresh", frag_threshold, 0);
if (unlikely(err)) {
WL_ERR(("Error (%d)\n", err));
return err;
}
return err;
}
static s32 wl_set_retry(struct net_device *dev, u32 retry, bool l)
{
s32 err = 0;
u32 cmd = (l ? WLC_SET_LRL : WLC_SET_SRL);
retry = htod32(retry);
err = wldev_ioctl(dev, cmd, &retry, sizeof(retry), true);
if (unlikely(err)) {
WL_ERR(("cmd (%d) , error (%d)\n", cmd, err));
return err;
}
return err;
}
static s32 wl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
{
struct bcm_cfg80211 *cfg = (struct bcm_cfg80211 *)wiphy_priv(wiphy);
struct net_device *ndev = bcmcfg_to_prmry_ndev(cfg);
s32 err = 0;
RETURN_EIO_IF_NOT_UP(cfg);
WL_DBG(("Enter\n"));
if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
(cfg->conf->rts_threshold != wiphy->rts_threshold)) {
cfg->conf->rts_threshold = wiphy->rts_threshold;
err = wl_set_rts(ndev, cfg->conf->rts_threshold);
if (!err)
return err;
}
if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
(cfg->conf->frag_threshold != wiphy->frag_threshold)) {
cfg->conf->frag_threshold = wiphy->frag_threshold;
err = wl_set_frag(ndev, cfg->conf->frag_threshold);
if (!err)
return err;
}
if (changed & WIPHY_PARAM_RETRY_LONG &&
(cfg->conf->retry_long != wiphy->retry_long)) {
cfg->conf->retry_long = wiphy->retry_long;
err = wl_set_retry(ndev, cfg->conf->retry_long, true);
if (!err)
return err;
}
if (changed & WIPHY_PARAM_RETRY_SHORT &&
(cfg->conf->retry_short != wiphy->retry_short)) {
cfg->conf->retry_short = wiphy->retry_short;
err = wl_set_retry(ndev, cfg->conf->retry_short, false);
if (!err) {
return err;
}
}
return err;
}
static chanspec_t
channel_to_chanspec(struct wiphy *wiphy, struct net_device *dev, u32 channel, u32 bw_cap)
{
struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
u8 *buf = NULL;
wl_uint32_list_t *list;
int err = BCME_OK;
chanspec_t c = 0, ret_c = 0;
int bw = 0, tmp_bw = 0;
int i;
u32 tmp_c;
u16 kflags = in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
#define LOCAL_BUF_SIZE 1024
buf = (u8 *) kzalloc(LOCAL_BUF_SIZE, kflags);
if (!buf) {
WL_ERR(("buf memory alloc failed\n"));
goto exit;
}
list = (wl_uint32_list_t *)(void *)buf;
list->count = htod32(WL_NUMCHANSPECS);
err = wldev_iovar_getbuf_bsscfg(dev, "chanspecs", NULL,
0, buf, LOCAL_BUF_SIZE, 0, &cfg->ioctl_buf_sync);
if (err != BCME_OK) {
WL_ERR(("get chanspecs failed with %d\n", err));
goto exit;
}
for (i = 0; i < dtoh32(list->count); i++) {
c = dtoh32(list->element[i]);
if (channel <= CH_MAX_2G_CHANNEL) {
if (!CHSPEC_IS20(c))
continue;
if (channel == CHSPEC_CHANNEL(c)) {
ret_c = c;
bw = 20;
goto exit;
}
}
tmp_c = wf_chspec_ctlchan(c);
tmp_bw = bw2cap[CHSPEC_BW(c) >> WL_CHANSPEC_BW_SHIFT];
if (tmp_c != channel)
continue;
if ((tmp_bw > bw) && (tmp_bw <= bw_cap)) {
bw = tmp_bw;
ret_c = c;
if (bw == bw_cap)
goto exit;
}
}
exit:
if (buf)
kfree(buf);
#undef LOCAL_BUF_SIZE
WL_INFORM(("return chanspec %x %d\n", ret_c, bw));
return ret_c;
}
void
wl_cfg80211_ibss_vsie_set_buffer(struct net_device *dev, vndr_ie_setbuf_t *ibss_vsie, int ibss_vsie_len)
{
struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
if (cfg != NULL && ibss_vsie != NULL) {
if (cfg->ibss_vsie != NULL) {
kfree(cfg->ibss_vsie);
}
cfg->ibss_vsie = ibss_vsie;
cfg->ibss_vsie_len = ibss_vsie_len;
}
}
static void
wl_cfg80211_ibss_vsie_free(struct bcm_cfg80211 *cfg)
{
/* free & initiralize VSIE (Vendor Specific IE) */
if (cfg->ibss_vsie != NULL) {
kfree(cfg->ibss_vsie);
cfg->ibss_vsie = NULL;
cfg->ibss_vsie_len = 0;
}
}
s32
wl_cfg80211_ibss_vsie_delete(struct net_device *dev)
{
struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
char *ioctl_buf = NULL;
s32 ret = BCME_OK;
if (cfg != NULL && cfg->ibss_vsie != NULL) {
ioctl_buf = kmalloc(WLC_IOCTL_MEDLEN, GFP_KERNEL);
if (!ioctl_buf) {
WL_ERR(("ioctl memory alloc failed\n"));
return -ENOMEM;
}
/* change the command from "add" to "del" */
strncpy(cfg->ibss_vsie->cmd, "del", VNDR_IE_CMD_LEN - 1);
cfg->ibss_vsie->cmd[VNDR_IE_CMD_LEN - 1] = '\0';
ret = wldev_iovar_setbuf(dev, "ie",
cfg->ibss_vsie, cfg->ibss_vsie_len,
ioctl_buf, WLC_IOCTL_MEDLEN, NULL);
WL_ERR(("ret=%d\n", ret));
if (ret == BCME_OK) {
/* free & initiralize VSIE */
kfree(cfg->ibss_vsie);
cfg->ibss_vsie = NULL;
cfg->ibss_vsie_len = 0;
}
if (ioctl_buf) {
kfree(ioctl_buf);
}
}
return ret;
}
static bcm_struct_cfgdev*
bcm_cfg80211_add_ibss_if(struct wiphy *wiphy, char *name)
{
int err = 0;
struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
struct wireless_dev* wdev = NULL;
struct net_device *new_ndev = NULL;
struct net_device *primary_ndev = NULL;
s32 timeout;
wl_aibss_if_t aibss_if;
wl_if_event_info *event = NULL;
if (cfg->ibss_cfgdev != NULL) {
WL_ERR(("IBSS interface %s already exists\n", name));
return NULL;
}
WL_ERR(("Try to create IBSS interface %s\n", name));
primary_ndev = bcmcfg_to_prmry_ndev(cfg);
/* generate a new MAC address for the IBSS interface */
get_primary_mac(cfg, &cfg->ibss_if_addr);
cfg->ibss_if_addr.octet[4] ^= 0x40;
memset(&aibss_if, sizeof(aibss_if), 0);
memcpy(&aibss_if.addr, &cfg->ibss_if_addr, sizeof(aibss_if.addr));
aibss_if.chspec = 0;
aibss_if.len = sizeof(aibss_if);
cfg->bss_pending_op = TRUE;
memset(&cfg->if_event_info, 0, sizeof(cfg->if_event_info));
err = wldev_iovar_setbuf(primary_ndev, "aibss_ifadd", &aibss_if,
sizeof(aibss_if), cfg->ioctl_buf, WLC_IOCTL_MAXLEN, NULL);
if (err) {
WL_ERR(("IOVAR aibss_ifadd failed with error %d\n", err));
goto fail;
}
timeout = wait_event_interruptible_timeout(cfg->netif_change_event,
!cfg->bss_pending_op, msecs_to_jiffies(MAX_WAIT_TIME));
if (timeout <= 0 || cfg->bss_pending_op)
goto fail;
event = &cfg->if_event_info;
strncpy(event->name, name, IFNAMSIZ - 1);
/* By calling wl_cfg80211_allocate_if (dhd_allocate_if eventually) we give the control
* over this net_device interface to dhd_linux, hence the interface is managed by dhd_liux
* and will be freed by dhd_detach unless it gets unregistered before that. The
* wireless_dev instance new_ndev->ieee80211_ptr associated with this net_device will
* be freed by wl_dealloc_netinfo
*/
new_ndev = wl_cfg80211_allocate_if(cfg, event->ifidx, event->name,
event->mac, event->bssidx);
if (new_ndev == NULL)
goto fail;
wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
if (wdev == NULL)
goto fail;
wdev->wiphy = wiphy;
wdev->iftype = NL80211_IFTYPE_ADHOC;
wdev->netdev = new_ndev;
new_ndev->ieee80211_ptr = wdev;
SET_NETDEV_DEV(new_ndev, wiphy_dev(wdev->wiphy));
/* rtnl lock must have been acquired, if this is not the case, wl_cfg80211_register_if
* needs to be modified to take one parameter (bool need_rtnl_lock)
*/
ASSERT_RTNL();
if (wl_cfg80211_register_if(cfg, event->ifidx, new_ndev) != BCME_OK)
goto fail;
wl_alloc_netinfo(cfg, new_ndev, wdev, WL_MODE_IBSS, PM_ENABLE);
cfg->ibss_cfgdev = ndev_to_cfgdev(new_ndev);
WL_ERR(("IBSS interface %s created\n", new_ndev->name));
return cfg->ibss_cfgdev;