Add DFS master ability
Subsystems (2)
v9 cover Add DFS master ability
This is patch series version 9 of the DFS master ability, based on Victor Goldenshteins original work. See changelog in the various patches for details. The main changes to v8 are:
* checked and fixed locking - note the new patch 1 changing the locking for use/release_channel to remove rtnl dependency
* report radar detected and NOP only once
* fix gfp usage
* merge "nl80211: allow DFS in start_ap" in the main nl80211 patch
* various style changes
* rebased on latest master, of course
As always, thanks a lot to Johannes for review and support.
I've verified the implementation (again) with ath9k a patched hostapd (patches to be released later). This time also lock verified (I used a tainted kernel before, so locking was disabled ...).
iw patches for interface combinations and DFS state handling are attached as well.
One open issue (still) remains: On my system, DFS channels are flagged with NO_IBSS and DISABLED, this is due to my country code setting to 00. I can manually circumvent that, but should we find a proper solution for this? This regularity intersection gives me quite a bit of a headache ...
Simon Wunderlich (3):
mac80211: lock AP_VLAN list with iflist_mtx nl80211/cfg80211: add radar detection command/event
mac80211: add radar detection command/event
include/net/cfg80211.h | 46 ++++++++++++++ include/net/mac80211.h | 14 +++++ include/uapi/linux/nl80211.h | 61 +++++++++++++++++++ net/mac80211/cfg.c | 51 +++++++++++++++- net/mac80211/chan.c | 37 +++++++++++- net/mac80211/ieee80211_i.h | 15 +++++ net/mac80211/iface.c | 23 ++++++- net/mac80211/main.c | 3 + net/mac80211/mlme.c | 56 ++++++++++++++++++ net/mac80211/scan.c | 3 + net/mac80211/trace.h | 19 ++++++ net/wireless/chan.c | 129 +++++++++++++++++++++++++++++++++++++++- net/wireless/core.c | 3 + net/wireless/core.h | 28 +++++++++ net/wireless/mlme.c | 121 +++++++++++++++++++++++++++++++++++++ net/wireless/nl80211.c | 135 ++++++++++++++++++++++++++++++++++++++++-- net/wireless/nl80211.h | 7 +++ net/wireless/reg.c | 3 + net/wireless/scan.c | 10 ---- net/wireless/trace.h | 47 +++++++++++++++ 20 files changed, 790 insertions(+), 21 deletions(-)
Signature · 1 line
1.7.10.4
PATCH v9 1/3 mac80211: lock AP_VLAN list with iflist_mtx
To remove the dependency to rtnl_lock() for ieee80211_vif_use/release_channel in AP mode, protect the AP_VLAN list with local->iflist_mtx instead.
RTNL can not be used from within mac80211 workers, but the DFS AP interface requires to release channels (after DFS channel availability checks).
--- net/mac80211/cfg.c | 14 ++++++++++++++ net/mac80211/chan.c | 4 ++-- net/mac80211/ieee80211_i.h | 2 ++ net/mac80211/iface.c | 11 ++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-)
net/mac80211/cfg.c +14 -0
@@ -923,8 +923,10 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, sdata->smps_mode =IEEE80211_SMPS_OFF ; sdata->needed_rx_chains = sdata->local->rx_chains; +mutex_lock (&sdata->local->iflist_mtx); err =ieee80211_vif_use_channel (sdata, ¶ms->chandef,IEEE80211_CHANCTX_SHARED ); +mutex_unlock (&sdata->local->iflist_mtx);if (err)return err;
@@ -934,12 +936,14 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,*/ sdata->control_port_protocol = params->crypto.control_port_ethertype; sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt; +mutex_lock (&sdata->local->iflist_mtx);list_for_each_entry (vlan, &sdata->u.ap.vlans, u.vlan.list) { vlan->control_port_protocol = params->crypto.control_port_ethertype; vlan->control_port_no_encrypt = params->crypto.control_port_no_encrypt; } +mutex_unlock (&sdata->local->iflist_mtx); sdata->vif.bss_conf.beacon_int = params->beacon_interval; sdata->vif.bss_conf.dtim_period = params->dtim_period;
@@ -972,8 +976,10 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,ieee80211_bss_info_change_notify (sdata, changed);netif_carrier_on (dev); +mutex_lock (&sdata->local->iflist_mtx);list_for_each_entry (vlan, &sdata->u.ap.vlans, u.vlan.list)netif_carrier_on (vlan->dev); +mutex_unlock (&sdata->local->iflist_mtx);return 0 ; }
@@ -1012,8 +1018,10 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev) old_probe_resp =rtnl_dereference (sdata->u.ap.probe_resp);/* turn off carrier for this interface and dependent VLANs */ +mutex_lock (&local->iflist_mtx);list_for_each_entry (vlan, &sdata->u.ap.vlans, u.vlan.list)netif_carrier_off (vlan->dev); +mutex_unlock (&local->iflist_mtx);netif_carrier_off (dev);/* remove beacon and probe response */
@@ -1023,12 +1031,16 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)if (old_probe_resp)kfree_rcu (old_probe_resp, rcu_head); +mutex_lock (&local->iflist_mtx);list_for_each_entry (vlan, &sdata->u.ap.vlans, u.vlan.list)sta_info_flush_defer (vlan); +mutex_unlock (&local->iflist_mtx);sta_info_flush_defer (sdata);rcu_barrier (); +mutex_lock (&local->iflist_mtx);list_for_each_entry (vlan, &sdata->u.ap.vlans, u.vlan.list)sta_info_flush_cleanup (vlan); +mutex_unlock (&local->iflist_mtx);sta_info_flush_cleanup (sdata); sdata->vif.bss_conf.enable_beacon = false;
@@ -1041,7 +1053,9 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev) local->total_ps_buffered -=skb_queue_len (&sdata->u.ap.ps.bc_buf);skb_queue_purge (&sdata->u.ap.ps.bc_buf); +mutex_lock (&local->iflist_mtx);ieee80211_vif_release_channel (sdata); +mutex_unlock (&local->iflist_mtx);return 0 ; }
net/mac80211/chan.c +2 -2
@@ -202,7 +202,7 @@ static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata)struct ieee80211_sub_if_data *vlan;/* for the VLAN list */ -ASSERT_RTNL (); +lockdep_assert_held (&local->iflist_mtx);list_for_each_entry (vlan, &sdata->u.ap.vlans, u.vlan.list)rcu_assign_pointer (vlan->vif.chanctx_conf,NULL ); }
@@ -330,7 +330,7 @@ int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata,struct ieee80211_sub_if_data *vlan;/* for the VLAN list */ -ASSERT_RTNL (); +lockdep_assert_held (&local->iflist_mtx);list_for_each_entry (vlan, &sdata->u.ap.vlans, u.vlan.list)rcu_assign_pointer (vlan->vif.chanctx_conf, &ctx->conf); }
net/mac80211/ieee80211_i.h +2 -0
@@ -294,6 +294,7 @@ struct ieee80211_if_ap {struct beacon_data __rcu *beacon;struct probe_resp __rcu *probe_resp; +/* protected with local->iflist_mtx */ struct list_head vlans;struct ps_data ps;
@@ -306,6 +307,7 @@ struct ieee80211_if_wds { };struct ieee80211_if_vlan { +/* protected with local->iflist_mtx */ struct list_head list;/* used for all tx if the VLAN is configured to 4-addr mode */
net/mac80211/iface.c +10 -1
@@ -517,7 +517,9 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)if (!sdata->bss)return -ENOLINK ; +mutex_lock (&local->iflist_mtx);list_add (&sdata->u.vlan.list, &sdata->bss->vlans); +mutex_unlock (&local->iflist_mtx); master =container_of (sdata->bss, struct ieee80211_sub_if_data, u.ap);
@@ -717,8 +719,11 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)drv_stop (local); err_del_bss: sdata->bss =NULL ; -if (sdata->vif.type ==NL80211_IFTYPE_AP_VLAN ) +if (sdata->vif.type ==NL80211_IFTYPE_AP_VLAN ) { +mutex_lock (&sdata->local->iflist_mtx);list_del (&sdata->u.vlan.list); +mutex_unlock (&sdata->local->iflist_mtx); + }/* might already be clear but that doesn't matter */ clear_bit (SDATA_STATE_RUNNING , &sdata->state);return res;
@@ -821,10 +826,12 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,if (sdata->vif.type ==NL80211_IFTYPE_AP ) {struct ieee80211_sub_if_data *vlan, *tmpsdata; +mutex_lock (&local->iflist_mtx);/* down all dependent devices, that is VLANs */ list_for_each_entry_safe (vlan, tmpsdata, &sdata->u.ap.vlans, u.vlan.list)dev_close (vlan->dev); +mutex_unlock (&local->iflist_mtx);WARN_ON (!list_empty (&sdata->u.ap.vlans)); }else if (sdata->vif.type ==NL80211_IFTYPE_STATION ) {ieee80211_mgd_stop (sdata);
@@ -835,7 +842,9 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,switch (sdata->vif.type) {case NL80211_IFTYPE_AP_VLAN : +mutex_lock (&sdata->local->iflist_mtx);list_del (&sdata->u.vlan.list); +mutex_unlock (&sdata->local->iflist_mtx);rcu_assign_pointer (sdata->vif.chanctx_conf,NULL );/* no need to tell driver */ break ;
Signature · 1 line
1.7.10.4
Johannes Berg
maintainerRe: [PATCHv9 1/3] mac80211: lock AP_VLAN list with iflist_mtx
Quoted 7 lines · Simon Wunderlich
To remove the dependency to
rtnl_lock()for ieee80211_vif_use/release_channel in AP mode, protect theAP_VLANlist withlocal->iflist_mtxinstead.RTNL can not be used from within mac80211 workers, but the DFS AP interface requires to release channels (after DFS channel availability checks).
I have to say ... I don't like this churn.
Quoted 16 lines
net/mac80211/cfg.c +2
-0@@ -934,12 +936,14 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,*/ sdata->control_port_protocol = params->crypto.control_port_ethertype; sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt; +mutex_lock (&sdata->local->iflist_mtx);list_for_each_entry (vlan, &sdata->u.ap.vlans, u.vlan.list) { vlan->control_port_protocol = params->crypto.control_port_ethertype; vlan->control_port_no_encrypt = params->crypto.control_port_no_encrypt; } +mutex_unlock (&sdata->local->iflist_mtx); sdata->vif.bss_conf.beacon_int = params->beacon_interval; sdata->vif.bss_conf.dtim_period = params->dtim_period;
net/mac80211/cfg.c static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, · line 982
Quoted 7 lines
net/mac80211/cfg.c +2
-0@@ -972,8 +976,10 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,ieee80211_bss_info_change_notify (sdata, changed);netif_carrier_on (dev); +mutex_lock (&sdata->local->iflist_mtx);list_for_each_entry (vlan, &sdata->u.ap.vlans, u.vlan.list)netif_carrier_on (vlan->dev); +mutex_unlock (&sdata->local->iflist_mtx);
Things like this are also questionable -- it still only works because the RTNL is there.
I'm not sure what the solution would be though -- maybe allowing/using both locks.
johannes
PATCH v9 2/3 nl80211/cfg80211: add radar detection command/event
In reply to Simon WunderlichAdd new NL80211_CMD_RADAR_DETECT, which starts the Channel Availability Check (CAC). This command will also notify the usermode about events (CAC finished, CAC aborted, radar detected, NOP finished). Once radar detection has started it should continuously monitor for radars as long as the channel is active.
This patch enables DFS for AP mode in nl80211/cfg80211.
based on original patch by Victor Goldenshtein <[email protected]>
---
Changes to PATCHv8:
* report radar and NOP only for hw (don't report wdev)
* split radar and cac event callbacks
* move cfg80211_chandef_dfs_required to core.h
* allow radar detect events for phy without wdev
* various style issues (kerneldoc)
* return better error codes
* merged patch "nl80211: allow DFS in start_ap"
Changes to PATCHv7:
* initialize ieee80211_dfs_state enum with numbers
* fix documentation for dfs_state_entered
* move NL80211_DFS_MIN_CAC_TIME_MS/NL80211_DFS_MIN_NOP_TIME_MS to cfg80211.h
* remove NL80211_FEATURE_DFS
* fix cfg80211_chandef_get_width return value
* beautify cfg80211_dfs_channels_update_work
* fix nl80211_start_radar_detection return code for dfs_required
* fix rdev->devlist_mtx for cac_started
* add cac_started_time and use it for CAC
* remove wrong check in nl80211_join_ibss()
* add warning for not defined event in cfg80211_radar_event()
* unexport cfg80211_chandef_dfs_required()
* use wdev->channel instead of wdev->preset_chandef.chan for CAC
* report dfs state and how long it is active to userspace
* add event when NOP has been finished
* from "nl80211: allow DFS in start_ap":
* set radar required in AP params
Changes to PATCHv6:
* use chandef in radar_detected_notify()
* add channel states, and handle them in cfg80211
* add Channel Switch Announcement (CAC) and Non-Occupancy Period (NOP) handling to cfg80211
* add cfg80211_chandef_dfs_required function
* add tracing for wireless event/functions
* from "nl80211: allow DFS in start_ap":
* let reg_can_beacon() and others check for channel states, simplify start_ap
* check using cfg80211_chandef_dfs_required
Changes to PATCHv5:
* remove unused cac_type
* fix doc for cac_started
* remove dfs_nlportid
* from "nl80211: allow DFS in start_ap":
* check radar detection width
--- include/net/cfg80211.h | 46 ++++++++++++++ include/uapi/linux/nl80211.h | 61 +++++++++++++++++++ net/wireless/chan.c | 129 +++++++++++++++++++++++++++++++++++++++- net/wireless/core.c | 3 + net/wireless/core.h | 28 +++++++++ net/wireless/mlme.c | 121 +++++++++++++++++++++++++++++++++++++ net/wireless/nl80211.c | 135 ++++++++++++++++++++++++++++++++++++++++-- net/wireless/nl80211.h | 7 +++ net/wireless/reg.c | 3 + net/wireless/scan.c | 10 ---- net/wireless/trace.h | 47 +++++++++++++++ 11 files changed, 573 insertions(+), 17 deletions(-)
include/net/cfg80211.h +46 -0
@@ -113,6 +113,9 @@ enum ieee80211_channel_flags {#define IEEE80211_CHAN_NO_HT40 \ (IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS) +#define IEEE80211_DFS_MIN_CAC_TIME_MS 60000 +#define IEEE80211_DFS_MIN_NOP_TIME_MS (30 * 60 * 1000) +/** * struct ieee80211_channel - channel definition *
@@ -133,6 +136,9 @@ enum ieee80211_channel_flags {* to enable this, this is useful only on 5 GHz band. * @orig_mag: internal use * @orig_mpwr: internal use +* @dfs_state: current state of this channel. Only relevant if radar is required +* on this channel. +* @dfs_state_entered: timestamp (jiffies) when the dfs state was entered. */ struct ieee80211_channel {enum ieee80211_band band;
@@ -145,6 +151,8 @@ struct ieee80211_channel {bool beacon_found;u32 orig_flags;int orig_mag, orig_mpwr; +enum nl80211_dfs_state dfs_state; +unsigned long dfs_state_entered; };/**
@@ -568,6 +576,7 @@ struct cfg80211_acl_data {* @p2p_opp_ps: P2P opportunistic PS * @acl: ACL configuration used by the drivers which has support for * MAC address based access control +* @radar_required: set if radar detection is required */ struct cfg80211_ap_settings {struct cfg80211_chan_def chandef;
@@ -585,6 +594,7 @@ struct cfg80211_ap_settings {u8 p2p_ctwindow;bool p2p_opp_ps;const struct cfg80211_acl_data *acl; +bool radar_required; };/**
@@ -1826,6 +1836,8 @@ struct cfg80211_gtk_rekey_data {* this new list replaces the existing one. Driver has to clear its ACL * when number of MAC addresses entries is passed as 0. Drivers which * advertise the support for MAC based ACL have to implement this callback. +* +* @start_radar_detection: Start radar detection in the driver. */ struct cfg80211_ops {int (*suspend)(struct wiphy *wiphy,struct cfg80211_wowlan *wow);
@@ -2049,6 +2061,10 @@ struct cfg80211_ops {int (*set_mac_acl)(struct wiphy *wiphy,struct net_device *dev,const struct cfg80211_acl_data *params); + +int (*start_radar_detection)(struct wiphy *wiphy, +struct net_device *dev, +struct cfg80211_chan_def *chandef); };/*
@@ -2621,6 +2637,8 @@ struct cfg80211_cached_keys;* beacons, 0 when not valid * @address: The address for this device, valid only if @netdev is %NULL * @p2p_started: true if this is a P2P Device that has been started +* @cac_started: true if DFS channel availability check has been started +* @cac_start_time: timestamp (jiffies) when the dfs state was entered. */ struct wireless_dev {struct wiphy *wiphy;
@@ -2672,6 +2690,9 @@ struct wireless_dev {u32 ap_unexpected_nlportid; +bool cac_started; +unsigned long cac_start_time; + #ifdef CONFIG_CFG80211_WEXT /* wext data */ struct {
@@ -3663,6 +3684,31 @@ void cfg80211_cqm_rssi_notify(struct net_device *dev, gfp_t gfp);/** +* cfg80211_radar_event - radar detection event +* @dev: network device +* @chandef: chandef for the current channel +* @gfp: context flags +* +* This function is called when a radar is detected on the current chanenl. +*/ +void cfg80211_radar_event (struct wiphy *wiphy, +struct cfg80211_chan_def *chandef,gfp_t gfp); + +/** +* cfg80211_cac_event - Channel availability check (CAC) event +* @dev: network device +* @event: type of event +* @gfp: context flags +* +* This function is called when a Channel availability check (CAC) is finished +* or aborted. This must be called to notify the completion of a CAC process, +* also by full-MAC drivers. +*/ +void cfg80211_cac_event (struct net_device *dev, +enum nl80211_radar_event event,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 +61 -0
101 lines not on this page · raw message
net/wireless/chan.c +127 -2
153 lines not on this page · raw message
net/wireless/core.c +3 -0
@@ -324,6 +324,8 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)INIT_LIST_HEAD (&rdev->bss_list);INIT_WORK (&rdev->scan_done_wk, __cfg80211_scan_done);INIT_WORK (&rdev->sched_scan_results_wk, __cfg80211_sched_scan_results); +INIT_DELAYED_WORK (&rdev->dfs_update_channels_wk, + cfg80211_dfs_channels_update_work);#ifdef CONFIG_CFG80211_WEXT rdev->wiphy.wext = &cfg80211_wext_handler;#endif
@@ -695,6 +697,7 @@ void wiphy_unregister(struct wiphy *wiphy)flush_work (&rdev->scan_done_wk);cancel_work_sync (&rdev->conn_work);flush_work (&rdev->event_work); +cancel_delayed_work_sync (&rdev->dfs_update_channels_wk);if (rdev->wowlan && rdev->ops->set_wakeup)rdev_set_wakeup (rdev, false);
net/wireless/core.h +28 -0
@@ -87,6 +87,8 @@ struct cfg80211_registered_device {struct cfg80211_wowlan *wowlan; +struct delayed_work dfs_update_channels_wk; +/* must be last because of the way we do wiphy_priv(), * and it should at least be aligned to NETDEV_ALIGN */ struct wiphy wiphy__aligned(NETDEV_ALIGN) ;
@@ -427,6 +429,22 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,struct ieee80211_channel *chan, enum cfg80211_chan_mode chanmode, u8 radar_detect); +/** +* cfg80211_chandef_dfs_required - checks if radar detection is required +* @wiphy: the wiphy to validate against +* @chandef: the channel definition to check +* Return: 1 if radar detection is required, 0 if it is not, < 0 on error +*/ +int cfg80211_chandef_dfs_required (struct wiphy *wiphy, +const struct cfg80211_chan_def *c); + + +void cfg80211_set_dfs_state (struct wiphy *wiphy, +const struct cfg80211_chan_def *chandef, +enum nl80211_dfs_state dfs_state); + +void cfg80211_dfs_channels_update_work (struct work_struct *work); + static inline int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
@@ -454,6 +472,16 @@ cfg80211_can_use_chan(struct cfg80211_registered_device *rdev, chan, chanmode, 0); } +static inline unsigned int elapsed_jiffies_msecs (unsigned long start) +{ +unsigned long end = jiffies; + +if (end >= start) +return jiffies_to_msecs (end - start); + +return jiffies_to_msecs (end + (MAX_JIFFY_OFFSET - start) +1 ); +} + void cfg80211_get_chan_state(struct wireless_dev *wdev, struct ieee80211_channel **chan,
net/wireless/mlme.c +121 -0
124 lines not on this page · raw message
net/wireless/nl80211.c +130 -5
172 lines not on this page · raw message
net/wireless/nl80211.h +7 -0
@@ -108,6 +108,13 @@ nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,struct net_device *netdev, enum nl80211_cqm_rssi_threshold_event rssi_event, gfp_t gfp); + +void +nl80211_radar_notify (struct cfg80211_registered_device *rdev, +struct cfg80211_chan_def *chandef, +enum nl80211_radar_event event, +struct net_device *netdev,gfp_t gfp); + void nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, struct net_device *netdev, const u8 *peer,
net/wireless/reg.c +3 -0
@@ -884,6 +884,9 @@ static void handle_channel(struct wiphy *wiphy,return ; } + chan->dfs_state =NL80211_DFS_USABLE ; + chan->dfs_state_entered = jiffies; + chan->beacon_found = false; chan->flags = flags | bw_flags |map_regdom_flags (reg_rule->flags); chan->max_antenna_gain =
net/wireless/scan.c +0 -10
@@ -1155,16 +1155,6 @@ static void ieee80211_scan_add_ies(struct iw_request_info *info, } } -static inline unsigned int elapsed_jiffies_msecs (unsigned long start) -{ -unsigned long end = jiffies; - -if (end >= start) -return jiffies_to_msecs (end - start); - -return jiffies_to_msecs (end + (MAX_JIFFY_OFFSET - start) +1 ); -} -static char * ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info, struct cfg80211_internal_bss *bss, char *current_ev,
net/wireless/trace.h +47 -0
59 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v9 3/3 mac80211: add radar detection command/event
In reply to Simon WunderlichAdd command to trigger radar detection in the driver/FW. Once radar detection is started it should continuously monitor for radars as long as the channel active. If radar is detected usermode notified with 'radar detected' event.
Scanning and remain on channel functionality must be disabled while doing radar detection/scanning, and vice versa.
based on original patch by Victor Goldenshtein <[email protected]>
---
Changes to PATCHv8:
* change from vif-interface to hw interface for radar detection reporting
* fix join_mesh (added radar required there by accident ...)
* add work queue for radar events
* change driver interface to report radar per hw, not per vif
* change to splitted radar/cac event reporting
* protect release_channel calls with local->iflist_mtx
Changes to PATCHv7:
* remove typo in mac80211.h (Zefir)
* remove comment about weather channels
* add break in ieee80211_recalc_radar_chanctx()
* reword comment in ieee80211_radar_detected() about virgin interfaces
* remove cfg80211_chandef_dfs_required dependency
Changes to PATCHv6:
* squash "check radar interaction with scan and roc" patch
* add radar detection flag to chanctx conf
* remove mac80211 radar detection command for drivers
* remove trace.h chandef macros and drv_start_radar_detection command
* use chandef in radar_detected_notification, remove channel argument (mac80211 already knows it)
* add timer for channel availability check notification to cfg80211
* add vif channel release
* check for dfs required using cfg80211 function
Changes to PATCHv5:
* use local instead of sdata->local
* change API to chandef
mac80211: lock AP_VLAN list with iflist_mtx
To remove the dependency to rtnl_lock() for ieee80211_vif_use/release_channel in AP mode, protect the AP_VLAN list with local->iflist_mtx instead.
RTNL can not be used from within mac80211 work structs, but the DFS AP interface requires to release channels (after DFS channel availability checks).
--- include/net/mac80211.h | 14 +++++++++++ net/mac80211/cfg.c | 37 ++++++++++++++++++++++++++++- net/mac80211/chan.c | 33 ++++++++++++++++++++++++++ net/mac80211/ieee80211_i.h | 13 ++++++++++ net/mac80211/iface.c | 12 ++++++++++ net/mac80211/main.c | 3 +++ net/mac80211/mlme.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ net/mac80211/scan.c | 3 +++ net/mac80211/trace.h | 19 +++++++++++++++ 9 files changed, 189 insertions(+), 1 deletion(-)
include/net/mac80211.h +14 -0
@@ -147,10 +147,12 @@ struct ieee80211_low_level_stats {* enum ieee80211_chanctx_change - change flag for channel context * @IEEE80211_CHANCTX_CHANGE_WIDTH: The channel width changed * @IEEE80211_CHANCTX_CHANGE_RX_CHAINS: The number of RX chains changed +* @IEEE80211_CHANCTX_CHANGE_RADAR: radar detection flag changed */ enum ieee80211_chanctx_change {IEEE80211_CHANCTX_CHANGE_WIDTH =BIT (0 ),IEEE80211_CHANCTX_CHANGE_RX_CHAINS =BIT (1 ), +IEEE80211_CHANCTX_CHANGE_RADAR =BIT (2 ), };/**
@@ -165,6 +167,7 @@ enum ieee80211_chanctx_change {* @rx_chains_dynamic: The number of RX chains that must be enabled * after RTS/CTS handshake to receive SMPS MIMO transmissions; * this will always be >= @rx_chains_static. +* @radar_enabled: whether radar detection is enabled on this channel. * @drv_priv: data area for driver use, will always be aligned to * sizeof(void *), size is determined in hw information. */
@@ -173,6 +176,8 @@ struct ieee80211_chanctx_conf {u8 rx_chains_static, rx_chains_dynamic; +bool radar_enabled; +u8 drv_priv[0 ]__aligned(sizeof(void *)) ; };
@@ -950,6 +955,7 @@ enum ieee80211_smps_mode {* * @channel: the channel to tune to * @channel_type: the channel (HT) type +* @radar_enabled: whether radar detection is enabled * * @long_frame_max_tx_count: Maximum number of transmissions for a "long" frame * (a frame not RTS protected), called "dot11LongRetryLimit" in 802.11,
@@ -976,6 +982,7 @@ struct ieee80211_conf {struct ieee80211_channel *channel;enum nl80211_channel_type channel_type; +bool radar_enabled;enum ieee80211_smps_mode smps_mode; };
@@ -3953,6 +3960,13 @@ void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, gfp_t gfp);/** +* ieee80211_radar_detected - inform that a radar was detected +* +* @hw: pointer as obtained from ieee80211_alloc_hw() +*/ +void ieee80211_radar_detected (struct ieee80211_hw *hw); + +/** * ieee80211_chswitch_done - Complete channel switch process * @vif: &struct ieee80211_vif pointer from the add_interface callback. * @success: make the channel switch successful or not
net/mac80211/cfg.c +36 -1
@@ -922,6 +922,7 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,/* TODO: make hostapd tell us what it wants */ sdata->smps_mode =IEEE80211_SMPS_OFF ; sdata->needed_rx_chains = sdata->local->rx_chains; + sdata->radar_required = params->radar_required;mutex_lock (&sdata->local->iflist_mtx); err = ieee80211_vif_use_channel(sdata, ¶ms->chandef,
@@ -2382,7 +2383,9 @@ static int ieee80211_start_roc_work(struct ieee80211_local *local,INIT_LIST_HEAD (&roc->dependents);/* if there's one pending or we're scanning, queue this one */ -if (!list_empty (&local->roc_list) || local->scanning) +if (!list_empty (&local->roc_list) || + local->scanning || + local->radar_detect_enabled) goto out_check_combine;/* if not HW assist, just queue & schedule work */
@@ -2632,6 +2635,37 @@ static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,return ieee80211_cancel_roc (local, cookie, false); } +static int ieee80211_start_radar_detection (struct wiphy *wiphy, +struct net_device *dev, +struct cfg80211_chan_def *chandef) +{ +struct ieee80211_sub_if_data *sdata =IEEE80211_DEV_TO_SUB_IF (dev); +struct ieee80211_local *local = sdata->local; +unsigned long timeout; +int err; + +if (!list_empty (&local->roc_list) || local->scanning) +return -EBUSY ; + +/* whatever, but channel contexts should not complain about that one */ + sdata->smps_mode =IEEE80211_SMPS_OFF ; + sdata->needed_rx_chains = local->rx_chains; + sdata->radar_required = true; + +mutex_lock (&local->iflist_mtx); + err =ieee80211_vif_use_channel (sdata, chandef, +IEEE80211_CHANCTX_SHARED ); +mutex_unlock (&local->iflist_mtx); +if (err) +return err; + + timeout =msecs_to_jiffies (IEEE80211_DFS_MIN_CAC_TIME_MS ); +ieee80211_queue_delayed_work (&sdata->local->hw, + &sdata->dfs_cac_timer_work, timeout); + +return 0 ; +} + static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, struct ieee80211_channel *chan, bool offchan, unsigned int wait, const u8 *buf, size_t len,
@@ -3336,4 +3370,5 @@ struct cfg80211_ops mac80211_config_ops = { .get_et_stats = ieee80211_get_et_stats, .get_et_strings = ieee80211_get_et_strings, .get_channel = ieee80211_cfg_get_channel, + .start_radar_detection = ieee80211_start_radar_detection, };
net/mac80211/chan.c +33 -0
@@ -180,6 +180,7 @@ static void ieee80211_unassign_vif_chanctx(struct ieee80211_sub_if_data *sdata,if (ctx->refcount >0 ) {ieee80211_recalc_chanctx_chantype (sdata->local, ctx);ieee80211_recalc_smps_chanctx (local, ctx); +ieee80211_recalc_radar_chanctx (local, ctx); } }
@@ -212,6 +213,37 @@ static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata)ieee80211_free_chanctx (local, ctx); } +void ieee80211_recalc_radar_chanctx (struct ieee80211_local *local, +struct ieee80211_chanctx *chanctx) +{ +struct ieee80211_sub_if_data *sdata; +bool radar_enabled = false; + +lockdep_assert_held (&local->chanctx_mtx); + +rcu_read_lock (); +list_for_each_entry_rcu (sdata, &local->interfaces, list) { +if (sdata->radar_required) { + radar_enabled = true; +break ; + } + } +rcu_read_unlock (); + +if (radar_enabled == chanctx->conf.radar_enabled) +return ; + + chanctx->conf.radar_enabled = radar_enabled; + local->radar_detect_enabled = chanctx->conf.radar_enabled; + +if (!local->use_chanctx) { + local->hw.conf.radar_enabled = chanctx->conf.radar_enabled; +ieee80211_hw_config (local,IEEE80211_CONF_CHANGE_CHANNEL ); + } + +drv_change_chanctx (local, chanctx,IEEE80211_CHANCTX_CHANGE_RADAR ); +} +void ieee80211_recalc_smps_chanctx (struct ieee80211_local *local,struct ieee80211_chanctx *chanctx) {
@@ -336,6 +368,7 @@ int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata, }ieee80211_recalc_smps_chanctx (local, ctx); +ieee80211_recalc_radar_chanctx (local, ctx); out:mutex_unlock (&local->chanctx_mtx);return ret;
net/mac80211/ieee80211_i.h +13 -0
@@ -755,6 +755,9 @@ struct ieee80211_sub_if_data {int user_power_level;/* in dBm */ int ap_power_level;/* in dBm */ +bool radar_required; +struct delayed_work dfs_cac_timer_work; +/* * AP this belongs to: self in AP mode and * corresponding AP in VLAN mode, NULL for
@@ -974,6 +977,10 @@ struct ieee80211_local {/* wowlan is enabled -- don't reconfig on resume */ bool wowlan; +/* DFS/radar detection is enabled */ +bool radar_detect_enabled; +struct work_struct radar_detected_work; +/* number of RX chains the hardware has */ u8 rx_chains;
@@ -1641,6 +1648,12 @@ void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata);void ieee80211_recalc_smps_chanctx (struct ieee80211_local *local,struct ieee80211_chanctx *chanctx); +void ieee80211_recalc_radar_chanctx (struct ieee80211_local *local, +struct ieee80211_chanctx *chanctx); + +void ieee80211_dfs_cac_timer (unsigned long data); +void ieee80211_dfs_cac_timer_work (struct work_struct *work); +void ieee80211_dfs_radar_detected_work (struct work_struct *work);#ifdef CONFIG_MAC80211_NOINLINE #define debug_noinline noinline
net/mac80211/iface.c +12 -0
@@ -822,6 +822,16 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,cancel_work_sync (&sdata->recalc_smps); +cancel_delayed_work_sync (&sdata->dfs_cac_timer_work); + +if (sdata->wdev.cac_started) { +mutex_lock (&local->iflist_mtx); +ieee80211_vif_release_channel (sdata); +mutex_unlock (&local->iflist_mtx); +cfg80211_cac_event (sdata->dev,NL80211_RADAR_CAC_ABORTED , +GFP_KERNEL ); + } +/* APs need special treatment */ if (sdata->vif.type ==NL80211_IFTYPE_AP ) {struct ieee80211_sub_if_data *vlan, *tmpsdata;
@@ -1592,6 +1602,8 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,spin_lock_init (&sdata->cleanup_stations_lock);INIT_LIST_HEAD (&sdata->cleanup_stations);INIT_WORK (&sdata->cleanup_stations_wk, ieee80211_cleanup_sdata_stas_wk); +INIT_DELAYED_WORK (&sdata->dfs_cac_timer_work, + ieee80211_dfs_cac_timer_work);for (i =0 ; i <IEEE80211_NUM_BANDS ; i++) {struct ieee80211_supported_band *sband;
net/mac80211/main.c +3 -0
@@ -632,6 +632,9 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,INIT_WORK (&local->restart_work, ieee80211_restart_work); +INIT_WORK (&local->radar_detected_work, + ieee80211_dfs_radar_detected_work); +INIT_WORK (&local->reconfig_filter, ieee80211_reconfig_filter); local->smps_mode =IEEE80211_SMPS_OFF ;
net/mac80211/mlme.c +56 -0
65 lines not on this page · raw message
net/mac80211/scan.c +3 -0
@@ -356,6 +356,9 @@ static int ieee80211_start_sw_scan(struct ieee80211_local *local)static bool ieee80211_can_scan (struct ieee80211_local *local,struct ieee80211_sub_if_data *sdata) { +if (local->radar_detect_enabled) +return false; +if (!list_empty (&local->roc_list))return false;
net/mac80211/trace.h +19 -0
@@ -1860,6 +1860,25 @@ TRACE_EVENT(drv_set_default_unicast_key, LOCAL_PR_ARG, VIF_PR_ARG, __entry->key_idx) ); +TRACE_EVENT (api_radar_detected, + TP_PROTO(struct ieee80211_local *local), + +TP_ARGS (local), + +TP_STRUCT__entry ( +LOCAL_ENTRY + ), + +TP_fast_assign ( + LOCAL_ASSIGN; + ), + +TP_printk ( +LOCAL_PR_FMT " radar detected" , +LOCAL_PR_ARG + ) +); +#ifdef CONFIG_MAC80211_MESSAGE_TRACING #undef TRACE_SYSTEM#define TRACE_SYSTEM mac80211_msg
Signature · 1 line
1.7.10.4
PATCH 1/2 iw: add radar detect widths to phy info
In reply to Simon Wunderlich--- info.c | 22 +++++++++++++++++++++- interface.c | 2 +- iw.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-)
info.c +21 -1
@@ -245,6 +245,7 @@ static int print_phy_handler(struct nl_msg *msg, void *arg) [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 }, [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG }, [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 }, + [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 }, };struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB ];static struct nla_policy iface_limit_policy[NUM_NL80211_IFACE_LIMIT ] = {
@@ -296,11 +297,30 @@ static int print_phy_handler(struct nl_msg *msg, void *arg) }printf (",\n\t\t " ); -printf ("total <= %d, #channels <= %d%s\n" , +printf ("total <= %d, #channels <= %d%s" ,nla_get_u32 (tb_comb[NL80211_IFACE_COMB_MAXNUM ]),nla_get_u32 (tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS ]), tb_comb[NL80211_IFACE_COMB_STA_AP_BI_MATCH ] ?", STA/AP BI must match" :"" ); +if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS ]) { +unsigned long widths =nla_get_u32 (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS ]); + +if (widths) { +int width; +bool first = true; + +printf (", radar detect widths: {" ); +for (width =0 ; width <32 ; width++) +if (widths & (1 << width)) { +printf ("%s %s" , + first ?"" :"," , +channel_width_name (width)); + first = false; + } +printf (" }\n" ); + } + } +printf ("\n" ); broken_combination: ; }
interface.c +1 -1
@@ -262,7 +262,7 @@ static char *channel_type_name(enum nl80211_channel_type channel_type) } } -static char *channel_width_name (enum nl80211_chan_width width) +char *channel_width_name (enum nl80211_chan_width width) {switch (width) {case NL80211_CHAN_WIDTH_20_NOHT :
iw.h +1 -0
@@ -145,6 +145,7 @@ void print_ampdu_spacing(__u8 spacing);void print_ht_capability (__u16 cap);void print_vht_info (__u32 capa,const __u8 *mcs); +char *channel_width_name (enum nl80211_chan_width width);const char *iftype_name (enum nl80211_iftype iftype);const char *command_name (enum nl80211_commands cmd);int ieee80211_channel_to_frequency (int chan);
Signature · 1 line
1.7.10.4
PATCH 2/2 iw: print DFS states for channels if available
In reply to Simon Wunderlich--- info.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
info.c +25 -0
@@ -49,6 +49,20 @@ static char *cipher_name(__u32 c) } } +static char *dfs_state_name (enum nl80211_dfs_state state) +{ +switch (state) { +case NL80211_DFS_USABLE : +return "usable" ; +case NL80211_DFS_AVAILABLE : +return "available" ; +case NL80211_DFS_UNAVAILABLE : +return "unavailable" ; +default : +return "unknown" ; + } +} +static int print_phy_handler (struct nl_msg *msg,void *arg) {struct nlattr *tb_msg[NL80211_ATTR_MAX +1 ];
@@ -147,6 +161,17 @@ static int print_phy_handler(struct nl_msg *msg, void *arg) next:if (open)printf (")" ); +if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE ]) { +enum nl80211_dfs_state state =nla_get_u32 (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE ]); +unsigned long time; + +printf (" DFS state: %s" ,dfs_state_name (state)); +if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_TIME ]) { + time =nla_get_u32 (tb_freq[NL80211_FREQUENCY_ATTR_DFS_TIME ]); +printf (" (for %lu sec)" , time/1000 ); + } + } +printf ("\n" ); }
Signature · 1 line
1.7.10.4