RDK Documentation (Open Sourced RDK Components)
webpa_attribute.cpp
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_adapter.cpp
21  *
22  * @description This file describes the Webpa Attribute request handling
23  *
24  */
25 #include <string.h>
26 #include "webpa_attribute.h"
27 #include "hostIf_msgHandler.h"
28 #include "rdk_debug.h"
29 #include "webpa_parameter.h"
30 #include "webpa_notification.h"
31 #include "safec_lib.h"
32 
33 /*----------------------------------------------------------------------------*/
34 /* File Scoped Variables */
35 /*----------------------------------------------------------------------------*/
36 
37 extern char **g_notifyParamList;
38 extern unsigned int g_notifyListSize;
39 /*----------------------------------------------------------------------------*/
40 /* Function Prototypes */
41 /*----------------------------------------------------------------------------*/
42 static WAL_STATUS get_AttribValues_tr69hostIf(HOSTIF_MsgData_t *ptrParam);
43 static WAL_STATUS set_AttribValues_tr69hostIf (HOSTIF_MsgData_t *param);
44 static WAL_STATUS getParamAttributes(const char *pParameterName, AttrVal ***attr, int *TotalParams);
45 static WAL_STATUS setParamAttributes(const char *pParameterName, const AttrVal *attArr);
46 
47 
48 /*----------------------------------------------------------------------------*/
49 /* External Functions */
50 /*----------------------------------------------------------------------------*/
51 
52 /**
53  *
54  *
55  * @param[in] paramName List of Parameters.
56  * @param[in] paramCount Number of parameters.
57  * @param[out] attr Two dimentional array of attribute name/value pairs.
58  * @param[out] retAttrCount List of "number of attributes" for each input paramName.
59  * @param[out] retStatus List of Return status.
60  */
61 void getAttributes(const char *paramName[], const unsigned int paramCount, money_trace_spans *timeSpan, AttrVal ***attr, int *retAttrCount, WAL_STATUS *retStatus)
62 {
63  int cnt=0;
64  for(cnt=0; cnt<paramCount; cnt++)
65  {
66  retStatus[cnt]=getParamAttributes(paramName[cnt], &attr[cnt], &retAttrCount[cnt]);
67  RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,"Parameter Name: %s, Parameter Attributes return: %d\n",paramName[cnt],retStatus[cnt]);
68  }
69 }
70 
71 /**
72  * @brief setAttributes interface sets the attribute values.
73  *
74  * @param[in] paramName List of Parameters.
75  * @param[in] paramCount Number of parameters.
76  * @param[in] attr List of attribute name/value pairs.
77  * @param[out] retStatus List of Return status.
78  */
79 void setAttributes(ParamVal params[], const unsigned int paramCount, money_trace_spans *timeSpan, const AttrVal *attr[], WDMP_STATUS **retStatus)
80 {
81  RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,"[%s:%s:%d] Inside setAttributes, Param Count = %d\n", __FILE__, __FUNCTION__, __LINE__,paramCount);
82  int cnt=0;
83  for(cnt=0; cnt<paramCount; cnt++)
84  {
85  (*retStatus)[cnt] = (WDMP_STATUS) setParamAttributes(const_cast<const char*>(params[cnt].name),attr[cnt]);
86  }
87 }
88 
89 /*----------------------------------------------------------------------------*/
90 /* Internal functions */
91 /*----------------------------------------------------------------------------*/
92 /**
93  * @brief Get Attribute value
94  *
95  * @param[in] Parameter struct to fill
96  */
97 static WAL_STATUS get_AttribValues_tr69hostIf(HOSTIF_MsgData_t *ptrParam)
98 {
99  int retStatus = -1;
100  ptrParam->reqType = HOSTIF_GETATTRIB;
101  hostIf_GetAttributesMsgHandler(ptrParam);
102  if(retStatus != 0) {
103  RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,"[%s:%s:%d] Failed in IARM_Bus_Call(), with return value: %d\n", __FILE__, __FUNCTION__, __LINE__, retStatus);
104  return WAL_ERR_INVALID_PARAM;
105  }
106  else
107  {
108  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);
109  }
110  return WAL_SUCCESS; // Mock Response
111 }
112 
113 /**
114  * @brief Get Attribute value
115  *
116  */
117 static WAL_STATUS getParamAttributes(const char *pParameterName, AttrVal ***attr, int *TotalParams)
118 {
119  int ret = WAL_SUCCESS;
120  errno_t safec_rc = -1;
121  int sizeAttrArr = 1; // Currently support only Notification parameter
122  int i = 0;
123  HOSTIF_MsgData_t Param = {0};
124 
125  memset(&Param, '\0', sizeof(HOSTIF_MsgData_t));
126 
127  // Check if pParameterName is in the list of notification parameters and check if the parameter is one among them
128  int found = 0;
129  for(i = 0; i < g_notifyListSize; i++)
130  {
131  if(!strcmp(pParameterName,g_notifyParamList[i]))
132  {
133  found = 1;
134  break;
135  }
136  }
137  if(!found)
138  {
139  return WAL_ERR_INVALID_PARAM;
140  }
141 
142  *TotalParams = sizeAttrArr;
143  attr[0] = (AttrVal **) malloc(sizeof(AttrVal *) * sizeAttrArr);
144  for(i = 0; i < sizeAttrArr; i++)
145  {
146  attr[0][i] = (AttrVal *) malloc(sizeof(AttrVal) * 1);
147  attr[0][i]->name = (char *) malloc(sizeof(char) * MAX_PARAMETER_LENGTH);
148  attr[0][i]->value = (char *) malloc(sizeof(char) * MAX_PARAMETERVALUE_LEN);
149 
150  safec_rc=strcpy_s(attr[0][i]->name,MAX_PARAMETER_LENGTH,pParameterName); // Currently only one attribute ie., notification, so use the parameter name to get its value
151  if(safec_rc!=EOK)
152  {
153  ERR_CHK(safec_rc);
154  }
155  /* Get Notification value for the parameter from hostif */
156  strncpy(Param.paramName,pParameterName,strlen(pParameterName)+1);
157  Param.instanceNum = 0;
158  Param.paramtype = hostIf_IntegerType;
159  ret = get_AttribValues_tr69hostIf(&Param);
160  strncpy(attr[0][i]->value,Param.paramValue, strlen(Param.paramValue));
161  attr[0][i]->value[strlen(Param.paramValue)] = '\0';
162  attr[0][i]->type = WAL_INT; // Currently only notification which is a int
163  }
164  return WAL_SUCCESS;
165 }
166 
167 
168 /**
169  * generic Api for set attribute HostIf parameters through IARM_TR69Bus
170  **/
171 static WAL_STATUS set_AttribValues_tr69hostIf (HOSTIF_MsgData_t *param) //CID:18602,18273 - Passbyvalue
172 {
173  int retStatus = -1;
174  param->reqType = HOSTIF_SETATTRIB;
175 
176  // Try to set value
177  retStatus = hostIf_SetAttributesMsgHandler(param);
178 
179  if(retStatus != 0)
180  {
181  RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,"[%s:%s:%d] Failed in Set Attribute call, with return value: %d\n", __FILE__, __FUNCTION__, __LINE__, retStatus);
182  return WAL_ERR_INVALID_PARAMETER_NAME;
183  }
184  else
185  {
186  RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,"[%s:%s:%d] Set Successful for value : %s\n", __FILE__, __FUNCTION__, __LINE__, (char *)param->paramValue);
187  }
188  return WAL_SUCCESS;
189 }
190 /**
191  * @brief Set Attribute value
192  *
193  */
194 static WAL_STATUS setParamAttributes(const char *pParameterName, const AttrVal *attArr)
195 {
196  errno_t safec_rc = -1;
197  WAL_STATUS ret = WAL_SUCCESS;
198  int i = 0;
199  HOSTIF_MsgData_t Param = {0};
200  memset(&Param, '\0', sizeof(HOSTIF_MsgData_t));
201  // Enable only for notification parameters in the config file
202  int found = 0;
203  for(i = 0; i < g_notifyListSize; i++)
204  {
205  if(!strcmp(pParameterName,g_notifyParamList[i]))
206  {
207  found = 1;
208  RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,"[%s:%s:%d] Inside setParamAttributes, Param Found in Glist \n", __FILE__, __FUNCTION__, __LINE__,pParameterName);
209  break;
210  }
211  }
212  if(!found)
213  {
214  return WAL_SUCCESS; //Fake success for all setattributes now
215  }
216 
217  safec_rc=strcpy_s(Param.paramName,sizeof(Param.paramName) ,pParameterName);
218  if(safec_rc!=EOK)
219  {
220  ERR_CHK(safec_rc);
221  }
222  safec_rc=strcpy_s(Param.paramValue,sizeof(Param.paramValue), attArr->value);
223  if(safec_rc!=EOK)
224  {
225  ERR_CHK(safec_rc);
226  }
227  Param.paramtype = hostIf_IntegerType;
228  ret = set_AttribValues_tr69hostIf (&Param);
229  return ret;
230 }
_HostIf_MsgData_t::reqType
HostIf_ReqType_t reqType
Definition: hostIf_tr69ReqHandler.h:178
_HostIf_MsgData_t::instanceNum
short instanceNum
Definition: hostIf_tr69ReqHandler.h:176
setAttributes
void setAttributes(ParamVal params[], const unsigned int paramCount, money_trace_spans *timeSpan, const AttrVal *attr[], WDMP_STATUS **retStatus)
setAttributes interface sets the attribute values.
Definition: webpa_attribute.cpp:79
webpa_attribute.h
rdk_debug.h
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
WAL_STATUS
WAL_STATUS
WebPA Error codes.
Definition: webpa_adapter.h:60
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
_HostIf_MsgData_t::paramName
char paramName[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:171
webpa_parameter.h
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
getAttributes
void getAttributes(const char *paramName[], const unsigned int paramCount, money_trace_spans *timeSpan, AttrVal ***attr, int *retAttrCount, WAL_STATUS *retStatus)
Definition: webpa_attribute.cpp:61
ParamVal
Structure to store Parameter info or Attribute info.
Definition: webpa_adapter.h:159
hostIf_msgHandler.h
The header file provides HostIf message handler information APIs.
WAL_SUCCESS
@ WAL_SUCCESS
Definition: webpa_adapter.h:62
_HostIf_MsgData_t::paramLen
short paramLen
Definition: hostIf_tr69ReqHandler.h:175