Change in pysim[master]: ts_51_011: move _decode_select_response into profile class

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

dexter gerrit-no-reply at lists.osmocom.org
Thu Nov 11 11:41:30 UTC 2021


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/26205 )


Change subject: ts_51_011: move _decode_select_response into profile class
......................................................................

ts_51_011: move _decode_select_response into profile class

The method decode_select_response just calls the function
_decode_select_response. But the function _decode_select_response
is not called from any other location, so we can move it into the
profile class.

Change-Id: Icf0143f64ca7d1c1ebf60ba06585f7afc1ac0d11
---
M pySim/ts_51_011.py
1 file changed, 38 insertions(+), 44 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/05/26205/1

diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py
index 2742218..3bec516 100644
--- a/pySim/ts_51_011.py
+++ b/pySim/ts_51_011.py
@@ -932,48 +932,6 @@
           ]
         self.add_files(files)
 
-
-
-def _decode_select_response(resp_hex):
-
-    resp_bin = h2b(resp_hex)
-    struct_of_file_map = {
-        0: 'transparent',
-        1: 'linear_fixed',
-        3: 'cyclic'
-        }
-    type_of_file_map = {
-        1: 'mf',
-        2: 'df',
-        4: 'working_ef'
-        }
-    ret = {
-        'file_descriptor': {},
-        'proprietary_info': {},
-        }
-    ret['file_id'] = b2h(resp_bin[4:6])
-    ret['proprietary_info']['available_memory'] = int.from_bytes(resp_bin[2:4], 'big')
-    file_type = type_of_file_map[resp_bin[6]] if resp_bin[6] in type_of_file_map else resp_bin[6]
-    ret['file_descriptor']['file_type'] = file_type
-    if file_type in ['mf', 'df']:
-        ret['file_characteristics'] = b2h(resp_bin[13:14])
-        ret['num_direct_child_df'] = resp_bin[14]
-        ret['num_direct_child_ef'] = resp_bin[15]
-        ret['num_chv_unblock_adm_codes'] = int(resp_bin[16])
-        # CHV / UNBLOCK CHV stats
-    elif file_type in ['working_ef']:
-        file_struct = struct_of_file_map[resp_bin[13]] if resp_bin[13] in struct_of_file_map else resp_bin[13]
-        ret['file_descriptor']['structure'] = file_struct
-        ret['access_conditions'] = b2h(resp_bin[8:10])
-        if resp_bin[11] & 0x01 == 0:
-            ret['life_cycle_status_int'] = 'operational_activated'
-        elif resp_bin[11] & 0x04:
-            ret['life_cycle_status_int'] = 'operational_deactivated'
-        else:
-            ret['life_cycle_status_int'] = 'terminated'
-
-    return ret
-
 class CardProfileSIM(CardProfile):
     def __init__(self):
         sw = {
@@ -1014,8 +972,44 @@
           }
 
         super().__init__('SIM', desc='GSM SIM Card', cla="a0", sel_ctrl="0000", files_in_mf=[DF_TELECOM(), DF_GSM()], sw=sw)
-    def decode_select_response(self, data_hex:str) -> Any:
-	    return _decode_select_response(data_hex)
+
+    def decode_select_response(self, resp_hex:str) -> Any:
+        resp_bin = h2b(resp_hex)
+        struct_of_file_map = {
+            0: 'transparent',
+            1: 'linear_fixed',
+            3: 'cyclic'
+            }
+        type_of_file_map = {
+            1: 'mf',
+            2: 'df',
+            4: 'working_ef'
+            }
+        ret = {
+            'file_descriptor': {},
+            'proprietary_info': {},
+            }
+        ret['file_id'] = b2h(resp_bin[4:6])
+        ret['proprietary_info']['available_memory'] = int.from_bytes(resp_bin[2:4], 'big')
+        file_type = type_of_file_map[resp_bin[6]] if resp_bin[6] in type_of_file_map else resp_bin[6]
+        ret['file_descriptor']['file_type'] = file_type
+        if file_type in ['mf', 'df']:
+            ret['file_characteristics'] = b2h(resp_bin[13:14])
+            ret['num_direct_child_df'] = resp_bin[14]
+            ret['num_direct_child_ef'] = resp_bin[15]
+            ret['num_chv_unblock_adm_codes'] = int(resp_bin[16])
+            # CHV / UNBLOCK CHV stats
+        elif file_type in ['working_ef']:
+            file_struct = struct_of_file_map[resp_bin[13]] if resp_bin[13] in struct_of_file_map else resp_bin[13]
+            ret['file_descriptor']['structure'] = file_struct
+            ret['access_conditions'] = b2h(resp_bin[8:10])
+            if resp_bin[11] & 0x01 == 0:
+                ret['life_cycle_status_int'] = 'operational_activated'
+            elif resp_bin[11] & 0x04:
+                ret['life_cycle_status_int'] = 'operational_deactivated'
+            else:
+                ret['life_cycle_status_int'] = 'terminated'
+        return ret
 
     @staticmethod
     def match_with_card(scc:SimCardCommands) -> bool:

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/26205
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Icf0143f64ca7d1c1ebf60ba06585f7afc1ac0d11
Gerrit-Change-Number: 26205
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211111/6492c59a/attachment.htm>


More information about the gerrit-log mailing list