• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2017 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15namespace chre.fbs;
16
17/// Represents a message sent to/from a nanoapp from/to a client on the host
18table NanoappMessage {
19  app_id:ulong = 0;
20  message_type:uint = 0;
21
22  /// Identifies the host-side endpoint on the host that sent or should receive
23  /// this message. The default value is a special value defined in the HAL and
24  /// elsewhere that indicates that the endpoint is unspecified.
25  host_endpoint:ushort = 0xfffe;
26
27  /// Vector containing arbitrary application-specific message data
28  message:[ubyte] (required);
29
30  /// List of Android permissions that cover the contents of a message from a
31  /// nanoapp to the host.
32  /// These permissions are used to record and attribute access to
33  /// permissions-controlled resources.
34  message_permissions:uint;
35
36  /// List of Android permissions declared by the nanoapp / granted to the host.
37  /// For messages from a nanoaapp to the host, this must be a superset of
38  /// message_permissions.
39  permissions:uint;
40
41  // If true, the message has awakened the host AP (i.e. the AP has transitioned
42  // from suspend to awake as a result of this message transfer). This field is
43  // only valid for messages originating from a nanoapp.
44  woke_host:bool = false;
45}
46
47table HubInfoRequest {}
48table HubInfoResponse {
49  /// The name of the hub. Nominally a UTF-8 string, but note that we're not
50  /// using the built-in "string" data type from FlatBuffers here, because the
51  /// generated C++ uses std::string which is not well-supported in CHRE. This
52  /// applies for vendor and toolchain as well.
53  name:[byte];
54  vendor:[byte];
55  toolchain:[byte];
56
57  /// Legacy platform version reported in the HAL; semantics not strictly
58  /// defined
59  platform_version:uint;
60
61  /// Toolchain version reported in the HAL; semantics not strictly defined
62  toolchain_version:uint;
63
64  peak_mips:float;
65  stopped_power:float;
66  sleep_power:float;
67  peak_power:float;
68
69  /// Maximum size message that can be sent to a nanoapp
70  max_msg_len:uint;
71
72  /// @see chreGetPlatformId()
73  platform_id:ulong;
74
75  /// @see chreGetVersion()
76  chre_platform_version:uint;
77
78  // TODO: list of connected sensors
79}
80
81table NanoappListRequest {}
82
83/// Metadata regarding a Nanoapp RPC service. See the Android API
84/// core/java/android/hardware/location/NanoAppRpcService.java for more details
85/// on how this value is used by the Android application.
86table NanoappRpcService {
87  id: ulong;
88  version: uint;
89}
90
91table NanoappListEntry {
92  app_id:ulong;
93  version:uint;
94  enabled:bool = true;
95
96  /// Whether the nanoapp is a pre-loaded "system" nanoapp, i.e. one that should
97  /// not show up in the list of nanoapps in the context hub HAL. System
98  /// nanoapps are typically used to leverage CHRE for some device functionality
99  /// and do not interact via the context hub HAL.
100  is_system:bool = false;
101
102  /// Nanoapp permissions, if supported. Nanoapp permissions are required on
103  /// CHRE API v1.5+, and are defined in chre/util/system/napp_permissions.h
104  permissions:uint;
105
106  /// The list of RPC services supported by this nanoapp.
107  rpc_services:[NanoappRpcService];
108
109  // TODO: memory usage
110}
111
112table NanoappListResponse {
113  nanoapps:[NanoappListEntry] (required);
114}
115
116/// Represents a request for loading a nanoapp.
117/// The nanaopp can either be requested to be loaded via a file or via a buffer.
118/// For loading via a file, the following steps will be taken:
119/// 1. The loader sends a LoadNanoappRequest message to CHRE. app_binary must
120///    be set for legacy purposes, but should be empty. Additionally,
121///    fragment_id and total_app_size are unused in this request. The loading
122///    that happens as part of this request is serialized, but asynchronous
123///    meaning that load requests will be processed in the order they are sent
124///    but multiple requests can be outstanding at any given time.
125/// 2. CHRE stores the filename and waits until its event loop is able to
126///    process the request.
127/// 3. Once ready, the nanoapp will be loaded from the file specified in the
128///    original request and will send a callback indicating the
129///    completion/failure of the request.
130/// For loading via a buffer, loading may optionally be fragmented into multiple
131/// sequential requests, which will follow the following steps:
132/// 1. The loader sends a LoadNanoappRequest message to CHRE. If the request
133///    is fragmented, then the fields fragment_id and total_app_size must
134///    be defined. Once the first fragment is sent to CHRE, all subsequent
135///    fragments must be delivered before a new LoadNanoappRequest can be
136///    issued. If a new request is received while a current request has
137///    outstanding fragments, the current request will be overridden with the
138///    new one.
139/// 2. CHRE preallocates the required amount of memory, and loads app_binary,
140///    appending to already loaded fragments as appropriate.
141/// 3. If the request is fragmented, then the requestor must sequentially send
142///    multiple LoadNanoappRequest with incremental nanoapp binary fragments.
143///    CHRE will respond with LoadNanoappResponse for each request. For
144///    requests starting from the second fragment, all fields except
145///    fragment_id and app_binary should be ignored by CHRE.
146///
147///    Once the LoadNanoappRepsonse for the last fragment is received
148///    by the HAL, the HAL client will receive a callback indicating the
149///    completion/failure of a load request.
150///
151/// If any request fragment is lost, then the entire load request will be
152/// considered to have failed. If the request times out (e.g. the requestor
153/// process crashes), then the load request will be cancelled at CHRE and fail.
154table LoadNanoappRequest {
155  transaction_id:uint;
156
157  app_id:ulong;
158  app_version:uint;
159  target_api_version:uint;
160
161  app_binary:[ubyte] (required);
162
163  /// Fields that are relevant for fragmented loading
164  /// The framgent count starts at 1 and should end at the total number of
165  /// fragments. For clients that do not support fragmented loading, the
166  /// default behavior should be to assume one fragment.
167  fragment_id:uint = 0;
168  total_app_size:uint;
169
170  /// Null-terminated ASCII string containing the file name that contains the
171  /// app binary to be loaded.
172  app_binary_file_name:[byte];
173
174  /// The nanoapp flag values from the nanoapp header defined in
175  /// build/build_template.mk. Refer to that file for more details.
176  app_flags:uint;
177
178  /// If true and fragmented loading is requested, the LoadNanoappResponse
179  /// for the last fragment will be sent after the fragment was confirmed
180  /// to be placed in memory and no additional response will be sent after
181  /// the nanoapp is linked and started in the framework.
182  respond_before_start:bool;
183}
184
185table LoadNanoappResponse {
186  transaction_id:uint;
187
188  /// Denotes whether a load request succeeded or failed.
189  /// If any fragment of a load request fails, the entire load request for
190  /// the same transaction will fail.
191  success:bool;
192
193  /// The fragment count of the load reponse is for.
194  fragment_id:uint = 0;
195
196  // TODO: detailed error code?
197}
198
199table UnloadNanoappRequest {
200  transaction_id:uint;
201
202  app_id:ulong;
203
204  /// Set to true to allow this request to unload nanoapps identified as "system
205  /// nanoapps", i.e. ones with is_system set to true in NanoappListResponse.
206  allow_system_nanoapp_unload:bool;
207}
208
209table UnloadNanoappResponse {
210  transaction_id:uint;
211  success:bool;
212}
213
214/// Represents log messages from CHRE.
215table LogMessage {
216  /// A buffer containing formatted log data. A flat array is used here to avoid
217  /// overhead in serializing and deserializing. The format is as follows:
218  ///
219  /// uint8_t                 - log level (1 = error, 2 = warning,
220  ///                                      3 = info, 4 = debug)
221  /// uint64_t, little-endian - timestamp in nanoseconds
222  /// char[]                  - message to log
223  /// char, \0                - null-terminator
224  ///
225  /// This pattern repeats until the end of the buffer for multiple log
226  /// messages. The last byte will always be a null-terminator. There are no
227  /// padding bytes between these fields. Treat this like a packed struct and be
228  /// cautious with unaligned access when reading/writing this buffer.
229  buffer:[byte];
230}
231
232/// Represents a message sent to CHRE to indicate AP timestamp for time sync
233table TimeSyncMessage {
234  /// Offset between AP and CHRE timestamp
235  offset:long;
236}
237
238/// A request to gather and return debugging information. Only one debug dump
239/// session can be active at a time. Upon accepting a request, zero or more
240/// DebugDumpData messages are generated, followed by a DebugDumpResponse
241/// indicating the completion of the operation.
242table DebugDumpRequest {}
243
244table DebugDumpData {
245  /// Null-terminated ASCII string containing debugging information
246  debug_str:[byte];
247}
248
249table DebugDumpResponse {
250  /// true if the request was accepted and a dump was performed, false if it was
251  /// rejected or failed to complete for some reason
252  success:bool;
253
254  /// The number of DebugDumpData messages sent in this session
255  data_count:uint;
256}
257
258/// A request from CHRE for host to initiate a time sync message
259/// (system feature, platform-specific - not all platforms necessarily use this)
260table TimeSyncRequest {}
261
262/// Request from CHRE to enable direct access to data from the low-power
263/// microphone. On some systems, coordination via the AP (e.g. with
264/// SoundTrigger HAL) is needed to ensure this capability is powered up when
265/// CHRE needs it. The host does not send a response.
266table LowPowerMicAccessRequest {}
267
268/// Notification from CHRE that it no longer needs direct access to low-power
269/// microphone data.
270table LowPowerMicAccessRelease {}
271
272/// An enum describing the setting type.
273enum Setting : byte {
274  LOCATION = 0,
275  WIFI_AVAILABLE,
276  AIRPLANE_MODE,
277  MICROPHONE,
278  BLE_AVAILABLE,
279}
280
281/// An enum describing the state of a setting.
282enum SettingState : byte {
283  DISABLED = 0,
284  ENABLED,
285}
286
287/// Notification from the host that a system setting has changed
288table SettingChangeMessage {
289  /// The setting that has changed
290  setting:Setting = LOCATION;
291
292  /// The new setting value
293  state:SettingState = DISABLED;
294}
295
296// An enum describing the level of a log.
297enum LogLevel : byte {
298  ERROR = 1,
299  WARNING = 2,
300  INFO = 3,
301  DEBUG = 4,
302  VERBOSE = 5,
303}
304
305// An enum describing the type of a log.
306enum LogType : byte {
307  STRING = 0,
308  TOKENIZED = 1,
309  BLUETOOTH = 2,
310}
311
312// An enum indicating the direction of a BT snoop log.
313enum BtSnoopDirection : byte {
314  INCOMING_FROM_BT_CONTROLLER = 0,
315  OUTGOING_TO_ARBITER = 1,
316}
317
318/// Represents V2 log messages from CHRE.
319table LogMessageV2 {
320  /// A buffer containing formatted log data. A flat array is used here to avoid
321  /// overhead in serializing and deserializing. The format is as follows:
322  ///
323  /// uint8_t                 - Log metadata, encoded as follows:
324  ///                           [EI(Upper nibble) | Level(Lower nibble)]
325  ///                            * Log Type
326  ///                              (0 = No encoding, 1 = Tokenized log, 2 = BT snoop log)
327  ///                            * LogBuffer log level (1 = error, 2 = warn,
328  ///                                                   3 = info,  4 = debug,
329  ///                                                   5 = verbose)
330  /// uint32_t, little-endian - timestamp in milliseconds
331  /// char[]                  - Log data buffer
332  ///
333  /// The log data buffer format is as follows:
334  /// * Unencoded (string) logs: The log buffer can be interpreted as a NULL
335  ///   terminated string (eg: pass to string manipulation functions, get its
336  ///   size via strlen(), etc.).
337  ///
338  /// * Encoded logs: The first byte of the log buffer indicates the size of
339  ///   the actual encoded data to follow. For example, if a tokenized log of
340  ///   size 24 bytes were to be represented, a buffer of size 25 bytes would
341  ///   be needed to encode this as: [Size(1B) | Data(24B)]. A decoder would
342  ///   then have to decode this starting from a 1 byte offset from the
343  ///   received buffer.
344  ///
345  /// * Bt Snoop logs: The first byte of the log buffer indicates the direction
346  ///   of the bt snoop log, depending on whether it is incoming for the BT
347  ///   controller or outgoing to the arbiter. The second byte indicates the size
348  ///   of the actual BT payload followed. For example, if a bt snoop log of
349  ///   size 24 bytes were to be represented, a buffer of size 26 bytes would
350  ///   be needed to encode this as: [Direction(1B) | Size(1B) | Data(24B)].
351  ///
352  /// This pattern repeats until the end of the buffer for multiple log
353  /// messages. The last byte will always be a null-terminator. There are no
354  /// padding bytes between these fields. Treat this like a packed struct and be
355  /// cautious with unaligned access when reading/writing this buffer.
356  /// Note that the log message might not be null-terminated if an encoding is
357  /// used.
358  buffer:[byte];
359
360  /// The number of logs dropped since CHRE started
361  num_logs_dropped:uint;
362}
363
364// A request to perform basic internal self-test in CHRE. The test to be performed
365// is platform-dependent, and can be used to check if the system is functioning
366// properly. This message should be used for debugging/testing.
367table SelfTestRequest {}
368table SelfTestResponse {
369  // True if the self-test succeeded.
370  success:bool;
371}
372
373// Message sent whenever a host endpoint has connected with the Context Hub.
374// CHRE may receive messages from this host afterwards.
375table HostEndpointConnected {
376  /// The host-side endpoint that has connected to the framework.
377  host_endpoint:ushort;
378
379  /// The type of host endpoint, which should be any of the CHRE_HOST_ENDPOINT_TYPE_*
380  /// values defined in the chre_api/chre/event.h.
381  type:ubyte;
382
383  /// The (optional) package name associated with the host endpoint.
384  package_name:[byte];
385
386  /// The (optional) attribution tag associated with this host.
387  attribution_tag:[byte];
388}
389
390// Message sent whenever a host endpoint has disconnected from the Context Hub.
391table HostEndpointDisconnected {
392  /// The host-side endpoint that has disconnected from the framework.
393  host_endpoint:ushort;
394}
395
396// Represents metric messages from CHRE
397table MetricLog {
398  // A unique identifier for the encoded metric message.
399  id:uint;
400
401  // The metric data, which is encoded using a custom-defined protocol. This
402  // same protocol must be used to decode the data at the host side for consumption.
403  encoded_metric:[byte];
404}
405
406// A container to store batched metrics messages
407table BatchedMetricLog {
408  // The batched metrics
409  metrics: [MetricLog];
410}
411
412// NAN enable request sent from CHRE to the host.
413table NanConfigurationRequest {
414  enable:bool;
415}
416
417// NAN status message sent from the host to CHRE whenever a change in the NAN
418// enabled state is detected. Note that this update can be sent to CHRE either
419// as a response to a configuration request, or from out of band if NAN was
420// disabled by an external agent.
421table NanConfigurationUpdate {
422  enabled:bool;
423}
424
425// Debug configurastion that will be send from Android AP to CHRE during boot time
426table DebugConfiguration {
427  // Should HealthMonitor::onFailure crash when receiving a false condition
428  health_monitor_failure_crash:bool;
429}
430
431/// A union that joins together all possible messages. Note that in FlatBuffers,
432/// unions have an implicit type
433union ChreMessage {
434  NanoappMessage,
435
436  HubInfoRequest,
437  HubInfoResponse,
438
439  NanoappListRequest,
440  NanoappListResponse,
441
442  LoadNanoappRequest,
443  LoadNanoappResponse,
444
445  UnloadNanoappRequest,
446  UnloadNanoappResponse,
447
448  LogMessage,
449
450  TimeSyncMessage,
451
452  DebugDumpRequest,
453  DebugDumpData,
454  DebugDumpResponse,
455
456  TimeSyncRequest,
457
458  LowPowerMicAccessRequest,
459  LowPowerMicAccessRelease,
460
461  SettingChangeMessage,
462
463  LogMessageV2,
464
465  SelfTestRequest,
466  SelfTestResponse,
467
468  HostEndpointConnected,
469  HostEndpointDisconnected,
470
471  MetricLog,
472  BatchedMetricLog,
473
474  NanConfigurationRequest,
475  NanConfigurationUpdate,
476
477  DebugConfiguration,
478}
479
480struct HostAddress {
481  client_id:ushort;
482}
483
484/// The top-level container that encapsulates all possible messages. Note that
485/// per FlatBuffers requirements, we can't use a union as the top-level
486/// structure (root type), so we must wrap it in a table.
487table MessageContainer {
488  message:ChreMessage (required);
489
490  /// The originating or destination client ID on the host side, used to direct
491  /// responses only to the client that sent the request. Although initially
492  /// populated by the requesting client, this is enforced to be the correct
493  /// value by the entity guarding access to CHRE.
494  /// This is wrapped in a struct to ensure that it is always included when
495  /// encoding the message, so it can be mutated by the host daemon.
496  host_addr:HostAddress (required);
497}
498
499root_type MessageContainer;
500