1 // 2 // Copyright (C) Microsoft. All rights reserved. 3 // 4 #ifndef _FXUSBINTERFACE_H_ 5 #define _FXUSBINTERFACE_H_ 6 7 extern "C" { 8 #include <usbdrivr.h> 9 #include <wdfusb.h> 10 } 11 12 #include "fxusbrequestcontext.hpp" 13 14 #define FX_USB_INTERFACE_TAG 'uItG' //using a random uniqure value 15 16 17 18 struct FxUsbInterfaceSetting{ 19 PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor; 20 #if (FX_CORE_MODE == FX_CORE_USER_MODE) 21 22 23 24 25 26 27 28 USB_INTERFACE_DESCRIPTOR InterfaceDescriptorAlloc; 29 #endif 30 }; 31 32 class FxUsbInterface : public FxNonPagedObject { //any base class 33 public: 34 friend FxUsbDevice; 35 friend FxUsbPipe; 36 //friend FxUsbTarget; 37 38 FxUsbInterface( 39 _In_ PFX_DRIVER_GLOBALS FxDriverGlobals, 40 _In_ FxUsbDevice* UsbDevice, 41 _In_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor 42 ); 43 44 VOID 45 SetInfo( 46 __in PUSBD_INTERFACE_INFORMATION Interface 47 ); 48 49 VOID 50 CleanUpAndDelete( 51 __in BOOLEAN ClearDestroyCallback 52 ); 53 54 _Must_inspect_result_ 55 NTSTATUS 56 SelectSetting( 57 __in PWDF_OBJECT_ATTRIBUTES PipesAttributes, 58 __in PURB Urb 59 ); 60 61 UCHAR 62 GetNumConfiguredPipes( 63 VOID 64 ) 65 { 66 return m_NumberOfConfiguredPipes; 67 } 68 69 UCHAR 70 GetInterfaceNumber( 71 VOID 72 ) 73 { 74 return m_InterfaceNumber; 75 } 76 77 UCHAR 78 GetNumSettings( 79 VOID 80 ) 81 { 82 return m_NumSettings; 83 } 84 85 UCHAR 86 GetNumEndpoints( 87 __in UCHAR SettingIndex 88 ); 89 90 VOID 91 GetEndpointInformation( 92 __in UCHAR SettingIndex, 93 __in UCHAR PipeIndex, 94 __in PWDF_USB_PIPE_INFORMATION PipeInfo 95 ); 96 97 VOID 98 GetDescriptor( 99 __in PUSB_INTERFACE_DESCRIPTOR UsbInterfaceDescriptor, 100 __in UCHAR SettingIndex 101 ); 102 103 //post config 104 105 UCHAR 106 GetConfiguredSettingIndex( 107 VOID 108 ) ; 109 110 WDFUSBPIPE 111 GetConfiguredPipe( 112 __in UCHAR PipeIndex, 113 __out_opt PWDF_USB_PIPE_INFORMATION PipeInfo 114 ); 115 116 _Must_inspect_result_ 117 NTSTATUS 118 CreateSettings( 119 VOID 120 ); 121 122 VOID 123 SetNumConfiguredPipes( 124 __in UCHAR NumberOfPipes 125 ) 126 { 127 m_NumberOfConfiguredPipes = NumberOfPipes; 128 } 129 130 VOID 131 SetConfiguredPipes( 132 __in FxUsbPipe **ppPipes 133 ) 134 { 135 m_ConfiguredPipes = ppPipes; 136 } 137 138 BOOLEAN 139 IsInterfaceConfigured( 140 VOID 141 ) 142 { 143 return m_ConfiguredPipes != NULL ? TRUE : FALSE; 144 } 145 146 _Must_inspect_result_ 147 NTSTATUS 148 SelectSettingByDescriptor( 149 __in PWDF_OBJECT_ATTRIBUTES PipesAttributes, 150 __in PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor 151 ); 152 153 _Must_inspect_result_ 154 NTSTATUS 155 SelectSettingByIndex( 156 __in PWDF_OBJECT_ATTRIBUTES PipesAttributes, 157 __in UCHAR SettingIndex 158 ); 159 160 VOID 161 CopyEndpointFieldsFromDescriptor( 162 __in PWDF_USB_PIPE_INFORMATION PipeInfo, 163 __in PUSB_ENDPOINT_DESCRIPTOR EndpointDesc, 164 __in UCHAR SettingIndex 165 ); 166 167 ULONG 168 DetermineDefaultMaxTransferSize( 169 VOID 170 ); 171 172 WDFUSBINTERFACE 173 GetHandle(VOID) 174 { 175 return (WDFUSBINTERFACE) GetObjectHandle(); 176 } 177 178 PUSB_INTERFACE_DESCRIPTOR 179 GetSettingDescriptor( 180 __in UCHAR Setting 181 ); 182 183 NTSTATUS 184 CheckAndSelectSettingByIndex( 185 __in UCHAR SettingIndex 186 ); 187 188 NTSTATUS 189 UpdatePipeAttributes( 190 __in PWDF_OBJECT_ATTRIBUTES PipesAttributes 191 ); 192 193 protected: 194 ~FxUsbInterface( 195 VOID 196 ); 197 198 VOID 199 RemoveDeletedPipe( 200 __in FxUsbPipe* Pipe 201 ); 202 203 VOID 204 FormatSelectSettingUrb( 205 __in_bcount(GET_SELECT_INTERFACE_REQUEST_SIZE(NumEndpoints)) PURB Urb, 206 __in USHORT NumEndpoints, 207 __in UCHAR SettingNumber 208 ); 209 210 #if (FX_CORE_MODE == FX_CORE_USER_MODE) 211 public: 212 NTSTATUS 213 SetWinUsbHandle( 214 _In_ UCHAR FrameworkInterfaceIndex 215 ); 216 217 NTSTATUS 218 MakeAndConfigurePipes( 219 __in PWDF_OBJECT_ATTRIBUTES PipesAttributes, 220 __in UCHAR NumPipes 221 ); 222 #endif 223 224 protected: 225 // 226 // Backpointer to the owning device 227 // 228 FxUsbDevice* m_UsbDevice; 229 230 // 231 // Array of pipe pointers 232 // 233 FxUsbPipe** m_ConfiguredPipes; 234 235 // 236 // Array of alternative settings for the interface 237 // 238 __field_ecount(m_NumSettings) FxUsbInterfaceSetting* m_Settings; 239 240 // 241 // Number of elements in m_Settings 242 // 243 UCHAR m_NumSettings; 244 245 // 246 // Number of elements in m_ConfiguredPipes 247 // 248 UCHAR m_NumberOfConfiguredPipes; 249 250 // 251 // Information out of the interface descriptor 252 // 253 UCHAR m_InterfaceNumber; 254 UCHAR m_CurAlternateSetting; 255 UCHAR m_Class; 256 UCHAR m_SubClass; 257 UCHAR m_Protocol; 258 259 #if (FX_CORE_MODE == FX_CORE_USER_MODE) 260 private: 261 // 262 // Handle to USB interface exposed by WinUsb 263 // 264 WINUSB_INTERFACE_HANDLE m_WinUsbHandle; 265 #endif 266 }; 267 268 269 #endif // _FXUSBINTERFACE_H_ 270 271