
    kj?z                        d Z ddlZddlmZmZmZmZ ddlmZmZm	Z	 ddl
mZ ddlT ddlT ddlmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlZ G d ded          Zej        j        j                            e           defdZ de!fdZ" G d de#          Z$ e$ ede%                    Z&dZ'dZ(dZ)dZ* G d ded          Z+ G d dede+g          Z, G d  d!ed"ej        j-        e,gz             Z. G d# d$ed%          Z/ G d& d'ed(          Z0 G d) d*ed+e/e0g          Z1 G d, d-ed%          Z2 G d. d/ed0e/e2g          Z3 G d1 d2ed%          Z4 G d3 d4ed5e4g          Z5 G d6 d7ed          Z6 G d8 d9ed:          Z7 G d; d<ed=e7g          Z8 G d> d?ed@e7g          Z9 G dA dBedCe6e8e9g          Z: G dD dEed(          Z; G dF dGedH          Z< G dI dJedK          Z= G dL dMedN          Z> G dO dPedQ          Z? G dR dSedT          Z@ G dU dVedW          ZA G dX dYedZ          ZB G d[ d\ed:          ZC G d] d^ed_          ZD G d` daedb          ZE G dc dded%          ZF G de dfedgeFg          ZG G dh diedjeGg          ZH G dk dledme;e6e<e=e>e?e@eAe8e9eBeCeDeEeHg          ZI G dn doed(          ZJ G dp dqedreJg          ZK G ds dted%          ZL G du dved_          ZM G dw dxed          ZN G dy dzed{eLeJeMeNg          ZO G d| d}edgeOg          ZP G d~ ded(          ZQ G d dedrePeQg          ZR G d ded%          ZS G d dedeLg          ZT G d dedeSg          ZU G d dedg           ZV G d ded          ZW G d dedeWg          ZX G d ded          ZY G d ded          ZZ G d dedb          Z[ G d ded          Z\ G d ded          Z] G d ded          Z^ G d dedj          Z_ G d ded          Z` G d ded          Za G d ded          Zb G d ded%          Zc G d ded(          Zd G d ded          Ze G d dedecedeeg          Zf G d ded          Zg G d dedeNeYeZe[e\e]e^e_e`eaebefegg          Zh G d dedgehg          Zi G d ded(          Zj G d dedeiejg          Zk G dÄ ded(          Zl G dń ded%          Zm G dǄ dedgeYeNg          Zn G dɄ dedenelg          Zo G d̄ dedemg          Zp G d΄ ded%          Zq G dЄ dedenelg          Zr G dӄ dedeqg          Zs G dՄ ded%          Zt G dׄ dedeYeNg          Zu G dڄ dedetg          Zv G d܄ ded          Zw G dބ ded%          Zx G d dedewg          Zy G d dedexg          Zz G d ded          Z{ G d dedeWe{g          Z| G d ded          Z} G d dedeNe}g          Z~ G d ded%          Z G d dedeg          Z G d ded          Z G d ded          Z G d ded          Z G d ded(          Z G d d edeeeg          Z G d ded%          Z G d ded(          Z G d ded          Z G d dedH          Z G d	 d
edK          Z G d dedT          Z G d ded%eeeeeeg          Z G d dedgeg          Z G d dedeg          Z G d dej        j                  Z G d dej        j                  Z G d de          Z G d de          Z G d de          ZdS (  z
Various definitions related to GSMA consumer + IoT eSIM / eUICC

Does *not* implement anything related to M2M eUICC

Related Specs: GSMA SGP.21, SGP.22, SGP.31, SGP32
    N)ArrayStruct	FlagsEnumGreedyRange)cmd2
CommandSetwith_default_category)Hexstr)*)SwMatchError)r
   SwHexstr
SwMatchstr)SimCardCommands)CardProfileUICCc                   $    e Zd Z ee          ZdS )Sgp02EidN)__name__
__module____qualname__
BcdAdapterGreedyBytes
_construct     A/home/jenkins/jenkins/workspace/simtester-sanitize/pySim/euicc.pyr   r   )   s        K((JJJr   r   Z   tagreturnc                 ^   t          | t                    rYt          |           dk    r| dz  } n0t          |           dk    r| dd         dz   } nt          d          t	          |           }n$t          | t                    r| }|dz  r||dz  z  }d|d	z  z
  }||z  }t          |          S )
