hc
2024-05-08 f309769f8af08599af39b6de4f675784ce76530d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/******************************************************************************
 *
 * Copyright(c) 2007 - 2017 Realtek Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 *****************************************************************************/
 
#ifndef _RTW_CFGVENDOR_H_
#define _RTW_CFGVENDOR_H_
 
#define OUI_GOOGLE  0x001A11
#define ATTRIBUTE_U32_LEN                  (NLA_HDRLEN  + 4)
#define VENDOR_ID_OVERHEAD                 ATTRIBUTE_U32_LEN
#define VENDOR_SUBCMD_OVERHEAD             ATTRIBUTE_U32_LEN
#define VENDOR_DATA_OVERHEAD               (NLA_HDRLEN)
 
#define SCAN_RESULTS_COMPLETE_FLAG_LEN       ATTRIBUTE_U32_LEN
#define SCAN_INDEX_HDR_LEN                   (NLA_HDRLEN)
#define SCAN_ID_HDR_LEN                      ATTRIBUTE_U32_LEN
#define SCAN_FLAGS_HDR_LEN                   ATTRIBUTE_U32_LEN
#define GSCAN_NUM_RESULTS_HDR_LEN            ATTRIBUTE_U32_LEN
#define GSCAN_RESULTS_HDR_LEN                (NLA_HDRLEN)
#define GSCAN_BATCH_RESULT_HDR_LEN  (SCAN_INDEX_HDR_LEN + SCAN_ID_HDR_LEN + \
                    SCAN_FLAGS_HDR_LEN + \
                    GSCAN_NUM_RESULTS_HDR_LEN + \
                    GSCAN_RESULTS_HDR_LEN)
 
#define VENDOR_REPLY_OVERHEAD       (VENDOR_ID_OVERHEAD + \
                    VENDOR_SUBCMD_OVERHEAD + \
                    VENDOR_DATA_OVERHEAD)
typedef enum {
    /* don't use 0 as a valid subcommand */
    VENDOR_NL80211_SUBCMD_UNSPECIFIED,
 
    /* define all vendor startup commands between 0x0 and 0x0FFF */
    VENDOR_NL80211_SUBCMD_RANGE_START = 0x0001,
    VENDOR_NL80211_SUBCMD_RANGE_END   = 0x0FFF,
 
    /* define all GScan related commands between 0x1000 and 0x10FF */
    ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START = 0x1000,
    ANDROID_NL80211_SUBCMD_GSCAN_RANGE_END   = 0x10FF,
 
    /* define all NearbyDiscovery related commands between 0x1100 and 0x11FF */
    ANDROID_NL80211_SUBCMD_NBD_RANGE_START = 0x1100,
    ANDROID_NL80211_SUBCMD_NBD_RANGE_END   = 0x11FF,
 
    /* define all RTT related commands between 0x1100 and 0x11FF */
    ANDROID_NL80211_SUBCMD_RTT_RANGE_START = 0x1100,
    ANDROID_NL80211_SUBCMD_RTT_RANGE_END   = 0x11FF,
 
    ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START = 0x1200,
    ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END   = 0x12FF,
 
    /* define all Logger related commands between 0x1400 and 0x14FF */
    ANDROID_NL80211_SUBCMD_DEBUG_RANGE_START = 0x1400,
    ANDROID_NL80211_SUBCMD_DEBUG_RANGE_END   = 0x14FF,
 
    /* define all wifi offload related commands between 0x1600 and 0x16FF */
    ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_START = 0x1600,
    ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_END   = 0x16FF,
 
    /* define all NAN related commands between 0x1700 and 0x17FF */
    ANDROID_NL80211_SUBCMD_NAN_RANGE_START = 0x1700,
    ANDROID_NL80211_SUBCMD_NAN_RANGE_END   = 0x17FF,
 
    /* define all Android Packet Filter related commands between 0x1800 and 0x18FF */
    ANDROID_NL80211_SUBCMD_PKT_FILTER_RANGE_START = 0x1800,
    ANDROID_NL80211_SUBCMD_PKT_FILTER_RANGE_END   = 0x18FF,
 
    /* This is reserved for future usage */
 
} ANDROID_VENDOR_SUB_COMMAND;
 
enum rtw_vendor_subcmd {
    GSCAN_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START,
 
    GSCAN_SUBCMD_SET_CONFIG,                            /* 0x1001 */
 
