Created
September 15, 2014 17:28
-
-
Save neocturne/edc838febbd19ef03eda to your computer and use it in GitHub Desktop.
20-wireless
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 index = 0 | |
local function configure_radio(device) | |
local radio = device['.name'] | |
local hwmode = uci:get('wireless', radio, 'hwmode') | |
local client_macaddr = util.generate_mac(2, index) | |
local mesh_macaddr = util.generate_mac(3, index) | |
index = index + 1 | |
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: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 | |
uci:delete('wireless', client) | |
uci:section('wireless', 'wifi-iface', client, | |
{ | |
device = radio, | |
network = 'client', | |
mode = 'ap', | |
ssid = config.ssid, | |
macaddr = client_macaddr, | |
} | |
) | |
local mesh = 'mesh_' .. radio | |
uci:delete('network', mesh) | |
uci:section('network', 'interface', mesh, | |
{ | |
proto = 'batadv', | |
mtu = '1528', | |
mesh = 'bat0', | |
} | |
) | |
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 = mesh_macaddr, | |
mcast_rate = config.mesh_mcast_rate, | |
} | |
) | |
return true | |
end | |
uci:foreach('wireless', 'wifi-device', configure_radio) | |
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