mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2025-05-10 19:13:22 +02:00
Access point can now be made on start up and the activated network config is always moved to the top so it's picked on startup
This commit is contained in:
parent
880e090cfe
commit
524d41e39b
src
@ -53,6 +53,7 @@ local function setupAutoWifiMode()
|
|||||||
-- try to find a known network which is also visible (ordered by known network definitions)
|
-- try to find a known network which is also visible (ordered by known network definitions)
|
||||||
local connectWith = nil
|
local connectWith = nil
|
||||||
for _,kn in ipairs(knownSsids) do
|
for _,kn in ipairs(knownSsids) do
|
||||||
|
if kn.mode == 'ap' and kn.ssid == apSsid then break end
|
||||||
if findSsidInList(scanList, kn.ssid) then
|
if findSsidInList(scanList, kn.ssid) then
|
||||||
connectWith = kn.ssid
|
connectWith = kn.ssid
|
||||||
break
|
break
|
||||||
|
@ -34,6 +34,7 @@ local function bothBits(dlist, itemname) dlist[itemname] = 'b' end
|
|||||||
function M.init(wifiInstance, reloadSilent)
|
function M.init(wifiInstance, reloadSilent)
|
||||||
wifi = wifiInstance
|
wifi = wifiInstance
|
||||||
silent = reloadSilent or false
|
silent = reloadSilent or false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -289,7 +290,8 @@ function M.associateSsid(ssid, passphrase, recreate)
|
|||||||
-- try to associate with the network
|
-- try to associate with the network
|
||||||
wifi.activateConfig(ssid)
|
wifi.activateConfig(ssid)
|
||||||
--M.switchConfiguration{ wifiiface="add", apnet="rm", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wwwcaptive="rm", wireless="reload" }
|
--M.switchConfiguration{ wifiiface="add", apnet="rm", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wwwcaptive="rm", wireless="reload" }
|
||||||
M.switchConfiguration{ wifiiface="add", apnet="rm", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wireless="reload" }
|
--M.switchConfiguration{ wifiiface="add", apnet="rm", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wireless="reload" }
|
||||||
|
M.switchConfiguration{ wifiiface="add", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wireless="reload" }
|
||||||
|
|
||||||
-- check if we are actually associated
|
-- check if we are actually associated
|
||||||
local status = wifi.getDeviceState()
|
local status = wifi.getDeviceState()
|
||||||
|
@ -19,12 +19,12 @@ local cachedApSsid, baseApSsid = nil, nil
|
|||||||
function M.getSubstitutedSsid(unformattedSsid)
|
function M.getSubstitutedSsid(unformattedSsid)
|
||||||
if unformattedSsid == baseApSsid and cachedApSsid ~= nil then return cachedApSsid end
|
if unformattedSsid == baseApSsid and cachedApSsid ~= nil then return cachedApSsid end
|
||||||
if not unformattedSsid or type(unformattedSsid) ~= 'string' then return nil end
|
if not unformattedSsid or type(unformattedSsid) ~= 'string' then return nil end
|
||||||
|
|
||||||
local macTail = M.getMacAddress():sub(7)
|
local macTail = M.getMacAddress():sub(7)
|
||||||
|
|
||||||
baseApSsid = unformattedSsid
|
baseApSsid = unformattedSsid
|
||||||
cachedApSsid = unformattedSsid:gsub('%%%%MAC_ADDR_TAIL%%%%', macTail)
|
cachedApSsid = unformattedSsid:gsub('%%%%MAC_ADDR_TAIL%%%%', macTail)
|
||||||
|
|
||||||
return cachedApSsid
|
return cachedApSsid
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -48,10 +48,10 @@ end
|
|||||||
]]
|
]]
|
||||||
function M.mapEncryptionType(scanEncrTbl)
|
function M.mapEncryptionType(scanEncrTbl)
|
||||||
local wpaModeMap = { [1] = 'psk', [2] = 'psk2', [3] = 'mixed-psk' }
|
local wpaModeMap = { [1] = 'psk', [2] = 'psk2', [3] = 'mixed-psk' }
|
||||||
|
|
||||||
if scanEncrTbl.enabled == false then return 'none' end
|
if scanEncrTbl.enabled == false then return 'none' end
|
||||||
if scanEncrTbl.wep == true then return 'wep' end
|
if scanEncrTbl.wep == true then return 'wep' end
|
||||||
|
|
||||||
return wpaModeMap[scanEncrTbl.wpa] or scanEncrTbl.description
|
return wpaModeMap[scanEncrTbl.wpa] or scanEncrTbl.description
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -66,9 +66,9 @@ function M.init(device)
|
|||||||
local devInitial = deviceName
|
local devInitial = deviceName
|
||||||
deviceName = M.DFL_DEVICE_FALLBACK
|
deviceName = M.DFL_DEVICE_FALLBACK
|
||||||
deviceApi = iwinfo.type(deviceName)
|
deviceApi = iwinfo.type(deviceName)
|
||||||
|
|
||||||
log:info("wireless device '" .. devInitial .. "' not found, trying fallback '" .. deviceName .. "'")
|
log:info("wireless device '" .. devInitial .. "' not found, trying fallback '" .. deviceName .. "'")
|
||||||
|
|
||||||
if not deviceApi then
|
if not deviceApi then
|
||||||
return false, "No such wireless device: '" .. devInitial .. "' (and fallback '" .. deviceName .. "' does not exist either)"
|
return false, "No such wireless device: '" .. devInitial .. "' (and fallback '" .. deviceName .. "' does not exist either)"
|
||||||
end
|
end
|
||||||
@ -101,15 +101,15 @@ end
|
|||||||
function M.getMacAddress()
|
function M.getMacAddress()
|
||||||
local macText = utils.readFile('/sys/class/net/' .. deviceName .. '/address')
|
local macText = utils.readFile('/sys/class/net/' .. deviceName .. '/address')
|
||||||
local out = ''
|
local out = ''
|
||||||
|
|
||||||
-- Hack to prevent failure in case the MAC address could not be obtained.
|
-- Hack to prevent failure in case the MAC address could not be obtained.
|
||||||
if not macText or macText == '' then return "000000000000" end
|
if not macText or macText == '' then return "000000000000" end
|
||||||
|
|
||||||
for i = 0, 5 do
|
for i = 0, 5 do
|
||||||
local bt = string.sub(macText, i*3+1, i*3+2)
|
local bt = string.sub(macText, i*3+1, i*3+2)
|
||||||
out = out .. bt
|
out = out .. bt
|
||||||
end
|
end
|
||||||
|
|
||||||
return out:upper()
|
return out:upper()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -121,6 +121,7 @@ end
|
|||||||
-- @param ssid return data for given SSID or for all networks if SSID not given
|
-- @param ssid return data for given SSID or for all networks if SSID not given
|
||||||
-- @return data for all or requested network; false+error on failure or nil when requested network not found
|
-- @return data for all or requested network; false+error on failure or nil when requested network not found
|
||||||
function M.getScanInfo(ssid)
|
function M.getScanInfo(ssid)
|
||||||
|
|
||||||
local iw = iwinfo[deviceApi]
|
local iw = iwinfo[deviceApi]
|
||||||
local sr = iw.scanlist(deviceName)
|
local sr = iw.scanlist(deviceName)
|
||||||
local si, se
|
local si, se
|
||||||
@ -167,11 +168,35 @@ end
|
|||||||
--- Activate wireless section for given SSID and disable all others
|
--- Activate wireless section for given SSID and disable all others
|
||||||
-- @param ssid SSID of config to enable, or nil to disable all network configs
|
-- @param ssid SSID of config to enable, or nil to disable all network configs
|
||||||
function M.activateConfig(ssid)
|
function M.activateConfig(ssid)
|
||||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
|
||||||
|
--local utils = require('util.utils')
|
||||||
|
--local log = require('util.logger')
|
||||||
|
--log:info("wlanconfig:activateConfig: "..utils.dump(ssid))
|
||||||
|
|
||||||
|
-- make sure only one is enabled
|
||||||
|
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||||
local disabled = s.ssid ~= ssid and '1' or '0'
|
local disabled = s.ssid ~= ssid and '1' or '0'
|
||||||
|
--log:info(" "..utils.dump(s.ssid).." disable: "..utils.dump(disabled))
|
||||||
uci:set('wireless', s['.name'], 'disabled', disabled)
|
uci:set('wireless', s['.name'], 'disabled', disabled)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
uci:commit('wireless')
|
uci:commit('wireless')
|
||||||
|
|
||||||
|
-- make sure the wifi-device radio0 is on top
|
||||||
|
uci:reorder('wireless', 'radio0', 0)
|
||||||
|
|
||||||
|
uci:commit('wireless')
|
||||||
|
|
||||||
|
-- put it on top of the wireless configuration so it's the first option when the devices starts
|
||||||
|
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||||
|
if s.ssid == ssid then
|
||||||
|
uci:reorder('wireless', s['.name'], 1)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
uci:commit('wireless')
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create a new UCI network from the given iwinfo data
|
--- Create a new UCI network from the given iwinfo data
|
||||||
@ -193,7 +218,7 @@ function M.createConfigFromScanInfo(info, passphrase, disabled)
|
|||||||
}
|
}
|
||||||
if passphrase ~= nil then apconfig.key = passphrase end
|
if passphrase ~= nil then apconfig.key = passphrase end
|
||||||
apconfig.disabled = disabled ~= nil and disabled and 1 or 0
|
apconfig.disabled = disabled ~= nil and disabled and 1 or 0
|
||||||
|
|
||||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||||
if s.bssid == info.bssid then
|
if s.bssid == info.bssid then
|
||||||
log:debug("removing old wireless config for net '" .. s.ssid .. "(bssid: " .. s.bssid .. ")'")
|
log:debug("removing old wireless config for net '" .. s.ssid .. "(bssid: " .. s.bssid .. ")'")
|
||||||
@ -201,7 +226,7 @@ function M.createConfigFromScanInfo(info, passphrase, disabled)
|
|||||||
-- return false --keep looking, just in case multiple entries with this bssid exist
|
-- return false --keep looking, just in case multiple entries with this bssid exist
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local sname = uci:add('wireless', 'wifi-iface');
|
local sname = uci:add('wireless', 'wifi-iface');
|
||||||
for k, v in pairs(apconfig) do
|
for k, v in pairs(apconfig) do
|
||||||
uci:set('wireless', sname, k, v)
|
uci:set('wireless', sname, k, v)
|
||||||
|
@ -110,7 +110,7 @@ function M.associate_POST(request, response)
|
|||||||
end
|
end
|
||||||
response:addPostResponseFunction(associate)
|
response:addPostResponseFunction(associate)
|
||||||
|
|
||||||
local helloA = function()
|
--[[local helloA = function()
|
||||||
local log = require('util.logger')
|
local log = require('util.logger')
|
||||||
log:info("HELLO A")
|
log:info("HELLO A")
|
||||||
end
|
end
|
||||||
@ -120,7 +120,7 @@ function M.associate_POST(request, response)
|
|||||||
local log = require('util.logger')
|
local log = require('util.logger')
|
||||||
log:info("HELLO B")
|
log:info("HELLO B")
|
||||||
end
|
end
|
||||||
response:addPostResponseFunction(helloB)
|
response:addPostResponseFunction(helloB)]]--
|
||||||
|
|
||||||
--[[response:addData("ssid", argSsid)
|
--[[response:addData("ssid", argSsid)
|
||||||
if rv then
|
if rv then
|
||||||
|
@ -80,17 +80,13 @@ function M:addData(k, v)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M:addPostResponseFunction(fn)
|
function M:addPostResponseFunction(fn)
|
||||||
local utils = require('util.utils')
|
|
||||||
local log = require('util.logger')
|
|
||||||
log:info("Response:addPostResponseFunction: " .. utils.dump(fn))
|
|
||||||
table.insert(self.postResponseQueue, fn)
|
table.insert(self.postResponseQueue, fn)
|
||||||
log:info(" self.postResponseQueue: " .. utils.dump(self.postResponseQueue))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:executePostResponseQueue()
|
function M:executePostResponseQueue()
|
||||||
local utils = require('util.utils')
|
--local utils = require('util.utils')
|
||||||
local log = require('util.logger')
|
--local log = require('util.logger')
|
||||||
log:info("Response:executePostResponseQueue: " .. utils.dump(self.postResponseQueue))
|
--log:info("Response:executePostResponseQueue: " .. utils.dump(self.postResponseQueue))
|
||||||
|
|
||||||
for i,fn in ipairs(self.postResponseQueue) do fn() end
|
for i,fn in ipairs(self.postResponseQueue) do fn() end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user