How detecting the Wifi area my iwi0 is in?

Sam Leffler sam at errno.com
Mon Jul 16 16:28:35 UTC 2007


Matthias Apitz wrote:
> El día Monday, July 16, 2007 a las 12:50:24PM +0300, Dennis Melentyev escribió:
> 
>> Hello Mattias,
>>
>> Have you tried wpa_supplicant for this? It can perfectly autodetect
>> networks for me (office/home). With iwi driver on 7.0-CURRENT-200706
>> snapshot (HP/Compaq nc8230).
> 
> Hello Dennis,
> 
> In some of the offices I'm as well using wpa_supplicant, at home
> I have only WEP (maybe this would work as well with wpa_supplicant,
> I've never tried it and just putting the wepkey with ifconfig into
> the interface); but all this is more complex then just doing the
> association, because I have also (sometimes) use a dedicated IP
> addr, sometimes I must fetch it with DHCP, and/or have to set other
> network related files accordingly (/etc/hosts, /etc/resolv.conf
> and others); thats why my idea was having a script in
> /usr/local/etc/rc.d/wlan.sh with the logic like:
> 
> 
> #!/bin/sh
> 
> ifconfig iwi0 scan 
> ifconfig iwi0 list ap | fgrep -q office1    && wifi=office1
> ifconfig iwi0 list ap | fgrep -q office2    && wifi=office2
> ifconfig iwi0 list ap | fgrep -q office3    && wifi=office3
> #....
> 
> #
> # switch IP layout: office1 / office2 / ... based on ${wifi}
> #
> case ${wifi} in
> 
>     office1)  printf "Found Wifi 'office1' ... " ;
>            cat /home/guru/sys/hosts.office1         > /etc/hosts
>            cat /home/guru/sys/resolv.conf.office1   > /etc/resolv.conf
>            cat /home/guru/sys/nsswitch.conf.office1 > /etc/nsswitch.conf
>            route delete default > /dev/null
>            ifconfig bge0 down
>            ssid=office1
>            wepkey=xxxxxxxxxxxxxxxxxxxxxxxxxx
>            inet=192.168.2.3
>            netmask=0xffffff00
>            ifconfig iwi0 inet ${inet} \
>                     netmask ${netmask} \
>                     ssid ${ssid} \
>                     wepkey ${wepkey} \
>                     channel 9 weptxkey 1 wepmode on
>            ping -c3 -o smc
>            route add default    192.168.2.1 > /dev/null
>            printf "... done.\n" ;
>            ;;
>       
>      
>     office2) printf "Found Wifi 'office2' ... " ;
>            route flush > /dev/null
>            route delete 193.31.10.32/27 > /dev/null
>            wpa_supplicant -B -i iwi0 -c /etc/wpa_supplicant.conf
>            # let the WPA client come up and init the iwi0 interface
>            sleep 1
>            ifconfig iwi0 inet 193.31.10.34 netmask 255.255.255.224
>            route add default 193.31.10.58 > /dev/null
>            cat /home/guru/sys/hosts.office2         > /etc/hosts
>            cat /home/guru/sys/resolv.conf.office2   > /etc/resolv.conf
>            cat /home/guru/sys/nsswitch.conf.office2 > /etc/nsswitch.conf
> 
> 	   # ....
> 
> 
> I'm clearer now what I want to do?

wpa_supplicant grok's WEP and should also handle open auth (no crypto). 
  The intended way to handle the rest of your needs is to hook into devd 
and launch a script the link UP event (or similar).  For the latter 
you'll probably want to write your script to work only on first link UP 
so you don't repeat work for each DOWN/UP transition (as happens when 
the AP dumps the station for inactivity).

You can find the ssid of the associated ap with ifconfig (e.g. ifconfig 
iwi0 list sta | awk '{print $1;}') or use wpa_cli to query the info from 
wpa_supplicant if you use it to setup your network.  Given the wealth of 
wireless state displayed by ifconfig I've also considered adding a new 
program that's designed for shell scripts; it could be used to query 
individual settings and/or generate shell syntax for multiple params; e.g.

SSID=`wlanconfig iwi0 ssid`
eval `wlanconfig iwi0 ssid channel authmode`

Another thing to look at is the wlanwatch program in 
tools/tools/net80211; you can use it to write a program that waits for 
the first link UP event (on associate) and then have it print the SSID 
of the ap to stdout.

I think all the mechanisms for doing stuff are present in the system; 
we're just lacking better integration to autoconfig network state.

	Sam


More information about the freebsd-mobile mailing list