- Properly implement NdisGetSystemUpTime, based on http://www.tech-archive.net/Archiv...
[reactos.git] / reactos / drivers / network / ndis / ndis / stubs.c
index 3eecb64..448860a 100644 (file)
@@ -10,7 +10,6 @@
 
 #include "ndissys.h"
 
-
 /*
  * @unimplemented
  */
@@ -302,7 +301,10 @@ NdisOpenFile(
   memmove ( FullFileName.Buffer, NDIS_FILE_FOLDER, FullFileName.Length );
   *Status = RtlAppendUnicodeStringToString ( &FullFileName, FileName );
   if ( !NT_SUCCESS(*Status) )
+  {
+    *Status = NDIS_STATUS_FAILURE;
     goto cleanup;
+  }
 
   InitializeObjectAttributes ( &ObjectAttributes,
     &FullFileName,
@@ -322,9 +324,11 @@ NdisOpenFile(
     FILE_SYNCHRONOUS_IO_NONALERT, // ULONG CreateOptions
     0, // PVOID EaBuffer
     0 ); // ULONG EaLength
-
-  //if ( !NT_SUCCESS(*Status) )
-  //  goto cleanup;
+  
+  if ( !NT_SUCCESS(*Status) )
+  {
+    *Status = NDIS_STATUS_FAILURE;
+  }
 
 cleanup:
   if ( FullFileName.Buffer != NULL )
@@ -332,10 +336,12 @@ cleanup:
     ExFreePool ( FullFileName.Buffer );
     FullFileName.Buffer = NULL;
   }
-  if ( !NT_SUCCESS(*Status) && FileHandleObject != NULL )
+  if ( !NT_SUCCESS(*Status) )
   {
-    ExFreePool ( FileHandleObject );
-    FileHandleObject = NULL;
+    if( FileHandleObject ) {
+       ExFreePool ( FileHandleObject );
+       FileHandleObject = NULL;
+    }
     *FileHandle = NULL;
   }
   else
@@ -384,14 +390,14 @@ NdisSetProtocolFilter(
 
 
 /*
- * @unimplemented
+ * @implemented
  */
 CCHAR
 EXPORT
 NdisSystemProcessorCount(
     VOID)
 {
-       return (CCHAR)1;
+       return (CCHAR)KeNumberProcessors;
 }
 
 
@@ -462,7 +468,7 @@ NdisConvertStringToAtmAddress(
 
 
 /*
- * @unimplemented
+ * @implemented
  */
 VOID
 EXPORT
@@ -477,7 +483,7 @@ NdisGetCurrentProcessorCounts(
  *    NDIS 5.0
  */
 {
-    UNIMPLEMENTED
+    ExGetCurrentProcessorCounts( (PULONG) pIdleCount, (PULONG) pKernelAndUser, (PULONG) pIndex); 
 }
 
 
@@ -522,20 +528,23 @@ NdisGetReceivedPacket(
 
 
 /*
- * @unimplemented
+ * @implemented
  */
 VOID
 EXPORT
-NdisGetSystemUptime(
-    OUT PULONG  pSystemUpTime)
-/*
- * FUNCTION:
- * ARGUMENTS:
- * NOTES:
- *    NDIS 5.0
- */
-{
-    UNIMPLEMENTED
+NdisGetSystemUpTime(OUT PULONG pSystemUpTime)
+{           
+    ULONG Increment;
+    LARGE_INTEGER TickCount;
+
+    /* Get the increment and current tick count */
+    Increment = KeQueryTimeIncrement();
+    KeQueryTickCount(&TickCount);
+
+    /* Convert to milliseconds and return */
+    TickCount.QuadPart *= Increment;
+    TickCount.QuadPart /= (10 * 1000);
+    *pSystemUpTime = TickCount.LowPart;
 }
 
 
@@ -1036,4 +1045,23 @@ NdisIMInitializeDeviceInstanceEx(
     return NDIS_STATUS_FAILURE;
 }
 
-/* EOF */
+
+VOID
+NTAPI
+ndisProcWorkItemHandler(PVOID pContext)
+{
+    PNDIS_WORK_ITEM pNdisItem = (PNDIS_WORK_ITEM)pContext;
+    pNdisItem->Routine(pNdisItem, pNdisItem->Context);
+}
+
+EXPORT
+NDIS_STATUS
+NdisScheduleWorkItem(
+    IN PNDIS_WORK_ITEM  pWorkItem)
+{
+    PWORK_QUEUE_ITEM pntWorkItem = (PWORK_QUEUE_ITEM)pWorkItem->WrapperReserved;
+    ExInitializeWorkItem(pntWorkItem, ndisProcWorkItemHandler, pWorkItem);
+    ExQueueWorkItem(pntWorkItem, CriticalWorkQueue);
+    return NDIS_STATUS_SUCCESS;
+}