summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--include/tethering.h28
-rw-r--r--plugins/bluetooth.c40
-rw-r--r--src/tethering.c31
4 files changed, 98 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index badab1c6..651eede6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,7 +8,7 @@ include_HEADERS = include/types.h include/log.h include/plugin.h \
include/storage.h include/service.h \
include/resolver.h include/ipconfig.h \
include/device.h include/network.h include/inet.h \
- include/ondemand.h
+ include/ondemand.h include/tethering.h
nodist_include_HEADERS = include/version.h
diff --git a/include/tethering.h b/include/tethering.h
new file mode 100644
index 00000000..63f4f68c
--- /dev/null
+++ b/include/tethering.h
@@ -0,0 +1,28 @@
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __CONNMAN_TETHERING_H
+#define __CONNMAN_TETHERING_H
+
+void connman_tethering_enabled(void);
+void connman_tethering_disabled(void);
+
+#endif
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 9a73e96f..984a647f 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -36,6 +36,7 @@
#include <connman/technology.h>
#include <connman/device.h>
#include <connman/inet.h>
+#include <connman/tethering.h>
#include <connman/dbus.h>
#include <connman/log.h>
@@ -968,8 +969,35 @@ static void server_register_reply(DBusPendingCall *call, void *user_data)
dbus_message_unref(reply);
dbus_pending_call_unref(call);
+ connman_tethering_enabled();
}
+static void server_unregister_reply(DBusPendingCall *call, void *user_data)
+{
+ DBusError error;
+ DBusMessage *reply;
+
+ DBG("");
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&error);
+
+ if (dbus_set_error_from_message(&error, reply) == TRUE) {
+ connman_error("%s", error.message);
+ dbus_error_free(&error);
+ dbus_message_unref(reply);
+ dbus_pending_call_unref(call);
+ return;
+ }
+
+ dbus_message_unref(reply);
+ dbus_pending_call_unref(call);
+
+ connman_tethering_disabled();
+}
+
+
static void server_register(const char *path, const char *uuid,
const char *bridge, connman_bool_t enabled)
{
@@ -1008,8 +1036,12 @@ static void server_register(const char *path, const char *uuid,
return;
}
- dbus_pending_call_set_notify(call, server_register_reply,
- g_strdup(path), g_free);
+ if (enabled == TRUE)
+ dbus_pending_call_set_notify(call, server_register_reply,
+ NULL, NULL);
+ else
+ dbus_pending_call_set_notify(call, server_unregister_reply,
+ NULL, NULL);
dbus_message_unref(message);
}
@@ -1021,6 +1053,8 @@ static void enable_nap(gpointer key, gpointer value,
const char *bridge = user_data;
const char *path;
+ DBG("");
+
path = connman_device_get_string(device, "Path");
server_register(path, "nap", bridge, TRUE);
@@ -1033,6 +1067,8 @@ static void disable_nap(gpointer key, gpointer value,
const char *bridge = user_data;
const char *path;
+ DBG("");
+
path = connman_device_get_string(device, "Path");
server_register(path, "nap", bridge, FALSE);
diff --git a/src/tethering.c b/src/tethering.c
index 864f22c9..208a39f4 100644
--- a/src/tethering.c
+++ b/src/tethering.c
@@ -30,9 +30,12 @@
#include "connman.h"
+#include <connman/tethering.h>
+
#define BRIDGE_NAME "tether"
static connman_bool_t tethering_status = FALSE;
+gint tethering_enabled;
connman_bool_t __connman_tethering_get_status(void)
{
@@ -79,6 +82,32 @@ static int remove_bridge(const char *name)
return 0;
}
+void connman_tethering_enabled(void)
+{
+ if (tethering_status == FALSE)
+ return;
+
+ DBG("enabled %d", tethering_enabled + 1);
+
+ if (g_atomic_int_exchange_and_add(&tethering_enabled, 1) == 0) {
+ /* TODO Start DHCP server and DNS proxy on the bridge */
+ DBG("tethering started");
+ }
+}
+
+void connman_tethering_disabled(void)
+{
+ if (tethering_status == FALSE)
+ return;
+
+ DBG("enabled %d", tethering_enabled - 1);
+
+ if (g_atomic_int_dec_and_test(&tethering_enabled) == 0) {
+ /* TODO Stop DHCP server and DNS proxy on the bridge */
+ DBG("tethering stopped");
+ }
+}
+
int __connman_tethering_set_status(connman_bool_t status)
{
if (status == tethering_status)
@@ -106,6 +135,8 @@ int __connman_tethering_init(void)
{
DBG("");
+ tethering_enabled = 0;
+
return 0;
}