Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
update luci-app-mtwifi
Browse files Browse the repository at this point in the history
- auto-add ra0/rai0 to br-lan (option "Add ra0/rai0 to br-lan" in the interface settings).
- reboot fix for 7603 and 7612.
- other minor changes.
  • Loading branch information
Azexios committed Oct 13, 2022
1 parent c6d0efd commit 0d5a5d2
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MTK Wi-Fi driver for OpenWrt 22.03.0
# MTK Wi-Fi driver for OpenWrt 22.03.1
#### For Xiaomi Mi R3P and devices using:
- MT7615+MT7615
- MT7603+MT7615
Expand Down
7 changes: 3 additions & 4 deletions README_RU.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Для сборки прошивки я использую **Ubuntu 22.04 LTS** (на других OS не проверял).
\**Инструкция только о том как заменить драйвер, Вы должны уметь собирать OpenWrt из исходников.*
\**Wi-Fi интерфейсы не добавляются автоматически в lan (для доступа к сети их нужно самостоятельно добавить в lan после установки прошивки), если Вы хотите это изменить на этапе сборки, то прочитайте этот пост на [4pda](https://4pda.to/forum/index.php?s=&showtopic=975687&view=findpost&p=117363861)*

1. Клонировать исходный код и перенести в каталог openwrt (вместо /home/alex/openwrt указать свой путь до openwrt):

Expand All @@ -12,18 +11,18 @@

2. Перейти в каталог openwrt, удалить свой .config - запустить make menuconfig, выбрать своё устройство, перейти в раздел - LuCI > Applications - включить <\*> luci-app-mtwifi, далее в Kernel modules > Wireless Drivers > включить <\*> нужный драйвер/драйвера mtk и зайти в их настройки (выбрать нужные параметры или использовать дефолтные), запомнить настройки/сделать скриншоты и аналогично с Network > Wireless > mt_wifi - MT_WIFI Configuration.

3. Скачать конфиг (для сборки OpenWrt с правильным .vermagiс), ниже пример для OpenWrt 22.03.0 и устройств с CPU mt7621:
3. Скачать конфиг (для сборки OpenWrt с правильным .vermagiс), ниже пример для OpenWrt 22.03.1 и устройств с CPU mt7621:

```bash
wget -O .config https://downloads.openwrt.org/releases/22.03.0/targets/ramips/mt7621/config.buildinfo
wget -O .config https://downloads.openwrt.org/releases/22.03.1/targets/ramips/mt7621/config.buildinfo
make defconfig
```

4. Запустить make menuconfig, выбрать своё устройство, в Kernel modules > Wireless Drivers - включить <\*> нужный драйвер/драйвера mtk и зайти в их настройки - выставить настройки полученные на 2 пункте.
В LuCI > Applications - включить <\*> luci-app-mtwifi.
В Network > Wireless - выставить настройки в mt_wifi из 2 пункта.
В Network > WirelessAPD - отключить wpad-basic-wolfssl и выбрать как модуль \<M> hostapd-common.
Не обязательно - открыть profiles.json (для mt7621 и OpenWrt 22.03.0 - https://downloads.openwrt.org/releases/22.03.0/targets/ramips/mt7621/profiles.json), найти своё устройство и посмотреть какие пакеты (device_packages, кроме Wi-Fi драйверов) нужно дополнительно включить в прошивку.
Не обязательно - открыть profiles.json (для mt7621 и OpenWrt 22.03.1 - https://downloads.openwrt.org/releases/22.03.1/targets/ramips/mt7621/profiles.json), найти своё устройство и посмотреть какие пакеты (device_packages, кроме Wi-Fi драйверов) нужно дополнительно включить в прошивку.

5. Выйти, сохранив настройки и собрать прошивку:

Expand Down
2 changes: 1 addition & 1 deletion package/mt/drivers/mt_wifi/files/mt7603.dat
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ DscpQosMap=
DscpQosMapEnable=
DtimPeriod=1
E2pAccessMode=2
EAPifname=
EAPifname=br-lan
EdcaIdx=0;0;0;0;0;0;0;0;0
EDCCAEnable=1
EfuseBufferMode=0
Expand Down
4 changes: 2 additions & 2 deletions package/mt/drivers/mt_wifi/files/mt7612.dat
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ DisableOLBC=0
DLSCapable=0
DtimPeriod=1
E2pAccessMode=2
EAPifname=
EAPifname=br-lan
EncrypType=AES
FCCParamCh0=
FCCParamCh1=
Expand All @@ -119,7 +119,7 @@ HT_GI=1
HT_HTC=0
HT_LDPC=0
HT_LinkAdapt=0
HT_MCS=33;33;33;33;33;33;33;33;33
HT_MCS=33;33;33;33;33;33;33;33
HT_MpduDensity=5
HT_OpMode=0
HT_PROTECT=1
Expand Down
2 changes: 1 addition & 1 deletion package/mt/drivers/mt_wifi/files/mt7615.2G.dat
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ DscpQosMap=
DscpQosMapEnable=
DtimPeriod=1
E2pAccessMode=2
EAPifname=
EAPifname=br-lan
EdcaIdx=0;0;0;0;0;0;0;0;0
EDCCAEnable=1
EfuseBufferMode=0
Expand Down
2 changes: 1 addition & 1 deletion package/mt/drivers/mt_wifi/files/mt7615.5G.dat
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ DscpQosMap=
DscpQosMapEnable=
DtimPeriod=1
E2pAccessMode=2
EAPifname=
EAPifname=br-lan
EdcaIdx=0;0;0;0;0;0;0;0;0
EDCCAEnable=1
EfuseBufferMode=0
Expand Down
32 changes: 31 additions & 1 deletion package/mt/luci-app-mtwifi/luasrc/controller/mtkwifi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,21 @@ function vif_disable(iface)
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi"))
end

function vif_enable(iface)
function vif_enable(dev, iface)
local devname = dev
local profiles = mtkwifi.search_dev_and_profile()
assert(profiles[devname])

local cfgs = mtkwifi.load_profile(profiles[devname])

if iface == "ra0" or iface == "rai0" then
if cfgs.EAPifname == "br-lan" then
mt_lan = mtkwifi.read_pipe("uci show network.cfg030f15.ports | grep -q "..iface.." && echo 1")
if mt_lan ~= "1\n" then
os.execute("uci add_list network.cfg030f15.ports='"..iface.."'; uci commit network; logger -t MTK-Wi-Fi Add "..iface.." to br-lan; service network reload")
end
end
end
os.execute("ifconfig "..iface.." up")
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi"))
end
Expand Down Expand Up @@ -705,8 +719,24 @@ function vif_cfg(dev, vif)

__security_cfg(cfgs, vif_idx)

if vifname == "ra0" or vifname == "rai0" then
mt_lan = mtkwifi.read_pipe("uci show network.cfg030f15.ports | grep -q "..vifname.." && echo 1")
if http.formvalue("__lan") == "1" then
cfgs.EAPifname = "br-lan"
if mt_lan ~= "1\n" then
os.execute("uci add_list network.cfg030f15.ports='"..vifname.."'; uci commit network; logger -t MTK-Wi-Fi Add "..vifname.." to br-lan; service network reload")
end
else
cfgs.EAPifname = ""
if mt_lan == "1\n" then
os.execute("uci del_list network.cfg030f15.ports='"..vifname.."'; uci commit network; logger -t MTK-Wi-Fi Remove "..vifname.." from br-lan; service network reload")
end
end
end

-- mtkwifi.debug(devname, profile)
mtkwifi.save_profile(cfgs, profile)

if http.formvalue("__apply") then
__mtkwifi_reload(devname)
luci.http.redirect(luci.dispatcher.build_url("admin", "network", "wifi"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
border-collapse:separate;
border-spacing:0px 5px
}
@media screen and (min-device-width: 601px) {
.b2 {
display:none;
}
}
@media screen and (max-device-width: 600px) {
header h3 a,
header .brand {
Expand Down Expand Up @@ -73,6 +78,9 @@
.b1 {
display:none;
}
.a2 {
display:none;
}
}
</style>

Expand Down Expand Up @@ -142,9 +150,14 @@ <h2><a>Wireless Overview</a></h2>
<% if not vif.state then %>
<input class="cbi-button cbi-button-apply" style="width:100px" title="Enable this Wi-Fi network" value="Enable" 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="Disable this Wi-Fi network" value="Disable" type="button" onclick='wifi_reload("<%=luci.dispatcher.build_url("admin", "network", "wifi", "vif_disable", vif.vifname)%>")' />
<span class="a2">
<input class="cbi-button cbi-button-reset" style="width:100px" title="Disable this Wi-Fi network" value="Disable" type="button" onclick='wifi_reload("<%=luci.dispatcher.build_url("admin", "network", "wifi", "vif_disable", vif.vifname)%>")' />
</span>
<span class="b2">
<input class="cbi-button cbi-button-reset" style="width:100px" title="Disable this Wi-Fi network" value="Disable" type="button" onclick="if (confirm('Are you sure?')) location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "vif_disable", vif.vifname)%>'" />
</span>
<% else %>
<input class="cbi-button cbi-button-apply" style="width:100px" title="Enable this Wi-Fi network" value="Enable" type="button" onclick='wifi_reload("<%=luci.dispatcher.build_url("admin", "network", "wifi", "vif_enable", vif.vifname)%>")' />
<input class="cbi-button cbi-button-apply" style="width:100px" title="Enable this Wi-Fi network" value="Enable" type="button" onclick='wifi_reload("<%=luci.dispatcher.build_url("admin", "network", "wifi", "vif_enable", dev.devname, vif.vifname)%>")' />
<% end %>
<input class="cbi-button cbi-button-edit" style="width:100px" title="Edit this Wi-Fi network" value="Config" 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="Delete this Wi-Fi network" value="Remove" type="button" onclick="if (confirm('You are going to delete the interface <%=vif.vifname%>, are you sure?')) location.href='<%=luci.dispatcher.build_url("admin", "network", "wifi", "vif_del", dev.devname, vif.vifname)%>'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
<tr>
<td>Key</td>
<td>
<input value="<%=vif.__wpapsk%>" type="text" name="<%="WPAPSK"..vifidx%>" id="<%="WPAPSK"..vifidx%>" />
<input value="<%=vif.__wpapsk%>" type="text" name="<%="WPAPSK"..vifidx%>" id="<%="WPAPSK"..vifidx%>" /><span class="he1">8~63 symbols</span>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -431,6 +431,17 @@
<% end %> type="checkbox" />
</td>
</tr>
<% if vifname == "ra0" or vifname == "rai0" then %>
<tr>
<td>Add <%=vifname%> to br-lan</td>
<td>
<input name="__lan" value="1"
<% if mtkwifi.token_get(cfgs["EAPifname"], vifidx, 0) == "br-lan" then %>
checked="checked"
<% end %> type="checkbox" />
</td>
</tr>
<% end %>
<!--
<tr>
<td>TX Rate</td>
Expand Down
82 changes: 48 additions & 34 deletions package/mt/luci-app-mtwifi/root/lib/wifi/mt7615.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function mt7615_vifup_save(devname)
local nixio = require("nixio")
local mtkwifi = require("mtkwifi")
local vif_prefix = vif_pre(devname)
nixio.syslog("debug", "mt7615_vifup_save called!")
nixio.syslog("debug", "MTK-Wi-Fi: vifup_save called!")

for _,pre in ipairs(vif_prefix) do
for _,vif in ipairs(string.split(mtkwifi.read_pipe("ls /sys/class/net"), "\n"))
Expand All @@ -58,7 +58,7 @@ function mt7615_ifup_save(devname)
local nixio = require("nixio")
local mtkwifi = require("mtkwifi")
local vif_prefix = vif_pre(devname)
nixio.syslog("debug", "mt7615_ifup_save called!")
nixio.syslog("debug", "MTK-Wi-Fi: ifup_save called!")

for _,pre in ipairs(vif_prefix) do
for _,vif in ipairs(string.split(mtkwifi.read_pipe("ls /sys/class/net"), "\n"))
Expand All @@ -68,21 +68,21 @@ function mt7615_ifup_save(devname)
end
end
end

os.execute("> /tmp/mtk/ifup-save")
for _,ifs in ipairs(string.split(mtkwifi.read_pipe("cat /tmp/mtk/if-save"), "\n")) do
os.execute("ifstatus "..ifs.." | grep -q '.up.: true,' && echo "..ifs.." >> /tmp/mtk/ifup-save")
os.execute("ifstatus "..ifs.." | grep -q '.up.: true,' && echo "..ifs.." >> /tmp/mtk/ifup-save")
end

end

function mt7615_ifup_up(devname)
local mtkwifi = require("mtkwifi")
local nixio = require("nixio")
nixio.syslog("debug", "mt7615_ifup_up called!")
nixio.syslog("debug", "MTK-Wi-Fi: ifup_up called!")

for _,ifs in ipairs(string.split(mtkwifi.read_pipe("cat /tmp/mtk/ifup-save"), "\n")) do
nixio.syslog("debug", "mt7615_ifup_up: ifup "..ifs)
nixio.syslog("debug", "MTK-Wi-Fi: ifup "..ifs)
os.execute("ifup "..ifs)
end

Expand All @@ -94,75 +94,75 @@ end
function mt7615_ifup_down(devname)
local mtkwifi = require("mtkwifi")
local nixio = require("nixio")
nixio.syslog("debug", "mt7615_ifup_down called!")
nixio.syslog("debug", "MTK-Wi-Fi: ifup_down called!")

for _,ifs in ipairs(string.split(mtkwifi.read_pipe("cat /tmp/mtk/ifup-save"), "\n")) do
nixio.syslog("debug", "mt7615_ifup_down: ifdown "..ifs)
nixio.syslog("debug", "MTK-Wi-Fi: ifdown "..ifs)
os.execute("ifdown "..ifs)
end
end

function mt7615_up(devname)
local nixio = require("nixio")
local mtkwifi = require("mtkwifi")
nixio.syslog("debug", "mt7615_up called!")

nixio.syslog("debug", "MTK-Wi-Fi: up called!")

if not devname then
-- we have to bring up root vif first, root vif will create all other vifs.
mt2 = mtkwifi.read_pipe("cat /tmp/mtk/vifup-save | grep -qE '(ra[0-9])|apcli0' && echo 1 2>/dev/null")
mt5 = mtkwifi.read_pipe("cat /tmp/mtk/vifup-save | grep -qE '(rai[0-9])|apclii0' && echo 1 2>/dev/null")
mt2 = mtkwifi.read_pipe("cat /tmp/mtk/vifup-save | grep -qE '(ra[0-9])|apcli0' && echo 1")
mt5 = mtkwifi.read_pipe("cat /tmp/mtk/vifup-save | grep -qE '(rai[0-9])|apclii0' && echo 1")

if mt2 == "1\n" then
nixio.syslog("debug", "mt7615_up_r: ifconfig ra0 up")
nixio.syslog("debug", "MTK-Wi-Fi: restart - ifconfig ra0 up")
os.execute("ifconfig ra0 up")
end
end
if mt5 == "1\n" then
nixio.syslog("debug", "mt7615_up_r: ifconfig rai0 up")
nixio.syslog("debug", "MTK-Wi-Fi: restart - ifconfig rai0 up")
os.execute("ifconfig rai0 up")
end
end

for _,vif in ipairs(string.split(mtkwifi.read_pipe("cat /tmp/mtk/vifup-save"), "\n"))
do
nixio.syslog("debug", "mt7615_up: ifconfig "..vif.." up")
nixio.syslog("debug", "MTK-Wi-Fi: ifconfig "..vif.." up")
os.execute("ifconfig "..vif.." up")
end
end

function mt7615_vifup_down(devname)
local nixio = require("nixio")
local mtkwifi = require("mtkwifi")
nixio.syslog("debug", "mt7615_vifup_down called!")
nixio.syslog("debug", "MTK-Wi-Fi: vifup_down called!")

for _,vif in ipairs(string.split(mtkwifi.read_pipe("cat /tmp/mtk/vifup-save"), "\n"))
do
nixio.syslog("debug", "mt7615_vifup_down: ifconfig "..vif.." down")
nixio.syslog("debug", "MTK-Wi-Fi: ifconfig "..vif.." down")
os.execute("ifconfig "..vif.." down")
end
end

function mt7615_down_r()
local nixio = require("nixio")
local mtkwifi = require("mtkwifi")
nixio.syslog("debug", "mt7615_down_r called!")
nixio.syslog("debug", "MTK-Wi-Fi: down_r called!")

mt2 = mtkwifi.read_pipe("cat /tmp/mtk/vifup-save | grep -q ra0 && echo 1 2>/dev/null")
mt5 = mtkwifi.read_pipe("cat /tmp/mtk/vifup-save | grep -q rai0 && echo 1 2>/dev/null")
mt2 = mtkwifi.read_pipe("cat /tmp/mtk/vifup-save | grep -q ra0 && echo 1")
mt5 = mtkwifi.read_pipe("cat /tmp/mtk/vifup-save | grep -q rai0 && echo 1")

if mt2 ~= "1\n" then
nixio.syslog("debug", "mt7615_down_r: ifconfig ra0 down")
nixio.syslog("debug", "MTK-Wi-Fi: restart - ifconfig ra0 down")
os.execute("ifconfig ra0 down")
end
if mt5 ~= "1\n" then
nixio.syslog("debug", "mt7615_down_r: ifconfig rai0 down")
nixio.syslog("debug", "MTK-Wi-Fi: restart - ifconfig rai0 down")
os.execute("ifconfig rai0 down")
end
end

function mt7615_reload(devname)
local nixio = require("nixio")
nixio.syslog("debug", "mt7615_reload called!")
nixio.syslog("debug", "MTK-Wi-Fi: reload called!")

mt7615_vifup_save(devname)
mt7615_ifup_save(devname)
Expand All @@ -174,16 +174,30 @@ end

function mt7615_restart(devname)
local nixio = require("nixio")
nixio.syslog("debug", "mt7615_restart called!")
local mtkwifi = require("mtkwifi")
nixio.syslog("debug", "MTK-Wi-Fi: restart called!")

mt7615_vifup_save()
mt7615_ifup_save()
mt7615_ifup_down(devname)
mt7615_vifup_down(devname)
nixio.syslog("debug", "mt7615_restart: rmmod mt_wifi")
os.execute("rmmod mt_wifi")
nixio.syslog("debug", "mt7615_restart: modprobe mt_wifi")
os.execute("modprobe mt_wifi")
if mtkwifi.exists("/etc/wireless/mt7603/") then
nixio.syslog("debug", "mt7603 restart: rmmod mt7603e")
os.execute("rmmod mt7603e")
nixio.syslog("debug", "mt7603 restart: modprobe mt7603e")
os.execute("modprobe mt7603e")
end
if mtkwifi.exists("/etc/wireless/mt7612/") then
nixio.syslog("debug", "mt7612 restart: rmmod mt76x2_ap")
os.execute("rmmod mt76x2_ap")
nixio.syslog("debug", "mt7612 restart: modprobe mt76x2_ap")
os.execute("modprobe mt76x2_ap")
else
nixio.syslog("debug", "mt7615 restart: rmmod mt_wifi")
os.execute("rmmod mt_wifi")
nixio.syslog("debug", "mt7615 restart: modprobe mt_wifi")
os.execute("modprobe mt_wifi")
end
mt7615_up()
mt7615_down_r()
mt7615_ifup_up(devname)
Expand All @@ -192,13 +206,13 @@ end
function mt7615_reset(devname)
local nixio = require("nixio")
local mtkwifi = require("mtkwifi")
nixio.syslog("debug", "mt7615_reset called!")
nixio.syslog("debug", "MTK-Wi-Fi: reset called!")
if mtkwifi.exists("/rom/etc/wireless/mt7615/") then
os.execute("rm -rf /etc/wireless/mt7615/")
os.execute("cp -rf /rom/etc/wireless/mt7615/ /etc/wireless/")
mt7615_reload(devname)
else
nixio.syslog("debug", "mt7615_reset: /rom"..profile.." missing, unable to reset!")
nixio.syslog("debug", "MTK-Wi-Fi: reset - /rom"..profile.." missing, unable to reset!")
end
end

Expand Down
Loading

0 comments on commit 0d5a5d2

Please sign in to comment.