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 b308b60
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ The `:wifi` key has the following common fields:
* 1: Do passive scans.
* `:priority`: The priority to set for a network if you are using multiple network
configurations
* `:regulatory_domain`: Two character country code. Technology configuration
will take priority over Application configuration
* `:networks` - A list of WiFi networks to configure, these configs have the same
fields listed above

Expand Down Expand Up @@ -301,6 +303,21 @@ iex> VintageNet.configure("wlan0", %{
})
```

Example of setting regulatory domain:

```elixir
iex> VintageNet.configure("wlan0", %{
type: VintageNet.Technology.WiFi,
wifi: %{
ssid: "testing",
key_mgmt: :wpa_psk,
psk: "super secret",
regulatory_domain: "US"
},
ipv4: %{method: :dhcp}
})
```

### LTE

TBD
Expand Down
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_domain at 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 b308b60

Please sign in to comment.