using WdfIoTargetSendIoctlSynchronously to send Ioctls

Hello im a newbie when i comes to windows kernel drivers, and im eager to learn this new topic,
im trying to send ATA/SCSI IOCTLS to Harddrives/SSDs/USB connected devices from kernel driver.
i researched abit and found WdfIoTargetSendIoctlSynchronously function, but im unable to understand how to fill the function it self in order to succeed with sending ATA/SCSI IOCTLs
i was able to send ATA/SCSI commands from userspace using DeviceIoControl, now im trying to do it from the kernel instead
I’ve researched for few days and still couldn’t understand on how to achieve my goal, any help is appreciated .
TL;DR: Can’t figure how to send ATA/SCSI commands to connected PhysicalDrives from Windows Kernel Drivers (WDF)

Anything that CAN be done in user mode SHOULD be done in user mode. Don’t use the kernel just because it’s fun. Kernel code is always more dangerous, because bugs have such drastic consequences.

Having said that, WdfIoTargetSendIoctlSynchronously is one of the simplest KMDF functions. It builds the IRP for you and handles all of the completion and cancellation details for you. The parameters are practically the same as the user mode DeviceIoControl call. What is giving you trouble?

@Tim_Roberts said:
Anything that CAN be done in user mode SHOULD be done in user mode. Don’t use the kernel just because it’s fun. Kernel code is always more dangerous, because bugs have such drastic consequences.

Having said that, WdfIoTargetSendIoctlSynchronously is one of the simplest KMDF functions. It builds the IRP for you and handles all of the completion and cancellation details for you. The parameters are practically the same as the user mode DeviceIoControl call. What is giving you trouble?

I understand the situation and how dangerous it is, this research is for curiosity and see what’s possible and what isn’t

Initially what gives me trouble is initializing IoTarget, and Request parameters, and understanding how to set a “PhysicallDriveX” as my target

@michaeljaplin said:

@Tim_Roberts said:
Anything that CAN be done in user mode SHOULD be done in user mode. Don’t use the kernel just because it’s fun. Kernel code is always more dangerous, because bugs have such drastic consequences.

Having said that, WdfIoTargetSendIoctlSynchronously is one of the simplest KMDF functions. It builds the IRP for you and handles all of the completion and cancellation details for you. The parameters are practically the same as the user mode DeviceIoControl call. What is giving you trouble?

I understand the situation and how dangerous it is, this research is for curiosity and see what’s possible and what isn’t

Initially what gives me trouble is initializing IoTarget, and Request parameters, and understanding how to set a “PhysicallDriveX” as my target

i have found that in order to target PhysicalDrives, i need to use the SymLink of \Device\Harddisk\DR?, where do I initialize this Target?

where do I initialize this Target?

I don’t understand the question.

Call WdfIoTargetOpen sometime before you need to use the Target.

Enter