2 * @brief Device 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_USBClassRNDISDevice RNDIS Class Device 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 * - nxpUSBlib/Drivers/USB/Class/Device/RNDIS.c <i>(Makefile source module name: NXPUSBLIB_SRC_USBCLASS)</i>
\r
40 * @section Sec_ModDescription Module Description
\r
41 * Device Mode USB Class driver framework interface, for the RNDIS USB Class driver.
\r
46 #ifndef _RNDIS_CLASS_DEVICE_H_
\r
47 #define _RNDIS_CLASS_DEVICE_H_
\r
50 #include "../../USB.h"
\r
51 #include "../Common/RNDISClassCommon.h"
\r
53 /* Enable C linkage for C++ Compilers: */
\r
54 #if defined(__cplusplus)
\r
58 /* Preprocessor Checks: */
\r
59 #if !defined(__INCLUDE_FROM_RNDIS_DRIVER)
\r
60 #error Do not include this file directly. Include LPCUSBlib/Drivers/USB.h instead.
\r
63 /* Public Interface - May be used in end-application: */
\r
66 * @brief RNDIS Class Device Mode Configuration and State Structure.
\r
68 * Class state structure. An instance of this structure should be made for each RNDIS interface
\r
69 * within the user application, and passed to each of the RNDIS class driver functions as the
\r
70 * \c RNDISInterfaceInfo parameter. This stores each RNDIS interface's configuration and state information.
\r
74 uint8_t ControlInterfaceNumber; /**< Interface number of the RNDIS control interface within the device. */
\r
76 uint8_t DataINEndpointNumber; /**< Endpoint number of the RNDIS interface's IN data endpoint. */
\r
77 uint16_t DataINEndpointSize; /**< Size in bytes of the RNDIS interface's IN data endpoint. */
\r
78 bool DataINEndpointDoubleBank; /**< Indicates if the RNDIS interface's IN data endpoint should use double banking. */
\r
80 uint8_t DataOUTEndpointNumber; /**< Endpoint number of the RNDIS interface's OUT data endpoint. */
\r
81 uint16_t DataOUTEndpointSize; /**< Size in bytes of the RNDIS interface's OUT data endpoint. */
\r
82 bool DataOUTEndpointDoubleBank; /**< Indicates if the RNDIS interface's OUT data endpoint should use double banking. */
\r
84 uint8_t NotificationEndpointNumber; /**< Endpoint number of the RNDIS interface's IN notification endpoint, if used. */
\r
85 uint16_t NotificationEndpointSize; /**< Size in bytes of the RNDIS interface's IN notification endpoint, if used. */
\r
86 bool NotificationEndpointDoubleBank; /**< Indicates if the RNDIS interface's notification endpoint should use double banking. */
\r
88 char *AdapterVendorDescription; /**< String description of the adapter vendor. */
\r
89 MAC_Address_t AdapterMACAddress; /**< MAC address of the adapter. */
\r
90 uint8_t PortNumber; /**< Port number that this interface is running.*/
\r
91 } Config; /**< Config data for the USB class interface within the device. All elements in this section
\r
92 * <b>must</b> be set or the interface will fail to enumerate and operate correctly.
\r
96 uint8_t RNDISMessageBuffer[RNDIS_MESSAGE_BUFFER_SIZE]; /**< Buffer to hold RNDIS messages to and from the host,
\r
97 * managed by the class driver.
\r
99 bool ResponseReady; /**< Internal flag indicating if a RNDIS message is waiting to be returned to the host. */
\r
100 uint8_t CurrRNDISState; /**< Current RNDIS state of the adapter, a value from the @ref RNDIS_States_t enum. */
\r
101 uint32_t CurrPacketFilter; /**< Current packet filter mode, used internally by the class driver. */
\r
102 } State; /**< State data for the USB class interface within the device. All elements in this section
\r
103 * are reset to their defaults when the interface is enumerated.
\r
106 } USB_ClassInfo_RNDIS_Device_t;
\r
108 /* Function Prototypes: */
\r
110 * @brief Configures the endpoints of a given RNDIS interface, ready for use. This should be linked to the library
\r
111 * @ref EVENT_USB_Device_ConfigurationChanged() event so that the endpoints are configured when the configuration
\r
112 * containing the given RNDIS interface is selected.
\r
114 * @param RNDISInterfaceInfo : Pointer to a structure containing a RNDIS Class configuration and state.
\r
116 * @return Boolean \c true if the endpoints were successfully configured, \c false otherwise.
\r
118 bool RNDIS_Device_ConfigureEndpoints(USB_ClassInfo_RNDIS_Device_t *const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
\r
121 * @brief Processes incoming control requests from the host, that are directed to the given RNDIS class interface. This should be
\r
122 * linked to the library @ref EVENT_USB_Device_ControlRequest() event.
\r
124 * @param RNDISInterfaceInfo : Pointer to a structure containing a RNDIS Class configuration and state.
\r
127 void RNDIS_Device_ProcessControlRequest(USB_ClassInfo_RNDIS_Device_t *const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
\r
130 * @brief General management task for a given RNDIS class interface, required for the correct operation of the interface. This should
\r
131 * be called frequently in the main program loop, before the master USB management task @ref USB_USBTask().
\r
133 * @param RNDISInterfaceInfo : Pointer to a structure containing a RNDIS Class configuration and state.
\r
136 void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_Device_t *const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
\r
139 * @brief Determines if a packet is currently waiting for the device to read in and process.
\r
141 * @pre This function must only be called when the Device state machine is in the @ref DEVICE_STATE_Configured state or the
\r
144 * @param RNDISInterfaceInfo : Pointer to a structure containing an RNDIS Class configuration and state.
\r
146 * @return Boolean \c true if a packet is waiting to be read in by the host, \c false otherwise.
\r
148 bool RNDIS_Device_IsPacketReceived(USB_ClassInfo_RNDIS_Device_t *const RNDISInterfaceInfo);
\r
151 * @brief Retrieves the next pending packet from the device, discarding the remainder of the RNDIS packet header to leave
\r
152 * only the packet contents for processing by the device in the nominated buffer.
\r
154 * @pre This function must only be called when the Device state machine is in the @ref DEVICE_STATE_Configured state or the
\r
157 * @param RNDISInterfaceInfo : Pointer to a structure containing an RNDIS Class configuration and state.
\r
158 * @param Buffer : Pointer to a buffer where the packer data is to be written to.
\r
159 * @param PacketLength : Pointer to where the length in bytes of the read packet is to be stored.
\r
161 * @return A value from the @ref Endpoint_Stream_RW_ErrorCodes_t enum.
\r
163 uint8_t RNDIS_Device_ReadPacket(USB_ClassInfo_RNDIS_Device_t *const RNDISInterfaceInfo,
\r
165 uint16_t *const PacketLength);
\r
168 * @brief Sends the given packet to the attached RNDIS device, after adding a RNDIS packet message header.
\r
170 * @pre This function must only be called when the Device state machine is in the @ref DEVICE_STATE_Configured state or the
\r
173 * @param RNDISInterfaceInfo : Pointer to a structure containing an RNDIS Class configuration and state.
\r
174 * @param Buffer : Pointer to a buffer where the packer data is to be read from.
\r
175 * @param PacketLength : Length in bytes of the packet to send.
\r
177 * @return A value from the @ref Endpoint_Stream_RW_ErrorCodes_t enum.
\r
179 uint8_t RNDIS_Device_SendPacket(USB_ClassInfo_RNDIS_Device_t *const RNDISInterfaceInfo,
\r
181 const uint16_t PacketLength);
\r
183 /* Private Interface - For use in library only: */
\r
184 #if !defined(__DOXYGEN__)
\r
185 /* Function Prototypes: */
\r
186 #if defined(__INCLUDE_FROM_RNDIS_DEVICE_C)
\r
187 static void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_Device_t *const RNDISInterfaceInfo)
\r
188 ATTR_NON_NULL_PTR_ARG(1);
\r
190 static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_Device_t *const RNDISInterfaceInfo,
\r
191 const uint32_t OId,
\r
192 void *const QueryData,
\r
193 const uint16_t QuerySize,
\r
194 void *ResponseData,
\r
195 uint16_t *const ResponseSize) ATTR_NON_NULL_PTR_ARG(1)
\r
196 ATTR_NON_NULL_PTR_ARG(5) ATTR_NON_NULL_PTR_ARG(6);
\r
198 static bool RNDIS_Device_ProcessNDISSet(USB_ClassInfo_RNDIS_Device_t *const RNDISInterfaceInfo,
\r
199 const uint32_t OId,
\r
200 const void *SetData,
\r
201 const uint16_t SetSize) ATTR_NON_NULL_PTR_ARG(1)
\r
202 ATTR_NON_NULL_PTR_ARG(3);
\r
208 /* Disable C linkage for C++ Compilers: */
\r
209 #if defined(__cplusplus)
\r