Automatic Activation, Hotplug and UDEV, Configuration
Post Reply
buhtz
Posts: 5
Joined: 28 Nov 2021, 16:38

Modeswitch not working while booting (Debian 11) but when re-plug the device

Post by buhtz » 28 Nov 2021, 16:48

X-Post: https://debianforum.de/forum/viewtopic.php?t=182755

The main problem is that the modeswitching does not work when the system boots. But after plug off and re-plug the USB-WLAN-Stick it works well and a network device appears. So it seams that modeswitch itself works for that device. There is just a problem while booting.

It is Debian 11 (stable) on a Raspberry Pi 4. The Debian is from raspi.debian.net; official and pure Debian and not a derivate like Raspian aka Raspberry Pi OS.
The USB-Device is an USB-WLAN-Adapter DMG-19 (RTL8811CU Chipset). The driver was build and installed by myself (with help from Debian community).

I activated (EnableLogging=1) in /etc/usb_modeswitch.conf.
When booting without usb-stick and then pluging it in the log looks like this. https://debianforum.de/forum/pastebin/? ... ew&s=41539
When booting with the usb-stick and it is not recognized or switch while booting the log looks like this: https://debianforum.de/forum/pastebin/? ... ew&s=41538

Someone from the Debian community mentioned that the difference could be that EJECT does not work.

Code: Select all

Sending standard EJECT sequence
Looking for active drivers ...
Set up interface 0
and

Code: Select all

Sending standard EJECT sequence
Looking for active drivers ...
 OK, driver detached
Set up interface 0
I did not understand but tried the SetStorageDelay option with values from 0, 1, 3, 10, 20, 100, 200, 5000. It does not help. The switching does not happen while booting.
In the end of the log is a message like this

Code: Select all

Current value is higher than 3. Leave it alone

LOM
Posts: 1404
Joined: 11 Jul 2012, 15:14
Location: Koh Samui, TH

Re: Modeswitch not working while booting (Debian 11) but when re-plug the device

Post by LOM » 29 Nov 2021, 07:54

You are getting a libusb timeout error (-7) for the first two of the four eject messages and it is the first two which are essential for switching your dongle.

What happens if you do the cmd:
sudo usb_modeswitch -W -K -v 0bda -p 1a2b

after you had the switch failure when dongle is plugged in at boot? Is the dongle ready now, does it switch?

buhtz
Posts: 5
Joined: 28 Nov 2021, 16:38

Re: Modeswitch not working while booting (Debian 11) but when re-plug the device

Post by buhtz » 29 Nov 2021, 08:58

No the device is not ready then because an wlan1 does not appear.

Code: Select all

$ sudo usb_modeswitch -W -K -v 0bda -p 1a2b
[sudo] Passwort für user: 
Take all parameters from the command line


 * usb_modeswitch: handle USB devices with multiple modes
 * Version 2.6.1 (C) Josua Dietze 2017
 * Based on libusb1/libusbx

 ! PLEASE REPORT NEW CONFIGURATIONS !

DefaultVendor=  0x0bda
DefaultProduct= 0x1a2b

StandardEject=1

Look for default devices ...
  found USB ID 1d6b:0003
  found USB ID 0bda:1a2b
   vendor ID matched
   product ID matched
  found USB ID 2109:3431
  found USB ID 1d6b:0002
 Found devices in default mode (1)
Access device 003 on bus 001
Get the current device configuration ...
Current configuration number is 1
Use interface number 0
 with class 8
Use endpoints 0x0b (out) and 0x8a (in)

USB description data (for identification)
-------------------------
Manufacturer: Realtek
     Product: DISK
  Serial No.: not provided
-------------------------
Sending standard EJECT sequence
Looking for active drivers ...
Set up interface 0
Use endpoint 0x0b for message sending ...
Trying to send message 1 to endpoint 0x0b ...
 OK, message successfully sent
Read the response to message 1 (CSW) ...
 Response reading failed (error -7)
 Device is gone, skip any further commands
-> Run lsusb to note any changes. Bye!

$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
    link/ether e4:5f:01:5d:1c:b8 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DORMANT group default qlen 1000
    link/ether e4:5f:01:5d:1c:b9 brd ff:ff:ff:ff:ff:ff

LOM
Posts: 1404
Joined: 11 Jul 2012, 15:14
Location: Koh Samui, TH

Re: Modeswitch not working while booting (Debian 11) but when re-plug the device

Post by LOM » 30 Nov 2021, 04:14

Ok, since the fault condition remains once it has appeared then I guess the problem is not in usb_modeswitch so you'll have to isolate it and find what it depends on.
Does the dongle switch correctly on another host (hardware)? On another linux kernel version or another distro?

