NTSTATUS EvtDevicePrepareHardware( IN WDFDEVICE Device, IN WDFCMRESLIST ResourceList, IN WDFCMRESLIST ResourceListTranslated ) { NTSTATUS status; PDEVICE_CONTEXT devCtx = NULL; WDF_USB_CONTINUOUS_READER_CONFIG interruptConfig; UNREFERENCED_PARAMETER(ResourceList); UNREFERENCED_PARAMETER(ResourceListTranslated); // Get device context devCtx = GetDeviceContext(Device); // Configure USB Interface status = ConfigureUsbInterface(Device, devCtx); if(!NT_SUCCESS(status)) return status; // Configure USB Pipe status = ConfigureUsbPipes(devCtx); if(!NT_SUCCESS(status)) return status; // Init Power Management status = InitPowerManagement(Device, devCtx); if(!NT_SUCCESS(status)) return status; /*Set up the interrupt endpoint with a continuous read operation. that way we are guaranteed that no interrupt data is lost.*/ WDF_USB_CONTINUOUS_READER_CONFIG_INIT(&interruptConfig, EvtUsbDeviceInterrupt, // Interrupt Event devCtx, sizeof(BYTE)); status = WdfUsbTargetPipeConfigContinuousReader( devCtx->UsbInterruptPipe, &interruptConfig); if(!NT_SUCCESS(status)) { KdPrint((__DRIVER_NAME "WdfUsbTargetPipeConfigContinuousReader failed with status 0x%08x\n", status)); return status; } return status; }
HRESULT CMyDevice::OnPrepareHardware( __in IWDFDevice * /* FxDevice */ ) /*++ Routine Description: This routine is invoked to ready the driver to talk to hardware. It opens the handle to the device and talks to it using the WINUSB interface. It invokes WINUSB to discver the interfaces and stores the information related to bulk endpoints. Arguments: FxDevice : Pointer to the WDF device interface Return Value: HRESULT --*/ { PWSTR deviceName = NULL; DWORD deviceNameCch = 0; HRESULT hr; // // Get the device name. // Get the length to allocate first // hr = m_FxDevice->RetrieveDeviceName(NULL, &deviceNameCch); if (FAILED(hr)) { TraceEvents(TRACE_LEVEL_ERROR, TEST_TRACE_DEVICE, "%!FUNC! Cannot get device name %!HRESULT!", hr ); } // // Allocate the buffer // if (SUCCEEDED(hr)) { deviceName = new WCHAR[deviceNameCch]; if (deviceName == NULL) { hr = E_OUTOFMEMORY; } } // // Get the actual name // if (SUCCEEDED(hr)) { hr = m_FxDevice->RetrieveDeviceName(deviceName, &deviceNameCch); if (FAILED(hr)) { TraceEvents(TRACE_LEVEL_ERROR, TEST_TRACE_DEVICE, "%!FUNC! Cannot get device name %!HRESULT!", hr ); } } if (SUCCEEDED(hr)) { TraceEvents(TRACE_LEVEL_INFORMATION, TEST_TRACE_DEVICE, "%!FUNC! Device name %S", deviceName ); } // // Create USB I/O Targets and configure them // if (SUCCEEDED(hr)) { hr = CreateUsbIoTargets(); } if (SUCCEEDED(hr)) { ULONG length = sizeof(m_Speed); hr = m_pIUsbTargetDevice->RetrieveDeviceInformation(DEVICE_SPEED, &length, &m_Speed); if (FAILED(hr)) { TraceEvents(TRACE_LEVEL_ERROR, TEST_TRACE_DEVICE, "%!FUNC! Cannot get usb device speed information %!HRESULT!", hr ); } } if (SUCCEEDED(hr)) { TraceEvents(TRACE_LEVEL_INFORMATION, TEST_TRACE_DEVICE, "%!FUNC! Speed - %x\n", m_Speed ); } if (SUCCEEDED(hr)) { hr = ConfigureUsbPipes(); } // // Setup power-management settings on the device. // if (SUCCEEDED(hr)) { hr = SetPowerManagement(); } // // Clear the seven segement display to indicate that we're done with // prepare hardware. // if (SUCCEEDED(hr)) { hr = IndicateDeviceReady(); } #if defined(_NOT_POWER_POLICY_OWNER_) // // We have non-power managed queues, so we Stop them in OnReleaseHardware // and start them in OnPrepareHardware // if (SUCCEEDED(hr)) { m_ReadWriteQueue->Start(); m_ControlQueue->Start(); } #endif if (SUCCEEDED(hr)) { hr = ConfigContReaderForInterruptEndPoint(); } delete[] deviceName; return hr; }
HRESULT CMyDevice::OnPrepareHardware( _In_ IWDFDevice * /* FxDevice */ ) /*++ Routine Description: This routine is invoked to ready the driver to talk to hardware. It opens the handle to the device and talks to it using the WINUSB interface. It invokes WINUSB to discver the interfaces and stores the information related to bulk endpoints. Arguments: FxDevice : Pointer to the WDF device interface Return Value: HRESULT --*/ { PWSTR deviceName = NULL; DWORD deviceNameCch = 0; HRESULT hr; // // Get the device name. // Get the length to allocate first // hr = m_FxDevice->RetrieveDeviceName(NULL, &deviceNameCch); if (FAILED(hr)) { TraceEvents(TRACE_LEVEL_ERROR, TEST_TRACE_DEVICE, "%!FUNC! Cannot get device name %!hresult!", hr ); } // // Allocate the buffer // if (SUCCEEDED(hr)) { deviceName = new WCHAR[deviceNameCch]; if (deviceName == NULL) { hr = E_OUTOFMEMORY; } } // // Get the actual name // if (SUCCEEDED(hr)) { hr = m_FxDevice->RetrieveDeviceName(deviceName, &deviceNameCch); if (FAILED(hr)) { TraceEvents(TRACE_LEVEL_ERROR, TEST_TRACE_DEVICE, "%!FUNC! Cannot get device name %!hresult!", hr ); } } if (SUCCEEDED(hr)) { TraceEvents(TRACE_LEVEL_INFORMATION, TEST_TRACE_DEVICE, "%!FUNC! Device name %S", deviceName ); } // // Create USB I/O Targets and configure them // if (SUCCEEDED(hr)) { hr = CreateUsbIoTargets(); } if (SUCCEEDED(hr)) { ULONG length = sizeof(m_Speed); hr = m_pIUsbTargetDevice->RetrieveDeviceInformation(DEVICE_SPEED, &length, &m_Speed); if (FAILED(hr)) { TraceEvents(TRACE_LEVEL_ERROR, TEST_TRACE_DEVICE, "%!FUNC! Cannot get usb device speed information %!HRESULT!", hr ); } } if (SUCCEEDED(hr)) { TraceEvents(TRACE_LEVEL_INFORMATION, TEST_TRACE_DEVICE, "%!FUNC! Speed - %x\n", m_Speed ); } if (SUCCEEDED(hr)) { hr = ConfigureUsbPipes(); } delete[] deviceName; return hr; }