switchbrew / libnx

Library for Switch Homebrew
https://switchbrew.github.io/libnx/
ISC License
1.27k stars 174 forks source link

USB bind error #109

Closed RKX1209 closed 6 years ago

RKX1209 commented 6 years ago

Hi. I'm developing debugger client that communicates with nxdbg stub app through USB connection. But stub app can't initialize usb connection due to error code 0xf601(i.e port remote dead) in this line.

My debugger client opens USB connection correctly(right vendor id, endpoint...).
What's the problem? Have you encountered such error code?

yellows8 commented 6 years ago

So you try to run the original nxdbg sysmodule and it throws a fatal-error?(Completely unrelated to client when it's during init)

What sysver?

RKX1209 commented 6 years ago

Yes. My client-side env.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 17.10
Release:        17.10
Codename:       artful

And stub app runs on Nintendo switch 3.0.0.

I also tried to run the original nxdbg client but, it cause some errors. Here is the log.

$ sudo python MainWindow.py --pid 100
Traceback (most recent call last):                                              
  File "MainWindow.py", line 198, in <module>                                   
    sys.exit(main(sys.argv))                                                    
  File "MainWindow.py", line 161, in main                                       
    usb = UsbConnection()                                                       
  File "nxdbg/debugger/UsbConnection.py", line 180, in
 __init__                                                                       
    self.dev.set_configuration()                                                
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 869, in set_co
nfiguration                                                                     
    self._ctx.managed_set_configuration(self, configuration)                    
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 102, in wrappe
r                                                                               
    return f(self, *args, **kwargs)                                             
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 148, in managed_set_configuration 
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)          File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 79$, in set_configuration                  
    _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))    File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 59$, in _check         
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])                     
usb.core.USBError: [Errno None] Other error

And original stub app failed too, which is same situation as my case. (Same error code 0xf601 at the point)

I'd like to confirm, does usb communication capability requires kernelhax? If so, my switch has no kernel access yet, and it can cause this problem.

But I guess it can be possible to use usb:ds service from hb apps without kernel privilege.

yellows8 commented 6 years ago

Client should be irrelevant - 0xF601 happens without any client running right?

RKX1209 commented 6 years ago

Yes. It happens regardless of client status, running or not. So it can be stub side problem.

yellows8 commented 6 years ago

usbds doesn't need kernelhax. How are you running HBL?

RKX1209 commented 6 years ago

Along with this instruction So backend may be pegaswitch.(not fusee launcher)

RKX1209 commented 6 years ago

Hi. Any progress?

yellows8 commented 6 years ago

Dunno what's wrong.

Gillou68310 commented 6 years ago

Same issue here, usbds initialization fails at _usbDsBindDevice while testing usbds example. I first thought this could be caused by usb sysmodule modifications on newer sysver (I'm on 5.0.2), but since it also happens to @RKX1209 on 3.0.0 there' s probably something else going on here!

sphaerophoria commented 6 years ago

My switch also crashes using the usbds example inside the usbDsInitialize call somewhere. Launching on firmware 5.1.0 through SXOS 1.2 (error code 2001-0123 which should be the same as noted 0xf601 in parent)

sphaerophoria commented 6 years ago

I dug into my error a little further yesterday. It looks like it's actually coming from _usbDsSetVidPidBcd. I can dodge this call with a NULL deviceinfo passed into the function, but I then get it a little further up on _usbDsGetSession.

I tried ignoring all 0xf601's due to the comment in http://switchbrew.org/index.php?title=SVC#svcReplyAndReceive . Although it's not usb related I thought they may mean that another session has closed. I think it's unlikely this is the case.

I also started digging around the ptm service. Thought process was that maybe someone is holding the usb port in a certain mode for charging so we can't change it. On second thought it's probably more likely to be the HID module since I'm seeing it show up on my linux box as an hid device

└> dmesg | grep hid
[33734.203715] hid-generic 0003:057E:2000.003B: hiddev0,hidraw0: USB HID v1.11 Device [Nintendo Nintendo Switch] on usb-0000:00:1d.0-1.2/input0
CordY5 commented 6 years ago

Any plans to fix this issue ? Need this error to be fixed if I want to finish my app.

misson20000 commented 6 years ago

On my 3.0.0 console, USB initialization blocks somewhere pretty early until you unplug the USB cable and plug it back in again. Try that?

CordY5 commented 6 years ago

@misson2000 doesn't work

JustForNothing commented 6 years ago

It seems the USB sysmodule is completely different in 5.X But for the debugger I found a workaround: just use TCP instead.

yellows8 commented 6 years ago

On <5.0 with the usbds example, does it happen with both the original example and with the second param here changed to NULL? https://github.com/switchbrew/switch-examples/blob/master/usb/usbds/source/main.c#L129

Monotek18 commented 6 years ago

@yellows8 on 3.0.0, it doesn't happen with the original example + with the second param here changed to NULL. But when you change the second param to NULL, I get 2140-0305 whenever you unplug the USB while running the homebrew.

yellows8 commented 6 years ago

@Monotek18 Were you reading from the serial device host-side?

EDIT: Sounds like usbds is fine as long as deviceinfo is set.

yellows8 commented 6 years ago

Can someone on 5.x also try this? https://github.com/switchbrew/libnx/issues/109#issuecomment-406746990

Monotek18 commented 6 years ago

@yellows8 On my 5.1.0, I still have 2001-0123 even with the 2nd param changed to NULL & with the original example.

WinterMute commented 6 years ago

On 5.1.0 I get the same 2001-0123 error.

On 3.0.0 the nxdbg stub app inits fine and the usbds example works fine. With the 2nd parameter set to NULL the Switch reads VID/PID as 057e/3000

yellows8 commented 6 years ago

@RKX1209 Since it works fine for everyone else on pre-5.0.0, can you try again with RCM + latest libnx/nx-hbloader?

(5.0.0+ support can't be fixed until the new commands are documented)

RKX1209 commented 6 years ago

On my 5.1.0, same error 2001-0123 happen even if with latest hbloader, fusee launcher;)

SciresM commented 6 years ago

Should be closed by PR #181

RKX1209 commented 6 years ago

Thank you all you guys!