From 9013fc641bd17d3ec1004028081d6bbc2541858f Mon Sep 17 00:00:00 2001 From: liuxingxingxing <19862122810@163.com> Date: Tue, 5 Dec 2023 10:00:12 +0800 Subject: [PATCH] Add interfaces to NDK Signed-off-by: liuxingxingxing <19862122810@163.com> --- network/netmanager/include/net_connection.h | 83 +++++++++- .../netmanager/include/net_connection_type.h | 149 +++++++++++++++++- 2 files changed, 229 insertions(+), 3 deletions(-) diff --git a/network/netmanager/include/net_connection.h b/network/netmanager/include/net_connection.h index 02b937057de..9bdaf50ae5a 100644 --- a/network/netmanager/include/net_connection.h +++ b/network/netmanager/include/net_connection.h @@ -45,6 +45,85 @@ extern "C" { #endif +/** + * @brief Query whether there is a data network activated by default + * + * @param hasDefaultNet Is there a default network + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. + * @permission ohos.permission.GET_NETWORK_INFO + * @since 11 + * @version 1.0 +*/ +int32_t OH_NetConn_HasDefaultNet(int32_t *hasDefaultNet); + +/** + * @brief Get the activated default data network + * + * @param netHandle Store 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 + * @since 11 + * @version 1.0 + */ +int32_t OH_NetConn_GetDefaultNet(OH_NetConn_NetHandle *netHandle); + +/** + * @brief Check whether the default data network records traffic + * + * @param isMetered Activate now + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. + * @permission ohos.permission.GET_NETWORK_INFO + * @since 11 + * @version 1.0 + */ +int32_t OH_NetConn_IsDefaultNetMetered(int32_t *isMetered); + +/** + * @brief Query the link information of a data network + * + * @param netHandle Store network ID + * @param info Store link information + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. + * @permission ohos.permission.GET_NETWORK_INFO + * @since 11 + * @version 1.0 + */ +int32_t OH_NetConn_GetConnectionProperties(OH_NetConn_NetHandle *netHandle, NetConn_NetLinkInfo *info); + +/** + * @brief Query the capability set of a network + * + * @param netHandle Store network ID + * @param netAllCapacities storage capability set + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. + * @permission ohos.permission.GET_NETWORK_INFO + * @since 11 + * @version 1.0 + */ +int32_t OH_NetConn_GetNetCapabilities(OH_NetConn_NetHandle *netHandle, NetConn_NetAllCapabilities *netAllCapacities); + +/** + * @brief Query the default network proxy + * + * @param httpProxy Store proxy configuration information + * @return 0 - Success. 201 - Missing permissions. + * 401 - Parameter error. 2100002 - Unable to connect to service. + * 2100003 - Internal error. + * @since 11 + * @version 1.0 + */ +int32_t OH_NetConn_GetDefaultHttpProxy(NetConn_HttpProxy *httpProxy); + /** * @brief Get DNS result with netId. * @@ -61,7 +140,7 @@ extern "C" { * @since 11 * @version 1.0 */ -int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, struct addrinfo **res, int32_t netId); +int32_t NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, struct addrinfo **res, int32_t netId); /** * @brief Free DNS result. @@ -123,4 +202,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 17cfc24eb63..259ed570c34 100644 --- a/network/netmanager/include/net_connection_type.h +++ b/network/netmanager/include/net_connection_type.h @@ -44,6 +44,48 @@ extern "C" { #endif #define OH_NETCONN_MAX_NET_SIZE 32 +#define OH_NETCONN_MAX_NET_SIZE 32 +#define OH_NETCONN_MAX_BEAR_TYPE_SIZE 32 +#define OH_NETCONN_MAX_CAP_SIZE 32 +#define OH_NETCONN_MAX_ADDR_SIZE 32 +#define OH_NETCONN_MAX_ROUTE_SIZE 64 +#define OH_NETCONN_MAX_EXCLUSION_SIZE 256 +#define OH_NETCONN_MAX_STR_LEN 256 + +/** +* @brief Defines network capabilities. +* +* @since 10 +* @version 1.0 +*/ + +typedef enum NetConn_NetCap { + /* MMS */ + OH_NETCONN_NET_CAPABILITY_MMS = 0, + /* Not Metered */ + OH_NETCONN_NET_CAPABILITY_NOT_METERED = 11, + /* Internet */ + OH_NETCONN_NET_CAPABILITY_INTERNET = 12, + /* Not VPN */ + OH_NETCONN_NET_CAPABILITY_NOT_VPN = 15, + /* Validated */ + OH_NETCONN_NET_CAPABILITY_VALIDATED = 16, +} NetConn_NetCap; + +/** + * @brief Defines network bearer types. + * + * @since 11 + * @version 1.0 + */ +typedef enum NetConn_NetBearType { + /** Cellular network */ + OH_NETCONN_BEARER_CELLULAR = 0, + /** WIFI */ + OH_NETCONN_BEARER_WIFI = 1, + /** Ethernet */ + OH_NETCONN_BEARER_ETHERNET = 3, +} NetConn_NetBearType; /** * @brief Defines the network handle. @@ -56,6 +98,111 @@ typedef struct OH_NetConn_NetHandle { int32_t netId; } OH_NetConn_NetHandle; +/** + * @brief Defines all network capabilities. + * + * @since 11 + * @version 1.0 + */ +typedef struct NetConn_NetAllCapabilities { + /** Uplink bandwidth */ + uint32_t linkUpBandwidthKbps; + /** Downlink bandwidth */ + uint32_t linkDownBandwidthKbps; + /** Network capability list */ + NetConn_NetCap netCaps[OH_NETCONN_MAX_CAP_SIZE]; + /** Actual size of the network capability list */ + int32_t netCapsSize; + /** Bearer type list */ + NetConn_NetBearType bearerTypes[OH_NETCONN_MAX_BEAR_TYPE_SIZE]; + /** Actual size of the bearer type list */ + int32_t bearerTypesSize; +} NetConn_NetAllCapabilities; + +/** + * @brief Defines the network address. + * + * @since 11 + * @version 1.0 + */ +typedef struct NetConn_INetAddr { + /** Network address family */ + uint8_t family; + /** Prefix length */ + uint8_t prefixlen; + /** Port number */ + uint8_t port; + /** Address */ + char address[OH_NETCONN_MAX_STR_LEN]; +} NetConn_INetAddr; + +/** + * @brief Defines the route configuration information. + * + * @since 11 + * @version 1.0 + */ +typedef struct NetConn_Route { + /** Network interface */ + char iface[OH_NETCONN_MAX_STR_LEN]; + /** Destination address */ + NetConn_INetAddr destination; + /** Gateway address */ + NetConn_INetAddr 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[OH_NETCONN_MAX_STR_LEN]; + /** Exclusion list of proxy servers */ + char exclusionList[OH_NETCONN_MAX_EXCLUSION_SIZE][OH_NETCONN_MAX_STR_LEN]; + /** Actual size of the exclusion list */ + int32_t exclusionListSize; + /** Port number */ + uint16_t port; +} NetConn_HttpProxy; + +/** + * @brief Defines the network link information. + * + * @since 11 + * @version 1.0 + */ +typedef struct NetConn_NetLinkInfo { + /** Network interface name */ + char ifaceName[OH_NETCONN_MAX_STR_LEN]; + /** Domain name of the network connection */ + char domain[OH_NETCONN_MAX_STR_LEN]; + /** TCP buffer size */ + char tcpBufferSizes[OH_NETCONN_MAX_STR_LEN]; + /** MTU */ + uint16_t mtu; + /** Address list */ + NetConn_INetAddr netAddrList[OH_NETCONN_MAX_ADDR_SIZE]; + /** Actual size of the address list */ + int32_t netAddrListSize; + /** DNS list */ + NetConn_INetAddr dnsList[OH_NETCONN_MAX_ADDR_SIZE]; + /** Actual size of the DNS list */ + int32_t dnsListSize; + /** Route list */ + NetConn_Route routeList[OH_NETCONN_MAX_ROUTE_SIZE]; + /** Actual size of the route list */ + int32_t routeListSize; + /** HTTP proxy information */ + NetConn_HttpProxy httpProxy; +} NetConn_NetLinkInfo; + /** * @brief Defines the network handle list. * @@ -81,7 +228,7 @@ typedef struct OH_NetConn_NetHandleList { * @version 1.0 */ typedef int (*OH_NetConn_CustomDnsResolver)(const char *host, const char *serv, - const struct addrinfo *hint, struct addrinfo **res); + const struct addrinfo *hint, struct addrinfo **res); #ifdef __cplusplus } -- Gitee