An eject sequence in usb_modeswitch consists of two pairs of messages, one for SCSI LUN#0 and one for SCSI LUN#1 (LUN#1 because a few dongles has a built in SD-card reader on LUN#0 and the virtual cd-rom, which has to be ejected, on LUN#1).
It is somewhat remarkable that your wifi dongle does not respond to the first message pair for LUN#0 (timeout) but does respond to the message pair for LUN1.
I thought about linux taking long time to read all drivers and other MS Win junk on the virtual cd-rom but if it was linux locking access to the cd-rom then the response should have been another error code, BUSY, unless the realtek firmware in the dongle is buggy..

LOM
Posts: 1404
Joined: 11 Jul 2012, 15:14
Location: Koh Samui, TH

Re: Modeswitch not working while booting (Debian 11) but when re-plug the device

Post by LOM » 30 Nov 2021, 04:59

LOM wrote: 30 Nov 2021, 04:14 unless the realtek firmware in the dongle is buggy..
I think it is, we've had this device with the same problem here previosly, see viewtopic.php?f=3&t=2989
The response from cmds to LUN#0 is weird there also.

buhtz
Posts: 5
Joined: 28 Nov 2021, 16:38

Re: Modeswitch not working while booting (Debian 11) but when re-plug the device

Post by buhtz » 15 Sep 2023, 17:12

I'm still at this problem now moved to Debian 12. Driver is compiled and installed. The USB-WLAN-Stick is working after re-plugging after boot but not while booting.

After booting

Code: Select all

Bus 001 Device 003: ID 0bda:1a2b Realtek Semiconductor Corp. RTL8188GU 802.11n WLAN Adapter (Driver CDROM Mode)
This first "call" did not work.

Code: Select all

$ sudo usb_modeswitch -W -K -v 0bda -p 1a2b
Take all parameters from the command line


 * usb_modeswitch: handle USB devices with multiple modes
 * Version 2.6.1 (C) Josua Dietze 2017
 * Based on libusb1/libusbx

 ! PLEASE REPORT NEW CONFIGURATIONS !

DefaultVendor=  0x0bda
DefaultProduct= 0x1a2b

StandardEject=1

Look for default devices ...
  found USB ID 1d6b:0003
  found USB ID 0bda:1a2b
   vendor ID matched
   product ID matched
  found USB ID 2109:3431
  found USB ID 1d6b:0002
 Found devices in default mode (1)
Access device 003 on bus 001
Get the current device configuration ...
Current configuration number is 1
Use interface number 0
 with class 8
Use endpoints 0x0b (out) and 0x8a (in)

USB description data (for identification)
-------------------------
Manufacturer: Realtek
     Product: DISK
  Serial No.: not provided
-------------------------
Sending standard EJECT sequence
Looking for active drivers ...
Set up interface 0
Use endpoint 0x0b for message sending ...
Trying to send message 1 to endpoint 0x0b ...
 OK, message successfully sent
Read the response to message 1 (CSW) ...
 Response reading failed (error -7)
 Device is gone, skip any further commands
-> Run lsusb to note any changes. Bye!
It always says

Code: Select all

Bus 001 Device 003: ID 0bda:1a2b Realtek Semiconductor Corp. RTL8188GU 802.11n WLAN Adapter (Driver CDROM Mode)
But trying it a second time

Code: Select all

$ sudo usb_modeswitch -W -K -v 0bda -p 1a2b
sudo: Hostname quark kann nicht aufgelöst werden: Temporärer Fehler bei der Namensauflösung
Take all parameters from the command line


 * usb_modeswitch: handle USB devices with multiple modes
 * Version 2.6.1 (C) Josua Dietze 2017
 * Based on libusb1/libusbx

 ! PLEASE REPORT NEW CONFIGURATIONS !

DefaultVendor=  0x0bda
DefaultProduct= 0x1a2b

StandardEject=1

Look for default devices ...
  found USB ID 1d6b:0003
  found USB ID 0bda:1a2b
   vendor ID matched
   product ID matched
  found USB ID 2109:3431
  found USB ID 1d6b:0002
 Found devices in default mode (1)
Access device 003 on bus 001
Get the current device configuration ...
Current configuration number is 1
Use interface number 0
 with class 8
Use endpoints 0x0b (out) and 0x8a (in)

USB description data (for identification)
-------------------------
Manufacturer: Realtek
     Product: DISK
  Serial No.: not provided
-------------------------
Sending standard EJECT sequence
Looking for active drivers ...
Set up interface 0
Use endpoint 0x0b for message sending ...
Trying to send message 1 to endpoint 0x0b ...
 OK, message successfully sent
Read the response to message 1 (CSW) ...
 Response successfully read (13 bytes), status 1
Trying to send message 2 to endpoint 0x0b ...
 OK, message successfully sent
Read the response to message 2 (CSW) ...
 Response successfully read (13 bytes), status 0
Trying to send message 3 to endpoint 0x0b ...
 Sending the message returned error -1. Try to continue
