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