RDK Documentation (Open Sourced RDK Components)
webpa_parameter.cpp
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 /**
20  * @file webpa_parameter.cpp
21  *
22  * @description This file describes the Webpa Parameter Request Handling
23  *
24  */
25 
26 #include <string.h>
27 #include <math.h>
28 #include <stdio.h>
29 
30 #include "webpa_parameter.h"
31 #include "rdk_debug.h"
32 #include "waldb.h"
33 #include "hostIf_msgHandler.h"
34 #include "hostIf_utils.h"
35 #include "rbus.h"
36 
37 /*----------------------------------------------------------------------------*/
38 /* Function Prototypes */
39 /*----------------------------------------------------------------------------*/
40 static WDMP_STATUS GetParamInfo (const char *pParameterName, param_t ***parametervalPtrPtr, int *paramCountPtr,int paramIndex);
41 static WDMP_STATUS get_ParamValues_tr69hostIf(HOSTIF_MsgData_t *ptrParam);
42 int isWildCardParam(const char *paramName);
43 static void converttohostIfType(char *ParamDataType,HostIf_ParamType_t* pParamType);
44 static void converttoWalType(HostIf_ParamType_t paramType,WAL_DATA_TYPE* pwalType);
45 static WAL_STATUS SetParamInfo(ParamVal paramVal , char * transaction_id);
47 static WAL_STATUS convertFaultCodeToWalStatus(faultCode_t faultCode);
48 
49 /*----------------------------------------------------------------------------*/
50 /* External Functions */
51 /*----------------------------------------------------------------------------*/
52 
53 
54 
55 /**
56  * @brief getValues interface returns the parameter values.
57  *
58  * getValues supports an option to pass wildward parameters. This can be achieved by passing an object name followed by '.'
59  * instead of parameter name.
60  *
61  * @param[in] paramName List of Parameters.
62  * @param[in] paramCount Number of parameters.
63  * @param[out] paramValArr Two dimentional array of parameter name/value pairs.
64  * @param[out] retValCount List of "number of parameters" for each input paramName. Usually retValCount will be 1 except
65  * for wildcards request where it represents the number of param/value pairs retrieved for the particular wildcard parameter.
66  * @param[out] retStatus List of Return status.
67  */
68 void getValues (const char *paramName[], const unsigned int paramCount, param_t ***paramValArr,size_t **retValCount, WDMP_STATUS **retStatus)
69 {
70  // Generic code mallocs paramValArr to hold paramCount items but only paramValArr[0] is ever accessed.
71  // Generic code uses "paramValArr[0][cnt2]" (iterating over the 2nd dimension instead of the 1st). This means
72  // paramValArr[0] (which is of type "ParamVal**") is expected to point to an array of "ParamVal*" objects
73  int cnt = 0;
74  int numParams = 0;
75  for (cnt = 0; cnt < paramCount; cnt++)
76  {
77  // GetParamInfo is responsible for generating the output response including wild card. Allocate the memory for
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]);
82  } else {
83  (*retStatus)[cnt] = WDMP_ERR_INVALID_PARAMETER_NAME;
84  (*retValCount)[cnt] = 0;
85  }
86  }
87 }
88 /**
89  * @brief setValues interface sets the parameter value.
90  *
91  * @param[in] paramVal List of Parameter name/value pairs.
92  * @param[in] paramCount Number of parameters.
93  * @param[out] retStatus List of Return status.
94  */
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)
96 {
97  int cnt=0;
98  for(cnt = 0; cnt < paramCount; cnt++)
99  {
100  (*retStatus)[cnt] = (WDMP_STATUS) SetParamInfo(paramVal[cnt], transaction_id);
101  }
102 }
103 
104 /******************************************************************************/
105 /* RBUS Internal functions */
106 /******************************************************************************/
107 rbusHandle_t g_busHandle = 0;
108 
109 static void ensureRbusHandle()
110 {
111  if(!g_busHandle)
112  {
113  rbusError_t rc;
114  char compName[50] = "";
115  snprintf(compName, 50, "parodus-rbus-If");
116  rc = rbus_open(&g_busHandle, compName);
117  if(rc != RBUS_ERROR_SUCCESS)
118  {
119  RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,"rbus_open failed err: %d\n", rc);
120  return;
121  }
122  }
123  return;
124 }
125 
126 static rbusValueType_t getRbusDataTypefromWebPA(WAL_DATA_TYPE type)
127 {
128  if (type == WAL_STRING)
129  return RBUS_STRING;
130 
131  if (type == WAL_INT)
132  return RBUS_INT32;
133 
134  if (type == WAL_UINT)
135  return RBUS_UINT32;
136 
137  if (type == WAL_BOOLEAN)
138  return RBUS_BOOLEAN;
139 
140  if (type == WAL_DATETIME)
141  return RBUS_DATETIME;
142 
143  if (type == WAL_BASE64)
144  return RBUS_BYTES;
145 
146  if (type == WAL_LONG)
147  return RBUS_INT64;
148 
149  if (type == WAL_ULONG)
150  return RBUS_UINT64;
151 
152  if (type == WAL_FLOAT)
153  return RBUS_SINGLE;
154 
155  if (type == WAL_DOUBLE)
156  return RBUS_DOUBLE;
157 
158  if (type == WAL_BYTE)
159  return RBUS_BYTE;
160 
161  return RBUS_STRING;
162 }
163 
164 static DATA_TYPE mapRbusDataTypeToWebPA (rbusValueType_t type)
165 {
166  DATA_TYPE rc = WDMP_STRING;
167  switch(type)
168  {
169  case RBUS_BOOLEAN:
170  rc = WDMP_BOOLEAN;
171  break;
172  case RBUS_CHAR :
173  case RBUS_BYTE:
174  case RBUS_INT8:
175  case RBUS_UINT8:
176  rc = WDMP_BYTE;
177  break;
178  case RBUS_INT16:
179  case RBUS_INT32:
180  rc = WDMP_INT;
181  break;
182  case RBUS_UINT16:
183  case RBUS_UINT32:
184  rc = WDMP_UINT;
185  break;
186  case RBUS_INT64:
187  rc = WDMP_LONG;
188  break;
189  case RBUS_UINT64:
190  rc = WDMP_ULONG;
191  break;
192  case RBUS_STRING:
193  rc = WDMP_STRING;
194  break;
195  case RBUS_DATETIME:
196  rc = WDMP_DATETIME;
197  break;
198  case RBUS_BYTES:
199  rc = WDMP_BASE64;
200  break;
201  case RBUS_SINGLE:
202  rc = WDMP_FLOAT;
203  break;
204  case RBUS_DOUBLE:
205  rc = WDMP_DOUBLE;
206  break;
207  case RBUS_PROPERTY:
208  case RBUS_OBJECT:
209  case RBUS_NONE:
210  rc = WDMP_NONE;
211  break;
212  }
213  return rc;
214 }
215 
216 static WDMP_STATUS rbusGetParamInfo (const char *pParameterName, param_t ***parametervalPtrPtr, int *paramCountPtr, int index)
217 {
218  WDMP_STATUS ret = WDMP_FAILURE;
219  rbusError_t rc;
220  int numOfOutVals = 0;
221  rbusProperty_t outputVals = NULL;
222 
223  ensureRbusHandle();
224 
225  *paramCountPtr = 0;
226  if (isWildCardParam(pParameterName)) // It is a wildcard Param
227  rc = rbus_getExt(g_busHandle, 1, &pParameterName, &numOfOutVals, &outputVals);
228  else
229  {
230  rbusValue_t getVal;
231  rc = rbus_get(g_busHandle, pParameterName, &getVal);
232  if(RBUS_ERROR_SUCCESS == rc)
233  {
234  numOfOutVals = 1;
235  rbusProperty_Init(&outputVals, pParameterName, getVal);
236  rbusValue_Release(getVal);
237  }
238  }
239 
240  if(RBUS_ERROR_SUCCESS == rc)
241  {
242  rbusProperty_t next = outputVals;
243  *paramCountPtr = numOfOutVals;
244 
245  (*parametervalPtrPtr)[index] = (param_t *) calloc(sizeof(param_t),*paramCountPtr);
246 
247  for (int i = 0; i < numOfOutVals; i++)
248  {
249  rbusValue_t val = rbusProperty_GetValue(next);
250  rbusValueType_t type = rbusValue_GetType(val);
251 
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);
255 
256  next = rbusProperty_GetNext(next);
257  }
258  /* Free the memory */
259  rbusProperty_Release(outputVals);
260  ret = WDMP_SUCCESS;
261  }
262  else
263  {
264  RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF, "Failed to get the data for %s with error : %d\n", pParameterName, rc);
265  }
266 
267  return ret;
268 }
269 
270 static WAL_STATUS rbusSetParamInfo(ParamVal paramVal, char * transactionID)
271 {
272  rbusError_t rc;
273  WAL_STATUS ret = WAL_SUCCESS;
274  rbusValue_t setVal;
275 
276  ensureRbusHandle();
277 
278  /* Get Param Type */
279  rbusValueType_t type = getRbusDataTypefromWebPA(paramVal.type);
280  rbusValue_Init(&setVal);
281  if (rbusValue_SetFromString(setVal, type, paramVal.value))
282  {
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)
286  {
287  RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF," Invalid Parameter name %s\n",paramVal.name);
288  ret = WAL_ERR_INVALID_PARAMETER_VALUE;
289  }
290  /* Free the data pointer that was allocated */
291  rbusValue_Release(setVal);
292  RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,"set_ParamValues_tr69hostIf %d\n",ret);
293  }
294  else
295  {
296  RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF," Invalid Parameter name %s\n",paramVal.name);
297  ret = WAL_ERR_INVALID_PARAMETER_NAME;
298  }
299  return ret;
300 }
301 
302 
303 /*----------------------------------------------------------------------------*/
304 /* Internal functions */
305 /*----------------------------------------------------------------------------*/
306 static WDMP_STATUS GetParamInfo (const char *pParameterName, param_t ***parametervalPtrPtr, int *paramCountPtr,int index)
307 {
308  void *dataBaseHandle = NULL;
309  DB_STATUS dbRet = DB_FAILURE;
310  HOSTIF_MsgData_t Param = { 0 };
311  WDMP_STATUS ret = WDMP_FAILURE;
312 
313  // Memset to 0
314  memset(&Param, '\0', sizeof(HOSTIF_MsgData_t));
315 
316  // Get DB handle
317  dataBaseHandle = getDataModelHandle();
318  if (dataBaseHandle)
319  {
320  if (isWildCardParam(pParameterName)) // It is a wildcard Param
321  {
322  /* Translate wildcard to list of parameters */
323  char **getParamList = (char**) calloc (MAX_NUM_PARAMETERS, sizeof(char*));
324  if (NULL == getParamList)
325  {
326  RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF, "Error allocating memory\n");
327  return WDMP_FAILURE;
328  }
329  char **ParamDataTypeList = (char**) calloc (MAX_NUM_PARAMETERS, sizeof(char*));
330  if(NULL == ParamDataTypeList)
331  {
332  RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF, "Error allocating memory\n");
333  free(getParamList);
334  return WDMP_FAILURE;
335  }
336  *paramCountPtr = 0;
337  int wc_cnt = 0;
338  WDMP_STATUS getRet = WDMP_FAILURE;
339  int successWcCnt = 0;
340 
341  dbRet = getChildParamNamesFromDataModel((void *) dataBaseHandle,const_cast<char*> (pParameterName), getParamList, ParamDataTypeList, paramCountPtr);
342  if(*paramCountPtr != 0 && dbRet == DB_SUCCESS)
343  {
344  (*parametervalPtrPtr)[index] = (param_t *) calloc(sizeof(param_t),*paramCountPtr);
345  for(wc_cnt = 0; wc_cnt < *paramCountPtr; wc_cnt++)
346  {
347  strncpy (Param.paramName, getParamList[wc_cnt], MAX_PARAM_LENGTH - 1);
348  free(getParamList[wc_cnt]);
349  Param.paramName[MAX_PARAM_LENGTH - 1] = '\0';
350 
351  // Convert ParamDataType to hostIf datatype
352  converttohostIfType (ParamDataTypeList[wc_cnt], &(Param.paramtype));
353  Param.instanceNum = 0;
354  free(ParamDataTypeList[wc_cnt]);
355 
356  // Initialize Name and Value to NULL
357  (*parametervalPtrPtr)[index][wc_cnt].name = NULL;
358  (*parametervalPtrPtr)[index][wc_cnt].value = NULL;
359 
360  // Convert Param.paramtype to ParamVal.type
361  getRet = get_ParamValues_tr69hostIf (&Param);
362  // Fill Only if we can able to get Proper value
363  if(WDMP_SUCCESS == getRet)
364  {
365  int iParamValSize = MAX_PARAM_LENGTH;
366  if (Param.isLengthyParam && (NULL != Param.paramValueLong)) {
367  iParamValSize = strlen(Param.paramValueLong)+1;
368  }
369 
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)
373  {
374  RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF, "Error allocating memory\n");
375  ret = WDMP_FAILURE;
376  break;
377  }
378  // Copy Param Name
379  strncat((*parametervalPtrPtr)[index][successWcCnt].name, Param.paramName, MAX_PARAM_LENGTH - 1);
380  // Copy Type
381  converttoWalType (Param.paramtype, (WAL_DATA_TYPE *) &(*parametervalPtrPtr)[index][successWcCnt].type);
382  // Copy param value
383  switch (Param.paramtype)
384  {
385  case hostIf_IntegerType:
386  case hostIf_BooleanType:
387  snprintf ((*parametervalPtrPtr)[index][successWcCnt].value, MAX_PARAM_LENGTH, "%d", *((int *) Param.paramValue));
388  break;
389  case hostIf_UnsignedIntType:
390  snprintf ((*parametervalPtrPtr)[index][successWcCnt].value, MAX_PARAM_LENGTH, "%u", *((unsigned int *) Param.paramValue));
391  break;
392  case hostIf_UnsignedLongType:
393  snprintf ((*parametervalPtrPtr)[index][successWcCnt].value, MAX_PARAM_LENGTH, "%u", *((unsigned long *) Param.paramValue));
394  break;
395  case hostIf_StringType:
396  default: // handle as string
397  if (Param.isLengthyParam && (NULL != Param.paramValueLong)) {
398  strncat ((*parametervalPtrPtr)[index][successWcCnt].value, Param.paramValueLong, iParamValSize);
399  free (Param.paramValueLong);
400  Param.paramValueLong = NULL;
401  }
402  else {
403  strncat ((*parametervalPtrPtr)[index][successWcCnt].value, Param.paramValue, MAX_PARAM_LENGTH - 1);
404  }
405  break;
406  }
407  memset(&Param, '\0', sizeof(HOSTIF_MsgData_t));
408  successWcCnt++;
409  }
410  } // End of Wild card for loop
411  // Lets Free GetParameter List
412  free(getParamList);
413  free(ParamDataTypeList);
414  *paramCountPtr = successWcCnt;
415  ret = WDMP_SUCCESS;
416  }
417  else
418  {
419  free(getParamList);
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);
423  }
424  }
425  else // Not a wildcard Parameter Lets fill it
426  {
427  RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF, "Get Request for a Non-WildCard Parameter \n");
428  *paramCountPtr = 0;
429  DataModelParam dmParam = {0};
430 
431  if (getParamInfoFromDataModel(dataBaseHandle, const_cast<char*> (pParameterName), &dmParam))
432  {
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';
436  Param.requestor = HOSTIF_SRC_WEBPA;
437  Param.bsUpdate = getBSUpdateEnum(dmParam.bsUpdate);
438 
439  if(dmParam.dataType != NULL)
440  {
441  converttohostIfType (dmParam.dataType, &(Param.paramtype)); //CID:18170 - FORWARD NULL
442  }
443  freeDataModelParam(dmParam);
444  Param.instanceNum = 0;
445  ret = get_ParamValues_tr69hostIf (&Param);
446  if (ret == WDMP_SUCCESS)
447  {
448  int iParamValSize = MAX_PARAM_LENGTH;
449  if (Param.isLengthyParam && (NULL != Param.paramValueLong)) {
450  iParamValSize = strlen(Param.paramValueLong)+1;
451  }
452 
453  // allocate parametervalPtr as a single param_t and initialize variables
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;
458 
459  if (NULL == (*parametervalPtrPtr)[index] || NULL == (*parametervalPtrPtr)[index][0].name || NULL == (*parametervalPtrPtr)[index][0].value)
460  {
461  RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF, "Error allocating memory\n");
462  //de-allocating if not NULL and not required
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]);
466  ret = WDMP_FAILURE;
467  }
468  else {
469  RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF, "CMCSA:: GetParamInfo Param.paramtype is %d\n", Param.paramtype);
470  // Convert Param.paramtype to ParamVal.type
471  converttoWalType (Param.paramtype, (WAL_DATA_TYPE *) &(*parametervalPtrPtr)[index][0].type);
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");
474 
475  strncpy((*parametervalPtrPtr)[index][0].name, Param.paramName, strlen(pParameterName)+1);
476  switch (Param.paramtype)
477  {
478  case hostIf_IntegerType:
479  case hostIf_BooleanType:
480  snprintf ((*parametervalPtrPtr)[index][0].value, MAX_PARAM_LENGTH, "%d", *((int *) Param.paramValue));
481  break;
482  case hostIf_UnsignedIntType:
483  snprintf ((*parametervalPtrPtr)[index][0].value, MAX_PARAM_LENGTH, "%u", *((unsigned int *) Param.paramValue));
484  break;
485  case hostIf_UnsignedLongType:
486  snprintf ((*parametervalPtrPtr)[index][0].value, MAX_PARAM_LENGTH, "%u", *((unsigned long *) Param.paramValue));
487  break;
488  case hostIf_StringType:
489  default: // handle as string
490  if (Param.isLengthyParam && (NULL != Param.paramValueLong)) {
491  strncat ((*parametervalPtrPtr)[index][0].value, Param.paramValueLong, iParamValSize);
492  free (Param.paramValueLong);
493  Param.paramValueLong = NULL;
494  }
495  else {
496  strncat ((*parametervalPtrPtr)[index][0].value, Param.paramValue, MAX_PARAM_LENGTH - 1);
497  }
498  break;
499  }
500  RDK_LOG (RDK_LOG_DEBUG, LOG_PARODUS_IF, "CMCSA:: GetParamInfo value is %s\n", (*parametervalPtrPtr)[index][0].value);
501  *paramCountPtr = 1;
502  ret = WDMP_SUCCESS;
503  }
504  }
505  else
506  {
507  RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF, "Failed get_ParamValues_tr69hostIf() Param Name :- %s \n",pParameterName);
508  }
509  }
510  else
511  {
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);
514  }
515  }
516  }
517  else
518  {
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);
521  }
522  return ret;
523 }
524 
525 static WAL_STATUS SetParamInfo(ParamVal paramVal, char * transactionID)
526 {
527  WAL_STATUS ret = WAL_SUCCESS;
528  void *dataBaseHandle = NULL;
529  HOSTIF_MsgData_t Param = {0};
530  DataModelParam dmParam = {0};
531  memset(&Param, '\0', sizeof(HOSTIF_MsgData_t));
532 
533  dataBaseHandle = getDataModelHandle();
534  if(!dataBaseHandle)
535  {
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);
538  }
539  else if(getParamInfoFromDataModel((void *)dataBaseHandle,paramVal.name,&dmParam))
540  {
541  WAL_DATA_TYPE walType;
542  if(dmParam.dataType != NULL)
543  {
544  converttohostIfType(dmParam.dataType,&(Param.paramtype)); //CID:18545 - FORWARD NULL
545  }
546  Param.bsUpdate = getBSUpdateEnum(dmParam.bsUpdate);
547  Param.requestor = HOSTIF_SRC_WEBPA;
548  freeDataModelParam(dmParam);
549  // Convert Param.paramtype to ParamVal.type
550  converttoWalType(Param.paramtype,&walType);
551 
552  if(walType != paramVal.type)
553  {
554  RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF," Invalid Parameter type for %s\n",paramVal.name);
555  return WAL_ERR_INVALID_PARAMETER_TYPE;
556  }
557 
558  strncpy(Param.paramName, paramVal.name,MAX_PARAM_LENGTH-1);
559  Param.paramName[MAX_PARAM_LENGTH-1]='\0';
560 
561  Param.isLengthyParam = false;
562  Param.paramValueLong = NULL;
563  if (strcasecmp(Param.paramName, "Device.X_RDKCENTRAL-COM_T2.ReportProfiles") == 0) {
564 
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;
567  }
568  else {
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);
570  }
571 
572  if (Param.paramtype == hostIf_BooleanType)
573  {
574  bool* boolPtr = (bool*) Param.paramValue;
575  if (strcmp (paramVal.value, "1") == 0 || strcasecmp (paramVal.value, "true") == 0)
576  {
577  *boolPtr = 1;
578  }
579  else if (strcmp (paramVal.value, "0") == 0 || strcasecmp (paramVal.value, "false") == 0)
580  {
581  *boolPtr = 0;
582  }
583  else
584  {
585  return WAL_ERR_INVALID_PARAMETER_VALUE;
586  }
587  }
588  else if (Param.paramtype == hostIf_IntegerType)
589  {
590  char *tailPtr;
591  long int value = (int) strtol (paramVal.value, &tailPtr, 10);
592  if (strlen (tailPtr)) // "whole" string cannot be interpreted as integer
593  return WAL_ERR_INVALID_PARAMETER_VALUE;
594  *((int*) Param.paramValue) = (int) value;
595  }
596  else if (Param.paramtype == hostIf_UnsignedIntType)
597  {
598  char *tailPtr;
599  long int value = (int) strtol (paramVal.value, &tailPtr, 10);
600  if (strlen (tailPtr) || value < 0) // "whole" string cannot be interpreted as unsigned integer
601  return WAL_ERR_INVALID_PARAMETER_VALUE;
602  *((int*) Param.paramValue) = (int) value;
603  }
604  else
605  {
606 
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;
613  return ret;
614  }
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;
619  return ret;
620  }
621  else {
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);
625  }
626  }
627  else {
628  strncpy(Param.paramValue, paramVal.value,MAX_PARAM_LENGTH-1);
629  Param.paramValue[MAX_PARAM_LENGTH-1]='\0';
630  }
631  }
632 #if 0
633  /* transactionID */
634  if ((NULL != strstr (Param.paramName, "Device.X_RDK_WebConfig.")) && (transactionID))
635  {
636  strncpy(Param.transactionID, transactionID, _BUF_LEN_256-1);
637  Param.transactionID[_BUF_LEN_256-1]='\0';
638  }
639 #endif
640  ret = set_ParamValues_tr69hostIf(&Param);
641  RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,"set_ParamValues_tr69hostIf %d\n",ret);
642  }
643  else
644  {
645  /* Its not owned by tr69HostIf. lets post it thro the rbus. */
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);
648  }
649 
650  return ret;
651 }
652 
653 /**
654  * generic Api for get HostIf parameters
655  **/
656 static WDMP_STATUS get_ParamValues_tr69hostIf(HOSTIF_MsgData_t *ptrParam)
657 {
658  int status = -1;
659  ptrParam->reqType = HOSTIF_GET;
660  WDMP_STATUS retStatus = WDMP_FAILURE;
661  status = hostIf_GetMsgHandler(ptrParam);
662 
663  if(status != 0) {
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); // returning appropriate fault code for get
666  RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,"[%s:%d] return status of fault code: %d\n", __FUNCTION__, __LINE__, retStatus);
667  }
668  else
669  {
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;
672  }
673  return retStatus;
674 }
675 
676 /**
677  * generic Api for get HostIf parameters through IARM_TR69Bus
678  **/
680 {
681  int status = -1;
682  WAL_STATUS retStatus = WAL_FAILURE;
683 
684  ptrParam->reqType = HOSTIF_SET;
685  status = hostIf_SetMsgHandler(ptrParam);
686  if(status != 0) {
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);
689  }
690  else
691  {
692  retStatus = WAL_SUCCESS;
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);
694  }
695  return retStatus;
696 }
697 
698 static WAL_STATUS convertFaultCodeToWalStatus(faultCode_t faultCode)
699 {
700  WAL_STATUS retWalStatus = WAL_FAILURE;
701  switch(faultCode)
702  {
703  case fcNoFault:
704  case fcRequestDenied:
705  retWalStatus = WAL_FAILURE;
706  break;
707  case fcAttemptToSetaNonWritableParameter:
708  retWalStatus = WAL_ERR_NOT_WRITABLE;
709  break;
710  case fcInvalidParameterName:
711  retWalStatus = WAL_ERR_INVALID_PARAMETER_NAME;
712  break;
713  case fcInvalidParameterType:
714  retWalStatus = WAL_ERR_INVALID_PARAMETER_TYPE;
715  break;
716  case fcInvalidParameterValue:
717  retWalStatus = WAL_ERR_INVALID_PARAMETER_VALUE;
718  break;
719  default:
720  retWalStatus = WAL_FAILURE;
721  break;
722  }
723  return retWalStatus;
724 }
725 
726 /**
727  * @brief Check if Parameter Name ends with . If yes it is a wild card param
728  *
729  * @param[in] paramName Name of the Parameter.
730  * @param[out] retValue 0 if present and 1 if not
731  */
732 int isWildCardParam(const char *paramName)
733 {
734  int isWildCard = 0;
735  if(NULL != paramName)
736  {
737  if(!strcmp(paramName+strlen(paramName)-1,"."))
738  {
739  isWildCard = 1;
740  }
741  }
742  return isWildCard;
743 }
744 
745 static void converttohostIfType(char *ParamDataType,HostIf_ParamType_t* pParamType)
746 {
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;
759  else
760  *pParamType = hostIf_StringType;
761 }
762 
763 static void converttoWalType(HostIf_ParamType_t paramType,WAL_DATA_TYPE* pwalType)
764 {
765  RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,"Inside converttoWalType \n");
766  switch(paramType)
767  {
768  case hostIf_StringType:
769  *pwalType = WAL_STRING;
770  break;
771  case hostIf_UnsignedIntType:
772  *pwalType = WAL_UINT;
773  break;
774  case hostIf_IntegerType:
775  *pwalType = WAL_INT;
776  break;
777  case hostIf_BooleanType:
778  *pwalType = WAL_BOOLEAN;
779  break;
780  case hostIf_UnsignedLongType:
781  *pwalType = WAL_ULONG;
782  break;
783  case hostIf_DateTimeType:
784  *pwalType = WAL_DATETIME;
785  break;
786  default:
787  *pwalType = WAL_STRING;
788  break;
789  }
790 }
791 
__DataModelParam
Definition: waldb.h:39
_HostIf_MsgData_t::reqType
HostIf_ReqType_t reqType
Definition: hostIf_tr69ReqHandler.h:178
_HostIf_MsgData_t::instanceNum
short instanceNum
Definition: hostIf_tr69ReqHandler.h:176
_HostIf_MsgData_t::bsUpdate
HostIf_Source_Type_t bsUpdate
Definition: hostIf_tr69ReqHandler.h:181
rdk_debug.h
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
WEBPA_SET_TYPE
WEBPA_SET_TYPE
Set operations supported by WebPA.
Definition: webpa_adapter.h:101
WAL_STATUS
WAL_STATUS
WebPA Error codes.
Definition: webpa_adapter.h:60
get_ParamValues_tr69hostIf
static WDMP_STATUS get_ParamValues_tr69hostIf(HOSTIF_MsgData_t *ptrParam)
Definition: webpa_parameter.cpp:656
faultCode_t
enum _faultCodes faultCode_t
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
HostIf_ParamType_t
enum _HostIf_ParamType HostIf_ParamType_t
_HostIf_MsgData_t::faultCode
faultCode_t faultCode
Definition: hostIf_tr69ReqHandler.h:179
WAL_DATA_TYPE
WAL_DATA_TYPE
WebPA Data types.
Definition: webpa_adapter.h:112
_HostIf_MsgData_t::paramName
char paramName[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:171
webpa_parameter.h
getValues
void getValues(const char *paramName[], const unsigned int paramCount, param_t ***paramValArr, size_t **retValCount, WDMP_STATUS **retStatus)
getValues interface returns the parameter values.
Definition: webpa_parameter.cpp:68
WAL_FAILURE
@ WAL_FAILURE
Definition: webpa_adapter.h:63
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
isWildCardParam
int isWildCardParam(const char *paramName)
Check if Parameter Name ends with . If yes it is a wild card param.
Definition: webpa_parameter.cpp:732
ParamVal
Structure to store Parameter info or Attribute info.
Definition: webpa_adapter.h:159
setValues
void setValues(const ParamVal paramVal[], const unsigned int paramCount, const WEBPA_SET_TYPE setType, money_trace_spans *timeSpan, WDMP_STATUS **retStatus, char *transaction_id)
setValues interface sets the parameter value.
Definition: webpa_parameter.cpp:95
set_ParamValues_tr69hostIf
static WAL_STATUS set_ParamValues_tr69hostIf(HOSTIF_MsgData_t *param)
Definition: webpa_parameter.cpp:679
_HostIf_MsgData_t::transactionID
char transactionID[256]
Definition: hostIf_tr69ReqHandler.h:174
hostIf_msgHandler.h
The header file provides HostIf message handler information APIs.
_HostIf_MsgData_t::requestor
HostIf_Source_Type_t requestor
Definition: hostIf_tr69ReqHandler.h:180
WAL_SUCCESS
@ WAL_SUCCESS
Definition: webpa_adapter.h:62
_HostIf_MsgData_t::paramLen
short paramLen
Definition: hostIf_tr69ReqHandler.h:175