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 struct { 134 void (*onLaneAllocSuccess)(uint32_t laneHandle, const LaneConnInfo *info); 135 void (*onLaneAllocFail)(uint32_t laneHandle, int32_t errCode); 136 void (*onLaneFreeSuccess)(uint32_t laneHandle); 137 void (*onLaneFreeFail)(uint32_t laneHandle, int32_t errCode); 138 } LaneAllocListener; 139 140 typedef struct { 141 void (*onLaneRequestSuccess)(uint32_t laneReqId, const LaneConnInfo *info); 142 void (*onLaneRequestFail)(uint32_t laneReqId, int32_t errCode); 143 } ILaneListener; 144 145 typedef enum { 146 LANE_TYPE_HDLC = 0x0, 147 LANE_TYPE_TRANS, 148 LANE_TYPE_CTRL, 149 LANE_TYPE_BUTT, 150 } LaneType; 151 152 typedef enum { 153 QUERY_RESULT_OK = 0, 154 QUERY_RESULT_RESOURCE_LIMIT, 155 QUERY_RESULT_UNKNOWN, 156 QUERY_RESULT_REQUEST_ILLEGAL, 157 } QueryResult; 158 159 typedef enum { 160 LANE_RTT_LEVEL_DEFAULT = 0, 161 LANE_RTT_LEVEL_LOW = 1, 162 } LaneRttLevel; 163 164 typedef struct { 165 char networkId[NETWORK_ID_BUF_LEN]; 166 LaneTransType transType; 167 } LaneQueryInfo; 168 169 typedef struct { 170 uint32_t linkTypeNum; 171 LaneLinkType linkType[LANE_LINK_TYPE_BUTT]; 172 } LanePreferredLinkList; 173 174 typedef struct { 175 uint32_t minBW; 176 uint32_t maxLaneLatency; 177 uint32_t minLaneLatency; 178 LaneRttLevel rttLevel; 179 } QosInfo; 180 181 typedef struct { 182 char localMac[MAX_MAC_LEN]; 183 char remoteMac[MAX_MAC_LEN]; 184 } LnnMacInfo; 185 186 typedef struct { 187 char networkId[NETWORK_ID_BUF_LEN]; 188 LaneTransType transType; 189 bool networkDelegate; 190 bool p2pOnly; 191 ProtocolType acceptableProtocols; 192 int32_t pid; 193 char peerBleMac[MAX_MAC_LEN]; 194 //'psm' is valid only when 'expectedlink' contains 'LANE_COC' 195 int32_t psm; 196 uint32_t expectedBw; 197 LanePreferredLinkList expectedLink; 198 uint32_t actionAddr; 199 bool isSupportIpv6; 200 } TransOption; 201 202 typedef struct { 203 LaneType type; 204 union { 205 TransOption trans; 206 } requestInfo; 207 } LaneRequestOption; 208 209 typedef struct { 210 LaneType type; 211 LaneTransType transType; 212 QosInfo qosRequire; 213 uint32_t actionAddr; 214 uint8_t udidHash[UDID_HASH_LEN]; 215 } RawLaneAllocInfo; 216 217 typedef struct { 218 void (*onLaneLinkup)(uint64_t laneId, const char *peerUdid, const LaneConnInfo *laneConnInfo); 219 void (*onLaneLinkdown)(uint64_t laneId, const char *peerUdid, const LaneConnInfo *laneConnInfo); 220 void (*onLaneStateChange)(uint64_t laneId, LaneState state); 221 } LaneStatusListener; 222 223 typedef struct { 224 char peerBleMac[MAX_MAC_LEN]; 225 bool networkDelegate; 226 bool isSpecifiedLink; 227 LaneSpecifiedLink linkType; 228 uint32_t actionAddr; 229 bool isSupportIpv6; 230 } AllocExtendInfo; 231 232 typedef struct { 233 LaneType type; 234 char networkId[NETWORK_ID_BUF_LEN]; 235 QosInfo qosRequire; 236 LaneTransType transType; 237 int32_t pid; 238 ProtocolType acceptableProtocols; 239 AllocExtendInfo extendInfo; 240 } LaneAllocInfo; 241 242 typedef struct { 243 char networkId[NETWORK_ID_BUF_LEN]; 244 LaneTransType transType; 245 } LaneAllocCommInfo; 246 247 typedef struct { 248 LaneType type; 249 LaneAllocCommInfo commInfo; 250 LanePreferredLinkList linkList; 251 } LaneAllocInfoExt; 252 253 typedef struct { 254 int32_t (*lnnQueryLaneResource)(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo); 255 uint32_t (*lnnGetLaneHandle)(LaneType type); 256 int32_t (*lnnAllocLane)(uint32_t laneHandle, const LaneAllocInfo *allocInfo, const LaneAllocListener *listener); 257 int32_t (*lnnAllocRawLane)(uint32_t laneRequestId, const RawLaneAllocInfo *request, 258 const LaneAllocListener *listener); 259 int32_t (*lnnReAllocLane)(uint32_t laneHandle, uint64_t laneId, const LaneAllocInfo *allocInfo, 260 const LaneAllocListener *listener); 261 int32_t (*lnnAllocTargetLane)(uint32_t laneHandle, const LaneAllocInfoExt *allocInfo, 262 const LaneAllocListener *listener); 263 int32_t (*lnnCancelLane)(uint32_t laneHandle); 264 int32_t (*lnnFreeLane)(uint32_t laneHandle); 265 int32_t (*registerLaneListener)(LaneType type, const LaneStatusListener *listener); 266 int32_t (*unRegisterLaneListener)(LaneType type); 267 } LnnLaneManager; 268 269 LnnLaneManager* GetLaneManager(void); 270 271 int32_t LnnQueryLaneResource(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo); 272 uint32_t ApplyLaneReqId(LaneType type); 273 int32_t LnnRequestLane(uint32_t laneReqId, const LaneRequestOption *request, const ILaneListener *listener); 274 int32_t LnnFreeLane(uint32_t laneReqId); 275 int32_t GetMacInfoByLaneId(uint64_t laneId, LnnMacInfo *macInfo); 276 277 #ifdef __cplusplus 278 } 279 #endif 280 #endif // LNN_LANE_INTERFACE_H 281