From 948b49c4077946bc5aea7b8def79e5f856997197 Mon Sep 17 00:00:00 2001 From: Proxcloud Date: Wed, 7 Feb 2018 01:07:48 +0800 Subject: [PATCH 1/6] Add BOS USB descriptor. This allows non-root access on Android devices --- common/usb_cdc.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/common/usb_cdc.c b/common/usb_cdc.c index 348b97e9..36df2a86 100644 --- a/common/usb_cdc.c +++ b/common/usb_cdc.c @@ -156,6 +156,28 @@ static const char cfgDescriptor[] = { 0x00, 0x00 // bInterval }; +const char BOSDescriptor[] = { + // BOS descriptor header + 0x05, 0x0F, 0x39, 0x00, 0x02, + + // Microsoft OS 2.0 Platform Capability Descriptor + 0x1C, // Descriptor size (28 bytes) + 0x10, // Descriptor type (Device Capability) + 0x05, // Capability type (Platform) + 0x00, // Reserved + + // MS OS 2.0 Platform Capability ID (D8DD60DF-4589-4CC7-9CD2-659D9E648A9F) + 0xDF, 0x60, 0xDD, 0xD8, + 0x89, 0x45, + 0xC7, 0x4C, + 0x9C, 0xD2, + 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F, + + 0x00, 0x00, 0x03, 0x06, // Windows version (8.1) (0x06030000) + 0x1e, 0x00, + 252, // Vendor-assigned bMS_VendorCode + 0x00 // Doesn’t support alternate enumeration +}; static const char StrDescLanguageCodes[] = { 4, // Length @@ -550,6 +572,10 @@ void AT91F_CDC_Enumerate() { AT91F_USB_SendData(pUdp, devDescriptor, MIN(sizeof(devDescriptor), wLength)); else if (wValue == 0x200) // Return Configuration Descriptor AT91F_USB_SendData(pUdp, cfgDescriptor, MIN(sizeof(cfgDescriptor), wLength)); + else if ((wValue & 0xF00) == 0xF00) // Return BOS Descriptor + AT91F_USB_SendData(pUdp, BOSDescriptor, MIN(sizeof(BOSDescriptor), wLength)); + else if ((wValue & 0x300) == 0x300) // Return Manufacturer Descriptor - this is needed by Android + AT91F_USB_SendData(pUdp, StrDescManufacturer, MIN(sizeof(StrDescManufacturer), wLength)); else if ((wValue & 0xF00) == 0x300) { // Return String Descriptor const char *strDescriptor = getStringDescriptor(wValue & 0xff); if (strDescriptor != NULL) { From 8b9de94afe7436eb14bf6e6c801bd4054842abe2 Mon Sep 17 00:00:00 2001 From: Proxcloud Date: Thu, 8 Feb 2018 17:47:40 +0800 Subject: [PATCH 2/6] Remove BOS descriptor, leave just manufacturer descriptor for Android --- common/usb_cdc.c | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/common/usb_cdc.c b/common/usb_cdc.c index 36df2a86..3553d850 100644 --- a/common/usb_cdc.c +++ b/common/usb_cdc.c @@ -156,28 +156,6 @@ static const char cfgDescriptor[] = { 0x00, 0x00 // bInterval }; -const char BOSDescriptor[] = { - // BOS descriptor header - 0x05, 0x0F, 0x39, 0x00, 0x02, - - // Microsoft OS 2.0 Platform Capability Descriptor - 0x1C, // Descriptor size (28 bytes) - 0x10, // Descriptor type (Device Capability) - 0x05, // Capability type (Platform) - 0x00, // Reserved - - // MS OS 2.0 Platform Capability ID (D8DD60DF-4589-4CC7-9CD2-659D9E648A9F) - 0xDF, 0x60, 0xDD, 0xD8, - 0x89, 0x45, - 0xC7, 0x4C, - 0x9C, 0xD2, - 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F, - - 0x00, 0x00, 0x03, 0x06, // Windows version (8.1) (0x06030000) - 0x1e, 0x00, - 252, // Vendor-assigned bMS_VendorCode - 0x00 // Doesn’t support alternate enumeration -}; static const char StrDescLanguageCodes[] = { 4, // Length @@ -572,8 +550,6 @@ void AT91F_CDC_Enumerate() { AT91F_USB_SendData(pUdp, devDescriptor, MIN(sizeof(devDescriptor), wLength)); else if (wValue == 0x200) // Return Configuration Descriptor AT91F_USB_SendData(pUdp, cfgDescriptor, MIN(sizeof(cfgDescriptor), wLength)); - else if ((wValue & 0xF00) == 0xF00) // Return BOS Descriptor - AT91F_USB_SendData(pUdp, BOSDescriptor, MIN(sizeof(BOSDescriptor), wLength)); else if ((wValue & 0x300) == 0x300) // Return Manufacturer Descriptor - this is needed by Android AT91F_USB_SendData(pUdp, StrDescManufacturer, MIN(sizeof(StrDescManufacturer), wLength)); else if ((wValue & 0xF00) == 0x300) { // Return String Descriptor From c179e7b1f886f5ca0c2f924197349195a8925215 Mon Sep 17 00:00:00 2001 From: Proxcloud Date: Thu, 8 Feb 2018 19:37:55 +0800 Subject: [PATCH 3/6] remove old Manufacturer description code. fix Product description length --- common/usb_cdc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/common/usb_cdc.c b/common/usb_cdc.c index 3553d850..d3f5cd0c 100644 --- a/common/usb_cdc.c +++ b/common/usb_cdc.c @@ -183,7 +183,7 @@ static const char StrDescManufacturer[] = { }; static const char StrDescProduct[] = { - 8, // Length + 4, // Length 0x03, // Type is string 'P', 0x00, 'M', 0x00, @@ -550,16 +550,15 @@ void AT91F_CDC_Enumerate() { AT91F_USB_SendData(pUdp, devDescriptor, MIN(sizeof(devDescriptor), wLength)); else if (wValue == 0x200) // Return Configuration Descriptor AT91F_USB_SendData(pUdp, cfgDescriptor, MIN(sizeof(cfgDescriptor), wLength)); - else if ((wValue & 0x300) == 0x300) // Return Manufacturer Descriptor - this is needed by Android - AT91F_USB_SendData(pUdp, StrDescManufacturer, MIN(sizeof(StrDescManufacturer), wLength)); else if ((wValue & 0xF00) == 0x300) { // Return String Descriptor const char *strDescriptor = getStringDescriptor(wValue & 0xff); if (strDescriptor != NULL) { AT91F_USB_SendData(pUdp, strDescriptor, MIN(strDescriptor[0], wLength)); } else { - AT91F_USB_SendStall(pUdp); + AT91F_USB_SendData(pUdp, StrDescManufacturer, MIN(sizeof(StrDescManufacturer), wLength)); } } + else AT91F_USB_SendStall(pUdp); break; From 13c25f892e003f1fa3639b7154782c3146aad4eb Mon Sep 17 00:00:00 2001 From: Proxcloud Date: Thu, 8 Feb 2018 19:43:03 +0800 Subject: [PATCH 4/6] remove debug change --- common/usb_cdc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/usb_cdc.c b/common/usb_cdc.c index d3f5cd0c..51dcacdb 100644 --- a/common/usb_cdc.c +++ b/common/usb_cdc.c @@ -555,10 +555,9 @@ void AT91F_CDC_Enumerate() { if (strDescriptor != NULL) { AT91F_USB_SendData(pUdp, strDescriptor, MIN(strDescriptor[0], wLength)); } else { - AT91F_USB_SendData(pUdp, StrDescManufacturer, MIN(sizeof(StrDescManufacturer), wLength)); + AT91F_USB_SendStall(pUdp); } } - else AT91F_USB_SendStall(pUdp); break; From d03a573eee1e2d9f87990524fee3502d5e730665 Mon Sep 17 00:00:00 2001 From: Proxcloud Date: Thu, 8 Feb 2018 20:40:57 +0800 Subject: [PATCH 5/6] change product desc to 9 and add extra null byte --- common/usb_cdc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/usb_cdc.c b/common/usb_cdc.c index 51dcacdb..82522623 100644 --- a/common/usb_cdc.c +++ b/common/usb_cdc.c @@ -183,11 +183,12 @@ static const char StrDescManufacturer[] = { }; static const char StrDescProduct[] = { - 4, // Length + 9, // Length 0x03, // Type is string 'P', 0x00, 'M', 0x00, - '3', 0x00 + '3', 0x00, + 0x00 }; const char* getStringDescriptor(uint8_t idx) From f3dc6d59f45e25fd199cb20cdf4d3af270d93963 Mon Sep 17 00:00:00 2001 From: Proxcloud Date: Thu, 8 Feb 2018 22:32:08 +0800 Subject: [PATCH 6/6] make product string even length --- common/usb_cdc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/common/usb_cdc.c b/common/usb_cdc.c index 82522623..d33bca7b 100644 --- a/common/usb_cdc.c +++ b/common/usb_cdc.c @@ -183,12 +183,17 @@ static const char StrDescManufacturer[] = { }; static const char StrDescProduct[] = { - 9, // Length + 20, // Length 0x03, // Type is string - 'P', 0x00, - 'M', 0x00, - '3', 0x00, - 0x00 + 'p', 0x00, + 'r', 0x00, + 'o', 0x00, + 'x', 0x00, + 'm', 0x00, + 'a', 0x00, + 'r', 0x00, + 'k', 0x00, + '3', 0x00 }; const char* getStringDescriptor(uint8_t idx)