diff --git a/network/netmanager/include/net_connection.h b/network/netmanager/include/net_connection.h index 02b937057deb6bc65db3c670e003fba0be04435d..7a64821bca25756685e7ec0035e4dcf167509d3f 100644 --- a/network/netmanager/include/net_connection.h +++ b/network/netmanager/include/net_connection.h @@ -45,6 +45,91 @@ extern "C" { #endif +/** + * @brief Checks whether a default activated data network is available. + * + * @param hasDefaultNet Pointer to the result that specifies whether a default activated data network is available. + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. + * @permission ohos.permission.GET_NETWORK_INFO + * @syscap SystemCapability.Communication.NetManager.Core + * @since 11 + * @version 1.0 + */ +int32_t OH_NetConn_HasDefaultNet(int32_t *hasDefaultNet); + +/** + * @brief Obtains the default activated data network. + * + * @param netHandle Pointer to the network handle that contains the network ID. + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. + * @permission ohos.permission.GET_NETWORK_INFO + * @syscap SystemCapability.Communication.NetManager.Core + * @since 11 + * @version 1.0 + */ +int32_t OH_NetConn_GetDefaultNet(NetConn_NetHandle *netHandle); + +/** + * @brief Checks whether metering is enabled for the default data network. + * + * @param isMetered Pointer to the result that specifies whether metering is enabled. + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. + * @permission ohos.permission.GET_NETWORK_INFO + * @syscap SystemCapability.Communication.NetManager.Core + * @since 11 + * @version 1.0 + */ +int32_t OH_NetConn_IsDefaultNetMetered(int32_t *isMetered); + +/** + * @brief Obtains the connection properties of a data network. + * + * @param netHandle Pointer to the network handle that contains the network ID. + * @param prop Pointer to the connection properties. + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. + * @permission ohos.permission.GET_NETWORK_INFO + * @syscap SystemCapability.Communication.NetManager.Core + * @since 11 + * @version 1.0 + */ +int32_t OH_NetConn_GetConnectionProperties(NetConn_NetHandle *netHandle, NetConn_ConnectionProperties *prop); + +/** + * @brief Obtains the capabilities of a data network. + * + * @param netHandle Pointer to the network handle that contains the network ID. + * @param netCapacities Pointer to the network capabilities. + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. + * @permission ohos.permission.GET_NETWORK_INFO + * @syscap SystemCapability.Communication.NetManager.Core + * @since 11 + * @version 1.0 + */ +int32_t OH_NetConn_GetNetCapabilities(NetConn_NetHandle *netHandle, NetConn_NetCapabilities *netCapacities); + +/** + * @brief Obtains the default http proxy. + * + * @param httpProxy Pointer to the HTTP proxy. + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. + * @syscap SystemCapability.Communication.NetManager.Core + * @since 11 + * @version 1.0 + */ +int32_t OH_NetConn_GetDefaultHttpProxy(NetConn_HttpProxy *httpProxy); + /** * @brief Get DNS result with netId. * @@ -60,7 +145,7 @@ extern "C" { * @syscap SystemCapability.Communication.NetManager.Core * @since 11 * @version 1.0 -*/ + */ int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, struct addrinfo **res, int32_t netId); /** @@ -74,7 +159,7 @@ int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, st * @syscap SystemCapability.Communication.NetManager.Core * @since 11 * @version 1.0 -*/ + */ int32_t OH_NetConn_FreeDnsResult(struct addrinfo *res); /** @@ -89,7 +174,7 @@ int32_t OH_NetConn_FreeDnsResult(struct addrinfo *res); * @since 11 * @version 1.0 */ -int32_t OH_NetConn_GetAllNets(OH_NetConn_NetHandleList *netHandleList); +int32_t OH_NetConn_GetAllNets(NetConn_NetHandleList *netHandleList); /** * @brief Registers a custom DNS resolver. @@ -102,7 +187,7 @@ int32_t OH_NetConn_GetAllNets(OH_NetConn_NetHandleList *netHandleList); * @syscap SystemCapability.Communication.NetManager.Core * @since 11 * @version 1.0 -*/ + */ int32_t OHOS_NetConn_RegisterDnsResolver(OH_NetConn_CustomDnsResolver resolver); /** @@ -115,7 +200,7 @@ int32_t OHOS_NetConn_RegisterDnsResolver(OH_NetConn_CustomDnsResolver resolver); * @syscap SystemCapability.Communication.NetManager.Core * @since 11 * @version 1.0 -*/ + */ int32_t OHOS_NetConn_UnregisterDnsResolver(void); #ifdef __cplusplus @@ -123,4 +208,4 @@ int32_t OHOS_NetConn_UnregisterDnsResolver(void); #endif /** @} */ -#endif /* NATIVE_NET_CONN_API_H */ +#endif /* NATIVE_NET_CONN_API_H */ \ No newline at end of file diff --git a/network/netmanager/include/net_connection_type.h b/network/netmanager/include/net_connection_type.h index 17cfc24eb63eeb7b3c317edcb9e7a97ad3552379..2455ac8e26859e0beb876d92e6933c3fec16bc1c 100644 --- a/network/netmanager/include/net_connection_type.h +++ b/network/netmanager/include/net_connection_type.h @@ -1,41 +1,41 @@ /* -* Copyright (c) 2023 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef NATIVE_NET_CONN_TYPE_H #define NATIVE_NET_CONN_TYPE_H /** -* @addtogroup NetConnection -* @{ -* -* @brief Provides the data structures for the C APIs of the network connection module for network management. -* -* @since 11 -* @version 1.0 -*/ + * @addtogroup NetConnection + * @{ + * + * @brief Provides the data structures for the C APIs of the network connection module for network management. + * + * @since 11 + * @version 1.0 + */ /** -* @file net_connection_type.h -* @brief Defines the data structures for the C APIs of the network connection module. -* -* @library libnet_connection.so -* @syscap SystemCapability.Communication.NetManager.Core -* @since 11 -* @version 1.0 -* -*/ + * @file net_connection_type.h + * @brief Defines the data structures for the C APIs of the network connection module. + * + * @library libnet_connection.so + * @syscap SystemCapability.Communication.NetManager.Core + * @since 11 + * @version 1.0 + * + */ #include @@ -43,33 +43,178 @@ extern "C" { #endif -#define OH_NETCONN_MAX_NET_SIZE 32 +#define NETCONN_MAX_NET_SIZE 32 +#define NETCONN_MAX_BEARER_TYPE_SIZE 32 +#define NETCONN_MAX_CAP_SIZE 32 +#define NETCONN_MAX_ADDR_SIZE 32 +#define NETCONN_MAX_ROUTE_SIZE 64 +#define NETCONN_MAX_EXCLUSION_SIZE 256 +#define NETCONN_MAX_STR_LEN 256 /** -* @brief Defines the network handle. -* -* @since 11 -* @version 1.0 -*/ -typedef struct OH_NetConn_NetHandle { + * @brief Defines network capabilities. + * + * @since 11 + * @version 1.0 + */ +typedef enum NetConn_NetCap { + /** MMS */ + NETCONN_NET_CAPABILITY_MMS = 0, + /** Not Metered */ + NETCONN_NET_CAPABILITY_NOT_METERED = 11, + /** Internet */ + NETCONN_NET_CAPABILITY_INTERNET = 12, + /** Not VPN */ + NETCONN_NET_CAPABILITY_NOT_VPN = 15, + /** Validated */ + NETCONN_NET_CAPABILITY_VALIDATED = 16, +} NetConn_NetCap; + +/** + * @brief Defines network bearer types. + * + * @since 11 + * @version 1.0 + */ +typedef enum NetConn_NetBearerType { + /** Cellular network */ + NETCONN_BEARER_CELLULAR = 0, + /** WIFI */ + NETCONN_BEARER_WIFI = 1, + /** Ethernet */ + NETCONN_BEARER_ETHERNET = 3, +} NetConn_NetBearerType; + +/** + * @brief Defines the network handle. + * + * @since 11 + * @version 1.0 + */ +typedef struct NetConn_NetHandle { /** Network ID */ int32_t netId; -} OH_NetConn_NetHandle; +} NetConn_NetHandle; + +/** + * @brief Defines all network capabilities. + * + * @since 11 + * @version 1.0 + */ +typedef struct NetConn_NetCapabilities { + /** Uplink bandwidth */ + uint32_t linkUpBandwidthKbps; + /** Downlink bandwidth */ + uint32_t linkDownBandwidthKbps; + /** Network capability list */ + NetConn_NetCap netCaps[NETCONN_MAX_CAP_SIZE]; + /** Actual size of the network capability list */ + int32_t netCapsSize; + /** Bearer type list */ + NetConn_NetBearerType bearerTypes[NETCONN_MAX_BEARER_TYPE_SIZE]; + /** Actual size of the bearer type list */ + int32_t bearerTypesSize; +} NetConn_NetCapabilities; /** -* @brief Defines the network handle list. -* -* @since 11 -* @version 1.0 -*/ -typedef struct OH_NetConn_NetHandleList { + * @brief Defines the network address. + * + * @since 11 + * @version 1.0 + */ +typedef struct NetConn_NetAddr { + /** Network address family */ + uint8_t family; + /** Prefix length */ + uint8_t prefixlen; + /** Port number */ + uint8_t port; + /** Address */ + char address[NETCONN_MAX_STR_LEN]; +} NetConn_NetAddr; + +/** + * @brief Defines the route configuration information. + * + * @since 11 + * @version 1.0 + */ +typedef struct NetConn_Route { + /** Network interface */ + char iface[NETCONN_MAX_STR_LEN]; + /** Destination address */ + NetConn_NetAddr destination; + /** Gateway address */ + NetConn_NetAddr gateway; + /** Gateway exists or not */ + int32_t hasGateway; + /** Default route or not */ + int32_t isDefaultRoute; +} NetConn_Route; + +/** + * @brief Defines the proxy configuration information. + * + * @since 11 + * @version 1.0 + */ +typedef struct NetConn_HttpProxy { + /** Host name */ + char host[NETCONN_MAX_STR_LEN]; + /** Exclusion list of proxy servers */ + char exclusionList[NETCONN_MAX_EXCLUSION_SIZE][NETCONN_MAX_STR_LEN]; + /** Actual size of the exclusion list */ + int32_t exclusionListSize; + /** Port number */ + uint16_t port; +} NetConn_HttpProxy; + +/** + * @brief Defines the network connection properties. + * + * @since 11 + * @version 1.0 + */ +typedef struct NetConn_ConnectionProperties { + /** Network interface name */ + char ifaceName[NETCONN_MAX_STR_LEN]; + /** Domain name of the network connection */ + char domain[NETCONN_MAX_STR_LEN]; + /** TCP buffer size */ + char tcpBufferSizes[NETCONN_MAX_STR_LEN]; + /** MTU */ + uint16_t mtu; + /** Address list */ + NetConn_NetAddr netAddrList[NETCONN_MAX_ADDR_SIZE]; + /** Actual size of the address list */ + int32_t netAddrListSize; + /** DNS list */ + NetConn_NetAddr dnsList[NETCONN_MAX_ADDR_SIZE]; + /** Actual size of the DNS list */ + int32_t dnsListSize; + /** Route list */ + NetConn_Route routeList[NETCONN_MAX_ROUTE_SIZE]; + /** Actual size of the route list */ + int32_t routeListSize; + /** HTTP proxy information */ + NetConn_HttpProxy httpProxy; +} NetConn_ConnectionProperties; + +/** + * @brief Defines the network handle list. + * + * @since 11 + * @version 1.0 + */ +typedef struct NetConn_NetHandleList { /** Network handle list */ - OH_NetConn_NetHandle netHandles[OH_NETCONN_MAX_NET_SIZE]; + NetConn_NetHandle netHandles[NETCONN_MAX_NET_SIZE]; /** Actual size of the network handle list */ int32_t netHandleListSize; -} OH_NetConn_NetHandleList; +} NetConn_NetHandleList; -/* +/** * @brief Pointer to the custom DNS resolver. * * @param host The host name to query. @@ -82,7 +227,6 @@ typedef struct OH_NetConn_NetHandleList { */ typedef int (*OH_NetConn_CustomDnsResolver)(const char *host, const char *serv, const struct addrinfo *hint, struct addrinfo **res); - #ifdef __cplusplus } #endif diff --git a/network/netmanager/libnet_connection.ndk.json b/network/netmanager/libnet_connection.ndk.json index fdac6cc66ef22f54b6acd69066b87c89a410ff5e..284e7ad50a64bfd4aef2a7af5714dbde1d3fa673 100644 --- a/network/netmanager/libnet_connection.ndk.json +++ b/network/netmanager/libnet_connection.ndk.json @@ -11,6 +11,30 @@ "first_introduced": "11", "name": "OH_NetConn_GetAllNets" }, + { + "first_introduced": "11", + "name": "OH_NetConn_HasDefaultNet" + }, + { + "first_introduced": "11", + "name": "OH_NetConn_IsDefaultNetMetered" + }, + { + "first_introduced": "11", + "name": "OH_NetConn_GetDefaultNet" + }, + { + "first_introduced": "11", + "name": "OH_NetConn_GetConnectionProperties" + }, + { + "first_introduced": "11", + "name": "OH_NetConn_GetNetCapabilities" + }, + { + "first_introduced": "11", + "name": "OH_NetConn_GetDefaultHttpProxy" + }, { "first_introduced": "11", "name": "OHOS_NetConn_RegisterDnsResolver"