Skip to contentSkip to conversation

cfg80211/mac80211: Add support to configure and monitor rssi/txrate threshold

RFC Superseded Tamizh chelvam 1 participant 7 messages Apr 27, 2018

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover cfg80211/mac80211: Add support to configure and monitor rssi/txrate threshold

This patchsets introduced new NL command and api to support configuring rssi and txrate for the connected stations. And implemented new api to notify the threshold cross event. This will be useful/requires for the user application like steering to monitor station's activity change.

Tamizh chelvam (6):
cfg80211: Add support to configure station specific rssi threshold for
AP mode
mac80211: Add support to configure rssi threshold for AP mode
mac80211: Implement functionality to monitor station's rssi threshold
cross
cfg80211: Add support to configure station specific txrate threshold
for AP mode
mac80211: Add support to configure txrate threshold for station
mac80211: Implement functionality to monitor txrate cross event for
station

v2:
* fixed kbuild warnings
* updated commit log

 include/net/cfg80211.h       |  69 ++++++-
 include/net/mac80211.h       |  12 ++
 include/uapi/linux/nl80211.h |  96 +++++++++
 net/mac80211/cfg.c           | 111 +++++++++++
 net/mac80211/rx.c            |  65 +++++-
 net/mac80211/sta_info.h      |  37 ++++
 net/mac80211/status.c        |  40 +++-
 net/wireless/core.c          |  26 ++-
 net/wireless/core.h          |   6 +-
 net/wireless/nl80211.c       | 462 ++++++++++++++++++++++++++++++++++++++-----
 net/wireless/rdev-ops.h      |  48 +++++
 net/wireless/trace.h         | 123 ++++++++++++
 12 files changed, 1030 insertions(+), 65 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

RFC v2 1/6 cfg80211: Add support to configure station specific rssi threshold for AP mode

This patch add support to configure station specific rssi threshold to monitor station's signal strength modification. This will be useful for the user application like steering to configure and monitor the station's signal strength change event.

New NL80211_CMD_STA_MON command introduced to cofigure single or multi rssi thresholds using NL80211_ATTR_STA_MON_RSSI_THOLD and NL80211_ATTR_STA_MON_RSSI_HYST.

cfg80211_sta_mon_rssi_notify introduce to notify station's signal strength goes out of range using NL80211_CMD_NOTIFY_STA_MON command.

NL80211_EXT_FEATURE_STA_MON_RSSI_CONFIG flag needs to be advertised by the drvier to allow single rssi threshold and hysteresis configuration. NL80211_EXT_FEATURE_STA_MON_RSSI_LIST needs to be advertised to allow multi rssi thresholds.

---
 include/net/cfg80211.h       |  43 ++++-
 include/uapi/linux/nl80211.h |  62 +++++++
 net/wireless/core.c          |  26 ++-
 net/wireless/core.h          |   6 +-
 net/wireless/nl80211.c       | 388 +++++++++++++++++++++++++++++++++++++------
 net/wireless/rdev-ops.h      |  31 ++++
 net/wireless/trace.h         |  74 +++++++++
 7 files changed, 567 insertions(+), 63 deletions(-)
