• 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 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 #define WIFI_SSID_LEN 32
30 #define WIFI_MAC_LEN 6
31 #define OFFLINE_CODE_LEN 32
32 #define OFFLINE_CODE_BYTE_SIZE 4
33 #define EXTDATA_LEN 8
34 
35 #define LNN_RELATION_MASK 0x03
36 #define WIFI_CFG_INFO_MAX_LEN 512
37 #define CHANNEL_LIST_STR_LEN  256
38 
39 typedef enum {
40     ROLE_UNKNOWN = 0,
41     ROLE_CONTROLLER,
42     ROLE_LEAF,
43 } ConnectRole;
44 
45 typedef enum {
46     STATUS_OFFLINE = 0,
47     STATUS_ONLINE,
48 } ConnectStatus;
49 
50 typedef enum {
51     DISCOVERY_TYPE_UNKNOWN = 0,
52     DISCOVERY_TYPE_WIFI,
53     DISCOVERY_TYPE_BLE,
54     DISCOVERY_TYPE_BR,
55     DISCOVERY_TYPE_P2P,
56     DISCOVERY_TYPE_LSA,
57     DISCOVERY_TYPE_COUNT,
58 } DiscoveryType;
59 
60 typedef struct {
61     char ssid[WIFI_SSID_LEN + 1];
62     unsigned char targetBssid[WIFI_MAC_LEN];
63 } BssTransInfo;
64 
65 typedef struct {
66     int32_t p2pRole;
67     char wifiCfg[WIFI_CFG_INFO_MAX_LEN];
68     char chanList5g[CHANNEL_LIST_STR_LEN];
69     int32_t staFrequency;
70     char p2pMac[MAC_LEN]; // the mac of local p2p interface
71     char goMac[MAC_LEN]; // the mac of p2p Go device, while local device as Gc role.
72 } P2pInfo;
73 
74 typedef struct {
75     bool isMetaNode;
76     uint32_t metaDiscType;
77 } MetaInfo;
78 
79 typedef struct {
80     bool isCharging;
81     int32_t batteryLevel;
82 } BatteryInfo;
83 
84 typedef struct {
85     char softBusVersion[VERSION_MAX_LEN];
86     char versionType[VERSION_MAX_LEN]; // compatible nearby
87     char pkgVersion[VERSION_MAX_LEN];
88     char uuid[UUID_BUF_LEN]; // compatible nearby
89     char networkId[NETWORK_ID_BUF_LEN];
90     char publicId[ID_MAX_LEN];
91     char parentId[ID_MAX_LEN];
92     char masterUdid[UDID_BUF_LEN];
93     char nodeAddress[SHORT_ADDRESS_MAX_LEN];
94     char extData[EXTDATA_LEN];
95     uint8_t relation[CONNECTION_ADDR_MAX];
96     int32_t masterWeight;
97     ConnectRole role;
98     ConnectStatus status;
99     uint32_t netCapacity;
100     uint32_t discoveryType;
101     uint64_t heartbeatTimeStamp;
102     DeviceBasicInfo deviceInfo;
103     ConnectInfo connectInfo;
104     int64_t authSeqNum;
105     int32_t authChannelId[CONNECTION_ADDR_MAX];
106     BssTransInfo bssTransInfo;
107     bool isBleP2p; // true: this device support connect p2p via ble connection
108     P2pInfo p2pInfo;
109     char wifiDirectAddr[MAC_LEN];
110     uint64_t supportedProtocols;
111     char accountHash[SHA_256_HASH_LEN];
112     int64_t accountId;
113     unsigned char offlineCode[OFFLINE_CODE_BYTE_SIZE];
114     int64_t authSeq[DISCOVERY_TYPE_COUNT];
115     MetaInfo metaInfo;
116     uint32_t AuthTypeValue;
117     uint16_t dataChangeFlag;
118     BatteryInfo batteryInfo;
119     bool isScreenOn;
120     int64_t wifiVersion;
121     int64_t bleVersion;
122     uint64_t feature;
123     int64_t bleStartTimestamp;
124     uint64_t onlinetTimestamp;
125     int32_t wifiBuffSize;
126     int32_t brBuffSize;
127     int32_t stateVersion;
128     int32_t localStateVersion;
129     int32_t groupType;
130     bool initPreventFlag;
131 } NodeInfo;
132 
133 const char *LnnGetDeviceUdid(const NodeInfo *info);
134 int32_t LnnSetDeviceUdid(NodeInfo *info, const char *udid);
135 const char *LnnGetDeviceUuid(const NodeInfo *info);
136 bool LnnHasDiscoveryType(const NodeInfo *info, DiscoveryType type);
137 int32_t LnnSetDiscoveryType(NodeInfo *info, DiscoveryType type);
138 int32_t LnnClearDiscoveryType(NodeInfo *info, DiscoveryType type);
139 bool LnnIsNodeOnline(const NodeInfo *info);
140 void LnnSetNodeConnStatus(NodeInfo *info, ConnectStatus status);
141 const char *LnnGetBtMac(const NodeInfo *info);
142 void LnnSetBtMac(NodeInfo *info, const char *mac);
143 const char *LnnGetWiFiIp(const NodeInfo *info);
144 void LnnSetWiFiIp(NodeInfo *info, const char *ip);
145 const char *LnnGetNetIfName(const NodeInfo *info);
146 void LnnSetNetIfName(NodeInfo *info, const char *netIfName);
147 const char *LnnGetMasterUdid(const NodeInfo *info);
148 int32_t LnnSetMasterUdid(NodeInfo *info, const char *udid);
149 int32_t LnnGetAuthPort(const NodeInfo *info);
150 int32_t LnnSetAuthPort(NodeInfo *info, int32_t port);
151 int32_t LnnGetSessionPort(const NodeInfo *info);
152 int32_t LnnSetSessionPort(NodeInfo *info, int32_t port);
153 int32_t LnnGetProxyPort(const NodeInfo *info);
154 int32_t LnnSetProxyPort(NodeInfo *info, int32_t port);
155 int32_t LnnSetP2pRole(NodeInfo *info, int32_t role);
156 int32_t LnnGetP2pRole(const NodeInfo *info);
157 int32_t LnnSetWifiCfg(NodeInfo *info, const char *wifiCfg);
158 const char *LnnGetWifiCfg(const NodeInfo *info);
159 int32_t LnnSetChanList5g(NodeInfo *info, const char *chanList5g);
160 const char *LnnGetChanList5g(const NodeInfo *info);
161 int32_t LnnSetStaFrequency(NodeInfo *info, int32_t staFrequency);
162 int32_t LnnGetStaFrequency(const NodeInfo *info);
163 int32_t LnnSetP2pMac(NodeInfo *info, const char *p2pMac);
164 uint16_t LnnGetDataChangeFlag(const NodeInfo *info);
165 int32_t LnnSetDataChangeFlag(NodeInfo *info, uint16_t dataChangeFlag);
166 const char *LnnGetP2pMac(const NodeInfo *info);
167 int32_t LnnSetP2pGoMac(NodeInfo *info, const char *goMac);
168 const char *LnnGetP2pGoMac(const NodeInfo *info);
169 uint64_t LnnGetSupportedProtocols(const NodeInfo *info);
170 int32_t LnnSetSupportedProtocols(NodeInfo *info, uint64_t protocols);
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif // LNN_NODE_INFO_H
177