RNDISClassHost.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2017.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaims all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. * \brief Host mode driver for the library USB RNDIS Class driver.
  28. *
  29. * Host mode driver for the library USB RNDIS Class driver.
  30. *
  31. * \note This file should not be included directly. It is automatically included as needed by the USB module driver
  32. * dispatch header located in LUFA/Drivers/USB.h.
  33. */
  34. /** \ingroup Group_USBClassRNDIS
  35. * \defgroup Group_USBClassRNDISHost RNDIS Class Host Mode Driver
  36. *
  37. * \section Sec_USBClassRNDISHost_Dependencies Module Source Dependencies
  38. * The following files must be built with any user project that uses this module:
  39. * - LUFA/Drivers/USB/Class/Host/RNDISClassHost.c <i>(Makefile source module name: LUFA_SRC_USBCLASS)</i>
  40. *
  41. * \section Sec_USBClassRNDISHost_ModDescription Module Description
  42. * Host Mode USB Class driver framework interface, for the Microsoft RNDIS Ethernet
  43. * USB Class driver.
  44. *
  45. * @{
  46. */
  47. #ifndef __RNDIS_CLASS_HOST_H__
  48. #define __RNDIS_CLASS_HOST_H__
  49. /* Includes: */
  50. #include "../../USB.h"
  51. #include "../Common/RNDISClassCommon.h"
  52. /* Enable C linkage for C++ Compilers: */
  53. #if defined(__cplusplus)
  54. extern "C" {
  55. #endif
  56. /* Preprocessor Checks: */
  57. #if !defined(__INCLUDE_FROM_RNDIS_DRIVER)
  58. #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
  59. #endif
  60. /* Public Interface - May be used in end-application: */
  61. /* Type Defines: */
  62. /** \brief RNDIS Class Host Mode Configuration and State Structure.
  63. *
  64. * Class state structure. An instance of this structure should be made within the user application,
  65. * and passed to each of the RNDIS class driver functions as the \c RNDISInterfaceInfo parameter. This
  66. * stores each RNDIS interface's configuration and state information.
  67. */
  68. typedef struct
  69. {
  70. struct
  71. {
  72. USB_Pipe_Table_t DataINPipe; /**< Data IN Pipe configuration table. */
  73. USB_Pipe_Table_t DataOUTPipe; /**< Data OUT Pipe configuration table. */
  74. USB_Pipe_Table_t NotificationPipe; /**< Notification IN Pipe configuration table. */
  75. uint32_t HostMaxPacketSize; /**< Maximum size of a packet which can be buffered by the host. */
  76. } Config; /**< Config data for the USB class interface within the device. All elements in this section
  77. * <b>must</b> be set or the interface will fail to enumerate and operate correctly.
  78. */
  79. struct
  80. {
  81. bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid
  82. * after \ref RNDIS_Host_ConfigurePipes() is called and the Host state machine is in the
  83. * Configured state.
  84. */
  85. uint8_t ControlInterfaceNumber; /**< Interface index of the RNDIS control interface within the attached device. */
  86. uint32_t DeviceMaxPacketSize; /**< Maximum size of a packet which can be buffered by the attached RNDIS device. */
  87. uint32_t RequestID; /**< Request ID counter to give a unique ID for each command/response pair. */
  88. } State; /**< State data for the USB class interface within the device. All elements in this section
  89. * <b>may</b> be set to initial values, but may also be ignored to default to sane values when
  90. * the interface is enumerated.
  91. */
  92. } USB_ClassInfo_RNDIS_Host_t;
  93. /* Enums: */
  94. /** Enum for the possible error codes returned by the \ref RNDIS_Host_ConfigurePipes() function. */
  95. enum RNDIS_Host_EnumerationFailure_ErrorCodes_t
  96. {
  97. RNDIS_ENUMERROR_NoError = 0, /**< Configuration Descriptor was processed successfully. */
  98. RNDIS_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor. */
  99. RNDIS_ENUMERROR_NoCompatibleInterfaceFound = 2, /**< A compatible RNDIS interface was not found in the device's Configuration Descriptor. */
  100. RNDIS_ENUMERROR_PipeConfigurationFailed = 3, /**< One or more pipes for the specified interface could not be configured correctly. */
  101. };
  102. /* Function Prototypes: */
  103. /** Host interface configuration routine, to configure a given RNDIS host interface instance using the Configuration
  104. * Descriptor read from an attached USB device. This function automatically updates the given RNDIS Host instance's
  105. * state values and configures the pipes required to communicate with the interface if it is found within the device.
  106. * This should be called once after the stack has enumerated the attached device, while the host state machine is in
  107. * the Addressed state.
  108. *
  109. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class host configuration and state.
  110. * \param[in] ConfigDescriptorSize Length of the attached device's Configuration Descriptor.
  111. * \param[in] ConfigDescriptorData Pointer to a buffer containing the attached device's Configuration Descriptor.
  112. *
  113. * \return A value from the \ref RNDIS_Host_EnumerationFailure_ErrorCodes_t enum.
  114. */
  115. uint8_t RNDIS_Host_ConfigurePipes(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
  116. uint16_t ConfigDescriptorSize,
  117. void* ConfigDescriptorData) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);
  118. /** Sends a RNDIS KEEPALIVE command to the device, to ensure that it does not enter standby mode after periods
  119. * of long inactivity.
  120. *
  121. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class host configuration and state.
  122. *
  123. * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum or \ref RNDIS_ERROR_LOGICAL_CMD_FAILED if the device returned a
  124. * logical command failure.
  125. */
  126. uint8_t RNDIS_Host_SendKeepAlive(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
  127. /** Initializes the attached RNDIS device's RNDIS interface. This should be called after the device's pipes have been
  128. * configured via the call to \ref RNDIS_Host_ConfigurePipes().
  129. *
  130. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class host configuration and state.
  131. *
  132. * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum or \ref RNDIS_ERROR_LOGICAL_CMD_FAILED if the
  133. * device returned a logical command failure.
  134. */
  135. uint8_t RNDIS_Host_InitializeDevice(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
  136. /** Sets a given RNDIS property of an attached RNDIS device.
  137. *
  138. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class host configuration and state.
  139. * \param[in] Oid OID number of the parameter to set.
  140. * \param[in] Buffer Pointer to where the property data is to be sourced from.
  141. * \param[in] Length Length in bytes of the property data to sent to the device.
  142. *
  143. * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum or \ref RNDIS_ERROR_LOGICAL_CMD_FAILED if the
  144. * device returned a logical command failure.
  145. */
  146. uint8_t RNDIS_Host_SetRNDISProperty(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
  147. const uint32_t Oid,
  148. void* Buffer,
  149. const uint16_t Length) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);
  150. /** Gets a given RNDIS property of an attached RNDIS device.
  151. *
  152. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class host configuration and state.
  153. * \param[in] Oid OID number of the parameter to get.
  154. * \param[in] Buffer Pointer to where the property data is to be written to.
  155. * \param[in] MaxLength Length in bytes of the destination buffer size.
  156. *
  157. * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum or \ref RNDIS_ERROR_LOGICAL_CMD_FAILED if the
  158. * device returned a logical command failure.
  159. */
  160. uint8_t RNDIS_Host_QueryRNDISProperty(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
  161. const uint32_t Oid,
  162. void* Buffer,
  163. const uint16_t MaxLength) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);
  164. /** Determines if a packet is currently waiting for the host to read in and process.
  165. *
  166. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  167. * call will fail.
  168. *
  169. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class host configuration and state.
  170. *
  171. * \return Boolean \c true if a packet is waiting to be read in by the host, \c false otherwise.
  172. */
  173. bool RNDIS_Host_IsPacketReceived(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
  174. /** Retrieves the next pending packet from the device, discarding the remainder of the RNDIS packet header to leave
  175. * only the packet contents for processing by the host in the nominated buffer.
  176. *
  177. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  178. * call will fail.
  179. *
  180. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class host configuration and state.
  181. * \param[out] Buffer Pointer to a buffer where the packer data is to be written to.
  182. * \param[out] PacketLength Pointer to where the length in bytes of the read packet is to be stored.
  183. *
  184. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
  185. */
  186. uint8_t RNDIS_Host_ReadPacket(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
  187. void* Buffer,
  188. uint16_t* const PacketLength) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2)
  189. ATTR_NON_NULL_PTR_ARG(3);
  190. /** Sends the given packet to the attached RNDIS device, after adding a RNDIS packet message header.
  191. *
  192. * \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the
  193. * call will fail.
  194. *
  195. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class host configuration and state.
  196. * \param[in] Buffer Pointer to a buffer where the packer data is to be read from.
  197. * \param[in] PacketLength Length in bytes of the packet to send.
  198. *
  199. * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
  200. */
  201. uint8_t RNDIS_Host_SendPacket(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
  202. void* Buffer,
  203. const uint16_t PacketLength) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
  204. /* Inline Functions: */
  205. /** General management task for a given RNDIS host class interface, required for the correct operation of the interface. This should
  206. * be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
  207. *
  208. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class host configuration and state.
  209. */
  210. static inline void RNDIS_Host_USBTask(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
  211. static inline void RNDIS_Host_USBTask(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo)
  212. {
  213. (void)RNDISInterfaceInfo;
  214. }
  215. /* Private Interface - For use in library only: */
  216. #if !defined(__DOXYGEN__)
  217. /* Function Prototypes: */
  218. #if defined(__INCLUDE_FROM_RNDIS_HOST_C)
  219. static uint8_t RNDIS_SendEncapsulatedCommand(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
  220. void* Buffer,
  221. const uint16_t Length) ATTR_NON_NULL_PTR_ARG(1)
  222. ATTR_NON_NULL_PTR_ARG(2);
  223. static uint8_t RNDIS_GetEncapsulatedResponse(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
  224. void* Buffer,
  225. const uint16_t Length) ATTR_NON_NULL_PTR_ARG(1)
  226. ATTR_NON_NULL_PTR_ARG(2);
  227. static uint8_t DCOMP_RNDIS_Host_NextRNDISControlInterface(void* const CurrentDescriptor)
  228. ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
  229. static uint8_t DCOMP_RNDIS_Host_NextRNDISDataInterface(void* const CurrentDescriptor)
  230. ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
  231. static uint8_t DCOMP_RNDIS_Host_NextRNDISInterfaceEndpoint(void* const CurrentDescriptor)
  232. ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
  233. #endif
  234. #endif
  235. /* Disable C linkage for C++ Compilers: */
  236. #if defined(__cplusplus)
  237. }
  238. #endif
  239. #endif
  240. /** @} */