3 case "$METHOD" in loopback) exit 0 ;; esac
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
11 WLANCTL=/sbin/wlanctl-ng
12 PRIV_GENERATOR=/sbin/nwepgen
14 if [ ! -x $WLANCTL ] ; then
18 # Detect and act only on linux-wlan-ng interfaces
19 if [ "$IF_WIRELESS_TYPE" != "wlan-ng" ]; then
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
30 touch /var/lock/wlan-$IFACE.lock
32 rm -f /var/lock/wlan-$IFACE.lock
36 if [ -z "$IF_WIRELESS_MODE" ]; then
37 IF_WIRELESS_MODE="ad_hoc"
40 if [ -z "$IF_WLAN_NG_HOSTWEP" ]; then
41 IF_WLAN_NG_HOSTWEP=false
44 if [ -z "$IF_WLAN_NG_DEFAULT_KEY_ID" ]; then
45 IF_WLAN_NG_DEFAULT_KEY_ID=0
48 if [ -z "$IF_WLAN_NG_EXCLUDE_UNENCRYPTED" ]; then
49 IF_WLAN_NG_EXCLUDE_UNENCRYPTED=true
52 if [ -z "$IF_WLAN_NG_PRIV_KEY128" ]; then
53 IF_WLAN_NG_PRIV_KEY128=false
56 if [ -z "$IF_WLAN_NG_BCINT" ]; then
60 if [ -z "$IF_WLAN_NG_BASICRATES" ]; then
61 IF_WLAN_NG_BASICRATES="2 4"
64 if [ -z "$IF_WLAN_NG_OPRATES" ]; then
65 IF_WLAN_NG_OPRATES="2 4 11 22"
68 if [ -z "$IF_WLAN_NG_AUTHTYPE" ]; then
69 IF_WLAN_NG_AUTHTYPE="opensystem"
72 if [ -z "$IF_WIRELESS_CHANNEL" ]; then
76 if ! modprobe p80211; then
77 echo "Failed to load p80211.o." >&2
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.
88 # Bring the card up into an operable state.
89 result=`$WLANCTL $IFACE lnxreq_ifstate ifstate=enable`
92 if [ $resultcode != "success" ]; then
93 echo "Failed to enable the device, resultcode=" $resultcode "." >&2
97 echo "Failed to enable the device, exitcode=" $? "." >&2
101 # Set user-specified MIB items.
102 for i in $IF_WLAN_NG_USER_MIBS; do
103 result=`$WLANCTL $IFACE dot11req_mibset "mibattribute=$i"`
107 if [ $resultcode != "success" ] ; then
108 echo "Failed to set user MIB $i." >&2
112 echo "Failed to set user MIB $i." >&2
117 if [ "$IF_WIRELESS_ENC" = "on" ]; then
119 result=`$WLANCTL $IFACE dot11req_mibget mibattribute=dot11PrivacyOptionImplemented`
124 echo "mibget failed." >&2
128 if [ "$dot11PrivacyOptionImplemented" != "true" ]; then
129 echo "Cannot enable privacy, dot11PrivacyOptionImplemented=$dot11PrivacyOptionImplemented." >&2
133 $WLANCTL $IFACE lnxreq_hostwep decrypt=$IF_WLAN_NG_HOSTWEP encrypt=$IF_WLAN_NG_HOSTWEP >/dev/null
135 $WLANCTL $IFACE dot11req_mibset \
136 mibattribute=dot11WEPDefaultKeyID=$IF_WLAN_NG_DEFAULT_KEY_ID \
139 $WLANCTL $IFACE dot11req_mibset \
140 mibattribute=dot11ExcludeUnencrypted=$IF_WLAN_NG_EXCLUDE_UNENCRYPTED \
143 $WLANCTL $IFACE dot11req_mibset \
144 mibattribute=dot11PrivacyInvoked=true >/dev/null
146 if [ -e "$IF_WLAN_NG_KEYFILE" ]; then
147 IF_WLAN_NG_PRIV_GENSTR=`cat $IF_WLAN_NG_KEYFILE`
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`
153 keys=`$PRIV_GENERATOR "$IF_WLAN_NG_PRIV_GENSTR" 13`
158 $WLANCTL $IFACE dot11req_mibset \
159 mibattribute=dot11WEPDefaultKey$knum=$i \
161 knum=$(expr $knum + 1)
164 $WLANCTL $IFACE dot11req_mibset \
165 mibattribute=dot11WEPDefaultKey0=$IF_WLAN_NG_KEY0 \
167 $WLANCTL $IFACE dot11req_mibset \
168 mibattribute=dot11WEPDefaultKey1=$IF_WLAN_NG_KEY1 \
170 $WLANCTL $IFACE dot11req_mibset \
171 mibattribute=dot11WEPDefaultKey2=$IF_WLAN_NG_KEY2 \
173 $WLANCTL $IFACE dot11req_mibset \
174 mibattribute=dot11WEPDefaultKey3=$IF_WLAN_NG_KEY3 \
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"
194 for i in $IF_WLAN_NG_BASICRATES; do
195 startcmd="$startcmd basicrate$j=$i"
199 for i in $IF_WLAN_NG_OPRATES; do
200 startcmd="$startcmd operationalrate$j=$i"
207 if [ $resultcode != "success" ] ; then
208 echo "IBSS not started, resultcode=$resultcode" >&2
212 echo FAILED: $startcmd >&2
216 # Infrastructure mode.
217 results=`$WLANCTL $IFACE lnxreq_autojoin \
218 "ssid=$IF_WIRELESS_ESSID" \
219 authtype=$IF_WLAN_NG_AUTHTYPE | sed 's/\([^=]*\)=\(.*\)/\1="\2"/'`
222 if [ ${resultcode:-"failure"} != "success" ]; then
223 echo 'error: Autojoin indicated failure!' >&2