    GSCAN_SUBCMD_SET_SCAN_CONFIG,                       /* 0x1002 */
    GSCAN_SUBCMD_ENABLE_GSCAN,                          /* 0x1003 */
    GSCAN_SUBCMD_GET_SCAN_RESULTS,                      /* 0x1004 */
    GSCAN_SUBCMD_SCAN_RESULTS,                          /* 0x1005 */
 
    GSCAN_SUBCMD_SET_HOTLIST,                           /* 0x1006 */
 
    GSCAN_SUBCMD_SET_SIGNIFICANT_CHANGE_CONFIG,         /* 0x1007 */
    GSCAN_SUBCMD_ENABLE_FULL_SCAN_RESULTS,              /* 0x1008 */
    GSCAN_SUBCMD_GET_CHANNEL_LIST,                       /* 0x1009 */
 
    WIFI_SUBCMD_GET_FEATURE_SET,                         /* 0x100A */
    WIFI_SUBCMD_GET_FEATURE_SET_MATRIX,                  /* 0x100B */
    WIFI_SUBCMD_SET_PNO_RANDOM_MAC_OUI,                  /* 0x100C */
    WIFI_SUBCMD_NODFS_SET,                               /* 0x100D */
    WIFI_SUBCMD_SET_COUNTRY_CODE,                             /* 0x100E */
    /* Add more sub commands here */
    GSCAN_SUBCMD_SET_EPNO_SSID,                          /* 0x100F */
 
    WIFI_SUBCMD_SET_SSID_WHITE_LIST,                    /* 0x1010 */
    WIFI_SUBCMD_SET_ROAM_PARAMS,                        /* 0x1011 */
    WIFI_SUBCMD_ENABLE_LAZY_ROAM,                       /* 0x1012 */
    WIFI_SUBCMD_SET_BSSID_PREF,                         /* 0x1013 */
    WIFI_SUBCMD_SET_BSSID_BLACKLIST,                     /* 0x1014 */
 
    GSCAN_SUBCMD_ANQPO_CONFIG,                          /* 0x1015 */
    WIFI_SUBCMD_SET_RSSI_MONITOR,                       /* 0x1016 */
    WIFI_SUBCMD_CONFIG_ND_OFFLOAD,                      /* 0x1017 */
    /* Add more sub commands here */
 
    GSCAN_SUBCMD_MAX,
 
   RTT_SUBCMD_SET_CONFIG = ANDROID_NL80211_SUBCMD_RTT_RANGE_START,
   RTT_SUBCMD_CANCEL_CONFIG,
   RTT_SUBCMD_GETCAPABILITY,
 
    APF_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_PKT_FILTER_RANGE_START,
    APF_SUBCMD_SET_FILTER,
    
    LOGGER_START_LOGGING = ANDROID_NL80211_SUBCMD_DEBUG_RANGE_START,
    LOGGER_TRIGGER_MEM_DUMP,
    LOGGER_GET_MEM_DUMP,
    LOGGER_GET_VER,
    LOGGER_GET_RING_STATUS,
    LOGGER_GET_RING_DATA,
    LOGGER_GET_FEATURE,
    LOGGER_RESET_LOGGING,
    LOGGER_TRIGGER_DRIVER_MEM_DUMP,
    LOGGER_GET_DRIVER_MEM_DUMP,
    LOGGER_START_PKT_FATE_MONITORING,
    LOGGER_GET_TX_PKT_FATES,
    LOGGER_GET_RX_PKT_FATES,
 
   WIFI_OFFLOAD_SUBCMD_START_MKEEP_ALIVE = ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_START,
   WIFI_OFFLOAD_SUBCMD_STOP_MKEEP_ALIVE,
 
   VENDOR_SUBCMD_MAX
};
 
enum gscan_attributes {
   GSCAN_ATTRIBUTE_NUM_BUCKETS = 10,
   GSCAN_ATTRIBUTE_BASE_PERIOD,
   GSCAN_ATTRIBUTE_BUCKETS_BAND,
   GSCAN_ATTRIBUTE_BUCKET_ID,
   GSCAN_ATTRIBUTE_BUCKET_PERIOD,
   GSCAN_ATTRIBUTE_BUCKET_NUM_CHANNELS,
   GSCAN_ATTRIBUTE_BUCKET_CHANNELS,
   GSCAN_ATTRIBUTE_NUM_AP_PER_SCAN,
   GSCAN_ATTRIBUTE_REPORT_THRESHOLD,
   GSCAN_ATTRIBUTE_NUM_SCANS_TO_CACHE,
   GSCAN_ATTRIBUTE_BAND = GSCAN_ATTRIBUTE_BUCKETS_BAND,
 
