<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/20171">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">utils.py: Add helper method to encode Service Table<br><br>This method helps in encoding of Service Tables in EF.SST, EF.UST, EF.EST, EF.IST.<br>Takes original hex string of EF.SST, EF.UST, EF.EST, EF.IST, Service number,<br>Service to be enabled or disable flag as input and outputs the modified Service Table.<br><br>Change-Id: I0c97317d5a17aa0df720659d021b5cbf7d30edcc<br>---<br>M pySim/utils.py<br>1 file changed, 43 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim/utils.py b/pySim/utils.py</span><br><span>index dc14d58..d0d6cb5 100644</span><br><span>--- a/pySim/utils.py</span><br><span>+++ b/pySim/utils.py</span><br><span>@@ -460,6 +460,49 @@</span><br><span>                        bytelist = bytelist[ L+2 : ]</span><br><span>         return ret</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+def enc_st(st, service, state=1):</span><br><span style="color: hsl(120, 100%, 40%);">+     """</span><br><span style="color: hsl(120, 100%, 40%);">+    Encodes the EF S/U/IST/EST and returns the updated Service Table</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    Parameters:</span><br><span style="color: hsl(120, 100%, 40%);">+           st - Current value of SIM/USIM/ISIM Service Table</span><br><span style="color: hsl(120, 100%, 40%);">+             service - Service Number to encode as activated/de-activated</span><br><span style="color: hsl(120, 100%, 40%);">+          state - 1 mean activate, 0 means de-activate</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        Returns:</span><br><span style="color: hsl(120, 100%, 40%);">+              s - Modified value of SIM/USIM/ISIM Service Table</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   Default values:</span><br><span style="color: hsl(120, 100%, 40%);">+               - state: 1 - Sets the particular Service bit to 1</span><br><span style="color: hsl(120, 100%, 40%);">+     """</span><br><span style="color: hsl(120, 100%, 40%);">+    st_bytes = [st[i:i+2] for i in range(0, len(st), 2) ]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       s = ""</span><br><span style="color: hsl(120, 100%, 40%);">+      # Check whether the requested service is present in each byte</span><br><span style="color: hsl(120, 100%, 40%);">+ for i in range(0, len(st_bytes)):</span><br><span style="color: hsl(120, 100%, 40%);">+             # Byte i contains info about Services num (8i+1) to num (8i+8)</span><br><span style="color: hsl(120, 100%, 40%);">+                if service in range((8*i) + 1, (8*i) + 9):</span><br><span style="color: hsl(120, 100%, 40%);">+                    byte = int(st_bytes[i], 16)</span><br><span style="color: hsl(120, 100%, 40%);">+                   # Services in each byte are in order MSB to LSB</span><br><span style="color: hsl(120, 100%, 40%);">+                       # MSB - Service (8i+8)</span><br><span style="color: hsl(120, 100%, 40%);">+                        # LSB - Service (8i+1)</span><br><span style="color: hsl(120, 100%, 40%);">+                        mod_byte = 0x00</span><br><span style="color: hsl(120, 100%, 40%);">+                       # Copy bit by bit contents of byte to mod_byte with modified bit</span><br><span style="color: hsl(120, 100%, 40%);">+                      # for requested service</span><br><span style="color: hsl(120, 100%, 40%);">+                       for j in range(1, 9):</span><br><span style="color: hsl(120, 100%, 40%);">+                         mod_byte = mod_byte >> 1</span><br><span style="color: hsl(120, 100%, 40%);">+                                if service == (8*i) + j:</span><br><span style="color: hsl(120, 100%, 40%);">+                                      mod_byte = state == 1 and mod_byte|0x80 or mod_byte&0x7f</span><br><span style="color: hsl(120, 100%, 40%);">+                          else:</span><br><span style="color: hsl(120, 100%, 40%);">+                                 mod_byte = byte&0x01 == 0x01 and mod_byte|0x80 or mod_byte&0x7f</span><br><span style="color: hsl(120, 100%, 40%);">+                               byte = byte >> 1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                      s += ('%02x' % (mod_byte))</span><br><span style="color: hsl(120, 100%, 40%);">+            else:</span><br><span style="color: hsl(120, 100%, 40%);">+                 s += st_bytes[i]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    return s</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> def dec_epdgid(hexstr):</span><br><span>        """</span><br><span>   Decode ePDG Id to get EF.ePDGId or EF.ePDGIdEm.</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/20171">change 20171</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/+/20171"/><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: I0c97317d5a17aa0df720659d021b5cbf7d30edcc </div>
<div style="display:none"> Gerrit-Change-Number: 20171 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: herlesupreeth <herlesupreeth@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: herlesupreeth <herlesupreeth@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>