#include "connman.h"
#define BRIDGE_NAME "tether"
+#define BRIDGE_IP "192.168.218.1"
+#define BRIDGE_BCAST "192.168.218.255"
+#define BRIDGE_SUBNET "255.255.255.0"
static connman_bool_t tethering_status = FALSE;
static const char *default_interface = NULL;
return 0;
}
+static int enable_bridge(const char *name)
+{
+ int err, index;
+
+ index = connman_inet_ifindex(name);
+ if (index < 0)
+ return index;
+
+ err = __connman_inet_modify_address(RTM_NEWADDR,
+ NLM_F_REPLACE | NLM_F_ACK, index, AF_INET,
+ BRIDGE_IP, NULL, 24, BRIDGE_BCAST);
+ if (err < 0)
+ return err;
+
+ return connman_inet_ifup(index);
+}
+
+static int disable_bridge(const char *name)
+{
+ int index;
+
+ index = connman_inet_ifindex(name);
+ if (index < 0)
+ return index;
+
+ return connman_inet_ifdown(index);
+}
+
static int enable_ip_forward(connman_bool_t enable)
{
void __connman_tethering_set_enabled(void)
{
+ int err;
+
if (tethering_status == FALSE)
return;
DBG("enabled %d", tethering_enabled + 1);
if (g_atomic_int_exchange_and_add(&tethering_enabled, 1) == 0) {
+ err = enable_bridge(BRIDGE_NAME);
+ if (err < 0)
+ return;
+
/* TODO Start DHCP server and DNS proxy on the bridge */
enable_nat(default_interface);
+
DBG("tethering started");
}
}
/* TODO Stop DHCP server and DNS proxy on the bridge */
disable_nat(default_interface);
+
+ disable_bridge(BRIDGE_NAME);
+
DBG("tethering stopped");
}
}
{
DBG("");
- if (tethering_status == TRUE)
+ if (tethering_status == TRUE) {
+ disable_bridge(BRIDGE_NAME);
remove_bridge(BRIDGE_NAME);
+ }
}