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 #if defined(CONFIG_RTW_CFGVENDOR_RANDOM_MAC_OUI) || defined(CONFIG_RTW_SCAN_RAND)
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
1569 #ifdef CONFIG_RTW_WIFI_HAL
1570 #ifdef CONFIG_RTW_CFGVENDOR_RANDOM_MAC_OUI
1571
1572 #ifndef ETHER_ISMULTI
1573 #define ETHER_ISMULTI(ea) (((const u8 *)(ea))[0] & 1)
1574 #endif
1575
1576
1577 static u8 null_addr[ETH_ALEN] = {0};
rtw_hal_random_gen_mac_addr(u8 * mac_addr)1578 static void rtw_hal_random_gen_mac_addr(u8 *mac_addr)
1579 {
1580 do {
1581 get_random_bytes(&mac_addr[3], ETH_ALEN-3);
1582 if (memcmp(mac_addr, null_addr, ETH_ALEN) != 0)
1583 break;
1584 } while(1);
1585 }
1586
rtw_hal_pno_random_gen_mac_addr(PADAPTER adapter)1587 void rtw_hal_pno_random_gen_mac_addr(PADAPTER adapter)
1588 {
1589 u8 mac_addr[ETH_ALEN];
1590 struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter);
1591
1592 memcpy(mac_addr, pwdev_priv->pno_mac_addr, ETH_ALEN);
1593 if (mac_addr[0] == 0xFF) return;
1594 rtw_hal_random_gen_mac_addr(mac_addr);
1595 memcpy(pwdev_priv->pno_mac_addr, mac_addr, ETH_ALEN);
1596 #ifdef CONFIG_RTW_DEBUG
1597 print_hex_dump(KERN_DEBUG, "pno_mac_addr: ",
1598 DUMP_PREFIX_OFFSET, 16, 1, pwdev_priv->pno_mac_addr,
1599 ETH_ALEN, 1);
1600 #endif
1601 }
1602
1603
rtw_cfgvendor_set_rand_mac_oui(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1604 static int rtw_cfgvendor_set_rand_mac_oui(struct wiphy *wiphy,
1605 struct wireless_dev *wdev, const void *data, int len)
1606 {
1607 int err = 0;
1608 PADAPTER adapter;
1609 void *devaddr;
1610 struct net_device *netdev;
1611 int type, mac_len;
1612 u8 pno_random_mac_oui[3];
1613 u8 mac_addr[ETH_ALEN] = {0};
1614 struct pwrctrl_priv *pwrctl;
1615 struct rtw_wdev_priv *pwdev_priv;
1616
1617 type = nla_type(data);
1618 mac_len = nla_len(data);
1619 if (mac_len != 3) {
1620 RTW_ERR("%s oui len error %d != 3\n", __func__, mac_len);
1621 return -1;
1622 }
1623
1624 if (type == ANDR_WIFI_ATTRIBUTE_RANDOM_MAC_OUI) {
1625 memcpy(pno_random_mac_oui, nla_data(data), 3);
1626 print_hex_dump(KERN_DEBUG, "pno_random_mac_oui: ",
1627 DUMP_PREFIX_OFFSET, 16, 1, pno_random_mac_oui,
1628 3, 1);
1629
1630 if (ETHER_ISMULTI(pno_random_mac_oui)) {
1631 pr_err("%s: oui is multicast address\n", __func__);
1632 return -1;
1633 }
1634
1635 adapter = wiphy_to_adapter(wiphy);
1636 if (adapter == NULL) {
1637 pr_err("%s: wiphy_to_adapter == NULL\n", __func__);
1638 return -1;
1639 }
1640
1641 pwdev_priv = adapter_wdev_data(adapter);
1642
1643 memcpy(mac_addr, pno_random_mac_oui, 3);
1644 rtw_hal_random_gen_mac_addr(mac_addr);
1645 memcpy(pwdev_priv->pno_mac_addr, mac_addr, ETH_ALEN);
1646 #ifdef CONFIG_RTW_DEBUG
1647 print_hex_dump(KERN_DEBUG, "pno_mac_addr: ",
1648 DUMP_PREFIX_OFFSET, 16, 1, pwdev_priv->pno_mac_addr,
1649 ETH_ALEN, 1);
1650 #endif
1651 } else {
1652 RTW_ERR("%s oui type error %x != 0x2\n", __func__, type);
1653 err = -1;
1654 }
1655
1656
1657 return err;
1658 }
1659 #endif
1660
1661 #ifdef CONFIG_RTW_CFGVENDOR_WIFI_OFFLOAD
rtw_cfgvendor_start_mkeep_alive(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1662 static int rtw_cfgvendor_start_mkeep_alive(struct wiphy *wiphy, struct wireless_dev *wdev,
1663 const void *data, int len)
1664 {
1665 int ret = WIFI_SUCCESS;
1666
1667 RTW_INFO("%s : TODO\n", __func__);
1668
1669 return ret;
1670 }
1671
rtw_cfgvendor_stop_mkeep_alive(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1672 static int rtw_cfgvendor_stop_mkeep_alive(struct wiphy *wiphy, struct wireless_dev *wdev,
1673 const void *data, int len)
1674 {
1675 int ret = WIFI_SUCCESS;
1676
1677 RTW_INFO("%s : TODO\n", __func__);
1678
1679 return ret;
1680 }
1681 #endif
1682
rtw_cfgvendor_set_nodfs_flag(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1683 static int rtw_cfgvendor_set_nodfs_flag(struct wiphy *wiphy,
1684 struct wireless_dev *wdev, const void *data, int len)
1685 {
1686 int err = 0;
1687 int type;
1688 u32 nodfs = 0;
1689 _adapter *padapter = GET_PRIMARY_ADAPTER(wiphy_to_adapter(wiphy));
1690
1691 RTW_DBG(FUNC_NDEV_FMT" %s\n", FUNC_NDEV_ARG(wdev_to_ndev(wdev)), (char*)data);
1692
1693 type = nla_type(data);
1694 if (type == ANDR_WIFI_ATTRIBUTE_NODFS_SET) {
1695 nodfs = nla_get_u32(data);
1696 adapter_to_dvobj(padapter)->nodfs = nodfs;
1697 } else {
1698 err = -EINVAL;
1699 }
1700
1701 RTW_INFO("%s nodfs=%d, err=%d\n", __func__, nodfs, err);
1702
1703 return err;
1704 }
1705
rtw_cfgvendor_set_country(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1706 static int rtw_cfgvendor_set_country(struct wiphy *wiphy,
1707 struct wireless_dev *wdev, const void *data, int len)
1708 {
1709 #define CNTRY_BUF_SZ 4 /* Country string is 3 bytes + NUL */
1710 int err = 0, rem, type;
1711 char country_code[CNTRY_BUF_SZ] = {0};
1712 const struct nlattr *iter;
1713 _adapter *padapter = GET_PRIMARY_ADAPTER(wiphy_to_adapter(wiphy));
1714
1715 RTW_DBG(FUNC_NDEV_FMT" %s\n", FUNC_NDEV_ARG(wdev_to_ndev(wdev)), (char*)data);
1716
1717 nla_for_each_attr(iter, data, len, rem) {
1718 type = nla_type(iter);
1719 switch (type) {
1720 case ANDR_WIFI_ATTRIBUTE_COUNTRY:
1721 _rtw_memcpy(country_code, nla_data(iter),
1722 MIN(nla_len(iter), CNTRY_BUF_SZ));
1723 break;
1724 default:
1725 RTW_ERR("Unknown type: %d\n", type);
1726 return -EINVAL;
1727 }
1728 }
1729
1730 RTW_INFO("%s country_code:\"%c%c\" \n", __func__, country_code[0], country_code[1]);
1731
1732 rtw_set_country(padapter, country_code, RTW_REGD_SET_BY_USER);
1733
1734 return err;
1735 }
1736
rtw_cfgvendor_set_nd_offload(struct wiphy * wiphy,struct wireless_dev * wdev,const void * data,int len)1737 static int rtw_cfgvendor_set_nd_offload(struct wiphy *wiphy,
1738 struct wireless_dev *wdev, const void *data, int len)
1739 {
1740 int err = 0;
1741 int type;
1742 u8 nd_en = 0;
1743 _adapter *padapter = GET_PRIMARY_ADAPTER(wiphy_to_adapter(wiphy));
1744
1745 RTW_DBG(FUNC_NDEV_FMT" %s\n", FUNC_NDEV_ARG(wdev_to_ndev(wdev)), (char*)data);
1746
1747 type = nla_type(data);
1748 if (type == ANDR_WIFI_ATTRIBUTE_ND_OFFLOAD_VALUE) {
1749 nd_en = nla_get_u8(data);
1750 /* ND has been enabled when wow is enabled */
1751 } else {
1752 err = -EINVAL;
1753 }
1754
1755 RTW_INFO("%s nd_en=%d, err=%d\n", __func__, nd_en, err);
1756
1757 return err;
1758 }
1759 #endif /* CONFIG_RTW_WIFI_HAL */
1760
1761 static const struct wiphy_vendor_command rtw_vendor_cmds[] = {
1762 #if defined(GSCAN_SUPPORT) && 0
1763 {
1764 {
1765 .vendor_id = OUI_GOOGLE,
1766 .subcmd = GSCAN_SUBCMD_GET_CAPABILITIES
1767 },
1768 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1769 .doit = rtw_cfgvendor_gscan_get_capabilities
1770 },
1771 {
1772 {
1773 .vendor_id = OUI_GOOGLE,
1774 .subcmd = GSCAN_SUBCMD_SET_CONFIG
1775 },
1776 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1777 .doit = rtw_cfgvendor_set_scan_cfg
1778 },
1779 {
1780 {
1781 .vendor_id = OUI_GOOGLE,
1782 .subcmd = GSCAN_SUBCMD_SET_SCAN_CONFIG
1783 },
1784 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1785 .doit = rtw_cfgvendor_set_batch_scan_cfg
1786 },
1787 {
1788 {
1789 .vendor_id = OUI_GOOGLE,
1790 .subcmd = GSCAN_SUBCMD_ENABLE_GSCAN
1791 },
1792 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1793 .doit = rtw_cfgvendor_initiate_gscan
1794 },
1795 {
1796 {
1797 .vendor_id = OUI_GOOGLE,
1798 .subcmd = GSCAN_SUBCMD_ENABLE_FULL_SCAN_RESULTS
1799 },
1800 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1801 .doit = rtw_cfgvendor_enable_full_scan_result
1802 },
1803 {
1804 {
1805 .vendor_id = OUI_GOOGLE,
1806 .subcmd = GSCAN_SUBCMD_SET_HOTLIST
1807 },
1808 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1809 .doit = rtw_cfgvendor_hotlist_cfg
1810 },
1811 {
1812 {
1813 .vendor_id = OUI_GOOGLE,
1814 .subcmd = GSCAN_SUBCMD_SET_SIGNIFICANT_CHANGE_CONFIG
1815 },
1816 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1817 .doit = rtw_cfgvendor_significant_change_cfg
1818 },
1819 {
1820 {
1821 .vendor_id = OUI_GOOGLE,
1822 .subcmd = GSCAN_SUBCMD_GET_SCAN_RESULTS
1823 },
1824 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1825 .doit = rtw_cfgvendor_gscan_get_batch_results
1826 },
1827 {
1828 {
1829 .vendor_id = OUI_GOOGLE,
1830 .subcmd = GSCAN_SUBCMD_GET_CHANNEL_LIST
1831 },
1832 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1833 .doit = rtw_cfgvendor_gscan_get_channel_list
1834 },
1835 #endif /* GSCAN_SUPPORT */
1836 #if defined(RTT_SUPPORT) && 0
1837 {
1838 {
1839 .vendor_id = OUI_GOOGLE,
1840 .subcmd = RTT_SUBCMD_SET_CONFIG
1841 },
1842 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1843 .doit = rtw_cfgvendor_rtt_set_config
1844 },
1845 {
1846 {
1847 .vendor_id = OUI_GOOGLE,
1848 .subcmd = RTT_SUBCMD_CANCEL_CONFIG
1849 },
1850 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1851 .doit = rtw_cfgvendor_rtt_cancel_config
1852 },
1853 {
1854 {
1855 .vendor_id = OUI_GOOGLE,
1856 .subcmd = RTT_SUBCMD_GETCAPABILITY
1857 },
1858 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1859 .doit = rtw_cfgvendor_rtt_get_capability
1860 },
1861 #endif /* RTT_SUPPORT */
1862 #ifdef CONFIG_RTW_CFGVENDOR_LLSTATS
1863 {
1864 {
1865 .vendor_id = OUI_GOOGLE,
1866 .subcmd = LSTATS_SUBCMD_GET_INFO
1867 },
1868 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1869 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1870 .policy = VENDOR_CMD_RAW_DATA,
1871 #endif
1872 .doit = rtw_cfgvendor_lstats_get_info
1873 },
1874 {
1875 {
1876 .vendor_id = OUI_GOOGLE,
1877 .subcmd = LSTATS_SUBCMD_SET_INFO
1878 },
1879 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1880 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1881 .policy = VENDOR_CMD_RAW_DATA,
1882 #endif
1883 .doit = rtw_cfgvendor_lstats_set_info
1884 },
1885 {
1886 {
1887 .vendor_id = OUI_GOOGLE,
1888 .subcmd = LSTATS_SUBCMD_CLEAR_INFO
1889 },
1890 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1891 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1892 .policy = VENDOR_CMD_RAW_DATA,
1893 #endif
1894 .doit = rtw_cfgvendor_lstats_clear_info
1895 },
1896 #endif /* CONFIG_RTW_CFGVENDOR_LLSTATS */
1897 #ifdef CONFIG_RTW_CFGVENDOR_RSSIMONITOR
1898 {
1899 {
1900 .vendor_id = OUI_GOOGLE,
1901 .subcmd = WIFI_SUBCMD_SET_RSSI_MONITOR
1902 },
1903 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1904 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1905 .policy = VENDOR_CMD_RAW_DATA,
1906 #endif
1907 .doit = rtw_cfgvendor_set_rssi_monitor
1908 },
1909 #endif /* CONFIG_RTW_CFGVENDOR_RSSIMONITOR */
1910 #ifdef CONFIG_RTW_CFGVENDOR_WIFI_LOGGER
1911 {
1912 {
1913 .vendor_id = OUI_GOOGLE,
1914 .subcmd = LOGGER_START_LOGGING
1915 },
1916 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1917 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1918 .policy = VENDOR_CMD_RAW_DATA,
1919 #endif
1920 .doit = rtw_cfgvendor_logger_start_logging
1921 },
1922 {
1923 {
1924 .vendor_id = OUI_GOOGLE,
1925 .subcmd = LOGGER_GET_FEATURE
1926 },
1927 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1928 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1929 .policy = VENDOR_CMD_RAW_DATA,
1930 #endif
1931 .doit = rtw_cfgvendor_logger_get_feature
1932 },
1933 {
1934 {
1935 .vendor_id = OUI_GOOGLE,
1936 .subcmd = LOGGER_GET_VER
1937 },
1938 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1939 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1940 .policy = VENDOR_CMD_RAW_DATA,
1941 #endif
1942 .doit = rtw_cfgvendor_logger_get_version
1943 },
1944 {
1945 {
1946 .vendor_id = OUI_GOOGLE,
1947 .subcmd = LOGGER_GET_RING_STATUS
1948 },
1949 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1950 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1951 .policy = VENDOR_CMD_RAW_DATA,
1952 #endif
1953 .doit = rtw_cfgvendor_logger_get_ring_status
1954 },
1955 {
1956 {
1957 .vendor_id = OUI_GOOGLE,
1958 .subcmd = LOGGER_GET_RING_DATA
1959 },
1960 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1961 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1962 .policy = VENDOR_CMD_RAW_DATA,
1963 #endif
1964 .doit = rtw_cfgvendor_logger_get_ring_data
1965 },
1966 {
1967 {
1968 .vendor_id = OUI_GOOGLE,
1969 .subcmd = LOGGER_TRIGGER_MEM_DUMP
1970 },
1971 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1972 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1973 .policy = VENDOR_CMD_RAW_DATA,
1974 #endif
1975 .doit = rtw_cfgvendor_logger_get_firmware_memory_dump
1976 },
1977 {
1978 {
1979 .vendor_id = OUI_GOOGLE,
1980 .subcmd = LOGGER_START_PKT_FATE_MONITORING
1981 },
1982 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1983 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1984 .policy = VENDOR_CMD_RAW_DATA,
1985 #endif
1986 .doit = rtw_cfgvendor_logger_start_pkt_fate_monitoring
1987 },
1988 {
1989 {
1990 .vendor_id = OUI_GOOGLE,
1991 .subcmd = LOGGER_GET_TX_PKT_FATES
1992 },
1993 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
1994 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
1995 .policy = VENDOR_CMD_RAW_DATA,
1996 #endif
1997 .doit = rtw_cfgvendor_logger_get_tx_pkt_fates
1998 },
1999 {
2000 {
2001 .vendor_id = OUI_GOOGLE,
2002 .subcmd = LOGGER_GET_RX_PKT_FATES
2003 },
2004 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2005 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2006 .policy = VENDOR_CMD_RAW_DATA,
2007 #endif
2008 .doit = rtw_cfgvendor_logger_get_rx_pkt_fates
2009 },
2010 #endif /* CONFIG_RTW_CFGVENDOR_WIFI_LOGGER */
2011 #ifdef CONFIG_RTW_WIFI_HAL
2012 #ifdef CONFIG_RTW_CFGVENDOR_RANDOM_MAC_OUI
2013 {
2014 {
2015 .vendor_id = OUI_GOOGLE,
2016 .subcmd = WIFI_SUBCMD_SET_PNO_RANDOM_MAC_OUI
2017 },
2018 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2019 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2020 .policy = VENDOR_CMD_RAW_DATA,
2021 #endif
2022 .doit = rtw_cfgvendor_set_rand_mac_oui
2023 },
2024 #endif
2025 #ifdef CONFIG_RTW_CFGVENDOR_WIFI_OFFLOAD
2026 {
2027 {
2028 .vendor_id = OUI_GOOGLE,
2029 .subcmd = WIFI_OFFLOAD_SUBCMD_START_MKEEP_ALIVE
2030 },
2031 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2032 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2033 .policy = VENDOR_CMD_RAW_DATA,
2034 #endif
2035 .doit = rtw_cfgvendor_start_mkeep_alive
2036 },
2037 {
2038 {
2039 .vendor_id = OUI_GOOGLE,
2040 .subcmd = WIFI_OFFLOAD_SUBCMD_STOP_MKEEP_ALIVE
2041 },
2042 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2043 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2044 .policy = VENDOR_CMD_RAW_DATA,
2045 #endif
2046 .doit = rtw_cfgvendor_stop_mkeep_alive
2047 },
2048 #endif
2049 {
2050 {
2051 .vendor_id = OUI_GOOGLE,
2052 .subcmd = WIFI_SUBCMD_NODFS_SET
2053 },
2054 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2055 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2056 .policy = VENDOR_CMD_RAW_DATA,
2057 #endif
2058 .doit = rtw_cfgvendor_set_nodfs_flag
2059
2060 },
2061 {
2062 {
2063 .vendor_id = OUI_GOOGLE,
2064 .subcmd = WIFI_SUBCMD_SET_COUNTRY_CODE
2065 },
2066 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2067 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2068 .policy = VENDOR_CMD_RAW_DATA,
2069 #endif
2070 .doit = rtw_cfgvendor_set_country
2071 },
2072 {
2073 {
2074 .vendor_id = OUI_GOOGLE,
2075 .subcmd = WIFI_SUBCMD_CONFIG_ND_OFFLOAD
2076 },
2077 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2078 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2079 .policy = VENDOR_CMD_RAW_DATA,
2080 #endif
2081 .doit = rtw_cfgvendor_set_nd_offload
2082 },
2083 #endif /* CONFIG_RTW_WIFI_HAL */
2084 {
2085 {
2086 .vendor_id = OUI_GOOGLE,
2087 .subcmd = WIFI_SUBCMD_GET_FEATURE_SET
2088 },
2089 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2090 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2091 .policy = VENDOR_CMD_RAW_DATA,
2092 #endif
2093 .doit = rtw_cfgvendor_get_feature_set
2094 },
2095 {
2096 {
2097 .vendor_id = OUI_GOOGLE,
2098 .subcmd = WIFI_SUBCMD_GET_FEATURE_SET_MATRIX
2099 },
2100 .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
2101 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
2102 .policy = VENDOR_CMD_RAW_DATA,
2103 #endif
2104 .doit = rtw_cfgvendor_get_feature_set_matrix
2105 }
2106 };
2107
2108 static const struct nl80211_vendor_cmd_info rtw_vendor_events[] = {
2109 #if defined(GSCAN_SUPPORT) && 0
2110 { OUI_GOOGLE, GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS },
2111 { OUI_GOOGLE, GSCAN_EVENT_HOTLIST_RESULTS_FOUND },
2112 { OUI_GOOGLE, GSCAN_EVENT_SCAN_RESULTS_AVAILABLE },
2113 { OUI_GOOGLE, GSCAN_EVENT_FULL_SCAN_RESULTS },
2114 #endif /* GSCAN_SUPPORT */
2115 #if defined(RTT_SUPPORT) && 0
2116 { OUI_GOOGLE, RTT_EVENT_COMPLETE },
2117 #endif /* RTT_SUPPORT */
2118
2119 #ifdef CONFIG_RTW_CFGVENDOR_RSSIMONITOR
2120 { OUI_GOOGLE, GOOGLE_RSSI_MONITOR_EVENT },
2121 #endif /* RTW_CFGVENDOR_RSSIMONITR */
2122
2123 #if defined(GSCAN_SUPPORT) && 0
2124 { OUI_GOOGLE, GSCAN_EVENT_COMPLETE_SCAN },
2125 { OUI_GOOGLE, GSCAN_EVENT_HOTLIST_RESULTS_LOST }
2126 #endif /* GSCAN_SUPPORT */
2127 };
2128
rtw_cfgvendor_attach(struct wiphy * wiphy)2129 int rtw_cfgvendor_attach(struct wiphy *wiphy)
2130 {
2131
2132 RTW_INFO("Register RTW cfg80211 vendor cmd(0x%x) interface\n", NL80211_CMD_VENDOR);
2133
2134 wiphy->vendor_commands = rtw_vendor_cmds;
2135 wiphy->n_vendor_commands = ARRAY_SIZE(rtw_vendor_cmds);
2136 wiphy->vendor_events = rtw_vendor_events;
2137 wiphy->n_vendor_events = ARRAY_SIZE(rtw_vendor_events);
2138
2139 return 0;
2140 }
2141
rtw_cfgvendor_detach(struct wiphy * wiphy)2142 int rtw_cfgvendor_detach(struct wiphy *wiphy)
2143 {
2144 RTW_INFO("Vendor: Unregister RTW cfg80211 vendor interface\n");
2145
2146 wiphy->vendor_commands = NULL;
2147 wiphy->vendor_events = NULL;
2148 wiphy->n_vendor_commands = 0;
2149 wiphy->n_vendor_events = 0;
2150
2151 return 0;
2152 }
2153 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(RTW_VENDOR_EXT_SUPPORT) */
2154
2155 #endif /* CONFIG_IOCTL_CFG80211 */
2156