/**
* Functions implementing wlan scan IOCTL and firmware command APIs
*
* IOCTL handlers as well as command preperation and response routines
* for sending scan commands to the firmware.
*/
#include <linux/etherdevice.h>
#include <asm/unaligned.h>
#include "host.h"
#include "decl.h"
#include "dev.h"
#include "scan.h"
#include "cmd.h"
//! Approximate amount of data needed to pass a scan result back to iwlist
#define MAX_SCAN_CELL_SIZE (IW_EV_ADDR_LEN \
+ IW_ESSID_MAX_SIZE \
+ IW_EV_UINT_LEN \
+ IW_EV_FREQ_LEN \
+ IW_EV_QUAL_LEN \
+ IW_ESSID_MAX_SIZE \
+ IW_EV_PARAM_LEN \
+ 40) /* 40 for WPAIE */
//! Memory needed to store a max sized channel List TLV for a firmware scan
#define CHAN_TLV_MAX_SIZE (sizeof(struct mrvlietypesheader) \
+ (MRVDRV_MAX_CHANNELS_PER_SCAN \
* sizeof(struct chanscanparamset)))
//! Memory needed to store a max number/size SSID TLV for a firmware scan
#define SSID_TLV_MAX_SIZE (1 * sizeof(struct mrvlietypes_ssidparamset))
//! Maximum memory needed for a cmd_ds_802_11_scan with all TLVs at max
#define MAX_SCAN_CFG_ALLOC (sizeof(struct cmd_ds_802_11_scan) \
+ CHAN_TLV_MAX_SIZE + SSID_TLV_MAX_SIZE)
//! The maximum number of channels the firmware can scan per command
#define MRVDRV_MAX_CHANNELS_PER_SCAN 14
/**
* @brief Number of channels to scan per firmware scan command issuance.
*
* Number restricted to prevent hitting the limit on the amount of scan data
* returned in a single firmware scan command.
*/
#define MRVDRV_CHANNELS_PER_SCAN_CMD 4
//! Scan time specified in the channel TLV for each channel for passive scans
#define MRVDRV_PASSIVE_SCAN_CHAN_TIME 100
//! Scan time specified in the channel TLV for each channel for active scans
#define MRVDRV_ACTIVE_SCAN_CHAN_TIME 100
static int lbs_ret_80211_scan(struct lbs_private *priv, unsigned long dummy,
struct cmd_header *resp);
/*********************************************************************/
/* */
/* Misc helper functions */
/* */
/*********************************************************************/
/**
* @brief Unsets the MSB on basic rates
*
* Scan through an array and unset the MSB for basic data rates.
*
* @param rates buffer of data rates
* @param len size of buffer
*/
static void lbs_unset_basic_rate_flags(u8 *rates, size_t len)
{
int i;
for (i = 0; i < len; i++)
rates[i] &= 0x7f;
}
static inline void clear_bss_descriptor(struct bss_descriptor *bss)
{
/* Don't blow away ->list, just BSS data */
memset(bss, 0, offsetof(struct bss_descriptor, list));
}
/**
* @brief Compare two SSIDs
*
* @param ssid1 A pointer to ssid to compare
* @param ssid2 A pointer to ssid to compare
*
* @return 0: ssid is same, otherwise is different
*/
int lbs_ssid_cmp(uint8_t *ssid1, uint8_t ssid1_len, uint8_t *ssid2,
uint8_t ssid2_len)
{
if (ssid1_len != ssid2_len)
return -1;
return memcmp(ssid1, ssid2, ssid1_len);
}
static inline int is_same_network(struct bss_descriptor *src,
struct bss_descriptor *dst)
{
/* A network is only a duplicate if the channel, BSSID, and ESSID
* all match. We treat all <hidden> with the same BSSID and channel
* as one network */
return ((src->ssid_len == dst->ssid_len) &&
(src->channel == dst->channel) &&
!compare_ether_addr(src->bssid, dst->bssid) &&
!memcmp(src->ssid, dst->ssid, src->ssid_len));
}
/*********************************************************************/
/* */
/* Main scanning support */
/* */
/*********************************************************************/
/**
* @brief Create a channel list for the driver to scan based on region info
*
* Only used from lbs_scan_setup_scan_config()
*
* Use the driver region/band information to construct a comprehensive list
* of channels to scan. This routine is used for any scan that is not
* provided a specific channel list to scan.
*
* @param priv A pointer to struct lbs_private structure
* @param scanchanlist Output parameter: resulting channel list to scan
*
* @return void
*/
static int lbs_scan_create_channel_list(struct lbs_private *priv,
struct chanscanparamset *scanchanlist)
{
struct region_channel *scanregion;
struct chan_freq_power *cfp;
int rgnidx;
int chanidx;
int nextchan;
uint8_t scantype;
chanidx = 0;
/* Set the default scan type to the user specified type, will later
* be changed to passive on a per channel basis if restricted by
* regulatory requirements (11d or 11h)
*/