/**********************************************************************

    caller:     owner of this object

    prototype

        BOOL
        ConnectivityTest_SetParamBoolValue
            (
                ANSC_HANDLE                 hInsContext,
                char*                       ParamName,
                BOOL                        bValue
            );

    description:

        This function is called to set BOOL parameter value;

    argument:   ANSC_HANDLE                 hInsContext,
                The instance handle;

                char*                       ParamName,
                The parameter name;

                BOOL                        bValue 
                The buffer of returned BOOL value;

    return:     TRUE if succeeded.

**********************************************************************/
BOOL ConnectivityTest_SetParamBoolValue  
    (
        ANSC_HANDLE                 hInsContext,
        char*                       ParamName,
        BOOL                        bValue
    )
{
    PCOSA_DATAMODEL_SELFHEAL            pMyObject    = (PCOSA_DATAMODEL_SELFHEAL)g_pCosaBEManager->hSelfHeal; 
    if( AnscEqualString(ParamName, "X_RDKCENTRAL-COM_CorrectiveAction", TRUE))
    {
        if ( pMyObject->pConnTest->CorrectiveAction == bValue )
        {
            return  TRUE;
        }
	CcspTraceWarning(("%s Changing X_RDKCENTRAL-COM_CorrectiveAction state to %d \n",__FUNCTION__,bValue));
        /* save update to backup */
        char buf[128];
        memset(buf, 0, sizeof(buf));
        snprintf(buf,sizeof(buf),"%s",bValue ? "true" : "false");
		if (syscfg_set(NULL, "ConnTest_CorrectiveAction", buf) != 0)
		{
			CcspTraceWarning(("%s syscfg set failed for ConnTest_CorrectiveAction\n",__FUNCTION__));
			return FALSE;
		}
    	if (syscfg_commit() != 0)
		{
        	CcspTraceWarning(("%s syscfg commit failed for ConnTest_CorrectiveAction\n",__FUNCTION__));
		    return FALSE;
        }
        pMyObject->pConnTest->CorrectiveAction = bValue;
        return TRUE;
    }
    return FALSE;
}
/**********************************************************************

    caller:     owner of this object

    prototype:

        BOOL
        SelfHeal_SetParamUlongValue
            (
                ANSC_HANDLE                 hInsContext,
                char*                       ParamName,
                ULONG                       uValue
            );

    description:

        This function is called to set ULONG parameter value;

    argument:   ANSC_HANDLE                 hInsContext,
                The instance handle;

                char*                       ParamName,
                The parameter name;

                ULONG                       uValue
                The updated ULONG value;

    return:     TRUE if succeeded.

**********************************************************************/
BOOL
SelfHeal_SetParamUlongValue
    (
        ANSC_HANDLE                 hInsContext,
        char*                       ParamName,
        ULONG                       uValue
    )
{
    PCOSA_DATAMODEL_SELFHEAL            pMyObject    = (PCOSA_DATAMODEL_SELFHEAL)g_pCosaBEManager->hSelfHeal; 

    if( AnscEqualString(ParamName, "X_RDKCENTRAL-COM_MaxRebootCount", TRUE))
    {
        if( pMyObject->MaxRebootCnt == uValue )
        {
            return TRUE;
		}
        char buf[8];
        memset(buf, 0, sizeof(buf));
        snprintf(buf,sizeof(buf),"%d",uValue);
        if (syscfg_set(NULL, "max_reboot_count", buf) != 0)
        {
			CcspTraceWarning(("%s: syscfg_set failed for %s\n", __FUNCTION__, ParamName));
			return FALSE;
        }
		if (syscfg_commit() != 0)
		{
            CcspTraceWarning(("%s: syscfg commit failed for %s\n", __FUNCTION__, ParamName));
			return FALSE;
		}
        pMyObject->MaxRebootCnt = uValue;
        return TRUE;
    }

    if( AnscEqualString(ParamName, "X_RDKCENTRAL-COM_MaxResetCount", TRUE))
    {
        if( pMyObject->MaxResetCnt == uValue )
        {
            return TRUE;
        }

        char buf[8];
        memset(buf, 0, sizeof(buf));
        snprintf(buf,sizeof(buf),"%d",uValue);
        if (syscfg_set(NULL, "max_reset_count", buf) != 0)
        {
            CcspTraceWarning(("%s: syscfg_set failed for %s\n", __FUNCTION__, ParamName));
            return FALSE;
        }
        if (syscfg_commit() != 0)
        {
            CcspTraceWarning(("%s: syscfg commit failed for %s\n", __FUNCTION__, ParamName));
            return FALSE;
        }
        pMyObject->MaxResetCnt = uValue;
        return TRUE;
    }

    return FALSE;
}
Beispiel #3
0
// Function: process_setdetail
// Example: ./psmcli setdetail string COM.CISCO.CCSP.ETH0.IPv4_ADDR 192.168.100.2
unsigned int process_setdetail(int const argCnt, char const * const argVars[], char const * const busHandle) {

    //printf("Command Arguments = %s\n", argVars[1]);
    int cmd_index = 2;
    int cmd_cnt = argCnt - 2;
    unsigned int ret = 0;
    unsigned int func_ret = CCSP_SUCCESS;
    char *psmValue = NULL;
    unsigned int psmType = ccsp_string;
    char *typeStr = NULL;
    char const func_name[] = "process_setdetail";

    if ((cmd_cnt % 3) != 0) {
    	CcspTraceWarning(("<%s>[%s]: arg count = %d is not a multiple of 3, returning %d CCSP_ERR_INVALID_ARGUMENTS\n", 
                        prog_name, func_name, cmd_cnt, CCSP_ERR_INVALID_ARGUMENTS));
    	return CCSP_ERR_INVALID_ARGUMENTS;
    }
    
    // setdetail shall override the current object type and set the new specified type
    cmd_cnt = cmd_cnt/3;
    while(cmd_cnt--) {
        
    	get_type_info(&psmType, (char**)&argVars[cmd_index], TYPE_FORMAT_STRING);
    	if(psmType != ccsp_none) {
            
            ret = 0;
            ret = PSM_Set_Record_Value2((void*)busHandle,
        	            		subsys_prefix, //	PSMCLI_SUBSYSTEM_PREFIX,
                                        argVars[cmd_index+1],
                                        psmType,
                                        argVars[cmd_index+2]);
            
            if (ret == CCSP_SUCCESS) {
                printf("%d\n", CCSP_SUCCESS);
            } else {
                CcspTraceWarning(("<%s>[%s]: processing setting '%s' to '%s' unsuccessful, return set to %d\n", 
                                prog_name, func_name, argVars[cmd_index+1], argVars[cmd_index+2], ret));
                func_ret = ret;
                //                break;  // to accommondate more cmd
            }
        } else {
            CcspTraceWarning(("<%s>[%s]: unsupported datatype '%s', return set to %d = CCSP_CR_ERR_UNSUPPORTED_DATATYPE\n", 
                            prog_name, func_name, argVars[cmd_index], CCSP_CR_ERR_UNSUPPORTED_DATATYPE));
            func_ret = CCSP_CR_ERR_UNSUPPORTED_DATATYPE;
            //                break;  // to accommondate more cmd
        }

        cmd_index+=3;
    }

    //    CcspTraceDebug(("<%s>[%s]: function finished returing %d\n", prog_name, func_name, func_ret));

    return func_ret;
}
Beispiel #4
0
/* GetParameterValues */
BOOL Cosa_GetParamValues
	(
		char*	   				    pDestComp,
		char*						pDestPath,
		char**						pParamArray, 
		int 						uParamSize,
		int* 						puValueSize,
		parameterValStruct_t***  	pppValueArray
	)
{
	
                CcspTraceInfo(("RDKB_SNMP : SNMP GET called for param '%s'\n",*pParamArray));     
		int							iStatus = 0;
		iStatus = 
			CcspBaseIf_getParameterValues
				(
					bus_handle,
					pDestComp,
					pDestPath,
					pParamArray,
					uParamSize,
					puValueSize,
					pppValueArray
				);
                if(iStatus != CCSP_SUCCESS && *pParamArray)
                {
                  CcspTraceWarning(("RDKB_SNMP : Failed to get parameter value for '%s'\n",*pParamArray));    
                }
                else
                {
                   
                CcspTraceInfo(("RDKB_SNMP : SNMP GET SUCCESS for param '%s'\n",*pParamArray));
                }            
		return iStatus == CCSP_SUCCESS;
}
Beispiel #5
0
// Function: process_del
// Example: ./psmcli del COM.CISCO.CCSP.ETH0.IPv4_ADDR
unsigned int process_del(int const argCnt, char const * const argVars[], char const * const busHandle) {

    //printf("Command Arguments = %s\n", argVars[1]);
    int cmd_index = 2;
    int cmd_cnt = argCnt - 2;
    unsigned int func_ret = CCSP_SUCCESS;
    unsigned int ret = 0;
    char const func_name[] = "process_del";

    // Loop over the commands and extract the values
    while(cmd_cnt--) {
        ret = 0;
        ret = PSM_Del_Record((void*)busHandle, 
                             subsys_prefix, // PSMCLI_SUBSYSTEM_PREFIX, 
                             argVars[cmd_index]);
        
        if ( ret == CCSP_SUCCESS ) {
            printf("%d", CCSP_SUCCESS);
        } else {
            CcspTraceWarning(("<%s>[%s]: error deleting '%s', return set to %d\n",
                            prog_name, func_name, argVars[cmd_index], ret));
            func_ret = ret;
            //                break;  // to accommondate more cmd
        }
        
        cmd_index++;
    }

    //    CcspTraceDebug(("<%s>[%s]: function finished returing %d\n", prog_name, func_name, func_ret));

    return func_ret;
}
ANSC_STATUS
CosaDmlGetTCPImplementation
    (
        ANSC_HANDLE                 hContext,
        char*                       pValue,
        ULONG*                      pulSize    
    )
{
    char value[25];
    FILE *fp;

    AnscCopyString(pValue, _ERROR_);
    memset(value,0,10);

    fp = popen("cat /proc/sys/net/ipv4/tcp_congestion_control", "r");
    if (fp == NULL)
    {
        CcspTraceWarning(("ERROR '%s'\n","ERROR")); 
        return ANSC_STATUS_FAILURE;
    }
   
    while(fgets(value, 25, fp) != NULL)
    {
        AnscCopyString(pValue ,value);
    }

    pclose(fp);
    *pulSize = AnscSizeOfString(pValue);
    return ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
CosaDmlMldGetCfg
    (
        ANSC_HANDLE                 hContext,
        PCOSA_DML_MLD_CFG           pCfg
    )
{
    FILE *cfg_f, *pid_f, *fd;
    char buffer[256];
    pid_t pid;

    if (!pCfg)
    {
        return ANSC_STATUS_FAILURE;
    }

    pCfg->bSnoopingEnabled = FALSE;

    fd = fopen("/sys/class/net/brlan0/bridge/multicast_snooping", "r");

    if (fd)
    {
        if ( 1 == fread(buffer, 1, 1, fd) )
        {
            if ( buffer[0] == '1' )
            {
                pCfg->bSnoopingEnabled = TRUE;
            }
        }
        fclose(fd);        
    }

    if ( (pid_f = fopen("/var/run/ecmh.pid", "r")) != NULL )
    {
        if(fgets(buffer, 255,pid_f) != '\0')
        {
            fclose(pid_f);
            sscanf( buffer, "%d", &pid);
            CcspTraceWarning(("Sending SIGUSR1 to proccess %d...\n", pid));
            if ( kill(pid,SIGUSR1) == -1 )
            {
                pCfg->bEnabled = FALSE;
                return ANSC_STATUS_SUCCESS;
            }
            else
            {
                pCfg->bEnabled = TRUE;
            }
        }
    }
    else
    {
        return ANSC_STATUS_SUCCESS;
    }

    return ANSC_STATUS_SUCCESS;
}
int SetNDTHarvestingStatus(BOOL status)
{
    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, LMLite %s ENTER\n", __FUNCTION__ ));
    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, LMLite %s : Old[%d] New[%d] \n", __FUNCTION__, NDTReportStatus, status ));

    if (NDTReportStatus != status)
        NDTReportStatus = status;
    else
        return 0;

    if (NDTReportStatus)
    {
        pthread_t tid;

        CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, LMLite %s : Starting Thread to start DeviceData Harvesting  \n", __FUNCTION__ ));

        if (pthread_create(&tid, NULL, StartNetworkDevicesTrafficHarvesting, NULL))
        {
            CcspLMLiteTrace(("RDK_LOG_ERROR, LMLite %s : Failed to Start Thread to start DeviceData Harvesting  \n", __FUNCTION__ ));
            return ANSC_STATUS_FAILURE;
        }
	CcspTraceWarning(("LMLite: Network Traffic Report STARTED %s\n",__FUNCTION__));
    }
    else
    {
        int ret;
        pthread_mutex_lock(&ndtMutex);
        ret = pthread_cond_signal(&ndtCond);
        pthread_mutex_unlock(&ndtMutex);
        if (ret == 0)
        {
            CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, LMLite %s : pthread_cond_signal success\n", __FUNCTION__ ));
        }
        else
        {
            CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, LMLite %s : pthread_cond_signal fail\n", __FUNCTION__ ));
        }
	CcspTraceWarning(("LMLite: Network Traffic Report STOPPED %s\n",__FUNCTION__));
    }

    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, LMLite %s : EXIT \n", __FUNCTION__ ));

    return 0;
}
/*register the new callback function to the cbList*/
ANSC_STATUS
EvtDispterRgstCbFuncToList
    (
        EVT_DISPTER_CB_LIST     cbList,
        char *                  eventName,
        CALLBACK_FUNC_NAME      func,
        void *                  arg 
    )
{
    ANSC_STATUS                 returnStatus = ANSC_STATUS_SUCCESS;
    PEVT_DISPTER_CALLBACK_FUNC  pCbFunc = NULL;
    PEVT_DISPTER_METHOD_NODE    pNewMethodNode = NULL;
    EVT_DISPTER_EVENT_CB_LIST   eventCbList = NULL;
    PEVT_DISPTER_METHOD_NODE    tmpNode = NULL;

    if ( (NULL == eventName) || (NULL == func))
    {
        CcspTraceWarning(("event/function name should not be null!\n"));
        return ANSC_STATUS_FAILURE;
    }

    pCbFunc = (PEVT_DISPTER_CALLBACK_FUNC)malloc(sizeof(EVT_DISPTER_CALLBACK_FUNC));
    if(NULL != pCbFunc) {
        pCbFunc->MethodName = NULL; /*currently, methodname not used*/
        pCbFunc->Func = func;
        pCbFunc->Arg = arg;
    }
    else /*RDKB-6747, CID-32958, return if malloc failed */
    {
        returnStatus = ANSC_STATUS_FAILURE;
        return returnStatus;
    }

    /*create the new callback function node*/
    pNewMethodNode = (PEVT_DISPTER_METHOD_NODE)malloc(sizeof(EVT_DISPTER_METHOD_NODE));
    if(NULL == pNewMethodNode) {
        free(pCbFunc);  /*RDKB-6747, CID-32958, free unused resources */
        returnStatus = ANSC_STATUS_FAILURE;
        return returnStatus;
    }
    pNewMethodNode->CallbackFunc = pCbFunc;
    pNewMethodNode->Next = NULL;

    /*insert the node into the right event list*/
    eventCbList = EvtDispterFindListByEventName(cbList, eventName);
    tmpNode = eventCbList;
    while((NULL != tmpNode) && (NULL != tmpNode->Next))
    {
        tmpNode = tmpNode->Next;
    }

    tmpNode->Next = pNewMethodNode;

    return returnStatus;
}
Beispiel #10
0
BOOL
IPv6rdIF_SetParamStringValue(
        ANSC_HANDLE hInsContext,
        char        *ParamName,
        char        *pString
        )
{
    PCOSA_CONTEXT_LINK_OBJECT       pLinkObject = (PCOSA_CONTEXT_LINK_OBJECT)hInsContext;
    PCOSA_DML_IPV6RD_IF             pEntry = (PCOSA_DML_IPV6RD_IF)pLinkObject->hContext;
    char v4addr[16];
    ULONG addlen;
    char tmp[128];

    if (!pLinkObject || !pEntry)
        return FALSE;

    if (AnscEqualString(ParamName, "Alias", TRUE))
    {
        AnscCopyString(pEntry->Alias, pString);
        return TRUE;
    }
    else if (AnscEqualString(ParamName, "BorderRelayIPv4Addresses", TRUE))
    {
        AnscCopyString(pEntry->BorderRelayIPv4Addr, pString);
        return TRUE;
    }
    else if (AnscEqualString(ParamName, "SPIPv6Prefix", TRUE))
    {
        AnscCopyString(pEntry->SPIPv6Prefix, pString);
        return TRUE;
    }
    else if (AnscEqualString(ParamName, "AddressSource", TRUE))
    {
        if (!pString || _ansc_strlen(pString) == 0)
        {
            AnscCopyString(pEntry->AddressSource, "");
            return TRUE;
        }

        addlen = sizeof(v4addr);
        _ansc_sprintf(tmp, "%sIPAddress", pString);
        if (g_GetParamValueString(g_pDslhDmlAgent, tmp, v4addr, &addlen) != 0)
        {
            CcspTraceWarning(("IPv6rdIF_SetParamStringValue: fail to get %s\n", tmp));
            return FALSE;
        }

        AnscCopyString(pEntry->AddressSource, v4addr);
        /* AnscCopyString(pEntry->AddressSource, pString); */
        return TRUE;
    }

    return FALSE;
}
Beispiel #11
0
// Function: process_getallinst
// Get all object instance names
unsigned int process_getallinst(int const argCnt, char const * const argVars[], char const * const busHandle) {
    
    int cmd_index = 2;
    int cmd_cnt = argCnt - 2;
    unsigned int func_ret = CCSP_SUCCESS;
    unsigned int instanceCnt = 0;
    unsigned int *instanceList = NULL;
    unsigned int i = 0;
    char const func_name[] = "process_getallinst";

    if(cmd_cnt != 1) {
    	CcspTraceWarning(("<%s>[%s]: arg count = %d is not 1, returning %d CCSP_ERR_INVALID_ARGUMENTS\n", 
                        prog_name, func_name, cmd_cnt, CCSP_ERR_INVALID_ARGUMENTS));
        return CCSP_ERR_INVALID_ARGUMENTS;
    } 
    
    func_ret = PsmGetNextLevelInstances((void*)busHandle, 
                                        subsys_prefix, // PSMCLI_SUBSYSTEM_PREFIX, 
                                        argVars[cmd_index], 
                                        &instanceCnt, 
                                        &instanceList);

    if(func_ret == CCSP_SUCCESS && instanceList != NULL) {
        for(i = 0; i < instanceCnt; i++) {
            printf("%d\n", instanceList[i]);
        }
        ((CCSP_MESSAGE_BUS_INFO*)busHandle)->freefunc(instanceList); 
        instanceList = NULL;
    } else {
        CcspTraceWarning(("<%s>[%s]: function unsuccessful, returning %d\n",
                        prog_name, func_name, func_ret));
    }


    if(instanceList != NULL) ((CCSP_MESSAGE_BUS_INFO*)busHandle)->freefunc(instanceList);

    //    CcspTraceDebug(("<%s>[%s]: function finished returing %d\n", prog_name, func_name, func_ret));

    return func_ret; 
}
ULONG COSADmlGetMaxWindowSize()
{
    FILE *fp;
    ULONG winSize = 0;
    char value[10];

    memset(value,0,10);
    fp = popen("cat /proc/sys/net/core/wmem_max", "r");
    if (fp == NULL)
    {
       CcspTraceWarning(("ERROR '%s'\n","ERROR")); 
       return 0;
    }
   
    while(fgets(value, 10, fp) != NULL)
    {
       winSize = AnscString2Int(value);
       CcspTraceWarning(("********MaxWindowSize is '%d\n", winSize)); 
    }
    pclose(fp);

    return winSize;   
}
ANSC_STATUS
CosaDmlSetCaptivePortalEnable
    (
        BOOL value
    )
{
	char buf[10];
	char cmd[50];
	memset(buf,0,sizeof(buf));
	memset(cmd,0,sizeof(cmd));
	if (value)
	{
		strcpy(buf,"true");
		CcspTraceWarning(("CaptivePortal: Enabling Captive Portal switch ...\n"));		
	}
	else
	{
		CcspTraceWarning(("CaptivePortal: Disabling Captive Portal switch ...\n"));		
		strcpy(buf,"false");
	}
	PSM_Set_Record_Value2(bus_handle,g_Subsystem,"Device.DeviceInfo.X_RDKCENTRAL-COM_CaptivePortalEnable", ccsp_string,buf);

	return ANSC_STATUS_SUCCESS;
}
BOOL
ConnectivityTest_SetParamIntValue
    (
        ANSC_HANDLE                 hInsContext,
        char*                       ParamName,
        int                         pInt
    )
{
    PCOSA_DATAMODEL_SELFHEAL            pMyObject           = (PCOSA_DATAMODEL_SELFHEAL)g_pCosaBEManager->hSelfHeal;

    if( AnscEqualString(ParamName, "X_RDKCENTRAL-COM_RebootInterval", TRUE))
    {
        if ( pMyObject->pConnTest->RouterRebootInterval == pInt )
        {
            return  TRUE;
        }
	char cValue[10];
	memset(cValue, 0, sizeof(cValue));
        snprintf(cValue, sizeof(cValue), "%d", pInt);
	if (syscfg_set(NULL, "router_reboot_Interval", cValue) != 0)
	{
		CcspTraceWarning(("%s syscfg set failed for X_RDKCENTRAL-COM_RebootInterval\n",__FUNCTION__));
		return FALSE;
	}
        if (syscfg_commit() != 0)
	{
		CcspTraceWarning(("%s syscfg commit failed for X_RDKCENTRAL-COM_RebootInterval\n",__FUNCTION__));
		return FALSE;
	}     
        /* save update to backup */
	pMyObject->pConnTest->RouterRebootInterval = pInt;
        return TRUE;
    }
    
    return FALSE;
}
Beispiel #15
0
/* SetParameterValues */
BOOL Cosa_SetParamValuesNoCommit
	(
		char*	   				    pDestComp,
		char*						pDestPath,
		parameterValStruct_t		*val,
		int							size
	)
{
	int                        iStatus     = 0;
	char                       *faultParam = NULL;

    CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle;
        /*Removing Logging of Password values due to Security Requirement*/
	if(NULL != strstr(val->parameterName,".Security.X_COMCAST-COM_KeyPassphrase"))
	{
		CcspTraceInfo(("RDKB_SNMP : SNMP SET called for param '%s'\n",val->parameterName));
	}
	else
	{
		CcspTraceInfo(("RDKB_SNMP : SNMP SET called for param '%s' with value '%s'\n",val->parameterName,val->parameterValue));
	}
    iStatus = CcspBaseIf_setParameterValues
				(
					bus_handle, 
					pDestComp, 
					pDestPath,
					0, CCSP_COMPONENT_ID_SNMP,   /* session id and write id */
					val, 
					size, 
					FALSE,   /* no commit */
					&faultParam
				);	

    if (iStatus != CCSP_SUCCESS && faultParam)
    {
		AnscTraceError(("Error:Failed to SetValue for param '%s'\n", faultParam));
        CcspTraceWarning(("RDKB_SNMP : Failed to set parameter value for '%s'\n",faultParam)); 
		bus_info->freefunc(faultParam);
    }
    else
    {
                
                CcspTraceInfo(("RDKB_SNMP : SNMP SET SUCCESS for param '%s'\n",val->parameterName));
    } 
            return iStatus == CCSP_SUCCESS;
}
ANSC_STATUS
CosaDmlMldGetInfo
    (
        ANSC_HANDLE                 hContext,
        PCOSA_DML_MLD_INFO          pInfo
    )
{
    FILE *pid_f;
    char buffer[256];
    pid_t pid;

    if (!pInfo)
    {
        return ANSC_STATUS_FAILURE;
    }

    if ( (pid_f = fopen("/var/run/ecmh.pid", "r")) != NULL )
    {
        if(fgets(buffer, 255,pid_f) != '\0')
        {
            fclose(pid_f);
            pid_f = NULL;
            sscanf( buffer, "%d", &pid);
            CcspTraceWarning(("Sending SIGUSR1 to proccess %d...\n", pid));
            if ( kill(pid,SIGUSR1) == -1 )
            {
                pInfo->Status = COSA_DML_MLD_STATUS_Disabled;
            }
            else
            {
                pInfo->Status = COSA_DML_MLD_STATUS_Enabled;
            }
        }

        if(pid_f) /*RDKB-6846, CID-33365, free unused resources before exit*/
            fclose(pid_f);

    }
    else
    {
        pInfo->Status = COSA_DML_MLD_STATUS_Disabled;
    }
    
    return ANSC_STATUS_SUCCESS;
}
/*
 * the sysevent handler in event dispatcher
 */
void *
EvtDispterEventHandler(void *arg)
{
    int ret = EVENT_ERROR;

    while(EVENT_ERROR == EvtDispterEventInits())
    {
        CcspTraceError(("%s: sysevent init failed!\n", __FUNCTION__));
        sleep(1);
    }

    /*first check the events status*/
    EvtDispterCheckEvtStatus(se_fd, token);

    while(1)
    {
        ret = EvtDispterEventListen();
        switch (ret)
        {
            case EVENT_LAN_STARTED:
                EvtDispterCallFuncByEvent("lan-status");
                break;
            case EVENT_LAN_STOPPED:
                break;
            case EVENT_WAN_STARTED:
                EvtDispterCallFuncByEvent("wan-status");
                break;
            case EVENT_WAN_STOPPED:
                break;
            default :
                CcspTraceWarning(("The received event status is not expected!\n"));
                break;
        }

        if (EVENT_HANDLE_EXIT == ret) //end this event handling loop
            break;

        sleep(2);
    }

    EvtDispterEventClose();

    return NULL;
}
Beispiel #18
0
// Function: process_getallinst
// Get number of instances of an object
unsigned int process_getinstcnt(int const argCnt, char const * const argVars[], char const * const busHandle) {

    int cmd_index = 2;
    int cmd_cnt = argCnt - 2;
    unsigned int func_ret = CCSP_SUCCESS;
    unsigned int ret = 0;
    unsigned int instanceCnt = 0;
    unsigned  int *instanceList = NULL;
    unsigned int i = 0;
    char const func_name[] = "process_getinstcnt";

    while(cmd_cnt--) {
        ret = 0;
        ret = PsmGetNextLevelInstances((void*)busHandle, 
                                       subsys_prefix, // PSMCLI_SUBSYSTEM_PREFIX, 
                                       argVars[cmd_index], 
                                       &instanceCnt, 
                                       &instanceList);
        
        if ( ret == CCSP_SUCCESS) {
            printf("%d\n", instanceCnt);
            if(instanceList != NULL) {
                ((CCSP_MESSAGE_BUS_INFO*)busHandle)->freefunc(instanceList); 
                instanceList = NULL;
            }
        } else {
            CcspTraceWarning(("<%s>[%s]: function unsuccessful, return set to %d\n",
                            prog_name, func_name, ret));
            func_ret = ret;
            //                break;  // to accommondate more cmd
        }
        
        cmd_index++;
    }

    if(instanceList != NULL) ((CCSP_MESSAGE_BUS_INFO*)busHandle)->freefunc(instanceList); 

    //    CcspTraceDebug(("<%s>[%s]: function finished returing %d\n", prog_name, func_name, func_ret));

    return func_ret;
}
ANSC_STATUS
CosaDmlDiGetProcessorSpeed
    (
        ANSC_HANDLE                 hContext,
        char*                       pValue,
        ULONG*                      pulSize
    )
{
    #define TOKEN_STR       "BogoMIPS"
 #define MAX_LINE_SIZE   30
    char line[MAX_LINE_SIZE];
    char *pcur;
    FILE *fp;
    int status;

    memset(line, 0, MAX_LINE_SIZE);
    fp = popen("cat /proc/cpuinfo", "r");
    if (fp == NULL)
    {
        CcspTraceWarning(("Read cpuinfo ERROR '%s'\n","ERROR")); 
        return ANSC_STATUS_FAILURE;
    }
   
    while(fgets(line, MAX_LINE_SIZE, fp) != NULL )
    {
       if(strstr(line, TOKEN_STR) != NULL)
       {
        pcur = strstr(line, ":");
        pcur++;
        while(*pcur == ' ') pcur++;           
        AnscCopyString(pValue, pcur);   
       }     
    }

    status = pclose(fp);
    *pulSize = AnscSizeOfString(pValue);
    if(pValue[*pulSize-1] == '\n') pValue[--(*pulSize)] = '\0';
    return ANSC_STATUS_SUCCESS; 
}
Beispiel #20
0
void WriteWiFiLog(char *msg)
{
	char LogMsg_arr[512] = {0};
	char *LogMsg = LogMsg_arr;
	char LogLevel[512] = {0};
	strcpy (LogLevel, msg);
	strtok_r (LogLevel, ",",&LogMsg);
	if( AnscEqualString(LogLevel, "RDK_LOG_ERROR", TRUE))
	{
		CcspTraceError((LogMsg));
	}
	else if( AnscEqualString(LogLevel, "RDK_LOG_WARN", TRUE))
	{
		CcspTraceWarning((LogMsg));
	}
	else if( AnscEqualString(LogLevel, "RDK_LOG_NOTICE", TRUE))
	{
		CcspTraceNotice((LogMsg));
	}
	else if( AnscEqualString(LogLevel, "RDK_LOG_INFO", TRUE))
	{
		CcspTraceInfo((LogMsg));
	}
	else if( AnscEqualString(LogLevel, "RDK_LOG_DEBUG", TRUE))
	{
		CcspTraceDebug((LogMsg));
	}
	else if( AnscEqualString(LogLevel, "RDK_LOG_FATAL", TRUE))
	{
		CcspTraceCritical((LogMsg));
	}
	else
	{
		CcspTraceInfo((LogMsg));
	}
}
/* function call from lmlite with parameters */
void network_devices_status_report(struct networkdevicestatusdata *head, BOOL extender, char* parent_mac)
{
  int i = 0, k = 0;
  uint8_t* b64buffer =  NULL;
  size_t decodesize = 0;
  int numElements = 0;
  struct networkdevicestatusdata* ptr = head;
  avro_writer_t writer;
  char * serviceName = "lmlite";
  char * dest = "event:raw.kestrel.reports.NetworkDevicesStatus";
  char * contentType = "avro/binary"; // contentType "application/json", "avro/binary"
  uuid_t transaction_id;
  char trans_id[37];
  char CpeMacHoldingBuf[ 20 ] = {0};
  unsigned char CpeMacid[ 7 ] = {0};

  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, LMLite %s : ENTER \n", __FUNCTION__ ));

  numElements = NumberofElementsinLinkedList(head);

  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, numElements = %d\n", numElements ));

  OneAvroSerializedSize = 0;

  /* goes thru total number of elements in link list */
  writer = prepare_writer_status();


  //Reset out writer
  avro_writer_reset(writer);

  //Network Device Report
  avro_value_t  adr;
  avro_generic_value_new(iface, &adr);

  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, GatewayNetworkDeviceStatusReport\tType: %d\n", avro_value_get_type(&adr)));

  avro_value_t  adrField = {0,0};
  avro_value_t array = {0,0};
  size_t new_index = 0;
  //Optional value for unions, mac address is an union
  avro_value_t optional = {0,0};

  // timestamp - long
  avro_value_get_by_name(&adr, "header", &adrField, NULL);
  if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
  avro_value_get_by_name(&adrField, "timestamp", &adrField, NULL);
  avro_value_set_branch(&adrField, 1, &optional);
  if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

  struct timeval ts;
  gettimeofday(&ts, NULL);
#ifndef UTC_ENABLE
  int64_t tstamp_av_main = ((int64_t) (ts.tv_sec - getTimeOffsetFromUtc()) * 1000000) + (int64_t) ts.tv_usec;
#else
  int64_t tstamp_av_main = ((int64_t) (ts.tv_sec) * 1000000) + (int64_t) ts.tv_usec;
#endif
  tstamp_av_main = tstamp_av_main/1000;

  avro_value_set_long(&optional, tstamp_av_main );
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, timestamp = ""%" PRId64 "\n", tstamp_av_main ));
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, timestamp\tType: %d\n", avro_value_get_type(&optional)));
  if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

  // uuid - fixed 16 bytes
  uuid_generate_random(transaction_id); 
  uuid_unparse(transaction_id, trans_id);

  avro_value_get_by_name(&adr, "header", &adrField, NULL);
  if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
  avro_value_get_by_name(&adrField, "uuid", &adrField, NULL);
  avro_value_set_branch(&adrField, 1, &optional);
  if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
  avro_value_set_fixed(&optional, transaction_id, 16);
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, uuid\tType: %d\n", avro_value_get_type(&optional)));
  if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

  //source - string
  avro_value_get_by_name(&adr, "header", &adrField, NULL);
  if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
  avro_value_get_by_name(&adrField, "source", &adrField, NULL);
  if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
  avro_value_set_branch(&adrField, 1, &optional);
  avro_value_set_string(&optional, ReportSource);
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, source\tType: %d\n", avro_value_get_type(&optional)));
  if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));


  if ( extender == FALSE )
  {
    //cpe_id block
    /* MAC - Get CPE mac address, do it only pointer is NULL */

    memset(CpeMacHoldingBuf, 0, sizeof CpeMacHoldingBuf);
    memset(CpeMacid, 0, sizeof CpeMacid);

    if ( macStr == NULL )
    {
      macStr = getDeviceMac();

      strncpy( CpemacStr, macStr, sizeof(CpemacStr));
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Received DeviceMac from Atom side: %s\n",macStr));
    }


    for (k = 0; k < 6; k++ )
    {
      /* copy 2 bytes */
      CpeMacHoldingBuf[ k * 2 ] = CpemacStr[ k * 2 ];
      CpeMacHoldingBuf[ k * 2 + 1 ] = CpemacStr[ k * 2 + 1 ];
      CpeMacid[ k ] = (unsigned char)strtol(&CpeMacHoldingBuf[ k * 2 ], NULL, 16);
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Mac address = %0x\n", CpeMacid[ k ] ));
    }

    avro_value_get_by_name(&adr, "cpe_id", &adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_get_by_name(&adrField, "mac_address", &adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_set_branch(&adrField, 1, &optional);
    avro_value_set_fixed(&optional, CpeMacid, 6);
    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, mac_address\tType: %d\n", avro_value_get_type(&optional)));
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

    // cpe_type - string
    avro_value_get_by_name(&adr, "cpe_id", &adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_get_by_name(&adrField, "cpe_type", &adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_set_branch(&adrField, 1, &optional);
    avro_value_set_string(&optional, CPE_TYPE_GATEWAY_STRING);
    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, cpe_type\tType: %d\n", avro_value_get_type(&optional)));
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

    // cpe_parent - Recurrsive CPEIdentifier block
    avro_value_get_by_name(&adr, "cpe_id", &adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_get_by_name(&adrField, "cpe_parent", &adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_set_branch(&adrField, 0, &optional);
    avro_value_set_null(&optional);
    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, cpe_parent\tType: %d\n", avro_value_get_type(&optional)));
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
  }
  else
  {
    //cpe_id block
    avro_value_t parent_optional = {0,0}, parent_adrField = {0,0};

    memset(CpeMacHoldingBuf, 0, sizeof CpeMacHoldingBuf);
    memset(CpeMacid, 0, sizeof CpeMacid);

    for (k = 0; k < 6; k++ )
    {
      /* copy 2 bytes */
      CpeMacHoldingBuf[ k * 2 ] = parent_mac[ k * 3 ];
      CpeMacHoldingBuf[ k * 2 + 1 ] = parent_mac[ k * 3 + 1 ];
      CpeMacid[ k ] = (unsigned char)strtol(&CpeMacHoldingBuf[ k * 2 ], NULL, 16);
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Extender Mac address = %0x\n", CpeMacid[ k ] ));
    }

    avro_value_get_by_name(&adr, "cpe_id", &adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_get_by_name(&adrField, "mac_address", &adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_set_branch(&adrField, 1, &optional);
    avro_value_set_fixed(&optional, CpeMacid, 6);
    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, mac_address\tType: %d\n", avro_value_get_type(&optional)));
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

    // cpe_type - string
    avro_value_get_by_name(&adr, "cpe_id", &adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_get_by_name(&adrField, "cpe_type", &adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_set_branch(&adrField, 1, &optional);
    avro_value_set_string(&optional, CPE_TYPE_EXTENDER_STRING);
    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, cpe_type\tType: %d\n", avro_value_get_type(&optional)));
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

    // cpe_parent - Recurrsive CPEIdentifier block
    avro_value_get_by_name(&adr, "cpe_id", &adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_get_by_name(&adrField, "cpe_parent", &adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

    
    /* MAC - Get CPE mac address, do it only pointer is NULL */
    if ( macStr == NULL )
    {
      macStr = getDeviceMac();

      strncpy( CpemacStr, macStr, sizeof(CpemacStr));
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Received DeviceMac from Atom side: %s\n",macStr));
    }

    memset(CpeMacHoldingBuf, 0, sizeof CpeMacHoldingBuf);
    memset(CpeMacid, 0, sizeof CpeMacid);

    for (k = 0; k < 6; k++ )
    {
      /* copy 2 bytes */
      CpeMacHoldingBuf[ k * 2 ] = CpemacStr[ k * 2 ];
      CpeMacHoldingBuf[ k * 2 + 1 ] = CpemacStr[ k * 2 + 1 ];
      CpeMacid[ k ] = (unsigned char)strtol(&CpeMacHoldingBuf[ k * 2 ], NULL, 16);
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG Parent Mac address = %0x\n", CpeMacid[ k ] ));
    }

    // assume 1 parent ONLY
    // Parent MAC
    avro_value_set_branch(&adrField, 1, &parent_optional);
    avro_value_get_by_name(&parent_optional, "mac_address", &parent_adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_set_branch(&parent_adrField, 1, &parent_optional);
    avro_value_set_fixed(&parent_optional, CpeMacid, 6);
    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, parent mac_address\tType: %d\n", avro_value_get_type(&parent_optional)));
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

    // Parent cpe_type
    avro_value_set_branch(&adrField, 1, &parent_optional);
    avro_value_get_by_name(&parent_optional, "cpe_type", &parent_adrField, NULL);
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    avro_value_set_branch(&parent_adrField, 1, &parent_optional);
    avro_value_set_string(&parent_optional, CPE_TYPE_GATEWAY_STRING);
    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, parent cpe_type\tType: %d\n", avro_value_get_type(&parent_optional)));
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

    // no more parent, set NULL
    avro_value_set_branch(&adrField, 1, &parent_optional);
    avro_value_get_by_name(&parent_optional, "cpe_parent", &parent_adrField, NULL);
    avro_value_set_branch(&parent_adrField, 0, &parent_optional);
    avro_value_set_null(&parent_optional);
    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, parent cpe_parent\tType: %d\n", avro_value_get_type(&parent_optional)));
    if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
    
  }



  //host_table_version block
  avro_value_get_by_name(&adr, "host_table_version", &adrField, NULL);
  if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
  avro_value_set_branch(&adrField, 1, &optional);
  avro_value_set_long(&optional, lmHosts.lastActivity);
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, host_table_version\tType: %d\n", avro_value_get_type(&optional)));
  if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

  //Data Field block

  avro_value_get_by_name(&adr, "data", &adrField, NULL);
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, NetworkDeviceStatusReports - data array\tType: %d\n", avro_value_get_type(&adrField)));
  if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

  //adrField now contains a reference to the AssociatedDeviceReportsArray
  //Device Report
  avro_value_t dr = {0,0};

  //Current Device Report Field
  avro_value_t drField = {0,0};

  while(ptr)
  {

    if( (!strcmp(ptr->parent, parent_mac) && (extender == TRUE)) || (extender == FALSE) )
    {

      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Current Link List Ptr = [0x%lx], numElements = %d\n", (ulong)ptr, numElements ));
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \tDevice entry #: %d\n", i + 1));

      //Append a DeviceReport item to array
      avro_value_append(&adrField, &dr, NULL);
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \tDevice Status Report\tType: %d\n", avro_value_get_type(&dr)));

      //data array block

      memset(CpeMacHoldingBuf, 0, sizeof CpeMacHoldingBuf);
      memset(CpeMacid, 0, sizeof CpeMacid);

      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Mac address from node list  = %s \n", ptr->device_mac ));

      for (k = 0; k < 6; k++ )
      {
        /* copy 2 bytes */
        CpeMacHoldingBuf[ k * 2 ] = ptr->device_mac[ k * 3 ];
        CpeMacHoldingBuf[ k * 2 + 1 ] = ptr->device_mac[ k * 3 + 1 ];
        CpeMacid[ k ] = (unsigned char)strtol(&CpeMacHoldingBuf[ k * 2 ], NULL, 16);
        CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Mac address = %0x\n", CpeMacid[ k ] ));
      }

      //device_mac - fixed 6 bytes
      avro_value_get_by_name(&dr, "device_id", &drField, NULL);
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, device_id\tType: %d\n", avro_value_get_type(&drField)));
      avro_value_get_by_name(&drField, "mac_address", &drField, NULL);
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
      avro_value_set_branch(&drField, 1, &optional);
      avro_value_set_fixed(&optional, CpeMacid, 6);
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \tmac_address\tType: %d\n", avro_value_get_type(&optional)));
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

      //device_type - string
      avro_value_get_by_name(&dr, "device_id", &drField, NULL);
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, device_id\tType: %d\n", avro_value_get_type(&drField)));
      avro_value_get_by_name(&drField, "device_type", &drField, NULL);
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
      avro_value_set_branch(&drField, 1, &optional);
      avro_value_set_string(&optional, ptr->device_type);
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \tdevice_type\tType: %d\n", avro_value_get_type(&optional)));
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

      //timestamp - long
      avro_value_get_by_name(&dr, "timestamp", &drField, NULL);
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
      avro_value_set_branch(&drField, 1, &optional);
      int64_t tstamp_av = (int64_t) ptr->timestamp.tv_sec * 1000000 + (int64_t) ptr->timestamp.tv_usec;
      tstamp_av = tstamp_av/1000;
      avro_value_set_long(&optional, tstamp_av);
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, timestamp = ""%" PRId64 "\n", tstamp_av ));

      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \ttimestamp\tType: %d\n", avro_value_get_type(&optional)));
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

      //interface_name - string
      avro_value_get_by_name(&dr, "interface_name", &drField, NULL);
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
      avro_value_set_branch(&drField, 1, &optional);
      //avro_value_set_string(&optional, "  aa  ");
      avro_value_set_string(&optional, ptr->interface_name );
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \tinterface_name\tType: %d\n", avro_value_get_type(&optional)));
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

      //status - enum
      avro_value_get_by_name(&dr, "status", &drField, NULL);
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
      avro_value_set_branch(&drField, 1, &optional);
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, status\tType: %d\n", avro_value_get_type(&optional)));
      if ( ptr->is_active )
          avro_value_set_enum(&optional, avro_schema_enum_get_by_name(avro_value_get_schema(&optional), "ONLINE"));
      else
          avro_value_set_enum(&optional, avro_schema_enum_get_by_name(avro_value_get_schema(&optional), "OFFLINE"));
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

      //hostname - string
      avro_value_get_by_name(&dr, "hostname", &drField, NULL);
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
      avro_value_set_branch(&drField, 1, &optional);
      avro_value_set_string(&optional, ptr->hostname);
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \thostname\tType: %d\n", avro_value_get_type(&optional)));
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

      //ipaddress - array
      avro_value_get_by_name(&dr, "ip_addresses", &drField, NULL);
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));
      avro_value_set_branch(&drField, 1, &optional);
      avro_value_append(&optional, &array, NULL);
      avro_value_set_string(&array, ptr->ipaddress);
      CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, \tipaddress\tType: %d\n", avro_value_get_type(&optional)));
      if ( CHK_AVRO_ERR ) CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, %s\n", avro_strerror()));

      i++;
    }

#if SIMULATION
    ptr = 0;
#else
    ptr = ptr->next; // next link list
#endif

    /* check for writer size, if buffer is almost full, skip trailing linklist */
    avro_value_sizeof(&adr, &AvroSerializedSize);
    OneAvroSerializedSize = ( OneAvroSerializedSize == 0 ) ? AvroSerializedSize : OneAvroSerializedSize;

    if ( ( WRITER_BUF_SIZE - AvroSerializedSize ) < OneAvroSerializedSize )
    {
      CcspLMLiteTrace(("RDK_LOG_ERROR, AVRO write buffer is almost full, size = %d func %s, exit!\n", (int)AvroSerializedSize, __FUNCTION__ ));
      break;
    }

  }

  //Thats the end of that
  avro_value_write(writer, &adr);

  avro_value_sizeof(&adr, &AvroSerializedSize);
  AvroSerializedSize += MAGIC_NUMBER_SIZE + SCHEMA_ID_LENGTH;
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Serialized writer size %d\n", (int)AvroSerializedSize));

  //Free up memory
  avro_value_decref(&adr);

  avro_writer_free(writer);
  //free(buffer);



/*  if ( consoleDebugEnable )
  {
    // b64 encoding 
    decodesize = b64_get_encoded_buffer_size( AvroSerializedSize );
    b64buffer = malloc(decodesize * sizeof(uint8_t));
    b64_encode( (uint8_t*)AvroSerializedBuf, AvroSerializedSize, b64buffer);

    fprintf( stderr, "\nAVro serialized data\n");
    for (k = 0; k < (int)AvroSerializedSize ; k++)
    {
      char buf[30];
      if ( ( k % 32 ) == 0 )
        fprintf( stderr, "\n");
      sprintf(buf, "%02X", (unsigned char)AvroSerializedBuf[k]);
      fprintf( stderr, "%c%c", buf[0], buf[1] );
    }

    fprintf( stderr, "\n\nB64 data\n");
    for (k = 0; k < (int)decodesize; k++)
    {
      if ( ( k % 32 ) == 0 )
        fprintf( stderr, "\n");
      fprintf( stderr, "%c", b64buffer[k]);
    }
    fprintf( stderr, "\n\n");
    free(b64buffer);
  }*/

  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Before ND WebPA SEND message call\n"));
#ifdef PARODUS_ENABLE  
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, serviceName: %s\n", serviceName));
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, dest: %s\n", dest));
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, trans_id: %s\n", trans_id));
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, contentType: %s\n", contentType));
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, AvroSerializedBuf: %s\n", AvroSerializedBuf));
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, AvroSerializedSize: %d\n", (int)AvroSerializedSize));
#endif
  // Send data from LMLite to webpa using CCSP bus interface
  sendWebpaMsg(serviceName, dest, trans_id, contentType, AvroSerializedBuf, AvroSerializedSize);

  CcspTraceWarning(("NetworkDevicesStatus report sent to Webpa, Destination=%s, Transaction-Id=%s  \n",dest,trans_id));
  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, After ND WebPA SEND message call\n"));


  CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, LMLite %s : EXIT \n", __FUNCTION__ ));

#if SIMULATION
  exit(0);
#endif
}
ANSC_STATUS
CosaNatSyncPortTrigger
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus        = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_NAT             pMyObject           = (PCOSA_DATAMODEL_NAT     )hThisObject;
    PCOSA_CONTEXT_LINK_OBJECT       pCxtLink            = NULL;
    PSINGLE_LINK_ENTRY              pSListEntry         = NULL;
    PCOSA_DML_NAT_PTRIGGER          pPortTrigger        = NULL;
    PCOSA_DML_NAT_PTRIGGER          pPtEntry            = NULL;
    ULONG                           entryCount          = 0;
    ULONG                           i                   = 0;
    BOOL*                           pbFoundPt           = NULL;

    CcspTraceWarning(("!!!!!!!! in CosaNatSyncPortTrigger !!!!!!!!\n"));

    pPortTrigger = CosaDmlNatGetPortTriggers(NULL,&entryCount,TRUE);

    if ( !pPortTrigger )
    {
        /* Get Error, we don't del link because next time, it may be successful */
        return ANSC_STATUS_FAILURE;
    }

    pbFoundPt     = (BOOL*)AnscAllocateMemory(sizeof(BOOL) * entryCount);
    AnscZeroMemory(pbFoundPt, (sizeof(BOOL) * entryCount));

    if ( !pbFoundPt )
    {
        AnscFreeMemory(pPortTrigger); /*RDKB-6742, CID-32996, free unused resources before exit*/
        return ANSC_STATUS_RESOURCES;
    }

    pSListEntry =   AnscSListGetFirstEntry(&pMyObject->NatPTriggerList);

    while( pSListEntry )
    {
        pCxtLink          = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSListEntry);
        pSListEntry       = AnscSListGetNextEntry(pSListEntry);

        pPtEntry          = (PCOSA_DML_NAT_PTRIGGER)pCxtLink->hContext;

        for ( i = 0; i < entryCount; i++)
        {
            if ( pPtEntry->InstanceNumber == pPortTrigger[i].InstanceNumber )
            {
                /* If found, update the content also */
                CcspTraceWarning(("!!!!!!!! Ready to copy 1 !!!!!!!!\n"));
                AnscCopyMemory(pPtEntry, &pPortTrigger[i], sizeof(COSA_DML_NAT_PTRIGGER)); /* pOriAlias is NULL, no deep copy needed */

                pCxtLink->bNew = FALSE;
                pbFoundPt[i]   = TRUE;

                break;
            }
        }
    }

    /* Check those in backend but not yet in middle layer */

    for ( i = 0; i < entryCount; i++ )
    {
        if ( pbFoundPt[i] == FALSE )
        {
            /* We add new entry into our link table */
            pCxtLink = AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));
            if ( !pCxtLink )
            {
                goto EXIT1;
            }

            pPtEntry = AnscAllocateMemory(sizeof(COSA_DML_NAT_PTRIGGER));
            if ( !pPtEntry )
            {
                goto EXIT2;
            }

            /* copy new content which should include InstanceNumber and Alias */
            CcspTraceWarning(("!!!!!!!! Ready to copy 2 &pPortTrigger[%d]->InsNumber: %d !!!!!!!!\n", i, pPortTrigger[i].InstanceNumber));
            AnscCopyMemory(pPtEntry, &pPortTrigger[i], sizeof(COSA_DML_NAT_PTRIGGER)); /* pOriAlias is NULL, no deep copy needed */
            CcspTraceWarning(("!!!!!!!! After copy 2 pPtEntry->InsNumber: %d !!!!!!!!\n", pPtEntry->InstanceNumber));

            pCxtLink->hContext       = (ANSC_HANDLE)pPtEntry;
            pCxtLink->InstanceNumber = pPtEntry->InstanceNumber;
            pCxtLink->bNew           = FALSE;

            CosaSListPushEntryByInsNum(&pMyObject->NatPTriggerList, (PCOSA_CONTEXT_LINK_OBJECT)pCxtLink);
        }
    }

    returnStatus = ANSC_STATUS_SUCCESS;

    goto EXIT1;


EXIT2:

    AnscFreeMemory(pCxtLink);

EXIT1:

    AnscFreeMemory(pbFoundPt);
    AnscFreeMemory(pPortTrigger);

    CcspTraceWarning(("!!!!!!!! out CosaNatSyncPortTrigger !!!!!!!!\n"));

    return returnStatus;
}
ANSC_STATUS
CosaNatRegGetNatInfo
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus      = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_NAT             pMyObject         = ( PCOSA_DATAMODEL_NAT )hThisObject;

    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoNat      = (PPOAM_IREP_FOLDER_OBJECT )pMyObject->hIrepFolderNat;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoNatPt    = (PPOAM_IREP_FOLDER_OBJECT )pMyObject->hIrepFolderNatPt;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoEnumNat  = (PPOAM_IREP_FOLDER_OBJECT )NULL;
    PCOSA_CONTEXT_PMAPPING_LINK_OBJECT     pCosaNatContext   = NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaNatPtContext   = NULL;
    PCOSA_DML_NAT_PMAPPING          pCosaNat          = NULL;
    PCOSA_DML_NAT_PTRIGGER          pCosaNatPt        = NULL;
    PSLAP_VARIABLE                  pSlapVariable     = NULL;
    ULONG                           ulEntryCount      = 0;
    ULONG                           ulIndex           = 0;
    ULONG                           uInstanceNumber   = 0;
    BOOL                            bNew              = FALSE;
    char*                           pAliasNat         = NULL;
    char*                           pFolderName       = NULL;

    CcspTraceWarning(("!!!!!! In CosaNatRegGetNatInfo !!!!!!\n"));

    if ( !pPoamIrepFoNat || !pPoamIrepFoNatPt )
    {
        CcspTraceWarning(("!!!!!! pPoamIrepFoNat: %p, pPoamIrepFoNatPt: %p !!!!!!\n", pPoamIrepFoNat, pPoamIrepFoNatPt));
        return ANSC_STATUS_FAILURE;
    }

    /* This is saved structure for nat
        *****************************************
              <Nat>
                  <1>
                       <alias>xxx</>
                       <bNew>false</>
                 </1>
                 <2>
                      <alias>xxx</>
                      <bNew>false</>
                 </2>
            </Nat>
      ****************************************************
      */

    /* enumerate Portmapping.{i} */
    ulEntryCount = pPoamIrepFoNat->GetFolderCount((ANSC_HANDLE)pPoamIrepFoNat);
    for ( ulIndex = 0; ulIndex < ulEntryCount; ulIndex++ )
    {
        /* Get i in Portmapping.{i} */
        pFolderName =
            pPoamIrepFoNat->EnumFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoNat,
                    ulIndex
                );

        if ( !pFolderName )
        {
            continue;
        }

        uInstanceNumber = _ansc_atol(pFolderName);

        if ( uInstanceNumber == 0 )
        {
            AnscFreeMemory(pFolderName);
            continue;
        }

        pPoamIrepFoEnumNat = pPoamIrepFoNat->GetFolder((ANSC_HANDLE)pPoamIrepFoNat, pFolderName);

        AnscFreeMemory(pFolderName);

        if ( !pPoamIrepFoEnumNat )
        {
            continue;
        }

        /* Get PortMapping.{i}.Alias value*/
        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoEnumNat->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumNat,
                        COSA_DML_RR_NAME_NATAlias,
                        NULL
                    );

            if ( pSlapVariable )
            {
                pAliasNat = AnscCloneString(pSlapVariable->Variant.varString);

                SlapFreeVariable(pSlapVariable);
            }
        }

        /* Get PortMapping.{i}.bNew value*/
        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoEnumNat->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumNat,
                        COSA_DML_RR_NAME_NATbNew,
                        NULL
                    );

            if ( pSlapVariable )
            {
                bNew = pSlapVariable->Variant.varBool;

                SlapFreeVariable(pSlapVariable);
            }
            else
            {
                bNew = TRUE;
            }
        }

        /* Create one entry and keep this delay_added entry */
        pCosaNat = (PCOSA_DML_NAT_PMAPPING)AnscAllocateMemory(sizeof(COSA_DML_NAT_PMAPPING));
        if ( !pCosaNat )
        {
            returnStatus = ANSC_STATUS_FAILURE;
            goto EXIT1;
        }

        /* set some default value firstly */
        NAT_PORTMAPPING_SET_DEFAULTVALUE(pCosaNat);

        /* save alias and instanceNumber */
        pCosaNat->InstanceNumber = uInstanceNumber;
        AnscCopyString( pCosaNat->Alias, pAliasNat );

        /* Create one link point */
        pCosaNatContext = (PCOSA_CONTEXT_PMAPPING_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_PMAPPING_LINK_OBJECT));
        if ( !pCosaNatContext )
        {
            returnStatus = ANSC_STATUS_FAILURE;
            goto EXIT2;
        }

        NAT_PMAPPING_INITIATION_CONTEXT(pCosaNatContext)

        pCosaNatContext->InstanceNumber = pCosaNat->InstanceNumber;
        pCosaNatContext->hContext       = (ANSC_HANDLE)pCosaNat;
        pCosaNat                        = 0;
        pCosaNatContext->bNew           = bNew;

        CosaSListPushEntryByInsNum(&pMyObject->NatPMappingList, (PCOSA_CONTEXT_LINK_OBJECT)pCosaNatContext);

        /* release some memory */
        if (pAliasNat)
        {
            AnscFreeMemory(pAliasNat);
            pAliasNat = NULL;
        }

        pPoamIrepFoEnumNat->Remove((ANSC_HANDLE)pPoamIrepFoEnumNat);
        pPoamIrepFoEnumNat = NULL;
    }

    /* This is saved structure for nat port trigger
        *****************************************
              <Nat>
                <PortTrigger>
                  <Record>NextInsNumber</Record>
                  <1>
                       <alias>xxx</>
                       <bNew>true</>
                 </1>
                 <2>
                      <alias>xxx</>
                      <bNew>true</>
                 </2>
                 </PortTrigger>
            </Nat>
      ****************************************************
      */

    /* enumerate PortTrigger.{i} */
    ulEntryCount = pPoamIrepFoNatPt->GetFolderCount((ANSC_HANDLE)pPoamIrepFoNatPt);
    CcspTraceWarning(("!!!!!! ulEntryCount for PortTrigger: %d !!!!!!\n", ulEntryCount));

    for ( ulIndex = 0; ulIndex < ulEntryCount; ulIndex++ )
    {
        /* Get i in PortTrigger.{i} */
        pFolderName =
            pPoamIrepFoNatPt->EnumFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoNatPt,
                    ulIndex
                );
        CcspTraceWarning(("!!!!!! pFolderName: %s !!!!!!\n", pFolderName));

        if ( !pFolderName )
        {
            continue;
        }

        uInstanceNumber = _ansc_atol(pFolderName);

        if ( uInstanceNumber == 0 )
        {
            AnscFreeMemory(pFolderName);
            continue;
        }

        pPoamIrepFoEnumNat = pPoamIrepFoNatPt->GetFolder((ANSC_HANDLE)pPoamIrepFoNatPt, pFolderName);

        AnscFreeMemory(pFolderName);

        if ( !pPoamIrepFoEnumNat )
        {
            continue;
        }

        /* Get PortTrigger.{i}.Alias value*/
        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoEnumNat->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumNat,
                        COSA_DML_RR_NAME_NATAlias,
                        NULL
                    );

            if ( pSlapVariable )
            {
                pAliasNat = AnscCloneString(pSlapVariable->Variant.varString);

                SlapFreeVariable(pSlapVariable);
            }
        }

        /* Get PortTrigger.{i}.bNew value*/
        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoEnumNat->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumNat,
                        COSA_DML_RR_NAME_NATbNew,
                        NULL
                    );

            if ( pSlapVariable )
            {
                bNew = pSlapVariable->Variant.varBool;

                SlapFreeVariable(pSlapVariable);
            }
            else
            {
                bNew = TRUE;
            }
        }

        /* Create one entry and keep this delay_added entry */
        pCosaNatPt = (PCOSA_DML_NAT_PTRIGGER)AnscAllocateMemory(sizeof(COSA_DML_NAT_PTRIGGER));

        if ( !pCosaNatPt )
        {
            returnStatus = ANSC_STATUS_RESOURCES;
            goto EXIT1;
        }

        /* set some default value firstly */
        COSA_DML_NAT_PTRIGGER_INIT(pCosaNatPt);

        /* save alias and instanceNumber */
        pCosaNatPt->InstanceNumber = uInstanceNumber;
        AnscCopyString( pCosaNatPt->Alias, pAliasNat );

        CcspTraceWarning(("!!!!!! pCosaNatPt->InstanceNumber: %d, pCosaNatPt->Alias: %s !!!!!!\n", pCosaNatPt->InstanceNumber, pCosaNatPt->Alias));

        /* Create one link point */
        pCosaNatPtContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));
        if ( !pCosaNatPtContext )
        {
            AnscFreeMemory(pCosaNatPt); /*RDKB-6742, CID-33206, Free unused resources after use*/
            pCosaNatPt = NULL;
            returnStatus = ANSC_STATUS_FAILURE;
            goto EXIT2;
        }

         COSA_CONTEXT_LINK_INITIATION_CONTENT(pCosaNatPtContext)

        pCosaNatPtContext->InstanceNumber = pCosaNatPt->InstanceNumber;
        pCosaNatPtContext->hContext       = (ANSC_HANDLE)pCosaNatPt;
        pCosaNatPtContext->bNew           = bNew;

        CosaSListPushEntryByInsNum(&pMyObject->NatPTriggerList, (PCOSA_CONTEXT_LINK_OBJECT)pCosaNatPtContext);

        /* release some memory */
        if (pAliasNat)
        {
            AnscFreeMemory(pAliasNat);
            pAliasNat = NULL;
        }

        pPoamIrepFoEnumNat->Remove((ANSC_HANDLE)pPoamIrepFoEnumNat);
        pPoamIrepFoEnumNat = NULL;
    }



