Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1379474pxv; Fri, 16 Jul 2021 08:05:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyg8SiIXJNi5DOs8ULcUWsYeMXIaGXC/vNgZz1d6e3lTN2Tsl4Q2E2nboY9TEy3rr4RKy3O X-Received: by 2002:a17:907:3e94:: with SMTP id hs20mr11940720ejc.95.1626447942778; Fri, 16 Jul 2021 08:05:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626447942; cv=none; d=google.com; s=arc-20160816; b=xGG7f8OFhb0+pMi7H0yeUoByX+uCTpK+JIhweYkfX+qNFmIs/JWGRO6Yj6fSFvAP6g ruEcMmDNYMYT5R39iycDRGbfiRqKjQuqQtA5vPjBxSE643GSZi91Fgk4b5CtCq8LYzCD i9x0Ahr6l02GdgEfMawszB01DRXb0m3T1cuYyQGg7k6rUi5dE/aY+yzUtj2QR54PXomt 3p30iHdBfd13sXQOKBoRGiLMSMlxqW0ovWIFUMGXi63N+LqmDs93G5FhHXFpJpx/BWb6 9d8E2QDcaBkEeWHezTTrbyL+UIt1a2wJFKUyl0atmuN3Uc8G++z7RKeMT2Oe5yQfbgpm Aq6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MBWAcoAQkMvhEAK63fDKpJ+6zVxJOZCxhrYrZawFzog=; b=Bonn73Qmns7yecDdsXvviHUyriRABNGX1hIce0rzhuWmSyHo8j67PNLTnAXpRwvHwC ES2iUFrfuqnhFL/vPOS0Bfd0AR9v7lOtra4hIDh9m7+anCRv8TJMKX7gBFsBpZpV17Dc qve7Ks2qoopOWtZcFall9rr4NROQ8jAqoLMIUAhdb3ylVVJXdaSXaxrOAE7Plg4WVMAl MW2AkowIeJs0eoWxT/fUd6BN1FhsXkGbuRuGbSG7ckA8UJ3PXG4pGgs+jINAdTwjyY7s wZoSHO0p5Orcv6VjxV6F2EKk8RyvXvBduHY46TqhExbcGGhePbY0RTmp7V3dPfT7hnmF NMMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CN4Ey2ji; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si4616168eda.189.2021.07.16.08.04.59; Fri, 16 Jul 2021 08:05:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CN4Ey2ji; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240635AbhGPPHb (ORCPT + 99 others); Fri, 16 Jul 2021 11:07:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:46646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240645AbhGPPHb (ORCPT ); Fri, 16 Jul 2021 11:07:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 161B3613CF; Fri, 16 Jul 2021 15:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626447876; bh=+oRoMlZupxSXsPxBADGfONvU0iOMjqE4DR1w2Z9J5fg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CN4Ey2jiJvK9NBQ29+6wdzDlu808z39CAETBqh8Y12nwwqq1DjM6fxqjfakYOg4lC pbD9RMnqKiNeigK2hGOBPj7cfAG9FxMZDNE3sQ1+W4t8TMa9yPUXEhyywlYrTZmka0 eFyKV1uPucbrFX42v1U3yocm8aM2g9YgaQedoxXii135GQI3iAI0/RTstS2bGpOtRE HLrW9ElXIWbAnbUYpxpAcpXvdNaQyLrnDFvdDYbDHHS7ScASuzWxpoa/9QzgarQTUB 4a25euqHKZlqXIpusB1MIE3jPpZ/kaUoguCT9K/YxaKwN/BHPXlu0bhoUvQ9aKxOax nUHpM89zS6rIQ== From: Lorenzo Bianconi To: linux-wireless@vger.kernel.org Cc: johannes@sipsolutions.net, nbd@nbd.name, ryder.lee@mediatek.com, lorenzo.bianconi@redhat.com Subject: [RFC mac80211-next 2/7] mac80211: introduce individual TWT support in AP mode. Date: Fri, 16 Jul 2021 17:04:01 +0200 Message-Id: <31389d3256d05dd6fae7fbeb13bc5c0ceb653096.1626447537.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Introduce TWT action frames parsing support to mac80211. Currently just individual TWT agreement are support in AP mode. Whenever the AP receives a TWT action frame from an associated client, after performing sanity checks, it will notify the underlay driver with requested parameters in order to check if they are supported and if there is enough room for a new agreement. The hw is expected to set agreement result and report it to mac80211. The two following drv callbacks have been added to mac80211: - add_twt_setup (mandatory) - twt_teardown_request (optional) mac80211 will send an action frame reply according to the result reported by the driver/fw. Signed-off-by: Lorenzo Bianconi --- include/net/mac80211.h | 13 +++ net/mac80211/driver-ops.h | 24 +++++ net/mac80211/ieee80211_i.h | 3 + net/mac80211/iface.c | 10 ++ net/mac80211/rx.c | 54 +++++++++++ net/mac80211/s1g.c | 183 +++++++++++++++++++++++++++++++++++++ net/mac80211/status.c | 30 +++++- 7 files changed, 316 insertions(+), 1 deletion(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index e89530d0d9c6..bd98d3257f2a 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -3898,6 +3898,13 @@ enum ieee80211_reconfig_type { * @set_sar_specs: Update the SAR (TX power) settings. * @sta_set_decap_offload: Called to notify the driver when a station is allowed * to use rx decapsulation offload + * @add_twt_setup: Update hw with TWT agreement parameters received from the peer. + * This callback allows the hw to check if requested parameters + * are supported and if there is enough room for a new agreement. + * The hw is expected to set agreement result in the req_type field of + * agrt_resp structure. + * @twt_teardown_request: Update the hw with TWT teardown request received + * from the peer. */ struct ieee80211_ops { void (*tx)(struct ieee80211_hw *hw, @@ -4218,6 +4225,12 @@ struct ieee80211_ops { void (*sta_set_decap_offload)(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta, bool enabled); + int (*add_twt_setup)(struct ieee80211_hw *hw, + struct ieee80211_sta *sta, + struct ieee80211_twt_params *agrt_req, + struct ieee80211_twt_params *agrt_resp); + void (*twt_teardown_request)(struct ieee80211_hw *hw, + struct ieee80211_sta *sta, u8 flowid); }; /** diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h index 604ca59937f0..79dc83d61c19 100644 --- a/net/mac80211/driver-ops.h +++ b/net/mac80211/driver-ops.h @@ -1429,4 +1429,28 @@ static inline void drv_sta_set_decap_offload(struct ieee80211_local *local, trace_drv_return_void(local); } +static inline int drv_add_twt_setup(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_sta *sta, + struct ieee80211_twt_params *agrt_req, + struct ieee80211_twt_params *agrt_resp) +{ + might_sleep(); + check_sdata_in_driver(sdata); + + return local->ops->add_twt_setup(&local->hw, sta, agrt_req, agrt_resp); +} + +static inline void drv_twt_teardown_request(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_sta *sta, + u8 flowid) +{ + might_sleep(); + check_sdata_in_driver(sdata); + + if (local->ops->twt_teardown_request) + local->ops->twt_teardown_request(&local->hw, sta, flowid); +} + #endif /* __MAC80211_DRIVER_OPS */ diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 648696b49f89..c0f6fe6d38e1 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -1912,6 +1912,9 @@ ieee80211_he_op_ie_to_bss_conf(struct ieee80211_vif *vif, /* S1G */ void ieee80211_s1g_sta_rate_init(struct sta_info *sta); +bool ieee80211_s1g_is_twt_setup(struct sk_buff *skb); +int ieee80211_s1g_h_twt(struct ieee80211_sub_if_data *sdata, + struct sk_buff *skb); /* Spectrum management */ void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata, diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index 137fa4c50e07..b05cec75a733 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -1396,6 +1396,16 @@ static void ieee80211_iface_work(struct work_struct *work) WARN_ON(1); break; } + } else if (ieee80211_is_action(mgmt->frame_control) && + mgmt->u.action.category == WLAN_CATEGORY_S1G) { + switch (mgmt->u.action.u.s1g.action_code) { + case WLAN_S1G_TWT_TEARDOWN: + case WLAN_S1G_TWT_SETUP: + ieee80211_s1g_h_twt(sdata, skb); + break; + default: + break; + } } else if (ieee80211_is_ext(mgmt->frame_control)) { if (sdata->vif.type == NL80211_IFTYPE_STATION) ieee80211_sta_rx_queued_ext(sdata, skb); diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index af0ef456eb0f..683ec5e4182a 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -3198,6 +3198,50 @@ ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx) return RX_CONTINUE; } +static ieee80211_rx_result debug_noinline +ieee80211_rx_h_twt(struct ieee80211_rx_data *rx) +{ + struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)rx->skb->data; + struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); + struct ieee80211_sub_if_data *sdata = rx->sdata; + const struct ieee80211_sband_iftype_data *iftd; + struct ieee80211_supported_band *sband; + + /* TWT actions are only supported in AP for the moment */ + if (sdata->vif.type != NL80211_IFTYPE_AP) + return RX_CONTINUE; + + sband = rx->local->hw.wiphy->bands[status->band]; + iftd = ieee80211_get_sband_iftype_data(sband, sdata->vif.type); + if (!iftd) + return RX_CONTINUE; + + if (!rx->local->ops->add_twt_setup) + return RX_CONTINUE; + + if (!(iftd->he_cap.he_cap_elem.mac_cap_info[0] & + IEEE80211_HE_MAC_CAP0_TWT_RES)) + return RX_CONTINUE; + + if (!rx->sta) + return RX_CONTINUE; + + switch (mgmt->u.action.u.s1g.action_code) { + case WLAN_S1G_TWT_SETUP: + if (rx->skb->len < IEEE80211_TWT_IND_SETUP_SIZE) + break; + return RX_QUEUED; + case WLAN_S1G_TWT_TEARDOWN: + if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE + 2) + break; + return RX_QUEUED; + default: + break; + } + + return RX_CONTINUE; +} + static ieee80211_rx_result debug_noinline ieee80211_rx_h_action(struct ieee80211_rx_data *rx) { @@ -3477,6 +3521,16 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx) !mesh_path_sel_is_hwmp(sdata)) break; goto queue; + case WLAN_CATEGORY_S1G: + switch (mgmt->u.action.u.s1g.action_code) { + case WLAN_S1G_TWT_SETUP: + case WLAN_S1G_TWT_TEARDOWN: + if (ieee80211_rx_h_twt(rx) != RX_CONTINUE) + goto queue; + default: + break; + } + break; } return RX_CONTINUE; diff --git a/net/mac80211/s1g.c b/net/mac80211/s1g.c index c33f332b049a..ce3a93776a1a 100644 --- a/net/mac80211/s1g.c +++ b/net/mac80211/s1g.c @@ -6,6 +6,7 @@ #include #include #include "ieee80211_i.h" +#include "driver-ops.h" void ieee80211_s1g_sta_rate_init(struct sta_info *sta) { @@ -14,3 +15,185 @@ void ieee80211_s1g_sta_rate_init(struct sta_info *sta) sta->rx_stats.last_rate = STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_S1G); } + +bool ieee80211_s1g_is_twt_setup(struct sk_buff *skb) +{ + struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; + + if (likely(!ieee80211_is_action(mgmt->frame_control))) + return false; + + if (likely(mgmt->u.action.category != WLAN_CATEGORY_S1G)) + return false; + + return mgmt->u.action.u.s1g.action_code == WLAN_S1G_TWT_SETUP; +} + +static int +ieee80211_s1g_send_twt_setup(struct ieee80211_sub_if_data *sdata, + const u8 *da, const u8 *bssid, u8 dialog_token, + struct ieee80211_twt_params *params) +{ + struct ieee80211_local *local = sdata->local; + struct ieee80211_twt_setup *twt; + struct ieee80211_mgmt *mgmt; + struct sk_buff *skb; + + skb = dev_alloc_skb(local->hw.extra_tx_headroom + + IEEE80211_TWT_IND_SETUP_SIZE); + if (!skb) + return -ENOMEM; + + skb_reserve(skb, local->hw.extra_tx_headroom); + mgmt = skb_put_zero(skb, IEEE80211_TWT_IND_SETUP_SIZE); + mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | + IEEE80211_STYPE_ACTION); + memcpy(mgmt->da, da, ETH_ALEN); + memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); + memcpy(mgmt->bssid, bssid, ETH_ALEN); + + mgmt->u.action.category = WLAN_CATEGORY_S1G; + mgmt->u.action.u.s1g.action_code = WLAN_S1G_TWT_SETUP; + + twt = (struct ieee80211_twt_setup *)mgmt->u.action.u.s1g.variable; + twt->dialog_token = dialog_token; + twt->element_id = WLAN_EID_S1G_TWT; + twt->length = sizeof(struct ieee80211_twt_params); + + memcpy(twt->params, params, twt->length); + + IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | + IEEE80211_TX_CTL_REQ_TX_STATUS; + ieee80211_tx_skb(sdata, skb); + + return 0; +} + +static int +ieee80211_s1g_send_twt_teardown(struct ieee80211_sub_if_data *sdata, + const u8 *da, const u8 *bssid, u8 flowid) +{ + struct ieee80211_local *local = sdata->local; + struct ieee80211_mgmt *mgmt; + struct sk_buff *skb; + u8 *id; + + skb = dev_alloc_skb(local->hw.extra_tx_headroom + + IEEE80211_MIN_ACTION_SIZE + 2); + if (!skb) + return -ENOMEM; + + skb_reserve(skb, local->hw.extra_tx_headroom); + mgmt = skb_put_zero(skb, IEEE80211_MIN_ACTION_SIZE + 2); + mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | + IEEE80211_STYPE_ACTION); + memcpy(mgmt->da, da, ETH_ALEN); + memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); + memcpy(mgmt->bssid, bssid, ETH_ALEN); + + mgmt->u.action.category = WLAN_CATEGORY_S1G; + mgmt->u.action.u.s1g.action_code = WLAN_S1G_TWT_TEARDOWN; + id = (u8 *)mgmt->u.action.u.s1g.variable; + *id = flowid; + + IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | + IEEE80211_TX_CTL_REQ_TX_STATUS; + ieee80211_tx_skb(sdata, skb); + + return 0; +} + +static int +ieee80211_s1g_rx_h_twt_setup(struct ieee80211_sub_if_data *sdata, + struct sta_info *sta, struct sk_buff *skb) +{ + struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; + struct ieee80211_twt_params *agrt_req, agrt_resp; + struct ieee80211_twt_setup *twt; + + twt = (struct ieee80211_twt_setup *)mgmt->u.action.u.s1g.variable; + if (twt->element_id != WLAN_EID_S1G_TWT) + return -EINVAL; + + agrt_req = (struct ieee80211_twt_params *)twt->params; + + /* broadcast TWT not supported yet */ + if (agrt_req->control & IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST) + return -EINVAL; + + drv_add_twt_setup(sdata->local, sdata, &sta->sta, agrt_req, + &agrt_resp); + + return ieee80211_s1g_send_twt_setup(sdata, mgmt->sa, sdata->vif.addr, + twt->dialog_token, &agrt_resp); +} + +static int +ieee80211_s1g_status_twt_setup(struct ieee80211_sub_if_data *sdata, + struct sta_info *sta, struct sk_buff *skb) +{ + struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); + struct ieee80211_twt_params *agrt_resp; + struct ieee80211_twt_setup *twt; + u8 flowid; + + if (info->flags & IEEE80211_TX_STAT_ACK) + return 0; /* nothing to do */ + + twt = (struct ieee80211_twt_setup *)mgmt->u.action.u.s1g.variable; + agrt_resp = (struct ieee80211_twt_params *)twt->params; + flowid = FIELD_GET(IEEE80211_TWT_REQTYPE_FLOWID, + le16_to_cpu(agrt_resp->req_type)); + + drv_twt_teardown_request(sdata->local, sdata, &sta->sta, flowid); + + return ieee80211_s1g_send_twt_teardown(sdata, mgmt->sa, + sdata->vif.addr, flowid); +} + +static int +ieee80211_s1g_rx_h_twt_teardown(struct ieee80211_sub_if_data *sdata, + struct sta_info *sta, struct sk_buff *skb) +{ + struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; + + drv_twt_teardown_request(sdata->local, sdata, &sta->sta, + mgmt->u.action.u.s1g.variable[0]); + + return 0; +} + +int ieee80211_s1g_h_twt(struct ieee80211_sub_if_data *sdata, + struct sk_buff *skb) +{ + struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; + struct ieee80211_local *local = sdata->local; + struct sta_info *sta; + const u8 *addr; + + mutex_lock(&local->sta_mtx); + + addr = skb->pkt_type == IEEE80211_TX_STATUS_MSG ? mgmt->da : mgmt->sa; + sta = sta_info_get_bss(sdata, addr); + if (!sta) + goto out; + + switch (mgmt->u.action.u.s1g.action_code) { + case WLAN_S1G_TWT_SETUP: + if (skb->pkt_type == IEEE80211_TX_STATUS_MSG) + ieee80211_s1g_status_twt_setup(sdata, sta, skb); + else + ieee80211_s1g_rx_h_twt_setup(sdata, sta, skb); + break; + case WLAN_S1G_TWT_TEARDOWN: + ieee80211_s1g_rx_h_twt_teardown(sdata, sta, skb); + break; + default: + break; + } + +out: + mutex_unlock(&local->sta_mtx); + return 0; +} diff --git a/net/mac80211/status.c b/net/mac80211/status.c index 9baf185ee4c7..6fc37cf86eda 100644 --- a/net/mac80211/status.c +++ b/net/mac80211/status.c @@ -17,6 +17,29 @@ #include "led.h" #include "wme.h" +static struct sk_buff * +ieee80211_tx_queue_skb(struct ieee80211_hw *hw, + struct ieee80211_tx_status *status, + bool monitor) +{ + struct sk_buff *skb = status->skb; + struct sta_info *sta; + + if (!status->sta) + goto out; + + if (likely(!ieee80211_s1g_is_twt_setup(skb))) + goto out; + + sta = container_of(status->sta, struct sta_info, sta); + skb->pkt_type = IEEE80211_TX_STATUS_MSG; + skb_queue_tail(&sta->sdata->skb_queue, skb); + skb = monitor ? skb_clone(skb, GFP_ATOMIC) : NULL; + ieee80211_queue_work(hw, &sta->sdata->work); + +out: + return skb; +} void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb) @@ -1028,13 +1051,18 @@ static void __ieee80211_tx_status(struct ieee80211_hw *hw, * with this test... */ if (!local->monitors && (!send_to_cooked || !local->cooked_mntrs)) { - if (status->free_list) + skb = ieee80211_tx_queue_skb(hw, status, false); + if (skb && status->free_list) list_add_tail(&skb->list, status->free_list); else dev_kfree_skb(skb); return; } + skb = ieee80211_tx_queue_skb(hw, status, true); + if (!skb) + return; + /* send to monitor interfaces */ ieee80211_tx_monitor(local, skb, sband, retry_count, shift, send_to_cooked, status); -- 2.31.1