luci-app-mtk: show tx power info

This commit is contained in:
hanwckf 2023-12-04 19:04:40 +08:00
parent 57cbd3d8f3
commit ca6260fbf2
5 changed files with 63 additions and 1 deletions

View File

@ -85,7 +85,11 @@ local chipname
<span> <%:Work mode%>: <% if dev.ApCliEnable == "1" then %> APCli <% else %> AP <% end %> <br/> </span>
<%local temp = mtkwifi.get_temp(dev.devname)%>
<%if temp then%>
<span> <%:Tempature%>: <%=temp%>&#176;C</span>
<span> <%:Tempature%>: <%=temp%>&#176;C <br/> </span>
<%end%>
<%local txpwr = mtkwifi.get_txpwr(dev.devname)%>
<%if txpwr then%>
<span> <%:Tx Power%>: <%=txpwr%> dbm <br/> </span>
<%end%>
<%end%>
</td>

View File

@ -46,6 +46,9 @@ msgstr "始终关闭"
msgid "Tempature"
msgstr "温度"
msgid "Tx Power"
msgstr "发射功率"
msgid "Driver version"
msgstr "驱动版本"

View File

@ -344,6 +344,21 @@ function mtkwifi.__profile_applied_settings_path(profile)
return bak
end
function mtkwifi.get_txpwr(devname)
local l1dat, l1 = mtkwifi.__get_l1dat()
local dridx = l1.DEV_RINDEX
local devs = mtkwifi.get_all_devs()
if devs and devs[devname] then
local ifname = l1dat and l1dat[dridx][devname].main_ifname
if ifname then
return c_getTxPower(ifname)['txpower']
end
end
return nil
end
function mtkwifi.get_temp(devname)
local vif_name = nil
local devs = mtkwifi.get_all_devs()

View File

@ -20,6 +20,7 @@ int luaopen_ioctl_helper(lua_State *L)
lua_register(L,"c_getWMode",getWMOde);
lua_register(L,"c_getTempature",getTempature);
lua_register(L,"c_scanResult",scanResult);
lua_register(L,"c_getTxPower",getTxPower);
return 0;
}
@ -100,6 +101,44 @@ int getTempature(lua_State *L)
return 1;
}
static unsigned int get_txpower(const char *interface)
{
int socket_id;
struct iwreq wrq;
int txpower = 0;
socket_id = socket(AF_INET, SOCK_DGRAM, 0);
if (socket_id < 0) {
perror("socket() failed");
return socket_id;
}
snprintf(wrq.ifr_name, sizeof(wrq.ifr_name), "%s", interface);
wrq.u.txpower.flags = 0;
if(ioctl(socket_id, SIOCGIWTXPOW, &wrq) >= 0) {
txpower = wrq.u.txpower.value;
} else {
fprintf(stderr, "%s: ioctl fail\n", __func__);
}
close(socket_id);
return txpower;
}
int getTxPower(lua_State *L)
{
char tempstr[5] = {0};
const char *interface = luaL_checkstring(L, 1);
snprintf(tempstr, sizeof(tempstr), "%d", get_txpower(interface));
lua_newtable(L);
lua_pushstring(L, "txpower"); /* push key */
lua_pushstring(L, tempstr); /* push value */
lua_settable(L, -3);
/* Returning one table which is already on top of Lua stack. */
return 1;
}
static unsigned int get_w_mode(const char *interface)
{
int socket_id;

View File

@ -208,6 +208,7 @@ int get_macaddr(lua_State *L);
int convert_string_display(lua_State *L);
int StaInfo(lua_State *L);
int getWMOde(lua_State *L);
int getTxPower(lua_State *L);
int getTempature(lua_State *L);
int scanResult(lua_State *L);
void getRate(HTTRANSMIT_SETTING_FIX HTSetting, ULONG *fLastTxRxRate);