2007-02-10 09:25:27 -05:00
|
|
|
/**
|
|
|
|
* 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/ctype.h>
|
|
|
|
#include <linux/if.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/wireless.h>
|
2007-05-25 16:15:56 -04:00
|
|
|
#include <linux/etherdevice.h>
|
2007-02-10 09:25:27 -05:00
|
|
|
|
|
|
|
#include <net/ieee80211.h>
|
|
|
|
#include <net/iw_handler.h>
|
|
|
|
|
2007-09-06 21:45:36 -04:00
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
2007-02-10 09:25:27 -05:00
|
|
|
#include "host.h"
|
|
|
|
#include "decl.h"
|
|
|
|
#include "dev.h"
|
|
|
|
#include "scan.h"
|
2007-08-02 11:40:45 -04:00
|
|
|
#include "join.h"
|
2007-02-10 09:25:27 -05:00
|
|
|
|
|
|
|
//! 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))
|
|
|
|
|
2007-11-15 18:05:47 -05:00
|
|
|
//! Maximum memory needed for a lbs_scan_cmd_config with all TLVs at max
|
|
|
|
#define MAX_SCAN_CFG_ALLOC (sizeof(struct lbs_scan_cmd_config) \
|
2007-02-10 09:25:27 -05:00
|
|
|
+ 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
|
|
|
|
|
2007-05-25 23:23:43 -04:00
|
|
|
static const u8 zeromac[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
static const u8 bcastmac[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
2007-05-25 16:25:21 -04:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Misc helper functions */
|
|
|
|
/* */
|
|
|
|
/*********************************************************************/
|
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
/**
|
|
|
|
* @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(u8 *ssid1, u8 ssid1_len, u8 *ssid2, u8 ssid2_len)
|
|
|
|
{
|
|
|
|
if (ssid1_len != ssid2_len)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return memcmp(ssid1, ssid2, ssid1_len);
|
|
|
|
}
|
|
|
|
|
2007-11-15 18:05:47 -05:00
|
|
|
static inline int match_bss_no_security(struct lbs_802_11_security *secinfo,
|
2007-05-25 16:15:56 -04:00
|
|
|
struct bss_descriptor * match_bss)
|
|
|
|
{
|
|
|
|
if ( !secinfo->wep_enabled
|
|
|
|
&& !secinfo->WPAenabled
|
|
|
|
&& !secinfo->WPA2enabled
|
2007-08-02 10:48:02 -04:00
|
|
|
&& match_bss->wpa_ie[0] != MFIE_TYPE_GENERIC
|
|
|
|
&& match_bss->rsn_ie[0] != MFIE_TYPE_RSN
|
2007-08-02 10:43:44 -04:00
|
|
|
&& !(match_bss->capability & WLAN_CAPABILITY_PRIVACY)) {
|
2007-05-25 16:15:56 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-15 18:05:47 -05:00
|
|
|
static inline int match_bss_static_wep(struct lbs_802_11_security *secinfo,
|
2007-05-25 16:15:56 -04:00
|
|
|
struct bss_descriptor * match_bss)
|
|
|
|
{
|
|
|
|
if ( secinfo->wep_enabled
|
|
|
|
&& !secinfo->WPAenabled
|
|
|
|
&& !secinfo->WPA2enabled
|
2007-08-02 10:43:44 -04:00
|
|
|
&& (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) {
|
2007-05-25 16:15:56 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-15 18:05:47 -05:00
|
|
|
static inline int match_bss_wpa(struct lbs_802_11_security *secinfo,
|
2007-05-25 16:15:56 -04:00
|
|
|
struct bss_descriptor * match_bss)
|
|
|
|
{
|
|
|
|
if ( !secinfo->wep_enabled
|
|
|
|
&& secinfo->WPAenabled
|
2007-08-02 10:48:02 -04:00
|
|
|
&& (match_bss->wpa_ie[0] == MFIE_TYPE_GENERIC)
|
2007-05-25 16:15:56 -04:00
|
|
|
/* privacy bit may NOT be set in some APs like LinkSys WRT54G
|
2007-08-02 10:43:44 -04:00
|
|
|
&& (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) {
|
|
|
|
*/
|
2007-05-25 16:15:56 -04:00
|
|
|
) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-15 18:05:47 -05:00
|
|
|
static inline int match_bss_wpa2(struct lbs_802_11_security *secinfo,
|
2007-05-25 16:15:56 -04:00
|
|
|
struct bss_descriptor * match_bss)
|
|
|
|
{
|
|
|
|
if ( !secinfo->wep_enabled
|
|
|
|
&& secinfo->WPA2enabled
|
2007-08-02 10:48:02 -04:00
|
|
|
&& (match_bss->rsn_ie[0] == MFIE_TYPE_RSN)
|
2007-05-25 16:15:56 -04:00
|
|
|
/* privacy bit may NOT be set in some APs like LinkSys WRT54G
|
2007-08-02 10:43:44 -04:00
|
|
|
&& (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) {
|
|
|
|
*/
|
2007-05-25 16:15:56 -04:00
|
|
|
) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-15 18:05:47 -05:00
|
|
|
static inline int match_bss_dynamic_wep(struct lbs_802_11_security *secinfo,
|
2007-05-25 16:15:56 -04:00
|
|
|
struct bss_descriptor * match_bss)
|
|
|
|
{
|
|
|
|
if ( !secinfo->wep_enabled
|
|
|
|
&& !secinfo->WPAenabled
|
|
|
|
&& !secinfo->WPA2enabled
|
2007-08-02 10:48:02 -04:00
|
|
|
&& (match_bss->wpa_ie[0] != MFIE_TYPE_GENERIC)
|
|
|
|
&& (match_bss->rsn_ie[0] != MFIE_TYPE_RSN)
|
2007-08-02 10:43:44 -04:00
|
|
|
&& (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) {
|
2007-05-25 16:15:56 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2007-02-10 09:25:27 -05:00
|
|
|
/**
|
|
|
|
* @brief Check if a scanned network compatible with the driver settings
|
|
|
|
*
|
|
|
|
* WEP WPA WPA2 ad-hoc encrypt Network
|
|
|
|
* enabled enabled enabled AES mode privacy WPA WPA2 Compatible
|
|
|
|
* 0 0 0 0 NONE 0 0 0 yes No security
|
|
|
|
* 1 0 0 0 NONE 1 0 0 yes Static WEP
|
|
|
|
* 0 1 0 0 x 1x 1 x yes WPA
|
|
|
|
* 0 0 1 0 x 1x x 1 yes WPA2
|
|
|
|
* 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
|
|
|
|
* 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
|
|
|
|
*
|
|
|
|
*
|
2007-12-08 15:04:36 -05:00
|
|
|
* @param priv A pointer to struct lbs_private
|
2007-02-10 09:25:27 -05:00
|
|
|
* @param index Index in scantable to check against current driver settings
|
|
|
|
* @param mode Network mode: Infrastructure or IBSS
|
|
|
|
*
|
|
|
|
* @return Index in scantable, or error code if negative
|
|
|
|
*/
|
2007-12-08 15:04:36 -05:00
|
|
|
static int is_network_compatible(struct lbs_private *priv,
|
2007-05-25 16:15:56 -04:00
|
|
|
struct bss_descriptor * bss, u8 mode)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
2007-05-25 16:15:56 -04:00
|
|
|
int matched = 0;
|
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
if (bss->mode != mode)
|
|
|
|
goto done;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
if ((matched = match_bss_no_security(&priv->secinfo, bss))) {
|
2007-05-25 16:15:56 -04:00
|
|
|
goto done;
|
2007-12-08 15:04:36 -05:00
|
|
|
} else if ((matched = match_bss_static_wep(&priv->secinfo, bss))) {
|
2007-05-25 16:15:56 -04:00
|
|
|
goto done;
|
2007-12-08 15:04:36 -05:00
|
|
|
} else if ((matched = match_bss_wpa(&priv->secinfo, bss))) {
|
2007-05-25 16:15:56 -04:00
|
|
|
lbs_deb_scan(
|
2007-12-07 10:52:10 -05:00
|
|
|
"is_network_compatible() WPA: wpa_ie 0x%x "
|
|
|
|
"wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
|
|
|
|
"privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0],
|
2007-12-08 15:04:36 -05:00
|
|
|
priv->secinfo.wep_enabled ? "e" : "d",
|
|
|
|
priv->secinfo.WPAenabled ? "e" : "d",
|
|
|
|
priv->secinfo.WPA2enabled ? "e" : "d",
|
2007-08-02 10:43:44 -04:00
|
|
|
(bss->capability & WLAN_CAPABILITY_PRIVACY));
|
2007-05-25 16:15:56 -04:00
|
|
|
goto done;
|
2007-12-08 15:04:36 -05:00
|
|
|
} else if ((matched = match_bss_wpa2(&priv->secinfo, bss))) {
|
2007-05-25 16:15:56 -04:00
|
|
|
lbs_deb_scan(
|
2007-12-07 10:52:10 -05:00
|
|
|
"is_network_compatible() WPA2: wpa_ie 0x%x "
|
|
|
|
"wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
|
|
|
|
"privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0],
|
2007-12-08 15:04:36 -05:00
|
|
|
priv->secinfo.wep_enabled ? "e" : "d",
|
|
|
|
priv->secinfo.WPAenabled ? "e" : "d",
|
|
|
|
priv->secinfo.WPA2enabled ? "e" : "d",
|
2007-08-02 10:43:44 -04:00
|
|
|
(bss->capability & WLAN_CAPABILITY_PRIVACY));
|
2007-05-25 16:15:56 -04:00
|
|
|
goto done;
|
2007-12-08 15:04:36 -05:00
|
|
|
} else if ((matched = match_bss_dynamic_wep(&priv->secinfo, bss))) {
|
2007-05-25 16:15:56 -04:00
|
|
|
lbs_deb_scan(
|
|
|
|
"is_network_compatible() dynamic WEP: "
|
2007-12-07 10:52:10 -05:00
|
|
|
"wpa_ie 0x%x wpa2_ie 0x%x privacy 0x%x\n",
|
2007-08-02 10:43:44 -04:00
|
|
|
bss->wpa_ie[0], bss->rsn_ie[0],
|
|
|
|
(bss->capability & WLAN_CAPABILITY_PRIVACY));
|
2007-05-25 11:27:16 -04:00
|
|
|
goto done;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
/* bss security settings don't match those configured on card */
|
|
|
|
lbs_deb_scan(
|
2007-12-07 10:52:10 -05:00
|
|
|
"is_network_compatible() FAILED: wpa_ie 0x%x "
|
|
|
|
"wpa2_ie 0x%x WEP %s WPA %s WPA2 %s privacy 0x%x\n",
|
2007-05-25 16:15:56 -04:00
|
|
|
bss->wpa_ie[0], bss->rsn_ie[0],
|
2007-12-08 15:04:36 -05:00
|
|
|
priv->secinfo.wep_enabled ? "e" : "d",
|
|
|
|
priv->secinfo.WPAenabled ? "e" : "d",
|
|
|
|
priv->secinfo.WPA2enabled ? "e" : "d",
|
2007-08-02 10:43:44 -04:00
|
|
|
(bss->capability & WLAN_CAPABILITY_PRIVACY));
|
2007-05-25 11:27:16 -04:00
|
|
|
|
|
|
|
done:
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "matched: %d", matched);
|
2007-05-25 16:15:56 -04:00
|
|
|
return matched;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Main scanning support */
|
|
|
|
/* */
|
|
|
|
/*********************************************************************/
|
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
void lbs_scan_worker(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv =
|
|
|
|
container_of(work, struct lbs_private, scan_work.work);
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
|
|
|
lbs_scan_networks(priv, NULL, 0);
|
|
|
|
lbs_deb_leave(LBS_DEB_SCAN);
|
|
|
|
}
|
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
|
2007-02-10 09:25:27 -05:00
|
|
|
/**
|
|
|
|
* @brief Create a channel list for the driver to scan based on region info
|
|
|
|
*
|
2007-11-15 18:05:47 -05:00
|
|
|
* Only used from lbs_scan_setup_scan_config()
|
2007-10-09 08:15:19 -04:00
|
|
|
*
|
2007-02-10 09:25:27 -05:00
|
|
|
* 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.
|
|
|
|
*
|
2007-11-23 09:43:44 -05:00
|
|
|
* @param priv A pointer to struct lbs_private structure
|
2007-02-10 09:25:27 -05:00
|
|
|
* @param scanchanlist Output parameter: resulting channel list to scan
|
|
|
|
* @param filteredscan Flag indicating whether or not a BSSID or SSID filter
|
|
|
|
* is being sent in the command to firmware. Used to
|
|
|
|
* increase the number of channels sent in a scan
|
|
|
|
* command and to disable the firmware channel scan
|
|
|
|
* filter.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-12-07 10:52:10 -05:00
|
|
|
static int lbs_scan_create_channel_list(struct lbs_private *priv,
|
2007-02-10 09:25:27 -05:00
|
|
|
struct chanscanparamset * scanchanlist,
|
|
|
|
u8 filteredscan)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct region_channel *scanregion;
|
|
|
|
struct chan_freq_power *cfp;
|
|
|
|
int rgnidx;
|
|
|
|
int chanidx;
|
|
|
|
int nextchan;
|
|
|
|
u8 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)
|
|
|
|
*/
|
2007-08-02 13:12:27 -04:00
|
|
|
scantype = CMD_SCAN_TYPE_ACTIVE;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
for (rgnidx = 0; rgnidx < ARRAY_SIZE(priv->region_channel); rgnidx++) {
|
|
|
|
if (priv->enable11d &&
|
|
|
|
(priv->connect_status != LBS_CONNECTED) &&
|
|
|
|
(priv->mesh_connect_status != LBS_CONNECTED)) {
|
2007-02-10 09:25:27 -05:00
|
|
|
/* Scan all the supported chan for the first scan */
|
2007-12-08 15:04:36 -05:00
|
|
|
if (!priv->universal_channel[rgnidx].valid)
|
2007-02-10 09:25:27 -05:00
|
|
|
continue;
|
2007-12-08 15:04:36 -05:00
|
|
|
scanregion = &priv->universal_channel[rgnidx];
|
2007-02-10 09:25:27 -05:00
|
|
|
|
|
|
|
/* clear the parsed_region_chan for the first scan */
|
2007-12-08 15:04:36 -05:00
|
|
|
memset(&priv->parsed_region_chan, 0x00,
|
|
|
|
sizeof(priv->parsed_region_chan));
|
2007-02-10 09:25:27 -05:00
|
|
|
} else {
|
2007-12-08 15:04:36 -05:00
|
|
|
if (!priv->region_channel[rgnidx].valid)
|
2007-02-10 09:25:27 -05:00
|
|
|
continue;
|
2007-12-08 15:04:36 -05:00
|
|
|
scanregion = &priv->region_channel[rgnidx];
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (nextchan = 0;
|
|
|
|
nextchan < scanregion->nrcfp; nextchan++, chanidx++) {
|
|
|
|
|
|
|
|
cfp = scanregion->CFP + nextchan;
|
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
if (priv->enable11d) {
|
2007-02-10 09:25:27 -05:00
|
|
|
scantype =
|
2007-11-15 18:05:47 -05:00
|
|
|
lbs_get_scan_type_11d(cfp->channel,
|
2007-12-08 15:04:36 -05:00
|
|
|
&priv->
|
2007-02-10 09:25:27 -05:00
|
|
|
parsed_region_chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (scanregion->band) {
|
|
|
|
case BAND_B:
|
|
|
|
case BAND_G:
|
|
|
|
default:
|
|
|
|
scanchanlist[chanidx].radiotype =
|
2007-08-02 11:31:18 -04:00
|
|
|
CMD_SCAN_RADIO_TYPE_BG;
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-08-02 11:31:18 -04:00
|
|
|
if (scantype == CMD_SCAN_TYPE_PASSIVE) {
|
2007-02-10 09:25:27 -05:00
|
|
|
scanchanlist[chanidx].maxscantime =
|
2007-05-25 23:36:54 -04:00
|
|
|
cpu_to_le16(MRVDRV_PASSIVE_SCAN_CHAN_TIME);
|
2007-02-10 09:25:27 -05:00
|
|
|
scanchanlist[chanidx].chanscanmode.passivescan =
|
|
|
|
1;
|
|
|
|
} else {
|
|
|
|
scanchanlist[chanidx].maxscantime =
|
2007-05-25 23:36:54 -04:00
|
|
|
cpu_to_le16(MRVDRV_ACTIVE_SCAN_CHAN_TIME);
|
2007-02-10 09:25:27 -05:00
|
|
|
scanchanlist[chanidx].chanscanmode.passivescan =
|
|
|
|
0;
|
|
|
|
}
|
|
|
|
|
|
|
|
scanchanlist[chanidx].channumber = cfp->channel;
|
|
|
|
|
|
|
|
if (filteredscan) {
|
|
|
|
scanchanlist[chanidx].chanscanmode.
|
|
|
|
disablechanfilt = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-07 10:52:10 -05:00
|
|
|
return chanidx;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-08-02 13:19:04 -04:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
/*
|
|
|
|
* Add SSID TLV of the form:
|
|
|
|
*
|
|
|
|
* TLV-ID SSID 00 00
|
|
|
|
* length 06 00
|
|
|
|
* ssid 4d 4e 54 45 53 54
|
|
|
|
*/
|
|
|
|
static int lbs_scan_add_ssid_tlv(u8 *tlv,
|
|
|
|
const struct lbs_ioctl_user_scan_cfg *user_cfg)
|
2007-08-02 13:19:04 -04:00
|
|
|
{
|
2007-12-07 10:52:10 -05:00
|
|
|
struct mrvlietypes_ssidparamset *ssid_tlv =
|
|
|
|
(struct mrvlietypes_ssidparamset *)tlv;
|
|
|
|
ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
|
|
|
|
ssid_tlv->header.len = cpu_to_le16(user_cfg->ssid_len);
|
|
|
|
memcpy(ssid_tlv->ssid, user_cfg->ssid, user_cfg->ssid_len);
|
|
|
|
return sizeof(ssid_tlv->header) + user_cfg->ssid_len;
|
2007-08-02 13:19:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
/*
|
|
|
|
* Add CHANLIST TLV of the form
|
2007-02-10 09:25:27 -05:00
|
|
|
*
|
2007-12-07 10:52:10 -05:00
|
|
|
* TLV-ID CHANLIST 01 01
|
|
|
|
* length 5b 00
|
|
|
|
* channel 1 00 01 00 00 00 64 00
|
|
|
|
* radio type 00
|
|
|
|
* channel 01
|
|
|
|
* scan type 00
|
|
|
|
* min scan time 00 00
|
|
|
|
* max scan time 64 00
|
|
|
|
* channel 2 00 02 00 00 00 64 00
|
|
|
|
* channel 3 00 03 00 00 00 64 00
|
|
|
|
* channel 4 00 04 00 00 00 64 00
|
|
|
|
* channel 5 00 05 00 00 00 64 00
|
|
|
|
* channel 6 00 06 00 00 00 64 00
|
|
|
|
* channel 7 00 07 00 00 00 64 00
|
|
|
|
* channel 8 00 08 00 00 00 64 00
|
|
|
|
* channel 9 00 09 00 00 00 64 00
|
|
|
|
* channel 10 00 0a 00 00 00 64 00
|
|
|
|
* channel 11 00 0b 00 00 00 64 00
|
|
|
|
* channel 12 00 0c 00 00 00 64 00
|
|
|
|
* channel 13 00 0d 00 00 00 64 00
|
2007-02-10 09:25:27 -05:00
|
|
|
*
|
|
|
|
*/
|
2007-12-07 10:52:10 -05:00
|
|
|
static int lbs_scan_add_chanlist_tlv(u8 *tlv,
|
|
|
|
struct chanscanparamset *chan_list,
|
|
|
|
int chan_count)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
2007-12-07 10:52:10 -05:00
|
|
|
size_t size = sizeof(struct chanscanparamset) * chan_count;
|
|
|
|
struct mrvlietypes_chanlistparamset *chan_tlv =
|
|
|
|
(struct mrvlietypes_chanlistparamset *) tlv;
|
|
|
|
|
|
|
|
chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
|
|
|
|
memcpy(chan_tlv->chanscanparam, chan_list, size);
|
|
|
|
chan_tlv->header.len = cpu_to_le16(size);
|
|
|
|
return sizeof(chan_tlv->header) + size;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add RATES TLV of the form
|
2007-02-10 09:25:27 -05:00
|
|
|
*
|
2007-12-07 10:52:10 -05:00
|
|
|
* TLV-ID RATES 01 00
|
|
|
|
* length 0e 00
|
|
|
|
* rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
|
2007-02-10 09:25:27 -05:00
|
|
|
*
|
2007-12-07 10:52:10 -05:00
|
|
|
* The rates are in lbs_bg_rates[], but for the 802.11b
|
|
|
|
* rates the high bit isn't set.
|
2007-02-10 09:25:27 -05:00
|
|
|
*/
|
2007-12-07 10:52:10 -05:00
|
|
|
static int lbs_scan_add_rates_tlv(u8 *tlv)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
2007-12-07 10:52:10 -05:00
|
|
|
int i;
|
|
|
|
struct mrvlietypes_ratesparamset *rate_tlv =
|
|
|
|
(struct mrvlietypes_ratesparamset *) tlv;
|
|
|
|
|
|
|
|
rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
|
|
|
|
tlv += sizeof(rate_tlv->header);
|
|
|
|
for (i = 0; i < MAX_RATES; i++) {
|
|
|
|
*tlv = lbs_bg_rates[i];
|
|
|
|
if (*tlv == 0)
|
|
|
|
break;
|
|
|
|
/* This code makes sure that the 802.11b rates (1 MBit/s, 2
|
|
|
|
MBit/s, 5.5 MBit/s and 11 MBit/s get's the high bit set.
|
|
|
|
Note that the values are MBit/s * 2, to mark them as
|
|
|
|
basic rates so that the firmware likes it better */
|
|
|
|
if (*tlv == 0x02 || *tlv == 0x04 ||
|
|
|
|
*tlv == 0x0b || *tlv == 0x16)
|
|
|
|
*tlv |= 0x80;
|
|
|
|
tlv++;
|
2007-08-02 13:19:04 -04:00
|
|
|
}
|
2007-12-07 10:52:10 -05:00
|
|
|
rate_tlv->header.len = cpu_to_le16(i);
|
|
|
|
return sizeof(rate_tlv->header) + i;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
/*
|
2007-12-07 10:52:10 -05:00
|
|
|
* Generate the CMD_802_11_SCAN command with the proper tlv
|
|
|
|
* for a bunch of channels.
|
|
|
|
*/
|
|
|
|
static int lbs_do_scan(struct lbs_private *priv,
|
|
|
|
u8 bsstype,
|
|
|
|
struct chanscanparamset *chan_list,
|
|
|
|
int chan_count,
|
|
|
|
const struct lbs_ioctl_user_scan_cfg *user_cfg)
|
2007-05-25 16:25:21 -04:00
|
|
|
{
|
2007-12-07 10:52:10 -05:00
|
|
|
int ret = -ENOMEM;
|
|
|
|
struct lbs_scan_cmd_config *scan_cmd;
|
|
|
|
u8 *tlv; /* pointer into our current, growing TLV storage area */
|
2007-05-25 16:25:21 -04:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_enter_args(LBS_DEB_SCAN, "bsstype %d, chanlist[].chan %d, "
|
|
|
|
"chan_count %d",
|
|
|
|
bsstype, chan_list[0].channumber, chan_count);
|
2007-10-09 08:15:19 -04:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
/* create the fixed part for scan command */
|
|
|
|
scan_cmd = kzalloc(MAX_SCAN_CFG_ALLOC, GFP_KERNEL);
|
|
|
|
if (scan_cmd == NULL)
|
2007-10-09 08:15:19 -04:00
|
|
|
goto out;
|
2007-12-07 10:52:10 -05:00
|
|
|
tlv = scan_cmd->tlvbuffer;
|
|
|
|
if (user_cfg)
|
|
|
|
memcpy(scan_cmd->bssid, user_cfg->bssid, ETH_ALEN);
|
|
|
|
scan_cmd->bsstype = bsstype;
|
|
|
|
|
|
|
|
/* add TLVs */
|
|
|
|
if (user_cfg && user_cfg->ssid_len)
|
|
|
|
tlv += lbs_scan_add_ssid_tlv(tlv, user_cfg);
|
|
|
|
if (chan_list && chan_count)
|
|
|
|
tlv += lbs_scan_add_chanlist_tlv(tlv, chan_list, chan_count);
|
|
|
|
tlv += lbs_scan_add_rates_tlv(tlv);
|
|
|
|
|
|
|
|
/* This is the final data we are about to send */
|
|
|
|
scan_cmd->tlvbufferlen = tlv - scan_cmd->tlvbuffer;
|
|
|
|
lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd, 1+6);
|
|
|
|
lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer,
|
|
|
|
scan_cmd->tlvbufferlen);
|
|
|
|
|
|
|
|
ret = lbs_prepare_and_send_command(priv, CMD_802_11_SCAN, 0,
|
|
|
|
CMD_OPTION_WAITFORRSP, 0, scan_cmd);
|
2007-10-09 08:15:19 -04:00
|
|
|
out:
|
2007-12-07 10:52:10 -05:00
|
|
|
kfree(scan_cmd);
|
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
|
|
|
|
return ret;
|
2007-05-25 16:25:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-10 09:25:27 -05:00
|
|
|
/**
|
|
|
|
* @brief Internal function used to start a scan based on an input config
|
|
|
|
*
|
2007-10-09 08:15:19 -04:00
|
|
|
* Also used from debugfs
|
|
|
|
*
|
2007-02-10 09:25:27 -05:00
|
|
|
* Use the input user scan configuration information when provided in
|
|
|
|
* order to send the appropriate scan commands to firmware to populate or
|
|
|
|
* update the internal driver scan table
|
|
|
|
*
|
2007-11-23 09:43:44 -05:00
|
|
|
* @param priv A pointer to struct lbs_private structure
|
2007-02-10 09:25:27 -05:00
|
|
|
* @param puserscanin Pointer to the input configuration for the requested
|
|
|
|
* scan.
|
|
|
|
*
|
|
|
|
* @return 0 or < 0 if error
|
|
|
|
*/
|
2007-11-23 09:43:44 -05:00
|
|
|
int lbs_scan_networks(struct lbs_private *priv,
|
2007-12-07 10:52:10 -05:00
|
|
|
const struct lbs_ioctl_user_scan_cfg *user_cfg,
|
2007-08-02 13:19:04 -04:00
|
|
|
int full_scan)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
2007-12-07 10:52:10 -05:00
|
|
|
int ret = -ENOMEM;
|
|
|
|
struct chanscanparamset *chan_list;
|
|
|
|
struct chanscanparamset *curr_chans;
|
|
|
|
int chan_count;
|
|
|
|
u8 bsstype = CMD_BSS_TYPE_ANY;
|
|
|
|
int numchannels = MRVDRV_CHANNELS_PER_SCAN_CMD;
|
|
|
|
int filteredscan = 0;
|
|
|
|
union iwreq_data wrqu;
|
2007-05-30 10:12:55 -04:00
|
|
|
#ifdef CONFIG_LIBERTAS_DEBUG
|
2007-12-07 10:52:10 -05:00
|
|
|
struct bss_descriptor *iter;
|
2007-05-30 10:12:55 -04:00
|
|
|
int i = 0;
|
2007-10-03 20:59:30 -04:00
|
|
|
DECLARE_MAC_BUF(mac);
|
2007-05-30 10:12:55 -04:00
|
|
|
#endif
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_enter_args(LBS_DEB_SCAN, "full_scan %d",
|
|
|
|
full_scan);
|
2007-08-02 13:19:04 -04:00
|
|
|
|
|
|
|
/* Cancel any partial outstanding partial scans if this scan
|
|
|
|
* is a full scan.
|
|
|
|
*/
|
|
|
|
if (full_scan && delayed_work_pending(&priv->scan_work))
|
|
|
|
cancel_delayed_work(&priv->scan_work);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
/* Determine same scan parameters */
|
|
|
|
if (user_cfg) {
|
|
|
|
if (user_cfg->bsstype)
|
|
|
|
bsstype = user_cfg->bsstype;
|
|
|
|
if (compare_ether_addr(user_cfg->bssid, &zeromac[0]) != 0) {
|
|
|
|
numchannels = MRVDRV_MAX_CHANNELS_PER_SCAN;
|
|
|
|
filteredscan = 1;
|
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("numchannels %d, bsstype %d, "
|
|
|
|
"filteredscan %d\n",
|
|
|
|
numchannels, bsstype, filteredscan);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
/* Create list of channels to scan */
|
|
|
|
chan_list = kzalloc(sizeof(struct chanscanparamset) *
|
|
|
|
LBS_IOCTL_USER_SCAN_CHAN_MAX, GFP_KERNEL);
|
|
|
|
if (!chan_list) {
|
|
|
|
lbs_pr_alert("SCAN: chan_list empty\n");
|
2007-02-10 09:25:27 -05:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
/* We want to scan all channels */
|
|
|
|
chan_count = lbs_scan_create_channel_list(priv, chan_list,
|
|
|
|
filteredscan);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
netif_stop_queue(priv->dev);
|
|
|
|
netif_carrier_off(priv->dev);
|
|
|
|
if (priv->mesh_dev) {
|
2007-08-02 11:50:12 -04:00
|
|
|
netif_stop_queue(priv->mesh_dev);
|
|
|
|
netif_carrier_off(priv->mesh_dev);
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
/* Prepare to continue an interrupted scan */
|
|
|
|
lbs_deb_scan("chan_count %d, last_scanned_channel %d\n",
|
2007-12-08 15:04:36 -05:00
|
|
|
chan_count, priv->last_scanned_channel);
|
2007-12-07 10:52:10 -05:00
|
|
|
curr_chans = chan_list;
|
|
|
|
/* advance channel list by already-scanned-channels */
|
2007-12-08 15:04:36 -05:00
|
|
|
if (priv->last_scanned_channel > 0) {
|
|
|
|
curr_chans += priv->last_scanned_channel;
|
|
|
|
chan_count -= priv->last_scanned_channel;
|
2007-12-07 10:52:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send scan command(s)
|
|
|
|
* numchannels contains the number of channels we should maximally scan
|
|
|
|
* chan_count is the total number of channels to scan
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (chan_count) {
|
|
|
|
int to_scan = min(numchannels, chan_count);
|
|
|
|
lbs_deb_scan("scanning %d of %d channels\n",
|
|
|
|
to_scan, chan_count);
|
|
|
|
ret = lbs_do_scan(priv, bsstype, curr_chans,
|
|
|
|
to_scan, user_cfg);
|
|
|
|
if (ret) {
|
|
|
|
lbs_pr_err("SCAN_CMD failed\n");
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
curr_chans += to_scan;
|
|
|
|
chan_count -= to_scan;
|
|
|
|
|
|
|
|
/* somehow schedule the next part of the scan */
|
|
|
|
if (chan_count &&
|
|
|
|
!full_scan &&
|
2007-12-08 15:04:36 -05:00
|
|
|
!priv->surpriseremoved) {
|
2007-12-07 10:52:10 -05:00
|
|
|
/* -1 marks just that we're currently scanning */
|
2007-12-08 15:04:36 -05:00
|
|
|
if (priv->last_scanned_channel < 0)
|
|
|
|
priv->last_scanned_channel = to_scan;
|
2007-12-07 10:52:10 -05:00
|
|
|
else
|
2007-12-08 15:04:36 -05:00
|
|
|
priv->last_scanned_channel += to_scan;
|
2007-12-07 10:52:10 -05:00
|
|
|
cancel_delayed_work(&priv->scan_work);
|
|
|
|
queue_delayed_work(priv->work_thread, &priv->scan_work,
|
|
|
|
msecs_to_jiffies(300));
|
|
|
|
/* skip over GIWSCAN event */
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
memset(&wrqu, 0, sizeof(union iwreq_data));
|
|
|
|
wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-30 10:12:55 -04:00
|
|
|
#ifdef CONFIG_LIBERTAS_DEBUG
|
|
|
|
/* Dump the scan table */
|
2007-12-08 15:04:36 -05:00
|
|
|
mutex_lock(&priv->lock);
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("scan table:\n");
|
2007-12-08 15:04:36 -05:00
|
|
|
list_for_each_entry(iter, &priv->network_list, list)
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("%02d: BSSID %s, RSSI %d, SSID '%s'\n",
|
|
|
|
i++, print_mac(mac, iter->bssid), (s32) iter->rssi,
|
|
|
|
escape_essid(iter->ssid, iter->ssid_len));
|
2007-12-08 15:04:36 -05:00
|
|
|
mutex_unlock(&priv->lock);
|
2007-05-30 10:12:55 -04:00
|
|
|
#endif
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
out2:
|
2007-12-08 15:04:36 -05:00
|
|
|
priv->last_scanned_channel = 0;
|
2007-12-07 10:52:10 -05:00
|
|
|
|
|
|
|
out:
|
2007-12-08 15:04:36 -05:00
|
|
|
if (priv->connect_status == LBS_CONNECTED) {
|
2007-05-25 13:05:16 -04:00
|
|
|
netif_carrier_on(priv->dev);
|
|
|
|
netif_wake_queue(priv->dev);
|
2007-11-20 17:44:14 -05:00
|
|
|
}
|
2007-12-08 15:04:36 -05:00
|
|
|
if (priv->mesh_dev && (priv->mesh_connect_status == LBS_CONNECTED)) {
|
2007-11-20 17:44:14 -05:00
|
|
|
netif_carrier_on(priv->mesh_dev);
|
|
|
|
netif_wake_queue(priv->mesh_dev);
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
2007-12-07 10:52:10 -05:00
|
|
|
kfree(chan_list);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 11:27:16 -04:00
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
|
2007-02-10 09:25:27 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Result interpretation */
|
|
|
|
/* */
|
|
|
|
/*********************************************************************/
|
|
|
|
|
2007-02-10 09:25:27 -05:00
|
|
|
/**
|
|
|
|
* @brief Interpret a BSS scan response returned from the firmware
|
|
|
|
*
|
|
|
|
* Parse the various fixed fields and IEs passed back for a a BSS probe
|
2007-12-07 10:52:10 -05:00
|
|
|
* response or beacon from the scan command. Record information as needed
|
|
|
|
* in the scan table struct bss_descriptor for that entry.
|
2007-02-10 09:25:27 -05:00
|
|
|
*
|
2007-05-25 16:15:56 -04:00
|
|
|
* @param bss Output parameter: Pointer to the BSS Entry
|
2007-02-10 09:25:27 -05:00
|
|
|
*
|
|
|
|
* @return 0 or -1
|
|
|
|
*/
|
2007-11-15 18:05:47 -05:00
|
|
|
static int lbs_process_bss(struct bss_descriptor *bss,
|
2007-05-25 16:15:56 -04:00
|
|
|
u8 ** pbeaconinfo, int *bytesleft)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
|
|
|
struct ieeetypes_fhparamset *pFH;
|
|
|
|
struct ieeetypes_dsparamset *pDS;
|
|
|
|
struct ieeetypes_cfparamset *pCF;
|
|
|
|
struct ieeetypes_ibssparamset *pibss;
|
2007-10-03 20:59:30 -04:00
|
|
|
DECLARE_MAC_BUF(mac);
|
2007-02-10 09:25:27 -05:00
|
|
|
struct ieeetypes_countryinfoset *pcountryinfo;
|
2007-08-02 11:40:45 -04:00
|
|
|
u8 *pos, *end, *p;
|
|
|
|
u8 n_ex_rates = 0, got_basic_rates = 0, n_basic_rates = 0;
|
|
|
|
u16 beaconsize = 0;
|
|
|
|
int ret;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
|
|
|
if (*bytesleft >= sizeof(beaconsize)) {
|
|
|
|
/* Extract & convert beacon size from the command buffer */
|
2007-09-06 21:45:36 -04:00
|
|
|
beaconsize = le16_to_cpu(get_unaligned((u16 *)*pbeaconinfo));
|
2007-02-10 09:25:27 -05:00
|
|
|
*bytesleft -= sizeof(beaconsize);
|
|
|
|
*pbeaconinfo += sizeof(beaconsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (beaconsize == 0 || beaconsize > *bytesleft) {
|
|
|
|
*pbeaconinfo += *bytesleft;
|
|
|
|
*bytesleft = 0;
|
2007-10-09 08:15:19 -04:00
|
|
|
ret = -1;
|
|
|
|
goto done;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the current working beacon pointer for this BSS iteration */
|
2007-08-02 10:48:02 -04:00
|
|
|
pos = *pbeaconinfo;
|
|
|
|
end = pos + beaconsize;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
|
|
|
/* Advance the return beacon pointer past the current beacon */
|
|
|
|
*pbeaconinfo += beaconsize;
|
|
|
|
*bytesleft -= beaconsize;
|
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
memcpy(bss->bssid, pos, ETH_ALEN);
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("process_bss: BSSID %s\n", print_mac(mac, bss->bssid));
|
2007-08-02 10:48:02 -04:00
|
|
|
pos += ETH_ALEN;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
if ((end - pos) < 12) {
|
2007-05-25 16:15:56 -04:00
|
|
|
lbs_deb_scan("process_bss: Not enough bytes left\n");
|
2007-10-09 08:15:19 -04:00
|
|
|
ret = -1;
|
|
|
|
goto done;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* next 4 fields are RSSI, time stamp, beacon interval,
|
|
|
|
* and capability information
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* RSSI is 1 byte long */
|
2007-08-02 10:48:02 -04:00
|
|
|
bss->rssi = *pos;
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("process_bss: RSSI %d\n", *pos);
|
2007-08-02 10:48:02 -04:00
|
|
|
pos++;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
|
|
|
/* time stamp is 8 bytes long */
|
2007-08-02 10:48:02 -04:00
|
|
|
pos += 8;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
|
|
|
/* beacon interval is 2 bytes long */
|
2007-08-02 10:48:02 -04:00
|
|
|
bss->beaconperiod = le16_to_cpup((void *) pos);
|
|
|
|
pos += 2;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
|
|
|
/* capability information is 2 bytes long */
|
2007-08-02 10:48:02 -04:00
|
|
|
bss->capability = le16_to_cpup((void *) pos);
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("process_bss: capabilities 0x%04x\n", bss->capability);
|
2007-08-02 10:48:02 -04:00
|
|
|
pos += 2;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-08-02 10:43:44 -04:00
|
|
|
if (bss->capability & WLAN_CAPABILITY_PRIVACY)
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("process_bss: WEP enabled\n");
|
2007-08-02 10:43:44 -04:00
|
|
|
if (bss->capability & WLAN_CAPABILITY_IBSS)
|
|
|
|
bss->mode = IW_MODE_ADHOC;
|
|
|
|
else
|
|
|
|
bss->mode = IW_MODE_INFRA;
|
|
|
|
|
2007-02-10 09:25:27 -05:00
|
|
|
/* rest of the current buffer are IE's */
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("process_bss: IE len %zd\n", end - pos);
|
2007-08-02 11:53:06 -04:00
|
|
|
lbs_deb_hex(LBS_DEB_SCAN, "process_bss: IE info", pos, end - pos);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
|
|
|
/* process variable IE */
|
2007-08-02 10:48:02 -04:00
|
|
|
while (pos <= end - 2) {
|
|
|
|
struct ieee80211_info_element * elem =
|
|
|
|
(struct ieee80211_info_element *) pos;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
if (pos + elem->len > end) {
|
2007-05-25 16:15:56 -04:00
|
|
|
lbs_deb_scan("process_bss: error in processing IE, "
|
2007-02-10 09:25:27 -05:00
|
|
|
"bytes left < IE length\n");
|
2007-08-02 10:48:02 -04:00
|
|
|
break;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
switch (elem->id) {
|
|
|
|
case MFIE_TYPE_SSID:
|
|
|
|
bss->ssid_len = elem->len;
|
|
|
|
memcpy(bss->ssid, elem->data, elem->len);
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("got SSID IE: '%s', len %u\n",
|
2007-05-28 23:54:55 -04:00
|
|
|
escape_essid(bss->ssid, bss->ssid_len),
|
|
|
|
bss->ssid_len);
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
case MFIE_TYPE_RATES:
|
2007-08-02 11:40:45 -04:00
|
|
|
n_basic_rates = min_t(u8, MAX_RATES, elem->len);
|
|
|
|
memcpy(bss->rates, elem->data, n_basic_rates);
|
|
|
|
got_basic_rates = 1;
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("got RATES IE\n");
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
case MFIE_TYPE_FH_SET:
|
|
|
|
pFH = (struct ieeetypes_fhparamset *) pos;
|
2007-05-25 16:15:56 -04:00
|
|
|
memmove(&bss->phyparamset.fhparamset, pFH,
|
2007-02-10 09:25:27 -05:00
|
|
|
sizeof(struct ieeetypes_fhparamset));
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("got FH IE\n");
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
case MFIE_TYPE_DS_SET:
|
|
|
|
pDS = (struct ieeetypes_dsparamset *) pos;
|
2007-05-25 16:15:56 -04:00
|
|
|
bss->channel = pDS->currentchan;
|
|
|
|
memcpy(&bss->phyparamset.dsparamset, pDS,
|
2007-02-10 09:25:27 -05:00
|
|
|
sizeof(struct ieeetypes_dsparamset));
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("got DS IE, channel %d\n", bss->channel);
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
case MFIE_TYPE_CF_SET:
|
|
|
|
pCF = (struct ieeetypes_cfparamset *) pos;
|
2007-05-25 16:15:56 -04:00
|
|
|
memcpy(&bss->ssparamset.cfparamset, pCF,
|
2007-02-10 09:25:27 -05:00
|
|
|
sizeof(struct ieeetypes_cfparamset));
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("got CF IE\n");
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
case MFIE_TYPE_IBSS_SET:
|
|
|
|
pibss = (struct ieeetypes_ibssparamset *) pos;
|
2007-05-25 16:15:56 -04:00
|
|
|
bss->atimwindow = le32_to_cpu(pibss->atimwindow);
|
|
|
|
memmove(&bss->ssparamset.ibssparamset, pibss,
|
2007-02-10 09:25:27 -05:00
|
|
|
sizeof(struct ieeetypes_ibssparamset));
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("got IBSS IE\n");
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
case MFIE_TYPE_COUNTRY:
|
|
|
|
pcountryinfo = (struct ieeetypes_countryinfoset *) pos;
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("got COUNTRY IE\n");
|
2007-05-25 16:15:56 -04:00
|
|
|
if (pcountryinfo->len < sizeof(pcountryinfo->countrycode)
|
2007-02-10 09:25:27 -05:00
|
|
|
|| pcountryinfo->len > 254) {
|
2007-05-25 16:15:56 -04:00
|
|
|
lbs_deb_scan("process_bss: 11D- Err "
|
2007-12-07 10:52:10 -05:00
|
|
|
"CountryInfo len %d, min %zd, max 254\n",
|
2007-02-10 09:25:27 -05:00
|
|
|
pcountryinfo->len,
|
|
|
|
sizeof(pcountryinfo->countrycode));
|
2007-05-25 11:27:16 -04:00
|
|
|
ret = -1;
|
|
|
|
goto done;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
memcpy(&bss->countryinfo,
|
2007-02-10 09:25:27 -05:00
|
|
|
pcountryinfo, pcountryinfo->len + 2);
|
2007-08-02 11:53:06 -04:00
|
|
|
lbs_deb_hex(LBS_DEB_SCAN, "process_bss: 11d countryinfo",
|
2007-02-10 09:25:27 -05:00
|
|
|
(u8 *) pcountryinfo,
|
|
|
|
(u32) (pcountryinfo->len + 2));
|
|
|
|
break;
|
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
case MFIE_TYPE_RATES_EX:
|
|
|
|
/* only process extended supported rate if data rate is
|
|
|
|
* already found. Data rate IE should come before
|
2007-02-10 09:25:27 -05:00
|
|
|
* extended supported rate IE
|
|
|
|
*/
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("got RATESEX IE\n");
|
|
|
|
if (!got_basic_rates) {
|
|
|
|
lbs_deb_scan("... but ignoring it\n");
|
2007-08-02 10:48:02 -04:00
|
|
|
break;
|
2007-12-07 10:52:10 -05:00
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-08-02 11:40:45 -04:00
|
|
|
n_ex_rates = elem->len;
|
|
|
|
if (n_basic_rates + n_ex_rates > MAX_RATES)
|
|
|
|
n_ex_rates = MAX_RATES - n_basic_rates;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-08-02 11:40:45 -04:00
|
|
|
p = bss->rates + n_basic_rates;
|
|
|
|
memcpy(p, elem->data, n_ex_rates);
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
2007-08-02 10:48:02 -04:00
|
|
|
|
|
|
|
case MFIE_TYPE_GENERIC:
|
|
|
|
if (elem->len >= 4 &&
|
|
|
|
elem->data[0] == 0x00 &&
|
|
|
|
elem->data[1] == 0x50 &&
|
|
|
|
elem->data[2] == 0xf2 &&
|
|
|
|
elem->data[3] == 0x01) {
|
|
|
|
bss->wpa_ie_len = min(elem->len + 2,
|
|
|
|
MAX_WPA_IE_LEN);
|
|
|
|
memcpy(bss->wpa_ie, elem, bss->wpa_ie_len);
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("got WPA IE\n");
|
|
|
|
lbs_deb_hex(LBS_DEB_SCAN, "WPA IE", bss->wpa_ie,
|
2007-08-02 10:48:02 -04:00
|
|
|
elem->len);
|
2007-08-02 10:51:27 -04:00
|
|
|
} else if (elem->len >= MARVELL_MESH_IE_LENGTH &&
|
|
|
|
elem->data[0] == 0x00 &&
|
|
|
|
elem->data[1] == 0x50 &&
|
|
|
|
elem->data[2] == 0x43 &&
|
|
|
|
elem->data[3] == 0x04) {
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("got mesh IE\n");
|
2007-08-02 10:51:27 -04:00
|
|
|
bss->mesh = 1;
|
2007-12-07 10:52:10 -05:00
|
|
|
} else {
|
|
|
|
lbs_deb_scan("got generiec IE: "
|
|
|
|
"%02x:%02x:%02x:%02x, len %d\n",
|
|
|
|
elem->data[0], elem->data[1],
|
|
|
|
elem->data[2], elem->data[3],
|
|
|
|
elem->len);
|
2007-08-02 10:48:02 -04:00
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
2007-08-02 10:48:02 -04:00
|
|
|
|
|
|
|
case MFIE_TYPE_RSN:
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("got RSN IE\n");
|
2007-08-02 10:48:02 -04:00
|
|
|
bss->rsn_ie_len = min(elem->len + 2, MAX_WPA_IE_LEN);
|
|
|
|
memcpy(bss->rsn_ie, elem, bss->rsn_ie_len);
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_hex(LBS_DEB_SCAN, "process_bss: RSN_IE",
|
|
|
|
bss->rsn_ie, elem->len);
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
default:
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("got IE 0x%04x, len %d\n",
|
|
|
|
elem->id, elem->len);
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-08-02 10:48:02 -04:00
|
|
|
pos += elem->len + 2;
|
|
|
|
}
|
2007-05-25 16:15:56 -04:00
|
|
|
|
|
|
|
/* Timestamp */
|
|
|
|
bss->last_scanned = jiffies;
|
2007-11-15 18:05:47 -05:00
|
|
|
lbs_unset_basic_rate_flags(bss->rates, sizeof(bss->rates));
|
2007-05-25 16:15:56 -04:00
|
|
|
|
2007-05-25 11:27:16 -04:00
|
|
|
ret = 0;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 11:27:16 -04:00
|
|
|
done:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
|
|
|
|
return ret;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function finds a specific compatible BSSID in the scan list
|
|
|
|
*
|
2007-10-09 08:15:19 -04:00
|
|
|
* Used in association code
|
|
|
|
*
|
2007-12-08 15:04:36 -05:00
|
|
|
* @param priv A pointer to struct lbs_private
|
2007-02-10 09:25:27 -05:00
|
|
|
* @param bssid BSSID to find in the scan list
|
|
|
|
* @param mode Network mode: Infrastructure or IBSS
|
|
|
|
*
|
|
|
|
* @return index in BSSID list, or error return code (< 0)
|
|
|
|
*/
|
2007-12-08 15:04:36 -05:00
|
|
|
struct bss_descriptor *lbs_find_bssid_in_list(struct lbs_private *priv,
|
2007-05-25 16:15:56 -04:00
|
|
|
u8 * bssid, u8 mode)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
2007-05-25 16:15:56 -04:00
|
|
|
struct bss_descriptor * iter_bss;
|
|
|
|
struct bss_descriptor * found_bss = NULL;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
|
|
|
|
2007-02-10 09:25:27 -05:00
|
|
|
if (!bssid)
|
2007-10-09 08:15:19 -04:00
|
|
|
goto out;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-08-02 11:53:06 -04:00
|
|
|
lbs_deb_hex(LBS_DEB_SCAN, "looking for",
|
2007-05-25 16:15:56 -04:00
|
|
|
bssid, ETH_ALEN);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
/* Look through the scan table for a compatible match. The loop will
|
|
|
|
* continue past a matched bssid that is not compatible in case there
|
|
|
|
* is an AP with multiple SSIDs assigned to the same BSSID
|
2007-02-10 09:25:27 -05:00
|
|
|
*/
|
2007-12-08 15:04:36 -05:00
|
|
|
mutex_lock(&priv->lock);
|
|
|
|
list_for_each_entry (iter_bss, &priv->network_list, list) {
|
2007-05-25 17:28:30 -04:00
|
|
|
if (compare_ether_addr(iter_bss->bssid, bssid))
|
2007-05-25 16:15:56 -04:00
|
|
|
continue; /* bssid doesn't match */
|
|
|
|
switch (mode) {
|
|
|
|
case IW_MODE_INFRA:
|
|
|
|
case IW_MODE_ADHOC:
|
2007-12-08 15:04:36 -05:00
|
|
|
if (!is_network_compatible(priv, iter_bss, mode))
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
2007-05-25 16:15:56 -04:00
|
|
|
found_bss = iter_bss;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
found_bss = iter_bss;
|
|
|
|
break;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
}
|
2007-12-08 15:04:36 -05:00
|
|
|
mutex_unlock(&priv->lock);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
out:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss);
|
2007-05-25 16:15:56 -04:00
|
|
|
return found_bss;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function finds ssid in ssid list.
|
|
|
|
*
|
2007-10-09 08:15:19 -04:00
|
|
|
* Used in association code
|
|
|
|
*
|
2007-12-08 15:04:36 -05:00
|
|
|
* @param priv A pointer to struct lbs_private
|
2007-02-10 09:25:27 -05:00
|
|
|
* @param ssid SSID to find in the list
|
|
|
|
* @param bssid BSSID to qualify the SSID selection (if provided)
|
|
|
|
* @param mode Network mode: Infrastructure or IBSS
|
|
|
|
*
|
|
|
|
* @return index in BSSID list
|
|
|
|
*/
|
2007-12-08 15:04:36 -05:00
|
|
|
struct bss_descriptor *lbs_find_ssid_in_list(struct lbs_private *priv,
|
2007-05-28 23:54:55 -04:00
|
|
|
u8 *ssid, u8 ssid_len, u8 * bssid, u8 mode,
|
2007-05-25 22:30:48 -04:00
|
|
|
int channel)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
|
|
|
u8 bestrssi = 0;
|
2007-05-25 16:15:56 -04:00
|
|
|
struct bss_descriptor * iter_bss = NULL;
|
|
|
|
struct bss_descriptor * found_bss = NULL;
|
|
|
|
struct bss_descriptor * tmp_oldest = NULL;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
mutex_lock(&priv->lock);
|
2007-05-25 16:15:56 -04:00
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
list_for_each_entry (iter_bss, &priv->network_list, list) {
|
2007-05-25 16:15:56 -04:00
|
|
|
if ( !tmp_oldest
|
|
|
|
|| (iter_bss->last_scanned < tmp_oldest->last_scanned))
|
|
|
|
tmp_oldest = iter_bss;
|
|
|
|
|
2007-11-15 18:05:47 -05:00
|
|
|
if (lbs_ssid_cmp(iter_bss->ssid, iter_bss->ssid_len,
|
2007-05-28 23:54:55 -04:00
|
|
|
ssid, ssid_len) != 0)
|
2007-05-25 16:15:56 -04:00
|
|
|
continue; /* ssid doesn't match */
|
2007-05-25 17:28:30 -04:00
|
|
|
if (bssid && compare_ether_addr(iter_bss->bssid, bssid) != 0)
|
2007-05-25 16:15:56 -04:00
|
|
|
continue; /* bssid doesn't match */
|
2007-05-25 22:30:48 -04:00
|
|
|
if ((channel > 0) && (iter_bss->channel != channel))
|
|
|
|
continue; /* channel doesn't match */
|
2007-05-25 16:15:56 -04:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case IW_MODE_INFRA:
|
|
|
|
case IW_MODE_ADHOC:
|
2007-12-08 15:04:36 -05:00
|
|
|
if (!is_network_compatible(priv, iter_bss, mode))
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
2007-05-25 16:15:56 -04:00
|
|
|
|
|
|
|
if (bssid) {
|
|
|
|
/* Found requested BSSID */
|
|
|
|
found_bss = iter_bss;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
|
|
|
|
bestrssi = SCAN_RSSI(iter_bss->rssi);
|
|
|
|
found_bss = iter_bss;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IW_MODE_AUTO:
|
|
|
|
default:
|
|
|
|
if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
|
|
|
|
bestrssi = SCAN_RSSI(iter_bss->rssi);
|
|
|
|
found_bss = iter_bss;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
2007-05-25 16:15:56 -04:00
|
|
|
break;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
out:
|
2007-12-08 15:04:36 -05:00
|
|
|
mutex_unlock(&priv->lock);
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss);
|
2007-05-25 16:15:56 -04:00
|
|
|
return found_bss;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function finds the best SSID in the Scan List
|
|
|
|
*
|
|
|
|
* Search the scan table for the best SSID that also matches the current
|
|
|
|
* adapter network preference (infrastructure or adhoc)
|
|
|
|
*
|
2007-12-08 15:04:36 -05:00
|
|
|
* @param priv A pointer to struct lbs_private
|
2007-02-10 09:25:27 -05:00
|
|
|
*
|
|
|
|
* @return index in BSSID list
|
|
|
|
*/
|
2007-11-23 09:43:44 -05:00
|
|
|
static struct bss_descriptor *lbs_find_best_ssid_in_list(
|
2007-12-08 15:04:36 -05:00
|
|
|
struct lbs_private *priv,
|
2007-11-23 09:43:44 -05:00
|
|
|
u8 mode)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
|
|
|
u8 bestrssi = 0;
|
2007-05-25 16:15:56 -04:00
|
|
|
struct bss_descriptor * iter_bss;
|
|
|
|
struct bss_descriptor * best_bss = NULL;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
mutex_lock(&priv->lock);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
list_for_each_entry (iter_bss, &priv->network_list, list) {
|
2007-02-10 09:25:27 -05:00
|
|
|
switch (mode) {
|
2007-05-10 22:58:02 -04:00
|
|
|
case IW_MODE_INFRA:
|
|
|
|
case IW_MODE_ADHOC:
|
2007-12-08 15:04:36 -05:00
|
|
|
if (!is_network_compatible(priv, iter_bss, mode))
|
2007-05-25 16:15:56 -04:00
|
|
|
break;
|
|
|
|
if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
|
|
|
|
break;
|
|
|
|
bestrssi = SCAN_RSSI(iter_bss->rssi);
|
|
|
|
best_bss = iter_bss;
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
2007-05-10 22:58:02 -04:00
|
|
|
case IW_MODE_AUTO:
|
2007-02-10 09:25:27 -05:00
|
|
|
default:
|
2007-05-25 16:15:56 -04:00
|
|
|
if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
|
|
|
|
break;
|
|
|
|
bestrssi = SCAN_RSSI(iter_bss->rssi);
|
|
|
|
best_bss = iter_bss;
|
2007-02-10 09:25:27 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
mutex_unlock(&priv->lock);
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "best_bss %p", best_bss);
|
2007-05-25 16:15:56 -04:00
|
|
|
return best_bss;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Find the AP with specific ssid in the scan list
|
|
|
|
*
|
2007-10-09 08:15:19 -04:00
|
|
|
* Used from association worker.
|
|
|
|
*
|
2007-11-23 09:43:44 -05:00
|
|
|
* @param priv A pointer to struct lbs_private structure
|
2007-02-10 09:25:27 -05:00
|
|
|
* @param pSSID A pointer to AP's ssid
|
|
|
|
*
|
|
|
|
* @return 0--success, otherwise--fail
|
|
|
|
*/
|
2007-11-23 09:43:44 -05:00
|
|
|
int lbs_find_best_network_ssid(struct lbs_private *priv,
|
2007-05-28 23:54:55 -04:00
|
|
|
u8 *out_ssid, u8 *out_ssid_len, u8 preferred_mode, u8 *out_mode)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
2007-05-25 16:15:56 -04:00
|
|
|
int ret = -1;
|
|
|
|
struct bss_descriptor * found;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-11-15 18:05:47 -05:00
|
|
|
lbs_scan_networks(priv, NULL, 1);
|
2007-12-08 15:04:36 -05:00
|
|
|
if (priv->surpriseremoved)
|
2007-10-09 08:15:19 -04:00
|
|
|
goto out;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
found = lbs_find_best_ssid_in_list(priv, preferred_mode);
|
2007-05-28 23:54:55 -04:00
|
|
|
if (found && (found->ssid_len > 0)) {
|
|
|
|
memcpy(out_ssid, &found->ssid, IW_ESSID_MAX_SIZE);
|
|
|
|
*out_ssid_len = found->ssid_len;
|
2007-05-25 16:15:56 -04:00
|
|
|
*out_mode = found->mode;
|
|
|
|
ret = 0;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
out:
|
2007-05-25 11:27:16 -04:00
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
|
2007-02-10 09:25:27 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
|
2007-02-10 09:25:27 -05:00
|
|
|
/**
|
|
|
|
* @brief Send a scan command for all available channels filtered on a spec
|
|
|
|
*
|
2007-10-09 08:15:19 -04:00
|
|
|
* Used in association code and from debugfs
|
|
|
|
*
|
2007-11-23 09:43:44 -05:00
|
|
|
* @param priv A pointer to struct lbs_private structure
|
2007-10-09 08:15:19 -04:00
|
|
|
* @param ssid A pointer to the SSID to scan for
|
|
|
|
* @param ssid_len Length of the SSID
|
|
|
|
* @param clear_ssid Should existing scan results with this SSID
|
|
|
|
* be cleared?
|
2007-02-10 09:25:27 -05:00
|
|
|
*
|
|
|
|
* @return 0-success, otherwise fail
|
|
|
|
*/
|
2007-11-23 09:43:44 -05:00
|
|
|
int lbs_send_specific_ssid_scan(struct lbs_private *priv,
|
2007-05-28 23:54:55 -04:00
|
|
|
u8 *ssid, u8 ssid_len, u8 clear_ssid)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
2007-11-15 18:05:47 -05:00
|
|
|
struct lbs_ioctl_user_scan_cfg scancfg;
|
2007-05-25 16:25:21 -04:00
|
|
|
int ret = 0;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_enter_args(LBS_DEB_SCAN, "SSID '%s', clear %d",
|
|
|
|
escape_essid(ssid, ssid_len), clear_ssid);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-28 23:54:55 -04:00
|
|
|
if (!ssid_len)
|
2007-05-25 16:25:21 -04:00
|
|
|
goto out;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
|
|
|
memset(&scancfg, 0x00, sizeof(scancfg));
|
2007-05-28 23:54:55 -04:00
|
|
|
memcpy(scancfg.ssid, ssid, ssid_len);
|
|
|
|
scancfg.ssid_len = ssid_len;
|
2007-05-25 16:25:21 -04:00
|
|
|
scancfg.clear_ssid = clear_ssid;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-11-15 18:05:47 -05:00
|
|
|
lbs_scan_networks(priv, &scancfg, 1);
|
2007-12-08 15:04:36 -05:00
|
|
|
if (priv->surpriseremoved) {
|
2007-10-09 08:15:19 -04:00
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 16:25:21 -04:00
|
|
|
out:
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
|
2007-05-25 16:25:21 -04:00
|
|
|
return ret;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Support for Wireless Extensions */
|
|
|
|
/* */
|
|
|
|
/*********************************************************************/
|
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
|
2007-08-02 13:14:56 -04:00
|
|
|
#define MAX_CUSTOM_LEN 64
|
|
|
|
|
2007-11-23 09:43:44 -05:00
|
|
|
static inline char *lbs_translate_scan(struct lbs_private *priv,
|
2007-05-25 16:15:56 -04:00
|
|
|
char *start, char *stop,
|
|
|
|
struct bss_descriptor *bss)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
|
|
|
struct chan_freq_power *cfp;
|
|
|
|
char *current_val; /* For rates */
|
|
|
|
struct iw_event iwe; /* Temporary buffer */
|
|
|
|
int j;
|
|
|
|
#define PERFECT_RSSI ((u8)50)
|
|
|
|
#define WORST_RSSI ((u8)0)
|
|
|
|
#define RSSI_DIFF ((u8)(PERFECT_RSSI - WORST_RSSI))
|
|
|
|
u8 rssi;
|
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
cfp = lbs_find_cfp_by_band_and_channel(priv, 0, bss->channel);
|
2007-05-25 16:15:56 -04:00
|
|
|
if (!cfp) {
|
|
|
|
lbs_deb_scan("Invalid channel number %d\n", bss->channel);
|
2007-10-09 08:15:19 -04:00
|
|
|
start = NULL;
|
|
|
|
goto out;
|
2007-05-25 00:33:28 -04:00
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
/* First entry *MUST* be the BSSID */
|
2007-05-25 16:15:56 -04:00
|
|
|
iwe.cmd = SIOCGIWAP;
|
|
|
|
iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
|
|
|
|
memcpy(iwe.u.ap_addr.sa_data, &bss->bssid, ETH_ALEN);
|
|
|
|
start = iwe_stream_add_event(start, stop, &iwe, IW_EV_ADDR_LEN);
|
|
|
|
|
|
|
|
/* SSID */
|
|
|
|
iwe.cmd = SIOCGIWESSID;
|
|
|
|
iwe.u.data.flags = 1;
|
2007-05-28 23:54:55 -04:00
|
|
|
iwe.u.data.length = min((u32) bss->ssid_len, (u32) IW_ESSID_MAX_SIZE);
|
|
|
|
start = iwe_stream_add_point(start, stop, &iwe, bss->ssid);
|
2007-05-25 16:15:56 -04:00
|
|
|
|
|
|
|
/* Mode */
|
|
|
|
iwe.cmd = SIOCGIWMODE;
|
|
|
|
iwe.u.mode = bss->mode;
|
|
|
|
start = iwe_stream_add_event(start, stop, &iwe, IW_EV_UINT_LEN);
|
|
|
|
|
|
|
|
/* Frequency */
|
|
|
|
iwe.cmd = SIOCGIWFREQ;
|
|
|
|
iwe.u.freq.m = (long)cfp->freq * 100000;
|
|
|
|
iwe.u.freq.e = 1;
|
|
|
|
start = iwe_stream_add_event(start, stop, &iwe, IW_EV_FREQ_LEN);
|
|
|
|
|
|
|
|
/* Add quality statistics */
|
|
|
|
iwe.cmd = IWEVQUAL;
|
|
|
|
iwe.u.qual.updated = IW_QUAL_ALL_UPDATED;
|
|
|
|
iwe.u.qual.level = SCAN_RSSI(bss->rssi);
|
|
|
|
|
|
|
|
rssi = iwe.u.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE;
|
|
|
|
iwe.u.qual.qual =
|
|
|
|
(100 * RSSI_DIFF * RSSI_DIFF - (PERFECT_RSSI - rssi) *
|
|
|
|
(15 * (RSSI_DIFF) + 62 * (PERFECT_RSSI - rssi))) /
|
|
|
|
(RSSI_DIFF * RSSI_DIFF);
|
|
|
|
if (iwe.u.qual.qual > 100)
|
|
|
|
iwe.u.qual.qual = 100;
|
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
|
2007-05-25 16:15:56 -04:00
|
|
|
iwe.u.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
|
|
|
|
} else {
|
|
|
|
iwe.u.qual.noise =
|
2007-12-08 15:04:36 -05:00
|
|
|
CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
|
2007-05-25 16:15:56 -04:00
|
|
|
}
|
2007-05-25 22:18:47 -04:00
|
|
|
|
|
|
|
/* Locally created ad-hoc BSSs won't have beacons if this is the
|
|
|
|
* only station in the adhoc network; so get signal strength
|
|
|
|
* from receive statistics.
|
|
|
|
*/
|
2007-12-08 15:04:36 -05:00
|
|
|
if ((priv->mode == IW_MODE_ADHOC)
|
|
|
|
&& priv->adhoccreate
|
|
|
|
&& !lbs_ssid_cmp(priv->curbssparams.ssid,
|
|
|
|
priv->curbssparams.ssid_len,
|
2007-05-28 23:54:55 -04:00
|
|
|
bss->ssid, bss->ssid_len)) {
|
2007-05-25 22:18:47 -04:00
|
|
|
int snr, nf;
|
2007-12-08 15:04:36 -05:00
|
|
|
snr = priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
|
|
|
|
nf = priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
|
2007-05-25 22:18:47 -04:00
|
|
|
iwe.u.qual.level = CAL_RSSI(snr, nf);
|
2007-05-25 16:15:56 -04:00
|
|
|
}
|
|
|
|
start = iwe_stream_add_event(start, stop, &iwe, IW_EV_QUAL_LEN);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
/* Add encryption capability */
|
|
|
|
iwe.cmd = SIOCGIWENCODE;
|
2007-08-02 10:43:44 -04:00
|
|
|
if (bss->capability & WLAN_CAPABILITY_PRIVACY) {
|
2007-05-25 16:15:56 -04:00
|
|
|
iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
|
|
|
|
} else {
|
|
|
|
iwe.u.data.flags = IW_ENCODE_DISABLED;
|
|
|
|
}
|
|
|
|
iwe.u.data.length = 0;
|
2007-05-28 23:54:55 -04:00
|
|
|
start = iwe_stream_add_point(start, stop, &iwe, bss->ssid);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
current_val = start + IW_EV_LCP_LEN;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
iwe.cmd = SIOCGIWRATE;
|
|
|
|
iwe.u.bitrate.fixed = 0;
|
|
|
|
iwe.u.bitrate.disabled = 0;
|
|
|
|
iwe.u.bitrate.value = 0;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-08-02 11:40:45 -04:00
|
|
|
for (j = 0; bss->rates[j] && (j < sizeof(bss->rates)); j++) {
|
|
|
|
/* Bit rate given in 500 kb/s units */
|
|
|
|
iwe.u.bitrate.value = bss->rates[j] * 500000;
|
2007-05-25 16:15:56 -04:00
|
|
|
current_val = iwe_stream_add_value(start, current_val,
|
|
|
|
stop, &iwe, IW_EV_PARAM_LEN);
|
|
|
|
}
|
|
|
|
if ((bss->mode == IW_MODE_ADHOC)
|
2007-12-08 15:04:36 -05:00
|
|
|
&& !lbs_ssid_cmp(priv->curbssparams.ssid,
|
|
|
|
priv->curbssparams.ssid_len,
|
2007-05-28 23:54:55 -04:00
|
|
|
bss->ssid, bss->ssid_len)
|
2007-12-08 15:04:36 -05:00
|
|
|
&& priv->adhoccreate) {
|
2007-05-25 16:15:56 -04:00
|
|
|
iwe.u.bitrate.value = 22 * 500000;
|
|
|
|
current_val = iwe_stream_add_value(start, current_val,
|
|
|
|
stop, &iwe, IW_EV_PARAM_LEN);
|
|
|
|
}
|
|
|
|
/* Check if we added any event */
|
|
|
|
if((current_val - start) > IW_EV_LCP_LEN)
|
|
|
|
start = current_val;
|
|
|
|
|
|
|
|
memset(&iwe, 0, sizeof(iwe));
|
|
|
|
if (bss->wpa_ie_len) {
|
|
|
|
char buf[MAX_WPA_IE_LEN];
|
|
|
|
memcpy(buf, bss->wpa_ie, bss->wpa_ie_len);
|
|
|
|
iwe.cmd = IWEVGENIE;
|
|
|
|
iwe.u.data.length = bss->wpa_ie_len;
|
|
|
|
start = iwe_stream_add_point(start, stop, &iwe, buf);
|
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
memset(&iwe, 0, sizeof(iwe));
|
|
|
|
if (bss->rsn_ie_len) {
|
|
|
|
char buf[MAX_WPA_IE_LEN];
|
|
|
|
memcpy(buf, bss->rsn_ie, bss->rsn_ie_len);
|
|
|
|
iwe.cmd = IWEVGENIE;
|
|
|
|
iwe.u.data.length = bss->rsn_ie_len;
|
|
|
|
start = iwe_stream_add_point(start, stop, &iwe, buf);
|
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-08-02 13:14:56 -04:00
|
|
|
if (bss->mesh) {
|
|
|
|
char custom[MAX_CUSTOM_LEN];
|
|
|
|
char *p = custom;
|
|
|
|
|
|
|
|
iwe.cmd = IWEVCUSTOM;
|
|
|
|
p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
|
|
|
|
"mesh-type: olpc");
|
|
|
|
iwe.u.data.length = p - custom;
|
|
|
|
if (iwe.u.data.length)
|
|
|
|
start = iwe_stream_add_point(start, stop, &iwe, custom);
|
|
|
|
}
|
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
out:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "start %p", start);
|
2007-05-25 16:15:56 -04:00
|
|
|
return start;
|
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Handle Scan Network ioctl
|
|
|
|
*
|
|
|
|
* @param dev A pointer to net_device structure
|
|
|
|
* @param info A pointer to iw_request_info structure
|
|
|
|
* @param vwrq A pointer to iw_param structure
|
|
|
|
* @param extra A pointer to extra data buf
|
|
|
|
*
|
|
|
|
* @return 0 --success, otherwise fail
|
|
|
|
*/
|
|
|
|
int lbs_set_scan(struct net_device *dev, struct iw_request_info *info,
|
|
|
|
struct iw_param *wrqu, char *extra)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv = dev->priv;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
|
|
|
|
|
|
|
if (!netif_running(dev))
|
|
|
|
return -ENETDOWN;
|
|
|
|
|
|
|
|
/* mac80211 does this:
|
|
|
|
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
|
|
|
if (sdata->type != IEEE80211_IF_TYPE_xxx)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
if (wrqu->data.length == sizeof(struct iw_scan_req) &&
|
|
|
|
wrqu->data.flags & IW_SCAN_THIS_ESSID) {
|
|
|
|
req = (struct iw_scan_req *)extra;
|
|
|
|
ssid = req->essid;
|
|
|
|
ssid_len = req->essid_len;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!delayed_work_pending(&priv->scan_work))
|
|
|
|
queue_delayed_work(priv->work_thread, &priv->scan_work,
|
|
|
|
msecs_to_jiffies(50));
|
|
|
|
/* set marker that currently a scan is taking place */
|
2007-12-08 15:04:36 -05:00
|
|
|
priv->last_scanned_channel = -1;
|
2007-12-07 10:52:10 -05:00
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
if (priv->surpriseremoved)
|
2007-12-07 10:52:10 -05:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_SCAN);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
/**
|
2007-10-09 08:15:19 -04:00
|
|
|
* @brief Handle Retrieve scan table ioctl
|
2007-05-25 16:15:56 -04:00
|
|
|
*
|
|
|
|
* @param dev A pointer to net_device structure
|
|
|
|
* @param info A pointer to iw_request_info structure
|
|
|
|
* @param dwrq A pointer to iw_point structure
|
|
|
|
* @param extra A pointer to extra data buf
|
|
|
|
*
|
|
|
|
* @return 0 --success, otherwise fail
|
|
|
|
*/
|
2007-11-15 18:05:47 -05:00
|
|
|
int lbs_get_scan(struct net_device *dev, struct iw_request_info *info,
|
2007-05-25 16:15:56 -04:00
|
|
|
struct iw_point *dwrq, char *extra)
|
|
|
|
{
|
|
|
|
#define SCAN_ITEM_SIZE 128
|
2007-11-23 09:43:44 -05:00
|
|
|
struct lbs_private *priv = dev->priv;
|
2007-05-25 16:15:56 -04:00
|
|
|
int err = 0;
|
|
|
|
char *ev = extra;
|
|
|
|
char *stop = ev + dwrq->length;
|
|
|
|
struct bss_descriptor * iter_bss;
|
|
|
|
struct bss_descriptor * safe;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
/* iwlist should wait until the current scan is finished */
|
2007-12-08 15:04:36 -05:00
|
|
|
if (priv->last_scanned_channel)
|
2007-12-07 10:52:10 -05:00
|
|
|
return -EAGAIN;
|
|
|
|
|
2007-05-25 22:18:47 -04:00
|
|
|
/* Update RSSI if current BSS is a locally created ad-hoc BSS */
|
2007-12-08 15:04:36 -05:00
|
|
|
if ((priv->mode == IW_MODE_ADHOC) && priv->adhoccreate) {
|
2007-11-15 18:05:47 -05:00
|
|
|
lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
|
2007-08-02 11:31:18 -04:00
|
|
|
CMD_OPTION_WAITFORRSP, 0, NULL);
|
2007-05-25 22:18:47 -04:00
|
|
|
}
|
|
|
|
|
2007-12-08 15:04:36 -05:00
|
|
|
mutex_lock(&priv->lock);
|
|
|
|
list_for_each_entry_safe (iter_bss, safe, &priv->network_list, list) {
|
2007-05-25 16:15:56 -04:00
|
|
|
char * next_ev;
|
|
|
|
unsigned long stale_time;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
if (stop - ev < SCAN_ITEM_SIZE) {
|
|
|
|
err = -E2BIG;
|
|
|
|
break;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-08-02 10:51:27 -04:00
|
|
|
/* For mesh device, list only mesh networks */
|
|
|
|
if (dev == priv->mesh_dev && !iter_bss->mesh)
|
|
|
|
continue;
|
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
/* Prune old an old scan result */
|
|
|
|
stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE;
|
|
|
|
if (time_after(jiffies, stale_time)) {
|
|
|
|
list_move_tail (&iter_bss->list,
|
2007-12-08 15:04:36 -05:00
|
|
|
&priv->network_free_list);
|
2007-05-25 16:15:56 -04:00
|
|
|
clear_bss_descriptor(iter_bss);
|
|
|
|
continue;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
/* Translate to WE format this entry */
|
2007-11-15 18:05:47 -05:00
|
|
|
next_ev = lbs_translate_scan(priv, ev, stop, iter_bss);
|
2007-05-25 16:15:56 -04:00
|
|
|
if (next_ev == NULL)
|
|
|
|
continue;
|
|
|
|
ev = next_ev;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
2007-12-08 15:04:36 -05:00
|
|
|
mutex_unlock(&priv->lock);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
dwrq->length = (ev - extra);
|
2007-02-10 09:25:27 -05:00
|
|
|
dwrq->flags = 0;
|
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", err);
|
2007-05-25 16:15:56 -04:00
|
|
|
return err;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Command execution */
|
|
|
|
/* */
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
|
|
|
2007-02-10 09:25:27 -05:00
|
|
|
/**
|
|
|
|
* @brief Prepare a scan command to be sent to the firmware
|
|
|
|
*
|
2007-12-07 10:52:10 -05:00
|
|
|
* Called via lbs_prepare_and_send_command(priv, CMD_802_11_SCAN, ...)
|
|
|
|
* from cmd.c
|
2007-02-10 09:25:27 -05:00
|
|
|
*
|
2007-10-09 08:15:19 -04:00
|
|
|
* Sends a fixed lenght data part (specifying the BSS type and BSSID filters)
|
|
|
|
* as well as a variable number/length of TLVs to the firmware.
|
2007-02-10 09:25:27 -05:00
|
|
|
*
|
2007-11-23 09:43:44 -05:00
|
|
|
* @param priv A pointer to struct lbs_private structure
|
2007-02-10 09:25:27 -05:00
|
|
|
* @param cmd A pointer to cmd_ds_command structure to be sent to
|
|
|
|
* firmware with the cmd_DS_801_11_SCAN structure
|
2007-11-15 18:05:47 -05:00
|
|
|
* @param pdata_buf Void pointer cast of a lbs_scan_cmd_config struct used
|
2007-02-10 09:25:27 -05:00
|
|
|
* to set the fields/TLVs for the command sent to firmware
|
|
|
|
*
|
|
|
|
* @return 0 or -1
|
|
|
|
*/
|
2007-11-23 09:43:44 -05:00
|
|
|
int lbs_cmd_80211_scan(struct lbs_private *priv,
|
2007-12-07 10:52:10 -05:00
|
|
|
struct cmd_ds_command *cmd, void *pdata_buf)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
|
|
|
struct cmd_ds_802_11_scan *pscan = &cmd->params.scan;
|
2007-11-15 18:05:47 -05:00
|
|
|
struct lbs_scan_cmd_config *pscancfg = pdata_buf;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
|
|
|
/* Set fixed field variables in scan command */
|
|
|
|
pscan->bsstype = pscancfg->bsstype;
|
2007-08-02 11:16:07 -04:00
|
|
|
memcpy(pscan->bssid, pscancfg->bssid, ETH_ALEN);
|
2007-02-10 09:25:27 -05:00
|
|
|
memcpy(pscan->tlvbuffer, pscancfg->tlvbuffer, pscancfg->tlvbufferlen);
|
|
|
|
|
|
|
|
/* size is equal to the sizeof(fixed portions) + the TLV len + header */
|
2007-08-02 11:16:07 -04:00
|
|
|
cmd->size = cpu_to_le16(sizeof(pscan->bsstype) + ETH_ALEN
|
|
|
|
+ pscancfg->tlvbufferlen + S_DS_GEN);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_leave(LBS_DEB_SCAN);
|
2007-02-10 09:25:27 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function handles the command response of scan
|
|
|
|
*
|
2007-10-09 08:15:19 -04:00
|
|
|
* Called from handle_cmd_response() in cmdrespc.
|
|
|
|
*
|
2007-02-10 09:25:27 -05:00
|
|
|
* The response buffer for the scan command has the following
|
|
|
|
* memory layout:
|
|
|
|
*
|
|
|
|
* .-----------------------------------------------------------.
|
|
|
|
* | header (4 * sizeof(u16)): Standard command response hdr |
|
|
|
|
* .-----------------------------------------------------------.
|
|
|
|
* | bufsize (u16) : sizeof the BSS Description data |
|
|
|
|
* .-----------------------------------------------------------.
|
|
|
|
* | NumOfSet (u8) : Number of BSS Descs returned |
|
|
|
|
* .-----------------------------------------------------------.
|
|
|
|
* | BSSDescription data (variable, size given in bufsize) |
|
|
|
|
* .-----------------------------------------------------------.
|
|
|
|
* | TLV data (variable, size calculated using header->size, |
|
|
|
|
* | bufsize and sizeof the fixed fields above) |
|
|
|
|
* .-----------------------------------------------------------.
|
|
|
|
*
|
2007-11-23 09:43:44 -05:00
|
|
|
* @param priv A pointer to struct lbs_private structure
|
2007-02-10 09:25:27 -05:00
|
|
|
* @param resp A pointer to cmd_ds_command
|
|
|
|
*
|
|
|
|
* @return 0 or -1
|
|
|
|
*/
|
2007-11-23 09:43:44 -05:00
|
|
|
int lbs_ret_80211_scan(struct lbs_private *priv, struct cmd_ds_command *resp)
|
2007-02-10 09:25:27 -05:00
|
|
|
{
|
|
|
|
struct cmd_ds_802_11_scan_rsp *pscan;
|
2007-05-25 16:15:56 -04:00
|
|
|
struct bss_descriptor * iter_bss;
|
|
|
|
struct bss_descriptor * safe;
|
2007-02-10 09:25:27 -05:00
|
|
|
u8 *pbssinfo;
|
|
|
|
u16 scanrespsize;
|
|
|
|
int bytesleft;
|
|
|
|
int idx;
|
|
|
|
int tlvbufsize;
|
2007-05-25 11:27:16 -04:00
|
|
|
int ret;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-10-09 08:15:19 -04:00
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
/* Prune old entries from scan table */
|
2007-12-08 15:04:36 -05:00
|
|
|
list_for_each_entry_safe (iter_bss, safe, &priv->network_list, list) {
|
2007-05-25 16:15:56 -04:00
|
|
|
unsigned long stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE;
|
|
|
|
if (time_before(jiffies, stale_time))
|
|
|
|
continue;
|
2007-12-08 15:04:36 -05:00
|
|
|
list_move_tail (&iter_bss->list, &priv->network_free_list);
|
2007-05-25 16:15:56 -04:00
|
|
|
clear_bss_descriptor(iter_bss);
|
|
|
|
}
|
|
|
|
|
2007-02-10 09:25:27 -05:00
|
|
|
pscan = &resp->params.scanresp;
|
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
if (pscan->nr_sets > MAX_NETWORK_COUNT) {
|
|
|
|
lbs_deb_scan(
|
|
|
|
"SCAN_RESP: too many scan results (%d, max %d)!!\n",
|
|
|
|
pscan->nr_sets, MAX_NETWORK_COUNT);
|
2007-05-25 11:27:16 -04:00
|
|
|
ret = -1;
|
|
|
|
goto done;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-09-06 21:45:36 -04:00
|
|
|
bytesleft = le16_to_cpu(get_unaligned((u16*)&pscan->bssdescriptsize));
|
2007-05-25 11:27:16 -04:00
|
|
|
lbs_deb_scan("SCAN_RESP: bssdescriptsize %d\n", bytesleft);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-09-06 21:45:36 -04:00
|
|
|
scanrespsize = le16_to_cpu(get_unaligned((u16*)&resp->size));
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("SCAN_RESP: scan results %d\n",
|
2007-02-10 09:25:27 -05:00
|
|
|
pscan->nr_sets);
|
|
|
|
|
|
|
|
pbssinfo = pscan->bssdesc_and_tlvbuffer;
|
|
|
|
|
|
|
|
/* The size of the TLV buffer is equal to the entire command response
|
|
|
|
* size (scanrespsize) minus the fixed fields (sizeof()'s), the
|
|
|
|
* BSS Descriptions (bssdescriptsize as bytesLef) and the command
|
|
|
|
* response header (S_DS_GEN)
|
|
|
|
*/
|
|
|
|
tlvbufsize = scanrespsize - (bytesleft + sizeof(pscan->bssdescriptsize)
|
|
|
|
+ sizeof(pscan->nr_sets)
|
|
|
|
+ S_DS_GEN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process each scan response returned (pscan->nr_sets). Save
|
|
|
|
* the information in the newbssentry and then insert into the
|
|
|
|
* driver scan table either as an update to an existing entry
|
|
|
|
* or as an addition at the end of the table
|
|
|
|
*/
|
|
|
|
for (idx = 0; idx < pscan->nr_sets && bytesleft; idx++) {
|
2007-05-25 16:15:56 -04:00
|
|
|
struct bss_descriptor new;
|
|
|
|
struct bss_descriptor * found = NULL;
|
|
|
|
struct bss_descriptor * oldest = NULL;
|
2007-10-03 20:59:30 -04:00
|
|
|
DECLARE_MAC_BUF(mac);
|
2007-02-10 09:25:27 -05:00
|
|
|
|
|
|
|
/* Process the data fields and IEs returned for this BSS */
|
2007-05-25 16:15:56 -04:00
|
|
|
memset(&new, 0, sizeof (struct bss_descriptor));
|
2007-11-15 18:05:47 -05:00
|
|
|
if (lbs_process_bss(&new, &pbssinfo, &bytesleft) != 0) {
|
2007-05-25 16:15:56 -04:00
|
|
|
/* error parsing the scan response, skipped */
|
|
|
|
lbs_deb_scan("SCAN_RESP: process_bss returned ERROR\n");
|
|
|
|
continue;
|
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
/* Try to find this bss in the scan table */
|
2007-12-08 15:04:36 -05:00
|
|
|
list_for_each_entry (iter_bss, &priv->network_list, list) {
|
2007-05-25 16:15:56 -04:00
|
|
|
if (is_same_network(iter_bss, &new)) {
|
|
|
|
found = iter_bss;
|
|
|
|
break;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
if ((oldest == NULL) ||
|
|
|
|
(iter_bss->last_scanned < oldest->last_scanned))
|
|
|
|
oldest = iter_bss;
|
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 16:15:56 -04:00
|
|
|
if (found) {
|
|
|
|
/* found, clear it */
|
|
|
|
clear_bss_descriptor(found);
|
2007-12-08 15:04:36 -05:00
|
|
|
} else if (!list_empty(&priv->network_free_list)) {
|
2007-05-25 16:15:56 -04:00
|
|
|
/* Pull one from the free list */
|
2007-12-08 15:04:36 -05:00
|
|
|
found = list_entry(priv->network_free_list.next,
|
2007-05-25 16:15:56 -04:00
|
|
|
struct bss_descriptor, list);
|
2007-12-08 15:04:36 -05:00
|
|
|
list_move_tail(&found->list, &priv->network_list);
|
2007-05-25 16:15:56 -04:00
|
|
|
} else if (oldest) {
|
|
|
|
/* If there are no more slots, expire the oldest */
|
|
|
|
found = oldest;
|
|
|
|
clear_bss_descriptor(found);
|
2007-12-08 15:04:36 -05:00
|
|
|
list_move_tail(&found->list, &priv->network_list);
|
2007-02-10 09:25:27 -05:00
|
|
|
} else {
|
2007-05-25 16:15:56 -04:00
|
|
|
continue;
|
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-12-07 10:52:10 -05:00
|
|
|
lbs_deb_scan("SCAN_RESP: BSSID %s\n",
|
2007-10-03 20:59:30 -04:00
|
|
|
print_mac(mac, new.bssid));
|
2007-05-25 16:15:56 -04:00
|
|
|
|
|
|
|
/* Copy the locally created newbssentry to the scan table */
|
|
|
|
memcpy(found, &new, offsetof(struct bss_descriptor, list));
|
|
|
|
}
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 11:27:16 -04:00
|
|
|
ret = 0;
|
2007-02-10 09:25:27 -05:00
|
|
|
|
2007-05-25 11:27:16 -04:00
|
|
|
done:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
|
|
|
|
return ret;
|
2007-02-10 09:25:27 -05:00
|
|
|
}
|