OpenBSD Journal
Home : : Add Story : : Archives : : About : : Create Account : : Login :
Wireless Network Profiles
Contributed by merdely on Mon Dec 24 16:46:29 2007 (GMT)
from the wifi-value-meal dept.

D. Adam Karim shares his solution to using multiple wireless networks:

Having to jump to various wireless network all the time, I have been forced to come up with a way to keep track of them all and make it as seamless as possible to use one or another. The other feature that I wanted was to be able to keep the base files unchanged as much as possible.

Basically, what I have done was create two files, /etc/rc.wireless and /etc/rc.wireless.conf. These two files handle setting up a hostname.if(5) files for the given device based on the configuration in /etc/rc.wireless.conf. One must also add just a small bit to /etc/netstart in order to get it started.

Here is the diff for /etc/netstart as well as the two files:

--- /usr/src/etc/netstart       Wed Aug  1 21:21:27 2007
+++ /etc/netstart       Thu Dec 20 15:22:18 2007
@@ -2,6 +2,11 @@
 #
 #      $OpenBSD: netstart,v 1.116 2007/08/02 03:19:10 david Exp $

+# Create hostname.if(5) file for wireless device.
+if [ -f /etc/rc.wireless ]; then
+       . /etc/rc.wireless
+fi
+
 # Strip comments (and leading/trailing whitespace if IFS is set)
 # from a file and spew to stdout
 stripcom() {

/etc/rc.wireless:

#!/bin/sh

CONF="/etc/rc.wireless.conf"
IFNAME=`sed -ne 's/IFNAME=\"\(.*\)\"/\1/p' ${CONF}`
HFILE="/etc/hostname.${IFNAME}"
TFILE=`mktemp`
OUTPUT="dhcp NONE NONE NONE "

rm -f ${HFILE}

ifconfig -M ${IFNAME} | sed -ne 's/.*\(..:..:..:..:..:..\).*/\1/p' | \
while read MAC; do

        if [ -r ${CONF} ]; then
                . ${CONF}
        else
                exit 1
        fi

        if [ $? = 0 ]; then

                if [ -n "${NWID}" ]; then
                        OUTPUT="${OUTPUT} nwid ${NWID}"
                fi

                if [ -n "${BSSID}" ]; then
                        OUTPUT="${OUTPUT} bssid ${BSSID}"
                fi

                if [ -n "${NWKEY}" ]; then
                        OUTPUT="${OUTPUT} nwkey ${NWKEY}"
                fi

                echo ${OUTPUT} >> ${TFILE}

                break
        fi

done

if [ -s ${TFILE} ]; then
        cp ${TFILE} ${HFILE}
fi

rm -f ${TFILE}

/etc/rc.wireless.conf:

#!/bin/sh
# wireless configuration

IFNAME="iwi0"

case "${MAC}" in
        00:1a:70:4b:f5:64)
                NWID="Akarsoft"
                NWKEY=""
                ;;
        00:e0:98:f4:55:ab)
                NWID="Karim"
                NWKEY="somekey"
                ;;
        00:0d:3a:2a:83:7d)
                NWID="xythos"
                NWKEY="somekey"
                BSSID="00:0d:3a:2a:83:7d"
                ;;
        00:01:95:6a:40:2b)
                NWID="xythos"
                NWKEY="0xf345ad1293"
                BSSID="00:01:95:6a:40:2b"
                ;;
        00:06:25:92:53:df)
                NWID="Lemny"
                NWKEY="somekey"
                ;;
        *)
                return 1
esac

Don't get me wrong, I don't say that this is perfect but it works for me and thought that others who jump from network to network like I do might enjoy it!

[topicopenbsd]

<< New Ports of the Week #51 (December 16) | | Flattened | Collapsed | Flashboot 4.2 released >>

Threshold: Help

Related Links
more by merdely


  Re: Wireless Network Profiles (mod -1/3)
by Anonymous Coward (69.70.68.38) on Mon Dec 24 16:47:28 2007 (GMT)
  What does sed -ne 's/.*\(..:..:..:..:..:..\).*/\1/p' do exactly? This looks possibly like something I can use for another script I made that I'm looking to clean up and share too. uses ifstated and soon relayd too.

