• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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_NODE_INFO_H
17 #define LNN_NODE_INFO_H
18 
19 #include "lnn_connect_info.h"
20 #include "lnn_device_info.h"
21 #include "lnn_net_capability.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 #define WIFI_SSID_LEN 32
27 #define WIFI_MAC_LEN 6
28 #define OFFLINE_CODE_LEN 32
29 #define OFFLINE_CODE_BYTE_SIZE 4
30 #define EXTDATA_LEN 8
31 #define PTK_DEFAULT_LEN 32
32 #define STATIC_CAP_LEN 100
33 #define USERID_CHECKSUM_LEN 4
34 #define USERID_LEN 4
35 #define STATIC_CAP_STR_LEN 201
36 #define PTK_ENCODE_LEN 45
37 
38 #define LNN_RELATION_MASK 0x03
39 #define WIFI_CFG_INFO_MAX_LEN 512
40 #define CHANNEL_LIST_STR_LEN  256
41 
42 #define SESSION_KEY_STR_LEN 65
43 #define PTK_STR_LEN 65
44 
45 #define BROADCAST_IV_LEN 16
46 #define BROADCAST_IV_STR_LEN 33
47 
48 #define LFINDER_UDID_HASH_LEN 32
49 #define LFINDER_IRK_LEN 16
50 #define LFINDER_IRK_STR_LEN 33
51 #define LFINDER_MAC_ADDR_LEN 6
52 #define LFINDER_MAC_ADDR_STR_LEN 13
53 
54 typedef enum {
55     AUTH_AS_CLIENT_SIDE = 0,
56     AUTH_AS_SERVER_SIDE,
57     AUTH_SIDE_MAX,
58 } AuthSide;
59 
60 typedef enum {
61     ROLE_UNKNOWN = 0,
62     ROLE_CONTROLLER,
63     ROLE_LEAF,
64 } ConnectRole;
65 
66 typedef enum {
67     STATUS_OFFLINE = 0,
68     STATUS_ONLINE,
69 } ConnectStatus;
70 
71 typedef enum {
72     DISCOVERY_TYPE_UNKNOWN = 0,
73     DISCOVERY_TYPE_WIFI,
74     DISCOVERY_TYPE_BLE,
75     DISCOVERY_TYPE_BR,
76     DISCOVERY_TYPE_P2P,
77     DISCOVERY_TYPE_LSA,
78     DISCOVERY_TYPE_SESSION_KEY,
79     DISCOVERY_TYPE_COUNT,
80 } DiscoveryType;
81 
82 typedef struct {
83     char ssid[WIFI_SSID_LEN + 1];
84     unsigned char targetBssid[WIFI_MAC_LEN];
85 } BssTransInfo;
86 
87 typedef struct {
88     int32_t p2pRole;
89     char wifiCfg[WIFI_CFG_INFO_MAX_LEN];
90     char chanList5g[CHANNEL_LIST_STR_LEN];
91     int32_t staFrequency;
92     char p2pMac[MAC_LEN]; // the mac of local p2p interface
93     char goMac[MAC_LEN]; // the mac of p2p Go device, while local device as Gc role.
94     char p2pIp[IP_LEN];
95 } P2pInfo;
96 
97 typedef struct {
98     bool isMetaNode;
99     uint32_t metaDiscType;
100 } MetaInfo;
101 
102 typedef struct {
103     bool isCharging;
104     int32_t batteryLevel;
105 } BatteryInfo;
106 
107 typedef enum {
108     BIT_SUPPORT_EXCHANGE_NETWORKID = 0,
109     BIT_SUPPORT_NORMALIZED_LINK = 1,
110     BIT_SUPPORT_NEGOTIATION_AUTH = 2,
111     BIT_SUPPORT_BR_DUP_BLE = 3,
112     BIT_SUPPORT_ADV_OFFLINE = 4,
113     BIT_SUPPORT_ENHANCEDP2P_DUP_BLE = 5,
114     BIT_SUPPORT_SESSION_DUP_BLE = 6,
115 } AuthCapability;
116 
117 typedef struct {
118     int32_t keylen;
119     unsigned char key[SESSION_KEY_LENGTH];
120     unsigned char iv[BROADCAST_IV_LEN];
121 } BroadcastCipherInfo;
122 
123 typedef struct {
124     uint8_t peerIrk[LFINDER_IRK_LEN];
125     unsigned char publicAddress[LFINDER_MAC_ADDR_LEN];
126     unsigned char peerUdidHash[LFINDER_UDID_HASH_LEN];
127 } RpaInfo;
128 
129 typedef struct {
130     char softBusVersion[VERSION_MAX_LEN];
131     char versionType[VERSION_MAX_LEN]; // compatible nearby
132     char pkgVersion[VERSION_MAX_LEN];
133     char uuid[UUID_BUF_LEN]; // compatible nearby
134     char lastNetworkId[NETWORK_ID_BUF_LEN];
135     char networkId[NETWORK_ID_BUF_LEN];
136     char publicId[ID_MAX_LEN];
137     char parentId[ID_MAX_LEN];
138     char masterUdid[UDID_BUF_LEN];
139     char nodeAddress[SHORT_ADDRESS_MAX_LEN];
140     char extData[EXTDATA_LEN];
141     char wifiDirectAddr[MAC_LEN];
142     char accountHash[SHA_256_HASH_LEN];
143     unsigned char offlineCode[OFFLINE_CODE_BYTE_SIZE];
144     char remotePtk[PTK_DEFAULT_LEN];
145     char remoteMetaPtk[PTK_DEFAULT_LEN];
146     bool isNeedReSyncDeviceName;
147     bool isScreenOn;
148     bool initPreventFlag;
149     bool isAuthExchangeUdid;
150     bool isSupportIpv6;
151     bool isBleP2p; // true: this device support connect p2p via ble connection
152     bool isSupportSv;
153     uint8_t staticCapability[STATIC_CAP_LEN];
154     uint8_t relation[CONNECTION_ADDR_MAX];
155     uint8_t userIdCheckSum[USERID_CHECKSUM_LEN];
156     uint16_t dataChangeFlag;
157     uint16_t dataDynamicLevel;
158     uint16_t dataStaticLevel;
159     uint32_t dataSwitchLevel;
160     uint16_t dataSwitchLength;
161     BssTransInfo bssTransInfo;
162     RpaInfo rpaInfo;
163     int32_t masterWeight;
164     ConnectRole role;
165     ConnectStatus status;
166     uint32_t staticNetCap;
167     uint32_t netCapacity;
168     uint32_t authCapacity;
169     uint32_t heartbeatCapacity;
170     uint32_t discoveryType;
171     int32_t wifiBuffSize;
172     int32_t brBuffSize;
173     int32_t stateVersion;
174     int32_t localStateVersion;
175     uint32_t groupType;
176     int32_t bleMacRefreshSwitch;
177     int32_t bleConnCloseDelayTime;
178     int32_t staticCapLen;
179     int32_t userId;
180     uint32_t stateVersionReason;
181     int32_t deviceSecurityLevel;
182     int32_t authChannelId[CONNECTION_ADDR_MAX][AUTH_SIDE_MAX];
183     uint32_t AuthTypeValue;
184     DeviceBasicInfo deviceInfo;
185     P2pInfo p2pInfo;
186     MetaInfo metaInfo;
187     BatteryInfo batteryInfo;
188     BroadcastCipherInfo cipherInfo;
189     int64_t wifiVersion;
190     int64_t bleVersion;
191     uint64_t feature;
192     uint64_t connSubFeature;
193     int64_t bleStartTimestamp;
194     uint64_t supportedProtocols;
195     int64_t accountId;
196     int64_t authSeq[DISCOVERY_TYPE_COUNT];
197     int64_t networkIdTimestamp;
198     int64_t authSeqNum;
199     uint64_t heartbeatTimestamp;
200     uint64_t bleDirectTimestamp;
201     uint64_t onlinetTimestamp;
202     uint64_t updateTimestamp;
203     int64_t lastAuthSeq;
204     ConnectInfo connectInfo;
205 } NodeInfo;
206 
207 const char *LnnGetDeviceUdid(const NodeInfo *info);
208 int32_t LnnSetDeviceUdid(NodeInfo *info, const char *udid);
209 const char *LnnGetDeviceUuid(const NodeInfo *info);
210 bool LnnHasDiscoveryType(const NodeInfo *info, DiscoveryType type);
211 int32_t LnnSetDiscoveryType(NodeInfo *info, DiscoveryType type);
212 int32_t LnnClearDiscoveryType(NodeInfo *info, DiscoveryType type);
213 bool LnnIsNodeOnline(const NodeInfo *info);
214 void LnnSetNodeConnStatus(NodeInfo *info, ConnectStatus status);
215 const char *LnnGetBtMac(const NodeInfo *info);
216 void LnnSetBtMac(NodeInfo *info, const char *mac);
217 const char *LnnGetBleMac(const NodeInfo *info);
218 void LnnSetBleMac(NodeInfo *info, const char *mac);
219 const char *LnnGetWiFiIp(const NodeInfo *info);
220 void LnnSetWiFiIp(NodeInfo *info, const char *ip);
221 const char *LnnGetNetIfName(const NodeInfo *info);
222 void LnnSetNetIfName(NodeInfo *info, const char *netIfName);
223 const char *LnnGetMasterUdid(const NodeInfo *info);
224 int32_t LnnSetMasterUdid(NodeInfo *info, const char *udid);
225 int32_t LnnGetAuthPort(const NodeInfo *info);
226 int32_t LnnSetAuthPort(NodeInfo *info, int32_t port);
227 int32_t LnnGetSessionPort(const NodeInfo *info);
228 int32_t LnnSetSessionPort(NodeInfo *info, int32_t port);
229 int32_t LnnGetProxyPort(const NodeInfo *info);
230 int32_t LnnSetProxyPort(NodeInfo *info, int32_t port);
231 int32_t LnnSetP2pRole(NodeInfo *info, int32_t role);
232 int32_t LnnGetP2pRole(const NodeInfo *info);
233 int32_t LnnSetWifiCfg(NodeInfo *info, const char *wifiCfg);
234 const char *LnnGetWifiCfg(const NodeInfo *info);
235 int32_t LnnSetChanList5g(NodeInfo *info, const char *chanList5g);
236 const char *LnnGetChanList5g(const NodeInfo *info);
237 int32_t LnnSetStaFrequency(NodeInfo *info, int32_t staFrequency);
238 int32_t LnnGetStaFrequency(const NodeInfo *info);
239 int32_t LnnSetP2pMac(NodeInfo *info, const char *p2pMac);
240 uint16_t LnnGetDataChangeFlag(const NodeInfo *info);
241 int32_t LnnSetDataChangeFlag(NodeInfo *info, uint16_t dataChangeFlag);
242 uint16_t LnnGetDataDynamicLevel(const NodeInfo *info);
243 int32_t LnnSetDataDynamicLevel(NodeInfo *info, uint16_t dataDynamicLevel);
244 uint16_t LnnGetDataStaticLevel(const NodeInfo *info);
245 int32_t LnnSetDataStaticLevel(NodeInfo *info, uint16_t dataStaticLvel);
246 uint32_t LnnGetDataSwitchLevel(const NodeInfo *info);
247 int32_t LnnSetDataSwitchLevel(NodeInfo *info, uint32_t dataSwitchLevel);
248 uint16_t LnnGetDataSwitchLength(const NodeInfo *info);
249 int32_t LnnSetDataSwitchLength(NodeInfo *info, uint16_t dataSwitchLevel);
250 const char *LnnGetP2pMac(const NodeInfo *info);
251 int32_t LnnSetP2pGoMac(NodeInfo *info, const char *goMac);
252 const char *LnnGetP2pGoMac(const NodeInfo *info);
253 uint64_t LnnGetSupportedProtocols(const NodeInfo *info);
254 int32_t LnnSetSupportedProtocols(NodeInfo *info, uint64_t protocols);
255 int32_t LnnSetStaticCapability(NodeInfo *info, uint8_t *cap, uint32_t len);
256 int32_t LnnGetStaticCapability(NodeInfo *info, uint8_t *cap, uint32_t len);
257 int32_t LnnSetUserIdCheckSum(NodeInfo *info, uint8_t *data, uint32_t len);
258 int32_t LnnGetUserIdCheckSum(NodeInfo *info, uint8_t *data, uint32_t len);
259 int32_t LnnSetPtk(NodeInfo *info, const char *remotePtk);
260 void LnnDumpRemotePtk(const char *oldPtk, const char *newPtk, const char *log);
261 int32_t LnnSetWifiDirectAddr(NodeInfo *info, const char *wifiDirectAddr);
262 const char *LnnGetWifiDirectAddr(const NodeInfo *info);
263 void LnnDumpNodeInfo(const NodeInfo *deviceInfo, const char *log);
264 int32_t LnnSetScreenStatus(NodeInfo *info, bool isScreenOn);
265 #ifdef __cplusplus
266 }
267 #endif
268 
269 #endif // LNN_NODE_INFO_H
270