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