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