Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 89979
b: refs/heads/master
c: db4d116
h: refs/heads/master
i:
  89977: 43cbee8
  89975: 4050db3
v: v3
  • Loading branch information
Johannes Berg authored and John W. Linville committed Feb 29, 2008
1 parent ecb2d61 commit 5c9352f
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 99 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6f48422a29714ed92f6136d9e7d3ff39c75607d7
refs/heads/master: db4d1169d0b893bfb7923b6526748fe2c5a7373f
27 changes: 19 additions & 8 deletions trunk/net/mac80211/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
struct sta_info *sta = NULL;
enum ieee80211_key_alg alg;
int ret;
struct ieee80211_key *key;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

Expand All @@ -141,16 +142,21 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
return -EINVAL;
}

key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
if (!key)
return -ENOMEM;

if (mac_addr) {
sta = sta_info_get(sdata->local, mac_addr);
if (!sta)
if (!sta) {
ieee80211_key_free(key);
return -ENOENT;
}
}

ieee80211_key_link(key, sdata, sta);

ret = 0;
if (!ieee80211_key_alloc(sdata, sta, alg, key_idx,
params->key_len, params->key))
ret = -ENOMEM;

if (sta)
sta_info_put(sta);
Expand All @@ -164,6 +170,7 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
struct ieee80211_sub_if_data *sdata;
struct sta_info *sta;
int ret;
struct ieee80211_key *key;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

Expand All @@ -173,9 +180,11 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
return -ENOENT;

ret = 0;
if (sta->key)
ieee80211_key_free(sta->key);
else
if (sta->key) {
key = sta->key;
ieee80211_key_free(key);
WARN_ON(sta->key);
} else
ret = -ENOENT;

sta_info_put(sta);
Expand All @@ -185,7 +194,9 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
if (!sdata->keys[key_idx])
return -ENOENT;

ieee80211_key_free(sdata->keys[key_idx]);
key = sdata->keys[key_idx];
ieee80211_key_free(key);
WARN_ON(sdata->keys[key_idx]);

return 0;
}
Expand Down
90 changes: 48 additions & 42 deletions trunk/net/mac80211/ieee80211_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
size_t key_len)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
int ret = 0;
struct sta_info *sta;
int ret;
struct sta_info *sta = NULL;
struct ieee80211_key *key;
struct ieee80211_sub_if_data *sdata;

Expand All @@ -46,58 +46,64 @@ static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
return -EINVAL;
}

if (is_broadcast_ether_addr(sta_addr)) {
sta = NULL;
key = sdata->keys[idx];
} else {
set_tx_key = 0;
/*
* According to the standard, the key index of a pairwise
* key must be zero. However, some AP are broken when it
* comes to WEP key indices, so we work around this.
*/
if (idx != 0 && alg != ALG_WEP) {
printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
"individual key\n", dev->name);
return -EINVAL;
if (remove) {
if (is_broadcast_ether_addr(sta_addr)) {
key = sdata->keys[idx];
} else {
sta = sta_info_get(local, sta_addr);
if (!sta) {
ret = -ENOENT;
key = NULL;
goto err_out;
}

key = sta->key;
}

sta = sta_info_get(local, sta_addr);
if (!sta) {
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
DECLARE_MAC_BUF(mac);
printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
"%s\n",
dev->name, print_mac(mac, sta_addr));
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
if (!key)
ret = -ENOENT;
else
ret = 0;
} else {
key = ieee80211_key_alloc(alg, idx, key_len, _key);
if (!key)
return -ENOMEM;

if (!is_broadcast_ether_addr(sta_addr)) {
set_tx_key = 0;
/*
* According to the standard, the key index of a
* pairwise key must be zero. However, some AP are
* broken when it comes to WEP key indices, so we
* work around this.
*/
if (idx != 0 && alg != ALG_WEP) {
ret = -EINVAL;
goto err_out;
}

return -ENOENT;
sta = sta_info_get(local, sta_addr);
if (!sta) {
ret = -ENOENT;
goto err_out;
}
}

key = sta->key;
}
ieee80211_key_link(key, sdata, sta);

if (remove) {
ieee80211_key_free(key);
if (set_tx_key || (!sta && !sdata->default_key && key))
ieee80211_set_default_key(sdata, idx);

/* don't free key later */
key = NULL;
} else {
/*
* Automatically frees any old key if present.
*/
key = ieee80211_key_alloc(sdata, sta, alg, idx, key_len, _key);
if (!key) {
ret = -ENOMEM;
goto err_out;
}
}

if (set_tx_key || (!sta && !sdata->default_key && key))
ieee80211_set_default_key(sdata, idx);
ret = 0;
}

ret = 0;
err_out:
if (sta)
sta_info_put(sta);
ieee80211_key_free(key);
return ret;
}

Expand Down
26 changes: 22 additions & 4 deletions trunk/net/mac80211/ieee80211_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/types.h>
#include <linux/list.h>
#include <linux/crypto.h>
#include <linux/rcupdate.h>
#include <net/mac80211.h>

/* ALG_TKIP
Expand Down Expand Up @@ -45,7 +46,19 @@ struct ieee80211_local;
struct ieee80211_sub_if_data;
struct sta_info;

#define KEY_FLAG_UPLOADED_TO_HARDWARE (1<<0)
/**
* enum ieee80211_internal_key_flags - internal key flags
*
* @KEY_FLAG_UPLOADED_TO_HARDWARE: Indicates that this key is present
* in the hardware for TX crypto hardware acceleration.
* @KEY_FLAG_REMOVE_FROM_HARDWARE: Indicates to the key code that this
* key is present in the hardware (but it cannot be used for
* hardware acceleration any more!)
*/
enum ieee80211_internal_key_flags {
KEY_FLAG_UPLOADED_TO_HARDWARE = BIT(0),
KEY_FLAG_REMOVE_FROM_HARDWARE = BIT(1),
};

struct ieee80211_key {
struct ieee80211_local *local;
Expand Down Expand Up @@ -112,12 +125,17 @@ struct ieee80211_key {
struct ieee80211_key_conf conf;
};

struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
struct sta_info *sta,
enum ieee80211_key_alg alg,
struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg,
int idx,
size_t key_len,
const u8 *key_data);
/*
* Insert a key into data structures (sdata, sta if necessary)
* to make it used, free old key.
*/
void ieee80211_key_link(struct ieee80211_key *key,
struct ieee80211_sub_if_data *sdata,
struct sta_info *sta);
void ieee80211_key_free(struct ieee80211_key *key);
void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx);
void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata);
Expand Down
Loading

0 comments on commit 5c9352f

Please sign in to comment.