-
Notifications
You must be signed in to change notification settings - Fork 49
/
webpa_notification.c
1999 lines (1807 loc) · 60.5 KB
/
webpa_notification.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file webpa_notification.c
*
* @description This file describes the Webpa Abstraction Layer
*
* Copyright (c) 2015 Comcast
*/
#include <pthread.h>
#include <math.h>
#include "webpa_notification.h"
#include "webpa_internal.h"
#ifdef RDKB_BUILD
#include <sysevent/sysevent.h>
#endif
#if defined(FEATURE_SUPPORT_WEBCONFIG)
#include <webcfg_generic.h>
#endif
/*----------------------------------------------------------------------------*/
/* Macros */
/*----------------------------------------------------------------------------*/
/* Notify Macros */
#define WEBPA_SET_INITIAL_NOTIFY_RETRY_COUNT 7
#define WEBPA_SET_INITIAL_NOTIFY_RETRY_SEC 15
#define WEBPA_NOTIFY_EVENT_HANDLE_INTERVAL_MSEC 250
#define BACKOFF_MAX_RETRY_SEC 512
#define WEBPA_NOTIFY_EVENT_MAX_LENGTH 256
#define MAX_REASON_LENGTH 64
#define WEBPA_PARAM_HOSTS_NAME "Device.Hosts.Host."
#define WRP_TRANSACTION_ID "transaction_uuid"
#define PARAM_HOSTS_VERSION "Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"
#define PARAM_SYSTEM_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_SystemTime"
#define PARAM_FIRMWARE_VERSION "Device.DeviceInfo.X_CISCO_COM_FirmwareName"
#define WEBPA_CFG_FIRMWARE_VER "oldFirmwareVersion"
#define DEVICE_BOOT_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_BootTime"
#define FP_PARAM "Device.DeviceInfo.X_RDKCENTRAL-COM_DeviceFingerPrint.Enable"
#define CLOUD_STATUS "cloud-status"
pthread_mutex_t sync_mutex=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t sync_condition=PTHREAD_COND_INITIALIZER;
/*----------------------------------------------------------------------------*/
/* Data Structures */
/*----------------------------------------------------------------------------*/
typedef struct NotifyMsg__
{
NotifyData *notifyData;
struct NotifyMsg__ *next;
} NotifyMsg;
typedef struct
{
char oldFirmwareVersion[256];
} WebPaCfg;
/*----------------------------------------------------------------------------*/
/* File Scoped Variables */
/*----------------------------------------------------------------------------*/
static NotifyMsg *notifyMsgQ = NULL;
void (*notifyCbFn)(NotifyData*) = NULL;
static WebPaCfg webPaCfg;
char deviceMAC[32]={'\0'};
int g_syncRetryThreadStarted = 0;
//This flag is used to avoid sync notification retry when param notification is already in progress.
int g_syncNotifyInProgress = 0;
//This flag is used to avoid CMC check when CPE and cloud are in sync.
int g_checkSyncNotifyRetry = 0;
#ifdef FEATURE_SUPPORT_WEBCONFIG
char *g_systemReadyTime=NULL;
#endif
pthread_mutex_t mut=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t con=PTHREAD_COND_INITIALIZER;
pthread_mutex_t device_mac_mutex = PTHREAD_MUTEX_INITIALIZER;
const char * notifyparameters[]={
"Device.NotifyComponent.X_RDKCENTRAL-COM_Connected-Client",
"Device.Bridging.Bridge.1.Port.8.Enable",
"Device.Bridging.Bridge.2.Port.2.Enable",
"Device.DeviceInfo.X_COMCAST_COM_xfinitywifiEnable",
"Device.WiFi.AccessPoint.10001.Security.ModeEnabled",
"Device.WiFi.AccessPoint.10001.Security.X_COMCAST-COM_KeyPassphrase",
"Device.WiFi.AccessPoint.10001.SSIDAdvertisementEnabled",
"Device.WiFi.AccessPoint.10001.X_CISCO_COM_MACFilter.Enable",
"Device.WiFi.AccessPoint.10001.X_CISCO_COM_MACFilter.FilterAsBlackList",
"Device.WiFi.AccessPoint.10101.Security.ModeEnabled",
"Device.WiFi.AccessPoint.10101.Security.X_COMCAST-COM_KeyPassphrase",
"Device.WiFi.AccessPoint.10101.SSIDAdvertisementEnabled",
"Device.WiFi.AccessPoint.10101.X_CISCO_COM_MACFilter.Enable",
"Device.WiFi.AccessPoint.10101.X_CISCO_COM_MACFilter.FilterAsBlackList",
"Device.WiFi.AccessPoint.10002.Security.ModeEnabled",
"Device.WiFi.AccessPoint.10002.Security.X_COMCAST-COM_KeyPassphrase",
"Device.WiFi.AccessPoint.10002.Security.KeyPassphrase",
"Device.WiFi.AccessPoint.10002.Security.PreSharedKey",
"Device.WiFi.AccessPoint.10102.Security.ModeEnabled",
"Device.WiFi.AccessPoint.10102.Security.X_COMCAST-COM_KeyPassphrase",
"Device.WiFi.AccessPoint.10102.Security.KeyPassphrase",
"Device.WiFi.AccessPoint.10102.Security.PreSharedKey",
"Device.WiFi.Radio.10000.Enable",
"Device.WiFi.Radio.10100.Enable",
"Device.WiFi.SSID.10001.Enable",
"Device.WiFi.SSID.10001.SSID",
"Device.WiFi.SSID.10101.Enable",
"Device.WiFi.SSID.10101.SSID",
"Device.WiFi.SSID.10002.Enable",
"Device.WiFi.SSID.10002.SSID",
"Device.WiFi.SSID.10102.Enable",
"Device.WiFi.SSID.10102.SSID",
"Device.X_CISCO_COM_DeviceControl.LanManagementEntry.1.LanMode",
"Device.X_CISCO_COM_Security.Firewall.FilterAnonymousInternetRequests",
"Device.X_CISCO_COM_Security.Firewall.FilterHTTP",
"Device.X_CISCO_COM_Security.Firewall.FilterIdent",
"Device.X_CISCO_COM_Security.Firewall.FilterMulticast",
"Device.X_CISCO_COM_Security.Firewall.FilterP2P",
"Device.X_CISCO_COM_Security.Firewall.FirewallLevel",
"Device.X_CISCO_COM_Security.Firewall.FilterAnonymousInternetRequestsV6",
"Device.X_CISCO_COM_Security.Firewall.FilterHTTPV6",
"Device.X_CISCO_COM_Security.Firewall.FilterIdentV6",
"Device.X_CISCO_COM_Security.Firewall.FilterMulticastV6",
"Device.X_CISCO_COM_Security.Firewall.FilterP2PV6",
"Device.X_CISCO_COM_Security.Firewall.FirewallLevelV6",
// Commenting this parameter to avoid PSM crash
//"Device.DHCPv4.Server.Enable",
"Device.X_CISCO_COM_DeviceControl.LanManagementEntry.1.LanIPAddress",
"Device.X_CISCO_COM_DeviceControl.LanManagementEntry.1.LanSubnetMask",
"Device.DHCPv4.Server.Pool.1.MinAddress",
"Device.DHCPv4.Server.Pool.1.MaxAddress",
"Device.DHCPv4.Server.Pool.1.LeaseTime",
// Commenting as some boxes may not have this parameter
//"Device.Routing.Router.1.IPv4Forwarding.1.GatewayIPAddress",
"Device.NAT.X_CISCO_COM_DMZ.Enable",
"Device.NAT.X_CISCO_COM_DMZ.InternalIP",
"Device.NAT.X_CISCO_COM_DMZ.IPv6Host",
"Device.NAT.X_Comcast_com_EnablePortMapping",
"Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.Mesh.Enable",
"Device.DeviceInfo.X_RDKCENTRAL-COM_DeviceFingerPrint.Enable",
"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.PrivacyProtection.Enable",
"Device.DeviceInfo.X_RDKCENTRAL-COM_PrivacyProtection.Activate",
"Device.DeviceInfo.X_RDKCENTRAL-COM_CloudUIEnable",
#ifndef _CBR_PRODUCT_REQ_
"Device.DeviceInfo.X_RDKCENTRAL-COM_AkerEnable",
#endif
#if ! defined(_HUB4_PRODUCT_REQ_) && ! defined(_CBR_PRODUCT_REQ_) && ! defined(_SCER11BEL_PRODUCT_REQ_) && ! defined(_XER5_PRODUCT_REQ_)
"Device.MoCA.Interface.1.Enable",
#endif
"Device.NotifyComponent.X_RDKCENTRAL-COM_PresenceNotification",
"Device.WiFi.X_CISCO_COM_FactoryResetRadioAndAp",
"Device.WiFi.SSID.10003.SSID",
"Device.WiFi.SSID.10103.SSID",
"Device.WiFi.SSID.10005.SSID",
"Device.WiFi.SSID.10105.SSID",
"Device.WiFi.SSID.10003.Status",
"Device.WiFi.SSID.10103.Status",
"Device.WiFi.SSID.10005.Status",
"Device.WiFi.SSID.10105.Status",
"Device.WiFi.AccessPoint.10003.SSIDAdvertisementEnabled",
"Device.WiFi.AccessPoint.10103.SSIDAdvertisementEnabled",
"Device.WiFi.AccessPoint.10005.SSIDAdvertisementEnabled",
"Device.WiFi.AccessPoint.10105.SSIDAdvertisementEnabled",
"Device.WiFi.AccessPoint.10003.Security.RadiusServerIPAddr",
"Device.WiFi.AccessPoint.10103.Security.RadiusServerIPAddr",
"Device.WiFi.AccessPoint.10005.Security.RadiusServerIPAddr",
"Device.WiFi.AccessPoint.10105.Security.RadiusServerIPAddr",
"Device.WiFi.SSID.10003.BSSID",
"Device.WiFi.SSID.10103.BSSID",
"Device.WiFi.SSID.10005.BSSID",
"Device.WiFi.SSID.10105.BSSID",
"Device.WiFi.AccessPoint.10003.Security.ModeEnabled",
"Device.WiFi.AccessPoint.10103.Security.ModeEnabled",
"Device.WiFi.AccessPoint.10005.Security.ModeEnabled",
"Device.WiFi.AccessPoint.10105.Security.ModeEnabled",
"Device.X_COMCAST-COM_GRE.Tunnel.1.PrimaryRemoteEndpoint",
"Device.X_COMCAST-COM_GRE.Tunnel.1.SecondaryRemoteEndpoint",
"Device.WiFi.Radio.10000.Channel",
"Device.WiFi.Radio.10100.Channel",
"Device.WiFi.Radio.10000.OperatingFrequencyBand",
"Device.WiFi.Radio.10100.OperatingFrequencyBand",
"Device.WiFi.Radio.10000.OperatingChannelBandwidth",
"Device.WiFi.Radio.10100.OperatingChannelBandwidth",
"Device.X_COMCAST-COM_GRE.Tunnel.1.Interface.1.VLANID",
"Device.X_COMCAST-COM_GRE.Tunnel.1.Interface.1.LocalInterfaces",
"Device.X_COMCAST-COM_GRE.Tunnel.1.Interface.2.VLANID",
"Device.X_COMCAST-COM_GRE.Tunnel.1.Interface.2.LocalInterfaces",
#ifdef _HUB4_PRODUCT_REQ_
"Device.NAT.X_CISCO_COM_PortTriggers.Enable",
"Device.UPnP.Device.UPnPIGD",
"Device.UserInterface.X_CISCO_COM_RemoteAccess.HttpEnable",
"Device.UserInterface.X_CISCO_COM_RemoteAccess.HttpsEnable",
#endif
#ifdef FEATURE_SUPPORT_6G_RADIO
"Device.WiFi.AccessPoint.10201.Security.ModeEnabled",
"Device.WiFi.AccessPoint.10201.Security.X_COMCAST-COM_KeyPassphrase",
"Device.WiFi.AccessPoint.10201.SSIDAdvertisementEnabled",
"Device.WiFi.AccessPoint.10201.X_CISCO_COM_MACFilter.Enable",
"Device.WiFi.AccessPoint.10201.X_CISCO_COM_MACFilter.FilterAsBlackList",
"Device.WiFi.AccessPoint.10202.Security.ModeEnabled",
"Device.WiFi.AccessPoint.10202.Security.X_COMCAST-COM_KeyPassphrase",
"Device.WiFi.AccessPoint.10202.Security.KeyPassphrase",
"Device.WiFi.AccessPoint.10202.Security.PreSharedKey",
"Device.WiFi.Radio.10200.Enable",
"Device.WiFi.SSID.10201.Enable",
"Device.WiFi.SSID.10201.SSID",
"Device.WiFi.SSID.10202.Enable",
"Device.WiFi.SSID.10202.SSID",
"Device.WiFi.SSID.10203.SSID",
"Device.WiFi.SSID.10205.SSID",
"Device.WiFi.SSID.10205.Status",
"Device.WiFi.SSID.10203.Status",
"Device.WiFi.AccessPoint.10203.SSIDAdvertisementEnabled",
"Device.WiFi.AccessPoint.10205.SSIDAdvertisementEnabled",
"Device.WiFi.AccessPoint.10203.Security.RadiusServerIPAddr",
"Device.WiFi.AccessPoint.10205.Security.RadiusServerIPAddr",
"Device.WiFi.SSID.10203.BSSID",
"Device.WiFi.SSID.10205.BSSID",
"Device.WiFi.AccessPoint.10203.Security.ModeEnabled",
"Device.WiFi.AccessPoint.10205.Security.ModeEnabled",
"Device.WiFi.Radio.10200.Channel",
"Device.WiFi.Radio.10200.OperatingFrequencyBand",
"Device.WiFi.Radio.10200.OperatingChannelBandwidth",
#endif
/* Always keep AdvancedSecurity parameters as the last parameters in notify list as these have to be removed if cujo/fp is not enabled. */
"Device.DeviceInfo.X_RDKCENTRAL-COM_AdvancedSecurity.SafeBrowsing.Enable",
"Device.DeviceInfo.X_RDKCENTRAL-COM_AdvancedSecurity.Softflowd.Enable"
};
/*----------------------------------------------------------------------------*/
/* Function Prototypes */
/*----------------------------------------------------------------------------*/
void loadCfgFile();
static int writeToJson(char *data);
static PARAMVAL_CHANGE_SOURCE mapWriteID(unsigned int writeID);
static void *notifyTask(void *status);
void *FactoryResetCloudSync();
static void notifyCallback(NotifyData *notifyData);
static void addNotifyMsgToQueue(NotifyData *notifyData);
static void handleNotificationEvents();
static void freeNotifyMessage(NotifyData *notifyData);
static void getNotifyParamList(const char ***paramList,int *size);
void processNotification(NotifyData *notifyData);
void sendNotificationForFactoryReset();
void sendNotificationForFirmwareUpgrade();
static WDMP_STATUS addOrUpdateFirmwareVerToConfigFile(char *value);
static WDMP_STATUS processParamNotification(ParamNotify *paramNotify, 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);
void processDeviceStatusNotification(int status);
static void mapComponentStatusToGetReason(COMPONENT_STATUS status, char *reason);
void getDeviceMac();
void SyncNotifyRetryTask();
void *SyncNotifyRetry();
/*----------------------------------------------------------------------------*/
/* External Functions */
/*----------------------------------------------------------------------------*/
void initNotifyTask(int status)
{
int err = 0;
pthread_t threadId;
notifyMsgQ = NULL;
int *device_status = (int *) malloc(sizeof(int));
*device_status = status;
err = pthread_create(&threadId, NULL, notifyTask, (void *) device_status);
if (err != 0)
{
WalError("Error creating notifyTask thread :[%s]\n", strerror(err));
}
else
{
WalPrint("notifyTask Thread created Successfully\n");
}
}
#ifdef FEATURE_SUPPORT_WEBCONFIG
char *get_global_systemReadyTime()
{
return g_systemReadyTime;
}
#endif
void FactoryResetCloudSyncTask()
{
int err = 0;
pthread_t threadId;
err = pthread_create(&threadId, NULL, FactoryResetCloudSync, NULL);
if (err != 0)
{
WalError("Error creating FactoryResetCloudSync thread :[%s]\n", strerror(err));
}
else
{
WalInfo("FactoryResetCloudSync Thread created Successfully\n");
}
}
void *FactoryResetCloudSync()
{
pthread_detach(pthread_self());
char *dbCID = NULL;
int retryCount = 0;
int status = 0;
int backoffRetryTime = 0;
int c=120;
while(FOREVER())
{
if(retryCount < FACTORY_RESET_NOTIFY_MAX_RETRY_COUNT)
{
if(status < 0)
{
WalError("Failed to get cloud-status from parodus. Retrying after %d seconds\n", BACKOFF_MAX_RETRY_SEC);
sleep(BACKOFF_MAX_RETRY_SEC);
}
else
{
backoffRetryTime = (int) (1 << retryCount)*c+1;
//wait for backoff delay for retransmission
WalInfo("Wait for backoffRetryTime %d sec for retransmission\n", backoffRetryTime);
sleep(backoffRetryTime);
}
//check cloud-status
WalPrint("check cloud-status\n");
status = getConnCloudStatus(deviceMAC);
WalPrint("getConnCloudStatus : status returned is %d\n", status);
if(status==1)
{
//check CID
WalPrint("check CID \n");
dbCID = getParameterValue(PARAM_CID);
if(dbCID == NULL)
{
WalError("Unable to get dbCID value\n");
return NULL;
}
if (dbCID != NULL && strcmp(dbCID, "0") == 0)
{
WalInfo("dbCID value is %s\n", dbCID);
//sendFactoryreset notification for cloud CPE sync
WalPrint("sendNotificationForFactoryReset\n");
NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData));
memset(notifyData,0,sizeof(NotifyData));
notifyData->type = FACTORY_RESET;
processNotification(notifyData);
retryCount++;
}
else
{
WalInfo("dbCID has non-zero value\n");
retryCount = 0;
WAL_FREE(dbCID);
break;
}
WAL_FREE(dbCID);
WalInfo("Factory reset notify retryCount is %d\n", retryCount);
}
}
else
{
WalError("Max Retransmission limit reached for Factory Reset Notification\n");
break;
}
}
return NULL;
}
void SyncNotifyRetryTask()
{
int err = 0;
pthread_t threadId;
err = pthread_create(&threadId, NULL, SyncNotifyRetry, NULL);
if (err != 0)
{
WalError("Error creating SyncNotifyRetry thread :[%s]\n", strerror(err));
}
else
{
WalInfo("SyncNotifyRetry Thread created Successfully\n");
g_syncRetryThreadStarted = 1;
}
}
void *SyncNotifyRetry()
{
pthread_detach(pthread_self());
char *dbCMC = NULL;
int backoffRetryTime = 0;
int backoff_max_time = 9;
struct timespec ts;
int c = 3;
int rv;
int max_retry_sleep = (int) pow(2, backoff_max_time) -1;
WalInfo("SyncNotifyRetry: max_retry_sleep is %d\n", max_retry_sleep );
while(FOREVER())
{
if(backoffRetryTime < max_retry_sleep)
{
backoffRetryTime = (int) pow(2, c) -1;
}
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += backoffRetryTime;
//wait for backoff delay for retransmission
if(g_checkSyncNotifyRetry == 1)
{
WalInfo("Wait for backoffRetryTime %d sec to check sync notification retry\n", backoffRetryTime);
}
rv = pthread_cond_timedwait(&sync_condition, &sync_mutex, &ts);
if (rv == 0)
{
WalInfo("Received connection online event signal for retrying sync notification.\n");
}
else if (rv == ETIMEDOUT)
{
WalPrint("SyncNotifyRetry thread: Timeout occurred.\n");
}
else
{
WalError("SyncNotifyRetry thread: Error occurred: %d\n", rv);
continue;
}
if(g_syncNotifyInProgress == 1)
{
WalInfo("PARAM_NOTIFY is in progress\n");
continue;
}
if(g_checkSyncNotifyRetry || (rv == 0))
{
dbCMC = getParameterValue(PARAM_CMC);
}
else
{
WalPrint("g_checkSyncNotifyRetry is 0 and skip dbCMC sync checking\n");
continue;
}
if(NULL == dbCMC)
{
WalError("SyncNotifyRetry thread: dbCMC is Null\n");
continue;
}
if(strcmp(dbCMC,"512"))
{
//Retry sending sync notification to cloud
WalInfo("Retrying sync notification as cloud and CPE are out of sync, dbCMC is %s\n", dbCMC);
NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData) * 1);
if(notifyData != NULL)
{
memset(notifyData,0,sizeof(NotifyData));
notifyData->type = PARAM_NOTIFY_RETRY;
processNotification(notifyData);
}
WalPrint("After Sending processNotification\n");
c++;
if(backoffRetryTime == max_retry_sleep)
{
c = 3;
backoffRetryTime = 0;
WalPrint("backoffRetryTime reached max value, reseting to initial value\n");
}
}
else
{
g_checkSyncNotifyRetry = 0;
WalInfo("CMC is equal to 512, cloud and CPE are in sync\n");
WalInfo("g_checkSyncNotifyRetry is set to 0\n");
c = 3;
backoffRetryTime = 0;
WalPrint("CMC is 512, reseting backoffRetryTime to initial value\n");
}
WAL_FREE(dbCMC);
}
return NULL;
}
void ccspWebPaValueChangedCB(parameterSigStruct_t* val, int size, void* user_data)
{
WalPrint("Inside CcspWebpaValueChangedCB\n");
ParamNotify *paramNotify;
if (NULL == notifyCbFn)
{
WalError("Fatal: ccspWebPaValueChangedCB() notifyCbFn is NULL\n");
return;
}
g_syncNotifyInProgress = 1;
g_checkSyncNotifyRetry = 1;
WalInfo("set g_syncNotifyInProgress, g_checkSyncNotifyRetry to 1\n");
paramNotify= (ParamNotify *) malloc(sizeof(ParamNotify));
paramNotify->paramName = val->parameterName;
paramNotify->oldValue= val->oldValue;
paramNotify->newValue = val->newValue;
paramNotify->type = val->type;
paramNotify->changeSource = mapWriteID(val->writeID);
NotifyData *notifyDataPtr = (NotifyData *) malloc(sizeof(NotifyData) * 1);
notifyDataPtr->type = PARAM_NOTIFY;
notifyDataPtr->u.notify = paramNotify;
WalInfo("Notification Event from stack: Parameter Name: %s, Data Type: %d, Change Source: %d\n", paramNotify->paramName, paramNotify->type, paramNotify->changeSource);
(*notifyCbFn)(notifyDataPtr);
}
int RegisterNotifyCB(notifyCB cb)
{
notifyCbFn = cb;
return 1;
}
void * getNotifyCB()
{
WalPrint("Inside getNotifyCB\n");
return notifyCbFn;
}
void processTransactionNotification(char transId[])
{
WalPrint("processTransactionNotification\n");
if (NULL == notifyCbFn)
{
WalError("Fatal: notifyCbFn is NULL\n");
return;
}
else
{
WalPrint("transId : %s\n",transId);
WalPrint("Allocate memory to NotifyData \n");
NotifyData *notifyDataPtr = (NotifyData *) malloc(sizeof(NotifyData) * 1);
memset(notifyDataPtr,0,sizeof(NotifyData));
notifyDataPtr->type = TRANS_STATUS;
notifyDataPtr->u.status = (TransData*) malloc(sizeof(TransData));
notifyDataPtr->u.status->transId = (char *)malloc(sizeof(char) * (strlen(transId)+1));
walStrncpy(notifyDataPtr->u.status->transId, transId, (strlen(transId)+1));
WalPrint("notifyDataPtr->u.status->transId : %s\n",notifyDataPtr->u.status->transId);
(*notifyCbFn)(notifyDataPtr);
}
}
void sendConnectedClientNotification(char * macId, char *status, char *interface, char *hostname)
{
NotifyData *notifyDataPtr = (NotifyData *) malloc(sizeof(NotifyData) * 1);
NodeData * node = NULL;
notifyDataPtr->type = CONNECTED_CLIENT_NOTIFY;
if(macId != NULL && status != NULL && interface != NULL && hostname != NULL)
{
node = (NodeData *) malloc(sizeof(NodeData) * 1);
memset(node, 0, sizeof(NodeData));
WalPrint("macId : %s status : %s interface : %s hostname :%s\n",macId,status, interface, hostname);
node->nodeMacId = (char *)(malloc(sizeof(char) * strlen(macId) + 1));
strncpy(node->nodeMacId, macId, strlen(macId) + 1);
node->status = (char *)(malloc(sizeof(char) * strlen(status) + 1));
strncpy(node->status, status, strlen(status) + 1);
node->interface = (char *)(malloc(sizeof(char) * strlen(interface) + 1));
strncpy(node->interface, interface, strlen(interface) + 1);
node->hostname = (char *)(malloc(sizeof(char) * strlen(hostname) + 1));
strncpy(node->hostname, hostname, strlen(hostname) + 1);
WalPrint("node->nodeMacId : %s node->status: %s node->interface: %s node->hostname: %s\n",node->nodeMacId,node->status, node->interface, node->hostname);
}
notifyDataPtr->u.node = node;
(*notifyCbFn)(notifyDataPtr);
}
void processDeviceManageableNotification()
{
struct timespec cTime;
char systemReadyTime[32];
int ret = -1;
memset(systemReadyTime, 0, sizeof(systemReadyTime));
getCurrentTime(&cTime);
snprintf(systemReadyTime,sizeof(systemReadyTime),"%d",(int)cTime.tv_sec);
WalInfo("systemReadyTime is %s\n",systemReadyTime);
#ifdef FEATURE_SUPPORT_WEBCONFIG
//To access systemReadyTime in webConfig through getter function.
g_systemReadyTime = strdup(systemReadyTime);
#endif
ret = setParameterValue("Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.DeviceManageableNotification", systemReadyTime, WDMP_STRING);
if(ret == WDMP_SUCCESS)
{
WalInfo("Device manageable notification processed\n");
}
}
/*----------------------------------------------------------------------------*/
/* Internal functions */
/*----------------------------------------------------------------------------*/
/*
* @brief loadCfgFile To load the config file.
*/
void loadCfgFile()
{
FILE *fp;
cJSON *webpa_cfg = NULL;
char *cfg_file_content = NULL, *temp_ptr = NULL;
int ch_count = 0;
int flag = 0;
size_t sz;
fp = fopen(WEBPA_CFG_FILE, "r");
if (fp == NULL)
{
WalError("Failed to open cfg file in read mode creating new file %s\n", WEBPA_CFG_FILE);
fp = fopen(WEBPA_CFG_FILE, "w");
if (fp == NULL)
{
WalError("Failed to create cfg file %s\n", WEBPA_CFG_FILE);
return;
}
flag = 1;
fprintf(fp, "{\n}");
}
fseek(fp, 0, SEEK_END);
ch_count = ftell(fp);
if (ch_count == (int)-1)
{
WalError("fread failed.\n");
fclose(fp);
return WDMP_FAILURE;
}
fseek(fp, 0, SEEK_SET);
cfg_file_content = (char *) malloc(sizeof(char) * (ch_count + 1));
sz = fread(cfg_file_content, 1, ch_count,fp);
if (sz == 0 && ferror(fp))
{
fclose(fp);
WalError("fread failed.\n");
WAL_FREE(cfg_file_content);
return WDMP_FAILURE;
}
cfg_file_content[ch_count] ='\0';
WalPrint("cfg_file_content : \n%s\n",cfg_file_content);
fclose(fp);
if(flag == 0)
{
webpa_cfg = cJSON_Parse(cfg_file_content);
if(webpa_cfg)
{
WalPrint("**********Loading Webpa Config***********\n");
if(cJSON_GetObjectItem(webpa_cfg, WEBPA_CFG_FIRMWARE_VER) != NULL)
{
temp_ptr = cJSON_GetObjectItem(webpa_cfg, WEBPA_CFG_FIRMWARE_VER)->valuestring;
strncpy(webPaCfg.oldFirmwareVersion, temp_ptr, strlen(temp_ptr)+1);
WalPrint("oldFirmwareVersion : %s\n", webPaCfg.oldFirmwareVersion);
}
else
{
strcpy(webPaCfg.oldFirmwareVersion,"");
}
}
else
{
WalError("Error parsing WebPA config file. Replace it with empty json\n");
/* replace corrupted config file with empty json of content {}. This file will get added/updated from addOrUpdateFirmwareVerToConfigFile to send firmware upgrade notification */
fp = fopen(WEBPA_CFG_FILE, "w");
if (fp == NULL)
{
WalError("WEBPA_CFG_FILE is empty \n");
return;
}
fprintf(fp, "{}");
fclose(fp);
}
}
free(cfg_file_content);
}
/**
* @brief getNotifyParamList Get notification parameters from intial NotifList
* returns notif parameter names and size of list
*
* @param[inout] paramList Initial Notif parameters list
* @param[inout] size Notif List array size
*/
static void getNotifyParamList(const char ***paramList, int *size)
{
int removeFlag = 0, count = 0, i = 0, fpRemoveFlag = 0;
count = sizeof(notifyparameters)/sizeof(notifyparameters[0]);
#ifdef RDKB_BUILD
char *fpEnable = NULL;
fpEnable = getParameterValue(FP_PARAM);
if(fpEnable != NULL && strncmp(fpEnable, "true", strlen("true")) == 0)
{
WalInfo("Device fingerprint/cujo is enabled\n");
removeFlag = 1;
}
else
{
if(fpEnable != NULL && strncmp(fpEnable, "false", strlen("false")) == 0)
{
WalInfo("Device fingerprint/cujo is disabled\n");
fpRemoveFlag = 1;
}
char meshEnable[64];
memset(meshEnable, 0, sizeof(meshEnable));
if(syscfg_get( NULL, "mesh_enable", meshEnable, sizeof(meshEnable))!=0)
WalError("syscfg_get failed\n");
if(meshEnable[0] != '\0' && strncmp(meshEnable, "true", strlen("true")) == 0)
{
WalInfo("Mesh/plume is enabled\n");
removeFlag = 1;
}
}
WAL_FREE(fpEnable);
if(removeFlag == 1)
{
WalInfo("Removing %s from notification list\n", notifyparameters[0]);
for(i = 1; i<count; i++)
{
notifyparameters[i-1] = notifyparameters[i];
}
count = count-1;
}
// Remove Advanced Security params from NotifyList when cujo/fp is not enabled.
if(fpRemoveFlag == 1)
{
WalInfo("Fingerprint/cujo is disabled. Removing Advanced Security parameters from notification list\n");
count = count-2;
}
#endif
*size = count;
WalPrint("Notify param list size :%d\n", *size);
*paramList = notifyparameters;
}
/**
* @brief To turn on notification for the parameters extracted from the notifyList of the config file.
*/
static void setInitialNotify()
{
WalPrint("***************Inside setInitialNotify*****************\n");
int i = 0, isError = 0, retry = 0;
char notif[20] = "";
const char **notifyparameters = NULL;
int notifyListSize = 0;
int backoffRetryTime = 0;
int backoff_max_time = 10;
int max_retry_sleep;
//Retry Backoff count will start at c=2 & calculate 2^c - 1.
int c = 2;
max_retry_sleep = (int) pow(2, backoff_max_time) -1;
WalInfo("setInitialNotify max_retry_sleep is %d\n", max_retry_sleep );
getNotifyParamList(¬ifyparameters, ¬ifyListSize);
//notifyparameters is empty for webpa-video
if (notifyparameters != NULL)
{
int *setInitialNotifStatus = (int *) malloc(
sizeof(int) * notifyListSize);
WDMP_STATUS ret = WDMP_FAILURE;
param_t *attArr = NULL;
for (i = 0; i < notifyListSize; i++)
{
setInitialNotifStatus[i] = 0;
}
do
{
if(backoffRetryTime < max_retry_sleep)
{
backoffRetryTime = (int) pow(2, c) - 1;
}
WalPrint("setInitialNotify backoffRetryTime calculated as %d seconds\n", backoffRetryTime);
isError = 0;
WalPrint("notify List Size: %d\n", notifyListSize);
attArr = (param_t *) malloc(sizeof(param_t));
for (i = 0; i < notifyListSize; i++)
{
if (setInitialNotifStatus[i] == 0)
{
snprintf(notif, sizeof(notif), "%d", 1);
attArr[0].value = (char *) malloc(sizeof(char) * 20);
walStrncpy(attArr[0].value, notif, 20);
attArr[0].name = (char *) notifyparameters[i];
attArr[0].type = WDMP_INT;
WalPrint("notifyparameters[%d]: %s\n", i,notifyparameters[i]);
setAttributes(attArr, 1, NULL, &ret);
if (ret != WDMP_SUCCESS)
{
isError = 1;
setInitialNotifStatus[i] = 0;
WalError("Failed to turn notification ON for parameter : %s ret: %d Attempt Number: %d\n",
notifyparameters[i], ret, retry + 1);
}
else
{
setInitialNotifStatus[i] = 1;
WalInfo("Successfully set notification ON for parameter : %s ret: %d\n",notifyparameters[i], ret);
}
WAL_FREE(attArr[0].value);
}
}
WAL_FREE(attArr);
if (isError == 0)
{
WalInfo("Successfully set initial notifications\n");
break;
}
WalInfo("setInitialNotify backoffRetryTime %d seconds, retry:%d\n", backoffRetryTime, retry);
sleep(backoffRetryTime);
c++;
if(backoffRetryTime == 127) // after 127s backoff delay, next delay will be 2^10 - 1 = 1023s i.e. > 15mins
{
c = 10; // skip c = 8,9
WalInfo("setInitialNotify backoffRetryTime reached 127s, wait for more than 15mins for next retry\n");
}
else if(backoffRetryTime == max_retry_sleep)
{
c = 2;
backoffRetryTime = 0;
WalInfo("setInitialNotify backoffRetryTime reached max value, reseting to initial value\n");
}
} while (retry++ < WEBPA_SET_INITIAL_NOTIFY_RETRY_COUNT);
WAL_FREE(setInitialNotifStatus);
WalPrint("**********************End of setInitial Notify************************\n");
}
else
{
WalError("Initial Notification list is empty\n");
}
}
/**
* @brief mapWriteID maps write id and returns change source
*
* @param[in] writeID
*/
static PARAMVAL_CHANGE_SOURCE mapWriteID(unsigned int writeID)
{
PARAMVAL_CHANGE_SOURCE source;
WalPrint("WRITE ID is %d\n", writeID);
switch(writeID)
{
case CCSP_COMPONENT_ID_ACS:
source = CHANGED_BY_ACS;
break;
case CCSP_COMPONENT_ID_WebPA:
source = CHANGED_BY_WEBPA;
break;
case CCSP_COMPONENT_ID_XPC:
source = CHANGED_BY_XPC;
break;
case DSLH_MPA_ACCESS_CONTROL_CLIENTTOOL:
source = CHANGED_BY_CLI;
break;
case CCSP_COMPONENT_ID_SNMP:
source = CHANGED_BY_SNMP;
break;
case CCSP_COMPONENT_ID_WebUI:
source = CHANGED_BY_WEBUI;
break;
default:
source = CHANGED_BY_UNKNOWN;
break;
}
WalInfo("CMC/component_writeID is: %d\n", source);
return source;
}
#ifdef FEATURE_SUPPORT_WEBCONFIG
char* get_deviceMAC()
{
if(strlen(deviceMAC) == 0)
{
WalInfo("deviceMAC is empty. getDeviceMac\n");
getDeviceMac();
}
return deviceMAC;
}
#endif
void getDeviceMac()
{
char *macID = NULL;
char deviceMACValue[32] = { '\0' };
int retryCount = 0;
int backoffRetryTime = 0;
int c=2;
if(strlen(deviceMAC) == 0)
{
do
{
backoffRetryTime = (int) pow(2, c) -1;
#ifdef RDKB_BUILD
token_t token;
int fd = s_sysevent_connect(&token);
if(WDMP_SUCCESS == check_ethernet_wan_status() && sysevent_get(fd, token, "eth_wan_mac", deviceMACValue, sizeof(deviceMACValue)) == 0 && deviceMACValue[0] != '\0')
{
pthread_mutex_lock(&device_mac_mutex);
macToLower(deviceMACValue, deviceMAC);
WalInfo("deviceMAC is %s\n", deviceMAC);
}
else
#endif
{
pthread_mutex_lock(&device_mac_mutex);
macID = getParameterValue(DEVICE_MAC);
if (macID != NULL)
{
strncpy(deviceMACValue, macID, strlen(macID)+1);
macToLower(deviceMACValue, deviceMAC);
WalInfo("deviceMAC: %s\n",deviceMAC);
WAL_FREE(macID);
}
}
if(strlen(deviceMAC) == 0)
{
WalError("Failed to GetValue for MAC. Retrying...\n");
pthread_mutex_unlock(&device_mac_mutex);
WalInfo("backoffRetryTime %d seconds\n", backoffRetryTime);
sleep(backoffRetryTime);
c++;
retryCount++;
}
else
{
pthread_mutex_unlock(&device_mac_mutex);
break;
}
}while((retryCount >= 1) && (retryCount <= 5));
}
}
/*
* @brief To handle notification tasks
*/
static void *notifyTask(void *status)
{
pthread_detach(pthread_self());
getDeviceMac();
loadCfgFile();
processDeviceStatusNotification(*(int *)status);
RegisterNotifyCB(¬ifyCallback);
sendNotificationForFactoryReset();
WalInfo("Registered notifyCallback, create /tmp/webpanotifyready file\n");
system("touch /tmp/webpanotifyready");
FactoryResetCloudSyncTask();
sendNotificationForFirmwareUpgrade();
setInitialNotify();
handleNotificationEvents();
WAL_FREE(status);
WalPrint("notifyTask ended!\n");
return NULL;
}
/*
* @brief notifyCallback is to check if notification event needs to be sent
* @param[in] paramNotify parameters to be notified .
*/
static void notifyCallback(NotifyData *notifyData)
{
addNotifyMsgToQueue(notifyData);
}
/*
* @brief To add Notification message to queue
*/
static void addNotifyMsgToQueue(NotifyData *notifyData)
{