[][MAC80211][hostapd][core][Config TWT by User]

[Description]
Add user configuration for TWT

[Release-log]
N/A

Change-Id: I1bf85718a48144e24ca1c158441bc1921d4bdf87
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/5531443
diff --git a/openwrt_patches-21.02/412-master-mac80211-check-twt-responder-when-setup-twt.patch b/openwrt_patches-21.02/412-master-mac80211-check-twt-responder-when-setup-twt.patch
new file mode 100644
index 0000000..d402f90
--- /dev/null
+++ b/openwrt_patches-21.02/412-master-mac80211-check-twt-responder-when-setup-twt.patch
@@ -0,0 +1,46 @@
+From 27c6b56c3335614299cf1dcf5a8b5320f83f64d5 Mon Sep 17 00:00:00 2001
+From: Peter Chiu <chui-hao.chiu@mediatek.com>
+Date: Tue, 18 Jan 2022 20:55:44 +0800
+Subject: [PATCH 1/2] mac80211: check twt responder when setup twt
+
+Change-Id: Iee987aaf9e907ea78367c8f1061d05bfacb5c1be
+---
+ ...11-check-twt-responder-when-setu-twt.patch | 26 +++++++++++++++++++
+ 1 file changed, 26 insertions(+)
+ create mode 100644 package/kernel/mac80211/patches/subsys/901-mac80211-check-twt-responder-when-setu-twt.patch
+
+diff --git a/package/kernel/mac80211/patches/subsys/901-mac80211-check-twt-responder-when-setu-twt.patch b/package/kernel/mac80211/patches/subsys/901-mac80211-check-twt-responder-when-setu-twt.patch
+new file mode 100644
+index 0000000..e2f24b4
+--- /dev/null
++++ b/package/kernel/mac80211/patches/subsys/901-mac80211-check-twt-responder-when-setu-twt.patch
+@@ -0,0 +1,26 @@
++From fa2d47980f56462c5767a0ad9537f3e58f5864f4 Mon Sep 17 00:00:00 2001
++From: Peter Chiu <chui-hao.chiu@mediatek.com>
++Date: Tue, 18 Jan 2022 20:29:44 +0800
++Subject: [PATCH] mac80211: do not setup twt when twt responder is false
++
++---
++ net/mac80211/rx.c | 3 +++
++ 1 file changed, 3 insertions(+)
++
++diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
++index 41c3f22..3961270 100644
++--- a/net/mac80211/rx.c
+++++ b/net/mac80211/rx.c
++@@ -3231,6 +3231,9 @@ ieee80211_process_rx_twt_action(struct ieee80211_rx_data *rx)
++ 	if (sdata->vif.type != NL80211_IFTYPE_AP)
++ 		return false;
++ 
+++	if (!sdata->vif.bss_conf.twt_responder)
+++		return false;
+++
++ 	if (!rx->local->ops->add_twt_setup)
++ 		return false;
++ 
++-- 
++2.29.2
++
+-- 
+2.29.2
+
diff --git a/openwrt_patches-21.02/413-master-hostapd-AP-Add-user-configuration-for-TWT-responder-role.patch b/openwrt_patches-21.02/413-master-hostapd-AP-Add-user-configuration-for-TWT-responder-role.patch
new file mode 100644
index 0000000..889ab95
--- /dev/null
+++ b/openwrt_patches-21.02/413-master-hostapd-AP-Add-user-configuration-for-TWT-responder-role.patch
@@ -0,0 +1,107 @@
+From 98cbf8b36d141112c7bc9e3a366ecc333b60ee90 Mon Sep 17 00:00:00 2001
+From: Peter Chiu <chui-hao.chiu@mediatek.com>
+Date: Tue, 18 Jan 2022 20:56:46 +0800
+Subject: [PATCH 2/2] AP Add user configuration for TWT responder role
+
+Change-Id: I4f669319eb72e37d22bd97901a0d418450f301c3
+---
+ ...configuration-for-TWT-responder-role.patch | 87 +++++++++++++++++++
+ 1 file changed, 87 insertions(+)
+ create mode 100644 package/network/services/hostapd/patches/905-AP-Add-user-configuration-for-TWT-responder-role.patch
+
+diff --git a/package/network/services/hostapd/patches/905-AP-Add-user-configuration-for-TWT-responder-role.patch b/package/network/services/hostapd/patches/905-AP-Add-user-configuration-for-TWT-responder-role.patch
+new file mode 100644
+index 0000000..1ece165
+--- /dev/null
++++ b/package/network/services/hostapd/patches/905-AP-Add-user-configuration-for-TWT-responder-role.patch
+@@ -0,0 +1,87 @@
++From c0ce87b34e120d1bc79bdca349fa8211ecff3a71 Mon Sep 17 00:00:00 2001
++From: Mohammad Asaad Akram <asadkrm@codeaurora.org>
++Date: Fri, 28 May 2021 09:47:38 +0530
++Subject: [PATCH 1/7] AP: Add user configuration for TWT responder role
++
++Add user configuration he_twt_responder for enabling/disabling TWT
++responder role, in addition to checking the driver's capability. The
++default configuration is to enable TWT responder role when the driver
++supports this.
++
++Signed-off-by: Mohammad Asaad Akram <asadkrm@codeaurora.org>
++---
++ hostapd/config_file.c  | 2 ++
++ hostapd/hostapd.conf   | 5 +++++
++ src/ap/ap_config.c     | 1 +
++ src/ap/ap_config.h     | 1 +
++ src/ap/ieee802_11_he.c | 3 ++-
++ 5 files changed, 11 insertions(+), 1 deletion(-)
++
++diff --git a/hostapd/config_file.c b/hostapd/config_file.c
++index 8f6281a..45aa809 100644
++--- a/hostapd/config_file.c
+++++ b/hostapd/config_file.c
++@@ -3537,6 +3537,8 @@ static int hostapd_config_fill(struct hostapd_config *conf,
++ 		conf->he_op.he_default_pe_duration = atoi(pos);
++ 	} else if (os_strcmp(buf, "he_twt_required") == 0) {
++ 		conf->he_op.he_twt_required = atoi(pos);
+++	} else if (os_strcmp(buf, "he_twt_responder") == 0) {
+++		conf->he_op.he_twt_responder = atoi(pos);
++ 	} else if (os_strcmp(buf, "he_rts_threshold") == 0) {
++ 		conf->he_op.he_rts_threshold = atoi(pos);
++ 	} else if (os_strcmp(buf, "he_basic_mcs_nss_set") == 0) {
++diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf
++index 0c951a9..77775fc 100644
++--- a/hostapd/hostapd.conf
+++++ b/hostapd/hostapd.conf
++@@ -838,6 +838,11 @@ wmm_ac_vo_acm=0
++ # 1 = required
++ #he_twt_required=0
++ 
+++#he_twt_responder: Whether TWT (HE) responder is enabled
+++# 0 = disabled
+++# 1 = enabled if supported by the driver (default)
+++#he_twt_responder=1
+++
++ #he_rts_threshold: Duration of STA transmission
++ # 0 = not set (default)
++ # unsigned integer = duration in units of 16 us
++diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c
++index ce281ac..59c356d 100644
++--- a/src/ap/ap_config.c
+++++ b/src/ap/ap_config.c
++@@ -274,6 +274,7 @@ struct hostapd_config * hostapd_config_defaults(void)
++ 	conf->he_op.he_bss_color_disabled = 1;
++ 	conf->he_op.he_bss_color_partial = 0;
++ 	conf->he_op.he_bss_color = 1;
+++	conf->he_op.he_twt_responder = 1;
++ 	conf->he_6ghz_max_mpdu = 2;
++ 	conf->he_6ghz_max_ampdu_len_exp = 7;
++ 	conf->he_6ghz_rx_ant_pat = 1;
++diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
++index ffc3c2c..28d199e 100644
++--- a/src/ap/ap_config.h
+++++ b/src/ap/ap_config.h
++@@ -921,6 +921,7 @@ struct he_operation {
++ 	u8 he_bss_color_partial;
++ 	u8 he_default_pe_duration;
++ 	u8 he_twt_required;
+++	u8 he_twt_responder;
++ 	u16 he_rts_threshold;
++ 	u16 he_basic_mcs_nss_set;
++ };
++diff --git a/src/ap/ieee802_11_he.c b/src/ap/ieee802_11_he.c
++index 8ff3835..cbe5e63 100644
++--- a/src/ap/ieee802_11_he.c
+++++ b/src/ap/ieee802_11_he.c
++@@ -514,5 +514,6 @@ int hostapd_get_he_twt_responder(struct hostapd_data *hapd,
++ 
++ 	mac_cap = hapd->iface->current_mode->he_capab[mode].mac_cap;
++ 
++-	return !!(mac_cap[HE_MAC_CAPAB_0] & HE_MACCAP_TWT_RESPONDER);
+++	return !!(mac_cap[HE_MAC_CAPAB_0] & HE_MACCAP_TWT_RESPONDER) &&
+++		hapd->iface->conf->he_op.he_twt_responder;
++ }
++-- 
++2.29.2
++
+-- 
+2.29.2
+