• 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
31table HubInfoRequest {}
32table HubInfoResponse {
33  /// The name of the hub. Nominally a UTF-8 string, but note that we're not
34  /// using the built-in "string" data type from FlatBuffers here, because the
35  /// generated C++ uses std::string which is not well-supported in CHRE. This
36  /// applies for vendor and toolchain as well.
37  name:[byte];
38  vendor:[byte];
39  toolchain:[byte];
40
41  /// Legacy platform version reported in the HAL; semantics not strictly
42  /// defined
43  platform_version:uint;
44
45  /// Toolchain version reported in the HAL; semantics not strictly defined
46  toolchain_version:uint;
47
48  peak_mips:float;
49  stopped_power:float;
50  sleep_power:float;
51  peak_power:float;
52
53  /// Maximum size message that can be sent to a nanoapp
54  max_msg_len:uint;
55
56  /// @see chreGetPlatformId()
57  platform_id:ulong;
58
59  /// @see chreGetVersion()
60  chre_platform_version:uint;
61
62  // TODO: list of connected sensors
63}
64
65table NanoappListRequest {}
66
67table NanoappListEntry {
68  app_id:ulong;
69  version:uint;
70  enabled:bool = true;
71
72  /// Whether the nanoapp is a pre-loaded "system" nanoapp, i.e. one that should
73  /// not show up in the list of nanoapps in the context hub HAL. System
74  /// nanoapps are typically used to leverage CHRE for some device functionality
75  /// and do not interact via the context hub HAL.
76  is_system:bool = false;
77
78  // TODO: memory usage
79}
80
81table NanoappListResponse {
82  nanoapps:[NanoappListEntry] (required);
83}
84
85/// Represents a request for loading a nanoapp.
86/// The nanaopp can either be requested to be loaded via a file or via a buffer.
87/// For loading via a file, the following steps will be taken:
88/// 1. The loader sends a LoadNanoappRequest message to CHRE. app_binary must
89///    be set for legacy purposes, but should be empty. Additionally,
90///    fragment_id and total_app_size are unused in this request. The loading
91///    that happens as part of this request is serialized, but asynchronous
92///    meaning that load requests will be processed in the order they are sent
93///    but multiple requests can be outstanding at any given time.
94/// 2. CHRE stores the filename and waits until its event loop is able to
95///    process the request.
96/// 3. Once ready, the nanoapp will be loaded from the file specified in the
97///    original request and will send a callback indicating the
98///    completion/failure of the request.
99/// For loading via a buffer, loading may optionally be fragmented into multiple
100/// sequential requests, which will follow the following steps:
101/// 1. The loader sends a LoadNanoappRequest message to CHRE. If the request
102///    is fragmented, then the fields fragment_id and total_app_size must
103///    be defined. Once the first fragment is sent to CHRE, all subsequent
104///    fragments must be delivered before a new LoadNanoappRequest can be
105///    issued. If a new request is received while a current request has
106///    outstanding fragments, the current request will be overridden with the
107///    new one.
108/// 2. CHRE preallocates the required amount of memory, and loads app_binary,
109///    appending to already loaded fragments as appropriate.
110/// 3. If the request is fragmented, then the requestor must sequentially send
111///    multiple LoadNanoappRequest with incremental nanoapp binary fragments.
112///    CHRE will respond with LoadNanoappResponse for each request. For
113///    requests starting from the second fragment, all fields except
114///    fragment_id and app_binary should be ignored by CHRE.
115///
116///    Once the LoadNanoappRepsonse for the last fragment is received
117///    by the HAL, the HAL client will receive a callback indicating the
118///    completion/failure of a load request.
119///
120/// If any request fragment is lost, then the entire load request will be
121/// considered to have failed. If the request times out (e.g. the requestor
122/// process crashes), then the load request will be cancelled at CHRE and fail.
123table LoadNanoappRequest {
124  transaction_id:uint;
125
126  app_id:ulong;
127  app_version:uint;
128  target_api_version:uint;
129
130  app_binary:[ubyte] (required);
131
132  /// Fields that are relevant for fragmented loading
133  /// The framgent count starts at 1 and should end at the total number of
134  /// fragments. For clients that do not support fragmented loading, the
135  /// default behavior should be to assume one fragment.
136  fragment_id:uint = 0;
137  total_app_size:uint;
138
139  /// Null-terminated ASCII string containing the file name that contains the
140  /// app binary to be loaded.
141  app_binary_file_name:[byte];
142}
143
144table LoadNanoappResponse {
145  transaction_id:uint;
146
147  /// Denotes whether a load request succeeded or failed.
148  /// If any fragment of a load request fails, the entire load request for
149  /// the same transaction will fail.
150  success:bool;
151
152  /// The fragment count of the load reponse is for.
153  fragment_id:uint = 0;
154
155  // TODO: detailed error code?
156}
157
158table UnloadNanoappRequest {
159  transaction_id:uint;
160
161  app_id:ulong;
162
163  /// Set to true to allow this request to unload nanoapps identified as "system
164  /// nanoapps", i.e. ones with is_system set to true in NanoappListResponse.
165  allow_system_nanoapp_unload:bool;
166}
167
168table UnloadNanoappResponse {
169  transaction_id:uint;
170  success:bool;
171}
172
173/// Represents log messages from CHRE.
174table LogMessage {
175  /// A buffer containing formatted log data. A flat array is used here to avoid
176  /// overhead in serializing and deserializing. The format is as follows:
177  ///
178  /// uint8_t                 - log level (1 = error, 2 = warning,
179  ///                                      3 = info, 4 = debug)
180  /// uint64_t, little-endian - timestamp in nanoseconds
181  /// char[]                  - message to log
182  /// char, \0                - null-terminator
183  ///
184  /// This pattern repeats until the end of the buffer for multiple log
185  /// messages. The last byte will always be a null-terminator. There are no
186  /// padding bytes between these fields. Treat this like a packed struct and be
187  /// cautious with unaligned access when reading/writing this buffer.
188  buffer:[byte];
189}
190
191/// Represents a message sent to CHRE to indicate AP timestamp for time sync
192table TimeSyncMessage {
193  /// Offset between AP and CHRE timestamp
194  offset:long;
195}
196
197/// A request to gather and return debugging information. Only one debug dump
198/// session can be active at a time. Upon accepting a request, zero or more
199/// DebugDumpData messages are generated, followed by a DebugDumpResponse
200/// indicating the completion of the operation.
201table DebugDumpRequest {}
202
203table DebugDumpData {
204  /// Null-terminated ASCII string containing debugging information
205  debug_str:[byte];
206}
207
208table DebugDumpResponse {
209  /// true if the request was accepted and a dump was performed, false if it was
210  /// rejected or failed to complete for some reason
211  success:bool;
212
213  /// The number of DebugDumpData messages sent in this session
214  data_count:uint;
215}
216
217/// A request from CHRE for host to initiate a time sync message
218/// (system feature, platform-specific - not all platforms necessarily use this)
219table TimeSyncRequest {}
220
221/// Request from CHRE to enable direct access to data from the low-power
222/// microphone. On some systems, coordination via the AP (e.g. with
223/// SoundTrigger HAL) is needed to ensure this capability is powered up when
224/// CHRE needs it. The host does not send a response.
225table LowPowerMicAccessRequest {}
226
227/// Notification from CHRE that it no longer needs direct access to low-power
228/// microphone data.
229table LowPowerMicAccessRelease {}
230
231/// An enum describing the setting type.
232enum Setting : byte {
233  LOCATION = 0,
234}
235
236/// An enum describing the state of a setting.
237enum SettingState : byte {
238  DISABLED = 0,
239  ENABLED,
240}
241
242/// Notification from the host that a system setting has changed
243table SettingChangeMessage {
244  /// The setting that has changed
245  setting:Setting = LOCATION;
246
247  /// The new setting value
248  state:SettingState = DISABLED;
249}
250
251/// A union that joins together all possible messages. Note that in FlatBuffers,
252/// unions have an implicit type
253union ChreMessage {
254  NanoappMessage,
255
256  HubInfoRequest,
257  HubInfoResponse,
258
259  NanoappListRequest,
260  NanoappListResponse,
261
262  LoadNanoappRequest,
263  LoadNanoappResponse,
264
265  UnloadNanoappRequest,
266  UnloadNanoappResponse,
267
268  LogMessage,
269
270  TimeSyncMessage,
271
272  DebugDumpRequest,
273  DebugDumpData,
274  DebugDumpResponse,
275
276  TimeSyncRequest,
277
278  LowPowerMicAccessRequest,
279  LowPowerMicAccessRelease,
280
281  SettingChangeMessage,
282}
283
284struct HostAddress {
285  client_id:ushort;
286}
287
288/// The top-level container that encapsulates all possible messages. Note that
289/// per FlatBuffers requirements, we can't use a union as the top-level
290/// structure (root type), so we must wrap it in a table.
291table MessageContainer {
292  message:ChreMessage (required);
293
294  /// The originating or destination client ID on the host side, used to direct
295  /// responses only to the client that sent the request. Although initially
296  /// populated by the requesting client, this is enforced to be the correct
297  /// value by the entity guarding access to CHRE.
298  /// This is wrapped in a struct to ensure that it is always included when
299  /// encoding the message, so it can be mutated by the host daemon.
300  host_addr:HostAddress (required);
301}
302
303root_type MessageContainer;
304