|
@@ -1,69 +1,76 @@
|
|
|
#!/usr/bin/lua
|
|
|
|
|
|
local site = require 'gluon.site_config'
|
|
|
-local uci = require 'luci.model.uci'
|
|
|
+local util = require 'gluon.util'
|
|
|
|
|
|
-local c = uci.cursor()
|
|
|
+local uci = require('luci.model.uci').cursor()
|
|
|
|
|
|
|
|
|
-local function configure_radio(device)
|
|
|
- local radio = device['.name']
|
|
|
- local hwmode = c:get('wireless', radio, 'hwmode')
|
|
|
+local function configure_radio(radio, index, config)
|
|
|
+ uci:delete('wireless', radio, 'disabled')
|
|
|
|
|
|
- local config
|
|
|
- if hwmode == '11g' or hwmode == '11ng' then
|
|
|
- config = site.wifi24
|
|
|
- elseif hwmode == '11a' or hwmode == '11na' then
|
|
|
- config = site.wifi5
|
|
|
- else
|
|
|
- return true
|
|
|
- end
|
|
|
+ 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
|
|
|
+ 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),
|
|
|
+ }
|
|
|
+ )
|
|
|
|
|
|
- c:delete('wireless', radio, 'disabled')
|
|
|
+ local mesh = 'mesh_' .. radio
|
|
|
+ uci:delete('network', mesh)
|
|
|
+ uci:section('network', 'interface', mesh,
|
|
|
+ {
|
|
|
+ proto = 'batadv',
|
|
|
+ mtu = '1528',
|
|
|
+ mesh = 'bat0',
|
|
|
+ }
|
|
|
+ )
|
|
|
|
|
|
- c:set('wireless', radio, 'channel', config.channel)
|
|
|
- c:set('wireless', radio, 'htmode', config.htmode)
|
|
|
- c:set('wireless', radio, 'country', site.regdom)
|
|
|
+ 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,
|
|
|
+ }
|
|
|
+ )
|
|
|
+end
|
|
|
|
|
|
- local client = 'client_' .. radio
|
|
|
- c:delete('wireless', client)
|
|
|
- c:section('wireless', 'wifi-iface', client,
|
|
|
- {
|
|
|
- device = radio,
|
|
|
- network = 'client',
|
|
|
- mode = 'ap',
|
|
|
- ssid = config.ssid,
|
|
|
- }
|
|
|
- )
|
|
|
|
|
|
- local mesh = 'mesh_' .. radio
|
|
|
- c:delete('network', mesh)
|
|
|
- c:section('network', 'interface', mesh,
|
|
|
- {
|
|
|
- proto = 'batadv',
|
|
|
- mtu = '1528',
|
|
|
- mesh = 'bat0',
|
|
|
- }
|
|
|
- )
|
|
|
+local radios = {}
|
|
|
|
|
|
- c:delete('wireless', mesh)
|
|
|
- c:section('wireless', 'wifi-iface', mesh,
|
|
|
- {
|
|
|
- device = radio,
|
|
|
- network = mesh,
|
|
|
- mode = 'adhoc',
|
|
|
- ssid = config.mesh_ssid,
|
|
|
- bssid = config.mesh_bssid,
|
|
|
- mcast_rate = config.mesh_mcast_rate,
|
|
|
- }
|
|
|
- )
|
|
|
+uci:foreach('wireless', 'wifi-device',
|
|
|
+ function(s)
|
|
|
+ table.insert(radios, s['.name'])
|
|
|
+ end
|
|
|
+)
|
|
|
|
|
|
- return true
|
|
|
+for index, radio in ipairs(radios) do
|
|
|
+ local hwmode = uci:get('wireless', radio, 'hwmode')
|
|
|
+
|
|
|
+ local config
|
|
|
+ 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
|
|
|
|
|
|
-c:foreach('wireless', 'wifi-device', configure_radio)
|
|
|
|
|
|
-c:save('wireless')
|
|
|
-c:save('network')
|
|
|
-c:commit('wireless')
|
|
|
-c:commit('network')
|
|
|
+uci:save('wireless')
|
|
|
+uci:save('network')
|
|
|
+uci:commit('wireless')
|
|
|
+uci:commit('network')
|