   GSCAN_ATTRIBUTE_ENABLE_FEATURE = 20,
   GSCAN_ATTRIBUTE_SCAN_RESULTS_COMPLETE,
   GSCAN_ATTRIBUTE_FLUSH_FEATURE,
   GSCAN_ATTRIBUTE_ENABLE_FULL_SCAN_RESULTS,
   GSCAN_ATTRIBUTE_REPORT_EVENTS,
   /* remaining reserved for additional attributes */
   GSCAN_ATTRIBUTE_NUM_OF_RESULTS = 30,
   GSCAN_ATTRIBUTE_FLUSH_RESULTS,
   GSCAN_ATTRIBUTE_SCAN_RESULTS,                       /* flat array of wifi_scan_result */
   GSCAN_ATTRIBUTE_SCAN_ID,                            /* indicates scan number */
   GSCAN_ATTRIBUTE_SCAN_FLAGS,                         /* indicates if scan was aborted */
   GSCAN_ATTRIBUTE_AP_FLAGS,                           /* flags on significant change event */
   GSCAN_ATTRIBUTE_NUM_CHANNELS,
   GSCAN_ATTRIBUTE_CHANNEL_LIST,
 
   /* remaining reserved for additional attributes */
 
   GSCAN_ATTRIBUTE_SSID = 40,
   GSCAN_ATTRIBUTE_BSSID,
   GSCAN_ATTRIBUTE_CHANNEL,
   GSCAN_ATTRIBUTE_RSSI,
   GSCAN_ATTRIBUTE_TIMESTAMP,
   GSCAN_ATTRIBUTE_RTT,
   GSCAN_ATTRIBUTE_RTTSD,
 
   /* remaining reserved for additional attributes */
 
   GSCAN_ATTRIBUTE_HOTLIST_BSSIDS = 50,
   GSCAN_ATTRIBUTE_RSSI_LOW,
   GSCAN_ATTRIBUTE_RSSI_HIGH,
   GSCAN_ATTRIBUTE_HOSTLIST_BSSID_ELEM,
   GSCAN_ATTRIBUTE_HOTLIST_FLUSH,
 
   /* remaining reserved for additional attributes */
   GSCAN_ATTRIBUTE_RSSI_SAMPLE_SIZE = 60,
   GSCAN_ATTRIBUTE_LOST_AP_SAMPLE_SIZE,
   GSCAN_ATTRIBUTE_MIN_BREACHING,
   GSCAN_ATTRIBUTE_SIGNIFICANT_CHANGE_BSSIDS,
   GSCAN_ATTRIBUTE_SIGNIFICANT_CHANGE_FLUSH,
   GSCAN_ATTRIBUTE_MAX
};
 
enum gscan_bucket_attributes {
   GSCAN_ATTRIBUTE_CH_BUCKET_1,
   GSCAN_ATTRIBUTE_CH_BUCKET_2,
   GSCAN_ATTRIBUTE_CH_BUCKET_3,
   GSCAN_ATTRIBUTE_CH_BUCKET_4,
   GSCAN_ATTRIBUTE_CH_BUCKET_5,
   GSCAN_ATTRIBUTE_CH_BUCKET_6,
   GSCAN_ATTRIBUTE_CH_BUCKET_7
};
 
enum gscan_ch_attributes {
   GSCAN_ATTRIBUTE_CH_ID_1,
   GSCAN_ATTRIBUTE_CH_ID_2,
   GSCAN_ATTRIBUTE_CH_ID_3,
   GSCAN_ATTRIBUTE_CH_ID_4,
   GSCAN_ATTRIBUTE_CH_ID_5,
   GSCAN_ATTRIBUTE_CH_ID_6,
   GSCAN_ATTRIBUTE_CH_ID_7
};
 
