Beispiel #1
0
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc: uicc = arg_components.modeler.uicc

        set_content = None
        dict_args = convert_arguments_to_dict(arg_arguments)
        for key, value in dict_args.items():
            if key == "set":
                set_content = value

        uicc_resp: uicc_sel_resp = uicc.select(UICC_FILE.ICCID)
        read_resp = uicc.read_binary(uicc_resp)
        if read_resp != None:
            print(self.get_res("original").format(convert_bcd_to_string(read_resp), toHexString(read_resp)))

            if set_content != None and self.is_update_require_adm == uicc.adm_verified:
                original = convert_bcd_to_string(read_resp)
                update_content = set_content + original[len(set_content):]

                if uicc.update_binary(convert_string_to_bcd(update_content)) == ERROR.NONE:
                    print(self.get_res("updated").format(update_content, toHexString(convert_string_to_bcd(update_content))))
                else:
                    print(self.get_res("update_error"))

        else:
            print(self.get_res("read_error"))

        log.debug(self.__class__.__name__, "EXIT")
Beispiel #2
0
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc_resp: uicc_sel_resp = None
        uicc: uicc = arg_components.modeler.uicc

        set_content = None

        dict_args = convert_arguments_to_dict(arg_arguments)
        for key, value in dict_args.items():
            if key == "set":
                set_content = value

        # read EF_IMSI
        uicc_resp = uicc.select(UICC_FILE.IMSI)
        read_resp = uicc.read_binary(uicc_resp)
        if read_resp == None:
            print(self.get_res("read_error"))
            return

        # RAW IMSI: 08 09 10 10 10 32 54 76 98
        #              -  --------------------
        # Convert 09 10 10 10 32 54 76 98 => 9001010123456789
        # Ignore 1st char, and just use '001010123456789'
        print(
            self.get_res("original").format(
                convert_bcd_to_string(read_resp[1:])[1:],
                toHexString(read_resp)))

        if set_content != None and self.is_update_require_adm == uicc.adm_verified:
            imsi_update_content = read_resp[:]

            for i in range(len(set_content)):
                if i == 15:
                    break
                Idx_of_PayLoad = int(((i + 1) / 2) + 1)
                Mod_Value = (i % 2)

                if Mod_Value == 0:
                    imsi_update_content[Idx_of_PayLoad] = (
                        imsi_update_content[Idx_of_PayLoad]
                        & 0x0F) + (int(set_content[i]) << 4)
                else:
                    imsi_update_content[Idx_of_PayLoad] = (
                        imsi_update_content[Idx_of_PayLoad] & 0xF0) + int(
                            set_content[i])

            if uicc.update_binary(imsi_update_content) != ERROR.NONE:
                print(self.get_res("update_error"))
                return

            print(
                self.get_res("updated").format(
                    convert_bcd_to_string(imsi_update_content[1:])[1:],
                    toHexString(imsi_update_content)))

        log.debug(self.__class__.__name__, "EXIT")
Beispiel #3
0
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc: uicc = arg_components.modeler.uicc

        change_pin1_state_key = None
        dict_args = convert_arguments_to_dict(arg_arguments)
        for key, value in dict_args.items():
            if key == "pin1":
                change_pin1_state_key = value

        # change pin1 state
        if change_pin1_state_key != None:
            if is_valid_pin_code(change_pin1_state_key) == False:
                print(self.get_res("invalid_pin"))
            else:
                msg = None
                if uicc.pin_enabled:
                    ret_result, ret_retries = uicc.disable_pin(
                        toASCIIBytes(change_pin1_state_key))
                    msg = self.get_res(
                        'disable_ok') if ret_result == ERROR.NONE else self.get_res('disable_fail')
                else:
                    ret_result, ret_retries = uicc.enable_pin(
                        toASCIIBytes(change_pin1_state_key))
                    msg = self.get_res(
                        'enable_ok') if ret_result == ERROR.NONE else self.get_res('enable_fail')
                print(msg)

            print(os.linesep, end='')

        print(self.get_res("pin1").format(self.get_res("enable"),
                                          res.get_string("yes") if uicc.pin_enabled else res.get_string("no")))
        print(self.get_res("pin1").format(self.get_res("verify"),
                                          res.get_string("yes") if uicc.pin_verified else res.get_string("na")))

        ret_result, ret_retries = uicc.verify_pin(PIN_TYPE.PIN1, "")
        print(self.get_res("pin1").format(self.get_res("retries"), ret_retries))

        # space line
        print('')

        print(self.get_res("adm").format(self.get_res("verify"),
                                         res.get_string("yes") if uicc.adm_verified else res.get_string("no")))

        ret_result, ret_retries = uicc.verify_pin(PIN_TYPE.ADM1, "")
        print(self.get_res("adm").format(self.get_res("retries"), ret_retries))

        log.debug(self.__class__.__name__, "EXIT")
