Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f8079d43 authored by Eliad Peller's avatar Eliad Peller Committed by Johannes Berg
Browse files

mac80211: move TKIP TX IVs to public part of key struct



Some drivers/devices might want to set the IVs by
themselves (and still let mac80211 generate MMIC).

Specifically, this is needed when the device does
offloading at certain times, and the driver has
to make sure that the IVs of new tx frames (from
the host) are synchronized with IVs that were
potentially used during the offloading.

Similarly to CCMP, move the TX IVs of TKIP keys to the
public part of the key struct, and export a function
to add the IV right into the crypto header.

The public tx_pn field is defined as atomic64, so define
TKIP_PN_TO_IV16/32 helper macros to convert it to iv16/32
when needed.

Since the iv32 used for the p1k cache is taken
directly from the frame, we can safely remove
iv16/32 from being protected by tkip.txlock.

Signed-off-by: default avatarEliad Peller <eliadx.peller@intel.com>
Signed-off-by: default avatarEmmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 109843b0
Loading
Loading
Loading
Loading
+20 −3
Original line number Original line Diff line number Diff line
@@ -1521,9 +1521,8 @@ enum ieee80211_key_flags {
 *	wants to be given when a frame is transmitted and needs to be
 *	wants to be given when a frame is transmitted and needs to be
 *	encrypted in hardware.
 *	encrypted in hardware.
 * @cipher: The key's cipher suite selector.
 * @cipher: The key's cipher suite selector.
 * @tx_pn: PN used for TX on non-TKIP keys, may be used by the driver
 * @tx_pn: PN used for TX keys, may be used by the driver as well if it
 *	as well if it needs to do software PN assignment by itself
 *	needs to do software PN assignment by itself (e.g. due to TSO)
 *	(e.g. due to TSO)
 * @flags: key flags, see &enum ieee80211_key_flags.
 * @flags: key flags, see &enum ieee80211_key_flags.
 * @keyidx: the key index (0-3)
 * @keyidx: the key index (0-3)
 * @keylen: key material length
 * @keylen: key material length
@@ -1549,6 +1548,9 @@ struct ieee80211_key_conf {


#define IEEE80211_MAX_PN_LEN	16
#define IEEE80211_MAX_PN_LEN	16


#define TKIP_PN_TO_IV16(pn) ((u16)(pn & 0xffff))
#define TKIP_PN_TO_IV32(pn) ((u32)((pn >> 16) & 0xffffffff))

/**
/**
 * struct ieee80211_key_seq - key sequence counter
 * struct ieee80211_key_seq - key sequence counter
 *
 *
@@ -4446,6 +4448,21 @@ void ieee80211_get_tkip_rx_p1k(struct ieee80211_key_conf *keyconf,
void ieee80211_get_tkip_p2k(struct ieee80211_key_conf *keyconf,
void ieee80211_get_tkip_p2k(struct ieee80211_key_conf *keyconf,
			    struct sk_buff *skb, u8 *p2k);
			    struct sk_buff *skb, u8 *p2k);


/**
 * ieee80211_tkip_add_iv - write TKIP IV and Ext. IV to pos
 *
 * @pos: start of crypto header
 * @keyconf: the parameter passed with the set key
 * @pn: PN to add
 *
 * Returns: pointer to the octet following IVs (i.e. beginning of
 * the packet payload)
 *
 * This function writes the tkip IV value to pos (which should
 * point to the crypto header)
 */
u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key_conf *keyconf, u64 pn);

/**
/**
 * ieee80211_get_key_tx_seq - get key TX sequence counter
 * ieee80211_get_key_tx_seq - get key TX sequence counter
 *
 *
+3 −2
Original line number Original line Diff line number Diff line
@@ -339,8 +339,9 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,


	switch (key->conf.cipher) {
	switch (key->conf.cipher) {
	case WLAN_CIPHER_SUITE_TKIP:
	case WLAN_CIPHER_SUITE_TKIP:
		iv32 = key->u.tkip.tx.iv32;
		pn64 = atomic64_read(&key->conf.tx_pn);
		iv16 = key->u.tkip.tx.iv16;
		iv32 = TKIP_PN_TO_IV32(pn64);
		iv16 = TKIP_PN_TO_IV16(pn64);


		if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
		if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
		    !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
		    !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
+3 −2
Original line number Original line Diff line number Diff line
@@ -132,9 +132,10 @@ static ssize_t key_tx_spec_read(struct file *file, char __user *userbuf,
		len = scnprintf(buf, sizeof(buf), "\n");
		len = scnprintf(buf, sizeof(buf), "\n");
		break;
		break;
	case WLAN_CIPHER_SUITE_TKIP:
	case WLAN_CIPHER_SUITE_TKIP:
		pn = atomic64_read(&key->conf.tx_pn);
		len = scnprintf(buf, sizeof(buf), "%08x %04x\n",
		len = scnprintf(buf, sizeof(buf), "%08x %04x\n",
				key->u.tkip.tx.iv32,
				TKIP_PN_TO_IV32(pn),
				key->u.tkip.tx.iv16);
				TKIP_PN_TO_IV16(pn));
		break;
		break;
	case WLAN_CIPHER_SUITE_CCMP:
	case WLAN_CIPHER_SUITE_CCMP:
	case WLAN_CIPHER_SUITE_CCMP_256:
	case WLAN_CIPHER_SUITE_CCMP_256:
+5 −4
Original line number Original line Diff line number Diff line
@@ -945,8 +945,9 @@ void ieee80211_get_key_tx_seq(struct ieee80211_key_conf *keyconf,


	switch (key->conf.cipher) {
	switch (key->conf.cipher) {
	case WLAN_CIPHER_SUITE_TKIP:
	case WLAN_CIPHER_SUITE_TKIP:
		seq->tkip.iv32 = key->u.tkip.tx.iv32;
		pn64 = atomic64_read(&key->conf.tx_pn);
		seq->tkip.iv16 = key->u.tkip.tx.iv16;
		seq->tkip.iv32 = TKIP_PN_TO_IV32(pn64);
		seq->tkip.iv16 = TKIP_PN_TO_IV16(pn64);
		break;
		break;
	case WLAN_CIPHER_SUITE_CCMP:
	case WLAN_CIPHER_SUITE_CCMP:
	case WLAN_CIPHER_SUITE_CCMP_256:
	case WLAN_CIPHER_SUITE_CCMP_256:
@@ -1039,8 +1040,8 @@ void ieee80211_set_key_tx_seq(struct ieee80211_key_conf *keyconf,


	switch (key->conf.cipher) {
	switch (key->conf.cipher) {
	case WLAN_CIPHER_SUITE_TKIP:
	case WLAN_CIPHER_SUITE_TKIP:
		key->u.tkip.tx.iv32 = seq->tkip.iv32;
		pn64 = (u64)seq->tkip.iv16 | ((u64)seq->tkip.iv32 << 16);
		key->u.tkip.tx.iv16 = seq->tkip.iv16;
		atomic64_set(&key->conf.tx_pn, pn64);
		break;
		break;
	case WLAN_CIPHER_SUITE_CCMP:
	case WLAN_CIPHER_SUITE_CCMP:
	case WLAN_CIPHER_SUITE_CCMP_256:
	case WLAN_CIPHER_SUITE_CCMP_256:
+7 −3
Original line number Original line Diff line number Diff line
@@ -44,13 +44,17 @@ enum ieee80211_internal_tkip_state {
};
};


struct tkip_ctx {
struct tkip_ctx {
	u32 iv32;	/* current iv32 */
	u16 iv16;	/* current iv16 */
	u16 p1k[5];	/* p1k cache */
	u16 p1k[5];	/* p1k cache */
	u32 p1k_iv32;	/* iv32 for which p1k computed */
	u32 p1k_iv32;	/* iv32 for which p1k computed */
	enum ieee80211_internal_tkip_state state;
	enum ieee80211_internal_tkip_state state;
};
};


struct tkip_ctx_rx {
	struct tkip_ctx ctx;
	u32 iv32;	/* current iv32 */
	u16 iv16;	/* current iv16 */
};

struct ieee80211_key {
struct ieee80211_key {
	struct ieee80211_local *local;
	struct ieee80211_local *local;
	struct ieee80211_sub_if_data *sdata;
	struct ieee80211_sub_if_data *sdata;
@@ -71,7 +75,7 @@ struct ieee80211_key {
			struct tkip_ctx tx;
			struct tkip_ctx tx;


			/* last received RSC */
			/* last received RSC */
			struct tkip_ctx rx[IEEE80211_NUM_TIDS];
			struct tkip_ctx_rx rx[IEEE80211_NUM_TIDS];


			/* number of mic failures */
			/* number of mic failures */
			u32 mic_failures;
			u32 mic_failures;
Loading