1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef USBD_TYPE_H 17 #define USBD_TYPE_H 18 19 #include <stdint.h> 20 #include <stdlib.h> 21 22 #define USB_MAX_INTERFACES 32 23 24 #define HDF_USB_USBD_DESC "hdf.usb.usbd" 25 #define HDF_USB_USBFN_DESC "hdf.usb.usbfn" 26 27 /** 28 * Bitmask used for extracting the USBEndpoint direction from it's address 29 */ 30 static const int32_t USB_ENDPOINT_DIR_MASK = 0x80; 31 32 /** 33 * Used to signify direction of data for USBEndpoint is IN, device to host 34 */ 35 static const int32_t USB_ENDPOINT_DIR_IN = 0x80; 36 37 /** 38 * Used to signify direction of data for USBEndpoint is OUT, host to device 39 */ 40 static const int32_t USB_ENDPOINT_DIR_OUT = 0; 41 42 typedef void (*UsbdRequestCallback)(uint8_t *requestArg); 43 44 enum UsbdBulkCbCmd { 45 CMD_USBD_BULK_CALLBACK_READ, 46 CMD_USBD_BULK_CALLBACK_WRITE, 47 }; 48 49 enum UsbdDeviceAction { 50 ACT_DEVUP = 0, 51 ACT_DEVDOWN, 52 ACT_UPDEVICE, 53 ACT_DOWNDEVICE, 54 }; 55 56 enum UsbdCmd { 57 CMD_BIND_USB_SUBSCRIBER = 0, 58 CMD_UNBIND_USB_SUBSCRIBER, 59 CMD_NOTIFY_DEVICE_DOWN, 60 CMD_NOTIFY_DEVICE_FOUND, 61 CMD_NOTIFY_PORT_CHANGED, 62 CMD_CLASS_CTRL_SYNC, 63 CMD_FUN_ADD_FUNCTION, 64 CMD_FUN_ADD_INTERFACE, 65 CMD_FUN_CLAIM_INTERFACE, 66 CMD_FUN_CLOSE_DEVICE, 67 CMD_FUN_CONNECT_DEVICE, 68 CMD_FUN_DELETE_INTERFACE, 69 CMD_FUN_GET_CONFIG, 70 CMD_FUN_GET_CURRENT_FUNCTIONS, 71 CMD_FUN_GET_DESCRIPTOR, 72 CMD_FUN_GET_FILEDESCRIPTOR, 73 CMD_FUN_GET_DEVICE_DESCRIPTOR, 74 CMD_FUN_GET_CONFIG_DESCRIPTOR, 75 CMD_FUN_GET_STRING_DESCRIPTOR, 76 CMD_FUN_GET_INTERFACE_DESCRIPTOR, 77 CMD_FUN_GET_ENDPOINT_DESCRIPTOR, 78 CMD_FUN_HANDLE_REQUEST, 79 CMD_FUN_OPEN_DEVICE, 80 CMD_FUN_RELEASE_INTERFACE, 81 CMD_FUN_REMOVE_FUNCTION, 82 CMD_FUN_REMOVE_INTERFACE, 83 CMD_FUN_SEND_BULK_READ_ASYNC, 84 CMD_FUN_SEND_BULK_READ_SYNC, 85 CMD_FUN_SEND_BULK_WRITE_ASYNC, 86 CMD_FUN_SEND_BULK_WRITE_SYNC, 87 CMD_FUN_SEND_CTRL_READ_ASYNC, 88 CMD_FUN_SEND_CTRL_READ_SYNC, 89 CMD_FUN_SEND_CTRL_REQUEST_ASYNC, 90 CMD_FUN_SEND_CTRL_REQUEST_SYNC, 91 CMD_FUN_SEND_CTRL_WRITE_ASYNC, 92 CMD_FUN_SEND_CTRL_WRITE_SYNC, 93 CMD_FUN_SEND_INTERRUPT_READ_ASYNC, 94 CMD_FUN_SEND_INTERRUPT_READ_SYNC, 95 CMD_FUN_SEND_INTERRUPT_WRITE_ASYNC, 96 CMD_FUN_SEND_INTERRUPT_WRITE_SYNC, 97 CMD_FUN_SEND_ISO_READ_ASYNC, 98 CMD_FUN_SEND_ISO_READ_SYNC, 99 CMD_FUN_SEND_ISO_WRITE_ASYNC, 100 CMD_FUN_SEND_ISO_WRITE_SYNC, 101 CMD_FUN_SET_CONFIG, 102 CMD_FUN_SET_CURRENT_FUNCTIONS, 103 CMD_FUN_SET_INTERFACE, 104 CMD_ADD_INTERFACE, 105 CMD_REMOVE_INTERFACE, 106 CMD_GET_CHARGE_STATE, 107 CMD_GET_DEVICES, 108 CMD_HAS_RIGHT, 109 CMD_READ_DATA_SYNC, 110 CMD_READ_PARM, 111 CMD_SET_BAUDRATE, 112 CMD_SET_ROLE, 113 CMD_QUERY_PORT, 114 CMD_STD_CTRL_GET_CONFIGURATION, 115 CMD_STD_CTRL_GET_DESCRIPTOR_ASYNC, 116 CMD_STD_CTRL_GET_DESCRIPTOR_CMD, 117 CMD_STD_CTRL_GET_INTERFACE, 118 CMD_STD_CTRL_GET_STATUS_CMD, 119 CMD_NOTIFY_SUBSCRIBER_DEVICE_EVENT, 120 CMD_FUN_REQUEST_QUEUE, 121 CMD_FUN_REQUEST_WAIT, 122 CMD_FUN_REQUEST_CANCEL, 123 CMD_FUN_REG_BULK_CALLBACK, 124 CMD_FUN_UNREG_BULK_CALLBACK, 125 CMD_FUN_BULK_CANCEL, 126 }; 127 128 struct UsbdDevice { 129 uint8_t busNum; 130 uint8_t devAddr; 131 uint8_t interface; 132 uint8_t endPoint; 133 }; 134 struct UsbdPeripheral { 135 uint8_t busNum; 136 uint8_t devAddr; 137 uint8_t iSerialNumber; 138 }; 139 struct UsbdPort { 140 uint8_t modes; 141 uint8_t roles; 142 }; 143 struct UsbdRequestDataSync { 144 uint8_t endPoint; 145 int32_t *requested; 146 uint8_t *data; 147 int32_t length; 148 uint32_t timeout; 149 }; 150 struct UsbdRequestDataAsync { 151 unsigned char endPoint; 152 unsigned char *buffer; 153 int32_t length; 154 int32_t numIsoPackets; 155 UsbdRequestCallback callback; 156 uint8_t *userData; 157 uint32_t timeout; 158 }; 159 struct UsbdControlRequestSetupData { 160 uint8_t requestType; 161 uint8_t requestCmd; 162 uint16_t value; 163 uint16_t index; 164 uint8_t *data; 165 uint16_t length; 166 uint32_t timeout; 167 }; 168 struct UsbdDescriptorParam { 169 uint8_t descType; 170 uint8_t descIndex; 171 int32_t length; 172 }; 173 struct UsbdDescriptorHeader { 174 uint8_t bLength; 175 uint8_t bDescriptorType; 176 } __attribute__((packed)); 177 178 struct UsbdDeviceDescriptor { 179 uint8_t bLength; 180 uint8_t bDescriptorType; 181 uint16_t bcdUSB; 182 uint8_t bDeviceClass; 183 uint8_t bDeviceSubClass; 184 uint8_t bDeviceProtocol; 185 uint8_t bMaxPacketSize0; 186 uint16_t idVendor; 187 uint16_t idProduct; 188 uint16_t bcdDevice; 189 uint8_t iManufacturer; 190 uint8_t iProduct; 191 uint8_t iSerialNumber; 192 uint8_t bNumConfigurations; 193 } __attribute__((packed)); 194 195 struct UsbdConfigDescriptor { 196 uint8_t bLength; 197 uint8_t bDescriptorType; 198 uint16_t wTotalLength; 199 uint8_t bNumInterfaces; 200 uint8_t bConfigurationValue; 201 uint8_t iConfiguration; 202 uint8_t bmAttributes; 203 uint8_t bMaxPower; 204 } __attribute__((packed)); 205 206 struct UsbdInterfaceDescriptor { 207 uint8_t bLength; 208 uint8_t bDescriptorType; 209 uint8_t bInterfaceNumber; 210 uint8_t bAlternateSetting; 211 uint8_t bNumEndpoints; 212 uint8_t bInterfaceClass; 213 uint8_t bInterfaceSubClass; 214 uint8_t bInterfaceProtocol; 215 uint8_t iInterface; 216 } __attribute__((packed)); 217 218 struct UsbdEndpointDescriptor { 219 uint8_t bLength; 220 uint8_t bDescriptorType; 221 uint8_t bEndpointAddress; 222 uint8_t bmAttributes; 223 uint16_t wMaxPacketSize; 224 uint8_t bInterval; 225 } __attribute__((packed)); 226 227 struct UsbNotifyServiceInfo { 228 uint32_t length; 229 230 int32_t devNum; 231 int32_t busNum; 232 233 int32_t interfaceLength; 234 uint8_t interfaceNumber[USB_MAX_INTERFACES]; 235 } __attribute__((packed)); 236 237 enum PortRoleType { DATA_ROLE, POWER_ROLE, MODE }; 238 239 enum PortPowerRole { SOURCE, SINK }; 240 241 enum PortMode { HOST, DEVICE, OTG }; 242 243 struct PortInfo { 244 int32_t portId; 245 int32_t powerRole; 246 int32_t dataRole; 247 int32_t mode; 248 }; 249 250 // Keep it same as the inner kit usb_info.h 251 struct UsbdInfo { 252 int32_t capacity_; 253 int32_t voltage_; 254 int32_t temperature_; 255 int32_t healthState_; 256 int32_t pluggedType_; 257 int32_t pluggedMaxCurrent_; 258 int32_t pluggedMaxVoltage_; 259 int32_t chargeState_; 260 int32_t chargeCounter_; 261 int8_t present_; 262 const char *technology_; 263 }; 264 265 struct UsbdRequest { 266 }; 267 268 #endif // USBD_TYPE_H 269