wl1251-modules: rc script: handle phy change
[openpandora.oe.git] / recipes / pandora-system / wl1251-modules / rc.wl1251
index 5018c6b..d1834e1 100755 (executable)
@@ -11,29 +11,43 @@ d_stop() {
 }
 
 d_start() {
-       insmod $(busybox find /lib/modules/$(uname -r)/updates -name "rfkill_backport.ko")
-        insmod $(busybox find /lib/modules/$(uname -r)/updates -name "compat.ko")
-        insmod $(busybox find /lib/modules/$(uname -r)/updates -name "cfg80211.ko")
-       insmod $(busybox find /lib/modules/$(uname -r)/updates -name "mac80211.ko")
-        insmod $(busybox find /lib/modules/$(uname -r)/updates -name "compat_firmware_class.ko")
-        insmod $(busybox find /lib/modules/$(uname -r) -name "ecb.ko")
-       insmod $(busybox find /lib/modules/$(uname -r) -name "pcbc.ko")
-        insmod $(busybox find /lib/modules/$(uname -r) -name "arc4.ko")
-       insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211.ko")
-       insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211_crypt_tkip.ko")
-       insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211_crypt_wep.ko")
-       insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211_crypt_ccmp.ko")
+       if ! lsmod | grep -q mac80211 ; then
+               insmod $(busybox find /lib/modules/$(uname -r)/updates -name "rfkill_backport.ko")
+               insmod $(busybox find /lib/modules/$(uname -r)/updates -name "compat.ko")
+               insmod $(busybox find /lib/modules/$(uname -r)/updates -name "cfg80211.ko")
+               insmod $(busybox find /lib/modules/$(uname -r)/updates -name "mac80211.ko")
+               insmod $(busybox find /lib/modules/$(uname -r)/updates -name "compat_firmware_class.ko")
+               insmod $(busybox find /lib/modules/$(uname -r) -name "ecb.ko")
+               insmod $(busybox find /lib/modules/$(uname -r) -name "pcbc.ko")
+               insmod $(busybox find /lib/modules/$(uname -r) -name "arc4.ko")
+               insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211.ko")
+               insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211_crypt_tkip.ko")
+               insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211_crypt_wep.ko")
+               insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211_crypt_ccmp.ko")
+       fi
        insmod $(busybox find /lib/modules/$(uname -r)/updates -name "wl1251.ko")
        insmod $(busybox find /lib/modules/$(uname -r)/updates -name "wl1251_sdio.ko")
        insmod $(busybox find /lib/modules/$(uname -r) -name "board-omap3pandora-wifi.ko")
 
-       # restore phyX related LED triggers (they come from mac80211.ko)
-       sleep 0.5
+       # find our phy index, they change every time driver module is reinserted
+       # assume our interface is wlan0
+       phy_idx=0
+       for a in `seq 20` ; do
+               if [ -e /sys/class/net/wlan0 ] ; then
+                       phy_idx=$(cat /sys/class/net/wlan0/phy80211/index)
+                       break
+               else
+                       sleep 0.2
+               fi
+       done
+
+       # restore phy related LED triggers (they come from mac80211.ko)
        if [ -e /sys/class/leds/ ] ; then
                for led in /sys/class/leds/* ; do
-                       trigger=$(grep "$(basename $led)" /etc/default/leds | grep "phy" | awk '{print $2}')
+                       trigger=$(grep "$(basename $led)" /etc/default/leds | grep phy | \
+                                       awk '{print $2}' | sed -e 's/.*phy[0-9]*\(.*\)/\1/')
                        if [ "x$trigger" != "x" ] ; then
-                               echo "$trigger" > "$led/trigger"
+                               echo "phy${phy_idx}$trigger" > "$led/trigger"
                        fi
                done
        fi