• 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 Get maximum transmission unit of socket
47  *
48  * @param socket Indicates the unique socket fd.
49  * @param size Indicates the maximum transmission unit.
50  *
51  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected.
52  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
53  *
54  * @since 1.0
55  * @version 1.0
56  */
57 int32_t GetMtuSize(int32_t socket, uint32_t *mtuSize);
58 
59 /**
60  * @brief Grant permission to socket with uid and pid.
61  *
62  * @param uid Indicates the uid of the process.
63  * @param pid Indicates the pid of the process.
64  * @param socketName Indicates the name of the socket to grant permission.
65  *
66  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected.
67  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
68  *
69  * @since 1.0
70  * @version 1.0
71  */
72 int32_t DBinderGrantPermission(int32_t uid, int32_t pid, const char *socketName);
73 
74 /**
75  * @brief Removes permissions for a specific socket
76  *
77  * @param socketName Indicates the name of the socket to remove permission.
78  *
79  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected.
80  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
81  *
82  * @since 1.0
83  * @version 1.0
84  */
85 int32_t DBinderRemovePermission(const char *socketName);
86 
87 /**
88  * @brief Bind for dfs.
89  *
90  * @param socket Indicates the the unique socket fd.
91  * @param listener Indicates the pointer to the socket callback.
92  * @return Returns <b>SOFTBUS_TRANS_INVALID_PARAM</b> if invalid parameters are detected.
93  * @return Returns <b>INVALID_SOCKET</b> if the operation fails.
94  * @return Returns <b>SOFTBUS_OK</b> if the socket is bind;
95  * returns an error code otherwise.
96  * @since 1.0
97  * @version 1.0
98  */
99 int32_t DfsBind(int32_t socket, const ISocketListener *listener);
100 
101 /**
102  * @brief Set socket option.
103  *
104  * @param socket Indicates the unique socket fd.
105  * @param level Indicates the level of option.
106  * @param optType Indicates the type of option.
107  * @param optValue Indicates the pointer to the option value to set, which cannot be <b>NULL</b>.
108  * @param optValueSize Indicates the length of the option value to set.
109  *
110  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if <b>optValue</b> is <b>NULL</b> or <b>optValueSize</b> is zero.
111  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
112  * @since 2.0
113  * @version 2.0
114  */
115 int32_t SetSocketOpt(int32_t socket, OptLevel level, OptType optType, void *optValue, int32_t optValueSize);
116 
117 /**
118  * @brief Get socket option.
119  *
120  * @param socket Indicates the unique socket fd.
121  * @param level Indicates the level of option.
122  * @param optType Indicates the type of option.
123  * @param optValue Indicates the pointer to the option value to get, which cannot be <b>NULL</b>.
124  * @param optValueSize Indicates the pointer to the optValue size to get, which cannot be <b>NULL</b>.
125  *
126  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if <b>optValue</b> is <b>NULL</b> or <b>optValueSize</b> is <b>NULL</b>.
127  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
128  * @since 2.0
129  * @version 2.0
130  */
131 int32_t GetSocketOpt(int32_t socket, OptLevel level, OptType optType, void *optValue, int32_t *optValueSize);
132 
133 /**
134  * @brief privilege shutdown session only dms service can call.
135  *
136  * @param tokenId Indicates the token of channel creater.
137  * @param pid Indicates the pid of channel creater.
138  * @param peerNetworkId Indicates the peer device network id. empty mean all peer device
139  *
140  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
141  * @since 2.0
142  * @version 2.0
143  */
144 int32_t PrivilegeShutdown(uint64_t tokenId, int32_t pid, const char *peerNetworkId);
145 
146 /**
147  * @brief Defines socket bind relation checker
148  *
149  * When a socket is binding, relation checker will be called to check the feature ability relation.
150  *
151  * @since 2.0
152  * @version 2.0
153  */
154 typedef struct {
155     /**
156      * @brief Called when a socket is binding
157      *
158      * When a socket is bind, sink side will to call this function to check feature ability relation.
159      *
160      * @param sourceInfo Indicates the source Collab info.
161      * @param sinkInfo Indicates the sink Collab info.
162      *
163      * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
164      *
165      * @since 2.0
166      * @version 2.0
167     */
168     int32_t (*CheckCollabRelation)(const CollabInfo *sourceInfo, const CollabInfo *sinkInfo);
169 } IFeatureAbilityRelationChecker;
170 
171 /**
172  * @brief Register feature ability relation checker.
173  *
174  * @param relationChecker relation checker.
175  *
176  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
177  *
178  * @since 2.0
179  * @version 2.0
180  */
181 int32_t RegisterRelationChecker(IFeatureAbilityRelationChecker *relationChecker);
182 #ifdef __cplusplus
183 }
184 #endif
185 #endif // INNER_SOCKET_H