Skip to content

Commit

Permalink
Feat:WebPA Sync Notification handling during Factory reset cloud sync
Browse files Browse the repository at this point in the history
  • Loading branch information
nlrcomcast committed Nov 13, 2024
1 parent 039fa62 commit 0283c56
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
2 changes: 2 additions & 0 deletions source/broadband/include/webpa_notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,5 @@ WDMP_STATUS validate_webpa_notification_data(char *notify_param_name, char *writ

pthread_cond_t *get_global_sync_condition(void);
pthread_mutex_t *get_global_sync_mutex(void);

void FR_CloudSyncCheck();
53 changes: 50 additions & 3 deletions source/broadband/webpa_notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void sendNotificationForFactoryReset();
void sendNotificationForFirmwareUpgrade();
static WDMP_STATUS addOrUpdateFirmwareVerToConfigFile(char *value);
static WDMP_STATUS processParamNotification(ParamNotify *paramNotify, unsigned int *cmc, char **cid);
static WDMP_STATUS processParamNotificationRetry(unsigned int *cmc, char **cid);
static WDMP_STATUS getCmcCidValues(unsigned int *cmc, char **cid);
static void processConnectedClientNotification(NodeData *connectedNotify, char *deviceId, char **version, char ** nodeMacId, char **timeStamp, char **destination);
static WDMP_STATUS processFactoryResetNotification(ParamNotify *paramNotify, unsigned int *cmc, char **cid, char **reason);
static WDMP_STATUS processFirmwareUpgradeNotification(ParamNotify *paramNotify, unsigned int *cmc, char **cid);
Expand Down Expand Up @@ -1041,12 +1041,59 @@ static void addNotifyMsgToQueue(NotifyData *notifyData)
WalPrint("*****Returned from addNotifyMsgToQueue*****\n");
}

/*
* @brief To delay sync notifications until FR cloud sync is acknowledged by cloud with Test and Set request for max wait period of 60s
*/
void FR_CloudSyncCheck()
{
char *cid = NULL;
unsigned int cmc = 0;
int FR_cloud_sync_completed = false;
WDMP_STATUS ret = WDMP_FAILURE;

for(int i=0;i<12;i++)
{
ret = getCmcCidValues(&cmc, &cid);
if (ret != WDMP_SUCCESS)
{
WalError("Unable to get dbCID/CMC value in handleNotificationEvents\n");
}
else if ((strcmp(cid, "0") == 0) && cmc != 512) //To check whether the device is up after factory reset
{
WalInfo("factory reset cloud sync is in progress, wait 5sec for process sync notifications\n");
WAL_FREE(cid);
}
else
{
FR_cloud_sync_completed = true;
WAL_FREE(cid);
break;
}
sleep(5);
}

if(FR_cloud_sync_completed == false)
{
WalInfo("factory reset cloud sync is failed after 60sec, proceding sync notifications without FR cloud sync\n");
}else
{
WalInfo("cloud acknowledged for factory reset notification, proceeding for sync notifications\n");
}
}

/*
* @brief To monitor notification events in Notification queue
*/
static void handleNotificationEvents()
{
char *reboot_reason = NULL;
reboot_reason = getParameterValue(PARAM_REBOOT_REASON);
if( (NULL != reboot_reason) && (strcmp(reboot_reason,"factory-reset")==0) )
{
WAL_FREE(reboot_reason);
FR_CloudSyncCheck();
}

while(1)
{
pthread_mutex_lock (&mut);
Expand Down Expand Up @@ -1420,7 +1467,7 @@ void processNotification(NotifyData *notifyData)
case PARAM_NOTIFY_RETRY:
{
strcpy(dest, "event:SYNC_NOTIFICATION");
ret = processParamNotificationRetry(&cmc, &cid);
ret = getCmcCidValues(&cmc, &cid);
if (ret != WDMP_SUCCESS)
{
free(dest);
Expand Down Expand Up @@ -1522,7 +1569,7 @@ static WDMP_STATUS processParamNotification(ParamNotify *paramNotify,
return status;
}

static WDMP_STATUS processParamNotificationRetry(unsigned int *cmc, char **cid)
static WDMP_STATUS getCmcCidValues(unsigned int *cmc, char **cid)
{
char *dbCID = NULL, *dbCMC = NULL;

Expand Down

0 comments on commit 0283c56

Please sign in to comment.