cezanne / usbip-win

USB/IP for Windows
GNU General Public License v3.0
1.92k stars 346 forks source link

usb-tokens with same vid/pid #317

Open Kogotoro opened 2 years ago

Kogotoro commented 2 years ago

Hi. Encountered next strange behavior have d1 = 1-10 = usb-token USB\VID_0529&PID_0620\5&12C8F4C0&0&2 d2 = 1-29 = usb-token USB\VID_0529&PID_0620\5&12C8F4C0&0&3 d1 & d2 both is USB\VID_0529&PID_0620&REV_0100 : server: plug d1 (shows in Device Manager as Smart card readers > Microsoft Usbccid Smartcard Reader (WUDF) > no errors) bind d1 (shows as Smart card readers > USB/IP STUB > no errors)

client:

>usbip list -r 192.168.0.105
Exportable USB devices
======================
 - 192.168.0.105
       1-10: unknown vendor : unknown product (0000:0000)
           : \\?\usb#vid_0529&pid_0620#5&12c8f4c0&0&2#{fb265267-c609-41e6-8eca-a20d92a833e6}
           : (Defined at Interface level) (00/00/00)

server usbipd output have ERROR: usbipd: debug: usbipd_stub.c:77:[get_devinfo] get_devinfo: [\\?\usb#vid_0529&pid_0620#5&12c8f4c0&0&2#{fb265267-c609-41e6-8eca-a20d92a833e6}] DeviceIoControl failed: err: 0x1f

it still show device as shared but some data missing

server: plug d2 (shows as System devices > USB/IP STUB > no errors (and i just plug it witout any comands))

client:
>usbip list -r 192.168.0.105
c:\test\usbip-d10576d-test>usbip.exe list -r 192.168.0.105
Exportable USB devices
======================
 - 192.168.0.105
       1-10: unknown vendor : unknown product (0000:0000)
           : \\?\usb#vid_0529&pid_0620#5&12c8f4c0&0&2#{fb265267-c609-41e6-8eca-a20d92a833e6}
           : (Defined at Interface level) (00/00/00)

       1-29: Aladdin Knowledge Systems : Token JC (0529:0620)
           : \\?\usb#vid_0529&pid_0620#5&12c8f4c0&0&3#{fb265267-c609-41e6-8eca-a20d92a833e6}
           : (Defined at Interface level) (00/00/00)

server usbipd output: for d1 same error as before for d2 no errors

BUT: usbview util says for d2 !ERROR: No open pipes!

and open pipes presents before and after bind for d1 and also for d2 if it plugged while d1 not binded

BUT ALSO: i can attach d2... but cant d1 ...Oo? for d1 server says usbipd: debug: usbipd_stub.c:73:[get_devinfo] get_devinfo: cannot open device: \\?\usb#vid_0529&pid_0620#5&12c8f4c0&0&2#{fb265267-c609-41e6-8eca-a20d92a833e6}

strange but last time list -r error from server side was at usbipd_stub.c:77 , ie at DeviceIoControl but now it fails at CreateFile

static BOOL
get_devinfo(const char *devpath, ioctl_usbip_stub_devinfo_t *devinfo)
{
    HANDLE  hdev;
    DWORD   len;

    hdev = CreateFile(devpath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
    if (hdev == INVALID_HANDLE_VALUE) {
        dbg("get_devinfo: cannot open device: %s", devpath);
        return FALSE;
    }
    if (!DeviceIoControl(hdev, IOCTL_USBIP_STUB_GET_DEVINFO, NULL, 0, devinfo, sizeof(ioctl_usbip_stub_devinfo_t), &len, NULL)) {
        dbg("get_devinfo: DeviceIoControl failed: err: 0x%lx", GetLastError());
        CloseHandle(hdev);
        return FALSE;
    }
....

UPDATE: strange but i cant attach d1 even without d2 -_- with same errors.

Kogotoro commented 1 year ago

so... there is 2 errors:

  1. install process seems not apply co-installers for already plugged token while apply stub driver; (i tried rewrite install similar to this (with some changes) https://cpp.hotexamples.com/examples/-/-/SetupDiCallClassInstaller/cpp-setupdicallclassinstaller-function-examples.html#0xdbaebc902614d61e7f79211336dda175a9d0ed40eafde126c0c927992b794066-283,,585, where called SetupDiCallClassInstaller(DIF_REGISTER_COINSTALLERS, ...) and it was ok, and if comment call with DIF_REGISTER_COINSTALLERS i get same error as was with original install process )
  2. auto-selection stub driver (as best compatible) for new pluged devices with same vid/pid.

ps: but still... better(probably) adapt stub install/deinstall from https://github.com/dorssel/usbipd-win ... what can directly (without manual pre-install to driver storage, and manual search/select it after) install inf's without matching id for device (and it also free us from compile/sign inf/cat during programm work). Also we need lower inf chances for auto-install/select by system, it can be achieved by adding to inf section [ControlFlags] with attribute 'ExcludeFromSelect'.