enum wifi_rssi_monitor_attr {
        RSSI_MONITOR_ATTRIBUTE_MAX_RSSI,
        RSSI_MONITOR_ATTRIBUTE_MIN_RSSI,
        RSSI_MONITOR_ATTRIBUTE_START,
};
 
 
enum rtt_attributes {
   RTT_ATTRIBUTE_TARGET_CNT,
   RTT_ATTRIBUTE_TARGET_INFO,
   RTT_ATTRIBUTE_TARGET_MAC,
   RTT_ATTRIBUTE_TARGET_TYPE,
   RTT_ATTRIBUTE_TARGET_PEER,
   RTT_ATTRIBUTE_TARGET_CHAN,
   RTT_ATTRIBUTE_TARGET_MODE,
   RTT_ATTRIBUTE_TARGET_INTERVAL,
   RTT_ATTRIBUTE_TARGET_NUM_MEASUREMENT,
   RTT_ATTRIBUTE_TARGET_NUM_PKT,
   RTT_ATTRIBUTE_TARGET_NUM_RETRY
};
 
enum logger_attributes {
   LOGGER_ATTRIBUTE_GET_DRIVER,
   LOGGER_ATTRIBUTE_GET_FW,
   LOGGER_ATTRIBUTE_RING_ID,
   LOGGER_ATTRIBUTE_RING_NAME,
   LOGGER_ATTRIBUTE_RING_FLAGS,
   LOGGER_ATTRIBUTE_LOG_LEVEL,
   LOGGER_ATTRIBUTE_LOG_TIME_INTVAL,
   LOGGER_ATTRIBUTE_LOG_MIN_DATA_SIZE,
   LOGGER_ATTRIBUTE_FW_DUMP_LEN,
   LOGGER_ATTRIBUTE_FW_DUMP_DATA,
   LOGGERG_ATTRIBUTE_RING_DATA,
   LOGGER_ATTRIBUTE_RING_STATUS,
   LOGGER_ATTRIBUTE_RING_NUM
};
typedef enum rtw_vendor_event {
    RTK_RESERVED1,
    RTK_RESERVED2,
    GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS ,
    GSCAN_EVENT_HOTLIST_RESULTS_FOUND,
    GSCAN_EVENT_SCAN_RESULTS_AVAILABLE,
    GSCAN_EVENT_FULL_SCAN_RESULTS,
    RTT_EVENT_COMPLETE,
    GSCAN_EVENT_COMPLETE_SCAN,
    GSCAN_EVENT_HOTLIST_RESULTS_LOST,
    GSCAN_EVENT_EPNO_EVENT,
    GOOGLE_DEBUG_RING_EVENT,
    GOOGLE_DEBUG_MEM_DUMP_EVENT,
    GSCAN_EVENT_ANQPO_HOTSPOT_MATCH,
    GOOGLE_RSSI_MONITOR_EVENT
} rtw_vendor_event_t;
 
enum andr_wifi_feature_set_attr {
   ANDR_WIFI_ATTRIBUTE_NUM_FEATURE_SET,
   ANDR_WIFI_ATTRIBUTE_FEATURE_SET,
   ANDR_WIFI_ATTRIBUTE_RANDOM_MAC_OUI,
   ANDR_WIFI_ATTRIBUTE_NODFS_SET,
   ANDR_WIFI_ATTRIBUTE_COUNTRY,
   ANDR_WIFI_ATTRIBUTE_ND_OFFLOAD_VALUE
   // Add more attribute here
};
 
typedef enum rtw_vendor_gscan_attribute {
   ATTR_START_GSCAN,
   ATTR_STOP_GSCAN,
   ATTR_SET_SCAN_BATCH_CFG_ID, /* set batch scan params */
   ATTR_SET_SCAN_GEOFENCE_CFG_ID, /* set list of bssids to track */
   ATTR_SET_SCAN_SIGNIFICANT_CFG_ID, /* set list of bssids, rssi threshold etc.. */
   ATTR_SET_SCAN_CFG_ID, /* set common scan config params here */
   ATTR_GET_GSCAN_CAPABILITIES_ID,
   /* Add more sub commands here */
   ATTR_GSCAN_MAX
} rtw_vendor_gscan_attribute_t;
 
typedef enum gscan_batch_attribute {
   ATTR_GSCAN_BATCH_BESTN,
   ATTR_GSCAN_BATCH_MSCAN,
   ATTR_GSCAN_BATCH_BUFFER_THRESHOLD
} gscan_batch_attribute_t;
 
