5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <sys/ioctl.h>
29 #include <linux/sockios.h>
33 #include <connman/tethering.h>
35 #define BRIDGE_NAME "tether"
37 static connman_bool_t tethering_status = FALSE;
38 gint tethering_enabled;
40 connman_bool_t __connman_tethering_get_status(void)
42 return tethering_status;
45 static int create_bridge(const char *name)
51 sk = socket(AF_INET, SOCK_STREAM, 0);
55 err = ioctl(sk, SIOCBRADDBR, name);
65 static int remove_bridge(const char *name)
71 sk = socket(AF_INET, SOCK_STREAM, 0);
75 err = ioctl(sk, SIOCBRDELBR, name);
85 void connman_tethering_enabled(void)
87 if (tethering_status == FALSE)
90 DBG("enabled %d", tethering_enabled + 1);
92 if (g_atomic_int_exchange_and_add(&tethering_enabled, 1) == 0) {
93 /* TODO Start DHCP server and DNS proxy on the bridge */
94 DBG("tethering started");
98 void connman_tethering_disabled(void)
100 if (tethering_status == FALSE)
103 DBG("enabled %d", tethering_enabled - 1);
105 if (g_atomic_int_dec_and_test(&tethering_enabled) == 0) {
106 /* TODO Stop DHCP server and DNS proxy on the bridge */
107 DBG("tethering stopped");
111 int __connman_tethering_set_status(connman_bool_t status)
113 if (status == tethering_status)
116 if (status == TRUE) {
117 create_bridge(BRIDGE_NAME);
118 __connman_technology_enable_tethering(BRIDGE_NAME);
120 __connman_technology_disable_tethering(BRIDGE_NAME);
121 remove_bridge(BRIDGE_NAME);
124 tethering_status = status;
129 void __connman_tethering_update_interface(const char *interface)
131 DBG("interface %s", interface);
134 int __connman_tethering_init(void)
138 tethering_enabled = 0;
143 void __connman_tethering_cleanup(void)
147 if (tethering_status == TRUE)
148 remove_bridge(BRIDGE_NAME);