From b271be3dc009cfe6c17d4e9fdd389e147975b77a Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Thu, 11 Mar 2021 23:56:58 +0100 Subject: Revert "utils.py: Fix for parsing MNC" This reverts commit bdf3d3597b5d8e4260f80a00ada78e9ad612b00b, which broke pySim.utils.dec_mnc_from_plmn(). According to 3GPP TS 31.102, which points to TS 24.008, the three-digit EHPLMN shall be encoded as shown below (ASCII-art interpretation): 0 1 2 3 4 5 6 7 +---+---+---+---+---+---+---+---+ | MCC Digit 2 | MCC Digit 1 | +---+---+---+---+---+---+---+---+ | MNC Digit 3 | MCC Digit 3 | +---+---+---+---+---+---+---+---+ | MNC Digit 2 | MNC Digit 1 | +---+---+---+---+---+---+---+---+ So the original implementation was correct, and we even had a unit test for it. Most likely, the SIM card itself was programmed incorrectly? Makes 'testDecMNCfromPLMN_threeDigitMNC' pass again. Change-Id: If6bf5383988ad442e275efc7c5a159327d104879 --- pySim/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pySim/utils.py b/pySim/utils.py index 6dbd980..b49a437 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -140,9 +140,9 @@ def dec_mcc_from_plmn(plmn): def dec_mnc_from_plmn(plmn): ia = h2i(plmn) - digit1 = (ia[1] & 0xF0) >>4 # 2nd byte, MSB - digit2 = ia[2] & 0x0F # 3rd byte, LSB - digit3 = (ia[2] & 0xF0) >> 4 # 3nd byte, MSB + digit1 = ia[2] & 0x0F # 3rd byte, LSB + digit2 = (ia[2] & 0xF0) >> 4 # 3rd byte, MSB + digit3 = (ia[1] & 0xF0) >> 4 # 2nd byte, MSB if digit3 == 0xF and digit2 == 0xF and digit1 == 0xF: return 0xFFF # 4095 return derive_mnc(digit1, digit2, digit3) -- cgit v1.2.3