typedef enum gscan_geofence_attribute {
   ATTR_GSCAN_NUM_HOTLIST_BSSID,
   ATTR_GSCAN_HOTLIST_BSSID
} gscan_geofence_attribute_t;
 
typedef enum gscan_complete_event {
   WIFI_SCAN_BUFFER_FULL,
   WIFI_SCAN_COMPLETE
} gscan_complete_event_t;
/* wifi_hal.h */
/* WiFi Common definitions */
typedef unsigned char byte;
typedef int wifi_request_id;
typedef int wifi_channel;                       // indicates channel frequency in MHz
typedef int wifi_rssi;
typedef byte mac_addr[6];
typedef byte oui[3];
typedef int64_t wifi_timestamp;                 // In microseconds (us)
typedef int64_t wifi_timespan;                  // In picoseconds  (ps)
 
struct wifi_info;
struct wifi_interface_info;
typedef struct wifi_info *wifi_handle;
typedef struct wifi_interface_info *wifi_interface_handle;
 
/* channel operating width */
typedef enum {
    WIFI_CHAN_WIDTH_20    = 0,
    WIFI_CHAN_WIDTH_40    = 1,
    WIFI_CHAN_WIDTH_80    = 2,
    WIFI_CHAN_WIDTH_160   = 3,
    WIFI_CHAN_WIDTH_80P80 = 4,
    WIFI_CHAN_WIDTH_5     = 5,
    WIFI_CHAN_WIDTH_10    = 6,
    WIFI_CHAN_WIDTH_INVALID = -1
} wifi_channel_width;
 
typedef int wifi_radio;
 
typedef struct {
    wifi_channel_width width;
    int center_frequency0;
    int center_frequency1;
    int primary_frequency;
} wifi_channel_spec;
 
typedef enum {
    WIFI_SUCCESS = 0,
    WIFI_ERROR_NONE = 0,
    WIFI_ERROR_UNKNOWN = -1,
    WIFI_ERROR_UNINITIALIZED = -2,
    WIFI_ERROR_NOT_SUPPORTED = -3,
    WIFI_ERROR_NOT_AVAILABLE = -4,              // Not available right now, but try later
    WIFI_ERROR_INVALID_ARGS = -5,
    WIFI_ERROR_INVALID_REQUEST_ID = -6,
    WIFI_ERROR_TIMED_OUT = -7,
    WIFI_ERROR_TOO_MANY_REQUESTS = -8,          // Too many instances of this request
    WIFI_ERROR_OUT_OF_MEMORY = -9,
    WIFI_ERROR_BUSY = -10,
} wifi_error;
 
typedef int wifi_ring_buffer_id;
/* ring buffer params */
/**
 * written_bytes and read_bytes implement a producer consumer API
 *     hence written_bytes >= read_bytes
 * a modulo arithmetic of the buffer size has to be applied to those counters:
 * actual offset into ring buffer = written_bytes % ring_buffer_byte_size
 *
 */
typedef struct {
    u8 name[32];
    u32 flags;
    wifi_ring_buffer_id ring_id; // unique integer representing the ring
    u32 ring_buffer_byte_size;   // total memory size allocated for the buffer
    u32 verbose_level;           // verbose level for ring buffer
    u32 written_bytes;           // number of bytes that was written to the buffer by driver,
                                 // monotonously increasing integer
    u32 read_bytes;              // number of bytes that was read from the buffer by user land,
                                 // monotonously increasing integer
    u32 written_records;         // number of records that was written to the buffer by driver,
                                 // monotonously increasing integer
} wifi_ring_buffer_status;
 
#ifdef CONFIG_RTW_CFGVENDOR_LLSTATS
#define STATS_MAJOR_VERSION      1
#define STATS_MINOR_VERSION      0
#define STATS_MICRO_VERSION      0
 
typedef enum {
    WIFI_DISCONNECTED = 0,
    WIFI_AUTHENTICATING = 1,
    WIFI_ASSOCIATING = 2,
    WIFI_ASSOCIATED = 3,
    WIFI_EAPOL_STARTED = 4,   // if done by firmware/driver
    WIFI_EAPOL_COMPLETED = 5, // if done by firmware/driver
} wifi_connection_state;
 