zYCompute and add/replace check digits of an EID value according to GSMA SGP.29 Section 10.   00    Nzand EID must be 30 or 32 digitsd   b   a   )
isinstancestrlen
ValueErrorint)eideid_intcsums      r   compute_eid_checksumr0   /   s    #s %s88r>>4KCCXX^^crc(T/CC>???c((	C		 %S= 	%w}$G 2DtOGw<<r   c                 .    t          |           dz  dk    S )zLVerify the check digits of an EID value according to GSMA SGP.29 Section 10.r'      r,   )r-   s    r   verify_eid_checksumr4   G   s     s88b=Ar   c                       e Zd ZdZd Zd ZdS )VersionAdapterzCconvert an EUICC Version (3-int array) to a textual representation.c                 6    d|d         |d         |d         fz  S )Nz%u.%u.%ur   r2      r   selfobjcontextpaths       r   _decodezVersionAdapter._decodeP   s     SVSVSV444r   c                 @    d |                     d          D             S )Nc                 ,    g | ]}t          |          S r   r3   ).0xs     r   
<listcomp>z*VersionAdapter._encode.<locals>.<listcomp>T   s    ///1A///r   .)splitr9   s       r   _encodezVersionAdapter._encodeS   s     //		#////r   N)r   r   r   __doc__r>   rF   r   r   r   r6   r6   M   s8        MM5 5 50 0 0 0 0r   r6       A0000005591010FFFFFFFF8900000100 A0000005591010FFFFFFFF8900000200 A0000005591010FFFFFFFF8900000D00 A0000005591010FFFFFFFF8900000E00c                       e Zd ZeZdS )SupportedVersionNumberNr   r   r   r   r   r   r   r   rN   rN   ^           JJJr   rN      c                       e Zd ZdS )"IsdrProprietaryApplicationTemplateNr   r   r   r   r   r   rS   rS   a           Dr   rS      )r   nestedc                       e Zd ZdS )FciTemplateNrT   r   r   r   rY   rY   f   rU   r   rY   o   c                   $    e Zd Z ee          ZdS )DefaultDpAddressNr   r   r   Utf8Adapterr   r   r   r   r   r\   r\   l           [))JJJr   r\      c                   $    e Zd Z ee          ZdS )RootDsAddressNr]   r   r   r   rb   rb   n   r_   r   rb      c                       e Zd ZdS )EuiccConfiguredAddressesNrT   r   r   r   re   re   p           Dr   re   i<  c                   *    e Zd Z eedd          ZdS )SetDefaultDpAddrResr      )okundefinedErrorNr   r   r   EnumInt8ubr   r   r   r   rh   rh   t   s$        f3777JJJr   rh   c                       e Zd ZdS )SetDefaultDpAddressNrT   r   r   r   rp   rp   v   rf   r   rp   i?  c                   $    e Zd Z ed          ZdS )EuiccChallenge   N)r   r   r   Bytesr   r   r   r   rr   rr   z   s        rJJJr   rr   c                       e Zd ZdS )GetEuiccChallengeNrT   r   r   r   rv   rv   |   rf   r   rv   i.  c                       e Zd ZeZdS )SVNNr   r   r   VersionTyper   r   r   r   rx   rx      rP   r   rx   c                       e Zd ZeZdS )SubjectKeyIdentifierNrO   r   r   r   r|   r|      rP   r   r|      c                       e Zd ZdS )EuiccCiPkiListForVerificationNrT   r   r   r   r   r      rf   r   r      c                       e Zd ZdS )EuiccCiPkiListForSigningNrT   r   r   r   r   r      rf   r   r      c                       e Zd ZdS )
EuiccInfo1NrT   r   r   r   r   r      rf   r   r   i   c                       e Zd ZeZdS )ProfileVersionNry   r   r   r   r   r      rP   r   r   c                       e Zd ZeZdS )EuiccFirmwareVerNry   r   r   r   r   r      rP   r   r      c                       e Zd ZeZdS )ExtCardResourceNrO   r   r   r   r   r      rP   r   r      c                       e Zd ZeZdS )UiccCapabilityNrO   r   r   r   r   r      rP   r   r      c                       e Zd ZeZdS )TS102241VersionNry   r   r   r   r   r      rP   r   r      c                       e Zd ZeZdS )GlobalPlatformVersionNry   r   r   r   r   r      rP   r   r      c                       e Zd ZeZdS )RspCapabilityNrO   r   r   r   r   r      rP   r   r      c                   .    e Zd Z eedddd          ZdS )EuiccCategoryr   r2   r8   rH   )other
basicEuiccmediumEuicccontactlessEuiccNrl   r   r   r   r   r      s)        fA!UVWWWJJJr   r      c                       e Zd ZeZdS )	PpVersionNry   r   r   r   r   r      rP   r   r   c                   $    e Zd Z ee          ZdS )SsAcreditationNumberNr]   r   r   r   r   r      r_   r   r      c                   *    e Zd Z eedd          ZdS )IpaModer   r2   )ipadipeaNrl   r   r   r   r   r      s$        f11---JJJr   r      c                       e Zd ZeZdS )
IotVersionNry   r   r   r   r   r      rP   r   r   c                       e Zd ZdS )IotVersionSeqNrT   r   r   r   r   r      rf   r   r      c                       e Zd ZdS )IotSpecificInfoNrT   r   r   r   r   r      rf   r   r      c                       e Zd ZdS )
EuiccInfo2NrT   r   r   r   r   r      s        
 	Dr   r   i"  c                   H    e Zd Z eed eedddd          z            ZdS )ProfileMgmtOperationpmor`   @   r#   rs   )installenabledisabledeleteN)r   r   r   r   Byter   r   r   r   r   r   r      s;        eIIdDW[dh$i$i$iijjJJJr   r   c                       e Zd ZdS )ListNotificationReqNrT   r   r   r   r   r      rf   r   r   i(  c                   "    e Zd Z e            ZdS )	SeqNumberNr   r   r   Asn1DerIntegerr   r   r   r   r   r              !!JJJr   r   c                   $    e Zd Z ee          ZdS )NotificationAddressNr]   r   r   r   r   r      r_   r   r   c                   $    e Zd Z ee          ZdS )IccidN)r   r   r   PaddedBcdAdapterr   r   r   r   r   r   r      s        !!+..JJJr   r   c                       e Zd ZdS )NotificationMetadataNrT   r   r   r   r   r      rU   r   r   i/  c                       e Zd ZdS )NotificationMetadataListNrT   r   r   r   r   r      rf   r   r   c                   (    e Zd Z eed          ZdS )ListNotificationsResultErrorri   )rk   Nrl   r   r   r   r   r      s"        fS111JJJr   r   c                       e Zd ZdS )ListNotificationRespNrT   r   r   r   r   r      rU   r   r   c                   ,    e Zd Z eeddd          ZdS )DeleteNotificationStatusr   r2   ri   rj   nothingToDeleterk   Nrl   r   r   r   r   r      &        fAcJJJJJJr   r   c                       e Zd ZdS )NotificationSentReqNrT   r   r   r   r   r      rf   r   r   i0  c                       e Zd ZdS )NotificationSentRespNrT   r   r   r   r   r      rf   r   r   c                       e Zd ZdS )LoadCRLNrT   r   r   r   r   r      rf   r   r   i5  c                   $    e Zd Z ee          ZdS )TagListN)r   r   r   r   rn   r   r   r   r   r   r      s        V$$JJJr   r   \   c                       e Zd ZdS )ProfileInfoListReqNrT   r   r   r   r   r      rf   r   r   i-  c                       e Zd ZeZdS )IsdpAidNrO   r   r   r   r   r      rP   r   r   O   c                   *    e Zd Z eedd          ZdS )ProfileStater   r2   )disabledenabledNrl   r   r   r   r   r      s$        fq!444JJJr   r   ip  c                   $    e Zd Z ee          ZdS )ProfileNicknameNr]   r   r   r   r   r      r_   r   r   c                   $    e Zd Z ee          ZdS )ServiceProviderNameNr]   r   r   r   r   r      r_   r   r      c                   $    e Zd Z ee          ZdS )ProfileNameNr]   r   r   r   r   r      r_   r   r      c                   *    e Zd Z eedd          ZdS )IconTyper   r2   )jpgpngNrl   r   r   r   r   r      s$        f!+++JJJr   r      c                       e Zd ZeZdS )IconNrO   r   r   r   r   r      rP   r   r   c                   ,    e Zd Z eeddd          ZdS )ProfileClassr   r2   r8   )testprovisioningoperationalNrl   r   r   r   r   r      s&        f11!DDDJJJr   r      c                       e Zd ZeZdS )ProfilePolicyRulesNrO   r   r   r   r   r      rP   r   r      c                       e Zd ZeZdS )NotificationConfigurationInfoNrO   r   r   r   r  r     rP   r   r     c                   6    e Zd Z e ed                    ZdS )ProfileOwnerPLMNrH   N)r   r   r   PlmnAdapterrt   r   r   r   r   r  r     s%        UU1XX&&JJJr   r  c                       e Zd ZeZdS )ProfileOwnerGID1NrO   r   r   r   r  r     rP   r   r  c                       e Zd ZeZdS )ProfileOwnerGID2NrO   r   r   r   r
  r
     rP   r   r
  c                       e Zd ZeZdS )ProfileOwnerNrO   r   r   r   r  r     rP   r   r     c                       e Zd ZeZdS )SMDPPProprietaryDataNrO   r   r   r   r  r     rP   r   r     c                       e Zd ZdS )ProfileInfoNrT   r   r   r   r  r     s         	Dr   r     c                       e Zd ZdS )ProfileInfoSeqNrT   r   r   r   r  r     rf   r   r  c                   *    e Zd Z eedd          ZdS )ProfileInfoListErrorr2   r8   )incorrectInputValuesrk   Nrl   r   r   r   r  r     s$        f1QGGGJJJr   r  c                       e Zd ZdS )ProfileInfoListRespNrT   r   r   r   r  r     rf   r   r  c                       e Zd ZeZdS )RefreshFlagN)r   r   r   rn   r   r   r   r   r  r    s        JJJr   r  c            
       4    e Zd Z eeddddddd          Zd	S )
