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 #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 * @syscap SystemCapability.Communication.NetManager.Core 35 * @since 11 36 * @version 1.0 37 * 38 */ 39 40 #include <stdbool.h> 41 #include <stdint.h> 42 #include <netdb.h> 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 #define NETCONN_MAX_NET_SIZE 32 49 #define NETCONN_MAX_BEARER_TYPE_SIZE 32 50 #define NETCONN_MAX_CAP_SIZE 32 51 #define NETCONN_MAX_ADDR_SIZE 32 52 #define NETCONN_MAX_ROUTE_SIZE 64 53 #define NETCONN_MAX_EXCLUSION_SIZE 256 54 #define NETCONN_MAX_STR_LEN 256 55 #define NETCONN_MAX_JUMP_NUM 30 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 /** SUPL */ 67 NETCONN_NET_CAPABILITY_SUPL = 1, 68 /** DUN */ 69 NETCONN_NET_CAPABILITY_DUN = 2, 70 /** IA */ 71 NETCONN_NET_CAPABILITY_IA = 3, 72 /** XCAP */ 73 NETCONN_NET_CAPABILITY_XCAP = 4, 74 /** Not Metered */ 75 NETCONN_NET_CAPABILITY_NOT_METERED = 11, 76 /** Internet */ 77 NETCONN_NET_CAPABILITY_INTERNET = 12, 78 /** Not VPN */ 79 NETCONN_NET_CAPABILITY_NOT_VPN = 15, 80 /** Validated */ 81 NETCONN_NET_CAPABILITY_VALIDATED = 16, 82 /** portal */ 83 NETCONN_NET_CAPABILITY_PORTAL = 17, 84 /** Checking connectivity */ 85 NETCONN_NET_CAPABILITY_CHECKING_CONNECTIVITY = 31 86 } NetConn_NetCap; 87 88 /** 89 * @brief Defines network bearer types. 90 * 91 * @since 11 92 * @version 1.0 93 */ 94 typedef enum NetConn_NetBearerType { 95 /** Cellular network */ 96 NETCONN_BEARER_CELLULAR = 0, 97 /** WIFI */ 98 NETCONN_BEARER_WIFI = 1, 99 /** Bluetooth */ 100 NETCONN_BEARER_BLUETOOTH = 2, 101 /** Ethernet */ 102 NETCONN_BEARER_ETHERNET = 3, 103 /** VPN */ 104 NETCONN_BEARER_VPN = 4, 105 } NetConn_NetBearerType; 106 107 /** 108 * @brief Defines the network handle. 109 * 110 * @since 11 111 * @version 1.0 112 */ 113 typedef struct NetConn_NetHandle { 114 /** Network ID */ 115 int32_t netId; 116 } NetConn_NetHandle; 117 118 /** 119 * @brief Defines network capabilities. 120 * 121 * @since 11 122 * @version 1.0 123 */ 124 typedef struct NetConn_NetCapabilities { 125 /** Uplink bandwidth */ 126 uint32_t linkUpBandwidthKbps; 127 /** Downlink bandwidth */ 128 uint32_t linkDownBandwidthKbps; 129 /** Network capability list */ 130 NetConn_NetCap netCaps[NETCONN_MAX_CAP_SIZE]; 131 /** Actual size of the network capability list */ 132 int32_t netCapsSize; 133 /** Bearer type list */ 134 NetConn_NetBearerType bearerTypes[NETCONN_MAX_BEARER_TYPE_SIZE]; 135 /** Actual size of the bearer type list */ 136 int32_t bearerTypesSize; 137 } NetConn_NetCapabilities; 138 139 /** 140 * @brief Defines the network address. 141 * 142 * @since 11 143 * @version 1.0 144 */ 145 typedef struct NetConn_NetAddr { 146 /** Network address family */ 147 uint8_t family; 148 /** Prefix length */ 149 uint8_t prefixlen; 150 /** Port number */ 151 uint8_t port; 152 /** Address */ 153 char address[NETCONN_MAX_STR_LEN]; 154 } NetConn_NetAddr; 155 156 /** 157 * @brief Defines the route configuration information. 158 * 159 * @since 11 160 * @version 1.0 161 */ 162 typedef struct NetConn_Route { 163 /** Network interface */ 164 char iface[NETCONN_MAX_STR_LEN]; 165 /** Destination address */ 166 NetConn_NetAddr destination; 167 /** Gateway address */ 168 NetConn_NetAddr gateway; 169 /** Gateway exists or not */ 170 int32_t hasGateway; 171 /** Default route or not */ 172 int32_t isDefaultRoute; 173 } NetConn_Route; 174 175 /** 176 * @brief Defines the proxy configuration information. 177 * 178 * @since 11 179 * @version 1.0 180 */ 181 typedef struct NetConn_HttpProxy { 182 /** Host name */ 183 char host[NETCONN_MAX_STR_LEN]; 184 /** Exclusion list of proxy servers */ 185 char exclusionList[NETCONN_MAX_EXCLUSION_SIZE][NETCONN_MAX_STR_LEN]; 186 /** Actual size of the exclusion list */ 187 int32_t exclusionListSize; 188 /** Port number */ 189 uint16_t port; 190 } NetConn_HttpProxy; 191 192 /** 193 * @brief Defines the network connection properties. 194 * 195 * @since 11 196 * @version 1.0 197 */ 198 typedef struct NetConn_ConnectionProperties { 199 /** Network interface name */ 200 char ifaceName[NETCONN_MAX_STR_LEN]; 201 /** Domain name of the network connection */ 202 char domain[NETCONN_MAX_STR_LEN]; 203 /** TCP buffer size */ 204 char tcpBufferSizes[NETCONN_MAX_STR_LEN]; 205 /** MTU */ 206 uint16_t mtu; 207 /** Address list */ 208 NetConn_NetAddr netAddrList[NETCONN_MAX_ADDR_SIZE]; 209 /** Actual size of the address list */ 210 int32_t netAddrListSize; 211 /** DNS list */ 212 NetConn_NetAddr dnsList[NETCONN_MAX_ADDR_SIZE]; 213 /** Actual size of the DNS list */ 214 int32_t dnsListSize; 215 /** Route list */ 216 NetConn_Route routeList[NETCONN_MAX_ROUTE_SIZE]; 217 /** Actual size of the route list */ 218 int32_t routeListSize; 219 /** HTTP proxy information */ 220 NetConn_HttpProxy httpProxy; 221 } NetConn_ConnectionProperties; 222 223 /** 224 * @brief Defines the network handle list. 225 * 226 * @since 11 227 * @version 1.0 228 */ 229 typedef struct NetConn_NetHandleList { 230 /** Network handle list */ 231 NetConn_NetHandle netHandles[NETCONN_MAX_NET_SIZE]; 232 /** Actual size of the network handle list */ 233 int32_t netHandleListSize; 234 } NetConn_NetHandleList; 235 236 /** 237 * @brief Pointer to the custom DNS resolver. 238 * 239 * @param host The host name to query. 240 * @param serv Service name. 241 * @param hint Pointer to the addrinfo structure. 242 * @param res Store DNS query results and return them in a linked list format. 243 * 244 * @since 11 245 * @version 1.0 246 */ 247 typedef int (*OH_NetConn_CustomDnsResolver)(const char *host, const char *serv, const struct addrinfo *hint, 248 struct addrinfo **res); 249 250 typedef void (*OH_NetConn_AppHttpProxyChange)(NetConn_HttpProxy *proxy); 251 252 typedef struct NetConn_NetSpecifier { 253 NetConn_NetCapabilities caps; 254 char *bearerPrivateIdentifier; 255 } NetConn_NetSpecifier; 256 257 typedef void (*OH_NetConn_NetworkAvailable)(NetConn_NetHandle *netHandle); 258 259 typedef void (*OH_NetConn_NetCapabilitiesChange)(NetConn_NetHandle *netHandle, 260 NetConn_NetCapabilities *netCapabilities); 261 262 typedef void (*OH_NetConn_NetConnectionPropertiesChange)(NetConn_NetHandle *netHandle, 263 NetConn_ConnectionProperties *connConnetionProperties); 264 265 typedef void (*OH_NetConn_NetLost)(NetConn_NetHandle *netHandle); 266 267 typedef void (*OH_NetConn_NetUnavailable)(void); 268 269 typedef void (*OH_NetConn_NetBlockStatusChange)(NetConn_NetHandle *netHandle, bool blocked); 270 271 typedef struct NetConn_NetConnCallback { 272 OH_NetConn_NetworkAvailable onNetworkAvailable; 273 OH_NetConn_NetCapabilitiesChange onNetCapabilitiesChange; 274 OH_NetConn_NetConnectionPropertiesChange onConnetionProperties; 275 OH_NetConn_NetLost onNetLost; 276 OH_NetConn_NetUnavailable onNetUnavailable; 277 OH_NetConn_NetBlockStatusChange onNetBlockStatusChange; 278 } NetConn_NetConnCallback; 279 280 constexpr int32_t NETCONN_MAX_RTT_NUM = 4; 281 typedef struct NetConn_ProbeResultInfo { 282 uint8_t lossRate; 283 284 uint32_t rtt[NETCONN_MAX_RTT_NUM]; 285 } NetConn_ProbeResultInfo; 286 287 typedef enum NetConn_PacketsType { 288 /** ICMP */ 289 NETCONN_PACKETS_ICMP = 0, 290 /** UDP */ 291 NETCONN_PACKETS_UDP = 1, 292 } NetConn_PacketsType; 293 294 typedef struct NetConn_TraceRouteOption { 295 /** Maximum number of jumps */ 296 uint8_t maxJumpNumber; /** default NETCONN_MAX_JUMP_NUM */ 297 /** Packets Type */ 298 NetConn_PacketsType packetsType; /** default ICMP */ 299 } NetConn_TraceRouteOption; 300 301 typedef struct NetConn_TraceRouteInfo { 302 /** Number of jumps */ 303 uint8_t jumpNo; 304 /** host name or address */ 305 char address[NETCONN_MAX_STR_LEN]; 306 /** RTT in millisecond */ 307 uint32_t rtt[NETCONN_MAX_RTT_NUM]; 308 } NetConn_TraceRouteInfo; 309 #ifdef __cplusplus 310 } 311 #endif 312 313 /** @} */ 314 #endif /* NATIVE_NET_CONN_TYPE_H */ 315