summaryrefslogtreecommitdiff
path: root/recipes/initscripts/initscripts-openmoko/campgsm
diff options
context:
space:
mode:
authorDenys Dmytriyenko <denis@denix.org>2009-03-17 14:32:59 -0400
committerDenys Dmytriyenko <denis@denix.org>2009-03-17 14:32:59 -0400
commit709c4d66e0b107ca606941b988bad717c0b45d9b (patch)
tree37ee08b1eb308f3b2b6426d5793545c38396b838 /recipes/initscripts/initscripts-openmoko/campgsm
parentfa6cd5a3b993f16c27de4ff82b42684516d433ba (diff)
rename packages/ to recipes/ per earlier agreement
See links below for more details: http://thread.gmane.org/gmane.comp.handhelds.openembedded/21326 http://thread.gmane.org/gmane.comp.handhelds.openembedded/21816 Signed-off-by: Denys Dmytriyenko <denis@denix.org> Acked-by: Mike Westerhof <mwester@dls.net> Acked-by: Philip Balister <philip@balister.org> Acked-by: Khem Raj <raj.khem@gmail.com> Acked-by: Marcin Juszkiewicz <hrw@openembedded.org> Acked-by: Koen Kooi <koen@openembedded.org> Acked-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>
Diffstat (limited to 'recipes/initscripts/initscripts-openmoko/campgsm')
-rw-r--r--recipes/initscripts/initscripts-openmoko/campgsm128
1 files changed, 128 insertions, 0 deletions
diff --git a/recipes/initscripts/initscripts-openmoko/campgsm b/recipes/initscripts/initscripts-openmoko/campgsm
new file mode 100644
index 0000000000..5be67086c2
--- /dev/null
+++ b/recipes/initscripts/initscripts-openmoko/campgsm
@@ -0,0 +1,128 @@
+#!/bin/sh
+
+VERBOSE=no
+
+PIDS=`pidof -x "$0"`
+
+# make sure pidof sees us
+if [ -z "$PIDS" ]; then
+ exec "$0"
+ exit 1
+fi
+
+GSM_DEVICE="/dev/ttySAC0"
+GSM_POWER="/sys/devices/platform/neo1973-pm-gsm.0/power_on"
+GSM_RESET="/sys/devices/platform/neo1973-pm-gsm.0/reset"
+
+GSM_COMMANDS="Z E0V1 +CFUN=1 +COPS=0"
+
+gsm_running () {
+ if [ "$PIDS" != "$$" ]; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+gsm_send () {
+ cmd="$1"
+ echo -ne "AT${cmd}\r" > "$GSM_DEVICE"
+}
+
+# this function might block forever
+gsm_wait () {
+ ret="UNKNOWN"
+
+ while read status; do
+ case "$status" in
+ OK*)
+ ret="OK"
+ ;;
+ ERROR*)
+ ret="ERROR"
+ ;;
+ *)
+ ret="UNKNOWN"
+ ;;
+ esac
+ if [ "x$ret" != "xUNKNOWN" ]; then
+ break
+ fi
+ done < "$GSM_DEVICE"
+
+ if [ "x$ret" != "xOK" ]; then
+ return 1
+ fi
+
+ return 0
+}
+
+gsm_setup () {
+ [ $VERBOSE == "yes" ] && echo -n "Powering up GSM modem..."
+ echo 0 > "$GSM_POWER"; sleep 1
+ echo 1 > "$GSM_POWER"; sleep 1
+ echo 1 > "$GSM_RESET"; sleep 1
+ echo 0 > "$GSM_RESET"; sleep 4
+ [ $VERBOSE == "yes" ] && echo "done"
+
+ stty -F "$GSM_DEVICE" cooked -opost -echo crtscts 115200
+}
+
+gsm_wakeup () {
+ [ $VERBOSE == "yes" ] && echo "Waking up GSM modem"
+
+ # there is at most one OK/ERROR even if we send multiple commands
+ gsm_send ""
+ gsm_send ""
+ gsm_send ""
+
+ if gsm_wait; then
+ [ $VERBOSE == "yes" ] && echo "GSM modem awake"
+ return 0
+ else
+ echo "failed to wake up GSM modem"
+ return 1
+ fi
+}
+
+start () {
+ gsm_setup
+
+ if gsm_wakeup; then
+ for cmd in $GSM_COMMANDS
+ do
+ [ $VERBOSE == "yes" ] && echo "Sending AT$cmd"
+ gsm_send "$cmd"
+
+ if ! gsm_wait; then
+ echo "AT$cmd failed"
+ break
+ fi
+ done
+ fi
+}
+
+set -e
+
+case "$1" in
+ start)
+ if gsm_running; then
+ echo "Another instance is already running"
+ exit 1
+ fi
+
+ start &
+ ;;
+ stop)
+ if gsm_running; then
+ PIDS=`pidof -x -o "$$" "$0"`
+ echo -n "Stopping other instances..."
+ kill $PIDS
+ echo "done"
+ fi
+ ;;
+ *)
+ echo "Usage: $0 {start|stop}"
+ exit 1
+ ;;
+esac