EnableResultr   r2   r8   rH   r}      ri   )rj   iccidOrAidNotFoundprofileNotInDisabledStatedisallowedByPolicywrongProfileReenablingcatBusyrk   Nrl   r   r   r   r  r    s:        fqTU)*1a`ce e eJJJr   r  c                       e Zd ZdS )ProfileIdentifierNrT   r   r   r   r&  r&  	  rf   r   r&  c                       e Zd ZdS )EnableProfileReqNrT   r   r   r   r(  r(    rf   r   r(  i1  c                       e Zd ZdS )EnableProfileRespNrT   r   r   r   r*  r*    rf   r   r*  c            	       2    e Zd Z eedddddd          ZdS )	DisableResultr   r2   r8   rH   r  ri   )rj   r   profileNotInEnabledStater"  r$  rk   Nrl   r   r   r   r,  r,    s7        fqST)*AcK K KJJJr   r,  c                       e Zd ZdS )DisableProfileReqNrT   r   r   r   r/  r/    rf   r   r/  i2  c                       e Zd ZdS )DisableProfileRespNrT   r   r   r   r1  r1    rf   r   r1  c                   0    e Zd Z eeddddd          ZdS )DeleteResultr   r2   r8   rH   ri   )rj   r   r!  r"  rk   Nrl   r   r   r   r3  r3    s5        fqTU)*3@ @ @JJJr   r3  c                       e Zd ZdS )DeleteProfileReqNrT   r   r   r   r5  r5    rf   r   r5  i3  c                       e Zd ZdS )DeleteProfileRespNrT   r   r   r   r7  r7    rf   r   r7  c                   ,    e Zd Z eeddd          ZdS )ResetOptionsr`   r   r#   )deleteOperationalProfilesdeleteFieldLoadedTestProfilesresetDefaultSmdpAddressN)r   r   r   r   r   r   r   r   r   r9  r9  #  s.        44_c379 9 9JJJr   r9  c                   ,    e Zd Z eeddd          ZdS )ResetResultr   r2   ri   r   Nrl   r   r   r   r>  r>  &  r   r   r>  c                       e Zd ZdS )EuiccMemoryResetReqNrT   r   r   r   r@  r@  (  rf   r   r@  i4  c                       e Zd ZdS )EuiccMemoryResetRespNrT   r   r   r   rB  rB  *  rf   r   rB  c                       e Zd ZeZdS )EidValueNrO   r   r   r   rD  rD  .  rP   r   rD  c                       e Zd ZdS )GetEuiccDataNrT   r   r   r   rF  rF  0  rf   r   rF  i>  c                   $    e Zd Z ee          ZdS )SnrProfileNicknameNr]   r   r   r   rH  rH  4  r_   r   rH     c                       e Zd ZdS )SetNicknameReqNrT   r   r   r   rK  rK  6  rf   r   rK  i)  c                   ,    e Zd Z eeddd          ZdS )SetNicknameResultr   r2   ri   )rj   iccidNotFoundrk   Nrl   r   r   r   rM  rM  8  s&        f!CHHHJJJr   rM  c                       e Zd ZdS )SetNicknameRespNrT   r   r   r   rP  rP  :  rf   r   rP  c                       e Zd ZdS )GetCertsReqNrT   r   r   r   rR  rR  >  rf   r   rR  iV  c                       e Zd ZeZdS )EumCertificateNrO   r   r   r   rT  rT  @  rP   r   rT     c                       e Zd ZeZdS )EuiccCertificateNrO   r   r   r   rW  rW  B  rP   r   rW     c                   *    e Zd Z eedd          ZdS )GetCertsErrorr2   ri   )invalidCiPKIdrk   Nrl   r   r   r   rZ  rZ  D  s$        fAcBBBJJJr   rZ  c                       e Zd ZdS )GetCertsRespNrT   r   r   r   r]  r]  F  rf   r   r]  c                   $    e Zd Z ee          ZdS )EimIdNr]   r   r   r   r_  r_  J  r_   r   r_  c                   $    e Zd Z ee          ZdS )EimFqdnNr]   r   r   r   ra  ra  L  r_   r   ra  c                   ,    e Zd Z eeddd          ZdS )	EimIdTyper2   r8   rH   )eimIdTypeOideimIdTypeFqdneimIdTypeProprietaryNrl   r   r   r   rc  rc  N  s'        f1ATUVVVJJJr   rc  c                   "    e Zd Z e            ZdS )CounterValueNr   r   r   r   rh  rh  P  r   r   rh  c                   "    e Zd Z e            ZdS )AssociationTokenNr   r   r   r   rj  rj  R  r   r   rj  c                   0    e Zd Z eeddddd          ZdS )EimSupportedProtocolr   r2   r8   rH   r}   )eimRetrieveHttpseimRetrieveCoapseimInjectHttpseimInjectCoapseimProprietaryNrl   r   r   r   rl  rl  T  s3        fq1UVgh%&( ( (JJJr   rl  c                       e Zd ZdS )EimConfigurationDataNrT   r   r   r   rs  rs  X  rU   r   rs  c                       e Zd ZdS )EimConfigurationDataSeqNrT   r   r   r   ru  ru  [  rf   r   ru  c                       e Zd ZdS )GetEimConfigurationDataNrT   r   r   r   rw  rw  ]  rf   r   rw  iU  c                        e Zd Z fdZeddedededeee	f         fd            Z
eddedefd            Zededefd	            Zd
edefdZ ed           G d de                      Z xZS )CardApplicationISDRc                     t                                          dt          d           | j        | j        _        | j        xj        |                                 gz  c_        d| j        _        d S )Nz	ADF.ISD-Rz/ISD-R (Issuer Security Domain Root) ApplicationnameaiddescEID)super__init__	AID_ISD_Rdecode_select_responseadfshell_commandsAddlShellCommandsscp_key_identityr:   	__class__s    r   r  zCardApplicationISDR.__init__a  sp    kyO 	 	Q 	Q 	Q*.*E'D$:$:$<$<#==$)!!!r   9000scctx_doexp_swr   c                 \    dt          |          dz  |fz  }|                     ||          S )zzPerform STORE DATA according to Table 47+48 in Section 5.7.2 of SGP.22.
        Only single-block store supported for now.z80E29100%02x%s00r8   )r*   send_apdu_checksw)r  r  r  capdus       r   
