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 56 /** 57 * @brief Defines network capabilities. 58 * 59 * @since 11 60 * @version 1.0 61 */ 62 typedef enum NetConn_NetCap { 63 /** MMS */ 64 NETCONN_NET_CAPABILITY_MMS = 0, 65 /** SUPL */ 66 NETCONN_NET_CAPABILITY_SUPL = 1, 67 /** DUN */ 68 NETCONN_NET_CAPABILITY_DUN = 2, 69 /** IA */ 70 NETCONN_NET_CAPABILITY_IA = 3, 71 /** XCAP */ 72 NETCONN_NET_CAPABILITY_XCAP = 4, 73 /** Not Metered */ 74 NETCONN_NET_CAPABILITY_NOT_METERED = 11, 75 /** Internet */ 76 NETCONN_NET_CAPABILITY_INTERNET = 12, 77 /** Not VPN */ 78 NETCONN_NET_CAPABILITY_NOT_VPN = 15, 79 /** Validated */ 80 NETCONN_NET_CAPABILITY_VALIDATED = 16, 81 /** portal */ 82 NETCONN_NET_CAPABILITY_PORTAL = 17, 83 /** Checking connectivity */ 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 /** Bluetooth */ 99 NETCONN_BEARER_BLUETOOTH = 2, 100 /** Ethernet */ 101 NETCONN_BEARER_ETHERNET = 3, 102 /** VPN */ 103 NETCONN_BEARER_VPN = 4, 104 } NetConn_NetBearerType; 105 106 /** 107 * @brief Defines the network handle. 108 * 109 * @since 11 110 * @version 1.0 111 */ 112 typedef struct NetConn_NetHandle { 113 /** Network ID */ 114 int32_t netId; 115 } NetConn_NetHandle; 116 117 /** 118 * @brief Defines network capabilities. 119 * 120 * @since 11 121 * @version 1.0 122 */ 123 typedef struct NetConn_NetCapabilities { 124 /** Uplink bandwidth */ 125 uint32_t linkUpBandwidthKbps; 126 /** Downlink bandwidth */ 127 uint32_t linkDownBandwidthKbps; 128 /** Network capability list */ 129 NetConn_NetCap netCaps[NETCONN_MAX_CAP_SIZE]; 130 /** Actual size of the network capability list */ 131 int32_t netCapsSize; 132 /** Bearer type list */ 133 NetConn_NetBearerType bearerTypes[NETCONN_MAX_BEARER_TYPE_SIZE]; 134 /** Actual size of the bearer type list */ 135 int32_t bearerTypesSize; 136 } NetConn_NetCapabilities; 137 138 /** 139 * @brief Defines the network address. 140 * 141 * @since 11 142 * @version 1.0 143 */ 144 typedef struct NetConn_NetAddr { 145 /** Network address family */ 146 uint8_t family; 147 /** Prefix length */ 148 uint8_t prefixlen; 149 /** Port number */ 150 uint8_t port; 151 /** Address */ 152 char address[NETCONN_MAX_STR_LEN]; 153 } NetConn_NetAddr; 154 155 /** 156 * @brief Defines the route configuration information. 157 * 158 * @since 11 159 * @version 1.0 160 */ 161 typedef struct NetConn_Route { 162 /** Network interface */ 163 char iface[NETCONN_MAX_STR_LEN]; 164 /** Destination address */ 165 NetConn_NetAddr destination; 166 /** Gateway address */ 167 NetConn_NetAddr gateway; 168 /** Gateway exists or not */ 169 int32_t hasGateway; 170 /** Default route or not */ 171 int32_t isDefaultRoute; 172 } NetConn_Route; 173 174 /** 175 * @brief Defines the proxy configuration information. 176 * 177 * @since 11 178 * @version 1.0 179 */ 180 typedef struct NetConn_HttpProxy { 181 /** Host name */ 182 char host[NETCONN_MAX_STR_LEN]; 183 /** Exclusion list of proxy servers */ 184 char exclusionList[NETCONN_MAX_EXCLUSION_SIZE][NETCONN_MAX_STR_LEN]; 185 /** Actual size of the exclusion list */ 186 int32_t exclusionListSize; 187 /** Port number */ 188 uint16_t port; 189 } NetConn_HttpProxy; 190 191 /** 192 * @brief Defines the network connection properties. 193 * 194 * @since 11 195 * @version 1.0 196 */ 197 typedef struct NetConn_ConnectionProperties { 198 /** Network interface name */ 199 char ifaceName[NETCONN_MAX_STR_LEN]; 200 /** Domain name of the network connection */ 201 char domain[NETCONN_MAX_STR_LEN]; 202 /** TCP buffer size */ 203 char tcpBufferSizes[NETCONN_MAX_STR_LEN]; 204 /** MTU */ 205 uint16_t mtu; 206 /** Address list */ 207 NetConn_NetAddr netAddrList[NETCONN_MAX_ADDR_SIZE]; 208 /** Actual size of the address list */ 209 int32_t netAddrListSize; 210 /** DNS list */ 211 NetConn_NetAddr dnsList[NETCONN_MAX_ADDR_SIZE]; 212 /** Actual size of the DNS list */ 213 int32_t dnsListSize; 214 /** Route list */ 215 NetConn_Route routeList[NETCONN_MAX_ROUTE_SIZE]; 216 /** Actual size of the route list */ 217 int32_t routeListSize; 218 /** HTTP proxy information */ 219 NetConn_HttpProxy httpProxy; 220 } NetConn_ConnectionProperties; 221 222 /** 223 * @brief Defines the network handle list. 224 * 225 * @since 11 226 * @version 1.0 227 */ 228 typedef struct NetConn_NetHandleList { 229 /** Network handle list */ 230 NetConn_NetHandle netHandles[NETCONN_MAX_NET_SIZE]; 231 /** Actual size of the network handle list */ 232 int32_t netHandleListSize; 233 } NetConn_NetHandleList; 234 235 /** 236 * @brief Pointer to the custom DNS resolver. 237 * 238 * @param host The host name to query. 239 * @param serv Service name. 240 * @param hint Pointer to the addrinfo structure. 241 * @param res Store DNS query results and return them in a linked list format. 242 * 243 * @since 11 244 * @version 1.0 245 */ 246 typedef int (*OH_NetConn_CustomDnsResolver)(const char *host, const char *serv, const struct addrinfo *hint, 247 struct addrinfo **res); 248 249 typedef void (*OH_NetConn_AppHttpProxyChange)(NetConn_HttpProxy *proxy); 250 251 typedef struct NetConn_NetSpecifier { 252 NetConn_NetCapabilities caps; 253 char *bearerPrivateIdentifier; 254 } NetConn_NetSpecifier; 255 256 typedef void (*OH_NetConn_NetworkAvailable)(NetConn_NetHandle *netHandle); 257 258 typedef void (*OH_NetConn_NetCapabilitiesChange)(NetConn_NetHandle *netHandle, 259 NetConn_NetCapabilities *netCapabilities); 260 261 typedef void (*OH_NetConn_NetConnectionPropertiesChange)(NetConn_NetHandle *netHandle, 262 NetConn_ConnectionProperties *connConnetionProperties); 263 264 typedef void (*OH_NetConn_NetLost)(NetConn_NetHandle *netHandle); 265 266 typedef void (*OH_NetConn_NetUnavailable)(void); 267 268 typedef void (*OH_NetConn_NetBlockStatusChange)(NetConn_NetHandle *netHandle, bool blocked); 269 270 typedef struct NetConn_NetConnCallback { 271 OH_NetConn_NetworkAvailable onNetworkAvailable; 272 OH_NetConn_NetCapabilitiesChange onNetCapabilitiesChange; 273 OH_NetConn_NetConnectionPropertiesChange onConnetionProperties; 274 OH_NetConn_NetLost onNetLost; 275 OH_NetConn_NetUnavailable onNetUnavailable; 276 OH_NetConn_NetBlockStatusChange onNetBlockStatusChange; 277 } NetConn_NetConnCallback; 278 279 #ifdef __cplusplus 280 } 281 #endif 282 283 /** @} */ 284 #endif /* NATIVE_NET_CONN_TYPE_H */ 285