blob: 8e0dcc37ef93620801ce0f7f30bb91ec67efc115 [file] [log] [blame]
developer294f8862022-08-29 15:00:13 +08001From 9e4545526749cc1d7b2eec18020d8329cf278dc0 Mon Sep 17 00:00:00 2001
2From: "Allen.Ye" <allen.ye@mediatek.com>
3Date: Fri, 26 Aug 2022 16:12:05 +0800
4Subject: [PATCH] HAL add get channel stats
5
6---
7 source/wifi/wifi_hal.c | 76 ++++++++++++++++++++++++++++++++++++++++++
8 1 file changed, 76 insertions(+)
9
10diff --git a/source/wifi/wifi_hal.c b/source/wifi/wifi_hal.c
11index 453e551..f9639a2 100644
12--- a/source/wifi/wifi_hal.c
13+++ b/source/wifi/wifi_hal.c
14@@ -75,6 +75,7 @@ Licensed under the ISC license
15 #define VAP_STATUS_FILE "/tmp/vap-status"
16 #define ESSID_FILE "/tmp/essid"
17 #define GUARD_INTERVAL_FILE "/tmp/guard-interval"
18+#define CHANNEL_STATS_FILE "/tmp/channel_stats"
19
20 #ifdef MTK_IMPL
21 #define DRIVER_2GHZ "mt7915e"
22@@ -1065,6 +1066,81 @@ INT wifi_setRadioCountryCode(INT radioIndex, CHAR *CountryCode)
23 return RETURN_OK;
24 }
25
26+INT wifi_getRadioChannelStats2(INT radioIndex, wifi_channelStats2_t *outputChannelStats2)
27+{
28+ char channel_util_file[64] = {0};
29+ char cmd[128] = {0};
30+ char buf[128] = {0};
31+ char *line = NULL, *param = NULL, *value = NULL;
32+ int read = 0;
33+ unsigned int ActiveTime = 0, BusyTime = 0, TransmitTime = 0;
34+ unsigned int preActiveTime = 0, preBusyTime = 0, preTransmitTime = 0;
35+ size_t len = 0;
36+ FILE *f = NULL;
37+
38+ WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__);
39+
40+ snprintf(cmd, sizeof(cmd), "iw %s%d scan | grep signal | awk '{print $2}' | sort -n | tail -n1", AP_PREFIX, radioIndex);
41+ _syscmd(cmd, buf, sizeof(buf));
42+ outputChannelStats2->ch_Max80211Rssi = strtol(buf, NULL, 10);
43+
44+ memset(cmd, 0, sizeof(cmd));
45+ memset(buf, 0, sizeof(buf));
46+ snprintf(cmd, sizeof(cmd), "iw %s%d survey dump | grep 'in use' -A6", AP_PREFIX, radioIndex);
47+ if ((f = popen(cmd, "r")) == NULL) {
48+ wifi_dbg_printf("%s: popen %s error\n", __func__, cmd);
49+ return RETURN_ERR;
50+ }
51+
52+ read = getline(&line, &len, f);
53+ while (read != -1) {
54+ param = strtok(line, ":\t");
55+ value = strtok(NULL, " ");
56+ if(strstr(param, "frequency") != NULL) {
57+ outputChannelStats2->ch_Frequency = strtol(value, NULL, 10);
58+ }
59+ if(strstr(param, "noise") != NULL) {
60+ outputChannelStats2->ch_NoiseFloor = strtol(value, NULL, 10);
61+ outputChannelStats2->ch_Non80211Noise = strtol(value, NULL, 10);
62+ }
63+ if(strstr(param, "channel active time") != NULL) {
64+ ActiveTime = strtol(value, NULL, 10);
65+ }
66+ if(strstr(param, "channel busy time") != NULL) {
67+ BusyTime = strtol(value, NULL, 10);
68+ }
69+ if(strstr(param, "channel transmit time") != NULL) {
70+ TransmitTime = strtol(value, NULL, 10);
71+ }
72+ read = getline(&line, &len, f);
73+ }
74+ pclose(f);
75+
76+ // The file should store the last active, busy and transmit time
77+ snprintf(channel_util_file, sizeof(channel_util_file), "%s%d.txt", CHANNEL_STATS_FILE, radioIndex);
78+ f = fopen(channel_util_file, "r");
79+ if (f != NULL) {
80+ read = getline(&line, &len, f);
81+ preActiveTime = strtol(line, NULL, 10);
82+ read = getline(&line, &len, f);
83+ preBusyTime = strtol(line, NULL, 10);
84+ read = getline(&line, &len, f);
85+ preTransmitTime = strtol(line, NULL, 10);
86+ fclose(f);
87+ }
88+
89+ outputChannelStats2->ch_ObssUtil = (BusyTime - preBusyTime)*100/(ActiveTime - preActiveTime);
90+ outputChannelStats2->ch_SelfBssUtil = (TransmitTime - preTransmitTime)*100/(ActiveTime - preActiveTime);
91+
92+ f = fopen(channel_util_file, "w");
93+ if (f != NULL) {
94+ fprintf(f, "%u\n%u\n%u\n", ActiveTime, BusyTime, TransmitTime);
95+ fclose(f);
96+ }
97+ WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__);
98+ return RETURN_OK;
99+}
100+
101 /**********************************************************************************
102 *
103 * Wifi radio level function prototypes
104--
1052.18.0
106