28 #include "webpa_notification.h"
32 #include "hostIf_NotificationHandler.h"
34 #include "safec_lib.h"
48 #define WEBPA_DEVICE_REBOOT_PARAM "Device.X_CISCO_COM_DeviceControl.RebootDevice"
49 #define WEBPA_DEVICE_REBOOT_VALUE "Device"
50 #define WEBPA_NOTIFICATION_SOURCE "Unknown"
58 char* webPANotifySource = NULL;
64 void notificationCallBack();
85 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"***************Inside registerNotifyCallback*****************\n");
89 pIface = NotificationHandler::getInstance();
92 pIface->registerUpdateCallback(notificationCallBack);
96 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"Unable to get Notification Handler, Error in Callback Registration\n");
110 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"***************Inside setInitialNotify*****************\n");
113 char **notifyparameters=NULL;
114 int notifyListSize =0;
118 if(notifyparameters != NULL)
120 WDMP_STATUS *ret = NULL;
122 char ** tempArr = NULL;
124 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"notify List Size: %d\n",notifyListSize);
125 ret = (WDMP_STATUS *) malloc(
sizeof(WDMP_STATUS) * 1);
127 for(i=0; i < notifyListSize; i++)
130 snprintf(notif,
sizeof(notif),
"%d", 1);
131 attArr[0]->value = (
char *) malloc(
sizeof(
char) * 20);
132 strncpy(attArr[0]->value, notif, 20);
133 attArr[0]->name= (
char *) notifyparameters[i];
134 attArr[0]->type = WAL_INT;
135 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"notifyparameters[%d]: %s\n", i, notifyparameters[i]);
139 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"Failed to turn notification ON for parameter : %s ret: %d ",notifyparameters[i],ret[0]);
143 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Successfully set notification ON for parameter : %s ret: %d\n",notifyparameters[i], ret[0]);
145 if(NULL != attArr[0] && NULL != attArr[0]->value)
147 free(attArr[0]->value);
162 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Initial Notification list is empty\n");
167 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"**********************End of setInitial Notify************************\n");
172 req_struct *reqObj = NULL;
173 res_struct *resObj = NULL;
174 WDMP_STATUS ret = WDMP_FAILURE, setRet = WDMP_FAILURE;
175 int paramCount = 0, i = 0, retCount=0, index = 0, error = 0;
176 const char *getParamList[MAX_PARAMETERNAME_LEN];
177 WDMP_STATUS setCidStatus = WDMP_SUCCESS, setCmcStatus = WDMP_SUCCESS;
180 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"************** processRequest *****************\n");
182 wdmp_parse_request(reqPayload,&reqObj);
186 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Request:> Type : %d\n",reqObj->reqType);
188 resObj = (res_struct *) malloc(
sizeof(res_struct));
189 memset(resObj, 0,
sizeof(res_struct));
191 resObj->reqType = reqObj->reqType;
193 switch( reqObj->reqType )
198 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Processing GET request \n");
199 resObj->paramCnt = reqObj->u.getReq->paramCnt;
200 resObj->retStatus = (WDMP_STATUS *) calloc(resObj->paramCnt,
sizeof(WDMP_STATUS));
201 resObj->timeSpan = NULL;
202 paramCount = (int)reqObj->u.getReq->paramCnt;
204 for (i = 0; i < paramCount; i++)
206 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Request:> paramNames[%d] = %s\n",i,reqObj->u.getReq->paramNames[i]);
207 param = reqObj->u.getReq->paramNames[i];
208 getParamList[i] = strdup(param);
211 if(error != 1 && paramCount > 0)
213 resObj->u.getRes = (get_res_t *) malloc(
sizeof(get_res_t));
214 memset(resObj->u.getRes, 0,
sizeof(get_res_t));
217 resObj->u.getRes->paramCnt = reqObj->u.getReq->paramCnt;
218 resObj->u.getRes->paramNames = (
char **) malloc(
sizeof(
char *) * paramCount);
219 resObj->u.getRes->retParamCnt = (
size_t *) calloc(paramCount,
sizeof(
size_t));
220 resObj->u.getRes->params = (param_t **) malloc(
sizeof(param_t*)*paramCount);
223 memset(resObj->u.getRes->params, 0,
sizeof(param_t*)*paramCount);
224 memset(resObj->u.getRes->paramNames, 0,
sizeof(
char *) * paramCount);
225 memset(resObj->u.getRes->params, 0,
sizeof(param_t*)*paramCount);
226 getValues(getParamList, paramCount,&resObj->u.getRes->params,&resObj->u.getRes->retParamCnt ,&resObj->retStatus);
228 for(i = 0; i < paramCount; i++)
230 resObj->u.getRes->paramNames[i] =
const_cast<char *
>(getParamList[i]);
231 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Response:> paramNames[%d] = %s\n",i,resObj->u.getRes->paramNames[i]);
232 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Response:> retParamCnt[%d] = %zu\n",i,resObj->u.getRes->retParamCnt[i]);
233 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Response:> retStatus[%d] = %d\n",i,resObj->retStatus[i]);
243 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Processing GETATTR request \n");
244 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Request:> ParamCount = %zu\n",reqObj->u.getReq->paramCnt);
245 resObj->paramCnt = reqObj->u.getReq->paramCnt;
246 resObj->retStatus = (WDMP_STATUS *) malloc(
sizeof(WDMP_STATUS)*resObj->paramCnt);
247 resObj->timeSpan = NULL;
248 paramCount = (int)reqObj->u.getReq->paramCnt;
250 for (i = 0; i < paramCount; i++)
252 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Request:> paramNames[%d] = %s\n",i,reqObj->u.getReq->paramNames[i]);
253 if(reqObj->u.getReq->paramNames[i][(strlen(reqObj->u.getReq->paramNames[i])-1)] ==
'.')
255 *resObj->retStatus = WDMP_ERR_WILDCARD_NOT_SUPPORTED;
263 resObj->u.paramRes = (param_res_t *) malloc(
sizeof(param_res_t));
264 memset(resObj->u.paramRes, 0,
sizeof(param_res_t));
266 resObj->u.paramRes->params = (param_t *) malloc(
sizeof(param_t)*paramCount);
267 memset(resObj->u.paramRes->params, 0,
sizeof(param_t)*paramCount);
269 getAttributes(
const_cast<const char**
>(reqObj->u.getReq->paramNames), paramCount, resObj->timeSpan, (
ParamVal ***)&resObj->u.paramRes->params, &retCount, (
WAL_STATUS *)&ret);
270 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"retCount : %d ret : %d\n",retCount, ret);
272 for (i = 0; i < paramCount; i++)
274 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Response:> params[%d].name = %s\n",i,resObj->u.paramRes->params[i].name);
275 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Response:> params[%d].value = %s\n",i,resObj->u.paramRes->params[i].value);
276 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Response:> params[%d].type = %d\n",i,resObj->u.paramRes->params[i].type);
278 resObj->retStatus[i] = ret;
279 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Response:> retStatus[%d] = %d\n",i,resObj->retStatus[i]);
287 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Processing SET/SETATTR request \n");
288 WDMP_STATUS *retList = (WDMP_STATUS *) calloc(resObj->paramCnt,
sizeof(WDMP_STATUS));
289 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Request:> ParamCount = %zu\n",reqObj->u.setReq->paramCnt);
290 resObj->paramCnt = reqObj->u.setReq->paramCnt;
291 resObj->timeSpan = NULL;
292 paramCount = (int)reqObj->u.setReq->paramCnt;
293 resObj->retStatus = (WDMP_STATUS *) calloc(resObj->paramCnt,
sizeof(WDMP_STATUS));
294 resObj->u.paramRes = (param_res_t *) malloc(
sizeof(param_res_t));
295 memset(resObj->u.paramRes, 0,
sizeof(param_res_t));
297 for (i = 0; i < paramCount; i++)
299 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Request:> param[%d].name = %s\n",i,reqObj->u.setReq->param[i].name);
300 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Request:> param[%d].value = %s\n",i,reqObj->u.setReq->param[i].value);
305 if(ret == WDMP_SUCCESS)
307 if(reqObj->reqType == SET)
309 setValues((
ParamVal*)reqObj->u.setReq->param, paramCount, WEBPA_SET, resObj->timeSpan, &resObj->retStatus, transactionId);
313 setAttributes((
ParamVal*)reqObj->u.setReq->param, paramCount, resObj->timeSpan, (
const AttrVal **) reqObj->u.setReq->param, &resObj->retStatus);
315 resObj->u.paramRes->params = (param_t *) malloc(
sizeof(param_t)*paramCount);
316 memset(resObj->u.paramRes->params, 0,
sizeof(param_t)*paramCount);
318 for (i = 0; i < paramCount; i++)
320 resObj->u.paramRes->params[i].name = (
char *) malloc(
sizeof(
char) * MAX_PARAMETERNAME_LEN);
321 if(resObj->u.paramRes->params[i].name!=NULL){
322 rc=strcpy_s(resObj->u.paramRes->params[i].name, MAX_PARAMETERNAME_LEN, reqObj->u.setReq->param[i].name);
327 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Response:> params[%d].name = %s\n",i,resObj->u.paramRes->params[i].name);
328 resObj->u.paramRes->params[i].value = NULL;
329 resObj->u.paramRes->params[i].type = WDMP_STRING;
330 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Response:> retStatus[%d] = %d\n",i,resObj->retStatus[i]);
335 resObj->retStatus[0] = ret;
336 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"Response:> resObj->retStatus[0] = %d\n",resObj->retStatus[0]);
347 wdmp_form_response(resObj,resPayload);
351 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"Response:> Payload = %s\n", *resPayload);
355 wdmp_free_req_struct(reqObj);
359 wdmp_free_res_struct(resObj);
361 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"************** processRequest *****************\n");
364 void notificationCallBack()
366 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"************** notificationCallBack *****************\n");
368 GAsyncQueue* notificationQueue;
373 bool sentNotification =
false;
375 if (NULL == (notificationQueue = NotificationHandler::getInstance()->GetNotificationQueue()))
377 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"Notification Queue is Not Initialized\n");
380 else if (NULL == (notifyMsg = (
NotifyData*) g_async_queue_timeout_pop (notificationQueue, 1000)))
382 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"Notification Queue is Empty\n");
385 else if (NULL == notifyMsg->data)
387 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"Notify data is NULL!!\n");
390 else if (NULL == (param = notifyMsg->data->notify))
392 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"ParamNotify is NULL.. !!\n");
393 goto freeNotifyMsgData;
395 else if (notifyMsg->type < 0 || notifyMsg->type >= NOTIFY_TYPE_MAX)
397 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"Invalid Notify type %d \n", notifyMsg->type);
399 else if (NULL == param->notifyDest || NULL == param->notifyPayload)
401 RDK_LOG (RDK_LOG_ERROR, LOG_PARODUS_IF,
"Source is NULL or Dest is NULL or Payload is NULL \n");
406 sentNotification =
true;
408 if (sentNotification ==
false)
409 WAL_FREE(param->notifyPayload);
411 WAL_FREE(param->notifyDest);
414 WAL_FREE(notifyMsg->data);
431 RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,
"------------ validate_parameter ----------\n");
432 for (i = 0; i < paramCount; i++)
435 if(param[i].name[(strlen(param[i].name)-1)] ==
'.')
437 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Wildcard SET/SET-ATTRIBUTES is not supported \n");
438 return WDMP_ERR_WILDCARD_NOT_SUPPORTED;
441 if(strcmp(param[i].name, PARAM_CID) == 0 || strcmp(param[i].name, PARAM_CMC) == 0)
443 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Invalid Input parameter - CID/CMC value cannot be set \n");
444 return WDMP_ERR_SET_OF_CMC_OR_CID_NOT_SUPPORTED;
447 if(param[i].name == NULL || param[i].value == NULL)
449 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Parameter value is null\n");
450 return WDMP_ERR_VALUE_IS_NULL;
463 WDMP_STATUS *retReason = NULL;
464 param_t *rebootParam = NULL;
466 if(strcmp(param.name, WEBPA_DEVICE_REBOOT_PARAM) == 0 && strcmp(param.value, WEBPA_DEVICE_REBOOT_VALUE) == 0)
468 rebootParam = (param_t *) malloc(
sizeof(param_t));
469 retReason = (WDMP_STATUS *) malloc(
sizeof(WDMP_STATUS));
471 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"RDKB_REBOOT : Reboot triggered through WEBPA\n");
472 rebootParam[0].name = strdup(
"Device.DeviceInfo.X_RDKCENTRAL-COM_LastRebootReason");
473 rebootParam[0].value = strdup(
"webpa-reboot");
474 rebootParam[0].type = WDMP_STRING;
477 if(retReason[0] != WDMP_SUCCESS)
479 RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,
"Failed to set Reason with status %d\n",retReason[0]);
483 RDK_LOG(RDK_LOG_INFO,LOG_PARODUS_IF,
"Successfully set Reason with status %d\n",retReason[0]);
486 WAL_FREE(rebootParam);
497 clock_gettime(CLOCK_REALTIME, timer);