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 #ifndef NATIVE_NET_CONN_TYPE_H 17 #define NATIVE_NET_CONN_TYPE_H 18 19 /** 20 * @addtogroup NetConnection 21 * @{ 22 * 23 * @brief Provides the data structures for the C APIs of the network connection module for network management. 24 * 25 * @since 11 26 * @version 1.0 27 */ 28 29 /** 30 * @file net_connection_type.h 31 * @brief Defines the data structures for the C APIs of the network connection module. 32 * 33 * @library libnet_connection.so 34 * @kit NetworkKit 35 * @syscap SystemCapability.Communication.NetManager.Core 36 * @since 11 37 * @version 1.0 38 * 39 */ 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 57 /** 58 * @brief Defines network capabilities. 59 * 60 * @since 11 61 * @version 1.0 62 */ 63 typedef enum NetConn_NetCap { 64 /** MMS */ 65 NETCONN_NET_CAPABILITY_MMS = 0, 66 /** Not Metered */ 67 NETCONN_NET_CAPABILITY_NOT_METERED = 11, 68 /** Internet */ 69 NETCONN_NET_CAPABILITY_INTERNET = 12, 70 /** Not VPN */ 71 NETCONN_NET_CAPABILITY_NOT_VPN = 15, 72 /** Validated */ 73 NETCONN_NET_CAPABILITY_VALIDATED = 16, 74 /** 75 * Portal 76 * @since 12 77 */ 78 NETCONN_NET_CAPABILITY_PORTAL = 17, 79 /** 80 * In checking network connectivity. 81 * @since 12 82 */ 83 NETCONN_NET_CAPABILITY_CHECKING_CONNECTIVITY = 31 84 } NetConn_NetCap; 85 86 /** 87 * @brief Defines network bearer types. 88 * 89 * @since 11 90 * @version 1.0 91 */ 92 typedef enum NetConn_NetBearerType { 93 /** Cellular network */ 94 NETCONN_BEARER_CELLULAR = 0, 95 /** WIFI */ 96 NETCONN_BEARER_WIFI = 1, 97 /** 98 * Bluetooth 99 * @since 12 100 */ 101 NETCONN_BEARER_BLUETOOTH = 2, 102 /** Ethernet */ 103 NETCONN_BEARER_ETHERNET = 3, 104 /** 105 * VPN 106 * @since 12 107 */ 108 NETCONN_BEARER_VPN = 4, 109 } NetConn_NetBearerType; 110 111 /** 112 * @brief Defines the network handle. 113 * 114 * @since 11 115 * @version 1.0 116 */ 117 typedef struct NetConn_NetHandle { 118 /** Network ID */ 119 int32_t netId; 120 } NetConn_NetHandle; 121 122 /** 123 * @brief Defines all network capabilities. 124 * 125 * @since 11 126 * @version 1.0 127 */ 128 typedef struct NetConn_NetCapabilities { 129 /** Uplink bandwidth */ 130 uint32_t linkUpBandwidthKbps; 131 /** Downlink bandwidth */ 132 uint32_t linkDownBandwidthKbps; 133 /** Network capability list */ 134 NetConn_NetCap netCaps[NETCONN_MAX_CAP_SIZE]; 135 /** Actual size of the network capability list */ 136 int32_t netCapsSize; 137 /** Bearer type list */ 138 NetConn_NetBearerType bearerTypes[NETCONN_MAX_BEARER_TYPE_SIZE]; 139 /** Actual size of the bearer type list */ 140 int32_t bearerTypesSize; 141 } NetConn_NetCapabilities; 142 143 /** 144 * @brief Defines the network address. 145 * 146 * @since 11 147 * @version 1.0 148 */ 149 typedef struct NetConn_NetAddr { 150 /** Network address family */ 151 uint8_t family; 152 /** Prefix length */ 153 uint8_t prefixlen; 154 /** Port number */ 155 uint8_t port; 156 /** Address */ 157 char address[NETCONN_MAX_STR_LEN]; 158 } NetConn_NetAddr; 159 160 /** 161 * @brief Defines the route configuration information. 162 * 163 * @since 11 164 * @version 1.0 165 */ 166 typedef struct NetConn_Route { 167 /** Network interface */ 168 char iface[NETCONN_MAX_STR_LEN]; 169 /** Destination address */ 170 NetConn_NetAddr destination; 171 /** Gateway address */ 172 NetConn_NetAddr gateway; 173 /** Gateway exists or not */ 174 int32_t hasGateway; 175 /** Default route or not */ 176 int32_t isDefaultRoute; 177 } NetConn_Route; 178 179 /** 180 * @brief Defines the proxy configuration information. 181 * 182 * @since 11 183 * @version 1.0 184 */ 185 typedef struct NetConn_HttpProxy { 186 /** Host name */ 187 char host[NETCONN_MAX_STR_LEN]; 188 /** Exclusion list of proxy servers */ 189 char exclusionList[NETCONN_MAX_EXCLUSION_SIZE][NETCONN_MAX_STR_LEN]; 190 /** Actual size of the exclusion list */ 191 int32_t exclusionListSize; 192 /** Port number */ 193 uint16_t port; 194 } NetConn_HttpProxy; 195 196 /** 197 * @brief Defines the network connection properties. 198 * 199 * @since 11 200 * @version 1.0 201 */ 202 typedef struct NetConn_ConnectionProperties { 203 /** Network interface name */ 204 char ifaceName[NETCONN_MAX_STR_LEN]; 205 /** Domain name of the network connection */ 206 char domain[NETCONN_MAX_STR_LEN]; 207 /** TCP buffer size */ 208 char tcpBufferSizes[NETCONN_MAX_STR_LEN]; 209 /** MTU */ 210 uint16_t mtu; 211 /** Address list */ 212 NetConn_NetAddr netAddrList[NETCONN_MAX_ADDR_SIZE]; 213 /** Actual size of the address list */ 214 int32_t netAddrListSize; 215 /** DNS list */ 216 NetConn_NetAddr dnsList[NETCONN_MAX_ADDR_SIZE]; 217 /** Actual size of the DNS list */ 218 int32_t dnsListSize; 219 /** Route list */ 220 NetConn_Route routeList[NETCONN_MAX_ROUTE_SIZE]; 221 /** Actual size of the route list */ 222 int32_t routeListSize; 223 /** HTTP proxy information */ 224 NetConn_HttpProxy httpProxy; 225 } NetConn_ConnectionProperties; 226 227 /** 228 * @brief Defines the network handle list. 229 * 230 * @since 11 231 * @version 1.0 232 */ 233 typedef struct NetConn_NetHandleList { 234 /** Network handle list */ 235 NetConn_NetHandle netHandles[NETCONN_MAX_NET_SIZE]; 236 /** Actual size of the network handle list */ 237 int32_t netHandleListSize; 238 } NetConn_NetHandleList; 239 240 /** 241 * @brief Pointer to the custom DNS resolver. 242 * 243 * @param host The host name to query. 244 * @param serv Service name. 245 * @param hint Pointer to the addrinfo structure. 246 * @param res Store DNS query results and return them in a linked list format. 247 * 248 * @since 11 249 * @version 1.0 250 */ 251 typedef int (*OH_NetConn_CustomDnsResolver)(const char *host, const char *serv, 252 const struct addrinfo *hint, struct addrinfo **res); 253 254 /** 255 * @brief Callback for application’s http proxy information changed. 256 * 257 * @param proxy The changed proxy information, may be a null pointer. 258 * 259 * @since 12 260 * @version 1.0 261 */ 262 typedef void (*OH_NetConn_AppHttpProxyChange)(NetConn_HttpProxy *proxy); 263 264 /** 265 * @brief Definition of network specifier. 266 * 267 * @since 12 268 * @version 1.0 269 */ 270 typedef struct NetConn_NetSpecifier { 271 /** Network capabilities. */ 272 NetConn_NetCapabilities caps; 273 /** Network identifier */ 274 char *bearerPrivateIdentifier; 275 } NetConn_NetSpecifier; 276 277 /** 278 * @brief Callback for network available. 279 * 280 * @param netHandle The network handle. 281 * 282 * @since 12 283 * @version 1.0 284 */ 285 typedef void (*OH_NetConn_NetworkAvailable)(NetConn_NetHandle *netHandle); 286 287 /** 288 * @brief Callback for network capabilities changed. 289 * 290 * @param netHandle The network handle. 291 * @param netCapabilities The network capabilities. 292 * 293 * @since 12 294 * @version 1.0 295 */ 296 typedef void (*OH_NetConn_NetCapabilitiesChange)(NetConn_NetHandle *netHandle, 297 NetConn_NetCapabilities *netCapabilities); 298 299 /** 300 * @brief Callback for network connection properties changed. 301 * 302 * @param netHandle The network handle. 303 * @param connConnetionProperties The network connection properties. 304 * 305 * @since 12 306 * @version 1.0 307 */ 308 typedef void (*OH_NetConn_NetConnectionPropertiesChange)(NetConn_NetHandle *netHandle, 309 NetConn_ConnectionProperties *connConnetionProperties); 310 311 /** 312 * @brief Callback for network lost. 313 * 314 * @param netHandle The network handle. 315 * 316 * @since 12 317 * @version 1.0 318 */ 319 typedef void (*OH_NetConn_NetLost)(NetConn_NetHandle *netHandle); 320 321 /** 322 * @brief Callback for network unavailable, this function invoked while network can not be available in given timeout. 323 * 324 * @since 12 325 * @version 1.0 326 */ 327 typedef void (*OH_NetConn_NetUnavailable)(void); 328 329 /** 330 * @brief Callback for network blocked status changed. 331 * 332 * @param netHandle The network handle. 333 * @param blocked The flag used to indicate whether the network will be blocked. 334 * 335 * @since 12 336 * @version 1.0 337 */ 338 typedef void (*OH_NetConn_NetBlockStatusChange)(NetConn_NetHandle *netHandle, bool blocked); 339 340 /** 341 * @brief Defines the network connection callbacks. 342 * 343 * @since 12 344 * @version 1.0 345 */ 346 typedef struct NetConn_NetConnCallback { 347 /** Callback for network available */ 348 OH_NetConn_NetworkAvailable onNetworkAvailable; 349 /** Callback for network capabilities changed */ 350 OH_NetConn_NetCapabilitiesChange onNetCapabilitiesChange; 351 /** Callback for network connection properties changed */ 352 OH_NetConn_NetConnectionPropertiesChange onConnetionProperties; 353 /** Callback for network lost */ 354 OH_NetConn_NetLost onNetLost; 355 /** Callback for network unavailable, this function invoked while network can not be available in given timeout */ 356 OH_NetConn_NetUnavailable onNetUnavailable; 357 /** Callback for network blocked status changed */ 358 OH_NetConn_NetBlockStatusChange onNetBlockStatusChange; 359 } NetConn_NetConnCallback; 360 361 #ifdef __cplusplus 362 } 363 #endif 364 365 /** @} */ 366 #endif /* NATIVE_NET_CONN_TYPE_H */