wifi: fix reboot panic issue
[GitHub/LineageOS/G12/android_hardware_amlogic_kernel-modules_dhd-driver.git] / bcmdhd.1.363.59.144.x.cn / dhd_pno.h
1 /*
2 * Header file of Broadcom Dongle Host Driver (DHD)
3 * Prefered Network Offload code and Wi-Fi Location Service(WLS) code.
4 *
5 * Copyright (C) 1999-2016, Broadcom Corporation
6 *
7 * Unless you and Broadcom execute a separate written software license
8 * agreement governing use of this software, this software is licensed to you
9 * under the terms of the GNU General Public License version 2 (the "GPL"),
10 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
11 * following added to such license:
12 *
13 * As a special exception, the copyright holders of this software give you
14 * permission to link this software with independent modules, and to copy and
15 * distribute the resulting executable under terms of your choice, provided that
16 * you also meet, for each linked independent module, the terms and conditions of
17 * the license of that module. An independent module is a module which is not
18 * derived from this software. The special exception does not apply to any
19 * modifications of the software.
20 *
21 * Notwithstanding the above, under no circumstances may you combine this
22 * software in any way with any other Broadcom software provided under a license
23 * other than the GPL, without Broadcom's express prior written consent.
24 *
25 *
26 * <<Broadcom-WL-IPTag/Open:>>
27 *
28 * $Id: dhd_pno.h 591285 2015-10-07 11:56:29Z $
29 */
30
31 #ifndef __DHD_PNO_H__
32 #define __DHD_PNO_H__
33
34 #if defined(PNO_SUPPORT)
35 #define PNO_TLV_PREFIX 'S'
36 #define PNO_TLV_VERSION '1'
37 #define PNO_TLV_SUBTYPE_LEGACY_PNO '2'
38 #define PNO_TLV_RESERVED '0'
39 #define PNO_BATCHING_SET "SET"
40 #define PNO_BATCHING_GET "GET"
41 #define PNO_BATCHING_STOP "STOP"
42 #define PNO_PARAMS_DELIMETER " "
43 #define PNO_PARAM_CHANNEL_DELIMETER ","
44 #define PNO_PARAM_VALUE_DELLIMETER '='
45 #define PNO_PARAM_SCANFREQ "SCANFREQ"
46 #define PNO_PARAM_BESTN "BESTN"
47 #define PNO_PARAM_MSCAN "MSCAN"
48 #define PNO_PARAM_CHANNEL "CHANNEL"
49 #define PNO_PARAM_RTT "RTT"
50
51 #define PNO_TLV_TYPE_SSID_IE 'S'
52 #define PNO_TLV_TYPE_TIME 'T'
53 #define PNO_TLV_FREQ_REPEAT 'R'
54 #define PNO_TLV_FREQ_EXPO_MAX 'M'
55
56 #define MAXNUM_SSID_PER_ADD 16
57 #define MAXNUM_PNO_PARAMS 2
58 #define PNO_TLV_COMMON_LENGTH 1
59 #define DEFAULT_BATCH_MSCAN 16
60
61 #define RESULTS_END_MARKER "----\n"
62 #define SCAN_END_MARKER "####\n"
63 #define AP_END_MARKER "====\n"
64 #define PNO_RSSI_MARGIN_DBM 30
65
66 #ifdef GSCAN_SUPPORT
67
68 #define GSCAN_MAX_CH_BUCKETS 8
69 #define GSCAN_BG_BAND_MASK (1 << 0)
70 #define GSCAN_A_BAND_MASK (1 << 1)
71 #define GSCAN_DFS_MASK (1 << 2)
72 #define GSCAN_ABG_BAND_MASK (GSCAN_A_BAND_MASK | GSCAN_BG_BAND_MASK)
73 #define GSCAN_BAND_MASK (GSCAN_ABG_BAND_MASK | GSCAN_DFS_MASK)
74
75 #define GSCAN_FLUSH_HOTLIST_CFG (1 << 0)
76 #define GSCAN_FLUSH_SIGNIFICANT_CFG (1 << 1)
77 #define GSCAN_FLUSH_SCAN_CFG (1 << 2)
78 #define GSCAN_FLUSH_ALL_CFG (GSCAN_FLUSH_SCAN_CFG | \
79 GSCAN_FLUSH_SIGNIFICANT_CFG | \
80 GSCAN_FLUSH_HOTLIST_CFG)
81 /* Do not change GSCAN_BATCH_RETRIEVAL_COMPLETE */
82 #define GSCAN_BATCH_RETRIEVAL_COMPLETE 0
83 #define GSCAN_BATCH_RETRIEVAL_IN_PROGRESS 1
84 #define GSCAN_BATCH_NO_THR_SET 101
85 #define GSCAN_LOST_AP_WINDOW_DEFAULT 4
86 #define GSCAN_MIN_BSSID_TIMEOUT 90
87 #define GSCAN_BATCH_GET_MAX_WAIT 500
88 #define CHANNEL_BUCKET_EMPTY_INDEX 0xFFFF
89 #define GSCAN_RETRY_THRESHOLD 3
90 #endif /* GSCAN_SUPPORT */
91
92 enum scan_status {
93 /* SCAN ABORT by other scan */
94 PNO_STATUS_ABORT,
95 /* RTT is presence or not */
96 PNO_STATUS_RTT_PRESENCE,
97 /* Disable PNO by Driver */
98 PNO_STATUS_DISABLE,
99 /* NORMAL BATCHING GET */
100 PNO_STATUS_NORMAL,
101 /* WLC_E_PFN_BEST_BATCHING */
102 PNO_STATUS_EVENT,
103 PNO_STATUS_MAX
104 };
105 #define PNO_STATUS_ABORT_MASK 0x0001
106 #define PNO_STATUS_RTT_MASK 0x0002
107 #define PNO_STATUS_DISABLE_MASK 0x0004
108 #define PNO_STATUS_OOM_MASK 0x0010
109
110 enum index_mode {
111 INDEX_OF_LEGACY_PARAMS,
112 INDEX_OF_BATCH_PARAMS,
113 INDEX_OF_HOTLIST_PARAMS,
114 /* GSCAN includes hotlist scan and they do not run
115 * independent of each other
116 */
117 #ifdef GSCAN_SUPPORT
118 INDEX_OF_GSCAN_PARAMS = INDEX_OF_HOTLIST_PARAMS,
119 #endif /* GSCAN_SUPPORT */
120 INDEX_MODE_MAX
121 };
122 enum dhd_pno_status {
123 DHD_PNO_DISABLED,
124 DHD_PNO_ENABLED,
125 DHD_PNO_SUSPEND
126 };
127 typedef struct cmd_tlv {
128 char prefix;
129 char version;
130 char subtype;
131 char reserved;
132 } cmd_tlv_t;
133 #ifdef GSCAN_SUPPORT
134 typedef enum {
135 WIFI_BAND_UNSPECIFIED,
136 WIFI_BAND_BG = 1, /* 2.4 GHz */
137 WIFI_BAND_A = 2, /* 5 GHz without DFS */
138 WIFI_BAND_A_DFS = 4, /* 5 GHz DFS only */
139 WIFI_BAND_A_WITH_DFS = 6, /* 5 GHz with DFS */
140 WIFI_BAND_ABG = 3, /* 2.4 GHz + 5 GHz; no DFS */
141 WIFI_BAND_ABG_WITH_DFS = 7, /* 2.4 GHz + 5 GHz with DFS */
142 } gscan_wifi_band_t;
143
144 typedef enum {
145 HOTLIST_LOST,
146 HOTLIST_FOUND
147 } hotlist_type_t;
148
149 typedef enum dhd_pno_gscan_cmd_cfg {
150 DHD_PNO_BATCH_SCAN_CFG_ID,
151 DHD_PNO_GEOFENCE_SCAN_CFG_ID,
152 DHD_PNO_SIGNIFICANT_SCAN_CFG_ID,
153 DHD_PNO_SCAN_CFG_ID,
154 DHD_PNO_GET_CAPABILITIES,
155 DHD_PNO_GET_BATCH_RESULTS,
156 DHD_PNO_GET_CHANNEL_LIST
157 } dhd_pno_gscan_cmd_cfg_t;
158
159 typedef enum dhd_pno_mode {
160 /* Wi-Fi Legacy PNO Mode */
161 DHD_PNO_NONE_MODE = 0,
162 DHD_PNO_LEGACY_MODE = (1 << (0)),
163 /* Wi-Fi Android BATCH SCAN Mode */
164 DHD_PNO_BATCH_MODE = (1 << (1)),
165 /* Wi-Fi Android Hotlist SCAN Mode */
166 DHD_PNO_HOTLIST_MODE = (1 << (2)),
167 /* Wi-Fi Google Android SCAN Mode */
168 DHD_PNO_GSCAN_MODE = (1 << (3))
169 } dhd_pno_mode_t;
170 #else
171 typedef enum dhd_pno_mode {
172 /* Wi-Fi Legacy PNO Mode */
173 DHD_PNO_NONE_MODE = 0,
174 DHD_PNO_LEGACY_MODE = (1 << (0)),
175 /* Wi-Fi Android BATCH SCAN Mode */
176 DHD_PNO_BATCH_MODE = (1 << (1)),
177 /* Wi-Fi Android Hotlist SCAN Mode */
178 DHD_PNO_HOTLIST_MODE = (1 << (2))
179 } dhd_pno_mode_t;
180 #endif /* GSCAN_SUPPORT */
181 struct dhd_pno_ssid {
182 bool hidden;
183 uint32 SSID_len;
184 uchar SSID[DOT11_MAX_SSID_LEN];
185 struct list_head list;
186 };
187 struct dhd_pno_bssid {
188 struct ether_addr macaddr;
189 /* Bit4: suppress_lost, Bit3: suppress_found */
190 uint16 flags;
191 struct list_head list;
192 };
193 typedef struct dhd_pno_bestnet_entry {
194 struct ether_addr BSSID;
195 uint8 SSID_len;
196 uint8 SSID[DOT11_MAX_SSID_LEN];
197 int8 RSSI;
198 uint8 channel;
199 uint32 timestamp;
200 uint16 rtt0; /* distance_cm based on RTT */
201 uint16 rtt1; /* distance_cm based on sample standard deviation */
202 unsigned long recorded_time;
203 struct list_head list;
204 } dhd_pno_bestnet_entry_t;
205 #define BESTNET_ENTRY_SIZE (sizeof(dhd_pno_bestnet_entry_t))
206
207 typedef struct dhd_pno_bestnet_header {
208 struct dhd_pno_bestnet_header *next;
209 uint8 reason;
210 uint32 tot_cnt;
211 uint32 tot_size;
212 struct list_head entry_list;
213 } dhd_pno_best_header_t;
214 #define BEST_HEADER_SIZE (sizeof(dhd_pno_best_header_t))
215
216 typedef struct dhd_pno_scan_results {
217 dhd_pno_best_header_t *bestnetheader;
218 uint8 cnt_header;
219 struct list_head list;
220 } dhd_pno_scan_results_t;
221 #define SCAN_RESULTS_SIZE (sizeof(dhd_pno_scan_results_t))
222
223 struct dhd_pno_get_batch_info {
224 /* info related to get batch */
225 char *buf;
226 bool batch_started;
227 uint32 tot_scan_cnt;
228 uint32 expired_tot_scan_cnt;
229 uint32 top_node_cnt;
230 uint32 bufsize;
231 uint32 bytes_written;
232 int reason;
233 struct list_head scan_results_list;
234 struct list_head expired_scan_results_list;
235 };
236 struct dhd_pno_legacy_params {
237 uint16 scan_fr;
238 uint16 chan_list[WL_NUMCHANNELS];
239 uint16 nchan;
240 int pno_repeat;
241 int pno_freq_expo_max;
242 int nssid;
243 struct list_head ssid_list;
244 };
245 struct dhd_pno_batch_params {
246 int32 scan_fr;
247 uint8 bestn;
248 uint8 mscan;
249 uint8 band;
250 uint16 chan_list[WL_NUMCHANNELS];
251 uint16 nchan;
252 uint16 rtt;
253 struct dhd_pno_get_batch_info get_batch;
254 };
255 struct dhd_pno_hotlist_params {
256 uint8 band;
257 int32 scan_fr;
258 uint16 chan_list[WL_NUMCHANNELS];
259 uint16 nchan;
260 uint16 nbssid;
261 struct list_head bssid_list;
262 };
263 #ifdef GSCAN_SUPPORT
264 typedef struct dhd_pno_gscan_channel_bucket {
265 uint16 bucket_freq_multiple;
266 /* band = 1 All bg band channels,
267 * band = 2 All a band channels,
268 * band = 0 chan_list channels
269 */
270 uint16 band;
271 uint8 report_flag;
272 uint8 num_channels;
273 uint16 chan_list[GSCAN_MAX_CH_BUCKETS];
274 } dhd_pno_gscan_channel_bucket_t;
275
276 typedef struct dhd_pno_swc_evt_param {
277 uint16 results_rxed_so_far;
278 wl_pfn_significant_net_t *change_array;
279 } dhd_pno_swc_evt_param_t;
280
281 typedef struct wifi_gscan_result {
282 uint64 ts; /* Time of discovery */
283 char ssid[DOT11_MAX_SSID_LEN+1]; /* null terminated */
284 struct ether_addr macaddr; /* BSSID */
285 uint32 channel; /* channel frequency in MHz */
286 int32 rssi; /* in db */
287 uint64 rtt; /* in nanoseconds */
288 uint64 rtt_sd; /* standard deviation in rtt */
289 uint16 beacon_period; /* units are Kusec */
290 uint16 capability; /* Capability information */
291 uint32 ie_length; /* byte length of Information Elements */
292 char ie_data[1]; /* IE data to follow */
293 } wifi_gscan_result_t;
294
295 typedef struct gscan_results_cache {
296 struct gscan_results_cache *next;
297 uint8 scan_id;
298 uint8 flag;
299 uint8 tot_count;
300 uint8 tot_consumed;
301 wifi_gscan_result_t results[1];
302 } gscan_results_cache_t;
303
304 typedef struct dhd_pno_gscan_capabilities {
305 int max_scan_cache_size;
306 int max_scan_buckets;
307 int max_ap_cache_per_scan;
308 int max_rssi_sample_size;
309 int max_scan_reporting_threshold;
310 int max_hotlist_aps;
311 int max_significant_wifi_change_aps;
312 } dhd_pno_gscan_capabilities_t;
313
314 struct dhd_pno_gscan_params {
315 int32 scan_fr;
316 uint8 bestn;
317 uint8 mscan;
318 uint8 buffer_threshold;
319 uint8 swc_nbssid_threshold;
320 uint8 swc_rssi_window_size;
321 uint8 lost_ap_window;
322 uint8 nchannel_buckets;
323 uint8 reason;
324 uint8 get_batch_flag;
325 uint8 send_all_results_flag;
326 uint16 max_ch_bucket_freq;
327 gscan_results_cache_t *gscan_batch_cache;
328 gscan_results_cache_t *gscan_hotlist_found;
329 gscan_results_cache_t *gscan_hotlist_lost;
330 uint16 nbssid_significant_change;
331 uint16 nbssid_hotlist;
332 struct dhd_pno_swc_evt_param param_significant;
333 struct dhd_pno_gscan_channel_bucket channel_bucket[GSCAN_MAX_CH_BUCKETS];
334 struct list_head hotlist_bssid_list;
335 struct list_head significant_bssid_list;
336 };
337
338 typedef struct gscan_scan_params {
339 int32 scan_fr;
340 uint16 nchannel_buckets;
341 struct dhd_pno_gscan_channel_bucket channel_bucket[GSCAN_MAX_CH_BUCKETS];
342 } gscan_scan_params_t;
343
344 typedef struct gscan_batch_params {
345 uint8 bestn;
346 uint8 mscan;
347 uint8 buffer_threshold;
348 } gscan_batch_params_t;
349
350 struct bssid_t {
351 struct ether_addr macaddr;
352 int16 rssi_reporting_threshold; /* 0 -> no reporting threshold */
353 };
354
355 typedef struct gscan_hotlist_scan_params {
356 uint16 lost_ap_window; /* number of scans to declare LOST */
357 uint16 nbssid; /* number of bssids */
358 struct bssid_t bssid[1]; /* n bssids to follow */
359 } gscan_hotlist_scan_params_t;
360
361 /* SWC (Significant WiFi Change) params */
362 typedef struct gscan_swc_params {
363 /* Rssi averaging window size */
364 uint8 rssi_window;
365 /* Number of scans that the AP has to be absent before
366 * being declared LOST
367 */
368 uint8 lost_ap_window;
369 /* if x Aps have a significant change generate an event. */
370 uint8 swc_threshold;
371 uint8 nbssid;
372 wl_pfn_significant_bssid_t bssid_elem_list[1];
373 } gscan_swc_params_t;
374
375 typedef struct dhd_pno_significant_bssid {
376 struct ether_addr BSSID;
377 int8 rssi_low_threshold;
378 int8 rssi_high_threshold;
379 struct list_head list;
380 } dhd_pno_significant_bssid_t;
381 #endif /* GSCAN_SUPPORT */
382 typedef union dhd_pno_params {
383 struct dhd_pno_legacy_params params_legacy;
384 struct dhd_pno_batch_params params_batch;
385 struct dhd_pno_hotlist_params params_hotlist;
386 #ifdef GSCAN_SUPPORT
387 struct dhd_pno_gscan_params params_gscan;
388 #endif /* GSCAN_SUPPORT */
389 } dhd_pno_params_t;
390 typedef struct dhd_pno_status_info {
391 uint8 pno_oui[DOT11_OUI_LEN];
392 dhd_pub_t *dhd;
393 struct work_struct work;
394 struct mutex pno_mutex;
395 #ifdef GSCAN_SUPPORT
396 wait_queue_head_t batch_get_wait;
397 #endif /* GSCAN_SUPPORT */
398 struct completion get_batch_done;
399 bool wls_supported; /* wifi location service supported or not */
400 enum dhd_pno_status pno_status;
401 enum dhd_pno_mode pno_mode;
402 dhd_pno_params_t pno_params_arr[INDEX_MODE_MAX];
403 struct list_head head_list;
404 } dhd_pno_status_info_t;
405
406 /* wrapper functions */
407 extern int
408 dhd_dev_pno_enable(struct net_device *dev, int enable);
409
410 extern int
411 dhd_dev_pno_stop_for_ssid(struct net_device *dev);
412
413 extern int
414 dhd_dev_pno_set_for_ssid(struct net_device *dev, wlc_ssid_ext_t* ssids_local, int nssid,
415 uint16 scan_fr, int pno_repeat, int pno_freq_expo_max, uint16 *channel_list, int nchan);
416
417 extern int
418 dhd_dev_pno_set_for_batch(struct net_device *dev,
419 struct dhd_pno_batch_params *batch_params);
420
421 extern int
422 dhd_dev_pno_get_for_batch(struct net_device *dev, char *buf, int bufsize);
423
424 extern int
425 dhd_dev_pno_stop_for_batch(struct net_device *dev);
426
427 extern int
428 dhd_dev_pno_set_for_hotlist(struct net_device *dev, wl_pfn_bssid_t *p_pfn_bssid,
429 struct dhd_pno_hotlist_params *hotlist_params);
430 extern int dhd_dev_pno_set_mac_oui(struct net_device *dev, uint8 *oui);
431 #ifdef GSCAN_SUPPORT
432 extern int
433 dhd_dev_pno_set_cfg_gscan(struct net_device *dev, dhd_pno_gscan_cmd_cfg_t type,
434 void *buf, uint8 flush);
435 extern void *
436 dhd_dev_pno_get_gscan(struct net_device *dev, dhd_pno_gscan_cmd_cfg_t type, void *info,
437 uint32 *len);
438 void dhd_dev_pno_lock_access_batch_results(struct net_device *dev);
439 void dhd_dev_pno_unlock_access_batch_results(struct net_device *dev);
440 extern int dhd_dev_pno_run_gscan(struct net_device *dev, bool run, bool flush);
441 extern int dhd_dev_pno_enable_full_scan_result(struct net_device *dev, bool real_time);
442 extern void * dhd_dev_swc_scan_event(struct net_device *dev, const void *data,
443 int *send_evt_bytes);
444 int dhd_retreive_batch_scan_results(dhd_pub_t *dhd);
445 extern void * dhd_dev_hotlist_scan_event(struct net_device *dev,
446 const void *data, int *send_evt_bytes, hotlist_type_t type);
447 void * dhd_dev_process_full_gscan_result(struct net_device *dev,
448 const void *data, int *send_evt_bytes);
449 extern int dhd_dev_gscan_batch_cache_cleanup(struct net_device *dev);
450 extern void dhd_dev_gscan_hotlist_cache_cleanup(struct net_device *dev, hotlist_type_t type);
451 extern void dhd_dev_wait_batch_results_complete(struct net_device *dev);
452 #endif /* GSCAN_SUPPORT */
453 /* dhd pno fuctions */
454 extern int dhd_pno_stop_for_ssid(dhd_pub_t *dhd);
455 extern int dhd_pno_enable(dhd_pub_t *dhd, int enable);
456 extern int dhd_pno_set_for_ssid(dhd_pub_t *dhd, wlc_ssid_ext_t* ssid_list, int nssid,
457 uint16 scan_fr, int pno_repeat, int pno_freq_expo_max, uint16 *channel_list, int nchan);
458
459 extern int dhd_pno_set_for_batch(dhd_pub_t *dhd, struct dhd_pno_batch_params *batch_params);
460
461 extern int dhd_pno_get_for_batch(dhd_pub_t *dhd, char *buf, int bufsize, int reason);
462
463
464 extern int dhd_pno_stop_for_batch(dhd_pub_t *dhd);
465
466 extern int dhd_pno_set_for_hotlist(dhd_pub_t *dhd, wl_pfn_bssid_t *p_pfn_bssid,
467 struct dhd_pno_hotlist_params *hotlist_params);
468
469 extern int dhd_pno_stop_for_hotlist(dhd_pub_t *dhd);
470
471 extern int dhd_pno_event_handler(dhd_pub_t *dhd, wl_event_msg_t *event, void *event_data);
472 extern int dhd_pno_init(dhd_pub_t *dhd);
473 extern int dhd_pno_deinit(dhd_pub_t *dhd);
474 extern bool dhd_is_pno_supported(dhd_pub_t *dhd);
475 extern int dhd_pno_set_mac_oui(dhd_pub_t *dhd, uint8 *oui);
476 #ifdef GSCAN_SUPPORT
477 extern int dhd_pno_set_cfg_gscan(dhd_pub_t *dhd, dhd_pno_gscan_cmd_cfg_t type,
478 void *buf, uint8 flush);
479 extern void * dhd_pno_get_gscan(dhd_pub_t *dhd, dhd_pno_gscan_cmd_cfg_t type, void *info,
480 uint32 *len);
481 extern void dhd_pno_lock_batch_results(dhd_pub_t *dhd);
482 extern void dhd_pno_unlock_batch_results(dhd_pub_t *dhd);
483 extern int dhd_pno_initiate_gscan_request(dhd_pub_t *dhd, bool run, bool flush);
484 extern int dhd_pno_enable_full_scan_result(dhd_pub_t *dhd, bool real_time_flag);
485 extern int dhd_pno_cfg_gscan(dhd_pub_t *dhd, dhd_pno_gscan_cmd_cfg_t type, void *buf);
486 extern int dhd_dev_retrieve_batch_scan(struct net_device *dev);
487 extern void *dhd_handle_swc_evt(dhd_pub_t *dhd, const void *event_data, int *send_evt_bytes);
488 extern void *dhd_handle_hotlist_scan_evt(dhd_pub_t *dhd, const void *event_data,
489 int *send_evt_bytes, hotlist_type_t type);
490 extern void *dhd_process_full_gscan_result(dhd_pub_t *dhd, const void *event_data,
491 int *send_evt_bytes);
492 extern int dhd_gscan_batch_cache_cleanup(dhd_pub_t *dhd);
493 extern void dhd_gscan_hotlist_cache_cleanup(dhd_pub_t *dhd, hotlist_type_t type);
494 extern void dhd_wait_batch_results_complete(dhd_pub_t *dhd);
495 #endif /* GSCAN_SUPPORT */
496 #endif
497
498 #endif /* __DHD_PNO_H__ */