commit b18cce63535b75f875f98210fe3b29d6316ea784
Author: yann.lopez <yann.lopez@gmail.com>
Date:   Mon Mar 29 18:07:28 2010 +0200

    Prevent lock of 3G dongle by adding a new parameter and send different return code according SIM response

diff --git a/package/comgt/files/3g.sh b/package/comgt/files/3g.sh
index 8fcac09..607b67b 100644
--- a/package/comgt/files/3g.sh
+++ b/package/comgt/files/3g.sh
@@ -40,6 +40,11 @@ setup_interface_3g() {
 	local config="$2"
 	local chat="/etc/chatscripts/3g.chat"
 	
+	config_get wrong_pincode $config wrong_pincode
+	[ $wrong_pincode -a $wrong_pincode = "1" ] && {
+                echo "PIN has already been tested and it does not work"
+                return 1                              
+        }                                    
 	config_get device "$config" device
 	config_get maxwait "$config" maxwait
 	maxwait=${maxwait:-20}
@@ -80,9 +85,17 @@ setup_interface_3g() {
 			mode="AT_OPSYS=${CODE}"
 		fi
 		# Don't assume Option to be default as it breaks with Huawei Cards/Sticks
-		
-		PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || {
+		PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom 
+		RESULT=$?
+		[ $RESULT -gt 1 ] && {
 			echo "$config(3g): Failed to set the PIN code."
+			[ $wrong_pincode ] && {
+				uci_set "network" "$config" "wrong_pincode" "1"
+				[ $RESULT -eq 3 ] && {
+					uci_set "network" "$config" "puk_needed" "1"
+				}
+				uci_commit "network"
+			}
 			set_3g_led 0 0 0
 			return 1
 		}
diff --git a/package/comgt/files/setpin.gcom b/package/comgt/files/setpin.gcom
index 66350fe..fc9e769 100644
--- a/package/comgt/files/setpin.gcom
+++ b/package/comgt/files/setpin.gcom
@@ -10,7 +10,7 @@ opengt
  send "AT+CPIN?^m"
  waitfor 15 "SIM PUK","SIM PIN","READY","ERROR","ERR"
  if % = -1 goto timeout
- if % = 0 goto ready
+ if % = 0 goto setpuk
  if % = 1 goto setpin
  if % = 2 goto ready
  if % = 3 goto checkrepeat
@@ -31,6 +31,10 @@ opengt
  goto continue
  exit 0
 
+:setpuk
+ print "Error code PUK needed"
+ exit 3
+
 :setpin
  # check if output was "SIM PIN2", that's ok.
  waitfor 1 "2"
@@ -48,7 +52,7 @@ opengt
 
 :pinerror
  print "Error setting PIN, check card manually\n"
- exit 1
+ exit 2
 
 :continue
  print "PIN set successfully\n"