store_datazCardApplicationISDR.store_datai  s3     #c%jj!mU%;;$$UF333r   c                 B   |r9|                                 }t          |          }|dk    rt          d          S nd}t                              | t          |          |          \  }}|r2|r. |            }|                    t          |                     |S |S dS )zTransceive STORE DATA APDU with the card, transparently encoding the command data from TLV
        and decoding the response data tlv.   z DO > 255 bytes not supported yetr   )r  N)to_tlvr*   r+   ry  r  b2hfrom_tlvh2b)	r  cmd_doresp_clsr  
cmd_do_enc
cmd_do_lendata_swresp_dos	            r   store_data_tlvz"CardApplicationISDR.store_data_tlvp  s      	JZJC!"DEEE   J)44S#j//RX4YYs 	 "(**  T+++4r   c                     t          t          dg          g          }t                              | |t                     }|                                }t          t          |d                   d                   S )Nr   decodedchildrenget_euicc_data	eid_value)rF  r   ry  r  to_dictr  flatten_dict_lists)r  ged_cmdgedds       r   get_eidzCardApplicationISDR.get_eid  sh    $)@)@)@(ABBB!00g|LLKKMM%a(8&9::;GHHHr   data_hexc                     t                      }|                    t          |                     |                                }t	          |d                   S Nfci_templaterY   r  r  r  r  r:   r  tr  s       r   r  z*CardApplicationISDR.decode_select_response  C    MM	

