nerves_wpa_supplicant v0.5.2 Nerves.WpaSupplicant
Link to this section Summary
Functions
Tell the wpa_supplicant to add and enable the specified network. Invoke like this
Returns a specification to start this module under a supervisor
Get the interface name from the wpa_supplicant state
Invoked when the server is started. start_link/3
or start/3
will
block until it returns
According to the docs, this forces a reassociation to the current access point, but in practice it causes the supplicant to go through the network list in priority order, connecting to the highest priority access point available
Removes all configured networks
Send a request to the wpa_supplicant
This is a helper function that will initiate a scan, wait for the scan to complete and return a list of all of the available access points. This can take a while if the wpa_supplicant hasn't scanned for access points recently
Tell the wpa_supplicant to connect to the specified network. Invoke like this
Start and link a Nerves.WpaSupplicant that uses the specified control socket
Return the current status of the wpa_supplicant. It wraps the STATUS command
Stop the Nerves.WpaSupplicant control interface
Link to this section Functions
add_network(pid, options)
Tell the wpa_supplicant to add and enable the specified network. Invoke like this:
iex> Nerves.WpaSupplicant.add_network(pid, ssid: "MyNetworkSsid", key_mgmt: :WPA_PSK, psk: "secret")
or like this:
iex> Nerves.WpaSupplicant.add_network(pid, %{ssid: "MyNetworkSsid", key_mgmt: :WPA_PSK, psk: "secret"})
For common options, see set_network/2
.
Returns {:ok, netid}
or {:error, key, reason}
if a key fails to set.
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
ifname(pid)
Get the interface name from the wpa_supplicant state
init(arg)
Invoked when the server is started. start_link/3
or start/3
will
block until it returns.
init_arg
is the argument term (second argument) passed to start_link/3
.
Returning {:ok, state}
will cause start_link/3
to return
{:ok, pid}
and the process to enter its loop.
Returning {:ok, state, timeout}
is similar to {:ok, state}
except handle_info(:timeout, state)
will be called after timeout
milliseconds if no messages are received within the timeout.
Returning {:ok, state, :hibernate}
is similar to {:ok, state}
except the process is hibernated before entering the loop. See
c:handle_call/3
for more information on hibernation.
Returning {:ok, state, {:continue, continue}}
is similar to
{:ok, state}
except that immediately after entering the loop
the c:handle_continue/2
callback will be invoked with the value
continue
as first argument.
Returning :ignore
will cause start_link/3
to return :ignore
and
the process will exit normally without entering the loop or calling
c:terminate/2
. If used when part of a supervision tree the parent
supervisor will not fail to start nor immediately try to restart the
GenServer
. The remainder of the supervision tree will be started
and so the GenServer
should not be required by other processes.
It can be started later with Supervisor.restart_child/2
as the child
specification is saved in the parent supervisor. The main use cases for
this are:
- The
GenServer
is disabled by configuration but might be enabled later. - An error occurred and it will be handled by a different mechanism than the
Supervisor
. Likely this approach involves callingSupervisor.restart_child/2
after a delay to attempt a restart.
Returning {:stop, reason}
will cause start_link/3
to return
{:error, reason}
and the process to exit with reason reason
without
entering the loop or calling c:terminate/2
.
Callback implementation for GenServer.init/1
.
reassociate(pid)
According to the docs, this forces a reassociation to the current access point, but in practice it causes the supplicant to go through the network list in priority order, connecting to the highest priority access point available.
remove_all_networks(pid)
Removes all configured networks.
Returns :ok
or {:error, key, reason}
if an error is encountered.
request(pid, command)
Send a request to the wpa_supplicant.
Example
iex> Nerves.WpaSupplicant.request(pid, :PING)
:PONG
scan(pid)
This is a helper function that will initiate a scan, wait for the scan to complete and return a list of all of the available access points. This can take a while if the wpa_supplicant hasn't scanned for access points recently.
set_network(pid, options)
Tell the wpa_supplicant to connect to the specified network. Invoke like this:
iex> Nerves.WpaSupplicant.set_network(pid, ssid: "MyNetworkSsid", key_mgmt: :WPA_PSK, psk: "secret")
or like this:
iex> Nerves.WpaSupplicant.set_network(pid, %{ssid: "MyNetworkSsid", key_mgmt: :WPA_PSK, psk: "secret"})
Many options are supported, but it is likely that ssid
and psk
are
the most useful. The full list can be found in the wpa_supplicant
documentation. Here's a list of some common ones:
Option | Description
----------------------|------------
:ssid | Network name. This is mandatory.
:key_mgmt | The security in use. This is mandatory. Set to :NONE, :WPA_PSK
:proto | Protocol use use. E.g., :WPA2
:psk | WPA preshared key. 8-63 chars or the 64 char one as processed by `wpa_passphrase`
:bssid | Optional BSSID. If set, only associate with the AP with a matching BSSID
:mode | Mode: 0 = infrastructure (default), 1 = ad-hoc, 2 = AP
:frequency | Channel frequency. e.g., 2412 for 802.11b/g channel 1
:wep_key0..3 | Static WEP key
:wep_tx_keyidx | Default WEP key index (0 to 3)
:priority | Integer priority of the network where higher number is higher priority
Note that this is a helper function that wraps several low-level calls and is limited to specifying only one network at a time. If you'd like to register multiple networks with the supplicant, use add_network.
Returns :ok
or {:error, key, reason}
if a key fails to set.
start_link(ifname, control_socket_path, opts \\ [])
Start and link a Nerves.WpaSupplicant that uses the specified control socket.
status(pid)
Return the current status of the wpa_supplicant. It wraps the STATUS command.
stop(pid)
Stop the Nerves.WpaSupplicant control interface