Skip to content

UICC Toolkit Application Instantiation failing with 6A80 error #389

@jelson-tech94

Description

@jelson-tech94

I have a very simple applet built with UICC Toolkit (TS 102 241). I can load the package properly on my card, but i cannot install the instance of the applet. It always fail with 6A80 error.

Below is my Install4Install command and the applet code just in case anyone here can help me.

Install 4 Install Command:

80 E6 0C 00 5B

08 A000000559101001 -- Package AID
0B A000000559101001112233 -- Applet AID
10 A00000055910100111223301D0000101 -- Instance AID

03 000000 --Privileges

2F 
	C9 01 00 -- Application Specific Parameters
	EF 00 
	EA 28 -- UICC Toolkit Application Specific Parameters
		80 0A 03001001000000000000
		81 18 0001000010A0000000871002FFFFFFFF8907090000010000
	82 00
00

Applet Code:

/** 
 * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
 * 
 */

package com.multiimsi.simple;

import javacard.framework.*;
import uicc.toolkit.*;
import uicc.access.*;
import uicc.system.*;

public class MultiIMSIsimple extends Applet implements ToolkitInterface, ToolkitConstants {
	private static final short FID_DF_USIM  = (short)0x7FFF; 
	private static final short FID_EF_IMSI  = (short)0x6F07;
	private static final byte DEV_ID_ME = (byte)0x82;
	private static final short FID_DF_MF  = (short)0x3F00;
	private static final byte[] IMSI_A = {(byte)0x08, (byte)0x26, (byte)0x18, (byte)0x10, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0xF1};
    private static final byte[] IMSI_B = {(byte)0x08, (byte)0x26, (byte)0x12, (byte)0x34, (byte)0x56, (byte)0x78, (byte)0x90, (byte)0x12, (byte)0xF1};

    private FileView simFileView;
    private byte[] tempBuffer;

    private MultiIMSIsimple() {
    	
        ToolkitRegistry reg = ToolkitRegistrySystem.getEntry();
        reg.setEvent(EVENT_EVENT_DOWNLOAD_LOCATION_STATUS);
        simFileView = UICCSystem.getTheUICCView(JCSystem.CLEAR_ON_RESET);
        tempBuffer = new byte[10];
    }

    /**
     * Installs this applet.
     * 
     * @param bArray
     *            the array containing installation parameters
     * @param bOffset
     *            the starting offset in bArray
     * @param bLength
     *            the length in bytes of the parameter data in bArray
     */
    public static void install(byte[] bArray, short bOffset, byte bLength) {
    	try {
    		// Checkpoint 1
            ISOException.throwIt((short) 0x6F01); // chegou aqui
            
            MultiIMSIsimple applet = new MultiIMSIsimple();
            
            ISOException.throwIt((short) 0x6F02); // chegou aqui
            
    		new MultiIMSIsimple().register();
    		
    		// Checkpoint 2
            ISOException.throwIt((short) 0x6F03); // chegou aqui
    		
    	} catch (Exception e) {
            // Captura silenciosa de qualquer erro
            ISOException.throwIt((short) 0x6F42); // ou outro código para depuração
        }
    }

    public void process(APDU apdu) {
        if (selectingApplet()) return;
    }

    public void processToolkit(short event) {
        if (event == EVENT_EVENT_DOWNLOAD_LOCATION_STATUS) {
            EnvelopeHandler env = EnvelopeHandlerSystem.getTheHandler();
            short mccMncOffset = env.findTLV(TAG_LOCATION_INFORMATION, (byte)0x01);
            if (mccMncOffset == TLV_NOT_FOUND) return;

            //short valueOffset = env.getValueOffset();
            byte mccDigit1 = env.getValueByte((short)(mccMncOffset));
            byte mccDigit2 = env.getValueByte((short)(mccMncOffset + 1));
            byte mccDigit3 = env.getValueByte((short)(mccMncOffset + 2));
            byte mncDigit1 = env.getValueByte((short)(mccMncOffset + 3));
            byte mncDigit2 = env.getValueByte((short)(mccMncOffset + 4));
            byte mncDigit3 = env.getValueByte((short)(mccMncOffset + 5));

            // Comparar com MCC = 268 e MNC = 01
            boolean is26801 = (mccDigit1 == '2' && mccDigit2 == '6' && mccDigit3 == '8' &&
                               mncDigit1 == '0' && mncDigit2 == '1');

            try {
                simFileView.select(FID_DF_MF);
                simFileView.select(FID_DF_USIM);
                simFileView.select(FID_EF_IMSI);

                byte[] imsiToWrite = is26801 ? IMSI_A : IMSI_B;
                simFileView.updateBinary((short)0, imsiToWrite, (short)0, (short)imsiToWrite.length);

                // Trigger refresh (simple refresh for EF IMSI)
                ProactiveHandler proHdlr = ProactiveHandlerSystem.getTheHandler();
                proHdlr.init(PRO_CMD_REFRESH, (byte)0x00, DEV_ID_ME);
                proHdlr.appendTLV(TAG_FILE_LIST, new byte[]{(byte)0x6F, (byte)0x07}, (short)0, (short)2);
                proHdlr.send();

            } catch (Exception e) {
                // Opcional: tratamento de erro (por ex., log, fallback, etc.)
            }
        }  
    }
}

I have tried changing the parameters with multiple combination with no success, including minimal and basic parameters installation. Also, by adding some error handling to the applet code, I could understand that the failure happens before the install method is called.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions