blob: e32e593655974c757c20ff48751ddf9bb5174aed [file] [log] [blame]
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -07001/*
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 */
16package 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 */
28interface ICanController {
29 /**
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -080030 * 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 Wasilczyka27d4e42019-06-07 15:21:02 -070033 */
34 enum InterfaceType : uint8_t {
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -080035 /** Virtual SocketCAN interface. */
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -070036 VIRTUAL,
37
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -080038 /** Native SocketCAN interface. */
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -070039 SOCKETCAN,
40
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -080041 /** Serial line CAN interface. */
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -070042 SLCAN,
43
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -080044 /** Proprietary, device-specific interface. */
45 INDEXED,
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -070046 };
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 Wasilczykf3da9b62020-02-14 10:54:28 -080066 * Provided interface ID (index, name, device path) doesn't exist or
67 * there is no device with a given serial number.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -070068 */
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -080069 BAD_INTERFACE_ID,
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -070070
chrisweir204b8f92020-01-09 15:25:45 -080071 /** Provided bit rate is not supported by the hardware. */
72 BAD_BITRATE,
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -070073 };
74
75 /**
76 * Configuration of the (physical or virtual) CAN bus.
77 *
78 * ISO TP and CAN FD are currently not supported.
79 */
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -080080 struct BusConfig {
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -070081 /**
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 Wasilczykf3da9b62020-02-14 10:54:28 -080086 *
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 Wasilczyka27d4e42019-06-07 15:21:02 -070091 */
92 string name;
93
94 /**
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -080095 * Hardware interface configuration.
96 *
97 * This union's discriminator has an equivalent enum
98 * {@see InterfaceType} to express compatibility via
99 * getSupportedInterfaceTypes().
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700100 */
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800101 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 Wasilczyka27d4e42019-06-07 15:21:02 -0700109
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800110 /** 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 Wasilczyka27d4e42019-06-07 15:21:02 -0700140
141 /**
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800142 * Proprietary, device-specific interface.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700143 *
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800144 * Non-SocketCAN interfaces should use this variant.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700145 */
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800146 struct Indexed {
147 /** Interface number, 0-based. */
148 uint8_t index;
149 } indexed;
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700150 } interfaceId;
151
152 /**
chrisweir204b8f92020-01-09 15:25:45 -0800153 * Bit rate for CAN communication.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700154 *
chrisweir204b8f92020-01-09 15:25:45 -0800155 * Typical bit rates are: 100000, 125000, 250000, 500000.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700156 *
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800157 * For {@see interfaceId#virtual} and pre-configured
158 * {@see interfaceId#indexed} interfaces this value is ignored.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700159 */
chrisweir204b8f92020-01-09 15:25:45 -0800160 uint32_t bitrate;
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700161 };
162
163 /**
164 * Fetches the list of interface types supported by this HAL server.
165 *
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800166 * @return iftypes The list of supported interface types.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700167 */
168 getSupportedInterfaceTypes() generates (vec<InterfaceType> iftypes);
169
170 /**
171 * Bring up the CAN interface and publish ICanBus server instance.
172 *
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800173 * @param config Configuration of the CAN interface.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700174 * @return result OK if the operation succeeded; error code otherwise.
175 */
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800176 upInterface(BusConfig config) generates (Result result);
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700177
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 Wasilczykf3da9b62020-02-14 10:54:28 -0800184 * @param name Name of the interface (@see BusConfig#name} to
185 * bring down.
186 * @return success true in case of success, false otherwise.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700187 */
188 downInterface(string name) generates (bool success);
189};