diff options
author | Chia-I Wu <olv@openmoko.com> | 2008-10-28 16:49:38 +0800 |
---|---|---|
committer | John Lee <john_lee@openmoko.org> | 2009-01-12 14:29:03 +0800 |
commit | 321b7dc88878ff24a48065048e01957d440a81c5 (patch) | |
tree | bcc1f0efb06afb662e250a45b83585870413eb30 /packages/initscripts/initscripts-openmoko/campgsm | |
parent | 0cd7f559c01c45f5fc287e533b7456fc2ba79cb9 (diff) |
fastboot: initscripts-openmoko: Replacement for initscripts.
Move the common files into 'files' dir and keep Openmoko specific
files under initscripts-openmoko. 'finish' was renamed to
'finish.sh', so various recipes have to be modified as well.
Diffstat (limited to 'packages/initscripts/initscripts-openmoko/campgsm')
-rw-r--r-- | packages/initscripts/initscripts-openmoko/campgsm | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/packages/initscripts/initscripts-openmoko/campgsm b/packages/initscripts/initscripts-openmoko/campgsm new file mode 100644 index 0000000000..5be67086c2 --- /dev/null +++ b/packages/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 |