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/// Represents V2 log messages from CHRE. 297table LogMessageV2 { 298 /// A buffer containing formatted log data. A flat array is used here to avoid 299 /// overhead in serializing and deserializing. The format is as follows: 300 /// 301 /// uint8_t - Log metadata, encoded as follows: 302 /// [EI(Upper nibble) | Level(Lower nibble)] 303 /// * EI: Encoding indicator (eg: via tokenization) 304 /// (0 = No encoding, 1 = Tokenized log) 305 /// * LogBuffer log level (1 = error, 2 = warn, 306 /// 3 = info, 4 = debug, 307 /// 5 = verbose) 308 /// uint32_t, little-endian - timestamp in milliseconds 309 /// char[] - Log data buffer 310 /// 311 /// The log data buffer format is as follows: 312 /// * Unencoded (string) logs: The log buffer can be interpreted as a NULL 313 /// terminated string (eg: pass to string manipulation functions, get its 314 /// size via strlen(), etc.). 315 /// 316 /// * Encoded logs: The first byte of the log buffer indicates the size of 317 /// the actual encoded data to follow. For example, if a tokenized log of 318 /// size 24 bytes were to be represented, a buffer of size 25 bytes would 319 /// be needed to encode this as: [Size(1B) | Data(24B)]. A decoder would 320 /// then have to decode this starting from a 1 byte offset from the 321 /// received buffer. 322 /// 323 /// This pattern repeats until the end of the buffer for multiple log 324 /// messages. The last byte will always be a null-terminator. There are no 325 /// padding bytes between these fields. Treat this like a packed struct and be 326 /// cautious with unaligned access when reading/writing this buffer. 327 /// Note that the log message might not be null-terminated if an encoding is 328 /// used. 329 buffer:[byte]; 330 331 /// The number of logs dropped since CHRE started 332 num_logs_dropped:uint; 333} 334 335// A request to perform basic internal self-test in CHRE. The test to be performed 336// is platform-dependent, and can be used to check if the system is functioning 337// properly. This message should be used for debugging/testing. 338table SelfTestRequest {} 339table SelfTestResponse { 340 // True if the self-test succeeded. 341 success:bool; 342} 343 344// Message sent whenever a host endpoint has connected with the Context Hub. 345// CHRE may receive messages from this host afterwards. 346table HostEndpointConnected { 347 /// The host-side endpoint that has connected to the framework. 348 host_endpoint:ushort; 349 350 /// The type of host endpoint, which should be any of the CHRE_HOST_ENDPOINT_TYPE_* 351 /// values defined in the chre_api/chre/event.h. 352 type:ubyte; 353 354 /// The (optional) package name associated with the host endpoint. 355 package_name:[byte]; 356 357 /// The (optional) attribution tag associated with this host. 358 attribution_tag:[byte]; 359} 360 361// Message sent whenever a host endpoint has disconnected from the Context Hub. 362table HostEndpointDisconnected { 363 /// The host-side endpoint that has disconnected from the framework. 364 host_endpoint:ushort; 365} 366 367// Represents metric messages from CHRE 368table MetricLog { 369 // A unique identifier for the encoded metric message. 370 id:uint; 371 372 // The metric data, which is encoded using a custom-defined protocol. This 373 // same protocol must be used to decode the data at the host side for consumption. 374 encoded_metric:[byte]; 375} 376 377// A container to store batched metrics messages 378table BatchedMetricLog { 379 // The batched metrics 380 metrics: [MetricLog]; 381} 382 383// NAN enable request sent from CHRE to the host. 384table NanConfigurationRequest { 385 enable:bool; 386} 387 388// NAN status message sent from the host to CHRE whenever a change in the NAN 389// enabled state is detected. Note that this update can be sent to CHRE either 390// as a response to a configuration request, or from out of band if NAN was 391// disabled by an external agent. 392table NanConfigurationUpdate { 393 enabled:bool; 394} 395 396/// A union that joins together all possible messages. Note that in FlatBuffers, 397/// unions have an implicit type 398union ChreMessage { 399 NanoappMessage, 400 401 HubInfoRequest, 402 HubInfoResponse, 403 404 NanoappListRequest, 405 NanoappListResponse, 406 407 LoadNanoappRequest, 408 LoadNanoappResponse, 409 410 UnloadNanoappRequest, 411 UnloadNanoappResponse, 412 413 LogMessage, 414 415 TimeSyncMessage, 416 417 DebugDumpRequest, 418 DebugDumpData, 419 DebugDumpResponse, 420 421 TimeSyncRequest, 422 423 LowPowerMicAccessRequest, 424 LowPowerMicAccessRelease, 425 426 SettingChangeMessage, 427 428 LogMessageV2, 429 430 SelfTestRequest, 431 SelfTestResponse, 432 433 HostEndpointConnected, 434 HostEndpointDisconnected, 435 436 MetricLog, 437 BatchedMetricLog, 438 439 NanConfigurationRequest, 440 NanConfigurationUpdate, 441} 442 443struct HostAddress { 444 client_id:ushort; 445} 446 447/// The top-level container that encapsulates all possible messages. Note that 448/// per FlatBuffers requirements, we can't use a union as the top-level 449/// structure (root type), so we must wrap it in a table. 450table MessageContainer { 451 message:ChreMessage (required); 452 453 /// The originating or destination client ID on the host side, used to direct 454 /// responses only to the client that sent the request. Although initially 455 /// populated by the requesting client, this is enforced to be the correct 456 /// value by the entity guarding access to CHRE. 457 /// This is wrapped in a struct to ensure that it is always included when 458 /// encoding the message, so it can be mutated by the host daemon. 459 host_addr:HostAddress (required); 460} 461 462root_type MessageContainer; 463