How detecting the Wifi area my iwi0 is in?

Matthias Apitz m.apitz at
Mon Jul 16 12:04:03 UTC 2007

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/ with the logic like:


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
           ifconfig iwi0 inet ${inet} \
                    netmask ${netmask} \
                    ssid ${ssid} \
                    wepkey ${wepkey} \
                    channel 9 weptxkey 1 wepmode on
           ping -c3 -o smc
           route add default > /dev/null
           printf "... done.\n" ;
    office2) printf "Found Wifi 'office2' ... " ;
           route flush > /dev/null
           route delete > /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 netmask
           route add default > /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?


Matthias Apitz
Manager Technical Support - OCLC PICA GmbH
Gruenwalder Weg 28g - 82041 Oberhaching - Germany
t +49-89-61308 351 - f +49-89-61308 399 - m +49-170-4527211
e <m.apitz at> - w
OCLC PICA GmbH, Geschaeftsfuehrer: Christine Magin-Weeger, Norbert Weinberger
Sitz der Gesellschaft: Oberhaching, HRB Muenchen: 113261

More information about the freebsd-mobile mailing list