| From 04376f0cc22533f9d2cf635bcb3bb9d564d5a3b5 Mon Sep 17 00:00:00 2001 |
| From: "Allen.Ye" <allen.ye@mediatek.com> |
| Date: Fri, 29 Jul 2022 10:11:31 +0800 |
| Subject: [PATCH] HAL: refactor SSIDTrafficStats2 function |
| |
| --- |
| source/wifi/wifi_hal.c | 69 ++++++++++++++++++++++++++++++++++-------- |
| 1 file changed, 56 insertions(+), 13 deletions(-) |
| |
| diff --git a/source/wifi/wifi_hal.c b/source/wifi/wifi_hal.c |
| index 0e047fc..556c73f 100644 |
| --- a/source/wifi/wifi_hal.c |
| +++ b/source/wifi/wifi_hal.c |
| @@ -7450,38 +7450,81 @@ INT wifi_getSSIDTrafficStats2(INT ssidIndex,wifi_ssidTrafficStats2_t *output_str |
| |
| sprintf(HConf_file,"%s%d%s","/nvram/hostapd",ssidIndex,".conf"); |
| GetInterfaceName(interface_name,HConf_file); |
| - sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f11 | tr -d '\n'"); |
| + sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f11 | tr -d '\\n'"); |
| fp = popen(pipeCmd, "r"); |
| fgets(str, MAX_BUF_SIZE,fp); |
| out->ssid_BytesSent = atol(str); |
| pclose(fp); |
| |
| - sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f3 | tr -d '\n'"); |
| + sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f3 | tr -d '\\n'"); |
| fp = popen(pipeCmd, "r"); |
| fgets(str, MAX_BUF_SIZE,fp); |
| out->ssid_BytesReceived = atol(str); |
| pclose(fp); |
| |
| - sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f12 | tr -d '\n'"); |
| + sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f12 | tr -d '\\n'"); |
| fp = popen(pipeCmd, "r"); |
| fgets(str, MAX_BUF_SIZE,fp); |
| out->ssid_PacketsSent = atol(str); |
| pclose(fp); |
| |
| - sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f4 | tr -d '\n'"); |
| + sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f4 | tr -d '\\n'"); |
| fp = popen(pipeCmd, "r"); |
| fgets(str, MAX_BUF_SIZE,fp); |
| out->ssid_PacketsReceived = atol(str); |
| pclose(fp); |
| - /* |
| - //TODO: |
| - out->ssid_UnicastPacketsSent = uni->ims_tx_data_packets; |
| - out->ssid_UnicastPacketsReceived = uni->ims_rx_data_packets; |
| - out->ssid_MulticastPacketsSent = multi->ims_tx_data_packets - multi->ims_tx_bcast_data_packets; |
| - out->ssid_MulticastPacketsReceived = multi->ims_rx_data_packets - multi->ims_rx_bcast_data_packets; |
| - out->ssid_BroadcastPacketsSent = multi->ims_tx_bcast_data_packets; |
| - out->ssid_BroadcastPacketsRecevied = multi->ims_rx_bcast_data_packets; |
| - */ |
| + |
| + sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f13 | tr -d '\\n'"); |
| + fp = popen(pipeCmd, "r"); |
| + fgets(str, MAX_BUF_SIZE,fp); |
| + out->ssid_ErrorsSent = atol(str); |
| + pclose(fp); |
| + |
| + sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f5 | tr -d '\\n'"); |
| + fp = popen(pipeCmd, "r"); |
| + fgets(str, MAX_BUF_SIZE,fp); |
| + out->ssid_ErrorsReceived = atol(str); |
| + pclose(fp); |
| + |
| + sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f14 | tr -d '\\n'"); |
| + fp = popen(pipeCmd, "r"); |
| + fgets(str, MAX_BUF_SIZE,fp); |
| + out->ssid_DiscardedPacketsSent = atol(str); |
| + pclose(fp); |
| + |
| + sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f6 | tr -d '\\n'"); |
| + fp = popen(pipeCmd, "r"); |
| + fgets(str, MAX_BUF_SIZE,fp); |
| + out->ssid_DiscardedPacketsReceived = atol(str); |
| + pclose(fp); |
| + |
| + sprintf(pipeCmd,"%s%s%s","tail -n1 /proc/net/netstat | cut -d ' ' -f5 | tr -d '\\n'"); |
| + fp = popen(pipeCmd, "r"); |
| + fgets(str, MAX_BUF_SIZE,fp); |
| + out->ssid_MulticastPacketsSent = atol(str); |
| + pclose(fp); |
| + |
| + sprintf(pipeCmd,"%s%s%s","tail -n1 /proc/net/netstat | cut -d ' ' -f4 | tr -d '\\n'"); |
| + fp = popen(pipeCmd, "r"); |
| + fgets(str, MAX_BUF_SIZE,fp); |
| + out->ssid_MulticastPacketsReceived = atol(str); |
| + pclose(fp); |
| + |
| + sprintf(pipeCmd,"%s%s%s","tail -n1 /proc/net/netstat | cut -d ' ' -f7 | tr -d '\\n'"); |
| + fp = popen(pipeCmd, "r"); |
| + fgets(str, MAX_BUF_SIZE,fp); |
| + out->ssid_BroadcastPacketsSent = atol(str); |
| + pclose(fp); |
| + |
| + sprintf(pipeCmd,"%s%s%s","tail -n1 /proc/net/netstat | cut -d ' ' -f6 | tr -d '\\n'"); |
| + fp = popen(pipeCmd, "r"); |
| + fgets(str, MAX_BUF_SIZE,fp); |
| + out->ssid_BroadcastPacketsRecevied = atol(str); |
| + pclose(fp); |
| + |
| + out->ssid_UnicastPacketsSent = out->ssid_PacketsSent - out->ssid_MulticastPacketsSent - out->ssid_BroadcastPacketsSent - out->ssid_DiscardedPacketsSent; |
| + out->ssid_UnicastPacketsReceived = out->ssid_PacketsReceived - out->ssid_MulticastPacketsReceived - out->ssid_BroadcastPacketsRecevied - out->ssid_DiscardedPacketsReceived; |
| + |
| return RETURN_OK; |
| } |
| |
| -- |
| 2.18.0 |
| |