fix URL in specfile - rm svn-keywords
[comgt.git] / gcom.h
1 /***************************************************************************
2  *  gcom.h - 3G/GPRS datacard management utility header file
3  *
4  *  Copyright (C) 2003  Paul Hardwick <paul@peck.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  ***************************************************************************/
21
22 /***************************************************************************
23 * $Id: gcom.h 10 2006-01-04 12:40:44Z paul $
24 * $HeadURL: http://10.0.0.4/svn/gcom/gcom.h $
25 ****************************************************************************/
26
27
28 char _default_code[] = 
29     "opengt\n\
30     set com 115200n81\n\
31     set senddelay 0.05\n\
32     send \"AT+CFUN=1^m\"\n\
33     waitquiet 1 0.2\n\
34   :start\n\
35     flash 0.1\n\
36     send \"AT+CPIN?^m\"\n\
37     waitfor 30 \"SIM PUK\",\"SIM PIN\",\"READY\",\"ERROR\",\"ERR\"\n\
38     if % = -1 goto error\n\
39     if % = 0 goto ready\n\
40     if % = 1 goto getpin\n\
41     if % = 2 goto ready\n\
42     if % = 3 goto error\n\
43     if % = 4 goto error\n\
44   :error\n\
45     print $s,\" ***SIM ERROR***\n\"\n\
46     print \"Check device port configuration.\nCheck SIM is inserted\nTest SIM in a mobile phone?\n\"\n\
47     exit 1\n\
48   :getpin\n\
49     #handle case where Vodafone 3 generates wrong response\n\
50     waitfor 1 \"2\"\n\
51     if % = 0 goto ready\n\
52     print \"\nEnter PIN number: \"\n\
53     input $x\n\
54     let a=len($x)\n\
55     if a<>5 goto getpin\n\
56     let c=0\n\
57   :test\n\
58     let $c=$mid($x,c,1)\n\
59     if $c<\"0\" goto getpin\n\
60     if $c>\"9\" goto getpin\n\
61     inc c\n\
62     if c<4 goto test\n\
63     let a=val($x)\n\
64     if a<0 goto getpin\n\
65     if a>9999 goto getpin\n\
66     let $c=$left($x,4)\n\
67   :enterpin\n\
68     send \"AT+CPIN=\\\"\"\n\
69     send $c\n\
70     send \"\\\"^m\"\n\
71     waitfor 20 \"OK\",\"ERR\"\n\
72     if % = -1 goto timeerror\n\
73     if % = 0 goto cont\n\
74     if % = 1 goto pinerror\n\
75   :pinerror\n\
76   :timeerror\n\
77     print \"ERROR entering PIN code\n\"\n\
78     print \"Caution! - entering the wrong PIN code three times will lock the SIM\n\"\n\
79     exit 1\n\
80   :ready\n\
81     print \"SIM ready\n\"\n\
82   :cont\n\
83     print \"Waiting for Registration..(120 sec max)\"\n\
84     let c = 0\n\
85   :waitreg\n\
86     send \"AT+CREG?^m\"\n\
87     waitfor 2 \"+CREG: 0,1\",\"+CREG: 0,5\"\n\
88     if % = -1 goto regagain\n\
89     if % = 0 goto homereg\n\
90     if % = 1 goto roamreg\n\
91   :regagain\n\
92     if c > 120 goto regtimeout\n\
93     let c=c+2\n\
94     print \".\"\n\
95     goto waitreg\n\
96   :regtimeout\n\
97     print \"\nFailed to register\n\"\n\
98     exit 1\n\
99   :homereg\n\
100     print \"\nRegistered on Home network: \"\n\
101     goto registered\n\
102   :roamreg\n\
103     print \"\nRegistered on Roaming network: \"\n\
104     goto registered\n\
105   :registered\n\
106     waitquiet 1 0.1\n\
107     send \"AT+COPS?^m\"\n\
108     get 2 \"^m\" $s\n\
109     get 2 \"^m\" $s\n\
110     let a=len($s)\n\
111     let b=a-12\n\
112     if b < 1 goto regtimeout\n\
113     let $c=$right($s,b)\n\
114     print $c,\"\n\"\n\
115     let c=0\n\
116   :signal\n\
117     waitquiet 1 0.1\n\
118     send \"AT+CSQ^m\"\n\
119     get 2 \"^m\" $s\n\
120     get 2 \"^m\" $s\n\
121     let a=len($s)\n\
122     let a=a-6\n\
123     let $s=$right($s,a)\n\
124     if $s <> \"0,0\" goto sigcont\n\
125     if c > 3 goto sigexit\n\
126     let c=c+1\n\
127     pause 1\n\
128     goto signal\n\
129   :sigexit\n\
130     print \"Signal strength measure 0,0 too low!\"\n\
131     exit 1\n\
132   :sigcont\n\
133     print \"Signal Quality:\",$s,\"\\n\"\n\
134     waitquiet 1 0.1\n";
135
136 char _info_code[]  = 
137     "print \"##### GlobeTrotter Configuration #####\\n\"\n\
138     opengt\n\
139     set com 115200n81\n\
140     set senddelay 0.05\n\
141     waitquiet 2 0.5\n\
142   :manf\n\
143     print \"Manufacturer Text:      \"\n\
144     send \"AT+cgmi^m\"\n\
145     get 2 \" ^m\" $s\n\
146     get 2 \" ^m\" $s\n\
147     let x=len($s)\n\
148     dec x\n\
149     let $s=$right($s,x)\n\
150     print $s,\"\\n\"\n\
151   :imei_serial\n\
152     waitquiet 5 0.1\n\
153     print \"IMEI and Serial Number: \"\n\
154     send \"AT+GSN^m\"\n\
155     get 2 \" ^m\" $s\n\
156     get 2 \" ^m\" $s\n\
157     let x=len($s)\n\
158     dec x\n\
159     let $s=$right($s,x)\n\
160     print ,$s,\"\\n\"\n\
161   :firmware\n\
162     waitquiet 5 0.1\n\
163     print \"Manufacturer\'s Revision: \"\n\
164     send \"AT+GMR^m\"\n\
165     get 2 \" ^m\" $s\n\
166     get 2 \" ^m\" $s\n\
167     get 2 \"^m\" $s\n\
168     print $s,\"\\n\"\n\
169   :hardware\n\
170     waitquiet 5 0.1\n\
171     print \"Hardware Revision:      \"\n\
172     send \"AT_OHWV^m\"\n\
173     get 2 \" ^m\" $s\n\
174     get 2 \" ^m\" $s\n\
175     get 2 \" ^m\" $s\n\
176     print $s,\"\\n\"\n\
177   :networklock\n\
178     waitquiet 5 0.1\n\
179     print \"Network Locked:         \"\n\
180     send \"AT+clck=\\\"PN\\\",2^m\"\n\
181     get 2 \" ^m\" $s\n\
182     get 2 \" ^m\" $s\n\
183     get 2 \" ^m\" $s\n\
184     print $s,\"\\n\"\n\
185     waitquiet 5 0.1\n\
186   :customized\n\
187     print \"Customisation:          \"\n\
188     send \"AT_ocst^m\"\n\
189     get 2 \" ^m\" $s\n\
190     get 2 \" ^m\" $s\n\
191     get 2 \",^m\" $s\n\
192     print $s,\"\\n\"\n\
193   :bandsettings\n\
194     waitquiet 5 0.1\n\
195     print \"Band settings:          \"\n\
196     send \"AT_OSBM?^m\"\n\
197     get 2 \" ^m\" $s\n\
198     get 2 \" ^m\" $s\n\
199     get 2 \" ^m\" $s\n\
200     if $s=\"4\" print \"Europe 900/1800MHz \"\n\
201     if $s=\"5\" print \"USA 900/1900MHz \"\n\
202     print \"(\",$s,\")\\n\" \n\
203   :autoattach\n\
204     waitquiet 5 0.1\n\
205     print \"Auto Attach:            \"\n\
206     send \"AT_OCGAA?^m\"\n\
207     get 2 \" ^m\" $s\n\
208     get 2 \" ^m\" $s\n\
209     get 2 \" ^m\" $s\n\
210     print $s,\"\\n\" \n\
211     waitquiet 5 0.1  \n\
212     print \"##### END #####\\n\"" ;
213
214
215 char _USA_code[]= 
216     "print \"##### Band Change to USA operation #####\\n\"\n\
217     opengt\n\
218     set com 115200n81\n\
219     set senddelay 0.05\n\
220     waitquiet 2 0.5\n\
221     send \"AT_OSBM=5^m\"\n\
222     waitfor 10 \"OK\",\"ERR\"\n\
223     if % = -1 goto timeout\n\
224     if % = 0 goto cont\n\
225     if % = 1 goto error\n\
226   :timeout\n\
227     print \"Timeout Error communicating with device.\n\"\n\
228     exit 1\n\
229   :error\n\
230     print \"Error response from device.\n\"\n\
231     exit 1\n\
232   :cont\n\
233     print \"Complete\\n\"\n";
234
235 char _Europe_code[]  = 
236     "print \"##### Band Change to European operation #####\\n\"\n\
237     opengt\n\
238     set com 115200n81\n\
239     set senddelay 0.05\n\
240     waitquiet 2 0.5\n\
241     send \"AT_OSBM=4^m\"\n\
242     waitfor 10 \"OK\",\"ERR\"\n\
243     if % = -1 goto timeout\n\
244     if % = 0 goto cont\n\
245     if % = 1 goto error\n\
246   :timeout\n\
247     print \"Timeout Error communicating with device.\n\"\n\
248     exit 1\n\
249   :error\n\
250     print \"Error response from device.\n\"\n\
251     exit 1\n\
252   :cont\n\
253     print \"Complete\\n\"\n";
254
255 char _sig_code[]  = 
256     "opengt\n\
257     set com 115200n81\n\
258     set senddelay 0.05\n\
259     waitquiet 2 0.5\n\
260     let c=0\n\
261   :signal\n\
262     waitquiet 1 0.1\n\
263     send \"AT+CSQ^m\"\n\
264     get 2 \"^m\" $s\n\
265     get 2 \"^m\" $s\n\
266     let a=len($s)\n\
267     let a=a-6\n\
268     let $s=$right($s,a)\n\
269     if $s <> \"0,0\" goto sigcont\n\
270     if c > 3 goto sigexit\n\
271     let c=c+1\n\
272     pause 1\n\
273     goto signal\n\
274   :sigexit\n\
275     print \"Signal strength measure 0,0 too low!\"\n\
276     exit 1\n\
277   :sigcont\n\
278     print \"Signal Quality:\",$s,\"\\n\"\n\
279     waitquiet 1 0.1\n\
280     exit 0\n";
281
282 char _reg_code[]  =
283     "opengt\n\
284     set com 115200n81\n\
285     set senddelay 0.05\n\
286     waitquiet 2 0.5\n\
287     print \"Waiting for Registration\"\n\
288     let c = 0\n\
289   :waitreg\n\
290     send \"AT+CREG?^m\"\n\
291     waitfor 2 \"+CREG: 0,1\",\"+CREG: 0,5\"\n\
292     if % = -1 goto regagain\n\
293     if % = 0 goto homereg\n\
294     if % = 1 goto roamreg\n\
295   :regagain\n\
296     if c > 120 goto regtimeout\n\
297     let c=c+2\n\
298     print \".\"\n\
299     goto waitreg\n\
300   :regtimeout\n\
301     print \"\nFailed to register\n\"\n\
302     exit 1\n\
303   :homereg\n\
304     print \"\nRegistered on Home network: \"\n\
305     goto registered\n\
306   :roamreg\n\
307     print \"\nRegistered on Roaming network: \"\n\
308     goto registered\n\
309   :registered\n\
310     waitquiet 1 0.1\n\
311     send \"AT+COPS?^m\"\n\
312     get 2 \"^m\" $s\n\
313     get 2 \"^m\" $s\n\
314     let a=len($s)\n\
315     let b=a-12\n\
316     if b < 1 goto regtimeout\n\
317     let $c=$right($s,b)\n\
318     print $c,\"\n\"\n";
319
320 char _3G2G_mode_code[] =
321     "opengt\n\
322     set com 115200n81\n\
323     set senddelay 0.05\n\
324     waitquiet 1 0.2\n\
325     send \"AT_OPSYS=3^m\"\n\
326     waitfor 10 \"OK\",\"ERR\"\n\
327     if % = -1 goto timeout\n\
328     if % = 0 goto cont\n\
329     if % = 1 goto error\n\
330   :timeout\n\
331     print \"Timeout Error communicating with device.\n\"\n\
332     exit 1\n\
333   :error\n\
334     print \"Error response from device.\n\"\n\
335     exit 1\n\
336   :cont\n\
337     print \"Set 3G preferred mode\\n\"\n";
338
339
340 char _3G_mode_code[] =
341     "opengt\n\
342     set com 115200n81\n\
343     set senddelay 0.05\n\
344     waitquiet 1 0.2\n\
345     send \"AT_OPSYS=1^m\"\n\
346     waitfor 10 \"OK\",\"ERR\"\n\
347     if % = -1 goto timeout\n\
348     if % = 0 goto cont\n\
349     if % = 1 goto error\n\
350   :timeout\n\
351     print \"Timeout Error communicating with device.\n\"\n\
352     exit 1\n\
353   :error\n\
354     print \"Error response from device.\n\"\n\
355     exit 1\n\
356   :cont\n\
357     print \"Set 3G only mode\\n\"\n";
358     
359 char _2G_mode_code[] =
360     "opengt\n\
361     set com 115200n81\n\
362     set senddelay 0.05\n\
363     waitquiet 1 0.2\n\
364     send \"AT_OPSYS=0^m\"\n\
365     waitfor 10 \"OK\",\"ERR\"\n\
366     if % = -1 goto timeout\n\
367     if % = 0 goto cont\n\
368     if % = 1 goto error\n\
369   :timeout\n\
370     print \"Timeout Error communicating with device.\n\"\n\
371     exit 1\n\
372   :error\n\
373     print \"Error response from device.\n\"\n\
374     exit 1\n\
375   :cont\n\
376     print \"Set 2G only mode\\n\"\n";
377     
378 char _GTEDGE_code[] = 
379     "opengt\n\
380     set com 57600n81\n\
381     send \"AT+CFUN=1^m\"\n\
382     waitquiet 5 0.2";
383
384 char _help_code[]  = 
385     "print \"gcom Version 0.3\n Usage: \"\n\
386     print \"gcom [options] [built in script]'|[external script]\n\n\"\n\
387     print \"Built in scripts -\n\"\n\
388     print \"  gcom [default]           Checks SIM status (requests PIN if required),\n\"\n\
389     print \"                           registration and signal strength reported by\n\"\n\
390     print \"                           datacard.\n\"\n\
391     print \"  gcom info                Display configuration of datacard.\n\"\n\
392     print \"  gcom sig                 Report Signal strength.\n\"\n\
393     print \"  gcom reg                 Report Registration status.\n\"\n\
394     print \"\n  Valid for GlobeTrotter GPRS only:\n\"\n\
395     print \"      gcom USA                 Switch to 900/1900 MHz band for USA operation.\n\"\n\
396     print \"      gcom Europe              Switch to 900/1800 MHz band for Europen operation.\n\"\n\
397     print \"\n  Valid for GlobeTrotter EDGE and Combo EDGE only:\n\"\n\
398     print \"      gcom GTEDGE             Switch on radio interface.\n\"\n\
399     print \"\n  Valid for Vodafone 3G, GlobeTrotter Fusion :\n\"\n\
400     print \"      gcom 2G             2G networks only.\n\"\n\
401     print \"      gcom 3G             3G networks only\n\"\n\
402     print \"      gcom 3G2G           3G network preferred\n\"\n\
403     print \"\nCommand line options (must be before script name) - \\n\"\n\
404     print \"  -d device                Use alternative device. e.g -d /dev/ttyUSB0\n\"\n\
405     print \"  -e                       Turn on communication echo.\n\"\n\
406     print \"  -h                       Help.\n\"\n\
407     print \"  -s                       Don't run internal 'default' script before running\n\"\n\
408     print \"                           external script.\n\"\n\
409     print \"  -t=\"\\n\"                    Set alternative line terminator (default=\"\\n\").\n\"\n\
410     print \"  -v                       Verbose mode. Print lots of trace info.\n\"\n\
411     print \"  -x                       Speed exchange. 115200 replaced by 57600.\n\"\n\
412     print \"                           ***used for GlobeTrotter EDGE and Combo EDGE***\n\"\n\
413     print \"NOTES:\ngcom assumes that the GlobeTrotter device is /dev/modem (create a logical link\n\"\n\
414     print \"to actual device or use -d switch). Unless you use the '-s' switch gcom will\n\"\n\
415     print \"run the internal 'default' script first before running an external script file.\n\"\n" ;
416
417 char *get_code(char* name){
418   if(strlen(name)==0) return(_default_code);
419   if (strcmp(name,"default")==0) return (_default_code);
420   if (strcmp(name,"help")==0) return (_help_code);
421   if (strcmp(name,"info")==0) return (_info_code);
422   if (strcmp(name,"USA")==0) return (_USA_code);
423   if (strcmp(name,"Europe")==0) return (_Europe_code);
424   if (strcmp(name,"sig")==0) return (_sig_code); 
425   if (strcmp(name,"reg")==0) return (_reg_code); 
426   if (strcmp(name,"GTEDGE")==0) return (_GTEDGE_code); 
427   if (strcmp(name,"2G")==0) return (_2G_mode_code);
428   if (strcmp(name,"3G")==0) return (_3G_mode_code);
429   if (strcmp(name,"3G2G")==0) return (_3G2G_mode_code);
430   return(NULL);
431 }    
432