Add APIs for NTP Server Details 41/294541/1 accepted/tizen_7.0_unified tizen_7.0 accepted/tizen/7.0/unified/20230622.035129
authorAnjali Nijhara <a.nijhara@samsung.com>
Wed, 14 Jun 2023 08:45:28 +0000 (14:15 +0530)
committerAnjali Nijhara <a.nijhara@samsung.com>
Tue, 20 Jun 2023 08:37:12 +0000 (14:07 +0530)
Change-Id: I533729b5f283d444c2fc12f3c19722ea7c26d5ad

include/common/network-cm-intf.h
include/internal/network-dbus-request.h
include/internal/network-internal.h
src/network-cm-intf.c
src/network-dbus-request.c
src/network-profile-intf.c

index 679bac8..2a7b5ad 100755 (executable)
@@ -834,10 +834,38 @@ int net_get_clock_update_info(void *handle, bool *state);
 /**
  * \brief      This API is only for Connection CAPI. Don't use this.
  *
- * \param[in] enable           Enable EAP over Ethernet network.
- * \param[in] pofilename       Profile name of ethernet.
+ * \param[in] handle           The network info handle.
+ * \param[out] ntp_server      IP/URL of NTP Server
+ *
+ ******************************************************************************************/
+int net_get_ntp_server_info(void * handle, char **ntp_server);
+
+/**
+ * \brief       This API is only for Connection CAPI. Don't use this.
+ *
+ * \param[in]   handle       The network info handle.
+ * \param[in]  ntp_server   The IP/URL of NTP Server.
  *
  ******************************************************************************************/