typedef enum {
    WIFI_ROAMING_IDLE = 0,
    WIFI_ROAMING_ACTIVE = 1,
} wifi_roam_state;
 
typedef enum {
    WIFI_INTERFACE_STA = 0,
    WIFI_INTERFACE_SOFTAP = 1,
    WIFI_INTERFACE_IBSS = 2,
    WIFI_INTERFACE_P2P_CLIENT = 3,
    WIFI_INTERFACE_P2P_GO = 4,
    WIFI_INTERFACE_NAN = 5,
    WIFI_INTERFACE_MESH = 6,
    WIFI_INTERFACE_UNKNOWN = -1
 } wifi_interface_mode;
 
#define WIFI_CAPABILITY_QOS          0x00000001     // set for QOS association
#define WIFI_CAPABILITY_PROTECTED    0x00000002     // set for protected association (802.11 beacon frame control protected bit set)
#define WIFI_CAPABILITY_INTERWORKING 0x00000004     // set if 802.11 Extended Capabilities element interworking bit is set
#define WIFI_CAPABILITY_HS20         0x00000008     // set for HS20 association
#define WIFI_CAPABILITY_SSID_UTF8    0x00000010     // set is 802.11 Extended Capabilities element UTF-8 SSID bit is set
#define WIFI_CAPABILITY_COUNTRY      0x00000020     // set is 802.11 Country Element is present
 
typedef struct {
   wifi_interface_mode mode;     // interface mode
   u8 mac_addr[6];               // interface mac address (self)
   wifi_connection_state state;  // connection state (valid for STA, CLI only)
   wifi_roam_state roaming;      // roaming state
   u32 capabilities;             // WIFI_CAPABILITY_XXX (self)
   u8 ssid[33];                  // null terminated SSID
   u8 bssid[6];                  // bssid
   u8 ap_country_str[3];         // country string advertised by AP
   u8 country_str[3];            // country string for this association
} wifi_interface_link_layer_info;
 
/* channel information */
typedef struct {
   wifi_channel_width width;   // channel width (20, 40, 80, 80+80, 160)
   wifi_channel center_freq;   // primary 20 MHz channel
   wifi_channel center_freq0;  // center frequency (MHz) first segment
   wifi_channel center_freq1;  // center frequency (MHz) second segment
} wifi_channel_info;
 
/* wifi rate */
typedef struct {
   u32 preamble   :3;   // 0: OFDM, 1:CCK, 2:HT 3:VHT 4..7 reserved
   u32 nss        :2;   // 0:1x1, 1:2x2, 3:3x3, 4:4x4
   u32 bw         :3;   // 0:20MHz, 1:40Mhz, 2:80Mhz, 3:160Mhz
   u32 rateMcsIdx :8;   // OFDM/CCK rate code would be as per ieee std in the units of 0.5mbps
                        // HT/VHT it would be mcs index
   u32 reserved  :16;   // reserved
   u32 bitrate;         // units of 100 Kbps
} wifi_rate;
 
/* channel statistics */
typedef struct {
   wifi_channel_info channel;  // channel
   u32 on_time;                // msecs the radio is awake (32 bits number accruing over time)
   u32 cca_busy_time;          // msecs the CCA register is busy (32 bits number accruing over time)
} wifi_channel_stat;
 
// Max number of tx power levels. The actual number vary per device and is specified by |num_tx_levels|
#define RADIO_STAT_MAX_TX_LEVELS 256
 
/* Internal radio statistics structure in the driver */
typedef struct {
   wifi_radio radio;                      // wifi radio (if multiple radio supported)
   u32 on_time;                           // msecs the radio is awake (32 bits number accruing over time)
   u32 tx_time;                           // msecs the radio is transmitting (32 bits number accruing over time)
   u32 rx_time;                           // msecs the radio is in active receive (32 bits number accruing over time)
   u32 on_time_scan;                      // msecs the radio is awake due to all scan (32 bits number accruing over time)
   u32 on_time_nbd;                       // msecs the radio is awake due to NAN (32 bits number accruing over time)
   u32 on_time_gscan;                     // msecs the radio is awake due to G?scan (32 bits number accruing over time)
   u32 on_time_roam_scan;                 // msecs the radio is awake due to roam?scan (32 bits number accruing over time)
   u32 on_time_pno_scan;                  // msecs the radio is awake due to PNO scan (32 bits number accruing over time)
   u32 on_time_hs20;                      // msecs the radio is awake due to HS2.0 scans and GAS exchange (32 bits number accruing over time)
   u32 num_channels;                      // number of channels
   wifi_channel_stat channels[];          // channel statistics
} wifi_radio_stat_internal;
 