Read the response to message 3 (CSW) ...
 Response reading failed (error -1)
 Device is gone, skip any further commands
-> Run lsusb to note any changes. Bye!
Now it is a WLAN-Stick.

Code: Select all

Bus 001 Device 004: ID 0bda:c811 Realtek Semiconductor Corp. 802.11ac NIC
How can I automate this? Why does it happen after the second time?

Scarlett
Posts: 2
Joined: 20 Sep 2023, 17:24

Re: Modeswitch not working while booting (Debian 11) but when re-plug the device

Post by Scarlett » 20 Sep 2023, 17:28

If your modeswitch isn't working during boot on Debian 11, but it works when you re-plug the device, it could be due to timing issues during the boot process. One possible solution is to delay the modeswitch script execution during boot.

To do this, you can modify the systemd service for your modeswitch script. Here's a simple comment to add:

```shell
# Delay modeswitch until USB devices are initialized
```
youtube vanced apk
Then, you can add a `ExecStartPre` command in the systemd service file to sleep for a few seconds before running the modeswitch script:

```shell
ExecStartPre=/bin/sleep 5
```

This will pause the script execution for 5 seconds before attempting the modeswitch, giving your USB devices time to initialize properly during boot.

Sebastian
Posts: 3
Joined: 28 Oct 2023, 20:36

Re: Modeswitch not working while booting (Debian 11) but when re-plug the device

Post by Sebastian » 30 Oct 2023, 22:19

It appears that the issue may not be related to `usb_modeswitch`, as the fault condition persists even after it triggers. To isolate the problem, consider testing the dongle on different hardware, using a different Linux kernel version, or trying it on another Linux distribution.
YouTube Vanced
In an `usb_modeswitch` eject sequence, there are two pairs of messages, one for SCSI LUN#0 and one for SCSI LUN#1. It's interesting that your Wi-Fi dongle doesn't respond to the first message pair for LUN#0 but does respond to the message pair for LUN#1. This could be due to the dongle's built-in SD-card reader on LUN#0 and the virtual CD-ROM on LUN#1.

If the issue was caused by Linux taking a long time to read drivers and Windows-related data from the virtual CD-ROM, the response should have been a different error code, like BUSY. The problem might indeed be related to buggy firmware in the Realtek dongle. Further investigation and testing may be required to pinpoint the exact issue.

timothyferriss
Posts: 5
Joined: 11 Oct 2023, 09:48

Re: Modeswitch not working while booting (Debian 11) but when re-plug the device

Post by timothyferriss » 16 Nov 2023, 04:51

Make sure you have the latest version of the driver installed for the RTL8811CU chipset. Sometimes, driver updates can address compatibility issues and improve device detection and mode switching.

cookie clicker

Sebastian
Posts: 3
Joined: 28 Oct 2023, 20:36

Re: Modeswitch not working while booting (Debian 11) but when re-plug the device

Post by Sebastian » 02 Dec 2023, 07:41

If the delay were due to Linux accessing drivers and Windows-related data from the virtual CD-ROM, the response might have been a different error code, such as BUSY. It's plausible that the issue might be rooted in flawed firmware within the Realtek dongle. Pinpointing the exact problem might necessitate further investigation and testing.

rajneo
Posts: 1
Joined: 08 Jan 2024, 08:35

Re: Modeswitch not working while booting (Debian 11) but when re-plug the device

Post by rajneo » 08 Jan 2024, 08:40

Sebastian wrote: 30 Oct 2023, 22:19 It appears that the issue may not be related to `usb_modeswitch`, as the fault condition persists even after it triggers. To isolate the problem, consider testing the dongle on different hardware, using a different Linux kernel version, or trying it on another Linux distribution.
Gold WhatsApp
In an `usb_modeswitch` eject sequence, there are two pairs of messages, one for SCSI LUN#0 and one for SCSI LUN#1. It's interesting that your Wi-Fi dongle doesn't respond to the first message pair for LUN#0 but does respond to the message pair for LUN#1. This could be due to the dongle's built-in SD-card reader on LUN#0 and the virtual CD-ROM on LUN#1.

If the issue was caused by Linux taking a long time to read drivers and Windows-related data from the virtual CD-ROM, the response should have been a different error code, like BUSY. The problem might indeed be related to buggy firmware in the Realtek dongle. Further investigation and testing may be required to pinpoint the exact issue.
Thank you so much for the clarity.. Great please.!

maicleusa
Posts: 3
Joined: 25 Mar 2024, 03:32

Re: Modeswitch not working while booting (Debian 11) but when re-plug the device

Post by maicleusa » 25 Mar 2024, 03:38

You should find out the reason why the Modeswitch is not working to find a quick and thorough fix fnf so that it no longer happens like that.You should find out the reason why the Modeswitch is not working to find a quick and thorough fix so that it no longer happens like that.

Post Reply