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