]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - common/usb_cdc.c
Add BOS USB descriptor. This allows non-root access on Android devices
[proxmark3-svn] / common / usb_cdc.c
index 56690ad87f69c42a095a2f515341dbf44304f858..36df2a860910d830820de12a3c59aae105dad2e3 100644 (file)
 #define AT91C_EP_OUT_SIZE 0x40\r
 #define AT91C_EP_IN_SIZE  0x40\r
 \r
+// Language must always be 0.\r
+#define STR_LANGUAGE_CODES 0x00\r
+#define STR_MANUFACTURER   0x01\r
+#define STR_PRODUCT        0x02\r
+\r
 static const char devDescriptor[] = {\r
        /* Device descriptor */\r
        0x12,      // bLength\r
@@ -56,8 +61,8 @@ static const char devDescriptor[] = {
        0xc4,0x9a, // Vendor ID (0x9ac4 = J. Westhues)\r
        0x8f,0x4b, // Product ID (0x4b8f = Proxmark-3 RFID Instrument)\r
        0x01,0x00, // Device release number (0001)\r
-       0x01,      // iManufacturer\r
-       0x02,      // iProduct\r
+       STR_MANUFACTURER,  // iManufacturer\r
+       STR_PRODUCT,       // iProduct\r
        0x00,      // iSerialNumber\r
        0x01       // bNumConfigs\r
 };\r
@@ -72,8 +77,8 @@ static const char cfgDescriptor[] = {
        0x02,   // CbNumInterfaces\r
        0x01,   // CbConfigurationValue\r
        0x00,   // CiConfiguration\r
-       0xC0,   // CbmAttributes 0xA0\r
-       0xFA,   // CMaxPower\r
+       0x80,   // CbmAttributes (Bus Powered)\r
+       0x4B,   // CMaxPower (150mA max current drawn from bus)\r
 \r
        /* Interface 0 Descriptor: Communication Class Interface */\r
        0x09, // bLength\r
@@ -151,13 +156,37 @@ static const char cfgDescriptor[] = {
        0x00,\r
        0x00    // bInterval\r
 };\r
+const char BOSDescriptor[] = {\r
+       // BOS descriptor header\r
+       0x05, 0x0F, 0x39, 0x00, 0x02,\r
+\r
+       // Microsoft OS 2.0 Platform Capability Descriptor\r
+       0x1C,  // Descriptor size (28 bytes)\r
+       0x10,  // Descriptor type (Device Capability)\r
+       0x05,  // Capability type (Platform)\r
+       0x00,  // Reserved\r
+\r
+       // MS OS 2.0 Platform Capability ID (D8DD60DF-4589-4CC7-9CD2-659D9E648A9F)\r
+       0xDF, 0x60, 0xDD, 0xD8,\r
+       0x89, 0x45,\r
+       0xC7, 0x4C,\r
+       0x9C, 0xD2,\r
+       0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F,\r
+\r
+       0x00, 0x00, 0x03, 0x06,    // Windows version (8.1) (0x06030000)\r
+       0x1e, 0x00,\r
+       252,    // Vendor-assigned bMS_VendorCode\r
+       0x00    // Doesn’t support alternate enumeration\r
+};\r
 \r
 static const char StrDescLanguageCodes[] = {\r
   4,                   // Length\r
   0x03,                        // Type is string\r
   0x09, 0x04   // supported language Code 0 = 0x0409 (English)\r
 };\r
-       \r
+\r
+// Note: ModemManager (Linux) ignores Proxmark3 devices by matching the\r
+// manufacturer string "proxmark.org". Don't change this.\r
 static const char StrDescManufacturer[] = {\r
   26,                  // Length\r
   0x03,                        // Type is string\r
@@ -182,20 +211,18 @@ static const char StrDescProduct[] = {
   'M', 0x00,\r
   '3', 0x00\r
 };\r
-       \r
-static const char* const pStrings[] =\r
-{\r
-    StrDescLanguageCodes,\r
-    StrDescManufacturer,\r
-       StrDescProduct\r
-};\r
 \r
 const char* getStringDescriptor(uint8_t idx)\r
 {\r
-    if(idx >= (sizeof(pStrings) / sizeof(pStrings[0]))) {\r
-        return(NULL);\r
-       } else {\r
-               return(pStrings[idx]);\r
+       switch (idx) {\r
+               case STR_LANGUAGE_CODES:\r
+                       return StrDescLanguageCodes;\r
+               case STR_MANUFACTURER:\r
+                       return StrDescManufacturer;\r
+               case STR_PRODUCT:\r
+                       return StrDescProduct;\r
+               default:\r
+                       return NULL;\r
        }\r
 }\r
 \r
@@ -545,6 +572,10 @@ void AT91F_CDC_Enumerate() {
                        AT91F_USB_SendData(pUdp, devDescriptor, MIN(sizeof(devDescriptor), wLength));\r
                else if (wValue == 0x200)  // Return Configuration Descriptor\r
                        AT91F_USB_SendData(pUdp, cfgDescriptor, MIN(sizeof(cfgDescriptor), wLength));\r
+               else if ((wValue & 0xF00) == 0xF00)  // Return BOS Descriptor\r
+                       AT91F_USB_SendData(pUdp, BOSDescriptor, MIN(sizeof(BOSDescriptor), wLength));\r
+               else if ((wValue & 0x300) == 0x300)  // Return Manufacturer Descriptor - this is needed by Android\r
+                       AT91F_USB_SendData(pUdp, StrDescManufacturer, MIN(sizeof(StrDescManufacturer), wLength));\r
                else if ((wValue & 0xF00) == 0x300) { // Return String Descriptor\r
                        const char *strDescriptor = getStringDescriptor(wValue & 0xff);\r
                        if (strDescriptor != NULL) {\r
Impressum, Datenschutz