Beispiel #4
0
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc: uicc = arg_components.modeler.uicc

        ID_GID1 = 0
        ID_GID2 = 1
        gid_working_list = [["GID1", UICC_FILE.GID1, None],
                            ["GID2", UICC_FILE.GID2, None]]

        dict_args = convert_arguments_to_dict(arg_arguments)
        for key, value in dict_args.items():
            if key == "gid1":
                gid_working_list[ID_GID1][2] = toBytes(value)
            elif key == "gid2":
                gid_working_list[ID_GID2][2] = toBytes(value)

        for i in range(len(gid_working_list)):
            uicc_resp: uicc_sel_resp = uicc.select(gid_working_list[i][1])
            read_resp = uicc.read_binary(uicc_resp)
            if read_resp != None:
                print(self.get_res("original").format(
                    gid_working_list[i][0], toHexString(read_resp)))

                if gid_working_list[i][2] != None and self.is_update_require_adm == uicc.adm_verified:
                    update_content = read_resp[:]

                    update_len = len(gid_working_list[i][2])
                    if update_len > uicc_resp.length:
                        update_len = uicc_resp.length

                    for j in range(0, update_len):
                        update_content[j] = gid_working_list[i][2][j]

                    if uicc.update_binary(update_content) == ERROR.NONE:
                        print(self.get_res("updated").format(
                            toHexString(update_content)))
                    else:
                        print(self.get_res("update_error").format(
                            gid_working_list[i][0]))
            elif uicc_resp.sw1 == 0x6A and uicc_resp.sw1 == 0x82:
                print(self.get_res("not_exist").format(gid_working_list[i][0]))
            else:
                print(self.get_res("read_error").format(
                    gid_working_list[i][0]))

        log.debug(self.__class__.__name__, "EXIT")
Beispiel #5
0
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc: uicc = arg_components.modeler.uicc

        set_content = None
        dict_args = convert_arguments_to_dict(arg_arguments)
        for key, value in dict_args.items():
            if key == "set":
                set_content = value

        uicc_resp: uicc_sel_resp = uicc.select(UICC_FILE.SPN)
        read_resp = uicc.read_binary(uicc_resp)
        if read_resp != None:

            # 01 4D 49 4E 47 FF FF FF FF FF FF FF FF FF FF FF FF
            # First byte is 'display condition'
            # 2 to 17 is 'service provider name'
            print(
                self.get_res("original").format(convert_alpha_to_string(
                    read_resp[1:]),
                                                toHexString(read_resp),
                                                width=(uicc_resp.length - 1)))

            if set_content != None and self.is_update_require_adm == uicc.adm_verified:
                update_len = len(set_content)
                if update_len > (uicc_resp.length - 1):
                    update_len = (uicc_resp.length - 1)

                update_content = [0xFF] * uicc_resp.length
                update_content[0] = 0x01
                for i in range(update_len):
                    update_content[i + 1] = ord(set_content[i])

                if uicc.update_binary(update_content) == ERROR.NONE:
                    print(
                        self.get_res("updated").format(
                            convert_alpha_to_string(update_content[1:]),
                            toHexString(update_content),
                            width=(uicc_resp.length - 1)))
                else:
                    print(self.get_res("update_error"))

        else:
            print(self.get_res("read_error"))

        log.debug(self.__class__.__name__, "EXIT")
