install -m 644 -D README $(DESTDIR)/$(PREFIX)/share/doc/mtetherd/README
install -m 644 -D mtetherd-plugin.desktop $(DESTDIR)/$(HILDON_DESKTOP)/mtetherd-plugin.desktop
install -m 755 -D mtetherd-plugin.so $(DESTDIR)/$(HILDON_PLUGIN)/mtetherd-plugin.so
+ install -m 755 -D mtetherd-usbnet-enable.sh $(DESTDIR)/$(PREFIX)/sbin/mtetherd-usbnet-enable.sh
+ install -m 755 -D mtetherd-usbnet-disable.sh $(DESTDIR)/$(PREFIX)/sbin/mtetherd-usbnet-disable.sh
+ install -m 755 -D mtetherd.sudoers $(DESTDIR)/etc/sudoers.d/mtetherd.sudoers
uninstall:
rm -f $(DESTDIR)/$(PREFIX)/sbin/mtetherd
rm -rf $(DESTDIR)/$(PREFIX)/share/doc/mtetherd
rm -f $(DESTDIR)/$(HILDON_DESKTOP)/mtetherd-plugin.desktop
rm -f $(DESTDIR)/$(HILDON_PLUGIN)/mtetherd-plugin.so
+ rm -f $(DESTDIR)/$(PREFIX)/sbin/mtetherd-usbnet-enable.sh
+ rm -f $(DESTDIR)/$(PREFIX)/sbin/mtetherd-usbnet-disable.sh
+ rm -f $(DESTDIR)/etc/sudoers.d/mtetherd.sudoers
%.o: %.c
$(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $^
+
+mtetherd (0.2-1) unstable; urgency=low
+
+ * Added status menu button to enable/disable USB networking
+
+ -- Gregor Riepl <onitake@gmail.com> Tue, 27 Jul 2010 23:48:00 +0200
+
mtetherd (0.1-1) unstable; urgency=low
* Initial release
+++ /dev/null
-usr/sbin
-etc/event.d
case "$1" in
configure)
+ update-sudoers
start mtetherd
;;
--- /dev/null
+#!/bin/sh
+# postrm script for mtetherd
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+# * <postrm> `remove'
+# * <postrm> `purge'
+# * <old-postrm> `upgrade' <new-version>
+# * <new-postrm> `failed-upgrade' <old-version>
+# * <new-postrm> `abort-install'
+# * <new-postrm> `abort-install' <old-version>
+# * <new-postrm> `abort-upgrade' <old-version>
+# * <disappearer's-postrm> `disappear' <overwriter>
+# <overwriter-version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+
+case "$1" in
+ purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
+ update-sudoers
+ ;;
+
+ *)
+ echo "postrm called with unknown argument \`$1'" >&2
+ exit 1
+ ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
+
+
--- /dev/null
+#!/bin/sh
+# This file is part of mtetherd
+#
+# Copyright (c) 2010 Gregor Riepl <onitake@gmail.com>
+#
+# Based on osso-usb-mass-storage-disable.sh,
+# Copyright (C) 2004-2009 Nokia Corporation. All rights reserved.
+# Contact: Kimmo Hämäläinen <kimmo.hamalainen@nokia.com>
+#
+# 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
+
+/sbin/lsmod | grep g_ether > /dev/null
+if [ $? != 0 ]; then
+ # the module is not loaded
+ exit 0
+fi
+
+/sbin/rmmod g_ether
+
+exit 0
--- /dev/null
+#!/bin/sh
+# This file is part of mtetherd
+#
+# Copyright (c) 2010 Gregor Riepl <onitake@gmail.com>
+#
+# Based on osso-usb-mass-storage-enable.sh and osso-usb-mass-storage-disable.sh,
+# Copyright (C) 2004-2009 Nokia Corporation. All rights reserved.
+# Contact: Kimmo Hämäläinen <kimmo.hamalainen@nokia.com>
+#
+# 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
+
+RC=0
+
+/sbin/lsmod | grep g_nokia > /dev/null
+if [ $? = 0 ]; then
+ logger "$0: removing g_nokia"
+
+ initctl emit G_NOKIA_REMOVE
+
+ PNATD_PID=`pidof pnatd`
+ if [ $? = 0 ]; then
+ kill $PNATD_PID
+ else
+ logger "$0: pnatd is not running"
+ fi
+ OBEXD_PID=`pidof obexd`
+ if [ $? = 0 ]; then
+ kill -HUP $OBEXD_PID
+ else
+ logger "$0: obexd is not running"
+ fi
+ SYNCD_PID=`pidof syncd`
+ if [ $? = 0 ]; then
+ kill $SYNCD_PID
+ else
+ logger "$0: syncd is not running"
+ fi
+
+ sleep 2
+ /sbin/rmmod g_nokia
+ if [ $? != 0 ]; then
+ logger "$0: failed to rmmod g_nokia!"
+ exit 1
+ fi
+fi
+
+/sbin/lsmod | grep g_file_storage > /dev/null
+if [ $? = 0 ]; then
+ logger "$0: removing g_file_storage"
+
+ GADGETPATH='/sys/devices/platform/musb_hdrc/gadget'
+ LUN0='gadget-lun0'
+ LUN1='gadget-lun1'
+
+ if [ $# = 0 ]; then
+ # unload all
+ echo "" > $GADGETPATH/$LUN0/file
+ echo "" > $GADGETPATH/$LUN1/file
+ exit 0
+ fi
+
+ # NOTE: works only for 1 or 2 device arguments
+ for lun in $LUN0 $LUN1; do
+ grep $1 $GADGETPATH/$lun/file > /dev/null
+ RC=$?
+
+ if [ $# = 2 ]; then
+ grep $2 $GADGETPATH/$lun/file > /dev/null
+ RC2=$?
+ else
+ RC2=1
+ fi
+
+ if [ $RC = 0 -o $RC2 = 0 ]; then
+ echo "" > $GADGETPATH/$lun/file
+ fi
+ done
+
+ /sbin/rmmod g_file_storage
+ if [ $? != 0 ]; then
+ logger "$0: failed to rmmod g_file_storage!"
+ exit 1
+ fi
+fi
+
+/sbin/lsmod | grep g_ether > /dev/null
+if [ $? != 0 ]; then
+ /sbin/modprobe g_ether
+ RC=$?
+fi
+
+if [ $RC != 0 ]; then
+ logger "$0: failed to install g_ether"
+ exit 1
+fi
+
+exit 0
fprintf(stderr, "Can't fork external process %s: %s\n", args[0], strerror(errno));
return -1;
} else {
- /*printf("Launching:");
- size_t a;
- for (a = 0; args[a]; a++) {
- printf(" %s", args[a]);
- }
- printf("\n");*/
int status = 0;
if (waitpid(pid, &status, WNOHANG) == -1) {
fprintf(stderr, "Error waiting for child process completion: %s\n", strerror(errno));
--- /dev/null
+user ALL = NOPASSWD: /usr/sbin/mtetherd-usbnet-enable.sh
+user ALL = NOPASSWD: /usr/sbin/mtetherd-usbnet-disable.sh
*/
#include <stdio.h>
+#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
g_type_class_add_private(klass, sizeof(MTetherDStatusPluginPrivate));
}
+static gboolean get_usbnet_enabled(MTetherDStatusPlugin *plugin) {
+ FILE *fp = fopen("/proc/modules", "r");
+ if (!fp) {
+ // fallback (useless?)
+ return plugin->priv->neton;
+ }
+ gboolean found = FALSE;
+ char *line = NULL;
+ while (!found && getline(&line, NULL, fp) != -1) {
+ if (strncmp(line, "g_ether", 7) == 0) {
+ found = TRUE;
+ }
+ free(line);
+ line = NULL;
+ }
+ fclose(fp);
+ return found;
+}
+
static void set_button_text(GtkWidget *button, gboolean enabled) {
if (enabled) {
gtk_button_set_label(GTK_BUTTON(button), "Disable USB Networking");
}
}
+static gboolean launch_usbnet_script(gboolean enable) {
+ const char *arg;
+ if (enable) {
+ arg = "/usr/sbin/mtetherd-usbnet-enable.sh";
+ } else {
+ arg = "/usr/sbin/mtetherd-usbnet-disable.sh";
+ }
+ const char *command[] = { "/usr/bin/sudo", arg, NULL };
+ pid_t pid = fork();
+ if (pid == 0) {
+ if (execv(command[0], (char **const) command) == -1) {
+ exit(1);
+ }
+ } else if (pid == -1) {
+ // error forking
+ return FALSE;
+ }
+ // launch ok
+ return TRUE;
+}
+
static void enable_usb_net_clicked(GtkWidget *button, gpointer user) {
MTetherDStatusPlugin *plugin = MTETHERD_STATUS_PLUGIN(user);
if (button == plugin->priv->button) {
- plugin->priv->neton = !plugin->priv->neton;
- set_button_text(plugin->priv->button, plugin->priv->neton);
- if (plugin->priv->neton) {
- // enable
+ gboolean enabled = get_usbnet_enabled(plugin);
+ set_button_text(plugin->priv->button, enabled);
+ if (enabled) {
+ if (launch_usbnet_script(FALSE)) {
+ // launch ok
+ plugin->priv->neton = FALSE;
+ }
} else {
- // disable
+ if (launch_usbnet_script(TRUE)) {
+ plugin->priv->neton = TRUE;
+ }
}
}
}