OpenBSD Journal

wiconfig - simplifies the configuration of wireless interfaces

Contributed by sean on from the airborne packets dept.

Daniel M wrote in about the wiconfig script that he wrote to handle moving a laptop between networks:

So, I got tired of doing my little time saving workarounds every time I connected to a wireless network and decided to look for a solution. Several people have posted little wireless scripts here, to misc@ and minor modifications to help simplify and automate the configuration of wireless, but the scripts never seemed to go far enough. That said, I took the shut up and hack motto and crafted my own solution that is more complete and well, "sucks less" than everyone else's solution (in my humble opinion). I've tried to keep it simple and as minimally intrusive as possible.

The following is an excerpt from the script's comments:

# EXAMPLE
#       Manually configure a wireless interface
#
#               # sh /etc/wiconfig iwi0
#
#       Automatically scan for wireless networks and, using previous manual
#       configurations, configure the wireless interface based on the strongest
#       wireless signal (for use with hostname.if(5) files)
#
#               $ cat /etc/hostname.iwi0
#               !/bin/sh /etc/wiconfig -q \$if
#
#       With the above /etc/hostname.iwi0 in place, iwi0 will be configured
#       upon startup or whenever /etc/netstart iwi0 is invoked.
#
#       wiconfig can also be used in conjunction with apmd.  In the following
#       example, upon resume, it'll check the status of the wireless connection
#       and, if there is no network connection, it'll automatically scan for
#       wireless networks and, using previous manual configurations, configure
#       the wireless interface based on the strongest wireless signal.
#
#               $ cat /etc/apmd/resume
#               #!/bin/sh
#               /bin/sh /etc/wiconfig -qs iwi0
I think this script will be quite useful for anyone who uses wireless on OpenBSD and enjoys taking his or her notebook places. That said, while this has been working well for me over the past couple of days, consider this a beta.

I would like others to give it a test-drive and provide feedback. Also, know that I am not a programmer by profession. While I've done minor scripts here and there, this is the largest script I've ever written and I learned a fair amount about pdksh in the process. I took some queues from other related scripts and reviewed some of the scripts used by OpenBSD in writing this so I'd appreciate feedback here as well and welcome patches.

It is my hope that the time I spent writing this will save time for many people when it comes to wireless on OpenBSD. The "wiconfig" script can currently be downloaded from http://bink.mooo.com/~daniel/pub/, but please know I've only used it on OpenBSD 5.0.

(Comments are closed)


