RDK Documentation (Open Sourced RDK Components)
Device_Ethernet_Interface.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_Ethernet_Interface.cpp
22  * @brief This source file contains the APIs of device ethernet interface.
23  */
24 
25 
26 /*****************************************************************************
27  * STANDARD INCLUDE FILES
28  *****************************************************************************/
29 
30 
31 
32 /**
33 * @defgroup tr69hostif
34 * @{
35 * @defgroup hostif
36 * @{
37 **/
38 
39 
40 #include <net/if.h>
41 
43 #ifdef YOCTO_BUILD
44 #include "secure_wrapper.h"
45 #endif
46 #include "safec_lib.h"
47 
48 EthernetInterface hostIf_EthernetInterface::stEthInterface = {0,};
49 
50 GMutex* hostIf_EthernetInterface::m_mutex = NULL;
51 
52 GHashTable *hostIf_EthernetInterface::ifHash = NULL;
53 
54 GHashTable* hostIf_EthernetInterface::m_notifyHash = NULL;
55 
56 /** Description: Counts the number of Ethernet
57  * interfaces present in the device.
58  *
59  * Get all the current interfaces in the system and
60  * count "eth" interface from the list.
61  *
62  * \Return: Count value or '0' if error
63  *
64  */
65 
67 {
68  hostIf_EthernetInterface* pRet = NULL;
69 
70  if(ifHash)
71  {
72  pRet = (hostIf_EthernetInterface *)g_hash_table_lookup(ifHash,(gpointer) dev_id);
73  }
74  else
75  {
76  ifHash = g_hash_table_new(NULL,NULL);
77  }
78 
79  if(!pRet)
80  {
81  try {
82  pRet = new hostIf_EthernetInterface(dev_id);
83  } catch(int e)
84  {
85  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create Ethernet Interface instance..\n");
86  }
87  g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
88  }
89  return pRet;
90 }
91 
92 GList* hostIf_EthernetInterface::getAllInstances()
93 {
94  if(ifHash)
95  return g_hash_table_get_keys(ifHash);
96  return NULL;
97 }
98 
99 void hostIf_EthernetInterface::closeInstance(hostIf_EthernetInterface *pDev)
100 {
101  if(pDev)
102  {
103  g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
104  delete pDev;
105  }
106 }
107 
108 void hostIf_EthernetInterface::closeAllInstances()
109 {
110  if(ifHash)
111  {
112  GList* tmp_list = g_hash_table_get_values (ifHash);
113 
114  while(tmp_list)
115  {
116  hostIf_EthernetInterface* pDev = (hostIf_EthernetInterface *)tmp_list->data;
117  tmp_list = tmp_list->next;
118  closeInstance(pDev);
119  }
120  }
121 }
122 
123 void hostIf_EthernetInterface::getLock()
124 {
125 
126  if(!m_mutex)
127  {
128  m_mutex = g_mutex_new();
129  }
130  g_mutex_lock(m_mutex);
131 
132 }
133 
134 void hostIf_EthernetInterface::releaseLock()
135 {
136  g_mutex_unlock(m_mutex);
137 }
138 
139 GHashTable* hostIf_EthernetInterface::getNotifyHash()
140 {
141  if(m_notifyHash)
142  {
143  return m_notifyHash;
144  }
145  else
146  {
147  return m_notifyHash = g_hash_table_new(g_str_hash, g_str_equal);
148  }
149 }
150 
151 /**
152  * @brief Class Constructor of the class hostIf_EthernetInterface.
153  *
154  * It will initialize the device id.
155  *
156  * @param[in] devid Device identification Number.
157  */
159  dev_id(dev_id),
160  backupEnable(false),
161  backupUpstream(false),
162  backupMaxBitRate(0),
163  bCalledEnable(false),
164  bCalledStatus(false),
165  bCalledName(false),
166  bCalledUpstream(false),
167  bCalledMACAddress(false),
168  bCalledMaxBitRate(false),
169  bCalledDuplexMode(false)
170 {
171  backupStatus[0]='\0';
172  backupName[0]='\0';
173  backupMACAddress[0]='\0';
174  backupDuplexMode[0]='\0';
175 }
176 
177 hostIf_EthernetInterface::~hostIf_EthernetInterface()
178 {
179  if(m_notifyHash)
180  {
181  g_hash_table_destroy(m_notifyHash);
182  }
183 }
184 
185 static int getEthernetInterfaceName (unsigned int ethInterfaceNum, char* name)
186 {
187  int ret = NOK;
188  errno_t rc = -1;
189  name[0]='\0';
190  //retrieve the current interfaces
191  struct if_nameindex* ifname = if_nameindex ();
192 
193  if (ifname != NULL)
194  {
195  unsigned int count = 0;
196  for (struct if_nameindex* ifnp = ifname; ifnp->if_index != 0; ifnp++)
197  {
198  if ((strncmp (ifnp->if_name, "eth", 3) == 0) && (++count == ethInterfaceNum))
199  {
200  rc=strcpy_s (name, BUFF_LENGTH_64,ifnp->if_name);
201  if(rc!=EOK)
202  {
203  ERR_CHK(rc);
204  }
205  ret = OK;
206  break;
207  }
208  }
209 
210  if_freenameindex (ifname); /* free the dynamic memory */
211 
212  if (ret != OK)
213  {
214  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s(): Cannot find Ethernet Interface Name for Ethernet Interface Number '%u'\n",
215  __FUNCTION__, ethInterfaceNum);
216  }
217  }
218  else
219  {
220  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s(): if_nameindex Error\n", __FUNCTION__);
221  }
222 
223  RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "%s(): Ethernet Interface (number,name) = (%u,%s)\n", __FUNCTION__, ethInterfaceNum, name);
224 
225  return ret;
226 }
227 
228 static int get_Device_Ethernet_Interface_Fields(unsigned int ethInterfaceNum,EEthInterfaceMembers ethInterfaceMem)
229 {
230  FILE *fp;
231  errno_t rc = -1;
232  char resultBuff[BUFF_LENGTH] = {'\0'};
233  char cmd[BUFF_LENGTH] = {'\0'};
234  int temp = 0;
235  char ethernetInterfaceName[BUFF_LENGTH_64];
236 
237  if(!ethInterfaceNum)
238  return 0;
239 
240  switch(ethInterfaceMem)
241  {
242  case eEnable:
243  hostIf_EthernetInterface::stEthInterface.enable = FALSE;
244 
245  if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName))
246  return 0;
247 
248  sprintf(cmd,"cat /sys/class/net/%s/carrier", ethernetInterfaceName);
249 
250 #ifdef YOCTO_BUILD
251  fp = v_secure_popen("r", "cat /sys/class/net/%s/carrier", ethernetInterfaceName);
252 #else
253  fp = popen(cmd,"r");
254 #endif
255 
256  if(fp == NULL)
257  {
258  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s(): Error in popen eEnable\n", __FUNCTION__);
259 
260  return 0;
261  }
262 
263  if(fgets(resultBuff,1024,fp)!=NULL)
264  {
265  sscanf(resultBuff,"%d",&hostIf_EthernetInterface::stEthInterface.enable);
266  }
267 #ifdef YOCTO_BUILD
268  v_secure_pclose(fp);
269 #else
270  pclose(fp);
271 #endif
272 
273  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): Interface %u Enable: %d \n",
274  __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.enable);
275 
276  break;
277 
278  case eStatus:
279  memset(hostIf_EthernetInterface::stEthInterface.status,'\0',sizeof(hostIf_EthernetInterface::stEthInterface.status)); //CID:45367 - OVERRUN
280 
281  if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName))
282  return 0;
283 
284  sprintf(cmd,"cat /sys/class/net/%s/carrier", ethernetInterfaceName);
285 
286 #ifdef YOCTO_BUILD
287  fp = v_secure_popen("r", "cat /sys/class/net/%s/carrier", ethernetInterfaceName);
288 #else
289  fp = popen(cmd,"r");
290 #endif
291 
292  if(fp == NULL)
293  {
294  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s(): Error in popen eStatus\n",__FUNCTION__);
295 
296  return 0;
297  }
298 
299  if(fgets(resultBuff,1024,fp)!=NULL)
300  {
301  sscanf(resultBuff,"%d",&temp);
302  }
303 
304  //rc=strcpy_s (hostIf_EthernetInterface::stEthInterface.status,sizeof(hostIf_EthernetInterface::stEthInterface.status) ,(TRUE == temp) ? "Up" : "Down");
305  if(TRUE==temp)
306  {
307  rc=strcpy_s (hostIf_EthernetInterface::stEthInterface.status,sizeof(hostIf_EthernetInterface::stEthInterface.status) ,"Up");
308  if(rc!=EOK)
309  {
310  ERR_CHK(rc);
311  }
312  }
313  else
314  {
315  rc=strcpy_s (hostIf_EthernetInterface::stEthInterface.status,sizeof(hostIf_EthernetInterface::stEthInterface.status) ,"Down");
316  if(rc!=EOK)
317  {
318  ERR_CHK(rc);
319  }
320  }
321  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): Interface %u Status: %s \n",
322  __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.status);
323 
324 #ifdef YOCTO_BUILD
325  v_secure_pclose(fp);
326 #else
327  pclose(fp);
328 #endif
329  break;
330  case eName:
331  {
332  if (OK != getEthernetInterfaceName (ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.name))
333  return 0;
334 
335  break;
336  }
337  case eLastChange:
338  break;
339  case eLowerLayers:
340  break;
341  case eUpstream:
342  hostIf_EthernetInterface::stEthInterface.upStream = FALSE;
343 
344  if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName))
345  return 0;
346 
347  sprintf(cmd,"cat /sys/class/net/%s/carrier", ethernetInterfaceName);
348 #ifdef YOCTO_BUILD
349  fp = v_secure_popen("r", "cat /sys/class/net/%s/carrier", ethernetInterfaceName);
350 #else
351  fp = popen(cmd,"r");
352 #endif
353 
354  if(fp == NULL)
355  {
356  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s(): Error in popen eUpStream\n", __FUNCTION__);
357  return 0;
358  }
359  if(fgets(resultBuff,1024,fp)!=NULL)
360  {
361  sscanf(resultBuff,"%d",&hostIf_EthernetInterface::stEthInterface.upStream );
362  }
363 #ifdef YOCTO_BUILD
364  v_secure_pclose(fp);
365 #else
366  pclose(fp);
367 #endif
368 
369  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): Interface %u UpStream: %d \n",
370  __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.upStream);
371 
372  break;
373 
374  case eMACAddress:
375  memset(hostIf_EthernetInterface::stEthInterface.mACAddress, '\0', S_LENGTH);
376 
377  if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName))
378  return 0;
379 
380  sprintf(cmd,"cat /sys/class/net/%s/address", ethernetInterfaceName);
381 #ifdef YOCTO_BUILD
382  fp = v_secure_popen("r", "cat /sys/class/net/%s/address", ethernetInterfaceName);
383 #else
384  fp = popen(cmd,"r");
385 #endif
386 
387  if(fp == NULL)
388  {
389  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s(): Error in popen eMACAddress\n", __FUNCTION__);
390 
391  return 0;
392  }
393 
394  if(fgets(resultBuff,1024,fp)!=NULL)
395  {
396  sscanf(resultBuff,"%s",hostIf_EthernetInterface::stEthInterface.mACAddress);
397  }
398 #ifdef YOCTO_BUILD
399  v_secure_pclose(fp);
400 #else
401  pclose(fp);
402 #endif
403 
404  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): Interface %u MACAddress: %s \n",
405  __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.mACAddress);
406 
407  break;
408  case eMaxBitRate:
409  hostIf_EthernetInterface::stEthInterface.maxBitRate = 0;
410 
411  if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName))
412  return 0;
413 
414  sprintf(cmd,"cat /sys/class/net/%s/speed", ethernetInterfaceName);
415 #ifdef YOCTO_BUILD
416  fp = v_secure_popen("r", "cat /sys/class/net/%s/speed", ethernetInterfaceName);
417 #else
418  fp = popen(cmd,"r");
419 #endif
420  if(fp == NULL)
421  {
422  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s(): Error in popen eMaxBitRate\n", __FUNCTION__);
423 
424  return 0;
425  }
426 
427  if(fgets(resultBuff,1024,fp)!=NULL)
428  {
429  sscanf(resultBuff,"%d",&hostIf_EthernetInterface::stEthInterface.maxBitRate);
430  }
431 #ifdef YOCTO_BUILD
432  v_secure_pclose(fp);
433 #else
434  pclose(fp);
435 #endif
436 
437  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): Interface %u MaxBitRate: %d\n",
438  __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.maxBitRate);
439  break;
440  case eDuplexMode:
441  memset(hostIf_EthernetInterface::stEthInterface.duplexMode, '\0',_BUF_LEN_16);
442 
443  if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName))
444  return 0;
445 
446  sprintf(cmd,"cat /sys/class/net/%s/duplex", ethernetInterfaceName);
447 #ifdef YOCTO_BUILD
448  fp = v_secure_popen("r", "cat /sys/class/net/%s/duplex", ethernetInterfaceName);
449 #else
450  fp = popen(cmd,"r");
451 #endif
452 
453  if(fp == NULL)
454  {
455  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s(): Error in popen eDuplex\n", __FUNCTION__);
456 
457  return 0;
458  }
459 
460  if(fgets(resultBuff,1024,fp)!=NULL)
461  {
462  sscanf(resultBuff,"%s",hostIf_EthernetInterface::stEthInterface.duplexMode);
463  }
464 #ifdef YOCTO_BUILD
465  v_secure_pclose(fp);
466 #else
467  pclose(fp);
468 #endif
469 
470  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): Interface %u DuplexMode: %s\n",
471  __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.duplexMode);
472 
473  break;
474  default:
475  break;
476 
477  }
478 
479  return 0;
480 }
481 
482 
483 /****************************************************************************************************************************************************/
484 // Device.Ethernet.Interface. Profile. Getters:
485 /****************************************************************************************************************************************************/
487 {
488  //retrieve the current interfaces
489  struct if_nameindex* ifname = if_nameindex ();
490 
491  if (ifname == NULL)
492  {
493  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s(): if_nameindex Error\n", __FUNCTION__);
494  return NOK;
495  }
496 
497  int noOfEthInterfaces = 0;
498  for (struct if_nameindex* ifnp = ifname; ifnp->if_index != 0; ifnp++)
499  {
500  if (strncmp (ifnp->if_name, "eth", 3) == 0)
501  {
502  noOfEthInterfaces++;
503  }
504  }
505 
506  if_freenameindex (ifname); /* free the dynamic memory */
507 
508  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): Current Ethernet Interfaces Count: [%d] \n", __FUNCTION__, noOfEthInterfaces);
509 
510  stMsgData->paramtype=hostIf_IntegerType;
511  stMsgData->paramLen=4;
512  put_int(stMsgData->paramValue,noOfEthInterfaces);
513 
514  return OK;
515 }
516 
517 /**
518  * @brief Get the status of an Ethernet interface is 'Enabled' or 'Disabled'.
519  *
520  * @param[out] stMsgData TR-069 Host interface message request.
521  * @param[in] pChanged Status of the operation.
522  *
523  * @return Returns the status of the operation.
524  *
525  * @retval OK if is successfully fetch the data from the device.
526  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
527  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
528  */
530 {
531  get_Device_Ethernet_Interface_Fields(dev_id, eEnable);
532 
533  if(bCalledEnable && pChanged && (backupEnable != stEthInterface.enable))
534  {
535  *pChanged = true;
536  }
537  bCalledEnable = true;
538  backupEnable = stEthInterface.enable;
539  put_boolean(stMsgData->paramValue,stEthInterface.enable);
540  stMsgData->paramtype = hostIf_BooleanType;
541  stMsgData->paramLen=1;
542 
543  return OK;
544 }
545 
546 
547 /**
548  * @brief This function gets the current operational state of the 'Ethernet' interface.
549  * Such as Up, Down, Unknown, Dormant, NotPresent, LowerLayerDown and Error (OPTIONAL).
550  *
551  * @note
552  * - When Enable is "false" then status SHOULD normally be 'Down' or 'NotPresent' or
553  * 'Error' if there is a fault condition on the interface.
554  *
555  * Code | Description
556  * -----------------|------------
557  * 'Error' | if there is an error or other fault condition detected on the interface.
558  * |
559  * 'NotPresent' | if the interface is missing i.e the hardware component is not present.
560  * |
561  * 'Unknown' | if the state of the interface can not be determined for some reason.
562  *
563  * - When enable is changed to "true" then status should change to
564  * Code | Description
565  * -----------------|------------
566  * 'Up' | if and only if the interface is able to transmit and receive network traffic
567  * |
568  * 'Dormant' | if and only if the interface is operable but is waiting for external actions before
569  * | it can transmit and receive network traffic and subsequently change to 'Up' if still operable
570  * | when the expected actions have completed.
571  * |
572  * 'LowerLayerDown' | if and only if the interface is prevented from entering the 'Up' state because one or more
573  * | of the interfaces beneath it is down.
574  *
575  * These parameter is based on ifOperStatus from RFC 2863, the Interfaces Group MIB, IETF, 2000.
576  *
577  *
578  * @param[out] stMsgData TR-069 Host interface message request.
579  * @param[in] pChanged Status of the operation.
580  *
581  * @return Returns the status of the operation.
582  *
583  * @retval OK if is successfully fetch the data from the device.
584  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
585  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
586  */
588 {
589  get_Device_Ethernet_Interface_Fields(dev_id, eStatus);
590 
591  errno_t rc = -1;
592  if(bCalledStatus && pChanged && strncmp(stEthInterface.status,backupStatus,_BUF_LEN_16-1))
593  {
594  *pChanged = true;
595  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s:%d] Ethernet Interface Status Changed..", __FUNCTION__, __FILE__, __LINE__);
596  }
597  bCalledStatus = true;
598  rc=strcpy_s(backupStatus,sizeof(backupStatus), stEthInterface.status);
599  if(rc!=EOK)
600  {
601  ERR_CHK(rc);
602  }
603  strncpy(stMsgData->paramValue,stEthInterface.status,_BUF_LEN_16-1 );
604  stMsgData->paramValue[_BUF_LEN_16-1] = '\0';
605  stMsgData->paramtype = hostIf_StringType;
606  stMsgData->paramLen = strlen(stEthInterface.status);
607  return OK;
608 }
609 
610 /**
611  * @brief Get the textual name of the 'Ethernet' interface.
612  *
613  * @param[out] stMsgData TR-069 Host interface message request.
614  * @param[in] pChanged Status of the operation.
615  *
616  * @return Returns the status of the operation.
617  *
618  * @retval OK if is successfully fetch the data from the device.
619  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
620  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
621  */
623 {
624  get_Device_Ethernet_Interface_Fields(dev_id, eName);
625 
626  errno_t rc = -1;
627  if(bCalledName && pChanged && strncmp(stEthInterface.name,backupName,_BUF_LEN_16-1))
628  {
629  *pChanged = true;
630  }
631  bCalledName = true;
632  rc=strcpy_s(backupName,sizeof(backupName), stEthInterface.name);
633  if(rc!=EOK)
634  {
635  ERR_CHK(rc);
636  }
637  strncpy(stMsgData->paramValue,stEthInterface.name,_BUF_LEN_16-1 );
638  stMsgData->paramValue[_BUF_LEN_16-1] = '\0';
639  stMsgData->paramtype = hostIf_StringType;
640  stMsgData->paramLen = strlen(stEthInterface.name);
641 
642  return OK;
643 }
644 
645 /**
646  * @brief This function provides the accumulated time in seconds since this Ethernet
647  * interface entered its current operational state. Currently not implemented.
648  *
649  * @param[out] stMsgData TR-069 Host interface message request.
650  * @param[in] pChanged Status of the operation.
651  *
652  * @return Returns enum integer '-1' on method completion.
653  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
654  */
656 {
657  /*Retrieving value */
658  // Implementation for SOC vendor
659  // value->out_cval =
660  return NOK;
661 }
662 
663 /**
664  * @brief This function provides a comma-separated list (maximum length 1024) of strings. Each
665  * list item MUST be the path name of an interface object that is stacked immediately
666  * below this Ethernet interface object. Currently not implemented.
667  *
668  * @note If the referenced object is deleted, the corresponding item MUST be removed from the list.
669  * Since Interface is a layer 1 interface, it is expected that 'LowerLayers' will not be used.
670  *
671  * @param[out] stMsgData TR-069 Host interface message request.
672  * @param[in] pChanged Status of the operation.
673  *
674  * @return Returns enum integer '-1' on method completion.
675  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
676  */
678 {
679  /*Retrieving value */
680  // Implementation for SOC vendor
681  // value->out_cval =
682  return NOK;
683 }
684 
685 /**
686  * @brief This function indicates whether the interface points towards the Internet represent by 'true'
687  * or towards End Devices represent by false
688  * For example:
689  * - For an Internet Gateway Device, Upstream will be "true" for all WAN interfaces and "false"
690  * for all LAN interfaces.
691  * - For a standalone WiFi Access Point that is connected via Ethernet to an Internet Gateway
692  * Device, Upstream will be "true" for the Ethernet interface and "false" for the WiFi Radio interface.
693  * - For an End Device, Upstream will be "true" for all interfaces.
694  *
695  * @param[out] stMsgData TR-069 Host interface message request.
696  * @param[in] pChanged Status of the operation.
697  *
698  * @return Returns the status of the operation.
699  *
700  * @retval OK if is successfully fetch the data from the device.
701  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
702  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
703  *
704  */
706 {
707  get_Device_Ethernet_Interface_Fields(dev_id, eUpstream);
708 
709  if(bCalledUpstream && pChanged && (backupUpstream != stEthInterface.upStream))
710  {
711  *pChanged = true;
712  }
713  bCalledUpstream = true;
714  backupUpstream = stEthInterface.upStream;
715  put_boolean(stMsgData->paramValue,stEthInterface.upStream);
716  stMsgData->paramtype = hostIf_BooleanType;
717  stMsgData->paramLen=1;
718 
719  return OK;
720 }
721 
722 /**
723  * @brief This function provides the MAC Address of this Ethernet interface.
724  *
725  * @note This is not necessarily the same as the Ethernet header source or
726  * destination MAC address, which is associated with the IP interface and is
727  * modelled via the Ethernet.Link.{i}.MACAddress parameter.
728  *
729  * @param[out] stMsgData TR-069 Host interface message request.
730  * @param[in] pChanged Status of the operation.
731  *
732  * @return Returns the status of the operation.
733  *
734  * @retval OK if is successfully get the MAC address.
735  * @retval ERR_INTERNAL_ERROR if not able to get the MAC address.
736  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
737  */
739 {
740  get_Device_Ethernet_Interface_Fields(dev_id, eMACAddress);
741 
742  errno_t rc = -1;
743  if(bCalledMACAddress && pChanged && strncmp(stEthInterface.mACAddress,backupMACAddress,S_LENGTH-1))
744  {
745  *pChanged = true;
746  }
747  bCalledMACAddress = true;
748  rc=strcpy_s(backupMACAddress,sizeof(backupMACAddress), stEthInterface.mACAddress);
749  if(rc!=EOK)
750  {
751  ERR_CHK(rc);
752  }
753  strncpy(stMsgData->paramValue,stEthInterface.mACAddress,S_LENGTH );
754  stMsgData->paramtype = hostIf_StringType;
755  stMsgData->paramLen = strlen(stEthInterface.mACAddress);
756 
757  return OK;
758 }
759 
760 /**
761  * @brief This function provides the maximum upstream and downstream PHY bit rate supported
762  * by this Ethernet interface it expressed in Mbps.
763  *
764  * @note A value of -1 indicates automatic selection of the maximum bit rate.
765  *
766  * @param[out] stMsgData TR-069 Host interface message request.
767  * @param[in] pChanged Status of the operation.
768  *
769  * @return Returns the status of the operation.
770  *
771  * @retval OK if is successfully get the Max BitRate.
772  * @retval ERR_INTERNAL_ERROR if not able to get the Max BitRate.
773  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
774  */
776 {
777  get_Device_Ethernet_Interface_Fields(dev_id, eMaxBitRate);
778 
779  stMsgData->paramtype=hostIf_IntegerType;
780  stMsgData->paramLen=4;
781  if(bCalledMaxBitRate && pChanged && (backupMaxBitRate != stEthInterface.maxBitRate))
782  {
783  *pChanged = true;
784  }
785  bCalledMaxBitRate = true;
786  backupMaxBitRate = stEthInterface.maxBitRate;
787  put_int(stMsgData->paramValue,stEthInterface.maxBitRate);
788 
789  return OK;
790 }
791 
792 /**
793  * @brief This function provides a string indicating the duplex mode available to this
794  * Ethernet connection. This contains the enumeration such as Half, Full, Auto.
795  *
796  * @param[out] stMsgData TR-069 Host interface message request.
797  * @param[in] pChanged Status of the operation.
798  *
799  * @return Returns the status of the operation.
800  *
801  * @retval OK if is successfully get the Duplex mode status of ethernet interface.
802  * @retval ERR_INTERNAL_ERROR if not able to get the Duplex mode status of ethernet interface.
803  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
804  */
806 {
807  get_Device_Ethernet_Interface_Fields(dev_id, eDuplexMode);
808 
809  errno_t rc = -1;
810  if(bCalledDuplexMode && pChanged && strncmp(stEthInterface.duplexMode,backupDuplexMode,_BUF_LEN_16-1))
811  {
812  *pChanged = true;
813  }
814  bCalledDuplexMode = true;
815  rc=strcpy_s(backupDuplexMode,sizeof(backupDuplexMode), stEthInterface.duplexMode);
816  if(rc!=EOK)
817  {
818  ERR_CHK(rc);
819  }
820  strncpy(stMsgData->paramValue,stEthInterface.duplexMode,_BUF_LEN_16-1 );
821  stMsgData->paramtype = hostIf_StringType;
822  stMsgData->paramLen = strlen(stEthInterface.duplexMode);
823 
824  return OK;
825 }
826 /****************************************************************************************************************************************************/
827 // Device.Ethernet.Interface. Profile. Setters:
828 /****************************************************************************************************************************************************/
829 
830 /**
831  * @brief This function sets the status of 'Ethernet' interface as enabled or disabled.
832  *
833  * @param[out] stMsgData TR-069 Host interface message request.
834  *
835  * @return Returns 'true' if the Ethernet interface is enabled successfully else 'false'.
836  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
837  */
839 {
840  unsigned int ethInterfNo = 0;
841  char cmd[64]= {'\0'};
842  bool value = get_boolean(stMsgData->paramValue);
843 
844  if(FALSE == value)
845  {
846  sprintf(cmd,"ifconfig eth%d down",ethInterfNo-1);
847  }
848  else
849  {
850  sprintf(cmd,"ifconfig eth%d up",ethInterfNo-1);
851  }
852 
853  if(system(cmd)< 0)
854  return NOK;
855  hostIf_EthernetInterface::stEthInterface.enable = value;
856 
857  return OK;
858 }
859 
860 /**
861  * @brief This function sets a non-volatile handle used to reference this Ethernet
862  * interface instance. Alias provides a mechanism for an ACS to label this instance
863  * for future reference. This function is currently not implemented.
864  * @note If the CPE supports the Alias-based Addressing feature as defined in
865  * [Section 3.6.1/TR-069 Amendment 4] and described in [Appendix II/TR-069
866  * Amendment 4], the following mandatory constraints MUST be enforced:
867  * - Its value MUST NOT be empty.
868  * - Its value MUST start with a letter.
869  * - If its instance object is created by the CPE, the initial
870  * value MUST start with a "cpe-" prefix.
871  * - The CPE MUST NOT change the parameter value.
872  *
873  * @param[out] TR-069 Host interface message request.
874  *
875  * @return Returns enum integer '-1' on method completion.
876  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
877  */
879 {
880  return NOK;
881 }
882 
883 /**
884  * @brief This function sets the 'Ethernet' interface 'LowerLayers'. Given a comma-separated list
885  * (maximum length 1024) of strings, each list item being the path name of an 'Ethernet' interface
886  * object, this function MUST stack each item in the list immediately below this interface object.
887  * Currently not implemented.
888  *
889  * @note If the referenced object is deleted, the corresponding item MUST be removed from the list.
890  * Since Interface is a layer 1 interface, it is expected that 'LowerLayers' will not be used.
891  *
892  * @param[out] stMsgData TR-069 Host interface message request.
893  *
894  * @return Returns enum integer '-1' on method completion.
895  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
896  */
898 {
899  /*Retrieving value */
900  // Implementation for SOC vendor
901  // value->out_cval =
902 
903  return NOK;
904 }
905 
906 
907 /**
908  * @brief This function sets the maximum bit rate attainable on an 'Ethernet' Interface.
909  * This function sets the maximum upstream and downstream PHY bit rate supported
910  * by this 'Ethernet' interface (expressed in Mbps). This function is currently not implemented.
911  *
912  * @note A value of -1 indicates automatic selection of the maximum bit rate.
913  *
914  * @param[out] stMsgData TR-069 Host interface message request.
915  *
916  * @return Returns enum integer '-1' on method completion.
917  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
918  */
920 {
921 
922  /*Retrieving value */
923  // Implementation for SOC vendor
924  // value->out_cval =
925  return NOK;
926 }
927 
928 /**
929  * @brief This function sets the 'Duplex Mode' available on an ethernet Interface.
930  * This function sets the string indicating the duplex mode available to this
931  * Ethernet connection. This is an enumeration having values Half, Full, Auto.
932  * This function is currently not implemented.
933  *
934  * @param[out] stMsgData TR-069 Host interface message request.
935  *
936  * @return Returns enum integer '-1' on method completion.
937  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_API
938  */
940 {
941  /*Retrieving value */
942  // Implementation for SOC vendor
943  // value->out_cval =
944 
945  return NOK;
946 }
947 
948 
949 /** @} */
950 /** @} */
hostIf_EthernetInterface::get_Device_Ethernet_InterfaceNumberOfEntries
static int get_Device_Ethernet_InterfaceNumberOfEntries(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the number of entries in the Interface table.
Definition: Device_Ethernet_Interface.cpp:486
hostIf_EthernetInterface::getInstance
static hostIf_EthernetInterface * getInstance(int dev_id)
Definition: Device_Ethernet_Interface.cpp:66
hostIf_EthernetInterface::get_Device_Ethernet_Interface_MaxBitRate
int get_Device_Ethernet_Interface_MaxBitRate(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function provides the maximum upstream and downstream PHY bit rate supported by this Ethernet in...
Definition: Device_Ethernet_Interface.cpp:775
hostIf_EthernetInterface::set_Device_Ethernet_Interface_Alias
int set_Device_Ethernet_Interface_Alias(HOSTIF_MsgData_t *)
This function sets a non-volatile handle used to reference this Ethernet interface instance....
Definition: Device_Ethernet_Interface.cpp:878
hostIf_EthernetInterface::get_Device_Ethernet_Interface_Name
int get_Device_Ethernet_Interface_Name(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the textual name of the 'Ethernet' interface.
Definition: Device_Ethernet_Interface.cpp:622
hostIf_EthernetInterface::set_Device_Ethernet_Interface_LowerLayers
int set_Device_Ethernet_Interface_LowerLayers(HOSTIF_MsgData_t *)
This function sets the 'Ethernet' interface 'LowerLayers'. Given a comma-separated list (maximum leng...
Definition: Device_Ethernet_Interface.cpp:897
hostIf_EthernetInterface::get_Device_Ethernet_Interface_Upstream
int get_Device_Ethernet_Interface_Upstream(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function indicates whether the interface points towards the Internet represent by 'true' or towa...
Definition: Device_Ethernet_Interface.cpp:705
hostIf_EthernetInterface::set_Device_Ethernet_Interface_Enable
int set_Device_Ethernet_Interface_Enable(HOSTIF_MsgData_t *)
This function sets the status of 'Ethernet' interface as enabled or disabled.
Definition: Device_Ethernet_Interface.cpp:838
hostIf_EthernetInterface::get_Device_Ethernet_Interface_LowerLayers
int get_Device_Ethernet_Interface_LowerLayers(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function provides a comma-separated list (maximum length 1024) of strings. Each list item MUST b...
Definition: Device_Ethernet_Interface.cpp:677
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
hostIf_EthernetInterface::get_Device_Ethernet_Interface_DuplexMode
int get_Device_Ethernet_Interface_DuplexMode(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the Duplex Mode available on an Ethernet Interface.
Definition: Device_Ethernet_Interface.cpp:805
hostIf_EthernetInterface::get_Device_Ethernet_Interface_LastChange
int get_Device_Ethernet_Interface_LastChange(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the time since an Ethernet interface's last change of status.
Definition: Device_Ethernet_Interface.cpp:655
put_boolean
void put_boolean(char *ptr, bool val)
This function converts the input data to Boolean type.
Definition: hostIf_utils.cpp:191
hostIf_EthernetInterface::set_Device_Ethernet_Interface_DuplexMode
int set_Device_Ethernet_Interface_DuplexMode(HOSTIF_MsgData_t *)
This function sets the 'Duplex Mode' available on an ethernet Interface. This function sets the strin...
Definition: Device_Ethernet_Interface.cpp:939
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
EEthInterfaceMembers
EEthInterfaceMembers
These values are the members of the EEthInterfaceMembers enum.
Definition: Device_Ethernet_Interface.h:104
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
hostIf_EthernetInterface
This class provides the interface for getting Device ethernet interface information.
Definition: Device_Ethernet_Interface.h:195
hostIf_EthernetInterface::get_Device_Ethernet_Interface_MACAddress
int get_Device_Ethernet_Interface_MACAddress(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function provides the MAC Address of this Ethernet interface.
Definition: Device_Ethernet_Interface.cpp:738
hostIf_EthernetInterface::get_Device_Ethernet_Interface_Enable
int get_Device_Ethernet_Interface_Enable(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the status (enabled/disabled) of an Ethernet interface.
Definition: Device_Ethernet_Interface.cpp:529
hostIf_EthernetInterface::hostIf_EthernetInterface
hostIf_EthernetInterface(int dev_id)
Class Constructor of the class hostIf_EthernetInterface.
Definition: Device_Ethernet_Interface.cpp:158
hostIf_EthernetInterface::get_Device_Ethernet_Interface_Status
int get_Device_Ethernet_Interface_Status(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the status of an Ethernet Interface.
Definition: Device_Ethernet_Interface.cpp:587
Device_Ethernet_Interface
It contains the members variables of the EthernetInterface structure.
Definition: Device_Ethernet_Interface.h:120
hostIf_EthernetInterface::set_Device_Ethernet_Interface_MaxBitRate
int set_Device_Ethernet_Interface_MaxBitRate(HOSTIF_MsgData_t *)
Set the maximum bit rate attainable on an Ethernet Interface.
Definition: Device_Ethernet_Interface.cpp:919
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152
Device_Ethernet_Interface.h
The header file provides TR069 device ethernet interface information APIs.
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