1From 5f022c4d3be32493d500be82f51032ef4fb3cdc0 Mon Sep 17 00:00:00 2001
2From: Giulio Benetti <giulio.benetti@benettiengineering.com>
3Date: Wed, 28 Dec 2022 21:08:45 +0100
4Subject: [PATCH] Fix struct station_parameters Linux 6.1 build failure
5
6Starting from Linux 6.1 struct station_parameters has changed by moving
7some member to its child struct link_station_parameters. Let's extract the
8values of the needed members into local values at the beginning of
9functions and substitute the member access with the local variables.
10
11[Upstream status: https://github.com/embeddedTS/wilc3000-external-module/pull/2]
12Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
13---
14 cfg80211.c | 48 ++++++++++++++++++++++++++++++++----------------
15 hif.c      | 44 ++++++++++++++++++++++++++++++++------------
16 2 files changed, 64 insertions(+), 28 deletions(-)
17
18diff --git a/cfg80211.c b/cfg80211.c
19index 57c777d..bdd480c 100644
20--- a/cfg80211.c
21+++ b/cfg80211.c
22@@ -1866,6 +1866,14 @@ static int add_station(struct wiphy *wiphy, struct net_device *dev,
23 	struct wilc_vif *vif = netdev_priv(dev);
24 	struct wilc_priv *priv = &vif->priv;
25 	u8 *assoc_bss = priv->assoc_stainfo.sta_associated_bss[params->aid];
26+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
27+	struct link_station_parameters *link_sta_params = &params->link_sta_params;
28+	const struct ieee80211_ht_cap *ht_capa = link_sta_params->ht_capa;
29+	u8 supported_rates_len = link_sta_params->supported_rates_len;
30+#else
31+	const struct ieee80211_ht_cap *ht_capa = params->ht_capa;
32+	u8 supported_rates_len = params->supported_rates_len;
33+#endif
34
35 	if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
36 		memcpy(assoc_bss, mac, ETH_ALEN);
37@@ -1879,27 +1887,27 @@ static int add_station(struct wiphy *wiphy, struct net_device *dev,
38 			   params->aid);
39 		PRINT_INFO(vif->ndev, HOSTAPD_DBG,
40 			   "Number of supported rates = %d\n",
41-			   params->supported_rates_len);
42+			   supported_rates_len);
43
44 		PRINT_INFO(vif->ndev, CFG80211_DBG, "IS HT supported = %d\n",
45-			   (!params->ht_capa) ? false : true);
46+			   (!ht_capa) ? false : true);
47
48-		if (params->ht_capa) {
49+		if (ht_capa) {
50 			PRINT_INFO(vif->ndev, CFG80211_DBG,
51 				   "Capability Info = %d\n",
52-				   params->ht_capa->cap_info);
53+				   ht_capa->cap_info);
54 			PRINT_INFO(vif->ndev, CFG80211_DBG,
55 				   "AMPDU Params = %d\n",
56-				   params->ht_capa->ampdu_params_info);
57+				   ht_capa->ampdu_params_info);
58 			PRINT_INFO(vif->ndev, CFG80211_DBG,
59 				   "HT Extended params= %d\n",
60-				   params->ht_capa->extended_ht_cap_info);
61+				   ht_capa->extended_ht_cap_info);
62 			PRINT_INFO(vif->ndev, CFG80211_DBG,
63 				   "Tx Beamforming Cap= %d\n",
64-				   params->ht_capa->tx_BF_cap_info);
65+				   ht_capa->tx_BF_cap_info);
66 			PRINT_INFO(vif->ndev, CFG80211_DBG,
67 				   "Antenna selection info = %d\n",
68-				   params->ht_capa->antenna_selection_info);
69+				   ht_capa->antenna_selection_info);
70 		}
71
72 		PRINT_INFO(vif->ndev, CFG80211_DBG, "Flag Mask = %d\n",
73@@ -1966,6 +1974,14 @@ static int change_station(struct wiphy *wiphy, struct net_device *dev,
74 {
75 	int ret = 0;
76 	struct wilc_vif *vif = netdev_priv(dev);
77+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
78+	struct link_station_parameters *link_sta_params = &params->link_sta_params;
79+	const struct ieee80211_ht_cap *ht_capa = link_sta_params->ht_capa;
80+	u8 supported_rates_len = link_sta_params->supported_rates_len;
81+#else
82+	const struct ieee80211_ht_cap *ht_capa = params->ht_capa;
83+	u8 supported_rates_len = params->supported_rates_len;
84+#endif
85
86 	PRINT_D(vif->ndev, CFG80211_DBG, "Change station parameters\n");
87
88@@ -1976,25 +1992,25 @@ static int change_station(struct wiphy *wiphy, struct net_device *dev,
89 			   params->aid);
90 		PRINT_INFO(vif->ndev, CFG80211_DBG,
91 			   "Number of supported rates = %d\n",
92-			   params->supported_rates_len);
93+			   supported_rates_len);
94 		PRINT_INFO(vif->ndev, CFG80211_DBG, "IS HT supported = %d\n",
95-			   (!params->ht_capa) ? false : true);
96-		if (params->ht_capa) {
97+			   (!ht_capa) ? false : true);
98+		if (ht_capa) {
99 			PRINT_INFO(vif->ndev, CFG80211_DBG,
100 				   "Capability Info = %d\n",
101-				   params->ht_capa->cap_info);
102+				   ht_capa->cap_info);
103 			PRINT_INFO(vif->ndev, CFG80211_DBG,
104 				   "AMPDU Params = %d\n",
105-				   params->ht_capa->ampdu_params_info);
106+				   ht_capa->ampdu_params_info);
107 			PRINT_INFO(vif->ndev, CFG80211_DBG,
108 				   "HT Extended params= %d\n",
109-				   params->ht_capa->extended_ht_cap_info);
110+				   ht_capa->extended_ht_cap_info);
111 			PRINT_INFO(vif->ndev, CFG80211_DBG,
112 				   "Tx Beamforming Cap= %d\n",
113-				   params->ht_capa->tx_BF_cap_info);
114+				   ht_capa->tx_BF_cap_info);
115 			PRINT_INFO(vif->ndev, CFG80211_DBG,
116 				   "Antenna selection info = %d\n",
117-				   params->ht_capa->antenna_selection_info);
118+				   ht_capa->antenna_selection_info);
119 		}
120 		PRINT_INFO(vif->ndev, CFG80211_DBG, "Flag Mask = %d\n",
121 			   params->sta_flags_mask);
122diff --git a/hif.c b/hif.c
123index 3f672a0..1a7365b 100644
124--- a/hif.c
125+++ b/hif.c
126@@ -2249,6 +2249,16 @@ int wilc_add_station(struct wilc_vif *vif, const u8 *mac,
127 	int result;
128 	struct host_if_msg *msg;
129 	struct add_sta_param *sta_params;
130+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
131+	struct link_station_parameters *link_sta_params = &params->link_sta_params;
132+	const struct ieee80211_ht_cap *ht_capa = link_sta_params->ht_capa;
133+	u8 supported_rates_len = link_sta_params->supported_rates_len;
134+	const u8 *supported_rates = link_sta_params->supported_rates;
135+#else
136+	const struct ieee80211_ht_cap *ht_capa = params->ht_capa;
137+	u8 supported_rates_len = params->supported_rates_len;
138+	const u8 *supported_rates = params->supported_rates;
139+#endif
140
141 	PRINT_INFO(vif->ndev, HOSTINF_DBG,
142 		   "Setting adding station message queue params\n");
143@@ -2260,20 +2270,20 @@ int wilc_add_station(struct wilc_vif *vif, const u8 *mac,
144 	sta_params = &msg->body.add_sta_info;
145 	memcpy(sta_params->bssid, mac, ETH_ALEN);
146 	sta_params->aid = params->aid;
147-	if (!params->ht_capa) {
148+	if (!ht_capa) {
149 		sta_params->ht_supported = false;
150 	} else {
151 		sta_params->ht_supported = true;
152-		memcpy(&sta_params->ht_capa, params->ht_capa,
153+		memcpy(&sta_params->ht_capa, ht_capa,
154 		       sizeof(struct ieee80211_ht_cap));
155 	}
156 	sta_params->flags_mask = params->sta_flags_mask;
157 	sta_params->flags_set = params->sta_flags_set;
158
159-	sta_params->supported_rates_len = params->supported_rates_len;
160-	if (params->supported_rates_len > 0) {
161-		sta_params->supported_rates = kmemdup(params->supported_rates,
162-					    params->supported_rates_len,
163+	sta_params->supported_rates_len = supported_rates_len;
164+	if (supported_rates_len > 0) {
165+		sta_params->supported_rates = kmemdup(supported_rates,
166+					    supported_rates_len,
167 					    GFP_KERNEL);
168 		if (!sta_params->supported_rates) {
169 			kfree(msg);
170@@ -2397,6 +2407,16 @@ int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
171 	int result;
172 	struct host_if_msg *msg;
173 	struct add_sta_param *sta_params;
174+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
175+	struct link_station_parameters *link_sta_params = &params->link_sta_params;
176+	const struct ieee80211_ht_cap *ht_capa = link_sta_params->ht_capa;
177+	u8 supported_rates_len = link_sta_params->supported_rates_len;
178+	const u8 *supported_rates = link_sta_params->supported_rates;
179+#else
180+	const struct ieee80211_ht_cap *ht_capa = params->ht_capa;
181+	u8 supported_rates_len = params->supported_rates_len;
182+	const u8 *supported_rates = params->supported_rates;
183+#endif
184
185 	PRINT_INFO(vif->ndev, HOSTINF_DBG,
186 		   "Setting editing station message queue params\n");
187@@ -2408,20 +2428,20 @@ int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
188 	sta_params = &msg->body.edit_sta_info;
189 	memcpy(sta_params->bssid, mac, ETH_ALEN);
190 	sta_params->aid = params->aid;
191-	if (!params->ht_capa) {
192+	if (!ht_capa) {
193 		sta_params->ht_supported = false;
194 	} else {
195 		sta_params->ht_supported = true;
196-		memcpy(&sta_params->ht_capa, params->ht_capa,
197+		memcpy(&sta_params->ht_capa, ht_capa,
198 		       sizeof(struct ieee80211_ht_cap));
199 	}
200 	sta_params->flags_mask = params->sta_flags_mask;
201 	sta_params->flags_set = params->sta_flags_set;
202
203-	sta_params->supported_rates_len = params->supported_rates_len;
204-	if (params->supported_rates_len > 0) {
205-		sta_params->supported_rates = kmemdup(params->supported_rates,
206-					    params->supported_rates_len,
207+	sta_params->supported_rates_len = supported_rates_len;
208+	if (supported_rates_len > 0) {
209+		sta_params->supported_rates = kmemdup(supported_rates,
210+					    supported_rates_len,
211 					    GFP_KERNEL);
212 		if (!sta_params->supported_rates) {
213 			kfree(msg);
214--
2152.34.1
216
217