• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SOFTBUS_DEF_H
16 #define SOFTBUS_DEF_H
17 
18 #include  <pthread.h>
19 #include "common_list.h"
20 #include "softbus_adapter_thread.h"
21 #include "stdint.h"
22 
23 
24 #ifdef __cplusplus
25 #if __cplusplus
26 extern "C" {
27 #endif
28 #endif
29 
30 #ifndef NO_SANITIZE
31 #ifdef __has_attribute
32 #if __has_attribute(no_sanitize)
33 #define NO_SANITIZE(type) __attribute__((no_sanitize(type)))
34 #endif
35 #endif
36 #endif
37 
38 #ifndef NO_SANITIZE
39 #define NO_SANITIZE(type)
40 #endif
41 
42 #define INVALID_SESSION_ID (-1)
43 #define INVALID_CHANNEL_ID (-1)
44 #define INVALID_ROUTE_TYPE (-1)
45 #define INVALID_DATA_CONFIG (0)
46 #define INVALID_SEQ_ID (0x7fffffff)
47 
48 #define PKG_NAME_SIZE_MAX 65
49 #define SESSION_NAME_SIZE_MAX 256
50 #define DEVICE_ID_SIZE_MAX 65
51 #define GROUP_ID_SIZE_MAX 128
52 #define REQ_ID_SIZE_MAX 65
53 #define AUTH_STATE_SIZE_MAX 65
54 #define FILE_RECV_ROOT_DIR_SIZE_MAX 256
55 
56 #define MAX_DEV_INFO_VALUE_LEN 65
57 #define MAX_CAPABILITY_LEN 33
58 #define MAX_CAPABILITY_DATA_LEN 512
59 #define MAX_PACKAGE_NAME_LEN 33
60 #define MAX_DEV_INFO_COUNT 32
61 #define MAX_PUBLISH_INFO_COUNT 32
62 #define IP_LEN 46
63 #define MAX_PEERS_NUM 32
64 #define MAX_OPERATION_CODE_LEN 32
65 #define SESSION_KEY_LENGTH 32
66 #define DEVICE_KEY_LEN 16
67 
68 #define MAX_SOCKET_ADDR_LEN 46
69 
70 #define MAX_SESSION_ID 16
71 #define MAX_SESSION_SERVER_NUMBER 32
72 
73 #define WAIT_SERVER_READY_INTERVAL 200
74 
75 #define NODE_ADDR_LOOPBACK "0"
76 
77 #define MAX_UDP_CHANNEL_ID_COUNT 20
78 
79 #ifndef ARRAY_SIZE
80 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
81 #endif
82 
83 typedef struct {
84     SoftBusMutex lock;
85     unsigned int cnt;
86     ListNode list;
87 } SoftBusList;
88 
89 typedef enum {
90     SEC_TYPE_UNKNOWN = 0,
91     SEC_TYPE_PLAINTEXT = 1,
92     SEC_TYPE_CIPHERTEXT = 2,
93 } SoftBusSecType;
94 
95 /* Timer type */
96 enum {
97     TIMER_TYPE_ONCE,
98     TIMER_TYPE_PERIOD,
99     TIMER_TYPE_MAX,
100 };
101 
102 typedef enum {
103     TRANS_SESSION_BYTES = 0,
104     TRANS_SESSION_ACK,
105     TRANS_SESSION_MESSAGE,
106     TRANS_SESSION_FILE_FIRST_FRAME = 3,
107     TRANS_SESSION_FILE_ONGOINE_FRAME,
108     TRANS_SESSION_FILE_LAST_FRAME,
109     TRANS_SESSION_FILE_ONLYONE_FRAME,
110     TRANS_SESSION_FILE_ALLFILE_SENT,
111     TRANS_SESSION_FILE_CRC_CHECK_FRAME,
112     TRANS_SESSION_FILE_RESULT_FRAME,
113     TRANS_SESSION_FILE_ACK_REQUEST_SENT,
114     TRANS_SESSION_FILE_ACK_RESPONSE_SENT,
115     TRANS_SESSION_ASYNC_MESSAGE,
116 } SessionPktType;
117 
118 typedef enum {
119     CHANNEL_TYPE_TCP_DIRECT = 0,
120     CHANNEL_TYPE_PROXY,
121     CHANNEL_TYPE_UDP,
122     CHANNEL_TYPE_AUTH,
123     CHANNEL_TYPE_BUTT,
124 } ChannelType;
125 
126 typedef enum {
127     BUSINESS_TYPE_MESSAGE = 1,
128     BUSINESS_TYPE_BYTE = 2,
129     BUSINESS_TYPE_FILE = 3,
130     BUSINESS_TYPE_STREAM = 4,
131 
132     BUSINESS_TYPE_NOT_CARE,
133     BUSINESS_TYPE_BUTT,
134 } BusinessType;
135 
136 typedef struct {
137     int32_t channelId;
138     int32_t channelType;
139     int32_t businessType;
140     int32_t fd;
141     bool isServer;
142     bool isEnabled;
143     bool isEncrypt;
144     int32_t peerUid;
145     int32_t peerPid;
146     char *groupId;
147     uint32_t keyLen;
148     char *sessionKey;
149     char *peerSessionName;
150     char *peerDeviceId;
151     char *myIp;
152     char *peerIp;
153     int32_t peerPort;
154     int32_t routeType;
155     int32_t streamType;
156     int32_t encrypt;
157     int32_t fileEncrypt;
158     int32_t algorithm;
159     int32_t crc;
160     int32_t autoCloseTime;
161     bool isUdpFile;
162     int myHandleId;
163     int peerHandleId;
164     char *reqId;
165     int64_t timeStart;
166     int32_t linkType;
167     int32_t connectType;
168     bool isFastData;
169     uint32_t dataConfig;
170 } ChannelInfo;
171 
172 #ifdef __cplusplus
173 #if __cplusplus
174 }
175 #endif /* __cplusplus */
176 #endif /* __cplusplus */
177 #endif /* SOFTBUS_DEF_H */
178 
179