blob: aaf85e94c92a8f0b84f1c1c9780b2cf8f5b0d555 [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 Wasilczyk793fab02020-02-18 15:19:35 -080073
74 /**
75 * Provided service name ({@see BusConfig#name}) either has invalid
76 * format or is not listed in device manifest file.
77 */
78 BAD_SERVICE_NAME,
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -070079 };
80
81 /**
82 * Configuration of the (physical or virtual) CAN bus.
83 *
84 * ISO TP and CAN FD are currently not supported.
85 */
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -080086 struct BusConfig {
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -070087 /**
88 * Name under which ICanBus HIDL service should be published.
89 *
90 * It must consist of only alphanumeric characters and underscore
91 * (a-z, A-Z, 0-9, '_'), at least 1 and at most 32 characters long.
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -080092 *
93 * This field is *not* meant to distinguish between hardware interfaces
94 * nor preselect parameters like bitrate. The only intended side-effect
95 * of changing it should be a different ICanBus HIDL service name and
96 * the HIDL service should make no assumptions on its contents.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -070097 */
98 string name;
99
100 /**
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800101 * Hardware interface configuration.
102 *
103 * This union's discriminator has an equivalent enum
104 * {@see InterfaceType} to express compatibility via
105 * getSupportedInterfaceTypes().
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700106 */
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800107 safe_union InterfaceId {
108 /** Virtual SocketCAN interface. */
109 struct Virtual {
110 /** Interface name, such as vcan0. If the interface doesn't
111 * exist, HAL server must create it.
112 */
113 string ifname;
114 } virtualif;
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700115
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800116 /** Native SocketCAN interface. */
117 safe_union Socketcan {
118 /** Interface name, such as can0. */
119 string ifname;
120 /**
121 * Alternatively to providing {@see ifname}, one may provide a
122 * list of interface serial number suffixes. If there happens to
123 * be a device (like USB2CAN) with a matching serial number
124 * suffix, the HAL service will have to select it.
125 *
126 * Client may utilize this in two ways: by matching against the
127 * entire serial number, or the last few characters (usually
128 * one). The former is better for small-scale test deployments
129 * (with just a handful of vehicles), the latter is good for
130 * larger scale (where a small suffix list may support large
131 * test fleet).
132 */
133 vec<string> serialno;
134 } socketcan;
135
136 /** Serial line CAN interface. */
137 safe_union Slcan {
138 /** Path to a device, such as /dev/ttyUSB0. */
139 string ttyname;
140 /**
141 * List of interface serial number suffixes.
142 * {@see Socketcan::serialno}
143 */
144 vec<string> serialno;
145 } slcan;
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700146
147 /**
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800148 * Proprietary, device-specific interface.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700149 *
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800150 * Non-SocketCAN interfaces should use this variant.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700151 */
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800152 struct Indexed {
153 /** Interface number, 0-based. */
154 uint8_t index;
155 } indexed;
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700156 } interfaceId;
157
158 /**
chrisweir204b8f92020-01-09 15:25:45 -0800159 * Bit rate for CAN communication.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700160 *
chrisweir204b8f92020-01-09 15:25:45 -0800161 * Typical bit rates are: 100000, 125000, 250000, 500000.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700162 *
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800163 * For {@see interfaceId#virtual} and pre-configured
164 * {@see interfaceId#indexed} interfaces this value is ignored.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700165 */
chrisweir204b8f92020-01-09 15:25:45 -0800166 uint32_t bitrate;
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700167 };
168
169 /**
170 * Fetches the list of interface types supported by this HAL server.
171 *
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800172 * @return iftypes The list of supported interface types.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700173 */
174 getSupportedInterfaceTypes() generates (vec<InterfaceType> iftypes);
175
176 /**
177 * Bring up the CAN interface and publish ICanBus server instance.
178 *
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800179 * @param config Configuration of the CAN interface.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700180 * @return result OK if the operation succeeded; error code otherwise.
181 */
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800182 upInterface(BusConfig config) generates (Result result);
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700183
184 /**
185 * Unpublish ICanBus server instance and bring down the CAN interface.
186 *
187 * In case of failure, at least the ICanBus server instance must be
188 * unpublished and resources freed on best-effort basis.
189 *
Tomasz Wasilczykf3da9b62020-02-14 10:54:28 -0800190 * @param name Name of the interface (@see BusConfig#name} to
191 * bring down.
192 * @return success true in case of success, false otherwise.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700193 */
194 downInterface(string name) generates (bool success);
195};