-2

In my Linux distribution I use an Edimax EW-7811UTC Wi-Fi USB Adapter.

Installation of the driver rtl8812au

I have installed the driver rtl8812au from source by following steps:

  • building of the kernel module 88XXau.ko (command make) from source
  • installing it in the directory: /lib/modules/$(uname -r)/kernel/drivers/net/wireless/ (command make install)

This driver support many Wi-Fi adapter, but I need to write a script or something else to load the module 88XXau.ko only if the Wi-Fi adapter is exactly the Edimax EW-7811UTC.

The module 88XXau.ko is automatically loaded

I'd like to show 2 scenarios:

  • by the command lsmod, I have checked that at boot time if the Wifi-USB adapter is not plugged in, the module 88XXau.ko is not loaded.

  • when I plug in the WiFi-USB adapter the kernel and udev automatically load the module (I have check this by the command lsmod | grep 88XXau), but I can not find the specific udev rule which executes this loading.

I haven't written any udev rule, so in the Linux distribution must be present a default udev rule responsible of this automatic loading of the kernel module 88XXau.ko.

The problem: find the udev rule

To reach my goal that is to load the module only if the WiFi adapter is the Edimax EW-7811UTC, I need to disable the automatism so I'm here to ask if someone could show me a procedure to find the default udev rule for this driver?

Thanks

frankfalse
  • 1,553
  • 1
  • 4
  • 17
  • By the answer of @KamilCuk (see below) I have found the udev rule; so his answer - **very very synthetic** - for me is enough. But I have to disable the rule because with it, udev mounts the module 88XXau.ko every time it is plugged in a WiFi adapter that it can manage. Requirements for my projects limit the mount for only Edimax EW-7811UTC. If I remove the rule ENV{MODALIAS}=="?*", RUN{builtin}+="kmod load '$env{MODALIAS}'" I will must to find an other way to load the module. – frankfalse Jan 23 '23 at 15:46
  • 1
    So write a rule to load it only if you plug in your adapter... ? – KamilCuk Jan 23 '23 at 15:49
  • @KamilCuk thank you. Obvious and clear! When I will restart to work on this task I will open a new question about this topic but I don't know if stackoverflow is suite for this type of question. As you can see this question have been closed immediatly after I wrote it. – frankfalse Jan 23 '23 at 16:08
  • 1
    If this is usb, usually I find what are the revision:something numbers from lsusb , and create /etc/udev.d/rules file with rule with those revision:something numbers. It's very rarely that someone plugs in two exact same usb devices. Something like..... (pulls notes) `SUBSYSTEM=="usb", ATTR{idVendor}=="04d8", ATTR{idProduct}=="000b", RUN{builtin}+="kmod load '$env{MODALIAS}'"` – KamilCuk Jan 23 '23 at 16:13
  • There are so many questions already, https://unix.stackexchange.com/search?q=udev+rule+for+usb https://stackoverflow.com/search?q=udev+rule+for+usb . `this question have been closed immediatly` Stackoverflow is for _programming_, specifically. See unix.stackexchange . – KamilCuk Jan 23 '23 at 16:14

1 Answers1

1

https://www.linuxfromscratch.org/lfs/view/development/chapter09/udev.html

Device drivers compiled as modules may have aliases built into them. Aliases are visible in the output of the modinfo program and are usually related to the bus-specific identifiers of devices supported by a module. For example, the snd-fm801 driver supports PCI devices with vendor ID 0x1319 and device ID 0x0801, and has an alias of “pci:v00001319d00000801svsdbc04sc01i*”. For most devices, the bus driver exports the alias of the driver that would handle the device via sysfs. E.g., the /sys/bus/pci/devices/0000:00:0d.0/modalias file might contain the string “pci:v00001319d00000801sv00001319sd00001319bc04sc01i00”. The default rules provided with udev will cause udevd to call out to /sbin/modprobe with the contents of the MODALIAS uevent environment variable (which should be the same as the contents of the modalias file in sysfs), thus loading all modules whose aliases match this string after wildcard expansion.

https://wiki.archlinux.org/title/Modalias

$ cd /usr/lib/udev/rules.d
$ grep -r MODALIAS .
80-drivers.rules
5:ENV{MODALIAS}=="?*", RUN{builtin}+="kmod load '$env{MODALIAS}'"
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • In my yocto distribuition I have the **udev** rules file `80-drivers.rules` and inside it I have found the rule: `ENV{MODALIAS}=="?*", RUN{builtin}+="kmod load '$env{MODALIAS}'"`. But if I execute the command `kmod load 88XXau`, busybox give me an error message with the information that the sub-commands allowed are: `help, show, static-nodes`. This means that **load** is not a sub-command allowed for the command **kmod** available in my distribution. – frankfalse Sep 22 '22 at 13:02
  • https://github.com/systemd/systemd/blob/main/src/udev/udev-builtin-kmod.c#L27 Not a command, builtin. – KamilCuk Sep 22 '22 at 13:08
  • Because the file `80-drivers.rules` is the default file created by my Yocto platform is strange that it requests the execution of a command with a sintax not allowed by BusyBox.. So the load of the module **88XXau** depens on some other event? – frankfalse Sep 22 '22 at 13:18
  • `kmod` is not a command here. It's a udev builtin. It doesn't execute the command. It executes the source code I linked to. I do not understand. – KamilCuk Sep 22 '22 at 13:25
  • Kamil I am not expert on **udev** and I haven't noted that in the rule is defined `RUN{builtin}` and not `RUN`. So do you think that the module loading is executed by this rule: `ENV{MODALIAS}=="?*", RUN{builtin}+="kmod load '$env{MODALIAS}'"`? – frankfalse Sep 22 '22 at 13:38
  • Kamil I've excluded the rule `ENV{MODALIAS}=="?*", RUN{builtin}+="kmod load '$env{MODALIAS}'` from the file `80-drivers.rules` and the module stop loading when the Wifi-USB adapter is plugged in. If I add the rule again, the module is again automatically loaded. Thanks very much. – frankfalse Sep 22 '22 at 14:17
  • 1
    (Off-topic, will delete this comment. Would you consider undeleting [this answer](https://stackoverflow.com/a/73811481)? The OP was a bit rude, but your answer was very good - the question was deleted and mod undeleted, and your answer looks like it would be worth keeping). – halfer Sep 23 '22 at 10:10