Added empty network setup scripts
[mtetherd] / plugin.c
index 2fb47d6..a0b4d5f 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -53,7 +53,6 @@ struct _MTetherDStatusPluginPrivate {
 #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";
@@ -166,9 +165,6 @@ static void mtetherd_status_plugin_init(MTetherDStatusPlugin *plugin) {
                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);
 
@@ -179,15 +175,27 @@ void mtetherd_status_plugin_device_added(MTetherDStatusPlugin *plugin, MTetherDD
        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");
                        }
                }
        }
@@ -203,7 +211,11 @@ void mtetherd_status_plugin_device_removed(MTetherDStatusPlugin *plugin, const g
                                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");