1
0

ms_os.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef _MS_OS_H_
  2. #define _MS_OS_H_
  3. /**
  4. * Extended Properties OS Feature Descriptor Specification
  5. * Extended Compat ID OS Feature Descriptor Specification
  6. * v1.0
  7. */
  8. /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers
  9. *
  10. * Copyright ©2018 Travis Robinson <libusbdotnet[at]gmail[dot]com>
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the "License");
  13. * you may not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. /** Macro to create a unicode char array */
  23. #define STRING_TO_WCHARS(s) {CAT(u,s)}
  24. /** Macro to return the total byte length of a string as if it were a unicode char array */
  25. #define SIZE_OF_WSTRING(s) sizeof(CAT(u,s))
  26. /** Total Length of a custom property name (in bytes).
  27. *
  28. * This can be hard-coded at 42 for a 'DeviceInterFaceGUIDs' property name.
  29. */
  30. #define MSOS_DEVGUID_NAME_BLEN (SIZE_OF_WSTRING("DeviceInterfaceGUIDs"))
  31. /** Total Length of a custom property value (in bytes).
  32. *
  33. * This can be hard-coded at 80 for a 'DeviceInterFaceGUIDs' property value.
  34. */
  35. #define MSOS_DEVGUID_VALUE_BLEN (SIZE_OF_WSTRING("{00000000-0000-0000-0000-000000000000}\0"))
  36. /**
  37. * \brief windows (winusb) Extended Compat ID OS Feature Descriptor
  38. *
  39. * Stores one or more compatible IDs and subcompatible IDs in device firmware on a per-interface or per-function
  40. * basis. Windows can then use these values much like class and subclass values to select an appropriate driver.
  41. * (WinUSB for example)
  42. */
  43. struct ms_os_compatid_descriptor {
  44. /**<\brief The length, in bytes, of the complete descriptor (DWORD LE). (40 bytes) */
  45. uint32_t dwLength;
  46. /**<\brief The descriptor’s version number, in binary coded decimal (BCD) format. (v1.00) */
  47. uint16_t bcdVersion;
  48. /**<\brief The index for extended properties OS descriptors. (always 0x04 for extended compat ID descriptors) */
  49. uint16_t wIndex;
  50. /**<\brief The number of custom property sections that follow the header section. (1 property) */
  51. uint8_t bCount;
  52. /**<\brief Not used. fill with zeros. */
  53. uint8_t _reservedA[7];
  54. /**<\brief Interface or function that is associated with the IDs in this section */
  55. uint8_t bInterfaceNumber;
  56. /**<\brief Not used. fill with zeros. */
  57. uint8_t _reservedB[1];
  58. /**<\brief A fixed string assign by Microsoft. 8 chars. fill extras with zero. (See MSDN) */
  59. uint8_t chCompatibleID[8];
  60. /**<\brief A fixed string assign by Microsoft. 8 chars. fill extras with zero. (See MSDN) */
  61. uint8_t chSubCompatibleID[8];
  62. /**<\brief Not used. fill with zeros. */
  63. uint8_t _reservedC[6];
  64. }__attribute__((packed));
  65. /**
  66. * \brief windows (winusb) \bDeviceInterfaceGUIDs custom property
  67. *
  68. * This is a DeviceInterfaceGUIDs property section used in \ref wusb_devguid_extprop_feature_descriptor.
  69. *
  70. */
  71. struct wusb_devguid_property {
  72. /**<\brief The size of this custom properties section, in bytes (136 bytes) */
  73. uint32_t dwPropertyLength;
  74. /**<\brief Property data format (7 = Unicode REG_MULTI_SZ) */
  75. uint32_t dwPropertyType;
  76. /**<\brief The total length of wPropertyName, in bytes (42) */
  77. uint16_t wPropertyNameLength;
  78. /**<\brief The property name, as a NULL-terminated Unicode string (42 bytes) */
  79. uint16_t wPropertyName[MSOS_DEVGUID_NAME_BLEN / 2];
  80. /**<\brief The total length of wPropertyData, in bytes (80) */
  81. uint32_t dwPropertyDataLength;
  82. /**<\brief (format-dependent) sz = Unicode strings (REG_MULTI_SZ, 76wchars + wnull + wnull = 80 bytes) */
  83. uint16_t wPropertyData[MSOS_DEVGUID_VALUE_BLEN / 2];
  84. } __attribute__((packed));
  85. /**
  86. * \brief windows (winusb) \bDeviceInterfaceGUIDs extended property feature descriptor
  87. *
  88. * This is an extended property feature descriptor containing a DeviceInterfaceGUIDs property section.
  89. *
  90. * Store DeviceInterfaceGUIDs in firmware and use them on Windows to locate and open a device.
  91. *
  92. */
  93. struct wusb_devguid_extprop_feature_descriptor {
  94. /**<\brief The length, in bytes, of the complete extended properties descriptor (DWORD LE). (146 bytes) */
  95. uint32_t dwLength;
  96. /**<\brief The descriptor’s version number, in binary coded decimal (BCD) format. */
  97. uint16_t bcdVersion;
  98. /**<\brief The index for extended properties OS descriptors. (always 5) */
  99. uint16_t wIndex;
  100. /**<\brief The number of custom property sections that follow the header section. (1 property) */
  101. uint16_t wCount;
  102. /**<\brief device interface guid custom property */
  103. struct wusb_devguid_property dev_guid_property;
  104. }__attribute__((packed));
  105. #endif