How to trigger a script when USB WLAN stick is plugged in?

Hi,

I’ve got a problem with my Netgear WG111v2 WLAN USB stick and openSUSE 11.0 on my notebook. The notebook has an internal rt2500pci WLAN device, but the reception of this card is quite poor. So I use the USB stick when I need a stable connection. I compiled and installed the driver aircrack-ng.org (module r8187), which allows to manually increase the transmission power. The original rtl8187 is blacklisted.

When I manually connect to a network using iwconfig everything works fine, but when I connect via the Gnome NetworkManager the default connection speed is set to 1 Mb/s even when sitting right next to the AP. So I always have to open up a terminal and set the rate to 54M via iwconfig.

So far I didn’t find a way to automate this. All I need is that “iwconfig wlan2 rate 54M” is executed as soon as the stick is plugged in. How can I do that?

[EDIT] I was wondering if there was a more general way to achieve this, some kind of mechanism that I could also use to trigger some action when a particular USB memory stick is inserted, e.g. Nevertheless, if there was a way to fine-tune NetworkManager, I’d be happy, too :slight_smile:

Thanks for your help!

You should be able to create a rule in /etc/udev for your NIC.
You may have to test this a bit to get it working. Here’s a site referencing udev rule writing - Writing udev rules

Here’s their NIC example
**Network interfaces

Even though they are referenced by names, network interfaces typically do not have device nodes associated with them. Despite that, the rule writing process is almost identical.

It makes sense to simply match the MAC address of your interface in the rule, as this is unique. However, make sure that you use the exact MAC address as shown as udevinfo, because if you do not match the case exactly, your rule will not work.

udevinfo -a -p /sys/class/net/eth0

looking at class device ‘/sys/class/net/eth0’:
KERNEL==“eth0”
ATTR{address}==“00:52:8b:d5:04:48”
Here is my rule:

KERNEL==“eth*”, ATTR{address}==“00:52:8b:d5:04:48”, NAME=“lan”
You will need to reload the net driver for this rule to take effect. You can either unload and reload the module, or simply reboot the system. You will also need to reconfigure your system to use “lan” rather than “eth0”. I had some troubles getting this going (the interface wasn’t being renamed) until I had completely dropped all references to eth0. After that, you should be able to use “lan” instead of “eth0” in any calls to ifconfig or similar utilities.**

So, I’m guessing you could do something like this…


 looking at class device '/sys/class/net/wlan0':    (adapting this to your system, of course)
 iwconfig wlan2 rate 54M

Honestly, that’s a pretty wild guess on my part, but hopefully it points you in the right direction.

Updated this to be more accurate. The last attempt was very bad.


looking at class device '/sys/class/net/wlan2':    (adapting this to your system, of course)
 KERNEL=="wlan2", ATTR{address}=="00:52:8b:d5:04:48", RUN+="/usr/bin/adjust_speed"   (put your mac address)  (put your command in a script iwconfig wlan2 rate 54M, and make sure it's executable)