diff mbox series

[10/13] wcn36xx: Add GTK offload info to WoWLAN resume

Message ID 20201228162839.369156-11-bryan.odonoghue@linaro.org
State Superseded
Headers show
Series wcn36xx: Enable downstream consistent Wake on Lan | expand

Commit Message

Bryan O'Donoghue Dec. 28, 2020, 4:28 p.m. UTC
Having enabled GTK rekey in suspend, we need to extract the replay counter
from the firmware on resume and perform a ieee80211_gtk_rekey_notify() so
that the STA remains verified from the perspective of the AP.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

---
 drivers/net/wireless/ath/wcn36xx/hal.h  |  4 +-
 drivers/net/wireless/ath/wcn36xx/main.c |  5 +-
 drivers/net/wireless/ath/wcn36xx/smd.c  | 72 +++++++++++++++++++++++++
 drivers/net/wireless/ath/wcn36xx/smd.h  |  3 ++
 4 files changed, 81 insertions(+), 3 deletions(-)

-- 
2.29.2


_______________________________________________
wcn36xx mailing list
wcn36xx@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/wcn36xx

Comments

Kalle Valo Jan. 11, 2021, 11:28 a.m. UTC | #1
Bryan O'Donoghue <bryan.odonoghue@linaro.org> writes:

> Having enabled GTK rekey in suspend, we need to extract the replay counter

> from the firmware on resume and perform a ieee80211_gtk_rekey_notify() so

> that the STA remains verified from the perspective of the AP.

>

> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

> ---

>  drivers/net/wireless/ath/wcn36xx/hal.h  |  4 +-

>  drivers/net/wireless/ath/wcn36xx/main.c |  5 +-

>  drivers/net/wireless/ath/wcn36xx/smd.c  | 72 +++++++++++++++++++++++++

>  drivers/net/wireless/ath/wcn36xx/smd.h  |  3 ++

>  4 files changed, 81 insertions(+), 3 deletions(-)

>

> diff --git a/drivers/net/wireless/ath/wcn36xx/hal.h b/drivers/net/wireless/ath/wcn36xx/hal.h

> index 1f3c2e840232..455143c4164e 100644

> --- a/drivers/net/wireless/ath/wcn36xx/hal.h

> +++ b/drivers/net/wireless/ath/wcn36xx/hal.h

> @@ -4919,7 +4919,7 @@ struct wcn36xx_hal_gtk_offload_rsp_msg {

>  struct wcn36xx_hal_gtk_offload_get_info_req_msg {

>  	struct wcn36xx_hal_msg_header header;

>  	u8 bss_index;

> -};

> +} __packed;

>  

>  struct wcn36xx_hal_gtk_offload_get_info_rsp_msg {

>  	struct wcn36xx_hal_msg_header header;

> @@ -4943,7 +4943,7 @@ struct wcn36xx_hal_gtk_offload_get_info_rsp_msg {

>  	u32 igtk_rekey_count;

>  

>  	u8 bss_index;

> -};

> +} __packed;


Why __packed? Commit log mentions nothing about that.

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

_______________________________________________
wcn36xx mailing list
wcn36xx@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/wcn36xx
Kalle Valo Jan. 11, 2021, 11:39 a.m. UTC | #2
Bryan O'Donoghue <bryan.odonoghue@linaro.org> writes:

> Having enabled GTK rekey in suspend, we need to extract the replay counter

> from the firmware on resume and perform a ieee80211_gtk_rekey_notify() so

> that the STA remains verified from the perspective of the AP.

>

> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>


[...]

>  static const struct wiphy_wowlan_support wowlan_support = {

> -	.flags = WIPHY_WOWLAN_ANY | WIPHY_WOWLAN_MAGIC_PKT

> +	.flags = WIPHY_WOWLAN_ANY |

> +		 WIPHY_WOWLAN_MAGIC_PKT |

> +		 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY

>  };


I wonder should these also be in the last patch? So that the features
are enabled only after everything is implemented.

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Bryan O'Donoghue Jan. 11, 2021, 11:47 a.m. UTC | #3
On 11/01/2021 11:28, Kalle Valo wrote:
> Bryan O'Donoghue <bryan.odonoghue@linaro.org> writes:

> 

>> Having enabled GTK rekey in suspend, we need to extract the replay counter

>> from the firmware on resume and perform a ieee80211_gtk_rekey_notify() so

>> that the STA remains verified from the perspective of the AP.

>>

>> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

>> ---

>>   drivers/net/wireless/ath/wcn36xx/hal.h  |  4 +-

>>   drivers/net/wireless/ath/wcn36xx/main.c |  5 +-

