0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-06-26 03:21:22 +02: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:
Wouter R 2013-07-25 01:06:00 +02:00
parent d4b9c39d60
commit 781c3f9ff1
7 changed files with 59 additions and 42 deletions

View File

@ -32,7 +32,7 @@ define Package/wifibox
# DEFAULT:=y
TITLE:=Doodle3D WifiBox firmware
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
define Package/wifibox/description

View File

@ -150,8 +150,8 @@ end
--[[ Add/remove DHCP pool for wireless net ]]
function reconf.dhcppool_add(dirtyList)
uci:set('dhcp', wifi.NET, 'dhcp') --create section
M.uciTableSet('dhcp', wifi.NET, {
uci:set('dhcp', wifi.getDeviceName(), 'dhcp') --create section
M.uciTableSet('dhcp', wifi.getDeviceName(), {
interface = wifi.NET,
start = '100',
limit = '150',

View File

@ -1,15 +1,17 @@
local log = require('util.logger')
local utils = require('util.utils')
local uci = require('uci').cursor()
local iwinfo = require('iwinfo')
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_FALLBACK = 'radio0'
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
local cachedApSsid, baseApSsid = nil, nil
@ -58,17 +60,17 @@ end
-- @param device wireless device to operate on (optional, defaults to DFL_DEVICE)
-- @return true on success or false+error on failure
function M.init(device)
-- iwinfo = pcall(require, 'iwinfo')
dev = device or M.DFL_DEVICE
dev_api = iwinfo.type(dev)
if not dev_api then
--TODO: warn about missing dev here?
local devInitial = dev
dev = M.DFL_DEVICE_FALLBACK
dev_api = iwinfo.type(dev)
deviceName = device or M.DFL_DEVICE
deviceApi = iwinfo.type(deviceName)
if not deviceApi then
local devInitial = deviceName
deviceName = M.DFL_DEVICE_FALLBACK
deviceApi = iwinfo.type(deviceName)
if not dev_api then
return false, "No such wireless device: '" .. devInitial .. "' (and fallback '" .. dev .. "' does not exist either)"
log:info("wireless device '" .. devInitial .. "' not found, trying fallback '" .. deviceName .. "'")
if not deviceApi then
return false, "No such wireless device: '" .. devInitial .. "' (and fallback '" .. deviceName .. "' does not exist either)"
end
end
@ -77,18 +79,19 @@ end
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 = {
['ssid'] = iw.ssid(dev),
['bssid'] = iw.bssid(dev),
['channel'] = iw.channel(dev),
['mode'] = M.mapDeviceMode(iw.mode(dev), true),
['encryption'] = M.mapEncryptionType(iw.encryption(dev).description),
['quality'] = iw.quality(dev),
['quality_max'] = iw.quality_max(dev),
['txpower'] = iw.txpower(dev),
['signal'] = iw.signal(dev),
['noise'] = iw.noise(dev)
['ssid'] = iw.ssid(deviceName),
['bssid'] = iw.bssid(deviceName),
['channel'] = iw.channel(deviceName),
['mode'] = M.mapDeviceMode(iw.mode(deviceName), true),
['encryption'] = M.mapEncryptionType(encDescription),
['quality'] = iw.quality(deviceName),
['quality_max'] = iw.quality_max(deviceName),
['txpower'] = iw.txpower(deviceName),
['signal'] = iw.signal(deviceName),
['noise'] = iw.noise(deviceName)
}
return result
end
@ -96,8 +99,7 @@ end
--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)
function M.getMacAddress()
local iw = iwinfo[dev_api]
local macText = iw.bssid(dev)
local macText = utils.readFile('/sys/class/net/' .. deviceName .. '/address')
local out = ''
for i = 0, 5 do
@ -105,15 +107,19 @@ function M.getMacAddress()
out = out .. bt
end
return out
return out:upper()
end
function M.getDeviceName()
return deviceName
end
--- 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
-- @return data for all or requested network; false+error on failure or nil when requested network not found
function M.getScanInfo(ssid)
local iw = iwinfo[dev_api]
local sr = iw.scanlist(dev)
local iw = iwinfo[deviceApi]
local sr = iw.scanlist(deviceName)
local si, se
if ssid == nil then

View File

@ -16,7 +16,7 @@ end
--accepts API argument 'nofilter'(bool) to disable filtering of APs and 'self'
--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 withRaw = u.toboolean(request:get("with_raw"))
local sr = wifi.getScanInfo()
@ -73,7 +73,7 @@ function M.known(request, response)
end
--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 ds = wifi.getDeviceState()
@ -93,7 +93,7 @@ end
--UNTESTED
--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 argPhrase = request:get("phrase")
local argRecreate = request:get("recreate")
@ -131,7 +131,7 @@ function M.assoc(request, response)
end
--UNTESTED
function M.disassoc(request, response)
function M.disassociate_POST(request, response)
wifi.activateConfig()
local rv = wifi.restart()
response:setSuccess("all wireless networks deactivated")
@ -139,12 +139,10 @@ function M.disassoc(request, response)
end
--UNTESTED
function M.openap(request, response)
--add AP net, activate it, deactivate all others, reload network/wireless config, add all dhcp and captive settings and reload as needed
function M.openap_POST(request, response)
local ssid = wifi.getSubstitutedSsid(s.get('apSsid'))
netconf.switchConfiguration{apnet="add_noreload"}
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" }
response:setSuccess("switched to Access Point mode")
response:addData("ssid", ssid)
@ -152,7 +150,7 @@ end
--UNTESTED
--requires ssid(string)
function M.rm(request, response)
function M.remove_POST(request, response)
local argSsid = request:get("ssid")
if argSsid == nil or argSsid == "" then

View File

@ -5,7 +5,7 @@ LOGGER="logger -s -t autowifi -p 6"
boot() {
$LOGGER "dummy boot"
#/www/cgi-bin/wfcf op=auto
/usr/share/lua/wifibox/script/d3dapi autowifi
}
start() {

View File

@ -17,8 +17,11 @@ end
function M.test_getMacAddress()
local reportedMac = wlanconfig.getMacAddress()
local output = captureCommandOutput('ifconfig wlan0')
local actualMac = output:match('HWaddr (%w%w:%w%w:%w%w:%w%w:%w%w:%w%w)'):gsub(':', ''):upper()
local f = io.open('/sys/class/net/wlan0/address')
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)
end

View File

@ -75,4 +75,14 @@ function M.symlink(from, to)
return os.execute(x)
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