<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/23658">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">ts_51_011: Full encoder/decoder for EF.AD<br><br>The EF.AD class only had a partial decoder and no encoder before this<br>patch.<br><br>You can now do things like<br><br>pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded<br>{<br>    "ms_operation_mode": "normal_and_specific_facilities",<br>    "specific_facilities": {<br>        "ofm": false<br>    },<br>    "len_of_mnc_in_imsi": 2<br>}<br>pySIM-shell (MF/ADF.USIM/EF.AD)> update_binary_decoded '{"ms_operation_mode": "normal_and_specific_facilities", "specific_facilities": {"ofm": false}, "len_of_mnc_in_imsi": 3}'<br><br>not quite all that elegant yet, but working at all.<br><br>Change-Id: Id2cb66cb26b6bd08befe9f8468b0b0773da842b1<br>---<br>M pySim/ts_51_011.py<br>1 file changed, 18 insertions(+), 6 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/58/23658/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py</span><br><span>index a671f31..bd71114 100644</span><br><span>--- a/pySim/ts_51_011.py</span><br><span>+++ b/pySim/ts_51_011.py</span><br><span>@@ -502,17 +502,29 @@</span><br><span> # TS 51.011 Section 10.3.18</span><br><span> class EF_AD(TransparentEF):</span><br><span>     OP_MODE = {</span><br><span style="color: hsl(0, 100%, 40%);">-            0x00: 'normal operation',</span><br><span style="color: hsl(0, 100%, 40%);">-            0x80: 'type approval operations',</span><br><span style="color: hsl(0, 100%, 40%);">-            0x01: 'normal operation + specific facilities',</span><br><span style="color: hsl(0, 100%, 40%);">-            0x81: 'type approval + specific facilities',</span><br><span style="color: hsl(0, 100%, 40%);">-            0x02: 'maintenance (off line)',</span><br><span style="color: hsl(0, 100%, 40%);">-            0x04: 'cell test operation',</span><br><span style="color: hsl(120, 100%, 40%);">+            0x00: 'normal',</span><br><span style="color: hsl(120, 100%, 40%);">+            0x80: 'type_approval',</span><br><span style="color: hsl(120, 100%, 40%);">+            0x01: 'normal_and_specific_facilities',</span><br><span style="color: hsl(120, 100%, 40%);">+            0x81: 'type_approval_and_specific_facilities',</span><br><span style="color: hsl(120, 100%, 40%);">+            0x02: 'maintenance_off_line',</span><br><span style="color: hsl(120, 100%, 40%);">+            0x04: 'cell_test',</span><br><span>         }</span><br><span style="color: hsl(120, 100%, 40%);">+    OP_MODE_reverse = dict(map(reversed, OP_MODE.items()))</span><br><span>     def __init__(self, fid='6fad', sfid=None, name='EF.AD', desc='Administrative Data', size={3,4}):</span><br><span>         super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)</span><br><span>     def _decode_bin(self, raw_bin):</span><br><span>         u = unpack('!BH', raw_bin[:3])</span><br><span style="color: hsl(120, 100%, 40%);">+        ofm = True if u[1] & 1 else False</span><br><span style="color: hsl(120, 100%, 40%);">+        res = {'ms_operation_mode': self.OP_MODE.get(u[0], u[0]), 'specific_facilities': { 'ofm': ofm } }</span><br><span style="color: hsl(120, 100%, 40%);">+        if len(raw_bin) > 3:</span><br><span style="color: hsl(120, 100%, 40%);">+            res['len_of_mnc_in_imsi'] = int(raw_bin[3]) & 0xf</span><br><span style="color: hsl(120, 100%, 40%);">+        return res</span><br><span style="color: hsl(120, 100%, 40%);">+    def _encode_bin(self, abstract):</span><br><span style="color: hsl(120, 100%, 40%);">+        op_mode = self.OP_MODE_reverse[abstract['ms_operation_mode']]</span><br><span style="color: hsl(120, 100%, 40%);">+        res = pack('!BH', op_mode, abstract['specific_facilities']['ofm'])</span><br><span style="color: hsl(120, 100%, 40%);">+        if 'len_of_mnc_in_imsi' in abstract:</span><br><span style="color: hsl(120, 100%, 40%);">+            res += pack('!B', abstract['len_of_mnc_in_imsi'])</span><br><span style="color: hsl(120, 100%, 40%);">+        return res</span><br><span> </span><br><span> # TS 51.011 Section 10.3.13</span><br><span> class EF_CBMID(EF_CBMI):</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/23658">change 23658</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/pysim/+/23658"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: pysim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Id2cb66cb26b6bd08befe9f8468b0b0773da842b1 </div>
<div style="display:none"> Gerrit-Change-Number: 23658 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>