mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 02:53:49 +01:00
Several fixes; add operation to enter AP mode; move todo list
This commit is contained in:
parent
b67d67eb91
commit
5b0e219ef6
15
src/README
15
src/README
@ -6,3 +6,18 @@ Installation:
|
||||
- create a symlink to ext/autowifi.js in /www
|
||||
- create a symlink to ext/autowifi_init in /etc/rc.d and name it S19autowifi_init
|
||||
- enable init script by calling it with 'enable' argument?
|
||||
- make sure radio0 in /etc/config/wireless is not disabled
|
||||
- create a wlan network in /etc/config/network as follows <<EOF
|
||||
config interface 'wlan'
|
||||
option ifname 'radio0'
|
||||
option proto 'dhcp'
|
||||
EOF
|
||||
- HOWEVER in ap mode it should be static with address '192.168.10.1' and netmask '255.255.255.0'
|
||||
AND act as dhcp server, add to /etc/config/dhcp <<EOF
|
||||
config dhcp 'wlan'
|
||||
option interface 'wlan0'
|
||||
option start '100'
|
||||
option limit '150'
|
||||
option leasetime '12h'
|
||||
EOF
|
||||
|
@ -2,10 +2,10 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15" />
|
||||
<title>Doodle3D</title>
|
||||
<title>Wireless configuration</title>
|
||||
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
|
||||
<script type="text/javascript" src="autowifi.js"></script>
|
||||
<link href="autowifi.css" rel="stylesheet" type="text/css" />
|
||||
<link href="/admin/autowifi.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -1,18 +1,3 @@
|
||||
/*
|
||||
* TODO
|
||||
* - finish network creation
|
||||
* - finish auto operation
|
||||
* - call auto op from init script
|
||||
* - in AP mode, route all addresses to the autowifi page
|
||||
* - escape text where necessary (e.g. in getKnown, '<unknown SSID>' is currently interpreted as html...)
|
||||
* - why is $.trim() required in string comparison? do we need to strip newlines in the parse functions?
|
||||
* - add hidden field to remember encryption (so we know whether or not a passphrase should be entered)
|
||||
* - instead of showing alerts on missing ssid/phrase in connect, disable the button until contraints have been satisfied
|
||||
* (this is also cleaner in case no networks are present)
|
||||
* - use json for communication
|
||||
* - local all functions (see: http://stackoverflow.com/questions/4643814/why-would-this-lua-optimization-hack-help)
|
||||
*/
|
||||
|
||||
animSpeed = 200;
|
||||
cgiBase = "../cgi-bin/wfcf";
|
||||
|
||||
@ -69,11 +54,10 @@ function fetchNetworkState() {
|
||||
data = parseResponse(data);
|
||||
if (data.status == "ERR") setResult(data.msg, true);
|
||||
var net = parseNetLine(data.payload);
|
||||
if (net.mode == "ap") {
|
||||
$("#wlan_state").text("Access point mode (SSID: " + net.ssid + "; BSSID: " + net.bssid + "; channel: " + net.channel + ")");
|
||||
} else {
|
||||
$("#wlan_state").text("Client mode (SSID: " + net.ssid + "; BSSID: " + net.bssid + "; channel: " + net.channel + ")");
|
||||
}
|
||||
var modeText = "Unknown device mode ('" + net.mode + "')";
|
||||
if (net.mode == "ap") modeText = "Access point mode";
|
||||
else if (net.mode == "sta") modeText = "Client mode";
|
||||
$("#wlan_state").text(modeText + " (SSID: " + net.ssid + "; BSSID: " + net.bssid + "; channel: " + net.channel + ")");
|
||||
});
|
||||
}
|
||||
|
||||
@ -104,15 +88,15 @@ function fetchKnownNetworks() {
|
||||
data = data.payload.split("\n");
|
||||
var container = $("#wlan_known_container");
|
||||
container.empty();
|
||||
container.append("<table class=\"known_nets\"><tr><th>SSID</th><th>BSSID</th><th>channel</th></tr>");
|
||||
container.append("<table class=\"known_nets\"><tr><th>SSID</th><th>BSSID</th><th>channel</th></tr></table>");
|
||||
var tbl = container.find("table");
|
||||
$.each(data, function(index,value) {
|
||||
if (value != "") {
|
||||
net = parseNetLine(value);
|
||||
console.log(net);
|
||||
container.append("<tr><td>" + net.ssid + "</td><td>" + net.bssid + "</td><td>" + net.channel + "</td></tr>");
|
||||
tbl.append("<tr><td>" + net.ssid + "</td><td>" + net.bssid + "</td><td>" + net.channel + "</td></tr>");
|
||||
}
|
||||
});
|
||||
container.append("</table>");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
...
|
||||
{comma-separated line n}
|
||||
|
||||
- see autowifi.js for TODO
|
||||
- general info on wireless config: http://wiki.openwrt.org/doc/uci/wireless
|
||||
- uci docs: http://wiki.openwrt.org/doc/techref/uci
|
||||
- parse/generate urls: https://github.com/keplerproject/cgilua/blob/master/src/cgilua/urlcode.lua
|
||||
@ -64,9 +63,9 @@ function main()
|
||||
local si, se
|
||||
|
||||
if sr and #sr > 0 then
|
||||
util.printWithSuccess(#sr .. " network(s) found");
|
||||
for _, se in ipairs(sr) do
|
||||
--print("[[ " .. util.dump(se) .. " ]]") --TEMP
|
||||
util.printWithSuccess(#sr .. " network(s) found");
|
||||
print(se.ssid .. "," .. se.bssid .. "," .. se.channel .. "," .. wifi.mapDeviceMode(se.mode))
|
||||
end
|
||||
else
|
||||
@ -74,11 +73,11 @@ function main()
|
||||
end
|
||||
|
||||
elseif argOperation == "getknown" then
|
||||
util.printWithSuccess("")
|
||||
for _, net in ipairs(wifi.getConfigs()) do
|
||||
if net.mode == "sta" then
|
||||
local bssid = net.bssid or "<unknown BSSID>"
|
||||
local channel = net.channel or "<unknown channel>"
|
||||
util.printWithSuccess("")
|
||||
print(net.ssid .. "," .. bssid .. "," .. channel)
|
||||
end
|
||||
end
|
||||
@ -102,7 +101,7 @@ function main()
|
||||
end
|
||||
end
|
||||
if cfg == nil or argRecreate ~= nil then
|
||||
scanResult = wifi.getScanInfo(argSsid)
|
||||
local scanResult = wifi.getScanInfo(argSsid)
|
||||
if scanResult ~= nil then
|
||||
wifi.createConfigFromScanInfo(scanResult)
|
||||
else
|
||||
@ -111,25 +110,30 @@ function main()
|
||||
end
|
||||
end
|
||||
wifi.activateConfig(argSsid)
|
||||
--restartWlan()
|
||||
util.printWithSuccess("");
|
||||
print("Wlan associated with network "..argSsid.."! (dummy mode, not restarting)")
|
||||
local rv = wifi.restart()
|
||||
util.exitWithSuccess("Wlan associated with network "..argSsid.."! [$?=" .. rv .. "]")
|
||||
|
||||
elseif argOperation == "disassoc" then
|
||||
wifi.activateConfig()
|
||||
--restartWlan()
|
||||
exitWithSuccess("Deactivated all wireless networks (dummy mode, not restarting)")
|
||||
local rv = wifi.restart()
|
||||
util.exitWithSuccess("Deactivated all wireless networks [$?=" .. rv .. "]")
|
||||
|
||||
elseif argOperation == "openap" then
|
||||
wifi.activateConfig(wifi.AP_SSID)
|
||||
wifi.configureDhcp(true)
|
||||
local rv = wifi.restart(true)
|
||||
util.exitWithSuccess("Switched to AP mode (SSID: '" .. wifi.AP_SSID .. "') [$?=" .. rv .. "]")
|
||||
|
||||
elseif argOperation == "rm" then
|
||||
if argSsid == nil or argSsid == "" then util.exitWithError("Please supply an SSID to remove") end
|
||||
if wifi.removeConfig(argSsid) then
|
||||
exitWithSuccess("Removed wireless network with SSID " .. argSsid)
|
||||
util.exitWithSuccess("Removed wireless network with SSID " .. argSsid)
|
||||
else
|
||||
exitWithWarning("No wireless network with SSID " .. argSsid)
|
||||
util.exitWithWarning("No wireless network with SSID " .. argSsid)
|
||||
end
|
||||
|
||||
elseif argOperation == "auto" then
|
||||
exitWithWarning("Not implemented");
|
||||
util.exitWithWarning("Not implemented");
|
||||
--scan nets
|
||||
--take union of scan and known
|
||||
--connect to first if not empty; setup ap otherwise
|
||||
@ -149,7 +153,7 @@ if init() == false then
|
||||
util.exitWithError(errortext)
|
||||
end
|
||||
|
||||
if wifi.createOrReplaceApConfig() == false then
|
||||
if wifi.createOrReplaceApConfig(true) == false then
|
||||
util.exitWithError(errortext)
|
||||
end
|
||||
|
||||
|
1
src/ext/www/admin
Symbolic link
1
src/ext/www/admin
Symbolic link
@ -0,0 +1 @@
|
||||
/usr/share/lua/autowifi/admin/
|
10
src/ext/www/index.html
Normal file
10
src/ext/www/index.html
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; URL=/admin/autowifi.html" />
|
||||
</head>
|
||||
<body style="background-color: black">
|
||||
<a style="color: white; text-decoration: none" href="/admin/autowifi.html">LuCI - Lua Configuration Interface</a>
|
||||
</body>
|
||||
</html>
|
@ -1,45 +0,0 @@
|
||||
|
||||
config wifi-device 'radio0'
|
||||
option type 'mac80211'
|
||||
option hwmode '11ng'
|
||||
option path 'platform/ar933x_wmac'
|
||||
option htmode 'HT20'
|
||||
list ht_capab 'SHORT-GI-20'
|
||||
list ht_capab 'SHORT-GI-40'
|
||||
list ht_capab 'RX-STBC1'
|
||||
list ht_capab 'DSSS_CCK-40'
|
||||
option channel '9'
|
||||
option country 'NL'
|
||||
option txpower '20'
|
||||
option disabled '0'
|
||||
|
||||
config wifi-iface
|
||||
option network 'lan'
|
||||
option ssid 'happiesnappie2'
|
||||
option encryption 'psk2'
|
||||
option device 'radio0'
|
||||
option mode 'sta'
|
||||
option bssid '00:22:6B:EF:BB:99'
|
||||
option key 'pr4ppal4trappa'
|
||||
option disabled '1'
|
||||
|
||||
config wifi-iface
|
||||
option device 'radio0'
|
||||
option encryption 'none'
|
||||
option ssid 'non-existing'
|
||||
option mode 'sta'
|
||||
option network 'lan'
|
||||
option disabled '0'
|
||||
|
||||
config wifi-iface
|
||||
option encryption 'none'
|
||||
option device 'radio0'
|
||||
option mode 'ap'
|
||||
option ssid 'd3d-ap'
|
||||
option network 'lan'
|
||||
option disabled '1'
|
||||
|
||||
Content-type: text/plain
|
||||
|
||||
[[1: { ["encryption"] = { ["enabled"] = true,["auth_algs"] = { } ,["description"] = mixed WPA/WPA2 PSK (TKIP),["wep"] = false,["auth_suites"] = { [1] = PSK,} ,["wpa"] = 3,["pair_ciphers"] = { [1] = TKIP,[2] = CCMP,} ,["group_ciphers"] = { [1] = TKIP,} ,} ,["quality_max"] = 70,["ssid"] = happiesnappie2,["channel"] = 9,["signal"] = -35,["bssid"] = 00:22:6B:EF:BB:99,["mode"] = Master,["quality"] = 70,} ]]
|
||||
happiesnappie2
|
@ -4,8 +4,11 @@ local iwinfo = require("iwinfo")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.DFL_AP_SSID = "d3d-ap"
|
||||
M.DFL_DEVICE = "radio0" -- was wlan0
|
||||
M.AP_SSID = "d3d-ap"
|
||||
M.AP_ADDRESS = "192.168.10.1"
|
||||
M.AP_NETMASK = "255.255.255.0"
|
||||
M.NET = "wlan"
|
||||
|
||||
local dev, dev_api
|
||||
|
||||
@ -17,9 +20,10 @@ local dev, dev_api
|
||||
function M.mapDeviceMode(mode, masterIsAp)
|
||||
local modeMap = {
|
||||
["Master"] = masterIsAp and "ap" or "sta",
|
||||
["Client"] = "sta",
|
||||
["Ad-Hoc"] = "adhoc"
|
||||
}
|
||||
return modeMap[mode]
|
||||
return modeMap[mode] or mode
|
||||
end
|
||||
|
||||
|
||||
@ -115,7 +119,7 @@ function M.createConfigFromScanInfo(info, passphrase, disabled)
|
||||
local mode = M.mapDeviceMode(info.mode)
|
||||
|
||||
local apconfig = {
|
||||
network = "lan",
|
||||
network = M.NET,
|
||||
device = "radio0",
|
||||
ssid = info.ssid,
|
||||
bssid = info.bssid,
|
||||
@ -145,7 +149,7 @@ function M.createOrReplaceApConfig(disabled)
|
||||
if sname == nil then sname = uci:add("wireless", "wifi-iface") end
|
||||
|
||||
local apconfig = {
|
||||
network = "lan",
|
||||
network = M.NET,
|
||||
ssid = M.AP_SSID,
|
||||
encryption = "none",
|
||||
device = "radio0",
|
||||
@ -165,8 +169,36 @@ end
|
||||
-- unneccesary interruptions there.
|
||||
-- * ubus does not seem to work -- local c=ubus.connect();
|
||||
-- c:call("network.interface.wlan", "down"); c:call("network.interface.wlan", "up"); c:close()
|
||||
function M.restart()
|
||||
local rv = os.execute("/etc/init.d/network reload")
|
||||
-- @param dhcpToo also reload dnsmasq if true
|
||||
function M.restart(dhcpToo)
|
||||
os.execute("/etc/init.d/network reload") --always seems to return 0
|
||||
if dhcpToo ~= nil and dhcpToo then os.execute("/etc/init.d/dnsmasq reload") end
|
||||
return 0
|
||||
end
|
||||
|
||||
--- Add or remove DHCP section for wlan network
|
||||
-- @param addCfg add section if true or nil, remove it if false
|
||||
function M.configureDhcp(addCfg)
|
||||
if addCfg == nil or addCfg == true then
|
||||
uci:set("dhcp", M.NET, "dhcp")
|
||||
uci:set("dhcp", M.NET, "interface", M.NET)
|
||||
uci:set("dhcp", M.NET, "start", "100")
|
||||
uci:set("dhcp", M.NET, "limit", "150")
|
||||
uci:set("dhcp", M.NET, "leasetime", "12h")
|
||||
uci:set("network", M.NET, "proto", "static")
|
||||
uci:set("network", M.NET, "ipaddr", M.AP_ADDRESS)
|
||||
uci:set("network", M.NET, "netmask", M.AP_NETMASK)
|
||||
uci:set("network", M.NET, "type", "bridge")
|
||||
else
|
||||
uci:delete("dhcp", M.NET)
|
||||
uci:set("network", M.NET, "proto", "dhcp")
|
||||
uci:delete("network", M.NET, "ipaddr")
|
||||
uci:delete("network", M.NET, "netmask")
|
||||
-- uci:delete("network", M.NET, "bridge")
|
||||
end
|
||||
uci:commit("dhcp")
|
||||
uci:commit("network")
|
||||
--TODO: is network reload enough here?
|
||||
end
|
||||
|
||||
return M
|
||||
|
Loading…
Reference in New Issue
Block a user