OSDN Git Service

fix comments and wifi_gscan_capabilities structure
[android-x86/hardware-libhardware_legacy.git] / include / hardware_legacy / gscan.h
1
2 #include "wifi_hal.h"
3
4 #ifndef __WIFI_HAL_GSCAN_H__
5 #define __WIFI_HAL_GSCAN_H__
6
7 /* AP Scans */
8
9 typedef enum {
10     WIFI_BAND_UNSPECIFIED,
11     WIFI_BAND_BG = 1,                       // 2.4 GHz
12     WIFI_BAND_A = 2,                        // 5 GHz without DFS
13     WIFI_BAND_A_DFS = 4,                    // 5 GHz DFS only
14     WIFI_BAND_A_WITH_DFS = 6,               // 5 GHz with DFS
15     WIFI_BAND_ABG = 3,                      // 2.4 GHz + 5 GHz; no DFS
16     WIFI_BAND_ABG_WITH_DFS = 7,             // 2.4 GHz + 5 GHz with DFS
17 } wifi_band;
18
19 const unsigned MAX_CHANNELS                = 16;
20 const unsigned MAX_BUCKETS                 = 16;
21 const unsigned MAX_HOTLIST_APS             = 128;
22 const unsigned MAX_SIGNIFICANT_CHANGE_APS  = 64;
23 const unsigned MAX_PNO_SSID                = 128;
24 const unsigned MAX_HOTLIST_SSID            = 8;
25 const unsigned MAX_BLACKLIST_BSSID         = 16;
26
27 wifi_error wifi_get_valid_channels(wifi_interface_handle handle,
28         int band, int max_channels, wifi_channel *channels, int *num_channels);
29
30 typedef struct {
31     int max_scan_cache_size;                 // total space allocated for scan (in bytes)
32     int max_scan_buckets;                    // maximum number of channel buckets
33     int max_ap_cache_per_scan;               // maximum number of APs that can be stored per scan
34     int max_rssi_sample_size;                // number of RSSI samples used for averaging RSSI
35     int max_scan_reporting_threshold;        // max possible report_threshold as described
36                                              // in wifi_scan_cmd_params
37     int max_hotlist_bssids;                  // maximum number of entries for hotlist BSSIDs
38     int max_hotlist_ssids;                   // maximum number of entries for hotlist SSIDs
39     int max_significant_wifi_change_aps;     // maximum number of entries for
40                                              // significant wifi change APs
41     int max_bssid_history_entries;           // number of BSSID/RSSI entries that device can hold
42     int max_number_epno_networks;            // max number of epno entries
43     int max_number_epno_networks_by_ssid;    // max number of epno entries if ssid is specified,
44                                              // that is, epno entries for which an exact match is
45                                              // required, or entries corresponding to hidden ssids
46     int max_number_of_white_listed_ssid;     // max number of white listed SSIDs, M target is 2 to 4
47 } wifi_gscan_capabilities;
48
49 wifi_error wifi_get_gscan_capabilities(wifi_interface_handle handle,
50         wifi_gscan_capabilities *capabilities);
51
52 typedef enum {
53    WIFI_SCAN_BUFFER_FULL,
54    WIFI_SCAN_COMPLETE,
55 } wifi_scan_event;
56
57
58 /* Format of information elements found in the beacon */
59 typedef struct {
60     byte id;                            // element identifier
61     byte len;                           // number of bytes to follow
62     byte data[];
63 } wifi_information_element;
64
65 typedef struct {
66     wifi_timestamp ts;                  // time since boot (in microsecond) when the result was
67                                         // retrieved
68     char ssid[32+1];                    // null terminated
69     mac_addr bssid;
70     wifi_channel channel;               // channel frequency in MHz
71     wifi_rssi rssi;                     // in db
72     wifi_timespan rtt;                  // in nanoseconds
73     wifi_timespan rtt_sd;               // standard deviation in rtt
74     unsigned short beacon_period;       // period advertised in the beacon
75     unsigned short capability;          // capabilities advertised in the beacon
76     unsigned int ie_length;             // size of the ie_data blob
77     char         ie_data[1];            // blob of all the information elements found in the
78                                         // beacon; this data should be a packed list of
79                                         // wifi_information_element objects, one after the other.
80     // other fields
81 } wifi_scan_result;
82
83 typedef struct {
84     /* reported when report_threshold is reached in scan cache */
85     void (*on_scan_results_available) (wifi_request_id id, unsigned num_results_available);
86
87     /* reported when each probe response is received, if report_events
88      * enabled in wifi_scan_cmd_params */
89     void (*on_full_scan_result) (wifi_request_id id, wifi_scan_result *result);
90
91     /* optional event - indicates progress of scanning statemachine */
92     void (*on_scan_event) (wifi_scan_event event, unsigned status);
93
94 } wifi_scan_result_handler;
95
96 typedef struct {
97     wifi_channel channel;               // frequency
98     int dwellTimeMs;                    // dwell time hint
99     int passive;                        // 0 => active, 1 => passive scan; ignored for DFS
100     /* Add channel class */
101 } wifi_scan_channel_spec;
102
103
104 typedef struct {
105     int bucket;                         // bucket index, 0 based
106     wifi_band band;                     // when UNSPECIFIED, use channel list
107     int period;                         // desired period, in millisecond; if this is too
108                                         // low, the firmware should choose to generate results as
109                                         // fast as it can instead of failing the command.
110                                         // for exponential backoff bucket this is the min_period
111     /* report_events semantics -
112      *  0 => report only when scan history is % full
113      *  1 => same as 0 + report a scan completion event after scanning this bucket
114      *  2 => same as 1 + forward scan results (beacons/probe responses + IEs) in real time to HAL
115      *  3 => same as 2 + forward scan results (beacons/probe responses + IEs) in real time to
116              supplicant as well (optional) .
117      */
118     byte report_events;
119     int max_period; // if max_period is non zero or different than period, then this bucket is
120                     // an exponential backoff bucket and the scan period will grow exponentially
121                     // as per formula: actual_period(N) = period ^ (N/(step_count+1))
122                     // to a maximum period of max_period
123     int exponent; // for exponential back off bucket: multiplier: new_period = old_period * exponent
124     int step_count; // for exponential back off bucket, number of scans performed at a given
125                     // period and until the exponent is applied
126
127     int num_channels;
128     // channels to scan; these may include DFS channels
129     // Note that a given channel may appear in multiple buckets
130     wifi_scan_channel_spec channels[MAX_CHANNELS];
131 } wifi_scan_bucket_spec;
132
133 typedef struct {
134     int base_period;                    // base timer period in ms
135     int max_ap_per_scan;                // number of APs to store in each scan ientryn the
136                                         // BSSID/RSSI history buffer (keep the highest RSSI APs)
137     int report_threshold_percent;       // in %, when scan buffer is this much full, wake up AP
138     int report_threshold_num_scans;     // in number of scans, wake up AP after these many scans
139     int num_buckets;
140     wifi_scan_bucket_spec buckets[MAX_BUCKETS];
141 } wifi_scan_cmd_params;
142
143 /* Start periodic GSCAN */
144 wifi_error wifi_start_gscan(wifi_request_id id, wifi_interface_handle iface,
145         wifi_scan_cmd_params params, wifi_scan_result_handler handler);
146
147 /* Stop periodic GSCAN */
148 wifi_error wifi_stop_gscan(wifi_request_id id, wifi_interface_handle iface);
149
150 typedef enum {
151     WIFI_SCAN_FLAG_INTERRUPTED = 1      // Indicates that scan results are not complete because
152                                         // probes were not sent on some channels
153 } wifi_scan_flags;
154
155 /* Get the GSCAN cached scan results */
156 typedef struct {
157     int scan_id;                        // a unique identifier for the scan unit
158     int flags;                          // a bitmask with additional information about scan
159     int num_results;                    // number of bssids retrieved by the scan
160     wifi_scan_result *results;          // scan results - one for each bssid
161 } wifi_cached_scan_results;
162
163 wifi_error wifi_get_cached_gscan_results(wifi_interface_handle iface, byte flush,
164         int max, wifi_cached_scan_results *results, int *num);
165
166 /* BSSID Hotlist */
167 typedef struct {
168     void (*on_hotlist_ap_found)(wifi_request_id id,
169             unsigned num_results, wifi_scan_result *results);
170     void (*on_hotlist_ap_lost)(wifi_request_id id,
171             unsigned num_results, wifi_scan_result *results);
172 } wifi_hotlist_ap_found_handler;
173
174 typedef struct {
175     mac_addr  bssid;                    // AP BSSID
176     wifi_rssi low;                      // low threshold
177     wifi_rssi high;                     // high threshold
178 } ap_threshold_param;
179
180 typedef struct {
181     int lost_ap_sample_size;
182     int num_bssid;                                 // number of hotlist APs
183     ap_threshold_param ap[MAX_HOTLIST_APS];     // hotlist APs
184 } wifi_bssid_hotlist_params;
185
186 /* Set the BSSID Hotlist */
187 wifi_error wifi_set_bssid_hotlist(wifi_request_id id, wifi_interface_handle iface,
188         wifi_bssid_hotlist_params params, wifi_hotlist_ap_found_handler handler);
189
190 /* Clear the BSSID Hotlist */
191 wifi_error wifi_reset_bssid_hotlist(wifi_request_id id, wifi_interface_handle iface);
192
193 /* SSID Hotlist */
194 typedef struct {
195     void (*on_hotlist_ssid_found)(wifi_request_id id,
196             unsigned num_results, wifi_scan_result *results);
197     void (*on_hotlist_ssid_lost)(wifi_request_id id,
198             unsigned num_results, wifi_scan_result *results);
199 } wifi_hotlist_ssid_handler;
200
201 typedef struct {
202     char  ssid[32+1];                   // SSID
203     wifi_band band;                     // band for this set of threshold params
204     wifi_rssi low;                      // low threshold
205     wifi_rssi high;                     // high threshold
206 } ssid_threshold_param;
207
208 typedef struct {
209     int lost_ssid_sample_size;
210     int num_ssid;                                   // number of hotlist SSIDs
211     ssid_threshold_param ssid[MAX_HOTLIST_SSID];    // hotlist SSIDs
212 } wifi_ssid_hotlist_params;
213
214
215 /* Set the SSID Hotlist */
216 wifi_error wifi_set_ssid_hotlist(wifi_request_id id, wifi_interface_handle iface,
217         wifi_ssid_hotlist_params params, wifi_hotlist_ssid_handler handler);
218
219 /* Clear the SSID Hotlist */
220 wifi_error wifi_reset_ssid_hotlist(wifi_request_id id, wifi_interface_handle iface);
221
222
223 /* BSSID blacklist */
224 typedef struct {
225     int num_bssid;                           // number of blacklisted BSSIDs
226     mac_addr bssids[MAX_BLACKLIST_BSSID];    // blacklisted BSSIDs
227 } wifi_bssid_params;
228
229 /* Set the BSSID blacklist */
230 wifi_error wifi_set_bssid_blacklist(wifi_request_id id, wifi_interface_handle iface,
231         wifi_bssid_params params);
232
233
234 /* Significant wifi change */
235 typedef struct {
236     mac_addr bssid;                     // BSSID
237     wifi_channel channel;               // channel frequency in MHz
238     int num_rssi;                       // number of rssi samples
239     wifi_rssi rssi[];                   // RSSI history in db
240 } wifi_significant_change_result;
241
242 typedef struct {
243     void (*on_significant_change)(wifi_request_id id,
244             unsigned num_results, wifi_significant_change_result **results);
245 } wifi_significant_change_handler;
246
247 // The sample size parameters in the wifi_significant_change_params structure
248 // represent the number of occurence of a g-scan where the BSSID was seen and RSSI was
249 // collected for that BSSID, or, the BSSID was expected to be seen and didn't.
250 // for instance: lost_ap_sample_size : number of time a g-scan was performed on the
251 // channel the BSSID was seen last, and the BSSID was not seen during those g-scans
252 typedef struct {
253     int rssi_sample_size;               // number of samples for averaging RSSI
254     int lost_ap_sample_size;            // number of samples to confirm AP loss
255     int min_breaching;                  // number of APs breaching threshold
256     int num_bssid;                         // max 64
257     ap_threshold_param ap[MAX_SIGNIFICANT_CHANGE_APS];
258 } wifi_significant_change_params;
259
260 /* Set the Signifcant AP change list */
261 wifi_error wifi_set_significant_change_handler(wifi_request_id id, wifi_interface_handle iface,
262         wifi_significant_change_params params, wifi_significant_change_handler handler);
263
264 /* Clear the Signifcant AP change list */
265 wifi_error wifi_reset_significant_change_handler(wifi_request_id id, wifi_interface_handle iface);
266
267 /* Random MAC OUI for PNO */
268 wifi_error wifi_set_scanning_mac_oui(wifi_interface_handle handle, oui scan_oui);
269
270 // Whether directed scan needs to be performed (for hidden SSIDs)
271 #define WIFI_PNO_FLAG_DIRECTED_SCAN = 1
272 // Whether PNO event shall be triggered if the network is found on A band
273 #define WIFI_PNO_FLAG_A_BAND = 2
274 // Whether PNO event shall be triggered if the network is found on G band
275 #define WIFI_PNO_FLAG_G_BAND = 4
276 // Whether strict matching is required (i.e. firmware shall not match on the entire SSID)
277 #define WIFI_PNO_FLAG_STRICT_MATCH = 8
278
279 // Code for matching the beacon AUTH IE - additional codes TBD
280 #define WIFI_PNO_AUTH_CODE_OPEN  1 // open
281 #define WIFI_PNO_AUTH_CODE_PSK   2 // WPA_PSK or WPA2PSK
282 #define WIFI_PNO_AUTH_CODE_EAPOL 4 // any EAPOL
283
284 // Enhanced PNO:
285 // Enhanced PNO feature is expected to be enabled all of the time (e.g. screen lit) and may thus
286 // requires firmware to store a large number of networks, covering the whole list of known network.
287 // Therefore, it is acceptable for firmware to store a crc24, crc32 or other short hash of the SSID,
288 // such that a low but non-zero probability of collision exist. With that scheme it should be
289 // possible for firmware to keep an entry as small as 4 bytes for each pno network.
290 // For instance, a firmware pn0 entry can be implemented in the form of:
291 //          PNO ENTRY = crc24(3 bytes) | RSSI_THRESHOLD>>3 (5 bits) | auth flags(3 bits)
292 //
293 // A PNO network shall be reported once, that is, once a network is reported by firmware
294 // its entry shall be marked as "done" until framework calls wifi_set_epno_list again.
295 // Calling wifi_set_epno_list shall reset the "done" status of pno networks in firmware.
296 typedef struct {
297     char ssid[32+1];
298     char rssi_threshold; // threshold for considering this SSID as found, required granularity for
299                          // this threshold is 4dBm to 8dBm
300     char flags;          //  WIFI_PNO_FLAG_XXX
301     char auth_bit_field; // auth bit field for matching WPA IE
302 } wifi_epno_network;
303
304 /* PNO list */
305 typedef struct {
306     int num_networks;                 // number of SSIDs
307     wifi_epno_network networks[];     // PNO networks
308 } wifi_epno_params;
309
310 typedef struct {
311     // on results
312     void (*on_network_found)(wifi_request_id id,
313             unsigned num_results, wifi_scan_result *results);
314 } wifi_epno_handler;
315
316
317 /* Set the PNO list */
318 wifi_error wifi_set_epno_list(wifi_request_id id, wifi_interface_handle iface,
319         int num_networks, wifi_epno_network *networks, wifi_epno_handler handler);
320
321
322 /* SSID white list */
323 /* Note that this feature requires firmware to be able to indicate to kernel sme and wpa_supplicant
324  * that the SSID of the network has changed
325  * and thus requires further changed in cfg80211 stack, for instance,
326  * the below function would change:
327
328  void __cfg80211_roamed(struct wireless_dev *wdev,
329                        struct cfg80211_bss *bss,
330                        const u8 *req_ie, size_t req_ie_len,
331                        const u8 *resp_ie, size_t resp_ie_len)
332  * when firmware roam to a new SSID the corresponding link layer stats info need to be updated:
333      struct wifi_interface_link_layer_info;
334  */
335 typedef struct {
336     char ssid[32+1]; // null terminated
337 } wifi_ssid;
338
339 wifi_error wifi_set_ssid_white_list(wifi_request_id id, wifi_interface_handle iface,
340         int num_networks, wifi_ssid *ssids);
341
342 /* Set G-SCAN roam parameters */
343 /**
344  * Firmware roaming is implemented with two modes:
345  *   1- "Alert" mode roaming, (Note: alert roaming is the pre-L roaming, whereas firmware is
346  *      "urgently" hunting for another BSSID because the RSSI is low, or because many successive
347  *      beacons have been lost or other bad link conditions).
348  *   2- "Lazy" mode, where firmware is hunting for a better BSSID or white listed SSID even though
349  *      the RSSI of the link is good.
350  *      Lazy mode is configured thru G-scan, that is, the results of G-scans are compared to the
351  *      current RSSI and fed thru the roaming engine.
352  *      Lazy scan will be enabled (and or throttled down by reducing the number of G-scans) by
353  *      framework only in certain conditions, such as:
354  *          - no real time (VO/VI) traffic at the interface
355  *          - low packet rate for BE/BK packets a the interface
356  *          - system conditions (screen lit/dark) etc...
357  *
358  * For consistency, the roam parameters will always be configured by framework such that:
359  *
360  * condition 1- A_band_boost_threshold >= (alert_roam_rssi_trigger + 10)
361  * This condition ensures that Lazy roam doesn't cause the device to roam to a 5GHz BSSID whose RSSI
362  * is lower than the alert threshold, which would consequently trigger a roam to a low RSSI BSSID,
363  * hence triggering alert mode roaming.
364  * In other words, in alert mode, the A_band parameters may safely be ignored by WiFi chipset.
365  *
366  * condition 2- A_band_boost_threshold > A_band_penalty_factor
367  *
368  */
369
370 /**
371  * Example:
372  * A_band_boost_threshold = -65
373  * A_band_penalty_threshold = -75
374  * A_band_boost_factor = 4
375  * A_band_penalty_factor = 2
376  * A_band_max_boost = 50
377  *
378  * a 5GHz RSSI value is transformed as below:
379  * -20 -> -20+ 50 = 30
380  * -60 -> -60 + 4 * (-60 - A_band_boost_threshold) = -60 + 16 = -44
381  * -70 -> -70
382  * -80 -> -80 - 2 * (A_band_penalty_threshold - (-80)) = -80 - 10 = -90
383  */
384
385 typedef struct {
386     // Lazy roam parameters
387     // A_band_XX parameters are applied to 5GHz BSSIDs when comparing with a 2.4GHz BSSID
388     // they may not be applied when comparing two 5GHz BSSIDs
389     int A_band_boost_threshold;     // RSSI threshold above which 5GHz RSSI is favored
390     int A_band_penalty_threshold;   // RSSI threshold below which 5GHz RSSI is penalized
391     int A_band_boost_factor;        // factor by which 5GHz RSSI is boosted
392                                // boost=RSSI_measured-5GHz_boost_threshold)*5GHz_boost_factor
393     int A_band_penalty_factor;      // factor by which 5GHz RSSI is penalized
394                                // penalty=(5GHz_penalty_factor-RSSI_measured)*5GHz_penalty_factor
395     int A_band_max_boost;           // maximum boost that can be applied to a 5GHz RSSI
396
397     // Hysteresis: ensuring the currently associated BSSID is favored
398     // so as to prevent ping-pong situations
399     int lazy_roam_hysteresis;       // boost applied to current BSSID
400
401     // Alert mode enable, i.e. configuring when firmware enters alert mode
402     int alert_roam_rssi_trigger;    // RSSI below which "Alert" roam is enabled
403 } wifi_roam_params;
404
405 wifi_error wifi_set_gscan_roam_params(wifi_request_id id, wifi_interface_handle iface,
406                                         wifi_roam_params * params);
407
408 /**
409  * Enable/Disable "Lazy" roam
410  */
411 wifi_error wifi_enable_lazy_roam(wifi_request_id id, wifi_interface_handle iface, int enable);
412
413 /**
414  * Per BSSID preference
415  */
416 typedef struct {
417     mac_addr bssid;
418     int rssi_modifier;  // modifier applied to the RSSI of the BSSID for the purpose of comparing
419                         // it with other roam candidate
420 } wifi_bssid_preference;
421
422 wifi_error wifi_set_bssid_preference(wifi_request_id id, wifi_interface_handle iface,
423                                     int num_bssid, wifi_bssid_preference *prefs);
424
425 #endif
426