ETC_DIR = /etc
CC = gcc
CFLAGS = -Wall -O2 -g -D_GNU_SOURCE -DIMAGE_DIR=\"$(IMAGE_DIR)\" -DSBIN_DIR=\"$(SBIN_DIR)\"
-INCLUDES = $(shell pkg-config --cflags dbus-1 libhildondesktop-1 hal)
+INCLUDES = $(shell pkg-config --cflags dbus-1 libhildondesktop-1 hal glib-2.0 gtk+-2.0)
LDFLAGS =
LIBS_DBUS = $(shell pkg-config --libs dbus-1)
LIBS_HILDON = $(shell pkg-config --libs libhildondesktop-1 hal glib-2.0 gtk+-2.0)
-all: mtetherd mtetherd-plugin.so
+all: mtetherd-plugin.so
mtetherd: mtetherd.o device.o
$(CC) $(LDFLAGS) $(LIBS_DBUS) -o $@ $^
clean:
rm -f *.o mtetherd mtetherd-plugin.so
-install: mtetherd mtetherd-plugin.so
- install -m 755 -D mtetherd $(DESTDIR)/$(SBIN_DIR)/mtetherd
- install -m 644 -D event.d-mtetherd $(DESTDIR)/$(ETC_DIR)/event.d/mtetherd
+install: mtetherd-plugin.so
install -m 644 -D README $(DESTDIR)/$(DOC_DIR)/README
install -m 644 -D mtetherd-plugin.desktop $(DESTDIR)/$(HILDON_DESKTOP_DIR)/mtetherd-plugin.desktop
install -m 755 -D mtetherd-plugin.so $(DESTDIR)/$(HILDON_PLUGIN_DIR)/mtetherd-plugin.so
install -m 755 -D mtetherd-usbnet-enable.sh $(DESTDIR)/$(SBIN_DIR)/mtetherd-usbnet-enable.sh
install -m 755 -D mtetherd-usbnet-disable.sh $(DESTDIR)/$(SBIN_DIR)/mtetherd-usbnet-disable.sh
+ install -m 755 -D mtetherd-net-setup.sh $(DESTDIR)/$(SBIN_DIR)/mtetherd-net-setup.sh
+ install -m 755 -D mtetherd-net-shutdown.sh $(DESTDIR)/$(SBIN_DIR)/mtetherd-net-shutdown.sh
install -m 644 -D mtetherd.sudoers $(DESTDIR)/$(ETC_DIR)/sudoers.d/mtetherd.sudoers
install -m 644 -D mtetherd-net-icon.png $(DESTDIR)/$(IMAGE_DIR)/mtetherd-net-icon.png
uninstall:
- rm -f $(DESTDIR)/$(SBIN_DIR)/mtetherd
rm -f $(DESTDIR)/$(ETC_DIR)/event.d/mtetherd
rm -rf $(DESTDIR)/$(PREFIX)/share/doc/mtetherd
rm -f $(DESTDIR)/$(HILDON_DESKTOP_DIR)/mtetherd-plugin.desktop
rm -f $(DESTDIR)/$(HILDON_PLUGIN_DIR)/mtetherd-plugin.so
rm -f $(DESTDIR)/$(SBIN_DIR)/mtetherd-usbnet-enable.sh
rm -f $(DESTDIR)/$(SBIN_DIR)/mtetherd-usbnet-disable.sh
+ rm -f $(DESTDIR)/$(SBIN_DIR)/mtetherd-net-setup.sh
+ rm -f $(DESTDIR)/$(SBIN_DIR)/mtetherd-net-shutdown.sh
rm -f $(DESTDIR)/$(ETC_DIR)/sudoers.d/mtetherd.sudoers
rm -f $(DESTDIR)/$(IMAGE_DIR)/mtetherd-net-icon.png
return NULL;
}
+gchar *mtetherd_device_get_addr(MTetherDDevice *self) {
+ if (self && self->priv) {
+ guchar a = self->priv->addr & 0xff;
+ guchar b = (self->priv->addr >> 8) & 0xff;
+ guchar c = (self->priv->addr >> 16) & 0xff;
+ guchar d = (self->priv->addr >> 24) & 0xff;
+ return g_strdup_printf("%u.%u.%u.%u", a, b, c, d);
+ }
+ return NULL;
+}
+
+gchar *mtetherd_device_get_netmask(MTetherDDevice *self) {
+ if (self && self->priv) {
+ guchar a = self->priv->netmask & 0xff;
+ guchar b = (self->priv->netmask >> 8) & 0xff;
+ guchar c = (self->priv->netmask >> 16) & 0xff;
+ guchar d = (self->priv->netmask >> 24) & 0xff;
+ return g_strdup_printf("%u.%u.%u.%u", a, b, c, d);
+ }
+ return NULL;
+}
+
+gchar *mtetherd_device_get_dhcp_start(MTetherDDevice *self) {
+ if (self && self->priv) {
+ guchar a = self->priv->dhcp_start & 0xff;
+ guchar b = (self->priv->dhcp_start >> 8) & 0xff;
+ guchar c = (self->priv->dhcp_start >> 16) & 0xff;
+ guchar d = (self->priv->dhcp_start >> 24) & 0xff;
+ return g_strdup_printf("%u.%u.%u.%u", a, b, c, d);
+ }
+ return NULL;
+}
+
+gchar *mtetherd_device_get_dhcp_end(MTetherDDevice *self) {
+ if (self && self->priv) {
+ guchar a = self->priv->dhcp_end & 0xff;
+ guchar b = (self->priv->dhcp_end >> 8) & 0xff;
+ guchar c = (self->priv->dhcp_end >> 16) & 0xff;
+ guchar d = (self->priv->dhcp_end >> 24) & 0xff;
+ return g_strdup_printf("%u.%u.%u.%u", a, b, c, d);
+ }
+ return NULL;
+}
+
static gint mtetherd_device_list_find_index(gpointer *array, const gchar *udi) {
guint i;
for (i = 0; i < MAX_DEVICES; i++) {
void mtetherd_device_set_index(MTetherDDevice *self, guint index);
// Returns the interface name
const gchar *mtetherd_device_get_interface(MTetherDDevice *self);
+// Returns the host address
+// Free when done
+gchar *mtetherd_device_get_addr(MTetherDDevice *self);
+// Returns the netmask
+// Free when done
+gchar *mtetherd_device_get_netmask(MTetherDDevice *self);
+// Returns the DHCP range start address
+// Free when done
+gchar *mtetherd_device_get_dhcp_start(MTetherDDevice *self);
+// Returns the DHCP range end address
+// Free when done
+gchar *mtetherd_device_get_dhcp_end(MTetherDDevice *self);
// Device list functions
// The list is constrained to 64 entries
#define SBIN_DIR "/usr/sbin"
#endif
-static const char *USBNET_MODULE = "g_ether";
// The UDI contains the MAC address and is thus unsuitable for
// loaded status checking, so we just use the interface name
static const char *USBNET_INTERFACE = "usb0";
plugin->priv->usb_plugged = FALSE;
}
- // Unnecessary, we scan the network device name instead
- //plugin->priv->usbnet_loaded = mtetherd_scan_modules(USBNET_MODULE);
-
// Update the button status
mtetherd_status_plugin_usb_plugged_show(plugin);
if (plugin && plugin->priv) {
const gchar *interface = mtetherd_device_get_interface(device);
if (mtetherd_device_ok(interface)) {
- if (!mtetherd_device_list_add(plugin->priv->devices, device)) {
- g_warning("Error adding network interface to list: Maximum number of devices exceeded");
- } else {
+ if (mtetherd_device_list_add(plugin->priv->devices, device)) {
if (g_strcmp0(USBNET_INTERFACE, interface) == 0) {
plugin->priv->usbnet_state = MTETHERD_STATUS_PLUGIN_USB_NET_ENABLED;
mtetherd_status_plugin_enable_button_set_text(plugin);
}
hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Starting network on %s", interface);
- // TODO: Launch network setup script
+ g_debug("Launching " SBIN_DIR "/mtetherd-net-setup.sh");
+ gchar *addr = mtetherd_device_get_addr(device);
+ gchar *netmask = mtetherd_device_get_netmask(device);
+ gchar *dhcp_start = mtetherd_device_get_dhcp_start(device);
+ gchar *dhcp_end = mtetherd_device_get_dhcp_end(device);
+ const char *command[] = { "/usr/bin/sudo", SBIN_DIR "/mtetherd-net-setup.sh", interface, addr, netmask, dhcp_start, dhcp_end, NULL };
+ if (!mtetherd_launch_script(command)) {
+ g_warning("Error launching USB networking setup script");
+ }
+ g_free(addr);
+ g_free(netmask);
+ g_free(dhcp_start);
+ g_free(dhcp_end);
+ } else {
+ g_warning("Error adding network interface to list: Maximum number of devices exceeded");
}
}
}
mtetherd_status_plugin_enable_button_set_text(plugin);
}
hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Shutting down network on %s", interface);
- // TODO: Launch network teardown script
+ g_debug("Launching " SBIN_DIR "/mtetherd-net-shutdown.sh");
+ const char *command[] = { "/usr/bin/sudo", SBIN_DIR "/mtetherd-net-shutdown.sh", interface, NULL };
+ if (!mtetherd_launch_script(command)) {
+ g_warning("Error launching USB networking shutdown script");
+ }
}
if (!mtetherd_device_list_remove(plugin->priv->devices, udi)) {
g_warning("Error removing network interface from list: Not found");
#include <glib.h>
-// Opens /proc/modules and scans for g_ether
+// Opens /proc/modules and scans for module
// Returns TRUE if found, FALSEĀ if not
gboolean mtetherd_scan_modules(const char *module);
// Launch an external script in the background