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_ID 0 30 31 typedef enum { 32 LANE_BR = 0x0, 33 LANE_BLE, 34 LANE_P2P, 35 LANE_WLAN_2P4G, 36 LANE_WLAN_5G, 37 LANE_ETH, 38 LANE_P2P_REUSE, 39 LANE_BLE_DIRECT, 40 LANE_BLE_REUSE, 41 LANE_COC, 42 LANE_COC_DIRECT, 43 LANE_LINK_TYPE_BUTT, 44 } LaneLinkType; 45 46 typedef enum { 47 LANE_T_CTRL = 0x0, 48 LANE_T_MIX, 49 LANE_T_BYTE, 50 LANE_T_MSG, 51 LANE_T_FILE, 52 LANE_T_RAW_STREAM, 53 LANE_T_COMMON_VIDEO, 54 LANE_T_COMMON_VOICE, 55 LANE_T_BUTT, 56 } LaneTransType; 57 58 typedef enum { 59 LANE_STATE_OK = 0, 60 LANE_STATE_EXCEPTION, 61 } LaneState; 62 63 typedef enum { 64 LANE_REQUEST_INFO_INVALID, 65 LANE_RESOURCE_EXHAUSTED, 66 LANE_LINK_FAILED, 67 } LaneRequestFailReason; 68 69 typedef struct { 70 char brMac[BT_MAC_LEN]; 71 } BrConnInfo; 72 73 typedef struct { 74 BleProtocolType protoType; 75 char bleMac[BT_MAC_LEN]; 76 char deviceIdHash[UDID_HASH_LEN]; 77 int32_t psm; 78 } BleConnInfo; 79 80 typedef struct { 81 BleProtocolType protoType; 82 char nodeIdHash[NODEID_SHORT_HASH_LEN]; 83 char localUdidHash[UDID_SHORT_HASH_LEN]; 84 char peerUdidHash[SHA_256_HASH_LEN]; 85 } BleDirectConnInfo; 86 87 typedef struct { 88 uint16_t protocol; 89 char localIp[IP_LEN]; 90 char peerIp[IP_LEN]; 91 } P2pConnInfo; 92 93 typedef struct { 94 uint16_t protocol; 95 char addr[MAX_SOCKET_ADDR_LEN]; 96 uint16_t port; 97 } WlanConnInfo; 98 99 typedef struct { 100 LaneLinkType type; 101 union { 102 BrConnInfo br; 103 BleConnInfo ble; 104 P2pConnInfo p2p; 105 WlanConnInfo wlan; 106 BleDirectConnInfo bleDirect; 107 } connInfo; 108 } LaneConnInfo; 109 110 typedef struct { 111 void (*OnLaneRequestSuccess)(uint32_t laneId, const LaneConnInfo *info); 112 void (*OnLaneRequestFail)(uint32_t laneId, LaneRequestFailReason reason); 113 void (*OnLaneStateChange)(uint32_t laneId, LaneState state); 114 } ILaneListener; 115 116 typedef enum { 117 LANE_TYPE_HDLC = 0x0, 118 LANE_TYPE_TRANS, 119 LANE_TYPE_CTRL, 120 LANE_TYPE_BUTT, 121 } LaneType; 122 123 typedef enum { 124 QUERY_RESULT_OK = 0, 125 QUERY_RESULT_RESOURCE_LIMIT, 126 QUERY_RESULT_UNKNOWN, 127 QUERY_RESULT_REQUEST_ILLEGAL, 128 } QueryResult; 129 130 typedef struct { 131 char networkId[NETWORK_ID_BUF_LEN]; 132 LaneTransType transType; 133 uint32_t expectedBw; 134 } LaneQueryInfo; 135 136 typedef struct { 137 uint32_t linkTypeNum; 138 LaneLinkType linkType[LANE_LINK_TYPE_BUTT]; 139 } LanePreferredLinkList; 140 141 typedef struct { 142 char networkId[NETWORK_ID_BUF_LEN]; 143 LaneTransType transType; 144 uint32_t expectedBw; 145 int32_t pid; 146 LanePreferredLinkList expectedLink; 147 bool networkDelegate; 148 ProtocolType acceptableProtocols; 149 } TransOption; 150 151 typedef struct { 152 LaneType type; 153 union { 154 TransOption trans; 155 } requestInfo; 156 } LaneRequestOption; 157 158 QueryResult LnnQueryLaneResource(const LaneQueryInfo *queryInfo); 159 uint32_t ApplyLaneId(LaneType type); 160 int32_t LnnRequestLane(uint32_t laneId, const LaneRequestOption *request, const ILaneListener *listener); 161 int32_t LnnFreeLane(uint32_t laneId); 162 163 #ifdef __cplusplus 164 } 165 #endif 166 #endif