Beispiel #6
0
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc: uicc = arg_components.modeler.uicc

        set_record_id = None
        set_name_content = None
        set_num_content = None

        dict_args = convert_arguments_to_dict(arg_arguments)
        for key, value in dict_args.items():
            if key == "id":
                set_record_id = int(value)
            elif key == "name":
                set_name_content = value
            elif key == "num":
                set_num_content = value

        uicc_resp: uicc_sel_resp = uicc.select(UICC_FILE.MSISDN)

        if uicc_resp.sw1 == 0x90:
            if set_record_id != None and (set_record_id <= 0 or set_record_id > uicc_resp.count):
                print(self.get_res("invalid_id"))
            else:
                name_length = uicc_resp.length - 14
                print(self.get_res("original"))
                for i in range(uicc_resp.count):
                    resp = uicc.read_record(i+1, uicc_resp)
                    if resp != None:
                        self.show_record(i+1, resp, name_length)

                if set_record_id != None and (set_num_content != None or set_name_content != None):
                    update_apdu = uicc.read_record(set_record_id, uicc_resp)

                    if set_name_content != None:
                        # Name
                        update_name_len = len(set_name_content)
                        for i in range(name_length):
                            if i < update_name_len:
                                update_apdu[i] = ord(set_name_content[i])
                            else:
                                update_apdu[i] = 0xFF

                    if set_num_content != None:
                        # Num Length
                        if len(set_num_content) % 2 == 1:
                            update_apdu[name_length] = int(
                                len(set_num_content)/2) + 1
                        else:
                            update_apdu[name_length] = int(
                                len(set_num_content)/2)

                        # Num: BCD 10 (20 digits) + TON NPI
                        if update_apdu[name_length] > 11:
                            update_apdu[name_length] = 11

                        # '+' symbol
                        if len(set_num_content) > 0 and set_num_content[0] == "+":
                            update_apdu[name_length+1] = 0x91
                            set_num_content = set_num_content[1:]
                        else:
                            update_apdu[name_length+1] = 0x81

                        # Reset Number to 0xFF
                        for i in range(10):
                            update_apdu[name_length+1+1+i] = 0xFF

                        update_num_len = len(set_num_content)
                        if update_num_len > 20:
                            update_num_len = 10

                        num_apdu_index = name_length+1+1
                        for i in range(update_num_len):
                            tmp = set_num_content[i*2:i*2+2]
                            if len(tmp) == 2:
                                update_apdu[num_apdu_index +
                                            i] = (int(tmp[1]) * 16) + int(tmp[0])
                            elif len(tmp) == 1:
                                update_apdu[num_apdu_index+i] = (
                                    update_apdu[num_apdu_index+i] & 0xF0) + int(tmp[0])

                    if uicc.update_record(set_record_id, update_apdu) == ERROR.NONE:
                        print(self.get_res("updated"))
                        self.show_record(
                            set_record_id, update_apdu, name_length)
                    else:
                        print(self.get_res("update_error"))
        else:
            print(self.get_res("read_error"))

        log.debug(self.__class__.__name__, "EXIT")
