当前位置: 代码迷 >> 驱动开发 >> send a IOCTL from driver A to driver B,该如何解决
  详细解决方案

send a IOCTL from driver A to driver B,该如何解决

热度:167   发布时间:2016-04-28 10:49:41.0
send a IOCTL from driver A to driver B
我现在从driver A传送IOCTL给driver B, driver B可以收到,可是用WdfRequestRetrieveInputMemory,无法从request中取得正确的资料,source code如下.

#define IOCTL_TEST CTL_CODE(FILE_DEVICE_FIREFLY, 0x802, METHOD_BUFFERED, FILE_ANY_ACCESS)

driver A:

NTSTATUS status;
WDFREQUEST Request;
WDF_OBJECT_ATTRIBUTES attributes;
WDFMEMORY MemBuffer = NULL;
char InputBuffer[5];

status = WdfRequestCreate(WDF_NO_OBJECT_ATTRIBUTES,
  DevExt->ioTarget,
  &Request);
  if (!NT_SUCCESS(status)) {
  KdPrint(("WdfRequestCreate failed.status=0x%x!", status));
  return;
  }
  WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
  attributes.ParentObject = Request;

  status = WdfMemoryCreate(&attributes,
  NonPagedPool,
  0,
  5,
  &MemBuffer,
  (PVOID)&InputBuffer);

  if (!NT_SUCCESS(status)) {
  KdPrint(("WdfMemoryCreate failed.status=0x%x!", status));
  return;
}

  status = WdfIoTargetFormatRequestForIoctl(DevExt->ioTarget,
Request,
IOCTL_TEST,
MemBuffer,
NULL,
NULL,
NULL);
if (!NT_SUCCESS(status)) {
KdPrint(("WdfIoTargetFormatRequestForIoctl failed.status=0x%x!", status));
return;
}

InputBuffer[0] = 0x05;
InputBuffer[1] = 0x04;
InputBuffer[2] = 0x03;
InputBuffer[3] = 0x02;
InputBuffer[4] = 0x01;

WDF_REQUEST_SEND_OPTIONS_INIT(&options,
WDF_REQUEST_SEND_OPTION_SYNCHRONOUS);
if (!WdfRequestSend(Request,
DevExt->ioTarget,
&options)) {
status = WdfRequestGetStatus(Request);
if (!NT_SUCCESS(status)) {
KdPrint(("WdfRequestSend failed! 0x%0.4x", status));
}
}

driver B:

NTSTATUS status;
PVOID buf;
size_t bufSize;
WDFMEMORY reqMemory;

status = WdfRequestRetrieveInputMemory(Request,
&reqMemory);
if (!NT_SUCCESS(status)) {
KdPrint(("WdfRequestRetrieveInputMemory fail\n"));
WdfRequestComplete(Request, STATUS_UNSUCCESSFUL);
return;
}
buf = WdfMemoryGetBuffer(reqMemory, &bufSize);
KdPrint(("0: 0x%X, bufSize: %d\n", ((char *)buf)[0], bufSize));

------解决方案--------------------
WDF 呀

 你这是驱动调用驱动吧?
 
 建议看看 张帆的那本书,有一章,专门描述这个内容的
  相关解决方案