update 2026-08-17 16:36:08

This commit is contained in:
action committed 2026-08-17 16:36:08 +08:00
1 parent 15f9ec83ad
commit 742209e24d
1969 files changed
+103 -1523162

No files matched your search

-19
View File
@@ -1,19 +0,0 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-mtwifi
PKG_LICENSE:=GPLv2
PKG_MAINTAINER:=Hua Shao <nossiac@163.com>
LUCI_TITLE:=LuCI support for mt wifi driver
LUCI_DEPENDS:=@TARGET_ramips @!PACKAGE_kmod-mt7615d_dbdc +mt_wifi
LUCI_PKGARCH:=all
PKG_VERSION:=1
PKG_RELEASE:=8
define Package/luci-app-mtwifi/conffiles
/etc/wireless/mt7615/
endef
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature
@@ -1,801 +0,0 @@
-- This module is a demo to configure MTK' proprietary WiFi driver.
-- Basic idea is to bypass uci and edit wireless profile (mt76xx.dat) directly.
-- LuCI's WiFi configuration is more logical and elegent, but it's quite tricky to
-- translate uci into MTK's WiFi profile (like we did in "uci2dat").
-- And you will get your hands dirty.
--
-- Hua Shao <nossiac@163.com>
module("luci.controller.mtkwifi", package.seeall)
local http = require("luci.http")
local mtkwifi = require("mtkwifi")
function __mtkwifi_reload(devname)
local profiles = mtkwifi.search_dev_and_profile()
for dev,profile in pairs(profiles) do
if not devname or devname == dev then
local diff = mtkwifi.diff_profile(profile)
-- Adding or deleting a vif will need to reinstall the wifi ko,
-- so we call "mtkwifi restart" here.
if diff.BssidNum then
os.execute("/sbin/mtkwifi restart "..devname)
else
os.execute("/sbin/mtkwifi reload "..devname)
end
-- keep a backup for this commit
-- it will be used in mtkwifi.diff_profile()
os.execute("cp -f "..profile.." "..mtkwifi.__profile_bak_path(profile))
end
end
end
function index()
entry({"admin", "network", "wifi"}, template("admin_mtk/mtk_wifi_overview"), _("Wireless"), 25)
entry({"admin", "network", "wifi", "dev_cfg_view"}, template("admin_mtk/mtk_wifi_dev_cfg")).leaf = true
entry({"admin", "network", "wifi", "dev_cfg"}, call("dev_cfg")).leaf = true
entry({"admin", "network", "wifi", "dev_cfg_reset"}, call("dev_cfg_reset")).leaf = true
entry({"admin", "network", "wifi", "dev_cfg_raw"}, call("dev_cfg_raw")).leaf = true
entry({"admin", "network", "wifi", "vif_cfg_view"}, template("admin_mtk/mtk_wifi_vif_cfg")).leaf = true
entry({"admin", "network", "wifi", "vif_cfg"}, call("vif_cfg")).leaf = true
entry({"admin", "network", "wifi", "vif_add_view"}, template("admin_mtk/mtk_wifi_vif_cfg")).leaf = true
entry({"admin", "network", "wifi", "vif_add"}, call("vif_cfg")).leaf = true
entry({"admin", "network", "wifi", "vif_del"}, call("vif_del")).leaf = true
entry({"admin", "network", "wifi", "vif_disable"}, call("vif_disable")).leaf = true
entry({"admin", "network", "wifi", "vif_enable"}, call("vif_enable")).leaf = true
entry({"admin", "network", "wifi", "get_station_list"}, call("get_station_list"))
entry({"admin", "network", "wifi", "get_country_region_list"}, call("get_country_region_list")).leaf = true
entry({"admin", "network", "wifi", "get_channel_list"}, call("get_channel_list"))
entry({"admin", "network", "wifi", "get_HT_ext_channel_list"}, call("get_HT_ext_channel_list"))
entry({"admin", "network", "wifi", "get_5G_2nd_80Mhz_channel_list"}, call("get_5G_2nd_80Mhz_channel_list"))
entry({"admin", "network", "wifi", "reset"}, call("reset_wifi")).leaf = true
entry({"admin", "network", "wifi", "reload"}, call("reload_wifi")).leaf = true
entry({"admin", "network", "wifi", "get_raw_profile"}, call("get_raw_profile"))
entry({"admin", "network", "wifi", "apcli_cfg_view"}, template("admin_mtk/mtk_wifi_apcli")).leaf = true
entry({"admin", "network", "wifi", "apcli_cfg"}, call("apcli_cfg")).leaf = true
entry({"admin", "network", "wifi", "apcli_disconnect"}, call("apcli_disconnect")).leaf = true
entry({"admin", "network", "wifi", "apcli_connect"}, call("apcli_connect")).leaf = true
entry({"admin", "network", "wifi", "apcli_scan"}, call("apcli_scan")).leaf = true;
end
function dev_cfg(devname)
local profiles = mtkwifi.search_dev_and_profile()
assert(profiles[devname])
local cfgs = mtkwifi.load_profile(profiles[devname])
for k,v in pairs(http.formvalue()) do
if type(v) ~= type("") and type(v) ~= type(0) then
nixio.syslog("err", "dev_cfg, invalid value type for "..k..","..type(v))
elseif string.byte(k) == string.byte("_") then
nixio.syslog("err", "dev_cfg, special: "..k.."="..v)
else
cfgs[k] = v or ""
end
end
if mtkwifi.band(cfgs.WirelessMode) == "5G" then
cfgs.CountryRegionABand = http.formvalue("__cr");
else
cfgs.CountryRegion = http.formvalue("__cr");
end
if cfgs.Channel == "0" then -- Auto Channel Select
cfgs.AutoChannelSelect = "3"
else
cfgs.AutoChannelSelect = "0"
end
if http.formvalue("__bw") == "20" then
cfgs.HT_BW = 0
cfgs.VHT_BW = 0
elseif http.formvalue("__bw") == "40" then
cfgs.HT_BW = 1
cfgs.VHT_BW = 0
cfgs.HT_BSSCoexistence = 0
elseif http.formvalue("__bw") == "60" then
cfgs.HT_BW = 1
cfgs.VHT_BW = 0
cfgs.HT_BSSCoexistence = 1
elseif http.formvalue("__bw") == "80" then
cfgs.HT_BW = 1
cfgs.VHT_BW = 1
elseif http.formvalue("__bw") == "160" then
cfgs.HT_BW = 1
cfgs.VHT_BW = 2
elseif http.formvalue("__bw") == "161" then
cfgs.HT_BW = 1
cfgs.VHT_BW = 3
cfgs.VHT_Sec80_Channel = http.formvalue("VHT_Sec80_Channel") or ""
end
local mimo = http.formvalue("__mimo")
if mimo == "0" then
cfgs.ETxBfEnCond=1
cfgs.MUTxRxEnable=0
cfgs.ITxBfEn=1
elseif mimo == "1" then
cfgs.ETxBfEnCond=1
cfgs.MUTxRxEnable=0
cfgs.ITxBfEn=1
elseif mimo == "2" then
cfgs.ETxBfEnCond=1
cfgs.MUTxRxEnable=0
cfgs.ITxBfEn=1
elseif mimo == "3" then
cfgs.ETxBfEnCond=1
cfgs.MUTxRxEnable=0
cfgs.ITxBfEn=1
elseif mimo == "4" then
cfgs.ETxBfEnCond=1
cfgs.MUTxRxEnable=0
cfgs.ITxBfEn=1
else
cfgs.ETxBfEnCond=1
cfgs.MUTxRxEnable=0
cfgs.ITxBfEn=1
end
-- if cfgs.ApCliEnable == "1" then
-- cfgs.Channel = http.formvalue("__apcli_channel")
-- end
-- VOW
-- ATC should actually be scattered into each SSID, but I'm just lazy.
if cfgs.VOW_Airtime_Fairness_En then
for i = 1,tonumber(cfgs.BssidNum) do
__atc_tp = http.formvalue("__atc_vif"..i.."_tp") or "0"
__atc_min_tp = http.formvalue("__atc_vif"..i.."_min_tp") or "0"
__atc_max_tp = http.formvalue("__atc_vif"..i.."_max_tp") or "0"
__atc_at = http.formvalue("__atc_vif"..i.."_at") or "0"
__atc_min_at = http.formvalue("__atc_vif"..i.."_min_at") or "0"
__atc_max_at = http.formvalue("__atc_vif"..i.."_max_at") or "0"
nixio.syslog("info", "ATC.__atc_tp ="..i..__atc_tp );
nixio.syslog("info", "ATC.__atc_min_tp ="..i..__atc_min_tp );
nixio.syslog("info", "ATC.__atc_max_tp ="..i..__atc_max_tp );
nixio.syslog("info", "ATC.__atc_at ="..i..__atc_at );
nixio.syslog("info", "ATC.__atc_min_at ="..i..__atc_min_at );
nixio.syslog("info", "ATC.__atc_max_at ="..i..__atc_max_at );
cfgs.VOW_Rate_Ctrl_En = mtkwifi.token_set(cfgs.VOW_Rate_Ctrl_En, i, __atc_tp)
cfgs.VOW_Group_Min_Rate = mtkwifi.token_set(cfgs.VOW_Group_Min_Rate, i, __atc_min_tp)
cfgs.VOW_Group_Max_Rate = mtkwifi.token_set(cfgs.VOW_Group_Max_Rate, i, __atc_max_tp)
cfgs.VOW_Airtime_Ctrl_En = mtkwifi.token_set(cfgs.VOW_Airtime_Ctrl_En, i, __atc_at)
cfgs.VOW_Group_Min_Ratio = mtkwifi.token_set(cfgs.VOW_Group_Min_Ratio, i, __atc_min_at)
cfgs.VOW_Group_Max_Ratio = mtkwifi.token_set(cfgs.VOW_Group_Max_Ratio, i, __atc_max_at)
end
cfgs.VOW_RX_En = http.formvalue("VOW_RX_En") or "0"
end
-- http.write_json(http.formvalue())
mtkwifi.save_profile(cfgs, profiles[devname])
if http.formvalue("__apply") then
__mtkwifi_reload(devname)
end
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi", "dev_cfg_view",devname))
end
function dev_cfg_raw(devname)
-- http.write_json(http.formvalue())
local profiles = mtkwifi.search_dev_and_profile()
assert(profiles[devname])
local raw = http.formvalue("raw")
raw = string.gsub(raw, "\r\n", "\n")
local cfgs = mtkwifi.load_profile(nil, raw)
mtkwifi.save_profile(cfgs, profiles[devname])
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi", "dev_cfg_view", devname))
end
function dev_cfg_reset(devname)
-- http.write_json(http.formvalue())
local profiles = mtkwifi.search_dev_and_profile()
assert(profiles[devname])
local fd = io.open("/rom"..profiles[devname], "r")
if fd then
fd:close() -- just to test if file exists.
os.execute("cp -f /rom"..profiles[devname].." "..profiles[devname])
else
mtkwifi.debug("unable to find /rom"..profiles[devname])
end
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi", "dev_cfg_view", devname))
end
function vif_del(dev, vif)
mtkwifi.debug("vif_del("..dev..vif..")")
local devname,vifname = dev, vif
mtkwifi.debug("devname="..devname)
mtkwifi.debug("vifname="..vifname)
local devs = mtkwifi.get_all_devs()
local idx = devs[devname]["vifs"][vifname].vifidx -- or tonumber(string.match(vifname, "%d+")) + 1
mtkwifi.debug("idx="..idx, devname, vifname)
local profile = devs[devname].profile
assert(profile)
if idx and tonumber(idx) >= 0 then
local cfgs = mtkwifi.load_profile(profile)
if cfgs then
mtkwifi.debug("ssid"..idx.."="..cfgs["SSID"..idx].."<br>")
cfgs["SSID"..idx] = ""
mtkwifi.debug("ssid"..idx.."="..cfgs["SSID"..idx].."<br>")
mtkwifi.debug("wpapsk"..idx.."="..cfgs["WPAPSK"..idx].."<br>")
cfgs["WPAPSK"..idx] = ""
local ssidlist = {}
local j = 1
for i = 1,16 do
if cfgs["SSID"..i] ~= "" then
ssidlist[j] = cfgs["SSID"..i]
j = j + 1
end
end
for i,v in ipairs(ssidlist) do
mtkwifi.debug("ssidlist"..i.."="..v)
end
mtkwifi.debug("cfgs.BssidNum="..cfgs.BssidNum.." #ssidlist="..#ssidlist)
assert(tonumber(cfgs.BssidNum) == #ssidlist + 1, "Please delete vif from larger idx.")
cfgs.BssidNum = #ssidlist
for i = 1,16 do
if i <= cfgs.BssidNum then
cfgs["SSID"..i] = ssidlist[i]
elseif cfgs["SSID"..i] then
cfgs["SSID"..i] = ""
end
end
mtkwifi.save_profile(cfgs, profile)
else
mtkwifi.debug(profile.." cannot be found!")
end
end
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi"))
end
function vif_disable(iface)
os.execute("ifconfig "..iface.." down")
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi"))
end
function vif_enable(iface)
os.execute("ifconfig "..iface.." up")
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi"))
end
--[[
-- security config in mtk wifi is quite complicated!
-- cfgs listed below are attached with vif and combined like "0;0;0;0". They need specicial treatment.
TxRate, WmmCapable, NoForwarding,
HideSSID, IEEE8021X, PreAuth,
AuthMode, EncrypType, RekeyMethod,
RekeyInterval, PMKCachePeriod,
DefaultKeyId, Key{n}Type, HT_EXTCHA,
RADIUS_Server, RADIUS_Port,
]]
local function conf_wep_keys(cfgs,vifidx)
cfgs.DefaultKeyID = mtkwifi.token_set(cfgs.DefaultKeyID, vifidx, http.formvalue("__DefaultKeyID") or 1)
cfgs["Key1Str"..vifidx] = http.formvalue("Key1Str"..vifidx)
cfgs["Key2Str"..vifidx] = http.formvalue("Key2Str"..vifidx)
cfgs["Key3Str"..vifidx] = http.formvalue("Key3Str"..vifidx)
cfgs["Key4Str"..vifidx] = http.formvalue("Key4Str"..vifidx)
cfgs["Key1Type"]=mtkwifi.token_set(cfgs["Key1Type"],vifidx, http.formvalue("WEP1Type"..vifidx))
cfgs["Key2Type"]=mtkwifi.token_set(cfgs["Key2Type"],vifidx, http.formvalue("WEP2Type"..vifidx))
cfgs["Key3Type"]=mtkwifi.token_set(cfgs["Key3Type"],vifidx, http.formvalue("WEP3Type"..vifidx))
cfgs["Key4Type"]=mtkwifi.token_set(cfgs["Key4Type"],vifidx, http.formvalue("WEP4Type"..vifidx))
return cfgs
end
local function __security_cfg(cfgs, vif_idx)
mtkwifi.debug("__security_cfg, before, HideSSID="..tostring(cfgs.HideSSID))
mtkwifi.debug("__security_cfg, before, NoForwarding="..tostring(cfgs.NoForwarding))
mtkwifi.debug("__security_cfg, before, WmmCapable="..tostring(cfgs.WmmCapable))
mtkwifi.debug("__security_cfg, before, TxRate="..tostring(cfgs.TxRate))
mtkwifi.debug("__security_cfg, before, RekeyInterval="..tostring(cfgs.RekeyInterval))
mtkwifi.debug("__security_cfg, before, AuthMode="..tostring(cfgs.AuthMode))
mtkwifi.debug("__security_cfg, before, EncrypType="..tostring(cfgs.EncrypType))
mtkwifi.debug("__security_cfg, before, WscModeOption="..tostring(cfgs.WscModeOption))
mtkwifi.debug("__security_cfg, before, RekeyMethod="..tostring(cfgs.RekeyMethod))
mtkwifi.debug("__security_cfg, before, IEEE8021X="..tostring(cfgs.IEEE8021X))
mtkwifi.debug("__security_cfg, before, DefaultKeyID="..tostring(cfgs.DefaultKeyID))
mtkwifi.debug("__security_cfg, before, PMFMFPC="..tostring(cfgs.PMFMFPC))
mtkwifi.debug("__security_cfg, before, PMFMFPR="..tostring(cfgs.PMFMFPR))
mtkwifi.debug("__security_cfg, before, PMFSHA256="..tostring(cfgs.PMFSHA256))
mtkwifi.debug("__security_cfg, before, RADIUS_Server="..tostring(cfgs.RADIUS_Server))
mtkwifi.debug("__security_cfg, before, RADIUS_Port="..tostring(cfgs.RADIUS_Port))
mtkwifi.debug("__security_cfg, before, session_timeout_interval="..tostring(cfgs.session_timeout_interval))
mtkwifi.debug("__security_cfg, before, PMKCachePeriod="..tostring(cfgs.PMKCachePeriod))
mtkwifi.debug("__security_cfg, before, PreAuth="..tostring(cfgs.PreAuth))
mtkwifi.debug("__security_cfg, before, Wapiifname="..tostring(cfgs.Wapiifname))
cfgs.HideSSID = mtkwifi.token_set(cfgs.HideSSID, vif_idx, http.formvalue("__hidessid") or "0")
cfgs.NoForwarding = mtkwifi.token_set(cfgs.NoForwarding, vif_idx, http.formvalue("__noforwarding") or "0")
cfgs.WmmCapable = mtkwifi.token_set(cfgs.WmmCapable, vif_idx, http.formvalue("__wmmcapable") or "0")
cfgs.TxRate = mtkwifi.token_set(cfgs.TxRate, vif_idx, http.formvalue("__txrate") or "0");
cfgs.RekeyInterval = mtkwifi.token_set(cfgs.RekeyInterval, vif_idx, http.formvalue("__rekeyinterval") or "0");
local __authmode = http.formvalue("__authmode") or "Disable"
cfgs.AuthMode = mtkwifi.token_set(cfgs.AuthMode, vif_idx, __authmode)
--[[ need to handle disable case as it conflicts with OPENWEP
case = disable; authmode = OPEN, encryption = NONE
case = open/OPENWEP; authmode = OPEN, encryption = WEP
]]
if __authmode == "Disable" then
cfgs.AuthMode = mtkwifi.token_set(cfgs.AuthMode, vif_idx, "OPEN")
cfgs.EncrypType = mtkwifi.token_set(cfgs.EncrypType, vif_idx, "NONE")
cfgs.RekeyMethod = mtkwifi.token_set(cfgs.RekeyMethod, vif_idx, "DISABLE")
elseif __authmode == "OPEN" or __authmode == "SHARED" or __authmode == "WEPAUTO" then
--[[ the following required cfgs are already set in loop above
cfgs.Key{n}Str, ...
cfgs.Key{n}Type, ...
cfgs.DefaultKeyID
]]
cfgs.WscModeOption = "0"
cfgs.EncrypType = mtkwifi.token_set(cfgs.EncrypType, vif_idx, "WEP")
cfgs.RekeyMethod = mtkwifi.token_set(cfgs.RekeyMethod, vif_idx, "DISABLE")
cfgs = conf_wep_keys(cfgs,vif_idx)
cfgs.WscConfMode = mtkwifi.token_set(cfgs.WscConfMode, vif_idx, 0)
elseif __authmode == "WPAPSK" or __authmode == "WPAPSKWPA2PSK" then
--[[ the following required cfgs are already set in loop above
cfgs.WPAPSK{n}, ...
cfgs.RekeyInterval
]]
cfgs.RekeyMethod = mtkwifi.token_set(cfgs.RekeyMethod, vif_idx, "TIME")
cfgs.IEEE8021X = mtkwifi.token_set(cfgs.IEEE8021X, vif_idx, "0")
cfgs.DefaultKeyID = mtkwifi.token_set(cfgs.DefaultKeyID, vif_idx, "2")
cfgs.EncrypType = mtkwifi.token_set(cfgs.EncrypType, vif_idx, http.formvalue("__wpa_encrypttype") or "NONE")
--cfgs["WPAPSK"..vif_idx] = http.formvalue("WPAPSK"..vif_idx)
elseif __authmode == "WPA2PSK" then
--[[ the following required cfgs are already set in loop above
cfgs.WPAPSK{n}, ...
cfgs.RekeyInterval
]]
-- for DOT11W_PMF_SUPPORT
cfgs.EncrypType = mtkwifi.token_set(cfgs.EncrypType, vif_idx, http.formvalue("__wpa_encrypttype") or "0")
if cfgs.PMFMFPC then
cfgs.PMFMFPC = mtkwifi.token_set(cfgs.PMFMFPC, vif_idx, http.formvalue("__pmfmfpc") or "0")
end
if cfgs.PMFMFPR then
cfgs.PMFMFPR = mtkwifi.token_set(cfgs.PMFMFPR, vif_idx, http.formvalue("__pmfmfpr") or "0")
end
if cfgs.PMFSHA256 then
cfgs.PMFSHA256 = mtkwifi.token_set(cfgs.PMFSHA256, vif_idx, http.formvalue("__pmfsha256") or "0")
end
cfgs.RekeyMethod = mtkwifi.token_set(cfgs.RekeyMethod, vif_idx, "TIME")
cfgs.IEEE8021X = mtkwifi.token_set(cfgs.IEEE8021X, vif_idx, "0")
cfgs.DefaultKeyID = mtkwifi.token_set(cfgs.DefaultKeyID, vif_idx, "2")
elseif __authmode == "WPA" then
--[[ the following required cfgs are already set in loop above
cfgs.WPAPSK{n}, ...
cfgs.RekeyInterval
cfgs.RADIUS_Key
]]
cfgs.EncrypType = mtkwifi.token_set(cfgs.EncrypType, vif_idx, http.formvalue("__wpa_encrypttype") or "0")
cfgs.RADIUS_Server = mtkwifi.token_set(cfgs.RADIUS_Server, vif_idx, http.formvalue("__radius_server") or "0")
cfgs.RADIUS_Port = mtkwifi.token_set(cfgs.RADIUS_Port, vif_idx, http.formvalue("__radius_port") or "0")
cfgs.session_timeout_interval = mtkwifi.token_set(cfgs.session_timeout_interval, vif_idx, http.formvalue("__session_timeout_interval") or "0")
cfgs.RekeyMethod = mtkwifi.token_set(cfgs.RekeyMethod, vif_idx, "TIME")
cfgs.IEEE8021X = mtkwifi.token_set(cfgs.IEEE8021X, vif_idx, "0")
cfgs.DefaultKeyID = mtkwifi.token_set(cfgs.DefaultKeyID, vif_idx, "2")
elseif __authmode == "WPA2" then
--[[ the following required cfgs are already set in loop above
cfgs.WPAPSK{n}, ...
cfgs.RekeyInterval
cfgs.RADIUS_Key
]]
cfgs.EncrypType = mtkwifi.token_set(cfgs.EncrypType, vif_idx, http.formvalue("__wpa_encrypttype") or "0")
cfgs.RADIUS_Server = mtkwifi.token_set(cfgs.RADIUS_Server, vif_idx, http.formvalue("__radius_server") or "0")
cfgs.RADIUS_Port = mtkwifi.token_set(cfgs.RADIUS_Port, vif_idx, http.formvalue("__radius_port") or "0")
cfgs.session_timeout_interval = mtkwifi.token_set(cfgs.session_timeout_interval, vif_idx, http.formvalue("__session_timeout_interval") or "0")
cfgs.PMKCachePeriod = mtkwifi.token_set(cfgs.PMKCachePeriod, vif_idx, http.formvalue("__pmkcacheperiod") or "0")
cfgs.PreAuth = mtkwifi.token_set(cfgs.PreAuth, vif_idx, http.formvalue("__preauth") or "0")
-- for DOT11W_PMF_SUPPORT
if cfgs.PMFMFPC then
cfgs.PMFMFPC = mtkwifi.token_set(cfgs.PMFMFPC, vif_idx, http.formvalue("__pmfmfpc") or "0")
end
if cfgs.PMFMFPR then
cfgs.PMFMFPR = mtkwifi.token_set(cfgs.PMFMFPR, vif_idx, http.formvalue("__pmfmfpr") or "0")
end
if cfgs.PMFSHA256 then
cfgs.PMFSHA256 = mtkwifi.token_set(cfgs.PMFSHA256, vif_idx, http.formvalue("__pmfsha256") or "0")
end
cfgs.RekeyMethod = mtkwifi.token_set(cfgs.RekeyMethod, vif_idx, "TIME")
cfgs.IEEE8021X = mtkwifi.token_set(cfgs.IEEE8021X, vif_idx, "0")
cfgs.DefaultKeyID = mtkwifi.token_set(cfgs.DefaultKeyID, vif_idx, "2")
elseif __authmode == "WPA1WPA2" then
--[[ the following required cfgs are already set in loop above
cfgs.WPAPSK{n}, ...
cfgs.RekeyInterval
cfgs.RADIUS_Key
]]
cfgs.EncrypType = mtkwifi.token_set(cfgs.EncrypType, vif_idx, http.formvalue("__wpa_encrypttype") or "0")
cfgs.RADIUS_Server = mtkwifi.token_set(cfgs.RADIUS_Server, vif_idx, http.formvalue("__radius_server") or "0")
cfgs.RADIUS_Port = mtkwifi.token_set(cfgs.RADIUS_Port, vif_idx, http.formvalue("__radius_port") or "1812")
cfgs.session_timeout_interval = mtkwifi.token_set(cfgs.session_timeout_interval, vif_idx, http.formvalue("__session_timeout_interval") or "0")
cfgs.PMKCachePeriod = mtkwifi.token_set(cfgs.PMKCachePeriod, vif_idx, http.formvalue("__pmkcacheperiod") or "0")
cfgs.PreAuth = mtkwifi.token_set(cfgs.PreAuth, vif_idx, http.formvalue("__preauth") or "0")
cfgs.RekeyMethod = mtkwifi.token_set(cfgs.RekeyMethod, vif_idx, "TIME")
cfgs.IEEE8021X = mtkwifi.token_set(cfgs.IEEE8021X, vif_idx, "0")
cfgs.DefaultKeyID = mtkwifi.token_set(cfgs.DefaultKeyID, vif_idx, "2")
elseif __authmode == "IEEE8021X" then
cfgs.RekeyMethod = mtkwifi.token_set(cfgs.RekeyMethod, vif_idx, "DISABLE")
cfgs.AuthMode = mtkwifi.token_set(cfgs.AuthMode, vif_idx, "OPEN")
cfgs.IEEE8021X = mtkwifi.token_set(cfgs.IEEE8021X, vif_idx, "1")
cfgs.RADIUS_Server = mtkwifi.token_set(cfgs.RADIUS_Server, vif_idx, http.formvalue("__radius_server") or "0")
cfgs.RADIUS_Port = mtkwifi.token_set(cfgs.RADIUS_Port, vif_idx, http.formvalue("__radius_port") or "0")
cfgs.session_timeout_interval = mtkwifi.token_set(cfgs.session_timeout_interval, vif_idx, http.formvalue("__session_timeout_interval") or "0")
if http.formvalue("__8021x_wep") then
cfgs.EncrypType = mtkwifi.token_set(cfgs.EncrypType, vif_idx, "WEP")
else
cfgs.EncrypType = mtkwifi.token_set(cfgs.EncrypType, vif_idx, "NONE")
end
elseif __authmode == "WAICERT" then
cfgs.EncrypType = mtkwifi.token_set(cfgs.EncrypType, vif_idx, "SMS4")
cfgs.Wapiifname = mtkwifi.token_set(cfgs.Wapiifname, vif_idx, "br-lan")
-- cfgs.wapicert_asipaddr
-- cfgs.WapiAsPort
-- cfgs.wapicert_ascert
-- cfgs.wapicert_usercert
elseif __authmode == "WAIPSK" then
cfgs.EncrypType = mtkwifi.token_set(cfgs.EncrypType, vif_idx, "SMS4")
-- cfgs.wapipsk_keytype
-- cfgs.wapipsk_prekey
end
mtkwifi.debug("__security_cfg, after, HideSSID="..tostring(cfgs.HideSSID))
mtkwifi.debug("__security_cfg, after, NoForwarding="..tostring(cfgs.NoForwarding))
mtkwifi.debug("__security_cfg, after, WmmCapable="..tostring(cfgs.WmmCapable))
mtkwifi.debug("__security_cfg, after, TxRate="..tostring(cfgs.TxRate))
mtkwifi.debug("__security_cfg, after, RekeyInterval="..tostring(cfgs.RekeyInterval))
mtkwifi.debug("__security_cfg, after, AuthMode="..tostring(cfgs.AuthMode))
mtkwifi.debug("__security_cfg, after, EncrypType="..tostring(cfgs.EncrypType))
mtkwifi.debug("__security_cfg, after, WscModeOption="..tostring(cfgs.WscModeOption))
mtkwifi.debug("__security_cfg, after, RekeyMethod="..tostring(cfgs.RekeyMethod))
mtkwifi.debug("__security_cfg, after, IEEE8021X="..tostring(cfgs.IEEE8021X))
mtkwifi.debug("__security_cfg, after, DefaultKeyID="..tostring(cfgs.DefaultKeyID))
mtkwifi.debug("__security_cfg, after, PMFMFPC="..tostring(cfgs.PMFMFPC))
mtkwifi.debug("__security_cfg, after, PMFMFPR="..tostring(cfgs.PMFMFPR))
mtkwifi.debug("__security_cfg, after, PMFSHA256="..tostring(cfgs.PMFSHA256))
mtkwifi.debug("__security_cfg, after, RADIUS_Server="..tostring(cfgs.RADIUS_Server))
mtkwifi.debug("__security_cfg, after, RADIUS_Port="..tostring(cfgs.RADIUS_Port))
mtkwifi.debug("__security_cfg, after, session_timeout_interval="..tostring(cfgs.session_timeout_interval))
mtkwifi.debug("__security_cfg, after, PMKCachePeriod="..tostring(cfgs.PMKCachePeriod))
mtkwifi.debug("__security_cfg, after, PreAuth="..tostring(cfgs.PreAuth))
mtkwifi.debug("__security_cfg, after, Wapiifname="..tostring(cfgs.Wapiifname))
end
function initialize_multiBssParameters(cfgs,vif_idx)
cfgs["WPAPSK"..vif_idx]="12345678"
cfgs["Key1Type"]=mtkwifi.token_set(cfgs["Key1Type"],vif_idx,"0")
cfgs["Key2Type"]=mtkwifi.token_set(cfgs["Key2Type"],vif_idx,"0")
cfgs["Key3Type"]=mtkwifi.token_set(cfgs["Key3Type"],vif_idx,"0")
cfgs["Key4Type"]=mtkwifi.token_set(cfgs["Key4Type"],vif_idx,"0")
cfgs["RADIUS_Server"]=mtkwifi.token_set(cfgs["RADIUS_Server"],vif_idx,"0")
cfgs["RADIUS_Key"..vif_idx]="ralink"
cfgs["DefaultKeyID"]=mtkwifi.token_set(cfgs["DefaultKeyID"],vif_idx,"1")
cfgs["IEEE8021X"]=mtkwifi.token_set(cfgs["IEEE8021X"],vif_idx,"0")
cfgs["WscConfMode"]=mtkwifi.token_set(cfgs["WscConfMode"],vif_idx,"0")
cfgs["PreAuth"]=mtkwifi.token_set(cfgs["PreAuth"],vif_idx,"0")
return cfgs
end
function vif_cfg(dev, vif)
local devname, vifname = dev, vif
if not devname then devname = vif end
mtkwifi.debug("devname="..devname)
mtkwifi.debug("vifname="..(vifname or ""))
local devs = mtkwifi.get_all_devs()
local profile = devs[devname].profile
assert(profile)
local cfgs = mtkwifi.load_profile(profile)
for k,v in pairs(http.formvalue()) do
if type(v) == type("") or type(v) == type(0) then
nixio.syslog("debug", "post."..k.."="..tostring(v))
else
nixio.syslog("debug", "post."..k.." invalid, type="..type(v))
end
end
-- sometimes vif_idx start from 0, like AccessPolicy0
-- sometimes it starts from 1, like WPAPSK1. nice!
local vif_idx
local to_url
if http.formvalue("__action") == "vif_cfg_view" then
vif_idx = devs[devname]["vifs"][vifname].vifidx
mtkwifi.debug("vif_idx=", vif_idx, devname, vifname)
to_url = luci.dispatcher.build_url("admin", "network", "wifi", "vif_cfg_view", devname, vifname)
elseif http.formvalue("__action") == "vif_add_view" then
cfgs.BssidNum = tonumber(cfgs.BssidNum) + 1
vif_idx = tonumber(cfgs.BssidNum)
to_url = luci.dispatcher.build_url("admin", "network", "wifi")
-- initializing ; separated parameters for the new interface
cfgs = initialize_multiBssParameters(cfgs, vif_idx)
end
-- "__" should not be in the name if user wants to copy formvalue data directly in the dat file variable
for k,v in pairs(http.formvalue()) do
if type(v) ~= type("") and type(v) ~= type(0) then
nixio.syslog("err", "vif_cfg, invalid value type for "..k..","..type(v))
elseif string.byte(k) ~= string.byte("_") then
mtkwifi.debug("copying values for "..k)
cfgs[k] = v or ""
end
end
cfgs["AccessPolicy"..vif_idx-1] = http.formvalue("__accesspolicy")
local t = mtkwifi.parse_mac(http.formvalue("__maclist"))
cfgs["AccessControlList"..vif_idx-1] = table.concat(t, ";")
__security_cfg(cfgs, vif_idx)
mtkwifi.debug(devname, profile)
mtkwifi.save_profile(cfgs, profile)
if http.formvalue("__apply") then
__mtkwifi_reload(devname)
end
return luci.http.redirect(to_url)
end
function apcli_scan(ifname)
local aplist = mtkwifi.scan_ap(ifname)
http.write_json(aplist)
end
function get_station_list()
http.write("get_station_list")
end
function reset_wifi(devname)
if devname then
os.execute("cp -f /rom/etc/wireless/"..devname.."/ /etc/wireless/")
else
os.execute("cp -rf /rom/etc/wireless /etc/")
end
os.execute("rm -rf /tmp/mtk/wifi")
__mtkwifi_reload(devname)
return luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi"))
end
function reload_wifi(devname)
__mtkwifi_reload(devname)
return luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi"))
end
function get_raw_profile()
local sid = http.formvalue("sid")
http.write_json("get_raw_profile")
end
function get_country_region_list()
local mode = http.formvalue("mode")
local cr_list;
if mtkwifi.band(mode) == "5G" then
cr_list = mtkwifi.CountryRegionList_5G_All
else
cr_list = mtkwifi.CountryRegionList_2G_All
end
http.write_json(cr_list)
end
function remove_ch_by_region(ch_list, region)
for i = #ch_list,2,-1 do
if not ch_list[i].region[region] then
table.remove(ch_list, i)
end
end
end
function get_channel_list()
local mode = http.formvalue("mode")
local region = tonumber(http.formvalue("country_region")) or 1
local ch_list
if mtkwifi.band(mode) == "5G" then
ch_list = mtkwifi.ChannelList_5G_All
else
ch_list = mtkwifi.ChannelList_2G_All
end
remove_ch_by_region(ch_list, region)
http.write_json(ch_list)
end
function get_HT_ext_channel_list()
local ch_cur = tonumber(http.formvalue("ch_cur"))
local region = tonumber(http.formvalue("country_region")) or 1
local ext_ch_list = {}
if ch_cur <= 14 then -- 2.4G Channel
local ch_list = mtkwifi.ChannelList_2G_All
local below_ch = ch_cur - 4
local above_ch = ch_cur + 4
local i = 1
if below_ch > 0 and ch_list[below_ch + 1].region[region] then
ext_ch_list[i] = {}
ext_ch_list[i].val = 0
ext_ch_list[i].text = ch_list[below_ch + 1].text
i = i + 1
end
if above_ch <= 14 and ch_list[above_ch + 1].region[region] then
ext_ch_list[i] = {}
ext_ch_list[i].val = 1
ext_ch_list[i].text = ch_list[above_ch + 1].text
end
else -- 5G Channel
local ch_list = mtkwifi.ChannelList_5G_All
local ext_ch_idx = -1
local len = 0
for k, v in ipairs(ch_list) do
len = len + 1
if v.channel == ch_cur then
ext_ch_idx = (k % 2 == 0) and k + 1 or k - 1
end
end
if ext_ch_idx > 0 and ext_ch_idx < len and ch_list[ext_ch_idx].region[region] then
ext_ch_list[1] = {}
ext_ch_list[1].val = ext_ch_idx % 2
ext_ch_list[1].text = ch_list[ext_ch_idx].text
end
end
http.write_json(ext_ch_list)
end
function get_5G_2nd_80Mhz_channel_list()
local ch_cur = tonumber(http.formvalue("ch_cur"))
local region = tonumber(http.formvalue("country_region"))
local ch_list = mtkwifi.ChannelList_5G_2nd_80MHZ_ALL
local ch_list_5g = mtkwifi.ChannelList_5G_All
local i, j, test_ch, test_idx
local bw80_1st_idx = -1
-- remove adjacent freqencies starting from list tail.
for i = #ch_list,1,-1 do
for j = 0,3 do
if ch_list[i].channel == -1 then
break
end
test_ch = ch_list[i].channel + j * 4
test_idx = ch_list[i].chidx + j
if test_ch == ch_cur then
if i + 1 <= #ch_list and ch_list[i + 1] then
table.remove(ch_list, i + 1)
end
table.remove(ch_list, i)
bw80_1st_idx = i
break
end
if i == (bw80_1st_idx - 1) or (not ch_list_5g[test_idx].region[region]) then
table.remove(ch_list, i)
break
end
end
end
-- remove unused channel.
for i = #ch_list,1,-1 do
if ch_list[i].channel == -1 then
table.remove(ch_list, i)
end
end
http.write_json(ch_list)
end
function apcli_cfg(dev, vif)
local devname = dev
mtkwifi.debug(devname)
local profiles = mtkwifi.search_dev_and_profile()
mtkwifi.debug(profiles[devname])
assert(profiles[devname])
local cfgs = mtkwifi.load_profile(profiles[devname])
for k,v in pairs(http.formvalue()) do
if type(v) ~= type("") and type(v) ~= type(0) then
nixio.syslog("err", "apcli_cfg, invalid value type for "..k..","..type(v))
elseif string.byte(k) ~= string.byte("_") then
cfgs[k] = v or ""
end
end
cfgs.ApCliSsid = ''..mtkwifi.__handleSpecialChars(http.formvalue("ApCliSsid"))
local __authmode = http.formvalue("ApCliAuthMode")
if __authmode == "Disable" then
cfgs.ApCliAuthMode = "OPEN"
cfgs.ApCliEncrypType = "NONE"
elseif __authmode == "OPEN" or __authmode == "SHARED" then
cfgs.ApCliAuthMode = __authmode
cfgs.ApCliEncrypType = http.formvalue("wep_ApCliEncrypType")
else
cfgs.ApCliAuthMode = __authmode
cfgs.ApCliEncrypType = http.formvalue("wpa_ApCliEncrypType")
end
mtkwifi.save_profile(cfgs, profiles[devname])
if http.formvalue("__apply") then
__mtkwifi_reload(devname)
end
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi", "apcli_cfg_view", dev, vif))
end
function apcli_connect(dev, vif)
-- dev_vif can be
-- 1. mt7620.apcli0 # simple case
-- 2. mt7615e.1.apclix0 # multi-card
-- 3. mt7615e.1.2G.apclix0 # multi-card & multi-profile
local devname,vifname = dev, vif
mtkwifi.debug("devname=", dev, "vifname=", vif)
mtkwifi.debug(devname)
mtkwifi.debug(vifname)
local profiles = mtkwifi.search_dev_and_profile()
mtkwifi.debug(profiles[devname])
assert(profiles[devname])
local cfgs = mtkwifi.load_profile(profiles[devname])
cfgs.ApCliEnable = "1"
mtkwifi.save_profile(cfgs, profiles[devname])
os.execute("iwpriv "..vifname.." set ApCliEnable=0")
os.execute("ifconfig "..vifname.." up")
os.execute("iwpriv "..vifname.." set Channel="..cfgs.Channel)
os.execute("iwpriv "..vifname.." set ApCliAuthMode="..cfgs.ApCliAuthMode)
os.execute("iwpriv "..vifname.." set ApCliEncrypType="..cfgs.ApCliEncrypType)
if cfgs.ApCliAuthMode == "WEP" then
os.execute("#iwpriv "..vifname.." set ApCliDefaultKeyID="..cfgs.ApCliDefaultKeyID)
os.execute("#iwpriv "..vifname.." set ApCliKey1="..cfgs.ApCliKey1Str)
elseif cfgs.ApCliAuthMode == "WPAPSK"
or cfgs.ApCliAuthMode == "WPA2PSK"
or cfgs.ApCliAuthMode == "WPA1PSKWPA2PSK" then
os.execute("iwpriv "..vifname.." set ApCliWPAPSK="..cfgs.ApCliWPAPSK)
end
os.execute("iwpriv "..vifname.." set ApCliSsid=\""..cfgs.ApCliSsid.."\"")
os.execute("iwpriv "..vifname.." set ApCliEnable=1")
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi"))
end
function apcli_disconnect(dev, vif)
-- dev_vif can be
-- 1. mt7620.apcli0 # simple case
-- 2. mt7615e.1.apclix0 # multi-card
-- 3. mt7615e.1.2G.apclix0 # multi-card & multi-profile
local devname,vifname = dev, vif
mtkwifi.debug("devname=", dev, "vifname", vif)
mtkwifi.debug(devname)
mtkwifi.debug(vifname)
local profiles = mtkwifi.search_dev_and_profile()
mtkwifi.debug(profiles[devname])
assert(profiles[devname])
local cfgs = mtkwifi.load_profile(profiles[devname])
cfgs.ApCliEnable = "0"
mtkwifi.save_profile(cfgs, profiles[devname])
os.execute("iwpriv "..vifname.." set ApCliEnable=0")
os.execute("ifconfig "..vifname.." down")
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi"))
end
@@ -1,327 +0,0 @@
<%+header%>
<!--
This module is a demo to configure MTK' proprietary WiFi driver.
Basic idea is to bypass uci and edit wireless profile (mt76xx.dat) directly.
LuCI's WiFi configuration is more logical and elegent, but it's quite tricky to
translate uci into MTK's WiFi profile (like we did in "uci2dat").
Hua Shao <nossiac@163.com>
-->
<%
local disp = require "luci.dispatcher"
-- local request = disp.context.path
local request = disp.context.request
local mtkwifi = require("mtkwifi")
--local devname = string.match(request[5], "(mt.+)%.")
local devname = request[5]
local devs = mtkwifi.get_all_devs()
local dev = {}
local vif = {}
local vifidx
for _,v in ipairs(devs) do
if v.devname == devname then
dev = v
end
end
local vifname = request[6] or dev.apcli.vifname
assert(vifname)
vif = dev and dev.vifs[vifname] or nil
vifidx = vif and vif.vifidx or nil
--print(devs, dev, dev.apcli, devname, vifname)
local cfgs = mtkwifi.load_profile(dev.profile)
local debug = 0
%>
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-17.250.41546-90ac861"></script>
<div id="loading" style="margin-top: 1em; display: none;">
<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:e;" />
&nbsp;&nbsp;&nbsp; 正在处理,请耐心等待......
</div>
<form method="post" name="cbi" action="<%=luci.dispatcher.build_url("admin", "network", "wifi", "apcli_cfg", devname, vifname)%>" enctype="multipart/form-data" onreset="return cbi_validate_reset(this)" onsubmit="return cbi_validate_form(this, 'Some fields are invalid, cannot save values!')" autocomplete="off">
<fieldset class="cbi-section" id="vif-cfg-apcli">
<legend> <a name="apcli_scan_section">无线中继 - <%=devname.."@"..vifname%> </a></legend>
<br />
<p class="left">
<input id="scan" type="button" class="cbi-button cbi-button-find" onclick="get_ap_list('<%=vifname%>')" value="扫描网络" />
</p>
<div id="loading" style="display:none;">
<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle;" />
&nbsp;&nbsp;&nbsp; 正在处理,请耐心等待......
</div>
<div id="aplist">
</div>
</fieldset>
<fieldset class="cbi-section" id="vif-cfg-apcli-config">
<legend> <a name="apcli_cfg_section"> 中继参数</a> </legend>
<table class="cbi-section-table">
<tbody>
<tr><th class="th1"></th><th></th><th></th></tr>
<tr>
<td>上级无线 SSID</td>
<td>
<input type="text" name="ApCliSsid" id="ApCliSsid" value="<%=cfgs.ApCliSsid%>"/>
</td>
<td></td>
</tr>
<tr>
<td>上级无线信道</td>
<td>
<input type="text" name="Channel" id="Channel" value="<%=dev.Channel%>"/>
</td>
<td> <span style="color:red;">将会重置当前信道.</span></td>
</tr>
<tr>
<td>上级无线加密模式</td>
<td>
<select name="ApCliAuthMode" cfg="ApCliAuthMode" id="ApCliAuthMode" onchange="ApCliAuthMode_onchange(this.options[this.options.selectedIndex].value)">
<% for _,v in ipairs(dev.ApCliAuthModeList) do %>
<% if (cfgs.ApCliAuthMode == "OPEN" and cfgs.ApCliEncrypType== "NONE") then
if(v == "Disable") then %>
<option value="<%=v%>" selected="selected" ><%=v%>
</option>
<% else %>
<option value="<%=v%>" ><%=v%>
</option>
<% end
else %>
<option value="<%=v%>" <% if cfgs.ApCliAuthMode==v then %>selected="selected" <% end %>><%=v%>
</option>
<% end %>
<% end %>
</select>
</td>
<td></td>
</tr>
</tbody>
<tbody id="apcli_wpa"<% if cfgs.ApCliAuthMode ~= "WPA2PSK" then %> style="display: none;"<% end %>>
<tr>
<td>上级无线加密算法</td>
<td>
<select name="wpa_ApCliEncrypType" id="wpa_ApCliEncrypType" >
<% for _, v in ipairs(dev.WPA_Enc_List) do %>
<option value="<%=v%>" <% if cfgs.ApCliEncrypType==v then %>selected="selected" <% end %>><%=v%>
</option>
<% end %>
</select>
</td>
<td></td>
</tr>
<tr>
<td>上级无线密码</td>
<td>
<input type="text" name="ApCliWPAPSK" id="ApCliWPAPSK" value="<%=cfgs.ApCliWPAPSK%>"/>
</td>
<td></td>
</tr>
</tbody>
<tbody id="apcli_wep"<% if cfgs.ApCliAuthMode ~= "WEP" then %> style="display: none;"<% end %>>
<tr>
<td>上级无线加密算法</td>
<td>
<select name="wep_ApCliEncrypType" id="wep_ApCliEncrypType" >
<% for _, v in ipairs(dev.WEP_Enc_List) do %>
<option value="<%=v%>" <% if cfgs.ApCliEncrypType==v then %>selected="selected" <% end %>><%=v%>
</option>
<% end %>
</select>
</td>
<td></td>
</tr>
<tr>
<td>上级无线密码</td>
<td>
<input type="text" name="ApCliKey1Str" id="ApCliKey1Str" value="<%=cfgs.ApCliKey1Str%>"/>
<input type="hidden" name="ApCliDefaultKeyID" value="1"/>
</td>
<td></td>
</tr>
</tbody>
</table>
</fieldset>
<div class="cbi-page-actions" id="apcli_form_buttons">
<input class="cbi-button cbi-button-apply" value="重启无线" type="button" onclick='wifi_reload("<%=luci.dispatcher.build_url("admin", "network", "wifi", "reload", devname)%>");' />
<input class="cbi-button cbi-button-apply" value="保存设置" type="submit" />
<input class="cbi-button cbi-button-reset" value="重置设置" type="reset" />
</div>
</form>
<script type="text/javascript">
function wifi_reload(url) {
window.scrollTo(0, 0);
document.getElementById('loading').style.display="";
XHR.get(url, null,
function(x)
{
console.log(x);
document.getElementById("loading").style.display="none";
window.location.reload();
}
);
}
function decode_ssid(ssid)
{
ssid = ssid.replace(/&amp;/g, "&");
ssid = ssid.replace(/&lt;/g, "<");
ssid = ssid.replace(/&gt;/g, ">");
ssid = ssid.replace(/&#34;/g, "\"");
ssid = ssid.replace(/&#39;/g, "'");
ssid = ssid.replace(/&nbsp;/g, " ");
var patt = new RegExp(/&#(\d+);/);
while (res = patt.exec(ssid))
{
ssid = ssid.replace("&#" + res[1] + ";", String.fromCharCode(res[1]));
}
return ssid;
}
var ap_list;
function create_ap_table (aplist) {
var table = document.createElement('table');
table.setAttribute("id", "aplist_table");
for (i in aplist) {
var tr = table.insertRow(i);
var td0 = tr.insertCell(0);
td0.innerHTML = aplist[i].ssid;
var td1 = tr.insertCell(1);
td1.innerHTML = aplist[i].channel;
var td2 = tr.insertCell(2);
td2.innerHTML = aplist[i].bssid;
var td3 = tr.insertCell(3);
td3.innerHTML = aplist[i].security;
var td4 = tr.insertCell(4);
td4.innerHTML = aplist[i].rssi;
var td5 = tr.insertCell(5);
if (aplist[i].authmode == "OPEN"
|| aplist[i].authmode == "WPAPSK"
|| aplist[i].authmode == "WPA2PSK"
|| aplist[i].authmode == "WPAPSKWPA2PSK") {
td5.innerHTML = '<a href="javascript:choose_rootap(\''+i+'\')" >启用</a>';
} else {
td5.innerHTML = 'Security Not Supported';
}
}
var tr = table.insertRow(0);
var td0 = tr.insertCell(0);
td0.innerHTML = '<strong>无线名称</strong>';
var td1 = tr.insertCell(1);
td1.innerHTML = '<strong>信道</strong>';
var td2 = tr.insertCell(2);
td2.innerHTML = '<strong>BSSID</strong>';
var td3 = tr.insertCell(3);
td3.innerHTML = '<strong>加密方式</strong>';
var td4 = tr.insertCell(4);
td4.innerHTML = '<strong>信号强度</strong>';
var td5 = tr.insertCell(5);
td5.innerHTML = '<strong>动作</strong>';
var div = document.getElementById('aplist');
div.innerHTML = "";
div.appendChild(table);
}
function get_ap_list(vifname) {
document.getElementById("loading").style.display="";
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "wifi", "apcli_scan")%>/' + vifname, null,
function(x)
{
console.log(x)
ap_list = eval(x.response);
console.log(ap_list);
create_ap_table(ap_list);
document.getElementById("loading").style.display="none";
}
);
}
function toggle_apcli (show) {
if (show) {
document.getElementById('apcli_cfg').style.display = "";
var a = document.getElementById('ApCliAuthMode')
var to = a.options[a.options.selectedIndex].value
if (to == "WPA2PSK"
|| to == "WPAPSK"
|| to == "WPAPSKWPA2PSK") {
document.getElementById("apcli_wpa").style.display="";
document.getElementById("apcli_wep").style.display="none";
} else if (to == "WEP") {
document.getElementById("apcli_wpa").style.display="none";
document.getElementById("apcli_wep").style.display="";
} else {
document.getElementById("apcli_wpa").style.display="none";
document.getElementById("apcli_wep").style.display="none";
}
}
else {
document.getElementById('apcli_cfg').style.display = "none";
document.getElementById('apcli_wpa').style.display = "none";
document.getElementById('apcli_wep').style.display = "none";
}
}
function ApCliAuthMode_onchange (to) {
if (to == "WPA2PSK"
|| to == "WPAPSK"
|| to == "WPAPSKWPA2PSK") {
document.getElementById("apcli_wpa").style.display="";
document.getElementById("apcli_wep").style.display="none";
} else if (to == "OPEN" || to == "SHARED") {
document.getElementById("apcli_wpa").style.display="none";
document.getElementById("apcli_wep").style.display="";
} else {
document.getElementById("apcli_wpa").style.display="none";
document.getElementById("apcli_wep").style.display="none";
}
}
function choose_rootap(index) {
document.getElementById("ApCliSsid").value=decode_ssid(ap_list[index].ssid);
document.getElementById("Channel").value=ap_list[index].channel;
document.getElementById("ApCliAuthMode").value=ap_list[index].authmode;
if (ap_list[index].authmode == "WPA2PSK"
|| ap_list[index].authmode == "WPAPSK"
|| ap_list[index].authmode == "WPAPSKWPA2PSK") {
document.getElementById("wpa_ApCliEncrypType").value=ap_list[index].encrypttype;
} else if (ap_list[index].authmode == "OPEN" || ap_list[index].authmode == "SHARED") {
if (ap_list[index].encrypttype == "NONE")
{
document.getElementById("ApCliAuthMode").value="Disable";
}
else
{
document.getElementById("wep_ApCliEncrypType").value=ap_list[index].encrypttype;
}
}
ApCliAuthMode_onchange(document.getElementById("ApCliAuthMode").value);
document.getElementById("ApCliWPAPSK").value="";
document.getElementById("ApCliKey1Str").value="";
location.href="#apcli_cfg_section";
}
window.onload = function() {
ApCliAuthMode_onchange(document.getElementById("ApCliAuthMode").value);
<% if cfgs.ApCliEnable == "1" then %>
toggle_apcli(true);
<% else %>
toggle_apcli(false);
<% end %>
}
</script>
<%+footer%>
@@ -1,851 +0,0 @@
<%+header%>
<!--
This module is a demo to configure MTK' proprietary WiFi driver.
Basic idea is to bypass uci and edit wireless profile (mt76xx.dat) directly.
LuCI's WiFi configuration is more logical and elegent, but it's quite tricky to
translate uci into MTK's WiFi profile (like we did in "uci2dat").
Hua Shao <nossiac@163.com>
-->
<%
local disp = require "luci.dispatcher"
-- local request = disp.context.path
local request = disp.context.request
local mtkwifi = require("mtkwifi")
local devname = request[5]
local devs = mtkwifi.get_all_devs()
local dev = {}
for _,v in ipairs(devs) do
if v.devname == devname then
dev = v
end
end
local cfgs = mtkwifi.load_profile(dev.profile)
%>
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-17.250.41546-90ac861"></script>
<div id="loading" style="margin-top: 1em; display: none;">
<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:e;" />
&nbsp;&nbsp;&nbsp; Please waiting while the page is loading......
</div>
<form method="post" name="cbi" action="<%=luci.dispatcher.build_url("admin", "network", "wifi", "dev_cfg", devname)%>" enctype="multipart/form-data" onreset="return cbi_validate_reset(this)" onsubmit="return cbi_validate_form(this, 'Some fields are invalid, cannot save values!')" autocomplete="false">
<fieldset class="cbi-section">
<legend> 无线高级设置 - <%=devname%>
<%
local diff = mtkwifi.diff_profile(dev.profile)
if next(diff) ~= nil then
%>
<span style="color:red;">(<a href="javascript:location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "reload", dev.devname)%>'">reload</a> to apply changes)</span>
<%
end
%>
</legend>
<table id="dev-cfg-basic" class="cbi-section-table">
<tr><th></th><td></td><td></td></tr>
<tr>
<td>模式</td>
<td>
<select style="width:auto" name="WirelessMode" id="WirelessMode" onchange="WirelessMode_onchange(this.options[this.options.selectedIndex].value)">
<% for k,v in pairs(dev.WirelessModeList) do %>
<option value="<%=k%>" <% if tonumber(dev.WirelessMode) == tonumber(k) then%> selected="selected"<% end %>><%=k%> - <%=v%></option>
<% end %>
</select>
</td>
<td></td>
</tr>
<tr>
<td>信道</td>
<td>
<select style="width:auto; min-width:180px;" name="Channel" id="Channel" onchange="Channel_onchange(this.value)" <% if cfgs.ApCliEnable == "1" then %> disabled="disabled" <% end %>>
</select>
</td>
<td><% if cfgs.ApCliEnable == "1" then %> APClient/Repeater Mode. <% end %></td>
</tr>
<tr>
<td>区域代码</td>
<td>
<select name="CountryCode" style="width:auto">
<option value="US" id="advCountryCodeUS" <% if cfgs.CountryCode == "US" then %> selected="selected"<% end %>>US (United States)</option>
<option value="JP" id="advCountryCodeJP" <% if cfgs.CountryCode == "JP" then %> selected="selected"<% end %>>JP (Japan)</option>
<option value="FR" id="advCountryCodeFR" <% if cfgs.CountryCode == "FR" then %> selected="selected"<% end %>>FR (France)</option>
<option value="TW" id="advCountryCodeTW" <% if cfgs.CountryCode == "TW" then %> selected="selected"<% end %>>TW (Taiwan)</option>
<option value="IE" id="advCountryCodeIE" <% if cfgs.CountryCode == "IE" then %> selected="selected"<% end %>>IE (Ireland)</option>
<option value="HK" id="advCountryCodeHK" <% if cfgs.CountryCode == "HK" then %> selected="selected"<% end %>>HK (Hong Kong)</option>
<option value="NONE" id="advCountryCodeNONE"<% if cfgs.CountryCode == "NONE" then %> checked="checked"<% end %>>NONE</option>
</select>
</td>
<td></td>
</tr>
<tr>
<td>Country Region</td>
<td>
<select style="width:auto; min-width:180px;" name="__cr" id="__cr" onchange="CountryRegion_onchange(this.value)">
</select>
</td>
<td></td>
</tr>
<% if cfgs.HT_OpMode then %>
<tr>
<td>无线模式</td>
<td>
<select style="width:auto" name="HT_OpMode">
<option value="0" <% if cfgs.HT_OpMode == "0" then %> selected="selected"<% end%>>正常模式</option>
<option value="1" <% if cfgs.HT_OpMode == "1" then %> selected="selected"<% end%>>绿色模式</option>
</select>
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.HT_GI then %>
<tr>
<td>HT Guard Interval</td>
<td>
<select style="width:auto" name="HT_GI">
<option value="0" <% if cfgs.HT_GI == "0" then %> selected="selected"<% end%>>Long</option>
<option value="1" <% if cfgs.HT_GI == "1" then %> selected="selected"<% end%>>Short</option>
<option value="2" <% if cfgs.HT_GI == "2" then %> selected="selected"<% end%>>Auto</option>
</select>
</td>
<td></td>
</tr>
<% end %>
<tr>
<td>信道带宽</td>
<td>
<select style="width:auto" name="__bw" id="__bw" onchange="Bw_onchange(this.options[this.options.selectedIndex].value)">
<option value="20" <% if dev.__bw == "20" then %> selected="selected"<% end%>>20 MHz</option>
<option value="40" <% if dev.__bw == "40" then %> selected="selected"<% end%>>40 MHz</option>
<option value="60" <% if dev.__bw == "60" then %> selected="selected"<% end%>>20/40 MHz</option>
<option value="80" <% if dev.__bw == "80" then %> selected="selected"<% end%>>80 MHz</option>
<option value="160" <% if dev.__bw == "160" then %> selected="selected"<% end%>>160 MHz</option>
<option value="161" <% if dev.__bw == "161" then %> selected="selected"<% end%>>80+80 MHz</option>
</select>
</td>
<td></td>
</tr>
<% if cfgs.VHT_BW then %>
<tr>
<td>2G 40MHZ模式辅助信道</td>
<td>
<select style="width:auto; min-width:180px;" name="HT_EXTCHA" id="HT_EXTCHA" <% if cfgs.ApCliEnable == "1" or dev.__bw ~= "40" or dev.__bw ~= "60" then %> disabled="disabled" <% end %>>
</select>
</td>
<td><% if cfgs.ApCliEnable == "1" then %> APClient/Repeater Mode. <% end %></td>
</tr>
<tr>
<td>5G 2nd 80Mhz Channel</td>
<td>
<select style="width:auto; min-width:180px;" name="VHT_Sec80_Channel" id="VHT_Sec80_Channel" <% if cfgs.ApCliEnable == "1" or dev.__bw ~= "180" then %> disabled="disabled" <% end %>>
</select>
</td>
<td><% if cfgs.ApCliEnable == "1" then %> APClient/Repeater Mode. <% end %></td>
</tr>
<% end %>
<% if cfgs.HT_STBC then %>
<tr>
<td>STBC</td>
<td>
<input type="radio" name="HT_STBC" value="1" <% if cfgs.HT_STBC == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="HT_STBC" value="0" <% if cfgs.HT_STBC == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.HT_AMSDU then %>
<tr>
<td>A-MSDU</td>
<td>
<input type="radio" name="HT_AMSDU" value="1" <% if cfgs.HT_AMSDU == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="HT_AMSDU" value="0" <% if cfgs.HT_AMSDU == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.HT_AutoBA then %>
<tr>
<td>Auto Block ACK</td>
<td>
<input type="radio" name="HT_AutoBA" value="1" <% if cfgs.HT_AutoBA == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="HT_AutoBA" value="0" <% if cfgs.HT_AutoBA == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.HT_BADecline then %>
<tr>
<td>Decline BA Request</td>
<td>
<input type="radio" name="HT_BADecline" value="1" <% if cfgs.HT_BADecline == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="HT_BADecline" value="0" <% if cfgs.HT_BADecline == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.HT_DisallowTKIP then %>
<tr>
<td>HT Disallow TKIP</td>
<td>
<input type="radio" name="HT_DisallowTKIP" value="1" <% if cfgs.HT_DisallowTKIP == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="HT_DisallowTKIP" value="0" <% if cfgs.HT_DisallowTKIP == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.HT_LDPC then %>
<tr>
<td>HT LDPC</td>
<td>
<input type="radio" name="HT_LDPC" value="1" <% if cfgs.HT_LDPC == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="HT_LDPC" value="0" <% if cfgs.HT_LDPC == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.VHT_SGI then %>
<tr>
<td>VHT Short GI</td>
<td>
<select style="width:auto" name="VHT_SGI">
<option value="0" <% if cfgs.VHT_SGI == "0" then %> selected="selected"<% end%>>Long</option>
<option value="1" <% if cfgs.VHT_SGI == "1" then %> selected="selected"<% end%>>Short</option>
</select>
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.VHT_STBC then %>
<tr>
<td>VHT STBC</td>
<td>
<input type="radio" name="VHT_STBC" value="1" <% if cfgs.VHT_STBC == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="VHT_STBC" value="0" <% if cfgs.VHT_STBC == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.VHT_BW_SIGNAL then %>
<tr>
<td>VHT BW Signaling</td>
<td>
<input type="radio" name="VHT_BW_SIGNAL" value="1" <% if cfgs.VHT_BW_SIGNAL == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="VHT_BW_SIGNAL" value="0" <% if cfgs.VHT_BW_SIGNAL == "0" then %> checked="checked"<% end %>/> 禁用
<input type="radio" name="VHT_BW_SIGNAL" value="0" <% if cfgs.VHT_BW_SIGNAL == "2" then %> checked="checked"<% end %>/> Dynamic
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.VHT_LDPC then %>
<tr>
<td>VHT LDPC</td>
<td>
<input type="radio" name="VHT_LDPC" value="1" <% if cfgs.VHT_LDPC == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="VHT_LDPC" value="0" <% if cfgs.VHT_LDPC == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.BGProtection then %>
<tr>
<td>BG Protection Mode</td>
<td>
<select name="BGProtection" style="width:auto">
<option value="0" <% if cfgs.BGProtection == "0" then %>selected="selected"<% end %>>Auto</option>
<option value="1" <% if cfgs.BGProtection == "1" then %>selected="selected"<% end %>>Always On</option>
<option value="2" <% if cfgs.BGProtection == "2" then %>selected="selected"<% end %>>Always Off</option>
</select>
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.VHT_BW then %>
<tr>
<td>HT Protection</td>
<td>
<input type="radio" name="HT_PROTECT" value="1" <% if cfgs.HT_PROTECT == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="HT_PROTECT" value="0" <% if cfgs.HT_PROTECT == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.BeaconPeriod then %>
<tr>
<td>Beacon Interval</td>
<td>
<input name="BeaconPeriod" value="<%=cfgs.BeaconPeriod%>" />ms(范围 20-999, 默认值 100)
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.DtimPeriod then %>
<tr>
<td>Data Beacon Rate (DTIM)</td>
<td>
<input name="DtimPeriod" value="<%=cfgs.DtimPeriod%>" />ms(范围 1-255, 默认值 1)
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.FragThreshold then %>
<tr>
<td>Fragment Threshold</td>
<td>
<input name="FragThreshold" value="<%=cfgs.FragThreshold%>" />(范围 256-2346, 默认值 2346)
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.RTSThreshold then %>
<tr>
<td>RTS Threshold</td>
<td>
<input name="RTSThreshold" value="<%=cfgs.RTSThreshold%>" />(范围 256-2347, 默认值 2347)
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.TxPower then %>
<tr>
<td>TX Power</td>
<td>
<input name="TxPower" value="<%=cfgs.TxPower%>" />dbm(范围 1-100, 默认值 100)
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.TxPreamble then %>
<tr>
<td>Short Preamble</td>
<td>
<input type="radio" name="TxPreamble" value="1" <% if cfgs.TxPreamble == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="TxPreamble" value="0" <% if cfgs.TxPreamble == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.ShortSlot then %>
<tr>
<td>Short Slot</td>
<td>
<input type="radio" name="ShortSlot" value="1" <% if cfgs.ShortSlot == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="ShortSlot" value="0" <% if cfgs.ShortSlot == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.TxBurst then %>
<tr>
<td>TX Burst</td>
<td>
<input type="radio" name="TxBurst" value="1" <% if cfgs.TxBurst == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="TxBurst" value="0" <% if cfgs.TxBurst == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.PktAggregate then %>
<tr>
<td>Packet Aggregate</td>
<td>
<input type="radio" name="PktAggregate" value="1" <% if cfgs.PktAggregate == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="PktAggregate" value="0" <% if cfgs.PktAggregate == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
<% if cfgs.IEEE80211H then %>
<tr>
<td>802.11H</td>
<td>
<input type="radio" name="IEEE80211H" value="1" <% if cfgs.IEEE80211H == "1" then %> checked="checked"<% end %>/> 启用
<input type="radio" name="IEEE80211H" value="0" <% if cfgs.IEEE80211H == "0" then %> checked="checked"<% end %>/> 禁用
</td>
<td></td>
</tr>
<% end %>
</table>
</fieldset>
<div class="cbi-page-actions">
<input class="cbi-button cbi-button-apply" value="重启无线" type="button" onclick='wifi_reload("<%=luci.dispatcher.build_url("admin", "network", "wifi", "reload", devname)%>");' />
<input class="cbi-button cbi-button-apply" value="保存设置" type="submit" />
<input class="cbi-button cbi-button-apply" name="__apply" value="保存&应用" type="submit" />
<input class="cbi-button cbi-button-reset" value="重置" type="reset" />
</div>
</form>
<form method="post" name="cbi2" action="<%=luci.dispatcher.build_url("admin", "network", "wifi", "dev_cfg_raw", devname)%>" enctype="multipart/form-data" onreset="return cbi_validate_reset(this)" onsubmit="return cbi_validate_form(this, 'Some fields are invalid, cannot save values!')" autocomplete="off">
<fieldset class="cbi-section">
<legend> 无线参数(直接修改无线配置)</legend>
<p> <span style="color: red"><b>警告</b></span> : 如果你不了解请不要修改!</p>
<textarea name="raw" id="raw" style="width:98%; height: 200px;"><%
local fd = io.open(dev.profile)
for line in fd:lines() do
print(line)
end
%></textarea>
</fieldset>
<div class="cbi-page-actions">
<input class="cbi-button cbi-button-reset" value="重置" onclick="location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "dev_cfg_view", devname)%>'" type="button" />
<input class="cbi-button cbi-button-apply" id="save" value="保存" type="submit" onclick="if (confirm('你将修改无线参数,确认要修改?')) return true; else return false;" />
<input class="cbi-button cbi-button-apply" id="reset" value="恢复出厂设置" type="button" onclick="if (confirm(' 确认恢复<%=devname%> 至出厂设置?')) location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "dev_cfg_reset", devname)%>'" />
</div>
</form>
<script type="text/javascript">
function wifi_reload(url) {
window.scrollTo(0, 0);
document.getElementById('loading').style.display="";
XHR.get(url, null,
function(x)
{
console.log(x);
document.getElementById("loading").style.display="none";
window.location.reload();
}
);
}
function WirelessMode_onchange (mode) {
var cr = GetCountryRegion(mode);
getCountryRegionList(mode, cr);
}
function CountryRegion_onchange(country_region) {
var wmode_o = document.getElementById('WirelessMode');
var wmode;
if (wmode_o)
wmode = wmode_o.value;
if (wmode == "")
wmode = "<%=cfgs.WirelessMode%>";
getChannelList(wmode, country_region);
}
function Channel_onchange (ch) {
getBw(null, ch);
}
function Bw_onchange(bw, ch) {
var ch_val;
if (!ch){
var ch_o = document.getElementById('Channel');
if (ch_o)
ch_val = ch_o.value;
if (ch_val == "")
ch_val = "<%=cfgs.Channel%>";
} else {
ch_val = ch
}
get5G2nd80MhzChannelList(bw, ch_val);
getHTExtChannel(bw, ch_val);
}
function initCountryRegionList(list, mode){
var select = document.getElementById('__cr');
var cr = {};
if (is_mode_gband(mode))
cr = "<%=cfgs.CountryRegion%>";
else if (is_mode_aband(mode))
cr = "<%=cfgs.CountryRegionABand%>";
var new_cr = initList(select, list, cr, "region");
CountryRegion_onchange(new_cr);
}
function getCountryRegionList(mode) {
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "wifi", "get_country_region_list")%>', 'mode='+mode,
function(x)
{
//console.log(x);
//console.log(x.response);
var json = eval(x.response);
initCountryRegionList(json, mode);
}
);
}
function initChannelList(list) {
/* choose auto select when no matching item in the lis */
var select = document.getElementById('Channel');
var ch = {};
var new_ch = null;
ch.cval = select.value;
ch.oval = "<%=dev.Channel%>";
var new_ch = initList(select, list, ch, "channel");
Channel_onchange(new_ch);
}
function getChannelList(mode, country_region) {
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "wifi", "get_channel_list")%>', 'mode='+mode+'&country_region='+country_region,
function(x)
{
console.log(x);
console.log(x.response);
var json = eval(x.response);
initChannelList(json);
}
);
}
function GetCountryRegion(mode) {
var cr_o = document.getElementById('__cr');
var cr = "";
if (cr_o) {
cr = cr_o.value;
}
if (cr == "") {
if (is_mode_gband(mode)) {
cr = "<%=cfgs.CountryRegion%>";
} else if (is_mode_aband(mode)) {
cr = "<%=cfgs.CountryRegionABand%>";
} else {
alert("Cannot get valid CountryRegion from invalid WireleeMode");
}
}
return cr;
}
function getBw(mode, ch) {
/* choose bw as wide as possible if modification is needed */
var bw_sel = document.getElementById('__bw');
var wmode;
if (!mode) {
wmode = document.getElementById('WirelessMode');
wmode = wmode.value*1;
} else {
wmode = mode*1;
}
if (is_mode_legacy_only(wmode)) {
for (var idx in bw_sel.options) {
bw_sel.options[idx].disabled = false;
if (bw_sel.options[idx].value == 20)
bw_sel.options[idx].selected = true;
if (bw_sel.options[idx].value > 20)
bw_sel.options[idx].disabled = true;
}
} else if (is_ch_gband(ch)) {
for (var idx in bw_sel.options) {
bw_sel.options[idx].disabled = false;
if ((bw_sel.options[idx].value == 60) && (bw_sel.selectedIndex > idx))
bw_sel.options[idx].selected = true;
if (bw_sel.options[idx].value > 60)
bw_sel.options[idx].disabled = true;
}
} else if (is_ch_aband(ch)) {
var chosen60 = false;
var bw160 = "<%=cfgs.VHT_BW%>"*1;
if (bw_sel.value == 60)
chosen60 = 1;
for (var idx in bw_sel.options) {
bw_sel.options[idx].disabled = false;
if (bw_sel.options[idx].value == 40 && chosen60 && bw160 == 0) {
bw_sel.options[idx].selected = true;
} else if (bw_sel.options[idx].value == 60) {
bw_sel.options[idx].disabled = true;
bw_sel.options[idx].selected = false;
} else if (bw_sel.options[idx].value == 160 && chosen60 && bw160 == 1) {
bw_sel.options[idx].selected = true;
}
}
}
Bw_onchange(bw_sel.value, ch);
}
function init5G2nd80MhzChannelList(list) {
var select = document.getElementById('VHT_Sec80_Channel');
var ch2 = {};
var new_ch2 = null;
ch2.cval = select.value;
ch2.oval = "<%=cfgs.VHT_Sec80_Channel%>";
initList(select, list, ch2, "channel");
if (select.length > 0)
select.disabled = false;
else
alert("[Warning] 5G 2nd 80Mhz Channel is not available. Please Check CountryRegion.");
}
function get5G2nd80MhzChannelList(bw, ch) {
var ch_5g_2nd = document.getElementById('VHT_Sec80_Channel');
ch_5g_2nd.disabled = true;
if (ch == "0")
return;
if (bw != "161" || ch == "0")
return;
var mode = document.getElementById('WirelessMode');
mode = mode.value*1;
var cr = GetCountryRegion(mode);
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "wifi", "get_5G_2nd_80Mhz_channel_list")%>', 'ch_cur='+ch+'&country_region='+cr,
function(x)
{
//console.log(x);
//console.log(x.response);
var json = eval(x.response);
init5G2nd80MhzChannelList(json);
}
);
}
function initHTExtChannelList(list) {
var select = document.getElementById('HT_EXTCHA');
var ch2 = {};
var new_ch2 = null;
ch2.cval = select.value;
ch2.oval = "<%=cfgs.HT_EXTCHA%>";
initList(select, list, ch2, "val");
if (select.length > 0)
select.disabled = false;
else
alert("[Warning] 2G 40Mhz Ext Channel is not avalable. Please Check CountryRegion.");
}
function getHTExtChannel(bw, ch) {
var ch_2g_ext = document.getElementById('HT_EXTCHA');
ch_2g_ext.disabled = true;
if (ch == "0")
return;
if (bw != "40" && bw != "60")
return;
var mode = document.getElementById('WirelessMode');
mode = mode.value*1;
var cr = GetCountryRegion(mode);
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "wifi", "get_HT_ext_channel_list")%>', 'ch_cur='+ch+'&country_region='+cr,
function(x)
{
console.log(x);
console.log(x.response);
var json = eval(x.response);
initHTExtChannelList(json);
}
);
}
function toggle_apcli (show) {
if (show) {
document.getElementById('apcli_cfg').style.display = "";
var a = document.getElementById('ApCliAuthMode')
var to = a.options[a.options.selectedIndex].value
if (to == "WPA2PSK") {
document.getElementById("apcli_wpa").style.display="";
document.getElementById("apcli_wep").style.display="none";
} else if (to == "WEP") {
document.getElementById("apcli_wpa").style.display="none";
document.getElementById("apcli_wep").style.display="";
} else {
document.getElementById("apcli_wpa").style.display="none";
document.getElementById("apcli_wep").style.display="none";
}
}
else {
document.getElementById('apcli_cfg').style.display = "none";
document.getElementById('apcli_wpa').style.display = "none";
document.getElementById('apcli_wep').style.display = "none";
}
}
function ApCliAuthMode_onchange (to) {
if (to == "WPA2PSK") {
document.getElementById("apcli_wpa").style.display="";
document.getElementById("apcli_wep").style.display="none";
} else if (to == "WEP") {
document.getElementById("apcli_wpa").style.display="none";
document.getElementById("apcli_wep").style.display="";
} else {
document.getElementById("apcli_wpa").style.display="none";
document.getElementById("apcli_wep").style.display="none";
}
}
function toggle_atf(o) {
if (o.getAttribute("value") == "1") {
document.getElementById("VOW_Airtime_Fairness_En").value = "0";
o.setAttribute("value", "0");
o.className = "cbi-button cbi-button-add";
o.innerHTML = "Enable ATC";
} else {
document.getElementById("VOW_Airtime_Fairness_En").value = "1";
o.setAttribute("value", "1");
o.className = "cbi-button cbi-button-remove";
o.innerHTML = "Disable ATC";
}
}
function toggle_atc(o) {
if (o.getAttribute("value") == "1") {
document.getElementById("VOW_BW_Ctrl").value = "0";
o.setAttribute("value", "0");
o.className = "cbi-button cbi-button-add";
o.innerHTML = "Enable ATC";
document.getElementById("atc-table").style.display = "none";
} else {
document.getElementById("VOW_BW_Ctrl").value = "1";
o.setAttribute("value", "1");
o.className = "cbi-button cbi-button-remove";
o.innerHTML = "Disable ATC";
document.getElementById("atc-table").style.display = "";
}
}
function is_mode_legacy_only(mode) {
var imode = mode*1;
return ((imode >= 0) && (imode <= 4));
}
function is_mode_gband(mode) {
var imode = mode*1;
var gband_mode_list = [0,1,4,6,7,9,16];
var i;
for (i = 0; i < gband_mode_list.length; i++){
if( gband_mode_list[i] == imode )
return true;
}
return false;
}
function is_mode_aband(mode) {
var imode = mode*1;
var aband_mode_list = [2,8,11,14,15,17];
var i;
for (i = 0; i < aband_mode_list.length; i++){
if( aband_mode_list[i] == imode )
return true;
}
return false;
}
function is_ch_gband(ch) {
ch = ch*1;
if (ch == 0) {
var wmode = document.getElementById('WirelessMode');
return is_mode_gband(wmode.value);
}
return ((ch > 0) && (ch <= 14));
}
function is_ch_aband(ch) {
ch = ch*1;
if (ch == 0) {
var wmode = document.getElementById('WirelessMode');
return is_mode_aband(wmode.value);
}
return ((ch >= 36 ) && (ch <= 165));
}
function initList(selobj, list, selvals, value, text){
var sel = {};
var id = selobj.id;
if (typeof(selvals) != "object")
sel[0] = selvals;
else
sel = selvals;
selobj.innerHTML = "";
for (var i in list) {
var opt = document.createElement('option');
if(value)
opt.value = list[i][value];
else
opt.value = list[i].value;
if(text)
opt.text = list[i][text];
else
opt.text = list[i].text;
selobj.appendChild(opt);
}
var selv = null;
for (var k in sel) {
//console.log("[initList][" + id + "] sel[" + k + "]=" + sel[k]);
for (var i in selobj.options){
if (selobj.options[i].value == sel[k]){
selobj.options[i].selected = true;
selv = sel[k];
//console.log("[initList][" + id + "] found selv=" + selv);
break;
}
}
if (selv) break;
}
if (!selv) {
selv = selobj.value;
//console.log("[initList][" + id + "] !selv, selv=" + selv);
}
return selv;
}
window.onload = function() {
WirelessMode_onchange('<%=dev.WirelessMode%>');
ApCliAuthMode_onchange('<%=cfgs.ApCliAuthMode%>');
}
</script>
<%+footer%>
@@ -1,159 +0,0 @@
<%+header%>
<!--
This module is a demo to configure MTK' proprietary WiFi driver.
Basic idea is to bypass uci and edit wireless profile (mt76xx.dat) directly.
LuCI's WiFi configuration is more logical and elegent, but it's quite tricky to
translate uci into MTK's WiFi profile (like we did in "uci2dat").
Hua Shao <nossiac@163.com>
-->
<%
local mtkwifi = require("mtkwifi")
local devs = mtkwifi.get_all_devs()
%>
<h2><a name="content">无线概况</a></h2>
<div id="loading" style="margin-top: 1em; display: none;">
<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:e;" />
&nbsp;&nbsp;&nbsp; Please waiting while the page is loading......
</div>
<% if #devs == 0 then %>
<fieldset class="cbi-section">
<legend>No wireless device found.</legend>
</fieldset>
<% end %>
<% for _,dev in ipairs(devs) do %>
<fieldset class="cbi-section">
<table class="cbi-section-table" style="margin:10px; empty-cells:hide">
<!-- physical device -->
<tbody>
<tr>
<td style="width:34px">
<img src="/luci-static/resources/icons/wifi_big.png" style="float:left; margin-right:10px" />
</td>
<td colspan="2" style="text-align:left">
<big><strong title="<%=dev.profile%>"> Generic Mediatek <%=dev.devname%></strong></big>
<%
local diff = mtkwifi.diff_profile(dev.profile)
%>
<br/>
<span><strong>模式:</strong> <% if dev.ApCliEnable == "1" then %> APCli <% else %> Master AP<% end %> </span>
</td>
<td style="width:310px;text-align:right">
<input class="cbi-button cbi-button-reload" style="width:100px" title="重启无线" value="重启无线" type="button" onclick='wifi_reload("<%=luci.dispatcher.build_url("admin", "network", "wifi", "reload", dev.devname)%>");' />
<input class="cbi-button cbi-button-edit" style="width:100px" title="配置无线高级设置" value="高级设置" type="button" onclick="location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "dev_cfg_view", dev.devname)%>'" />
<input class="cbi-button cbi-button-add" style="width:100px" title="添加SSID" value="添加" type="button" onclick="location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "vif_add_view", dev.devname,dev.vifs.__prefix)%>'" />
</td>
</tr>
<!-- /physical device -->
<!-- network list -->
<% for _,vif in ipairs(dev.vifs) do %>
<tr class="cbi-section-table-row cbi-rowstyle-1">
<td></td>
<td class="cbi-value-field" style="width:16px; padding:3px">
<% if vif.state == "up" then %>
<img src="/luci-static/resources/icons/signal-75-100.png" />
<% else %>
<img src="/luci-static/resources/icons/signal-none.png" />
<% end %>
</td>
<td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px"><strong>接口:</strong> <%=vif.vifname%> | <strong>无线名称:</strong> <%=vif.__ssid%> | <strong>信道:</strong> <%=vif.__channel or dev.Channel%>
<br/>
<% if vif.state == "up" then %>
<strong>BSSID:</strong>:<%=vif.__bssid%> | <strong>无线模式:</strong> <%=dev.WirelessModeList[tonumber(vif.__wirelessmode or dev.WirelessMode)]%>
<% else %>
Wireless is disabled or not associated
<% end %>
</td>
<td class="cbi-value-field" style="text-align:right">
<% if not vif.state then %>
<input class="cbi-button cbi-button-apply" style="width:100px" title="启用无线" value="启用" type="button" onclick="alert('Please restart manually to create this interface.')" />
<% elseif vif.state == "up" then %>
<input class="cbi-button cbi-button-reset" style="width:100px" title="禁用无线" value="停用" type="button" onclick="location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "vif_disable", vif.vifname)%>'" />
<% else %>
<input class="cbi-button cbi-button-apply" style="width:100px" title="禁用无线" value="启用" type="button" onclick="location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "vif_enable", vif.vifname)%>'" />
<% end %>
<input class="cbi-button cbi-button-edit" style="width:100px" title="修改无线基本设置" value="基本设置" type="button" onclick="location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "vif_cfg_view", dev.devname, vif.vifname)%>'" />
<input class="cbi-button cbi-button-remove" style="width:100px" title="删除网络" value="移除" type="button" onclick="location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "vif_del", dev.devname, vif.vifname)%>'" />
</td>
</tr>
<% end %>
<!-- /network list -->
<!-- apcli list -->
<% if dev.apcli then %>
<tr>
<td></td>
<td class="cbi-value-field" style="width:16px; padding:3px">
<% if dev.apcli.state == "up" then %>
<img src="/luci-static/resources/icons/signal-75-100.png" />
<% else %>
<img src="/luci-static/resources/icons/signal-none.png" />
<% end %>
</td>
<td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px"><strong>接口:</strong> <%=dev.apcli.devname%> | <strong>类型:</strong> 中继 | <strong>状态:</strong> <%=dev.apcli.status%>
<br/>
<% if dev.apcli.status == "已连接" then %>
<strong>BSSID:</strong>:<%=dev.apcli.bssid%> |
<strong>上级SSID:</strong>:<%=dev.apcli.ssid%>
<% else %>
无线中继未连接
<% end %>
</td>
<td style="text-align:right">
<input class="cbi-button cbi-button-reload" style="width:100px" title="连接中继" value="连接中继" type="button" onclick='wifi_reload("<%=luci.dispatcher.build_url("admin", "network", "wifi", "apcli_connect", dev.devname,dev.apcli.vifname)%>")' />
<input class="cbi-button cbi-button-remove" style="width:100px" title="断开中继" value="断开中继" type="button" onclick='wifi_reload("<%=luci.dispatcher.build_url("admin", "network", "wifi", "apcli_disconnect", dev.devname, dev.apcli.vifname)%>")' />
<input class="cbi-button cbi-button-edit" style="width:100px" title="修改中继参数" value="中继设置" type="button" onclick="location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "apcli_cfg_view", dev.devname, dev.apcli.vifname)%>'" />
</td>
</tr>
<% end %>
<!-- /apcli list -->
</tbody>
</table>
</fieldset>
<% end %>
<!--
<h2><a id="content" name="content"><%:Station List%></a></h2>
<fieldset class="cbi-section">
<table class="cbi-section-table" style="margin:10px" id="iw-assoclist">
<tr class="cbi-section-table-titles">
<th class="cbi-section-table-cell"></th>
<th class="cbi-section-table-cell"><%:SSID%></th>
<th class="cbi-section-table-cell"><%:MAC-Address%></th>
<th class="cbi-section-table-cell"><%:IPv4-Address%></th>
<th class="cbi-section-table-cell"><%:Signal%></th>
<th class="cbi-section-table-cell"><%:Noise%></th>
<th class="cbi-section-table-cell"><%:RX Rate%></th>
<th class="cbi-section-table-cell"><%:TX Rate%></th>
</tr>
<tr class="cbi-section-table-row cbi-rowstyle-2">
<td class="cbi-value-field" colspan="8">
<em><%:Collecting data...%></em>
</td>
</tr>
</table>
</fieldset>
-->
<script type="text/javascript">
function wifi_reload(url) {
window.scrollTo(0, 0);
document.getElementById('loading').style.display="";
XHR.get(url, null,
function(x)
{
console.log(x);
document.getElementById("loading").style.display="none";
window.location.reload();
}
);
}
</script>
<%+footer%>
@@ -1,590 +0,0 @@
<%+header%>
<!--
This module is a demo to configure MTK' proprietary WiFi driver.
Basic idea is to bypass uci and edit wireless profile (mt76xx.dat) directly.
LuCI's WiFi configuration is more logical and elegent, but it's quite tricky to
translate uci into MTK's WiFi profile (like we did in "uci2dat").
Hua Shao <nossiac@163.com>
-->
<%
function any_wsc_enabled(wsc_conf_mode)
if (wsc_conf_mode == "7") then
return 1;
end
if (wsc_conf_mode == "4") then
return 1;
end
if (wsc_conf_mode == "2") then
return 1;
end
if (wsc_conf_mode == "1") then
return 1;
end
return 0;
end
local disp = require "luci.dispatcher"
local path = disp.context.path
local request = disp.context.request
local mtkwifi = require("mtkwifi")
local devname
local vifname, vifidx
local dev = {}
local vif = {}
if request[4] == "vif_add_view" then
devname, vifname = request[5], request[6]
local devs = mtkwifi.get_all_devs()
dev = devs and devs[devname]
vifname = vifname..#dev.vifs
vifidx = #dev.vifs + 1
elseif request[4] == "vif_cfg_view" then
devname, vifname = request[5], request[6]
local devs = mtkwifi.get_all_devs()
dev = devs and devs[devname] or nil
vif = dev and dev.vifs[vifname] or nil
vifidx = vif and vif.vifidx or nil
end
local cfgs = mtkwifi.load_profile(dev.profile)
local WscValue = mtkwifi.token_get(cfgs["WscConfMode"], vifidx, "0") or "0"
%>
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-17.250.41546-90ac861"></script>
<div id="loading" style="margin-top: 1em; display: none;">
<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:e;" />
&nbsp;&nbsp;&nbsp; Please waiting while the page is loading......
</div>
<form method="post" name="cbi" action="<%=luci.dispatcher.build_url("admin", "network", "wifi", "vif_cfg", devname, vifname)%>" enctype="multipart/form-data" onsubmit="return validate_security(<%=vifidx%>,<%=cfgs["HT_DisallowTKIP"]%>)" autocomplete="off">
<% if not dev or not vif then%>
<fieldset class="cbi-section">
<legend>Interface Not Exist - <%=vifname and devname.."@"..vifname or devname%>
</legend>
</fieldset>
<% else %>
<fieldset class="cbi-section">
<legend>无线高级设置 - <%=vifname and devname.."@"..vifname or devname%>
<%
local diff = mtkwifi.diff_profile(dev.profile)
if next(diff) ~= nil then
%>
<span style="color:red;">(<a href="javascript:location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "reload", dev.devname)%>'">reload</a> to apply changes)</span>
<%
end
%>
</legend>
<table id="vif-cfg-basic">
<tbody>
<tr>
<td>SSID</td>
<td>
<input value="<%=vif.__ssid%>" name="<%="SSID"..vifidx%>" required="required" />
<input value="<%=request[4]%>" name="__action" type="hidden" />
</td>
</tr>
<% if dev.DBDC_MODE == "0" then %>
<tr>
<td>Channel</td>
<td>
<select style="width:auto" name="__channel">
<% for i=0,14 do %>
<option value="<%=i%>" <% if i==vif.__channel then %> selected="selected"<% end %>>
<% if i==0 then %>Auto<% else %><%=i%><% end %>
</option>
<% end %>
</select>
</td>
</tr>
<% end %>
<tr>
<td>加密</td>
<td>
<select name="__authmode" cfg="AuthMode" id="AuthMode" onchange="AuthMode_onchange(this.options[this.options.selectedIndex].value)">
<%
local AuthModes
if(WscValue == "0") then
AuthModes = dev.AuthModeList
else
AuthModes = dev.WpsEnableAuthModeList
end
for _, v in ipairs(AuthModes) do
if (mtkwifi.token_get(cfgs.IEEE8021X, vifidx, nil) == "1") then
if(v == "IEEE8021X") then %>
<option value="<%=v%>" selected="selected" ><%=v%>
</option>
<% else %>
<option value="<%=v%>" ><%=v%>
</option>
<% end
elseif (vif.__authmode == "OPEN" and vif.__encrypttype== "NONE") then
if(v == "Disable") then %>
<option value="<%=v%>" selected="selected" ><%=v%>
</option>
<% else %>
<option value="<%=v%>" ><%=v%>
</option>
<% end
else%>
<option value="<%=v%>" <% if vif.__authmode==v then %>selected="selected" <% end %>><%=v%>
</option>
<% end %>
<% end %>
</select>
</td>
</tr>
</tbody>
<tbody id="wpacommon" style="display:none;">
<tr>
<td>算法</td>
<td>
<select name="__wpa_encrypttype" id="__wpa_encrypttype" cfg="EncrypType">
<% for _,v in ipairs(dev.WPA_Enc_List) do %>
<option value="<%=v%>" <% if vif.__encrypttype==v then %>selected="selected" <% end %>><%=v%>
</option>
<% end %>
</select>
</td>
</tr>
<tr>
<td>密钥更新时间</td>
<td>
<input value="<%=vif.__rekeyinterval%>" type="text" name="__rekeyinterval" id="__rekeyinterval" cfg="RekeyInterval" /> (0 ~ 4194303) 秒
</td>
</tr>
</tbody>
<tbody id="WPA2PSK" style="display:none;">
<tr>
<td>密码</td>
<td>
<input value="<%=vif.__wpapsk%>" type="text" name="<%="WPAPSK"..vifidx%>" id="<%="WPAPSK"..vifidx%>" />
</td>
</tr>
</tbody>
<tbody id="WEP" style="display:none;">
<tr>
<td>Encryption</td>
<td>
<select name="__wep_encrypttype" cfg="EncrypType">
<% for _,v in ipairs(dev.WEP_Enc_List) do %>
<option value="<%=v%>" <% if vif.__encrypttype==v then %>selected="selected" <% end %>><%=v%>
</option>
<% end %>
</select>
</td>
</tr>
<tr>
<td>Default Key</td>
<td>
<select name="__DefaultKeyID" id="__DefaultKeyID">
<option value="1" <%if tonumber(vif.__wepkey_id) == 1 then%>selected="selected"<%end%>>1</option>
<option value="2" <%if tonumber(vif.__wepkey_id) == 2 then%>selected="selected"<%end%>>2</option>
<option value="3" <%if tonumber(vif.__wepkey_id) == 3 then%>selected="selected"<%end%>>3</option>
<option value="4" <%if tonumber(vif.__wepkey_id) == 4 then%>selected="selected"<%end%>>4</option>
</select>
</td>
</tr>
<tr>
<td>WEP Key 1</td>
<td>
<input value="<%=cfgs["Key1Str"..vifidx]%>" type="text" name="<%="Key1Str"..vifidx%>" id="<%="Key1Str"..vifidx%>" />
</td>
</tr>
<tr>
<td>Key Type 1</td>
<td>
<select id="<%="WEP1Type"..vifidx%>" name="<%="WEP1Type"..vifidx%>">
<option value="1" <%if(mtkwifi.token_get(cfgs["Key1Type"], vifidx, 0)) == "1" then %> selected="selected"<%end%>>ASCII</option>
<option value="0" <%if(mtkwifi.token_get(cfgs["Key1Type"], vifidx, 0)) == "0" then %> selected="selected"<%end%>>Hex</option>
</select>
</td>
</tr>
<tr>
<td>WEP Key 2</td>
<td>
<input value="<%=cfgs["Key2Str"..vifidx]%>" type="text" name="<%="Key2Str"..vifidx%>" id="<%="Key2Str"..vifidx%>" />
</td>
</tr>
<tr>
<td>Key Type 2</td>
<td>
<select id="<%="WEP2Type"..vifidx%>" name="<%="WEP2Type"..vifidx%>">
<option value="1" <%if(mtkwifi.token_get(cfgs["Key2Type"], vifidx, 0)) == "1" then %> selected="selected"<%end%>>ASCII</option>
<option value="0" <%if(mtkwifi.token_get(cfgs["Key2Type"], vifidx, 0)) == "0" then %> selected="selected"<%end%>>Hex</option>
</select>
</td>
</tr>
<tr>
<td>WEP Key 3</td>
<td>
<input value="<%=cfgs["Key3Str"..vifidx]%>" type="text" name="<%="Key3Str"..vifidx%>" id="<%="Key3Str"..vifidx%>" />
</td>
</tr>
<tr>
<td>Key Type 3</td>
<td>
<select id="<%="WEP3Type"..vifidx%>" name="<%="WEP3Type"..vifidx%>">
<option value="1" <%if(mtkwifi.token_get(cfgs["Key3Type"], vifidx, 0)) == "1" then %> selected="selected"<%end%>>ASCII</option>
<option value="0" <%if(mtkwifi.token_get(cfgs["Key3Type"], vifidx, 0)) == "0" then %> selected="selected"<%end%>>Hex</option>
</select>
</td>
</tr>
<tr>
<td>WEP Key 4</td>
<td>
<input value="<%=cfgs["Key4Str"..vifidx]%>" type="text" name="<%="Key4Str"..vifidx%>" id="<%="Key4Str"..vifidx%>" />
</td>
</tr>
<tr>
<td>Key Type 4</td>
<td>
<select id="<%="WEP4Type"..vifidx%>" name="<%="WEP4Type"..vifidx%>">
<option value="1" <%if(mtkwifi.token_get(cfgs["Key4Type"], vifidx, 0)) == "1" then %> selected="selected"<%end%>>ASCII</option>
<option value="0" <%if(mtkwifi.token_get(cfgs["Key4Type"], vifidx, 0)) == "0" then %> selected="selected"<%end%>>Hex</option>
</select>
</td>
</tr>
</tbody>
<tbody id="WPA2" style="display:none;">
<tr>
<td>PMK Cache Period</td>
<td>
<input value="<%=vif.__pmkcacheperiod%>" type="text" name="__pmkcacheperiod" id="__pmkcacheperiod" cfg="PMKCachePeriod" /> minute(s)
</td>
</tr>
<tr>
<td>Pre-Authentication</td>
<td>
<input name="__preauth" id="__preauth" value="1"
<% if mtkwifi.token_get(cfgs["PreAuth"], vifidx, 0) == "1" then %>
checked="checked"
<% end %> type="checkbox" />
</td>
</tr>
</tbody>
<tbody id="PMF" style="display:none;">
<tr>
<td>MFPC </td>
<td> <input name="__pmfmfpc" id="__pmfmfpc" value="1"
<% if mtkwifi.token_get(cfgs["PMFMFPC"], vifidx, 0) == "1" then %>
checked="checked"
<% end %> type="checkbox" /> </td>
</tr>
<tr>
<td>MFPR </td>
<td> <input name="__pmfmfpr" id="__pmfmfpr" value="1"
<% if mtkwifi.token_get(cfgs["PMFMFPR"], vifidx, 0) == "1" then %>
checked="checked"
<% end %> type="checkbox" /></td>
</tr>
<tr>
<td>MFPSHA256 </td>
<td> <input name="__pmfsha256" id="__pmfsha256" value="1"
<% if mtkwifi.token_get(cfgs["PMFSHA256"], vifidx, 0) == "1" then %>
checked="checked"
<% end %> type="checkbox" /> </td>
</tr>
</tbody>
<tbody id="IEEE8021X" style="display:none;">
<tr>
<td>WEP for 8021X</td>
<td>
<input value="1" type="checkbox" name="__8021x_wep" <% if vif.__encrypttype=="WEP" then %>checked="checked" <% end %> />
</td>
</tr>
</tbody>
<tbody id="radius" style="display:none">
<tr>
<td>Radius Server IP</td>
<td>
<input value="<%=vif.__radius_server%>" type="text" name="__radius_server" id="__radius_server" cfg="RADIUS_Server" />
</td>
</tr>
<tr>
<td>Radius Server Port</td>
<td>
<input value="<%=vif.__radius_port%>" type="text" name="__radius_port" id="__radius_port" cfg="RADIUS_Port" />
</td>
</tr>
<tr>
<td>Shared Secret</td>
<td>
<input value="<%=cfgs["RADIUS_Key"..vifidx]%>" type="text" name="<%="RADIUS_Key"..vifidx%>" id="<%="RADIUS_Key"..vifidx%>" />
</td>
</tr>
<tr>
<td>Session Timeout</td>
<td>
<input value="<%=mtkwifi.token_get(cfgs.session_timeout_interval, vifidx, 0)%>" type="text" name="__session_timeout_interval" id="__session_timeout_interval" /> second(s)
</td>
</tr>
<tr>
<td>Idle Timeout</td>
<td>
<input value="<%=cfgs.idle_timeout_interval%>" type="text" name="idle_timeout_interval" id="idle_timeout_interval" /> second(s)
</td>
</tr>
</tbody>
<tbody>
<tr>
<td>隐藏 SSID</td>
<td>
<input name="__hidessid" cfg="HideSSID" value="1"
<% if vif.__hidessid == "1" then %>
checked="checked"
<% end %> type="checkbox" />
</td>
</tr>
<tr>
<td>隔离客户端</td>
<td>
<input name="__noforwarding" cfg="NoForwarding" value="1"
<% if vif.__noforwarding == "1" then %>
checked="checked"
<% end %> type="checkbox" />
</td>
</tr>
<tr>
<td>WMM 模式</td>
<td>
<input name="__wmmcapable" cfg="WmmCapable" value="1"
<% if vif.__wmmcapable ~= "0" then %>
checked="checked"
<% end %> type="checkbox" />
</td>
</tr>
<tr>
<td>强制发射速率 ( 0为自动,建议值 )</td>
<td>
<input value="<%=vif.__txrate or 0%>" name="__txrate" id="__txrate" />
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
</tr>
</tfoot>
</table>
</fieldset>
<div class="cbi-page-actions">
<input class="cbi-button cbi-button-apply" value="重启无线" type="button" onclick='wifi_reload("<%=luci.dispatcher.build_url("admin", "network", "wifi", "reload", devname)%>");' />
<input class="cbi-button cbi-button-apply" value="保存设置" type="submit" />
<input class="cbi-button cbi-button-apply" name="__apply" value="保存&应用" type="submit" />
<input class="cbi-button cbi-button-reset" value="重置" type="reset" />
</div>
<% end %> <!-- if not dev -->
</form>
<script type="text/javascript">
function wifi_reload(url) {
window.scrollTo(0, 0);
document.getElementById('loading').style.display="";
XHR.get(url, null,
function(x)
{
console.log(x);
document.getElementById("loading").style.display="none";
window.location.reload();
}
);
}
function AuthMode_onchange(to) {
var enc_list = new Array()
enc_list[0] = "OPEN";
enc_list[1] = "WEP";
enc_list[2] = "WPA2PSK";
enc_list[3] = "WPA2";
enc_list[4] = "IEEE8021X";
enc_list[5] = "WPAPSKWPA2PSK";
enc_list[6] = "WPA1WPA2";
//replacing input string to WEP (for the case of OPEN, SHARED, WEPAUTO) so as to enable the control with id wep
if ((to == "WEPAUTO") || (to == "SHARED") || (to == "OPEN")) {
to = "WEP";
}
for (enc in enc_list) {
var e = document.getElementById(enc_list[enc])
if (enc_list[enc] == to) {
if (e) e.style.display = "";
} else {
if (e) e.style.display = "none";
}
}
if (to == "WPA2" || to == "IEEE8021X" || to == "WPA1WPA2") {
document.getElementById("radius").style.display = "";
} else {
document.getElementById("radius").style.display = "none";
}
if (to == "WPA2" || to == "WPA2PSK" || to == "WPAPSKWPA2PSK" || to == "WPA1WPA2") {
document.getElementById("wpacommon").style.display = "";
if (to != "WPAPSKWPA2PSK") {
document.getElementById("PMF").style.display = "";
} else {
document.getElementById("PMF").style.display = "none";
}
} else {
document.getElementById("wpacommon").style.display = "none";
}
if (to == "WPAPSKWPA2PSK") {
document.getElementById("WPA2PSK").style.display = "";
}
}
function validate_security(vifidx, ht_disallow_tkip) {
if (document.getElementById("__activeTab").value != "basic") {
return true;
}
var e = document.getElementById("AuthMode");
var AuthMode = e.options[e.selectedIndex].value;
if (AuthMode == "Disable") {
if (isNaN(document.getElementById("__txrate").value) == true || (document.getElementById("__txrate").value == "")) {
alert('Please input a valid TX Rate value');
return false;
}
} else if (AuthMode == "OPEN" || AuthMode == "WEPAUTO" || AuthMode == "SHARED") {
return check_Wep(AuthMode, vifidx, ht_disallow_tkip);
} else if (AuthMode == "WPAPSK" || AuthMode == "WPA2PSK" || AuthMode == "WPAPSKWPA2PSK") {
return check_WpaKey(AuthMode, vifidx, ht_disallow_tkip);
} else if (AuthMode == "WPA2") {
if (check_Wpa2(AuthMode, vifidx) == false)
return false;
if (check_radius(vifidx) == false)
return false;
} else if (AuthMode == "8021X") {
if (check_radius(vifidx) == false)
return false;
} else if (AuthMode == "WPA" || AuthMode == "WPA1WPA2") // WPA or WPA1WP2 mixed mode
{
if (check_Wpa(AuthMode, vifidx, ht_disallow_tkip) == false)
return false;
if (check_radius(vifidx) == false)
return false;
} else if (AuthMode == "IEEE8021X") // 802.1x
{
if (check_radius(vifidx) == false)
return false;
} else {
alert("Unknown value " + AuthMode + "for Auth Mode");
return false;
}
return true;
}
function check_Wpa2(AuthMode, vifidx) {
if (isNaN(document.getElementById("__rekeyinterval").value) == true) {
alert('Please input a valid key renewal interval');
return false;
}
if (document.getElementById("__rekeyinterval").value == 0) {
alert('Renew key interval is equal to 0, so the device will not refresh key');
}
if (!document.getElementById("__pmkcacheperiod").value.length) {
alert('Please input the PMK Cache Period.');
return false;
} else if (isNaN(document.getElementById("__pmkcacheperiod").value)) {
alert('Please input a number for PMK Cache Period.');
return false;
}
if (check_radius(vifidx) == false)
return false;
}
function check_WpaKey(AuthMode, vifidx, ht_disallow_tkip) {
var keyvalue = document.getElementById("WPAPSK" + vifidx).value;
if (keyvalue.length == 0) {
alert('Please input wpapsk key!');
return false;
}
if (keyvalue.length < 8) {
alert('Please input at least 8 character of wpapsk key!');
return false;
}
if (keyvalue.length == 64 && checkHex(keyvalue) == false) {
alert('Please input 8~63 ASCII or 64 Hexadecimal character!');
return false;
}
if (checkInjection(keyvalue) == false) {
alert('Invalid characters in Pass Phrase.');
return false;
}
return check_Wpa(AuthMode, vifidx, ht_disallow_tkip);
}
function check_Wpa(AuthMode, vifidx, ht_disallow_tkip) {
var e = document.getElementById("__wpa_encrypttype");
var EncrypType = e.options[e.selectedIndex].value;
// there is no tkip-aes mixed mode in WPA-PSK.
if ((AuthMode == "WPA" || AuthMode == "WPAPSK") && (EncrypType == "TKIPAES")) {
alert("There is no TKIP-AES mode in WPA-PSK");
return false;
}
if (ht_disallow_tkip == "1" && EncrypType == "TKIP")
alert("Disallow TKIP/WEP encryption is enabled, so 11N rate will turn off!");
if (isNaN(document.getElementById("__rekeyinterval").value) == true) {
alert('Please input a valid key renewal interval');
return false;
}
if (document.getElementById("__rekeyinterval").value == 0) {
alert('Renew key interval is equal to 0, so the device will not refresh key');
}
return true;
}
function check_Wep(AuthMode, vifidx, ht_disallow_tkip) {
var e = document.getElementById("__DefaultKeyID");
var defaultid = e.options[e.selectedIndex].value;
var keyvalue = document.getElementById("Key" + defaultid + "Str" + vifidx).value;
if (keyvalue.length == 0) {
alert('Please input wep key' + defaultid + ' !');
return false;
}
var keylength = keyvalue.length;
if (keylength != 0) {
if (document.getElementById("WEP" + defaultid + "Type" + vifidx).selectedIndex == 0) {
if (keylength != 5 && keylength != 13) {
alert('Please input 5 or 13 characters of wep key' + defaultid + ' !');
return false;
}
if (checkInjection(keyvalue) == false) {
alert('Wep key' + defaultid + " contains invalid characters.");
return false;
}
}
if (document.getElementById("WEP" + defaultid + "Type" + vifidx).selectedIndex == 1) {
if (keylength != 10 && keylength != 26) {
alert('Please input 10 or 26 characters of wep key' + defaultid + ' !');
return false;
}
if (checkHex(keyvalue) == false) {
alert('Invalid Wep key1 format!');
return false;
}
}
}
if (ht_disallow_tkip == "1")
alert("Disallow TKIP/WEP encryption is enabled, so 11N rate will turn off!");
return true;
}
window.onload = AuthMode_onchange(document.getElementById("AuthMode").options[document.getElementById("AuthMode").selectedIndex].value)
</script>
<%+footer%>
@@ -1,2 +0,0 @@
/etc/wireless/mt7615/
-187
View File
@@ -1,187 +0,0 @@
#!/usr/bin/env lua
-- Alternative for OpenWrt's /sbin/wifi.
-- Copyright Not Reserved.
-- Hua Shao <nossiac@163.com>
package.path = '/lib/wifi/?.lua;'..package.path
local mtkwifi = require("mtkwifi")
local nixio = require("nixio")
function usage()
print("wifi <up|down|reset|reload|status> [devname]")
end
function wifi_common_up(devname)
nixio.syslog("debug", "wifi_common_up "..tostring(devname))
-- need to find out the vif prefix for this device
for _,vif in ipairs(string.split(mtkwifi.read_pipe("ls /sys/class/net"), "\n"))
do
if string.match(vif, "ra%a-%d+") then
os.execute("ifconfig "..vif.." up")
os.execute("brctl addif br-lan "..vif.." ")
end
end
end
function wifi_common_down(devname)
nixio.syslog("debug", "wifi_common_down "..tostring(devname))
-- need to find out the vif prefix for this device
for _,vif in ipairs(string.split(mtkwifi.read_pipe("ls /sys/class/net"), "\n"))
do
if string.match(vif, "ra%d+")
or string.match(vif, "rai%d+")
or string.match(vif, "rae%d+")
or string.match(vif, "rax%d+") then
os.execute("ifconfig "..vif.." down")
end
end
end
function wifi_common_reload(devname)
nixio.syslog("debug", "wifi_common_reload "..tostring(devname))
wifi_common_up()
wifi_common_down()
end
function wifi_common_restart(devname)
nixio.syslog("debug", "wifi_common_restart "..tostring(devname))
wifi_common_reload()
end
function wifi_common_reset(devname)
nixio.syslog("debug", "wifi_common_reset called!")
local curpath = "/etc/wireless/"
if devname then
curpath = curpath..devname.."/"
end
local defpath = "/rom"..defpath
if mtkwifi.exists(defpath) then
os.execute("rm -rf "..curpath)
os.execute("cp -rf "..defpath.." "..curpath)
wifi_common_reload()
else
nixio.syslog("debug", defpath.." missing, unable to reset!")
end
end
function wifi_common_status(devname)
nixio.syslog("debug", "wifi_common_status "..tostring(devname))
print(mtkwifi.read_pipe("iwconfig"))
print(mtkwifi.read_pipe("ifconfig -a"))
end
function wifi_common_detect(devname)
nixio.syslog("debug", "wifi_common_detect "..tostring(devname))
local devs = mtkwifi.getdevs()
for _,dev in ipairs(devs) do
print("config wifi-device "..dev.devname..
"\n\toption type "..dev.devname..
"\n\toption vendor ralink"..
"\n\toption channel "..dev.Channel)
for _,vif in ipairs(dev.vifs) do
print("\nconfig wifi-iface"..
"\n\toption device"..dev.devname..
"\n\toption ifname"..vif.vifname..
"\n\toption network lan"..
"\n\toption mode ap")
end
end
end
for _,f in ipairs(string.split(mtkwifi.read_pipe("find /lib/wifi/ -name \"*.lua\" 2>/dev/null"), "\n")) do
dofile(f)
end
function wifi(cmd, devname)
local mtkwifi = require("mtkwifi")
local devs, l1parser = mtkwifi.__get_l1dat()
if not devs or not l1parser then
return wifi_orig(cmd, devname)
end
if devname then
local dev = devs.devname_ridx[devname]
assert(mtkwifi.exists(dev.init_script))
local compatname = dev.init_compatible
assert(compatname)
if _G[compatname.."_"..cmd] then
nixio.syslog("info", "call "..compatname.."_"..cmd.."("..devname..")")
_G[compatname.."_"..cmd](devname)
end
return
end
-- if devname not not specified
for devname, dev in pairs(devs.devname_ridx) do
local compatname = dev.init_compatible
nixio.syslog("info", "call "..compatname.."_"..cmd.."("..devname..")")
_G[compatname.."_"..cmd](devname)
end
end
function wifi_orig(cmd,devname)
local relname = nil
if devname then
relname = string.split(devname,".")[1]
end
if relname then
if _G[relname.."_"..cmd] then
nixio.syslog("info", "call "..relname.."_"..cmd.."("..devname..")")
_G[relname.."_"..cmd](devname)
end
else
local devinfo = mtkwifi.search_dev_and_profile()
local done = {}
for __devname in pairs(devinfo) do
local __relname = string.split(__devname,".")[1]
repeat
-- common case
if done[__relname] then break else done[__relname] = true end
if _G[__relname.."_"..cmd] then
nixio.syslog("info", "call "..__relname.."_"..cmd.."("..__devname..")")
_G[__relname.."_"..cmd](__devname)
break
end
-- try shell
local dev_shell = "/lib/wifi/"..__relname..".sh"
if mtkwifi.exists(dev_shell) then
local cmd = "source "..dev_shell.."; "..__relname.."_"..cmd.." > /dev/null"
nixio.syslog("info", cmd)
if os.execute(cmd) ~= 0 then
nixio.syslog("err", cmd)
end
break
end
-- fall back on common api
nixio.syslog("info", "no scripts for "..__relname.." found, fall back on common api!")
_G["wifi_common_"..cmd](__devname)
until true
end
end
end
cmd = arg[1]
dev = arg[2]
if cmd == "up"
or cmd == "down"
or cmd == "status"
or cmd == "detect"
or cmd == "reload"
or cmd == "restart"
or cmd == "reset" then
wifi(cmd, dev)
elseif cmd == "reload_legacy" then
nixio.syslog("info", "legacy command "..cmd)
wifi("up", dev)
else
usage()
end
@@ -1,956 +0,0 @@
#!/usr/bin/env lua
--[[
* A lua library to manipulate mtk's wifi driver. used in luci-app-mtk.
*
* Hua Shao <nossiac@163.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
]]
local mtkwifi = {}
local _, nixio = pcall(require, "nixio")
function mtkwifi.debug(...)
local ff = io.open("/tmp/mtkwifi.dbg.log", "a")
local vars = {...}
for _, v in pairs(vars) do
ff:write(v.." ")
end
ff:write("\n")
ff:close()
end
if not nixio then
nixio.syslog = mtkwifi.debug
end
function string:split(sep)
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
self:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end
function mtkwifi.__trim(s)
if s then return (s:gsub("^%s*(.-)%s*$", "%1")) end
end
function mtkwifi.__handleSpecialChars(s)
s = s:gsub("\\", "\\\\")
s = s:gsub("\"", "\\\"")
s = mtkwifi.__trim(s)
return s
end
-- if order function given, sort by it by passing the table and keys a, b,
-- otherwise just sort the keys
function mtkwifi.__spairs(t, order)
-- collect the keys
local keys = {}
for k in pairs(t) do keys[#keys+1] = k end
table.sort(keys, order)
-- return the iterator function
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
function mtkwifi.__lines(str)
local t = {}
local function helper(line) table.insert(t, line) return "" end
helper((str:gsub("(.-)\r?\n", helper)))
return t
end
function mtkwifi.__get_l1dat()
if not pcall(require, "l1dat_parser") then
return
end
local parser = require("l1dat_parser")
local l1dat = parser.load_l1_profile(parser.L1_DAT_PATH)
return l1dat, parser
end
function mtkwifi.sleep(s)
local ntime = os.clock() + s
repeat until os.clock() > ntime
end
function mtkwifi.deepcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[mtkwifi.deepcopy(orig_key)] = mtkwifi.deepcopy(orig_value)
end
setmetatable(copy, mtkwifi.deepcopy(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end
function mtkwifi.read_pipe(pipe)
local fp = io.popen(pipe)
local txt = fp:read("*a")
fp:close()
return txt
end
function mtkwifi.load_profile(path, raw)
local cfgs = {}
local content
if path then
local fd = io.open(path, "r")
if not fd then return end
content = fd:read("*all")
fd:close()
elseif raw then
content = raw
else
return
end
-- convert profile into lua table
for _,line in ipairs(mtkwifi.__lines(content)) do
line = mtkwifi.__trim(line)
if string.byte(line) ~= string.byte("#") then
local i = string.find(line, "=")
if i then
local k,v
k = string.sub(line, 1, i-1)
v = string.sub(line, i+1)
if cfgs[mtkwifi.__trim(k)] then
mtkwifi.debug("warning", "skip repeated key"..line)
end
cfgs[mtkwifi.__trim(k)] = mtkwifi.__trim(v) or ""
else
mtkwifi.debug("warning", "skip line without '=' "..line)
end
else
mtkwifi.debug("warning", "skip comment line "..line)
end
end
return cfgs
end
function mtkwifi.__profile_bak_path(profile)
local bak = "/tmp/mtk/wifi/"..string.match(profile, "([^/]+\.dat)")..".last"
os.execute("mkdir -p /tmp/mtk/wifi")
return bak
end
function mtkwifi.save_profile(cfgs, path)
if not cfgs then
mtkwifi.debug("configuration was empty, nothing saved")
return
end
local fd = io.open(path, "w")
table.sort(cfgs, function(a,b) return a<b end)
if not fd then return end
fd:write("# Generated by mtkwifi.lua\n")
fd:write("Default\n")
for k,v in mtkwifi.__spairs(cfgs, function(a,b) return string.upper(a) < string.upper(b) end) do
fd:write(k.."="..v.."\n")
end
fd:close()
if pcall(require, "mtknvram") then
local nvram = require("mtknvram")
local l1dat, l1 = mtkwifi.__get_l1dat()
local zone = l1 and l1.l1_path_to_zone(path)
if not l1dat then
mtkwifi.debug("save_profile: no l1dat", path)
nvram.nvram_save_profile(path)
else
if zone then
mtkwifi.debug("save_profile:", path, zone)
nvram.nvram_save_profile(path, zone)
else
mtkwifi.debug("save_profile:", path)
nvram.nvram_save_profile(path)
end
end
end
end
-- if path2 not give, we use path1's backup.
function mtkwifi.diff_profile(path1, path2)
assert(path1)
if not path2 then
path2 = mtkwifi.__profile_bak_path(path1)
if not mtkwifi.exists(path2) then
return {}
end
end
assert(path2)
local diff = {}
local cfg1 = mtkwifi.load_profile(path1) or {}
local cfg2 = mtkwifi.load_profile(path2) or {}
for k,v in pairs(cfg1) do
if cfg2[k] ~= cfg1[k] then
diff[k] = {cfg1[k] or "", cfg2[k] or ""}
end
end
for k,v in pairs(cfg2) do
if cfg2[k] ~= cfg1[k] then
diff[k] = {cfg1[k] or "", cfg2[k] or ""}
end
end
return diff
end
-- Mode 12 and 13 are only available for STAs.
local WirelessModeList = {
[0] = "B/G mixed",
[1] = "B only",
[2] = "A only",
-- [3] = "A/B/G mixed",
[4] = "G only",
-- [5] = "A/B/G/GN/AN mixed",
[6] = "N in 2.4G only",
[7] = "G/GN", -- i.e., no CCK mode
[8] = "A/N in 5 band",
[9] = "B/G/GN mode",
-- [10] = "A/AN/G/GN mode", --not support B mode
[11] = "only N in 5G band",
-- [12] = "B/G/GN/A/AN/AC mixed",
-- [13] = "G/GN/A/AN/AC mixed", -- no B mode
[14] = "A/AC/AN mixed",
[15] = "AC/AN mixed", --but no A mode
[16] = "AX/B/G/GN mode",
[17] = "AX/AC/AN mixed",
}
local DevicePropertyMap = {
-- 2.4G
{device="MT7603", band={"0", "1", "4", "6", "7", "9"}},
{device="MT7620", band={"0", "1", "4", "6", "7", "9"}},
{device="MT7622", band={"0", "1", "4", "9"}},
{device="MT7628", band={"0", "1", "4", "6", "7", "9"}},
-- 5G
{device="MT7610", band={"2", "8", "11", "14", "15"}},
{device="MT7612", band={"2", "8", "11", "14", "15"}},
{device="MT7662", band={"2", "8", "11", "14", "15"}},
-- Mix
{device="MT7615", band={"0", "1", "4", "9", "2", "8", "14", "15","16","17"}}
}
mtkwifi.CountryRegionList_5G_All = {
{region=0, text="0: Ch36~64, Ch149~165"},
{region=1, text="1: Ch36~64, Ch100~140"},
{region=2, text="2: Ch36~64"},
{region=3, text="3: Ch52~64, Ch149~161"},
{region=4, text="4: Ch149~165"},
{region=5, text="5: Ch149~161"},
{region=6, text="6: Ch36~48"},
{region=7, text="7: Ch36~64, Ch100~140, Ch149~165"},
{region=8, text="8: Ch52~64"},
{region=9, text="9: Ch36~64, Ch100~116, Ch132~140, Ch149~165"},
{region=10, text="10: Ch36~48, Ch149~165"},
{region=11, text="11: Ch36~64, Ch100~120, Ch149~161"},
{region=12, text="12: Ch36~64, Ch100~144"},
{region=13, text="13: Ch36~64, Ch100~144, Ch149~165"},
{region=14, text="14: Ch36~64, Ch100~116, Ch132~144, Ch149~165"},
{region=15, text="15: Ch149~173"},
{region=16, text="16: Ch52~64, Ch149~165"},
{region=17, text="17: Ch36~48, Ch149~161"},
{region=18, text="18: Ch36~64, Ch100~116, Ch132~140"},
{region=19, text="19: Ch56~64, Ch100~140, Ch149~161"},
{region=20, text="20: Ch36~64, Ch100~124, Ch149~161"},
{region=21, text="21: Ch36~64, Ch100~140, Ch149~161"},
{region=22, text="22: Ch100~140"},
{region=30, text="30: Ch36~48, Ch52~64, Ch100~140, Ch149~165"},
{region=31, text="31: Ch52~64, Ch100~140, Ch149~165"},
{region=32, text="32: Ch36~48, Ch52~64, Ch100~140, Ch149~161"},
{region=33, text="33: Ch36~48, Ch52~64, Ch100~140"},
{region=34, text="34: Ch36~48, Ch52~64, Ch149~165"},
{region=35, text="35: Ch36~48, Ch52~64"},
{region=36, text="36: Ch36~48, Ch100~140, Ch149~165"},
{region=37, text="37: Ch36~48, Ch52~64, Ch149~165, Ch173"},
}
mtkwifi.CountryRegionList_2G_All = {
{region=0, text="0: Ch1~11"},
{region=1, text="1: Ch1~13"},
{region=2, text="2: Ch10~11"},
{region=3, text="3: Ch10~13"},
{region=4, text="4: Ch14"},
{region=5, text="5: Ch1~14"},
{region=6, text="6: Ch3~9"},
{region=7, text="7: Ch5~13"},
{region=31, text="31: Ch1~11, Ch12~14"},
{region=32, text="32: Ch1~11, Ch12~13"},
{region=33, text="33: Ch1~14"},
}
mtkwifi.ChannelList_5G_All = {
{channel=0, text="Channel 0 (Auto )", region={}},
{channel= 36, text="Channel 36 (5.180 GHz)", region={[0]=1, [1]=1, [2]=1, [6]=1, [7]=1, [9]=1, [10]=1, [11]=1, [12]=1, [13]=1, [14]=1, [17]=1, [18]=1, [20]=1, [21]=1, [30]=1, [32]=1, [33]=1, [34]=1, [35]=1, [36]=1, [37]=1}},
{channel= 40, text="Channel 40 (5.200 GHz)", region={[0]=1, [1]=1, [2]=1, [6]=1, [7]=1, [9]=1, [10]=1, [11]=1, [12]=1, [13]=1, [14]=1, [17]=1, [18]=1, [20]=1, [21]=1, [30]=1, [32]=1, [33]=1, [34]=1, [35]=1, [36]=1, [37]=1}},
{channel= 44, text="Channel 44 (5.220 GHz)", region={[0]=1, [1]=1, [2]=1, [6]=1, [7]=1, [9]=1, [10]=1, [11]=1, [12]=1, [13]=1, [14]=1, [17]=1, [18]=1, [20]=1, [21]=1, [30]=1, [32]=1, [33]=1, [34]=1, [35]=1, [36]=1, [37]=1}},
{channel= 48, text="Channel 48 (5.240 GHz)", region={[0]=1, [1]=1, [2]=1, [6]=1, [7]=1, [9]=1, [10]=1, [11]=1, [12]=1, [13]=1, [14]=1, [17]=1, [18]=1, [20]=1, [21]=1, [30]=1, [32]=1, [33]=1, [34]=1, [35]=1, [36]=1, [37]=1}},
{channel= 52, text="Channel 52 (5.260 GHz)", region={[0]=1, [1]=1, [2]=1, [3]=1, [7]=1, [8]=1, [9]=1, [11]=1, [12]=1, [13]=1, [14]=1, [16]=1, [18]=1, [20]=1, [21]=1, [30]=1, [31]=1, [32]=1, [33]=1, [34]=1, [35]=1, [37]=1}},
{channel= 56, text="Channel 56 (5.280 GHz)", region={[0]=1, [1]=1, [2]=1, [3]=1, [7]=1, [8]=1, [9]=1, [11]=1, [12]=1, [13]=1, [14]=1, [16]=1, [18]=1, [19]=1, [20]=1, [21]=1, [30]=1, [31]=1, [32]=1, [33]=1, [34]=1, [35]=1, [37]=1}},
{channel= 60, text="Channel 60 (5.300 GHz)", region={[0]=1, [1]=1, [2]=1, [3]=1, [7]=1, [8]=1, [9]=1, [11]=1, [12]=1, [13]=1, [14]=1, [16]=1, [18]=1, [19]=1, [20]=1, [21]=1, [30]=1, [31]=1, [32]=1, [33]=1, [34]=1, [35]=1, [37]=1}},
{channel= 64, text="Channel 64 (5.320 GHz)", region={[0]=1, [1]=1, [2]=1, [3]=1, [7]=1, [8]=1, [9]=1, [11]=1, [12]=1, [13]=1, [14]=1, [16]=1, [18]=1, [19]=1, [20]=1, [21]=1, [30]=1, [31]=1, [32]=1, [33]=1, [34]=1, [35]=1, [37]=1}},
{channel=100, text="Channel 100 (5.500 GHz)", region={[1]=1, [7]=1, [9]=1, [11]=1, [12]=1, [13]=1, [14]=1, [18]=1, [19]=1, [20]=1, [21]=1, [22]=1, [30]=1, [31]=1, [32]=1, [33]=1, [36]=1}},
{channel=104, text="Channel 104 (5.520 GHz)", region={[1]=1, [7]=1, [9]=1, [11]=1, [12]=1, [13]=1, [14]=1, [18]=1, [19]=1, [20]=1, [21]=1, [22]=1, [30]=1, [31]=1, [32]=1, [33]=1, [36]=1}},
{channel=108, text="Channel 108 (5.540 GHz)", region={[1]=1, [7]=1, [9]=1, [11]=1, [12]=1, [13]=1, [14]=1, [18]=1, [19]=1, [20]=1, [21]=1, [22]=1, [30]=1, [31]=1, [32]=1, [33]=1, [36]=1}},
{channel=112, text="Channel 112 (5.560 GHz)", region={[1]=1, [7]=1, [9]=1, [11]=1, [12]=1, [13]=1, [14]=1, [18]=1, [19]=1, [20]=1, [21]=1, [22]=1, [30]=1, [31]=1, [32]=1, [33]=1, [36]=1}},
{channel=116, text="Channel 116 (5.580 GHz)", region={[1]=1, [7]=1, [9]=1, [11]=1, [12]=1, [13]=1, [14]=1, [18]=1, [19]=1, [20]=1, [21]=1, [22]=1, [30]=1, [31]=1, [32]=1, [33]=1, [36]=1}},
{channel=120, text="Channel 120 (5.600 GHz)", region={[1]=1, [7]=1, [11]=1, [12]=1, [13]=1, [19]=1, [20]=1, [21]=1, [22]=1, [30]=1, [31]=1, [32]=1, [33]=1, [36]=1}},
{channel=124, text="Channel 124 (5.620 GHz)", region={[1]=1, [7]=1, [12]=1, [13]=1, [19]=1, [20]=1, [21]=1, [22]=1, [30]=1, [31]=1, [32]=1, [33]=1, [36]=1}},
{channel=128, text="Channel 128 (5.640 GHz)", region={[1]=1, [7]=1, [12]=1, [13]=1, [19]=1, [21]=1, [22]=1, [30]=1, [31]=1, [32]=1, [33]=1, [36]=1}},
{channel=132, text="Channel 132 (5.660 GHz)", region={[1]=1, [7]=1, [9]=1, [12]=1, [13]=1, [14]=1, [18]=1, [19]=1, [21]=1, [22]=1, [30]=1, [31]=1, [32]=1, [33]=1, [36]=1}},
{channel=136, text="Channel 136 (5.680 GHz)", region={[1]=1, [7]=1, [9]=1, [12]=1, [13]=1, [14]=1, [18]=1, [19]=1, [21]=1, [22]=1, [30]=1, [31]=1, [32]=1, [33]=1, [36]=1}},
{channel=140, text="Channel 140 (5.700 GHz)", region={[1]=1, [7]=1, [9]=1, [12]=1, [13]=1, [14]=1, [18]=1, [19]=1, [21]=1, [22]=1, [30]=1, [31]=1, [32]=1, [33]=1, [36]=1}},
{channel=144, text="Channel 144 (5.720 GHz)", region={[12]=1, [13]=1, [14]=1}},
{channel=149, text="Channel 149 (5.745 GHz)", region={[0]=1, [3]=1, [4]=1, [5]=1, [7]=1, [9]=1, [10]=1, [11]=1, [13]=1, [14]=1, [15]=1, [16]=1, [17]=1, [19]=1, [20]=1, [21]=1, [30]=1, [31]=1, [32]=1, [34]=1, [36]=1, [37]=1}},
{channel=153, text="Channel 153 (5.765 GHz)", region={[0]=1, [3]=1, [4]=1, [5]=1, [7]=1, [9]=1, [10]=1, [11]=1, [13]=1, [14]=1, [15]=1, [16]=1, [17]=1, [19]=1, [20]=1, [21]=1, [30]=1, [31]=1, [32]=1, [34]=1, [36]=1, [37]=1}},
{channel=157, text="Channel 157 (5.785 GHz)", region={[0]=1, [3]=1, [4]=1, [5]=1, [7]=1, [9]=1, [10]=1, [11]=1, [13]=1, [14]=1, [15]=1, [16]=1, [17]=1, [19]=1, [20]=1, [21]=1, [30]=1, [31]=1, [32]=1, [34]=1, [36]=1, [37]=1}},
{channel=161, text="Channel 161 (5.805 GHz)", region={[0]=1, [3]=1, [4]=1, [5]=1, [7]=1, [9]=1, [10]=1, [11]=1, [13]=1, [14]=1, [15]=1, [16]=1, [17]=1, [19]=1, [20]=1, [21]=1, [30]=1, [31]=1, [32]=1, [34]=1, [36]=1, [37]=1}},
{channel=165, text="Channel 165 (5.825 GHz)", region={[0]=1, [4]=1, [7]=1, [9]=1, [10]=1, [13]=1, [14]=1, [15]=1, [16]=1, [30]=1, [31]=1, [34]=1, [36]=1, [37]=1}},
{channel=169, text="Channel 169 (5.845 GHz)", region={[15]=1}},
{channel=173, text="Channel 173 (5.865 GHz)", region={[15]=1, [37]=1}},
}
mtkwifi.ChannelList_2G_All = {
{channel=0, text="Channel 0 (Auto )", region={}},
{channel= 1, text="Channel 1 (2412 GHz)", region={[0]=1, [1]=1, [5]=1, [31]=1, [32]=1, [33]=1}},
{channel= 2, text="Channel 2 (2417 GHz)", region={[0]=1, [1]=1, [5]=1, [31]=1, [32]=1, [33]=1}},
{channel= 3, text="Channel 3 (2422 GHz)", region={[0]=1, [1]=1, [5]=1, [6]=1, [31]=1, [32]=1, [33]=1}},
{channel= 4, text="Channel 4 (2427 GHz)", region={[0]=1, [1]=1, [5]=1, [6]=1, [31]=1, [32]=1, [33]=1}},
{channel= 5, text="Channel 5 (2432 GHz)", region={[0]=1, [1]=1, [5]=1, [6]=1, [7]=1, [31]=1, [32]=1, [33]=1}},
{channel= 6, text="Channel 6 (2437 GHz)", region={[0]=1, [1]=1, [5]=1, [6]=1, [7]=1, [31]=1, [32]=1, [33]=1}},
{channel= 7, text="Channel 7 (2442 GHz)", region={[0]=1, [1]=1, [5]=1, [6]=1, [7]=1, [31]=1, [32]=1, [33]=1}},
{channel= 8, text="Channel 8 (2447 GHz)", region={[0]=1, [1]=1, [5]=1, [6]=1, [7]=1, [31]=1, [32]=1, [33]=1}},
{channel= 9, text="Channel 9 (2452 GHz)", region={[0]=1, [1]=1, [5]=1, [6]=1, [7]=1, [31]=1, [32]=1, [33]=1}},
{channel=10, text="Channel 10 (2457 GHz)", region={[0]=1, [1]=1, [2]=1, [3]=1, [5]=1, [7]=1, [31]=1, [32]=1, [33]=1}},
{channel=11, text="Channel 11 (2462 GHz)", region={[0]=1, [1]=1, [2]=1, [3]=1, [5]=1, [7]=1, [31]=1, [32]=1, [33]=1}},
{channel=12, text="Channel 12 (2467 GHz)", region={[1]=1, [3]=1, [5]=1, [7]=1, [31]=1, [32]=1, [33]=1}},
{channel=13, text="Channel 13 (2472 GHz)", region={[1]=1, [3]=1, [5]=1, [7]=1, [31]=1, [32]=1, [33]=1}},
{channel=14, text="Channel 14 (2477 GHz)", region={[4]=1, [5]=1, [31]=1, [33]=1}},
}
mtkwifi.ChannelList_5G_2nd_80MHZ_ALL = {
{channel=36, text="Ch36(5.180 GHz) - Ch48(5.240 GHz)", chidx=2},
{channel=52, text="Ch52(5.260 GHz) - Ch64(5.320 GHz)", chidx=6},
{channel=-1, text="Channel between 64 100", chidx=-1},
{channel=100, text="Ch100(5.500 GHz) - Ch112(5.560 GHz)", chidx=10},
{channel=112, text="Ch116(5.580 GHz) - Ch128(5.640 GHz)", chidx=14},
{channel=-1, text="Channel between 128 132", chidx=-1},
{channel=132, text="Ch132(5.660 GHz) - Ch144(5.720 GHz)", chidx=18},
{channel=-1, text="Channel between 144 149", chidx=-1},
{channel=149, text="Ch149(5.745 GHz) - Ch161(5.805 GHz)", chidx=22},
}
local AuthModeList = {
"Disable",
"OPEN",--OPENWEP
"SHARED",--SHAREDWEP
"WEPAUTO",
"WPA2",
"WPA2PSK",
"WPAPSKWPA2PSK",
"WPA1WPA2",
"IEEE8021X",
}
local WpsEnableAuthModeList = {
"Disable",
"OPEN",--OPENWEP
"WPA2PSK",
"WPAPSKWPA2PSK",
}
local ApCliAuthModeList = {
"Disable",
"OPEN",
"SHARED",
"WPAPSK",
"WPA2PSK",
"WPAPSKWPA2PSK",
-- "WPA",
-- "WPA2",
-- "WPAWPA2",
-- "8021X",
}
local WPA_Enc_List = {
"AES",
"TKIP",
"TKIPAES",
}
local WEP_Enc_List = {
"WEP",
}
local dbdc_prefix = {
{"ra", "rax"},
{"rai", "ray"},
{"rae", "raz"},
}
local dbdc_apcli_prefix = {
{"apcli", "apclix"},
{"apclii", "apcliy"},
{"apclie", "apcliz"},
}
function mtkwifi.band(mode)
local i = tonumber(mode)
if i == 0
or i == 1
or i == 4
or i == 6
or i == 7
or i == 9
or i == 16 then
return "2.4G"
else
return "5G"
end
end
function mtkwifi.__cfg2list(str)
-- delimeter == ";"
local i = 1
local list = {}
for k in string.gmatch(str, "([^;]+)") do
list[i] = k
i = i + 1
end
return list
end
function mtkwifi.token_set(str, n, v)
-- n start from 1
-- delimeter == ";"
if not str then return end
local tmp = mtkwifi.__cfg2list(str)
if type(v) ~= type("") and type(v) ~= type(0) then
mtkwifi.debug("err", "invalid value type in token_set, "..type(v))
return
end
if #tmp < tonumber(n) then
for i=#tmp, tonumber(n) do
if not tmp[i] then
tmp[i] = v -- pad holes with v !
end
end
else
tmp[n] = v
end
return table.concat(tmp, ";")
end
function mtkwifi.token_get(str, n, v)
-- n starts from 1
-- v is the backup in case token n is nil
if not str then return v end
local tmp = mtkwifi.__cfg2list(str)
return tmp[tonumber(n)] or v
end
function mtkwifi.search_dev_and_profile_orig()
local dir = io.popen("ls /etc/wireless/")
if not dir then return end
local result = {}
-- case 1: mt76xx.dat (best)
-- case 2: mt76xx.n.dat (multiple card of same dev)
-- case 3: mt76xx.n.nG.dat (case 2 plus dbdc and multi-profile, bloody hell....)
for line in dir:lines() do
-- mtkwifi.debug("debug", "scan "..line)
local tmp = io.popen("find /etc/wireless/"..line.." -type f -name \"*.dat\"")
for datfile in tmp:lines() do
-- mtkwifi.debug("debug", "test "..datfile)
repeat do
-- for case 1
local devname = string.match(datfile, "("..line..").dat")
if devname then
result[devname] = datfile
-- mtkwifi.debug("debug", "yes "..devname.."="..datfile)
break
end
-- for case 2
local devname = string.match(datfile, "("..line.."%.%d)%.dat")
if devname then
result[devname] = datfile
-- mtkwifi.debug("debug", "yes "..devname.."="..datfile)
break
end
-- for case 3
local devname = string.match(datfile, "("..line.."%.%d%.%dG)%.dat")
if devname then
result[devname] = datfile
-- mtkwifi.debug("debug", "yes "..devname.."="..datfile)
break
end
end until true
end
end
for k,v in pairs(result) do
mtkwifi.debug("debug", "search_dev_and_profile_orig: "..k.."="..v)
end
return result
end
function mtkwifi.search_dev_and_profile_l1()
local l1dat = mtkwifi.__get_l1dat()
if not l1dat then return end
local result = {}
local dbdc_2nd_if = ""
for k, dev in ipairs(l1dat) do
dbdc_2nd_if = mtkwifi.token_get(dev.main_ifname, 2, nil)
if dbdc_2nd_if then
result[dev["INDEX"].."."..dev["mainidx"]..".1"] = mtkwifi.token_get(dev.profile_path, 1, nil)
result[dev["INDEX"].."."..dev["mainidx"]..".2"] = mtkwifi.token_get(dev.profile_path, 2, nil)
else
result[dev["INDEX"].."."..dev["mainidx"]] = dev.profile_path
end
end
for k,v in pairs(result) do
mtkwifi.debug("debug", "search_dev_and_profile_l1: "..k.."="..v)
end
return result
end
function mtkwifi.search_dev_and_profile()
return mtkwifi.search_dev_and_profile_l1() or mtkwifi.search_dev_and_profile_orig()
end
function mtkwifi.__setup_vifs(cfgs, devname, mainidx, subidx)
local l1dat, l1 = mtkwifi.__get_l1dat()
local dridx = l1dat and l1.DEV_RINDEX
local prefix
local main_ifname
local vifs = {}
local dev_idx = ""
prefix = l1dat and l1dat[dridx][devname].ext_ifname or dbdc_prefix[mainidx][subidx]
dev_idx = string.match(devname, "(%w+)")
vifs["__prefix"] = prefix
if (cfgs.BssidNum == nil) then
mtkwifi.debug("BssidNum configuration value not found.")
mtkwifi.debug("debug","BssidNum configuration value not found.")
return
end
for j=1,tonumber(cfgs.BssidNum) do
vifs[j] = {}
vifs[j].vifidx = j -- start from 1
dev_idx = string.match(devname, "(%w+)")
main_ifname = l1dat and l1dat[dridx][devname].main_ifname or dbdc_prefix[mainidx][subidx].."0"
mtkwifi.debug("setup_vifs", prefix, dev_idx, mainidx, subidx)
vifs[j].vifname = j == 1 and main_ifname or prefix..(j-1)
if mtkwifi.exists("/sys/class/net/"..vifs[j].vifname) then
local flags = tonumber(mtkwifi.read_pipe("cat /sys/class/net/"..vifs[j].vifname.."/flags 2>/dev/null")) or 0
vifs[j].state = flags%2 == 1 and "up" or "down"
end
vifs[j].__ssid = cfgs["SSID"..j]
vifs[j].__bssid = mtkwifi.read_pipe("cat /sys/class/net/"..prefix..(j-1).."/address 2>/dev/null") or "?"
if dbdc then
vifs[j].__channel = mtkwifi.token_get(cfgs.Channel, j, 0)
vifs[j].__wirelessmode = mtkwifi.token_get(cfgs.WirelessMode, j, 0)
end
vifs[j].__authmode = mtkwifi.token_get(cfgs.AuthMode, j, "OPEN")
vifs[j].__encrypttype = mtkwifi.token_get(cfgs.EncrypType, j, "NONE")
vifs[j].__hidessid = mtkwifi.token_get(cfgs.HideSSID, j, 0)
vifs[j].__noforwarding = mtkwifi.token_get(cfgs.NoForwarding, j, 0)
vifs[j].__wmmcapable = mtkwifi.token_get(cfgs.WmmCapable, j, 0)
vifs[j].__txrate = mtkwifi.token_get(cfgs.TxRate, j, 0)
vifs[j].__ieee8021x = mtkwifi.token_get(cfgs.IEEE8021X, j, 0)
vifs[j].__preauth = mtkwifi.token_get(cfgs.PreAuth, j, 0)
vifs[j].__rekeymethod = mtkwifi.token_get(cfgs.RekeyMethod, j, 0)
vifs[j].__rekeyinterval = mtkwifi.token_get(cfgs.RekeyInterval, j, 0)
vifs[j].__pmkcacheperiod = mtkwifi.token_get(cfgs.PMKCachePeriod, j, 0)
vifs[j].__ht_extcha = mtkwifi.token_get(cfgs.HT_EXTCHA, j, 0)
vifs[j].__radius_server = mtkwifi.token_get(cfgs.RADIUS_Server, j, 0)
vifs[j].__radius_port = mtkwifi.token_get(cfgs.RADIUS_Port, j, 0)
vifs[j].__wepkey_id = mtkwifi.token_get(cfgs.DefaultKeyID, j, 0)
vifs[j].__wscconfmode = mtkwifi.token_get(cfgs.WscConfMode, j, 0)
vifs[j].__wepkeys = {
cfgs["Key"..j.."Str1"],
cfgs["Key"..j.."Str2"],
cfgs["Key"..j.."Str3"],
cfgs["Key"..j.."Str4"],
}
vifs[j].__wpapsk = cfgs["WPAPSK"..j]
-- VoW
vifs[j].__atc_tp = mtkwifi.token_get(cfgs.VOW_Rate_Ctrl_En, j, 0)
vifs[j].__atc_min_tp = mtkwifi.token_get(cfgs.VOW_Group_Min_Rate, j, "")
vifs[j].__atc_max_tp = mtkwifi.token_get(cfgs.VOW_Group_Max_Rate, j, "")
vifs[j].__atc_at = mtkwifi.token_get(cfgs.VOW_Airtime_Ctrl_En, j, 0)
vifs[j].__atc_min_at = mtkwifi.token_get(cfgs.VOW_Group_Min_Ratio, j, "")
vifs[j].__atc_max_at = mtkwifi.token_get(cfgs.VOW_Group_Max_Ratio, j, "")
-- TODO index by vifname
vifs[vifs[j].vifname] = vifs[j]
end
return vifs
end
function mtkwifi.__setup_apcli(cfgs, devname, mainidx, subidx)
local l1dat, l1 = mtkwifi.__get_l1dat()
local dridx = l1dat and l1.DEV_RINDEX
local apcli = {}
local dev_idx = string.match(devname, "(%w+)")
local apcli_prefix = l1dat and l1dat[dridx][devname].apcli_ifname or
dbdc_apcli_prefix[mainidx][subidx]
local apcli_name = apcli_prefix.."0"
if mtkwifi.exists("/sys/class/net/"..apcli_name) then
apcli.vifname = apcli_name
apcli.vifidx = "1"
local iwapcli = mtkwifi.read_pipe("iwconfig "..apcli_name.." | grep ESSID 2>/dev/null")
local _,_,ssid = string.find(iwapcli, "ESSID:\"(.*)\"")
local flags = tonumber(mtkwifi.read_pipe("cat /sys/class/net/"..apcli_name.."/flags 2>/dev/null")) or 0
apcli.state = flags%2 == 1 and "up" or "down"
if not ssid or ssid == "" then
apcli.status = "未连接"
else
apcli.ssid = ssid
apcli.status = "已连接"
end
apcli.devname = apcli_name
apcli.bssid = mtkwifi.read_pipe("cat /sys/class/net/"..apcli_name.."/address 2>/dev/null") or "?"
local flags = tonumber(mtkwifi.read_pipe("cat /sys/class/net/"..apcli_name.."/flags 2>/dev/null")) or 0
apcli.ifstatus = flags%2 == 1 and "up" or ""
return apcli
else
return
end
end
function mtkwifi.get_all_devs()
local devs = {}
local i = 1 -- dev idx
local profiles = mtkwifi.search_dev_and_profile()
local wpa_support = 0
local wapi_support = 0
for devname,profile in pairs(profiles) do
mtkwifi.debug("debug", "checking "..profile)
local fd = io.open(profile,"r")
if not fd then
mtkwifi.debug("debug", "cannot find "..profile)
else
fd:close()
mtkwifi.debug("debug", "load "..profile)
mtkwifi.debug("loading profile"..profile)
local cfgs = mtkwifi.load_profile(profile)
if not cfgs then
mtkwifi.debug("error loading profile"..profile)
mtkwifi.debug("err", "error loading "..profile)
return
end
devs[i] = {}
devs[i].vifs = {}
devs[i].apcli = {}
devs[i].devname = devname
devs[i].profile = profile
local tmp = ""
tmp = string.split(devname, ".")
devs[i].maindev = tmp[1]
devs[i].mainidx = tonumber(tmp[2]) or 1
devs[i].subdev = devname
devs[i].subidx = string.match(tmp[3] or "", "(%d+)")=="2" and 2 or 1
devs[i].devband = tonumber(tmp[3])
if devs[i].devband then
devs[i].multiprofile = true
devs[i].dbdc = true
end
devs[i].version = mtkwifi.read_pipe("cat /etc/wireless/"..devs[i].maindev.."/version 2>/dev/null") or "unknown"
devs[i].ApCliEnable = cfgs.ApCliEnable
devs[i].WirelessMode = cfgs.WirelessMode
devs[i].WirelessModeList = {}
for key, value in pairs(DevicePropertyMap) do
local found = string.find(string.upper(devname), string.upper(value.device))
if found then
for k=1,#value.band do
devs[i].WirelessModeList[tonumber(value.band[k])] = WirelessModeList[tonumber(value.band[k])]
end
end
end
devs[i].WscConfMode = cfgs.WscConfMode
devs[i].AuthModeList = AuthModeList
devs[i].WpsEnableAuthModeList = WpsEnableAuthModeList
if wpa_support == 1 then
table.insert(devs[i].AuthModeList,"WPAPSK")
table.insert(devs[i].AuthModeList,"WPA")
end
if wapi_support == 1 then
table.insert(devs[i].AuthModeList,"WAIPSK")
table.insert(devs[i].AuthModeList,"WAICERT")
end
devs[i].ApCliAuthModeList = ApCliAuthModeList
devs[i].WPA_Enc_List = WPA_Enc_List
devs[i].WEP_Enc_List = WEP_Enc_List
devs[i].Channel = tonumber(cfgs.Channel)
devs[i].DBDC_MODE = tonumber(cfgs.DBDC_MODE)
devs[i].band = devs[i].devband or mtkwifi.band(cfgs.WirelessMode)
if cfgs.MUTxRxEnable then
if tonumber(cfgs.ETxBfEnCond)==1
and tonumber(cfgs.MUTxRxEnable)==0
and tonumber(cfgs.ITxBfEn)==0
then devs[i].__mimo = 0
elseif tonumber(cfgs.ETxBfEnCond)==0
and tonumber(cfgs.MUTxRxEnable)==0
and tonumber(cfgs.ITxBfEn)==1
then devs[i].__mimo = 1
elseif tonumber(cfgs.ETxBfEnCond)==1
and tonumber(cfgs.MUTxRxEnable)==0
and tonumber(cfgs.ITxBfEn)==1
then devs[i].__mimo = 2
elseif tonumber(cfgs.ETxBfEnCond)==1
and tonumber(cfgs.MUTxRxEnable)>0
and tonumber(cfgs.ITxBfEn)==0
then devs[i].__mimo = 3
elseif tonumber(cfgs.ETxBfEnCond)==1
and tonumber(cfgs.MUTxRxEnable)>0
and tonumber(cfgs.ITxBfEn)==1
then devs[i].__mimo = 4
else devs[i].__mimo = 5
end
end
if cfgs.HT_BW == "0" or not cfgs.HT_BW then
devs[i].__bw = "20"
elseif cfgs.HT_BW == "1" and cfgs.VHT_BW == "0" or not cfgs.VHT_BW then
if cfgs.HT_BSSCoexistence == "0" or not cfgs.HT_BSSCoexistence then
devs[i].__bw = "40"
else
devs[i].__bw = "60" -- 20/40 coexist
end
elseif cfgs.HT_BW == "1" and cfgs.VHT_BW == "1" then
devs[i].__bw = "80"
elseif cfgs.HT_BW == "1" and cfgs.VHT_BW == "2" then
devs[i].__bw = "160"
elseif cfgs.HT_BW == "1" and cfgs.VHT_BW == "3" then
devs[i].__bw = "161"
end
devs[i].vifs = mtkwifi.__setup_vifs(cfgs, devname, devs[i].mainidx, devs[i].subidx)
devs[i].apcli = mtkwifi.__setup_apcli(cfgs, devname, devs[i].mainidx, devs[i].subidx)
-- Setup reverse indices by devname
devs[devname] = devs[i]
if devs[i].apcli then
devs[i][devs[i].apcli.devname] = devs[i].apcli
end
i = i + 1
end
end
return devs
end
function mtkwifi.exists(path)
local fp = io.open(path, "rb")
if fp then fp:close() end
return fp ~= nil
end
function mtkwifi.parse_mac(str)
local macs = {}
local pat = "^[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]$"
local function ismac(str)
if str:match(pat) then return str end
end
if not str then return macs end
local t = str:split("\n")
for _,v in pairs(t) do
local mac = ismac(mtkwifi.__trim(v))
if mac then
table.insert(macs, mac)
end
end
return macs
-- body
end
function mtkwifi.scan_ap(vifname)
os.execute("ifconfig "..vifname.." down")
os.execute("ifconfig "..vifname.." up")
os.execute("iwpriv "..vifname.." set SiteSurvey=0")
os.execute("sleep 4") -- depends on your env
local scan_result = mtkwifi.read_pipe("iwpriv "..vifname.." get_site_survey 2>/dev/null")
local aplist = {}
local xx = {}
for i, line in ipairs(mtkwifi.__lines(scan_result)) do
if #line>40 and string.match(line, " BSSID ") then
xx.Ch = {string.find(line, "Ch "),3}
xx.SSID = {string.find(line, "SSID "),32}
xx.BSSID = {string.find(line, "BSSID "),17}
xx.Security = {string.find(line, "Security "),22}
xx.Signal = {string.find(line, "Sig%a%al"),4}
xx.Mode = {string.find(line, "W-Mode"),5}
xx.ExtCh = {string.find(line, "ExtCH"),6}
xx.NT = {string.find(line, "NT"),2}
end
local tmp = {}
if #line>40 and not string.match(line, " BSSID ") then
tmp = {}
tmp.channel = mtkwifi.__trim(string.sub(line, xx.Ch[1], xx.Ch[1]+xx.Ch[2]))
tmp.ssid = mtkwifi.__trim(string.sub(line, xx.SSID[1], xx.SSID[1]+xx.SSID[2]))
tmp.bssid = string.upper(mtkwifi.__trim(string.sub(line, xx.BSSID[1], xx.BSSID[1]+xx.BSSID[2])))
tmp.security = mtkwifi.__trim(string.sub(line, xx.Security[1], xx.Security[1]+xx.Security[2]))
tmp.authmode = mtkwifi.__trim(string.split(tmp.security, "/")[1])
tmp.encrypttype = mtkwifi.__trim(string.split(tmp.security, "/")[2] or "NONE")
tmp.rssi = mtkwifi.__trim(string.sub(line, xx.Signal[1], xx.Signal[1]+xx.Signal[2]))
tmp.extch = mtkwifi.__trim(string.sub(line, xx.ExtCh[1], xx.ExtCh[1]+xx.ExtCh[2]))
tmp.mode = mtkwifi.__trim(string.sub(line, xx.Mode[1], xx.Mode[1]+xx.Mode[2]))
tmp.nt = mtkwifi.__trim(string.sub(line, xx.NT[1], xx.NT[1]+xx.NT[2]))
table.insert(aplist, tmp)
end
end
return aplist
end
function mtkwifi.__any_wsc_enabled(wsc_conf_mode)
if (wsc_conf_mode == "") then
return 0;
end
if (wsc_conf_mode == "7") then
return 1;
end
if (wsc_conf_mode == "4") then
return 1;
end
if (wsc_conf_mode == "2") then
return 1;
end
if (wsc_conf_mode == "1") then
return 1;
end
return 0;
end
function mtkwifi.__restart_if_wps(devname, ifname, cfgs)
local devs = mtkwifi.get_all_devs()
local ssid_index = devs[devname]["vifs"][ifname].vifidx
local wsc_conf_mode = ""
wsc_conf_mode=mtkwifi.token_get(cfgs["WscConfMode"], ssid_index, "")
os.execute("iwpriv "..ifname.." set WscConfMode=0")
mtkwifi.debug("iwpriv "..ifname.." set WscConfMode=0")
os.execute("route delete 239.255.255.250")
mtkwifi.debug("route delete 239.255.255.250")
if(mtkwifi.__any_wsc_enabled(wsc_conf_mode)) then
os.execute("iwpriv "..ifname.." set WscConfMode=7")
mtkwifi.debug("iwpriv "..ifname.." set WscConfMode=7")
os.execute("route add -host 239.255.255.250 dev br0")
mtkwifi.debug("route add -host 239.255.255.250 dev br0")
end
-- execute wps_action.lua file to send signal for current interface
os.execute("lua wps_action.lua "..ifname)
mtkwifi.debug("lua wps_action.lua "..ifname)
return cfgs
end
function mtkwifi.restart_8021x(devname, devices)
local l1dat, l1 = mtkwifi.__get_l1dat()
local dridx = l1dat and l1.DEV_RINDEX
local devs = devices or mtkwifi.get_all_devs()
local dev = devs[devname]
local main_ifname = l1dat and l1dat[dridx][devname].main_ifname or dbdc_prefix[mainidx][subidx].."0"
local prefix = l1dat and l1dat[dridx][devname].ext_ifname or dbdc_prefix[mainidx][subidx]
local ps_cmd = "ps | grep -v grep | grep rt2860apd | grep "..main_ifname.." | awk '{print $1}'"
local pid_cmd = "cat /var/run/rt2860apd_"..devs[devname].vifs[1].vifname..".pid"
local apd_pid = mtkwifi.read_pipe(pid_cmd) or mtkwifi.read_pipe(ps_cmd)
if tonumber(apd_pid) then
os.execute("kill "..apd_pid)
end
local cfgs = mtkwifi.load_profile(devs[devname].profile)
local auth_mode = cfgs['AuthMode']
local ieee8021x = cfgs['IEEE8021X']
local pat_auth_mode = {"WPA$", "WPA;", "WPA2$", "WPA2;", "WPA1WPA2$", "WPA1WPA2;"}
local pat_ieee8021x = {"1$", "1;"}
local apd_en = false
for _, pat in ipairs(pat_auth_mode) do
if string.find(auth_mode, pat) then
apd_en = true
end
end
for _, pat in ipairs(pat_ieee8021x) do
if string.find(ieee8021x, pat) then
apd_en = true
end
end
if not apd_en then
return
end
os.execute("rt2860apd -i "..main_ifname.." -p "..prefix)
end
return mtkwifi