OSDN Git Service

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