1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
|
#!/bin/bash
#########################################
# start_net script #
# acx100 project #
# acx100.sourceforge.net #
# edited by arnie <urnotwelcome@gmx.de> #
#########################################
# with modifications by craig #
# summary at end of file #
#########################################
# Please edit below
# syntax is: VARIABLENAME=VALUE, with _no_ spaces in between
# make sure to _preserve_ any double-quotes (")
# text beginning with the comment delimiter (#) is ignored
# make sure to _preserve_ at least one space before any
# comment delimiters (#) that do not begin a line
# "uncommenting" a line means to remove it's leading "#" character
ESSID="network_down" # THIS IS CASE SeNsItIvE!! any == associate to any ESSID
# Default rate configured as 11Mbps to not cause speed problems (while
# using auto rate) or connection problems (while not using auto rate)
# with non-22Mbps hardware...
RATE=11M
AUTORATE=1 # only disable auto rate if you know what you're doing...
CHAN=1 # it's useful to try to stick to channels 1, 6 or 11 only, since these don't overlap with other channels
#SHORTPREAMBLE=1 # set a value of 1 in order to force "Short Preamble" (incompatible with very old WLAN hardware!) instead of peer autodetect
#TXPOWER=20 # 0..20 (dBm) (18dBm is firmware default) overly large setting might perhaps destroy your radio eventually!
MODE=Managed # Managed for infrastructure, Ad-hoc for peer-to-peer. NOTE: Auto mode is not supported any more, you HAVE to select a specific mode!
DEBUG=0xb # 0xffff for maximum debug info, 0 for none
# WEP Key(s)
# ascii keys (passphrase) should look like this: KEY="s:asciikey"
# hex keys should look like this: KEY="4378c2f43a"
# most wep users will want to use this line
KEY=""
# alternatively, you can uncomment and use these lines to
# set all 4 possible WEP keys
#KEY1="1234567890" #WEP64
#KEY2="1234567890"
#KEY3="1234567890"
#KEY4="1234567890"
# you must select which of the 4 keys above to use here:
#KEY="[1]" # for KEY1, "[2]" for KEY2, etc
ALG=open # open == Open System, restricted == Shared Key
#IP address
USE_DHCP=0 # set to 1 for auto configuration instead of fixed IP setting
IP=192.168.1.98 # set this if you did not set USE_DHCP=1
NETMASK=255.255.255.0 # set this if you did not set USE_DHCP=1
GATEWAY=192.168.1.254 # set this if you did not set USE_DHCP=1
LED_OFF=1 # set to 1 to turn off the power LED to save power
MTU_576=0 # set to 1 if you have buffer management problems
# DO NOT EDIT BELOW THIS LINE
##################################################################
if test "$UID" != "0"; then echo "You are not root. To insert the module into your kernel, you need to be root. Enter su and try again. Bailing..."; exit 1; fi
SYNC=`which sync`
INSMOD=`which insmod`
MODPROBE=`which modprobe`
IFCONF=`which ifconfig`
IWCONF=`which iwconfig`
IWPRIV=`which iwpriv`
ROUTE=`which route`
SCRIPT_AT=`dirname $0`
# while we check for all 3, we run them in this
# "preferred" order: dhcpcd, pump, dhclient
# so if more than one exists it's ok
which dhcpcd &> /dev/null
if [ $? -eq 0 ]; then DHCPCD=`which dhcpcd`; fi
which pump &> /dev/null
if [ $? -eq 0 ]; then PUMP=`which pump`; fi
which dhclient &> /dev/null
if [ $? -eq 0 ]; then DHCLIENT=`which dhclient`; fi
if test -z "$SYNC"; then echo "sync not found. Go get a sane Linux system. Bailing..."; exit 1; fi
if test -z "$INSMOD"; then echo "insmod not found. Go get a sane Linux system. Bailing..."; exit 1; fi
if test -z "$IFCONF"; then echo "ifconfig not found. I can insert the module for you, but you won't be able to configure your interface."; CONTINUE=ASK; fi
if test -z "$IWCONF"; then echo "iwconfig not found. Make sure it is installed. The interface might work without, though."; CONTINUE=ASK; fi
if test -n "$CONTINUE"; then echo -n "Problems encountered. Do you want to continue? [n] "; read ANSWER
case $ANSWER in ( y | Y | Yes | YES | yes | j | J | ja | Ja | JA ) ;;
( * ) exit 1 ;;
esac
fi
case "`uname -r`" in
2.4*)
MODULE_AT="${SCRIPT_AT}/../src/acx_pci.o"
;;
*)
MODULE_AT="${SCRIPT_AT}/../src/acx_pci.ko"
;;
esac
if test ! -r "$MODULE_AT"; then echo "Module not found or not readable.
Have you built it? This script expects it to be at ../src/acx_pci.[k]o, relative to the script's location. Bailing..."; exit 1; fi
# check whether any file name of the required main firmware file is
# available in the acx100/firmware or global firmware directory
# FIRMWARE_AT has to be given as an absolute path!!
for FIRMWARE_AT in "${SCRIPT_AT}/../firmware" "/usr/share/acx"; do
for FW_FILE in WLANGEN.BIN TIACX111.BIN FwRad16.bin FW1130.BIN; do
if test -r "$FIRMWARE_AT/$FW_FILE"; then
#echo A firmware file has been found at "$FIRMWARE_AT/$FW_FILE"
FW_FOUND=1
break 2
fi
done
done
if test "$FW_FOUND" != "1"; then
echo "Firmware not found or not readable. Have you placed it in the firmware directory or run make extract_firmware once? This script expects it to be either at ../firmware/WLANGEN.BIN (or ../firmware/TIACX111.BIN for the ACX111 chip), relative to the script's location, OR have you placed it in the default directory:/usr/share/acx?. Bailing...";
exit 1;
fi
if test $AUTORATE != "1"; then
if test "$RATE" != "11M"; then echo "Transfer rate is not set to 11
Mbps, but $RATE (and not using auto rate either). If something doesn't work, try 11 Mbps or auto rate."; fi
fi
test "$AUTORATE" = "1" && AUTO=auto || AUTO=
# for better debugging
# set -x
#echo 8 > /proc/sys/kernel/printk
# just in case ;)
$SYNC
sleep 1
DEV=wlan0 # this may become wlan1, wlan2, etc depending on if any other wlanX devices are found
if test -n "`lsmod | grep acx_pci`"; then ${SCRIPT_AT}/stop_net;fi
# now that the interface is "down", let's also check for and remove
# those *really* old modules that might be supplied with some distributions
lsmod | grep acx100_pci &> /dev/null
if test "$?" = "0"; then
rmmod acx100_pci;
echo "NOTICE: Found a very old version of the driver loaded (acx100_pci), removing."
# we could also add the old module's name to the blacklist, though this
# only benefits hotplug devices and might be considered invasive
# echo acx100_pci >> /etc/hotplug/blacklist
fi
# before inserting the module, let's check for the presence of existing wlan devices
# and if necessary, adjust our $DEV variable to be wlan1, wlan2, etc.
# these could be other wireless drivers' devs, or the device created by acx_usb
MAX_WLANS=9 # failsafe break counter
while true
do
# at this point $DEV is always "wlan0"
$IFCONF $DEV &> /dev/null
if test "$?" = "0"; then
echo -n "$DEV exists, "
DIGIT=`echo $DEV | cut -d 'n' -f 2`
DIGIT=`expr $DIGIT + 1`
DEV="wlan${DIGIT}"
echo -n "trying $DEV..."
else
echo "using $DEV."
break
fi
# failsafe break
if test $MAX_WLANS -eq 0; then break;fi
MAX_WLANS=`expr $MAX_WLANS - 1`
done
$MODPROBE -q firmware_class # Linux 2.6.x hotplug firmware loading support
$INSMOD $MODULE_AT debug=$DEBUG firmware_dir=$FIRMWARE_AT
if test "$?" = "0"; then echo "Module successfully inserted."; else echo "Error while inserting module! Bailing..."; exit 1; fi
# before we get too involved in trying to setup $DEV, let's verify that it exists
$IFCONF $DEV &> /dev/null
if test "$?" = "0"; then # $DEV exists
if test -n "$IWCONF"; then
if test -n "$RATE"; then
echo Setting rate to $RATE $AUTO.
$IWCONF $DEV rate $RATE $AUTO
test "$?" != "0" && echo Failed.
fi
if test -n "$CHAN"; then
echo Setting channel $CHAN.
$IWCONF $DEV channel $CHAN
test "$?" != "0" && echo Failed.
fi
if test -n "$SHORTPREAMBLE"; then
echo Setting short preamble to $SHORTPREAMBLE.
$IWPRIV $DEV SetSPreamble $SHORTPREAMBLE
test "$?" != "0" && echo Failed.
sleep 1
fi
if test -n "$TXPOWER"; then
echo Setting Tx power level to $TXPOWER dBm.
$IWCONF $DEV txpower $TXPOWER
test "$?" != "0" && echo Failed.
sleep 1
fi
echo Going to try to join or setup ESSID $ESSID.
$IWCONF $DEV essid "$ESSID"
test "$?" != "0" && echo Failed.
if test -n "$MODE"; then
echo Setting mode to $MODE.
$IWCONF $DEV mode $MODE
test "$?" != "0" && echo Failed.
fi
if test -n "$KEY1"; then
echo Setting key 1 to $KEY1, algorithm $ALG.
$IWCONF $DEV key $ALG "$KEY1" [1]
test "$?" != "0" && echo Failed.
fi
if test -n "$KEY2"; then
echo Setting key 2 to $KEY2, algorithm $ALG.
$IWCONF $DEV key $ALG "$KEY2" [2]
test "$?" != "0" && echo Failed.
fi
if test -n "$KEY3"; then
echo Setting key 3 to $KEY3, algorithm $ALG.
$IWCONF $DEV key $ALG "$KEY3" [3]
test "$?" != "0" && echo Failed.
fi
if test -n "$KEY4"; then
echo Setting key 4 to $KEY4, algorithm $ALG.
$IWCONF $DEV key $ALG "$KEY4" [4]
test "$?" != "0" && echo Failed.
fi
# this is now placed after the "KEY%D" stuff
# to support the "KEY=[1]" option
if test -n "$KEY"; then
echo Setting key to $KEY, algorithm $ALG.
$IWCONF $DEV key "$KEY" $ALG
test "$?" != "0" && echo Failed.
fi
fi # end "if found(iwconfig)"
# for notebook use - a power LED is sooo useless anyway ;-))
if test "$LED_OFF" -eq 1; then
test -n "$IWPRIV" && "$IWPRIV" $DEV SetLEDPower 0
echo Setting power LED to off.
fi
# It shouldn't hurt to bring the device up, and dhcp seems to like it that way
$IFCONF $DEV up
sleep 1
# if they want dhcp or they've set to managed mode, then we
# take up to 10 seconds to wait for something to show up
# in iwconfig besides zeros, we don't want to give the user
# the wrong impression re: success/failure and mainly we don't
# want to bother with a dhcp attempt without association
# we could also use /proc/driver/acx_$DEV instead ??
# check MODE for some form of the word "managed", case-insensitive
echo $MODE | grep -ic managed &> /dev/null
if test "$?" = "0" -o $USE_DHCP -eq 1; then # begin test for association
WAIT_ASSOC=10
echo -n "Waiting for association..."
while true
do
echo -n "$WAIT_ASSOC "
if test "`$IWCONF $DEV | grep -c 00:00:00:00:00:00`" = "0"; then
echo "OK."
# ok, have association, now verify that the card associated with
# the desired AP, it could easily have found a stray linksys instead ;^}
if test -n "$ESSID"; then
echo "$ESSID" | grep -ic any &> /dev/null # don't bother checking "essid=any"
if test "$?" = "0" -a "`$IWCONF $DEV | grep -c $ESSID`" = "0"; then
echo "NOTICE: $DEV associated, but NOT with $ESSID!"
fi
fi
break
fi
WAIT_ASSOC=`expr $WAIT_ASSOC - 1`
if test "$WAIT_ASSOC" = "0"; then
echo FAILED.
# if they wanted dhcp, tell them the bad news
if test $USE_DHCP -eq 1; then
echo "Error: $DEV failed to associate, can't use DHCP for IP address."
USE_DHCP=0;
fi
break
fi
# we *could* issue an iwconfig here at the end of each loop:
# $IWCONF $DEV essid $ESSID
# I'm not sure if it would help or hinder...it isn't necessary w/my hardware
sleep 1 # give it a second
done
fi # end test for association, if mode=managed or USE_DHCP=1
if test $USE_DHCP -eq 1; then
# now we fetch an IP address from DHCP
# first, try dhcpcd:
if test -n "$DHCPCD"; then
echo -n "Attempting to use $DHCPCD for DHCP, this may take a moment..."
rm -f /etc/dhcpc/dhcpcd-$DEV.pid > /dev/null
$DHCPCD -d $DEV -t 5 &> /dev/null
if test "$?" = "0"; then
echo "OK."
echo "Interface has been set up successfully.";
else echo "FAILED"
fi
# no dhcpcd was found, next we try pump:
elif test -n "$PUMP"; then
echo -n "Attempting to use $PUMP for DHCP, this may take a moment..."
$PUMP -i $DEV &> /dev/null
if test "$?" = "0"; then
echo "OK."
echo "Interface has been set up successfully.";
else echo "FAILED"
fi
# no dhcpcd or pump was found, finally we try dhclient;
elif test -n "$DHCLIENT"; then
echo -n "Attempting to use $DHCLIENT for DHCP, this may take a moment..."
rm -f /var/run/dhclient.pid
$DHCLIENT $DEV &> /dev/null
if test "$?" = "0"; then
echo "OK."
echo "Interface has been set up successfully.";
else echo "FAILED"
fi
else # dhcpcd, pump, and dhclient not found, inform user and bail
echo "ERROR: USE_DHCP=1 , but no dhcp clients could be found"
echo "Bailing..."
exit 1;
fi #end check for usable dhcp client
else # wants manual config
# Hehe, this can be done after iwconfigs now :)
$IFCONF $DEV $IP netmask $NETMASK
if test "$?" != "0"; then
echo "Error in \"$IFCONF $DEV $IP netmask $NETMASK\". Bailing..."; exit 1;
else
echo "Interface has been set up successfully.";
test -n "$GATEWAY" && $ROUTE add default gw $GATEWAY $DEV
fi
fi # end if USE_DHCP=1
# ugly workaround for buffer management problems
if test "$MTU_576" -eq 1; then
echo "Setting mtu down to 576. NOTE that e.g. IPv6 would need >= 1280, so make sure you're doing the right thing here!"
test -n "$IFCONF" && "$IFCONF" $DEV mtu 576
if test "$?" != "0"; then echo "Error in \"$IFCONF $DEV mtu 576\". Bailing..."; exit 1; fi
fi
else # $DEV is not found by ifconfig
echo "Error: Failed to create device: $DEV...bailing."
exit 1;
fi # end test for $DEV exists
# just in case ;)
$SYNC
##############################################################
# summary of craig's changes to pf33's start_net:
# added SET_LED and MTU_576 vars, moved DEV below the do-not-edit line
# changed KEY0-KEY3 vars to KEY1-KEY4 to match iwconfig's scheme
# added a line for selecting a numbered key eg: "KEY=[1]"
# moved setting wep key to last in the order for above to work
# added attempt to automagically find/use a dhcp client
# added checking for firmware in /usr/share/acx before bailing
# check for and unload the old acx100_pci module if present
# don't assume $DEV is going to always be wlan0 (needs more work)
# don't assume that $DEV exists, even after a successful module load
# if MODE=managed || USE_DHCP=1, wait for association
# upon assoc, test for correct SSID if one was specified
# added $DEV to route add default gw command
##############################################################
# end of file
|