>>   drivers/net/wireless/ath/wcn36xx/smd.c  | 72 +++++++++++++++++++++++++

>>   drivers/net/wireless/ath/wcn36xx/smd.h  |  3 ++

>>   4 files changed, 81 insertions(+), 3 deletions(-)

>>

>> diff --git a/drivers/net/wireless/ath/wcn36xx/hal.h b/drivers/net/wireless/ath/wcn36xx/hal.h

>> index 1f3c2e840232..455143c4164e 100644

>> --- a/drivers/net/wireless/ath/wcn36xx/hal.h

>> +++ b/drivers/net/wireless/ath/wcn36xx/hal.h

>> @@ -4919,7 +4919,7 @@ struct wcn36xx_hal_gtk_offload_rsp_msg {

>>   struct wcn36xx_hal_gtk_offload_get_info_req_msg {

>>   	struct wcn36xx_hal_msg_header header;

>>   	u8 bss_index;

>> -};

>> +} __packed;

>>   

>>   struct wcn36xx_hal_gtk_offload_get_info_rsp_msg {

>>   	struct wcn36xx_hal_msg_header header;

>> @@ -4943,7 +4943,7 @@ struct wcn36xx_hal_gtk_offload_get_info_rsp_msg {

>>   	u32 igtk_rekey_count;

>>   

>>   	u8 bss_index;

>> -};

>> +} __packed;

> 

> Why __packed? Commit log mentions nothing about that.

> 


Because the __u8 at the end aligns to 4 bytes.

I'll add this to the log desc

_______________________________________________
wcn36xx mailing list
wcn36xx@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/wcn36xx
diff mbox series

Patch

