Skip to contentSkip to conversation

mac80211: eliminate cached fc from struct ieee80211_{tx|rx}_data

RFC-PATCH Harvey Harrison 2 participants 2 messages Jun 10, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Rather than keep a cached host-endian frame control, use byteswapped helpers throughout and get the frame control directly from the 802.11 frame itself.

Very little testing has been done so far of this, but it does compile.

Applies on top of the 8-patch series adding byteswapped frame control helpers.

---
 include/linux/ieee80211.h  |  113 ++++++++++++++++++++++
 net/mac80211/ieee80211_i.h |    4 +-
 net/mac80211/rx.c          |  226 +++++++++++++++++++++-----------------------
 net/mac80211/tx.c          |   51 +++++------
 net/mac80211/wep.c         |    6 +-
 net/mac80211/wpa.c         |   16 ++--
 6 files changed, 255 insertions(+), 161 deletions(-)
include/linux/ieee80211.h +113 -0
index 9a964ff..be718e4 100644
@@ -129,6 +129,33 @@ static inline int ieee80211_has_morefrags(__le16 fc)
 }
 
 /**
+ * ieee80211_has_retry - check if IEEE80211_FCTL_RETRY is set
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline int ieee80211_has_retry(__le16 fc)
+{
+	return (fc & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0;
+}
+
+/**
+ * ieee80211_has_pm - check if IEEE80211_FCTL_PM is set
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline int ieee80211_has_pm(__le16 fc)
+{
+	return (fc & cpu_to_le16(IEEE80211_FCTL_PM)) != 0;
+}
+
+/**
+ * ieee80211_has_order - check if IEEE80211_FCTL_ORDER is set
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline int ieee80211_has_order(__le16 fc)
+{
+	return (fc & cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0;
+}
+
+/**
  * ieee80211_has_tods - check if IEEE80211_FCTL_TODS is set
  * @fc: frame control bytes in little-endian byteorder
  */
@@ -202,6 +229,19 @@ static inline int ieee80211_is_data_qos(__le16 fc)
 }
 
 /**
+ * ieee80211_data_present - check if data is present in the frame
+ * @fc: frame control bytes in little-endian byteorder
+ *
+ * Only mask with one bit in the STYPE to only match those STYPES that
+ * carry data.
+ */
+static inline int ieee80211_data_present(__le16 fc)
+{
+	return (fc & cpu_to_le16(0x40 | IEEE80211_FCTL_FTYPE)) ==
+	       cpu_to_le16(IEEE80211_FTYPE_DATA);
+}
+
+/**
  * ieee80211_is_nullfunc - check if FTYPE=IEEE80211_FTYPE_DATA and STYPE=IEEE80211_STYPE_NULLFUNC
  * @fc: frame control bytes in little-endian byteorder
  */
@@ -257,6 +297,61 @@ static inline int ieee80211_is_beacon(__le16 fc)
 }
 
 /**
+ * ieee80211_is_auth - check if FTYPE=IEEE80211_FTYPE_MGMT and STYPE=IEEE80211_STYPE_AUTH
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline int ieee80211_is_auth(__le16 fc)
+{
+	return (fc &
+	       cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
+	       cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
+}
+
+/**
+ * ieee80211_is_assoc_req - check if FTYPE=IEEE80211_FTYPE_MGMT and STYPE=IEEE80211_STYPE_ASSOC_REQ
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline int ieee80211_is_assoc_req(__le16 fc)
+{
+	return (fc &
+	       cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
+	       cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_REQ);
+}
+
+/**
+ * ieee80211_is_reassoc_req - check if FTYPE=IEEE80211_FTYPE_MGMT and STYPE=IEEE80211_STYPE_REASSOC_REQ
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline int ieee80211_is_reassoc_req(__le16 fc)
+{
+	return (fc &
+	       cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
+	       cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_REQ);
+}
+
+/**
+ * ieee80211_is_probe_req - check if FTYPE=IEEE80211_FTYPE_MGMT and STYPE=IEEE80211_STYPE_PROBE_REQ
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline int ieee80211_is_probe_req(__le16 fc)
+{
+	return (fc &
+	       cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
+	       cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ);
+}
+
+/**
+ * ieee80211_is_probe_resp - check if FTYPE=IEEE80211_FTYPE_MGMT and STYPE=IEEE80211_STYPE_PROBE_RESP
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline int ieee80211_is_probe_resp(__le16 fc)
+{
+	return (fc &
+	       cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
+	       cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
+}
+
+/**
  * ieee80211_set_protected - set the IEEE80211_FCTL_PROTECTED bit
  * @hdr: the frame
  */
@@ -266,6 +361,24 @@ static inline void ieee80211_set_protected(struct ieee80211_hdr *hdr)
 }
 
 /**
+ * ieee80211_set_morefrags - set the IEEE80211_FCTL_MOREFRAGS bit
+ * @hdr: the frame
+ */
+static inline void ieee80211_set_morefrags(struct ieee80211_hdr *hdr)
+{
+	hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
+}
+
+/**
+ * ieee80211_set_morefrags - clear the IEEE80211_FCTL_MOREFRAGS bit
+ * @hdr: the frame
+ */
+static inline void ieee80211_clear_morefrags(struct ieee80211_hdr *hdr)
+{
+	hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
+}
+
+/**
  * ieee80211_set_moredata - set the IEEE80211_FCTL_MOREDATA bit
  * @hdr: the frame
  */
