RDK Documentation (Open Sourced RDK Components)
Device_IP_Interface_IPv4Address.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_Interface_IPv4Address.cpp
22  * @brief This source file contains the APIs of device IPv4 interface address.
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 <sys/sysinfo.h>
40 #include <sys/ioctl.h>
41 #include <sys/socket.h>
42 #include <sys/types.h>
43 #include <ifaddrs.h>
44 #include <arpa/inet.h>
45 
48 #include "Device_IP_Interface.h"
49 #include "hostIf_utils.h"
50 #include "Device_IP.h"
51 #include "safec_lib.h"
52 
53 #ifdef YOCTO_BUILD
54 #include "secure_wrapper.h"
55 #endif
56 GMutex* hostIf_IPv4Address::m_mutex = NULL;
57 GHashTable *hostIf_IPv4Address::ifHash = NULL;
58 
59 int hostIf_IPv4Address::getIPv4AddressAndMask (int instance, struct in_addr& in_address, struct in_addr& in_mask)
60 {
61  LOG_ENTRY_EXIT;
62 
63  int rc = NOK;
64  struct ifaddrs *ifa;
65  if (getifaddrs (&ifa))
66  return rc;
67 
68  int current_instance = 0;
69  for (struct ifaddrs *ifa_node = ifa; ifa_node; ifa_node = ifa_node->ifa_next)
70  {
71  if (ifa_node->ifa_addr->sa_family == AF_INET && !strcmp (ifa_node->ifa_name, nameOfInterface) && (++current_instance == instance))
72  {
73  in_address = ((struct sockaddr_in *) ifa_node->ifa_addr)->sin_addr;
74  in_mask = ((struct sockaddr_in *) ifa_node->ifa_netmask)->sin_addr;
75  rc = OK;
76  break;
77  }
78  }
79 
80  freeifaddrs (ifa);
81 
82  RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s]: rc=%d, if=%s, instance=%d\n", __FUNCTION__, rc, nameOfInterface, instance);
83 
84  return rc;
85 }
86 
87 //Function to set the IP OR SubNetMask Address for the Interface
88 int hostIf_IPv4Address::setIpOrMask(int interfaceNo, char *value, const char* ipOrMask)
89 {
90  LOG_ENTRY_EXIT;
91 
92  if (0 != strcmp (value, ""))
93  {
94  if (0 == strcasecmp (backupAddressingType, "static"))
95  {
96 #ifdef YOCTO_BUILD
97  v_secure_system("ifconfig %s %s %s", nameOfInterface, ipOrMask, value);
98 #else
99  char cmd[BUFF_LENGTH] = { 0 };
100  sprintf (cmd, "ifconfig %s %s %s", nameOfInterface, ipOrMask, value);
101  system(cmd);
102 #endif
103  RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s(),%d] IPv4Address: IPAddress/SubnetMask is set \n", __FUNCTION__, __LINE__);
104  }
105  }
106  return OK;
107 }
108 
109 void hostIf_IPv4Address::refreshInterfaceName ()
110 {
111  nameOfInterface[0] = 0;
112  if (NULL == hostIf_IP::getInterfaceName (dev_id, nameOfInterface))
113  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: error getting interface name for Device.IP.Interface.%d\n", __FUNCTION__, dev_id);
114 }
115 
116 /**
117  * @brief Class Constructor of the class hostIf_IPv4Address.
118  *
119  * It will initialize the device id. Initialize the status, IP Address, SubnetMask and AddressingType to
120  * empty string.
121  *
122  * @param[in] devid Identification number of the device to communicate.
123  */
125  dev_id(dev_id),
126  bCalledEnable(0),
127  bCalledStatus(0),
128  bCalledIPAddress(0),
129  bCalledSubnetMask(0),
130  bCalledAddressingType(0),
131  backupEnable (false)
132 {
133  errno_t rc = -1;
134  backupStatus[0]='\0';
135  backupIPAddress[0]='\0';
136  backupSubnetMask[0]='\0';
137  rc=strcpy_s (backupAddressingType,sizeof(backupAddressingType), "Static");
138  if(rc!=EOK)
139  {
140  ERR_CHK(rc);
141  }
142 }
143 
144 hostIf_IPv4Address* hostIf_IPv4Address::getInstance(int dev_id)
145 {
146  LOG_ENTRY_EXIT;
147 
148  hostIf_IPv4Address* pRet = NULL;
149 
150  if(ifHash)
151  {
152  pRet = (hostIf_IPv4Address *)g_hash_table_lookup(ifHash,(gpointer) dev_id);
153  }
154  else
155  {
156  ifHash = g_hash_table_new(NULL,NULL);
157  }
158 
159  if(!pRet)
160  {
161  try {
162  pRet = new hostIf_IPv4Address(dev_id);
163  } catch(int e)
164  {
165  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create MoCA Interface instance..\n");
166  }
167  g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
168  }
169 
170  // make sure returned instance has interface name set
171  if (pRet)
172  pRet->refreshInterfaceName ();
173 
174  return pRet;
175 }
176 
177 GList* hostIf_IPv4Address::getAllInstances()
178 {
179  LOG_ENTRY_EXIT;
180 
181  if(ifHash)
182  return g_hash_table_get_keys(ifHash);
183  return NULL;
184 }
185 
186 void hostIf_IPv4Address::closeInstance(hostIf_IPv4Address *pDev)
187 {
188  LOG_ENTRY_EXIT;
189 
190  if(pDev)
191  {
192  g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
193  delete pDev;
194  }
195 }
196 
197 void hostIf_IPv4Address::closeAllInstances()
198 {
199  LOG_ENTRY_EXIT;
200 
201  if(ifHash)
202  {
203  GList* tmp_list = g_hash_table_get_values (ifHash);
204 
205  while(tmp_list)
206  {
207  hostIf_IPv4Address* pDev = (hostIf_IPv4Address *)tmp_list->data;
208  tmp_list = tmp_list->next;
209  closeInstance(pDev);
210  }
211  }
212 }
213 
214 void hostIf_IPv4Address::getLock()
215 {
216  if(!m_mutex)
217  {
218  m_mutex = g_mutex_new();
219  }
220  g_mutex_lock(m_mutex);
221 }
222 
223 void hostIf_IPv4Address::releaseLock()
224 {
225  g_mutex_unlock(m_mutex);
226 }
227 
228 int hostIf_IPv4Address::handleGetMsg (const char* pSubSetting, int subInstanceNumber, HOSTIF_MsgData_t* stMsgData)
229 {
230  LOG_ENTRY_EXIT;
231 
232  int ret = NOT_HANDLED;
233 
234  if (!strcasecmp (pSubSetting, "Enable"))
235  {
236  ret = get_IPv4Address_Enable (stMsgData, subInstanceNumber);
237  }
238  else if (!strcasecmp (pSubSetting, "Status"))
239  {
240  ret = get_IPv4Address_Status (stMsgData, subInstanceNumber);
241  }
242  else if (!strcasecmp (pSubSetting, "Alias"))
243  {
244  ret = get_IPv4Address_Alias (stMsgData, subInstanceNumber);
245  }
246  else if (!strcasecmp (pSubSetting, "SubnetMask"))
247  {
248  ret = get_IPv4Address_SubnetMask (stMsgData, subInstanceNumber);
249  }
250  else if (!strcasecmp (pSubSetting, "AddressingType"))
251  {
252  ret = get_IPv4Address_AddressingType (stMsgData, subInstanceNumber);
253  }
254  else if (!strcasecmp (pSubSetting, "IPAddress"))
255  {
256  ret = get_IPv4Address_IPAddress (stMsgData, subInstanceNumber);
257  }
258  else
259  {
260  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%d] Device.IPv4: Parameter \'%s\' is Not Supported \n", __FUNCTION__, __LINE__, stMsgData->paramName);
261  stMsgData->faultCode = fcInvalidParameterName;
262  ret = NOK;
263  }
264  return ret;
265 }
266 
267 int hostIf_IPv4Address::handleSetMsg (const char* pSubSetting, int subInstanceNumber, HOSTIF_MsgData_t* stMsgData)
268 {
269  LOG_ENTRY_EXIT;
270 
271  int ret = NOT_HANDLED;
272 
273  if (!strcasecmp (pSubSetting, "Enable"))
274  {
275  ret = set_IPv4Address_Enable (stMsgData, subInstanceNumber);
276  }
277  else if (!strcasecmp (pSubSetting, "SubnetMask"))
278  {
279  ret = set_IPv4Address_SubnetMask (stMsgData, subInstanceNumber);
280  }
281  else if (!strcasecmp (pSubSetting, "IPAddress"))
282  {
283  ret = set_IPv4Address_IPAddress (stMsgData, subInstanceNumber);
284  }
285  else
286  {
287  stMsgData->faultCode = fcInvalidParameterName;
288  ret = NOT_HANDLED;
289  }
290 
291  return ret;
292 }
293 
294 /****************************************************************************************************************************************************/
295 // Device_IP_Interface_IPv4Address Profile. Getters:
296 /****************************************************************************************************************************************************/
297 
298 
299 /**
300  * @brief This function gets the status of the IPv4 interface 'enabled' or 'disabled'.
301  * It provides 'true' for enable and 'false' for disable IPv4 address.
302  *
303  * @param[out] stMsgData TR-069 Host interface message request.
304  * @param[in] subInstanceNo SubInstance number currently not in use.
305  * @param[in] pChanged Status of the operation.
306  *
307  * @return Returns the status of the operation.
308  *
309  * @retval OK if it is successfully fetch the data from the device.
310  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
311  * @ingroup TR69_HOSTIF_DEVICE_IP_IPv4_INTERFACE_ADDRESS_API
312  */
313 int hostIf_IPv4Address::get_IPv4Address_Enable(HOSTIF_MsgData_t *stMsgData,int subInstanceNo, bool *pChanged)
314 {
315  LOG_ENTRY_EXIT;
316 
317  struct in_addr in_address;
318  struct in_addr in_mask;
319  bool enable = (OK == getIPv4AddressAndMask (subInstanceNo, in_address, in_mask));
320 
321  if (bCalledEnable && pChanged && (backupEnable != enable))
322  {
323  *pChanged = true;
324  }
325  bCalledEnable = true;
326  backupEnable = enable;
327  put_int (stMsgData->paramValue, enable);
328  stMsgData->paramtype = hostIf_BooleanType;
329  stMsgData->paramLen = 1;
330 
331  return OK;
332 }
333 
334 /**
335  * @brief This function gets the status of an IPv4 Address table entry. It provides the status of
336  * this IPv4Address table entry. Possible enum values are Disabled, Enabled, Error_Misconfigured
337  * and Error (OPTIONAL).
338  *
339  * @note - The 'Error_Misconfigured' value indicates that a necessary
340  * configuration value is undefined or invalid.
341  * - The 'Error' value MAY be used by the CPE to indicate a
342  * locally defined error condition.
343  *
344  * @param[out] stMsgData TR-069 Host interface message request.
345  * @param[in] subInstanceNo SubInstance number currently not in use.
346  * @param[in] pChanged Status of the operation.
347  *
348  * @return Returns the status of the operation.
349  *
350  * @retval OK if it is successfully fetch the data from the device.
351  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
352  * @ingroup TR69_HOSTIF_DEVICE_IP_IPv4_INTERFACE_ADDRESS_API
353  */
354 int hostIf_IPv4Address::get_IPv4Address_Status(HOSTIF_MsgData_t *stMsgData,int subInstanceNo, bool *pChanged)
355 {
356  LOG_ENTRY_EXIT;
357  errno_t rc = -1;
358  char status[BUFF_LENGTH_16];
359  struct in_addr in_address;
360  struct in_addr in_mask;
361  //rc=strcpy_s (status,sizeof(status) ,(OK == getIPv4AddressAndMask (subInstanceNo, in_address, in_mask)) ? "Enabled" : "Disabled");
362  if(OK == getIPv4AddressAndMask (subInstanceNo, in_address, in_mask))
363  {
364  rc=strcpy_s (status,sizeof(status) ,"Enabled");
365  if(rc!=EOK)
366  {
367  ERR_CHK(rc);
368  }
369  }
370  else
371  {
372  rc=strcpy_s (status,sizeof(status) ,"Disabled");
373  if(rc!=EOK)
374  {
375  ERR_CHK(rc);
376  }
377  }
378 
379  if (bCalledStatus && pChanged && strncmp (status, backupStatus, BUFF_LENGTH_16))
380  {
381  *pChanged = true;
382  }
383  bCalledStatus = true;
384  strncpy (backupStatus, status, BUFF_LENGTH_16 -1); //CID:136516 - Buffer size warning
385  strncpy (stMsgData->paramValue, status, BUFF_LENGTH_16);
386  stMsgData->paramtype = hostIf_StringType;
387  stMsgData->paramLen = strlen (status);
388 
389  return OK;
390 }
391 
392 /**
393  * @brief This function gets the instance handle for an IPv4 Address of an IP Interface.
394  * It provides a non-volatile handle used to reference this IPv4 address
395  * instance of this IP interface. Alias provides a mechanism for an ACS to label this
396  * instance for future reference. Currently not implemented.
397  *
398  * @note <ul>
399  * <li>If the CPE supports the Alias-based Addressing feature as defined
400  * in [Section 3.6.1/TR-069 Amendment 4] and described in [Appendix
401  * II/TR-069 Amendment 4], the following mandatory constraints MUST be
402  * enforced:
403  * <ul><li>Its value MUST NOT be empty.</li>
404  * <li>Its value MUST start with a letter.</li>
405  * <li>If its instance object is created by the CPE, the initial
406  * value MUST start with a "cpe-" prefix.</li>
407  * <li>The CPE MUST NOT change the parameter value.</li>
408  * </ul></li>
409  * <li>This parameter can only be modified if <tt>AddressingType</tt>
410  * is <tt>Static</tt>.</li>
411  * </ul>
412  *
413  * @param[out] stMsgData TR-069 Host interface message request.
414  * @param[in] subInstanceNo SubInstance number currently not in use.
415  * @param[in] pChanged Status of the operation.
416  *
417  * @return Returns the status of the operation.
418  *
419  * @retval OK if it is successfully fetch the data from the device.
420  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
421  * @ingroup TR69_HOSTIF_DEVICE_IP_IPv4_INTERFACE_ADDRESS_API
422  */
423 int hostIf_IPv4Address::get_IPv4Address_Alias(HOSTIF_MsgData_t *stMsgData,int subInstanceNo, bool *pChanged)
424 {
425  LOG_ENTRY_EXIT;
426  // TODO: example Device.IP.Interface.1.IPv4Address.1.Alias = cpe-IPv4Address_1
427  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: Not Implemented\n", __FUNCTION__);
428  return NOK;
429 }
430 
431 /**
432  * @brief This function used to get an IP Interface IPv4 IP Address.
433  *
434  * @note This parameter can only be modified if 'AddressingType' is static.
435  *
436  * @param[out] stMsgData TR-069 Host interface message request.
437  * @param[in] subInstanceNo SubInstance number currently not in use.
438  * @param[in] pChanged Status of the operation.
439  *
440  * @return Returns the status of the operation.
441  *
442  * @retval OK if it is successfully fetch the data from the device.
443  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
444  * @ingroup TR69_HOSTIF_DEVICE_IP_IPv4_INTERFACE_ADDRESS_API
445  */
446 int hostIf_IPv4Address::get_IPv4Address_IPAddress(HOSTIF_MsgData_t *stMsgData,int subInstanceNo, bool *pChanged)
447 {
448  LOG_ENTRY_EXIT;
449 
450  struct in_addr in_address;
451  struct in_addr in_mask;
452  if (OK != getIPv4AddressAndMask (subInstanceNo, in_address, in_mask))
453  return NOK;
454 
455  char ipv4Address[BUFF_LENGTH_64] = {0};
456  inet_ntop (AF_INET, &in_address, ipv4Address, BUFF_LENGTH_64);
457  RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s]: ipv4Address = %s\n", __FUNCTION__, ipv4Address);
458 
459  if (bCalledIPAddress && pChanged && strncmp (ipv4Address, backupIPAddress, BUFF_LENGTH_64))
460  {
461  *pChanged = true;
462  }
463  bCalledIPAddress = true;
464  strncpy (backupIPAddress, ipv4Address, BUFF_LENGTH_64);
465  strncpy (stMsgData->paramValue, ipv4Address, BUFF_LENGTH_64);
466  stMsgData->paramtype = hostIf_StringType;
467  stMsgData->paramLen = strlen (ipv4Address);
468 
469  return OK;
470 }
471 
472 /**
473  * @brief This function gets an IP Interface IPv4 Address SubnetMask.
474  *
475  * @note This parameter can only be modified if 'AddressingType' is static.
476  *
477  * @param[out] stMsgData TR-069 Host interface message request.
478  * @param[in] subInstanceNo SubInstance number currently not in use.
479  * @param[in] pChanged Status of the operation.
480  *
481  * @return Returns the status of the operation.
482  *
483  * @retval OK if it is successfully fetch the data from the device.
484  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
485  * @ingroup TR69_HOSTIF_DEVICE_IP_IPv4_INTERFACE_ADDRESS_API
486  */
487 int hostIf_IPv4Address::get_IPv4Address_SubnetMask(HOSTIF_MsgData_t *stMsgData,int subInstanceNo, bool *pChanged)
488 {
489  LOG_ENTRY_EXIT;
490 
491  struct in_addr in_address;
492  struct in_addr in_mask;
493  if (OK != getIPv4AddressAndMask (subInstanceNo, in_address, in_mask))
494  return NOK;
495 
496  char subnetMask[BUFF_LENGTH_64] = {0};
497  inet_ntop (AF_INET, &in_mask, subnetMask, BUFF_LENGTH_64);
498  RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s]: subnetMask = %s\n", __FUNCTION__, subnetMask);
499 
500  if (bCalledSubnetMask && pChanged && strncmp (subnetMask, backupSubnetMask, BUFF_LENGTH_64))
501  {
502  *pChanged = true;
503  }
504  bCalledSubnetMask = true;
505  strncpy (backupSubnetMask, subnetMask, BUFF_LENGTH_64);
506  strncpy (stMsgData->paramValue, subnetMask, BUFF_LENGTH_64);
507  stMsgData->paramtype = hostIf_StringType;
508  stMsgData->paramLen = strlen (subnetMask);
509 
510  return OK;
511 }
512 
513 /**
514  * @brief tests if an IPv4 address is link-local.
515  *
516  * @param[in] in_address the IPv4 address to test.
517  *
518  * @retval true if the IPv4 address is link-local.
519  * @retval false otherwise.
520  */
521 bool hostIf_IPv4Address::isLinkLocalAddress (const struct in_addr& in_address)
522 {
523  LOG_ENTRY_EXIT;
524 
525  // check if the given IPv4 address falls in the IPv4 link-local address range (169.254.x.y)
526 
527  char ipv4Address[BUFF_LENGTH_64];
528  inet_ntop (AF_INET, &in_address, ipv4Address, BUFF_LENGTH_64);
529 
530  bool isAutoIp = (strncmp (ipv4Address, "169.254.", 8) == 0);
531 
532  RDK_LOG (RDK_LOG_TRACE1, LOG_TR69HOSTIF, "[%s]: ipv4Address = %s, isAutoIp = %d\n", __FUNCTION__, ipv4Address, isAutoIp);
533 
534  return isAutoIp;
535 }
536 
537 /**
538  * @brief This function gets an IP Interface IPv4 Address AddressingType assign the IP address.
539  * Possible enum values are DHCP, AutoIP, IPCP and Static.
540  *
541  * @param[out] stMsgData TR-069 Host interface message request.
542  * @param[in] subInstanceNo SubInstance number currently not in use.
543  * @param[in] pChanged Status of the operation.
544  *
545  * @return Returns the status of the operation.
546  *
547  * @retval OK if it is successfully fetch the data from the device.
548  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
549  * @ingroup TR69_HOSTIF_DEVICE_IP_IPv4_INTERFACE_ADDRESS_API
550  */
551 int hostIf_IPv4Address::get_IPv4Address_AddressingType(HOSTIF_MsgData_t *stMsgData,int subInstanceNo, bool *pChanged)
552 {
553  LOG_ENTRY_EXIT;
554 
555 /*
556  From the spec:
557 
558  Addressing method used to assign the IP address. Enumeration of:
559 
560  DHCP
561 
562  IKEv2 (Assigned by IKEv2 [RFC5996])
563 
564  AutoIP
565 
566  IPCP
567 
568  Static
569 */
570 
571  // first verify that we have an IPv4 address for the given instance
572  struct in_addr in_address;
573  struct in_addr in_mask;
574  errno_t rc = -1;
575  if (OK != getIPv4AddressAndMask (subInstanceNo, in_address, in_mask))
576  return NOK;
577 
578  char ipv4Address[BUFF_LENGTH_64];
579  inet_ntop (AF_INET, &in_address, ipv4Address, BUFF_LENGTH_64);
580 
581  char addressingType[BUFF_LENGTH_16];
582  if (hostIf_IPInterface::isLoopback (nameOfInterface))
583  {
584  rc=strcpy_s (addressingType,sizeof(addressingType), "Static");
585  if(rc!=EOK)
586  {
587  ERR_CHK(rc);
588  }
589  }
590  else if (isLinkLocalAddress (in_address))
591  {
592  rc=strcpy_s (addressingType,sizeof(addressingType), "AutoIP");
593  if(rc!=EOK)
594  {
595  ERR_CHK(rc);
596  }
597  }
598  /*
599  * If a MoCA / WiFi interface (specified by MOCA_INTERFACE / WIFI_INTERFACE in /etc/device.properties)
600  * still has its default IPv4 address (specified by DEFAULT_MOCA_IFACE_IP / DEFAULT_WIFI_IFACE_IP),
601  * then IPv4 AddressingType for that interface is reported as Static. Otherwise, it is reported as DHCP.
602  */
603  else if (((hasPhysicalInterfaceAs (getenvOrDefault ("MOCA_INTERFACE", ""))) &&
604  (0 == strcmp (ipv4Address, getenvOrDefault ("DEFAULT_MOCA_IFACE_IP", "")))) ||
605  ((hasPhysicalInterfaceAs (getenvOrDefault ("WIFI_INTERFACE", ""))) &&
606  (0 == strcmp (ipv4Address, getenvOrDefault ("DEFAULT_WIFI_IFACE_IP", "")))))
607  {
608  rc=strcpy_s (addressingType,sizeof(addressingType), "Static");
609  if(rc!=EOK)
610  {
611  ERR_CHK(rc);
612  }
613  }
614  else
615  {
616  rc=strcpy_s (addressingType,sizeof(addressingType), "DHCP"); // DHCP - otherwise (assume)
617  if(rc!=EOK)
618  {
619  ERR_CHK(rc);
620  }
621  }
622 
623  if (bCalledAddressingType && pChanged && strncmp (addressingType, backupAddressingType, BUFF_LENGTH_16))
624  {
625  *pChanged = true;
626  }
627  bCalledAddressingType = true;
628  strncpy (backupAddressingType, addressingType, BUFF_LENGTH_16);
629  strncpy (stMsgData->paramValue, addressingType, BUFF_LENGTH_16);
630  stMsgData->paramtype = hostIf_StringType;
631  stMsgData->paramLen = strlen (addressingType);
632 
633  return OK;
634 }
635 
636 bool hostIf_IPv4Address::hasPhysicalInterfaceAs (char* phy_if_name)
637 {
638  int l = strlen (phy_if_name);
639  return strncmp (nameOfInterface, phy_if_name, l) == 0 && (nameOfInterface[l] == 0 || nameOfInterface[l] == ':');
640 }
641 
642 /****************************************************************************************************************************************************/
643 // Device_IP_Interface_IPv4Address Profile. Setters:
644 /****************************************************************************************************************************************************/
645 
646 /**
647  * @brief This function sets the device IP Interface IPv4 Address to 'Enable' or 'Disable'.
648  *
649  * @param[out] stMsgData TR-069 Host interface message request.
650  * @param[in] subInstanceNo SubInstance number currently not in use.
651  *
652  * @return Returns the status of the operation.
653  *
654  * @retval OK if it is successfully fetch the data from the device.
655  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
656  * @ingroup TR69_HOSTIF_DEVICE_IP_IPv4_INTERFACE_ADDRESS_API
657  */
659 {
660  LOG_ENTRY_EXIT;
661 
662  char cmd[BUFF_LENGTH] = { 0 };
663  if(FALSE == get_boolean(stMsgData->paramValue))
664  {
665 #ifdef YOCTO_BUILD
666  v_secure_system("ifconfig %s 0.0.0.0", nameOfInterface);
667 #else
668  sprintf(cmd,"ifconfig %s 0.0.0.0", nameOfInterface);
669  system(cmd);
670 #endif
671  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s(),%d] IPv4Address Disabled \n",__FUNCTION__,__LINE__);
672 
673  }
674  if(TRUE == get_boolean(stMsgData->paramValue))
675  {
676 #ifdef YOCTO_BUILD
677  v_secure_system("ifdown %s && ifup %s", nameOfInterface, nameOfInterface);
678 #else
679  sprintf(cmd,"ifdown %s && ifup %s", nameOfInterface, nameOfInterface);
680  system(cmd);
681 #endif
682  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s(),%d] IPv4Address Enabled \n",__FUNCTION__,__LINE__);
683  }
684 
685  return OK;
686 }
687 
688 /**
689  * @brief This function sets a non-volatile handle used to reference this IPv4 address
690  * instance of this IP interface. Alias provides a mechanism for an ACS to label this
691  * instance for future reference. Currently not implemented.
692  *
693  * @note If the CPE supports the Alias-based Addressing feature as defined in
694  * [Section 3.6.1/TR-069 Amendment 4] and described in [Appendix II/TR-069
695  * Amendment 4], the following mandatory constraints MUST be enforced:
696  * <ul><li>Its value MUST NOT be empty.</li>
697  * <li>Its value MUST start with a letter.</li>
698  * <li>If its instance object is created by the CPE, the initial
699  * value MUST start with a "cpe-" prefix.</li>
700  * <li>The CPE MUST NOT change the parameter value.</li>
701  * </ul>
702  *
703  * @param[out] stMsgData TR-069 Host interface message request.
704  * @param[in] subInstanceNo SubInstance number currently not in use.
705  *
706  * @return Returns the status of the operation.
707  *
708  * @retval OK if it is successfully fetch the data from the device.
709  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
710  * @ingroup TR69_HOSTIF_DEVICE_IP_IPv4_INTERFACE_ADDRESS_API
711  */
713 {
714  LOG_ENTRY_EXIT;
715  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: Not Implemented\n", __FUNCTION__);
716  return NOK;
717 }
718 
719 /**
720  * @brief This function sets an IP Interface IPv4 Address.
721  *
722  * @note This parameter can only be modified if the 'AddressingType' is Static.
723  *
724  * @param[out] stMsgData TR-069 Host interface message request.
725  * @param[in] subInstanceNo SubInstance number currently not in use.
726  *
727  * @return Returns the status of the operation.
728  *
729  * @retval OK if it is successfully fetch the data from the device.
730  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
731  * @ingroup TR69_HOSTIF_DEVICE_IP_IPv4_INTERFACE_ADDRESS_API
732  */
734 {
735  LOG_ENTRY_EXIT;
736 
737  setIpOrMask(dev_id, stMsgData->paramValue ,"inet");
738 
739  return OK;
740 }
741 
742 /**
743  * @brief This function sets an IP Interface IPv4Address Subnet Mask of an IPv4 address.
744  *
745  * @note This parameter can only be modified if the 'AddressingType' is static.
746  *
747  * @param[out] stMsgData TR-069 Host interface message request.
748  * @param[in] subInstanceNo SubInstance number currently not in use.
749  *
750  * @return Returns the status of the operation.
751  *
752  * @retval OK if it is successfully fetch the data from the device.
753  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
754  * @ingroup TR69_HOSTIF_DEVICE_IP_IPv4_INTERFACE_ADDRESS_API
755  */
757 {
758  LOG_ENTRY_EXIT;
759 
760  setIpOrMask(dev_id, stMsgData->paramValue ,"netmask");
761 
762  return OK;
763 }
764 /* End of doxygen group */
765 /**
766  * @}
767  */
768 
769 /* End of file xxx_api.c. */
770 
771 
772 /** @} */
773 /** @} */
hostIf_IPv4Address::set_IPv4Address_SubnetMask
int set_IPv4Address_SubnetMask(HOSTIF_MsgData_t *stMsgData, int subInstanceNo)
This function sets an IP Interface IPv4Address Subnet Mask of an IPv4 address.
Definition: Device_IP_Interface_IPv4Address.cpp:756
hostIf_IPv4Address::get_IPv4Address_IPAddress
int get_IPv4Address_IPAddress(HOSTIF_MsgData_t *stMsgData, int subInstanceNo, bool *pChanged=NULL)
This function used to get an IP Interface IPv4 IP Address.
Definition: Device_IP_Interface_IPv4Address.cpp:446
getenvOrDefault
char * getenvOrDefault(const char *name, char *defaultValue)
Definition: hostIf_utils.cpp:404
hostIf_IPv4Address::isLinkLocalAddress
static bool isLinkLocalAddress(const struct in_addr &in_address)
tests if an IPv4 address is link-local.
Definition: Device_IP_Interface_IPv4Address.cpp:521
hostIf_IPv4Address::set_IPv4Address_Alias
int set_IPv4Address_Alias(HOSTIF_MsgData_t *stMsgData, int subInstanceNo)
This function sets a non-volatile handle used to reference this IPv4 address instance of this IP inte...
Definition: Device_IP_Interface_IPv4Address.cpp:712
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
Device_IP_Interface.h
The header file provides TR069 device IP interface information APIs.
hostIf_IPv4Address
This class provides the hostIf IPv4 interface address for getting interface address information.
Definition: Device_IP_Interface_IPv4Address.h:127
Device_IP_Interface_Stats.h
The header file provides TR069 device IP interface stats information APIs.
_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
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_IPv4Address::set_IPv4Address_Enable
int set_IPv4Address_Enable(HOSTIF_MsgData_t *stMsgData, int subInstanceNo)
This function sets the device IP Interface IPv4 Address to 'Enable' or 'Disable'.
Definition: Device_IP_Interface_IPv4Address.cpp:658
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
hostIf_IPv4Address::get_IPv4Address_AddressingType
int get_IPv4Address_AddressingType(HOSTIF_MsgData_t *stMsgData, int subInstanceNo, bool *pChanged=NULL)
This function gets an IP Interface IPv4 Address AddressingType assign the IP address....
Definition: Device_IP_Interface_IPv4Address.cpp:551
Device_IP.h
The header file provides TR069 device IP information APIs.
hostIf_IPv4Address::get_IPv4Address_Status
int get_IPv4Address_Status(HOSTIF_MsgData_t *stMsgData, int subInstanceNo, bool *pChanged=NULL)
This function gets the status of an IPv4 Address table entry. It provides the status of this IPv4Addr...
Definition: Device_IP_Interface_IPv4Address.cpp:354
hostIf_IPv4Address::set_IPv4Address_IPAddress
int set_IPv4Address_IPAddress(HOSTIF_MsgData_t *stMsgData, int subInstanceNo)
This function sets an IP Interface IPv4 Address.
Definition: Device_IP_Interface_IPv4Address.cpp:733
hostIf_IPv4Address::get_IPv4Address_Enable
int get_IPv4Address_Enable(HOSTIF_MsgData_t *stMsgData, int subInstanceNo, bool *pChanged=NULL)
Get status (enabled/disabled) of IPv4 address.
Definition: Device_IP_Interface_IPv4Address.cpp:313
hostIf_IPv4Address::hostIf_IPv4Address
hostIf_IPv4Address(int dev_id)
Class Constructor of the class hostIf_IPv4Address.
Definition: Device_IP_Interface_IPv4Address.cpp:124
hostIf_IPv4Address::get_IPv4Address_Alias
int get_IPv4Address_Alias(HOSTIF_MsgData_t *stMsgData, int subInstanceNo, bool *pChanged=NULL)
This function gets the instance handle for an IPv4 Address of an IP Interface. It provides a non-vola...
Definition: Device_IP_Interface_IPv4Address.cpp:423
Device_IP_Interface_IPv4Address.h
The header file provides TR069 device IPv4 interface address information APIs.
hostIf_IPv4Address::get_IPv4Address_SubnetMask
int get_IPv4Address_SubnetMask(HOSTIF_MsgData_t *stMsgData, int subInstanceNo, bool *pChanged=NULL)
This function gets an IP Interface IPv4 Address SubnetMask.
Definition: Device_IP_Interface_IPv4Address.cpp:487
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152
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