*g9dZddlZddlZddlmZddlmZddlmZddl m Z m Z ddl m Z Gdd ZGd d ejZdS) z) pySim: tell old 2G SIMs apart from UICC N)List) SwMatchError)SimCardCommands)CardApplication interpret_sw)all_subclassesc eZdZdZdZdZdefdZdefdZ e ded e fd Z e d e d ed edeed ef dZeejd e d dfdZed e d efdZe d e fdZddZdS) CardProfilezA Card Profile describes a card, it's filesystem hierarchy, an [initial] list of applications as well as profile-specific SW and shell commands. Every card has one card profile, but there may be multiple applications within that profile.c ||_|dd|_|dg|_|di|_|dg|_|dg|_|dd|_|d d |_|d g|_ dS) aw Args: desc (str) : Description files_in_mf : List of CardEF instances present in MF applications : List of CardApplications present on card sw : List of status word definitions shell_cmdsets : List of cmd2 shell command sets of profile-specific commands cla : class byte that should be used with cards of this profile sel_ctrl : selection control bytes class byte that should be used with cards of this profile addons: List of optional CardAddons that a card of this profile might have descN files_in_mfsw applications shell_cmdsetscla00sel_ctrl0004addons) namegetr r rrrrrrselfrkws ;/home/jenkins/workspace/simtester-sanitize/pySim/profile.py__init__zCardProfile.__init__&s FF64(( 66-44&&r""FF>266VVOR8866%&&z622 ffXr** c|jSNrrs r__str__zCardProfile.__str__= yrappc:|j|dS)zAdd an application to a card profile. Args: app : CardApplication instance to be added to profile N)rappend)rr$s radd_applicationzCardProfile.add_application@s!   %%%%%rrc,t|j|S)zInterpret a given status word within the profile. Args: sw : Status word as string of 4 hex digits Returns: Tuple of two strings )rr)rrs rrzCardProfile.interpret_swHsDGR(((rdata_hexreturnc|S)aDecode the response to a SELECT command. This is the fall-back method which doesn't perform any decoding. It mostly exists so specific derived classes can overload it for actual decoding. This method is implemented in the profile and is only used when application specific decoding cannot be performed (no ADF is selected). Args: data_hex: Hex string of the select response )r)s rdecode_select_responsez"CardProfile.decode_select_responseSs rscccla_byterfidsc~|||_||_|D]}||dS)z?Helper function used by some derived _try_match_card() methods.N) reset_cardr/r select_file)r.r/rr0fids r_mf_select_testzCardProfile._mf_select_testasP    ! !C OOC  ! !rNcdS)a4Try to see if the specific profile matches the card. This method is a placeholder that is overloaded by specific dirived classes. The method actively probes the card to make sure the profile class matches the physical card. This usually also means that the card is reset during the process, so this method must not be called at random times. It may only be called on startup. If there is no exception raised, we assume the card matches the profile. Args: scc: SimCardCommands class Nr,)clsr.s r_try_match_cardzCardProfile._try_match_cardms  rcH|j}|j} || ||_||_|dS#t$r&Y||_||_|dSwxYw#||_||_|wxYw)aCheck if the specific profile matches the card. The method actively probes the card to make sure the profile class matches the physical card. This usually also means that the card is reset during the process, so this method must not be called at random times. It may only be called on startup. Args: scc: SimCardCommands class Returns: match = True, no match = False TF)rr/r8r2r)r7r. sel_backup cla_backups rmatch_with_cardzCardProfile.match_with_card}s\ \      $ $ $&CL%CL NN         %CL%CL NN       &CL%CL NN    s#A A:A=9A::A==$B!cttt}|t jd|D]#}||r |cS$dS)NORDER)key)listrr sortoperator attrgetterr<)r.profilesps rpickzCardProfile.picksv{3344 (-g66 777  A  %% qss  traddonCardProfileAddoncP||jvsJ|j|dSr)rr&)rrGs r add_addonzCardProfile.add_addons1DK'''' 5!!!!!r)rGrH)__name__ __module__ __qualname____doc__rr"rr'strr staticmethodobjectr-rrboolr5 classmethodabcabstractmethodr8r<rFrJr,rrr r !sUU+++.&?&&&& )s ) ) ) )     \  !_ !"% !14 !"3i !,0 ! ! !\ !  /  d    [  /d[0/\""""""rr cNeZdZdZdefdZdZejddde fdZ d S) rHzA Card Profile Add-on is something that is not a card application or a full stand-alone card profile, but an add-on to an existing profile. Think of GSM-R specific files existing on what is otherwise a SIM or USIM+SIM card.rc ||_|dd|_|dg|_|dg|_dS)z Args: desc (str) : Description files_in_mf : List of CardEF instances present in MF shell_cmdsets : List of cmd2 shell command sets of profile-specific commands r Nr r)rrr r rrs rrzCardProfileAddon.__init__sR FF64(( 66-44VVOR88rc|jSrr r!s rr"zCardProfileAddon.__str__r#rcardCardBaser*cdS)zPProbe a given card to determine whether or not this add-on is present/supported.Nr,)rrYs rprobezCardProfileAddon.probesrN) rKrLrMrNrOrr"rTrUrRr\r,rrrHrHs44 9S 9 9 9 9 _*_______rrH)rNrTrBtypingrpySim.exceptionsrpySim.commandsrpySim.filesystemrr pySim.utilsrr ABCrHr,rrrcs* ))))))******::::::::&&&&&&C"C"C"C"C"C"C"C"J_____sw_____r