wl1251-modules: rc script: handle phy change
[openpandora.oe.git] / recipes / pandora-system / wl1251-modules / rc.wl1251
1 #!/bin/sh
2 DESC="WL1251 MAC80211 Wireless LAN driver"
3 NAME="wl1251"
4
5 d_stop() {
6         if `grep -q wl1251 /proc/modules` ; then
7                 rmmod wl1251_sdio
8                 rmmod wl1251
9                 rmmod board-omap3pandora-wifi
10         fi
11 }
12
13 d_start() {
14         if ! lsmod | grep -q mac80211 ; then
15                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "rfkill_backport.ko")
16                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "compat.ko")
17                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "cfg80211.ko")
18                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "mac80211.ko")
19                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "compat_firmware_class.ko")
20                 insmod $(busybox find /lib/modules/$(uname -r) -name "ecb.ko")
21                 insmod $(busybox find /lib/modules/$(uname -r) -name "pcbc.ko")
22                 insmod $(busybox find /lib/modules/$(uname -r) -name "arc4.ko")
23                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211.ko")
24                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211_crypt_tkip.ko")
25                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211_crypt_wep.ko")
26                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211_crypt_ccmp.ko")
27         fi
28         insmod $(busybox find /lib/modules/$(uname -r)/updates -name "wl1251.ko")
29         insmod $(busybox find /lib/modules/$(uname -r)/updates -name "wl1251_sdio.ko")
30         insmod $(busybox find /lib/modules/$(uname -r) -name "board-omap3pandora-wifi.ko")
31
32         # find our phy index, they change every time driver module is reinserted
33         # assume our interface is wlan0
34         phy_idx=0
35         for a in `seq 20` ; do
36                 if [ -e /sys/class/net/wlan0 ] ; then
37                         phy_idx=$(cat /sys/class/net/wlan0/phy80211/index)
38                         break
39                 else
40                         sleep 0.2
41                 fi
42         done
43
44         # restore phy related LED triggers (they come from mac80211.ko)
45         if [ -e /sys/class/leds/ ] ; then
46                 for led in /sys/class/leds/* ; do
47                         trigger=$(grep "$(basename $led)" /etc/default/leds | grep phy | \
48                                         awk '{print $2}' | sed -e 's/.*phy[0-9]*\(.*\)/\1/')
49                         if [ "x$trigger" != "x" ] ; then
50                                 echo "phy${phy_idx}$trigger" > "$led/trigger"
51                         fi
52                 done
53         fi
54 }
55
56 case "$1" in
57   start)
58         echo -n "Starting $DESC: $NAME"
59         d_start &
60         echo "."
61         ;;
62   stop)
63         echo -n "Stopping $DESC: $NAME"
64         d_stop
65         echo "."
66         ;;
67   restart|force-reload)
68         echo -n "Restarting $DESC: $NAME"
69         d_stop
70         sleep 1
71         d_start
72         echo "."
73         ;;
74   *)
75         echo "Usage: $0 {start|stop|restart|force-reload}" >&2
76         exit 1
77         ;;
78 esac
79
80 exit 0