1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.hardware.contexthub@1.0; 18 19enum Result : uint32_t { 20 OK, // Success 21 UNKNOWN_FAILURE, // Failure, unknown reason 22 BAD_PARAMS, // Parameters not sane 23 NOT_INIT, // Not initialized 24 TRANSACTION_FAILED, // Transaction failed 25 TRANSACTION_PENDING, // Pending transaction, cannot accept a new request 26}; 27 28enum NanoAppFlags : uint32_t { 29 SIGNED = 1 << 0, 30 ENCRYPTED = 1 << 1, 31}; 32 33struct NanoAppBinary { 34 uint64_t appId; // Nanoapp identifier 35 uint32_t appVersion; // Version of the app (semantics defined by app) 36 bitfield<NanoAppFlags> flags; 37 38 // The version of the CHRE API that this nanoApp was compiled against. See 39 // the CHRE API header file chre/version.h for more information. The hub 40 // implementation must use this to confirm compatibility before loading 41 // this nanoApp. 42 uint8_t targetChreApiMajorVersion; 43 uint8_t targetChreApiMinorVersion; 44 45 // Implementation-specific binary nanoapp data. This does not include the 46 // common nanoapp header that contains the app ID, etc., as this data is 47 // explicitly passed through the other fields in this struct. 48 vec<uint8_t> customBinary; 49}; 50 51enum SensorType : uint32_t { 52 RESERVED, 53 ACCELEROMETER, 54 GYROSCOPE, 55 MAGNETOMETER, 56 BAROMETER, 57 PROXIMITY_SENSOR, 58 AMBIENT_LIGHT_SENSOR, 59 STATIONARY_DETECT, 60 INSTANT_MOTION_DETECT, 61 62 GPS = 0x100, 63 // Reserving this space for variants on GPS 64 65 WIFI = 0x200, 66 // Reserving this space for variants on WIFI 67 68 AUDIO = 0x300, 69 // Reserving this space for variants on Audio 70 71 CAMERA = 0x400, 72 // Reserving this space for variants on Camera 73 74 BLE = 0x500, 75 // Reserving this space for variants on Bluetooth Low Energy 76 77 WWAN = 0x600, 78 // Reserving this space for variants on WWAN 79 80 PRIVATE_SENSOR_BASE = 0x10000, 81 // Sensor types beyond PRIVATE_SENSOR_BASE are custom types 82}; 83 84struct PhysicalSensor{ 85 SensorType sensorType; // From the definitions above eg: 100 86 string type; // Type as a string. eg: "GPS" 87 string name; // Identifier eg: "Bosch BMI160" 88 string vendor; // Vendor : eg "STM" 89 uint32_t version; // Version : eg 0x1001 90 uint32_t fifoReservedCount; // Batching possible in hardware. Please 91 // note that here hardware does not include 92 // the context hub itself. Thus, this 93 // definition may be different from say the 94 // number advertised in the sensors HAL 95 // which allows for batching in a hub. 96 uint32_t fifoMaxCount; // Maximum number of batchable events. 97 uint64_t minDelayMs; // In milliseconds, corresponding to highest 98 // sampling freq. 99 uint64_t maxDelayMs; // In milliseconds, corresponds to minimum 100 // sampling frequency 101 float peakPowerMw; // At max frequency & no batching, power 102 // in milliwatts 103}; 104 105struct ContextHub { 106 string name; // Descriptive name eg: "Awesome Hub #1" 107 string vendor; // Hub hardware vendor eg: "Qualcomm" 108 string toolchain; // Toolchain to make binaries eg: "gcc ARM" 109 uint32_t platformVersion; // Version of the hardware : eg 0x20 110 uint32_t toolchainVersion; // Version of the toolchain : eg: 0x484 111 uint32_t hubId; // A device unique ID for this hub 112 113 float peakMips; // Peak MIPS platform can deliver 114 float stoppedPowerDrawMw; // If stopped, retention power, milliwatts 115 float sleepPowerDrawMw; // If sleeping, retention power, milliwatts 116 float peakPowerDrawMw; // For a busy CPU, power in milliwatts 117 118 vec<PhysicalSensor> connectedSensors; // Array of connected sensors 119 120 uint32_t maxSupportedMsgLen;// This is the maximum size of the message that can 121 // be sent to the hub in one chunk (in bytes) 122 123 // Machine-readable CHRE platform ID, returned to nanoapps in the CHRE API 124 // function call chreGetPlatformId(). This field pairs with 125 // chreApiMajorVersion, chreApiMinorVersion, and chrePatchVersion to fully 126 // specify the CHRE implementation version. See also the CHRE API header 127 // file chre/version.h. 128 uint64_t chrePlatformId; 129 130 // The version of the CHRE implementation returned to nanoApps in the CHRE 131 // API function call chreGetVersion(). The major and minor version specify 132 // the implemented version of the CHRE API, while the patch version 133 // describes the implementation version within the scope of the platform 134 // ID. See also the CHRE API header file chre/version.h. 135 uint8_t chreApiMajorVersion; 136 uint8_t chreApiMinorVersion; 137 uint16_t chrePatchVersion; 138}; 139 140enum HostEndPoint : uint16_t { 141 BROADCAST = 0xFFFF, // The message endpoint is a broadcast end point. 142 // This value must never be used for a message from 143 // the host to the hub. 144 // If BROADCAST is specified as a destination for a 145 // message from the context hub to the ContextHub 146 // service, the message must be broadcast to all 147 // registered clients by the Context Hub service. 148 UNSPECIFIED = 0xFFFE, // The message endpoint is unspecified. This value 149 // must not be used for messages from the hub to host. 150 // This value may be used for messages from the host 151 // to the hub. 152}; 153 154struct ContextHubMsg { 155 uint64_t appName; // Intended recipient (appId) 156 uint16_t hostEndPoint; // identifier for the endpoint. (also see enum HostEndPoint) 157 uint32_t msgType; // Identifier for message 158 vec<uint8_t> msg; // Message body 159}; 160 161enum HubMemoryType : uint32_t { 162 MAIN = 0, // Main memory 163 SECONDARY = 1, // Secondary memory 164 TCM = 2, // Tightly coupled memory 165}; 166 167enum HubMemoryFlag : uint32_t { 168 READ = 1 << 0, // Readable 169 WRITE = 1 << 1, // Writable 170 EXEC = 1 << 2, // Executable 171}; 172 173struct MemRange { 174 uint32_t totalBytes; // Total capacity in bytes 175 uint32_t freeBytes; // Free capacity in bytes 176 HubMemoryType type; // Type of memory, see HubMemoryType 177 bitfield<HubMemoryFlag> flags; 178}; 179 180enum AsyncEventType : uint32_t { 181 RESTARTED = 1, // Hub restarted unexpectedly 182}; 183 184enum TransactionResult : int32_t { 185 SUCCESS, // Successful completion of transaction 186 FAILURE, // Failed transaction 187}; 188 189struct HubAppInfo { 190 uint64_t appId; // Identifier of the app 191 uint32_t version; // Version of the app 192 vec<MemRange> memUsage; // Memory used by this app 193 bool enabled; // true if the app is currently enabled and running, 194 // or false if in the loaded but disabled state 195}; 196 197