1

I can send data driver to app.

In app:

DeviceIoControl(dHandle, IOCTL_TEST, (PVOID)InputBuffer, sizeof(InputBuffer), (PVOID)OutputBuffer, sizeof(OutputBuffer), &dwRet, 0);
printf("num : %s\n", OutputBuffer);

In driver:

char pData[1024];
pData="eeee";
case IOCTL_TEST:
        pInputBuffer = Irp->AssociatedIrp.SystemBuffer;
        pOutputBuffer = Irp->AssociatedIrp.SystemBuffer;
        inputBufferLength = pStack->Parameters.DeviceIoControl.OutputBufferLength;
        RtlCopyMemory(pOutputBuffer, pData, strlen(pData));
        break;
Irp.IoStatus.Information=1024;

The result is printed "eeee" in application console.

But i don't know how to send app data to driver. DeviceIoControl's 3, 4 parameters are input buffer and length.
If I add char InputBuffer[1024] = "InputBuffer's data"; in app, how driver can receive this data? I want to use DbgPrint() for accepted data from app.


I want to select answer. plz answer not comment.

Lightstar
  • 183
  • 3
  • 12
  • It depends on the `TransferType` parameter in the control code. For `METHOD_BUFFERED` the device driver just reads the data from `pInputBuffer`. It's all described at http://msdn.microsoft.com/en-us/library/windows/hardware/ff540663%28v=vs.85%29.aspx – Harry Johnston Jan 09 '15 at 05:08
  • hm... This is my thought... I call Irp->AssociatedIrp.Systembuffer 2 tiems, so pInputBuffer and pOutputBuffer point same address. And RtlCopyMemory() write pOutputBuffer with pData. Then, if pInputBuffer have a data from app, this data is gone. Therefore i have to copy pInputBuffer(data from app) to another buffer, and have to call RtlCopyMemory to write data to app. Is it correct? – Lightstar Jan 09 '15 at 05:31
  • Yes. If you need to use the input data *after* you've written the output data, you'll have to copy the input data somewhere. Typically, though, you would process the input data first (send it to DbgPrint, for instance) and only then write the output data to the buffer. – Harry Johnston Jan 09 '15 at 05:35
  • Thank you for your help. I success in app - driver communication. However If i want to send data from driver to app first and almost every time,(don't need to write data from app to driver), DeviceIoControl is not suitable. – Lightstar Jan 09 '15 at 05:59
  • Actually i develop packet filter driver. So packet capture function in drver is called. I want to send this packet data captured to app. But DeviceIoControl have to called in app. App only need to read packet data from driver when driver send. This send work occure faster than 1seconds. ... Driver only write packet data to app and app only read packet from when driver send packet data. – Lightstar Jan 09 '15 at 06:03
  • Of course, I'll use DeviceIoControl() another way. ex) driver control... Anyway how the one way send work is implemented? Some keyword plz – Lightstar Jan 09 '15 at 06:06
  • If the driver doesn't need input for this particular control code, you pass `NULL` for the input buffer in the call to DeviceIoControl(). There are plenty of control codes that work that way. Nor does the DeviceIoControl() have to return immediately, you can wait until a packet has been captured before completing the I/O request. It should work fine. But you can use ReadFile() and DispatchRead() instead if you prefer, unless you need that to communicate with other drivers in the stack. – Harry Johnston Jan 09 '15 at 23:17
  • If packet(1514byte) is captured every 100 miliseconds or more faster and want driver to send this to app immediately, should i call ReadFile() in app more fast than every 100 miliseconds? So, to close this question, plz answer with lower answer button not comment. – Lightstar Jan 10 '15 at 04:08

1 Answers1

0

I solved it. The solution is the driver receive data from app with Irp->AssociatedIrp.Systembuffer; So, just print this pointer's data.

Lightstar
  • 183
  • 3
  • 12