1 /*
2  * Copyright (c) 2023-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 /**
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 #include "trans_type.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 /**
47  * @brief Get maximum transmission unit of socket
48  *
49  * @param socket Indicates the unique socket fd.
50  * @param size Indicates the maximum transmission unit.
51  *
52  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected.
53  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
54  *
55  * @since 1.0
56  * @version 1.0
57  */
58 int32_t GetMtuSize(int32_t socket, uint32_t *mtuSize);
59 
60 /**
61  * @brief Grant permission to socket with uid and pid.
62  *
63  * @param uid Indicates the uid of the process.
64  * @param pid Indicates the pid of the process.
65  * @param socketName Indicates the name of the socket to grant permission.
66  *
67  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected.
68  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
69  *
70  * @since 1.0
71  * @version 1.0
72  */
73 int32_t DBinderGrantPermission(int32_t uid, int32_t pid, const char *socketName);
74 
75 /**
76  * @brief Removes permissions for a specific socket
77  *
78  * @param socketName Indicates the name of the socket to remove permission.
79  *
80  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected.
81  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
82  *
83  * @since 1.0
84  * @version 1.0
85  */
86 int32_t DBinderRemovePermission(const char *socketName);
87 
88 /**
89  * @brief Bind for dfs.
90  *
91  * @param socket Indicates the the unique socket fd.
92  * @param listener Indicates the pointer to the socket callback.
93  * @return Returns <b>SOFTBUS_TRANS_INVALID_PARAM</b> if invalid parameters are detected.
94  * @return Returns <b>INVALID_SOCKET</b> if the operation fails.
95  * @return Returns <b>SOFTBUS_OK</b> if the socket is bind;
96  * returns an error code otherwise.
97  * @since 1.0
98  * @version 1.0
99  */
100 int32_t DfsBind(int32_t socket, const ISocketListener *listener);
101 
102 /**
103  * @brief Set socket option.
104  *
105  * @param socket Indicates the unique socket fd.
106  * @param level Indicates the level of option.
107  * @param optType Indicates the type of option.
108  * @param optValue Indicates the pointer to the option value to set, which cannot be <b>NULL</b>.
109  * @param optValueSize Indicates the length of the option value to set.
110  *
111  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if <b>optValue</b> is <b>NULL</b> or <b>optValueSize</b> is zero.
112  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
113  * @since 2.0
114  * @version 2.0
115  */
116 int32_t SetSocketOpt(int32_t socket, OptLevel level, OptType optType, void *optValue, int32_t optValueSize);
117 
118 /**
119  * @brief Get socket option.
120  *
121  * @param socket Indicates the unique socket fd.
122  * @param level Indicates the level of option.
123  * @param optType Indicates the type of option.
124  * @param optValue Indicates the pointer to the option value to get, which cannot be <b>NULL</b>.
125  * @param optValueSize Indicates the pointer to the optValue size to get, which cannot be <b>NULL</b>.
126  *
127  * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if <b>optValue</b> is <b>NULL</b> or <b>optValueSize</b> is <b>NULL</b>.
128  * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise.
129  * @since 2.0
130  * @version 2.0
131  */
132 int32_t GetSocketOpt(int32_t socket, OptLevel level, OptType optType, void *optValue, int32_t *optValueSize);
133 #ifdef __cplusplus
134 }
135 #endif
136 #endif // INNER_SOCKET_H