Comments
  1. By Matthias Kilian (kili) kili@outback.escape.de on

    I'm a good guy, so I just changed my home wlan nwid to `rm /etc/wiconfig` to protect people who are using this script from the really bad guys ;-)

    Comments
    1. By Daniel M (danielm) on

      Hi Matthias--appreciate you peeking at the script and exposing the issue. For what it's worth, the script doesn't automatically connect to the strongest network it finds until you configure a specific network, so you'd have to tell it to connect to `rm /etc/wiconfig`, which is akin to someone typing ifconfig iwi0 nwid "`rm /etc/wiconfig`". I have modified the script to use single quotes instead of double quotes, but I'm not certain if this is the best solution. That said, I do see that some input validation is warranted and I'll work on it. Thanks.

      Comments
      1. By Matthias Kilian (kili) on

        > Hi Matthias--appreciate you peeking at the script and exposing the issue. For what it's worth, the script doesn't automatically connect to the strongest network it finds until you configure a specific network, so you'd have to tell it to connect to `rm /etc/wiconfig`, which is akin to someone typing ifconfig iwi0 nwid "`rm /etc/wiconfig`". I have modified the script to use single quotes instead of double quotes, but I'm not certain if this is the best solution. That said, I do see that some input validation is warranted and I'll work on it. Thanks.

        Actually, I didn't even test wether that `rm /etc/wiconfig` works or not. IMHO it's wrong to parse ifconfig output, and it's dangerous parsing ifconfig output with a shell script.

        I don't think that something like your wiconfig can be done correctly as a sole shell script.

        Comments
        1. By Daniel M (danielm) on

          I concur. A C program that does this with ioctl(2) would be ideal, but, until then, I hacked this together.

  2. By wim wauters (unisoftdesign) undeadly@unisoftdesign.co.uk on www.unisoftdesign.co.uk

    Excellent, thanks for sharing. I'm in the KISS and absolute control-freak camp, but it's neat to see automatic picking based on signal strength.

  3. By Peter Ljung (peter_ljung) ljung.peter@gmail.com on http://www.lounge.se

    I agree that a script of this kind may be very useful in many situations, even if hostname.if configuration is really slick and simple. So I have also been tinkering with a similar script for some time.

    This is certainly work in progress, but works for me in common situations.

    auto-wifi.sh

  4. By Aaron Bieber (qbit) deftly@gmail.com on http://qbit.io

    I ran into a few issues so far:
    1. athn seems to take longer than 3 seconds to set state to "active".
    2. adsuck wants /var/adsuck/files/resolve.conf to be 644, but the umask is causing it to be 640.

    Here is a patch that fixes both my issues:

    <pre>
    diff --git a/wiconfig b/wiconfig
    index 3f271f6..d714ae1 100644
    --- a/wiconfig
    +++ b/wiconfig
    @@ -79,9 +79,6 @@ myname=$0
    max=20
    wiconfigdb="/etc/wiconfig.db"

    -# Don't allow others to read the files we create
    -umask 027
    -
    function usage {
    echo "usage: $myname [-dqs] interface"
    exit 1
    @@ -400,15 +397,15 @@ function determine {
    # Must bring interface up for status to become active
    ifconfig $if nwid ${nwid[$choice]} wpakey $pass1 up > /dev/null 2>&1
    typeset _status=$?
    - sleep 3
    + sleep 10
    # Network is active
    if [ $_status -eq 0 ] && active $(ifconfig $if | fgrep status); then
    update wpa
    else
    ifconfig $if -nwid -wpakey down > /dev/null 2>&1
    - ifconfig $if nwid ${nwid[$choice]} nwkey $pass1 up > /dev/null 2>&1
    + ifconfig $if nwid ${nwid[$choice]} wpakey $pass1 up > /dev/null 2>&1
    _status=$?
    - sleep 3
    + sleep 10
    if [ $_status -eq 0 ] && \
    active $(ifconfig $if | fgrep status); then
    update wep
    @@ -452,12 +449,16 @@ function secure {
    }

    function createdb {
    + # Don't allow others to read the files we create
    + oldumask=$( umask )
    + umask 027
    echo -n > $wiconfigdb
    typeset _i=1
    while [ $_i -le ${#r[@]} ]; do
    echo ${r[$_i]} >> $wiconfigdb
    _i=$(($_i+1))
    done
    + umask $oldumask
    }

    function end {
    </pre>

    Comments
    1. By Daniel M (danielm) on

      Hi Aaron, thanks for giving the script a spin and taking the time to post a diff. Does athn really take 10 seconds to go active? Could you time this, as 10 seconds seems like quite a long time? As for adsuck, I wasn't certain why this would be affected since the umask should only affect the current process, but, in looking into this, it appears adsuck requires modification to dhclient and, since this script uses dhclient, dhclient is inheriting the umask. That said, I have modified the script to just use chmod instead since it's only required when we first create the file anyway. I also noticed you needed to change nwkey to wpakey, but I'm not certain why this is the case, as the first use of wpakey should have you covered. Cheers.

      Comments
      1. By Aaron Bieber (qbit) on http://qbit.io

        > Hi Aaron, thanks for giving the script a spin and taking the time to post a diff. Does athn really take 10 seconds to go active? Could you time this, as 10 seconds seems like quite a long time? As for adsuck, I wasn't certain why this would be affected since the umask should only affect the current process, but, in looking into this, it appears adsuck requires modification to dhclient and, since this script uses dhclient, dhclient is inheriting the umask. That said, I have modified the script to just use chmod instead since it's only required when we first create the file anyway. I also noticed you needed to change nwkey to wpakey, but I'm not certain why this is the case, as the first use of wpakey should have you covered. Cheers.

        it seems that the athn takes anywhere form 5 to 10 seconds.. so i just went with 10 :D

        The nwkey to wpakey bit was leftover from debugging the 10 second issue.

        Is the project hosted anywhere that is conducive to communal hacking? Github maybe?

        Comments
        1. By Daniel M (danielm) on

          Another person chimed in with the athn issue, so I put a workaround for it, but it's not ideal (there seems to be differences in how the interface is marked active between iwi and athn and I imagine other drivers as well). As for communal hacking, I have not used github yet, but feel free to put it up there and post the URL.

          Comments
          1. By Aaron Bieber (qbit) on http://qbit.io

            > Another person chimed in with the athn issue, so I put a workaround for it, but it's not ideal (there seems to be differences in how the interface is marked active between iwi and athn and I imagine other drivers as well). As for communal hacking, I have not used github yet, but feel free to put it up there and post the URL.

            Added it up to github : https://github.com/devious/wiconfig

  5. By Anonymous Coward (erlang) on

    thank you daniel

Latest Articles

Credits

Copyright © - 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 as well as images and HTML templates were copied from the fabulous original deadly.org with Jose's and Jim's kind permission. This journal runs as CGI with httpd(8) on OpenBSD, the source code is BSD licensed. undeadly \Un*dead"ly\, a. Not subject to death; immortal. [Obs.]