• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 /**
17  * @addtogroup SoftBus
18  * @{
19  *
20  * @brief Provides secure, high-speed communications between devices.
21  *
22  * This module implements unified distributed communication management of nearby devices and provides link-independent
23  * device discovery and transmission interfaces to support service publishing and data transmission.
24  * @since 1.0
25  * @version 1.0
26  */
27 
28 /**
29  * @file inner_socket.h
30  *
31  * @brief Declare the function for getting the maximum transmission unit.
32  *
33  * @since 1.0
34  * @version 1.0
35  */
36 #ifndef INNER_SOCKET_H
37 #define INNER_SOCKET_H
38 
39 #include "socket.h"
40 #include "softbus_common.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 /**
46  * @brief Enumerates flow session types.
47  *
48  * @since 2.0
49  * @version 2.0
50  */
51 typedef enum {
52     LONG_BACKGROUND_SESSION = 0,  /**< Long duration and background session. */
53     LONG_FOREGROUND_SESSION = 1,  /**< Long duration and foreground session. */
54     SHORT_BACKGROUND_SESSION = 2, /**< Short duration and background session. */
55     SHORT_FOREGROUND_SESSION = 3  /**< Short duration and foreground session. */
56 } FlowSessionType;
57 
58 /**
59  * @brief Enumerates flow qos types.
60  *
61  * @since 2.0
62  * @version 2.0
63  */
64 typedef enum {
65     LOW_LATENCY_10MS = 0x01,  /**< Low latency 10ms. */
66     LOW_LATENCY_30MS = 0x02,  /**< Low latency 30ms. */
67     LOW_LATENCY_50MS = 0x03,  /**< Low latency 50ms. */
68     LOW_LATENCY_100MS = 0x04, /**< Low latency 100ms. */
69     HIGH_THROUGHPUT = 0x08,   /**< High throughput. */
70     HIGH_RELIABILITY = 0x10,  /**< High reliability. */
71     SEMI_RELIABILITY = 0x20,  /**< Semi reliability. */
72 } FlowQosType;
73 
74 /**
75  * @brief Transmission flow information.
76  *
77  * @since 2.0
78  * @version 2.0
79  */
80 typedef struct {
81     uint64_t flowSize;           /**< Flow size, the unit is byte. */
82     FlowSessionType sessionType; /**< Flow session type. */
83     FlowQosType flowQosType;     /**< Flow qos type. */
84 } TransFlowInfo;
85 
86 /**
87  * @brief Media bandwidth type.
88  *
89  * @since 2.0
90  * @version 2.0
91  */
92 typedef enum {
93     LOW_BANDWIDTH = 0, /**< Low bandwidth. */
94     MEDIUM_BANDWIDTH,  /**< Medium bandwidth. */
95     HIGH_BANDWIDTH,    /**< High bandwidth. */
96     BANDWIDTH_BUTT,    /**< Bandwidth buff. */
97 } LogicalBandwidth;
98 
99 /**
100  * @brief Get maximum transmission unit of socket
101  *
102  * @param socket Indicates the unique socket fd.
103  * @param size Indicates the maximum transmission unit.
104  *
105  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected.
106  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
107  *
108  * @since 1.0
109  * @version 1.0
110  */
111 int32_t GetMtuSize(int32_t socket, uint32_t *mtuSize);
112 
113 /**
114  * @brief Grant permission to socket with uid and pid.
115  *
116  * @param uid Indicates the uid of the process.
117  * @param pid Indicates the pid of the process.
118  * @param socketName Indicates the name of the socket to grant permission.
119  *
120  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected.
121  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
122  *
123  * @since 1.0
124  * @version 1.0
125  */
126 int32_t DBinderGrantPermission(int32_t uid, int32_t pid, const char *socketName);
127 
128 /**
129  * @brief Removes permissions for a specific socket
130  *
131  * @param socketName Indicates the name of the socket to remove permission.
132  *
133  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected.
134  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
135  *
136  * @since 1.0
137  * @version 1.0
138  */
139 int32_t DBinderRemovePermission(const char *socketName);
140 
141 /**
142  * @brief Bind for dfs.
143  *
144  * @param socket Indicates the the unique socket fd.
145  * @param listener Indicates the pointer to the socket callback.
146  * @return Returns <b>SOFTBUS_TRANS_INVALID_PARAM</b> if invalid parameters are detected.
147  * @return Returns <b>INVALID_SOCKET</b> if the operation fails.
148  * @return Returns <b>SOFTBUS_OK</b> if the socket is bind;
149  * returns an error code otherwise.
150  * @since 1.0
151  * @version 1.0
152  */
153 int32_t DfsBind(int32_t socket, const ISocketListener *listener);
154 
155 /**
156  * @brief Set socket option.
157  *
158  * @param socket Indicates the unique socket fd.
159  * @param level Indicates the level of option.
160  * @param optType Indicates the type of option.
161  * @param optValue Indicates the pointer to the option value to set, which cannot be <b>NULL</b>.
162  * @param optValueSize Indicates the length of the option value to set.
163  *
164  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if <b>optValue</b> is <b>NULL</b> or <b>optValueSize</b> is zero.
165  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
166  * @since 2.0
167  * @version 2.0
168  */
169 int32_t SetSocketOpt(int32_t socket, OptLevel level, OptType optType, void *optValue, int32_t optValueSize);
170 
171 /**
172  * @brief Get socket option.
173  *
174  * @param socket Indicates the unique socket fd.
175  * @param level Indicates the level of option.
176  * @param optType Indicates the type of option.
177  * @param optValue Indicates the pointer to the option value to get, which cannot be <b>NULL</b>.
178  * @param optValueSize Indicates the pointer to the optValue size to get, which cannot be <b>NULL</b>.
179  *
180  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if <b>optValue</b> is <b>NULL</b> or <b>optValueSize</b> is <b>NULL</b>.
181  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
182  * @since 2.0
183  * @version 2.0
184  */
185 int32_t GetSocketOpt(int32_t socket, OptLevel level, OptType optType, void *optValue, int32_t *optValueSize);
186 
187 /**
188  * @brief privilege shutdown session only dms service can call.
189  *
190  * @param tokenId Indicates the token of channel creater.
191  * @param pid Indicates the pid of channel creater.
192  * @param peerNetworkId Indicates the peer device network id. empty mean all peer device
193  *
194  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
195  * @since 2.0
196  * @version 2.0
197  */
198 int32_t PrivilegeShutdown(uint64_t tokenId, int32_t pid, const char *peerNetworkId);
199 
200 /**
201  * @brief Defines socket bind relation checker
202  *
203  * When a socket is binding, relation checker will be called to check the feature ability relation.
204  *
205  * @since 2.0
206  * @version 2.0
207  */
208 typedef struct {
209     /**
210      * @brief Called when a socket is binding
211      *
212      * When a socket is bind, sink side will to call this function to check feature ability relation.
213      *
214      * @param sourceInfo Indicates the source Collab info.
215      * @param sinkInfo Indicates the sink Collab info.
216      *
217      * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
218      *
219      * @since 2.0
220      * @version 2.0
221     */
222     int32_t (*CheckCollabRelation)(const CollabInfo *sourceInfo, const CollabInfo *sinkInfo);
223 } IFeatureAbilityRelationChecker;
224 
225 /**
226  * @brief Register feature ability relation checker.
227  *
228  * @param relationChecker relation checker.
229  *
230  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
231  *
232  * @since 2.0
233  * @version 2.0
234  */
235 int32_t RegisterRelationChecker(IFeatureAbilityRelationChecker *relationChecker);
236 #ifdef __cplusplus
237 }
238 #endif
239 #endif // INNER_SOCKET_H