*gq4ddlmZddlZddlZddlmZmZddlmZmZm Z m Z ddl Tde de ded e fd Zed Gd d eZdS))ListN) CommandSetwith_default_category)b2h auto_uint8 auto_uint16 is_hexstr)*patternrepeatsizereturnc|s"|t|z }||dd|zzS|t|z}||t|zz }||z|d|zS)zNExpand the fill/repeat pattern as per TS 102 222 Section 6.3.2.2.2 Tags C1/C2.N)len)r r r pad_lencountpart_lens >/home/jenkins/workspace/simtester-sanitize/pySim/ts_102_222.pyexpand_patternrso 4W%///G $%#g,,..(!333z"TS 102 222 Administrative CommandsceZdZdZejZedddedede j ed Z d e efd Z ejZed dd edede j edZd e efdZe j edZd e efdZejZeddde j edZejZejedZedZeddededdededdeded degd!d"#ed$ed%ed&dd'ed(ed)ed*ed+e j ed,ZejZejedZ edZ!ed-Z"e ddede ddede!d&dd'e!d.ed/e!d0ed1e"d2d3e"d4d3e"d5d3e"d6d3ed*ed+e j ed7Z#ejZ$e$je$dZ%e%ddede$ded8e j e$d9Z&d e efd:Z'd;S)<Ts102222Commandsz;Administrative commands for telecommunication applications.z--force-delete store_truezSI really want to permanently delete the file. I know pySim cannot re-create it yet!)actionhelpNAMEzFile name or FID to delete)typerc|js|jddS|jj|j}|jjj|j\}}dS)zDelete the specified file. DANGEROUS! See TS 102 222 Section 6.4. This will permanently delete the specified file from the card. pySim has no support to re-create files yet, and even if it did, your card may not allow it!zCRefusing to permanently delete the file, please read the help text.N) force_delete_cmdperrorlchanget_file_for_filenamerscc delete_filefidselfoptsf_data_sws rdo_delete_filezTs102222Commands.do_delete_file/sh    I  b c c c F IO 1 1$) < <y*66qu== rrcd|jjji}|j|||||S)z+Command Line tab completion for DELETE FILE index_dictr!r# selected_fileget_selectable_namesindex_based_completer)textlinebegidxendidxr2s rcomplete_delete_filez%Ts102222Commands.complete_delete_file:A6KKMMN y--dD&&U_-```rz--forcezFI really want to terminate the file. I know I can not recover from it!zFile name or FIDc|js|jddS|jj|j}|jjj|j\}}dS)aTerminate the specified DF. DANGEROUS! See TS 102 222 6.7. This is a permanent, one-way operation on the card. There is no undo, you can not recover a terminated DF. The only permitted command for a terminated DF is the DLETE FILE command.:Refusing to terminate the file, please read the help text.N) forcer!r"r#r$rr% terminate_dfr'r(s rdo_terminate_dfz Ts102222Commands.do_terminate_dfDg z  I  Y Z Z Z F IO 1 1$) < <y*77>> rcd|jjji}|j|||||S)z,Command Line tab completion for TERMINATE DFr0r1r3r7s rcomplete_terminate_dfz&Ts102222Commands.complete_terminate_dfOr=rc|js|jddS|jj|j}|jjj|j\}}dS)aTerminate the specified EF. DANGEROUS! See TS 102 222 6.8. This is a permanent, one-way operation on the card. There is no undo, you can not recover a terminated EF. The only permitted command for a terminated EF is the DLETE FILE command.r?N) r@r!r"r#r$rr% terminate_efr'r(s rdo_terminate_efz Ts102222Commands.do_terminate_efTrCrcd|jjji}|j|||||S)z,Command Line tab completion for TERMINATE EFr0r1r3r7s rcomplete_terminate_efz&Ts102222Commands.complete_terminate_ef_r=rz--force-terminate-cardzRI really want to permanently terminate the card. It will not be usable afterwards!c|js|jddS|jjj\}}dS)zTerminate the Card. SUPER DANGEROUS! See TS 102 222 Section 6.9. This will permanently brick the card and can NOT be recovered from!zFRefusing to permanently terminate the card, please read the help text.N)force_terminate_cardr!r"r#r%terminate_card_usage)r)r*r,r-s rdo_terminate_card_usagez(Ts102222Commands.do_terminate_card_usagehsK(  I  e f f f Fy*??AA rzrequired argumentszoptional argumentsz--ef-arr-file-idTz.Referenced Security: File Identifier of EF.ARR)requiredrrz--ef-arr-record-nrz0Referenced Security: Record Number within EF.ARRz --file-sizezSize of file in octetsz --structure) transparent linear_fixedber_tlvz!Structure of the to-be-created EF)rOrchoicesrz--short-file-idz+Short File Identifier as 2-digit hex stringz --shareablezShould the file be shareable?z--record-lengthzLength of each record in octetsFILE_IDz)File Identifier as 4-character hex stringcXd|jd|jdi}|jdkri|js|jddS|j|d<|j|jz|d<|d|dz|jkrt d n'|jd kr|jd dSt| t|j td t|j |j d t|j t|j g}t#|}|jjjt+|\}}|jj|jjjdS)zNCreate a new EF below the currently selected DF. Requires related privileges.file_descriptor_byte working_ef shareable file_type structurerQz8you must specify the --record-length for linear fixed EFN record_len num_of_recz/File size not evenly divisible by record lengthrRz/BER-TLV creation not yet fully supported, sorrydecodedoperational_activatedef_arr_file_idef_arr_record_nrchildren)rYr[ record_lengthr!r" file_size ValueErrorFileDescriptorFileIdentifierrTLifeCycleStatusIntegerSecurityAttribReferencedrbrcFileSizeShortFileIdentifier short_file_id FcpTemplater#r% create_filerto_tlv select_filer4)r)r*file_descriptoriesfcpr,r-s r do_create_efzTs102222Commands.do_create_efs #!^)!^%%  >^ + +%    ![\\\,0,>OL ),0Nd>P,POL )|,|/LLPTP^^^ !RSSS_ ^y ( ( I  N O O O Fo666t|8\8\8\%.EFFF'4CVEIEZ1]1]^^^///"4+=>>> 3'''y*66s3::<<7H7HII  ##DIO$ABBBBBrz sysmoISIM-SJA optional argumentsz--aidz0Application ID (creates an ADF, instead of a DF)z--total-file-sizez.Physical memory allocated for DF/ADi in octetsz--permit-rfm-create)rz--permit-rfm-delete-terminatez--permit-other-applet-createz&--permit-other-applet-delete-terminatecd|jdddi}g}|t||t|j|jr(|t |j|td|t|j |j d|j r(|t|j |j s|js|js|jrM|j |j|j|jd}|t#t%|g t'| }|jjjt1|\}}|jj|jjjd S) zNCreate a new DF below the currently selected DF. Requires related privileges.rVdf no_info_givenrXr^r`ra) rfm_createrfm_delete_terminateother_applet_createother_applet_delete_terminaterdN)rYappendrirjrTaidDfNamerkrlrbrctotal_file_size TotalFileSizepermit_rfm_createpermit_rfm_delete_terminatepermit_other_applet_create$permit_other_applet_delete_terminateProprietaryInformationToolkitAccessConditionsrpr!r#r%rqrrrrsr4)r)r*rtru toolkit_acrvr,r-s r do_create_dfzTs102222Commands.do_create_dfs #!^!,%%  >/:::;;; >$,777888 8 1 JJvdh/// 0 0 0 )2IJJJKKK +tGZIMI^5a5abbb c c c   D JJ}T-ABBB C C C  ! gT%E gIh glpmV g!3'+'G&*&E040Y J JJ-8OXb8c8c8c7deee f f f3'''y*66s3::<<7H7HII  ##DIO$ABBBBBrz!Name or FID of file to be resizedc|jj|j}t |jt |jg}t|}|jjj t| \}}|jj |jjjdS)zTResize an existing EF below the currently selected DF. Requires related privileges.r^rdN)r!r#r$rrjr'rmrgrpr% resize_filerrrrsr4)r)r*r+rurvr,r-s r do_resize_efzTs102222Commands.do_resize_efs IO 1 1$) < <ae,,,///13'''y*66s3::<<7H7HII  ##DIO$ABBBBBrcd|jjji}|j|||||S)z)Command Line tab completion for RESIZE EFr0r1r3r7s rcomplete_resize_efz#Ts102222Commands.complete_resize_efr=rN)(__name__ __module__ __qualname____doc__argparseArgumentParserdelfile_parser add_argumentstrcmd2with_argparserr.rr< termdf_parserrBrErHrJ tcard_parserrN create_parser_action_groupspopadd_argument_groupcreate_requiredcreate_optionalrrr rwcreatedf_parsercreatedf_requiredcreatedf_optionalcreatedf_sja_optionalrresize_ef_parserresize_ef_requiredrrrrrr&s4EE,X,..N 0f hhhS7STTTT((>>)(>a$s)aaaa ,H+--MyY[[[vC6HIIIT''??('?a49aaaa T''??('?a49aaaa +8*,,L6|egggT&&BB'&B,H+--M $$&&&#667KLLO#667KLLO  !3dTD EEE  !5:]O PPP  KVn ooo  CQ{Q{Q{&I!KKK  !2Cp qqq  |Ji jjj  !2Kl mmmyy?jkkkT''CC('C@.h-//O"&&((('::;OPP'::;OPP+>>?abb""#53VF"GGG""#7$Z_Q"RRR""=Lk"lll""7As"ttt""#6[O"AAA&&'<\&RRR&&'F|&\\\&&'El&[[[&&'OXd&eee  Al mmmT))CC*)CB/x.00#''))))<<=QRR##MD{Yq#rrr!!&s9\!]]]T)**CC+*CaS aaaaaarr)typingrrrrr osmocom.utilsrrrr pySim.ts_102_221bytesboolintrrrrrrs( 22222222AAAAAAAAAAAA4E444s4u4444;<<@a@a@a@a@az@a@a=<@a@a@ar