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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
/*
* BRLTTY - A background process providing access to the console screen (when in
* text mode) for a blind person using a refreshable braille display.
*
* Copyright (C) 1995-2014 by The BRLTTY Developers.
*
* BRLTTY comes with ABSOLUTELY NO WARRANTY.
*
* This is free software, placed under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any
* later version. Please see the file LICENSE-GPL for details.
*
* Web Page: http://mielke.cc/brltty/
*
* This software is maintained by Dave Mielke <dave@mielke.cc>.
*/
#ifndef BRLTTY_INCLUDED_USB_TYPES
#define BRLTTY_INCLUDED_USB_TYPES
#include "serial_types.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Descriptor types. */
typedef enum {
UsbDescriptorType_Device = 0X01,
UsbDescriptorType_Configuration = 0X02,
UsbDescriptorType_String = 0X03,
UsbDescriptorType_Interface = 0X04,
UsbDescriptorType_Endpoint = 0X05,
UsbDescriptorType_HID = 0X21,
UsbDescriptorType_Report = 0X22
} UsbDescriptorType;
/* Descriptor sizes. */
typedef enum {
UsbDescriptorSize_Device = 18,
UsbDescriptorSize_Configuration = 9,
UsbDescriptorSize_String = 2,
UsbDescriptorSize_Interface = 9,
UsbDescriptorSize_Endpoint = 7,
UsbDescriptorSize_HID = 6,
UsbDescriptorSize_Class = 3
} UsbDescriptorSize;
typedef enum {
UsbSpecificationVersion_1_0 = 0X0100,
UsbSpecificationVersion_1_1 = 0X0110,
UsbSpecificationVersion_2_0 = 0X0200,
UsbSpecificationVersion_3_0 = 0X0300
} UsbSpecificationVersion;
/* Configuration attributes (bmAttributes). */
typedef enum {
UsbConfigurationAttribute_BusPowered = 0X80,
UsbConfigurationAttribute_SelfPowered = 0X40,
UsbConfigurationAttribute_RemoteWakeup = 0X20
} UsbConfigurationAttribute;
/* Device and interface classes (bDeviceClass, bInterfaceClass). */
typedef enum {
UsbClass_PerInterface = 0X00,
UsbClass_Audio = 0X01,
UsbClass_Comm = 0X02,
UsbClass_Hid = 0X03,
UsbClass_Physical = 0X05,
UsbClass_Printer = 0X07,
UsbClass_MassStorage = 0X08,
UsbClass_Hub = 0X09,
UsbClass_Data = 0X0A,
UsbClass_AppSpec = 0XFE,
UsbClass_VendorSpec = 0XFF
} UsbClass;
/* Endpoint numbers (bEndpointAddress). */
typedef enum {
UsbEndpointNumber_Mask = 0X0F
} UsbEndpointNumber;
#define USB_ENDPOINT_NUMBER(descriptor) ((descriptor)->bEndpointAddress & UsbEndpointNumber_Mask)
/* Endpoint directions (bEndpointAddress). */
typedef enum {
UsbEndpointDirection_Output = 0X00,
UsbEndpointDirection_Input = 0X80,
UsbEndpointDirection_Mask = 0X80
} UsbEndpointDirection;
#define USB_ENDPOINT_DIRECTION(descriptor) ((descriptor)->bEndpointAddress & UsbEndpointDirection_Mask)
/* Endpoint transfer types (bmAttributes). */
typedef enum {
UsbEndpointTransfer_Control = 0X00,
UsbEndpointTransfer_Isochronous = 0X01,
UsbEndpointTransfer_Bulk = 0X02,
UsbEndpointTransfer_Interrupt = 0X03,
UsbEndpointTransfer_Mask = 0X03
} UsbEndpointTransfer;
#define USB_ENDPOINT_TRANSFER(descriptor) ((descriptor)->bmAttributes & UsbEndpointTransfer_Mask)
/* Endpoint isochronous types (bmAttributes). */
typedef enum {
UsbEndpointIsochronous_Asynchronous = 0X04,
UsbEndpointIsochronous_Adaptable = 0X08,
UsbEndpointIsochronous_Synchronous = 0X0C,
UsbEndpointIsochronous_Mask = 0X0C
} UsbEndpointIsochronous;
#define USB_ENDPOINT_ISOCHRONOUS(descriptor) ((descriptor)->bmAttributes & UsbEndpointIsochronous_Mask)
/* Control transfer recipients. */
typedef enum {
UsbControlRecipient_Device = 0X00,
UsbControlRecipient_Interface = 0X01,
UsbControlRecipient_Endpoint = 0X02,
UsbControlRecipient_Other = 0X03,
UsbControlRecipient_Mask = 0X1F
} UsbControlRecipient;
/* Control transfer types. */
typedef enum {
UsbControlType_Standard = 0X00,
UsbControlType_Class = 0X20,
UsbControlType_Vendor = 0X40,
UsbControlType_Reserved = 0X60,
UsbControlType_Mask = 0X60
} UsbControlType;
/* Transfer directions. */
typedef enum {
UsbControlDirection_Output = 0X00,
UsbControlDirection_Input = 0X80,
UsbControlDirection_Mask = 0X80
} UsbControlDirection;
/* Standard control requests. */
typedef enum {
UsbStandardRequest_GetStatus = 0X00,
UsbStandardRequest_ClearFeature = 0X01,
UsbStandardRequest_GetState = 0X02,
UsbStandardRequest_SetFeature = 0X03,
UsbStandardRequest_SetAddress = 0X05,
UsbStandardRequest_GetDescriptor = 0X06,
UsbStandardRequest_SetDescriptor = 0X07,
UsbStandardRequest_GetConfiguration = 0X08,
UsbStandardRequest_SetConfiguration = 0X09,
UsbStandardRequest_GetInterface = 0X0A,
UsbStandardRequest_SetInterface = 0X0B,
UsbStandardRequest_SynchFrame = 0X0C
} UsbStandardRequest;
/* Standard features. */
typedef enum {
UsbFeature_Endpoint_Stall = 0X00,
UsbFeature_Device_RemoteWakeup = 0X01
} UsbFeature;
typedef struct {
uint8_t bLength; /* Descriptor size in bytes. */
uint8_t bDescriptorType; /* Descriptor type. */
} PACKED UsbDescriptorHeader;
typedef struct {
uint8_t bLength; /* Descriptor size in bytes (18). */
uint8_t bDescriptorType; /* Descriptor type (1 == device). */
uint16_t bcdUSB; /* USB revision number. */
uint8_t bDeviceClass; /* Device class. */
uint8_t bDeviceSubClass; /* Device subclass. */
uint8_t bDeviceProtocol; /* Device protocol. */
uint8_t bMaxPacketSize0; /* Maximum packet size in bytes for endpoint 0. */
uint16_t idVendor; /* Vendor identifier. */
uint16_t idProduct; /* Product identifier. */
uint16_t bcdDevice; /* Product revision number. */
uint8_t iManufacturer; /* String index for manufacturer name. */
uint8_t iProduct; /* String index for product description. */
uint8_t iSerialNumber; /* String index for serial number. */
uint8_t bNumConfigurations; /* Number of configurations. */
} PACKED UsbDeviceDescriptor;
typedef struct {
uint8_t bLength; /* Descriptor size in bytes (9). */
uint8_t bDescriptorType; /* Descriptor type (2 == configuration). */
uint16_t wTotalLength; /* Block size in bytes for all descriptors. */
uint8_t bNumInterfaces; /* Number of interfaces. */
uint8_t bConfigurationValue; /* Configuration number. */
uint8_t iConfiguration; /* String index for configuration description. */
uint8_t bmAttributes; /* Configuration attributes. */
uint8_t bMaxPower; /* Maximum power in 2 milliamp units. */
} PACKED UsbConfigurationDescriptor;
typedef struct {
uint8_t bLength; /* Descriptor size in bytes (2 + numchars/2). */
uint8_t bDescriptorType; /* Descriptor type (3 == string). */
uint16_t wData[127]; /* 16-bit characters. */
} PACKED UsbStringDescriptor;
typedef struct {
uint8_t bLength; /* Descriptor size in bytes (9). */
uint8_t bDescriptorType; /* Descriptor type (4 == interface). */
uint8_t bInterfaceNumber; /* Interface number. */
uint8_t bAlternateSetting; /* Interface alternative. */
uint8_t bNumEndpoints; /* Number of endpoints. */
uint8_t bInterfaceClass; /* Interface class. */
uint8_t bInterfaceSubClass; /* Interface subclass. */
uint8_t bInterfaceProtocol; /* Interface protocol. */
uint8_t iInterface; /* String index for interface description. */
} PACKED UsbInterfaceDescriptor;
typedef struct {
uint8_t bLength; /* Descriptor size in bytes (7, 9 for audio). */
uint8_t bDescriptorType; /* Descriptor type (5 == endpoint). */
uint8_t bEndpointAddress; /* Endpoint number (ored with 0X80 if input. */
uint8_t bmAttributes; /* Endpoint type and attributes. */
uint16_t wMaxPacketSize; /* Maximum packet size in bytes. */
uint8_t bInterval; /* Maximum interval in milliseconds between transfers. */
uint8_t bRefresh;
uint8_t bSynchAddress;
} PACKED UsbEndpointDescriptor;
typedef struct {
uint8_t bDescriptorType;
uint16_t wDescriptorLength;
} PACKED UsbClassDescriptor;
typedef struct {
uint8_t bLength; /* Descriptor size in bytes (6). */
uint8_t bDescriptorType; /* Descriptor type (33 == HID). */
uint16_t bcdHID;
uint8_t bCountryCode;
uint8_t bNumDescriptors;
UsbClassDescriptor descriptors[(0XFF - UsbDescriptorSize_HID) / UsbDescriptorSize_Class];
} PACKED UsbHidDescriptor;
typedef union {
UsbDescriptorHeader header;
UsbDeviceDescriptor device;
UsbConfigurationDescriptor configuration;
UsbStringDescriptor string;
UsbInterfaceDescriptor interface;
UsbEndpointDescriptor endpoint;
UsbHidDescriptor hid;
unsigned char bytes[0XFF];
} UsbDescriptor;
typedef struct {
uint8_t bRequestType; /* Recipient, direction, and type. */
uint8_t bRequest; /* Request code. */
uint16_t wValue; /* Request value. */
uint16_t wIndex; /* Recipient number (language for strings). */
uint16_t wLength; /* Data length in bytes. */
} PACKED UsbSetupPacket;
typedef enum {
UsbHidRequest_GetReport = 0X01,
UsbHidRequest_GetIdle = 0X02,
UsbHidRequest_GetProtocol = 0X03,
UsbHidRequest_SetReport = 0X09,
UsbHidRequest_SetIdle = 0X0A,
UsbHidRequest_SetProtocol = 0X0B
} UsbHidRequest;
typedef enum {
UsbHidReportType_Input = 0X01,
UsbHidReportType_Output = 0X02,
UsbHidReportType_Feature = 0X03
} UsbHidReportType;
typedef enum {
UsbHidItemType_UsagePage = 0X04,
UsbHidItemType_Usage = 0X08,
UsbHidItemType_LogicalMinimum = 0X14,
UsbHidItemType_UsageMinimum = 0X18,
UsbHidItemType_LogicalMaximum = 0X24,
UsbHidItemType_UsageMaximum = 0X28,
UsbHidItemType_PhysicalMinimum = 0X34,
UsbHidItemType_DesignatorIndex = 0X38,
UsbHidItemType_PhysicalMaximum = 0X44,
UsbHidItemType_DesignatorMinimum = 0X48,
UsbHidItemType_UnitExponent = 0X54,
UsbHidItemType_DesignatorMaximum = 0X58,
UsbHidItemType_Unit = 0X64,
UsbHidItemType_ReportSize = 0X74,
UsbHidItemType_StringIndex = 0X78,
UsbHidItemType_Input = 0X80,
UsbHidItemType_ReportID = 0X84,
UsbHidItemType_StringMinimum = 0X88,
UsbHidItemType_Output = 0X90,
UsbHidItemType_ReportCount = 0X94,
UsbHidItemType_StringMaximum = 0X98,
UsbHidItemType_Collection = 0XA0,
UsbHidItemType_Push = 0XA4,
UsbHidItemType_Delimiter = 0XA8,
UsbHidItemType_Feature = 0XB0,
UsbHidItemType_Pop = 0XB4,
UsbHidItemType_EndCollection = 0XC0,
UsbHidItemType_Mask = 0XFC
} UsbHidItemType;
#define USB_HID_ITEM_TYPE(item) ((item) & UsbHidItemType_Mask)
#define USB_HID_ITEM_LENGTH(item) ((item) & ~UsbHidItemType_Mask)
#define USB_HID_ITEM_BIT(type) (UINT64_C(1) << ((type) >> 2))
typedef struct {
uint16_t vendor;
uint16_t product;
uint16_t version;
unsigned char configuration;
unsigned char interface;
unsigned char alternative;
unsigned char inputEndpoint;
unsigned char outputEndpoint;
unsigned disableAutosuspend:1;
unsigned disableEndpointReset:1;
const SerialParameters *serial;
const void *data;
} UsbChannelDefinition;
typedef struct UsbDeviceStruct UsbDevice;
typedef struct {
void *const buffer;
const size_t size;
ssize_t length;
} UsbInputFilterData;
typedef int UsbInputFilter (UsbInputFilterData *data);
typedef struct {
const char *name;
int (*setLineConfiguration) (UsbDevice *device, unsigned int baud, unsigned int dataBits, SerialStopBits stopBits, SerialParity parity, SerialFlowControl flowControl);
int (*setLineProperties) (UsbDevice *device, unsigned int baud, unsigned int dataBits, SerialStopBits stopBits, SerialParity parity);
int (*setBaud) (UsbDevice *device, unsigned int baud);
int (*setDataFormat) (UsbDevice *device, unsigned int dataBits, SerialStopBits stopBits, SerialParity parity);
int (*setFlowControl) (UsbDevice *device, SerialFlowControl flow);
int (*setDtrState) (UsbDevice *device, int state);
int (*setRtsState) (UsbDevice *device, int state);
int (*enableAdapter) (UsbDevice *device);
UsbInputFilter *inputFilter;
ssize_t (*writeData) (UsbDevice *device, const void *data, size_t size);
} UsbSerialOperations;
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* BRLTTY_INCLUDED_USB_TYPES */
|