Add a dbus method for DHCP status 99/293799/1
authorJaehyun Kim <jeik01.kim@samsung.com>
Mon, 5 Jun 2023 07:19:22 +0000 (16:19 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Mon, 5 Jun 2023 07:19:22 +0000 (16:19 +0900)
Change-Id: Ibb590f234c4db807add7cd5edf7a83c081579618
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
src/connman.h
src/manager.c
src/network.c

index 902dd3e..db51e04 100755 (executable)
@@ -685,6 +685,7 @@ const char *__connman_network_get_ident(struct connman_network *network);
 bool __connman_network_get_weakness(struct connman_network *network);
 bool __connman_network_native_autoconnect(struct connman_network *network);
 #if defined TIZEN_EXT
+char *__connman_network_get_dhcp_status(const char *ifname);
 dbus_bool_t __connman_network_notify_dhcp_changed(const char *key, const char *val);
 bool connman_network_get_psk_sha256(struct connman_network *network);
 void connman_network_set_psk_sha256(struct connman_network *network, bool is_psk_sha256);
index 0000f78..b3f9ff2 100755 (executable)
@@ -266,6 +266,29 @@ static DBusMessage *get_connected_service(DBusConnection *conn,
 
        return connman_service_create_dbus_service_reply(msg, service);
 }
+
+static DBusMessage *get_dhcp_status(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+       const char *ifname;
+       const char *dhcp_status;
+       DBusMessage *reply;
+       DBusMessageIter iter;
+
+       dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ifname, DBUS_TYPE_INVALID);
+       dhcp_status = __connman_network_get_dhcp_status(ifname);
+
+       reply = dbus_message_new_method_return(msg);
+       if (!reply)
+               return NULL;
+
+       if (!dhcp_status)
+               dhcp_status = "Unknown";
+
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &dhcp_status);
+
+       return reply;
+}
 #endif
 
 #if defined TIZEN_EXT_INS
@@ -751,6 +774,10 @@ static const GDBusMethodTable manager_methods[] = {
                        GDBUS_ARGS({ "ifname", "s" }),
                        GDBUS_ARGS({ "service", "oa{sv}" }),
                        get_connected_service) },
+       { GDBUS_METHOD("GetDhcpStatus",
+                       GDBUS_ARGS({ "ifname", "s" }),
+                       GDBUS_ARGS({ "status", "s" }),
+                       get_dhcp_status) },
 #endif
 #if defined TIZEN_EXT_INS
        { GDBUS_METHOD("GetINS",
index db0e72e..580f859 100755 (executable)
@@ -62,6 +62,8 @@ static DBusConnection *connection;
 static unsigned char invalid_bssid[WIFI_BSSID_LEN_MAX] = {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 };
+
+static GHashTable *dhcp_status_list = NULL;
 #endif
 
 static GSList *network_list = NULL;
@@ -2108,6 +2110,28 @@ out:
 }
 
 #if defined TIZEN_EXT
+char *__connman_network_get_dhcp_status(const char *ifname)
+{
+       char *status = NULL;
+
+       if (!ifname)
+               return NULL;
+
+       status = g_hash_table_lookup(dhcp_status_list, ifname);
+       DBG("ifname: %s, DHCP status: %s", ifname, status);
+
+       return status;
+}
+
+static void __connman_network_update_dhcp_status(
+                               const char *ifname, const char *status)
+{
+       if (!ifname || !status)
+               return;
+
+       g_hash_table_replace(dhcp_status_list, g_strdup(ifname), g_strdup(status));
+}
+
 dbus_bool_t __connman_network_notify_dhcp_changed(const char *key, const char *val)
 {
        DBusMessage *signal;
@@ -2136,6 +2160,8 @@ dbus_bool_t __connman_network_notify_dhcp_changed(const char *key, const char *v
 
        dbus_message_unref(signal);
 
+       __connman_network_update_dhcp_status(val, key);
+
        return result;
 }
 #endif
@@ -3320,6 +3346,8 @@ int __connman_network_init(void)
        DBG("");
 #if defined TIZEN_EXT
        connection = connman_dbus_get_connection();
+       dhcp_status_list = g_hash_table_new_full(g_str_hash,
+                       g_str_equal, g_free, g_free);
 #endif
 
        return 0;
@@ -3330,5 +3358,7 @@ void __connman_network_cleanup(void)
        DBG("");
 #if defined TIZEN_EXT
        dbus_connection_unref(connection);
+       if (dhcp_status_list)
+               g_hash_table_destroy(dhcp_status_list);
 #endif
 }