From: Michael Tremer Date: Tue, 26 Aug 2014 13:22:30 +0000 (+0200) Subject: Make the wireless regulatory domain a global configuration option X-Git-Tag: 007~109 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=316707415241da8ad180e8d29eb4263570f29c1f;p=network.git Make the wireless regulatory domain a global configuration option It does not make any sense to make this configurable per device as the kernel does not support this. --- diff --git a/man/network-port-batman-adv-port.xml b/man/network-port-batman-adv-port.xml index 2113a106..15f2f4e1 100644 --- a/man/network-port-batman-adv-port.xml +++ b/man/network-port-batman-adv-port.xml @@ -80,18 +80,6 @@ - - - - - - - - Sets the country code for the wireless interface. - - - - diff --git a/src/functions/functions.hostapd b/src/functions/functions.hostapd index 1d10b978..d98bf9fe 100644 --- a/src/functions/functions.hostapd +++ b/src/functions/functions.hostapd @@ -33,7 +33,7 @@ function hostapd_config_write() { local broadcast_ssid local channel - local country_code + local country_code="$(wireless_get_reg_domain)" local encryption local ieee80211d="1" local key @@ -49,9 +49,6 @@ function hostapd_config_write() { --channel=*) channel=$(cli_get_val ${1}) ;; - --country-code=*) - country_code=$(cli_get_val ${1}) - ;; --encryption=*) encryption=$(cli_get_val ${1}) ;; @@ -93,7 +90,6 @@ function hostapd_config_write() { assert isset channel assert isinteger channel - assert isset country_code assert isset mode assert isset ssid diff --git a/src/functions/functions.phy b/src/functions/functions.phy index f6b74984..366eccc2 100644 --- a/src/functions/functions.phy +++ b/src/functions/functions.phy @@ -46,7 +46,6 @@ function phy_list() { function phy_get() { local info=${1} - local phy if listmatch ${info} $(phy_list); then @@ -65,6 +64,8 @@ function phy_get() { done fi + log DEBUG "Searching for phy = ${info}, found ${phy:-none}" + if [ -z "${phy}" ]; then return ${EXIT_ERROR} fi diff --git a/src/functions/functions.wireless b/src/functions/functions.wireless index cd17de4c..f32733ac 100644 --- a/src/functions/functions.wireless +++ b/src/functions/functions.wireless @@ -19,6 +19,12 @@ # # ############################################################################### +# Sets the global wireless country code. Default is 00 = world. +WIRELESS_REGULATORY_DOMAIN="00" +NETWORK_CONFIG_FILE_PARAMS="${NETWORK_CONFIG_FILE_PARAMS} WIRELESS_REGULATORY_DOMAIN" + +init_register wireless_init_reg_domain + function wireless_create() { local device=${1} assert isset device @@ -95,6 +101,29 @@ function wireless_remove() { return ${ret} } +function wireless_get_reg_domain() { + # Returns the country code for the wireless device. + # Defaults to 00 = world if unset. + print "${WIRELESS_REGULATORY_DOMAIN:-00}" +} + +function wireless_init_reg_domain() { + local country_code="$(wireless_get_reg_domain)" + + wireless_set_reg_domain "${country_code}" +} + +function wireless_set_reg_domain() { + local country_code="${1}" + assert isset country_code + + # Before the wireless reg domain is set, it helps to reset to 00 first. + iw reg set 00 &>/dev/null + + log INFO "Setting wireless regulatory domain country to '${country_code}'" + iw reg set "${country_code}" +} + function wireless_channel_to_frequency() { # http://en.wikipedia.org/wiki/List_of_WLAN_channels diff --git a/src/functions/functions.wpa_supplicant b/src/functions/functions.wpa_supplicant index 1c043aff..b2357d59 100644 --- a/src/functions/functions.wpa_supplicant +++ b/src/functions/functions.wpa_supplicant @@ -30,7 +30,7 @@ function wpa_supplicant_config_write() { shift 2 - local ap_scan=1 country_code mode key ssid + local ap_scan=1 mode key ssid local arg for arg in "$@"; do @@ -38,9 +38,6 @@ function wpa_supplicant_config_write() { --ap-scan=*) ap_scan=$(cli_get_val ${arg}) ;; - --country-code=*) - country_code=$(cli_get_val ${arg}) - ;; --mode=*) mode=$(cli_get_val ${arg}) @@ -64,6 +61,7 @@ function wpa_supplicant_config_write() { assert isset mode local auth_alg key_mgmt proto ssid psk wep_key0 wep_tx_keyidx + local country_code="$(wireless_get_reg_domain)" case "${mode}" in # Normal WPA. diff --git a/src/helpers/hostapd-config-helper b/src/helpers/hostapd-config-helper index 668945b0..5ad2d761 100644 --- a/src/helpers/hostapd-config-helper +++ b/src/helpers/hostapd-config-helper @@ -37,7 +37,6 @@ case "${action}" in hostapd_config_write ${port} ${config_file} \ --broadcast-ssid="${BROADCAST_SSID}" \ --channel="${CHANNEL}" \ - --country-code="${COUNTRY_CODE}" \ --encryption="${ENCRYPTION}" \ --key="${KEY}" \ --mode="${MODE}" \ diff --git a/src/hooks/ports/batman-adv-port b/src/hooks/ports/batman-adv-port index bfa73215..b14351e0 100644 --- a/src/hooks/ports/batman-adv-port +++ b/src/hooks/ports/batman-adv-port @@ -21,11 +21,10 @@ . /usr/lib/network/header-port -HOOK_SETTINGS="HOOK ADDRESS MESH_ID SSID CHANNEL COUNTRY_CODE PHY" +HOOK_SETTINGS="HOOK ADDRESS MESH_ID SSID CHANNEL PHY" ADDRESS=$(mac_generate) CHANNEL=1 -COUNTRY_CODE="US" MESH_ID= SSID= @@ -37,7 +36,6 @@ function hook_check() { assert isset ADDRESS assert ismac ADDRESS assert isset CHANNEL - assert isset COUNTRY_CODE assert isset MESH_ID assert ismac MESH_ID assert isset PHY @@ -54,9 +52,6 @@ function hook_create() { --channel=*) CHANNEL=$(cli_get_val ${1}) ;; - --country-code=*) - COUNTRY_CODE=$(cli_get_val ${1}) - ;; --phy=*) PHY=$(cli_get_val ${1}) ;; @@ -97,9 +92,6 @@ function hook_edit() { --channel=*) CHANNEL=$(cli_get_val ${1}) ;; - --country-code=*) - COUNTRY_CODE=$(cli_get_val ${1}) - ;; --mesh-id=*) MESH_ID=$(cli_get_val ${1}) ;; diff --git a/src/hooks/ports/wireless-ap b/src/hooks/ports/wireless-ap index c6d91da0..ba8a7fd5 100644 --- a/src/hooks/ports/wireless-ap +++ b/src/hooks/ports/wireless-ap @@ -21,13 +21,12 @@ . /usr/lib/network/header-port -HOOK_SETTINGS="HOOK ADDRESS BROADCAST_SSID CHANNEL COUNTRY_CODE MODE PHY SSID" +HOOK_SETTINGS="HOOK ADDRESS BROADCAST_SSID CHANNEL MODE PHY SSID" HOOK_SETTINGS="${HOOK_SETTINGS} ENCRYPTION KEY" ADDRESS=$(mac_generate) BROADCAST_SSID=on CHANNEL=1 -COUNTRY_CODE="US" ENCRYPTION="" KEY="" MODE="g" @@ -39,7 +38,6 @@ function hook_check() { assert isset BROADCAST_SSID assert isbool BROADCAST_SSID assert isset CHANNEL - assert isset COUNTRY_CODE assert isset MODE assert isoneof MODE a b g n assert isset PHY @@ -64,9 +62,6 @@ function hook_create() { --channel=*) CHANNEL=$(cli_get_val ${1}) ;; - --country-code=*) - COUNTRY_CODE=$(cli_get_val ${1}) - ;; --encryption=*) ENCRYPTION=$(cli_get_val ${1}) ;; @@ -120,9 +115,6 @@ function hook_edit() { --channel=*) CHANNEL=$(cli_get_val ${1}) ;; - --country-code=*) - COUNTRY_CODE=$(cli_get_val ${1}) - ;; --encryption=*) ENCRYPTION=$(cli_get_val ${1}) ;; diff --git a/src/hooks/zones/batman-adv b/src/hooks/zones/batman-adv index 7390114e..23aa66d7 100644 --- a/src/hooks/zones/batman-adv +++ b/src/hooks/zones/batman-adv @@ -21,12 +21,11 @@ . /usr/lib/network/header-zone -HOOK_SETTINGS="HOOK ADDRESS MESH_ID SSID CHANNEL COUNTRY_CODE PHY" +HOOK_SETTINGS="HOOK ADDRESS MESH_ID SSID CHANNEL PHY" # Default values ADDRESS=$(mac_generate) CHANNEL=1 -COUNTRY_CODE="US" MESH_ID= SSID= @@ -38,7 +37,6 @@ function hook_check() { assert isset ADDRESS assert ismac ADDRESS assert isset CHANNEL - assert isset COUNTRY_CODE assert isset MESH_ID assert ismac MESH_ID assert isset PHY @@ -55,9 +53,6 @@ function hook_parse_cmdline() { --channel=*) CHANNEL="$(cli_get_val ${1})" ;; - --country-code=*) - COUNTRY_CODE="$(cli_get_val ${1})" - ;; --mesh-id=*) MESH_ID="$(cli_get_val ${1})" ;;