1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.telephony.uicc; 18 19 import android.os.Build; 20 21 /** 22 * {@hide} 23 */ 24 public class 25 IccIoResult { 26 27 private static final String UNKNOWN_ERROR = "unknown"; 28 29 private String getErrorString() { 30 // Errors from 3gpp 11.11 9.4.1 31 // Additional Errors from ETSI 102.221 32 // 33 // All error codes below are copied directly from their respective specification 34 // without modification except in cases where necessary string formatting has been omitted. 35 switch(sw1) { 36 case 0x62: 37 switch(sw2) { 38 case 0x00: return "No information given," 39 + " state of non volatile memory unchanged"; 40 case 0x81: return "Part of returned data may be corrupted"; 41 case 0x82: return "End of file/record reached before reading Le bytes"; 42 case 0x83: return "Selected file invalidated"; 43 case 0x84: return "Selected file in termination state"; 44 case 0xF1: return "More data available"; 45 case 0xF2: return "More data available and proactive command pending"; 46 case 0xF3: return "Response data available"; 47 } 48 break; 49 case 0x63: 50 if (sw2 >> 4 == 0x0C) { 51 return "Command successful but after using an internal" 52 + "update retry routine but Verification failed"; 53 } 54 switch(sw2) { 55 case 0xF1: return "More data expected"; 56 case 0xF2: return "More data expected and proactive command pending"; 57 } 58 break; 59 case 0x64: 60 switch(sw2) { 61 case 0x00: return "No information given," 62 + " state of non-volatile memory unchanged"; 63 } 64 break; 65 case 0x65: 66 switch(sw2) { 67 case 0x00: return "No information given, state of non-volatile memory changed"; 68 case 0x81: return "Memory problem"; 69 } 70 break; 71 case 0x67: 72 switch(sw2) { 73 case 0x00: return "incorrect parameter P3"; 74 default: return "The interpretation of this status word is command dependent"; 75 } 76 // break; 77 case 0x6B: return "incorrect parameter P1 or P2"; 78 case 0x6D: return "unknown instruction code given in the command"; 79 case 0x6E: return "wrong instruction class given in the command"; 80 case 0x6F: 81 switch(sw2) { 82 case 0x00: return "technical problem with no diagnostic given"; 83 default: return "The interpretation of this status word is command dependent"; 84 } 85 // break; 86 case 0x68: 87 switch(sw2) { 88 case 0x00: return "No information given"; 89 case 0x81: return "Logical channel not supported"; 90 case 0x82: return "Secure messaging not supported"; 91 } 92 break; 93 case 0x69: 94 switch(sw2) { 95 case 0x00: return "No information given"; 96 case 0x81: return "Command incompatible with file structure"; 97 case 0x82: return "Security status not satisfied"; 98 case 0x83: return "Authentication/PIN method blocked"; 99 case 0x84: return "Referenced data invalidated"; 100 case 0x85: return "Conditions of use not satisfied"; 101 case 0x86: return "Command not allowed (no EF selected)"; 102 case 0x89: return "Command not allowed - secure channel -" 103 + " security not satisfied"; 104 } 105 break; 106 case 0x6A: 107 switch(sw2) { 108 case 0x80: return "Incorrect parameters in the data field"; 109 case 0x81: return "Function not supported"; 110 case 0x82: return "File not found"; 111 case 0x83: return "Record not found"; 112 case 0x84: return "Not enough memory space"; 113 case 0x86: return "Incorrect parameters P1 to P2"; 114 case 0x87: return "Lc inconsistent with P1 to P2"; 115 case 0x88: return "Referenced data not found"; 116 } 117 break; 118 case 0x90: return null; // success 119 case 0x91: return null; // success 120 //Status Code 0x92 has contradictory meanings from 11.11 and 102.221 10.2.1.1 121 case 0x92: 122 if (sw2 >> 4 == 0) { 123 return "command successful but after using an internal update retry routine"; 124 } 125 switch(sw2) { 126 case 0x40: return "memory problem"; 127 } 128 break; 129 case 0x93: 130 switch(sw2) { 131 case 0x00: 132 return "SIM Application Toolkit is busy. Command cannot be executed" 133 + " at present, further normal commands are allowed."; 134 } 135 break; 136 case 0x94: 137 switch(sw2) { 138 case 0x00: return "no EF selected"; 139 case 0x02: return "out f range (invalid address)"; 140 case 0x04: return "file ID not found/pattern not found"; 141 case 0x08: return "file is inconsistent with the command"; 142 } 143 break; 144 case 0x98: 145 switch(sw2) { 146 case 0x02: return "no CHV initialized"; 147 case 0x04: return "access condition not fulfilled/" 148 + "unsuccessful CHV verification, at least one attempt left/" 149 + "unsuccessful UNBLOCK CHV verification, at least one attempt left/" 150 + "authentication failed"; 151 case 0x08: return "in contradiction with CHV status"; 152 case 0x10: return "in contradiction with invalidation status"; 153 case 0x40: return "unsuccessful CHV verification, no attempt left/" 154 + "unsuccessful UNBLOCK CHV verification, no attempt left/" 155 + "CHV blocked" 156 + "UNBLOCK CHV blocked"; 157 case 0x50: return "increase cannot be performed, Max value reached"; 158 // The definition for these status codes can be found in TS 31.102 7.3.1 159 case 0x62: return "authentication error, application specific"; 160 case 0x64: return "authentication error, security context not supported"; 161 case 0x65: return "key freshness failure"; 162 case 0x66: return "authentication error, no memory space available"; 163 case 0x67: return "authentication error, no memory space available in EF_MUK"; 164 } 165 break; 166 case 0x9E: return null; // success 167 case 0x9F: return null; // success 168 } 169 return UNKNOWN_ERROR; 170 } 171 172 173 public int sw1; 174 public int sw2; 175 176 public byte[] payload; 177 178 public IccIoResult(int sw1, int sw2, byte[] payload) { 179 this.sw1 = sw1; 180 this.sw2 = sw2; 181 this.payload = payload; 182 } 183 184 public IccIoResult(int sw1, int sw2, String hexString) { 185 this(sw1, sw2, IccUtils.hexStringToBytes(hexString)); 186 } 187 188 @Override 189 public String toString() { 190 return "IccIoResult sw1:0x" + Integer.toHexString(sw1) + " sw2:0x" 191 + Integer.toHexString(sw2) + " Payload: " 192 + ((Build.IS_DEBUGGABLE && Build.IS_ENG) ? payload : "*******") 193 + ((!success()) ? " Error: " + getErrorString() : ""); 194 } 195 196 /** 197 * true if this operation was successful 198 * See GSM 11.11 Section 9.4 199 * (the fun stuff is absent in 51.011) 200 */ 201 public boolean success() { 202 return sw1 == 0x90 || sw1 == 0x91 || sw1 == 0x9e || sw1 == 0x9f; 203 } 204 205 /** 206 * Returns exception on error or null if success 207 */ 208 public IccException getException() { 209 if (success()) return null; 210 211 switch (sw1) { 212 case 0x94: 213 if (sw2 == 0x08) { 214 return new IccFileTypeMismatch(); 215 } else { 216 return new IccFileNotFound(); 217 } 218 default: 219 return new IccException("sw1:" + sw1 + " sw2:" + sw2); 220 } 221 } 222 } 223