Skip to contentSkip to conversation

cfg80211: Add support for QoS mapping

PATCH In review Jouni Malinen 2 participants 4 messages Nov 20, 2013 – Nov 25, 2013

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

PATCH 1/2 cfg80211: Add support for QoS mapping

From: Kyeyoon Park <[email protected]>

This allows QoS mapping from external networks to be implemented as defined in IEEE Std 802.11-2012, 10.24.9. APs can use this to advertise DSCP ranges and exceptions for mapping frames to a specific UP over Wi-Fi.

The payload of the QoS Map Set element (IEEE Std 802.11-2012, 8.4.2.97) is sent to the driver through the new NL80211_ATTR_QOS_MAP attribute to configure the local behavior either on the AP (based on local configuration) or on a station (based on information received from the AP).

---
 drivers/net/wireless/brcm80211/brcmfmac/fwsignal.c |    2 +-
 drivers/net/wireless/mwifiex/main.c                |    2 +-
 include/net/cfg80211.h                             |   55 +++++++++++++++++++-
 include/uapi/linux/nl80211.h                       |   12 +++++
 net/mac80211/wme.c                                 |    2 +-
 net/wireless/nl80211.c                             |   50 ++++++++++++++++++
 net/wireless/rdev-ops.h                            |   12 +++++
 net/wireless/trace.h                               |   44 ++++++++++++++++
 net/wireless/util.c                                |   18 ++++++-
 9 files changed, 192 insertions(+), 5 deletions(-)
drivers/net/wireless/brcm80211/brcmfmac/fwsignal.c +1 -1
index d0cd0bf..ac0fd69 100644
@@ -1757,7 +1757,7 @@ int brcmf_fws_process_skb(struct brcmf_if *ifp, struct sk_buff *skb)
 	brcmf_dbg(DATA, "tx proto=0x%X\n", ntohs(eh->h_proto));
 	/* determine the priority */
 	if (!skb->priority)
-		skb->priority = cfg80211_classify8021d(skb);
+		skb->priority = cfg80211_classify8021d(skb, NULL);
 
 	drvr->tx_multicast += !!multicast;
 	if (pae)
drivers/net/wireless/mwifiex/main.c +1 -1
index 78e8a66..76df74b 100644
@@ -748,7 +748,7 @@ static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
 static u16
 mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb)
 {
-	skb->priority = cfg80211_classify8021d(skb);
+	skb->priority = cfg80211_classify8021d(skb, NULL);
 	return mwifiex_1d_to_wmm_queue[skb->priority];
 }
 
include/net/cfg80211.h +54 -1

81 lines not on this page · raw message

include/uapi/linux/nl80211.h +12 -0
index f752e98..4782c20 100644
@@ -686,6 +686,10 @@
  *	other station that transmission must be blocked until the channel
  *	switch is complete.
  *
+ * @NL80211_CMD_SET_QOS_MAP: Set Interworking QoS mapping for IP DSCP values.
+ *	The QoS mapping information is included in %NL80211_ATTR_QOS_MAP. If
+ *	that attribute is not included, QoS mapping is disabled.
+ *
  * @NL80211_CMD_MAX: highest used command number
  * @__NL80211_CMD_AFTER_LAST: internal use
  */
