add chaos_calmer branch
[15.05/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+CPIN?^m"
11  waitfor 15 "SIM PUK","SIM PIN","READY","ERROR","ERR"
12  if % = -1 goto timeout
13  if % = 0 goto ready
14  if % = 1 goto setpin
15  if % = 2 goto ready
16  if % = 3 goto checkrepeat
17  if % = 4 goto checkrepeat
18
19 :checkrepeat
20  inc c
21  if c>3 goto pinerror
22  waitquiet 12 0.5
23  goto start
24
25 :timeout
26  print "timeout checking for PIN."
27  exit 1
28
29 :ready
30  print "SIM ready\n"
31  goto continue
32  exit 0
33
34 :setpin
35  # check if output was "SIM PIN2", that's ok.
36  waitfor 1 "2"
37  if % = 0 goto ready
38
39  print "Trying to set PIN\n"
40  send "AT+CPIN=\""
41  send $env("PINCODE")
42  send "\"^m"
43
44  waitfor 20 "OK","ERR"
45  if % = -1 goto pinerror
46  if % = 0 goto continue
47  if % = 1 goto pinerror
48
49 :pinerror
50  print "Error setting PIN, check card manually\n"
51  exit 1
52
53 :continue
54  print "PIN set successfully\n"
55  exit 0