/**
 * Packet statistics reporting by firmware is performed on MPDU basi (i.e. counters increase by 1 for each MPDU)
 * As well, "data packet" in associated comments, shall be interpreted as 802.11 data packet,
 * that is, 802.11 frame control subtype == 2 and excluding management and control frames.
 *
 * As an example, in the case of transmission of an MSDU fragmented in 16 MPDUs which are transmitted
 * OTA in a 16 units long a-mpdu, for which a block ack is received with 5 bits set:
 *          tx_mpdu : shall increase by 5
 *          retries : shall increase by 16
 *          tx_ampdu : shall increase by 1
 * data packet counters shall not increase regardless of the number of BAR potentially sent by device for this a-mpdu
 * data packet counters shall not increase regardless of the number of BA received by device for this a-mpdu
 *
 * For each subsequent retransmission of the 11 remaining non ACK'ed mpdus
 * (regardless of the fact that they are transmitted in a-mpdu or not)
 *          retries : shall increase by 1
 *
 * If no subsequent BA or ACK are received from AP, until packet lifetime expires for those 11 packet that were not ACK'ed
 *          mpdu_lost : shall increase by 11
 */
 
/* per rate statistics */
typedef struct {
   wifi_rate rate;     // rate information
   u32 tx_mpdu;        // number of successfully transmitted data pkts (ACK rcvd)
   u32 rx_mpdu;        // number of received data pkts
   u32 mpdu_lost;      // number of data packet losses (no ACK)
   u32 retries;        // total number of data pkt retries
   u32 retries_short;  // number of short data pkt retries
   u32 retries_long;   // number of long data pkt retries
} wifi_rate_stat;
 
/* access categories */
typedef enum {
   WIFI_AC_VO  = 0,
   WIFI_AC_VI  = 1,
   WIFI_AC_BE  = 2,
   WIFI_AC_BK  = 3,
   WIFI_AC_MAX = 4,
} wifi_traffic_ac;
 
/* wifi peer type */
typedef enum
{
   WIFI_PEER_STA,
   WIFI_PEER_AP,
   WIFI_PEER_P2P_GO,
   WIFI_PEER_P2P_CLIENT,
   WIFI_PEER_NAN,
   WIFI_PEER_TDLS,
   WIFI_PEER_INVALID,
} wifi_peer_type;
 
/* per peer statistics */
typedef struct {
   wifi_peer_type type;           // peer type (AP, TDLS, GO etc.)
   u8 peer_mac_address[6];        // mac address
   u32 capabilities;              // peer WIFI_CAPABILITY_XXX
   u32 num_rate;                  // number of rates
   wifi_rate_stat rate_stats[];   // per rate statistics, number of entries  = num_rate
} wifi_peer_info;
 
/* Per access category statistics */
typedef struct {
   wifi_traffic_ac ac;             // access category (VI, VO, BE, BK)
   u32 tx_mpdu;                    // number of successfully transmitted unicast data pkts (ACK rcvd)
   u32 rx_mpdu;                    // number of received unicast data packets
   u32 tx_mcast;                   // number of succesfully transmitted multicast data packets
                                   // STA case: implies ACK received from AP for the unicast packet in which mcast pkt was sent
   u32 rx_mcast;                   // number of received multicast data packets
   u32 rx_ampdu;                   // number of received unicast a-mpdus; support of this counter is optional
   u32 tx_ampdu;                   // number of transmitted unicast a-mpdus; support of this counter is optional
   u32 mpdu_lost;                  // number of data pkt losses (no ACK)
   u32 retries;                    // total number of data pkt retries
   u32 retries_short;              // number of short data pkt retries
   u32 retries_long;               // number of long data pkt retries
   u32 contention_time_min;        // data pkt min contention time (usecs)
   u32 contention_time_max;        // data pkt max contention time (usecs)
   u32 contention_time_avg;        // data pkt avg contention time (usecs)
   u32 contention_num_samples;     // num of data pkts used for contention statistics
} wifi_wmm_ac_stat;
 
