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 * @syscap SystemCapability.Communication.NetManager.Core 35 * @since 11 36 * @version 1.0 37 * 38 */ 39 40 #include <stdint.h> 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 #define NETCONN_MAX_NET_SIZE 32 47 #define NETCONN_MAX_BEARER_TYPE_SIZE 32 48 #define NETCONN_MAX_CAP_SIZE 32 49 #define NETCONN_MAX_ADDR_SIZE 32 50 #define NETCONN_MAX_ROUTE_SIZE 64 51 #define NETCONN_MAX_EXCLUSION_SIZE 256 52 #define NETCONN_MAX_STR_LEN 256 53 54 /** 55 * @brief Defines network capabilities. 56 * 57 * @since 11 58 * @version 1.0 59 */ 60 typedef enum NetConn_NetCap { 61 /** MMS */ 62 NETCONN_NET_CAPABILITY_MMS = 0, 63 /** Not Metered */ 64 NETCONN_NET_CAPABILITY_NOT_METERED = 11, 65 /** Internet */ 66 NETCONN_NET_CAPABILITY_INTERNET = 12, 67 /** Not VPN */ 68 NETCONN_NET_CAPABILITY_NOT_VPN = 15, 69 /** Validated */ 70 NETCONN_NET_CAPABILITY_VALIDATED = 16, 71 } NetConn_NetCap; 72 73 /** 74 * @brief Defines network bearer types. 75 * 76 * @since 11 77 * @version 1.0 78 */ 79 typedef enum NetConn_NetBearerType { 80 /** Cellular network */ 81 NETCONN_BEARER_CELLULAR = 0, 82 /** WIFI */ 83 NETCONN_BEARER_WIFI = 1, 84 /** Ethernet */ 85 NETCONN_BEARER_ETHERNET = 3, 86 } NetConn_NetBearerType; 87 88 /** 89 * @brief Defines the network handle. 90 * 91 * @since 11 92 * @version 1.0 93 */ 94 typedef struct NetConn_NetHandle { 95 /** Network ID */ 96 int32_t netId; 97 } NetConn_NetHandle; 98 99 /** 100 * @brief Defines network capabilities. 101 * 102 * @since 11 103 * @version 1.0 104 */ 105 typedef struct NetConn_NetCapabilities { 106 /** Uplink bandwidth */ 107 uint32_t linkUpBandwidthKbps; 108 /** Downlink bandwidth */ 109 uint32_t linkDownBandwidthKbps; 110 /** Network capability list */ 111 NetConn_NetCap netCaps[NETCONN_MAX_CAP_SIZE]; 112 /** Actual size of the network capability list */ 113 int32_t netCapsSize; 114 /** Bearer type list */ 115 NetConn_NetBearerType bearerTypes[NETCONN_MAX_BEARER_TYPE_SIZE]; 116 /** Actual size of the bearer type list */ 117 int32_t bearerTypesSize; 118 } NetConn_NetCapabilities; 119 120 /** 121 * @brief Defines the network address. 122 * 123 * @since 11 124 * @version 1.0 125 */ 126 typedef struct NetConn_NetAddr { 127 /** Network address family */ 128 uint8_t family; 129 /** Prefix length */ 130 uint8_t prefixlen; 131 /** Port number */ 132 uint8_t port; 133 /** Address */ 134 char address[NETCONN_MAX_STR_LEN]; 135 } NetConn_NetAddr; 136 137 /** 138 * @brief Defines the route configuration information. 139 * 140 * @since 11 141 * @version 1.0 142 */ 143 typedef struct NetConn_Route { 144 /** Network interface */ 145 char iface[NETCONN_MAX_STR_LEN]; 146 /** Destination address */ 147 NetConn_NetAddr destination; 148 /** Gateway address */ 149 NetConn_NetAddr gateway; 150 /** Gateway exists or not */ 151 int32_t hasGateway; 152 /** Default route or not */ 153 int32_t isDefaultRoute; 154 } NetConn_Route; 155 156 /** 157 * @brief Defines the proxy configuration information. 158 * 159 * @since 11 160 * @version 1.0 161 */ 162 typedef struct NetConn_HttpProxy { 163 /** Host name */ 164 char host[NETCONN_MAX_STR_LEN]; 165 /** Exclusion list of proxy servers */ 166 char exclusionList[NETCONN_MAX_EXCLUSION_SIZE][NETCONN_MAX_STR_LEN]; 167 /** Actual size of the exclusion list */ 168 int32_t exclusionListSize; 169 /** Port number */ 170 uint16_t port; 171 } NetConn_HttpProxy; 172 173 /** 174 * @brief Defines the network connection properties. 175 * 176 * @since 11 177 * @version 1.0 178 */ 179 typedef struct NetConn_ConnectionProperties { 180 /** Network interface name */ 181 char ifaceName[NETCONN_MAX_STR_LEN]; 182 /** Domain name of the network connection */ 183 char domain[NETCONN_MAX_STR_LEN]; 184 /** TCP buffer size */ 185 char tcpBufferSizes[NETCONN_MAX_STR_LEN]; 186 /** MTU */ 187 uint16_t mtu; 188 /** Address list */ 189 NetConn_NetAddr netAddrList[NETCONN_MAX_ADDR_SIZE]; 190 /** Actual size of the address list */ 191 int32_t netAddrListSize; 192 /** DNS list */ 193 NetConn_NetAddr dnsList[NETCONN_MAX_ADDR_SIZE]; 194 /** Actual size of the DNS list */ 195 int32_t dnsListSize; 196 /** Route list */ 197 NetConn_Route routeList[NETCONN_MAX_ROUTE_SIZE]; 198 /** Actual size of the route list */ 199 int32_t routeListSize; 200 /** HTTP proxy information */ 201 NetConn_HttpProxy httpProxy; 202 } NetConn_ConnectionProperties; 203 204 /** 205 * @brief Defines the network handle list. 206 * 207 * @since 11 208 * @version 1.0 209 */ 210 typedef struct NetConn_NetHandleList { 211 /** Network handle list */ 212 NetConn_NetHandle netHandles[NETCONN_MAX_NET_SIZE]; 213 /** Actual size of the network handle list */ 214 int32_t netHandleListSize; 215 } NetConn_NetHandleList; 216 217 /** 218 * @brief Pointer to the custom DNS resolver. 219 * 220 * @param host The host name to query. 221 * @param serv Service name. 222 * @param hint Pointer to the addrinfo structure. 223 * @param res Store DNS query results and return them in a linked list format. 224 * 225 * @since 11 226 * @version 1.0 227 */ 228 typedef int (*OH_NetConn_CustomDnsResolver)(const char *host, const char *serv, 229 const struct addrinfo *hint, struct addrinfo **res); 230 #ifdef __cplusplus 231 } 232 #endif 233 234 /** @} */ 235 #endif /* NATIVE_NET_CONN_TYPE_H */