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