+int net_set_ntp_server(void *handle, const char *ntp_server);
+
+/**
+ * \brief      This API is only for Connection CAPI. Don't use this.
+ *
+ * \param[in]   handle    The network info handle.
+ *
+ ******************************************************************************************/
+int net_clear_ntp_server(void *handle);
+
+/**
+ * \brief      This API is only for Connection CAPI. Don't use this.
+ *
+ * \param[in] enable            Enable EAP over Ethernet network.
+ * \param[in] pofilename        Profile name of ethernet.
+ *
+ ******************************************************************************************/
+
+
 int net_ethernet_eap_enable(gboolean enable, const char *profilename);
 
 /**
index dac69ad..6e3a4a7 100755 (executable)
@@ -96,6 +96,9 @@ typedef struct {
 int _net_dbus_get_ethernet_cable_state(network_info_t *network_info, int *state);
 int _net_dbus_get_metered_state(network_info_t *network_info, int *state);
 int _net_dbus_get_clock_updated(network_info_t *network_info, bool *state);
+int _net_dbus_get_ntp_server(network_info_t *network_info, char ** ntp_server);
+int _net_dbus_set_ntp_server(network_info_t *network_info, const char* ntp_server);
+int _net_dbus_clear_ntp_server(network_info_t *network_info);
 int _net_dbus_get_preferred_ipv6_address(const char *profilename, char **address);
 int _net_dbus_set_agent_passphrase_and_connect(network_info_t *network_info,
                const char *passphrase, const char *profilename);
index 7f2497c..aa0378f 100755 (executable)
@@ -67,15 +67,17 @@ extern "C" {
 #define NETCONFIG_NETWORK_INTERFACE            NETCONFIG_SERVICE ".network"
 #define NETCONFIG_TCPDUMP_INTERFACE            NETCONFIG_SERVICE ".tcpdump"
 #define NETCONFIG_WIFI_INTERFACE               NETCONFIG_SERVICE ".wifi"
-#define NETCONFIG_STATISTICS_INTERFACE NETCONFIG_SERVICE ".network_statistics"
+#define NETCONFIG_STATISTICS_INTERFACE         NETCONFIG_SERVICE ".network_statistics"
 #define NETCONFIG_MPTCP_INTERFACE              NETCONFIG_SERVICE ".mptcp"
 #define NETCONFIG_ETHERNET_INTERFACE           NETCONFIG_SERVICE ".ethernet"
+#define NETCONFIG_CLOCK_INTERFACE              NETCONFIG_SERVICE ".clock"
 
 #define NETCONFIG_NETWORK_PATH                 "/net/netconfig/network"
 #define NETCONFIG_WIFI_PATH                            "/net/netconfig/wifi"
 #define NETCONFIG_STATISTICS_PATH              "/net/netconfig/network_statistics"
 #define NETCONFIG_MPTCP_PATH                   "/net/netconfig/mptcp"
 #define NETCONFIG_ETHERNET_PATH                        "/net/netconfig/ethernet"
+#define NETCONFIG_CLOCK_PATH                   "/net/netconfig/clock"
 
 #define NETCONFIG_TV_PROFILE_INTERFACE NETCONFIG_SERVICE ".tv_profile"
 
@@ -225,6 +227,7 @@ int _net_extract_service_info(network_info_t *network_info,
                const char *ProfileName, GVariantIter *iter,
                net_profile_info_t *prof_info);
 void _net_extract_clock_updated(GVariantIter *iter, bool *state);
+void _net_extract_ntp_server(GVariantIter *iter, char **ntp_server);
 
 int _net_dbus_create_gdbus_call(network_info_t *network_info);
 void _net_dbus_close_gdbus_call(network_info_t *network_info);
index 44a801e..b1dad78 100755 (executable)
@@ -1035,6 +1035,52 @@ EXPORT_API int net_get_clock_update_info(void *handle, bool *state)
        return Error;
 }
 
+EXPORT_API int net_get_ntp_server_info(void * handle, char **ntp_server)
+{
+       __NETWORK_FUNC_ENTER__;
+       net_err_t Error = NET_ERR_NONE;
+       network_info_t *network_info = (network_info_t *)handle;
+
+       Error = _net_dbus_get_ntp_server(network_info, ntp_server);
+
+       if (Error != NET_ERR_NONE)
+               NETWORK_LOG(NETWORK_ERROR, "net_get_ntp_server_info failed\n");
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
+EXPORT_API int net_set_ntp_server(void *handle, const char *ntp_server)
+{
+       __NETWORK_FUNC_ENTER__;
+       net_err_t Error = NET_ERR_NONE;
+       network_info_t *network_info = (network_info_t *)handle;
+
+       Error = _net_dbus_set_ntp_server(network_info, ntp_server);
+
+       if (Error != NET_ERR_NONE)
+               NETWORK_LOG(NETWORK_ERROR, "net_set_ntp_server failed\n");
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
+EXPORT_API int net_clear_ntp_server(void *handle)
+{
+       __NETWORK_FUNC_ENTER__;
+       net_err_t Error = NET_ERR_NONE;
+       network_info_t *network_info = (network_info_t *)handle;
+
+       Error = _net_dbus_clear_ntp_server(network_info);
+
+       if (Error != NET_ERR_NONE)
+               NETWORK_LOG(NETWORK_ERROR, "net_clear_ntp_server failed\n");
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
+
 EXPORT_API void net_set_cs_tid(int tid, void *handle)
 {
        network_info_t *network_info = (network_info_t *)handle;
index b52b455..37bb34c 100755 (executable)
@@ -1218,6 +1218,99 @@ int _net_dbus_get_clock_updated(network_info_t *network_info, bool *state)
        return Error;
 }
 
+int _net_dbus_get_ntp_server(network_info_t *network_info, char ** ntp_server)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_t Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+       GVariantIter *servers = NULL;
+
+       if (ntp_server == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_INVALID_PARAM;
+       }
+
+       message = _net_invoke_dbus_method(network_info, CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
+                       CONNMAN_CLOCK_INTERFACE, "GetProperties", NULL, &Error);
+
+       /* LCOV_EXCL_START */
+       if (message == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to get NTP Server information\n");
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
+       /* LCOV_EXCL_STOP */
+
+       g_variant_get(message, "(a{sv})", &servers);
+       _net_extract_ntp_server(servers, ntp_server);
+
+       g_variant_iter_free(servers);
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
+int _net_dbus_set_ntp_server(network_info_t *network_info, const char *ntp_server)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_t Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+
+       if (ntp_server == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter\n");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_INVALID_PARAM;
+       }
+
+       params = g_variant_new("(s)", ntp_server);
+       message = _net_invoke_dbus_method(network_info, NETCONFIG_SERVICE, NETCONFIG_CLOCK_PATH,
+                       NETCONFIG_CLOCK_INTERFACE, "SetNtpServer", params, &Error);
+
+       /* LCOV_EXCL_START */
+       if (message == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to set NTP server\n");
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
+       /* LCOV_EXCL_STOP */
+
+       NETWORK_LOG(NETWORK_LOW, "Set NTP Server [%s]\n", ntp_server);
+
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
+int _net_dbus_clear_ntp_server(network_info_t *network_info)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_t Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+
+       message = _net_invoke_dbus_method(network_info, NETCONFIG_SERVICE, NETCONFIG_CLOCK_PATH,
+                       NETCONFIG_CLOCK_INTERFACE, "UnsetNtpServer", NULL, &Error);
+
+       /* LCOV_EXCL_START */
+       if (message == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to clear NTP server\n");
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
+       /* LCOV_EXCL_STOP */
+
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 /* LCOV_EXCL_START */
 int _net_dbus_get_preferred_ipv6_address(const char *profilename, char **address)
 {
index 120edae..02614fd 100755 (executable)
@@ -1934,6 +1934,38 @@ void _net_extract_clock_updated(GVariantIter *iter, bool *state)
        __NETWORK_FUNC_EXIT__;
 }
 
+void _net_extract_ntp_server(GVariantIter *iter, char **ntp_server)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       gchar *key = NULL;
+       GVariant *value = NULL;
+       gchar *server = NULL;
+
+       while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+
+               if (g_strcmp0(key, "Timeservers") == 0) {
+                       GVariantIter *iter_sub = NULL;
+
+                       g_variant_get(value, "as", &iter_sub);
+                       if (!g_variant_iter_loop(iter_sub, "s", &server))
+                               NETWORK_LOG(NETWORK_ERROR, "No NTP Server");
+
+                       g_variant_iter_free(iter_sub);
+
+                       if (server) {
+                               *ntp_server = g_strdup(server);
+                               g_free(server);
+                       }
+
+                       g_variant_unref(value);
+                       g_free(key);
+                       break;
+               }
+       }
+
+       __NETWORK_FUNC_EXIT__;
+}
 
 static int __net_get_mesh_peers(network_info_t *network_info,
                const char *profile_name, net_profile_info_t *prof_info)