https://osmocom.org/https://osmocom.org/favicon.ico?16647414092020-05-05T15:39:11ZOpen Source Mobile CommunicationspySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=181612020-05-05T15:39:11Zlaforge
<ul><li><b>Checklist item</b> <input type='checkbox' class='checklist-checkbox' disabled> <i>verify sysmoISIM-SJA2 fix</i> added</li><li><b>Checklist item</b> <input type='checkbox' class='checklist-checkbox' disabled> <i>ensure we have a test covering all PLMN files are written correctly</i> added</li><li><b>Checklist item</b> <input type='checkbox' class='checklist-checkbox' disabled> <i>port fix to WavemobileSIM (if needed, maybe it doesn't haven have that EF?)</i> added</li><li><strong>Subject</strong> changed from <i>support writing the various PLMN files</i> to <i>fix writing the various PLMN files</i></li><li><strong>Assignee</strong> set to <i>dexter</i></li><li><strong>Priority</strong> changed from <i>Low</i> to <i>High</i></li></ul><p>Contrary to my original assumption, we actually do have code to write them. This code is used in both SysmoUSIMSJS1 and FairwavesSIM. However, the code is missing from the sysmoISIMSJA2 (and also from WavemobileSIM).</p>
<p><a class="user active" href="https://osmocom.org/users/15">dexter</a>, I created a trivial fix for the sysmoISIMSJA2, see <a class="external" href="https://gerrit.osmocom.org/c/pysim/+/18051">https://gerrit.osmocom.org/c/pysim/+/18051</a></p>
<p>Please verify this patch, make sure we have test coverage (our tests didn't discover this bug, they should!) and also consider expanding the fix to WavemobileSIM</p> pySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=181622020-05-05T15:39:50Zlaforge
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/18162/diff?detail_id=30097">diff</a>)</li></ul> pySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=182462020-05-11T11:45:36Zdexter
<ul><li><b>Checklist item</b> <input type='checkbox' class='checklist-checkbox' checked disabled> <i>verify sysmoISIM-SJA2 fix</i> set to Done</li><li><strong>File</strong> <a href="/attachments/4133">mksim_sja2.sh</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/4133/mksim_sja2.sh">mksim_sja2.sh</a> added</li><li><strong>File</strong> <a href="/attachments/4134">sysmo_usim_sja2_after_write.txt</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/4134/sysmo_usim_sja2_after_write.txt">sysmo_usim_sja2_after_write.txt</a> added</li><li><strong>File</strong> <a href="/attachments/4135">sysmo_usim_sja2_before_write.txt</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/4135/sysmo_usim_sja2_before_write.txt">sysmo_usim_sja2_before_write.txt</a> added</li><li><strong>Status</strong> changed from <i>New</i> to <i>In Progress</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>20</i></li></ul><p>I have checked the problem back and from what I can see PLMNsel, PLMNwAcT, OPLMNwAcT, HPLMNAcT are updated. I have attached the output of pySim-Read.py before and after the write. So from what I can see the patch is working fine.</p> pySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=182732020-05-12T12:11:14Zlaforge
<ul></ul><p>There are some open questions on the correctness of the encoding of the files (see related sysmocom customer support inquiry)</p> pySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=183062020-05-12T16:44:32Zdexter
<ul></ul><p>The implementation of enc_plmn() in utils.py seems have a problem with padding unused digits correctly.</p>
<p>See 3GPP TS 51.011, 10.3.4 gives an example, lets try encoding it manually and see if the result matches up</p>
<pre>
246 81 MCC/MNC
246F81 Padd unused digit with 0xF
42F618 Swap nibbles (matches also output of enc_plmn()
</pre>
<p>And now lets try the PLMN we try to use</p>
<pre>
262 02
262F02
62F220
</pre><br />When calling enc_plmn() manually with 262 02, we get: 62f22f
<p>I think the way enc_plmn handles leading zeros is wrong.</p> pySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=183072020-05-12T17:00:14Zdexter
<ul><li><strong>File</strong> <a href="/attachments/4136">mobilcom_sim.txt</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/4136/mobilcom_sim.txt">mobilcom_sim.txt</a> added</li></ul><p>I had a look at a simcard from a productive network. There the leading zeros of the MNC are also preserved but what confuses me is that the PLMNsel file does not start with 62f210, which would be the home network (262 01).</p>
<p>Here is what what the beginning of my PLMNsel looks like:<br /><pre>
32f23012f47022f21002f8100
32f230 => 232f03 => 232 03
12f470 => 214f07 => 214 07
</pre></p>
<p>Attached one can find the dump from the simcard I used for this test.</p> pySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=183082020-05-12T18:31:56Zlaforge
<ul></ul><p>In case this is not obvious: MNCs come as 2-digit MNC or as 3-digit MNC.</p>
<p>Hence, 262-02 and 262-002 are different networks.</p>
<p>The encoding as per TS 04.08 is implemented in libosmocore for more than a decade and we use it pretty much anywhre on the radio interface, whether in RR or MM or other sub-layers such as BSSMAP. They python code should just simply replicate what the C code is doing.</p>
The encoding of the above two examples should be:
<ul>
<li>262-02 -> 62F220</li>
<li>262-002 -> 620220</li>
</ul>
<p>Furthermore, it is not surprising that EF_PLMNsel doesn't list the home operator (derived from the IMSI prefix). In classic 2G SIM cards, the home network is always derived from the IMSI prefix, and it cannot be overridden. Only in USIM, it is possible that the HPLMN MCC/MNC is explicitly set different (e.g. like the EF_HPLMNwAcT</p> pySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=183092020-05-12T19:15:13Zlaforge
<ul></ul>It seems like pySim unfortunately treats mnc as integer. So there is no way to know if the user entererd 02 or 002 (referring to the above example). I suggest to
<ul>
<li>treat MNC as a string</li>
<li>verify that it only contains decimal digits</li>
<li>pad it to three characters length (if it is 2 only) using a leading F</li>
<li>then concatenate + nibble-swap with the MCC in enc_plmn()</li>
</ul>
<p>I hacked this up in <a class="external" href="https://gerrit.osmocom.org/c/pysim/+/18225">https://gerrit.osmocom.org/c/pysim/+/18225</a> and it seemed to work locally with both 2-digit and 3-digit MNC as well as 1/2/3 digit MCC.</p> pySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=183352020-05-14T19:29:27Zlaforge
<ul><li><strong>% Done</strong> changed from <i>20</i> to <i>70</i></li></ul><p>patch has been merged. <a class="user active" href="https://osmocom.org/users/15">dexter</a>, please check the two missing checklist items in this ticket and take any action, if required.</p> pySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=208872021-01-20T20:56:25Zlaforge
<ul><li><strong>Status</strong> changed from <i>In Progress</i> to <i>Stalled</i></li></ul> pySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=218892021-04-11T12:59:05Zlaforge
<ul></ul><p>laforge wrote:</p>
<blockquote>
<p>patch has been merged. <a class="user active" href="https://osmocom.org/users/15">dexter</a>, please check the two missing checklist items in this ticket and take any action, if required.</p>
</blockquote>
<p><a class="user active" href="https://osmocom.org/users/15">dexter</a>, it has been 11 months on a "high" priority, but still no update?</p> pySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=220462021-05-03T18:52:25Zdexter
<ul><li><b>Checklist item</b> <input type='checkbox' class='checklist-checkbox' checked disabled> <i>ensure we have a test covering all PLMN files are written correctly</i> set to Done</li><li><b>Checklist item</b> <input type='checkbox' class='checklist-checkbox' checked disabled> <i>port fix to WavemobileSIM (if needed, maybe it doesn't haven have that EF?)</i> set to Done</li></ul> pySim - Feature #4532: fix writing the various PLMN fileshttps://osmocom.org/issues/4532?journal_id=220472021-05-03T19:04:02Zdexter
<ul><li><strong>Status</strong> changed from <i>Stalled</i> to <i>Resolved</i></li><li><strong>% Done</strong> changed from <i>70</i> to <i>100</i></li></ul><p>I have checked the test data of sysmo-usim-sjs1 and sysmo-isim-sja2, both write PLMNsel, PLMNwAcT, OPLMNwAcT and HPLMNAcT with pySim-prog.py and re-read them with pySim-read.py. The same is true for WavemobileSIM, but it seems not to have HPLMNAcT on the card (we also do not make any write attemts, but pySim-read.py complains). So from what I can see we should be fine as far as this ticket is concerned.</p>