fix USB descriptors

- indicate compliance with USB release 2.0
- set correct vendor and product IDs
- indicate power consumption (500mA)
- add String Descriptor 0 indicating supported languages
- add String Descriptors for Manufacturer and Product
This commit is contained in:
pwpiwi 2017-04-24 14:19:39 +02:00
commit 1f42ccddfb

View file

@ -33,34 +33,33 @@
*/ */
#include "usb_cdc.h" #include "usb_cdc.h"
#include "at91sam7s512.h"
#include "config_gpio.h" #include "config_gpio.h"
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define AT91C_EP_IN_SIZE 0x40 #define AT91C_EP_IN_SIZE 0x40
#define AT91C_EP_OUT 1 #define AT91C_EP_OUT 1
#define AT91C_EP_OUT_SIZE 0x40 #define AT91C_EP_OUT_SIZE 0x40
#define AT91C_EP_IN 2 #define AT91C_EP_IN 2
const char devDescriptor[] = { static const char devDescriptor[] = {
/* Device descriptor */ /* Device descriptor */
0x12, // bLength 0x12, // bLength
0x01, // bDescriptorType 0x01, // bDescriptorType
0x10,0x01, // Complies with USB Spec. Release (0110h = release 1.10) 0x00,0x02, // Complies with USB Spec. Release (0200h = release 2.0)
0x02, // bDeviceClass: CDC class code 0x02, // bDeviceClass: CDC class code
0x00, // bDeviceSubclass: CDC class sub code 0x00, // bDeviceSubclass: CDC class sub code
0x00, // bDeviceProtocol: CDC Device protocol 0x00, // bDeviceProtocol: CDC Device protocol
0x08, // bMaxPacketSize0 0x08, // bMaxPacketSize0
0x2d,0x2d, // Vendor ID (--) 0xc4,0x9a, // Vendor ID (0x9ac4 = J. Westhues)
0x4d,0x50, // Product ID (PM), transmitted in reverse 0x8f,0x4b, // Product ID (0x4b8f = Proxmark-3 RFID Instrument)
0x01,0x00, // Device release number (0001) 0x01,0x00, // Device release number (0001)
0x01, // iManufacturer // 0x01 0x01, // iManufacturer
0x00, // iProduct 0x02, // iProduct
0x00, // SerialNumber 0x00, // iSerialNumber
0x01 // bNumConfigs 0x01 // bNumConfigs
}; };
const char cfgDescriptor[] = { static const char cfgDescriptor[] = {
/* ============== CONFIGURATION 1 =========== */ /* ============== CONFIGURATION 1 =========== */
/* Configuration 1 descriptor */ /* Configuration 1 descriptor */
0x09, // CbLength 0x09, // CbLength
@ -71,7 +70,7 @@ const char cfgDescriptor[] = {
0x01, // CbConfigurationValue 0x01, // CbConfigurationValue
0x00, // CiConfiguration 0x00, // CiConfiguration
0xC0, // CbmAttributes 0xA0 0xC0, // CbmAttributes 0xA0
0x00, // CMaxPower 0xFA, // CMaxPower
/* Communication Class Interface Descriptor Requirement */ /* Communication Class Interface Descriptor Requirement */
0x09, // bLength 0x09, // bLength
@ -81,7 +80,7 @@ const char cfgDescriptor[] = {
0x01, // bNumEndpoints 0x01, // bNumEndpoints
0x02, // bInterfaceClass 0x02, // bInterfaceClass
0x02, // bInterfaceSubclass 0x02, // bInterfaceSubclass
0x00, // bInterfaceProtocol 0x01, // bInterfaceProtocol
0x00, // iInterface 0x00, // iInterface
/* Header Functional Descriptor */ /* Header Functional Descriptor */
@ -95,7 +94,7 @@ const char cfgDescriptor[] = {
0x04, // bFunctionLength 0x04, // bFunctionLength
0x24, // bDescriptor Type: CS_INTERFACE 0x24, // bDescriptor Type: CS_INTERFACE
0x02, // bDescriptor Subtype: ACM Func Desc 0x02, // bDescriptor Subtype: ACM Func Desc
0x00, // bmCapabilities 0x02, // bmCapabilities
/* Union Functional Descriptor */ /* Union Functional Descriptor */
0x05, // bFunctionLength 0x05, // bFunctionLength
@ -151,8 +150,14 @@ const char cfgDescriptor[] = {
0x00 // bInterval 0x00 // bInterval
}; };
const char strDescriptor[] = { static const char StrDescLanguageCodes[] = {
26, // Length 4, // Length
0x03, // Type is string
0x09, 0x04 // supported language Code 0 = 0x0409 (English)
};
static const char StrDescManufacturer[] = {
26, // Length
0x03, // Type is string 0x03, // Type is string
'p', 0x00, 'p', 0x00,
'r', 0x00, 'r', 0x00,
@ -165,9 +170,32 @@ const char strDescriptor[] = {
'.', 0x00, '.', 0x00,
'o', 0x00, 'o', 0x00,
'r', 0x00, 'r', 0x00,
'g', 0x00, 'g', 0x00
}; };
static const char StrDescProduct[] = {
8, // Length
0x03, // Type is string
'P', 0x00,
'M', 0x00,
'3', 0x00
};
static const char* const pStrings[] =
{
StrDescLanguageCodes,
StrDescManufacturer,
StrDescProduct
};
const char* getStringDescriptor(uint8_t idx)
{
if(idx >= (sizeof(pStrings) / sizeof(pStrings[0]))) {
return(NULL);
} else {
return(pStrings[idx]);
}
}
/* USB standard request code */ /* USB standard request code */
#define STD_GET_STATUS_ZERO 0x0080 #define STD_GET_STATUS_ZERO 0x0080
@ -480,8 +508,14 @@ void AT91F_CDC_Enumerate() {
AT91F_USB_SendData(pUdp, devDescriptor, MIN(sizeof(devDescriptor), wLength)); AT91F_USB_SendData(pUdp, devDescriptor, MIN(sizeof(devDescriptor), wLength));
else if (wValue == 0x200) // Return Configuration Descriptor else if (wValue == 0x200) // Return Configuration Descriptor
AT91F_USB_SendData(pUdp, cfgDescriptor, MIN(sizeof(cfgDescriptor), wLength)); AT91F_USB_SendData(pUdp, cfgDescriptor, MIN(sizeof(cfgDescriptor), wLength));
else if ((wValue & 0x300) == 0x300) // Return String Descriptor else if ((wValue & 0xF00) == 0x300) { // Return String Descriptor
AT91F_USB_SendData(pUdp, strDescriptor, MIN(sizeof(strDescriptor), wLength)); const char *strDescriptor = getStringDescriptor(wValue & 0xff);
if (strDescriptor != NULL) {
AT91F_USB_SendData(pUdp, strDescriptor, MIN(strDescriptor[0], wLength));
} else {
AT91F_USB_SendStall(pUdp);
}
}
else else
AT91F_USB_SendStall(pUdp); AT91F_USB_SendStall(pUdp);
break; break;