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