xref: /aosp_15_r20/system/chre/apps/nearby/location/lbs/contexthub/nanoapps/nearby/proto/nearby_extension.proto (revision 84e339476a462649f82315436d70fd732297a399)
1//  Copyright (C) 2023 The Android Open Source Project
2//  Licensed under the Apache License, Version 2.0 (the "License");
3//  you may not use this file except in compliance with the License.
4//  You may obtain a copy of the License at
5//
6//       http://www.apache.org/licenses/LICENSE-2.0
7//
8//  Unless required by applicable law or agreed to in writing, software
9//  distributed under the License is distributed on an "AS IS" BASIS,
10//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11//  See the License for the specific language governing permissions and
12//  limitations under the License.
13//
14// Proto Messages define the interface between Nearby nanoapp and its hosts
15// (OEM services) for Nearby offload extension.
16//
17syntax = "proto2";
18
19package nearby_extension;
20
21option java_package = "com.google.location.lbs.contexthub";
22option java_outer_classname = "NearbyOffloadExtension";
23
24message ExtConfigRequest {
25  message FilterConfig {
26    // Vendor-specific configuration data for extended filter. Byte array opaque
27    // to Nearby nanoapp, which will be forwarded through
28    // chrexNearbySetExtendedFilterConfig().
29    // If both hardware and oem filters are empty, the scan requested by this
30    // host will stop. Otherwise, the scan will start with the scan filters.
31    // If the OEM service wishes to send more data than can fit in a single
32    // message, or update previous configuration, it can send additional
33    // messages.
34    optional bytes oem_filter = 1;
35    optional uint32 oem_filter_length = 2;
36
37    // List of Hardware filters (follows chreBleScanFilter defined in CHRE BLE
38    // API). Resource for hardware filters is constrained in CHRE, and hardware
39    // filtering is best effort, i.e. advertisements may still be forwarded for
40    // inspection if they do not match the configured hardware filters. It is
41    // expected that an OEM service will include at least one hardware filter in
42    // the first message. Subsequent messages that do not include this field
43    // will not impact previously configured filters. But if this field is
44    // populated in a subsequent message, its contents will replace any
45    // previously set filters. To remove all previously set hardware filters,
46    // reset extended filtering by closing the ContextHubClient connection.
47    repeated ChreBleGenericFilter hardware_filter = 3;
48
49    // Maximum time to batch BLE scan results before processing in the nanoapp,
50    // in milliseconds. For optimal power, specify the longest value that the
51    // use case permits. If not provided, either the last provided value will
52    // continue to be used, or if no previous value was given, defaults defined
53    // in the Nearby nanoapp will be used.
54    optional uint32 report_delay_ms = 4;
55
56    // BLE scan modes identify functional scan levels without specifying or
57    // guaranteeing particular scan parameters (e.g. duty cycle, interval, radio
58    // chain). The actual scan parameters may be platform dependent and may
59    // change without notice in real time based on contextual cues, etc.
60    optional ChreBleScanMode scan_mode = 5;
61
62    // BLE advertising report cache expires after this time period.
63    // The expired reports are descarded and not delivered to the OEM service.
64    optional uint32 cache_expire_ms = 6 [default = 5000];
65  }
66
67  message ServiceConfig {
68    // Vendor-specific configuration data for OEM service. Byte array opaque
69    // to Nearby nanoapp, which will be forwarded through
70    // chrexNearbySetServiceConfig().
71    // If OEM service cannot pass service config data through oem_filter in
72    // FilterConfig, or if OEM service want to pass it at another time, it can
73    // pass the service config data to the OEM library through ServiceConfig.
74    // ServiceConfig is only responsible for passing service config data to the
75    // OEM library, regardless of the LE scan start/stop behavior and
76    // hardware_filter.
77    // If the OEM service wishes to send more data than can fit in a single
78    // message, or update previous configuration, it can send additional
79    // messages.
80    optional bytes data = 1;
81    optional uint32 data_length = 2;
82  }
83
84  message TrackerFilterConfig {
85    // Tracker scan filter configuration as list of Hardware filters which
86    // follows chreBleScanFilter defined in CHRE BLE API.
87    repeated ChreBleGenericFilter hardware_filter = 1;
88
89    // The advertising report is considered seen only if the signal strength is
90    // higher than the RSSI threshold in dBm. If the RSSI threshold is
91    // CHRE_BLE_RSSI_NONE (127), the RSSI filter is not applied.
92    optional sint32 rssi_threshold = 2 [default = 127];
93
94    // Tracker batch report configuration.
95    // Minimum sampling interval to update tracker history.
96    optional uint32 sample_interval_ms = 3 [default = 60000];
97
98    // Maximum number of tracker reports that can be stored in storage.
99    optional uint32 max_tracker_count = 4 [default = 30];
100
101    // Notification threshold of the number of tracker reports, which should be
102    // equal to or smaller than max_tracker_count.
103    optional uint32 notify_threshold_tracker_count = 5 [default = 28];
104
105    // Maximum number of tracker histories that can be stored in tracker report.
106    optional uint32 max_history_count = 6 [default = 20];
107
108    // Timeout for tracker history to be considered lost.
109    optional uint32 lost_timeout_ms = 7 [default = 60000];
110
111    // Time based threshold for opportunistic flush of tracker reports. When
112    // the nanoapp receives host awake event, it flueshes tracker reports if
113    // the epalsed time since the previous flush (by host or opportunistic)
114    // is equal to or greater than this threshold. The default value effectively
115    // disables the opportunistic flush.
116    optional uint32 opportunistic_flush_threshold_time_ms = 8
117        [default = 4294967295];
118
119    // Active interval for tracker scan filter. The tracker scan filter is
120    // enabled at the beginning of the active interval and disabled at the end
121    // of the active window. This creates a toggle effect for the tracker scan
122    // filter and reduces the BLE scan power consumption. If the interval and
123    // window are not set by host, the default values are 0, and the tracker
124    // scan filter is always enabled.
125    // The active interval must be greater than the active window so that the
126    // scan toggling can function properly.
127    optional uint32 active_interval_ms = 9 [default = 0];
128
129    // Active window for tracker scan filter.
130    optional uint32 active_window_ms = 10 [default = 0];
131  }
132
133  message FlushTrackerReports {}
134
135  // Request ID specified by the client to pair Request/Response messages.
136  optional uint32 request_id = 1;
137
138  oneof config {
139    FilterConfig filter_config = 2;
140    ServiceConfig service_config = 3;
141    TrackerFilterConfig tracker_filter_config = 4;
142    FlushTrackerReports flush_tracker_reports = 5;
143  }
144}
145
146message ChreBleGenericFilter {
147  enum ChreBleAdType {
148    CHRE_BLE_AD_TYPE_SERVICE_DATA_NONE = 0;
149
150    // Service Data with 16-bit UUID
151    CHRE_BLE_AD_TYPE_SERVICE_DATA_WITH_UUID_16 = 0x16;
152
153    // Manufacturer Specific Data
154    CHRE_BLE_AD_TYPE_MANUFACTURER_DATA = 0xff;
155  }
156
157  optional ChreBleAdType type = 1;
158  // Length of data and data_mask below.
159  optional uint32 len = 2;
160
161  // data and dataMask must have the same length and are combined together
162  // to filter an advertisement.
163  optional bytes data = 3;
164  optional bytes data_mask = 4;
165}
166
167enum ChreBleScanMode {
168  CHRE_BLE_SCAN_MODE_UNSPECIFIED = 0;
169  //! A background scan level for always-running ambient applications.
170  //! A representative duty cycle may be between 3 - 10 % (tentative, and
171  //! with no guarantees).
172  CHRE_BLE_SCAN_MODE_BACKGROUND = 1;
173
174  //! A foreground scan level to be used for short periods.
175  //! A representative duty cycle may be between 10 - 20 % (tentative, and
176  //! with no guarantees).
177  CHRE_BLE_SCAN_MODE_FOREGROUND = 2;
178
179  //! A very high duty cycle scan level to be used for very short durations.
180  //! A representative duty cycle may be between 50 - 100 % (tentative, and
181  //! with no guarantees).
182  CHRE_BLE_SCAN_MODE_AGGRESSIVE = 3;
183}
184
185// Sent in response to ExtConfigRequest
186message ExtConfigResponse {
187  // Request ID of the corresponding Request message.
188  optional uint32 request_id = 1;
189  // Value from enum chrexNearbyResult that was returned from OEM library.
190  optional int32 result = 2;
191  // Vendor-defined status code provided from OEM library.
192  optional uint32 vendor_status = 3;
193}
194
195// Sent when one or more advertisements matched an extended filter
196message FilterResult {
197  enum ErrorCode {
198    UNSUPPORTED = 0;
199    SUCCESS = 1;
200  }
201
202  // Error code returned to OEM services.
203  optional ErrorCode error_code = 1;
204
205  // Each report contains multiple advertisements in a batch.
206  repeated ChreBleAdvertisingReport report = 2;
207}
208
209message ChreBleAdvertisingReport {
210  enum AddressType {
211    // Public device address.
212    PUBLIC = 0x00;
213
214    // Random device address.
215    RANDOM = 0x01;
216
217    // Public identity address (corresponds to resolved private address).
218    PUBLIC_IDENTITY = 0x02;
219
220    // Random (static) Identity Address (corresponds to resolved private
221    // address)
222    RANDOM_IDENTITY = 0x03;
223
224    // No address provided (anonymous advertisement).
225    NONE = 0xff;
226  }
227
228  // Timestamp the advertisement was received, in nanoseconds, relative to
229  // Android SystemClock.elapsedRealtimeNanos().
230  optional uint64 timestamp = 1;
231
232  // BLE event type and status. Refer to BT Core Spec v5.2, Vol 4, Part E,
233  // Section 7.7.65.13, LE Extended Advertising Report event, Event_Type for
234  // details on how to interpret this field.
235  optional uint32 event_type_and_data_status = 2;
236
237  // Advertising address type
238  optional AddressType address_type = 3;
239
240  // Advertising device address
241  optional bytes address = 4;
242
243  // Transmit (Tx) power in dBm. Typical values are [-127, 20].
244  optional int32 tx_power = 5;
245
246  // RSSI in dBm. Typical values are [-127, 20].
247  optional int32 rssi = 6;
248
249  // BLE advertisement data payload.
250  optional bytes data = 7;
251
252  optional int32 data_length = 8;
253}
254
255message TrackerReport {
256  // Advertising key report
257  optional ChreBleAdvertisingReport report = 1;
258
259  // Found and lost history for the tracker
260  repeated TrackerHistory historian = 2;
261}
262
263message TrackerHistory {
264  enum TrackerState {
265    UNSPECIFIED = 0;
266    PRESENT = 1;
267    ABSENT = 2;
268  }
269
270  // The number of times the tracker report was found at each sampling interval
271  // when in the Present state.
272  optional uint32 found_count = 1;
273
274  // The timestamp when the tracker report was first discovered when it was not
275  // in the present state, relative to Android
276  // SystemClock.elapsedRealtimeNanos().
277  optional uint32 first_found_time_ms = 2;
278
279  // The most recent timestamp when the tracker report was discovered for each
280  // sampling period in the Present state, relative to Android
281  // SystemClock.elapsedRealtimeNanos().
282  optional uint32 last_found_time_ms = 3;
283
284  // The timestamp at which the tracker report was lost. Only valid when the
285  // tracker state is Absent, relative to Android
286  // SystemClock.elapsedRealtimeNanos().
287  optional uint32 lost_time_ms = 4;
288
289  // The latest state of the tracker history.
290  optional TrackerState state = 5;
291}
292
293message ExtConfigEvent {
294  enum EventCode {
295    UNSPECIFIED = 0;
296
297    // This event is sent to host when the storage size reaches the notification
298    // level or higher defined as notify_threshold_tracker_count.
299    STORAGE_FULL = 1;
300  }
301
302  // Event code returned to host.
303  optional EventCode event_code = 1;
304}
305