/* interface statistics */
typedef struct {
   wifi_interface_handle iface;          // wifi interface
   wifi_interface_link_layer_info info;  // current state of the interface
   u32 beacon_rx;                        // access point beacon received count from connected AP
   u64 average_tsf_offset;               // average beacon offset encountered (beacon_TSF - TBTT)
                                         // The average_tsf_offset field is used so as to calculate the
                                         // typical beacon contention time on the channel as well may be
                                         // used to debug beacon synchronization and related power consumption issue
   u32 leaky_ap_detected;                // indicate that this AP typically leaks packets beyond the driver guard time.
   u32 leaky_ap_avg_num_frames_leaked;  // average number of frame leaked by AP after frame with PM bit set was ACK'ed by AP
   u32 leaky_ap_guard_time;              // guard time currently in force (when implementing IEEE power management based on
                                         // frame control PM bit), How long driver waits before shutting down the radio and
                                         // after receiving an ACK for a data frame with PM bit set)
   u32 mgmt_rx;                          // access point mgmt frames received count from connected AP (including Beacon)
   u32 mgmt_action_rx;                   // action frames received count
   u32 mgmt_action_tx;                   // action frames transmit count
   wifi_rssi rssi_mgmt;                  // access Point Beacon and Management frames RSSI (averaged)
   wifi_rssi rssi_data;                  // access Point Data Frames RSSI (averaged) from connected AP
   wifi_rssi rssi_ack;                   // access Point ACK RSSI (averaged) from connected AP
   wifi_wmm_ac_stat ac[WIFI_AC_MAX];     // per ac data packet statistics
   u32 num_peers;                        // number of peers
   wifi_peer_info peer_info[];           // per peer statistics
} wifi_iface_stat;
 
/* configuration params */
typedef struct {
   u32 mpdu_size_threshold;             // threshold to classify the pkts as short or long
                                        // packet size < mpdu_size_threshold => short
   u32 aggressive_statistics_gathering; // set for field debug mode. Driver should collect all statistics regardless of performance impact.
} wifi_link_layer_params;
 
/* wifi statistics bitmap  */
#define WIFI_STATS_RADIO              0x00000001      // all radio statistics
#define WIFI_STATS_RADIO_CCA          0x00000002      // cca_busy_time (within radio statistics)
#define WIFI_STATS_RADIO_CHANNELS     0x00000004      // all channel statistics (within radio statistics)
#define WIFI_STATS_RADIO_SCAN         0x00000008      // all scan statistics (within radio statistics)
#define WIFI_STATS_IFACE              0x00000010      // all interface statistics
#define WIFI_STATS_IFACE_TXRATE       0x00000020      // all tx rate statistics (within interface statistics)
#define WIFI_STATS_IFACE_AC           0x00000040      // all ac statistics (within interface statistics)
#define WIFI_STATS_IFACE_CONTENTION   0x00000080      // all contention (min, max, avg) statistics (within ac statisctics)
 
#endif /* CONFIG_RTW_CFGVENDOR_LLSTATS */
 
 
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(RTW_VENDOR_EXT_SUPPORT)
extern int rtw_cfgvendor_attach(struct wiphy *wiphy);
extern int rtw_cfgvendor_detach(struct wiphy *wiphy);
extern int rtw_cfgvendor_send_async_event(struct wiphy *wiphy,
   struct net_device *dev, int event_id, const void  *data, int len);
#if defined(GSCAN_SUPPORT) && 0
extern int rtw_cfgvendor_send_hotlist_event(struct wiphy *wiphy,
   struct net_device *dev, void  *data, int len, rtw_vendor_event_t event);
#endif
#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(RTW_VENDOR_EXT_SUPPORT) */
 
#ifdef CONFIG_RTW_CFGVENDOR_RSSIMONITOR
void rtw_cfgvendor_rssi_monitor_evt(_adapter *padapter);
#define RSSI_MONITOR_EVT_VERSION   1
typedef struct {
    u8 version;
    s8 cur_rssi;
    mac_addr BSSID;
} rssi_monitor_evt;
#endif
 
#ifdef CONFIG_RTW_CFGVENDOR_RANDOM_MAC_OUI
void rtw_hal_pno_random_gen_mac_addr(PADAPTER adapter);
#endif
 
#endif /* _RTW_CFGVENDOR_H_ */