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 47 #ifdef __cplusplus 48 extern "C" { 49 #endif // __cplusplus 50 51 typedef enum { 52 CODE_OPEN_CHANNEL = 1, 53 } MessageCode; 54 55 #define FAST_DATA_HEAD_SIZE 16 56 #define FAST_BYTE_TOS 0x60 57 #define FAST_MESSAGE_TOS 0xC0 58 59 typedef struct { 60 uint32_t magicNumber; 61 int32_t seq; 62 uint32_t flags; 63 uint32_t dataLen; 64 } __attribute__((packed)) TcpFastDataPacketHead; 65 66 #define FAST_TDC_EXT_DATA_SIZE (OVERHEAD_LEN + sizeof(TcpFastDataPacketHead)) 67 68 enum { 69 FLAG_BYTES = 0, 70 FLAG_MESSAGE = 2, 71 }; 72 73 char *PackRequest(const AppInfo *appInfo); 74 75 int32_t UnpackRequest(const cJSON *msg, AppInfo *appInfo); 76 77 char *PackReply(const AppInfo *appInfo); 78 79 int32_t UnpackReply(const cJSON *msg, AppInfo *appInfo, uint16_t *fastDataSize); 80 81 char *PackError(int errCode, const char *errDesc); 82 83 int32_t UnpackReplyErrCode(const cJSON *msg, int32_t *errCode); 84 85 char *TransTdcPackFastData(const AppInfo *appInfo, uint32_t *outLen); 86 87 #ifdef __cplusplus 88 } 89 #endif // __cplusplus 90 #endif // SOFTBUS_MESSAGE_OPEN_CHANNEL 91