diff --git a/drivers/net/wireless/ath/wcn36xx/hal.h b/drivers/net/wireless/ath/wcn36xx/hal.h
index 1f3c2e840232..455143c4164e 100644
--- a/drivers/net/wireless/ath/wcn36xx/hal.h
+++ b/drivers/net/wireless/ath/wcn36xx/hal.h
@@ -4919,7 +4919,7 @@  struct wcn36xx_hal_gtk_offload_rsp_msg {
 struct wcn36xx_hal_gtk_offload_get_info_req_msg {
 	struct wcn36xx_hal_msg_header header;
 	u8 bss_index;
-};
+} __packed;
 
 struct wcn36xx_hal_gtk_offload_get_info_rsp_msg {
 	struct wcn36xx_hal_msg_header header;
@@ -4943,7 +4943,7 @@  struct wcn36xx_hal_gtk_offload_get_info_rsp_msg {
 	u32 igtk_rekey_count;
 
 	u8 bss_index;
-};
+} __packed;
 
 struct dhcp_info {
 	/* Indicates the device mode which indicates about the DHCP activity */
diff --git a/drivers/net/wireless/ath/wcn36xx/main.c b/drivers/net/wireless/ath/wcn36xx/main.c
index aa2a416daa7f..b48a3f0dcc0b 100644
--- a/drivers/net/wireless/ath/wcn36xx/main.c
+++ b/drivers/net/wireless/ath/wcn36xx/main.c
@@ -173,7 +173,9 @@  static struct ieee80211_supported_band wcn_band_5ghz = {
 #ifdef CONFIG_PM
 
 static const struct wiphy_wowlan_support wowlan_support = {
-	.flags = WIPHY_WOWLAN_ANY | WIPHY_WOWLAN_MAGIC_PKT
+	.flags = WIPHY_WOWLAN_ANY |
+		 WIPHY_WOWLAN_MAGIC_PKT |
+		 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
 };
 
 #endif
@@ -1149,6 +1151,7 @@  static int wcn36xx_resume(struct ieee80211_hw *hw)
 			goto out;
 
 		wcn36xx_smd_set_power_params(wcn, false);
+		wcn36xx_smd_gtk_offload_get_info(wcn, vif);
 		wcn36xx_smd_gtk_offload(wcn, vif, false);
 		wcn36xx_smd_ipv6_ns_offload(wcn, vif, false);
 		wcn36xx_smd_arp_offload(wcn, vif, false);
diff --git a/drivers/net/wireless/ath/wcn36xx/smd.c b/drivers/net/wireless/ath/wcn36xx/smd.c
index db7988176526..dd12575f33c3 100644
--- a/drivers/net/wireless/ath/wcn36xx/smd.c
+++ b/drivers/net/wireless/ath/wcn36xx/smd.c
@@ -2886,6 +2886,77 @@  int wcn36xx_smd_gtk_offload(struct wcn36xx *wcn, struct ieee80211_vif *vif,
 	return ret;
 }
 
+static int wcn36xx_smd_gtk_offload_get_info_rsp(struct wcn36xx *wcn,
+						struct ieee80211_vif *vif)
+{
+	struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
+	struct wcn36xx_hal_gtk_offload_get_info_rsp_msg *rsp;
+	__be64 replay_ctr;
+
+	if (wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len))
+		return -EIO;
+
+	rsp = (struct wcn36xx_hal_gtk_offload_get_info_rsp_msg *)wcn->hal_buf;
+
+	if (rsp->bss_index != vif_priv->bss_index) {
+		wcn36xx_err("gtk_offload_info invalid response bss index %d\n",
+			    rsp->bss_index);
+		return -ENOENT;
+	}
+
+	replay_ctr = cpu_to_be64(le64_to_cpu(rsp->key_replay_counter));
+	if (vif_priv->rekey_data.replay_ctr != rsp->key_replay_counter) {
+		vif_priv->rekey_data.replay_ctr = rsp->key_replay_counter;
+		ieee80211_gtk_rekey_notify(vif, vif->bss_conf.bssid,
+					   (void *)&replay_ctr, GFP_KERNEL);
+		 wcn36xx_dbg(WCN36XX_DBG_HAL,
+			     "GTK replay counter increment %llu\n",
+			     rsp->key_replay_counter);
+	}
+
+	wcn36xx_dbg(WCN36XX_DBG_HAL,
+		    "gtk offload info status %d last_rekey_status %d "
+		    "replay_counter %llu total_rekey_count %d gtk_rekey_count %d "
+		    "igtk_rekey_count %d bss_index %d\n",
+		    rsp->status, rsp->last_rekey_status,
+		    rsp->key_replay_counter, rsp->total_rekey_count,
+		    rsp->gtk_rekey_count, rsp->igtk_rekey_count,
+		    rsp->bss_index);
+
+	return 0;
+}
+
+int wcn36xx_smd_gtk_offload_get_info(struct wcn36xx *wcn,
+				     struct ieee80211_vif *vif)
+{
+	struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
+	struct wcn36xx_hal_gtk_offload_get_info_req_msg msg_body;
+	int ret;
+
+	mutex_lock(&wcn->hal_mutex);
+
+	INIT_HAL_MSG(msg_body, WCN36XX_HAL_GTK_OFFLOAD_GETINFO_REQ);
+
+	msg_body.bss_index = vif_priv->bss_index;
+
+	PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
+
+	ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
+	if (ret) {
+		wcn36xx_err("Sending gtk_offload_get_info failed\n");
+		goto out;
+	}
+	ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
+	if (ret) {
+		wcn36xx_err("gtk_offload_get_info failed err=%d\n", ret);
+		goto out;
+	}
+	ret = wcn36xx_smd_gtk_offload_get_info_rsp(wcn, vif);
+out:
+	mutex_unlock(&wcn->hal_mutex);
+	return ret;
+}
+
 int wcn36xx_smd_rsp_process(struct rpmsg_device *rpdev,
 			    void *buf, int len, void *priv, u32 addr)
 {
@@ -2936,6 +3007,7 @@  int wcn36xx_smd_rsp_process(struct rpmsg_device *rpdev,
 	case WCN36XX_HAL_STOP_SCAN_OFFLOAD_RSP:
 	case WCN36XX_HAL_HOST_OFFLOAD_RSP:
 	case WCN36XX_HAL_GTK_OFFLOAD_RSP:
+	case WCN36XX_HAL_GTK_OFFLOAD_GETINFO_RSP:
 		memcpy(wcn->hal_buf, buf, len);
 		wcn->hal_rsp_len = len;
 		complete(&wcn->hal_rsp_compl);
diff --git a/drivers/net/wireless/ath/wcn36xx/smd.h b/drivers/net/wireless/ath/wcn36xx/smd.h
index dd6710672db8..b225c805107c 100644
--- a/drivers/net/wireless/ath/wcn36xx/smd.h
+++ b/drivers/net/wireless/ath/wcn36xx/smd.h
@@ -156,4 +156,7 @@  int wcn36xx_smd_ipv6_ns_offload(struct wcn36xx *wcn, struct ieee80211_vif *vif,
 int wcn36xx_smd_gtk_offload(struct wcn36xx *wcn, struct ieee80211_vif *vif,
 			    bool enable);
 
+int wcn36xx_smd_gtk_offload_get_info(struct wcn36xx *wcn,
+				     struct ieee80211_vif *vif);
+
 #endif	/* _SMD_H_ */