Last active
August 29, 2015 14:25
-
-
Save tcatm/6d21ff87dadb7dcec832 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/lua | |
local site = require 'gluon.site_config' | |
local util = require 'gluon.util' | |
local uci = require('luci.model.uci').cursor() | |
local function is_disabled(config, name) | |
local disabled = config.disabled | |
if uci:get('wireless', name) then | |
disabled = uci:get_bool('wireless', name, 'disabled') | |
end | |
return disabled and 1 or 0 | |
end | |
local function configure_client(config, index, name, ifname) | |
local disabled = is_disabled(config, name) | |
uci:delete('wireless', name) | |
if config ~= nil then | |
uci:section('wireless', 'wifi-iface', name, | |
{ | |
device = radio, | |
network = 'client', | |
mode = 'ap', | |
ssid = config.ssid, | |
macaddr = util.generate_mac(2, index), | |
ifname = ifname, | |
disabled = disabled, | |
} | |
) | |
end | |
end | |
local function configure_ibss(config, index, name, ifname) | |
local disabled = is_disabled(config, name) | |
uci:delete('network', name) | |
uci:delete('network', name .. '_vlan') | |
uci:delete('wireless', name) | |
if config ~= nil 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 = ifname, | |
disabled = disabled, | |
} | |
) | |
end | |
end | |
local function configure_mesh(config, index, name, ifname) | |
local disabled = is_disabled(config, name) | |
uci:delete('network', name) | |
uci:delete('wireless', name) | |
if config ~= nil 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 = ifname, | |
disabled = disabled, | |
} | |
) | |
end | |
end | |
local function configure_radio(radio, index, config) | |
local suffix = radio:match('^radio(%d+)$') | |
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.master, index, 'client_' .. radio, suffix and 'client' .. suffix) | |
configure_ibss(config.master, index, 'ibss_' .. radio, suffix and 'ibss' .. suffix) | |
configure_mesh(config.master, index, 'mesh_' .. radio, suffix and 'mesh' .. suffix) | |
end | |
local radios = {} | |
uci:foreach('wireless', 'wifi-device', | |
function(s) | |
table.insert(radios, s['.name']) | |
end | |
) | |
for index, radio in ipairs(radios) do | |
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 | |
end | |
uci:save('wireless') | |
uci:save('network') | |
uci:commit('wireless') | |
uci:commit('network') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment