xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8188fu/os_dep/linux/rtw_cfgvendor.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2017 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 
16 #include <drv_types.h>
17 
18 #ifdef CONFIG_IOCTL_CFG80211
19 
20 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(RTW_VENDOR_EXT_SUPPORT)
21 
22 /*
23 #include <linux/kernel.h>
24 #include <linux/if_arp.h>
25 #include <asm/uaccess.h>
26 
27 #include <linux/kernel.h>
28 #include <linux/kthread.h>
29 #include <linux/netdevice.h>
30 #include <linux/sched.h>
31 #include <linux/etherdevice.h>
32 #include <linux/wireless.h>
33 #include <linux/ieee80211.h>
34 #include <linux/wait.h>
35 #include <net/cfg80211.h>
36 */
37 
38 #include <net/rtnetlink.h>
39 
40 #ifndef MIN
41 #define MIN(x,y) (((x) < (y)) ? (x) : (y))
42 #endif
43 
44 #ifdef DBG_MEM_ALLOC
45 extern bool match_mstat_sniff_rules(const enum mstat_f flags, const size_t size);
dbg_rtw_cfg80211_vendor_event_alloc(struct wiphy * wiphy,struct wireless_dev * wdev,int len,int event_id,gfp_t gfp,const enum mstat_f flags,const char * func,const int line)46 struct sk_buff *dbg_rtw_cfg80211_vendor_event_alloc(struct wiphy *wiphy, struct wireless_dev *wdev, int len, int event_id, gfp_t gfp
47 		, const enum mstat_f flags, const char *func, const int line)
48 {
49 	struct sk_buff *skb;
50 	unsigned int truesize = 0;
51 
52 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0))
53 	skb = cfg80211_vendor_event_alloc(wiphy, len, event_id, gfp);
54 #else
55 	skb = cfg80211_vendor_event_alloc(wiphy, wdev, len, event_id, gfp);
56 #endif
57 
58 	if (skb)
59 		truesize = skb->truesize;
60 
61 	if (!skb || truesize < len || match_mstat_sniff_rules(flags, truesize))
62 		RTW_INFO("DBG_MEM_ALLOC %s:%d %s(%d), skb:%p, truesize=%u\n", func, line, __FUNCTION__, len, skb, truesize);
63 
64 	rtw_mstat_update(
65 		flags
66 		, skb ? MSTAT_ALLOC_SUCCESS : MSTAT_ALLOC_FAIL
67 		, truesize
68 	);
69 
70 	return skb;
71 }
72 
dbg_rtw_cfg80211_vendor_event(struct sk_buff * skb,gfp_t gfp,const enum mstat_f flags,const char * func,const int line)73 void dbg_rtw_cfg80211_vendor_event(struct sk_buff *skb, gfp_t gfp
74 		   , const enum mstat_f flags, const char *func, const int line)
75 {
76 	unsigned int truesize = skb->truesize;
77 
78 	if (match_mstat_sniff_rules(flags, truesize))
79 		RTW_INFO("DBG_MEM_ALLOC %s:%d %s, truesize=%u\n", func, line, __FUNCTION__, truesize);
80 
81 	cfg80211_vendor_event(skb, gfp);
82 
83 	rtw_mstat_update(
84 		flags
85 		, MSTAT_FREE
86 		, truesize
87 	);
88 }
89 
dbg_rtw_cfg80211_vendor_cmd_alloc_reply_skb(struct wiphy * wiphy,int len,const enum mstat_f flags,const char * func,const int line)90 struct sk_buff *dbg_rtw_cfg80211_vendor_cmd_alloc_reply_skb(struct wiphy *wiphy, int len
91 		, const enum mstat_f flags, const char *func, const int line)
92 {
93 	struct sk_buff *skb;
94 	unsigned int truesize = 0;
95 
96 	skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, len);
97 
98 	if (skb)
99 		truesize = skb->truesize;
100 
101 	if (!skb || truesize < len || match_mstat_sniff_rules(flags, truesize))
102 		RTW_INFO("DBG_MEM_ALLOC %s:%d %s(%d), skb:%p, truesize=%u\n", func, line, __FUNCTION__, len, skb, truesize);
103 
104 	rtw_mstat_update(
105 		flags
106 		, skb ? MSTAT_ALLOC_SUCCESS : MSTAT_ALLOC_FAIL
107 		, truesize
108 	);
109 
110 	return skb;
111 }
112 
dbg_rtw_cfg80211_vendor_cmd_reply(struct sk_buff * skb,const enum mstat_f flags,const char * func,const int line)113 int dbg_rtw_cfg80211_vendor_cmd_reply(struct sk_buff *skb
114 	      , const enum mstat_f flags, const char *func, const int line)
115 {
116 	unsigned int truesize = skb->truesize;
117 	int ret;
118 
119 	if (match_mstat_sniff_rules(flags, truesize))
120 		RTW_INFO("DBG_MEM_ALLOC %s:%d %s, truesize=%u\n", func, line, __FUNCTION__, truesize);
121 
122 	ret = cfg80211_vendor_cmd_reply(skb);
123 
124 	rtw_mstat_update(
125 		flags
126 		, MSTAT_FREE
127 		, truesize
128 	);
129 
130 	return ret;
131 }
132 
133 #define rtw_cfg80211_vendor_event_alloc(wiphy, wdev, len, event_id, gfp) \
134 	dbg_rtw_cfg80211_vendor_event_alloc(wiphy, wdev, len, event_id, gfp, MSTAT_FUNC_CFG_VENDOR | MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
135 
136 #define rtw_cfg80211_vendor_event(skb, gfp) \
137 	dbg_rtw_cfg80211_vendor_event(skb, gfp, MSTAT_FUNC_CFG_VENDOR | MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
138 
139 #define rtw_cfg80211_vendor_cmd_alloc_reply_skb(wiphy, len) \
140 	dbg_rtw_cfg80211_vendor_cmd_alloc_reply_skb(wiphy, len, MSTAT_FUNC_CFG_VENDOR | MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
141 
142 #define rtw_cfg80211_vendor_cmd_reply(skb) \
143 	dbg_rtw_cfg80211_vendor_cmd_reply(skb, MSTAT_FUNC_CFG_VENDOR | MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
144 #else
145 
rtw_cfg80211_vendor_event_alloc(struct wiphy * wiphy,struct wireless_dev * wdev,int len,int event_id,gfp_t gfp)146 struct sk_buff *rtw_cfg80211_vendor_event_alloc(
147 	struct wiphy *wiphy, struct wireless_dev *wdev, int len, int event_id, gfp_t gfp)
148 {
149 	struct sk_buff *skb;
150 
151 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0))
152 	skb = cfg80211_vendor_event_alloc(wiphy, len, event_id, gfp);
153 #else
154 	skb = cfg80211_vendor_event_alloc(wiphy, wdev, len, event_id, gfp);
155 #endif
156 	return skb;
157 }
158 
159 #define rtw_cfg80211_vendor_event(skb, gfp) \
160 	cfg80211_vendor_event(skb, gfp)
161 
162 #define rtw_cfg80211_vendor_cmd_alloc_reply_skb(wiphy, len) \
163 	cfg80211_vendor_cmd_alloc_reply_skb(wiphy, len)
164 
165 #define rtw_cfg80211_vendor_cmd_reply(skb) \
166 	cfg80211_vendor_cmd_reply(skb)
167 #endif /* DBG_MEM_ALLOC */
168 
169 /*
170  * This API is to be used for asynchronous vendor events. This
171  * shouldn't be used in response to a vendor command from its
172  * do_it handler context (instead rtw_cfgvendor_send_cmd_reply should
173  * be used).
174  */
rtw_cfgvendor_send_async_event(struct wiphy * wiphy,struct net_device * dev,int event_id,const void * data,int len)175 int rtw_cfgvendor_send_async_event(struct wiphy *wiphy,
176 	   struct net_device *dev, int event_id, const void  *data, int len)
177 {
178 	gfp_t kflags;
179 	struct sk_buff *skb;
180 
181 	kflags = in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
182 
183 	/* Alloc the SKB for vendor_event */
184 	skb = rtw_cfg80211_vendor_event_alloc(wiphy, ndev_to_wdev(dev), len, event_id, kflags);
185 	if (!skb) {
186 		RTW_ERR(FUNC_NDEV_FMT" skb alloc failed", FUNC_NDEV_ARG(dev));
187 		return -ENOMEM;
188 	}
189 
190 	/* Push the data to the skb */
191 	nla_put_nohdr(skb, len, data);
192 
193 	rtw_cfg80211_vendor_event(skb, kflags);
194 
195 	return 0;
196 }
197 
rtw_cfgvendor_send_cmd_reply(struct wiphy * wiphy,struct net_device * dev,const void * data,int len)198 static int rtw_cfgvendor_send_cmd_reply(struct wiphy *wiphy,
199 			struct net_device *dev, const void  *data, int len)
200 {
201 	struct sk_buff *skb;
202 
203 	/* Alloc the SKB for vendor_event */
204 	skb = rtw_cfg80211_vendor_cmd_alloc_reply_skb(wiphy, len);
205 	if (unlikely(!skb)) {
206 		RTW_ERR(FUNC_NDEV_FMT" skb alloc failed", FUNC_NDEV_ARG(dev));
207 		return -ENOMEM;
208 	}
209 
210 	/* Push the data to the skb */
211 	nla_put_nohdr(skb, len, data);
212 
213 	return rtw_cfg80211_vendor_cmd_reply(skb);
214 }
215 
216 /* Feature enums */
217 #define WIFI_FEATURE_INFRA              0x0001      // Basic infrastructure mode
218 #define WIFI_FEATURE_INFRA_5G           0x0002      // Support for 5 GHz Band
219 #define WIFI_FEATURE_HOTSPOT            0x0004      // Support for GAS/ANQP
220 #define WIFI_FEATURE_P2P                0x0008      // Wifi-Direct
221 #define WIFI_FEATURE_SOFT_AP            0x0010      // Soft AP
222 #define WIFI_FEATURE_GSCAN              0x0020      // Google-Scan APIs
223 #define WIFI_FEATURE_NAN                0x0040      // Neighbor Awareness Networking
224 #define WIFI_FEATURE_D2D_RTT            0x0080      // Device-to-device RTT
225 #define WIFI_FEATURE_D2AP_RTT           0x0100      // Device-to-AP RTT
226 #define WIFI_FEATURE_BATCH_SCAN         0x0200      // Batched Scan (legacy)
227 #define WIFI_FEATURE_PNO                0x0400      // Preferred network offload
228 #define WIFI_FEATURE_ADDITIONAL_STA     0x0800      // Support for two STAs
229 #define WIFI_FEATURE_TDLS               0x1000      // Tunnel directed link setup
230 #define WIFI_FEATURE_TDLS_OFFCHANNEL    0x2000      // Support for TDLS off channel
231 #define WIFI_FEATURE_EPR                0x4000      // Enhanced power reporting
232 #define WIFI_FEATURE_AP_STA             0x8000      // Support for AP STA Concurrency
233 #define WIFI_FEATURE_LINK_LAYER_STATS   0x10000     // Link layer stats collection
234 #define WIFI_FEATURE_LOGGER             0x20000     // WiFi Logger
235 #define WIFI_FEATURE_HAL_EPNO           0x40000     // WiFi PNO enhanced
236 #define WIFI_FEATURE_RSSI_MONITOR       0x80000     // RSSI Monitor
237 #define WIFI_FEATURE_MKEEP_ALIVE        0x100000    // WiFi mkeep_alive
238 #define WIFI_FEATURE_CONFIG_NDO         0x200000    // ND offload configure
239 #define WIFI_FEATURE_TX_TRANSMIT_POWER  0x400000    // Capture Tx transmit power levels
240 #define WIFI_FEATURE_CONTROL_ROAMING    0x800000    // Enable/Disable firmware roaming
241 #define WIFI_FEATURE_IE_WHITELIST       0x1000000   // Support Probe IE white listing
242 #define WIFI_FEATURE_SCAN_RAND          0x2000000   // Support MAC & Probe Sequence Number randomization
243 #define WIFI_FEATURE_SET_TX_POWER_LIMIT 0x4000000   // Support Tx Power Limit setting
244 #define WIFI_FEATURE_USE_BODY_HEAD_SAR  0x8000000   // Support Using Body/Head Proximity for SAR
245 #define WIFI_FEATURE_SET_LATENCY_MODE   0x40000000  // Support Latency mode setting
246 #define WIFI_FEATURE_P2P_RAND_MAC       0x80000000  // Support Support P2P MAC randomization
247 // Add more features here
248 
249 #define MAX_FEATURE_SET_CONCURRRENT_GROUPS  3
250 
251 #include <hal_data.h>
rtw_dev_get_feature_set(struct net_device * dev)252 int rtw_dev_get_feature_set(struct net_device *dev)
253 {
254 	_adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
255 	HAL_DATA_TYPE *HalData = GET_HAL_DATA(adapter);
256 	int feature_set = 0;
257 
258 	feature_set |= WIFI_FEATURE_INFRA;
259 
260 #if CONFIG_IEEE80211_BAND_5GHZ
261 	if (is_supported_5g(adapter_to_regsty(adapter)->wireless_mode))
262 		feature_set |= WIFI_FEATURE_INFRA_5G;
263 #endif
264 
265 	feature_set |= WIFI_FEATURE_P2P;
266 	feature_set |= WIFI_FEATURE_SOFT_AP;
267 
268 	feature_set |= WIFI_FEATURE_ADDITIONAL_STA;
269 #ifdef CONFIG_RTW_CFGVENDOR_LLSTATS
270 	feature_set |= WIFI_FEATURE_LINK_LAYER_STATS;
271 #endif /* CONFIG_RTW_CFGVENDOR_LLSTATS */
272 
273 #ifdef CONFIG_RTW_CFGVENDOR_RSSIMONITOR
274         feature_set |= WIFI_FEATURE_RSSI_MONITOR;
275 #endif
276 
277 #ifdef CONFIG_RTW_CFGVENDOR_WIFI_LOGGER
278 	feature_set |= WIFI_FEATURE_LOGGER;
279 #endif
280 
281 #ifdef CONFIG_RTW_WIFI_HAL
282 	feature_set |= WIFI_FEATURE_CONFIG_NDO;
283 #ifdef CONFIG_RTW_CFGVENDOR_RANDOM_MAC_OUI
284 	feature_set |= WIFI_FEATURE_SCAN_RAND;
285 #endif
286 #endif
287 
288 	return feature_set;
289 }
290 
rtw_dev_get_feature_set_matrix(struct net_device * dev,int * num)291 int *rtw_dev_get_feature_set_matrix(struct net_device *dev, int *num)
292 {
293 	int feature_set_full, mem_needed;
294 	int *ret;
295 
296 	*num = 0;
297 	mem_needed = sizeof(int) * MAX_FEATURE_SET_CONCURRRENT_GROUPS;
298 	ret = (int *)rtw_malloc(mem_needed);
299 
300 	if (!ret) {
301 		RTW_ERR(FUNC_NDEV_FMT" failed to allocate %d bytes\n"
302 			, FUNC_NDEV_ARG(dev), mem_needed);
303 		return ret;
304 	}
305 
306 	feature_set_full = rtw_dev_get_feature_set(dev);
307 
308 	ret[0] = (feature_set_full & WIFI_FEATURE_INFRA) |
309 		 (feature_set_full & WIFI_FEATURE_INFRA_5G) |
310 		 (feature_set_full & WIFI_FEATURE_NAN) |
311 		 (feature_set_full & WIFI_FEATURE_D2D_RTT) |
312 		 (feature_set_full & WIFI_FEATURE_D2AP_RTT) |
313 		 (feature_set_full & WIFI_FEATURE_PNO) |
314 		 (feature_set_full & WIFI_FEATURE_BATCH_SCAN) |
315 		 (feature_set_full & WIFI_FEATURE_GSCAN) |
316 		 (feature_set_full & WIFI_FEATURE_HOTSPOT) |
317 		 (feature_set_full & WIFI_FEATURE_ADDITIONAL_STA) |
318 		 (feature_set_full & WIFI_FEATURE_EPR);
319 
320 	ret[1] = (feature_set_full & WIFI_FEATURE_INFRA) |
321 		 (feature_set_full & WIFI_FEATURE_INFRA_5G) |
322 		 /* Not yet verified NAN with P2P */
323 		 /* (feature_set_full & WIFI_FEATURE_NAN) | */
324 		 (feature_set_full & WIFI_FEATURE_P2P) |
325 		 (feature_set_full & WIFI_FEATURE_D2AP_RTT) |
326 		 (feature_set_full & WIFI_FEATURE_D2D_RTT) |
327 		 (feature_set_full & WIFI_FEATURE_EPR);
328 
329 	ret[2] = (feature_set_full & WIFI_FEATURE_INFRA) |
330 		 (feature_set_full & WIFI_FEATURE_INFRA_5G) |
331 		 (feature_set_full & WIFI_FEATURE_NAN) |
332 		 (feature_set_full & WIFI_FEATURE_D2D_RTT) |
333 		 (feature_set_full & WIFI_FEATURE_D2AP_RTT) |
334 		 (feature_set_full & WIFI_FEATURE_TDLS) |
335 		 (feature_set_full & WIFI_FEATURE_TDLS_OFFCHANNEL) |
336 		 (feature_set_full & WIFI_FEATURE_EPR);
337 	*num = MAX_FEATURE_SET_CONCURRRENT_GROUPS;
338 
339 	return ret;
340 }
341 
rtw_cfgvendor_get_feature_set(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)342 static int rtw_cfgvendor_get_feature_set(struct wiphy *wiphy,
343 		struct wireless_dev *wdev, const void  *data, int len)
344 {
345 	int err = 0;
346 	int reply;
347 
348 	reply = rtw_dev_get_feature_set(wdev_to_ndev(wdev));
349 
350 	err =  rtw_cfgvendor_send_cmd_reply(wiphy, wdev_to_ndev(wdev), &reply, sizeof(int));
351 
352 	if (unlikely(err))
353 		RTW_ERR(FUNC_NDEV_FMT" Vendor Command reply failed ret:%d\n"
354 			, FUNC_NDEV_ARG(wdev_to_ndev(wdev)), err);
355 
356 	return err;
357 }
358 
rtw_cfgvendor_get_feature_set_matrix(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)359 static int rtw_cfgvendor_get_feature_set_matrix(struct wiphy *wiphy,
360 		struct wireless_dev *wdev, const void  *data, int len)
361 {
362 	int err = 0;
363 	struct sk_buff *skb;
364 	int *reply;
365 	int num, mem_needed, i;
366 
367 	reply = rtw_dev_get_feature_set_matrix(wdev_to_ndev(wdev), &num);
368 
369 	if (!reply) {
370 		RTW_ERR(FUNC_NDEV_FMT" Could not get feature list matrix\n"
371 			, FUNC_NDEV_ARG(wdev_to_ndev(wdev)));
372 		err = -EINVAL;
373 		return err;
374 	}
375 
376 	mem_needed = VENDOR_REPLY_OVERHEAD + (ATTRIBUTE_U32_LEN * num) +
377 		     ATTRIBUTE_U32_LEN;
378 
379 	/* Alloc the SKB for vendor_event */
380 	skb = rtw_cfg80211_vendor_cmd_alloc_reply_skb(wiphy, mem_needed);
381 	if (unlikely(!skb)) {
382 		RTW_ERR(FUNC_NDEV_FMT" skb alloc failed", FUNC_NDEV_ARG(wdev_to_ndev(wdev)));
383 		err = -ENOMEM;
384 		goto exit;
385 	}
386 
387 	nla_put_u32(skb, ANDR_WIFI_ATTRIBUTE_NUM_FEATURE_SET, num);
388 	for (i = 0; i < num; i++)
389 		nla_put_u32(skb, ANDR_WIFI_ATTRIBUTE_FEATURE_SET, reply[i]);
390 
391 	err =  rtw_cfg80211_vendor_cmd_reply(skb);
392 
393 	if (unlikely(err))
394 		RTW_ERR(FUNC_NDEV_FMT" Vendor Command reply failed ret:%d\n"
395 			, FUNC_NDEV_ARG(wdev_to_ndev(wdev)), err);
396 exit:
397 	rtw_mfree((u8 *)reply, sizeof(int) * num);
398 	return err;
399 }
400 
401 #if defined(GSCAN_SUPPORT) && 0
rtw_cfgvendor_send_hotlist_event(struct wiphy * wiphy,struct net_device * dev,void * data,int len,rtw_vendor_event_t event)402 int rtw_cfgvendor_send_hotlist_event(struct wiphy *wiphy,
403 	struct net_device *dev, void  *data, int len, rtw_vendor_event_t event)
404 {
405 	u16 kflags;
406 	const void *ptr;
407 	struct sk_buff *skb;
408 	int malloc_len, total, iter_cnt_to_send, cnt;
409 	gscan_results_cache_t *cache = (gscan_results_cache_t *)data;
410 
411 	total = len / sizeof(wifi_gscan_result_t);
412 	while (total > 0) {
413 		malloc_len = (total * sizeof(wifi_gscan_result_t)) + VENDOR_DATA_OVERHEAD;
414 		if (malloc_len > NLMSG_DEFAULT_SIZE)
415 			malloc_len = NLMSG_DEFAULT_SIZE;
416 		iter_cnt_to_send =
417 			(malloc_len - VENDOR_DATA_OVERHEAD) / sizeof(wifi_gscan_result_t);
418 		total = total - iter_cnt_to_send;
419 
420 		kflags = in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
421 
422 		/* Alloc the SKB for vendor_event */
423 		skb = rtw_cfg80211_vendor_event_alloc(wiphy, ndev_to_wdev(dev), malloc_len, event, kflags);
424 		if (!skb) {
425 			WL_ERR(("skb alloc failed"));
426 			return -ENOMEM;
427 		}
428 
429 		while (cache && iter_cnt_to_send) {
430 			ptr = (const void *) &cache->results[cache->tot_consumed];
431 
432 			if (iter_cnt_to_send < (cache->tot_count - cache->tot_consumed))
433 				cnt = iter_cnt_to_send;
434 			else
435 				cnt = (cache->tot_count - cache->tot_consumed);
436 
437 			iter_cnt_to_send -= cnt;
438 			cache->tot_consumed += cnt;
439 			/* Push the data to the skb */
440 			nla_append(skb, cnt * sizeof(wifi_gscan_result_t), ptr);
441 			if (cache->tot_consumed == cache->tot_count)
442 				cache = cache->next;
443 
444 		}
445 
446 		rtw_cfg80211_vendor_event(skb, kflags);
447 	}
448 
449 	return 0;
450 }
451 
452 
rtw_cfgvendor_gscan_get_capabilities(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)453 static int rtw_cfgvendor_gscan_get_capabilities(struct wiphy *wiphy,
454 		struct wireless_dev *wdev, const void  *data, int len)
455 {
456 	int err = 0;
457 	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
458 	dhd_pno_gscan_capabilities_t *reply = NULL;
459 	uint32 reply_len = 0;
460 
461 
462 	reply = dhd_dev_pno_get_gscan(bcmcfg_to_prmry_ndev(cfg),
463 			      DHD_PNO_GET_CAPABILITIES, NULL, &reply_len);
464 	if (!reply) {
465 		WL_ERR(("Could not get capabilities\n"));
466 		err = -EINVAL;
467 		return err;
468 	}
469 
470 	err =  rtw_cfgvendor_send_cmd_reply(wiphy, bcmcfg_to_prmry_ndev(cfg),
471 					    reply, reply_len);
472 
473 	if (unlikely(err))
474 		WL_ERR(("Vendor Command reply failed ret:%d\n", err));
475 
476 	kfree(reply);
477 	return err;
478 }
479 
rtw_cfgvendor_gscan_get_channel_list(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)480 static int rtw_cfgvendor_gscan_get_channel_list(struct wiphy *wiphy,
481 		struct wireless_dev *wdev, const void  *data, int len)
482 {
483 	int err = 0, type, band;
484 	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
485 	uint16 *reply = NULL;
486 	uint32 reply_len = 0, num_channels, mem_needed;
487 	struct sk_buff *skb;
488 
489 	type = nla_type(data);
490 
491 	if (type == GSCAN_ATTRIBUTE_BAND)
492 		band = nla_get_u32(data);
493 	else
494 		return -1;
495 
496 	reply = dhd_dev_pno_get_gscan(bcmcfg_to_prmry_ndev(cfg),
497 			      DHD_PNO_GET_CHANNEL_LIST, &band, &reply_len);
498 
499 	if (!reply) {
500 		WL_ERR(("Could not get channel list\n"));
501 		err = -EINVAL;
502 		return err;
503 	}
504 	num_channels =  reply_len / sizeof(uint32);
505 	mem_needed = reply_len + VENDOR_REPLY_OVERHEAD + (ATTRIBUTE_U32_LEN * 2);
506 
507 	/* Alloc the SKB for vendor_event */
508 	skb = rtw_cfg80211_vendor_cmd_alloc_reply_skb(wiphy, mem_needed);
509 	if (unlikely(!skb)) {
510 		WL_ERR(("skb alloc failed"));
511 		err = -ENOMEM;
512 		goto exit;
513 	}
514 
515 	nla_put_u32(skb, GSCAN_ATTRIBUTE_NUM_CHANNELS, num_channels);
516 	nla_put(skb, GSCAN_ATTRIBUTE_CHANNEL_LIST, reply_len, reply);
517 
518 	err =  rtw_cfg80211_vendor_cmd_reply(skb);
519 
520 	if (unlikely(err))
521 		WL_ERR(("Vendor Command reply failed ret:%d\n", err));
522 exit:
523 	kfree(reply);
524 	return err;
525 }
526 
rtw_cfgvendor_gscan_get_batch_results(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)527 static int rtw_cfgvendor_gscan_get_batch_results(struct wiphy *wiphy,
528 		struct wireless_dev *wdev, const void  *data, int len)
529 {
530 	int err = 0;
531 	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
532 	gscan_results_cache_t *results, *iter;
533 	uint32 reply_len, complete = 0, num_results_iter;
534 	int32 mem_needed;
535 	wifi_gscan_result_t *ptr;
536 	uint16 num_scan_ids, num_results;
537 	struct sk_buff *skb;
538 	struct nlattr *scan_hdr;
539 
540 	dhd_dev_wait_batch_results_complete(bcmcfg_to_prmry_ndev(cfg));
541 	dhd_dev_pno_lock_access_batch_results(bcmcfg_to_prmry_ndev(cfg));
542 	results = dhd_dev_pno_get_gscan(bcmcfg_to_prmry_ndev(cfg),
543 				DHD_PNO_GET_BATCH_RESULTS, NULL, &reply_len);
544 
545 	if (!results) {
546 		WL_ERR(("No results to send %d\n", err));
547 		err =  rtw_cfgvendor_send_cmd_reply(wiphy, bcmcfg_to_prmry_ndev(cfg),
548 						    results, 0);
549 
550 		if (unlikely(err))
551 			WL_ERR(("Vendor Command reply failed ret:%d\n", err));
552 		dhd_dev_pno_unlock_access_batch_results(bcmcfg_to_prmry_ndev(cfg));
553 		return err;
554 	}
555 	num_scan_ids = reply_len & 0xFFFF;
556 	num_results = (reply_len & 0xFFFF0000) >> 16;
557 	mem_needed = (num_results * sizeof(wifi_gscan_result_t)) +
558 		     (num_scan_ids * GSCAN_BATCH_RESULT_HDR_LEN) +
559 		     VENDOR_REPLY_OVERHEAD + SCAN_RESULTS_COMPLETE_FLAG_LEN;
560 
561 	if (mem_needed > (int32)NLMSG_DEFAULT_SIZE) {
562 		mem_needed = (int32)NLMSG_DEFAULT_SIZE;
563 		complete = 0;
564 	} else
565 		complete = 1;
566 
567 	WL_TRACE(("complete %d mem_needed %d max_mem %d\n", complete, mem_needed,
568 		  (int)NLMSG_DEFAULT_SIZE));
569 	/* Alloc the SKB for vendor_event */
570 	skb = rtw_cfg80211_vendor_cmd_alloc_reply_skb(wiphy, mem_needed);
571 	if (unlikely(!skb)) {
572 		WL_ERR(("skb alloc failed"));
573 		dhd_dev_pno_unlock_access_batch_results(bcmcfg_to_prmry_ndev(cfg));
574 		return -ENOMEM;
575 	}
576 	iter = results;
577 
578 	nla_put_u32(skb, GSCAN_ATTRIBUTE_SCAN_RESULTS_COMPLETE, complete);
579 
580 	mem_needed = mem_needed - (SCAN_RESULTS_COMPLETE_FLAG_LEN + VENDOR_REPLY_OVERHEAD);
581 
582 	while (iter && ((mem_needed - GSCAN_BATCH_RESULT_HDR_LEN)  > 0)) {
583 		scan_hdr = nla_nest_start(skb, GSCAN_ATTRIBUTE_SCAN_RESULTS);
584 		nla_put_u32(skb, GSCAN_ATTRIBUTE_SCAN_ID, iter->scan_id);
585 		nla_put_u8(skb, GSCAN_ATTRIBUTE_SCAN_FLAGS, iter->flag);
586 		num_results_iter =
587 			(mem_needed - GSCAN_BATCH_RESULT_HDR_LEN) / sizeof(wifi_gscan_result_t);
588 
589 		if ((iter->tot_count - iter->tot_consumed) < num_results_iter)
590 			num_results_iter = iter->tot_count - iter->tot_consumed;
591 
592 		nla_put_u32(skb, GSCAN_ATTRIBUTE_NUM_OF_RESULTS, num_results_iter);
593 		if (num_results_iter) {
594 			ptr = &iter->results[iter->tot_consumed];
595 			iter->tot_consumed += num_results_iter;
596 			nla_put(skb, GSCAN_ATTRIBUTE_SCAN_RESULTS,
597 				num_results_iter * sizeof(wifi_gscan_result_t), ptr);
598 		}
599 		nla_nest_end(skb, scan_hdr);
600 		mem_needed -= GSCAN_BATCH_RESULT_HDR_LEN +
601 			      (num_results_iter * sizeof(wifi_gscan_result_t));
602 		iter = iter->next;
603 	}
604 
605 	dhd_dev_gscan_batch_cache_cleanup(bcmcfg_to_prmry_ndev(cfg));
606 	dhd_dev_pno_unlock_access_batch_results(bcmcfg_to_prmry_ndev(cfg));
607 
608 	return rtw_cfg80211_vendor_cmd_reply(skb);
609 }
610 
rtw_cfgvendor_initiate_gscan(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)611 static int rtw_cfgvendor_initiate_gscan(struct wiphy *wiphy,
612 		       struct wireless_dev *wdev, const void  *data, int len)
613 {
614 	int err = 0;
615 	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
616 	int type, tmp = len;
617 	int run = 0xFF;
618 	int flush = 0;
619 	const struct nlattr *iter;
620 
621 	nla_for_each_attr(iter, data, len, tmp) {
622 		type = nla_type(iter);
623 		if (type == GSCAN_ATTRIBUTE_ENABLE_FEATURE)
624 			run = nla_get_u32(iter);
625 		else if (type == GSCAN_ATTRIBUTE_FLUSH_FEATURE)
626 			flush = nla_get_u32(iter);
627 	}
628 
629 	if (run != 0xFF) {
630 		err = dhd_dev_pno_run_gscan(bcmcfg_to_prmry_ndev(cfg), run, flush);
631 
632 		if (unlikely(err))
633 			WL_ERR(("Could not run gscan:%d\n", err));
634 		return err;
635 	} else
636 		return -1;
637 
638 
639 }
640 
rtw_cfgvendor_enable_full_scan_result(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)641 static int rtw_cfgvendor_enable_full_scan_result(struct wiphy *wiphy,
642 		struct wireless_dev *wdev, const void  *data, int len)
643 {
644 	int err = 0;
645 	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
646 	int type;
647 	bool real_time = FALSE;
648 
649 	type = nla_type(data);
650 
651 	if (type == GSCAN_ATTRIBUTE_ENABLE_FULL_SCAN_RESULTS) {
652 		real_time = nla_get_u32(data);
653 
654 		err = dhd_dev_pno_enable_full_scan_result(bcmcfg_to_prmry_ndev(cfg), real_time);
655 
656 		if (unlikely(err))
657 			WL_ERR(("Could not run gscan:%d\n", err));
658 
659 	} else
660 		err = -1;
661 
662 	return err;
663 }
664 
rtw_cfgvendor_set_scan_cfg(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)665 static int rtw_cfgvendor_set_scan_cfg(struct wiphy *wiphy,
666 		     struct wireless_dev *wdev, const void  *data, int len)
667 {
668 	int err = 0;
669 	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
670 	gscan_scan_params_t *scan_param;
671 	int j = 0;
672 	int type, tmp, tmp1, tmp2, k = 0;
673 	const struct nlattr *iter, *iter1, *iter2;
674 	struct dhd_pno_gscan_channel_bucket  *ch_bucket;
675 
676 	scan_param = kzalloc(sizeof(gscan_scan_params_t), GFP_KERNEL);
677 	if (!scan_param) {
678 		WL_ERR(("Could not set GSCAN scan cfg, mem alloc failure\n"));
679 		err = -EINVAL;
680 		return err;
681 
682 	}
683 
684 	scan_param->scan_fr = PNO_SCAN_MIN_FW_SEC;
685 	nla_for_each_attr(iter, data, len, tmp) {
686 		type = nla_type(iter);
687 
688 		if (j >= GSCAN_MAX_CH_BUCKETS)
689 			break;
690 
691 		switch (type) {
692 		case GSCAN_ATTRIBUTE_BASE_PERIOD:
693 			scan_param->scan_fr = nla_get_u32(iter) / 1000;
694 			break;
695 		case GSCAN_ATTRIBUTE_NUM_BUCKETS:
696 			scan_param->nchannel_buckets = nla_get_u32(iter);
697 			break;
698 		case GSCAN_ATTRIBUTE_CH_BUCKET_1:
699 		case GSCAN_ATTRIBUTE_CH_BUCKET_2:
700 		case GSCAN_ATTRIBUTE_CH_BUCKET_3:
701 		case GSCAN_ATTRIBUTE_CH_BUCKET_4:
702 		case GSCAN_ATTRIBUTE_CH_BUCKET_5:
703 		case GSCAN_ATTRIBUTE_CH_BUCKET_6:
704 		case GSCAN_ATTRIBUTE_CH_BUCKET_7:
705 			nla_for_each_nested(iter1, iter, tmp1) {
706 				type = nla_type(iter1);
707 				ch_bucket =
708 					scan_param->channel_bucket;
709 
710 				switch (type) {
711 				case GSCAN_ATTRIBUTE_BUCKET_ID:
712 					break;
713 				case GSCAN_ATTRIBUTE_BUCKET_PERIOD:
714 					ch_bucket[j].bucket_freq_multiple =
715 						nla_get_u32(iter1) / 1000;
716 					break;
717 				case GSCAN_ATTRIBUTE_BUCKET_NUM_CHANNELS:
718 					ch_bucket[j].num_channels =
719 						nla_get_u32(iter1);
720 					break;
721 				case GSCAN_ATTRIBUTE_BUCKET_CHANNELS:
722 					nla_for_each_nested(iter2, iter1, tmp2) {
723 						if (k >= PFN_SWC_RSSI_WINDOW_MAX)
724 							break;
725 						ch_bucket[j].chan_list[k] =
726 							nla_get_u32(iter2);
727 						k++;
728 					}
729 					k = 0;
730 					break;
731 				case GSCAN_ATTRIBUTE_BUCKETS_BAND:
732 					ch_bucket[j].band = (uint16)
733 							    nla_get_u32(iter1);
734 					break;
735 				case GSCAN_ATTRIBUTE_REPORT_EVENTS:
736 					ch_bucket[j].report_flag = (uint8)
737 							   nla_get_u32(iter1);
738 					break;
739 				}
740 			}
741 			j++;
742 			break;
743 		}
744 	}
745 
746 	if (dhd_dev_pno_set_cfg_gscan(bcmcfg_to_prmry_ndev(cfg),
747 				      DHD_PNO_SCAN_CFG_ID, scan_param, 0) < 0) {
748 		WL_ERR(("Could not set GSCAN scan cfg\n"));
749 		err = -EINVAL;
750 	}
751 
752 	kfree(scan_param);
753 	return err;
754 
755 }
756 
rtw_cfgvendor_hotlist_cfg(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)757 static int rtw_cfgvendor_hotlist_cfg(struct wiphy *wiphy,
758 		    struct wireless_dev *wdev, const void  *data, int len)
759 {
760 	int err = 0;
761 	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
762 	gscan_hotlist_scan_params_t *hotlist_params;
763 	int tmp, tmp1, tmp2, type, j = 0, dummy;
764 	const struct nlattr *outer, *inner, *iter;
765 	uint8 flush = 0;
766 	struct bssid_t *pbssid;
767 
768 	hotlist_params = (gscan_hotlist_scan_params_t *)kzalloc(len, GFP_KERNEL);
769 	if (!hotlist_params) {
770 		WL_ERR(("Cannot Malloc mem to parse config commands size - %d bytes\n", len));
771 		return -1;
772 	}
773 
774 	hotlist_params->lost_ap_window = GSCAN_LOST_AP_WINDOW_DEFAULT;
775 
776 	nla_for_each_attr(iter, data, len, tmp2) {
777 		type = nla_type(iter);
778 		switch (type) {
779 		case GSCAN_ATTRIBUTE_HOTLIST_BSSIDS:
780 			pbssid = hotlist_params->bssid;
781 			nla_for_each_nested(outer, iter, tmp) {
782 				nla_for_each_nested(inner, outer, tmp1) {
783 					type = nla_type(inner);
784 
785 					switch (type) {
786 					case GSCAN_ATTRIBUTE_BSSID:
787 						memcpy(&(pbssid[j].macaddr),
788 						       nla_data(inner), ETHER_ADDR_LEN);
789 						break;
790 					case GSCAN_ATTRIBUTE_RSSI_LOW:
791 						pbssid[j].rssi_reporting_threshold =
792 							(int8) nla_get_u8(inner);
793 						break;
794 					case GSCAN_ATTRIBUTE_RSSI_HIGH:
795 						dummy = (int8) nla_get_u8(inner);
796 						break;
797 					}
798 				}
799 				j++;
800 			}
801 			hotlist_params->nbssid = j;
802 			break;
803 		case GSCAN_ATTRIBUTE_HOTLIST_FLUSH:
804 			flush = nla_get_u8(iter);
805 			break;
806 		case GSCAN_ATTRIBUTE_LOST_AP_SAMPLE_SIZE:
807 			hotlist_params->lost_ap_window = nla_get_u32(iter);
808 			break;
809 		}
810 
811 	}
812 
813 	if (dhd_dev_pno_set_cfg_gscan(bcmcfg_to_prmry_ndev(cfg),
814 		DHD_PNO_GEOFENCE_SCAN_CFG_ID, hotlist_params, flush) < 0) {
815 		WL_ERR(("Could not set GSCAN HOTLIST cfg\n"));
816 		err = -EINVAL;
817 		goto exit;
818 	}
819 exit:
820 	kfree(hotlist_params);
821 	return err;
822 }
rtw_cfgvendor_set_batch_scan_cfg(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)823 static int rtw_cfgvendor_set_batch_scan_cfg(struct wiphy *wiphy,
824 		struct wireless_dev *wdev, const void  *data, int len)
825 {
826 	int err = 0, tmp, type;
827 	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
828 	gscan_batch_params_t batch_param;
829 	const struct nlattr *iter;
830 
831 	batch_param.mscan = batch_param.bestn = 0;
832 	batch_param.buffer_threshold = GSCAN_BATCH_NO_THR_SET;
833 
834 	nla_for_each_attr(iter, data, len, tmp) {
835 		type = nla_type(iter);
836 
837 		switch (type) {
838 		case GSCAN_ATTRIBUTE_NUM_AP_PER_SCAN:
839 			batch_param.bestn = nla_get_u32(iter);
840 			break;
841 		case GSCAN_ATTRIBUTE_NUM_SCANS_TO_CACHE:
842 			batch_param.mscan = nla_get_u32(iter);
843 			break;
844 		case GSCAN_ATTRIBUTE_REPORT_THRESHOLD:
845 			batch_param.buffer_threshold = nla_get_u32(iter);
846 			break;
847 		}
848 	}
849 
850 	if (dhd_dev_pno_set_cfg_gscan(bcmcfg_to_prmry_ndev(cfg),
851 			      DHD_PNO_BATCH_SCAN_CFG_ID, &batch_param, 0) < 0) {
852 		WL_ERR(("Could not set batch cfg\n"));
853 		err = -EINVAL;
854 		return err;
855 	}
856 
857 	return err;
858 }
859 
rtw_cfgvendor_significant_change_cfg(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)860 static int rtw_cfgvendor_significant_change_cfg(struct wiphy *wiphy,
861 		struct wireless_dev *wdev, const void  *data, int len)
862 {
863 	int err = 0;
864 	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
865 	gscan_swc_params_t *significant_params;
866 	int tmp, tmp1, tmp2, type, j = 0;
867 	const struct nlattr *outer, *inner, *iter;
868 	uint8 flush = 0;
869 	wl_pfn_significant_bssid_t *pbssid;
870 
871 	significant_params = (gscan_swc_params_t *) kzalloc(len, GFP_KERNEL);
872 	if (!significant_params) {
873 		WL_ERR(("Cannot Malloc mem to parse config commands size - %d bytes\n", len));
874 		return -1;
875 	}
876 
877 
878 	nla_for_each_attr(iter, data, len, tmp2) {
879 		type = nla_type(iter);
880 
881 		switch (type) {
882 		case GSCAN_ATTRIBUTE_SIGNIFICANT_CHANGE_FLUSH:
883 			flush = nla_get_u8(iter);
884 			break;
885 		case GSCAN_ATTRIBUTE_RSSI_SAMPLE_SIZE:
886 			significant_params->rssi_window = nla_get_u16(iter);
887 			break;
888 		case GSCAN_ATTRIBUTE_LOST_AP_SAMPLE_SIZE:
889 			significant_params->lost_ap_window = nla_get_u16(iter);
890 			break;
891 		case GSCAN_ATTRIBUTE_MIN_BREACHING:
892 			significant_params->swc_threshold = nla_get_u16(iter);
893 			break;
894 		case GSCAN_ATTRIBUTE_SIGNIFICANT_CHANGE_BSSIDS:
895 			pbssid = significant_params->bssid_elem_list;
896 			nla_for_each_nested(outer, iter, tmp) {
897 				nla_for_each_nested(inner, outer, tmp1) {
898 					switch (nla_type(inner)) {
899 					case GSCAN_ATTRIBUTE_BSSID:
900 						memcpy(&(pbssid[j].macaddr),
901 						       nla_data(inner),
902 						       ETHER_ADDR_LEN);
903 						break;
904 					case GSCAN_ATTRIBUTE_RSSI_HIGH:
905 						pbssid[j].rssi_high_threshold =
906 							(int8) nla_get_u8(inner);
907 						break;
908 					case GSCAN_ATTRIBUTE_RSSI_LOW:
909 						pbssid[j].rssi_low_threshold =
910 							(int8) nla_get_u8(inner);
911 						break;
912 					}
913 				}
914 				j++;
915 			}
916 			break;
917 		}
918 	}
919 	significant_params->nbssid = j;
920 
921 	if (dhd_dev_pno_set_cfg_gscan(bcmcfg_to_prmry_ndev(cfg),
922 		DHD_PNO_SIGNIFICANT_SCAN_CFG_ID, significant_params, flush) < 0) {
923 		WL_ERR(("Could not set GSCAN significant cfg\n"));
924 		err = -EINVAL;
925 		goto exit;
926 	}
927 exit:
928 	kfree(significant_params);
929 	return err;
930 }
931 #endif /* GSCAN_SUPPORT */
932 
933 #if defined(RTT_SUPPORT) && 0
rtw_cfgvendor_rtt_evt(void * ctx,void * rtt_data)934 void rtw_cfgvendor_rtt_evt(void *ctx, void *rtt_data)
935 {
936 	struct wireless_dev *wdev = (struct wireless_dev *)ctx;
937 	struct wiphy *wiphy;
938 	struct sk_buff *skb;
939 	uint32 tot_len = NLMSG_DEFAULT_SIZE, entry_len = 0;
940 	gfp_t kflags;
941 	rtt_report_t *rtt_report = NULL;
942 	rtt_result_t *rtt_result = NULL;
943 	struct list_head *rtt_list;
944 	wiphy = wdev->wiphy;
945 
946 	WL_DBG(("In\n"));
947 	/* Push the data to the skb */
948 	if (!rtt_data) {
949 		WL_ERR(("rtt_data is NULL\n"));
950 		goto exit;
951 	}
952 	rtt_list = (struct list_head *)rtt_data;
953 	kflags = in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
954 	/* Alloc the SKB for vendor_event */
955 	skb = rtw_cfg80211_vendor_event_alloc(wiphy, wdev, tot_len, GOOGLE_RTT_COMPLETE_EVENT, kflags);
956 	if (!skb) {
957 		WL_ERR(("skb alloc failed"));
958 		goto exit;
959 	}
960 	/* fill in the rtt results on each entry */
961 	list_for_each_entry(rtt_result, rtt_list, list) {
962 		entry_len = 0;
963 		if (rtt_result->TOF_type == TOF_TYPE_ONE_WAY) {
964 			entry_len = sizeof(rtt_report_t);
965 			rtt_report = kzalloc(entry_len, kflags);
966 			if (!rtt_report) {
967 				WL_ERR(("rtt_report alloc failed"));
968 				goto exit;
969 			}
970 			rtt_report->addr = rtt_result->peer_mac;
971 			rtt_report->num_measurement = 1; /* ONE SHOT */
972 			rtt_report->status = rtt_result->err_code;
973 			rtt_report->type = (rtt_result->TOF_type == TOF_TYPE_ONE_WAY) ? RTT_ONE_WAY : RTT_TWO_WAY;
974 			rtt_report->peer = rtt_result->target_info->peer;
975 			rtt_report->channel = rtt_result->target_info->channel;
976 			rtt_report->rssi = rtt_result->avg_rssi;
977 			/* tx_rate */
978 			rtt_report->tx_rate = rtt_result->tx_rate;
979 			/* RTT */
980 			rtt_report->rtt = rtt_result->meanrtt;
981 			rtt_report->rtt_sd = rtt_result->sdrtt;
982 			/* convert to centi meter */
983 			if (rtt_result->distance != 0xffffffff)
984 				rtt_report->distance = (rtt_result->distance >> 2) * 25;
985 			else /* invalid distance */
986 				rtt_report->distance = -1;
987 
988 			rtt_report->ts = rtt_result->ts;
989 			nla_append(skb, entry_len, rtt_report);
990 			kfree(rtt_report);
991 		}
992 	}
993 	rtw_cfg80211_vendor_event(skb, kflags);
994 exit:
995 	return;
996 }
997 
rtw_cfgvendor_rtt_set_config(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)998 static int rtw_cfgvendor_rtt_set_config(struct wiphy *wiphy, struct wireless_dev *wdev,
999 				       const void *data, int len)
1000 {
1001 	int err = 0, rem, rem1, rem2, type;
1002 	rtt_config_params_t rtt_param;
1003 	rtt_target_info_t *rtt_target = NULL;
1004 	const struct nlattr *iter, *iter1, *iter2;
1005 	int8 eabuf[ETHER_ADDR_STR_LEN];
1006 	int8 chanbuf[CHANSPEC_STR_LEN];
1007 	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
1008 
1009 	WL_DBG(("In\n"));
1010 	err = dhd_dev_rtt_register_noti_callback(wdev->netdev, wdev, wl_cfgvendor_rtt_evt);
1011 	if (err < 0) {
1012 		WL_ERR(("failed to register rtt_noti_callback\n"));
1013 		goto exit;
1014 	}
1015 	memset(&rtt_param, 0, sizeof(rtt_param));
1016 	nla_for_each_attr(iter, data, len, rem) {
1017 		type = nla_type(iter);
1018 		switch (type) {
1019 		case RTT_ATTRIBUTE_TARGET_CNT:
1020 			rtt_param.rtt_target_cnt = nla_get_u8(iter);
1021 			if (rtt_param.rtt_target_cnt > RTT_MAX_TARGET_CNT) {
1022 				WL_ERR(("exceed max target count : %d\n",
1023 					rtt_param.rtt_target_cnt));
1024 				err = BCME_RANGE;
1025 			}
1026 			break;
1027 		case RTT_ATTRIBUTE_TARGET_INFO:
1028 			rtt_target = rtt_param.target_info;
1029 			nla_for_each_nested(iter1, iter, rem1) {
1030 				nla_for_each_nested(iter2, iter1, rem2) {
1031 					type = nla_type(iter2);
1032 					switch (type) {
1033 					case RTT_ATTRIBUTE_TARGET_MAC:
1034 						memcpy(&rtt_target->addr, nla_data(iter2), ETHER_ADDR_LEN);
1035 						break;
1036 					case RTT_ATTRIBUTE_TARGET_TYPE:
1037 						rtt_target->type = nla_get_u8(iter2);
1038 						break;
1039 					case RTT_ATTRIBUTE_TARGET_PEER:
1040 						rtt_target->peer = nla_get_u8(iter2);
1041 						break;
1042 					case RTT_ATTRIBUTE_TARGET_CHAN:
1043 						memcpy(&rtt_target->channel, nla_data(iter2),
1044 						       sizeof(rtt_target->channel));
1045 						break;
1046 					case RTT_ATTRIBUTE_TARGET_MODE:
1047 						rtt_target->continuous = nla_get_u8(iter2);
1048 						break;
1049 					case RTT_ATTRIBUTE_TARGET_INTERVAL:
1050 						rtt_target->interval = nla_get_u32(iter2);
1051 						break;
1052 					case RTT_ATTRIBUTE_TARGET_NUM_MEASUREMENT:
1053 						rtt_target->measure_cnt = nla_get_u32(iter2);
1054 						break;
1055 					case RTT_ATTRIBUTE_TARGET_NUM_PKT:
1056 						rtt_target->ftm_cnt = nla_get_u32(iter2);
1057 						break;
1058 					case RTT_ATTRIBUTE_TARGET_NUM_RETRY:
1059 						rtt_target->retry_cnt = nla_get_u32(iter2);
1060 					}
1061 				}
1062 				/* convert to chanspec value */
1063 				rtt_target->chanspec = dhd_rtt_convert_to_chspec(rtt_target->channel);
1064 				if (rtt_target->chanspec == 0) {
1065 					WL_ERR(("Channel is not valid\n"));
1066 					goto exit;
1067 				}
1068 				WL_INFORM(("Target addr %s, Channel : %s for RTT\n",
1069 					bcm_ether_ntoa((const struct ether_addr *)&rtt_target->addr, eabuf),
1070 					wf_chspec_ntoa(rtt_target->chanspec, chanbuf)));
1071 				rtt_target++;
1072 			}
1073 			break;
1074 		}
1075 	}
1076 	WL_DBG(("leave :target_cnt : %d\n", rtt_param.rtt_target_cnt));
1077 	if (dhd_dev_rtt_set_cfg(bcmcfg_to_prmry_ndev(cfg), &rtt_param) < 0) {
1078 		WL_ERR(("Could not set RTT configuration\n"));
1079 		err = -EINVAL;
1080 	}
1081 exit:
1082 	return err;
1083 }
1084 
rtw_cfgvendor_rtt_cancel_config(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1085 static int rtw_cfgvendor_rtt_cancel_config(struct wiphy *wiphy, struct wireless_dev *wdev,
1086 		const void *data, int len)
1087 {
1088 	int err = 0, rem, type, target_cnt = 0;
1089 	const struct nlattr *iter;
1090 	struct ether_addr *mac_list = NULL, *mac_addr = NULL;
1091 	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
1092 
1093 	nla_for_each_attr(iter, data, len, rem) {
1094 		type = nla_type(iter);
1095 		switch (type) {
1096 		case RTT_ATTRIBUTE_TARGET_CNT:
1097 			target_cnt = nla_get_u8(iter);
1098 			mac_list = (struct ether_addr *)kzalloc(target_cnt * ETHER_ADDR_LEN , GFP_KERNEL);
1099 			if (mac_list == NULL) {
1100 				WL_ERR(("failed to allocate mem for mac list\n"));
1101 				goto exit;
1102 			}
1103 			mac_addr = &mac_list[0];
1104 			break;
1105 		case RTT_ATTRIBUTE_TARGET_MAC:
1106 			if (mac_addr)
1107 				memcpy(mac_addr++, nla_data(iter), ETHER_ADDR_LEN);
1108 			else {
1109 				WL_ERR(("mac_list is NULL\n"));
1110 				goto exit;
1111 			}
1112 			break;
1113 		}
1114 		if (dhd_dev_rtt_cancel_cfg(bcmcfg_to_prmry_ndev(cfg), mac_list, target_cnt) < 0) {
1115 			WL_ERR(("Could not cancel RTT configuration\n"));
1116 			err = -EINVAL;
1117 			goto exit;
1118 		}
1119 	}
1120 exit:
1121 	if (mac_list)
1122 		kfree(mac_list);
1123 	return err;
1124 }
rtw_cfgvendor_rtt_get_capability(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1125 static int rtw_cfgvendor_rtt_get_capability(struct wiphy *wiphy, struct wireless_dev *wdev,
1126 		const void *data, int len)
1127 {
1128 	int err = 0;
1129 	struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
1130 	rtt_capabilities_t capability;
1131 
1132 	err = dhd_dev_rtt_capability(bcmcfg_to_prmry_ndev(cfg), &capability);
1133 	if (unlikely(err)) {
1134 		WL_ERR(("Vendor Command reply failed ret:%d\n", err));
1135 		goto exit;
1136 	}
1137 	err =  rtw_cfgvendor_send_cmd_reply(wiphy, bcmcfg_to_prmry_ndev(cfg),
1138 					    &capability, sizeof(capability));
1139 
1140 	if (unlikely(err))
1141 		WL_ERR(("Vendor Command reply failed ret:%d\n", err));
1142 exit:
1143 	return err;
1144 }
1145 
1146 #endif /* RTT_SUPPORT */
1147 
1148 #ifdef CONFIG_RTW_CFGVENDOR_LLSTATS
1149 enum {
1150     LSTATS_SUBCMD_GET_INFO = ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START,
1151 	LSTATS_SUBCMD_SET_INFO,
1152 	LSTATS_SUBCMD_CLEAR_INFO,
1153 };
LinkLayerStats(_adapter * padapter)1154 static void LinkLayerStats(_adapter *padapter)
1155 {
1156 	struct xmit_priv		*pxmitpriv = &(padapter->xmitpriv);
1157 	struct recv_priv		*precvpriv = &(padapter->recvpriv);
1158 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1159 	struct dvobj_priv	*pdvobjpriv = adapter_to_dvobj(padapter);
1160 	u32 ps_time, trx_total_time;
1161 	u64 tx_bytes, rx_bytes, trx_total_bytes = 0;
1162 	u64 tmp = 0;
1163 
1164 	RTW_DBG("%s adapter type : %u\n", __func__, padapter->adapter_type);
1165 
1166 	tx_bytes = 0;
1167 	rx_bytes = 0;
1168 	ps_time = 0;
1169 	trx_total_time = 0;
1170 
1171 	if ( padapter->netif_up == _TRUE ) {
1172 
1173 		pwrpriv->on_time = rtw_get_passing_time_ms(pwrpriv->radio_on_start_time);
1174 
1175 		if (rtw_mi_check_fwstate(padapter, WIFI_ASOC_STATE)) {
1176 			if ( pwrpriv->bpower_saving == _TRUE ) {
1177 				pwrpriv->pwr_saving_time += rtw_get_passing_time_ms(pwrpriv->pwr_saving_start_time);
1178 				pwrpriv->pwr_saving_start_time = rtw_get_current_time();
1179 			}
1180 		} else {
1181 #ifdef CONFIG_IPS
1182 			if ( pwrpriv->bpower_saving == _TRUE ) {
1183 				pwrpriv->pwr_saving_time += rtw_get_passing_time_ms(pwrpriv->pwr_saving_start_time);
1184 				pwrpriv->pwr_saving_start_time = rtw_get_current_time();
1185 			}
1186 #else
1187 			pwrpriv->pwr_saving_time = pwrpriv->on_time;
1188 #endif
1189 		}
1190 
1191 		ps_time = pwrpriv->pwr_saving_time;
1192 
1193 		/* Deviation caused by caculation start time */
1194 		if ( ps_time > pwrpriv->on_time )
1195 			ps_time = pwrpriv->on_time;
1196 
1197 		tx_bytes = pdvobjpriv->traffic_stat.last_tx_bytes;
1198 		rx_bytes = pdvobjpriv->traffic_stat.last_rx_bytes;
1199 		trx_total_bytes = tx_bytes + rx_bytes;
1200 
1201 		trx_total_time = pwrpriv->on_time - ps_time;
1202 
1203 		if ( trx_total_bytes == 0) {
1204 			pwrpriv->tx_time = 0;
1205 			pwrpriv->rx_time = 0;
1206 		} else {
1207 
1208 			/* tx_time = (trx_total_time * tx_total_bytes) / trx_total_bytes; */
1209 			/* rx_time = (trx_total_time * rx_total_bytes) / trx_total_bytes; */
1210 
1211 			tmp = (tx_bytes * trx_total_time);
1212 			tmp = rtw_division64(tmp, trx_total_bytes);
1213 			pwrpriv->tx_time = tmp;
1214 
1215 			tmp = (rx_bytes * trx_total_time);
1216 			tmp = rtw_division64(tmp, trx_total_bytes);
1217 			pwrpriv->rx_time = tmp;
1218 
1219 		}
1220 
1221 	}
1222 	else {
1223 			pwrpriv->on_time = 0;
1224 			pwrpriv->tx_time = 0;
1225 			pwrpriv->rx_time = 0;
1226 	}
1227 
1228 #ifdef CONFIG_RTW_WIFI_HAL_DEBUG
1229 	RTW_INFO("- tx_bytes : %llu rx_bytes : %llu total bytes : %llu\n", tx_bytes, rx_bytes, trx_total_bytes);
1230 	RTW_INFO("- netif_up = %s, on_time : %u ms\n", padapter->netif_up ? "1":"0", pwrpriv->on_time);
1231 	RTW_INFO("- pwr_saving_time : %u (%u) ms\n", pwrpriv->pwr_saving_time, ps_time);
1232 	RTW_INFO("- trx_total_time : %u ms\n", trx_total_time);
1233 	RTW_INFO("- tx_time : %u ms\n", pwrpriv->tx_time);
1234 	RTW_INFO("- rx_time : %u ms\n", pwrpriv->rx_time);
1235 #endif /* CONFIG_RTW_WIFI_HAL_DEBUG */
1236 
1237 }
1238 
1239 #define DUMMY_TIME_STATICS 99
rtw_cfgvendor_lstats_get_info(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1240 static int rtw_cfgvendor_lstats_get_info(struct wiphy *wiphy,
1241 	struct wireless_dev *wdev, const void  *data, int len)
1242 {
1243 	int err = 0;
1244 	_adapter *padapter = GET_PRIMARY_ADAPTER(wiphy_to_adapter(wiphy));
1245 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1246 	wifi_radio_stat_internal *radio;
1247 	wifi_iface_stat *iface;
1248 	char *output;
1249 
1250 	output = rtw_malloc(sizeof(wifi_radio_stat_internal) + sizeof(wifi_iface_stat));
1251 	if (output == NULL) {
1252 		RTW_DBG("Allocate lstats info buffer fail!\n");
1253 	}
1254 
1255 	radio = (wifi_radio_stat_internal *)output;
1256 
1257 	radio->num_channels = 0;
1258 	radio->radio = 1;
1259 
1260 	/* to get on_time, tx_time, rx_time */
1261 	LinkLayerStats(padapter);
1262 
1263 	radio->on_time = pwrpriv->on_time;
1264 	radio->tx_time = pwrpriv->tx_time;
1265 	radio->rx_time = pwrpriv->rx_time;
1266 	radio->on_time_scan = 0;
1267 	radio->on_time_nbd = 0;
1268 	radio->on_time_gscan = 0;
1269 	radio->on_time_pno_scan = 0;
1270 	radio->on_time_hs20 = 0;
1271 	#ifdef CONFIG_RTW_WIFI_HAL_DEBUG
1272 	RTW_INFO("==== %s ====\n", __func__);
1273 	RTW_INFO("radio->radio : %d\n", (radio->radio));
1274 	RTW_INFO("pwrpriv->on_time : %u ms\n", (pwrpriv->on_time));
1275 	RTW_INFO("pwrpriv->tx_time :  %u ms\n", (pwrpriv->tx_time));
1276 	RTW_INFO("pwrpriv->rx_time :  %u ms\n", (pwrpriv->rx_time));
1277 	RTW_INFO("radio->on_time :  %u ms\n", (radio->on_time));
1278 	RTW_INFO("radio->tx_time :  %u ms\n", (radio->tx_time));
1279 	RTW_INFO("radio->rx_time :  %u ms\n", (radio->rx_time));
1280 	#endif /* CONFIG_RTW_WIFI_HAL_DEBUG */
1281 
1282 	RTW_DBG(FUNC_NDEV_FMT" %s\n", FUNC_NDEV_ARG(wdev_to_ndev(wdev)), (char*)data);
1283 	err =  rtw_cfgvendor_send_cmd_reply(wiphy, wdev_to_ndev(wdev),
1284 		output, sizeof(wifi_iface_stat) + sizeof(wifi_radio_stat_internal));
1285 	if (unlikely(err))
1286 		RTW_ERR(FUNC_NDEV_FMT"Vendor Command reply failed ret:%d \n"
1287 			, FUNC_NDEV_ARG(wdev_to_ndev(wdev)), err);
1288 	rtw_mfree(output, sizeof(wifi_iface_stat) + sizeof(wifi_radio_stat_internal));
1289 	return err;
1290 }
rtw_cfgvendor_lstats_set_info(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1291 static int rtw_cfgvendor_lstats_set_info(struct wiphy *wiphy,
1292 	struct wireless_dev *wdev, const void  *data, int len)
1293 {
1294 	int err = 0;
1295 	RTW_INFO("%s\n", __func__);
1296 	return err;
1297 }
rtw_cfgvendor_lstats_clear_info(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1298 static int rtw_cfgvendor_lstats_clear_info(struct wiphy *wiphy,
1299 	struct wireless_dev *wdev, const void  *data, int len)
1300 {
1301 	int err = 0;
1302 	RTW_INFO("%s\n", __func__);
1303 	return err;
1304 }
1305 #endif /* CONFIG_RTW_CFGVENDOR_LLSTATS */
1306 #ifdef CONFIG_RTW_CFGVENDOR_RSSIMONITOR
rtw_cfgvendor_set_rssi_monitor(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1307 static int rtw_cfgvendor_set_rssi_monitor(struct wiphy *wiphy,
1308 	struct wireless_dev *wdev, const void  *data, int len)
1309 {
1310         _adapter *padapter = GET_PRIMARY_ADAPTER(wiphy_to_adapter(wiphy));
1311         struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
1312 
1313         struct recv_priv *precvpriv = &padapter->recvpriv;
1314 	int err = 0, rem, type;
1315         const struct nlattr *iter;
1316 
1317         RTW_DBG(FUNC_NDEV_FMT" %s\n", FUNC_NDEV_ARG(wdev_to_ndev(wdev)), (char*)data);
1318 
1319 	nla_for_each_attr(iter, data, len, rem) {
1320 		type = nla_type(iter);
1321 
1322 		switch (type) {
1323         		case RSSI_MONITOR_ATTRIBUTE_MAX_RSSI:
1324                                 pwdev_priv->rssi_monitor_max = (s8)nla_get_u32(iter);;
1325 	        		break;
1326 		        case RSSI_MONITOR_ATTRIBUTE_MIN_RSSI:
1327                                 pwdev_priv->rssi_monitor_min = (s8)nla_get_u32(iter);
1328 			        break;
1329         		case RSSI_MONITOR_ATTRIBUTE_START:
1330                                 pwdev_priv->rssi_monitor_enable = (u8)nla_get_u32(iter);
1331 	        		break;
1332 		}
1333 	}
1334 
1335 	return err;
1336 }
1337 
rtw_cfgvendor_rssi_monitor_evt(_adapter * padapter)1338 void rtw_cfgvendor_rssi_monitor_evt(_adapter *padapter) {
1339 	struct wireless_dev *wdev =  padapter->rtw_wdev;
1340 	struct wiphy *wiphy= wdev->wiphy;
1341         struct recv_priv *precvpriv = &padapter->recvpriv;
1342 	struct	mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
1343 	struct	wlan_network	*pcur_network = &pmlmepriv->cur_network;
1344         struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
1345 	struct sk_buff *skb;
1346 	u32 tot_len = NLMSG_DEFAULT_SIZE;
1347 	gfp_t kflags;
1348         rssi_monitor_evt data ;
1349         s8 rssi = precvpriv->rssi;
1350 
1351         if (pwdev_priv->rssi_monitor_enable == 0 || check_fwstate(pmlmepriv, WIFI_ASOC_STATE) != _TRUE)
1352                 return;
1353 
1354         if (rssi < pwdev_priv->rssi_monitor_max || rssi > pwdev_priv->rssi_monitor_min)
1355                 return;
1356 
1357 	kflags = in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
1358 
1359 	/* Alloc the SKB for vendor_event */
1360 	skb = rtw_cfg80211_vendor_event_alloc(wiphy, wdev, tot_len, GOOGLE_RSSI_MONITOR_EVENT, kflags);
1361 	if (!skb) {
1362 		goto exit;
1363 	}
1364 
1365         _rtw_memset(&data, 0, sizeof(data));
1366 
1367         data.version = RSSI_MONITOR_EVT_VERSION;
1368         data.cur_rssi = rssi;
1369         _rtw_memcpy(data.BSSID, pcur_network->network.MacAddress, sizeof(mac_addr));
1370 
1371         nla_append(skb, sizeof(data), &data);
1372 
1373 	rtw_cfg80211_vendor_event(skb, kflags);
1374 exit:
1375 	return;
1376 }
1377 #endif /* CONFIG_RTW_CFGVENDOR_RSSIMONITR */
1378 
1379 #ifdef CONFIG_RTW_CFGVENDOR_WIFI_LOGGER
rtw_cfgvendor_logger_start_logging(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1380 static int rtw_cfgvendor_logger_start_logging(struct wiphy *wiphy,
1381 	struct wireless_dev *wdev, const void  *data, int len)
1382 {
1383 	int ret = 0, rem, type;
1384 	char ring_name[32] = {0};
1385 	int log_level = 0, flags = 0, time_intval = 0, threshold = 0;
1386 	const struct nlattr *iter;
1387 
1388 	nla_for_each_attr(iter, data, len, rem) {
1389 		type = nla_type(iter);
1390 		switch (type) {
1391 			case LOGGER_ATTRIBUTE_RING_NAME:
1392 				strncpy(ring_name, nla_data(iter),
1393 					MIN(sizeof(ring_name) -1, nla_len(iter)));
1394 				break;
1395 			case LOGGER_ATTRIBUTE_LOG_LEVEL:
1396 				log_level = nla_get_u32(iter);
1397 				break;
1398 			case LOGGER_ATTRIBUTE_RING_FLAGS:
1399 				flags = nla_get_u32(iter);
1400 				break;
1401 			case LOGGER_ATTRIBUTE_LOG_TIME_INTVAL:
1402 				time_intval = nla_get_u32(iter);
1403 				break;
1404 			case LOGGER_ATTRIBUTE_LOG_MIN_DATA_SIZE:
1405 				threshold = nla_get_u32(iter);
1406 				break;
1407 			default:
1408 				RTW_ERR("Unknown type: %d\n", type);
1409 				ret = WIFI_ERROR_INVALID_ARGS;
1410 				goto exit;
1411 		}
1412 	}
1413 
1414 exit:
1415 	return ret;
1416 }
rtw_cfgvendor_logger_get_feature(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1417 static int rtw_cfgvendor_logger_get_feature(struct wiphy *wiphy,
1418 	struct wireless_dev *wdev, const void *data, int len)
1419 {
1420 	int err = 0;
1421 	u32 supported_features = 0;
1422 
1423 	err =  rtw_cfgvendor_send_cmd_reply(wiphy, wdev_to_ndev(wdev), &supported_features, sizeof(supported_features));
1424 
1425 	if (unlikely(err))
1426 		RTW_ERR(FUNC_NDEV_FMT" Vendor Command reply failed ret:%d\n"
1427 			, FUNC_NDEV_ARG(wdev_to_ndev(wdev)), err);
1428 
1429 	return err;
1430 }
rtw_cfgvendor_logger_get_version(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1431 static int rtw_cfgvendor_logger_get_version(struct wiphy *wiphy,
1432 	struct wireless_dev *wdev, const void *data, int len)
1433 {
1434 	_adapter *padapter = GET_PRIMARY_ADAPTER(wiphy_to_adapter(wiphy));
1435 	HAL_DATA_TYPE *hal = GET_HAL_DATA(padapter);
1436 	int ret = 0, rem, type;
1437 	int buf_len = 1024;
1438 	char *buf_ptr;
1439 	const struct nlattr *iter;
1440 	gfp_t kflags;
1441 
1442 	kflags = in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
1443 	buf_ptr = kzalloc(buf_len, kflags);
1444 	if (!buf_ptr) {
1445 		RTW_ERR("failed to allocate the buffer for version n");
1446 		ret = -ENOMEM;
1447 		goto exit;
1448 	}
1449 	nla_for_each_attr(iter, data, len, rem) {
1450 		type = nla_type(iter);
1451 		switch (type) {
1452 			case LOGGER_ATTRIBUTE_GET_DRIVER:
1453 				memcpy(buf_ptr, DRIVERVERSION, strlen(DRIVERVERSION)+1);
1454 				break;
1455 			case LOGGER_ATTRIBUTE_GET_FW:
1456 				sprintf(buf_ptr, "v%d.%d", hal->firmware_version, hal->firmware_sub_version);
1457 				break;
1458 			default:
1459 				RTW_ERR("Unknown type: %d\n", type);
1460 				ret = -EINVAL;
1461 				goto exit;
1462 		}
1463 	}
1464 	if (ret < 0) {
1465 		RTW_ERR("failed to get the version %d\n", ret);
1466 		goto exit;
1467 	}
1468 
1469 
1470 	ret =  rtw_cfgvendor_send_cmd_reply(wiphy, wdev_to_ndev(wdev), buf_ptr, strlen(buf_ptr));
1471 exit:
1472 	kfree(buf_ptr);
1473 	return ret;
1474 }
1475 
rtw_cfgvendor_logger_get_ring_status(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1476 static int rtw_cfgvendor_logger_get_ring_status(struct wiphy *wiphy,
1477 	struct wireless_dev *wdev, const void  *data, int len)
1478 {
1479 	int ret = 0;
1480 	int ring_id;
1481 	char ring_buf_name[] = "RTW_RING_BUFFER";
1482 
1483 	struct sk_buff *skb;
1484 	wifi_ring_buffer_status ring_status;
1485 
1486 
1487 	_rtw_memcpy(ring_status.name, ring_buf_name, strlen(ring_buf_name)+1);
1488 	ring_status.ring_id = 1;
1489 	/* Alloc the SKB for vendor_event */
1490 	skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy,
1491 		sizeof(wifi_ring_buffer_status));
1492 	if (!skb) {
1493 		RTW_ERR("skb allocation is failed\n");
1494 		ret = FAIL;
1495 		goto exit;
1496 	}
1497 
1498 	nla_put_u32(skb, LOGGER_ATTRIBUTE_RING_NUM, 1);
1499 	nla_put(skb, LOGGER_ATTRIBUTE_RING_STATUS, sizeof(wifi_ring_buffer_status),
1500 				&ring_status);
1501 	ret = cfg80211_vendor_cmd_reply(skb);
1502 
1503 	if (ret) {
1504 		RTW_ERR("Vendor Command reply failed ret:%d \n", ret);
1505 	}
1506 exit:
1507 	return ret;
1508 }
1509 
rtw_cfgvendor_logger_get_ring_data(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1510 static int rtw_cfgvendor_logger_get_ring_data(struct wiphy *wiphy,
1511 	struct wireless_dev *wdev, const void  *data, int len)
1512 {
1513 	int ret = 0, rem, type;
1514 	char ring_name[32] = {0};
1515 	const struct nlattr *iter;
1516 
1517 	nla_for_each_attr(iter, data, len, rem) {
1518 		type = nla_type(iter);
1519 		switch (type) {
1520 			case LOGGER_ATTRIBUTE_RING_NAME:
1521 				strncpy(ring_name, nla_data(iter),
1522 					MIN(sizeof(ring_name) -1, nla_len(iter)));
1523 				RTW_INFO(" %s LOGGER_ATTRIBUTE_RING_NAME : %s\n", __func__, ring_name);
1524 				break;
1525 			default:
1526 				RTW_ERR("Unknown type: %d\n", type);
1527 				return ret;
1528 		}
1529 	}
1530 
1531 
1532 	return ret;
1533 }
1534 
rtw_cfgvendor_logger_get_firmware_memory_dump(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1535 static int rtw_cfgvendor_logger_get_firmware_memory_dump(struct wiphy *wiphy,
1536 	struct wireless_dev *wdev, const void  *data, int len)
1537 {
1538 	int ret = WIFI_ERROR_NOT_SUPPORTED;
1539 
1540 	return ret;
1541 }
1542 
rtw_cfgvendor_logger_start_pkt_fate_monitoring(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1543 static int rtw_cfgvendor_logger_start_pkt_fate_monitoring(struct wiphy *wiphy,
1544 	struct wireless_dev *wdev, const void  *data, int len)
1545 {
1546 	int ret = WIFI_SUCCESS;
1547 
1548 	return ret;
1549 }
1550 
rtw_cfgvendor_logger_get_tx_pkt_fates(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1551 static int rtw_cfgvendor_logger_get_tx_pkt_fates(struct wiphy *wiphy,
1552 	struct wireless_dev *wdev, const void  *data, int len)
1553 {
1554 	int ret = WIFI_SUCCESS;
1555 
1556 	return ret;
1557 }
1558 
rtw_cfgvendor_logger_get_rx_pkt_fates(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1559 static int rtw_cfgvendor_logger_get_rx_pkt_fates(struct wiphy *wiphy,
1560 	struct wireless_dev *wdev, const void  *data, int len)
1561 {
1562 	int ret = WIFI_SUCCESS;
1563 
1564 	return ret;
1565 }
1566 
1567 #endif /* CONFIG_RTW_CFGVENDOR_WIFI_LOGGER */
1568 #ifdef CONFIG_RTW_WIFI_HAL
1569 #ifdef CONFIG_RTW_CFGVENDOR_RANDOM_MAC_OUI
1570 
1571 #ifndef ETHER_ISMULTI
1572 #define ETHER_ISMULTI(ea) (((const u8 *)(ea))[0] & 1)
1573 #endif
1574 
1575 
1576 static u8 null_addr[ETH_ALEN] = {0};
rtw_hal_random_gen_mac_addr(u8 * mac_addr)1577 static void rtw_hal_random_gen_mac_addr(u8 *mac_addr)
1578 {
1579 	do {
1580 		get_random_bytes(&mac_addr[3], ETH_ALEN-3);
1581 		if (memcmp(mac_addr, null_addr, ETH_ALEN) != 0)
1582 			break;
1583 	} while(1);
1584 }
1585 
rtw_hal_pno_random_gen_mac_addr(PADAPTER adapter)1586 void rtw_hal_pno_random_gen_mac_addr(PADAPTER adapter)
1587 {
1588 	u8 mac_addr[ETH_ALEN];
1589 	struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter);
1590 
1591 	memcpy(mac_addr, pwdev_priv->pno_mac_addr, ETH_ALEN);
1592 	if (mac_addr[0] == 0xFF) return;
1593 	rtw_hal_random_gen_mac_addr(mac_addr);
1594 	memcpy(pwdev_priv->pno_mac_addr, mac_addr, ETH_ALEN);
1595 #ifdef CONFIG_RTW_DEBUG
1596 	print_hex_dump(KERN_DEBUG, "pno_mac_addr: ",
1597 		       DUMP_PREFIX_OFFSET, 16, 1, pwdev_priv->pno_mac_addr,
1598 		       ETH_ALEN, 1);
1599 #endif
1600 }
1601 
rtw_hal_set_hw_mac_addr(PADAPTER adapter,u8 * mac_addr)1602 void rtw_hal_set_hw_mac_addr(PADAPTER adapter, u8 *mac_addr)
1603 {
1604 	rtw_ps_deny(adapter, PS_DENY_IOCTL);
1605 	LeaveAllPowerSaveModeDirect(adapter);
1606 
1607 #ifdef CONFIG_MI_WITH_MBSSID_CAM
1608 	rtw_hal_change_macaddr_mbid(adapter, mac_addr);
1609 #else
1610 	rtw_hal_set_hwreg(adapter, HW_VAR_MAC_ADDR, mac_addr);
1611 #endif
1612 #ifdef CONFIG_RTW_DEBUG
1613 	rtw_hal_dump_macaddr(RTW_DBGDUMP, adapter);
1614 #endif
1615 	rtw_ps_deny_cancel(adapter, PS_DENY_IOCTL);
1616 }
1617 
rtw_cfgvendor_set_rand_mac_oui(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1618 static int rtw_cfgvendor_set_rand_mac_oui(struct wiphy *wiphy,
1619 		struct wireless_dev *wdev, const void  *data, int len)
1620 {
1621 	int err = 0;
1622 	PADAPTER adapter;
1623 	void *devaddr;
1624 	struct net_device *netdev;
1625 	int type, mac_len;
1626 	u8 pno_random_mac_oui[3];
1627 	u8 mac_addr[ETH_ALEN] = {0};
1628 	struct pwrctrl_priv *pwrctl;
1629 	struct rtw_wdev_priv *pwdev_priv;
1630 
1631 	type = nla_type(data);
1632 	mac_len = nla_len(data);
1633 	if (mac_len != 3) {
1634 		RTW_ERR("%s oui len error %d != 3\n", __func__, mac_len);
1635 		return -1;
1636 	}
1637 
1638 	if (type == ANDR_WIFI_ATTRIBUTE_RANDOM_MAC_OUI) {
1639 		memcpy(pno_random_mac_oui, nla_data(data), 3);
1640 		print_hex_dump(KERN_DEBUG, "pno_random_mac_oui: ",
1641 			       DUMP_PREFIX_OFFSET, 16, 1, pno_random_mac_oui,
1642 			       3, 1);
1643 
1644 		if (ETHER_ISMULTI(pno_random_mac_oui)) {
1645 			pr_err("%s: oui is multicast address\n", __func__);
1646 			return -1;
1647 		}
1648 
1649 		adapter = wiphy_to_adapter(wiphy);
1650 		if (adapter == NULL) {
1651 			pr_err("%s: wiphy_to_adapter == NULL\n", __func__);
1652 			return -1;
1653 		}
1654 
1655 		pwdev_priv = adapter_wdev_data(adapter);
1656 
1657 		memcpy(mac_addr, pno_random_mac_oui, 3);
1658 		rtw_hal_random_gen_mac_addr(mac_addr);
1659 		memcpy(pwdev_priv->pno_mac_addr, mac_addr, ETH_ALEN);
1660 #ifdef CONFIG_RTW_DEBUG
1661 		print_hex_dump(KERN_DEBUG, "pno_mac_addr: ",
1662 			       DUMP_PREFIX_OFFSET, 16, 1, pwdev_priv->pno_mac_addr,
1663 			       ETH_ALEN, 1);
1664 #endif
1665 	} else {
1666 		RTW_ERR("%s oui type error %x != 0x2\n", __func__, type);
1667 		err = -1;
1668 	}
1669 
1670 
1671 	return err;
1672 }
1673 
1674 #endif
1675 
1676 #ifdef CONFIG_RTW_CFGVENDOR_WIFI_OFFLOAD
rtw_cfgvendor_start_mkeep_alive(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1677 static int rtw_cfgvendor_start_mkeep_alive(struct wiphy *wiphy, struct wireless_dev *wdev,
1678 	const void *data, int len)
1679 {
1680 	int ret = WIFI_SUCCESS;
1681 
1682 	RTW_INFO("%s : TODO\n", __func__);
1683 
1684 	return ret;
1685 }
1686 
rtw_cfgvendor_stop_mkeep_alive(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1687 static int rtw_cfgvendor_stop_mkeep_alive(struct wiphy *wiphy, struct wireless_dev *wdev,
1688 	const void *data, int len)
1689 {
1690 	int ret = WIFI_SUCCESS;
1691 
1692 	RTW_INFO("%s : TODO\n", __func__);
1693 
1694 	return ret;
1695 }
1696 #endif
1697 
rtw_cfgvendor_set_nodfs_flag(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1698 static int rtw_cfgvendor_set_nodfs_flag(struct wiphy *wiphy,
1699 	struct wireless_dev *wdev, const void *data, int len)
1700 {
1701 	int err = 0;
1702 	int type;
1703 	u32 nodfs = 0;
1704 	_adapter *padapter = GET_PRIMARY_ADAPTER(wiphy_to_adapter(wiphy));
1705 
1706 	RTW_DBG(FUNC_NDEV_FMT" %s\n", FUNC_NDEV_ARG(wdev_to_ndev(wdev)), (char*)data);
1707 
1708 	type = nla_type(data);
1709 	if (type == ANDR_WIFI_ATTRIBUTE_NODFS_SET) {
1710 		nodfs = nla_get_u32(data);
1711 		adapter_to_dvobj(padapter)->nodfs = nodfs;
1712 	} else {
1713 		err = -EINVAL;
1714 	}
1715 
1716 	RTW_INFO("%s nodfs=%d, err=%d\n", __func__, nodfs, err);
1717 
1718 	return err;
1719 }
1720 
rtw_cfgvendor_set_country(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1721 static int rtw_cfgvendor_set_country(struct wiphy *wiphy,
1722 	struct wireless_dev *wdev, const void  *data, int len)
1723 {
1724 #define CNTRY_BUF_SZ	4	/* Country string is 3 bytes + NUL */
1725 	int err = 0, rem, type;
1726 	char country_code[CNTRY_BUF_SZ] = {0};
1727 	const struct nlattr *iter;
1728 	_adapter *padapter = GET_PRIMARY_ADAPTER(wiphy_to_adapter(wiphy));
1729 
1730 	RTW_DBG(FUNC_NDEV_FMT" %s\n", FUNC_NDEV_ARG(wdev_to_ndev(wdev)), (char*)data);
1731 
1732 	nla_for_each_attr(iter, data, len, rem) {
1733 		type = nla_type(iter);
1734 		switch (type) {
1735 			case ANDR_WIFI_ATTRIBUTE_COUNTRY:
1736 				_rtw_memcpy(country_code, nla_data(iter),
1737 					MIN(nla_len(iter), CNTRY_BUF_SZ));
1738 				break;
1739 			default:
1740 				RTW_ERR("Unknown type: %d\n", type);
1741 				return -EINVAL;
1742 		}
1743 	}
1744 
1745 	RTW_INFO("%s country_code:\"%c%c\" \n", __func__, country_code[0], country_code[1]);
1746 
1747 	rtw_set_country(padapter, country_code);
1748 
1749 	return err;
1750 }
1751 
rtw_cfgvendor_set_nd_offload(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1752 static int rtw_cfgvendor_set_nd_offload(struct wiphy *wiphy,
1753 	struct wireless_dev *wdev, const void *data, int len)
1754 {
1755 	int err = 0;
1756 	int type;
1757 	u8 nd_en = 0;
1758 	_adapter *padapter = GET_PRIMARY_ADAPTER(wiphy_to_adapter(wiphy));
1759 
1760 	RTW_DBG(FUNC_NDEV_FMT" %s\n", FUNC_NDEV_ARG(wdev_to_ndev(wdev)), (char*)data);
1761 
1762 	type = nla_type(data);
1763 	if (type == ANDR_WIFI_ATTRIBUTE_ND_OFFLOAD_VALUE) {
1764 		nd_en = nla_get_u8(data);
1765 		/* ND has been enabled when wow is enabled */
1766 	} else {
1767 		err = -EINVAL;
1768 	}
1769 
1770 	RTW_INFO("%s nd_en=%d, err=%d\n", __func__, nd_en, err);
1771 
1772 	return err;
1773 }
1774 #endif /* CONFIG_RTW_WIFI_HAL */
1775 
1776 static const struct wiphy_vendor_command rtw_vendor_cmds[] = {
1777 #if defined(GSCAN_SUPPORT) && 0
1778 	{
1779 		{
1780 			.vendor_id = OUI_GOOGLE,
1781 			.subcmd = GSCAN_SUBCMD_GET_CAPABILITIES
1782 		},
1783 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1784 		.doit = rtw_cfgvendor_gscan_get_capabilities
1785 	},
1786 	{
1787 		{
1788 			.vendor_id = OUI_GOOGLE,
1789 			.subcmd = GSCAN_SUBCMD_SET_CONFIG
1790 		},
1791 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1792 		.doit = rtw_cfgvendor_set_scan_cfg
1793 	},
1794 	{
1795 		{
1796 			.vendor_id = OUI_GOOGLE,
1797 			.subcmd = GSCAN_SUBCMD_SET_SCAN_CONFIG
1798 		},
1799 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1800 		.doit = rtw_cfgvendor_set_batch_scan_cfg
1801 	},
1802 	{
1803 		{
1804 			.vendor_id = OUI_GOOGLE,
1805 			.subcmd = GSCAN_SUBCMD_ENABLE_GSCAN
1806 		},
1807 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1808 		.doit = rtw_cfgvendor_initiate_gscan
1809 	},
1810 	{
1811 		{
1812 			.vendor_id = OUI_GOOGLE,
1813 			.subcmd = GSCAN_SUBCMD_ENABLE_FULL_SCAN_RESULTS
1814 		},
1815 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1816 		.doit = rtw_cfgvendor_enable_full_scan_result
1817 	},
1818 	{
1819 		{
1820 			.vendor_id = OUI_GOOGLE,
1821 			.subcmd = GSCAN_SUBCMD_SET_HOTLIST
1822 		},
1823 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1824 		.doit = rtw_cfgvendor_hotlist_cfg
1825 	},
1826 	{
1827 		{
1828 			.vendor_id = OUI_GOOGLE,
1829 			.subcmd = GSCAN_SUBCMD_SET_SIGNIFICANT_CHANGE_CONFIG
1830 		},
1831 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1832 		.doit = rtw_cfgvendor_significant_change_cfg
1833 	},
1834 	{
1835 		{
1836 			.vendor_id = OUI_GOOGLE,
1837 			.subcmd = GSCAN_SUBCMD_GET_SCAN_RESULTS
1838 		},
1839 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1840 		.doit = rtw_cfgvendor_gscan_get_batch_results
1841 	},
1842 	{
1843 		{
1844 			.vendor_id = OUI_GOOGLE,
1845 			.subcmd = GSCAN_SUBCMD_GET_CHANNEL_LIST
1846 		},
1847 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1848 		.doit = rtw_cfgvendor_gscan_get_channel_list
1849 	},
1850 #endif /* GSCAN_SUPPORT */
1851 #if defined(RTT_SUPPORT) && 0
1852 	{
1853 		{
1854 			.vendor_id = OUI_GOOGLE,
1855 			.subcmd = RTT_SUBCMD_SET_CONFIG
1856 		},
1857 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1858 		.doit = rtw_cfgvendor_rtt_set_config
1859 	},
1860 	{
1861 		{
1862 			.vendor_id = OUI_GOOGLE,
1863 			.subcmd = RTT_SUBCMD_CANCEL_CONFIG
1864 		},
1865 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1866 		.doit = rtw_cfgvendor_rtt_cancel_config
1867 	},
1868 	{
1869 		{
1870 			.vendor_id = OUI_GOOGLE,
1871 			.subcmd = RTT_SUBCMD_GETCAPABILITY
1872 		},
1873 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1874 		.doit = rtw_cfgvendor_rtt_get_capability
1875 	},
1876 #endif /* RTT_SUPPORT */
1877 #ifdef CONFIG_RTW_CFGVENDOR_LLSTATS
1878 	{
1879 		{
1880 			.vendor_id = OUI_GOOGLE,
1881 			.subcmd = LSTATS_SUBCMD_GET_INFO
1882 		},
1883 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1884 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1885 		.policy = VENDOR_CMD_RAW_DATA,
1886 #endif
1887 		.doit = rtw_cfgvendor_lstats_get_info
1888 	},
1889 	{
1890 		{
1891 			.vendor_id = OUI_GOOGLE,
1892 			.subcmd = LSTATS_SUBCMD_SET_INFO
1893 		},
1894 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1895 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1896 		.policy = VENDOR_CMD_RAW_DATA,
1897 #endif
1898 		.doit = rtw_cfgvendor_lstats_set_info
1899 	},
1900 	{
1901 		{
1902 			.vendor_id = OUI_GOOGLE,
1903 			.subcmd = LSTATS_SUBCMD_CLEAR_INFO
1904 		},
1905 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1906 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1907 		.policy = VENDOR_CMD_RAW_DATA,
1908 #endif
1909 		.doit = rtw_cfgvendor_lstats_clear_info
1910 	},
1911 #endif /* CONFIG_RTW_CFGVENDOR_LLSTATS */
1912 #ifdef CONFIG_RTW_CFGVENDOR_RSSIMONITOR
1913         {
1914                 {
1915                         .vendor_id = OUI_GOOGLE,
1916                         .subcmd = WIFI_SUBCMD_SET_RSSI_MONITOR
1917                 },
1918                 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1919 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1920 		.policy = VENDOR_CMD_RAW_DATA,
1921 #endif
1922                 .doit = rtw_cfgvendor_set_rssi_monitor
1923         },
1924 #endif /* CONFIG_RTW_CFGVENDOR_RSSIMONITOR */
1925 #ifdef CONFIG_RTW_CFGVENDOR_WIFI_LOGGER
1926 	{
1927 		{
1928 			.vendor_id = OUI_GOOGLE,
1929 			.subcmd = LOGGER_START_LOGGING
1930 		},
1931 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1932 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1933 		.policy = VENDOR_CMD_RAW_DATA,
1934 #endif
1935 		.doit = rtw_cfgvendor_logger_start_logging
1936 	},
1937 	{
1938 		{
1939 			.vendor_id = OUI_GOOGLE,
1940 			.subcmd = LOGGER_GET_FEATURE
1941 		},
1942 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1943 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1944 		.policy = VENDOR_CMD_RAW_DATA,
1945 #endif
1946 		.doit = rtw_cfgvendor_logger_get_feature
1947 	},
1948 	{
1949 		{
1950 			.vendor_id = OUI_GOOGLE,
1951 			.subcmd = LOGGER_GET_VER
1952 		},
1953 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1954 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1955 		.policy = VENDOR_CMD_RAW_DATA,
1956 #endif
1957 		.doit = rtw_cfgvendor_logger_get_version
1958 	},
1959 	{
1960 		{
1961 			.vendor_id = OUI_GOOGLE,
1962 			.subcmd = LOGGER_GET_RING_STATUS
1963 		},
1964 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1965 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1966 		.policy = VENDOR_CMD_RAW_DATA,
1967 #endif
1968 		.doit = rtw_cfgvendor_logger_get_ring_status
1969 	},
1970 	{
1971 		{
1972 			.vendor_id = OUI_GOOGLE,
1973 			.subcmd = LOGGER_GET_RING_DATA
1974 		},
1975 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1976 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1977 		.policy = VENDOR_CMD_RAW_DATA,
1978 #endif
1979 		.doit = rtw_cfgvendor_logger_get_ring_data
1980 	},
1981 	{
1982 		{
1983 			.vendor_id = OUI_GOOGLE,
1984 			.subcmd = LOGGER_TRIGGER_MEM_DUMP
1985 		},
1986 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1987 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1988 		.policy = VENDOR_CMD_RAW_DATA,
1989 #endif
1990 		.doit = rtw_cfgvendor_logger_get_firmware_memory_dump
1991 	},
1992 	{
1993 		{
1994 			.vendor_id = OUI_GOOGLE,
1995 			.subcmd = LOGGER_START_PKT_FATE_MONITORING
1996 		},
1997 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1998 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1999 		.policy = VENDOR_CMD_RAW_DATA,
2000 #endif
2001 		.doit = rtw_cfgvendor_logger_start_pkt_fate_monitoring
2002 	},
2003 	{
2004 		{
2005 			.vendor_id = OUI_GOOGLE,
2006 			.subcmd = LOGGER_GET_TX_PKT_FATES
2007 		},
2008 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2009 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2010 		.policy = VENDOR_CMD_RAW_DATA,
2011 #endif
2012 		.doit = rtw_cfgvendor_logger_get_tx_pkt_fates
2013 	},
2014 	{
2015 		{
2016 			.vendor_id = OUI_GOOGLE,
2017 			.subcmd = LOGGER_GET_RX_PKT_FATES
2018 		},
2019 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2020 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2021 		.policy = VENDOR_CMD_RAW_DATA,
2022 #endif
2023 		.doit = rtw_cfgvendor_logger_get_rx_pkt_fates
2024 	},
2025 #endif /* CONFIG_RTW_CFGVENDOR_WIFI_LOGGER */
2026 #ifdef CONFIG_RTW_WIFI_HAL
2027 #ifdef CONFIG_RTW_CFGVENDOR_RANDOM_MAC_OUI
2028 	{
2029 		{
2030 			.vendor_id = OUI_GOOGLE,
2031 			.subcmd = WIFI_SUBCMD_SET_PNO_RANDOM_MAC_OUI
2032 		},
2033 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2034 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2035 		.policy = VENDOR_CMD_RAW_DATA,
2036 #endif
2037 		.doit = rtw_cfgvendor_set_rand_mac_oui
2038 	},
2039 #endif
2040 #ifdef CONFIG_RTW_CFGVENDOR_WIFI_OFFLOAD
2041 	{
2042 		{
2043 			.vendor_id = OUI_GOOGLE,
2044 			.subcmd = WIFI_OFFLOAD_SUBCMD_START_MKEEP_ALIVE
2045 		},
2046 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2047 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2048 		.policy = VENDOR_CMD_RAW_DATA,
2049 #endif
2050 		.doit = rtw_cfgvendor_start_mkeep_alive
2051 	},
2052 	{
2053 		{
2054 			.vendor_id = OUI_GOOGLE,
2055 			.subcmd = WIFI_OFFLOAD_SUBCMD_STOP_MKEEP_ALIVE
2056 		},
2057 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2058 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2059 		.policy = VENDOR_CMD_RAW_DATA,
2060 #endif
2061 		.doit = rtw_cfgvendor_stop_mkeep_alive
2062 	},
2063 #endif
2064 	{
2065 		{
2066 			.vendor_id = OUI_GOOGLE,
2067 			.subcmd = WIFI_SUBCMD_NODFS_SET
2068 		},
2069 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2070 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2071 		.policy = VENDOR_CMD_RAW_DATA,
2072 #endif
2073 		.doit = rtw_cfgvendor_set_nodfs_flag
2074 
2075 	},
2076 	{
2077 		{
2078 			.vendor_id = OUI_GOOGLE,
2079 			.subcmd = WIFI_SUBCMD_SET_COUNTRY_CODE
2080 		},
2081 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2082 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2083 		.policy = VENDOR_CMD_RAW_DATA,
2084 #endif
2085 		.doit = rtw_cfgvendor_set_country
2086 	},
2087 	{
2088 		{
2089 			.vendor_id = OUI_GOOGLE,
2090 			.subcmd = WIFI_SUBCMD_CONFIG_ND_OFFLOAD
2091 		},
2092 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2093 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2094 		.policy = VENDOR_CMD_RAW_DATA,
2095 #endif
2096 		.doit = rtw_cfgvendor_set_nd_offload
2097 	},
2098 #endif /* CONFIG_RTW_WIFI_HAL */
2099 	{
2100 		{
2101 			.vendor_id = OUI_GOOGLE,
2102 			.subcmd = WIFI_SUBCMD_GET_FEATURE_SET
2103 		},
2104 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2105 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2106 		.policy = VENDOR_CMD_RAW_DATA,
2107 #endif
2108 		.doit = rtw_cfgvendor_get_feature_set
2109 	},
2110 	{
2111 		{
2112 			.vendor_id = OUI_GOOGLE,
2113 			.subcmd = WIFI_SUBCMD_GET_FEATURE_SET_MATRIX
2114 		},
2115 		.flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2116 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2117 		.policy = VENDOR_CMD_RAW_DATA,
2118 #endif
2119 		.doit = rtw_cfgvendor_get_feature_set_matrix
2120 	}
2121 };
2122 
2123 static const struct  nl80211_vendor_cmd_info rtw_vendor_events[] = {
2124 #if defined(GSCAN_SUPPORT) && 0
2125 	{ OUI_GOOGLE, GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS },
2126 	{ OUI_GOOGLE, GSCAN_EVENT_HOTLIST_RESULTS_FOUND },
2127 	{ OUI_GOOGLE, GSCAN_EVENT_SCAN_RESULTS_AVAILABLE },
2128 	{ OUI_GOOGLE, GSCAN_EVENT_FULL_SCAN_RESULTS },
2129 #endif /* GSCAN_SUPPORT */
2130 #if defined(RTT_SUPPORT) && 0
2131 	{ OUI_GOOGLE, RTT_EVENT_COMPLETE },
2132 #endif /* RTT_SUPPORT */
2133 
2134 #ifdef CONFIG_RTW_CFGVENDOR_RSSIMONITOR
2135 	{ OUI_GOOGLE, GOOGLE_RSSI_MONITOR_EVENT },
2136 #endif /* RTW_CFGVENDOR_RSSIMONITR */
2137 
2138 #if defined(GSCAN_SUPPORT) && 0
2139 	{ OUI_GOOGLE, GSCAN_EVENT_COMPLETE_SCAN },
2140 	{ OUI_GOOGLE, GSCAN_EVENT_HOTLIST_RESULTS_LOST }
2141 #endif /* GSCAN_SUPPORT */
2142 };
2143 
rtw_cfgvendor_attach(struct wiphy * wiphy)2144 int rtw_cfgvendor_attach(struct wiphy *wiphy)
2145 {
2146 
2147 	RTW_INFO("Register RTW cfg80211 vendor cmd(0x%x) interface\n", NL80211_CMD_VENDOR);
2148 
2149 	wiphy->vendor_commands	= rtw_vendor_cmds;
2150 	wiphy->n_vendor_commands = ARRAY_SIZE(rtw_vendor_cmds);
2151 	wiphy->vendor_events	= rtw_vendor_events;
2152 	wiphy->n_vendor_events	= ARRAY_SIZE(rtw_vendor_events);
2153 
2154 	return 0;
2155 }
2156 
rtw_cfgvendor_detach(struct wiphy * wiphy)2157 int rtw_cfgvendor_detach(struct wiphy *wiphy)
2158 {
2159 	RTW_INFO("Vendor: Unregister RTW cfg80211 vendor interface\n");
2160 
2161 	wiphy->vendor_commands  = NULL;
2162 	wiphy->vendor_events    = NULL;
2163 	wiphy->n_vendor_commands = 0;
2164 	wiphy->n_vendor_events  = 0;
2165 
2166 	return 0;
2167 }
2168 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(RTW_VENDOR_EXT_SUPPORT) */
2169 
2170 #endif /* CONFIG_IOCTL_CFG80211 */
2171