34 #include "hostIf_utils.h"
40 static WDMP_STATUS GetParamInfo (
const char *pParameterName, param_t ***parametervalPtrPtr,
int *paramCountPtr,
int paramIndex);
68 void getValues (
const char *paramName[],
const unsigned int paramCount, param_t ***paramValArr,
size_t **retValCount, WDMP_STATUS **retStatus)
75 for (cnt = 0; cnt < paramCount; cnt++)
78 if(strlen(paramName[cnt]) < MAX_PARAMETERNAME_LEN) {
79 (*retStatus)[cnt] = GetParamInfo (paramName[cnt], paramValArr, &numParams,cnt);
80 (*retValCount)[cnt] = numParams;
81 RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF,
"Parameter Name: %s return: %d\n", paramName[cnt], (*retStatus)[cnt]);
83 (*retStatus)[cnt] = WDMP_ERR_INVALID_PARAMETER_NAME;
84 (*retValCount)[cnt] = 0;
95 void setValues(
const ParamVal paramVal[],
const unsigned int paramCount,
const WEBPA_SET_TYPE setType, money_trace_spans *timeSpan, WDMP_STATUS **retStatus,
char * transaction_id)
98 for(cnt = 0; cnt < paramCount; cnt++)
100 (*retStatus)[cnt] = (WDMP_STATUS) SetParamInfo(paramVal[cnt], transaction_id);
107 rbusHandle_t g_busHandle = 0;
109 static void ensureRbusHandle()
114 char compName[50] =
"";
115 snprintf(compName, 50,
"parodus-rbus-If");
116 rc = rbus_open(&g_busHandle, compName);
117 if(rc != RBUS_ERROR_SUCCESS)
119 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"rbus_open failed err: %d\n", rc);
126 static rbusValueType_t getRbusDataTypefromWebPA(
WAL_DATA_TYPE type)
128 if (type == WAL_STRING)
134 if (type == WAL_UINT)
137 if (type == WAL_BOOLEAN)
140 if (type == WAL_DATETIME)
141 return RBUS_DATETIME;
143 if (type == WAL_BASE64)
146 if (type == WAL_LONG)
149 if (type == WAL_ULONG)
152 if (type == WAL_FLOAT)
155 if (type == WAL_DOUBLE)
158 if (type == WAL_BYTE)
164 static DATA_TYPE mapRbusDataTypeToWebPA (rbusValueType_t type)
166 DATA_TYPE rc = WDMP_STRING;
216 static WDMP_STATUS rbusGetParamInfo (
const char *pParameterName, param_t ***parametervalPtrPtr,
int *paramCountPtr,
int index)
218 WDMP_STATUS ret = WDMP_FAILURE;
220 int numOfOutVals = 0;
221 rbusProperty_t outputVals = NULL;
227 rc = rbus_getExt(g_busHandle, 1, &pParameterName, &numOfOutVals, &outputVals);
231 rc = rbus_get(g_busHandle, pParameterName, &getVal);
232 if(RBUS_ERROR_SUCCESS == rc)
235 rbusProperty_Init(&outputVals, pParameterName, getVal);
236 rbusValue_Release(getVal);
240 if(RBUS_ERROR_SUCCESS == rc)
242 rbusProperty_t next = outputVals;
243 *paramCountPtr = numOfOutVals;
245 (*parametervalPtrPtr)[index] = (param_t *) calloc(
sizeof(param_t),*paramCountPtr);
247 for (
int i = 0; i < numOfOutVals; i++)
249 rbusValue_t val = rbusProperty_GetValue(next);
250 rbusValueType_t type = rbusValue_GetType(val);
252 (*parametervalPtrPtr)[index][i].name = strdup(rbusProperty_GetName(next));
253 (*parametervalPtrPtr)[index][i].value = rbusValue_ToString(val,NULL,0);
254 (*parametervalPtrPtr)[index][i].type = mapRbusDataTypeToWebPA(type);
256 next = rbusProperty_GetNext(next);
259 rbusProperty_Release(outputVals);
264 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"Failed to get the data for %s with error : %d\n", pParameterName, rc);
279 rbusValueType_t type = getRbusDataTypefromWebPA(paramVal.type);
280 rbusValue_Init(&setVal);
281 if (rbusValue_SetFromString(setVal, type, paramVal.value))
283 rbusSetOptions_t opts = {
true, strtoul (transactionID, NULL, 0)};
284 rc = rbus_set(g_busHandle, paramVal.name, setVal, &opts);
285 if(rc != RBUS_ERROR_SUCCESS)
287 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
" Invalid Parameter name %s\n",paramVal.name);
288 ret = WAL_ERR_INVALID_PARAMETER_VALUE;
291 rbusValue_Release(setVal);
292 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"set_ParamValues_tr69hostIf %d\n",ret);
296 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
" Invalid Parameter name %s\n",paramVal.name);
297 ret = WAL_ERR_INVALID_PARAMETER_NAME;
306 static WDMP_STATUS GetParamInfo (
const char *pParameterName, param_t ***parametervalPtrPtr,
int *paramCountPtr,
int index)
308 void *dataBaseHandle = NULL;
309 DB_STATUS dbRet = DB_FAILURE;
311 WDMP_STATUS ret = WDMP_FAILURE;
317 dataBaseHandle = getDataModelHandle();
323 char **getParamList = (
char**) calloc (MAX_NUM_PARAMETERS,
sizeof(
char*));
324 if (NULL == getParamList)
326 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"Error allocating memory\n");
329 char **ParamDataTypeList = (
char**) calloc (MAX_NUM_PARAMETERS,
sizeof(
char*));
330 if(NULL == ParamDataTypeList)
332 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"Error allocating memory\n");
338 WDMP_STATUS getRet = WDMP_FAILURE;
339 int successWcCnt = 0;
341 dbRet = getChildParamNamesFromDataModel((
void *) dataBaseHandle,
const_cast<char*
> (pParameterName), getParamList, ParamDataTypeList, paramCountPtr);
342 if(*paramCountPtr != 0 && dbRet == DB_SUCCESS)
344 (*parametervalPtrPtr)[index] = (param_t *) calloc(
sizeof(param_t),*paramCountPtr);
345 for(wc_cnt = 0; wc_cnt < *paramCountPtr; wc_cnt++)
347 strncpy (Param.
paramName, getParamList[wc_cnt], MAX_PARAM_LENGTH - 1);
348 free(getParamList[wc_cnt]);
349 Param.
paramName[MAX_PARAM_LENGTH - 1] =
'\0';
352 converttohostIfType (ParamDataTypeList[wc_cnt], &(Param.
paramtype));
354 free(ParamDataTypeList[wc_cnt]);
357 (*parametervalPtrPtr)[index][wc_cnt].name = NULL;
358 (*parametervalPtrPtr)[index][wc_cnt].value = NULL;
363 if(WDMP_SUCCESS == getRet)
365 int iParamValSize = MAX_PARAM_LENGTH;
366 if (Param.isLengthyParam && (NULL != Param.paramValueLong)) {
367 iParamValSize = strlen(Param.paramValueLong)+1;
370 (*parametervalPtrPtr)[index][successWcCnt].name = (
char*) calloc (MAX_PARAM_LENGTH,
sizeof(
char));
371 (*parametervalPtrPtr)[index][successWcCnt].value = (
char*) calloc (iParamValSize,
sizeof(
char));
372 if ((*parametervalPtrPtr)[index][successWcCnt].name == NULL || (*parametervalPtrPtr)[index][successWcCnt].value == NULL)
374 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"Error allocating memory\n");
379 strncat((*parametervalPtrPtr)[index][successWcCnt].name, Param.
paramName, MAX_PARAM_LENGTH - 1);
385 case hostIf_IntegerType:
386 case hostIf_BooleanType:
387 snprintf ((*parametervalPtrPtr)[index][successWcCnt].value, MAX_PARAM_LENGTH,
"%d", *((
int *) Param.
paramValue));
389 case hostIf_UnsignedIntType:
390 snprintf ((*parametervalPtrPtr)[index][successWcCnt].value, MAX_PARAM_LENGTH,
"%u", *((
unsigned int *) Param.
paramValue));
392 case hostIf_UnsignedLongType:
393 snprintf ((*parametervalPtrPtr)[index][successWcCnt].value, MAX_PARAM_LENGTH,
"%u", *((
unsigned long *) Param.
paramValue));
395 case hostIf_StringType:
397 if (Param.isLengthyParam && (NULL != Param.paramValueLong)) {
398 strncat ((*parametervalPtrPtr)[index][successWcCnt].value, Param.paramValueLong, iParamValSize);
399 free (Param.paramValueLong);
400 Param.paramValueLong = NULL;
403 strncat ((*parametervalPtrPtr)[index][successWcCnt].value, Param.
paramValue, MAX_PARAM_LENGTH - 1);
413 free(ParamDataTypeList);
414 *paramCountPtr = successWcCnt;
420 free(ParamDataTypeList);
421 RDK_LOG (RDK_LOG_INFO, LOG_PARODUS_IF,
" %s :: Wild card Param list is empty; Not owned by tr69HostIf; Post it to RBUS\n", pParameterName);
422 ret = rbusGetParamInfo(pParameterName, parametervalPtrPtr, paramCountPtr, index);
427 RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF,
"Get Request for a Non-WildCard Parameter \n");
431 if (getParamInfoFromDataModel(dataBaseHandle,
const_cast<char*
> (pParameterName), &dmParam))
433 RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF,
"Valid Parameter..! \n ");
434 strncpy (Param.
paramName, pParameterName, MAX_PARAM_LENGTH - 1);
435 Param.
paramName[MAX_PARAM_LENGTH - 1] =
'\0';
437 Param.
bsUpdate = getBSUpdateEnum(dmParam.bsUpdate);
439 if(dmParam.dataType != NULL)
441 converttohostIfType (dmParam.dataType, &(Param.
paramtype));
443 freeDataModelParam(dmParam);
446 if (ret == WDMP_SUCCESS)
448 int iParamValSize = MAX_PARAM_LENGTH;
449 if (Param.isLengthyParam && (NULL != Param.paramValueLong)) {
450 iParamValSize = strlen(Param.paramValueLong)+1;
454 (*parametervalPtrPtr)[index] = (param_t*) calloc (1,
sizeof(param_t));
455 (*parametervalPtrPtr)[index][0].name = (
char*) calloc (strlen(pParameterName)+1,
sizeof(char));
456 (*parametervalPtrPtr)[index][0].value = (
char*) calloc (iParamValSize,
sizeof(
char));
457 (*parametervalPtrPtr)[index][0].type = WDMP_STRING;
459 if (NULL == (*parametervalPtrPtr)[index] || NULL == (*parametervalPtrPtr)[index][0].name || NULL == (*parametervalPtrPtr)[index][0].value)
461 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"Error allocating memory\n");
463 if((*parametervalPtrPtr)[index][0].value != NULL) free((*parametervalPtrPtr)[index][0].value);
464 if((*parametervalPtrPtr)[index][0].name != NULL) free((*parametervalPtrPtr)[index][0].name);
465 if((*parametervalPtrPtr)[index] != NULL) free((*parametervalPtrPtr)[index]);
469 RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF,
"CMCSA:: GetParamInfo Param.paramtype is %d\n", Param.
paramtype);
472 RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF,
"CMCSA:: GetParamInfo parametervalPtr->type is %d\n",((*parametervalPtrPtr)[index][0].type));
473 RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF,
"CMCSA:: GetParamInfo\n");
475 strncpy((*parametervalPtrPtr)[index][0].name, Param.
paramName, strlen(pParameterName)+1);
478 case hostIf_IntegerType:
479 case hostIf_BooleanType:
480 snprintf ((*parametervalPtrPtr)[index][0].value, MAX_PARAM_LENGTH,
"%d", *((
int *) Param.
paramValue));
482 case hostIf_UnsignedIntType:
483 snprintf ((*parametervalPtrPtr)[index][0].value, MAX_PARAM_LENGTH,
"%u", *((
unsigned int *) Param.
paramValue));
485 case hostIf_UnsignedLongType:
486 snprintf ((*parametervalPtrPtr)[index][0].value, MAX_PARAM_LENGTH,
"%u", *((
unsigned long *) Param.
paramValue));
488 case hostIf_StringType:
490 if (Param.isLengthyParam && (NULL != Param.paramValueLong)) {
491 strncat ((*parametervalPtrPtr)[index][0].value, Param.paramValueLong, iParamValSize);
492 free (Param.paramValueLong);
493 Param.paramValueLong = NULL;
496 strncat ((*parametervalPtrPtr)[index][0].value, Param.
paramValue, MAX_PARAM_LENGTH - 1);
500 RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF,
"CMCSA:: GetParamInfo value is %s\n", (*parametervalPtrPtr)[index][0].value);
507 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"Failed get_ParamValues_tr69hostIf() Param Name :- %s \n",pParameterName);
512 RDK_LOG (RDK_LOG_INFO, LOG_PARODUS_IF,
"%s :: Not owned by tr69HostIf; Post it to RBUS.\n",pParameterName);
513 ret = rbusGetParamInfo(pParameterName, parametervalPtrPtr, paramCountPtr, index);
519 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"Data base Handle is not Initialized %s\n", pParameterName);
520 ret = rbusGetParamInfo(pParameterName, parametervalPtrPtr, paramCountPtr, index);
528 void *dataBaseHandle = NULL;
533 dataBaseHandle = getDataModelHandle();
536 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"Data Model Not Initialized... Unable to process the SET operation\n");
537 ret = rbusSetParamInfo(paramVal, transactionID);
539 else if(getParamInfoFromDataModel((
void *)dataBaseHandle,paramVal.name,&dmParam))
542 if(dmParam.dataType != NULL)
544 converttohostIfType(dmParam.dataType,&(Param.
paramtype));
546 Param.
bsUpdate = getBSUpdateEnum(dmParam.bsUpdate);
548 freeDataModelParam(dmParam);
550 converttoWalType(Param.
paramtype,&walType);
552 if(walType != paramVal.type)
554 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
" Invalid Parameter type for %s\n",paramVal.name);
555 return WAL_ERR_INVALID_PARAMETER_TYPE;
558 strncpy(Param.
paramName, paramVal.name,MAX_PARAM_LENGTH-1);
559 Param.
paramName[MAX_PARAM_LENGTH-1]=
'\0';
561 Param.isLengthyParam =
false;
562 Param.paramValueLong = NULL;
563 if (strcasecmp(Param.
paramName,
"Device.X_RDKCENTRAL-COM_T2.ReportProfiles") == 0) {
565 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"[%s:%s:%d] Device.X_RDKCENTRAL-COM_T2.ReportProfiles allocating long buff \n", __FILE__, __FUNCTION__, __LINE__);
566 Param.isLengthyParam =
true;
569 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"[%s:%s:%d] Not Device.X_RDKCENTRAL-COM_T2.ReportProfiles. Param.paramName: %s \n", __FILE__, __FUNCTION__, __LINE__, Param.
paramName);
572 if (Param.
paramtype == hostIf_BooleanType)
575 if (strcmp (paramVal.value,
"1") == 0 || strcasecmp (paramVal.value,
"true") == 0)
579 else if (strcmp (paramVal.value,
"0") == 0 || strcasecmp (paramVal.value,
"false") == 0)
585 return WAL_ERR_INVALID_PARAMETER_VALUE;
588 else if (Param.
paramtype == hostIf_IntegerType)
591 long int value = (int) strtol (paramVal.value, &tailPtr, 10);
592 if (strlen (tailPtr))
593 return WAL_ERR_INVALID_PARAMETER_VALUE;
596 else if (Param.
paramtype == hostIf_UnsignedIntType)
599 long int value = (int) strtol (paramVal.value, &tailPtr, 10);
600 if (strlen (tailPtr) || value < 0)
601 return WAL_ERR_INVALID_PARAMETER_VALUE;
607 if (Param.isLengthyParam) {
608 int iParamLen = strlen(paramVal.value);
609 if (TR69HOSTIFMGR_MAX_LONG_PARAM_LEN < iParamLen) {
610 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"[%s:%s:%d] Longer than expected parameter. Max len:%d iParamLen: %d\n",
611 __FILE__, __FUNCTION__, __LINE__, TR69HOSTIFMGR_MAX_LONG_PARAM_LEN, iParamLen);
612 ret = WAL_ERR_INVALID_PARAMETER_VALUE;
615 Param.paramValueLong = (
char*) malloc (iParamLen+1);
616 if (NULL == Param.paramValueLong) {
617 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
" Memory allocation failed.\n");
618 ret = WAL_STATUS_RESOURCES;
622 memset (Param.paramValueLong,
'\0', iParamLen+1);
623 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"[%s:%s:%d] Long iParamLen: %d\n", __FILE__, __FUNCTION__, __LINE__, iParamLen);
624 strncpy(Param.paramValueLong, paramVal.value, iParamLen);
628 strncpy(Param.
paramValue, paramVal.value,MAX_PARAM_LENGTH-1);
634 if ((NULL != strstr (Param.
paramName,
"Device.X_RDK_WebConfig.")) && (transactionID))
641 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"set_ParamValues_tr69hostIf %d\n",ret);
646 RDK_LOG(RDK_LOG_WARN, LOG_PARODUS_IF,
" %s :: Not owned by TR69HostIF.. Forward to RBUS\n",paramVal.name);
647 ret = rbusSetParamInfo(paramVal, transactionID);
659 ptrParam->
reqType = HOSTIF_GET;
660 WDMP_STATUS retStatus = WDMP_FAILURE;
661 status = hostIf_GetMsgHandler(ptrParam);
664 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"[%s:%s:%d] Error in Get Message Handler : %d\n", __FILE__, __FUNCTION__, __LINE__, status);
665 retStatus =(WDMP_STATUS) convertFaultCodeToWalStatus(ptrParam->
faultCode);
666 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"[%s:%d] return status of fault code: %d\n", __FUNCTION__, __LINE__, retStatus);
670 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"[%s:%s:%d] The value for param: %s is %s paramLen : %d\n", __FILE__, __FUNCTION__, __LINE__, ptrParam->
paramName,ptrParam->
paramValue, ptrParam->
paramLen);
671 retStatus = WDMP_SUCCESS;
684 ptrParam->
reqType = HOSTIF_SET;
685 status = hostIf_SetMsgHandler(ptrParam);
687 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"[%s:%s:%d] Error in Set Message Handler Status : %d\n", __FILE__, __FUNCTION__, __LINE__, status);
688 retStatus = convertFaultCodeToWalStatus(ptrParam->
faultCode);
693 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"[%s:%s:%d] The value for param: %s is %s paramLen : %d\n", __FILE__, __FUNCTION__, __LINE__, ptrParam->
paramName,ptrParam->
paramValue, ptrParam->
paramLen);
704 case fcRequestDenied:
707 case fcAttemptToSetaNonWritableParameter:
708 retWalStatus = WAL_ERR_NOT_WRITABLE;
710 case fcInvalidParameterName:
711 retWalStatus = WAL_ERR_INVALID_PARAMETER_NAME;
713 case fcInvalidParameterType:
714 retWalStatus = WAL_ERR_INVALID_PARAMETER_TYPE;
716 case fcInvalidParameterValue:
717 retWalStatus = WAL_ERR_INVALID_PARAMETER_VALUE;
735 if(NULL != paramName)
737 if(!strcmp(paramName+strlen(paramName)-1,
"."))
747 if(!strcmp(ParamDataType,
"string"))
748 *pParamType = hostIf_StringType;
749 else if(!strcmp(ParamDataType,
"unsignedInt"))
750 *pParamType = hostIf_UnsignedIntType;
751 else if(!strcmp(ParamDataType,
"int"))
752 *pParamType = hostIf_IntegerType;
753 else if(!strcmp(ParamDataType,
"unsignedLong"))
754 *pParamType = hostIf_UnsignedLongType;
755 else if(!strcmp(ParamDataType,
"boolean"))
756 *pParamType = hostIf_BooleanType;
757 else if(!strcmp(ParamDataType,
"hexBinary"))
758 *pParamType = hostIf_StringType;
760 *pParamType = hostIf_StringType;
765 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Inside converttoWalType \n");
768 case hostIf_StringType:
769 *pwalType = WAL_STRING;
771 case hostIf_UnsignedIntType:
772 *pwalType = WAL_UINT;
774 case hostIf_IntegerType:
777 case hostIf_BooleanType:
778 *pwalType = WAL_BOOLEAN;
780 case hostIf_UnsignedLongType:
781 *pwalType = WAL_ULONG;
783 case hostIf_DateTimeType:
784 *pwalType = WAL_DATETIME;
787 *pwalType = WAL_STRING;