update 2026-07-29 01:22:16

This commit is contained in:
action committed 2026-07-29 01:22:16 +08:00
1 parent be186a4d0b
commit 2e00a5e4eb
1957 files changed
+1523143 -2

No files matched your search

@@ -0,0 +1,327 @@
<%+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%>
@@ -0,0 +1,851 @@
<%+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%>
@@ -0,0 +1,159 @@
<%+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%>
@@ -0,0 +1,590 @@
<%+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%>