Are the dots wildcards?
  [ Show thread ] [ Mod Up ] [ Mod Down ]

       
Re: Wireless Network Profiles (mod -1/3)
by Anonymous Coward (12.158.188.186) on Mon Dec 24 17:31:42 2007 (GMT)
  > What does sed -ne 's/.*\(..:..:..:..:..:..\).*/\1/p' do exactly? This looks possibly like something I can use for another script I made that I'm looking to clean up and share too. uses ifstated and soon relayd too.
>
> Are the dots wildcards?

It turns "garbage(FF:FF:FF:FF:FF:FF)garbage" in to "FF:FF:FF:FF:FF:FF". (each "." represents any character in regex)
  [ Show thread ] [ Mod Up ] [ Mod Down ]

         
Re: Wireless Network Profiles (mod 1/3)
by Anonymous Coward (99.235.193.57) on Tue Dec 25 05:45:40 2007 (GMT)
  > > What does sed -ne 's/.*\(..:..:..:..:..:..\).*/\1/p' do exactly? This looks possibly like something I can use for another script I made that I'm looking to clean up and share too. uses ifstated and soon relayd too.
> >
> > Are the dots wildcards?
>
> It turns "garbage(FF:FF:FF:FF:FF:FF)garbage" in to "FF:FF:FF:FF:FF:FF". (each "." represents any character in regex)

Actually, it turns "garbageFF:FF:FF:FF:FF:FFgarbage" into "FF:FF:FF:FF:FF:FF".
  [ Show thread ] [ Mod Up ] [ Mod Down ]

           
Re: Wireless Network Profiles (mod 2/4)
by Mark Peloquin (incripshin) on Thu Dec 27 06:25:17 2007 (GMT)
  > > > What does sed -ne 's/.*\(..:..:..:..:..:..\).*/\1/p' do exactly? This looks possibly like something I can use for another script I made that I'm looking to clean up and share too. uses ifstated and soon relayd too.
> > >
> > > Are the dots wildcards?
> >
> > It turns "garbage(FF:FF:FF:FF:FF:FF)garbage" in to "FF:FF:FF:FF:FF:FF". (each "." represents any character in regex)
>
> Actually, it turns "garbageFF:FF:FF:FF:FF:FFgarbage" into "FF:FF:FF:FF:FF:FF".

I suppose it has to do with backwards-compatibility. Matching probably wasn't always part of sed.
  [ Show thread ] [ Mod Up ] [ Mod Down ]

  Re: Wireless Network Profiles (mod 3/5)
by D. Adam Karim (Archite) (adam@akarsoft.com) on Mon Dec 24 18:03:05 2007 (GMT)
  One thing that I forgot to add was that often I am in places where there is no wireless network available (you have to love antiquated commuter trains). One advantage is that this script will not create a hostname.if file in that case meaning that I won't have to wait for dhcp to time out during a cold boot.
  [ Show thread ] [ Mod Up ] [ Mod Down ]

  Re: Wireless Network Profiles (mod -1/3)
by Anonymous Coward (158.109.1.9) on Mon Dec 24 20:45:39 2007 (GMT)
  http://marc.info/?l=openbsd-misc&m=119611252029773&w=2
  [ Show thread ] [ Mod Up ] [ Mod Down ]

       
Re: Wireless Network Profiles (mod 4/4)
by D. Adam Karim (Archite) on Wed Dec 26 03:40:17 2007 (GMT)
  > http://marc.info/?l=openbsd-misc&m=119611252029773&w=2

That's a nice script! The only issue is that it is not automated, which was a big thing for me as I don't want to deal with having to do anything: I want it to just work. I'll most likely keep it around though for when I'm at the local coffee shop though. Thanks for the link!
  [ Show thread ] [ Mod Up ] [ Mod Down ]

  Re: Wireless Network Profiles (mod 2/4)
by Anonymous Coward (76.103.60.14) on Tue Dec 25 01:50:59 2007 (GMT)
  errr. wep keys?

what's that for?

lol.
  [ Show thread ] [ Mod Up ] [ Mod Down ]

       
