[Debian-eeepc-devel] [PATCH v2] add support for GSM (3G) toggling

Thiemo Nagel thiemo.nagel at ph.tum.de
Tue Jul 21 22:26:34 UTC 2009


For kernels <= 2.6.30, the "HUAWEI Mobile" device is toggled
via USB power level.  For later kernels, the eeepc-wwan3g rfkill
is used through /sys/class/rfkill/rfkillX/state, which does
not (yet) work for 2.6.31-rc3, though.  In this case, USB again
is used as a fallback.
---
 debian/changelog                  |    2 +
 debian/eeepc-acpi-scripts.default |    2 +
 etc/acpi/actions/gsm.sh           |   64 +++++++++++++++++++++++++++++++++++++
 etc/acpi/actions/hotkey.sh        |   10 ++++++
 4 files changed, 78 insertions(+), 0 deletions(-)
 create mode 100644 etc/acpi/actions/gsm.sh

diff --git a/debian/changelog b/debian/changelog
index 13e8dd2..4e99134 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -8,6 +8,8 @@ eeepc-acpi-scripts (1.1.2) UNRELEASED; urgency=low
     control & muting. Off by default; normally takes effect while booting.
 
   [ Thiemo Nagel ]
+  * Add support for GSM (3G) toggling, automatically chosing between rfkill
+    and USB methods.
   * spelling fix in the default file
   * fix actions/wireless.sh usage message
 
diff --git a/debian/eeepc-acpi-scripts.default b/debian/eeepc-acpi-scripts.default
index cdd6a95..92efdc7 100644
--- a/debian/eeepc-acpi-scripts.default
+++ b/debian/eeepc-acpi-scripts.default
@@ -91,6 +91,8 @@ BLUETOOTH_FALLBACK_TO_HCITOOL='yes'
 #      on/off any USB bluetooth adapter found
 #  - handle_camera_toggle
 #      Toggles internal camera on/off
+#  - handle_gsm_toggle
+#      Toggles internal GSM modem (HUAWEI) on/off
 #  - handle_mute_toggle
 #      Toggles audio on/off
 #  - handle_volume_up
diff --git a/etc/acpi/actions/gsm.sh b/etc/acpi/actions/gsm.sh
new file mode 100644
index 0000000..1c106f4
--- /dev/null
+++ b/etc/acpi/actions/gsm.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+# do nothing if package is removed
+PKG=eeepc-acpi-scripts
+FUNC_LIB=/usr/share/$PKG/functions.sh
+[ -e $FUNC_LIB ] || exit 0
+
+. $FUNC_LIB
+
+# first try kernel rfkill
+detect_rfkill eeepc-wwan3g
+if [ -n "$RFKILL" ]; then
+    if echo `cat $RFKILL` > $RFKILL 2> /dev/null; then
+        gsm_control="$RFKILL"
+        gsm_on=1
+        gsm_off=0
+    fi
+fi
+
+# then try USB
+if [ -z "$gsm_control" ]; then
+    for f in /sys/bus/usb/devices/*; do
+	if [ -f "$f/product" ] && grep -q '^HUAWEI Mobile' $f/product; then
+            gsm_control="$f/power/level"
+            gsm_on=auto
+            gsm_off=suspend
+            break
+	fi
+    done
+fi
+
+# give up if no method to toggle GSM was found
+if [ -z "$gsm_control" ]; then
+    echo "GSM control not found."
+    exit 1
+fi
+
+case "$1" in
+    detect)
+        if [ `cat "$gsm_control"` != "$gsm_off" ]; then
+            exit 1
+        else
+            exit 0
+        fi
+	;;
+    toggle)
+        if [ `cat "$gsm_control"` != "$gsm_off" ]; then
+            echo "$gsm_off" > "$gsm_control"
+        else
+            echo "$gsm_on" > "$gsm_control"
+        fi        
+        ;;
+    on|enable|1)
+        echo "$gsm_on" > "$gsm_control"
+	;;
+    off|disable|0)
+        echo "$gsm_off" > "$gsm_control"
+	;;
+    *)
+	echo "Usage: $0 [on|off|detect|toggle]"
+	exit 1
+	;;
+esac
+
diff --git a/etc/acpi/actions/hotkey.sh b/etc/acpi/actions/hotkey.sh
index a0da708..2e92597 100755
--- a/etc/acpi/actions/hotkey.sh
+++ b/etc/acpi/actions/hotkey.sh
@@ -98,6 +98,16 @@ handle_shengine() {
     handle_shengine "$@"
 }
 
+handle_gsm_toggle() {
+    /etc/acpi/actions/gsm.sh toggle
+    if /etc/acpi/actions/gsm.sh detect; then
+        notify gsm "GSM off"
+    else
+        notify gsm "GSM on"
+    fi
+}
+
+
 case $code in
     # Fn + key:
     # <700/900-series key>/<1000-series key> - function
-- 
1.5.6.5




More information about the Debian-eeepc-devel mailing list