1 /* 2 * Copyright (c) 2021-2024 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 TRANS_UDP_CHANNEL_MANAGER_H 17 #define TRANS_UDP_CHANNEL_MANAGER_H 18 19 #include <stdint.h> 20 #include "softbus_app_info.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 typedef enum { 27 UDP_CHANNEL_STATUS_INIT = 0, 28 UDP_CHANNEL_STATUS_OPEN_AUTH, 29 UDP_CHANNEL_STATUS_NEGING, 30 UDP_CHANNEL_STATUS_DONE 31 } UdpChannelStatus; 32 33 typedef struct { 34 ListNode node; 35 int64_t seq; 36 AppInfo info; 37 uint32_t timeOut; 38 UdpChannelStatus status; 39 uint32_t requestId; 40 bool isMeta; 41 int32_t errCode; 42 uint8_t tos; 43 } UdpChannelInfo; 44 45 typedef struct { 46 ListNode node; 47 int64_t channelId; 48 int pid; 49 char pkgName[PKG_NAME_SIZE_MAX]; 50 } UdpChannelNotifyInfo; 51 52 SoftBusList *GetUdpChannelMgrHead(void); 53 54 int32_t TransUdpChannelMgrInit(void); 55 void TransUdpChannelMgrDeinit(void); 56 57 int32_t GetUdpChannelLock(void); 58 void ReleaseUdpChannelLock(void); 59 60 int32_t TransAddUdpChannel(UdpChannelInfo *channel); 61 int32_t TransDelUdpChannel(int32_t channelId); 62 void TransCloseUdpChannelByNetWorkId(const char* netWorkId); 63 64 int32_t TransGetUdpChannelBySeq(int64_t seq, UdpChannelInfo *channel); 65 int32_t TransGetUdpChannelById(int32_t channelId, UdpChannelInfo *channel); 66 int32_t TransGetUdpChannelByRequestId(uint32_t requestId, UdpChannelInfo *channel); 67 68 int32_t TransSetUdpChannelStatus(int64_t seq, UdpChannelStatus status); 69 int32_t TransSetUdpChannelOptType(int32_t channelId, UdpChannelOptType type); 70 71 int32_t TransUdpGetNameByChanId(int32_t channelId, char *pkgName, char *sessionName, 72 uint16_t pkgNameLen, uint16_t sessionNameLen); 73 74 void TransUpdateUdpChannelInfo(int64_t seq, const AppInfo *appInfo); 75 76 UdpChannelInfo *TransGetChannelObj(int32_t channelId); 77 78 int32_t TransGetUdpAppInfoByChannelId(int32_t channelId, AppInfo *appInfo); 79 int32_t TransUdpGetChannelIdByAddr(AppInfo *appInfo); 80 81 int32_t UdpChannelFileTransLimit(const ChannelInfo *channel, uint8_t tos); 82 83 int32_t UdpChannelFileTransRecoveryLimit(uint8_t tos); 84 85 bool IsUdpRecoveryTransLimit(void); 86 87 int32_t TransUdpGetIpAndConnectTypeById(int32_t channelId, char *localIp, char *remoteIp, uint32_t maxIpLen, 88 int32_t *connectType); 89 90 #ifdef __cplusplus 91 } 92 #endif 93 94 #endif // !TRANS_UDP_CHANNEL_MANAGER_H