1 /*
2  * Copyright (c) 2021 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 LNN_DISTRIBUTED_NET_LEDGER_H
17 #define LNN_DISTRIBUTED_NET_LEDGER_H
18 
19 #include "auth_interface.h"
20 #include "bus_center_info_key.h"
21 #include "lnn_node_info.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define INT_TO_STR_SIZE 12
28 #define INVALID_CONNECTION_CODE_VALUE -1
29 #define SHORT_UDID_HASH_LEN 8
30 #define SHORT_UDID_HASH_HEX_LEN 16
31 typedef struct {
32     InfoKey key;
33     int32_t (*getInfo)(const char *netWorkId, bool checkOnline, void *info, uint32_t len);
34 } DistributedLedgerKey;
35 
36 typedef enum {
37     CATEGORY_UDID,
38     CATEGORY_UUID,
39     CATEGORY_NETWORK_ID,
40 } IdCategory;
41 
42 typedef enum {
43     REPORT_NONE,
44     REPORT_CHANGE,
45     REPORT_ONLINE,
46     REPORT_OFFLINE,
47 } ReportCategory;
48 
49 int32_t LnnInitDistributedLedger(void);
50 void LnnDeinitDistributedLedger(void);
51 
52 ReportCategory LnnAddOnlineNode(NodeInfo *info);
53 ReportCategory LnnSetNodeOffline(const char *udid, ConnectionAddrType type, int32_t authId);
54 int32_t LnnSetAuthTypeValue(uint32_t *authTypeValue, AuthType type);
55 int32_t LnnClearAuthTypeValue(uint32_t *authTypeValue, AuthType type);
56 void LnnRemoveNode(const char *udid);
57 int32_t LnnGetRemoteNodeInfoById(const char *id, IdCategory type, NodeInfo *info);
58 int32_t LnnGetRemoteNodeInfoByKey(const char *key, NodeInfo *info); /* key means udid/uuid/networkId/macAddr/ip */
59 bool LnnSetDLDeviceInfoName(const char *udid, const char *name);
60 bool LnnSetDLDeviceNickName(const char *networkId, const char *name);
61 bool LnnSetDLP2pInfo(const char *networkId, const P2pInfo *info);
62 bool LnnSetRemoteScreenStatusInfo(const char *networkId, bool isScreenOn);
63 const char *LnnConvertDLidToUdid(const char *id, IdCategory type);
64 int32_t LnnConvertDlId(const char *srcId, IdCategory srcIdType, IdCategory dstIdType,
65     char *dstIdBuf, uint32_t dstIdBufLen);
66 short LnnGetCnnCode(const char *uuid, DiscoveryType type);
67 int32_t LnnGetBasicInfoByUdid(const char *udid, NodeBasicInfo *basicInfo);
68 int32_t LnnGetDLHeartbeatTimestamp(const char *networkId, uint64_t *timestamp);
69 int32_t LnnGetDLOnlineTimestamp(const char *networkId, uint64_t *timestamp);
70 int32_t LnnSetDLHeartbeatTimestamp(const char *networkId, const uint64_t timestamp);
71 int32_t LnnGetDLBleDirectTimestamp(const char *networkId, uint64_t *timestamp);
72 int32_t LnnGetDLUpdateTimestamp(const char *udid, uint64_t *timestamp);
73 int32_t LnnSetDLBleDirectTimestamp(const char *networkId, uint64_t timestamp);
74 int32_t LnnGetDLAuthCapacity(const char *networkId, uint32_t *authCapacity);
75 bool LnnGetOnlineStateById(const char *id, IdCategory type);
76 int32_t LnnGetLnnRelation(const char *id, IdCategory type, uint8_t *relation, uint32_t len);
77 int32_t LnnSetDLConnCapability(const char *networkId, uint32_t connCapability);
78 int32_t LnnSetDLNodeAddr(const char *id, IdCategory type, const char *addr);
79 int32_t LnnSetDLBatteryInfo(const char *networkId, const BatteryInfo *info);
80 int32_t LnnSetDLBssTransInfo(const char *networkId, const BssTransInfo *info);
81 const NodeInfo *LnnGetOnlineNodeByUdidHash(const char *recvUdidHash);
82 void LnnRefreshDeviceOnlineStateAndDevIdInfo(const char *pkgName, DeviceInfo *device,
83     const InnerDeviceInfoAddtions *addtions);
84 int32_t LnnUpdateNetworkId(const NodeInfo *newInfo);
85 int32_t LnnUpdateNodeInfo(NodeInfo *newInfo);
86 int32_t LnnAddMetaInfo(NodeInfo *info);
87 int32_t LnnDeleteMetaInfo(const char *udid, AuthLinkType type);
88 int32_t UpdateGroupType(NodeInfo *info);
89 int32_t LnnUpdateGroupType(const NodeInfo *info);
90 int32_t LnnUpdateAccountInfo(const NodeInfo *info);
91 int32_t LnnSetDLProxyPort(const char *id, IdCategory type, int32_t proxyPort);
92 int32_t LnnSetDLSessionPort(const char *id, IdCategory type, int32_t sessionPort);
93 int32_t LnnSetDLAuthPort(const char *id, IdCategory type, int32_t authPort);
94 int32_t LnnSetDLP2pIp(const char *id, IdCategory type, const char *p2pIp);
95 NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type);
96 bool LnnSetDLWifiDirectAddr(const char *networkId, const char *addr);
97 bool LnnSetDlPtk(const char *networkId, const char *remotePtk);
98 int32_t LnnGetOsTypeByNetworkId(const char *networkId, int32_t *osType);
99 int32_t LnnSetDLUnifiedDeviceName(const char *udid, const char *name);
100 int32_t LnnSetDLUnifiedDefaultDeviceName(const char *udid, const char *name);
101 int32_t LnnSetDLDeviceNickNameByUdid(const char *udid, const char *name);
102 int32_t LnnSetDLDeviceStateVersion(const char *udid, int32_t stateVersion);
103 int32_t LnnUpdateDistributedNodeInfo(NodeInfo *newInfo, const char *udid);
104 int32_t LnnSetDLDeviceBroadcastCipherKey(const char *udid, const void *cipherKey);
105 int32_t LnnSetDLDeviceBroadcastCipherIv(const char *udid, const void *cipherIv);
106 bool IsAvailableMeta(const char *peerNetWorkId);
107 #ifdef __cplusplus
108 }
109 #endif
110 
111 #endif // LNN_DISTRIBUTED_NET_LEDGER_H