From 321b7dc88878ff24a48065048e01957d440a81c5 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 28 Oct 2008 16:49:38 +0800 Subject: 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. --- packages/initscripts/initscripts-openmoko/campgsm | 128 ++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 packages/initscripts/initscripts-openmoko/campgsm (limited to 'packages/initscripts/initscripts-openmoko/campgsm') 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 -- cgit v1.2.3