• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef CHRE_BLE_H_
17 #define CHRE_BLE_H_
18 
19 /**
20  * @file
21  * CHRE BLE (Bluetooth Low Energy, Bluetooth LE) API.
22  * The CHRE BLE API currently supports BLE scanning features.
23  *
24  * The features in the CHRE BLE API are a subset and adaptation of Android
25  * capabilities as described in the Android BLE API and HCI requirements.
26  * ref:
27  * https://developer.android.com/guide/topics/connectivity/bluetooth/ble-overview
28  * ref: https://source.android.com/devices/bluetooth/hci_requirements
29  */
30 
31 #include <chre/common.h>
32 #include <stdbool.h>
33 #include <stddef.h>
34 #include <stdint.h>
35 #include <string.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /**
42  * The set of flags returned by chreBleGetCapabilities().
43  *
44  * @defgroup CHRE_BLE_CAPABILITIES
45  * @{
46  */
47 //! No BLE APIs are supported
48 #define CHRE_BLE_CAPABILITIES_NONE UINT32_C(0)
49 
50 //! CHRE supports BLE scanning
51 #define CHRE_BLE_CAPABILITIES_SCAN UINT32_C(1 << 0)
52 
53 //! CHRE BLE supports batching of scan results, either through Android-specific
54 //! HCI (OCF: 0x156), or by the CHRE framework, internally.
55 #define CHRE_BLE_CAPABILITIES_SCAN_RESULT_BATCHING UINT32_C(1 << 1)
56 
57 //! CHRE BLE scan supports best-effort hardware filtering. If filtering is
58 //! available, chreBleGetFilterCapabilities() returns a bitmap indicating the
59 //! specific filtering capabilities that are supported.
60 //! To differentiate best-effort vs. no filtering, the following requirement
61 //! must be met for this flag:
62 //! If only one nanoapp is requesting BLE scans and there are no BLE scans from
63 //! the AP, only filtered results will be provided to the nanoapp.
64 #define CHRE_BLE_CAPABILITIES_SCAN_FILTER_BEST_EFFORT UINT32_C(1 << 2)
65 /** @} */
66 
67 /**
68  * The set of flags returned by chreBleGetFilterCapabilities().
69  *
70  * The representative bit for each filtering capability is based on the sub-OCF
71  * of the Android filtering HCI vendor-specific command (LE_APCF_Command, OCF:
72  * 0x0157) for that particular filtering capability, as found in
73  * https://source.android.com/devices/bluetooth/hci_requirements
74  *
75  * For example, the Service Data filter has a sub-command of 0x7; hence
76  * the filtering capability is indicated by (1 << 0x7).
77  *
78  * @defgroup CHRE_BLE_FILTER_CAPABILITIES
79  * @{
80  */
81 //! No CHRE BLE filters are supported
82 #define CHRE_BLE_FILTER_CAPABILITIES_NONE UINT32_C(0)
83 
84 //! CHRE BLE supports RSSI filters
85 #define CHRE_BLE_FILTER_CAPABILITIES_RSSI UINT32_C(1 << 1)
86 
87 //! CHRE BLE supports Service Data filters (Corresponding HCI OCF: 0x0157,
88 //! Sub-command: 0x07)
89 #define CHRE_BLE_FILTER_CAPABILITIES_SERVICE_DATA UINT32_C(1 << 7)
90 /** @} */
91 
92 /**
93  * Produce an event ID in the block of IDs reserved for BLE.
94  *
95  * Valid input range is [0, 15]. Do not add new events with ID > 15
96  * (see chre/event.h)
97  *
98  * @param offset Index into BLE event ID block; valid range is [0, 15].
99  *
100  * @defgroup CHRE_BLE_EVENT_ID
101  * @{
102  */
103 #define CHRE_BLE_EVENT_ID(offset) (CHRE_EVENT_BLE_FIRST_EVENT + (offset))
104 
105 /**
106  * nanoappHandleEvent argument: struct chreAsyncResult
107  *
108  * Communicates the asynchronous result of a request to the BLE API. The
109  * requestType field in {@link #chreAsyncResult} is set to a value from enum
110  * chreBleRequestType.
111  *
112  * This is used for results of async config operations which need to
113  * interop with lower level code (potentially in a different thread) or send an
114  * HCI command to the FW and wait on the response.
115  */
116 #define CHRE_EVENT_BLE_ASYNC_RESULT CHRE_BLE_EVENT_ID(0)
117 
118 /**
119  * nanoappHandleEvent argument: struct chreBleAdvertisementEvent
120  *
121  * Provides results of a BLE scan.
122  */
123 #define CHRE_EVENT_BLE_ADVERTISEMENT CHRE_BLE_EVENT_ID(1)
124 
125 // NOTE: Do not add new events with ID > 15
126 /** @} */
127 
128 /**
129  * Maximum BLE (legacy) advertisement payload data length, in bytes
130  * This is calculated by subtracting 2 (type + len) from 31 (max payload).
131  */
132 #define CHRE_BLE_DATA_LEN_MAX (29)
133 
134 /**
135  * BLE device address length, in bytes.
136  */
137 #define CHRE_BLE_ADDRESS_LEN (6)
138 
139 /**
140  * RSSI value (int8_t) indicating no RSSI threshold.
141  */
142 #define CHRE_BLE_RSSI_THRESHOLD_NONE (-128)
143 
144 /**
145  * RSSI value (int8_t) indicating no RSSI value available.
146  */
147 #define CHRE_BLE_RSSI_NONE (127)
148 
149 /**
150  * Tx power value (int8_t) indicating no Tx power value available.
151  */
152 #define CHRE_BLE_TX_POWER_NONE (127)
153 
154 /**
155  * Indicates ADI field was not provided in advertisement.
156  */
157 #define CHRE_BLE_ADI_NONE (0xFF)
158 
159 /**
160  * The CHRE BLE advertising event type is based on the BT Core Spec v5.2,
161  * Vol 4, Part E, Section 7.7.65.13, LE Extended Advertising Report event,
162  * Event_Type.
163  *
164  * Note: helper functions are provided to avoid bugs, e.g. a nanoapp doing
165  * (eventTypeAndDataStatus == ADV_IND) instead of properly masking off reserved
166  * and irrelevant bits.
167  *
168  * @defgroup CHRE_BLE_EVENT
169  * @{
170  */
171 // Extended event types
172 #define CHRE_BLE_EVENT_MASK_TYPE (0x1f)
173 #define CHRE_BLE_EVENT_TYPE_FLAG_CONNECTABLE (1 << 0)
174 #define CHRE_BLE_EVENT_TYPE_FLAG_SCANNABLE (1 << 1)
175 #define CHRE_BLE_EVENT_TYPE_FLAG_DIRECTED (1 << 2)
176 #define CHRE_BLE_EVENT_TYPE_FLAG_SCAN_RSP (1 << 3)
177 #define CHRE_BLE_EVENT_TYPE_FLAG_LEGACY (1 << 4)
178 
179 // Data status
180 #define CHRE_BLE_EVENT_MASK_DATA_STATUS (0x3 << 5)
181 #define CHRE_BLE_EVENT_DATA_STATUS_COMPLETE (0x0 << 5)
182 #define CHRE_BLE_EVENT_DATA_STATUS_MORE_DATA_PENDING (0x1 << 5)
183 #define CHRE_BLE_EVENT_DATA_STATUS_DATA_TRUNCATED (0x2 << 5)
184 
185 // Legacy event types
186 #define CHRE_BLE_EVENT_TYPE_LEGACY_ADV_IND                                  \
187   (CHRE_BLE_EVENT_TYPE_FLAG_LEGACY | CHRE_BLE_EVENT_TYPE_FLAG_CONNECTABLE | \
188    CHRE_BLE_EVENT_TYPE_FLAG_SCANNABLE)
189 #define CHRE_BLE_EVENT_TYPE_LEGACY_DIRECT_IND \
190   (CHRE_BLE_EVENT_TYPE_FLAG_LEGACY | CHRE_BLE_EVENT_TYPE_FLAG_CONNECTABLE)
191 #define CHRE_BLE_EVENT_TYPE_LEGACY_ADV_SCAN_IND \
192   (CHRE_BLE_EVENT_TYPE_FLAG_LEGACY | CHRE_BLE_EVENT_TYPE_FLAG_SCANNABLE)
193 #define CHRE_BLE_EVENT_TYPE_LEGACY_ADV_NONCONN_IND \
194   (CHRE_BLE_EVENT_TYPE_FLAG_LEGACY)
195 #define CHRE_BLE_EVENT_TYPE_LEGACY_SCAN_RESP_ADV_IND \
196   (CHRE_BLE_EVENT_TYPE_FLAG_SCAN_RSP | CHRE_BLE_EVENT_TYPE_LEGACY_ADV_IND)
197 #define CHRE_BLE_EVENT_TYPE_LEGACY_SCAN_RESP_ADV_SCAN_IND \
198   (CHRE_BLE_EVENT_TYPE_FLAG_SCAN_RSP | CHRE_BLE_EVENT_TYPE_LEGACY_ADV_SCAN_IND)
199 /** @} */
200 
201 /**
202  * Indicates a type of request made in this API. Used to populate the resultType
203  * field of struct chreAsyncResult sent with CHRE_EVENT_BLE_ASYNC_RESULT.
204  */
205 enum chreBleRequestType {
206   CHRE_BLE_REQUEST_TYPE_START_SCAN = 1,
207   CHRE_BLE_REQUEST_TYPE_STOP_SCAN = 2,
208 };
209 
210 /**
211  * CHRE BLE scan modes identify functional scan levels without specifying or
212  * guaranteeing particular scan parameters (e.g. duty cycle, interval, radio
213  * chain).
214  *
215  * The actual scan parameters may be platform dependent and may change without
216  * notice in real time based on contextual cues, etc.
217  *
218  * Scan modes should be selected based on use cases as described.
219  */
220 enum chreBleScanMode {
221   //! A background scan level for always-running ambient applications.
222   //! A representative duty cycle may be between 3 - 10 % (tentative, and
223   //! with no guarantees).
224   CHRE_BLE_SCAN_MODE_BACKGROUND = 1,
225 
226   //! A foreground scan level to be used for short periods.
227   //! A representative duty cycle may be between 10 - 20 % (tentative, and
228   //! with no guarantees).
229   CHRE_BLE_SCAN_MODE_FOREGROUND = 2,
230 
231   //! A very high duty cycle scan level to be used for very short durations.
232   //! A representative duty cycle may be between 50 - 100 % (tentative, and
233   //! with no guarantees).
234   CHRE_BLE_SCAN_MODE_AGGRESSIVE = 3,
235 };
236 
237 /**
238  * Selected AD Types are available among those defined in the Bluetooth spec.
239  * Assigned Numbers, Generic Access Profile.
240  * ref: https://www.bluetooth.com/specifications/assigned-numbers/
241  */
242 enum chreBleAdType {
243   //! Service Data with 16-bit UUID
244   CHRE_BLE_AD_TYPE_SERVICE_DATA_WITH_UUID_16 = 0x16,
245 };
246 
247 /**
248  * Generic scan filters definition based on AD Type, mask, and values. The
249  * maximum data length is limited to the maximum possible legacy advertisement
250  * payload data length (29 bytes).
251  *
252  * The filter is matched when
253  *   data & dataMask == advData & dataMask
254  * where advData is the advertisement packet data for the specified AD type.
255  *
256  * The CHRE generic filter structure represents a generic filter on an AD Type
257  * as defined in the Bluetooth spec Assigned Numbers, Generic Access Profile
258  * (ref: https://www.bluetooth.com/specifications/assigned-numbers/). This
259  * generic structure is used by the Advertising Packet Content Filter
260  * (APCF) HCI generic AD type sub-command 0x08 (ref:
261  * https://source.android.com/devices/bluetooth/hci_requirements#le_apcf_command).
262  *
263  * Note that the CHRE implementation may not support every kind of filter that
264  * can be represented by this structure. Use chreBleGetFilterCapabilities() to
265  * discover supported filtering capabilities at runtime.
266  *
267  * For example, to filter on a 16 bit service data UUID of 0xFE2C, the following
268  * settings would be used:
269  *   type = CHRE_BLE_AD_TYPE_SERVICE_DATA_WITH_UUID_16
270  *   len = 2
271  *   data = {0xFE, 0x2C}
272  *   dataMask = {0xFF, 0xFF}
273  */
274 struct chreBleGenericFilter {
275   //! Acceptable values among enum chreBleAdType
276   uint8_t type;
277 
278   /**
279    * Length of data and dataMask. AD payloads shorter than this length will not
280    * be matched by the filter. Length must be greater than 0.
281    */
282   uint8_t len;
283 
284   //! Used in combination with dataMask to filter an advertisement
285   char data[CHRE_BLE_DATA_LEN_MAX];
286 
287   //! Used in combination with data to filter an advertisement
288   char dataMask[CHRE_BLE_DATA_LEN_MAX];
289 };
290 
291 /**
292  * CHRE Bluetooth LE scan filters are based on a combination of an RSSI
293  * threshold and generic scan filters as defined by AD Type, mask, and values.
294  *
295  * CHRE-provided filters are implemented in a best-effort manner, depending on
296  * HW capabilities of the system and available resources. Therefore, provided
297  * scan results may be a superset of the specified filters. Nanoapps should try
298  * to take advantage of CHRE scan filters as much as possible, but must design
299  * their logic as to not depend on CHRE filtering.
300  *
301  * The syntax of CHRE scan filter definitions are based on the Android
302  * Advertising Packet Content Filter (APCF) HCI requirement subtype 0x08
303  * ref:
304  * https://source.android.com/devices/bluetooth/hci_requirements#le_apcf_command-set_filtering_parameters_sub_cmd
305  * and AD Types as defined in the Bluetooth spec Assigned Numbers, Generic
306  * Access Profile
307  * ref: https://www.bluetooth.com/specifications/assigned-numbers/
308  *
309  * Even though the scan filters are defined in a generic manner, CHRE Bluetooth
310  * is expected to initially support only a limited set of AD Types.
311  */
312 struct chreBleScanFilter {
313   //! RSSI threshold filter (Corresponding HCI OCF: 0x0157, Sub: 0x01), where
314   //! advertisements with RSSI values below this threshold may be disregarded.
315   //! An rssiThreshold value of CHRE_BLE_RSSI_THRESHOLD_NONE indicates no RSSI
316   //! filtering.
317   int8_t rssiThreshold;
318 
319   //! Number of generic scan filters provided in the scanFilters array.
320   //! A scanFilterCount value of 0 indicates no generic scan filters.
321   uint8_t scanFilterCount;
322 
323   //! Pointer to an array of scan filters. If the array contains more than one
324   //! entry, advertisements matching any of the entries will be returned
325   //! (functional OR).
326   const struct chreBleGenericFilter *scanFilters;
327 };
328 
329 /**
330  * CHRE BLE advertising address type is based on the BT Core Spec v5.2, Vol 4,
331  * Part E, Section 7.7.65.13, LE Extended Advertising Report event,
332  * Address_Type.
333  */
334 enum chreBleAddressType {
335   //! Public device address.
336   CHRE_BLE_ADDRESS_TYPE_PUBLIC = 0x00,
337 
338   //! Random device address.
339   CHRE_BLE_ADDRESS_TYPE_RANDOM = 0x01,
340 
341   //! Public identity address (corresponds to resolved private address).
342   CHRE_BLE_ADDRESS_TYPE_PUBLIC_IDENTITY = 0x02,
343 
344   //! Random (static) Identity Address (corresponds to resolved private
345   //! address)
346   CHRE_BLE_ADDRESS_TYPE_RANDOM_IDENTITY = 0x03,
347 
348   //! No address provided (anonymous advertisement).
349   CHRE_BLE_ADDRESS_TYPE_NONE = 0xff,
350 };
351 
352 /**
353  * CHRE BLE physical (PHY) channel encoding type, if supported, is based on the
354  * BT Core Spec v5.2, Vol 4, Part E, Section 7.7.65.13, LE Extended Advertising
355  * Report event, entries Primary_PHY and Secondary_PHY.
356  */
357 enum chreBlePhyType {
358   //! No packets on this PHY (only on the secondary channel), or feature not
359   //! supported.
360   CHRE_BLE_PHY_NONE = 0x00,
361 
362   //! LE 1 MBPS PHY encoding.
363   CHRE_BLE_PHY_1M = 0x01,
364 
365   //! LE 2 MBPS PHY encoding (only on the secondary channel).
366   CHRE_BLE_PHY_2M = 0x02,
367 
368   //! LE long-range coded PHY encoding.
369   CHRE_BLE_PHY_CODED = 0x03,
370 };
371 
372 /**
373  * The CHRE BLE Advertising Report event is based on the BT Core Spec v5.2,
374  * Vol 4, Part E, Section 7.7.65.13, LE Extended Advertising Report event, with
375  * the following differences:
376  *
377  * 1) A CHRE timestamp field, which can be useful if CHRE is batching results.
378  * 2) Reordering of the rssi and periodicAdvertisingInterval fields for memory
379  *    alignment (prevent padding).
380  * 3) Addition of four reserved bytes to reclaim padding.
381  */
382 struct chreBleAdvertisingReport {
383   //! The base timestamp, in nanoseconds, in the same time base as chreGetTime()
384   uint64_t timestamp;
385 
386   //! @see CHRE_BLE_EVENT
387   uint8_t eventTypeAndDataStatus;
388 
389   //! Advertising address type as defined in enum chreBleAddressType
390   uint8_t addressType;
391 
392   //! Advertising device address
393   uint8_t address[CHRE_BLE_ADDRESS_LEN];
394 
395   //! Advertiser PHY on primary advertising physical channel, if supported, as
396   //! defined in enum chreBlePhyType.
397   uint8_t primaryPhy;
398 
399   //! Advertiser PHY on secondary advertising physical channel, if supported, as
400   //! defined in enum chreBlePhyType.
401   uint8_t secondaryPhy;
402 
403   //! Value of the Advertising SID subfield in the ADI field of the PDU among
404   //! the range of [0, 0x0f].
405   //! CHRE_BLE_ADI_NONE indicates no ADI field was provided.
406   //! Other values are reserved.
407   uint8_t advertisingSid;
408 
409   //! Transmit (Tx) power in dBm. Typical values are [-127, 20].
410   //! CHRE_BLE_TX_POWER_NONE indicates Tx power not available.
411   int8_t txPower;
412 
413   //! Interval of the periodic advertising in 1.25 ms intervals, i.e.
414   //! time = periodicAdvertisingInterval * 1.25 ms
415   //! 0 means no periodic advertising. Minimum value is otherwise 6 (7.5 ms).
416   uint16_t periodicAdvertisingInterval;
417 
418   //! RSSI in dBm. Typical values are [-127, 20].
419   //! CHRE_BLE_RSSI_NONE indicates RSSI is not available.
420   int8_t rssi;
421 
422   //! Direct address type (i.e. only accept connection requests from a known
423   //! peer device) as defined in enum chreBleAddressType.
424   uint8_t directAddressType;
425 
426   //! Direct address (i.e. only accept connection requests from a known peer
427   //! device).
428   uint8_t directAddress[CHRE_BLE_ADDRESS_LEN];
429 
430   //! Length of data field. Acceptable range is [0, 31] for legacy and
431   //! [0, 229] for extended advertisements.
432   uint16_t dataLength;
433 
434   //! dataLength bytes of data, or null if dataLength is 0
435   const uint8_t *data;
436 
437   //! Reserved for future use; set to 0
438   uint32_t reserved;
439 };
440 
441 /**
442  * A CHRE BLE Advertising Event can contain any number of CHRE BLE Advertising
443  * Reports (i.e. advertisements).
444  */
445 struct chreBleAdvertisementEvent {
446   //! Reserved for future use; set to 0
447   uint16_t reserved;
448 
449   //! Number of advertising reports in this event
450   uint16_t numReports;
451 
452   //! Array of length numReports
453   const struct chreBleAdvertisingReport *reports;
454 };
455 
456 /**
457  * Retrieves a set of flags indicating the BLE features supported by the
458  * current CHRE implementation. The value returned by this function must be
459  * consistent for the entire duration of the nanoapp's execution.
460  *
461  * The client must allow for more flags to be set in this response than it knows
462  * about, for example if the implementation supports a newer version of the API
463  * than the client was compiled against.
464  *
465  * @return A bitmask with zero or more CHRE_BLE_CAPABILITIES_* flags set. @see
466  *         CHRE_BLE_CAPABILITIES
467  *
468  * @since v1.6
469  */
470 uint32_t chreBleGetCapabilities(void);
471 
472 /**
473  * Retrieves a set of flags indicating the BLE filtering features supported by
474  * the current CHRE implementation. The value returned by this function must be
475  * consistent for the entire duration of the nanoapp's execution.
476  *
477  * The client must allow for more flags to be set in this response than it knows
478  * about, for example if the implementation supports a newer version of the API
479  * than the client was compiled against.
480  *
481  * @return A bitmask with zero or more CHRE_BLE_FILTER_CAPABILITIES_* flags set.
482  *         @see CHRE_BLE_FILTER_CAPABILITIES
483  *
484  * @since v1.6
485  */
486 uint32_t chreBleGetFilterCapabilities(void);
487 
488 /**
489  * Helper function to extract event type from eventTypeAndDataStatus as defined
490  * in the BT Core Spec v5.2, Vol 4, Part E, Section 7.7.65.13, LE Extended
491  * Advertising Report event, entry Event_Type.
492  *
493  * @see CHRE_BLE_EVENT
494  *
495  * @param eventTypeAndDataStatus Combined event type and data status
496  *
497  * @return The event type portion of eventTypeAndDataStatus
498  */
chreBleGetEventType(uint8_t eventTypeAndDataStatus)499 static inline uint8_t chreBleGetEventType(uint8_t eventTypeAndDataStatus) {
500   return (eventTypeAndDataStatus & CHRE_BLE_EVENT_MASK_TYPE);
501 }
502 
503 /**
504  * Helper function to extract data status from eventTypeAndDataStatus as defined
505  * in the BT Core Spec v5.2, Vol 4, Part E, Section 7.7.65.13, LE Extended
506  * Advertising Report event, entry Event_Type.
507  *
508  * @see CHRE_BLE_EVENT
509  *
510  * @param eventTypeAndDataStatus Combined event type and data status
511  *
512  * @return The data status portion of eventTypeAndDataStatus
513  */
chreBleGetDataStatus(uint8_t eventTypeAndDataStatus)514 static inline uint8_t chreBleGetDataStatus(uint8_t eventTypeAndDataStatus) {
515   return (eventTypeAndDataStatus & CHRE_BLE_EVENT_MASK_DATA_STATUS);
516 }
517 
518 /**
519  * Helper function to to combine an event type with a data status to create
520  * eventTypeAndDataStatus as defined in the BT Core Spec v5.2, Vol 4, Part E,
521  * Section 7.7.65.13, LE Extended Advertising Report event, entry Event_Type.
522  *
523  * @see CHRE_BLE_EVENT
524  *
525  * @param eventType Event type
526  * @param dataStatus Data status
527  *
528  * @return A combined eventTypeAndDataStatus
529  */
chreBleGetEventTypeAndDataStatus(uint8_t eventType,uint8_t dataStatus)530 static inline uint8_t chreBleGetEventTypeAndDataStatus(uint8_t eventType,
531                                                        uint8_t dataStatus) {
532   return ((eventType & CHRE_BLE_EVENT_MASK_TYPE) |
533           (dataStatus & CHRE_BLE_EVENT_MASK_DATA_STATUS));
534 }
535 
536 /**
537  * Nanoapps must define CHRE_NANOAPP_USES_BLE somewhere in their build
538  * system (e.g. Makefile) if the nanoapp needs to use the following BLE APIs.
539  * In addition to allowing access to these APIs, defining this macro will also
540  * ensure CHRE enforces that all host clients this nanoapp talks to have the
541  * required Android permissions needed to access BLE functionality by adding
542  * metadata to the nanoapp.
543  */
544 #if defined(CHRE_NANOAPP_USES_BLE) || !defined(CHRE_IS_NANOAPP_BUILD)
545 
546 /**
547  * Start Bluetooth LE (BLE) scanning on CHRE.
548  *
549  * The result of the operation will be delivered asynchronously via the CHRE
550  * event CHRE_EVENT_BLE_ASYNC_RESULT.
551  *
552  * The scan results will be delivered asynchronously via the CHRE event
553  * CHRE_EVENT_BLE_ADVERTISEMENT.
554  *
555  * If the Bluetooth setting is disabled at the Android level, CHRE is expected
556  * to return a result with CHRE_ERROR_FUNCTION_DISABLED.
557  *
558  * If chreBleStartScanAsync() is called while a previous scan has been started,
559  * the previous scan will be stopped first and replaced with the new scan.
560  *
561  * Note that some corresponding Android parameters are missing from the CHRE
562  * API, where the following default or typical parameters are used:
563  * Callback type: CALLBACK_TYPE_ALL_MATCHES
564  * Result type: SCAN_RESULT_TYPE_FULL
565  * Match mode: MATCH_MODE_AGGRESSIVE
566  * Number of matches per filter: MATCH_NUM_MAX_ADVERTISEMENT
567  * Legacy-only: false
568  * PHY type: PHY_LE_ALL_SUPPORTED
569  *
570  * @param mode Scanning mode selected among enum chreBleScanMode
571  * @param reportDelayMs Maximum requested batching delay in ms. 0 indicates no
572  *                      batching. Note that the system may deliver results
573  *                      before the maximum specified delay is reached.
574  * @param filter Pointer to the requested best-effort filter configuration as
575  *               defined by struct chreBleScanFilter. The ownership of filter
576  *               and its nested elements remains with the caller, and the caller
577  *               may release it as soon as chreBleStartScanAsync() returns.
578  *
579  * @return True to indicate that the request was accepted. False otherwise.
580  *
581  * @since v1.6
582  */
583 bool chreBleStartScanAsync(enum chreBleScanMode mode, uint32_t reportDelayMs,
584                            const struct chreBleScanFilter *filter);
585 /**
586  * Stops a CHRE BLE scan.
587  *
588  * The result of the operation will be delivered asynchronously via the CHRE
589  * event CHRE_EVENT_BLE_ASYNC_RESULT.
590  *
591  * @return True to indicate that the request was accepted. False otherwise.
592  *
593  * @since v1.6
594  */
595 bool chreBleStopScanAsync(void);
596 
597 /**
598  * Definitions for handling unsupported CHRE BLE scenarios.
599  */
600 #else  // defined(CHRE_NANOAPP_USES_BLE) || !defined(CHRE_IS_NANOAPP_BUILD)
601 
602 #define CHRE_BLE_PERM_ERROR_STRING                                       \
603   "CHRE_NANOAPP_USES_BLE must be defined when building this nanoapp in " \
604   "order to refer to "
605 
606 #define chreBleStartScanAsync(...) \
607   CHRE_BUILD_ERROR(CHRE_BLE_PERM_ERROR_STRING "chreBleStartScanAsync")
608 
609 #define chreBleStopScanAsync(...) \
610   CHRE_BUILD_ERROR(CHRE_BLE_PERM_ERROR_STRING "chreBleStopScanAsync")
611 
612 #endif  // defined(CHRE_NANOAPP_USES_BLE) || !defined(CHRE_IS_NANOAPP_BUILD)
613 
614 #ifdef __cplusplus
615 }
616 #endif
617 
618 #endif /* CHRE_BLE_H_ */
619