BOOL OpenContext::IsPipeHalted(LPUKWD_ENDPOINT_INFO lpEndpointInfo, LPBOOL halted) { MutexLocker lock(mMutex); DevicePtr dev (mDevice->GetDeviceList(), lpEndpointInfo->lpDevice); if (!Validate(dev) || halted == NULL) { SetLastError(ERROR_INVALID_HANDLE); return FALSE; } // Find the interface for this device DWORD dwInterface = -1; if (lpEndpointInfo->Endpoint != 0) { if (!dev->FindInterface(lpEndpointInfo->Endpoint, dwInterface)) { ERROR_MSG((TEXT("USBKWrapperDrv!OpenContext::IsPipeHalted() - ") TEXT("failed to find interface for endpoint %d on device 0x%08x\r\n"), lpEndpointInfo->Endpoint, lpEndpointInfo->lpDevice)); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } // See if it's already been claimed if (!dev->InterfaceClaimed(dwInterface, this)) { WARN_MSG((TEXT("USBKWrapperDrv!OpenContext::IsPipeHalted() - ") TEXT("using interface %d on device 0x%08x without claiming\r\n"), dwInterface, lpEndpointInfo->lpDevice)); if (!dev->ClaimInterface(dwInterface, this)) { return FALSE; } } } return dev->IsEndpointHalted(dwInterface, lpEndpointInfo->Endpoint, *halted); }
BOOL OpenContext::StartBulkTransfer(LPUKWD_BULK_TRANSFER_INFO lpTransferInfo) { MutexLocker lock(mMutex); DevicePtr dev (mDevice->GetDeviceList(), lpTransferInfo->lpDevice); if (!Validate(dev)) { SetLastError(ERROR_INVALID_HANDLE); return FALSE; } // Interface can't be used if device has closed if (dev->Closed()) { SetLastError(ERROR_INVALID_HANDLE); return FALSE; } // Find the interface for this transfer DWORD dwInterface; if (!dev->FindInterface(lpTransferInfo->Endpoint, dwInterface)) { ERROR_MSG((TEXT("USBKWrapperDrv!OpenContext::StartBulkTransfer() - ") TEXT("failed to find interface for endpoint %d on device 0x%08x\r\n"), lpTransferInfo->Endpoint, lpTransferInfo->lpDevice)); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } // See if it's already been claimed if (!dev->InterfaceClaimed(dwInterface, this)) { WARN_MSG((TEXT("USBKWrapperDrv!OpenContext::StartBulkTransfer() - ") TEXT("using interface %d on device 0x%08x without claiming\r\n"), dwInterface, lpTransferInfo->lpDevice)); if (!dev->ClaimInterface(dwInterface, this)) { return FALSE; } } TRANSFERLIFETIME_MSG((TEXT("USBKWrapperDrv!OpenContext::StartBulkTransfer() on ep %x, flag 0x%08x and size %d\r\n"), lpTransferInfo->Endpoint, lpTransferInfo->dwFlags, lpTransferInfo->dwDataBufferSize)); // Construct and start the bulk transfer BulkTransfer* bt = new (std::nothrow) BulkTransfer( this, dev, dwInterface, lpTransferInfo); if (!bt) { ERROR_MSG((TEXT("USBKWrapperDrv!OpenContext::StartBulkTransfer() - failed to create bulk transfer, aborting\r\n"))); SetLastError(ERROR_NOT_ENOUGH_MEMORY); return FALSE; } BOOL ret = bt->Start(); mTransferList->PutTransfer(bt); bt = NULL; if (!ret) { ERROR_MSG((TEXT("USBKWrapperDrv!OpenContext::StartBulkTransfer() - failed to start bulk transfer %d\r\n"), GetLastError())); return FALSE; } // Ownership of ct has passed to the transfer callback return TRUE; }
BOOL OpenContext::ClearHaltDevice(LPUKWD_ENDPOINT_INFO lpEndpointInfo) { MutexLocker lock(mMutex); DevicePtr dev (mDevice->GetDeviceList(), lpEndpointInfo->lpDevice); if (!Validate(dev)) { SetLastError(ERROR_INVALID_HANDLE); return FALSE; } // Interface can't be used if device has closed if (dev->Closed()) { SetLastError(ERROR_INVALID_HANDLE); return FALSE; } // Find the interface for this device DWORD dwInterface; if (!dev->FindInterface(lpEndpointInfo->Endpoint, dwInterface)) { ERROR_MSG((TEXT("USBKWrapperDrv!OpenContext::ClearHalt() - ") TEXT("failed to find interface for endpoint %d on device 0x%08x\r\n"), lpEndpointInfo->Endpoint, lpEndpointInfo->lpDevice)); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } // See if it's already been claimed if (!dev->InterfaceClaimed(dwInterface, this)) { WARN_MSG((TEXT("USBKWrapperDrv!OpenContext::ClearHalt() - ") TEXT("using interface %d on device 0x%08x without claiming\r\n"), dwInterface, lpEndpointInfo->lpDevice)); if (!dev->ClaimInterface(dwInterface, this)) { return FALSE; } } return dev->ClearHaltDevice(dwInterface, lpEndpointInfo->Endpoint); }