comgt-3g: enable modem before to setpin
[openwrt/openwrt.git] / package / network / utils / comgt / files / setpin.gcom
1 # set pin code from evnironment "$PINCODE"
2 opengt
3 set com 115200n81
4 set senddelay 0.05
5 waitquiet 3 0.5
6 flash 0.1
7
8 let c=0
9 :start
10 send "AT+CFUN=1^m"
11 send "AT+CPIN?^m"
12 waitfor 15 "SIM PUK","SIM PIN","READY","ERROR","ERR"
13 if % = -1 goto timeout
14 if % = 0 goto ready
15 if % = 1 goto setpin
16 if % = 2 goto ready
17 if % = 3 goto checkrepeat
18 if % = 4 goto checkrepeat
19
20 :checkrepeat
21 inc c
22 if c>3 goto pinerror
23 waitquiet 12 0.5
24 goto start
25
26 :timeout
27 print "timeout checking for PIN."
28 exit 1
29
30 :ready
31 print "SIM ready\n"
32 goto continue
33 exit 0
34
35 :setpin
36 # check if output was "SIM PIN2", that's ok.
37 waitfor 1 "2"
38 if % = 0 goto ready
39
40 print "Trying to set PIN\n"
41 send "AT+CPIN=\""
42 send $env("PINCODE")
43 send "\"^m"
44
45 waitfor 20 "OK","ERR"
46 if % = -1 goto pinerror
47 if % = 0 goto continue
48 if % = 1 goto pinerror
49
50 :pinerror
51 print "Error setting PIN, check card manually\n"
52 exit 1
53
54 :continue
55 print "PIN set successfully\n"
56 exit 0