usbd_vendor_desc.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. #include "usbd_vendor_desc.h"
  2. #include "usbd_vendor.h"
  3. #include "usbd_desc.h"
  4. #include "usbd_ctlreq.h"
  5. static const uint8_t * USBD_VENDOR_GetDeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  6. //static const uint8_t * USBD_VENDOR_GetLangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  7. static const uint8_t * USBD_VENDOR_GetManufacturerStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  8. static const uint8_t * USBD_VENDOR_GetProductStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  9. static const uint8_t * USBD_VENDOR_GetSerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  10. static const uint8_t * USBD_VENDOR_GetConfigurationStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  11. static const uint8_t * USBD_VENDOR_GetInterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
  12. static const uint8_t * USBD_VENDOR_GetCfgDesc( USBD_SpeedTypeDef speed ,uint16_t *length );
  13. static const uint8_t * USBD_VENDOR_GetMsOsStringDescriptor (USBD_SpeedTypeDef speed, uint16_t *length);
  14. static const uint8_t * USBD_VENDOR_GetExtCompatIdOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t * length);
  15. static const uint8_t * USBD_VENDOR_GetExtPropertiesOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t * length);
  16. #define USBD_VENDOR_LANGID_STRING 1033
  17. const USBD_DescriptorsTypeDef USBD_VENDOR_DescriptorHandlers = {
  18. #if USBD_GETDESCRIPTORS_ALTMETHOD == 1
  19. // default handlers
  20. USBD_GETDESCRIPTOR_DEFAULT_HANDLERS_SET,
  21. #endif
  22. // overrided handlers:
  23. .GetDeviceDescriptor = USBD_VENDOR_GetDeviceDescriptor,
  24. //.GetLangIDStrDescriptor = USBD_VENDOR_GetLangIDStrDescriptor,
  25. .GetManufacturerStrDescriptor = USBD_VENDOR_GetManufacturerStrDescriptor,
  26. .GetProductStrDescriptor = USBD_VENDOR_GetProductStrDescriptor,
  27. //.GetSerialStrDescriptor = USBD_VENDOR_GetSerialStrDescriptor,
  28. .GetConfigurationStrDescriptor = USBD_VENDOR_GetConfigurationStrDescriptor,
  29. .GetInterfaceStrDescriptor = USBD_VENDOR_GetInterfaceStrDescriptor,
  30. .GetConfigDescriptor = USBD_VENDOR_GetCfgDesc,
  31. .GetMsOsStringDescriptor = USBD_VENDOR_GetMsOsStringDescriptor,
  32. .GetExtCompatIdOsFeatureDescriptor = USBD_VENDOR_GetExtCompatIdOsFeatureDescriptor,
  33. .GetExtPropertiesOsFeatureDescriptor = USBD_VENDOR_GetExtPropertiesOsFeatureDescriptor
  34. };
  35. #if defined ( __ICCARM__ ) /* IAR Compiler */
  36. #pragma data_alignment=4
  37. #endif /* defined ( __ICCARM__ ) */
  38. /** USB standard device descriptor. */
  39. static __ALIGN_BEGIN const uint8_t USBD_VENDOR_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
  40. {
  41. USB_LEN_DEV_DESC, /*bLength */
  42. USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
  43. LOBYTE(0x0200), /*bcdUSB */
  44. HIBYTE(0x0200), /*bcdUSB */
  45. 0x02, /*bDeviceClass*/
  46. 0x02, /*bDeviceSubClass*/
  47. 0x00, /*bDeviceProtocol*/
  48. USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
  49. LOBYTE(USB_VID), /*idVendor*/
  50. HIBYTE(USB_VID), /*idVendor*/
  51. LOBYTE(USB_PID_VENDOR), /*idProduct*/
  52. HIBYTE(USB_PID_VENDOR), /*idProduct*/
  53. LOBYTE(0x0200), /*bcdDevice rel. 2.00*/
  54. HIBYTE(0x0200),
  55. USBD_IDX_MFC_STR, /*Index of manufacturer string*/
  56. USBD_IDX_PRODUCT_STR, /*Index of product string*/
  57. USBD_IDX_SERIAL_STR, /*Index of serial number string*/
  58. USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
  59. };
  60. /**
  61. * @brief Return the device descriptor
  62. * @param speed : Current device speed
  63. * @param length : Pointer to data length variable
  64. * @retval Pointer to descriptor buffer
  65. */
  66. static const uint8_t * USBD_VENDOR_GetDeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  67. {
  68. *length = sizeof(USBD_VENDOR_DeviceDesc);
  69. return USBD_VENDOR_DeviceDesc;
  70. }
  71. #define USB_VENDOR_CONFIG_DESC_SIZ 18
  72. /* USB Vendor device Configuration Descriptor */
  73. __ALIGN_BEGIN const uint8_t USBD_VENDOR_CfgDesc[USB_VENDOR_CONFIG_DESC_SIZ] __ALIGN_END =
  74. {
  75. /*Configuration Descriptor*/
  76. 0x09, /* bLength: Configuration Descriptor size */
  77. USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
  78. USB_VENDOR_CONFIG_DESC_SIZ, /* wTotalLength: # of returned bytes */
  79. 0x00,
  80. 0x01, /* bNumInterfaces: 1 interface */
  81. 0x01, /* bConfigurationValue: Configuration value */
  82. 0x00, /* iConfiguration: Index of string descriptor describing the configuration */
  83. 0x80, /* bmAttributes: no options */
  84. 0x32, /* MaxPower 0 mA */
  85. /*---------------------------------------------------------------------------*/
  86. /*Data class interface descriptor*/
  87. 0x09, /* bLength: Endpoint Descriptor size */
  88. USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
  89. 0x00, /* bInterfaceNumber: Number of Interface */
  90. 0x00, /* bAlternateSetting: Alternate setting */
  91. 0x00, /* bNumEndpoints: No endpoints used */
  92. 0x00, /* bInterfaceClass: */
  93. 0x00, /* bInterfaceSubClass: */
  94. 0x00, /* bInterfaceProtocol: */
  95. 0x00, /* iInterface: */
  96. };
  97. #define USB_MICROSOFT_OS_STRING_DECRIPTOR_SIZ 18
  98. /* USB Vendor device Configuration Descriptor */
  99. static __ALIGN_BEGIN const uint8_t USBD_VENDOR_MSOSDESCR[USB_MICROSOFT_OS_STRING_DECRIPTOR_SIZ] __ALIGN_END =
  100. {
  101. /*Configuration Descriptor*/
  102. 0x12, /* bLength: Configuration Descriptor size */
  103. USB_DESC_TYPE_STRING, /* bDescriptorType: Configuration */
  104. 0x4D, 0x00, 0x53, /* Signature: 'MSFT100' UNICODE STRING (LE)*/
  105. 0x00, 0x46, 0x00,
  106. 0x54, 0x00, 0x31,
  107. 0x00, 0x30, 0x00,
  108. 0x30, 0x00,
  109. USBD_MSOS_VENDOR, /* Vendor Code: */
  110. 0x00, /* Padding: */
  111. };
  112. #define USB_MICROSOFT_OS_COMP_DECRIPTOR_SIZ 40
  113. /* USB Vendor device Configuration Descriptor */
  114. static __ALIGN_BEGIN const uint8_t USBD_VENDOR_MSCOMPATIBLEDESCR[USB_MICROSOFT_OS_COMP_DECRIPTOR_SIZ] __ALIGN_END =
  115. {
  116. /*Configuration Descriptor*/
  117. 0x28, 0x00, 0x00, 0x00, /* bLength: Descriptor length (40 bytes) */
  118. 0x00, 0x01, /* Version ('1.0') */
  119. 0x04, 0x00, /* Compatible ID Descriptor index (0x0004)*/
  120. 0x01, /* Number of sections (1) */
  121. 0x00, 0x00, 0x00, 0x00, /* Reserved */
  122. 0x00, 0x00, 0x00,
  123. 0x00, /* Interface Number (Interface #0) */
  124. 0x01, /* Reserved */
  125. 'W', 'I', 'N', 'U', /* Compatible ID ("WINUSB\0\0") */
  126. 'S', 'B', 0x00, 0x00,
  127. 0x00, 0x00, 0x00, 0x00, /* Sub-Compatible Id (unused) */
  128. 0x00, 0x00, 0x00, 0x00,
  129. 0x00, 0x00, 0x00, 0x00, /* Reserved */
  130. 0x00, 0x00,
  131. };
  132. #define USB_MICROSOFT_EXT_PROP_SIZ 142
  133. /* USB Vendor device Configuration Descriptor */
  134. static __ALIGN_BEGIN const uint8_t USBD_VENDOR_EXTPROPDESCR[USB_MICROSOFT_EXT_PROP_SIZ] __ALIGN_END =
  135. {
  136. /*Extended properties Descriptor Header*/
  137. 0x8E, 0x00, 0x00, 0x00, /* bLength: Descriptor length (142 bytes) */
  138. 0x00, 0x01, /* Version ('1.0') */
  139. 0x05, 0x00, /* Extended property descriptor index*/
  140. 0x01, 0x00, /* Number of sections (1) */
  141. /* Custom Property section 1 */
  142. 0x84, 0x00, 0x00, 0x00, /* Size of the property section (132 bytes) */
  143. 0x01, 0x00, 0x00, 0x00, /* Property data type (1 - UNICODE) */
  144. 0x28, 0x00, /* Property name length (40 bytes) */
  145. 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, /* 'DeviceIntefaceGUID'*/
  146. 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00,
  147. 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00,
  148. 'D', 0x00, 0x00, 0x00,
  149. 0x4E, 0x00, 0x00, 0x00, /* Property Name {78cdcb7a-6971-4210-997c-5b8ea05e1715} */
  150. '{', 0x00, '7', 0x00, '8', 0x00, 'C', 0x00, 'D', 0x00, 'C', 0x00, 'B', 0x00, '7', 0x00, 'A', 0x00, '-', 0x00,
  151. '6', 0x00, '9', 0x00, '7', 0x00, '1', 0x00, '-', 0x00,
  152. '4', 0x00, '2', 0x00, '1', 0x00, '0', 0x00, '-', 0x00,
  153. '9', 0x00, '9', 0x00, '7', 0x00, 'C', 0x00, '-', 0x00,
  154. '5', 0x00, 'B', 0x00, '8', 0x00, 'E', 0x00, 'A', 0x00, '0', 0x00, '5', 0x00, 'E', 0x00, '1', 0x00, '7', 0x00, '1', 0x00, '5', 0x00, '}', 0x00, 0x00, 0x00,
  155. };
  156. /**
  157. * @brief USBD_VENDOR_GetCfgDesc
  158. * Return configuration descriptor
  159. * @param speed : current device speed
  160. * @param length : pointer data length
  161. * @retval pointer to descriptor buffer
  162. */
  163. static const uint8_t * USBD_VENDOR_GetCfgDesc (USBD_SpeedTypeDef speed, uint16_t *length)
  164. {
  165. *length = sizeof (USBD_VENDOR_CfgDesc);
  166. return USBD_VENDOR_CfgDesc;
  167. }
  168. #if defined ( __ICCARM__ ) /* IAR Compiler */
  169. #pragma data_alignment=4
  170. #endif /* defined ( __ICCARM__ ) */
  171. /** USB lang indentifier descriptor. */
  172. /*
  173. static __ALIGN_BEGIN const uint8_t USBD_VENDOR_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
  174. {
  175. USB_LEN_LANGID_STR_DESC,
  176. USB_DESC_TYPE_STRING,
  177. LOBYTE(USBD_VENDOR_LANGID_STRING),
  178. HIBYTE(USBD_VENDOR_LANGID_STRING)
  179. };
  180. */
  181. /**
  182. * @brief Return the LangID string descriptor
  183. * @param speed : Current device speed
  184. * @param length : Pointer to data length variable
  185. * @retval Pointer to descriptor buffer
  186. */
  187. /*
  188. static const uint8_t * USBD_VENDOR_GetLangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  189. {
  190. *length = sizeof(USBD_VENDOR_LangIDDesc);
  191. return USBD_VENDOR_LangIDDesc;
  192. }
  193. */
  194. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  195. static const uint8_t * USBD_VENDOR_GetMsOsStringDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  196. #else
  197. const uint8_t * USBD_VENDOR_GetMsOsStringDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  198. #endif
  199. {
  200. *length = sizeof(USBD_VENDOR_MSOSDESCR);
  201. return USBD_VENDOR_MSOSDESCR;
  202. }
  203. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  204. static const uint8_t * USBD_VENDOR_GetExtCompatIdOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  205. #else
  206. const uint8_t * USBD_VENDOR_GetExtCompatIdOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  207. #endif
  208. {
  209. *length = sizeof(USBD_VENDOR_MSCOMPATIBLEDESCR);
  210. return USBD_VENDOR_MSCOMPATIBLEDESCR;
  211. }
  212. #if USBD_GETDESCRIPTORS_ALTMETHOD == 0
  213. static const uint8_t * USBD_VENDOR_GetExtPropertiesOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  214. #else
  215. const uint8_t * USBD_VENDOR_GetExtPropertiesOsFeatureDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  216. #endif
  217. {
  218. *length = sizeof(USBD_VENDOR_EXTPROPDESCR);
  219. return USBD_VENDOR_EXTPROPDESCR;
  220. }
  221. #if defined(CMT)
  222. //static const uint8_t USBD_VENDOR_MANUFACTURER_STRING[] = { 122, USB_DESC_TYPE_STRING,
  223. // 'C', 0, 'o', 0, 'p', 0, 'p', 0, 'e', 0, 'r', 0, ' ', 0, 'M', 0, 'o', 0, 'u', 0, 'n', 0, 't', 0, 'a', 0, 'i', 0, 'n', 0, ' ', 0, 'T', 0, 'e', 0, 'c', 0, 'h', 0, 'n', 0, 'o', 0, 'l', 0, 'o', 0, 'g', 0, 'i', 0, 'e', 0, 's', 0, ' ', 0, '(', 0, 'h', 0, 't', 0, 't', 0, 'p', 0, ':', 0, '/', 0, '/', 0, 'c', 0, 'o', 0, 'p', 0, 'p', 0, 'e', 0, 'r', 0, 'm', 0, 'o', 0, 'u', 0, 'n', 0, 't', 0, 'a', 0, 'i', 0, 'n', 0, 't', 0, 'e', 0, 'c', 0, 'h', 0, '.', 0, 'c', 0, 'o', 0, 'm', 0, ')', 0,
  224. //};
  225. static const uint8_t USBD_VENDOR_MANUFACTURER_STRING[] = { 8, USB_DESC_TYPE_STRING,
  226. 'C', 0, 'M', 0, 'T', 0,
  227. };
  228. #elif defined(PLANAR)
  229. static const uint8_t USBD_VENDOR_MANUFACTURER_STRING[] = { 68, USB_DESC_TYPE_STRING,
  230. 'P', 0,'l', 0,'a', 0,'n', 0,'a', 0,'r', 0,' ', 0,'(', 0,'h', 0,'t', 0, 't', 0,'p', 0,':', 0,'/', 0,'/', 0,'w', 0,'w', 0,'w', 0,'.', 0,'p', 0,'l', 0, 'a', 0, 'n', 0, 'a', 0, 'r', 0, 'c', 0, 'h', 0, 'e', 0, 'l', 0, '.', 0, 'r', 0, 'u', 0, ')', 0,
  231. };
  232. #else
  233. #error Specify PLANAR or CMT macro in project settings!
  234. #endif
  235. /**
  236. * @brief Return the manufacturer string descriptor
  237. * @param speed : Current device speed
  238. * @param length : Pointer to data length variable
  239. * @retval Pointer to descriptor buffer
  240. */
  241. static const uint8_t * USBD_VENDOR_GetManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  242. {
  243. *length = sizeof(USBD_VENDOR_MANUFACTURER_STRING);
  244. return USBD_VENDOR_MANUFACTURER_STRING;
  245. }
  246. static const uint8_t USBD_VENDOR_PRODUCT_STRING[] = { 38, USB_DESC_TYPE_STRING,
  247. 'M', 0,'K', 0,'2', 0,'0', 0,'7', 0,'-', 0,'0', 0, '4', 0, 'H', 0, ' ', 0, ' ', 0, ' ', 0, ' ', 0,' ', 0,' ', 0,' ', 0,' ', 0,' ', 0,
  248. };
  249. /**
  250. * @brief Return the product string descriptor
  251. * @param speed : Current device speed
  252. * @param length : Pointer to data length variable
  253. * @retval Pointer to descriptor buffer
  254. */
  255. static const uint8_t * USBD_VENDOR_GetProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  256. {
  257. *length = sizeof(USBD_VENDOR_PRODUCT_STRING);
  258. return USBD_VENDOR_PRODUCT_STRING;
  259. }
  260. //static const uint8_t USBD_VENDOR_SERIALNUMBER_STRING[] = { 26, USB_DESC_TYPE_STRING,
  261. //'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,'0',0,
  262. //};
  263. // /**
  264. // * @brief Return the serial number string descriptor
  265. // * @param speed : Current device speed
  266. // * @param length : Pointer to data length variable
  267. // * @retval Pointer to descriptor buffer
  268. // */
  269. // static const uint8_t * USBD_VENDOR_GetSerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  270. // {
  271. // *length = sizeof(USBD_VENDOR_SERIALNUMBER_STRING);
  272. // return USBD_VENDOR_SERIALNUMBER_STRING;
  273. // }
  274. static const uint8_t USBD_VENDOR_CONFIGURATION_STRING[] = { 22, USB_DESC_TYPE_STRING,
  275. 'M',0,'a',0,'i',0,'n',0,'C',0,'o',0,'n',0,'f',0,'i',0,'g',0,
  276. };
  277. /**
  278. * @brief Return the configuration string descriptor
  279. * @param speed : Current device speed
  280. * @param length : Pointer to data length variable
  281. * @retval Pointer to descriptor buffer
  282. */
  283. const uint8_t * USBD_VENDOR_GetConfigurationStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  284. {
  285. *length = sizeof(USBD_VENDOR_CONFIGURATION_STRING);
  286. return USBD_VENDOR_CONFIGURATION_STRING;
  287. }
  288. static const uint8_t USBD_VENDOR_INTERFACE_STRING_FS[] = { 24, USB_DESC_TYPE_STRING,
  289. 'V',0,'e',0,'n',0,'d',0,'o',0,'r',0,'I',0,'f',0,'a',0,'c',0,'e',0,
  290. };
  291. /**
  292. * @brief Return the interface string descriptor
  293. * @param speed : Current device speed
  294. * @param length : Pointer to data length variable
  295. * @retval Pointer to descriptor buffer
  296. */
  297. static const uint8_t * USBD_VENDOR_GetInterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  298. {
  299. *length = sizeof(USBD_VENDOR_INTERFACE_STRING_FS);
  300. return USBD_VENDOR_INTERFACE_STRING_FS;
  301. }