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 17 #ifndef CHRE_PLATFORM_PLATFORM_BLE_H_ 18 #define CHRE_PLATFORM_PLATFORM_BLE_H_ 19 20 #include "chre/target_platform/platform_ble_base.h" 21 #include "chre/util/time.h" 22 23 namespace chre { 24 25 class PlatformBle : public PlatformBleBase { 26 public: 27 /** 28 * Performs platform-specific deinitialization of the PlatformBle instance. 29 */ 30 ~PlatformBle(); 31 32 /** 33 * Initializes the platform-specific BLE implementation. This is potentially 34 * called at a later stage of initialization than the constructor, so platform 35 * implementations are encouraged to put any blocking initialization here. 36 */ 37 void init(); 38 39 /** 40 * Returns the set of BLE capabilities that the platform has exposed. This 41 * may return CHRE_BLE_CAPABILITIES_NONE if BLE is not supported. 42 * 43 * @return the BLE capabilities exposed by this platform. 44 */ 45 uint32_t getCapabilities(); 46 47 /** 48 * Returns the set of BLE filter capabilities that the platform has exposed. 49 * This may return CHRE_BLE_FILTER_CAPABILITIES_NONE if BLE filtering is not 50 * supported. 51 * 52 * @return the BLE filter capabilities exposed by this platform. 53 */ 54 uint32_t getFilterCapabilities(); 55 56 /** 57 * Begins a BLE scan asynchronously. The result is delivered through a 58 * CHRE_EVENT_BLE_ASYNC_RESULT event. 59 * 60 * @param mode Scanning mode selected among enum chreBleScanMode 61 * @param reportDelayMs Maximum requested batching delay in ms. 0 indicates no 62 * batching. Note that the system may deliver results 63 * before the maximum specified delay is reached. 64 * @param filter Pointer to the requested best-effort filter configuration as 65 * defined by struct chreBleScanFilter. The ownership of filter 66 * and its nested elements remains with the caller, and the 67 * caller may release it as soon as chreBleStartScanAsync() 68 * returns. 69 * @return true if scan was successfully enabled. 70 */ 71 bool startScanAsync(chreBleScanMode mode, uint32_t reportDelayMs, 72 const struct chreBleScanFilterV1_9 *filter); 73 74 /** 75 * End a BLE scan asynchronously. The result is delivered through a 76 * CHRE_EVENT_BLE_ASYNC_RESULT event. 77 * 78 * @return true if scan was successfully ended. 79 */ 80 bool stopScanAsync(); 81 82 /** 83 * Releases an advertising event that was previously provided to the BLE 84 * manager. 85 * 86 * @param event the event to release. 87 */ 88 void releaseAdvertisingEvent(struct chreBleAdvertisementEvent *event); 89 90 /** 91 * Reads the RSSI on a given LE-ACL connection handle. 92 * 93 * Only one call to this method may be outstanding until the 94 * readRssiCallback() is invoked. The readRssiCallback() is guaranteed to be 95 * invoked exactly once within CHRE_PAL_BLE_READ_RSSI_COMPLETE_TIMEOUT_NS of 96 * readRssi() being invoked. 97 * 98 * @param connectionHandle The LE-ACL handle upon which the RSSI is to be 99 * read. 100 * 101 * @return true if the request was accepted, in which case a subsequent call 102 * to readRssiCallback() will be used to indicate the result of the 103 * operation. 104 * 105 * @since v1.8 106 */ 107 bool readRssiAsync(uint16_t connectionHandle); 108 109 /** 110 * Initiates a flush operation where all batched advertisement events will be 111 * immediately processed. 112 * 113 * @return true if the request was accepted, in which case a subsequent call 114 * to flushCallback() will be used to indicate the result of the operation. 115 * 116 * @since v1.9 117 */ 118 bool flushAsync(); 119 }; 120 121 } // namespace chre 122 123 /* The platform can optionally provide an inlined implementation */ 124 #if __has_include("chre/target_platform/platform_ble_impl.h") 125 #include "chre/target_platform/platform_ble_impl.h" 126 #endif // __has_include("chre/target_platform/platform_ble_impl.h") 127 128 #endif // CHRE_PLATFORM_PLATFORM_BLE_H_ 129