Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | package android.hardware.automotive.can@1.0; |
| 17 | |
| 18 | /** |
| 19 | * Represents a CAN controller that's capable of configuring CAN bus interfaces. |
| 20 | * |
| 21 | * The goal of this service is to configure CAN interfaces and bring up HIDL |
| 22 | * server instances of ICanBus for each one that's up. |
| 23 | * |
| 24 | * Providing an ICanController interface to configure CAN buses is optional. |
| 25 | * A system can elect to publish only ICanBus if the hardware is hardcoded |
| 26 | * for a specific application. |
| 27 | */ |
| 28 | interface ICanController { |
| 29 | /** |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 30 | * Type of an interface, an equivalent to BusConfig::InterfaceId |
| 31 | * union discriminator. Defines a number of specific standard hardware |
| 32 | * families and a generic catch-all type of {@see INDEXED}. |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 33 | */ |
| 34 | enum InterfaceType : uint8_t { |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 35 | /** Virtual SocketCAN interface. */ |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 36 | VIRTUAL, |
| 37 | |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 38 | /** Native SocketCAN interface. */ |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 39 | SOCKETCAN, |
| 40 | |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 41 | /** Serial line CAN interface. */ |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 42 | SLCAN, |
| 43 | |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 44 | /** Proprietary, device-specific interface. */ |
| 45 | INDEXED, |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | enum Result : uint8_t { |
| 49 | OK, |
| 50 | |
| 51 | /** |
| 52 | * General error class, if others are not applicable. |
| 53 | */ |
| 54 | UNKNOWN_ERROR, |
| 55 | |
| 56 | /** |
| 57 | * Up request was called out of order (i.e. trying to up the |
| 58 | * interface twice). |
| 59 | */ |
| 60 | INVALID_STATE, |
| 61 | |
| 62 | /** Interface type is not supported. */ |
| 63 | NOT_SUPPORTED, |
| 64 | |
| 65 | /** |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 66 | * Provided interface ID (index, name, device path) doesn't exist or |
| 67 | * there is no device with a given serial number. |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 68 | */ |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 69 | BAD_INTERFACE_ID, |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 70 | |
chrisweir | 204b8f9 | 2020-01-09 15:25:45 -0800 | [diff] [blame] | 71 | /** Provided bit rate is not supported by the hardware. */ |
| 72 | BAD_BITRATE, |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | /** |
| 76 | * Configuration of the (physical or virtual) CAN bus. |
| 77 | * |
| 78 | * ISO TP and CAN FD are currently not supported. |
| 79 | */ |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 80 | struct BusConfig { |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 81 | /** |
| 82 | * Name under which ICanBus HIDL service should be published. |
| 83 | * |
| 84 | * It must consist of only alphanumeric characters and underscore |
| 85 | * (a-z, A-Z, 0-9, '_'), at least 1 and at most 32 characters long. |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 86 | * |
| 87 | * This field is *not* meant to distinguish between hardware interfaces |
| 88 | * nor preselect parameters like bitrate. The only intended side-effect |
| 89 | * of changing it should be a different ICanBus HIDL service name and |
| 90 | * the HIDL service should make no assumptions on its contents. |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 91 | */ |
| 92 | string name; |
| 93 | |
| 94 | /** |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 95 | * Hardware interface configuration. |
| 96 | * |
| 97 | * This union's discriminator has an equivalent enum |
| 98 | * {@see InterfaceType} to express compatibility via |
| 99 | * getSupportedInterfaceTypes(). |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 100 | */ |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 101 | safe_union InterfaceId { |
| 102 | /** Virtual SocketCAN interface. */ |
| 103 | struct Virtual { |
| 104 | /** Interface name, such as vcan0. If the interface doesn't |
| 105 | * exist, HAL server must create it. |
| 106 | */ |
| 107 | string ifname; |
| 108 | } virtualif; |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 109 | |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 110 | /** Native SocketCAN interface. */ |
| 111 | safe_union Socketcan { |
| 112 | /** Interface name, such as can0. */ |
| 113 | string ifname; |
| 114 | /** |
| 115 | * Alternatively to providing {@see ifname}, one may provide a |
| 116 | * list of interface serial number suffixes. If there happens to |
| 117 | * be a device (like USB2CAN) with a matching serial number |
| 118 | * suffix, the HAL service will have to select it. |
| 119 | * |
| 120 | * Client may utilize this in two ways: by matching against the |
| 121 | * entire serial number, or the last few characters (usually |
| 122 | * one). The former is better for small-scale test deployments |
| 123 | * (with just a handful of vehicles), the latter is good for |
| 124 | * larger scale (where a small suffix list may support large |
| 125 | * test fleet). |
| 126 | */ |
| 127 | vec<string> serialno; |
| 128 | } socketcan; |
| 129 | |
| 130 | /** Serial line CAN interface. */ |
| 131 | safe_union Slcan { |
| 132 | /** Path to a device, such as /dev/ttyUSB0. */ |
| 133 | string ttyname; |
| 134 | /** |
| 135 | * List of interface serial number suffixes. |
| 136 | * {@see Socketcan::serialno} |
| 137 | */ |
| 138 | vec<string> serialno; |
| 139 | } slcan; |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 140 | |
| 141 | /** |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 142 | * Proprietary, device-specific interface. |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 143 | * |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 144 | * Non-SocketCAN interfaces should use this variant. |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 145 | */ |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 146 | struct Indexed { |
| 147 | /** Interface number, 0-based. */ |
| 148 | uint8_t index; |
| 149 | } indexed; |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 150 | } interfaceId; |
| 151 | |
| 152 | /** |
chrisweir | 204b8f9 | 2020-01-09 15:25:45 -0800 | [diff] [blame] | 153 | * Bit rate for CAN communication. |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 154 | * |
chrisweir | 204b8f9 | 2020-01-09 15:25:45 -0800 | [diff] [blame] | 155 | * Typical bit rates are: 100000, 125000, 250000, 500000. |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 156 | * |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 157 | * For {@see interfaceId#virtual} and pre-configured |
| 158 | * {@see interfaceId#indexed} interfaces this value is ignored. |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 159 | */ |
chrisweir | 204b8f9 | 2020-01-09 15:25:45 -0800 | [diff] [blame] | 160 | uint32_t bitrate; |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | /** |
| 164 | * Fetches the list of interface types supported by this HAL server. |
| 165 | * |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 166 | * @return iftypes The list of supported interface types. |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 167 | */ |
| 168 | getSupportedInterfaceTypes() generates (vec<InterfaceType> iftypes); |
| 169 | |
| 170 | /** |
| 171 | * Bring up the CAN interface and publish ICanBus server instance. |
| 172 | * |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 173 | * @param config Configuration of the CAN interface. |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 174 | * @return result OK if the operation succeeded; error code otherwise. |
| 175 | */ |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 176 | upInterface(BusConfig config) generates (Result result); |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 177 | |
| 178 | /** |
| 179 | * Unpublish ICanBus server instance and bring down the CAN interface. |
| 180 | * |
| 181 | * In case of failure, at least the ICanBus server instance must be |
| 182 | * unpublished and resources freed on best-effort basis. |
| 183 | * |
Tomasz Wasilczyk | f3da9b6 | 2020-02-14 10:54:28 -0800 | [diff] [blame^] | 184 | * @param name Name of the interface (@see BusConfig#name} to |
| 185 | * bring down. |
| 186 | * @return success true in case of success, false otherwise. |
Tomasz Wasilczyk | a27d4e4 | 2019-06-07 15:21:02 -0700 | [diff] [blame] | 187 | */ |
| 188 | downInterface(string name) generates (bool success); |
| 189 | }; |