1 /* 2 * Copyright (c) 2022-2025 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_LANE_INTERFACE_STRUCT_H 17 #define LNN_LANE_INTERFACE_STRUCT_H 18 19 #include <stdint.h> 20 #include "inner_socket.h" 21 #include "session.h" 22 #include "softbus_common.h" 23 #include "softbus_def.h" 24 #include "softbus_protocol_def.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 #define INVALID_LANE_REQ_ID 0 31 #define INVALID_LANE_ID 0 32 #define LANE_REQ_ID_TYPE_SHIFT 28 33 #define DB_MAGIC_NUMBER 0x5A5A5A5A 34 #define MESH_MAGIC_NUMBER 0xA5A5A5A5 35 36 typedef enum { 37 LANE_BR = 0x0, 38 LANE_BLE, 39 LANE_P2P, 40 LANE_WLAN_2P4G, 41 LANE_WLAN_5G, 42 LANE_ETH, 43 LANE_P2P_REUSE, 44 LANE_BLE_DIRECT, 45 LANE_BLE_REUSE, 46 LANE_COC, 47 LANE_COC_DIRECT, 48 LANE_HML, 49 LANE_HML_RAW, 50 LANE_SLE, 51 LANE_USB, 52 LANE_SLE_DIRECT, 53 LANE_LINK_TYPE_BUTT, 54 } LaneLinkType; 55 56 typedef enum { 57 LANE_T_CTRL = 0x0, 58 LANE_T_MIX, 59 LANE_T_BYTE, 60 LANE_T_MSG, 61 LANE_T_FILE, 62 LANE_T_RAW_STREAM, 63 LANE_T_COMMON_VIDEO, 64 LANE_T_COMMON_VOICE, 65 LANE_T_BUTT, 66 } LaneTransType; 67 68 typedef enum { 69 LANE_STATE_OK = 0, 70 LANE_STATE_LINKUP, 71 LANE_STATE_LINKDOWN, 72 } LaneState; 73 74 typedef enum { 75 LANE_REQUEST_INFO_INVALID, 76 LANE_RESOURCE_EXHAUSTED, 77 LANE_LINK_FAILED, 78 } LaneRequestFailReason; 79 80 typedef enum { 81 LANE_LINK_TYPE_WIFI_WLAN = 1, 82 LANE_LINK_TYPE_WIFI_P2P = 2, 83 LANE_LINK_TYPE_BR = 3, 84 LANE_LINK_TYPE_COC_DIRECT = 4, 85 LANE_LINK_TYPE_BLE_DIRECT = 5, 86 LANE_LINK_TYPE_HML = 6, 87 LANE_LINK_TYPE_SLE_DIRECT = 7, 88 LANE_LINK_TYPE_USB = 8, 89 LANE_LINK_TYPE_MAX, 90 } LaneSpecifiedLink; 91 92 typedef struct { 93 char brMac[BT_MAC_LEN]; 94 } BrConnInfo; 95 96 typedef struct { 97 BleProtocolType protoType; 98 char bleMac[BT_MAC_LEN]; 99 char deviceIdHash[UDID_HASH_LEN]; 100 int32_t psm; 101 } BleConnInfo; 102 103 typedef struct { 104 BleProtocolType protoType; 105 char networkId[NETWORK_ID_BUF_LEN]; 106 } BleDirectConnInfo; 107 108 typedef struct { 109 SleProtocolType protoType; 110 char networkId[NETWORK_ID_BUF_LEN]; 111 } SleDirectConnInfo; 112 113 typedef struct { 114 SleProtocolType protoType; 115 char sleMac[SLE_MAC_LEN]; 116 char deviceIdHash[UDID_HASH_LEN]; 117 } SleConnInfo; 118 119 typedef struct { 120 uint16_t protocol; 121 char localIp[IP_LEN]; 122 char peerIp[IP_LEN]; 123 } P2pConnInfo; 124 125 typedef struct { 126 ProtocolType protocol; 127 char addr[MAX_SOCKET_ADDR_LEN]; 128 uint16_t port; 129 } WlanConnInfo; 130 131 typedef struct { 132 ProtocolType protocol; 133 char addr[MAX_SOCKET_ADDR_LEN]; 134 uint16_t port; 135 } UsbConnInfo; 136 137 typedef struct { 138 bool isReuse; 139 int32_t pid; 140 141 char localIp[IP_LEN]; 142 char peerIp[IP_LEN]; 143 uint16_t protocol; 144 145 // localIpv6 and remoteIpv6 is only used with port 146 char localIpv6[IP_LEN]; 147 char peerIpv6[IP_LEN]; 148 int32_t port; 149 } RawWifiDirectConnInfo; 150 151 typedef struct { 152 uint64_t laneId; 153 LaneLinkType type; 154 bool isLowLatency; 155 union { 156 BrConnInfo br; 157 BleConnInfo ble; 158 P2pConnInfo p2p; 159 WlanConnInfo wlan; 160 BleDirectConnInfo bleDirect; 161 RawWifiDirectConnInfo rawWifiDirect; 162 UsbConnInfo usb; 163 SleConnInfo sle; 164 SleDirectConnInfo sleDirect; 165 } connInfo; 166 } LaneConnInfo; 167 168 typedef enum { 169 LANE_OWNER_SELF = 0x0, 170 LANE_OWNER_OTHER, 171 LANE_OWNER_BUTT, 172 } LaneOwner; 173 174 typedef enum { 175 LANE_QOS_BW_HIGH = 0x0, 176 LANE_QOS_BW_MID, 177 LANE_QOS_BW_LOW, 178 LANE_QOS_BW_BUTT, 179 } LaneQosEvent; 180 181 typedef struct { 182 void (*onLaneAllocSuccess)(uint32_t laneHandle, const LaneConnInfo *info); 183 void (*onLaneAllocFail)(uint32_t laneHandle, int32_t errCode); 184 void (*onLaneFreeSuccess)(uint32_t laneHandle); 185 void (*onLaneFreeFail)(uint32_t laneHandle, int32_t errCode); 186 void (*onLaneQosEvent)(uint32_t laneHandle, LaneOwner laneOwner, LaneQosEvent qosEvent); 187 } LaneAllocListener; 188 189 typedef struct { 190 void (*onLaneRequestSuccess)(uint32_t laneReqId, const LaneConnInfo *info); 191 void (*onLaneRequestFail)(uint32_t laneReqId, int32_t errCode); 192 } ILaneListener; 193 194 typedef enum { 195 LANE_TYPE_HDLC = 0x0, 196 LANE_TYPE_TRANS, 197 LANE_TYPE_CTRL, 198 LANE_TYPE_BUTT, 199 } LaneType; 200 201 typedef enum { 202 QUERY_RESULT_OK = 0, 203 QUERY_RESULT_RESOURCE_LIMIT, 204 QUERY_RESULT_UNKNOWN, 205 QUERY_RESULT_REQUEST_ILLEGAL, 206 } QueryResult; 207 208 typedef enum { 209 LANE_RTT_LEVEL_DEFAULT = 0, 210 LANE_RTT_LEVEL_LOW = 1, 211 } LaneRttLevel; 212 213 typedef struct { 214 char networkId[NETWORK_ID_BUF_LEN]; 215 LaneTransType transType; 216 } LaneQueryInfo; 217 218 typedef struct { 219 uint32_t linkTypeNum; 220 LaneLinkType linkType[LANE_LINK_TYPE_BUTT]; 221 } LanePreferredLinkList; 222 223 typedef struct { 224 uint32_t minBW; 225 uint32_t maxLaneLatency; 226 uint32_t minLaneLatency; 227 LaneRttLevel rttLevel; 228 bool continuousTask; 229 bool reuseBestEffort; 230 bool ratePreference; 231 } QosInfo; 232 233 typedef struct { 234 char localMac[MAX_MAC_LEN]; 235 char remoteMac[MAX_MAC_LEN]; 236 } LnnMacInfo; 237 238 typedef struct { 239 char networkId[NETWORK_ID_BUF_LEN]; 240 char peerBleMac[MAX_MAC_LEN]; 241 bool networkDelegate; 242 bool p2pOnly; 243 bool isSupportIpv6; 244 bool isInnerCalled; // Indicates whether to select a link for TransOpenNetWorkingChannel 245 LaneTransType transType; 246 ProtocolType acceptableProtocols; 247 int32_t pid; 248 //'psm' is valid only when 'expectedlink' contains 'LANE_COC' 249 int32_t psm; 250 uint32_t expectedBw; 251 uint32_t actionAddr; 252 LanePreferredLinkList expectedLink; 253 } TransOption; 254 255 typedef struct { 256 LaneType type; 257 union { 258 TransOption trans; 259 } requestInfo; 260 } LaneRequestOption; 261 262 typedef struct { 263 LaneType type; 264 LaneTransType transType; 265 uint32_t actionAddr; 266 QosInfo qosRequire; 267 } RawLaneAllocInfo; 268 269 typedef struct { 270 void (*onLaneLinkup)(uint64_t laneId, const char *peerUdid, const LaneConnInfo *laneConnInfo); 271 void (*onLaneLinkdown)(uint64_t laneId, const char *peerUdid, const LaneConnInfo *laneConnInfo); 272 void (*onLaneStateChange)(uint64_t laneId, LaneState state); 273 } LaneStatusListener; 274 275 typedef struct { 276 char peerBleMac[MAX_MAC_LEN]; 277 bool networkDelegate; 278 bool isSpecifiedLink; 279 bool isSupportIpv6; 280 LaneSpecifiedLink linkType; 281 uint32_t actionAddr; 282 TransFlowInfo flowInfo; 283 bool isVirtualLink; 284 } AllocExtendInfo; 285 286 typedef struct { 287 char networkId[NETWORK_ID_BUF_LEN]; 288 LaneType type; 289 LaneTransType transType; 290 int32_t pid; 291 ProtocolType acceptableProtocols; 292 QosInfo qosRequire; 293 AllocExtendInfo extendInfo; 294 } LaneAllocInfo; 295 296 typedef struct { 297 char networkId[NETWORK_ID_BUF_LEN]; 298 bool isSupportIpv6; 299 LaneTransType transType; 300 uint32_t actionAddr; 301 bool isVirtualLink; 302 } LaneAllocCommInfo; 303 304 typedef struct { 305 LaneType type; 306 LanePreferredLinkList linkList; 307 LaneAllocCommInfo commInfo; 308 } LaneAllocInfoExt; 309 310 typedef struct { 311 int32_t (*lnnQueryLaneResource)(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo); 312 uint32_t (*lnnGetLaneHandle)(LaneType type); 313 int32_t (*lnnAllocLane)(uint32_t laneHandle, const LaneAllocInfo *allocInfo, const LaneAllocListener *listener); 314 int32_t (*lnnAllocRawLane)(uint32_t laneHandle, const RawLaneAllocInfo *request, 315 const LaneAllocListener *listener); 316 int32_t (*lnnReAllocLane)(uint32_t laneHandle, uint64_t laneId, const LaneAllocInfo *allocInfo, 317 const LaneAllocListener *listener); 318 int32_t (*lnnAllocTargetLane)(uint32_t laneHandle, const LaneAllocInfoExt *allocInfo, 319 const LaneAllocListener *listener); 320 int32_t (*lnnCancelLane)(uint32_t laneHandle); 321 int32_t (*lnnFreeLane)(uint32_t laneHandle); 322 int32_t (*registerLaneListener)(LaneType type, const LaneStatusListener *listener); 323 int32_t (*unRegisterLaneListener)(LaneType type); 324 } LnnLaneManager; 325 326 #ifdef __cplusplus 327 } 328 #endif 329 #endif // LNN_LANE_INTERFACE_STRUCT_H