3x==!!!IIKK!!N"3444r   Application-Specific Commandsc                      e Zd Z ej                    Ze                    dd            ej        e          d             Z	d Z
 ej                    Ze                    dd            ej        e          d             Zd	 Zd
 Zd Zd Z ej                    Ze                    ded            ej        e          d             Z ej                    Ze                    ddd            ej        e          d             Z ej                    Ze                                Ze                    dd           e                    dd           e                    ddd            ej        e          d             Z ej                    Ze                                Ze                    dd           e                    dd           e                    ddd            ej        e          d             Z ej                    Ze                                Ze                    dd           e                    dd            ej        e          d             Z ej                    Z e                     ddd            e                     d!dd"           e                     d#dd$            ej        e           d%             Z!d& Z" ej                    Z#e#                    d'd(           e#                    d)d*            ej        e#          d+             Z$d, Z%d- Z&d.S )/%CardApplicationISDR.AddlShellCommandsTX_DOz)Hexstring of encoded to-be-transmitted DO)helpc                 j    t                               | j        j        j        |j                  \  }}dS )zJPerform a raw STORE DATA command as defined for the ES10x eUICC interface.N)ry  r  _cmdlchanr  r  )r:   opts_datar  s       r   do_es10x_store_dataz9CardApplicationISDR.AddlShellCommands.do_es10x_store_data  s*     /99$)/:MtzZZLUCCCr   c                     t                               | j        j        j        t                      t
                    }|                                }| j                            t          |d                              dS )z6Perform an ES10a GetEuiccConfiguredAddresses function.euicc_configured_addressesN)	ry  r  r  r  r  re   r  poutput_jsonr  )r:   _optsecar  s       r   !do_get_euicc_configured_addresseszGCardApplicationISDR.AddlShellCommands.do_get_euicc_configured_addresses  s`    %44TY_5HJbJdJdf~CAI""#5a8T6U#V#VWWWWWr   
DP_ADDRESSz&Default SM-DP+ address as UTF-8 stringc                 0   t          t          |j                  g          }t                              | j        j        j        |t                     }|                                }| j        	                    t          |d                              dS )z.Perform an ES10a SetDefaultDpAddress function.r  r  set_default_dp_addressN)rp   r\   r  ry  r  r  r  r  r  r  r  )r:   r  sdda_cmdsddar  s        r   do_set_default_dp_addressz?CardApplicationISDR.AddlShellCommands.do_set_default_dp_address  s|     +5Edo5^5^5^4_```H&55dio6I8UhiiDAI""#5a8P6Q#R#RSSSSSr   c                     t                               | j        j        j        t                      t
                    }|                                }| j                            t          |d                              dS )z,Perform an ES10b GetEUICCChallenge function.get_euicc_challengeN)	ry  r  r  r  r  rv   r  r  r  r:   r  gecr  s       r   do_get_euicc_challengez<CardApplicationISDR.AddlShellCommands.do_get_euicc_challenge  s`    %44TY_5HJ[J]J]_pqqCAI""#5a8M6N#O#OPPPPPr   c                     t                               | j        j        j        t                      t
                    }|                                }| j                            t          |d                              dS )z+Perform an ES10b GetEUICCInfo (1) function.euicc_info1N)	ry  r  r  r  r  r   r  r  r  )r:   r  ei1r  s       r   do_get_euicc_info1z8CardApplicationISDR.AddlShellCommands.do_get_euicc_info1  \    %44TY_5H*,,XbccCAI""#5a6F#G#GHHHHHr   c                     t                               | j        j        j        t                      t
                    }|                                }| j                            t          |d                              dS )z+Perform an ES10b GetEUICCInfo (2) function.euicc_info2N)	ry  r  r  r  r  r   r  r  r  )r:   r  ei2r  s       r   do_get_euicc_info2z8CardApplicationISDR.AddlShellCommands.do_get_euicc_info2  r  r   c                     t                               | j        j        j        t                      t                    }|                                }| j                            t          |d                              dS )z+Perform an ES10b ListNotification function.list_notification_respN)
ry  r  r  r  r  r   r   r  r  r  )r:   r  lnr  s       r   do_list_notificationz:CardApplicationISDR.AddlShellCommands.do_list_notification  s`    $33DIO4GI\I^I^`tuuB

AI""#5a8P6Q#R#RSSSSSr   SEQ_NRz1Sequence Number of the to-be-removed notification)typer  c                 0   t          t          |j                  g          }t                              | j        j        j        |t                    }|	                                }| j        
                    t          |d                              dS )z5Perform an ES10b RemoveNotificationFromList function.r  r  notification_sent_respN)r   r   r  ry  r  r  r  r  r   r  r  r  )r:   r  rn_cmdrnr  s        r    do_remove_notification_from_listzFCardApplicationISDR.AddlShellCommands.do_remove_notification_from_list  s{     )9T[3Q3Q3Q2RSSSF$33DIO4GQeffB

AI""#5a8P6Q#R#RSSSSSr   z--all
store_truez$Retrieve all known tags of a profile)actionr  c                 T   |j         rd t                                          j        D             }g }|D ]T}|dk    r|                    |           |dk    r0|                    |dz	             |                    |dz             Ut          t          |          g          }nt                      }t                              | j	        j
        j        |t                    }|                                }| j	                            t          |d                              dS )	z*Perform an ES10c GetProfilesInfo function.c                     g | ]	}|j         
S r   r   )rA   nests     r   rC   zNCardApplicationISDR.AddlShellCommands.do_get_profiles_info.<locals>.<listcomp>  s    XXXTXXXr   r  i     r  r  profile_info_list_respN)allr  nested_collection_clsrW   appendr   r   ry  r  r  r  r  r  r  r  r  )r:   r  tagsu8tagsr   reqpir  s           r   do_get_profiles_infoz:CardApplicationISDR.AddlShellCommands.do_get_profiles_info  s    x +XX[-N-N-P-P-WXXX 2 2Cczzc****cQh///cDj111(763J3J3J2KLLL(**$33DIO4GNabbB

AI""#5a8P6Q#R#RSSSSSr   z
--isdp-aidz#Profile identified by its ISD-P AIDz--iccidzProfile identified by its ICCIDz--refresh-requiredzwhether a REFRESH is requiredc                    |j         r%t          t          |j                   g          }n;|j        r%t          t	          |j                  g          }nt          d          |t          |j                  g}t          |          }t          
                    | j        j        j        |t                    }|                                }| j                            t#          |d                              dS )z(Perform an ES10c EnableProfile function.r  r  'Either ISD-P AID or ICCID must be givenenable_profile_respN)isdp_aidr&  r   iccidr   r+   r  refresh_requiredr(  ry  r  r  r  r  r*  r  r  r  )r:   r  p_idep_cmd_contentsep_cmdepr  s          r   do_enable_profilez7CardApplicationISDR.AddlShellCommands.do_enable_profile  s     } L(74=3Q3Q3Q2RSSS L(53L3L3L2MNNN !!JKKK#[9N%O%O%OPO%???F$33DIO4GQbccB

AI""#5a8M6N#O#OPPPPPr   c                    |j         r%t          t          |j                   g          }n;|j        r%t          t	          |j                  g          }nt          d          |t          |j                  g}t          |          }t          
                    | j        j        j        |t                    }|                                }| j                            t#          |d                              dS )z)Perform an ES10c DisableProfile function.r  r  r  disable_profile_respN)r  r&  r   r  r   r+   r  r  r/  ry  r  r  r  r  r1  r  r  r  r:   r  r  dp_cmd_contentsdp_cmddpr  s          r   do_disable_profilez8CardApplicationISDR.AddlShellCommands.do_disable_profile  s     } L(74=3Q3Q3Q2RSSS L(53L3L3L2MNNN !!JKKK#[9N%O%O%OPO&@@@F$33DIO4GQcddB

AI""#5a8N6O#P#PQQQQQr   c                    |j         rt          |j                   }n,|j        rt          |j                  }nt	          d          |g}t          |          }t                              | j        j	        j
        |t                    }|                                }| j                            t          |d                              dS )z(Perform an ES10c DeleteProfile function.r  r  r  delete_profile_respN)r  r   r  r   r+   r5  ry  r  r  r  r  r7  r  r  r  r  s          r   do_delete_profilez7CardApplicationISDR.AddlShellCommands.do_delete_profile  s     } Lt}555 LTZ000 !!JKKK#fO%???F$33DIO4GQbccB

AI""#5a8M6N#O#OPPPPPr   z--delete-operationalzDelete all operational profilesz--delete-test-field-installedz3Delete all test profiles, except pre-installed onesz--reset-smdp-addresszReset the SM-DP+ addressc                 r   i }|j         rd|d<   |j        rd|d<   |j        rd|d<   t          t	          |          g          }t
                              | j        j        j	        |t                    }|                                }| j                            t          |d                              dS )	zPerform an ES10c eUICCMemoryReset function. This will permanently delete the selected subset of
            profiles from the eUICC.Tr:  r;  r<  r  r  euicc_memory_reset_respN)delete_operationaldelete_test_field_installedreset_smdp_addressr@  r9  ry  r  r  r  r  rB  r  r  r  )r:   r  flagsmr_cmdmrr  s         r   do_euicc_memory_resetz;CardApplicationISDR.AddlShellCommands.do_euicc_memory_reset4  s     E& :5912/ >9=56& 837/0(<3N3N3N2OPPPF$33DIO4GQeffB

AI""#5a8Q6R#S#STTTTTr   c                 (   t          t          dg          g          }t                              | j        j        j        |t                     }|                                }| j                            t          |d                              dS )z!Perform an ES10c GetEID function.r   r  r  r  N)
rF  r   ry  r  r  r  r  r  r  r  )r:   r  r  r  r  s        r   
do_get_eidz0CardApplicationISDR.AddlShellCommands.do_get_eidE  sy    "WdV-D-D-D,EFFFG%44TY_5H'S_``CAI""#5a8H6I#J#JKKKKKr   z--profile-nicknamezNickname of the profileICCIDz*ICCID of the profile whose nickname to setc                 d   |j         pd}t          |j                  t          |          g}t	          |          }t
                              | j        j        j	        |t                    }|                                }| j                            t          |d                              dS )z&Perform an ES10c SetNickname function. r  r  set_nickname_respN)profile_nicknamer   r  r   rK  ry  r  r  r  r  rP  r  r  r  )r:   r  nicknamesn_cmd_contentssn_cmdsnr  s          r   do_set_nicknamez5CardApplicationISDR.AddlShellCommands.do_set_nicknameP  s     ,2H$TZ888/RZ:[:[:[\O#_===F$33DIO4GQ`aaB

