KMDF - IOCTL_ATA_PASS_THROUGH

I’m trying to understand how to go about sending a “IOCTL_ATA_PASS_THROUGH” via
WdfIoTargetFormatRequestForInternalIoctl or WdfIoTargetSendIoctlSynchronously.

Im using WdfMemoryCreate() to setup a Input and Output memory. I use WDF_MEMORY_DESCRIPTOR_INIT_BUFFER to allocate space to a ATA_PASS_THROUGH_EX structure. etc… Seam to keep hitting issue after issue.

Am I making any simply mistakes? or am i simply going about it wrong? To make a long story short im sending some PTE structures that I’ve tested in a user based application directly to PhysicalDrive0 and works fine using DeviceIoControl. I’ve tried ZwDeviceIoControl and had no success, and am not really familiar with the KMDF framework. if someone could point me in the correct direction be helpful.

EOF>>>

ATA_PASS_THROUGH_EX *PTE_SEND;
ATA_PASS_THROUGH_EX *PTE_RECV;

WDF_OBJECT_ATTRIBUTES memoryObjAttr;
WDF_OBJECT_ATTRIBUTES_INIT(&memoryObjAttr);
memoryObjAttr.ParentObject = Request;

//READ BUFFER FOR IOCTL DATA OUT
status = WdfMemoryCreate(&memoryObjAttr, NonPagedPool, RAMDISK_TAG_READ, sizeof(ATA_PASS_THROUGH_EX)+cmdBufferSize, &(deviceContext->DiskReadBuffer), NULL);
if (!NT_SUCCESS(status)) {
WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&(deviceContext->DiskReadBufferDescriptor),
(PVOID)&PTE_SEND,
sizeof(ATA_PASS_THROUGH_EX)+cmdBufferSize
);
} else {
TraceEvents(TRACE_LEVEL_ERROR, TRACE_DEVICE, “WdfMemoryCreate failed %!STATUS!”, status);
return status;
}

//WRITE BUFFER FOR IOCTL DATA IN
status = WdfMemoryCreate(&memoryObjAttr, NonPagedPool, RAMDISK_TAG_WRITE, sizeof(ATA_PASS_THROUGH_EX)+cmdBufferSize, &(deviceContext->DiskWriteBuffer), NULL);
if (NT_SUCCESS(status)) {
WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&(deviceContext->DiskWriteBufferDescriptor),
(PVOID)&PTE_RECV,
sizeof(ATA_PASS_THROUGH_EX)+cmdBufferSize
);
} else {
TraceEvents(TRACE_LEVEL_ERROR, TRACE_DEVICE, “WdfMemoryCreate failed %!STATUS!”, status);
return status;
}
WDFIOTARGET Target = GetHDD(Queue);
if (Target != NULL) {

status = WdfIoTargetFormatRequestForInternalIoctl(
Target,
Request,
IOCTL_ATA_PASS_THROUGH,
deviceContext->DiskReadBuffer,
NULL,
deviceContext->DiskWritedBuffer,
NULL
);

if (!NT_SUCCESS(status)) { KdPrint((“WdfIoTargetSendIoctlSynchronously failed with status 0x % x\n”, status)); }
else {
WdfRequestSetCompletionRoutine( Request, NULL, NULL );

if (WdfRequestSend(Request, Target, WDF_NO_SEND_OPTIONS) == FALSE) {

status = WdfRequestGetStatus(Request);
KdPrint((“WdfRequestGetStatus = 0x%x\n”, status));
}
else {
status = STATUS_SUCCESS;
}
}
}
else {
KdPrint((“Failed to Create WDFTargetIOHandle”));
}
KdPrint((“IO StatusCode = 0x%x\n”, status));

EOF<<<