From d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Mon, 11 Dec 2023 02:45:28 +0000
Subject: [PATCH] add boot partition  size

---
 kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/wldev_common.c |  175 +++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 119 insertions(+), 56 deletions(-)

diff --git a/kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/wldev_common.c b/kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/wldev_common.c
index d374136..3c108e2 100644
--- a/kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/wldev_common.c
+++ b/kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/wldev_common.c
@@ -1,15 +1,16 @@
-/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Common function shared by Linux WEXT, cfg80211 and p2p drivers
  *
- * Copyright (C) 1999-2019, Broadcom Corporation
- * 
+ * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation
+ *
+ * Copyright (C) 1999-2017, Broadcom Corporation
+ *
  *      Unless you and Broadcom execute a separate written software license
  * agreement governing use of this software, this software is licensed to you
  * under the terms of the GNU General Public License version 2 (the "GPL"),
  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  * following added to such license:
- * 
+ *
  *      As a special exception, the copyright holders of this software give you
  * permission to link this software with independent modules, and to copy and
  * distribute the resulting executable under terms of your choice, provided that
@@ -17,7 +18,7 @@
  * the license of that module.  An independent module is a module which is not
  * derived from this software.  The special exception does not apply to any
  * modifications of the software.
- * 
+ *
  *      Notwithstanding the above, under no circumstances may you combine this
  * software in any way with any other Broadcom software provided under a license
  * other than the GPL, without Broadcom's express prior written consent.
@@ -25,7 +26,7 @@
  *
  * <<Broadcom-WL-IPTag/Open:>>
  *
- * $Id: wldev_common.c 674374 2017-10-20 07:38:00Z $
+ * $Id: wldev_common.c 698236 2017-05-08 19:41:09Z $
  */
 
 #include <osl.h>
@@ -35,6 +36,10 @@
 
 #include <wldev_common.h>
 #include <bcmutils.h>
+#ifdef WL_CFG80211
+#include <wl_cfg80211.h>
+#include <wl_cfgscan.h>
+#endif /* WL_CFG80211 */
 
 #define htod32(i) (i)
 #define htod16(i) (i)
@@ -45,28 +50,58 @@
 
 #define	WLDEV_ERROR(args)						\
 	do {										\
-		printk(KERN_ERR "WLDEV-ERROR) %s : ", __func__);	\
+		printk(KERN_ERR "WLDEV-ERROR) ");	\
+		printk args;							\
+	} while (0)
+
+#define	WLDEV_INFO(args)						\
+	do {										\
+		printk(KERN_INFO "WLDEV-INFO) ");	\
 		printk args;							\
 	} while (0)
 
 extern int dhd_ioctl_entry_local(struct net_device *net, wl_ioctl_t *ioc, int cmd);
 
-s32 wldev_ioctl(
+static s32 wldev_ioctl(
 	struct net_device *dev, u32 cmd, void *arg, u32 len, u32 set)
 {
 	s32 ret = 0;
-	struct wl_ioctl ioc;
-
+	struct wl_ioctl  ioc;
 
 	memset(&ioc, 0, sizeof(ioc));
 	ioc.cmd = cmd;
 	ioc.buf = arg;
 	ioc.len = len;
 	ioc.set = set;
-
-	ret = dhd_ioctl_entry_local(dev, &ioc, cmd);
+	ret = dhd_ioctl_entry_local(dev, (wl_ioctl_t *)&ioc, cmd);
 
 	return ret;
+}
+
+/*
+SET commands :
+cast buffer to non-const  and call the GET function
+*/
+
+s32 wldev_ioctl_set(
+	struct net_device *dev, u32 cmd, const void *arg, u32 len)
+{
+
+#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
+#endif // endif
+	return wldev_ioctl(dev, cmd, (void *)arg, len, 1);
+#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif // endif
+
+}
+
+s32 wldev_ioctl_get(
+	struct net_device *dev, u32 cmd, void *arg, u32 len)
+{
+	return wldev_ioctl(dev, cmd, (void *)arg, len, 0);
 }
 
 /* Format a iovar buffer, not bsscfg indexed. The bsscfg index will be
@@ -74,7 +109,7 @@
  * wl_iw, wl_cfg80211 and wl_cfgp2p
  */
 static s32 wldev_mkiovar(
-	const s8 *iovar_name, s8 *param, s32 paramlen,
+	const s8 *iovar_name, const s8 *param, s32 paramlen,
 	s8 *iovar_buf, u32 buflen)
 {
 	s32 iolen = 0;
@@ -85,23 +120,37 @@
 
 s32 wldev_iovar_getbuf(
 	struct net_device *dev, s8 *iovar_name,
-	void *param, s32 paramlen, void *buf, s32 buflen, struct mutex* buf_sync)
+	const void *param, s32 paramlen, void *buf, s32 buflen, struct mutex* buf_sync)
 {
 	s32 ret = 0;
 	if (buf_sync) {
 		mutex_lock(buf_sync);
 	}
-	wldev_mkiovar(iovar_name, param, paramlen, buf, buflen);
-	ret = wldev_ioctl(dev, WLC_GET_VAR, buf, buflen, FALSE);
+
+	if (buf && (buflen > 0)) {
+		/* initialize the response buffer */
+		memset(buf, 0, buflen);
+	} else {
+		ret = BCME_BADARG;
+		goto exit;
+	}
+
+	ret = wldev_mkiovar(iovar_name, param, paramlen, buf, buflen);
+
+	if (!ret) {
+		ret = BCME_BUFTOOSHORT;
+		goto exit;
+	}
+	ret = wldev_ioctl_get(dev, WLC_GET_VAR, buf, buflen);
+exit:
 	if (buf_sync)
 		mutex_unlock(buf_sync);
 	return ret;
 }
 
-
 s32 wldev_iovar_setbuf(
 	struct net_device *dev, s8 *iovar_name,
-	void *param, s32 paramlen, void *buf, s32 buflen, struct mutex* buf_sync)
+	const void *param, s32 paramlen, void *buf, s32 buflen, struct mutex* buf_sync)
 {
 	s32 ret = 0;
 	s32 iovar_len;
@@ -110,7 +159,7 @@
 	}
 	iovar_len = wldev_mkiovar(iovar_name, param, paramlen, buf, buflen);
 	if (iovar_len > 0)