Beispiel #7
0
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc_resp: uicc_sel_resp = None
        uicc: uicc = arg_components.modeler.uicc

        ori_mnc_length = None
        mnc_length = None
        efad_data_response = None

        set_mcc = ""
        set_mnc = ""
        update_mcc = False
        update_mnc = False

        dict_args = convert_arguments_to_dict(arg_arguments)
        for key, value in dict_args.items():
            if key == "mcc":
                set_mcc = value
                update_mcc = True
            elif key == "mnc":
                set_mnc = value
                update_mnc = True

        # Check the length of MCC/MNC
        if update_mcc and len(set_mcc) not in (0, 3):
            print(self.get_res("invalid_mcc"))
            return
        if update_mnc and len(set_mnc) not in (0, 2, 3):
            print(self.get_res("invalid_mnc"))
            return

        # read mnc length from EF_AD
        uicc_resp = uicc.select(UICC_FILE.AD)
        read_resp = uicc.read_binary(uicc_resp)
        if read_resp == None:
            print(self.get_res("read_error"))
            return

        efad_data_response = read_resp[:]  # keep for update mnc length
        ori_mnc_length = mnc_length = read_resp[3]
        # update mnc length to EF_AD if not equal
        if update_mnc and len(set_mnc) != mnc_length:
            mnc_length = len(set_mnc)
            efad_data_response[3] = mnc_length

            if uicc.update_binary(efad_data_response) != ERROR.NONE:
                print(self.get_res("update_error"))
                return

        # read EF_IMSI
        uicc_resp = uicc.select(UICC_FILE.IMSI)
        read_resp = uicc.read_binary(uicc_resp)
        if read_resp == None:
            print(self.get_res("read_error"))
            return

        mcc = convert_bcd_to_string(read_resp[1:])[1:4]
        mnc = convert_bcd_to_string(read_resp[1:])[4:4 + ori_mnc_length]
        print(self.get_res("original").format(mcc, mnc))

        if (update_mcc or update_mnc
            ) and self.is_update_require_adm == uicc.adm_verified:
            update_imsi = read_resp[:]

            # prepare MCC
            if update_mcc and (len(set_mcc) == 3):
                update_imsi[1] = (update_imsi[1]
                                  & 0x0F) + (int(set_mcc[0]) << 4)
                update_imsi[2] = (update_imsi[2] & 0xF0) + (int(set_mcc[1]))
                update_imsi[2] = (update_imsi[2]
                                  & 0x0F) + (int(set_mcc[2]) << 4)

            # prepare MNC
            if update_mnc and (len(set_mnc) >= 2):
                update_imsi[3] = (update_imsi[3] & 0xF0) + (int(set_mnc[0]))
                update_imsi[3] = (update_imsi[3]
                                  & 0x0F) + (int(set_mnc[1]) << 4)

                if len(set_mnc) == 3:
                    update_imsi[4] = (update_imsi[4] & 0xF0) + (int(
                        set_mnc[2]))

            if uicc.update_binary(update_imsi) != ERROR.NONE:
                print(self.get_res("update_error"))
                return

            mcc = convert_bcd_to_string(update_imsi[1:])[1:4]
            mnc = convert_bcd_to_string(update_imsi[1:])[4:4 + mnc_length]
            print(self.get_res("updated").format(mcc, mnc))

        log.debug(self.__class__.__name__, "EXIT")
