diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c4d2ce34..da15e6779 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Fixed USB WCID descriptors - the device advertised Microsoft OS descriptor support in string 0xEE but stalled the vendor request that follows (@iceman1001) - Added `hf mfdes sim` - answers GetDFNames and GetISOFileIDs, so a reader sees the ISO file ids and DF names of the simulated card (@iceman1001) - Fixed `hf 14a` - an FPGA bitstream download no longer destroys the emulator memory that `eload` just filled (@iceman1001) - Changed `hf mfdes sim` - now a self contained DESFire simulation, answering both native and ISO 7816 wrapped commands (@iceman1001) diff --git a/common_arm/usb/usb_cdc_at91.c b/common_arm/usb/usb_cdc_at91.c index 3e80b36a9..2479251b5 100644 --- a/common_arm/usb/usb_cdc_at91.c +++ b/common_arm/usb/usb_cdc_at91.c @@ -48,12 +48,9 @@ AT91SAM7S256 USB Device Port #define AT91C_USB_EP_IN_SIZE 64 /* WCID specific Request Code */ -#define MS_OS_DESCRIPTOR_INDEX 0xEE -#define MS_VENDOR_CODE 0x1C -#define MS_EXTENDED_COMPAT_ID 0x04 -#define MS_EXTENDED_PROPERTIES 0x05 -#define MS_WCID_GET_DESCRIPTOR 0xC0 -#define MS_WCID_GET_FEATURE_DESCRIPTOR 0xC1 +/* MS_OS_DESCRIPTOR_INDEX, MS_EXTENDED_COMPAT_ID, MS_EXTENDED_PROPERTIES and + the MS_WCID_* request types come from usb_cdc_desc.h */ +#define MS_VENDOR_CODE USB_CDC_DESC_MS_VENDOR_CODE /* USB standard request code */ #define STD_GET_STATUS_ZERO 0x0080 @@ -727,23 +724,26 @@ void AT91F_CDC_Enumerate(void) { UDP_CLEAR_EP_FLAGS(AT91C_EP_CONTROL, AT91C_UDP_RXSETUP); while ((pUdp->UDP_CSR[AT91C_EP_CONTROL] & AT91C_UDP_RXSETUP)) {}; - /* - if ( bRequest == MS_VENDOR_CODE) { - if ( bmRequestType == MS_WCID_GET_DESCRIPTOR ) { // C0 - if ( wIndex == MS_EXTENDED_COMPAT_ID ) { // 4 - //AT91F_USB_SendData(pUdp, CompatIDFeatureDescriptor, MIN(sizeof(CompatIDFeatureDescriptor), wLength)); - //return; - } + // WCID vendor request. StrMS_OSDescriptor advertises MS_VENDOR_CODE, so + // every request carrying it has to be answered here. Falling through to the + // standard switch below stalls it, which makes Windows cache the device as + // having no MS OS descriptors and stop asking. + if (bRequest == MS_VENDOR_CODE) { + + if (bmRequestType == MS_WCID_GET_DESCRIPTOR && wIndex == MS_EXTENDED_COMPAT_ID) { + AT91F_USB_SendData(pUdp, CompatIDFeatureDescriptor, MIN(sizeof(CompatIDFeatureDescriptor), wLength)); + return; } - if ( bmRequestType == MS_WCID_GET_FEATURE_DESCRIPTOR ) { //C1 - // if ( wIndex == MS_EXTENDED_PROPERTIES ) { // 5 - winusb bug with wIndex == interface index, so I just send it always) - //AT91F_USB_SendData(pUdp, OSprop, MIN(sizeof(OSprop), wLength)); - //return; - // } + // wValue holds the interface number, wIndex the descriptor index. + if (bmRequestType == MS_WCID_GET_FEATURE_DESCRIPTOR && wIndex == MS_EXTENDED_PROPERTIES) { + AT91F_USB_SendData(pUdp, OSprop, MIN(sizeof(OSprop), wLength)); + return; } + + AT91F_USB_SendStall(pUdp); + return; } - */ // Handle supported standard device request Cf Table 9-3 in USB specification Rev 1.1 switch ((bRequest << 8) | bmRequestType) { diff --git a/common_arm/usb/usb_cdc_desc.c b/common_arm/usb/usb_cdc_desc.c index 68e2b94cb..2f2c073f9 100644 --- a/common_arm/usb/usb_cdc_desc.c +++ b/common_arm/usb/usb_cdc_desc.c @@ -158,84 +158,100 @@ const char bosDescriptor[12] = { 0x0 }; -// Microsoft OS Extended Configuration Compatible ID Descriptor -/* -const char CompatIDFeatureDescriptor[] = { - 0x28, 0x00, 0x00, 0x00, // Descriptor Length 40bytes (0x28) - 0x00, 0x01, // Version ('1.0') - MS_EXTENDED_COMPAT_ID, 0x00, // Compatibility ID Descriptor Index 0x0004 - 0x01, // Number of sections. 0x1 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Reserved (7bytes) - // -----function section 1------ - 0x00, // Interface Number #0 - 0x01, // reserved (0x1) - 0x57, 0x49, 0x4E, 0x55, 0x53, 0x42, 0x00, 0x00, // Compatible ID ('WINUSB\0\0') (8bytes) - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Sub-Compatible ID (8byte) - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Reserved (6bytes) -}; -*/ +// Only the AT91 driver answers the WCID vendor request that carries these. +#ifndef PM5 -// Microsoft Extended Properties Feature Descriptor -/* -const char OSprop[] = { - // u32 Descriptor Length (10+132+64+102 == 308 - 0x34, 0x01, 0, 0, - // u16 Version ('1.0') - 0, 1, - // u16 wIndex - MS_EXTENDED_PROPERTIES, 0, - // u16 wCount -- three section - 3, 0, +// Microsoft OS 1.0 Extended Compat ID Feature Descriptor, returned for +// bmRequestType 0xC0 / wIndex 0x0004. The compatible ID is left empty so +// Windows keeps its normal CDC driver match instead of loading WinUSB. +const char CompatIDFeatureDescriptor[40] = { + 0x28, 0x00, 0x00, 0x00, // Descriptor length (40) + 0x00, 0x01, // Version ('1.0') + MS_EXTENDED_COMPAT_ID, 0x00, // Index 0x0004 + 0x01, // Number of sections + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Reserved (7 bytes) - // -----property section 1------ - // u32 size ( 14+40+78 == 132) - 132, 0, 0, 0, - // u32 type - 1, 0, 0, 0, // unicode string - // u16 namelen (20*2 = 40) - 40, 0, - // name DeviceInterfaceGUID - 'D',0,'e',0,'v',0,'i',0,'c',0,'e',0,'I',0,'n',0,'t',0,'e',0,'r',0,'f',0,'a',0,'c',0,'e',0,'G',0,'U',0,'I',0,'D',0,0,0, - // u32 datalen (39*2 = 78) - 78, 0, 0, 0, - // data {4D36E978-E325-11CE-BFC1-08002BE10318} - '{',0,'4',0,'d',0,'3',0,'6',0,'e',0,'9',0,'7',0,'8',0,'-',0,'e',0,'3',0,'2',0,'5',0, - '-',0,'1',0,'1',0,'c',0,'e',0,'-',0,'b',0,'f',0,'c',0,'1',0,'-',0,'0',0,'8',0,'0',0, - '0',0,'2',0,'b',0,'e',0,'1',0,'0',0,'3',0,'1',0,'8',0,'}',0,0,0, - - // -----property section 2------ - // u32 size ( 14+12+38 == 64) - 64, 0, 0, 0, - // u32 type - 1, 0, 0, 0, // unicode string - // u16 namelen (12) - 12, 0, - // name Label - 'L',0,'a',0,'b',0,'e',0,'l',0,0,0, - // u32 datalen ( 19*2 = 38 ) - 38, 0, 0, 0, - // data 'Awesome PM3 Device' - 'A',0,'w',0,'e',0,'s',0,'o',0,'m',0,'e',0,' ',0,'P',0,'M',0,'3',0,' ',0,'D',0,'e',0,'v',0,'i',0,'c',0,'e',0,0,0, - - // -----property section 3------ - // u32 size ( 14+12+76 == 102) - 102, 0, 0, 0, - // u32 type - 2, 0, 0, 0, //Unicode string with environment variables - // u16 namelen (12) - 12, 0, - // name Icons - 'I',0,'c',0,'o',0,'n',0,'s',0,0,0, - // u32 datalen ( 38*2 == 76) - 76, 0, 0, 0, - // data '%SystemRoot%\\system32\\Shell32.dll,-13' - '%',0,'S',0,'y',0,'s',0,'t',0,'e',0,'m',0,'R',0,'o',0,'o',0,'t',0,'%',0, - '\\',0,'s',0,'y',0,'s',0,'t',0,'e',0,'m',0,'3',0,'2',0,'\\',0, - 'S',0,'h',0,'e',0,'l',0,'l',0,'3',0,'2',0,'.',0,'d',0,'l',0,'l',0,',',0, - '-',0,'1',0,'3',0,0,0 + // ----- function section 1 ----- + 0x00, // Interface number #0 + 0x01, // Reserved + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Compatible ID (none) + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Sub-compatible ID (none) + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Reserved (6 bytes) }; -*/ +// Microsoft OS 1.0 Extended Properties Feature Descriptor, returned for +// bmRequestType 0xC1 / wIndex 0x0005. +const char OSprop[304] = { + // u32 Descriptor length (10 + 132 + 60 + 102 == 304) + LBYTE(304), HBYTE(304), 0, 0, + // u16 Version ('1.0') + 0, 1, + // u16 wIndex + MS_EXTENDED_PROPERTIES, 0, + // u16 wCount + 3, 0, + + // ----- property section 1 ----- + // u32 size (14 + 40 + 78 == 132) + 132, 0, 0, 0, + // u32 type + 1, 0, 0, 0, // unicode string + // u16 namelen (40) + 40, 0, + // name DeviceInterfaceGUID + 'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, + 'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, + 'a', 0, 'c', 0, 'e', 0, 'G', 0, 'U', 0, 'I', 0, + 'D', 0, 0, 0, + // u32 datalen (78) + 78, 0, 0, 0, + // data {9ac44b8f-1ce1-4ceb-abee-01ce1cebabee} + '{', 0, '9', 0, 'a', 0, 'c', 0, '4', 0, '4', 0, + 'b', 0, '8', 0, 'f', 0, '-', 0, '1', 0, 'c', 0, + 'e', 0, '1', 0, '-', 0, '4', 0, 'c', 0, 'e', 0, + 'b', 0, '-', 0, 'a', 0, 'b', 0, 'e', 0, 'e', 0, + '-', 0, '0', 0, '1', 0, 'c', 0, 'e', 0, '1', 0, + 'c', 0, 'e', 0, 'b', 0, 'a', 0, 'b', 0, 'e', 0, + 'e', 0, '}', 0, 0, 0, + + // ----- property section 2 ----- + // u32 size (14 + 12 + 34 == 60) + 60, 0, 0, 0, + // u32 type + 1, 0, 0, 0, // unicode string + // u16 namelen (12) + 12, 0, + // name Label + 'L', 0, 'a', 0, 'b', 0, 'e', 0, 'l', 0, 0, 0, + // u32 datalen (34) + 34, 0, 0, 0, + // data Proxmark3 Iceman + 'P', 0, 'r', 0, 'o', 0, 'x', 0, 'm', 0, 'a', 0, + 'r', 0, 'k', 0, '3', 0, ' ', 0, 'I', 0, 'c', 0, + 'e', 0, 'm', 0, 'a', 0, 'n', 0, 0, 0, + + // ----- property section 3 ----- + // u32 size (14 + 12 + 76 == 102) + 102, 0, 0, 0, + // u32 type + 2, 0, 0, 0, // unicode string with environment variables + // u16 namelen (12) + 12, 0, + // name Icons + 'I', 0, 'c', 0, 'o', 0, 'n', 0, 's', 0, 0, 0, + // u32 datalen (76) + 76, 0, 0, 0, + // data %SystemRoot%\system32\Shell32.dll,-13 + '%', 0, 'S', 0, 'y', 0, 's', 0, 't', 0, 'e', 0, + 'm', 0, 'R', 0, 'o', 0, 'o', 0, 't', 0, '%', 0, + '\\', 0, 's', 0, 'y', 0, 's', 0, 't', 0, 'e', 0, + 'm', 0, '3', 0, '2', 0, '\\', 0, 'S', 0, 'h', 0, + 'e', 0, 'l', 0, 'l', 0, '3', 0, '2', 0, '.', 0, + 'd', 0, 'l', 0, 'l', 0, ',', 0, '-', 0, '1', 0, + '3', 0, 0, 0 +}; + +#endif const char StrLanguageCodes[4] = { 4, // Length diff --git a/common_arm/usb/usb_cdc_desc.h b/common_arm/usb/usb_cdc_desc.h index 206f7b1b2..de7ca2241 100644 --- a/common_arm/usb/usb_cdc_desc.h +++ b/common_arm/usb/usb_cdc_desc.h @@ -52,6 +52,15 @@ // https://www.usbzh.com/article/detail-625.html #define USB_CDC_DESC_MS_VENDOR_CODE 0x1C +// WCID request codes. The OS string descriptor lives at string index +// MS_OS_DESCRIPTOR_INDEX and names USB_CDC_DESC_MS_VENDOR_CODE as the bRequest +// Windows then uses for the two feature descriptors below. +#define MS_OS_DESCRIPTOR_INDEX 0xEE +#define MS_EXTENDED_COMPAT_ID 0x04 +#define MS_EXTENDED_PROPERTIES 0x05 +#define MS_WCID_GET_DESCRIPTOR 0xC0 +#define MS_WCID_GET_FEATURE_DESCRIPTOR 0xC1 + // exported all desc. extern const char devDescriptor[18]; extern const char cfgDescriptor[67]; @@ -71,4 +80,14 @@ extern char StrSerialNumber[50]; // DOCS: https://www.usbzh.com/article/detail-625.html extern const char StrMS_OSDescriptor[18]; +// WCID feature descriptors. Only the AT91 driver answers the vendor request +// that carries them; the AT32 stack routes vendor requests into its +// third-party class handler, so it does not build these. +// +// OSprop publishes this device interface GUID to Windows. +#ifndef PM5 +extern const char CompatIDFeatureDescriptor[40]; +extern const char OSprop[304]; +#endif + #endif