• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_NODE_INFO_H
17 #define LNN_NODE_INFO_H
18 
19 #include <stdbool.h>
20 #include <stdint.h>
21 
22 #include "lnn_connect_info.h"
23 #include "lnn_device_info.h"
24 #include "lnn_net_capability.h"
25 #include "softbus_def.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 #define WIFI_SSID_LEN 32
31 #define WIFI_MAC_LEN 6
32 #define OFFLINE_CODE_LEN 32
33 #define OFFLINE_CODE_BYTE_SIZE 4
34 #define EXTDATA_LEN 8
35 #define PTK_DEFAULT_LEN 32
36 #define STATIC_CAP_LEN 100
37 #define STATIC_CAP_STR_LEN 201
38 #define PTK_ENCODE_LEN 45
39 
40 #define LNN_RELATION_MASK 0x03
41 #define WIFI_CFG_INFO_MAX_LEN 512
42 #define CHANNEL_LIST_STR_LEN  256
43 
44 #define SESSION_KEY_STR_LEN 65
45 
46 #define BROADCAST_IV_LEN 16
47 #define BROADCAST_IV_STR_LEN 33
48 
49 #define LFINDER_UDID_HASH_LEN 32
50 #define LFINDER_IRK_LEN 16
51 #define LFINDER_IRK_STR_LEN 33
52 #define LFINDER_MAC_ADDR_LEN 6
53 #define LFINDER_MAC_ADDR_STR_LEN 13
54 
55 typedef enum {
56     AUTH_AS_CLIENT_SIDE = 0,
57     AUTH_AS_SERVER_SIDE,
58     AUTH_SIDE_MAX,
59 } AuthSide;
60 
61 typedef enum {
62     ROLE_UNKNOWN = 0,
63     ROLE_CONTROLLER,
64     ROLE_LEAF,
65 } ConnectRole;
66 
67 typedef enum {
68     STATUS_OFFLINE = 0,
69     STATUS_ONLINE,
70 } ConnectStatus;
71 
72 typedef enum {
73     DISCOVERY_TYPE_UNKNOWN = 0,
74     DISCOVERY_TYPE_WIFI,
75     DISCOVERY_TYPE_BLE,
76     DISCOVERY_TYPE_BR,
77     DISCOVERY_TYPE_P2P,
78     DISCOVERY_TYPE_LSA,
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 } AuthCapability;
110 
111 typedef struct {
112     int32_t keylen;
113     unsigned char key[SESSION_KEY_LENGTH];
114     unsigned char iv[BROADCAST_IV_LEN];
115 } BroadcastCipherInfo;
116 
117 typedef struct {
118     uint8_t peerIrk[LFINDER_IRK_LEN];
119     unsigned char publicAddress[LFINDER_MAC_ADDR_LEN];
120     unsigned char peerUdidHash[LFINDER_UDID_HASH_LEN];
121 } RpaInfo;
122 
123 typedef struct {
124     char softBusVersion[VERSION_MAX_LEN];
125     char versionType[VERSION_MAX_LEN]; // compatible nearby
126     char pkgVersion[VERSION_MAX_LEN];
127     char uuid[UUID_BUF_LEN]; // compatible nearby
128     char networkId[NETWORK_ID_BUF_LEN];
129     char publicId[ID_MAX_LEN];
130     char parentId[ID_MAX_LEN];
131     char masterUdid[UDID_BUF_LEN];
132     char nodeAddress[SHORT_ADDRESS_MAX_LEN];
133     char extData[EXTDATA_LEN];
134     int32_t masterWeight;
135     ConnectRole role;
136     ConnectStatus status;
137     uint32_t netCapacity;
138     uint32_t authCapacity;
139     uint32_t discoveryType;
140     DeviceBasicInfo deviceInfo;
141     ConnectInfo connectInfo;
142     int64_t authSeqNum;
143     int32_t authChannelId[CONNECTION_ADDR_MAX][AUTH_SIDE_MAX];
144     BssTransInfo bssTransInfo;
145     bool isBleP2p; // true: this device support connect p2p via ble connection
146     P2pInfo p2pInfo;
147     char wifiDirectAddr[MAC_LEN];
148     uint64_t supportedProtocols;
149     char accountHash[SHA_256_HASH_LEN];
150     int64_t accountId;
151     unsigned char offlineCode[OFFLINE_CODE_BYTE_SIZE];
152     int64_t authSeq[DISCOVERY_TYPE_COUNT];
153     MetaInfo metaInfo;
154     uint32_t AuthTypeValue;
155     uint16_t dataChangeFlag;
156     BatteryInfo batteryInfo;
157     bool isScreenOn;
158     int64_t wifiVersion;
159     int64_t bleVersion;
160     uint64_t feature;
161     uint64_t connSubFeature;
162     int64_t bleStartTimestamp;
163     int32_t wifiBuffSize;
164     int32_t brBuffSize;
165     int32_t stateVersion;
166     int32_t localStateVersion;
167     int32_t groupType;
168     bool initPreventFlag;
169     int64_t networkIdTimestamp;
170     RpaInfo rpaInfo;
171     BroadcastCipherInfo cipherInfo;
172     int32_t bleMacRefreshSwitch;
173     int32_t bleConnCloseDelayTime;
174     uint8_t staticCapability[STATIC_CAP_LEN];
175     int32_t staticCapLen;
176     char remotePtk[PTK_DEFAULT_LEN];
177     uint8_t relation[CONNECTION_ADDR_MAX];
178     uint64_t heartbeatTimestamp;
179     uint64_t bleDirectTimestamp;
180     uint64_t onlinetTimestamp;
181 } NodeInfo;
182 
183 const char *LnnGetDeviceUdid(const NodeInfo *info);
184 int32_t LnnSetDeviceUdid(NodeInfo *info, const char *udid);
185 const char *LnnGetDeviceUuid(const NodeInfo *info);
186 bool LnnHasDiscoveryType(const NodeInfo *info, DiscoveryType type);
187 int32_t LnnSetDiscoveryType(NodeInfo *info, DiscoveryType type);
188 int32_t LnnClearDiscoveryType(NodeInfo *info, DiscoveryType type);
189 bool LnnIsNodeOnline(const NodeInfo *info);
190 void LnnSetNodeConnStatus(NodeInfo *info, ConnectStatus status);
191 const char *LnnGetBtMac(const NodeInfo *info);
192 void LnnSetBtMac(NodeInfo *info, const char *mac);
193 const char *LnnGetBleMac(const NodeInfo *info);
194 void LnnSetBleMac(NodeInfo *info, const char *mac);
195 const char *LnnGetWiFiIp(const NodeInfo *info);
196 void LnnSetWiFiIp(NodeInfo *info, const char *ip);
197 const char *LnnGetNetIfName(const NodeInfo *info);
198 void LnnSetNetIfName(NodeInfo *info, const char *netIfName);
199 const char *LnnGetMasterUdid(const NodeInfo *info);
200 int32_t LnnSetMasterUdid(NodeInfo *info, const char *udid);
201 int32_t LnnGetAuthPort(const NodeInfo *info);
202 int32_t LnnSetAuthPort(NodeInfo *info, int32_t port);
203 int32_t LnnGetSessionPort(const NodeInfo *info);
204 int32_t LnnSetSessionPort(NodeInfo *info, int32_t port);
205 int32_t LnnGetProxyPort(const NodeInfo *info);
206 int32_t LnnSetProxyPort(NodeInfo *info, int32_t port);
207 int32_t LnnSetP2pRole(NodeInfo *info, int32_t role);
208 int32_t LnnGetP2pRole(const NodeInfo *info);
209 int32_t LnnSetWifiCfg(NodeInfo *info, const char *wifiCfg);
210 const char *LnnGetWifiCfg(const NodeInfo *info);
211 int32_t LnnSetChanList5g(NodeInfo *info, const char *chanList5g);
212 const char *LnnGetChanList5g(const NodeInfo *info);
213 int32_t LnnSetStaFrequency(NodeInfo *info, int32_t staFrequency);
214 int32_t LnnGetStaFrequency(const NodeInfo *info);
215 int32_t LnnSetP2pMac(NodeInfo *info, const char *p2pMac);
216 uint16_t LnnGetDataChangeFlag(const NodeInfo *info);
217 int32_t LnnSetDataChangeFlag(NodeInfo *info, uint16_t dataChangeFlag);
218 const char *LnnGetP2pMac(const NodeInfo *info);
219 int32_t LnnSetP2pGoMac(NodeInfo *info, const char *goMac);
220 const char *LnnGetP2pGoMac(const NodeInfo *info);
221 uint64_t LnnGetSupportedProtocols(const NodeInfo *info);
222 int32_t LnnSetSupportedProtocols(NodeInfo *info, uint64_t protocols);
223 int32_t LnnSetStaticCapability(NodeInfo *info, uint8_t *cap, uint32_t len);
224 int32_t LnnGetStaticCapability(NodeInfo *info, uint8_t *cap, uint32_t len);
225 int32_t LnnSetPtk(NodeInfo *info, const char *remotePtk);
226 int32_t LnnSetWifiDirectAddr(NodeInfo *info, const char *wifiDirectAddr);
227 const char *LnnGetWifiDirectAddr(const NodeInfo *info);
228 #ifdef __cplusplus
229 }
230 #endif
231 
232 #endif // LNN_NODE_INFO_H
233