1 /*
2 * Copyright (c) 2023 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 #ifndef CONN_AUDIT_CONVERTER_H
17 #define CONN_AUDIT_CONVERTER_H
18
19 #include "softbus_event_converter.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #define CONN_AUDIT_ASSIGNER(type, fieldName, field) \
26 static inline bool ConnAuditAssigner##fieldName( \
27 const char *eventName, HiSysEventParamType paramType, SoftbusEventForm *form, HiSysEventParam *param) \
28 { \
29 if (Assigner##type(form->connAuditExtra->field, ¶m) && \
30 CopyString(param->name, eventName, MAX_LENGTH_OF_PARAM_NAME)) { \
31 param->t = paramType; \
32 return true; \
33 } \
34 return false; \
35 }
36
37 CONN_AUDIT_ASSIGNER(Errcode, Errcode, errcode)
38 CONN_AUDIT_ASSIGNER(Int32, AuditType, auditType)
39 CONN_AUDIT_ASSIGNER(Int32, ConnectionId, connectionId)
40 CONN_AUDIT_ASSIGNER(Int32, RequestId, requestId)
41 CONN_AUDIT_ASSIGNER(Int32, LinkType, linkType)
42 CONN_AUDIT_ASSIGNER(Int32, ExpectRole, expectRole)
43 CONN_AUDIT_ASSIGNER(Int32, CostTime, costTime)
44 CONN_AUDIT_ASSIGNER(String, Frequency, frequency)
45 CONN_AUDIT_ASSIGNER(String, ChallengeCode, challengeCode)
46 CONN_AUDIT_ASSIGNER(String, PeerBrMac, peerBrMac)
47 CONN_AUDIT_ASSIGNER(String, PeerBleMac, peerBleMac)
48 CONN_AUDIT_ASSIGNER(String, PeerWifiMac, peerWifiMac)
49 CONN_AUDIT_ASSIGNER(String, PeerDeviceType, peerDeviceType)
50 CONN_AUDIT_ASSIGNER(String, PeerUdid, peerUdid)
51 CONN_AUDIT_ASSIGNER(String, ConnPayload, connPayload)
52 CONN_AUDIT_ASSIGNER(String, LocalDeviceName, localDeviceName)
53 CONN_AUDIT_ASSIGNER(String, PeerIp, peerIp)
54 CONN_AUDIT_ASSIGNER(String, CallerPkg, callerPkg)
55 CONN_AUDIT_ASSIGNER(String, CalleePkg, calleePkg)
56 CONN_AUDIT_ASSIGNER(Int32, ConnectTimes, connectTimes)
57 CONN_AUDIT_ASSIGNER(String, LocalBrMac, localBrMac)
58 CONN_AUDIT_ASSIGNER(String, LocalBleMac, localBleMac)
59 CONN_AUDIT_ASSIGNER(String, LocalUdid, localUdid)
60 CONN_AUDIT_ASSIGNER(String, LocalIp, localIp)
61 CONN_AUDIT_ASSIGNER(String, PeerPort, peerPort)
62 CONN_AUDIT_ASSIGNER(String, LocalPort, localPort)
63
64 #define CONN_AUDIT_ASSIGNER_SIZE 26 // Size of g_connAuditAssigners
65 static HiSysEventParamAssigner g_connAuditAssigners[] = {
66 { "ERROR_CODE", HISYSEVENT_INT32, ConnAuditAssignerErrcode },
67 { "AUDIT_TYPE", HISYSEVENT_INT32, ConnAuditAssignerAuditType },
68 { "CONN_ID", HISYSEVENT_INT32, ConnAuditAssignerConnectionId },
69 { "REQ_ID", HISYSEVENT_INT32, ConnAuditAssignerRequestId },
70 { "LINK_TYPE", HISYSEVENT_INT32, ConnAuditAssignerLinkType },
71 { "EXPECT_ROLE", HISYSEVENT_INT32, ConnAuditAssignerExpectRole },
72 { "COST_TIME", HISYSEVENT_INT32, ConnAuditAssignerCostTime },
73 { "CONN_TIMES", HISYSEVENT_INT32, ConnAuditAssignerConnectTimes },
74 { "FREQ", HISYSEVENT_STRING, ConnAuditAssignerFrequency },
75 { "CHALLENGE_CODE", HISYSEVENT_STRING, ConnAuditAssignerChallengeCode },
76 { "PEER_BR_MAC", HISYSEVENT_STRING, ConnAuditAssignerPeerBrMac },
77 { "LOCAL_BR_MAC", HISYSEVENT_STRING, ConnAuditAssignerLocalBrMac },
78 { "PEER_BLE_MAC", HISYSEVENT_STRING, ConnAuditAssignerPeerBleMac },
79 { "LOCAL_BLE_MAC", HISYSEVENT_STRING, ConnAuditAssignerLocalBleMac },
80 { "PEER_DEV_TYPE", HISYSEVENT_STRING, ConnAuditAssignerPeerDeviceType },
81 { "PEER_UDID", HISYSEVENT_STRING, ConnAuditAssignerPeerUdid },
82 { "LOCAL_UDID", HISYSEVENT_STRING, ConnAuditAssignerLocalUdid },
83 { "CONN_PAYLOAD", HISYSEVENT_STRING, ConnAuditAssignerConnPayload },
84 { "LOCAL_DEV_NAME", HISYSEVENT_STRING, ConnAuditAssignerLocalDeviceName},
85 { "PEER_IP", HISYSEVENT_STRING, ConnAuditAssignerPeerIp },
86 { "LOCAL_IP", HISYSEVENT_STRING, ConnAuditAssignerLocalIp },
87 { "HOST_PKG", HISYSEVENT_STRING, ConnAuditAssignerCallerPkg },
88 { "TO_CALL_PKG", HISYSEVENT_STRING, ConnAuditAssignerCalleePkg },
89 { "PEER_PORT", HISYSEVENT_STRING, ConnAuditAssignerPeerPort },
90 { "LOCAL_PORT", HISYSEVENT_STRING, ConnAuditAssignerLocalPort },
91 { "PEER_WIFI_MAC", HISYSEVENT_STRING, ConnAuditAssignerPeerWifiMac },
92 // Modification Note: remember updating CONN_AUDIT_ASSIGNER_SIZE
93 };
94
ConvertConnAuditForm2Param(HiSysEventParam params[],SoftbusEventForm * form)95 static inline size_t ConvertConnAuditForm2Param(HiSysEventParam params[], SoftbusEventForm *form)
96 {
97 size_t validSize = 0;
98 if (form == NULL || form->connExtra == NULL) {
99 return validSize;
100 }
101 for (size_t i = 0; i < sizeof(g_connAuditAssigners) / sizeof(g_connAuditAssigners[0]); ++i) {
102 HiSysEventParamAssigner assigner = g_connAuditAssigners[i];
103 if (assigner.Assign(assigner.name, assigner.type, form, ¶ms[validSize])) {
104 ++validSize;
105 }
106 }
107 return validSize;
108 }
109
110 #ifdef __cplusplus
111 }
112 #endif /* __cplusplus */
113 #endif // CONN_AUDIT_CONVERTER_H
114