Ejemplo n.º 1
0
    def __get_iccid(self, arg_connection):
        self.__logging.debug("__get_iccid")

        # select EF_ICCID
        response, sw1, sw2 = select_file_in_mf(arg_connection,
                                               USIM_FILE_ID.ICCID.value)

        if sw1 == 0x90:
            data_length = get_data_length(response)
            response, sw1, sw2 = arg_connection.read_binary(data_length)
            return convert_bcd_to_string(response)

        return None
Ejemplo n.º 2
0
    def execute(self, arg_connection, arg_parameter=""):
        self.__logging.debug("execute()")

        if not os.path.exists(DEF_SECURITY_CACHE_FOLDER):
            os.makedirs(DEF_SECURITY_CACHE_FOLDER)

        ret_content = "Unexpected error!!"

        adm_code = None
        pin1_code = None

        dict_args = convert_arguments_to_dict(arg_parameter)
        for key, value in dict_args.items():
            if key == "adm":
                adm_code = value
            elif key == "pin1":
                pin1_code = value

        if (adm_code == None or pin1_code == None or len(adm_code) != 16
                or len(pin1_code) < 4 or len(pin1_code) > 8):
            ret_content = "Invalid PIN1/ADM code, operation terminated!!"
        else:
            response, sw1, sw2 = select_file_in_mf(arg_connection,
                                                   USIM_FILE_ID.ICCID.value)
            if sw1 == 0x90:
                data_length = get_data_length(response)
                response, sw1, sw2 = arg_connection.read_binary(data_length)

                iccid = convert_bcd_to_string(response)

                try:
                    security_node = etree.Element("security")
                    adm_node = etree.SubElement(security_node, "adm")
                    adm_node.text = adm_code
                    pin1_node = etree.SubElement(security_node, "pin1")
                    pin1_node.text = pin1_code
                    xmltree = etree.ElementTree(security_node)
                    xmltree.write(DEF_SECURITY_CACHE_FOLDER + os.sep + iccid +
                                  ".xml",
                                  pretty_print=True,
                                  xml_declaration=True,
                                  encoding='utf-8')
                    ret_content = "The " + iccid + ".xml file stored success."
                except:
                    ret_content = "Can't store " + iccid + ".xml file, operation terminated!"

        return ret_content
Ejemplo n.º 3
0
    def execute(self, arg_connection, arg_parameter=""):
        self.__logging.debug("execute()")

        ret_content = "Can't read the content from EF_ICCID!"
        raw_format = False
        update_iccid = False
        set_content = ""

        dict_args = convert_arguments_to_dict(arg_parameter)
        for key, value in dict_args.items():
            if key == "format" and value.lower() == "raw":
                raw_format = True
            elif key == "set":
                set_content = value
                update_iccid = True

        # select EF_ICCID
        response, sw1, sw2 = select_file_in_mf(
            arg_connection, USIM_FILE_ID.ICCID.value)

        if sw1 == 0x90:
            data_length = get_data_length(response)
            response, sw1, sw2 = arg_connection.read_binary(data_length)

            if update_iccid:
                original = convert_bcd_to_string(response)
                update_content = set_content + original[len(set_content):]

                response, sw1, sw2 = arg_connection.update_binary(
                    convert_string_to_bcd(update_content))
                if sw1 == 0x90:
                    ret_content = "ICCID: Updated to '%s'" % (update_content)
                else:
                    ret_content = "Can't update the new content to EF_ICCID!"
            else:
                if raw_format:
                    ret_content = "ICCID: " + toHexString(response)
                else:
                    ret_content = "ICCID: " + convert_bcd_to_string(response)

        return ret_content
Ejemplo n.º 4
0
    def execute(self, arg_connection, arg_parameter=""):
        self.__logging.debug("execute()")
        ret_content = ""
        selected_arr = "mf"

        dict_args = convert_arguments_to_dict(arg_parameter)
        for key, value in dict_args.items():
            if key.lower() == "type" and value.lower() == "adf":
                selected_arr = value.lower()

        # select EF_ARR
        if selected_arr == "adf":
            response, sw1, sw2 = select_file_in_adf(arg_connection,
                                                    USIM_FILE_ID.ADF_ARR.value)
        else:
            response, sw1, sw2 = select_file_in_mf(arg_connection,
                                                   USIM_FILE_ID.MF_ARR.value)

        if sw1 == 0x90:
            record_count = get_record_count(response)
            data_length = get_data_length(response)

            for i in range(record_count):
                response, sw1, sw2 = arg_connection.read_record(
                    i + 1, data_length)

                if sw1 == 0x90:
                    if ret_content != "":
                        ret_content += "\n"

                    ret_content += "%s ARR #%02d - %s" % (
                        selected_arr.upper(), i + 1, toHexString(response))

        if ret_content == "":
            ret_content = "Can't read the content from EF_ARR!"

        return ret_content
Ejemplo n.º 5
0
    def execute(self, arg_connection, arg_parameter=""):
        self.__logging.debug("execute()")
        ret_content = ""
        raw_format = False

        dict_args = convert_arguments_to_dict(arg_parameter)
        for key, value in dict_args.items():
            if key == "format" and value.lower() == "raw":
                raw_format = True

        # select EF_DIR
        response, sw1, sw2 = select_file_in_mf(arg_connection,
                                               USIM_FILE_ID.DIR.value)

        if sw1 == 0x90:
            record_count = get_record_count(response)
            data_length = get_data_length(response)

            for i in range(record_count):
                response, sw1, sw2 = arg_connection.read_record(
                    i + 1, data_length)

                if sw1 == 0x90:
                    if ret_content != "":
                        ret_content += "\n"

                    if raw_format:
                        ret_content += "EF_DIR #%d - %s" % (
                            i + 1, toHexString(response))
                    else:
                        aid_identifier = None
                        aid_lable = None

                        aid_identifier_content = search_fcp_content(
                            response, TLV_TAG.APPLICATION_IDENTIFIER.value)

                        if aid_identifier_content != None and len(
                                aid_identifier_content) > 2:
                            aid_identifier = toHexString(
                                aid_identifier_content[2:], format=PACK)

                        aid_label_content = search_fcp_content(
                            response, TLV_TAG.APPLICATION_LABEL.value)

                        if aid_label_content != None and len(
                                aid_label_content) > 2:
                            aid_lable = toASCIIString(aid_label_content[2:])

                        if aid_identifier == None:
                            ret_content += "EF_DIR #%02d - [Empty Content]" % (
                                i + 1)
                        elif aid_lable == None:
                            ret_content += "EF_DIR #%02d - AID: %s" % (
                                i + 1, aid_identifier)
                        else:
                            ret_content += "EF_DIR #%02d - AID: %s, Label: %s" % (
                                i + 1, aid_identifier, aid_lable)

        if ret_content == "":
            ret_content = "Can't read the content from EF_DIR!"

        return ret_content