EXIT2:
    if(pCosaNat)
        AnscFreeMemory(pCosaNat);

EXIT1:

    if(pAliasNat)
        AnscFreeMemory(pAliasNat);

    if ( pPoamIrepFoEnumNat )
        pPoamIrepFoEnumNat->Remove((ANSC_HANDLE)pPoamIrepFoEnumNat);

    return returnStatus;
}
ANSC_STATUS
CosaDdnsInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus    = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_DDNS            pMyObject       = (PCOSA_DATAMODEL_DDNS     )hThisObject;
    PSLIST_HEADER                   pListHead       = (PSLIST_HEADER            )&pMyObject->ContextHead;
    PCOSA_DML_DDNS_CFG              pDdnsCfg        = (PCOSA_DML_DDNS_CFG       )NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext    = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
    PCOSA_DML_DDNS_SERVICE          pDdnsService    = (PCOSA_DML_DDNS_SERVICE   )NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT )NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoDdns = (PPOAM_IREP_FOLDER_OBJECT )NULL;
    PSLAP_VARIABLE                  pSlapVariable   = (PSLAP_VARIABLE           )NULL;
    ULONG                           ulServiceCount  = 0;
    ULONG                           ulIndex         = 0;
    
    returnStatus = CosaDmlDdnsInit(NULL, NULL);

    if ( returnStatus != ANSC_STATUS_SUCCESS )
    {
        return returnStatus;
    }

    /* Initiation all functions */
    pMyObject->ulNextInstance      = 1;

    AnscSListInitializeHeader(&pMyObject->ContextHead);

    pDdnsCfg = AnscAllocateMemory(sizeof(COSA_DML_DDNS_CFG));

    if ( !pDdnsCfg )
    {
        CcspTraceWarning(("X_CISCO_COM_DDNS Resource allocation error\n"));

        return ANSC_STATUS_RESOURCES;
    }

    returnStatus = CosaDmlDdnsGetConfig(NULL, pDdnsCfg);

    if ( returnStatus != ANSC_STATUS_SUCCESS )
    {
        goto EXIT1;
    }

    pMyObject->DdnsConfig.bEnabled = pDdnsCfg->bEnabled;

    pMyObject->hIrepFolderCOSA = g_GetRegistryRootFolder(g_pDslhDmlAgent);

    pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderCOSA;

    if ( !pPoamIrepFoCOSA )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto  EXIT1;
    }

    pPoamIrepFoDdns = 
        (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoCOSA->GetFolder
            (
                (ANSC_HANDLE)pPoamIrepFoCOSA,
                COSA_IREP_FOLDER_NAME_DDNS
            );

    if ( !pPoamIrepFoDdns )
    {
        pPoamIrepFoDdns =
            pPoamIrepFoCOSA->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoCOSA,
                    COSA_IREP_FOLDER_NAME_DDNS,
                    0
                );
    }

    if ( !pPoamIrepFoDdns )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto  EXIT1;
    }
    else
    {
        pMyObject->hIrepFolderDdns = (ANSC_HANDLE)pPoamIrepFoDdns;
    }

    /* Retrieve Next Instance Number */

    if ( TRUE )
    {
        pSlapVariable =
            (PSLAP_VARIABLE)pPoamIrepFoDdns->GetRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoDdns,
                    COSA_DML_RR_NAME_DdnsServiceNextInsNumber,
                    NULL
                );

        if ( pSlapVariable )
        {
            pMyObject->ulNextInstance = pSlapVariable->Variant.varUint32;

            SlapFreeVariable(pSlapVariable);
        }
    }

    /* Initialize middle layer */

    ulServiceCount = CosaDmlDdnsGetNumberOfServices(NULL);

    for ( ulIndex = 0; ulIndex < ulServiceCount; ulIndex++ )
    {
        pDdnsService = (PCOSA_DML_DDNS_SERVICE)AnscAllocateMemory(sizeof(COSA_DML_DDNS_SERVICE));

        if ( !pDdnsService )
        {
            returnStatus = ANSC_STATUS_RESOURCES;

            goto EXIT1;
        }

        returnStatus = CosaDmlDdnsGetService(NULL, ulIndex, pDdnsService);

        if ( returnStatus == ANSC_STATUS_SUCCESS )
        {
            pCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

            if ( !pCosaContext )
            {
                returnStatus = ANSC_STATUS_RESOURCES;

                goto EXIT2;
            }

            if ( pDdnsService->InstanceNumber != 0 )
            {
                pCosaContext->InstanceNumber = pDdnsService->InstanceNumber;

                if ( pMyObject->ulNextInstance <= pDdnsService->InstanceNumber )
                {
                    pMyObject->ulNextInstance = pDdnsService->InstanceNumber + 1;

                    if ( pMyObject->ulNextInstance == 0 )
                    {
                        pMyObject->ulNextInstance = 1;
                    }
                }  
            }
            else
            {
                pDdnsService->InstanceNumber = pCosaContext->InstanceNumber = pMyObject->ulNextInstance;

                pMyObject->ulNextInstance++;

                if ( pMyObject->ulNextInstance == 0 )
                {
                    pMyObject->ulNextInstance = 1;
                }

                /* Generate Alias */
                _ansc_sprintf(pDdnsService->Alias, "DdnsService%d", pCosaContext->InstanceNumber);

                returnStatus = 
                    CosaDmlDdnsServiceSetValues
                        (
                            NULL, 
                            ulIndex, 
                            pCosaContext->InstanceNumber, 
                            pDdnsService->Alias
                        );

                if ( returnStatus != ANSC_STATUS_SUCCESS )
                {
                    CcspTraceWarning(("!!! CosaDmlDdnsServiceSetValues index: %d-- fail !!!\n", ulIndex));
                    
                    AnscFreeMemory(pDdnsService);
                    AnscFreeMemory(pCosaContext);

                    continue;
                }
            }

            pCosaContext->hContext     = (ANSC_HANDLE)pDdnsService;
            pCosaContext->hParentTable = NULL;
            pCosaContext->bNew         = FALSE;

            CosaSListPushEntryByInsNum(pListHead, pCosaContext);
        }
    }

    /* Load the newly added but not yet committed entries, if exist */

    CosaDdnsRegGetDdnsInfo((ANSC_HANDLE)pMyObject);

    goto EXIT1;

