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