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 static gboolean g_is_running = FALSE;
31 static void __netconfig_clatd_async_callback(GObject *source_object,
32 GAsyncResult *res, gpointer user_data)
34 GDBusConnection *conn = NULL;
35 GVariant *reply = NULL;
37 DBG("__netconfig_clatd_async_callback");
39 conn = G_DBUS_CONNECTION(source_object);
40 reply = g_dbus_connection_call_finish(conn, res, &error);
42 ERR("Dbus error : %s", error->message);
45 int is_clat_enabled = -1;
46 g_variant_get(reply, "(i)", &is_clat_enabled);
48 if (is_clat_enabled == 0) {
50 } else if (is_clat_enabled == 1) {
51 INFO("already on going");
54 ERR("Failed to clat enable, %d", is_clat_enabled);
59 g_variant_unref(reply);
62 int netconfig_clatd_enable(void)
65 GVariant *params = NULL;
66 GVariantBuilder *builder = NULL;
68 struct clatd_ctrl_hint hint = {0 ,};
69 char ns_buff[256] = {0, };
72 INFO("clatd is already ENABLED");
76 if (!netconfig_get_connected_cellular_internet_ipv6only_profile(&hint)) {
77 ERR("Failed to get cellular profile");
81 const char *if_name = netconfig_get_default_ifname();
82 if (if_name == NULL) {
84 for (idx = 0; idx < MAX_DNS; idx++)
85 g_free(hint.nameserver[idx]);
87 ERR("There is no interface name");
90 DBG("if_name : %s", if_name);
93 builder = g_variant_builder_new(G_VARIANT_TYPE ("a{is}"));
95 g_variant_builder_add(builder, "{is}", 'i', if_name);
97 // nameserver addresses
98 if (hint.nameserver[0] != NULL || hint.nameserver[1] != NULL) {
99 g_snprintf(ns_buff, 256, "%s;%s",
100 ((hint.nameserver[0] != NULL) ? hint.nameserver[0] : "NULL"),
101 ((hint.nameserver[1] != NULL) ? hint.nameserver[1] : "NULL"));
103 g_variant_builder_add(builder, "{is}", 'd', ns_buff);
105 params = g_variant_builder_end(builder);
106 g_variant_builder_unref(builder);
108 rv = netconfig_invoke_dbus_method_nonblock(CLATD_SERVICE, CLATD_PATH,
109 CLATD_INTERFACE, "Start", g_variant_new("(@a{is})", params),
110 __netconfig_clatd_async_callback, NULL);
113 DBG("Failed to dbus call");
114 g_variant_unref(params);
117 for (idx = 0; idx < MAX_DNS; idx++)
118 g_free(hint.nameserver[idx]);
123 DBG("clatd enabled[%d]", g_is_running);
125 for (idx = 0; idx < MAX_DNS; idx++)
126 g_free(hint.nameserver[idx]);
130 int netconfig_clatd_disable(void)
136 ERR("clatd is already DISABLED");
140 rv = netconfig_invoke_dbus_method_nonblock(CLATD_SERVICE, CLATD_PATH,
141 CLATD_INTERFACE, "Stop", NULL, NULL, NULL);
142 g_is_running = FALSE;
143 DBG("clatd disabled[%d]", g_is_running);
145 DBG("Failed to dbus call");
152 void netconfig_clatd_reset()
155 g_is_running = FALSE;
156 netconfig_clatd_enable();