10704ebd2Sopenharmony_ci/* 20704ebd2Sopenharmony_ci * Copyright (c) 2021 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#include "net_trans_common.h" 170704ebd2Sopenharmony_ci 180704ebd2Sopenharmony_cistatic int ONE_SECOND = 1; 190704ebd2Sopenharmony_cistatic int32_t g_currentSessionId4Data = -1; 200704ebd2Sopenharmony_cistatic int32_t g_currentSessionId4Ctl = -1; 210704ebd2Sopenharmony_cistatic int32_t g_currentSessionId4Proxy = -1; 220704ebd2Sopenharmony_cistatic int32_t g_waitFlag = WAIT_DEF_VALUE; 230704ebd2Sopenharmony_cistatic int32_t g_waitFlag4Data = WAIT_DEF_VALUE; 240704ebd2Sopenharmony_cistatic int32_t g_waitFlag4Ctl = WAIT_DEF_VALUE; 250704ebd2Sopenharmony_cistatic int32_t g_waitFlag4CtlClose = WAIT_DEF_VALUE; 260704ebd2Sopenharmony_cistatic int32_t g_waitFlag4Proxy = WAIT_DEF_VALUE; 270704ebd2Sopenharmony_cistatic int32_t g_waitFlag4Stream = WAIT_DEF_VALUE; 280704ebd2Sopenharmony_cistatic int32_t g_waitFlag4DataClose = WAIT_DEF_VALUE; 290704ebd2Sopenharmony_cistatic int32_t g_passiveOpenRetFlag = SOFTBUS_OK; 300704ebd2Sopenharmony_cistatic int32_t g_nodeOnlineCount = 0; 310704ebd2Sopenharmony_cistatic int32_t g_nodeOfflineCount = 0; 320704ebd2Sopenharmony_cistatic int32_t g_msgCount4Data = 0; 330704ebd2Sopenharmony_cistatic int32_t g_byteCount4Data = 0; 340704ebd2Sopenharmony_cistatic int32_t g_sessionCloseCount4Data = 0; 350704ebd2Sopenharmony_cistatic int32_t g_sessionCloseCount4Ctrl = 0; 360704ebd2Sopenharmony_cistatic int32_t g_sessionOpenCount4Data = 0; 370704ebd2Sopenharmony_cistatic int32_t g_sessionOpenCount4Ctrl = 0; 380704ebd2Sopenharmony_cistatic int32_t g_sessionOpenCount4Proxy = 0; 390704ebd2Sopenharmony_ci 400704ebd2Sopenharmony_cistatic SessionAttribute* g_sessionAttr4Data = NULL; 410704ebd2Sopenharmony_cistatic SessionAttribute* g_sessionAttr4Ctl = NULL; 420704ebd2Sopenharmony_cistatic SessionAttribute* g_sessionAttr4Pass = NULL; 430704ebd2Sopenharmony_cistatic SessionAttribute* g_sessionAttr4Perf = NULL; 440704ebd2Sopenharmony_cistatic SessionAttribute* g_sessionAttr4Proxy = NULL; 450704ebd2Sopenharmony_cistatic SessionAttribute* g_p2pattribute = NULL; 460704ebd2Sopenharmony_cistatic SessionAttribute* g_p2pattributeProxy = NULL; 470704ebd2Sopenharmony_cistatic ISessionListener* g_sessionlistener4Data = NULL; 480704ebd2Sopenharmony_cistatic ISessionListener* g_sessionlistener4Ctl = NULL; 490704ebd2Sopenharmony_cistatic ISessionListener* g_sessionlistener4Pass = NULL; 500704ebd2Sopenharmony_cistatic ISessionListener* g_sessionlistener4Perf = NULL; 510704ebd2Sopenharmony_cistatic ISessionListener* g_sessionlistener4Proxy = NULL; 520704ebd2Sopenharmony_cistatic ISessionListener* g_sessionlistener4Stream = NULL; 530704ebd2Sopenharmony_ci 540704ebd2Sopenharmony_cistatic IFileSendListener* g_fileSendListener = NULL; 550704ebd2Sopenharmony_cistatic IFileReceiveListener* g_fileRecvListener = NULL; 560704ebd2Sopenharmony_ci 570704ebd2Sopenharmony_cistatic char g_networkId[NETWORK_ID_BUF_LEN] = { 0 }; 580704ebd2Sopenharmony_cistatic INodeStateCb g_defNodeStateCallback; 590704ebd2Sopenharmony_ci 600704ebd2Sopenharmony_cistatic int* g_sId4Task2; 610704ebd2Sopenharmony_cistatic int* g_sId4Task3; 620704ebd2Sopenharmony_cistatic char g_fillContentChar = 'd'; 630704ebd2Sopenharmony_cistatic unsigned int g_expectDataSize = 0; 640704ebd2Sopenharmony_cistatic char* g_expectDataContent = NULL; 650704ebd2Sopenharmony_cistatic char* g_expectMessageContent = NULL; 660704ebd2Sopenharmony_cistatic int32_t g_recvMsgStat4Control[MAX_SESSION_NUM] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 670704ebd2Sopenharmony_cistatic int32_t g_recvByteStat4Control[MAX_SESSION_NUM] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 680704ebd2Sopenharmony_cistatic uint64_t g_transTimeEnd; 690704ebd2Sopenharmony_cistatic pthread_barrier_t* g_barrier = NULL; 700704ebd2Sopenharmony_ci 710704ebd2Sopenharmony_civoid sleepn(int n) 720704ebd2Sopenharmony_ci{ 730704ebd2Sopenharmony_ci for(int i = 0; i < n; i++) { 740704ebd2Sopenharmony_ci sleep(1); 750704ebd2Sopenharmony_ci } 760704ebd2Sopenharmony_ci} 770704ebd2Sopenharmony_ciint Wait(int timeout) 780704ebd2Sopenharmony_ci{ 790704ebd2Sopenharmony_ci LOG("start wait,timeout:%d", timeout); 800704ebd2Sopenharmony_ci int count = 0; 810704ebd2Sopenharmony_ci int t = timeout; 820704ebd2Sopenharmony_ci while (t > 0) { 830704ebd2Sopenharmony_ci sleep(1); 840704ebd2Sopenharmony_ci if (g_waitFlag != WAIT_DEF_VALUE) { 850704ebd2Sopenharmony_ci LOG("Wait success[flag:%d] [time:%d]", g_waitFlag, count); 860704ebd2Sopenharmony_ci break; 870704ebd2Sopenharmony_ci } 880704ebd2Sopenharmony_ci t--; 890704ebd2Sopenharmony_ci count++; 900704ebd2Sopenharmony_ci } 910704ebd2Sopenharmony_ci if (g_waitFlag != WAIT_SUCCESS_VALUE) { 920704ebd2Sopenharmony_ci LOG("Wait fail[exp:%d, real:%d][used time:%d]", WAIT_SUCCESS_VALUE, g_waitFlag, count); 930704ebd2Sopenharmony_ci return SOFTBUS_ERR; 940704ebd2Sopenharmony_ci } 950704ebd2Sopenharmony_ci return SOFTBUS_OK; 960704ebd2Sopenharmony_ci} 970704ebd2Sopenharmony_ci 980704ebd2Sopenharmony_ciint Wait4Session(int timeout, WaitSessionType type) 990704ebd2Sopenharmony_ci{ 1000704ebd2Sopenharmony_ci int hitFlag = -1; 1010704ebd2Sopenharmony_ci int t = timeout; 1020704ebd2Sopenharmony_ci while (t > 0) { 1030704ebd2Sopenharmony_ci sleep(1); 1040704ebd2Sopenharmony_ci switch (type) { 1050704ebd2Sopenharmony_ci case SESSION_4CTL: 1060704ebd2Sopenharmony_ci if (g_waitFlag4Ctl != WAIT_DEF_VALUE) { 1070704ebd2Sopenharmony_ci LOG("Wait4Session[ctrl] succ, flag:%d", g_waitFlag4Ctl); 1080704ebd2Sopenharmony_ci hitFlag = 1; 1090704ebd2Sopenharmony_ci } 1100704ebd2Sopenharmony_ci break; 1110704ebd2Sopenharmony_ci case SESSION_4DATA: 1120704ebd2Sopenharmony_ci if (g_waitFlag4Data != WAIT_DEF_VALUE) { 1130704ebd2Sopenharmony_ci LOG("Wait4Session[data] succ,flag:%d", g_waitFlag4Data); 1140704ebd2Sopenharmony_ci hitFlag = 1; 1150704ebd2Sopenharmony_ci } 1160704ebd2Sopenharmony_ci break; 1170704ebd2Sopenharmony_ci case SESSION_4PROXY: 1180704ebd2Sopenharmony_ci if (g_waitFlag4Proxy != WAIT_DEF_VALUE) { 1190704ebd2Sopenharmony_ci LOG("Wait4Session[proxy] succ,flag:%d", g_waitFlag4Proxy); 1200704ebd2Sopenharmony_ci hitFlag = 1; 1210704ebd2Sopenharmony_ci } 1220704ebd2Sopenharmony_ci break; 1230704ebd2Sopenharmony_ci case SESSION_4STREAM: 1240704ebd2Sopenharmony_ci if (g_waitFlag4Stream != WAIT_DEF_VALUE) { 1250704ebd2Sopenharmony_ci LOG("Wait4Session[proxy] succ,flag:%d", g_waitFlag4Stream); 1260704ebd2Sopenharmony_ci hitFlag = 1; 1270704ebd2Sopenharmony_ci } 1280704ebd2Sopenharmony_ci break; 1290704ebd2Sopenharmony_ci default: 1300704ebd2Sopenharmony_ci LOG("Wait4Session type error"); 1310704ebd2Sopenharmony_ci hitFlag = 1; 1320704ebd2Sopenharmony_ci break; 1330704ebd2Sopenharmony_ci } 1340704ebd2Sopenharmony_ci if (hitFlag != -1) { 1350704ebd2Sopenharmony_ci break; 1360704ebd2Sopenharmony_ci } 1370704ebd2Sopenharmony_ci t--; 1380704ebd2Sopenharmony_ci } 1390704ebd2Sopenharmony_ci switch (type) { 1400704ebd2Sopenharmony_ci case SESSION_4CTL: 1410704ebd2Sopenharmony_ci if (g_waitFlag4Ctl != WAIT_SUCCESS_VALUE) { 1420704ebd2Sopenharmony_ci LOG("Wait4Session[ctrl] fail[exp:%d, real:%d]", WAIT_SUCCESS_VALUE, g_waitFlag4Ctl); 1430704ebd2Sopenharmony_ci return SOFTBUS_ERR; 1440704ebd2Sopenharmony_ci } 1450704ebd2Sopenharmony_ci break; 1460704ebd2Sopenharmony_ci case SESSION_4DATA: 1470704ebd2Sopenharmony_ci if (g_waitFlag4Data != WAIT_SUCCESS_VALUE) { 1480704ebd2Sopenharmony_ci LOG("Wait4Session[data] fail[exp:%d, real:%d]", WAIT_SUCCESS_VALUE, g_waitFlag4Data); 1490704ebd2Sopenharmony_ci return SOFTBUS_ERR; 1500704ebd2Sopenharmony_ci } 1510704ebd2Sopenharmony_ci break; 1520704ebd2Sopenharmony_ci case SESSION_4PROXY: 1530704ebd2Sopenharmony_ci if (g_waitFlag4Proxy != WAIT_SUCCESS_VALUE) { 1540704ebd2Sopenharmony_ci LOG("Wait4Session[proxy] fail[exp:%d, real:%d]", WAIT_SUCCESS_VALUE, g_waitFlag4Proxy); 1550704ebd2Sopenharmony_ci return SOFTBUS_ERR; 1560704ebd2Sopenharmony_ci } 1570704ebd2Sopenharmony_ci break; 1580704ebd2Sopenharmony_ci case SESSION_4STREAM: 1590704ebd2Sopenharmony_ci if (g_waitFlag4Stream != WAIT_SUCCESS_VALUE) { 1600704ebd2Sopenharmony_ci LOG("Wait4Session[proxy] fail[exp:%d, real:%d]", WAIT_SUCCESS_VALUE, g_waitFlag4Stream); 1610704ebd2Sopenharmony_ci return SOFTBUS_ERR; 1620704ebd2Sopenharmony_ci } 1630704ebd2Sopenharmony_ci break; 1640704ebd2Sopenharmony_ci default: 1650704ebd2Sopenharmony_ci return SOFTBUS_ERR; 1660704ebd2Sopenharmony_ci } 1670704ebd2Sopenharmony_ci return SOFTBUS_OK; 1680704ebd2Sopenharmony_ci} 1690704ebd2Sopenharmony_ci 1700704ebd2Sopenharmony_ciuint64_t GetCurrentTimeOfMs(void) 1710704ebd2Sopenharmony_ci{ 1720704ebd2Sopenharmony_ci int unit = 1000; 1730704ebd2Sopenharmony_ci struct timeval tv; 1740704ebd2Sopenharmony_ci gettimeofday(&tv, NULL); 1750704ebd2Sopenharmony_ci return (tv.tv_sec * unit + tv.tv_usec / unit); 1760704ebd2Sopenharmony_ci} 1770704ebd2Sopenharmony_ci 1780704ebd2Sopenharmony_cichar* GetSoftbusPid(void) 1790704ebd2Sopenharmony_ci{ 1800704ebd2Sopenharmony_ci FILE* file = NULL; 1810704ebd2Sopenharmony_ci int buffSize = 20; 1820704ebd2Sopenharmony_ci char* buffer = (char*)malloc(buffSize); 1830704ebd2Sopenharmony_ci if (buffer == NULL) { 1840704ebd2Sopenharmony_ci LOG("malloc fail"); 1850704ebd2Sopenharmony_ci return NULL; 1860704ebd2Sopenharmony_ci } 1870704ebd2Sopenharmony_ci 1880704ebd2Sopenharmony_ci file = popen(CMD_PIDOF_SOFTBUS, "r"); 1890704ebd2Sopenharmony_ci if (file == NULL) { 1900704ebd2Sopenharmony_ci LOG("call popen fail"); 1910704ebd2Sopenharmony_ci free(buffer); 1920704ebd2Sopenharmony_ci return NULL; 1930704ebd2Sopenharmony_ci } 1940704ebd2Sopenharmony_ci (void)fgets(buffer, buffSize, file); 1950704ebd2Sopenharmony_ci LOG("##################Softbus PID:%s", buffer); 1960704ebd2Sopenharmony_ci pclose(file); 1970704ebd2Sopenharmony_ci 1980704ebd2Sopenharmony_ci return buffer; 1990704ebd2Sopenharmony_ci} 2000704ebd2Sopenharmony_ci 2010704ebd2Sopenharmony_cistatic int OnReceiveFileStarted(int sessionId, const char* files, int fileCnt) 2020704ebd2Sopenharmony_ci{ 2030704ebd2Sopenharmony_ci LOG("[recv file]start,sid:%d, fileCnt:%d", sessionId, fileCnt); 2040704ebd2Sopenharmony_ci return 0; 2050704ebd2Sopenharmony_ci} 2060704ebd2Sopenharmony_ci 2070704ebd2Sopenharmony_cistatic int OnReceiveFileProcess(int sessionId, const char* firstFile, uint64_t bytesUpload, uint64_t bytesTotal) 2080704ebd2Sopenharmony_ci{ 2090704ebd2Sopenharmony_ci return 0; 2100704ebd2Sopenharmony_ci} 2110704ebd2Sopenharmony_ci 2120704ebd2Sopenharmony_cistatic void OnReceiveFileFinished(int sessionId, const char* files, int fileCnt) 2130704ebd2Sopenharmony_ci{ 2140704ebd2Sopenharmony_ci LOG("[recv file]finish,sid:%d, fileCnt:%d", sessionId, fileCnt); 2150704ebd2Sopenharmony_ci} 2160704ebd2Sopenharmony_ci 2170704ebd2Sopenharmony_cistatic void OnRecvFileTransError(int sessionId) 2180704ebd2Sopenharmony_ci{ 2190704ebd2Sopenharmony_ci LOG("[recv file]trans error,sid:%d", sessionId); 2200704ebd2Sopenharmony_ci} 2210704ebd2Sopenharmony_ci 2220704ebd2Sopenharmony_cistatic int OnSendFileProcess(int sessionId, uint64_t bytesUpload, uint64_t bytesTotal) 2230704ebd2Sopenharmony_ci{ 2240704ebd2Sopenharmony_ci return 0; 2250704ebd2Sopenharmony_ci} 2260704ebd2Sopenharmony_ci 2270704ebd2Sopenharmony_cistatic int OnSendFileFinished(int sessionId, const char* firstFile) 2280704ebd2Sopenharmony_ci{ 2290704ebd2Sopenharmony_ci g_waitFlag = WAIT_SUCCESS_VALUE; 2300704ebd2Sopenharmony_ci LOG("[send file]finish,sid:%d, firstFile:%s\n", sessionId, firstFile); 2310704ebd2Sopenharmony_ci return 0; 2320704ebd2Sopenharmony_ci} 2330704ebd2Sopenharmony_ci 2340704ebd2Sopenharmony_cistatic void OnSendFileTransError(int sessionId) 2350704ebd2Sopenharmony_ci{ 2360704ebd2Sopenharmony_ci g_waitFlag = WAIT_FAIL_VALUE; 2370704ebd2Sopenharmony_ci LOG("[send file]trans error,sid = %d\n", sessionId); 2380704ebd2Sopenharmony_ci} 2390704ebd2Sopenharmony_ci 2400704ebd2Sopenharmony_cistatic void OnDefNodeOnline(NodeBasicInfo* info) 2410704ebd2Sopenharmony_ci{ 2420704ebd2Sopenharmony_ci if (info == NULL) { 2430704ebd2Sopenharmony_ci LOG("[cb]Online: info is null"); 2440704ebd2Sopenharmony_ci return; 2450704ebd2Sopenharmony_ci } 2460704ebd2Sopenharmony_ci (void)strncpy_s(g_networkId, NETWORK_ID_BUF_LEN, info->networkId, NETWORK_ID_BUF_LEN); 2470704ebd2Sopenharmony_ci LOG("[cb]Online id:%s, name:%s, type id:%u", info->networkId, info->deviceName, info->deviceTypeId); 2480704ebd2Sopenharmony_ci g_nodeOnlineCount++; 2490704ebd2Sopenharmony_ci} 2500704ebd2Sopenharmony_ci 2510704ebd2Sopenharmony_cistatic void OnDefNodeOffline(NodeBasicInfo* info) 2520704ebd2Sopenharmony_ci{ 2530704ebd2Sopenharmony_ci if (info == NULL) { 2540704ebd2Sopenharmony_ci LOG("[cb]Offline: info is null"); 2550704ebd2Sopenharmony_ci return; 2560704ebd2Sopenharmony_ci } 2570704ebd2Sopenharmony_ci LOG("[cb]Offline id:%s, name:%s, type id:%u", info->networkId, info->deviceName, info->deviceTypeId); 2580704ebd2Sopenharmony_ci g_nodeOfflineCount++; 2590704ebd2Sopenharmony_ci} 2600704ebd2Sopenharmony_ci 2610704ebd2Sopenharmony_cistatic void OnDefNodeBasicInfoChanged(NodeBasicInfoType type, NodeBasicInfo* info) 2620704ebd2Sopenharmony_ci{ 2630704ebd2Sopenharmony_ci if (info == NULL) { 2640704ebd2Sopenharmony_ci LOG("[cb]InfoChanged: info is null, type[%d]", type); 2650704ebd2Sopenharmony_ci return; 2660704ebd2Sopenharmony_ci } 2670704ebd2Sopenharmony_ci LOG("[cb]InfoChanged id: %s,name: %s", info->networkId, info->deviceName); 2680704ebd2Sopenharmony_ci} 2690704ebd2Sopenharmony_ci 2700704ebd2Sopenharmony_cistatic void onDefNodeStatusChanged(NodeStatusType type, NodeStatus *status) 2710704ebd2Sopenharmony_ci{ 2720704ebd2Sopenharmony_ci if (status == NULL) { 2730704ebd2Sopenharmony_ci LOG("[cb]StatusChanged: info is null, type[%d]", type); 2740704ebd2Sopenharmony_ci return; 2750704ebd2Sopenharmony_ci } 2760704ebd2Sopenharmony_ci LOG("[cb]StatusChanged id: %s,status: %d", status->basicInfo.networkId, status->authStatus); 2770704ebd2Sopenharmony_ci} 2780704ebd2Sopenharmony_ci 2790704ebd2Sopenharmony_cistatic int DataSessionOpened(int sessionId, int result) 2800704ebd2Sopenharmony_ci{ 2810704ebd2Sopenharmony_ci // wait 1s, ensure set current session id 2820704ebd2Sopenharmony_ci sleep(1); 2830704ebd2Sopenharmony_ci g_sessionOpenCount4Data++; 2840704ebd2Sopenharmony_ci if (result == SOFTBUS_OK) { 2850704ebd2Sopenharmony_ci if (sessionId == g_currentSessionId4Data) { 2860704ebd2Sopenharmony_ci LOG("[cb][data]open session check success sid[%d]", sessionId); 2870704ebd2Sopenharmony_ci g_waitFlag4Data = WAIT_SUCCESS_VALUE; 2880704ebd2Sopenharmony_ci } else { 2890704ebd2Sopenharmony_ci LOG("[cb][data]open session callback sid[%d] not match open " 2900704ebd2Sopenharmony_ci "sid[%d]", 2910704ebd2Sopenharmony_ci sessionId, g_currentSessionId4Data); 2920704ebd2Sopenharmony_ci g_waitFlag4Data = WAIT_FAIL_VALUE; 2930704ebd2Sopenharmony_ci } 2940704ebd2Sopenharmony_ci } else { 2950704ebd2Sopenharmony_ci g_waitFlag4Data = WAIT_FAIL_VALUE; 2960704ebd2Sopenharmony_ci } 2970704ebd2Sopenharmony_ci return SOFTBUS_OK; 2980704ebd2Sopenharmony_ci} 2990704ebd2Sopenharmony_ci 3000704ebd2Sopenharmony_cistatic void DataSessionClosed(int sessionId) 3010704ebd2Sopenharmony_ci{ 3020704ebd2Sopenharmony_ci g_sessionCloseCount4Data++; 3030704ebd2Sopenharmony_ci if (sessionId == g_currentSessionId4Data) { 3040704ebd2Sopenharmony_ci LOG("[cb][data]closed session,check sid[%d] success", sessionId); 3050704ebd2Sopenharmony_ci g_currentSessionId4Data = -1; 3060704ebd2Sopenharmony_ci g_waitFlag4DataClose = WAIT_SUCCESS_VALUE; 3070704ebd2Sopenharmony_ci } else { 3080704ebd2Sopenharmony_ci LOG("[cb][data]closed session, callback sid[%d] not match open sid[%d]", sessionId, g_currentSessionId4Data); 3090704ebd2Sopenharmony_ci g_waitFlag4DataClose = WAIT_FAIL_VALUE; 3100704ebd2Sopenharmony_ci } 3110704ebd2Sopenharmony_ci} 3120704ebd2Sopenharmony_ci 3130704ebd2Sopenharmony_cistatic void CheckReceiveData(int sessionId, const void* data, unsigned int dataLen) 3140704ebd2Sopenharmony_ci{ 3150704ebd2Sopenharmony_ci // check session id 3160704ebd2Sopenharmony_ci if (sessionId == g_currentSessionId4Data && dataLen == g_expectDataSize) { 3170704ebd2Sopenharmony_ci LOG("[check]sid/size ok[sid:%d,size:%u]", sessionId, dataLen); 3180704ebd2Sopenharmony_ci } else { 3190704ebd2Sopenharmony_ci LOG("[check]sid/size fail[sid exp:%d,real:%d][size exp:%u,real:%u]", g_currentSessionId4Data, sessionId, 3200704ebd2Sopenharmony_ci g_expectDataSize, dataLen); 3210704ebd2Sopenharmony_ci g_waitFlag = WAIT_FAIL_VALUE; 3220704ebd2Sopenharmony_ci return; 3230704ebd2Sopenharmony_ci } 3240704ebd2Sopenharmony_ci 3250704ebd2Sopenharmony_ci // check data content 3260704ebd2Sopenharmony_ci int cmpRst = strncmp(g_expectDataContent, (char*)data, dataLen); 3270704ebd2Sopenharmony_ci if (cmpRst == 0) { 3280704ebd2Sopenharmony_ci LOG("[check] cmp content ok"); 3290704ebd2Sopenharmony_ci g_waitFlag = WAIT_SUCCESS_VALUE; 3300704ebd2Sopenharmony_ci } else { 3310704ebd2Sopenharmony_ci LOG("[check] cmp content fail[exp:%s,real:%s]", g_expectDataContent, (char*)data); 3320704ebd2Sopenharmony_ci g_waitFlag = WAIT_FAIL_VALUE; 3330704ebd2Sopenharmony_ci } 3340704ebd2Sopenharmony_ci} 3350704ebd2Sopenharmony_ci 3360704ebd2Sopenharmony_cistatic void DataBytesReceived(int sessionId, const void* data, unsigned int dataLen) 3370704ebd2Sopenharmony_ci{ 3380704ebd2Sopenharmony_ci LOG("[cb][data]ByteRec start"); 3390704ebd2Sopenharmony_ci CheckReceiveData(sessionId, data, dataLen); 3400704ebd2Sopenharmony_ci g_byteCount4Data++; 3410704ebd2Sopenharmony_ci LOG("[cb][data]ByteRec end"); 3420704ebd2Sopenharmony_ci} 3430704ebd2Sopenharmony_ci 3440704ebd2Sopenharmony_cistatic void DataMessageReceived(int sessionId, const void* data, unsigned int dataLen) 3450704ebd2Sopenharmony_ci{ 3460704ebd2Sopenharmony_ci LOG("[cb][data]MessageRec start"); 3470704ebd2Sopenharmony_ci CheckReceiveData(sessionId, data, dataLen); 3480704ebd2Sopenharmony_ci g_msgCount4Data++; 3490704ebd2Sopenharmony_ci LOG("[cb][data]MessageRec end"); 3500704ebd2Sopenharmony_ci} 3510704ebd2Sopenharmony_ci 3520704ebd2Sopenharmony_cistatic int ControlSessionOpened(int sessionId, int result) 3530704ebd2Sopenharmony_ci{ 3540704ebd2Sopenharmony_ci // wait 1s, ensure set current session id 3550704ebd2Sopenharmony_ci sleep(1); 3560704ebd2Sopenharmony_ci g_sessionOpenCount4Ctrl++; 3570704ebd2Sopenharmony_ci if (result == SOFTBUS_OK) { 3580704ebd2Sopenharmony_ci if (sessionId == g_currentSessionId4Ctl) { 3590704ebd2Sopenharmony_ci LOG("[cb][ctrl]open session check success sid[%d]", sessionId); 3600704ebd2Sopenharmony_ci g_waitFlag4Ctl = WAIT_SUCCESS_VALUE; 3610704ebd2Sopenharmony_ci } else { 3620704ebd2Sopenharmony_ci LOG("[cb][ctrl]open session callback sid[%d] not match open " 3630704ebd2Sopenharmony_ci "sid[%d]", 3640704ebd2Sopenharmony_ci sessionId, g_currentSessionId4Ctl); 3650704ebd2Sopenharmony_ci g_waitFlag4Ctl = WAIT_FAIL_VALUE; 3660704ebd2Sopenharmony_ci } 3670704ebd2Sopenharmony_ci } else { 3680704ebd2Sopenharmony_ci g_waitFlag4Ctl = WAIT_FAIL_VALUE; 3690704ebd2Sopenharmony_ci } 3700704ebd2Sopenharmony_ci return SOFTBUS_OK; 3710704ebd2Sopenharmony_ci} 3720704ebd2Sopenharmony_ci 3730704ebd2Sopenharmony_cistatic void ControlSessionClosed(int sessionId) 3740704ebd2Sopenharmony_ci{ 3750704ebd2Sopenharmony_ci g_sessionCloseCount4Ctrl++; 3760704ebd2Sopenharmony_ci if (sessionId == g_currentSessionId4Ctl) { 3770704ebd2Sopenharmony_ci LOG("[cb][ctrl]closed session check sid[%d] success", sessionId); 3780704ebd2Sopenharmony_ci g_currentSessionId4Ctl = -1; 3790704ebd2Sopenharmony_ci g_waitFlag4CtlClose = WAIT_SUCCESS_VALUE; 3800704ebd2Sopenharmony_ci } else { 3810704ebd2Sopenharmony_ci LOG("[cb][ctrl]closed session callback sid[%d] not match open sid[%d]", sessionId, g_currentSessionId4Ctl); 3820704ebd2Sopenharmony_ci g_waitFlag4CtlClose = WAIT_FAIL_VALUE; 3830704ebd2Sopenharmony_ci } 3840704ebd2Sopenharmony_ci} 3850704ebd2Sopenharmony_ci 3860704ebd2Sopenharmony_cistatic void ControlBytesReceived(int sessionId, const void* data, unsigned int dataLen) 3870704ebd2Sopenharmony_ci{ 3880704ebd2Sopenharmony_ci LOG("[cb][ctrl]ByteRec sid:%d, data len:%u", sessionId, dataLen); 3890704ebd2Sopenharmony_ci if (sessionId < 0 || sessionId > MAX_SESSION_NUM) { 3900704ebd2Sopenharmony_ci LOG("[cb][ctrl]ByteRec invalid session sid[%d]", sessionId); 3910704ebd2Sopenharmony_ci return; 3920704ebd2Sopenharmony_ci } 3930704ebd2Sopenharmony_ci if (data == NULL) { 3940704ebd2Sopenharmony_ci LOG("[cb][ctrl]ByteRec invalid data=null sid[%d]", sessionId); 3950704ebd2Sopenharmony_ci return; 3960704ebd2Sopenharmony_ci } 3970704ebd2Sopenharmony_ci int sid = sessionId % MAX_SESSION_NUM; 3980704ebd2Sopenharmony_ci g_recvByteStat4Control[sid]++; 3990704ebd2Sopenharmony_ci} 4000704ebd2Sopenharmony_ci 4010704ebd2Sopenharmony_cistatic void ControlMessageReceived(int sessionId, const void* data, unsigned int dataLen) 4020704ebd2Sopenharmony_ci{ 4030704ebd2Sopenharmony_ci LOG("[cb][ctrl]MessageRec sid:%d, data len:%u", sessionId, dataLen); 4040704ebd2Sopenharmony_ci if (sessionId < 0 || sessionId > MAX_SESSION_NUM) { 4050704ebd2Sopenharmony_ci LOG("[cb][ctrl]MessageRec invalid session sid[%d]", sessionId); 4060704ebd2Sopenharmony_ci return; 4070704ebd2Sopenharmony_ci } 4080704ebd2Sopenharmony_ci if (data == NULL) { 4090704ebd2Sopenharmony_ci LOG("[cb][ctrl]MessageRec invalid data=null sid[%d]", sessionId); 4100704ebd2Sopenharmony_ci return; 4110704ebd2Sopenharmony_ci } 4120704ebd2Sopenharmony_ci int sid = sessionId % MAX_SESSION_NUM; 4130704ebd2Sopenharmony_ci g_recvMsgStat4Control[sid]++; 4140704ebd2Sopenharmony_ci} 4150704ebd2Sopenharmony_ci 4160704ebd2Sopenharmony_cistatic int PassiveSessionOpened(int sessionId, int result) 4170704ebd2Sopenharmony_ci{ 4180704ebd2Sopenharmony_ci LOG("[cb][pass]open session passive sid[%d],rst[%d]", sessionId, result); 4190704ebd2Sopenharmony_ci if (result == SOFTBUS_OK) { 4200704ebd2Sopenharmony_ci g_waitFlag = WAIT_SUCCESS_VALUE; 4210704ebd2Sopenharmony_ci } else { 4220704ebd2Sopenharmony_ci g_waitFlag = WAIT_FAIL_VALUE; 4230704ebd2Sopenharmony_ci } 4240704ebd2Sopenharmony_ci if (g_passiveOpenRetFlag == SOFTBUS_ERR) { 4250704ebd2Sopenharmony_ci LOG("[cb][pass]return fail"); 4260704ebd2Sopenharmony_ci g_passiveOpenRetFlag = SOFTBUS_OK; 4270704ebd2Sopenharmony_ci return SOFTBUS_ERR; 4280704ebd2Sopenharmony_ci } else { 4290704ebd2Sopenharmony_ci return SOFTBUS_OK; 4300704ebd2Sopenharmony_ci } 4310704ebd2Sopenharmony_ci} 4320704ebd2Sopenharmony_ci 4330704ebd2Sopenharmony_cistatic void PassiveSessionClosed(int sessionId) 4340704ebd2Sopenharmony_ci{ 4350704ebd2Sopenharmony_ci LOG("[cb][pass]close session passive sid[%d]", sessionId); 4360704ebd2Sopenharmony_ci g_waitFlag = WAIT_SUCCESS_VALUE; 4370704ebd2Sopenharmony_ci} 4380704ebd2Sopenharmony_ci 4390704ebd2Sopenharmony_cistatic void PassiveBytesReceived(int sessionId, const void* data, unsigned int dataLen) 4400704ebd2Sopenharmony_ci{ 4410704ebd2Sopenharmony_ci LOG("[cb][pass]ByteRec sid:%d, data len:%u", sessionId, dataLen); 4420704ebd2Sopenharmony_ci if (data == NULL) { 4430704ebd2Sopenharmony_ci LOG("[cb][pass]ByteRec invalid data=null sid[%d]", sessionId); 4440704ebd2Sopenharmony_ci g_waitFlag = WAIT_FAIL_VALUE; 4450704ebd2Sopenharmony_ci return; 4460704ebd2Sopenharmony_ci } 4470704ebd2Sopenharmony_ci int ret = SendBytes(sessionId, data, dataLen); 4480704ebd2Sopenharmony_ci LOG("[cb][pass]ByteRec send back ret[%d]", ret); 4490704ebd2Sopenharmony_ci if (ret == SOFTBUS_OK) { 4500704ebd2Sopenharmony_ci g_waitFlag = WAIT_SUCCESS_VALUE; 4510704ebd2Sopenharmony_ci } else { 4520704ebd2Sopenharmony_ci g_waitFlag = WAIT_FAIL_VALUE; 4530704ebd2Sopenharmony_ci } 4540704ebd2Sopenharmony_ci} 4550704ebd2Sopenharmony_ci 4560704ebd2Sopenharmony_cistatic void PassiveMessageReceived(int sessionId, const void* data, unsigned int dataLen) 4570704ebd2Sopenharmony_ci{ 4580704ebd2Sopenharmony_ci LOG("[cb][pass]MessageRec sid:%d, data len:%u", sessionId, dataLen); 4590704ebd2Sopenharmony_ci if (data == NULL) { 4600704ebd2Sopenharmony_ci LOG("[cb][pass]MessageRec invalid data=null sid[%d]", sessionId); 4610704ebd2Sopenharmony_ci g_waitFlag = WAIT_FAIL_VALUE; 4620704ebd2Sopenharmony_ci return; 4630704ebd2Sopenharmony_ci } 4640704ebd2Sopenharmony_ci int ret = SendMessage(sessionId, data, dataLen); 4650704ebd2Sopenharmony_ci LOG("[cb][pass]MessageRec send back ret[%d]", ret); 4660704ebd2Sopenharmony_ci if (ret == SOFTBUS_OK) { 4670704ebd2Sopenharmony_ci g_waitFlag = WAIT_SUCCESS_VALUE; 4680704ebd2Sopenharmony_ci } else { 4690704ebd2Sopenharmony_ci g_waitFlag = WAIT_FAIL_VALUE; 4700704ebd2Sopenharmony_ci } 4710704ebd2Sopenharmony_ci} 4720704ebd2Sopenharmony_ci 4730704ebd2Sopenharmony_cistatic int PerfSessionOpened(int sessionId, int result) 4740704ebd2Sopenharmony_ci{ 4750704ebd2Sopenharmony_ci if (result == SOFTBUS_OK) { 4760704ebd2Sopenharmony_ci g_waitFlag = WAIT_SUCCESS_VALUE; 4770704ebd2Sopenharmony_ci } else { 4780704ebd2Sopenharmony_ci LOG("[cb][perf]open session result fail, ret:%d", result); 4790704ebd2Sopenharmony_ci g_waitFlag = WAIT_FAIL_VALUE; 4800704ebd2Sopenharmony_ci } 4810704ebd2Sopenharmony_ci return SOFTBUS_OK; 4820704ebd2Sopenharmony_ci} 4830704ebd2Sopenharmony_ci 4840704ebd2Sopenharmony_cistatic void PerfSessionClosed(int sessionId) 4850704ebd2Sopenharmony_ci{ 4860704ebd2Sopenharmony_ci LOG("[cb][perf]closed session,sid[%d]", sessionId); 4870704ebd2Sopenharmony_ci} 4880704ebd2Sopenharmony_ci 4890704ebd2Sopenharmony_cistatic void PerfBytesReceived(int sessionId, const void* data, unsigned int dataLen) 4900704ebd2Sopenharmony_ci{ 4910704ebd2Sopenharmony_ci g_transTimeEnd = GetCurrentTimeOfMs(); 4920704ebd2Sopenharmony_ci 4930704ebd2Sopenharmony_ci LOG("[cb][perf]Byte recv"); 4940704ebd2Sopenharmony_ci g_waitFlag = WAIT_SUCCESS_VALUE; 4950704ebd2Sopenharmony_ci} 4960704ebd2Sopenharmony_ci 4970704ebd2Sopenharmony_cistatic void PerfMessageReceived(int sessionId, const void* data, unsigned int dataLen) 4980704ebd2Sopenharmony_ci{ 4990704ebd2Sopenharmony_ci LOG("[cb][perf]Message recv"); 5000704ebd2Sopenharmony_ci} 5010704ebd2Sopenharmony_ci 5020704ebd2Sopenharmony_cistatic int ProxySessionOpened(int sessionId, int result) 5030704ebd2Sopenharmony_ci{ 5040704ebd2Sopenharmony_ci LOG("[cb][proxy]open session proxy sid[%d],rst[%d]", sessionId, result); 5050704ebd2Sopenharmony_ci if (result == SOFTBUS_OK) { 5060704ebd2Sopenharmony_ci g_waitFlag4Proxy = WAIT_SUCCESS_VALUE; 5070704ebd2Sopenharmony_ci } else { 5080704ebd2Sopenharmony_ci g_waitFlag4Proxy = WAIT_FAIL_VALUE; 5090704ebd2Sopenharmony_ci } 5100704ebd2Sopenharmony_ci return SOFTBUS_OK; 5110704ebd2Sopenharmony_ci} 5120704ebd2Sopenharmony_ci 5130704ebd2Sopenharmony_cistatic void ProxySessionClosed(int sessionId) 5140704ebd2Sopenharmony_ci{ 5150704ebd2Sopenharmony_ci LOG("[cb][proxy]close session proxy sid[%d]", sessionId); 5160704ebd2Sopenharmony_ci g_waitFlag4Proxy = WAIT_SUCCESS_VALUE; 5170704ebd2Sopenharmony_ci} 5180704ebd2Sopenharmony_ci 5190704ebd2Sopenharmony_cistatic void ProxyBytesReceived(int sessionId, const void* data, unsigned int dataLen) 5200704ebd2Sopenharmony_ci{ 5210704ebd2Sopenharmony_ci LOG("[cb][proxy]ByteRec sid:%d, data len:%u", sessionId, dataLen); 5220704ebd2Sopenharmony_ci if (data == NULL) { 5230704ebd2Sopenharmony_ci LOG("[cb][proxy]ByteRec invalid data=null sid:[%d]", sessionId); 5240704ebd2Sopenharmony_ci g_waitFlag4Proxy = WAIT_FAIL_VALUE; 5250704ebd2Sopenharmony_ci } else { 5260704ebd2Sopenharmony_ci g_waitFlag4Proxy = WAIT_SUCCESS_VALUE; 5270704ebd2Sopenharmony_ci } 5280704ebd2Sopenharmony_ci} 5290704ebd2Sopenharmony_ci 5300704ebd2Sopenharmony_cistatic void ProxyMessageReceived(int sessionId, const void* data, unsigned int dataLen) 5310704ebd2Sopenharmony_ci{ 5320704ebd2Sopenharmony_ci LOG("[cb][proxy]MessageRec sid:%d, data len:%u", sessionId, dataLen); 5330704ebd2Sopenharmony_ci if (data == NULL) { 5340704ebd2Sopenharmony_ci LOG("[cb][proxy]MessageRec invalid data=null sid[%d]", sessionId); 5350704ebd2Sopenharmony_ci g_waitFlag4Proxy = WAIT_FAIL_VALUE; 5360704ebd2Sopenharmony_ci } else { 5370704ebd2Sopenharmony_ci g_waitFlag4Proxy = WAIT_SUCCESS_VALUE; 5380704ebd2Sopenharmony_ci } 5390704ebd2Sopenharmony_ci} 5400704ebd2Sopenharmony_ci 5410704ebd2Sopenharmony_cistatic int StreamSessionOpened(int sessionId, int result) 5420704ebd2Sopenharmony_ci{ 5430704ebd2Sopenharmony_ci LOG("[cb][stream]open session sessionId[%d],rst[%d]", sessionId, result); 5440704ebd2Sopenharmony_ci if (result == SOFTBUS_OK) { 5450704ebd2Sopenharmony_ci g_waitFlag4Stream = WAIT_SUCCESS_VALUE; 5460704ebd2Sopenharmony_ci } else { 5470704ebd2Sopenharmony_ci g_waitFlag4Stream = WAIT_FAIL_VALUE; 5480704ebd2Sopenharmony_ci } 5490704ebd2Sopenharmony_ci return SOFTBUS_OK; 5500704ebd2Sopenharmony_ci} 5510704ebd2Sopenharmony_ci 5520704ebd2Sopenharmony_cistatic void StreamSessionClosed(int sessionId) 5530704ebd2Sopenharmony_ci{ 5540704ebd2Sopenharmony_ci LOG("[cb][stream]close session sessionId[%d]", sessionId); 5550704ebd2Sopenharmony_ci} 5560704ebd2Sopenharmony_ci 5570704ebd2Sopenharmony_ci 5580704ebd2Sopenharmony_cistatic void StreamReceived(int sessionId, const StreamData *data, const StreamData *ext, const StreamFrameInfo *frame) 5590704ebd2Sopenharmony_ci{ 5600704ebd2Sopenharmony_ci if (data != NULL) { 5610704ebd2Sopenharmony_ci LOG("[cb][stream]ByteRec sessionId:%d, data= %.*s.\n", sessionId, data->bufLen, data->buf); 5620704ebd2Sopenharmony_ci g_waitFlag4Stream = WAIT_SUCCESS_VALUE; 5630704ebd2Sopenharmony_ci } 5640704ebd2Sopenharmony_ci} 5650704ebd2Sopenharmony_ci 5660704ebd2Sopenharmony_civoid ResetWaitFlag(void) 5670704ebd2Sopenharmony_ci{ 5680704ebd2Sopenharmony_ci g_waitFlag = WAIT_DEF_VALUE; 5690704ebd2Sopenharmony_ci} 5700704ebd2Sopenharmony_ci 5710704ebd2Sopenharmony_civoid ResetWaitFlag4Data(void) 5720704ebd2Sopenharmony_ci{ 5730704ebd2Sopenharmony_ci g_waitFlag4Data = WAIT_DEF_VALUE; 5740704ebd2Sopenharmony_ci g_waitFlag4DataClose = WAIT_DEF_VALUE; 5750704ebd2Sopenharmony_ci} 5760704ebd2Sopenharmony_ci 5770704ebd2Sopenharmony_civoid ResetWaitFlag4Ctl(void) 5780704ebd2Sopenharmony_ci{ 5790704ebd2Sopenharmony_ci g_waitFlag4Ctl = WAIT_DEF_VALUE; 5800704ebd2Sopenharmony_ci g_waitFlag4CtlClose = WAIT_DEF_VALUE; 5810704ebd2Sopenharmony_ci} 5820704ebd2Sopenharmony_ci 5830704ebd2Sopenharmony_civoid ResetWaitFlag4Proxy(void) 5840704ebd2Sopenharmony_ci{ 5850704ebd2Sopenharmony_ci g_waitFlag4Proxy = WAIT_DEF_VALUE; 5860704ebd2Sopenharmony_ci} 5870704ebd2Sopenharmony_ci 5880704ebd2Sopenharmony_civoid ResetwaitCount4Online(void) 5890704ebd2Sopenharmony_ci{ 5900704ebd2Sopenharmony_ci g_nodeOnlineCount = 0; 5910704ebd2Sopenharmony_ci} 5920704ebd2Sopenharmony_ci 5930704ebd2Sopenharmony_civoid ResetwaitCount4Offline(void) 5940704ebd2Sopenharmony_ci{ 5950704ebd2Sopenharmony_ci g_nodeOfflineCount = 0; 5960704ebd2Sopenharmony_ci} 5970704ebd2Sopenharmony_ci 5980704ebd2Sopenharmony_ciint RegisterDeviceStateDefCallback(void) 5990704ebd2Sopenharmony_ci{ 6000704ebd2Sopenharmony_ci return RegNodeDeviceStateCb(DEF_PKG_NAME, &g_defNodeStateCallback); 6010704ebd2Sopenharmony_ci} 6020704ebd2Sopenharmony_ci 6030704ebd2Sopenharmony_ciint UnRegisterDeviceStateDefCallback(void) 6040704ebd2Sopenharmony_ci{ 6050704ebd2Sopenharmony_ci return UnregNodeDeviceStateCb(&g_defNodeStateCallback); 6060704ebd2Sopenharmony_ci} 6070704ebd2Sopenharmony_ci 6080704ebd2Sopenharmony_ciint CreateSsAndOpenSession4Data(void) 6090704ebd2Sopenharmony_ci{ 6100704ebd2Sopenharmony_ci int ret; 6110704ebd2Sopenharmony_ci int timeout = 10; 6120704ebd2Sopenharmony_ci ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, g_sessionlistener4Data); 6130704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 6140704ebd2Sopenharmony_ci LOG("call CreateSessionServer[data] fail, ret:%d", ret); 6150704ebd2Sopenharmony_ci return ret; 6160704ebd2Sopenharmony_ci } 6170704ebd2Sopenharmony_ci 6180704ebd2Sopenharmony_ci ResetWaitFlag4Data(); 6190704ebd2Sopenharmony_ci int sessionId; 6200704ebd2Sopenharmony_ci sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, g_networkId, DEF_GROUP_ID, g_sessionAttr4Data); 6210704ebd2Sopenharmony_ci if (sessionId < SESSION_ID_MIN) { 6220704ebd2Sopenharmony_ci LOG("call OpenSession[data] fail, ret sid:%d,netId:%s", sessionId, g_networkId); 6230704ebd2Sopenharmony_ci ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA); 6240704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 6250704ebd2Sopenharmony_ci LOG("RemoveSessionServer[data] fail, ret:%d", ret); 6260704ebd2Sopenharmony_ci } 6270704ebd2Sopenharmony_ci return SOFTBUS_ERR; 6280704ebd2Sopenharmony_ci } 6290704ebd2Sopenharmony_ci SetCurrentSessionId4Data(sessionId); 6300704ebd2Sopenharmony_ci LOG("call OpenSession[data] success,sid:%d", sessionId); 6310704ebd2Sopenharmony_ci 6320704ebd2Sopenharmony_ci ret = Wait4Session(timeout, SESSION_4DATA); 6330704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 6340704ebd2Sopenharmony_ci LOG("OpenSession[data] fail"); 6350704ebd2Sopenharmony_ci ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA); 6360704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 6370704ebd2Sopenharmony_ci LOG("RemoveSessionServer[data] fail, ret:%d", ret); 6380704ebd2Sopenharmony_ci } 6390704ebd2Sopenharmony_ci return SOFTBUS_ERR; 6400704ebd2Sopenharmony_ci } 6410704ebd2Sopenharmony_ci return ret; 6420704ebd2Sopenharmony_ci} 6430704ebd2Sopenharmony_ci 6440704ebd2Sopenharmony_ciint CreateSsAndOpenSession4Ctl(void) 6450704ebd2Sopenharmony_ci{ 6460704ebd2Sopenharmony_ci int ret; 6470704ebd2Sopenharmony_ci int timeout = 10; 6480704ebd2Sopenharmony_ci ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL, g_sessionlistener4Ctl); 6490704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 6500704ebd2Sopenharmony_ci LOG("call CreateSessionServer[ctl] fail, ret:%d", ret); 6510704ebd2Sopenharmony_ci return ret; 6520704ebd2Sopenharmony_ci } 6530704ebd2Sopenharmony_ci 6540704ebd2Sopenharmony_ci int sessionId; 6550704ebd2Sopenharmony_ci ResetWaitFlag4Ctl(); 6560704ebd2Sopenharmony_ci sessionId = OpenSession(SESSION_NAME_CTL, SESSION_NAME_CTL, g_networkId, DEF_GROUP_ID, g_sessionAttr4Ctl); 6570704ebd2Sopenharmony_ci if (sessionId < SESSION_ID_MIN) { 6580704ebd2Sopenharmony_ci LOG("call OpenSession[ctl] fail, ret sid:%d", sessionId); 6590704ebd2Sopenharmony_ci ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL); 6600704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 6610704ebd2Sopenharmony_ci LOG("RemoveSessionServer[ctl] fail, ret:%d", ret); 6620704ebd2Sopenharmony_ci } 6630704ebd2Sopenharmony_ci return SOFTBUS_ERR; 6640704ebd2Sopenharmony_ci } 6650704ebd2Sopenharmony_ci SetCurrentSessionId4Ctl(sessionId); 6660704ebd2Sopenharmony_ci LOG("call OpenSession[ctl] success,sid:%d", sessionId); 6670704ebd2Sopenharmony_ci 6680704ebd2Sopenharmony_ci ret = Wait4Session(timeout, SESSION_4CTL); 6690704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 6700704ebd2Sopenharmony_ci LOG("OpenSession[ctl] fail"); 6710704ebd2Sopenharmony_ci ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL); 6720704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 6730704ebd2Sopenharmony_ci LOG("RemoveSessionServer[ctl] fail, ret:%d", ret); 6740704ebd2Sopenharmony_ci } 6750704ebd2Sopenharmony_ci return SOFTBUS_ERR; 6760704ebd2Sopenharmony_ci } 6770704ebd2Sopenharmony_ci return ret; 6780704ebd2Sopenharmony_ci} 6790704ebd2Sopenharmony_ci 6800704ebd2Sopenharmony_ciint CreateSsAndOpenSession4Proxy(void) 6810704ebd2Sopenharmony_ci{ 6820704ebd2Sopenharmony_ci int ret; 6830704ebd2Sopenharmony_ci int timeout = 10; 6840704ebd2Sopenharmony_ci ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_PROXY, g_sessionlistener4Proxy); 6850704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 6860704ebd2Sopenharmony_ci LOG("call CreateSessionServer[Proxy] fail, ret:%d", ret); 6870704ebd2Sopenharmony_ci return ret; 6880704ebd2Sopenharmony_ci } 6890704ebd2Sopenharmony_ci 6900704ebd2Sopenharmony_ci int sessionId; 6910704ebd2Sopenharmony_ci ResetWaitFlag(); 6920704ebd2Sopenharmony_ci sessionId = OpenSession(SESSION_NAME_PROXY, SESSION_NAME_PROXY, g_networkId, DEF_GROUP_ID, g_sessionAttr4Proxy); 6930704ebd2Sopenharmony_ci if (sessionId < SESSION_ID_MIN) { 6940704ebd2Sopenharmony_ci LOG("call OpenSession[Proxy] fail, ret sid:%d", sessionId); 6950704ebd2Sopenharmony_ci return SOFTBUS_ERR; 6960704ebd2Sopenharmony_ci } 6970704ebd2Sopenharmony_ci SetCurrentSessionId4Proxy(sessionId); 6980704ebd2Sopenharmony_ci LOG("call OpenSession[Proxy] success,sid:%d", sessionId); 6990704ebd2Sopenharmony_ci 7000704ebd2Sopenharmony_ci ret = Wait4Session(timeout, SESSION_4PROXY); 7010704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 7020704ebd2Sopenharmony_ci LOG("OpenSession[Proxy] fail"); 7030704ebd2Sopenharmony_ci return SOFTBUS_ERR; 7040704ebd2Sopenharmony_ci } 7050704ebd2Sopenharmony_ci return ret; 7060704ebd2Sopenharmony_ci} 7070704ebd2Sopenharmony_ci 7080704ebd2Sopenharmony_ciint SendData4Data(DataType type, int size) 7090704ebd2Sopenharmony_ci{ 7100704ebd2Sopenharmony_ci int ret; 7110704ebd2Sopenharmony_ci if (size > 0) { 7120704ebd2Sopenharmony_ci g_expectDataContent = (char*)calloc(1, size); 7130704ebd2Sopenharmony_ci if (g_expectDataContent == NULL) { 7140704ebd2Sopenharmony_ci LOG("[send data]calloc fail"); 7150704ebd2Sopenharmony_ci return SOFTBUS_ERR; 7160704ebd2Sopenharmony_ci } 7170704ebd2Sopenharmony_ci (void)memset_s(g_expectDataContent, size, g_fillContentChar, size); 7180704ebd2Sopenharmony_ci } else { 7190704ebd2Sopenharmony_ci LOG("[send data]invalid param[size>=1]"); 7200704ebd2Sopenharmony_ci return SOFTBUS_ERR; 7210704ebd2Sopenharmony_ci } 7220704ebd2Sopenharmony_ci 7230704ebd2Sopenharmony_ci g_expectDataSize = size; 7240704ebd2Sopenharmony_ci ResetWaitFlag(); 7250704ebd2Sopenharmony_ci if (type == DATA_TYPE_MSG) { 7260704ebd2Sopenharmony_ci ret = SendMessage(g_currentSessionId4Data, g_expectDataContent, size); 7270704ebd2Sopenharmony_ci } else if (type == DATA_TYPE_BYTE) { 7280704ebd2Sopenharmony_ci ret = SendBytes(g_currentSessionId4Data, g_expectDataContent, size); 7290704ebd2Sopenharmony_ci } else { 7300704ebd2Sopenharmony_ci LOG("[send data]invalid param[DataType]"); 7310704ebd2Sopenharmony_ci free(g_expectDataContent); 7320704ebd2Sopenharmony_ci return SOFTBUS_ERR; 7330704ebd2Sopenharmony_ci } 7340704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 7350704ebd2Sopenharmony_ci LOG("[send data]call SendX fail, ret:%d", ret); 7360704ebd2Sopenharmony_ci free(g_expectDataContent); 7370704ebd2Sopenharmony_ci return SOFTBUS_ERR; 7380704ebd2Sopenharmony_ci } 7390704ebd2Sopenharmony_ci LOG("[send data]call SendX success"); 7400704ebd2Sopenharmony_ci int sleeptime = 15; 7410704ebd2Sopenharmony_ci int timeout = 5; 7420704ebd2Sopenharmony_ci if (size > SIZE_1K * SIZE_1K) { 7430704ebd2Sopenharmony_ci timeout = sleeptime; 7440704ebd2Sopenharmony_ci } 7450704ebd2Sopenharmony_ci ret = Wait(timeout); 7460704ebd2Sopenharmony_ci free(g_expectDataContent); 7470704ebd2Sopenharmony_ci g_expectDataContent = NULL; 7480704ebd2Sopenharmony_ci return ret; 7490704ebd2Sopenharmony_ci} 7500704ebd2Sopenharmony_ci 7510704ebd2Sopenharmony_ciint SendData4Message(DataType type, int size) 7520704ebd2Sopenharmony_ci{ 7530704ebd2Sopenharmony_ci int ret; 7540704ebd2Sopenharmony_ci if (size > 0) { 7550704ebd2Sopenharmony_ci g_expectMessageContent = (char*)calloc(1, size); 7560704ebd2Sopenharmony_ci if (g_expectMessageContent == NULL) { 7570704ebd2Sopenharmony_ci LOG("[send data]calloc fail"); 7580704ebd2Sopenharmony_ci return SOFTBUS_ERR; 7590704ebd2Sopenharmony_ci } 7600704ebd2Sopenharmony_ci (void)memset_s(g_expectMessageContent, size, g_fillContentChar, size); 7610704ebd2Sopenharmony_ci } else { 7620704ebd2Sopenharmony_ci LOG("[send data]invalid param[size>=1]"); 7630704ebd2Sopenharmony_ci return SOFTBUS_ERR; 7640704ebd2Sopenharmony_ci } 7650704ebd2Sopenharmony_ci 7660704ebd2Sopenharmony_ci g_expectDataSize = size; 7670704ebd2Sopenharmony_ci ResetWaitFlag(); 7680704ebd2Sopenharmony_ci if (type == DATA_TYPE_MSG) { 7690704ebd2Sopenharmony_ci ret = SendMessage(g_currentSessionId4Proxy, g_expectMessageContent, size); 7700704ebd2Sopenharmony_ci } else if (type == DATA_TYPE_BYTE) { 7710704ebd2Sopenharmony_ci ret = SendBytes(g_currentSessionId4Proxy, g_expectMessageContent, size); 7720704ebd2Sopenharmony_ci } else { 7730704ebd2Sopenharmony_ci LOG("[send data]invalid param[DataType]"); 7740704ebd2Sopenharmony_ci free(g_expectMessageContent); 7750704ebd2Sopenharmony_ci return SOFTBUS_ERR; 7760704ebd2Sopenharmony_ci } 7770704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 7780704ebd2Sopenharmony_ci LOG("[send data]call SendX fail, ret:%d", ret); 7790704ebd2Sopenharmony_ci free(g_expectMessageContent); 7800704ebd2Sopenharmony_ci return SOFTBUS_ERR; 7810704ebd2Sopenharmony_ci } 7820704ebd2Sopenharmony_ci free(g_expectMessageContent); 7830704ebd2Sopenharmony_ci g_expectMessageContent = NULL; 7840704ebd2Sopenharmony_ci return ret; 7850704ebd2Sopenharmony_ci} 7860704ebd2Sopenharmony_ci 7870704ebd2Sopenharmony_ciint CloseSessionAndRemoveSs4Data(void) 7880704ebd2Sopenharmony_ci{ 7890704ebd2Sopenharmony_ci int ret4Close; 7900704ebd2Sopenharmony_ci int timeout = 2; 7910704ebd2Sopenharmony_ci // 主动close不回调 7920704ebd2Sopenharmony_ci ResetWaitFlag4Data(); 7930704ebd2Sopenharmony_ci CloseSession(g_currentSessionId4Data); 7940704ebd2Sopenharmony_ci ret4Close = Wait4Session(timeout, SESSION_4DATA); 7950704ebd2Sopenharmony_ci if (ret4Close == SOFTBUS_OK) { 7960704ebd2Sopenharmony_ci LOG("CloseSession[data] recv callback"); 7970704ebd2Sopenharmony_ci } 7980704ebd2Sopenharmony_ci 7990704ebd2Sopenharmony_ci int ret4Ss; 8000704ebd2Sopenharmony_ci ret4Ss = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA); 8010704ebd2Sopenharmony_ci if (ret4Ss != SOFTBUS_OK) { 8020704ebd2Sopenharmony_ci LOG("RemoveSessionServer[data] fail, ret:%d", ret4Ss); 8030704ebd2Sopenharmony_ci } 8040704ebd2Sopenharmony_ci 8050704ebd2Sopenharmony_ci if (ret4Ss != SOFTBUS_OK || ret4Close == SOFTBUS_OK) { 8060704ebd2Sopenharmony_ci return SOFTBUS_ERR; 8070704ebd2Sopenharmony_ci } else { 8080704ebd2Sopenharmony_ci return SOFTBUS_OK; 8090704ebd2Sopenharmony_ci } 8100704ebd2Sopenharmony_ci} 8110704ebd2Sopenharmony_ci 8120704ebd2Sopenharmony_ciint CloseSessionAndRemoveSs4Ctl(void) 8130704ebd2Sopenharmony_ci{ 8140704ebd2Sopenharmony_ci int ret4Close; 8150704ebd2Sopenharmony_ci int timeout = 2; 8160704ebd2Sopenharmony_ci ResetWaitFlag4Ctl(); 8170704ebd2Sopenharmony_ci CloseSession(g_currentSessionId4Ctl); 8180704ebd2Sopenharmony_ci ret4Close = Wait4Session(timeout, SESSION_4CTL); 8190704ebd2Sopenharmony_ci if (ret4Close == SOFTBUS_OK) { 8200704ebd2Sopenharmony_ci LOG("CloseSession[ctrl] recv callback"); 8210704ebd2Sopenharmony_ci } 8220704ebd2Sopenharmony_ci 8230704ebd2Sopenharmony_ci int ret4Ss; 8240704ebd2Sopenharmony_ci ret4Ss = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL); 8250704ebd2Sopenharmony_ci if (ret4Ss != SOFTBUS_OK) { 8260704ebd2Sopenharmony_ci LOG("RemoveSessionServer[ctl] fail, ret:%d", ret4Ss); 8270704ebd2Sopenharmony_ci } 8280704ebd2Sopenharmony_ci 8290704ebd2Sopenharmony_ci if (ret4Ss != SOFTBUS_OK || ret4Close == SOFTBUS_OK) { 8300704ebd2Sopenharmony_ci return SOFTBUS_ERR; 8310704ebd2Sopenharmony_ci } else { 8320704ebd2Sopenharmony_ci return SOFTBUS_OK; 8330704ebd2Sopenharmony_ci } 8340704ebd2Sopenharmony_ci} 8350704ebd2Sopenharmony_ci 8360704ebd2Sopenharmony_ciint CloseSessionAndRemoveSs4Proxy(void) 8370704ebd2Sopenharmony_ci{ 8380704ebd2Sopenharmony_ci int ret4Close; 8390704ebd2Sopenharmony_ci int timeout = 2; 8400704ebd2Sopenharmony_ci ResetWaitFlag(); 8410704ebd2Sopenharmony_ci CloseSession(g_currentSessionId4Proxy); 8420704ebd2Sopenharmony_ci ret4Close = Wait(timeout); 8430704ebd2Sopenharmony_ci if (ret4Close == SOFTBUS_OK) { 8440704ebd2Sopenharmony_ci LOG("CloseSession[Proxy] recv callback"); 8450704ebd2Sopenharmony_ci } 8460704ebd2Sopenharmony_ci 8470704ebd2Sopenharmony_ci int ret4Ss; 8480704ebd2Sopenharmony_ci ret4Ss = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_PROXY); 8490704ebd2Sopenharmony_ci if (ret4Ss != SOFTBUS_OK) { 8500704ebd2Sopenharmony_ci LOG("RemoveSessionServer[Proxy] fail, ret:%d", ret4Ss); 8510704ebd2Sopenharmony_ci } 8520704ebd2Sopenharmony_ci 8530704ebd2Sopenharmony_ci if (ret4Ss != SOFTBUS_OK || ret4Close == SOFTBUS_OK) { 8540704ebd2Sopenharmony_ci return SOFTBUS_ERR; 8550704ebd2Sopenharmony_ci } else { 8560704ebd2Sopenharmony_ci return SOFTBUS_OK; 8570704ebd2Sopenharmony_ci } 8580704ebd2Sopenharmony_ci} 8590704ebd2Sopenharmony_ci 8600704ebd2Sopenharmony_ciint OpenSession4DataByP2p(void) 8610704ebd2Sopenharmony_ci{ 8620704ebd2Sopenharmony_ci int ret; 8630704ebd2Sopenharmony_ci int timeout = 10; 8640704ebd2Sopenharmony_ci ResetWaitFlag4Data(); 8650704ebd2Sopenharmony_ci int sId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, g_networkId, DEF_GROUP_ID, g_p2pattribute); 8660704ebd2Sopenharmony_ci if (sId < SESSION_ID_MIN) { 8670704ebd2Sopenharmony_ci LOG("openSession[data] fail,id:%d, netId:%s", sId, g_networkId); 8680704ebd2Sopenharmony_ci return SOFTBUS_ERR; 8690704ebd2Sopenharmony_ci } 8700704ebd2Sopenharmony_ci SetCurrentSessionId4Data(sId); 8710704ebd2Sopenharmony_ci ret = Wait4Session(timeout, SESSION_4DATA); 8720704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 8730704ebd2Sopenharmony_ci LOG("Wait4Session[data] fail"); 8740704ebd2Sopenharmony_ci return SOFTBUS_ERR; 8750704ebd2Sopenharmony_ci } 8760704ebd2Sopenharmony_ci return ret; 8770704ebd2Sopenharmony_ci} 8780704ebd2Sopenharmony_ci 8790704ebd2Sopenharmony_ciint OpenSession4ProxyByP2p(void) 8800704ebd2Sopenharmony_ci{ 8810704ebd2Sopenharmony_ci int ret; 8820704ebd2Sopenharmony_ci int timeout = 10; 8830704ebd2Sopenharmony_ci ResetWaitFlag4Proxy(); 8840704ebd2Sopenharmony_ci int sId = OpenSession(SESSION_NAME_PROXY, SESSION_NAME_PROXY, g_networkId, DEF_GROUP_ID, g_p2pattributeProxy); 8850704ebd2Sopenharmony_ci if (sId < SESSION_ID_MIN) { 8860704ebd2Sopenharmony_ci LOG("openSession[data] fail,id:%d, netId:%s", sId, g_networkId); 8870704ebd2Sopenharmony_ci return SOFTBUS_ERR; 8880704ebd2Sopenharmony_ci } 8890704ebd2Sopenharmony_ci SetCurrentSessionId4Proxy(sId); 8900704ebd2Sopenharmony_ci ret = Wait4Session(timeout, SESSION_4PROXY); 8910704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 8920704ebd2Sopenharmony_ci LOG("Wait4Session[data] fail"); 8930704ebd2Sopenharmony_ci return SOFTBUS_ERR; 8940704ebd2Sopenharmony_ci } 8950704ebd2Sopenharmony_ci 8960704ebd2Sopenharmony_ci return ret; 8970704ebd2Sopenharmony_ci} 8980704ebd2Sopenharmony_ci 8990704ebd2Sopenharmony_ciint OpenSessionBatch4Data(char groupId[][GROUP_ID_LEN], int* sessionId, int count) 9000704ebd2Sopenharmony_ci{ 9010704ebd2Sopenharmony_ci int ret; 9020704ebd2Sopenharmony_ci int timeout = 10; 9030704ebd2Sopenharmony_ci int rstFlag = SOFTBUS_OK; 9040704ebd2Sopenharmony_ci for (int i = 0; i < count; i++) { 9050704ebd2Sopenharmony_ci ResetWaitFlag4Data(); 9060704ebd2Sopenharmony_ci int sId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, g_networkId, groupId[i], g_sessionAttr4Data); 9070704ebd2Sopenharmony_ci if (sId < SESSION_ID_MIN) { 9080704ebd2Sopenharmony_ci LOG("call OpenSession[data] fail,sid:%d,i:%d", sId, i); 9090704ebd2Sopenharmony_ci rstFlag = SOFTBUS_ERR; 9100704ebd2Sopenharmony_ci continue; 9110704ebd2Sopenharmony_ci } 9120704ebd2Sopenharmony_ci SetCurrentSessionId4Data(sId); 9130704ebd2Sopenharmony_ci *(sessionId + i) = sId; 9140704ebd2Sopenharmony_ci ret = Wait4Session(timeout, SESSION_4DATA); 9150704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 9160704ebd2Sopenharmony_ci LOG("Wait4Session[data] fail,i:%d", i); 9170704ebd2Sopenharmony_ci rstFlag = SOFTBUS_ERR; 9180704ebd2Sopenharmony_ci } 9190704ebd2Sopenharmony_ci } 9200704ebd2Sopenharmony_ci return rstFlag; 9210704ebd2Sopenharmony_ci} 9220704ebd2Sopenharmony_ci 9230704ebd2Sopenharmony_ciint OpenSessionBatch4Ctl(char groupId[][GROUP_ID_LEN], int* sessionId, int count) 9240704ebd2Sopenharmony_ci{ 9250704ebd2Sopenharmony_ci int ret; 9260704ebd2Sopenharmony_ci int timeout = 10; 9270704ebd2Sopenharmony_ci int rstFlag = SOFTBUS_OK; 9280704ebd2Sopenharmony_ci for (int i = 0; i < count; i++) { 9290704ebd2Sopenharmony_ci ResetWaitFlag4Ctl(); 9300704ebd2Sopenharmony_ci int sId = OpenSession(SESSION_NAME_CTL, SESSION_NAME_CTL, g_networkId, groupId[i], g_sessionAttr4Ctl); 9310704ebd2Sopenharmony_ci if (sId < SESSION_ID_MIN) { 9320704ebd2Sopenharmony_ci LOG("call OpenSession[ctrl] fail,sid:%d,i:%d", sId, i); 9330704ebd2Sopenharmony_ci rstFlag = SOFTBUS_ERR; 9340704ebd2Sopenharmony_ci continue; 9350704ebd2Sopenharmony_ci } 9360704ebd2Sopenharmony_ci SetCurrentSessionId4Ctl(sId); 9370704ebd2Sopenharmony_ci *(sessionId + i) = sId; 9380704ebd2Sopenharmony_ci ret = Wait4Session(timeout, SESSION_4CTL); 9390704ebd2Sopenharmony_ci if (ret != SOFTBUS_OK) { 9400704ebd2Sopenharmony_ci LOG("Wait4Session[ctrl] fail,i:%d", i); 9410704ebd2Sopenharmony_ci rstFlag = SOFTBUS_ERR; 9420704ebd2Sopenharmony_ci } 9430704ebd2Sopenharmony_ci } 9440704ebd2Sopenharmony_ci return rstFlag; 9450704ebd2Sopenharmony_ci} 9460704ebd2Sopenharmony_ci 9470704ebd2Sopenharmony_ciint CloseSessionBatch4Data(int* sessionId, int count) 9480704ebd2Sopenharmony_ci{ 9490704ebd2Sopenharmony_ci for (int i = 0; i < count; i++) { 9500704ebd2Sopenharmony_ci int sid = *(sessionId + i); 9510704ebd2Sopenharmony_ci LOG("close session[data] sid:%d", sid); 9520704ebd2Sopenharmony_ci 9530704ebd2Sopenharmony_ci SetCurrentSessionId4Data(sid); 9540704ebd2Sopenharmony_ci CloseSession(sid); 9550704ebd2Sopenharmony_ci } 9560704ebd2Sopenharmony_ci return SOFTBUS_OK; 9570704ebd2Sopenharmony_ci} 9580704ebd2Sopenharmony_ci 9590704ebd2Sopenharmony_ciint CloseSessionBatch4Ctl(int* sessionId, int count) 9600704ebd2Sopenharmony_ci{ 9610704ebd2Sopenharmony_ci for (int i = 0; i < count; i++) { 9620704ebd2Sopenharmony_ci int sid = *(sessionId + i); 9630704ebd2Sopenharmony_ci LOG("close session[ctrl] sid:%d", sid); 9640704ebd2Sopenharmony_ci 9650704ebd2Sopenharmony_ci SetCurrentSessionId4Ctl(sid); 9660704ebd2Sopenharmony_ci CloseSession(sid); 9670704ebd2Sopenharmony_ci } 9680704ebd2Sopenharmony_ci return SOFTBUS_OK; 9690704ebd2Sopenharmony_ci} 9700704ebd2Sopenharmony_ci 9710704ebd2Sopenharmony_ciint WaitNodeCount(int timeout, WaitNodeStateType state, int expectCount) 9720704ebd2Sopenharmony_ci{ 9730704ebd2Sopenharmony_ci LOG("Wait4Node,timeout:%d, type:%d, exp count:%d", timeout, state, expectCount); 9740704ebd2Sopenharmony_ci int hitFlag = -1; 9750704ebd2Sopenharmony_ci while (timeout > 0) { 9760704ebd2Sopenharmony_ci sleep(ONE_SECOND); 9770704ebd2Sopenharmony_ci switch (state) { 9780704ebd2Sopenharmony_ci case STATE_ONLINE: 9790704ebd2Sopenharmony_ci if (g_nodeOnlineCount == expectCount) { 9800704ebd2Sopenharmony_ci LOG("Wait4Node[online] succ,timeout:%d", timeout); 9810704ebd2Sopenharmony_ci hitFlag = 1; 9820704ebd2Sopenharmony_ci } 9830704ebd2Sopenharmony_ci break; 9840704ebd2Sopenharmony_ci case STATE_OFFLINE: 9850704ebd2Sopenharmony_ci if (g_nodeOfflineCount == expectCount) { 9860704ebd2Sopenharmony_ci LOG("Wait4Node[offline] succ,timeout:%d", timeout); 9870704ebd2Sopenharmony_ci hitFlag = 1; 9880704ebd2Sopenharmony_ci } 9890704ebd2Sopenharmony_ci break; 9900704ebd2Sopenharmony_ci default: 9910704ebd2Sopenharmony_ci LOG("Wait4Node state error"); 9920704ebd2Sopenharmony_ci hitFlag = 1; 9930704ebd2Sopenharmony_ci break; 9940704ebd2Sopenharmony_ci } 9950704ebd2Sopenharmony_ci if (hitFlag != -1) { 9960704ebd2Sopenharmony_ci break; 9970704ebd2Sopenharmony_ci } 9980704ebd2Sopenharmony_ci timeout--; 9990704ebd2Sopenharmony_ci } 10000704ebd2Sopenharmony_ci switch (state) { 10010704ebd2Sopenharmony_ci case STATE_ONLINE: 10020704ebd2Sopenharmony_ci if (g_nodeOnlineCount != expectCount) { 10030704ebd2Sopenharmony_ci LOG("Wait4Node[online] fail[exp:%d, real:%d]", expectCount, g_nodeOnlineCount); 10040704ebd2Sopenharmony_ci return SOFTBUS_ERR; 10050704ebd2Sopenharmony_ci } 10060704ebd2Sopenharmony_ci break; 10070704ebd2Sopenharmony_ci case STATE_OFFLINE: 10080704ebd2Sopenharmony_ci if (g_nodeOfflineCount != expectCount) { 10090704ebd2Sopenharmony_ci LOG("Wait4Node[offline] fail[exp:%d, real:%d]", expectCount, g_nodeOfflineCount); 10100704ebd2Sopenharmony_ci return SOFTBUS_ERR; 10110704ebd2Sopenharmony_ci } 10120704ebd2Sopenharmony_ci break; 10130704ebd2Sopenharmony_ci default: 10140704ebd2Sopenharmony_ci return SOFTBUS_ERR; 10150704ebd2Sopenharmony_ci } 10160704ebd2Sopenharmony_ci return SOFTBUS_OK; 10170704ebd2Sopenharmony_ci} 10180704ebd2Sopenharmony_ci 10190704ebd2Sopenharmony_ci// set/get function 10200704ebd2Sopenharmony_civoid ResetClosedSessionCount4Data(void) 10210704ebd2Sopenharmony_ci{ 10220704ebd2Sopenharmony_ci g_sessionCloseCount4Data = 0; 10230704ebd2Sopenharmony_ci} 10240704ebd2Sopenharmony_ci 10250704ebd2Sopenharmony_civoid ResetClosedSessionCount4Ctrl(void) 10260704ebd2Sopenharmony_ci{ 10270704ebd2Sopenharmony_ci g_sessionCloseCount4Ctrl = 0; 10280704ebd2Sopenharmony_ci} 10290704ebd2Sopenharmony_ci 10300704ebd2Sopenharmony_ciint GetClosedSessionCount4Data(void) 10310704ebd2Sopenharmony_ci{ 10320704ebd2Sopenharmony_ci return g_sessionCloseCount4Data; 10330704ebd2Sopenharmony_ci} 10340704ebd2Sopenharmony_ci 10350704ebd2Sopenharmony_ciint GetClosedSessionCount4Ctrl(void) 10360704ebd2Sopenharmony_ci{ 10370704ebd2Sopenharmony_ci return g_sessionCloseCount4Ctrl; 10380704ebd2Sopenharmony_ci} 10390704ebd2Sopenharmony_ci 10400704ebd2Sopenharmony_cichar* GetNetworkId(void) 10410704ebd2Sopenharmony_ci{ 10420704ebd2Sopenharmony_ci return g_networkId; 10430704ebd2Sopenharmony_ci} 10440704ebd2Sopenharmony_ci 10450704ebd2Sopenharmony_ci// To one device only 10460704ebd2Sopenharmony_ciint CheckRemoteDeviceIsNull(int isSetNetId) 10470704ebd2Sopenharmony_ci{ 10480704ebd2Sopenharmony_ci int nodeNum = 0; 10490704ebd2Sopenharmony_ci NodeBasicInfo* nodeInfo = NULL; 10500704ebd2Sopenharmony_ci int ret = GetAllNodeDeviceInfo(DEF_PKG_NAME, &nodeInfo, &nodeNum); 10510704ebd2Sopenharmony_ci LOG("[check]get node number is:%d, ret:%d", nodeNum, ret); 10520704ebd2Sopenharmony_ci if (nodeInfo != NULL && nodeNum > 0) { 10530704ebd2Sopenharmony_ci LOG("[check]get netid is:%s", nodeInfo->networkId); 10540704ebd2Sopenharmony_ci if (isSetNetId == BOOL_TRUE) { 10550704ebd2Sopenharmony_ci (void)strncpy_s(g_networkId, NETWORK_ID_BUF_LEN, nodeInfo->networkId, NETWORK_ID_BUF_LEN); 10560704ebd2Sopenharmony_ci } 10570704ebd2Sopenharmony_ci FreeNodeInfo(nodeInfo); 10580704ebd2Sopenharmony_ci return SOFTBUS_OK; 10590704ebd2Sopenharmony_ci } else { 10600704ebd2Sopenharmony_ci LOG("[check]get nodeInfo is null"); 10610704ebd2Sopenharmony_ci return SOFTBUS_ERR; 10620704ebd2Sopenharmony_ci } 10630704ebd2Sopenharmony_ci} 10640704ebd2Sopenharmony_ci 10650704ebd2Sopenharmony_ciISessionListener* GetSessionListenser4Data(void) 10660704ebd2Sopenharmony_ci{ 10670704ebd2Sopenharmony_ci return g_sessionlistener4Data; 10680704ebd2Sopenharmony_ci} 10690704ebd2Sopenharmony_ci 10700704ebd2Sopenharmony_ciISessionListener* GetSessionListenser4Ctl(void) 10710704ebd2Sopenharmony_ci{ 10720704ebd2Sopenharmony_ci return g_sessionlistener4Ctl; 10730704ebd2Sopenharmony_ci} 10740704ebd2Sopenharmony_ci 10750704ebd2Sopenharmony_ciISessionListener* GetSessionListenser4Proxy(void) 10760704ebd2Sopenharmony_ci{ 10770704ebd2Sopenharmony_ci return g_sessionlistener4Proxy; 10780704ebd2Sopenharmony_ci} 10790704ebd2Sopenharmony_ci 10800704ebd2Sopenharmony_ciISessionListener* GetSessionListenser4Stream(void) 10810704ebd2Sopenharmony_ci{ 10820704ebd2Sopenharmony_ci return g_sessionlistener4Stream; 10830704ebd2Sopenharmony_ci} 10840704ebd2Sopenharmony_ci 10850704ebd2Sopenharmony_ciIFileSendListener* GetSendFileListener(void) 10860704ebd2Sopenharmony_ci{ 10870704ebd2Sopenharmony_ci return g_fileSendListener; 10880704ebd2Sopenharmony_ci} 10890704ebd2Sopenharmony_ci 10900704ebd2Sopenharmony_ciIFileReceiveListener* GetRecvFileListener(void) 10910704ebd2Sopenharmony_ci{ 10920704ebd2Sopenharmony_ci return g_fileRecvListener; 10930704ebd2Sopenharmony_ci} 10940704ebd2Sopenharmony_ci 10950704ebd2Sopenharmony_ciSessionAttribute* GetSessionAttr4Data(void) 10960704ebd2Sopenharmony_ci{ 10970704ebd2Sopenharmony_ci return g_sessionAttr4Data; 10980704ebd2Sopenharmony_ci} 10990704ebd2Sopenharmony_ci 11000704ebd2Sopenharmony_ciSessionAttribute* GetSessionAttr4DataP2p(void) 11010704ebd2Sopenharmony_ci{ 11020704ebd2Sopenharmony_ci return g_p2pattribute; 11030704ebd2Sopenharmony_ci} 11040704ebd2Sopenharmony_ci 11050704ebd2Sopenharmony_ciSessionAttribute* GetSessionAttr4ProxyP2p(void) 11060704ebd2Sopenharmony_ci{ 11070704ebd2Sopenharmony_ci return g_p2pattributeProxy; 11080704ebd2Sopenharmony_ci} 11090704ebd2Sopenharmony_ciSessionAttribute* GetSessionAttr4Ctl(void) 11100704ebd2Sopenharmony_ci{ 11110704ebd2Sopenharmony_ci return g_sessionAttr4Ctl; 11120704ebd2Sopenharmony_ci} 11130704ebd2Sopenharmony_ci 11140704ebd2Sopenharmony_ciSessionAttribute* GetSessionAttr4Proxy(void) 11150704ebd2Sopenharmony_ci{ 11160704ebd2Sopenharmony_ci return g_sessionAttr4Proxy; 11170704ebd2Sopenharmony_ci} 11180704ebd2Sopenharmony_ci 11190704ebd2Sopenharmony_civoid SetCurrentSessionId4Data(int sessionId) 11200704ebd2Sopenharmony_ci{ 11210704ebd2Sopenharmony_ci g_currentSessionId4Data = sessionId; 11220704ebd2Sopenharmony_ci} 11230704ebd2Sopenharmony_ci 11240704ebd2Sopenharmony_civoid SetCurrentSessionId4Ctl(int sessionId) 11250704ebd2Sopenharmony_ci{ 11260704ebd2Sopenharmony_ci g_currentSessionId4Ctl = sessionId; 11270704ebd2Sopenharmony_ci} 11280704ebd2Sopenharmony_ci 11290704ebd2Sopenharmony_civoid SetCurrentSessionId4Proxy(int sessionId) 11300704ebd2Sopenharmony_ci{ 11310704ebd2Sopenharmony_ci g_currentSessionId4Proxy = sessionId; 11320704ebd2Sopenharmony_ci} 11330704ebd2Sopenharmony_ci 11340704ebd2Sopenharmony_ciint GetCurrentSessionId4Data(void) 11350704ebd2Sopenharmony_ci{ 11360704ebd2Sopenharmony_ci return g_currentSessionId4Data; 11370704ebd2Sopenharmony_ci} 11380704ebd2Sopenharmony_ci 11390704ebd2Sopenharmony_ciint GetCurrentSessionId4Ctl(void) 11400704ebd2Sopenharmony_ci{ 11410704ebd2Sopenharmony_ci return g_currentSessionId4Ctl; 11420704ebd2Sopenharmony_ci} 11430704ebd2Sopenharmony_ci 11440704ebd2Sopenharmony_ciint GetCurrentSessionId4Proxy(void) 11450704ebd2Sopenharmony_ci{ 11460704ebd2Sopenharmony_ci return g_currentSessionId4Proxy; 11470704ebd2Sopenharmony_ci} 11480704ebd2Sopenharmony_ci 11490704ebd2Sopenharmony_ciint GetOpenSessionCount4Proxy(void) 11500704ebd2Sopenharmony_ci{ 11510704ebd2Sopenharmony_ci return g_sessionOpenCount4Proxy; 11520704ebd2Sopenharmony_ci} 11530704ebd2Sopenharmony_ci 11540704ebd2Sopenharmony_civoid TestSetUp(void) 11550704ebd2Sopenharmony_ci{ 11560704ebd2Sopenharmony_ci g_defNodeStateCallback.events = EVENT_NODE_STATE_MASK; 11570704ebd2Sopenharmony_ci g_defNodeStateCallback.onNodeOnline = OnDefNodeOnline; 11580704ebd2Sopenharmony_ci g_defNodeStateCallback.onNodeOffline = OnDefNodeOffline; 11590704ebd2Sopenharmony_ci g_defNodeStateCallback.onNodeBasicInfoChanged = OnDefNodeBasicInfoChanged; 11600704ebd2Sopenharmony_ci g_defNodeStateCallback.onNodeStatusChanged = onDefNodeStatusChanged; 11610704ebd2Sopenharmony_ci if (g_sessionlistener4Data == NULL) { 11620704ebd2Sopenharmony_ci g_sessionlistener4Data = (ISessionListener*)calloc(1, sizeof(ISessionListener)); 11630704ebd2Sopenharmony_ci g_sessionlistener4Data->OnSessionOpened = DataSessionOpened; 11640704ebd2Sopenharmony_ci g_sessionlistener4Data->OnSessionClosed = DataSessionClosed; 11650704ebd2Sopenharmony_ci g_sessionlistener4Data->OnMessageReceived = DataMessageReceived; 11660704ebd2Sopenharmony_ci g_sessionlistener4Data->OnBytesReceived = DataBytesReceived; 11670704ebd2Sopenharmony_ci } 11680704ebd2Sopenharmony_ci if (g_sessionlistener4Ctl == NULL) { 11690704ebd2Sopenharmony_ci g_sessionlistener4Ctl = (ISessionListener*)calloc(1, sizeof(ISessionListener)); 11700704ebd2Sopenharmony_ci g_sessionlistener4Ctl->OnSessionOpened = ControlSessionOpened; 11710704ebd2Sopenharmony_ci g_sessionlistener4Ctl->OnSessionClosed = ControlSessionClosed; 11720704ebd2Sopenharmony_ci g_sessionlistener4Ctl->OnMessageReceived = ControlMessageReceived; 11730704ebd2Sopenharmony_ci g_sessionlistener4Ctl->OnBytesReceived = ControlBytesReceived; 11740704ebd2Sopenharmony_ci } 11750704ebd2Sopenharmony_ci if (g_sessionlistener4Pass == NULL) { 11760704ebd2Sopenharmony_ci g_sessionlistener4Pass = (ISessionListener*)calloc(1, sizeof(ISessionListener)); 11770704ebd2Sopenharmony_ci g_sessionlistener4Pass->OnSessionOpened = PassiveSessionOpened; 11780704ebd2Sopenharmony_ci g_sessionlistener4Pass->OnSessionClosed = PassiveSessionClosed; 11790704ebd2Sopenharmony_ci g_sessionlistener4Pass->OnMessageReceived = PassiveMessageReceived; 11800704ebd2Sopenharmony_ci g_sessionlistener4Pass->OnBytesReceived = PassiveBytesReceived; 11810704ebd2Sopenharmony_ci } 11820704ebd2Sopenharmony_ci if (g_sessionlistener4Perf == NULL) { 11830704ebd2Sopenharmony_ci g_sessionlistener4Perf = (ISessionListener*)calloc(1, sizeof(ISessionListener)); 11840704ebd2Sopenharmony_ci g_sessionlistener4Perf->OnSessionOpened = PerfSessionOpened; 11850704ebd2Sopenharmony_ci g_sessionlistener4Perf->OnSessionClosed = PerfSessionClosed; 11860704ebd2Sopenharmony_ci g_sessionlistener4Perf->OnMessageReceived = PerfMessageReceived; 11870704ebd2Sopenharmony_ci g_sessionlistener4Perf->OnBytesReceived = PerfBytesReceived; 11880704ebd2Sopenharmony_ci } 11890704ebd2Sopenharmony_ci if (g_sessionlistener4Proxy == NULL) { 11900704ebd2Sopenharmony_ci g_sessionlistener4Proxy = (ISessionListener*)calloc(1, sizeof(ISessionListener)); 11910704ebd2Sopenharmony_ci g_sessionlistener4Proxy->OnSessionOpened = ProxySessionOpened; 11920704ebd2Sopenharmony_ci g_sessionlistener4Proxy->OnSessionClosed = ProxySessionClosed; 11930704ebd2Sopenharmony_ci g_sessionlistener4Proxy->OnMessageReceived = ProxyMessageReceived; 11940704ebd2Sopenharmony_ci g_sessionlistener4Proxy->OnBytesReceived = ProxyBytesReceived; 11950704ebd2Sopenharmony_ci } 11960704ebd2Sopenharmony_ci if (g_sessionlistener4Stream == NULL) { 11970704ebd2Sopenharmony_ci g_sessionlistener4Stream = (ISessionListener*)calloc(1, sizeof(ISessionListener)); 11980704ebd2Sopenharmony_ci g_sessionlistener4Stream->OnSessionOpened = StreamSessionOpened; 11990704ebd2Sopenharmony_ci g_sessionlistener4Stream->OnSessionClosed = StreamSessionClosed; 12000704ebd2Sopenharmony_ci g_sessionlistener4Stream->OnStreamReceived = StreamReceived; 12010704ebd2Sopenharmony_ci } 12020704ebd2Sopenharmony_ci if (g_fileSendListener == NULL) { 12030704ebd2Sopenharmony_ci g_fileSendListener = (IFileSendListener*)calloc(1, sizeof(IFileSendListener)); 12040704ebd2Sopenharmony_ci g_fileSendListener->OnSendFileProcess = OnSendFileProcess; 12050704ebd2Sopenharmony_ci g_fileSendListener->OnSendFileFinished = OnSendFileFinished; 12060704ebd2Sopenharmony_ci g_fileSendListener->OnFileTransError = OnSendFileTransError; 12070704ebd2Sopenharmony_ci }; 12080704ebd2Sopenharmony_ci if (g_fileRecvListener == NULL) { 12090704ebd2Sopenharmony_ci g_fileRecvListener = (IFileReceiveListener*)calloc(1, sizeof(IFileReceiveListener)); 12100704ebd2Sopenharmony_ci g_fileRecvListener->OnReceiveFileStarted = OnReceiveFileStarted; 12110704ebd2Sopenharmony_ci g_fileRecvListener->OnReceiveFileProcess = OnReceiveFileProcess; 12120704ebd2Sopenharmony_ci g_fileRecvListener->OnReceiveFileFinished = OnReceiveFileFinished; 12130704ebd2Sopenharmony_ci g_fileRecvListener->OnFileTransError = OnRecvFileTransError; 12140704ebd2Sopenharmony_ci } 12150704ebd2Sopenharmony_ci if (g_sessionAttr4Data == NULL) { 12160704ebd2Sopenharmony_ci g_sessionAttr4Data = (SessionAttribute*)calloc(1, sizeof(SessionAttribute)); 12170704ebd2Sopenharmony_ci g_sessionAttr4Data->dataType = TYPE_BYTES; 12180704ebd2Sopenharmony_ci } 12190704ebd2Sopenharmony_ci if (g_sessionAttr4Ctl == NULL) { 12200704ebd2Sopenharmony_ci g_sessionAttr4Ctl = (SessionAttribute*)calloc(1, sizeof(SessionAttribute)); 12210704ebd2Sopenharmony_ci g_sessionAttr4Ctl->dataType = TYPE_BYTES; 12220704ebd2Sopenharmony_ci } 12230704ebd2Sopenharmony_ci if (g_sessionAttr4Pass == NULL) { 12240704ebd2Sopenharmony_ci g_sessionAttr4Pass = (SessionAttribute*)calloc(1, sizeof(SessionAttribute)); 12250704ebd2Sopenharmony_ci g_sessionAttr4Pass->dataType = TYPE_BYTES; 12260704ebd2Sopenharmony_ci } 12270704ebd2Sopenharmony_ci if (g_sessionAttr4Perf == NULL) { 12280704ebd2Sopenharmony_ci g_sessionAttr4Perf = (SessionAttribute*)calloc(1, sizeof(SessionAttribute)); 12290704ebd2Sopenharmony_ci g_sessionAttr4Perf->dataType = TYPE_BYTES; 12300704ebd2Sopenharmony_ci } 12310704ebd2Sopenharmony_ci if (g_sessionAttr4Proxy == NULL) { 12320704ebd2Sopenharmony_ci g_sessionAttr4Proxy = (SessionAttribute*)calloc(1, sizeof(SessionAttribute)); 12330704ebd2Sopenharmony_ci g_sessionAttr4Proxy->dataType = TYPE_MESSAGE; 12340704ebd2Sopenharmony_ci } 12350704ebd2Sopenharmony_ci if (g_p2pattribute == NULL) { 12360704ebd2Sopenharmony_ci g_p2pattribute = (SessionAttribute*)calloc(1, sizeof(SessionAttribute)); 12370704ebd2Sopenharmony_ci g_p2pattribute->dataType = TYPE_BYTES; 12380704ebd2Sopenharmony_ci g_p2pattribute->linkTypeNum = 1; 12390704ebd2Sopenharmony_ci g_p2pattribute->linkType[0] = LINK_TYPE_WIFI_P2P; 12400704ebd2Sopenharmony_ci } 12410704ebd2Sopenharmony_ci if (g_p2pattributeProxy == NULL) { 12420704ebd2Sopenharmony_ci g_p2pattributeProxy = (SessionAttribute*)calloc(1, sizeof(SessionAttribute)); 12430704ebd2Sopenharmony_ci g_p2pattributeProxy->dataType = TYPE_MESSAGE; 12440704ebd2Sopenharmony_ci g_p2pattributeProxy->linkTypeNum = 1; 12450704ebd2Sopenharmony_ci g_p2pattributeProxy->linkType[0] = LINK_TYPE_WIFI_P2P; 12460704ebd2Sopenharmony_ci } 12470704ebd2Sopenharmony_ci if (g_barrier == NULL) { 12480704ebd2Sopenharmony_ci g_barrier = (pthread_barrier_t*)calloc(1, sizeof(pthread_barrier_t)); 12490704ebd2Sopenharmony_ci } 12500704ebd2Sopenharmony_ci if (g_sId4Task2 == NULL) { 12510704ebd2Sopenharmony_ci g_sId4Task2 = (int*)malloc(sizeof(int) * DEF_SEND_DATA_SID_COUNT); 12520704ebd2Sopenharmony_ci } 12530704ebd2Sopenharmony_ci if (g_sId4Task3 == NULL) { 12540704ebd2Sopenharmony_ci g_sId4Task3 = (int*)malloc(sizeof(int) * DEF_SEND_DATA_SID_COUNT); 12550704ebd2Sopenharmony_ci } 12560704ebd2Sopenharmony_ci} 12570704ebd2Sopenharmony_ci 12580704ebd2Sopenharmony_civoid TestTearDown(void) 12590704ebd2Sopenharmony_ci{ 12600704ebd2Sopenharmony_ci if (g_sessionlistener4Data != NULL) { 12610704ebd2Sopenharmony_ci free(g_sessionlistener4Data); 12620704ebd2Sopenharmony_ci g_sessionlistener4Data = NULL; 12630704ebd2Sopenharmony_ci } 12640704ebd2Sopenharmony_ci if (g_sessionlistener4Ctl != NULL) { 12650704ebd2Sopenharmony_ci free(g_sessionlistener4Ctl); 12660704ebd2Sopenharmony_ci g_sessionlistener4Ctl = NULL; 12670704ebd2Sopenharmony_ci } 12680704ebd2Sopenharmony_ci if (g_sessionlistener4Pass != NULL) { 12690704ebd2Sopenharmony_ci free(g_sessionlistener4Pass); 12700704ebd2Sopenharmony_ci g_sessionlistener4Pass = NULL; 12710704ebd2Sopenharmony_ci } 12720704ebd2Sopenharmony_ci if (g_sessionlistener4Perf != NULL) { 12730704ebd2Sopenharmony_ci free(g_sessionlistener4Perf); 12740704ebd2Sopenharmony_ci g_sessionlistener4Perf = NULL; 12750704ebd2Sopenharmony_ci } 12760704ebd2Sopenharmony_ci if (g_sessionlistener4Proxy != NULL) { 12770704ebd2Sopenharmony_ci free(g_sessionlistener4Proxy); 12780704ebd2Sopenharmony_ci g_sessionlistener4Proxy = NULL; 12790704ebd2Sopenharmony_ci } 12800704ebd2Sopenharmony_ci if (g_sessionlistener4Stream != NULL) { 12810704ebd2Sopenharmony_ci free(g_sessionlistener4Stream); 12820704ebd2Sopenharmony_ci g_sessionlistener4Stream = NULL; 12830704ebd2Sopenharmony_ci } 12840704ebd2Sopenharmony_ci if (g_fileRecvListener != NULL) { 12850704ebd2Sopenharmony_ci free(g_fileRecvListener); 12860704ebd2Sopenharmony_ci g_fileRecvListener = NULL; 12870704ebd2Sopenharmony_ci } 12880704ebd2Sopenharmony_ci if (g_fileSendListener != NULL) { 12890704ebd2Sopenharmony_ci free(g_fileSendListener); 12900704ebd2Sopenharmony_ci g_fileSendListener = NULL; 12910704ebd2Sopenharmony_ci } 12920704ebd2Sopenharmony_ci if (g_sessionAttr4Data != NULL) { 12930704ebd2Sopenharmony_ci free(g_sessionAttr4Data); 12940704ebd2Sopenharmony_ci g_sessionAttr4Data = NULL; 12950704ebd2Sopenharmony_ci } 12960704ebd2Sopenharmony_ci if (g_sessionAttr4Ctl != NULL) { 12970704ebd2Sopenharmony_ci free(g_sessionAttr4Ctl); 12980704ebd2Sopenharmony_ci g_sessionAttr4Ctl = NULL; 12990704ebd2Sopenharmony_ci } 13000704ebd2Sopenharmony_ci if (g_sessionAttr4Pass != NULL) { 13010704ebd2Sopenharmony_ci free(g_sessionAttr4Pass); 13020704ebd2Sopenharmony_ci g_sessionAttr4Pass = NULL; 13030704ebd2Sopenharmony_ci } 13040704ebd2Sopenharmony_ci if (g_sessionAttr4Perf != NULL) { 13050704ebd2Sopenharmony_ci free(g_sessionAttr4Perf); 13060704ebd2Sopenharmony_ci g_sessionAttr4Perf = NULL; 13070704ebd2Sopenharmony_ci } 13080704ebd2Sopenharmony_ci if (g_sessionAttr4Proxy != NULL) { 13090704ebd2Sopenharmony_ci free(g_sessionAttr4Proxy); 13100704ebd2Sopenharmony_ci g_sessionAttr4Proxy = NULL; 13110704ebd2Sopenharmony_ci } 13120704ebd2Sopenharmony_ci if (g_p2pattribute != NULL) { 13130704ebd2Sopenharmony_ci free(g_p2pattribute); 13140704ebd2Sopenharmony_ci g_p2pattribute = NULL; 13150704ebd2Sopenharmony_ci } 13160704ebd2Sopenharmony_ci if (g_p2pattributeProxy != NULL) { 13170704ebd2Sopenharmony_ci free(g_p2pattributeProxy); 13180704ebd2Sopenharmony_ci g_p2pattributeProxy = NULL; 13190704ebd2Sopenharmony_ci } 13200704ebd2Sopenharmony_ci if (g_barrier != NULL) { 13210704ebd2Sopenharmony_ci free(g_barrier); 13220704ebd2Sopenharmony_ci g_barrier = NULL; 13230704ebd2Sopenharmony_ci } 13240704ebd2Sopenharmony_ci if (g_sId4Task2 != NULL) { 13250704ebd2Sopenharmony_ci free(g_sId4Task2); 13260704ebd2Sopenharmony_ci g_sId4Task2 = NULL; 13270704ebd2Sopenharmony_ci } 13280704ebd2Sopenharmony_ci if (g_sId4Task3 != NULL) { 13290704ebd2Sopenharmony_ci free(g_sId4Task3); 13300704ebd2Sopenharmony_ci g_sId4Task3 = NULL; 13310704ebd2Sopenharmony_ci } 13320704ebd2Sopenharmony_ci} 13330704ebd2Sopenharmony_ci 13340704ebd2Sopenharmony_civoid AddPermission(void) 13350704ebd2Sopenharmony_ci{ 13360704ebd2Sopenharmony_ci uint64_t tokenId; 13370704ebd2Sopenharmony_ci const char *perms[2]; 13380704ebd2Sopenharmony_ci perms[0] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER; 13390704ebd2Sopenharmony_ci perms[1] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC; 13400704ebd2Sopenharmony_ci NativeTokenInfoParams infoTnstance = { 13410704ebd2Sopenharmony_ci .dcapsNum = 0, 13420704ebd2Sopenharmony_ci .permsNum = 2, 13430704ebd2Sopenharmony_ci .aclsNum = 0, 13440704ebd2Sopenharmony_ci .dcaps = NULL, 13450704ebd2Sopenharmony_ci .perms = perms, 13460704ebd2Sopenharmony_ci .acls = NULL, 13470704ebd2Sopenharmony_ci .processName = "dsoftbus_test_service", 13480704ebd2Sopenharmony_ci .aplStr = "system_core", 13490704ebd2Sopenharmony_ci }; 13500704ebd2Sopenharmony_ci tokenId = GetAccessTokenId(&infoTnstance); 13510704ebd2Sopenharmony_ci SetSelfTokenID(tokenId); 13520704ebd2Sopenharmony_ci}