mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 19:13:49 +01:00
Add kmod-usb-serial-ftdi as package dependency for FTDI-based 3D printers; fix MAC address lookup; fix dhcp configuration when switching to AP mode; rename api functions in network module; minor fixes and changes.
This commit is contained in:
parent
d4b9c39d60
commit
781c3f9ff1
2
Makefile
2
Makefile
@ -32,7 +32,7 @@ define Package/wifibox
|
|||||||
# DEFAULT:=y
|
# DEFAULT:=y
|
||||||
TITLE:=Doodle3D WifiBox firmware
|
TITLE:=Doodle3D WifiBox firmware
|
||||||
URL:=http://www.doodle3d.com/wifibox
|
URL:=http://www.doodle3d.com/wifibox
|
||||||
DEPENDS:=+lua +libuci-lua +libiwinfo-lua +uhttpd +kmod-usb-acm
|
DEPENDS:=+lua +libuci-lua +libiwinfo-lua +uhttpd +kmod-usb-acm +kmod-usb-serial-ftdi
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/wifibox/description
|
define Package/wifibox/description
|
||||||
|
@ -150,8 +150,8 @@ end
|
|||||||
|
|
||||||
--[[ Add/remove DHCP pool for wireless net ]]
|
--[[ Add/remove DHCP pool for wireless net ]]
|
||||||
function reconf.dhcppool_add(dirtyList)
|
function reconf.dhcppool_add(dirtyList)
|
||||||
uci:set('dhcp', wifi.NET, 'dhcp') --create section
|
uci:set('dhcp', wifi.getDeviceName(), 'dhcp') --create section
|
||||||
M.uciTableSet('dhcp', wifi.NET, {
|
M.uciTableSet('dhcp', wifi.getDeviceName(), {
|
||||||
interface = wifi.NET,
|
interface = wifi.NET,
|
||||||
start = '100',
|
start = '100',
|
||||||
limit = '150',
|
limit = '150',
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
local log = require('util.logger')
|
local log = require('util.logger')
|
||||||
|
local utils = require('util.utils')
|
||||||
local uci = require('uci').cursor()
|
local uci = require('uci').cursor()
|
||||||
local iwinfo = require('iwinfo')
|
local iwinfo = require('iwinfo')
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
--NOTE: fallback device 'radio0' is required because sometimes the wlan0 device disappears
|
-- NOTE: fallback device 'radio0' is required because sometimes the wlan0 device disappears
|
||||||
M.DFL_DEVICE = 'wlan0'
|
M.DFL_DEVICE = 'wlan0'
|
||||||
M.DFL_DEVICE_FALLBACK = 'radio0'
|
M.DFL_DEVICE_FALLBACK = 'radio0'
|
||||||
M.NET = 'wlan'
|
M.NET = 'wlan'
|
||||||
|
|
||||||
local dev, dev_api
|
-- NOTE: deviceApi is returned by iwinfo.tpe(deviceName)
|
||||||
|
local deviceName, deviceApi
|
||||||
|
|
||||||
-- if a substitution of baseApSsid is requested, cachedApSsid is returned if not nil
|
-- if a substitution of baseApSsid is requested, cachedApSsid is returned if not nil
|
||||||
local cachedApSsid, baseApSsid = nil, nil
|
local cachedApSsid, baseApSsid = nil, nil
|
||||||
@ -58,17 +60,17 @@ end
|
|||||||
-- @param device wireless device to operate on (optional, defaults to DFL_DEVICE)
|
-- @param device wireless device to operate on (optional, defaults to DFL_DEVICE)
|
||||||
-- @return true on success or false+error on failure
|
-- @return true on success or false+error on failure
|
||||||
function M.init(device)
|
function M.init(device)
|
||||||
-- iwinfo = pcall(require, 'iwinfo')
|
deviceName = device or M.DFL_DEVICE
|
||||||
dev = device or M.DFL_DEVICE
|
deviceApi = iwinfo.type(deviceName)
|
||||||
dev_api = iwinfo.type(dev)
|
if not deviceApi then
|
||||||
if not dev_api then
|
local devInitial = deviceName
|
||||||
--TODO: warn about missing dev here?
|
deviceName = M.DFL_DEVICE_FALLBACK
|
||||||
local devInitial = dev
|
deviceApi = iwinfo.type(deviceName)
|
||||||
dev = M.DFL_DEVICE_FALLBACK
|
|
||||||
dev_api = iwinfo.type(dev)
|
|
||||||
|
|
||||||
if not dev_api then
|
log:info("wireless device '" .. devInitial .. "' not found, trying fallback '" .. deviceName .. "'")
|
||||||
return false, "No such wireless device: '" .. devInitial .. "' (and fallback '" .. dev .. "' does not exist either)"
|
|
||||||
|
if not deviceApi then
|
||||||
|
return false, "No such wireless device: '" .. devInitial .. "' (and fallback '" .. deviceName .. "' does not exist either)"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -77,18 +79,19 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function M.getDeviceState()
|
function M.getDeviceState()
|
||||||
local iw = iwinfo[dev_api]
|
local iw = iwinfo[deviceApi]
|
||||||
|
local encDescription = type(iw.encryption) == 'function' and iw.encryption(deviceName) or '<unknown>'
|
||||||
local result = {
|
local result = {
|
||||||
['ssid'] = iw.ssid(dev),
|
['ssid'] = iw.ssid(deviceName),
|
||||||
['bssid'] = iw.bssid(dev),
|
['bssid'] = iw.bssid(deviceName),
|
||||||
['channel'] = iw.channel(dev),
|
['channel'] = iw.channel(deviceName),
|
||||||
['mode'] = M.mapDeviceMode(iw.mode(dev), true),
|
['mode'] = M.mapDeviceMode(iw.mode(deviceName), true),
|
||||||
['encryption'] = M.mapEncryptionType(iw.encryption(dev).description),
|
['encryption'] = M.mapEncryptionType(encDescription),
|
||||||
['quality'] = iw.quality(dev),
|
['quality'] = iw.quality(deviceName),
|
||||||
['quality_max'] = iw.quality_max(dev),
|
['quality_max'] = iw.quality_max(deviceName),
|
||||||
['txpower'] = iw.txpower(dev),
|
['txpower'] = iw.txpower(deviceName),
|
||||||
['signal'] = iw.signal(dev),
|
['signal'] = iw.signal(deviceName),
|
||||||
['noise'] = iw.noise(dev)
|
['noise'] = iw.noise(deviceName)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
@ -96,8 +99,7 @@ end
|
|||||||
--returns the wireless device's MAC address (as string, without colons)
|
--returns the wireless device's MAC address (as string, without colons)
|
||||||
--(lua numbers on openWrt seem to be 32bit so they cannot represent a MAC address as one number)
|
--(lua numbers on openWrt seem to be 32bit so they cannot represent a MAC address as one number)
|
||||||
function M.getMacAddress()
|
function M.getMacAddress()
|
||||||
local iw = iwinfo[dev_api]
|
local macText = utils.readFile('/sys/class/net/' .. deviceName .. '/address')
|
||||||
local macText = iw.bssid(dev)
|
|
||||||
local out = ''
|
local out = ''
|
||||||
|
|
||||||
for i = 0, 5 do
|
for i = 0, 5 do
|
||||||
@ -105,15 +107,19 @@ function M.getMacAddress()
|
|||||||
out = out .. bt
|
out = out .. bt
|
||||||
end
|
end
|
||||||
|
|
||||||
return out
|
return out:upper()
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.getDeviceName()
|
||||||
|
return deviceName
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Return one or all available wifi networks resulting from an iwinfo scan
|
--- Return one or all available wifi networks resulting from an iwinfo scan
|
||||||
-- @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[dev_api]
|
local iw = iwinfo[deviceApi]
|
||||||
local sr = iw.scanlist(dev)
|
local sr = iw.scanlist(deviceName)
|
||||||
local si, se
|
local si, se
|
||||||
|
|
||||||
if ssid == nil then
|
if ssid == nil then
|
||||||
|
@ -16,7 +16,7 @@ end
|
|||||||
|
|
||||||
--accepts API argument 'nofilter'(bool) to disable filtering of APs and 'self'
|
--accepts API argument 'nofilter'(bool) to disable filtering of APs and 'self'
|
||||||
--accepts with_raw(bool) to include raw table dump
|
--accepts with_raw(bool) to include raw table dump
|
||||||
function M.available(request, response)
|
function M.scan(request, response)
|
||||||
local noFilter = u.toboolean(request:get("nofilter"))
|
local noFilter = u.toboolean(request:get("nofilter"))
|
||||||
local withRaw = u.toboolean(request:get("with_raw"))
|
local withRaw = u.toboolean(request:get("with_raw"))
|
||||||
local sr = wifi.getScanInfo()
|
local sr = wifi.getScanInfo()
|
||||||
@ -73,7 +73,7 @@ function M.known(request, response)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--accepts with_raw(bool) to include raw table dump
|
--accepts with_raw(bool) to include raw table dump
|
||||||
function M.state(request, response)
|
function M.status(request, response)
|
||||||
local withRaw = u.toboolean(request:get("with_raw"))
|
local withRaw = u.toboolean(request:get("with_raw"))
|
||||||
local ds = wifi.getDeviceState()
|
local ds = wifi.getDeviceState()
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ end
|
|||||||
|
|
||||||
--UNTESTED
|
--UNTESTED
|
||||||
--requires ssid(string), accepts phrase(string), recreate(bool)
|
--requires ssid(string), accepts phrase(string), recreate(bool)
|
||||||
function M.assoc(request, response)
|
function M.associate_POST(request, response)
|
||||||
local argSsid = request:get("ssid")
|
local argSsid = request:get("ssid")
|
||||||
local argPhrase = request:get("phrase")
|
local argPhrase = request:get("phrase")
|
||||||
local argRecreate = request:get("recreate")
|
local argRecreate = request:get("recreate")
|
||||||
@ -131,7 +131,7 @@ function M.assoc(request, response)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--UNTESTED
|
--UNTESTED
|
||||||
function M.disassoc(request, response)
|
function M.disassociate_POST(request, response)
|
||||||
wifi.activateConfig()
|
wifi.activateConfig()
|
||||||
local rv = wifi.restart()
|
local rv = wifi.restart()
|
||||||
response:setSuccess("all wireless networks deactivated")
|
response:setSuccess("all wireless networks deactivated")
|
||||||
@ -139,12 +139,10 @@ function M.disassoc(request, response)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--UNTESTED
|
--UNTESTED
|
||||||
function M.openap(request, response)
|
function M.openap_POST(request, response)
|
||||||
--add AP net, activate it, deactivate all others, reload network/wireless config, add all dhcp and captive settings and reload as needed
|
|
||||||
local ssid = wifi.getSubstitutedSsid(s.get('apSsid'))
|
local ssid = wifi.getSubstitutedSsid(s.get('apSsid'))
|
||||||
netconf.switchConfiguration{apnet="add_noreload"}
|
netconf.switchConfiguration{apnet="add_noreload"}
|
||||||
wifi.activateConfig(ssid)
|
wifi.activateConfig(ssid)
|
||||||
--netconf.switchConfiguration{ wifiiface="add", network="reload", staticaddr="add", dhcppool="add", wwwredir="add", dnsredir="add", wwwcaptive="add" }
|
|
||||||
netconf.switchConfiguration{ wifiiface="add", network="reload", staticaddr="add", dhcppool="add", wwwredir="add", dnsredir="add" }
|
netconf.switchConfiguration{ wifiiface="add", network="reload", staticaddr="add", dhcppool="add", wwwredir="add", dnsredir="add" }
|
||||||
response:setSuccess("switched to Access Point mode")
|
response:setSuccess("switched to Access Point mode")
|
||||||
response:addData("ssid", ssid)
|
response:addData("ssid", ssid)
|
||||||
@ -152,7 +150,7 @@ end
|
|||||||
|
|
||||||
--UNTESTED
|
--UNTESTED
|
||||||
--requires ssid(string)
|
--requires ssid(string)
|
||||||
function M.rm(request, response)
|
function M.remove_POST(request, response)
|
||||||
local argSsid = request:get("ssid")
|
local argSsid = request:get("ssid")
|
||||||
|
|
||||||
if argSsid == nil or argSsid == "" then
|
if argSsid == nil or argSsid == "" then
|
||||||
|
@ -5,7 +5,7 @@ LOGGER="logger -s -t autowifi -p 6"
|
|||||||
|
|
||||||
boot() {
|
boot() {
|
||||||
$LOGGER "dummy boot"
|
$LOGGER "dummy boot"
|
||||||
#/www/cgi-bin/wfcf op=auto
|
/usr/share/lua/wifibox/script/d3dapi autowifi
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
|
@ -17,8 +17,11 @@ end
|
|||||||
|
|
||||||
function M.test_getMacAddress()
|
function M.test_getMacAddress()
|
||||||
local reportedMac = wlanconfig.getMacAddress()
|
local reportedMac = wlanconfig.getMacAddress()
|
||||||
local output = captureCommandOutput('ifconfig wlan0')
|
local f = io.open('/sys/class/net/wlan0/address')
|
||||||
local actualMac = output:match('HWaddr (%w%w:%w%w:%w%w:%w%w:%w%w:%w%w)'):gsub(':', ''):upper()
|
assert(f)
|
||||||
|
local output = f:read('*all')
|
||||||
|
f:close()
|
||||||
|
local actualMac = output:match('(%w%w:%w%w:%w%w:%w%w:%w%w:%w%w)'):gsub(':', ''):upper()
|
||||||
|
|
||||||
assert(reportedMac == actualMac)
|
assert(reportedMac == actualMac)
|
||||||
end
|
end
|
||||||
|
@ -75,4 +75,14 @@ function M.symlink(from, to)
|
|||||||
return os.execute(x)
|
return os.execute(x)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.readFile(filePath)
|
||||||
|
local f, msg, nr = io.open(filePath, 'r')
|
||||||
|
if not f then return nil,msg,nr end
|
||||||
|
|
||||||
|
local res = f:read('*all')
|
||||||
|
f:close()
|
||||||
|
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
Reference in New Issue
Block a user