-		ret = wldev_ioctl(dev, WLC_SET_VAR, buf, iovar_len, TRUE);
+		ret = wldev_ioctl_set(dev, WLC_SET_VAR, buf, iovar_len);
 	else
 		ret = BCME_BUFTOOSHORT;
 
@@ -129,7 +178,6 @@
 	return wldev_iovar_setbuf(dev, iovar, &val, sizeof(val), iovar_buf,
 		sizeof(iovar_buf), NULL);
 }
-
 
 s32 wldev_iovar_getint(
 	struct net_device *dev, s8 *iovar, s32 *pval)
@@ -153,7 +201,7 @@
  *  wl_iw, wl_cfg80211 and wl_cfgp2p
  */
 s32 wldev_mkiovar_bsscfg(
-	const s8 *iovar_name, s8 *param, s32 paramlen,
+	const s8 *iovar_name, const s8 *param, s32 paramlen,
 	s8 *iovar_buf, s32 buflen, s32 bssidx)
 {
 	const s8 *prefix = "bsscfg:";
@@ -163,7 +211,7 @@
 	u32 iolen;
 
 	/* initialize buffer */
-	if (!iovar_buf || buflen == 0)
+	if (!iovar_buf || buflen <= 0)
 		return BCME_BADARG;
 	memset(iovar_buf, 0, buflen);
 
@@ -176,8 +224,7 @@
 	namelen = (u32) strlen(iovar_name) + 1; /* lengh of iovar  name + null */
 	iolen = prefixlen + namelen + sizeof(u32) + paramlen;
 
-	if (buflen < 0 || iolen > (u32)buflen)
-	{
+	if (iolen > (u32)buflen) {
 		WLDEV_ERROR(("%s: buffer is too short\n", __FUNCTION__));
 		return BCME_BUFTOOSHORT;
 	}
@@ -215,7 +262,7 @@
 	}
 
 	wldev_mkiovar_bsscfg(iovar_name, param, paramlen, buf, buflen, bsscfg_idx);
-	ret = wldev_ioctl(dev, WLC_GET_VAR, buf, buflen, FALSE);
+	ret = wldev_ioctl_get(dev, WLC_GET_VAR, buf, buflen);
 	if (buf_sync) {
 		mutex_unlock(buf_sync);
 	}
@@ -224,8 +271,9 @@
 }
 
 s32 wldev_iovar_setbuf_bsscfg(
-	struct net_device *dev, s8 *iovar_name,
-	void *param, s32 paramlen, void *buf, s32 buflen, s32 bsscfg_idx, struct mutex* buf_sync)
+	struct net_device *dev, const s8 *iovar_name,
+	const void *param, s32 paramlen,
+	void *buf, s32 buflen, s32 bsscfg_idx, struct mutex* buf_sync)
 {
 	s32 ret = 0;
 	s32 iovar_len;
@@ -234,7 +282,7 @@
 	}
 	iovar_len = wldev_mkiovar_bsscfg(iovar_name, param, paramlen, buf, buflen, bsscfg_idx);
 	if (iovar_len > 0)
