2009-10-06 22:31:54 +08:00
|
|
|
/*
|
|
|
|
* Implement cfg80211 ("iw") support.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 M&N Solutions GmbH, 61191 Rosbach, Germany
|
|
|
|
* Holger Schurig <hs4233@mail.mn-solutions.de>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-05-03 07:49:14 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2011-06-06 18:43:46 +08:00
|
|
|
#include <linux/hardirq.h>
|
2010-08-11 09:01:06 +08:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/wait.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2010-06-05 14:20:42 +08:00
|
|
|
#include <linux/ieee80211.h>
|
2009-10-06 22:31:54 +08:00
|
|
|
#include <net/cfg80211.h>
|
2010-06-15 00:31:26 +08:00
|
|
|
#include <asm/unaligned.h>
|
2009-10-06 22:31:54 +08:00
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
#include "decl.h"
|
2009-10-06 22:31:54 +08:00
|
|
|
#include "cfg.h"
|
|
|
|
#include "cmd.h"
|
2011-07-22 03:43:17 +08:00
|
|
|
#include "mesh.h"
|
2009-10-06 22:31:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define CHAN2G(_channel, _freq, _flags) { \
|
|
|
|
.band = IEEE80211_BAND_2GHZ, \
|
|
|
|
.center_freq = (_freq), \
|
|
|
|
.hw_value = (_channel), \
|
|
|
|
.flags = (_flags), \
|
|
|
|
.max_antenna_gain = 0, \
|
|
|
|
.max_power = 30, \
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ieee80211_channel lbs_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),
|
|
|
|
};
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
#define RATETAB_ENT(_rate, _hw_value, _flags) { \
|
|
|
|
.bitrate = (_rate), \
|
|
|
|
.hw_value = (_hw_value), \
|
|
|
|
.flags = (_flags), \
|
2009-10-06 22:31:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
/* Table 6 in section 3.2.1.1 */
|
2009-10-06 22:31:54 +08:00
|
|
|
static struct ieee80211_rate lbs_rates[] = {
|
2010-06-15 00:31:26 +08:00
|
|
|
RATETAB_ENT(10, 0, 0),
|
|
|
|
RATETAB_ENT(20, 1, 0),
|
|
|
|
RATETAB_ENT(55, 2, 0),
|
|
|
|
RATETAB_ENT(110, 3, 0),
|
|
|
|
RATETAB_ENT(60, 9, 0),
|
|
|
|
RATETAB_ENT(90, 6, 0),
|
|
|
|
RATETAB_ENT(120, 7, 0),
|
|
|
|
RATETAB_ENT(180, 8, 0),
|
|
|
|
RATETAB_ENT(240, 9, 0),
|
|
|
|
RATETAB_ENT(360, 10, 0),
|
|
|
|
RATETAB_ENT(480, 11, 0),
|
|
|
|
RATETAB_ENT(540, 12, 0),
|
2009-10-06 22:31:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct ieee80211_supported_band lbs_band_2ghz = {
|
|
|
|
.channels = lbs_2ghz_channels,
|
|
|
|
.n_channels = ARRAY_SIZE(lbs_2ghz_channels),
|
|
|
|
.bitrates = lbs_rates,
|
|
|
|
.n_bitrates = ARRAY_SIZE(lbs_rates),
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const u32 cipher_suites[] = {
|
|
|
|
WLAN_CIPHER_SUITE_WEP40,
|
|
|
|
WLAN_CIPHER_SUITE_WEP104,
|
|
|
|
WLAN_CIPHER_SUITE_TKIP,
|
|
|
|
WLAN_CIPHER_SUITE_CCMP,
|
|
|
|
};
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
/* Time to stay on the channel */
|
|
|
|
#define LBS_DWELL_PASSIVE 100
|
|
|
|
#define LBS_DWELL_ACTIVE 40
|
2009-10-06 22:31:54 +08:00
|
|
|
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* Misc utility functions
|
|
|
|
*
|
|
|
|
* TLVs are Marvell specific. They are very similar to IEs, they have the
|
|
|
|
* same structure: type, length, data*. The only difference: for IEs, the
|
|
|
|
* type and length are u8, but for TLVs they're __le16.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1
|
|
|
|
* in the firmware spec
|
|
|
|
*/
|
2012-03-29 02:38:01 +08:00
|
|
|
static int lbs_auth_to_authtype(enum nl80211_auth_type auth_type)
|
2010-06-15 00:31:26 +08:00
|
|
|
{
|
|
|
|
int ret = -ENOTSUPP;
|
|
|
|
|
|
|
|
switch (auth_type) {
|
|
|
|
case NL80211_AUTHTYPE_OPEN_SYSTEM:
|
|
|
|
case NL80211_AUTHTYPE_SHARED_KEY:
|
|
|
|
ret = auth_type;
|
|
|
|
break;
|
|
|
|
case NL80211_AUTHTYPE_AUTOMATIC:
|
|
|
|
ret = NL80211_AUTHTYPE_OPEN_SYSTEM;
|
|
|
|
break;
|
|
|
|
case NL80211_AUTHTYPE_NETWORK_EAP:
|
|
|
|
ret = 0x80;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* silence compiler */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
|
|
|
* Various firmware commands need the list of supported rates, but with
|
|
|
|
* the hight-bit set for basic rates
|
|
|
|
*/
|
2010-06-15 00:31:26 +08:00
|
|
|
static int lbs_add_rates(u8 *rates)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
|
|
|
|
u8 rate = lbs_rates[i].bitrate / 5;
|
|
|
|
if (rate == 0x02 || rate == 0x04 ||
|
|
|
|
rate == 0x0b || rate == 0x16)
|
|
|
|
rate |= 0x80;
|
|
|
|
rates[i] = rate;
|
|
|
|
}
|
|
|
|
return ARRAY_SIZE(lbs_rates);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* TLV utility functions
|
|
|
|
*
|
|
|
|
* TLVs are Marvell specific. They are very similar to IEs, they have the
|
|
|
|
* same structure: type, length, data*. The only difference: for IEs, the
|
|
|
|
* type and length are u8, but for TLVs they're __le16.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add ssid TLV
|
|
|
|
*/
|
|
|
|
#define LBS_MAX_SSID_TLV_SIZE \
|
|
|
|
(sizeof(struct mrvl_ie_header) \
|
|
|
|
+ IEEE80211_MAX_SSID_LEN)
|
|
|
|
|
|
|
|
static int lbs_add_ssid_tlv(u8 *tlv, const u8 *ssid, int ssid_len)
|
|
|
|
{
|
|
|
|
struct mrvl_ie_ssid_param_set *ssid_tlv = (void *)tlv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TLV-ID SSID 00 00
|
|
|
|
* length 06 00
|
|
|
|
* ssid 4d 4e 54 45 53 54
|
|
|
|
*/
|
|
|
|
ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
|
|
|
|
ssid_tlv->header.len = cpu_to_le16(ssid_len);
|
|
|
|
memcpy(ssid_tlv->ssid, ssid, ssid_len);
|
|
|
|
return sizeof(ssid_tlv->header) + ssid_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add channel list TLV (section 8.4.2)
|
|
|
|
*
|
|
|
|
* Actual channel data comes from priv->wdev->wiphy->channels.
|
|
|
|
*/
|
|
|
|
#define LBS_MAX_CHANNEL_LIST_TLV_SIZE \
|
|
|
|
(sizeof(struct mrvl_ie_header) \
|
|
|
|
+ (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset)))
|
|
|
|
|
|
|
|
static int lbs_add_channel_list_tlv(struct lbs_private *priv, u8 *tlv,
|
|
|
|
int last_channel, int active_scan)
|
|
|
|
{
|
|
|
|
int chanscanparamsize = sizeof(struct chanscanparamset) *
|
|
|
|
(last_channel - priv->scan_channel);
|
|
|
|
|
|
|
|
struct mrvl_ie_header *header = (void *) tlv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TLV-ID CHANLIST 01 01
|
|
|
|
* length 0e 00
|
|
|
|
* channel 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
header->type = cpu_to_le16(TLV_TYPE_CHANLIST);
|
|
|
|
header->len = cpu_to_le16(chanscanparamsize);
|
|
|
|
tlv += sizeof(struct mrvl_ie_header);
|
|
|
|
|
|
|
|
/* lbs_deb_scan("scan: channels %d to %d\n", priv->scan_channel,
|
|
|
|
last_channel); */
|
|
|
|
memset(tlv, 0, chanscanparamsize);
|
|
|
|
|
|
|
|
while (priv->scan_channel < last_channel) {
|
|
|
|
struct chanscanparamset *param = (void *) tlv;
|
|
|
|
|
|
|
|
param->radiotype = CMD_SCAN_RADIO_TYPE_BG;
|
|
|
|
param->channumber =
|
|
|
|
priv->scan_req->channels[priv->scan_channel]->hw_value;
|
|
|
|
if (active_scan) {
|
|
|
|
param->maxscantime = cpu_to_le16(LBS_DWELL_ACTIVE);
|
|
|
|
} else {
|
|
|
|
param->chanscanmode.passivescan = 1;
|
|
|
|
param->maxscantime = cpu_to_le16(LBS_DWELL_PASSIVE);
|
|
|
|
}
|
|
|
|
tlv += sizeof(struct chanscanparamset);
|
|
|
|
priv->scan_channel++;
|
|
|
|
}
|
|
|
|
return sizeof(struct mrvl_ie_header) + chanscanparamsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add rates TLV
|
|
|
|
*
|
|
|
|
* The rates are in lbs_bg_rates[], but for the 802.11b
|
|
|
|
* rates the high bit is set. We add this TLV only because
|
|
|
|
* there's a firmware which otherwise doesn't report all
|
|
|
|
* APs in range.
|
|
|
|
*/
|
|
|
|
#define LBS_MAX_RATES_TLV_SIZE \
|
|
|
|
(sizeof(struct mrvl_ie_header) \
|
|
|
|
+ (ARRAY_SIZE(lbs_rates)))
|
|
|
|
|
|
|
|
/* Adds a TLV with all rates the hardware supports */
|
|
|
|
static int lbs_add_supported_rates_tlv(u8 *tlv)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TLV-ID RATES 01 00
|
|
|
|
* length 0e 00
|
|
|
|
* rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
|
|
|
|
*/
|
|
|
|
rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
|
|
|
|
tlv += sizeof(rate_tlv->header);
|
|
|
|
i = lbs_add_rates(tlv);
|
|
|
|
tlv += i;
|
|
|
|
rate_tlv->header.len = cpu_to_le16(i);
|
|
|
|
return sizeof(rate_tlv->header) + i;
|
|
|
|
}
|
|
|
|
|
2010-07-30 14:16:01 +08:00
|
|
|
/* Add common rates from a TLV and return the new end of the TLV */
|
|
|
|
static u8 *
|
|
|
|
add_ie_rates(u8 *tlv, const u8 *ie, int *nrates)
|
|
|
|
{
|
|
|
|
int hw, ap, ap_max = ie[1];
|
|
|
|
u8 hw_rate;
|
|
|
|
|
|
|
|
/* Advance past IE header */
|
|
|
|
ie += 2;
|
|
|
|
|
|
|
|
lbs_deb_hex(LBS_DEB_ASSOC, "AP IE Rates", (u8 *) ie, ap_max);
|
|
|
|
|
|
|
|
for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
|
|
|
|
hw_rate = lbs_rates[hw].bitrate / 5;
|
|
|
|
for (ap = 0; ap < ap_max; ap++) {
|
|
|
|
if (hw_rate == (ie[ap] & 0x7f)) {
|
|
|
|
*tlv++ = ie[ap];
|
|
|
|
*nrates = *nrates + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tlv;
|
|
|
|
}
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Adds a TLV with all rates the hardware *and* BSS supports.
|
|
|
|
*/
|
|
|
|
static int lbs_add_common_rates_tlv(u8 *tlv, struct cfg80211_bss *bss)
|
|
|
|
{
|
|
|
|
struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
|
2010-07-30 14:16:01 +08:00
|
|
|
const u8 *rates_eid, *ext_rates_eid;
|
|
|
|
int n = 0;
|
|
|
|
|
2012-11-29 08:25:20 +08:00
|
|
|
rcu_read_lock();
|
2010-07-30 14:16:01 +08:00
|
|
|
rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
|
|
|
|
ext_rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 01 00 TLV_TYPE_RATES
|
|
|
|
* 04 00 len
|
|
|
|
* 82 84 8b 96 rates
|
|
|
|
*/
|
|
|
|
rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
|
|
|
|
tlv += sizeof(rate_tlv->header);
|
|
|
|
|
2010-07-30 14:16:01 +08:00
|
|
|
/* Add basic rates */
|
|
|
|
if (rates_eid) {
|
|
|
|
tlv = add_ie_rates(tlv, rates_eid, &n);
|
|
|
|
|
|
|
|
/* Add extended rates, if any */
|
|
|
|
if (ext_rates_eid)
|
|
|
|
tlv = add_ie_rates(tlv, ext_rates_eid, &n);
|
|
|
|
} else {
|
|
|
|
lbs_deb_assoc("assoc: bss had no basic rate IE\n");
|
2010-06-15 00:31:26 +08:00
|
|
|
/* Fallback: add basic 802.11b rates */
|
|
|
|
*tlv++ = 0x82;
|
|
|
|
*tlv++ = 0x84;
|
|
|
|
*tlv++ = 0x8b;
|
|
|
|
*tlv++ = 0x96;
|
|
|
|
n = 4;
|
|
|
|
}
|
2012-11-29 08:25:20 +08:00
|
|
|
rcu_read_unlock();
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
rate_tlv->header.len = cpu_to_le16(n);
|
|
|
|
return sizeof(rate_tlv->header) + n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add auth type TLV.
|
|
|
|
*
|
|
|
|
* This is only needed for newer firmware (V9 and up).
|
|
|
|
*/
|
|
|
|
#define LBS_MAX_AUTH_TYPE_TLV_SIZE \
|
|
|
|
sizeof(struct mrvl_ie_auth_type)
|
|
|
|
|
|
|
|
static int lbs_add_auth_type_tlv(u8 *tlv, enum nl80211_auth_type auth_type)
|
|
|
|
{
|
|
|
|
struct mrvl_ie_auth_type *auth = (void *) tlv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1f 01 TLV_TYPE_AUTH_TYPE
|
|
|
|
* 01 00 len
|
|
|
|
* 01 auth type
|
|
|
|
*/
|
|
|
|
auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
|
|
|
|
auth->header.len = cpu_to_le16(sizeof(*auth)-sizeof(auth->header));
|
|
|
|
auth->auth = cpu_to_le16(lbs_auth_to_authtype(auth_type));
|
|
|
|
return sizeof(*auth);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add channel (phy ds) TLV
|
|
|
|
*/
|
|
|
|
#define LBS_MAX_CHANNEL_TLV_SIZE \
|
|
|
|
sizeof(struct mrvl_ie_header)
|
|
|
|
|
|
|
|
static int lbs_add_channel_tlv(u8 *tlv, u8 channel)
|
|
|
|
{
|
|
|
|
struct mrvl_ie_ds_param_set *ds = (void *) tlv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 03 00 TLV_TYPE_PHY_DS
|
|
|
|
* 01 00 len
|
|
|
|
* 06 channel
|
|
|
|
*/
|
|
|
|
ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
|
|
|
|
ds->header.len = cpu_to_le16(sizeof(*ds)-sizeof(ds->header));
|
|
|
|
ds->channel = channel;
|
|
|
|
return sizeof(*ds);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add (empty) CF param TLV of the form:
|
|
|
|
*/
|
|
|
|
#define LBS_MAX_CF_PARAM_TLV_SIZE \
|
|
|
|
sizeof(struct mrvl_ie_header)
|
|
|
|
|
|
|
|
static int lbs_add_cf_param_tlv(u8 *tlv)
|
|
|
|
{
|
|
|
|
struct mrvl_ie_cf_param_set *cf = (void *)tlv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 04 00 TLV_TYPE_CF
|
|
|
|
* 06 00 len
|
|
|
|
* 00 cfpcnt
|
|
|
|
* 00 cfpperiod
|
|
|
|
* 00 00 cfpmaxduration
|
|
|
|
* 00 00 cfpdurationremaining
|
|
|
|
*/
|
|
|
|
cf->header.type = cpu_to_le16(TLV_TYPE_CF);
|
|
|
|
cf->header.len = cpu_to_le16(sizeof(*cf)-sizeof(cf->header));
|
|
|
|
return sizeof(*cf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add WPA TLV
|
|
|
|
*/
|
|
|
|
#define LBS_MAX_WPA_TLV_SIZE \
|
|
|
|
(sizeof(struct mrvl_ie_header) \
|
|
|
|
+ 128 /* TODO: I guessed the size */)
|
|
|
|
|
|
|
|
static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len)
|
|
|
|
{
|
|
|
|
size_t tlv_len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need just convert an IE to an TLV. IEs use u8 for the header,
|
|
|
|
* u8 type
|
|
|
|
* u8 len
|
|
|
|
* u8[] data
|
|
|
|
* but TLVs use __le16 instead:
|
|
|
|
* __le16 type
|
|
|
|
* __le16 len
|
|
|
|
* u8[] data
|
|
|
|
*/
|
|
|
|
*tlv++ = *ie++;
|
|
|
|
*tlv++ = 0;
|
|
|
|
tlv_len = *tlv++ = *ie++;
|
|
|
|
*tlv++ = 0;
|
|
|
|
while (tlv_len--)
|
|
|
|
*tlv++ = *ie++;
|
|
|
|
/* the TLV is two bytes larger than the IE */
|
|
|
|
return ie_len + 2;
|
|
|
|
}
|
|
|
|
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
2010-06-15 00:31:26 +08:00
|
|
|
* Set Channel
|
|
|
|
*/
|
|
|
|
|
2012-06-06 14:18:22 +08:00
|
|
|
static int lbs_cfg_set_monitor_channel(struct wiphy *wiphy,
|
2012-11-09 04:25:48 +08:00
|
|
|
struct cfg80211_chan_def *chandef)
|
2009-10-06 22:31:54 +08:00
|
|
|
{
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
2010-06-15 00:31:26 +08:00
|
|
|
int ret = -ENOTSUPP;
|
|
|
|
|
2012-06-06 14:18:22 +08:00
|
|
|
lbs_deb_enter_args(LBS_DEB_CFG80211, "freq %d, type %d",
|
2012-11-09 04:25:48 +08:00
|
|
|
chandef->chan->center_freq,
|
|
|
|
cfg80211_get_chandef_type(chandef));
|
2010-06-15 00:31:26 +08:00
|
|
|
|
2012-11-09 04:25:48 +08:00
|
|
|
if (cfg80211_get_chandef_type(chandef) != NL80211_CHAN_NO_HT)
|
2010-06-15 00:31:26 +08:00
|
|
|
goto out;
|
|
|
|
|
2012-11-09 04:25:48 +08:00
|
|
|
ret = lbs_set_channel(priv, chandef->chan->hw_value);
|
2012-06-06 14:18:22 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lbs_cfg_set_mesh_channel(struct wiphy *wiphy,
|
|
|
|
struct net_device *netdev,
|
|
|
|
struct ieee80211_channel *channel)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
|
|
|
int ret = -ENOTSUPP;
|
|
|
|
|
|
|
|
lbs_deb_enter_args(LBS_DEB_CFG80211, "iface %s freq %d",
|
|
|
|
netdev_name(netdev), channel->center_freq);
|
|
|
|
|
|
|
|
if (netdev != priv->mesh_dev)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = lbs_mesh_set_channel(priv, channel->hw_value);
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
2010-06-15 00:31:26 +08:00
|
|
|
* Scanning
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When scanning, the firmware doesn't send a nul packet with the power-safe
|
|
|
|
* bit to the AP. So we cannot stay away from our current channel too long,
|
|
|
|
* otherwise we loose data. So take a "nap" while scanning every other
|
|
|
|
* while.
|
|
|
|
*/
|
|
|
|
#define LBS_SCAN_BEFORE_NAP 4
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When the firmware reports back a scan-result, it gives us an "u8 rssi",
|
|
|
|
* which isn't really an RSSI, as it becomes larger when moving away from
|
|
|
|
* the AP. Anyway, we need to convert that into mBm.
|
|
|
|
*/
|
|
|
|
#define LBS_SCAN_RSSI_TO_MBM(rssi) \
|
|
|
|
((-(int)rssi + 3)*100)
|
|
|
|
|
|
|
|
static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
|
|
|
|
struct cmd_header *resp)
|
|
|
|
{
|
2011-11-12 02:49:45 +08:00
|
|
|
struct cfg80211_bss *bss;
|
2010-06-15 00:31:26 +08:00
|
|
|
struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp;
|
|
|
|
int bsssize;
|
|
|
|
const u8 *pos;
|
|
|
|
const u8 *tsfdesc;
|
|
|
|
int tsfsize;
|
|
|
|
int i;
|
|
|
|
int ret = -EILSEQ;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
bsssize = get_unaligned_le16(&scanresp->bssdescriptsize);
|
2010-07-30 14:11:30 +08:00
|
|
|
|
|
|
|
lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n",
|
2010-09-16 03:40:12 +08:00
|
|
|
scanresp->nr_sets, bsssize, le16_to_cpu(resp->size));
|
2010-07-30 14:11:30 +08:00
|
|
|
|
2010-09-16 03:40:12 +08:00
|
|
|
if (scanresp->nr_sets == 0) {
|
2010-07-30 14:11:30 +08:00
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The general layout of the scan response is described in chapter
|
|
|
|
* 5.7.1. Basically we have a common part, then any number of BSS
|
|
|
|
* descriptor sections. Finally we have section with the same number
|
|
|
|
* of TSFs.
|
|
|
|
*
|
|
|
|
* cmd_ds_802_11_scan_rsp
|
|
|
|
* cmd_header
|
|
|
|
* pos_size
|
|
|
|
* nr_sets
|
|
|
|
* bssdesc 1
|
|
|
|
* bssid
|
|
|
|
* rssi
|
|
|
|
* timestamp
|
|
|
|
* intvl
|
|
|
|
* capa
|
|
|
|
* IEs
|
|
|
|
* bssdesc 2
|
|
|
|
* bssdesc n
|
|
|
|
* MrvlIEtypes_TsfFimestamp_t
|
|
|
|
* TSF for BSS 1
|
|
|
|
* TSF for BSS 2
|
|
|
|
* TSF for BSS n
|
|
|
|
*/
|
|
|
|
|
|
|
|
pos = scanresp->bssdesc_and_tlvbuffer;
|
|
|
|
|
2010-07-30 14:12:53 +08:00
|
|
|
lbs_deb_hex(LBS_DEB_SCAN, "SCAN_RSP", scanresp->bssdesc_and_tlvbuffer,
|
|
|
|
scanresp->bssdescriptsize);
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
tsfdesc = pos + bsssize;
|
|
|
|
tsfsize = 4 + 8 * scanresp->nr_sets;
|
2010-07-30 14:12:53 +08:00
|
|
|
lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TSF", (u8 *) tsfdesc, tsfsize);
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
/* Validity check: we expect a Marvell-Local TLV */
|
|
|
|
i = get_unaligned_le16(tsfdesc);
|
|
|
|
tsfdesc += 2;
|
2010-07-30 14:12:53 +08:00
|
|
|
if (i != TLV_TYPE_TSFTIMESTAMP) {
|
|
|
|
lbs_deb_scan("scan response: invalid TSF Timestamp %d\n", i);
|
2010-06-15 00:31:26 +08:00
|
|
|
goto done;
|
2010-07-30 14:12:53 +08:00
|
|
|
}
|
|
|
|
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
|
|
|
* Validity check: the TLV holds TSF values with 8 bytes each, so
|
|
|
|
* the size in the TLV must match the nr_sets value
|
|
|
|
*/
|
2010-06-15 00:31:26 +08:00
|
|
|
i = get_unaligned_le16(tsfdesc);
|
|
|
|
tsfdesc += 2;
|
2010-07-30 14:12:53 +08:00
|
|
|
if (i / 8 != scanresp->nr_sets) {
|
|
|
|
lbs_deb_scan("scan response: invalid number of TSF timestamp "
|
|
|
|
"sets (expected %d got %d)\n", scanresp->nr_sets,
|
|
|
|
i / 8);
|
2010-06-15 00:31:26 +08:00
|
|
|
goto done;
|
2010-07-30 14:12:53 +08:00
|
|
|
}
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
for (i = 0; i < scanresp->nr_sets; i++) {
|
|
|
|
const u8 *bssid;
|
|
|
|
const u8 *ie;
|
|
|
|
int left;
|
|
|
|
int ielen;
|
|
|
|
int rssi;
|
|
|
|
u16 intvl;
|
|
|
|
u16 capa;
|
|
|
|
int chan_no = -1;
|
|
|
|
const u8 *ssid = NULL;
|
|
|
|
u8 ssid_len = 0;
|
|
|
|
DECLARE_SSID_BUF(ssid_buf);
|
|
|
|
|
|
|
|
int len = get_unaligned_le16(pos);
|
|
|
|
pos += 2;
|
|
|
|
|
|
|
|
/* BSSID */
|
|
|
|
bssid = pos;
|
|
|
|
pos += ETH_ALEN;
|
|
|
|
/* RSSI */
|
|
|
|
rssi = *pos++;
|
|
|
|
/* Packet time stamp */
|
|
|
|
pos += 8;
|
|
|
|
/* Beacon interval */
|
|
|
|
intvl = get_unaligned_le16(pos);
|
|
|
|
pos += 2;
|
|
|
|
/* Capabilities */
|
|
|
|
capa = get_unaligned_le16(pos);
|
|
|
|
pos += 2;
|
|
|
|
|
|
|
|
/* To find out the channel, we must parse the IEs */
|
|
|
|
ie = pos;
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
|
|
|
* 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
|
|
|
|
* interval, capabilities
|
|
|
|
*/
|
2010-06-15 00:31:26 +08:00
|
|
|
ielen = left = len - (6 + 1 + 8 + 2 + 2);
|
|
|
|
while (left >= 2) {
|
|
|
|
u8 id, elen;
|
|
|
|
id = *pos++;
|
|
|
|
elen = *pos++;
|
|
|
|
left -= 2;
|
2010-07-30 14:12:53 +08:00
|
|
|
if (elen > left || elen == 0) {
|
|
|
|
lbs_deb_scan("scan response: invalid IE fmt\n");
|
2010-06-15 00:31:26 +08:00
|
|
|
goto done;
|
2010-07-30 14:12:53 +08:00
|
|
|
}
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
if (id == WLAN_EID_DS_PARAMS)
|
|
|
|
chan_no = *pos;
|
|
|
|
if (id == WLAN_EID_SSID) {
|
|
|
|
ssid = pos;
|
|
|
|
ssid_len = elen;
|
|
|
|
}
|
|
|
|
left -= elen;
|
|
|
|
pos += elen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No channel, no luck */
|
|
|
|
if (chan_no != -1) {
|
|
|
|
struct wiphy *wiphy = priv->wdev->wiphy;
|
2011-01-17 12:37:28 +08:00
|
|
|
int freq = ieee80211_channel_to_frequency(chan_no,
|
|
|
|
IEEE80211_BAND_2GHZ);
|
2010-06-15 00:31:26 +08:00
|
|
|
struct ieee80211_channel *channel =
|
|
|
|
ieee80211_get_channel(wiphy, freq);
|
|
|
|
|
|
|
|
lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %s, "
|
|
|
|
"%d dBm\n",
|
|
|
|
bssid, capa, chan_no,
|
|
|
|
print_ssid(ssid_buf, ssid, ssid_len),
|
|
|
|
LBS_SCAN_RSSI_TO_MBM(rssi)/100);
|
|
|
|
|
2010-12-09 16:38:36 +08:00
|
|
|
if (channel &&
|
2011-11-12 02:49:45 +08:00
|
|
|
!(channel->flags & IEEE80211_CHAN_DISABLED)) {
|
|
|
|
bss = cfg80211_inform_bss(wiphy, channel,
|
2011-11-09 16:30:40 +08:00
|
|
|
bssid, get_unaligned_le64(tsfdesc),
|
2010-06-15 00:31:26 +08:00
|
|
|
capa, intvl, ie, ielen,
|
|
|
|
LBS_SCAN_RSSI_TO_MBM(rssi),
|
|
|
|
GFP_KERNEL);
|
2013-02-01 08:49:58 +08:00
|
|
|
cfg80211_put_bss(wiphy, bss);
|
2011-11-12 02:49:45 +08:00
|
|
|
}
|
2010-07-30 14:12:53 +08:00
|
|
|
} else
|
|
|
|
lbs_deb_scan("scan response: missing BSS channel IE\n");
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
tsfdesc += 8;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our scan command contains a TLV, consting of a SSID TLV, a channel list
|
|
|
|
* TLV and a rates TLV. Determine the maximum size of them:
|
|
|
|
*/
|
|
|
|
#define LBS_SCAN_MAX_CMD_SIZE \
|
|
|
|
(sizeof(struct cmd_ds_802_11_scan) \
|
|
|
|
+ LBS_MAX_SSID_TLV_SIZE \
|
|
|
|
+ LBS_MAX_CHANNEL_LIST_TLV_SIZE \
|
|
|
|
+ LBS_MAX_RATES_TLV_SIZE)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assumes priv->scan_req is initialized and valid
|
|
|
|
* Assumes priv->scan_channel is initialized
|
|
|
|
*/
|
|
|
|
static void lbs_scan_worker(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv =
|
|
|
|
container_of(work, struct lbs_private, scan_work.work);
|
|
|
|
struct cmd_ds_802_11_scan *scan_cmd;
|
|
|
|
u8 *tlv; /* pointer into our current, growing TLV storage area */
|
|
|
|
int last_channel;
|
|
|
|
int running, carrier;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_SCAN);
|
|
|
|
|
|
|
|
scan_cmd = kzalloc(LBS_SCAN_MAX_CMD_SIZE, GFP_KERNEL);
|
|
|
|
if (scan_cmd == NULL)
|
|
|
|
goto out_no_scan_cmd;
|
|
|
|
|
|
|
|
/* prepare fixed part of scan command */
|
|
|
|
scan_cmd->bsstype = CMD_BSS_TYPE_ANY;
|
|
|
|
|
|
|
|
/* stop network while we're away from our main channel */
|
|
|
|
running = !netif_queue_stopped(priv->dev);
|
|
|
|
carrier = netif_carrier_ok(priv->dev);
|
|
|
|
if (running)
|
|
|
|
netif_stop_queue(priv->dev);
|
|
|
|
if (carrier)
|
|
|
|
netif_carrier_off(priv->dev);
|
|
|
|
|
|
|
|
/* prepare fixed part of scan command */
|
|
|
|
tlv = scan_cmd->tlvbuffer;
|
|
|
|
|
|
|
|
/* add SSID TLV */
|
2011-09-22 01:43:59 +08:00
|
|
|
if (priv->scan_req->n_ssids && priv->scan_req->ssids[0].ssid_len > 0)
|
2010-06-15 00:31:26 +08:00
|
|
|
tlv += lbs_add_ssid_tlv(tlv,
|
|
|
|
priv->scan_req->ssids[0].ssid,
|
|
|
|
priv->scan_req->ssids[0].ssid_len);
|
|
|
|
|
|
|
|
/* add channel TLVs */
|
|
|
|
last_channel = priv->scan_channel + LBS_SCAN_BEFORE_NAP;
|
|
|
|
if (last_channel > priv->scan_req->n_channels)
|
|
|
|
last_channel = priv->scan_req->n_channels;
|
|
|
|
tlv += lbs_add_channel_list_tlv(priv, tlv, last_channel,
|
|
|
|
priv->scan_req->n_ssids);
|
|
|
|
|
|
|
|
/* add rates TLV */
|
|
|
|
tlv += lbs_add_supported_rates_tlv(tlv);
|
|
|
|
|
|
|
|
if (priv->scan_channel < priv->scan_req->n_channels) {
|
|
|
|
cancel_delayed_work(&priv->scan_work);
|
2011-08-01 23:43:13 +08:00
|
|
|
if (netif_running(priv->dev))
|
2010-11-05 05:21:52 +08:00
|
|
|
queue_delayed_work(priv->work_thread, &priv->scan_work,
|
|
|
|
msecs_to_jiffies(300));
|
2010-06-15 00:31:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the final data we are about to send */
|
|
|
|
scan_cmd->hdr.size = cpu_to_le16(tlv - (u8 *)scan_cmd);
|
|
|
|
lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd,
|
|
|
|
sizeof(*scan_cmd));
|
|
|
|
lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer,
|
|
|
|
tlv - scan_cmd->tlvbuffer);
|
|
|
|
|
|
|
|
__lbs_cmd(priv, CMD_802_11_SCAN, &scan_cmd->hdr,
|
|
|
|
le16_to_cpu(scan_cmd->hdr.size),
|
|
|
|
lbs_ret_scan, 0);
|
|
|
|
|
libertas: clean up scan thread handling
The libertas scan thread expects priv->scan_req to be non-NULL. In theory,
it should always be set. In practice, we've seen the following oops:
[ 8363.067444] Unable to handle kernel NULL pointer dereference at virtual address 00000004
[ 8363.067490] pgd = c0004000
[ 8363.078393] [00000004] *pgd=00000000
[ 8363.086711] Internal error: Oops: 17 [#1] PREEMPT
[ 8363.091375] Modules linked in: fuse libertas_sdio libertas psmouse mousedev ov7670 mmp_camera joydev videobuf2_core videobuf2_dma_sg videobuf2_memops [last unloaded: scsi_wait_scan]
[ 8363.107490] CPU: 0 Not tainted (3.0.0-gf7ccc69 #671)
[ 8363.112799] PC is at lbs_scan_worker+0x108/0x5a4 [libertas]
[ 8363.118326] LR is at 0x0
[ 8363.120836] pc : [<bf03a854>] lr : [<00000000>] psr: 60000113
[ 8363.120845] sp : ee66bf48 ip : 00000000 fp : 00000000
[ 8363.120845] r10: ee2c2088 r9 : c04e2efc r8 : eef97005
[ 8363.132231] r7 : eee0716f r6 : ee2c02c0 r5 : ee2c2088 r4 : eee07160
[ 8363.137419] r3 : 00000000 r2 : a0000113 r1 : 00000001 r0 : eee07160
[ 8363.143896] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel
[ 8363.157630] Control: 10c5387d Table: 2e754019 DAC: 00000015
[ 8363.163334] Process kworker/u:1 (pid: 25, stack limit = 0xee66a2f8)
While I've not found a smoking gun, there are two places that raised red flags
for me. The first is in _internal_start_scan, when we queue up a scan; we
first queue the worker, and then set priv->scan_req. There's theoretically
a 50mS delay which should be plenty, but doing things that way just seems
racy (and not in the good way).
The second is in the scan worker thread itself. Depending on the state of
priv->scan_channel, we cancel pending scan runs and then requeue a run in
300mS. We then send the scan command down to the hardware, sleep, and if
we get scan results for all the desired channels, we set priv->scan_req to
NULL. However, it that's happened in less than 300mS, what happens with
the pending scan run?
This patch addresses both of those concerns. With the patch applied, we
have not seen the oops in the past two weeks.
Signed-off-by: Andres Salomon <dilinger@queued.net>
Cc: stable@kernel.org
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2011-12-20 04:22:58 +08:00
|
|
|
if (priv->scan_channel >= priv->scan_req->n_channels) {
|
2010-06-15 00:31:26 +08:00
|
|
|
/* Mark scan done */
|
libertas: clean up scan thread handling
The libertas scan thread expects priv->scan_req to be non-NULL. In theory,
it should always be set. In practice, we've seen the following oops:
[ 8363.067444] Unable to handle kernel NULL pointer dereference at virtual address 00000004
[ 8363.067490] pgd = c0004000
[ 8363.078393] [00000004] *pgd=00000000
[ 8363.086711] Internal error: Oops: 17 [#1] PREEMPT
[ 8363.091375] Modules linked in: fuse libertas_sdio libertas psmouse mousedev ov7670 mmp_camera joydev videobuf2_core videobuf2_dma_sg videobuf2_memops [last unloaded: scsi_wait_scan]
[ 8363.107490] CPU: 0 Not tainted (3.0.0-gf7ccc69 #671)
[ 8363.112799] PC is at lbs_scan_worker+0x108/0x5a4 [libertas]
[ 8363.118326] LR is at 0x0
[ 8363.120836] pc : [<bf03a854>] lr : [<00000000>] psr: 60000113
[ 8363.120845] sp : ee66bf48 ip : 00000000 fp : 00000000
[ 8363.120845] r10: ee2c2088 r9 : c04e2efc r8 : eef97005
[ 8363.132231] r7 : eee0716f r6 : ee2c02c0 r5 : ee2c2088 r4 : eee07160
[ 8363.137419] r3 : 00000000 r2 : a0000113 r1 : 00000001 r0 : eee07160
[ 8363.143896] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel
[ 8363.157630] Control: 10c5387d Table: 2e754019 DAC: 00000015
[ 8363.163334] Process kworker/u:1 (pid: 25, stack limit = 0xee66a2f8)
While I've not found a smoking gun, there are two places that raised red flags
for me. The first is in _internal_start_scan, when we queue up a scan; we
first queue the worker, and then set priv->scan_req. There's theoretically
a 50mS delay which should be plenty, but doing things that way just seems
racy (and not in the good way).
The second is in the scan worker thread itself. Depending on the state of
priv->scan_channel, we cancel pending scan runs and then requeue a run in
300mS. We then send the scan command down to the hardware, sleep, and if
we get scan results for all the desired channels, we set priv->scan_req to
NULL. However, it that's happened in less than 300mS, what happens with
the pending scan run?
This patch addresses both of those concerns. With the patch applied, we
have not seen the oops in the past two weeks.
Signed-off-by: Andres Salomon <dilinger@queued.net>
Cc: stable@kernel.org
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2011-12-20 04:22:58 +08:00
|
|
|
cancel_delayed_work(&priv->scan_work);
|
2011-10-27 01:19:26 +08:00
|
|
|
lbs_scan_done(priv);
|
libertas: clean up scan thread handling
The libertas scan thread expects priv->scan_req to be non-NULL. In theory,
it should always be set. In practice, we've seen the following oops:
[ 8363.067444] Unable to handle kernel NULL pointer dereference at virtual address 00000004
[ 8363.067490] pgd = c0004000
[ 8363.078393] [00000004] *pgd=00000000
[ 8363.086711] Internal error: Oops: 17 [#1] PREEMPT
[ 8363.091375] Modules linked in: fuse libertas_sdio libertas psmouse mousedev ov7670 mmp_camera joydev videobuf2_core videobuf2_dma_sg videobuf2_memops [last unloaded: scsi_wait_scan]
[ 8363.107490] CPU: 0 Not tainted (3.0.0-gf7ccc69 #671)
[ 8363.112799] PC is at lbs_scan_worker+0x108/0x5a4 [libertas]
[ 8363.118326] LR is at 0x0
[ 8363.120836] pc : [<bf03a854>] lr : [<00000000>] psr: 60000113
[ 8363.120845] sp : ee66bf48 ip : 00000000 fp : 00000000
[ 8363.120845] r10: ee2c2088 r9 : c04e2efc r8 : eef97005
[ 8363.132231] r7 : eee0716f r6 : ee2c02c0 r5 : ee2c2088 r4 : eee07160
[ 8363.137419] r3 : 00000000 r2 : a0000113 r1 : 00000001 r0 : eee07160
[ 8363.143896] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel
[ 8363.157630] Control: 10c5387d Table: 2e754019 DAC: 00000015
[ 8363.163334] Process kworker/u:1 (pid: 25, stack limit = 0xee66a2f8)
While I've not found a smoking gun, there are two places that raised red flags
for me. The first is in _internal_start_scan, when we queue up a scan; we
first queue the worker, and then set priv->scan_req. There's theoretically
a 50mS delay which should be plenty, but doing things that way just seems
racy (and not in the good way).
The second is in the scan worker thread itself. Depending on the state of
priv->scan_channel, we cancel pending scan runs and then requeue a run in
300mS. We then send the scan command down to the hardware, sleep, and if
we get scan results for all the desired channels, we set priv->scan_req to
NULL. However, it that's happened in less than 300mS, what happens with
the pending scan run?
This patch addresses both of those concerns. With the patch applied, we
have not seen the oops in the past two weeks.
Signed-off-by: Andres Salomon <dilinger@queued.net>
Cc: stable@kernel.org
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2011-12-20 04:22:58 +08:00
|
|
|
}
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
/* Restart network */
|
|
|
|
if (carrier)
|
|
|
|
netif_carrier_on(priv->dev);
|
|
|
|
if (running && !priv->tx_pending_len)
|
|
|
|
netif_wake_queue(priv->dev);
|
|
|
|
|
|
|
|
kfree(scan_cmd);
|
|
|
|
|
2010-08-04 13:43:47 +08:00
|
|
|
/* Wake up anything waiting on scan completion */
|
|
|
|
if (priv->scan_req == NULL) {
|
|
|
|
lbs_deb_scan("scan: waking up waiters\n");
|
|
|
|
wake_up_all(&priv->scan_q);
|
|
|
|
}
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
out_no_scan_cmd:
|
|
|
|
lbs_deb_leave(LBS_DEB_SCAN);
|
|
|
|
}
|
|
|
|
|
2010-08-04 13:43:47 +08:00
|
|
|
static void _internal_start_scan(struct lbs_private *priv, bool internal,
|
|
|
|
struct cfg80211_scan_request *request)
|
|
|
|
{
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
|
|
|
|
request->n_ssids, request->n_channels, request->ie_len);
|
|
|
|
|
|
|
|
priv->scan_channel = 0;
|
|
|
|
priv->scan_req = request;
|
|
|
|
priv->internal_scan = internal;
|
|
|
|
|
libertas: clean up scan thread handling
The libertas scan thread expects priv->scan_req to be non-NULL. In theory,
it should always be set. In practice, we've seen the following oops:
[ 8363.067444] Unable to handle kernel NULL pointer dereference at virtual address 00000004
[ 8363.067490] pgd = c0004000
[ 8363.078393] [00000004] *pgd=00000000
[ 8363.086711] Internal error: Oops: 17 [#1] PREEMPT
[ 8363.091375] Modules linked in: fuse libertas_sdio libertas psmouse mousedev ov7670 mmp_camera joydev videobuf2_core videobuf2_dma_sg videobuf2_memops [last unloaded: scsi_wait_scan]
[ 8363.107490] CPU: 0 Not tainted (3.0.0-gf7ccc69 #671)
[ 8363.112799] PC is at lbs_scan_worker+0x108/0x5a4 [libertas]
[ 8363.118326] LR is at 0x0
[ 8363.120836] pc : [<bf03a854>] lr : [<00000000>] psr: 60000113
[ 8363.120845] sp : ee66bf48 ip : 00000000 fp : 00000000
[ 8363.120845] r10: ee2c2088 r9 : c04e2efc r8 : eef97005
[ 8363.132231] r7 : eee0716f r6 : ee2c02c0 r5 : ee2c2088 r4 : eee07160
[ 8363.137419] r3 : 00000000 r2 : a0000113 r1 : 00000001 r0 : eee07160
[ 8363.143896] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kernel
[ 8363.157630] Control: 10c5387d Table: 2e754019 DAC: 00000015
[ 8363.163334] Process kworker/u:1 (pid: 25, stack limit = 0xee66a2f8)
While I've not found a smoking gun, there are two places that raised red flags
for me. The first is in _internal_start_scan, when we queue up a scan; we
first queue the worker, and then set priv->scan_req. There's theoretically
a 50mS delay which should be plenty, but doing things that way just seems
racy (and not in the good way).
The second is in the scan worker thread itself. Depending on the state of
priv->scan_channel, we cancel pending scan runs and then requeue a run in
300mS. We then send the scan command down to the hardware, sleep, and if
we get scan results for all the desired channels, we set priv->scan_req to
NULL. However, it that's happened in less than 300mS, what happens with
the pending scan run?
This patch addresses both of those concerns. With the patch applied, we
have not seen the oops in the past two weeks.
Signed-off-by: Andres Salomon <dilinger@queued.net>
Cc: stable@kernel.org
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2011-12-20 04:22:58 +08:00
|
|
|
queue_delayed_work(priv->work_thread, &priv->scan_work,
|
|
|
|
msecs_to_jiffies(50));
|
|
|
|
|
2010-08-04 13:43:47 +08:00
|
|
|
lbs_deb_leave(LBS_DEB_CFG80211);
|
|
|
|
}
|
2010-06-15 00:31:26 +08:00
|
|
|
|
2011-10-27 01:19:26 +08:00
|
|
|
/*
|
|
|
|
* Clean up priv->scan_req. Should be used to handle the allocation details.
|
|
|
|
*/
|
|
|
|
void lbs_scan_done(struct lbs_private *priv)
|
|
|
|
{
|
|
|
|
WARN_ON(!priv->scan_req);
|
|
|
|
|
|
|
|
if (priv->internal_scan)
|
|
|
|
kfree(priv->scan_req);
|
|
|
|
else
|
|
|
|
cfg80211_scan_done(priv->scan_req, false);
|
|
|
|
|
|
|
|
priv->scan_req = NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
static int lbs_cfg_scan(struct wiphy *wiphy,
|
|
|
|
struct cfg80211_scan_request *request)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
if (priv->scan_req || delayed_work_pending(&priv->scan_work)) {
|
|
|
|
/* old scan request not yet processed */
|
|
|
|
ret = -EAGAIN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-08-04 13:43:47 +08:00
|
|
|
_internal_start_scan(priv, false, request);
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
if (priv->surpriseremoved)
|
|
|
|
ret = -EIO;
|
|
|
|
|
|
|
|
out:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
2010-06-15 00:31:26 +08:00
|
|
|
* Events
|
|
|
|
*/
|
|
|
|
|
|
|
|
void lbs_send_disconnect_notification(struct lbs_private *priv)
|
|
|
|
{
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
cfg80211_disconnected(priv->dev,
|
|
|
|
0,
|
|
|
|
NULL, 0,
|
|
|
|
GFP_KERNEL);
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CFG80211);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event)
|
|
|
|
{
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
cfg80211_michael_mic_failure(priv->dev,
|
|
|
|
priv->assoc_bss,
|
|
|
|
event == MACREG_INT_CODE_MIC_ERR_MULTICAST ?
|
|
|
|
NL80211_KEYTYPE_GROUP :
|
|
|
|
NL80211_KEYTYPE_PAIRWISE,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
GFP_KERNEL);
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CFG80211);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
2010-06-15 00:31:26 +08:00
|
|
|
* Connect/disconnect
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This removes all WEP keys
|
|
|
|
*/
|
|
|
|
static int lbs_remove_wep_keys(struct lbs_private *priv)
|
|
|
|
{
|
|
|
|
struct cmd_ds_802_11_set_wep cmd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
|
|
|
cmd.hdr.size = cpu_to_le16(sizeof(cmd));
|
|
|
|
cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
|
|
|
|
cmd.action = cpu_to_le16(CMD_ACT_REMOVE);
|
|
|
|
|
|
|
|
ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CFG80211);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set WEP keys
|
|
|
|
*/
|
|
|
|
static int lbs_set_wep_keys(struct lbs_private *priv)
|
|
|
|
{
|
|
|
|
struct cmd_ds_802_11_set_wep cmd;
|
|
|
|
int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* command 13 00
|
|
|
|
* size 50 00
|
|
|
|
* sequence xx xx
|
|
|
|
* result 00 00
|
|
|
|
* action 02 00 ACT_ADD
|
|
|
|
* transmit key 00 00
|
|
|
|
* type for key 1 01 WEP40
|
|
|
|
* type for key 2 00
|
|
|
|
* type for key 3 00
|
|
|
|
* type for key 4 00
|
|
|
|
* key 1 39 39 39 39 39 00 00 00
|
|
|
|
* 00 00 00 00 00 00 00 00
|
|
|
|
* key 2 00 00 00 00 00 00 00 00
|
|
|
|
* 00 00 00 00 00 00 00 00
|
|
|
|
* key 3 00 00 00 00 00 00 00 00
|
|
|
|
* 00 00 00 00 00 00 00 00
|
|
|
|
* key 4 00 00 00 00 00 00 00 00
|
|
|
|
*/
|
|
|
|
if (priv->wep_key_len[0] || priv->wep_key_len[1] ||
|
|
|
|
priv->wep_key_len[2] || priv->wep_key_len[3]) {
|
|
|
|
/* Only set wep keys if we have at least one of them */
|
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
|
|
|
cmd.hdr.size = cpu_to_le16(sizeof(cmd));
|
|
|
|
cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
|
|
|
|
cmd.action = cpu_to_le16(CMD_ACT_ADD);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
switch (priv->wep_key_len[i]) {
|
|
|
|
case WLAN_KEY_LEN_WEP40:
|
|
|
|
cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
|
|
|
|
break;
|
|
|
|
case WLAN_KEY_LEN_WEP104:
|
|
|
|
cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cmd.keytype[i] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memcpy(cmd.keymaterial[i], priv->wep_key[i],
|
|
|
|
priv->wep_key_len[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
|
|
|
|
} else {
|
|
|
|
/* Otherwise remove all wep keys */
|
|
|
|
ret = lbs_remove_wep_keys(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CFG80211);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable/Disable RSN status
|
|
|
|
*/
|
|
|
|
static int lbs_enable_rsn(struct lbs_private *priv, int enable)
|
|
|
|
{
|
|
|
|
struct cmd_ds_802_11_enable_rsn cmd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", enable);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cmd 2f 00
|
|
|
|
* size 0c 00
|
|
|
|
* sequence xx xx
|
|
|
|
* result 00 00
|
|
|
|
* action 01 00 ACT_SET
|
|
|
|
* enable 01 00
|
|
|
|
*/
|
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
|
|
|
cmd.hdr.size = cpu_to_le16(sizeof(cmd));
|
|
|
|
cmd.action = cpu_to_le16(CMD_ACT_SET);
|
|
|
|
cmd.enable = cpu_to_le16(enable);
|
|
|
|
|
|
|
|
ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CFG80211);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set WPA/WPA key material
|
|
|
|
*/
|
|
|
|
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
|
|
|
* like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
|
|
|
|
* get rid of WEXT, this should go into host.h
|
|
|
|
*/
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
struct cmd_key_material {
|
|
|
|
struct cmd_header hdr;
|
|
|
|
|
|
|
|
__le16 action;
|
|
|
|
struct MrvlIEtype_keyParamSet param;
|
2010-07-14 22:37:03 +08:00
|
|
|
} __packed;
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
static int lbs_set_key_material(struct lbs_private *priv,
|
|
|
|
int key_type,
|
|
|
|
int key_info,
|
|
|
|
u8 *key, u16 key_len)
|
|
|
|
{
|
|
|
|
struct cmd_key_material cmd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Example for WPA (TKIP):
|
|
|
|
*
|
|
|
|
* cmd 5e 00
|
|
|
|
* size 34 00
|
|
|
|
* sequence xx xx
|
|
|
|
* result 00 00
|
|
|
|
* action 01 00
|
|
|
|
* TLV type 00 01 key param
|
|
|
|
* length 00 26
|
|
|
|
* key type 01 00 TKIP
|
|
|
|
* key info 06 00 UNICAST | ENABLED
|
|
|
|
* key len 20 00
|
|
|
|
* key 32 bytes
|
|
|
|
*/
|
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
|
|
|
cmd.hdr.size = cpu_to_le16(sizeof(cmd));
|
|
|
|
cmd.action = cpu_to_le16(CMD_ACT_SET);
|
|
|
|
cmd.param.type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
|
|
|
|
cmd.param.length = cpu_to_le16(sizeof(cmd.param) - 4);
|
|
|
|
cmd.param.keytypeid = cpu_to_le16(key_type);
|
|
|
|
cmd.param.keyinfo = cpu_to_le16(key_info);
|
|
|
|
cmd.param.keylen = cpu_to_le16(key_len);
|
|
|
|
if (key && key_len)
|
|
|
|
memcpy(cmd.param.key, key, key_len);
|
|
|
|
|
|
|
|
ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CFG80211);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets the auth type (open, shared, etc) in the firmware. That
|
|
|
|
* we use CMD_802_11_AUTHENTICATE is misleading, this firmware
|
|
|
|
* command doesn't send an authentication frame at all, it just
|
|
|
|
* stores the auth_type.
|
|
|
|
*/
|
|
|
|
static int lbs_set_authtype(struct lbs_private *priv,
|
|
|
|
struct cfg80211_connect_params *sme)
|
|
|
|
{
|
|
|
|
struct cmd_ds_802_11_authenticate cmd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", sme->auth_type);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cmd 11 00
|
|
|
|
* size 19 00
|
|
|
|
* sequence xx xx
|
|
|
|
* result 00 00
|
|
|
|
* BSS id 00 13 19 80 da 30
|
|
|
|
* auth type 00
|
|
|
|
* reserved 00 00 00 00 00 00 00 00 00 00
|
|
|
|
*/
|
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
|
|
|
cmd.hdr.size = cpu_to_le16(sizeof(cmd));
|
|
|
|
if (sme->bssid)
|
|
|
|
memcpy(cmd.bssid, sme->bssid, ETH_ALEN);
|
|
|
|
/* convert auth_type */
|
|
|
|
ret = lbs_auth_to_authtype(sme->auth_type);
|
|
|
|
if (ret < 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
cmd.authtype = ret;
|
|
|
|
ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd);
|
|
|
|
|
|
|
|
done:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create association request
|
|
|
|
*/
|
|
|
|
#define LBS_ASSOC_MAX_CMD_SIZE \
|
|
|
|
(sizeof(struct cmd_ds_802_11_associate) \
|
|
|
|
- 512 /* cmd_ds_802_11_associate.iebuf */ \
|
|
|
|
+ LBS_MAX_SSID_TLV_SIZE \
|
|
|
|
+ LBS_MAX_CHANNEL_TLV_SIZE \
|
|
|
|
+ LBS_MAX_CF_PARAM_TLV_SIZE \
|
|
|
|
+ LBS_MAX_AUTH_TYPE_TLV_SIZE \
|
|
|
|
+ LBS_MAX_WPA_TLV_SIZE)
|
|
|
|
|
|
|
|
static int lbs_associate(struct lbs_private *priv,
|
|
|
|
struct cfg80211_bss *bss,
|
|
|
|
struct cfg80211_connect_params *sme)
|
|
|
|
{
|
|
|
|
struct cmd_ds_802_11_associate_response *resp;
|
|
|
|
struct cmd_ds_802_11_associate *cmd = kzalloc(LBS_ASSOC_MAX_CMD_SIZE,
|
|
|
|
GFP_KERNEL);
|
|
|
|
const u8 *ssid_eid;
|
|
|
|
size_t len, resp_ie_len;
|
|
|
|
int status;
|
|
|
|
int ret;
|
|
|
|
u8 *pos = &(cmd->iebuf[0]);
|
2010-07-30 14:16:01 +08:00
|
|
|
u8 *tmp;
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
if (!cmd) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cmd 50 00
|
|
|
|
* length 34 00
|
|
|
|
* sequence xx xx
|
|
|
|
* result 00 00
|
|
|
|
* BSS id 00 13 19 80 da 30
|
|
|
|
* capabilities 11 00
|
|
|
|
* listen interval 0a 00
|
|
|
|
* beacon interval 00 00
|
|
|
|
* DTIM period 00
|
|
|
|
* TLVs xx (up to 512 bytes)
|
|
|
|
*/
|
|
|
|
cmd->hdr.command = cpu_to_le16(CMD_802_11_ASSOCIATE);
|
|
|
|
|
|
|
|
/* Fill in static fields */
|
|
|
|
memcpy(cmd->bssid, bss->bssid, ETH_ALEN);
|
|
|
|
cmd->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
|
|
|
|
cmd->capability = cpu_to_le16(bss->capability);
|
|
|
|
|
|
|
|
/* add SSID TLV */
|
2012-11-29 08:25:20 +08:00
|
|
|
rcu_read_lock();
|
2010-06-15 00:31:26 +08:00
|
|
|
ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
|
|
|
|
if (ssid_eid)
|
|
|
|
pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_eid[1]);
|
|
|
|
else
|
|
|
|
lbs_deb_assoc("no SSID\n");
|
2012-11-29 08:25:20 +08:00
|
|
|
rcu_read_unlock();
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
/* add DS param TLV */
|
|
|
|
if (bss->channel)
|
|
|
|
pos += lbs_add_channel_tlv(pos, bss->channel->hw_value);
|
|
|
|
else
|
|
|
|
lbs_deb_assoc("no channel\n");
|
|
|
|
|
|
|
|
/* add (empty) CF param TLV */
|
|
|
|
pos += lbs_add_cf_param_tlv(pos);
|
|
|
|
|
|
|
|
/* add rates TLV */
|
2010-07-30 14:16:01 +08:00
|
|
|
tmp = pos + 4; /* skip Marvell IE header */
|
2010-06-15 00:31:26 +08:00
|
|
|
pos += lbs_add_common_rates_tlv(pos, bss);
|
2010-07-30 14:16:01 +08:00
|
|
|
lbs_deb_hex(LBS_DEB_ASSOC, "Common Rates", tmp, pos - tmp);
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
/* add auth type TLV */
|
2010-07-30 14:14:33 +08:00
|
|
|
if (MRVL_FW_MAJOR_REV(priv->fwrelease) >= 9)
|
2010-06-15 00:31:26 +08:00
|
|
|
pos += lbs_add_auth_type_tlv(pos, sme->auth_type);
|
|
|
|
|
|
|
|
/* add WPA/WPA2 TLV */
|
|
|
|
if (sme->ie && sme->ie_len)
|
|
|
|
pos += lbs_add_wpa_tlv(pos, sme->ie, sme->ie_len);
|
|
|
|
|
|
|
|
len = (sizeof(*cmd) - sizeof(cmd->iebuf)) +
|
|
|
|
(u16)(pos - (u8 *) &cmd->iebuf);
|
|
|
|
cmd->hdr.size = cpu_to_le16(len);
|
|
|
|
|
2010-07-30 14:14:33 +08:00
|
|
|
lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_CMD", (u8 *) cmd,
|
|
|
|
le16_to_cpu(cmd->hdr.size));
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
/* store for later use */
|
|
|
|
memcpy(priv->assoc_bss, bss->bssid, ETH_ALEN);
|
|
|
|
|
|
|
|
ret = lbs_cmd_with_response(priv, CMD_802_11_ASSOCIATE, cmd);
|
|
|
|
if (ret)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* generate connect message to cfg80211 */
|
|
|
|
|
|
|
|
resp = (void *) cmd; /* recast for easier field access */
|
|
|
|
status = le16_to_cpu(resp->statuscode);
|
|
|
|
|
2010-07-30 14:14:33 +08:00
|
|
|
/* Older FW versions map the IEEE 802.11 Status Code in the association
|
|
|
|
* response to the following values returned in resp->statuscode:
|
|
|
|
*
|
|
|
|
* IEEE Status Code Marvell Status Code
|
|
|
|
* 0 -> 0x0000 ASSOC_RESULT_SUCCESS
|
|
|
|
* 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
|
|
|
|
* 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
|
|
|
|
* 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
|
|
|
|
* 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
|
|
|
|
* others -> 0x0003 ASSOC_RESULT_REFUSED
|
|
|
|
*
|
|
|
|
* Other response codes:
|
|
|
|
* 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
|
|
|
|
* 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
|
|
|
|
* association response from the AP)
|
|
|
|
*/
|
|
|
|
if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
|
2010-06-15 00:31:26 +08:00
|
|
|
switch (status) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
lbs_deb_assoc("invalid association parameters\n");
|
|
|
|
status = WLAN_STATUS_CAPS_UNSUPPORTED;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
lbs_deb_assoc("timer expired while waiting for AP\n");
|
|
|
|
status = WLAN_STATUS_AUTH_TIMEOUT;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
lbs_deb_assoc("association refused by AP\n");
|
|
|
|
status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
lbs_deb_assoc("authentication refused by AP\n");
|
|
|
|
status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lbs_deb_assoc("association failure %d\n", status);
|
2010-07-30 14:14:33 +08:00
|
|
|
/* v5 OLPC firmware does return the AP status code if
|
|
|
|
* it's not one of the values above. Let that through.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
2010-06-15 00:31:26 +08:00
|
|
|
}
|
|
|
|
|
2010-07-30 14:14:33 +08:00
|
|
|
lbs_deb_assoc("status %d, statuscode 0x%04x, capability 0x%04x, "
|
|
|
|
"aid 0x%04x\n", status, le16_to_cpu(resp->statuscode),
|
|
|
|
le16_to_cpu(resp->capability), le16_to_cpu(resp->aid));
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
resp_ie_len = le16_to_cpu(resp->hdr.size)
|
|
|
|
- sizeof(resp->hdr)
|
|
|
|
- 6;
|
|
|
|
cfg80211_connect_result(priv->dev,
|
|
|
|
priv->assoc_bss,
|
|
|
|
sme->ie, sme->ie_len,
|
|
|
|
resp->iebuf, resp_ie_len,
|
|
|
|
status,
|
|
|
|
GFP_KERNEL);
|
|
|
|
|
|
|
|
if (status == 0) {
|
|
|
|
/* TODO: get rid of priv->connect_status */
|
|
|
|
priv->connect_status = LBS_CONNECTED;
|
|
|
|
netif_carrier_on(priv->dev);
|
|
|
|
if (!priv->tx_pending_len)
|
|
|
|
netif_tx_wake_all_queues(priv->dev);
|
|
|
|
}
|
|
|
|
|
2012-08-02 04:35:36 +08:00
|
|
|
kfree(cmd);
|
2010-06-15 00:31:26 +08:00
|
|
|
done:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-04 13:43:47 +08:00
|
|
|
static struct cfg80211_scan_request *
|
|
|
|
_new_connect_scan_req(struct wiphy *wiphy, struct cfg80211_connect_params *sme)
|
|
|
|
{
|
|
|
|
struct cfg80211_scan_request *creq = NULL;
|
|
|
|
int i, n_channels = 0;
|
|
|
|
enum ieee80211_band band;
|
|
|
|
|
|
|
|
for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
|
|
|
|
if (wiphy->bands[band])
|
|
|
|
n_channels += wiphy->bands[band]->n_channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
|
|
|
|
n_channels * sizeof(void *),
|
|
|
|
GFP_ATOMIC);
|
|
|
|
if (!creq)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* SSIDs come after channels */
|
|
|
|
creq->ssids = (void *)&creq->channels[n_channels];
|
|
|
|
creq->n_channels = n_channels;
|
|
|
|
creq->n_ssids = 1;
|
|
|
|
|
|
|
|
/* Scan all available channels */
|
|
|
|
i = 0;
|
|
|
|
for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (!wiphy->bands[band])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
|
|
|
|
/* ignore disabled channels */
|
|
|
|
if (wiphy->bands[band]->channels[j].flags &
|
|
|
|
IEEE80211_CHAN_DISABLED)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
creq->channels[i] = &wiphy->bands[band]->channels[j];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i) {
|
|
|
|
/* Set real number of channels specified in creq->channels[] */
|
|
|
|
creq->n_channels = i;
|
|
|
|
|
|
|
|
/* Scan for the SSID we're going to connect to */
|
|
|
|
memcpy(creq->ssids[0].ssid, sme->ssid, sme->ssid_len);
|
|
|
|
creq->ssids[0].ssid_len = sme->ssid_len;
|
|
|
|
} else {
|
|
|
|
/* No channels found... */
|
|
|
|
kfree(creq);
|
|
|
|
creq = NULL;
|
|
|
|
}
|
2010-06-15 00:31:26 +08:00
|
|
|
|
2010-08-04 13:43:47 +08:00
|
|
|
return creq;
|
|
|
|
}
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
|
|
|
|
struct cfg80211_connect_params *sme)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
|
|
|
struct cfg80211_bss *bss = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
u8 preamble = RADIO_PREAMBLE_SHORT;
|
|
|
|
|
2011-07-22 03:43:17 +08:00
|
|
|
if (dev == priv->mesh_dev)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
2010-08-04 13:43:47 +08:00
|
|
|
if (!sme->bssid) {
|
2011-09-22 01:43:59 +08:00
|
|
|
struct cfg80211_scan_request *creq;
|
2010-06-15 00:31:26 +08:00
|
|
|
|
2011-09-22 01:43:59 +08:00
|
|
|
/*
|
|
|
|
* Scan for the requested network after waiting for existing
|
|
|
|
* scans to finish.
|
|
|
|
*/
|
|
|
|
lbs_deb_assoc("assoc: waiting for existing scans\n");
|
|
|
|
wait_event_interruptible_timeout(priv->scan_q,
|
|
|
|
(priv->scan_req == NULL),
|
|
|
|
(15 * HZ));
|
2010-08-04 13:43:47 +08:00
|
|
|
|
2011-09-22 01:43:59 +08:00
|
|
|
creq = _new_connect_scan_req(wiphy, sme);
|
|
|
|
if (!creq) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto done;
|
2010-08-04 13:43:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-22 01:43:59 +08:00
|
|
|
lbs_deb_assoc("assoc: scanning for compatible AP\n");
|
|
|
|
_internal_start_scan(priv, true, creq);
|
|
|
|
|
2010-08-04 13:43:47 +08:00
|
|
|
lbs_deb_assoc("assoc: waiting for scan to complete\n");
|
|
|
|
wait_event_interruptible_timeout(priv->scan_q,
|
|
|
|
(priv->scan_req == NULL),
|
|
|
|
(15 * HZ));
|
|
|
|
lbs_deb_assoc("assoc: scanning competed\n");
|
|
|
|
}
|
2010-06-15 00:31:26 +08:00
|
|
|
|
2010-08-04 13:43:47 +08:00
|
|
|
/* Find the BSS we want using available scan results */
|
|
|
|
bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
|
|
|
|
sme->ssid, sme->ssid_len,
|
|
|
|
WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
|
2010-06-15 00:31:26 +08:00
|
|
|
if (!bss) {
|
2011-05-03 07:49:15 +08:00
|
|
|
wiphy_err(wiphy, "assoc: bss %pM not in scan results\n",
|
|
|
|
sme->bssid);
|
2010-06-15 00:31:26 +08:00
|
|
|
ret = -ENOENT;
|
|
|
|
goto done;
|
|
|
|
}
|
2010-08-04 13:43:47 +08:00
|
|
|
lbs_deb_assoc("trying %pM\n", bss->bssid);
|
2010-06-15 00:31:26 +08:00
|
|
|
lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
|
|
|
|
sme->crypto.cipher_group,
|
|
|
|
sme->key_idx, sme->key_len);
|
|
|
|
|
|
|
|
/* As this is a new connection, clear locally stored WEP keys */
|
|
|
|
priv->wep_tx_key = 0;
|
|
|
|
memset(priv->wep_key, 0, sizeof(priv->wep_key));
|
|
|
|
memset(priv->wep_key_len, 0, sizeof(priv->wep_key_len));
|
|
|
|
|
|
|
|
/* set/remove WEP keys */
|
|
|
|
switch (sme->crypto.cipher_group) {
|
|
|
|
case WLAN_CIPHER_SUITE_WEP40:
|
|
|
|
case WLAN_CIPHER_SUITE_WEP104:
|
|
|
|
/* Store provided WEP keys in priv-> */
|
|
|
|
priv->wep_tx_key = sme->key_idx;
|
|
|
|
priv->wep_key_len[sme->key_idx] = sme->key_len;
|
|
|
|
memcpy(priv->wep_key[sme->key_idx], sme->key, sme->key_len);
|
|
|
|
/* Set WEP keys and WEP mode */
|
|
|
|
lbs_set_wep_keys(priv);
|
|
|
|
priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
|
|
|
|
lbs_set_mac_control(priv);
|
|
|
|
/* No RSN mode for WEP */
|
|
|
|
lbs_enable_rsn(priv, 0);
|
|
|
|
break;
|
|
|
|
case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */
|
|
|
|
/*
|
|
|
|
* If we don't have no WEP, no WPA and no WPA2,
|
|
|
|
* we remove all keys like in the WPA/WPA2 setup,
|
|
|
|
* we just don't set RSN.
|
|
|
|
*
|
2011-03-31 09:57:33 +08:00
|
|
|
* Therefore: fall-through
|
2010-06-15 00:31:26 +08:00
|
|
|
*/
|
|
|
|
case WLAN_CIPHER_SUITE_TKIP:
|
|
|
|
case WLAN_CIPHER_SUITE_CCMP:
|
|
|
|
/* Remove WEP keys and WEP mode */
|
|
|
|
lbs_remove_wep_keys(priv);
|
|
|
|
priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
|
|
|
|
lbs_set_mac_control(priv);
|
|
|
|
|
|
|
|
/* clear the WPA/WPA2 keys */
|
|
|
|
lbs_set_key_material(priv,
|
|
|
|
KEY_TYPE_ID_WEP, /* doesn't matter */
|
|
|
|
KEY_INFO_WPA_UNICAST,
|
|
|
|
NULL, 0);
|
|
|
|
lbs_set_key_material(priv,
|
|
|
|
KEY_TYPE_ID_WEP, /* doesn't matter */
|
|
|
|
KEY_INFO_WPA_MCAST,
|
|
|
|
NULL, 0);
|
|
|
|
/* RSN mode for WPA/WPA2 */
|
|
|
|
lbs_enable_rsn(priv, sme->crypto.cipher_group != 0);
|
|
|
|
break;
|
|
|
|
default:
|
2011-05-03 07:49:15 +08:00
|
|
|
wiphy_err(wiphy, "unsupported cipher group 0x%x\n",
|
|
|
|
sme->crypto.cipher_group);
|
2010-06-15 00:31:26 +08:00
|
|
|
ret = -ENOTSUPP;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2012-03-29 02:38:01 +08:00
|
|
|
ret = lbs_set_authtype(priv, sme);
|
|
|
|
if (ret == -ENOTSUPP) {
|
|
|
|
wiphy_err(wiphy, "unsupported authtype 0x%x\n", sme->auth_type);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
lbs_set_radio(priv, preamble, 1);
|
|
|
|
|
|
|
|
/* Do the actual association */
|
2010-08-04 13:43:47 +08:00
|
|
|
ret = lbs_associate(priv, bss, sme);
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (bss)
|
2013-02-01 08:49:58 +08:00
|
|
|
cfg80211_put_bss(wiphy, bss);
|
2010-06-15 00:31:26 +08:00
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-08-01 23:43:13 +08:00
|
|
|
int lbs_disconnect(struct lbs_private *priv, u16 reason)
|
2010-06-15 00:31:26 +08:00
|
|
|
{
|
|
|
|
struct cmd_ds_802_11_deauthenticate cmd;
|
2011-08-01 23:43:13 +08:00
|
|
|
int ret;
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
|
|
|
cmd.hdr.size = cpu_to_le16(sizeof(cmd));
|
|
|
|
/* Mildly ugly to use a locally store my own BSSID ... */
|
|
|
|
memcpy(cmd.macaddr, &priv->assoc_bss, ETH_ALEN);
|
2011-08-01 23:43:13 +08:00
|
|
|
cmd.reasoncode = cpu_to_le16(reason);
|
2010-06-15 00:31:26 +08:00
|
|
|
|
2011-08-01 23:43:13 +08:00
|
|
|
ret = lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2010-06-05 14:20:37 +08:00
|
|
|
|
|
|
|
cfg80211_disconnected(priv->dev,
|
2011-08-01 23:43:13 +08:00
|
|
|
reason,
|
2010-06-05 14:20:37 +08:00
|
|
|
NULL, 0,
|
|
|
|
GFP_KERNEL);
|
|
|
|
priv->connect_status = LBS_DISCONNECTED;
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 23:43:13 +08:00
|
|
|
static int lbs_cfg_disconnect(struct wiphy *wiphy, struct net_device *dev,
|
|
|
|
u16 reason_code)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
|
|
|
|
|
|
|
if (dev == priv->mesh_dev)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
lbs_deb_enter_args(LBS_DEB_CFG80211, "reason_code %d", reason_code);
|
|
|
|
|
|
|
|
/* store for lbs_cfg_ret_disconnect() */
|
|
|
|
priv->disassoc_reason = reason_code;
|
|
|
|
|
|
|
|
return lbs_disconnect(priv, reason_code);
|
|
|
|
}
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
static int lbs_cfg_set_default_key(struct wiphy *wiphy,
|
|
|
|
struct net_device *netdev,
|
2010-12-10 02:58:59 +08:00
|
|
|
u8 key_index, bool unicast,
|
|
|
|
bool multicast)
|
2010-06-15 00:31:26 +08:00
|
|
|
{
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
|
|
|
|
2011-07-22 03:43:17 +08:00
|
|
|
if (netdev == priv->mesh_dev)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
if (key_index != priv->wep_tx_key) {
|
|
|
|
lbs_deb_assoc("set_default_key: to %d\n", key_index);
|
|
|
|
priv->wep_tx_key = key_index;
|
|
|
|
lbs_set_wep_keys(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int lbs_cfg_add_key(struct wiphy *wiphy, struct net_device *netdev,
|
2010-10-06 01:39:30 +08:00
|
|
|
u8 idx, bool pairwise, const u8 *mac_addr,
|
2010-06-15 00:31:26 +08:00
|
|
|
struct key_params *params)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
|
|
|
u16 key_info;
|
|
|
|
u16 key_type;
|
|
|
|
int ret = 0;
|
|
|
|
|
2011-07-22 03:43:17 +08:00
|
|
|
if (netdev == priv->mesh_dev)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
lbs_deb_assoc("add_key: cipher 0x%x, mac_addr %pM\n",
|
|
|
|
params->cipher, mac_addr);
|
|
|
|
lbs_deb_assoc("add_key: key index %d, key len %d\n",
|
|
|
|
idx, params->key_len);
|
|
|
|
if (params->key_len)
|
|
|
|
lbs_deb_hex(LBS_DEB_CFG80211, "KEY",
|
|
|
|
params->key, params->key_len);
|
|
|
|
|
|
|
|
lbs_deb_assoc("add_key: seq len %d\n", params->seq_len);
|
|
|
|
if (params->seq_len)
|
|
|
|
lbs_deb_hex(LBS_DEB_CFG80211, "SEQ",
|
|
|
|
params->seq, params->seq_len);
|
|
|
|
|
|
|
|
switch (params->cipher) {
|
|
|
|
case WLAN_CIPHER_SUITE_WEP40:
|
|
|
|
case WLAN_CIPHER_SUITE_WEP104:
|
|
|
|
/* actually compare if something has changed ... */
|
|
|
|
if ((priv->wep_key_len[idx] != params->key_len) ||
|
|
|
|
memcmp(priv->wep_key[idx],
|
|
|
|
params->key, params->key_len) != 0) {
|
|
|
|
priv->wep_key_len[idx] = params->key_len;
|
|
|
|
memcpy(priv->wep_key[idx],
|
|
|
|
params->key, params->key_len);
|
|
|
|
lbs_set_wep_keys(priv);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WLAN_CIPHER_SUITE_TKIP:
|
|
|
|
case WLAN_CIPHER_SUITE_CCMP:
|
|
|
|
key_info = KEY_INFO_WPA_ENABLED | ((idx == 0)
|
|
|
|
? KEY_INFO_WPA_UNICAST
|
|
|
|
: KEY_INFO_WPA_MCAST);
|
|
|
|
key_type = (params->cipher == WLAN_CIPHER_SUITE_TKIP)
|
|
|
|
? KEY_TYPE_ID_TKIP
|
|
|
|
: KEY_TYPE_ID_AES;
|
|
|
|
lbs_set_key_material(priv,
|
|
|
|
key_type,
|
|
|
|
key_info,
|
|
|
|
params->key, params->key_len);
|
|
|
|
break;
|
|
|
|
default:
|
2011-05-03 07:49:15 +08:00
|
|
|
wiphy_err(wiphy, "unhandled cipher 0x%x\n", params->cipher);
|
2010-06-15 00:31:26 +08:00
|
|
|
ret = -ENOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int lbs_cfg_del_key(struct wiphy *wiphy, struct net_device *netdev,
|
2010-10-06 01:39:30 +08:00
|
|
|
u8 key_index, bool pairwise, const u8 *mac_addr)
|
2010-06-15 00:31:26 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
lbs_deb_assoc("del_key: key_idx %d, mac_addr %pM\n",
|
|
|
|
key_index, mac_addr);
|
|
|
|
|
|
|
|
#ifdef TODO
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
|
|
|
/*
|
|
|
|
* I think can keep this a NO-OP, because:
|
|
|
|
|
|
|
|
* - we clear all keys whenever we do lbs_cfg_connect() anyway
|
|
|
|
* - neither "iw" nor "wpa_supplicant" won't call this during
|
|
|
|
* an ongoing connection
|
|
|
|
* - TODO: but I have to check if this is still true when
|
|
|
|
* I set the AP to periodic re-keying
|
|
|
|
* - we've not kzallec() something when we've added a key at
|
|
|
|
* lbs_cfg_connect() or lbs_cfg_add_key().
|
|
|
|
*
|
|
|
|
* This causes lbs_cfg_del_key() only called at disconnect time,
|
|
|
|
* where we'd just waste time deleting a key that is not going
|
|
|
|
* to be used anyway.
|
|
|
|
*/
|
|
|
|
if (key_index < 3 && priv->wep_key_len[key_index]) {
|
|
|
|
priv->wep_key_len[key_index] = 0;
|
|
|
|
lbs_set_wep_keys(priv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
2010-06-15 00:31:26 +08:00
|
|
|
* Get station
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int lbs_cfg_get_station(struct wiphy *wiphy, struct net_device *dev,
|
|
|
|
u8 *mac, struct station_info *sinfo)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
|
|
|
s8 signal, noise;
|
|
|
|
int ret;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
sinfo->filled |= STATION_INFO_TX_BYTES |
|
|
|
|
STATION_INFO_TX_PACKETS |
|
|
|
|
STATION_INFO_RX_BYTES |
|
|
|
|
STATION_INFO_RX_PACKETS;
|
|
|
|
sinfo->tx_bytes = priv->dev->stats.tx_bytes;
|
|
|
|
sinfo->tx_packets = priv->dev->stats.tx_packets;
|
|
|
|
sinfo->rx_bytes = priv->dev->stats.rx_bytes;
|
|
|
|
sinfo->rx_packets = priv->dev->stats.rx_packets;
|
|
|
|
|
|
|
|
/* Get current RSSI */
|
2010-07-28 03:55:21 +08:00
|
|
|
ret = lbs_get_rssi(priv, &signal, &noise);
|
2010-06-15 00:31:26 +08:00
|
|
|
if (ret == 0) {
|
|
|
|
sinfo->signal = signal;
|
|
|
|
sinfo->filled |= STATION_INFO_SIGNAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert priv->cur_rate from hw_value to NL80211 value */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
|
|
|
|
if (priv->cur_rate == lbs_rates[i].hw_value) {
|
|
|
|
sinfo->txrate.legacy = lbs_rates[i].bitrate;
|
|
|
|
sinfo->filled |= STATION_INFO_TX_BITRATE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
2010-06-15 00:31:26 +08:00
|
|
|
* Change interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int lbs_change_intf(struct wiphy *wiphy, struct net_device *dev,
|
|
|
|
enum nl80211_iftype type, u32 *flags,
|
|
|
|
struct vif_params *params)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
|
|
|
int ret = 0;
|
|
|
|
|
2011-07-22 03:43:17 +08:00
|
|
|
if (dev == priv->mesh_dev)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
switch (type) {
|
|
|
|
case NL80211_IFTYPE_MONITOR:
|
|
|
|
case NL80211_IFTYPE_STATION:
|
|
|
|
case NL80211_IFTYPE_ADHOC:
|
|
|
|
break;
|
|
|
|
default:
|
2011-10-14 19:05:26 +08:00
|
|
|
return -EOPNOTSUPP;
|
2010-06-15 00:31:26 +08:00
|
|
|
}
|
|
|
|
|
2011-10-14 19:05:26 +08:00
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
if (priv->iface_running)
|
|
|
|
ret = lbs_set_iface_type(priv, type);
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
if (!ret)
|
|
|
|
priv->wdev->iftype = type;
|
|
|
|
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
2010-06-15 00:31:26 +08:00
|
|
|
* IBSS (Ad-Hoc)
|
|
|
|
*/
|
|
|
|
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
|
|
|
* The firmware needs the following bits masked out of the beacon-derived
|
2010-06-15 00:31:26 +08:00
|
|
|
* capability field when associating/joining to a BSS:
|
|
|
|
* 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
|
|
|
|
*/
|
|
|
|
#define CAPINFO_MASK (~(0xda00))
|
|
|
|
|
|
|
|
|
|
|
|
static void lbs_join_post(struct lbs_private *priv,
|
|
|
|
struct cfg80211_ibss_params *params,
|
|
|
|
u8 *bssid, u16 capability)
|
|
|
|
{
|
|
|
|
u8 fake_ie[2 + IEEE80211_MAX_SSID_LEN + /* ssid */
|
|
|
|
2 + 4 + /* basic rates */
|
|
|
|
2 + 1 + /* DS parameter */
|
|
|
|
2 + 2 + /* atim */
|
|
|
|
2 + 8]; /* extended rates */
|
|
|
|
u8 *fake = fake_ie;
|
2011-11-12 02:49:45 +08:00
|
|
|
struct cfg80211_bss *bss;
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For cfg80211_inform_bss, we'll need a fake IE, as we can't get
|
|
|
|
* the real IE from the firmware. So we fabricate a fake IE based on
|
|
|
|
* what the firmware actually sends (sniffed with wireshark).
|
|
|
|
*/
|
|
|
|
/* Fake SSID IE */
|
|
|
|
*fake++ = WLAN_EID_SSID;
|
|
|
|
*fake++ = params->ssid_len;
|
|
|
|
memcpy(fake, params->ssid, params->ssid_len);
|
|
|
|
fake += params->ssid_len;
|
|
|
|
/* Fake supported basic rates IE */
|
|
|
|
*fake++ = WLAN_EID_SUPP_RATES;
|
|
|
|
*fake++ = 4;
|
|
|
|
*fake++ = 0x82;
|
|
|
|
*fake++ = 0x84;
|
|
|
|
*fake++ = 0x8b;
|
|
|
|
*fake++ = 0x96;
|
|
|
|
/* Fake DS channel IE */
|
|
|
|
*fake++ = WLAN_EID_DS_PARAMS;
|
|
|
|
*fake++ = 1;
|
2012-11-09 04:25:48 +08:00
|
|
|
*fake++ = params->chandef.chan->hw_value;
|
2010-06-15 00:31:26 +08:00
|
|
|
/* Fake IBSS params IE */
|
|
|
|
*fake++ = WLAN_EID_IBSS_PARAMS;
|
|
|
|
*fake++ = 2;
|
|
|
|
*fake++ = 0; /* ATIM=0 */
|
|
|
|
*fake++ = 0;
|
|
|
|
/* Fake extended rates IE, TODO: don't add this for 802.11b only,
|
|
|
|
* but I don't know how this could be checked */
|
|
|
|
*fake++ = WLAN_EID_EXT_SUPP_RATES;
|
|
|
|
*fake++ = 8;
|
|
|
|
*fake++ = 0x0c;
|
|
|
|
*fake++ = 0x12;
|
|
|
|
*fake++ = 0x18;
|
|
|
|
*fake++ = 0x24;
|
|
|
|
*fake++ = 0x30;
|
|
|
|
*fake++ = 0x48;
|
|
|
|
*fake++ = 0x60;
|
|
|
|
*fake++ = 0x6c;
|
|
|
|
lbs_deb_hex(LBS_DEB_CFG80211, "IE", fake_ie, fake - fake_ie);
|
|
|
|
|
2011-11-12 02:49:45 +08:00
|
|
|
bss = cfg80211_inform_bss(priv->wdev->wiphy,
|
2012-11-09 04:25:48 +08:00
|
|
|
params->chandef.chan,
|
2011-11-12 02:49:45 +08:00
|
|
|
bssid,
|
|
|
|
0,
|
|
|
|
capability,
|
|
|
|
params->beacon_interval,
|
|
|
|
fake_ie, fake - fake_ie,
|
|
|
|
0, GFP_KERNEL);
|
2013-02-01 08:49:58 +08:00
|
|
|
cfg80211_put_bss(priv->wdev->wiphy, bss);
|
2010-06-05 14:20:37 +08:00
|
|
|
|
|
|
|
memcpy(priv->wdev->ssid, params->ssid, params->ssid_len);
|
|
|
|
priv->wdev->ssid_len = params->ssid_len;
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
cfg80211_ibss_joined(priv->dev, bssid, GFP_KERNEL);
|
|
|
|
|
|
|
|
/* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
|
|
|
|
priv->connect_status = LBS_CONNECTED;
|
|
|
|
netif_carrier_on(priv->dev);
|
|
|
|
if (!priv->tx_pending_len)
|
|
|
|
netif_wake_queue(priv->dev);
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CFG80211);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lbs_ibss_join_existing(struct lbs_private *priv,
|
|
|
|
struct cfg80211_ibss_params *params,
|
|
|
|
struct cfg80211_bss *bss)
|
|
|
|
{
|
2012-11-29 08:25:20 +08:00
|
|
|
const u8 *rates_eid;
|
2010-06-15 00:31:26 +08:00
|
|
|
struct cmd_ds_802_11_ad_hoc_join cmd;
|
|
|
|
u8 preamble = RADIO_PREAMBLE_SHORT;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
/* TODO: set preamble based on scan result */
|
|
|
|
ret = lbs_set_radio(priv, preamble, 1);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Example CMD_802_11_AD_HOC_JOIN command:
|
|
|
|
*
|
|
|
|
* command 2c 00 CMD_802_11_AD_HOC_JOIN
|
|
|
|
* size 65 00
|
|
|
|
* sequence xx xx
|
|
|
|
* result 00 00
|
|
|
|
* bssid 02 27 27 97 2f 96
|
|
|
|
* ssid 49 42 53 53 00 00 00 00
|
|
|
|
* 00 00 00 00 00 00 00 00
|
|
|
|
* 00 00 00 00 00 00 00 00
|
|
|
|
* 00 00 00 00 00 00 00 00
|
|
|
|
* type 02 CMD_BSS_TYPE_IBSS
|
|
|
|
* beacon period 64 00
|
|
|
|
* dtim period 00
|
|
|
|
* timestamp 00 00 00 00 00 00 00 00
|
|
|
|
* localtime 00 00 00 00 00 00 00 00
|
|
|
|
* IE DS 03
|
|
|
|
* IE DS len 01
|
|
|
|
* IE DS channel 01
|
|
|
|
* reserveed 00 00 00 00
|
|
|
|
* IE IBSS 06
|
|
|
|
* IE IBSS len 02
|
|
|
|
* IE IBSS atim 00 00
|
|
|
|
* reserved 00 00 00 00
|
|
|
|
* capability 02 00
|
|
|
|
* rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
|
|
|
|
* fail timeout ff 00
|
|
|
|
* probe delay 00 00
|
|
|
|
*/
|
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
|
|
|
cmd.hdr.size = cpu_to_le16(sizeof(cmd));
|
|
|
|
|
|
|
|
memcpy(cmd.bss.bssid, bss->bssid, ETH_ALEN);
|
|
|
|
memcpy(cmd.bss.ssid, params->ssid, params->ssid_len);
|
|
|
|
cmd.bss.type = CMD_BSS_TYPE_IBSS;
|
|
|
|
cmd.bss.beaconperiod = cpu_to_le16(params->beacon_interval);
|
|
|
|
cmd.bss.ds.header.id = WLAN_EID_DS_PARAMS;
|
|
|
|
cmd.bss.ds.header.len = 1;
|
2012-11-09 04:25:48 +08:00
|
|
|
cmd.bss.ds.channel = params->chandef.chan->hw_value;
|
2010-06-15 00:31:26 +08:00
|
|
|
cmd.bss.ibss.header.id = WLAN_EID_IBSS_PARAMS;
|
|
|
|
cmd.bss.ibss.header.len = 2;
|
|
|
|
cmd.bss.ibss.atimwindow = 0;
|
|
|
|
cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
|
|
|
|
|
|
|
|
/* set rates to the intersection of our rates and the rates in the
|
|
|
|
bss */
|
2012-11-29 08:25:20 +08:00
|
|
|
rcu_read_lock();
|
|
|
|
rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
|
2010-06-15 00:31:26 +08:00
|
|
|
if (!rates_eid) {
|
|
|
|
lbs_add_rates(cmd.bss.rates);
|
|
|
|
} else {
|
|
|
|
int hw, i;
|
|
|
|
u8 rates_max = rates_eid[1];
|
|
|
|
u8 *rates = cmd.bss.rates;
|
|
|
|
for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
|
|
|
|
u8 hw_rate = lbs_rates[hw].bitrate / 5;
|
|
|
|
for (i = 0; i < rates_max; i++) {
|
|
|
|
if (hw_rate == (rates_eid[i+2] & 0x7f)) {
|
|
|
|
u8 rate = rates_eid[i+2];
|
|
|
|
if (rate == 0x02 || rate == 0x04 ||
|
|
|
|
rate == 0x0b || rate == 0x16)
|
|
|
|
rate |= 0x80;
|
|
|
|
*rates++ = rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-29 08:25:20 +08:00
|
|
|
rcu_read_unlock();
|
2010-06-15 00:31:26 +08:00
|
|
|
|
|
|
|
/* Only v8 and below support setting this */
|
|
|
|
if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
|
|
|
|
cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
|
|
|
|
cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
|
|
|
|
}
|
|
|
|
ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a sample response to CMD_802_11_AD_HOC_JOIN:
|
|
|
|
*
|
|
|
|
* response 2c 80
|
|
|
|
* size 09 00
|
|
|
|
* sequence xx xx
|
|
|
|
* result 00 00
|
|
|
|
* reserved 00
|
|
|
|
*/
|
|
|
|
lbs_join_post(priv, params, bss->bssid, bss->capability);
|
|
|
|
|
|
|
|
out:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int lbs_ibss_start_new(struct lbs_private *priv,
|
|
|
|
struct cfg80211_ibss_params *params)
|
|
|
|
{
|
|
|
|
struct cmd_ds_802_11_ad_hoc_start cmd;
|
|
|
|
struct cmd_ds_802_11_ad_hoc_result *resp =
|
|
|
|
(struct cmd_ds_802_11_ad_hoc_result *) &cmd;
|
|
|
|
u8 preamble = RADIO_PREAMBLE_SHORT;
|
|
|
|
int ret = 0;
|
|
|
|
u16 capability;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
ret = lbs_set_radio(priv, preamble, 1);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Example CMD_802_11_AD_HOC_START command:
|
|
|
|
*
|
|
|
|
* command 2b 00 CMD_802_11_AD_HOC_START
|
|
|
|
* size b1 00
|
|
|
|
* sequence xx xx
|
|
|
|
* result 00 00
|
|
|
|
* ssid 54 45 53 54 00 00 00 00
|
|
|
|
* 00 00 00 00 00 00 00 00
|
|
|
|
* 00 00 00 00 00 00 00 00
|
|
|
|
* 00 00 00 00 00 00 00 00
|
|
|
|
* bss type 02
|
|
|
|
* beacon period 64 00
|
|
|
|
* dtim period 00
|
|
|
|
* IE IBSS 06
|
|
|
|
* IE IBSS len 02
|
|
|
|
* IE IBSS atim 00 00
|
|
|
|
* reserved 00 00 00 00
|
|
|
|
* IE DS 03
|
|
|
|
* IE DS len 01
|
|
|
|
* IE DS channel 01
|
|
|
|
* reserved 00 00 00 00
|
|
|
|
* probe delay 00 00
|
|
|
|
* capability 02 00
|
|
|
|
* rates 82 84 8b 96 (basic rates with have bit 7 set)
|
|
|
|
* 0c 12 18 24 30 48 60 6c
|
|
|
|
* padding 100 bytes
|
|
|
|
*/
|
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
|
|
|
cmd.hdr.size = cpu_to_le16(sizeof(cmd));
|
|
|
|
memcpy(cmd.ssid, params->ssid, params->ssid_len);
|
|
|
|
cmd.bsstype = CMD_BSS_TYPE_IBSS;
|
|
|
|
cmd.beaconperiod = cpu_to_le16(params->beacon_interval);
|
|
|
|
cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS;
|
|
|
|
cmd.ibss.header.len = 2;
|
|
|
|
cmd.ibss.atimwindow = 0;
|
|
|
|
cmd.ds.header.id = WLAN_EID_DS_PARAMS;
|
|
|
|
cmd.ds.header.len = 1;
|
2012-11-09 04:25:48 +08:00
|
|
|
cmd.ds.channel = params->chandef.chan->hw_value;
|
2010-06-15 00:31:26 +08:00
|
|
|
/* Only v8 and below support setting probe delay */
|
|
|
|
if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8)
|
|
|
|
cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
|
|
|
|
/* TODO: mix in WLAN_CAPABILITY_PRIVACY */
|
|
|
|
capability = WLAN_CAPABILITY_IBSS;
|
|
|
|
cmd.capability = cpu_to_le16(capability);
|
|
|
|
lbs_add_rates(cmd.rates);
|
|
|
|
|
|
|
|
|
|
|
|
ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a sample response to CMD_802_11_AD_HOC_JOIN:
|
|
|
|
*
|
|
|
|
* response 2b 80
|
|
|
|
* size 14 00
|
|
|
|
* sequence xx xx
|
|
|
|
* result 00 00
|
|
|
|
* reserved 00
|
|
|
|
* bssid 02 2b 7b 0f 86 0e
|
|
|
|
*/
|
|
|
|
lbs_join_post(priv, params, resp->bssid, capability);
|
|
|
|
|
|
|
|
out:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int lbs_join_ibss(struct wiphy *wiphy, struct net_device *dev,
|
|
|
|
struct cfg80211_ibss_params *params)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
|
|
|
int ret = 0;
|
|
|
|
struct cfg80211_bss *bss;
|
|
|
|
DECLARE_SSID_BUF(ssid_buf);
|
|
|
|
|
2011-07-22 03:43:17 +08:00
|
|
|
if (dev == priv->mesh_dev)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
2012-11-09 04:25:48 +08:00
|
|
|
if (!params->chandef.chan) {
|
2010-06-15 00:31:26 +08:00
|
|
|
ret = -ENOTSUPP;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-11-09 04:25:48 +08:00
|
|
|
ret = lbs_set_channel(priv, params->chandef.chan->hw_value);
|
2010-06-15 00:31:26 +08:00
|
|
|
if (ret)
|
2009-10-06 22:31:54 +08:00
|
|
|
goto out;
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
/* Search if someone is beaconing. This assumes that the
|
|
|
|
* bss list is populated already */
|
2012-11-09 04:25:48 +08:00
|
|
|
bss = cfg80211_get_bss(wiphy, params->chandef.chan, params->bssid,
|
2010-06-15 00:31:26 +08:00
|
|
|
params->ssid, params->ssid_len,
|
|
|
|
WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
|
|
|
|
|
|
|
|
if (bss) {
|
|
|
|
ret = lbs_ibss_join_existing(priv, params, bss);
|
2013-02-01 08:49:58 +08:00
|
|
|
cfg80211_put_bss(wiphy, bss);
|
2010-06-15 00:31:26 +08:00
|
|
|
} else
|
|
|
|
ret = lbs_ibss_start_new(priv, params);
|
|
|
|
|
2009-10-06 22:31:54 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
static int lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
|
|
|
struct cmd_ds_802_11_ad_hoc_stop cmd;
|
|
|
|
int ret = 0;
|
|
|
|
|
2011-07-22 03:43:17 +08:00
|
|
|
if (dev == priv->mesh_dev)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
|
|
|
cmd.hdr.size = cpu_to_le16(sizeof(cmd));
|
|
|
|
ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd);
|
|
|
|
|
|
|
|
/* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
|
|
|
|
lbs_mac_event_disconnected(priv);
|
|
|
|
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-06 22:31:54 +08:00
|
|
|
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
|
2011-04-27 06:25:29 +08:00
|
|
|
/*
|
2010-06-15 00:31:26 +08:00
|
|
|
* Initialization
|
|
|
|
*/
|
|
|
|
|
2009-10-06 22:31:54 +08:00
|
|
|
static struct cfg80211_ops lbs_cfg80211_ops = {
|
2012-06-06 14:18:22 +08:00
|
|
|
.set_monitor_channel = lbs_cfg_set_monitor_channel,
|
|
|
|
.libertas_set_mesh_channel = lbs_cfg_set_mesh_channel,
|
2010-06-15 00:31:26 +08:00
|
|
|
.scan = lbs_cfg_scan,
|
|
|
|
.connect = lbs_cfg_connect,
|
|
|
|
.disconnect = lbs_cfg_disconnect,
|
|
|
|
.add_key = lbs_cfg_add_key,
|
|
|
|
.del_key = lbs_cfg_del_key,
|
|
|
|
.set_default_key = lbs_cfg_set_default_key,
|
|
|
|
.get_station = lbs_cfg_get_station,
|
|
|
|
.change_virtual_intf = lbs_change_intf,
|
|
|
|
.join_ibss = lbs_join_ibss,
|
|
|
|
.leave_ibss = lbs_leave_ibss,
|
2009-10-06 22:31:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this time lbs_private *priv doesn't even exist, so we just allocate
|
|
|
|
* memory and don't initialize the wiphy further. This is postponed until we
|
|
|
|
* can talk to the firmware and happens at registration time in
|
|
|
|
* lbs_cfg_wiphy_register().
|
|
|
|
*/
|
|
|
|
struct wireless_dev *lbs_cfg_alloc(struct device *dev)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct wireless_dev *wdev;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
|
2013-02-04 01:28:14 +08:00
|
|
|
if (!wdev)
|
2009-10-06 22:31:54 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private));
|
|
|
|
if (!wdev->wiphy) {
|
|
|
|
dev_err(dev, "cannot allocate wiphy\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_wiphy_new;
|
|
|
|
}
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CFG80211);
|
|
|
|
return wdev;
|
|
|
|
|
|
|
|
err_wiphy_new:
|
|
|
|
kfree(wdev);
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
static void lbs_cfg_set_regulatory_hint(struct lbs_private *priv)
|
|
|
|
{
|
|
|
|
struct region_code_mapping {
|
|
|
|
const char *cn;
|
|
|
|
int code;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Section 5.17.2 */
|
2010-11-21 10:38:58 +08:00
|
|
|
static const struct region_code_mapping regmap[] = {
|
2010-06-15 00:31:26 +08:00
|
|
|
{"US ", 0x10}, /* US FCC */
|
|
|
|
{"CA ", 0x20}, /* Canada */
|
|
|
|
{"EU ", 0x30}, /* ETSI */
|
|
|
|
{"ES ", 0x31}, /* Spain */
|
|
|
|
{"FR ", 0x32}, /* France */
|
|
|
|
{"JP ", 0x40}, /* Japan */
|
|
|
|
};
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(regmap); i++)
|
|
|
|
if (regmap[i].code == priv->regioncode) {
|
|
|
|
regulatory_hint(priv->wdev->wiphy, regmap[i].cn);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CFG80211);
|
|
|
|
}
|
|
|
|
|
2013-01-12 02:39:36 +08:00
|
|
|
static void lbs_reg_notifier(struct wiphy *wiphy,
|
|
|
|
struct regulatory_request *request)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv = wiphy_priv(wiphy);
|
|
|
|
|
|
|
|
lbs_deb_enter_args(LBS_DEB_CFG80211, "cfg80211 regulatory domain "
|
|
|
|
"callback for domain %c%c\n", request->alpha2[0],
|
|
|
|
request->alpha2[1]);
|
|
|
|
|
|
|
|
memcpy(priv->country_code, request->alpha2, sizeof(request->alpha2));
|
|
|
|
if (lbs_iface_active(priv))
|
|
|
|
lbs_set_11d_domain_info(priv);
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CFG80211);
|
|
|
|
}
|
2010-06-15 00:31:26 +08:00
|
|
|
|
2009-10-06 22:31:54 +08:00
|
|
|
/*
|
|
|
|
* This function get's called after lbs_setup_firmware() determined the
|
|
|
|
* firmware capabities. So we can setup the wiphy according to our
|
|
|
|
* hardware/firmware.
|
|
|
|
*/
|
|
|
|
int lbs_cfg_register(struct lbs_private *priv)
|
|
|
|
{
|
|
|
|
struct wireless_dev *wdev = priv->wdev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
wdev->wiphy->max_scan_ssids = 1;
|
|
|
|
wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
wdev->wiphy->interface_modes =
|
|
|
|
BIT(NL80211_IFTYPE_STATION) |
|
|
|
|
BIT(NL80211_IFTYPE_ADHOC);
|
|
|
|
if (lbs_rtap_supported(priv))
|
|
|
|
wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
|
2011-07-22 03:43:17 +08:00
|
|
|
if (lbs_mesh_activated(priv))
|
|
|
|
wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MESH_POINT);
|
2009-10-06 22:31:54 +08:00
|
|
|
|
|
|
|
wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &lbs_band_2ghz;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
|
|
|
|
* never seen a firmware without WPA
|
|
|
|
*/
|
|
|
|
wdev->wiphy->cipher_suites = cipher_suites;
|
|
|
|
wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
|
2010-06-05 14:20:42 +08:00
|
|
|
wdev->wiphy->reg_notifier = lbs_reg_notifier;
|
2009-10-06 22:31:54 +08:00
|
|
|
|
|
|
|
ret = wiphy_register(wdev->wiphy);
|
|
|
|
if (ret < 0)
|
2011-05-03 07:49:14 +08:00
|
|
|
pr_err("cannot register wiphy device\n");
|
2009-10-06 22:31:54 +08:00
|
|
|
|
2010-03-29 23:14:18 +08:00
|
|
|
priv->wiphy_registered = true;
|
|
|
|
|
2009-10-06 22:31:54 +08:00
|
|
|
ret = register_netdev(priv->dev);
|
|
|
|
if (ret)
|
2011-05-03 07:49:14 +08:00
|
|
|
pr_err("cannot register network device\n");
|
2009-10-06 22:31:54 +08:00
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
|
|
|
|
|
|
|
|
lbs_cfg_set_regulatory_hint(priv);
|
|
|
|
|
2009-10-06 22:31:54 +08:00
|
|
|
lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-06-15 00:31:26 +08:00
|
|
|
void lbs_scan_deinit(struct lbs_private *priv)
|
|
|
|
{
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
cancel_delayed_work_sync(&priv->scan_work);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-06 22:31:54 +08:00
|
|
|
void lbs_cfg_free(struct lbs_private *priv)
|
|
|
|
{
|
|
|
|
struct wireless_dev *wdev = priv->wdev;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CFG80211);
|
|
|
|
|
|
|
|
if (!wdev)
|
|
|
|
return;
|
|
|
|
|
2010-03-29 23:14:18 +08:00
|
|
|
if (priv->wiphy_registered)
|
2009-10-06 22:31:54 +08:00
|
|
|
wiphy_unregister(wdev->wiphy);
|
2010-03-29 23:14:18 +08:00
|
|
|
|
|
|
|
if (wdev->wiphy)
|
2009-10-06 22:31:54 +08:00
|
|
|
wiphy_free(wdev->wiphy);
|
2010-03-29 23:14:18 +08:00
|
|
|
|
2009-10-06 22:31:54 +08:00
|
|
|
kfree(wdev);
|
|
|
|
}
|