47 #include "hostIf_utils.h"
48 #include "hostIf_tr69ReqHandler.h"
52 #include "exception.hpp"
53 #include "illegalArgumentException.hpp"
56 #define MAX_NUM_PARAMETERS 2048
57 #define MAX_PARAMETER_LENGTH 512
59 static const char *EXCLUDE_PARAMLIST[] = {
"Device.X_RDKCENTRAL-COM_T2.ReportProfiles", \
60 "Device.X_RDKCENTRAL-COM_T2.ReportProfilesMsgPack"
63 #define EXCLUDE_LIST_SIZE (sizeof((EXCLUDE_PARAMLIST))/sizeof((EXCLUDE_PARAMLIST)[0]))
65 rbusError_t TR_Dml_GetHandler(rbusHandle_t handle, rbusProperty_t property, rbusGetHandlerOptions_t* opts);
66 static rbusHandle_t rbusHandle = NULL;
68 static bool isInExclusionList(
const char* param) {
70 bool isMatch = false ;
71 for (i = 0; i < EXCLUDE_LIST_SIZE ; i++) {
72 if (strncmp(EXCLUDE_PARAMLIST[i], param, MAX_PARAMETER_LENGTH) == 0) {
80 static void convert2hostIfDataType(
char *ParamDataType,
HostIf_ParamType_t* pParamType)
82 if(!strcmp(ParamDataType,
"string"))
83 *pParamType = hostIf_StringType;
84 else if(!strcmp(ParamDataType,
"unsignedInt"))
85 *pParamType = hostIf_UnsignedIntType;
86 else if(!strcmp(ParamDataType,
"int"))
87 *pParamType = hostIf_IntegerType;
88 else if(!strcmp(ParamDataType,
"unsignedLong"))
89 *pParamType = hostIf_UnsignedLongType;
90 else if(!strcmp(ParamDataType,
"boolean"))
91 *pParamType = hostIf_BooleanType;
92 else if(!strcmp(ParamDataType,
"hexBinary"))
93 *pParamType = hostIf_StringType;
95 *pParamType = hostIf_StringType;
98 rbusError_t TR_Dml_GetHandler(rbusHandle_t handle, rbusProperty_t inProperty, rbusGetHandlerOptions_t* opts)
102 rbusError_t rc = RBUS_ERROR_SUCCESS;
104 const char *name = NULL;
109 void *dataBaseHandle = NULL;
111 rbusValue_Init(&value);
113 name = rbusProperty_GetName(inProperty);
117 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s][rbusdml] The parameter requested through rbus interface is invalid..!!! \n ", __FUNCTION__);
118 rc = RBUS_ERROR_INVALID_INPUT;
122 dataBaseHandle = getDataModelHandle();
126 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s][rbusdml] Failed to initialized data base handle..!!! \n ", __FUNCTION__);
127 rc = RBUS_ERROR_DESTINATION_RESPONSE_FAILURE;
131 if (getParamInfoFromDataModel(dataBaseHandle, name, &dmParam) == 0)
133 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s][rbusdml] Invalid Parameter [%d]. \n ", __FUNCTION__);
134 rc = RBUS_ERROR_INVALID_INPUT;
138 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s][rbusdml] Valid Parameter..! \n ", __FUNCTION__);
141 char *defaultValue = NULL;
143 strncpy (param.
paramName, name, TR69HOSTIFMGR_MAX_PARAM_LEN - 1);
144 convert2hostIfDataType(dmParam.dataType, &(param.
paramtype));
145 if(dmParam.defaultValue)
147 defaultValue = strdup(dmParam.defaultValue);
150 freeDataModelParam(dmParam);
152 status = hostIf_GetMsgHandler(¶m);
155 if(status == OK && param.
faultCode == fcNoFault)
159 case hostIf_IntegerType:
160 rbusValue_SetInt32(value, *((
int *)param.
paramValue));
162 case hostIf_BooleanType:
163 rbusValue_SetBoolean(value, *((
int *)param.
paramValue));
165 case hostIf_UnsignedIntType:
166 rbusValue_SetUInt32(value, *((
unsigned int *)param.
paramValue));
168 case hostIf_UnsignedLongType:
169 rbusValue_SetUInt64(value, *((
unsigned long long *)param.
paramValue));
171 case hostIf_StringType:
178 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s][rbusdml] Successfully return the get value for the Parameter [%s].\n", __FUNCTION__, name);
179 rbusProperty_SetValue(inProperty, value);
180 rc = RBUS_ERROR_SUCCESS;
188 case hostIf_IntegerType:
189 rbusValue_SetInt32(value, *((
int *)defaultValue));
191 case hostIf_BooleanType:
192 rbusValue_SetBoolean(value, *((
int *)defaultValue));
194 case hostIf_UnsignedIntType:
195 rbusValue_SetUInt32(value, *((
unsigned int *)defaultValue));
197 case hostIf_UnsignedLongType:
198 rbusValue_SetUInt64(value, *((
unsigned long long *)defaultValue));
200 case hostIf_StringType:
201 rbusValue_SetString(value, defaultValue);
204 rbusValue_SetString(value, defaultValue);
207 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s][rbusdml] Successfully return the get the default value for the Parameter [%s].\n", __FUNCTION__, name);
208 rbusProperty_SetValue(inProperty, value);
209 rc = RBUS_ERROR_SUCCESS;
212 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s][rbusdml] Get Parameter [%s] Invalid format to send across.\n", __FUNCTION__, name);
213 rc = RBUS_ERROR_BUS_ERROR;
225 rbusValue_Release(value);
230 void init_rbus_dml_provider()
242 rs = rbus_checkStatus();
243 if(rs == RBUS_ENABLED)
245 RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF,
"[%s] [rbusdml] The rbus_checkStatus() is Enabled (%d). \n", __FUNCTION__, rs);
249 if(retry_count >= max_retry) {
250 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s] [rbusdml] The rbus_checkStatus() is Not Enabled, exiting rbus support after max retry (%d). \n",__FUNCTION__, max_retry);
253 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s][rbusdml] The rbus_checkStatus() is Not Enabled, returned with status (%d), so retrying... \n", __FUNCTION__, rs);
259 if(rs != RBUS_ENABLED) {
260 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s][rbusdml] Failed to initialized, rbus_checkStatus() returned with status (%d). \n", __FUNCTION__, rs);
264 rbusError_t rc = RBUS_ERROR_SUCCESS;
265 rbusDataElement_t* dataElements = NULL;
267 rc = rbus_open(&rbusHandle,
"tr69hostif");
268 if(rc != RBUS_ERROR_SUCCESS)
270 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"consumer: rbus_open failed: %d\n", rc);
274 char **pParamNameList = (
char**) calloc (MAX_NUM_PARAMETERS,
sizeof(
char*));
275 int num_of_params = 0;
276 int num_of_rbus_params = 0;
277 int rbus_param_counter = 0;
282 if(DB_SUCCESS != get_complete_param_list (pParamNameList, &num_of_params))
284 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s][rbusdml] Failed to get complete parameter list. The number of parameter is :%d\n", __FUNCTION__, num_of_params);
288 RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,
"[%s:%d][rbusdml]Successfully get the complete parameter list, the Parameter counts is = %d\n", __FUNCTION__, __LINE__, num_of_params);
290 num_of_rbus_params = num_of_params - EXCLUDE_LIST_SIZE ;
291 dataElements = (rbusDataElement_t*)calloc(num_of_rbus_params,
sizeof(rbusDataElement_t));
293 if(dataElements != NULL)
295 for(i=0; i< num_of_params; i++)
297 if(pParamNameList[i] != NULL) {
298 if(isInExclusionList(pParamNameList[i])) {
301 RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s] [rbusdml] Parameter %s is externally rbus registered, ignoring from datamodel list.\n", __FUNCTION__,pParamNameList[i]);
304 dataElements[rbus_param_counter].name = strdup(pParamNameList[i]);
305 if(strstr(pParamNameList[i],
".{i}.")){
306 RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s] [rbusdml] Parameter [%d] : [ %s ] registered as [RBUS_ELEMENT_TYPE_TABLE]\n", __FUNCTION__, i + 1,pParamNameList[i]);
307 dataElements[rbus_param_counter].type = RBUS_ELEMENT_TYPE_TABLE;
308 dataElements[rbus_param_counter].cbTable.getHandler = TR_Dml_GetHandler;
311 RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s] [rbusdml]Parameter [%d] : [ %s ] registered as [RBUS_ELEMENT_TYPE_PROPERTY]\n", __FUNCTION__, i + 1,pParamNameList[i]);
312 dataElements[rbus_param_counter].type = RBUS_ELEMENT_TYPE_PROPERTY;
313 dataElements[rbus_param_counter].cbTable.getHandler = TR_Dml_GetHandler;
315 rbus_param_counter++ ;
320 rc = rbus_regDataElements(rbusHandle, rbus_param_counter, dataElements);
322 if(rc != RBUS_ERROR_SUCCESS)
324 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s][rbusdml] rbusPropertyProvider_Register failed: %d\n", __FUNCTION__, rc);
326 rbus_close(rbusHandle);
331 RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,
"[%s][rbusdml] rbus_regDataElements registered successfully.\n", __FUNCTION__);
335 for (i=0; i< num_of_params; i++) {
336 if(pParamNameList[i]) free(pParamNameList[i]);
342 catch (
const std::exception e)
344 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"[%s][rbusdml] Exception: %s\r\n",__FUNCTION__, e.what());
346 if(pParamNameList) free(pParamNameList);
350 int setRbusStringParam(
char *rbusParamName,
char* rbusParamValue) {
353 rbusSetOptions_t opts;
355 int ret = RBUS_ERROR_SUCCESS;
357 RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,
"[%s][rbusdml] rbusHandle is NULL.\n", __FUNCTION__);
361 rbusValue_Init(&value);
362 rbusValue_SetString(value, rbusParamValue);
364 ret = rbus_set(rbusHandle, rbusParamName, value, &opts);
365 if (ret != RBUS_ERROR_SUCCESS) {
366 RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,
"[%s][rbusdml] rbus_set Failed for [%s] with error [%d].\n", __FUNCTION__, rbusParamName, ret);
369 rbusValue_Release(value);
375 int getRbusStringParam(
char *rbusParamName,
char **rbusParamValue) {
377 rbusValue_t paramValue_t;
378 rbusValueType_t rbusValueType ;
379 int ret = RBUS_ERROR_SUCCESS ;
380 char *stringValue = NULL;
381 rbusSetOptions_t opts;
385 printf(
"rbusHandle is NULL\n");
389 ret = rbus_get(rbusHandle, rbusParamName, ¶mValue_t);
390 if(ret != RBUS_ERROR_SUCCESS) {
391 printf(
"Unable to get %s\n", rbusParamName);
394 stringValue = rbusValue_ToString(paramValue_t, NULL, 0);
395 if (stringValue != NULL)
396 *rbusParamValue = strdup(stringValue);
398 rbusValue_Release(paramValue_t);