From 334f0014d495183f6d9ef9c1e12a51d697e8b4ff Mon Sep 17 00:00:00 2001 From: Manika Shrivastava Date: Wed, 14 Jun 2023 16:28:39 +0530 Subject: [PATCH] Add APIs for setting and clearing NTP server. Change-Id: Iac057baa88d19cde7c473f3d525d188009934dbc Signed-off-by: Manika Shrivastava --- include/net_connection_private.h | 2 ++ src/connection.c | 50 ++++++++++++++++++++++++++++++++++++++++ src/libnetwork.c | 32 +++++++++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/include/net_connection_private.h b/include/net_connection_private.h index 1b2c74f..9194476 100755 --- a/include/net_connection_private.h +++ b/include/net_connection_private.h @@ -219,6 +219,8 @@ int _connection_libnet_stop_tcpdump(connection_handle_s *conn_handle); int _connection_libnet_get_tcpdump_state(connection_handle_s *conn_handle, gboolean *tcpdump_state); int _connection_libnet_get_clock_updated(connection_handle_s *conn_handle, bool *updated); +int _connection_libnet_set_ntp_server(connection_handle_s *conn_handle, const char *ntp_server); +int _connection_libnet_clear_ntp_server(connection_handle_s *conn_handle); void _connection_lock(void); void _connection_unlock(void); diff --git a/src/connection.c b/src/connection.c index 0d33571..1b444cd 100755 --- a/src/connection.c +++ b/src/connection.c @@ -1963,3 +1963,53 @@ EXPORT_API int connection_clock_is_updated(connection_h connection, bool *update return CONNECTION_ERROR_NONE; } + +EXPORT_API int connection_set_ntp_server(connection_h connection, const char *ntp_server) +{ + CONN_LOCK; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE); + + if (!(__connection_check_handle_validity(connection)) || ntp_server == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + CONN_UNLOCK; + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + int rv = _connection_libnet_set_ntp_server(connection, ntp_server); + + if (rv != CONNECTION_ERROR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "Fail to set NTP server[%d]", rv); //LCOV_EXCL_LINE + CONN_UNLOCK; //LCOV_EXCL_LINE + return rv; //LCOV_EXCL_LINE + } + + CONN_UNLOCK; + + return CONNECTION_ERROR_NONE; +} + +EXPORT_API int connection_clear_ntp_server(connection_h connection) +{ + CONN_LOCK; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE); + + if (!(__connection_check_handle_validity(connection))) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + CONN_UNLOCK; + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + int rv = _connection_libnet_clear_ntp_server(connection); + + if (rv != CONNECTION_ERROR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "Fail to clear NTP server[%d]", rv); //LCOV_EXCL_LINE + CONN_UNLOCK; //LCOV_EXCL_LINE + return rv; //LCOV_EXCL_LINE + } + + CONN_UNLOCK; + + return CONNECTION_ERROR_NONE; +} diff --git a/src/libnetwork.c b/src/libnetwork.c index 5ed4ddb..f235fc6 100755 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -1824,6 +1824,38 @@ int _connection_libnet_get_clock_updated(connection_handle_s *conn_handle, bool return CONNECTION_ERROR_NONE; } +int _connection_libnet_set_ntp_server(connection_handle_s *conn_handle, const char *ntp_server) +{ + int rv = 0; + + rv = net_set_ntp_server(conn_handle->network_info_handle, ntp_server); + if (rv == NET_ERR_ACCESS_DENIED) { + CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE + return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE + } else if (rv != NET_ERR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "Failed to set NTP server[%d]", rv); //LCOV_EXCL_LINE + return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + } + + return CONNECTION_ERROR_NONE; +} + +int _connection_libnet_clear_ntp_server(connection_handle_s *conn_handle) +{ + int rv = 0; + + rv = net_clear_ntp_server(conn_handle->network_info_handle); + if (rv == NET_ERR_ACCESS_DENIED) { + CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE + return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE + } else if (rv != NET_ERR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "Failed to clear NTP server[%d]", rv); //LCOV_EXCL_LINE + return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + } + + return CONNECTION_ERROR_NONE; +} + void _connection_lock(void) { if (g_conn_thread_mutex_ref == 0) -- 2.7.4