]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/wlan-ng/files/pre-up
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / wlan-ng / files / pre-up
1 #!/bin/sh
2
3 case "$METHOD" in loopback) exit 0 ;; esac
4
5 #
6 # This script takes care of bringing up wlan-ng device.
7 # It is run by ifup, and gets information from the 
8 # /etc/network/interfaces file. It is derived from the
9 # init.d/wlan script in the wlan-ng distribution 
10
11 WLANCTL=/sbin/wlanctl-ng
12 PRIV_GENERATOR=/sbin/nwepgen
13
14 if [ ! -x $WLANCTL ] ; then 
15         exit 0
16 fi
17
18 # Detect and act only on linux-wlan-ng interfaces
19 if [ "$IF_WIRELESS_TYPE" != "wlan-ng" ]; then
20   exit 0
21 fi
22
23 # Create a lock file; remove on script exit. This is a fairly crummy lock,
24 # but all it needs to do is prevent hotplug from calling this script,
25 # which may happen when the module is loaded below. Since it should only
26 # happen when the module is loaded, I don't need a proper lock.
27 if [ -e /var/lock/wlan-$IFACE.lock ]; then
28         exit 0
29 fi
30 touch /var/lock/wlan-$IFACE.lock
31 cleanup () {
32         rm -f /var/lock/wlan-$IFACE.lock
33 }
34 trap cleanup 0
35
36 if [ -z "$IF_WIRELESS_MODE" ]; then
37         IF_WIRELESS_MODE="ad_hoc"
38 fi
39
40 if [ -z "$IF_WLAN_NG_HOSTWEP" ]; then
41         IF_WLAN_NG_HOSTWEP=false
42 fi
43
44 if [ -z "$IF_WLAN_NG_DEFAULT_KEY_ID" ]; then
45         IF_WLAN_NG_DEFAULT_KEY_ID=0
46 fi
47
48 if [ -z "$IF_WLAN_NG_EXCLUDE_UNENCRYPTED" ]; then
49         IF_WLAN_NG_EXCLUDE_UNENCRYPTED=true
50 fi
51
52 if [ -z "$IF_WLAN_NG_PRIV_KEY128" ]; then
53         IF_WLAN_NG_PRIV_KEY128=false
54 fi
55
56 if [ -z "$IF_WLAN_NG_BCINT" ]; then
57         IF_WLAN_NG_BCINT=100
58 fi
59
60 if [ -z "$IF_WLAN_NG_BASICRATES" ]; then
61         IF_WLAN_NG_BASICRATES="2 4"
62 fi
63
64 if [ -z "$IF_WLAN_NG_OPRATES" ]; then
65         IF_WLAN_NG_OPRATES="2 4 11 22"
66 fi
67
68 if [ -z "$IF_WLAN_NG_AUTHTYPE" ]; then
69         IF_WLAN_NG_AUTHTYPE="opensystem"
70 fi
71
72 if [ -z "$IF_WIRELESS_CHANNEL" ]; then
73         IF_WIRELESS_CHANNEL=1
74 fi
75
76 if ! modprobe p80211; then
77         echo "Failed to load p80211.o." >&2
78         exit 1
79 fi
80
81 # NOTE: We don't explicitly insmod the card driver here.  The
82 #  best thing to do is to specify an alias in /etc/modules.conf.
83 #  Then, the first time we call wlanctl with the named device,
84 #  the kernel module autoload stuff will take over.
85 #  But, if you prefer, you could modprobe it here.
86
87
88 # Bring the card up into an operable state.
89 result=`$WLANCTL $IFACE lnxreq_ifstate ifstate=enable`
90 if [ $? = 0 ] ; then
91         eval $result
92         if [ $resultcode != "success" ]; then
93                 echo "Failed to enable the device, resultcode=" $resultcode "." >&2
94                 exit 1
95         fi
96 else
97         echo "Failed to enable the device, exitcode=" $? "." >&2
98         exit 1
99 fi
100
101 # Set user-specified MIB items.
102 for i in $IF_WLAN_NG_USER_MIBS; do
103         result=`$WLANCTL $IFACE dot11req_mibset "mibattribute=$i"`
104
105         if [ $? = 0 ] ; then
106                 eval $result
107                 if [ $resultcode != "success" ] ; then
108                         echo "Failed to set user MIB $i." >&2
109                         exit 1
110                 fi
111         else
112                 echo "Failed to set user MIB $i." >&2
113                 exit 1
114         fi
115 done
116
117 if [ "$IF_WIRELESS_ENC" = "on" ]; then
118         # Set up WEP.
119         result=`$WLANCTL $IFACE dot11req_mibget mibattribute=dot11PrivacyOptionImplemented`
120         if [ $? = 0 ] ; then
121                 eval $result
122                 eval $mibattribute
123         else
124                 echo "mibget failed." >&2
125                 exit 1
126         fi
127         
128         if [ "$dot11PrivacyOptionImplemented" != "true" ]; then
129                 echo "Cannot enable privacy, dot11PrivacyOptionImplemented=$dot11PrivacyOptionImplemented." >&2
130                 exit 1
131         fi
132
133         $WLANCTL $IFACE lnxreq_hostwep decrypt=$IF_WLAN_NG_HOSTWEP encrypt=$IF_WLAN_NG_HOSTWEP >/dev/null
134         
135         $WLANCTL $IFACE dot11req_mibset \
136                 mibattribute=dot11WEPDefaultKeyID=$IF_WLAN_NG_DEFAULT_KEY_ID \
137              >/dev/null
138         
139         $WLANCTL $IFACE dot11req_mibset \
140                 mibattribute=dot11ExcludeUnencrypted=$IF_WLAN_NG_EXCLUDE_UNENCRYPTED \
141             >/dev/null
142
143         $WLANCTL $IFACE dot11req_mibset \
144                 mibattribute=dot11PrivacyInvoked=true >/dev/null
145
146         if [ -e "$IF_WLAN_NG_KEYFILE" ]; then
147                 IF_WLAN_NG_PRIV_GENSTR=`cat $IF_WLAN_NG_KEYFILE`
148         fi
149         if [ ! -z "$IF_WLAN_NG_PRIV_GENSTR" ]; then
150                 if [ "$IF_WLAN_NG_PRIV_KEY128" = "false" ]; then
151                         keys=`$PRIV_GENERATOR "$IF_WLAN_NG_PRIV_GENSTR" 5`
152                 else
153                         keys=`$PRIV_GENERATOR "$IF_WLAN_NG_PRIV_GENSTR" 13`
154                 fi
155
156                 knum=0
157                 for i in $keys; do
158                         $WLANCTL $IFACE dot11req_mibset \
159                                 mibattribute=dot11WEPDefaultKey$knum=$i \
160                              >/dev/null
161                         knum=$(expr $knum + 1)
162                 done
163         else
164                 $WLANCTL $IFACE dot11req_mibset \
165                         mibattribute=dot11WEPDefaultKey0=$IF_WLAN_NG_KEY0 \
166                      >/dev/null
167                 $WLANCTL $IFACE dot11req_mibset \
168                         mibattribute=dot11WEPDefaultKey1=$IF_WLAN_NG_KEY1 \
169                      >/dev/null
170                 $WLANCTL $IFACE dot11req_mibset \
171                         mibattribute=dot11WEPDefaultKey2=$IF_WLAN_NG_KEY2 \
172                      >/dev/null
173                 $WLANCTL $IFACE dot11req_mibset \
174                         mibattribute=dot11WEPDefaultKey3=$IF_WLAN_NG_KEY3 \
175                      >/dev/null
176         fi
177 fi
178         
179 # MAC startup
180 if [ "$IF_WIRELESS_MODE" = "ad_hoc" ] || 
181    [ "$IF_WIRELESS_MODE" = "ad-hoc" ]; then
182         startcmd="$WLANCTL $IFACE dot11req_start "
183         startcmd="$startcmd ssid=$IF_WIRELESS_ESSID"
184         startcmd="$startcmd bsstype=independent"
185         startcmd="$startcmd beaconperiod=$IF_WLAN_NG_BCINT"
186         startcmd="$startcmd dtimperiod=3"
187         startcmd="$startcmd cfpollable=false"
188         startcmd="$startcmd cfpollreq=false"
189         startcmd="$startcmd cfpperiod=3"
190         startcmd="$startcmd cfpmaxduration=100"
191         startcmd="$startcmd probedelay=100"
192         startcmd="$startcmd dschannel=$IF_WIRELESS_CHANNEL"
193         j=1
194         for i in $IF_WLAN_NG_BASICRATES; do
195                 startcmd="$startcmd basicrate$j=$i"
196                 j=$(expr $j + 1)
197         done
198         j=1
199         for i in $IF_WLAN_NG_OPRATES; do
200                 startcmd="$startcmd operationalrate$j=$i"
201                 j=$(expr $j + 1)
202         done
203
204         results=`$startcmd`
205         if [ $? = 0 ]; then 
206                 eval $results
207                 if [ $resultcode != "success" ] ; then
208                         echo "IBSS not started, resultcode=$resultcode" >&2
209                         exit 1
210                 fi
211         else
212                 echo FAILED: $startcmd >&2
213                 exit 1
214         fi
215 else
216         # Infrastructure mode.
217         results=`$WLANCTL $IFACE lnxreq_autojoin \
218                 "ssid=$IF_WIRELESS_ESSID" \
219                 authtype=$IF_WLAN_NG_AUTHTYPE | sed 's/\([^=]*\)=\(.*\)/\1="\2"/'`
220         if [ $? = 0 ]; then
221                 eval $results
222                 if [ ${resultcode:-"failure"} != "success" ]; then
223                         echo 'error: Autojoin indicated failure!' >&2
224                         exit 1
225                 fi
226         fi
227 fi