AI""#5a8K6L#M#MNNNNNr   c                     t                               | j        j        j        t                      t                    }|                                }| j                            t          |d                              dS )z5Perform an ES10c GetCerts() function on an IoT eUICC.get_certs_respN)
ry  r  r  r  r  rR  r]  r  r  r  )r:   r  gcr  s       r   do_get_certsz2CardApplicationISDR.AddlShellCommands.do_get_certsZ  s]    $33DIO4GXdeeB

AI""#5a8H6I#J#JKKKKKr   c                     t                               | j        j        j        t                      t
                    }|                                }| j                            t          |d                              dS )zBPerform an ES10b GetEimConfigurationData function on an Iot eUICC.get_eim_configuration_dataN)	ry  r  r  r  r  rw  r  r  r  r  s       r   do_get_eim_configuration_datazCCardApplicationISDR.AddlShellCommands.do_get_eim_configuration_data`  sf    %44TY_5HJaJcJc5LN NCAI""#5a8T6U#V#VWWWWWr   N)'r   r   r   argparseArgumentParseres10x_store_data_parseradd_argumentr   with_argparserr  r  set_def_dp_addr_parserr  r  r  r  r  rem_notif_parserr,   r  get_profiles_info_parserr  en_prof_parseradd_mutually_exclusive_groupen_prof_grpr  dis_prof_parserdis_prof_grpr  del_prof_parserdel_prof_grpr  mem_res_parserr  r  set_nickname_parserr  r!  r$  r   r   r   r  r    s        #:("9";";,,W;f,ggg		4	5	5	[ 	[ 
6	5	[	X 	X 	X "9!8!:!:++L?g+hhh		3	4	4	T 	T 
5	4	T	Q 	Q 	Q	I 	I 	I	I 	I 	I	T 	T 	T 38244%%hS?r%sss		-	.	.	T 	T 
/	.	T $;8#:#<#<  --glQw-xxx		5	6	6	T 	T 
7	6	T* 1022$AACC  4Y ZZZ  1R SSS##$8Ts#ttt		^	,	,	Q 	Q 
-	,	Q 2(133&CCEE!!,5Z![[[!!)2S!TTT$$%9,Ut$uuu		_	-	-	R 	R 
.	-	R 2(133&CCEE!!,5Z![[[!!)2S!TTT		_	-	-	Q 	Q 
.	-	Q 1022##$:<)J 	$ 	L 	L 	L##$CL)^ 	$ 	` 	` 	`##$:<)C 	$ 	E 	E 	E 
	^	,	,	U 	U 
