set debug true
set echo true

# Create a backup the files we will modify
export --filename MF/ADF.USIM/EF.BDN > restore_ef_bdn.script.tmp

# Select an arbitrary file to work with
select MF/ADF.USIM/EF.BDN

# Clear file contents
update_record 1 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
read_record 1 > test_record_uicc.tmp

# Write some short pattern to the file, expect tail to be padded with 0xff
update_record 1 abcdef
read_record 1 >> test_record_uicc.tmp

# Write some pattern to three different records
update_record 1 0123456789abcdef0123456789abcdef0123456789abcdef0123456789
update_record 5 0123456789abcdef0123456789abcdef0123456789abcdef0123456789
update_record 10 0123456789abcdef0123456789abcdef0123456789abcdef0123456789
read_records >> test_record_uicc.tmp

# Write some json encoded content to three different records
update_record_decoded 1 '{ "alpha_id": "", "len_of_bcd": 7, "ton_npi": { "ext": true, "type_of_number": "reserved_for_extension", "numbering_plan_id": "reserved_for_extension" }, "dialing_nr": "1234567", "cap_conf_id": 42, "ext4_record_id": 23 }'
update_record_decoded 5 '{ "alpha_id": "", "len_of_bcd": 7, "ton_npi": { "ext": true, "type_of_number": "reserved_for_extension", "numbering_plan_id": "reserved_for_extension" }, "dialing_nr": "1234567", "cap_conf_id": 42, "ext4_record_id": 23 }'
update_record_decoded 10 '{ "alpha_id": "", "len_of_bcd": 7, "ton_npi": { "ext": true, "type_of_number": "reserved_for_extension", "numbering_plan_id": "reserved_for_extension" }, "dialing_nr": "1234567", "cap_conf_id": 42, "ext4_record_id": 23 }'
read_records_decoded >> test_record_uicc.tmp
read_record_decoded 1 >> test_record_uicc.tmp

# Restore modified files to their original state
run_script restore_ef_bdn.script.tmp
