huangcm
2025-07-03 a76b2fadf6ad4adf86e241e3753a63efe03ef80c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.hardware.usb@1.0;
 
 
enum Status : uint32_t {
    SUCCESS = 0,
 
    /**
     * error value when the HAL operation fails for reasons not listed here.
     */
    ERROR = 1,
 
    /**
     * error value returned when input argument is invalid.
     */
    INVALID_ARGUMENT = 2,
 
    /**
     * error value returned when role string is unrecognized.
     */
    UNRECOGNIZED_ROLE = 3,
};
 
/**
 * Denotes the Port role type.
 * Passed as an argument for functions used to query or change port roles.
 */
enum PortRoleType : uint32_t {
    /**
     * Denotes the data role of the port.
     * The port can either be a "host" or a "device" for data.
     * This maps to the PortDataRole enum.
     */
    DATA_ROLE = 0,
 
    /**
     * Denotes the power role of the port.
     * The port can either be a "source" or "sink" for power.
     * This maps to PortPowerRole enum.
     */
    POWER_ROLE = 1,
 
    /**
     * USB ports can be a pure DFP port which can only act
     * as a host. A UFP port which can only act as a device.
     * Or a dual role ports which can either can as a host or
     * a device. This property is used to mention them.
     */
    MODE = 2,
};
 
@export
enum PortDataRole : uint32_t {
    /**
     * Indicates that the port does not have a data role.
     * In case of DRP, the current data role of the port is only resolved
     * when the type-c handshake happens.
     */
    NONE = 0,
 
    /**
     * Indicates that the port is acting as a host for data.
     */
    HOST = 1,
 
    /**
     * Indicated that the port is acting as a device for data.
     */
    DEVICE = 2,
 
    NUM_DATA_ROLES = 3,
};
 
@export
enum PortPowerRole : uint32_t {
    /**
     * Indicates that the port does not have a power role.
     * In case of DRP, the current power role of the port is only resolved
     * when the type-c handshake happens.
     */
    NONE = 0,
 
    /**
     * Indicates that the port is supplying power to the other port.
     */
    SOURCE = 1,
 
    /**
     * Indicates that the port is sinking power from the other port.
     */
    SINK = 2,
 
    NUM_POWER_ROLES = 3,
};
 
@export
enum PortMode : uint32_t {
    /**
     * Indicates that the port does not have a mode.
     * In case of DRP, the current mode of the port is only resolved
     * when the type-c handshake happens.
     */
    NONE = 0,
    /**
     * Indicates that port can only act as device for data and sink for power.
     */
    UFP = 1,
 
    /**
     * Indicates the port can only act as host for data and source for power.
     */
    DFP = 2,
 
    /**
     * Indicates can either act as UFP or DFP at a given point of time.
     */
    DRP = 3,
 
    NUM_MODES = 4,
};
 
/**
 * Used as a container to send port role information.
 */
struct PortRole {
    /**
     * Indicates the type of Port Role.
     * Maps to the PortRoleType enum.
     */
    PortRoleType type;
 
    /**
     * when type is HAL_USB_DATA_ROLE pass values from enum PortDataRole.
     * when type is HAL_USB_POWER_ROLE pass values from enum PortPowerRole.
     * when type is HAL_USB_MODE pass values from enum PortMode.
     */
    uint32_t role;
};
 
/**
 * Used as the container to report data back to the caller.
 * Represents the current connection status of a single USB port.
 */
struct PortStatus {
     /**
      * Name of the port.
      * Used as the port's id by the caller.
      */
     string portName;
 
     /**
      * Data role of the port.
      */
     PortDataRole currentDataRole;
 
     /**
      * Power Role of thte port.
      */
     PortPowerRole currentPowerRole;
 
     /**
      * Mode in which the port is connected.
      * Can be UFP or DFP.
      */
     PortMode currentMode;
 
     /**
      * True indicates that the port's mode can
      * be changed. False otherwise.
      */
     bool canChangeMode;
 
     /**
      * True indicates that the port's data role
      * can be changed. False otherwise.
      * For example, true if Type-C PD PD_SWAP
      * is supported.
      */
     bool canChangeDataRole;
 
     /**
      * True indicates that the port's power role
      * can be changed. False otherwise.
      * For example, true if Type-C PD PR_SWAP
      * is supported.
      */
     bool canChangePowerRole;
 
     /**
      * Identifies the type of the local port.
      *
      * UFP - Indicates that port can only act as device for
      *       data and sink for power.
      * DFP - Indicates the port can only act as host for data
      *       and source for power.
      * DRP - Indicates can either act as UFP or DFP at a
      *       given point of time.
      */
      PortMode supportedModes;
};