aboutsummaryrefslogtreecommitdiff
path: root/platform/include/chre/platform/platform_ble.h
blob: fdb495f0910702467815d4e5aef9a1b32a771e2e (plain)
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
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef CHRE_PLATFORM_PLATFORM_BLE_H_
#define CHRE_PLATFORM_PLATFORM_BLE_H_

#include "chre/target_platform/platform_ble_base.h"
#include "chre/util/time.h"

namespace chre {

class PlatformBle : public PlatformBleBase {
 public:
  /**
   * Performs platform-specific deinitialization of the PlatformBle instance.
   */
  ~PlatformBle();

  /**
   * Initializes the platform-specific BLE implementation. This is potentially
   * called at a later stage of initialization than the constructor, so platform
   * implementations are encouraged to put any blocking initialization here.
   */
  void init();

  /**
   * Returns the set of BLE capabilities that the platform has exposed. This
   * may return CHRE_BLE_CAPABILITIES_NONE if BLE is not supported.
   *
   * @return the BLE capabilities exposed by this platform.
   */
  uint32_t getCapabilities();

  /**
   * Returns the set of BLE filter capabilities that the platform has exposed.
   * This may return CHRE_BLE_FILTER_CAPABILITIES_NONE if BLE filtering is not
   * supported.
   *
   * @return the BLE filter capabilities exposed by this platform.
   */
  uint32_t getFilterCapabilities();

  /**
   * Begins a BLE scan asynchronously. The result is delivered through a
   * CHRE_EVENT_BLE_ASYNC_RESULT event.
   *
   * @param mode Scanning mode selected among enum chreBleScanMode
   * @param reportDelayMs Maximum requested batching delay in ms. 0 indicates no
   *                      batching. Note that the system may deliver results
   *                      before the maximum specified delay is reached.
   * @param filter Pointer to the requested best-effort filter configuration as
   *               defined by struct chreBleScanFilter. The ownership of filter
   *               and its nested elements remains with the caller, and the
   *               caller may release it as soon as chreBleStartScanAsync()
   *               returns.
   * @return true if scan was successfully enabled.
   */
  bool startScanAsync(chreBleScanMode mode, uint32_t reportDelayMs,
                      const struct chreBleScanFilterV1_9 *filter);

  /**
   * End a BLE scan asynchronously. The result is delivered through a
   * CHRE_EVENT_BLE_ASYNC_RESULT event.
   *
   * @return true if scan was successfully ended.
   */
  bool stopScanAsync();

  /**
   * Releases an advertising event that was previously provided to the BLE
   * manager.
   *
   * @param event the event to release.
   */
  void releaseAdvertisingEvent(struct chreBleAdvertisementEvent *event);

  /**
   * Reads the RSSI on a given LE-ACL connection handle.
   *
   * Only one call to this method may be outstanding until the
   * readRssiCallback() is invoked. The readRssiCallback() is guaranteed to be
   * invoked exactly once within CHRE_PAL_BLE_READ_RSSI_COMPLETE_TIMEOUT_NS of
   * readRssi() being invoked.
   *
   * @param connectionHandle The LE-ACL handle upon which the RSSI is to be
   * read.
   *
   * @return true if the request was accepted, in which case a subsequent call
   *         to readRssiCallback() will be used to indicate the result of the
   *         operation.
   *
   * @since v1.8
   */
  bool readRssiAsync(uint16_t connectionHandle);

  /**
   * Initiates a flush operation where all batched advertisement events will be
   * immediately processed.
   *
   * @return true if the request was accepted, in which case a subsequent call
   * to flushCallback() will be used to indicate the result of the operation.
   *
   * @since v1.9
   */
  bool flushAsync();
};

}  // namespace chre

#endif  // CHRE_PLATFORM_PLATFORM_BLE_H_