-	,	U 	L 	L 	L 6h577(()=D](^^^((7c(ddd		0	1	1	O 	O 
2	1	O	L 	L 	L	X 	X 	X 	X 	Xr   r  )r  )r   r   r   r  staticmethodr   r
   r   Tupler   r  r  r)   r  objectr  r	   r   r  __classcell__r  s   @r   ry  ry  `  sj       * * * * * 4 4 4 4
 4W\]cem]mWn 4 4 4 \4  O z    \* I_ I I I I \I5v 5& 5 5 5 5 :;;QX QX QX QX QXJ QX QX <;QX QX QX QX QXr   ry  c                   l     e Zd ZdedefdZ fdZ ed           G d de                      Z	 xZ
S )CardApplicationECASDr  r   c                     t                      }|                    t          |                     |                                }t	          |d                   S r  r  r  s       r   r  z+CardApplicationECASD.decode_select_responseh  r  r   c                     t                                          dt          d           | j        | j        _        | j        xj        |                                 gz  c_        d| j        _        d S )Nz	ADF.ECASDz?ECASD (eUICC Controlling Authority Security Domain) Applicationr{  r  )r  r  	AID_ECASDr  r  r  r  r  r  s    r   r  zCardApplicationECASD.__init__n  sp    ky_ 	 	a 	a 	a*.*E'D$:$:$<$<#==$)!!!r   r  c                       e Zd ZdS )&CardApplicationECASD.AddlShellCommandsNrT   r   r   r   r  rA  v  s        r   r  )r   r   r   r
   r8  r  r  r	   r   r  r9  r:  s   @r   r<  r<  g  s        5v 5& 5 5 5 5* * * * * :;;    J   <;    r   r<  c                   B     e Zd ZdZ fdZededdfd            Z xZS )CardProfileEuiccSGP32r  c                 L    t                                          d           d S )NzIoT eUICC (SGP.32)r|  r  r  r  s    r   r  zCardProfileEuiccSGP32.__init__}  %    233333r   r  r   Nc                     d|_         |                    t                     t                              |t                      t                     d S Nr"   )cla_byte
select_adfr  ry  r  rR  r]  clsr  s     r   _try_match_cardz%CardProfileEuiccSGP32._try_match_card  s?     y!!!**3|LLLLLr   	r   r   r   ORDERr  classmethodr   rN  r9  r:  s   @r   rC  rC  z  su        E4 4 4 4 4 M/ Md M M M [M M M M Mr   rC  c                   B     e Zd ZdZ fdZededdfd            Z xZS )CardProfileEuiccSGP22   c                 L    t                                          d           d S )NzConsumer eUICC (SGP.22)rE  rF  r  s    r   r  zCardProfileEuiccSGP22.__init__  s%    788888r   r  r   Nc                 |    d|_         |                    t                     t                              |          }d S rI  )rJ  rK  r  ry  r  )rM  r  r-   s      r   rN  z%CardProfileEuiccSGP22._try_match_card  s4     y!!!!))#..r   rO  r:  s   @r   rS  rS    sk        E9 9 9 9 9 // /d / / / [/ / / / /r   rS  c                   B     e Zd ZdZ fdZededdfd            Z xZS )CardProfileEuiccSGP02   c                 L    t                                          d           d S )NzM2M eUICC (SGP.02)rE  rF  r  s    r   r  zCardProfileEuiccSGP02.__init__  rG  r   r  r   Nc                 r    d|_         |                    t                     |                    d           d S )Nr"   r   )rJ  rK  r?  get_datarL  s     r   rN  z%CardProfileEuiccSGP02._try_match_card  s3    y!!!Tr   rO  r:  s   @r   rX  rX    sk        E4 4 4 4 4 / d    [    r   rX  )rG   r%  	constructr   r   r   r   r   r   r	   osmocom.utilsr
   osmocom.tlvosmocom.constructpySim.exceptionsr   pySim.utilsr   r   pySim.commandsr   pySim.ts_102_221r   pySim.global_platformpySim
BER_TLV_IEr   global_platformDataCollectionpossible_nestedr  r)   r0   boolr4   Adapterr6   rn   rz   r  r?  AID_ISD_P_FILEAID_ISD_P_MODULErN   rS   FciTemplateNestedListrY   r\   rb   re   rh   rp   rr   rv   rx   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r
  r  r  r  r  r  r  r  r  r&  r(  r*  r,  r/  r1  r3  r5  r7  r9  r>  r@  rB  rD  rF  rH  rK  rM  rP  rR  rT  rW  rZ  r]  r_  ra  rc  rh  rj  rl  rs  ru  rw  CardApplicationSDry  r<  rC  rS  rX  r   r   r   <module>rq     s   .  ; ; ; ; ; ; ; ; ; ; ; ; 8 8 8 8 8 8 8 8 8 8                     ) ) ) ) ) ) 4 4 4 4 4 4 4 4 4 4 * * * * * * , , , , , ,    ) ) ) ) )zt ) ) ) )   $ 4 ; ;H E E E    0    0 0 0 0 0W 0 0 0 nUU1f--.. 9	8	88     ZT    	 	 	 	 	G]F^ 	 	 	 	
	 	 	 	 	*$u/D/Z0R/S0T 	 	 	 	* * * * *zt * * * ** * * * *JD * * * *	 	 	 	 	zv?OQ^>_ 	 	 	 	8 8 8 8 8*$ 8 8 8 8	 	 	 	 	*&:JL_9` 	 	 	 	    ZT    	 	 	 	 	
7G 	 	 	 	    *$        :4    	 	 	 	 	JDBVAW 	 	 	 		 	 	 	 	zt=Q<R 	 	 	 		 	 	 	 	6SUm0n 	 	 	 	    ZT        zt        jd        ZT        jd        JD        JD    X X X X XJD X X X X    
    * * * * *:4 * * * *. . . . .jd . . . .        	 	 	 	 	JD* 	 	 	 		 	 	 	 	jdM? 	 	 	 		 	 	 	 	FVXg1?Rg1>@]1I=Zc1EwP_	1a 	 	 	 	k k k k k:4 k k k k	 	 	 	 	*&:N9O 	 	 	 	" " " " "
 " " " "* * * * **$ * * * */ / / / /JD / / / /	 	 	 	 	:69FZ;NPU;W 	 	 	 		 	 	 	 	zt=Q<R 	 	 	 	2 2 2 2 2:4 2 2 2 2	 	 	 	 	:6;S;W;Y 	 	 	 	
