44 #include "secure_wrapper.h"
46 #include "safec_lib.h"
50 GMutex* hostIf_EthernetInterface::m_mutex = NULL;
52 GHashTable *hostIf_EthernetInterface::ifHash = NULL;
54 GHashTable* hostIf_EthernetInterface::m_notifyHash = NULL;
76 ifHash = g_hash_table_new(NULL,NULL);
85 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"Caught exception, not able create Ethernet Interface instance..\n");
87 g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
92 GList* hostIf_EthernetInterface::getAllInstances()
95 return g_hash_table_get_keys(ifHash);
103 g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
108 void hostIf_EthernetInterface::closeAllInstances()
112 GList* tmp_list = g_hash_table_get_values (ifHash);
117 tmp_list = tmp_list->next;
123 void hostIf_EthernetInterface::getLock()
128 m_mutex = g_mutex_new();
130 g_mutex_lock(m_mutex);
134 void hostIf_EthernetInterface::releaseLock()
136 g_mutex_unlock(m_mutex);
139 GHashTable* hostIf_EthernetInterface::getNotifyHash()
147 return m_notifyHash = g_hash_table_new(g_str_hash, g_str_equal);
161 backupUpstream(false),
163 bCalledEnable(false),
164 bCalledStatus(false),
166 bCalledUpstream(false),
167 bCalledMACAddress(false),
168 bCalledMaxBitRate(false),
169 bCalledDuplexMode(false)
171 backupStatus[0]=
'\0';
173 backupMACAddress[0]=
'\0';
174 backupDuplexMode[0]=
'\0';
177 hostIf_EthernetInterface::~hostIf_EthernetInterface()
181 g_hash_table_destroy(m_notifyHash);
185 static int getEthernetInterfaceName (
unsigned int ethInterfaceNum,
char* name)
191 struct if_nameindex* ifname = if_nameindex ();
195 unsigned int count = 0;
196 for (
struct if_nameindex* ifnp = ifname; ifnp->if_index != 0; ifnp++)
198 if ((strncmp (ifnp->if_name,
"eth", 3) == 0) && (++count == ethInterfaceNum))
200 rc=strcpy_s (name, BUFF_LENGTH_64,ifnp->if_name);
210 if_freenameindex (ifname);
214 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s(): Cannot find Ethernet Interface Name for Ethernet Interface Number '%u'\n",
215 __FUNCTION__, ethInterfaceNum);
220 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s(): if_nameindex Error\n", __FUNCTION__);
223 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"%s(): Ethernet Interface (number,name) = (%u,%s)\n", __FUNCTION__, ethInterfaceNum, name);
228 static int get_Device_Ethernet_Interface_Fields(
unsigned int ethInterfaceNum,
EEthInterfaceMembers ethInterfaceMem)
232 char resultBuff[BUFF_LENGTH] = {
'\0'};
233 char cmd[BUFF_LENGTH] = {
'\0'};
235 char ethernetInterfaceName[BUFF_LENGTH_64];
240 switch(ethInterfaceMem)
243 hostIf_EthernetInterface::stEthInterface.enable = FALSE;
245 if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName))
248 sprintf(cmd,
"cat /sys/class/net/%s/carrier", ethernetInterfaceName);
251 fp = v_secure_popen(
"r",
"cat /sys/class/net/%s/carrier", ethernetInterfaceName);
258 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s(): Error in popen eEnable\n", __FUNCTION__);
263 if(fgets(resultBuff,1024,fp)!=NULL)
265 sscanf(resultBuff,
"%d",&hostIf_EthernetInterface::stEthInterface.enable);
273 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"%s(): Interface %u Enable: %d \n",
274 __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.enable);
279 memset(hostIf_EthernetInterface::stEthInterface.status,
'\0',
sizeof(hostIf_EthernetInterface::stEthInterface.status));
281 if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName))
284 sprintf(cmd,
"cat /sys/class/net/%s/carrier", ethernetInterfaceName);
287 fp = v_secure_popen(
"r",
"cat /sys/class/net/%s/carrier", ethernetInterfaceName);
294 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s(): Error in popen eStatus\n",__FUNCTION__);
299 if(fgets(resultBuff,1024,fp)!=NULL)
301 sscanf(resultBuff,
"%d",&temp);
307 rc=strcpy_s (hostIf_EthernetInterface::stEthInterface.status,
sizeof(hostIf_EthernetInterface::stEthInterface.status) ,
"Up");
315 rc=strcpy_s (hostIf_EthernetInterface::stEthInterface.status,
sizeof(hostIf_EthernetInterface::stEthInterface.status) ,
"Down");
321 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"%s(): Interface %u Status: %s \n",
322 __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.status);
332 if (OK != getEthernetInterfaceName (ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.name))
342 hostIf_EthernetInterface::stEthInterface.upStream = FALSE;
344 if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName))
347 sprintf(cmd,
"cat /sys/class/net/%s/carrier", ethernetInterfaceName);
349 fp = v_secure_popen(
"r",
"cat /sys/class/net/%s/carrier", ethernetInterfaceName);
356 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s(): Error in popen eUpStream\n", __FUNCTION__);
359 if(fgets(resultBuff,1024,fp)!=NULL)
361 sscanf(resultBuff,
"%d",&hostIf_EthernetInterface::stEthInterface.upStream );
369 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"%s(): Interface %u UpStream: %d \n",
370 __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.upStream);
375 memset(hostIf_EthernetInterface::stEthInterface.mACAddress,
'\0', S_LENGTH);
377 if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName))
380 sprintf(cmd,
"cat /sys/class/net/%s/address", ethernetInterfaceName);
382 fp = v_secure_popen(
"r",
"cat /sys/class/net/%s/address", ethernetInterfaceName);
389 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s(): Error in popen eMACAddress\n", __FUNCTION__);
394 if(fgets(resultBuff,1024,fp)!=NULL)
396 sscanf(resultBuff,
"%s",hostIf_EthernetInterface::stEthInterface.mACAddress);
404 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"%s(): Interface %u MACAddress: %s \n",
405 __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.mACAddress);
409 hostIf_EthernetInterface::stEthInterface.maxBitRate = 0;
411 if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName))
414 sprintf(cmd,
"cat /sys/class/net/%s/speed", ethernetInterfaceName);
416 fp = v_secure_popen(
"r",
"cat /sys/class/net/%s/speed", ethernetInterfaceName);
422 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s(): Error in popen eMaxBitRate\n", __FUNCTION__);
427 if(fgets(resultBuff,1024,fp)!=NULL)
429 sscanf(resultBuff,
"%d",&hostIf_EthernetInterface::stEthInterface.maxBitRate);
437 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"%s(): Interface %u MaxBitRate: %d\n",
438 __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.maxBitRate);
441 memset(hostIf_EthernetInterface::stEthInterface.duplexMode,
'\0',_BUF_LEN_16);
443 if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName))
446 sprintf(cmd,
"cat /sys/class/net/%s/duplex", ethernetInterfaceName);
448 fp = v_secure_popen(
"r",
"cat /sys/class/net/%s/duplex", ethernetInterfaceName);
455 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s(): Error in popen eDuplex\n", __FUNCTION__);
460 if(fgets(resultBuff,1024,fp)!=NULL)
462 sscanf(resultBuff,
"%s",hostIf_EthernetInterface::stEthInterface.duplexMode);
470 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"%s(): Interface %u DuplexMode: %s\n",
471 __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.duplexMode);
489 struct if_nameindex* ifname = if_nameindex ();
493 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s(): if_nameindex Error\n", __FUNCTION__);
497 int noOfEthInterfaces = 0;
498 for (
struct if_nameindex* ifnp = ifname; ifnp->if_index != 0; ifnp++)
500 if (strncmp (ifnp->if_name,
"eth", 3) == 0)
506 if_freenameindex (ifname);
508 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"%s(): Current Ethernet Interfaces Count: [%d] \n", __FUNCTION__, noOfEthInterfaces);
531 get_Device_Ethernet_Interface_Fields(dev_id, eEnable);
533 if(bCalledEnable && pChanged && (backupEnable != stEthInterface.enable))
537 bCalledEnable =
true;
538 backupEnable = stEthInterface.enable;
540 stMsgData->
paramtype = hostIf_BooleanType;
589 get_Device_Ethernet_Interface_Fields(dev_id, eStatus);
592 if(bCalledStatus && pChanged && strncmp(stEthInterface.status,backupStatus,_BUF_LEN_16-1))
595 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s:%s:%d] Ethernet Interface Status Changed..", __FUNCTION__, __FILE__, __LINE__);
597 bCalledStatus =
true;
598 rc=strcpy_s(backupStatus,
sizeof(backupStatus), stEthInterface.status);
603 strncpy(stMsgData->
paramValue,stEthInterface.status,_BUF_LEN_16-1 );
605 stMsgData->
paramtype = hostIf_StringType;
606 stMsgData->
paramLen = strlen(stEthInterface.status);
624 get_Device_Ethernet_Interface_Fields(dev_id, eName);
627 if(bCalledName && pChanged && strncmp(stEthInterface.name,backupName,_BUF_LEN_16-1))
632 rc=strcpy_s(backupName,
sizeof(backupName), stEthInterface.name);
637 strncpy(stMsgData->
paramValue,stEthInterface.name,_BUF_LEN_16-1 );
639 stMsgData->
paramtype = hostIf_StringType;
640 stMsgData->
paramLen = strlen(stEthInterface.name);
707 get_Device_Ethernet_Interface_Fields(dev_id, eUpstream);
709 if(bCalledUpstream && pChanged && (backupUpstream != stEthInterface.upStream))
713 bCalledUpstream =
true;
714 backupUpstream = stEthInterface.upStream;
716 stMsgData->
paramtype = hostIf_BooleanType;
740 get_Device_Ethernet_Interface_Fields(dev_id, eMACAddress);
743 if(bCalledMACAddress && pChanged && strncmp(stEthInterface.mACAddress,backupMACAddress,S_LENGTH-1))
747 bCalledMACAddress =
true;
748 rc=strcpy_s(backupMACAddress,
sizeof(backupMACAddress), stEthInterface.mACAddress);
753 strncpy(stMsgData->
paramValue,stEthInterface.mACAddress,S_LENGTH );
754 stMsgData->
paramtype = hostIf_StringType;
755 stMsgData->
paramLen = strlen(stEthInterface.mACAddress);
777 get_Device_Ethernet_Interface_Fields(dev_id, eMaxBitRate);
781 if(bCalledMaxBitRate && pChanged && (backupMaxBitRate != stEthInterface.maxBitRate))
785 bCalledMaxBitRate =
true;
786 backupMaxBitRate = stEthInterface.maxBitRate;
807 get_Device_Ethernet_Interface_Fields(dev_id, eDuplexMode);
810 if(bCalledDuplexMode && pChanged && strncmp(stEthInterface.duplexMode,backupDuplexMode,_BUF_LEN_16-1))
814 bCalledDuplexMode =
true;
815 rc=strcpy_s(backupDuplexMode,
sizeof(backupDuplexMode), stEthInterface.duplexMode);
820 strncpy(stMsgData->
paramValue,stEthInterface.duplexMode,_BUF_LEN_16-1 );
821 stMsgData->
paramtype = hostIf_StringType;
822 stMsgData->
paramLen = strlen(stEthInterface.duplexMode);
840 unsigned int ethInterfNo = 0;
841 char cmd[64]= {
'\0'};
842 bool value = get_boolean(stMsgData->
paramValue);
846 sprintf(cmd,
"ifconfig eth%d down",ethInterfNo-1);
850 sprintf(cmd,
"ifconfig eth%d up",ethInterfNo-1);
855 hostIf_EthernetInterface::stEthInterface.enable = value;