1 /* 2 * Copyright (c) 2021-2025 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_PROXYCHANNEL_MESSAGE_STRUCT_H 17 #define SOFTBUS_PROXYCHANNEL_MESSAGE_STRUCT_H 18 #include "stdint.h" 19 #include "common_list.h" 20 #include "softbus_app_info.h" 21 #include "softbus_conn_interface_struct.h" 22 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif 27 #endif 28 29 typedef enum { 30 PROXYCHANNEL_MSG_TYPE_NORMAL, 31 PROXYCHANNEL_MSG_TYPE_HANDSHAKE, 32 PROXYCHANNEL_MSG_TYPE_HANDSHAKE_ACK, 33 PROXYCHANNEL_MSG_TYPE_RESET, 34 PROXYCHANNEL_MSG_TYPE_KEEPALIVE, 35 PROXYCHANNEL_MSG_TYPE_KEEPALIVE_ACK, 36 PROXYCHANNEL_MSG_TYPE_HANDSHAKE_AUTH, 37 PROXYCHANNEL_MSG_TYPE_PAGING_HANDSHAKE = 10, 38 PROXYCHANNEL_MSG_TYPE_PAGING_HANDSHAKE_ACK, 39 PROXYCHANNEL_MSG_TYPE_PAGING_BADKEY, 40 PROXYCHANNEL_MSG_TYPE_PAGING_RESET, 41 PROXYCHANNEL_MSG_TYPE_D2D, 42 PROXYCHANNEL_MSG_TYPE_MAX 43 } MsgType; 44 45 #define JSON_KEY_TYPE "TYPE" 46 #define JSON_KEY_IDENTITY "IDENTITY" 47 #define JSON_KEY_DEVICE_ID "DEVICE_ID" 48 #define JSON_KEY_MTU_SIZE "MTU_SIZE" 49 #define JSON_KEY_DST_BUS_NAME "DST_BUS_NAME" 50 #define JSON_KEY_SRC_BUS_NAME "SRC_BUS_NAME" 51 #define JSON_KEY_HAS_PRIORITY "HAS_PRIORITY" 52 #define JSON_KEY_UID "UID" 53 #define JSON_KEY_PID "PID" 54 #define JSON_KEY_GROUP_ID "GROUP_ID" 55 #define JSON_KEY_PKG_NAME "PKG_NAME" 56 #define JSON_KEY_SESSION_KEY "SESSION_KEY" 57 #define JSON_KEY_REQUEST_ID "REQUEST_ID" 58 #define JSON_KEY_ENCRYPT "ENCRYPT" 59 #define JSON_KEY_ALGORITHM "ALGORITHM" 60 #define JSON_KEY_CRC "CRC" 61 #define JSON_KEY_BUSINESS_TYPE "BUSINESS_TYPE" 62 #define JSON_KEY_TRANS_FLAGS "TRANS_FLAGS" 63 #define JSON_KEY_MIGRATE_OPTION "MIGRATE_OPTION" 64 #define JSON_KEY_MY_HANDLE_ID "MY_HANDLE_ID" 65 #define JSON_KEY_PEER_HANDLE_ID "PEER_HANDLE_ID" 66 #define JSON_KEY_AUTH_SEQ "AUTH_SEQ" 67 #define JSON_KEY_ROUTE_TYPE "ROUTE_TYPE" 68 #define JSON_KEY_FIRST_DATA "FIRST_DATA" 69 #define JSON_KEY_FIRST_DATA_SIZE "FIRST_DATA_SIZE" 70 #define JSON_KEY_CALLING_TOKEN_ID "CALLING_TOKEN_ID" 71 #define JSON_KEY_ACCOUNT_ID "ACCOUNT_ID" 72 #define JSON_KEY_USER_ID "USER_ID" 73 #define JSON_KEY_SOURCE_ACL_TOKEN_ID "SOURCE_ACL_TOKEN_ID" 74 #define JSON_KEY_SOURCE_ACL_EXTRA_INFO "SOURCE_ACL_EXTRA_INFO" 75 #define JSON_KEY_SINK_ACL_ACCOUNT_ID "SINK_ACL_ACCOUNT_ID" 76 #define JSON_KEY_SINK_ACL_USER_ID "SINK_ACL_USER_ID" 77 #define JSON_KEY_SINK_ACL_TOKEN_ID "SINK_ACL_TOKEN_ID" 78 #define TRANS_CAPABILITY "TRANS_CAPABILITY" 79 #define JSON_KEY_CALLEE_ACCOUNT_ID "CALLEE_ACCOUNT_ID" 80 #define JSON_KEY_CALLER_ACCOUNT_ID "CALLER_ACCOUNT_ID" 81 #define JSON_KEY_PAGING_NONCE "PAGING_NONCE" 82 #define JSON_KEY_PAGING_EXT_DATA "PAGING_EXT_DATA" 83 #define JSON_KEY_PAGING_DATA_LEN "PAGING_DATA_LEN" 84 #define JSON_KEY_PAGING_SINK_CHANNEL_ID "PAGING_SINK_CHANNEL_ID" 85 #define JSON_KEY_PAGING_BUSINESS_FLAG "PAGING_BUSINESS_FLAG" 86 #define JSON_KEY_DEVICETYPE_ID "DEVICETYPE_ID" 87 88 typedef struct { 89 uint8_t type; // MsgType 90 uint8_t cipher; 91 int16_t myId; 92 int16_t peerId; 93 int16_t reserved; 94 } ProxyMessageHead; 95 96 typedef struct { 97 uint8_t type; // MsgType 98 int16_t myId; 99 int16_t peerId; 100 } ProxyMessageShortHead; 101 102 typedef struct { 103 uint8_t type; // MsgType 104 int16_t channelId; 105 } PagingMessageHead; 106 107 typedef struct { 108 bool isHandshake; 109 uint8_t authKey[SESSION_KEY_LENGTH]; 110 PagingMessageHead msgHead; 111 } PagingProxyMessage; 112 113 typedef struct { 114 int32_t dataLen; 115 char *data; 116 uint32_t connId; 117 int32_t keyIndex; 118 ProxyMessageHead msgHead; 119 AuthHandle authHandle; /* for cipher */ 120 } ProxyMessage; 121 122 #define VERSION 1 123 #define PROXY_CHANNEL_HEAD_LEN 8 124 #define PROXY_CHANNEL_D2D_HEAD_LEN 6 125 #define PROXY_CHANNEL_MESSAGE_HEAD_LEN 7 126 #define PROXY_CHANNEL_BYTES_HEAD_LEN 6 127 #define PAGING_CHANNEL_HEAD_LEN 4 128 #define PAGING_CHANNEL_HANDSHAKE_HEAD_LEN 14 129 #define VERSION_SHIFT 4 130 #define FOUR_BIT_MASK 0xF 131 #define ENCRYPTED 0x1 132 #define AUTH_SERVER_SIDE 0x2 133 #define USE_BLE_CIPHER 0x4 134 #define BAD_CIPHER 0x8 135 #define CS_MODE 0x10 136 #define AUTH_SINGLE_CIPHER 0x28 // To be compatible with LegacyOs, use 0x28 which & BAD_CIPHER also BAD_CIPHER 137 #define PROXY_BYTES_LENGTH_MAX (4 * 1024 * 1024) 138 #define PROXY_MESSAGE_LENGTH_MAX 1024 139 140 #define IDENTITY_LEN 32 141 typedef enum { 142 PROXY_CHANNEL_STATUS_PYH_CONNECTED, 143 PROXY_CHANNEL_STATUS_PYH_CONNECTING, 144 PROXY_CHANNEL_STATUS_HANDSHAKEING, 145 PROXY_CHANNEL_STATUS_KEEPLIVEING, 146 PROXY_CHANNEL_STATUS_TIMEOUT, 147 PROXY_CHANNEL_STATUS_HANDSHAKE_TIMEOUT, 148 PROXY_CHANNEL_STATUS_CONNECTING_TIMEOUT, 149 PROXY_CHANNEL_STATUS_COMPLETED 150 } ProxyChannelStatus; 151 152 typedef enum { 153 PAGING_WAIT_LISTEN_DONE, 154 PAGING_WAIT_LISTEN_LOAD_SA_FAIL 155 } PagingWaitListenStatus; 156 157 #define BASE64KEY 45 // encrypt SessionKey len 158 typedef struct { 159 char sessionKeyBase64[BASE64KEY]; 160 size_t len; 161 } SessionKeyBase64; 162 163 typedef struct { 164 bool deviceTypeIsWinpc; 165 char identity[IDENTITY_LEN + 1]; 166 int8_t isServer; 167 bool isD2D; 168 bool retried; 169 int8_t status; 170 uint16_t timeout; 171 int16_t myId; 172 int16_t peerId; 173 ConnectType type; 174 BleProtocolType bleProtocolType; 175 SleProtocolType sleProtocolType; 176 uint32_t connId; 177 int32_t channelId; 178 int32_t reqId; 179 uint32_t authReqId; 180 int32_t seq; 181 ListNode node; 182 AuthHandle authHandle; /* for cipher */ 183 AppInfo appInfo; 184 } ProxyChannelInfo; 185 186 typedef struct { 187 int32_t magicNumber; 188 int32_t seq; 189 int32_t flags; 190 int32_t dataLen; 191 } PacketFastHead; 192 193 typedef struct { 194 int32_t priority; 195 int32_t sliceNum; 196 int32_t sliceSeq; 197 int32_t reserved; 198 } SliceFastHead; 199 200 typedef struct { 201 int seq; 202 int packetFlag; 203 int shouldAck; 204 } SessionHead; 205 206 #ifdef __cplusplus 207 #if __cplusplus 208 } 209 #endif /* __cplusplus */ 210 #endif /* __cplusplus */ 211 212 #endif 213