From 14d10dcf9bfe347dd7f34204e9be1d0e8b5d88d1 Mon Sep 17 00:00:00 2001
From: vanhofen <vanhofen@gmx.de>
Date: Sat, 12 Dec 2020 00:47:24 +0100
Subject: [PATCH] - add missing patches for rtl8812au and rtl8822bu

---
 patches/rtl8812au/0001-rt8812au-gcc5.patch    | 24 +++++++++
 ...rt8812au-Add-support-for-kernels-4.8.patch | 44 +++++++++++++++++
 .../0001-add-linux-4.19-support.patch         | 23 +++++++++
 .../0002-add-linux-4.20-support.patch         | 34 +++++++++++++
 .../0003-add-linux-5.0-support.patch          | 16 ++++++
 .../0004-add-linux-5.1-support.patch          | 49 +++++++++++++++++++
 .../0005-add-linux-5.2-support.patch          | 17 +++++++
 7 files changed, 207 insertions(+)
 create mode 100644 patches/rtl8812au/0001-rt8812au-gcc5.patch
 create mode 100644 patches/rtl8812au/0002-rt8812au-Add-support-for-kernels-4.8.patch
 create mode 100644 patches/rtl8822bu/0001-add-linux-4.19-support.patch
 create mode 100644 patches/rtl8822bu/0002-add-linux-4.20-support.patch
 create mode 100644 patches/rtl8822bu/0003-add-linux-5.0-support.patch
 create mode 100644 patches/rtl8822bu/0004-add-linux-5.1-support.patch
 create mode 100644 patches/rtl8822bu/0005-add-linux-5.2-support.patch

