Skip to content
Snippets Groups Projects
dsl_cpe_configuration_parser.c 58.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    /******************************************************************************
    
             Copyright (c) 2018 - 2019 Intel Corporation
    
      For licensing information, see the file 'LICENSE' in the root folder of
      this software module.
    
    *******************************************************************************/
    
    #if defined(INCLUDE_DSL_JSON_PARSING) && (INCLUDE_DSL_JSON_PARSING == 1)
    
    #include "json.h"
    #include "dsl_cpe_control.h"
    #include "dsl_cpe_configuration_parser.h"
    
    #include "dsl_cpe_interface.h"
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    
    #include "drv_dsl_cpe_api_ioctl.h"
    #if defined(INCLUDE_DSL_CPE_API_VRX)
    /* MEI CPE driver specific header (e.g. IOCtls) */
    #include "drv_mei_cpe_interface.h"
    #endif /* defined(INCLUDE_DSL_CPE_API_VRX) */
    
    #undef DSL_CCA_DBG_BLOCK
    #define DSL_CCA_DBG_BLOCK DSL_CCA_DBG_APP
    
    #define CONFIG_ROOT_NAME "Root"
    #define CONFIG_SECTION_PATH_SEPARATOR "."
    
    /* DSL sections */
    #define CONFIG_DSL_SECTION_PATH \
       CONFIG_ROOT_NAME CONFIG_SECTION_PATH_SEPARATOR "dsl"
    
    #define CONFIG_DEBUGGING_SECTION_PATH \
       CONFIG_DSL_SECTION_PATH CONFIG_SECTION_PATH_SEPARATOR "debugging"
    
    #define CONFIG_STARTUPINIT_SECTION_PATH \
       CONFIG_DSL_SECTION_PATH CONFIG_SECTION_PATH_SEPARATOR "startup_init"
    
    #define CONFIG_BITSWAP_SECTION_PATH \
       CONFIG_DSL_SECTION_PATH CONFIG_SECTION_PATH_SEPARATOR "bitswap"
    
    #define CONFIG_RETRANSMISSION_SECTION_PATH \
       CONFIG_DSL_SECTION_PATH CONFIG_SECTION_PATH_SEPARATOR "retransmission"
    
    #define CONFIG_SRA_SECTION_PATH \
       CONFIG_DSL_SECTION_PATH CONFIG_SECTION_PATH_SEPARATOR "sra"
    
    #define CONFIG_VIRTUALNOISE_SECTION_PATH \
       CONFIG_DSL_SECTION_PATH CONFIG_SECTION_PATH_SEPARATOR "virtual_noise"
    
    #define CONFIG_REBOOTCRITERIA_SECTION_PATH \
       CONFIG_DSL_SECTION_PATH CONFIG_SECTION_PATH_SEPARATOR "reboot_criteria"
    
    #define CONFIG_XTSE_SECTION_PATH \
       CONFIG_DSL_SECTION_PATH CONFIG_SECTION_PATH_SEPARATOR "xtse"
    
    #define CONFIG_TCLAYER_SECTION_PATH \
       CONFIG_DSL_SECTION_PATH CONFIG_SECTION_PATH_SEPARATOR "tc_layer"
    
    #define CONFIG_COMMON_SECTION_PATH \
       CONFIG_DSL_SECTION_PATH CONFIG_SECTION_PATH_SEPARATOR "common"
    
    /* DSL Common subsections */
    #define CONFIG_LOWLEVELHSTONES_SECTION_PATH \
       CONFIG_COMMON_SECTION_PATH CONFIG_SECTION_PATH_SEPARATOR "low_level_hs_tones"
    
    #define CONFIGURATION_VALUE_UNDEFINED 0x7FFFFFFF
    
    #define PARSE_SECTION_INT(Section, ParameterName, ConfigField) \
       do { \
          if (bFound == DSL_FALSE && \
              strstr(pSectionPath, Section CONFIG_SECTION_PATH_SEPARATOR ParameterName) \
             != NULL) \
          { \
             ConfigField = nIntVal; \
             bFound = DSL_TRUE; \
          } \
       } \
       while(0)
    
    #define PARSE_SECTION_STRING(Section, ParameterName, ConfigField) \
       do { \
          if (bFound == DSL_FALSE && \
              strstr(pSectionPath, Section CONFIG_SECTION_PATH_SEPARATOR ParameterName) \
             != NULL) \
          { \
             cpe_control_strncpy_s( \
                ConfigField, sizeof(ConfigField), nStringVal, sizeof(nStringVal)); \
             bFound = DSL_TRUE; \
          } \
       } \
       while(0)
    
    #define PARSE_SECTION_HEX(Section, ParameterName, ConfigField) \
       do { \
          if (bFound == DSL_FALSE && \
              strstr(pSectionPath, Section CONFIG_SECTION_PATH_SEPARATOR ParameterName) \
             != NULL) \
          { \
             ConfigField = (DSL_uint32_t)(strtol(nStringVal, NULL, 16)); \
             bFound = DSL_TRUE; \
          } \
       } \
       while(0)
    
    /* Macro used to check if configuration parameter is in valid range */
    #define CONFIG_PARAM_RANGE_VALIDATION(Param, nMinVal, nMaxVal) \
       do { \
          int val = Param; \
          if (val == CONFIGURATION_VALUE_UNDEFINED) \
          { \
                break; \
          } \
          if ((val > nMaxVal) || (val < nMinVal)) \
          { \
             DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, \
                (DSL_CPE_PREFIX"ERROR - Configuration param %s " \
                "validation failed! (min = %d, max = %d, current = %d)!" \
                DSL_CPE_CRLF, #Param, nMinVal, nMaxVal, val)); \
             return DSL_ERROR; \
          } \
       } \
       while(0)
    
    /* Macro used to check if parameter in DSL_CPE_Configuration_t (configParam)
    is undefined, if so use currentParam (from DSL_xxxGet function or any other source) */
    #define CONFIG_PARAM_APPLY(currentParam, configParam) \
       do { \
          currentParam = (configParam == CONFIGURATION_VALUE_UNDEFINED) ? currentParam : configParam; \
       } \
       while(0)
    
    #define SECTION_PATH_LENGTH 256
    
    /* Configuration file path */
    
    static const char *g_pJsonConfigPath = "/tmp/dsl/dsl.conf";
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    static DSL_Configuration_t g_sConfiguration = { 0 };
    
    /**********************************************/
    /* start local function declarations          */
    /**********************************************/
    
    static DSL_Error_t DSL_CPE_JsonParseConfigFile(
       const DSL_char_t * pPath,
       DSL_Configuration_t *pData
    );
    
    static DSL_void_t DSL_CPE_JsonReadObj(
       json_object * pObj,
       DSL_char_t * pSectionPath,
       DSL_Configuration_t *pData
    );
    
    static DSL_void_t DSL_CPE_JsonParse(
       json_object * pObj,
       DSL_char_t * pSectionPath,
       DSL_Configuration_t *pData
    );
    
    static DSL_void_t DSL_CPE_JsonParseArray(
       json_object * pObj,
       DSL_char_t * pKey,
       DSL_char_t * pSectionPath,
       DSL_Configuration_t *pData
    );
    
    static DSL_Error_t DSL_CPE_ConfigRead();
    
    static DSL_Error_t DSL_CPE_ConfigValidateAndApply(
       DSL_CPE_Control_Context_t *pCtrlCtx
    );
    
    static DSL_Error_t DSL_CPE_LowLevelCfgValidateAndApply(
       DSL_CPE_Control_Context_t *pControlContext,
       const DSL_uint32_t nDevNum
    );
    
    static DSL_Error_t DSL_CPE_LineFeatureCfgValidateAndApply(
       DSL_CPE_Control_Context_t *pControlContext,
       const DSL_uint32_t nDevNum
    );
    
    static DSL_Error_t DSL_CPE_RebootCriteriaCfgValidateAndApply(
       DSL_CPE_Control_Context_t *pControlContext,
       const DSL_uint32_t nDevNum
    );
    
    static DSL_Error_t DSL_CPE_VdslProfileCfgValidateAndApply(
       DSL_CPE_Control_Context_t *pControlContext,
       const DSL_uint32_t nDevNum
    );
    
    static DSL_Error_t DSL_CPE_G997_RateAdaptationCfgValidateAndApply(
       DSL_CPE_Control_Context_t *pControlContext,
       const DSL_uint32_t nDevNum
    );
    
    static DSL_Error_t DSL_CPE_SysIfCfgValidateAndApply(
       DSL_CPE_Control_Context_t *pControlContext,
       const DSL_uint32_t nDevNum
    );
    
    static DSL_Error_t DSL_CPE_XtseCfgValidateAndApply(
       DSL_CPE_Control_Context_t *pControlContext,
       const DSL_uint32_t nDevNum
    );
    
    static DSL_Error_t DSL_CPE_VectoringEnableCfgApply(
       const DSL_uint32_t nDevNum
    );
    
    static DSL_Error_t DSL_CPE_FwMessagePollingCfgValidateAndApply(
       DSL_CPE_Control_Context_t *pControlContext,
       const DSL_uint32_t nDevNum
    );
    
    static DSL_Error_t DSL_CPE_OperatorSelectCfgValidateAndApply(
       DSL_CPE_Control_Context_t *pControlContext,
       const DSL_uint32_t nDevNum
    );
    
    /**********************************************/
    /* start interface function definitions       */
    /**********************************************/
    
    /*
       For a detailed description of the function, its arguments and return value
       please refer to the description in the header file 'dsl_cpe_configuration_parser.h'
    */
    DSL_Error_t DSL_CPE_ConfigInit()
    {
       static DSL_boolean_t bInitDone = DSL_FALSE;
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    
       if (bInitDone == DSL_FALSE)
       {
          if (DSL_CPE_ConfigRead() == DSL_ERROR)
          {
             /* keep default configuration just awhile
                to reduce memory consumption */
             DSL_ConfigurationData_t sDefaultConfigData =
             {
                /* DSL_CFG_Debugging_t */
                { 1 },
    
                /* DSL_CFG_StartupInit_t */
                { 0, 1, 1, 1 },
    
                /* DSL_CFG_Bitswap_t */
                { 1, 1, 1, 1 },
    
                /* DSL_CFG_Retransmission_t */
                { 0, 0, 1, 1 },
    
                /* DSL_CFG_Sra_t */
                { 0, 0, 1, 1 },
    
                /* DSL_CFG_VirtualNoise_t */
                { 1, 1 },
    
                /* DSL_CFG_RebootCriteria_t */
                { 0x4F, 0xF },
    
                /* DSL_CFG_SystemInterface_t */
                { 0, 0 },
    
                /* DSL_CFG_Common_t */
                {
                   /* OperatorSelect */
                   0,
    
                   /* LdAfeShutdown */
                   1,
    
                   /* VectoringEnable */
                   0,
    
                   /* VdslProfileVal */
                   0x1FF,
    
                   /* ActSeq */
                   1,
    
                   /* ActMode */
                   1,
    
                   /* Remember */
                   0,
    
                   /* FWMsgPollingOnly */
                   0,
    
                   /* DSL_CFG_LowLevelHsTones_t */
                   { 0, 0 }
                },
    
                /* xtse */
                { 0x4, 0x0, 0x4, 0x0, 0xC, 0x1, 0x0, 0x7 }
             };
             DSL_Configuration_t sDefaultConfig = { 0 };
    
             cpe_control_memcpy_s(
                &(sDefaultConfig.data), sizeof(DSL_ConfigurationData_t),
                &sDefaultConfigData, sizeof(DSL_ConfigurationData_t));
    
             cpe_control_memcpy_s(
                &g_sConfiguration, sizeof(DSL_Configuration_t),
                &sDefaultConfig, sizeof(DSL_Configuration_t));
    
             DSL_CCA_DEBUG(DSL_CCA_DBG_WRN, (DSL_CPE_PREFIX
                "WARNING - Configuration initialized with default values!" DSL_CPE_CRLF));
    
    
             nRet = DSL_WRN_CONFIG_PARAM_IGNORED;
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
          bInitDone = DSL_TRUE;
    
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    }
    
    /*
       For a detailed description of the function, its arguments and return value
       please refer to the description in the header file 'dsl_cpe_configuration_parser.h'
    */
    DSL_Error_t DSL_CPE_ConfigGet(const DSL_Configuration_t **pConfiguration)
    {
       *pConfiguration = &g_sConfiguration;
    
       return DSL_SUCCESS;
    }
    
    /*
       For a detailed description of the function, its arguments and return value
       please refer to the description in the header file 'dsl_cpe_configuration_parser.h'
    */
    DSL_Error_t DSL_CPE_ConfigUpdate(
       DSL_CPE_Control_Context_t *pCtrlCtx)
    {
       DSL_Error_t nRet = DSL_SUCCESS;
       static DSL_boolean_t bReconfig = DSL_FALSE;
    
       /* on init, ConfigRead is already called in ConfigInit function -
          no need to call it again */
       if (bReconfig == DSL_TRUE)
       {
          nRet = DSL_CPE_ConfigRead();
       }
    
       /* do not proceed when ConfigRead failed with undefined values */
       if (nRet == DSL_SUCCESS)
       {
          nRet = DSL_CPE_ConfigValidateAndApply(pCtrlCtx);
       }
    
       bReconfig = DSL_TRUE;
    
       return nRet;
    }
    
    /*********************************************/
    /* start local function definitions          */
    /*********************************************/
    
    static DSL_Error_t DSL_CPE_JsonParseConfigFile(
       const DSL_char_t * pPath,
       DSL_Configuration_t *pData)
    {
       DSL_CPE_File_t *pFile = DSL_NULL;
       DSL_int_t nFileLength = 0;
       DSL_char_t * pBuffer = DSL_NULL;
       DSL_char_t currentSectionPath[SECTION_PATH_LENGTH] = { CONFIG_ROOT_NAME };
    
       json_object * pRootObj = DSL_NULL;
    
       pFile = DSL_CPE_FOpen(pPath, "r");
       if (pFile == DSL_NULL)
       {
          return DSL_ERROR;
       }
    
       /* Get length of file as JSON has strict format
       and we have to read whole file at once */
       fseek(pFile, 0, SEEK_END);
       nFileLength = ftell(pFile);
       fseek(pFile, 0, SEEK_SET);
    
       /* Alloc buffer for JSON file content */
       pBuffer = (DSL_char_t *)DSL_CPE_Malloc(nFileLength * sizeof(DSL_char_t));
       if (pBuffer == DSL_NULL)
       {
          DSL_CPE_FClose(pFile);
          return DSL_ERROR;
       }
    
       /* Read file */
       DSL_CPE_FRead(pBuffer, sizeof(DSL_char_t), nFileLength, pFile);
       DSL_CPE_FClose(pFile);
    
       /* Create JSON Object from string */
       pRootObj = json_tokener_parse(pBuffer);
       DSL_CPE_Free(pBuffer);
    
       if (pRootObj == DSL_NULL)
       {
          DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
             "Configuration Parser: invalid JSON file syntax" DSL_CPE_CRLF));
          return DSL_ERROR;
       }
    
       /* Start parsing */
       DSL_CPE_JsonReadObj(pRootObj, currentSectionPath, pData);
    
       return DSL_SUCCESS;
    }
    
    static DSL_void_t DSL_CPE_JsonReadObj(
       json_object * pObj,
       DSL_char_t *pSectionPath,
       DSL_Configuration_t *pData)
    {
       enum json_type nType = json_type_null;
       DSL_char_t currentSectionPath[SECTION_PATH_LENGTH];
       json_object *pTmpObj = DSL_NULL;
    
       json_object_object_foreach(pObj, key, val)
       {
          pTmpObj = pObj;
          DSL_CPE_snprintf(currentSectionPath,
             sizeof(currentSectionPath), "%s.%s", pSectionPath, key);
    
          nType = json_object_get_type(val);
    
          switch (nType)
          {
          case json_type_array:
             DSL_CPE_JsonParseArray(pTmpObj, key, currentSectionPath, pData);
             break;
          case json_type_object:
             json_object_object_get_ex(pTmpObj, key, &pTmpObj);
    
             if (pTmpObj != DSL_NULL)
             {
                DSL_CPE_JsonReadObj(pTmpObj, currentSectionPath, pData);
             }
             break;
          case json_type_null:
          case json_type_boolean:
          case json_type_double:
          case json_type_int:
          case json_type_string:
             DSL_CPE_JsonParse(val, currentSectionPath, pData);
             break;
          }
       }
    }
    
    static DSL_void_t DSL_CPE_JsonParse(
       json_object * pObj,
       DSL_char_t * pSectionPath,
       DSL_Configuration_t *pData)
    {
       enum json_type nType = json_type_null;
       DSL_int_t nIntVal = 0;
       DSL_char_t nStringVal[64] = { 0 };
       DSL_boolean_t bFound = DSL_FALSE;
    
       DSL_CFG_Debugging_t *pDebuggingConfig = &pData->data.sDebuggingConfig;
       DSL_CFG_StartupInit_t *pStartupInitConfig = &pData->data.sStartupInitConfig;
       DSL_CFG_Bitswap_t *pBitswapConfig = &pData->data.sBitswapConfig;
       DSL_CFG_Common_t *pCommonConfig = &pData->data.sCommonConfig;
       DSL_CFG_Retransmission_t *pRetransmissionConfig =
          &pData->data.sRetransmissionConfig;
       DSL_CFG_Sra_t *pSraConfig = &pData->data.sSraConfig;
       DSL_CFG_VirtualNoise_t *pVirtualNoiseConfig =
          &pData->data.sVirtualNoiseConfig;
       DSL_CFG_RebootCriteria_t *pRebootCriteriaConfig =
          &pData->data.sRebootCriteriaConfig;
       DSL_CFG_SystemInterface_t *pSystemIfConfig =
          &pData->data.sSystemIfConfig;
    
       /* We are only interested in Root.DSL section */
       if (strstr(pSectionPath, CONFIG_DSL_SECTION_PATH) == DSL_NULL)
       {
          return;
       }
    
       nType = json_object_get_type(pObj);
    
       switch (nType)
       {
          case json_type_boolean:
          case json_type_int:
             nIntVal = (DSL_int_t)json_object_get_int(pObj);
    
             DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
                "Configuration Parser: %s: %d" DSL_CPE_CRLF,
                pSectionPath, nIntVal));
    
             /* Debugging */
             PARSE_SECTION_INT(
    
                CONFIG_DEBUGGING_SECTION_PATH, DSL_CFG_DEBUG_AND_TEST_INTERFACES, pDebuggingConfig->nDebugAndTestInterfaces);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    
             /* StartupInit */
             PARSE_SECTION_INT(
    
                CONFIG_STARTUPINIT_SECTION_PATH, DSL_CFG_NEXT_MODE, pStartupInitConfig->nNextMode);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_STARTUPINIT_SECTION_PATH, DSL_CFG_MAX_DEVICE_NUMBER, pStartupInitConfig->nMaxDeviceNumber);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_STARTUPINIT_SECTION_PATH, DSL_CFG_LINES_PER_DEVICE, pStartupInitConfig->nLinesPerDevice);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_STARTUPINIT_SECTION_PATH, DSL_CFG_CHANNELS_PER_LINE, pStartupInitConfig->nChannelsPerLine);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    
             /* Bitswap */
             PARSE_SECTION_INT(
    
                CONFIG_BITSWAP_SECTION_PATH, DSL_CFG_BITSWAP_VDSL_US, pBitswapConfig->Us_Vdsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_BITSWAP_SECTION_PATH, DSL_CFG_BITSWAP_VDSL_DS, pBitswapConfig->Ds_Vdsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_BITSWAP_SECTION_PATH, DSL_CFG_BITSWAP_ADSL_US, pBitswapConfig->Us_Adsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_BITSWAP_SECTION_PATH, DSL_CFG_BITSWAP_ADSL_DS, pBitswapConfig->Ds_Adsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    
             /* Retransmission */
             PARSE_SECTION_INT(
    
                CONFIG_RETRANSMISSION_SECTION_PATH, DSL_CFG_RETX_VDSL_US, pRetransmissionConfig->Us_Vdsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_RETRANSMISSION_SECTION_PATH, DSL_CFG_RETX_VDSL_DS, pRetransmissionConfig->Ds_Vdsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_RETRANSMISSION_SECTION_PATH, DSL_CFG_RETX_ADSL_US, pRetransmissionConfig->Us_Adsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_RETRANSMISSION_SECTION_PATH, DSL_CFG_RETX_ADSL_DS, pRetransmissionConfig->Ds_Adsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    
             /* SRA */
             PARSE_SECTION_INT(
    
                CONFIG_SRA_SECTION_PATH, DSL_CFG_SRA_VDSL_US, pSraConfig->Us_Vdsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_SRA_SECTION_PATH, DSL_CFG_SRA_VDSL_DS, pSraConfig->Ds_Vdsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_SRA_SECTION_PATH, DSL_CFG_SRA_ADSL_US, pSraConfig->Us_Adsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_SRA_SECTION_PATH, DSL_CFG_SRA_ADSL_DS, pSraConfig->Ds_Adsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    
             /* Virtualnoise */
             PARSE_SECTION_INT(
    
                CONFIG_VIRTUALNOISE_SECTION_PATH, DSL_CFG_VN_US, pVirtualNoiseConfig->Us);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_VIRTUALNOISE_SECTION_PATH, DSL_CFG_VN_DS, pVirtualNoiseConfig->Ds);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    
             /* TcLayer */
             PARSE_SECTION_INT(
    
                CONFIG_TCLAYER_SECTION_PATH, DSL_CFG_TC_ADSL, pSystemIfConfig->nTcLayer_Adsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_TCLAYER_SECTION_PATH, DSL_CFG_TC_VDSL, pSystemIfConfig->nTcLayer_Vdsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    
             /* Common */
             PARSE_SECTION_INT(
    
                CONFIG_COMMON_SECTION_PATH, DSL_CFG_OPERATOR_SELECT, pCommonConfig->nOperatorSelect);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_COMMON_SECTION_PATH, DSL_CFG_LD_AFE_SHUTDOWN, pCommonConfig->LdAfeShutdown);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_COMMON_SECTION_PATH, DSL_CFG_VECTORING_ENABLE, pCommonConfig->VectoringEnable);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_COMMON_SECTION_PATH, DSL_CFG_ACTIVATION_SEQUENCE, pCommonConfig->ActSeq);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_COMMON_SECTION_PATH, DSL_CFG_ACTIVATION_MODE, pCommonConfig->ActMode);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_COMMON_SECTION_PATH, DSL_CFG_REMEMBER, pCommonConfig->Remember);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_INT(
    
                CONFIG_COMMON_SECTION_PATH, DSL_CFG_FW_MSG_POLLING_ONLY, pCommonConfig->FWMsgPollingOnly);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    
             if (bFound == DSL_FALSE)
             {
                DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
                   "Configuration Parser: Unknown parameter %s" DSL_CPE_CRLF,
                   pSectionPath));
             }
             break;
          case json_type_string:
             DSL_CPE_snprintf(nStringVal, sizeof(nStringVal), "%s",
                json_object_get_string(pObj));
             DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
                "Configuration Parser: %s: %s" DSL_CPE_CRLF, pSectionPath, nStringVal));
    
             /* Reboot criteria */
             PARSE_SECTION_HEX(
    
                CONFIG_REBOOTCRITERIA_SECTION_PATH, DSL_CFG_REBOOT_ADSL, pRebootCriteriaConfig->Adsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_HEX(
    
                CONFIG_REBOOTCRITERIA_SECTION_PATH, DSL_CFG_REBOOT_VDSL, pRebootCriteriaConfig->Vdsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    
             /* Common */
             PARSE_SECTION_HEX(
    
                CONFIG_COMMON_SECTION_PATH, DSL_CFG_VDSL_PROFILE, pCommonConfig->VdslProfileVal);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_HEX(
    
                CONFIG_LOWLEVELHSTONES_SECTION_PATH, DSL_CFG_LOW_LEVEL_HS_TONES_ADSL, pCommonConfig->sLowLevelHsTonesConfig.Adsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             PARSE_SECTION_HEX(
    
                CONFIG_LOWLEVELHSTONES_SECTION_PATH, DSL_CFG_LOW_LEVEL_HS_TONES_VDSL, pCommonConfig->sLowLevelHsTonesConfig.Vdsl);
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
    604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
    
             if (bFound == DSL_FALSE)
             {
                DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
                   "Configuration Parser: Unknown parameter %s" DSL_CPE_CRLF,
                   pSectionPath));
             }
             break;
          default:
             break;
       }
    }
    
    static DSL_void_t DSL_CPE_JsonParseArray(
       json_object * pObj,
       DSL_char_t * pKey,
       DSL_char_t * pSectionPath,
       DSL_Configuration_t *pData)
    {
       enum json_type nType = json_type_null;
       json_object * pArrayObj = pObj;
       json_object * pValue = DSL_NULL;
       DSL_char_t currentSectionPath[SECTION_PATH_LENGTH];
       DSL_int_t nArrayLength = 0;
       DSL_char_t nStringVal[64] = { 0 };
       unsigned char *pG997XtuVal = pData->data.G997XtuVal;
       DSL_boolean_t bFound = DSL_FALSE;
    
       if (pKey != DSL_NULL)
       {
          json_object_object_get_ex(pObj, pKey, &pArrayObj);
       }
    
       nArrayLength = json_object_array_length(pArrayObj);
    
       for (DSL_int_t i = 0; i < nArrayLength; i++)
       {
          DSL_CPE_snprintf(currentSectionPath,
             sizeof(currentSectionPath), "%s[%d]", pSectionPath, i);
    
          pValue = json_object_array_get_idx(pArrayObj, i);
          nType = json_object_get_type(pValue);
    
          bFound = DSL_FALSE;
    
          switch (nType)
          {
          case json_type_array:
             DSL_CPE_JsonParseArray(pValue, DSL_NULL, currentSectionPath, pData);
             break;
          case json_type_object:
             DSL_CPE_JsonReadObj(pValue, currentSectionPath, pData);
             break;
          case json_type_string:
             DSL_CPE_snprintf(nStringVal, sizeof(nStringVal), "%s",
                json_object_get_string(pValue));
    
             /* XTSE */
             if (strstr(pSectionPath, CONFIG_XTSE_SECTION_PATH) != DSL_NULL)
             {
                if (i >= DSL_G997_NUM_XTSE_OCTETS)
                {
                   DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
                      "Configuration Array Parser: XTSE, index out of range (%d)"
                      DSL_CPE_CRLF, i));
                   break;
                }
                PARSE_SECTION_HEX(CONFIG_DSL_SECTION_PATH, "xtse",
                   pG997XtuVal[i]);
             }
             break;
          case json_type_null:
          case json_type_boolean:
          case json_type_double:
          case json_type_int:
          default:
             break;
          }
       }
    }
    
    /**
       Read configuration from the config file
    */
    static DSL_Error_t DSL_CPE_ConfigRead()
    {
       DSL_ConfigurationData_t sUndefinedConfigData =
       {
          /* DSL_CFG_Debugging_t */
          {
             CONFIGURATION_VALUE_UNDEFINED
          },
    
          /* DSL_CFG_StartupInit_t */
          {
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED
          },
    
          /* DSL_CFG_Bitswap_t */
          {
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED
          },
    
          /* DSL_CFG_Retransmission_t */
          {
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED
          },
    
          /* DSL_CFG_Sra_t */
          {
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED
          },
    
          /* DSL_CFG_VirtualNoise_t */
          {
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED
          },
    
          /* DSL_CFG_RebootCriteria_t */
          {
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED
          },
    
          /* DSL_CFG_SystemInterface_t */
          {
             CONFIGURATION_VALUE_UNDEFINED,
             CONFIGURATION_VALUE_UNDEFINED
          },
    
          /* DSL_CFG_Common_t */
          {
             /* operator_select */
             CONFIGURATION_VALUE_UNDEFINED,
    
             /* ld_afe_shutdown */
             CONFIGURATION_VALUE_UNDEFINED,
    
             /* vectoring_enable */
             CONFIGURATION_VALUE_UNDEFINED,
    
             /* vdsl_profile */
             CONFIGURATION_VALUE_UNDEFINED,
    
             /* activation_sequence */
             CONFIGURATION_VALUE_UNDEFINED,
    
             /* activation_mode */
             CONFIGURATION_VALUE_UNDEFINED,
    
             /* remember */
             CONFIGURATION_VALUE_UNDEFINED,
    
             /* fw_msg_polling_only */
             CONFIGURATION_VALUE_UNDEFINED,
    
             /* low_level_hs_tones */
             {
                CONFIGURATION_VALUE_UNDEFINED,
                CONFIGURATION_VALUE_UNDEFINED
             }
          },
    
          /* xtse */
          ""
       };
    
       cpe_control_memcpy_s(
          &(g_sConfiguration.data), sizeof(DSL_ConfigurationData_t),
          &sUndefinedConfigData, sizeof(DSL_ConfigurationData_t));
    
       if (DSL_CPE_JsonParseConfigFile(g_pJsonConfigPath, &g_sConfiguration) == DSL_ERROR)
       {
          DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
             "ERROR - Parsing configuration file failed!" DSL_CPE_CRLF));
    
          return DSL_ERROR;
       }
    
       return DSL_SUCCESS;
    }
    
    /**
       Execute config update
    */
    static DSL_Error_t DSL_CPE_ConfigValidateAndApply(
       DSL_CPE_Control_Context_t *pCtrlCtx)
    {
       DSL_Error_t nRet = DSL_SUCCESS, nErrCode = DSL_SUCCESS;
    
       DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
          "IN - DSL_CPE_ConfigValidateAndApply" DSL_CPE_CRLF));
    
       if (pCtrlCtx == DSL_NULL)
       {
          DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
             "ERROR - Invalid context pointer!" DSL_CPE_CRLF));
          return DSL_ERROR;
       }
    
       for (int nDevice = 0; nDevice < DSL_CPE_DSL_ENTITIES; ++nDevice)
       {
          nRet = DSL_CPE_LowLevelCfgValidateAndApply(pCtrlCtx, nDevice);
          if (nRet != DSL_SUCCESS)
          {
             nErrCode = nRet;
          }
    
          nRet = DSL_CPE_LineFeatureCfgValidateAndApply(pCtrlCtx, nDevice);
          if (nRet != DSL_SUCCESS)
          {
             nErrCode = nRet;
          }
    
          nRet = DSL_CPE_RebootCriteriaCfgValidateAndApply(pCtrlCtx, nDevice);
          if (nRet != DSL_SUCCESS)
          {
             nErrCode = nRet;
          }
    
          nRet = DSL_CPE_VdslProfileCfgValidateAndApply(pCtrlCtx, nDevice);
          if (nRet != DSL_SUCCESS)
          {
             nErrCode = nRet;
          }
    
          nRet = DSL_CPE_G997_RateAdaptationCfgValidateAndApply(pCtrlCtx, nDevice);
          if (nRet != DSL_SUCCESS)
          {
             nErrCode = nRet;
          }
    
          nRet = DSL_CPE_SysIfCfgValidateAndApply(pCtrlCtx, nDevice);
          if (nRet != DSL_SUCCESS)
          {
             nErrCode = nRet;
          }
    
          nRet = DSL_CPE_XtseCfgValidateAndApply(pCtrlCtx, nDevice);
          if (nRet != DSL_SUCCESS)
          {
             nErrCode = nRet;
          }
    
    #if defined(INCLUDE_DSL_CPE_API_VRX)
          nRet = DSL_CPE_VectoringEnableCfgApply(nDevice);
          if (nRet != DSL_SUCCESS)
          {
             nErrCode = nRet;
          }
    #endif
    
          nRet = DSL_CPE_FwMessagePollingCfgValidateAndApply(pCtrlCtx, nDevice);
          if (nRet != DSL_SUCCESS)
          {
             nErrCode = nRet;
          }
    
          nRet = DSL_CPE_OperatorSelectCfgValidateAndApply(pCtrlCtx, nDevice);
          if (nRet != DSL_SUCCESS)
          {
             nErrCode = nRet;
          }
       }
    
       DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
          "OUT - DSL_CPE_ConfigValidateAndApply, retCode=%d" DSL_CPE_CRLF,
          nErrCode));
    
       return nErrCode;
    }
    
    /*
       This function validates and applies device LowLevel configuration
       taken from the config file
    
       \param pControlContext     Pointer to DSL CPE Control context structure, [I]
       \param nDevNum             Number of device for configuration, [I]
    
       \return  Return values are defined within the \ref DSL_Error_t definition
       - DSL_SUCCESS in case of success
       - DSL_ERROR if operation failed
    */
    static DSL_Error_t DSL_CPE_LowLevelCfgValidateAndApply(
       DSL_CPE_Control_Context_t *pControlContext,
       const DSL_uint32_t nDevNum)
    {
       DSL_Error_t nErrCode = DSL_SUCCESS;
       DSL_LowLevelConfiguration_t sLowLevelCfg = { 0 };
       DSL_CFG_LowLevelHsTones_t sCFGLowLevelHsTones;
    
       DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
          "IN - DSL_CPE_LowLevelCfgValidateAndApply, device<%u>" DSL_CPE_CRLF,
          nDevNum));
    
       sCFGLowLevelHsTones = g_sConfiguration.data.sCommonConfig.sLowLevelHsTonesConfig;
    
       CONFIG_PARAM_RANGE_VALIDATION(
          sCFGLowLevelHsTones.Adsl,
          DSL_DEV_HS_TONE_GROUP_CLEANED,
          DSL_DEV_HS_TONE_GROUP_ADSL2_A43C);
       CONFIG_PARAM_RANGE_VALIDATION(
          sCFGLowLevelHsTones.Vdsl,
          DSL_DEV_HS_TONE_GROUP_CLEANED,
          DSL_DEV_HS_TONE_GROUP_ADSL2_A43C);
    
       if (sCFGLowLevelHsTones.Adsl == DSL_DEV_HS_TONE_GROUP_CLEANED &&
           sCFGLowLevelHsTones.Vdsl == DSL_DEV_HS_TONE_GROUP_CLEANED)
       {
          DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
             "API default handshake tones will be used." DSL_CPE_CRLF));
    
          return nErrCode;
       }
    
       nErrCode = DSL_CPE_Ioctl(
                      pControlContext->fd[nDevNum],
                      DSL_FIO_LOW_LEVEL_CONFIGURATION_GET,
                      (int) &sLowLevelCfg);
    
       if (nErrCode == DSL_SUCCESS)
       {
          if (sCFGLowLevelHsTones.Adsl > DSL_DEV_HS_TONE_GROUP_CLEANED ||
             sCFGLowLevelHsTones.Vdsl > DSL_DEV_HS_TONE_GROUP_CLEANED)
          {
             CONFIG_PARAM_APPLY(
                sLowLevelCfg.data.nHsToneGroupMode,
                DSL_DEV_HS_TONE_GROUP_MODE_MANUAL);
             CONFIG_PARAM_APPLY(
                sLowLevelCfg.data.nHsToneGroup_AV,
                DSL_DEV_HS_TONE_GROUP_CLEANED);
          }
          else
          {
             CONFIG_PARAM_APPLY(
                sLowLevelCfg.data.nHsToneGroupMode,
                DSL_DEV_HS_TONE_GROUP_MODE_AUTO);
          }
    
          if (sCFGLowLevelHsTones.Adsl > DSL_DEV_HS_TONE_GROUP_CLEANED)
          {
             CONFIG_PARAM_APPLY(
                sLowLevelCfg.data.nHsToneGroup_A,
                sCFGLowLevelHsTones.Adsl);
          }
          if (sCFGLowLevelHsTones.Vdsl > DSL_DEV_HS_TONE_GROUP_CLEANED)
          {
             CONFIG_PARAM_APPLY(
                sLowLevelCfg.data.nHsToneGroup_V,
                sCFGLowLevelHsTones.Vdsl);
          }
    
          nErrCode = DSL_CPE_Ioctl(
                         pControlContext->fd[nDevNum],
                         DSL_FIO_LOW_LEVEL_CONFIGURATION_SET,
                         (int) &sLowLevelCfg);
    
          if (nErrCode != DSL_SUCCESS)
          {
             DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
                "ERROR - DSL_FIO_LOW_LEVEL_CONFIGURATION_SET ioctl failed, "
                "error=%d!" DSL_CPE_CRLF,
                nErrCode));
          }
       }
       else
       {
          DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
             "ERROR - DSL_FIO_LOW_LEVEL_CONFIGURATION_GET ioctl failed, "
             "error=%d!" DSL_CPE_CRLF,
             nErrCode));
       }
    
       /* on failure print additional debug info */
       if (sLowLevelCfg.accessCtl.nReturn)
       {
          DSL_CCA_DEBUG(DSL_CCA_DBG_WRN, (DSL_CPE_PREFIX
             "WARNING - DSL_FIO_LOW_LEVEL_CONFIGURATION "
             "access control retCode=%d!" DSL_CPE_CRLF,
             sLowLevelCfg.accessCtl.nReturn));
       }
    
       DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
          "OUT - DSL_CPE_LowLevelCfgValidateAndApply, retCode=%d" DSL_CPE_CRLF,