-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathreportprofiles.c
More file actions
1517 lines (1343 loc) · 47.6 KB
/
reportprofiles.c
File metadata and controls
1517 lines (1343 loc) · 47.6 KB
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
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2019 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <dirent.h>
#include <stddef.h>
#include <limits.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "reportprofiles.h"
#include "xconfclient.h"
#include "t2collection.h"
#include "persistence.h"
#include "t2log_wrapper.h"
#include "profile.h"
#include "profilexconf.h"
#include "t2eventreceiver.h"
#if defined(CCSP_SUPPORT_ENABLED)
#include "t2_custom.h"
#endif
#include "scheduler.h"
#include "t2markers.h"
#include "datamodel.h"
#include "msgpack.h"
#include "busInterface.h"
#include "t2parser.h"
#include "telemetry2_0.h"
#include "t2MtlsUtils.h"
#include "persistence.h"
#ifdef LIBRDKCERTSEL_BUILD
#include "curlinterface.h"
#endif
#if defined(PRIVACYMODES_CONTROL)
#include "rdkservices_privacyutils.h"
#endif
#include "dcautil.h"
//Including Webconfig Framework For Telemetry 2.0 As part of RDKB-28897
#define SUBDOC_COUNT 1
#define SUBDOC_NAME "telemetry"
#if defined(ENABLE_RDKB_SUPPORT)
#define WEBCONFIG_BLOB_VERSION "/nvram/telemetry_webconfig_blob_version.txt"
#elif defined(DEVICE_EXTENDER)
#define WEBCONFIG_BLOB_VERSION "/usr/opensync/data/telemetry_webconfig_blob_version.txt"
#else
#define WEBCONFIG_BLOB_VERSION "/opt/telemetry_webconfig_blob_version.txt"
#endif
//Used in check_component_crash to inform Webconfig about telemetry component crash
#define TELEMETRY_INIT_FILE_BOOTUP "/tmp/telemetry_initialized_bootup"
#define MAX_PROFILENAMES_LENGTH 2048
#define T2_VERSION_DATAMODEL_PARAM "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Telemetry.Version"
//Timeout per profile for webconfig
#define MAXTIMEOUT_PERPROFILE 30
#if defined(DROP_ROOT_PRIV)
#include "cap.h"
static cap_user appcaps;
#endif
static BulkData bulkdata;
static bool rpInitialized = false;
static char *t2Version = NULL;
pthread_mutex_t rpMutex = PTHREAD_MUTEX_INITIALIZER;
T2ERROR RemovePreRPfromDisk(const char* path, hash_map_t *map);
static bool isT2MtlsEnable = false;
static bool initT2MtlsEnable = false;
struct rusage pusage;
unsigned int profilemem = 0;
bool previousLogCheck = false;
#if defined(DROP_ROOT_PRIV)
static void drop_root()
{
appcaps.caps = NULL;
appcaps.user_name = NULL;
T2Info("NonRoot feature is enabled, dropping root privileges for Telemetry 2.0 Process\n");
init_capability();
drop_root_caps(&appcaps);
if(update_process_caps(&appcaps) != -1)//CID 281096: Unchecked return value (CHECKED_RETURN)
{
read_capability(&appcaps);
}
}
#endif
#if defined(FEATURE_SUPPORT_WEBCONFIG)
uint32_t getTelemetryBlobVersion(char* subdoc)
{
T2Debug("Inside getTelemetryBlobVersion subdoc %s \n", subdoc);
uint32_t version = 0, ret = 0;
FILE *file = NULL;
file = fopen(WEBCONFIG_BLOB_VERSION, "r+");
if(file == NULL)
{
T2Debug("Failed to read from /nvram/telemetry_webconfig_blob_version.txt \n");
}
else
{
/* CID 157387: Unchecked return value from library */
if ((ret = fscanf(file, "%u", &version)) != 1)
{
T2Debug("Failed to read version from /nvram/telemetry_webconfig_blob_version.txt \n");
}
T2Debug("Version of Telemetry blob is %u\n", version);
fclose(file);
return version;
}
return 0;
}
int setTelemetryBlobVersion(char* subdoc, uint32_t version)
{
T2Debug("Inside setTelemetryBlobVersion subdoc %s version %u \n", subdoc, version);
FILE* file = NULL;
file = fopen(WEBCONFIG_BLOB_VERSION, "w+");
if(file != NULL)
{
fprintf(file, "%u", version);
T2Debug("New Version of Telemetry blob is %u\n", version);
fclose(file);
return 0;
}
else
{
T2Error("Failed to write into /nvram/telemetry_webconfig_blob_version \n");
}
return -1;
}
int tele_web_config_init()
{
char *sub_docs[SUBDOC_COUNT + 1] = {SUBDOC_NAME, (char *) 0 };
blobRegInfo *blobData = NULL, *blobDataPointer = NULL;
int i;
blobData = (blobRegInfo*) malloc(SUBDOC_COUNT * sizeof(blobRegInfo));
if (blobData == NULL)
{
T2Error("%s: Malloc error\n", __FUNCTION__);
return -1;
}
memset(blobData, 0, SUBDOC_COUNT * sizeof(blobRegInfo));
blobDataPointer = blobData;
for (i = 0 ; i < SUBDOC_COUNT; i++)
{
strncpy(blobDataPointer->subdoc_name, sub_docs[i], sizeof(blobDataPointer->subdoc_name) - 1);
blobDataPointer++;
}
blobDataPointer = blobData;
getVersion versionGet = getTelemetryBlobVersion;
setVersion versionSet = setTelemetryBlobVersion;
T2Debug("Calling Call Back Function \n");
register_sub_docs(blobData, SUBDOC_COUNT, versionGet, versionSet);
T2Debug("Called register_sub_docs Succussfully \n");
return 0;
}
#endif // CCSP_SUPPORT_ENABLED
void ReportProfiles_Interrupt()
{
T2Debug("%s ++in\n", __FUNCTION__);
// Interrupt the multi profile first as the DCADONE Flag is added from the xconf
sendLogUploadInterruptToScheduler();
char* xconfProfileName = NULL ;
if (ProfileXConf_isSet())
{
xconfProfileName = ProfileXconf_getName();
if (xconfProfileName)
{
SendInterruptToTimeoutThread(xconfProfileName);
free(xconfProfileName);
}
}
T2Debug("%s --out\n", __FUNCTION__);
}
void ReportProfiles_TimeoutCb(char* profileName, bool isClearSeekMap)
{
T2Info("%s ++in\n", __FUNCTION__);
T2Info("calling ProfileXConf_isNameEqual function form %s and line %d\n", __FUNCTION__, __LINE__);
if(ProfileXConf_isNameEqual(profileName))
{
T2Debug("isclearSeekmap = %s \n", isClearSeekMap ? "true" : "false");
ProfileXConf_notifyTimeout(isClearSeekMap, false);
}
else
{
T2Debug("isclearSeekmap = %s \n", isClearSeekMap ? "true" : "false");
NotifyTimeout(profileName, isClearSeekMap);
}
T2Info("%s --out\n", __FUNCTION__);
}
void ReportProfiles_ActivationTimeoutCb(char* profileName)
{
T2Info("%s ++in\n", __FUNCTION__);
bool isDeleteRequired = false;
T2Debug("calling ProfileXConf_isNameEqual function form %s and line %d\n", __FUNCTION__, __LINE__);
if(ProfileXConf_isNameEqual(profileName))
{
T2Error("ActivationTimeout received for Xconf profile. Ignoring!!!! \n");
}
else
{
if (T2ERROR_SUCCESS != disableProfile(profileName, &isDeleteRequired))
{
T2Error("Failed to disable profile after timeout: %s \n", profileName);
return;
}
if (isDeleteRequired)
{
removeProfileFromDisk(REPORTPROFILES_PERSISTENCE_PATH, profileName);
}
if (T2ERROR_SUCCESS != deleteProfile(profileName))
{
T2Error("Failed to delete profile after timeout: %s \n", profileName);
}
T2ER_StopDispatchThread();
clearT2MarkerComponentMap();
if(ProfileXConf_isSet())
{
ProfileXConf_updateMarkerComponentMap();
}
updateMarkerComponentMap();
/* Restart DispatchThread */
if (ProfileXConf_isSet() || getProfileCount() > 0)
{
T2ER_StartDispatchThread();
}
}
T2Info("%s --out\n", __FUNCTION__);
}
T2ERROR ReportProfiles_storeMarkerEvent(char *profileName, T2Event *eventInfo)
{
T2Debug("%s ++in\n", __FUNCTION__);
T2Debug("calling ProfileXConf_isNameEqual function form %s and line %d\n", __FUNCTION__, __LINE__);
if(ProfileXConf_isNameEqual(profileName))
{
ProfileXConf_storeMarkerEvent(eventInfo);
}
else
{
Profile_storeMarkerEvent(profileName, eventInfo);
}
T2Debug("%s --out\n", __FUNCTION__);
return T2ERROR_SUCCESS;
}
T2ERROR ReportProfiles_setProfileXConf(ProfileXConf *profile)
{
T2Debug("%s ++in\n", __FUNCTION__);
if(T2ERROR_SUCCESS != ProfileXConf_set(profile))
{
T2Error("Failed to set XConf profile\n");
return T2ERROR_FAILURE;
}
T2ER_StopDispatchThread();
// un-register and re-register Component Event List
// This is done to support any new components added for events
if(isRbusEnabled())
{
unregisterDEforCompEventList();
createComponentDataElements();
publishEventsProfileUpdates();
}
T2ER_StartDispatchThread();
T2Debug("%s --out\n", __FUNCTION__);
return T2ERROR_SUCCESS;
}
T2ERROR ReportProfiles_deleteProfileXConf(ProfileXConf *profile)
{
T2Debug("%s ++in\n", __FUNCTION__);
if(ProfileXConf_isSet())
{
T2ER_StopDispatchThread();
clearT2MarkerComponentMap();
updateMarkerComponentMap();
return ProfileXConf_delete(profile);
}
T2Debug("%s --out\n", __FUNCTION__);
return T2ERROR_SUCCESS;
}
T2ERROR ReportProfiles_addReportProfile(Profile *profile)
{
T2Debug("%s ++in\n", __FUNCTION__);
if(T2ERROR_SUCCESS != addProfile(profile))
{
T2Error("Failed to create/add new report profile : %s\n", profile->name);
return T2ERROR_FAILURE;
}
if(T2ERROR_SUCCESS != enableProfile(profile->name))
{
T2Error("Failed to enable profile : %s\n", profile->name);
return T2ERROR_FAILURE;
}
T2ER_StartDispatchThread(); //Error case can be ignored as Dispatch thread may be running already
T2Debug("%s --out\n", __FUNCTION__);
return T2ERROR_SUCCESS;
}
T2ERROR ReportProfiles_deleteProfile(const char* profileName)
{
bool is_profile_enable = false;
T2Debug("%s ++in\n", __FUNCTION__);
is_profile_enable = isProfileEnabled(profileName);
if(T2ERROR_SUCCESS != deleteProfile(profileName))
{
T2Error("Failed to delete profile : %s\n", profileName);
T2Debug("%s --out\n", __FUNCTION__);
return T2ERROR_FAILURE;
}
if(is_profile_enable == true)
{
T2ER_StopDispatchThread();
clearT2MarkerComponentMap();
if(ProfileXConf_isSet())
{
ProfileXConf_updateMarkerComponentMap();
}
updateMarkerComponentMap();
/* Restart DispatchThread */
if (ProfileXConf_isSet() || getProfileCount() > 0)
{
T2ER_StartDispatchThread();
}
}
T2Debug("%s --out\n", __FUNCTION__);
return T2ERROR_SUCCESS;
}
void profilemem_usage(unsigned int *value)
{
T2Debug("%s ++in\n", __FUNCTION__);
*value = profilemem;
T2Debug("value is %u\n", *value);
T2Debug("%s --out\n", __FUNCTION__);
}
void T2totalmem_calculate()
{
T2Debug("%s ++in\n", __FUNCTION__);
getrusage(RUSAGE_SELF, &pusage);
profilemem = (unsigned int)pusage.ru_maxrss;
T2Debug("T2 memory = %u\n", profilemem);
T2Debug("%s --out\n", __FUNCTION__);
}
static void* reportOnDemand(void *input)
{
T2Debug("%s ++in\n", __FUNCTION__);
char* action = (char*) input;
if(!input)
{
T2Warning("Input is NULL, no action specified \n");
return NULL ;
}
T2Debug("%s : action = %s \n", __FUNCTION__, action);
if(!strncmp(action, ON_DEMAND_ACTION_UPLOAD, MAX_PROFILENAMES_LENGTH))
{
T2Info("Upload XCONF report on demand \n");
set_logdemand(true);
generateDcaReport(false, true);
}
else if(!strncmp(action, ON_DEMAND_ACTION_ABORT, MAX_PROFILENAMES_LENGTH))
{
T2Info("Abort report on demand\n");
T2Info("Abort of the on-demand report is no longer supported; fork-based report execution and termination have been removed\n");
}
else
{
T2Warning("Unkown action - %s \n", action);
}
return NULL;
T2Debug("%s --out\n", __FUNCTION__);
}
T2ERROR privacymode_do_not_share ()
{
T2Debug("%s ++in\n", __FUNCTION__);
#ifndef DEVICE_EXTENDER
stopXConfClient();
if(T2ERROR_SUCCESS == startXConfClient())
{
T2Info("XCONF Fetch with privacymode is enabled \n");
}
else
{
T2Info("XCONF Fetch - IN PROGRESS ... Ignore current reload request \n");
return T2ERROR_FAILURE;
}
return T2ERROR_SUCCESS;
#endif
T2Debug("%s --out\n", __FUNCTION__);
return T2ERROR_SUCCESS;
}
T2ERROR initReportProfiles()
{
T2Debug("%s ++in\n", __FUNCTION__);
if(rpInitialized)
{
T2Error("%s ReportProfiles already initialized - ignoring\n", __FUNCTION__);
return T2ERROR_FAILURE;
}
#ifndef LIBRDKCERTSEL_BUILD
if(isMtlsEnabled() == true)
{
initMtls();
}
#endif
// Drop root before we are creating any folders/flags to avoid access issues
#if defined(DROP_ROOT_PRIV)
// Drop root privileges for Telemetry 2.0, If NonRootSupport RFC is true
drop_root();
#endif
#if defined (PRIVACYMODES_CONTROL)
// Define scope
{
DIR *dir = opendir(PRIVACYMODE_PATH);
if(dir == NULL)
{
T2Info("Persistence folder %s not present, creating folder\n", PRIVACYMODE_PATH);
if(mkdir(PRIVACYMODE_PATH, S_IRWXU | S_IRWXG | S_IRWXO) != 0)
{
T2Error("%s,%d: Failed to make directory : %s \n", __FUNCTION__, __LINE__, PRIVACYMODE_PATH);
}
}
else
{
closedir(dir);
}
}
#endif
#ifdef PERSIST_LOG_MON_REF
//Define scope
{
DIR *dir = opendir(SEEKFOLDER);
if(dir == NULL)
{
T2Info("SEEKMAP folder %s not present, creating folder\n", SEEKFOLDER);
if(mkdir(SEEKFOLDER, S_IRWXU | S_IRWXG | S_IRWXO) != 0)
{
T2Error("%s,%d: Failed to make directory : %s \n", __FUNCTION__, __LINE__, SEEKFOLDER);
}
}
else
{
closedir(dir);
previousLogCheck = true;
T2Info("SEEKMAP folder is present notify the profiles for saved seekmap\n");
}
}
#endif
rpInitialized = true;
bulkdata.enable = false;
bulkdata.minReportInterval = 10;
bulkdata.protocols = strdup("HTTP");
bulkdata.encodingTypes = strdup("JSON");
bulkdata.parameterWildcardSupported = true;
bulkdata.maxNoOfParamReferences = MAX_PARAM_REFERENCES;
bulkdata.maxReportSize = DEFAULT_MAX_REPORT_SIZE;
initScheduler((TimeoutNotificationCB)ReportProfiles_TimeoutCb, (ActivationTimeoutCB)ReportProfiles_ActivationTimeoutCb, (NotifySchedulerstartCB)NotifySchedulerstart);
initT2MarkerComponentMap();
T2ER_Init();
#ifndef DEVICE_EXTENDER
ProfileXConf_init(previousLogCheck);
#endif
t2Version = strdup("2.0.1"); // Setting the version to 2.0.1
{
T2Debug("T2 Version = %s\n", t2Version);
initProfileList(previousLogCheck);
free(t2Version);
// Init datamodel processing thread
if (T2ERROR_SUCCESS == datamodel_init())
{
#if defined(CCSP_SUPPORT_ENABLED)
if(isRbusEnabled())
#endif
{
T2Debug("Enabling datamodel for report profiles in RBUS mode \n");
callBackHandlers *interfaceListForBus = NULL;
interfaceListForBus = (callBackHandlers*) malloc(sizeof(callBackHandlers));
if(interfaceListForBus)
{
interfaceListForBus->dmCallBack = datamodel_processProfile;
interfaceListForBus->dmMsgPckCallBackHandler = datamodel_MsgpackProcessProfile;
interfaceListForBus->dmSavedJsonCallBack = datamodel_getSavedJsonProfilesasString;
interfaceListForBus->dmSavedMsgPackCallBack = datamodel_getSavedMsgpackProfilesasString;
interfaceListForBus->pmCallBack = profilemem_usage;
interfaceListForBus->reportonDemand = reportOnDemand;
interfaceListForBus->privacyModesDoNotShare = privacymode_do_not_share;
interfaceListForBus->mprofilesdeleteDoNotShare = deleteAllReportProfiles;
regDEforProfileDataModel(interfaceListForBus);
free(interfaceListForBus);
}
else
{
T2Error("Unable to allocate memory for callback handler registry\n");
}
}
#if defined(CCSP_SUPPORT_ENABLED)
else
{
// Register TR-181 DM for T2.0
T2Debug("Enabling datamodel for report profiles in DBUS mode \n");
if(0 != initTR181_dm())
{
T2Error("Unable to initialize TR181!!! \n");
datamodel_unInit();
}
}
#endif
// Message pack format is supported only for reportprofile which is activated only if version is set to 2.0.1
// Call webconfig init only when it is required and datamodel's have been initialized .
#if defined(FEATURE_SUPPORT_WEBCONFIG)
if(tele_web_config_init() != 0)
{
T2Error("Failed to intilize tele_web_config_init \n");
}
else
{
T2Debug("tele_web_config_init Successful\n");
//Informing Webconfig about telemetry component crash
check_component_crash(TELEMETRY_INIT_FILE_BOOTUP);
//Touching TELEMETRY_INIT_FILE_BOOTUP during Bootup
system("touch /tmp/telemetry_initialized_bootup");
T2Debug(" %s Touched \n", TELEMETRY_INIT_FILE_BOOTUP);
}
#endif
//Web Config Framework init ends
}
else
{
T2Error("Unable to start message processing thread!!! \n");
}
}
if(ProfileXConf_isSet() || getProfileCount() > 0)
{
if(isRbusEnabled())
{
unregisterDEforCompEventList();
createComponentDataElements();
FILE* cfgReadyFlag = NULL ;
cfgReadyFlag = fopen(T2_CONFIG_READY, "w+");
if(cfgReadyFlag)
{
fclose(cfgReadyFlag);
}
setT2EventReceiveState(T2_STATE_CONFIG_READY);
T2Info("T2 is now Ready to be configured for report profiles\n");
getMarkerCompRbusSub(true);
}
T2ER_StartDispatchThread();
}
//Initialise the properties file RDK-58222
T2InitProperties();
T2Info("InitProperties is successful\n");
// This indicates telemetry has started
FILE* bootFlag = NULL ;
bootFlag = fopen(BOOTFLAG, "w+");
if(bootFlag)
{
T2Debug("%s Touched \n", BOOTFLAG);
fclose(bootFlag);
}
else
{
T2Error("Failed to create T2 bootflag %s \n", BOOTFLAG);
}
T2Debug("%s --out\n", __FUNCTION__);
T2Info("Init ReportProfiles Successful\n");
return T2ERROR_SUCCESS;
}
void generateDcaReport(bool isDelayed, bool isOnDemand)
{
if(ProfileXConf_isSet())
{
/**
* Field requirement - Generate the first report at early stage after around 2 mins of stabilization during boot
* This is to make it at par with legacy dca reporting pattern
*/
if(isDelayed)
{
T2Info("Triggering XCONF report generation during boot with delay \n");
#ifdef PERSIST_LOG_MON_REF
sleep(180); // increase the delay if we are reporting previous logs
#else
sleep(120); // 2 minutes delay
#endif
}
else
{
T2Info("Triggering XCONF report generation \n");
}
ProfileXConf_notifyTimeout(false, isOnDemand);
}
}
T2ERROR ReportProfiles_uninit( )
{
T2Debug("%s ++in\n", __FUNCTION__);
if(!rpInitialized)
{
T2Error("%s ReportProfiles is not initialized yet - ignoring\n", __FUNCTION__);
return T2ERROR_FAILURE;
}
rpInitialized = false;
if(isRbusEnabled())
{
getMarkerCompRbusSub(false); // remove Rbus subscription
}
T2ER_Uninit();
destroyT2MarkerComponentMap();
uninitScheduler();
if(t2Version && strcmp(t2Version, "2"))
{
#if defined(CCSP_SUPPORT_ENABLED)
// Unregister TR-181 DM
unInitTR181_dm();
#endif
// Stop datamodel processing thread;
datamodel_unInit();
uninitProfileList();
}
#ifndef DEVICE_EXTENDER
ProfileXConf_uninit();
#endif
free(bulkdata.protocols);
bulkdata.protocols = NULL ;
free(bulkdata.encodingTypes);
bulkdata.encodingTypes = NULL ;
T2Debug("%s --out\n", __FUNCTION__);
T2Info("Uninit ReportProfiles Successful\n");
return T2ERROR_SUCCESS;
}
T2ERROR RemovePreRPfromDisk(const char* path, hash_map_t *map)
{
T2Debug("%s ++in\n", __FUNCTION__);
struct dirent *entry;
DIR *dir = opendir(path);
if (dir == NULL)
{
T2Info("Failed to open persistence folder : %s, creating folder\n", path);
return T2ERROR_FAILURE;
}
while ((entry = readdir(dir)) != NULL)
{
T2Info("Filename : %s \n", entry->d_name);
if((entry->d_name[0] == '.') || (strcmp(entry->d_name, "..") == 0))
{
continue;
}
if(NULL == hash_map_get(map, entry->d_name))
{
T2Debug("%s : Removed %s report profile from the disk due to coming new report profile \n", __FUNCTION__, entry->d_name);
removeProfileFromDisk(REPORTPROFILES_PERSISTENCE_PATH, entry->d_name);
}
}
closedir(dir);
T2Debug("%s ++out\n", __FUNCTION__);
return T2ERROR_SUCCESS;
}
static void freeProfilesHashMap(void *data)
{
T2Debug("%s ++in\n", __FUNCTION__);
if(data != NULL)
{
hash_element_t *element = (hash_element_t *) data;
if(element->key)
{
T2Debug("Freeing hash entry element for Profiles object Name:%s\n", element->key);
free(element->key);
}
if (element->data)
{
free(element->data);
}
free(element);
}
T2Debug("%s --out\n", __FUNCTION__);
}
static void freeReportProfileHashMap(void *data)
{
T2Debug("%s ++in\n", __FUNCTION__);
if (data != NULL)
{
hash_element_t *element = (hash_element_t *) data;
if (element->key)
{
T2Debug("Freeing hash entry element for Profiles object Name:%s\n", element->key);
free(element->key);
}
if (element->data)
{
T2Debug("Freeing element data\n");
ReportProfile *entry = (ReportProfile *)element->data;
if (entry->hash)
{
free(entry->hash);
}
if (entry->config)
{
free(entry->config);
}
free(entry);
}
free(element);
element = NULL ;
}
T2Debug("%s --out\n", __FUNCTION__);
}
T2ERROR deleteAllReportProfiles()
{
T2Debug("%s ++in\n", __FUNCTION__);
if (T2ERROR_SUCCESS != deleteAllProfiles(true))
{
T2Error("Error while deleting all report profiles \n");
}
T2ER_StopDispatchThread();
clearT2MarkerComponentMap();
if(ProfileXConf_isSet())
{
ProfileXConf_updateMarkerComponentMap();
}
/* Restart DispatchThread */
if (ProfileXConf_isSet())
{
T2ER_StopDispatchThread();
T2ER_StartDispatchThread();
}
T2Debug("%s --out\n", __FUNCTION__);
return T2ERROR_SUCCESS;
}
void ReportProfiles_ProcessReportProfilesBlob(cJSON *profiles_root, bool rprofiletypes)
{
T2Debug("%s ++in\n", __FUNCTION__);
if(profiles_root == NULL)
{
T2Error("Profile profiles_root is null . Unable to ReportProfiles_ProcessReportProfilesBlob \n");
T2Debug("%s --out\n", __FUNCTION__);
return;
}
#if defined(PRIVACYMODES_CONTROL)
char* paramValue = NULL;
getPrivacyMode(¶mValue);
if(strcmp(paramValue, "DO_NOT_SHARE") == 0)
{
T2Warning("Privacy Mode is DO_NOT_SHARE. Reportprofiles is not supported\n");
free(paramValue);
paramValue = NULL;
return;
}
free(paramValue);
paramValue = NULL;
#endif
cJSON *profilesArray = cJSON_GetObjectItem(profiles_root, "profiles");
uint32_t profiles_count = cJSON_GetArraySize(profilesArray);
T2Info("Number of report profiles in current configuration is %u \n", profiles_count);
if(profiles_count == 0)
{
if(rprofiletypes == T2_TEMP_RP)
{
T2Info("Empty report profiles are not valid configuration for temporary report profiles. \n");
}
else
{
T2Debug("Empty report profiles in configuration. Delete all active profiles. \n");
if (T2ERROR_SUCCESS != deleteAllReportProfiles())
{
T2Error("Failed to delete all profiles \n");
}
}
T2Debug("%s --out\n", __FUNCTION__);
return;
}
char* profileName = NULL;
uint32_t profileIndex = 0;
hash_map_t *profileHashMap = getProfileHashMap();
hash_map_t *receivedProfileHashMap = hash_map_create();
// Rbus subscription of Tr181 datamodel events
if(isRbusEnabled())
{
getMarkerCompRbusSub(false);
}
// Populate profile hash map for current configuration
for( profileIndex = 0; profileIndex < profiles_count; profileIndex++ )
{
cJSON* singleProfile = cJSON_GetArrayItem(profilesArray, profileIndex);
if(singleProfile == NULL)
{
T2Error("Incomplete profile information, unable to create profile for index %u \n", profileIndex);
continue;
}
cJSON* nameObj = cJSON_GetObjectItem(singleProfile, "name");
cJSON* hashObj = cJSON_GetObjectItem(singleProfile, "hash");
if(hashObj == NULL)
{
hashObj = cJSON_GetObjectItem(singleProfile, "versionHash");
}
cJSON* profileObj = cJSON_GetObjectItem(singleProfile, "value");
if(nameObj == NULL || hashObj == NULL || profileObj == NULL || strcmp(nameObj->valuestring, "") == 0 || strcmp(hashObj->valuestring, "") == 0 )
{
T2Error("Incomplete profile object information, unable to create profile\n");
continue;
}
ReportProfile *profileEntry = (ReportProfile *)malloc(sizeof(ReportProfile));
profileName = strdup(nameObj->valuestring);
profileEntry->hash = strdup(hashObj->valuestring);
profileEntry->config = cJSON_PrintUnformatted(profileObj);
hash_map_put(receivedProfileHashMap, profileName, profileEntry, freeReportProfileHashMap);
} // End of looping through report profiles
// Delete profiles not present in the new profile list
char *profileNameKey = NULL;
int count = hash_map_count(profileHashMap) - 1;
const char *DirPath = NULL;
if (rprofiletypes == T2_RP)
{
DirPath = REPORTPROFILES_PERSISTENCE_PATH;
}
else if (rprofiletypes == T2_TEMP_RP)
{
DirPath = SHORTLIVED_PROFILES_PATH;
}
bool rm_flag = false;
if(rprofiletypes == T2_RP)
{
while(count >= 0)
{
profileNameKey = hash_map_lookupKey(profileHashMap, count--);
T2Debug("%s Map content from disk = %s \n", __FUNCTION__, profileNameKey);
if(NULL == hash_map_get(receivedProfileHashMap, profileNameKey))
{
T2Debug("%s Profile %s not present in current config . Remove profile from disk \n", __FUNCTION__, profileNameKey);
removeProfileFromDisk(DirPath, profileNameKey);
T2Debug("%s Terminate profile %s \n", __FUNCTION__, profileNameKey);
ReportProfiles_deleteProfile(profileNameKey);
rm_flag = true;
}
}
if(T2ERROR_SUCCESS != RemovePreRPfromDisk(DirPath, receivedProfileHashMap))
{
T2Error("Failed to remove previous report profile from the disk\n");
}
}
if(isRbusEnabled())
{
unregisterDEforCompEventList();
}
for( profileIndex = 0; profileIndex < hash_map_count(receivedProfileHashMap); profileIndex++ )
{
ReportProfile *profileEntry = (ReportProfile *)hash_map_lookup(receivedProfileHashMap, profileIndex);
profileName = hash_map_lookupKey(receivedProfileHashMap, profileIndex);
char *existingProfileHash = hash_map_remove(profileHashMap, profileName);
if(existingProfileHash != NULL)
{
if(!strcmp(existingProfileHash, profileEntry->hash))
{
T2Debug("%s Profile hash for %s is same as previous profile, ignore processing config\n", __FUNCTION__, profileName);
free(existingProfileHash);
continue;
}
else