RDK Documentation (Open Sourced RDK Components)
Device_WiFi_EndPoint.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_EndPoint.cpp
23  *
24  * @brief Device_WiFi_SSID 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  *****************************************************************************/
38 
39 #include "Device_WiFi_EndPoint.h"
40 #include <mutex>
41 #include "safec_lib.h"
42 
43 extern "C" {
44 #include "wifiSrvMgrIarmIf.h"
45 };
46 
47 GHashTable* hostIf_WiFi_EndPoint::ifHash = NULL;
48 
49 hostIf_WiFi_EndPoint* hostIf_WiFi_EndPoint::getInstance(int dev_id)
50 {
51  hostIf_WiFi_EndPoint* pRet = NULL;
52 
53  if(ifHash)
54  {
55  pRet = (hostIf_WiFi_EndPoint *)g_hash_table_lookup(ifHash,(gpointer) dev_id);
56  }
57  else
58  {
59  ifHash = g_hash_table_new(NULL,NULL);
60  }
61 
62  if(!pRet)
63  {
64  try {
65  pRet = new hostIf_WiFi_EndPoint(dev_id);
66  } catch(int e)
67  {
68  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create hostIf_WiFi_EndPoint instance..\n");
69  }
70  g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
71  }
72  return pRet;
73 }
74 
75 GList* hostIf_WiFi_EndPoint::getAllInstances()
76 {
77  if(ifHash)
78  return g_hash_table_get_keys(ifHash);
79  return NULL;
80 }
81 
82 void hostIf_WiFi_EndPoint::closeInstance(hostIf_WiFi_EndPoint *pDev)
83 {
84  if(pDev)
85  {
86  g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
87  delete pDev;
88  }
89 }
90 
91 void hostIf_WiFi_EndPoint::closeAllInstances()
92 {
93  if(ifHash)
94  {
95  GList* tmp_list = g_hash_table_get_values (ifHash);
96 
97  while(tmp_list)
98  {
99  hostIf_WiFi_EndPoint* pDev = (hostIf_WiFi_EndPoint *)tmp_list->data;
100  tmp_list = tmp_list->next;
101  closeInstance(pDev);
102  }
103  }
104 }
105 
106 
107 hostIf_WiFi_EndPoint::hostIf_WiFi_EndPoint (int dev_id) :
108  dev_id (dev_id),
109  Enable(false),
110  ProfileNumberOfEntries(0)
111 {
112  memset(Status, 0, 64);
113  memset(Alias, 0, 64);
114  memset(ProfileReference, 0, 256);
115  memset(SSIDReference, 0, 256);
116  stats.LastDataDownlinkRate = 0;
117  stats.LastDataUplinkRate = 0;
118  stats.SignalStrength = 0;
119  stats.Retransmissions = 0;
120 }
121 
122 
123 /**
124 * @brief Enables/disables this end point.
125 */
127 {
128  LOG_ENTRY_EXIT;
129  if (OK != refreshCache ())
130  return NOK;
131  RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] Enable = [%d]\n", __FUNCTION__, Enable);
132  put_int (stMsgData->paramValue, Enable);
133  stMsgData->paramtype = hostIf_BooleanType;
134  stMsgData->paramLen = sizeof (bool);
135  return OK;
136 }
137 
139 {
140  return OK;
141 }
142 
144 {
145  errno_t rc = -1;
146  LOG_ENTRY_EXIT;
147  if (OK != refreshCache ())
148  return NOK;
149  RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] Status = [%s]\n", __FUNCTION__, Status);
150  rc=strcpy_s (stMsgData->paramValue,sizeof(stMsgData->paramValue), Status);
151  if(rc!=EOK)
152  {
153  ERR_CHK(rc);
154  }
155  stMsgData->paramtype = hostIf_StringType;
156  stMsgData->paramLen = strlen (Status);
157  return OK;
158 }
159 
161 {
162  errno_t rc = -1;
163  LOG_ENTRY_EXIT;
164  if (OK != refreshCache ())
165  return NOK;
166  RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] Alias = [%s]\n", __FUNCTION__, Alias);
167  rc=strcpy_s (stMsgData->paramValue,sizeof(stMsgData->paramValue), Alias);
168  if(rc!=EOK)
169  {
170  ERR_CHK(rc);
171  }
172  stMsgData->paramtype = hostIf_StringType;
173  stMsgData->paramLen = strlen (Alias);
174  return OK;
175 }
176 
178 {
179  return OK;
180 }
181 
183 {
184  return OK;
185 }
186 
188 {
189  return OK;
190 }
191 
193 {
194 /*
195  From the spec:
196 
197  The value MUST be the path name of a row in the SSID table. If the
198  referenced object is deleted, the parameter value MUST be set to an empty
199  string. SSIDReference is determined based on the Profile.{i}.SSID within the
200  associated ProfileReference) endpoint profile. SSIDReference MUST be an
201  empty string if ProfileReference is an empty string (i.e. only when an
202  active profile is assigned can the associated SSID interface be determined).
203 */
204  // not same as value of SSIDReference returned by netsrvmgr, captured in member SSIDReference
205 
206  return OK;
207 }
208 
209 /*
210  * @brief The number of entries in the Profile table.
211  */
213 {
214  return OK;
215 }
216 
218 {
219  LOG_ENTRY_EXIT;
220  if (OK != refreshCache ())
221  return NOK;
222  RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] Stats.LastDataDownlinkRate = [%lu]\n", __FUNCTION__, stats.LastDataDownlinkRate);
223  put_int (stMsgData->paramValue, stats.LastDataDownlinkRate);
224  stMsgData->paramtype = hostIf_UnsignedLongType;
225  stMsgData->paramLen = sizeof (unsigned long);
226  return OK;
227 }
228 
230 {
231  LOG_ENTRY_EXIT;
232  if (OK != refreshCache ())
233  return NOK;
234  RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] Stats.LastDataUplinkRate = [%lu]\n", __FUNCTION__, stats.LastDataUplinkRate);
235  put_int (stMsgData->paramValue, stats.LastDataUplinkRate);
236  stMsgData->paramtype = hostIf_UnsignedLongType;
237  stMsgData->paramLen = sizeof (unsigned long);
238  return OK;
239 }
240 
242 {
243  LOG_ENTRY_EXIT;
244  if (OK != refreshCache ())
245  return NOK;
246  RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] Stats.SignalStrength = [%d]\n", __FUNCTION__, stats.SignalStrength);
247  put_int (stMsgData->paramValue, stats.SignalStrength);
248  stMsgData->paramtype = hostIf_IntegerType;
249  stMsgData->paramLen = sizeof (int);
250  return OK;
251 }
252 
254 {
255  LOG_ENTRY_EXIT;
256  if (OK != refreshCache ())
257  return NOK;
258  RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] Stats.Retransmissions = [%u]\n", __FUNCTION__, stats.Retransmissions);
259  put_int (stMsgData->paramValue, stats.Retransmissions);
260  stMsgData->paramtype = hostIf_UnsignedLongType;
261  stMsgData->paramLen = sizeof (unsigned long);
262  return OK;
263 }
264 
265 /**
266 * @brief Refreshes the cache of Device.WiFi.EndPoint. parameters
267 */
268 int hostIf_WiFi_EndPoint::refreshCache()
269 {
270  LOG_ENTRY_EXIT;
271 
272  static time_t time_of_last_successful_query = 0;
273  static int last_call_status = NOK;
274  static std::mutex m;
275 
276  std::lock_guard<std::mutex> lg (m);
277 
278  // Using a 1-second cache.
279  if ((last_call_status == OK ) && (time (0) <= time_of_last_successful_query + 1))
280  {
281  RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s] Cache not stale. last call status is SUCCESS, Refresh not required.\n", __FUNCTION__);
282  return OK;
283  }
284 
286  IARM_Result_t retVal = IARM_Bus_Call (IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getEndPointProps, (void *) &param, sizeof(param));
287  if (IARM_RESULT_SUCCESS != retVal)
288  {
289  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Cache refresh failed. IARM_Bus_Call to netsrvmgr returned [%d]\n", __FUNCTION__, retVal);
290  last_call_status = NOK;
291  return NOK;
292  }
293 
294  time_of_last_successful_query = time (0);
295 
296  Enable = param.data.endPointInfo.enable;
297  strncpy (Status, param.data.endPointInfo.status, BUFF_LENGTH_64);
298  strncpy (Alias, param.data.endPointInfo.alias, BUFF_LENGTH_64);
299  strncpy (ProfileReference, param.data.endPointInfo.ProfileReference, BUFF_LENGTH_256);
300  strncpy (SSIDReference, param.data.endPointInfo.SSIDReference, BUFF_LENGTH_256);
301  ProfileNumberOfEntries = param.data.endPointInfo.ProfileNumberOfEntries;
302  stats.LastDataDownlinkRate = param.data.endPointInfo.stats.lastDataDownlinkRate;
303  stats.LastDataUplinkRate = param.data.endPointInfo.stats.lastDataUplinkRate;
304  stats.SignalStrength = param.data.endPointInfo.stats.signalStrength;
305  stats.Retransmissions = param.data.endPointInfo.stats.retransmissions;
306 
307  RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s] Cache refreshed.\n", __FUNCTION__);
308 
309  if (false == param.data.endPointInfo.enable) // "Disabled" endpoint
310  {
311  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] EndPoint is disabled\n", __FUNCTION__);
312  last_call_status = NOK;
313  return OK;
314  }
315  last_call_status = OK;
316  return OK;
317 }
318 
319 #endif /* #ifdef USE_WIFI_PROFILE */
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_EndPoint::set_Device_WiFi_EndPoint_Alias
int set_Device_WiFi_EndPoint_Alias(HOSTIF_MsgData_t *stMsgData)
Set the alias name for the wireless endpoint.
hostIf_WiFi_EndPoint::get_Device_WiFi_EndPoint_Enable
int get_Device_WiFi_EndPoint_Enable(HOSTIF_MsgData_t *stMsgData)
Check wethen wifi endpoint is enabled or not.
hostIf_WiFi_EndPoint::set_Device_WiFi_EndPoint_ProfileReference
int set_Device_WiFi_EndPoint_ProfileReference(HOSTIF_MsgData_t *stMsgData)
Set the value MUST be the path name of a row in the Profile table. If the referenced object is delete...
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
hostIf_WiFi_EndPoint::get_Device_WiFi_EndPoint_Alias
int get_Device_WiFi_EndPoint_Alias(HOSTIF_MsgData_t *stMsgData)
Get the alias name of the wireless endpoint.
IARM_BUS_WIFI_MGR_API_getEndPointProps
#define IARM_BUS_WIFI_MGR_API_getEndPointProps
Definition: wifiSrvMgrIarmIf.h:86
hostIf_WiFi_EndPoint
Definition: Device_WiFi_EndPoint.h:62
_IARM_BUS_WiFi_DiagsPropParam_t
Definition: wifiSrvMgrIarmIf.h:396
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
hostIf_WiFi_EndPoint::get_Device_WiFi_EndPoint_Stats_LastDataUplinkRate
int get_Device_WiFi_EndPoint_Stats_LastDataUplinkRate(HOSTIF_MsgData_t *stMsgData)
The data transmit rate in kbps that was most recently used for transmission from the end point to the...
hostIf_WiFi_EndPoint::get_Device_WiFi_EndPoint_ProfileNumberOfEntries
int get_Device_WiFi_EndPoint_ProfileNumberOfEntries(HOSTIF_MsgData_t *stMsgData)
Check wethen wifi endpoint is enabled or not.
hostIf_WiFi_EndPoint::get_Device_WiFi_EndPoint_Stats_SignalStrength
int get_Device_WiFi_EndPoint_Stats_SignalStrength(HOSTIF_MsgData_t *stMsgData)
This function provide an indicator of radio signal strength of the downlink from the access point to ...
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
hostIf_WiFi_EndPoint::set_Device_WiFi_EndPoint_Enable
int set_Device_WiFi_EndPoint_Enable(HOSTIF_MsgData_t *stMsgData)
Enables or disables this end point.
hostIf_WiFi_EndPoint::get_Device_WiFi_EndPoint_ProfileReference
int get_Device_WiFi_EndPoint_ProfileReference(HOSTIF_MsgData_t *stMsgData)
Set the alias name for the wireless endpoint.
hostIf_WiFi_EndPoint::get_Device_WiFi_EndPoint_Stats_LastDataDownlinkRate
int get_Device_WiFi_EndPoint_Stats_LastDataDownlinkRate(HOSTIF_MsgData_t *stMsgData)
Get the data transmit rate in kbps that was most recently used for transmission from the access point...
hostIf_WiFi_EndPoint::get_Device_WiFi_EndPoint_SSIDReference
int get_Device_WiFi_EndPoint_SSIDReference(HOSTIF_MsgData_t *stMsgData)
Check wethen wifi endpoint is enabled or not.
hostIf_WiFi_EndPoint::get_Device_WiFi_EndPoint_Status
int get_Device_WiFi_EndPoint_Status(HOSTIF_MsgData_t *stMsgData)
Get the status of the wireless end point.
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_EndPoint::get_Device_WiFi_EndPoint_Stats_Retransmissions
int get_Device_WiFi_EndPoint_Stats_Retransmissions(HOSTIF_MsgData_t *stMsgData)
Get the number of packets that had to be re-transmitted, from the last 100 packets sent to the access...