From 2bbdb27ea6d17e950d03337df77314e0ba8bd27c Mon Sep 17 00:00:00 2001
From: Adesh Kumar Singh <adeshkumar.singh@infineon.com>
Date: Fri, 24 Mar 2023 00:12:24 -0500
Subject: [PATCH 268/296] non-upstream: PFN: Add support for remove_network all
 and add ssid_len field to network_blob struct

Fixes: SWWLAN-146151 and SWWLAN-146162

Added below changes:
1-ssid_len field is added to network_blob structure
2-support to disconnect and remove all network from pfn list

Signed-off-by: Adesh Kumar Singh <adeshkumar.singh@infineon.com>
---
 .../broadcom/brcm80211/brcmfmac/cfg80211.c    |  8 +++--
 .../broadcom/brcm80211/brcmfmac/cfg80211.h    |  1 +
 .../broadcom/brcm80211/brcmfmac/pno.c         | 34 +++++++++++--------
 .../broadcom/brcm80211/brcmfmac/vendor_ifx.c  | 26 ++++++++------
 4 files changed, 41 insertions(+), 28 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
index e6c222610232..411fcc5d695a 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
@@ -7905,11 +7905,13 @@ brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
 
 	brcmf_dbg(TRACE, "Enter cfg->pfn_enable %d\n", cfg->pfn_enable);
 	if (cfg->pfn_enable) {
-		if (!completed)
+		if (!completed) {
 			memset(&cfg->curr_network, '\0', sizeof(struct network_blob));
-
-		if (strlen(cfg->curr_network.ssid))
 			pfn_send_network_blob_fw(cfg->wiphy, &ifp->vif->wdev);
+		}
+		if (cfg->curr_network.ssid_len) {
+			pfn_send_network_blob_fw(cfg->wiphy, &ifp->vif->wdev);
+		}
 	}
 
 	if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h