diff --git a/patches/rtl8812au/0001-rt8812au-gcc5.patch b/patches/rtl8812au/0001-rt8812au-gcc5.patch
new file mode 100644
index 00000000..8598e94b
--- /dev/null
+++ b/patches/rtl8812au/0001-rt8812au-gcc5.patch
@@ -0,0 +1,24 @@
+--- a/include/ieee80211.h
++++ b/include/ieee80211.h
+@@ -1314,18 +1314,18 @@ enum ieee80211_state {
+ (((Addr[2]) & 0xff) == 0xff) && (((Addr[3]) & 0xff) == 0xff) && (((Addr[4]) & 0xff) == 0xff) && \
+ (((Addr[5]) & 0xff) == 0xff))
+ #else
+-extern __inline int is_multicast_mac_addr(const u8 *addr)
++static inline int is_multicast_mac_addr(const u8 *addr)
+ {
+         return ((addr[0] != 0xff) && (0x01 & addr[0]));
+ }
+ 
+-extern __inline int is_broadcast_mac_addr(const u8 *addr)
++static inline int is_broadcast_mac_addr(const u8 *addr)
+ {
+ 	return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&   \
+ 		(addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
+ }
+ 
+-extern __inline int is_zero_mac_addr(const u8 *addr)
++static inline int is_zero_mac_addr(const u8 *addr)
+ {
+ 	return ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) &&   \
+ 		(addr[3] == 0x00) && (addr[4] == 0x00) && (addr[5] == 0x00));
diff --git a/patches/rtl8812au/0002-rt8812au-Add-support-for-kernels-4.8.patch b/patches/rtl8812au/0002-rt8812au-Add-support-for-kernels-4.8.patch
new file mode 100644
index 00000000..f626290d
--- /dev/null
+++ b/patches/rtl8812au/0002-rt8812au-Add-support-for-kernels-4.8.patch
@@ -0,0 +1,44 @@
+From 9dcc95a6fc5e41fe941152036fa39a409ba68068 Mon Sep 17 00:00:00 2001
+From: Masashi Honma <masashi.honma@gmail.com>
+Date: Sun, 25 Sep 2016 18:56:40 +0900
+Subject: [PATCH 1/2] Add support for kernels >= 4.8
+
+This patch fix compilation failure caused by modification of
+cfg80211_scan_done() prototype.
+
+Signed-off-by: Masashi Honma <masashi.honma@gmail.com>
+---
+ os_dep/linux/ioctl_cfg80211.c | 9 +++++++++
+ 1 file changed, 9 insertions(+)
+
+diff --git a/os_dep/linux/ioctl_cfg80211.c b/os_dep/linux/ioctl_cfg80211.c
+index e9f74df..b693a57 100644
+--- a/os_dep/linux/ioctl_cfg80211.c
++++ b/os_dep/linux/ioctl_cfg80211.c
+@@ -1978,6 +1978,9 @@ void rtw_cfg80211_indicate_scan_done(_adapter *adapter, bool aborted)
+ {
+ 	struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter);
+ 	_irqL	irqL;
++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
++	struct cfg80211_scan_info info;
++#endif // (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
+ 
+ 	_enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
+ 	if (pwdev_priv->scan_request != NULL) {
+@@ -1992,7 +1995,13 @@ void rtw_cfg80211_indicate_scan_done(_adapter *adapter, bool aborted)
+ 		}
+ 		else
+ 		{
++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
++			memset(&info, 0, sizeof(info));
++			info.aborted = aborted;
++			cfg80211_scan_done(pwdev_priv->scan_request, &info);
++#else // (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
+ 			cfg80211_scan_done(pwdev_priv->scan_request, aborted);
++#endif // (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
+ 		}
+ 
+ 		pwdev_priv->scan_request = NULL;
+-- 
+2.10.0.windows.1
+
diff --git a/patches/rtl8822bu/0001-add-linux-4.19-support.patch b/patches/rtl8822bu/0001-add-linux-4.19-support.patch
new file mode 100644
index 00000000..b4b63b02
--- /dev/null
+++ b/patches/rtl8822bu/0001-add-linux-4.19-support.patch
@@ -0,0 +1,23 @@
+--- a/os_dep/linux/os_intfs.c	2018-10-23 21:11:56.009471377 +0200
++++ b/os_dep/linux/os_intfs.c	2018-10-23 21:12:40.189684185 +0200
+@@ -1190,7 +1190,11 @@
+ 	return dscp >> 5;
+ }
+ 
+-
++#if (LINUX_VERSION_CODE>=KERNEL_VERSION(4,19,0))
++static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb,
++				struct net_device *sb_dev,
++				select_queue_fallback_t fallback
++#else
+ static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
+ 	, void *accel_priv
+@@ -1198,6 +1202,7 @@
+ 	, select_queue_fallback_t fallback
+ 	#endif
+ #endif
++#endif
+ )
+ {
+ 	_adapter	*padapter = rtw_netdev_priv(dev);
diff --git a/patches/rtl8822bu/0002-add-linux-4.20-support.patch b/patches/rtl8822bu/0002-add-linux-4.20-support.patch
new file mode 100644
index 00000000..0ded20c7
--- /dev/null
+++ b/patches/rtl8822bu/0002-add-linux-4.20-support.patch
@@ -0,0 +1,34 @@
+diff --git a/include/wifi.h b/include/wifi.h
+index ecb93a364f57..859efa6658ff 100644
+--- a/include/wifi.h
++++ b/include/wifi.h
+@@ -1011,7 +1011,11 @@ typedef enum _HT_CAP_AMPDU_DENSITY {
+  * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2)
+  */
+ #define IEEE80211_MIN_AMPDU_BUF 0x8
++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,0))
++#define IEEE80211_MAX_AMPDU_BUF 0x100
++#else
+ #define IEEE80211_MAX_AMPDU_BUF 0x40
++#endif
+ 
+ 
+ /* Spatial Multiplexing Power Save Modes */
+diff --git a/os_dep/linux/ioctl_cfg80211.c b/os_dep/linux/ioctl_cfg80211.c
+index 4069d5489873..7c6f1c21fa55 100644
+--- a/os_dep/linux/ioctl_cfg80211.c
++++ b/os_dep/linux/ioctl_cfg80211.c
+@@ -327,6 +327,13 @@ static const struct ieee80211_txrx_stypes
+ };
+ #endif
+ 
++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,0))
++static inline void get_monotonic_boottime(struct timespec *ts)
++{
++	*ts = ktime_to_timespec(ktime_get_boottime());
++}
++#endif
++
+ static u64 rtw_get_systime_us(void)
+ {
+ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
diff --git a/patches/rtl8822bu/0003-add-linux-5.0-support.patch b/patches/rtl8822bu/0003-add-linux-5.0-support.patch
new file mode 100644
index 00000000..4e7636b3
--- /dev/null
+++ b/patches/rtl8822bu/0003-add-linux-5.0-support.patch
@@ -0,0 +1,16 @@
+diff --git a/os_dep/linux/rtw_android.c b/os_dep/linux/rtw_android.c
+index a4affae2f8cb..0996159d1379 100644
+--- a/os_dep/linux/rtw_android.c
++++ b/os_dep/linux/rtw_android.c
+@@ -621,7 +621,11 @@ int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
+ 		goto exit;
+ 	}
+ 
++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
++	if (!access_ok(priv_cmd.buf, priv_cmd.total_len)) {
++#else
+ 	if (!access_ok(VERIFY_READ, priv_cmd.buf, priv_cmd.total_len)) {
++#endif
+ 		RTW_INFO("%s: failed to access memory\n", __FUNCTION__);
+ 		ret = -EFAULT;
+ 		goto exit;
diff --git a/patches/rtl8822bu/0004-add-linux-5.1-support.patch b/patches/rtl8822bu/0004-add-linux-5.1-support.patch
new file mode 100644
index 00000000..d41933f4
--- /dev/null
+++ b/patches/rtl8822bu/0004-add-linux-5.1-support.patch
@@ -0,0 +1,49 @@
+diff --git a/os_dep/osdep_service.c b/os_dep/osdep_service.c
+index dcd26b6a15b4..c44b5f593135 100644
+--- a/os_dep/osdep_service.c
++++ b/os_dep/osdep_service.c
+@@ -2076,7 +2076,13 @@ static int isFileReadable(const char *path, u32 *sz)
+ 		ret = PTR_ERR(fp);
+ 	else {
+ 		oldfs = get_fs();
+-		set_fs(get_ds());
++		set_fs(
++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0))
++			KERNEL_DS
++#else
++			get_ds()
++#endif
++			);
+ 
+ 		if (1 != readFile(fp, &buf, 1))
+ 			ret = PTR_ERR(fp);
+@@ -2114,7 +2120,13 @@ static int retriveFromFile(const char *path, u8 *buf, u32 sz)
+ 			RTW_INFO("%s openFile path:%s fp=%p\n", __FUNCTION__, path , fp);
+ 
+ 			oldfs = get_fs();
+-			set_fs(get_ds());
++			set_fs(
++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0))
++				KERNEL_DS
++#else
++				get_ds()
++#endif
++				);
+ 			ret = readFile(fp, buf, sz);
+ 			set_fs(oldfs);
+ 			closeFile(fp);
+@@ -2149,7 +2161,13 @@ static int storeToFile(const char *path, u8 *buf, u32 sz)
+ 			RTW_INFO("%s openFile path:%s fp=%p\n", __FUNCTION__, path , fp);
+ 
+ 			oldfs = get_fs();
+-			set_fs(get_ds());
++			set_fs(
++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0))
++				KERNEL_DS
++#else
++				get_ds()
++#endif
++				);
+ 			ret = writeFile(fp, buf, sz);
+ 			set_fs(oldfs);
+ 			closeFile(fp);
diff --git a/patches/rtl8822bu/0005-add-linux-5.2-support.patch b/patches/rtl8822bu/0005-add-linux-5.2-support.patch
new file mode 100644
index 00000000..c681c1e1
--- /dev/null
+++ b/patches/rtl8822bu/0005-add-linux-5.2-support.patch
@@ -0,0 +1,17 @@
+diff --git a/os_dep/linux/os_intfs.c b/os_dep/linux/os_intfs.c
+index 24e7cf0c650b..a47aeca1f393 100644
+--- a/os_dep/linux/os_intfs.c
++++ b/os_dep/linux/os_intfs.c
+@@ -1192,8 +1192,10 @@ unsigned int rtw_classify8021d(struct sk_buff *skb)
+ 
+ #if (LINUX_VERSION_CODE>=KERNEL_VERSION(4,19,0))
+ static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb,
+-				struct net_device *sb_dev,
+-				select_queue_fallback_t fallback
++				struct net_device *sb_dev
++#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0))
++				, select_queue_fallback_t fallback
++#endif
+ #else
+ static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)