Skip to content

Commit

Permalink
Allow supplying regulatory domain at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorRigby committed Jul 23, 2019
1 parent f7761b6 commit f28f88a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/vintage_net/technology/wifi.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ defmodule VintageNet.Technology.WiFi do
defp wifi_to_supplicant_contents(wifi, control_interface_dir, regulatory_domain) do
config = [
"ctrl_interface=#{control_interface_dir}",
"country=#{regulatory_domain}",
"country=#{wifi[:regulatory_domain] || regulatory_domain}",
into_config_string(wifi, :bgscan),
into_config_string(wifi, :ap_scan)
]
Expand Down
48 changes: 48 additions & 0 deletions test/vintage_net/technology/wifi_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,54 @@ defmodule VintageNet.Technology.WiFiTest do
assert {:ok, output} == WiFi.to_raw_config("wlan0", input, default_opts())
end

test "Set regulatory_domainat runtime" do
input = %{
type: VintageNet.Technology.WiFi,
wifi: %{
regulatory_domain: "AU"
},
ipv4: %{method: :dhcp},
hostname: "unit_test"
}

output = %RawConfig{
ifname: "wlan0",
type: VintageNet.Technology.WiFi,
source_config: normalize_config(input),
child_specs: [
{VintageNet.Interface.ConnectivityChecker, "wlan0"},
{VintageNet.WiFi.WPASupplicant,
[ifname: "wlan0", control_path: "/tmp/vintage_net/wpa_supplicant", ap_mode: false]}
],
files: [
{"/tmp/vintage_net/network_interfaces.wlan0", dhcp_interface("wlan0", "unit_test")},
{"/tmp/vintage_net/wpa_supplicant.conf.wlan0",
"""
ctrl_interface=/tmp/vintage_net/wpa_supplicant
country=AU
network={
}
"""}
],
up_cmd_millis: 60_000,
up_cmds: [
{:run_ignore_errors, "ifdown",
["-i", "/tmp/vintage_net/network_interfaces.wlan0", "wlan0"]},
{:run_ignore_errors, "killall", ["-q", "wpa_supplicant"]},
{:run, "wpa_supplicant",
["-B", "-i", "wlan0", "-c", "/tmp/vintage_net/wpa_supplicant.conf.wlan0", "-dd"]},
{:run, "ifup", ["-i", "/tmp/vintage_net/network_interfaces.wlan0", "wlan0"]}
],
down_cmds: [
{:run, "ifdown", ["-i", "/tmp/vintage_net/network_interfaces.wlan0", "wlan0"]},
{:run, "killall", ["-q", "wpa_supplicant"]}
],
cleanup_files: ["/tmp/vintage_net/wpa_supplicant/wlan0"]
}

assert {:ok, output} == WiFi.to_raw_config("wlan0", input, default_opts())
end

test "create a WPA2 WiFi configuration with passphrase" do
input = %{
type: VintageNet.Technology.WiFi,
Expand Down

0 comments on commit f28f88a

Please sign in to comment.