Beispiel #8
0
    def execute(self, arg_components: components, arg_arguments=''):
        log.debug(self.__class__.__name__, "ENTER")

        uicc: uicc = arg_components.modeler.uicc

        # ETSI TS 131 102 V16.6.0 (2021-01)
        usim_service_table = [
            # 1
            "Local Phone Book",
            "Fixed Dialling Numbers(FDN)",
            "Extension 2",
            "Service Dialling Numbers(SDN)",
            "Extension 3",
            "Barred Dialling Numbers(BDN)",
            "Extension 4",
            "Outgoing Call Information(OCI and OCT)",
            "Incoming Call Information(ICI and ICT)",
            "Short Message Storage(SMS)",
            # 11
            "Short Message Status Reports(SMSR)",
            "Short Message Service Parameters(SMSP)",
            "Advice of Charge(AoC)",
            "Capability Configuration Parameters 2 (CCP2)",
            "Cell Broadcast Message Identifier",
            "Cell Broadcast Message Identifier Ranges",
            "Group Identifier Level 1",
            "Group Identifier Level 2",
            "Service Provider Name",
            "User controlled PLMN selector with Access Technology",
            # 21
            "MSISDN",
            "Image(IMG)",
            "Support of Localised Service Areas(SoLSA)",
            "Enhanced Multi-Level Precedence and Pre-emption Service",
            "Automatic Answer for eMLPP",
            "RFU",
            "GSM Access",
            "Data download via SMS-PP",
            "Data download via SMS-CB",
            "Call Control by USIM",
            # 31
            "MO-SMS Control by USIM",
            "RUN A T COMMAND command",
            "shall be set to '1'",
            "Enabled Services Table",
            "APN Control List(ACL)",
            "Depersonalisation Control Keys",
            "Co-operative Network List",
            "GSM security context",
            "CPBCCH Information",
            "Investigation Scan",
            # 41
            "MexE",
            "Operator controlled PLMN selector with Access Technology",
            "HPLMN selector with Access Technology",
            "Extension 5",
            "PLMN Network Name",
            "Operator PLMN List",
            "Mailbox Dialling Numbers",
            "Message W aiting Indication Status",
            "Call Forwarding Indication Status",
            "Reserved and shall be ignored",
            # 51
            "Service Provider Display Information",
            "Multimedia Messaging Service(MMS)",
            "Extension 8",
            "Call control on GPRS by USIM",
            "MMS User Connectivity Parameters",
            "Network's indication of alerting in the MS(NIA)",
            "VGCS Group Identifier List(EFVGCS and EFVGCSS)",
            "VBS Group Identifier List(EFVBS and EFVBSS)",
            "Pseudonym",
            "User Controlled PLMN selector for I-WLAN access",
            # 61
            "Operator Controlled PLMN selector for I-WLAN access",
            "User controlled WSID list",
            "Operator controlled WSID list",
            "VGCS security",
            "VBS security",
            "WLAN Reauthentication Identity",
            "Multimedia Messages Storage",
            "Generic Bootstrapping Architecture(GBA)",
            "MBMS security",
            "Data download via USSD and USSD application mode",
            # 71
            "Equivalent HPLMN",
            "Additional TERMINAL PROFILE after UICC activation",
            "Equivalent HPLMN Presentation Indication",
            "Last RPLMN Selection Indication",
            "OMA BCAST Smart Card Profile",
            "GBA-based Local Key Establishment Mechanism",
            "Terminal Applications",
            "Service Provider Name Icon",
            "PLMN Network Name Icon",
            "Connectivity Parameters for USIM IP connections",
            # 81
            "Home I-WLAN Specific Identifier List",
            "I-WLAN Equivalent HPLMN Presentation Indication",
            "I-WLAN HPLMN Priority Indication",
            "I-WLAN Last Registered PLMN",
            "EPS Mobility Management Information",
            "Allowed CSG Lists and corresponding indications",
            "Call control on EPS PDN connection by USIM",
            "HPLMN Direct Access",
            "eCall Data",
            "Operator CSG Lists and corresponding indications",
            # 91
            "Support for SM-over-IP",
            "Support of CSG Display Control",
            "Communication Control for IMS by USIM",
            "Extended Terminal Applications",
            "Support of UICC access to IMS",
            "Non-Access Stratum configuration by USIM",
            "PWS configuration by USIM",
            "RFU",
            "URI support by UICC",
            "Extended EARFCN support",
            # 101
            "ProSe",
            "USA T Application Pairing",
            "Media Type support",
            "IMS call disconnection cause",
            "URI support for MO SHORT MESSAGE CONTROL",
            "ePDG configuration Information support",
            "ePDG configuration Information configured",
            "ACDC support",
            "Mission Critical Services",
            "ePDG configuration Information for Emergency Service support",
            # 111
            "ePDG configuration Information for Emergency Service configured",
            "eCall Data over IMS",
            "URI support for SMS-PP DOWNLOAD as defined in 3GPP TS 31.111 [12]",
            "From Preferred",
            "IMS configuration data",
            "TV configuration",
            "3GPP PS Data Off",
            "3GPP PS Data Off Service List",
            "V2X",
            "XCAP Configuration Data",
            "EARFCN list for MTC/NB-IOT UEs",
            "5GS Mobility Management Information",
            "5G Security Parameters",
            "Subscription identifier privacy support",
            "SUCI calculation by the USIM",
            "UAC Access Identities support",
            "Expect control plane-based Steering of Roaming information during initial registration in VPLMN",
            "Call control on PDU Session by USIM"
        ]

        set_content = None
        dict_args = convert_arguments_to_dict(arg_arguments)
        for key, value in dict_args.items():
            if key == "set":
                set_content = value

        uicc_resp: uicc_sel_resp = uicc.select(UICC_FILE.UST)
        read_resp = uicc.read_binary(uicc_resp)
        if read_resp != None:
            print(self.get_res("original").format(toHexString(read_resp)))
            print("")
            for i in range(len(read_resp)):
                for j in range(8):
                    if read_resp[i] >> j & 1 == 1:
                        print(
                            self.get_res("service").format(
                                i * 8 + j + 1, usim_service_table[i * 8 + j]))

        else:
            print(self.get_res("read_error"))

        log.debug(self.__class__.__name__, "EXIT")