1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "dslm_hievent.h"
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 
21 #include "securec.h"
22 
23 #include "device_security_defines.h"
24 #include "dslm_core_defines.h"
25 #include "dslm_cred.h"
26 #include "dslm_bigdata.h"
27 
ReportHiEventServiceStartFailed(const uint32_t errorType)28 void ReportHiEventServiceStartFailed(const uint32_t errorType)
29 {
30     ReportServiceStartFailedEvent(errorType);
31 }
32 
ReportHiEventInitSelfFailed(const char * errorString)33 void ReportHiEventInitSelfFailed(const char *errorString)
34 {
35     ReportInitSelfFailedEvent(errorString);
36 }
37 
ReportHiEventInfoSync(const DslmDeviceInfo * info)38 void ReportHiEventInfoSync(const DslmDeviceInfo *info)
39 {
40     if (info == NULL) {
41         return;
42     }
43 
44     SecurityInfoSyncEvent event;
45     (void)memset_s(&event, sizeof(SecurityInfoSyncEvent), 0, sizeof(SecurityInfoSyncEvent));
46 
47     if (info->lastResponseTime >= info->lastRequestTime) {
48         event.costTime = (int32_t)(info->lastResponseTime - info->lastRequestTime);
49     }
50 
51     event.retCode = (int32_t)info->result;
52     event.secLevel = (int32_t)info->credInfo.credLevel;
53     event.localVersion = GetCurrentVersion();
54     event.targetVersion = info->version;
55     if (memcpy_s(event.targetModel, MODEL_MAX_LEN, info->credInfo.model, CRED_INFO_MODEL_LEN) != EOK) {
56         (void)memset_s(event.targetModel, MODEL_MAX_LEN, 0, MODEL_MAX_LEN);
57     }
58 
59     event.credType = info->credInfo.credType;
60     ReportSecurityInfoSyncEvent(&event);
61 }
62 
ReportHiEventAppInvoke(const DslmDeviceInfo * info)63 void ReportHiEventAppInvoke(const DslmDeviceInfo *info)
64 {
65     if (info == NULL) {
66         return;
67     }
68 
69     AppInvokeEvent event;
70     (void)memset_s(&event, sizeof(AppInvokeEvent), 0, sizeof(AppInvokeEvent));
71     event.costTime = 0;
72     if (info->lastResponseTime >= info->lastRequestTime) {
73         event.costTime = (int32_t)(info->lastResponseTime - info->lastRequestTime);
74     }
75     event.uid = 0;
76     event.retCode = (int32_t)info->result;
77     event.secLevel = (int32_t)info->credInfo.credLevel;
78     event.retMode = (info->result == ERR_NEED_COMPATIBLE) ? 1 : 0;
79 
80     if (memcpy_s(event.targetModel, MODEL_MAX_LEN, info->credInfo.model, CRED_INFO_MODEL_LEN) != EOK) {
81         (void)memset_s(event.targetModel, MODEL_MAX_LEN, 0, MODEL_MAX_LEN);
82     }
83 
84     ReportAppInvokeEvent(&event);
85 }