2 * @brief Host mode driver for the library USB RNDIS Class driver
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * Copyright(C) Dean Camera, 2011, 2012
\r
7 * All rights reserved.
\r
10 * Software that is described herein is for illustrative purposes only
\r
11 * which provides customers with programming information regarding the
\r
12 * LPC products. This software is supplied "AS IS" without any warranties of
\r
13 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
14 * all warranties, express or implied, including all implied warranties of
\r
15 * merchantability, fitness for a particular purpose and non-infringement of
\r
16 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
17 * or liability for the use of the software, conveys no license or rights under any
\r
18 * patent, copyright, mask work right, or any other intellectual property rights in
\r
19 * or to any products. NXP Semiconductors reserves the right to make changes
\r
20 * in the software without notification. NXP Semiconductors also makes no
\r
21 * representation or warranty that such application will be suitable for the
\r
22 * specified use without further testing or modification.
\r
25 * Permission to use, copy, modify, and distribute this software and its
\r
26 * documentation is hereby granted, under NXP Semiconductors' and its
\r
27 * licensor's relevant copyrights in the software, without fee, provided that it
\r
28 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
29 * copyright, permission, and disclaimer notice must appear in all copies of
\r
33 /** @ingroup Group_USBClassRNDIS
\r
34 * @defgroup Group_USBClassRNDISHost RNDIS Class Host Mode Driver
\r
36 * @section Sec_Dependencies Module Source Dependencies
\r
37 * The following files must be built with any user project that uses this module:
\r
38 * - LPCUSBlib/Drivers/USB/Class/Host/RNDIS.c <i>(Makefile source module name: LPCUSBlib_SRC_USBCLASS)</i>
\r
40 * @section Sec_ModDescription Module Description
\r
41 * Host Mode USB Class driver framework interface, for the Microsoft RNDIS Ethernet
\r
47 #ifndef __RNDIS_CLASS_HOST_H__
\r
48 #define __RNDIS_CLASS_HOST_H__
\r
51 #include "../../USB.h"
\r
52 #include "../Common/RNDISClassCommon.h"
\r
54 /* Enable C linkage for C++ Compilers: */
\r
55 #if defined(__cplusplus)
\r
59 /* Preprocessor Checks: */
\r
60 #if !defined(__INCLUDE_FROM_RNDIS_DRIVER)
\r
61 #error Do not include this file directly. Include LPCUSBlib/Drivers/USB.h instead.
\r
64 /* Public Interface - May be used in end-application: */
\r
66 /** @brief RNDIS Class Host Mode Configuration and State Structure.
\r
68 * Class state structure. An instance of this structure should be made within the user application,
\r
69 * and passed to each of the RNDIS class driver functions as the \c RNDISInterfaceInfo parameter. This
\r
70 * stores each RNDIS interface's configuration and state information.
\r
76 uint8_t DataINPipeNumber; /**< Pipe number of the RNDIS interface's IN data pipe. */
\r
77 bool DataINPipeDoubleBank; /**< Indicates if the RNDIS interface's IN data pipe should use double banking. */
\r
79 uint8_t DataOUTPipeNumber; /**< Pipe number of the RNDIS interface's OUT data pipe. */
\r
80 bool DataOUTPipeDoubleBank; /**< Indicates if the RNDIS interface's OUT data pipe should use double banking. */
\r
82 uint8_t NotificationPipeNumber; /**< Pipe number of the RNDIS interface's IN notification endpoint, if used. */
\r
83 bool NotificationPipeDoubleBank; /**< Indicates if the RNDIS interface's notification pipe should use double banking. */
\r
85 uint32_t HostMaxPacketSize; /**< Maximum size of a packet which can be buffered by the host. */
\r
86 uint8_t PortNumber; /**< Port number that this interface is running.
\r
88 } Config; /**< Config data for the USB class interface within the device. All elements in this section
\r
89 * <b>must</b> be set or the interface will fail to enumerate and operate correctly.
\r
93 bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid
\r
94 * after @ref RNDIS_Host_ConfigurePipes() is called and the Host state machine is in the
\r
97 uint8_t ControlInterfaceNumber; /**< Interface index of the RNDIS control interface within the attached device. */
\r
99 uint16_t DataINPipeSize; /**< Size in bytes of the RNDIS interface's IN data pipe. */
\r
100 uint16_t DataOUTPipeSize; /**< Size in bytes of the RNDIS interface's OUT data pipe. */
\r
101 uint16_t NotificationPipeSize; /**< Size in bytes of the RNDIS interface's IN notification pipe, if used. */
\r
103 uint32_t DeviceMaxPacketSize; /**< Maximum size of a packet which can be buffered by the attached RNDIS device. */
\r
105 uint32_t RequestID; /**< Request ID counter to give a unique ID for each command/response pair. */
\r
106 } State; /**< State data for the USB class interface within the device. All elements in this section
\r
107 * <b>may</b> be set to initial values, but may also be ignored to default to sane values when
\r
108 * the interface is enumerated.
\r
110 } USB_ClassInfo_RNDIS_Host_t;
\r
113 /** Enum for the possible error codes returned by the @ref RNDIS_Host_ConfigurePipes() function. */
\r
114 enum RNDIS_Host_EnumerationFailure_ErrorCodes_t
\r
116 RNDIS_ENUMERROR_NoError = 0, /**< Configuration Descriptor was processed successfully. */
\r
117 RNDIS_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor. */
\r
118 RNDIS_ENUMERROR_NoCompatibleInterfaceFound = 2, /**< A compatible RNDIS interface was not found in the device's Configuration Descriptor. */
\r
119 RNDIS_ENUMERROR_PipeConfigurationFailed = 3, /**< One or more pipes for the specified interface could not be configured correctly. */
\r
122 /* Function Prototypes: */
\r
123 /** @brief Host interface configuration routine, to configure a given RNDIS host interface instance using the Configuration
\r
124 * Descriptor read from an attached USB device. This function automatically updates the given RNDIS Host instance's
\r
125 * state values and configures the pipes required to communicate with the interface if it is found within the device.
\r
126 * This should be called once after the stack has enumerated the attached device, while the host state machine is in
\r
127 * the Addressed state.
\r
129 * @param RNDISInterfaceInfo : Pointer to a structure containing an RNDIS Class host configuration and state.
\r
130 * @param ConfigDescriptorSize : Length of the attached device's Configuration Descriptor.
\r
131 * @param DeviceConfigDescriptor : Pointer to a buffer containing the attached device's Configuration Descriptor.
\r
133 * @return A value from the @ref RNDIS_Host_EnumerationFailure_ErrorCodes_t enum.
\r
135 uint8_t RNDIS_Host_ConfigurePipes(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
\r
136 uint16_t ConfigDescriptorSize,
\r
137 void* DeviceConfigDescriptor) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);
\r
139 /** @brief Sends a RNDIS KEEPALIVE command to the device, to ensure that it does not enter standby mode after periods
\r
140 * of long inactivity.
\r
142 * @param RNDISInterfaceInfo : Pointer to a structure containing an RNDIS Class host configuration and state.
\r
144 * @return A value from the @ref USB_Host_SendControlErrorCodes_t enum or @ref RNDIS_ERROR_LOGICAL_CMD_FAILED if the device returned a
\r
145 * logical command failure.
\r
147 uint8_t RNDIS_Host_SendKeepAlive(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
\r
149 /** @brief Initializes the attached RNDIS device's RNDIS interface. This should be called after the device's pipes have been
\r
150 * configured via the call to @ref RNDIS_Host_ConfigurePipes().
\r
152 * @param RNDISInterfaceInfo : Pointer to a structure containing an RNDIS Class host configuration and state.
\r
154 * @return A value from the @ref USB_Host_SendControlErrorCodes_t enum or @ref RNDIS_ERROR_LOGICAL_CMD_FAILED if the
\r
155 * device returned a logical command failure.
\r
157 uint8_t RNDIS_Host_InitializeDevice(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
\r
159 /** @brief Sets a given RNDIS property of an attached RNDIS device.
\r
161 * @param RNDISInterfaceInfo : Pointer to a structure containing an RNDIS Class host configuration and state.
\r
162 * @param Oid : OID number of the parameter to set.
\r
163 * @param Buffer : Pointer to where the property data is to be sourced from.
\r
164 * @param Length : Length in bytes of the property data to sent to the device.
\r
166 * @return A value from the @ref USB_Host_SendControlErrorCodes_t enum or @ref RNDIS_ERROR_LOGICAL_CMD_FAILED if the
\r
167 * device returned a logical command failure.
\r
169 uint8_t RNDIS_Host_SetRNDISProperty(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
\r
170 const uint32_t Oid,
\r
172 const uint16_t Length) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);
\r
174 /** @brief Gets a given RNDIS property of an attached RNDIS device.
\r
176 * @param RNDISInterfaceInfo : Pointer to a structure containing an RNDIS Class host configuration and state.
\r
177 * @param Oid : OID number of the parameter to get.
\r
178 * @param Buffer : Pointer to where the property data is to be written to.
\r
179 * @param MaxLength : Length in bytes of the destination buffer size.
\r
181 * @return A value from the @ref USB_Host_SendControlErrorCodes_t enum or @ref RNDIS_ERROR_LOGICAL_CMD_FAILED if the
\r
182 * device returned a logical command failure.
\r
184 uint8_t RNDIS_Host_QueryRNDISProperty(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
\r
185 const uint32_t Oid,
\r
187 const uint16_t MaxLength) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);
\r
189 /** @brief Determines if a packet is currently waiting for the host to read in and process.
\r
191 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
194 * @param RNDISInterfaceInfo : Pointer to a structure containing an RNDIS Class host configuration and state.
\r
196 * @return Boolean \c true if a packet is waiting to be read in by the host, \c false otherwise.
\r
198 bool RNDIS_Host_IsPacketReceived(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
\r
200 /** @brief Retrieves the next pending packet from the device, discarding the remainder of the RNDIS packet header to leave
\r
201 * only the packet contents for processing by the host in the nominated buffer.
\r
203 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
206 * @param RNDISInterfaceInfo : Pointer to a structure containing an RNDIS Class host configuration and state.
\r
207 * @param Buffer : Pointer to a buffer where the packer data is to be written to.
\r
208 * @param PacketLength : Pointer to where the length in bytes of the read packet is to be stored.
\r
210 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum.
\r
212 uint8_t RNDIS_Host_ReadPacket(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
\r
214 uint16_t* const PacketLength) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2)
\r
215 ATTR_NON_NULL_PTR_ARG(3);
\r
217 /** @brief Sends the given packet to the attached RNDIS device, after adding a RNDIS packet message header.
\r
219 * @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the
\r
222 * @param RNDISInterfaceInfo : Pointer to a structure containing an RNDIS Class host configuration and state.
\r
223 * @param Buffer : Pointer to a buffer where the packer data is to be read from.
\r
224 * @param PacketLength : Length in bytes of the packet to send.
\r
226 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum.
\r
228 uint8_t RNDIS_Host_SendPacket(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
\r
230 const uint16_t PacketLength) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
\r
232 /* Inline Functions: */
\r
233 /** @brief General management task for a given RNDIS host class interface, required for the correct operation of the interface. This should
\r
234 * be called frequently in the main program loop, before the master USB management task @ref USB_USBTask().
\r
236 * @param RNDISInterfaceInfo : Pointer to a structure containing an RNDIS Class host configuration and state.
\r
239 static inline void RNDIS_Host_USBTask(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
\r
240 static inline void RNDIS_Host_USBTask(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo)
\r
242 (void)RNDISInterfaceInfo;
\r
245 /* Private Interface - For use in library only: */
\r
246 #if !defined(__DOXYGEN__)
\r
247 /* Function Prototypes: */
\r
248 #if defined(__INCLUDE_FROM_RNDIS_HOST_C)
\r
249 static uint8_t RNDIS_SendEncapsulatedCommand(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
\r
251 const uint16_t Length) ATTR_NON_NULL_PTR_ARG(1)
\r
252 ATTR_NON_NULL_PTR_ARG(2);
\r
253 static uint8_t RNDIS_GetEncapsulatedResponse(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo,
\r
255 const uint16_t Length) ATTR_NON_NULL_PTR_ARG(1)
\r
256 ATTR_NON_NULL_PTR_ARG(2);
\r
258 static uint8_t DCOMP_RNDIS_Host_NextRNDISControlInterface(void* const CurrentDescriptor)
\r
259 ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
\r
260 static uint8_t DCOMP_RNDIS_Host_NextRNDISDataInterface(void* const CurrentDescriptor)
\r
261 ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
\r
262 static uint8_t DCOMP_RNDIS_Host_NextRNDISInterfaceEndpoint(void* const CurrentDescriptor)
\r
263 ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
\r
267 /* Disable C linkage for C++ Compilers: */
\r
268 #if defined(__cplusplus)
\r