USB Auto Switch in NixOS-26.05

Hello, guys , I am using a USB network adapter. I have added this information. Is this a normal phenomenon at present?

This is the information for the USB network card, Based on online information, this USB board already exists in the kernel, and I am using the default kernel 26.05.

Bus 004 Device 002: ID 0e8d:7612 MediaTek Inc. MT7612U 802.11a/b/g/n/ac Wireless Adapter

hardware.usb-modeswitch.enable = true 

  environment.systemPackages = with pkgs; [
 usb-modeswitch-data 
];

However, this doesn’t work; you still need to manually switch each time.

[nix-shell:~]$   sudo usb_modeswitch -KW -v 0e8d -p 2870
Take all parameters from the command line


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

 ! PLEASE REPORT NEW CONFIGURATIONS !

DefaultVendor=  0x0e8d
DefaultProduct= 0x2870

StandardEject=1

Look for default devices ...
  found USB ID 1d6b:0003
  found USB ID 04f3:0c7e
  found USB ID 0e8d:2870
   vendor ID matched
   product ID matched
  found USB ID 8087:0033
  found USB ID 04f2:b73b
  found USB ID 1d6b:0002
  found USB ID 1d6b:0003
  found USB ID 1d6b:0002
 Found devices in default mode (1)
Access device 005 on bus 003
Get the current device configuration ...
Current configuration number is 1
Use interface number 0
 with class 8
Use endpoints 0x02 (out) and 0x82 (in)

USB description data (for identification)
-------------------------
Manufacturer: ?
     Product: ?
  Serial No.: ?
-------------------------
Sending standard EJECT sequence
Looking for active drivers ...
 OK, driver detached
Set up interface 0
Use endpoint 0x02 for message sending ...
Trying to send message 1 to endpoint 0x02 ...
 OK, message successfully sent
Read the response to message 1 (CSW) ...
 Response successfully read (0 bytes), status 0
Trying to send message 2 to endpoint 0x02 ...
 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 0x02 ...
 Device seems to have vanished right after sending. Good.
 Device is gone, skip any further commands
-> Run lsusb to note any changes. Bye!


[nix-shell:~]$ lsusb 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 002: ID 04f2:b73b Chicony Electronics Co., Ltd HP HD Camera
Bus 003 Device 003: ID 04f3:0c7e Elan Microelectronics Corp. ELAN:ARM-M4
Bus 003 Device 004: ID 8087:0033 Intel Corp. AX211 Bluetooth
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 004 Device 002: ID 0e8d:7612 MediaTek Inc. MT7612U 802.11a/b/g/n/ac Wireless Adapter

Anything interesting in the logs? Did you read the source code of the module that provides this option?

I don’t understand what you mean by ā€œlogā€ here. It was initially loaded as a USB storage device, but didn’t switch automatically.

I’ve reviewed the changes in this PR, but I haven’t actually read the entire source code. (What I mean is that I looked at the Makefile here using AI; I’m not familiar with this stuff, and many of the functions were guided by AI :sad_but_relieved_face:)

Well. My problem. I’ve figured it out. I misread the merge date of the PR. It first appeared in Jan, and my flake.lock was at the end of May.

In other words, it has already merged the modification information. I’ll write udev and use it for now. We’ll talk about it again in version 26-11.

1 Like