|
@@ -6,110 +6,146 @@ local util = require 'gluon.util'
|
|
local uci = require('luci.model.uci').cursor()
|
|
local uci = require('luci.model.uci').cursor()
|
|
|
|
|
|
|
|
|
|
-local function configure_radio(radio, index, config)
|
|
|
|
- uci:delete('wireless', radio, 'disabled')
|
|
|
|
-
|
|
|
|
- uci:set('wireless', radio, 'channel', config.channel)
|
|
|
|
- uci:set('wireless', radio, 'htmode', config.htmode)
|
|
|
|
- uci:set('wireless', radio, 'country', site.regdom)
|
|
|
|
-
|
|
|
|
- local client = 'client_' .. radio
|
|
|
|
- local mesh = 'mesh_' .. radio
|
|
|
|
|
|
+local function is_disabled(config, name)
|
|
|
|
+ local disabled = config and config.disabled
|
|
|
|
+ if uci:get('wireless', name) then
|
|
|
|
+ disabled = uci:get_bool('wireless', name, 'disabled')
|
|
|
|
+ end
|
|
|
|
|
|
- local disable_state_client = false
|
|
|
|
- local disable_state_mesh = false
|
|
|
|
|
|
+ return disabled and 1 or 0
|
|
|
|
+end
|
|
|
|
|
|
- if uci:get('wireless', client) then
|
|
|
|
- disable_state_client = uci:get_bool('wireless', client, "disabled")
|
|
|
|
- elseif config.client_disabled then
|
|
|
|
- disable_state_client = true
|
|
|
|
|
|
+local function configure_client(config, radio, index, suffix)
|
|
|
|
+ local name = 'client_' .. radio
|
|
|
|
+ local disabled = is_disabled(config, name)
|
|
|
|
+
|
|
|
|
+ uci:delete('wireless', name)
|
|
|
|
+
|
|
|
|
+ if config then
|
|
|
|
+ uci:section('wireless', 'wifi-iface', name,
|
|
|
|
+ {
|
|
|
|
+ device = radio,
|
|
|
|
+ network = 'client',
|
|
|
|
+ mode = 'ap',
|
|
|
|
+ ssid = config.ssid,
|
|
|
|
+ macaddr = util.generate_mac(2, index),
|
|
|
|
+ ifname = suffix and 'client' .. suffix,
|
|
|
|
+ disabled = disabled,
|
|
|
|
+ }
|
|
|
|
+ )
|
|
end
|
|
end
|
|
|
|
+end
|
|
|
|
|
|
- if uci:get('wireless', mesh) then
|
|
|
|
- disable_state_mesh = uci:get_bool('wireless', mesh, "disabled")
|
|
|
|
- elseif config.mesh_disabled then
|
|
|
|
- disable_state_mesh = true
|
|
|
|
|
|
+local function configure_ibss(config, radio, index, suffix)
|
|
|
|
+ local name = 'ibss_' .. radio
|
|
|
|
+ local disabled = is_disabled(config, name)
|
|
|
|
+
|
|
|
|
+ uci:delete('network', name)
|
|
|
|
+ uci:delete('network', name .. '_vlan')
|
|
|
|
+ uci:delete('wireless', name)
|
|
|
|
+
|
|
|
|
+ if config then
|
|
|
|
+ if config.vlan then
|
|
|
|
+ uci:section('network', 'interface', name,
|
|
|
|
+ {
|
|
|
|
+ proto = 'none',
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ uci:section('network', 'interface', name .. '_vlan',
|
|
|
|
+ {
|
|
|
|
+ ifname = '@' .. name .. '.' .. config.vlan,
|
|
|
|
+ proto = 'batadv',
|
|
|
|
+ mesh = 'bat0',
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ else
|
|
|
|
+ uci:section('network', 'interface', name,
|
|
|
|
+ {
|
|
|
|
+ proto = 'batadv',
|
|
|
|
+ mesh = 'bat0',
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ uci:section('wireless', 'wifi-iface', name,
|
|
|
|
+ {
|
|
|
|
+ device = radio,
|
|
|
|
+ network = name,
|
|
|
|
+ mode = 'adhoc',
|
|
|
|
+ ssid = config.ssid,
|
|
|
|
+ bssid = config.bssid,
|
|
|
|
+ macaddr = util.generate_mac(3, index),
|
|
|
|
+ mcast_rate = config.mcast_rate,
|
|
|
|
+ ifname = suffix and 'ibss' .. suffix,
|
|
|
|
+ disabled = disabled,
|
|
|
|
+ }
|
|
|
|
+ )
|
|
end
|
|
end
|
|
|
|
+end
|
|
|
|
|
|
- local client_ifname
|
|
|
|
- local mesh_ifname
|
|
|
|
- local radio_suffix = radio:match('^radio(%d+)$')
|
|
|
|
- if radio_suffix then
|
|
|
|
- client_ifname = 'client' .. radio_suffix
|
|
|
|
- mesh_ifname = 'mesh' .. radio_suffix
|
|
|
|
|
|
+local function configure_mesh(config, radio, index, suffix)
|
|
|
|
+ local name = 'mesh_' .. radio
|
|
|
|
+ local disabled = is_disabled(config, name)
|
|
|
|
+
|
|
|
|
+ uci:delete('network', name)
|
|
|
|
+ uci:delete('wireless', name)
|
|
|
|
+
|
|
|
|
+ if config then
|
|
|
|
+ uci:section('network', 'interface', name,
|
|
|
|
+ {
|
|
|
|
+ proto = 'batadv',
|
|
|
|
+ mesh = 'bat0',
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ uci:section('wireless', 'wifi-iface', name,
|
|
|
|
+ {
|
|
|
|
+ device = radio,
|
|
|
|
+ network = name,
|
|
|
|
+ mode = 'mesh',
|
|
|
|
+ mesh_id = config.id,
|
|
|
|
+ mesh_fwding = 0,
|
|
|
|
+ macaddr = util.generate_mac(5, index),
|
|
|
|
+ mcast_rate = config.mcast_rate,
|
|
|
|
+ ifname = suffix and 'mesh' .. suffix,
|
|
|
|
+ disabled = disabled,
|
|
|
|
+ }
|
|
|
|
+ )
|
|
end
|
|
end
|
|
|
|
+end
|
|
|
|
|
|
- uci:delete('wireless', client)
|
|
|
|
- uci:section('wireless', 'wifi-iface', client,
|
|
|
|
- {
|
|
|
|
- device = radio,
|
|
|
|
- network = 'client',
|
|
|
|
- mode = 'ap',
|
|
|
|
- ssid = config.ssid,
|
|
|
|
- macaddr = util.generate_mac(2, index),
|
|
|
|
- ifname = client_ifname,
|
|
|
|
- disabled = disable_state_client and 1 or 0,
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- uci:delete('network', mesh)
|
|
|
|
- uci:delete('network', mesh .. '_vlan')
|
|
|
|
-
|
|
|
|
- if config.mesh_vlan then
|
|
|
|
- uci:section('network', 'interface', mesh,
|
|
|
|
- {
|
|
|
|
- proto = 'none',
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
- uci:section('network', 'interface', mesh .. '_vlan',
|
|
|
|
- {
|
|
|
|
- ifname = '@' .. mesh .. '.' .. config.mesh_vlan,
|
|
|
|
- proto = 'batadv',
|
|
|
|
- mesh = 'bat0',
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
- else
|
|
|
|
- uci:section('network', 'interface', mesh,
|
|
|
|
- {
|
|
|
|
- proto = 'batadv',
|
|
|
|
- mesh = 'bat0',
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
- end
|
|
|
|
|
|
+local function configure_radio(radio, index, config)
|
|
|
|
+ local suffix = radio:match('^radio(%d+)$')
|
|
|
|
|
|
- uci:delete('wireless', mesh)
|
|
|
|
- uci:section('wireless', 'wifi-iface', mesh,
|
|
|
|
- {
|
|
|
|
- device = radio,
|
|
|
|
- network = mesh,
|
|
|
|
- mode = 'adhoc',
|
|
|
|
- ssid = config.mesh_ssid,
|
|
|
|
- bssid = config.mesh_bssid,
|
|
|
|
- macaddr = util.generate_mac(3, index),
|
|
|
|
- mcast_rate = config.mesh_mcast_rate,
|
|
|
|
- ifname = mesh_ifname,
|
|
|
|
- disabled = disable_state_mesh and 1 or 0,
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
|
|
+ uci:delete('wireless', radio, 'disabled')
|
|
|
|
+
|
|
|
|
+ uci:set('wireless', radio, 'channel', config.channel)
|
|
|
|
+ uci:set('wireless', radio, 'htmode', config.htmode)
|
|
|
|
+ uci:set('wireless', radio, 'country', site.regdom)
|
|
|
|
+
|
|
|
|
+ configure_client(config.ap, radio, index, suffix)
|
|
|
|
+ configure_ibss(config.ibss, radio, index, suffix)
|
|
|
|
+ configure_mesh(config.mesh, radio, index, suffix)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
local radios = {}
|
|
local radios = {}
|
|
|
|
|
|
uci:foreach('wireless', 'wifi-device',
|
|
uci:foreach('wireless', 'wifi-device',
|
|
- function(s)
|
|
|
|
- table.insert(radios, s['.name'])
|
|
|
|
- end
|
|
|
|
|
|
+ function(s)
|
|
|
|
+ table.insert(radios, s['.name'])
|
|
|
|
+ end
|
|
)
|
|
)
|
|
|
|
|
|
for index, radio in ipairs(radios) do
|
|
for index, radio in ipairs(radios) do
|
|
- local hwmode = uci:get('wireless', radio, 'hwmode')
|
|
|
|
|
|
+ local hwmode = uci:get('wireless', radio, 'hwmode')
|
|
|
|
|
|
- if hwmode == '11g' or hwmode == '11ng' then
|
|
|
|
- configure_radio(radio, index, site.wifi24)
|
|
|
|
- elseif hwmode == '11a' or hwmode == '11na' then
|
|
|
|
- configure_radio(radio, index, site.wifi5)
|
|
|
|
- end
|
|
|
|
|
|
+ if hwmode == '11g' or hwmode == '11ng' then
|
|
|
|
+ configure_radio(radio, index, site.wifi24)
|
|
|
|
+ elseif hwmode == '11a' or hwmode == '11na' then
|
|
|
|
+ configure_radio(radio, index, site.wifi5)
|
|
|
|
+ end
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|