diff --git a/src/README b/src/README index fb55a31..e43124d 100644 --- a/src/README +++ b/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 < - Doodle3D + Wireless configuration - + diff --git a/src/admin/autowifi.js b/src/admin/autowifi.js index 132ca88..bcd8c2f 100644 --- a/src/admin/autowifi.js +++ b/src/admin/autowifi.js @@ -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, '' 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(""); + container.append("
SSIDBSSIDchannel
SSIDBSSIDchannel
"); + var tbl = container.find("table"); $.each(data, function(index,value) { if (value != "") { net = parseNetLine(value); console.log(net); - container.append("" + net.ssid + "" + net.bssid + "" + net.channel + ""); + tbl.append("" + net.ssid + "" + net.bssid + "" + net.channel + ""); } }); - container.append(""); }); } diff --git a/src/autowifi.lua b/src/autowifi.lua index c3ef0dd..50424a5 100644 --- a/src/autowifi.lua +++ b/src/autowifi.lua @@ -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 "" local channel = net.channel or "" - 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 diff --git a/src/ext/www/admin b/src/ext/www/admin new file mode 120000 index 0000000..b9cdf14 --- /dev/null +++ b/src/ext/www/admin @@ -0,0 +1 @@ +/usr/share/lua/autowifi/admin/ \ No newline at end of file diff --git a/src/ext/www/index.html b/src/ext/www/index.html new file mode 100644 index 0000000..9034ac6 --- /dev/null +++ b/src/ext/www/index.html @@ -0,0 +1,10 @@ + + + + + + + +LuCI - Lua Configuration Interface + + diff --git a/src/misc/wireless.org b/src/misc/wireless.org deleted file mode 100644 index 06a406f..0000000 --- a/src/misc/wireless.org +++ /dev/null @@ -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 diff --git a/src/wifihelper.lua b/src/wifihelper.lua index 03899d1..be5d445 100644 --- a/src/wifihelper.lua +++ b/src/wifihelper.lua @@ -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