2 * Network Configuration Module
4 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
25 #include "network-state.h"
27 #include "clatd-handler.h"
29 #define CLATD_SERVICE "com.samsung.clatd"
30 #define CLATD_PATH "/com/samsung/clatd"
31 #define CLATD_INTERFACE "com.samsung.clatd.Control"
33 static gboolean g_is_running = FALSE;
35 static void __netconfig_clatd_async_callback(GObject *source_object,
36 GAsyncResult *res, gpointer user_data)
38 GDBusConnection *conn = NULL;
39 GVariant *reply = NULL;
41 DBG("__netconfig_clatd_async_callback");
43 conn = G_DBUS_CONNECTION(source_object);
44 reply = g_dbus_connection_call_finish(conn, res, &error);
46 ERR("Dbus error : %s", error->message);
49 int is_clat_enabled = -1;
50 g_variant_get(reply, "(i)", &is_clat_enabled);
52 if (is_clat_enabled == 0) {
54 } else if (is_clat_enabled == 1) {
55 INFO("already on going");
58 ERR("Failed to clat enable, %d", is_clat_enabled);
63 g_variant_unref(reply);
66 int netconfig_clatd_enable(void)
69 GVariant *params = NULL;
70 GVariantBuilder *builder = NULL;
72 struct clatd_ctrl_hint hint = {0 ,};
73 char ns_buff[256] = {0, };
76 INFO("clatd is already ENABLED");
80 if (!netconfig_get_connected_cellular_internet_ipv6only_profile(&hint)) {
81 ERR("Failed to get cellular profile");
85 const char *if_name = netconfig_get_default_ifname();
86 if (if_name == NULL) {
88 for (idx = 0; idx < MAX_DNS; idx++)
89 g_free(hint.nameserver[idx]);
91 ERR("There is no interface name");
94 DBG("if_name : %s", if_name);
97 builder = g_variant_builder_new(G_VARIANT_TYPE ("a{is}"));
99 g_variant_builder_add(builder, "{is}", 'i', if_name);
101 // nameserver addresses
102 if (hint.nameserver[0] != NULL || hint.nameserver[1] != NULL) {
103 g_snprintf(ns_buff, 256, "%s;%s",
104 ((hint.nameserver[0] != NULL) ? hint.nameserver[0] : "NULL"),
105 ((hint.nameserver[1] != NULL) ? hint.nameserver[1] : "NULL"));
107 g_variant_builder_add(builder, "{is}", 'd', ns_buff);
109 params = g_variant_builder_end(builder);
110 g_variant_builder_unref(builder);
112 rv = netconfig_invoke_dbus_method_nonblock(CLATD_SERVICE, CLATD_PATH,
113 CLATD_INTERFACE, "Start", g_variant_new("(@a{is})", params), __netconfig_clatd_async_callback);
116 DBG("Failed to dbus call");
117 g_variant_unref(params);
120 for (idx = 0; idx < MAX_DNS; idx++)
121 g_free(hint.nameserver[idx]);
126 DBG("clatd enabled[%d]", g_is_running);
128 for (idx = 0; idx < MAX_DNS; idx++)
129 g_free(hint.nameserver[idx]);
133 int netconfig_clatd_disable(void)
139 ERR("clatd is already DISABLED");
143 rv = netconfig_invoke_dbus_method_nonblock(CLATD_SERVICE, CLATD_PATH,
144 CLATD_INTERFACE, "Stop", NULL, NULL);
145 g_is_running = FALSE;
146 DBG("clatd disabled[%d]", g_is_running);
148 DBG("Failed to dbus call");