Skip to content

Commit

Permalink
Support strings for key_mgmt
Browse files Browse the repository at this point in the history
As mentioned in #17, nerves_network does not currently allow for
strings as the key_mgmt method, this PR fixes this by converting
them to atoms as required by nerves_wpa_supplicant.
  • Loading branch information
Hermanverschooten authored and fhunleth committed Oct 10, 2017
1 parent 997d1e5 commit 9146e95
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/nerves_network/wifi_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ defmodule Nerves.Network.WiFiManager do
end

# This happens when we are managing a wireless interface, but we haven't got
# the `ifup` event yet.
# the `ifup` event yet.
def handle_call(_call, _from, %{wpa_pid: nil} = s) do
{:reply, {:error, :wpa_not_started}, s}
end
Expand Down Expand Up @@ -328,7 +328,7 @@ defmodule Nerves.Network.WiFiManager do
{:ok, pid} = Nerves.WpaSupplicant.start_link(state.ifname, wpa_control_pipe, name: :"Nerves.WpaSupplicant.#{state.ifname}")
Logger.info "Register Nerves.WpaSupplicant #{inspect state.ifname}"
{:ok, _} = Registry.register(Nerves.WpaSupplicant, state.ifname, [])
wpa_supplicant_settings = Map.new(state.settings)
wpa_supplicant_settings = parse_settings(state.settings)
case Nerves.WpaSupplicant.set_network(pid, wpa_supplicant_settings) do
:ok -> :ok
error ->
Expand All @@ -339,6 +339,19 @@ defmodule Nerves.Network.WiFiManager do
%Nerves.Network.WiFiManager{state | wpa_pid: pid}
end

defp parse_settings(settings) when is_list(settings) do
settings
|> Map.new
|> parse_settings
end

defp parse_settings(settings = %{ key_mgmt: key_mgmt }) when is_binary(key_mgmt) do
%{ settings | key_mgmt: String.to_atom(key_mgmt) }
|> parse_settings
end

defp parse_settings(settings), do: settings

@spec stop_udhcpc(t) :: t
defp stop_udhcpc(state) do
if is_pid(state.dhcp_pid) do
Expand Down

0 comments on commit 9146e95

Please sign in to comment.