blob: 2eae0fd1f790c99f7533aaeb64202f0a84c2f64e [file] [log] [blame]
/*
* Linux cfg80211 driver
*
* Copyright 1999-2016, Broadcom Corporation
* All rights reserved,
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided by the copyright holder "as is" and any express or
* implied warranties, including, but not limited to, the implied warranties of
* merchantability and fitness for a particular purpose are disclaimed. In no event
* shall copyright holder be liable for any direct, indirect, incidental, special,
* exemplary, or consequential damages (including, but not limited to, procurement
* of substitute goods or services; loss of use, data, or profits; or business
* interruption) however caused and on any theory of liability, whether in
* contract, strict liability, or tort (including negligence or otherwise) arising
* in any way out of the use of this software, even if advised of the possibility
* of such damage
*
*
* <<Broadcom-WL-IPTag/Open:>>
*
* $Id: wl_cfg80211.c 610196 2016-01-06 11:20:45Z $
*/
/* */
#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 <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 <linux/time.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>
#include <dngl_stats.h>
#include <dhd.h>
#include <dhd_linux.h>
#include <dhdioctl.h>
#include <wlioctl.h>
#include <dhd_cfg80211.h>
#include <dhd_bus.h>
#ifdef PNO_SUPPORT
#include <dhd_pno.h>
#endif /* PNO_SUPPORT */
#if defined(WL_VENDOR_EXT_SUPPORT)
#include <wl_cfgvendor.h>
#endif /* defined(WL_VENDOR_EXT_SUPPORT) */
#ifdef WL_NAN
#include <wl_cfgnan.h>
#endif /* WL_NAN */
#include <dhd_config.h>
#ifdef PROP_TXSTATUS
#include <dhd_wlfc.h>
#endif
#ifdef BCMPCIE
#include <dhd_flowring.h>
#endif
#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;
#ifdef CUSTOMER_HW4_DEBUG
u32 wl_dbg_level = WL_DBG_ERR | WL_DBG_P2P_ACTION;
#else
u32 wl_dbg_level = WL_DBG_ERR;
#endif /* CUSTOMER_HW4_DEBUG */
#define MAX_WAIT_TIME 1500
#ifdef WLAIBSS_MCHAN
#define IBSS_IF_NAME "ibss%d"
#endif /* WLAIBSS_MCHAN */
#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 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
#define ACTIVE_SCAN 1
#define PASSIVE_SCAN 0
#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == \
4 && __GNUC_MINOR__ >= 6))
#define BCM_SET_LIST_FIRST_ENTRY(entry, ptr, type, member) \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wcast-qual\"") \
(entry) = list_first_entry((ptr), type, member); \
_Pragma("GCC diagnostic pop") \
#define BCM_SET_CONTAINER_OF(entry, ptr, type, member) \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wcast-qual\"") \
entry = container_of((ptr), type, member); \
_Pragma("GCC diagnostic pop") \
#else
#define BCM_SET_LIST_FIRST_ENTRY(entry, ptr, type, member) \
(entry) = list_first_entry((ptr), type, member); \
#define BCM_SET_CONTAINER_OF(entry, ptr, type, member) \
entry = container_of((ptr), type, member); \
#endif /* STRICT_GCC_WARNINGS */
enum rmc_event_type {
RMC_EVENT_NONE,
RMC_EVENT_LEADER_CHECK_FAIL
};
/* 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.
*
* this definition reuires disabling missing-field-initializer warning
* as the ieee80211_regdomain definition differs in plain linux and in Android
*/
#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == \
4 && __GNUC_MINOR__ >= 6))
_Pragma("GCC diagnostic push")
_Pragma("GCC diagnostic ignored \"-Wmissing-field-initializers\"")
#endif
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, 80, 6, 20, 0),
/* IEEE 802.11a, channel 100..165 */
REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), }
};
#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == \
4 && __GNUC_MINOR__ >= 6))
_Pragma("GCC diagnostic pop")
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0)) && \
(defined(WL_IFACE_COMB_NUM_CHANNELS) || defined(WL_CFG80211_P2P_DEV_IF))
static const struct ieee80211_iface_limit common_if_limits[] = {
{
/*
* Driver can support up to 2 AP's
*/
.max = 2,
.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 struct ieee80211_iface_combination
common_iface_combinations[] = {
{
.num_different_channels = NUM_DIFF_CHANNELS,
/*
* max_interfaces = 4
* The max no of interfaces will be used in dual p2p case.
* {STA, P2P Device, P2P Group 1, P2P Group 2}. Though we
* will not be using the STA functionality in this case, it
* will remain registered as it is the primary interface.
*/
.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
#define WL_AKM_SUITE_SHA256_1X 0x000FAC05
#define WL_AKM_SUITE_SHA256_PSK 0x000FAC06
#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 */
#define LONG_LISTEN_TIME 2000
#define MAX_SCAN_ABORT_WAIT_CNT 20
#define WAIT_SCAN_ABORT_OSL_SLEEP_TIME 10
#define IDSUP_4WAY_HANDSHAKE_TIMEOUT 10000
enum idsup_event_type {
IDSUP_EVENT_SUCCESS = 0,
IDSUP_EVENT_4WAY_HANDSHAKE_TIMEOUT
};
/*
* 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);
#ifdef WLAIBSS_MCHAN
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);
#endif /* WLAIBSS_MCHAN */
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);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
static s32 wl_cfg80211_get_station(struct wiphy *wiphy,
struct net_device *dev, const u8 *mac,
struct station_info *sinfo);
#else
static s32 wl_cfg80211_get_station(struct wiphy *wiphy,
struct net_device *dev, u8 *mac,
struct station_info *sinfo);
#endif
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);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0))
static s32 wl_cfg80211_del_station(
struct wiphy *wiphy, struct net_device *ndev,
struct station_del_parameters *params);
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
static s32 wl_cfg80211_del_station(struct wiphy *wiphy,
struct net_device *ndev, const u8* mac_addr);
#else
static s32 wl_cfg80211_del_station(struct wiphy *wiphy,
struct net_device *ndev, u8* mac_addr);
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
static s32 wl_cfg80211_change_station(struct wiphy *wiphy,
struct net_device *dev, const u8 *mac, struct station_parameters *params);
#else
static s32 wl_cfg80211_change_station(struct wiphy *wiphy,
struct net_device *dev, u8 *mac, struct station_parameters *params);
#endif
#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 /* KERNEL_VERSION(2, 6, 39) || WL_COMPAT_WIRELES */
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 void wl_cfg80211_cancel_scan(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))
#if (defined(CONFIG_ARCH_MSM) && defined(TDLS_MGMT_VERSION2)) || (LINUX_VERSION_CODE < \
KERNEL_VERSION(3, 16, 0) && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0))
static s32 wl_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
u8 *peer, u8 action_code, u8 dialog_token, u16 status_code,
u32 peer_capability, const u8 *data, size_t len);
#elif ((LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)) && \
(LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)))
static s32 wl_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
const u8 *peer, u8 action_code, u8 dialog_token, u16 status_code,
u32 peer_capability, const u8 *data, size_t len);
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0))
static s32 wl_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
const u8 *peer, u8 action_code, u8 dialog_token, u16 status_code,
u32 peer_capability, bool initiator, const u8 *data, size_t len);
#else
static s32 wl_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
u8 *peer, u8 action_code, u8 dialog_token, u16 status_code, const u8 *data,
size_t len);
#endif /* CONFIG_ARCH_MSM && TDLS_MGMT_VERSION2 */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
static s32 wl_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
const u8 *peer, enum nl80211_tdls_operation oper);
#else
static s32 wl_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
u8 *peer, enum nl80211_tdls_operation oper);
#endif
#endif
#ifdef WL_SCHED_SCAN
static int wl_cfg80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev);
#endif
static s32 wl_cfg80211_set_ap_role(struct bcm_cfg80211 *cfg, struct net_device *dev);
#if defined(WL_VIRTUAL_APSTA) || 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(WL_VIRTUAL_APSTA) || defined(DUAL_STA_STATIC_IF) */
s32 wl_cfg80211_interface_ops(struct bcm_cfg80211 *cfg,
struct net_device *ndev, s32 bsscfg_idx,
enum nl80211_iftype iface_type, s32 del, u8 *addr);
s32 wl_cfg80211_add_del_bss(struct bcm_cfg80211 *cfg,
struct net_device *ndev, s32 bsscfg_idx,
enum nl80211_iftype iface_type, s32 del, u8 *addr);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0))
static s32 wl_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev);
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0) */
chanspec_t wl_chspec_driver_to_host(chanspec_t chanspec);
chanspec_t wl_chspec_host_to_driver(chanspec_t chanspec);
#ifdef WL11ULB
static s32 wl_cfg80211_get_ulb_bw(struct bcm_cfg80211 *cfg, struct wireless_dev *wdev);
static chanspec_t wl_cfg80211_ulb_get_min_bw_chspec(struct bcm_cfg80211 *cfg,
struct wireless_dev *wdev, s32 bssidx);
static s32 wl_cfg80211_ulbbw_to_ulbchspec(u32 ulb_bw);
#else
static inline chanspec_t wl_cfg80211_ulb_get_min_bw_chspec(
struct bcm_cfg80211 *cfg, struct wireless_dev *wdev, s32 bssidx)
{
return WL_CHANSPEC_BW_20;
}
#endif /* WL11ULB */
static void wl_cfg80211_wait_for_disconnection(struct bcm_cfg80211 *cfg, struct net_device *dev);
/*
* 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);
#endif /* GSCAN_SUPPORT */
static s32 wl_notifier_change_state(struct bcm_cfg80211 *cfg, struct net_info *_net_info,
enum wl_status state, bool set);
#ifdef DHD_LOSSLESS_ROAMING
static s32 wl_notify_roam_prep_status(struct bcm_cfg80211 *cfg,
bcm_struct_cfgdev *cfgdev, const wl_event_msg_t *e, void *data);
static void wl_del_roam_timeout(struct bcm_cfg80211 *cfg);
#endif /* DHD_LOSSLESS_ROAMING */
#ifdef CUSTOM_EVENT_PM_WAKE
static s32 wl_check_pmstatus(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
const wl_event_msg_t *e, void *data);
#endif /* CUSTOM_EVENT_PM_WAKE */
#ifdef WLTDLS
static s32 wl_cfg80211_tdls_config(struct bcm_cfg80211 *cfg,
enum wl_tdls_config state, bool tdls_mode);
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, const 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 s32 wl_ch_to_chanspec(struct net_device *dev, int ch,
struct wl_join_params *join_params, size_t *join_params_size);
void wl_cfg80211_clear_security(struct bcm_cfg80211 *cfg);
/*
* 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, const 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, dhd_pub_t *data);
static void wl_free_wdev(struct bcm_cfg80211 *cfg);
#ifdef CONFIG_CFG80211_INTERNAL_REGDB
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0))
static int
#else
static void
#endif /* kernel version < 3.10.11 */
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(struct bcm_cfg80211 *cfg,
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 */
/*
* 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 DHD_IFDEBUG
void wl_dump_ifinfo(struct bcm_cfg80211 *cfg);
#endif
#ifdef P2P_LISTEN_OFFLOADING
s32 wl_cfg80211_p2plo_deinit(struct bcm_cfg80211 *cfg);
#endif /* P2P_LISTEN_OFFLOADING */
static int wl_cfg80211_delayed_roam(struct bcm_cfg80211 *cfg, struct net_device *ndev,
const struct ether_addr *bssid);
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 };
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0))
#define CFG80211_DISCONNECTED(dev, reason, ie, len, loc_gen, gfp) \
cfg80211_disconnected(dev, reason, ie, len, gfp);
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0))
#define CFG80211_DISCONNECTED(dev, reason, ie, len, loc_gen, gfp) \
cfg80211_disconnected(dev, reason, ie, len, loc_gen, gfp);
#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 */
extern int passive_channel_skip;
static s32
wl_ap_start_ind(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
const wl_event_msg_t *e, void *data);
static s32
wl_csa_complete_ind(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
const wl_event_msg_t *e, void *data);
#if ((LINUX_VERSION_CODE >= KERNEL_VERSION (3, 5, 0)) && (LINUX_VERSION_CODE <= (3, 7, \
0)))
struct chan_info {
int freq;
int chan_type;
};
#endif
#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_XXX_ASSOC_START", "WLC_E_XXX_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 */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
#define ieee80211_band nl80211_band
#define IEEE80211_BAND_2GHZ NL80211_BAND_2GHZ
#define IEEE80211_BAND_5GHZ NL80211_BAND_5GHZ
#define IEEE80211_NUM_BANDS NUM_NL80211_BANDS
#endif
#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
#ifdef CUSTOMER_HW4_DEBUG
uint prev_dhd_console_ms = 0;
u32 prev_wl_dbg_level = 0;
bool wl_scan_timeout_dbg_enabled = 0;
static void wl_scan_timeout_dbg_set(void);
static void wl_scan_timeout_dbg_clear(void);
static void wl_scan_timeout_dbg_set(void)
{
WL_ERR(("Enter \n"));
prev_dhd_console_ms = dhd_console_ms;
prev_wl_dbg_level = wl_dbg_level;
dhd_console_ms = 1;
wl_dbg_level |= (WL_DBG_ERR | WL_DBG_P2P_ACTION | WL_DBG_SCAN);
wl_scan_timeout_dbg_enabled = 1;
}
static void wl_scan_timeout_dbg_clear(void)
{
WL_ERR(("Enter \n"));
dhd_console_ms = prev_dhd_console_ms;
wl_dbg_level = prev_wl_dbg_level;
wl_scan_timeout_dbg_enabled = 0;
}
#endif /* CUSTOMER_HW4_DEBUG */
/* watchdog timer for disconnecting when fw is not associated for FW_ASSOC_WATCHDOG_TIME ms */
uint32 fw_assoc_watchdog_ms = 0;
bool fw_assoc_watchdog_started = 0;
#define FW_ASSOC_WATCHDOG_TIME 10 * 1000 /* msec */
#ifdef DHD_IFDEBUG
void wl_dump_ifinfo(struct bcm_cfg80211 *cfg)
{
WL_ERR(("cfg=%p\n", cfg));
if (cfg) {
WL_ERR(("cfg->wdev=%p\n", bcmcfg_to_prmry_wdev(cfg)));
if (bcmcfg_to_prmry_wdev(cfg)) {
WL_ERR(("cfg->wdev->wiphy=%p\n", bcmcfg_to_wiphy(cfg)));
WL_ERR(("cfg->wdev->netdev=%p\n", bcmcfg_to_prmry_ndev(cfg)));
}
}
}
#endif
static void wl_add_remove_pm_enable_work(struct bcm_cfg80211 *cfg,
enum wl_pm_workq_act_type type)
{
u16 wq_duration = 0;
if (cfg == NULL)
return;
mutex_lock(&cfg->pm_sync);
/*
* Make cancel and schedule work part mutually exclusive
* so that while cancelling, we are sure that there is no
* work getting scheduled.
*/
if (delayed_work_pending(&cfg->pm_enable_work)) {
cancel_delayed_work_sync(&cfg->pm_enable_work);
DHD_OS_WAKE_UNLOCK(cfg->pub);
}
if (type == WL_PM_WORKQ_SHORT) {
wq_duration = WL_PM_ENABLE_TIMEOUT;
} else if (type == WL_PM_WORKQ_LONG) {
wq_duration = (WL_PM_ENABLE_TIMEOUT*2);
}
if (wq_duration) {
DHD_OS_WAKE_LOCK(cfg->pub);
schedule_delayed_work(&cfg->pm_enable_work,
msecs_to_jiffies((const unsigned int)wq_duration));
}
mutex_unlock(&cfg->pm_sync);
}
/* 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
*/
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(struct bcm_cfg80211 *cfg, s32 bssidx, 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_cfg80211_ulb_get_min_bw_chspec(cfg, NULL, bssidx);
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
*/
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);
}
/* 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;
s32 bssidx = 0; /* Explicitly set to primary bssidx */
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(cfg, bssidx, 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(cfg, bssidx, 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(const 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 */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0))
unsigned char name_assign_type,
#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)) */
enum nl80211_iftype type, u32 *flags,
struct vif_params *params)
{
s32 err = -ENODEV;
s32 timeout = -1;
s32 wlif_type = -1;
s32 mode = 0;
s32 val = 0;
s32 cfg_type;
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 WL_VIRTUAL_APSTA
bcm_struct_cfgdev *new_cfgdev;
#endif /* WL_VIRTUAL_APSTA */
dhd_pub_t *dhd;
#ifdef PROP_TXSTATUS_VSDB
#if defined(BCMSDIO)
s32 up = 1;
bool enabled;
#endif
#endif /* PROP_TXSTATUS_VSDB */
#if defined(SUPPORT_AP_POWERSAVE)
dhd_pub_t *dhd;
#endif /* SUPPORT_AP_POWERSAVE */
bool hang_required = false;
if (!cfg)
return ERR_PTR(-EINVAL);
dhd = (dhd_pub_t *)(cfg->pub);
#if defined(SUPPORT_AP_POWERSAVE)
dhd = (dhd_pub_t *)(cfg->pub);
#endif /* SUPPORT_AP_POWERSAVE */
/* 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);
}
if (!name) {
WL_ERR(("Interface name not provided \n"));
return ERR_PTR(-EINVAL);
}
#ifdef WLTDLS
/* disable TDLS if number of connected interfaces is >= 1 */
wl_cfg80211_tdls_config(cfg, TDLS_STATE_IF_CREATE, false);
#endif /* WLTDLS */
mutex_lock(&cfg->if_sync);
WL_DBG(("if name: %s, type: %d\n", name, type));
switch (type) {
case NL80211_IFTYPE_ADHOC:
#ifdef WLAIBSS_MCHAN
new_cfgdev = bcm_cfg80211_add_ibss_if(wiphy, (char *)name);
mutex_unlock(&cfg->if_sync);
return new_cfgdev;
#endif /* WLAIBSS_MCHAN */
case NL80211_IFTYPE_AP_VLAN:
case NL80211_IFTYPE_WDS:
case NL80211_IFTYPE_MESH_POINT:
WL_ERR(("Unsupported interface type\n"));
mode = WL_MODE_IBSS;
err = -EINVAL;
goto fail;
case NL80211_IFTYPE_MONITOR:
new_cfgdev = wl_cfg80211_add_monitor_if(name);
mutex_unlock(&cfg->if_sync);
return new_cfgdev;
#if defined(WL_CFG80211_P2P_DEV_IF)
case NL80211_IFTYPE_P2P_DEVICE:
cfg->down_disc_if = FALSE;
new_cfgdev = wl_cfgp2p_add_p2p_disc_if(cfg);
mutex_unlock(&cfg->if_sync);
return new_cfgdev;
#endif /* WL_CFG80211_P2P_DEV_IF */
case NL80211_IFTYPE_STATION:
#ifdef WL_VIRTUAL_APSTA
#ifdef WLAIBSS_MCHAN
if (cfg->ibss_cfgdev) {
WL_ERR(("AIBSS is already operational. "
" AIBSS & DUALSTA can't be used together \n"));
err = -ENOMEM;
goto fail;
}
#endif /* WLAIBSS_MCHAN */
if (wl_cfgp2p_vif_created(cfg)) {
WL_ERR(("Could not create new iface."
"Already one p2p interface is running"));
err = -ENOMEM;
goto fail;
}
new_cfgdev = wl_cfg80211_create_iface(cfg->wdev->wiphy,
NL80211_IFTYPE_STATION, NULL, name);
if (!new_cfgdev) {
err = -ENOMEM;
goto fail;
} else {
mutex_unlock(&cfg->if_sync);
return new_cfgdev;
}
#endif /* WL_VIRTUAL_APSTA */
case NL80211_IFTYPE_P2P_CLIENT:
wlif_type = WL_P2P_IF_CLIENT;
mode = WL_MODE_BSS;
break;
case NL80211_IFTYPE_P2P_GO:
wlif_type = WL_P2P_IF_GO;
mode = WL_MODE_AP;
break;
#ifdef WL_VIRTUAL_APSTA
case NL80211_IFTYPE_AP:
dhd->op_mode = DHD_FLAG_HOSTAP_MODE;
new_cfgdev = wl_cfg80211_create_iface(cfg->wdev->wiphy,
NL80211_IFTYPE_AP, NULL, name);
if (!new_cfgdev) {
err = -ENOMEM;
goto fail;
} else {
mutex_unlock(&cfg->if_sync);
return new_cfgdev;
}
#endif /* WL_VIRTUAL_APSTA */
default:
WL_ERR(("Unsupported interface type\n"));
err = -EINVAL;
goto fail;
}
if (cfg->p2p_supported && (wlif_type != -1)) {
ASSERT(cfg->p2p); /* ensure expectation of p2p initialization */
#ifdef PROP_TXSTATUS_VSDB
#if defined(BCMSDIO)
if (!dhd) {
err = -EINVAL;
goto fail;
}
#endif
#endif /* PROP_TXSTATUS_VSDB */
if (!cfg->p2p) {
WL_ERR(("Failed to start p2p"));
err = -ENODEV;
goto fail;
}
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(cfg, &primary_mac);
}
strncpy(cfg->p2p->vir_ifname, name, IFNAMSIZ - 1);
cfg->p2p->vir_ifname[IFNAMSIZ - 1] = '\0';
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 */
/* Dual p2p doesn't support multiple P2PGO interfaces,
* p2p_go_count is the counter for GO creation
* requests.
*/
if ((cfg->p2p->p2p_go_count > 0) && (type == NL80211_IFTYPE_P2P_GO)) {
WL_ERR(("Fw doesnot support multiple Go"));
err = -ENOTSUPP;
goto fail;
}
/* 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));
cfg_type = wl_cfgp2p_get_conn_idx(cfg);
if (cfg_type == BCME_ERROR) {
wl_clr_p2p_status(cfg, IF_ADDING);
WL_ERR(("Failed to get connection idx for p2p interface"));
err = -ENOTSUPP;
goto fail;
}
err = wl_cfgp2p_ifadd(cfg, wl_to_p2p_bss_macaddr(cfg, cfg_type),
htod32(wlif_type), chspec);
if (unlikely(err)) {
wl_clr_p2p_status(cfg, IF_ADDING);
WL_ERR((" virtual iface add failed (%d) \n", err));
err = -ENOMEM;
goto fail;
}
timeout = wait_event_interruptible_timeout(cfg->netif_change_event,
((wl_get_p2p_status(cfg, IF_ADDING) == false) &&
(cfg->if_event_info.valid)),
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)
*/
new_ndev = wl_cfg80211_allocate_if(cfg, event->ifidx, cfg->p2p->vir_ifname,
event->mac, event->bssidx, event->name);
if (new_ndev == NULL) {
err = -ENODEV;
goto fail;
}
wl_to_p2p_bss_ndev(cfg, cfg_type) = new_ndev;
wl_to_p2p_bss_bssidx(cfg, cfg_type) = event->bssidx;
vwdev = kzalloc(sizeof(*vwdev), GFP_KERNEL);
if (unlikely(!vwdev)) {
WL_ERR(("Could not allocate wireless device\n"));
err = -ENOMEM;
goto fail;
}
vwdev->wiphy = cfg->wdev->wiphy;
WL_INFORM(("virtual interface(%s) is created\n", cfg->p2p->vir_ifname));
if (type == NL80211_IFTYPE_P2P_GO) {
cfg->p2p->p2p_go_count++;
}
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);
if (wl_config_ifmode(cfg, new_ndev, type) < 0) {
WL_ERR(("conf ifmode failed\n"));
kfree(vwdev);
err = -ENOTSUPP;
goto fail;
}
if (wl_cfg80211_register_if(cfg,
event->ifidx, new_ndev, FALSE) != BCME_OK) {
wl_cfg80211_remove_if(cfg, event->ifidx, new_ndev, FALSE);
err = -ENODEV;
goto fail;
}
err = wl_alloc_netinfo(cfg, new_ndev, vwdev, mode, pm_mode, event->bssidx);
if (unlikely(err != 0)) {
wl_cfg80211_remove_if(cfg, event->ifidx, new_ndev, FALSE);
WL_ERR(("Allocation of netinfo failed (%d) \n", err));
goto fail;
}
val = 1;
/* Disable firmware roaming for P2P interface */
wldev_iovar_setint(new_ndev, "roam_off", val);
wldev_iovar_setint(new_ndev, "bcn_timeout", dhd->conf->bcn_timeout);
#ifdef WL11ULB
if (cfg->p2p_wdev && is_p2p_group_iface(new_ndev->ieee80211_ptr)) {
u32 ulb_bw = wl_cfg80211_get_ulb_bw(cfg, cfg->p2p_wdev);
if (ulb_bw) {
/* Apply ULB BW settings on the newly spawned interface */
WL_DBG(("[ULB] Applying ULB BW for the newly"
"created P2P interface \n"));
if (wl_cfg80211_set_ulb_bw(new_ndev,
ulb_bw, new_ndev->name) < 0) {
/*
* If ulb_bw set failed, fail the iface creation.
* wl_dealloc_netinfo_by_wdev will be called by the
* unregister notifier.
*/
wl_cfg80211_remove_if(cfg,
event->ifidx, new_ndev, FALSE);
err = -EINVAL;
goto fail;
}
}
}
#endif /* WL11ULB */
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);
#ifdef SUPPORT_AP_POWERSAVE
if (mode == WL_MODE_AP) {
dhd_set_ap_powersave(dhd, 0, TRUE);
}
#endif /* SUPPORT_AP_POWERSAVE */
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
mutex_unlock(&cfg->if_sync);
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));
WL_ERR(("left timeout : %d\n", timeout));
WL_ERR(("IF_ADDING status : %d\n", wl_get_p2p_status(cfg, IF_ADDING)));
WL_ERR(("event valid : %d\n", cfg->if_event_info.valid));
wl_clr_p2p_status(cfg, GO_NEG_PHASE);
wl_set_p2p_status(cfg, IF_DELETING);
hang_required = true;
if ((err = wl_cfgp2p_ifdel(cfg,
wl_to_p2p_bss_macaddr(cfg,
cfg_type))) == BCME_OK) {
timeout = wait_event_interruptible_timeout(cfg->netif_change_event,
((wl_get_p2p_status(cfg, IF_DELETING) == false) &&
(cfg->if_event_info.valid)),
msecs_to_jiffies(MAX_WAIT_TIME));
if (timeout > 0 && !wl_get_p2p_status(cfg, IF_DELETING) &&
cfg->if_event_info.valid) {
hang_required = false;
WL_ERR(("IFDEL operation done\n"));
} else {
WL_ERR(("IFDEL didn't complete properly\n"));
}
err = -ENODEV;
#ifdef SUPPORT_SET_CAC
wl_cfg80211_set_cac(cfg, 1);
#endif /* SUPPORT_SET_CAC */
} else {
WL_ERR(("IFDEL operation failed, error code = %d\n", err));
}
memset(cfg->p2p->vir_ifname, '\0', IFNAMSIZ);
wl_to_p2p_bss_bssidx(cfg, cfg_type) = -1;
#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:
mutex_unlock(&cfg->if_sync);
if (err) {
#ifdef WLTDLS
/* Enable back TDLS on failure */
wl_cfg80211_tdls_config(cfg, TDLS_STATE_IF_DELETE, false);
#endif /* WLTDLS */
if (err != -ENOTSUPP) {
#if defined(BCMPCIE) && defined(DHD_FW_COREDUMP)
if (dhd->memdump_enabled) {
/* Load the dongle side dump to host
* memory and then BUG_ON()
*/
dhd->memdump_type = DUMP_TYPE_HANG_ON_IFACE_OP_FAIL;
dhd_bus_mem_dump(dhd);
}
#endif /* BCMPCIE && DHD_FW_COREDUMP */
if (hang_required) {
/* Notify the user space to recover */
struct net_device *ndev = bcmcfg_to_prmry_ndev(cfg);
WL_ERR(("if add failed, error %d, sent HANG event to %s\n",
err, ndev->name));
dhd->hang_reason = HANG_REASON_IFACE_OP_FAILURE;
net_os_send_hang_message(ndev);
}
}
}
return ERR_PTR(err);
}
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;
s32 type = -1;
#ifdef CUSTOM_SET_CPUCORE
dhd_pub_t *dhd = (dhd_pub_t *)(cfg->pub);
#endif /* CUSTOM_SET_CPUCORE */
WL_DBG(("Enter\n"));
memset(&p2p_mac, 0, sizeof(struct ether_addr));
#ifdef CUSTOM_SET_CPUCORE
dhd->chan_isvht80 &= ~DHD_FLAG_P2P_MODE;
if (!(dhd->chan_isvht80))
dhd_set_cpucore(dhd, FALSE);
#endif /* CUSTOM_SET_CPUCORE */
mutex_lock(&cfg->if_sync);
#ifdef WL_CFG80211_P2P_DEV_IF
if (cfgdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
if (dhd_download_fw_on_driverload) {
ret = wl_cfgp2p_del_p2p_disc_if(cfgdev, cfg);
} else {
cfg->down_disc_if = TRUE;
ret = 0;
}
mutex_unlock(&cfg->if_sync);
return ret;
}
#endif /* WL_CFG80211_P2P_DEV_IF */
dev = cfgdev_to_wlc_ndev(cfgdev, cfg);
#ifdef WLAIBSS_MCHAN
if (cfgdev == cfg->ibss_cfgdev) {
ret = bcm_cfg80211_del_ibss_if(wiphy, cfgdev);
goto done;
}
#endif /* WLAIBSS_MCHAN */
if ((index = wl_get_bssidx_by_wdev(cfg, cfgdev_to_wdev(cfgdev))) < 0) {
WL_ERR(("Find p2p index from wdev failed\n"));
ret = -ENODEV;
goto done;
}
if (wl_check_dongle_idle(wiphy) != TRUE) {
WL_ERR(("FW is busy to add interface"));
return BCME_ERROR;
}
if ((cfg->p2p_supported) && index && (wl_cfgp2p_find_type(cfg, index, &type) == BCME_OK)) {
/* Handle P2P Interace del */
memcpy(p2p_mac.octet, wl_to_p2p_bss_macaddr(cfg, type).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 (wl_cfgp2p_vif_created(cfg)) {
if (wl_get_drv_status(cfg, SCANNING, dev)) {
wl_notify_escan_complete(cfg, dev, true, true);
}
/* Delete pm_enable_work */
wl_add_remove_pm_enable_work(cfg, WL_PM_WORKQ_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);
cfg->p2p->p2p_go_count--;
/* 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_cfg80211_clear_per_bss_ies(cfg, index);
if (wl_get_mode_by_netdev(cfg, dev) != WL_MODE_AP)
wldev_iovar_setint(dev, "buf_key_b4_m4", 0);
memcpy(p2p_mac.octet, wl_to_p2p_bss_macaddr(cfg, type).octet,
ETHER_ADDR_LEN);
CFGP2P_INFO(("primary idx %d : cfg p2p_ifdis "MACDBG"\n",
dev->ifindex, MAC2STRDBG(p2p_mac.octet)));
/* 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);
dhd_pub_t *dhd = (dhd_pub_t *)(cfg->pub);
WL_ERR(("p2p_ifdel failed, error %d, sent HANG event to %s\n",
ret, ndev->name));
dhd->hang_reason = HANG_REASON_IFACE_OP_FAILURE;
net_os_send_hang_message(ndev);
} 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) &&
(cfg->if_event_info.valid)),
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));
}
}
} else if ((dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP) ||
(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION)) {
#ifdef WL_VIRTUAL_APSTA
ret = wl_cfg80211_del_iface(wiphy, cfgdev);
#else
WL_ERR(("Virtual APSTA not supported!\n"));
#endif /* WL_VIRTUAL_APSTA */
}
done:
mutex_unlock(&cfg->if_sync);
#ifdef WLTDLS
if (ret == BCME_OK) {
/* If interface del is success, try enabling back TDLS */
wl_cfg80211_tdls_config(cfg, TDLS_STATE_IF_DELETE, false);
}
#endif /* WLTDLS */
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_ibss = 1;
s32 wlif_type;
s32 mode = 0;
s32 err = BCME_OK;
s32 index;
s32 conn_idx = -1;
chanspec_t chspec;
struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
dhd_pub_t *dhd = (dhd_pub_t *)(cfg->pub);
mutex_lock(&cfg->if_sync);
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;
infra_ibss = 0;
break;
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_P2P_CLIENT:
if (ndev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP) {
s32 bssidx = wl_get_bssidx_by_wdev(cfg, ndev->ieee80211_ptr);
if (bssidx < 0) {
/* validate bssidx */
WL_ERR(("Wrong bssidx! \n"));
err = -EINVAL;
goto error;
}
WL_DBG(("del interface. bssidx:%d", bssidx));
/* Downgrade role from AP to STA */
if ((err = wl_cfg80211_add_del_bss(cfg, ndev,
bssidx, NL80211_IFTYPE_STATION, 0, NULL)) < 0) {
WL_ERR(("AP-STA Downgrade failed \n"));
err = -EINVAL;
goto error;
}
}
mode = WL_MODE_BSS;
break;
case NL80211_IFTYPE_AP:
dhd->op_mode |= DHD_FLAG_HOSTAP_MODE;
/* intentional fall through */
case NL80211_IFTYPE_AP_VLAN:
case NL80211_IFTYPE_P2P_GO:
mode = WL_MODE_AP;
ap = 1;
break;
default:
err = -EINVAL;
goto error;
}
/* If any scan is going on, abort it */
if (wl_get_drv_status_all(cfg, SCANNING)) {
int wait_cnt = MAX_SCAN_ABORT_WAIT_CNT;
WL_ERR(("Scan in progress. Aborting the scan!\n"));
wl_cfg80211_scan_abort(cfg);
while (wl_get_drv_status_all(cfg, SCANNING) && wait_cnt) {
WL_DBG(("Waiting for SCANNING terminated, wait_cnt: %d\n", wait_cnt));
wait_cnt--;
OSL_SLEEP(WAIT_SCAN_ABORT_OSL_SLEEP_TIME);
}
if (wl_get_drv_status_all(cfg, SCANNING)) {
wl_notify_escan_complete(cfg, cfg->escan_info.ndev, true, true);
}
}
if (wl_check_dongle_idle(wiphy) != TRUE) {
WL_ERR(("FW is busy to add interface\n"));
err = -EINVAL;
goto error;
}
if (!dhd) {
err = -EINVAL;
goto error;
}
if (ap) {
wl_set_mode_by_netdev(cfg, ndev, mode);
if (is_p2p_group_iface(ndev->ieee80211_ptr) &&
cfg->p2p && wl_cfgp2p_vif_created(cfg)) {
WL_DBG(("p2p_vif_created p2p_on (%d)\n", p2p_on(cfg)));
wl_notify_escan_complete(cfg, ndev, true, true);
/* Dual p2p doesn't support multiple P2PGO interfaces,
* p2p_go_count is the counter for GO creation
* requests.
*/
if ((cfg->p2p->p2p_go_count > 0) && (type == NL80211_IFTYPE_P2P_GO)) {
wl_set_mode_by_netdev(cfg, ndev, WL_MODE_BSS);
WL_ERR(("Fw doesnot support multiple GO "));
err = BCME_ERROR;
goto error;
}
/* 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);
index = wl_get_bssidx_by_wdev(cfg, ndev->ieee80211_ptr);
if (index < 0) {
WL_ERR(("Find p2p index from ndev(%p) failed\n", ndev));
err = BCME_ERROR;
goto error;
}
if (wl_cfgp2p_find_type(cfg, index, &conn_idx) != BCME_OK) {
err = BCME_ERROR;
goto error;
}
wlif_type = WL_P2P_IF_GO;
WL_DBG(("%s : ap (%d), infra_ibss (%d), iftype (%d) conn_idx (%d)\n",
ndev->name, ap, infra_ibss, type, conn_idx));
wl_set_p2p_status(cfg, IF_CHANGING);
wl_clr_p2p_status(cfg, IF_CHANGED);
wl_cfgp2p_ifchange(cfg, wl_to_p2p_bss_macaddr(cfg, conn_idx),
htod32(wlif_type), chspec, conn_idx);
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);
#ifdef SUPPORT_AP_POWERSAVE
dhd_set_ap_powersave(dhd, 0, TRUE);
#endif /* SUPPORT_AP_POWERSAVE */
} else if ((type == NL80211_IFTYPE_AP) &&
!wl_get_drv_status(cfg, AP_CREATED, ndev)) {
err = wl_cfg80211_set_ap_role(cfg, ndev);
if (unlikely(err)) {
WL_ERR(("set ap role failed!\n"));
goto error;
}
} else {
WL_ERR(("Cannot change the interface for GO or SOFTAP\n"));
err = -EINVAL;
goto error;
}
} else {
/* P2P GO interface deletion is handled on the basis of role type (AP).
* So avoid changing role for p2p type.
*/
if (ndev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
wl_set_mode_by_netdev(cfg, ndev, mode);
WL_DBG(("Change_virtual_iface for transition from GO/AP to client/STA\n"));
#ifdef SUPPORT_AP_POWERSAVE
dhd_set_ap_powersave(dhd, 0, FALSE);
#endif /* SUPPORT_AP_POWERSAVE */
}
err = wldev_ioctl(ndev, WLC_SET_INFRA, &infra_ibss, sizeof(s32), true);
if (err < 0) {
WL_ERR(("SET INFRA/IBSS error %d\n", err));
err = -EINVAL;
goto error;
}
WL_DBG(("Setting iftype to %d \n", type));
ndev->ieee80211_ptr->iftype = type;
error:
mutex_unlock(&cfg->if_sync);
return err;
}
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_CONNECTION1) &&
bssidx != wl_to_p2p_bss_bssidx(cfg, P2PAPI_BSSCFG_CONNECTION2)) {
WL_ERR(("got IF_DEL for if %d, not owned by cfg driver\n", bssidx));
return BCME_ERROR;
}
if (p2p_is_on(cfg) && wl_cfgp2p_vif_created(cfg)) {
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) {
/* Update P2P data */
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) = -1;
} else if (wl_get_bssidx_by_wdev(cfg, ndev->ieee80211_ptr) < 0) {
WL_ERR(("bssidx not known for the given ndev as per net_info data \n"));
return BCME_ERROR;
}
#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->conf->disable_proptx!=0) {
dhd_wlfc_deinit(dhd);
cfg->wlfc_on = false;
}
#endif
#endif /* PROP_TXSTATUS_VSDB */
}
dhd_net_if_lock(ndev);
wl_cfg80211_remove_if(cfg, if_event_info->ifidx, ndev, FALSE);
dhd_net_if_unlock(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;
/* unfortunately const cast required here - function is
* a callback so its signature must not be changed
* and cascade of changing wl_cfgp2p_find_p2pie
* causes need for const cast in other places
*/
#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == \
4 && __GNUC_MINOR__ >= 6))
_Pragma("GCC diagnostic push")
_Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
#endif
pos = (u8 *)ie;
#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == \
4 && __GNUC_MINOR__ >= 6))
_Pragma("GCC diagnostic pop")
#endif
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;
struct wireless_dev *wdev;
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++) {
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 defined(WL_CFG80211_P2P_DEV_IF)
wdev = request->wdev;
#else
wdev = request->dev->ieee80211_ptr;
#endif /* WL_CFG80211_P2P_DEV_IF */
chanspec = wl_cfg80211_ulb_get_min_bw_chspec(cfg, wdev, -1);
if (chanspec == INVCHANSPEC) {
WL_ERR(("Invalid chanspec! Skipping channel\n"));
continue;
}
if (request->channels[i]->band == IEEE80211_BAND_2GHZ) {
chanspec |= WL_CHANSPEC_BAND_2G;
} else {
chanspec |= WL_CHANSPEC_BAND_5G;
}
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 = MIN(request->ssids[i].ssid_len, DOT11_MAX_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_SHORT_DWELL_TIME)
#define FIRST_SCAN_ACTIVE_DWELL_TIME_MS 40
bool g_first_broadcast_scan = TRUE;
#endif
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;
u32 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;
s32 bssidx = -1;
struct net_device *dev = NULL;
#if defined(USE_INITIAL_SHORT_DWELL_TIME)
bool is_first_init_2g_scan = false;
#endif
p2p_scan_purpose_t p2p_scan_purpose = P2P_SCAN_PURPOSE_MIN;
scb_val_t scbval;
static int cnt = 0;
WL_DBG(("Enter \n"));
/* scan request can come with empty request : perform all default scan */
if (!cfg) {
err = -EINVAL;
goto exit;
}
if (!cfg->p2p_supported || !p2p_scan(cfg)) {
/* LEGACY SCAN TRIGGER */
WL_SCAN((" LEGACY E-SCAN START\n"));
#if defined(USE_INITIAL_SHORT_DWELL_TIME)
if (!request) {
err = -EINVAL;
goto exit;
}
if (ndev == bcmcfg_to_prmry_ndev(cfg) && g_first_broadcast_scan == true) {
is_first_init_2g_scan = true;
g_first_broadcast_scan = false;
}
#endif
/* 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;