Re: Wireless Network Profiles (mod 2/4)
by Anonymous Coward (122.49.150.21) on Tue Dec 25 04:51:17 2007 (GMT)
  > errr. wep keys?
>
> what's that for?
>
> lol.

For connecting to the network you've just cracked, duh.
  [ Show thread ] [ Mod Up ] [ Mod Down ]

         
Re: Wireless Network Profiles (mod 1/1)
by Anonymous Coward (85.178.80.238) on Wed Dec 26 00:03:14 2007 (GMT)
  > > errr. wep keys?
> >
> > what's that for?
> >
> > lol.
>
> For connecting to the network you've just cracked, duh.

And what's about WEP(2)? :-p
  [ Show thread ] [ Mod Up ] [ Mod Down ]

  Re: Wireless Network Profiles (mod 3/3)
by Anonymous Coward (71.178.166.14) on Tue Dec 25 20:05:24 2007 (GMT)
  Hm. My own solution to this problem is quite a bit more simple. I just create a bunch of shell scripts with the relevant ifconfig/dhclient commands and run them with sudo when I want to connect to a specific network.
  [ Show thread ] [ Mod Up ] [ Mod Down ]

  Re: Wireless Network Profiles (mod 1/5)
by Anonymous Coward (24.78.165.238) on Wed Dec 26 05:34:53 2007 (GMT)
  Is there something (perhaps not yet) in/for ports that accomplishes this for non technical users (eg. grandmas) without having them know of the shell?
  [ Show thread ] [ Mod Up ] [ Mod Down ]

       
Re: Wireless Network Profiles (mod -3/5)
by D. Adam Karim (Archite) on Wed Dec 26 06:29:50 2007 (GMT)
  > Is there something (perhaps not yet) in/for ports that accomplishes this for non technical users (eg. grandmas) without having them know of the shell?

If your Grandma is running OpenBSD, I'm sure that she has very good knowledge of shells ;)

Anyways, the point of my script would be to make joining the network seamless on startup. If the /etc/rc.wireless.conf file is filled out, then she would not even notice anything and just see her wireless interface requesting an IP address on startup. If no network was around, it would not waste time running DHCP and she'd get to her desktop.
  [ Show thread ] [ Mod Up ] [ Mod Down ]

         
Re: Wireless Network Profiles (mod 2/12)
by Anonymous Coward (199.18.139.74) on Wed Dec 26 18:30:16 2007 (GMT)
  > > Is there something (perhaps not yet) in/for ports that accomplishes this for non technical users (eg. grandmas) without having them know of the shell?
>
> If your Grandma is running OpenBSD, I'm sure that she has very good knowledge of shells ;)

I am a grandmother, I am sexy, and I run OpenBSD, and I know shells. Why don't you call Suzie? She was such a nice girl. I know she'd like to hear from you.
  [ Show thread ] [ Mod Up ] [ Mod Down ]

         
Re: Wireless Network Profiles (mod 0/4)
by Anonymous Coward (152.160.24.178) on Thu Jan 3 20:01:16 2008 (GMT)
  >Anyways, the point of my script would be to make joining the network >seamless on startup. If the /etc/rc.wireless.conf file is filled out, >then she would not even notice anything and just see her wireless >interface requesting an IP address on startup. If no network was >around, it would not waste time running DHCP and she'd get to her >desktop.

My grandmother will be so happy. The real question is why are you trying to satisfy her.
  [ Show thread ] [ Mod Up ] [ Mod Down ]

[ Home | Add Story | Archives | Polls | About ]

Copyright © 2004-2009 Daniel Hartmeier. All rights reserved. Articles and comments are copyright their respective authors, submission implies license to publish on this web site. Contents of the archive prior to April 2nd 2004 as well as images and HTML templates were copied from the fabulous original deadly.org with Jose's and Jim's kind permission. Some icons from slashdot.org used with permission from Kathleen. This journal runs as CGI with thttpd (plus patches) on OpenBSD, the source code is BSD licensed. Search engine is ht://Dig. undeadly \Un*dead"ly\, a. Not subject to death; immortal. [Obs.]