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 CLIENT_TRANS_PROXY_FILE_MANAGER_H 17 #define CLIENT_TRANS_PROXY_FILE_MANAGER_H 18 19 #include <stdint.h> 20 21 #include "client_trans_file_listener.h" 22 23 #ifdef __linux__ 24 #define MAX_SEND_FILE_NUM 10 25 #else 26 #define MAX_SEND_FILE_NUM 1 27 #endif 28 #define MAX_FILE_SIZE (0x500000) /* 5M */ 29 30 #define DEFAULT_NEW_PATH_AUTHORITY (0750) 31 32 #define INVALID_NODE_INDEX (-1) 33 34 #define FILE_MAGIC_NUMBER 0xBABEFACE 35 36 #define PROXY_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 2000 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 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 int32_t ClinetTransProxyFileManagerInit(void); 100 void ClinetTransProxyFileManagerDeinit(void); 101 102 int32_t ProxyChannelSendFile(int32_t channelId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt); 103 int32_t ProcessRecvFileFrameData(int32_t sessionId, int32_t channelId, const FileFrame *oneFrame); 104 #ifdef __cplusplus 105 } 106 #endif 107 #endif