blob: 0c6f53eff379a9d6258e21e1263df6618fe4a712 [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 /**
30 * Type of an interface, a mean to express the domain of device address.
31 */
32 enum InterfaceType : uint8_t {
33 /**
34 * Virtual SocketCAN interface.
35 *
36 * The address is an interface name, such as vcan0. If the interface
37 * doesn't exist, HAL server must create it.
38 *
39 * Valid InterfaceIdentifier types:
40 * - address.
41 */
42 VIRTUAL,
43
44 /**
45 * Native SocketCAN interface.
46 *
47 * The address is an interface name, such as can0.
48 *
49 * Valid InterfaceIdentifier types:
50 * - address;
51 * - serialno.
52 */
53 SOCKETCAN,
54
55 /**
56 * Serial-based interface.
57 *
58 * The address is a patch to a device, such as /dev/ttyUSB0.
59 *
60 * Valid InterfaceIdentifier types:
61 * - address;
62 * - serialno.
63 */
64 SLCAN,
65
66 /**
67 * Proprietary interface, specific to the hardware system Android
68 * is running on. Instead of using address field, the interface is
69 * addressed with 0-based index.
70 *
71 * Valid InterfaceIdentifier types:
72 * - index
73 */
74 INDEXED
75 };
76
77 enum Result : uint8_t {
78 OK,
79
80 /**
81 * General error class, if others are not applicable.
82 */
83 UNKNOWN_ERROR,
84
85 /**
86 * Up request was called out of order (i.e. trying to up the
87 * interface twice).
88 */
89 INVALID_STATE,
90
91 /** Interface type is not supported. */
92 NOT_SUPPORTED,
93
94 /**
95 * Provided address (interface name, device path) doesn't exist or there
96 * is no device with a given serial no.
97 */
98 BAD_ADDRESS,
99
chrisweir204b8f92020-01-09 15:25:45 -0800100 /** Provided bit rate is not supported by the hardware. */
101 BAD_BITRATE,
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700102 };
103
104 /**
105 * Configuration of the (physical or virtual) CAN bus.
106 *
107 * ISO TP and CAN FD are currently not supported.
108 */
109 struct BusConfiguration {
110 /**
111 * Name under which ICanBus HIDL service should be published.
112 *
113 * It must consist of only alphanumeric characters and underscore
114 * (a-z, A-Z, 0-9, '_'), at least 1 and at most 32 characters long.
115 */
116 string name;
117
118 /**
119 * Type of the hardware (or virtual) CAN interface.
120 */
121 InterfaceType iftype;
122
123 /**
124 * Identification of hardware interface to configure.
125 */
126 safe_union InterfaceIdentifier {
127 /**
128 * Interface name or other mean of identification of the specific
129 * interface port. Syntax depends on {@see iftype}, for details
130 * {@see InterfaceType}.
131 */
132 string address;
133
134 /**
135 * Numerical identifier of interface, used for InterfaceType#INDEXED.
136 */
137 uint8_t index;
138
139 /**
140 * Alternatively to providing {@see address}, one may provide a list
141 * of interface serial number suffixes. If there happens to be
142 * a device (like USB2CAN) with a matching serial number suffix,
143 * it gets selected.
144 *
145 * Client may utilize this in two ways: by matching against the
146 * entire serial number, or the last few characters (usually one).
147 * The former is better for small-scale test deployments (with just
148 * a handful of vehicles), the latter is good for larger scale
149 * (where a small suffix list may support large test fleet).
150 */
151 vec<string> serialno;
152 } interfaceId;
153
154 /**
chrisweir204b8f92020-01-09 15:25:45 -0800155 * Bit rate for CAN communication.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700156 *
chrisweir204b8f92020-01-09 15:25:45 -0800157 * Typical bit rates are: 100000, 125000, 250000, 500000.
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700158 *
159 * For virtual interfaces this value is ignored.
160 */
chrisweir204b8f92020-01-09 15:25:45 -0800161 uint32_t bitrate;
Tomasz Wasilczyka27d4e42019-06-07 15:21:02 -0700162 };
163
164 /**
165 * Fetches the list of interface types supported by this HAL server.
166 *
167 * @return iftypes The list of supported interface types
168 */
169 getSupportedInterfaceTypes() generates (vec<InterfaceType> iftypes);
170
171 /**
172 * Bring up the CAN interface and publish ICanBus server instance.
173 *
174 * @param config Configuration of the CAN interface
175 * @return result OK if the operation succeeded; error code otherwise.
176 */
177 upInterface(BusConfiguration config) generates (Result result);
178
179 /**
180 * Unpublish ICanBus server instance and bring down the CAN interface.
181 *
182 * In case of failure, at least the ICanBus server instance must be
183 * unpublished and resources freed on best-effort basis.
184 *
185 * @param name Name of the interface (@see BusConfiguration#name} to
186 * bring down
187 * @return success true in case of success, false otherwise
188 */
189 downInterface(string name) generates (bool success);
190};