@@ -853,6 +857,8 @@ enum nl80211_commands {
 
 	NL80211_CMD_CHANNEL_SWITCH,
 
+	NL80211_CMD_SET_QOS_MAP,
+
 	/* add new commands above here */
 
 	/* used to define NL80211_CMD_MAX below */
@@ -1508,6 +1514,10 @@ enum nl80211_commands {
  *	to react to radar events, e.g. initiate a channel switch or leave the
  *	IBSS network.
  *
+ * @NL80211_ATTR_QOS_MAP: IP DSCP mapping for Interworking QoS mapping. This
+ *	data is in the format defined for the payload of the QoS Map Set element
+ *	in IEEE Std 802.11-2012, 8.4.2.97.
+ *
  * @NL80211_ATTR_MAX: highest attribute number currently defined
  * @__NL80211_ATTR_AFTER_LAST: internal use
  */
@@ -1824,6 +1834,8 @@ enum nl80211_attrs {
 
 	NL80211_ATTR_HANDLE_DFS,
 
+	NL80211_ATTR_QOS_MAP,
+
 	/* add attributes here, update the policy in nl80211.c */
 
 	__NL80211_ATTR_AFTER_LAST,
net/mac80211/wme.c +1 -1
index afba19c..faa9d8e 100644
@@ -155,7 +155,7 @@ u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
 
 	/* use the data classifier to determine what 802.1d tag the
 	 * data frame has */
-	skb->priority = cfg80211_classify8021d(skb);
+	skb->priority = cfg80211_classify8021d(skb, NULL);
 
 	return ieee80211_downgrade_queue(sdata, skb);
 }
net/wireless/nl80211.c +50 -0

68 lines not on this page · raw message

net/wireless/rdev-ops.h +12 -0
index 37ce9fd..be4247e 100644
@@ -936,4 +936,16 @@ static inline int rdev_channel_switch(struct cfg80211_registered_device *rdev,
 	return ret;
 }
 
+static inline int rdev_set_qos_map(struct cfg80211_registered_device *rdev,
+				   struct net_device *dev,
+				   struct cfg80211_qos_map *qos_map)
+{
+	int ret;
+
+	trace_rdev_set_qos_map(&rdev->wiphy, dev, qos_map);
+	ret = rdev->ops->set_qos_map(&rdev->wiphy, dev, qos_map);
+	trace_rdev_return_int(&rdev->wiphy, ret);
+	return ret;
+}
+
 #endif /* __CFG80211_RDEV_OPS */
net/wireless/trace.h +44 -0

56 lines not on this page · raw message

net/wireless/util.c +17 -1
index 935dea9..e129822 100644
@@ -689,7 +689,8 @@ void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
 EXPORT_SYMBOL(ieee80211_amsdu_to_8023s);
 
 /* Given a data frame determine the 802.1p/1d tag to use. */
-unsigned int cfg80211_classify8021d(struct sk_buff *skb)
+unsigned int cfg80211_classify8021d(struct sk_buff *skb,
+				    struct cfg80211_qos_map *qos_map)
 {
 	unsigned int dscp;
 	unsigned char vlan_priority;
@@ -720,6 +721,21 @@ unsigned int cfg80211_classify8021d(struct sk_buff *skb)
 		return 0;
 	}
 
+	if (qos_map && qos_map->valid) {
+		unsigned int i, tmp_dscp = dscp >> 2;
+
+		for (i = 0; i < qos_map->num_des; i++) {
+			if (tmp_dscp == qos_map->dscp_exception[i].dscp)
+				return qos_map->dscp_exception[i].up;
+		}
+
+		for (i = 0; i < 8; i++) {
+			if (tmp_dscp >= qos_map->up[i].low &&
+			    tmp_dscp <= qos_map->up[i].high)
+				return i;
+		}
+	}
+
 	return dscp >> 5;
 }
 EXPORT_SYMBOL(cfg80211_classify8021d);
Signature · 5 lines
1.7.9.5


-- 
Jouni Malinen                                            PGP id EFC895FA
maintainer
#1 lore raw

include/net/cfg80211.h struct cfg80211_update_ft_ies_params { · line 1987

Quoted 2 lines · Jouni Malinen
include/net/cfg80211.h +2 -0
+struct cfg80211_qos_map {
+	bool valid;

why do we need a validity flag? isn't NULL pointer enough?

include/net/cfg80211.h struct cfg80211_ops { · line 2481

Quoted 11 lines

+ * @set_qos_map: Set QoS mapping information to the driver */
struct cfg80211_ops {

include/net/cfg80211.h +3 -0
 	int	(*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -2428,6 +2476,9 @@ struct cfg80211_ops {
 	int	(*channel_switch)(struct wiphy *wiphy,
 				  struct net_device *dev,
 				  struct cfg80211_csa_settings *params);
+	int     (*set_qos_map)(struct wiphy *wiphy,
+			       struct net_device *dev,
+			       struct cfg80211_qos_map *qos_map);

I wonder if this is necessary? The driver could just have a flag for "support QoS mapping" and having such support requires using classify8021d(). OTOH, that function needs to gain a parameter anyway, so it's not really worth it. Also, it's something that could be changed purely internal to the kernel, so I guess I'm not worried about it much.

include/uapi/linux/nl80211.h line 691

Quoted 3 lines
include/uapi/linux/nl80211.h +3 -0
+ * @NL80211_CMD_SET_QOS_MAP: Set Interworking QoS mapping for IP DSCP values.
+ *	The QoS mapping information is included in %NL80211_ATTR_QOS_MAP. If
+ *	that attribute is not included, QoS mapping is disabled.

Might be useful to say that this is only valid while associated?

In fact, why is this even a new operation? Can this change during the lifetime of the BSS? If not, then it might be worth just putting the attribute into START_AP and ASSOCIATE/CONNECT etc?

net/wireless/nl80211.c static int nl80211_crit_protocol_stop(struct sk_buff *skb, · line 8862

Quoted 1 line
net/wireless/nl80211.c +1 -0
+		if (len & 1 || len < IEEE80211_QOS_MAP_LEN_MIN ||

I think len%2 would be easier to read? Not that it makes a big difference, but fundamentally this isn't a bitop thing, it's a "length must be even" thing.

net/wireless/nl80211.c static struct genl_ops nl80211_ops[] = { · line 9610

Quoted 6 lines
net/wireless/nl80211.c +2 -0
@@ -9564,6 +9606,14 @@ static struct genl_ops nl80211_ops[] = {
 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
 				  NL80211_FLAG_NEED_RTNL,
 	},
+	{
+		.cmd = NL80211_CMD_SET_QOS_MAP,

You forgot to advertise availability of the operation, but then again see above - is it even needed?

Quoted 8 lines
net/wireless/util.c +4 -0
@@ -720,6 +721,21 @@ unsigned int cfg80211_classify8021d(struct sk_buff *skb)
 		return 0;
 	}
 
+	if (qos_map && qos_map->valid) {
+		unsigned int i, tmp_dscp = dscp >> 2;
+
+		for (i = 0; i < qos_map->num_des; i++) {

net/wireless/util.c unsigned int cfg80211_classify8021d(struct sk_buff *skb) · line 737

Quoted 10 lines
net/wireless/util.c +10 -0
+			if (tmp_dscp == qos_map->dscp_exception[i].dscp)
+				return qos_map->dscp_exception[i].up;
+		}
+
+		for (i = 0; i < 8; i++) {
+			if (tmp_dscp >= qos_map->up[i].low &&
+			    tmp_dscp <= qos_map->up[i].high)
+				return i;
+		}
+	}

Much better than the first version I saw :)

johannes

#2 lore raw
Quoted 6 lines · Johannes Berg

include/net/cfg80211.h struct cfg80211_update_ft_ies_params { · line 1987

Quoted 2 lines · Jouni Malinen
include/net/cfg80211.h +2 -0
+struct cfg80211_qos_map {
+	bool valid;

why do we need a validity flag? isn't NULL pointer enough?

For cfg80211, NULL would be fine. I guess the mac80211 use case could be handled outside this structure.

Quoted 9 lines
Quoted 9 lines

+ * @set_qos_map: Set QoS mapping information to the driver */
struct cfg80211_ops {

include/net/cfg80211.h +1 -0
 	int	(*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -2428,6 +2476,9 @@ struct cfg80211_ops {
 	int	(*channel_switch)(struct wiphy *wiphy,
 				  struct net_device *dev,
 				  struct cfg80211_csa_settings *params);
+	int     (*set_qos_map)(struct wiphy *wiphy,
Quoted 8 lines

include/net/cfg80211.h struct cfg80211_ops { · line 2481

Quoted 2 lines
include/net/cfg80211.h +2 -0
+			       struct net_device *dev,
+			       struct cfg80211_qos_map *qos_map);

I wonder if this is necessary? The driver could just have a flag for "support QoS mapping" and having such support requires using classify8021d(). OTOH, that function needs to gain a parameter anyway, so it's not really worth it. Also, it's something that could be changed purely internal to the kernel, so I guess I'm not worried about it much.

Hmm.. How else would the caller (that driver or mac80211 receiving this call..) of classify8021d() get these parameters?

Quoted 5 lines

include/uapi/linux/nl80211.h line 691

Quoted 3 lines
include/uapi/linux/nl80211.h +3 -0
+ * @NL80211_CMD_SET_QOS_MAP: Set Interworking QoS mapping for IP DSCP values.
+ *	The QoS mapping information is included in %NL80211_ATTR_QOS_MAP. If
+ *	that attribute is not included, QoS mapping is disabled.

Might be useful to say that this is only valid while associated?

When else can you send an IP packet? I don't have anything against adding that here, but it sounds pretty obvious to me.

Quoted 3 lines

In fact, why is this even a new operation? Can this change during the lifetime of the BSS? If not, then it might be worth just putting the attribute into START_AP and ASSOCIATE/CONNECT etc?

Yes, this can change during an association (configurable operation on AP; a new Action frame from AP to STA for notifying about the change).

Quoted 5 lines

net/wireless/nl80211.c static int nl80211_crit_protocol_stop(struct sk_buff *skb, · line 8862

Quoted 1 line
net/wireless/nl80211.c +1 -0
+		if (len & 1 || len < IEEE80211_QOS_MAP_LEN_MIN ||

I think len%2 would be easier to read? Not that it makes a big difference, but fundamentally this isn't a bitop thing, it's a "length must be even" thing.

Sure, that's fine.

Quoted 9 lines

net/wireless/nl80211.c static struct genl_ops nl80211_ops[] = { · line 9610

Quoted 6 lines
net/wireless/nl80211.c +2 -0
@@ -9564,6 +9606,14 @@ static struct genl_ops nl80211_ops[] = {
 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
 				  NL80211_FLAG_NEED_RTNL,
 	},
+	{
+		.cmd = NL80211_CMD_SET_QOS_MAP,

You forgot to advertise availability of the operation, but then again see above - is it even needed?

I think it is needed and yes, it could be useful to advertise availability.

Signature · 1 line
Jouni Malinen                                            PGP id EFC895FA
maintainer
#3 lore raw
Quoted 10 lines · Jouni Malinen
Quoted 6 lines · Johannes Berg

include/net/cfg80211.h struct cfg80211_update_ft_ies_params { · line 1987

Quoted 2 lines · Jouni Malinen
include/net/cfg80211.h +2 -0
+struct cfg80211_qos_map {
+	bool valid;

why do we need a validity flag? isn't NULL pointer enough?

For cfg80211, NULL would be fine. I guess the mac80211 use case could be handled outside this structure.

mac80211 could also just kmemdup() it and only keep a pointer (RCU protected?), that'd indeed be more efficient if nobody is using it, which is probably still the majority of APs?

Quoted 10 lines
Quoted 9 lines

include/net/cfg80211.h struct cfg80211_ops { · line 2481

Quoted 3 lines
include/net/cfg80211.h +3 -0
+	int     (*set_qos_map)(struct wiphy *wiphy,
+			       struct net_device *dev,
+			       struct cfg80211_qos_map *qos_map);

I wonder if this is necessary? The driver could just have a flag for "support QoS mapping" and having such support requires using classify8021d(). OTOH, that function needs to gain a parameter anyway, so it's not really worth it. Also, it's something that could be changed purely internal to the kernel, so I guess I'm not worried about it much.

Quoted 2 lines

Hmm.. How else would the caller (that driver or mac80211 receiving this call..) of classify8021d() get these parameters?

We'd have to pass the wdev instead of the qos_map, and then we could store it all in the wdev and handle it all in cfg80211. But then again many other drivers might actually need it for firmware or whatever, so I guess it makes sense. We can also see, this isn't really related to the userland API.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

+ * @NL80211_CMD_SET_QOS_MAP: Set Interworking QoS mapping for IP DSCP values.
+ * The QoS mapping information is included in %NL80211_ATTR_QOS_MAP. If
+ * that attribute is not included, QoS mapping is disabled.

Might be useful to say that this is only valid while associated?

When else can you send an IP packet? I don't have anything against adding that here, but it sounds pretty obvious to me.

Yes, obviously, but also not. If we say this, then we should also say that it's cleared on disassoc/stop_ap and things like that, I guess? I generally dislike state that can survive between associations (unless the device is roaming itself, but in this case presumably it'd have to handle it all by itself then) or across stop_ap/start_ap.

Quoted 6 lines
Quoted 3 lines

In fact, why is this even a new operation? Can this change during the lifetime of the BSS? If not, then it might be worth just putting the attribute into START_AP and ASSOCIATE/CONNECT etc?

Yes, this can change during an association (configurable operation on AP; a new Action frame from AP to STA for notifying about the change).

Ok.

johannes