diff --git a/Changelog b/Changelog new file mode 100644 index 0000000000000000000000000000000000000000..36b112262f2242d16a51b31cd4ff3ee3a8320e36 --- /dev/null +++ b/Changelog @@ -0,0 +1,5 @@ +------------------------------------------------------------------------------- + version 1.0.0.0 | 2016-1-07 | +------------------------------------------------------------------------------- +Spilted API's for ugwframework and list manipulation purposes. + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..71319c8d8a6ac8e410715bf87a29132860f04cc3 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +# ******************************************************************************** # +# Copyright (c) 2015 # +# Lantiq Beteiligungs-GmbH & Co. KG # +# Lilienthalstrasse 15, 85579 Neubiberg, Germany # +# For licensing information, see the file 'LICENSE' in the root folder of # +# this software module. # +# ******************************************************************************* # + +PKG_NAME:= libhelper + +CFLAGS := $(strip $(subst -DPACKAGE_ID=\"libhelper\",,$(CFLAGS))) -DPACKAGE_ID=\"libhelper\" +CFLAGS := $(strip $(subst -DLOGGING_ID="libhelper",,$(CFLAGS))) -DLOGGING_ID="libhelper" + +opt_no_flags := -Wcast-qual + +bins := libhelper.so + +libhelper.so_sources := $(wildcard *.c) +libhelper.so_cflags := -I./include/ +libhelper.so_ldflags := + +include make.inc diff --git a/README b/README new file mode 100644 index 0000000000000000000000000000000000000000..1dfda70f566d68a04a3e2c2fbb4601e1e05a9e36 --- /dev/null +++ b/README @@ -0,0 +1,6 @@ +Helper Library +============== + +Helper library is framework library, which contains API's, enums, defs, structs and +these lib provides functions for list manipulation, debugging, and logging framework + diff --git a/VERSION b/VERSION new file mode 100644 index 0000000000000000000000000000000000000000..ed8769ea40a8b413598a1ae380db1d7959f43133 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.0.4.0 diff --git a/fapi_init_sequence.c b/fapi_init_sequence.c new file mode 100644 index 0000000000000000000000000000000000000000..cbfef5b381ad3e2fac256b35ca703b6359f48c9a --- /dev/null +++ b/fapi_init_sequence.c @@ -0,0 +1,19 @@ +#include "fapi_init_sequence.h" +#include <syslog.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> + +int sequence = 0; + +void log_fapi_init_msg(const char* file, const char *func, const int line) +{ + syslog(LOG_DEBUG, "FAPI_INIT: %s [%s:%d] FAPI sequence number: %d Process ID: %d\n", file, func, line, ++sequence, getpid()); + +} + +void log_fapi_done_msg(const char* file, const char *func, const int line) +{ + + syslog(LOG_DEBUG, "FAPI_INIT: %s [%s:%d]\n", file, func, line); +} diff --git a/help_debug.c b/help_debug.c new file mode 100755 index 0000000000000000000000000000000000000000..a3d57a5052b2ecd5d50e4b999eaa80911507b522 --- /dev/null +++ b/help_debug.c @@ -0,0 +1,275 @@ +/******************************************************************************** + + Copyright (c) 2015 + Lantiq Beteiligungs-GmbH & Co. KG + Lilienthalstrasse 15, 85579 Neubiberg, Germany + For licensing information, see the file 'LICENSE' in the root folder of + this software module. + +********************************************************************************/ + +/* ****************************************************************************** + * File Name : ugw_debug.c * + * Description : Memory Debug Library to check Memory Leaks * + * ******************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include "help_objlist.h" + +#ifdef MEM_DEBUG +#define OFFSET 0 + +MemDbgUtil *pxHead; + +/* ============================================================================= + * Function Name : help_storeMemInfo * + * Description : Function to updated internal list for every allocation* + * and free * + * ============================================================================*/ +static MemDbgUtil* help_storeMemInfo(void *vId,uint32_t iSize,char *pcFile, uint32_t iLine) +{ + MemDbgUtil *pxNew, *pxPrev, *pxCurr; + if((pxNew = calloc(1,sizeof(MemDbgUtil))) != NULL) + { + pxNew->vId = vId; + pxNew->iSize = iSize; + pxNew->iLine = iLine; + strcpy(pxNew->acFile,pcFile+OFFSET); + pxNew->pxNext = NULL; + } + else + { + LOGF_LOG_CRITICAL("Memory allocation failed\n"); + } + if(pxHead == NULL) + { + pxHead = pxNew; + } + else + { + pxPrev = pxCurr = pxHead; + while((pxCurr!=NULL) && (pxCurr->pxNext != NULL)) + { + pxPrev = pxCurr; + pxCurr = pxCurr->pxNext; + } + if(pxCurr != NULL) + { + pxCurr->pxNext = pxNew; + } + else + { + pxPrev->pxNext = pxNew; + } + } + return pxNew; +} + +/* ============================================================================= + * function name : help_locatememinfo * + * description : function to get memory information from internal list * + * ============================================================================*/ +static MemDbgUtil* help_locateMemInfo(void *vId, MemDbgUtil **pxPrevNode) +{ + MemDbgUtil *pxCurr, *pxPrev=NULL; + pxCurr = pxHead; + while((pxCurr!=NULL) && (pxCurr->vId != vId)) + { + pxPrev = pxCurr; + pxCurr = pxCurr->pxNext; + } + if(pxPrevNode != NULL) + { + *pxPrevNode = pxPrev; + } + return pxCurr; +} + +/* ============================================================================= + * function name : help_bytesAllocated * + * description : function to get number of allocated bytes * + * ============================================================================*/ +static int32_t help_bytesAllocated(int32_t *piNumBytes) +{ + int32_t iCount=0,iNumAllocs=0; + MemDbgUtil *pxCurr; + pxCurr = pxHead; + while(pxCurr != NULL) + { + iCount += pxCurr->iSize; + iNumAllocs++; + pxCurr = pxCurr->pxNext; + } + if(piNumBytes != NULL) + { + *piNumBytes = iCount; + } + return iNumAllocs; +} + +#endif + +/* ============================================================================= + * function name : help_free * + * description : function to free the allocated bytes * + * ============================================================================*/ +int help_free(void* pcFree, char *pcFile, uint32_t iLine) +{ +#ifdef MEM_DEBUG + MemDbgUtil *pxCurr, *pxPrev; + if((pxCurr = help_locateMemInfo(pcFree,&pxPrev)) != NULL) + { + if(pxPrev != NULL) + { + pxPrev->pxNext = pxCurr->pxNext; + } + else + { + pxHead = pxCurr->pxNext; + } + free(pxCurr); + pxCurr = NULL; + } + else{ + LOGF_LOG_DEBUG("Already Freed %p Line: %d File: %s\n",pcFree,iLine,pcFile+OFFSET); + } + + if(pcFree) + { + int iSize1, iNumAllocs; + iNumAllocs=help_bytesAllocated(&iSize1); + LOGF_LOG_DEBUG("Freed %p Line: %d File: %s TotalAllocs = %d\n",pcFree,iLine,pcFile+OFFSET,iNumAllocs); + free(pcFree); + pcFree = NULL; + } + return UGW_SUCCESS; +#else + UNUSED_VAR(pcFile); + UNUSED_VAR(iLine); + if(pcFree) + { + free(pcFree); + pcFree = NULL; + } + return UGW_SUCCESS; +#endif +} + +/* ============================================================================= + * function name : help_callocDbg * + * description : function to allocate memory * + * ============================================================================*/ +void* help_calloc(uint32_t uiNum, uint32_t iSize, char *pcFile, uint32_t iLine) +{ +#ifdef MEM_DEBUG + MemDbgUtil *pxMemDbg; + int32_t iNumAllocs, iSize1=0; + void *pTemp; + + pTemp = calloc(uiNum,iSize + 1); + if(pTemp == NULL) + { + LOGF_LOG_CRITICAL("Memory allocation failed\n"); + return NULL; + } + + if((pxMemDbg = help_storeMemInfo(pTemp,iSize,pcFile,iLine)) == NULL) + { + help_free(pTemp,pcFile,iLine); + return NULL; + } + iNumAllocs=help_bytesAllocated(&iSize1); + LOGF_LOG_DEBUG("Alloc at addr %p ,Bytes Alloc %d ,File %s line %d , TotalAllocs = %d\n", + pTemp,(iSize*uiNum),pcFile+OFFSET,iLine,iNumAllocs); + memset(pTemp, 0, iSize); + return pTemp; +#else + UNUSED_VAR(pcFile); + UNUSED_VAR(iLine); + return calloc(uiNum,iSize); +#endif +} + +/* ============================================================================= + * function name : help_malloc * + * description : function to allocate memory * + * ============================================================================*/ +void* help_malloc(uint32_t unSize, char *pcFile, uint32_t iLine) +{ +#ifdef MEM_DEBUG + return help_calloc(1,unSize,pcFile,iLine); +#else + UNUSED_VAR(pcFile); + UNUSED_VAR(iLine); + return calloc(1,unSize); +#endif +} + +/* ============================================================================= + * function name : help_realloc * + * description : function to allocate memory * + * ============================================================================*/ +void* help_realloc(void *pPtr,uint32_t unSize, char *pcFile, uint32_t iLine) +{ + +#ifdef MEM_DEBUG + MemDbgUtil *pxMemDbg; + int32_t iNumAllocs, iSize1=0; + void *pTemp; + + pTemp = realloc(pPtr,unSize); + + if(pTemp == NULL) + { + LOGF_LOG_CRITICAL("Memory allocation failed\n"); + return NULL; + } + + if((pxMemDbg = help_storeMemInfo(pTemp,unSize,pcFile,iLine)) == NULL) + { + help_free(pTemp,pcFile,iLine); + return NULL; + } + iNumAllocs=help_bytesAllocated(&iSize1); + LOGF_LOG_DEBUG("Alloc at addr %p ,Bytes Alloc %d ,File %s line %d , TotalAllocs = %d\n", + pTemp,(unSize*1),pcFile+OFFSET,iLine,iNumAllocs); + + + HELP_FREE(pPtr); + + return pTemp; +#else + UNUSED_VAR(pcFile); + UNUSED_VAR(iLine); + void *pTmp; + pTmp = realloc(pPtr,unSize); + return pTmp; +#endif + +} + +/* ============================================================================= + * function name : help_memInfo * + * description : function to dump allocated memory details * + * ============================================================================*/ +void help_memInfo() +{ +#ifdef MEM_DEBUG + MemDbgUtil *pxCurr; + pxCurr = pxHead; + fprintf(stderr,"\n---------------MEMORY INFO START--------------"); + fprintf(stderr,"\n----------------------------------------------"); + fprintf(stderr,"\n Address | Size | Line | File name"); + fprintf(stderr,"\n----------------------------------------------"); + while(pxCurr != NULL){ + fprintf(stderr,"\n%8x | %5u | %4d | %s",(uint32_t)pxCurr->vId,pxCurr->iSize,pxCurr->iLine, + pxCurr->acFile); + pxCurr = pxCurr->pxNext; + } + fprintf(stderr,"\n----------------------------------------------"); + fprintf(stderr,"\n---------------MEMORY INFO END----------------\n"); +#else + printf("Debug not enabled \n"); +#endif +} diff --git a/help_list.c b/help_list.c new file mode 100644 index 0000000000000000000000000000000000000000..6c14cdb009f61fd2987d3be2b82952a862d7192f --- /dev/null +++ b/help_list.c @@ -0,0 +1,1551 @@ +/******************************************************************************** + + Copyright (c) 2015 + Lantiq Beteiligungs-GmbH & Co. KG + Lilienthalstrasse 15, 85579 Neubiberg, Germany + For licensing information, see the file 'LICENSE' in the root folder of + this software module. + +********************************************************************************/ + +/* ****************************************************************************** + * File Name : ugw_list.c * + * Description : helper Library , which contains list manipulation * + * fuctions used across the system * + * ******************************************************************************/ +#define _GNU_SOURCE + +#include <stdio.h> +#include <string.h> +#include "help_objlist.h" + +#ifndef LOG_LEVEL +uint16_t LOGLEVEL = SYS_LOG_DEBUG + 1; +#else +uint16_t LOGLEVEL = LOG_LEVEL + 1; +#endif + +#ifndef LOG_TYPE +uint16_t LOGTYPE = SYS_LOG_TYPE_FILE; +#else +uint16_t LOGTYPE = LOG_TYPE; +#endif + +/* \brief Helper function that removes the index suffix from the string and returns it as integer + \param[in,out] s - string with index suffix and "_" separator between them. + \return for legal value returned the index number, for ERROR cases returned -1 +*/ +static int indexFromString(char *s); + + +/* ============================================================================= + * Function Name : help_storeLocalDB * + * Description : Function to dump to objlist to local tmp file. * + * ============================================================================*/ +int help_storeLocalDB(ObjList *wlObj, const char *pcPath) +{ + char *paramNamePtr; + char *paramValuePtr; + char *objName; + int objIndex = 0; //running index + int nRet = UGW_SUCCESS; + + ObjList *obj; + ParamList *param; + + FILE *fp = fopen(pcPath, "w"); + if (!fp) { + LOGF_LOG_ERROR("Failed to open file for writing : %s\n",pcPath); + nRet = UGW_FAILURE; + goto finish; + } + + if (!wlObj) { + LOGF_LOG_ERROR("ERROR Null Pointer WlObj, can't return data \n"); + nRet = UGW_FAILURE; + goto finish; + } + + FOR_EACH_OBJ(wlObj, obj) { + objName = GET_OBJ_NAME(obj); + //Write Obj name to loacl file + fprintf(fp, "Object_%d=%s\n", objIndex, objName); + + FOR_EACH_PARAM(obj,param) { + paramNamePtr = GET_PARAM_NAME(param); + paramValuePtr = GET_PARAM_VALUE(param); + + fprintf(fp, "%s_%d=%s\n",paramNamePtr, objIndex, paramValuePtr); + } + objIndex++;; + } + +finish: + if(fp) + fclose(fp); + return nRet; +} + +/* ============================================================================= + * Function Name : help_loadLocalDB * + * Description : Function to fill to objlist from local tmp file data * + * ============================================================================*/ +int help_loadLocalDB(ObjList* wlObj, const char *pcPath) +{ + FILE* fp; + char* line = NULL; + + unsigned int len = 0; + + char* parameterName = NULL; + char* parameterValue = NULL; + + int objCurrentIdx = -1; + char objCurrentName[MAX_LEN_PARAM_NAME]; + + ObjList* obj = NULL; + int nRet = UGW_SUCCESS; + + fp = fopen(pcPath, "r"); + if (fp == NULL){ + LOGF_LOG_ERROR("File Not Found : %s\n",pcPath); + nRet = UGW_FAILURE; + goto finish; + } + + if ( wlObj == NULL) { + LOGF_LOG_ERROR("ERROR Null Pointer WlObj, can't return data \n"); + nRet = UGW_FAILURE; + goto finish; + } + + obj = wlObj; + while ( getline(&line, &len, fp) != -1 ) { + parameterName=strtok(line, "="); + parameterValue=strtok(NULL, "\n"); + + + if (parameterName == NULL) + { + nRet = UGW_FAILURE; + goto finish; + } + + if(parameterValue == NULL) + { + continue; + } + + if ( ! strncmp(parameterName, "Object", strlen("Object")) ) { + objCurrentIdx = indexFromString(parameterName); + if ( objCurrentIdx < 0 ) { + LOGF_LOG_ERROR("Illegal Object Index \n"); + nRet = UGW_FAILURE; + goto finish; + } + + //strcpy(objCurrentName, parameterValue); + snprintf(objCurrentName, MAX_LEN_OBJNAME, "%s", parameterValue); + obj = help_addObjList(obj, objCurrentName, 0, 0, 0, 0); + continue; + } + + if ( indexFromString(parameterName) != objCurrentIdx ) { + LOGF_LOG_ERROR("Parameter Index not equal to Object Index \n"); + nRet = UGW_FAILURE; + goto finish; + } + + HELP_EDIT_SELF_NODE(obj, objCurrentName, parameterName, parameterValue, 0, 0); + } + +finish: + if ( fp ) + fclose(fp); + if ( line ) + free(line); + return nRet; +} + + +/* ============================================================================= + * Function Name : help_updateObjName * + * Description : Function to update object incase object name doesnt * + * end with "." + * ============================================================================*/ +static void help_updateObjName( ObjList *pxObjSrc, ObjList *pxObjDst) +{ + ObjList *pxTmpObj; + char sBuf[MAX_LEN_OBJNAME]={0}; + int nObjLen=0; + + FOR_EACH_OBJ(pxObjSrc, pxTmpObj) + { + sBuf[0]='\0'; + nObjLen = strlen(pxTmpObj->sObjName); + if (nObjLen > 1) + { + if(pxTmpObj->sObjName[nObjLen-1] != '.') + { + snprintf(sBuf, MAX_LEN_OBJNAME-1, "%s.", pxTmpObj->sObjName); + snprintf(pxTmpObj->sObjName, MAX_LEN_OBJNAME, "%s", sBuf); + } + } + } + + FOR_EACH_OBJ(pxObjDst, pxTmpObj) + { + sBuf[0]='\0'; + nObjLen = strlen(pxTmpObj->sObjName); + if (nObjLen > 1) + { + if(pxTmpObj->sObjName[nObjLen-1] != '.') + { + snprintf(sBuf, MAX_LEN_OBJNAME-1, "%s.", pxTmpObj->sObjName); + snprintf(pxTmpObj->sObjName, MAX_LEN_OBJNAME, "%s", sBuf); + } + } + } +} + + + +/* ============================================================================= + * Function Name : help_addAttrObjList * + * Description : Function to add attr object to the head node * + * ============================================================================*/ +OUT ObjAttrList * help_addObjAttrList(IN ObjAttrList *pxObjList, IN const char *pcObjName, IN const char *pcWebName,IN uint32_t unFlag) +{ + ObjAttrList *pxTmp; + pxTmp = HELP_MALLOC(sizeof(ObjAttrList)); + if(!pxTmp) + { + LOGF_LOG_CRITICAL(" malloc failed\n"); + return NULL; + } + + if(pcObjName != NULL) + { + snprintf(pxTmp->sObjName,MAX_LEN_OBJNAME, "%s",pcObjName); + } + + if(pcWebName != NULL) + { + snprintf(pxTmp->sObjWebName,MAX_LEN_WEBNAME, "%s",pcWebName); + } + + pxTmp->unObjAttr = unFlag; + + INIT_LIST_HEAD(&pxTmp->xParamAttrList.xPlist); + list_add_tail( &(pxTmp->xOlist), &(pxObjList->xOlist) ); + return pxTmp; +} + +/* ============================================================================= + * Function Name : help_addParamAttrList * + * Description : Function to add parameter list to the head node * + * ============================================================================*/ +ParamAttrList * help_addParamAttrList(IN ObjAttrList *pxObjList,IN const char *pcParamName, IN const char *pcParamProfile, + IN const char *pcParamWebName, IN const char *pcValidVal,IN const char *pcParamValue, + IN uint32_t unMinVal, IN uint32_t unMaxVal, IN uint32_t unMinLen, IN uint32_t unMaxLen, + IN uint32_t unParamFlag) +{ + ParamAttrList *pxTmp; + pxTmp = HELP_MALLOC(sizeof(ParamAttrList)); + if(!pxTmp) + { + LOGF_LOG_CRITICAL("malloc failed\n"); + return NULL; + } + + if(pcParamName != NULL) + { + snprintf(pxTmp->sParamName, MAX_LEN_PARAM_NAME, "%s", pcParamName); + } + + if(pcParamProfile != NULL) + { + snprintf(pxTmp->sParamProfile, MAX_LEN_PROFILENAME, "%s", pcParamProfile); + } + + if(pcParamWebName != NULL) + { + snprintf(pxTmp->sParamWebName,MAX_LEN_WEBNAME, "%s",pcParamWebName); + } + + if(pcValidVal != NULL) + { + snprintf(pxTmp->sParamValidVal, MAX_LEN_VALID_VALUE, "%s", pcValidVal); + } + + if(pcParamValue != NULL) + { + snprintf(pxTmp->sParamValue, MAX_LEN_PARAM_VALUE, "%s", pcParamValue); + } + + pxTmp->unMinVal = unMinVal; + pxTmp->unMaxVal = unMaxVal; + pxTmp->unMinLen = unMinLen; + pxTmp->unMaxLen = unMaxLen; + pxTmp->unParamFlag = unParamFlag; + + list_add_tail( &(pxTmp->xPlist), &(pxObjList->xParamAttrList.xPlist) ); + return pxTmp; +} + +/* ============================================================================= + * Function Name : help_addAcsObjList * + * Description : Function to add object to the head node * + * ============================================================================*/ +OUT ObjACSList * help_addAcsObjList(IN ObjACSList *pxObjList, IN const char *pcObjName, IN uint32_t unObjOper, IN uint32_t unFlag) +{ + ObjACSList *pxTmp; + pxTmp = HELP_MALLOC(sizeof(ObjACSList)); + if(!pxTmp) + { + LOGF_LOG_CRITICAL(" malloc failed\n"); + return NULL; + } + + if((pcObjName != NULL) && (strlen(pcObjName) < MAX_LEN_OBJNAME) ) + { + memset(pxTmp->sObjName, 0x0, MAX_LEN_OBJNAME); + snprintf(pxTmp->sObjName, MAX_LEN_OBJNAME, "%s", pcObjName); + } + else + { + if(pcObjName != NULL) + { + LOGF_LOG_CRITICAL("Object Name Buffer OverFlow [%s]\n",pcObjName); + } + HELP_FREE(pxTmp); + return NULL; + } + + pxTmp->unObjOper = unObjOper; + pxTmp->unObjFlag = unFlag; + + INIT_LIST_HEAD(&pxTmp->xParamAcsList.xPlist); + list_add_tail( &(pxTmp->xOlist), &(pxObjList->xOlist) ); + return pxTmp; +} + +/* ============================================================================= + * Function Name : help_addAcsParamList * + * Description : Function to add parameter list to the head node * + * ============================================================================*/ +OUT ParamACSList * help_addAcsParamList(IN ObjACSList *pxObjList, IN const char *pcParamName, + IN const char *pcParamValue,IN uint32_t unFlag) +{ + ParamACSList *pxTmp; + pxTmp = HELP_MALLOC(sizeof(ParamACSList)); + if(!pxTmp) + { + LOGF_LOG_CRITICAL("malloc failed\n"); + return NULL; + } + + if( (pcParamName != NULL) && (strlen(pcParamName) < MAX_LEN_PARAM_NAME) ) + { + memset(pxTmp->sParamName, 0x0, MAX_LEN_PARAM_NAME); + snprintf(pxTmp->sParamName, MAX_LEN_PARAM_NAME, "%s", pcParamName); + } + else + { + if(pcParamName != NULL) + { + LOGF_LOG_CRITICAL("Param Name Buffer OverFlow ParamName[%s]: ParamNameLen[%zu]\n",pcParamName,strlen(pcParamName)); + } + HELP_FREE(pxTmp); + return NULL; + } + + if((pcParamValue != NULL) && (strlen(pcParamValue) < MAX_LEN_PARAM_VALUE) ) + { + memset(pxTmp->sParamValue, 0x0, MAX_LEN_PARAM_VALUE); + snprintf(pxTmp->sParamValue, MAX_LEN_PARAM_VALUE, "%s", pcParamValue); + } + else + { + if((pcParamValue != NULL)) + { + LOGF_LOG_CRITICAL("Param Value Buffer OverFlow ParamName [%s] ParamValue[%s]: ParamValueLen[%zu]\n",pcParamName,pcParamValue,strlen(pcParamValue)); + HELP_FREE(pxTmp); + return NULL; + } + } + + pxTmp->unParamFlag=unFlag; + + list_add_tail( &(pxTmp->xPlist), &(pxObjList->xParamAcsList.xPlist) ); + + return pxTmp; +} + +/* ============================================================================= + * Function Name : help_addObjList * + * Description : Function to add object to the head node * + * ============================================================================*/ +OUT ObjList * help_addObjList(IN ObjList *pxObjList, IN const char *pcObjName, IN uint16_t unSid, IN uint16_t unOid, IN uint32_t unObjOper, IN uint32_t unFlag) +{ + ObjList *pxTmp; + pxTmp = HELP_MALLOC(sizeof(ObjList)); + if(!pxTmp) + { + LOGF_LOG_CRITICAL(" malloc failed\n"); + return NULL; + } + + if((pcObjName != NULL) && (strlen(pcObjName) < MAX_LEN_OBJNAME) ) + { + memset(pxTmp->sObjName, 0x0, MAX_LEN_OBJNAME); + snprintf(pxTmp->sObjName, MAX_LEN_OBJNAME, "%s", pcObjName); + } + else + { + LOGF_LOG_CRITICAL("Object Name Buffer OverFlow [%s]\n",pcObjName); + HELP_FREE(pxTmp); + return NULL; + } + + pxTmp->unSid = unSid; + pxTmp->unOid = unOid; + pxTmp->unObjOper = unObjOper; + pxTmp->unObjFlag = unFlag; + + INIT_LIST_HEAD(&pxTmp->xParamList.xPlist); + list_add_tail( &(pxTmp->xOlist), &(pxObjList->xOlist) ); + return pxTmp; +} + +/* ============================================================================= + * Function Name : help_addParamList * + * Description : Function to add parameter list to the head node * + * ============================================================================*/ +OUT ParamList * help_addParamList(IN ObjList *pxObjList,IN const char *pcParamName, IN uint16_t unParamId, + IN const char *pcParamValue,IN uint32_t unFlag) +{ + ParamList *pxTmp; + pxTmp = HELP_MALLOC(sizeof(ParamList)); + if(!pxTmp) + { + LOGF_LOG_CRITICAL("malloc failed\n"); + return NULL; + } + + if( (pcParamName != NULL) && (strlen(pcParamName) < MAX_LEN_PARAM_NAME) ) + { + memset(pxTmp->sParamName, 0x0, MAX_LEN_PARAM_NAME); + snprintf(pxTmp->sParamName, MAX_LEN_PARAM_NAME, "%s", pcParamName); + } + else + { + if(pcParamName != NULL) + { + LOGF_LOG_CRITICAL("Param Name Buffer OverFlow ParamName[%s]: ParamNameLen[%zu]\n",pcParamName,strlen(pcParamName)); + } + HELP_FREE(pxTmp); + return NULL; + } + + + pxTmp->unParamId = unParamId; + + if((pcParamValue != NULL) && (strlen(pcParamValue) < MAX_LEN_PARAM_VALUE) ) + { + memset(pxTmp->sParamValue, 0x0, MAX_LEN_PARAM_VALUE); + snprintf(pxTmp->sParamValue, MAX_LEN_PARAM_VALUE, "%s", pcParamValue); + } + else + { + if((pcParamValue != NULL)) + { + LOGF_LOG_CRITICAL("Param Value Buffer OverFlow ParamName [%s] ParamValue[%s]: ParamValueLen[%zu]\n",pcParamName,pcParamValue,strlen(pcParamValue)); + HELP_FREE(pxTmp); + return NULL; + } + } + + pxTmp->unParamFlag=unFlag; + + list_add_tail( &(pxTmp->xPlist), &(pxObjList->xParamList.xPlist) ); + + return pxTmp; +} + +/* ============================================================================= + * Function Name : help_paramListOnly * + * Description : Function to add parameter list to the head node * + * ============================================================================*/ +ParamList * help_paramListOnly(IN ParamList *pxParamList,IN const char *pcParamName, IN uint16_t unParamId, + IN const char *pcParamValue,IN uint32_t unFlag) +{ + ParamList *pxTmp; + pxTmp = HELP_MALLOC(sizeof(ParamList)); + if(!pxTmp) + { + LOGF_LOG_CRITICAL(" malloc failed\n"); + return NULL; + } + + if((pcParamName != NULL) && (strlen(pcParamName) < MAX_LEN_PARAM_NAME) ) + { + memset(pxTmp->sParamName, 0x0, MAX_LEN_PARAM_NAME); + snprintf(pxTmp->sParamName, MAX_LEN_PARAM_NAME, "%s", pcParamName); + } + else + { + if(pcParamName != NULL) + { + LOGF_LOG_CRITICAL(" Param Name Buffer OverFlow [%s] \n",pcParamName); + } + HELP_FREE(pxTmp); + return NULL; + } + + pxTmp->unParamId = unParamId; + + if((pcParamValue != NULL) && (strlen(pcParamValue) < MAX_LEN_PARAM_VALUE) ) + { + memset(pxTmp->sParamValue, 0x0, MAX_LEN_PARAM_VALUE); + snprintf(pxTmp->sParamValue, MAX_LEN_PARAM_VALUE, "%s", pcParamValue); + } + else + { + if((pcParamValue != NULL)) + { + LOGF_LOG_CRITICAL("Param Value Buffer OverFlow ParamName [%s] ParamValue[%s]: ParamValueLen[%zu]\n",pcParamName,pcParamValue,strlen(pcParamValue)); + HELP_FREE(pxTmp); + return NULL; + } + } + + pxTmp->unParamFlag=unFlag; + + list_add_tail( &(pxTmp->xPlist), &(pxParamList->xPlist) ); + return pxTmp; +} + +/* ============================================================================= + * Function Name : help_printObj * + * Description : Function to traverse list and dump object name,id * + * ============================================================================*/ +void help_printObj(IN void *pxObj,uint32_t unSubOper) +{ + if (IS_OBJLIST(unSubOper)) + { + ObjList *pxTmpObj; + ParamList *pxParam; + + printf("\n @@@ PRINT OBJLIST START @@@\n"); + + FOR_EACH_OBJ(pxObj,pxTmpObj) + { + printf("\"%s\": { \n",GET_OBJ_NAME(pxTmpObj)); + printf("\t\t \"Sid\" :\"%d\",\n",GET_OBJ_SID(pxTmpObj)); + printf("\t\t \"Oid\" : \"%d\",\n", GET_OBJ_OID(pxTmpObj)); + + if (IS_SOPT_OBJNAME(unSubOper)) + { + printf("\t\t \"ObjOper\" : \"%d\"\n",GET_OBJ_SUBOPER(pxTmpObj)); + } + else + { + printf("\t\t \"ObjOper\" : \"%d\",\n",GET_OBJ_SUBOPER(pxTmpObj)); + } + + printf("\t\t \"Flag\" : \"0x%x\",\n",GET_OBJ_FLAG(pxTmpObj)); + + FOR_EACH_PARAM(pxTmpObj,pxParam) + { + + printf("\t\t \"%s\": { \n",GET_PARAM_NAME(pxParam)); + printf("\t\t\t \"paramId\" : \"%d\",\n",GET_PARAM_ID(pxParam)); + printf("\t\t\t \"paramValue\" : \"%s\",\n",GET_PARAM_VALUE(pxParam)); + printf("\t\t\t \"paramFlag\" : \"0x%x\"\n",GET_PARAM_FLAG(pxParam)); + printf("\t\t },\n"); + } + printf("\t },\n"); + } + printf(" }\n"); + printf("\n @@@@@@ PRINT OBJLIST END @@@@@@\n"); + } + else if (IS_SOPT_OBJATTR(unSubOper)) + { + ObjAttrList *pxTmpAttrObj; + ParamAttrList *pxAttrParam; + + FOR_EACH_OBJATTR(pxObj,pxTmpAttrObj) + { + fprintf(stderr,"\t \"%s\": { \n",GET_ATTR_OBJNAME(pxTmpAttrObj)); + fprintf(stderr,"\t\t \"WebName\" :\"%s\",\n",GET_ATTR_WEBNAME(pxTmpAttrObj)); + fprintf(stderr,"\t\t \"ObjFlag\" : \"0x%x\",\n",GET_ATTR_FLAG(pxTmpAttrObj)); + FOR_EACH_PARAM_ATTR(pxTmpAttrObj,pxAttrParam) + { + fprintf(stderr,"\t\t \"%s\": { \n",GET_ATTR_PARAMNAME(pxAttrParam)); + fprintf(stderr,"\t\t\t \"paramProfile\" : \"%s\",\n",GET_ATTR_PARAMPROFILE(pxAttrParam)); + fprintf(stderr,"\t\t\t \"paramWebName\" : \"%s\",\n",GET_ATTR_PARAMWEBNAME(pxAttrParam)); + fprintf(stderr,"\t\t\t \"paramValidVal\" : \"%s\",\n",pxAttrParam->sParamValidVal); + fprintf(stderr,"\t\t\t \"paramValue\" : \"%s\",\n",GET_ATTR_PARAMVALUE(pxAttrParam)); + fprintf(stderr,"\t\t\t \"paramMinVal\" : \"%d\",\n",GET_ATTR_MINVAL(pxAttrParam)); + fprintf(stderr,"\t\t\t \"paramMaxVal\" : \"%d\",\n",GET_ATTR_MAXVAL(pxAttrParam)); + fprintf(stderr,"\t\t\t \"paramMinLen\" : \"%d\",\n",GET_ATTR_MINLEN(pxAttrParam)); + fprintf(stderr,"\t\t\t \"paramMaxLen\" : \"%d\",\n",GET_ATTR_MAXLEN(pxAttrParam)); + fprintf(stderr,"\t\t\t \"paramFlag\" : \"0x%x\",\n",GET_ATTR_PARAMFLAG(pxAttrParam)); + fprintf(stderr,"\t\t },\n"); + } + fprintf(stderr,"\t },\n"); + } + fprintf(stderr,"}\n"); + } + else if (IS_SOPT_OBJACSATTR(unSubOper)) + { + ObjACSList *pxTmpAcsObj; + ParamACSList *pxAcsParam; + + FOR_EACH_OBJ_ACS_ATTR(pxObj,pxTmpAcsObj) + { + fprintf(stderr,"\t \"%s\": { \n",GET_ACS_OBJNAME(pxTmpAcsObj)); + fprintf(stderr,"\t\t \"ObjOper\" :\"%d\",\n",GET_ACS_OBJOPER(pxTmpAcsObj)); + fprintf(stderr,"\t\t \"ObjFlag\" : \"0x%x\",\n",GET_ACS_OBJFLAG(pxTmpAcsObj)); + FOR_EACH_PARAM_ACS_ATTR(pxTmpAcsObj,pxAcsParam) + { + fprintf(stderr,"\t\t \"%s\": { \n",GET_ACS_PARAMNAME(pxAcsParam)); + fprintf(stderr,"\t\t\t \"AccessList\" : \"%s\",\n",GET_ACS_ACCESSLIST(pxAcsParam)); + if(IS_ATTR_ACTIVE_NOTIFY_SET(GET_ACS_PARAMFLAG(pxAcsParam))) + { + fprintf(stderr,"\t\t\t \"Notification\" : \"Active\",\n"); + } + else if(IS_ATTR_PASSIVE_NOTIFY_SET(GET_ACS_PARAMFLAG(pxAcsParam))) + { + fprintf(stderr,"\t\t\t \"Notification\" : \"Passive\",\n"); + } + else + { + fprintf(stderr,"\t\t\t \"Notification\" : \"Disabled\",\n"); + } + fprintf(stderr,"\t\t\t \"paramFlag\" : \"%d\",\n",pxAcsParam->unParamFlag); + fprintf(stderr,"\t\t },\n"); + } + fprintf(stderr,"\t },\n"); + } + fprintf(stderr,"}\n"); + } +} + +/* ============================================================================= + * Function Name : help_printParamList * + * Description : Function to traverse list and dump paramlist * + * ============================================================================*/ +void help_printParamList(IN ParamList *pxParamList) +{ + ParamList *pxParam; + fprintf(stderr,"{\n"); + FOR_EACH_PARAM_ONLY(pxParamList,pxParam) + { + fprintf(stderr,"\t\t \"%s\": { \n",GET_PARAM_NAME(pxParam)); + fprintf(stderr,"\t\t\t \"paramId\" : \"%d\",\n",(int16_t)GET_PARAM_ID(pxParam)); + fprintf(stderr,"\t\t\t \"paramValue\" : \"%s\",\n",GET_PARAM_VALUE(pxParam)); + fprintf(stderr,"\t\t\t \"paramFlag\" : \"%d\"\n",GET_PARAM_FLAG(pxParam)); + fprintf(stderr,"\t\t }\n"); + } + fprintf(stderr,"}\n"); +} + +/* ============================================================================= + * Function Name : help_delCurObj * + * Description : Function to traverse list and free objects * + * ============================================================================*/ +int help_delCurObj(IN void *pObj, const char * pcObjName, IN uint32_t unSubOper) +{ + if (IS_OBJLIST(unSubOper)) + { + ObjList *pxTempObj; + ParamList *pxParamList; + ObjList *pxObjList; + + pxObjList = pObj; + while( !list_empty(&pxObjList->xOlist) ) + { + if (strcmp(pxObjList->sObjName,pcObjName) == 0) + { + pxTempObj = pxObjList; + while( !list_empty(&pxTempObj->xParamList.xPlist) ) + { + pxParamList = list_entry(pxTempObj->xParamList.xPlist.next,ParamList,xPlist); + list_del(&pxParamList->xPlist); + free(pxParamList); + pxParamList = NULL; + } + list_del(&pxTempObj->xOlist); + free(pxTempObj); + pxTempObj = NULL; + return UGW_SUCCESS; + } + else + { + pxObjList = list_entry(pxObjList->xOlist.next,ObjList,xOlist); + } + } + } + else if (IS_SOPT_OBJATTR(unSubOper)) + { + ObjAttrList *pxTempAttrObj; + ParamAttrList *pxParamAttrList; + ObjAttrList *pxObjAttrList; + + pxObjAttrList = pObj; + while( !list_empty(&pxObjAttrList->xOlist) ) + { + if (strcmp(pxObjAttrList->sObjName,pcObjName) == 0) + { + pxTempAttrObj = list_entry(pxObjAttrList->xOlist.next,ObjAttrList,xOlist); + while( !list_empty(&pxTempAttrObj->xParamAttrList.xPlist) ) + { + pxParamAttrList = list_entry(pxTempAttrObj->xParamAttrList.xPlist.next,ParamAttrList,xPlist); + list_del(&pxParamAttrList->xPlist); + free(pxParamAttrList); + pxParamAttrList = NULL; + } + list_del(&pxTempAttrObj->xOlist); + free(pxTempAttrObj); + pxTempAttrObj = NULL; + return UGW_SUCCESS; + } + } + } +return UGW_SUCCESS; +} +/* ============================================================================= + * Function Name : help_delObj * + * Description : Function to traverse list and free objects * + * ============================================================================*/ +void help_delObj(IN void *pObj, IN uint32_t unSubOper,IN uint32_t unFlag) +{ + if (IS_OBJLIST(unSubOper)) + { + ObjList *pxTempObj; + ParamList *pxParamList; + ObjList *pxObjList; + + pxObjList = pObj; + while( !list_empty(&pxObjList->xOlist) ) + { + pxTempObj = list_entry(pxObjList->xOlist.next,ObjList,xOlist); + while( !list_empty(&pxTempObj->xParamList.xPlist) ) + { + pxParamList = list_entry(pxTempObj->xParamList.xPlist.next,ParamList,xPlist); + list_del(&pxParamList->xPlist); + free(pxParamList); + pxParamList = NULL; + } + list_del(&pxTempObj->xOlist); + free(pxTempObj); + pxTempObj = NULL; + } + } + else if (IS_SOPT_OBJATTR(unSubOper)) + { + ObjAttrList *pxTempAttrObj; + ParamAttrList *pxParamAttrList; + ObjAttrList *pxObjAttrList; + + pxObjAttrList = pObj; + while( !list_empty(&pxObjAttrList->xOlist) ) + { + pxTempAttrObj = list_entry(pxObjAttrList->xOlist.next,ObjAttrList,xOlist); + while( !list_empty(&pxTempAttrObj->xParamAttrList.xPlist) ) + { + pxParamAttrList = list_entry(pxTempAttrObj->xParamAttrList.xPlist.next,ParamAttrList,xPlist); + list_del(&pxParamAttrList->xPlist); + free(pxParamAttrList); + pxParamAttrList = NULL; + } + list_del(&pxTempAttrObj->xOlist); + free(pxTempAttrObj); + pxTempAttrObj = NULL; + } + } + else if (IS_SOPT_OBJACSATTR(unSubOper)) + { + ObjACSList *pxTempAcsObj; + ParamACSList *pxParamAcsList; + ObjACSList *pxObjAcsList; + + pxObjAcsList = pObj; + while( !list_empty(&pxObjAcsList->xOlist) ) + { + pxTempAcsObj = list_entry(pxObjAcsList->xOlist.next,ObjACSList,xOlist); + while( !list_empty(&pxTempAcsObj->xParamAcsList.xPlist) ) + { + pxParamAcsList = list_entry(pxTempAcsObj->xParamAcsList.xPlist.next,ParamACSList,xPlist); + list_del(&pxParamAcsList->xPlist); + free(pxParamAcsList); + pxParamAcsList = NULL; + } + list_del(&pxTempAcsObj->xOlist); + free(pxTempAcsObj); + pxTempAcsObj = NULL; + } + } + + if(unFlag == FREE_OBJLIST) + { + if (pObj != NULL) + { + free(pObj); + } + } +} + +/* ============================================================================= + * Function Name : help_delParam * + * Description : Function to traverse Param list and free objects * + * ============================================================================*/ +void help_delParam(IN void *pParam, IN uint32_t unFlag) +{ + if (IS_OBJLIST(unFlag)) + { + ParamList *pxParamList; + ParamList *pxTmpParamList; + + pxParamList = pParam; + while( !list_empty(&pxParamList->xPlist) ) + { + pxTmpParamList = list_entry(pxParamList->xPlist.next,ParamList,xPlist); + list_del(&pxTmpParamList->xPlist); + free(pxTmpParamList); + pxTmpParamList = NULL; + } + } + if (pParam != NULL) + { + free(pParam); + } +} + +/* ============================================================================= + * Function Name : help_copyObjList * + * Description : copy current objlist to new objlist * + * ============================================================================*/ +void help_copyObjList(IN void *pDst , IN uint32_t unFlag , OUT void *pSrc) +{ + if (IS_OBJLIST(unFlag)) + { + void *pxTObj; + ParamList *pxParam; + ObjList *pxSrcObj; + pxSrcObj = pSrc; + pxTObj = help_addObjList(pDst,GET_OBJ_NAME(pxSrcObj), + GET_OBJ_SID(pxSrcObj), + GET_OBJ_OID(pxSrcObj), + GET_OBJ_SUBOPER(pxSrcObj), + GET_OBJ_FLAG(pxSrcObj)); + FOR_EACH_PARAM(pxSrcObj,pxParam) + { + help_addParamList(pxTObj,GET_PARAM_NAME(pxParam), + GET_PARAM_ID(pxParam), + GET_PARAM_VALUE(pxParam), + GET_PARAM_FLAG(pxParam)); + } + } + else if (IS_SOPT_OBJATTR(unFlag)) + { + void *pxTObj; + ParamAttrList *pxParam; + ObjAttrList *pxSrcObj; + pxSrcObj = pSrc; + pxTObj = help_addObjAttrList(pDst,GET_ATTR_OBJNAME(pxSrcObj), + GET_ATTR_WEBNAME(pxSrcObj), + GET_ATTR_FLAG(pxSrcObj)); + FOR_EACH_PARAM_ATTR(pxSrcObj,pxParam) + { + help_addParamAttrList(pxTObj,GET_ATTR_PARAMNAME(pxParam), + GET_ATTR_PARAMPROFILE(pxParam), + GET_ATTR_PARAMWEBNAME(pxParam), + GET_ATTR_PARAMVALUE(pxParam), + pxParam->sParamValidVal, + GET_ATTR_MINVAL(pxParam), + GET_ATTR_MAXVAL(pxParam), + GET_ATTR_MINLEN(pxParam), + GET_ATTR_MAXLEN(pxParam), + GET_ATTR_PARAMFLAG(pxParam)); + } + } + else if (IS_SOPT_OBJACSATTR(unFlag)) + { + void *pxTObj; + ParamACSList *pxParam; + ObjACSList *pxSrcObj; + pxSrcObj = pSrc; + + pxTObj = help_addAcsObjList(pDst, GET_ACS_OBJNAME(pxSrcObj), GET_ACS_OBJOPER(pxSrcObj), GET_ACS_OBJFLAG(pxSrcObj)); + FOR_EACH_PARAM_ACS_ATTR(pxSrcObj, pxParam) + { + help_addAcsParamList(pxTObj, GET_ACS_PARAMNAME(pxParam), GET_ACS_ACCESSLIST(pxParam), GET_ACS_PARAMFLAG(pxParam)); + } + } +} + +/* ============================================================================= + * Function Name : help_copyObj * + * Description : Function to copy object list as is to tmp objlist * + * ============================================================================*/ +static void help_copyObj(ObjList *pxDst,ObjList *pxSrc) +{ + + ObjList *pxTmpObj=NULL,*pxObj=NULL; + ParamList *pxParam; + list_for_each_entry(pxTmpObj,&(pxSrc->xOlist),xOlist) + { + pxObj = help_addObjList(pxDst,pxTmpObj->sObjName,pxTmpObj->unSid,pxTmpObj->unOid,pxTmpObj->unObjOper,pxTmpObj->unObjFlag); + list_for_each_entry(pxParam,&(pxTmpObj->xParamList.xPlist),xPlist) + { + help_addParamList(pxObj,pxParam->sParamName,pxParam->unParamId,pxParam->sParamValue,pxParam->unParamFlag); + } + } +} + + +/* ============================================================================= + * Function Name : help_addParam * + * Description : Function to add parameter list to the parameter node * + * ============================================================================*/ +static int help_addParam(IN ParamList *pxParam, IN const char *pcParamName, IN uint16_t unParamId, + IN const char *pcParamValue, IN uint32_t unFlag) +{ + ParamList *pxTmp; + pxTmp = HELP_MALLOC(sizeof(ParamList)); + if(!pxTmp) + { + LOGF_LOG_CRITICAL("malloc failed\n"); + return ERR_MEMORY_ALLOC_FAILED; + } + + if((pcParamName != NULL) && (strlen(pcParamName) < MAX_LEN_PARAM_NAME) ) + { + snprintf(pxTmp->sParamName, MAX_LEN_PARAM_NAME, "%s", pcParamName); + } + else + { + if(pcParamName != NULL) + { + LOGF_LOG_CRITICAL("Param Name Buffer OverFlow\n"); + } + HELP_FREE(pxTmp); + return UGW_FAILURE; + } + + pxTmp->unParamId = unParamId; + + if((pcParamValue != NULL) && (strlen(pcParamValue) < MAX_LEN_PARAM_VALUE) ) + { + snprintf(pxTmp->sParamValue, MAX_LEN_PARAM_VALUE, "%s", pcParamValue); + } + else + { + if((pcParamValue != NULL)) + { + LOGF_LOG_CRITICAL("Param value Buffer OverFlow ParamName[%s] ParamValue[%s] ParamLen[%zu]\n",pcParamName, pcParamValue, strlen(pcParamValue)); + HELP_FREE(pxTmp); + return UGW_FAILURE; + } + } + + pxTmp->unParamFlag=unFlag; + + list_add_tail( &(pxTmp->xPlist), &(pxParam->xPlist) ); + + return UGW_SUCCESS; +} + +/* ============================================================================= + * Function Name : help_copyParam * + * Description : Function to copy param list as is to another paramlist* + * ============================================================================*/ +void help_copyParamList(ParamList *pxDst,ParamList *pxSrc) +{ + ParamList *pxParam; + list_for_each_entry(pxParam,&(pxSrc->xPlist),xPlist) + { + help_addParam(pxDst,pxParam->sParamName,pxParam->unParamId,pxParam->sParamValue,pxParam->unParamFlag); + } +} + +/* ============================================================================= + * Function Name : help_copyObjAttr * + * Description : Function to copy object list as is to tmp objlist * + * ============================================================================*/ +static void help_copyObjAttr(ObjAttrList *pxDst,ObjAttrList *pxSrc) +{ + + ObjAttrList *pxTmpObj=NULL,*pxObj=NULL; + ParamAttrList *pxParam; + FOR_EACH_OBJATTR(pxSrc,pxTmpObj) + { + pxObj = help_addObjAttrList(pxDst,pxTmpObj->sObjName,pxTmpObj->sObjWebName,pxTmpObj->unObjAttr); + FOR_EACH_PARAM_ATTR(pxTmpObj,pxParam) + { + help_addParamAttrList(pxObj,pxParam->sParamName,pxParam->sParamProfile,pxParam->sParamWebName, + pxParam->sParamValidVal,pxParam->sParamValue,pxParam->unMinVal, + pxParam->unMaxVal,pxParam->unMinLen,pxParam->unMaxLen,pxParam->unParamFlag); + } + } +} + +/* ============================================================================= + * Function Name : help_copyAcsObj * + * Description : Function to copy acs object list as is to tmp objlist * + * ============================================================================*/ +static void help_copyAcsObj(ObjACSList *pxDst, ObjACSList *pxSrc) +{ + + ObjACSList *pxTmpObj=NULL,*pxObj=NULL; + ParamACSList *pxParam; + FOR_EACH_OBJ_ACS_ATTR(pxSrc,pxTmpObj) + { + pxObj = help_addAcsObjList(pxDst,pxTmpObj->sObjName,pxTmpObj->unObjOper,pxTmpObj->unObjFlag); + FOR_EACH_PARAM_ACS_ATTR(pxTmpObj,pxParam) + { + help_addAcsParamList(pxObj,pxParam->sParamName, pxParam->sParamValue, pxParam->unParamFlag); + } + } +} +/* ============================================================================= + * Function Name : help_copyCompelteObjList * + * Description : Function to copy object list as is to tmp objlist * + * ============================================================================*/ +void help_copyCompleteObjList(IN void *pDst , IN uint32_t unFlag , OUT void *pSrc) +{ + if (IS_OBJLIST(unFlag)) + { + help_copyObj(pDst, pSrc); + } + else if (IS_SOPT_OBJATTR(unFlag)) + { + help_copyObjAttr(pDst, pSrc); + } + else if (IS_SOPT_OBJACSATTR(unFlag)) + { + help_copyAcsObj(pDst, pSrc); + } +} + +/* ============================================================================= + * Function Name : help_editNode * + * Description : Function to update node in given objlist * + * ============================================================================*/ +uint32_t help_editNode (INOUT ObjList *pxDstObjList, IN char *pcObjName, IN char *pcParamName, IN char *pcParamValue, + IN uint32_t uParamId, IN uint32_t uParamFlag) +{ + ObjList *pxTmpObjDst; + ParamList *pxParam; + uint32_t nRet = UGW_FAILURE; + + FOR_EACH_OBJ(pxDstObjList,pxTmpObjDst) + { + nRet = UGW_FAILURE; + if ( (strncmp(pxTmpObjDst->sObjName,pcObjName,strlen(pxTmpObjDst->sObjName)) == 0) && (strlen(pcObjName) == strlen(pxTmpObjDst->sObjName)) ) + { + FOR_EACH_PARAM(pxTmpObjDst,pxParam) + { + if ( (strcmp(pxParam->sParamName,pcParamName) == 0 ) && (strlen(pxParam->sParamName) == strlen(pcParamName))) + { + if(pcParamValue != NULL) + { + /* Tmp fix to cover SL issues*/ + if (pxParam->sParamValue == pcParamValue) + { + LOGF_LOG_INFO("Input and output ptrs are the same. Skipping update\n"); + nRet = UGW_SUCCESS; + } + else if(strlen(pcParamValue) < MAX_LEN_PARAM_VALUE ) + { + snprintf(pxParam->sParamValue,MAX_LEN_PARAM_VALUE, "%s", pcParamValue); + nRet = UGW_SUCCESS; + } + else + { + LOGF_LOG_CRITICAL("Buffer OverFlow \n"); + return UGW_FAILURE; + } + } + } + } + if (nRet != UGW_SUCCESS) + { + /* parameter not exists add to the list. */ + help_addParamList(pxTmpObjDst,pcParamName,uParamId,pcParamValue,uParamFlag); + nRet = UGW_SUCCESS; + + } + goto finish; + } + } +finish: + return nRet; +} + +/* ============================================================================= + * Function Name : help_editSelfNode * + * Description : Function to edit extarcted from for_each and addobj * + * ============================================================================*/ +uint32_t help_editSelfNode(INOUT ObjList *pxDstObjList, IN char *pcObjName, IN char *pcParamName, + IN char *pcParamValue, IN uint32_t uParamId, IN uint32_t uParamFlag) +{ + ParamList *pxParam; + uint32_t nRet = UGW_FAILURE; + if( (strcmp(pxDstObjList->sObjName, pcObjName) == 0) && (strlen(pxDstObjList->sObjName) == strlen(pcObjName)) ) + { + FOR_EACH_PARAM(pxDstObjList,pxParam) + { + if ( (strcmp(pxParam->sParamName,pcParamName) == 0 ) && (strlen(pxParam->sParamName) == strlen(pcParamName))) + { + if(pcParamValue != NULL) + { + /* Tmp fix to cover SL issues*/ + if (pxParam->sParamValue == pcParamValue) + { + LOGF_LOG_INFO("Input and output ptrs are the same. Skipping update\n"); + nRet = UGW_SUCCESS; + } + else if(strlen(pcParamValue) < MAX_LEN_PARAM_VALUE) + { + snprintf(pxParam->sParamValue,MAX_LEN_PARAM_VALUE, "%s", pcParamValue); + nRet = UGW_SUCCESS; + } + else + { + LOGF_LOG_CRITICAL("Buffer OverFlow \n"); + return UGW_FAILURE; + } + } + } + } + if (nRet != UGW_SUCCESS) + { + /* parameter not exists add to the list. */ + help_addParamList(pxDstObjList,pcParamName,uParamId,pcParamValue,uParamFlag); + nRet = UGW_SUCCESS; + + } + } + return nRet; +} + +/* ============================================================================= + * Function Name : help_mergeObjList * + * Description : Function merge two objlist , parameter value update. * + * ============================================================================*/ +uint32_t help_mergeObjList(INOUT ObjList *pxObjDst,IN ObjList *pxObjSrc) +{ + ObjList *pxTmpObj; + ParamList *pxParam; + uint32_t nRet = UGW_SUCCESS; + + help_updateObjName(pxObjSrc, pxObjDst); + + FOR_EACH_OBJ(pxObjSrc,pxTmpObj) + { + FOR_EACH_PARAM(pxTmpObj,pxParam) + { + nRet = help_editNode(pxObjDst, pxTmpObj->sObjName, pxParam->sParamName, pxParam->sParamValue, + pxParam->unParamId, pxParam->unParamFlag); + } + if (nRet != UGW_SUCCESS) + { + /* objects doesnt exists, add to the dst objlist */ + HELP_COPY_OBJ(pxObjDst, pxTmpObj, SOPT_OBJVALUE, COPY_SINGLE_OBJ); + nRet = UGW_SUCCESS; + } + else if(list_empty(&(pxTmpObj->xParamList.xPlist))) + { + ObjList *pxObj; + int32_t nFlag = NOT_SET; + FOR_EACH_OBJ(pxObjDst, pxObj) + { + if(strcmp(pxObj->sObjName, pxTmpObj->sObjName) == 0) + { + nFlag=SET; + pxObj->unSid = pxTmpObj->unSid; + pxObj->unOid = pxTmpObj->unOid; + pxObj->unObjFlag = pxTmpObj->unObjFlag; + break; + } + } + if(nFlag == NOT_SET) + { + /* objects doesnt exists, add to the dst objlist */ + HELP_COPY_OBJ(pxObjDst, pxTmpObj, SOPT_OBJVALUE, COPY_SINGLE_OBJ); + nRet = UGW_SUCCESS; + } + } + + } + return nRet; +} + +/* ============================================================================= + * Function Name : help_getObjPtr * + * Description : Function to get the objnode ptr based on the paramname* + * and value. * + * ============================================================================*/ +ObjList* help_getObjPtr(ObjList *pxObj, const char *paramName, const char *paramValue) +{ + ObjList *pxTmpObj; + ParamList *pxTmpParam; + + if(paramName == NULL || pxObj == NULL) + { + LOGF_LOG_ERROR("Requested object ptr can't find since paramName is NULL\n"); + return NULL; + } + + FOR_EACH_OBJ(pxObj, pxTmpObj) + { + FOR_EACH_PARAM(pxTmpObj,pxTmpParam) + { + if((strcmp(paramName,pxTmpParam->sParamName) == 0 ) && (strlen(paramName) == strlen(pxTmpParam->sParamName))) + { + if(paramValue != NULL) + { + if( (strcmp(paramValue,pxTmpParam->sParamValue) == 0 ) && (strlen(paramValue) == strlen(pxTmpParam->sParamValue))) + { + return pxTmpObj; + } + } + else + { + return pxTmpObj; + } + } + } + } + return NULL; +} + +/* ============================================================================= + * Function Name : help_DelObjPtr * + * Description : Function to del the objnode ptr in head node objlist * + * ============================================================================*/ +int help_delObjPtr(ObjList *pxObjList, ObjList *pxDelObj) +{ + ObjList *pxTempObj; + ParamList *pxParamList; + + while( !list_empty(&pxObjList->xOlist) ) + { + pxTempObj = list_entry(pxObjList->xOlist.next,ObjList,xOlist); + if (pxTempObj == pxDelObj) + { + while( !list_empty(&pxTempObj->xParamList.xPlist) ) + { + pxParamList = list_entry(pxTempObj->xParamList.xPlist.next,ParamList,xPlist); + list_del(&pxParamList->xPlist); + free(pxParamList); + pxParamList = NULL; + } + list_del(&pxTempObj->xOlist); + free(pxTempObj); + pxTempObj = NULL; + return UGW_SUCCESS; + } + else + { + pxObjList = list_entry(pxObjList->xOlist.next,ObjList,xOlist); + } + } + return UGW_FAILURE; +} + +/* ============================================================================= + * Function Name : help_moveObjList * + * Description : Function to move paraticular objlist from one to * + * another * + * ============================================================================*/ +int help_moveObjList(ObjList *pxDstObj, ObjList *pxSrcObj, const char * pcObjName, uint32_t unFlag) +{ + ObjList *pxTmpObj=NULL; + + FOR_EACH_OBJ(pxSrcObj,pxTmpObj) + { + if((strcmp(GET_OBJ_NAME(pxTmpObj), pcObjName) == 0) && (strlen(GET_OBJ_NAME(pxTmpObj)) == strlen(pcObjName))) + { + help_copyObjList(pxDstObj, unFlag, pxTmpObj); + /* delete node from the src */ + help_delObjPtr(pxSrcObj,pxTmpObj); + return UGW_SUCCESS; + } + } + return UGW_FAILURE; +} + +/* ============================================================================= + * function : help_isEmptyObj * + * Description :function to function find objlist is empty or not * + * ============================================================================*/ +OUT int help_isEmptyObj(IN ObjList *pxObj) +{ + ObjList *pxObjTmp; + FOR_EACH_OBJ(pxObj,pxObjTmp) + { + return UGW_FAILURE; + } + return UGW_SUCCESS; +} + +/* ============================================================================= + * function : help_isEmptyObjParam * + * Description :function to find if a given objlist includes parameters or not* + * ============================================================================*/ +OUT int help_isEmptyObjParam(IN ObjList *pxObj) +{ + ObjList *pxObjTmp; + ParamList *pxParam; + FOR_EACH_OBJ(pxObj,pxObjTmp) + { + FOR_EACH_PARAM(pxObjTmp, pxParam) + { + return UGW_FAILURE; + } + } + return UGW_SUCCESS; +} + +/* ============================================================================= + * Function Name : help_getValue * + * Description : Function to get the value from Objlist * + * ============================================================================*/ +int help_getValue(IN ObjList *pxObj, IN uint32_t unOid, IN uint32_t unInstance, IN uint32_t unParamId, OUT char *pcVal) +{ + ObjList *pxTmpObj; + ParamList *pxParam; + uint32_t unCount=0; + uint32_t nRet=UGW_FAILURE; + + if (unInstance == 0) + { + FOR_EACH_OBJ(pxObj, pxTmpObj) + { + if(pxTmpObj->unOid == unOid) + { + FOR_EACH_PARAM(pxTmpObj, pxParam) + { + if (pxParam->unParamId == unParamId) + { + snprintf(pcVal, MAX_LEN_PARAM_VALUE, "%s", pxParam->sParamValue); + nRet = UGW_SUCCESS; + return nRet; + } + } + } + } + } + else + { + /* Instance based get, it depends on total number of entries of requested object */ + FOR_EACH_OBJ(pxObj, pxTmpObj) + { + if(pxTmpObj->unOid == unOid) + { + unCount++; + if (unCount == unInstance) + { + FOR_EACH_PARAM(pxTmpObj, pxParam) + { + if (pxParam->unParamId == unParamId) + { + snprintf(pcVal, MAX_LEN_PARAM_VALUE, "%s", pxParam->sParamValue); + nRet = UGW_SUCCESS; + return nRet; + } + } + } + } + } + } + return nRet; +} + +/* ============================================================================= + * Function Name : help_getValueNameBased * + * Description : Function to get the value from Objlist thru * + * object/parameter name match * + * ============================================================================*/ +int help_getValueNameBased(IN ObjList *pxObj, IN char *pcObjName, IN uint32_t unInstance, IN char *pcParamName, OUT char *pcVal) +{ + ObjList *pxTmpObj; + ParamList *pxParam; + uint32_t unCount=0; + uint32_t nRet=UGW_FAILURE; + + /* object instance based or single instance object parameter value get */ + FOR_EACH_OBJ(pxObj, pxTmpObj) + { + if(strstr(GET_OBJ_NAME(pxTmpObj), pcObjName) != NULL) + { + unCount++; + if (unInstance > 0 && unCount != unInstance) + { + continue; + } + FOR_EACH_PARAM(pxTmpObj, pxParam) + { + if (strcmp(pxParam->sParamName,pcParamName) == 0) + { + snprintf(pcVal, MAX_LEN_PARAM_VALUE, "%s", pxParam->sParamValue); + nRet = UGW_SUCCESS; + return nRet; + } + } + } + } + return nRet; +} + +/* ============================================================================= + * Function Name : help_setValue * + * Description : Function to set the value in given Objlist * + * ============================================================================*/ +int help_setValue(IN ObjList *pxObj, IN uint32_t unOid, IN uint32_t unInstance, IN uint32_t unParamId, OUT char *pcVal) +{ + ObjList *pxTmpObj; + ParamList *pxParam; + uint32_t unCount=0; + uint32_t nRet=UGW_FAILURE; + + if (unInstance == 0) + { + FOR_EACH_OBJ(pxObj, pxTmpObj) + { + if(pxTmpObj->unOid == unOid) + { + FOR_EACH_PARAM(pxTmpObj, pxParam) + { + if (pxParam->unParamId == unParamId) + { + if(pcVal != NULL) + { + if( strlen(pcVal) < MAX_LEN_PARAM_VALUE) + { + snprintf(pxParam->sParamValue, MAX_LEN_PARAM_VALUE, "%s", pcVal); + nRet=UGW_SUCCESS; + } + else + { + LOGF_LOG_CRITICAL("Buffer OverFlow \n"); + nRet = UGW_FAILURE; + } + } + return nRet; + } + } + } + } + } + else + { + /* Instance based get, it depends on total number of entries of requested object */ + FOR_EACH_OBJ(pxObj, pxTmpObj) + { + if(pxTmpObj->unOid == unOid) + { + unCount++; + if (unCount == unInstance) + { + FOR_EACH_PARAM(pxTmpObj, pxParam) + { + if (pxParam->unParamId == unParamId) + { + if(pcVal != NULL) + { + if(strlen(pcVal) < MAX_LEN_PARAM_VALUE) + { + snprintf(pxParam->sParamValue, MAX_LEN_PARAM_VALUE, "%s", pcVal); + nRet = UGW_SUCCESS; + } + else + { + LOGF_LOG_CRITICAL("Buffer OverFlow \n"); + nRet = UGW_FAILURE; + } + return nRet; + } + } + } + } + } + } + } + + return nRet; +} + +/* ============================================================================= + * Function Name : help_setValueNameBased * + * Description : Function to set the value in given Objlist thru * + * object/parameter name match * + * ============================================================================*/ +int help_setValueNameBased(IN ObjList *pxObj, IN char *pcObjName, IN uint32_t unInstance, IN char *pcParamName, OUT char *pcVal) +{ + ObjList *pxTmpObj; + ParamList *pxParam; + uint32_t unCount=0; + uint32_t nRet=UGW_FAILURE; + + /* object instance based or single instance object parameter value get */ + FOR_EACH_OBJ(pxObj, pxTmpObj) + { + if(strstr(GET_OBJ_NAME(pxTmpObj), pcObjName) != NULL) + { + unCount++; + if (unInstance > 0 && unCount != unInstance) + { + continue; + } + FOR_EACH_PARAM(pxTmpObj, pxParam) + { + if (strcmp(pxParam->sParamName,pcParamName) == 0) + { + if(pcVal != NULL) + { + if( strlen(pcVal) < MAX_LEN_PARAM_VALUE) + { + snprintf(pxParam->sParamValue, MAX_LEN_PARAM_VALUE, "%s", pcVal); + nRet = UGW_SUCCESS; + } + else + { + LOGF_LOG_CRITICAL("Buffer OverFlow \n"); + nRet = UGW_FAILURE; + } + } + return nRet; + } + } + } + } + return nRet; +} + +static int indexFromString(char *s) { + unsigned int i; + char * indexPtr; + + if (!s) { + return -1; + } + + i = strlen(s) - 1; + while ((i > 0) && (s[i] != '_')) { + i--; + } + + if (i < 1) { + return -1; + } + + s[i] = '\0'; + indexPtr = &s[i+1]; + return atoi(indexPtr); +} diff --git a/include/crc32.h b/include/crc32.h new file mode 100644 index 0000000000000000000000000000000000000000..782245cf73e656ce2f2f1a82666994e007ad0d1a --- /dev/null +++ b/include/crc32.h @@ -0,0 +1,127 @@ +/* + * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or + * code or tables extracted from it, as desired without restriction. + * + * First, the polynomial itself and its table of feedback terms. The + * polynomial is + * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 + * + * Note that we take it "backwards" and put the highest-order term in + * the lowest-order bit. The X^32 term is "implied"; the LSB is the + * X^31 term, etc. The X^0 term (usually shown as "+1") results in + * the MSB being 1 + * + * Note that the usual hardware shift register implementation, which + * is what we're using (we're merely optimizing it by doing eight-bit + * chunks at a time) shifts bits into the lowest-order term. In our + * implementation, that means shifting towards the right. Why do we + * do it this way? Because the calculated CRC must be transmitted in + * order from highest-order term to lowest-order term. UARTs transmit + * characters in order from LSB to MSB. By storing the CRC this way + * we hand it to the UART in the order low-byte to high-byte; the UART + * sends each low-bit to hight-bit; and the result is transmission bit + * by bit from highest- to lowest-order term without requiring any bit + * shuffling on our part. Reception works similarly + * + * The feedback terms table consists of 256, 32-bit entries. Notes + * + * The table can be generated at runtime if desired; code to do so + * is shown later. It might not be obvious, but the feedback + * terms simply represent the results of eight shift/xor opera + * tions for all combinations of data and CRC register values + * + * The values must be right-shifted by eight bits by the "updcrc + * logic; the shift must be unsigned (bring in zeroes). On some + * hardware you could probably optimize the shift in assembler by + * using byte-swap instructions + * polynomial $edb88320 + */ + +#include <stdint.h> + +const uint32_t crc32_table[256] = { + 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, + 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, + 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, + 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, + 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, + 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, + 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, + 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, + 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, + 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, + 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, + 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, + 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, + 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, + 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, + 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, + 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, + 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, + 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, + 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, + 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, + 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, + 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, + 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, + 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, + 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, + 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, + 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, + 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, + 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, + 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, + 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, + 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, + 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, + 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, + 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, + 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, + 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, + 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, + 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, + 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, + 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, + 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, + 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, + 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, + 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, + 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, + 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, + 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, + 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, + 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, + 0x2d02ef8dL +}; + +/* Return a 32-bit CRC of the contents of the buffer. */ + +/*!\ + \brief static integer type function Returns a 32-bit CRC of the contents of the buffer + \param[in] val TBD + \param[in] ss TBD + \param[in] len TBD + \return uint32_t +*/ +static inline uint32_t crc32(uint32_t val, const void *ss, int len) +{ + const unsigned char *s = ss; + while (--len >= 0) + val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8); + return val; +} + + +static inline uint32_t calculate_crc32Buf(const char **ppStringArray, int unArrayCount) +{ + const unsigned char *psBuf; + uint32_t unVal = 0xFFFFFFFF; + while (--unArrayCount >= 0) { + psBuf = (const unsigned char *) *ppStringArray++; + while (*psBuf != '\0') { + unVal = crc32_table[(unVal ^ *psBuf++) & 0xff] ^ (unVal >> 8); + } + } + return unVal; +} + diff --git a/include/fapi_init_sequence.h b/include/fapi_init_sequence.h new file mode 100755 index 0000000000000000000000000000000000000000..fa715ef0d0d40c836babb6ef73782c43904d6642 --- /dev/null +++ b/include/fapi_init_sequence.h @@ -0,0 +1,51 @@ +#ifndef FAPI_INIT_SEQUENCE_H +#define FAPI_INIT_SEQUENCE_H + +#include <sys/time.h> +#include <syslog.h> +#include <unistd.h> + +/** +* This file is checked for LOGGING the FAPI init messages +*/ +#define FAPI_LOG_FILE VENDOR_PATH "/etc/fapi_debug" + +typedef struct { + struct timeval xTv1; + struct timeval xTv2; +} __xFAPITime; + +void log_fapi_init_msg(const char* file, const char *func, const int line); +void log_fapi_done_msg(const char* file, const char *func, const int line); + +/** +* FAPI time profiling related MACROS +*/ +#define TIME_INIT(__ix) __xFAPITime __ix +#define TIME_START(__ix) gettimeofday(&__ix.xTv1, NULL) +#define TIME_STOP(__ix) gettimeofday(&__ix.xTv2, NULL) + +#define LOG_FAPI_INIT() log_fapi_init_msg(__FILE__, __func__, __LINE__) +#define LOG_FAPI_DONE() log_fapi_done_msg(__FILE__, __func__, __LINE__) +#define LOG_FAPI_ARGS(args...) syslog(LOG_DEBUG, "FAPI_INIT: "args) + +#define FAPI_PRINT_DIFFTIME(fapi_name, __ix) syslog(LOG_DEBUG, "FAPI_INIT: %s initialization completed in %f seconds\n", \ + fapi_name ,(double) (__ix.xTv2.tv_usec - __ix.xTv1.tv_usec) / 1000000 + (double) (__ix.xTv2.tv_sec - __ix.xTv1.tv_sec)) + +#define LOG_FAPI_CALLFLOW_OPEN(arg) \ + TIME_INIT(xTime); \ + memset(&xTime, 0, sizeof(__xFAPITime)); \ + if (access(FAPI_LOG_FILE, F_OK) == 0) { \ + LOG_FAPI_INIT(); \ + TIME_START(xTime); \ + LOG_FAPI_ARGS(arg); \ + } + +#define LOG_FAPI_CALLFLOW_CLOSE() \ + if (access(FAPI_LOG_FILE, F_OK) == 0) { \ + TIME_STOP(xTime); \ + FAPI_PRINT_DIFFTIME(__func__, xTime); \ + LOG_FAPI_DONE(); \ + } + +#endif /*FAPI_INIT_SEQUENCE_H*/ diff --git a/include/help_debug.h b/include/help_debug.h new file mode 100755 index 0000000000000000000000000000000000000000..60c7ea8cc39fea9998647c9378d52331d82f74c2 --- /dev/null +++ b/include/help_debug.h @@ -0,0 +1,83 @@ +/******************************************************************************** + + Copyright (c) 2015 + Lantiq Beteiligungs-GmbH & Co. KG + Lilienthalstrasse 15, 85579 Neubiberg, Germany + For licensing information, see the file 'LICENSE' in the root folder of + this software module. + +********************************************************************************/ + +/* ***************************************************************************** + * File Name : help_debug.h * + * Description : Memory debugging utility * + * *****************************************************************************/ + +#ifndef __HELP_DEBUG_API_H +#define __HELP_DEBUG_API_H +#include <string.h> +#include <stdlib.h> +#include "help_defs.h" + +/*! \file help_debug.h + \brief File contains structs, defines, macros related to memory debugging utility +*/ + +/** \addtogroup LIBHELP */ +/* @{ */ + + +/*! + * \brief Keeps track of allocated and freed memory details + */ +typedef struct DEBUG +{ + void *vId; /*!< Id */ + uint32_t iSize; /*!< Size in bytes */ + char acFile[100]; /*!< File name */ + uint32_t iLine; /*!< Line number */ + struct Dbg *pxNext; /*!< Next node */ +}MemDbgUtil; + +/*! \brief Function to dump allocated and freed memory details + \return Dumps memory information in table format on successful +*/ +void help_memInfo(void); + +/*! \brief Function to allocate the memory with calloc + \param[in] unNum Number of memory blocks to be allocated + \param[in] unSize Number of bytes to be allocated + \param[in] pcFile __File__ info keep track mem info + \param[in] unLine __LINE__ info keep track mem info + \return Allocated memory as requested on success, else failure +*/ +OUT void* help_calloc(IN uint32_t unNum, IN uint32_t unSize, IN char *pcFile, IN uint32_t unLine); + +/*! \brief Function to allocate the memory with malloc + \param[in] unSize Number of bytes to be allocated + \param[in] pcFile __File__ info keep track mem info + \param[in] unLine __LINE__ info keep track mem info + \return Allocated memory as requested on success, else failure +*/ +OUT void* help_malloc(IN uint32_t unSize, IN char *pcFile, IN uint32_t unLine); + + +/*! \brief Function is used to allocate the memory with realloc + \param[in] ptr Previously allocated ptr to be realloced + \param[in] unSize Number of bytes to be allocated + \param[in] pcFile __File__ info keep track mem info + \param[in] unLine __LINE__ info keep track mem info + \return Allocated memory as requested on success, else failure +*/ +OUT void* help_realloc(IN void *ptr, IN uint32_t unSize, IN char *pcFile, IN uint32_t unLine); + +/*! \brief Function to free the memory with free + \param[in] ptr to free + \param[in] pcFile __file__ info keep track mem info + \param[in] unLine __LINE__ info keep track mem info + \return +*/ +int help_free(IN void *ptr, IN char *pcFile, IN uint32_t unLine); + +/* @} */ +#endif /* __HELP_DEBUG_API_H */ diff --git a/include/help_defs.h b/include/help_defs.h new file mode 100755 index 0000000000000000000000000000000000000000..78f85abc491768cd52226c0cc2ff6c610a07d9c6 --- /dev/null +++ b/include/help_defs.h @@ -0,0 +1,230 @@ +/******************************************************************************** + + Copyright (c) 2015 + Lantiq Beteiligungs-GmbH & Co. KG + Lilienthalstrasse 15, 85579 Neubiberg, Germany + For licensing information, see the file 'LICENSE' in the root folder of + this software module. + +********************************************************************************/ + +/* ***************************************************************************** + * File Name : help_defs.h * + * Description : Common Library contains functions, defines, * + * structs, enums used across modules like CAL, CAPI, * + * CSD, Servd, and Management Entities * + * *****************************************************************************/ + + +/*! \file help_defs.h +\brief File contains the common definitions, macros and data + structures common across all the modules in the software +*/ +/** \addtogroup LIBHELP */ +/* @{ */ + +#ifndef _HELP_DEFS_H +#define _HELP_DEFS_H + +#include <stdint.h> +#include <syslog.h> + +#include "help_enums.h" + +#ifndef OUT +/*! + \brief +*/ +#define OUT /*!< Macro for OUT null */ +#endif + +#ifndef INOUT +/*! + \brief +*/ +#define INOUT /*!< Macro INOUT null */ +#endif + +#ifndef IN +/*! + \brief +*/ +#define IN /*!< Macro for IN null */ +#endif + +#define UNUSED_VAR(arg) (void)(arg) /*!< Macro to define variable unused in the function */ + +#define UNUSED_ARG __attribute__ ((unused)) /*!< Macro to define function argument unused in the function */ + +#define OBJLIST(x) (IS_SOPT_ID(x) || IS_SOPT_OBJVALUE(x) || \ + IS_SOPT_LEAFNODE(x) || IS_SOPT_OBJNAME(x) || IS_SOPT_DEFVAL(x)) /*!< Macro find objlist type check */ + + +#define OBJATTRLIST(x) IS_SOPT_OBJATTR(x) /*!< Macro to find objattrlist type check */ + +#define OWNER_MGMT(x) IS_OWN_WEB(x) || IS_OWN_TR69(x) || IS_OWN_CLI(x) /*!< Macro to check owner */ + +/*! + \brief +*/ +#define BOOT_CHK_PARAM "Device.X_INTEL_COM_BootChk" + + +/*! + \brief +*/ +#define IS_SOPT_ORGOWN(bit) (bit & SOPT_ORGOWN) /*!< Macro to check orginal owner bit set */ + + +/*! + \brief +*/ +#define IS_SOPT_ID(bit) (bit & SOPT_ID) /*!< Macro to check suboper id bit set */ + +/*! + \brief +*/ +#define IS_SOPT_OBJNAME(bit) (bit & SOPT_OBJNAME) /*!< Macro to check suboper subtree bit set */ + +/*! + \brief +*/ +#define IS_SOPT_OBJVALUE(bit) (bit & SOPT_OBJVALUE) /*!< Macro to check suboper complete bit set */ + +/*! + \brief +*/ +#define IS_SOPT_OBJATTR(bit) (bit & SOPT_OBJATTR) /*!< Macro to check suboper attrval bit set */ + +/*! + \brief +*/ +#define IS_SOPT_LEAFNODE(bit) (bit & SOPT_LEAFNODE) /*!< Macro to check suboper leaf node bit set */ + +/*! + \brief +*/ +#define IS_SOPT_DEFVAL(bit) (bit & SOPT_DEFVAL) /*!< Macro to check suboper defult val bit set */ + +/*! + \brief +*/ +#define IS_SOPT_OBJACSATTR(bit) (bit & SOPT_OBJACSATTR) /*!< Macro to check suboper ACS attrval bit set */ + +/*! + \brief +*/ +#define IS_ATTR_ACTIVE_NOTIFY_SET(bit) (bit & ATTR_ACTIVENOTI) /*!< Macro for access control attribute */ + + +/*! + \brief +*/ +#define IS_OWN_TR69(bit) (bit & OWN_TR69) /*!< Macro to check tr69 owner bit set */ + +/*! + \brief +*/ +#define IS_OWN_WEB(bit) (bit & OWN_WEB) /*!< Macro to check web owner bit set */ + +/*! + \brief +*/ +#define IS_OWN_SERVD(bit) (bit & OWN_SERVD) /*!< Macro to check servd owner bit set */ + +/*! + \brief +*/ +#define IS_OWN_CLI(bit) (bit & OWN_CLI) /*!< Macro to check cli owner bit set */ + +/*! + \brief +*/ +#define IS_OWN_OTHER(bit) (bit & OWN_OTHER) /*!< Macro to check other owner bit set */ + +/*! + \brief +*/ +#define IS_OWN_POLLD(bit) (bit & OWN_POLLD) /*!< Macro to check polld owner bit set */ + + +/*! + \brief +*/ +#define MAX_LEN_OBJNAME 256 /*!< Object Name string length */ + +/*! + \brief +*/ +#define MAX_LEN_ID 6 /*!< Object ID string length */ + +/*! + \brief +*/ +#define MAX_LEN_PARAM_NAME 256 /*!< Parameter Name string length */ + +/*! + \brief +*/ +#define MAX_LEN_PARAM_VALUE 128 /*!< Parameter Value string length */ + +/*! + \brief +*/ +#define MAX_LEN_VALID_VALUE 1024 /*!< Parameter valid value string length */ + +/*! + \brief +*/ +#define NO_ARG_VALUE 0 /*!< Macro for NO_ARG_VALUE null */ + +/*! + \brief +*/ +#define MAX_LEN_PROFILENAME 64 /*!< Profile name string length */ + +/*! + \brief +*/ +#define MAX_LEN_WEBNAME 128 /*!< Webname string length */ + +/*! + \brief +*/ +#define MAX_LEN_PARAM_TYPE 20 /*!< Parameter Type string length */ + +/*! + \brief +*/ +typedef struct list_head ListHead; /*!< List head structure typedef */ + +/*! + \brief +*/ +#define char8_t int8_t /*!< Character typedef */ + +/*! + \brief +*/ +#define IS_OBJLIST(x) OBJLIST(x) /*!< Macro to check objlist structure used */ + +/*! + \brief +*/ +#define IS_ATTR_PASSIVE_NOTIFY_SET(bit) (bit & ATTR_PASSIVENOTI) /*!< Macro for access control attribute */ + +/*! \def NOT_SET + \brief + */ +#define NOT_SET 2 /*!< Flag Not Set*/ + +/*! \def SET + \brief + */ +#define SET 3 /*!< Flag Set*/ + + + +#endif //#ifndef _HELP_DEFS_H + +/* @} */ diff --git a/include/help_enums.h b/include/help_enums.h new file mode 100755 index 0000000000000000000000000000000000000000..2c133911987e54b97744ed9ffb4009c0180174d1 --- /dev/null +++ b/include/help_enums.h @@ -0,0 +1,89 @@ +/******************************************************************************** + + Copyright (c) 2015 + Lantiq Beteiligungs-GmbH & Co. KG + Lilienthalstrasse 15, 85579 Neubiberg, Germany + For licensing information, see the file 'LICENSE' in the root folder of + this software module. + +********************************************************************************/ + +/* ***************************************************************************** + * File Name : help_enums.h * + * Description : Common Library contains functions, defines, * + * structs, enums used across modules like CAL, CAPI, * + * CSD, Servd, and Management Entities * + * *****************************************************************************/ + + +/*! \file help_enums.h +\brief File contains all enumerations for the common library +*/ + +#ifndef _HELP_ENUMS_H +#define _HELP_ENUMS_H + +/** \addtogroup LIBHELP */ + +/* @{ */ + +/*! \enum SubOper + \brief Enum containing the type of operation which includes ID_ONLY, SUB_TREE etc + \ for per transaction +*/ +typedef enum +{ + SOPT_ID = 0x1,/*!< SET/GET_ID_ONLY */ + SOPT_OBJNAME = 0x2,/*!< SET/GET_SUB_TREE */ + SOPT_OBJVALUE = 0x4,/*!< SET/GET_COMPLETE */ + SOPT_OBJATTR = 0x8,/*!< SET/GET_ATTR_VALUE */ + SOPT_OBJACSATTR = 0x10,/*!< SET/GET_ATTR_VALUE */ + SOPT_VALIDATION = 0x20,/*!< SET/GET_VALID_VALUES */ + SOPT_DEFVAL = 0x40,/*!< SET/GET_DEFAULT_VALUE */ + SOPT_NOSUBOPER= 0x80,/*!< NO_SUBOPER */ + SOPT_LEAFNODE = 0x100,/*!< GET LEAF NODE ONLY */ + SOPT_ORGOWN = 0x200/*!< IDENTIFY ORGINAL OWNER */ +}SubOper; + +/*! \enum MiscType + \brief Enum containing the misc type for various requirements +*/ +typedef enum +{ + COPY_COMPLETE_OBJ=0, /*!< Copy complete objlist objlist */ + COPY_SINGLE_OBJ=1, /*!< Copy single objlist */ + EMPTY_OBJLIST, /*!< Empty objlist */ + FREE_OBJLIST /*!< Free objlist */ +}MiscType; + +/*! \enum ACSATTR + \brief Enum containing the attribute list for ACS +*/ +typedef enum +{ + ATTR_NOTSAVETOFLASH = 0x400, /*!< Save To Flash (true if the not attribute is not present and false if the not attribute is present) */ + ATTR_INFORMTOACS = 0x800, /*!< Inform to ACS */ + ATTR_ACTIVENOTI = 0x1000, /*!< Active Notification */ + ATTR_PASSIVENOTI = 0x2000, /*!< Passive Notificaton */ + ATTR_NOTIDISABLED = 0x4000, /*!< Disabled Notification */ + ATTR_CHANGEFLAG = 0x8000, /*!< Change flag */ + ATTR_CANDENY = 0x20000000 /*!< CanDeny flag */ +}AcsAttr; + +/*! \enum Owner + \brief Enum containing the Owner Type whose try to set/get for ex:web.tr69 etc +*/ +typedef enum +{ + OWN_TR69 = 0x1,/*!< DeVM */ + OWN_WEB = 0x2,/*!< WEB */ + OWN_SERVD = 0x4,/*!< SERVD */ + OWN_CLI = 0x8,/*!< CLI */ + OWN_POLLD = 0x10,/*!< POLLD */ + OWN_OTHER = 0x20/*!< OTHER */ +}Owner; + + +/* @} */ + +#endif // #ifndef _HELP_ENUMS_H diff --git a/include/help_error.h b/include/help_error.h new file mode 100755 index 0000000000000000000000000000000000000000..43f3f549207e853c19b59fcdac9fbd7b952f57a9 --- /dev/null +++ b/include/help_error.h @@ -0,0 +1,123 @@ +/******************************************************************************** + + Copyright (c) 2015 + Lantiq Beteiligungs-GmbH & Co. KG + Lilienthalstrasse 15, 85579 Neubiberg, Germany + For licensing information, see the file 'LICENSE' in the root folder of + this software module. + +********************************************************************************/ + +/* ***************************************************************************** + * File Name : help_error.h * + * Description : Common Library contains functions, defines, * + * structs, enums used across modules like CAL, CAPI, * + * CSD, Servd, and Management Entities * + * *****************************************************************************/ + +/*! \file help_error.h +\brief File contains the error code returned with respect to Framework, SL, and ME +*/ +/* @{ */ + + +/*! CAUTION: While adding the new error code + The comment section for that error code is must, else that error message will not be handle by web. + String within the comment section in the same line of error code enum will be displayed as error message on the web. + Format of the comment section should follow doxygen format comment as below. +*/ + + +#ifndef _HELP_ERROR_H +#define _HELP_ERROR_H + +#define UGW_SUCCESS 0 /*!< Macro to define success status */ +#define UGW_FAILURE -1 /*!< Macro to define failure status */ + +/*! \enum FrameWorkErrCode + \brief Enum containing the type of error code which can be returned from the framework + modules like servd, csd, and cal. Buffer error code -200 to -240 +*/ +typedef enum { + ERR_INVALID_OBJNAME_REQUEST = -200, /*!< Error Requested Object is Invalid */ + ERR_INVALID_PARAMETER_REQUEST = -201, /*!< Error Requested Parameter is Invalid */ + ERR_INVALID_INSTANCE_REQUEST = -202, /*!< Error Invalid Instance Request */ + ERR_INVALID_XML_FILE = -203, /*!< Invalid XML File request */ + ERR_FILE_NOT_FOUND = -204, /*!< File not found, Cannot perform the operation */ + ERR_FILE_LOCK_FAILED = -205, /*!< File lock failed */ + ERR_FILE_WRITE_FAILED = -206, /*!< File write failed, Cannot perform the operation */ + ERR_FILE_TRUNCATE_FAILED = -207, /*!< File truncate failed, Cannot perform the operation */ + ERR_NO_CONTENT = -208, /*!< No content in recived msg */ + ERR_INVALID_UBUS_ARG = -209, /*!< Invalid ubus arguments */ + ERR_UBUSMSG_OVERLOAD = -210, /*!< Ubus msg overloaded */ + ERR_UBUSD_NOT_RUNNING = -211, /*!< Ubusd daemon not running */ + ERR_MEMORY_ALLOC_FAILED = -212, /*!< Memory Allocation failed */ + ERR_UPDATE_FAILED = -213, /*!< Update failed it can be anything like (tree update, servd internal update, csd internal update, etc) */ + ERR_MAX_INSTANCE_EXCEEDED = -214, /*!< Add operation failed, max limit reached */ + ERR_MIN_INSTANCE_REACHED = -215, /*!< Delete operation failed, system expects this entry */ + ERR_MERGE_FAILED = -216, /*!< Merge Failed */ + ERR_VALIDATION_FAILED = -217, /*!< Validataion Failed, Cannot perform the operation */ + ERR_NON_INSTANCEABLE = -218, /*!< Add Operation Failed, due to non-instancable property of the object */ + ERR_DEFAULT_LOAD_FAILURE = -219, /*!< Default value get failed */ + ERR_PATH_NOT_FOUND = -220, /*!< File directory path not found */ + ERR_RECEIVER_NOT_RUNNING = -221, /*!< Requested server not running */ + ERR_ADD_OBJECT_FAILED = -222, /*!< ADD object failed */ + ERR_DEL_OBJECT_FAILED = -223, /*!< DEL object failed */ + ERR_MIN_VAL_REACHED = -224, /*!< Value is not number or less than expected value*/ + ERR_MAX_VAL_EXCEEDED = -225, /*!< Value is not number or greater than expected value*/ + ERR_MIN_LEN_REACHED = -226, /*!< String length is less than expected length*/ + ERR_MAX_LEN_EXCEEDED = -227, /*!< String length is greater than expected length */ + ERR_BOOLEAN_FAILED = -228, /*!< Boolean Failed */ + ERR_DATETIME_FAILED = -229, /*!< Date Time Failed */ + ERR_READ_ONLY = -230, /*!< Read only parameter, Cannot perform the operation */ + ERR_GET_ID_FAILED = -231, /*!< Get Id Failed */ + ERR_STRING_NOT_FOUND = -232, /*!< String not found or String match failed */ + ERR_BAD_FD = -233, /*!< Bad File descriptor */ + ERR_IOCTL_FAILED = -234, /*!< IOCTL failed */ + ERR_INVALID_PARAMETER_VALUE_REQUEST = -235, /*!< Invalid parameter value request */ + ERR_ALIAS_REPLACEMENT_FAILED = -236, /*!< Invalid parameter value request */ + ERR_UBUS_TIME_OUT = -237, /*!< Response not received for GET/SET Request */ + ERR_SL_TIME_OUT = -238, /*!< SL failed to complete the operation or timed out */ + ERR_EXPECTED_NUM = -239 /*!< Strings are not allowed, Only numbers are allowed */ +} FrameWorkErrCode; + +/*! \enum SLErrCode + \brief Enum containing the type of error code which can be returned from the Service Layer. + Buffer error code -241 to -280 +*/ +typedef enum { + ERR_INVALID_SL = -241, /*!< Required Service Library doesnot Exist !! */ + ERR_INVALID_SET_PARAM_REQ = -242, /*!< Set Parameter Request Failed */ + ERR_INVALID_OPERATION = -243, /*!< Invalid Operation Requested */ + ERR_INVALID_IPADDRESS = -244, /*!< Invalid IpAddress */ + ERR_INVALID_IP_POOL_RANGE = -245, /*!< Pool Range Specified in Invalid */ + ERR_INTERNAL = -246, /*!< Internal Error. Please correct the entered data */ + ERR_EXISTING_ATM_WAN = -247, /*!< Can't delete ATM Link, already a connection exists with this link */ + ERR_MULTIPLE_IPOA_PPPOA_WAN = -248, /*!< Creation of a New or Modification of existing IPoA/PPPoA Connection not supported. Kindly delete the existing connection and Re-create a new connection */ + ERR_MULTIPLE_BRIDGED_WAN = -249, /*!< Creation of multiple bridged WAN connection is not permitted */ + ERR_IPOA_PPPOA_WAN_ON_VLAN = -250, /*!< Creation of IPoA/PPPoA connection on a VLAN interface is not permitted */ + ERR_DB_READ_FAILED = -251, /*!< DataBase Read Failed */ + ERR_RULE_MODIFY_NOT_ALLOWED = -252, /*!< This rule cannot be modified/deleted */ + ERR_REJECT_BRIDGED_WAN_CONN = -253, /*!< WAN exists on concerned wan interface, Creation of new Bridged WAN Connection is not permitted */ + ERR_REJECT_PPPOE_WAN_CONN = -254, /*!< Bridged WAN exists on concerned wan interface, Creation of new PPP WAN Connection is not permitted */ + ERR_REJECT_STATIC_DHCP_WAN_CONN = -255, /*!< Static/DHCP/Bridged WAN exists on concerned wan interface, Creation of new Static/DHCP WAN Connection is not permitted */ + ERR_USER_ADD = -256, /*!< Failed to add user, Check system logs for proper error message */ + ERR_USER_REMOVE = -257, /*!< Failed to remove user, Check system logs for proper error message */ + ERR_BRIDGED_LANVLAN_DELETE = -258, /*!< LAN VLAN Interface cannot be deleted as it is part of bridge. Please remove it from bridge and try again */ + ERR_PRIMARY_BRIDGE_DELETE = -259, /*!< Deletion of Primary LAN Bridge (br-lan) is not Allowed */ + ERR_DEFAULT_STATIC_ROUTE = -260, /*!< Adding static route against 0.0.0.0 network is not allowed */ + ERR_BRIDGE_WITOUT_LANPORT = -261, /*!< Bridge (br-lan) should have atleast one lan port */ + ERR_MACADDRESS_POOL_EXHAUSTED = -262 /*!< MAC Address pool exhausted. Rejecting WAN connection */ +} SLErrCode; + +/*! \enum MEErrCode (Management Entity) + \brief Enum containing the type of error code which can be returned from the ME(web, cwmp, upnp, cli, etc). + Buffer error code -281 to -320 +*/ +typedef enum { + ERR_402_NOT_FOUND = -281 /*!< ME Error */ +} MEErrCode; + +#endif //#ifndef _HELP_ERROR_H + +/* @} */ diff --git a/include/help_logging.h b/include/help_logging.h new file mode 100755 index 0000000000000000000000000000000000000000..4f2df534386b83ed18106f8c43b5e890e2809b3f --- /dev/null +++ b/include/help_logging.h @@ -0,0 +1,269 @@ +/******************************************************************************** + + Copyright (c) 2015 + Lantiq Beteiligungs-GmbH & Co. KG + Lilienthalstrasse 15, 85579 Neubiberg, Germany + For licensing information, see the file 'LICENSE' in the root folder of + this software module. + +********************************************************************************/ + +/* ***************************************************************************** + * File Name : help_logging.h * + * Description : header file for logging framework * + * *****************************************************************************/ + + +#ifndef HELP_LOGGING_H +#define HELP_LOGGING_H +#define DBG_TIMESTAMP 1 /*!< Macro for debug timestamp */ +#include<stdio.h> +#include<stdint.h> +#include<stdarg.h> +#include<syslog.h> +#ifdef DBG_TIMESTAMP +#include <sys/time.h> +#include <time.h> +#endif +#include <vendor.h> + +/*! \file help_logging.h + \brief File contains macros and enums for logging debug messages +*/ + +/** \addtogroup SYSFRAMEWORK_LOG */ +/* @{ */ + + +#define AFTERX_TYPE(x) un ## x ## LogType /*!< x type */ +#define XAFTERX_TYPE(x) AFTERX_TYPE(x) /*!< x after type */ +#define AFTERX_LEVEL(x) un ## x ## LogLevel /*!< x level */ +#define XAFTERX_LEVEL(x) AFTERX_LEVEL(x) /*!< x after level */ + +#define log_level(NAME) XAFTERX_LEVEL(NAME) /*!< log level */ +#define log_type(NAME) XAFTERX_TYPE(NAME) /*!< log type */ + +#ifndef LOGGING_ID +#error "Please define LOGGING_ID" +#else +#define LOGTYPE log_type(LOGGING_ID) /*!< log type */ +#define LOGLEVEL log_level(LOGGING_ID) /*!< log level */ +#endif + +#define COLOR_NRM "\x1B[0m" +#define COLOR_RED "\x1B[31m" +#define COLOR_GRN "\x1B[32m" +#define COLOR_YEL "\x1B[33m" +#define COLOR_BLU "\x1B[34m" +#define COLOR_MAG "\x1B[35m" +#define COLOR_CYN "\x1B[36m" +#define COLOR_WHT "\x1B[37m" +#define COLOR_ORA "\x1B[38;5;214m" + +#define UGW_LOG_PROFILE 1 +//#define SYS_LOG_EMERG LOG_EMERG +//#define SYS_LOG_ALERT LOG_ALERT +#define SYS_LOG_CRIT LOG_CRIT /*!< critical level */ +#define SYS_LOG_ERR LOG_ERR /*!< error level */ +//#define SYS_LOG_WARNING LOG_WARNING +//#define SYS_LOG_NOTICE LOG_NOTICE +#define SYS_LOG_INFO LOG_INFO /*!< info level */ +#define SYS_LOG_DEBUG LOG_DEBUG /*!< debug level */ + +#define SYS_LOG_TYPE_NONE 0 /*!< log type */ +#define SYS_LOG_TYPE_FILE (1 << 0) /*!< log type file */ +#define SYS_LOG_TYPE_CONSOLE (1 << 1) /*!< log type console */ +#define SYS_LOG_TYPE_FILE_AND_CONSOLE (SYS_LOG_TYPE_FILE | SYS_LOG_TYPE_CONSOLE) /*!< log type both console and file */ + +extern uint16_t LOGPROFILE; /*!< log level */ +extern uint16_t LOGLEVEL; /*!< log level */ +extern uint16_t LOGTYPE; /*!< log type */ +static void LOGF_LOG_PRINT(const char *color_code, const char *logtype, const char *fmt, ...) __attribute__((format(printf, 3, 4))); + +static void LOGF_LOG_PRINT(const char *color_code, const char *logtype, const char *fmt, ...) { + char cAppendStr[256]={0}; + va_list args; +#ifdef DBG_TIMESTAMP + struct timeval tv; + struct tm * timeinfo; + time_t nowtime; + char tmbuf[50]="\0"; + gettimeofday(&tv, NULL); + nowtime = tv.tv_sec; + timeinfo = localtime(&nowtime); + if(timeinfo != NULL) + strftime(tmbuf,50,"%d-%m-%Y %T", timeinfo); +#endif +#ifdef DBG_TIMESTAMP + snprintf(cAppendStr, sizeof(cAppendStr), "%s<%s> [%s] ",color_code, tmbuf, logtype); +#else + snprintf(cAppendStr, sizeof(cAppendStr), "%s[%s] ",color_code, logtype); +#endif + do{ + printf("%s", cAppendStr); + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); + printf("%s",COLOR_NRM); + fflush(stdout); + }while(0); +} + +#define LOGF_OPEN(sl_name) openlog(sl_name, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER) /*!< LOG OPEN */ +#define LOGF_CLOSE() closelog() /*!< LOG CLOSE */ + +static inline void LOGF_MASK(int log_level) { +#ifdef PROC_LEVEL + if ( log_level >= SYS_LOG_EMERG && log_level <= SYS_LOG_DEBUG) + setlogmask(LOG_UPTO(log_level)); + else + setlogmask(LOG_UPTO(SYS_LOG_INFO)); +#else + LOGLEVEL = log_level; +#endif +} + +static inline void LOGF_TYPE(int log_type) { + LOGTYPE = log_type; +} + +/* PACKAGE_ID will be provided by relevant package make file. */ +#define LOGF_LOG_PROFILE(args...) PROFILE_PRINTF(INFO, ##args); /*!< Macro to define profile logging */ +#define LOGF_LOG_ERROR(args...) PRINTF(ERR, ##args); /*!< Macro to define error level */ +#define LOGF_LOG_EMERG(args...) PRINTF(EMERG, ##args) /*!< Macro to define emergency level */ +#define LOGF_LOG_ALERT(args...) PRINTF(ALERT, ##args) /*!< Macro to define alert level */ +#define LOGF_LOG_CRITICAL(args...) PRINTF(CRIT, ##args) /*!< Macro to define critical level */ +#define LOGF_LOG_WARNING(args...) PRINTF(WARNING, ##args) /*!< Macro to define warnning level */ +#define LOGF_LOG_NOTICE(args...) PRINTF(NOTICE, ##args) /*!< Macro to define notice level */ +#define LOGF_LOG_INFO(args...) PRINTF(INFO, ##args) /*!< Macro to define info level */ +#define LOGF_LOG_DEBUG(args...) PRINTF(DEBUG, ##args) /*!< Macro to define debug level */ +#define LOGF_LOG(LEVEL, fmt, args...) SYSLOG_##LEVEL(PACKAGE_ID"{%s, %d}:"fmt, __func__, __LINE__, ##args) /*!< PROFILE PRINTF Macro */ + +#define PRINTF(LEVEL, fmt, args...) SYSLOG_##LEVEL(PACKAGE_ID"{%s, %d}:"fmt, __func__, __LINE__, ##args) /*!< PRINTF Macro */ +#define PROFILE_PRINTF(LEVEL, fmt, args...) UGWLOG_PROFILE(PACKAGE_ID"{%s, %d}:"fmt, __func__, __LINE__, ##args) /*!< PRINTF Macro */ + +#define UGWLOG_PROFILE(fmt, args...) \ + do{ \ + if( UGW_LOG_PROFILE != LOGPROFILE) \ + break; \ + if( LOGTYPE & SYS_LOG_TYPE_FILE) \ + syslog(LOG_INFO, fmt, ##args); \ + if( LOGTYPE & SYS_LOG_TYPE_CONSOLE) \ + LOGF_LOG_PRINT(COLOR_RED, "INFO", fmt, ##args); \ + }while(0); + +#ifdef SYS_LOG_EMERG // level 0 +#define SYSLOG_EMERG(fmt, args...) \ + do{ \ + if( SYS_LOG_EMERG > LOGLEVEL) \ + break; \ + if( LOGTYPE & SYS_LOG_TYPE_FILE) \ + syslog(LOG_EMERG, fmt, ##args); \ + if( LOGTYPE & SYS_LOG_TYPE_CONSOLE) \ + LOGF_LOG_PRINT(COLOR_RED, "EMERG", fmt, ##args); \ + }while(0); +#else +#define SYSLOG_EMERG(fmt, args...) { } /*!< Emergency log level */ +#endif + +#ifdef SYS_LOG_ALERT // level 1 +#define SYSLOG_ALERT(fmt, args...) \ + do{ \ + if( SYS_LOG_ALERT > LOGLEVEL) \ + break; \ + if( LOGTYPE & SYS_LOG_TYPE_FILE) \ + syslog(LOG_ALERT, fmt, ##args); \ + if( LOGTYPE & SYS_LOG_TYPE_CONSOLE) \ + LOGF_LOG_PRINT(COLOR_RED, "ALERT", fmt, ##args); \ + }while(0); +#else +#define SYSLOG_ALERT(fmt, args...) { } /*!< Alert log level */ +#endif + +#ifdef SYS_LOG_CRIT // level 2 +#define SYSLOG_CRIT(fmt, args...) \ + do{ \ + if( SYS_LOG_CRIT > LOGLEVEL) \ + break; \ + if( LOGTYPE & SYS_LOG_TYPE_FILE) \ + syslog(LOG_CRIT, fmt, ##args); \ + if( LOGTYPE & SYS_LOG_TYPE_CONSOLE) \ + LOGF_LOG_PRINT(COLOR_RED, "CRITICAL", fmt, ##args); \ + }while(0); /*!< Critical log level */ +#else +#define SYSLOG_CRIT(fmt, args...) { } /*!< Critical log level */ +#endif + +#ifdef SYS_LOG_ERR // level 3 +#define SYSLOG_ERR(fmt, args...) \ + do{ \ + if( SYS_LOG_ERR > LOGLEVEL) \ + break; \ + if( LOGTYPE & SYS_LOG_TYPE_FILE) \ + syslog(LOG_ERR, fmt, ##args); \ + if( LOGTYPE & SYS_LOG_TYPE_CONSOLE) \ + LOGF_LOG_PRINT(COLOR_ORA, "ERROR" , fmt, ##args); \ + }while(0); /*!< Error log level */ +#else +#define SYSLOG_ERR(fmt, args...) { } /*!< Error log level */ +#endif + +#ifdef SYS_LOG_WARNING // level 4 +#define SYSLOG_WARNING(fmt, args...) \ + do{ \ + if( SYS_LOG_WARNING > LOGLEVEL) \ + break; \ + if( LOGTYPE & SYS_LOG_TYPE_FILE) \ + syslog(LOG_WARNING, fmt, ##args); \ + if( LOGTYPE & SYS_LOG_TYPE_CONSOLE) \ + LOGF_LOG_PRINT(COLOR_NRM, "WARNING" , fmt, ##args); \ + }while(0); /*!< Warning log level */ +#else +#define SYSLOG_WARNING(fmt, args...) { } /*!< Warning log level */ +#endif + +#ifdef SYS_LOG_NOTICE // level 5 +#define SYSLOG_NOTICE(fmt, args...) \ + do{ \ + if( SYS_LOG_NOTICE > LOGLEVEL) \ + break; \ + if( LOGTYPE & SYS_LOG_TYPE_FILE) \ + syslog(LOG_NOTICE, fmt, ##args); \ + if( LOGTYPE & SYS_LOG_TYPE_CONSOLE) \ + LOGF_LOG_PRINT(COLOR_NRM, "NOTICE", fmt, ##args); \ + }while(0); /*!< Notice log level */ +#else +#define SYSLOG_NOTICE(fmt, args...) { } /*!< Notice log level */ +#endif + +#ifdef SYS_LOG_INFO // level 6 +#define SYSLOG_INFO(fmt, args...) \ + do{ \ + if( SYS_LOG_INFO > LOGLEVEL) \ + break; \ + if( LOGTYPE & SYS_LOG_TYPE_FILE) \ + syslog(LOG_INFO, fmt, ##args); \ + if( LOGTYPE & SYS_LOG_TYPE_CONSOLE) \ + LOGF_LOG_PRINT(COLOR_NRM, "INFO", fmt, ##args); \ + }while(0); /*!< Information log level */ +#else +#define SYSLOG_INFO(fmt, args...) { } /*!< Information log level */ +#endif + +#ifdef SYS_LOG_DEBUG // level 7 +#define SYSLOG_DEBUG(fmt, args...) \ + do{ \ + if( SYS_LOG_DEBUG > LOGLEVEL) \ + break; \ + if(LOGTYPE & SYS_LOG_TYPE_FILE) \ + syslog(LOG_DEBUG, fmt, ##args); \ + if( LOGTYPE & SYS_LOG_TYPE_CONSOLE) \ + LOGF_LOG_PRINT(COLOR_NRM, "DEBUG", fmt, ##args); \ + }while(0); /*!< Debug log level */ +#else +#define SYSLOG_DEBUG(fmt, args...) { } /*!< Debug log level */ +#endif + +/* @} */ + +#endif //_LTQ_DEBUG_H diff --git a/include/help_objlist.h b/include/help_objlist.h new file mode 100755 index 0000000000000000000000000000000000000000..dca50c6791fb5042419f2c463eab1ce51a161217 --- /dev/null +++ b/include/help_objlist.h @@ -0,0 +1,884 @@ +/******************************************************************************** + + Copyright (c) 2015 + Lantiq Beteiligungs-GmbH & Co. KG + Lilienthalstrasse 15, 85579 Neubiberg, Germany + For licensing information, see the file 'LICENSE' in the root folder of + this software module. + +********************************************************************************/ + +/* ***************************************************************************** + * File Name : help_objmsg.h * + * Description : Common Helper Library contains functions, * + * defines, structs, and enums used across the modules * + * like CAL, CAPI, CSD, Servd, and Management Entities * + * *****************************************************************************/ + + +/*! \file help_objmsg.h +\brief File contains the Constants, enumerations, related Data + structures and API's common for all modules in LQ software. +*/ + +/** \addtogroup LIBHELP */ +/* @{ */ + +#ifndef _HELP_OBJMSG_H +#define _HELP_OBJMSG_H + +#include <stdio.h> +#include <string.h> +#include <inttypes.h> +#include "help_proto.h" +#include "help_debug.h" +#include "help_logging.h" +#include "help_defs.h" +#include "help_error.h" + + +#define var(z) Obj##z /*!< To get unified variable name on every declaration */ +#define decl(x) var(x) /*!< Define varible with line number */ +#define OBJ decl(__LINE__) /*!< To get line number */ + + +/*! + \brief Allocates memory for given number of bytes + \param[in] unBytes Number of bytes to allocate + \return On Successful returns number of bytes allocated ptr +*/ +#define HELP_MALLOC(unBytes) help_calloc(1,unBytes,__FILE__,__LINE__); + +/*! + \brief Allocates memory for given number of bytes + \param[in] *pSrcPtr Pointer allocate to reallocate. + \param[in] unBytes Number of bytes to allocate + \return On Successful returns number of bytes allocated ptr +*/ +#define HELP_REALLOC(pSrcPtr, unBytes) help_realloc(pSrcPtr,unBytes,__FILE__,__LINE__); + + +/*! + \brief Allocates memory for given number of bytes + \param[in] unBytes Number of bytes to allocate + \param[in] unNum Number of elementes to allocate + \return On Successful returns number of bytes allocated ptr +*/ +#define HELP_CALLOC(unNum, unBytes) help_calloc(unNum,unBytes,__FILE__,__LINE__); + + +/*! + \brief Frees up the memory allocated using calloc, malloc + \param[in] ptr Pointer to free + \return On Successful allocated memory gets freed +*/ +#define HELP_FREE(ptr) help_free(ptr,__FILE__,__LINE__); + + +/*! + \brief Dumps the allocated and freed memory details + \return On Successful prints memory information +*/ +static inline void HELP_DUMP_MEMINFO(void) +{ + help_memInfo(); +} + +static inline void * HELP_CREATE_OBJ(IN uint32_t unSubOper); + +/*! + \brief Macro to create object list based on the sub-operation type + \param[in] unSubOper Differentiates the objlist type + \return Void ptr(it can be either objlist, objattrlist, objacslist) returned +*/ +static inline void * HELP_CREATE_OBJ(IN uint32_t unSubOper) +{ + if (OBJLIST(unSubOper)) + { + ObjList *__pxTmpObj; + __pxTmpObj = HELP_MALLOC(sizeof(ObjList)); + if(!__pxTmpObj) + { + LOGF_LOG_CRITICAL(" malloc failed\n"); + return NULL; + } + INIT_LIST_HEAD(&(__pxTmpObj->xOlist)); + return (void*)__pxTmpObj; + } + else if (OBJATTRLIST(unSubOper)) + { + ObjAttrList *__pxTmpAttrObj; + __pxTmpAttrObj = HELP_MALLOC(sizeof(ObjAttrList)); + if(!__pxTmpAttrObj) + { + LOGF_LOG_CRITICAL(" malloc failed\n"); + return NULL; + } + INIT_LIST_HEAD(&(__pxTmpAttrObj->xOlist)); + return (void*)__pxTmpAttrObj; + + } + else if (IS_SOPT_OBJACSATTR(unSubOper)) + { + ObjACSList *__pxTmpAcsObj; + __pxTmpAcsObj = HELP_MALLOC(sizeof(ObjACSList)); + if(!__pxTmpAcsObj) + { + LOGF_LOG_CRITICAL(" malloc failed\n"); + return NULL; + } + INIT_LIST_HEAD(&(__pxTmpAcsObj->xOlist)); + return (void*)__pxTmpAcsObj; + } + else + { + LOGF_LOG_ERROR(" Pass Proper Objlist Flag (i.e SOPT_OBJVALUE, SOPT_OBJATTR, SOPT_OBJACSATTR\n"); + return NULL; + } +} + +/*! + \brief Macro to delete object list based on the sub-operation type + \param[in] pxObj Msg head ptr + \param[in] unSubOper Identify the objlist structure. + \param[in] unFlag 0-empty objlist for re-use 1-free objlist completely + \return +*/ +#define HELP_DELETE_OBJ(pxObj, unSubOper, unFlag) \ + help_delObj(pxObj,unSubOper,unFlag);\ + if(unFlag == FREE_OBJLIST) \ + pxObj = NULL; + +/*! + \brief Macro to delete current object list based on the sub-operation type + \param[in] pxMsgObj Complete msg on where to remove the current object + \param[in] pcObjName Objname based on the objname remove obj node from the list + \param[in] pxObj Current object for reference + \param[in] unSubOper Object list type + \return Removes requested objnode from list +*/ +#define HELP_DELETE_CURRENT_OBJ(pxMsgObj, pcObjName, pxObj, unSubOper) \ + if (OBJLIST(unSubOper)) \ + { \ + void *pTmp;\ + pTmp = list_entry(pxObj->xOlist.next,ObjList,xOlist); /*TODO*/ \ + help_delCurObj(pxMsgObj,pcObjName,unSubOper); \ + pxObj = pTmp; \ + } \ + +/*! + \brief Macro to create param list for notification + \param[in] unSubOper Differentiates the objlist type + \return Parameter list ptr +*/ +static inline void * HELP_CREATE_PARAM(IN uint32_t unSubOper) +{ + if (OBJLIST(unSubOper)) + { + ParamList *__pxTmpParam; + __pxTmpParam = HELP_MALLOC(sizeof(ParamList)); + if(!__pxTmpParam) + { + LOGF_LOG_CRITICAL(" malloc failed\n"); + return NULL; + } + INIT_LIST_HEAD(&(__pxTmpParam->xPlist)); + return (void*)__pxTmpParam; + } + else + { + LOGF_LOG_INFO(" Attribute list handling\n"); + } + return UGW_SUCCESS; +} + +/*! + \brief Macro to delete paramlist + \param[in] pxParam Paramlist ptr + \param[in] unSubOper + \return +*/ +#define HELP_DELETE_PARAM(pxParam, unSubOper) \ + help_delParam(pxParam,unSubOper);\ + pxParam = NULL; + +/*! + \brief Fills the objlist for get request on objects + \param[in] pxObj Msg void ptr + \param[in] pcObjName Objname + \param[in] unSubOper Objlist type (objlist, attrlist, acslist) + \return Void ptr which is used in paramlist addition +*/ + +static inline OUT void * HELP_OBJECT_GET(IN void *pxObj, IN const char *pcObjName, IN uint32_t unSubOper) +{ + if(OBJLIST(unSubOper)) + { + return help_addObjList(pxObj,pcObjName,NO_ARG_VALUE,NO_ARG_VALUE,NO_ARG_VALUE,NO_ARG_VALUE); + } + else if (OBJATTRLIST(unSubOper)) + { + return help_addObjAttrList(pxObj,pcObjName,NO_ARG_VALUE,NO_ARG_VALUE); + } + else + { + LOGF_LOG_ERROR("Error in Objlist Construction, Pass proper flag(i.e SOPT_OBJVALUE, SOPT_OBJATTR\n"); + return NULL; + } +} + +/*! + \brief Fills the paramlist which is part of objlist to get request on parameters + \param[in] pxObj Void ptr + \param[in] pcParamName Parameter name + \param[in] unSubOper Objlist type (objlist, attrlist, acslist) + \return +*/ + +static inline void HELP_PARAM_GET(IN void *pxObj, IN const char *pcParamName, IN uint32_t unSubOper) +{ + if(OBJLIST(unSubOper)) + { + help_addParamList(pxObj,pcParamName,NO_ARG_VALUE,NO_ARG_VALUE,NO_ARG_VALUE); + } + else if (OBJATTRLIST(unSubOper)) + { + help_addParamAttrList(pxObj,pcParamName,NO_ARG_VALUE,NO_ARG_VALUE,NO_ARG_VALUE, + NO_ARG_VALUE,NO_ARG_VALUE,NO_ARG_VALUE,NO_ARG_VALUE,NO_ARG_VALUE,NO_ARG_VALUE); + } + else + { + LOGF_LOG_ERROR("Error in Objlist Construction, Pass proper flag(i.e SOPT_OBJVALUE, SOPT_OBJATTR\n"); + } +} + +/*! + \brief Constructs objlist for get/set request + \param[in] pxObj Msg void ptr + \param[in] pcObjName Objname + \param[in] unOper Operation (ADD, DEL, MODIFY) + \param[in] unFlag Flag + \return Void ptr which is used to create ACS paramlist +*/ +static inline void * HELP_ACS_OBJ_CONSTRUCT(IN void *pxObj, IN const char *pcObjName, IN uint32_t unOper, IN uint32_t unObjFlag) +{ + return help_addAcsObjList(pxObj, pcObjName, unOper, unObjFlag); +} + +/*! + \brief Fills paramlist for get request on parameters + \param[in] pxObj Void ptr + \param[in] pcParamName Parameter name + \param[in] pcParamValue Parameter value + \param[in] unSubOper Objlist type (objlist,attrlist,acslist) + \return +*/ +static inline void * HELP_ACS_PARAM_CONSTRUCT(IN void *pxObj, IN const char *pcParamName, IN const char *pcParamValue, IN uint32_t unParamFlag) +{ + return help_addAcsParamList(pxObj, pcParamName, pcParamValue, unParamFlag); +} + +/*! + \brief Fills objlist for set request on objects + \param[in] pxObj Msg void ptr + \param[in] pcObjName Objname + \param[in] unSid Service id number + \param[in] unOper Operation (ADD, DEL, MODIFY) + \param[in] unSubOper Objlist type (objlist, attrlist, acslist) + \return Void ptr which is used to create paramlist +*/ +static inline void * HELP_OBJECT_SET(IN void *pxObj, IN const char *pcObjName, IN uint32_t unSid, IN uint32_t unOper,IN uint32_t unSubOper) +{ + (void)unSubOper; + return help_addObjList(pxObj,pcObjName,unSid,NO_ARG_VALUE,unOper,NO_ARG_VALUE); + +} + +/*! + \brief Fills paramlist for get request on parameters + \param[in] pxObj Void ptr + \param[in] pcParamName Parameter name + \param[in] pcParamValue Parameter value + \param[in] unSubOper Objlist type (objlist, attrlist, acslist) + \return +*/ +static inline void * HELP_PARAM_SET(IN void *pxObj, IN const char *pcParamName, IN const char *pcParamValue, IN uint32_t unSubOper) +{ + (void)unSubOper; + return help_addParamList(pxObj,pcParamName,NO_ARG_VALUE,pcParamValue,NO_ARG_VALUE); +} + +/*! + \brief Fills the paramlist on notification + \param[in] pxParam Void ptr + \param[in] pcParamName Parameter name + \param[in] pcParamValue Parameter value + \param[in] unSubOper Objlist type (objlist, attrlist, acslist) + \return +*/ + +static inline void HELP_ONLY_PARAM_SET(IN void *pxParam, IN const char *pcParamName, IN const char *pcParamValue, IN uint32_t unSubOper) +{ + (void)unSubOper; + help_paramListOnly(pxParam,pcParamName,NO_ARG_VALUE,pcParamValue,NO_ARG_VALUE); +} +/*! + \brief Copies the objlist from one list to another + \param[in] pSrc Source objlist ptr + \param[in] unSubOper Objtype + \param[in] pDst Destination objlist ptr + \param[in] nFlag Set to 0(copy complete object == COPY_COMPLETE_OBJ), 1(current object = COPY_SINGLE_OBJ) + \return Pdst copies the obj with values, on successful +*/ +static inline void HELP_COPY_OBJ(OUT void *pDst, IN void *pSrc, IN uint32_t unSubOper, IN uint8_t nFlag) +{ + if (nFlag == COPY_SINGLE_OBJ) + help_copyObjList(pDst,unSubOper,pSrc); + else + help_copyCompleteObjList(pDst,unSubOper,pSrc); +} +/*! + \brief Copies the paramlist from one list to another + \param[in] pSrc Source paramlist ptr + \param[in] pDst Destination objlist ptr + \return Pdst copies the paramlist with values +*/ +static inline void HELP_COPY_PARAM(OUT void *pDst, IN void *pSrc) +{ + help_copyParamList(pDst,pSrc); +} + +/*! + \brief Checks if the given object is empty or not + \param[in] pxObj Objlist ptr + \return UGW_SUCCESS on successful / UGW_FAILURE on failure +*/ +static inline int HELP_IS_EMPTY_OBJ(IN ObjList *pxObj) +{ + return help_isEmptyObj(pxObj); +} + +/*! + \brief Checks if the given object includes parameters or not + \param[in] pxObj Objlist ptr + \return UGW_SUCCESS on successful / UGW_FAILURE on failure +*/ +static inline int HELP_IS_EMPTY_OBJ_PARAM(IN ObjList *pxObj) +{ + return help_isEmptyObjParam(pxObj); +} + +/*! + \brief Prints recieved or constructed objlist + \param[in] pxObj Objlist ptr + \param[in] unSubOper Get objtype + \return +*/ +static inline void HELP_PRINT_OBJ(IN void *pxObj, IN uint32_t unSubOper) +{ + help_printObj(pxObj,unSubOper); +} + +/*! + \brief Prints recieved or constructed objlist + \param[in] pxParam Param list ptr + \param[in] unSubOper Get objtype + \return +*/ +static inline void HELP_PRINT_PARAM(IN void *pxParam, IN uint32_t unSubOper) +{ + (void)unSubOper; + help_printParamList(pxParam); +} + +/*! \brief Updates the particular parameter node in the given objlist if param node found, else adds new param node + \param[in] pxDstObjList Objlist list ptr where parameter values need to be updated + \param[in] pcObjname Object name + \param[in] pcParamName Parameter name + \param[in] pcParamValue Parameter value to update + \param[in] unParamId Parameter id + \param[in] unParamFlag Parameter flag + \return Destination objlist parameter value updated on successful / ugw_failure on failure +*/ +static inline int HELP_EDIT_NODE (INOUT ObjList *pxDstObjList, IN char *pcObjname, IN char *pcParamName, IN char *pcParamValue, + IN uint32_t unParamId, IN uint32_t unParamFlag) +{ + return help_editNode(pxDstObjList,pcObjname,pcParamName,pcParamValue,unParamId,unParamFlag); +} + +/*! \brief Updates particular parameter node in given object node if param node found, else adds new param node + \param[in] pxDstObjList Objlist list ptr where parameter values need to be updated + \param[in] pcObjname Object name + \param[in] pcParamName Parameter name + \param[in] pcParamValue Parameter value to update + \param[in] unParamId Parameter id + \param[in] unParamFlag Parameter flag + \return Destination objlist parameter value updated on successful / ugw_failure on failure +*/ +static inline int HELP_EDIT_SELF_NODE (INOUT ObjList *pxDstObjList, IN char *pcObjname, IN char *pcParamName, IN char *pcParamValue, + IN uint32_t unParamId, IN uint32_t unParamFlag) +{ + return help_editSelfNode(pxDstObjList,pcObjname,pcParamName,pcParamValue,unParamId,unParamFlag); +} + +/*! + \brief Moves object from one list to another and removes from the original list + \param[in] pxDstObj dst Objlist ptr + \param[in] pxSrcObj src Objlist ptr + \param[in] pcObjName Name to move objlist from src to dst + \param[in] unFlag Flag to identify objlist + \return ObjList on successful / UGW_FAILURE on failure +*/ +static inline int HELP_MOVEOBJLIST(INOUT ObjList *pxDstObj, + IN ObjList *pxSrcObj, + IN const char * pcObjName, + IN uint32_t unFlag) +{ + return help_moveObjList(pxDstObj, pxSrcObj, pcObjName, unFlag); +} + +/*! \brief Updates particular parameter node in given objlist + \param[in] pxObjDst Objlist list ptr where parameter values need to be updated + \param[in] pxObjSrc Source objlist ptr + \return Source objlist merged with destinition on successful / err_merge_failed on failure +*/ +static inline int HELP_MERGE_OBJLIST (INOUT ObjList *pxObjDst,IN ObjList *pxObjSrc) +{ + return help_mergeObjList(pxObjDst,pxObjSrc); +} + +/*! + \brief Macro to get the values from the given objlist structure + \param[in] pxObj Objlist ptr + \param[in] unOid ObjectId + \param[in] unInstance Instance number + \param[in] unParamId Parameter ID + \param[in] pcVal Parameter value + \return Pcval value of the parameter on successful +*/ +static inline int HELP_SL_GET (IN ObjList *pxObj, IN uint32_t unOid, IN uint32_t unInstance, IN uint32_t unParamId, OUT char *pcVal) +{ + return help_getValue(pxObj,unOid,unInstance,unParamId,pcVal); +} + +/*! + \brief Macro to get value of specfic parameter from the given objlist structure through object/parameter name match + \param[in] pxObj Objlist ptr + \param[in] pcObjName Object name + \param[in] unInstance Instance number + \param[in] pcParamname Parameter name + \param[out] pcVal Parameter value + \return value of the parameter when successful +*/ +static inline int HELP_SL_GET_NAME_BASED (IN ObjList *pxObj, IN char *pcObjName, IN uint32_t unInstance, IN char *pcParamName, OUT char *pcVal) +{ + return help_getValueNameBased(pxObj, pcObjName ,unInstance, pcParamName, pcVal); +} + +/*! + \brief Macro to set the values in the given objlist structure + \param[in] pxObj Objlist ptr + \param[in] unOid ObjectId + \param[in] unInstance Instance number + \param[in] unParamId Parameter ID + \param[in] pcVal Parameter value \ + \return Updated objlist on successful +*/ +static inline int HELP_SL_SET (INOUT ObjList *pxObj, IN uint32_t unOid, IN uint32_t unInstance, IN uint32_t unParamId, IN char *pcVal) +{ + return help_setValue(pxObj,unOid,unInstance,unParamId,pcVal); +} + +/*! + \brief Macro to set value of specfic parameter to the given objlist structure through object/parameter name match + \param[in] pxObj Objlist ptr + \param[in] unOid ObjectId + \param[in] unInstance Instance number + \param[in] unParamId Parameter ID + \param[in] pcVal Parameter value + \return Updated objlist on successful +*/ +static inline int HELP_SL_SET_NAME_BASED (INOUT ObjList *pxObj, IN char *pcObjName, IN uint32_t unInstance, IN char *pcParamName, IN char *pcVal) +{ + return help_setValueNameBased(pxObj, pcObjName, unInstance, pcParamName, pcVal); +} + +/*! + \brief Stores objlist value to tmp file for later use + \param[in] pxObj Objlist ptr + \param[in] pcPath Path to create a tmp file + \return UGW_SUCCESS on successful / UGW_FAILURE on failure +*/ +static inline int HELP_STORELOCALDB(IN ObjList *pxObj, IN const char *pcPath) +{ + return help_storeLocalDB(pxObj, pcPath); +} + +/*! + \brief Constructs objlist from tmp file + \param[out] pxObj Objlist ptr + \param[in] pcPath Path to fetch the values + \return Returns ObjList on successful / UGW_FAILURE on failure +*/ +static inline int HELP_LOADLOCALDB(OUT ObjList *pxObj, IN const char *pcPath) +{ + return help_loadLocalDB(pxObj, pcPath); +} + +/*! + \brief Function to objlist to get the objlist ptr based on the condition + \param[in] pxObj Objlist ptr + \param[in] paramName Parameter name to match + \param[in] paramValue Parameter value name to value + \return Returns ObjList on successful / UGW_FAILURE on failure +*/ +static inline OUT ObjList* HELP_GETOBJPTR(IN ObjList *pxObj, IN const char *paramName, IN const char *paramValue) +{ + return help_getObjPtr(pxObj, paramName, paramValue); +} + +/*! + \brief Deletes object from given objlist + \param[in] pxHeadObj Head Objlist ptr + \param[in] pxObj Object to be deleted from the list + \return UGW_SUCCESS on successful / UGW_FAILURE on failure +*/ +static inline int HELP_DELOBJPTR(INOUT ObjList *pxHeadObj, IN ObjList *pxObj) +{ + return help_delObjPtr(pxHeadObj, pxObj); +} + +/*! + \brief Macro to loop through objlist to get object node information + \param[in] __pxMsgObj Msg header objlist pointer + \param[in] __pxObj Objlist pointer used to copy the actual objlist values +*/ +#define FOR_EACH_OBJ(__pxMsgObj,__pxObj)\ + ObjList * OBJ; \ + OBJ = __pxMsgObj; \ + list_for_each_entry(__pxObj,&(OBJ->xOlist),xOlist) \ +/*! + \brief FOR_EACH_ATTROBJ macro is used to loop through objAttrlist to get object node information + \param[in] __pxMsgObj msg header objattrlist pointer + \param[in] __pxObj objlist pointer used to copy the actual objlist values +*/ +#define FOR_EACH_OBJATTR(__pxMsgObj,__pxObj)\ + ObjAttrList * OBJ; \ + OBJ = __pxMsgObj; \ + list_for_each_entry(__pxObj,&(OBJ->xOlist),xOlist) \ + +/*! + \brief Macro to loop through ACS objAttrlist to get object node information + \param[in] __pxMsgObj Msg header ACS objattrlist pointer + \param[in] __pxObj ACS objlist pointer used to copy the actual objlist values +*/ +#define FOR_EACH_OBJ_ACS_ATTR(__pxMsgObj,__pxObj)\ + ObjACSList * OBJ; \ + OBJ = __pxMsgObj; \ + list_for_each_entry(__pxObj,&(OBJ->xOlist),xOlist) \ + + +/*! + \brief Macro to loop through paramlist + \param[in] __pxObj Objlist pointer + \param[in] __pxParam Paramlist pointer used to copy the actual paramlist values +*/ +#define FOR_EACH_PARAM(__pxObj,__pxParam)\ + list_for_each_entry(__pxParam,&(__pxObj->xParamList.xPlist),xPlist) \ + +/*! + \brief Macro to loop through paramlist + \param[in] __pxObj ObjiAttrlist pointer + \param[in] __pxParam Paramlist pointer used to copy the actual paramattrlist values +*/ +#define FOR_EACH_PARAM_ATTR(__pxObj,__pxParam)\ + list_for_each_entry(__pxParam,&(__pxObj->xParamAttrList.xPlist),xPlist) \ + +/*! + \brief Macro to loop through paramlist + \param[in] __pxObj ObjAcsAttrlist pointer + \param[in] __pxParam Paramlist pointer used to copy the actual paramattrlist values +*/ +#define FOR_EACH_PARAM_ACS_ATTR(__pxObj,__pxParam)\ + list_for_each_entry(__pxParam,&(__pxObj->xParamAcsList.xPlist),xPlist) \ + +/*! + \brief Macro to loop through paramlist used in case of notification + \param[in] __pxSrc Paramlist pointer + \param[in] __pxParam Paramlist pointer used to copy the actual paramlist values +*/ +#define FOR_EACH_PARAM_ONLY(__pxSrc,__pxParam)\ + list_for_each_entry(__pxParam,&(__pxSrc->xPlist),xPlist) \ + +/*! + \brief Function to get objname from objlist + \param[in] __pxObjName Objnode ptr + \return Returns objname on successful +*/ +static inline char * GET_OBJ_NAME(IN ObjList * __pxObjName) +{ + return __pxObjName->sObjName; +} + +/*! + \brief Function to get sid from objlist + \param[in] __pxObjSid Objnode ptr + \return Returns sid on successful +*/ +static inline int16_t GET_OBJ_SID(IN ObjList * __pxObjSid) +{ + return (int16_t)__pxObjSid->unSid; +} + +/*! + \brief Function to get oid from objlist + \param[in] __pxObjOid Objnode ptr + \return Returns oid on successful +*/ + +#define GET_OBJ_OID(__pxObjOid) \ + (int16_t)__pxObjOid->unOid + +/*! + \brief Function to get subOper from objlist + \param[in] __pxObjSubOper Objnode ptr + \return Returns subOper(add, delete, modify) on successful +*/ +static inline uint32_t GET_OBJ_SUBOPER(IN ObjList * __pxObjSubOper) +{ + return __pxObjSubOper->unObjOper; +} + +/*! + \brief Function to get object flag from objlist + \param[in] __pxObjFlag Objnode ptr + \return Flag(access, dynamic, etc) on successful +*/ +static inline uint32_t GET_OBJ_FLAG(IN ObjList * __pxObjFlag) +{ + return __pxObjFlag->unObjFlag; +} + +/*! + \brief Function to get paramname from paramlist + \param[in] __pxParamName Param Node ptr + \return Param name on successful +*/ +static inline char * GET_PARAM_NAME(IN ParamList * __pxParamName) +{ + return __pxParamName->sParamName; +} + +/*! + \brief Function to get paramvalue from paramlist + \param[in] __pxParamValue Param Node ptr + \return Param value on successful +*/ +static inline char * GET_PARAM_VALUE(IN ParamList * __pxParamValue) +{ + return __pxParamValue->sParamValue; +} + +/*! + \brief Function to get paramId from paramlist + \param[in] __pxParamId Param Node ptr + \return ParamId on successful +*/ +#define GET_PARAM_ID(__pxParamId) \ + (int16_t)__pxParamId->unParamId + +/*! + \brief Function to get paramFlag from paramlist + \param[in] __pxParamFlag Param Node ptr + \return Param Flag(dynamic, type, modified, etc) on successful +*/ +static inline uint32_t GET_PARAM_FLAG(IN ParamList * __pxParamFlag) +{ + return __pxParamFlag->unParamFlag; +} + +/*! + \brief Function to get objname from ObjAttrList + \param[in] __pxAttrObjname ObjAttr Node ptr + \return ObjAttr objname on successful +*/ +static inline char * GET_ATTR_OBJNAME(IN ObjAttrList * __pxAttrObjname) +{ + return __pxAttrObjname->sObjName; +} + +/*! + \brief Function to get web name from ObjAttrList + \param[in] __pxAttrWebName ObjAttr Node ptr + \return ObjAttr web name on successful +*/ +static inline char * GET_ATTR_WEBNAME(IN ObjAttrList * __pxAttrWebName) +{ + return __pxAttrWebName->sObjWebName; +} + +/*! + \brief Function to get unObjAttr from ObjAttrList + \param[in] __pxAttrFlag ObjAttr Node ptr + \return ObjAttr flag on successful +*/ +#define GET_ATTR_FLAG(__pxAttrFlag) \ + (int32_t)__pxAttrFlag->unObjAttr + +/*! + \brief Function to get paramname from ParamAttrList + \param[in] __pxParamAttrName ParamAttrlist Node ptr + \return Param name on successful +*/ +static inline char * GET_ATTR_PARAMNAME(IN ParamAttrList * __pxParamAttrName) +{ + return __pxParamAttrName->sParamName; +} + +/*! + \brief Function to get param profile from ParamAttrList + \param[in] __pxParamAttrProfile ParamAttrlist Node ptr + \return Param profile on successful +*/ +static inline char * GET_ATTR_PARAMPROFILE(IN ParamAttrList * __pxParamAttrProfile) +{ + return __pxParamAttrProfile->sParamProfile; +} + +/*! + \brief Function to get param webname from ParamAttrList + \param[in] __pxParamAttrWebName paramAttrlist Node ptr + \return Param web name on successful +*/ +static inline char * GET_ATTR_PARAMWEBNAME(IN ParamAttrList * __pxParamAttrWebName) +{ + return __pxParamAttrWebName->sParamWebName; +} + +/*! + \brief Function to get param valid values from ParamAttrList + \param[in] __pxParamAttrValidValue ParamAttrlist Node ptr + \return Param enums on successful +*/ +static inline char * GET_ATTR_VALIDVAL(IN ParamAttrList * __pxParamAttrValidValue) +{ + return __pxParamAttrValidValue->sParamValidVal; +} + +/*! + \brief Function to get param webname from ParamAttrList + \param[in] __pxParamAttrValue ParamAttrlist Node ptr + \return Param default value on successful +*/ +static inline char * GET_ATTR_PARAMVALUE(IN ParamAttrList * __pxParamAttrValue) +{ + return __pxParamAttrValue->sParamValue; +} + +/*! + \brief Function to get param minvalue from ParamAttrList + \param[in] __pxParamAttrMinValue ParamAttrlist Node ptr + \return Param Minimum value on successful +*/ +static inline uint32_t GET_ATTR_MINVAL(IN ParamAttrList * __pxParamAttrMinValue) +{ + return __pxParamAttrMinValue->unMinVal; +} + +/*! + \brief Function to get param maxvalue from ParamAttrList + \param[in] __pxParamAttrMaxValue ParamAttrlist Node ptr + \return Param Maximum value on successful +*/ +static inline uint32_t GET_ATTR_MAXVAL(IN ParamAttrList * __pxParamAttrMaxValue) +{ + return __pxParamAttrMaxValue->unMaxVal; +} + +/*! + \brief Function to get param minlen from ParamAttrList + \param[in] __pxParamAttrMinLen ParamAttrList Node ptr + \return Param Min Len on successful +*/ +static inline uint32_t GET_ATTR_MINLEN(IN ParamAttrList * __pxParamAttrMinLen) +{ + return __pxParamAttrMinLen->unMinLen; +} + +/*! + \brief Function to get param maxlen from ParamAttrList + \param[in] __pxParamAttrMaxLen ParamAttrList Node ptr + \return Param Max Len on successful +*/ +static inline uint32_t GET_ATTR_MAXLEN(IN ParamAttrList * __pxParamAttrMaxLen) +{ + return __pxParamAttrMaxLen->unMaxLen; + +} + +/*! + \brief Function to get param flag from ParamAttrList + \param[in] __pxParamAttrFlag ParamAttrList Node ptr + \return Param flag(which holds access, syntax, permit, etc) on successful +*/ +#define GET_ATTR_PARAMFLAG(__pxParamAttrFlag) \ + (int32_t)__pxParamAttrFlag->unParamFlag + +/*! + \brief Function to get acslist objname + \param[in] __pxAcsObjName Objname ptr + \return Objname on successful +*/ +static inline char * GET_ACS_OBJNAME(IN ObjACSList * __pxAcsObjName) +{ + return __pxAcsObjName->sObjName; +} + +/*! + \brief Function to get acslist objper + \param[in] __pxAcsObjOper ObjOper ptr + \return ObjOper on successful +*/ +static inline uint32_t GET_ACS_OBJOPER(IN ObjACSList * __pxAcsObjOper) +{ + return __pxAcsObjOper->unObjOper; +} + +/*! + \brief Function to get acslist objFlag + \param[in] __pxAcsObjFlag ObjFlag ptr + \return ObjFlag on successful +*/ +#define GET_ACS_OBJFLAG(__pxAcsObjFlag) \ + (int32_t)__pxAcsObjFlag->unObjFlag + +/*! + \brief Function to get acslist parmname + \param[in] __pxAcsParamName objparm ptr + \return on successfull return paramname +*/ +static inline char * GET_ACS_PARAMNAME(IN ParamACSList * __pxAcsParamName) +{ + return __pxAcsParamName->sParamName; +} + +/*! + \brief Function to get acslist param accesslist value + \param[in] __pxAcsParam Access list value ptr + \return Accesslist info on successful +*/ +static inline char * GET_ACS_ACCESSLIST(IN ParamACSList * __pxAcsParam) +{ + return __pxAcsParam->sParamValue; +} + +/*! + \brief Function to get acslist ParamFlag + \param[in] __pxAcsObjFlag ParamFlag ptr + \return ParamFlag on successful +*/ +#define GET_ACS_PARAMFLAG(__pxAcsParamFlag) \ + (int32_t)__pxAcsParamFlag->unParamFlag + +#endif //_HELP_OBJMSG_H +/* @} */ diff --git a/include/help_proto.h b/include/help_proto.h new file mode 100755 index 0000000000000000000000000000000000000000..47d70e4fce4bc942384776d2546483e3723e6a35 --- /dev/null +++ b/include/help_proto.h @@ -0,0 +1,376 @@ +/******************************************************************************** + + Copyright (c) 2015 + Lantiq Beteiligungs-GmbH & Co. KG + Lilienthalstrasse 15, 85579 Neubiberg, Germany + For licensing information, see the file 'LICENSE' in the root folder of + this software module. + +********************************************************************************/ + +/* ***************************************************************************** + * File Name : help_proto.h * + * Description : Helper Library contains list manipulation function * + * prototypes used across the system. * + * *****************************************************************************/ + +/*! \file help_proto.h + \brief File contains common API prototypes used across all modules the software +*/ + +/** \addtogroup LIBHELP */ +/* @{ */ + + +#ifndef _HELP_PROTO_H +#define _HELP_PROTO_H + + +#include "help_structs.h" + +/*! + \brief API to store objlist value to tmp file for later use + \param[in] pxObj Objlist ptr + \param[in] pcPath Path where to create a tmp file + \return UGW_SUCCESS on successful / UGW_FAILURE on failure +*/ +int help_storeLocalDB(IN ObjList *pxObj, + IN const char *pcPath); + +/*! + \brief API to construct objlist from tmp file + \param[out] pxObj Objlist ptr + \param[in] pcPath Path where to fetch the values from + \return ObjList on successful / UGW_FAILURE on failure +*/ +int help_loadLocalDB(OUT ObjList *pxObj, + IN const char *pcPath); + + +/*! \brief API to add an add object node to the head node + \param[in] pxObjList Pointer to the List head object node + \param[in] pcObjName Name of the Object + \param[in] unSid Service Id corresponding to the Object + \param[in] unOid Parameter Id + \param[in] unSubOper Suboperation at object level(add, del, modify) + \param[in] unObjFlag Identify access, dynamic, etc + \return +*/ + +ObjList * help_addObjList(IN ObjList *pxObjList, + IN const char *pcObjName, + IN uint16_t unSid, + IN uint16_t unOid, + IN uint32_t unSubOper, + IN uint32_t unObjFlag); + +/*! \brief API to add a add param node to Objlist node + \param[in] pxObjList Pointer to the List head object node + \param[in] pcParamName Name of the Parameter + \param[in] unParamId Parameter Id + \param[in] pcParamValue Parameter Value + \param[in] unFlag Holds masks type, dynamic, modified information in bit + \return Values in paramList on successful / Proper code on failure +*/ +ParamList * help_addParamList(IN ObjList *pxObjList, + IN const char *pcParamName, + IN uint16_t unParamId, + IN const char *pcParamValue, + IN uint32_t unFlag); + +/*! \brief API to dump/print the Object Info from the provided Object List + \param[in] pxObj Void ptr + \param[in] unSubOper Suboperation to print objects(objlist, attrlist, acslist) + \return +*/ +void help_printObj(IN void *pxObj, + IN uint32_t unSubOper); + +/*! \brief API to print paramlist information + \param[in] pxParamList ParamList node ptr + \return +*/ +void help_printParamList(IN ParamList *pxParamList); + +/*! \brief API to free the object info from the Object List structure + \param[in] pObj Pointer to the List head object node + \param[in] unSubOper Suboperation to identify object type + \param[in] unFlag EMPTY_OBJLIST - empty objlist for reuse, FREE_OBJLIST - free objlist completely + \return +*/ +void help_delObj(IN void *pObj, + IN uint32_t unSubOper, + IN uint32_t unFlag); + +/*! \brief API to free the object info from the Object List structure + \param[in] pObj Pointer to the List head object node + \param[in] pcObjName Object name + \param[in] unFlag Flag to identify object type + \return +*/ +int help_delCurObj(IN void *pObj, + IN const char *pcObjName, + IN uint32_t unFlag); +/*! \brief API to free the paramlist + \param[in] pParam Pointer paramlist ptr + \param[in] unFlag Flag to identify paramlist type type + \return +*/ +void help_delParam(IN void *pParam, + IN uint32_t unFlag); + +/*! \brief API to get object count + \param[in] pxObjList Pointer to the objlist + \param[in] pnObjCnt Total number of object node count in given list + \return +*/ +void help_getObjListCnt(IN ObjList *pxObjList, + OUT int32_t *pnObjCnt); + + +/*! \brief API to get parameter count + \param[in] pxObjList Pointer to the objlist + \param[in] pcObjName Object name under which parmater node count to get + \param[in] pParamCnt Total number of parameter count + \return +*/ +void help_getParamListCnt( IN ObjList *pxObjList, + IN char8_t *pcObjName, + OUT int32_t *pParamCnt); + +/*! \brief Function to copy src object "as is" to dst object + \param[in] pSrcObj Void ptr + \param[in] unFlag Flag to define object type(objlist, attrobjlist, acsobjlist) + \param[out] pDstObj Void ptr + \return +*/ +void help_copyObjList(OUT void *pDstObj , + IN uint32_t unFlag, + IN void *pSrcObj); + +/*! \brief API to copy src object complete objlist "as is" to dst object + \param[in] pDst Void ptr + \param[in] unFlag Flag to define object type(objlist, attrobjlist, acsobjlist) + \param[out] pSrc Void ptr + \return +*/ +void help_copyCompleteObjList(OUT void *pDst , + IN uint32_t unFlag , + IN void *pSrc); +/*! \brief API to add and traverse paramlist alone, used for notification + \param[in] pxSrcParam Void ptr + \param[in] pcParamName Parameter name + \param[in] unParamId Parameter Id + \param[in] pcParamValue Parameter Value + \param[in] unFlag Holds masks type, dynamic, modified information in bit + \return +*/ +OUT ParamList * help_paramListOnly(IN ParamList *pxSrcParam , + IN const char *pcParamName, + IN uint16_t unParamId, + IN const char *pcParamValue, + IN uint32_t unFlag); + + +/*! \brief API to construct attrlist for object with requested attribute values + \param[in] pxObjAttrList Attrobj head node ptr + \param[in] pcObjName Object name + \param[in] pcWebName Webname for requested object + \param[in] unObjAttrFlag Holds access, multiinst information in bits + \return +*/ +ObjAttrList * help_addObjAttrList(IN ObjAttrList *pxObjAttrList, + IN const char *pcObjName, + IN const char *pcWebName, + IN uint32_t unObjAttrFlag); + +/*! \brief API to construct attrlist for parameter with requested attribute values + \param[in] pxObjAttrList Attrobj head node ptr + \param[in] pcParamName Parameter name + \param[in] pcParamProfile Parameter profile + \param[in] pcParamWebName Parameter webname + \param[in] pcParamValidVal Validation values with comma separated + \param[in] pcParamDefaultVal Default value of the parameter + \param[in] unMinVal Minimum value if the parameter type is int + \param[in] unMaxVal Maximum value if the parameter type is int + \param[in] unMinLen Minimum length if the parameter type is string + \param[in] unMaxLen Maximum length if the parameter type is string + \param[in] unParamFlag Holds access, syntax, permit information in bits + \return +*/ + +OUT ParamAttrList * help_addParamAttrList(IN ObjAttrList *pxObjAttrList, + IN const char *pcParamName, + IN const char *pcParamProfile, + IN const char *pcParamWebName, + IN const char *pcParamValidVal, + IN const char *pcParamDefaultVal, + IN uint32_t unMinVal, + IN uint32_t unMaxVal, + IN uint32_t unMinLen, + IN uint32_t unMaxLen, + IN uint32_t unParamFlag); + +/*! \brief API to construct ACS attrlist for object with requested attribute values + \param[in] pxObjACSList Object list with ACS attribute supported + \param[in] sObjName Object name + \param[in] unObjOper Suboperation for the given object MODIFY + \param[in] unObjFlag Flag + \return +*/ +OUT ObjACSList* help_addAcsObjList(IN ObjACSList *pxObjACSList, + IN const char sObjName[MAX_LEN_OBJNAME], + IN uint32_t unObjOper, + IN uint32_t unObjFlag); + +/*! \brief API to construct ACS attrlist for parameter with requested attribute values + \param[in] pxObjACSList Object list with ACS attribute supported + \param[in] sParamName Parameter name + \param[in] sParamValue Parameter value + \param[in] nParamFlag Holds syntax, InformToAcs, SaveToFlash, Notification, AccessControl, ChangeFlag information in bits + \return +*/ +OUT ParamACSList * help_addAcsParamList(IN ObjACSList *pxObjACSList, + IN const char sParamName[MAX_LEN_PARAM_NAME], + IN const char sParamValue[MAX_LEN_PARAM_VALUE], + IN uint32_t nParamFlag); + +/*! \brief API to update particular parameter node in given objlist + \param[in] pxDstObjList Objlist list ptr where parameter values needed to update + \param[in] pcObjname Object name + \param[in] pcParamName Parameter name + \param[in] pcParamValue Parameter value to update + \param[in] unParamId Parameter id to update + \param[in] unParamFlag Parameter flag to update + \return Destination objlist parameter value updated on successful +*/ +uint32_t help_editNode (INOUT ObjList *pxDstObjList, + IN char *pcObjname, + IN char *pcParamName, + IN char *pcParamValue, + IN uint32_t unParamId, + IN uint32_t unParamFlag); + +/*! \brief API to update particular parameter node in given objlist ptr + \param[in] pxDstObjList Objlist list ptr where parameter values need to be updated + \param[in] pcObjname Object name + \param[in] pcParamName Parameter name + \param[in] pcParamValue Parameter value to update + \param[in] unParamId Parameter id to update + \param[in] unParamFlag Parameter flag to update + \return Destination objlist parameter value updated on successful +*/ +uint32_t help_editSelfNode (INOUT ObjList *pxDstObjList, + IN char *pcObjname, + IN char *pcParamName, + IN char *pcParamValue, + IN uint32_t unParamId, + IN uint32_t unParamFlag); + + +/*! \brief API to update particular parameter node in given objlist + \param[in] pxObjDst Objlist list ptr where parameter values needed to update + \param[in] pxObjSrc Source objlist ptr + \return Source objlist is merged with destination objlist on successful +*/ +uint32_t help_mergeObjList(INOUT ObjList *pxObjDst, + IN ObjList *pxObjSrc); +/*! + \brief API to copy paramlist from one list to another + \param[in] pxSrc Source paramlist ptr + \param[in] pxDst Destination objlist ptr + \return Paramlist with values is copied to pxdst on successful +*/ +void help_copyParamList(OUT ParamList *pxDst, + OUT ParamList *pxSrc); + + +/*! + \brief API to get the values from the given objlist structure + \param[in] pxObj Objlist ptr + \param[in] unOid ObjectId + \param[in] unInstance Instance number + \param[in] unParamId Parameter ID + \param[in] pcVal Parameter value + \return Pcval Value of the parameter on successful / failure +*/ +int help_getValue (IN ObjList *pxObj, IN uint32_t unOid, IN uint32_t unInstance, IN uint32_t unParamId, OUT char *pcVal); + +/*! + \brief API to get value of specfic parameter from the given objlist structure through object/parameter name match + \param[in] pxObj Objlist ptr + \param[in] pcObjName Object name + \param[in] unInstance Instance number + \param[in] pcParamname Parameter name + \param[out] pcVal Parameter value + \return value of the parameter when successful +*/ +int help_getValueNameBased(IN ObjList *pxObj, IN char *pcObjName, IN uint32_t unInstance, IN char *pcParamName, OUT char *pcVal); + +/*! + \brief Macro to set the values in the given objlist structure + \param[in] pxObj Objlist ptr + \param[in] unOid ObjectId + \param[in] unInstance Instance number + \param[in] unParamId Parameter ID + \param[in] pcVal Parameter value + \return Updated objlist on successful / failure +*/ +int help_setValue (INOUT ObjList *pxObj, IN uint32_t unOid, IN uint32_t unInstance, IN uint32_t unParamId, IN char *pcVal); + +/*! + \brief API to set value of specfic parameter to the given objlist structure through object/parameter name match + \param[in] pxObj Objlist ptr + \param[in] unOid ObjectId + \param[in] unInstance Instance number + \param[in] unParamId Parameter ID + \param[in] pcVal Parameter value + \return Updated objlist on successful / failure +*/ +int help_setValueNameBased(IN ObjList *pxObj, IN char *pcObjName, IN uint32_t unInstance, IN char *pcParamName, OUT char *pcVal); + +/*! + \brief API to traverse objlist and get objlist ptr based on the defined condition + \param[in] pxObj Objlist ptr + \param[in] paramName Parameter name to match + \param[in] paramValue Parameter value to match + \return ObjList on successful / UGW_FAILURE on failure +*/ +OUT ObjList* help_getObjPtr(IN ObjList *pxObj, + IN const char *paramName, + IN const char *paramValue); +/*! + \brief API to objlist to get the objlist ptr based on the condition + \param[in] pxHeadObj Head Objlist ptr + \param[in] pxObj Object to be deleted from the list + \return ObjList on successful / UGW_FAILURE on failure +*/ +OUT int help_delObjPtr(INOUT ObjList *pxHeadObj, IN ObjList *pxObj); + +/*! + \brief API to move object from one list to another and remove from the original list + \param[in] pxDstObj Destination(dst) Objlist ptr + \param[in] pxSrcObj Source(src) Objlist ptr + \param[in] pcObjName Name to move objlist from src to dst + \param[in] unFlag Flag to identify objlist + \return ObjList on successful / UGW_FAILURE on failure +*/ +OUT int help_moveObjList(INOUT ObjList *pxDstObj, + IN ObjList *pxSrcObj, + IN const char * pcObjName, + IN uint32_t unFlag); + +/*! \brief API to check if obj list ptr is empty or not + \param[in] pxObj Obj ptr + \return UGW_SUCCESS on successful / UGW_FAILURE on failure +*/ +OUT int help_isEmptyObj(IN ObjList *pxObj); + +/*! \brief API to check if obj list included parameters or not + \param[in] pxObj Obj ptr + \return UGW_SUCCESS on successful / UGW_FAILURE on failure +*/ +OUT int help_isEmptyObjParam(IN ObjList *pxObj); + +#endif //#ifndef _HELP_PROTO_H +/* @} */ diff --git a/include/help_structs.h b/include/help_structs.h new file mode 100755 index 0000000000000000000000000000000000000000..44ae4bd2608fc57e2139e8baa8dad04caf5d4c31 --- /dev/null +++ b/include/help_structs.h @@ -0,0 +1,122 @@ +/******************************************************************************** + + Copyright (c) 2015 + Lantiq Beteiligungs-GmbH & Co. KG + Lilienthalstrasse 15, 85579 Neubiberg, Germany + For licensing information, see the file 'LICENSE' in the root folder of + this software module. + +********************************************************************************/ + +/* ***************************************************************************** + * File Name : help_structs.h * + * Description : Common Library contains functions, defines, * + * structs, enums used across the modules like CAL, CAPI,* + * CSD, Servd, and Management Entities * + * *****************************************************************************/ + + +/*! \file help_structs.h +\brief File contains the data + structures common across all modules in UGW software +*/ + +#ifndef _HELP_STRUCTS_H +#define _HELP_STRUCTS_H + +#include "help_enums.h" +#include "help_defs.h" +#include "list.h" + +/** \addtogroup LIBHELP */ +/* @{ */ + +/*! + * \brief Contains the parameters list(attribute values) + * */ +typedef struct +{ + char sParamName[MAX_LEN_PARAM_NAME]; /*!< Parameter Name */ + char sParamProfile[MAX_LEN_PROFILENAME]; /*!< Profile name */ + char sParamWebName[MAX_LEN_WEBNAME]; /*!< Web name */ + char sParamValidVal[MAX_LEN_VALID_VALUE]; /*!< Valid values */ + char sParamValue[MAX_LEN_PARAM_VALUE]; /*!< Default values */ + uint32_t unMinVal; /*!< Minimum value */ + uint32_t unMaxVal; /*!< Maximum value */ + uint32_t unMinLen; /*!< Minimum length */ + uint32_t unMaxLen; /*!< Maximum length */ + uint32_t unParamFlag; /*!< Parameter ACCESS[READ, WRITE], SYNTAX[Int, string, boolean, hex, datetime, etc], + PERMIT[SuperAdmin,Admin,Normal,Guest] */ + ListHead xPlist; /*!< Traverse List */ +}ParamAttrList; + +/*! + * \brief Contains the (objname,attr list,paramlist) + * */ +typedef struct +{ + char sObjName[MAX_LEN_OBJNAME]; /*!< Object Name */ + char sObjWebName[MAX_LEN_WEBNAME]; /*!< Web name mapping with respect to object */ + uint32_t unObjAttr; /*!< ACCESS[READ,WRITE], MultiInst, attribute value */ + ParamAttrList xParamAttrList; /*!< Attribute paramlist */ + ListHead xOlist; /*!< Traverse List */ +}ObjAttrList; + + +/*! + * \brief Contains the parameters list(attribute values) + * */ +typedef struct +{ + char sParamName[MAX_LEN_PARAM_NAME]; /*!< Parameter Name */ + char sParamValue[MAX_LEN_PARAM_VALUE]; /*!< AccessList param value can be NULL/subscriber*/ + uint32_t unParamFlag; /*!< Parameter flag which holds Notification[active,passive,disabled] */ + ListHead xPlist; /*!< Traverse List */ +}ParamACSList; + +/*! + * \brief Contains the (objname, attr list, paramlist) + * */ +typedef struct +{ + char sObjName[MAX_LEN_OBJNAME]; /*!< Object Name */ + uint32_t unObjOper; /*!< Object Operation MODIFY */ + uint32_t unObjFlag; /*!< Reserved */ + ParamACSList xParamAcsList; /*!< Attribute paramlist */ + ListHead xOlist; /*!< Traverse List */ +}ObjACSList; + + +/*! + \brief Contains the parameters list(name, value, type) that are passed in related functions and Callbacks + */ +typedef struct +{ + char sParamName[MAX_LEN_PARAM_NAME]; /*!< Parameter Name */ + char sParamValue[MAX_LEN_PARAM_VALUE]; /*!< Parameter Value */ + uint16_t unParamId; /*!< Parameter Id */ + uint32_t unParamFlag; /*!< Parameter to mask type, dynamic, modified, etc info in bit */ + ListHead xPlist; /*!< Traverse List */ +}ParamList; + +/*! + \brief Contains the (objname, sid, oid, paramlist) that are passed in related functions and Callbacks + */ +typedef struct +{ + char sObjName[MAX_LEN_OBJNAME]; /*!< Object Name */ + uint16_t unSid; /*!< Corresponding Service Id */ + uint16_t unOid; /*!< Object Id */ + uint32_t unObjOper; /*!< Object Operation ADD, DELETE, MODIFY, etc */ + uint32_t unObjFlag; /*!< Object flag for access, dynamic, etc */ + ParamList xParamList; /*!< Name Value Pair */ + ListHead xOlist; /*!< Traverse List */ +}ObjList; + + +/* @} */ + +#endif //#ifndef _HELP_STRUCTS_H + + + diff --git a/include/list.h b/include/list.h new file mode 100755 index 0000000000000000000000000000000000000000..9cb5523c438011365619a6f583e814b1d6f1f76e --- /dev/null +++ b/include/list.h @@ -0,0 +1,211 @@ +/*- + * Copyright (c) 2011 Felix Fietkau <nbd@openwrt.org> + * Copyright (c) 2010 Isilon Systems, Inc. + * Copyright (c) 2010 iX Systems, Inc. + * Copyright (c) 2010 Panasas, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _LINUX_LIST_H_ +#define _LINUX_LIST_H_ + +#include <stddef.h> +#include <stdbool.h> + +#define prefetch(x) + +#ifndef container_of +#define container_of(ptr, type, member) \ + ({ \ + const typeof(((type *) NULL)->member) *__mptr = (ptr); \ + (type *) ((char *) __mptr - offsetof(type, member)); \ + }) +#endif + +/*! + \brief list_head +*/ +struct list_head { + struct list_head *next; /*!< next node ptr */ + struct list_head *prev; /*!< prev node ptr */ +}; + +#define LIST_HEAD_INIT(name) { &(name), &(name) } +#undef LIST_HEAD +#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name) + +static inline void +INIT_LIST_HEAD(struct list_head *list) +{ + list->next = list->prev = list; +} + +static inline bool +list_empty(const struct list_head *head) +{ + return (head->next == head); +} + +static inline bool +list_is_first(const struct list_head *list, + const struct list_head *head) +{ + return list->prev == head; +} + +static inline bool +list_is_last(const struct list_head *list, + const struct list_head *head) +{ + return list->next == head; +} + +static inline void +_list_del(struct list_head *entry) +{ + entry->next->prev = entry->prev; + entry->prev->next = entry->next; +} + +static inline void +list_del(struct list_head *entry) +{ + _list_del(entry); + entry->next = entry->prev = NULL; +} + +static inline void +_list_add(struct list_head *_new, struct list_head *prev, + struct list_head *next) +{ + + next->prev = _new; + _new->next = next; + _new->prev = prev; + prev->next = _new; +} + +static inline void +list_del_init(struct list_head *entry) +{ + _list_del(entry); + INIT_LIST_HEAD(entry); +} + +#define list_entry(ptr, type, field) container_of(ptr, type, field) +#define list_first_entry(ptr, type, field) list_entry((ptr)->next, type, field) +#define list_last_entry(ptr, type, field) list_entry((ptr)->prev, type, field) + +#define list_for_each(p, head) \ + for (p = (head)->next; p != (head); p = p->next) + +#define list_for_each_safe(p, n, head) \ + for (p = (head)->next, n = p->next; p != (head); p = n, n = p->next) + +#define list_for_each_entry(p, h, field) \ + for (p = list_first_entry(h, typeof(*p), field); &p->field != (h); \ + p = list_entry(p->field.next, typeof(*p), field)) + +#define list_for_each_entry_safe(p, n, h, field) \ + for (p = list_first_entry(h, typeof(*p), field), \ + n = list_entry(p->field.next, typeof(*p), field); &p->field != (h);\ + p = n, n = list_entry(n->field.next, typeof(*n), field)) + +#define list_for_each_entry_reverse(p, h, field) \ + for (p = list_last_entry(h, typeof(*p), field); &p->field != (h); \ + p = list_entry(p->field.prev, typeof(*p), field)) + +#define list_for_each_prev(p, h) for (p = (h)->prev; p != (h); p = p->prev) +#define list_for_each_prev_safe(p, n, h) for (p = (h)->prev, n = p->prev; p != (h); p = n, n = p->prev) + +static inline void +list_add(struct list_head *_new, struct list_head *head) +{ + _list_add(_new, head, head->next); +} + +static inline void +list_add_tail(struct list_head *_new, struct list_head *head) +{ + _list_add(_new, head->prev, head); +} + +static inline void +list_move(struct list_head *list, struct list_head *head) +{ + _list_del(list); + list_add(list, head); +} + +static inline void +list_move_tail(struct list_head *entry, struct list_head *head) +{ + _list_del(entry); + list_add_tail(entry, head); +} + +static inline void +_list_splice(const struct list_head *list, struct list_head *prev, + struct list_head *next) +{ + struct list_head *first; + struct list_head *last; + + if (list_empty(list)) + return; + + first = list->next; + last = list->prev; + first->prev = prev; + prev->next = first; + last->next = next; + next->prev = last; +} + +static inline void +list_splice(const struct list_head *list, struct list_head *head) +{ + _list_splice(list, head, head->next); +} + +static inline void +list_splice_tail(struct list_head *list, struct list_head *head) +{ + _list_splice(list, head->prev, head); +} + +static inline void +list_splice_init(struct list_head *list, struct list_head *head) +{ + _list_splice(list, head, head->next); + INIT_LIST_HEAD(list); +} + +static inline void +list_splice_tail_init(struct list_head *list, struct list_head *head) +{ + _list_splice(list, head->prev, head); + INIT_LIST_HEAD(list); +} + +#endif /* _LINUX_LIST_H_ */ diff --git a/make.inc b/make.inc new file mode 100644 index 0000000000000000000000000000000000000000..f3fe3b7c342c55c8f838fbacc67f8d900f4a8fb1 --- /dev/null +++ b/make.inc @@ -0,0 +1,97 @@ +# ******************************************************************************** # +# Copyright (C) 2017 Intel Corporation # +# For licensing information, see the file 'LICENSE' in the root folder of # +# this software module. # +# ******************************************************************************* # + +# +# Makefile addon to compile C Binaries and Libraries +# +# Copyright (c) Intel Corporation 2017 alexander.abraham@intel.com +# +# Use this in your Makefile by adding 'include make.inc' in the end of file. +# Syntax:- +# Assign your binaries and libraries to 'bins :=' macro. +# Example:- bins := bin1 bin2 .. binN libXX1.so libXX2.so .. libXXN.so' +# Order above based on dependency. Example if binary 'abc' have a dependency +# on 'libXYZ.so', then order like:- bins := libXYZ.so abc +# +# Also supports options to pass additional sources (objs), cflags and ldflags +# for the binary/library. Example:- +# 'binN_sources := a.c b.c c.c d.c' 'binN_cflags := -I./abc/ -O2 -g' +# 'binN_ldflags := -ldl -lncurses' +# 'libXXN.so_sources := x.c y.c z.c' 'libXXN.so_cflags := -DDEBUG -I./include/' +# 'libXXN.so_ldflags := -L./xyz/ -ldl' +# +# make.inc additionally adds strict Werror flags via 'opt_flags'. You can either +# override them by redefining opt_flags:= variable or remove unneeded flags by +# passing them to opt_no_flags:= in your Makefile. +# + +ifeq ($(CC),cc) +CC := gcc +endif +STRIP ?= strip +AR ?= ar +RANLIB ?= ranlib +req_flags := -Wall -Werror -Wextra -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Winit-self -Wno-missing-braces +opt_flags ?= $(filter-out $(opt_no_flags),$(req_flags)) + +all: $(bins) + +# Generate Object files (.o) +define build_objs +DEPS += $(patsubst %.c,%_$(notdir $(1)).d,$(2)) +$(patsubst %.c,%_$(notdir $(1)).o,$(2)): $(2) $($(notdir $(1))_hdrs) + $(CC) $(filter-out $(3) $(opt_flags),$(CFLAGS) $($(notdir $(1))_cflags)) $(3) $(opt_flags) -MT $$@ -MD -MP -MF $$(patsubst %.o,%.d,$$@) -c -o $$@ $$< +endef + +# Generate final Binaries +define build_bins +$(foreach oname,$(if $($(notdir $(1))_sources),$($(notdir $(1))_sources),$(1).c),$(eval $(call build_objs,$(1),$(oname),-fPIE))) +$(1): $(if $($(notdir $(1))_sources),$(patsubst %.c,%_$(notdir $(1)).o,$($(notdir $(1))_sources)),$(1)_$(notdir $(1)).o) + $(CC) -pie -o $$@ $$^ $(LDFLAGS) $($(notdir $(1))_ldflags) $(if $(opt_strip),$(if $(STRIP),&& $(STRIP) $$@)) +endef + +# Generate final Libraries +define build_libs +$(foreach oname,$(if $($(notdir $(1))_sources),$($(notdir $(1))_sources),$(dir $(1))$(patsubst lib%.so,%.c,$(notdir $(1)))),$(eval $(call build_objs,$(1),$(oname),-fPIC))) +$(1): $(if $($(notdir $(1))_sources),$(patsubst %.c,%_$(notdir $(1)).o,$($(notdir $(1))_sources)),$(dir $(1))$(patsubst lib%.so,%_$(notdir $(1)).o,$(notdir $(1)))) + $(CC) -shared -fPIC -Wl,-soname,$(notdir $(1)) -o $$@ $$^ $(LDFLAGS) $($(notdir $(1))_ldflags) $(if $(opt_strip),$(if $(STRIP),&& $(STRIP) $$@)) +endef + +# Generate final Lib Archives +define build_lib_ars +$(foreach oname,$(if $($(notdir $(1))_sources),$($(notdir $(1))_sources),$(dir $(1))$(patsubst lib%.a,%.c,$(notdir $(1)))),$(eval $(call build_objs,$(1),$(oname),-fPIC))) +$(1): $(if $($(notdir $(1))_sources),$(patsubst %.c,%_$(notdir $(1)).o,$($(notdir $(1))_sources)),$(dir $(1))$(patsubst lib%.a,%_$(notdir $(1)).o,$(notdir $(1)))) + $(AR) cru $$@ $$^ && $(RANLIB) $$@ +endef + +$(foreach bname,$(bins),$(if $(filter lib%.so,$(notdir $(bname))),$(eval $(call build_libs,$(bname))),$(if $(filter lib%.a,$(notdir $(bname))),$(eval $(call build_lib_ars,$(bname))),$(eval $(call build_bins,$(bname)))))) + +# Clean operation +clean: + $(foreach bname,$(bins),$(if $(filter lib%.so,$(notdir $(bname))),\ + rm -f $(if $($(notdir $(bname))_sources),$(patsubst %.c,%_$(notdir $(bname)).o,$($(notdir $(bname))_sources)),$(dir $(bname))$(patsubst lib%.so,%_$(notdir $(bname)).o,$(notdir $(bname)))) $(patsubst %.c,%_$(notdir $(bname)).d,$(if $($(notdir $(bname))_sources),$($(notdir $(bname))_sources),$(dir $(bname))$(patsubst lib%.so,%_$(notdir $(bname)).d,$(notdir $(bname)))));\ + ,\ + $(if $(filter lib%.a,$(notdir $(bname))),\ + rm -f $(if $($(notdir $(bname))_sources),$(patsubst %.c,%_$(notdir $(bname)).o,$($(notdir $(bname))_sources)),$(dir $(bname))$(patsubst lib%.a,%_$(notdir $(bname)).o,$(notdir $(bname)))) $(patsubst %.c,%_$(notdir $(bname)).d,$(if $($(notdir $(bname))_sources),$($(notdir $(bname))_sources),$(dir $(bname))$(patsubst lib%.a,%_$(notdir $(bname)).d,$(notdir $(bname)))));\ + ,\ + rm -f $(if $($(notdir $(bname))_sources),$(patsubst %.c,%_$(notdir $(bname)).o,$($(notdir $(bname))_sources)),$(bname)_$(notdir $(bname)).o) $(patsubst %.c,%_$(notdir $(bname)).d,$(if $($(notdir $(bname))_sources),$($(notdir $(bname))_sources),$(bname)_$(notdir $(bname)).d));\ + )\ + )) + rm -f $(bins) + +distclean: clean + find . -type f -name "*.[o,a,d]" | xargs rm -f + find . -type f -name "*.so" | xargs rm -f + rm -rf ipkg-*;rm -f *.tar.* + +dist: distclean + @$(if $(PKG_NAME),,echo "Define a proper package name in PKG_NAME macro!!";exit 1) + @$(if $(PKG_VERSION),,$(eval PKG_VERSION=$(shell cat VERSION 2>/dev/null)) $(if $(PKG_VERSION),,echo "Define a proper package version in PKG_VERSION macro or add a VERSION file!!";exit 1)) + @rm -rf "$(PKG_NAME)-$(PKG_VERSION)";rm -f "$(PKG_NAME)-$(PKG_VERSION)".tar*;mkdir -p "$(PKG_NAME)-$(PKG_VERSION)"; + @cp -af `find ./ -maxdepth 1|grep -Ev '$(PKG_NAME)-$(PKG_VERSION)|./$$'` "$(PKG_NAME)-$(PKG_VERSION)/" && tar -cvzf "$(PKG_NAME)-$(PKG_VERSION).tar.gz" "$(PKG_NAME)-$(PKG_VERSION)" + @rm -rf "$(PKG_NAME)-$(PKG_VERSION)"; + +-include $(DEPS)