blob: ae6f734c77b8120c1e02f3d9778a9002c7b287c6 [file] [log] [blame]
developer0ca00f32022-07-29 10:42:02 +08001From 04376f0cc22533f9d2cf635bcb3bb9d564d5a3b5 Mon Sep 17 00:00:00 2001
2From: "Allen.Ye" <allen.ye@mediatek.com>
3Date: Fri, 29 Jul 2022 10:11:31 +0800
4Subject: [PATCH] HAL: refactor SSIDTrafficStats2 function
5
6---
7 source/wifi/wifi_hal.c | 69 ++++++++++++++++++++++++++++++++++--------
8 1 file changed, 56 insertions(+), 13 deletions(-)
9
10diff --git a/source/wifi/wifi_hal.c b/source/wifi/wifi_hal.c
11index 0e047fc..556c73f 100644
12--- a/source/wifi/wifi_hal.c
13+++ b/source/wifi/wifi_hal.c
14@@ -7450,38 +7450,81 @@ INT wifi_getSSIDTrafficStats2(INT ssidIndex,wifi_ssidTrafficStats2_t *output_str
15
16 sprintf(HConf_file,"%s%d%s","/nvram/hostapd",ssidIndex,".conf");
17 GetInterfaceName(interface_name,HConf_file);
18- sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f11 | tr -d '\n'");
19+ sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f11 | tr -d '\\n'");
20 fp = popen(pipeCmd, "r");
21 fgets(str, MAX_BUF_SIZE,fp);
22 out->ssid_BytesSent = atol(str);
23 pclose(fp);
24
25- sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f3 | tr -d '\n'");
26+ sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f3 | tr -d '\\n'");
27 fp = popen(pipeCmd, "r");
28 fgets(str, MAX_BUF_SIZE,fp);
29 out->ssid_BytesReceived = atol(str);
30 pclose(fp);
31
32- sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f12 | tr -d '\n'");
33+ sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f12 | tr -d '\\n'");
34 fp = popen(pipeCmd, "r");
35 fgets(str, MAX_BUF_SIZE,fp);
36 out->ssid_PacketsSent = atol(str);
37 pclose(fp);
38
39- sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f4 | tr -d '\n'");
40+ sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f4 | tr -d '\\n'");
41 fp = popen(pipeCmd, "r");
42 fgets(str, MAX_BUF_SIZE,fp);
43 out->ssid_PacketsReceived = atol(str);
44 pclose(fp);
45- /*
46- //TODO:
47- out->ssid_UnicastPacketsSent = uni->ims_tx_data_packets;
48- out->ssid_UnicastPacketsReceived = uni->ims_rx_data_packets;
49- out->ssid_MulticastPacketsSent = multi->ims_tx_data_packets - multi->ims_tx_bcast_data_packets;
50- out->ssid_MulticastPacketsReceived = multi->ims_rx_data_packets - multi->ims_rx_bcast_data_packets;
51- out->ssid_BroadcastPacketsSent = multi->ims_tx_bcast_data_packets;
52- out->ssid_BroadcastPacketsRecevied = multi->ims_rx_bcast_data_packets;
53- */
54+
55+ sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f13 | tr -d '\\n'");
56+ fp = popen(pipeCmd, "r");
57+ fgets(str, MAX_BUF_SIZE,fp);
58+ out->ssid_ErrorsSent = atol(str);
59+ pclose(fp);
60+
61+ sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f5 | tr -d '\\n'");
62+ fp = popen(pipeCmd, "r");
63+ fgets(str, MAX_BUF_SIZE,fp);
64+ out->ssid_ErrorsReceived = atol(str);
65+ pclose(fp);
66+
67+ sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f14 | tr -d '\\n'");
68+ fp = popen(pipeCmd, "r");
69+ fgets(str, MAX_BUF_SIZE,fp);
70+ out->ssid_DiscardedPacketsSent = atol(str);
71+ pclose(fp);
72+
73+ sprintf(pipeCmd,"%s%s%s","cat /proc/net/dev | grep ",interface_name," | tr -s ' ' | cut -d ' ' -f6 | tr -d '\\n'");
74+ fp = popen(pipeCmd, "r");
75+ fgets(str, MAX_BUF_SIZE,fp);
76+ out->ssid_DiscardedPacketsReceived = atol(str);
77+ pclose(fp);
78+
79+ sprintf(pipeCmd,"%s%s%s","tail -n1 /proc/net/netstat | cut -d ' ' -f5 | tr -d '\\n'");
80+ fp = popen(pipeCmd, "r");
81+ fgets(str, MAX_BUF_SIZE,fp);
82+ out->ssid_MulticastPacketsSent = atol(str);
83+ pclose(fp);
84+
85+ sprintf(pipeCmd,"%s%s%s","tail -n1 /proc/net/netstat | cut -d ' ' -f4 | tr -d '\\n'");
86+ fp = popen(pipeCmd, "r");
87+ fgets(str, MAX_BUF_SIZE,fp);
88+ out->ssid_MulticastPacketsReceived = atol(str);
89+ pclose(fp);
90+
91+ sprintf(pipeCmd,"%s%s%s","tail -n1 /proc/net/netstat | cut -d ' ' -f7 | tr -d '\\n'");
92+ fp = popen(pipeCmd, "r");
93+ fgets(str, MAX_BUF_SIZE,fp);
94+ out->ssid_BroadcastPacketsSent = atol(str);
95+ pclose(fp);
96+
97+ sprintf(pipeCmd,"%s%s%s","tail -n1 /proc/net/netstat | cut -d ' ' -f6 | tr -d '\\n'");
98+ fp = popen(pipeCmd, "r");
99+ fgets(str, MAX_BUF_SIZE,fp);
100+ out->ssid_BroadcastPacketsRecevied = atol(str);
101+ pclose(fp);
102+
103+ out->ssid_UnicastPacketsSent = out->ssid_PacketsSent - out->ssid_MulticastPacketsSent - out->ssid_BroadcastPacketsSent - out->ssid_DiscardedPacketsSent;
104+ out->ssid_UnicastPacketsReceived = out->ssid_PacketsReceived - out->ssid_MulticastPacketsReceived - out->ssid_BroadcastPacketsRecevied - out->ssid_DiscardedPacketsReceived;
105+
106 return RETURN_OK;
107 }
108
109--
1102.18.0
111