-		ret = wldev_ioctl(dev, WLC_SET_VAR, buf, iovar_len, TRUE);
+		ret = wldev_ioctl_set(dev, WLC_SET_VAR, buf, iovar_len);
 	else {
 		ret = BCME_BUFTOOSHORT;
 	}
@@ -255,7 +303,6 @@
 	return wldev_iovar_setbuf_bsscfg(dev, iovar, &val, sizeof(val), iovar_buf,
 		sizeof(iovar_buf), bssidx, NULL);
 }
-
 
 s32 wldev_iovar_getint_bsscfg(
 	struct net_device *dev, s8 *iovar, s32 *pval, s32 bssidx)
@@ -281,8 +328,8 @@
 
 	if (!plink_speed)
 		return -ENOMEM;
-	plink_speed = 0;
-	error = wldev_ioctl(dev, WLC_GET_RATE, plink_speed, sizeof(int), 0);
+	*plink_speed = 0;
+	error = wldev_ioctl_get(dev, WLC_GET_RATE, plink_speed, sizeof(int));
 	if (unlikely(error))
 		return error;
 
@@ -299,8 +346,7 @@
 	if (!scb_val)
 		return -ENOMEM;
 
-	memset(scb_val, 0, sizeof(scb_val_t));
-	error = wldev_ioctl(dev, WLC_GET_RSSI, scb_val, sizeof(scb_val_t), 0);
+	error = wldev_ioctl_get(dev, WLC_GET_RSSI, scb_val, sizeof(scb_val_t));
 	if (unlikely(error))
 		return error;
 
@@ -314,9 +360,8 @@
 
 	if (!pssid)
 		return -ENOMEM;
-
 	memset(pssid, 0, sizeof(wlc_ssid_t));
-	error = wldev_ioctl(dev, WLC_GET_SSID, pssid, sizeof(wlc_ssid_t), 0);
+	error = wldev_ioctl_get(dev, WLC_GET_SSID, pssid, sizeof(wlc_ssid_t));
 	if (unlikely(error))
 		return error;
 	pssid->SSID_len = dtoh32(pssid->SSID_len);
@@ -328,7 +373,8 @@
 {
 	int error;
 
-	error = wldev_ioctl(dev, WLC_GET_BAND, pband, sizeof(uint), 0);
+	*pband = 0;
+	error = wldev_ioctl_get(dev, WLC_GET_BAND, pband, sizeof(uint));
 	return error;
 }
 
@@ -338,7 +384,7 @@
 	int error = -1;
 
 	if ((band == WLC_BAND_AUTO) || (band == WLC_BAND_5G) || (band == WLC_BAND_2G)) {
-		error = wldev_ioctl(dev, WLC_SET_BAND, &band, sizeof(band), true);
+		error = wldev_ioctl_set(dev, WLC_SET_BAND, &band, sizeof(band));
 		if (!error)
 			dhd_bus_band_set(dev, band);
 	}
