wifi: cfg80211/mac80211: add NAN Instant Communication support
v3 cover wifi: cfg80211/mac80211: add NAN Instant Communication support
This series adds support for NAN Instant Communication, including hwsim support.
Changes in v3:
- Patches applied on top of latest wirless-next main branch.
Ilan Peer (11):
wifi: cfg80211: nan: add Instant Communication support
wifi: mac80211: nan: Update NAN configuration copy
wifi: cfg80211: nan: check Rx registration for NAN beacons
wifi: cfg80211: do not use NAN beacons to update the BSS table
wifi: mac80211: nan: allow Rx registration for NAN beacons
wifi: mac80211: accept NAN beacons only when IC is enabled
wifi: ieee80211: add NAN service ID list attribute definitions
wifi: mac80211_hwsim: nan: use ieee80211_is_nan_beacon() helper
wifi: mac80211_hwsim: nan: prepare for more configurable NAN settings
wifi: mac80211_hwsim: nan: Handle more of the NAN configuration
wifi: mac80211_hwsim: add NAN Instant Communication support
.../wireless/virtual/mac80211_hwsim_main.c | 7 +- .../net/wireless/virtual/mac80211_hwsim_nan.c | 245 +++++++++++++++--- .../net/wireless/virtual/mac80211_hwsim_nan.h | 7 + include/linux/ieee80211-nan.h | 28 ++ include/net/cfg80211.h | 9 +- include/uapi/linux/nl80211.h | 12 + net/mac80211/cfg.c | 1 + net/mac80211/main.c | 7 +- net/mac80211/rx.c | 6 +- net/wireless/core.c | 12 + net/wireless/nl80211.c | 22 ++ net/wireless/scan.c | 4 + 12 files changed, 315 insertions(+), 45 deletions(-)
Signature · 1 line
2.55.0
PATCH v3 1/11 wifi: cfg80211: nan: add Instant Communication support
Add NL80211_NAN_CONF_INSTANT_COMM flag to let user space request that the NAN synchronization logic starts Instant Communication (IC) as defined in Chapter 13 of the Wi-Fi Aware Specification v4.0.
Add NL80211_NAN_CAPA_INSTANT_COMM for drivers to advertise it. The capability requires configurable synchronization support, and IC requests are rejected if it isn't advertised.
When IC is enabled, user space must also configure the discovery beacon interval. The IC schedule is expected to be configured by user space.
--- include/net/cfg80211.h | 9 ++++++++- include/uapi/linux/nl80211.h | 12 ++++++++++++ net/wireless/core.c | 5 +++++ net/wireless/nl80211.c | 22 ++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-)
include/net/cfg80211.h +8 -1
@@ -4191,9 +4191,12 @@ struct cfg80211_nan_band_config {* that can take a value from 50-6F-9A-01-00-00 to 50-6F-9A-01-FF-FF. * @scan_period: period (in seconds) between NAN scans. * @scan_dwell_time: dwell time (in milliseconds) for NAN scans. -* @discovery_beacon_interval: interval (in TUs) for discovery beacons. +* @discovery_beacon_interval: interval (in TUs) for discovery beacons. Must be +* greater than 0 when @instant_comm is true. * @enable_dw_notification: flag to enable/disable discovery window * notifications. +* @instant_comm: if true, start Instant Communication (IC) as defined in +* Chapter 13 of the Wi-Fi Aware Specification v4.0. * @band_cfgs: array of band specific configurations, indexed by * &enum nl80211_band values. * @extra_nan_attrs: pointer to additional NAN attributes.
@@ -4209,6 +4212,7 @@ struct cfg80211_nan_conf {u16 scan_dwell_time;u8 discovery_beacon_interval;bool enable_dw_notification; +bool instant_comm;struct cfg80211_nan_band_config band_cfgs[NUM_NL80211_BANDS ];const u8 *extra_nan_attrs;u16 extra_nan_attrs_len;
@@ -6305,10 +6309,13 @@ struct wiphy_radio {* @WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC: Device supports NAN configurable * synchronization. * @WIPHY_NAN_FLAGS_USERSPACE_DE: Device doesn't support DE offload. +* @WIPHY_NAN_FLAGS_INSTANT_COMM: Device can switch to Instant Communication +* (IC) mode. Can only be set along with %WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC. */ enum wiphy_nan_flags {WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC =BIT (0 ),WIPHY_NAN_FLAGS_USERSPACE_DE =BIT (1 ), +WIPHY_NAN_FLAGS_INSTANT_COMM =BIT (2 ), };/**
include/uapi/linux/nl80211.h +12 -0
@@ -7890,6 +7890,11 @@ enum nl80211_nan_band_conf_attributes {* the upcoming discovery window with * %NL80211_CMD_NAN_NEXT_DW_NOTIFICATION. * This is a flag attribute. +* @NL80211_NAN_CONF_INSTANT_COMM: If set, the NAN synchronization logic will +* start Instant Communication (IC) as defined in Chapter 13 of the +* Wi-Fi Aware Specification v4.0. +* %NL80211_NAN_CONF_DISCOVERY_BEACON_INTERVAL must be set as well. +* This is a flag attribute. * @NUM_NL80211_NAN_CONF_ATTR: Internal. * @NL80211_NAN_CONF_ATTR_MAX: Highest NAN configuration attribute. *
@@ -7905,6 +7910,7 @@ enum nl80211_nan_conf_attributes {NL80211_NAN_CONF_SCAN_DWELL_TIME ,NL80211_NAN_CONF_DISCOVERY_BEACON_INTERVAL ,NL80211_NAN_CONF_NOTIFY_DW , +NL80211_NAN_CONF_INSTANT_COMM ,/* keep last */ NUM_NL80211_NAN_CONF_ATTR,
@@ -9121,6 +9127,11 @@ enum nl80211_s1g_short_beacon_attrs {* specification Table 79 (Capabilities field). * @NL80211_NAN_CAPA_PHY: nested attribute containing band-agnostic * capabilities for NAN data path. See &enum nl80211_nan_phy_cap_attr. +* @NL80211_NAN_CAPA_INSTANT_COMM: Flag attribute indicating that the device +* can switch to Instant Communication (IC) mode, as defined in Chapter 13 +* of the Wi-Fi Aware Specification v4.0. Can only be set if +* %NL80211_NAN_CAPA_CONFIGURABLE_SYNC is set. When IC is enabled, the IC +* schedule is expected to be configured by user space. * @__NL80211_NAN_CAPABILITIES_LAST: Internal * @NL80211_NAN_CAPABILITIES_MAX: Highest NAN capability attribute. */
@@ -9134,6 +9145,7 @@ enum nl80211_nan_capabilities {NL80211_NAN_CAPA_MAX_CHANNEL_SWITCH_TIME ,NL80211_NAN_CAPA_CAPABILITIES ,NL80211_NAN_CAPA_PHY , +NL80211_NAN_CAPA_INSTANT_COMM ,/* keep last */ __NL80211_NAN_CAPABILITIES_LAST, NL80211_NAN_CAPABILITIES_MAX = __NL80211_NAN_CAPABILITIES_LAST - 1,
net/wireless/core.c +5 -0
@@ -964,6 +964,11 @@ int wiphy_register(struct wiphy *wiphy) (!wiphy->nan_capa.phy.ht.ht_supported || wiphy->n_radio > 1)))return -EINVAL ; +if (WARN_ON ((wiphy->nan_capa.flags &WIPHY_NAN_FLAGS_INSTANT_COMM ) && + !(wiphy->nan_capa.flags & +WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC ))) +return -EINVAL ; +if (WARN_ON (wiphy->interface_modes &BIT (NL80211_IFTYPE_WDS )))return -EINVAL ;
net/wireless/nl80211.c +22 -0
@@ -687,6 +687,7 @@ nl80211_nan_conf_policy[NL80211_NAN_CONF_ATTR_MAX + 1] = { [NL80211_NAN_CONF_DISCOVERY_BEACON_INTERVAL ] = NLA_POLICY_RANGE(NLA_U8, 50, 200), [NL80211_NAN_CONF_NOTIFY_DW] = { .type = NLA_FLAG }, + [NL80211_NAN_CONF_INSTANT_COMM] = { .type = NLA_FLAG }, };static const struct netlink_range_validation nl80211_punct_bitmap_range = {
@@ -3036,6 +3037,10 @@ static int nl80211_put_nan_capa(struct wiphy *wiphy, struct sk_buff *msg) nla_put_flag(msg, NL80211_NAN_CAPA_USERSPACE_DE)) goto fail; +if ((wiphy->nan_capa.flags &WIPHY_NAN_FLAGS_INSTANT_COMM ) && +nla_put_flag (msg,NL80211_NAN_CAPA_INSTANT_COMM )) + goto fail; +if (nla_put_u8 (msg,NL80211_NAN_CAPA_OP_MODE , wiphy->nan_capa.op_mode) || nla_put_u8(msg, NL80211_NAN_CAPA_NUM_ANTENNAS,
@@ -16781,6 +16786,23 @@ static int nl80211_parse_nan_conf(struct wiphy *wiphy, conf->enable_dw_notification =nla_get_flag (attrs[NL80211_NAN_CONF_NOTIFY_DW ]); + conf->instant_comm =nla_get_flag (attrs[NL80211_NAN_CONF_INSTANT_COMM ]); +if (conf->instant_comm) { +if (!(wiphy->nan_capa.flags &WIPHY_NAN_FLAGS_INSTANT_COMM )) { +NL_SET_ERR_MSG_ATTR (info->extack, + attrs[NL80211_NAN_CONF_INSTANT_COMM ], +"Instant Communication is not supported" ); +return -EOPNOTSUPP ; + } + +if (!conf->discovery_beacon_interval) { +NL_SET_ERR_MSG_ATTR (info->extack, + attrs[NL80211_NAN_CONF_INSTANT_COMM ], +"Instant Communication requires a discovery beacon interval" ); +return -EINVAL ; + } + } + out:if (!conf->band_cfgs[NL80211_BAND_5GHZ ].chan && (!conf->bands || conf->bands &BIT (NL80211_BAND_5GHZ ))) {
Signature · 1 line
2.55.0
PATCH v3 2/11 wifi: mac80211: nan: Update NAN configuration copy
In reply to Ilan PeerCopy the Instant Communication flag when storing the NAN configuration.
--- net/mac80211/cfg.c | 1 + 1 file changed, 1 insertion(+)
net/mac80211/cfg.c +1 -0
@@ -368,6 +368,7 @@ static int ieee80211_nan_conf_copy(struct cfg80211_nan_conf *dst, dst->discovery_beacon_interval = src->discovery_beacon_interval; dst->enable_dw_notification = src->enable_dw_notification; + dst->instant_comm = src->instant_comm;memcpy (&dst->band_cfgs, &src->band_cfgs,sizeof (dst->band_cfgs));
Signature · 1 line
2.55.0
PATCH v3 3/11 wifi: cfg80211: nan: check Rx registration for NAN beacons
In reply to Ilan PeerInstant Communication requires user space to track the NAN beacons, so fail device registration when the device declares NAN Device support for Instant Communication but doesn't support Rx registration for beacon frames.
--- net/wireless/core.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/wireless/core.c +7 -0
@@ -969,6 +969,13 @@ int wiphy_register(struct wiphy *wiphy) WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC)))return -EINVAL ; +/* Instant Communication requires user space to track NAN beacons */ +if (WARN_ON ((wiphy->nan_capa.flags &WIPHY_NAN_FLAGS_INSTANT_COMM ) && + (!wiphy->mgmt_stypes || + !(wiphy->mgmt_stypes[NL80211_IFTYPE_NAN ].rx & +BIT (IEEE80211_STYPE_BEACON >>4 ))))) +return -EINVAL ; +if (WARN_ON (wiphy->interface_modes &BIT (NL80211_IFTYPE_WDS )))return -EINVAL ;
Signature · 1 line
2.55.0
PATCH v3 4/11 wifi: cfg80211: do not use NAN beacons to update the BSS table
In reply to Ilan PeerAs NAN beacons have a different structure compared to beacons defined in the IEEE802.11 specification, e.g., they do not contain a SSID element etc., they cannot be used to update the BSS table.
Add a utility function to check if a frame is a NAN beacon and use it do return early in cfg80211_inform_bss_frame_data().
--- include/linux/ieee80211-nan.h | 26 ++++++++++++++++++++++++++ net/wireless/scan.c | 4 ++++ 2 files changed, 30 insertions(+)
include/linux/ieee80211-nan.h +26 -0
@@ -74,4 +74,30 @@ struct ieee80211_nan_anchor_master_info { _attr = (const struct ieee80211_nan_attr *) \ (_attr->data + le16_to_cpu(_attr->length))) +static inline bool ieee80211_is_nan_beacon (const struct ieee80211_mgmt *mgmt, +size_t len) +{ +const struct element *elem; + +/* The NAN IE is at least 6 octets */ + if (len < offsetofend(struct ieee80211_mgmt, u.beacon) + 6) +return false; + +if (!ieee80211_is_beacon (mgmt->frame_control)) +return false; + +/* NAN Cluster IDs range from 50-6F-9A-01-00-00 to 50-6F-9A-01-FF-FF */ +if (get_unaligned_be32 (mgmt->bssid) != ((WLAN_OUI_WFA <<8 ) |0x01 )) +return false; + + elem = (const struct element *)mgmt->u.beacon.variable; +if (elem->id !=WLAN_EID_VENDOR_SPECIFIC || + elem->datalen <4 || +get_unaligned_be32 (elem->data) != + (WLAN_OUI_WFA <<8 |WLAN_OUI_TYPE_WFA_NAN )) +return false; + +return true; +} +#endif /* LINUX_IEEE80211_NAN_H */
net/wireless/scan.c +4 -0
@@ -3338,6 +3338,10 @@ cfg80211_inform_bss_frame_data(struct wiphy *wiphy,if (WARN_ON (!wiphy))return NULL ; +/* NAN beacons are not a BSS, don't add to the BSS table */ +if (ieee80211_is_nan_beacon (mgmt, len)) +return NULL ; + BUILD_BUG_ON(offsetof(struct ieee80211_mgmt, u.probe_resp.variable) != offsetof(struct ieee80211_mgmt, u.beacon.variable));
Signature · 1 line
2.55.0
PATCH v3 5/11 wifi: mac80211: nan: allow Rx registration for NAN beacons
In reply to Ilan PeerInstant Communication requires user space to track the NAN beacons, so let it register for Rx of beacons on a NAN interface.
--- net/mac80211/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/mac80211/main.c +6 -1
@@ -745,8 +745,13 @@ ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = { }, [NL80211_IFTYPE_NAN] = { .tx = 0xffff, +/* +* Beacon Rx registration is needed to let user space handle +* service discovery when Instant Communication is enabled. +*/ .rx =BIT (IEEE80211_STYPE_ACTION >>4 ) | - BIT(IEEE80211_STYPE_AUTH >> 4), +BIT (IEEE80211_STYPE_AUTH >>4 ) | + BIT(IEEE80211_STYPE_BEACON >> 4), }, [NL80211_IFTYPE_NAN_DATA] = { .tx = 0xffff,
Signature · 1 line
2.55.0
PATCH v3 6/11 wifi: mac80211: accept NAN beacons only when IC is enabled
In reply to Ilan PeerAccept NAN beacons in the Rx path only when Instant Communication (IC) is enabled in the NAN configuration.
--- net/mac80211/rx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/mac80211/rx.c +5 -1
@@ -4687,7 +4687,8 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)* Accept only frames that are addressed to the NAN cluster * (based on the Cluster ID). From these frames, accept only * - public action frames, -* - authentication frames to the local address, and +* - authentication frames to the local address, +* - NAN beacons, when Instant Communication is enabled, and * - robust management frames except disassoc. */ if (!ether_addr_equal (sdata->u.nan.conf.cluster_id, hdr->addr3))
@@ -4697,6 +4698,9 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)if (ieee80211_is_auth (hdr->frame_control) &ðer_addr_equal (sdata->vif.addr, hdr->addr1))return true; +if (ieee80211_is_nan_beacon ((struct ieee80211_mgmt *)hdr, + skb->len)) +return sdata->u.nan.conf.instant_comm;if (!ieee80211_is_disassoc (hdr->frame_control) &&ieee80211_is_robust_mgmt_frame (skb))return true;
Signature · 1 line
2.55.0
PATCH v3 7/11 wifi: ieee80211: add NAN service ID list attribute definitions
In reply to Ilan PeerAdd the Service ID List and Subscribe Service ID List NAN attribute IDs. These are needed to filter in NAN beacons during Instant Communication.
--- include/linux/ieee80211-nan.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/ieee80211-nan.h +2 -0
@@ -40,6 +40,8 @@/* NAN attributes, as defined in Wi-Fi Aware (TM) specification 4.0 Table 42 */ #define NAN_ATTR_MASTER_INDICATION 0x00#define NAN_ATTR_CLUSTER_INFO 0x01 +#define NAN_ATTR_SERVICE_ID_LIST 0x02 +#define NAN_ATTR_SUBSCRIBE_SERVICE_ID_LIST 0x28struct ieee80211_nan_attr {u8 attr;
Signature · 1 line
2.55.0
PATCH v3 8/11 wifi: mac80211_hwsim: nan: use ieee80211_is_nan_beacon() helper
In reply to Ilan PeerUse the new ieee80211_is_nan_beacon() helper to identify NAN beacons instead of open-coding the cluster ID and vendor element checks.
--- drivers/net/wireless/virtual/mac80211_hwsim_nan.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/net/wireless/virtual/mac80211_hwsim_nan.c +1 -14
@@ -230,9 +230,7 @@ void mac80211_hwsim_nan_rx(struct ieee80211_hw *hw,ssize_t data_len;u8 slot; -/* Need a NAN vendor element at the start */ - if (skb->len < (offsetofend(struct ieee80211_mgmt, u.beacon) + 6) || - !ieee80211_is_beacon (mgmt->frame_control)) +if (!ieee80211_is_nan_beacon (mgmt, skb->len))return ; data_len = skb->len - offsetofend(struct ieee80211_mgmt, u.beacon);
@@ -279,17 +277,6 @@ void mac80211_hwsim_nan_rx(struct ieee80211_hw *hw,if (rx_status.signal <NAN_RSSI_MIDDLE )return ; -/* Needs to be a valid NAN cluster ID in A3 */ -if (get_unaligned_be32 (mgmt->bssid) != ((WLAN_OUI_WFA <<8 ) |0x01 )) -return ; - -/* We are only interested in NAN beacons */ -if (nan_elem->id !=WLAN_EID_VENDOR_SPECIFIC || - nan_elem->datalen <4 || -get_unaligned_be32 (nan_elem->data) != - (WLAN_OUI_WFA <<8 |WLAN_OUI_TYPE_WFA_NAN )) -return ; - u8 *nan_defragmented __free(kfree) = kzalloc(data_len, GFP_ATOMIC);if (!nan_defragmented)return ;
Signature · 1 line
2.55.0
PATCH v3 9/11 wifi: mac80211_hwsim: nan: prepare for more configurable NAN settings
In reply to Ilan PeerIn preparation for handling more of the NAN configuration setting, do some refactoring and cleanup:
- Extract mac80211_hwsim_nan_set_config() and call it both when NAN is started and when the configuration changes.
- Add NAN_BEACON_ELEM_LEN instead of the hardcoded 27.
--- .../net/wireless/virtual/mac80211_hwsim_nan.c | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-)
drivers/net/wireless/virtual/mac80211_hwsim_nan.c +25 -7
@@ -33,6 +33,9 @@ static_assert(DW0_TSF_MASK + 1 == 8192 * 1024);#define NAN_RSSI_CLOSE (-60)#define NAN_RSSI_MIDDLE (-75) +/* Size of the NAN vendor element carrying the mandatory attributes */ +#define NAN_BEACON_ELEM_LEN 27 +/* Quiet time at the end of each slot where TX is suppressed */ #define NAN_CHAN_SWITCH_TIME_US 256
@@ -685,7 +688,7 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data, {struct ieee80211_vendor_ie nan_ie = { .element_id =WLAN_EID_VENDOR_SPECIFIC , - .len =27 -2 , + .len =NAN_BEACON_ELEM_LEN -2 , .oui = {u32_get_bits (WLAN_OUI_WFA ,0xff0000 ),u32_get_bits (WLAN_OUI_WFA ,0xff00 ),u32_get_bits (WLAN_OUI_WFA ,0xff ) },
@@ -694,7 +697,7 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data,size_t alloc_size =IEEE80211_TX_STATUS_HEADROOM + offsetofend(struct ieee80211_mgmt, u.beacon) + -27 /* size of NAN vendor element */ ; +NAN_BEACON_ELEM_LEN ;struct ieee80211_nan_master_indication master_indication;struct ieee80211_nan_attr nan_attr;struct ieee80211_mgmt *mgmt;
@@ -905,11 +908,20 @@ mac80211_hwsim_nan_sched_update_work(struct wiphy *wiphy,ieee80211_nan_sched_update_done (data->nan.device_vif); } +static int mac80211_hwsim_nan_set_config (struct mac80211_hwsim_data *data, +struct cfg80211_nan_conf *conf) +{ + data->nan.notify_dw = conf->enable_dw_notification; + +return 0 ; +} +int mac80211_hwsim_nan_start (struct ieee80211_hw *hw,struct ieee80211_vif *vif,struct cfg80211_nan_conf *conf) {struct mac80211_hwsim_data *data = hw->priv; +int err;if (vif->type !=NL80211_IFTYPE_NAN )return -EINVAL ;
@@ -917,6 +929,10 @@ int mac80211_hwsim_nan_start(struct ieee80211_hw *hw,if (data->nan.device_vif)return -EALREADY ; + err =mac80211_hwsim_nan_set_config (data, conf); +if (err) +return err; +/* set this before starting the timer, as preemption might occur */ data->nan.device_vif = vif; data->nan.bands = conf->bands;
@@ -945,8 +961,6 @@ int mac80211_hwsim_nan_start(struct ieee80211_hw *hw,ether_addr_copy (data->nan.cluster_id, conf->cluster_id); - data->nan.notify_dw = conf->enable_dw_notification; -return 0 ; }
@@ -983,13 +997,17 @@ int mac80211_hwsim_nan_change_config(struct ieee80211_hw *hw,wiphy_debug (hw->wiphy,"nan_config_changed: changes=0x%x\n" , changes); +if (changes &CFG80211_NAN_CONF_CHANGED_CONFIG ) { +int err =mac80211_hwsim_nan_set_config (data, conf); + +if (err) +return err; + } +/* Handle only the changes we care about for simulation purposes */ if (changes &CFG80211_NAN_CONF_CHANGED_BANDS ) data->nan.bands = conf->bands; -if (changes &CFG80211_NAN_CONF_CHANGED_CONFIG ) - data->nan.notify_dw = conf->enable_dw_notification; -if (changes &CFG80211_NAN_CONF_CHANGED_PREF ) {scoped_guard (spinlock_bh, &data->nan.state_lock) data->nan.master_pref = conf->master_pref;
Signature · 1 line
2.55.0
PATCH v3 10/11 wifi: mac80211_hwsim: nan: Handle more of the NAN configuration
In reply to Ilan Peer- Use the discovery beacon interval configured by user space instead of always using hardcoded 100 TUs.
- Append the NAN attributes set by user space to the locally generated ones in the discovery beacons.
--- .../net/wireless/virtual/mac80211_hwsim_nan.c | 69 +++++++++++++++++-- .../net/wireless/virtual/mac80211_hwsim_nan.h | 5 ++ 2 files changed, 69 insertions(+), 5 deletions(-)
drivers/net/wireless/virtual/mac80211_hwsim_nan.c +64 -5
@@ -36,6 +36,9 @@ static_assert(DW0_TSF_MASK + 1 == 8192 * 1024);/* Size of the NAN vendor element carrying the mandatory attributes */ #define NAN_BEACON_ELEM_LEN 27 +/* Space left in the NAN vendor element for the configured attributes */ +#define NAN_BEACON_EXTRA_ATTRS_LEN (255 - (NAN_BEACON_ELEM_LEN - 2)) +/* Quiet time at the end of each slot where TX is suppressed */ #define NAN_CHAN_SWITCH_TIME_US 256
@@ -704,16 +707,27 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data,struct sk_buff *skb;/* -* TODO: Should the configured vendor elements or NAN attributes be -* included in some of these beacons? +* TODO: Should the configured vendor elements be included in some of +* these beacons? */ +/* Allocate maximal size for NAN IE */ +if (is_discovery) + alloc_size +=NAN_BEACON_EXTRA_ATTRS_LEN ; + skb =alloc_skb (alloc_size,GFP_ATOMIC );if (!skb)return ;spin_lock (&data->nan.state_lock); +/* +* The attributes configured by user space are appended to the +* mandatory ones. +*/ +if (is_discovery) + nan_ie.len += data->nan.extra_nan_attrs_len; +skb_reserve (skb,IEEE80211_TX_STATUS_HEADROOM ); mgmt = skb_put(skb, offsetofend(struct ieee80211_mgmt, u.beacon));
@@ -724,7 +738,9 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data, mgmt->frame_control =cpu_to_le16 (IEEE80211_FTYPE_MGMT |IEEE80211_STYPE_BEACON ); - mgmt->u.beacon.beacon_int =cpu_to_le16 (is_discovery ?100 :DWST_TU ); + mgmt->u.beacon.beacon_int = +cpu_to_le16 (is_discovery ? data->nan.discovery_beacon_interval : +DWST_TU ); mgmt->u.beacon.capab_info =cpu_to_le16 (WLAN_CAPABILITY_SHORT_SLOT_TIME |WLAN_CAPABILITY_SHORT_PREAMBLE );
@@ -755,6 +771,10 @@ mac80211_hwsim_nan_tx_beacon(struct mac80211_hwsim_data *data,skb_put_data (skb, &data->nan.current_ami,sizeof (data->nan.current_ami)); +if (is_discovery && data->nan.extra_nan_attrs_len) +skb_put_data (skb, data->nan.extra_nan_attrs, + data->nan.extra_nan_attrs_len); +spin_unlock (&data->nan.state_lock);mac80211_hwsim_tx_frame (data->hw, skb, channel);
@@ -884,10 +904,11 @@ mac80211_hwsim_nan_discovery_beacon_timer(struct hrtimer *timer) tsf_now =mac80211_hwsim_get_tsf (data->hw, data->nan.device_vif);/* Wrap value to be after the next TBTT */ - tbtt = tsf_now +ieee80211_tu_to_usec (100 ); + tbtt = tsf_now +ieee80211_tu_to_usec (data->nan.discovery_beacon_interval);/* Round TBTT down to the correct time */ -div_u64_rem (tbtt,ieee80211_tu_to_usec (100 ), &remainder); +div_u64_rem (tbtt,ieee80211_tu_to_usec (data->nan.discovery_beacon_interval), + &remainder); tbtt = tbtt - remainder; hrtimer_set_expires(&data->nan.discovery_beacon_timer,
@@ -911,8 +932,37 @@ mac80211_hwsim_nan_sched_update_work(struct wiphy *wiphy,static int mac80211_hwsim_nan_set_config (struct mac80211_hwsim_data *data,struct cfg80211_nan_conf *conf) { +const u8 *extra_nan_attrs =NULL ; +const u8 *old; + +if (conf->extra_nan_attrs_len >NAN_BEACON_EXTRA_ATTRS_LEN ) +return -EINVAL ; + +if (conf->extra_nan_attrs_len) { + extra_nan_attrs =kmemdup (conf->extra_nan_attrs, + conf->extra_nan_attrs_len, +GFP_KERNEL ); +if (!extra_nan_attrs) +return -ENOMEM ; + } + data->nan.notify_dw = conf->enable_dw_notification; + scoped_guard(spinlock_bh, &data->nan.state_lock) { +/* +* Fall back to the device default if user space did not +* configure it +*/ + data->nan.discovery_beacon_interval = + conf->discovery_beacon_interval ? :100 ; + + old = data->nan.extra_nan_attrs; + data->nan.extra_nan_attrs = extra_nan_attrs; + data->nan.extra_nan_attrs_len = conf->extra_nan_attrs_len; + } + +kfree (old); +return 0 ; }
@@ -968,6 +1018,7 @@ int mac80211_hwsim_nan_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif) {struct mac80211_hwsim_data *data = hw->priv; +const u8 *old;if (vif->type !=NL80211_IFTYPE_NAN || !data->nan.device_vif || data->nan.device_vif != vif)
@@ -979,6 +1030,14 @@ int mac80211_hwsim_nan_stop(struct ieee80211_hw *hw,wiphy_delayed_work_cancel (hw->wiphy, &data->nan.sched_update_work); data->nan.device_vif =NULL ; + scoped_guard(spinlock_bh, &data->nan.state_lock) { + old = data->nan.extra_nan_attrs; + data->nan.extra_nan_attrs =NULL ; + data->nan.extra_nan_attrs_len =0 ; + } + +kfree (old); +return 0 ; }
drivers/net/wireless/virtual/mac80211_hwsim_nan.h +5 -0
@@ -32,6 +32,9 @@ struct mac80211_hwsim_nan_data {/* Later members are protected by this lock */ spinlock_t state_lock; +const u8 *extra_nan_attrs; +u16 extra_nan_attrs_len; +u8 master_pref;u8 random_factor;
@@ -53,6 +56,8 @@ struct mac80211_hwsim_nan_data {bool tsf_adjusted;bool tsf_discontinuity; +u8 discovery_beacon_interval; +/* * Local schedule - stores channel definition for each 16TU slot. * Derived from NMI vif->cfg.nan_schedule. chan == NULL means not
Signature · 1 line
2.55.0
PATCH v3 11/11 wifi: mac80211_hwsim: add NAN Instant Communication support
In reply to Ilan PeerAdvertise Instant Communication (IC) support, and when it is enabled:
- Transmit the discovery beacons disregarding the role and the state, with the configured beacon interval and the NAN attributes set by user space.
- Accept beacons that carry a Service ID List or a Subscribe Service ID List attribute at any time, so that they are forwarded to mac80211.
- Process discovery beacons received during non DW slots for anchor master tracking and synchronization.
--- .../wireless/virtual/mac80211_hwsim_main.c | 7 +- .../net/wireless/virtual/mac80211_hwsim_nan.c | 129 ++++++++++++++++-- .../net/wireless/virtual/mac80211_hwsim_nan.h | 2 + 3 files changed, 122 insertions(+), 16 deletions(-)
drivers/net/wireless/virtual/mac80211_hwsim_main.c +6 -1
@@ -1775,6 +1775,7 @@ struct tx_iter_data {struct ieee80211_channel *channel;struct ieee80211_rx_status *rx_status;struct ieee80211_hw *hw; +struct sk_buff *skb;bool receive; };
@@ -1787,6 +1788,7 @@ static void mac80211_hwsim_tx_iter(void *_data, u8 *addr,if (vif->type ==NL80211_IFTYPE_NAN || vif->type ==NL80211_IFTYPE_NAN_DATA ) { data->receive =mac80211_hwsim_nan_receive (data->hw, + data->skb, data->channel, data->rx_status);return ;
@@ -1968,6 +1970,7 @@ static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw, .hw = data2->hw, .channel = chan, .rx_status = &rx_status, + .skb = skb, };if (data == data2)
@@ -5841,7 +5844,8 @@ static int mac80211_hwsim_new_radio(struct genl_info *info,BIT (NL80211_BAND_5GHZ ); hw->wiphy->nan_capa.flags =WIPHY_NAN_FLAGS_CONFIGURABLE_SYNC | -WIPHY_NAN_FLAGS_USERSPACE_DE ; +WIPHY_NAN_FLAGS_USERSPACE_DE | +WIPHY_NAN_FLAGS_INSTANT_COMM ; hw->wiphy->nan_capa.op_mode =NAN_OP_MODE_PHY_MODE_MASK |NAN_OP_MODE_80P80MHZ |NAN_OP_MODE_160MHZ ;
@@ -6643,6 +6647,7 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,struct tx_iter_data iter_data = { .hw = data2->hw, .rx_status = &rx_status, + .skb = skb, };/* throw away off-channel packets, but allow both the temporary
drivers/net/wireless/virtual/mac80211_hwsim_nan.c +114 -15
203 lines not on this page · raw message
drivers/net/wireless/virtual/mac80211_hwsim_nan.h +2 -0
@@ -56,6 +56,7 @@ struct mac80211_hwsim_nan_data {bool tsf_adjusted;bool tsf_discontinuity; +bool instant_comm;u8 discovery_beacon_interval;/*
@@ -98,6 +99,7 @@ void mac80211_hwsim_nan_get_tx_chandef(struct ieee80211_hw *hw, struct cfg80211_chan_def *chandef);bool mac80211_hwsim_nan_receive (struct ieee80211_hw *hw, +struct sk_buff *skb,struct ieee80211_channel *channel,struct ieee80211_rx_status *rx_status);
Signature · 1 line
2.55.0