RDK Documentation (Open Sourced RDK Components)
Device_WiFi_Radio_Stats.cpp
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 /**
22  * @file Device_WiFi_Radio_Stats.cpp
23  *
24  * @brief Device.WiFi.Radio.Stats API Implementation.
25  *
26  * This is the implementation of the WiFi API.
27  *
28  * @par Document
29  */
30 /** @addtogroup TR-069 WiFi Implementation
31  * This is the implementation of the Device Public API.
32  * @{
33  */
34 #ifdef USE_WIFI_PROFILE
35 /*****************************************************************************
36  * STANDARD INCLUDE FILES
37  *****************************************************************************/
39 
40 extern "C" {
41 #include "wifiSrvMgrIarmIf.h"
42  /* #include "c_only_header.h"*/
43 };
44 
45 GHashTable* hostIf_WiFi_Radio_Stats::ifHash = NULL;
46 static time_t radioFirstExTime = 0;
47 
48 hostIf_WiFi_Radio_Stats *hostIf_WiFi_Radio_Stats::getInstance(int dev_id)
49 {
50  static hostIf_WiFi_Radio_Stats* pRet = NULL;
51 
52  if(ifHash)
53  {
54  pRet = (hostIf_WiFi_Radio_Stats *)g_hash_table_lookup(ifHash, (gpointer) dev_id);
55  }
56  else
57  {
58  ifHash = g_hash_table_new(NULL,NULL);
59  }
60 
61  if(!pRet)
62  {
63  try {
64  pRet = new hostIf_WiFi_Radio_Stats(dev_id);
65  } catch(int e)
66  {
67  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create hostIf_WiFi_Radio_Stats instance..\n");
68  }
69  g_hash_table_insert(ifHash,(gpointer)dev_id, pRet);
70  }
71  return pRet;
72 }
73 
74 void hostIf_WiFi_Radio_Stats::closeInstance(hostIf_WiFi_Radio_Stats *pDev)
75 {
76  if(pDev)
77  {
78 // g_hash_table_remove(devHash, (gconstpointer)pDev->dev_id);
79 // if(pDev->ctxt)
80  delete pDev;
81  }
82 }
83 
84 void hostIf_WiFi_Radio_Stats::closeAllInstances()
85 {
86  if(ifHash)
87  {
88  GList* tmp_list = g_hash_table_get_values (ifHash);
89 
90  while(tmp_list)
91  {
92  hostIf_WiFi_Radio_Stats* pDev = (hostIf_WiFi_Radio_Stats *)tmp_list->data;
93  tmp_list = tmp_list->next;
94  closeInstance(pDev);
95  }
96  }
97 }
98 
99 
100 hostIf_WiFi_Radio_Stats::hostIf_WiFi_Radio_Stats(int dev_id):
101  dev_id(dev_id),
102  BytesSent(0),
103  BytesReceived(0),
104  PacketsSent(0),
105  PacketsReceived(0),
106  ErrorsSent(0),
107  ErrorsReceived(0),
108  DiscardPacketsSent(0),
109  DiscardPacketsReceived(0),
110  NoiseFloor(0)
111 {
112 
113 }
114 
115 int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_Props_Fields(int radioIndex)
116 {
117  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
118  IARM_BUS_WiFi_DiagsPropParam_t param = {0};
119  int ret;
120  radioIndex=1;
121 
122  hostIf_WiFi_Radio_Stats *pDev = hostIf_WiFi_Radio_Stats::getInstance(dev_id);
123  if(pDev)
124  {
125  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getRadioStatsProps, (void *)&param, sizeof(param));
126  if (IARM_RESULT_SUCCESS != retVal)
127  {
128  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] IARM BUS CALL failed with : %d.\n", __FILE__, __FUNCTION__, retVal);
129  return NOK;
130  }
131  BytesSent = param.data.radio_stats.params.bytesSent;
132  BytesReceived = param.data.radio_stats.params.bytesReceived;
133  PacketsSent = param.data.radio_stats.params.packetsSent;
134  PacketsReceived = param.data.radio_stats.params.packetsReceived;
135  ErrorsSent = param.data.radio_stats.params.errorsSent;
136  ErrorsReceived = param.data.radio_stats.params.errorsReceived;
137  DiscardPacketsSent = param.data.radio_stats.params.discardPacketsSent;
138  DiscardPacketsReceived = param.data.radio_stats.params.discardPacketsReceived;
139  NoiseFloor = param.data.radio_stats.params.noiseFloor;
140  radioFirstExTime = time (NULL);
141  return OK;
142  }
143  else
144  {
145  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s]Error! Unable to connect to wifi instance\n", __FILE__, __FUNCTION__);
146  return NOK;
147  }
148 
149 }
150 
151 void hostIf_WiFi_Radio_Stats::checkWifiRadioPropsFetch(int radioIndex)
152 {
153  int ret = NOK;
154  time_t currExTime = time (NULL);
155  if ((currExTime - radioFirstExTime ) > QUERY_INTERVAL)
156  {
157  ret = get_Device_WiFi_Radio_Stats_Props_Fields(radioIndex);
158  if( OK != ret)
159  {
160  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] Failed to fetch : %d.\n", __FILE__, __FUNCTION__, ret);
161  }
162  }
163 }
164 
166 {
167  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
168  checkWifiRadioPropsFetch(radioIndex);
169  put_int(stMsgData->paramValue, BytesSent);
170  stMsgData->paramtype = hostIf_UnsignedIntType;
171  stMsgData->paramLen=4;
172  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
173  return OK;
174 
175 }
176 
177 
179 {
180  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
181  checkWifiRadioPropsFetch(radioIndex);
182  put_int(stMsgData->paramValue, BytesReceived);
183  stMsgData->paramtype = hostIf_UnsignedIntType;
184  stMsgData->paramLen=4;
185  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
186  return OK;
187 }
188 
190 {
191  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
192  checkWifiRadioPropsFetch(radioIndex);
193  put_int(stMsgData->paramValue, PacketsSent);
194  stMsgData->paramtype = hostIf_UnsignedIntType;
195  stMsgData->paramLen=4;
196  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
197  return OK;
198 }
199 
201 {
202  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
203  checkWifiRadioPropsFetch(radioIndex);
204  put_int(stMsgData->paramValue, PacketsReceived);
205  stMsgData->paramtype = hostIf_UnsignedIntType;
206  stMsgData->paramLen=4;
207  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
208  return OK;
209 }
210 
212 {
213  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
214  checkWifiRadioPropsFetch(radioIndex);
215  put_int(stMsgData->paramValue, ErrorsSent);
216  stMsgData->paramtype = hostIf_UnsignedIntType;
217  stMsgData->paramLen=4;
218  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
219  return OK;
220 }
221 
223 {
224  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
225  checkWifiRadioPropsFetch(radioIndex);
226  put_int(stMsgData->paramValue, ErrorsReceived);
227  stMsgData->paramtype = hostIf_UnsignedIntType;
228  stMsgData->paramLen=4;
229  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
230  return OK;
231 }
232 
234 {
235  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
236  checkWifiRadioPropsFetch(radioIndex);
237  put_int(stMsgData->paramValue, DiscardPacketsSent);
238  stMsgData->paramtype = hostIf_UnsignedIntType;
239  stMsgData->paramLen=4;
240  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
241  return OK;
242 }
243 
245 {
246  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
247  checkWifiRadioPropsFetch(radioIndex);
248  put_int(stMsgData->paramValue, DiscardPacketsReceived);
249  stMsgData->paramtype = hostIf_UnsignedIntType;
250  stMsgData->paramLen=4;
251  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
252  return OK;
253 }
255 {
256  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
257  checkWifiRadioPropsFetch(radioIndex);
258  put_int(stMsgData->paramValue, NoiseFloor);
259  stMsgData->paramtype = hostIf_IntegerType;
260  stMsgData->paramLen=4;
261  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
262  return OK;
263 }
264 
265 
266 #endif /* #ifdef USE_WIFI_PROFILE */
hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_BytesReceived
int get_Device_WiFi_Radio_Stats_BytesReceived(HOSTIF_MsgData_t *stMsgData, int radioIndex)
Get the total number of bytes received on the interface, including framing characters.
hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_DiscardPacketsReceived
int get_Device_WiFi_Radio_Stats_DiscardPacketsReceived(HOSTIF_MsgData_t *stMsgData, int radioIndex)
Get the total number of inbound packets which were chosen to be discarded even though no errors had b...
Device_WiFi_Radio_Stats.h
hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_BytesSent
int get_Device_WiFi_Radio_Stats_BytesSent(HOSTIF_MsgData_t *stMsgData, int radioIndex)
Get total number of bytes transmitted out of the interface, including framing characters.
IARM_Bus_Call
IARM_Result_t IARM_Bus_Call(const char *ownerName, const char *methodName, void *arg, size_t argLen)
This API is used to Invoke RPC method by its application name and method name.
Definition: iarm_bus.c:57
hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_DiscardPacketsSent
int get_Device_WiFi_Radio_Stats_DiscardPacketsSent(HOSTIF_MsgData_t *stMsgData, int radioIndex)
Get the total number of outbound packets which were chosen to be discarded even though no errors had ...
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_PacketsSent
int get_Device_WiFi_Radio_Stats_PacketsSent(HOSTIF_MsgData_t *stMsgData, int radioIndex)
Get the value of 'Device.WiFi.Radio.Stats.PacketsSent'. This function provides the total number of pa...
hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_ErrorsReceived
int get_Device_WiFi_Radio_Stats_ErrorsReceived(HOSTIF_MsgData_t *stMsgData, int radioIndex)
Get the total number of inbound packets that contained errors preventing them from being delivered to...
_IARM_BUS_WiFi_DiagsPropParam_t
Definition: wifiSrvMgrIarmIf.h:396
hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_NoiseFloor
int get_Device_WiFi_Radio_Stats_NoiseFloor(HOSTIF_MsgData_t *stMsgData, int radioIndex)
Get total number of bytes transmitted out of the interface, including framing characters.
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
IARM_BUS_WIFI_MGR_API_getRadioStatsProps
#define IARM_BUS_WIFI_MGR_API_getRadioStatsProps
Definition: wifiSrvMgrIarmIf.h:83
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_ErrorsSent
int get_Device_WiFi_Radio_Stats_ErrorsSent(HOSTIF_MsgData_t *stMsgData, int radioIndex)
Get the total number of outbound packets that could not be transmitted because of errors.
hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_PacketsReceived
int get_Device_WiFi_Radio_Stats_PacketsReceived(HOSTIF_MsgData_t *stMsgData, int radioIndex)
Get the total number of packets received on the interface.
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152
_HostIf_MsgData_t::paramLen
short paramLen
Definition: hostIf_tr69ReqHandler.h:175
hostIf_WiFi_Radio_Stats
Definition: Device_WiFi_Radio_Stats.h:67