Automatic WLAN configuration in OpenBSD

The idea is to enable automatic WLAN configuration of known networks in OpenBSD in a similar manner that is done in e.g. MacOS X.

OpenBSD if configuration is done in hostname.if configuration files and I have ended up with a number of interface configurations in my WLAN hostname.if file. The idea is to add semantics (like a switch statement) to handle different alternative network configurations which is selected based on availabilitly. Configurations may also be priortized on e.g. signal strength, security etc. when many networks are available simultaneously.

As a rough example on hostname.if.

switch network prio "signal security"
  case: NETWORK_X
    dhcp nwid NETWORK
  case: NETWORK_Y
    dhcp chan 1 nwid Campanile nwkey <key>
  case: NETWORK_Z
    dhcp chan 6 nwid astrid wpa wpapsk <key>
end

netstart script would have to updated to support this new semantics.

Alternative solutions

Question is if this is the right solution.

ifstated is used to take actions on network changes. Possibly it can be used or extended to support also initial network configuration. ifstated can also be used to reconnect to a new network when current network is lost. This could possibly be performed by ifstated by itself or in a combination with described solution.

Another solution is to provide an external script to handle multiple alternative networks like a wifi probe. This script would then switch network configuration in hostname.if and use netstart to change network. This is probably the most lean solution. The following command will present a list of available networks.

ifconfig ral0 scan