Skip to content

Commit

Permalink
Enable ssid parametrization
Browse files Browse the repository at this point in the history
  • Loading branch information
G10h4ck committed Dec 15, 2014
1 parent 721707d commit 0595c1b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
13 changes: 11 additions & 2 deletions packages/lime-system/files/etc/config/lime
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# The options marked with "# Parametrizable with %Mn, %Nn, %H"
# can include %Mn templates that will be substituted
# with the n'th byte of the primary_interface MAC
# and %Nn templates that will be replaced by the n'th network-identifier byte,
# calculated from the hash of the ap_ssid value, so that all the nodes that
# form a mesh cloud (share the same ap_ssid) will produce the same value
# and %H template that will be replaced by hostname


### System options

#config lime system
# option hostname 'LiMeNode-%M4%M5%M6' # Parametrizable with %Mn, %Nn
# option hostname 'LiMeNode-%M4%M5%M6' # Parametrizable with %Mn


### Network general option
Expand All @@ -28,7 +37,7 @@
# list modes 'ap'
# list modes 'adhoc'
# option ap_ssid 'LiMe'
# option adhoc_ssid 'libre-mesh'
# option adhoc_ssid 'libre-mesh' # Parametrizable with %M, %H
# option adhoc_bssid 'ca:fe:00:c0:ff:ee'
# option adhoc_mcast_rate_2ghz '24000'
# option adhoc_mcast_rate_5ghz '6000'
Expand Down
27 changes: 6 additions & 21 deletions packages/lime-system/files/etc/config/lime-defaults
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
# Beware this file is not supposed to being edited, look at /etc/config/lime
# Beware this file is not supposed to store specific configuration, like "config net eth0"

# The options marked with "# Parametrizable with %Mn, %Nn"
# can include %Mn templates that will be substituted
# with the n'th byte of the primary_interface MAC
# and %Nn templates that will be replaced by a "network-identifier" byte,
# calculated from the hash of the ap_ssid value, so that all the nodes that
# form a mesh cloud (share the same ap_ssid) will produce the same value

# System option

config lime system
option hostname 'LiMeNode-%M4%M5%M6' # Parametrizable with %Mn, %Nn


# Network general option
option hostname 'LiMeNode-%M4%M5%M6'

config lime network
option primary_interface eth0 # The mac address of this device will be used in different places
option main_ipv4_address '192.0.2.0/24' # Parametrizable with %Mn, %Nn
option main_ipv6_address '2001:db8::%M5:%M6/64' # Parametrizable with %Mn, %Nn
option primary_interface eth0
option main_ipv4_address '192.0.2.0/24'
option main_ipv6_address '2001:db8::%M5:%M6/64'
list protocols adhoc
list protocols lan
list protocols anygw
list protocols batadv:%N1 # Parametrizable with %Nn
list protocols batadv:%N1
list protocols bmx6:13
list resolvers 8.8.8.8 # DNS servers node will use
list resolvers 8.8.8.8
list resolvers 2001:4860:4860::8844


# WiFi general options

config lime wifi
option channel_2ghz '11'
option channel_5ghz '48'
Expand Down
7 changes: 5 additions & 2 deletions packages/lime-system/files/usr/lib/lua/lime/system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ local utils = require("lime.utils")

system = {}

function system.set_hostname()
local hostname = utils.applyMacTemplate16(config.get("system", "hostname"), network.primary_mac())
function system.get_hostname()
return utils.applyMacTemplate16(config.get("system", "hostname"), network.primary_mac())
end

function system.set_hostname()
local hostname = system.get_hostname()
local uci = libuci:cursor()
uci:foreach("system", "system", function(s) uci:set("system", s[".name"], "hostname", hostname) end)
uci:save("system")
Expand Down
5 changes: 5 additions & 0 deletions packages/lime-system/files/usr/lib/lua/lime/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
utils = {}

local config = require("lime.config")
local system = require("lime.system")

function utils.split(string, sep)
local ret = {}
Expand Down Expand Up @@ -52,6 +53,10 @@ function utils.applyMacTemplate10(template, mac)
return template
end

function utils.applyHostnameTemplate(template)
return template:gsub("%%H", system.get_hostname())
end

function utils.network_id()
local network_essid = config.get("wifi", "ap_ssid")
local netid = {}
Expand Down
5 changes: 5 additions & 0 deletions packages/lime-system/files/usr/lib/lua/lime/wireless.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

local config = require("lime.config")
local network = require("lime.network")
local utils = require("lime.utils")
local libuci = require("uci")
local fs = require("nixio.fs")

Expand Down Expand Up @@ -124,6 +125,10 @@ function wireless.configure()

if isGoodOption then
local nk = key:gsub("^"..modeName.."_", ""):gsub(freqSuffix.."$", "")
if nk == "ssid" then
value = utils.applyHostnameTemplate(value)
value = utils.applyMacTemplate16(value, network.primary_mac())
end

uci:set("wireless", wirelessInterfaceName, nk, value)
end
Expand Down

0 comments on commit 0595c1b

Please sign in to comment.