On Wed, 13 Oct 2010, Christiano F. Haesbaert wrote: > From: Christiano F. Haesbaert <[email protected]> > To: OpenBSD Questions <[email protected]> > Date: Wed, 13 Oct 2010 17:17:16 > Subject: Re: Wireless Network GUI > > I use this silly script for wireless if someone is interested: > > http://github.com/haesbaert/scripts/blob/master/wifi
Pau Amaro-Seoane's wifiprobe script, posted to this mailing list in 2007, is useful. See: http://marc.info/?l=openbsd-misc&m=119442609818795&w=2 http://marc.info/?l=openbsd-misc&m=119611252029773&w=2 Also see the undeadly article from D. Adam Karin: http://undeadly.org/cgi?action=article&sid=20071224164233 which is shows a useful method of connecting to known wireless networks at boot time. Here at work I can often see several available wireless connection points. So I've tweaked the above script to connect to the one with the strongest signal. Here's what I've run on my venerable T23 Thinkpad running OpenBSD4.7. It's a shell archive. Note you'll need to make the /etc/rc.wireless script executable. # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # netstart.diffs # rc.wireless # rc.wireless.conf # echo x - netstart.diffs sed 's/^X//' >netstart.diffs << 'END-of-netstart.diffs' X--- netstart.orig Thu Mar 18 02:31:37 2010 X+++ netstart Tue Aug 31 12:42:08 2010 X@@ -174,6 +174,12 @@ X # Re-read /etc/rc.conf X . /etc/rc.conf X X+# Wireless configuration, if present and known. X+if [ -f /etc/rc.wireless -a -x /etc/rc.wireless \ X+ -a X"$1" = X"autoboot" ] ; then X+ /etc/rc.wireless X+fi X+ X # If we were invoked with a list of interface names, just reconfigure these X # interfaces (or bridges) and return. X if [ $1x = autobootx ]; then END-of-netstart.diffs echo x - rc.wireless sed 's/^X//' >rc.wireless << 'END-of-rc.wireless' X#!/bin/sh X X# This script is executed by /etc/netstart when booting. It X# does the following: X# X# (1) extracts wifi card & DHCP parameters from X# /etc/rc.wireless.conf X# X# (2) Performs a wifi scan looking for available wireless networks X# X# (3) Compares available wireless networks with those preconfigured X# in /etc/rc.wireless.conf X# X# (4) Stores the details for any known network in /etc/hostname.if. X# If there's more than one network, the one with the strongest X# signal is chosen. X# X# This script can also be used in "stand-alone" mode, X# "/etc/rc.wireless" followed by "sh /etc/netstart {interface-name}". X# So for removable wifi devices this script could form part of a X# hotplugd script to connect to known wifi networks. X XIFS=' X' X X# Commands we'll use. Xcp=/bin/cp Xecho=/bin/echo Xifconfig=/sbin/ifconfig Xmktemp=/usr/bin/mktemp Xrm=/bin/rm Xsed=/usr/bin/sed Xsort=/usr/bin/sort X X# Make sure we have a configuration file... XCONF=/etc/rc.wireless.conf X[ -r $CONF ] || exit 1 X X# ...that contains an interface name... XIFNAME=$($sed -ne 's/^#wifi[[:space:]]IFNAME=\(.*\)$/\1/p' $CONF) X[ -n "$IFNAME" ] || exit 1 X X# ...that's plugged in. X$ifconfig $IFNAME > /dev/null 2>&1 || exit 1 X X# Reset the wifi device if there's a command to do this. XRESET=$($sed -ne 's/^#wifi[[:space:]]RESET=\(.*\)$/\1/p' $CONF) X[ -n "$RESET" ] && { $ifconfig $IFNAME $RESET > /dev/null 2>&1; } X X# If present, note the wifi device's MAC address. It isn't crucial X# that we have this. XMAC_ADDR=$($sed -ne 's/^#wifi[[:space:]]MAC_ADDR=\(.*\)$/\1/p' $CONF) X X# Set DHCP parameters. Use default values if nothing is set in our X# configuration file. XDHCP=$($sed -ne 's/^#wifi[[:space:]]DHCP=\(.*\)$/\1/p' $CONF) XDHCP=${DHCP:-dhcp NONE NONE NONE} X X# Delete any existing hostname.if file. XHFILE=/etc/hostname.$IFNAME X$rm -fP $HFILE X X# Temporary file. Note the permissions (-rw-------) on this file X# are *exactly* as required. XTFILE=$($mktemp) X X# Wireless scan picking out any access points known to us. X$ifconfig $IFNAME scan | \ X $sed -ne 's/^.*\(..:..:..:..:..:..\) \([0-9]*\).*$/\1 \2/p' | \ Xwhile read MAC STRENGTH Xdo X . $CONF && { X X DATA="$STRENGTH " X X [ -n "$NWID" ] && DATA="$DATA nwid \"$NWID\"" X X [ -n "$BSSID" ] && DATA="$DATA bssid $BSSID" X X [ -n "$CHAN" ] && DATA="$DATA chan $CHAN" X X [ -n "$NWKEY" ] && DATA="$DATA nwkey $NWKEY" X X [ -n "$WPAKEY" ] && DATA="$DATA wpa wpask $WPAKEY" X X $echo $DATA >> $TFILE X } Xdone X X# Make sure our temporary file gets deleted. Xtrap "$rm -fP $TFILE; trap -" EXIT ERR HUP INT TERM X X# Check we have at least one known access point. X[ -s $TFILE ] || exit 0 X X# Pick out the access point with the strongest signal. XDATA=$($sort -n -r $TFILE | $sed -ne 's/^[0-9]* \(.*\)$/\1/p' -e 1q) X X# Finally set up our hostname.if file... X$echo "$DHCP $DATA" > $TFILE X X# ...and copy it to the right place. X[ -s $TFILE ] && $cp -p $TFILE $HFILE X Xexit 0 END-of-rc.wireless echo x - rc.wireless.conf sed 's/^X//' >rc.wireless.conf << 'END-of-rc.wireless.conf' X#!/bin/sh X X# Wireless configuration. Comments starting '#wifi ' are "special" X# and contain wifi card parameters, non-default DHCP values, that X# are picked out by our parent, /etc/rc.wireless. X X# Make sure this file is *NOT* accessible by others if it contains X# sensitive data, eg Wireless Equivalent Privacy (WEP) keys or Wi-Fi X# Protected Access (WPA-PSK and WPA2-PSK) passphrases. X X# Belkin cardbus wireless card. Broadcom AirForce based. X# X# bwi0 at cardbus0 dev 0 function 0 "Broadcom BCM4318" rev 0x02: irq 11, address 00:11:50:f4:f4:4c X# X#wifi IFNAME=bwi0 X#wifi RESET=-bssid -chan media autoselect nwid "" -nwkey -wpa -wpapsk X#wifi MAC_ADDR=00:11:50:f4:f4:4c X#wifi DHCP=dhcp media autoselect mode 11g X Xcase $MAC in X "$MAC_ADDR") X return 1 X ;; X X # University of Bath, UK. Computing Services, building X # 2 South. X X 00:0f:90:4d:e9:50 | 00:11:20:8d:b4:30 | 00:1b:d5:c0:11:00) X X NWID=BUCS-WiSM X NWKEY= X WPAKEY= X CHAN= X BSSID=$MAC X ;; X X # University of Bath, UK. All these seem visible, with X # varying strengths, from the University Library foyer. X X 00:11:20:70:4a:50 | 00:11:20:70:4d:30 | 00:11:20:70:4f:c0 | \ X 00:11:20:70:50:e0 | 00:11:20:70:56:50 | 00:11:20:70:66:10 | \ X 00:11:20:70:6d:b0 | 00:11:20:70:71:c0 | 00:11:20:70:78:e0 | \ X 00:11:20:70:79:f0 | 00:11:20:75:8e:e0 | 00:11:20:75:a2:30 | \ X 00:11:20:8d:b9:20 | 00:11:20:8d:ef:40 | 00:11:20:8d:f4:20 | \ X 00:11:20:90:d5:40 | 00:11:20:90:ff:00 | 00:16:47:0c:fd:10 | \ X 00:16:47:0d:02:90 | 00:16:47:0d:07:10 | 00:27:0d:4a:29:ef | \ X 00:27:0d:60:b3:ff) X X NWID=BUCS-WiSM X NWKEY= X WPAKEY= X CHAN= X BSSID=$MAC X ;; X X *) X return 1 X ;; Xesac X Xreturn 0 END-of-rc.wireless.conf exit -- Dennis Davis, BUCS, University of Bath, Bath, BA2 7AY, UK [email protected] Phone: +44 1225 386101

