cfg80211: rework key operation
Subsystems (2)
Johannes Berg
maintainerPATCH 1/1 cfg80211: rework key operation
This reworks the key operation in cfg80211, and now only allows, from userspace, configuring keys (via nl80211) after the connection has been established (in managed mode), the IBSS been joined (in IBSS mode), at any time (in AP[_VLAN] modes) or never for all the other modes.
In order to do shared key authentication correctly, it is now possible to give a WEP key to the AUTH command. To configure static WEP keys, these are given to the CONNECT or IBSS_JOIN command directly, for a userspace SME it is assumed it will configure it properly after the connection has been established.
Since mac80211 used to check the default key in IBSS mode to see whether or not the network is protected, it needs an update in that area, as well as an update to make use of the WEP key passed to auth() for shared key authentication.
---
Samuel, if you would like the keys passed directly to the connect() call then feel free submit a patch changing that.
include/linux/nl80211.h | 4 + include/net/cfg80211.h | 18 ++++ net/mac80211/ibss.c | 9 +- net/mac80211/ieee80211_i.h | 8 +- net/mac80211/mlme.c | 11 ++ net/mac80211/util.c | 16 ++-- net/mac80211/wep.c | 6 - net/mac80211/wep.h | 3 net/wireless/core.c | 11 +- net/wireless/core.h | 32 ++++++-- net/wireless/ibss.c | 79 +++++++++++++++++--- net/wireless/mlme.c | 16 +++- net/wireless/nl80211.c | 170 +++++++++++++++++++++++++++++++++++++++------ net/wireless/sme.c | 97 ++++++++++++++++++------- net/wireless/util.c | 41 ++++++++++ net/wireless/wext-compat.c | 167 +++++++++++++++++++++++++++----------------- net/wireless/wext-sme.c | 30 ++++++- 17 files changed, 555 insertions(+), 163 deletions(-)
include/linux/nl80211.h +4 -0
@@ -576,6 +576,9 @@ enum nl80211_commands {* * @NL80211_ATTR_KEY: key information in a nested attribute with * %NL80211_KEY_* sub-attributes +* @NL80211_ATTR_KEYS: array of keys for static WEP keys for connect() +* and join_ibss(), key information is in a nested attribute each +* with %NL80211_KEY_* sub-attributes * * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use
@@ -705,6 +708,7 @@ enum nl80211_attrs {NL80211_ATTR_PID ,NL80211_ATTR_KEY , + NL80211_ATTR_KEYS,/* add attributes here, update the policy in nl80211.c */
net/wireless/nl80211.c +151 -19
283 lines not on this page · raw message
net/wireless/wext-compat.c +103 -64
241 lines not on this page · raw message
include/net/cfg80211.h +17 -1
@@ -647,12 +647,17 @@ struct cfg80211_crypto_settings {* @auth_type: Authentication type (algorithm) * @ie: Extra IEs to add to Authentication frame or %NULL * @ie_len: Length of ie buffer in octets +* @key_len: length of WEP key for shared key authentication +* @key_idx: index of WEP key for shared key authentication +* @key: WEP key for shared key authentication */ struct cfg80211_auth_request {struct cfg80211_bss *bss;const u8 *ie;size_t ie_len;enum nl80211_auth_type auth_type; +const u8 *key; +u8 key_len, key_idx; };/**
@@ -727,6 +732,8 @@ struct cfg80211_disassoc_request {* @ie: information element(s) to include in the beacon * @ie_len: length of that * @beacon_interval: beacon interval to use +* @privacy: this is a protected network, keys will be configured +* after joining */ struct cfg80211_ibss_params {u8 *ssid;
@@ -736,6 +743,7 @@ struct cfg80211_ibss_params {u8 ssid_len, ie_len;u16 beacon_interval;bool channel_fixed; +bool privacy; };/**
@@ -755,6 +763,9 @@ struct cfg80211_ibss_params {* @assoc_ie_len: Length of assoc_ie in octets * @privacy: indicates whether privacy-enabled APs should be used * @crypto: crypto settings +* @key_len: length of WEP key for shared key authentication +* @key_idx: index of WEP key for shared key authentication +* @key: WEP key for shared key authentication */ struct cfg80211_connect_params {struct ieee80211_channel *channel;
@@ -766,6 +777,8 @@ struct cfg80211_connect_params {size_t ie_len;bool privacy;struct cfg80211_crypto_settings crypto; +const u8 *key; +u8 key_len, key_idx; };/**
@@ -1255,9 +1268,10 @@ extern void wiphy_unregister(struct wiph*/ extern void wiphy_free (struct wiphy *wiphy); -/* internal struct */ +/* internal structs */ struct cfg80211_conn ;struct cfg80211_internal_bss ; +struct cfg80211_cached_keys ;#define MAX_AUTH_BSSES 4
@@ -1299,6 +1313,7 @@ struct wireless_dev {CFG80211_SME_CONNECTED , } sme_state;struct cfg80211_conn *conn; +struct cfg80211_cached_keys *connect_keys;struct list_head event_list;spinlock_t event_lock;
@@ -1312,6 +1327,7 @@ struct wireless_dev {struct {struct cfg80211_ibss_params ibss;struct cfg80211_connect_params connect; +struct cfg80211_cached_keys *keys;u8 *ie;size_t ie_len;u8 bssid[ETH_ALEN ];
net/wireless/core.h +25 -7
@@ -241,6 +241,12 @@ struct cfg80211_event { }; }; +struct cfg80211_cached_keys { +struct key_params params[6 ]; +u8 data[6 ][WLAN_MAX_KEY_LEN ]; +int def, defmgmt; +}; +/* free object */ extern void cfg80211_dev_free (struct cfg80211_registered_device *rdev);
@@ -259,14 +265,18 @@ void cfg80211_bss_age(struct cfg80211_re/* IBSS */ int __cfg80211_join_ibss (struct cfg80211_registered_device *rdev,struct net_device *dev, -struct cfg80211_ibss_params *params); +struct cfg80211_ibss_params *params, +struct cfg80211_cached_keys *connkeys);int cfg80211_join_ibss (struct cfg80211_registered_device *rdev,struct net_device *dev, -struct cfg80211_ibss_params *params); +struct cfg80211_ibss_params *params, +struct cfg80211_cached_keys *connkeys);void cfg80211_clear_ibss (struct net_device *dev,bool nowext);int cfg80211_leave_ibss (struct cfg80211_registered_device *rdev,struct net_device *dev,bool nowext);void __cfg80211_ibss_joined (struct net_device *dev,const u8 *bssid); +int cfg80211_ibss_wext_join (struct cfg80211_registered_device *rdev, +struct wireless_dev *wdev);/* MLME */ int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
@@ -275,12 +285,14 @@ int __cfg80211_mlme_auth(struct cfg80211enum nl80211_auth_type auth_type, const u8 *bssid, const u8 *ssid, int ssid_len, - const u8 *ie, int ie_len); + const u8 *ie, int ie_len, + const u8 *key, int key_len, int key_idx);int cfg80211_mlme_auth (struct cfg80211_registered_device *rdev,struct net_device *dev,struct ieee80211_channel *chan,enum nl80211_auth_type auth_type,const u8 *bssid,const u8 *ssid,int ssid_len, -const u8 *ie,int ie_len); +const u8 *ie,int ie_len, +const u8 *key,int key_len,int key_idx); int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, struct net_device *dev, struct ieee80211_channel *chan,
@@ -313,10 +325,12 @@ void __cfg80211_connect_result(struct ne/* SME */ int __cfg80211_connect (struct cfg80211_registered_device *rdev,struct net_device *dev, -struct cfg80211_connect_params *connect); +struct cfg80211_connect_params *connect, +struct cfg80211_cached_keys *connkeys);int cfg80211_connect (struct cfg80211_registered_device *rdev,struct net_device *dev, -struct cfg80211_connect_params *connect); +struct cfg80211_connect_params *connect, +struct cfg80211_cached_keys *connkeys);int __cfg80211_disconnect (struct cfg80211_registered_device *rdev,struct net_device *dev,u16 reason,bool wextev);
@@ -326,11 +340,14 @@ int cfg80211_disconnect(struct cfg80211_void __cfg80211_roamed (struct wireless_dev *wdev,const u8 *bssid,const u8 *req_ie,size_t req_ie_len,const u8 *resp_ie,size_t resp_ie_len); +int cfg80211_mgd_wext_connect (struct cfg80211_registered_device *rdev, +struct wireless_dev *wdev);void cfg80211_conn_work (struct work_struct *work);/* internal helpers */ -int cfg80211_validate_key_settings (struct key_params *params,int key_idx, +int cfg80211_validate_key_settings (struct cfg80211_registered_device *rdev, +struct key_params *params,int key_idx,const u8 *mac_addr);void __cfg80211_disconnected (struct net_device *dev,const u8 *ie,size_t ie_len,u16 reason,bool from_ap);
@@ -338,5 +355,6 @@ void cfg80211_sme_scan_done(struct net_dvoid cfg80211_sme_rx_auth (struct net_device *dev,const u8 *buf,size_t len);void cfg80211_sme_disassoc (struct net_device *dev,int idx);void __cfg80211_scan_done (struct work_struct *wk); +void cfg80211_upload_connect_keys (struct wireless_dev *wdev);#endif /* __NET_WIRELESS_CORE_H */
net/wireless/core.c +5 -6
@@ -707,14 +707,10 @@ static int cfg80211_netdev_notifier_callwdev_lock (wdev);switch (wdev->iftype) {case NL80211_IFTYPE_ADHOC : -if (wdev->wext.ibss.ssid_len) -__cfg80211_join_ibss (rdev, dev, - &wdev->wext.ibss); +cfg80211_ibss_wext_join (rdev, wdev);break ;case NL80211_IFTYPE_STATION : -if (wdev->wext.connect.ssid_len) -__cfg80211_connect (rdev, dev, - &wdev->wext.connect); +cfg80211_mgd_wext_connect (rdev, wdev);break ;default :break ;
@@ -731,6 +727,9 @@ static int cfg80211_netdev_notifier_call }mutex_unlock (&rdev->devlist_mtx);mutex_destroy (&wdev->mtx); +#ifdef CONFIG_WIRELESS_EXT +kfree (wdev->wext.keys); +#endif break ;case NETDEV_PRE_UP :if (!(wdev->wiphy->interface_modes &BIT (wdev->iftype)))
net/wireless/sme.c +71 -26
184 lines not on this page · raw message
net/wireless/wext-sme.c +23 -7
@@ -10,10 +10,11 @@#include <net/cfg80211.h> #include "nl80211.h" -static int cfg80211_mgd_wext_connect (struct cfg80211_registered_device *rdev, -struct wireless_dev *wdev) +int cfg80211_mgd_wext_connect (struct cfg80211_registered_device *rdev, +struct wireless_dev *wdev) { -int err; +struct cfg80211_cached_keys *ck =NULL ; +int err, i;ASSERT_RDEV_LOCK (rdev);ASSERT_WDEV_LOCK (wdev);
@@ -25,10 +26,25 @@ static int cfg80211_mgd_wext_connect(str wdev->wext.connect.ie_len = wdev->wext.ie_len; wdev->wext.connect.privacy = wdev->wext.default_key !=-1 ; - err =0 ; -if (wdev->wext.connect.ssid_len !=0 ) - err =__cfg80211_connect (rdev, wdev->netdev, - &wdev->wext.connect); +if (wdev->wext.keys) { + wdev->wext.keys->def = wdev->wext.default_key; + wdev->wext.keys->defmgmt = wdev->wext.default_mgmt_key; + } + +if (!wdev->wext.connect.ssid_len) +return 0 ; + +if (wdev->wext.keys) { + ck =kmemdup (wdev->wext.keys,sizeof (*ck),GFP_KERNEL ); +if (!ck) +return -ENOMEM ; +for (i =0 ; i <6 ; i++) + ck->params[i].key = ck->data[i]; + } + err =__cfg80211_connect (rdev, wdev->netdev, + &wdev->wext.connect, ck); +if (err) +kfree (ck);return err; }
net/wireless/mlme.c +13 -3
@@ -328,7 +328,8 @@ int __cfg80211_mlme_auth(struct cfg80211enum nl80211_auth_type auth_type, const u8 *bssid, const u8 *ssid, int ssid_len, - const u8 *ie, int ie_len) + const u8 *ie, int ie_len, + const u8 *key, int key_len, int key_idx) { struct wireless_dev *wdev = dev->ieee80211_ptr;struct cfg80211_auth_request req;
@@ -337,6 +338,10 @@ int __cfg80211_mlme_auth(struct cfg80211ASSERT_WDEV_LOCK (wdev); +if (auth_type ==NL80211_AUTHTYPE_SHARED_KEY ) +if (!key || !key_len || key_idx <0 || key_idx >4 ) +return -EINVAL ; +if (wdev->current_bss &&memcmp (bssid, wdev->current_bss->pub.bssid,ETH_ALEN ) ==0 )return -EALREADY ;
@@ -359,6 +364,9 @@ int __cfg80211_mlme_auth(struct cfg80211 req.auth_type = auth_type; req.bss =cfg80211_get_bss (&rdev->wiphy, chan, bssid, ssid, ssid_len,WLAN_CAPABILITY_ESS ,WLAN_CAPABILITY_ESS ); + req.key = key; + req.key_len = key_len; + req.key_idx = key_idx;if (!req.bss)return -ENOENT ;
@@ -396,13 +404,15 @@ int cfg80211_mlme_auth(struct cfg80211_r struct net_device *dev, struct ieee80211_channel *chan, enum nl80211_auth_type auth_type, const u8 *bssid, const u8 *ssid, int ssid_len, - const u8 *ie, int ie_len) + const u8 *ie, int ie_len, + const u8 *key, int key_len, int key_idx) { int err;wdev_lock (dev->ieee80211_ptr); err =__cfg80211_mlme_auth (rdev, dev, chan, auth_type, bssid, - ssid, ssid_len, ie, ie_len); + ssid, ssid_len, ie, ie_len, + key, key_len, key_idx);wdev_unlock (dev->ieee80211_ptr);return err;
net/mac80211/ieee80211_i.h +6 -2
@@ -247,6 +247,9 @@ struct ieee80211_mgd_work {int tries; +u8 key[WLAN_KEY_LEN_WEP104 ]; +u8 key_len, key_idx; +/* must be last */ u8 ie[0 ];/* for auth or assoc frame, not probe */ };
@@ -321,6 +324,7 @@ struct ieee80211_if_ibss {bool fixed_bssid;bool fixed_channel; +bool privacy;u8 bssid[ETH_ALEN ];u8 ssid[IEEE80211_MAX_SSID_LEN ];
@@ -1090,8 +1094,8 @@ int ieee80211_add_pending_skbs(struct ievoid ieee80211_send_auth (struct ieee80211_sub_if_data *sdata,u16 transaction,u16 auth_alg, -u8 *extra,size_t extra_len, -const u8 *bssid,int encrypt); +u8 *extra,size_t extra_len,const u8 *bssid, +const u8 *key,u8 key_len,u8 key_idx);int ieee80211_build_preq_ies (struct ieee80211_local *local,u8 *buffer,const u8 *ie,size_t ie_len); void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
net/mac80211/mlme.c +9 -2
@@ -954,7 +954,7 @@ ieee80211_authenticate(struct ieee80211_ sdata->dev->name, wk->bss->cbss.bssid, wk->tries);ieee80211_send_auth (sdata,1 , wk->auth_alg, wk->ie, wk->ie_len, - wk->bss->cbss.bssid,0 ); + wk->bss->cbss.bssid,NULL ,0 ,0 ); wk->auth_transaction =2 ; wk->timeout = jiffies +IEEE80211_AUTH_TIMEOUT ;
@@ -1176,7 +1176,8 @@ static void ieee80211_auth_challenge(strreturn ;ieee80211_send_auth (sdata,3 , wk->auth_alg, elems.challenge -2 , elems.challenge_len +2 , - wk->bss->cbss.bssid,1 ); + wk->bss->cbss.bssid, + wk->key, wk->key_len, wk->key_idx); wk->auth_transaction =4 ; }
@@ -2175,6 +2176,12 @@ int ieee80211_mgd_auth(struct ieee80211_ wk->ie_len = req->ie_len; } +if (req->key && req->key_len) { + wk->key_len = req->key_len; + wk->key_idx = req->key_idx; +memcpy (wk->key, req->key, req->key_len); + } + ssid =ieee80211_bss_get_ie (req->bss,WLAN_EID_SSID );memcpy (wk->ssid, ssid +2 , ssid[1 ]); wk->ssid_len = ssid[1 ];
net/mac80211/ibss.c +5 -4
@@ -57,7 +57,7 @@ static void ieee80211_rx_mgmt_auth_ibss(*/ if (auth_alg ==WLAN_AUTH_OPEN && auth_transaction ==1 )ieee80211_send_auth (sdata,2 ,WLAN_AUTH_OPEN ,NULL ,0 , - sdata->u.ibss.bssid,0 ); + sdata->u.ibss.bssid,NULL ,0 ,0 ); } static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
@@ -494,7 +494,7 @@ static void ieee80211_sta_create_ibss(st capability =WLAN_CAPABILITY_IBSS ; -if (sdata->default_key) +if (ifibss->privacy) capability |=WLAN_CAPABILITY_PRIVACY ;else sdata->drop_unencrypted =0 ;
@@ -524,9 +524,8 @@ static void ieee80211_sta_find_ibss(strureturn ; capability =WLAN_CAPABILITY_IBSS ; -if (sdata->default_key) +if (ifibss->privacy) capability |=WLAN_CAPABILITY_PRIVACY ; -if (ifibss->fixed_bssid) bssid = ifibss->bssid;if (ifibss->fixed_channel)
@@ -872,6 +871,8 @@ int ieee80211_ibss_join(struct ieee80211 }else sdata->u.ibss.fixed_bssid = false; + sdata->u.ibss.privacy = params->privacy; + sdata->vif.bss_conf.beacon_int = params->beacon_interval; sdata->u.ibss.channel = params->channel;
net/mac80211/util.c +11 -5
@@ -31,6 +31,7 @@#include "mesh.h" #include "wme.h" #include "led.h" +#include "wep.h" /* privid for wiphys to determine whether they belong to us or not */ void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
@@ -778,12 +779,13 @@ u32 ieee80211_mandatory_rates(struct ieevoid ieee80211_send_auth (struct ieee80211_sub_if_data *sdata,u16 transaction,u16 auth_alg, -u8 *extra,size_t extra_len, -const u8 *bssid,int encrypt) +u8 *extra,size_t extra_len,const u8 *bssid, +const u8 *key,u8 key_len,u8 key_idx) {struct ieee80211_local *local = sdata->local;struct sk_buff *skb;struct ieee80211_mgmt *mgmt; +int err; skb =dev_alloc_skb (local->hw.extra_tx_headroom +sizeof (*mgmt) +6 + extra_len);
@@ -798,8 +800,6 @@ void ieee80211_send_auth(struct ieee8021memset (mgmt,0 ,24 +6 ); mgmt->frame_control =cpu_to_le16 (IEEE80211_FTYPE_MGMT |IEEE80211_STYPE_AUTH ); -if (encrypt) - mgmt->frame_control |=cpu_to_le16 (IEEE80211_FCTL_PROTECTED );memcpy (mgmt->da, bssid,ETH_ALEN );memcpy (mgmt->sa, sdata->dev->dev_addr,ETH_ALEN );memcpy (mgmt->bssid, bssid,ETH_ALEN );
@@ -809,7 +809,13 @@ void ieee80211_send_auth(struct ieee8021if (extra)memcpy (skb_put (skb, extra_len), extra, extra_len); -ieee80211_tx_skb (sdata, skb, encrypt); +if (auth_alg ==WLAN_AUTH_SHARED_KEY && transaction ==3 ) { + mgmt->frame_control |=cpu_to_le16 (IEEE80211_FCTL_PROTECTED ); + err =ieee80211_wep_encrypt (local, skb, key, key_len, key_idx); +WARN_ON (err); + } + +ieee80211_tx_skb (sdata, skb,0 ); } int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
net/mac80211/wep.c +3 -3
@@ -144,9 +144,9 @@ void ieee80211_wep_encrypt_data(struct c* * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data)) */ -static int ieee80211_wep_encrypt (struct ieee80211_local *local, -struct sk_buff *skb, -const u8 *key,int keylen,int keyidx) +int ieee80211_wep_encrypt (struct ieee80211_local *local, +struct sk_buff *skb, +const u8 *key,int keylen,int keyidx) {u8 *iv;size_t len;
net/mac80211/wep.h +3 -0
@@ -20,6 +20,9 @@ int ieee80211_wep_init(struct ieee80211_void ieee80211_wep_free (struct ieee80211_local *local);void ieee80211_wep_encrypt_data (struct crypto_blkcipher *tfm,u8 *rc4key,size_t klen,u8 *data,size_t data_len); +int ieee80211_wep_encrypt (struct ieee80211_local *local, +struct sk_buff *skb, +const u8 *key,int keylen,int keyidx);int ieee80211_wep_decrypt_data (struct crypto_blkcipher *tfm,u8 *rc4key,size_t klen,u8 *data,size_t data_len);bool ieee80211_wep_is_weak_iv (struct sk_buff *skb,struct ieee80211_key *key);
net/wireless/ibss.c +66 -13
154 lines not on this page · raw message
net/wireless/util.c +40 -1
58 lines not on this page · raw message
Johannes Berg
maintainerPATCH v2 1/1 cfg80211: rework key operation
This reworks the key operation in cfg80211, and now only allows, from userspace, configuring keys (via nl80211) after the connection has been established (in managed mode), the IBSS been joined (in IBSS mode), at any time (in AP[_VLAN] modes) or never for all the other modes.
In order to do shared key authentication correctly, it is now possible to give a WEP key to the AUTH command. To configure static WEP keys, these are given to the CONNECT or IBSS_JOIN command directly, for a userspace SME it is assumed it will configure it properly after the connection has been established.
Since mac80211 used to check the default key in IBSS mode to see whether or not the network is protected, it needs an update in that area, as well as an update to make use of the WEP key passed to auth() for shared key authentication.
---
v2: add #ifdef ability
include/linux/nl80211.h | 5 + include/net/cfg80211.h | 18 ++++ net/mac80211/ibss.c | 9 +- net/mac80211/ieee80211_i.h | 8 +- net/mac80211/mlme.c | 11 ++ net/mac80211/util.c | 16 ++-- net/mac80211/wep.c | 6 - net/mac80211/wep.h | 3 net/wireless/core.c | 11 +- net/wireless/core.h | 32 ++++++-- net/wireless/ibss.c | 79 +++++++++++++++++--- net/wireless/mlme.c | 16 +++- net/wireless/nl80211.c | 170 +++++++++++++++++++++++++++++++++++++++------ net/wireless/sme.c | 97 ++++++++++++++++++------- net/wireless/util.c | 41 ++++++++++ net/wireless/wext-compat.c | 167 +++++++++++++++++++++++++++----------------- net/wireless/wext-sme.c | 30 ++++++- 17 files changed, 556 insertions(+), 163 deletions(-)
include/linux/nl80211.h +5 -0
@@ -576,6 +576,9 @@ enum nl80211_commands {* * @NL80211_ATTR_KEY: key information in a nested attribute with * %NL80211_KEY_* sub-attributes +* @NL80211_ATTR_KEYS: array of keys for static WEP keys for connect() +* and join_ibss(), key information is in a nested attribute each +* with %NL80211_KEY_* sub-attributes * * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use
@@ -705,6 +708,7 @@ enum nl80211_attrs {NL80211_ATTR_PID ,NL80211_ATTR_KEY , + NL80211_ATTR_KEYS,/* add attributes here, update the policy in nl80211.c */
@@ -735,6 +739,7 @@ enum nl80211_attrs {#define NL80211_ATTR_WPA_VERSIONS NL80211_ATTR_WPA_VERSIONS#define NL80211_ATTR_AKM_SUITES NL80211_ATTR_AKM_SUITES#define NL80211_ATTR_KEY NL80211_ATTR_KEY +#define NL80211_ATTR_KEYS NL80211_ATTR_KEYS#define NL80211_MAX_SUPP_RATES 32#define NL80211_MAX_SUPP_REG_RULES 32
net/wireless/nl80211.c +151 -19
283 lines not on this page · raw message
net/wireless/wext-compat.c +103 -64
241 lines not on this page · raw message
include/net/cfg80211.h +17 -1
@@ -647,12 +647,17 @@ struct cfg80211_crypto_settings {* @auth_type: Authentication type (algorithm) * @ie: Extra IEs to add to Authentication frame or %NULL * @ie_len: Length of ie buffer in octets +* @key_len: length of WEP key for shared key authentication +* @key_idx: index of WEP key for shared key authentication +* @key: WEP key for shared key authentication */ struct cfg80211_auth_request {struct cfg80211_bss *bss;const u8 *ie;size_t ie_len;enum nl80211_auth_type auth_type; +const u8 *key; +u8 key_len, key_idx; };/**
@@ -727,6 +732,8 @@ struct cfg80211_disassoc_request {* @ie: information element(s) to include in the beacon * @ie_len: length of that * @beacon_interval: beacon interval to use +* @privacy: this is a protected network, keys will be configured +* after joining */ struct cfg80211_ibss_params {u8 *ssid;
@@ -736,6 +743,7 @@ struct cfg80211_ibss_params {u8 ssid_len, ie_len;u16 beacon_interval;bool channel_fixed; +bool privacy; };/**
@@ -755,6 +763,9 @@ struct cfg80211_ibss_params {* @assoc_ie_len: Length of assoc_ie in octets * @privacy: indicates whether privacy-enabled APs should be used * @crypto: crypto settings +* @key_len: length of WEP key for shared key authentication +* @key_idx: index of WEP key for shared key authentication +* @key: WEP key for shared key authentication */ struct cfg80211_connect_params {struct ieee80211_channel *channel;
@@ -766,6 +777,8 @@ struct cfg80211_connect_params {size_t ie_len;bool privacy;struct cfg80211_crypto_settings crypto; +const u8 *key; +u8 key_len, key_idx; };/**
@@ -1255,9 +1268,10 @@ extern void wiphy_unregister(struct wiph*/ extern void wiphy_free (struct wiphy *wiphy); -/* internal struct */ +/* internal structs */ struct cfg80211_conn ;struct cfg80211_internal_bss ; +struct cfg80211_cached_keys ;#define MAX_AUTH_BSSES 4
@@ -1299,6 +1313,7 @@ struct wireless_dev {CFG80211_SME_CONNECTED , } sme_state;struct cfg80211_conn *conn; +struct cfg80211_cached_keys *connect_keys;struct list_head event_list;spinlock_t event_lock;
@@ -1312,6 +1327,7 @@ struct wireless_dev {struct {struct cfg80211_ibss_params ibss;struct cfg80211_connect_params connect; +struct cfg80211_cached_keys *keys;u8 *ie;size_t ie_len;u8 bssid[ETH_ALEN ];
net/wireless/core.h +25 -7
@@ -241,6 +241,12 @@ struct cfg80211_event { }; }; +struct cfg80211_cached_keys { +struct key_params params[6 ]; +u8 data[6 ][WLAN_MAX_KEY_LEN ]; +int def, defmgmt; +}; +/* free object */ extern void cfg80211_dev_free (struct cfg80211_registered_device *rdev);
@@ -259,14 +265,18 @@ void cfg80211_bss_age(struct cfg80211_re/* IBSS */ int __cfg80211_join_ibss (struct cfg80211_registered_device *rdev,struct net_device *dev, -struct cfg80211_ibss_params *params); +struct cfg80211_ibss_params *params, +struct cfg80211_cached_keys *connkeys);int cfg80211_join_ibss (struct cfg80211_registered_device *rdev,struct net_device *dev, -struct cfg80211_ibss_params *params); +struct cfg80211_ibss_params *params, +struct cfg80211_cached_keys *connkeys);void cfg80211_clear_ibss (struct net_device *dev,bool nowext);int cfg80211_leave_ibss (struct cfg80211_registered_device *rdev,struct net_device *dev,bool nowext);void __cfg80211_ibss_joined (struct net_device *dev,const u8 *bssid); +int cfg80211_ibss_wext_join (struct cfg80211_registered_device *rdev, +struct wireless_dev *wdev);/* MLME */ int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
@@ -275,12 +285,14 @@ int __cfg80211_mlme_auth(struct cfg80211enum nl80211_auth_type auth_type, const u8 *bssid, const u8 *ssid, int ssid_len, - const u8 *ie, int ie_len); + const u8 *ie, int ie_len, + const u8 *key, int key_len, int key_idx);int cfg80211_mlme_auth (struct cfg80211_registered_device *rdev,struct net_device *dev,struct ieee80211_channel *chan,enum nl80211_auth_type auth_type,const u8 *bssid,const u8 *ssid,int ssid_len, -const u8 *ie,int ie_len); +const u8 *ie,int ie_len, +const u8 *key,int key_len,int key_idx); int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, struct net_device *dev, struct ieee80211_channel *chan,
@@ -313,10 +325,12 @@ void __cfg80211_connect_result(struct ne/* SME */ int __cfg80211_connect (struct cfg80211_registered_device *rdev,struct net_device *dev, -struct cfg80211_connect_params *connect); +struct cfg80211_connect_params *connect, +struct cfg80211_cached_keys *connkeys);int cfg80211_connect (struct cfg80211_registered_device *rdev,struct net_device *dev, -struct cfg80211_connect_params *connect); +struct cfg80211_connect_params *connect, +struct cfg80211_cached_keys *connkeys);int __cfg80211_disconnect (struct cfg80211_registered_device *rdev,struct net_device *dev,u16 reason,bool wextev);
@@ -326,11 +340,14 @@ int cfg80211_disconnect(struct cfg80211_void __cfg80211_roamed (struct wireless_dev *wdev,const u8 *bssid,const u8 *req_ie,size_t req_ie_len,const u8 *resp_ie,size_t resp_ie_len); +int cfg80211_mgd_wext_connect (struct cfg80211_registered_device *rdev, +struct wireless_dev *wdev);void cfg80211_conn_work (struct work_struct *work);/* internal helpers */ -int cfg80211_validate_key_settings (struct key_params *params,int key_idx, +int cfg80211_validate_key_settings (struct cfg80211_registered_device *rdev, +struct key_params *params,int key_idx,const u8 *mac_addr);void __cfg80211_disconnected (struct net_device *dev,const u8 *ie,size_t ie_len,u16 reason,bool from_ap);
@@ -338,5 +355,6 @@ void cfg80211_sme_scan_done(struct net_dvoid cfg80211_sme_rx_auth (struct net_device *dev,const u8 *buf,size_t len);void cfg80211_sme_disassoc (struct net_device *dev,int idx);void __cfg80211_scan_done (struct work_struct *wk); +void cfg80211_upload_connect_keys (struct wireless_dev *wdev);#endif /* __NET_WIRELESS_CORE_H */
net/wireless/core.c +5 -6
@@ -707,14 +707,10 @@ static int cfg80211_netdev_notifier_callwdev_lock (wdev);switch (wdev->iftype) {case NL80211_IFTYPE_ADHOC : -if (wdev->wext.ibss.ssid_len) -__cfg80211_join_ibss (rdev, dev, - &wdev->wext.ibss); +cfg80211_ibss_wext_join (rdev, wdev);break ;case NL80211_IFTYPE_STATION : -if (wdev->wext.connect.ssid_len) -__cfg80211_connect (rdev, dev, - &wdev->wext.connect); +cfg80211_mgd_wext_connect (rdev, wdev);break ;default :break ;
@@ -731,6 +727,9 @@ static int cfg80211_netdev_notifier_call }mutex_unlock (&rdev->devlist_mtx);mutex_destroy (&wdev->mtx); +#ifdef CONFIG_WIRELESS_EXT +kfree (wdev->wext.keys); +#endif break ;case NETDEV_PRE_UP :if (!(wdev->wiphy->interface_modes &BIT (wdev->iftype)))
net/wireless/sme.c +71 -26
184 lines not on this page · raw message
net/wireless/wext-sme.c +23 -7
@@ -10,10 +10,11 @@#include <net/cfg80211.h> #include "nl80211.h" -static int cfg80211_mgd_wext_connect (struct cfg80211_registered_device *rdev, -struct wireless_dev *wdev) +int cfg80211_mgd_wext_connect (struct cfg80211_registered_device *rdev, +struct wireless_dev *wdev) { -int err; +struct cfg80211_cached_keys *ck =NULL ; +int err, i;ASSERT_RDEV_LOCK (rdev);ASSERT_WDEV_LOCK (wdev);
@@ -25,10 +26,25 @@ static int cfg80211_mgd_wext_connect(str wdev->wext.connect.ie_len = wdev->wext.ie_len; wdev->wext.connect.privacy = wdev->wext.default_key !=-1 ; - err =0 ; -if (wdev->wext.connect.ssid_len !=0 ) - err =__cfg80211_connect (rdev, wdev->netdev, - &wdev->wext.connect); +if (wdev->wext.keys) { + wdev->wext.keys->def = wdev->wext.default_key; + wdev->wext.keys->defmgmt = wdev->wext.default_mgmt_key; + } + +if (!wdev->wext.connect.ssid_len) +return 0 ; + +if (wdev->wext.keys) { + ck =kmemdup (wdev->wext.keys,sizeof (*ck),GFP_KERNEL ); +if (!ck) +return -ENOMEM ; +for (i =0 ; i <6 ; i++) + ck->params[i].key = ck->data[i]; + } + err =__cfg80211_connect (rdev, wdev->netdev, + &wdev->wext.connect, ck); +if (err) +kfree (ck);return err; }
net/wireless/mlme.c +13 -3
@@ -328,7 +328,8 @@ int __cfg80211_mlme_auth(struct cfg80211enum nl80211_auth_type auth_type, const u8 *bssid, const u8 *ssid, int ssid_len, - const u8 *ie, int ie_len) + const u8 *ie, int ie_len, + const u8 *key, int key_len, int key_idx) { struct wireless_dev *wdev = dev->ieee80211_ptr;struct cfg80211_auth_request req;
@@ -337,6 +338,10 @@ int __cfg80211_mlme_auth(struct cfg80211ASSERT_WDEV_LOCK (wdev); +if (auth_type ==NL80211_AUTHTYPE_SHARED_KEY ) +if (!key || !key_len || key_idx <0 || key_idx >4 ) +return -EINVAL ; +if (wdev->current_bss &&memcmp (bssid, wdev->current_bss->pub.bssid,ETH_ALEN ) ==0 )return -EALREADY ;
@@ -359,6 +364,9 @@ int __cfg80211_mlme_auth(struct cfg80211 req.auth_type = auth_type; req.bss =cfg80211_get_bss (&rdev->wiphy, chan, bssid, ssid, ssid_len,WLAN_CAPABILITY_ESS ,WLAN_CAPABILITY_ESS ); + req.key = key; + req.key_len = key_len; + req.key_idx = key_idx;if (!req.bss)return -ENOENT ;
@@ -396,13 +404,15 @@ int cfg80211_mlme_auth(struct cfg80211_r struct net_device *dev, struct ieee80211_channel *chan, enum nl80211_auth_type auth_type, const u8 *bssid, const u8 *ssid, int ssid_len, - const u8 *ie, int ie_len) + const u8 *ie, int ie_len, + const u8 *key, int key_len, int key_idx) { int err;wdev_lock (dev->ieee80211_ptr); err =__cfg80211_mlme_auth (rdev, dev, chan, auth_type, bssid, - ssid, ssid_len, ie, ie_len); + ssid, ssid_len, ie, ie_len, + key, key_len, key_idx);wdev_unlock (dev->ieee80211_ptr);return err;
net/mac80211/ieee80211_i.h +6 -2
@@ -247,6 +247,9 @@ struct ieee80211_mgd_work {int tries; +u8 key[WLAN_KEY_LEN_WEP104 ]; +u8 key_len, key_idx; +/* must be last */ u8 ie[0 ];/* for auth or assoc frame, not probe */ };
@@ -321,6 +324,7 @@ struct ieee80211_if_ibss {bool fixed_bssid;bool fixed_channel; +bool privacy;u8 bssid[ETH_ALEN ];u8 ssid[IEEE80211_MAX_SSID_LEN ];
@@ -1090,8 +1094,8 @@ int ieee80211_add_pending_skbs(struct ievoid ieee80211_send_auth (struct ieee80211_sub_if_data *sdata,u16 transaction,u16 auth_alg, -u8 *extra,size_t extra_len, -const u8 *bssid,int encrypt); +u8 *extra,size_t extra_len,const u8 *bssid, +const u8 *key,u8 key_len,u8 key_idx);int ieee80211_build_preq_ies (struct ieee80211_local *local,u8 *buffer,const u8 *ie,size_t ie_len); void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
net/mac80211/mlme.c +9 -2
@@ -954,7 +954,7 @@ ieee80211_authenticate(struct ieee80211_ sdata->dev->name, wk->bss->cbss.bssid, wk->tries);ieee80211_send_auth (sdata,1 , wk->auth_alg, wk->ie, wk->ie_len, - wk->bss->cbss.bssid,0 ); + wk->bss->cbss.bssid,NULL ,0 ,0 ); wk->auth_transaction =2 ; wk->timeout = jiffies +IEEE80211_AUTH_TIMEOUT ;
@@ -1176,7 +1176,8 @@ static void ieee80211_auth_challenge(strreturn ;ieee80211_send_auth (sdata,3 , wk->auth_alg, elems.challenge -2 , elems.challenge_len +2 , - wk->bss->cbss.bssid,1 ); + wk->bss->cbss.bssid, + wk->key, wk->key_len, wk->key_idx); wk->auth_transaction =4 ; }
@@ -2175,6 +2176,12 @@ int ieee80211_mgd_auth(struct ieee80211_ wk->ie_len = req->ie_len; } +if (req->key && req->key_len) { + wk->key_len = req->key_len; + wk->key_idx = req->key_idx; +memcpy (wk->key, req->key, req->key_len); + } + ssid =ieee80211_bss_get_ie (req->bss,WLAN_EID_SSID );memcpy (wk->ssid, ssid +2 , ssid[1 ]); wk->ssid_len = ssid[1 ];
net/mac80211/ibss.c +5 -4
@@ -57,7 +57,7 @@ static void ieee80211_rx_mgmt_auth_ibss(*/ if (auth_alg ==WLAN_AUTH_OPEN && auth_transaction ==1 )ieee80211_send_auth (sdata,2 ,WLAN_AUTH_OPEN ,NULL ,0 , - sdata->u.ibss.bssid,0 ); + sdata->u.ibss.bssid,NULL ,0 ,0 ); } static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
@@ -494,7 +494,7 @@ static void ieee80211_sta_create_ibss(st capability =WLAN_CAPABILITY_IBSS ; -if (sdata->default_key) +if (ifibss->privacy) capability |=WLAN_CAPABILITY_PRIVACY ;else sdata->drop_unencrypted =0 ;
@@ -524,9 +524,8 @@ static void ieee80211_sta_find_ibss(strureturn ; capability =WLAN_CAPABILITY_IBSS ; -if (sdata->default_key) +if (ifibss->privacy) capability |=WLAN_CAPABILITY_PRIVACY ; -if (ifibss->fixed_bssid) bssid = ifibss->bssid;if (ifibss->fixed_channel)
@@ -872,6 +871,8 @@ int ieee80211_ibss_join(struct ieee80211 }else sdata->u.ibss.fixed_bssid = false; + sdata->u.ibss.privacy = params->privacy; + sdata->vif.bss_conf.beacon_int = params->beacon_interval; sdata->u.ibss.channel = params->channel;
net/mac80211/util.c +11 -5
@@ -31,6 +31,7 @@#include "mesh.h" #include "wme.h" #include "led.h" +#include "wep.h" /* privid for wiphys to determine whether they belong to us or not */ void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
@@ -778,12 +779,13 @@ u32 ieee80211_mandatory_rates(struct ieevoid ieee80211_send_auth (struct ieee80211_sub_if_data *sdata,u16 transaction,u16 auth_alg, -u8 *extra,size_t extra_len, -const u8 *bssid,int encrypt) +u8 *extra,size_t extra_len,const u8 *bssid, +const u8 *key,u8 key_len,u8 key_idx) {struct ieee80211_local *local = sdata->local;struct sk_buff *skb;struct ieee80211_mgmt *mgmt; +int err; skb =dev_alloc_skb (local->hw.extra_tx_headroom +sizeof (*mgmt) +6 + extra_len);
@@ -798,8 +800,6 @@ void ieee80211_send_auth(struct ieee8021memset (mgmt,0 ,24 +6 ); mgmt->frame_control =cpu_to_le16 (IEEE80211_FTYPE_MGMT |IEEE80211_STYPE_AUTH ); -if (encrypt) - mgmt->frame_control |=cpu_to_le16 (IEEE80211_FCTL_PROTECTED );memcpy (mgmt->da, bssid,ETH_ALEN );memcpy (mgmt->sa, sdata->dev->dev_addr,ETH_ALEN );memcpy (mgmt->bssid, bssid,ETH_ALEN );
@@ -809,7 +809,13 @@ void ieee80211_send_auth(struct ieee8021if (extra)memcpy (skb_put (skb, extra_len), extra, extra_len); -ieee80211_tx_skb (sdata, skb, encrypt); +if (auth_alg ==WLAN_AUTH_SHARED_KEY && transaction ==3 ) { + mgmt->frame_control |=cpu_to_le16 (IEEE80211_FCTL_PROTECTED ); + err =ieee80211_wep_encrypt (local, skb, key, key_len, key_idx); +WARN_ON (err); + } + +ieee80211_tx_skb (sdata, skb,0 ); } int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
net/mac80211/wep.c +3 -3
@@ -144,9 +144,9 @@ void ieee80211_wep_encrypt_data(struct c* * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data)) */ -static int ieee80211_wep_encrypt (struct ieee80211_local *local, -struct sk_buff *skb, -const u8 *key,int keylen,int keyidx) +int ieee80211_wep_encrypt (struct ieee80211_local *local, +struct sk_buff *skb, +const u8 *key,int keylen,int keyidx) {u8 *iv;size_t len;
net/mac80211/wep.h +3 -0
@@ -20,6 +20,9 @@ int ieee80211_wep_init(struct ieee80211_void ieee80211_wep_free (struct ieee80211_local *local);void ieee80211_wep_encrypt_data (struct crypto_blkcipher *tfm,u8 *rc4key,size_t klen,u8 *data,size_t data_len); +int ieee80211_wep_encrypt (struct ieee80211_local *local, +struct sk_buff *skb, +const u8 *key,int keylen,int keyidx);int ieee80211_wep_decrypt_data (struct crypto_blkcipher *tfm,u8 *rc4key,size_t klen,u8 *data,size_t data_len);bool ieee80211_wep_is_weak_iv (struct sk_buff *skb,struct ieee80211_key *key);
net/wireless/ibss.c +66 -13
154 lines not on this page · raw message
net/wireless/util.c +40 -1
58 lines not on this page · raw message
Johannes Berg
maintainerPATCH v3 1/1 cfg80211: rework key operation
This reworks the key operation in cfg80211, and now only allows, from userspace, configuring keys (via nl80211) after the connection has been established (in managed mode), the IBSS been joined (in IBSS mode), at any time (in AP[_VLAN] modes) or never for all the other modes.
In order to do shared key authentication correctly, it is now possible to give a WEP key to the AUTH command. To configure static WEP keys, these are given to the CONNECT or IBSS_JOIN command directly, for a userspace SME it is assumed it will configure it properly after the connection has been established.
Since mac80211 used to check the default key in IBSS mode to see whether or not the network is protected, it needs an update in that area, as well as an update to make use of the WEP key passed to auth() for shared key authentication.
---
v3: rebase to correct tree (w/o netns work)
include/linux/nl80211.h | 5 + include/net/cfg80211.h | 18 ++++ net/mac80211/ibss.c | 9 +- net/mac80211/ieee80211_i.h | 8 +- net/mac80211/mlme.c | 11 ++ net/mac80211/util.c | 16 ++-- net/mac80211/wep.c | 6 - net/mac80211/wep.h | 3 net/wireless/core.c | 11 +- net/wireless/core.h | 32 ++++++-- net/wireless/ibss.c | 79 +++++++++++++++++--- net/wireless/mlme.c | 16 +++- net/wireless/nl80211.c | 170 +++++++++++++++++++++++++++++++++++++++------ net/wireless/sme.c | 97 ++++++++++++++++++------- net/wireless/util.c | 41 ++++++++++ net/wireless/wext-compat.c | 167 +++++++++++++++++++++++++++----------------- net/wireless/wext-sme.c | 30 ++++++- 17 files changed, 556 insertions(+), 163 deletions(-)
include/linux/nl80211.h +5 -0
@@ -569,6 +569,9 @@ enum nl80211_commands {* * @NL80211_ATTR_KEY: key information in a nested attribute with * %NL80211_KEY_* sub-attributes +* @NL80211_ATTR_KEYS: array of keys for static WEP keys for connect() +* and join_ibss(), key information is in a nested attribute each +* with %NL80211_KEY_* sub-attributes * * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use
@@ -696,6 +699,7 @@ enum nl80211_attrs {NL80211_ATTR_PREV_BSSID ,NL80211_ATTR_KEY , + NL80211_ATTR_KEYS,/* add attributes here, update the policy in nl80211.c */
@@ -726,6 +730,7 @@ enum nl80211_attrs {#define NL80211_ATTR_WPA_VERSIONS NL80211_ATTR_WPA_VERSIONS#define NL80211_ATTR_AKM_SUITES NL80211_ATTR_AKM_SUITES#define NL80211_ATTR_KEY NL80211_ATTR_KEY +#define NL80211_ATTR_KEYS NL80211_ATTR_KEYS#define NL80211_MAX_SUPP_RATES 32#define NL80211_MAX_SUPP_REG_RULES 32
net/wireless/nl80211.c +151 -19
283 lines not on this page · raw message
net/wireless/wext-compat.c +103 -64
241 lines not on this page · raw message
include/net/cfg80211.h +17 -1
@@ -647,12 +647,17 @@ struct cfg80211_crypto_settings {* @auth_type: Authentication type (algorithm) * @ie: Extra IEs to add to Authentication frame or %NULL * @ie_len: Length of ie buffer in octets +* @key_len: length of WEP key for shared key authentication +* @key_idx: index of WEP key for shared key authentication +* @key: WEP key for shared key authentication */ struct cfg80211_auth_request {struct cfg80211_bss *bss;const u8 *ie;size_t ie_len;enum nl80211_auth_type auth_type; +const u8 *key; +u8 key_len, key_idx; };/**
@@ -727,6 +732,8 @@ struct cfg80211_disassoc_request {* @ie: information element(s) to include in the beacon * @ie_len: length of that * @beacon_interval: beacon interval to use +* @privacy: this is a protected network, keys will be configured +* after joining */ struct cfg80211_ibss_params {u8 *ssid;
@@ -736,6 +743,7 @@ struct cfg80211_ibss_params {u8 ssid_len, ie_len;u16 beacon_interval;bool channel_fixed; +bool privacy; };/**
@@ -755,6 +763,9 @@ struct cfg80211_ibss_params {* @assoc_ie_len: Length of assoc_ie in octets * @privacy: indicates whether privacy-enabled APs should be used * @crypto: crypto settings +* @key_len: length of WEP key for shared key authentication +* @key_idx: index of WEP key for shared key authentication +* @key: WEP key for shared key authentication */ struct cfg80211_connect_params {struct ieee80211_channel *channel;
@@ -766,6 +777,8 @@ struct cfg80211_connect_params {size_t ie_len;bool privacy;struct cfg80211_crypto_settings crypto; +const u8 *key; +u8 key_len, key_idx; };/**
@@ -1223,9 +1236,10 @@ extern void wiphy_unregister(struct wiph*/ extern void wiphy_free (struct wiphy *wiphy); -/* internal struct */ +/* internal structs */ struct cfg80211_conn ;struct cfg80211_internal_bss ; +struct cfg80211_cached_keys ;#define MAX_AUTH_BSSES 4
@@ -1267,6 +1281,7 @@ struct wireless_dev {CFG80211_SME_CONNECTED , } sme_state;struct cfg80211_conn *conn; +struct cfg80211_cached_keys *connect_keys;struct list_head event_list;spinlock_t event_lock;
@@ -1280,6 +1295,7 @@ struct wireless_dev {struct {struct cfg80211_ibss_params ibss;struct cfg80211_connect_params connect; +struct cfg80211_cached_keys *keys;u8 *ie;size_t ie_len;u8 bssid[ETH_ALEN ];
net/wireless/core.h +25 -7
@@ -238,6 +238,12 @@ struct cfg80211_event { }; }; +struct cfg80211_cached_keys { +struct key_params params[6 ]; +u8 data[6 ][WLAN_MAX_KEY_LEN ]; +int def, defmgmt; +}; +/* free object */ extern void cfg80211_dev_free (struct cfg80211_registered_device *rdev);
@@ -256,14 +262,18 @@ void cfg80211_bss_age(struct cfg80211_re/* IBSS */ int __cfg80211_join_ibss (struct cfg80211_registered_device *rdev,struct net_device *dev, -struct cfg80211_ibss_params *params); +struct cfg80211_ibss_params *params, +struct cfg80211_cached_keys *connkeys);int cfg80211_join_ibss (struct cfg80211_registered_device *rdev,struct net_device *dev, -struct cfg80211_ibss_params *params); +struct cfg80211_ibss_params *params, +struct cfg80211_cached_keys *connkeys);void cfg80211_clear_ibss (struct net_device *dev,bool nowext);int cfg80211_leave_ibss (struct cfg80211_registered_device *rdev,struct net_device *dev,bool nowext);void __cfg80211_ibss_joined (struct net_device *dev,const u8 *bssid); +int cfg80211_ibss_wext_join (struct cfg80211_registered_device *rdev, +struct wireless_dev *wdev);/* MLME */ int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
@@ -272,12 +282,14 @@ int __cfg80211_mlme_auth(struct cfg80211enum nl80211_auth_type auth_type, const u8 *bssid, const u8 *ssid, int ssid_len, - const u8 *ie, int ie_len); + const u8 *ie, int ie_len, + const u8 *key, int key_len, int key_idx);int cfg80211_mlme_auth (struct cfg80211_registered_device *rdev,struct net_device *dev,struct ieee80211_channel *chan,enum nl80211_auth_type auth_type,const u8 *bssid,const u8 *ssid,int ssid_len, -const u8 *ie,int ie_len); +const u8 *ie,int ie_len, +const u8 *key,int key_len,int key_idx); int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, struct net_device *dev, struct ieee80211_channel *chan,
@@ -310,10 +322,12 @@ void __cfg80211_connect_result(struct ne/* SME */ int __cfg80211_connect (struct cfg80211_registered_device *rdev,struct net_device *dev, -struct cfg80211_connect_params *connect); +struct cfg80211_connect_params *connect, +struct cfg80211_cached_keys *connkeys);int cfg80211_connect (struct cfg80211_registered_device *rdev,struct net_device *dev, -struct cfg80211_connect_params *connect); +struct cfg80211_connect_params *connect, +struct cfg80211_cached_keys *connkeys);int __cfg80211_disconnect (struct cfg80211_registered_device *rdev,struct net_device *dev,u16 reason,bool wextev);
@@ -323,11 +337,14 @@ int cfg80211_disconnect(struct cfg80211_void __cfg80211_roamed (struct wireless_dev *wdev,const u8 *bssid,const u8 *req_ie,size_t req_ie_len,const u8 *resp_ie,size_t resp_ie_len); +int cfg80211_mgd_wext_connect (struct cfg80211_registered_device *rdev, +struct wireless_dev *wdev);void cfg80211_conn_work (struct work_struct *work);/* internal helpers */ -int cfg80211_validate_key_settings (struct key_params *params,int key_idx, +int cfg80211_validate_key_settings (struct cfg80211_registered_device *rdev, +struct key_params *params,int key_idx,const u8 *mac_addr);void __cfg80211_disconnected (struct net_device *dev,const u8 *ie,size_t ie_len,u16 reason,bool from_ap);
@@ -335,5 +352,6 @@ void cfg80211_sme_scan_done(struct net_dvoid cfg80211_sme_rx_auth (struct net_device *dev,const u8 *buf,size_t len);void cfg80211_sme_disassoc (struct net_device *dev,int idx);void __cfg80211_scan_done (struct work_struct *wk); +void cfg80211_upload_connect_keys (struct wireless_dev *wdev);#endif /* __NET_WIRELESS_CORE_H */
net/wireless/core.c +5 -6
@@ -666,14 +666,10 @@ static int cfg80211_netdev_notifier_callwdev_lock (wdev);switch (wdev->iftype) {case NL80211_IFTYPE_ADHOC : -if (wdev->wext.ibss.ssid_len) -__cfg80211_join_ibss (rdev, dev, - &wdev->wext.ibss); +cfg80211_ibss_wext_join (rdev, wdev);break ;case NL80211_IFTYPE_STATION : -if (wdev->wext.connect.ssid_len) -__cfg80211_connect (rdev, dev, - &wdev->wext.connect); +cfg80211_mgd_wext_connect (rdev, wdev);break ;default :break ;
@@ -690,6 +686,9 @@ static int cfg80211_netdev_notifier_call }mutex_unlock (&rdev->devlist_mtx);mutex_destroy (&wdev->mtx); +#ifdef CONFIG_WIRELESS_EXT +kfree (wdev->wext.keys); +#endif break ;case NETDEV_PRE_UP :if (!(wdev->wiphy->interface_modes &BIT (wdev->iftype)))
net/wireless/sme.c +71 -26
184 lines not on this page · raw message
net/wireless/wext-sme.c +23 -7
@@ -10,10 +10,11 @@#include <net/cfg80211.h> #include "nl80211.h" -static int cfg80211_mgd_wext_connect (struct cfg80211_registered_device *rdev, -struct wireless_dev *wdev) +int cfg80211_mgd_wext_connect (struct cfg80211_registered_device *rdev, +struct wireless_dev *wdev) { -int err; +struct cfg80211_cached_keys *ck =NULL ; +int err, i;ASSERT_RDEV_LOCK (rdev);ASSERT_WDEV_LOCK (wdev);
@@ -25,10 +26,25 @@ static int cfg80211_mgd_wext_connect(str wdev->wext.connect.ie_len = wdev->wext.ie_len; wdev->wext.connect.privacy = wdev->wext.default_key !=-1 ; - err =0 ; -if (wdev->wext.connect.ssid_len !=0 ) - err =__cfg80211_connect (rdev, wdev->netdev, - &wdev->wext.connect); +if (wdev->wext.keys) { + wdev->wext.keys->def = wdev->wext.default_key; + wdev->wext.keys->defmgmt = wdev->wext.default_mgmt_key; + } + +if (!wdev->wext.connect.ssid_len) +return 0 ; + +if (wdev->wext.keys) { + ck =kmemdup (wdev->wext.keys,sizeof (*ck),GFP_KERNEL ); +if (!ck) +return -ENOMEM ; +for (i =0 ; i <6 ; i++) + ck->params[i].key = ck->data[i]; + } + err =__cfg80211_connect (rdev, wdev->netdev, + &wdev->wext.connect, ck); +if (err) +kfree (ck);return err; }
net/wireless/mlme.c +13 -3
@@ -328,7 +328,8 @@ int __cfg80211_mlme_auth(struct cfg80211enum nl80211_auth_type auth_type, const u8 *bssid, const u8 *ssid, int ssid_len, - const u8 *ie, int ie_len) + const u8 *ie, int ie_len, + const u8 *key, int key_len, int key_idx) { struct wireless_dev *wdev = dev->ieee80211_ptr;struct cfg80211_auth_request req;
@@ -337,6 +338,10 @@ int __cfg80211_mlme_auth(struct cfg80211ASSERT_WDEV_LOCK (wdev); +if (auth_type ==NL80211_AUTHTYPE_SHARED_KEY ) +if (!key || !key_len || key_idx <0 || key_idx >4 ) +return -EINVAL ; +if (wdev->current_bss &&memcmp (bssid, wdev->current_bss->pub.bssid,ETH_ALEN ) ==0 )return -EALREADY ;
@@ -359,6 +364,9 @@ int __cfg80211_mlme_auth(struct cfg80211 req.auth_type = auth_type; req.bss =cfg80211_get_bss (&rdev->wiphy, chan, bssid, ssid, ssid_len,WLAN_CAPABILITY_ESS ,WLAN_CAPABILITY_ESS ); + req.key = key; + req.key_len = key_len; + req.key_idx = key_idx;if (!req.bss)return -ENOENT ;
@@ -396,13 +404,15 @@ int cfg80211_mlme_auth(struct cfg80211_r struct net_device *dev, struct ieee80211_channel *chan, enum nl80211_auth_type auth_type, const u8 *bssid, const u8 *ssid, int ssid_len, - const u8 *ie, int ie_len) + const u8 *ie, int ie_len, + const u8 *key, int key_len, int key_idx) { int err;wdev_lock (dev->ieee80211_ptr); err =__cfg80211_mlme_auth (rdev, dev, chan, auth_type, bssid, - ssid, ssid_len, ie, ie_len); + ssid, ssid_len, ie, ie_len, + key, key_len, key_idx);wdev_unlock (dev->ieee80211_ptr);return err;
net/mac80211/ieee80211_i.h +6 -2
@@ -247,6 +247,9 @@ struct ieee80211_mgd_work {int tries; +u8 key[WLAN_KEY_LEN_WEP104 ]; +u8 key_len, key_idx; +/* must be last */ u8 ie[0 ];/* for auth or assoc frame, not probe */ };
@@ -321,6 +324,7 @@ struct ieee80211_if_ibss {bool fixed_bssid;bool fixed_channel; +bool privacy;u8 bssid[ETH_ALEN ];u8 ssid[IEEE80211_MAX_SSID_LEN ];
@@ -1090,8 +1094,8 @@ int ieee80211_add_pending_skbs(struct ievoid ieee80211_send_auth (struct ieee80211_sub_if_data *sdata,u16 transaction,u16 auth_alg, -u8 *extra,size_t extra_len, -const u8 *bssid,int encrypt); +u8 *extra,size_t extra_len,const u8 *bssid, +const u8 *key,u8 key_len,u8 key_idx);int ieee80211_build_preq_ies (struct ieee80211_local *local,u8 *buffer,const u8 *ie,size_t ie_len); void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
net/mac80211/mlme.c +9 -2
@@ -954,7 +954,7 @@ ieee80211_authenticate(struct ieee80211_ sdata->dev->name, wk->bss->cbss.bssid, wk->tries);ieee80211_send_auth (sdata,1 , wk->auth_alg, wk->ie, wk->ie_len, - wk->bss->cbss.bssid,0 ); + wk->bss->cbss.bssid,NULL ,0 ,0 ); wk->auth_transaction =2 ; wk->timeout = jiffies +IEEE80211_AUTH_TIMEOUT ;
@@ -1176,7 +1176,8 @@ static void ieee80211_auth_challenge(strreturn ;ieee80211_send_auth (sdata,3 , wk->auth_alg, elems.challenge -2 , elems.challenge_len +2 , - wk->bss->cbss.bssid,1 ); + wk->bss->cbss.bssid, + wk->key, wk->key_len, wk->key_idx); wk->auth_transaction =4 ; }
@@ -2175,6 +2176,12 @@ int ieee80211_mgd_auth(struct ieee80211_ wk->ie_len = req->ie_len; } +if (req->key && req->key_len) { + wk->key_len = req->key_len; + wk->key_idx = req->key_idx; +memcpy (wk->key, req->key, req->key_len); + } + ssid =ieee80211_bss_get_ie (req->bss,WLAN_EID_SSID );memcpy (wk->ssid, ssid +2 , ssid[1 ]); wk->ssid_len = ssid[1 ];
net/mac80211/ibss.c +5 -4
@@ -57,7 +57,7 @@ static void ieee80211_rx_mgmt_auth_ibss(*/ if (auth_alg ==WLAN_AUTH_OPEN && auth_transaction ==1 )ieee80211_send_auth (sdata,2 ,WLAN_AUTH_OPEN ,NULL ,0 , - sdata->u.ibss.bssid,0 ); + sdata->u.ibss.bssid,NULL ,0 ,0 ); } static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
@@ -494,7 +494,7 @@ static void ieee80211_sta_create_ibss(st capability =WLAN_CAPABILITY_IBSS ; -if (sdata->default_key) +if (ifibss->privacy) capability |=WLAN_CAPABILITY_PRIVACY ;else sdata->drop_unencrypted =0 ;
@@ -524,9 +524,8 @@ static void ieee80211_sta_find_ibss(strureturn ; capability =WLAN_CAPABILITY_IBSS ; -if (sdata->default_key) +if (ifibss->privacy) capability |=WLAN_CAPABILITY_PRIVACY ; -if (ifibss->fixed_bssid) bssid = ifibss->bssid;if (ifibss->fixed_channel)
@@ -872,6 +871,8 @@ int ieee80211_ibss_join(struct ieee80211 }else sdata->u.ibss.fixed_bssid = false; + sdata->u.ibss.privacy = params->privacy; + sdata->vif.bss_conf.beacon_int = params->beacon_interval; sdata->u.ibss.channel = params->channel;
net/mac80211/util.c +11 -5
@@ -31,6 +31,7 @@#include "mesh.h" #include "wme.h" #include "led.h" +#include "wep.h" /* privid for wiphys to determine whether they belong to us or not */ void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
@@ -778,12 +779,13 @@ u32 ieee80211_mandatory_rates(struct ieevoid ieee80211_send_auth (struct ieee80211_sub_if_data *sdata,u16 transaction,u16 auth_alg, -u8 *extra,size_t extra_len, -const u8 *bssid,int encrypt) +u8 *extra,size_t extra_len,const u8 *bssid, +const u8 *key,u8 key_len,u8 key_idx) {struct ieee80211_local *local = sdata->local;struct sk_buff *skb;struct ieee80211_mgmt *mgmt; +int err; skb =dev_alloc_skb (local->hw.extra_tx_headroom +sizeof (*mgmt) +6 + extra_len);
@@ -798,8 +800,6 @@ void ieee80211_send_auth(struct ieee8021memset (mgmt,0 ,24 +6 ); mgmt->frame_control =cpu_to_le16 (IEEE80211_FTYPE_MGMT |IEEE80211_STYPE_AUTH ); -if (encrypt) - mgmt->frame_control |=cpu_to_le16 (IEEE80211_FCTL_PROTECTED );memcpy (mgmt->da, bssid,ETH_ALEN );memcpy (mgmt->sa, sdata->dev->dev_addr,ETH_ALEN );memcpy (mgmt->bssid, bssid,ETH_ALEN );
@@ -809,7 +809,13 @@ void ieee80211_send_auth(struct ieee8021if (extra)memcpy (skb_put (skb, extra_len), extra, extra_len); -ieee80211_tx_skb (sdata, skb, encrypt); +if (auth_alg ==WLAN_AUTH_SHARED_KEY && transaction ==3 ) { + mgmt->frame_control |=cpu_to_le16 (IEEE80211_FCTL_PROTECTED ); + err =ieee80211_wep_encrypt (local, skb, key, key_len, key_idx); +WARN_ON (err); + } + +ieee80211_tx_skb (sdata, skb,0 ); } int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
net/mac80211/wep.c +3 -3
@@ -144,9 +144,9 @@ void ieee80211_wep_encrypt_data(struct c* * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data)) */ -static int ieee80211_wep_encrypt (struct ieee80211_local *local, -struct sk_buff *skb, -const u8 *key,int keylen,int keyidx) +int ieee80211_wep_encrypt (struct ieee80211_local *local, +struct sk_buff *skb, +const u8 *key,int keylen,int keyidx) {u8 *iv;size_t len;
net/mac80211/wep.h +3 -0
@@ -20,6 +20,9 @@ int ieee80211_wep_init(struct ieee80211_void ieee80211_wep_free (struct ieee80211_local *local);void ieee80211_wep_encrypt_data (struct crypto_blkcipher *tfm,u8 *rc4key,size_t klen,u8 *data,size_t data_len); +int ieee80211_wep_encrypt (struct ieee80211_local *local, +struct sk_buff *skb, +const u8 *key,int keylen,int keyidx);int ieee80211_wep_decrypt_data (struct crypto_blkcipher *tfm,u8 *rc4key,size_t klen,u8 *data,size_t data_len);bool ieee80211_wep_is_weak_iv (struct sk_buff *skb,struct ieee80211_key *key);
net/wireless/ibss.c +66 -13
154 lines not on this page · raw message
net/wireless/util.c +40 -1
58 lines not on this page · raw message
Quoted 6 lines · Johannes Berg
This reworks the key operation in cfg80211, and now only allows, from userspace, configuring keys (via nl80211) after the connection has been established (in managed mode), the IBSS been joined (in IBSS mode), at any time (in AP[_VLAN] modes) or never for all the other modes.
Quoted 6 lines
In order to do shared key authentication correctly, it is now possible to give a WEP key to the AUTH command. To configure static WEP keys, these are given to the CONNECT or
IBSS_JOINcommand directly, for a userspace SME it is assumed it will configure it properly after the connection has been established.
This breaks wireless-tools for WEP with fullmac cards because "iwconfig key" doesn't send the AUTH command. Is it expected?
Thanks,
-yi
Quoted 7 lines
Since mac80211 used to check the default key in IBSS mode to see whether or not the network is protected, it needs an update in that area, as well as an update to make use of the WEP key passed to
auth()for shared key authentication.Signed-off-by Johannes Berg <[email protected]>
Johannes Berg
maintainerQuoted 2 lines · Zhu Yi
This breaks wireless-tools for WEP with fullmac cards because "iwconfig key" doesn't send the AUTH command. Is it expected?
I did expect it to break iwm because I couldn't make sense of the iwm code, unfortunately, sorry about that. But the key needed for authentication should be being passed to the connect() call too.
johannes
Johannes Berg
maintainerQuoted 8 lines · Johannes Berg
Quoted 2 lines · Zhu Yi
This breaks wireless-tools for WEP with fullmac cards because "iwconfig key" doesn't send the AUTH command. Is it expected?
I did expect it to break iwm because I couldn't make sense of the iwm code, unfortunately, sorry about that. But the key needed for authentication should be being passed to the
connect()call too.
I should also note that you can now get rid of the stuff in iwm that caches the keys etc -- key callbacks will only be called after connecting.
As discussed with Samuel, there's a possibility to pass _all_ WEP keys directly to connect(), if desirable, instead of adding them with the key hooks later.
johannes
Quoted 3 lines · Johannes Berg
I should also note that you can now get rid of the stuff in iwm that caches the keys etc -- key callbacks will only be called after connecting.
Thanks. Patches are queued. Will send out later.
Quoted 3 lines
As discussed with Samuel, there's a possibility to pass _all_ WEP keys directly to
connect(), if desirable, instead of adding them with the key hooks later.
I think this should be the right way to go. Currently we have no way to connect to WEP APs (both open and shared) with iwconfig. Because the driver needs to set the correct cipher before connect. But the key callbacks are only called after connected... IWAUTH is expected to be the place to set the cipher here, but unfortunately iwconfig doesn't use it. Passing the WEP keys to connect() can solve this issue. The driver can at least parsing the connect parameters to set the correct cipher before connect.
Thanks,
-yi
Johannes Berg
maintainerQuoted 4 lines · Zhu Yi
Quoted 3 lines
As discussed with Samuel, there's a possibility to pass _all_ WEP keys directly to
connect(), if desirable, instead of adding them with the key hooks later.
Quoted 8 lines
I think this should be the right way to go. Currently we have no way to connect to WEP APs (both open and shared) with iwconfig. Because the driver needs to set the correct cipher before connect. But the key callbacks are only called after connected... IWAUTH is expected to be the place to set the cipher here, but unfortunately iwconfig doesn't use it. Passing the WEP keys to
connect()can solve this issue. The driver can at least parsing the connect parameters to set the correct cipher before connect.
We could also check the keys and pass the right cipher from cfg80211, in this case. Should be easy.
johannes