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