RDK Documentation (Open Sourced RDK Components)
Device_IP.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 /**
21  * @file Device_IP.cpp
22  * @brief This source file contains the APIs of device IP.
23  */
24 
25 /*****************************************************************************
26  * STANDARD INCLUDE FILES
27  *****************************************************************************/
28 
29 
30 
31 /**
32 * @defgroup tr69hostif
33 * @{
34 * @defgroup hostif
35 * @{
36 **/
37 
38 
39 #include "Device_IP.h"
40 #include <net/if.h>
41 #include <sys/types.h>
42 #include <ifaddrs.h>
43 #include "safec_lib.h"
44 
45 
46 IP hostIf_IP::stIPInstance = {TRUE,FALSE,{"Disabled"},FALSE,0,0};
47 
48 char* hostIf_IP::cmd_NumOfActivePorts = "cat /proc/net/tcp | awk '$4 == \"0A\" || $4 == \"01\" {print $2" "$3" "$4}' | wc -l";
49 
50 GMutex* hostIf_IP::m_mutex = NULL;
51 
52 GHashTable *hostIf_IP::ifHash = NULL;
53 
54 GHashTable* hostIf_IP::m_notifyHash = NULL;
55 
56 /**
57  * @brief Class Constructor of the class hostIf_IP.
58  *
59  * It will initialize the device id ,backup IP4 status to empty string.
60  *
61  * @param[in] dev_id Device identification number.
62  */
64  dev_id(dev_id),
65  bCalledIPv4Capable(false),
66  bCalledIPv4Enable(false),
67  bCalledIPv4Status(false),
68  bCalledInterfaceNumberOfEntries(false),
69  bCalledActivePortNumberOfEntries(false),
70  backupIPv4Capable(false),
71  backupIPv4Enable(false),
72  backupInterfaceNumberOfEntries(0),
73  backupActivePortNumberOfEntries(0)
74 {
75  backupIPv4Status[0]='\0';
76 }
77 
78 hostIf_IP* hostIf_IP::getInstance(int dev_id)
79 {
80  hostIf_IP* pRet = NULL;
81 
82  if(ifHash)
83  {
84  pRet = (hostIf_IP *)g_hash_table_lookup(ifHash,(gpointer) dev_id);
85  }
86  else
87  {
88  ifHash = g_hash_table_new(NULL,NULL);
89  }
90 
91  if(!pRet)
92  {
93  try {
94  pRet = new hostIf_IP(dev_id);
95  } catch(int e)
96  {
97  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create MoCA Interface instance..\n");
98  }
99  g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
100  }
101  return pRet;
102 }
103 
104 GList* hostIf_IP::getAllInstances()
105 {
106  if(ifHash)
107  return g_hash_table_get_keys(ifHash);
108  return NULL;
109 }
110 
111 void hostIf_IP::closeInstance(hostIf_IP *pDev)
112 {
113  if(pDev)
114  {
115  g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
116  delete pDev;
117  }
118 }
119 
120 void hostIf_IP::closeAllInstances()
121 {
122  if(ifHash)
123  {
124  GList* tmp_list = g_hash_table_get_values (ifHash);
125 
126  while(tmp_list)
127  {
128  hostIf_IP* pDev = (hostIf_IP *)tmp_list->data;
129  tmp_list = tmp_list->next;
130  closeInstance(pDev);
131  }
132  }
133 }
134 
135 void hostIf_IP::getLock()
136 {
137  if(!m_mutex)
138  {
139  m_mutex = g_mutex_new();
140  }
141  g_mutex_lock(m_mutex);
142 }
143 
144 void hostIf_IP::releaseLock()
145 {
146  g_mutex_unlock(m_mutex);
147 }
148 
149 GHashTable* hostIf_IP::getNotifyHash()
150 {
151  if(m_notifyHash)
152  {
153  return m_notifyHash;
154  }
155  else
156  {
157  return m_notifyHash = g_hash_table_new(g_str_hash, g_str_equal);
158  }
159 }
160 
161 hostIf_IP::~hostIf_IP()
162 {
163  if(m_notifyHash)
164  {
165  g_hash_table_destroy(m_notifyHash);
166  }
167 }
168 
169 /**
170  * This function's interface is just like that of the Linux API "if_indextoname" except that
171  * virtual interfaces are also reported.
172  *
173  * Maps an interface index to its corresponding name. The returned name is placed in the buffer
174  * pointed to by if_name, which must be at least IFNAMSIZ bytes in length. If the index was invalid,
175  * the function's return value is a null pointer, otherwise it is if_name.
176  *
177  * Example mapping below. All virtual interface indexes are greater than physical interface indexes.
178  * 1 - lo
179  * 2 - eth1
180  * 3 - sit0
181  * 4 - eth1:0
182  */
183 char* hostIf_IP::getInterfaceName (int if_index, char* if_name)
184 {
185  char* ret;
186  if ((ret = if_indextoname (if_index, if_name)) == NULL)
187  {
188  // check for virtual interfaces also
189  struct if_nameindex* phy_if_list = if_nameindex ();
190  if (phy_if_list == NULL)
191  {
192  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s(): if_nameindex Error\n", __FUNCTION__);
193  return NULL;
194  }
195 
196  int phy_if_count = getPhysicalInterfaceNumberOfEntries (phy_if_list);
197  if (if_index > phy_if_count)
198  {
199  ret = getVirtualInterfaceName (phy_if_list, if_index - phy_if_count, if_name);
200  }
201 
202  if_freenameindex (phy_if_list);
203  }
204 
205  RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "%s: if_index = %d, if_name = %s\n", __FUNCTION__, if_index, if_name);
206 
207  return ret;
208 }
209 
210 /** Description: Counts the number of IP
211  * interfaces present in the device.
212  *
213  * \Return: Count value or '0' if error
214  *
215  */
217 {
218  struct if_nameindex* phy_if_list = if_nameindex ();
219  if (phy_if_list == NULL)
220  {
221  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s(): if_nameindex Error\n", __FUNCTION__);
222  return 0;
223  }
224 
225  unsigned int if_count = 0;
226  if_count += getPhysicalInterfaceNumberOfEntries (phy_if_list);
227  if_count += getVirtualInterfaceNumberOfEntries (phy_if_list);
228 
229  if_freenameindex (phy_if_list);
230 
231  RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "%s: if_count = [%u]\n", __FUNCTION__, if_count);
232 
233  return if_count;
234 }
235 
236 unsigned int hostIf_IP::getPhysicalInterfaceNumberOfEntries (struct if_nameindex* phy_if_list)
237 {
238  unsigned int phy_if_count = 0;
239 
240  for (struct if_nameindex* phy_if = phy_if_list; phy_if->if_index != 0; phy_if++)
241  {
242  phy_if_count++;
243  }
244 
245  RDK_LOG (RDK_LOG_TRACE1, LOG_TR69HOSTIF, "%s: phy_if_count = [%u]\n", __FUNCTION__, phy_if_count);
246 
247  return phy_if_count;
248 }
249 
250 /**
251  * Returns the number of virtual interfaces on the system.
252  * Requires the list of physical interfaces as input.
253  */
254 unsigned int hostIf_IP::getVirtualInterfaceNumberOfEntries (struct if_nameindex* phy_if_list)
255 {
256  struct ifaddrs *ifa;
257  if (getifaddrs (&ifa))
258  {
259  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: getifaddrs returned error\n", __FUNCTION__);
260  return 0;
261  }
262 
263  int virtual_if_count = 0;
264  char *p, *v;
265  for (struct ifaddrs *ifa_node = ifa; ifa_node; ifa_node = ifa_node->ifa_next)
266  {
267  if (ifa_node->ifa_addr->sa_family == AF_INET) // virtual interfaces are IPv4-specific, so use IPv4 address family to hunt for them.
268  {
269  for (struct if_nameindex *phy_if = phy_if_list; phy_if->if_index != 0; phy_if++)
270  {
271  for (v = ifa_node->ifa_name, p = phy_if->if_name; *v == *p && *p; v++, p++)
272  ;
273 
274  if (*v == *p) // ifa_node->ifa_name matches exactly with this physical interface
275  break; // no need to try matching this ifa_node->ifa_name further
276 
277  if (*v == ':') // ifa_node->ifa_name could be a virtual interface, so check
278  {
279  char *tailPtr;
280  long int value = (int) strtol (++v, &tailPtr, 10);
281  if (*tailPtr == 0 && value >= 0) // string after ':' is an unsigned integer, virtual interface identified!
282  {
283  virtual_if_count++;
284  break; // no need to try matching this ifa_node->ifa_name further
285  }
286  }
287  }
288  }
289  }
290 
291  freeifaddrs (ifa);
292 
293  RDK_LOG (RDK_LOG_TRACE1, LOG_TR69HOSTIF, "%s: virtual_if_count = [%u]\n", __FUNCTION__, virtual_if_count);
294 
295  return virtual_if_count;
296 }
297 
298 /**
299  * Returns the virtual interface name corresponding to a virtual interface index.
300  * Requires the list of physical interfaces and the virtualInterfaceIndex as input.
301  * where virtualInterfaceIndex 1 refers to the first virtual interface returned by
302  * the kernel in the output from 'getifaddrs'.
303  */
304 char* hostIf_IP::getVirtualInterfaceName (struct if_nameindex *phy_if_list, unsigned int virtual_if_index, char* virtual_if_name)
305 {
306  char* ret = NULL;
307 
308  struct ifaddrs *ifa;
309  if (getifaddrs (&ifa))
310  return ret;
311 
312  int virtual_if_count = 0;
313  char *p, *v;
314  for (struct ifaddrs *ifa_node = ifa; ifa_node; ifa_node = ifa_node->ifa_next)
315  {
316  if (ifa_node->ifa_addr->sa_family == AF_INET) // virtual interfaces are IPv4-specific, so use IPv4 address family to hunt for them.
317  {
318  for (struct if_nameindex *phy_if = phy_if_list; phy_if->if_index != 0; phy_if++)
319  {
320  for (v = ifa_node->ifa_name, p = phy_if->if_name; *v == *p && *p; v++, p++)
321  ;
322 
323  if (*v == *p) // ifa_node->ifa_name matches exactly with this physical interface
324  break; // no need to try matching ifa_node->ifa_name further
325 
326  if (*v == ':') // ifa_node->ifa_name could be a virtual interface, so check
327  {
328  char *tailPtr;
329  long int value = (int) strtol (++v, &tailPtr, 10);
330  if (*tailPtr == 0 && value >= 0) // string after ':' is an unsigned integer, virtual interface identified!
331  {
332  if (++virtual_if_count == virtual_if_index)
333  {
334  errno_t rc = -1;
335  rc=strcpy_s (virtual_if_name,IF_NAMESIZE, ifa_node->ifa_name);
336  if(rc!=EOK)
337  {
338  ERR_CHK(rc);
339  }
340  ret = virtual_if_name;
341  goto freeResources; // we have found the virtualInterfaceName no need to try any matching ifa_node->ifa_name further
342  }
343  }
344  }
345  }
346  }
347  }
348 
349 freeResources:
350  freeifaddrs (ifa);
351 
352  RDK_LOG (RDK_LOG_TRACE1, LOG_TR69HOSTIF, "[%s(),%d] virtual_if_index = %u, virtual_if_name = %s\n",
353  __FUNCTION__, __LINE__, virtual_if_index, virtual_if_name);
354 
355  return ret;
356 }
357 
358 /** Description: Counts the number of tcp sockets in the device
359  * in listening or established state.
360  *
361  * \Return: Count value or '0' if error
362  *
363  */
364 unsigned int hostIf_IP::getNumOfActivePorts(void) {
365 
366  FILE *fp = NULL;
367  char resultBuff[BUFF_LENGTH] = {'\0'};
368  int noOfActivePorts = 0;
369 
370  fp = popen(cmd_NumOfActivePorts,"r");
371 
372  if(fp == NULL)
373  {
374  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s(): Error popen\n", __FUNCTION__);
375  return 0;
376  }
377 
378  if(fgets(resultBuff, BUFF_LENGTH, fp)!=NULL)
379  {
380  sscanf(resultBuff,"%d",&noOfActivePorts);
381  }
382 
383  pclose(fp);
384 
385  //RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s: Current Active Ports Count: [%u]\n", __FUNCTION__, noOfActivePorts);
386 
387  return (noOfActivePorts);
388 }
389 
390 
391 int hostIf_IP::get_Device_IP_Fields(EIPMembers ipMem)
392 {
393  FILE *fp = NULL;
394  struct if_nameindex *ifname, *ifnp;
395  unsigned int ipInterfaceCount = 0;
396  char resultBuff[BUFF_LENGTH] = {'\0'};
397  char command[BUFF_LENGTH] = {'\0'};
398  int ipv4AddressAvailable = 0;
399  errno_t rc = -1;
400 
401 
402  switch(ipMem)
403  {
404  case eIpIPv4Capable:
405  /*the assumption is that we are always IPv4 capable*/
406  /*HARD CODING it to 1*/
407  stIPInstance.iPv4Capable = TRUE;
408  break;
409  case eIpIPv4Enable:
410  case eIpIPv4Status:
411  sprintf(command,"ifconfig | egrep 'inet addr:' | wc -l");
412 
413  fp = popen(command,"r");
414 
415  if(fp == NULL)
416  {
417  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s(): Error in popen eIPv4Enable\n", __FUNCTION__);
418 
419  return NOK;
420  }
421 
422  if(fgets(resultBuff,BUFF_LENGTH,fp)!=NULL)
423  {
424  sscanf(resultBuff,"%d",&ipv4AddressAvailable);
425  }
426 
427  /*If there are no IPV4 address available, then assume that IPv4 has been disabled.*/
428  if(0 == ipv4AddressAvailable)
429  {
430  stIPInstance.iPv4Enable = FALSE;
431  rc=strcpy_s(stIPInstance.iPv4Status,sizeof(stIPInstance.iPv4Status),"Disabled");
432  if(rc!=EOK)
433  {
434  ERR_CHK(rc);
435  }
436  //RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): stIPInstance.iPv4Enable = %d,stIPInstance.iPv4Status = %s\n",__FUNCTION__,stIPInstance.iPv4Enable,stIPInstance.iPv4Status);
437  }
438  else
439  {
440  stIPInstance.iPv4Enable = TRUE;
441  rc=strcpy_s(stIPInstance.iPv4Status,sizeof(stIPInstance.iPv4Status),"Enabled");
442  if(rc!=EOK)
443  {
444  ERR_CHK(rc);
445  }
446  //RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): stIPInstance.iPv4Enable = %d,stIPInstance.iPv4Status = %s\n",__FUNCTION__,stIPInstance.iPv4Enable,stIPInstance.iPv4Status);
447  }
448 
449  pclose(fp);
450  break;
451  case eIpULAPrefix:
452  break;
453  case eIpInterfaceNumberOfEntries:
454  //retrieve the current interfaces
455  stIPInstance.interfaceNumberOfEntries = getInterfaceNumberOfEntries();
456 
457  //RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): InterfaceNumberOfEntries %u \n",__FUNCTION__,stIPInstance.interfaceNumberOfEntries);
458  break;
459 
460  case eIpActivePortNumberOfEntries:
461  stIPInstance.activePortNumberOfEntries = getNumOfActivePorts();
462  //RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): ActivePortsNumberOfEntries %u \n",__FUNCTION__,stIPInstance.activePortNumberOfEntries);
463  break;
464 
465  default:
466  break;
467  }
468 
469  return 0;
470 }
471 
472 int hostIf_IP::handleGetMsg (HOSTIF_MsgData_t* stMsgData)
473 {
474  int ret = NOT_HANDLED;
475 
476  if (!strcasecmp (stMsgData->paramName, "Device.IP.IPv4Capable"))
477  {
478  ret = get_Device_IP_IPv4Capable (stMsgData);
479  }
480  else if (!strcasecmp (stMsgData->paramName, "Device.IP.IPv4Enable"))
481  {
482  ret = get_Device_IP_IPv4Enable (stMsgData);
483  }
484  else if (!strcasecmp (stMsgData->paramName, "Device.IP.IPv4Status"))
485  {
486  ret = get_Device_IP_IPv4Status (stMsgData);
487  }
488  else if (!strcasecmp (stMsgData->paramName, "Device.IP.ULAPrefix"))
489  {
490  ret = get_Device_IP_ULAPrefix (stMsgData);
491  }
492  else if (!strcasecmp (stMsgData->paramName, "Device.IP.InterfaceNumberOfEntries"))
493  {
495  }
496  else if (!strcasecmp (stMsgData->paramName, "Device.IP.ActivePortNumberOfEntries"))
497  {
499  }
500  else
501  {
502  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%d]Device.IP: Parameter \'%s\' is Not Supported \n", __FUNCTION__, __LINE__, stMsgData->paramName);
503  stMsgData->faultCode = fcInvalidParameterName;
504  ret = NOK;
505  }
506 
507  return ret;
508 }
509 
510 int hostIf_IP::handleSetMsg (HOSTIF_MsgData_t* stMsgData)
511 {
512  int ret = NOT_HANDLED;
513 
514  if (!strcasecmp (stMsgData->paramName, "Device.IP.IPv4Enable"))
515  {
516  ret = set_Device_IP_IPv4Enable (stMsgData);
517  }
518  else
519  {
520  stMsgData->faultCode = fcInvalidParameterName;
521  ret = NOT_HANDLED;
522  }
523  return ret;
524 }
525 
526 /****************************************************************************************************************************************************/
527 // Device.IP. Profile. Getters:
528 /****************************************************************************************************************************************************/
529 
530 /**
531  * @brief This function gets the IPv4 capability of a device. It indicates
532  * whether or not the device is IPv4 capable. 'true' if it is capable, 'false' if it
533  * is not capable.
534  *
535  * @param[out] stMsgData TR-069 Host interface message request.
536  * @param[in] pChanged Status of the operation.
537  *
538  * @returns Returns '0' if the method successfully get the capability of IPv4 interface else
539  * returns '-1'.
540  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_API
541  */
543 {
544 
545  get_Device_IP_Fields(eIpIPv4Capable);
546  if(bCalledIPv4Capable && pChanged && (backupIPv4Capable != stIPInstance.iPv4Capable))
547  {
548  *pChanged = true;
549  }
550  bCalledIPv4Capable = true;
551  backupIPv4Capable = stIPInstance.iPv4Capable;
552  put_int(stMsgData->paramValue,stIPInstance.iPv4Capable);
553  stMsgData->paramtype = hostIf_BooleanType;
554  stMsgData->paramLen = 1;
555 
556  return OK;
557 }
558 
559 /**
560  * @brief Get the status of the IPv4 stack on a device. This function provides the status
561  * 'enabled' or 'disabled' of the IPv4 stack, and the use of IPv4 on the device. This affects
562  * only layer 3 and above.
563  *
564  * @param[out] stMsgData TR-069 Host interface message request.
565  * @param[in] pChanged Status of the operation.
566  *
567  * @returns Returns '0' if the method successfully get the device IPv4 enable else returns '-1'.
568  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_API
569  */
571 {
572 
573  get_Device_IP_Fields(eIpIPv4Enable);
574  if(bCalledIPv4Enable && pChanged && (backupIPv4Enable != stIPInstance.iPv4Enable))
575  {
576  *pChanged = true;
577  }
578  bCalledIPv4Enable = true;
579  backupIPv4Enable = stIPInstance.iPv4Enable;
580  put_int(stMsgData->paramValue,stIPInstance.iPv4Enable);
581  stMsgData->paramtype = hostIf_BooleanType;
582  stMsgData->paramLen = 1;
583 
584  return OK;
585 }
586 
587 /**
588  * @brief This function gets the status of the IPv4 stack on a device. It indicates the status of the IPv4 stack.
589  * It is an enumeration of: Disabled, Enabled, Error (OPTIONAL).
590  *
591  * @note The Error value MAY be used by the CPE to indicate a locally defined error condition.
592  *
593  * @param[out] stMsgData TR-069 Host interface message request.
594  * @param[in] pChanged Status of the operation.
595  *
596  * @returns Returns '0' if the method successfully get the device IPv4 status else returns '-1'.
597  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_API
598  */
600 {
601 
602  get_Device_IP_Fields(eIpIPv4Status);
603  if(bCalledIPv4Status && pChanged && strncmp(stIPInstance.iPv4Status, backupIPv4Status,_BUF_LEN_16 ))
604  {
605  *pChanged = true;
606  }
607  bCalledIPv4Status = true;
608  strncpy(stMsgData->paramValue,stIPInstance.iPv4Status,TR69HOSTIFMGR_MAX_PARAM_LEN );
609  strncpy(backupIPv4Status,stIPInstance.iPv4Status,sizeof(backupIPv4Status) -1); //CID:136557 - Buffer size warning
610  backupIPv4Status[sizeof(backupIPv4Status) -1] = '\0';
611  stMsgData->paramtype = hostIf_StringType;
612  stMsgData->paramLen = strlen(stIPInstance.iPv4Status);
613 
614  return OK;
615 }
616 
617 /**
618  * @brief Get the ULA(Unique Local Address)/48 prefix for a device. This function provides the
619  * ULA /48 prefix of the device. This is the IPv6 address prefix and can be any IPv6 prefix that
620  * is permitted by the IPPrefix data type. Currently not implemented.
621  *
622  * @note This is specified as an IP address followed by an appended "/n" suffix, where n
623  * (the prefix size) is an integer in the range 0-32 (for IPv4) or 0-128 (for IPv6) that
624  * indicates the number of (leftmost) '1' bits of the routing prefix.
625  * - IPv4 example: 192.168.1.0/24
626  * - IPv6 example: 2001:edff:fe6a:f76::/64
627  *
628  * @param[out] stMsgData TR-069 Host interface message request.
629  * @param[in] pChanged Status of the operation.
630  *
631  * @returns Returns '0' if the method successfully get the device IP ULA Prefix else returns '-1'.
632  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_API
633  */
635 {
636  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s()] Parameter Not Supported \n",__FUNCTION__);
637 
638  return NOK;
639 }
640 
642 {
643 
644  hostIf_IP::get_Device_IP_Fields(eIpInterfaceNumberOfEntries);
645  put_int(stMsgData->paramValue,stIPInstance.interfaceNumberOfEntries);
646  stMsgData->paramtype = hostIf_UnsignedIntType;
647  stMsgData->paramLen = 4;
648 
649  return OK;
650 }
651 
653 {
654 
655  get_Device_IP_Fields(eIpActivePortNumberOfEntries);
656  put_int(stMsgData->paramValue,stIPInstance.activePortNumberOfEntries);
657  stMsgData->paramtype = hostIf_UnsignedIntType;
658  stMsgData->paramLen = 4;
659 
660  return OK;
661 }
662 
663 
664 
665 
666 /****************************************************************************************************************************************************/
667 // Device.IP. Profile. Setters:
668 /****************************************************************************************************************************************************/
669 
670 
671 /**
672  * @brief This function sets the status to 'enabled' or 'disabled' of the IPv4 stack
673  * on a device. This affects only layer 3 and above.
674  *
675  * @note When 'false', IP interfaces that had been operationally up and
676  * passing IPv4 packets will now no longer be able to do so, and will be
677  * operationally down (unless also attached to an enabled IPv6 stack).
678  *
679  * @param[out] stMsgData TR-069 Host interface message request.
680  * @param[in] pChanged Status of the operation.
681  *
682  * @returns Returns '0' if the method successfully set the device IPv4 enable else returns '-1'.
683  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_API
684  */
686 {
687  char command[BUFF_LENGTH]= {'\0'};
688  errno_t rc = -1;
689 
690  if(get_int(stMsgData->paramValue) == 1)
691  {
692  rc=strcpy_s(command,sizeof(command),"ifup -a");
693  if(rc!=EOK)
694  {
695  ERR_CHK(rc);
696  }
697  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s()] Enabled \n",__FUNCTION__);
698 
699  }
700  else if(get_int(stMsgData->paramValue) == 0)
701  {
702  rc=strcpy_s(command,sizeof(command),"ifdown -a");
703  if(rc!=EOK)
704  {
705  ERR_CHK(rc);
706  }
707  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s()] Disabled \n",__FUNCTION__);
708  }
709 
710  if(system(command) < 0)
711  return NOK;
712 
713  return OK;
714 }
715 
716 /**
717  * @brief This function sets the ULA /48 prefix of the device. This is the IPv6 address
718  * prefix and can be any IPv6 prefix that is permitted by the IPPrefix data type.
719  * Currently not implemented.
720  *
721  * @note This is specified as an IP address followed by an appended "/n" suffix, where n
722  * (the prefix size) is an integer in the range 0-32 (for IPv4) or 0-128 (for IPv6) that
723  * indicates the number of (leftmost) '1' bits of the routing prefix.
724  * - IPv4 example: 192.168.1.0/24
725  * - IPv6 example: 2001:edff:fe6a:f76::/64
726  *
727  * @param[out] stMsgData TR-069 Host interface message request.
728  * @param[in] pChanged Status of the operation.
729  *
730  * @returns Returns '0' if the method successfully set the device IP ULA prefix else returns '-1'.
731  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_API
732  */
734 {
735  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s()] Parameter Not Supported \n",__FUNCTION__);
736 
737  return NOK;
738 }
739 
740 
741 /** @} */
742 /** @} */
hostIf_IP::set_Device_IP_IPv4Enable
int set_Device_IP_IPv4Enable(HOSTIF_MsgData_t *)
Set the status (enabled/disabled) of the IPv4 stack on a device.
Definition: Device_IP.cpp:685
hostIf_IP::get_Device_IP_ULAPrefix
int get_Device_IP_ULAPrefix(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the ULA(Unique Local Address)/48 prefix for a device. This function provides the ULA /48 prefix o...
Definition: Device_IP.cpp:634
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
hostIf_IP::getNumOfActivePorts
static unsigned int getNumOfActivePorts(void)
Definition: Device_IP.cpp:364
hostIf_IP::set_Device_IP_ULAPrefix
int set_Device_IP_ULAPrefix(HOSTIF_MsgData_t *)
This function sets the ULA /48 prefix of the device. This is the IPv6 address prefix and can be any I...
Definition: Device_IP.cpp:733
hostIf_IP
This class provides the hostIf IP interface for getting IP interface information.
Definition: Device_IP.h:162
hostIf_IP::get_Device_IP_InterfaceNumberOfEntries
static int get_Device_IP_InterfaceNumberOfEntries(HOSTIF_MsgData_t *)
Get the number of entries in the Interface table.
Definition: Device_IP.cpp:641
hostIf_IP::hostIf_IP
hostIf_IP(int dev_id)
Class Constructor of the class hostIf_IP.
Definition: Device_IP.cpp:63
Device_IP
It contains the members variables of the IP structure.
Definition: Device_IP.h:110
hostIf_IP::getInterfaceNumberOfEntries
static unsigned int getInterfaceNumberOfEntries(void)
Definition: Device_IP.cpp:216
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
hostIf_IP::getInterfaceName
static char * getInterfaceName(int if_index, char *if_name)
Definition: Device_IP.cpp:183
hostIf_IP::get_Device_IP_IPv4Capable
int get_Device_IP_IPv4Capable(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the IPv4 capability of a device.
Definition: Device_IP.cpp:542
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_IP::get_Device_IP_IPv4Enable
int get_Device_IP_IPv4Enable(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the status (enabled/disabled) of the IPv4 stack on a device.
Definition: Device_IP.cpp:570
hostIf_IP::getVirtualInterfaceNumberOfEntries
static unsigned int getVirtualInterfaceNumberOfEntries(struct if_nameindex *phy_if_list)
Definition: Device_IP.cpp:254
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
Device_IP.h
The header file provides TR069 device IP information APIs.
hostIf_IP::getVirtualInterfaceName
static char * getVirtualInterfaceName(struct if_nameindex *phy_if_list, unsigned int virtual_if_index, char *virtual_if_name)
Definition: Device_IP.cpp:304
EIPMembers
EIPMembers
These values are the members of the EIPMembers.
Definition: Device_IP.h:96
hostIf_IP::get_Device_IP_ActivePortNumberOfEntries
static int get_Device_IP_ActivePortNumberOfEntries(HOSTIF_MsgData_t *)
Get the number of entries in the ActivePort table.
Definition: Device_IP.cpp:652
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152
hostIf_IP::get_Device_IP_IPv4Status
int get_Device_IP_IPv4Status(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function gets the status of the IPv4 stack on a device. It indicates the status of the IPv4 stac...
Definition: Device_IP.cpp:599
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199
_HostIf_MsgData_t::paramLen
short paramLen
Definition: hostIf_tr69ReqHandler.h:175