243 lines
8.9 KiB
C
243 lines
8.9 KiB
C
enum USB_Class_Codes {
|
|
USB_CLASS_PER_INTERFACE = 0x00, // Use class info in Interface Descriptors
|
|
USB_CLASS_AUDIO = 0x01, // Audio
|
|
USB_CLASS_COMM_AND_CDC = 0x02, // Communications and CDC Control
|
|
USB_CLASS_HID = 0x03, // Human Interface Device
|
|
USB_CLASS_PHYSICAL = 0x05, // Physical
|
|
USB_CLASS_IMAGE = 0x06, // Image
|
|
USB_CLASS_PRINTER = 0x07, // Printer
|
|
USB_CLASS_MASS_STORAGE = 0x08, // Mass Storage
|
|
USB_CLASS_HUB = 0x09, // Hub
|
|
USB_CLASS_CDC_DATA = 0x0A, // CDC-Data
|
|
USB_CLASS_SMART_CARD = 0x0B, // Smart Card
|
|
USB_CLASS_CONTENT_SECURITY = 0x0D, // Content Security
|
|
USB_CLASS_VIDEO = 0x0E, // Video
|
|
USB_CLASS_PERSONAL_HEALTHCARE = 0x0F, // Personal Healthcare
|
|
USB_CLASS_AUDIO_VIDEO = 0x10, // Audio/Video Devices
|
|
USB_CLASS_BILLBOARD = 0x11, // Billboard Device Class
|
|
USB_CLASS_TYPE_C_BRIDGE = 0x12, // USB Type-C Bridge Class
|
|
USB_CLASS_BULK_DISPLAY = 0x13, // USB Bulk Display Protocol Device Class
|
|
USB_CLASS_MCTP = 0x14, // MCTP over USB Protocol Endpoint Device Class
|
|
USB_CLASS_I3C = 0x3C, // I3C Device Class
|
|
USB_CLASS_DIAGNOSTIC = 0xDC, // Diagnostic Device
|
|
USB_CLASS_WIRELESS = 0xE0, // Wireless Controller
|
|
USB_CLASS_MISCELLANEOUS = 0xEF, // Miscellaneous
|
|
USB_CLASS_APPLICATION_SPEC = 0xFE, // Application Specific
|
|
USB_CLASS_VENDOR_SPEC = 0xFF // Vendor Specific
|
|
};
|
|
|
|
enum USB_MassStorage_InterfaceProtocol {
|
|
MSC_PROTO_CBI_INT = 0x00, // Control/Bulk/Interrupt (with completion INT)
|
|
MSC_PROTO_CBI_NO_INT = 0x01, // Control/Bulk/Interrupt (without completion INT)
|
|
MSC_PROTO_ZIP = 0x02, // ZIP Drive Protocol (Legacy)
|
|
MSC_PROTO_BBB = 0x50, // Bulk-Only Transport (BOT / BBB)
|
|
MSC_PROTO_BOT = 0x50, // Alias for Bulk-Only Transport
|
|
MSC_PROTO_UAS = 0x62, // USB Attached SCSI Protocol (UASP)
|
|
MSC_PROTO_VENDOR = 0xFF // Vendor Specific Protocol
|
|
};
|
|
|
|
enum USB_HID_InterfaceProtocol {
|
|
HID_PROTO_NONE = 0x00, // No specific boot protocol / Report Protocol
|
|
HID_PROTO_KEYBOARD = 0x01, // Boot Keyboard Protocol
|
|
HID_PROTO_MOUSE = 0x02 // Boot Mouse Protocol
|
|
};
|
|
|
|
enum USB_MassStorage_SubClass {
|
|
MSC_SUBCLASS_RBC = 0x01, // Reduced Block Commands
|
|
MSC_SUBCLASS_ATAPI = 0x02, // SFF-8020i / MMC-2 (CD/DVD)
|
|
MSC_SUBCLASS_QIC157 = 0x03, // QIC-157 (Tape drive)
|
|
MSC_SUBCLASS_UFI = 0x04, // Uniform Floppy Interface
|
|
MSC_SUBCLASS_SFF8070I = 0x05, // SFF-8070i
|
|
MSC_SUBCLASS_SCSI = 0x06, // SCSI Transparent Command Set (Most Common)
|
|
MSC_SUBCLASS_LESD = 0x07, // Lockable Storage Devices
|
|
MSC_SUBCLASS_IEEE1667 = 0x08, // IEEE 1667 Security
|
|
MSC_SUBCLASS_VENDOR = 0xFF // Vendor Specific
|
|
};
|
|
|
|
enum USB_HID_SubClass {
|
|
HID_SUBCLASS_NONE = 0x00, // No SubClass (Standard HID device)
|
|
HID_SUBCLASS_BOOT = 0x01 // Boot Interface Subclass (Keyboards/Mice supported by BIOS)
|
|
};
|
|
|
|
enum USB_bDescriptorType {
|
|
DESCRIPTOR_DEVICE = 0x1,
|
|
DESCRIPTOR_CONFIGURATION = 0x2,
|
|
DESCRIPTOR_INTERFACE = 0x4,
|
|
DESCRIPTOR_ENDPOINT = 0x5
|
|
};
|
|
|
|
enum USB_Type_BCD {
|
|
USB20 = 0x0200,
|
|
USB11 = 0x0110,
|
|
USB10 = 0x0100
|
|
};
|
|
|
|
|
|
|
|
enum USB_PID {
|
|
// Token Packets
|
|
OUT_TOKEN = 0b0001,
|
|
IN_TOKEN = 0b1001,
|
|
SOF_TOKEN = 0b0101,
|
|
SETUP_TOKEN = 0b1101,
|
|
|
|
// Data Packets
|
|
DATA0_DATA = 0b0011,
|
|
DATA1_DATA = 0b1011,
|
|
DATA2_DATA = 0b0111,
|
|
MDATA_DATA = 0b1111,
|
|
|
|
// Handshake Packets
|
|
ACK_HANDSHAKE = 0b0010,
|
|
NAK_HANDSHAKE = 0b1010,
|
|
STALL_HANDSHAKE = 0b1110,
|
|
NYET_HANDSHAKE = 0b0110,
|
|
|
|
// Special & Other Packets
|
|
PRE_SPECIAL = 0b1100, // PREamble shares value with ERR
|
|
ERR_SPECIAL = 0b1100,
|
|
SPLIT_SPECIAL = 0b1000,
|
|
PING_SPECIAL = 0b0100
|
|
};
|
|
|
|
|
|
enum Configuration_bmAttributes_Values {
|
|
// Standard Bits
|
|
CONFIG_ATTR_RESERVED_BIT7 = (1 << 7), // Always set to 1 (legacy USB 1.0 bus-powered indicator)
|
|
CONFIG_ATTR_SELF_POWERED = (1 << 6), // 1 = Self-powered, 0 = Bus-powered
|
|
CONFIG_ATTR_REMOTE_WAKEUP = (1 << 5), // 1 = Supports remote wakeup
|
|
|
|
// Masks
|
|
CONFIG_ATTR_POWER_MASK = (1 << 6),
|
|
CONFIG_ATTR_WAKEUP_MASK = (1 << 5),
|
|
CONFIG_ATTR_RESERVED_MASK = 0b00011111 // Bits 4..0 reserved (set to 0)
|
|
};
|
|
|
|
|
|
enum Endpoint_bmAttributes {
|
|
// Bits 1..0: Transfer Type
|
|
TRANSFER_TYPE_MASK = 0b00000011,
|
|
TRANSFER_CONTROL = 0b00000000,
|
|
TRANSFER_ISOCHRONOUS = 0b00000001,
|
|
TRANSFER_BULK = 0b00000010,
|
|
TRANSFER_INTERRUPT = 0b00000011,
|
|
|
|
// Bits 3..2: Synchronization Type (Isochronous Mode only)
|
|
SYNC_TYPE_MASK = 0b00001100,
|
|
SYNC_NOSYNC = (0b00 << 2), // No Synchronization
|
|
SYNC_ASYNC = (0b01 << 2), // Asynchronous
|
|
SYNC_ADAPTIVE = (0b10 << 2), // Adaptive
|
|
SYNC_SYNCHRONOUS = (0b11 << 2), // Synchronous
|
|
|
|
// Bits 5..4: Usage Type (Isochronous Mode only)
|
|
USAGE_TYPE_MASK = 0b00110000,
|
|
USAGE_DATA = (0b00 << 4), // Data Endpoint
|
|
USAGE_FEEDBACK = (0b01 << 4), // Feedback Endpoint
|
|
USAGE_EXPLICIT_FEEDBACK = (0b10 << 4), // Explicit Feedback Data Endpoint
|
|
USAGE_RESERVED = (0b11 << 4) // Reserved
|
|
};
|
|
|
|
enum Setup_bmRequestType {
|
|
// Bit 7: Data Phase Transfer Direction
|
|
DIR_MASK = (1 << 7),
|
|
HOST_TO_DEVICE = (0 << 7),
|
|
DEVICE_TO_HOST = (1 << 7),
|
|
|
|
// Bits 6..5: Type
|
|
TYPE_MASK = (0b11 << 5),
|
|
TYPE_STANDARD = (0b00 << 5),
|
|
TYPE_CLASS = (0b01 << 5),
|
|
TYPE_VENDOR = (0b10 << 5),
|
|
TYPE_RESERVED = (0b11 << 5),
|
|
|
|
// Bits 4..0: Recipient
|
|
RECIPIENT_MASK = 0b11111,
|
|
RECIPIENT_DEVICE = 0,
|
|
RECIPIENT_INTERFACE = 1,
|
|
RECIPIENT_ENDPOINT = 2,
|
|
RECIPIENT_OTHER = 3
|
|
};
|
|
|
|
|
|
// Byte 0: Peripheral Qualifier (Bits 7..5) & Peripheral Device Type (Bits 4..0)
|
|
enum SCSI_Inquiry_Byte0 {
|
|
// Peripheral Qualifier (Bits 7..5)
|
|
SCSI_INQ_QUAL_CONNECTED = (0b000 << 5), // Connected to target device
|
|
SCSI_INQ_QUAL_NOT_CONNECTED = (0b001 << 5), // Supported, but device not connected
|
|
SCSI_INQ_QUAL_NOT_CAPABLE = (0b011 << 5), // Not capable of supporting a physical device
|
|
|
|
// Peripheral Device Type (Bits 4..0)
|
|
SCSI_INQ_DEV_TYPE_DIRECT_ACCESS = 0x00, // Direct access block device (Flash drive, HDD, SSD)
|
|
SCSI_INQ_DEV_TYPE_SEQUENTIAL = 0x01, // Sequential-access device (Tape)
|
|
SCSI_INQ_DEV_TYPE_PRINTER = 0x02, // Printer device
|
|
SCSI_INQ_DEV_TYPE_PROCESSOR = 0x03, // Processor device
|
|
SCSI_INQ_DEV_TYPE_CD_DVD = 0x05, // CD/DVD-ROM device
|
|
SCSI_INQ_DEV_TYPE_OPTICAL = 0x07, // Optical memory device
|
|
SCSI_INQ_DEV_TYPE_UNKNOWN = 0x1F // Unknown or no device type
|
|
};
|
|
|
|
// Byte 1: Control & Removable Media Flag
|
|
enum SCSI_Inquiry_Byte1 {
|
|
SCSI_INQ_RMB_FIXED = (0 << 7), // Fixed (non-removable) drive
|
|
SCSI_INQ_RMB_REMOVABLE = (1 << 7) // Removable media (sets gray icon on macOS)
|
|
};
|
|
|
|
// Byte 2: ANSI/SPC Standard Compliance Version
|
|
enum SCSI_Inquiry_Byte2_Version {
|
|
SCSI_INQ_VER_NONE = 0x00, // No standard compliance claimed
|
|
SCSI_INQ_VER_SCSI1 = 0x01, // ANSI X3.131-1986 (SCSI-1)
|
|
SCSI_INQ_VER_SCSI2 = 0x02, // ANSI X3.131-1994 (SCSI-2)
|
|
SCSI_INQ_VER_SPC = 0x03, // SPC (SCSI Primary Commands)
|
|
SCSI_INQ_VER_SPC_2 = 0x04, // SPC-2
|
|
SCSI_INQ_VER_SPC_3 = 0x05, // SPC-3
|
|
SCSI_INQ_VER_SPC_4 = 0x06 // SPC-4
|
|
};
|
|
|
|
// Byte 3: Response Data Format & Control Flags
|
|
enum SCSI_Inquiry_Byte3 {
|
|
SCSI_INQ_FMT_SCSI1 = 0x00,
|
|
SCSI_INQ_FMT_CCS = 0x01, // Common Command Set
|
|
SCSI_INQ_FMT_SCSI2 = 0x02, // Standard Response Data Format (SCSI-2 / SPC)
|
|
|
|
SCSI_INQ_HISUP = (1 << 4), // Hierarchical Support
|
|
SCSI_INQ_NORMACA = (1 << 5) // Normal ACA Supported
|
|
};
|
|
|
|
|
|
|
|
enum Standard__Device_Requests {
|
|
GET_STATUS = 0x00,
|
|
/**
|
|
* GET_STATUS will reuturn a 16bit word.
|
|
* D0 is "Self Powered" bit, if D0 == 0, then the device is powered by the bus
|
|
* D1 is the "Remote Wakeup" bit, if D1 == 1, then the host can wake up this device from suspend
|
|
*/
|
|
|
|
CLEAR_FEATURE = 0x01,
|
|
SET_FEATURE = 0x03,
|
|
SET_ADDRESS = 0x05,
|
|
GET_DESCRIPTOR = 0x06,
|
|
SET_DESCRIPTOR = 0x07,
|
|
GET_CONFIGURATION = 0x08,
|
|
SET_CONFIGURATION = 0x09
|
|
};
|
|
|
|
enum Standard_Interface_Requests {
|
|
GET_STATUS = 0x00,
|
|
CLEAR_FEATURE = 0x01,
|
|
SET_FEATURE = 0x03,
|
|
GET_INTERFACE = 0x0A,
|
|
SET_INTERFACE = 0x11,
|
|
};
|
|
|
|
enum Standard_Endpoint_Requests {
|
|
GET_STATUS = 0x00,
|
|
CLEAR_FEATURE = 0x01,
|
|
SET_FEATURE = 0x03,
|
|
/**
|
|
* Clear Feature and Set Feature are used to set Endpoint Features.
|
|
* The standard currently defines one endpoint feature selector,
|
|
* ENDPOINT_HALT (0x00) which allows the host to stall and clear an endpoint.
|
|
*/
|
|
SYNCH_FRAME = 0x12,
|
|
}; |