blob: 87def0e46666330683609b53245dcacbdd091c39 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file card_fs_uicc.c
2 * ETSI UICC specific structures / routines. */
Harald Weltead418632012-09-10 10:49:59 +02003/*
Harald Welte429adec2020-03-20 13:05:40 +01004 * (C) 2012-2020 by Harald Welte <laforge@gnumonks.org>
Harald Weltead418632012-09-10 10:49:59 +02005 *
6 * All Rights Reserved
7 *
Harald Weltee08da972017-11-13 01:00:26 +09008 * SPDX-License-Identifier: GPL-2.0+
9 *
Harald Weltead418632012-09-10 10:49:59 +020010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
Harald Weltead418632012-09-10 10:49:59 +020020 */
21
22
Harald Welted54c2ee2012-01-17 18:25:50 +010023#include <osmocom/sim/sim.h>
Harald Welte429adec2020-03-20 13:05:40 +010024#include <osmocom/core/talloc.h>
Harald Welted54c2ee2012-01-17 18:25:50 +010025#include <osmocom/gsm/tlv.h>
26
Harald Welte429adec2020-03-20 13:05:40 +010027#include "sim_int.h"
28#include "gsm_int.h"
29
Harald Welted54c2ee2012-01-17 18:25:50 +010030/* TS 102 221 V10.0.0 / 10.2.1 */
31const struct osim_card_sw ts102221_uicc_sw[] = {
32 {
33 0x9000, 0xffff, SW_TYPE_STR, SW_CLS_OK,
34 .u.str = "Normal ending of the command",
35 }, {
36 0x9100, 0xff00, SW_TYPE_STR, SW_CLS_OK,
37 .u.str = "Normal ending of the command, extra info proactive",
38 }, {
39 0x9200, 0xff00, SW_TYPE_STR, SW_CLS_OK,
40 .u.str = "Normal ending of the command, extra info regarding transfer session",
41 }, {
42 0x9300, 0xff00, SW_TYPE_STR, SW_CLS_POSTP,
43 .u.str = "SIM Application Toolkit is busy, command cannot be executed at present",
44 }, {
45 0x6200, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
46 .u.str = "No information given, state of non volatile memory unchanged",
47 }, {
48 0x6281, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
49 .u.str = "Part of returned data may be corrupted",
50 }, {
51 0x6282, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
52 .u.str = "End of file/record reached before reading Le bytes",
53 }, {
54 0x6283, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
55 .u.str = "Selected file invalidated",
56 }, {
57 0x6285, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
58 .u.str = "Selected file in termination state",
59 }, {
60 0x62f1, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
61 .u.str = "More data available",
62 }, {
63 0x62f2, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
64 .u.str = "More data available and proactive command pending",
65 }, {
66 0x62f3, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
67 .u.str = "Response data available",
68 }, {
69 0x63f1, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
70 .u.str = "More data expected",
71 }, {
72 0x63c0, 0xfff0, SW_TYPE_STR, SW_CLS_WARN,
73 .u.str = "Verification falied, X retries remaining",
74 }, {
75 0x6400, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
76 .u.str = "Execution - No information given, state of non-volatile memory unchanged",
77 }, {
78 0x6500, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
79 .u.str = "Execution - No information given, state of non-volatile memory changed",
80 }, {
81 0x6581, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
82 .u.str = "Execution - Memory problem",
83 }, {
84 0x6700, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
85 .u.str = "Checking - Wrong length",
86 }, {
87 0x6700, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
88 .u.str = "Checking - Command dependent error",
89 }, {
90 0x6b00, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
91 .u.str = "Checking - Wrong parameter(s) P1-P2",
92 }, {
93 0x6d00, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
94 .u.str = "Checking - Instruction code not supported or valid",
95 }, {
96 0x6e00, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
97 .u.str = "Checking - Class not supported",
98 }, {
99 0x6f00, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
100 .u.str = "Checking - Technical problem, no precise diagnostics",
101 }, {
102 0x6f00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
103 .u.str = "Checking - Command dependent error",
104 }, {
105 0x6800, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
106 .u.str = "Function in CLA not supported - No information given",
107 }, {
108 0x6881, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
109 .u.str = "Function in CLA not supported - Logical channel not supported",
110 }, {
111 0x6882, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
112 .u.str = "Function in CLA not supportied - Secure messaging not supported",
113 }, {
114 0x6900, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
115 .u.str = "Command not allowed - No information given",
116 }, {
117 0x6981, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
118 .u.str = "Command not allowed - Command incompatible with file structure",
119 }, {
120 0x6982, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
121 .u.str = "Command not allowed - Security status not satisfied",
122 }, {
123 0x6983, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
124 .u.str = "Command not allowed - Authentication/PIN method blocked",
125 }, {
126 0x6984, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
127 .u.str = "Command not allowed - Referenced data invalidated",
128 }, {
129 0x6985, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
130 .u.str = "Command not allowed - Conditions of use not satisfied",
131 }, {
132 0x6986, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
133 .u.str = "Command not allowed - Noe EF selected",
134 }, {
135 0x6989, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
136 .u.str = "Command not allowed - secure channel - security not satisfied",
137 }, {
138 0x6a80, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
139 .u.str = "Wrong parameters - Incorrect parameters in the data field",
140 }, {
141 0x6a81, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
142 .u.str = "Wrong parameters - Function not supported",
143 }, {
144 0x6a82, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
145 .u.str = "Wrong parameters - File not found",
146 }, {
147 0x6a83, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
148 .u.str = "Wrong parameters - Record not found",
149 }, {
150 0x6a84, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
151 .u.str = "Wrong parameters - Not enough memory space",
152 }, {
153 0x6a86, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
154 .u.str = "Wrong parameters - Incorrect parameters P1 to P2",
155 }, {
156 0x6a87, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
157 .u.str = "Wrong parameters - Lc inconsistent with P1 ot P2",
158 }, {
159 0x6a88, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
160 .u.str = "Wrong parameters - Referenced data not found",
161 }, {
162 0x9850, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
163 .u.str = "Application error - INCREASE cannot be performed, max value reached",
164 }, {
165 0x9862, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
166 .u.str = "Application error - Authentication error, application specific",
167 }, {
168 0x9863, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
169 .u.str = "Application error - Security session or association expired",
170 },
171 OSIM_CARD_SW_LAST
172};
173
Harald Welte429adec2020-03-20 13:05:40 +0100174static const struct osim_card_sw *uicc_card_sws[] = {
175 ts102221_uicc_sw,
176 NULL
177};
178
179/* TS 102 221 Chapter 13.1 */
180static const struct osim_file_desc uicc_ef_in_mf[] = {
181 EF_LIN_FIX_N(0x2f00, SFI_NONE, "EF.DIR", 0, 1, 32,
182 "Application directory"),
183 EF_TRANSP_N(0x2FE2, SFI_NONE, "EF.ICCID", 0, 10, 10,
184 "ICC Identification"),
185 EF_TRANSP_N(0x2F05, SFI_NONE, "EF.PL", 0, 2, 20,
186 "Preferred Languages"),
187 EF_LIN_FIX_N(0x2F06, SFI_NONE, "EF.ARR", F_OPTIONAL, 1, 256,
188 "Access Rule Reference"),
189};
190
Harald Welted54c2ee2012-01-17 18:25:50 +0100191const struct value_string ts102221_fcp_vals[14] = {
192 { UICC_FCP_T_FCP, "File control parameters" },
193 { UICC_FCP_T_FILE_SIZE, "File size" },
194 { UICC_FCP_T_TOT_F_SIZE, "Total size of files" },
195 { UICC_FCP_T_FILE_DESC, "File descriptor" },
196 { UICC_FCP_T_FILE_ID, "File identifier" },
197 { UICC_FCP_T_DF_NAME, "DF name" },
198 { UICC_FCP_T_SFID, "Short file identifier" },
199 { UICC_FCP_T_LIFEC_STS, "Lifecycle status integer" },
200 { UICC_FCP_T_SEC_ATTR_REFEXP, "Security attributes (Referenced/Expanded)" },
201 { UICC_FCP_T_SEC_ATTR_COMP, "Security attributes (Compact)" },
202 { UICC_FCP_T_PROPRIETARY, "Proprietary" },
203 { UICC_FCP_T_SEC_ATTR_EXP, "Security attributes (Expanded)" },
204 { UICC_FCP_T_PIN_STS_DO, "PIN Status DO" },
205 { 0, NULL }
206};
207
208/* FIXME: Ber-TLV ?? */
209const struct tlv_definition ts102221_fcp_tlv_def = {
210 .def = {
211 [UICC_FCP_T_FCP] = { TLV_TYPE_TLV },
212 [UICC_FCP_T_FILE_SIZE] = { TLV_TYPE_TLV },
213 [UICC_FCP_T_TOT_F_SIZE] = { TLV_TYPE_TLV },
214 [UICC_FCP_T_FILE_DESC] = { TLV_TYPE_TLV },
215 [UICC_FCP_T_FILE_ID] = { TLV_TYPE_TLV },
216 [UICC_FCP_T_DF_NAME] = { TLV_TYPE_TLV },
217 [UICC_FCP_T_SFID] = { TLV_TYPE_TLV },
218 [UICC_FCP_T_LIFEC_STS] = { TLV_TYPE_TLV },
219 [UICC_FCP_T_SEC_ATTR_REFEXP] = { TLV_TYPE_TLV },
220 [UICC_FCP_T_SEC_ATTR_COMP] = { TLV_TYPE_TLV },
221 [UICC_FCP_T_PROPRIETARY] = { TLV_TYPE_TLV },
222 [UICC_FCP_T_SEC_ATTR_EXP] = { TLV_TYPE_TLV },
223 [UICC_FCP_T_PIN_STS_DO] = { TLV_TYPE_TLV },
224 },
225};
226
227/* Annex E - TS 101 220 */
Pau Espin Pedrol92274452017-06-17 23:27:47 +0200228static const uint8_t __attribute__((__unused__)) adf_uicc_aid[] = { 0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x01 };
Harald Welte429adec2020-03-20 13:05:40 +0100229
Harald Welte58d173a2020-03-21 13:40:28 +0100230struct osim_card_profile *osim_cprof_uicc(void *ctx, bool have_df_gsm)
Harald Welte429adec2020-03-20 13:05:40 +0100231{
232 struct osim_card_profile *cprof;
233 struct osim_file_desc *mf;
234 int rc;
235
236 cprof = talloc_zero(ctx, struct osim_card_profile);
237 cprof->name = "3GPP UICC";
238 cprof->sws = uicc_card_sws; // FIXME: extend later
239
240 mf = alloc_df(cprof, 0x3f00, "MF");
241
242 cprof->mf = mf;
243
244 /* Core UICC Files */
245 add_filedesc(mf, uicc_ef_in_mf, ARRAY_SIZE(uicc_ef_in_mf));
246
247 /* DF.TELECOM hierarchy as sub-directory of MF */
248 rc = osim_int_cprof_add_telecom(mf);
249 if (rc != 0) {
250 talloc_free(cprof);
251 return NULL;
252 }
253
Harald Welte58d173a2020-03-21 13:40:28 +0100254 if (have_df_gsm) {
255 /* DF.GSM as sub-directory of MF */
256 rc = osim_int_cprof_add_gsm(mf);
257 if (rc != 0) {
258 talloc_free(cprof);
259 return NULL;
260 }
261 }
262
Harald Welte429adec2020-03-20 13:05:40 +0100263 return cprof;
264}