Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fdb2d511 authored by nharold's avatar nharold Committed by Gerrit Code Review
Browse files

Merge changes from topic 'dump-sim-records'

* changes:
  Add PLMN Selection Info to SIM Records
  Add meaningful error strings to IccIoResult
  Cleanup of IccConstants and SIMRecords Constants
parents 1ff88113 14545cbe
Loading
Loading
Loading
Loading
+36 −21
Original line number Diff line number Diff line
@@ -30,21 +30,21 @@ public interface IccConstants {
    static final int EF_EXT2 = 0x6F4B;
    static final int EF_EXT3 = 0x6F4C;
    static final int EF_EXT5 = 0x6F4E;
    static final int EF_EXT6 = 0x6fc8;   // Ext record for EF[MBDN]
    static final int EF_EXT6 = 0x6FC8;   // Ext record for EF[MBDN]
    static final int EF_MWIS = 0x6FCA;
    static final int EF_MBDN = 0x6fc7;
    static final int EF_PNN = 0x6fc5;
    static final int EF_OPL = 0x6fc6;
    static final int EF_MBDN = 0x6FC7;
    static final int EF_PNN = 0x6FC5;
    static final int EF_OPL = 0x6FC6;
    static final int EF_SPN = 0x6F46;
    static final int EF_SMS = 0x6F3C;
    static final int EF_ICCID = 0x2fe2;
    static final int EF_ICCID = 0x2FE2;
    static final int EF_AD = 0x6FAD;
    static final int EF_MBI = 0x6fc9;
    static final int EF_MSISDN = 0x6f40;
    static final int EF_SPDI = 0x6fcd;
    static final int EF_SST = 0x6f38;
    static final int EF_MBI = 0x6FC9;
    static final int EF_MSISDN = 0x6F40;
    static final int EF_SPDI = 0x6FCD;
    static final int EF_SST = 0x6F38;
    static final int EF_CFIS = 0x6FCB;
    static final int EF_IMG = 0x4f20;
    static final int EF_IMG = 0x4F20;

    // USIM SIM file ids from TS 131.102
    public static final int EF_PBR = 0x4F30;
@@ -54,13 +54,13 @@ public interface IccConstants {
    static final int EF_MAILBOX_CPHS = 0x6F17;
    static final int EF_VOICE_MAIL_INDICATOR_CPHS = 0x6F11;
    static final int EF_CFF_CPHS = 0x6F13;
    static final int EF_SPN_CPHS = 0x6f14;
    static final int EF_SPN_SHORT_CPHS = 0x6f18;
    static final int EF_INFO_CPHS = 0x6f16;
    static final int EF_CSP_CPHS = 0x6f15;
    static final int EF_SPN_CPHS = 0x6F14;
    static final int EF_SPN_SHORT_CPHS = 0x6F18;
    static final int EF_INFO_CPHS = 0x6F16;
    static final int EF_CSP_CPHS = 0x6F15;

    // CDMA RUIM file ids from 3GPP2 C.S0023-0
    static final int EF_CST = 0x6f32;
    static final int EF_CST = 0x6F32;
    static final int EF_RUIM_SPN =0x6F41;

    // ETSI TS.102.221
@@ -75,12 +75,27 @@ public interface IccConstants {
    static final int EF_CSIM_MIPUPP = 0x6F4D;

    //ISIM access
    static final int EF_IMPU = 0x6f04;
    static final int EF_IMPI = 0x6f02;
    static final int EF_DOMAIN = 0x6f03;
    static final int EF_IST = 0x6f07;
    static final int EF_PCSCF = 0x6f09;
    static final int EF_PSI = 0x6fe5;
    static final int EF_IMPU = 0x6F04;
    static final int EF_IMPI = 0x6F02;
    static final int EF_DOMAIN = 0x6F03;
    static final int EF_IST = 0x6F07;
    static final int EF_PCSCF = 0x6F09;
    static final int EF_PSI = 0x6FE5;

    //PLMN Selection Information w/ Access Technology TS 131.102
    static final int EF_PLMN_W_ACT = 0x6F60;
    static final int EF_OPLMN_W_ACT = 0x6F61;
    static final int EF_HPLMN_W_ACT = 0x6F62;

    //Equivalent Home and Forbidden PLMN Lists TS 131.102
    static final int EF_EHPLMN = 0x6FD9;
    static final int EF_FPLMN = 0x6F7B;

    // Last Roaming Selection Indicator
    static final int EF_LRPLMNSI = 0x6FDC;

    //Search interval for higher priority PLMNs
    static final int EF_HPPLMN = 0x6F31;

    // SMS record length from TS 51.011 10.5.3
    static public final int SMS_RECORD_LENGTH = 176;
+7 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.telephony.uicc;

import android.os.*;

import com.android.internal.telephony.CommandsInterface;

import java.util.ArrayList;
@@ -25,6 +26,7 @@ import java.util.ArrayList;
 * {@hide}
 */
public abstract class IccFileHandler extends Handler implements IccConstants {
    private static final boolean VDBG = false;

    //from TS 11.11 9.1 or elsewhere
    static protected final int COMMAND_READ_BINARY = 0xb0;
@@ -516,6 +518,11 @@ public abstract class IccFileHandler extends Handler implements IccConstants {

                fileid = msg.arg1;

                if (VDBG) {
                    logd(String.format("Contents of the Select Response for command %x: ", fileid)
                            + IccUtils.bytesToHexString(data));
                }

                if (TYPE_EF != data[RESPONSE_DATA_FILE_TYPE]) {
                    throw new IccFileTypeMismatch();
                }
@@ -628,7 +635,6 @@ public abstract class IccFileHandler extends Handler implements IccConstants {

    protected abstract String getEFPath(int efid);
    protected abstract void logd(String s);

    protected abstract void loge(String s);

}
+143 −2
Original line number Diff line number Diff line
@@ -22,6 +22,147 @@ package com.android.internal.telephony.uicc;
 */
public class
IccIoResult {

    private static final String UNKNOWN_ERROR = "unknown";

    private String getErrorString() {
        // Errors from 3gpp 11.11 9.4.1
        // Additional Errors from ETSI 102.221
        //
        // All error codes below are copied directly from their respective specification
        // without modification except in cases where necessary string formatting has been omitted.
        switch(sw1) {
            case 0x62:
                switch(sw2) {
                    case 0x00: return "No information given,"
                               + " state of non volatile memory unchanged";
                    case 0x81: return "Part of returned data may be corrupted";
                    case 0x82: return "End of file/record reached before reading Le bytes";
                    case 0x83: return "Selected file invalidated";
                    case 0x84: return "Selected file in termination state";
                    case 0xF1: return "More data available";
                    case 0xF2: return "More data available and proactive command pending";
                    case 0xF3: return "Response data available";
                }
                break;
            case 0x63:
                if (sw2 >> 4 == 0x0C) {
                    return "Command successful but after using an internal"
                        + "update retry routine but Verification failed";
                }
                switch(sw2) {
                    case 0xF1: return "More data expected";
                    case 0xF2: return "More data expected and proactive command pending";
                }
                break;
            case 0x64:
                switch(sw2) {
                    case 0x00: return "No information given,"
                               + " state of non-volatile memory unchanged";
                }
                break;
            case 0x65:
                switch(sw2) {
                    case 0x00: return "No information given, state of non-volatile memory changed";
                    case 0x81: return "Memory problem";
                }
                break;
            case 0x67:
                switch(sw2) {
                    case 0x00: return "incorrect parameter P3";
                    default: return "The interpretation of this status word is command dependent";
                }
                // break;
            case 0x6B: return "incorrect parameter P1 or P2";
            case 0x6D: return "unknown instruction code given in the command";
            case 0x6E: return "wrong instruction class given in the command";
            case 0x6F:
                switch(sw2) {
                    case 0x00: return "technical problem with no diagnostic given";
                    default: return "The interpretation of this status word is command dependent";
                }
                // break;
            case 0x68:
                switch(sw2) {
                    case 0x00: return "No information given";
                    case 0x81: return "Logical channel not supported";
                    case 0x82: return "Secure messaging not supported";
                }
                break;
            case 0x69:
                switch(sw2) {
                    case 0x00: return "No information given";
                    case 0x81: return "Command incompatible with file structure";
                    case 0x82: return "Security status not satisfied";
                    case 0x83: return "Authentication/PIN method blocked";
                    case 0x84: return "Referenced data invalidated";
                    case 0x85: return "Conditions of use not satisfied";
                    case 0x86: return "Command not allowed (no EF selected)";
                    case 0x89: return "Command not allowed - secure channel -"
                               + " security not satisfied";
                }
                break;
            case 0x6A:
                switch(sw2) {
                    case 0x80: return "Incorrect parameters in the data field";
                    case 0x81: return "Function not supported";
                    case 0x82: return "File not found";
                    case 0x83: return "Record not found";
                    case 0x84: return "Not enough memory space";
                    case 0x86: return "Incorrect parameters P1 to P2";
                    case 0x87: return "Lc inconsistent with P1 to P2";
                    case 0x88: return "Referenced data not found";
                }
                break;
            case 0x90: return null; // success
            case 0x91: return null; // success
            //Status Code 0x92 has contradictory meanings from 11.11 and 102.221 10.2.1.1
            case 0x92:
                if (sw2 >> 4 == 0) {
                    return "command successful but after using an internal update retry routine";
                }
                switch(sw2) {
                    case 0x40: return "memory problem";
                }
                break;
            case 0x93:
                switch(sw2) {
                    case 0x00:
                        return "SIM Application Toolkit is busy. Command cannot be executed"
                            + " at present, further normal commands are allowed.";
                }
                break;
            case 0x94:
                switch(sw2) {
                    case 0x00: return "no EF selected";
                    case 0x02: return "out f range (invalid address)";
                    case 0x04: return "file ID not found/pattern not found";
                    case 0x08: return "file is inconsistent with the command";
                }
                break;
            case 0x98:
                switch(sw2) {
                    case 0x02: return "no CHV initialized";
                    case 0x04: return "access condition not fulfilled/"
                            + "unsuccessful CHV verification, at least one attempt left/"
                            + "unsuccessful UNBLOCK CHV verification, at least one attempt left/"
                            + "authentication failed";
                    case 0x08: return "in contradiction with CHV status";
                    case 0x10: return "in contradiction with invalidation status";
                    case 0x40: return "unsuccessful CHV verification, no attempt left/"
                            + "unsuccessful UNBLOCK CHV verification, no attempt left/"
                            + "CHV blocked"
                            + "UNBLOCK CHV blocked";
                    case 0x50: return "increase cannot be performed, Max value reached";
                }
                break;
            case 0x9E: return null; // success
            case 0x9F: return null; // success
        }
        return UNKNOWN_ERROR;
    }


    public int sw1;
    public int sw2;

@@ -39,8 +180,8 @@ IccIoResult {

    @Override
    public String toString() {
        return "IccIoResponse sw1:0x" + Integer.toHexString(sw1) + " sw2:0x"
                + Integer.toHexString(sw2);
        return "IccIoResult sw1:0x" + Integer.toHexString(sw1) + " sw2:0x"
                + Integer.toHexString(sw2) + ((!success()) ? " Error: " + getErrorString() : "");
    }

    /**
+13 −28
Original line number Diff line number Diff line
@@ -23,9 +23,9 @@ import android.os.Message;
import android.os.Registrant;
import android.os.RegistrantList;

import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.telephony.SubscriptionInfo;

import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppState;
@@ -88,6 +88,13 @@ public abstract class IccRecords extends Handler implements IccConstants {
    protected String mGid2;
    protected String mPrefLang;

    protected PlmnActRecord[] mHplmnActRecords;
    protected PlmnActRecord[] mOplmnActRecords;
    protected PlmnActRecord[] mPlmnActRecords;

    protected String[] mEhplmns;
    protected String[] mFplmns;

    private final Object mLock = new Object();

    // ***** Constants
@@ -101,7 +108,6 @@ public abstract class IccRecords extends Handler implements IccConstants {
    public static final int SPN_RULE_SHOW_PLMN = 0x02;

    // ***** Event Constants
    protected static final int EVENT_SET_MSISDN_DONE = 30;
    public static final int EVENT_MWI = 0; // Message Waiting indication
    public static final int EVENT_CFI = 1; // Call Forwarding indication
    public static final int EVENT_SPN = 2; // Service Provider Name
@@ -327,34 +333,13 @@ public abstract class IccRecords extends Handler implements IccConstants {
        return null;
    }

    /**
     * Set subscriber number to SIM record
     *
     * The subscriber number is stored in EF_MSISDN (TS 51.011)
     *
     * When the operation is complete, onComplete will be sent to its handler
     *
     * @param alphaTag alpha-tagging of the dailing nubmer (up to 10 characters)
     * @param number dailing nubmer (up to 20 digits)
     *        if the number starts with '+', then set to international TOA
     * @param onComplete
     *        onComplete.obj will be an AsyncResult
     *        ((AsyncResult)onComplete.obj).exception == null on success
     *        ((AsyncResult)onComplete.obj).exception != null on fail
     */
    public void setMsisdnNumber(String alphaTag, String number,
            Message onComplete) {

        mMsisdn = number;
        mMsisdnTag = alphaTag;

        if (DBG) log("Set MSISDN: " + mMsisdnTag +" " + mMsisdn);


        AdnRecord adn = new AdnRecord(mMsisdnTag, mMsisdn);

        new AdnRecordLoader(mFh).updateEF(adn, EF_MSISDN, EF_EXT1, 1, null,
                obtainMessage(EVENT_SET_MSISDN_DONE, onComplete));
        loge("setMsisdn() should not be invoked on base IccRecords");
        // synthesize a "File Not Found" exception and return it
        AsyncResult.forMessage(onComplete).exception =
            (new IccIoResult(0x6A, 0x82, (byte[]) null)).getException();
        onComplete.sendToTarget();
    }

    public String getMsisdnAlphaTag() {
+23 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.graphics.Color;
import android.telephony.Rlog;

import com.android.internal.telephony.GsmAlphabet;

import java.io.UnsupportedEncodingException;

/**
@@ -60,6 +61,28 @@ public class IccUtils {
        return ret.toString();
    }

    /**
     * PLMN (MCC/MNC) is encoded as per 24.008 10.5.1.3
     * Returns a concatenated string of MCC+MNC, stripping
     * a trailing character for a 2-digit MNC
     */
    public static String bcdPlmnToString(byte[] data, int offset) {
        if (offset + 3 > data.length) {
            return null;
        }
        byte[] trans = new byte[3];
        trans[0] = (byte) ((data[0 + offset] << 4) | ((data[0 + offset] >> 4) & 0xF));
        trans[1] = (byte) ((data[1 + offset] << 4) | (data[2 + offset] & 0xF));
        trans[2] = (byte) ((data[2 + offset] & 0xF0) | ((data[1 + offset] >> 4) & 0xF));
        String ret = bytesToHexString(trans);

        // For a 2-digit MNC we trim the trailing 'f'
        if (ret.endsWith("f")) {
            ret = ret.substring(0, ret.length() - 1);
        }
        return ret;
    }

    /**
     * Some fields (like ICC ID) in GSM SIMs are stored as nibble-swizzled BCH
     */
Loading