diff --git a/reactos/drivers/network/tdi/cte/timer.c b/reactos/drivers/network/tdi/cte/timer.c index 653f3a4cf76..aa82dfe1455 100644 --- a/reactos/drivers/network/tdi/cte/timer.c +++ b/reactos/drivers/network/tdi/cte/timer.c @@ -10,57 +10,109 @@ #include +/* FIXME: Move to a common header! */ +struct _CTE_DELAYED_EVENT; +typedef void (*CTE_WORKER_ROUTINE)(struct _CTE_DELAYED_EVENT *, void *Context); + +typedef struct _CTE_TIMER +{ + BOOLEAN Queued; + KSPIN_LOCK Lock; + CTE_WORKER_ROUTINE Callback; + PVOID Context; + KDPC Dpc; + KTIMER Timer; +} CTE_TIMER, *PCTE_TIMER; + +LONG CteTimeIncrement; + +/* FUNCTIONS *****************************************************************/ + +VOID +NTAPI +InternalDpcRoutine(PKDPC Dpc, + PVOID Context, + PVOID SystemArgument1, + PVOID SystemArgument2) +{ + PCTE_TIMER Timer = (PCTE_TIMER)Context; + + /* Call our registered callback */ + Timer->Callback((struct _CTE_DELAYED_EVENT *)Timer, Timer->Context); +} + /* - * @unimplemented + * @implemented */ VOID NTAPI -CTEInitTimer ( - ULONG Unknown0 - ) +CTEInitTimer(PCTE_TIMER Timer) { + /* Zero all fields */ + RtlZeroMemory(Timer, sizeof(CTE_TIMER)); + + /* Create a DPC and a timer */ + KeInitializeDpc(&Timer->Dpc, InternalDpcRoutine, Timer); + KeInitializeTimer(&Timer->Timer); } - /* - * @unimplemented + * @implemented */ BOOLEAN NTAPI -CTEInitialize ( - VOID - ) +CTEStartTimer(PCTE_TIMER Timer, + ULONG DueTimeShort, + CTE_WORKER_ROUTINE Callback, + PVOID Context) { - /* FIXME: what should it initialize? */ - return TRUE; -} + LARGE_INTEGER DueTime; -/* - * @unimplemented - */ -BOOLEAN -NTAPI -CTEStartTimer ( - ULONG Unknown0, - ULONG Unknown1, - ULONG Unknown2, - ULONG Unknown3 - ) -{ - return FALSE; + /* Make sure a callback was provided */ + ASSERT(Callback); + + /* We need to convert due time, because DueTimeShort is in ms, + but NT timer expects 100s of ns, negative one */ + DueTime.QuadPart = -Int32x32To64(DueTimeShort, 10000); + + /* Set other timer members */ + Timer->Callback = Callback; + Timer->Context = Context; + + /* Set the timer */ + KeSetTimer(&Timer->Timer, DueTime, &Timer->Dpc); + + return TRUE; } /* - * @unimplemented + * @implemented */ ULONG NTAPI -CTESystemUpTime ( - VOID - ) +CTESystemUpTime(VOID) { - return 0; + LARGE_INTEGER Ticks; + + /* Get the tick count */ + KeQueryTickCount(&Ticks); + + /* Convert to 100s of ns and then to ms*/ + Ticks.QuadPart = (Ticks.QuadPart * CteTimeIncrement) / 10000ULL; + + return Ticks.LowPart; +} + +/* + * @implemented + */ +BOOLEAN +NTAPI +CTEInitialize(VOID) +{ + /* Just return success */ + return TRUE; } /* EOF */ diff --git a/reactos/drivers/network/tdi/misc/main.c b/reactos/drivers/network/tdi/misc/main.c index c7882d0e622..d66341c8dd9 100644 --- a/reactos/drivers/network/tdi/misc/main.c +++ b/reactos/drivers/network/tdi/misc/main.c @@ -1,17 +1,20 @@ -/* $Id$ - * +/* * DESCRIPTION: Entry point for TDI.SYS + * (c) Captain Obvious */ #include +extern LONG CteTimeIncrement; + NTSTATUS NTAPI -DriverEntry ( - IN PDRIVER_OBJECT DriverObject, - IN PUNICODE_STRING RegistryPath - ) +DriverEntry(IN PDRIVER_OBJECT DriverObject, + IN PUNICODE_STRING RegistryPath) { - return STATUS_UNSUCCESSFUL; + /* Initialize the time increment for CTE timers */ + CteTimeIncrement = KeQueryTimeIncrement(); + + return STATUS_SUCCESS; }