10704ebd2Sopenharmony_ci/*
20704ebd2Sopenharmony_ci * Copyright (c) 2024  Huawei Device Co., Ltd.
30704ebd2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40704ebd2Sopenharmony_ci * you may not use this file except in compliance with the License.
50704ebd2Sopenharmony_ci * You may obtain a copy of the License at
60704ebd2Sopenharmony_ci *
70704ebd2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
80704ebd2Sopenharmony_ci *
90704ebd2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100704ebd2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110704ebd2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120704ebd2Sopenharmony_ci * See the License for the specific language governing permissions and
130704ebd2Sopenharmony_ci * limitations under the License.
140704ebd2Sopenharmony_ci */
150704ebd2Sopenharmony_ci
160704ebd2Sopenharmony_ci#ifndef NET_TRANS_COMMON_H
170704ebd2Sopenharmony_ci#define NET_TRANS_COMMON_H
180704ebd2Sopenharmony_ci
190704ebd2Sopenharmony_ci#include <pthread.h>
200704ebd2Sopenharmony_ci#include <securec.h>
210704ebd2Sopenharmony_ci#include <sys/time.h>
220704ebd2Sopenharmony_ci#include <unistd.h>
230704ebd2Sopenharmony_ci#include <inttypes.h>
240704ebd2Sopenharmony_ci#include "session.h"
250704ebd2Sopenharmony_ci#include "socket.h"
260704ebd2Sopenharmony_ci#include "softbus_bus_center.h"
270704ebd2Sopenharmony_ci#include "softbus_common.h"
280704ebd2Sopenharmony_ci#include "softbus_errcode.h"
290704ebd2Sopenharmony_ci#include "nativetoken_kit.h"
300704ebd2Sopenharmony_ci#include "token_setproc.h"
310704ebd2Sopenharmony_ci
320704ebd2Sopenharmony_ci#ifdef __cplusplus
330704ebd2Sopenharmony_ciextern "C" {
340704ebd2Sopenharmony_ci#endif
350704ebd2Sopenharmony_ci
360704ebd2Sopenharmony_ci#define DEF_GROUP_ID "DEF_GROUP_ID"
370704ebd2Sopenharmony_ci#define DEF_SESSION_KEY "DEF_SESSION_KEY"
380704ebd2Sopenharmony_ci#define DEF_PKG_NAME "com.communication.demo1"
390704ebd2Sopenharmony_ci#define PKG_NAME_TWO "com.communication.demo2"
400704ebd2Sopenharmony_ci#define SESSIONNAME_MAX "com.communication.demo1.max.len.12345678901234567\
410704ebd2Sopenharmony_ci    0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\
420704ebd2Sopenharmony_ci    01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567"
430704ebd2Sopenharmony_ci#define SESSIONNAME_MAX_OUT "com.communication.demo1.max.len.12345678901234567\
440704ebd2Sopenharmony_ci    0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\
450704ebd2Sopenharmony_ci    012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
460704ebd2Sopenharmony_ci#define PKGNAME_MAX "com.communication.demo1.max.len.1234567890123456789012345678901"
470704ebd2Sopenharmony_ci#define PKGNAME_MAX_OUT "com.communication.demo1.max.len.123456789012345678901234567890123"
480704ebd2Sopenharmony_ci
490704ebd2Sopenharmony_ci#define SOCKET_NAME_BYTE "com.communication.demo1.socket.byte"
500704ebd2Sopenharmony_ci#define SOCKET_NAME_MESSAGE "com.communication.demo1.socket.message"
510704ebd2Sopenharmony_ci#define SOCKET_NAME_FILE "com.communication.demo1.socket.file"
520704ebd2Sopenharmony_ci#define SOCKET_NAME_STREAM "com.communication.demo1.socket.stream"
530704ebd2Sopenharmony_ci
540704ebd2Sopenharmony_ci#define DSOFT_PKG_NAME "com.plrdtest.dsoftbus"
550704ebd2Sopenharmony_ci#define SESSION_NAME_DSOFT_DATA "com.plrdtest.dsoftbus.data"
560704ebd2Sopenharmony_ci#define RECV_FILE_PATH "/data/"
570704ebd2Sopenharmony_ci
580704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_WIFI_THREE_SEC "close wifi 3sec"
590704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_WIFI_TEN_MIN "close wifi 10min"
600704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_WIFI_FIVE_MIN "close wifi 5min"
610704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_WIFI_TEN_SEC "close wifi 10sec"
620704ebd2Sopenharmony_ci#define CTRL_MSG_CHANGE_WIFI_TEN_SEC "change wifi 10sec"
630704ebd2Sopenharmony_ci#define CTRL_MSG_CHANGE_WIFI_SIXTY_SEC "change wifi 60sec"
640704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_WIFI_LOOP20 "close wifi loop 20"
650704ebd2Sopenharmony_ci#define CTRL_MSG_CHANGE_WIFI_LOOP20 "change wifi loop 20"
660704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_WIFI_LOOP100 "close wifi loop 100"
670704ebd2Sopenharmony_ci#define CTRL_MSG_CHANGE_WIFI_LOOP100 "change wifi loop 100"
680704ebd2Sopenharmony_ci#define CTRL_MSG_OPEN_SESSION "open session"
690704ebd2Sopenharmony_ci#define CTRL_MSG_OPEN_SESSION_MSG "open session msg"
700704ebd2Sopenharmony_ci#define CTRL_MSG_OPEN_SESSION_NOT_EXIST "open session not exist"
710704ebd2Sopenharmony_ci#define CTRL_MSG_OPEN_SESSION_FAIL "open session fail"
720704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_SESSION "close session"
730704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_BR "close br"
740704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_OPEN_BR "close-open br"
750704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_AIR "close air"
760704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_OPEN_AIR "close-open air"
770704ebd2Sopenharmony_ci#define CTRL_MSG_SEND_BIG_DATA "send big data"
780704ebd2Sopenharmony_ci
790704ebd2Sopenharmony_ci#define WAIT_DEF_VALUE (-1)
800704ebd2Sopenharmony_ci#define WAIT_SUCCESS_VALUE 1
810704ebd2Sopenharmony_ci#define WAIT_FAIL_VALUE 0
820704ebd2Sopenharmony_ci#define SESSION_ID_MIN 1
830704ebd2Sopenharmony_ci#define MAX_SESSION_NUM 16
840704ebd2Sopenharmony_ci#define BOOL_TRUE 1
850704ebd2Sopenharmony_ci#define BOOL_FALSE 0
860704ebd2Sopenharmony_ci#define OPEN_SESSION_TIMEOUT 19
870704ebd2Sopenharmony_ci#define MULTI_REMOTE_DEV_COUNT 3
880704ebd2Sopenharmony_ci#define DEF_REMOTE_DEV_COUNT 1
890704ebd2Sopenharmony_ci#define SIZE_1K 1024
900704ebd2Sopenharmony_ci#define CMD_PIDOF_SOFTBUS "pidof softbus_server"
910704ebd2Sopenharmony_ci#define MAX_SESSION_SERVER_NUM_CLIENT 8
920704ebd2Sopenharmony_ci#define MAX_SESSION_SERVER_NUM_SERVER 32
930704ebd2Sopenharmony_ci#define TRANS_BYTES_LENGTH_MAX (4 * 1024 * 1024)
940704ebd2Sopenharmony_ci#define TRANS_MESSAGE_LENGTH_MAX (4 * 1024)
950704ebd2Sopenharmony_ci#define TRANS_PROXY_BYTES_LENGTH_MAX (4 * 1024 * 1024)
960704ebd2Sopenharmony_ci#define TRANS_PROXY_MESSAGE_LENGTH_MAX (4 * 1024)
970704ebd2Sopenharmony_ci#define DEF_SEND_DATA_SID_COUNT 4
980704ebd2Sopenharmony_ci#define GROUP_ID_LEN 4
990704ebd2Sopenharmony_ci#define ONE_SECOND 1
1000704ebd2Sopenharmony_ci
1010704ebd2Sopenharmony_ci#define CASE_0 0
1020704ebd2Sopenharmony_ci#define CASE_1 1
1030704ebd2Sopenharmony_ci#define CASE_2 2
1040704ebd2Sopenharmony_ci#define CASE_3 3
1050704ebd2Sopenharmony_ci#define CASE_4 4
1060704ebd2Sopenharmony_ci#define CASE_5 5
1070704ebd2Sopenharmony_ci#define CASE_6 6
1080704ebd2Sopenharmony_ci#define CASE_7 7
1090704ebd2Sopenharmony_ci#define CASE_8 8
1100704ebd2Sopenharmony_ci#define CASE_9 9
1110704ebd2Sopenharmony_ci#define CASE_10 10
1120704ebd2Sopenharmony_ci
1130704ebd2Sopenharmony_ci#define INDEX_0 0
1140704ebd2Sopenharmony_ci#define INDEX_1 1
1150704ebd2Sopenharmony_ci#define INDEX_2 2
1160704ebd2Sopenharmony_ci#define INDEX_3 3
1170704ebd2Sopenharmony_ci#define INDEX_4 4
1180704ebd2Sopenharmony_ci
1190704ebd2Sopenharmony_ci#define TEN_PLACE 10
1200704ebd2Sopenharmony_ci#define HUNDRED_PLACE  100
1210704ebd2Sopenharmony_ci#define THOUSAND_PLACE  1000
1220704ebd2Sopenharmony_ci#define FRAME_10 10
1230704ebd2Sopenharmony_ci#define FRAME_100 100
1240704ebd2Sopenharmony_ci#define FRAME_1000 1000
1250704ebd2Sopenharmony_ci/*stream*/
1260704ebd2Sopenharmony_ci#define I_FRAME_TYPE (1)
1270704ebd2Sopenharmony_ci#define P_FRAME_TYPE (2)
1280704ebd2Sopenharmony_ci/*common*/
1290704ebd2Sopenharmony_ci#define I_FRAME_SIZE0 (0 * 1024)
1300704ebd2Sopenharmony_ci#define P_FRAME_SIZE0 (0 * 1024)
1310704ebd2Sopenharmony_ci/*1080P10 I_FRAME 400k P_FRAME 27k*/
1320704ebd2Sopenharmony_ci#define I_FRAME_SIZE1 (400 * 1024)
1330704ebd2Sopenharmony_ci#define P_FRAME_SIZE1 (27 * 1024)
1340704ebd2Sopenharmony_ci/*1080P30 I_FRAME 200k P_FRAME 46k*/
1350704ebd2Sopenharmony_ci#define I_FRAME_SIZE2 (200 * 1024)
1360704ebd2Sopenharmony_ci#define P_FRAME_SIZE2 (46 * 1024)
1370704ebd2Sopenharmony_ci/*1080P60 I_FRAME 150k P_FRAME 30k*/
1380704ebd2Sopenharmony_ci#define I_FRAME_SIZE3 (150 * 1024)
1390704ebd2Sopenharmony_ci#define P_FRAME_SIZE3 (30 * 1024)
1400704ebd2Sopenharmony_ci/*2kP60 I_FRAME 180k P_FRAME 62k*/
1410704ebd2Sopenharmony_ci#define I_FRAME_SIZE4 (180 * 1024)
1420704ebd2Sopenharmony_ci#define P_FRAME_SIZE4 (62 * 1024)
1430704ebd2Sopenharmony_ci/*2kP60 I_FRAME 270k P_FRAME 60k*/
1440704ebd2Sopenharmony_ci#define I_FRAME_SIZE5 (270 * 1024)
1450704ebd2Sopenharmony_ci#define P_FRAME_SIZE5 (60 * 1024)
1460704ebd2Sopenharmony_ci/*4KP30 I_FRAME 400k P_FRAME 119k*/
1470704ebd2Sopenharmony_ci#define I_FRAME_SIZE6 (400 * 1024)
1480704ebd2Sopenharmony_ci#define P_FRAME_SIZE6 (119 * 1024)
1490704ebd2Sopenharmony_ci/*4KP30 I_FRAME 600k P_FRAME 112k*/
1500704ebd2Sopenharmony_ci#define I_FRAME_SIZE7 (600 * 1024)
1510704ebd2Sopenharmony_ci#define P_FRAME_SIZE7 (112 * 1024)
1520704ebd2Sopenharmony_ci/*4KP60 I_FRAME 400K P_FRAME 123K*/
1530704ebd2Sopenharmony_ci#define I_FRAME_SIZE8 (400 * 1024)
1540704ebd2Sopenharmony_ci#define P_FRAME_SIZE8 (123 * 1024)
1550704ebd2Sopenharmony_ci/*4KP60 I_FRAME 600K P_FRAME 120K*/
1560704ebd2Sopenharmony_ci#define I_FRAME_SIZE9 (600 * 1024)
1570704ebd2Sopenharmony_ci#define P_FRAME_SIZE9 (120 * 1024)
1580704ebd2Sopenharmony_ci/*1080P60 I_FRAME 867K P_FRAME 7K*/
1590704ebd2Sopenharmony_ci#define I_FRAME_SIZE10 (867 * 1024)
1600704ebd2Sopenharmony_ci#define P_FRAME_SIZE10 (7 * 1024)
1610704ebd2Sopenharmony_ci/*1080P60 I_FRAME 1330K P_FRAME 10K*/
1620704ebd2Sopenharmony_ci#define I_FRAME_SIZE11 (1330 * 1024)
1630704ebd2Sopenharmony_ci#define P_FRAME_SIZE11 (10 * 1024)
1640704ebd2Sopenharmony_ci
1650704ebd2Sopenharmony_citypedef enum {
1660704ebd2Sopenharmony_ci    SOCKET_BYTES = 1,
1670704ebd2Sopenharmony_ci    SOCKET_MSG,
1680704ebd2Sopenharmony_ci    SOCKET_FILE,
1690704ebd2Sopenharmony_ci    SOCKET_STREAM,
1700704ebd2Sopenharmony_ci    SOCKET_SHUTDOWN,
1710704ebd2Sopenharmony_ci}WaitSocketType;
1720704ebd2Sopenharmony_ci
1730704ebd2Sopenharmony_citypedef enum {
1740704ebd2Sopenharmony_ci    DATA_TYPE_MSG = 1,
1750704ebd2Sopenharmony_ci    DATA_TYPE_BYTE,
1760704ebd2Sopenharmony_ci} DataType;
1770704ebd2Sopenharmony_ci
1780704ebd2Sopenharmony_citypedef enum {
1790704ebd2Sopenharmony_ci    STATE_ONLINE = 1,
1800704ebd2Sopenharmony_ci    STATE_OFFLINE,
1810704ebd2Sopenharmony_ci} WaitNodeStateType;
1820704ebd2Sopenharmony_ci
1830704ebd2Sopenharmony_citypedef enum {
1840704ebd2Sopenharmony_ci    CONC_CLOSE_SESSION = 1,
1850704ebd2Sopenharmony_ci    CONC_LEAVE_NET,
1860704ebd2Sopenharmony_ci    CONC_DIS_NET_RECOVERY,
1870704ebd2Sopenharmony_ci    CONC_DIS_NET_NOT_RECOVERY,
1880704ebd2Sopenharmony_ci    CONC_DOWN_NET,
1890704ebd2Sopenharmony_ci    CONC_SEND_DATA_ONLY,
1900704ebd2Sopenharmony_ci    CONC_CLOSE_SESSION_REMOTE,
1910704ebd2Sopenharmony_ci} ConcurrentType;
1920704ebd2Sopenharmony_ci
1930704ebd2Sopenharmony_citypedef enum {
1940704ebd2Sopenharmony_ci    CTRL_CODE_CLOSE_WIFI_TEN_SEC = 1,
1950704ebd2Sopenharmony_ci    CTRL_CODE_CLOSE_WIFI_TEN_MIN,
1960704ebd2Sopenharmony_ci    CTRL_CODE_CLOSE_WIFI_FIVE_MIN,
1970704ebd2Sopenharmony_ci    CTRL_CODE_CLOSE_WIFI_THREE_SEC,
1980704ebd2Sopenharmony_ci    CTRL_CODE_CHANGE_WIFI_TEN_SEC,
1990704ebd2Sopenharmony_ci    CTRL_CODE_CHANGE_WIFI_SIXTY_SEC,
2000704ebd2Sopenharmony_ci    CTRL_CODE_CHANGE_WIFI_LOOP20,
2010704ebd2Sopenharmony_ci    CTRL_CODE_CLOSE_WIFI_LOOP20,
2020704ebd2Sopenharmony_ci    CTRL_CODE_CHANGE_WIFI_LOOP100,
2030704ebd2Sopenharmony_ci    CTRL_CODE_CLOSE_WIFI_LOOP100,
2040704ebd2Sopenharmony_ci    CTRL_CODE_OPEN_SESSION,
2050704ebd2Sopenharmony_ci    CTRL_CODE_OPEN_SESSION_MSG,
2060704ebd2Sopenharmony_ci    CTRL_CODE_OPEN_SESSION_FAIL,
2070704ebd2Sopenharmony_ci    CTRL_CODE_OPEN_SESSION_NOT_EXIST,
2080704ebd2Sopenharmony_ci    CTRL_CODE_CLOSE_SESSION,
2090704ebd2Sopenharmony_ci    CTRL_CODE_CLOSE_BR,
2100704ebd2Sopenharmony_ci    CTRL_CODE_CLOSE_OPEN_BR,
2110704ebd2Sopenharmony_ci    CTRL_CODE_CLOSE_AIR,
2120704ebd2Sopenharmony_ci    CTRL_CODE_CLOSE_OPEN_AIR,
2130704ebd2Sopenharmony_ci    CTRL_CODE_SEND_BIG_DATA,
2140704ebd2Sopenharmony_ci} CtrlCodeType;
2150704ebd2Sopenharmony_ci
2160704ebd2Sopenharmony_ci#define LOG(format, ...)                                                           \
2170704ebd2Sopenharmony_ci    do {                                                                           \
2180704ebd2Sopenharmony_ci        time_t timeSec;                                                            \
2190704ebd2Sopenharmony_ci        time(&timeSec);                                                            \
2200704ebd2Sopenharmony_ci        struct tm tmRst;                                                           \
2210704ebd2Sopenharmony_ci        localtime_r(&timeSec, &tmRst);                                             \
2220704ebd2Sopenharmony_ci        char strTime[10];                                                          \
2230704ebd2Sopenharmony_ci        strftime(strTime, sizeof(strTime), "%H:%M:%S", &tmRst);                    \
2240704ebd2Sopenharmony_ci        fprintf(stdout, "[Test-softbus] %s " format "\n", strTime, ##__VA_ARGS__); \
2250704ebd2Sopenharmony_ci    } while (0)
2260704ebd2Sopenharmony_ci
2270704ebd2Sopenharmony_ciint Wait4Socket(int timeout, WaitSocketType type);
2280704ebd2Sopenharmony_ciint WaitNodeCount(int timeout, WaitNodeStateType state, int expectCount);
2290704ebd2Sopenharmony_ci
2300704ebd2Sopenharmony_civoid Sleepn(int n);
2310704ebd2Sopenharmony_civoid TestSetUp(void);
2320704ebd2Sopenharmony_civoid TestTearDown(void);
2330704ebd2Sopenharmony_ci
2340704ebd2Sopenharmony_ciint RegisterDeviceStateDefCallback(void);
2350704ebd2Sopenharmony_ciint UnRegisterDeviceStateDefCallback(void);
2360704ebd2Sopenharmony_ciint CheckRemoteDeviceIsNull(int isSetNetId);
2370704ebd2Sopenharmony_ci
2380704ebd2Sopenharmony_civoid ResetWaitFlag(void);
2390704ebd2Sopenharmony_civoid ResetWaitFlag4Shutdown(void);
2400704ebd2Sopenharmony_civoid ResetWaitFlag4Byte(void);
2410704ebd2Sopenharmony_civoid ResetWaitFlag4Message(void);
2420704ebd2Sopenharmony_civoid ResetWaitFlag4Stream(void);
2430704ebd2Sopenharmony_civoid ResetWaitFlag4File(void);
2440704ebd2Sopenharmony_civoid ResetwaitCount4Online(void);
2450704ebd2Sopenharmony_civoid ResetwaitCount4Offline(void);
2460704ebd2Sopenharmony_civoid AddPermission(void);
2470704ebd2Sopenharmony_ci
2480704ebd2Sopenharmony_ciint SendSocket4Data(DataType type, int size);
2490704ebd2Sopenharmony_ci
2500704ebd2Sopenharmony_cichar* GetSoftbusPid(void);
2510704ebd2Sopenharmony_cichar* GetNetworkId(void);
2520704ebd2Sopenharmony_ci
2530704ebd2Sopenharmony_civoid SetCurrentSocket4Data(int socket);
2540704ebd2Sopenharmony_ci
2550704ebd2Sopenharmony_ciint GetCurrentSocket4Data(void);
2560704ebd2Sopenharmony_ci
2570704ebd2Sopenharmony_ciISocketListener* GetSocketListnerData(void);
2580704ebd2Sopenharmony_ci
2590704ebd2Sopenharmony_ci#ifdef __cplusplus
2600704ebd2Sopenharmony_ci}
2610704ebd2Sopenharmony_ci#endif
2620704ebd2Sopenharmony_ci#endif