index e9b2d981d508..7e47f5dbf24a 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h
@@ -354,6 +354,7 @@ struct brcmf_cfg80211_wowl {
 
 struct network_blob {
 	char ssid[32];
+	u8 ssid_len;
 	int key_mgmt;
 	char psk[64];
 	char sae_password[64];
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pno.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pno.c
index a8bb440377d7..e5cb835855a7 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pno.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pno.c
@@ -612,6 +612,15 @@ int pfn_send_network_blob_fw(struct wiphy *wiphy,
 	ifp = vif->ifp;
 
 	brcmf_dbg(TRACE, "Enter\n");
+
+	if (!cfg->curr_network.ssid_len) {
+		ret = brcmf_fil_cmd_data_set(vif->ifp,
+				BRCMF_C_DISASSOC, NULL, 0);
+		if (ret) {
+			brcmf_err("BRCMF_C_DISASSOC error:%d\n", ret);
+			return -1;
+		}
+	}
 	brcmf_pno_clean(ifp);
 
 	ret = brcmf_fil_iovar_int_set(ifp, "sup_wpa", 1);
@@ -620,7 +629,7 @@ int pfn_send_network_blob_fw(struct wiphy *wiphy,
 		return -1;
 	}
 
-	if (!cfg->pfn_data.count && !strlen(cfg->curr_network.ssid))
+	if (!cfg->pfn_data.count && !cfg->curr_network.ssid_len)
 		return 0;
 
 	pfn_param.version = PFN_VERSION;
@@ -651,25 +660,25 @@ int pfn_send_network_blob_fw(struct wiphy *wiphy,
 
 	brcm_pfn_length = (cfg->pfn_data.count) * sizeof(struct brcm_pfn);
 
-	if (strlen(cfg->curr_network.ssid))
+	if (cfg->curr_network.ssid_len)
 		brcm_pfn_length += sizeof(struct brcm_pfn);
 
 	pfn_list_buffer = (struct brcm_pfn *)kzalloc(brcm_pfn_length, GFP_KERNEL);
 	pssidnet = pfn_list_buffer;
 	network_blob_data = cfg->pfn_data.network_blob_data;
 
-	if (strlen(cfg->curr_network.ssid)) {
+	if (cfg->curr_network.ssid_len) {
 		pssidnet->auth = WLAN_AUTH_OPEN;
 		pssidnet->wpa_auth = WPA_AUTH_DISABLED;
 		pssidnet->wsec = WPA_CIPHER_NONE;
 		pssidnet->infra = WPAS_MODE_IBSS;
 		pssidnet->flags = 0;
 		memcpy((char *)pssidnet->ssid.SSID, cfg->curr_network.ssid,
-				strlen(cfg->curr_network.ssid));
-		pssidnet->ssid.SSID_len = cpu_to_le32(strlen(cfg->curr_network.ssid));
+				cfg->curr_network.ssid_len);
+		pssidnet->ssid.SSID_len = cpu_to_le32(cfg->curr_network.ssid_len);
 		pssidnet->flags = cpu_to_le32(pssidnet->flags);
 
-		if (cfg->curr_network.proto == KEY_MGMT_WPA &&
+		if (cfg->curr_network.proto == WPA_PROTO_WPA &&
 				cfg->curr_network.key_mgmt == KEY_MGMT_WPA) {
 			pssidnet->wpa_auth = WPA_AUTH_PSK;
 
@@ -708,30 +717,26 @@ int pfn_send_network_blob_fw(struct wiphy *wiphy,
 		pssidnet->infra = WPAS_MODE_IBSS;
 		pssidnet->flags = 0;
 		memcpy((char *)pssidnet->ssid.SSID, network_blob_data->ssid,
-				strlen(network_blob_data->ssid));
-		pssidnet->ssid.SSID_len = cpu_to_le32(strlen(network_blob_data->ssid));
+				network_blob_data->ssid_len);
+		pssidnet->ssid.SSID_len = cpu_to_le32(network_blob_data->ssid_len);
 		pssidnet->flags = cpu_to_le32(pssidnet->flags);
 
-		if (network_blob_data->proto == KEY_MGMT_WPA &&
+		if (network_blob_data->proto == WPA_PROTO_WPA &&
 				network_blob_data->key_mgmt == KEY_MGMT_WPA) {
 			pssidnet->wpa_auth = WPA_AUTH_PSK;
-			pssidnet->wsec = AES_ENABLED;
 
 		} else if (network_blob_data->proto == WPA_PROTO_RSN &&
 				network_blob_data->key_mgmt == KEY_MGMT_WPA2) {
 			pssidnet->wpa_auth = WPA2_AUTH_PSK;
-			pssidnet->wsec = AES_ENABLED;
 
 		} else if (network_blob_data->proto == WPA_PROTO_RSN &&
 				network_blob_data->key_mgmt == KEY_MGMT_SAE) {
 			pssidnet->wpa_auth = WPA3_AUTH_SAE_PSK;
-			pssidnet->wsec = AES_ENABLED;
 			pssidnet->auth = WLAN_AUTH_SAE;
 
 		} else if (network_blob_data->proto == WPA_PROTO_RSN &&
 				network_blob_data->key_mgmt == KEY_MGMT_OWE) {
 			pssidnet->wpa_auth = WPA3_AUTH_OWE;
-			pssidnet->wsec = AES_ENABLED;
 		}
 
 		if (network_blob_data->pairwise_cipher == BIT(WPA_CIPHER_AES_CCM))
@@ -777,9 +782,10 @@ int pfn_save_curr_network(struct wiphy *wiphy, struct net_device *ndev,
 	curr_network = &cfg->curr_network;
 	brcmf_pno_clean(ifp);
 
-	if (sme->ssid)
+	if (sme->ssid_len)
 		memcpy(curr_network->ssid, sme->ssid, sme->ssid_len);
 
+	curr_network->ssid_len = sme->ssid_len;
 	ret = brcmf_fil_bsscfg_int_get(netdev_priv(ndev), "wpa_auth", &val);
 	if (ret) {
 		bphy_err(drvr, "could not get wpa_auth (%d)\n", ret);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor_ifx.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor_ifx.c
index afb6cf71977f..f025d98f5f3b 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor_ifx.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor_ifx.c
@@ -1048,9 +1048,6 @@ int ifx_cfg80211_vndr_cmds_config_pfn(struct wiphy *wiphy,
 	cfg->pfn_enable = 1;
 	cfg->pfn_data.count = *((u8 *)data);
 
-	if (!cfg->pfn_data.count)
-		return 0;
-
 	buflen = cfg->pfn_data.count * sizeof(struct network_blob);
 	cfg->pfn_data.network_blob_data = (struct network_blob *)kmalloc(buflen, GFP_KERNEL);
 	memset(cfg->pfn_data.network_blob_data, '\0', buflen);
@@ -1070,7 +1067,7 @@ int ifx_cfg80211_vndr_cmds_get_pfn_status(struct wiphy *wiphy,
 	int err = 0, i = 0;
 	struct brcmf_cfg80211_vif *vif;
 	struct brcmf_if *ifp;
-	struct network_blob *curr_network = NULL, *network_blob_data = NULL;
+	struct network_blob *network_blob_data = NULL;
 	struct brcmu_chan ch;
 	struct pfn_conn_info curr_bssid;
 
@@ -1107,14 +1104,21 @@ int ifx_cfg80211_vndr_cmds_get_pfn_status(struct wiphy *wiphy,
 		curr_bssid.SNR = bi->SNR;
 
 		network_blob_data = cfg->pfn_data.network_blob_data;
-		for (; i < cfg->pfn_data.count && network_blob_data; i++) {
-			if (!strncmp(network_blob_data->ssid, bi->SSID, bi->SSID_len)) {
-				curr_network = network_blob_data;
-				curr_bssid.proto = network_blob_data->proto;
-				curr_bssid.key_mgmt = network_blob_data->key_mgmt;
-				break;
+		if (cfg->curr_network.ssid_len) {
+			if (!strncmp(cfg->curr_network.ssid, bi->SSID, bi->SSID_len)) {
+				curr_bssid.proto = cfg->curr_network.proto;
+				curr_bssid.key_mgmt = cfg->curr_network.key_mgmt;
+			}
+
+		} else {
+			for (; i < cfg->pfn_data.count && network_blob_data; i++) {
+				if (!strncmp(network_blob_data->ssid, bi->SSID, bi->SSID_len)) {
+					curr_bssid.proto = network_blob_data->proto;
+					curr_bssid.key_mgmt = network_blob_data->key_mgmt;
+					break;
+				}
+				network_blob_data++;
 			}
-			network_blob_data++;
 		}
 	}
 	if (curr_bssid.SSID_len)
-- 
2.25.1

