ReactOS 0.4.17-dev-1037-g720d112
classlib.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS USB Host Controller Extension
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: KMDF class library registration and client binding
5 * COPYRIGHT: Copyright 2026 Justin Miller <justinmiller100@gmail.com>
6 */
7
8#include "ucx01000.h"
9
10#define NDEBUG
11#include <debug.h>
12
14
15extern "C"
16{
18{
19 sizeof(UcxClassLibraryInfo),
21 UcxOnClassLoad,
22 UcxOnClassUnload,
23 UcxOnClientBind,
24 UcxOnClientUnbind
25};
26}
27
28static
33{
34 if (Minor >= 4)
36
37 /* SetIdStrings arrived in 1.3 */
38 if (Minor == 3)
40
42}
43
47UcxOnClassLoad(VOID)
48{
50
51 PAGED_CODE();
52
53 Table[UcxIoDeviceControlTableIndex] = (PFN_UCXFUNC)UcxApiIoDeviceControl;
54 Table[UcxControllerCreateTableIndex] = (PFN_UCXFUNC)UcxApiControllerCreate;
55 Table[UcxControllerNeedsResetTableIndex] = (PFN_UCXFUNC)UcxApiControllerNeedsReset;
56 Table[UcxControllerResetCompleteTableIndex] = (PFN_UCXFUNC)UcxApiControllerResetComplete;
57 Table[UcxControllerSetFailedTableIndex] = (PFN_UCXFUNC)UcxApiControllerSetFailed;
58 Table[UcxRootHubCreateTableIndex] = (PFN_UCXFUNC)UcxApiRootHubCreate;
59 Table[UcxRootHubPortChangedTableIndex] = (PFN_UCXFUNC)UcxApiRootHubPortChanged;
60 Table[UcxUsbDeviceCreateTableIndex] = (PFN_UCXFUNC)UcxApiUsbDeviceCreate;
62 Table[UcxUsbDeviceRemoteWakeNotificationTableIndex] = (PFN_UCXFUNC)UcxApiUsbDeviceRemoteWakeNotification;
63 Table[UcxEndpointCreateTableIndex] = (PFN_UCXFUNC)UcxApiEndpointCreate;
64 Table[UcxEndpointGetStaticStreamsReferencedTableIndex] = (PFN_UCXFUNC)UcxApiEndpointGetStaticStreamsReferenced;
65 Table[UcxEndpointNeedToCancelTransfersTableIndex] = (PFN_UCXFUNC)UcxApiEndpointNeedToCancelTransfers;
69 Table[UcxEndpointPurgeCompleteTableIndex] = (PFN_UCXFUNC)UcxApiEndpointPurgeComplete;
70 Table[UcxEndpointAbortCompleteTableIndex] = (PFN_UCXFUNC)UcxApiEndpointAbortComplete;
71 Table[UcxEndpointNoPingResponseErrorTableIndex] = (PFN_UCXFUNC)UcxApiEndpointNoPingResponseError;
73 Table[UcxStaticStreamsCreateTableIndex] = (PFN_UCXFUNC)UcxApiStaticStreamsCreate;
74 Table[UcxInitializeDeviceInitTableIndex] = (PFN_UCXFUNC)UcxApiInitializeDeviceInit;
75 Table[UcxControllerSetIdStringsTableIndex] = (PFN_UCXFUNC)UcxApiControllerSetIdStrings;
77 (PFN_UCXFUNC)UcxApiControllerNotifyTransportCharacteristicsChange;
78
79 return STATUS_SUCCESS;
80}
81
83VOID
85UcxOnClassUnload(VOID)
86{
87 PAGED_CODE();
88}
89
93UcxOnClientBind(
94 _In_ PWDF_CLASS_BIND_INFO ClassBindInfo,
96{
100
102
103 ClientGlobals = (PUCX_DRIVER_GLOBALS *)ClassBindInfo->ClassBindInfo;
106
107 /* KMDF unbinds even after a failed bind, so clear the slot up front */
109
110 Minor = ClassBindInfo->Version.Minor;
111 if (ClassBindInfo->Version.Major != UCX_CLASS_MAJOR_VERSION || Minor > UCX_CLASS_MINOR_VERSION)
112 {
113 DPRINT1("Client wants UCX %lu.%lu, have %u.%u\n",
114 ClassBindInfo->Version.Major,
115 Minor,
119 }
120
121 if (ClassBindInfo->FunctionTableCount != UcxTableEntriesForMinor(Minor))
122 {
123 DPRINT1("UCX 1.%lu client has %lu table slots\n", Minor, ClassBindInfo->FunctionTableCount);
125 }
126
128 if (Globals == NULL)
130
131 Globals->Size = sizeof(*Globals);
133
134 RtlCopyMemory(ClassBindInfo->FunctionTable,
136 ClassBindInfo->FunctionTableCount * sizeof(UcxExportTable[0]));
137
140}
141
143VOID
144NTAPI
145UcxOnClientUnbind(
146 _In_ PWDF_CLASS_BIND_INFO ClassBindInfo,
148{
150
151 PAGED_CODE();
153
154 ClientGlobals = (PUCX_DRIVER_GLOBALS *)ClassBindInfo->ClassBindInfo;
156 return;
157
160}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
ULONG Minor
Definition: classlib.cpp:99
ClientGlobals
Definition: classlib.cpp:103
PUCX_DRIVER_GLOBALS Globals
Definition: classlib.cpp:98
_Out_ PWDF_COMPONENT_GLOBALS * ComponentGlobals
Definition: classlib.cpp:96
PAGED_CODE()
WDF_CLASS_LIBRARY_INFO UcxClassLibraryInfo
Definition: classlib.cpp:17
return STATUS_SUCCESS
Definition: classlib.cpp:139
static ULONG NTAPI UcxTableEntriesForMinor(_In_ ULONG Minor)
Definition: classlib.cpp:31
static PFN_UCXFUNC UcxExportTable[UcxFunctionTableNumEntries]
Definition: classlib.cpp:13
#define NULL
Definition: types.h:112
#define _IRQL_requires_(irql)
Definition: driverspecs.h:229
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define NonPagedPool
Definition: env_spec_w32.h:307
VOID NTAPI UcxApiDefaultEndpointInitSetEventCallbacks(_In_ PUCX_DRIVER_GLOBALS DriverGlobals, _Inout_ PUCXENDPOINT_INIT EndpointInit, _In_ PUCX_DEFAULT_ENDPOINT_EVENT_CALLBACKS EventCallbacks)
Definition: exports.cpp:299
VOID NTAPI UcxApiUsbDeviceInitSetEventCallbacks(_In_ PUCX_DRIVER_GLOBALS DriverGlobals, _Inout_ PUCXUSBDEVICE_INIT UsbDeviceInit, _In_ PUCX_USBDEVICE_EVENT_CALLBACKS EventCallbacks)
Definition: exports.cpp:207
VOID NTAPI UcxApiStaticStreamsSetStreamInfo(_In_ PUCX_DRIVER_GLOBALS DriverGlobals, _In_ UCXSSTREAMS StaticStreams, _In_ PSTREAM_INFO StreamInfo)
Definition: exports.cpp:363
VOID NTAPI UcxApiEndpointSetWdfIoQueue(_In_ PUCX_DRIVER_GLOBALS DriverGlobals, _In_ UCXENDPOINT Endpoint, _In_ WDFQUEUE WdfQueue)
Definition: exports.cpp:312
VOID NTAPI UcxApiEndpointInitSetEventCallbacks(_In_ PUCX_DRIVER_GLOBALS DriverGlobals, _Inout_ PUCXENDPOINT_INIT EndpointInit, _In_ PUCX_ENDPOINT_EVENT_CALLBACKS EventCallbacks)
Definition: exports.cpp:286
ASMGENDATA Table[]
Definition: genincdata.c:61
if(dx< 0)
Definition: linetemp.h:194
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
static PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
#define STATUS_REVISION_MISMATCH
Definition: ntstatus.h:419
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
#define UCX_CLASS_MAJOR_VERSION
Definition: ucx01000.h:18
#define UCX_CLASS_MINOR_VERSION
Definition: ucx01000.h:19
#define UCX_POOL_TAG
Definition: ucx01000.h:16
@ UcxIoDeviceControlTableIndex
Definition: ucxfuncenum.h:13
@ UcxControllerSetIdStringsTableIndex
Definition: ucxfuncenum.h:35
@ UcxEndpointInitSetEventCallbacksTableIndex
Definition: ucxfuncenum.h:26
@ UcxEndpointPurgeCompleteTableIndex
Definition: ucxfuncenum.h:29
@ UcxStaticStreamsCreateTableIndex
Definition: ucxfuncenum.h:33
@ UcxEndpointGetStaticStreamsReferencedTableIndex
Definition: ucxfuncenum.h:24
@ UcxRootHubPortChangedTableIndex
Definition: ucxfuncenum.h:19
@ UcxEndpointSetWdfIoQueueTableIndex
Definition: ucxfuncenum.h:28
@ UcxUsbDeviceRemoteWakeNotificationTableIndex
Definition: ucxfuncenum.h:22
@ UcxUsbDeviceCreateTableIndex
Definition: ucxfuncenum.h:20
@ UcxControllerCreateTableIndex
Definition: ucxfuncenum.h:14
@ UcxStaticStreamsSetStreamInfoTableIndex
Definition: ucxfuncenum.h:32
@ UcxEndpointNeedToCancelTransfersTableIndex
Definition: ucxfuncenum.h:25
@ UcxEndpointNoPingResponseErrorTableIndex
Definition: ucxfuncenum.h:31
@ UcxControllerResetCompleteTableIndex
Definition: ucxfuncenum.h:16
@ UcxControllerSetFailedTableIndex
Definition: ucxfuncenum.h:17
@ UcxRootHubCreateTableIndex
Definition: ucxfuncenum.h:18
@ UcxDefaultEndpointInitSetEventCallbacksTableIndex
Definition: ucxfuncenum.h:27
@ UcxEndpointCreateTableIndex
Definition: ucxfuncenum.h:23
@ UcxEndpointAbortCompleteTableIndex
Definition: ucxfuncenum.h:30
@ UcxFunctionTableNumEntries
Definition: ucxfuncenum.h:37
@ UcxUsbDeviceInitSetEventCallbacksTableIndex
Definition: ucxfuncenum.h:21
@ UcxControllerNeedsResetTableIndex
Definition: ucxfuncenum.h:15
@ UcxInitializeDeviceInitTableIndex
Definition: ucxfuncenum.h:34
@ UcxControllerNotifyTransportCharacteristicsChangeTableIndex
Definition: ucxfuncenum.h:36
WDF_EXTERN_C_START struct _UCX_DRIVER_GLOBALS * PUCX_DRIVER_GLOBALS
VOID(NTAPI * PFN_UCXFUNC)(VOID)
Definition: ucxglobals.h:21
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _WDF_DRIVER_GLOBALS * PWDF_DRIVER_GLOBALS