rc.wl1251: Bring network interface down on shutdown, otherwise, drivers cannot be...
[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                 ifconfig wlan0 down
8                 rmmod board_omap3pandora_wifi wl1251_sdio wl1251 2> /dev/null
9         fi
10 }
11
12 d_start() {
13         if ! lsmod | grep -q mac80211 ; then
14                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "rfkill_backport.ko")
15                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "compat.ko")
16                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "cfg80211.ko")
17                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "mac80211.ko")
18                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "compat_firmware_class.ko")
19                 insmod $(busybox find /lib/modules/$(uname -r) -name "ecb.ko")
20                 insmod $(busybox find /lib/modules/$(uname -r) -name "pcbc.ko")
21                 insmod $(busybox find /lib/modules/$(uname -r) -name "arc4.ko")
22                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211.ko")
23                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211_crypt_tkip.ko")
24                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211_crypt_wep.ko")
25                 insmod $(busybox find /lib/modules/$(uname -r)/updates -name "lib80211_crypt_ccmp.ko")
26         fi
27         modprobe wl1251
28         modprobe wl1251_sdio
29         # this does not exist on newer kernels
30         modprobe board-omap3pandora-wifi 2> /dev/null
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