Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RNDISClassDevice.h 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2014 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 Device mode driver for the library USB RNDIS Class driver.
  28. *
  29. * Device 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_USBClassRNDISDevice RNDIS Class Device Mode Driver
  36. *
  37. * \section Sec_USBClassRNDISDevice_Dependencies Module Source Dependencies
  38. * The following files must be built with any user project that uses this module:
  39. * - LUFA/Drivers/USB/Class/Device/RNDISClassDevice.c <i>(Makefile source module name: LUFA_SRC_USBCLASS)</i>
  40. *
  41. * \section Sec_USBClassRNDISDevice_ModDescription Module Description
  42. * Device Mode USB Class driver framework interface, for the RNDIS USB Class driver.
  43. *
  44. * @{
  45. */
  46. #ifndef _RNDIS_CLASS_DEVICE_H_
  47. #define _RNDIS_CLASS_DEVICE_H_
  48. /* Includes: */
  49. #include "../../USB.h"
  50. #include "../Common/RNDISClassCommon.h"
  51. /* Enable C linkage for C++ Compilers: */
  52. #if defined(__cplusplus)
  53. extern "C" {
  54. #endif
  55. /* Preprocessor Checks: */
  56. #if !defined(__INCLUDE_FROM_RNDIS_DRIVER)
  57. #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
  58. #endif
  59. /* Public Interface - May be used in end-application: */
  60. /* Type Defines: */
  61. /** \brief RNDIS Class Device Mode Configuration and State Structure.
  62. *
  63. * Class state structure. An instance of this structure should be made for each RNDIS interface
  64. * within the user application, and passed to each of the RNDIS class driver functions as the
  65. * \c RNDISInterfaceInfo parameter. This stores each RNDIS interface's configuration and state information.
  66. */
  67. typedef struct
  68. {
  69. struct
  70. {
  71. uint8_t ControlInterfaceNumber; /**< Interface number of the RNDIS control interface within the device. */
  72. USB_Endpoint_Table_t DataINEndpoint; /**< Data IN endpoint configuration table. */
  73. USB_Endpoint_Table_t DataOUTEndpoint; /**< Data OUT endpoint configuration table. */
  74. USB_Endpoint_Table_t NotificationEndpoint; /**< Notification IN Endpoint configuration table. */
  75. char* AdapterVendorDescription; /**< String description of the adapter vendor. */
  76. MAC_Address_t AdapterMACAddress; /**< MAC address of the adapter. */
  77. uint8_t* MessageBuffer; /**< Buffer where RNDIS messages can be stored by the internal driver. This
  78. * should be at least 132 bytes in length for minimal functionality. */
  79. uint16_t MessageBufferLength; /**< Length in bytes of the \ref MessageBuffer RNDIS buffer. */
  80. } Config; /**< Config data for the USB class interface within the device. All elements in this section
  81. * <b>must</b> be set or the interface will fail to enumerate and operate correctly.
  82. */
  83. struct
  84. {
  85. bool ResponseReady; /**< Internal flag indicating if a RNDIS message is waiting to be returned to the host. */
  86. uint8_t CurrRNDISState; /**< Current RNDIS state of the adapter, a value from the \ref RNDIS_States_t enum. */
  87. uint32_t CurrPacketFilter; /**< Current packet filter mode, used internally by the class driver. */
  88. } State; /**< State data for the USB class interface within the device. All elements in this section
  89. * are reset to their defaults when the interface is enumerated.
  90. */
  91. } USB_ClassInfo_RNDIS_Device_t;
  92. /* Function Prototypes: */
  93. /** Configures the endpoints of a given RNDIS interface, ready for use. This should be linked to the library
  94. * \ref EVENT_USB_Device_ConfigurationChanged() event so that the endpoints are configured when the configuration
  95. * containing the given RNDIS interface is selected.
  96. *
  97. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing a RNDIS Class configuration and state.
  98. *
  99. * \return Boolean \c true if the endpoints were successfully configured, \c false otherwise.
  100. */
  101. bool RNDIS_Device_ConfigureEndpoints(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
  102. /** Processes incoming control requests from the host, that are directed to the given RNDIS class interface. This should be
  103. * linked to the library \ref EVENT_USB_Device_ControlRequest() event.
  104. *
  105. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing a RNDIS Class configuration and state.
  106. */
  107. void RNDIS_Device_ProcessControlRequest(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
  108. /** General management task for a given RNDIS class interface, required for the correct operation of the interface. This should
  109. * be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
  110. *
  111. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing a RNDIS Class configuration and state.
  112. */
  113. void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
  114. /** Determines if a packet is currently waiting for the device to read in and process.
  115. *
  116. * \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or the
  117. * call will fail.
  118. *
  119. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class configuration and state.
  120. *
  121. * \return Boolean \c true if a packet is waiting to be read in by the host, \c false otherwise.
  122. */
  123. bool RNDIS_Device_IsPacketReceived(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
  124. /** Retrieves the next pending packet from the device, discarding the remainder of the RNDIS packet header to leave
  125. * only the packet contents for processing by the device in the nominated buffer.
  126. *
  127. * \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or the
  128. * call will fail.
  129. *
  130. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class configuration and state.
  131. * \param[out] Buffer Pointer to a buffer where the packer data is to be written to.
  132. * \param[out] PacketLength Pointer to where the length in bytes of the read packet is to be stored.
  133. *
  134. * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
  135. */
  136. uint8_t RNDIS_Device_ReadPacket(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo,
  137. void* Buffer,
  138. uint16_t* const PacketLength) ATTR_NON_NULL_PTR_ARG(1);
  139. /** Sends the given packet to the attached RNDIS device, after adding a RNDIS packet message header.
  140. *
  141. * \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or the
  142. * call will fail.
  143. *
  144. * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class configuration and state.
  145. * \param[in] Buffer Pointer to a buffer where the packer data is to be read from.
  146. * \param[in] PacketLength Length in bytes of the packet to send.
  147. *
  148. * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
  149. */
  150. uint8_t RNDIS_Device_SendPacket(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo,
  151. void* Buffer,
  152. const uint16_t PacketLength) ATTR_NON_NULL_PTR_ARG(1);
  153. /* Private Interface - For use in library only: */
  154. #if !defined(__DOXYGEN__)
  155. /* Macros: */
  156. #define RNDIS_DEVICE_MIN_MESSAGE_BUFFER_LENGTH sizeof(AdapterSupportedOIDList) + sizeof(RNDIS_Query_Complete_t)
  157. /* Function Prototypes: */
  158. #if defined(__INCLUDE_FROM_RNDIS_DEVICE_C)
  159. static void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo)
  160. ATTR_NON_NULL_PTR_ARG(1);
  161. static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo,
  162. const uint32_t OId,
  163. void* const QueryData,
  164. const uint16_t QuerySize,
  165. void* ResponseData,
  166. uint16_t* const ResponseSize) ATTR_NON_NULL_PTR_ARG(1)
  167. ATTR_NON_NULL_PTR_ARG(5) ATTR_NON_NULL_PTR_ARG(6);
  168. static bool RNDIS_Device_ProcessNDISSet(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo,
  169. const uint32_t OId,
  170. const void* SetData,
  171. const uint16_t SetSize) ATTR_NON_NULL_PTR_ARG(1)
  172. ATTR_NON_NULL_PTR_ARG(3);
  173. #endif
  174. #endif
  175. /* Disable C linkage for C++ Compilers: */
  176. #if defined(__cplusplus)
  177. }
  178. #endif
  179. #endif
  180. /** @} */