def exec(self): try: state_class = __import__("control.state.%s" % (self.__state), fromlist=[self.__state]) state_instance = getattr(state_class, self.__state)() log.debug(self.__class__.__name__, self.__state) self.__state, self.__arguments = state_instance.execute( self.__components, self.__arguments) except Exception as e: error_class = e.__class__.__name__ reason = e.args[0] cl, exc, tb = sys.exc_info() lastCallStack = traceback.extract_tb(tb)[-1] fileName = lastCallStack[0] lineNum = lastCallStack[1] funcName = lastCallStack[2] callstack = os.linesep.join([ line.strip() for line in traceback.format_exc(limit=5).splitlines()[1:-1] ]) errMsg = res.get_string("exception").format( os.path.basename(fileName), lineNum, funcName, reason, callstack) self.__state = STATE.EXCEPTION self.__arguments = errMsg if self.__state == STATE.NONE: return False return True
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")
def __transmit(self, arg_apdu_cmd): log.debug(self.__class__.__name__, "TX> %s" % (toHexString(arg_apdu_cmd))) response, sw1, sw2 = self.__connection.transmit(arg_apdu_cmd) log.debug(self.__class__.__name__, "RX< %s, %02X %02X" % (toHexString(response), sw1, sw2)) return (response, sw1, sw2)
def execute(self, arg_components: components, arg_arguments=''): log.debug(self.__class__.__name__, "ENTER") uicc: uicc = arg_components.modeler.uicc ''' ** Implement your code in here. In 'usim_modifier_v3' frameworks, just pass the arguments to plugin, so you need to handle all operation by self, such as: 1. select usim fields 2. get input 3. display message 4. read data from usim 5. update data to usim ** Example of select usim filed # select MF uicc_resp: uicc_sel_resp = uicc.select(UICC_FILE.MF, arg_type=UICC_SELECT_TYPE.FILE_ID) # select other sim fields uicc_resp: uicc_sel_resp = uicc.select(UICC_FILE.ICCID) uicc_resp: uicc_sel_resp = uicc.select(UICC_FILE.IMSI) ** Execute other plugin super(template, self).execute_plugin(plugin_name, arg_components) ''' print(self.get_res("hello")) log.debug(self.__class__.__name__, "EXIT")
def execute(self, arg_components: components, arg_arguments): log.debug(self.__class__.__name__, "ENTER") out_msg = layout_help.layout(arg_help=res.get_string('help')) print(out_msg) log.debug(self.__class__.__name__, "EXIT") return (STATE.CLI, None)
def execute(self, arg_components: components, arg_arguments): log.debug(self.__class__.__name__, "ENTER") ret_state = STATE.PLUGIN ret_arg = None verify_result, remainings = arg_components.modeler.uicc.verify_pin( PIN_TYPE.ADM1, toBytes(arg_arguments)) # If enabled 'configuration.adm', store the adm code for auto verify if verify_result == ERROR.NONE: arg_components.modeler.uicc.adm_verified = True if arg_components.config.adm == 1: arg_components.config.update_adm_code( arg_components.modeler.uicc.iccid, arg_arguments) else: if remainings == 0: ret_state = STATE.ERROR ret_arg = res.get_string("adm_blocked") else: ret_state = STATE.ADM_CODE ret_arg = res.get_string("incorrect_adm_code").format( remainings) log.debug(self.__class__.__name__, "EXIT") return (ret_state, ret_arg)
def execute(self, arg_components: components, arg_arguments): ret_state = STATE.DISPATCH_ERROR ret_arguments = None log.debug(self.__class__.__name__, "ENTER") log.info(self.__class__.__name__, arg_arguments) lower_arguments = arg_arguments.lower() if (lower_arguments == 'plugin'): ret_state = STATE.PLUGIN_LIST elif (lower_arguments == 'help'): ret_state = STATE.HELP elif (lower_arguments == 'exit'): ret_state = STATE.EXIT elif (arg_arguments != ''): cmd_list = arg_arguments.split(' ') for plugin in arg_components.plugin: if (plugin[0] == cmd_list[0].lower()): if (len(cmd_list) > 1 and 'help' == cmd_list[1].lower()): ret_state = STATE.PLUGIN_HELP ret_arguments = cmd_list[0] else: ret_state = STATE.EXECUTE ret_arguments = cmd_list[0].lower() + " " + " ".join(cmd_list[1:]) break log.debug(self.__class__.__name__, "EXIT") return (ret_state, ret_arguments)
def execute(self, arg_components: components, arg_arguments): log.debug(self.__class__.__name__, "ENTER") ret_state = STATE.EXIT ret_arguments = None if arg_components.modeler.reader.name == None: ret_state = STATE.ERROR ret_arguments = res.get_string("no_cardreader") else: ret = arg_components.modeler.open() if ret == ERROR.CARD_ABSENT: ret_state = STATE.ERROR ret_arguments = res.get_string("no_card") elif ret == ERROR.CARD_INVALID: ret_state = STATE.ERROR ret_arguments = res.get_string("invalid_card") else: ret_state = STATE.PIN_CODE out_msg = layout_initial.layout( res.get_string("reader_connected"), arg_components.modeler.reader.name) print(out_msg) log.debug(self.__class__.__name__, "EXIT") return (ret_state, ret_arguments)
def execute(self, arg_components: components, arg_arguments): log.debug(self.__class__.__name__, "ENTER") arg_components.modeler.close() log.debug(self.__class__.__name__, "EXIT") return (STATE.NONE, None)
def execute(self, arg_components: components, arg_arguments): log.debug(self.__class__.__name__, "ENTER") out_msg = layout_error.layout(arg_string=arg_arguments) print(out_msg) log.debug(self.__class__.__name__, "EXIT") return (STATE.EXIT, None)
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")
def execute(self, arg_components, arg_arguments=''): log.debug(self.__class__.__name__, "ENTER") execute_list = ["iccid", "imsi", "mccmnc", "spn", "gid"] for plugin in execute_list: super(cardinfo, self).execute_plugin(plugin, arg_components) log.debug(self.__class__.__name__, "EXIT")
def execute(self, arg_components: components, arg_arguments=''): log.debug(self.__class__.__name__, "ENTER") uicc: uicc = arg_components.modeler.uicc if len(arg_arguments) != 0 and len(arg_arguments) % 2 != 1: print("TX: %s" % (toHexString(toBytes(arg_arguments)))) response, sw1, sw2 = uicc.send(toBytes(arg_arguments)) rx_resp = "%s %02X %02X" % (toHexString(response), sw1, sw2) print("RX: " + rx_resp.strip()) log.debug(self.__class__.__name__, "EXIT")
def execute(self, arg_components: components, arg_arguments): ret_state = STATE.DISPATCH ret_arguments = None log.debug(self.__class__.__name__, "ENTER") out_msg = layout_cli.layout(arg_prefix=res.get_string('app_name')) print(out_msg, end='') ret_arguments = input().strip() log.debug(self.__class__.__name__, "EXIT") return (ret_state, ret_arguments)
def execute(self, arg_components: components, arg_arguments): log.debug(self.__class__.__name__, "ENTER") out_msg = layout_startup.layout(arg_name=res.get_string( 'app_name'), arg_version=res.get_string( 'app_version'), arg_copyright=res.get_string( 'copyright')) print(out_msg) log.debug(self.__class__.__name__, "EXIT") return (STATE.INITIAL, None)
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")
def execute(self, arg_components: components, arg_arguments): log.debug(self.__class__.__name__, "ENTER") if arg_components.config.autoexec: plugins = arg_components.plugin[:] for plugin in plugins: if plugin[4]: plugin_class = __import__("model.plugins.%s.%s" % (plugin[0], plugin[0]), fromlist=[plugin[0]]) instance_class = getattr(plugin_class, plugin[0])() instance_class.execute(arg_components, "") log.debug(self.__class__.__name__, "EXIT") return (STATE.HELP, None)
def execute(self, arg_components: components, arg_arguments): log.debug(self.__class__.__name__, "ENTER") plugin_class = __import__("model.plugins.%s.%s" % (arg_arguments, arg_arguments), fromlist=[arg_arguments]) instance_class = getattr(plugin_class, arg_arguments)() out_msg = layout_plugin_help.layout( arg_format=res.get_string('plugin_help_header'), arg_name=arg_arguments, arg_help=instance_class.help()) print(out_msg) log.debug(self.__class__.__name__, "EXIT") return (STATE.CLI, None)
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")
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")
def execute(self, arg_components: components, arg_arguments): log.debug(self.__class__.__name__, "ENTER") ret_state = STATE.ADM_VERIFY ret_arg = None adm_code = None out_msg = '' # if 'arg_arguments' exist, means may the auto verify fail # so we can't read the adm code from .xml file if arg_arguments == None: # Auto ADM operation (read from usim_modifier.xml) adm_code = arg_components.config.query_adm_code( arg_components.modeler.uicc.iccid) if adm_code == None: if arg_arguments == None: if arg_components.config.admhex == 1: out_msg = res.get_string("input_adm_code_hex") else: out_msg = res.get_string("input_adm_code") else: out_msg = arg_arguments print(layout_adm_code.layout(arg_msg=out_msg), end='') adm_code = input().strip().upper() # convert the 8 digits format to 16 hex digit if arg_components.config.admhex == 0: adm_code_byte = toASCIIBytes(adm_code) adm_code = toHexString(adm_code_byte, format=PACK) if len(adm_code) == 0: ret_state = STATE.PLUGIN print( layout_adm_code.layout( arg_msg=res.get_string("terminated_adm_code"))) elif not is_valid_adm_code(adm_code): ret_state = STATE.ADM_CODE if arg_components.config.admhex == 1: ret_arg = res.get_string("invalid_adm_code_hex") else: ret_arg = res.get_string("invalid_adm_code") if ret_state == STATE.ADM_VERIFY: ret_arg = adm_code log.debug(self.__class__.__name__, "EXIT") return (ret_state, ret_arg)
def execute(self, arg_components: components, arg_arguments): ret_state = STATE.CLI ret_arguments = None log.debug(self.__class__.__name__, "ENTER") log.info(self.__class__.__name__, arg_arguments) cmd_list = arg_arguments.split(" ") for plugin in arg_components.plugin: if (plugin[0] == cmd_list[0]): plugin_class = __import__("model.plugins.%s.%s" % (plugin[0], plugin[0]), fromlist=[plugin[0]]) instance_class = getattr(plugin_class, plugin[0])() instance_class.execute(arg_components, " ".join(cmd_list[1:])) break log.debug(self.__class__.__name__, "EXIT") return (ret_state, ret_arguments)
def execute(self, arg_components: components, arg_arguments): log.debug(self.__class__.__name__, "ENTER") ret_state = STATE.PIN_VERIFY ret_arg = None pin_code = None out_msg = '' if arg_components.modeler.uicc.pin_enabled == True: # if 'arg_arguments' exist, means may the auto verify fail. # so we can't read the pin code from .xml file if arg_arguments == None: # Auto PIN operation (read from usim_modifier.xml) pin_code = arg_components.config.query_pin_code( arg_components.modeler.uicc.iccid) if pin_code == None: if arg_arguments == None: out_msg = res.get_string("input_pin_code") else: out_msg = arg_arguments print(layout_pin_code.layout(arg_msg=out_msg), end='') pin_code = input().strip() if len(pin_code) == 0: ret_state = STATE.ERROR ret_arg = res.get_string("terminated_pin_code") elif not is_valid_pin_code(pin_code): ret_state = STATE.PIN_CODE ret_arg = res.get_string("invalid_pin_code") if ret_state == STATE.PIN_VERIFY: ret_arg = pin_code else: ret_state = STATE.ADM_CODE log.debug(self.__class__.__name__, "EXIT") return (ret_state, ret_arg)
def execute(self, arg_components: components, arg_arguments): log.debug(self.__class__.__name__, "ENTER") plugins = arg_components.plugin[:] # check the ADM verify state # org: plugin name, version, is update adm require # new: plugin name, version, is updatable # is_update_require_adm: # - None: No update feature # - True: update need adm verified # - False: Didn't need adm for update str_yes = res.get_string("yes") str_no = res.get_string("no") str_na = res.get_string("na") for plugin in plugins: if plugin[3] == None: plugin[3] = str_na elif arg_components.modeler.uicc.adm_verified: plugin[3] = str_yes else: plugin[3] = str_yes if plugin[3] == arg_components.modeler.uicc.adm_verified else str_no if plugin[4]: plugin[4] = str_yes else: plugin[4] = str_no out_msg = layout_plugin_list.layout(arg_format=res.get_string('plugin_found'), arg_plugin=plugins) print(out_msg) log.debug(self.__class__.__name__, "EXIT") return (STATE.CLI, None)
def execute(self, arg_components: components, arg_arguments): log.debug(self.__class__.__name__, "ENTER") plugin_count = 0 plugin = [] plugins_list = os.listdir("./model/plugins") for filename in plugins_list: name, ext = os.path.splitext(filename) if ext != '.py' and name != '__pycache__' and name != '.DS_Store': try: plugin_class = __import__("model.plugins.%s.%s" % (name, name), fromlist=[name]) res_files = [os.path.join(r, file) for r, d, f in os.walk( './model/plugins/%s/values' % (name)) for file in f] res.add_resource(name, res_files) instance_class = getattr(plugin_class, name)() if instance_class.summary() != None: plugin_count += 1 plugin.append([name, instance_class.version(), instance_class.summary(), instance_class.is_update_require_adm, instance_class.is_auto_exec]) except: log.debug(self.__class__.__name__, "Error to import '%s' plugin." % (name)) arg_components.plugin = plugin out_msg = layout_plugin.layout(arg_format=res.get_string("plugin_loaded"), arg_count=plugin_count) print(out_msg) log.debug(self.__class__.__name__, "EXIT") return (STATE.AUTO_EXEC, None)
def execute(self, arg_components: components, arg_arguments=''): log.debug(self.__class__.__name__, "ENTER") update_log = None update_localized = None update_pin = None update_adm = None update_autoexec = None update_admhex = None dict_args = convert_arguments_to_dict(arg_arguments) for key, value in dict_args.items(): if key == "log": update_log = int(value) elif key == "localized": update_localized = int(value) elif key == "pin": update_pin = int(value) elif key == "adm": update_adm = int(value) elif key == "autoexec": update_autoexec = int(value) elif key == "admhex": update_admhex = int(value) if update_log != None: arg_components.config.log = update_log if update_localized != None: arg_components.config.localized = update_localized if update_pin != None: arg_components.config.pin = update_pin if update_adm != None: arg_components.config.adm = update_adm if update_autoexec != None: arg_components.config.autoexec = update_autoexec if update_admhex != None: arg_components.config.admhex = update_admhex if update_log != None or update_localized != None or update_pin != None or update_adm != None or update_autoexec != None or update_admhex != None: arg_components.config.save() print( self.get_res("log").format( res.get_string("yes") if arg_components.config.log == 1 else res.get_string("no"))) print( self.get_res("localized").format( res.get_string("yes") if arg_components.config.localized == 1 else res.get_string("no"))) print( self.get_res("pin").format( res.get_string("yes") if arg_components.config.pin == 1 else res.get_string("no"))) print( self.get_res("adm").format( res.get_string("yes") if arg_components.config.adm == 1 else res.get_string("no"))) print( self.get_res("autoexec").format( res.get_string("yes") if arg_components.config.autoexec == 1 else res.get_string("no"))) print( self.get_res("admhex").format( res.get_string("yes") if arg_components.config.admhex == 1 else res.get_string("no"))) log.debug(self.__class__.__name__, "EXIT")
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")
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")
def execute(self, arg_components: components, arg_arguments=''): log.debug(self.__class__.__name__, "ENTER") print("ATR: {}".format(toHexString(arg_components.modeler.uicc.atr()))) log.debug(self.__class__.__name__, "EXIT")
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")