EXIT2:

    AnscFreeMemory(pDdnsService);

EXIT1:

    AnscFreeMemory(pDdnsCfg);

    return returnStatus;
}
Beispiel #25
0
ANSC_STATUS
ssp_create_wifi
    (
        PCCSP_COMPONENT_CFG         pStartCfg
    )
{
    /* Create component common data model object */

    g_pComponent_Common_Dm = (PCOMPONENT_COMMON_DM)AnscAllocateMemory(sizeof(COMPONENT_COMMON_DM));

    if ( !g_pComponent_Common_Dm )
    {
        return ANSC_STATUS_RESOURCES;
    }

    ComponentCommonDmInit(g_pComponent_Common_Dm);

    g_pComponent_Common_Dm->Name     = AnscCloneString(pStartCfg->ComponentName);
    g_pComponent_Common_Dm->Version  = 1;
    g_pComponent_Common_Dm->Author   = AnscCloneString("CCSP");

    /* Create ComponentCommonDatamodel interface*/
    if ( !pWifiCcdIf )
    {
        pWifiCcdIf = (PCCSP_CCD_INTERFACE)AnscAllocateMemory(sizeof(CCSP_CCD_INTERFACE));

        if ( !pWifiCcdIf )
        {
            return ANSC_STATUS_RESOURCES;
        }
        else
        {
            AnscCopyString(pWifiCcdIf->Name, CCSP_CCD_INTERFACE_NAME);

            pWifiCcdIf->InterfaceId              = CCSP_CCD_INTERFACE_ID;
            pWifiCcdIf->hOwnerContext            = NULL;
            pWifiCcdIf->Size                     = sizeof(CCSP_CCD_INTERFACE);

            pWifiCcdIf->GetComponentName         = ssp_WifiCCDmGetComponentName;
            pWifiCcdIf->GetComponentVersion      = ssp_WifiCCDmGetComponentVersion;
            pWifiCcdIf->GetComponentAuthor       = ssp_WifiCCDmGetComponentAuthor;
            pWifiCcdIf->GetComponentHealth       = ssp_WifiCCDmGetComponentHealth;
            pWifiCcdIf->GetComponentState        = ssp_WifiCCDmGetComponentState;
            pWifiCcdIf->GetLoggingEnabled        = ssp_WifiCCDmGetLoggingEnabled;
            pWifiCcdIf->SetLoggingEnabled        = ssp_WifiCCDmSetLoggingEnabled;
            pWifiCcdIf->GetLoggingLevel          = ssp_WifiCCDmGetLoggingLevel;
            pWifiCcdIf->SetLoggingLevel          = ssp_WifiCCDmSetLoggingLevel;
            pWifiCcdIf->GetMemMaxUsage           = ssp_WifiCCDmGetMemMaxUsage;
            pWifiCcdIf->GetMemMinUsage           = ssp_WifiCCDmGetMemMinUsage;
            pWifiCcdIf->GetMemConsumed           = ssp_WifiCCDmGetMemConsumed;
            pWifiCcdIf->ApplyChanges             = ssp_WifiCCDmApplyChanges;
        }
    }

    /* Create context used by data model */
    pWifiFcContext = (PCCSP_FC_CONTEXT)AnscAllocateMemory(sizeof(CCSP_FC_CONTEXT));

    if ( !pWifiFcContext )
    {
        return ANSC_STATUS_RESOURCES;
    }
    else
    {
        AnscZeroMemory(pWifiFcContext, sizeof(CCSP_FC_CONTEXT));
    }

    pDslhCpeController = DslhCreateCpeController(NULL, NULL, NULL);

    if ( !pDslhCpeController )
    {
        CcspTraceWarning(("CANNOT Create pDslhCpeController... Exit!\n"));

        return ANSC_STATUS_RESOURCES;
    }

    return ANSC_STATUS_SUCCESS;
}
int handleipv4PingServerList(
    netsnmp_mib_handler           *handler,
    netsnmp_handler_registration  *reginfo,
    netsnmp_agent_request_info    *reqinfo,
    netsnmp_request_info          *requests)
{
    netsnmp_request_info     *request = NULL;
    netsnmp_variable_list    *vb = NULL;
    int                      ins, rowstatus;
    oid                      subid = 0;
    PCCSP_TABLE_ENTRY        pEntry;
    char                     dmStr[128] = {'\0'};
    unsigned char            octet = 0;
    
    printf(" ******** handleipv4PingServerList ************ \n");

    for (request = requests; request != NULL; request = request->next){
        vb = request->requestvb;
        subid = vb->name[vb->name_length - 2];
        
        printf(" **** handleipv4PingServerList subid is %d ************ \n",subid);
        
        printf(" **** handleipv4PingServerList req is %d ************ \n",*(vb->val.integer));

        if(subid == saRgSelfHealIpv4PingServerRowstatus_lastOid &&
           (*(vb->val.integer) == 4 || *(vb->val.integer) == 5)){
            // CreateAndWait or CreateAndGo let framework handle
        }else{
            pEntry = (PCCSP_TABLE_ENTRY)netsnmp_tdata_extract_entry(request);
            if (pEntry == NULL) {
                netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE);
                CcspTraceWarning(("Entry not found for ipv4 server list\n"));
                continue;
            }
            ins = pEntry->IndexValue[0].Value.iValue;
        }

        switch (reqinfo->mode) {
        case MODE_GET:
             if(subid == saRgSelfHealIpv4PingServerRowstatus_lastOid){
                rowstatus = 1; // RS_ACTIVE
                snmp_set_var_typed_value(request->requestvb, (u_char)ASN_INTEGER, (u_char *)&rowstatus, sizeof(rowstatus));
                request->processed = 1;
            }
        break;

        case MODE_SET_RESERVE1:
            
            /* sanity check */
            break;

        case MODE_SET_RESERVE2:
            
            break;

        case MODE_SET_ACTION:
        /* commit */
        case MODE_SET_FREE:   
        case MODE_SET_COMMIT:
        case MODE_SET_UNDO:
        break;
        default:
            netsnmp_set_request_error(reqinfo, request, SNMP_ERR_GENERR);
            return SNMP_ERR_GENERR;
        }
    }
    return SNMP_ERR_NOERROR;
}
static void *handle_parodus()
{
    int backoffRetryTime = 0;
    int backoff_max_time = 9;
    int max_retry_sleep;
    //Retry Backoff count shall start at c=2 & calculate 2^c - 1.
    int c =2;
	int retval=-1;
    char *parodus_url = NULL;

    CcspLMLiteConsoleTrace(("RDK_LOG_INFO, ******** Start of handle_parodus ********\n"));

    pthread_detach(pthread_self());

    max_retry_sleep = (int) pow(2, backoff_max_time) -1;
    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, max_retry_sleep is %d\n", max_retry_sleep ));

        get_parodus_url(&parodus_url);
	if(parodus_url != NULL)
	{
	
		libpd_cfg_t cfg1 = {.service_name = "lmlite",
						.receive = false, .keepalive_timeout_secs = 0,
						.parodus_url = parodus_url,
						.client_url = NULL
					   };
		            
		CcspLMLiteConsoleTrace(("RDK_LOG_INFO, Configurations => service_name : %s parodus_url : %s client_url : %s\n", cfg1.service_name, cfg1.parodus_url, cfg1.client_url ));

		CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, Call parodus library init api \n"));

		while(1)
		{
		    if(backoffRetryTime < max_retry_sleep)
		    {
		        backoffRetryTime = (int) pow(2, c) -1;
		    }

		    CcspLMLiteConsoleTrace(("RDK_LOG_DEBUG, New backoffRetryTime value calculated as %d seconds\n", backoffRetryTime));
		    int ret =libparodus_init (&client_instance, &cfg1);
		    CcspLMLiteConsoleTrace(("RDK_LOG_INFO, ret is %d\n",ret));
		    if(ret ==0)
		    {
		        CcspTraceWarning(("LMLite: Init for parodus Success..!!\n"));
		        break;
		    }
		    else
		    {
		        CcspTraceError(("LMLite: Init for parodus (url %s) failed: '%s'\n", parodus_url, libparodus_strerror(ret)));
		        if( NULL == parodus_url ) {
		            get_parodus_url(&parodus_url);
		            cfg1.parodus_url = parodus_url;
		        }
		        sleep(backoffRetryTime);
		        c++;
		    }
		retval = libparodus_shutdown(client_instance);
		   
		}
	}
    return 0;
}
/*
 * Listen sysevent notification message
 */
