About Driver-Driver Communication.

  1. Data Structure

typedef struct _Data
{
char temp1[5];
char temp2[5];
} data, *pdata;
data DATA;
pdata PDATA;

  1. Sender (DriverA)
    RtlInitUnicodeString(&UIDeviceName, L"\Device\DriverB");
    if (status != STATUS_SUCCESS)
    {
    DbgPrint((“Error RtlQueryRegistryValues\n”));
    return FALSE;
    }
    status = IoGetDeviceObjectPointer(&UIDeviceName, FILE_READ_DATA,
    &MonitorDeviceFileObject, &MonitorDeviceObject);
    switch (status)
    {
    case STATUS_SUCCESS:
    ObDereferenceObject(MonitorDeviceFileObject);
    ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
    KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
    strcpy(DATA.temp1, “AAAA\0”);
    strcpy(DATA.temp2, “BBBB\0”);
    NewIrp = IoBuildDeviceIoControlRequest(IO_MESSAGE,
    MonitorDeviceObject,
    &DATA, sizeof(DATA), NULL, 0, FALSE,
    NULL, 0, NULL, 0, FALSE,
    &Event, &IoStatusBlock);
    if (NewIrp == NULL)
    {
    DbgPrint((“Error IoBuildDeviceIoControlRequest \n”));
    }
    status = IoCallDriver(MonitorDeviceObject, NewIrp);
    if (status == STATUS_PENDING)
    {
    KeWaitForSingleObject(&Event, Executive, KernelMode,
    FALSE, NULL);
    }
    DbgPrint((“End of Communication!\n”));
    break;
    }

  2. Receiver (DriverB)
    NTSTATUS DriverIoControlRoutine(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp )
    {
    NTSTATUS status = STATUS_SUCCESS;
    ULONG controlCode;
    PIO_STACK_LOCATION irpStack;
    HANDLE hEvent;
    OBJECT_HANDLE_INFORMATION objHandleInfo;
    LONG* outBuf;
    PVOID ioBuffer;
    irpStack = IoGetCurrentIrpStackLocation(Irp);
    controlCode = irpStack->Parameters.DeviceIoControl.IoControlCode;
    switch(controlCode)
    {
    case IO_MESSAGE:
    ioBuffer = Irp->AssociatedIrp.SystemBuffer;
    PDATA = (pdata) ioBuffer;
    DbgPrint((“%s\n”, PDATA->temp1);
    DbgPrint((“%s\n”, PDATA->temp2);
    break;
    default:
    break;
    }
    Irp->IoStatus.Status = STATUS_SUCCESS;
    Irp->IoStatus.Information = 0;
    IoCompleteRequest(Irp, IO_NO_INCREMENT);
    return status;
    }

“DriverA” want send a data-structure(_Data) to “DriverB”.
Characters-array variables of structure _Data, “temp1” and “temp2”, have a
value respectively.
I used “IoBuildDeviceIoControlRequest” moudule in “DriverA” to send this
structure.
Then, “DriverB” receives “IO_MESSAGE” through “DeviceIoControlRoutine”.
By the way, When i inserted “Dbgprint” command to confirm received value,
system downed showing blue-screen.
What’s the reason of this situation?
And, Is this method correct in sending a data to other drivers?

Any information would be really useful.
With regards!

Chang Sung, Jung.

What’s the ctlcode definition of your IOCTL? You may be accessing the
wrong buffer.

-----Original Message-----
From: Chang Sung, Jung. [mailto:xxxxx@korea.com]
Sent: Wednesday, October 02, 2002 1:48 AM
To: File Systems Developers
Subject: [ntfsd] About Driver-Driver Communication.

  1. Data Structure

typedef struct _Data
{
char temp1[5];
char temp2[5];
} data, *pdata;
data DATA;
pdata PDATA;

  1. Sender (DriverA)
    RtlInitUnicodeString(&UIDeviceName, L"\Device\DriverB");
    if (status != STATUS_SUCCESS)
    {
    DbgPrint((“Error RtlQueryRegistryValues\n”));
    return FALSE;
    }
    status = IoGetDeviceObjectPointer(&UIDeviceName, FILE_READ_DATA,
    &MonitorDeviceFileObject, &MonitorDeviceObject); switch
    (status) { case STATUS_SUCCESS:
    ObDereferenceObject(MonitorDeviceFileObject);
    ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
    KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
    strcpy(DATA.temp1, “AAAA\0”);
    strcpy(DATA.temp2, “BBBB\0”);
    NewIrp = IoBuildDeviceIoControlRequest(IO_MESSAGE,
    MonitorDeviceObject,
    &DATA, sizeof(DATA), NULL, 0, FALSE,
    NULL, 0, NULL, 0, FALSE,
    &Event, &IoStatusBlock);
    if (NewIrp == NULL)
    {
    DbgPrint((“Error IoBuildDeviceIoControlRequest \n”));
    }
    status = IoCallDriver(MonitorDeviceObject, NewIrp);
    if (status == STATUS_PENDING)
    {
    KeWaitForSingleObject(&Event, Executive, KernelMode,
    FALSE, NULL);
    }
    DbgPrint((“End of Communication!\n”));
    break;
    }

  2. Receiver (DriverB)
    NTSTATUS DriverIoControlRoutine(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp )
    {
    NTSTATUS status = STATUS_SUCCESS;
    ULONG controlCode;
    PIO_STACK_LOCATION irpStack;
    HANDLE hEvent;
    OBJECT_HANDLE_INFORMATION objHandleInfo;
    LONG* outBuf;
    PVOID ioBuffer;
    irpStack = IoGetCurrentIrpStackLocation(Irp);
    controlCode =
    irpStack->Parameters.DeviceIoControl.IoControlCode;
    switch(controlCode)
    {
    case IO_MESSAGE:
    ioBuffer = Irp->AssociatedIrp.SystemBuffer;
    PDATA = (pdata) ioBuffer;
    DbgPrint((“%s\n”, PDATA->temp1);
    DbgPrint((“%s\n”, PDATA->temp2);
    break;
    default:
    break;
    }
    Irp->IoStatus.Status = STATUS_SUCCESS;
    Irp->IoStatus.Information = 0;
    IoCompleteRequest(Irp, IO_NO_INCREMENT);
    return status;
    }

“DriverA” want send a data-structure(_Data) to “DriverB”.
Characters-array variables of structure _Data, “temp1” and “temp2”, have
a value respectively. I used “IoBuildDeviceIoControlRequest” moudule in
“DriverA” to send this structure. Then, “DriverB” receives “IO_MESSAGE”
through “DeviceIoControlRoutine”. By the way, When i inserted “Dbgprint”
command to confirm received value, system downed showing blue-screen.
What’s the reason of this situation? And, Is this method correct in
sending a data to other drivers?

Any information would be really useful.
With regards!

Chang Sung, Jung.


You are currently subscribed to ntfsd as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to %%email.unsub%%

Thanks for your advice.

Ctlcode definition of my IOCTL :

#define FILE_DEVICE_HOOK_DRIVER 0x00008810

#define IO_EVENT (ULONG) CTL_CODE(FILE_DEVICE_HOOK_DRIVER, 0x801,
METHOD_NEITHER, FILE_ANY_ACCESS)

Hi,

That will be your problem then! See summary of METHOD_xxxx types
at http://www.cmkrnl.com/arc-ioctlbuf.html or
http://www.osr.com/ntinsider/1996/custom-ioctl.htm

METHOD_NEITHER doesn’t use Irp->AssociatedIrp.SystemBuffer. Try
changing IOCTL code definition to METHOD_BUFFERED.

Hope this helps.

Ben

-----Original Message-----
From: Chang Sung, Jung. [mailto:xxxxx@korea.com]
Sent: 04 October 2002 05:39
To: File Systems Developers
Subject: [ntfsd] RE: About Driver-Driver Communication.

Thanks for your advice.

Ctlcode definition of my IOCTL :

#define FILE_DEVICE_HOOK_DRIVER 0x00008810

#define IO_EVENT (ULONG) CTL_CODE(FILE_DEVICE_HOOK_DRIVER, 0x801,
METHOD_NEITHER, FILE_ANY_ACCESS)


You are currently subscribed to ntfsd as: xxxxx@des.co.uk
To unsubscribe send a blank email to %%email.unsub%%