include/net/cfg80211.h +40 -3
index 250dac3..7e7a0bf 100644
@@ -2973,6 +2973,17 @@ struct cfg80211_external_auth_params {
  *
  * @tx_control_port: TX a control port frame (EAPoL).  The noencrypt parameter
  *	tells the driver that the frame should not be encrypted.
+ * @set_sta_mon_rssi_config: Configure  RSSI threshold for a station.
+ *	After configuration, the driver should (soon) send an event indicating
+ *	the current level of a station is above/below the configured threshold;
+ *	this may need some care when the configuration is changed
+ *	(without first being disabled.)
+ * @set_sta_mon_rssi_range_config: Configure two RSSI thresholds in the
+ *	station's rssi monitor.  An event is to be sent only when the
+ *	signal level of a station is found to be outside the two values.
+ *	The driver should set %NL80211_EXT_FEATURE_STA_MON_RSSI_LIST if this
+ *	method is implemented. If it is provided then there's no point providing
+ *	@set_sta_mon_rssi_config.
  */
 struct cfg80211_ops {
 	int	(*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -3274,6 +3285,14 @@ struct cfg80211_ops {
 				   const u8 *buf, size_t len,
 				   const u8 *dest, const __be16 proto,
 				   const bool noencrypt);
+	int     (*set_sta_mon_rssi_config)(struct wiphy *wiphy,
+					    struct net_device *dev,
+					    const u8 *addr,
+					    s32 rssi_thold, u32 rssi_hyst);
+	int     (*set_sta_mon_rssi_range_config)(struct wiphy *wiphy,
+						 struct net_device *dev,
+						 const u8 *addr,
+						 s32 rssi_low, s32 rssi_high);
 };
 
 /*
@@ -4076,7 +4095,7 @@ static inline struct wiphy *wiphy_new(const struct cfg80211_ops *ops,
 struct cfg80211_conn;
 struct cfg80211_internal_bss;
 struct cfg80211_cached_keys;
-struct cfg80211_cqm_config;
+struct cfg80211_rssi_config;
 
 /**
  * struct wireless_dev - wireless device state
@@ -4141,7 +4160,8 @@ static inline struct wiphy *wiphy_new(const struct cfg80211_ops *ops,
  * @event_lock: (private) lock for event list
  * @owner_nlportid: (private) owner socket port ID
  * @nl_owner_dead: (private) owner socket went away
- * @cqm_config: (private) nl80211 RSSI monitor state
+ * @rssi_config: (private) nl80211 RSSI monitor state
+ * @rssi_config_list: list of peer address based rssi configuration
  */
 struct wireless_dev {
 	struct wiphy *wiphy;
@@ -4212,7 +4232,8 @@ struct wireless_dev {
 	} wext;
 #endif
 
-	struct cfg80211_cqm_config *cqm_config;
+	struct cfg80211_rssi_config *rssi_config;
+	struct list_head rssi_config_list;
 };
 
 static inline u8 *wdev_address(struct wireless_dev *wdev)
@@ -5776,6 +5797,22 @@ void cfg80211_cqm_rssi_notify(struct net_device *dev,
 			      s32 rssi_level, gfp_t gfp);
 
 /**
+ * cfg80211_sta_mon_rssi_notify - Station's rssi out of range event
+ * @dev: network device
+ * @peer: Station's mac address
+ * @rssi_event: the triggered RSSI event
+ * @rssi_level: new RSSI level value or 0 if not available
+ * @gfp: context flags
+ *
+ * This function is called when a configured rssi threshold reached event
+ * occurs for a station.
+ */
+void
+cfg80211_sta_mon_rssi_notify(struct net_device *dev, const u8 *peer,
+		     enum nl80211_sta_mon_rssi_threshold_event rssi_event,
+		     s32 rssi_level, gfp_t gfp);
+
+/**
  * cfg80211_cqm_pktloss_notify - notify userspace about packetloss to peer
  * @dev: network device
  * @peer: peer's MAC address
include/uapi/linux/nl80211.h +62 -0

110 lines not on this page · raw message

net/wireless/core.c +21 -5
index c0fd8a8..7933337 100644
@@ -990,10 +990,25 @@ void wiphy_rfkill_set_hw_state(struct wiphy *wiphy, bool blocked)
 }
 EXPORT_SYMBOL(wiphy_rfkill_set_hw_state);
 
-void cfg80211_cqm_config_free(struct wireless_dev *wdev)
+void cfg80211_rssi_config_free(struct wireless_dev *wdev)
 {
-	kfree(wdev->cqm_config);
-	wdev->cqm_config = NULL;
+	struct cfg80211_rssi_config *rssi_config, *tmp;
+
+	if (list_empty(&wdev->rssi_config_list))
+		goto free;
+
+	list_for_each_entry_safe(rssi_config, tmp, &wdev->rssi_config_list,
+				 list) {
+		list_del(&rssi_config->list);
+		kfree(rssi_config);
+		if (list_empty(&wdev->rssi_config_list))
+			goto out;
+	}
+
+free:
+	kfree(wdev->rssi_config);
+out:
+	wdev->rssi_config = NULL;
 }
 
 void cfg80211_unregister_wdev(struct wireless_dev *wdev)
@@ -1023,7 +1038,7 @@ void cfg80211_unregister_wdev(struct wireless_dev *wdev)
 		break;
 	}
 
-	cfg80211_cqm_config_free(wdev);
+	cfg80211_rssi_config_free(wdev);
 }
 EXPORT_SYMBOL(cfg80211_unregister_wdev);
 
@@ -1159,6 +1174,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
 		spin_lock_init(&wdev->event_lock);
 		INIT_LIST_HEAD(&wdev->mgmt_registrations);
 		spin_lock_init(&wdev->mgmt_registrations_lock);
+		INIT_LIST_HEAD(&wdev->rssi_config_list);
 
 		/*
 		 * We get here also when the interface changes network namespaces,
@@ -1288,7 +1304,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
 			kzfree(wdev->wext.keys);
 #endif
 			flush_work(&wdev->disconnect_wk);
-			cfg80211_cqm_config_free(wdev);
+			cfg80211_rssi_config_free(wdev);
 		}
 		/*
 		 * synchronise (so that we won't find this netdev
net/wireless/core.h +4 -2
index 63eb1b5..17883ec 100644
@@ -260,10 +260,12 @@ struct cfg80211_beacon_registration {
 	u32 nlportid;
 };
 
-struct cfg80211_cqm_config {
+struct cfg80211_rssi_config {
+	struct list_head list;
 	u32 rssi_hyst;
 	s32 last_rssi_event_value;
 	int n_rssi_thresholds;
+	u8 addr[ETH_ALEN];
 	s32 rssi_thresholds[0];
 };
 
@@ -514,6 +516,6 @@ void cfg80211_stop_nan(struct cfg80211_registered_device *rdev,
 #define CFG80211_DEV_WARN_ON(cond)	({bool __r = (cond); __r; })
 #endif
 
-void cfg80211_cqm_config_free(struct wireless_dev *wdev);
+void cfg80211_rssi_config_free(struct wireless_dev *wdev);
 
 #endif /* __NET_WIRELESS_CORE_H */
net/wireless/nl80211.c +335 -53

486 lines not on this page · raw message

net/wireless/rdev-ops.h +31 -0
index 87479a5..47562b9 100644
@@ -1220,4 +1220,35 @@ static inline int rdev_del_pmk(struct cfg80211_registered_device *rdev,
 	return ret;
 }
 
+static inline int
+rdev_set_sta_mon_rssi_config(struct cfg80211_registered_device *rdev,
+			     struct net_device *dev, const u8 *peer,
+			     s32 rssi_tholds, u32 rssi_hyst)
+
+{
+	int ret;
+
+	trace_rdev_set_sta_mon_rssi_config(&rdev->wiphy, dev, peer,
+					   rssi_tholds, rssi_hyst);
+	ret = rdev->ops->set_sta_mon_rssi_config(&rdev->wiphy, dev, peer,
+						 rssi_tholds, rssi_hyst);
+	trace_rdev_return_int(&rdev->wiphy, ret);
+	return ret;
+}
+
+static inline int
+rdev_set_sta_mon_rssi_range_config(struct cfg80211_registered_device *rdev,
+				   struct net_device *dev, const u8 *peer,
+				   s32 low, s32 high)
+{
+	int ret;
+
+	trace_rdev_set_sta_mon_rssi_range_config(&rdev->wiphy, dev, peer,
+						 low, high);
+	ret = rdev->ops->set_sta_mon_rssi_range_config(&rdev->wiphy, dev, peer,
+						       low, high);
+	trace_rdev_return_int(&rdev->wiphy, ret);
+	return ret;
+}
+
 #endif /* __CFG80211_RDEV_OPS */
net/wireless/trace.h +74 -0

86 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

RFC v2 2/6 mac80211: Add support to configure rssi threshold for AP mode

In reply to Tamizh chelvam

This patch add support to configure station specific single or multi rssi thresholds using ieee80211_set_sta_mon_rssi_config and ieee80211_set_sta_mon_rssi_range_confg APIs. This configuration is used for tracking the connected station's signal strength.

---
 net/mac80211/cfg.c      | 75 +++++++++++++++++++++++++++++++++++++++++++++++++
 net/mac80211/sta_info.h | 18 ++++++++++++
 2 files changed, 93 insertions(+)
net/mac80211/cfg.c +75 -0
index 85dbaa8..0e2047c 100644
@@ -3705,6 +3705,79 @@ static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
 	return 0;
 }
 
+static int ieee80211_set_sta_mon_rssi_config(struct wiphy *wiphy,
+					     struct net_device *dev,
+					     const u8 *peer, s32 rssi_thold,
+					     u32 rssi_hyst)
+{
+	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	struct sta_info *sta;
+
+	if (sdata->vif.type == NL80211_IFTYPE_AP &&
+	    (!sdata->vif.bss_conf.enable_beacon ||
+	    !wiphy_ext_feature_isset(sdata->local->hw.wiphy,
+			NL80211_EXT_FEATURE_STA_MON_RSSI_CONFIG)))
+		return -EOPNOTSUPP;
+
+	mutex_lock(&sdata->local->sta_mtx);
+
+	sta = sta_info_get_bss(sdata, peer);
+	if (!sta) {
+		mutex_unlock(&sdata->local->sta_mtx);
+		return -ENOENT;
+	}
+
+	if (sta->rssi_thold == rssi_thold &&
+	    sta->rssi_hyst == rssi_hyst)
+		goto unlock;
+
+	sta->rssi_thold = rssi_thold;
+	sta->rssi_hyst = rssi_hyst;
+	sta->rssi_low = 0;
+	sta->rssi_high = 0;
+	sta->last_sta_mon_event_signal = 0;
+unlock:
+	mutex_unlock(&sdata->local->sta_mtx);
+	return 0;
+}
+
+static int ieee80211_set_sta_mon_rssi_range_confg(struct wiphy *wiphy,
+						  struct net_device *dev,
+						  const u8 *peer,
+						  s32 rssi_low, s32 rssi_high)
+{
+	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	struct sta_info *sta;
+
+	if (sdata->vif.type == NL80211_IFTYPE_AP &&
+	    (!sdata->vif.bss_conf.enable_beacon ||
+	    !wiphy_ext_feature_isset(sdata->local->hw.wiphy,
+			NL80211_EXT_FEATURE_STA_MON_RSSI_LIST)))
+		return -EOPNOTSUPP;
+
+	mutex_lock(&sdata->local->sta_mtx);
+
+	sta = sta_info_get_bss(sdata, peer);
+	if (!sta) {
+		mutex_unlock(&sdata->local->sta_mtx);
+		return -ENOENT;
+	}
+
+	if (sta->rssi_low == rssi_low &&
+	    sta->rssi_high == rssi_high)
+		goto unlock;
+
+	sta->rssi_thold = 0;
+	sta->rssi_hyst = 0;
+	sta->rssi_low = rssi_low;
+	sta->rssi_high = rssi_high;
+	sta->last_sta_mon_event_signal = 0;
+
+unlock:
+	mutex_unlock(&sdata->local->sta_mtx);
+	return 0;
+}
+
 const struct cfg80211_ops mac80211_config_ops = {
 	.add_virtual_intf = ieee80211_add_iface,
 	.del_virtual_intf = ieee80211_del_iface,
@@ -3798,4 +3871,6 @@ static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
 	.del_nan_func = ieee80211_del_nan_func,
 	.set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
 	.tx_control_port = ieee80211_tx_control_port,
+	.set_sta_mon_rssi_config = ieee80211_set_sta_mon_rssi_config,
+	.set_sta_mon_rssi_range_config = ieee80211_set_sta_mon_rssi_range_confg,
 };
net/mac80211/sta_info.h +18 -0
index f64eb86..701eb37 100644
@@ -481,6 +481,18 @@ struct ieee80211_sta_rx_stats {
  * @pcpu_rx_stats: per-CPU RX statistics, assigned only if the driver needs
  *	this (by advertising the USES_RSS hw flag)
  * @status_stats: TX status statistics
+ * @rssi_thold: RSSI threshold to monitor station's signal strength, a zero
+ *	value implies disabled. As with the cfg80211 callback, a change here
+ *	should cause an event to be sent indicating where the current value
+ *	is in relation to the newly configured threshold
+ * @rssi_hyst: Station's RSSI hysteresis
+ * @rssi_low: RSSI lower threshold to monitor station's signal strength, a zero
+ *	value implies disabled.  This is an alternative mechanism to the single
+ *	threshold event and can't be enabled simultaneously with it
+ * @rssi_high: RSSI upper threshold for station
+ * @last_sta_mon_event_signal: Last signal strength average for a station
+ *	that triggered a sta_mon event. 0 indicates that no event has been
+ *	generated for the current association
  */
 struct sta_info {
 	/* General information, mostly static */
@@ -581,6 +593,12 @@ struct sta_info {
 
 	struct cfg80211_chan_def tdls_chandef;
 
+	s32 rssi_thold;
+	u32 rssi_hyst;
+	s32 rssi_low;
+	s32 rssi_high;
+	int last_sta_mon_event_signal;
+
 	/* keep last! */
 	struct ieee80211_sta sta;
 };
Signature · 1 line
1.9.1
#3 lore raw

RFC v2 3/6 mac80211: Implement functionality to monitor station's rssi threshold cross

In reply to Tamizh chelvam

Triggers cfg80211_sta_mon_rssi_notify with the corresponding event when station signal goes out of configured threshold. It uses rx data signal to check against rssi threshold configured by the user.
This event will be useful for the application like steering to take decision on any station depends on its current capability.

---
 include/net/mac80211.h  |  7 ++++++
 net/mac80211/rx.c       | 65 ++++++++++++++++++++++++++++++++++++++++++++++++-
 net/mac80211/sta_info.h |  4 +++
 3 files changed, 75 insertions(+), 1 deletion(-)
include/net/mac80211.h +7 -0
index d2279b2..7b3d505 100644
@@ -803,6 +803,13 @@ enum mac80211_rate_control_flags {
 };
 
 
+/*
+ * How many frames need to have been used in average station's
+ * signal strength before checking against the threshold
+ */
+#define IEEE80211_STA_SIGNAL_AVE_MIN_COUNT	4
+
+
 /* there are 40 bytes if you don't need the rateset to be kept */
 #define IEEE80211_TX_INFO_DRIVER_DATA_SIZE 40
 
net/mac80211/rx.c +64 -1

85 lines not on this page · raw message

net/mac80211/sta_info.h +4 -0
index 701eb37..1599973 100644
@@ -493,6 +493,9 @@ struct ieee80211_sta_rx_stats {
  * @last_sta_mon_event_signal: Last signal strength average for a station
  *	that triggered a sta_mon event. 0 indicates that no event has been
  *	generated for the current association
+ * @count_rx_signal: Number of data frames used in averaging station signal.
+ *	This can be used to avoid generating less reliable station rssi cross
+ *	events that would be based only on couple of received frames.
  */
 struct sta_info {
 	/* General information, mostly static */
@@ -598,6 +601,7 @@ struct sta_info {
 	s32 rssi_low;
 	s32 rssi_high;
 	int last_sta_mon_event_signal;
+	unsigned int count_rx_signal;
 
 	/* keep last! */
 	struct ieee80211_sta sta;
Signature · 1 line
1.9.1
#4 lore raw

RFC v2 4/6 cfg80211: Add support to configure station specific txrate threshold for AP mode

In reply to Tamizh chelvam

This patch add support to configure station specific txrate threshold to monitor change in txrate for stations. This will be useful for the user application like steering to configure and monitor the change event of txrate for the station.

NL80211_ATTR_STA_MON_LOW_TXRATE_THOLD and NL80211_ATTR_STA_MON_HIGH_TXRATE_THOLD used with NL80211_CMD_STA_MON command to configure the txrate threshold and the configuration will be represented in 100kbps.

cfg80211_sta_mon_txrate_notify introduce to notify txrate for a station goes out of range using NL80211_CMD_NOTIFY_STA_MON command.

NL80211_EXT_FEATURE_STA_MON_TXRATE_CONFIG flag needs to be advertised by the drvier to allow and monitor txrate threshold configuration.

---
 include/net/cfg80211.h       | 26 ++++++++++++++++
 include/uapi/linux/nl80211.h | 34 ++++++++++++++++++++
 net/wireless/nl80211.c       | 74 ++++++++++++++++++++++++++++++++++++++++++++
 net/wireless/rdev-ops.h      | 17 ++++++++++
 net/wireless/trace.h         | 49 +++++++++++++++++++++++++++++
 5 files changed, 200 insertions(+)
include/net/cfg80211.h +26 -0
index 7e7a0bf..4456e2e 100644
@@ -2984,6 +2984,10 @@ struct cfg80211_external_auth_params {
  *	The driver should set %NL80211_EXT_FEATURE_STA_MON_RSSI_LIST if this
  *	method is implemented. If it is provided then there's no point providing
  *	@set_sta_mon_rssi_config.
+ * @set_sta_mon_txrate_config: Configure low and high TXRATE threshold in 100kbs
+ *	for a connected station. The driver should(soon) send an event
+ *	indicating the current attempted frame txrate level is above/below the
+ *	configured threshold.
  */
 struct cfg80211_ops {
 	int	(*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -3293,6 +3297,11 @@ struct cfg80211_ops {
 						 struct net_device *dev,
 						 const u8 *addr,
 						 s32 rssi_low, s32 rssi_high);
+	int     (*set_sta_mon_txrate_config)(struct wiphy *wiphy,
+					     struct net_device *dev,
+					     const u8 *addr,
+					     u32 low_txrate_thold,
+					     u32 high_txrate_thold);
 };
 
 /*
@@ -5813,6 +5822,23 @@ void cfg80211_cqm_rssi_notify(struct net_device *dev,
 		     s32 rssi_level, gfp_t gfp);
 
 /**
+ * cfg80211_sta_mon_txrate_notify - txrate event for connected stations
+ * @dev: network device
+ * @peer: peer's MAC address
+ * @txrate_event: the triggered TX RATE event
+ * @txrate_level: new TX RATE level value or 0 if not available
+ * @gfp: context flags
+ *
+ * This function is called when a average of attempted frame txrate crossed
+ * above configured high txrate or below configured low txrate event
+ * occurs for a station.
+ */
+void
+cfg80211_sta_mon_txrate_notify(struct net_device *dev, const u8 *peer,
+		enum nl80211_sta_mon_txrate_threshold_event txrate_event,
+		u32 txrate_level, gfp_t gfp);
+
+/**
  * cfg80211_cqm_pktloss_notify - notify userspace about packetloss to peer
  * @dev: network device
  * @peer: peer's MAC address
include/uapi/linux/nl80211.h +34 -0
index fa1fed1..a8b5e3d 100644
@@ -4266,6 +4266,15 @@ enum nl80211_attr_cqm {
  * @NL80211_ATTR_STA_MON_RSSI_THRESHOLD_EVENT: RSSI threshold event
  * @NL80211_ATTR_STA_MON_RSSI_LEVEL: the RSSI value in dBm that triggered the
  *	RSSI threshold event.
+ * @NL80211_ATTR_STA_MON_LOW_TXRATE_THOLD: TX_RATE threshold in 100kbps. This
+ *	u32 attribute specifies the low txrate threshold. Event will be sent
+ *	if the txrate for a station goes lesser than this threshold.
+ * @NL80211_ATTR_STA_MON_HIGH_TXRATE_THOLD: TX_RATE threshold in 100kbps. This
+ *	u32 attribute specifies the upper txrate threshold. Event will be sent
+ *	if the txrate for a station goes greater than this threshold.
+ * @NL80211_ATTR_STA_MON_TXRATE_THRESHOLD_EVENT: TX_RATE threshold cross event
+ * @NL80211_ATTR_STA_MON_TXRATE_LEVEL: TXRATE for a station in 100kbps that
+ *	triggered the TX_RATE threshold cross event.
  */
 enum nl80211_attr_sta_mon {
 	__NL80211_ATTR_STA_MON_INVALID,
@@ -4273,6 +4282,10 @@ enum nl80211_attr_sta_mon {
 	NL80211_ATTR_STA_MON_RSSI_HYST,
 	NL80211_ATTR_STA_MON_RSSI_THRESHOLD_EVENT,
 	NL80211_ATTR_STA_MON_RSSI_LEVEL,
+	NL80211_ATTR_STA_MON_LOW_TXRATE_THOLD,
+	NL80211_ATTR_STA_MON_HIGH_TXRATE_THOLD,
+	NL80211_ATTR_STA_MON_TXRATE_THRESHOLD_EVENT,
+	NL80211_ATTR_STA_MON_TXRATE_LEVEL,
 
 	/* keep last */
 	__NL80211_ATTR_STA_MON_AFTER_LAST,
@@ -4305,6 +4318,21 @@ enum nl80211_sta_mon_rssi_threshold_event {
 	NL80211_STA_MON_RSSI_THRESHOLD_EVENT_HIGH,
 };
 
+/**
+ * enum nl80211_sta_mon_txrate_threshold_event - TX_RATE threshold event
+ * @NL80211_STA_MON_TXRATE_THRESHOLD_IN_RANGE: The TX_RATE level is in between
+ *	low and high threshold
+ * @NL80211_STA_MON_TXRATE_THRESHOLD_EVENT_LOW: The TX_RATE level is lower than
+ *	the configured threshold
+ * @NL80211_STA_MON_TXRATE_THRESHOLD_EVENT_HIGH: The TX_RATE is higher than the
+ *      configured threshold
+ */
+enum nl80211_sta_mon_txrate_threshold_event {
+	NL80211_STA_MON_TXRATE_THRESHOLD_IN_RANGE,
+	NL80211_STA_MON_TXRATE_THRESHOLD_EVENT_LOW,
+	NL80211_STA_MON_TXRATE_THRESHOLD_EVENT_HIGH,
+};
+
 
 /**
  * enum nl80211_tx_power_setting - TX power adjustment
@@ -5100,6 +5128,11 @@ enum nl80211_feature_flags {
  * @NL80211_EXT_FEATURE_STA_MON_RSSI_LIST: With this driver the
  *	%NL80211_ATTR_STA_MON_RSSI_THOLD attribute accepts a list of zero or
  *	more RSSI threshold values to monitor rather than exactly one threshold.
+ * @NL80211_EXT_FEATURE_STA_MON_TXRATE_CONFIG: With this driver will accept
+ *	%NL80211_ATTR_STA_MON_LOW_TXRATE_THOLD attribute as low txrate and
+ *	%NL80211_ATTR_STA_MON_HIGH_TXRATE_THOLD attribute as high txrate
+ *	for AP/AP_VLAN/P2P_GO interface to monitor txrate for the connected
+ *	stations and the drvier should advertise txrate via ieee80211_tx_status.
  *
  * @NUM_NL80211_EXT_FEATURES: number of extended features.
  * @MAX_NL80211_EXT_FEATURES: highest extended feature index.
@@ -5134,6 +5167,7 @@ enum nl80211_ext_feature_index {
 	NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211,
 	NL80211_EXT_FEATURE_STA_MON_RSSI_CONFIG,
 	NL80211_EXT_FEATURE_STA_MON_RSSI_LIST,
+	NL80211_EXT_FEATURE_STA_MON_TXRATE_CONFIG,
 
 	/* add new features before the definition below */
 	NUM_NL80211_EXT_FEATURES,
net/wireless/nl80211.c +74 -0

98 lines not on this page · raw message

net/wireless/rdev-ops.h +17 -0
index 47562b9..5c3289c 100644
@@ -1251,4 +1251,21 @@ static inline int rdev_del_pmk(struct cfg80211_registered_device *rdev,
 	return ret;
 }
 
+static inline int
+rdev_set_sta_mon_txrate_config(struct cfg80211_registered_device *rdev,
+			       struct net_device *dev, const u8 *peer,
+			       u32 low_txrate_thold, u32 high_txrate_thold)
+{
+	int ret;
+
+	trace_rdev_set_sta_mon_txrate_config(&rdev->wiphy, dev, peer,
+					     low_txrate_thold,
+					     high_txrate_thold);
+	ret = rdev->ops->set_sta_mon_txrate_config(&rdev->wiphy, dev, peer,
+						   low_txrate_thold,
+						   high_txrate_thold);
+	trace_rdev_return_int(&rdev->wiphy, ret);
+	return ret;
+}
+
 #endif /* __CFG80211_RDEV_OPS */
net/wireless/trace.h +49 -0

55 lines not on this page · raw message

Signature · 1 line
1.9.1
#5 lore raw

RFC v2 5/6 mac80211: Add support to configure txrate threshold for station

In reply to Tamizh chelvam

This patch add support to configure station specific low and high txrate thresholds using ieee80211_set_sta_mon_txrate_config API. This configuration is used for tracking the txrate for connected stations.

---
 net/mac80211/cfg.c      | 35 +++++++++++++++++++++++++++++++++++
 net/mac80211/sta_info.h |  5 +++++
 2 files changed, 40 insertions(+)
net/mac80211/cfg.c +35 -0
index 0e2047c..ba2555d 100644
@@ -3778,6 +3778,40 @@ static int ieee80211_set_sta_mon_rssi_range_confg(struct wiphy *wiphy,
 	return 0;
 }
 
+static int ieee80211_set_sta_mon_txrate_config(struct wiphy *wiphy,
+					       struct net_device *dev,
+					       const u8 *peer,
+					       u32 low_txrate_thold,
+					       u32 high_txrate_thold)
+{
+	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	struct sta_info *sta;
+
+	if (sdata->vif.type == NL80211_IFTYPE_AP &&
+	    !wiphy_ext_feature_isset(sdata->local->hw.wiphy,
+			NL80211_EXT_FEATURE_STA_MON_TXRATE_CONFIG))
+		return -EOPNOTSUPP;
+
+	mutex_lock(&sdata->local->sta_mtx);
+
+	sta = sta_info_get_bss(sdata, peer);
+	if (!sta) {
+		mutex_unlock(&sdata->local->sta_mtx);
+		return -ENOENT;
+	}
+
+	if (sta->txrate_low == low_txrate_thold &&
+	    sta->txrate_high == high_txrate_thold)
+		goto unlock;
+
+	sta->txrate_low = low_txrate_thold;
+	sta->txrate_high = high_txrate_thold;
+
+unlock:
+	mutex_unlock(&sdata->local->sta_mtx);
+	return 0;
+}
+
 const struct cfg80211_ops mac80211_config_ops = {
 	.add_virtual_intf = ieee80211_add_iface,
 	.del_virtual_intf = ieee80211_del_iface,
@@ -3873,4 +3907,5 @@ static int ieee80211_set_sta_mon_rssi_range_confg(struct wiphy *wiphy,
 	.tx_control_port = ieee80211_tx_control_port,
 	.set_sta_mon_rssi_config = ieee80211_set_sta_mon_rssi_config,
 	.set_sta_mon_rssi_range_config = ieee80211_set_sta_mon_rssi_range_confg,
+	.set_sta_mon_txrate_config = ieee80211_set_sta_mon_txrate_config,
 };
net/mac80211/sta_info.h +5 -0
index 1599973..c73d010 100644
@@ -496,6 +496,8 @@ struct ieee80211_sta_rx_stats {
  * @count_rx_signal: Number of data frames used in averaging station signal.
  *	This can be used to avoid generating less reliable station rssi cross
  *	events that would be based only on couple of received frames.
+ * @txrate_low: TXRATE lower threshold for a station to monitor
+ * @txrate_high: TXRATE upper threshold for a station to monitor
  */
 struct sta_info {
 	/* General information, mostly static */
@@ -603,6 +605,9 @@ struct sta_info {
 	int last_sta_mon_event_signal;
 	unsigned int count_rx_signal;
 
+	u32 txrate_low;
+	u32 txrate_high;
+
 	/* keep last! */
 	struct ieee80211_sta sta;
 };
Signature · 1 line
1.9.1
#6 lore raw

RFC v2 6/6 mac80211: Implement functionality to monitor txrate cross event for station

In reply to Tamizh chelvam

Trigger cfg80211_sta_mon_txrate_notify with the corresponding txrate event when the txrate for a station goes out of configured range. This event will be useful for the application like steering to take decision on any station depends on its current capability.

---
 include/net/mac80211.h  |  5 +++++
 net/mac80211/cfg.c      |  1 +
 net/mac80211/sta_info.h | 10 ++++++++++
 net/mac80211/status.c   | 40 +++++++++++++++++++++++++++++++++++++++-
 4 files changed, 55 insertions(+), 1 deletion(-)
include/net/mac80211.h +5 -0
index 7b3d505..7023f40 100644
@@ -809,6 +809,11 @@ enum mac80211_rate_control_flags {
  */
 #define IEEE80211_STA_SIGNAL_AVE_MIN_COUNT	4
 
+/* Number of txrate count need to have been used in average station's
+ * txrate before checking against the threshold
+ */
+#define IEEE80211_STA_TXRATE_AVE_MIN_COUNT	4
+
 
 /* there are 40 bytes if you don't need the rateset to be kept */
 #define IEEE80211_TX_INFO_DRIVER_DATA_SIZE 40
net/mac80211/cfg.c +1 -0
index ba2555d..0f06b0b 100644
@@ -3806,6 +3806,7 @@ static int ieee80211_set_sta_mon_txrate_config(struct wiphy *wiphy,
 
 	sta->txrate_low = low_txrate_thold;
 	sta->txrate_high = high_txrate_thold;
+	sta->last_txrate_event = 0;
 
 unlock:
 	mutex_unlock(&sdata->local->sta_mtx);
net/mac80211/sta_info.h +10 -0
index c73d010..e23d916 100644
@@ -418,6 +418,8 @@ struct ieee80211_sta_rx_stats {
  */
 #define STA_SLOW_THRESHOLD 6000 /* 6 Mbps */
 
+DECLARE_EWMA(sta_txrate, 4, 4)
+
 /**
  * struct sta_info - STA information
  *
@@ -498,6 +500,11 @@ struct ieee80211_sta_rx_stats {
  *	events that would be based only on couple of received frames.
  * @txrate_low: TXRATE lower threshold for a station to monitor
  * @txrate_high: TXRATE upper threshold for a station to monitor
+ * @count_sta_txrate: Number of transmitted data frames used in ave_sta_txrate
+ * @last_txrate_event: Last txrate event that triggered sta_mon event for a
+ *	station
+ * @ave_sta_txrate: Average txrate to check against the txrate_low and
+ *	txrate_high. Values expressed in 100kbps
  */
 struct sta_info {
 	/* General information, mostly static */
@@ -608,6 +615,9 @@ struct sta_info {
 	u32 txrate_low;
 	u32 txrate_high;
 
+	unsigned int count_sta_txrate;
+	enum nl80211_sta_mon_txrate_threshold_event last_txrate_event;
+	struct ewma_sta_txrate ave_sta_txrate;
 	/* keep last! */
 	struct ieee80211_sta sta;
 };
net/mac80211/status.c +39 -1
index 743e89c..6656b04 100644
@@ -699,6 +699,40 @@ void ieee80211_tx_monitor(struct ieee80211_local *local, struct sk_buff *skb,
 	dev_kfree_skb(skb);
 }
 
+static void ieee80211_sta_mon_txrate_thold_check(struct sta_info *sta)
+{
+	struct rate_info rinfo;
+	enum nl80211_sta_mon_txrate_threshold_event sta_txrate_event;
+	int txrate;
+
+	if (!sta->txrate_high)
+		return;
+
+	sta_set_rate_info_tx(sta, &sta->tx_stats.last_rate, &rinfo);
+	txrate = cfg80211_calculate_bitrate(&rinfo);
+	ewma_sta_txrate_add(&sta->ave_sta_txrate, txrate);
+	sta->count_sta_txrate++;
+
+	if (sta->count_sta_txrate < IEEE80211_STA_TXRATE_AVE_MIN_COUNT)
+		return;
+
+	txrate = ewma_sta_txrate_read(&sta->ave_sta_txrate);
+
+	if (txrate < sta->txrate_low)
+		sta_txrate_event = NL80211_STA_MON_TXRATE_THRESHOLD_EVENT_LOW;
+	else if (txrate > sta->txrate_high)
+		sta_txrate_event = NL80211_STA_MON_TXRATE_THRESHOLD_EVENT_HIGH;
+	else
+		sta_txrate_event = NL80211_STA_MON_TXRATE_THRESHOLD_IN_RANGE;
+
+	if (sta_txrate_event != sta->last_txrate_event) {
+		cfg80211_sta_mon_txrate_notify(sta->sdata->dev, sta->addr,
+					       sta_txrate_event, txrate,
+					       GFP_ATOMIC);
+		sta->last_txrate_event = sta_txrate_event;
+	}
+}
+
 static void __ieee80211_tx_status(struct ieee80211_hw *hw,
 				  struct ieee80211_tx_status *status)
 {
@@ -748,9 +782,13 @@ static void __ieee80211_tx_status(struct ieee80211_hw *hw,
 
 		if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL) &&
 		    (ieee80211_is_data(hdr->frame_control)) &&
-		    (rates_idx != -1))
+		    (rates_idx != -1)) {
 			sta->tx_stats.last_rate =
 				info->status.rates[rates_idx];
+			if (wiphy_ext_feature_isset(hw->wiphy,
+				NL80211_EXT_FEATURE_STA_MON_TXRATE_CONFIG))
+				ieee80211_sta_mon_txrate_thold_check(sta);
+		}
 
 		if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
 		    (ieee80211_is_data_qos(fc))) {
Signature · 1 line
1.9.1