1 /***************************************************************************
2 * gcom.h - 3G/GPRS datacard management utility header file
4 * Copyright (C) 2003 Paul Hardwick <paul@peck.org>
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.
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.
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
20 ***************************************************************************/
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 ****************************************************************************/
28 char _default_code[] =
32 send \"AT+CFUN=1^m\"\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\
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\
49 #handle case where Vodafone 3 generates wrong response\n\
51 if % = 0 goto ready\n\
52 print \"\nEnter PIN number: \"\n\
55 if a<>5 goto getpin\n\
58 let $c=$mid($x,c,1)\n\
59 if $c<\"0\" goto getpin\n\
60 if $c>\"9\" goto getpin\n\
65 if a>9999 goto getpin\n\
68 send \"AT+CPIN=\\\"\"\n\
71 waitfor 20 \"OK\",\"ERR\"\n\
72 if % = -1 goto timeerror\n\
74 if % = 1 goto pinerror\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\
81 print \"SIM ready\n\"\n\
83 print \"Waiting for Registration..(120 sec max)\"\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\
92 if c > 120 goto regtimeout\n\
97 print \"\nFailed to register\n\"\n\
100 print \"\nRegistered on Home network: \"\n\
103 print \"\nRegistered on Roaming network: \"\n\
107 send \"AT+COPS?^m\"\n\
112 if b < 1 goto regtimeout\n\
113 let $c=$right($s,b)\n\
123 let $s=$right($s,a)\n\
124 if $s <> \"0,0\" goto sigcont\n\
125 if c > 3 goto sigexit\n\
130 print \"Signal strength measure 0,0 too low!\"\n\
133 print \"Signal Quality:\",$s,\"\\n\"\n\
137 "print \"##### GlobeTrotter Configuration #####\\n\"\n\
140 set senddelay 0.05\n\
143 print \"Manufacturer Text: \"\n\
144 send \"AT+cgmi^m\"\n\
149 let $s=$right($s,x)\n\
153 print \"IMEI and Serial Number: \"\n\
159 let $s=$right($s,x)\n\
163 print \"Manufacturer\'s Revision: \"\n\
171 print \"Hardware Revision: \"\n\
172 send \"AT_OHWV^m\"\n\
179 print \"Network Locked: \"\n\
180 send \"AT+clck=\\\"PN\\\",2^m\"\n\
187 print \"Customisation: \"\n\
188 send \"AT_ocst^m\"\n\
195 print \"Band settings: \"\n\
196 send \"AT_OSBM?^m\"\n\
200 if $s=\"4\" print \"Europe 900/1800MHz \"\n\
201 if $s=\"5\" print \"USA 900/1900MHz \"\n\
202 print \"(\",$s,\")\\n\" \n\
205 print \"Auto Attach: \"\n\
206 send \"AT_OCGAA?^m\"\n\
212 print \"##### END #####\\n\"" ;
216 "print \"##### Band Change to USA operation #####\\n\"\n\
219 set senddelay 0.05\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\
227 print \"Timeout Error communicating with device.\n\"\n\
230 print \"Error response from device.\n\"\n\
233 print \"Complete\\n\"\n";
235 char _Europe_code[] =
236 "print \"##### Band Change to European operation #####\\n\"\n\
239 set senddelay 0.05\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\
247 print \"Timeout Error communicating with device.\n\"\n\
250 print \"Error response from device.\n\"\n\
253 print \"Complete\\n\"\n";
258 set senddelay 0.05\n\
268 let $s=$right($s,a)\n\
269 if $s <> \"0,0\" goto sigcont\n\
270 if c > 3 goto sigexit\n\
275 print \"Signal strength measure 0,0 too low!\"\n\
278 print \"Signal Quality:\",$s,\"\\n\"\n\
285 set senddelay 0.05\n\
287 print \"Waiting for Registration\"\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\
296 if c > 120 goto regtimeout\n\
301 print \"\nFailed to register\n\"\n\
304 print \"\nRegistered on Home network: \"\n\
307 print \"\nRegistered on Roaming network: \"\n\
311 send \"AT+COPS?^m\"\n\
316 if b < 1 goto regtimeout\n\
317 let $c=$right($s,b)\n\
320 char _3G2G_mode_code[] =
323 set senddelay 0.05\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\
331 print \"Timeout Error communicating with device.\n\"\n\
334 print \"Error response from device.\n\"\n\
337 print \"Set 3G preferred mode\\n\"\n";
340 char _3G_mode_code[] =
343 set senddelay 0.05\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\
351 print \"Timeout Error communicating with device.\n\"\n\
354 print \"Error response from device.\n\"\n\
357 print \"Set 3G only mode\\n\"\n";
359 char _2G_mode_code[] =
362 set senddelay 0.05\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\
370 print \"Timeout Error communicating with device.\n\"\n\
373 print \"Error response from device.\n\"\n\
376 print \"Set 2G only mode\\n\"\n";
378 char _GTEDGE_code[] =
381 send \"AT+CFUN=1^m\"\n\
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" ;
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);