__init__: allow wildcards in expected SW for send_apdu_checksw()

The method send_apdu_checksw() is used to check the SW of the final
response against some pre defined value. However, in many cases the
last two digits of the SW are used to return varying information
(e.g. length information or a more specific status info). To cover
those cases it would be helfpul to define status words that contain
wildcards (e.g. 61**) in order to be able to accept all SWs from
6100 to 61ff.

- When the user supplies an expected SW with wildcards, mask out
  those digits in the response before comparing

Change-Id: I5bfc0522b4228b5d9b3415f6e708abcf0da0a7b7
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index dd04bba..0a71117 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -77,12 +77,23 @@
 		"""send_apdu_checksw(pdu,sw): Sends an APDU and check returned SW
 
 		   pdu    : string of hexadecimal characters (ex. "A0A40000023F00")
-		   sw     : string of 4 hexadecimal characters (ex. "9000")
+		   sw     : string of 4 hexadecimal characters (ex. "9000"). The
+		            user may mask out certain digits using a '?' to add some
+		            ambiguity if needed.
 		   return : tuple(data, sw), where
 		            data : string (in hex) of returned data (ex. "074F4EFFFF")
 		            sw   : string (in hex) of status word (ex. "9000")
 		"""
 		rv = self.send_apdu(pdu)
-		if sw.lower() != rv[1]:
+
+                # Create a masked version of the returned status word
+		sw_masked = ""
+		for i in range(0, 4):
+			if sw.lower()[i] == '?':
+				sw_masked = sw_masked + '?'
+			else:
+				sw_masked = sw_masked + rv[1][i].lower()
+
+		if sw.lower() != sw_masked:
 			raise RuntimeError("SW match failed ! Expected %s and got %s." % (sw.lower(), rv[1]))
 		return rv