Thursday, December 27, 2012

Manual wireless connection

For the sake of absolute simplicity I'll assume here the DefaultFixed NCP.
My wired and wireless interfaces have been respectively renamed to e0 and w0.

In this scenario, to manually establish a Wi-Fi connection is not that difficult.
The best of all is that you can do it with a few CLI commands.

You may need to double-check what wireless networks are in range:

# dladm scan-wifi
...

To connect to a secure wireless network you need to define a security object.
This object will typically store a WPA2 shared secret key:

# dladm create-secobj -c wpa secobj-W0
provide value for 'secobj-W0':

******************************************************
confirm value for 'secobj-W0':

******************************************************

# dladm show-secobj
OBJECT               CLASS
secobj-W0            wpa

 
Now it shall be possible to successfully connect to the proected wireless network.
Specify the wireless network, the security object and the wireless interface:

# dladm connect-wifi -e W0 -k secobj-W0 w0

If everything went well you'll get something such as:

# dladm show-wifi
LINK       STATUS       ESSID     SEC    STRENGTH   MODE   SPEED
w0         connected    W0        wpa    excellent  g      54Mb

 
# dladm show-link
LINK                CLASS     MTU    STATE    OVER
w0                  phys      1500   up       --
e0                  phys      1500   unknown  --

 
We have just enabled the link w0 corresponding to the secure wireless network W0.
Now just conclude the usual network configuration over the link w0.
For instance:
 
# ipadm show-if
IFNAME     CLASS    STATE    ACTIVE OVER
lo0        loopback ok       yes    --


# ipadm create-ip w0
# ipadm show-if

IFNAME     CLASS    STATE    ACTIVE OVER
lo0        loopback ok       yes    --
w0         ip       down     no     --


# ipadm create-addr -T dhcp -h vbox-1 w0/v4
# ipadm show-addr

lo0/v4            static   ok           127.0.0.1/8
w0/v4             dhcp     ok           10.0.0.7/28
lo0/v6            static   ok           ::1/128


This setup do not not automatically reconnect to W0 upon reboot.
Would this be by design of the fixed network configuration? I do not yet know.
By contrast, the reactive network configuration, such as the Automatic NCP does.
After a reboot it suffices to reenter the dladm connect-wifi command as above.

By the way, before shutdown or reboot it's advisable to manually disconnect.
Not issuing dladm disconnect-wifi before shutdown causes it to take a long time.