41 #include <sys/types.h>
43 #include "safec_lib.h"
46 IP hostIf_IP::stIPInstance = {
TRUE,FALSE,{
"Disabled"},FALSE,0,0};
48 char* hostIf_IP::cmd_NumOfActivePorts =
"cat /proc/net/tcp | awk '$4 == \"0A\" || $4 == \"01\" {print $2" "$3" "$4}' | wc -l";
50 GMutex* hostIf_IP::m_mutex = NULL;
52 GHashTable *hostIf_IP::ifHash = NULL;
54 GHashTable* hostIf_IP::m_notifyHash = NULL;
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)
75 backupIPv4Status[0]=
'\0';
78 hostIf_IP* hostIf_IP::getInstance(
int dev_id)
84 pRet = (
hostIf_IP *)g_hash_table_lookup(ifHash,(gpointer) dev_id);
88 ifHash = g_hash_table_new(NULL,NULL);
97 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"Caught exception, not able create MoCA Interface instance..\n");
99 g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
104 GList* hostIf_IP::getAllInstances()
107 return g_hash_table_get_keys(ifHash);
111 void hostIf_IP::closeInstance(
hostIf_IP *pDev)
115 g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
120 void hostIf_IP::closeAllInstances()
124 GList* tmp_list = g_hash_table_get_values (ifHash);
129 tmp_list = tmp_list->next;
135 void hostIf_IP::getLock()
139 m_mutex = g_mutex_new();
141 g_mutex_lock(m_mutex);
144 void hostIf_IP::releaseLock()
146 g_mutex_unlock(m_mutex);
149 GHashTable* hostIf_IP::getNotifyHash()
157 return m_notifyHash = g_hash_table_new(g_str_hash, g_str_equal);
161 hostIf_IP::~hostIf_IP()
165 g_hash_table_destroy(m_notifyHash);
186 if ((ret = if_indextoname (if_index, if_name)) == NULL)
189 struct if_nameindex* phy_if_list = if_nameindex ();
190 if (phy_if_list == NULL)
192 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s(): if_nameindex Error\n", __FUNCTION__);
196 int phy_if_count = getPhysicalInterfaceNumberOfEntries (phy_if_list);
197 if (if_index > phy_if_count)
202 if_freenameindex (phy_if_list);
205 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"%s: if_index = %d, if_name = %s\n", __FUNCTION__, if_index, if_name);
218 struct if_nameindex* phy_if_list = if_nameindex ();
219 if (phy_if_list == NULL)
221 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s(): if_nameindex Error\n", __FUNCTION__);
225 unsigned int if_count = 0;
226 if_count += getPhysicalInterfaceNumberOfEntries (phy_if_list);
229 if_freenameindex (phy_if_list);
231 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"%s: if_count = [%u]\n", __FUNCTION__, if_count);
236 unsigned int hostIf_IP::getPhysicalInterfaceNumberOfEntries (
struct if_nameindex* phy_if_list)
238 unsigned int phy_if_count = 0;
240 for (
struct if_nameindex* phy_if = phy_if_list; phy_if->if_index != 0; phy_if++)
245 RDK_LOG (RDK_LOG_TRACE1, LOG_TR69HOSTIF,
"%s: phy_if_count = [%u]\n", __FUNCTION__, phy_if_count);
257 if (getifaddrs (&ifa))
259 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: getifaddrs returned error\n", __FUNCTION__);
263 int virtual_if_count = 0;
265 for (
struct ifaddrs *ifa_node = ifa; ifa_node; ifa_node = ifa_node->ifa_next)
267 if (ifa_node->ifa_addr->sa_family == AF_INET)
269 for (
struct if_nameindex *phy_if = phy_if_list; phy_if->if_index != 0; phy_if++)
271 for (v = ifa_node->ifa_name, p = phy_if->if_name; *v == *p && *p; v++, p++)
280 long int value = (int) strtol (++v, &tailPtr, 10);
281 if (*tailPtr == 0 && value >= 0)
293 RDK_LOG (RDK_LOG_TRACE1, LOG_TR69HOSTIF,
"%s: virtual_if_count = [%u]\n", __FUNCTION__, virtual_if_count);
295 return virtual_if_count;
309 if (getifaddrs (&ifa))
312 int virtual_if_count = 0;
314 for (
struct ifaddrs *ifa_node = ifa; ifa_node; ifa_node = ifa_node->ifa_next)
316 if (ifa_node->ifa_addr->sa_family == AF_INET)
318 for (
struct if_nameindex *phy_if = phy_if_list; phy_if->if_index != 0; phy_if++)
320 for (v = ifa_node->ifa_name, p = phy_if->if_name; *v == *p && *p; v++, p++)
329 long int value = (int) strtol (++v, &tailPtr, 10);
330 if (*tailPtr == 0 && value >= 0)
332 if (++virtual_if_count == virtual_if_index)
335 rc=strcpy_s (virtual_if_name,IF_NAMESIZE, ifa_node->ifa_name);
340 ret = virtual_if_name;
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);
367 char resultBuff[BUFF_LENGTH] = {
'\0'};
368 int noOfActivePorts = 0;
370 fp = popen(cmd_NumOfActivePorts,
"r");
374 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s(): Error popen\n", __FUNCTION__);
378 if(fgets(resultBuff, BUFF_LENGTH, fp)!=NULL)
380 sscanf(resultBuff,
"%d",&noOfActivePorts);
387 return (noOfActivePorts);
391 int hostIf_IP::get_Device_IP_Fields(
EIPMembers ipMem)
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;
407 stIPInstance.iPv4Capable =
TRUE;
411 sprintf(command,
"ifconfig | egrep 'inet addr:' | wc -l");
413 fp = popen(command,
"r");
417 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s(): Error in popen eIPv4Enable\n", __FUNCTION__);
422 if(fgets(resultBuff,BUFF_LENGTH,fp)!=NULL)
424 sscanf(resultBuff,
"%d",&ipv4AddressAvailable);
428 if(0 == ipv4AddressAvailable)
430 stIPInstance.iPv4Enable = FALSE;
431 rc=strcpy_s(stIPInstance.iPv4Status,
sizeof(stIPInstance.iPv4Status),
"Disabled");
440 stIPInstance.iPv4Enable =
TRUE;
441 rc=strcpy_s(stIPInstance.iPv4Status,
sizeof(stIPInstance.iPv4Status),
"Enabled");
453 case eIpInterfaceNumberOfEntries:
460 case eIpActivePortNumberOfEntries:
474 int ret = NOT_HANDLED;
476 if (!strcasecmp (stMsgData->
paramName,
"Device.IP.IPv4Capable"))
480 else if (!strcasecmp (stMsgData->
paramName,
"Device.IP.IPv4Enable"))
484 else if (!strcasecmp (stMsgData->
paramName,
"Device.IP.IPv4Status"))
488 else if (!strcasecmp (stMsgData->
paramName,
"Device.IP.ULAPrefix"))
492 else if (!strcasecmp (stMsgData->
paramName,
"Device.IP.InterfaceNumberOfEntries"))
496 else if (!strcasecmp (stMsgData->
paramName,
"Device.IP.ActivePortNumberOfEntries"))
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;
512 int ret = NOT_HANDLED;
514 if (!strcasecmp (stMsgData->
paramName,
"Device.IP.IPv4Enable"))
520 stMsgData->
faultCode = fcInvalidParameterName;
545 get_Device_IP_Fields(eIpIPv4Capable);
546 if(bCalledIPv4Capable && pChanged && (backupIPv4Capable != stIPInstance.iPv4Capable))
550 bCalledIPv4Capable =
true;
551 backupIPv4Capable = stIPInstance.iPv4Capable;
553 stMsgData->
paramtype = hostIf_BooleanType;
573 get_Device_IP_Fields(eIpIPv4Enable);
574 if(bCalledIPv4Enable && pChanged && (backupIPv4Enable != stIPInstance.iPv4Enable))
578 bCalledIPv4Enable =
true;
579 backupIPv4Enable = stIPInstance.iPv4Enable;
581 stMsgData->
paramtype = hostIf_BooleanType;
602 get_Device_IP_Fields(eIpIPv4Status);
603 if(bCalledIPv4Status && pChanged && strncmp(stIPInstance.iPv4Status, backupIPv4Status,_BUF_LEN_16 ))
607 bCalledIPv4Status =
true;
608 strncpy(stMsgData->
paramValue,stIPInstance.iPv4Status,TR69HOSTIFMGR_MAX_PARAM_LEN );
609 strncpy(backupIPv4Status,stIPInstance.iPv4Status,
sizeof(backupIPv4Status) -1);
610 backupIPv4Status[
sizeof(backupIPv4Status) -1] =
'\0';
611 stMsgData->
paramtype = hostIf_StringType;
612 stMsgData->
paramLen = strlen(stIPInstance.iPv4Status);
636 RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,
"[%s()] Parameter Not Supported \n",__FUNCTION__);
644 hostIf_IP::get_Device_IP_Fields(eIpInterfaceNumberOfEntries);
646 stMsgData->
paramtype = hostIf_UnsignedIntType;
655 get_Device_IP_Fields(eIpActivePortNumberOfEntries);
657 stMsgData->
paramtype = hostIf_UnsignedIntType;
687 char command[BUFF_LENGTH]= {
'\0'};
692 rc=strcpy_s(command,
sizeof(command),
"ifup -a");
697 RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,
"[%s()] Enabled \n",__FUNCTION__);
702 rc=strcpy_s(command,
sizeof(command),
"ifdown -a");
707 RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,
"[%s()] Disabled \n",__FUNCTION__);
710 if(system(command) < 0)
735 RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,
"[%s()] Parameter Not Supported \n",__FUNCTION__);