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_APP_INFO_H
17 #define SOFTBUS_APP_INFO_H
18 
19 #include "session.h"
20 #include "softbus_def.h"
21 #include "softbus_protocol_def.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif // __cplusplus
26 
27 #define APP_INFO_FILE_FEATURES_SUPPORT 1
28 #define APP_INFO_FILE_FEATURES_NO_SUPPORT 0
29 
30 #define APP_INFO_ALGORITHM_AES_GCM_256 0
31 #define APP_INFO_ALGORITHM_CHACHA 1
32 
33 #define APP_INFO_UDP_FILE_PROTOCOL 0x5a
34 
35 #define TRANS_FLAG_HAS_CHANNEL_AUTH 0x02L
36 
37 #define MAX_FAST_DATA_LEN (4 * 1024)
38 #define BASE64_FAST_DATA_LEN 5558
39 #define TOKENID_NOT_SET 0
40 
41 typedef enum {
42     API_UNKNOWN = 0,
43     API_V1 = 1,
44     API_V2 = 2,
45 } ApiVersion;
46 
47 typedef enum {
48     APP_TYPE_NOT_CARE,
49     APP_TYPE_NORMAL,
50     APP_TYPE_AUTH,
51     APP_TYPE_INNER
52 } AppType;
53 
54 typedef enum {
55     TRANS_CONN_ALL = 0,
56     TRANS_CONN_P2P = 1,
57     TRANS_CONN_HML = 2,
58 } TransConnType;
59 
60 typedef enum {
61     ROUTE_TYPE_ALL = 0,
62     WIFI_STA = 1,
63     WIFI_P2P = 2,
64     BT_BR = 3,
65     BT_BLE = 4,
66     WIFI_P2P_REUSE = 6,
67 } RouteType;
68 
69 typedef enum {
70     UDP_CONN_TYPE_INVALID = -1,
71     UDP_CONN_TYPE_WIFI = 0,
72     UDP_CONN_TYPE_P2P = 1,
73 } UdpConnType;
74 
75 typedef enum {
76     TYPE_INVALID_CHANNEL = -1,
77     TYPE_UDP_CHANNEL_OPEN = 1,
78     TYPE_UDP_CHANNEL_CLOSE = 2,
79 } UdpChannelOptType;
80 
81 typedef struct {
82     ApiVersion apiVersion;
83     char deviceId[DEVICE_ID_SIZE_MAX];
84     char pkgName[PKG_NAME_SIZE_MAX];
85     char sessionName[SESSION_NAME_SIZE_MAX];
86     int uid;
87     int pid;
88     char authState[AUTH_STATE_SIZE_MAX];
89     char addr[IP_LEN];
90     int port;
91     int64_t channelId;
92     uint32_t dataConfig;
93 } AppInfoData;
94 
95 typedef struct {
96     char groupId[GROUP_ID_SIZE_MAX];
97     char sessionKey[SESSION_KEY_LENGTH];
98     char reqId[REQ_ID_SIZE_MAX];
99     char peerNetWorkId[DEVICE_ID_SIZE_MAX];
100     char peerUdid[DEVICE_ID_SIZE_MAX];
101     char peerVersion[DEVICE_VERSION_SIZE_MAX];
102     RouteType routeType;
103     BusinessType businessType;
104     StreamType streamType;
105     UdpConnType udpConnType;
106     UdpChannelOptType udpChannelOptType;
107     int fd;
108     AppType appType;
109     AppInfoData myData;
110     AppInfoData peerData;
111     ProtocolType protocol;
112     int32_t encrypt;
113     int32_t algorithm;
114     int32_t crc;
115     int32_t fileProtocol;
116     int32_t autoCloseTime;
117     int myHandleId;
118     int peerHandleId;
119     int32_t transFlag;
120     int64_t authSeq;
121     int32_t linkType;
122     int32_t connectType;
123     int32_t channelType;
124     int32_t errorCode;
125     int64_t timeStart;
126     int64_t connectedStart;
127     const uint8_t *fastTransData;
128     uint16_t fastTransDataSize;
129     uint32_t callingTokenId; // for transmission access control
130     bool isClient;
131     char tokenName[PKG_NAME_SIZE_MAX];
132     int32_t osType;
133 } AppInfo;
134 
135 #ifdef __cplusplus
136 }
137 #endif // __cplusplus
138 #endif // SOFTBUS_APP_INFO_H