how to manually configure a wireless network on freebsd

btw, for auto, configure in /etc/rc.conf:

wlans_iwn0="wlan0"
ifconfig_wlan0="WPA DHCP"

parameters

ssid

foonet

key

foonetkey

security

wpa-psk

interface

iwn0

/etc/wpa_supplicant.conf:

network={
     ssid="foonet"
     psk="foonetkey"
     proto=WPA
     key_mgmt=WPA-PSK
}

procedure:

ip=192.168.100.99
#ip=dhcp
mask=255.255.255.0
gw=192.168.100.1
#gw=dhcp
ethdown=yes
[ $ethdown = yes ] && ifconfig em0 0.0.0.0 down
ifconfig wlan create wlandev iwn0
[ $ip != dhcp ] ifconfig wlan0 $ip netmask $mask up
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
if [ $gw != dhcp ]
then
fi
  netstat -nr | cut -f1 -d' ' | grep '0.0.0.0' &&
    route del default
  route add default $gw -ifp wlan0
fi
[ $ip = dhcp ] && dhclient wlan0
sleep 2
ping -c 3 google.com    # test network *and* dns