From: Anjali Nijhara Date: Tue, 20 Jun 2023 05:11:01 +0000 (+0530) Subject: Add new APIs for NTP Server details X-Git-Tag: accepted/tizen/7.0/unified/20230622.035131^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Faccepted%2Ftizen_7.0_unified;p=platform%2Fcore%2Fapi%2Fconnection.git Add new APIs for NTP Server details Change-Id: I824ad75b2920e44ceb673d9c6604fed7a036c1b1 --- diff --git a/include/connection_extension.h b/include/connection_extension.h index 5a76443..667c969 100755 --- a/include/connection_extension.h +++ b/include/connection_extension.h @@ -693,6 +693,48 @@ int connection_profile_save_ethernet_eap_config(connection_h connection, */ int connection_clock_is_updated(connection_h connection, bool *updated); +/** + * @brief Sets NTP server. + * @since_tizen 8.0 + * @param[in] connection The connection handle + * @param[in] ntp_server requested NTP server IP/URL + * @return 0 on success, otherwise a negative error value + * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_INVALID_OPERATION Invalid operation + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_PERMISSION_DENIED Permission denied + * @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported + */ +int connection_set_ntp_server(connection_h connection, const char *ntp_server); + +/** + * @brief Get NTP server url. + * @since_tizen 8.0 + * @remarks You must release @a ntp_server using free(). + * @param[in] connection The connection handle + * @param[out] ntp_server The IP/URL of NTP Server + * @return 0 on success, otherwise a negative error value + * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_INVALID_OPERATION Invalid operation + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_PERMISSION_DENIED Permission denied + * @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported + */ +int connection_get_ntp_server(connection_h connection, char **ntp_server); + +/** + * @brief Clear NTP server. + * @since_tizen 8.0 + * @param[in] connection The connection handle + * @return 0 on success, otherwise a negative error value + * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_INVALID_OPERATION Invalid operation + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_PERMISSION_DENIED Permission denied + * @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported + */ +int connection_clear_ntp_server(connection_h connection); + /** * @} */ diff --git a/include/net_connection_private.h b/include/net_connection_private.h index 1b2c74f..5073eaa 100755 --- a/include/net_connection_private.h +++ b/include/net_connection_private.h @@ -220,6 +220,10 @@ 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_get_ntp_server(connection_handle_s *conn_handle, char **ntp_server); +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..a0cb92b 100755 --- a/src/connection.c +++ b/src/connection.c @@ -1963,3 +1963,87 @@ EXPORT_API int connection_clock_is_updated(connection_h connection, bool *update return CONNECTION_ERROR_NONE; } + + +EXPORT_API int connection_get_ntp_server(connection_h connection, char **ntp_server) +{ + CONN_LOCK; + + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + + if (ntp_server == NULL || !(_connection_check_handle_validity(connection))) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE + CONN_UNLOCK; //LCOV_EXCL_LINE + return CONNECTION_ERROR_INVALID_PARAMETER;//LCOV_EXCL_LINE + } + + char *server = NULL; + + int rv = _connection_libnet_get_ntp_server(connection, &server); + + if (rv != CONNECTION_ERROR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "Fail to get ntp server [%d]", rv); //LCOV_EXCL_LINE + CONN_UNLOCK; //LCOV_EXCL_LINE + return rv; //LCOV_EXCL_LINE + } + + if (server) { + *ntp_server = strdup(server); + g_free(server); + } + + CONNECTION_LOG(CONNECTION_INFO, "NTP SERVER: %s", *ntp_server); + CONN_UNLOCK; + + 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..92f25ce 100755 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -1824,6 +1824,54 @@ int _connection_libnet_get_clock_updated(connection_handle_s *conn_handle, bool return CONNECTION_ERROR_NONE; } +int _connection_libnet_get_ntp_server(connection_handle_s *conn_handle, char **ntp_server) +{ + int rv =0; + + rv = net_get_ntp_server_info(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 get NTP Server [%d]", rv); //LCOV_EXCL_LINE + return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + } + + 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)