@@ -348,7 +394,7 @@
 {
 	int error = 0;
 
-	error = wldev_ioctl(dev, WLC_GET_RATE, datarate, sizeof(int), false);
+	error = wldev_ioctl_get(dev, WLC_GET_RATE, datarate, sizeof(int));
 	if (error) {
 		return -1;
 	} else {
@@ -362,27 +408,30 @@
 wl_chspec_driver_to_host(chanspec_t chanspec);
 #define WL_EXTRA_BUF_MAX 2048
 int wldev_get_mode(
-	struct net_device *dev, uint8 *cap)
+	struct net_device *dev, uint8 *cap, uint8 caplen)
 {
 	int error = 0;
 	int chanspec = 0;
 	uint16 band = 0;
 	uint16 bandwidth = 0;
 	wl_bss_info_t *bss = NULL;
-	char* buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
+	char* buf = NULL;
+
+	buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
 	if (!buf) {
-		WLDEV_ERROR(("%s:NOMEM\n", __FUNCTION__));
+		WLDEV_ERROR(("%s:ENOMEM\n", __FUNCTION__));
 		return -ENOMEM;
 	}
+
 	*(u32*) buf = htod32(WL_EXTRA_BUF_MAX);
-	error = wldev_ioctl(dev, WLC_GET_BSS_INFO, (void*)buf, WL_EXTRA_BUF_MAX, false);
+	error = wldev_ioctl_get(dev, WLC_GET_BSS_INFO, (void*)buf, WL_EXTRA_BUF_MAX);
 	if (error) {
 		WLDEV_ERROR(("%s:failed:%d\n", __FUNCTION__, error));
 		kfree(buf);
 		buf = NULL;
 		return error;
 	}
-	bss = (struct  wl_bss_info *)(buf + 4);
+	bss = (wl_bss_info_t*)(buf + 4);
 	chanspec = wl_chspec_driver_to_host(bss->chanspec);
 
 	band = chanspec & WL_CHANSPEC_BAND_MASK;
@@ -390,21 +439,21 @@
 
 	if (band == WL_CHANSPEC_BAND_2G) {
 		if (bss->n_cap)
-			strcpy(cap, "n");
+			strncpy(cap, "n", caplen);
 		else
-			strcpy(cap, "bg");
+			strncpy(cap, "bg", caplen);
 	} else if (band == WL_CHANSPEC_BAND_5G) {
 		if (bandwidth == WL_CHANSPEC_BW_80)
-			strcpy(cap, "ac");
+			strncpy(cap, "ac", caplen);
 		else if ((bandwidth == WL_CHANSPEC_BW_40) || (bandwidth == WL_CHANSPEC_BW_20)) {
 			if ((bss->nbss_cap & 0xf00) && (bss->n_cap))
-				strcpy(cap, "n|ac");
+				strncpy(cap, "n|ac", caplen);
 			else if (bss->n_cap)
-				strcpy(cap, "n");
+				strncpy(cap, "n", caplen);
 			else if (bss->vht_cap)
-				strcpy(cap, "ac");
+				strncpy(cap, "ac", caplen);
 			else
-				strcpy(cap, "a");
+				strncpy(cap, "a", caplen);
 		} else {
 			WLDEV_ERROR(("%s:Mode get failed\n", __FUNCTION__));
 			error = BCME_ERROR;
@@ -422,6 +471,11 @@
 	wl_country_t cspec = {{0}, 0, {0}};
 	scb_val_t scbval;
 	char smbuf[WLC_IOCTL_SMLEN];
+#ifdef WL_CFG80211
+	struct wireless_dev *wdev = ndev_to_wdev(dev);
+	struct wiphy *wiphy = wdev->wiphy;
+	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
+#endif /* WL_CFG80211 */
 
 	if (!country_code)
 		return error;
@@ -434,12 +488,19 @@
 	}
 
 	if ((error < 0) ||
-			dhd_force_country_change(dev) ||
-	    (strncmp(country_code, cspec.country_abbrev, WLC_CNTRY_BUF_SZ) != 0)) {
+#ifdef OEM_ANDROID
+		dhd_force_country_change(dev) ||
+#endif /* OEM_ANDROID */
+	    (strncmp(country_code, cspec.ccode, WLC_CNTRY_BUF_SZ) != 0)) {
 
+#ifdef WL_CFG80211
+		if ((user_enforced) && (wl_get_drv_status(cfg, CONNECTED, dev))) {
+#else
 		if (user_enforced) {
+#endif /* WL_CFG80211 */
 			bzero(&scbval, sizeof(scb_val_t));
-			error = wldev_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t), true);
+			error = wldev_ioctl_set(dev, WLC_DISASSOC,
+			                        &scbval, sizeof(scb_val_t));
 			if (error < 0) {
 				WLDEV_ERROR(("%s: set country failed due to Disassoc error %d\n",
 					__FUNCTION__, error));
@@ -447,9 +508,11 @@
 			}
 		}
 
+		wl_cfg80211_scan_abort(cfg);
+
 		cspec.rev = revinfo;
-		memcpy(cspec.country_abbrev, country_code, WLC_CNTRY_BUF_SZ);
-		memcpy(cspec.ccode, country_code, WLC_CNTRY_BUF_SZ);
+		strlcpy(cspec.country_abbrev, country_code, WLC_CNTRY_BUF_SZ);
+		strlcpy(cspec.ccode, country_code, WLC_CNTRY_BUF_SZ);
 		dhd_get_customized_country_code(dev, (char *)&cspec.country_abbrev, &cspec);
 		error = wldev_iovar_setbuf(dev, "country", &cspec, sizeof(cspec),
 			smbuf, sizeof(smbuf), NULL);
@@ -459,7 +522,7 @@
 			return error;
 		}
 		dhd_bus_country_set(dev, &cspec, notify);
-		WLDEV_ERROR(("%s: set country for %s as %s rev %d\n",
+		WLDEV_INFO(("%s: set country for %s as %s rev %d\n",
 			__FUNCTION__, country_code, cspec.ccode, cspec.rev));
 	}
 	return 0;

--
Gitblit v1.6.2