first step towards GTK rekey offload
Subsystems (2)
Johannes Berg
maintainercover first step towards GTK rekey offload
These patches are a first step to allow devices to implement GTK rekeying while suspended (or really at any time).
The key iteration (first patch) is necessary as we need to load a different firmware image, and I don't want to do double-bookkeeping (tracking all keys in the driver).
The second and third patch allow wpa_supplicant to give the necessary information to the driver to implement GTK rekeying.
Note that for iwlwifi this isn't yet sufficient as it also needs access to the CCMP PN/TKIP IVs to encrypt the GTK rekey reply frame correctly. However, I have only tested with CCMP so I'll submit those patches only when I've also tested TKIP.
johannes
Johannes Berg
maintainerPATCH 1/3 mac80211: allow driver to iterate keys
From: Johannes Berg <[email protected]>
When in suspend/wowlan, devices might implement crypto offload differently (more features), and might require reprogramming keys for the WoWLAN (as it is the case for Intel devices that use another uCode image). Thus allow the driver to iterate all keys in this context.
--- include/net/mac80211.h | 23 +++++++++++++++++++++++ net/mac80211/key.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+)
include/net/mac80211.h +23 -0
@@ -2850,6 +2850,29 @@ void ieee80211_sta_block_awake(struct ie struct ieee80211_sta *pubsta, bool block);/** +* ieee80211_iter_keys - iterate keys programmed into the device +* @hw: pointer obtained from ieee80211_alloc_hw() +* @vif: virtual interface to iterate, may be %NULL for all +* @iter: iterator function that will be called for each key +* @iter_data: custom data to pass to the iterator function +* +* This function can be used to iterate all the keys known to +* mac80211, even those that weren't previously programmed into +* the device. This is intended for use in WoWLAN if the device +* needs reprogramming of the keys during suspend. Note that due +* to locking reasons, it is also only safe to call this at few +* spots since it must hold the RTNL and be able to sleep. +*/ +void ieee80211_iter_keys (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +void (*iter)(struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct ieee80211_key_conf *key, +void *data), +void *iter_data); + +/** * ieee80211_ap_probereq_get - retrieve a Probe Request template * @hw: pointer obtained from ieee80211_alloc_hw(). * @vif: &struct ieee80211_vif pointer from the add_interface callback.
net/mac80211/key.c +33 -0
@@ -504,6 +504,39 @@ void ieee80211_enable_keys(struct ieee80mutex_unlock (&sdata->local->key_mtx); } +void ieee80211_iter_keys (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +void (*iter)(struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta, +struct ieee80211_key_conf *key, +void *data), +void *iter_data) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct ieee80211_key *key; +struct ieee80211_sub_if_data *sdata; + +ASSERT_RTNL (); + +mutex_lock (&local->key_mtx); +if (vif) { + sdata =vif_to_sdata (vif); +list_for_each_entry (key, &sdata->key_list, list) +iter (hw, &sdata->vif, + key->sta ? &key->sta->sta :NULL , + &key->conf, iter_data); + }else { +list_for_each_entry (sdata, &local->interfaces, list) +list_for_each_entry (key, &sdata->key_list, list) +iter (hw, &sdata->vif, + key->sta ? &key->sta->sta :NULL , + &key->conf, iter_data); + } +mutex_unlock (&local->key_mtx); +} +EXPORT_SYMBOL (ieee80211_iter_keys); +void ieee80211_disable_keys (struct ieee80211_sub_if_data *sdata) {struct ieee80211_key *key;
Johannes Berg
maintainerPATCH 2/3 cfg80211/nl80211: support GTK rekey offload
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
In certain circumstances, like WoWLAN scenarios, devices may implement (partial) GTK rekeying on the device to avoid waking up the host for it.
In order to successfully go through GTK rekeying, the KEK, KCK and the replay counter are required.
Add API to let the supplicant hand the parameters to the driver which may store it for future GTK rekey operations.
Note that, of course, if GTK rekeying is done by the device, the EAP frame must not be passed up to userspace, instead a rekey event needs to be sent to let userspace update its replay counter.
--- include/linux/nl80211.h | 39 ++++++++++++++++ include/net/cfg80211.h | 26 +++++++++++ net/wireless/mlme.c | 11 ++++ net/wireless/nl80211.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ net/wireless/nl80211.h | 4 + 5 files changed, 193 insertions(+)
include/linux/nl80211.h +39 -0
@@ -483,6 +483,14 @@* more background information, see * http://wireless.kernel.org/en/users/Documentation/WoWLAN. * +* @NL80211_CMD_SET_REKEY_OFFLOAD: This command is used give the driver +* the necessary information for supporting GTK rekey offload. This +* feature is typically used during WoWLAN. The configuration data +* is contained in %NL80211_ATTR_REKEY_DATA (which is nested and +* contains the data in sub-attributes). After rekeying happened, +* this command may also be sent by the driver as an MLME event to +* inform userspace of the new replay counter. +* * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use */
@@ -605,6 +613,8 @@ enum nl80211_commands {NL80211_CMD_SCHED_SCAN_RESULTS ,NL80211_CMD_SCHED_SCAN_STOPPED , + NL80211_CMD_SET_REKEY_OFFLOAD, +/* add new commands above here */ /* used to define NL80211_CMD_MAX below */
@@ -996,6 +1006,9 @@ enum nl80211_commands {* are managed in software: interfaces of these types aren't subject to * any restrictions in their number or combinations. * +* @%NL80211_ATTR_REKEY_DATA: nested attribute containing the information +* necessary for GTK rekeying in the device, see &enum nl80211_rekey_data. +* * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use */
@@ -1194,6 +1207,8 @@ enum nl80211_attrs {NL80211_ATTR_INTERFACE_COMBINATIONS ,NL80211_ATTR_SOFTWARE_IFTYPES , +NL80211_ATTR_REKEY_DATA , +/* add attributes here, update the policy in nl80211.c */ __NL80211_ATTR_AFTER_LAST,
@@ -2361,4 +2376,28 @@ enum nl80211_plink_state {MAX_NL80211_PLINK_STATES =NUM_NL80211_PLINK_STATES -1 }; +#define NL80211_KCK_LEN 16 +#define NL80211_KEK_LEN 16 +#define NL80211_REPLAY_CTR_LEN 8 + +/** +* enum nl80211_rekey_data - attributes for GTK rekey offload +* @__NL80211_REKEY_DATA_INVALID: invalid number for nested attributes +* @NL80211_REKEY_DATA_KEK: key encryption key (binary) +* @NL80211_REKEY_DATA_KCK: key confirmation key (binary) +* @NL80211_REKEY_DATA_REPLAY_CTR: replay counter (binary) +* @NUM_NL80211_REKEY_DATA: number of rekey attributes (internal) +* @MAX_NL80211_REKEY_DATA: highest rekey attribute (internal) +*/ +enum nl80211_rekey_data { + __NL80211_REKEY_DATA_INVALID, +NL80211_REKEY_DATA_KEK , +NL80211_REKEY_DATA_KCK , +NL80211_REKEY_DATA_REPLAY_CTR , + +/* keep last */ +NUM_NL80211_REKEY_DATA , +MAX_NL80211_REKEY_DATA =NUM_NL80211_REKEY_DATA -1 +}; +#endif /* __LINUX_NL80211_H */
include/net/cfg80211.h +26 -0
@@ -1154,6 +1154,18 @@ struct cfg80211_wowlan { };/** +* struct cfg80211_gtk_rekey_data - rekey data +* @kek: key encryption key +* @kck: key confirmation key +* @replay_ctr: replay counter +*/ +struct cfg80211_gtk_rekey_data { +u8 kek[NL80211_KEK_LEN ]; +u8 kck[NL80211_KCK_LEN ]; +u8 replay_ctr[NL80211_REPLAY_CTR_LEN ]; +}; + +/** * struct cfg80211_ops - backend description for wireless configuration * * This struct is registered by fullmac card drivers and/or wireless stacks
@@ -1197,6 +1209,8 @@ struct cfg80211_wowlan {* * @set_default_mgmt_key: set the default management frame key on an interface * +* @set_rekey_data: give the data necessary for GTK rekeying to the driver +* * @add_beacon: Add a beacon with given parameters, @head, @interval * and @dtim_period will be valid, @tail is optional. * @set_beacon: Change the beacon parameters for an access point mode
@@ -1499,6 +1513,9 @@ struct cfg80211_ops {struct net_device *dev, struct cfg80211_sched_scan_request *request);int (*sched_scan_stop)(struct wiphy *wiphy,struct net_device *dev); + +int (*set_rekey_data)(struct wiphy *wiphy,struct net_device *dev, +struct cfg80211_gtk_rekey_data *data); };/*
@@ -3033,6 +3050,15 @@ void cfg80211_cqm_rssi_notify(struct netvoid cfg80211_cqm_pktloss_notify (struct net_device *dev,const u8 *peer,u32 num_packets,gfp_t gfp); +/** +* cfg80211_gtk_rekey_notify - notify userspace about driver rekeying +* @dev: network device +* @bssid: BSSID of AP (to avoid races) +* @replay_ctr: new replay counter +*/ +void cfg80211_gtk_rekey_notify (struct net_device *dev,const u8 *bssid, +const u8 *replay_ctr,gfp_t gfp); +/* Logging, debugging and troubleshooting/diagnostic helpers. */ /* wiphy_printk helpers, similar to dev_printk */
net/wireless/nl80211.c +113 -0
143 lines not on this page · raw message
net/wireless/mlme.c +11 -0
@@ -1084,3 +1084,14 @@ void cfg80211_cqm_pktloss_notify(structnl80211_send_cqm_pktloss_notify (rdev, dev, peer, num_packets, gfp); }EXPORT_SYMBOL (cfg80211_cqm_pktloss_notify); + +void cfg80211_gtk_rekey_notify (struct net_device *dev,const u8 *bssid, +const u8 *replay_ctr,gfp_t gfp) +{ +struct wireless_dev *wdev = dev->ieee80211_ptr; +struct wiphy *wiphy = wdev->wiphy; +struct cfg80211_registered_device *rdev =wiphy_to_dev (wiphy); + +nl80211_gtk_rekey_notify (rdev, dev, bssid, replay_ctr, gfp); +} +EXPORT_SYMBOL (cfg80211_gtk_rekey_notify);
net/wireless/nl80211.h +4 -0
@@ -109,4 +109,8 @@ nl80211_send_cqm_pktloss_notify(struct c struct net_device *netdev, const u8 *peer, u32 num_packets, gfp_t gfp); +void nl80211_gtk_rekey_notify (struct cfg80211_registered_device *rdev, +struct net_device *netdev,const u8 *bssid, +const u8 *replay_ctr,gfp_t gfp); +#endif /* __NET_WIRELESS_NL80211_H */
Johannes Berg
maintainerPATCH 3/3 mac80211: support GTK rekey offload
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
This adds the necessary mac80211 APIs to support
GTK rekey offload, mirroring the functionality
from cfg80211.
--- include/net/mac80211.h | 20 +++++++++++++++++ net/mac80211/cfg.c | 16 ++++++++++++++ net/mac80211/driver-ops.h | 10 ++++++++ net/mac80211/driver-trace.h | 49 ++++++++++++++++++++++++++++++++++++++++++++ net/mac80211/key.c | 12 ++++++++++ 5 files changed, 107 insertions(+)
include/net/mac80211.h +20 -0
@@ -1700,6 +1700,12 @@ enum ieee80211_ampdu_mlme_action {* which set IEEE80211_KEY_FLAG_TKIP_REQ_RX_P1_KEY. * The callback must be atomic. * +* @set_rekey_data: If the device supports GTK rekeying, for example while the +* host is suspended, it can assign this callback to retrieve the data +* necessary to do GTK rekeying, this is the KEK, KCK and replay counter. +* After rekeying was done it should (for example during resume) notify +* userspace of the new replay counter using ieee80211_gtk_rekey_notify(). +* * @hw_scan: Ask the hardware to service the scan request, no need to start * the scan state machine in stack. The scan must honour the channel * configuration done by the regulatory agent in the wiphy's
@@ -1912,6 +1918,9 @@ struct ieee80211_ops {struct ieee80211_key_conf *conf, struct ieee80211_sta *sta, u32 iv32, u16 *phase1key); +void (*set_rekey_data)(struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct cfg80211_gtk_rekey_data *data);int (*hw_scan)(struct ieee80211_hw *hw,struct ieee80211_vif *vif,struct cfg80211_scan_request *req); void (*cancel_hw_scan)(struct ieee80211_hw *hw,
@@ -2585,6 +2594,17 @@ ieee80211_get_buffered_bc(struct ieee802void ieee80211_get_tkip_key (struct ieee80211_key_conf *keyconf,struct sk_buff *skb,enum ieee80211_tkip_key_type type,u8 *key); + +/** +* ieee80211_gtk_rekey_notify - notify userspace supplicant of rekeying +* @vif: virtual interface the rekeying was done on +* @bssid: The BSSID of the AP, for checking association +* @replay_ctr: the new replay counter after GTK rekeying +* @gfp: allocation flags +*/ +void ieee80211_gtk_rekey_notify (struct ieee80211_vif *vif,const u8 *bssid, +const u8 *replay_ctr,gfp_t gfp); +/** * ieee80211_wake_queue - wake specific queue * @hw: pointer as obtained from ieee80211_alloc_hw().
net/mac80211/cfg.c +16 -0
@@ -2101,6 +2101,21 @@ static void ieee80211_get_ringparam(strudrv_get_ringparam (local, tx, tx_max, rx, rx_max); } +static int ieee80211_set_rekey_data (struct wiphy *wiphy, +struct net_device *dev, +struct cfg80211_gtk_rekey_data *data) +{ +struct ieee80211_local *local =wiphy_priv (wiphy); +struct ieee80211_sub_if_data *sdata =IEEE80211_DEV_TO_SUB_IF (dev); + +if (!local->ops->set_rekey_data) +return -EOPNOTSUPP ; + +drv_set_rekey_data (local, sdata, data); + +return 0 ; +} +struct cfg80211_ops mac80211_config_ops = { .add_virtual_intf = ieee80211_add_iface, .del_virtual_intf = ieee80211_del_iface,
@@ -2163,4 +2178,5 @@ struct cfg80211_ops mac80211_config_ops .get_antenna = ieee80211_get_antenna, .set_ringparam = ieee80211_set_ringparam, .get_ringparam = ieee80211_get_ringparam, + .set_rekey_data = ieee80211_set_rekey_data, };
net/mac80211/driver-trace.h +49 -0
61 lines not on this page · raw message
net/mac80211/key.c +12 -0
@@ -566,3 +566,15 @@ void ieee80211_free_keys(struct ieee8021mutex_unlock (&sdata->local->key_mtx); } + + +void ieee80211_gtk_rekey_notify (struct ieee80211_vif *vif,const u8 *bssid, +const u8 *replay_ctr,gfp_t gfp) +{ +struct ieee80211_sub_if_data *sdata =vif_to_sdata (vif); + +trace_api_gtk_rekey_notify (sdata, bssid, replay_ctr); + +cfg80211_gtk_rekey_notify (sdata->dev, bssid, replay_ctr, gfp); +} +EXPORT_SYMBOL_GPL (ieee80211_gtk_rekey_notify);
net/mac80211/driver-ops.h +10 -0
@@ -647,4 +647,14 @@ static inline int drv_set_bitrate_mask(s return ret; } +static inline void drv_set_rekey_data (struct ieee80211_local *local, +struct ieee80211_sub_if_data *sdata, +struct cfg80211_gtk_rekey_data *data) +{ +trace_drv_set_rekey_data (local, sdata, data); +if (local->ops->set_rekey_data) + local->ops->set_rekey_data (&local->hw, &sdata->vif, data); +trace_drv_return_void (local); +} +#endif /* __MAC80211_DRIVER_OPS */