RDK Documentation (Open Sourced RDK Components)
hostIf_InterfaceStackClient_ReqHandler.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 2016 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  * @brief Provides implementation for DHCPv4 Client Request Handler Interface
21  *
22  * @author vejuturu@cisco.com
23  */
24 
25 /**
26  * @file hostIf_InterfaceStackClient_ReqHandler.cpp
27  * @brief The header file provides HostIf InterfaceStack client request handler information APIs.
28  */
29 //#define HAVE_VALUE_CHANGE_EVENT
30 #include "hostIf_main.h"
31 #include "hostIf_utils.h"
32 #include "Device_InterfaceStack.h"
34 #include "safec_lib.h"
35 
36 InterfaceStackClientReqHandler* InterfaceStackClientReqHandler::pInstance = NULL;
37 
38 updateCallback InterfaceStackClientReqHandler::mUpdateCallback = NULL;
39 int InterfaceStackClientReqHandler::curNumOfEntriesInInterfaceStack = 0;
40 
41 msgHandler* InterfaceStackClientReqHandler::getInstance()
42 {
43  hostif_InterfaceStack::getLock();
44  if(!pInstance)
45  pInstance = new InterfaceStackClientReqHandler();
46  hostif_InterfaceStack::releaseLock();
47  return pInstance;
48 }
49 
50 void InterfaceStackClientReqHandler::reset()
51 {
52  hostif_InterfaceStack::getLock();
53  curNumOfEntriesInInterfaceStack = 0;
54  hostif_InterfaceStack::releaseLock();
55 }
56 
57 /**
58  * @brief This function is used to initialize. Currently not implemented.
59  *
60  * @return Returns the status of the operation.
61  *
62  * @retval true if initialization is successful.
63  * @retval false if initialization is not successful.
64  * @ingroup TR-069HOSTIF_INTERFACESTACKCLIENT_REQHANDLER_CLASSES
65  */
67 {
68  return true;
69 }
70 
71 /**
72  * @brief This function is used to close all the instances of interface stack.
73  *
74  * @return Returns the status of the operation.
75  *
76  * @retval true if it successfully close all the instances.
77  * @retval false if not able to close all the instances.
78  * @ingroup TR-069HOSTIF_INTERFACESTACKCLIENT_REQHANDLER_CLASSES
79  */
81 {
82  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s()] Interface Stack manager DeInitializing\n", __FUNCTION__);
83  hostif_InterfaceStack::closeAllInstances();
84 
85  return true;
86 }
87 
88 
89 /**
90  * @brief This function is used to handle the set message request of InterfaceStack Client.
91  * Currently not implemented.
92  *
93  * @param[out] stMsgData TR-069 Host interface message request.
94  *
95  * @return Returns the status of the operation.
96  *
97  * @retval OK if successful.
98  * @retval ERR_INTERNAL_ERROR if not able to set the data to the device.
99  * @ingroup TR-069HOSTIF_INTERFACESTACKCLIENT_REQHANDLER_CLASSES
100  */
102 {
103  int ret = NOT_HANDLED;
104 
105  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Found string as %s. Set command not supported.\n",
106  __FUNCTION__, __FILE__, stMsgData->paramName);
107  stMsgData->faultCode = fcAttemptToSetaNonWritableParameter;
108  return ret;
109 }
110 
111 /**
112  * @brief This function is used to handle the get message request of InterfaceStack Client.
113  * Gets the total number of active interface stack entries or get the attributes of
114  * interface stack such as "HigherLayer" and "LowerLayer".
115  *
116  * @param[out] stMsgData TR-069 Host interface message request.
117  *
118  * @return Returns the status of the operation.
119  *
120  * @retval OK if successful.
121  * @retval ERR_INTERNAL_ERROR if not able to set the data to the device.
122  * @ingroup TR-069HOSTIF_INTERFACESTACKCLIENT_REQHANDLER_CLASSES
123  */
125 {
126  int ret = NOT_HANDLED;
127  const char *pSetting;
128  int instanceNumber = 0;
129  hostif_InterfaceStack::getLock();
130 
131  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s:%d] Found string as %s\n", __FUNCTION__, __FILE__, __LINE__, stMsgData->paramName);
132  if(strcasecmp(stMsgData->paramName, "Device.InterfaceStackNumberOfEntries") == 0)
133  {
134  ret = hostif_InterfaceStack::get_Device_InterfaceStackNumberOfEntries(stMsgData);
135  }
136  else if(matchComponent(stMsgData->paramName,"Device.InterfaceStack",&pSetting,instanceNumber))
137  {
138  hostif_InterfaceStack *pInterfaceStack = hostif_InterfaceStack::getInstance(instanceNumber);
139  stMsgData->instanceNum = instanceNumber;
140  if(pInterfaceStack)
141  {
142  if(strcasecmp(pSetting,"HigherLayer") == 0)
143  {
144  ret = pInterfaceStack->get_Device_InterfaceStack_HigherLayer(stMsgData);
145  }
146  else if(strcasecmp(pSetting,"LowerLayer") == 0)
147  {
148  ret = pInterfaceStack->get_Device_InterfaceStack_LowerLayer(stMsgData);
149  }
150  else
151  {
152  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%d] Parameter : \'%s\' is Not Supported \n", __FUNCTION__, __LINE__, stMsgData->paramName);
153  stMsgData->faultCode = fcInvalidParameterName;
154  ret = NOK;
155  }
156  }
157  else
158  {
159  ret = NOK;
160  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%s:%d] hostif_InterfaceStack::getInstance() returned NULL for instance %d",
161  __FUNCTION__, __FILE__, __LINE__, instanceNumber);
162  }
163  }
164 
165  hostif_InterfaceStack::releaseLock();
166  return ret;
167 }
168 int InterfaceStackClientReqHandler::handleGetAttributesMsg(HOSTIF_MsgData_t *stMsgData)
169 {
170  int ret = NOT_HANDLED;
171  int instanceNumber = 0;
172 
173  hostif_InterfaceStack::getLock();
174  hostif_InterfaceStack *pIface = hostif_InterfaceStack::getInstance(instanceNumber);
175  stMsgData->instanceNum = instanceNumber;
176  if(!pIface)
177  {
178  hostif_InterfaceStack::releaseLock();
179  return NOK;
180  }
181 
182  GHashTable* notifyhash = pIface->getNotifyHash();
183  if(notifyhash != NULL)
184  {
185  int* notifyvalue = (int*) g_hash_table_lookup(notifyhash,stMsgData->paramName);
186  put_int(stMsgData->paramValue, *notifyvalue);
187  stMsgData->paramtype = hostIf_IntegerType;
188  ret = OK;
189  }
190  else
191  {
192  ret = NOK;
193  }
194  hostif_InterfaceStack::releaseLock();
195  return ret;
196 }
197 
198 int InterfaceStackClientReqHandler::handleSetAttributesMsg(HOSTIF_MsgData_t *stMsgData)
199 {
200  int ret = NOT_HANDLED;
201  int instanceNumber = 0;
202 
203  hostif_InterfaceStack::getLock();
204  hostif_InterfaceStack *pIface = hostif_InterfaceStack::getInstance(instanceNumber);
205  stMsgData->instanceNum = instanceNumber;
206  if(!pIface)
207  {
208  hostif_InterfaceStack::releaseLock();
209  return NOK;
210  }
211  GHashTable* notifyhash = pIface->getNotifyHash();
212  if(notifyhash != NULL)
213  {
214  int *notifyValuePtr;
215  notifyValuePtr = (int*) malloc(1 * sizeof(int));
216 
217  // Inserting Notification parameter to Notify Hash Table,
218  // Note that neither keys nor values are copied when inserted into the GHashTable, so they must exist for the lifetime of the GHashTable
219  // There for allocating a memory for both Param name and param value. This should be freed whenever we disable Notification.
220  char *notifyKey = NULL;
221  notifyKey = (char*) calloc(sizeof(char),strlen(stMsgData->paramName)+1);
222  if((NULL != notifyValuePtr) && (NULL != notifyValuePtr))
223  {
224  *notifyValuePtr = 1;
225  errno_t rc = -1;
226  rc=strcpy_s(notifyKey,strlen(stMsgData->paramName)+1,stMsgData->paramName);
227  if(rc!=EOK)
228  {
229  ERR_CHK(rc);
230  }
231  g_hash_table_insert(notifyhash,notifyKey,notifyValuePtr);
232  ret = OK;
233  }
234  else
235  {
236  ret = NOK;
237  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s:%d] Not able to allocate Notify pointer %s\n", __FUNCTION__, __FILE__, __LINE__, stMsgData->paramName);
238  }
239  free(notifyKey); //CID:80730 - Resource leak
240  free(notifyValuePtr);
241  }
242  else
243  {
244  ret = NOK;
245  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s:%d] Not able to get notifyhash %s\n", __FUNCTION__, __FILE__, __LINE__, stMsgData->paramName);
246  }
247  hostif_InterfaceStack::releaseLock();
248  return ret;
249 }
250 
251 void InterfaceStackClientReqHandler::registerUpdateCallback(updateCallback cb)
252 {
253  mUpdateCallback = cb;
254 }
255 
256 void InterfaceStackClientReqHandler::checkForUpdates()
257 {
258  HOSTIF_MsgData_t msgData;
259  bool bChanged;
260  GList *elem;
261  int index = 1;
262  int instanceNumber;
263  GHashTable* notifyhash = NULL;
264  const char *pSetting;
265 
266  char tmp_buff[TR69HOSTIFMGR_MAX_PARAM_LEN];
267  hostif_InterfaceStack::getLock();
268 
269  memset(&msgData,0,sizeof(msgData));
270  memset(tmp_buff,0,TR69HOSTIFMGR_MAX_PARAM_LEN);
271  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FILE__, __FUNCTION__);
272 
273 
274  if(hostif_InterfaceStack::get_Device_InterfaceStackNumberOfEntries(&msgData) == OK)
275  {
276  int tmpNoDev = get_int(msgData.paramValue);
277  char tmp[TR69HOSTIFMGR_MAX_PARAM_LEN] = "";
278  snprintf(tmp_buff, sizeof(tmp_buff), "Device.InterfaceStack");
279  while(curNumOfEntriesInInterfaceStack > tmpNoDev)
280  {
281  snprintf(tmp, sizeof(tmp), "%s.%d.", tmp_buff, tmpNoDev);
282  if(mUpdateCallback) mUpdateCallback(IARM_BUS_TR69HOSTIFMGR_EVENT_REMOVE, tmp, NULL, hostIf_IntegerType);
283  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] InterfaceStack Removed Event..\n", __FILE__, __FUNCTION__);
284 
285  tmpNoDev++;
286  }
287  while(curNumOfEntriesInInterfaceStack < tmpNoDev)
288  {
289  snprintf(tmp, sizeof(tmp), "%s.", tmp_buff);
290  if(mUpdateCallback) mUpdateCallback(IARM_BUS_TR69HOSTIFMGR_EVENT_ADD,tmp, NULL, hostIf_IntegerType);
291  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] InterfaceStack Added Event..\n", __FILE__, __FUNCTION__);
292 
293  tmpNoDev--;
294  }
295  curNumOfEntriesInInterfaceStack = get_int(msgData.paramValue);
296  }
297 
298 #ifdef HAVE_VALUE_CHANGE_EVENT
299 
300  instanceNumber = 0;
301  hostif_InterfaceStack *pInterfaceStackClient = hostif_InterfaceStack::getInstance(instanceNumber);
302  if(NULL != pInterfaceStackClient)
303  {
304  notifyhash = pInterfaceStackClient->getNotifyHash();
305  }
306  // Iterate through Ghash Table
307  if(NULL != notifyhash)
308  {
309  GHashTableIter notifyHashIterator;
310  gpointer paramName;
311  gpointer notifyEnable;
312  bool bChanged;
313 
314  g_hash_table_iter_init (&notifyHashIterator, notifyhash);
315  while (g_hash_table_iter_next (&notifyHashIterator, &paramName, &notifyEnable))
316  {
317  int* isNotifyEnabled = (int *)notifyEnable;
318  instanceNumber = 0;
319  if(matchComponent((const char*)paramName,"Device.InterfaceStack.",&pSetting,instanceNumber))
320  {
321  hostif_InterfaceStack *pIface = hostif_InterfaceStack::getInstance(instanceNumber);
322  if(pIface)
323  {
324  if (strcasecmp(pSetting,"HigherLayer") == 0)
325  {
326  memset(&msgData,0,sizeof(msgData));
327  bChanged = false;
328  pIface->get_Device_InterfaceStack_HigherLayer(&msgData,&bChanged);
329  if(bChanged)
330  {
331  if(mUpdateCallback && (*isNotifyEnabled == 1))
332  {
333  mUpdateCallback(IARM_BUS_TR69HOSTIFMGR_EVENT_VALUECHANGED,(const char*)paramName, msgData.paramValue, msgData.paramtype);
334  }
335  }
336  }
337  if (strcasecmp(pSetting,"LowerLayer") == 0)
338  {
339  memset(&msgData,0,sizeof(msgData));
340  bChanged = false;
341  pIface->get_Device_InterfaceStack_LowerLayer(&msgData,&bChanged);
342  if(bChanged)
343  {
344  if(mUpdateCallback && (*isNotifyEnabled == 1))
345  {
346  mUpdateCallback(IARM_BUS_TR69HOSTIFMGR_EVENT_VALUECHANGED,(const char*)paramName, msgData.paramValue, msgData.paramtype);
347  }
348  }
349  }
350  }
351  }
352  }
353  }
354 #endif
355  hostif_InterfaceStack::releaseLock();
356 }
InterfaceStackClientReqHandler::handleSetMsg
virtual int handleSetMsg(HOSTIF_MsgData_t *stMsgData)
This function is used to handle the set message request of InterfaceStack Client. Currently not imple...
Definition: hostIf_InterfaceStackClient_ReqHandler.cpp:101
IARM_BUS_TR69HOSTIFMGR_EVENT_REMOVE
@ IARM_BUS_TR69HOSTIFMGR_EVENT_REMOVE
Definition: hostIf_tr69ReqHandler.h:188
_HostIf_MsgData_t::instanceNum
short instanceNum
Definition: hostIf_tr69ReqHandler.h:176
InterfaceStackClientReqHandler::handleGetMsg
virtual int handleGetMsg(HOSTIF_MsgData_t *stMsgData)
This function is used to handle the get message request of InterfaceStack Client. Gets the total numb...
Definition: hostIf_InterfaceStackClient_ReqHandler.cpp:124
Device_InterfaceStack.h
The header file provides TR069 device interface stack information APIs.
IARM_BUS_TR69HOSTIFMGR_EVENT_ADD
@ IARM_BUS_TR69HOSTIFMGR_EVENT_ADD
Definition: hostIf_tr69ReqHandler.h:187
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
hostIf_main.h
hostIf_main API.
InterfaceStackClientReqHandler
This class provides the interface for getting InterfaceStack client request handler information.
Definition: hostIf_InterfaceStackClient_ReqHandler.h:59
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
_HostIf_MsgData_t::faultCode
faultCode_t faultCode
Definition: hostIf_tr69ReqHandler.h:179
_HostIf_MsgData_t::paramName
char paramName[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:171
hostIf_InterfaceStackClient_ReqHandler.h
The header file provides HostIf InterfaceStack client request handler information APIs.
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
msgHandler
Definition: hostIf_msgHandler.h:103
InterfaceStackClientReqHandler::init
virtual bool init()
This function is used to initialize. Currently not implemented.
Definition: hostIf_InterfaceStackClient_ReqHandler.cpp:66
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152
IARM_BUS_TR69HOSTIFMGR_EVENT_VALUECHANGED
@ IARM_BUS_TR69HOSTIFMGR_EVENT_VALUECHANGED
Definition: hostIf_tr69ReqHandler.h:189
InterfaceStackClientReqHandler::unInit
virtual bool unInit()
This function is used to close all the instances of interface stack.
Definition: hostIf_InterfaceStackClient_ReqHandler.cpp:80