1 /* 2 * Copyright (c) 2025 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 CONN_BR_CONNECTION_STRUCT_H 17 #define CONN_BR_CONNECTION_STRUCT_H 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 #include "common_list.h" 22 #include "softbus_conn_interface_struct.h" 23 #include "softbus_adapter_thread.h" 24 #include "softbus_def.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 #define INVALID_SOCKET_HANDLE (-1) 31 #define MAX_BR_READ_BUFFER_CAPACITY (40 * 1000) 32 #define MAX_BR_MTU_SIZE (3 * 1024) 33 34 #define WAIT_BR_NEGOTIATION_CLOSING_TIMEOUT_MILLIS (3 * 1000) 35 #define RETRY_NOTIFY_REFERENCE_DELAY_MILLIS (1 * 1000) 36 #define BR_CONNECTION_IDLE_DISCONNECT_TIMEOUT_MILLIS (2 * 60 * 60 * 1000) 37 38 #define MAX_RETRY_COUNT (2) 39 40 enum ConnBrConnectionState { 41 BR_CONNECTION_STATE_CONNECTING = 0, 42 BR_CONNECTION_STATE_CONNECTED, 43 BR_CONNECTION_STATE_EXCEPTION, 44 BR_CONNECTION_STATE_NEGOTIATION_CLOSING, 45 BR_CONNECTION_STATE_CLOSING, 46 BR_CONNECTION_STATE_CLOSED, 47 BR_CONNECTION_STATE_INVALID, 48 }; 49 50 typedef struct { 51 ListNode node; 52 uint32_t connectionId; 53 ConnSideType side; 54 char addr[BT_MAC_LEN]; 55 uint32_t mtu; 56 57 uint32_t retryCount; 58 // protect variable access below 59 SoftBusMutex lock; 60 int32_t socketHandle; 61 enum ConnBrConnectionState state; 62 // reference counter that record times required by buziness 63 int32_t connectionRc; 64 // reference counter that record times for memory management 65 int32_t objectRc; 66 67 bool isOccupied; 68 // congestion control 69 int32_t window; 70 int64_t sequence; 71 int64_t waitSequence; 72 int32_t ackTimeoutCount; 73 // connect process status 74 SoftBusList *connectProcessStatus; 75 } ConnBrConnection; 76 77 typedef struct { 78 void (*onServerAccepted)(uint32_t connectionId); 79 void (*onClientConnected)(uint32_t connectionId); 80 void (*onClientConnectFailed)(uint32_t connectionId, int32_t error); 81 void (*onDataReceived)(uint32_t connectionId, uint8_t *data, uint32_t dataLen); 82 void (*onConnectionException)(uint32_t connectionId, int32_t error); 83 void (*onConnectionResume)(uint32_t connectionId); 84 } ConnBrEventListener; 85 86 #ifdef __cplusplus 87 } 88 #endif /* __clpusplus */ 89 #endif /* CONN_BR_CONNECTION_STRUCT_H */ 90