1 /* 2 * Copyright (c) 2022-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 CLIENT_TRANS_PROXY_FILE_MANAGER_H 17 #define CLIENT_TRANS_PROXY_FILE_MANAGER_H 18 19 #include "client_trans_file_listener.h" 20 #include "client_trans_proxy_file_common.h" 21 22 #ifdef __linux__ 23 #define MAX_SEND_FILE_NUM 10 24 #else 25 #define MAX_SEND_FILE_NUM 1 26 #endif 27 #define MAX_FILE_SIZE (0x500000) /* 5M */ 28 29 #define DEFAULT_NEW_PATH_AUTHORITY (0750) 30 31 #define INVALID_NODE_INDEX (-1) 32 33 #define FILE_MAGIC_NUMBER 0xBABEFACE 34 35 #define PROXY_BR_MAX_PACKET_SIZE (4096 - 48) 36 #define PROXY_BLE_MAX_PACKET_SIZE (1024 - 48) 37 38 #define FRAME_MAGIC_OFFSET 4 39 #define FRAME_LEN_OFFSET 8 40 #define FRAME_HEAD_LEN (FRAME_MAGIC_OFFSET + FRAME_LEN_OFFSET) 41 #define FRAME_DATA_SEQ_OFFSET 4 42 #define FRAME_CRC_LEN 2 43 #define FRAME_CRC_CHECK_NUM_LEN 8 44 45 #define IS_SEND_RESULT 1 46 #define IS_RECV_RESULT 0 47 48 #define FILE_SEND_ACK_RESULT_SUCCESS 0xFFFFFFFF 49 #define FILE_SEND_ACK_INTERVAL 32 50 #define WAIT_START_ACK_TIME 20000 51 #define WAIT_ACK_TIME 200 52 #define WAIT_ACK_LAST_TIME 5000 53 #define WAIT_FRAME_ACK_TIMEOUT_COUNT 24 54 55 #ifdef __cplusplus 56 extern "C" { 57 #endif 58 59 typedef enum { 60 TRANS_FILE_RECV_IDLE_STATE = 0, 61 TRANS_FILE_RECV_START_STATE, 62 TRANS_FILE_RECV_PROCESS_STATE, 63 TRANS_FILE_RECV_ERR_STATE, 64 } FileRecvState; 65 66 typedef enum { 67 NODE_IDLE, 68 NODE_BUSY, 69 NODE_ERR, 70 } RecvFileNodeStatus; 71 72 typedef struct { 73 uint32_t magic; 74 int32_t frameType; 75 uint32_t frameLength; 76 uint32_t seq; 77 uint16_t crc; 78 uint8_t *data; 79 uint8_t *fileData; 80 } FileFrame; 81 82 typedef struct { 83 SoftBusMutex lock; 84 _Atomic uint32_t lockInitFlag; 85 } TransFileInfoLock; 86 87 typedef struct { 88 ListNode node; 89 int32_t channelId; 90 uint32_t count; 91 SoftBusMutex sendLock; 92 } ProxyFileMutexLock; 93 94 typedef struct { 95 uint32_t startSeq; 96 uint32_t seqResult; 97 } AckResponseData; 98 99 typedef struct { 100 const char **files; 101 uint32_t fileCnt; 102 uint64_t bytesProcessed; 103 uint64_t bytesTotal; 104 } FilesInfo; 105 106 typedef struct { 107 uint32_t seq; 108 int32_t fileFd; 109 int32_t fileStatus; /* 0: idle 1:busy */ 110 uint64_t fileOffset; 111 uint64_t oneFrameLen; 112 uint32_t startSeq; 113 uint64_t seqResult; 114 uint32_t preStartSeq; 115 uint32_t preSeqResult; 116 uint64_t fileSize; 117 int32_t timeOut; 118 uint64_t checkSumCRC; 119 char filePath[MAX_FILE_PATH_NAME_LEN]; 120 } SingleFileInfo; 121 122 typedef struct { 123 ListNode node; 124 int32_t sessionId; 125 int32_t channelId; 126 int32_t osType; 127 int32_t fileEncrypt; 128 int32_t algorithm; 129 int32_t crc; 130 int32_t result; 131 FileListener fileListener; 132 int32_t objRefCount; 133 int32_t recvState; 134 SingleFileInfo recvFileInfo; 135 } FileRecipientInfo; 136 137 typedef struct { 138 ListNode node; 139 int32_t channelId; 140 int32_t sessionId; 141 int32_t fd; 142 uint64_t fileSize; 143 uint64_t frameNum; 144 int32_t fileEncrypt; 145 int32_t algorithm; 146 int32_t crc; 147 uint32_t seq; 148 int32_t waitSeq; 149 int32_t waitTimeoutCount; 150 int32_t result; 151 uint64_t checkSumCRC; 152 FileListener fileListener; 153 FilesInfo totalInfo; 154 uint32_t packetSize; 155 int32_t osType; 156 } SendListenerInfo; 157 158 int32_t ClinetTransProxyFileManagerInit(void); 159 void ClinetTransProxyFileManagerDeinit(void); 160 void ClientDeleteRecvFileList(int32_t sessionId); 161 162 int32_t ProxyChannelSendFile(int32_t channelId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt); 163 int32_t ProcessRecvFileFrameData(int32_t sessionId, int32_t channelId, const FileFrame *oneFrame); 164 #ifdef __cplusplus 165 } 166 #endif 167 #endif // CLIENT_TRANS_PROXY_FILE_MANAGER_H 168