2008-12-05 05:01:41 +01:00
|
|
|
/******************************************************************************
|
|
|
|
|
|
|
|
Copyright(c) 2004 Intel Corporation. All rights reserved.
|
|
|
|
|
|
|
|
Portions of this file are based on the WEP enablement code provided by the
|
|
|
|
Host AP project hostap-drivers v0.1.3
|
|
|
|
Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
|
|
|
|
<jkmaline@cc.hut.fi>
|
|
|
|
Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of version 2 of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc., 59
|
|
|
|
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
The full GNU General Public License is included in this distribution in the
|
|
|
|
file called LICENSE.
|
|
|
|
|
|
|
|
Contact Information:
|
|
|
|
James P. Ketrenos <ipw2100-admin@linux.intel.com>
|
|
|
|
Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
#include <linux/wireless.h>
|
|
|
|
#include <linux/kmod.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 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2008-12-05 05:01:41 +01:00
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include "ieee80211.h"
|
|
|
|
static const char *ieee80211_modes[] = {
|
|
|
|
"?", "a", "b", "ab", "g", "ag", "bg", "abg"
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_CUSTOM_LEN 64
|
|
|
|
static inline char *rtl818x_translate_scan(struct ieee80211_device *ieee,
|
2012-11-29 14:34:39 +01:00
|
|
|
char *start, char *stop,
|
|
|
|
struct ieee80211_network *network,
|
|
|
|
struct iw_request_info *info)
|
2008-12-05 05:01:41 +01:00
|
|
|
{
|
|
|
|
char custom[MAX_CUSTOM_LEN];
|
|
|
|
char *p;
|
|
|
|
struct iw_event iwe;
|
|
|
|
int i, j;
|
|
|
|
u8 max_rate, rate;
|
|
|
|
|
|
|
|
/* First entry *MUST* be the AP MAC address */
|
|
|
|
iwe.cmd = SIOCGIWAP;
|
|
|
|
iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
|
|
|
|
memcpy(iwe.u.ap_addr.sa_data, network->bssid, ETH_ALEN);
|
|
|
|
start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_ADDR_LEN);
|
|
|
|
|
|
|
|
/* Remaining entries will be displayed in the order we provide them */
|
|
|
|
|
|
|
|
/* Add the ESSID */
|
|
|
|
iwe.cmd = SIOCGIWESSID;
|
|
|
|
iwe.u.data.flags = 1;
|
|
|
|
//YJ,modified,080903,for hidden ap
|
|
|
|
//if (network->flags & NETWORK_EMPTY_ESSID) {
|
|
|
|
if (network->ssid_len == 0) {
|
|
|
|
//YJ,modified,080903,end
|
|
|
|
iwe.u.data.length = sizeof("<hidden>");
|
|
|
|
start = iwe_stream_add_point(info, start, stop, &iwe, "<hidden>");
|
|
|
|
} else {
|
|
|
|
iwe.u.data.length = min(network->ssid_len, (u8)32);
|
|
|
|
start = iwe_stream_add_point(info, start, stop, &iwe, network->ssid);
|
|
|
|
}
|
|
|
|
//printk("ESSID: %s\n",network->ssid);
|
|
|
|
/* Add the protocol name */
|
|
|
|
iwe.cmd = SIOCGIWNAME;
|
|
|
|
snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11%s", ieee80211_modes[network->mode]);
|
|
|
|
start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN);
|
|
|
|
|
2012-11-29 14:34:39 +01:00
|
|
|
/* Add mode */
|
|
|
|
iwe.cmd = SIOCGIWMODE;
|
|
|
|
if (network->capability &
|
2008-12-05 05:01:41 +01:00
|
|
|
(WLAN_CAPABILITY_BSS | WLAN_CAPABILITY_IBSS)) {
|
|
|
|
if (network->capability & WLAN_CAPABILITY_BSS)
|
|
|
|
iwe.u.mode = IW_MODE_MASTER;
|
|
|
|
else
|
|
|
|
iwe.u.mode = IW_MODE_ADHOC;
|
|
|
|
|
|
|
|
start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN);
|
|
|
|
}
|
|
|
|
|
2012-11-29 14:34:39 +01:00
|
|
|
/* Add frequency/channel */
|
2008-12-05 05:01:41 +01:00
|
|
|
iwe.cmd = SIOCGIWFREQ;
|
|
|
|
/* iwe.u.freq.m = ieee80211_frequency(network->channel, network->mode);
|
|
|
|
iwe.u.freq.e = 3; */
|
|
|
|
iwe.u.freq.m = network->channel;
|
|
|
|
iwe.u.freq.e = 0;
|
|
|
|
iwe.u.freq.i = 0;
|
|
|
|
start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_FREQ_LEN);
|
|
|
|
|
|
|
|
/* Add encryption capability */
|
|
|
|
iwe.cmd = SIOCGIWENCODE;
|
|
|
|
if (network->capability & WLAN_CAPABILITY_PRIVACY)
|
|
|
|
iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
|
|
|
|
else
|
|
|
|
iwe.u.data.flags = IW_ENCODE_DISABLED;
|
|
|
|
iwe.u.data.length = 0;
|
|
|
|
start = iwe_stream_add_point(info, start, stop, &iwe, network->ssid);
|
|
|
|
|
|
|
|
/* Add basic and extended rates */
|
|
|
|
max_rate = 0;
|
|
|
|
p = custom;
|
|
|
|
p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): ");
|
|
|
|
for (i = 0, j = 0; i < network->rates_len; ) {
|
|
|
|
if (j < network->rates_ex_len &&
|
|
|
|
((network->rates_ex[j] & 0x7F) <
|
|
|
|
(network->rates[i] & 0x7F)))
|
|
|
|
rate = network->rates_ex[j++] & 0x7F;
|
|
|
|
else
|
|
|
|
rate = network->rates[i++] & 0x7F;
|
|
|
|
if (rate > max_rate)
|
|
|
|
max_rate = rate;
|
|
|
|
p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
|
|
|
|
"%d%s ", rate >> 1, (rate & 1) ? ".5" : "");
|
|
|
|
}
|
|
|
|
for (; j < network->rates_ex_len; j++) {
|
|
|
|
rate = network->rates_ex[j] & 0x7F;
|
|
|
|
p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
|
|
|
|
"%d%s ", rate >> 1, (rate & 1) ? ".5" : "");
|
|
|
|
if (rate > max_rate)
|
|
|
|
max_rate = rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
iwe.cmd = SIOCGIWRATE;
|
|
|
|
iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
|
|
|
|
iwe.u.bitrate.value = max_rate * 500000;
|
|
|
|
start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_PARAM_LEN);
|
|
|
|
|
|
|
|
iwe.cmd = IWEVCUSTOM;
|
|
|
|
iwe.u.data.length = p - custom;
|
|
|
|
if (iwe.u.data.length)
|
|
|
|
start = iwe_stream_add_point(info, start, stop, &iwe, custom);
|
|
|
|
|
|
|
|
/* Add quality statistics */
|
|
|
|
/* TODO: Fix these values... */
|
|
|
|
if (network->stats.signal == 0 || network->stats.rssi == 0)
|
|
|
|
printk("========>signal:%d, rssi:%d\n", network->stats.signal, network->stats.rssi);
|
|
|
|
iwe.cmd = IWEVQUAL;
|
|
|
|
// printk("SIGNAL: %d,RSSI: %d,NOISE: %d\n",network->stats.signal,network->stats.rssi,network->stats.noise);
|
|
|
|
iwe.u.qual.qual = network->stats.signalstrength;
|
|
|
|
iwe.u.qual.level = network->stats.signal;
|
|
|
|
iwe.u.qual.noise = network->stats.noise;
|
|
|
|
iwe.u.qual.updated = network->stats.mask & IEEE80211_STATMASK_WEMASK;
|
|
|
|
if (!(network->stats.mask & IEEE80211_STATMASK_RSSI))
|
|
|
|
iwe.u.qual.updated |= IW_QUAL_LEVEL_INVALID;
|
|
|
|
if (!(network->stats.mask & IEEE80211_STATMASK_NOISE))
|
|
|
|
iwe.u.qual.updated |= IW_QUAL_NOISE_INVALID;
|
|
|
|
if (!(network->stats.mask & IEEE80211_STATMASK_SIGNAL))
|
|
|
|
iwe.u.qual.updated |= IW_QUAL_QUAL_INVALID;
|
|
|
|
iwe.u.qual.updated = 7;
|
|
|
|
start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_QUAL_LEN);
|
|
|
|
|
|
|
|
iwe.cmd = IWEVCUSTOM;
|
|
|
|
p = custom;
|
|
|
|
|
|
|
|
iwe.u.data.length = p - custom;
|
|
|
|
if (iwe.u.data.length)
|
|
|
|
start = iwe_stream_add_point(info, start, stop, &iwe, custom);
|
|
|
|
|
2012-11-29 14:34:39 +01:00
|
|
|
memset(&iwe, 0, sizeof(iwe));
|
|
|
|
if (network->wpa_ie_len) {
|
2008-12-05 05:01:41 +01:00
|
|
|
// printk("wpa_ie_len:%d\n", network->wpa_ie_len);
|
2012-11-29 14:34:39 +01:00
|
|
|
char buf[MAX_WPA_IE_LEN];
|
|
|
|
memcpy(buf, network->wpa_ie, network->wpa_ie_len);
|
|
|
|
iwe.cmd = IWEVGENIE;
|
|
|
|
iwe.u.data.length = network->wpa_ie_len;
|
|
|
|
start = iwe_stream_add_point(info, start, stop, &iwe, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&iwe, 0, sizeof(iwe));
|
|
|
|
if (network->rsn_ie_len) {
|
2008-12-05 05:01:41 +01:00
|
|
|
// printk("=====>rsn_ie_len:\n", network->rsn_ie_len);
|
2012-11-29 14:34:39 +01:00
|
|
|
char buf[MAX_WPA_IE_LEN];
|
|
|
|
memcpy(buf, network->rsn_ie, network->rsn_ie_len);
|
|
|
|
iwe.cmd = IWEVGENIE;
|
|
|
|
iwe.u.data.length = network->rsn_ie_len;
|
2008-12-05 05:01:41 +01:00
|
|
|
start = iwe_stream_add_point(info, start, stop, &iwe, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add EXTRA: Age to display seconds since last beacon/probe response
|
|
|
|
* for given network. */
|
|
|
|
iwe.cmd = IWEVCUSTOM;
|
|
|
|
p = custom;
|
|
|
|
p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
|
|
|
|
" Last beacon: %lums ago", (jiffies - network->last_scanned) / (HZ / 100));
|
|
|
|
iwe.u.data.length = p - custom;
|
|
|
|
if (iwe.u.data.length)
|
|
|
|
start = iwe_stream_add_point(info, start, stop, &iwe, custom);
|
|
|
|
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
|
|
|
|
struct iw_request_info *info,
|
|
|
|
union iwreq_data *wrqu, char *extra)
|
|
|
|
{
|
|
|
|
struct ieee80211_network *network;
|
|
|
|
unsigned long flags;
|
|
|
|
int err = 0;
|
|
|
|
char *ev = extra;
|
|
|
|
char *stop = ev + wrqu->data.length;//IW_SCAN_MAX_DATA;
|
|
|
|
//char *stop = ev + IW_SCAN_MAX_DATA;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
IEEE80211_DEBUG_WX("Getting scan\n");
|
|
|
|
down(&ieee->wx_sem);
|
|
|
|
spin_lock_irqsave(&ieee->lock, flags);
|
|
|
|
|
2012-11-29 14:35:37 +01:00
|
|
|
if (!ieee->bHwRadioOff) {
|
2008-12-05 05:01:41 +01:00
|
|
|
list_for_each_entry(network, &ieee->network_list, list) {
|
|
|
|
i++;
|
|
|
|
|
2012-11-29 14:35:51 +01:00
|
|
|
if ((stop-ev) < 200) {
|
2008-12-05 05:01:41 +01:00
|
|
|
err = -E2BIG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ieee->scan_age == 0 ||
|
2012-11-29 14:35:37 +01:00
|
|
|
time_after(network->last_scanned + ieee->scan_age, jiffies)) {
|
2008-12-05 05:01:41 +01:00
|
|
|
ev = rtl818x_translate_scan(ieee, ev, stop, network, info);
|
2012-11-29 14:35:37 +01:00
|
|
|
} else
|
2008-12-05 05:01:41 +01:00
|
|
|
IEEE80211_DEBUG_SCAN(
|
|
|
|
"Not showing network '%s ("
|
2009-12-06 20:34:52 +01:00
|
|
|
"%pM)' due to age (%lums).\n",
|
2008-12-05 05:01:41 +01:00
|
|
|
escape_essid(network->ssid,
|
|
|
|
network->ssid_len),
|
2009-12-06 20:34:52 +01:00
|
|
|
network->bssid,
|
2008-12-05 05:01:41 +01:00
|
|
|
(jiffies - network->last_scanned) / (HZ / 100));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&ieee->lock, flags);
|
|
|
|
up(&ieee->wx_sem);
|
|
|
|
wrqu->data.length = ev - extra;
|
|
|
|
wrqu->data.flags = 0;
|
|
|
|
IEEE80211_DEBUG_WX("exit: %d networks returned.\n", i);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
|
|
|
|
struct iw_request_info *info,
|
|
|
|
union iwreq_data *wrqu, char *keybuf)
|
|
|
|
{
|
|
|
|
struct iw_point *erq = &(wrqu->encoding);
|
|
|
|
struct net_device *dev = ieee->dev;
|
|
|
|
struct ieee80211_security sec = {
|
|
|
|
.flags = 0
|
|
|
|
};
|
|
|
|
int i, key, key_provided, len;
|
|
|
|
struct ieee80211_crypt_data **crypt;
|
|
|
|
|
|
|
|
IEEE80211_DEBUG_WX("SET_ENCODE\n");
|
|
|
|
|
|
|
|
key = erq->flags & IW_ENCODE_INDEX;
|
|
|
|
if (key) {
|
|
|
|
if (key > WEP_KEYS)
|
|
|
|
return -EINVAL;
|
|
|
|
key--;
|
|
|
|
key_provided = 1;
|
|
|
|
} else {
|
|
|
|
key_provided = 0;
|
|
|
|
key = ieee->tx_keyidx;
|
|
|
|
}
|
|
|
|
|
|
|
|
IEEE80211_DEBUG_WX("Key: %d [%s]\n", key, key_provided ?
|
|
|
|
"provided" : "default");
|
|
|
|
|
|
|
|
crypt = &ieee->crypt[key];
|
|
|
|
|
|
|
|
if (erq->flags & IW_ENCODE_DISABLED) {
|
|
|
|
if (key_provided && *crypt) {
|
|
|
|
IEEE80211_DEBUG_WX("Disabling encryption on key %d.\n",
|
|
|
|
key);
|
|
|
|
ieee80211_crypt_delayed_deinit(ieee, crypt);
|
|
|
|
} else
|
|
|
|
IEEE80211_DEBUG_WX("Disabling encryption.\n");
|
|
|
|
|
|
|
|
/* Check all the keys to see if any are still configured,
|
|
|
|
* and if no key index was provided, de-init them all */
|
|
|
|
for (i = 0; i < WEP_KEYS; i++) {
|
|
|
|
if (ieee->crypt[i] != NULL) {
|
|
|
|
if (key_provided)
|
|
|
|
break;
|
|
|
|
ieee80211_crypt_delayed_deinit(
|
|
|
|
ieee, &ieee->crypt[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == WEP_KEYS) {
|
|
|
|
sec.enabled = 0;
|
|
|
|
sec.level = SEC_LEVEL_0;
|
|
|
|
sec.flags |= SEC_ENABLED | SEC_LEVEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sec.enabled = 1;
|
|
|
|
sec.flags |= SEC_ENABLED;
|
|
|
|
|
|
|
|
if (*crypt != NULL && (*crypt)->ops != NULL &&
|
|
|
|
strcmp((*crypt)->ops->name, "WEP") != 0) {
|
|
|
|
/* changing to use WEP; deinit previously used algorithm
|
|
|
|
* on this key */
|
|
|
|
ieee80211_crypt_delayed_deinit(ieee, crypt);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*crypt == NULL) {
|
|
|
|
struct ieee80211_crypt_data *new_crypt;
|
|
|
|
|
|
|
|
/* take WEP into use */
|
Staging: Use kcalloc or kzalloc
Use kcalloc or kzalloc rather than the combination of kmalloc and memset.
The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression x,y,flags;
statement S;
type T;
@@
x =
- kmalloc
+ kcalloc
(
- y * sizeof(T),
+ y, sizeof(T),
flags);
if (x == NULL) S
-memset(x, 0, y * sizeof(T));
@@
expression x,size,flags;
statement S;
@@
-x = kmalloc(size,flags);
+x = kzalloc(size,flags);
if (x == NULL) S
-memset(x, 0, size);
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
2010-05-13 22:00:05 +02:00
|
|
|
new_crypt = kzalloc(sizeof(struct ieee80211_crypt_data),
|
2008-12-05 05:01:41 +01:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (new_crypt == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
new_crypt->ops = ieee80211_get_crypto_ops("WEP");
|
2009-10-02 16:03:38 +02:00
|
|
|
if (!new_crypt->ops)
|
2008-12-05 05:01:41 +01:00
|
|
|
new_crypt->ops = ieee80211_get_crypto_ops("WEP");
|
|
|
|
|
2009-10-02 16:03:38 +02:00
|
|
|
if (new_crypt->ops)
|
2008-12-05 05:01:41 +01:00
|
|
|
new_crypt->priv = new_crypt->ops->init(key);
|
|
|
|
|
|
|
|
if (!new_crypt->ops || !new_crypt->priv) {
|
|
|
|
kfree(new_crypt);
|
|
|
|
new_crypt = NULL;
|
|
|
|
|
2012-11-29 14:36:07 +01:00
|
|
|
netdev_warn(ieee->dev,
|
|
|
|
"could not initialize WEP: load module ieee80211_crypt_wep\n");
|
2008-12-05 05:01:41 +01:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
*crypt = new_crypt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If a new key was provided, set it up */
|
|
|
|
if (erq->length > 0) {
|
|
|
|
len = erq->length <= 5 ? 5 : 13;
|
|
|
|
memcpy(sec.keys[key], keybuf, erq->length);
|
|
|
|
if (len > erq->length)
|
|
|
|
memset(sec.keys[key] + erq->length, 0,
|
|
|
|
len - erq->length);
|
|
|
|
IEEE80211_DEBUG_WX("Setting key %d to '%s' (%d:%d bytes)\n",
|
|
|
|
key, escape_essid(sec.keys[key], len),
|
|
|
|
erq->length, len);
|
|
|
|
sec.key_sizes[key] = len;
|
2012-11-29 14:34:39 +01:00
|
|
|
(*crypt)->ops->set_key(sec.keys[key], len, NULL,
|
2008-12-05 05:01:41 +01:00
|
|
|
(*crypt)->priv);
|
|
|
|
sec.flags |= (1 << key);
|
|
|
|
/* This ensures a key will be activated if no key is
|
2012-04-17 15:56:43 +02:00
|
|
|
* explicitly set */
|
2008-12-05 05:01:41 +01:00
|
|
|
if (key == sec.active_key)
|
|
|
|
sec.flags |= SEC_ACTIVE_KEY;
|
|
|
|
ieee->tx_keyidx = key;//by wb 080312
|
|
|
|
} else {
|
|
|
|
len = (*crypt)->ops->get_key(sec.keys[key], WEP_KEY_LEN,
|
|
|
|
NULL, (*crypt)->priv);
|
|
|
|
if (len == 0) {
|
|
|
|
/* Set a default key of all 0 */
|
|
|
|
IEEE80211_DEBUG_WX("Setting key %d to all zero.\n",
|
|
|
|
key);
|
|
|
|
memset(sec.keys[key], 0, 13);
|
|
|
|
(*crypt)->ops->set_key(sec.keys[key], 13, NULL,
|
|
|
|
(*crypt)->priv);
|
|
|
|
sec.key_sizes[key] = 13;
|
|
|
|
sec.flags |= (1 << key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No key data - just set the default TX key index */
|
|
|
|
if (key_provided) {
|
|
|
|
IEEE80211_DEBUG_WX(
|
|
|
|
"Setting key %d to default Tx key.\n", key);
|
|
|
|
ieee->tx_keyidx = key;
|
|
|
|
sec.active_key = key;
|
|
|
|
sec.flags |= SEC_ACTIVE_KEY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
ieee->open_wep = !(erq->flags & IW_ENCODE_RESTRICTED);
|
|
|
|
sec.auth_mode = ieee->open_wep ? WLAN_AUTH_OPEN : WLAN_AUTH_SHARED_KEY;
|
|
|
|
sec.flags |= SEC_AUTH_MODE;
|
|
|
|
IEEE80211_DEBUG_WX("Auth: %s\n", sec.auth_mode == WLAN_AUTH_OPEN ?
|
|
|
|
"OPEN" : "SHARED KEY");
|
|
|
|
|
|
|
|
/* For now we just support WEP, so only set that security level...
|
|
|
|
* TODO: When WPA is added this is one place that needs to change */
|
|
|
|
sec.flags |= SEC_LEVEL;
|
|
|
|
sec.level = SEC_LEVEL_1; /* 40 and 104 bit WEP */
|
|
|
|
|
|
|
|
if (ieee->set_security)
|
|
|
|
ieee->set_security(dev, &sec);
|
|
|
|
|
|
|
|
/* Do not reset port if card is in Managed mode since resetting will
|
|
|
|
* generate new IEEE 802.11 authentication which may end up in looping
|
|
|
|
* with IEEE 802.1X. If your hardware requires a reset after WEP
|
|
|
|
* configuration (for example... Prism2), implement the reset_port in
|
|
|
|
* the callbacks structures used to initialize the 802.11 stack. */
|
|
|
|
if (ieee->reset_on_keychange &&
|
|
|
|
ieee->iw_mode != IW_MODE_INFRA &&
|
|
|
|
ieee->reset_port && ieee->reset_port(dev)) {
|
2012-11-29 14:36:07 +01:00
|
|
|
netdev_dbg(ieee->dev, "reset_port failed\n");
|
2008-12-05 05:01:41 +01:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
|
|
|
|
struct iw_request_info *info,
|
|
|
|
union iwreq_data *wrqu, char *keybuf)
|
|
|
|
{
|
|
|
|
struct iw_point *erq = &(wrqu->encoding);
|
|
|
|
int len, key;
|
|
|
|
struct ieee80211_crypt_data *crypt;
|
|
|
|
|
|
|
|
IEEE80211_DEBUG_WX("GET_ENCODE\n");
|
|
|
|
|
2012-11-29 14:35:37 +01:00
|
|
|
if (ieee->iw_mode == IW_MODE_MONITOR)
|
2008-12-05 05:01:41 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
key = erq->flags & IW_ENCODE_INDEX;
|
|
|
|
if (key) {
|
|
|
|
if (key > WEP_KEYS)
|
|
|
|
return -EINVAL;
|
|
|
|
key--;
|
|
|
|
} else
|
|
|
|
key = ieee->tx_keyidx;
|
|
|
|
|
|
|
|
crypt = ieee->crypt[key];
|
|
|
|
erq->flags = key + 1;
|
|
|
|
|
|
|
|
if (crypt == NULL || crypt->ops == NULL) {
|
|
|
|
erq->length = 0;
|
|
|
|
erq->flags |= IW_ENCODE_DISABLED;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(crypt->ops->name, "WEP") != 0) {
|
|
|
|
/* only WEP is supported with wireless extensions, so just
|
|
|
|
* report that encryption is used */
|
|
|
|
erq->length = 0;
|
|
|
|
erq->flags |= IW_ENCODE_ENABLED;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = crypt->ops->get_key(keybuf, WEP_KEY_LEN, NULL, crypt->priv);
|
|
|
|
erq->length = (len >= 0 ? len : 0);
|
|
|
|
|
|
|
|
erq->flags |= IW_ENCODE_ENABLED;
|
|
|
|
|
|
|
|
if (ieee->open_wep)
|
|
|
|
erq->flags |= IW_ENCODE_OPEN;
|
|
|
|
else
|
|
|
|
erq->flags |= IW_ENCODE_RESTRICTED;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
|
2012-11-29 14:34:39 +01:00
|
|
|
struct iw_request_info *info,
|
|
|
|
union iwreq_data *wrqu, char *extra)
|
2008-12-05 05:01:41 +01:00
|
|
|
{
|
|
|
|
struct net_device *dev = ieee->dev;
|
2012-11-29 14:34:39 +01:00
|
|
|
struct iw_point *encoding = &wrqu->encoding;
|
|
|
|
struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
|
|
|
|
int i, idx, ret = 0;
|
|
|
|
int group_key = 0;
|
|
|
|
const char *alg;
|
|
|
|
struct ieee80211_crypto_ops *ops;
|
|
|
|
struct ieee80211_crypt_data **crypt;
|
|
|
|
|
|
|
|
struct ieee80211_security sec = {
|
|
|
|
.flags = 0,
|
|
|
|
};
|
2008-12-05 05:01:41 +01:00
|
|
|
//printk("======>encoding flag:%x,ext flag:%x, ext alg:%d\n", encoding->flags,ext->ext_flags, ext->alg);
|
2012-11-29 14:34:39 +01:00
|
|
|
idx = encoding->flags & IW_ENCODE_INDEX;
|
|
|
|
if (idx) {
|
|
|
|
if (idx < 1 || idx > WEP_KEYS)
|
|
|
|
return -EINVAL;
|
|
|
|
idx--;
|
|
|
|
} else
|
|
|
|
idx = ieee->tx_keyidx;
|
|
|
|
|
|
|
|
if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
|
|
|
|
crypt = &ieee->crypt[idx];
|
|
|
|
group_key = 1;
|
|
|
|
} else {
|
|
|
|
/* some Cisco APs use idx>0 for unicast in dynamic WEP */
|
2008-12-05 05:01:41 +01:00
|
|
|
//printk("not group key, flags:%x, ext->alg:%d\n", ext->ext_flags, ext->alg);
|
2012-11-29 14:34:39 +01:00
|
|
|
if (idx != 0 && ext->alg != IW_ENCODE_ALG_WEP)
|
|
|
|
return -EINVAL;
|
|
|
|
if (ieee->iw_mode == IW_MODE_INFRA)
|
|
|
|
crypt = &ieee->crypt[idx];
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sec.flags |= SEC_ENABLED;// | SEC_ENCRYPT;
|
|
|
|
if ((encoding->flags & IW_ENCODE_DISABLED) ||
|
|
|
|
ext->alg == IW_ENCODE_ALG_NONE) {
|
|
|
|
if (*crypt)
|
|
|
|
ieee80211_crypt_delayed_deinit(ieee, crypt);
|
|
|
|
|
|
|
|
for (i = 0; i < WEP_KEYS; i++)
|
|
|
|
if (ieee->crypt[i] != NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == WEP_KEYS) {
|
|
|
|
sec.enabled = 0;
|
|
|
|
// sec.encrypt = 0;
|
|
|
|
sec.level = SEC_LEVEL_0;
|
|
|
|
sec.flags |= SEC_LEVEL;
|
|
|
|
}
|
2008-12-05 05:01:41 +01:00
|
|
|
//printk("disabled: flag:%x\n", encoding->flags);
|
2012-11-29 14:34:39 +01:00
|
|
|
goto done;
|
|
|
|
}
|
2008-12-05 05:01:41 +01:00
|
|
|
|
|
|
|
sec.enabled = 1;
|
|
|
|
// sec.encrypt = 1;
|
2009-06-28 16:19:23 +02:00
|
|
|
|
2012-11-29 14:34:39 +01:00
|
|
|
switch (ext->alg) {
|
|
|
|
case IW_ENCODE_ALG_WEP:
|
|
|
|
alg = "WEP";
|
|
|
|
break;
|
|
|
|
case IW_ENCODE_ALG_TKIP:
|
|
|
|
alg = "TKIP";
|
|
|
|
break;
|
|
|
|
case IW_ENCODE_ALG_CCMP:
|
|
|
|
alg = "CCMP";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n",
|
|
|
|
dev->name, ext->alg);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
2009-01-07 23:31:57 +01:00
|
|
|
// printk("8-09-08-9=====>%s, alg name:%s\n",__func__, alg);
|
2008-12-05 05:01:41 +01:00
|
|
|
|
2012-11-29 14:34:39 +01:00
|
|
|
ops = ieee80211_get_crypto_ops(alg);
|
|
|
|
if (ops == NULL)
|
|
|
|
ops = ieee80211_get_crypto_ops(alg);
|
|
|
|
if (ops == NULL) {
|
|
|
|
IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n",
|
|
|
|
dev->name, ext->alg);
|
2008-12-05 05:01:41 +01:00
|
|
|
printk("========>unknown crypto alg %d\n", ext->alg);
|
2012-11-29 14:34:39 +01:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*crypt == NULL || (*crypt)->ops != ops) {
|
|
|
|
struct ieee80211_crypt_data *new_crypt;
|
|
|
|
|
|
|
|
ieee80211_crypt_delayed_deinit(ieee, crypt);
|
|
|
|
|
|
|
|
new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL);
|
|
|
|
if (new_crypt == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
new_crypt->ops = ops;
|
|
|
|
if (new_crypt->ops)
|
|
|
|
new_crypt->priv = new_crypt->ops->init(idx);
|
|
|
|
if (new_crypt->priv == NULL) {
|
|
|
|
kfree(new_crypt);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
*crypt = new_crypt;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ext->key_len > 0 && (*crypt)->ops->set_key &&
|
|
|
|
(*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
|
|
|
|
(*crypt)->priv) < 0) {
|
|
|
|
IEEE80211_DEBUG_WX("%s: key setting failed\n", dev->name);
|
2008-12-05 05:01:41 +01:00
|
|
|
printk("key setting failed\n");
|
2012-11-29 14:34:39 +01:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
2008-12-05 05:01:41 +01:00
|
|
|
#if 1
|
|
|
|
//skip_host_crypt:
|
|
|
|
//printk("skip_host_crypt:ext_flags:%x\n", ext->ext_flags);
|
2012-11-29 14:34:39 +01:00
|
|
|
if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
|
|
|
|
ieee->tx_keyidx = idx;
|
|
|
|
sec.active_key = idx;
|
|
|
|
sec.flags |= SEC_ACTIVE_KEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ext->alg != IW_ENCODE_ALG_NONE) {
|
|
|
|
memcpy(sec.keys[idx], ext->key, ext->key_len);
|
|
|
|
sec.key_sizes[idx] = ext->key_len;
|
|
|
|
sec.flags |= (1 << idx);
|
|
|
|
if (ext->alg == IW_ENCODE_ALG_WEP) {
|
|
|
|
// sec.encode_alg[idx] = SEC_ALG_WEP;
|
|
|
|
sec.flags |= SEC_LEVEL;
|
|
|
|
sec.level = SEC_LEVEL_1;
|
|
|
|
} else if (ext->alg == IW_ENCODE_ALG_TKIP) {
|
|
|
|
// sec.encode_alg[idx] = SEC_ALG_TKIP;
|
|
|
|
sec.flags |= SEC_LEVEL;
|
|
|
|
sec.level = SEC_LEVEL_2;
|
|
|
|
} else if (ext->alg == IW_ENCODE_ALG_CCMP) {
|
|
|
|
// sec.encode_alg[idx] = SEC_ALG_CCMP;
|
|
|
|
sec.flags |= SEC_LEVEL;
|
|
|
|
sec.level = SEC_LEVEL_3;
|
|
|
|
}
|
|
|
|
/* Don't set sec level for group keys. */
|
|
|
|
if (group_key)
|
|
|
|
sec.flags &= ~SEC_LEVEL;
|
|
|
|
}
|
2008-12-05 05:01:41 +01:00
|
|
|
#endif
|
|
|
|
done:
|
2012-11-29 14:34:39 +01:00
|
|
|
if (ieee->set_security)
|
|
|
|
ieee->set_security(ieee->dev, &sec);
|
2008-12-05 05:01:41 +01:00
|
|
|
|
|
|
|
if (ieee->reset_on_keychange &&
|
2012-11-29 14:34:39 +01:00
|
|
|
ieee->iw_mode != IW_MODE_INFRA &&
|
|
|
|
ieee->reset_port && ieee->reset_port(dev)) {
|
|
|
|
IEEE80211_DEBUG_WX("%s: reset_port failed\n", dev->name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2008-12-05 05:01:41 +01:00
|
|
|
|
2012-11-29 14:34:39 +01:00
|
|
|
return ret;
|
2008-12-05 05:01:41 +01:00
|
|
|
}
|
|
|
|
int ieee80211_wx_set_mlme(struct ieee80211_device *ieee,
|
2012-11-29 14:34:39 +01:00
|
|
|
struct iw_request_info *info,
|
|
|
|
union iwreq_data *wrqu, char *extra)
|
2008-12-05 05:01:41 +01:00
|
|
|
{
|
|
|
|
struct iw_mlme *mlme = (struct iw_mlme *) extra;
|
2009-01-07 23:31:57 +01:00
|
|
|
// printk("\ndkgadfslkdjgalskdf===============>%s(), cmd:%x\n", __func__, mlme->cmd);
|
2008-12-05 05:01:41 +01:00
|
|
|
#if 1
|
|
|
|
switch (mlme->cmd) {
|
2012-11-29 14:34:39 +01:00
|
|
|
case IW_MLME_DEAUTH:
|
2008-12-05 05:01:41 +01:00
|
|
|
case IW_MLME_DISASSOC:
|
|
|
|
// printk("disassoc now\n");
|
|
|
|
ieee80211_disassociate(ieee);
|
|
|
|
break;
|
|
|
|
default:
|
2012-11-29 14:34:39 +01:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
2008-12-05 05:01:41 +01:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
|
2012-11-29 14:34:39 +01:00
|
|
|
struct iw_request_info *info,
|
|
|
|
struct iw_param *data, char *extra)
|
2008-12-05 05:01:41 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
struct ieee80211_security sec = {
|
2012-11-29 14:34:39 +01:00
|
|
|
.flags = SEC_AUTH_MODE,
|
2008-12-05 05:01:41 +01:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
//printk("set auth:flag:%x, data value:%x\n", data->flags, data->value);
|
|
|
|
switch (data->flags & IW_AUTH_INDEX) {
|
2012-11-29 14:34:39 +01:00
|
|
|
case IW_AUTH_WPA_VERSION:
|
2008-12-05 05:01:41 +01:00
|
|
|
/*need to support wpa2 here*/
|
|
|
|
//printk("wpa version:%x\n", data->value);
|
|
|
|
break;
|
2012-11-29 14:34:39 +01:00
|
|
|
case IW_AUTH_CIPHER_PAIRWISE:
|
|
|
|
case IW_AUTH_CIPHER_GROUP:
|
|
|
|
case IW_AUTH_KEY_MGMT:
|
|
|
|
/*
|
2008-12-05 05:01:41 +01:00
|
|
|
* * Host AP driver does not use these parameters and allows
|
|
|
|
* * wpa_supplicant to control them internally.
|
|
|
|
* */
|
2012-11-29 14:34:39 +01:00
|
|
|
break;
|
|
|
|
case IW_AUTH_TKIP_COUNTERMEASURES:
|
|
|
|
ieee->tkip_countermeasures = data->value;
|
|
|
|
break;
|
|
|
|
case IW_AUTH_DROP_UNENCRYPTED:
|
|
|
|
ieee->drop_unencrypted = data->value;
|
2008-12-05 05:01:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IW_AUTH_80211_AUTH_ALG:
|
2012-11-29 14:35:51 +01:00
|
|
|
ieee->open_wep = (data->value&IW_AUTH_ALG_OPEN_SYSTEM) ? 1 : 0;
|
2008-12-05 05:01:41 +01:00
|
|
|
//printk("open_wep:%d\n", ieee->open_wep);
|
|
|
|
break;
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
case IW_AUTH_WPA_ENABLED:
|
2012-11-29 14:35:51 +01:00
|
|
|
ieee->wpa_enabled = (data->value) ? 1 : 0;
|
2010-01-12 15:57:56 +01:00
|
|
|
//printk("enable wpa:%d\n", ieee->wpa_enabled);
|
2008-12-05 05:01:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
case IW_AUTH_RX_UNENCRYPTED_EAPOL:
|
2012-11-29 14:34:39 +01:00
|
|
|
ieee->ieee802_1x = data->value;
|
2008-12-05 05:01:41 +01:00
|
|
|
break;
|
|
|
|
case IW_AUTH_PRIVACY_INVOKED:
|
|
|
|
ieee->privacy_invoked = data->value;
|
|
|
|
break;
|
|
|
|
default:
|
2012-11-29 14:34:39 +01:00
|
|
|
return -EOPNOTSUPP;
|
2008-12-05 05:01:41 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len)
|
|
|
|
{
|
|
|
|
u8 *buf = NULL;
|
|
|
|
|
2012-11-29 14:35:51 +01:00
|
|
|
if (len > MAX_WPA_IE_LEN || (len && ie == NULL)) {
|
2009-02-11 22:19:35 +01:00
|
|
|
printk("return error out, len:%zu\n", len);
|
2008-12-05 05:01:41 +01:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-11-29 14:35:37 +01:00
|
|
|
if (len) {
|
|
|
|
if (len != ie[1]+2) {
|
2009-02-11 22:19:35 +01:00
|
|
|
printk("len:%zu, ie:%d\n", len, ie[1]);
|
2008-12-05 05:01:41 +01:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-05-15 23:21:43 +02:00
|
|
|
buf = kmemdup(ie, len, GFP_KERNEL);
|
2008-12-05 05:01:41 +01:00
|
|
|
if (buf == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
kfree(ieee->wpa_ie);
|
|
|
|
ieee->wpa_ie = buf;
|
|
|
|
ieee->wpa_ie_len = len;
|
2012-11-29 14:35:37 +01:00
|
|
|
} else {
|
2008-12-05 05:01:41 +01:00
|
|
|
kfree(ieee->wpa_ie);
|
|
|
|
ieee->wpa_ie = NULL;
|
|
|
|
ieee->wpa_ie_len = 0;
|
|
|
|
}
|
2009-01-07 23:31:57 +01:00
|
|
|
// printk("<=====out %s()\n", __func__);
|
2008-12-05 05:01:41 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|