1#!/system/bin/sh
2
3atdev=/dev/omap_csmi_tty0
4pppdev=/dev/omap_csmi_tty1
5
6n1=`cat /data/phoneentry1 2>/dev/null`
7n2=`cat /data/phoneentry2 2>/dev/null`
8n3=`cat /data/phoneentry3 2>/dev/null`
9n1=${n1:-"*#06#"}
10n2=${n2:-"*#06#"}
11n3=${n3:-"*#06#"}
12phoneoutputpid=
13eventoutputpid=
14notifypid=
15notifytoggle=false
16pppdpid=
17powerdidletime=120
18
19# map phone specific keys
20setkey -k 0xe4 -v 0x23 # map #
21setkey -k 0xe3 -v 0x2a # map *
22setkey -k 231 -v 513 # map send to newline
23#setkey -k 0x67 -v 0x20b # map up to scroll back
24#setkey -k 0x6c -v 0x20a # map down to scroll forward
25setkey -k 0x73 -v 0x20b # map volume up to scroll back
26setkey -k 0x72 -v 0x20a # map volume down to scroll forward
27setkey -k 0x60 -v 0x211 # map PoC to next console
28
29# tuttle keys
30setkey -k 0x38 -v 0x703 # map leftalt to alt
31setkey -k 0x9b -v 0x703 # map mail to alt
32setkey -t 8 -k 0x9b -v 0x703 # map alt-mail to alt
33setkey -t 8 -k 0x10 -v 0x21 # map alt-q to !
34setkey -t 8 -k 0x11 -v 0x31 # map alt-w to 1
35setkey -t 8 -k 0x12 -v 0x32 # map alt-e to 2
36setkey -t 8 -k 0x13 -v 0x33 # map alt-r to 3
37setkey -t 8 -k 0x14 -v 0x2b # map alt-t to +
38setkey -t 8 -k 0x15 -v 0x28 # map alt-y to (
39setkey -t 8 -k 0x16 -v 0x29 # map alt-u to )
40setkey -t 8 -k 0x17 -v 0x2d # map alt-i to -
41setkey -t 8 -k 0x18 -v 0x5f # map alt-o to _
42setkey -t 8 -k 0x19 -v 0x22 # map alt-p to "
43setkey -t 8 -k 0x1e -v 0x23 # map alt-a to #
44setkey -t 8 -k 0x1f -v 0x34 # map alt-s to 4
45setkey -t 8 -k 0x20 -v 0x35 # map alt-d to 5
46setkey -t 8 -k 0x21 -v 0x36 # map alt-f to 6
47setkey -t 8 -k 0x22 -v 0x2f # map alt-g to /
48setkey -t 8 -k 0x23 -v 0x3f # map alt-h to ?
49setkey -t 8 -k 0x24 -v 0xa3 # map alt-j to pound
50setkey -t 8 -k 0x25 -v 0x24 # map alt-k to $
51setkey -t 8 -k 0x2c -v 0x2a # map alt-z to *
52setkey -t 8 -k 0x2d -v 0x37 # map alt-x to 7
53setkey -t 8 -k 0x2e -v 0x38 # map alt-c to 8
54setkey -t 8 -k 0x2f -v 0x39 # map alt-v to 9
55setkey -t 8 -k 0x30 -v 0x7c # map alt-b to |
56setkey -t 8 -k 0x31 -v 0x40 # map alt-n to @
57setkey -t 8 -k 0x32 -v 0x3d # map alt-m to =
58setkey -t 8 -k 0x33 -v 0x3b # map alt-, to ;
59setkey -t 8 -k 0x34 -v 0x3a # map alt-. to :
60setkey -t 8 -k 0x0f -v 0x30 # map alt-tab to 0
61setkey -t 8 -k 0x67 -v 0x20b # map alt-up to scroll back
62setkey -t 8 -k 0x6c -v 0x20a # map alt-down to scroll forward
63
64while true
65do
66	echo
67	echo "------------------------------"
68	echo " 1: init commands"
69	echo " 2: call commands"
70	echo " 3: misc phone"
71	echo " 4: phone debug output"
72	echo " 5: test data connection"
73	echo " 6: start runtime"
74	echo " 7: start runtime w/output"
75	echo " 8: stop runtime"
76	echo " 9: misc"
77	echo -n ": "
78	while true
79	do
80		c=`readtty -t 50 -f -a 1234567890#`
81		case "$c" in
82			"" ) ;;
83			* ) break;
84		esac
85	done
86	echo Got key -$c-
87	case $c in
88		"1" )
89			while true; do
90				echo
91				echo "------------------------------"
92				echo " 1: Print phone output"
93				echo " 2: ATQ0V1E1+CMEE=2;+CREG=0"
94				echo " 3: AT+CFUN=1"
95				echo " 4: AT+COPS=0"
96				echo " 5: AT+CREG?"
97				echo " 6: Stop phone output"
98				echo " 0: back"
99				echo -n ": "
100				c=`readtty -f -a 1234560#`
101				echo Got key -$c-
102				case "$c" in
103					"1" ) kill $phoneoutputpid; cat $atdev & phoneoutputpid=$! ;;
104					"2" ) echo -e "ATQ0V1E1+CMEE=2;+CREG=0\r" >$atdev;;
105					"3" ) echo -e "AT+CFUN=1\r" >$atdev;;
106					"4" ) echo -e "AT+COPS=0\r" >$atdev;;
107					"5" ) echo -e "AT+CREG?\r" >$atdev;;
108					"6" ) kill $phoneoutputpid; phoneoutputpid= ;;
109					"0" ) break;;
110				esac
111			done
112		;;
113		"2" )
114			while true; do
115				echo
116				echo "------------------------------"
117				echo " 1: Dial: ATD $n1;"
118				echo " 2: Dial: ATD $n2;"
119				echo " 3: Dial: ATD $n3;"
120				echo " 4: Set number for 1"
121				echo " 5: Set number for 2"
122				echo " 6: Set number for 3"
123				echo " 7: Dial: ATD ...;"
124				echo " 8: Hang up: ATH"
125				echo " 9: Answer: ATA"
126				echo " 0: back"
127				echo -n ": "
128				c=`readtty -f -a 1234567890#`
129				echo Got key -$c-
130				case "$c" in
131					"1" ) echo "Dialing $n1"; echo -e "ATD $n1;\r" >$atdev;;
132					"2" ) echo "Dialing $n2"; echo -e "ATD $n2;\r" >$atdev;;
133					"3" ) echo "Dialing $n3"; echo -e "ATD $n3;\r" >$atdev;;
134					"4" ) echo -n "Number: "; read n1; echo $n1 >/data/phoneentry1;;
135					"5" ) echo -n "Number: "; read n2; echo $n2 >/data/phoneentry2;;
136					"6" ) echo -n "Number: "; read n3; echo $n3 >/data/phoneentry3;;
137					"7" ) echo -n "Number: "; read n; echo "Dialing $n"; echo -e "ATD $n;\r" >$atdev;;
138					"8" ) echo -e "ATH\r" >$atdev;;
139					"9" ) echo -e "ATA\r" >$atdev;;
140					"0" ) break;;
141				esac
142			done
143		;;
144		"3" )
145			while true; do
146				echo
147				echo "------------------------------"
148				echo " 1: Save FFS data"
149				echo " 2: Load user FFS data"
150				echo " 3: Load system FFS data"
151				echo " 4: Reset FFS data"
152				echo " 5: Set uplink gain"
153				echo " 6: Set echo"
154				echo " 7: cat /dev/omap_csmi_battery_t"
155				echo " 8: cat /dev/omap_csmi_htc"
156				echo " 0: back"
157				echo -n ": "
158				c=`readtty -f -a 123456780#`
159				echo Got key -$c-
160				case "$c" in
161					"1" ) cat /dev/omap_csmi_ffs >/data/ffsdata;;
162					"2" ) cat /data/ffsdata >/dev/omap_csmi_ffs;;
163					"3" ) cat /system/ffsdata >/dev/omap_csmi_ffs;;
164					"4" ) echo - >/dev/omap_csmi_ffs;;
165					"5" )
166						echo -n "Gain: "; read g;
167						echo gu$g >/tmp/gain;
168						cat /tmp/gain 2>/dev/null >/dev/omap_csmi_audio_tes
169					;;
170					"6" )
171						echo -n "Echo param (hex): "; read e;
172						echo "e0x$e" >/tmp/echo;
173						cat /tmp/echo 2>/dev/null >/dev/omap_csmi_audio_tes
174					;;
175					"7" ) cat /dev/omap_csmi_battery_t;;
176					"8" ) cat /dev/omap_csmi_htc;;
177					"0" ) break;;
178				esac
179			done
180		;;
181		"4" )
182			while true; do
183				echo
184				echo "------------------------------"
185				echo " 1: Toggle debug I/O"
186				echo " 2: Toggle debug Flow"
187				echo " 3: Toggle debug Interrupt"
188				echo " 4: Toggle debug Info"
189				echo " 5: Toggle GSM run state"
190				echo " 6: Clear GSM data area"
191				echo " 0: back"
192				echo -n ": "
193				c=`readtty -f -a 1234560#`
194				echo Got key -$c-
195				case "$c" in
196					"1" ) echo -n "i" >/sys/devices/system/omap_csmi/debug;;
197					"2" ) echo -n "f" >/sys/devices/system/omap_csmi/debug;;
198					"3" ) echo -n "I" >/sys/devices/system/omap_csmi/debug;;
199					"4" ) echo -n "F" >/sys/devices/system/omap_csmi/debug;;
200					"5" ) echo -n "s" >/sys/devices/system/omap_csmi/debug;;
201					"6" ) echo -n "c" >/sys/devices/system/omap_csmi/debug;;
202					"0" ) break;;
203				esac
204			done
205		;;
206		"5" )
207			while true; do
208				echo
209				echo "------------------------------"
210				echo " 1: Start pppd - userspace"
211				echo " 2: Start pppd - kernel"
212				echo " 3: Start pppd - kernel <at1"
213				echo " 4: Configure ppp data to at2"
214				echo " 5: Test with HTTP GET"
215				echo " 6: Kill pppd"
216				echo " 0: back"
217				echo -n ": "
218				c=`readtty -f -a 1234560#`
219				echo Got key -$c-
220				case "$c" in
221					"1" ) kill $pppdpid; pppd notty < $pppdev > $pppdev & pppdpid=$!;;
222					"2" ) kill $pppdpid; pppd nodetach $pppdev & pppdpid=$!;;
223					"3" ) kill &pppdpid; pppd nodetach $pppdev connect "sh -c \"chat -v -f /etc/ppp/connect-data <$atdev >$atdev\"" & pppdpid=$!;;
224					"4" ) echo -e 'AT%DATA=2,"UART",1,,"SER","UART",0\r' >$atdev;;
225					"5" ) test-data-connection;;
226					"6" ) kill $pppdpid; pppdpid=;;
227					"0" ) break;;
228				esac
229			done
230		;;
231		"6" )
232			echo
233			echo ------------------------
234			echo Starting android runtime
235			echo ------------------------
236			start
237		;;
238		"7" )
239			echo
240			echo ------------------------
241			echo Starting android runtime
242			echo ------------------------
243			if exists /data/singleproc
244			then
245				single_process="-s"
246			else
247				single_process=""
248			fi
249			start runtime $single_process
250		;;
251		"8" )
252			stop
253		;;
254		"9" )
255			while true; do
256				echo
257				echo "------------------------------"
258				echo " 1: Print events"
259				echo " 2: Stop event output"
260				if $notifytoggle
261				then
262					echo " 3: stop notify"
263				else
264					echo " 3: notify /sys/android_power"
265				fi
266				echo " 4: start powerd"
267				echo " 5: start powerd verbose"
268				echo " 6: stop powerd"
269				echo " 7: set powerd idletime ($powerdidletime)"
270				echo " 8: start multitap shell"
271				if exists /data/singleproc
272				then
273					echo " 9: enable multiprocess"
274				else
275					echo " 9: disable multiprocess"
276				fi
277				echo " c: start shell"
278				echo " 0: back"
279				echo -n ": "
280				c=`readtty -f -a 1234567890c#`
281				echo Got key -$c-
282				case "$c" in
283					"1" ) kill $eventoutputpid; getevent & eventoutputpid=$! ;;
284					"2" ) kill $eventoutputpid; eventoutputpid= ;;
285					"3" )
286						if $notifytoggle
287						then
288							kill $notifypid
289							notifypid=
290							notifytoggle=false
291						else
292							kill $notifypid
293							notify -m 0x00000002 -c 0 -p -v 0 -w 30 /sys/android_power &
294							notifypid=$!
295							notifytoggle=true
296						fi
297					;;
298					"4" ) start powerd -i $powerdidletime ;;
299					"5" ) start powerd -i $powerdidletime -v ;;
300					"6" ) stop powerd ;;
301					"7" ) echo -n "Idle time (seconds): "; read powerdidletime ;;
302					"8" )
303						readtty -f -p -t 10 -e "[ ~" | sh -i
304					;;
305					"9" )
306						if exists /data/singleproc
307						then
308							echo "Enabling multiprocess environment."
309							rm /data/singleproc
310						else
311							echo "Disabling multiprocess environment."
312							echo >/data/singleproc "true"
313						fi
314					;;
315					"c" ) sh -i <>/dev/tty0 1>&0 2>&1 ;;
316					"0" ) break;;
317				esac
318			done
319		;;
320	esac
321done
322
323