1 /* 2 * Copyright (c) 2021-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 SOFTBUS_MESSAGE_OPEN_CHANNEL_H 17 #define SOFTBUS_MESSAGE_OPEN_CHANNEL_H 18 19 #include "cJSON.h" 20 #include "softbus_app_info.h" 21 22 #define CODE "CODE" 23 #define ERR_CODE "ERR_CODE" 24 #define ERR_DESC "ERR_DESC" 25 #define API_VERSION "API_VERSION" 26 #define DEVICE_ID "DEVICE_ID" 27 #define BUS_NAME "BUS_NAME" 28 #define GROUP_ID "GROUP_ID" 29 #define UID "UID" 30 #define PID "PID" 31 #define SESSION_KEY "SESSION_KEY" 32 #define MTU_SIZE "MTU_SIZE" 33 #define PKG_NAME "PKG_NAME" 34 #define CLIENT_BUS_NAME "CLIENT_BUS_NAME" 35 #define AUTH_STATE "AUTH_STATE" 36 #define MSG_ROUTE_TYPE "ROUTE_TYPE" 37 #define BUSINESS_TYPE "BUSINESS_TYPE" 38 #define AUTO_CLOSE_TIME "AUTO_CLOSE_TIME" 39 #define TRANS_FLAGS "TRANS_FLAGS" 40 #define MIGRATE_OPTION "MIGRATE_OPTION" 41 #define MY_HANDLE_ID "MY_HANDLE_ID" 42 #define PEER_HANDLE_ID "PEER_HANDLE_ID" 43 #define FIRST_DATA "FIRST_DATA" 44 #define FIRST_DATA_SIZE "FIRST_DATA_SIZE" 45 #define JSON_KEY_CALLING_TOKEN_ID "CALLING_TOKEN_ID" 46 #define ACCOUNT_ID "ACCOUNT_ID" 47 #define USER_ID "USER_ID" 48 #define TRANS_CAPABILITY "TRANS_CAPABILITY" 49 50 #ifdef __cplusplus 51 extern "C" { 52 #endif // __cplusplus 53 54 typedef enum { 55 CODE_OPEN_CHANNEL = 1, 56 } MessageCode; 57 58 #define FAST_DATA_HEAD_SIZE 16 59 #define FAST_BYTE_TOS 0x60 60 #define FAST_MESSAGE_TOS 0xC0 61 62 typedef struct { 63 uint32_t magicNumber; 64 int32_t seq; 65 uint32_t flags; 66 uint32_t dataLen; 67 } __attribute__((packed)) TcpFastDataPacketHead; 68 69 #define FAST_TDC_EXT_DATA_SIZE (OVERHEAD_LEN + sizeof(TcpFastDataPacketHead)) 70 71 enum { 72 FLAG_BYTES = 0, 73 FLAG_MESSAGE = 2, 74 }; 75 76 char *PackRequest(const AppInfo *appInfo); 77 78 int32_t UnpackRequest(const cJSON *msg, AppInfo *appInfo); 79 80 char *PackReply(const AppInfo *appInfo); 81 82 int32_t UnpackReply(const cJSON *msg, AppInfo *appInfo, uint16_t *fastDataSize); 83 84 char *PackError(int errCode, const char *errDesc); 85 86 int32_t UnpackReplyErrCode(const cJSON *msg, int32_t *errCode); 87 88 char *TransTdcPackFastData(const AppInfo *appInfo, uint32_t *outLen); 89 90 #ifdef __cplusplus 91 } 92 #endif // __cplusplus 93 #endif // SOFTBUS_MESSAGE_OPEN_CHANNEL 94