// Send control transfer status = WdfUsbTargetDeviceSendControlTransferSynchronously( UsbDevice, WDF_NO_HANDLE, // Optional WDFREQUEST WDF_NO_HANDLE, // Optional send options &setupPacket, NULL, // Optional memory NULL, // Optional offset &bytesTransferred );

int main() HANDLE hCamera = OpenCameraDevice(); if (hCamera == INVALID_HANDLE_VALUE) printf("Failed to open camera device\n"); return 1;

WDF_USB_CONTROL_SETUP_PACKET setupPacket; WDF_MEMORY memory; NTSTATUS status; ULONG bytesTransferred;

default: status = STATUS_INVALID_DEVICE_REQUEST; break;

case IOCTL_CAMERA_SET_FOCUS: if (InputBufferLength < sizeof(ULONG)) status = STATUS_INVALID_PARAMETER; break; ULONG focusValue = *(PULONG)inputBuffer; KdPrint(("Setting focus: %d\n", focusValue)); status = SendVendorCommand(deviceContext->UsbDevice, 0x02, focusValue); break;

// Helper function to send vendor-specific USB control transfer NTSTATUS SendVendorCommand( In WDFUSBDEVICE UsbDevice, In UCHAR Command, In ULONG Value )

deviceContext = DeviceGetContext(Device); KdPrint(("EagleEyeEvtDevicePrepareHardware\n"));

if (OutputBufferLength > 0) status = WdfRequestRetrieveOutputBuffer(Request, OutputBufferLength, &outputBuffer, NULL); if (!NT_SUCCESS(status)) WdfRequestComplete(Request, status); return;

WDF_DRIVER_CONFIG_INIT(&config, EagleEyeEvtDeviceAdd);

// Initialize device attributes with context WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&deviceAttributes, DEVICE_CONTEXT);

deviceContext = DeviceGetContext(device);

WDF_DRIVER_CONFIG config; NTSTATUS status;

for (DWORD i = 0; SetupDiEnumDeviceInterfaces(deviceInfoSet, NULL, &guid, i, &interfaceData); i++) DWORD requiredSize = 0; SetupDiGetDeviceInterfaceDetail(deviceInfoSet, &interfaceData, NULL, 0, &requiredSize, NULL); PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(requiredSize); detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); if (SetupDiGetDeviceInterfaceDetail(deviceInfoSet, &interfaceData, detailData, requiredSize, NULL, NULL)) GENERIC_WRITE, FILE_SHARE_READ free(detailData);