K K K K Kzt K K K K	 	 	 	 	*&) 	 	 	 		 	 	 	 	:6;S:T 	 	 	 		 	 	 	 	jfR 	 	 	 	% % % % %jd % % % %	 	 	 	 		 	 	 	 	    jd    5 5 5 5 5:6 5 5 5 5* * * * *jd * * * ** * * * **$ * * * ** * * * **$ * * * *, , , , ,zt , , , ,    :4    E E E E E:4 E E E E            JD    ' ' ' ' 'zt ' ' ' '    zt        zt        :41ACSUe0f        :4    	 	 	 	 	*$wo0C[RZ\`0<>PRo0<>R0T 	 	 	 	
	 	 	 	 	ZT;- 	 	 	 	H H H H H:4 H H H H	 	 	 	 	*&.J^9_ 	 	 	 	    *$    e e e e e:4 e e e e	 	 	 	 	
gu5E 	 	 	 		 	 	 	 	zv7H+6V 	 	 	 		 	 	 	 	
~ 	 	 	 	K K K K KJD K K K K	 	 	 	 	
8I;7W 	 	 	 		 	 	 	 	 	 	 	 	@ @ @ @ @:4 @ @ @ @	 	 	 	 	zvw6F 	 	 	 		 	 	 	 	
~ 	 	 	 	9 9 9 9 9:4 9 9 9 9K K K K K*$ K K K K	 	 	 	 	*&, 	 	 	 		 	 	 	 	:6;- 	 	 	 	    zt    	 	 	 	 	:67H2E 	 	 	 	* * * * * * * * *	 	 	 	 	ZVU<N4O 	 	 	 	I I I I I
 I I I I	 	 	 	 	jf6G5H 	 	 	 		 	 	 	 	*& 	 	 	 	    ZT        zt    C C C C CJD C C C C	 	 	 	 	:6>CSUb2c 	 	 	 	* * * * *JD * * * ** * * * *jd * * * *W W W W W
 W W W W" " " " ":4 " " " "" " " " "zt " " " "( ( ( ( (:4 ( ( ( (	 	 	 	 	:4T`9IK_9a 	 	 	 		 	 	 	 	jd<P;Q 	 	 	 		 	 	 	 	jf>U=V 	 	 	 	EX EX EX EX EX%/A EX EX EXN    50B   &M M M M MO M M M/ / / / /O / / /
 
 
 
 
O 
 
 
 
 
r   