int 
EvtDispterEventListen(void)
{
    int     ret = EVENT_TIMEOUT;
    fd_set  rfds;
    struct  timeval tv;
    int     retval;


    tv.tv_sec = 30;
    tv.tv_usec=0;
    FD_ZERO(&rfds);
    FD_SET(se_fd, &rfds);

    retval=select(se_fd+1, &rfds, NULL, NULL, NULL);

    if(retval) {
        se_buffer            msg_buffer;
        se_notification_msg *msg_body = (se_notification_msg *)msg_buffer;
        unsigned int         msg_size;
        token_t              from;
        int                  msg_type;

        msg_size  = sizeof(msg_buffer);
        msg_type = SE_msg_receive(se_fd, msg_buffer, &msg_size, &from);
        // if not a notification message then ignore it
        if (SE_MSG_NOTIFICATION == msg_type) {
            // extract the name and value from the return message data
            int   name_bytes;
            int   value_bytes;
            char *name_str;
            char *value_str;
            char *data_ptr;

            data_ptr   = (char *)&(msg_body->data);
            name_str   = (char *)SE_msg_get_string(data_ptr, &name_bytes);
            data_ptr  += name_bytes;
            value_str =  (char *)SE_msg_get_string(data_ptr, &value_bytes);

            if(!strcmp(name_str, "lan-status"))
            {
                if (!strncmp(value_str, "started", 7)) 
                    ret = EVENT_LAN_STARTED;
                else if (!strncmp(value_str, "stopped", 7)) 
                    ret = EVENT_LAN_STOPPED;
            }
            else if(!strcmp(name_str, "wan-status"))
            {
                if (!strncmp(value_str, "started", 7)) 
                    ret = EVENT_WAN_STARTED;
                else if (!strncmp(value_str, "stopped", 7)) 
                    ret = EVENT_WAN_STOPPED;
            }
        } else {
            CcspTraceWarning(("Received msg that is not a SE_MSG_NOTIFICATION (%d)\n", msg_type));
        }
    } else {
        CcspTraceError(("%s: Received no event retval=%d\n", __FUNCTION__, retval));
    }
    return ret;
}
ANSC_STATUS
CosaDmlMldSetCfg
    (
        ANSC_HANDLE                 hContext,
        PCOSA_DML_MLD_CFG           pCfg
    )
{
    FILE *cfg_f, *pid_f, *fd;
    char buffer[256];
    pid_t pid;
    COSA_DML_MLD_CFG Cfg2;

    if (!pCfg)
    {
        return ANSC_STATUS_FAILURE;
    }

    if ( pCfg->bSnoopingEnabled )
    {
        _write_sysctl_file("/sys/class/net/brlan0/bridge/multicast_snooping", 1);
    }
    else
    {
        _write_sysctl_file("/sys/class/net/brlan0/bridge/multicast_snooping", 0);
    }

#if !defined (_COSA_BCM_MIPS_)
    if ( (pid_f = fopen("/var/run/ecmh.pid", "r")) != NULL )
    {
        if(fgets(buffer, 255,pid_f) != '\0')
        {
            fclose(pid_f);
            pid_f = NULL;
            sscanf( buffer, "%d", &pid);
            CcspTraceWarning(("Sending SIGUSR1 to proccess %d...\n", pid));
            if ( kill(pid,SIGUSR1) == -1 )
            {
                if ( pCfg->bEnabled == TRUE )
                {
                    sprintf(buffer, "/usr/sbin/ecmh -i wan0");
                    system(buffer);
                }
            }
            else
            {
                if ( pCfg->bEnabled == FALSE )
                {
                    kill(pid,SIGKILL);
                }
            }
        }

        if(pid_f) /*RDKB-6846, CID-33252, CID-33248, Free unused resources before exit*/
            fclose(pid_f);

    }
    else
    {
        if ( pCfg->bEnabled == TRUE )
        {
            sprintf(buffer, "/usr/sbin/ecmh -i wan0");
            system(buffer);
        }
    }
#endif
    return ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
CosaDmlMldGetGroup
    (
        ANSC_HANDLE                 hContext,
        PULONG                      pulCount,
        PCOSA_DML_MLD_GROUP         pMldGroupArray        
    )
{
    FILE *stat_f, *pid_f;
    char buffer[1024];
    pid_t pid;
    char *pch;
    long count;

    if (!pulCount || !pMldGroupArray)
    {
        return ANSC_STATUS_FAILURE;
    }

    if ( (pid_f = fopen("/var/run/ecmh.pid", "r")) != NULL )
    {
        if(fgets(buffer, 255,pid_f) != '\0')
        {
            fclose(pid_f);
            pid_f = NULL;
            sscanf( buffer, "%d", &pid);
            CcspTraceWarning(("Sending SIGUSR1 to proccess %d...\n", pid));
            if ( kill(pid,SIGUSR1) == -1 )
            {
                return ANSC_STATUS_FAILURE;
            }
        }

        if(pid_f)
            fclose(pid_f); /*RDKB-6846, CID-33197, free unused resources before exit*/

    }
    else
    {
        return ANSC_STATUS_FAILURE;
    }

    sleep(1);   /* waits until the stat file is generated */

    *pulCount = 0;
    count = -1;

    if ( (stat_f = fopen("/var/run/ecmh.dump", "r")) != NULL )
    {
        fgets(buffer, 255, stat_f); /* Ignore the first line */
        
        while(fgets(buffer, 255,stat_f) != '\0')
        {
            pch = strtok(buffer, " \t\r\n");
            if (pch == NULL)
            {
                continue;
            }

            if (strcmp(pch, "Group") == 0)
            {
                pch = strtok(NULL, " \t\r\n");
                while(pch)
                {
                    if (*pch != ':')
                    {
                        count++;
                        if (count >= MLD_MAXINSTANCE)
                        {
                            *pulCount = count;
                            fclose(stat_f); /*RDKB-6846, CID-33403, free unused resources before exit*/
                            return ANSC_STATUS_SUCCESS;
                        }
                        
                        strcpy(pMldGroupArray[count].GroupAddress, pch);
                        pMldGroupArray[count].Interfaces[0] = '\0';

                        break;
                    }
                    pch = strtok(NULL, " \t\r\n");
                }
            }
            else if (strcmp(pch, "Interface:") == 0)
            {
                pch =strtok(NULL, " \t\r\n");
                if (pch)
                {
                    strcat(pMldGroupArray[count].Interfaces, pch);
                    strcat(pMldGroupArray[count].Interfaces, ",");
                }
            }
            else if (strcmp(pch, "***") == 0)
            {
                break;
            }
        }

        fclose(stat_f);
    }
    else
    {
        return ANSC_STATUS_FAILURE;
    }

    *pulCount = count+1;
    return ANSC_STATUS_SUCCESS;
}