SDP driver base code (only open a deice and let the user mode connect to it) (Rev 61)
authortzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 21 Nov 2005 10:30:39 +0000 (10:30 +0000)
committertzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 21 Nov 2005 10:30:39 +0000 (10:30 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@156 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/sdp/include/SdpLib.h [new file with mode: 0644]
ulp/sdp/kernel/SOURCES [new file with mode: 0644]
ulp/sdp/kernel/SdpDriver.cpp [new file with mode: 0644]
ulp/sdp/kernel/SdpDriver.h [new file with mode: 0644]
ulp/sdp/kernel/SdpTrace.h [new file with mode: 0644]
ulp/sdp/kernel/makefile [new file with mode: 0644]

diff --git a/ulp/sdp/include/SdpLib.h b/ulp/sdp/include/SdpLib.h
new file mode 100644 (file)
index 0000000..59378d3
--- /dev/null
@@ -0,0 +1,7 @@
+/* Copyright mellanox 2005 */\r
+\r
+\r
+\r
+#define SDP_DEVICE_NAME        L"\\Device\\SdpDriver"\r
+#define SDP_LINK_NAME L"\\DosDevices\\Global\\SdpDriver"\r
+\r
diff --git a/ulp/sdp/kernel/SOURCES b/ulp/sdp/kernel/SOURCES
new file mode 100644 (file)
index 0000000..4f8ce75
--- /dev/null
@@ -0,0 +1,23 @@
+TARGETNAME=Sdp\r
+TARGETPATH=..\..\..\bin\kernel\obj$(BUILD_ALT_DIR)\r
+TARGETTYPE=DRIVER\r
+\r
+SOURCES= SdpDriver.cpp \\r
+\r
+INCLUDES=..\include;..\..\..\inc;..\..\..\inc\kernel;\r
+\r
+C_DEFINES=$(C_DEFINES) -DNDIS_WDM=1  \\r
+       -DDEPRECATE_DDK_FUNCTIONS \r
+\r
+TARGETLIBS= \\r
+       $(TARGETPATH)\*\complib.lib \\r
+\r
+!if !defined(DDK_TARGET_OS) || "$(DDK_TARGET_OS)"=="Win2K"\r
+#\r
+# The driver is built in the Win2K build environment\r
+# - use the library version of safe strings \r
+#\r
+TARGETLIBS= $(TARGETLIBS) $(DDK_LIB_PATH)\ntstrsafe.lib\r
+!endif\r
+\r
+MSC_WARNING_LEVEL= /W3\r
diff --git a/ulp/sdp/kernel/SdpDriver.cpp b/ulp/sdp/kernel/SdpDriver.cpp
new file mode 100644 (file)
index 0000000..2c4bf6e
--- /dev/null
@@ -0,0 +1,164 @@
+/* Copyright mellanox */\r
+\r
+extern "C" {\r
+#include <NTDDK.h>\r
+}\r
+#include "sdpdriver.h"\r
+#include "SdpLib.h"\r
+#include "SdpTrace.h"\r
+\r
+NTSTATUS CreateDevice (IN PDRIVER_OBJECT       pDriverObject);\r
+\r
+VOID DriverUnload (\r
+        IN PDRIVER_OBJECT      pDriverObject   \r
+        ) \r
+{\r
+    SDP_PRINT(SDP_TRACE, SDP_DRIVER, ("DriverUnload called pDriverObject = 0x%x\n", pDriverObject ));\r
+\r
+    SdpDriver *pSdpDriver;\r
+    UNICODE_STRING LinkName;\r
+\r
+    pSdpDriver = (SdpDriver *) pDriverObject->DeviceObject->DeviceExtension;\r
+\r
+\r
+    RtlInitUnicodeString( &LinkName, SDP_LINK_NAME );\r
+    IoDeleteSymbolicLink(&LinkName);\r
+\r
+    IoDeleteDevice( pSdpDriver->GetDeviceObject());\r
+}\r
+\r
+\r
+\r
+extern "C" NTSTATUS DriverEntry (\r
+    IN PDRIVER_OBJECT pDriverObject,\r
+    IN PUNICODE_STRING pRegistryPath   )\r
+{\r
+    NTSTATUS rc;\r
+    PDEVICE_OBJECT pDevObj;\r
+    SdpDriver *pSdpDriver;\r
+    bool DeviceCreated = false;\r
+    UNICODE_STRING  DevName, LinkName;\r
+    int i;\r
+\r
+    SDP_PRINT(SDP_TRACE, SDP_DRIVER, ("DriverEntry called\n" ));\r
+\r
+    // fill the device functions\r
+    pDriverObject->DriverUnload = DriverUnload;\r
+    pDriverObject->FastIoDispatch = NULL;\r
+    pDriverObject->DriverStartIo = NULL;\r
+    for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++) {\r
+        pDriverObject->MajorFunction[i] = SdpDriver::Dispatch;\r
+    }\r
+\r
+\r
+\r
+    // Create the device that will be used for comunication with the user mode\r
+    // Now create the device\r
+\r
+    RtlInitUnicodeString( &DevName, SDP_DEVICE_NAME );\r
+    RtlInitUnicodeString( &LinkName, SDP_LINK_NAME );\r
+\r
+    \r
+    // BUGBUG: Should we crearte a secure device object \r
+    rc = IoCreateDevice( pDriverObject,\r
+                            sizeof(SdpDriver),\r
+                            &DevName,\r
+                            FILE_DEVICE_UNKNOWN,\r
+                            0, \r
+                            TRUE,\r
+                            &pDevObj );\r
+    if (!NT_SUCCESS(rc)) {\r
+        SDP_PRINT(SDP_ERR, SDP_DRIVER, ("IoCreateDevice failed rc = 0x%x\n", rc ));        \r
+        goto Cleanup;\r
+    }\r
+    DeviceCreated =  true;\r
+\r
+    pSdpDriver = (SdpDriver *) pDevObj->DeviceExtension;\r
+    rc = pSdpDriver->Init(pDevObj);\r
+\r
+    if (!NT_SUCCESS(rc)) {\r
+        SDP_PRINT(SDP_ERR, SDP_DRIVER, ("pSdpDriver->Init failed rc = 0x%x\n", rc ));\r
+        goto Cleanup;\r
+    }\r
+\r
+\r
+    // Create a Win32-accessible device object\r
+    rc = IoCreateSymbolicLink(\r
+            &LinkName,\r
+            &DevName            \r
+            );\r
+\r
+    if (!NT_SUCCESS(rc)) {\r
+        SDP_PRINT(SDP_ERR, SDP_DRIVER, ("IoCreateSymbolicLink failed rc = 0x%x\n", rc ));\r
+        goto Cleanup;\r
+    }\r
+\r
+Cleanup:\r
+    if (!NT_SUCCESS(rc)) {\r
+        if ( DeviceCreated ) {\r
+            IoDeleteDevice(pDevObj);\r
+        }\r
+    }\r
+    return rc;\r
+\r
+}\r
+\r
+\r
+NTSTATUS SdpDriver::Dispatch(\r
+    IN PDEVICE_OBJECT pDeviceObject,\r
+    IN PIRP pIrp\r
+    )\r
+{\r
+    NTSTATUS rc = STATUS_SUCCESS;\r
+    PIO_STACK_LOCATION pIrpSp;\r
+    pIrp->IoStatus.Status = STATUS_SUCCESS;\r
+    pIrp->IoStatus.Information = 0;\r
+\r
+\r
+    pIrpSp = IoGetCurrentIrpStackLocation(pIrp);\r
+\r
+    switch (pIrpSp->MajorFunction) {\r
+\r
+        case IRP_MJ_CREATE: {\r
+                SDP_PRINT(SDP_TRACE, SDP_DRIVER, ("IRP_MJ_CREATE pIrpSp->FileObject = 0x%x\n", \r
+                    pIrpSp->FileObject ));\r
+\r
+            break;\r
+        }\r
+        case IRP_MJ_CLEANUP: {\r
+            // All IRPs that were associated with this device should be cleaned\r
+                SDP_PRINT(SDP_TRACE, SDP_DRIVER, ("IRP_MJ_CLEANUP pIrpSp->FileObject = 0x%x\n", \r
+                    pIrpSp->FileObject ));\r
+            break;\r
+\r
+        }\r
+\r
+        case IRP_MJ_CLOSE: { \r
+            // Receipt of this request indicates that the last handle of the file object \r
+            // that is associated with the target device object has been closed and \r
+            //released. All outstanding I/O requests have been completed or canceled.\r
+                SDP_PRINT(SDP_TRACE, SDP_DRIVER, ("IRP_MJ_CLOSE pIrpSp->FileObject = 0x%x\n", \r
+                    pIrpSp->FileObject ));\r
+\r
+            break;\r
+        }\r
+        case IRP_MJ_DEVICE_CONTROL: {\r
+                SDP_PRINT(SDP_TRACE, SDP_DRIVER, ("IRP_MJ_DEVICE_CONTROL pIrpSp->FileObject = 0x%x\n", \r
+                    pIrpSp->FileObject ));\r
+\r
+            // IOCTLs are allowed only for user mode processes\r
+            if (UserMode != pIrp->RequestorMode) {\r
+                rc = STATUS_ACCESS_DENIED;\r
+                break;\r
+            }\r
+\r
+            // Handle the mode of the request and get it's params\r
+\r
+\r
+            // Handle the request itslef\r
+        }            \r
+    }\r
+\r
+    return rc;\r
+}\r
+\r
diff --git a/ulp/sdp/kernel/SdpDriver.h b/ulp/sdp/kernel/SdpDriver.h
new file mode 100644 (file)
index 0000000..b0805ca
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright mellanox 2005 */\r
+\r
+#ifndef H_SDP_DRIVER_H\r
+#define H_SDP_DRIVER_H \r
+\r
+\r
+class SdpDriver {\r
+public:\r
+       NTSTATUS Init(PDEVICE_OBJECT pDevObj) {\r
+               m_pDevObj = pDevObj;\r
+               return STATUS_SUCCESS;\r
+       }\r
+       PDEVICE_OBJECT GetDeviceObject() {\r
+               return m_pDevObj;\r
+       }\r
+\r
+       static \r
+       NTSTATUS Dispatch(\r
+               IN PDEVICE_OBJECT pDeviceObject,\r
+               IN PIRP pIrp\r
+               );\r
+\r
+\r
+\r
+private:\r
+\r
+       PDEVICE_OBJECT m_pDevObj;\r
+};\r
+\r
+#endif //H_SDP_DRIVER_H\r
diff --git a/ulp/sdp/kernel/SdpTrace.h b/ulp/sdp/kernel/SdpTrace.h
new file mode 100644 (file)
index 0000000..c07318e
--- /dev/null
@@ -0,0 +1,29 @@
+\r
+#ifndef H_SDP_TRACE_H\r
+#define H_SDP_TRACE_H \r
+\r
+// Debug level masks\r
+#define SDP_ALL        0x00000001\r
+#define SDP_DEBUG      0x00000002\r
+#define SDP_TRACE      0x00000004\r
+#define SDP_WARN       0x00000008\r
+#define SDP_ERR        0x00000010\r
+\r
+// Debug toppics\r
+#define SDP_API                        0x000001\r
+#define SDP_CONNECT    0x000002\r
+#define SDP_DRIVER             0x000004\r
+\r
+\r
+BOOLEAN CheckCondition(int sev, int top, char *file, int line) {\r
+       return TRUE;\r
+}\r
+\r
+#define SDP_PRINT(sev, toppic ,var_args)                                               \\r
+       if (CheckCondition(sev, toppic ,__FILE__, __LINE__)  != FALSE)  \\r
+       DbgPrint var_args\r
+\r
+\r
+\r
+#endif //H_SDP_TRACE_H\r
+\r
diff --git a/ulp/sdp/kernel/makefile b/ulp/sdp/kernel/makefile
new file mode 100644 (file)
index 0000000..9c985f5
--- /dev/null
@@ -0,0 +1,7 @@
+#\r
+# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source\r
+# file to this component.  This file merely indirects to the real make file\r
+# that is shared by all the driver components of the Windows NT DDK\r
+#\r
+\r
+!INCLUDE $(NTMAKEENV)\makefile.def\r