Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usbdk can't work with some USB serial device(eg 076b:23c3) twice #117

Open
crazyboy01crazy opened this issue Feb 2, 2023 · 4 comments
Open
Assignees

Comments

@crazyboy01crazy
Copy link

when I use ”usbDkController -r“ to redir it first time, It's OK. but when I redir it again after stop the first time redir, Faild!

C:\Program Files\UsbDk Runtime Library>UsbDkController -r "USB\VID_067B&PID_23C3" BDEHf103Y23
Redirect USB device USB\VID_067B&PID_23C3, BDEHf103Y23
USB device was redirected successfully. Redirected device handle = 0000028AE8A41A10
Press any key to stop redirection
Restore USB device 0000028AE8A41A10
USB device redirection was stopped successfully.

C:\Program Files\UsbDk Runtime Library>UsbDkController -r "USB\VID_067B&PID_23C3" BDEHf103Y23
Redirect USB device USB\VID_067B&PID_23C3, BDEHf103Y23
Redirect of USB device failed
@crazyboy01crazy
Copy link
Author

PS:on windows10

@ybendito
Copy link
Collaborator

@crazyboy01crazy If you replug the device - does it solve the problem?

@crazyboy01crazy
Copy link
Author

@crazyboy01crazy If you replug the device - does it solve the problem?

Replug it can resolve the problem as I remember.

But , I need to use it without replug it. I try to find it why
`NTSTATUS CUsbDkControlDevice::AddRedirect(const USB_DK_DEVICE_ID &DeviceId, HANDLE RequestorProcess, PHANDLE RedirectorDevice)
{
CUsbDkRedirection *Redirection;
auto addRes = AddRedirectionToSet(DeviceId, &Redirection);
if (!NT_SUCCESS(addRes))
{
return addRes;
}
Redirection->AddRef();
CObjHolder<CUsbDkRedirection, CRefCountingDeleter> dereferencer(Redirection);

TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CONTROLDEVICE, "%!FUNC! Success. New redirections list:");
m_Redirections.Dump();

auto resetRes = ResetUsbDevice(DeviceId, true);
if (!NT_SUCCESS(resetRes))
{
    TraceEvents(TRACE_LEVEL_ERROR, TRACE_CONTROLDEVICE, "%!FUNC! Reset after start redirection failed. %!STATUS!", resetRes);
    AddRedirectRollBack(DeviceId, false);
    return resetRes;
}

auto waitRes = Redirection->WaitForAttachment();
if ((waitRes == STATUS_TIMEOUT) || !NT_SUCCESS(waitRes))
{
    TraceEvents(TRACE_LEVEL_ERROR, TRACE_CONTROLDEVICE, "%!FUNC! Wait for redirector attachment failed. %!STATUS!", waitRes);
    AddRedirectRollBack(DeviceId, true);
    return (waitRes == STATUS_TIMEOUT) ? STATUS_DEVICE_NOT_CONNECTED : waitRes;
}

auto status = Redirection->CreateRedirectorHandle(RequestorProcess, RedirectorDevice);
if (!NT_SUCCESS(status))
{
    TraceEvents(TRACE_LEVEL_ERROR, TRACE_CONTROLDEVICE, "%!FUNC! CreateRedirectorHandle() failed. %!STATUS!", status);
    AddRedirectRollBack(DeviceId, true);
    return STATUS_DEVICE_NOT_CONNECTED;
}

return STATUS_SUCCESS;

}`

After debugging, I find that the corresponding event such as WaitForAttachment cannot be detected after executing the ResetUsbDevice operation

1 similar comment
@crazyboy01crazy
Copy link
Author

@crazyboy01crazy If you replug the device - does it solve the problem?

Replug it can resolve the problem as I remember.

But , I need to use it without replug it. I try to find it why
`NTSTATUS CUsbDkControlDevice::AddRedirect(const USB_DK_DEVICE_ID &DeviceId, HANDLE RequestorProcess, PHANDLE RedirectorDevice)
{
CUsbDkRedirection *Redirection;
auto addRes = AddRedirectionToSet(DeviceId, &Redirection);
if (!NT_SUCCESS(addRes))
{
return addRes;
}
Redirection->AddRef();
CObjHolder<CUsbDkRedirection, CRefCountingDeleter> dereferencer(Redirection);

TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CONTROLDEVICE, "%!FUNC! Success. New redirections list:");
m_Redirections.Dump();

auto resetRes = ResetUsbDevice(DeviceId, true);
if (!NT_SUCCESS(resetRes))
{
    TraceEvents(TRACE_LEVEL_ERROR, TRACE_CONTROLDEVICE, "%!FUNC! Reset after start redirection failed. %!STATUS!", resetRes);
    AddRedirectRollBack(DeviceId, false);
    return resetRes;
}

auto waitRes = Redirection->WaitForAttachment();
if ((waitRes == STATUS_TIMEOUT) || !NT_SUCCESS(waitRes))
{
    TraceEvents(TRACE_LEVEL_ERROR, TRACE_CONTROLDEVICE, "%!FUNC! Wait for redirector attachment failed. %!STATUS!", waitRes);
    AddRedirectRollBack(DeviceId, true);
    return (waitRes == STATUS_TIMEOUT) ? STATUS_DEVICE_NOT_CONNECTED : waitRes;
}

auto status = Redirection->CreateRedirectorHandle(RequestorProcess, RedirectorDevice);
if (!NT_SUCCESS(status))
{
    TraceEvents(TRACE_LEVEL_ERROR, TRACE_CONTROLDEVICE, "%!FUNC! CreateRedirectorHandle() failed. %!STATUS!", status);
    AddRedirectRollBack(DeviceId, true);
    return STATUS_DEVICE_NOT_CONNECTED;
}

return STATUS_SUCCESS;

}`

After debugging, I find that the corresponding event such as WaitForAttachment cannot be detected after executing the ResetUsbDevice operation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants