• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 NET_TRANS_COMMON_H
17 #define NET_TRANS_COMMON_H
18 
19 #include <pthread.h>
20 #include <securec.h>
21 #include <sys/time.h>
22 #include <unistd.h>
23 #include <inttypes.h>
24 #include "discovery_service.h"
25 #include "session.h"
26 #include "socket.h"
27 #include "softbus_bus_center.h"
28 #include "softbus_common.h"
29 #include "softbus_errcode.h"
30 #include "nativetoken_kit.h"
31 #include "token_setproc.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define DEF_GROUP_ID "DEF_GROUP_ID"
38 #define DEF_SESSION_KEY "DEF_SESSION_KEY"
39 #define DEF_PKG_NAME "com.communication.demo1"
40 #define PKG_NAME_TWO "com.communication.demo2"
41 #define SESSIONNAME_MAX "com.communication.demo1.max.len.12345678901234567\
42     0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\
43     01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567"
44 #define SESSIONNAME_MAX_OUT "com.communication.demo1.max.len.12345678901234567\
45     0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\
46     012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
47 #define PKGNAME_MAX "com.communication.demo1.max.len.1234567890123456789012345678901"
48 #define PKGNAME_MAX_OUT "com.communication.demo1.max.len.123456789012345678901234567890123"
49 
50 #define SOCKET_NAME_BYTE "com.communication.demo1.socket.byte"
51 #define SOCKET_NAME_MESSAGE "com.communication.demo1.socket.message"
52 #define SOCKET_NAME_FILE "com.communication.demo1.socket.file"
53 #define SOCKET_NAME_STREAM "com.communication.demo1.socket.stream"
54 
55 #define DSOFT_PKG_NAME "com.plrdtest.dsoftbus"
56 #define SESSION_NAME_DSOFT_DATA "com.plrdtest.dsoftbus.data"
57 #define RECV_FILE_PATH "/data/"
58 
59 #define CTRL_MSG_CLOSE_WIFI_THREE_SEC "close wifi 3sec"
60 #define CTRL_MSG_CLOSE_WIFI_TEN_MIN "close wifi 10min"
61 #define CTRL_MSG_CLOSE_WIFI_FIVE_MIN "close wifi 5min"
62 #define CTRL_MSG_CLOSE_WIFI_TEN_SEC "close wifi 10sec"
63 #define CTRL_MSG_CHANGE_WIFI_TEN_SEC "change wifi 10sec"
64 #define CTRL_MSG_CHANGE_WIFI_SIXTY_SEC "change wifi 60sec"
65 #define CTRL_MSG_CLOSE_WIFI_LOOP20 "close wifi loop 20"
66 #define CTRL_MSG_CHANGE_WIFI_LOOP20 "change wifi loop 20"
67 #define CTRL_MSG_CLOSE_WIFI_LOOP100 "close wifi loop 100"
68 #define CTRL_MSG_CHANGE_WIFI_LOOP100 "change wifi loop 100"
69 #define CTRL_MSG_OPEN_SESSION "open session"
70 #define CTRL_MSG_OPEN_SESSION_MSG "open session msg"
71 #define CTRL_MSG_OPEN_SESSION_NOT_EXIST "open session not exist"
72 #define CTRL_MSG_OPEN_SESSION_FAIL "open session fail"
73 #define CTRL_MSG_CLOSE_SESSION "close session"
74 #define CTRL_MSG_CLOSE_BR "close br"
75 #define CTRL_MSG_CLOSE_OPEN_BR "close-open br"
76 #define CTRL_MSG_CLOSE_AIR "close air"
77 #define CTRL_MSG_CLOSE_OPEN_AIR "close-open air"
78 #define CTRL_MSG_SEND_BIG_DATA "send big data"
79 
80 #define WAIT_DEF_VALUE (-1)
81 #define WAIT_SUCCESS_VALUE 1
82 #define WAIT_FAIL_VALUE 0
83 #define SESSION_ID_MIN 1
84 #define MAX_SESSION_NUM 16
85 #define BOOL_TRUE 1
86 #define BOOL_FALSE 0
87 #define OPEN_SESSION_TIMEOUT 19
88 #define MULTI_REMOTE_DEV_COUNT 3
89 #define DEF_REMOTE_DEV_COUNT 1
90 #define SIZE_1K 1024
91 #define CMD_PIDOF_SOFTBUS "pidof softbus_server"
92 #define MAX_SESSION_SERVER_NUM_CLIENT 8
93 #define MAX_SESSION_SERVER_NUM_SERVER 32
94 #define TRANS_BYTES_LENGTH_MAX (4 * 1024 * 1024)
95 #define TRANS_MESSAGE_LENGTH_MAX (4 * 1024)
96 #define TRANS_PROXY_BYTES_LENGTH_MAX (4 * 1024 * 1024)
97 #define TRANS_PROXY_MESSAGE_LENGTH_MAX (4 * 1024)
98 #define DEF_SEND_DATA_SID_COUNT 4
99 #define GROUP_ID_LEN 4
100 #define ONE_SECOND 1
101 
102 #define CASE_0 0
103 #define CASE_1 1
104 #define CASE_2 2
105 #define CASE_3 3
106 #define CASE_4 4
107 #define CASE_5 5
108 #define CASE_6 6
109 #define CASE_7 7
110 #define CASE_8 8
111 #define CASE_9 9
112 #define CASE_10 10
113 
114 #define INDEX_0 0
115 #define INDEX_1 1
116 #define INDEX_2 2
117 #define INDEX_3 3
118 #define INDEX_4 4
119 
120 #define TEN_PLACE 10
121 #define HUNDRED_PLACE  100
122 #define THOUSAND_PLACE  1000
123 #define FRAME_10 10
124 #define FRAME_100 100
125 #define FRAME_1000 1000
126 /*stream*/
127 #define I_FRAME_TYPE (1)
128 #define P_FRAME_TYPE (2)
129 /*common*/
130 #define I_FRAME_SIZE0 (0 * 1024)
131 #define P_FRAME_SIZE0 (0 * 1024)
132 /*1080P10 I_FRAME 400k P_FRAME 27k*/
133 #define I_FRAME_SIZE1 (400 * 1024)
134 #define P_FRAME_SIZE1 (27 * 1024)
135 /*1080P30 I_FRAME 200k P_FRAME 46k*/
136 #define I_FRAME_SIZE2 (200 * 1024)
137 #define P_FRAME_SIZE2 (46 * 1024)
138 /*1080P60 I_FRAME 150k P_FRAME 30k*/
139 #define I_FRAME_SIZE3 (150 * 1024)
140 #define P_FRAME_SIZE3 (30 * 1024)
141 /*2kP60 I_FRAME 180k P_FRAME 62k*/
142 #define I_FRAME_SIZE4 (180 * 1024)
143 #define P_FRAME_SIZE4 (62 * 1024)
144 /*2kP60 I_FRAME 270k P_FRAME 60k*/
145 #define I_FRAME_SIZE5 (270 * 1024)
146 #define P_FRAME_SIZE5 (60 * 1024)
147 /*4KP30 I_FRAME 400k P_FRAME 119k*/
148 #define I_FRAME_SIZE6 (400 * 1024)
149 #define P_FRAME_SIZE6 (119 * 1024)
150 /*4KP30 I_FRAME 600k P_FRAME 112k*/
151 #define I_FRAME_SIZE7 (600 * 1024)
152 #define P_FRAME_SIZE7 (112 * 1024)
153 /*4KP60 I_FRAME 400K P_FRAME 123K*/
154 #define I_FRAME_SIZE8 (400 * 1024)
155 #define P_FRAME_SIZE8 (123 * 1024)
156 /*4KP60 I_FRAME 600K P_FRAME 120K*/
157 #define I_FRAME_SIZE9 (600 * 1024)
158 #define P_FRAME_SIZE9 (120 * 1024)
159 /*1080P60 I_FRAME 867K P_FRAME 7K*/
160 #define I_FRAME_SIZE10 (867 * 1024)
161 #define P_FRAME_SIZE10 (7 * 1024)
162 /*1080P60 I_FRAME 1330K P_FRAME 10K*/
163 #define I_FRAME_SIZE11 (1330 * 1024)
164 #define P_FRAME_SIZE11 (10 * 1024)
165 
166 typedef enum {
167     SOCKET_BYTES = 1,
168     SOCKET_MSG,
169     SOCKET_FILE,
170     SOCKET_STREAM,
171     SOCKET_SHUTDOWN,
172 }WaitSocketType;
173 
174 typedef enum {
175     DATA_TYPE_MSG = 1,
176     DATA_TYPE_BYTE,
177 } DataType;
178 
179 typedef enum {
180     STATE_ONLINE = 1,
181     STATE_OFFLINE,
182 } WaitNodeStateType;
183 
184 typedef enum {
185     CONC_CLOSE_SESSION = 1,
186     CONC_LEAVE_NET,
187     CONC_DIS_NET_RECOVERY,
188     CONC_DIS_NET_NOT_RECOVERY,
189     CONC_DOWN_NET,
190     CONC_SEND_DATA_ONLY,
191     CONC_CLOSE_SESSION_REMOTE,
192 } ConcurrentType;
193 
194 typedef enum {
195     CTRL_CODE_CLOSE_WIFI_TEN_SEC = 1,
196     CTRL_CODE_CLOSE_WIFI_TEN_MIN,
197     CTRL_CODE_CLOSE_WIFI_FIVE_MIN,
198     CTRL_CODE_CLOSE_WIFI_THREE_SEC,
199     CTRL_CODE_CHANGE_WIFI_TEN_SEC,
200     CTRL_CODE_CHANGE_WIFI_SIXTY_SEC,
201     CTRL_CODE_CHANGE_WIFI_LOOP20,
202     CTRL_CODE_CLOSE_WIFI_LOOP20,
203     CTRL_CODE_CHANGE_WIFI_LOOP100,
204     CTRL_CODE_CLOSE_WIFI_LOOP100,
205     CTRL_CODE_OPEN_SESSION,
206     CTRL_CODE_OPEN_SESSION_MSG,
207     CTRL_CODE_OPEN_SESSION_FAIL,
208     CTRL_CODE_OPEN_SESSION_NOT_EXIST,
209     CTRL_CODE_CLOSE_SESSION,
210     CTRL_CODE_CLOSE_BR,
211     CTRL_CODE_CLOSE_OPEN_BR,
212     CTRL_CODE_CLOSE_AIR,
213     CTRL_CODE_CLOSE_OPEN_AIR,
214     CTRL_CODE_SEND_BIG_DATA,
215 } CtrlCodeType;
216 
217 #define LOG(format, ...)                                                           \
218     do {                                                                           \
219         time_t timeSec;                                                            \
220         time(&timeSec);                                                            \
221         struct tm tmRst;                                                           \
222         localtime_r(&timeSec, &tmRst);                                             \
223         char strTime[10];                                                          \
224         strftime(strTime, sizeof(strTime), "%H:%M:%S", &tmRst);                    \
225         fprintf(stdout, "[Test-softbus] %s " format "\n", strTime, ##__VA_ARGS__); \
226     } while (0)
227 
228 int Wait4Socket(int timeout, WaitSocketType type);
229 int WaitNodeCount(int timeout, WaitNodeStateType state, int expectCount);
230 
231 void Sleepn(int n);
232 void TestSetUp(void);
233 void TestTearDown(void);
234 
235 int RegisterDeviceStateDefCallback(void);
236 int UnRegisterDeviceStateDefCallback(void);
237 int CheckRemoteDeviceIsNull(int isSetNetId);
238 
239 void ResetWaitFlag(void);
240 void ResetWaitFlag4Shutdown(void);
241 void ResetWaitFlag4Byte(void);
242 void ResetWaitFlag4Message(void);
243 void ResetWaitFlag4Stream(void);
244 void ResetWaitFlag4File(void);
245 void ResetwaitCount4Online(void);
246 void ResetwaitCount4Offline(void);
247 void AddPermission(void);
248 
249 int SendSocket4Data(DataType type, int size);
250 
251 char* GetSoftbusPid(void);
252 char* GetNetworkId(void);
253 
254 void SetCurrentSocket4Data(int socket);
255 
256 int GetCurrentSocket4Data(void);
257 
258 ISocketListener* GetSocketListnerData(void);
259 
260 #ifdef __cplusplus
261 }
262 #endif
263 #endif