• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 NetConnection
18  * @{
19  *
20  * @brief Provides the data structures for the C APIs of the network connection module for network management.
21  *
22  * @since 11
23  * @version 1.0
24  */
25 
26 /**
27  * @file net_connection_type.h
28  * @brief Defines the data structures for the C APIs of the network connection module.
29  *
30  * @library libnet_connection.so
31  * @kit NetworkKit
32  * @syscap SystemCapability.Communication.NetManager.Core
33  * @since 11
34  * @version 1.0
35  *
36  */
37 
38 #ifndef NATIVE_NET_CONN_TYPE_H
39 #define NATIVE_NET_CONN_TYPE_H
40 
41 #include <stdbool.h>
42 #include <stdint.h>
43 #include <netdb.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #define NETCONN_MAX_NET_SIZE 32
50 #define NETCONN_MAX_BEARER_TYPE_SIZE 32
51 #define NETCONN_MAX_CAP_SIZE 32
52 #define NETCONN_MAX_ADDR_SIZE 32
53 #define NETCONN_MAX_ROUTE_SIZE 64
54 #define NETCONN_MAX_EXCLUSION_SIZE 256
55 #define NETCONN_MAX_STR_LEN 256
56 #define NETCONN_MAX_RTT_NUM 4
57 
58 /**
59  * @brief Defines network capabilities.
60  *
61  * @since 11
62  * @version 1.0
63  */
64 typedef enum NetConn_NetCap {
65     /** MMS */
66     NETCONN_NET_CAPABILITY_MMS = 0,
67     /** Not Metered */
68     NETCONN_NET_CAPABILITY_NOT_METERED = 11,
69     /** Internet */
70     NETCONN_NET_CAPABILITY_INTERNET = 12,
71     /** Not VPN */
72     NETCONN_NET_CAPABILITY_NOT_VPN = 15,
73     /** Validated */
74     NETCONN_NET_CAPABILITY_VALIDATED = 16,
75     /**
76     * Portal
77     * @since 12
78     */
79     NETCONN_NET_CAPABILITY_PORTAL = 17,
80     /**
81      * In checking network connectivity.
82      * @since 12
83      */
84     NETCONN_NET_CAPABILITY_CHECKING_CONNECTIVITY = 31
85 } NetConn_NetCap;
86 
87 /**
88  * @brief Defines network bearer types.
89  *
90  * @since 11
91  * @version 1.0
92  */
93 typedef enum NetConn_NetBearerType {
94     /** Cellular network */
95     NETCONN_BEARER_CELLULAR = 0,
96     /** WIFI */
97     NETCONN_BEARER_WIFI = 1,
98     /**
99      * Bluetooth
100      * @since 12
101      */
102     NETCONN_BEARER_BLUETOOTH = 2,
103     /** Ethernet */
104     NETCONN_BEARER_ETHERNET = 3,
105     /**
106      * VPN
107      * @since 12
108      */
109     NETCONN_BEARER_VPN = 4,
110 } NetConn_NetBearerType;
111 
112 /**
113  * @brief Enumerates NetConn error codes.
114  *
115  * @since 15
116  */
117 typedef enum NetConn_ErrorCode {
118     /** @error Success return code on success*/
119     NETCONN_SUCCESS = 0,
120     /** @error Permission verification failed */
121     NETCONN_PERMISSION_DENIED = 201,
122     /** @error Parameter check failed */
123     NETCONN_PARAMETER_ERROR = 401,
124     /** @error Failed to connect to the service */
125     NETCONN_OPERATION_FAILED = 2100002,
126     /**
127      * @error System internal error.
128      * 1. Memory-related error, for example, insufficient memory or memory data copy failures.
129      * 2. Null pointer error, for example, using memory that has already been released.
130      */
131     NETCONN_INTERNAL_ERROR = 2100003
132 } NetConn_ErrorCode;
133 
134 /**
135  * @brief Enumerates packets type of trace route.
136  *
137  * @since 20
138  */
139 typedef enum NetConn_PacketsType {
140     /** ICMP */
141     NETCONN_PACKETS_ICMP = 0,
142     /** UDP */
143     NETCONN_PACKETS_UDP = 1
144 } NetConn_PacketsType;
145 
146 /**
147  * @brief Defines the network handle.
148  *
149  * @since 11
150  * @version 1.0
151  */
152 typedef struct NetConn_NetHandle {
153     /** Network ID */
154     int32_t netId;
155 } NetConn_NetHandle;
156 
157 /**
158  * @brief Defines all network capabilities.
159  *
160  * @since 11
161  * @version 1.0
162  */
163 typedef struct NetConn_NetCapabilities {
164     /** Uplink bandwidth */
165     uint32_t linkUpBandwidthKbps;
166     /** Downlink bandwidth */
167     uint32_t linkDownBandwidthKbps;
168     /** Network capability list */
169     NetConn_NetCap netCaps[NETCONN_MAX_CAP_SIZE];
170     /** Actual size of the network capability list */
171     int32_t netCapsSize;
172     /** Bearer type list */
173     NetConn_NetBearerType bearerTypes[NETCONN_MAX_BEARER_TYPE_SIZE];
174     /** Actual size of the bearer type list */
175     int32_t bearerTypesSize;
176 } NetConn_NetCapabilities;
177 
178 /**
179  * @brief Defines the network address.
180  *
181  * @since 11
182  * @version 1.0
183  */
184 typedef struct NetConn_NetAddr {
185     /** Network address family */
186     uint8_t family;
187     /** Prefix length */
188     uint8_t prefixlen;
189     /** Port number */
190     uint8_t port;
191     /** Address */
192     char address[NETCONN_MAX_STR_LEN];
193 } NetConn_NetAddr;
194 
195 /**
196  * @brief Defines the route configuration information.
197  *
198  * @since 11
199  * @version 1.0
200  */
201 typedef struct NetConn_Route {
202     /** Network interface */
203     char iface[NETCONN_MAX_STR_LEN];
204     /** Destination address */
205     NetConn_NetAddr destination;
206     /** Gateway address */
207     NetConn_NetAddr gateway;
208     /** Gateway exists or not */
209     int32_t hasGateway;
210     /** Default route or not */
211     int32_t isDefaultRoute;
212 } NetConn_Route;
213 
214 /**
215  * @brief Defines the proxy configuration information.
216  *
217  * @since 11
218  * @version 1.0
219  */
220 typedef struct NetConn_HttpProxy {
221     /** Host name */
222     char host[NETCONN_MAX_STR_LEN];
223     /** Exclusion list of proxy servers */
224     char exclusionList[NETCONN_MAX_EXCLUSION_SIZE][NETCONN_MAX_STR_LEN];
225     /** Actual size of the exclusion list */
226     int32_t exclusionListSize;
227     /** Port number */
228     uint16_t port;
229 } NetConn_HttpProxy;
230 
231 /**
232  * @brief Defines the network connection properties.
233  *
234  * @since 11
235  * @version 1.0
236  */
237 typedef struct NetConn_ConnectionProperties {
238     /** Network interface name */
239     char ifaceName[NETCONN_MAX_STR_LEN];
240     /** Domain name of the network connection */
241     char domain[NETCONN_MAX_STR_LEN];
242     /** TCP buffer size */
243     char tcpBufferSizes[NETCONN_MAX_STR_LEN];
244     /** MTU */
245     uint16_t mtu;
246     /** Address list */
247     NetConn_NetAddr netAddrList[NETCONN_MAX_ADDR_SIZE];
248     /** Actual size of the address list */
249     int32_t netAddrListSize;
250     /** DNS list */
251     NetConn_NetAddr dnsList[NETCONN_MAX_ADDR_SIZE];
252     /** Actual size of the DNS list */
253     int32_t dnsListSize;
254     /** Route list */
255     NetConn_Route routeList[NETCONN_MAX_ROUTE_SIZE];
256     /** Actual size of the route list */
257     int32_t routeListSize;
258     /** HTTP proxy information */
259     NetConn_HttpProxy httpProxy;
260 } NetConn_ConnectionProperties;
261 
262 /**
263  * @brief Defines the network handle list.
264  *
265  * @since 11
266  * @version 1.0
267  */
268 typedef struct NetConn_NetHandleList {
269     /** Network handle list */
270     NetConn_NetHandle netHandles[NETCONN_MAX_NET_SIZE];
271     /** Actual size of the network handle list */
272     int32_t netHandleListSize;
273 } NetConn_NetHandleList;
274 
275 /**
276  * @brief Pointer to the custom DNS resolver.
277  *
278  * @param host The host name to query.
279  * @param serv Service name.
280  * @param hint Pointer to the addrinfo structure.
281  * @param res Store DNS query results and return them in a linked list format.
282  *
283  * @since 11
284  * @version 1.0
285  */
286 typedef int (*OH_NetConn_CustomDnsResolver)(const char *host, const char *serv,
287     const struct addrinfo *hint, struct addrinfo **res);
288 
289 /**
290  * @brief Callback for application’s http proxy information changed.
291  *
292  * @param proxy The changed proxy information, may be a null pointer.
293  *
294  * @since 12
295  * @version 1.0
296  */
297 typedef void (*OH_NetConn_AppHttpProxyChange)(NetConn_HttpProxy *proxy);
298 
299 /**
300  * @brief Definition of network specifier.
301  *
302  * @since 12
303  * @version 1.0
304  */
305 typedef struct NetConn_NetSpecifier {
306     /** Network capabilities. */
307     NetConn_NetCapabilities caps;
308     /** Network identifier */
309     char *bearerPrivateIdentifier;
310 } NetConn_NetSpecifier;
311 
312 /**
313  * @brief Callback for network available.
314  *
315  * @param netHandle The network handle.
316  *
317  * @since 12
318  * @version 1.0
319  */
320 typedef void (*OH_NetConn_NetworkAvailable)(NetConn_NetHandle *netHandle);
321 
322 /**
323  * @brief Callback for network capabilities changed.
324  *
325  * @param netHandle The network handle.
326  * @param netCapabilities The network capabilities.
327  *
328  * @since 12
329  * @version 1.0
330  */
331 typedef void (*OH_NetConn_NetCapabilitiesChange)(NetConn_NetHandle *netHandle,
332                                                  NetConn_NetCapabilities *netCapabilities);
333 
334 /**
335  * @brief Callback for network connection properties changed.
336  *
337  * @param netHandle The network handle.
338  * @param connConnetionProperties The network connection properties.
339  *
340  * @since 12
341  * @version 1.0
342  */
343 typedef void (*OH_NetConn_NetConnectionPropertiesChange)(NetConn_NetHandle *netHandle,
344                                                          NetConn_ConnectionProperties *connConnetionProperties);
345 
346 /**
347  * @brief Callback for network lost.
348  *
349  * @param netHandle The network handle.
350  *
351  * @since 12
352  * @version 1.0
353  */
354 typedef void (*OH_NetConn_NetLost)(NetConn_NetHandle *netHandle);
355 
356 /**
357  * @brief Callback for network unavailable, this function invoked while network can not be available in given timeout.
358  *
359  * @since 12
360  * @version 1.0
361  */
362 typedef void (*OH_NetConn_NetUnavailable)(void);
363 
364 /**
365  * @brief Callback for network blocked status changed.
366  *
367  * @param netHandle The network handle.
368  * @param blocked The flag used to indicate whether the network will be blocked.
369  *
370  * @since 12
371  * @version 1.0
372  */
373 typedef void (*OH_NetConn_NetBlockStatusChange)(NetConn_NetHandle *netHandle, bool blocked);
374 
375 /**
376  * @brief Defines the network connection callbacks.
377  *
378  * @since 12
379  * @version 1.0
380  */
381 typedef struct NetConn_NetConnCallback {
382     /** Callback for network available */
383     OH_NetConn_NetworkAvailable onNetworkAvailable;
384     /** Callback for network capabilities changed */
385     OH_NetConn_NetCapabilitiesChange onNetCapabilitiesChange;
386     /** Callback for network connection properties changed */
387     OH_NetConn_NetConnectionPropertiesChange onConnetionProperties;
388     /** Callback for network lost */
389     OH_NetConn_NetLost onNetLost;
390     /** Callback for network unavailable, this function invoked while network can not be available in given timeout */
391     OH_NetConn_NetUnavailable onNetUnavailable;
392     /** Callback for network blocked status changed */
393     OH_NetConn_NetBlockStatusChange onNetBlockStatusChange;
394 } NetConn_NetConnCallback;
395 
396 /**
397  * @brief Defines the probe result information.
398  *
399  * @since 20
400  */
401 typedef struct NetConn_ProbeResultInfo {
402     /** Number of jumps */
403     uint8_t lossRate;
404     /** RTT in micro seconds, min/avg/max/std */
405     uint32_t rtt[NETCONN_MAX_RTT_NUM];
406 } NetConn_ProbeResultInfo;
407 
408 /**
409  * @brief Defines the network trace route option.
410  *
411  * @since 20
412  */
413 typedef struct NetConn_TraceRouteOption {
414     /** Maximum number of jumps, default is 30 */
415     uint8_t maxJumpNumber;
416     /** Packets type */
417     NetConn_PacketsType packetsType;
418 } NetConn_TraceRouteOption;
419 
420 /**
421  * @brief Defines the trace route information.
422  *
423  * @since 20
424  */
425 typedef struct NetConn_TraceRouteInfo {
426     /** Number of jumps */
427     uint8_t jumpNo;
428     /** host name or address */
429     char address[NETCONN_MAX_STR_LEN];
430     /** RTT in micro seconds */
431     uint32_t rtt[NETCONN_MAX_RTT_NUM];
432 } NetConn_TraceRouteInfo;
433 
434 #ifdef __cplusplus
435 }
436 #endif
437 
438 /** @} */
439 #endif /* NATIVE_NET_CONN_TYPE_H */