• 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 
34 #define LNN_RELATION_MASK 0x03
35 
36 typedef enum {
37     ROLE_UNKNOWN = 0,
38     ROLE_CONTROLLER,
39     ROLE_LEAF,
40 } ConnectRole;
41 
42 typedef enum {
43     STATUS_OFFLINE = 0,
44     STATUS_ONLINE,
45 } ConnectStatus;
46 
47 typedef enum {
48     DISCOVERY_TYPE_UNKNOWN = 0,
49     DISCOVERY_TYPE_WIFI,
50     DISCOVERY_TYPE_BLE,
51     DISCOVERY_TYPE_BR,
52     DISCOVERY_TYPE_P2P,
53     DISCOVERY_TYPE_COUNT,
54 } DiscoveryType;
55 
56 typedef struct {
57     char ssid[WIFI_SSID_LEN + 1];
58     unsigned char targetBssid[WIFI_MAC_LEN];
59 } BssTransInfo;
60 
61 typedef struct {
62     int32_t p2pRole;
63     char p2pMac[MAC_LEN]; // the mac of local p2p interface
64     char goMac[MAC_LEN]; // the mac of p2p Go device, while local device as Gc role.
65 } P2pInfo;
66 
67 typedef struct {
68     bool isMetaNode;
69     uint32_t metaDiscType;
70 } MetaInfo;
71 
72 typedef struct {
73     char softBusVersion[VERSION_MAX_LEN];
74     char versionType[VERSION_MAX_LEN]; // compatible nearby
75     char uuid[UUID_BUF_LEN]; // compatible nearby
76     char networkId[NETWORK_ID_BUF_LEN];
77     char publicId[ID_MAX_LEN];
78     char parentId[ID_MAX_LEN];
79     char masterUdid[UDID_BUF_LEN];
80     char nodeAddress[SHORT_ADDRESS_MAX_LEN];
81     uint8_t relation[CONNECTION_ADDR_MAX];
82     int32_t masterWeight;
83     ConnectRole role;
84     ConnectStatus status;
85     uint32_t netCapacity;
86     uint32_t discoveryType;
87     uint64_t heartbeatTimeStamp;
88     DeviceBasicInfo deviceInfo;
89     ConnectInfo connectInfo;
90     int64_t authSeqNum;
91     int32_t authChannelId[CONNECTION_ADDR_MAX];
92     BssTransInfo bssTransInfo;
93     bool isBleP2p; // true: this device support connect p2p via ble connection
94     P2pInfo p2pInfo;
95     uint64_t supportedProtocols;
96     char accountHash[SHA_256_HASH_LEN];
97     unsigned char offlineCode[OFFLINE_CODE_BYTE_SIZE];
98     int64_t authSeq[DISCOVERY_TYPE_COUNT];
99     MetaInfo metaInfo;
100     uint32_t AuthTypeValue;
101     uint16_t dataChangeFlag;
102 } NodeInfo;
103 
104 const char *LnnGetDeviceUdid(const NodeInfo *info);
105 int32_t LnnSetDeviceUdid(NodeInfo *info, const char *udid);
106 bool LnnHasDiscoveryType(const NodeInfo *info, DiscoveryType type);
107 int32_t LnnSetDiscoveryType(NodeInfo *info, DiscoveryType type);
108 int32_t LnnClearDiscoveryType(NodeInfo *info, DiscoveryType type);
109 bool LnnIsNodeOnline(const NodeInfo *info);
110 void LnnSetNodeConnStatus(NodeInfo *info, ConnectStatus status);
111 const char *LnnGetBtMac(const NodeInfo *info);
112 void LnnSetBtMac(NodeInfo *info, const char *mac);
113 const char *LnnGetWiFiIp(const NodeInfo *info);
114 void LnnSetWiFiIp(NodeInfo *info, const char *ip);
115 const char *LnnGetNetIfName(const NodeInfo *info);
116 void LnnSetNetIfName(NodeInfo *info, const char *netIfName);
117 const char *LnnGetMasterUdid(const NodeInfo *info);
118 int32_t LnnSetMasterUdid(NodeInfo *info, const char *udid);
119 int32_t LnnGetAuthPort(const NodeInfo *info);
120 int32_t LnnSetAuthPort(NodeInfo *info, int32_t port);
121 int32_t LnnGetSessionPort(const NodeInfo *info);
122 int32_t LnnSetSessionPort(NodeInfo *info, int32_t port);
123 int32_t LnnGetProxyPort(const NodeInfo *info);
124 int32_t LnnSetProxyPort(NodeInfo *info, int32_t port);
125 int32_t LnnSetP2pRole(NodeInfo *info, int32_t role);
126 int32_t LnnGetP2pRole(const NodeInfo *info);
127 int32_t LnnSetP2pMac(NodeInfo *info, const char *p2pMac);
128 uint16_t LnnGetDataChangeFlag(const NodeInfo *info);
129 int32_t LnnSetDataChangeFlag(NodeInfo *info, uint16_t dataChangeFlag);
130 const char *LnnGetP2pMac(const NodeInfo *info);
131 int32_t LnnSetP2pGoMac(NodeInfo *info, const char *goMac);
132 const char *LnnGetP2pGoMac(const NodeInfo *info);
133 uint64_t LnnGetSupportedProtocols(const NodeInfo *info);
134 int32_t LnnSetSupportedProtocols(NodeInfo *info, uint64_t protocols);
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif // LNN_NODE_INFO_H
141