net/mac80211/ieee80211_i.h +2 -2
index 432011c..f938d3b 100644
@@ -171,7 +171,7 @@ struct ieee80211_tx_data {
 	struct sk_buff **extra_frag;
 	int num_extra_frag;
 
-	u16 fc, ethertype;
+	u16 ethertype;
 	unsigned int flags;
 };
 
@@ -199,7 +199,7 @@ struct ieee80211_rx_data {
 	struct ieee80211_rx_status *status;
 	struct ieee80211_rate *rate;
 
-	u16 fc, ethertype;
+	u16 ethertype;
 	unsigned int flags;
 	int sent_ps_buffered;
 	int queue;
net/mac80211/rx.c +107 -119

576 lines not on this page · raw message

net/mac80211/tx.c +22 -29

177 lines not on this page · raw message

net/mac80211/wep.c +3 -3
index e7b6344..fb57979 100644
@@ -304,9 +304,9 @@ u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key)
 ieee80211_rx_result
 ieee80211_crypto_wep_decrypt(struct ieee80211_rx_data *rx)
 {
-	if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
-	    ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
-	     (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH))
+	__le16 fc = ((struct ieee80211_hdr *)rx->skb->data)->frame_control;
+
+	if (!ieee80211_is_data(fc) && !ieee80211_is_auth(fc))
 		return RX_CONTINUE;
 
 	if (!(rx->status->flag & RX_FLAG_DECRYPTED)) {
net/mac80211/wpa.c +8 -8
index 9834cec..2b2d572 100644
@@ -51,16 +51,16 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx)
 {
 	u8 *data, *sa, *da, *key, *mic, qos_tid;
 	size_t data_len;
-	u16 fc;
+	__le16 fc;
 	struct sk_buff *skb = tx->skb;
 	int authenticator;
 	int wpa_test = 0;
 	int tail;
 
-	fc = tx->fc;
+	fc = ((struct ieee80211_hdr *)tx->skb->data)->frame_control;
 
 	if (!tx->key || tx->key->conf.alg != ALG_TKIP || skb->len < 24 ||
-	    !WLAN_FC_DATA_PRESENT(fc))
+	    !ieee80211_is_data(fc))
 		return TX_CONTINUE;
 
 	if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len))
@@ -102,13 +102,13 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
 {
 	u8 *data, *sa, *da, *key = NULL, qos_tid;
 	size_t data_len;
-	u16 fc;
+	__le16 fc;
 	u8 mic[MICHAEL_MIC_LEN];
 	struct sk_buff *skb = rx->skb;
 	int authenticator = 1, wpa_test = 0;
 	DECLARE_MAC_BUF(mac);
 
-	fc = rx->fc;
+	fc = ((struct ieee80211_hdr *)rx->skb->data)->frame_control;
 
 	/*
 	 * No way to verify the MIC if the hardware stripped it
@@ -117,7 +117,7 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
 		return RX_CONTINUE;
 
 	if (!rx->key || rx->key->conf.alg != ALG_TKIP ||
-	    !(rx->fc & IEEE80211_FCTL_PROTECTED) || !WLAN_FC_DATA_PRESENT(fc))
+	    !ieee80211_has_protected(fc) || !ieee80211_data_present(fc))
 		return RX_CONTINUE;
 
 	if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len)
@@ -254,7 +254,7 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx)
 
 	hdrlen = ieee80211_hdrlen(hdr->frame_control);
 
-	if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
+	if (!ieee80211_is_data(hdr->frame_control))
 		return RX_CONTINUE;
 
 	if (!rx->sta || skb->len - hdrlen < 12)
@@ -496,7 +496,7 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx)
 
 	hdrlen = ieee80211_hdrlen(hdr->frame_control);
 
-	if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
+	if (!ieee80211_is_data(hdr->frame_control))
 		return RX_CONTINUE;
 
 	data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN;
Signature · 1 line
1.5.6.rc2.261.ga8fbe
maintainer
#1 lore raw
Quoted 8 lines · Harvey Harrison

Rather than keep a cached host-endian frame control, use byteswapped helpers throughout and get the frame control directly from the 802.11 frame itself.

Very little testing has been done so far of this, but it does compile.

Applies on top of the 8-patch series adding byteswapped frame control helpers.

Cool. I'll test it later.

net/mac80211/rx.c ieee80211_data_to_8023(struct ieee80211_rx_data *rx) · line 1155

Quoted 2 lines
net/mac80211/rx.c +1 -1
-	case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
+	if (ieee80211_has_a4(fc)) {

I wonder if the compiler was smart enough to make the switch statement into something like

if (fromds) {
	if (tods) {
		...
	} else {
		...
	}
} else {
	if (tods) {
		...
	} else {
		...
	}
}

and if we should do that?

johannes