aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Chemeris <Alexander.Chemeris@gmail.com>2018-01-27 02:06:30 +0900
committerAlexander Chemeris <Alexander.Chemeris@gmail.com>2018-01-27 02:06:30 +0900
commit1198ad9e155fd65764b15f93729e1c625b36ace3 (patch)
treefc3b87b157570b26d8fae28043fa4a45cfbdfaf5
parentcc85a1ee7108a4190217d67676bbc83d505f5a3a (diff)
utils: Add a function to decode SELECT result for EF files.
-rw-r--r--pySim/utils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/pySim/utils.py b/pySim/utils.py
index 757394f..422af1e 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -113,3 +113,22 @@ def calculate_luhn(cc):
num = map(int, str(cc))
check_digit = 10 - sum(num[-2::-2] + [sum(divmod(d * 2, 10)) for d in num[::-2]]) % 10
return 0 if check_digit == 10 else check_digit
+
+def dec_select_ef_response(response):
+ '''
+ As defined in the TS 151.011 9.2.1 SELECT
+ '''
+
+ length = int(response[4:8], 16)
+ file_id = response[8:12]
+ file_type = response[12:14]
+ increase_cmd = response[14:16]
+ access_cond = response[16:22]
+ file_status = response[22:24]
+ data_len = int(response[24:26], 16)
+ ef_struct = response[26:28]
+ if len(response) >= 30:
+ record_len = int(response[28:30], 16)
+ else:
+ record_len = 0
+ return (length, file_id, file_type, increase_cmd, access_cond, file_status, data_len, ef_struct, record_len)